public function userpic()
 {
     $userpic_id = $this->author_userpic_asset_id;
     if (empty($userpic_id) || !is_numeric($userpic_id)) {
         return;
     }
     require_once 'class.mt_asset.php';
     $asset = new Asset();
     $asset->Load("asset_id = {$userpic_id}");
     return $asset;
 }
 public function asset()
 {
     $col_name = "objectasset_asset_id";
     $asset = null;
     if (isset($this->{$col_name}) && is_numeric($this->{$col_name})) {
         $asset_id = $this->{$col_name};
         require_once 'class.mt_asset.php';
         $asset = new Asset();
         $asset->Load("asset_id = {$asset_id}");
     }
     return $asset;
 }
 protected function SetupAsset()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intAssetId = QApplication::QueryString('intAssetId');
     if ($intAssetId) {
         $this->objAsset = Asset::Load($intAssetId);
         if (!$this->objAsset) {
             throw new Exception('Could not find a Asset object with PK arguments: ' . $intAssetId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objAsset = new Asset();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
Exemple #4
0
 public function SetupAsset($objCaller = null)
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     // Overridden from AssetEditFormBase to add the $objCaller parameter
     $intAssetId = QApplication::QueryString('intAssetId');
     if ($intAssetId) {
         $objCaller->objAsset = Asset::Load($intAssetId);
         if (!$objCaller->objAsset) {
             throw new Exception('Could not find a Asset object with PK arguments: ' . $intAssetId);
         }
         $objCaller->strTitleVerb = QApplication::Translate('Edit');
         $objCaller->blnEditMode = true;
     } else {
         $objCaller->objAsset = new Asset();
         $objCaller->strTitleVerb = QApplication::Translate('Create');
         $objCaller->blnEditMode = false;
     }
     QApplication::AuthorizeEntity($objCaller->objAsset, $objCaller->blnEditMode);
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     $this->btnCancel->Warning = "";
     if ($this->objAssetArray) {
         $blnError = false;
         foreach ($this->objAssetArray as $asset) {
             // TransactionTypeId = 1 is for moves
             if ($this->intTransactionTypeId == 1) {
                 if ($asset->LocationId == $this->lstLocation->SelectedValue) {
                     $this->dtgAssetTransact->Warning = 'Cannot move an asset from a location to the same location.';
                     $blnError = true;
                 }
             }
             // For all transactions except Unreserve, make sure the asset is not already reserved
             if ($this->intTransactionTypeId != 9 && $asset->ReservedFlag) {
                 $this->btnCancel->Warning = sprintf('The Asset %s is reserved.', $asset->AssetCode);
                 $blnError = true;
             }
             // For all transactions except Unarchive, make sure the asset is not already archived
             if ($this->intTransactionTypeId != 11 && $asset->ArchivedFlag) {
                 $this->btnCancel->Warning = sprintf('The Asset %s is archived.', $asset->AssetCode);
                 $blnError = true;
             }
         }
         if (!$blnError) {
             if ($this->intTransactionTypeId == 3) {
                 $this->lstCheckOutTo->Warning = '';
                 $this->lstDueDate->Warning = '';
                 $intToUser = "";
                 $intToContact = "";
                 $dttDueDate = "";
                 if ((QApplication::$TracmorSettings->CheckOutToOtherUsers == "1" || QApplication::$TracmorSettings->CheckOutToContacts == "1") && $this->lstCheckOutTo->Display) {
                     if ($this->lstCheckOutTo->SelectedValue == "1") {
                         if (!$this->lstUser->SelectedValue) {
                             $this->lstCheckOutTo->Warning = 'Please select a user.';
                             $blnError = true;
                         } else {
                             $intToUser = $this->lstUser->SelectedValue;
                         }
                     } elseif ($this->lstCheckOutTo->SelectedValue == "2") {
                         if (!$this->lstToContact->SelectedValue) {
                             $this->lstCheckOutTo->Warning = 'Please select a contact.';
                             $blnError = true;
                         } else {
                             $intToContact = $this->lstToContact->SelectedValue;
                         }
                     } else {
                         $this->lstCheckOutTo->Warning = 'Please select one of the options';
                         $blnError = true;
                     }
                 } else {
                     $intToUser = QApplication::$objUserAccount->UserAccountId;
                 }
                 if ($this->lstDueDate->Display) {
                     if ($this->lstDueDate->SelectedValue == 2) {
                         $dttDueDate = $this->dttDueDate;
                         if ($dttDueDate && $dttDueDate->DateTime < QDateTime::Now()) {
                             $this->lstDueDate->Warning = 'Due date must be a future date';
                             $blnError = true;
                         }
                     } elseif (QApplication::$TracmorSettings->DueDateRequired == "1") {
                         $this->lstDueDate->Warning = 'Due date is required';
                         $blnError = true;
                     }
                 }
             }
             if (QApplication::$TracmorSettings->ReasonRequired == "1" && !trim($this->txtNote->Text) && $this->intTransactionTypeId == 3) {
                 $this->txtNote->Warning = 'Reason is required.';
                 $blnError = true;
             } elseif (($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 2 || $this->intTransactionTypeId == 11) && is_null($this->lstLocation->SelectedValue)) {
                 $this->lstLocation->Warning = 'Location is required.';
                 $blnError = true;
             } elseif ($this->txtNote->Text == '' && $this->intTransactionTypeId != 3) {
                 $this->txtNote->Warning = 'Note is required.';
                 $blnError = true;
             }
         }
         if (!$blnError) {
             try {
                 // Get an instance of the database
                 $objDatabase = QApplication::$Database[1];
                 // Begin a MySQL Transaction to be either committed or rolled back
                 $objDatabase->TransactionBegin();
                 // Create the new transaction object and save it
                 $this->objTransaction = new Transaction();
                 // Entity Qtype is Asset
                 $this->objTransaction->EntityQtypeId = EntityQtype::Asset;
                 $this->objTransaction->TransactionTypeId = $this->intTransactionTypeId;
                 $this->objTransaction->Note = $this->txtNote->Text;
                 $this->objTransaction->Save();
                 // Assign different source and destinations depending on transaction type
                 foreach ($this->objAssetArray as $asset) {
                     if ($asset instanceof Asset && $asset->LinkedFlag != 1) {
                         $SourceLocationId = $asset->LocationId;
                         // Load all linked assets
                         $objLinkedAssetArrayByNewAsset = Asset::LoadChildLinkedArrayByParentAssetId($asset->AssetId);
                         if (!$objLinkedAssetArrayByNewAsset) {
                             $objLinkedAssetArrayByNewAsset = array();
                         }
                         if ($this->intTransactionTypeId == 1) {
                             $DestinationLocationId = $this->lstLocation->SelectedValue;
                         } elseif ($this->intTransactionTypeId == 2) {
                             $DestinationLocationId = $this->lstLocation->SelectedValue;
                             $asset->CheckedOutFlag = false;
                         } elseif ($this->intTransactionTypeId == 3) {
                             $DestinationLocationId = 1;
                             $asset->CheckedOutFlag = true;
                         } elseif ($this->intTransactionTypeId == 8) {
                             $DestinationLocationId = $asset->LocationId;
                             $asset->ReservedFlag = true;
                         } elseif ($this->intTransactionTypeId == 9) {
                             $DestinationLocationId = $asset->LocationId;
                             $asset->ReservedFlag = false;
                         } elseif ($this->intTransactionTypeId == 10) {
                             $DestinationLocationId = 6;
                             $asset->ArchivedFlag = true;
                             //$asset->CheckedOutFlag = false;
                             //$asset->ReservedFlag = false;
                         } elseif ($this->intTransactionTypeId == 11) {
                             $DestinationLocationId = $this->lstLocation->SelectedValue;
                             $asset->ArchivedFlag = false;
                         }
                         $asset->LocationId = $DestinationLocationId;
                         // Transact all child linked assets
                         foreach ($objLinkedAssetArrayByNewAsset as $objLinkedAsset) {
                             $objLinkedAsset->CheckedOutFlag = $asset->CheckedOutFlag;
                             $objLinkedAsset->ArchivedFlag = $asset->ArchivedFlag;
                             $objLinkedAsset->ReservedFlag = $asset->ReservedFlag;
                             $objLinkedAsset->LocationId = $asset->LocationId;
                             $objLinkedAsset->Save();
                             // Create the new assettransaction object and save it
                             $this->objAssetTransaction = new AssetTransaction();
                             $this->objAssetTransaction->AssetId = $objLinkedAsset->AssetId;
                             $this->objAssetTransaction->TransactionId = $this->objTransaction->TransactionId;
                             $this->objAssetTransaction->SourceLocationId = $SourceLocationId;
                             $this->objAssetTransaction->DestinationLocationId = $DestinationLocationId;
                             $this->objAssetTransaction->Save();
                             // Create the new AssetTransactionCheckout object and save it
                             if ($this->intTransactionTypeId == 3) {
                                 $objAssetTransactionCheckout = new AssetTransactionCheckout();
                                 $objAssetTransactionCheckout->AssetTransactionId = $this->objAssetTransaction->AssetTransactionId;
                                 $objAssetTransactionCheckout->ToContactId = $intToContact;
                                 $objAssetTransactionCheckout->ToUserId = $intToUser;
                                 if ($dttDueDate instanceof QDateTimePicker) {
                                     $objAssetTransactionCheckout->DueDate = $dttDueDate->DateTime;
                                 }
                                 $objAssetTransactionCheckout->Save();
                             }
                         }
                         $asset->Save();
                         // Create the new assettransaction object and save it
                         $this->objAssetTransaction = new AssetTransaction();
                         $this->objAssetTransaction->AssetId = $asset->AssetId;
                         $this->objAssetTransaction->TransactionId = $this->objTransaction->TransactionId;
                         $this->objAssetTransaction->SourceLocationId = $SourceLocationId;
                         $this->objAssetTransaction->DestinationLocationId = $DestinationLocationId;
                         $this->objAssetTransaction->Save();
                         // Create the new AssetTransactionCheckout object and save it for each linked asset
                         if ($this->intTransactionTypeId == 3) {
                             $objAssetTransactionCheckout = new AssetTransactionCheckout();
                             $objAssetTransactionCheckout->AssetTransactionId = $this->objAssetTransaction->AssetTransactionId;
                             $objAssetTransactionCheckout->ToContactId = $intToContact;
                             $objAssetTransactionCheckout->ToUserId = $intToUser;
                             if ($dttDueDate instanceof QDateTimePicker) {
                                 $objAssetTransactionCheckout->DueDate = $dttDueDate->DateTime;
                             }
                             $objAssetTransactionCheckout->Save();
                         }
                     }
                 }
                 // Commit the above transactions to the database
                 $objDatabase->TransactionCommit();
                 QApplication::Redirect('../common/transaction_edit.php?intTransactionId=' . $this->objTransaction->TransactionId);
             } catch (QOptimisticLockingException $objExc) {
                 // Rollback the database
                 $objDatabase->TransactionRollback();
                 $objAsset = Asset::Load($objExc->EntityId);
                 $this->objParentObject->btnRemove_Click($this->objParentObject->FormId, 'btnRemove' . $objExc->EntityId, $objExc->EntityId);
                 // Lock Exception Thrown, Report the Error
                 $this->btnCancel->Warning = sprintf('The Asset %s has been altered by another user and removed from the transaction. You may add the asset again or save the transaction without it.', $objAsset->AssetCode);
             }
         }
     } else {
         $this->btnCancel->Warning = sprintf('Please provide at least one asset.');
     }
 }
Exemple #6
0
 protected function UpdateShipmentFields()
 {
     if (!$this->blnEditMode) {
         //$this->objShipment->TransactionId = $this->objTransaction->TransactionId;
         $this->objShipment->Transaction = $this->objTransaction;
     }
     if ($this->blnEditMode) {
         if (!$this->objTransaction) {
             $this->objTransaction = Transaction::Load($this->objShipment->TransactionId);
         }
         $this->objShipment->Transaction = $this->objTransaction;
         $this->objShipment->ShipmentNumber = $this->lblShipmentNumber->Text;
     } elseif (QApplication::$TracmorSettings->CustomShipmentNumbers) {
         $this->objShipment->ShipmentNumber = $this->txtShipmentNumber->Text;
     } else {
         $this->objShipment->ShipmentNumber = Shipment::LoadNewShipmentNumber();
     }
     $this->objShipment->ToContactId = $this->lstToContact->SelectedValue;
     $this->objShipment->FromCompanyId = $this->lstFromCompany->SelectedValue;
     $this->objShipment->FromContactId = $this->lstFromContact->SelectedValue;
     $this->objShipment->ShipDate = $this->calShipDate->DateTime;
     $this->objShipment->FromAddressId = $this->lstFromAddress->SelectedValue;
     $this->objShipment->ToCompanyId = $this->lstToCompany->SelectedValue;
     $this->objShipment->ToAddressId = $this->lstToAddress->SelectedValue;
     $this->objShipment->CourierId = $this->lstCourier->SelectedValue;
     //if (!$this->lstCourier->SelectedValue) {
     $this->objShipment->TrackingNumber = $this->txtTrackingNumber->Text;
     //}
     // Reload the Assets and inventory locations so that they don't trigger an OLE if completing the shipment without reloading after adding an asset or inventory.
     if ($this->objAssetTransactionArray) {
         foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
             $objAssetTransaction->Asset = Asset::Load($objAssetTransaction->AssetId);
         }
     }
     if ($this->objInventoryTransactionArray) {
         foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
             $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId);
         }
     }
 }
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'AssetTransactionId':
             // Gets the value for intAssetTransactionId (Read-Only PK)
             // @return integer
             return $this->intAssetTransactionId;
         case 'AssetId':
             // Gets the value for intAssetId (Not Null)
             // @return integer
             return $this->intAssetId;
         case 'TransactionId':
             // Gets the value for intTransactionId (Not Null)
             // @return integer
             return $this->intTransactionId;
         case 'ParentAssetTransactionId':
             // Gets the value for intParentAssetTransactionId
             // @return integer
             return $this->intParentAssetTransactionId;
         case 'SourceLocationId':
             // Gets the value for intSourceLocationId
             // @return integer
             return $this->intSourceLocationId;
         case 'DestinationLocationId':
             // Gets the value for intDestinationLocationId
             // @return integer
             return $this->intDestinationLocationId;
         case 'NewAssetFlag':
             // Gets the value for blnNewAssetFlag
             // @return boolean
             return $this->blnNewAssetFlag;
         case 'NewAssetId':
             // Gets the value for intNewAssetId
             // @return integer
             return $this->intNewAssetId;
         case 'ScheduleReceiptFlag':
             // Gets the value for blnScheduleReceiptFlag
             // @return boolean
             return $this->blnScheduleReceiptFlag;
         case 'ScheduleReceiptDueDate':
             // Gets the value for dttScheduleReceiptDueDate
             // @return QDateTime
             return $this->dttScheduleReceiptDueDate;
         case 'CreatedBy':
             // Gets the value for intCreatedBy
             // @return integer
             return $this->intCreatedBy;
         case 'CreationDate':
             // Gets the value for dttCreationDate
             // @return QDateTime
             return $this->dttCreationDate;
         case 'ModifiedBy':
             // Gets the value for intModifiedBy
             // @return integer
             return $this->intModifiedBy;
         case 'ModifiedDate':
             // Gets the value for strModifiedDate (Read-Only Timestamp)
             // @return string
             return $this->strModifiedDate;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'Asset':
             // Gets the value for the Asset object referenced by intAssetId (Not Null)
             // @return Asset
             try {
                 if (!$this->objAsset && !is_null($this->intAssetId)) {
                     $this->objAsset = Asset::Load($this->intAssetId);
                 }
                 return $this->objAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'Transaction':
             // Gets the value for the Transaction object referenced by intTransactionId (Not Null)
             // @return Transaction
             try {
                 if (!$this->objTransaction && !is_null($this->intTransactionId)) {
                     $this->objTransaction = Transaction::Load($this->intTransactionId);
                 }
                 return $this->objTransaction;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ParentAssetTransaction':
             // Gets the value for the AssetTransaction object referenced by intParentAssetTransactionId
             // @return AssetTransaction
             try {
                 if (!$this->objParentAssetTransaction && !is_null($this->intParentAssetTransactionId)) {
                     $this->objParentAssetTransaction = AssetTransaction::Load($this->intParentAssetTransactionId);
                 }
                 return $this->objParentAssetTransaction;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'SourceLocation':
             // Gets the value for the Location object referenced by intSourceLocationId
             // @return Location
             try {
                 if (!$this->objSourceLocation && !is_null($this->intSourceLocationId)) {
                     $this->objSourceLocation = Location::Load($this->intSourceLocationId);
                 }
                 return $this->objSourceLocation;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'DestinationLocation':
             // Gets the value for the Location object referenced by intDestinationLocationId
             // @return Location
             try {
                 if (!$this->objDestinationLocation && !is_null($this->intDestinationLocationId)) {
                     $this->objDestinationLocation = Location::Load($this->intDestinationLocationId);
                 }
                 return $this->objDestinationLocation;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'NewAsset':
             // Gets the value for the Asset object referenced by intNewAssetId
             // @return Asset
             try {
                 if (!$this->objNewAsset && !is_null($this->intNewAssetId)) {
                     $this->objNewAsset = Asset::Load($this->intNewAssetId);
                 }
                 return $this->objNewAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'CreatedByObject':
             // Gets the value for the UserAccount object referenced by intCreatedBy
             // @return UserAccount
             try {
                 if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) {
                     $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy);
                 }
                 return $this->objCreatedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ModifiedByObject':
             // Gets the value for the UserAccount object referenced by intModifiedBy
             // @return UserAccount
             try {
                 if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) {
                     $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy);
                 }
                 return $this->objModifiedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'AssetTransactionCheckout':
             // Gets the value for the AssetTransactionCheckout object that uniquely references this AssetTransaction
             // by objAssetTransactionCheckout (Unique)
             // @return AssetTransactionCheckout
             try {
                 if ($this->objAssetTransactionCheckout === false) {
                     // We've attempted early binding -- and the reverse reference object does not exist
                     return null;
                 }
                 if (!$this->objAssetTransactionCheckout) {
                     $this->objAssetTransactionCheckout = AssetTransactionCheckout::LoadByAssetTransactionId($this->intAssetTransactionId);
                 }
                 return $this->objAssetTransactionCheckout;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         case '_ChildAssetTransaction':
             // Gets the value for the private _objChildAssetTransaction (Read-Only)
             // if set due to an expansion on the asset_transaction.parent_asset_transaction_id reverse relationship
             // @return AssetTransaction
             return $this->_objChildAssetTransaction;
         case '_ChildAssetTransactionArray':
             // Gets the value for the private _objChildAssetTransactionArray (Read-Only)
             // if set due to an ExpandAsArray on the asset_transaction.parent_asset_transaction_id reverse relationship
             // @return AssetTransaction[]
             return (array) $this->_objChildAssetTransactionArray;
         case '__Restored':
             return $this->__blnRestored;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
Exemple #8
0
 protected function btnNext_Click()
 {
     $blnError = false;
     $this->btnNext->Warning = '';
     if ($this->intStep == 1) {
         if ($this->chkHeaderRow->Checked) {
             $this->blnHeaderRow = true;
         } else {
             $this->blnHeaderRow = false;
         }
         // Check errors
         if ($this->lstFieldSeparator->SelectedValue == 'other' && !$this->txtFieldSeparator->Text) {
             $this->flcFileCsv->Warning = "Please enter the field separator.";
             $blnError = true;
         } elseif ($this->lstTextDelimiter->SelectedValue == 'other' && !$this->txtTextDelimiter->Text) {
             $this->flcFileCsv->Warning = "Please enter the text delimiter.";
             $blnError = true;
         } else {
             // Step 1 complete
             // File Not Uploaded
             if (!file_exists($this->flcFileCsv->File) || !$this->flcFileCsv->Size) {
                 //throw new QCallerException('FileAssetType must be a valid QFileAssetType constant value');
                 $this->flcFileCsv->Warning = 'The file could not be uploaded. Please provide a valid file.';
                 $blnError = true;
                 // File Has Incorrect MIME Type (only if an acceptiblemimearray is setup)
             } elseif (is_array($this->strAcceptibleMimeArray) && !array_key_exists($this->flcFileCsv->Type, $this->strAcceptibleMimeArray)) {
                 $this->flcFileCsv->Warning = "Extension must be 'csv' or 'txt'";
                 $blnError = true;
                 // File Successfully Uploaded
             } else {
                 $this->flcFileCsv->Warning = "";
                 // Setup Filename, Base Filename and Extension
                 $strFilename = $this->flcFileCsv->FileName;
                 $intPosition = strrpos($strFilename, '.');
             }
             if (!$blnError) {
                 $this->FileCsvData = new File_CSV_DataSource();
                 // Setup the settings which have got on step 1
                 $this->FileCsvData->settings($this->GetCsvSettings());
                 $file = fopen($this->flcFileCsv->File, "r");
                 // Counter of files
                 $i = 1;
                 // Counter of rows
                 $j = 1;
                 $this->strFilePathArray = array();
                 // The uploaded file splits up in order to avoid out of memory
                 while ($row = fgets($file, 1000)) {
                     if ($j == 1) {
                         $strFilePath = sprintf('%s/%s_%s.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId'], $i);
                         $this->strFilePathArray[] = $strFilePath;
                         $file_part = fopen($strFilePath, "w+");
                         if ($i == 1) {
                             $strHeaderRow = $row;
                         } else {
                             fwrite($file_part, $strHeaderRow);
                         }
                     }
                     fwrite($file_part, $row);
                     $j++;
                     if ($j > 200) {
                         $j = 1;
                         $i++;
                         fclose($file_part);
                     }
                 }
                 $this->intTotalCount = ($i - 1) * 200 + $j - 1;
                 $this->intTotalCount -= $this->chkHeaderRow->Checked ? 1 : 0;
                 if ($this->lstImportAction->SelectedValue == 1 && $this->intAssetLimit != null && $this->intAssetLimit < $this->intTotalCount + $this->intAssetCount) {
                     $blnError = true;
                     $this->btnNext->Warning = sprintf('This import of %s assets would exceed your limit of %s assets.', $this->intTotalCount, $this->intAssetLimit);
                 } else {
                     $this->arrMapFields = array();
                     $this->arrTracmorField = array();
                     // Load first file
                     $this->FileCsvData->load($this->strFilePathArray[0]);
                     $file_skipped = fopen($this->strFilePath = sprintf('%s/%s_skipped.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "w+");
                     // Get Headers
                     if ($this->blnHeaderRow) {
                         $this->arrCsvHeader = $this->FileCsvData->getHeaders();
                         // Create the header row in the skipped error file
                         $this->PutSkippedRecordInFile($file_skipped, $this->arrCsvHeader);
                     }
                     /*else {
                     		// If it is not first file
                     		$this->FileCsvData->appendRow($this->FileCsvData->getHeaders());
                     		}*/
                     $strFirstRowArray = $this->FileCsvData->getRow(0);
                     for ($i = 0; $i < count($strFirstRowArray); $i++) {
                         $this->arrMapFields[$i] = array();
                         if ($this->blnHeaderRow && array_key_exists($i, $this->arrCsvHeader)) {
                             if ($this->arrCsvHeader[$i] == '') {
                                 $this->arrCsvHeader[$i] = ' ';
                             }
                             $this->lstMapHeader_Create($this, $i, $this->arrCsvHeader[$i]);
                             $this->arrMapFields[$i]['header'] = $this->arrCsvHeader[$i];
                         } else {
                             $this->lstMapHeader_Create($this, $i);
                         }
                         // Create Default Value TextBox, ListBox and DateTimePicker
                         if ($this->blnHeaderRow && array_key_exists($i, $this->arrCsvHeader) && $this->arrCsvHeader[$i] || !$this->blnHeaderRow) {
                             $txtDefaultValue = new QTextBox($this);
                             $txtDefaultValue->Width = 200;
                             $this->txtMapDefaultValueArray[] = $txtDefaultValue;
                             $lstDefaultValue = new QListBox($this);
                             $lstDefaultValue->Width = 200;
                             $lstDefaultValue->Display = false;
                             $this->lstMapDefaultValueArray[] = $lstDefaultValue;
                             $dtpDate = new QDateTimePicker($this);
                             $dtpDate->DateTimePickerType = QDateTimePickerType::Date;
                             $dtpDate->DateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;
                             $dtpDate->Display = false;
                             $this->dtpDateArray[] = $dtpDate;
                             if (array_key_exists($i, $this->lstMapHeaderArray)) {
                                 $this->lstTramorField_Change(null, $this->lstMapHeaderArray[$i]->ControlId, null);
                             }
                         }
                         $this->arrMapFields[$i]['row1'] = $strFirstRowArray[$i];
                     }
                     $this->btnNext->Text = "Import Now";
                     fclose($file_skipped);
                     // Create Add Field button
                     $btnAddField = new QButton($this);
                     $btnAddField->Text = "Add Field";
                     $btnAddField->AddAction(new QClickEvent(), new QServerAction('btnAddField_Click'));
                     $btnAddField->AddAction(new QEnterKeyEvent(), new QServerAction('btnAddField_Click'));
                     $btnAddField->AddAction(new QEnterKeyEvent(), new QTerminateAction());
                     $this->lstMapHeaderArray[] = $btnAddField;
                 }
             }
         }
     } elseif ($this->intStep == 2) {
         // Step 2 complete
         $blnRequiredAllAssetCustomFields = true;
         $blnError = false;
         $blnAssetCode = false;
         $blnAssetModelShortDescription = false;
         $blnLocation = false;
         $blnAssetId = false;
         // $array Required Custom Fields for All Asset Models
         $arrAssetCustomFieldOptions = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
         // generate error flag and field names which are required for export;
         $arrRequiredAllAssetCustomFields = array();
         foreach ($arrAssetCustomFieldOptions as $arrAssetCustomFieldOption) {
             if ($arrAssetCustomFieldOption->CustomField->RequiredFlag && $arrAssetCustomFieldOption->CustomField->ActiveFlag && $arrAssetCustomFieldOption->CustomField->AllAssetModelsFlag) {
                 $arrRequiredAllAssetCustomFields[] = $arrAssetCustomFieldOption->CustomField->ShortDescription;
                 if (!in_array($arrAssetCustomFieldOption->CustomField->ShortDescription, $this->getLstKeys())) {
                     $blnRequiredAllAssetCustomFields = false;
                 }
             }
         }
         // Checking errors (Model Short Description, Model Code, Category and Manufacturer must be selected)
         for ($i = 0; $i < count($this->lstMapHeaderArray) - 1; $i++) {
             $lstMapHeader = $this->lstMapHeaderArray[$i];
             $strSelectedValue = strtolower($lstMapHeader->SelectedValue);
             if ($strSelectedValue == "model") {
                 $blnAssetModelShortDescription = true;
             } elseif ($strSelectedValue == "asset tag") {
                 $blnAssetCode = true;
             } elseif ($strSelectedValue == "location") {
                 $blnLocation = true;
             } elseif ($strSelectedValue == "id") {
                 $blnAssetId = true;
             }
         }
         if ($this->lstMapDefaultValueArray) {
             // Checking errors for required Default Value text fields
             foreach ($this->lstMapDefaultValueArray as $lstDefault) {
                 if ($lstDefault->Display && $lstDefault->Required && !$lstDefault->SelectedValue) {
                     $lstDefault->Warning = "You must select one default value.";
                     $blnError = true;
                     break;
                 } else {
                     $blnError = false;
                     $lstDefault->Warning = "";
                 }
             }
         }
         if ($this->txtMapDefaultValueArray) {
             // Checking errors for required Default Value lst fields
             foreach ($this->txtMapDefaultValueArray as $txtDefault) {
                 if ($txtDefault->Display && $txtDefault->Required && !$txtDefault->Text) {
                     $txtDefault->Warning = "You must enter default value.";
                     break;
                 } else {
                     $blnError = false;
                     $txtDefault->Warning = "";
                 }
             }
         }
         // If all required fields have no errors
         if (!$blnError && $blnRequiredAllAssetCustomFields && $blnAssetCode && $blnAssetModelShortDescription && $blnLocation && ($this->lstImportAction->SelectedValue != 2 || $blnAssetId)) {
             $this->btnNext->Warning = "";
             // Setup keys for main required fields
             foreach ($this->arrTracmorField as $key => $value) {
                 /*if ($value == 'category') {
                 		  $this->intCategoryKey = $key;
                 		}
                 		elseif ($value == 'manufacturer') {
                 		  $this->intManufacturerKey = $key;
                 		}
                 		else*/
                 if ($this->lstImportAction->SelectedValue == 2 && $value == 'id') {
                     $this->intItemIdKey = $key;
                 }
                 /*elseif ($value == 'created by') {
                 		  $this->intCreatedByKey = $key;
                 		}
                 		elseif ($value == 'created date') {
                 		  $this->intCreatedDateKey = $key;
                 		}
                 		elseif ($value == 'modified by') {
                 		  $this->intModifiedByKey = $key;
                 		}
                 		elseif ($value == 'modified date') {
                 		  $this->intModifiedDateKey = $key;
                 		}*/
             }
             $this->objNewAssetArray = array();
             $this->strAssetValuesArray = array();
             $this->blnImportEnd = false;
             $j = 1;
             $this->btnNext->RemoveAllActions('onclick');
             // Add new ajax actions for button
             $this->btnNext->AddAction(new QClickEvent(), new QAjaxAction('btnNext_Click'));
             $this->btnNext->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnNext));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnNext_Click'));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QToggleEnableAction($this->btnNext));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             $this->btnNext->Warning = "Please wait...";
             $this->intImportStep = 2;
             $this->intCurrentFile = 0;
             $this->strSelectedValueArray = array();
             // New asset models
             $this->dtgAsset = new QDataGrid($this);
             $this->dtgAsset->Name = 'asset_list';
             $this->dtgAsset->CellPadding = 5;
             $this->dtgAsset->CellSpacing = 0;
             $this->dtgAsset->CssClass = "datagrid";
             $this->dtgAsset->UseAjax = true;
             $this->dtgAsset->ShowColumnToggle = false;
             $this->dtgAsset->ShowExportCsv = false;
             $this->dtgAsset->ShowHeader = false;
             $this->dtgAsset->AddColumn(new QDataGridColumnExt('Model', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"'));
             // Updated assets
             $this->dtgUpdatedAsset = new QDataGrid($this);
             $this->dtgUpdatedAsset->Name = 'updated_asset_list';
             $this->dtgUpdatedAsset->CellPadding = 5;
             $this->dtgUpdatedAsset->CellSpacing = 0;
             $this->dtgUpdatedAsset->CssClass = "datagrid";
             $this->dtgUpdatedAsset->UseAjax = true;
             $this->dtgUpdatedAsset->ShowColumnToggle = false;
             $this->dtgUpdatedAsset->ShowExportCsv = false;
             $this->dtgUpdatedAsset->ShowHeader = false;
             $this->dtgUpdatedAsset->AddColumn(new QDataGridColumnExt('Asset Tag', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"'));
             // Create the label for successful import
             $this->lblImportSuccess = new QLabel($this);
             $this->lblImportSuccess->HtmlEntities = false;
             $this->lblImportSuccess->Display = false;
             // Undo Last Import button
             $this->btnUndoLastImport = new QButton($this);
             $this->btnUndoLastImport->Text = "Undo Last Import";
             $this->btnUndoLastImport->Display = false;
             $this->btnUndoLastImport->AddAction(new QClickEvent(), new QServerAction('btnCancel_Click'));
             $this->btnUndoLastImport->AddAction(new QEnterKeyEvent(), new QServerAction('btnCancel_Click'));
             $this->btnUndoLastImport->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             // Import More button
             $this->btnImportMore = new QButton($this);
             $this->btnImportMore->Text = "Import More";
             $this->btnImportMore->Display = false;
             $this->btnImportMore->AddAction(new QClickEvent(), new QServerAction('btnImportMore_Click'));
             $this->btnImportMore->AddAction(new QEnterKeyEvent(), new QServerAction('btnImportMore_Click'));
             $this->btnImportMore->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             // Return to Assets button
             $this->btnReturnToAssets = new QButton($this);
             $this->btnReturnToAssets->Text = "Return to Assets";
             $this->btnReturnToAssets->Display = false;
             $this->btnReturnToAssets->AddAction(new QClickEvent(), new QServerAction('btnReturnToAssets_Click'));
             $this->btnReturnToAssets->AddAction(new QEnterKeyEvent(), new QServerAction('btnReturnToAssets_Click'));
             $this->btnReturnToAssets->AddAction(new QEnterKeyEvent(), new QTerminateAction());
         } else {
             $strRequiredAllAssetCustomFields = '';
             if (count($arrRequiredAllAssetCustomFields) > 0) {
                 $strRequiredAllAssetCustomFields = implode(", ", $arrRequiredAllAssetCustomFields) . ", ";
             }
             $this->btnNext->Warning = "You must select all required fields (" . $strRequiredAllAssetCustomFields . "Asset Tag, Model Short Description and Location).";
             $blnError = true;
         }
     } else {
         // Step 3 complete
         set_time_limit(0);
         $file_skipped = fopen($strFilePath = sprintf('%s/%s_skipped.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "a");
         if (!$this->blnImportEnd) {
             // Asset
             if ($this->intImportStep == 2) {
                 $intCategoryArray = array();
                 // Load all categories with key=category_id
                 /*foreach (Category::LoadAllWithFlags(true, false) as $objCategory) {
                 		$intCategoryArray[$objCategory->CategoryId] = strtolower($objCategory->ShortDescription);
                 		}
                 		$intManufacturerArray = array();
                 		// Load all manufacturers with key=manufacturer_id
                 		foreach (Manufacturer::LoadAll() as $objManufacturer) {
                 		$intManufacturerArray[$objManufacturer->ManufacturerId] = strtolower($objManufacturer->ShortDescription);
                 		}*/
                 $intAssetCustomFieldKeyArray = array();
                 $arrAssetCustomField = array();
                 // Setup keys
                 foreach ($this->arrTracmorField as $key => $value) {
                     if ($value == 'asset tag') {
                         $intAssetCodeKey = $key;
                     } elseif ($value == 'model') {
                         $intAssetModelDescriptionKey = $key;
                     } elseif ($value == 'location') {
                         $intLocationKey = $key;
                     } elseif ($value == 'parent asset') {
                         $intParentAssetKey = $key;
                     } elseif ($value == 'locked to parent') {
                         $intLinkedKey = $key;
                     } elseif (substr($value, 0, 6) == 'asset_') {
                         $intAssetCustomFieldKeyArray[substr($value, 6)] = $key;
                         if (array_key_exists(substr($value, 6), $this->arrAssetCustomField)) {
                             $arrAssetCustomField[substr($value, 6)] = $this->arrAssetCustomField[substr($value, 6)];
                         }
                     } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "depreciate asset") {
                         $this->intDepreciationFlagKey = $key;
                     } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "purchase cost") {
                         $this->intPurchaseCostKey = $key;
                     } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "purchase date") {
                         $this->intPurchaseDateKey = $key;
                     }
                 }
                 $intAssetModelArray = array();
                 $strItemCFVArray = array();
                 $strUpdatedItemCFVArray = array();
                 $strUpdatedValuesArray = array();
                 $this->arrOldItemArray = array();
                 $this->objUpdatedItemArray = array();
                 // Load all asset models
                 foreach (AssetModel::LoadAllIntoArray() as $arrAssetModel) {
                     //$strAssetModelArray[] = strtolower(sprintf("%s_%s_%s_%s", addslashes($arrAssetModel['model_code']),  addslashes($arrAssetModel['short_description']),  $arrAssetModel['category_id'], $arrAssetModel['manufacturer_id']));
                     $intAssetModelArray[$arrAssetModel['asset_model_id']] = strtolower($arrAssetModel['short_description']);
                 }
                 $intLocationArray = array();
                 // Load all locations with keys=location_id
                 foreach (Location::LoadAll() as $objLocation) {
                     $intLocationArray[$objLocation->LocationId] = strtolower($objLocation->ShortDescription);
                 }
                 // Depreciation
                 /*if(QApplication::$TracmorSettings->DepreciationFlag == '1'){
                 			foreach (DepreciationClass::LoadAll() as $objDepreciationClass){
                 				$this->intDepreciationClassArray[$objDepreciationClass->DepreciationClassId] = strtolower($objDepreciationClass->ShortDescription);
                 			}
                 		}*/
                 $strAssetArray = array();
                 // Load all assets
                 // Loads array of AssetModelId
                 $arrAssetArray = Asset::LoadAllIntoArray();
                 $arrAssetId = array();
                 if (count($arrAssetArray)) {
                     foreach ($arrAssetArray as $arrAsset) {
                         $arrAssetId[$arrAsset['asset_id']] = addslashes(strtolower($arrAsset['asset_code']));
                         $strAssetArray[] = addslashes(strtolower($arrAsset['asset_code']));
                     }
                 }
             }
             for ($j = $this->intCurrentFile; $j < count($this->strFilePathArray); $j++) {
                 $this->FileCsvData->load($this->strFilePathArray[$j]);
                 if (!$j) {
                     //$this->FileCsvData->appendRow($this->FileCsvData->getHeaders());
                 }
                 if ($this->intImportStep == 2) {
                     $strAssetCFVArray = array();
                     $objNewAssetArray = array();
                     for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) {
                         $strRowArray = $this->FileCsvData->getRow($i);
                         $strAssetCode = trim($strRowArray[$intAssetCodeKey]) ? addslashes(trim($strRowArray[$intAssetCodeKey])) : false;
                         //$strAssetCode = (trim($strRowArray[$intAssetCodeKey])) ? trim($strRowArray[$intAssetCodeKey]) : false;
                         $strKeyArray = array_keys($intLocationArray, isset($strRowArray[$intLocationKey]) ? strtolower(trim($strRowArray[$intLocationKey])) : array());
                         if (count($strKeyArray)) {
                             $intLocationId = $strKeyArray[0];
                         } else {
                             $strKeyArray = array_keys($intLocationArray, strtolower(trim($this->txtMapDefaultValueArray[$intLocationKey]->Text)));
                             if (count($strKeyArray)) {
                                 $intLocationId = $strKeyArray[0];
                             } else {
                                 $intLocationId = false;
                             }
                         }
                         $strKeyArray = array_keys($intAssetModelArray, isset($strRowArray[$intAssetModelDescriptionKey]) ? strtolower(trim($strRowArray[$intAssetModelDescriptionKey])) : array());
                         if (count($strKeyArray)) {
                             $intAssetModelId = $strKeyArray[0];
                         } else {
                             $strKeyArray = array_keys($intAssetModelArray, strtolower(trim($this->txtMapDefaultValueArray[$intAssetModelDescriptionKey]->Text)));
                             if (count($strKeyArray)) {
                                 $intAssetModelId = $strKeyArray[0];
                             } else {
                                 $intAssetModelId = false;
                             }
                         }
                         $blnError = false;
                         // Skip records with not filled required custom fields
                         $log = '';
                         if ($intAssetModelId) {
                             foreach ($intAssetCustomFieldKeyArray as $k => $v) {
                                 $log .= 'k' . $k . '=' . $v;
                             }
                             // Load Specific asset model custom field
                             $arrRequiredSpecificAssetCustomFields = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($intAssetModelId);
                             foreach ($arrRequiredSpecificAssetCustomFields as $objRequiredCustomField) {
                                 if ($objRequiredCustomField->CustomField->RequiredFlag) {
                                     $log .= $objRequiredCustomField->CustomField->CustomFieldId;
                                     if (!array_key_exists($objRequiredCustomField->CustomField->CustomFieldId, $intAssetCustomFieldKeyArray) || empty($strRowArray[array_search($objRequiredCustomField->CustomField->CustomFieldId, $intAssetCustomFieldKeyArray)])) {
                                         $blnError = true;
                                         $this->intImportStep = 3;
                                         //   $log .= "<h1>".$objRequiredCustomField->CustomField->ShortDescription.$objRequiredCustomField->CustomField->CustomFieldId." is empty</h1>";
                                     }
                                 }
                             }
                         }
                         //print $log; exit;
                         if (!$blnError) {
                             if (isset($intParentAssetKey) && isset($strRowArray[$intParentAssetKey])) {
                                 $strKeyArray = array_keys($arrAssetId, strtolower(trim($strRowArray[$intParentAssetKey])));
                                 if (count($strKeyArray)) {
                                     $intParentAssetId = $strKeyArray[0];
                                 } else {
                                     $strKeyArray = array_keys($arrAssetId, strtolower(trim($this->txtMapDefaultValueArray[$intParentAssetKey]->Text)));
                                     if (count($strKeyArray)) {
                                         $intParentAssetId = $strKeyArray[0];
                                     } else {
                                         $intParentAssetId = null;
                                         $blnError = true;
                                     }
                                 }
                                 if (!$intParentAssetId || $strRowArray[$intParentAssetKey] == $strAssetCode) {
                                     $blnError = true;
                                 }
                                 $blnLinked = $intParentAssetId && isset($intLinkedKey) && strlen(trim($strRowArray[$intLinkedKey])) > 0 ? 1 : 0;
                             } else {
                                 $intParentAssetId = null;
                                 $blnLinked = 0;
                             }
                         }
                         /*$strKeyArray = array_keys($intCategoryArray, strtolower(trim($strRowArray[$this->intCategoryKey])));
                         		if (count($strKeyArray)) {
                         			$intCategoryId = $strKeyArray[0];
                         		} else {
                         			$strKeyArray = array_keys($intCategoryArray, strtolower(trim($this->txtMapDefaultValueArray[$this->intCategoryKey]->Text)));
                         			if (count($strKeyArray)) {
                         				$intCategoryId = $strKeyArray[0];
                         			} else {
                         				$intCategoryId = false;
                         			}
                         		}
                         		$strKeyArray = array_keys($intManufacturerArray, strtolower(trim($strRowArray[$this->intManufacturerKey])));
                         		if (count($strKeyArray)) {
                         			$intManufacturerId = $strKeyArray[0];
                         		} else {
                         			$strKeyArray = array_keys($intManufacturerArray, strtolower(trim($this->txtMapDefaultValueArray[$this->intManufacturerKey]->Text)));
                         			if (count($strKeyArray)) {
                         				$intManufacturerId = $strKeyArray[0];
                         			} else {
                         				$intManufacturerId = false;
                         			}
                         		}*/
                         // If depreciation is enabled within Application
                         // Any non-empty value sets to 1
                         $blnDepreciationError = false;
                         $blnDepreciationFlag = null;
                         $intPurchaseCost = null;
                         $dttPurchaseDate = null;
                         if (QApplication::$TracmorSettings->DepreciationFlag == '1' && $this->intDepreciationFlagKey && strlen(trim($strRowArray[$this->intDepreciationFlagKey]))) {
                             // Verify that the model has a depreciation class assigned
                             if ($intAssetModelId > 0 && AssetModel::Load($intAssetModelId)->DepreciationClassId) {
                                 // Verify that purchase date and purchase cost are set and valid
                                 if (isset($this->intPurchaseCostKey) && isset($this->intPurchaseDateKey)) {
                                     // Check intVal for Purchase cost
                                     $intPurchaseCost = trim($strRowArray[$this->intPurchaseCostKey]) ? addslashes(trim($strRowArray[$this->intPurchaseCostKey])) : false;
                                     if (!is_numeric($intPurchaseCost)) {
                                         $blnDepreciationError = true;
                                     }
                                     $strPurchaseDate = trim($strRowArray[$this->intPurchaseDateKey]);
                                     $dttPurchaseDate = new DateTime();
                                     // Check isDate for Purchase date
                                     if (!strlen($strPurchaseDate) || !($dttPurchaseDate = $dttPurchaseDate->setTimestamp(strtotime($strPurchaseDate)))) {
                                         $blnDepreciationError = true;
                                     } else {
                                         $dttPurchaseDate = $dttPurchaseDate->format('Y-m-d');
                                     }
                                     $blnDepreciationFlag = 1;
                                 } else {
                                     $blnDepreciationError = true;
                                 }
                             } else {
                                 $blnDepreciationError = true;
                             }
                         }
                         $objAsset = false;
                         if (!$strAssetCode || $blnError || $intAssetModelId === false || $intLocationId === false || $blnDepreciationError) {
                             //$blnError = true;
                             //echo sprintf("Desc: %s AssetCode: %s Cat: %s Man: %s<br/>", $strAssetCode, $strLocation, $intCategoryId, $intManufacturerId);
                             $strAssetCode = null;
                             $this->intSkippedRecordCount++;
                             $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                             continue;
                         } else {
                             if ($this->lstImportAction->SelectedValue == 2) {
                                 $intItemId = intval(trim($strRowArray[$this->intItemIdKey]));
                                 if ($intItemId > 0 && array_key_exists($intItemId, $arrAssetId)) {
                                     //QApplication::$Database[1]->EnableProfiling();
                                     $objAssetArray = Asset::LoadArrayBySearchHelper(null, null, null, null, null, false, null, null, null, null, null, null, null, null, null, false, null, null, null, false, false, false, null, null, false, $intItemId);
                                     //QApplication::$Database[1]->OutputProfiling();
                                     if ($objAssetArray) {
                                         $objAsset = $objAssetArray[0];
                                     }
                                 }
                             } else {
                                 $intItemId = 0;
                             }
                         }
                         if ($strAssetCode && !$intItemId && !$this->in_array_nocase($strAssetCode, $strAssetArray)) {
                             // Custom Fields Section
                             $strCFVArray = array();
                             $objDatabase = CustomField::GetDatabase();
                             $blnCheckCFVError = false;
                             // Asset Model Custom Field import
                             foreach ($arrAssetCustomField as $objCustomField) {
                                 if ($objCustomField->CustomFieldQtypeId != 2) {
                                     $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) : "";
                                     $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text);
                                     $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL";
                                 } else {
                                     $objDatabase = Asset::GetDatabase();
                                     $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])) : "";
                                     $blnInList = false;
                                     foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) {
                                         if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strCSDescription)) {
                                             //$intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                                             $blnInList = true;
                                             break;
                                         }
                                     }
                                     // Add the CustomFieldValue
                                     // Removed adding new 'select' values
                                     /*if (!$blnInList && !in_array($strCSDescription, $strAddedCFVArray)) {
                                     			$strQuery = sprintf("INSERT INTO custom_field_value (custom_field_id, short_description, created_by, creation_date) VALUES (%s, '%s', %s, NOW());", $objCustomField->CustomFieldId, $strCSDescription, $_SESSION['intUserAccountId']);
                                     			$objDatabase->NonQuery($strQuery);
                                     			$strAddedCFVArray[] = $strCSDescription;
                                     		}
                                     		else*/
                                     if (!$blnInList && $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) {
                                         $strCSDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName;
                                     } elseif (!$blnInList) {
                                         $blnCheckCFVError = true;
                                         break;
                                     }
                                     if (!$blnCheckCFVError) {
                                         if ($strCSDescription) {
                                             $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription);
                                         } else {
                                             $strCFVArray[$objCustomField->CustomFieldId] = "NULL";
                                         }
                                     }
                                 }
                             }
                             // Check if asset limit has been reached
                             $blnAssetLimitError = $this->intAssetLimit != null && $this->intAssetCount + count($objNewAssetArray) >= $this->intAssetLimit;
                             if (!$blnCheckCFVError && !$blnAssetLimitError) {
                                 $strAssetArray[] = stripslashes($strAssetCode);
                                 $this->strAssetValuesArray[] = sprintf("('%s', '%s', '%s', %s, %s, '%s', NOW(), %s, %s, %s)", $strAssetCode, $intLocationId, $intAssetModelId, $intParentAssetId ? $intParentAssetId : "NULL", $blnLinked ? "1" : "0", $_SESSION['intUserAccountId'], $blnDepreciationFlag ? $blnDepreciationFlag : "NULL", $intPurchaseCost ? $intPurchaseCost : "NULL", $dttPurchaseDate ? '"' . $dttPurchaseDate . '"' : "NULL");
                                 $objNewAssetArray[] = stripslashes($strAssetCode);
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strAssetCFVArray[] = str_replace('""', '"', implode(', ', $strCFVArray));
                                     /*if ($j == 2) {
                                     		echo "strAssetCFVArray: ";
                                     		print_r($strAssetCFVArray);
                                     		echo "strCFVArray: ";
                                     		print_r($strCFVArray);
                                     		exit;
                                     		}*/
                                 } else {
                                     $strAssetCFVArray[] = "";
                                 }
                             } else {
                                 $this->intSkippedRecordCount++;
                                 if ($blnAssetLimitError) {
                                     $strRowArray[] = sprintf('Asset limit of %s reached', $this->intAssetLimit);
                                 }
                                 $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                                 $strAssetCode = null;
                             }
                         } elseif ($strAssetCode && $this->lstImportAction->SelectedValue == 2 && $objAsset) {
                             // Import Action is "Create and Update Records"
                             $strUpdateFieldArray = array();
                             $strUpdateFieldArray[] = sprintf("`asset_code`='%s'", $strAssetCode);
                             $strUpdateFieldArray[] = sprintf("`asset_model_id`='%s'", $intAssetModelId);
                             $strUpdateFieldArray[] = sprintf("`parent_asset_id`=%s", QApplication::$Database[1]->SqlVariable($intParentAssetId));
                             $strUpdateFieldArray[] = sprintf("`linked_flag`=b'%s'", $blnLinked ? 1 : 0);
                             $strUpdateFieldArray[] = sprintf("`modified_by`='%s'", $_SESSION['intUserAccountId']);
                             // Depreciation Fields
                             $strUpdateFieldArray[] = sprintf("`depreciation_flag`=%s", $blnDepreciationFlag ? $blnDepreciationFlag : "NULL");
                             $strUpdateFieldArray[] = sprintf("`purchase_cost`=%s", $intPurchaseCost ? $intPurchaseCost : "NULL");
                             $strUpdateFieldArray[] = sprintf("`purchase_date`=%s", $dttPurchaseDate ? "'{$dttPurchaseDate}'" : "NULL");
                             $blnCheckCFVError = false;
                             foreach ($arrAssetCustomField as $objCustomField) {
                                 if ($objCustomField->CustomFieldQtypeId != 2) {
                                     $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) : "";
                                     $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text);
                                     $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL";
                                 } else {
                                     $objDatabase = CustomField::GetDatabase();
                                     $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])) : "";
                                     $strCFVArray[$objCustomField->CustomFieldId] = $strCSDescription ? sprintf("'%s'", $strCSDescription) : "NULL";
                                     $blnInList = false;
                                     foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) {
                                         if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strCSDescription)) {
                                             //$intItemKeyntCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                                             $blnInList = true;
                                             break;
                                         }
                                     }
                                     if (!$blnInList && $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) {
                                         $strCSDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName;
                                     } elseif (!$blnInList) {
                                         $blnCheckCFVError = true;
                                         break;
                                     }
                                     if (!$blnCheckCFVError) {
                                         if ($strCSDescription) {
                                             $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription);
                                         } else {
                                             $strCFVArray[$objCustomField->CustomFieldId] = "NULL";
                                         }
                                     }
                                 }
                             }
                             // The user can not change location
                             if ($intLocationId != $objAsset->LocationId) {
                                 $blnCheckCFVError = true;
                             }
                             if (!$blnCheckCFVError) {
                                 $strUpdatedValuesArray[] = sprintf("UPDATE `asset` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strUpdateFieldArray)), $objAsset->AssetId);
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strUpdatedItemCFVArray[$objAsset->AssetId] = $strCFVArray;
                                 } else {
                                     $strUpdatedItemCFVArray[$objAsset->AssetId] = "";
                                 }
                                 $this->objUpdatedItemArray[$objAsset->AssetId] = sprintf("%s", $objAsset->AssetCode);
                                 //$this->arrOldItemArray[$objAsset->AssetId] = $objAsset;
                                 //$strItemQuery = sprintf("UPDATE `asset` SET `asset_code`='%s', `asset_model_id`='%s', `parent_asset_id`=%s, `linked_flag`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_id`='%s'", $objAsset->AssetCode, $objAsset->AssetModelId, (!$objAsset->ParentAssetId) ? "NULL" : $objAsset->ParentAssetId, $objAsset->LinkedFlag, (!$objAsset->ModifiedBy) ? "NULL" : $objAsset->ModifiedBy, (!$objAsset->ModifiedBy) ? "NULL" : sprintf("'%s'", $objAsset->ModifiedDate), $objAsset->AssetId);
                                 $strItemQuery = sprintf("UPDATE `asset` SET `asset_code`='%s', `asset_model_id`='%s', `parent_asset_id`=%s, `linked_flag`='%s', `modified_by`=%s, `modified_date`=%s, `depreciation_flag`=%s, `purchase_cost`=%s, `purchase_date`=%s WHERE `asset_id`='%s'", $objAsset->AssetCode, $objAsset->AssetModelId, !$objAsset->ParentAssetId ? "NULL" : $objAsset->ParentAssetId, $objAsset->LinkedFlag, !$objAsset->ModifiedBy ? "NULL" : $objAsset->ModifiedBy, !$objAsset->ModifiedBy ? "NULL" : sprintf("'%s'", $objAsset->ModifiedDate), $blnDepreciationFlag ? $blnDepreciationFlag : "NULL", $intPurchaseCost ? $intPurchaseCost : "NULL", $dttPurchaseDate ? '"' . $dttPurchaseDate . '"' : "NULL", $objAsset->AssetId);
                                 $strCFVArray = array();
                                 foreach ($this->arrAssetCustomField as $objCustomField) {
                                     $strCFV = $objAsset->GetVirtualAttribute($objCustomField->CustomFieldId);
                                     $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strCFV);
                                 }
                                 // Update values for custom field set not allowed to model
                                 $arrToClear = $this->substactNotAllowedFields($objAsset->AssetModelId, null);
                                 foreach ($arrToClear as $idToBeNull) {
                                     $strCFVArray[] = sprintf("`cfv_%s`= NULL", $idToBeNull);
                                 }
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strCFVQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strCFVArray)), $intItemId);
                                 } else {
                                     $strCFVQuery = false;
                                 }
                                 $this->arrOldItemArray[$objAsset->AssetId] = array("ItemSql" => $strItemQuery, "CFVSql" => $strCFVQuery);
                             }
                         } else {
                             // If Import Action is "Create Records" and this Asset has already in the database
                             /*elseif ($this->lstImportAction->SelectedValue == 1 && $this->in_array_nocase($strAssetCode, $strAssetArray)) {
                             		// Skipped and flagged as duplicates
                             		$this->intSkippedRecordCount++;
                             		$this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                             		}*/
                             $this->intSkippedRecordCount++;
                             $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                         }
                     }
                     //if ($this->intCurrentFile == count($this->strFilePathArray)) {
                     // Inserts
                     if (count($this->strAssetValuesArray)) {
                         $objDatabase = Asset::GetDatabase();
                         //var_dump($this->strAssetValuesArray);
                         //exit();
                         // $objDatabase->NonQuery(sprintf("INSERT INTO `asset` (`asset_code`, `location_id`, `asset_model_id`, `parent_asset_id`, `linked_flag`, `created_by`, `creation_date`) VALUES %s;", str_replace('""','"',implode(", ", $this->strAssetValuesArray))));
                         $objDatabase->NonQuery(sprintf("INSERT INTO `asset` (`asset_code`, `location_id`, `asset_model_id`, `parent_asset_id`, `linked_flag`, `created_by`, `creation_date`, `depreciation_flag`, `purchase_cost`, `purchase_date` ) VALUES %s;", str_replace('""', '"', implode(", ", $this->strAssetValuesArray))));
                         $intInsertId = $objDatabase->InsertId();
                         if ($intInsertId) {
                             $strAssetIdArray = array();
                             $strCFVArray = array();
                             for ($i = 0; $i < count($objNewAssetArray); $i++) {
                                 $this->objNewAssetArray[$intInsertId + $i] = $objNewAssetArray[$i];
                                 $strCFVArray[$i] = sprintf("('%s', %s)", $intInsertId + $i, $strAssetCFVArray[$i]);
                                 $strAssetIdArray[$i] = sprintf("(%s)", $intInsertId + $i);
                             }
                             /*if ($j == 1) {
                             		echo "strCFVArray: ";
                             		print_r($strCFVArray);
                             		echo "strAssetCFVArray: ";
                             		print_r($strAssetCFVArray);
                             		exit;
                             		}*/
                             $strCFVNameArray = array();
                             foreach ($arrAssetCustomField as $objCustomField) {
                                 $strCFVNameArray[] = sprintf("`cfv_%s`", $objCustomField->CustomFieldId);
                             }
                             if (count($strAssetCFVArray) > 0 && count($strCFVNameArray) > 0) {
                                 $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`, %s) VALUES %s", str_replace('""', '"', implode(", ", $strCFVNameArray)), str_replace('""', '"', implode(", ", $strCFVArray)));
                             } else {
                                 $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`) VALUES %s", str_replace('""', '"', implode(", ", $strAssetIdArray)));
                             }
                             $objDatabase->NonQuery($strQuery);
                             $theAsset = Asset::Load($intInsertId);
                             $strQuery = $this->substactNotAllowedFields($theAsset->AssetModelId, $theAsset->AssetId);
                             if (!empty($strQuery)) {
                                 //$objDatabase->NonQuery($this->substactNotAllowedFields($theAsset->AssetModelId,$theAsset->AssetId));
                                 $objDatabase->NonQuery($strQuery);
                             }
                         }
                         $this->strAssetValuesArray = array();
                     }
                     // Updates
                     if (count($strUpdatedValuesArray)) {
                         $objDatabase = Asset::GetDatabase();
                         foreach ($strUpdatedValuesArray as $query) {
                             $objDatabase->NonQuery($query);
                         }
                         foreach ($this->objUpdatedItemArray as $intItemKey => $objUpdatedItem) {
                             if (isset($strUpdatedItemCFVArray[$intItemKey]) && count($strUpdatedItemCFVArray[$intItemKey])) {
                                 $strCFVArray = array();
                                 foreach ($arrAssetCustomField as $objCustomField) {
                                     $strCFVArray[] = sprintf("`cfv_%s`=%s", $objCustomField->CustomFieldId, $strUpdatedItemCFVArray[$intItemKey][$objCustomField->CustomFieldId]);
                                 }
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strCFVArray)), $intItemKey);
                                     $objDatabase->NonQuery($strQuery);
                                     // insert nulls where not allowed
                                     $theAsset = Asset::Load($intItemKey);
                                     $strQuery = $this->substactNotAllowedFields($theAsset->AssetModelId, $theAsset->AssetId);
                                     if ($strQuery) {
                                         $objDatabase->NonQuery($strQuery);
                                     }
                                 }
                             }
                         }
                     }
                     //}
                     //$this->intCurrentFile++;
                     //break;
                 }
                 //$j++;
             }
             if ($this->intImportStep == 3) {
                 /*if (count($this->strSelectedValueArray)) {
                 			$objDatabase = CustomField::GetDatabase();
                 			$strQuery = sprintf("INSERT INTO `custom_field_selection` " .
                 				"(`entity_id`,`entity_qtype_id`, `custom_field_value_id`) " .
                 				"VALUES %s;", implode(", ", $this->strSelectedValueArray));
                 			$objDatabase->NonQuery($strQuery);
                 		}*/
                 // Insert Values into helper tables
                 $objDatabase = Asset::GetDatabase();
                 $objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=0;");
                 // Insert into asset_custom_field_helper
                 $objDatabase->NonQuery(sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`) (SELECT `asset_id` FROM `asset` WHERE `asset_id` NOT IN (SELECT `asset_id` FROM `asset_custom_field_helper`));"));
                 // Inserts end
                 $objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=1;");
                 $this->blnImportEnd = true;
                 $this->btnNext->Warning = "";
                 $this->lblImportResults->Display = true;
                 if (count($this->objNewAssetArray)) {
                     //$this->lblImportAssets->Display = true;
                     $this->dtgAsset->Paginator = new QPaginator($this->dtgAsset);
                     $this->dtgAsset->ItemsPerPage = 20;
                 }
                 if (count($this->objUpdatedAssetArray)) {
                     $this->lblImportUpdatedAssets->Display = true;
                     $this->dtgUpdatedAsset->Paginator = new QPaginator($this->dtgUpdatedAsset);
                     $this->dtgUpdatedAsset->ItemsPerPage = 20;
                 }
                 if (count($this->objNewAssetArray)) {
                     $this->lblImportAsset->Display = true;
                     $this->dtgAsset->Paginator = new QPaginator($this->dtgAsset);
                     $this->dtgAsset->ItemsPerPage = 20;
                 }
                 $this->btnNext->Display = false;
                 $this->btnCancel->Display = false;
                 $this->btnUndoLastImport->Display = true;
                 $this->btnImportMore->Display = true;
                 $this->btnReturnToAssets->Display = true;
                 $this->lblImportSuccess->Display = true;
                 $this->lblImportSuccess->Text = sprintf("Success:<br/>" . "<b>%s</b> Records imported successfully<br/>" . "<b>%s</b> Records skipped due to error<br/>", count($this->objNewAssetArray) + count($this->objUpdatedItemArray), $this->intSkippedRecordCount);
                 if ($this->intSkippedRecordCount) {
                     $this->lblImportSuccess->Text .= sprintf("<a href='./asset_import.php?intDownloadCsv=1'>Click here to download records that could not be imported</a>");
                 }
                 $this->lblImportSuccess->Text .= "<br/><br/>";
                 $this->intImportStep = -1;
             }
             // Enable Next button
             $this->btnNext->Enabled = true;
             if (!$this->blnImportEnd && !$this->intCurrentFile) {
                 $this->intImportStep++;
             }
         }
         fclose($file_skipped);
     }
     if (!$blnError) {
         if (($this->blnImportEnd || $this->intImportStep == 2) && $this->intImportStep != -1) {
             $this->intStep++;
             $this->DisplayStepForm($this->intStep);
         }
         if (!$this->blnImportEnd) {
             $this->btnNext->Warning = "Please wait...";
             QApplication::ExecuteJavaScript("document.getElementById('" . $this->btnNext->ControlId . "').click();");
         }
         if (!($this->intCurrentFile < count($this->strFilePathArray))) {
             $this->intCurrentFile = 0;
             $this->intImportStep++;
         }
     }
 }
Exemple #9
0
 }
 if (!$blnError) {
     $arrPendingReceiptId = array_unique($arrPendingReceiptId);
     foreach ($objAssetArray as $objAsset) {
         $objDestinationLocation = $arrLocation[$objAsset->AssetId];
         $intDestinationLocationId = $objDestinationLocation->LocationId;
         // Set the DestinationLocation of the AssetTransaction
         $objAssetTransaction = $objAssetTransactionArray[$objAsset->AssetId];
         $objAssetTransaction->DestinationLocationId = $intDestinationLocationId;
         $objAssetTransaction->Save();
         // Reload AssetTransaction to avoid Optimistic Locking Exception if this receipt is edited and saved.
         $objAssetTransaction = AssetTransaction::Load($objAssetTransaction->AssetTransactionId);
         // Move the asset to the new location
         $objAssetTransaction->Asset->LocationId = $intDestinationLocationId;
         $objAssetTransaction->Asset->Save();
         $objAssetTransaction->Asset = Asset::Load($objAssetTransaction->AssetId);
     }
     foreach ($arrPendingReceiptId as $intReceiptId) {
         Receipt::ReceiptComplete($intReceiptId);
     }
     $strWarning .= "Your transaction has successfully completed<br /><a href='index.php'>Main Menu</a> | <a href='asset_menu.php'>Manage Assets</a><br />";
     //Remove that flag when transaction is compelete or exists some errors
     unset($_SESSION['intUserAccountId']);
     $blnTransactionComplete = true;
     $arrCheckedAssetCodeLocation = "";
 } else {
     $strWarning .= "This transaction has not been completed.<br />";
 }
 if (is_array($arrCheckedAssetCodeLocation)) {
     foreach ($arrCheckedAssetCodeLocation as $strAssetCodeLocation) {
         list($strAssetCode, $strLocation) = split('[|]', $strAssetCodeLocation, 2);
 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 btnEdit_Click($strFormId, $strControlId, $strParameter)
 {
     $strParameterArray = explode(',', $strParameter);
     $objAsset = Asset::Load($strParameterArray[0]);
     $objEditPanel = new AssetEditPanel($this, $this->strCloseEditPanelMethod, $objAsset);
     $strMethodName = $this->strSetEditPanelMethod;
     $this->objForm->{$strMethodName}($objEditPanel);
 }
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'AssetTransactionId':
             /**
              * Gets the value for intAssetTransactionId (Read-Only PK)
              * @return integer
              */
             return $this->intAssetTransactionId;
         case 'AssetId':
             /**
              * Gets the value for intAssetId (Not Null)
              * @return integer
              */
             return $this->intAssetId;
         case 'TransactionId':
             /**
              * Gets the value for intTransactionId (Not Null)
              * @return integer
              */
             return $this->intTransactionId;
         case 'ParentAssetTransactionId':
             /**
              * Gets the value for intParentAssetTransactionId 
              * @return integer
              */
             return $this->intParentAssetTransactionId;
         case 'SourceLocationId':
             /**
              * Gets the value for intSourceLocationId 
              * @return integer
              */
             return $this->intSourceLocationId;
         case 'DestinationLocationId':
             /**
              * Gets the value for intDestinationLocationId 
              * @return integer
              */
             return $this->intDestinationLocationId;
         case 'NewAssetFlag':
             /**
              * Gets the value for blnNewAssetFlag 
              * @return boolean
              */
             return $this->blnNewAssetFlag;
         case 'NewAssetId':
             /**
              * Gets the value for intNewAssetId 
              * @return integer
              */
             return $this->intNewAssetId;
         case 'ScheduleReceiptFlag':
             /**
              * Gets the value for blnScheduleReceiptFlag 
              * @return boolean
              */
             return $this->blnScheduleReceiptFlag;
         case 'ScheduleReceiptDueDate':
             /**
              * Gets the value for dttScheduleReceiptDueDate 
              * @return QDateTime
              */
             return $this->dttScheduleReceiptDueDate;
         case 'CreatedBy':
             /**
              * Gets the value for intCreatedBy 
              * @return integer
              */
             return $this->intCreatedBy;
         case 'CreationDate':
             /**
              * Gets the value for dttCreationDate 
              * @return QDateTime
              */
             return $this->dttCreationDate;
         case 'ModifiedBy':
             /**
              * Gets the value for intModifiedBy 
              * @return integer
              */
             return $this->intModifiedBy;
         case 'ModifiedDate':
             /**
              * Gets the value for strModifiedDate (Read-Only Timestamp)
              * @return string
              */
             return $this->strModifiedDate;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'Asset':
             /**
              * Gets the value for the Asset object referenced by intAssetId (Not Null)
              * @return Asset
              */
             try {
                 if (!$this->objAsset && !is_null($this->intAssetId)) {
                     $this->objAsset = Asset::Load($this->intAssetId);
                 }
                 return $this->objAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'Transaction':
             /**
              * Gets the value for the Transaction object referenced by intTransactionId (Not Null)
              * @return Transaction
              */
             try {
                 if (!$this->objTransaction && !is_null($this->intTransactionId)) {
                     $this->objTransaction = Transaction::Load($this->intTransactionId);
                 }
                 return $this->objTransaction;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ParentAssetTransaction':
             /**
              * Gets the value for the AssetTransaction object referenced by intParentAssetTransactionId 
              * @return AssetTransaction
              */
             try {
                 if (!$this->objParentAssetTransaction && !is_null($this->intParentAssetTransactionId)) {
                     $this->objParentAssetTransaction = AssetTransaction::Load($this->intParentAssetTransactionId);
                 }
                 return $this->objParentAssetTransaction;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'SourceLocation':
             /**
              * Gets the value for the Location object referenced by intSourceLocationId 
              * @return Location
              */
             try {
                 if (!$this->objSourceLocation && !is_null($this->intSourceLocationId)) {
                     $this->objSourceLocation = Location::Load($this->intSourceLocationId);
                 }
                 return $this->objSourceLocation;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'DestinationLocation':
             /**
              * Gets the value for the Location object referenced by intDestinationLocationId 
              * @return Location
              */
             try {
                 if (!$this->objDestinationLocation && !is_null($this->intDestinationLocationId)) {
                     $this->objDestinationLocation = Location::Load($this->intDestinationLocationId);
                 }
                 return $this->objDestinationLocation;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'NewAsset':
             /**
              * Gets the value for the Asset object referenced by intNewAssetId 
              * @return Asset
              */
             try {
                 if (!$this->objNewAsset && !is_null($this->intNewAssetId)) {
                     $this->objNewAsset = Asset::Load($this->intNewAssetId);
                 }
                 return $this->objNewAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'CreatedByObject':
             /**
              * Gets the value for the UserAccount object referenced by intCreatedBy 
              * @return UserAccount
              */
             try {
                 if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) {
                     $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy);
                 }
                 return $this->objCreatedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ModifiedByObject':
             /**
              * Gets the value for the UserAccount object referenced by intModifiedBy 
              * @return UserAccount
              */
             try {
                 if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) {
                     $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy);
                 }
                 return $this->objModifiedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         case '_ChildAssetTransaction':
             /**
              * Gets the value for the private _objChildAssetTransaction (Read-Only)
              * if set due to an expansion on the asset_transaction.parent_asset_transaction_id reverse relationship
              * @return AssetTransaction
              */
             return $this->_objChildAssetTransaction;
         case '_ChildAssetTransactionArray':
             /**
              * Gets the value for the private _objChildAssetTransactionArray (Read-Only)
              * if set due to an ExpandAsArray on the asset_transaction.parent_asset_transaction_id reverse relationship
              * @return AssetTransaction[]
              */
             return (array) $this->_objChildAssetTransactionArray;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 public function SetupDisplay($intTransactionTypeId)
 {
     $this->intTransactionTypeId = $intTransactionTypeId;
     $this->ctlAssetSearchTool->blnSearchArchived = false;
     switch ($this->intTransactionTypeId) {
         // Move
         case 1:
             $this->lstLocation->Display = true;
             break;
             // Check In
         // Check In
         case 2:
             $this->lstLocation->Display = true;
             break;
             // Check Out
         // Check Out
         case 3:
             $this->lstLocation->Display = false;
             break;
             // Reserve
         // Reserve
         case 8:
             $this->lstLocation->Display = false;
             break;
             // Unreserve
         // Unreserve
         case 9:
             $this->lstLocation->Display = false;
             break;
             // Archive
         // Archive
         case 10:
             $this->lstLocation->Display = false;
             break;
             // Unarchive
         // Unarchive
         case 11:
             $this->lstLocation->Display = true;
             $this->ctlAssetSearchTool->blnSearchArchived = true;
             break;
     }
     // Redeclare in case the asset has been edited
     $this->objAssetArray = null;
     if ($this->blnEditMode && $this->objAsset instanceof Asset) {
         $this->objAssetArray[] = Asset::Load($this->objAsset->AssetId);
         // Load all child assets
         $objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($this->objAsset->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", $this->objAsset->AssetCode, implode('<br />', $strAssetCodeArray));
         }
     }
 }
 public function SetupDisplay($intTransactionTypeId)
 {
     $this->intTransactionTypeId = $intTransactionTypeId;
     switch ($this->intTransactionTypeId) {
         // Move
         case 1:
             $this->lstLocation->Display = true;
             break;
             // Check In
         // Check In
         case 2:
             $this->lstLocation->Display = true;
             break;
             // Check Out
         // Check Out
         case 3:
             $this->lstLocation->Display = false;
             break;
             // Reserve
         // Reserve
         case 8:
             $this->lstLocation->Display = false;
             break;
             // Unreserve
         // Unreserve
         case 9:
             $this->lstLocation->Display = false;
             break;
     }
     // Redeclare in case the asset has been edited
     $this->objAssetArray = null;
     if ($this->blnEditMode && $this->objAsset instanceof Asset) {
         $this->objAssetArray[] = Asset::Load($this->objAsset->AssetId);
     }
 }
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'AssetId':
             // Gets the value for intAssetId (PK)
             // @return integer
             return $this->intAssetId;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'Asset':
             // Gets the value for the Asset object referenced by intAssetId (PK)
             // @return Asset
             try {
                 if (!$this->objAsset && !is_null($this->intAssetId)) {
                     $this->objAsset = Asset::Load($this->intAssetId);
                 }
                 return $this->objAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         case '__Restored':
             return $this->__blnRestored;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
  * edit, or if we are also allowed to create a new one, etc.
  * 
  * @param mixed $objParentObject QForm or QPanel which will be using this AssetMetaControl
  * @param integer $intAssetId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing Asset object creation - defaults to CreateOrEdit
  * @return AssetMetaControl
  */
 public static function Create($objParentObject, $intAssetId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intAssetId)) {
         $objAsset = Asset::Load($intAssetId);
         // Asset was found -- return it!
         if ($objAsset) {
             return new AssetMetaControl($objParentObject, $objAsset);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a Asset object with PK arguments: ' . $intAssetId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new AssetMetaControl($objParentObject, new Asset());
 }
Exemple #17
0
 protected function UpdateReceiptFields()
 {
     $this->objReceipt->TransactionId = $this->objTransaction->TransactionId;
     if (QApplication::$TracmorSettings->CustomReceiptNumbers) {
         $this->objReceipt->ReceiptNumber = $this->txtReceiptNumber->Text;
     } elseif (!$this->blnEditMode) {
         $this->objReceipt->ReceiptNumber = Receipt::LoadNewReceiptNumber();
     }
     $this->objReceipt->FromCompanyId = $this->lstFromCompany->SelectedValue;
     $this->objReceipt->FromContactId = $this->lstFromContact->SelectedValue;
     $this->objReceipt->ToContactId = $this->lstToContact->SelectedValue;
     $this->objReceipt->ToAddressId = $this->lstToAddress->SelectedValue;
     $this->objReceipt->DueDate = $this->calDueDate->DateTime;
     $this->objReceipt->ReceiptDate = $this->calDateReceived->DateTime;
     //!
     $this->objTransaction->Note = $this->txtNote->Text;
     // Reload the Assets and inventory locations so that they don't trigger an OLE if edit/save adding assets or inventory multiple times
     if ($this->objAssetTransactionArray) {
         foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
             $objAssetTransaction->Asset = Asset::Load($objAssetTransaction->AssetId);
         }
     }
     if ($this->objInventoryTransactionArray) {
         foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
             $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId);
         }
     }
 }
Exemple #18
0
 /**
  * Override method to perform a property "Get"
  * This will get the value of $strName
  *
  * @param string $strName Name of the property to get
  * @return mixed
  */
 public function __get($strName)
 {
     switch ($strName) {
         ///////////////////
         // Member Variables
         ///////////////////
         case 'AssetId':
             // Gets the value for intAssetId (Read-Only PK)
             // @return integer
             return $this->intAssetId;
         case 'ParentAssetId':
             // Gets the value for intParentAssetId
             // @return integer
             return $this->intParentAssetId;
         case 'AssetModelId':
             // Gets the value for intAssetModelId (Not Null)
             // @return integer
             return $this->intAssetModelId;
         case 'LocationId':
             // Gets the value for intLocationId
             // @return integer
             return $this->intLocationId;
         case 'AssetCode':
             // Gets the value for strAssetCode (Unique)
             // @return string
             return $this->strAssetCode;
         case 'ImagePath':
             // Gets the value for strImagePath
             // @return string
             return $this->strImagePath;
         case 'CheckedOutFlag':
             // Gets the value for blnCheckedOutFlag
             // @return boolean
             return $this->blnCheckedOutFlag;
         case 'ReservedFlag':
             // Gets the value for blnReservedFlag
             // @return boolean
             return $this->blnReservedFlag;
         case 'LinkedFlag':
             // Gets the value for blnLinkedFlag
             // @return boolean
             return $this->blnLinkedFlag;
         case 'ArchivedFlag':
             // Gets the value for blnArchivedFlag
             // @return boolean
             return $this->blnArchivedFlag;
         case 'CreatedBy':
             // Gets the value for intCreatedBy
             // @return integer
             return $this->intCreatedBy;
         case 'CreationDate':
             // Gets the value for dttCreationDate
             // @return QDateTime
             return $this->dttCreationDate;
         case 'ModifiedBy':
             // Gets the value for intModifiedBy
             // @return integer
             return $this->intModifiedBy;
         case 'ModifiedDate':
             // Gets the value for strModifiedDate (Read-Only Timestamp)
             // @return string
             return $this->strModifiedDate;
         case 'DepreciationFlag':
             // Gets the value for blnDepreciationFlag
             // @return boolean
             return $this->blnDepreciationFlag;
         case 'PurchaseDate':
             // Gets the value for dttPurchaseDate
             // @return QDateTime
             return $this->dttPurchaseDate;
         case 'PurchaseCost':
             // Gets the value for fltPurchaseCost
             // @return double
             return $this->fltPurchaseCost;
             ///////////////////
             // Member Objects
             ///////////////////
         ///////////////////
         // Member Objects
         ///////////////////
         case 'ParentAsset':
             // Gets the value for the Asset object referenced by intParentAssetId
             // @return Asset
             try {
                 if (!$this->objParentAsset && !is_null($this->intParentAssetId)) {
                     $this->objParentAsset = Asset::Load($this->intParentAssetId);
                 }
                 return $this->objParentAsset;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'AssetModel':
             // Gets the value for the AssetModel object referenced by intAssetModelId (Not Null)
             // @return AssetModel
             try {
                 if (!$this->objAssetModel && !is_null($this->intAssetModelId)) {
                     $this->objAssetModel = AssetModel::Load($this->intAssetModelId);
                 }
                 return $this->objAssetModel;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'Location':
             // Gets the value for the Location object referenced by intLocationId
             // @return Location
             try {
                 if (!$this->objLocation && !is_null($this->intLocationId)) {
                     $this->objLocation = Location::Load($this->intLocationId);
                 }
                 return $this->objLocation;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'CreatedByObject':
             // Gets the value for the UserAccount object referenced by intCreatedBy
             // @return UserAccount
             try {
                 if (!$this->objCreatedByObject && !is_null($this->intCreatedBy)) {
                     $this->objCreatedByObject = UserAccount::Load($this->intCreatedBy);
                 }
                 return $this->objCreatedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'ModifiedByObject':
             // Gets the value for the UserAccount object referenced by intModifiedBy
             // @return UserAccount
             try {
                 if (!$this->objModifiedByObject && !is_null($this->intModifiedBy)) {
                     $this->objModifiedByObject = UserAccount::Load($this->intModifiedBy);
                 }
                 return $this->objModifiedByObject;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
         case 'AssetCustomFieldHelper':
             // Gets the value for the AssetCustomFieldHelper object that uniquely references this Asset
             // by objAssetCustomFieldHelper (Unique)
             // @return AssetCustomFieldHelper
             try {
                 if ($this->objAssetCustomFieldHelper === false) {
                     // We've attempted early binding -- and the reverse reference object does not exist
                     return null;
                 }
                 if (!$this->objAssetCustomFieldHelper) {
                     $this->objAssetCustomFieldHelper = AssetCustomFieldHelper::LoadByAssetId($this->intAssetId);
                 }
                 return $this->objAssetCustomFieldHelper;
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
             ////////////////////////////
             // Virtual Object References (Many to Many and Reverse References)
             // (If restored via a "Many-to" expansion)
             ////////////////////////////
         ////////////////////////////
         // Virtual Object References (Many to Many and Reverse References)
         // (If restored via a "Many-to" expansion)
         ////////////////////////////
         case '_ChildAsset':
             // Gets the value for the private _objChildAsset (Read-Only)
             // if set due to an expansion on the asset.parent_asset_id reverse relationship
             // @return Asset
             return $this->_objChildAsset;
         case '_ChildAssetArray':
             // Gets the value for the private _objChildAssetArray (Read-Only)
             // if set due to an ExpandAsArray on the asset.parent_asset_id reverse relationship
             // @return Asset[]
             return (array) $this->_objChildAssetArray;
         case '_AssetTransaction':
             // Gets the value for the private _objAssetTransaction (Read-Only)
             // if set due to an expansion on the asset_transaction.asset_id reverse relationship
             // @return AssetTransaction
             return $this->_objAssetTransaction;
         case '_AssetTransactionArray':
             // Gets the value for the private _objAssetTransactionArray (Read-Only)
             // if set due to an ExpandAsArray on the asset_transaction.asset_id reverse relationship
             // @return AssetTransaction[]
             return (array) $this->_objAssetTransactionArray;
         case '_AssetTransactionAsNew':
             // Gets the value for the private _objAssetTransactionAsNew (Read-Only)
             // if set due to an expansion on the asset_transaction.new_asset_id reverse relationship
             // @return AssetTransaction
             return $this->_objAssetTransactionAsNew;
         case '_AssetTransactionAsNewArray':
             // Gets the value for the private _objAssetTransactionAsNewArray (Read-Only)
             // if set due to an ExpandAsArray on the asset_transaction.new_asset_id reverse relationship
             // @return AssetTransaction[]
             return (array) $this->_objAssetTransactionAsNewArray;
         case '__Restored':
             return $this->__blnRestored;
         default:
             try {
                 return parent::__get($strName);
             } catch (QCallerException $objExc) {
                 $objExc->IncrementOffset();
                 throw $objExc;
             }
     }
 }