Exemplo n.º 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();
 }
Exemplo n.º 2
0
$arrCheckedAssetCode = "";
$strJavaScriptCode = "";
if ($_POST && $_POST['method'] == 'complete_transaction') {
    /*
    Run error checking on the array of asset codes and the destination location
    If there are no errors, then you will add the transaction to the database.
    	That will include an entry in the Transaction and Asset Transaction table.
    	You will also have to change the asset.location_id to the destination location
    */
    $arrAssetCode = array_unique(explode('#', $_POST['result']));
    $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 />";
Exemplo n.º 3
0
 protected function btnAddChild_Click()
 {
     if ($this->txtAddChild->Text) {
         $objChildAsset = Asset::LoadByAssetCode($this->txtAddChild->Text);
         if ($objChildAsset) {
             // check if asset already within removed child assets
             $blnAssetNotRemoved = true;
             if (is_array($this->ctlAssetEdit->objRemovedChildAssetArray)) {
                 $newRemovedChildAssetArray = array();
                 foreach ($this->ctlAssetEdit->objRemovedChildAssetArray as $removedAsset) {
                     if ($removedAsset->AssetId == $objChildAsset->AssetId) {
                         $blnAssetNotRemoved = false;
                     } else {
                         $newRemovedChildAssetArray[] = $removedAsset;
                     }
                 }
                 if ($blnAssetNotRemoved == false) {
                     $this->ctlAssetEdit->objRemovedChildAssetArray = $newRemovedChildAssetArray;
                 }
             }
             if ($objChildAsset->ParentAssetId && $blnAssetNotRemoved) {
                 $this->txtAddChild->Warning = "That asset tag already have the parent asset tag. Please try another.";
             } elseif ($objChildAsset->AssetCode == $this->objAsset->AssetCode) {
                 $this->txtAddChild->Warning = "That asset tag does not exist. Please try another.";
             } else {
                 $objChildAsset->LinkedFlag = false;
                 $objChildAsset->ParentAssetId = $this->objAsset->AssetId;
                 array_push($this->ctlAssetEdit->objChildAssetArray, $objChildAsset);
                 $this->txtAddChild->Text = "";
                 $this->dtgChildAssets_Bind();
             }
         } else {
             $this->txtAddChild->Warning = "That asset tag does not exist. Please try another.";
         }
     } else {
         $this->txtAddChild->Warning = "";
     }
 }
Exemplo n.º 4
0
 protected function btnSaveExchange_Click($strFormId, $strControlId, $strParameter)
 {
     $intTempId = $this->dlgExchange->ActionParameter;
     $blnError = false;
     if ($this->chkAutoGenerateAssetCode->Checked) {
         $strAssetCode = '';
         $this->txtReceiptAssetCode->Text = '';
     } elseif ($this->txtReceiptAssetCode->Text) {
         $objAsset = Asset::LoadByAssetCode($this->txtReceiptAssetCode->Text);
         if ($objAsset) {
             $blnError = true;
             $this->txtReceiptAssetCode->Warning = 'That asset tag is already in use. Please input another.';
         } else {
             $strAssetCode = $this->txtReceiptAssetCode->Text;
         }
     }
     if (!$blnError) {
         if ($this->objAssetTransactionArray) {
             foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                 if ($objAssetTransaction->NewAsset instanceof Asset && $objAssetTransaction->NewAsset->AssetCode == $strAssetCode) {
                     $blnError = true;
                     $this->txtReceiptAssetCode->Warning = 'That asset tag is already in use. Please input another.';
                 }
                 if (!$blnError) {
                     if ($objAssetTransaction->Asset->TempId == $intTempId) {
                         $objAssetTransaction->ScheduleReceiptFlag = true;
                         $objAssetTransaction->NewAssetFlag = true;
                         $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 = $objAssetTransaction->Asset->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 = '';
                         			$this->txtReceiptAssetCode->Text = '';
                         		}
                         		else {
                         			$strAssetCode = $this->txtReceiptAssetCode->Text;
                         		}*/
                         $objReceiptAsset->AssetCode = $strAssetCode;
                         $objAssetTransaction->NewAsset = $objReceiptAsset;
                     }
                 }
             }
         }
         if (!$blnError) {
             $this->dlgExchange->ActionParameter = null;
             $this->dlgExchange->HideDialogBox();
         }
     }
 }
