/** * Load a single AssetTransactionCheckout object, * by AssetId * @param integer $intAssetId * @return object $objAssetTransactionCheckout */ public function LoadAssetTransactionCheckoutByAssetId($intAssetId = null) { // Loads objAssetTransaction $objClauses = array(); $objOrderByClause = QQ::OrderBy(QQN::AssetTransaction()->Transaction->CreationDate, false); $objLimitClause = QQ::LimitInfo(1, 0); array_push($objClauses, $objOrderByClause); array_push($objClauses, $objLimitClause); $AssetTransactionArray = AssetTransaction::LoadArrayByAssetId($this->AssetId, $objClauses); $intLastAssetTransactionId = $AssetTransactionArray[0]->AssetTransactionId; $objAssetTransactionCheckout = AssetTransactionCheckout::LoadByAssetTransactionId($intAssetLastTransactionId); return $objAssetTransactionCheckout; }
/** * Counts all associated AssetTransactionsAsDestination * @return int */ public function CountAssetTransactionsAsDestination() { if (is_null($this->intLocationId)) { return 0; } return AssetTransaction::CountByDestinationLocationId($this->intLocationId); }
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."; } }
/** * Returns a Location object from the most recent shipment transaction for this asset * * @return Object Location */ public function GetLastShippedFromLocation() { $objCondition = QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $this->AssetId), QQ::Equal(QQN::AssetTransaction()->Transaction->TransactionTypeId, 6)); $objClauses = array(); $objExpansionClause = QQ::Expand(QQN::AssetTransaction()->SourceLocation); $objOrderByClause = QQ::OrderBy(QQN::AssetTransaction()->Transaction->CreationDate, false); $objLimitClause = QQ::LimitInfo(1, 0); array_push($objClauses, $objExpansionClause); array_push($objClauses, $objOrderByClause); array_push($objClauses, $objLimitClause); $AssetTransactionArray = AssetTransaction::QueryArray($objCondition, $objClauses); if (count($AssetTransactionArray) > 0) { $Location = $AssetTransactionArray[0]->SourceLocation; } else { $Location = null; } return $Location; }
protected function dtgShipmentReceipt_Bind() { // Get Total Count for Pagination $objClauses = array(); $this->ctlAssetEdit->dtgShipmentReceipt->TotalItemCount = AssetTransaction::CountShipmentReceiptByAssetId($this->ctlAssetEdit->objAsset->AssetId); if ($this->ctlAssetEdit->dtgShipmentReceipt->TotalItemCount === 0) { $this->ctlAssetEdit->lblShipmentReceipt->Display = false; $this->ctlAssetEdit->dtgShipmentReceipt->ShowHeader = false; } else { $objClauses = array(); if ($objClause = QQ::OrderBy(QQN::AssetTransaction()->Transaction->CreationDate, false)) { array_push($objClauses, $objClause); } if ($objClause = $this->ctlAssetEdit->dtgShipmentReceipt->LimitClause) { array_push($objClauses, $objClause); } if ($objClause = QQ::Expand(QQN::AssetTransaction()->Transaction->Shipment)) { array_push($objClauses, $objClause); } if ($objClause = QQ::Expand(QQN::AssetTransaction()->Transaction->Receipt)) { array_push($objClauses, $objClause); } if ($objClause = QQ::Expand(QQN::AssetTransaction()->SourceLocation)) { array_push($objClauses, $objClause); } if ($objClause = QQ::Expand(QQN::AssetTransaction()->DestinationLocation)) { array_push($objClauses, $objClause); } $objCondition = QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $this->ctlAssetEdit->objAsset->AssetId), QQ::OrCondition(QQ::Equal(QQN::AssetTransaction()->Transaction->TransactionTypeId, 6), QQ::Equal(QQN::AssetTransaction()->Transaction->TransactionTypeId, 7))); $this->ctlAssetEdit->dtgShipmentReceipt->DataSource = AssetTransaction::QueryArray($objCondition, $objClauses); } }
/** * Counts all associated AssetTransactionsAsNew * @return int */ public function CountAssetTransactionsAsNew() { if (is_null($this->intAssetId)) { return 0; } return AssetTransaction::CountByNewAssetId($this->intAssetId); }
if (!$blnError) { $arrPendingReceiptId = array_unique($arrPendingReceiptId); foreach ($objAssetArray as $objAsset) { $objDestinationLocation = $arrLocation[$objAsset->AssetId]; $intDestinationLocationId = $objDestinationLocation->LocationId; // Set the DestinationLocation of the AssetTransaction $objAssetTransaction = $objAssetTransactionArray[$objAsset->AssetId]; $objAssetTransaction->DestinationLocationId = $intDestinationLocationId; $objAssetTransaction->Save(); $objAsset->LocationId = $intDestinationLocationId; $objAsset->Save(); if ($objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAsset->AssetId)) { foreach ($objLinkedAssetArray as $objLinkedAsset) { $objLinkedAsset->LocationId = $intDestinationLocationId; $objLinkedAsset->Save(); if ($objChildPendingReceipt = AssetTransaction::PendingReceipt($objLinkedAsset->AssetId)) { $objChildPendingReceipt->DestinationLocationId = $intDestinationLocationId; $objChildPendingReceipt->Save(); } } } } foreach ($arrPendingReceiptId as $intReceiptId) { Receipt::ReceiptComplete($intReceiptId); } $strWarning .= "Your transaction has successfully completed<br /><a href='index.php'>Main Menu</a> | <a href='asset_menu.php'>Manage Assets</a><br />"; //Remove that flag when transaction is compelete or exists some errors unset($_SESSION['intUserAccountId']); $blnTransactionComplete = true; $arrCheckedAssetCodeLocation = ""; } else {
/** * Count AssetTransactions (excluding transactions for linked assets) * by TransactionId Index(es) * @param integer $intTransactionId * @return int */ public static function CountByTransactionIdLinkedFlag($intTransactionId) { // Call AssetTransaction::QueryCount to perform the CountByTransactionId query return AssetTransaction::QueryCount(QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->TransactionId, $intTransactionId), QQ::NotEqual(QQN::AssetTransaction()->Asset->LinkedFlag, true))); }
/** * Returns a bool that determines whether or not this transaction has any AssetTransactions or InventoryTransactions associated with it * * @return bool */ public function IsEmpty() { $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($this->TransactionId); if (empty($objAssetTransactionArray)) { $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($this->TransactionId); if (empty($objInventoryTransactionArray)) { return true; } else { return false; } } else { return false; } }
public function dtgAssetTransaction_Bind() { // Get Total Count b/c of Pagination $this->dtgAssetTransaction->TotalItemCount = AssetTransaction::CountAll(); $objClauses = array(); if ($objClause = $this->dtgAssetTransaction->OrderByClause) { array_push($objClauses, $objClause); } if ($objClause = $this->dtgAssetTransaction->LimitClause) { array_push($objClauses, $objClause); } $this->dtgAssetTransaction->DataSource = AssetTransaction::LoadAll($objClauses); }
/** * Internally called method to assist with early binding of objects * on load methods. Can only early-bind references that this class owns in the database. * @param string $strParentAlias the alias of the parent (if any) * @param string $strAlias the alias of this object * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion) */ public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion) { if ($strAlias) { $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `asset_transaction_checkout` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`asset_transaction_checkout_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_transaction_checkout_id` AS `%s__%s__asset_transaction_checkout_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_transaction_id` AS `%s__%s__asset_transaction_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`to_contact_id` AS `%s__%s__to_contact_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`to_user_id` AS `%s__%s__to_user_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`due_date` AS `%s__%s__due_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`created_by` AS `%s__%s__created_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`creation_date` AS `%s__%s__creation_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_by` AS `%s__%s__modified_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_date` AS `%s__%s__modified_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $strParentAlias = $strParentAlias . '__' . $strAlias; } if (is_array($objExpansionMap)) { foreach ($objExpansionMap as $strKey => $objValue) { switch ($strKey) { case 'asset_transaction_id': try { AssetTransaction::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'to_contact_id': try { Contact::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'to_user_id': try { UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'created_by': try { UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'modified_by': try { UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } default: throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey)); } } } }
protected function btnSave_Click($strFormId, $strControlId, $strParameter) { $blnError = false; if ($this->objAssetTransactionArray && $this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::AssetInventory; } elseif ($this->objAssetTransactionArray) { $intEntityQtypeId = EntityQtype::Asset; } elseif ($this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::Inventory; } else { $blnError = true; $this->btnCancel->Warning = 'There are no assets or inventory in this shipment.'; } if (QApplication::$TracmorSettings->CustomShipmentNumbers) { if ($objShipment = Shipment::LoadByShipmentNumber($this->txtShipmentNumber->Text)) { if ($objShipment->ShipmentId != $this->objShipment->ShipmentId) { $blnError = true; $this->txtShipmentNumber->Warning = 'That is a duplicate shipment number.'; } } } if ($this->lstFxServiceType->SelectedValue) { $objtoFxAddress = Address::Load($this->lstToAddress->SelectedValue); if (!$objtoFxAddress || !$objtoFxAddress->PostalCode || !$objtoFxAddress->CountryId || !$objtoFxAddress->Address1) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid To Address."; } $objfromFxAddress = Address::Load($this->lstFromAddress->SelectedValue); if (!$objfromFxAddress || !$objfromFxAddress->PostalCode || !$objfromFxAddress->Address1 || !$objfromFxAddress->CountryId) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Address."; } $objfromFxContact = Contact::Load($this->lstFromContact->SelectedValue); if (!$objfromFxContact) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Contact."; } $objfromFxCompany = Company::Load($this->lstFromCompany->SelectedValue); if (!$objfromFxCompany) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Company."; } elseif (!$objfromFxCompany->Telephone) { $blnError = true; $this->lstFxServiceType->Warning = "The Shipping Company must have a telephone number."; } $objShippingAccount = ShippingAccount::Load($this->lstShippingAccount->SelectedValue); if (!$objShippingAccount) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid Shipping Account."; } /* $fed = new FedExDC($objShippingAccount->Value); $aRet = $fed->subscribe( array( 1 => $this->lblShipmentNumber->Text, // Don't really need this but can be used for ref 4003 => $objfromFxContact->__toString(), 4008 => $objfromFxAddress->Address1, 4009 => $objfromFxAddress->Address2, 4011 => $objfromFxAddress->City, 4012 => $objfromFxAddress->__toStringStateProvinceAbbreviation(), 4013 => $objfromFxAddress->PostalCode, 4014 => $objfromFxAddress->__toStringCountryAbbreviation(), 4015 => $this->FxStrip($objfromFxCompany->Telephone), ) ); if ($error = $fed->getError()) { $blnError = true; $this->lstFxServiceType->Warning = $error; } elseif (!$aRet[498]) { $blnError = true; $this->lstFxServiceType->Warning = "Fedex response is improperly formed."; } else { $this->objShipment->FedexMeterNumber = $aRet[498]; }*/ } if (!$blnError) { if (!$this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); // Create the new transaction object and save it $this->objTransaction = new Transaction(); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->TransactionTypeId = 6; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) { // Assign different source and destinations depending on transaction type foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->Asset instanceof Asset) { // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Assign the TransactionId $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Create the new asset if it was scheduled for receipt if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; //if ($objReceiptAsset->AssetCode == '') { if ($objAssetTransaction->NewAsset->AssetCode == '') { $objReceiptAsset->AssetCode = Asset::GenerateAssetCode(); } else { $objReceiptAsset->AssetCode = $objAssetTransaction->NewAsset->AssetCode; } $objReceiptAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objReceiptAsset->AssetId); // Associate the new Asset with the AssetTransaction $objAssetTransaction->NewAsset = $objReceiptAsset; } // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; $objAssetTransaction->Save(); /*$objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId); if ($objLinkedAssetArray) { foreach ($objLinkedAssetArray as $objLinkedAsset) { $objLinkedAssetTransaction = new AssetTransaction(); $objLinkedAssetTransaction->AssetId = $objLinkedAsset->AssetId; $objLinkedAssetTransaction->SourceLocationId = $objLinkedAsset->LocationId; $objLinkedAssetTransaction->TransactionId = $objAssetTransaction->TransactionId; $objLinkedAssetTransaction->Save(); } }*/ } } } if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) { // Assign different source and destinations depending on transaction type foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // Assign the TransactionId $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; $objInventoryTransaction->Save(); } } $this->UpdateShipmentFields(); $this->objShipment->ShippedFlag = false; $this->objShipment->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objShipment->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objShipment->ShipmentId, 10); } // If the courier is FedEx, create new fedexShipment if ($this->lstCourier->SelectedValue === 1) { $this->objFedexShipment = new FedexShipment(); $this->objFedexShipment->Shipment = $this->objShipment; $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } $objDatabase->TransactionCommit(); QApplication::Redirect('shipment_list.php'); } catch (QExtendedOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); if ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } if ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } elseif ($this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); $this->objTransaction = Transaction::Load($this->objShipment->TransactionId); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Remove AssetTransactions that were removed when editing if ($this->arrAssetTransactionToDelete) { foreach ($this->arrAssetTransactionToDelete as $intAssetTransactionId) { $objAssetTransactionToDelete = AssetTransaction::Load($intAssetTransactionId); // Make sure that it wasn't added and then removed if ($objAssetTransactionToDelete) { // Change back location $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId; $objAssetTransactionToDelete->Asset->Save(); // Delete the asset that was created for a new receipt if ($objAssetTransactionToDelete->NewAsset && $objAssetTransactionToDelete->NewAsset instanceof Asset && $objAssetTransactionToDelete->ScheduleReceiptFlag) { $objAssetTransactionToDelete->NewAsset->Delete(); } // Delete the asset transaction $objAssetTransactionToDelete->Delete(); unset($objAssetTransactionToDelete); } } } // Save new AssetTransactions if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { // If the AssetTransaction has not been saved if (!$objAssetTransaction->AssetTransactionId) { $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Create the new asset if it was scheduled for receipt // $DestinationLocationId = 2; // Shipped // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; // $objAssetTransaction->Asset->LocationId = $DestinationLocationId; // $objAssetTransaction->Asset->Save(); } if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset && !$objAssetTransaction->NewAssetId) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; if ($objAssetTransaction->NewAsset->AssetCode == '') { $objReceiptAsset->AssetCode = Asset::GenerateAssetCode(); } else { $objReceiptAsset->AssetCode = $objAssetTransaction->NewAsset->AssetCode; } $objReceiptAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objReceiptAsset->AssetId); // Associate the new Asset with the AssetTransaction $objAssetTransaction->NewAsset = $objReceiptAsset; } $objAssetTransaction->Save(); } } // Remove InventoryTransactions if ($this->arrInventoryTransactionToDelete) { foreach ($this->arrInventoryTransactionToDelete as $intInventoryTransactionId) { $objInventoryTransactionToDelete = InventoryTransaction::Load($intInventoryTransactionId); // Make sure that it wasn't added then removed if ($objInventoryTransactionToDelete) { // Change back the quantity $objInventoryTransactionToDelete->InventoryLocation->Quantity += $objInventoryTransactionToDelete->Quantity; $objInventoryTransactionToDelete->InventoryLocation->Save(); // Delete the InventoryTransaction $objInventoryTransactionToDelete->Delete(); unset($objInventoryTransactionToDelete); } } } // Save InventoryTransactions if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->InventoryTransactionId) { // Reload the InventoryLocation. If it was deleted and added in the same save click, then it will throw an Optimistic Locking Exception $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId); $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // $DestinationLocationId = 2; // Shipped // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; // $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity; // $objInventoryTransaction->InventoryLocation->Save(); $objInventoryTransaction->Save(); } } } $this->UpdateShipmentFields(); // $this->objShipment->Save(false, true); $this->objShipment->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objShipment->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objShipment->ShipmentId, 10); } // If the courier is FedEx, save the fedexShipment if ($this->lstCourier->SelectedValue === 1) { if ($this->objFedexShipment) { // FedexShipment already exists, so update it $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } else { // FedexShipment doesn't exist yet, so create it $this->objFedexShipment = new FedexShipment(); $this->objFedexShipment->Shipment = $this->objShipment; $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } } else { if ($this->objFedexShipment) { // FedexShipment exists - delete it because the selected courier is no longer FedEx $this->objFedexShipment->Delete(); $this->objFedexShipment = null; } } $objDatabase->TransactionCommit(); $this->UpdateShipmentLabels(); $this->SetupShipment(); $this->DisplayLabels(); if ($this->objShipment->CourierId == 1) { $this->txtTrackingNumber->Enabled = false; $this->lstPackageType->Enabled = true; } else { $this->txtTrackingNumber->Enabled = true; $this->lstPackageType->Enabled = false; } // Reload lstPackageType $this->lstPackageType->RemoveAllItems(); $this->LoadPackageTypes(); } catch (QExtendedOptimisticLockingException $objExc) { $objDatabase->TransactionRollback(); if ($objExc->Class == 'Shipment') { $this->btnCancel->Warning = sprintf('This shipment has been modified by another user. You must <a href="shipment_edit.php?intShipmentId=%s">Refresh</a> to edit this shipment.', $this->objShipment->ShipmentId); } elseif ($objExc->Class == 'Asset') { //$this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } elseif ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } } }
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 static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) { if ($objObject->objAsset) { $objObject->objAsset = Asset::GetSoapObjectFromObject($objObject->objAsset, false); } else { if (!$blnBindRelatedObjects) { $objObject->intAssetId = null; } } if ($objObject->objTransaction) { $objObject->objTransaction = Transaction::GetSoapObjectFromObject($objObject->objTransaction, false); } else { if (!$blnBindRelatedObjects) { $objObject->intTransactionId = null; } } if ($objObject->objParentAssetTransaction) { $objObject->objParentAssetTransaction = AssetTransaction::GetSoapObjectFromObject($objObject->objParentAssetTransaction, false); } else { if (!$blnBindRelatedObjects) { $objObject->intParentAssetTransactionId = null; } } if ($objObject->objSourceLocation) { $objObject->objSourceLocation = Location::GetSoapObjectFromObject($objObject->objSourceLocation, false); } else { if (!$blnBindRelatedObjects) { $objObject->intSourceLocationId = null; } } if ($objObject->objDestinationLocation) { $objObject->objDestinationLocation = Location::GetSoapObjectFromObject($objObject->objDestinationLocation, false); } else { if (!$blnBindRelatedObjects) { $objObject->intDestinationLocationId = null; } } if ($objObject->objNewAsset) { $objObject->objNewAsset = Asset::GetSoapObjectFromObject($objObject->objNewAsset, false); } else { if (!$blnBindRelatedObjects) { $objObject->intNewAssetId = null; } } if ($objObject->dttScheduleReceiptDueDate) { $objObject->dttScheduleReceiptDueDate = $objObject->dttScheduleReceiptDueDate->__toString(QDateTime::FormatSoap); } if ($objObject->objCreatedByObject) { $objObject->objCreatedByObject = UserAccount::GetSoapObjectFromObject($objObject->objCreatedByObject, false); } else { if (!$blnBindRelatedObjects) { $objObject->intCreatedBy = null; } } if ($objObject->dttCreationDate) { $objObject->dttCreationDate = $objObject->dttCreationDate->__toString(QDateTime::FormatSoap); } if ($objObject->objModifiedByObject) { $objObject->objModifiedByObject = UserAccount::GetSoapObjectFromObject($objObject->objModifiedByObject, false); } else { if (!$blnBindRelatedObjects) { $objObject->intModifiedBy = null; } } return $objObject; }
/** * Refresh this MetaControl with Data from the local AssetTransactionCheckout object. * @param boolean $blnReload reload AssetTransactionCheckout from the database * @return void */ public function Refresh($blnReload = false) { if ($blnReload) { $this->objAssetTransactionCheckout->Reload(); } if ($this->lblAssetTransactionCheckoutId) { if ($this->blnEditMode) { $this->lblAssetTransactionCheckoutId->Text = $this->objAssetTransactionCheckout->AssetTransactionCheckoutId; } } if ($this->lstAssetTransaction) { $this->lstAssetTransaction->RemoveAllItems(); if (!$this->blnEditMode) { $this->lstAssetTransaction->AddItem(QApplication::Translate('- Select One -'), null); } $objAssetTransactionArray = AssetTransaction::LoadAll(); if ($objAssetTransactionArray) { foreach ($objAssetTransactionArray as $objAssetTransaction) { $objListItem = new QListItem($objAssetTransaction->__toString(), $objAssetTransaction->AssetTransactionId); if ($this->objAssetTransactionCheckout->AssetTransaction && $this->objAssetTransactionCheckout->AssetTransaction->AssetTransactionId == $objAssetTransaction->AssetTransactionId) { $objListItem->Selected = true; } $this->lstAssetTransaction->AddItem($objListItem); } } } if ($this->lblAssetTransactionId) { $this->lblAssetTransactionId->Text = $this->objAssetTransactionCheckout->AssetTransaction ? $this->objAssetTransactionCheckout->AssetTransaction->__toString() : null; } if ($this->lstToContact) { $this->lstToContact->RemoveAllItems(); $this->lstToContact->AddItem(QApplication::Translate('- Select One -'), null); $objToContactArray = Contact::LoadAll(); if ($objToContactArray) { foreach ($objToContactArray as $objToContact) { $objListItem = new QListItem($objToContact->__toString(), $objToContact->ContactId); if ($this->objAssetTransactionCheckout->ToContact && $this->objAssetTransactionCheckout->ToContact->ContactId == $objToContact->ContactId) { $objListItem->Selected = true; } $this->lstToContact->AddItem($objListItem); } } } if ($this->lblToContactId) { $this->lblToContactId->Text = $this->objAssetTransactionCheckout->ToContact ? $this->objAssetTransactionCheckout->ToContact->__toString() : null; } if ($this->lstToUser) { $this->lstToUser->RemoveAllItems(); $this->lstToUser->AddItem(QApplication::Translate('- Select One -'), null); $objToUserArray = UserAccount::LoadAll(); if ($objToUserArray) { foreach ($objToUserArray as $objToUser) { $objListItem = new QListItem($objToUser->__toString(), $objToUser->UserAccountId); if ($this->objAssetTransactionCheckout->ToUser && $this->objAssetTransactionCheckout->ToUser->UserAccountId == $objToUser->UserAccountId) { $objListItem->Selected = true; } $this->lstToUser->AddItem($objListItem); } } } if ($this->lblToUserId) { $this->lblToUserId->Text = $this->objAssetTransactionCheckout->ToUser ? $this->objAssetTransactionCheckout->ToUser->__toString() : null; } if ($this->calDueDate) { $this->calDueDate->DateTime = $this->objAssetTransactionCheckout->DueDate; } if ($this->lblDueDate) { $this->lblDueDate->Text = sprintf($this->objAssetTransactionCheckout->DueDate) ? $this->objAssetTransactionCheckout->__toString($this->strDueDateDateTimeFormat) : null; } if ($this->lstCreatedByObject) { $this->lstCreatedByObject->RemoveAllItems(); $this->lstCreatedByObject->AddItem(QApplication::Translate('- Select One -'), null); $objCreatedByObjectArray = UserAccount::LoadAll(); if ($objCreatedByObjectArray) { foreach ($objCreatedByObjectArray as $objCreatedByObject) { $objListItem = new QListItem($objCreatedByObject->__toString(), $objCreatedByObject->UserAccountId); if ($this->objAssetTransactionCheckout->CreatedByObject && $this->objAssetTransactionCheckout->CreatedByObject->UserAccountId == $objCreatedByObject->UserAccountId) { $objListItem->Selected = true; } $this->lstCreatedByObject->AddItem($objListItem); } } } if ($this->lblCreatedBy) { $this->lblCreatedBy->Text = $this->objAssetTransactionCheckout->CreatedByObject ? $this->objAssetTransactionCheckout->CreatedByObject->__toString() : null; } if ($this->calCreationDate) { $this->calCreationDate->DateTime = $this->objAssetTransactionCheckout->CreationDate; } if ($this->lblCreationDate) { $this->lblCreationDate->Text = sprintf($this->objAssetTransactionCheckout->CreationDate) ? $this->objAssetTransactionCheckout->__toString($this->strCreationDateDateTimeFormat) : null; } if ($this->lstModifiedByObject) { $this->lstModifiedByObject->RemoveAllItems(); $this->lstModifiedByObject->AddItem(QApplication::Translate('- Select One -'), null); $objModifiedByObjectArray = UserAccount::LoadAll(); if ($objModifiedByObjectArray) { foreach ($objModifiedByObjectArray as $objModifiedByObject) { $objListItem = new QListItem($objModifiedByObject->__toString(), $objModifiedByObject->UserAccountId); if ($this->objAssetTransactionCheckout->ModifiedByObject && $this->objAssetTransactionCheckout->ModifiedByObject->UserAccountId == $objModifiedByObject->UserAccountId) { $objListItem->Selected = true; } $this->lstModifiedByObject->AddItem($objListItem); } } } if ($this->lblModifiedBy) { $this->lblModifiedBy->Text = $this->objAssetTransactionCheckout->ModifiedByObject ? $this->objAssetTransactionCheckout->ModifiedByObject->__toString() : null; } if ($this->lblModifiedDate) { if ($this->blnEditMode) { $this->lblModifiedDate->Text = $this->objAssetTransactionCheckout->ModifiedDate; } } }
/** * Counts all associated AssetTransactions * @return int */ public function CountAssetTransactions() { if (is_null($this->intTransactionId)) { return 0; } return AssetTransaction::CountByTransactionId($this->intTransactionId); }
/** * Deletes all associated AssetTransactionsAsDestination * @return void */ public function DeleteAllAssetTransactionsAsDestination() { if (is_null($this->intLocationId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAssetTransactionAsDestination on this unsaved Location.'); } // Get the Database Object for this Class $objDatabase = Location::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (AssetTransaction::LoadArrayByDestinationLocationId($this->intLocationId) as $objAssetTransaction) { $objAssetTransaction->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `asset_transaction` WHERE `destination_location_id` = ' . $objDatabase->SqlVariable($this->intLocationId) . ' '); }
/** * Refresh this MetaControl with Data from the local AssetTransaction object. * @param boolean $blnReload reload AssetTransaction from the database * @return void */ public function Refresh($blnReload = false) { if ($blnReload) { $this->objAssetTransaction->Reload(); } if ($this->lblAssetTransactionId) { if ($this->blnEditMode) { $this->lblAssetTransactionId->Text = $this->objAssetTransaction->AssetTransactionId; } } if ($this->lstAsset) { $this->lstAsset->RemoveAllItems(); if (!$this->blnEditMode) { $this->lstAsset->AddItem(QApplication::Translate('- Select One -'), null); } $objAssetArray = Asset::LoadAll(); if ($objAssetArray) { foreach ($objAssetArray as $objAsset) { $objListItem = new QListItem($objAsset->__toString(), $objAsset->AssetId); if ($this->objAssetTransaction->Asset && $this->objAssetTransaction->Asset->AssetId == $objAsset->AssetId) { $objListItem->Selected = true; } $this->lstAsset->AddItem($objListItem); } } } if ($this->lblAssetId) { $this->lblAssetId->Text = $this->objAssetTransaction->Asset ? $this->objAssetTransaction->Asset->__toString() : null; } if ($this->lstTransaction) { $this->lstTransaction->RemoveAllItems(); if (!$this->blnEditMode) { $this->lstTransaction->AddItem(QApplication::Translate('- Select One -'), null); } $objTransactionArray = Transaction::LoadAll(); if ($objTransactionArray) { foreach ($objTransactionArray as $objTransaction) { $objListItem = new QListItem($objTransaction->__toString(), $objTransaction->TransactionId); if ($this->objAssetTransaction->Transaction && $this->objAssetTransaction->Transaction->TransactionId == $objTransaction->TransactionId) { $objListItem->Selected = true; } $this->lstTransaction->AddItem($objListItem); } } } if ($this->lblTransactionId) { $this->lblTransactionId->Text = $this->objAssetTransaction->Transaction ? $this->objAssetTransaction->Transaction->__toString() : null; } if ($this->lstParentAssetTransaction) { $this->lstParentAssetTransaction->RemoveAllItems(); $this->lstParentAssetTransaction->AddItem(QApplication::Translate('- Select One -'), null); $objParentAssetTransactionArray = AssetTransaction::LoadAll(); if ($objParentAssetTransactionArray) { foreach ($objParentAssetTransactionArray as $objParentAssetTransaction) { $objListItem = new QListItem($objParentAssetTransaction->__toString(), $objParentAssetTransaction->AssetTransactionId); if ($this->objAssetTransaction->ParentAssetTransaction && $this->objAssetTransaction->ParentAssetTransaction->AssetTransactionId == $objParentAssetTransaction->AssetTransactionId) { $objListItem->Selected = true; } $this->lstParentAssetTransaction->AddItem($objListItem); } } } if ($this->lblParentAssetTransactionId) { $this->lblParentAssetTransactionId->Text = $this->objAssetTransaction->ParentAssetTransaction ? $this->objAssetTransaction->ParentAssetTransaction->__toString() : null; } if ($this->lstSourceLocation) { $this->lstSourceLocation->RemoveAllItems(); $this->lstSourceLocation->AddItem(QApplication::Translate('- Select One -'), null); $objSourceLocationArray = Location::LoadAll(); if ($objSourceLocationArray) { foreach ($objSourceLocationArray as $objSourceLocation) { $objListItem = new QListItem($objSourceLocation->__toString(), $objSourceLocation->LocationId); if ($this->objAssetTransaction->SourceLocation && $this->objAssetTransaction->SourceLocation->LocationId == $objSourceLocation->LocationId) { $objListItem->Selected = true; } $this->lstSourceLocation->AddItem($objListItem); } } } if ($this->lblSourceLocationId) { $this->lblSourceLocationId->Text = $this->objAssetTransaction->SourceLocation ? $this->objAssetTransaction->SourceLocation->__toString() : null; } if ($this->lstDestinationLocation) { $this->lstDestinationLocation->RemoveAllItems(); $this->lstDestinationLocation->AddItem(QApplication::Translate('- Select One -'), null); $objDestinationLocationArray = Location::LoadAll(); if ($objDestinationLocationArray) { foreach ($objDestinationLocationArray as $objDestinationLocation) { $objListItem = new QListItem($objDestinationLocation->__toString(), $objDestinationLocation->LocationId); if ($this->objAssetTransaction->DestinationLocation && $this->objAssetTransaction->DestinationLocation->LocationId == $objDestinationLocation->LocationId) { $objListItem->Selected = true; } $this->lstDestinationLocation->AddItem($objListItem); } } } if ($this->lblDestinationLocationId) { $this->lblDestinationLocationId->Text = $this->objAssetTransaction->DestinationLocation ? $this->objAssetTransaction->DestinationLocation->__toString() : null; } if ($this->chkNewAssetFlag) { $this->chkNewAssetFlag->Checked = $this->objAssetTransaction->NewAssetFlag; } if ($this->lblNewAssetFlag) { $this->lblNewAssetFlag->Text = $this->objAssetTransaction->NewAssetFlag ? QApplication::Translate('Yes') : QApplication::Translate('No'); } if ($this->lstNewAsset) { $this->lstNewAsset->RemoveAllItems(); $this->lstNewAsset->AddItem(QApplication::Translate('- Select One -'), null); $objNewAssetArray = Asset::LoadAll(); if ($objNewAssetArray) { foreach ($objNewAssetArray as $objNewAsset) { $objListItem = new QListItem($objNewAsset->__toString(), $objNewAsset->AssetId); if ($this->objAssetTransaction->NewAsset && $this->objAssetTransaction->NewAsset->AssetId == $objNewAsset->AssetId) { $objListItem->Selected = true; } $this->lstNewAsset->AddItem($objListItem); } } } if ($this->lblNewAssetId) { $this->lblNewAssetId->Text = $this->objAssetTransaction->NewAsset ? $this->objAssetTransaction->NewAsset->__toString() : null; } if ($this->chkScheduleReceiptFlag) { $this->chkScheduleReceiptFlag->Checked = $this->objAssetTransaction->ScheduleReceiptFlag; } if ($this->lblScheduleReceiptFlag) { $this->lblScheduleReceiptFlag->Text = $this->objAssetTransaction->ScheduleReceiptFlag ? QApplication::Translate('Yes') : QApplication::Translate('No'); } if ($this->calScheduleReceiptDueDate) { $this->calScheduleReceiptDueDate->DateTime = $this->objAssetTransaction->ScheduleReceiptDueDate; } if ($this->lblScheduleReceiptDueDate) { $this->lblScheduleReceiptDueDate->Text = sprintf($this->objAssetTransaction->ScheduleReceiptDueDate) ? $this->objAssetTransaction->__toString($this->strScheduleReceiptDueDateDateTimeFormat) : null; } if ($this->lstCreatedByObject) { $this->lstCreatedByObject->RemoveAllItems(); $this->lstCreatedByObject->AddItem(QApplication::Translate('- Select One -'), null); $objCreatedByObjectArray = UserAccount::LoadAll(); if ($objCreatedByObjectArray) { foreach ($objCreatedByObjectArray as $objCreatedByObject) { $objListItem = new QListItem($objCreatedByObject->__toString(), $objCreatedByObject->UserAccountId); if ($this->objAssetTransaction->CreatedByObject && $this->objAssetTransaction->CreatedByObject->UserAccountId == $objCreatedByObject->UserAccountId) { $objListItem->Selected = true; } $this->lstCreatedByObject->AddItem($objListItem); } } } if ($this->lblCreatedBy) { $this->lblCreatedBy->Text = $this->objAssetTransaction->CreatedByObject ? $this->objAssetTransaction->CreatedByObject->__toString() : null; } if ($this->calCreationDate) { $this->calCreationDate->DateTime = $this->objAssetTransaction->CreationDate; } if ($this->lblCreationDate) { $this->lblCreationDate->Text = sprintf($this->objAssetTransaction->CreationDate) ? $this->objAssetTransaction->__toString($this->strCreationDateDateTimeFormat) : null; } if ($this->lstModifiedByObject) { $this->lstModifiedByObject->RemoveAllItems(); $this->lstModifiedByObject->AddItem(QApplication::Translate('- Select One -'), null); $objModifiedByObjectArray = UserAccount::LoadAll(); if ($objModifiedByObjectArray) { foreach ($objModifiedByObjectArray as $objModifiedByObject) { $objListItem = new QListItem($objModifiedByObject->__toString(), $objModifiedByObject->UserAccountId); if ($this->objAssetTransaction->ModifiedByObject && $this->objAssetTransaction->ModifiedByObject->UserAccountId == $objModifiedByObject->UserAccountId) { $objListItem->Selected = true; } $this->lstModifiedByObject->AddItem($objListItem); } } } if ($this->lblModifiedBy) { $this->lblModifiedBy->Text = $this->objAssetTransaction->ModifiedByObject ? $this->objAssetTransaction->ModifiedByObject->__toString() : null; } if ($this->lblModifiedDate) { if ($this->blnEditMode) { $this->lblModifiedDate->Text = $this->objAssetTransaction->ModifiedDate; } } if ($this->lstAssetTransactionCheckout) { $this->lstAssetTransactionCheckout->RemoveAllItems(); $this->lstAssetTransactionCheckout->AddItem(QApplication::Translate('- Select One -'), null); $objAssetTransactionCheckoutArray = AssetTransactionCheckout::LoadAll(); if ($objAssetTransactionCheckoutArray) { foreach ($objAssetTransactionCheckoutArray as $objAssetTransactionCheckout) { $objListItem = new QListItem($objAssetTransactionCheckout->__toString(), $objAssetTransactionCheckout->AssetTransactionCheckoutId); if ($objAssetTransactionCheckout->AssetTransactionId == $this->objAssetTransaction->AssetTransactionId) { $objListItem->Selected = true; } $this->lstAssetTransactionCheckout->AddItem($objListItem); } } // Because AssetTransactionCheckout's AssetTransactionCheckout is not null, if a value is already selected, it cannot be changed. if ($this->lstAssetTransactionCheckout->SelectedValue) { $this->lstAssetTransactionCheckout->Enabled = false; } else { $this->lstAssetTransactionCheckout->Enabled = true; } } if ($this->lblAssetTransactionCheckout) { $this->lblAssetTransactionCheckout->Text = $this->objAssetTransaction->AssetTransactionCheckout ? $this->objAssetTransaction->AssetTransactionCheckout->__toString() : null; } }
protected function btnSave_Click($strFormId, $strControlId, $strParameter) { $blnError = false; if ($this->objAssetTransactionArray && $this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::AssetInventory; } elseif ($this->objAssetTransactionArray) { $intEntityQtypeId = EntityQtype::Asset; } elseif ($this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::Inventory; } else { $blnError = true; $this->btnCancel->Warning = 'There are no assets or inventory in this shipment.'; } if (QApplication::$TracmorSettings->CustomShipmentNumbers) { if ($objShipment = Shipment::LoadByShipmentNumber($this->txtShipmentNumber->Text)) { if ($objShipment->ShipmentId != $this->objShipment->ShipmentId) { $blnError = true; $this->txtShipmentNumber->Warning = 'That is a duplicate shipment number.'; } } } if (!$blnError) { if (!$this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); // Create the new transaction object and save it $this->objTransaction = new Transaction(); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->TransactionTypeId = 6; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) { // Assign different source and destinations depending on transaction type foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->Asset instanceof Asset) { // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Assign the TransactionId $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Create the new asset if it was scheduled for receipt if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; //if ($objReceiptAsset->AssetCode == '') { if ($objAssetTransaction->NewAsset->AssetCode == '') { $objReceiptAsset->AssetCode = Asset::GenerateAssetCode(); } else { $objReceiptAsset->AssetCode = $objAssetTransaction->NewAsset->AssetCode; } $objReceiptAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objReceiptAsset->AssetId); // Associate the new Asset with the AssetTransaction $objAssetTransaction->NewAsset = $objReceiptAsset; } // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; $objAssetTransaction->Save(); /*$objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId); if ($objLinkedAssetArray) { foreach ($objLinkedAssetArray as $objLinkedAsset) { $objLinkedAssetTransaction = new AssetTransaction(); $objLinkedAssetTransaction->AssetId = $objLinkedAsset->AssetId; $objLinkedAssetTransaction->SourceLocationId = $objLinkedAsset->LocationId; $objLinkedAssetTransaction->TransactionId = $objAssetTransaction->TransactionId; $objLinkedAssetTransaction->Save(); } }*/ } } } if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) { // Assign different source and destinations depending on transaction type foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // Assign the TransactionId $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; $objInventoryTransaction->Save(); } } $this->UpdateShipmentFields(); $this->objShipment->ShippedFlag = false; $this->objShipment->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objShipment->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objShipment->ShipmentId, 10); } $objDatabase->TransactionCommit(); QApplication::Redirect('shipment_list.php'); } catch (QExtendedOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); if ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } if ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } elseif ($this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); $this->objTransaction = Transaction::Load($this->objShipment->TransactionId); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Remove AssetTransactions that were removed when editing if ($this->arrAssetTransactionToDelete) { foreach ($this->arrAssetTransactionToDelete as $intAssetTransactionId) { $objAssetTransactionToDelete = AssetTransaction::Load($intAssetTransactionId); // Make sure that it wasn't added and then removed if ($objAssetTransactionToDelete) { // Change back location $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId; $objAssetTransactionToDelete->Asset->Save(); // Delete the asset that was created for a new receipt if ($objAssetTransactionToDelete->NewAsset && $objAssetTransactionToDelete->NewAsset instanceof Asset && $objAssetTransactionToDelete->ScheduleReceiptFlag) { $objAssetTransactionToDelete->NewAsset->Delete(); } // Delete the asset transaction $objAssetTransactionToDelete->Delete(); unset($objAssetTransactionToDelete); } } } // Save new AssetTransactions if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { // If the AssetTransaction has not been saved if (!$objAssetTransaction->AssetTransactionId) { $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Create the new asset if it was scheduled for receipt // $DestinationLocationId = 2; // Shipped // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; // $objAssetTransaction->Asset->LocationId = $DestinationLocationId; // $objAssetTransaction->Asset->Save(); } if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset && !$objAssetTransaction->NewAssetId) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; if ($objAssetTransaction->NewAsset->AssetCode == '') { $objReceiptAsset->AssetCode = Asset::GenerateAssetCode(); } else { $objReceiptAsset->AssetCode = $objAssetTransaction->NewAsset->AssetCode; } $objReceiptAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objReceiptAsset->AssetId); // Associate the new Asset with the AssetTransaction $objAssetTransaction->NewAsset = $objReceiptAsset; } $objAssetTransaction->Save(); } } // Remove InventoryTransactions if ($this->arrInventoryTransactionToDelete) { foreach ($this->arrInventoryTransactionToDelete as $intInventoryTransactionId) { $objInventoryTransactionToDelete = InventoryTransaction::Load($intInventoryTransactionId); // Make sure that it wasn't added then removed if ($objInventoryTransactionToDelete) { // Change back the quantity //$objInventoryTransactionToDelete->InventoryLocation->Quantity += $objInventoryTransactionToDelete->Quantity; //$objInventoryTransactionToDelete->InventoryLocation->Save(); // Delete the InventoryTransaction $objInventoryTransactionToDelete->Delete(); unset($objInventoryTransactionToDelete); } } } // Save InventoryTransactions if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->InventoryTransactionId) { // Reload the InventoryLocation. If it was deleted and added in the same save click, then it will throw an Optimistic Locking Exception $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId); $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // $DestinationLocationId = 2; // Shipped // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; // $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity; // $objInventoryTransaction->InventoryLocation->Save(); $objInventoryTransaction->Save(); } } } $this->UpdateShipmentFields(); // $this->objShipment->Save(false, true); $this->objShipment->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objShipment->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objShipment->ShipmentId, 10); } $objDatabase->TransactionCommit(); //$this->UpdateShipmentLabels(); //$this->SetupShipment(); //$this->DisplayLabels(); //$this->txtTrackingNumber->Enabled = true; QApplication::Redirect('shipment_edit.php?intShipmentId=' . $this->objShipment->ShipmentId); } catch (QExtendedOptimisticLockingException $objExc) { $objDatabase->TransactionRollback(); if ($objExc->Class == 'Shipment') { $this->btnCancel->Warning = sprintf('This shipment has been modified by another user. You must <a href="shipment_edit.php?intShipmentId=%s">Refresh</a> to edit this shipment.', $this->objShipment->ShipmentId); } elseif ($objExc->Class == 'Asset') { //$this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } elseif ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } } }
public function receiptDelete(Receipt $receipt) { $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($receipt->TransactionId); $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($receipt->TransactionId); // Take out the inventory from the TBR InventoryLocation if ($objInventoryTransactionArray) { foreach ($objInventoryTransactionArray as $objInventoryTransaction) { $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity; $objInventoryTransaction->InventoryLocation->Save(); } } // Delete any assets that were created while scheduling this receipt if ($objAssetTransactionArray) { foreach ($objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->NewAssetFlag) { $objAssetTransaction->Asset->Delete(); } } } // Load the Transaction $objTransaction = Transaction::Load($receipt->TransactionId); // Delete the Transaction Object and let it MySQL CASCADE down to asset_transaction, inventory_transaction, and receipt $objTransaction->Delete(); }
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(); }
/** * Count AssetTransactions * by AssetId Index(es), but only those transactions that are Shipments or Receipts * @param integer $intAssetId * @param boolean $blnInclude - include only shipments and receipts or all other transactions * @return int */ public static function CountShipmentReceiptByAssetId($intAssetId, $blnInclude = true) { // Call AssetTransaction::QueryCount to perform the CountByAssetId query if ($blnInclude) { $arrToReturn = AssetTransaction::QueryCount(QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $intAssetId), QQ::OrCondition(QQ::Equal(QQN::AssetTransaction()->Transaction->TransactionTypeId, 6), QQ::Equal(QQN::AssetTransaction()->Transaction->TransactionTypeId, 7)))); } else { $arrToReturn = AssetTransaction::QueryCount(QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $intAssetId), QQ::NotEqual(QQN::AssetTransaction()->Transaction->TransactionTypeId, 6), QQ::NotEqual(QQN::AssetTransaction()->Transaction->TransactionTypeId, 7))); } return $arrToReturn; }
protected function lstParentAssetTransaction_Create() { $this->lstParentAssetTransaction = new QListBox($this); $this->lstParentAssetTransaction->Name = QApplication::Translate('Parent Asset Transaction'); $this->lstParentAssetTransaction->AddItem(QApplication::Translate('- Select One -'), null); $objParentAssetTransactionArray = AssetTransaction::LoadAll(); if ($objParentAssetTransactionArray) { foreach ($objParentAssetTransactionArray as $objParentAssetTransaction) { $objListItem = new QListItem($objParentAssetTransaction->__toString(), $objParentAssetTransaction->AssetTransactionId); if ($this->objAssetTransaction->ParentAssetTransaction && $this->objAssetTransaction->ParentAssetTransaction->AssetTransactionId == $objParentAssetTransaction->AssetTransactionId) { $objListItem->Selected = true; } $this->lstParentAssetTransaction->AddItem($objListItem); } } }
protected function btnGenerate_Click() { $this->blnGenerate = true; // Expand the Asset object to include the AssetModel, Category, Manufacturer, and Location Objects $objExpansionMap[AssetTransaction::ExpandAsset][Asset::ExpandAssetModel][AssetModel::ExpandCategory] = true; $objExpansionMap[AssetTransaction::ExpandAsset][Asset::ExpandAssetModel][AssetModel::ExpandManufacturer] = true; $objExpansionMap[AssetTransaction::ExpandSourceLocation] = true; $objExpansionMap[AssetTransaction::ExpandDestinationLocation] = true; $objExpansionMap[AssetTransaction::ExpandTransaction][Transaction::ExpandTransactionType] = true; $objExpansionMap[AssetTransaction::ExpandTransaction][Transaction::ExpandCreatedByObject] = true; $objExpansionMap[AssetTransaction::ExpandTransaction][Transaction::ExpandModifiedByObject] = true; $arrTransactionTypes = array(); // Create an array of checked transaction types if ($this->chkMove->Checked) { $arrTransactionTypes[] = 1; } if ($this->chkCheckIn->Checked) { $arrTransactionTypes[] = 2; } if ($this->chkCheckOut->Checked) { $arrTransactionTypes[] = 3; } if ($this->chkReserve->Checked) { $arrTransactionTypes[] = 8; } if ($this->chkUnreserve->Checked) { $arrTransactionTypes[] = 9; } // Archived assets will be included in the Asset Transaction Report //$arrTransactionTypes[] = 10; // If checked at least one transaction type if (count($arrTransactionTypes)) { $this->lblReport->Warning = ""; // Total Transactions Count $intTotalTransactionCount = AssetTransaction::CountTransactionsBySearch($this->txtShortDescription->Text, $this->txtAssetCode->Text, $this->txtAssetModelCode->Text, $this->lstUser->SelectedValue, $this->lstCheckedOutBy->SelectedValue, $this->lstReservedBy->SelectedValue, $this->lstCategory->SelectedValue, $this->lstManufacturer->SelectedValue, $this->lstTransactionDate->SelectedValue, $this->dtpTransactionDateFirst->DateTime, $this->dtpTransactionDateLast->DateTime, $arrTransactionTypes, $objExpansionMap); // Total Transactions Count > 0 to avoid bug with NoDataMsg if ($intTotalTransactionCount) { // begins the report process $oRpt = new PHPReportMaker(); // Create the constant to use in xml template $oRpt->putEnvObj("TotalTransactions", $intTotalTransactionCount); //some data to show in the report $sSql = AssetTransaction::LoadArrayBySearch(true, $this->txtShortDescription->Text, $this->txtAssetCode->Text, $this->txtAssetModelCode->Text, $this->lstUser->SelectedValue, $this->lstCheckedOutBy->SelectedValue, $this->lstReservedBy->SelectedValue, $this->lstCategory->SelectedValue, $this->lstManufacturer->SelectedValue, $this->lstSortByDate->SelectedValue, $this->lstTransactionDate->SelectedValue, $this->dtpTransactionDateFirst->DateTime, $this->dtpTransactionDateLast->DateTime, $arrTransactionTypes, $objExpansionMap); $strXmlColNameByCustomField = ""; $strXmlFieldByCustomField = ""; $intCustomFieldCount = 0; if ($this->chkCustomFieldArray) { foreach ($this->chkCustomFieldArray as $chkCustomField) { if ($chkCustomField->Checked) { $strXmlColNameByCustomField .= "<COL CELLCLASS='report_column_header'>" . $chkCustomField->Text . "</COL>"; $strXmlFieldByCustomField .= "<COL TYPE='FIELD' CELLCLASS='report_cell'>__" . $chkCustomField->ActionParameter . "</COL>"; $intCustomFieldCount++; } } } $oGroups = "\n <GROUP NAME='transaction_id' EXPRESSION='transaction_id' PAGEBREAK='FALSE'>\n <HEADER>\n <ROW>\n <COL ALIGN='LEFT' TYPE='EXPRESSION' COLSPAN='" . (4 + $intCustomFieldCount) . "' CELLCLASS='report_section_heading'>\$this->getValue('asset_transaction__transaction_id__transaction_type_id__short_description').' by '.(\$this->getValue('asset_transaction__transaction_id__modified_by')?\$this->getValue('asset_transaction__transaction_id__modified_by__first_name').' '.\$this->getValue('asset_transaction__transaction_id__modified_by__last_name').' on '.\$this->getValue('asset_transaction__transaction_id__modified_date'):\$this->getValue('asset_transaction__transaction_id__created_by__first_name').' '.\$this->getValue('asset_transaction__transaction_id__created_by__last_name').' on '.\$this->getValue('asset_transaction__transaction_id__creation_date'))</COL>\n </ROW>\n\t\t\t\t<ROW>\n <COL ALIGN='LEFT' TYPE='EXPRESSION' COLSPAN='" . (4 + $intCustomFieldCount) . "' CELLCLASS='report_cell'>\$this->getValue('asset_transaction__transaction_id__note')</COL>\n </ROW>\n <ROW>\n <COL CELLCLASS='report_column_header'>Asset Code:</COL>\n <COL CELLCLASS='report_column_header'>Asset Model:</COL>\n <COL CELLCLASS='report_column_header'>From:</COL>\n <COL CELLCLASS='report_column_header'>To:</COL>\n {$strXmlColNameByCustomField}\n </ROW>\n </HEADER>\n <FIELDS>\n <ROW>\n <COL TYPE='FIELD' CELLCLASS='report_cell'><LINK TYPE='EXPRESSION'>'" . __SUBDIRECTORY__ . "/assets/asset_edit.php?intAssetId='.\$this->getValue('asset_transaction__asset_id__asset_id')</LINK>asset_transaction__asset_id__asset_code</COL>\n <COL TYPE='FIELD' CELLCLASS='report_cell'><LINK TYPE='EXPRESSION'>'" . __SUBDIRECTORY__ . "/assets/asset_model_edit.php?intAssetModelId='.\$this->getValue('asset_transaction__asset_id__asset_model_id__asset_model_id')</LINK>asset_transaction__asset_id__asset_model_id__short_description</COL>\n <COL TYPE='FIELD' CELLCLASS='report_cell'>asset_transaction__source_location_id__short_description</COL>\n <COL TYPE='FIELD' CELLCLASS='report_cell'>asset_transaction__destination_location_id__short_description</COL>\n {$strXmlFieldByCustomField}\n </ROW>\n </FIELDS>\n </GROUP>"; $arrDBInfo = unserialize(DB_CONNECTION_1); $oRpt->setSQL($sSql); $oRpt->setUser($arrDBInfo['username']); $oRpt->setPassword($arrDBInfo['password']); $oRpt->setConnection($arrDBInfo['server']); $oRpt->setDatabaseInterface('mysql'); $oRpt->setDatabase($arrDBInfo['database']); $oRpt->setNoDataMsg("No data was found, check your query"); $oRpt->setPageSize(200000000); if ($this->lstGenerateOptions->SelectedValue == "print") { // Start the output buffer ob_start(); $this->lblReport->Text = ""; $oDocs = "<CSS>../css/tracmor.css</CSS>"; $fOut = fopen(".." . __TRACMOR_TMP__ . "/" . $_SESSION['intUserAccountId'] . "_asset_transaction_report.htm", "w"); $oRpt->createFromTemplate('Asset Transaction Report', __DOCROOT__ . __SUBDIRECTORY__ . '/reports/asset_transaction_report.xml', null, $oDocs, $oGroups); $oRpt->run(); fwrite($fOut, ob_get_contents()); ob_end_clean(); fclose($fOut); // Open generated Report in new window QApplication::ExecuteJavaScript("window.open('.." . __TRACMOR_TMP__ . "/" . $_SESSION['intUserAccountId'] . "_asset_transaction_report.htm','AssetTransactionReport','resizeable=yes,menubar=yes,scrollbars=yes,left=0,top=0,width=800,height=600');history.go(-1);"); exit; } else { if ($this->lstGenerateOptions->SelectedValue == "csv") { $this->RenderCsvBegin(false); session_cache_limiter('must-revalidate'); // force a "no cache" effect header("Pragma: hack"); // IE chokes on "no cache", so set to something, anything, else. $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT"; header($ExpStr); header('Content-Type: text/csv'); header('Content-Disposition: csv; filename=export.csv'); ob_end_clean(); $oRpt->createFromTemplate('Asset Transaction Report', __DOCROOT__ . __SUBDIRECTORY__ . '/reports/asset_transaction_report.xml', null, null, $oGroups); $oOut = $oRpt->createOutputPlugin("csv"); $oRpt->setOutputPlugin($oOut); $oRpt->run(); ob_get_contents(); @ob_flush(); flush(); $this->RenderCsvEnd(false); exit; } else { // Start the output buffer ob_start(); // The head of the final html will be write by the Qform $oRpt->setBody(false); $oRpt->createFromTemplate('Asset Transaction Report', __DOCROOT__ . __SUBDIRECTORY__ . '/reports/asset_transaction_report.xml', null, null, $oGroups); $oRpt->run(); // Put the output buffer content in the Qlabel $this->lblReport->Text = ob_get_contents(); // Clean the output buffer ob_end_clean(); } } // Begin rendering the QForm //$this->RenderBegin(false); //ob_end_clean(); // Process the report //$oOut = $oRpt->createOutputPlugin("csv"); //$oRpt->setOutputPlugin($oOut); //$this->RenderEnd(false); //exit(); } else { $this->lblReport->Text = ""; $this->lblReport->Warning = "No data was found, check your query."; } } else { $this->lblReport->Text = ""; $this->lblReport->Warning = "You must check at least one transaction type."; } $this->blnGenerate = false; }
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; } } } }
/** * Load an Reciept Object * The method should check for assets or inventory in reciept that is still 'To Be Received' (TBR) * * @param int $intReceiptId * @return Receipt */ public function ReceiptComplete($intReceiptId) { $objClauses = null; $blnAllAssetsReceived = true; $blnAllInventoryReceived = true; $objReceipt = Receipt::Load($intReceiptId); if ($objReceipt) { if (!$objReceipt->ReceivedFlag) { $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($objReceipt->TransactionId, $objClauses); $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($objReceipt->TransactionId, $objClauses); foreach ($objAssetTransactionArray as &$objAssetTransaction) { if (!$objAssetTransaction->DestinationLocationId) { $blnAllAssetsReceived = false; } } if ($blnAllAssetsReceived) { if ($objInventoryTransactionArray) { foreach ($objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->DestinationLocationId) { $blnAllInventoryReceived = false; } } } // Set the entire receipt as received if assets and inventory have all been received if ($blnAllInventoryReceived) { $objReceipt->ReceivedFlag = true; $objReceipt->ReceiptDate = new QDateTime(QDateTime::Now); $objReceipt->Save(); } } } return $objReceipt; } else { return false; } }
} } else { $strWarning .= "Please enter an asset code.<br />"; } } if (!$blnError) { // There is a 1 to Many relationship between Transaction and AssetTransaction so each Transaction can have many AssetTransactions. $objTransaction = new Transaction(); $objTransaction->EntityQtypeId = EntityQtype::Asset; $objTransaction->TransactionTypeId = 3; // Check Out $objTransaction->Save(); $intDestinationLocationId = 1; // Check Out foreach ($objAssetArray as $objAsset) { $objAssetTransaction = new AssetTransaction(); $objAssetTransaction->AssetId = $objAsset->AssetId; $objAssetTransaction->TransactionId = $objTransaction->TransactionId; $objAssetTransaction->SourceLocationId = $objAsset->LocationId; $objAssetTransaction->DestinationLocationId = $intDestinationLocationId; $objAssetTransaction->Save(); $objAsset->LocationId = $intDestinationLocationId; $objAsset->CheckedOutFlag = true; $objAsset->Save(); } $strWarning .= "Your transaction has successfully completed<br /><a href='index.php'>Main Menu</a> | <a href='asset_menu.php'>Manage Assets</a><br />"; //Remove that flag when transaction is compelete or exists some errors unset($_SESSION['intUserAccountId']); $blnTransactionComplete = true; $arrCheckedAssetCode = ""; } else {
/** * Internally called method to assist with early binding of objects * on load methods. Can only early-bind references that this class owns in the database. * @param string $strParentAlias the alias of the parent (if any) * @param string $strAlias the alias of this object * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion) */ public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion) { if ($strAlias) { $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `asset_transaction` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`asset_transaction_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_transaction_id` AS `%s__%s__asset_transaction_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_id` AS `%s__%s__asset_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`transaction_id` AS `%s__%s__transaction_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`parent_asset_transaction_id` AS `%s__%s__parent_asset_transaction_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`source_location_id` AS `%s__%s__source_location_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`destination_location_id` AS `%s__%s__destination_location_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`new_asset_flag` AS `%s__%s__new_asset_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`new_asset_id` AS `%s__%s__new_asset_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`schedule_receipt_flag` AS `%s__%s__schedule_receipt_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`schedule_receipt_due_date` AS `%s__%s__schedule_receipt_due_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`created_by` AS `%s__%s__created_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`creation_date` AS `%s__%s__creation_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_by` AS `%s__%s__modified_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_date` AS `%s__%s__modified_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $strParentAlias = $strParentAlias . '__' . $strAlias; } if (is_array($objExpansionMap)) { foreach ($objExpansionMap as $strKey => $objValue) { switch ($strKey) { case 'asset_id': try { Asset::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'transaction_id': try { Transaction::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'parent_asset_transaction_id': try { AssetTransaction::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'source_location_id': try { Location::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'destination_location_id': try { Location::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'new_asset_id': try { Asset::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'created_by': try { UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'modified_by': try { UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } default: throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey)); } } } }
public function btnSave_Click($strFormId, $strControlId, $strParameter) { $blnError = false; if ($this->objAssetTransactionArray && $this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::AssetInventory; } elseif ($this->objAssetTransactionArray) { $intEntityQtypeId = EntityQtype::Asset; } elseif ($this->objInventoryTransactionArray) { $intEntityQtypeId = EntityQtype::Inventory; } else { $blnError = true; $this->btnCancel->Warning = 'There are no assets nor inventory in this receipt.'; } if (QApplication::$TracmorSettings->CustomReceiptNumbers) { if (trim($this->txtReceiptNumber->Text) == '') { $blnError = true; $this->txtReceiptNumber->Warning = 'Receipt number is a required field.'; } else { if ($objReceipt = Receipt::LoadByReceiptNumber($this->txtReceiptNumber->Text)) { if ($objReceipt->ReceiptId != $this->objReceipt->ReceiptId) { $blnError = true; $this->txtReceiptNumber->Warning = 'That is a duplicate receipt number.'; } } } } if (!$this->lstFromCompany->SelectedValue) { $blnError = true; $this->lstFromCompany->Warning = 'You must select a From Company'; } if (!$this->lstFromContact->SelectedValue) { $blnError = true; $this->lstFromContact->Warning = 'You must select a From Contact'; } if (!$this->lstToContact->SelectedValue) { $blnError = true; $this->lstToContact->Warning = 'You must select a To Contact'; } if (!$this->lstToAddress->SelectedValue) { $blnError = true; $this->lstToAddress->Warning = 'You must select a To Address'; } if (!$blnError) { if (!$this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); // Create the new transaction object and save it $this->objTransaction = new Transaction(); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->TransactionTypeId = 7; // Receive $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) { // Assign different source and destinations depending on transaction type foreach ($this->objAssetTransactionArray as $objAssetTransaction) { // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate if ($objAssetTransaction->Asset instanceof Asset) { // Save the asset to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate // Also set the location to 5 (TBR). This is in case the current LocationId is 2 (Shipped), because they can be received. $objAssetTransaction->Asset->LocationId = 5; // If the AssetId==0, then it is a newly created asset that hasn't been saved to the db yet // We have to create a new asset object and assign it to the AssetTransaction // Just resetting the values for the existing asset object won't work for some reason (not sure why). if ($objAssetTransaction->Asset->AssetId == 0) { $objNewAsset = new Asset(); $objNewAsset->AssetModelId = $objAssetTransaction->Asset->AssetModelId; $objNewAsset->TempId = $objAssetTransaction->Asset->TempId; $objNewAsset->LocationId = $objAssetTransaction->Asset->LocationId; // If the asset was selected for autogeneration, it will be blank, so create the asset code here (right before save) if ($objAssetTransaction->Asset->AssetCode == '') { $objAssetTransaction->Asset->AssetCode = Asset::GenerateAssetCode(); } $objNewAsset->AssetCode = $objAssetTransaction->Asset->AssetCode; // Save the new asset $objNewAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objNewAsset->AssetId); // Assign the new asset to the AssetTransaction $objAssetTransaction->Asset = $objNewAsset; $objAssetTransaction->NewAssetFlag = true; } else { $objAssetTransaction->NewAssetFlag = false; $objAssetTransaction->Asset->Save(); } // Create the new assettransaction object and save it $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; $objAssetTransaction->Save(); } } } if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) { // Assign different source and destinations depending on transaction type foreach ($this->objInventoryTransactionArray as &$objInventoryTransaction) { // Finish the InventoryTransaction and save it $objInventoryTransaction->InventoryLocation->Quantity += $objInventoryTransaction->Quantity; $objInventoryTransaction->InventoryLocation->Save(); $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; $objInventoryTransaction->Save(); } } $this->UpdateReceiptFields(); $this->objReceipt->ReceivedFlag = false; $this->objReceipt->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objReceipt->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objReceipt->ReceiptId, EntityQtype::Receipt); } $objDatabase->TransactionCommit(); QApplication::Redirect('receipt_list.php'); } catch (QExtendedOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); if ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } if ($objExc->Class == 'AssetTransaction') { $this->btnCancel->Warning = 'This asset transaction has been modified by another user. You may reload the receipt and try your modifications again.'; } if ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } elseif ($this->blnEditMode) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); // This should probably be changed to $this->objReceipt->Transaction $this->objTransaction = Transaction::Load($this->objReceipt->TransactionId); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Remove AssetTransactions that were removed when editing if ($this->arrAssetTransactionToDelete) { foreach ($this->arrAssetTransactionToDelete as $intAssetTransactionId) { $objAssetTransactionToDelete = AssetTransaction::Load($intAssetTransactionId); // Make sure that it wasn't added and then removed if ($objAssetTransactionToDelete) { // If a new asset was created in this receipt, it needs to be deleted if ($objAssetTransactionToDelete->NewAssetFlag) { $intAssetIdToDelete = $objAssetTransactionToDelete->Asset->AssetId; //$objAssetTransactionToDelete->Asset->Delete(); } else { // Change back location $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId; $objAssetTransactionToDelete->Asset->Save(); } // Delete the asset transaction $objAssetTransactionToDelete->Delete(); // If a new asset, delete it if (isset($intAssetIdToDelete)) { $objAssetToDelete = Asset::LoadByAssetId($intAssetIdToDelete); $objAssetToDelete->Delete(); } unset($objAssetTransactionToDelete); } } } // Save existing AssetTransactions if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if (!$objAssetTransaction->AssetTransactionId) { $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // This is done in case the original location is 'Shipped'(2), not 'To Be Received'(5) $objAssetTransaction->SourceLocationId = $objAssetTransaction->Asset->LocationId; $objAssetTransaction->Asset->LocationId = 5; // To Be Received // If the AssetId is 0 (it hasn't been saved to the database yet), then create a new Asset in the conventional way // We have to create a new asset object and assign it to the AssetTransaction // Just resetting the values for the existing asset object won't work for some reason (not sure why). if ($objAssetTransaction->Asset->AssetId == 0) { $objNewAsset = new Asset(); $objNewAsset->AssetModelId = $objAssetTransaction->Asset->AssetModelId; $objNewAsset->TempId = $objAssetTransaction->Asset->TempId; $objNewAsset->LocationId = $objAssetTransaction->Asset->LocationId; // If the asset was selected for autogeneration, it will be blank, so create the asset code here (right before save) if ($objAssetTransaction->Asset->AssetCode == '') { $objAssetTransaction->Asset->AssetCode = Asset::GenerateAssetCode(); } $objNewAsset->AssetCode = $objAssetTransaction->Asset->AssetCode; // Save the new asset $objNewAsset->Save(); // Assign any default custom field values CustomField::AssignNewEntityDefaultValues(1, $objNewAsset->AssetId); // Associate the new asset with the AssetTransaction $objAssetTransaction->Asset = $objNewAsset; $objAssetTransaction->NewAssetFlag = true; } else { $objAssetTransaction->NewAssetFlag = false; $objAssetTransaction->Asset->Save(); } } // Always save the asset transaction, to generate an Optimistic Locking Exception when appropriate $objAssetTransaction->Save(); // Reload AssetTransaction to avoid Optimistic Locking Exception if this receipt is edited and saved. $objAssetTransaction = AssetTransaction::Load($objAssetTransaction->AssetTransactionId); } } // Remove InventoryTransactions if ($this->arrInventoryTransactionToDelete) { foreach ($this->arrInventoryTransactionToDelete as $intInventoryTransactionId) { $objInventoryTransactionToDelete = InventoryTransaction::Load($intInventoryTransactionId); // Make sure that it wasn't added then removed if ($objInventoryTransactionToDelete) { // Change back the quantity $objInventoryTransactionToDelete->InventoryLocation->Quantity -= $objInventoryTransactionToDelete->Quantity; $objInventoryTransactionToDelete->InventoryLocation->Save(); // Delete the InventoryTransaction $objInventoryTransactionToDelete->Delete(); unset($objInventoryTransactionToDelete); } } } // Save InventoryTransactions if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->InventoryTransactionId) { // Reload the InventoryLocation. If it was deleted and added in the same save click, then it will throw an Optimistic Locking Exception $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId); $objInventoryTransaction->InventoryLocation->Quantity += $objInventoryTransaction->Quantity; $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; $objInventoryTransaction->InventoryLocation->Save(); $SourceLocationId = 5; // To Be Received $objInventoryTransaction->SourceLocationId = $SourceLocationId; } // Always save the InventoryTransaction, to generate an Optimistic Locking Exception when appropriate $objInventoryTransaction->Save(); // Reload the InventoryTransaction to get the new timestamp so that it doesn't generate an optimistic locking exception $objInventoryTransaction = InventoryTransaction::Load($objInventoryTransaction->InventoryTransactionId); } } // Check to see if all Inventory and Assets have been received (if the final entity was removed from the receipt without receiving it). // Only if it hasn't already been received if (!$this->objReceipt->ReceivedFlag) { // Check to see if all assets have been received $blnAllAssetsReceived = true; if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if (!$objAssetTransaction->DestinationLocationId) { $blnAllAssetsReceived = false; } } } // Check to see if all inventory have been received $blnAllInventoryReceived = true; if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->DestinationLocationId) { $blnAllInventoryReceived = false; } } } // If all Inventory and Assets have been received if ($blnAllAssetsReceived && $blnAllInventoryReceived) { // Flip the received flag for the entire Receipt $this->objReceipt->ReceivedFlag = true; $this->objReceipt->ReceiptDate = new QDateTime(QDateTime::Now); } } else { if ($this->objReceipt->ReceiptDate != $this->calDateReceived->DateTime) { $this->objReceipt->ReceiptDate = $this->calDateReceived->DateTime; } } $this->UpdateReceiptFields(); $this->UpdateReceiptLabels(); $this->objReceipt->Save(); if ($this->arrCustomFields) { // Save the values from all of the custom field controls to save the shipment CustomField::SaveControls($this->objReceipt->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objReceipt->ReceiptId, EntityQtype::Receipt); } // Reload to get new timestamp to avoid optimistic locking if edited/saved again without reload $this->objReceipt = Receipt::Load($this->objReceipt->ReceiptId); $this->DisplayLabels(); $objDatabase->TransactionCommit(); } catch (QExtendedOptimisticLockingException $objExc) { $objDatabase->TransactionRollback(); if ($objExc->Class == 'Receipt' || $objExc->Class == 'AssetTransaction' || $objExc->Class == 'InventoryTransaction') { $this->btnCancel->Warning = sprintf('This receipt has been modified by another user. You must <a href="receipt_edit.php?intReceiptId=%s">Refresh</a> to edit this receipt.', $this->objReceipt->ReceiptId); } elseif ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } elseif ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } else { throw new QOptimisticLockingException($objExc->Class); } } } } }
protected function dtgAssetTransaction_Bind() { // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll() // Remember! We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below $this->dtgAssetTransaction->TotalItemCount = AssetTransaction::CountAll(); // Setup the $objClauses Array $objClauses = array(); // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->dtgAssetTransaction->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->dtgAssetTransaction->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be the array of all AssetTransaction objects, given the clauses above $this->dtgAssetTransaction->DataSource = AssetTransaction::LoadAll($objClauses); }