Exemple #1
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();
 }
Exemple #2
0
 /**
  * Returns the HTML needed for the asset list datagrid to show reserved and checked out by icons, with hovertips with the username.
  * If the asset is neither reserved nor checked out, it returns an empty string.
  *
  * @param QDatagrid Object $objControl
  * @return string
  */
 public function ToStringHoverTips($objControl)
 {
     if ($this->blnReservedFlag) {
         $lblReservedImage = new QLabelExt($objControl);
         $lblReservedImage->HtmlEntities = false;
         $lblReservedImage->Text = sprintf('<img src="%s/icons/reserved_datagrid.png" style="vertical-align:middle;">', __IMAGE_ASSETS__);
         $objHoverTip = new QHoverTip($lblReservedImage);
         $objHoverTip->Text = 'Reserved by ' . $this->GetLastTransactionUser()->__toString();
         $lblReservedImage->HoverTip = $objHoverTip;
         $strToReturn = $lblReservedImage->Render(false);
     } elseif ($this->blnCheckedOutFlag) {
         $lblCheckedOutImage = new QLabelExt($objControl);
         $lblCheckedOutImage->HtmlEntities = false;
         $lblCheckedOutImage->Text = sprintf('<img src="%s/icons/checked_out_datagrid.png" style="vertical-align:middle;">', __IMAGE_ASSETS__);
         $objHoverTip = new QHoverTip($lblCheckedOutImage);
         //$objHoverTip->Text = 'Checked Out by ' . $this->GetLastTransactionUser()->__toString();
         $arrObjects = $this->GetLastTransactionCheckoutObjectArray();
         $objAccount = $arrObjects['objAccount'];
         $objAssetTransactionCheckout = $arrObjects['objAssetTransactionCheckout'];
         $strReason = $arrObjects['strNote'];
         if (!$objAssetTransactionCheckout) {
             $objHoverTip->Text = 'Checked Out by ' . $objAccount->__toString();
         } else {
             $objHoverTip->Text = 'Checked Out to ';
             if ($objAssetTransactionCheckout->ToContactId) {
                 $objHoverTip->Text .= $objAssetTransactionCheckout->ToContact->__toString();
             } else {
                 $objHoverTip->Text .= $objAssetTransactionCheckout->ToUser->__toString();
             }
             $objHoverTip->Text .= ' by ' . $objAccount->__toString();
             if (QApplication::$TracmorSettings->ReasonRequired == "1" || $strReason) {
                 $objHoverTip->Text .= "<br />Reason: " . $strReason;
             }
             if (QApplication::$TracmorSettings->DueDateRequired == "1" || $objAssetTransactionCheckout->DueDate) {
                 $objHoverTip->Text .= sprintf("<br />Due Date: %s", $objAssetTransactionCheckout->DueDate ? $objAssetTransactionCheckout->DueDate->format('m/d/Y g:i A') : "");
             }
         }
         $lblCheckedOutImage->HoverTip = $objHoverTip;
         $strToReturn = $lblCheckedOutImage->Render(false);
     } elseif ($this->blnArchivedFlag) {
         $lblArchivedImage = new QLabelExt($objControl);
         $lblArchivedImage->HtmlEntities = false;
         $lblArchivedImage->Text = sprintf('<img src="%s/icons/archived_datagrid.png" style="vertical-align:middle;">', __IMAGE_ASSETS__);
         $objHoverTip = new QHoverTip($lblArchivedImage);
         $objHoverTip->Text = 'Archived by ' . $this->GetLastTransactionUser()->__toString();
         $lblArchivedImage->HoverTip = $objHoverTip;
         $strToReturn = $lblArchivedImage->Render(false);
     } elseif ($objPendingShipment = AssetTransaction::PendingShipment($this->AssetId)) {
         $lblShipmentImage = new QLabelExt($objControl);
         $lblShipmentImage->HtmlEntities = false;
         $lblShipmentImage->Text = sprintf('<img src="%s/icons/shipment_datagrid.png" style="Vertical-align:middle;">', __IMAGE_ASSETS__);
         $objHoverTip = new QHoverTip($lblShipmentImage);
         $objHoverTip->Text = 'Scheduled for Shipment by ' . $this->GetLastTransactionUser()->__toString();
         $lblShipmentImage->HoverTip = $objHoverTip;
         $strToReturn = $lblShipmentImage->Render(false);
     } elseif ($objPendingReceipt = AssetTransaction::PendingReceipt($this->AssetId)) {
         $lblReceiptImage = new QLabelExt($objControl);
         $lblReceiptImage->HtmlEntities = false;
         $lblReceiptImage->Text = sprintf('<img src="%s/icons/receipt_datagrid.png" style="Vertical-align:middle;">', __IMAGE_ASSETS__);
         $objHoverTip = new QHoverTip($lblReceiptImage);
         $objHoverTip->Text = 'Scheduled for Receipt by ' . $this->GetLastTransactionUser()->__toString();
         $lblReceiptImage->HoverTip = $objHoverTip;
         $strToReturn = $lblReceiptImage->Render(false);
     } else {
         $strToReturn = '';
     }
     return $strToReturn;
 }
