Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Last active April 8, 2016 06:48
Show Gist options
  • Save mdmunir/3b4359a2b154426561adf45802fbff97 to your computer and use it in GitHub Desktop.
Save mdmunir/3b4359a2b154426561adf45802fbff97 to your computer and use it in GitHub Desktop.
Sub Query
<?php
$queryGM = (new Query())
->select(['gmd.product_id', 'total' => 'sum(gmd.qty)'])
->from(['gm' => '{{%goods_movement}}'])
->innerJoin(['gmd' => '{{%goods_movement_dtl}}'], '[[gmd.movement_id]]=[[gm.id]]')
->where(['gm.status' => 20, 'gm.reff_type' => self::REFF_SELF, 'gm.reff_id' => $this->id])
->groupBy(['gmd.product_id']);
$queryItem = (new Query())
->select(['md.product_id', 'md.cogs', 'md.qty', 'md.uom_id', 'g.total'])
->from(['md' => '{{%goods_movement_dtl}}'])
->leftJoin(['g' => $queryGM], '[[g.product_id]]=[[md.product_id]]')
->where(['md.movement_id' => $this->id]);
foreach ($queryItem->all() as $item) {
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment