/** * Load a single AssetTransactionCheckout object with expansion map of Contact and UserAccount, * by TransactionId * @param integer $intAssetId * @return object $objAssetTransactionCheckout */ public function LoadWithToContactToUserByTransactionId($intAssetTransactionId = null) { $objClauses = array(); array_push($objClauses, QQ::Expand(QQN::AssetTransactionCheckout()->ToContact)); array_push($objClauses, QQ::Expand(QQN::AssetTransactionCheckout()->ToUser)); $objAssetTransactionCheckout = AssetTransactionCheckout::QuerySingle(QQ::Equal(QQN::AssetTransactionCheckout()->AssetTransactionId, $intAssetTransactionId), $objClauses); return $objAssetTransactionCheckout; }
$objAssetTransactionCheckout->Save(); $objLinkedAssetArrayByNewAsset = Asset::LoadChildLinkedArrayByParentAssetId($objAsset->AssetId); if ($objLinkedAssetArrayByNewAsset) { 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 {
/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = AssetTransactionCheckout::QueryCount($objCondition, $objClauses); } // 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->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from AssetTransactionCheckout, given the clauses above $this->DataSource = AssetTransactionCheckout::QueryArray($objCondition, $objClauses); }
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.'); } }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this AssetTransactionCheckoutMetaControl * @param integer $intAssetTransactionCheckoutId primary key value * @param QMetaControlCreateType $intCreateType rules governing AssetTransactionCheckout object creation - defaults to CreateOrEdit * @return AssetTransactionCheckoutMetaControl */ public static function Create($objParentObject, $intAssetTransactionCheckoutId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intAssetTransactionCheckoutId)) { $objAssetTransactionCheckout = AssetTransactionCheckout::Load($intAssetTransactionCheckoutId); // AssetTransactionCheckout was found -- return it! if ($objAssetTransactionCheckout) { return new AssetTransactionCheckoutMetaControl($objParentObject, $objAssetTransactionCheckout); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a AssetTransactionCheckout object with PK arguments: ' . $intAssetTransactionCheckoutId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new AssetTransactionCheckoutMetaControl($objParentObject, new AssetTransactionCheckout()); }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'AssetTransactionId': // Gets the value for intAssetTransactionId (Read-Only PK) // @return integer return $this->intAssetTransactionId; case 'AssetId': // Gets the value for intAssetId (Not Null) // @return integer return $this->intAssetId; case 'TransactionId': // Gets the value for intTransactionId (Not Null) // @return integer return $this->intTransactionId; case 'ParentAssetTransactionId': // Gets the value for intParentAssetTransactionId // @return integer return $this->intParentAssetTransactionId; case 'SourceLocationId': // Gets the value for intSourceLocationId // @return integer return $this->intSourceLocationId; case 'DestinationLocationId': // Gets the value for intDestinationLocationId // @return integer return $this->intDestinationLocationId; case 'NewAssetFlag': // Gets the value for blnNewAssetFlag // @return boolean return $this->blnNewAssetFlag; case 'NewAssetId': // Gets the value for intNewAssetId // @return integer return $this->intNewAssetId; case 'ScheduleReceiptFlag': // Gets the value for blnScheduleReceiptFlag // @return boolean return $this->blnScheduleReceiptFlag; case 'ScheduleReceiptDueDate': // Gets the value for dttScheduleReceiptDueDate // @return QDateTime return $this->dttScheduleReceiptDueDate; case 'CreatedBy': // Gets the value for intCreatedBy // @return integer return $this->intCreatedBy; case 'CreationDate': // Gets the value for dttCreationDate // @return QDateTime return $this->dttCreationDate; case 'ModifiedBy': // Gets the value for intModifiedBy // @return integer return $this->intModifiedBy; case 'ModifiedDate': // Gets the value for strModifiedDate (Read-Only Timestamp) // @return string return $this->strModifiedDate; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Asset': // Gets the value for the Asset object referenced by intAssetId (Not Null) // @return Asset try { if (!$this->objAsset && !is_null($this->intAssetId)) { $this->objAsset = Asset::Load($this->intAssetId); } return $this->objAsset; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Transaction': // Gets the value for the Transaction object referenced by intTransactionId (Not Null) // @return Transaction try { if (!$this->objTransaction && !is_null($this->intTransactionId)) { $this->objTransaction = Transaction::Load($this->intTransactionId); } return $this->objTransaction; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'ParentAssetTransaction': // Gets the value for the AssetTransaction object referenced by intParentAssetTransactionId // @return AssetTransaction try { if (!$this->objParentAssetTransaction && !is_null($this->intParentAssetTransactionId)) { $this->objParentAssetTransaction = AssetTransaction::Load($this->intParentAssetTransactionId); } return $this->objParentAssetTransaction; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'SourceLocation': // Gets the value for the Location object referenced by intSourceLocationId // @return Location try { if (!$this->objSourceLocation && !is_null($this->intSourceLocationId)) { $this->objSourceLocation = Location::Load($this->intSourceLocationId); } return $this->objSourceLocation; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'DestinationLocation': // Gets the value for the Location object referenced by intDestinationLocationId // @return Location try { if (!$this->objDestinationLocation && !is_null($this->intDestinationLocationId)) { $this->objDestinationLocation = Location::Load($this->intDestinationLocationId); } return $this->objDestinationLocation; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'NewAsset': // Gets the value for the Asset object referenced by intNewAssetId // @return Asset try { if (!$this->objNewAsset && !is_null($this->intNewAssetId)) { $this->objNewAsset = Asset::Load($this->intNewAssetId); } return $this->objNewAsset; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'CreatedByObject': // Gets the value for the UserAccount object referenced by intCreatedBy // @return UserAccount try { if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) { $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy); } return $this->objCreatedByObject; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'ModifiedByObject': // Gets the value for the UserAccount object referenced by intModifiedBy // @return UserAccount try { if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) { $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy); } return $this->objModifiedByObject; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'AssetTransactionCheckout': // Gets the value for the AssetTransactionCheckout object that uniquely references this AssetTransaction // by objAssetTransactionCheckout (Unique) // @return AssetTransactionCheckout try { if ($this->objAssetTransactionCheckout === false) { // We've attempted early binding -- and the reverse reference object does not exist return null; } if (!$this->objAssetTransactionCheckout) { $this->objAssetTransactionCheckout = AssetTransactionCheckout::LoadByAssetTransactionId($this->intAssetTransactionId); } return $this->objAssetTransactionCheckout; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '_ChildAssetTransaction': // Gets the value for the private _objChildAssetTransaction (Read-Only) // if set due to an expansion on the asset_transaction.parent_asset_transaction_id reverse relationship // @return AssetTransaction return $this->_objChildAssetTransaction; case '_ChildAssetTransactionArray': // Gets the value for the private _objChildAssetTransactionArray (Read-Only) // if set due to an ExpandAsArray on the asset_transaction.parent_asset_transaction_id reverse relationship // @return AssetTransaction[] return (array) $this->_objChildAssetTransactionArray; case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * This will save this object's AssetTransaction instance, * updating only the fields which have had a control created for it. */ public function SaveAssetTransaction() { try { // Update any fields for controls that have been created if ($this->lstAsset) { $this->objAssetTransaction->AssetId = $this->lstAsset->SelectedValue; } if ($this->lstTransaction) { $this->objAssetTransaction->TransactionId = $this->lstTransaction->SelectedValue; } if ($this->lstParentAssetTransaction) { $this->objAssetTransaction->ParentAssetTransactionId = $this->lstParentAssetTransaction->SelectedValue; } if ($this->lstSourceLocation) { $this->objAssetTransaction->SourceLocationId = $this->lstSourceLocation->SelectedValue; } if ($this->lstDestinationLocation) { $this->objAssetTransaction->DestinationLocationId = $this->lstDestinationLocation->SelectedValue; } if ($this->chkNewAssetFlag) { $this->objAssetTransaction->NewAssetFlag = $this->chkNewAssetFlag->Checked; } if ($this->lstNewAsset) { $this->objAssetTransaction->NewAssetId = $this->lstNewAsset->SelectedValue; } if ($this->chkScheduleReceiptFlag) { $this->objAssetTransaction->ScheduleReceiptFlag = $this->chkScheduleReceiptFlag->Checked; } if ($this->calScheduleReceiptDueDate) { $this->objAssetTransaction->ScheduleReceiptDueDate = $this->calScheduleReceiptDueDate->DateTime; } if ($this->lstCreatedByObject) { $this->objAssetTransaction->CreatedBy = $this->lstCreatedByObject->SelectedValue; } if ($this->calCreationDate) { $this->objAssetTransaction->CreationDate = $this->calCreationDate->DateTime; } if ($this->lstModifiedByObject) { $this->objAssetTransaction->ModifiedBy = $this->lstModifiedByObject->SelectedValue; } // Update any UniqueReverseReferences (if any) for controls that have been created for it if ($this->lstAssetTransactionCheckout) { $this->objAssetTransaction->AssetTransactionCheckout = AssetTransactionCheckout::Load($this->lstAssetTransactionCheckout->SelectedValue); } // Save the AssetTransaction object $this->objAssetTransaction->Save(); // Finally, update any ManyToManyReferences (if any) } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } }
/** * Deletes all associated AssetTransactionCheckoutsAsTo * @return void */ public function DeleteAllAssetTransactionCheckoutsAsTo() { if (is_null($this->intContactId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAssetTransactionCheckoutAsTo on this unsaved Contact.'); } // Get the Database Object for this Class $objDatabase = Contact::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (AssetTransactionCheckout::LoadArrayByToContactId($this->intContactId) as $objAssetTransactionCheckout) { $objAssetTransactionCheckout->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `asset_transaction_checkout` WHERE `to_contact_id` = ' . $objDatabase->SqlVariable($this->intContactId) . ' '); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, AssetTransactionCheckout::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }