/** * Load an array of InventoryLocation objects, * by InventoryModelId Index(es) * @param integer $intInventoryModelId * @param string $strOrderBy * @param string $strLimit * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding * @return InventoryLocation[] */ public static function LoadArrayByInventoryModelIdLocations($intInventoryModelId, $strOrderBy = null, $strLimit = null, $objExpansionMap = null) { // Call to ArrayQueryHelper to Get Database Object and Get SQL Clauses InventoryLocation::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase); // Properly Escape All Input Parameters using Database->SqlVariable() $intInventoryModelId = $objDatabase->SqlVariable($intInventoryModelId, true); // This query subtracts any inventory that is pending shipment. That is inventory that has been added to a shipment but the shipment hasn't been included. // This pending inventory is the sum of the quantites in InventoryTransaction where the SourceLocation is anything greated than 5 (a custom location) and the Destination IS NULL (incomplete transaction) // Setup the SQL Query $strQuery = sprintf(' SELECT %s `inventory_location`.`inventory_location_id` AS `inventory_location_id`, `inventory_location`.`inventory_model_id` AS `inventory_model_id`, `inventory_location`.`location_id` AS `location_id`, `inventory_location`.`created_by` AS `created_by`, `inventory_location`.`creation_date` AS `creation_date`, `inventory_location`.`modified_by` AS `modified_by`, `inventory_location`.`modified_date` AS `modified_date`, `inventory_location`.`quantity` AS `__actual_quantity`, (`inventory_location`.`quantity` - IFNULL((SELECT SUM(`inventory_transaction`.`quantity`) AS `pending_quantity` FROM `inventory_transaction` AS `inventory_transaction` WHERE `inventory_transaction`.`inventory_location_id` = `inventory_location`.`inventory_location_id` AND `inventory_transaction`.`source_location_id` > 5 AND `inventory_transaction`.`destination_location_id` IS NULL), 0)) AS `quantity` %s FROM `inventory_location` AS `inventory_location` %s WHERE `inventory_location`.`inventory_model_id` %s AND `inventory_location`.`location_id` > 5 %s %s', $strLimitPrefix, $strExpandSelect, $strExpandFrom, $intInventoryModelId, $strOrderBy, $strLimitSuffix); // Perform the Query and Instantiate the Result $objDbResult = $objDatabase->Query($strQuery); return InventoryLocation::InstantiateDbResult($objDbResult); }