Exemplo n.º 1
0
 public function btnRemove_Click($strFormId, $strControlId, $strParameter)
 {
     $intAssetId = $strParameter;
     $objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($intAssetId);
     if ($this->ctlAssetTransact->objAssetArray) {
         foreach ($this->ctlAssetTransact->objAssetArray as $key => $value) {
             if ($value->AssetId == $intAssetId) {
                 unset($this->ctlAssetTransact->objAssetArray[$key]);
             } elseif ($objLinkedAssetArray) {
                 foreach ($objLinkedAssetArray as $objLinkedAsset) {
                     if ($value->AssetId == $objLinkedAsset->AssetId) {
                         unset($this->ctlAssetTransact->objAssetArray[$key]);
                     }
                 }
             }
         }
     }
     $this->ctlAssetTransact->dtgAssetTransact->Refresh();
 }
Exemplo n.º 2
0
 public function btnReceiveAssetTransaction_Click($strFormId, $strControlId, $strParameter)
 {
     $blnError = false;
     $intAssetTransactionId = $strParameter;
     if ($this->objAssetTransactionArray) {
         try {
             // Get an instance of the database
             $objDatabase = QApplication::$Database[1];
             // Begin a MySQL Transaction to be either committed or rolled back
             $objDatabase->TransactionBegin();
             // This boolean later lets us know if we need to flip the ReceivedFlag
             $blnAllAssetsReceived = true;
             $this->dtgAssetTransact->Warning = "";
             $objAssetTransactionArray = array();
             $objLinkedAssetTransactionArray = array();
             foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                 if (!$objAssetTransaction->Asset->LinkedFlag) {
                     $objAssetTransactionArray[] = $objAssetTransaction;
                 } else {
                     $objLinkedAssetTransactionArray[$objAssetTransaction->Asset->AssetCode] = $objAssetTransaction;
                 }
             }
             foreach ($objAssetTransactionArray as &$objAssetTransaction) {
                 if ($objAssetTransaction->AssetTransactionId == $intAssetTransactionId) {
                     // Get the value of the location where this Asset is being received to
                     $lstLocationAssetReceived = $this->GetControl('lstLocationAssetReceived' . $objAssetTransaction->AssetTransactionId);
                     if ($lstLocationAssetReceived && $lstLocationAssetReceived->SelectedValue) {
                         if ($objAssetTransaction->Asset->LinkedFlag) {
                             $blnError = true;
                             $this->dtgAssetTransact->Warning .= sprintf("Asset Tag %s is locked to a parent asset.<br />", $objAssetTransaction->Asset->AssetCode);
                         } else {
                             // Set the DestinationLocation of the AssetTransaction
                             $objAssetTransaction->DestinationLocationId = $lstLocationAssetReceived->SelectedValue;
                             $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 = $lstLocationAssetReceived->SelectedValue;
                             $objAssetTransaction->Asset->Save();
                             if ($objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId)) {
                                 foreach ($objLinkedAssetArray as $objLinkedAsset) {
                                     $objLinkedAssetTransaction = $objLinkedAssetTransactionArray[$objLinkedAsset->AssetCode];
                                     $objLinkedAssetTransaction->DestinationLocationId = $lstLocationAssetReceived->SelectedValue;
                                     $objLinkedAssetTransaction->Save();
                                     $objLinkedAssetTransaction->Asset->LocationId = $lstLocationAssetReceived->SelectedValue;
                                     $objLinkedAssetTransaction->Asset->Save();
                                 }
                             }
                             $objAssetTransaction->Asset = Asset::Load($objAssetTransaction->AssetId);
                         }
                     } else {
                         $blnError = true;
                         $lstLocationAssetReceived->Warning = "Please Select a Location.";
                     }
                 }
                 // If any AssetTransaction still does not have a DestinationLocation, it is still Pending
                 if (!$objAssetTransaction->DestinationLocationId && !$objAssetTransaction->Asset->LinkedFlag) {
                     $blnAllAssetsReceived = false;
                 }
             }
             // If all the assets have been received, check that all the inventory has been received
             if ($blnAllAssetsReceived) {
                 $blnAllInventoryReceived = true;
                 if ($this->objInventoryTransactionArray) {
                     foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
                         if (!$objInventoryTransaction->DestinationLocationId) {
                             $blnAllInventoryReceived = false;
                         }
                     }
                 }
                 // Set the entire receipt as received if assets and inventory have all been received
                 if ($blnAllInventoryReceived) {
                     $this->objReceipt->ReceivedFlag = true;
                     $this->objReceipt->ReceiptDate = new QDateTime(QDateTime::Now);
                     $this->objReceipt->Save();
                     // Reload to get new timestamp to avoid optimistic locking if edited/saved again without reload
                     $this->objReceipt = Receipt::Load($this->objReceipt->ReceiptId);
                     // Update labels (specifically we want to update Received Date)
                     $this->UpdateReceiptLabels();
                 }
             }
             // Commit all of the transactions to the database
             $objDatabase->TransactionCommit();
         } catch (QExtendedOptimisticLockingException $objExc) {
             // Rollback the database transactions if an exception was thrown
             $objDatabase->TransactionRollback();
             if ($objExc->Class == 'AssetTransaction' || $objExc->Class == 'Asset') {
                 // Set the offending AssetTransaction DestinationLocation to null so that the value doesn't change in the datagrid
                 if ($objExc->Class == 'AssetTransaction' && $this->objAssetTransactionArray) {
                     foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                         if ($objAssetTransaction->AssetTransactionId == $objExc->EntityId) {
                             $objAssetTransaction->DestinationLocationId = null;
                         }
                     }
                 }
                 $this->dtgAssetTransact->Warning = sprintf('That asset has been added, removed, or received by another user. You must <a href="receipt_edit.php?intReceiptId=%s">Refresh</a> to edit this receipt.', $this->objReceipt->ReceiptId);
             } else {
                 throw new QOptimisticLockingException($objExc->Class);
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Loads array of Child Linked Asset Objects with custom field virtual attributes
  *
  * @param int $intParentAssetId AssetId of the parent asset to load linked assets
  * @return mixed
  */
 public static function LoadChildLinkedArrayByParentAssetId($intParentAssetId)
 {
     $objLinkedAssetArray = array();
     Asset::QueryHelper($objDatabase);
     $arrCustomFieldSql = CustomField::GenerateHelperSql(EntityQtype::Asset);
     // Setup the SQL Query
     $strQuery = sprintf("\n\t\t\t\tSELECT \n\t\t\t\t\t`asset`.* \n\t\t\t\t\t%s\n\t\t\t\tFROM \n\t\t\t\t\t`asset` \n\t\t\t\t\t%s\n\t\t\t\tWHERE `asset`.`parent_asset_id` = %s\n\t\t\t\tAND `asset`.`linked_flag` = 1\n\t\t\t", $arrCustomFieldSql['strSelect'], $arrCustomFieldSql['strFrom'], $intParentAssetId);
     // Perform the Query and Instantiate the Result
     $objDbResult = $objDatabase->Query($strQuery);
     $objChildAssetArray = Asset::InstantiateDbResult($objDbResult);
     if ($objChildAssetArray && count($objChildAssetArray)) {
         foreach ($objChildAssetArray as $objLinkedAsset) {
             $objLinkedAssetArray[] = $objLinkedAsset;
             $objNewLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objLinkedAsset->AssetId);
             if ($objNewLinkedAssetArray) {
                 foreach ($objNewLinkedAssetArray as $objLinkedAsset2) {
                     $objLinkedAssetArray[] = $objLinkedAsset2;
                 }
             }
         }
         return $objLinkedAssetArray;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 } else {
     $intDestinationLocationId = $objDestinationLocation->LocationId;
     // There is a 1 to Many relationship between Transaction and AssetTransaction so each Transaction can have many AssetTransactions.
     $objTransaction = new Transaction();
     $objTransaction->EntityQtypeId = EntityQtype::Asset;
     $objTransaction->TransactionTypeId = 2;
     // Check in
     $objTransaction->Save();
     foreach ($objAssetArray as $objAsset) {
         $objAssetTransaction = new AssetTransaction();
         $objAssetTransaction->AssetId = $objAsset->AssetId;
         $objAssetTransaction->TransactionId = $objTransaction->TransactionId;
         $objAssetTransaction->SourceLocationId = $objAsset->LocationId;
         $objAssetTransaction->DestinationLocationId = $intDestinationLocationId;
         $objAssetTransaction->Save();
         $objLinkedAssetArrayByNewAsset = Asset::LoadChildLinkedArrayByParentAssetId($objAsset->AssetId);
         if ($objLinkedAssetArrayByNewAsset) {
             foreach ($objLinkedAssetArrayByNewAsset as $objLinkedAsset) {
                 $objLinkedAsset->CheckedOutFlag = false;
                 $objLinkedAsset->LocationId = $intDestinationLocationId;
                 $objLinkedAsset->Save();
                 // Create the new assettransaction object and save it
                 $objAssetTransaction = new AssetTransaction();
                 $objAssetTransaction->AssetId = $objLinkedAsset->AssetId;
                 $objAssetTransaction->TransactionId = $objTransaction->TransactionId;
                 $objAssetTransaction->SourceLocationId = $objAsset->LocationId;
                 $objAssetTransaction->DestinationLocationId = $intDestinationLocationId;
                 $objAssetTransaction->Save();
             }
         }
         $objAsset->CheckedOutFlag = false;
 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 by asset_id as asset_code also can be changed
     $this->objAssetArray = null;
     if ($this->blnEditMode && $this->objAsset instanceof Asset) {
         $this->objAssetArray[] = Asset::LoadByAssetIdWithCustomFields($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));
         }
     }
 }
