Ejemplo n.º 1
0
 /**
  * Gets all associated InventoryTransactions as an array of InventoryTransaction objects
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return InventoryTransaction[]
  */
 public function GetInventoryTransactionArray($objOptionalClauses = null)
 {
     if (is_null($this->intInventoryLocationId)) {
         return array();
     }
     try {
         return InventoryTransaction::LoadArrayByInventoryLocationId($this->intInventoryLocationId, $objOptionalClauses);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }
    /**
     * Deletes all associated InventoryTransactions
     * @return void
     */
    public function DeleteAllInventoryTransactions()
    {
        if (is_null($this->intInventoryLocationId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateInventoryTransaction on this unsaved InventoryLocation.');
        }
        // Get the Database Object for this Class
        $objDatabase = InventoryLocation::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (InventoryTransaction::LoadArrayByInventoryLocationId($this->intInventoryLocationId) as $objInventoryTransaction) {
                $objInventoryTransaction->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`inventory_transaction`
				WHERE
					`inventory_location_id` = ' . $objDatabase->SqlVariable($this->intInventoryLocationId) . '
			');
    }
Ejemplo n.º 3
0
 public function btnAddInventory_Click($strFormId, $strControlId, $strParameter)
 {
     $blnError = false;
     // Assign the values from the user submitted form input
     $intNewInventoryLocationId = $this->lstSourceLocation->SelectedValue;
     $intTransactionQuantity = $this->txtQuantity->Text;
     if ($intNewInventoryLocationId) {
         // Begin error checking
         if ($this->objInventoryTransactionArray) {
             foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
                 if ($objInventoryTransaction && $objInventoryTransaction->InventoryLocation->InventoryLocationId == $intNewInventoryLocationId) {
                     $blnError = true;
                     $this->txtNewInventoryModelCode->Warning = "That Inventory has already been added.";
                 }
             }
         }
         if (!$blnError) {
             $objNewInventoryLocation = InventoryLocation::LoadLocations($intNewInventoryLocationId);
             // This should not be possible because the list is populated with existing InventoryLocations
             if (!$objNewInventoryLocation instanceof InventoryLocation) {
                 $this->txtNewInventoryModelCode->Warning = "That Inventory location does not exist.";
                 $blnError = true;
             } elseif (!$intTransactionQuantity || !ctype_digit($intTransactionQuantity) || $intTransactionQuantity <= 0) {
                 $this->txtQuantity->Warning = "That is not a valid quantity.";
                 $blnError = true;
             } elseif ($objNewInventoryLocation->Quantity < $intTransactionQuantity) {
                 $this->txtQuantity->Warning = "Quantity shipped cannot exceed quantity available.";
                 $blnError = true;
             } elseif (!QApplication::AuthorizeEntityBoolean($objNewInventoryLocation->InventoryModel, 2)) {
                 $blnError = true;
                 $this->txtQuantity->Warning = "You do not have authorization to perform a transaction on this inventory model.";
             } else {
                 $objExpansionMap[InventoryTransaction::ExpandTransaction] = true;
                 $objInventoryTransactionArray = InventoryTransaction::LoadArrayByInventoryLocationId($objNewInventoryLocation->InventoryLocationId, null, null, $objExpansionMap);
                 if ($objInventoryTransactionArray) {
                     $intQuantityScheduled = 0;
                     foreach ($objInventoryTransactionArray as $objInventoryTransaction) {
                         // If there is a pending shipment
                         if ($objInventoryTransaction->Transaction->TransactionTypeId == 6) {
                             /*
                             									QCodo Beta3 is not generating a LoadArrayByTransactionId method anymore. Instead, it generates LoadByTransactionId.
                             									That is actually better, so we will use that from now on.
                             									$objShipmentArray = Shipment::LoadArrayByTransactionId($objInventoryTransaction->TransactionId);
                             									if ($objShipmentArray) {
                             										foreach ($objShipmentArray as $objShipment) {
                             											if (!$objShipment->ShippedFlag) {
                             												$intQuantityScheduled += $objInventoryTransaction->Quantity;
                             											}
                             										}
                             									}*/
                             $objShipment = Shipment::LoadByTransactionId($objInventoryTransaction->TransactionId);
                             if ($objShipment && !$objShipment->ShippedFlag) {
                                 $intQuantityScheduled += $objInventoryTransaction->Quantity;
                             }
                         }
                     }
                     if ($intTransactionQuantity > $objNewInventoryLocation->Quantity - $intQuantityScheduled) {
                         $blnError = true;
                         $this->txtNewInventoryModelCode->Warning = sprintf("That inventory has %s units already scheduled for shipment. Not enough available inventory.", $intQuantityScheduled);
                     }
                 }
             }
             $this->dtgInventoryTransact->Refresh();
         }
     } else {
         $this->txtNewInventoryModelCode->Warning = "Please select a source location.";
         $blnError = true;
     }
     if (!$blnError && $objNewInventoryLocation instanceof InventoryLocation) {
         $objInventoryTransaction = new InventoryTransaction();
         $objInventoryTransaction->InventoryLocationId = $objNewInventoryLocation->InventoryLocationId;
         // $objInventoryTransaction->InventoryLocation = $objNewInventoryLocation;
         $objInventoryTransaction->Quantity = $intTransactionQuantity;
         $objInventoryTransaction->SourceLocationId = $objNewInventoryLocation->LocationId;
         $this->objInventoryTransactionArray[] = $objInventoryTransaction;
         $this->txtNewInventoryModelCode->Text = null;
         $this->lstSourceLocation->SelectedIndex = 0;
         $this->txtQuantity->Text = null;
         $this->lstSourceLocation->Enabled = false;
         $this->txtQuantity->Enabled = false;
         $this->blnModifyInventory = true;
     }
 }