Exemplo n.º 1
0
 protected function dtrAssetHistory_Bind()
 {
     // Get Total Count for Pagination
     $this->dtrAssetHistory->TotalItemCount = AssetTransaction::CountAssetTransaction($this->ctlAssetEdit->objAsset->AssetId);
     $objClauses = array();
     $objClause = QQ::OrderBy(QQN::AssetTransaction()->Transaction->CreationDate, false);
     array_push($objClauses, $objClause);
     $objCondition = QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $this->ctlAssetEdit->objAsset->AssetId), QQ::OrCondition(QQ::In(QQN::AssetTransaction()->Transaction->TransactionTypeId, array(1, 2, 3, 6, 7, 8, 9, 10, 11))));
     $intItemsPerPage = $this->dtrAssetHistory->ItemsPerPage;
     $intItemOffset = ($this->dtrAssetHistory->PageNumber - 1) * $intItemsPerPage;
     $arrDataSource = array_slice(AssetTransaction::QueryArray($objCondition, $objClauses), $intItemOffset, $intItemsPerPage);
     $this->dtrAssetHistory->DataSource = $arrDataSource;
 }
Exemplo n.º 2
0
 public function btnAddAsset_Click($strFormId, $strControlId, $strParameter)
 {
     if ($this->rblAssetType->SelectedValue == 'new') {
         $blnError = false;
         // Do not allow creation of an asset if asset limit will be exceeded
         $intAssetLimit = is_numeric(QApplication::$TracmorSettings->AssetLimit) ? QApplication::$TracmorSettings->AssetLimit : false;
         if ($intAssetLimit && Asset::CountActive() >= $intAssetLimit) {
             $blnError = true;
             $this->txtNewAssetCode->Warning = "Your asset limit has been reached.";
         }
         // Assign an empty string to the asset code for now (NULL won't work to render properly in the datagrid
         if ($this->chkAutoGenerateAssetCode->Checked == true) {
             $strAssetCode = '';
         } else {
             $strAssetCode = $this->txtNewAssetCode->Text;
             if (!$strAssetCode) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = 'You must enter an asset tag.';
             }
         }
         // Generate an error if that asset code already exists
         if ($objDuplicate = Asset::LoadByAssetCode($strAssetCode)) {
             $blnError = true;
             $this->txtNewAssetCode->Warning = 'That asset tag already exists. Choose another.';
         } elseif (!$this->lstAssetModel->SelectedValue) {
             $blnError = true;
             $this->txtNewAssetCode->Warning = 'You must select one model.';
         }
         if (!$blnError) {
             $objNewAsset = new Asset();
             $objNewAsset->AssetModelId = $this->lstAssetModel->SelectedValue;
             $objNewAsset->LocationId = 5;
             // To Be Received
             $objNewAsset->AssetCode = $strAssetCode;
             // Set the AssetId to 0. This is so that it can be assigned to an AssetTransaction object without being saved to the db
             // We don't want to save this until btnSave_Click, because we don't want to create new assets that could get orphaned
             $objNewAsset->AssetId = 0;
             // This can be combined with the code below it
             $this->txtNewAssetCode->Text = null;
             $this->txtNewAssetCode->Enabled = true;
             $this->chkAutoGenerateAssetCode->Checked = false;
             $this->lstAssetModel->SelectedValue = null;
             $objNewAssetTransaction = new AssetTransaction();
             // The source location can either be 'Shipped'(2) or 'To Be Received'(5)
             $objNewAssetTransaction->SourceLocationId = $objNewAsset->LocationId;
             // $objNewAssetTransaction->AssetId = $objNewAsset->AssetId;
             $objNewAssetTransaction->Asset = $objNewAsset;
             $this->objAssetTransactionArray[] = $objNewAssetTransaction;
             // Set this boolean to true so that the datagrid updates
             $this->blnModifyAssets = true;
         }
     } elseif ($this->rblAssetType->SelectedValue == 'existing') {
         $strAssetCode = $this->txtNewAssetCode->Text;
         $blnDuplicate = false;
         $blnError = false;
         if ($strAssetCode) {
             // Begin error checking
             if ($this->objAssetTransactionArray) {
                 foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                     if ($objAssetTransaction && $objAssetTransaction->Asset->AssetCode == $strAssetCode) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = "That asset has already been added.";
                     }
                 }
             }
             if (!$blnError) {
                 $objNewAsset = Asset::LoadByAssetCode($this->txtNewAssetCode->Text);
                 if (!$objNewAsset instanceof Asset) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset tag does not exist.";
                 } elseif ($objNewAsset->LinkedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is locked to a parent asset.";
                 } elseif ($objNewAsset->ArchivedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is 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 (!($objNewAsset->LocationId == 5 || $objNewAsset->LocationId == 2)) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset has already been received.";
                 } elseif (!QApplication::AuthorizeEntityBoolean($objNewAsset, 2)) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "You do not have authorization to perform a transaction on this asset.";
                 } elseif ($objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objNewAsset->AssetId)) {
                     $strAssetCodeArray = array();
                     $objCheckedLinkedAssetArray = array();
                     foreach ($objLinkedAssetArray as $objLinkedAsset) {
                         if (!QApplication::AuthorizeEntityBoolean($objLinkedAsset, 2)) {
                             $blnError = true;
                             $this->txtNewAssetCode->Warning = sprintf("You do not have authorization to perform a transaction on locked asset %s.", $objLinkedAsset->AssetCode);
                             break;
                         } else {
                             $objCheckedLinkedAssetArray[] = $objLinkedAsset;
                             $strAssetCodeArray[] = $objLinkedAsset->AssetCode;
                         }
                         if (!$blnError) {
                             $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));
                         }
                     }
                     if (!$blnError) {
                         foreach ($objCheckedLinkedAssetArray as $objCheckedLinkedAsset) {
                             $objNewAssetTransaction = new AssetTransaction();
                             // We can assign the AssetId for existing assets because they have already been saved to the db
                             $objNewAssetTransaction->AssetId = $objCheckedLinkedAsset->AssetId;
                             // The source location can either be 'Shipped'(2) or 'To Be Received'(5)
                             $objNewAssetTransaction->SourceLocationId = $objCheckedLinkedAsset->LocationId;
                             $this->objAssetTransactionArray[] = $objNewAssetTransaction;
                         }
                     }
                 }
                 if (!$blnError) {
                     // Check that the asset isn't already in another pending receipt
                     $arrPendingReceipts = AssetTransaction::QueryArray(QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->AssetId, $objNewAsset->AssetId), QQ::In(QQN::AssetTransaction()->SourceLocationId, array(5, 2)), QQ::IsNull(QQN::AssetTransaction()->DestinationLocationId), QQ::NotEqual(QQN::AssetTransaction()->TransactionId, $this->objReceipt->TransactionId)));
                     if (!$blnError && count($arrPendingReceipts) != 0) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = 'That asset is already pending receipt.';
                     } elseif (!$blnError && ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId))) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = 'That asset is in a pending shipment.';
                     }
                 }
                 // Create a new, but incomplete AssetTransaction
                 if (!$blnError) {
                     $this->txtNewAssetCode->Text = null;
                     $this->txtNewAssetCode->Enabled = true;
                     $this->chkAutoGenerateAssetCode->Checked = false;
                     $this->lstAssetModel->SelectedValue = null;
                     $objNewAssetTransaction = new AssetTransaction();
                     // We can assign the AssetId for existing assets because they have already been saved to the db
                     $objNewAssetTransaction->AssetId = $objNewAsset->AssetId;
                     // The source location can either be 'Shipped'(2) or 'To Be Received'(5)
                     $objNewAssetTransaction->SourceLocationId = $objNewAsset->LocationId;
                     $this->objAssetTransactionArray[] = $objNewAssetTransaction;
                     // Set this boolean to true so that the datagrid updates
                     $this->blnModifyAssets = true;
                 }
             }
         }
     }
     $this->dtgAssetTransact->Refresh();
     $this->txtNewAssetCode->Focus();
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 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);
     }
 }
 /**
  * Load an array of AssetTransaction objects,
  * by ParentAssetTransactionId Index(es)
  * @param integer $intParentAssetTransactionId
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return AssetTransaction[]
  */
 public static function LoadArrayByParentAssetTransactionId($intParentAssetTransactionId, $objOptionalClauses = null)
 {
     // Call AssetTransaction::QueryArray to perform the LoadArrayByParentAssetTransactionId query
     try {
         return AssetTransaction::QueryArray(QQ::Equal(QQN::AssetTransaction()->ParentAssetTransactionId, $intParentAssetTransactionId), $objOptionalClauses);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }
Exemplo n.º 6
0
 /**
  * Load an array (excluding transactions for linked assets) of AssetTransaction objects,
  * by TransactionId Index(es)
  * @param integer $intTransactionId
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return AssetTransaction[]
  */
 public static function LoadArrayByTransactionIdLinkedFlag($intTransactionId, $objOptionalClauses = null)
 {
     // Call AssetTransaction::QueryArray to perform the LoadArrayByTransactionId query
     try {
         return AssetTransaction::QueryArray(QQ::AndCondition(QQ::Equal(QQN::AssetTransaction()->TransactionId, $intTransactionId), QQ::NotEqual(QQN::AssetTransaction()->Asset->LinkedFlag, true)), $objOptionalClauses);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }
 /**
  * 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 = AssetTransaction::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 AssetTransaction, given the clauses above
     $this->DataSource = AssetTransaction::QueryArray($objCondition, $objClauses);
 }