Exemplo n.º 6
0
             $objAssetTransactionArray[$objNewAsset->AssetId] = $objPendingReceipt;
         }
     }
 }
 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();
         $objAsset->LocationId = $intDestinationLocationId;
         $objAsset->Save();
         if ($objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAsset->AssetId)) {
             foreach ($objLinkedAssetArray as $objLinkedAsset) {
                 $objLinkedAsset->LocationId = $intDestinationLocationId;
                 $objLinkedAsset->Save();
                 if ($objChildPendingReceipt = AssetTransaction::PendingReceipt($objLinkedAsset->AssetId)) {
                     $objChildPendingReceipt->DestinationLocationId = $intDestinationLocationId;
                     $objChildPendingReceipt->Save();
                 }
             }
         }
     }
     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
Exemplo n.º 7
0
 protected function disableAdvancedIfInternal()
 {
     if (!$this->lblFromCompany->Display) {
         if ($this->lstToCompany->SelectedValue == $this->lstFromCompany->SelectedValue) {
             // switch off advansed parameters
             if ($this->objAssetTransactionArray) {
                 $objNewAssetTransactionArray = array();
                 foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                     $objNewAssetTransactionArray[$objAssetTransaction->Asset->AssetCode] = $objAssetTransaction;
                 }
                 foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                     // set advansed to 'None'
                     $objAssetTransaction->ScheduleReceiptFlag = false;
                     $objAssetTransaction->NewAssetFlag = false;
                     $objAssetTransaction->NewAssetId = null;
                     $objAssetTransaction->NewAsset = null;
                     $objAssetTransaction->ScheduleReceiptDueDate = null;
                     if ($objLinkedAssetCodeArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId)) {
                         foreach ($objLinkedAssetCodeArray as $objLinkedAssetCode) {
                             $objLinkedAssetTransaction = $objNewAssetTransactionArray[$objLinkedAssetCode->AssetCode];
                             $objLinkedAssetTransaction->ScheduleReceiptFlag = false;
                             $objLinkedAssetTransaction->NewAssetFlag = false;
                             $objLinkedAssetTransaction->NewAssetId = null;
                             $objLinkedAssetTransaction->NewAsset = null;
                             $objLinkedAssetTransaction->ScheduleReceiptDueDate = null;
                         }
                     }
                 }
                 $this->blnModifyAssets = true;
             }
             $this->dtgAssetTransact->RemoveColumnByName('Advanced');
             $this->dtgAssetTransact->RemoveColumnByName('Due Date');
         } else {
             if (!$this->dtgAssetTransact->GetColumnByName('Advanced')) {
                 $this->dtgAssetTransact->AddColumn(new QDataGridColumn('Advanced', '<?= $_FORM->AdvancedColumn_Render($_ITEM) ?>', array('CssClass' => "dtg_column", 'HtmlEntities' => false)));
                 $this->dtgAssetTransact->AddColumn(new QDataGridColumn('Due Date', '<?= $_FORM->DueDateColumn_Render($_ITEM) ?>', array('CssClass' => "dtg_column", 'HtmlEntities' => false)));
             }
         }
     }
 }
