Пример #1
0
 public function btnAddInventory_Click($strFormId, $strControlId, $strParameter)
 {
     // Clearing warning on previous attempt
     $this->txtNewInventoryModelCode->Warning = '';
     $this->txtQuantity->Warning = '';
     $blnError = false;
     // Assign the values from the user submitted form input
     $strInventoryModelCode = $this->txtNewInventoryModelCode->Text;
     $intTransactionQuantity = $this->txtQuantity->Text;
     // Check that the quantity is valid
     if (!$intTransactionQuantity || !ctype_digit($intTransactionQuantity) || $intTransactionQuantity <= 0) {
         $this->txtQuantity->Warning = "That is not a valid quantity.";
         $blnError = true;
     } elseif ($strInventoryModelCode) {
         $objNewInventoryModel = InventoryModel::LoadByInventoryModelCode($strInventoryModelCode);
         if ($objNewInventoryModel) {
             if ($this->objInventoryTransactionArray) {
                 foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
                     if ($objInventoryTransaction && $objInventoryTransaction->InventoryLocation->InventoryModelId == $objNewInventoryModel->InventoryModelId) {
                         $blnError = true;
                         $this->txtNewInventoryModelCode->Warning = "That inventory has already been added.";
                     }
                 }
             }
             if (!$blnError && !QApplication::AuthorizeEntityBoolean($objNewInventoryModel, 2)) {
                 $blnError = true;
                 $this->txtNewInventoryModelCode->Warning = "You do not have authorization to perform a transaction on this inventory model.";
             }
             if (!$blnError) {
                 $objNewInventoryLocation = InventoryLocation::LoadByLocationIdInventoryModelId(5, $objNewInventoryModel->InventoryModelId);
                 // If the 'To Be Received' inventory location for this InventoryModelId does not exist
                 // Create a new InventoryLocation with a quantity of 0. The quantity will be added to this location when the receipt is saved
                 if (!$objNewInventoryLocation) {
                     $objNewInventoryLocation = new InventoryLocation();
                     $objNewInventoryLocation->InventoryModelId = $objNewInventoryModel->InventoryModelId;
                     $objNewInventoryLocation->LocationId = 5;
                     $objNewInventoryLocation->Quantity = 0;
                     $objNewInventoryLocation->Save();
                 }
                 // Create the new Inventory Transaction
                 $objNewInventoryTransaction = new InventoryTransaction();
                 $objNewInventoryTransaction->InventoryLocationId = $objNewInventoryLocation->InventoryLocationId;
                 $objNewInventoryTransaction->Quantity = $intTransactionQuantity;
                 $objNewInventoryTransaction->SourceLocationId = 5;
                 $this->objInventoryTransactionArray[] = $objNewInventoryTransaction;
                 // Reset the input values
                 $this->txtNewInventoryModelCode->Text = null;
                 $this->txtQuantity->Text = null;
                 // This is so the datagrid knows to reload
                 $this->blnModifyInventory = true;
             }
         } else {
             $blnError = true;
             $this->txtNewInventoryModelCode->Warning = "That is not a valid inventory code.";
         }
     } else {
         $blnError = true;
         $this->txtNewInventoryModelCode->Warning = "Please enter an inventory code.";
     }
     $this->dtgInventoryTransact->Refresh();
 }