Exemple #3
0
 $blnError = false;
 $arrCheckedAssetCode = array();
 foreach ($arrAssetCode as $strAssetCode) {
     if ($strAssetCode) {
         // Begin error checking
         $objNewAsset = Asset::LoadByAssetCode($strAssetCode);
         if (!$objNewAsset instanceof Asset) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset code does not exist.<br />";
         } elseif ($objNewAsset->LocationId == 2) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset has already been shipped.<br />";
         } elseif ($objNewAsset->LocationId == 5) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset is currently scheduled to be received.<br />";
         } elseif ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId)) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset is already in a pending shipment.<br />";
         } elseif ($objNewAsset->CheckedOutFlag) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset is already checked out.<br />";
         } elseif ($objNewAsset->ReservedFlag) {
             $blnError = true;
             $strWarning .= $strAssetCode . " - That asset is reserved.<br />";
         } else {
             $arrCheckedAssetCode[] = $strAssetCode;
         }
         if (!$blnError && $objNewAsset instanceof Asset) {
             $objAssetArray[] = $objNewAsset;
         }
     } else {
 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();
 }
Exemple #5
0
 public function btnAddAsset_Click($strFormId, $strControlId, $strParameter)
 {
     // Clear if warning from previous attempt exists
     $this->txtNewAssetCode->Warning = '';
     $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->LocationId == 1) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset is checked out.";
             } 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 ($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 (!QApplication::AuthorizeEntityBoolean($objNewAsset, 2)) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "You do not have authorization to perform a transaction on this asset.";
             } else {
                 $objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objNewAsset->AssetId);
                 $strAssetCodeArray = array();
                 $objCheckedLinkedAssetArray = array();
                 if ($objLinkedAssetArray) {
                     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 {
                             $strAssetCodeArray[] = $objLinkedAsset->AssetCode;
                             $objCheckedLinkedAssetArray[] = $objLinkedAsset;
                         }
                     }
                     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 ($objNewAsset && ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId))) {
                 if ($objPendingShipment->TransactionId != $this->objShipment->TransactionId) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset was already scheduled for shipment.";
                 } else {
                     if ($this->arrAssetTransactionToDelete) {
                         foreach ($this->arrAssetTransactionToDelete as $key => $value) {
                             if ($value) {
                                 $objOffendingAssetTransaction = AssetTransaction::Load($value);
                                 if ($objOffendingAssetTransaction->AssetId == $objNewAsset->AssetId) {
                                     $objOffendingAssetTransaction->Delete();
                                     unset($this->arrAssetTransactionToDelete[$key]);
                                 }
                             }
                         }
                     }
                 }
             }
             /*					elseif ($this->lblAdvanced->Text == 'Hide Advanced' && $this->chkScheduleReceipt->Checked && $this->rblAssetType->SelectedValue == 'new' && !$this->chkAutoGenerateAssetCode->Checked && $this->txtReceiptAssetCode->Text == '') {
             						$blnError = true;
             						$this->txtReceiptAssetCode->Warning = "You must provide an asset tag for the new asset.";
             					}*/
             // Create a new, but incomplete AssetTransaction
             if (!$blnError) {
                 // Clear out the AssetCode field
                 $this->txtNewAssetCode->Text = null;
                 $objNewAssetTransaction = new AssetTransaction();
                 // $objNewAssetTransaction->Asset = $objNewAsset;
                 $objNewAssetTransaction->AssetId = $objNewAsset->AssetId;
                 $objNewAssetTransaction->SourceLocationId = $objNewAsset->LocationId;
                 // If scheduling a receipt for this asset
                 /*						if ($this->lblAdvanced->Text == "Hide Advanced" && $this->chkScheduleReceipt->Checked) {
                 							// If creating a new asset
                 							if ($this->rblAssetType->SelectedValue == 'new') {
                 								$objReceiptAsset = new Asset();
                 								// AssetId must be set so that it can be assigned to the AssetTransaction
                 								$objReceiptAsset->AssetId = 0;
                 								// The new receipt asset will be the same AssetModel as the asset being shipped (but a new asset)
                 								$objReceiptAsset->AssetModelId = $objNewAsset->AssetModelId;
                 								// Set Location to TBR
                 								$objReceiptAsset->LocationId = 5;
                 								// Set the asset tag to empty so that we'll know to auto generate later
                 								if ($this->chkAutoGenerateAssetCode->Checked) {
                 									$strAssetCode = '';
                 								}
                 								else {
                 									$strAssetCode = $this->txtReceiptAssetCode->Text;
                 								}
                 								$objReceiptAsset->AssetCode = $strAssetCode;
                 								$objNewAssetTransaction->NewAsset = $objReceiptAsset;
                 							}
                 							// Set this flag so that it will schedule this asset for receipt once the shipment is completed
                 							$objNewAssetTransaction->ScheduleReceiptFlag = true;
                 							$this->lblAdvanced_Click($this->FormId, $this->lblAdvanced->ControlId, null);
                 						}*/
                 $this->objAssetTransactionArray[] = $objNewAssetTransaction;
                 $this->blnModifyAssets = true;
                 foreach ($objCheckedLinkedAssetArray as $objCheckedLinkedAsset) {
                     $objPendingShipment = AssetTransaction::PendingShipment($objCheckedLinkedAsset->AssetId);
                     $objLinkedAssetTransaction = new AssetTransaction();
                     $objLinkedAssetTransaction->AssetId = $objCheckedLinkedAsset->AssetId;
                     $objLinkedAssetTransaction->SourceLocationId = $objCheckedLinkedAsset->LocationId;
                     $this->objAssetTransactionArray[] = $objLinkedAssetTransaction;
                 }
             }
             $this->dtgAssetTransact->Refresh();
         }
     } else {
         $this->txtNewAssetCode->Warning = 'Please enter an asset tag.';
         $blnError = true;
     }
     $this->txtNewAssetCode->Focus();
     $this->txtNewAssetCode->Select();
 }
 /**
  * Return a boolean if there is a pending transaction
  * @param integer $intAssetId
  * @return bool
  */
 public static function PendingTransaction($intAssetId)
 {
     if ($objPendingShipment = AssetTransaction::PendingShipment($intAssetId) || ($objPendingReceipt = AssetTransaction::PendingReceipt($intAssetId))) {
         return true;
     } else {
         return false;
     }
 }
 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) {
             $objNewAsset = Asset::LoadByAssetCode($this->txtNewAssetCode->Text);
             if (!$objNewAsset instanceof Asset) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset code does not exist.";
             } 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 ($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.";
                     }
                 }
             }
             if (!$blnError && $objNewAsset instanceof Asset) {
                 $this->objAssetArray[] = $objNewAsset;
                 $this->txtNewAssetCode->Text = null;
             }
         }
     } else {
         $this->txtNewAssetCode->Warning = "Please enter an asset code.";
     }
 }
