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(); }
public function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->EnableSelectedControls(); $this->ClearWarnings(); $blnError = false; // Make sure at least one checkbox is checked if (!$this->chkCategory->Checked && !$this->chkManufacturer->Checked && !$this->chkLongDescription->Checked) { $blnChecked = false; foreach ($this->arrCheckboxes as $objCheckBox) { if ($objCheckBox->Checked) { $blnChecked = true; break; } } if (!$blnChecked) { $blnError = true; $this->btnCancel->Warning = 'You must select at least one field to edit.'; return; } } // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); if (count($this->arrCustomFields) > 0) { $customFieldIdArray = array(); foreach ($this->arrCustomFields as $field) { if ($this->arrCheckboxes[$field['input']->strControlId]->Checked) { if ($field['input'] instanceof QTextBox && $field['input']->Required && $field['input']->Text == null || $field['input'] instanceof QListBox && $field['input']->Required && $field['input']->SelectedValue == null) { $blnError = true; $field['input']->Warning = "Required."; } else { $this->arrCustomFieldsToEdit[] = $field; $customFieldIdArray[] = (int) str_replace('cf', '', $field['input']->strControlId); } } } } $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId)); // Force modified_date timestamp update $set[] = '`modified_date` = NOW()'; if ($this->chkLongDescription->Checked) { $set[] = sprintf('`long_description`="%s"', $this->txtLongDescription->Text); } if ($this->chkManufacturer->Checked) { if ($this->lstManufacturer->SelectedValue !== null) { $set[] = sprintf('`manufacturer_id`=%s', $this->lstManufacturer->SelectedValue); } else { $blnError = true; $this->lstManufacturer->Warning = 'Manufacturer is required.'; } } if ($this->chkCategory->Checked) { if ($this->lstCategory->SelectedValue !== null) { $set[] = sprintf('`category_id`= %s', $this->lstCategory->SelectedValue); } else { $blnError = true; $this->lstCategory->Warning = 'Category is required.'; } } // First check that the user is authorized to edit these models foreach ($this->arrModelsToEdit as $intModelId) { $objAssetModel = AssetModel::Load($intModelId); if (!QApplication::AuthorizeEntityBoolean($objAssetModel, 2)) { $blnError = true; $this->btnCancel->Warning = 'You are not authorized to edit one or more of the selected models.'; break; } } if (!$blnError) { try { if (count($this->arrCustomFieldsToEdit) > 0) { // preparing data to edit // Save the values from all of the custom field controls to save the asset foreach ($this->arrModelsToEdit as $intModelId) { $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::AssetModel, false); $selectedCustomFieldsArray = array(); foreach ($objCustomFieldsArray as $objCustomField) { if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) { $selectedCustomFieldsArray[] = $objCustomField; } } CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intModelId, EntityQtype::AssetModel); } } $strQuery = sprintf("UPDATE `asset_model`\n\t\t\t\t\t\t\t\t\t SET " . implode(",", $set) . "\n\t\t\t\t\t\t\t\t\t WHERE `asset_model_id` IN (%s)", implode(",", $this->arrModelsToEdit)); // print $strQuery; exit; $objDatabase->NonQuery($strQuery); $objDatabase->TransactionCommit(); QApplication::Redirect(''); } catch (QMySqliDatabaseException $objExc) { $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } else { $objDatabase->TransactionRollback(); $this->arrCustomFieldsToEdit = array(); } }
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 btnAdd_Click($strFormId, $strControlId, $strParameter) { $strAssetCode = $this->txtNewAssetCode->Text; $blnDuplicate = false; $blnError = false; if ($strAssetCode) { // Begin error checking if ($this->objAssetArray) { foreach ($this->objAssetArray as $asset) { if ($asset && $asset->AssetCode == $strAssetCode) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset has already been added."; } } } if (!$blnError) { $this->txtNewAssetCode->Warning = ''; $objNewAsset = Asset::LoadByAssetCodeWithCustomFields($this->txtNewAssetCode->Text); if (!$objNewAsset instanceof Asset) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset code does not exist."; } elseif ($objNewAsset->LinkedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is locked to a parent asset."; } elseif ($objNewAsset->LocationId == 6 && $this->intTransactionTypeId != 11) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset has already been archived."; } elseif ($objNewAsset->LocationId == 2) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset has already been shipped."; } elseif ($objNewAsset->LocationId == 5) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is currently scheduled to be received."; } elseif ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId)) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already in a pending shipment."; } elseif (!QApplication::AuthorizeEntityBoolean($objNewAsset, 2)) { $blnError = true; $this->txtNewAssetCode->Warning = "You do not have authorization to perform a transaction on this asset."; } elseif ($this->intTransactionTypeId == 1) { if ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } } elseif ($this->intTransactionTypeId == 2) { if (!$objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is not checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } elseif ($objNewAsset->CheckedOutFlag) { $objUserAccount = $objNewAsset->GetLastTransactionUser(); if (QApplication::$TracmorSettings->StrictCheckinPolicy == '1' && $objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset was not checked out by the current user."; } } } elseif ($this->intTransactionTypeId == 3) { if ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } } elseif ($this->intTransactionTypeId == 8) { if ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already reserved."; } elseif ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } } elseif ($this->intTransactionTypeId == 9) { if (!$objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is not reserved"; } elseif ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } elseif ($objNewAsset->ReservedFlag) { $objUserAccount = $objNewAsset->GetLastTransactionUser(); if ($objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset was not reserved by the current user."; } } } elseif ($this->intTransactionTypeId == 10) { if ($objNewAsset->ArchivedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already archived."; } elseif ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } } elseif ($this->intTransactionTypeId == 11) { if (!$objNewAsset->ArchivedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is not archived."; } } if (!$blnError && ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 2 || $this->intTransactionTypeId == 3 || $this->intTransactionTypeId == 8 || $this->intTransactionTypeId == 9 || $this->intTransactionTypeId == 10 || $this->intTransactionTypeId == 11)) { $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::LoadByRoleIdTransactionTypeId(QApplication::$objUserAccount->RoleId, $this->intTransactionTypeId); if ($objRoleTransactionTypeAuthorization) { // If the user has 'None' privileges for this transaction if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) { $blnError = true; $this->txtNewAssetCode->Warning = "You do not have privileges for this transaction."; } elseif ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 2 && $objNewAsset->CreatedBy != QApplication::$objUserAccount->UserAccountId) { $blnError = true; $this->txtNewAssetCode->Warning = "You are not the owner of this asset."; } } } if (!$blnError && $objNewAsset instanceof Asset) { $this->objAssetArray[] = $objNewAsset; $this->txtNewAssetCode->Text = null; // Load all linked assets $objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetIdWithNoCustomFields($objNewAsset->AssetId); if ($objLinkedAssetArray) { $strAssetCodeArray = array(); foreach ($objLinkedAssetArray as $objLinkedAsset) { $strAssetCodeArray[] = $objLinkedAsset->AssetCode; $this->objAssetArray[] = $objLinkedAsset; } $this->txtNewAssetCode->Warning = sprintf("The following asset(s) have been added to the transaction because they are locked to asset (%s):<br />%s", $objNewAsset->AssetCode, implode('<br />', $strAssetCodeArray)); } unset($objLinkedAssetArray); $this->dtgAssetTransact->Refresh(); } } if (!$blnError) { $this->txtNewAssetCode->Warning = ''; } } else { $this->txtNewAssetCode->Warning = "Please enter an asset code."; } $this->txtNewAssetCode->Focus(); $this->txtNewAssetCode->Select(); }
protected function btnMassDeleteConfirm_Click() { $this->dlgMassDelete->HideDialogBox(); $items = $this->dtgAssetModel->getSelected('AssetModelId'); $this->lblWarning->Text = ""; $arrToSkip = array(); foreach ($items as $item) { // First check that the user is authorized to edit this model $objAssetModel = AssetModel::Load($item); if (!QApplication::AuthorizeEntityBoolean($objAssetModel, 3)) { $this->lblWarning->Text = 'You are not authorized to delete one or more of the selected models.'; $this->dlgMassDelete->HideDialogBox(); return; } } // Separating items able to be deleted foreach ($items as $item) { $arrAssetAssigned = Asset::LoadArrayByAssetModelId($item); if (!$arrAssetAssigned || count($arrAssetAssigned) <= 0) { $this->arrToDelete[] = $item; } else { $arrToSkip[] = $item; } } if (count($arrToSkip) > 0) { if (count($arrToSkip) == 1) { $toBe = 'is'; $ending = ''; $skipping = 'this'; } else { $toBe = 'are'; $ending = 's'; $skipping = 'these'; } if (count($arrToSkip) == count($items)) { $this->lblWarning->Text = 'Models with assigned assets cannot be deleted.'; $this->dlgMassDelete->HideDialogBox(); return; } $intToDelete = count($items) - count($arrToSkip); $this->dlgMassDelete->Text = sprintf('<div class="title"> Model Mass Delete - %s records</div><hr/>', $intToDelete); $this->dlgMassDelete->Text .= sprintf("%s of the selected Models %s assigned to an asset and cannot be deleted.\n\t\t\t\t\t\t\t\t Would you like to continue the deletion process,\n\t\t\t\t\t\t\t\t skipping %s Model%s?<br /><br />", count($arrToSkip), $toBe, count($arrToSkip) > 1 ? $skipping . ' ' . count($arrToSkip) : $skipping, $ending); $this->btnMassDeleteConfirm->Display = false; $this->btnMassDeleteConfirmSkip->Display = true; $this->dlgMassDelete->ShowDialogBox(); } else { if (count($this->arrToDelete) > 0) { AssetModel::DeleteSelected($this->arrToDelete); $this->arrToDelete = array(); QApplication::Redirect(''); } } }
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; } }
protected function btnMassDeleteConfirm_Click() { $items = $this->ctlSearchMenu->dtgAsset->getSelected('AssetId'); $this->lblWarning->Text = ""; // TODO perform validate // Get an instance of the database $objDatabase = QApplication::$Database[1]; $blnError = false; foreach ($items as $item) { // First check that the user is authorized to delete this asset $objAsset = Asset::LoadByAssetId($item); if (!QApplication::AuthorizeEntityBoolean($objAsset, 3)) { $blnError = true; $this->lblWarning->Text = 'You are not authorized to delete one or more of the selected assets.'; $this->dlgMassDelete->HideDialogBox(); return; } } if (!$blnError) { try { // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); foreach ($items as $item) { // ParentAssetId Field must be manually deleted because MySQL ON DELETE will not cascade to them Asset::ResetParentAssetIdToNullByAssetId($item); // Delete any audit scans of this asset Asset::DeleteAuditScanByAssetId($item); // Delete the asset Asset::LoadByAssetId($item)->Delete(); } $objDatabase->TransactionCommit(); $this->UncheckAllItems($this); // Hide the dialog $this->dlgMassDelete->HideDialogBox(); } catch (QMySqliDatabaseException $objExc) { // Rollback the transaction $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } }
public function btnApply_Click($strFormId, $strControlId, $strParameter) { $this->EnableSelectedControls(); $this->ClearWarnings(); $blnError = false; // Make sure at least one checkbox is checked if (!$this->chkModel->Checked && !$this->chkParentAssetCode->Checked && !$this->chkChkLockToParent->Checked) { $blnChecked = false; foreach ($this->arrCheckboxes as $objCheckBox) { if ($objCheckBox->Checked) { $blnChecked = true; break; } } if (!$blnChecked) { $blnError = true; $this->btnCancel->Warning = 'You must select at least one field to edit.'; return; } } // If Model is checked, make sure a model is selected if ($this->chkModel->Checked && $this->lstModel->SelectedValue == null) { $blnError = true; $this->lstModel->Warning = 'You must select a Model.'; return; } // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId)); if (count($this->arrCustomFields) > 0) { $customFieldIdArray = array(); foreach ($this->arrCustomFields as $field) { if ($this->arrCheckboxes[$field['input']->strControlId]->Checked) { if ($field['input'] instanceof QTextBox && $field['input']->Required && $field['input']->Text == null || $field['input'] instanceof QListBox && $field['input']->Required && $field['input']->SelectedValue == null) { $blnError = true; $field['input']->Warning = "Required."; } else { $this->arrCustomFieldsToEdit[] = $field; $customFieldIdArray[] = (int) str_replace('cf', '', $field['input']->strControlId); } } } } foreach ($this->arrAssetToEdit as $intAssetToEditId) { $objAsset = Asset::Load($intAssetToEditId); // First check that the user is authorized to edit this asset if (!QApplication::AuthorizeEntityBoolean($objAsset, 2)) { $blnError = true; $this->btnCancel->Warning = 'You are not authorized to edit one or more of the selected assets.'; break; } if ($this->chkParentAssetCode->Checked && $this->txtParentAssetCode->Text) { // Check if the parent asset tag is already a child asset of this asset $arrChildAsset = Asset::LoadArrayByParentAssetId($intAssetToEditId); foreach ($arrChildAsset as $objChildAsset) { if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) { $blnError = true; $this->txtParentAssetCode->Warning = "Parent asset tag is already a child of this asset."; break 2; } } if ($this->txtParentAssetCode->Text != $objAsset->AssetCode) { $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text); if (!$objParentAsset) { $blnError = true; $this->txtParentAssetCode->Warning = "That asset tag does not exist."; break; } else { if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $objAsset->LocationId) { // If locking child to parent, make sure assets are at the same location $blnError = true; $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.'; break; } else { if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) { $blnError = true; $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved."; break; } else { if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && ($objAsset->CheckedOutFlag || $objAsset->ReservedFlag || $objAsset->ArchivedFlag || $objAsset->LocationId == 2 || $objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objAsset->AssetId))) { $blnError = true; $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved."; break; } else { $objAsset->ParentAssetId = $objParentAsset->AssetId; if ($this->chkLockToParent->Checked) { $objAsset->LinkedFlag = 1; } else { $objAsset->LinkedFlag = 0; } } } } } } else { $blnError = true; $this->txtParentAssetCode->Warning = "Asset cannot be assigned as its own parent."; break; } } else { if ($this->chkChkLockToParent->Checked && $this->chkLockToParent->Checked) { // Make sure assets have a parent to lock to if lock is checked and no parent being assigned $objAsset = Asset::Load($intAssetToEditId); if (!$objAsset->ParentAssetId) { $blnError = true; $this->chkLockToParent->Warning = 'Asset cannot be locked without a parent assigned.'; break; } } } } // Apply checked main_table fields if ($this->chkModel->Checked) { $set[] = sprintf('`asset_model_id`="%s"', $this->lstModel->SelectedValue); } if ($this->chkChkLockToParent->Checked) { $set[] = sprintf('`linked_flag`=%s', $this->chkLockToParent->Checked ? 1 : "NULL"); } if ($this->chkParentAssetCode->Checked) { $parent_asset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text); if ($parent_asset instanceof Asset) { $parent_asset_id = $parent_asset->AssetId; } else { $parent_asset_id = "NULL"; $set[] = sprintf('`linked_flag`=%s', "NULL"); } $set[] = sprintf('`parent_asset_id`=%s', $parent_asset_id); } // Force modified_date timestamp update $set[] = '`modified_date` = NOW()'; if (!$blnError) { try { if (count($this->arrCustomFieldsToEdit) > 0) { // preparing data to edit // Save the values from all of the custom field controls to save the asset foreach ($this->arrAssetToEdit as $intAssetId) { $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::Asset, false, null, false, 'all'); $selectedCustomFieldsArray = array(); foreach ($objCustomFieldsArray as $objCustomField) { if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) { $selectedCustomFieldsArray[] = $objCustomField; } } CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intAssetId, EntityQtype::Asset); } } // Edit TransAction // Update main table $strQuery = sprintf("UPDATE `asset`\n\t\t\t\t\t\t\tSET " . implode(",", $set) . " WHERE `asset_id` IN (%s)", implode(",", $this->arrAssetToEdit)); //print $strQuery; exit; $objDatabase->NonQuery($strQuery); $objDatabase->TransactionCommit(); QApplication::Redirect(''); } catch (QMySqliDatabaseException $objExc) { $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } else { $objDatabase->TransactionRollback(); } }
public function btnAdd_Click($strFormId, $strControlId, $strParameter) { $strAssetCode = $this->txtNewAssetCode->Text; $blnDuplicate = false; $blnError = false; if ($strAssetCode) { // Begin error checking if ($this->objAssetArray) { foreach ($this->objAssetArray as $asset) { if ($asset && $asset->AssetCode == $strAssetCode) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset has already been added."; } } } if (!$blnError) { $objNewAsset = Asset::LoadByAssetCode($this->txtNewAssetCode->Text); if (!$objNewAsset instanceof Asset) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset code does not exist."; } elseif ($objNewAsset->LocationId == 2) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset has already been shipped."; } elseif ($objNewAsset->LocationId == 5) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is currently scheduled to be received."; } elseif ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId)) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already in a pending shipment."; } elseif (!QApplication::AuthorizeEntityBoolean($objNewAsset, 2)) { $blnError = true; $this->txtNewAssetCode->Warning = "You do not have authorization to perform a transaction on this asset."; } elseif ($this->intTransactionTypeId == 1) { if ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } } elseif ($this->intTransactionTypeId == 2) { if (!$objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is not checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } elseif ($objNewAsset->CheckedOutFlag) { $objUserAccount = $objNewAsset->GetLastTransactionUser(); if ($objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset was not checked out by the current user."; } } } elseif ($this->intTransactionTypeId == 3) { if ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already checked out."; } elseif ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is reserved."; } } elseif ($this->intTransactionTypeId == 8) { if ($objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is already reserved."; } elseif ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } } elseif ($this->intTransactionTypeId == 9) { if (!$objNewAsset->ReservedFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is not reserved"; } elseif ($objNewAsset->CheckedOutFlag) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset is checked out."; } elseif ($objNewAsset->ReservedFlag) { $objUserAccount = $objNewAsset->GetLastTransactionUser(); if ($objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) { $blnError = true; $this->txtNewAssetCode->Warning = "That asset was not reserved by the current user."; } } } if (!$blnError && $objNewAsset instanceof Asset) { $this->objAssetArray[] = $objNewAsset; $this->txtNewAssetCode->Text = null; } } } else { $this->txtNewAssetCode->Warning = "Please enter an asset code."; } }
protected function btnMassDeleteConfirm_Click() { $items = $this->ctlSearchMenu->dtgInventoryModel->getSelected('InventoryModelId'); foreach ($items as $item) { // First check that the user is authorized to delete this inventory $objInventoryModel = InventoryModel::Load($item); if (!QApplication::AuthorizeEntityBoolean($objInventoryModel, 3)) { $blnError = true; $this->lblWarning->Text = 'You are not authorized to delete one or more of the selected inventory models.'; $this->dlgMassDelete->HideDialogBox(); return; } } if (count($items) > 0) { $this->lblWarning->Text = ""; // TODO perform validate foreach ($items as $item) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); InventoryModel::Load($item)->Delete(); $objDatabase->TransactionCommit(); $this->UncheckAllItems($this); // Hide the dialog $this->dlgMassDelete->HideDialogBox(); } catch (QDatabaseExceptionBase $objExc) { // Roll back the transaction from the database $objDatabase->TransactionRollback(); if ($objExc->ErrorNumber == 1451) { $this->lblWarning->Text .= 'Inventory model ' . $item . 'cannot be deleted because it is associated with one or more transactions.'; } else { throw new QDatabaseExceptionBase(); } } } } else { $this->lblWarning->Text = "You haven't chosen any Inventory to Delete"; } }