Exemplo n.º 8
0
 protected function btnCompleteShipment_Click($strFormId, $strControlId, $strParameter)
 {
     $blnError = false;
     if ($this->objAssetTransactionArray && $this->objInventoryTransactionArray) {
         $intEntityQtypeId = EntityQtype::AssetInventory;
     } elseif ($this->objAssetTransactionArray) {
         $intEntityQtypeId = EntityQtype::Asset;
     } elseif ($this->objInventoryTransactionArray) {
         $intEntityQtypeId = EntityQtype::Inventory;
     } else {
         $blnError = true;
         $this->btnCompleteShipment->Warning = 'There are no assets or inventory in this shipment.';
     }
     // If Courier is Fedex, validate Fedex inputs
     if ($this->objShipment->CourierId === 1) {
         if (!$this->lstPackageType->SelectedValue) {
             $blnError = true;
             $this->lblPackageType->Warning = "Please select a package type.";
             $this->lstPackageType->Warning = "Please select a package type.";
         }
         if (!$this->txtPackageWeight->Text) {
             $blnError = true;
             $this->lblPackageWeight->Warning = "Please enter a weight for this package.";
             $this->txtPackageWeight->Warning = "Please enter a weight for this package.";
         }
         //if (!$this->lstWeightUnit->SelectedValue) {
         //	$blnError = true;
         //	$this->lstWeightUnit->Warning = "Please select a weight unit.";
         //}
         //if (!$this->txtValue->Text) {
         //	$blnError = true;
         //	$this->txtValue->Warning = "Please enter a value.";
         //}
         //if (!$this->lstCurrencyUnit->SelectedValue) {
         //	$blnError = true;
         //	$this->lstCurrencyUnit->Warning = "Please select a currency type.";
         //}
     }
     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();
             if (!$this->blnEditMode) {
                 // this is a new shipment so save the transaction & shipment before completing
                 // Create the new transaction object and save it
                 $this->objTransaction = new Transaction();
                 $this->objTransaction->EntityQtypeId = $intEntityQtypeId;
                 $this->objTransaction->TransactionTypeId = 6;
                 $this->objTransaction->Note = $this->txtNote->Text;
                 $this->objTransaction->Save();
                 $this->UpdateShipmentFields();
                 $this->objShipment->Save(true);
                 if ($this->arrCustomFields) {
                     // Save the values from all of the custom field controls to save the shipment
                     CustomField::SaveControls($this->objShipment->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objShipment->ShipmentId, 10);
                 }
                 // If the courier is FedEx, create new fedexShipment
                 if ($this->lstCourier->SelectedValue === 1) {
                     if (!$this->objFedexShipment instanceof FedexShipment) {
                         $this->objFedexShipment = new FedexShipment();
                     }
                     $this->objFedexShipment->ShipmentId = $this->objShipment->ShipmentId;
                     $this->UpdateFedexFields();
                     $this->objFedexShipment->Save(true);
                 }
             }
             // If courier is FedEx, initiate communication with FedEx
             if (!$blnError && $this->objShipment->CourierId == 1) {
                 if (!$this->FedEx()) {
                     $blnError = true;
                     $objDatabase->TransactionRollback();
                     return;
                 }
             }
             if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) {
                 $objTransaction = '';
                 $objReceipt = '';
                 $objNewAssetTransactionArray = array();
                 foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                     $objNewAssetTransactionArray[$objAssetTransaction->Asset->AssetCode] = $objAssetTransaction;
                 }
                 // Assign a destinationLocation to the AssetTransaction, and change the Location of the asset
                 foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                     if ($objAssetTransaction->Asset instanceof Asset) {
                         // LocationId #2 == Shipped
                         $DestinationLocationId = 2;
                         if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->Asset->LinkedFlag) {
                             $objAssetTransaction = $objNewAssetTransactionArray[$objAssetTransaction->Asset->AssetCode];
                         }
                         $objAssetTransaction->Asset->LocationId = $DestinationLocationId;
                         $objAssetTransaction->Asset->Save();
                         if (!$this->blnEditMode) {
                             // Assign the TransactionId
                             $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId;
                         }
                         $objAssetTransaction->DestinationLocationId = $DestinationLocationId;
                         // No any actions with linked items (LinkedFlag = 1) which have been scheduled for receipt
                         if ($objAssetTransaction->ScheduleReceiptFlag && !$objAssetTransaction->Asset->LinkedFlag) {
                             if ($objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset && $objAssetTransaction->NewAsset->AssetId == null) {
                                 // We have to create the new asset before we can
                                 $objReceiptAsset = new Asset();
                                 $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId;
                                 $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId;
                                 if ($objAssetTransaction->NewAsset->AssetCode == '') {
                                     $objReceiptAsset->AssetCode = Asset::GenerateAssetCode();
                                 } else {
                                     $objReceiptAsset->AssetCode = $objAssetTransaction->NewAsset->AssetCode;
                                 }
                                 $objReceiptAsset->Save();
                                 // Assign any default custom field values
                                 CustomField::AssignNewEntityDefaultValues(1, $objReceiptAsset->AssetId);
                                 // Associate the new Asset with the AssetTransaction
                                 $objAssetTransaction->NewAsset = $objReceiptAsset;
                             }
                             // If it doesn't exist, create a new transaction object and receipt object
                             if (!$objTransaction instanceof Transaction && !$objReceipt instanceof Receipt) {
                                 $objTransaction = new Transaction();
                                 // Transaction is asset only
                                 $objTransaction->EntityQtypeId = 1;
                                 // Transaction is a receipt
                                 $objTransaction->TransactionTypeId = 7;
                                 // Set a note showing how this receipt was created
                                 if (!$objAssetTransaction->NewAssetId) {
                                     $strTransactionType = 'return';
                                 } else {
                                     $strTransactionType = 'exchange';
                                 }
                                 $objTransaction->Note = sprintf('This %s receipt was automatically created when creating Shipment Number %s.', $strTransactionType, $this->objShipment->ShipmentNumber);
                                 // Save the transaction
                                 $objTransaction->Save();
                                 // Create a new receipt
                                 $objReceipt = new Receipt();
                                 $objReceipt->TransactionId = $objTransaction->TransactionId;
                                 // The receipt will be coming from the company that was shipped to
                                 $objReceipt->FromCompanyId = $this->objShipment->ToCompanyId;
                                 $objReceipt->FromContactId = $this->objShipment->ToContactId;
                                 $objReceipt->ToContactId = $this->objShipment->FromContactId;
                                 $objReceipt->ToAddressId = $this->objShipment->FromAddressId;
                                 $objReceipt->ReceivedFlag = 0;
                                 $objReceipt->ReceiptNumber = Receipt::LoadNewReceiptNumber();
                                 if ($objAssetTransaction->ScheduleReceiptDueDate) {
                                     $objReceipt->DueDate = $objAssetTransaction->ScheduleReceiptDueDate;
                                 }
                                 $objReceipt->Save();
                             }
                             $objReceiptAssetTransaction = new AssetTransaction();
                             // If this is a return
                             if (!$objAssetTransaction->NewAssetId) {
                                 $objReceiptAssetTransaction->AssetId = $objAssetTransaction->AssetId;
                             } else {
                                 // Both the shipmentAssetTranscation (objAssetTransaction and the objReceiptAssetTransaction were involved in creating a new asset
                                 // Asset Transactions where NewAssetFlag = true but AssetId is NULL are receipt asset transactions for exchanges.
                                 $objReceiptAssetTransaction->AssetId = $objAssetTransaction->NewAssetId;
                                 $objReceiptAssetTransaction->NewAssetFlag = true;
                                 $objAssetTransaction->NewAssetFlag = true;
                                 $objAssetTransaction->Save();
                             }
                             $objReceiptAssetTransaction->TransactionId = $objTransaction->TransactionId;
                             $objReceiptAssetTransaction->SourceLocationId = $objAssetTransaction->DestinationLocationId;
                             // This is not right. NewAssetFlag should be set only if a new asset was created when creating this AssetTransaction
                             // It should not be true on the new AssetTransaction, but only on the AssetTransaction that caused the new asset to be created.
                             // $objReceiptAssetTransaction->NewAssetFlag = true;
                             $objReceiptAssetTransaction->Save();
                             // Load all child assets
                             if ($objLinkedAssetCodeArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId)) {
                                 foreach ($objLinkedAssetCodeArray as $objLinkedAssetCode) {
                                     $objLinkedAssetTransaction = $objNewAssetTransactionArray[$objLinkedAssetCode->AssetCode];
                                     $objLinkedReceiptAssetTransaction = new AssetTransaction();
                                     // If this is a return
                                     if (!$objAssetTransaction->NewAssetId) {
                                         $objLinkedReceiptAssetTransaction->AssetId = $objLinkedAssetTransaction->AssetId;
                                         $objLinkedReceiptAssetTransaction->TransactionId = $objTransaction->TransactionId;
                                         $objLinkedReceiptAssetTransaction->SourceLocationId = $objAssetTransaction->DestinationLocationId;
                                         $objLinkedReceiptAssetTransaction->Save();
                                     } else {
                                         // Both the shipmentAssetTranscation (objAssetTransaction and the objReceiptAssetTransaction were involved in creating a new asset
                                         // Asset Transactions where NewAssetFlag = true but AssetId is NULL are receipt asset transactions for exchanges.
                                         $objLinkedReceiptAssetTransaction->AssetId = $objAssetTransaction->NewAssetId;
                                     }
                                     $objNewAssetTransactionArray[$objLinkedAssetCode->AssetCode] = $objLinkedAssetTransaction;
                                 }
                             }
                         }
                         $objAssetTransaction->Save();
                         if ($objAssetTransaction->ScheduleReceiptFlag) {
                             // Set the Receipt Asset Transaction as child of the Shipment Asset Transaction
                             $objAssetTransaction->AssociateChildAssetTransaction($objReceiptAssetTransaction);
                         }
                         $objReceipt = null;
                         $objTransaction = null;
                     }
                 }
             }
             if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) {
                 // Assign different source and destinations depending on transaction type
                 foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
                     // LocationId #2 == Shipped
                     $DestinationLocationId = 2;
                     if (!$this->blnEditMode) {
                         $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId;
                     }
                     // Remove the inventory quantity from the source
                     $objInventoryTransaction->InventoryLocation->Quantity = $objInventoryTransaction->InventoryLocation->Quantity - $objInventoryTransaction->Quantity;
                     $objInventoryTransaction->InventoryLocation->Save();
                     // Finish the InventoryTransaction and save it
                     $objInventoryTransaction->DestinationLocationId = $DestinationLocationId;
                     $objInventoryTransaction->Save();
                 }
             }
             if ($this->blnEditMode) {
                 $this->UpdateShipmentFields();
                 if ($this->objShipment->CourierId === 1) {
                     $this->UpdateFedexFields();
                 }
             } elseif ($this->objShipment->CourierId === 1) {
                 // Update $this->objShipment with FedEx tracking number
                 $this->objShipment->TrackingNumber = $this->txtTrackingNumber->Text;
             }
             $this->objShipment->ShippedFlag = true;
             // $this->objShipment->Save(false, true);
             $this->objShipment->Save();
             $objDatabase->TransactionCommit();
             QApplication::Redirect(sprintf('../shipping/shipment_edit.php?intShipmentId=%s', $this->objShipment->ShipmentId));
         } catch (QExtendedOptimisticLockingException $objExc) {
             $objDatabase->TransactionRollback();
             if ($objExc->Class == 'Shipment') {
                 $this->btnCancelShipment->Warning = sprintf('This shipment has been modified by another user. You must <a href="shipment_edit.php?intShipmentId=%s">Refresh</a> to complete this shipment.', $this->objShipment->ShipmentId);
             } else {
                 throw new QOptimisticLockingException($objExc->Class);
             }
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Loads array of Child Linked Asset Objects
  *
  * @param int $intParentAssetId AssetId of the parent asset to load linked assets
  * @return mixed
  */
 public function LoadChildLinkedArrayByParentAssetId($intParentAssetId)
 {
     $objLinkedAssetArray = array();
     $objChildAssetArray = Asset::LoadArrayByParentAssetIdLinkedFlag($intParentAssetId, 1);
     if ($objChildAssetArray && count($objChildAssetArray)) {
         foreach ($objChildAssetArray as $objLinkedAsset) {
             $objLinkedAssetArray[] = $objLinkedAsset;
             $objNewLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objLinkedAsset->AssetId);
             if ($objNewLinkedAssetArray) {
                 foreach ($objNewLinkedAssetArray as $objLinkedAsset2) {
                     $objLinkedAssetArray[] = $objLinkedAsset2;
                 }
             }
         }
         return $objLinkedAssetArray;
     } else {
         return false;
     }
 }