Exemplo n.º 5
0
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         // Get an instance of the database
         $objDatabase = QApplication::$Database[1];
         // Begin a MySQL Transaction to be either committed or rolled back
         $objDatabase->TransactionBegin();
         // Generate a new AssetCode based on the MinAssetCode value
         // This happens whether or not they are creating a new one or editing an existing one
         if ($this->chkAutoGenerateAssetCode->Checked) {
             $this->txtAssetCode->Text = Asset::GenerateAssetCode();
         }
         $this->objAsset->AssetCode = $this->txtAssetCode->Text;
         $this->objAsset->AssetModelId = $this->lstAssetModel->SelectedValue;
         $blnError = false;
         // If a new asset is being created
         if (!$this->blnEditMode) {
             // Do not allow creation of an asset if asset limit will be exceeded
             $intAssetLimit = is_numeric(QApplication::$TracmorSettings->AssetLimit) ? QApplication::$TracmorSettings->AssetLimit : false;
             if (!$this->blnEditMode) {
                 if ($intAssetLimit && Asset::CountActive() >= $intAssetLimit) {
                     $blnError = true;
                     $this->txtAssetCode->Warning = "Your asset limit has been reached.";
                 }
             }
             // Check to see if the asset code already exists
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset code is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                     $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                     if (!$objParentAsset) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "That asset code does not exist. Please try another.";
                     } else {
                         if ($this->chkLockToParent->Checked && $objParentAsset->LocationId != $this->lstLocation->SelectedValue) {
                             // If locking child to parent, make sure assets are at the same location
                             $blnError = true;
                             $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                         } else {
                             if ($this->chkLockToParent->Checked && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = "Parent asset code (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                             } else {
                                 $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                 if ($this->chkLockToParent->Checked) {
                                     $this->objAsset->LinkedFlag = 1;
                                 }
                             }
                         }
                     }
                 } else {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "Parent asset code must not be the same as asset code. Please try another.";
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
             }
             if (!$blnError) {
                 // Location can only be decided when creating an asset. Otherwise they must conduct a transaction.
                 if (!$this->blnEditMode) {
                     $this->objAsset->LocationId = $this->lstLocation->SelectedValue;
                 }
                 // Save child assets
                 $this->SaveChildAssets();
                 // Object should be saved only if it is new, to obtain the proper AssetId to add to the custom field tables
                 $this->objAsset->Save();
                 $this->objParentObject->RefreshChildAssets();
             }
         }
         // Assign input values to custom fields
         if ($this->arrCustomFields && !$blnError) {
             // Save the values from all of the custom field controls to save the asset
             CustomField::SaveControls($this->objAsset->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objAsset->AssetId, 1);
         }
         if ($this->blnEditMode) {
             // Check to see if the asset code already exists (and is not the asset code of the asset that the user is currently editing
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate && $AssetDuplicate->AssetId != $this->objAsset->AssetId) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset code is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 // Check if the parent asset code is already a child asset of this asset
                 $arrChildAsset = Asset::LoadArrayByParentAssetId($this->objAsset->AssetId);
                 foreach ($arrChildAsset as $objChildAsset) {
                     if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset code is already a child of this asset. Please try another.";
                         break;
                     }
                 }
                 if (!$blnError) {
                     if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                         $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                         if (!$objParentAsset) {
                             $blnError = true;
                             $this->txtParentAssetCode->Warning = "That asset code does not exist. Please try another.";
                         } else {
                             if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $this->objAsset->LocationId) {
                                 // If locking child to parent, make sure assets are at the same location
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                             } else {
                                 if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                     $blnError = true;
                                     $this->chkLockToParent->Warning = "Parent asset code (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                 } else {
                                     if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($this->objAsset->CheckedOutFlag || $this->objAsset->ReservedFlag || $this->objAsset->ArchivedFlag || $this->objAsset->LocationId == 2 || $this->objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($this->objAsset->AssetId))) {
                                         $blnError = true;
                                         $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                     } else {
                                         $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                         if ($this->chkLockToParent->Checked) {
                                             $this->objAsset->LinkedFlag = 1;
                                         } else {
                                             $this->objAsset->LinkedFlag = 0;
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset code must not be the same as asset code. Please try another.";
                     }
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
                 $this->chkLockToParent->Checked = false;
             }
             if (!$blnError) {
                 // Update the values of all fields for an Ajax reload
                 $this->UpdateAssetFields();
                 // Save child assets
                 $this->SaveChildAssets();
                 // If asset is not new, it must be saved after updating the assetfields
                 $this->objAsset->Save();
                 // This is called to retrieve the new Modified Date and User
                 $this->objParentObject->SetupAsset($this);
                 // Give the labels their appropriate values before display
                 $this->UpdateAssetLabels();
                 // This was necessary because it was not saving the changes of a second edit/save in a row
                 // Reload all custom fields
                 $this->objAsset->objCustomFieldArray = CustomField::LoadObjCustomFieldArray(1, $this->blnEditMode, $this->objAsset->AssetId);
                 // Commit the above transactions to the database
                 $objDatabase->TransactionCommit();
                 // Hide inputs and display labels
                 $this->displayLabels();
                 // Enable the appropriate transaction buttons
                 $this->EnableTransactionButtons();
                 $this->objParentObject->RefreshChildAssets();
             }
         } elseif (!$blnError) {
             // Commit the above transactions to the database
             $objDatabase->TransactionCommit();
             // Reload the edit asset page with the newly created asset
             $strRedirect = sprintf('asset_edit.php?intAssetId=%s', $this->objAsset->AssetId);
             QApplication::Redirect($strRedirect);
         }
     } catch (QOptimisticLockingException $objExc) {
         // Rollback the database
         $objDatabase->TransactionRollback();
         // Output the error
         $this->btnCancel->Warning = sprintf('This asset has been updated by another user. You must <a href="asset_edit.php?intAssetId=%s">Refresh</a> to edit this Asset.', $this->objAsset->AssetId);
     }
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         // Get an instance of the database
         $objDatabase = QApplication::$Database[1];
         // Begin a MySQL Transaction to be either committed or rolled back
         $objDatabase->TransactionBegin();
         // Generate a new AssetCode based on the MinAssetCode value
         // This happens whether or not they are creating a new one or editing an existing one
         if ($this->chkAutoGenerateAssetCode->Checked) {
             $this->txtAssetCode->Text = Asset::GenerateAssetCode();
         }
         $this->objAsset->AssetCode = $this->txtAssetCode->Text;
         $this->objAsset->AssetModelId = $this->lstAssetModel->SelectedValue;
         $blnError = false;
         // If a new asset is being created
         if (!$this->blnEditMode) {
             // Do not allow creation of an asset if asset limit will be exceeded
             $intAssetLimit = is_numeric(QApplication::$TracmorSettings->AssetLimit) ? QApplication::$TracmorSettings->AssetLimit : false;
             if (!$this->blnEditMode) {
                 if ($intAssetLimit && Asset::CountActive() >= $intAssetLimit) {
                     $blnError = true;
                     $this->txtAssetCode->Warning = "Your asset limit has been reached.";
                 }
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost value isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 }
             }
             // Check to see if the asset tag already exists
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                     $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                     if (!$objParentAsset) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                     } else {
                         if ($this->chkLockToParent->Checked && $objParentAsset->LocationId != $this->lstLocation->SelectedValue) {
                             // If locking child to parent, make sure assets are at the same location
                             $blnError = true;
                             $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                         } else {
                             if ($this->chkLockToParent->Checked && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                             } else {
                                 $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                 if ($this->chkLockToParent->Checked) {
                                     $this->objAsset->LinkedFlag = 1;
                                 }
                             }
                         }
                     }
                 } else {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
             }
             if (!$blnError) {
                 // Location can only be decided when creating an asset. Otherwise they must conduct a transaction.
                 if (!$this->blnEditMode) {
                     $this->objAsset->LocationId = $this->lstLocation->SelectedValue;
                 }
                 // Save child assets
                 $this->SaveChildAssets();
                 // Object should be saved only if it is new, to obtain the proper AssetId to add to the custom field tables
                 $this->objAsset->Save();
                 $this->objParentObject->RefreshChildAssets();
             }
         }
         // Assign input values to custom fields
         if (is_array($this->arrCustomFields) && count($this->arrCustomFields) > 0 && !$blnError) {
             // Save the values from all of the custom field controls to save the asset
             CustomField::SaveControls($this->objAsset->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objAsset->AssetId, 1);
         }
         if ($this->blnEditMode) {
             // Check to see if the asset tag already exists (and is not the asset tag of the asset that the user is currently editing
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate && $AssetDuplicate->AssetId != $this->objAsset->AssetId) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 // Check if the parent asset tag is already a child asset of this asset
                 $arrChildAsset = Asset::LoadArrayByParentAssetId($this->objAsset->AssetId);
                 foreach ($arrChildAsset as $objChildAsset) {
                     if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag is already a child of this asset. Please try another.";
                         break;
                     }
                 }
                 if (!$blnError) {
                     if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                         $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                         if (!$objParentAsset) {
                             $blnError = true;
                             $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                         } else {
                             if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $this->objAsset->LocationId) {
                                 // If locking child to parent, make sure assets are at the same location
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                             } else {
                                 if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                     $blnError = true;
                                     $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                 } else {
                                     if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($this->objAsset->CheckedOutFlag || $this->objAsset->ReservedFlag || $this->objAsset->ArchivedFlag || $this->objAsset->LocationId == 2 || $this->objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($this->objAsset->AssetId))) {
                                         $blnError = true;
                                         $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                     } else {
                                         $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                         if ($this->chkLockToParent->Checked) {
                                             $this->objAsset->LinkedFlag = 1;
                                         } else {
                                             $this->objAsset->LinkedFlag = 0;
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                     }
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
                 $this->chkLockToParent->Checked = false;
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 } else {
                     $this->objAsset->DepreciationFlag = false;
                     $this->objAsset->PurchaseDate = null;
                     $this->objAsset->PurchaseCost = null;
                 }
             }
             if (!$blnError) {
                 // Update the values of all fields for an Ajax reload
                 $this->UpdateAssetFields();
                 // Save child assets
                 $this->SaveChildAssets();
                 // If asset is not new, it must be saved after updating the assetfields
                 $this->objAsset->Save();
                 // This is called to retrieve the new Modified Date and User
                 $this->objParentObject->SetupAsset($this);
                 // Give the labels their appropriate values before display
                 $this->UpdateAssetLabels();
                 // This was necessary because it was not saving the changes of a second edit/save in a row
                 // Reload all custom fields
                 $this->objAsset->objCustomFieldArray = CustomField::LoadObjCustomFieldArray(1, $this->blnEditMode, $this->objAsset->AssetId, false, $this->objAsset->AssetModelId);
                 // Update not allowed custom fields set to null
                 $arrAllowed = array();
                 foreach (AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAsset->AssetModelId) as $objAssetCustomField) {
                     $arrAllowed[] = $objAssetCustomField->CustomFieldId;
                 }
                 $arrToClear = array();
                 foreach (EntityQtypeCustomField::LoadArrayByEntityQtypeId(1) as $objAssetCustomField) {
                     if (!in_array($objAssetCustomField->CustomFieldId, $arrAllowed) && $objAssetCustomField->CustomField->AllAssetModelsFlag != 1) {
                         $arrToClear[] = $objAssetCustomField->CustomFieldId;
                     }
                 }
                 if ($this->objAsset->AssetId && count($arrToClear)) {
                     $arrForQuery = array();
                     foreach ($arrToClear as $idToBeNull) {
                         $arrForQuery[] = sprintf("`cfv_%s`= NULL", $idToBeNull);
                     }
                     $objDatabase = Asset::GetDatabase();
                     $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $arrForQuery), $this->objAsset->AssetId);
                     //  print($strQuery); exit;
                     $objDatabase->NonQuery($strQuery);
                 }
                 // Commit the above transactions to the database
                 $objDatabase->TransactionCommit();
                 // Hide inputs and display labels
                 $this->displayLabels();
                 // Enable the appropriate transaction buttons
                 $this->EnableTransactionButtons();
                 $this->objParentObject->RefreshChildAssets();
             }
         } elseif (!$blnError) {
             // Commit the above transactions to the database
             $objDatabase->TransactionCommit();
             // Reload the edit asset page with the newly created asset
             $strRedirect = sprintf('asset_edit.php?intAssetId=%s', $this->objAsset->AssetId);
             QApplication::Redirect($strRedirect);
         }
     } catch (QOptimisticLockingException $objExc) {
         // Rollback the database
         $objDatabase->TransactionRollback();
         // Output the error
         $this->btnCancel->Warning = sprintf('This asset has been updated by another user. You must <a href="asset_edit.php?intAssetId=%s">Refresh</a> to edit this Asset.', $this->objAsset->AssetId);
     }
 }
 public function btnApply_Click($strFormId, $strControlId, $strParameter)
 {
     $this->EnableSelectedControls();
     $this->ClearWarnings();
     $blnError = false;
     // Make sure at least one checkbox is checked
     if (!$this->chkModel->Checked && !$this->chkParentAssetCode->Checked && !$this->chkChkLockToParent->Checked) {
         $blnChecked = false;
         foreach ($this->arrCheckboxes as $objCheckBox) {
             if ($objCheckBox->Checked) {
                 $blnChecked = true;
                 break;
             }
         }
         if (!$blnChecked) {
             $blnError = true;
             $this->btnCancel->Warning = 'You must select at least one field to edit.';
             return;
         }
     }
     // If Model is checked, make sure a model is selected
     if ($this->chkModel->Checked && $this->lstModel->SelectedValue == null) {
         $blnError = true;
         $this->lstModel->Warning = 'You must select a Model.';
         return;
     }
     // Get an instance of the database
     $objDatabase = QApplication::$Database[1];
     // Begin a MySQL Transaction to be either committed or rolled back
     $objDatabase->TransactionBegin();
     $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId));
     if (count($this->arrCustomFields) > 0) {
         $customFieldIdArray = array();
         foreach ($this->arrCustomFields as $field) {
             if ($this->arrCheckboxes[$field['input']->strControlId]->Checked) {
                 if ($field['input'] instanceof QTextBox && $field['input']->Required && $field['input']->Text == null || $field['input'] instanceof QListBox && $field['input']->Required && $field['input']->SelectedValue == null) {
                     $blnError = true;
                     $field['input']->Warning = "Required.";
                 } else {
                     $this->arrCustomFieldsToEdit[] = $field;
                     $customFieldIdArray[] = (int) str_replace('cf', '', $field['input']->strControlId);
                 }
             }
         }
     }
     foreach ($this->arrAssetToEdit as $intAssetToEditId) {
         $objAsset = Asset::Load($intAssetToEditId);
         // First check that the user is authorized to edit this asset
         if (!QApplication::AuthorizeEntityBoolean($objAsset, 2)) {
             $blnError = true;
             $this->btnCancel->Warning = 'You are not authorized to edit one or more of the selected assets.';
             break;
         }
         if ($this->chkParentAssetCode->Checked && $this->txtParentAssetCode->Text) {
             // Check if the parent asset tag is already a child asset of this asset
             $arrChildAsset = Asset::LoadArrayByParentAssetId($intAssetToEditId);
             foreach ($arrChildAsset as $objChildAsset) {
                 if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "Parent asset tag is already a child of this asset.";
                     break 2;
                 }
             }
             if ($this->txtParentAssetCode->Text != $objAsset->AssetCode) {
                 $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                 if (!$objParentAsset) {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "That asset tag does not exist.";
                     break;
                 } else {
                     if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $objAsset->LocationId) {
                         // If locking child to parent, make sure assets are at the same location
                         $blnError = true;
                         $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                         break;
                     } else {
                         if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                             $blnError = true;
                             $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                             break;
                         } else {
                             if ($this->chkLockToParent->Checked && !($objAsset->ParentAssetId == $objParentAsset->AssetId && $objAsset->LinkedFlag == 1) && ($objAsset->CheckedOutFlag || $objAsset->ReservedFlag || $objAsset->ArchivedFlag || $objAsset->LocationId == 2 || $objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objAsset->AssetId))) {
                                 $blnError = true;
                                 $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                 break;
                             } else {
                                 $objAsset->ParentAssetId = $objParentAsset->AssetId;
                                 if ($this->chkLockToParent->Checked) {
                                     $objAsset->LinkedFlag = 1;
                                 } else {
                                     $objAsset->LinkedFlag = 0;
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $blnError = true;
                 $this->txtParentAssetCode->Warning = "Asset cannot be assigned as its own parent.";
                 break;
             }
         } else {
             if ($this->chkChkLockToParent->Checked && $this->chkLockToParent->Checked) {
                 // Make sure assets have a parent to lock to if lock is checked and no parent being assigned
                 $objAsset = Asset::Load($intAssetToEditId);
                 if (!$objAsset->ParentAssetId) {
                     $blnError = true;
                     $this->chkLockToParent->Warning = 'Asset cannot be locked without a parent assigned.';
                     break;
                 }
             }
         }
     }
     // Apply checked main_table fields
     if ($this->chkModel->Checked) {
         $set[] = sprintf('`asset_model_id`="%s"', $this->lstModel->SelectedValue);
     }
     if ($this->chkChkLockToParent->Checked) {
         $set[] = sprintf('`linked_flag`=%s', $this->chkLockToParent->Checked ? 1 : "NULL");
     }
     if ($this->chkParentAssetCode->Checked) {
         $parent_asset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
         if ($parent_asset instanceof Asset) {
             $parent_asset_id = $parent_asset->AssetId;
         } else {
             $parent_asset_id = "NULL";
             $set[] = sprintf('`linked_flag`=%s', "NULL");
         }
         $set[] = sprintf('`parent_asset_id`=%s', $parent_asset_id);
     }
     // Force modified_date timestamp update
     $set[] = '`modified_date` = NOW()';
     if (!$blnError) {
         try {
             if (count($this->arrCustomFieldsToEdit) > 0) {
                 // preparing data to edit
                 // Save the values from all of the custom field controls to save the asset
                 foreach ($this->arrAssetToEdit as $intAssetId) {
                     $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::Asset, false, null, false, 'all');
                     $selectedCustomFieldsArray = array();
                     foreach ($objCustomFieldsArray as $objCustomField) {
                         if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) {
                             $selectedCustomFieldsArray[] = $objCustomField;
                         }
                     }
                     CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intAssetId, EntityQtype::Asset);
                 }
             }
             // Edit TransAction
             // Update main table
             $strQuery = sprintf("UPDATE `asset`\n\t\t\t\t\t\t\tSET " . implode(",", $set) . " WHERE `asset_id` IN (%s)", implode(",", $this->arrAssetToEdit));
             //print $strQuery; exit;
             $objDatabase->NonQuery($strQuery);
             $objDatabase->TransactionCommit();
             QApplication::Redirect('');
         } catch (QMySqliDatabaseException $objExc) {
             $objDatabase->TransactionRollback();
             throw new QDatabaseException();
         }
     } else {
         $objDatabase->TransactionRollback();
     }
 }
 public 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->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::LoadChildLinkedArrayByParentAssetId($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));
                 }
                 $this->dtgAssetTransact->Refresh();
             }
         }
     } else {
         $this->txtNewAssetCode->Warning = "Please enter an asset code.";
     }
     $this->txtNewAssetCode->Focus();
     $this->txtNewAssetCode->Select();
 }
 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.";
     }
 }
Exemplo n.º 10
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;
                 }
             }
         }
     }
 }