Last active
February 15, 2016 16:59
-
-
Save alexmccabe/b18d4c92fffcc8e3a542 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$query = DB::table(DB::raw(' | |
(SELECT | |
SupplierProduct.discontinued, | |
SupplierProduct.productID, | |
InstSupplier.*, | |
max(stockLevel) as stockLevel | |
FROM | |
SupplierProduct | |
JOIN InstSupplier ON SupplierProduct.supplierID = InstSupplier.supplierID AND InstSupplier.installationID = ? AND InstSupplier.active = 1 | |
LEFT JOIN SupplierStock ON SupplierStock.supplierProductID = SupplierProduct.id | |
group by SupplierStock.supplierProductID | |
) SupplierProduct'))->addBinding($this->installationID); | |
$query->select( | |
'MediaLink.url as imgUrl', | |
'MediaLink.providerID as imgProviderID', | |
'ProviderProduct.productID as pid', | |
DB::raw('sum(SupplierProduct.stockLevel) stockLevel')); | |
$query->leftJoin('ProviderProduct', 'SupplierProduct.productID', '=', 'ProviderProduct.productID'); | |
$query->leftJoin('MediaLink', function ($join) { | |
$join->on('MediaLink.productID', '=', 'ProviderProduct.productID'); | |
$join->where('MediaLink.mediaType', '=', 'IMG'); | |
}); | |
$query->where('SupplierProduct.discontinued', 0); | |
$query->whereIn('ProviderProduct.productID', $products->lists('pid')); | |
$query->groupBy('SupplierProduct.productID'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment