foreach ($objLinkedAssetArrayByNewAsset as $objLinkedAsset) { $objLinkedAsset->CheckedOutFlag = true; $objLinkedAsset->LocationId = $intDestinationLocationId; $objLinkedAsset->Save(); // Create the new assettransaction object and save it $objAssetTransaction = new AssetTransaction(); $objAssetTransaction->AssetId = $objLinkedAsset->AssetId; $objAssetTransaction->TransactionId = $objTransaction->TransactionId; $objAssetTransaction->SourceLocationId = $objAsset->LocationId; $objAssetTransaction->DestinationLocationId = $intDestinationLocationId; $objAssetTransaction->Save(); // Create new AssetTransactionCheckout by that user to the same user for each linked asset $objAssetTransactionCheckout = new AssetTransactionCheckout(); $objAssetTransactionCheckout->AssetTransactionId = $objAssetTransaction->AssetTransactionId; $objAssetTransactionCheckout->ToUserId = QApplication::$objUserAccount->UserAccountId; $objAssetTransactionCheckout->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 { $strWarning .= "This transaction has not been completed.<br />"; } if (is_array($arrCheckedAssetCode)) {
public function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->btnCancel->Warning = ""; if ($this->objAssetArray) { $blnError = false; foreach ($this->objAssetArray as $asset) { // TransactionTypeId = 1 is for moves if ($this->intTransactionTypeId == 1) { if ($asset->LocationId == $this->lstLocation->SelectedValue) { $this->dtgAssetTransact->Warning = 'Cannot move an asset from a location to the same location.'; $blnError = true; } } // For all transactions except Unreserve, make sure the asset is not already reserved if ($this->intTransactionTypeId != 9 && $asset->ReservedFlag) { $this->btnCancel->Warning = sprintf('The Asset %s is reserved.', $asset->AssetCode); $blnError = true; } // For all transactions except Unarchive, make sure the asset is not already archived if ($this->intTransactionTypeId != 11 && $asset->ArchivedFlag) { $this->btnCancel->Warning = sprintf('The Asset %s is archived.', $asset->AssetCode); $blnError = true; } } if (!$blnError) { if ($this->intTransactionTypeId == 3) { $this->lstCheckOutTo->Warning = ''; $this->lstDueDate->Warning = ''; $intToUser = ""; $intToContact = ""; $dttDueDate = ""; if ((QApplication::$TracmorSettings->CheckOutToOtherUsers == "1" || QApplication::$TracmorSettings->CheckOutToContacts == "1") && $this->lstCheckOutTo->Display) { if ($this->lstCheckOutTo->SelectedValue == "1") { if (!$this->lstUser->SelectedValue) { $this->lstCheckOutTo->Warning = 'Please select a user.'; $blnError = true; } else { $intToUser = $this->lstUser->SelectedValue; } } elseif ($this->lstCheckOutTo->SelectedValue == "2") { if (!$this->lstToContact->SelectedValue) { $this->lstCheckOutTo->Warning = 'Please select a contact.'; $blnError = true; } else { $intToContact = $this->lstToContact->SelectedValue; } } else { $this->lstCheckOutTo->Warning = 'Please select one of the options'; $blnError = true; } } else { $intToUser = QApplication::$objUserAccount->UserAccountId; } if ($this->lstDueDate->Display) { if ($this->lstDueDate->SelectedValue == 2) { $dttDueDate = $this->dttDueDate; if ($dttDueDate && $dttDueDate->DateTime < QDateTime::Now()) { $this->lstDueDate->Warning = 'Due date must be a future date'; $blnError = true; } } elseif (QApplication::$TracmorSettings->DueDateRequired == "1") { $this->lstDueDate->Warning = 'Due date is required'; $blnError = true; } } } if (QApplication::$TracmorSettings->ReasonRequired == "1" && !trim($this->txtNote->Text) && $this->intTransactionTypeId == 3) { $this->txtNote->Warning = 'Reason is required.'; $blnError = true; } elseif (($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 2 || $this->intTransactionTypeId == 11) && is_null($this->lstLocation->SelectedValue)) { $this->lstLocation->Warning = 'Location is required.'; $blnError = true; } elseif ($this->txtNote->Text == '' && $this->intTransactionTypeId != 3) { $this->txtNote->Warning = 'Note is required.'; $blnError = true; } } if (!$blnError) { 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(); // Entity Qtype is Asset $this->objTransaction->EntityQtypeId = EntityQtype::Asset; $this->objTransaction->TransactionTypeId = $this->intTransactionTypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Assign different source and destinations depending on transaction type foreach ($this->objAssetArray as $asset) { if ($asset instanceof Asset && $asset->LinkedFlag != 1) { $SourceLocationId = $asset->LocationId; // Load all linked assets $objLinkedAssetArrayByNewAsset = Asset::LoadChildLinkedArrayByParentAssetId($asset->AssetId); if (!$objLinkedAssetArrayByNewAsset) { $objLinkedAssetArrayByNewAsset = array(); } if ($this->intTransactionTypeId == 1) { $DestinationLocationId = $this->lstLocation->SelectedValue; } elseif ($this->intTransactionTypeId == 2) { $DestinationLocationId = $this->lstLocation->SelectedValue; $asset->CheckedOutFlag = false; } elseif ($this->intTransactionTypeId == 3) { $DestinationLocationId = 1; $asset->CheckedOutFlag = true; } elseif ($this->intTransactionTypeId == 8) { $DestinationLocationId = $asset->LocationId; $asset->ReservedFlag = true; } elseif ($this->intTransactionTypeId == 9) { $DestinationLocationId = $asset->LocationId; $asset->ReservedFlag = false; } elseif ($this->intTransactionTypeId == 10) { $DestinationLocationId = 6; $asset->ArchivedFlag = true; //$asset->CheckedOutFlag = false; //$asset->ReservedFlag = false; } elseif ($this->intTransactionTypeId == 11) { $DestinationLocationId = $this->lstLocation->SelectedValue; $asset->ArchivedFlag = false; } $asset->LocationId = $DestinationLocationId; // Transact all child linked assets foreach ($objLinkedAssetArrayByNewAsset as $objLinkedAsset) { $objLinkedAsset->CheckedOutFlag = $asset->CheckedOutFlag; $objLinkedAsset->ArchivedFlag = $asset->ArchivedFlag; $objLinkedAsset->ReservedFlag = $asset->ReservedFlag; $objLinkedAsset->LocationId = $asset->LocationId; $objLinkedAsset->Save(); // Create the new assettransaction object and save it $this->objAssetTransaction = new AssetTransaction(); $this->objAssetTransaction->AssetId = $objLinkedAsset->AssetId; $this->objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; $this->objAssetTransaction->SourceLocationId = $SourceLocationId; $this->objAssetTransaction->DestinationLocationId = $DestinationLocationId; $this->objAssetTransaction->Save(); // Create the new AssetTransactionCheckout object and save it if ($this->intTransactionTypeId == 3) { $objAssetTransactionCheckout = new AssetTransactionCheckout(); $objAssetTransactionCheckout->AssetTransactionId = $this->objAssetTransaction->AssetTransactionId; $objAssetTransactionCheckout->ToContactId = $intToContact; $objAssetTransactionCheckout->ToUserId = $intToUser; if ($dttDueDate instanceof QDateTimePicker) { $objAssetTransactionCheckout->DueDate = $dttDueDate->DateTime; } $objAssetTransactionCheckout->Save(); } } $asset->Save(); // Create the new assettransaction object and save it $this->objAssetTransaction = new AssetTransaction(); $this->objAssetTransaction->AssetId = $asset->AssetId; $this->objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; $this->objAssetTransaction->SourceLocationId = $SourceLocationId; $this->objAssetTransaction->DestinationLocationId = $DestinationLocationId; $this->objAssetTransaction->Save(); // Create the new AssetTransactionCheckout object and save it for each linked asset if ($this->intTransactionTypeId == 3) { $objAssetTransactionCheckout = new AssetTransactionCheckout(); $objAssetTransactionCheckout->AssetTransactionId = $this->objAssetTransaction->AssetTransactionId; $objAssetTransactionCheckout->ToContactId = $intToContact; $objAssetTransactionCheckout->ToUserId = $intToUser; if ($dttDueDate instanceof QDateTimePicker) { $objAssetTransactionCheckout->DueDate = $dttDueDate->DateTime; } $objAssetTransactionCheckout->Save(); } } } // Commit the above transactions to the database $objDatabase->TransactionCommit(); QApplication::Redirect('../common/transaction_edit.php?intTransactionId=' . $this->objTransaction->TransactionId); } catch (QOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); $objAsset = Asset::Load($objExc->EntityId); $this->objParentObject->btnRemove_Click($this->objParentObject->FormId, 'btnRemove' . $objExc->EntityId, $objExc->EntityId); // Lock Exception Thrown, Report the Error $this->btnCancel->Warning = sprintf('The Asset %s has been altered by another user and removed from the transaction. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } } } else { $this->btnCancel->Warning = sprintf('Please provide at least one asset.'); } }