Пример #2
0
 Run error checking on the array of asset codes and the destination location
 If there are no errors, then you will add the transaction to the database.
 	That will include an entry in the Transaction and Asset Transaction table.
 	You will also have to change the asset.location_id to the destination location
 */
 $arrInventoryCodeLocationQuantity = array_unique(explode('#', $_POST['result']));
 $blnError = false;
 $arrCheckedInventoryCodeLocationQuantity = array();
 foreach ($arrInventoryCodeLocationQuantity as $strInventoryCodeLocationQuantity) {
     $blnErrorCurrentInventory = false;
     list($strInventoryModelCode, $strSourceLocation, $intQuantity) = explode('|', $strInventoryCodeLocationQuantity, 3);
     if ($strInventoryModelCode && $strSourceLocation && $intQuantity) {
         $intNewInventoryLocationId = 0;
         // Begin error checking
         // Load the inventory model object based on the inventory_model_code submitted
         $objInventoryModel = InventoryModel::LoadByInventoryModelCode($strInventoryModelCode);
         if ($objInventoryModel) {
             // Load the array of InventoryLocations based on the InventoryModelId of the InventoryModel object
             $InventorySourceLocationArray = InventoryLocation::LoadArrayByInventoryModelIdLocations($objInventoryModel->InventoryModelId);
             if ($InventorySourceLocationArray) {
                 $blnErrorCurrentInventory = true;
                 foreach ($InventorySourceLocationArray as $InventoryLocation) {
                     if ($InventoryLocation->Quantity != 0) {
                         if (strtoupper($InventoryLocation->__toString()) == strtoupper($strSourceLocation)) {
                             $blnErrorCurrentInventory = false;
                             $intNewInventoryLocationId = $InventoryLocation->InventoryLocationId;
                             $objNewInventoryLocation = $InventoryLocation;
                         }
                     }
                 }
                 if ($blnErrorCurrentInventory) {
 public function btnAdd_Click($strFormId, $strControlId, $strParameter)
 {
     // Clear warnings from previous attempt
     $this->txtNewInventoryModelCode->Warning = '';
     $blnError = false;
     // Assign the values from the user submitted form input
     $intNewInventoryLocationId = $this->lstSourceLocation->SelectedValue;
     $intTransactionQuantity = $this->txtQuantity->Text;
     // Create array of TransactionType (key) and AuthorizationLevel (value) by RoleId
     $objRoleTransactionTypeAuthorizationArray = RoleTransactionTypeAuthorization::LoadArrayByRoleId(QApplication::$objUserAccount->RoleId);
     $intAuthorizationLevelIdArray = array();
     if ($objRoleTransactionTypeAuthorizationArray) {
         foreach ($objRoleTransactionTypeAuthorizationArray as $objRoleTransactionTypeAuthorization) {
             $intAuthorizationLevelIdArray[$objRoleTransactionTypeAuthorization->TransactionTypeId] = $objRoleTransactionTypeAuthorization->AuthorizationLevelId;
         }
     }
     // If transaction is a move or take out
     if ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 5) {
         if ($intNewInventoryLocationId) {
             // Begin error checking
             if ($this->objInventoryLocationArray) {
                 foreach ($this->objInventoryLocationArray as $objInventoryLocation) {
                     if ($objInventoryLocation && $objInventoryLocation->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 (!ctype_digit($intTransactionQuantity) || $intTransactionQuantity <= 0) {
                     $this->txtQuantity->Warning = "That is not a valid quantity.";
                     $blnError = true;
                 }
                 // Move
                 if ($this->intTransactionTypeId == 1) {
                     if ($objNewInventoryLocation->Quantity < $intTransactionQuantity) {
                         $this->txtQuantity->Warning = "Quantity moved cannot exceed quantity available.";
                         $blnError = true;
                     }
                 } elseif ($this->intTransactionTypeId == 5) {
                     if ($objNewInventoryLocation->Quantity < $intTransactionQuantity) {
                         $this->txtQuantity->Warning = "Quantity taken out cannot exceed quantity available.";
                         $blnError = true;
                     }
                 }
             }
         } elseif ($this->intTransactionTypeId != 4) {
             $this->txtNewInventoryModelCode->Warning = "Please select a source location.";
             $blnError = true;
         }
     } elseif ($this->intTransactionTypeId == 4) {
         // Check for duplicate inventory code
         $strNewInventoryModelCode = $this->txtNewInventoryModelCode->Text;
         if (!($objNewInventoryModel = InventoryModel::LoadByInventoryModelCode($strNewInventoryModelCode))) {
             $blnError = true;
             $this->txtNewInventoryModelCode->Warning = "That is an invalid Inventory Code.";
         } elseif ($this->objInventoryLocationArray) {
             foreach ($this->objInventoryLocationArray as $objInventoryLocation) {
                 if ($objInventoryLocation && $objInventoryLocation->InventoryModel->InventoryModelCode == $strNewInventoryModelCode) {
                     $blnError = true;
                     $this->txtNewInventoryModelCode->Warning = "That Inventory has already been added.";
                 }
             }
         }
         if (!$blnError) {
             $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::LoadByRoleIdTransactionTypeId(QApplication::$objUserAccount->RoleId, 4);
             if ($objRoleTransactionTypeAuthorization) {
                 // If the user has 'None' privileges for this transaction
                 if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) {
                     $this->txtNewInventoryModelCode->Warning = "You do not have privileges for this transaction.";
                     $blnError = true;
                 } elseif ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 2 && $objNewInventoryModel->CreatedBy != QApplication::$objUserAccount->UserAccountId) {
                     $this->txtNewInventoryModelCode->Warning = "You are not the owner of this inventory.";
                     $blnError = true;
                 }
             }
         }
         if (!$blnError) {
             // Create a new InventoryLocation for the time being
             // Before saving we will check to see if it already exists
             $objNewInventoryLocation = new InventoryLocation();
             $objNewInventoryLocation->InventoryModelId = $objNewInventoryModel->InventoryModelId;
             $objNewInventoryLocation->Quantity = 0;
             // LocationID = 4 is 'New Inventory' Location
             $objNewInventoryLocation->LocationId = 4;
         }
     }
     if (!$blnError && isset($objNewInventoryModel) && !QApplication::AuthorizeEntityBoolean($objNewInventoryModel, 2)) {
         $blnError = true;
         $this->txtNewInventoryModelCode->Warning = "You do not have authorization to perform a transaction on this inventory model.";
     }
     if (!$blnError && $objNewInventoryLocation instanceof InventoryLocation) {
         $objNewInventoryLocation->intTransactionQuantity = $intTransactionQuantity;
         $this->objInventoryLocationArray[] = $objNewInventoryLocation;
         $this->txtNewInventoryModelCode->Text = null;
         $this->lstSourceLocation->SelectedIndex = 0;
         $this->txtQuantity->Text = null;
         if ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 5) {
             $this->lstSourceLocation->Enabled = false;
             $this->txtQuantity->Enabled = false;
         }
     }
 }
Пример #4
0
 public function btnLookup_Click($strFormId, $strControlId, $strParameter)
 {
     // Clear if warning from previous attempt exists
     $this->txtNewInventoryModelCode->Warning = '';
     // Assign the value submitted from the form
     $strInventoryModelCode = $this->txtNewInventoryModelCode->Text;
     if ($strInventoryModelCode) {
         // Load the inventory model object based on the inventory_model_code submitted
         $objInventoryModel = InventoryModel::LoadByInventoryModelCode($strInventoryModelCode);
         if ($objInventoryModel) {
             // Load the array of InventoryLocations based on the InventoryModelId of the InventoryModel object
             $InventorySourceLocationArray = InventoryLocation::LoadArrayByInventoryModelIdLocations($objInventoryModel->InventoryModelId);
             $this->lstSourceLocation->RemoveAllItems();
             $this->lstSourceLocation->AddItem('- Select One -', null);
             if ($InventorySourceLocationArray) {
                 // Populate the Source Location list box
                 foreach ($InventorySourceLocationArray as $InventoryLocation) {
                     // Do not display locations where the quantity is 0
                     if ($InventoryLocation->Quantity != 0) {
                         $this->lstSourceLocation->AddItem($InventoryLocation->__toStringWithQuantity(), $InventoryLocation->InventoryLocationId);
                     }
                 }
                 $this->lstSourceLocation->Enabled = true;
                 $this->txtQuantity->Enabled = true;
             } else {
                 $this->txtNewInventoryModelCode->Warning = 'There is no inventory for that inventory code';
                 $this->lstSourceLocation->Enabled = false;
                 $this->txtQuantity->Enabled = false;
             }
         } else {
             $this->txtNewInventoryModelCode->Warning = 'That is not a valid inventory code.';
         }
     } else {
         $this->txtNewInventoryModelCode->Warning = 'Please enter an inventory code.';
     }
 }