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; } } }
public function btnAddInventory_Click($strFormId, $strControlId, $strParameter) { $blnError = false; $this->txtQuantity->Warning = ''; $this->txtNewInventoryModelCode->Warning = ''; // 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."; } // Check to see if that InventoryLocation has some quantity scheduled for shipment // If so, make sure that there is enough inventory available to add the new quantity. // This can be made faster by making a more targeted SQL query /*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) { $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; } }