Exemple #8
0
 public function btnAddAsset_Click($strFormId, $strControlId, $strParameter)
 {
     if ($this->rblAssetType->SelectedValue == 'new') {
         $blnError = false;
         // 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 code.';
             }
         }
         // Generate an error if that asset code already exists
         if ($objDuplicate = Asset::LoadByAssetCode($strAssetCode)) {
             $blnError = true;
             $this->txtNewAssetCode->Warning = 'That asset code already exists. Choose another.';
         }
         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 code does not exist.";
                 } 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 ($objNewAsset && ($objPendingReceipt = AssetTransaction::PendingReceipt($objNewAsset->AssetId))) {
                     if ($this->blnEditMode && $objPendingReceipt->TransactionId != $this->objReceipt->TransactionId || !$this->blnEditMode) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = 'That asset is already pending receipt.';
                     } else {
                         if ($this->arrAssetTransactionToDelete) {
                             foreach ($this->arrAssetTransactionToDelete as $key => $value) {
                                 if ($value) {
                                     $objOffendingAssetTransaction = AssetTransaction::Load($value);
                                     if ($objOffendingAssetTransaction->AssetId == $objNewAsset->AssetId) {
                                         $objOffendingAssetTransaction->Delete();
                                         unset($this->arrAssetTransactionToDelete[$key]);
                                     }
                                 }
                             }
                         }
                     }
                 } elseif ($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;
                 }
             }
         }
     }
 }