public function EnableTransactionButtons() { if ($this->blnEditMode) { if ($this->objAsset->LinkedFlag) { $this->DisableTransactionButtons(); } else { if (!$this->objAsset->ReservedFlag && !$this->objAsset->CheckedOutFlag && $this->objAsset->LocationId != 2 && $this->objAsset->LocationId != 5 && $this->objAsset->LocationId != 6 && !AssetTransaction::PendingTransaction($this->objAsset->AssetId)) { $this->btnMove->Enabled = true; $this->btnArchive->Enabled = true; } else { $this->btnMove->Enabled = false; if ($this->objAsset->ArchivedFlag) { $this->btnArchive->Enabled = true; } else { $this->btnArchive->Enabled = false; } } if (!$this->objAsset->ReservedFlag && !$this->objAsset->CheckedOutFlag && $this->objAsset->LocationId != 2 && $this->objAsset->LocationId != 5 && $this->objAsset->LocationId != 6 && !AssetTransaction::PendingTransaction($this->objAsset->AssetId)) { $this->btnCheckIn->Enabled = true; $this->btnCheckOut->Enabled = true; } elseif ($this->objAsset->CheckedOutFlag && $this->objAsset->LocationId != 6) { $objUserAccount = $this->objAsset->GetLastTransactionUser(); if (!QApplication::$TracmorSettings->StrictCheckinPolicy || $objUserAccount && $objUserAccount->UserAccountId == QApplication::$objUserAccount->UserAccountId) { $this->btnCheckIn->Enabled = true; $this->btnCheckOut->Enabled = true; } else { $this->btnCheckIn->Enabled = false; $this->btnCheckOut->Enabled = false; } } else { $this->btnCheckIn->Enabled = false; $this->btnCheckOut->Enabled = false; } if (!$this->objAsset->CheckedOutFlag && !$this->objAsset->ReservedFlag && $this->objAsset->LocationId != 2 && $this->objAsset->LocationId != 5 && $this->objAsset->LocationId != 6 && !AssetTransaction::PendingTransaction($this->objAsset->AssetId)) { $this->btnUnreserve->Enabled = true; $this->btnReserve->Enabled = true; } elseif ($this->objAsset->ReservedFlag && $this->objAsset->LocationId != 6) { $objUserAccount = $this->objAsset->GetLastTransactionUser(); if ($objUserAccount && $objUserAccount->UserAccountId == QApplication::$objUserAccount->UserAccountId) { $this->btnUnreserve->Enabled = true; $this->btnReserve->Enabled = true; } else { $this->btnUnreserve->Enabled = false; $this->btnReserve->Enabled = false; } } else { $this->btnUnreserve->Enabled = false; $this->btnReserve->Enabled = false; } if (!$this->objAsset->CheckedOutFlag && !$this->objAsset->ReservedFlag && $this->objAsset->LocationId != 6 && !AssetTransaction::PendingTransaction($this->objAsset->AssetId)) { $this->btnShip->Enabled = true; $this->btnReceive->Enabled = true; } else { $this->btnShip->Enabled = false; $this->btnReceive->Enabled = false; } } } }
protected function btnLinkToParent_Click() { $this->btnUnlink->Warning = ""; $blnError = false; $arrAssetId = $this->dtgChildAssets->GetSelected("AssetId"); if (count($arrAssetId)) { $objNewChildAssetArray = array(); // Creating the associative array with AssetId as a key foreach ($this->ctlAssetEdit->objChildAssetArray as $objChildAsset) { $objNewChildAssetArray[$objChildAsset->AssetId] = $objChildAsset; } // Foreach checked child assets foreach ($arrAssetId as $intAssetId) { // Load the object of the child asset from array by AssetId $objAsset = $objNewChildAssetArray[$intAssetId]; // Error checking if ($objAsset->LocationId != $this->objAsset->LocationId) { $blnError = true; $this->btnUnlink->Warning .= "The child asset (" . $objAsset->AssetCode . ") must be in the same location as the parent asset.<br />"; } elseif ($objAsset->CheckedOutFlag || $objAsset->ReservedFlag || $objAsset->ArchivedFlag || $objAsset->LocationId == 2 && $objAsset->LocationId == 3 || $objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objAsset->AssetId)) { $blnError = true; $this->btnUnlink->Warning .= "Child asset tag (" . $objAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.<br />"; } elseif ($this->objAsset->CheckedOutFlag || $this->objAsset->ReservedFlag || $this->objAsset->ArchivedFlag || $this->objAsset->LocationId == 2 && $this->objAsset->LocationId == 3 || $this->objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($this->objAsset->AssetId)) { $blnError = true; $this->btnUnlink->Warning .= "Parent asset tag (" . $this->objAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.<br />"; } else { $objAsset->LinkedFlag = true; $objNewChildAssetArray[$objAsset->AssetId] = $objAsset; } } if (!$blnError) { $this->ctlAssetEdit->objChildAssetArray = array(); foreach ($objNewChildAssetArray as $objChildAsset) { array_push($this->ctlAssetEdit->objChildAssetArray, $objChildAsset); } } $this->UncheckAllItems(); } else { $this->btnUnlink->Warning = "No selected assets."; } }
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(); } }