/** * Gets the historical journal for an object from the log database. * Objects will have VirtualAttributes available to lookup login, date, and action information from the journal object. * @param integer intInventoryLocationId * @return InventoryLocation[] */ public static function GetJournalForId($intInventoryLocationId) { $objDatabase = InventoryLocation::GetDatabase()->JournalingDatabase; $objResult = $objDatabase->Query('SELECT * FROM inventory_location WHERE inventory_location_id = ' . $objDatabase->SqlVariable($intInventoryLocationId) . ' ORDER BY __sys_date'); return InventoryLocation::InstantiateDbResult($objResult); }
/** * 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); }
/** * Static Qcodo Query method to query for an array of InventoryLocation objects. * Uses BuildQueryStatment to perform most of the work. * @param QQCondition $objConditions any conditions on the query, itself * @param QQClause[] $objOptionalClausees additional optional QQClause objects for this query * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with * @return InventoryLocation[] the queried objects as an array */ public static function QueryArray(QQCondition $objConditions, $objOptionalClauses = null, $mixParameterArray = null) { // Get the Query Statement try { $strQuery = InventoryLocation::BuildQueryStatement($objQueryBuilder, $objConditions, $objOptionalClauses, $mixParameterArray, false); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } // Perform the Query and Instantiate the Array Result $objDbResult = $objQueryBuilder->Database->Query($strQuery); return InventoryLocation::InstantiateDbResult($objDbResult, $objQueryBuilder->ExpandAsArrayNodes); }