protected function btnSave_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->btnCancel->Warning = 'There are no assets or inventory in this shipment.'; } if (QApplication::$TracmorSettings->CustomShipmentNumbers) { if ($objShipment = Shipment::LoadByShipmentNumber($this->txtShipmentNumber->Text)) { if ($objShipment->ShipmentId != $this->objShipment->ShipmentId) { $blnError = true; $this->txtShipmentNumber->Warning = 'That is a duplicate shipment number.'; } } } if (!$blnError) { if (!$this->blnEditMode) { 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(); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->TransactionTypeId = 6; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) { // Assign different source and destinations depending on transaction type foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->Asset instanceof Asset) { // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Assign the TransactionId $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Create the new asset if it was scheduled for receipt if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; //if ($objReceiptAsset->AssetCode == '') { 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; } // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; $objAssetTransaction->Save(); /*$objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId); if ($objLinkedAssetArray) { foreach ($objLinkedAssetArray as $objLinkedAsset) { $objLinkedAssetTransaction = new AssetTransaction(); $objLinkedAssetTransaction->AssetId = $objLinkedAsset->AssetId; $objLinkedAssetTransaction->SourceLocationId = $objLinkedAsset->LocationId; $objLinkedAssetTransaction->TransactionId = $objAssetTransaction->TransactionId; $objLinkedAssetTransaction->Save(); } }*/ } } } if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) { // Assign different source and destinations depending on transaction type foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // Assign the TransactionId $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; $objInventoryTransaction->Save(); } } $this->UpdateShipmentFields(); $this->objShipment->ShippedFlag = false; $this->objShipment->Save(); 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); } $objDatabase->TransactionCommit(); QApplication::Redirect('shipment_list.php'); } catch (QExtendedOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); if ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } if ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } elseif ($this->blnEditMode) { 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->objTransaction = Transaction::Load($this->objShipment->TransactionId); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Remove AssetTransactions that were removed when editing if ($this->arrAssetTransactionToDelete) { foreach ($this->arrAssetTransactionToDelete as $intAssetTransactionId) { $objAssetTransactionToDelete = AssetTransaction::Load($intAssetTransactionId); // Make sure that it wasn't added and then removed if ($objAssetTransactionToDelete) { // Change back location $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId; $objAssetTransactionToDelete->Asset->Save(); // Delete the asset that was created for a new receipt if ($objAssetTransactionToDelete->NewAsset && $objAssetTransactionToDelete->NewAsset instanceof Asset && $objAssetTransactionToDelete->ScheduleReceiptFlag) { $objAssetTransactionToDelete->NewAsset->Delete(); } // Delete the asset transaction $objAssetTransactionToDelete->Delete(); unset($objAssetTransactionToDelete); } } } // Save new AssetTransactions if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { // If the AssetTransaction has not been saved if (!$objAssetTransaction->AssetTransactionId) { $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Create the new asset if it was scheduled for receipt // $DestinationLocationId = 2; // Shipped // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; // $objAssetTransaction->Asset->LocationId = $DestinationLocationId; // $objAssetTransaction->Asset->Save(); } if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset && !$objAssetTransaction->NewAssetId) { $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; } $objAssetTransaction->Save(); } } // Remove InventoryTransactions if ($this->arrInventoryTransactionToDelete) { foreach ($this->arrInventoryTransactionToDelete as $intInventoryTransactionId) { $objInventoryTransactionToDelete = InventoryTransaction::Load($intInventoryTransactionId); // Make sure that it wasn't added then removed if ($objInventoryTransactionToDelete) { // Change back the quantity //$objInventoryTransactionToDelete->InventoryLocation->Quantity += $objInventoryTransactionToDelete->Quantity; //$objInventoryTransactionToDelete->InventoryLocation->Save(); // Delete the InventoryTransaction $objInventoryTransactionToDelete->Delete(); unset($objInventoryTransactionToDelete); } } } // Save InventoryTransactions if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->InventoryTransactionId) { // Reload the InventoryLocation. If it was deleted and added in the same save click, then it will throw an Optimistic Locking Exception $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId); $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // $DestinationLocationId = 2; // Shipped // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; // $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity; // $objInventoryTransaction->InventoryLocation->Save(); $objInventoryTransaction->Save(); } } } $this->UpdateShipmentFields(); // $this->objShipment->Save(false, true); $this->objShipment->Save(); 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); } $objDatabase->TransactionCommit(); //$this->UpdateShipmentLabels(); //$this->SetupShipment(); //$this->DisplayLabels(); //$this->txtTrackingNumber->Enabled = true; QApplication::Redirect('shipment_edit.php?intShipmentId=' . $this->objShipment->ShipmentId); } catch (QExtendedOptimisticLockingException $objExc) { $objDatabase->TransactionRollback(); if ($objExc->Class == 'Shipment') { $this->btnCancel->Warning = sprintf('This shipment has been modified by another user. You must <a href="shipment_edit.php?intShipmentId=%s">Refresh</a> to edit this shipment.', $this->objShipment->ShipmentId); } elseif ($objExc->Class == 'Asset') { //$this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } elseif ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } } }
protected function btnSave_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->btnCancel->Warning = 'There are no assets or inventory in this shipment.'; } if (QApplication::$TracmorSettings->CustomShipmentNumbers) { if ($objShipment = Shipment::LoadByShipmentNumber($this->txtShipmentNumber->Text)) { if ($objShipment->ShipmentId != $this->objShipment->ShipmentId) { $blnError = true; $this->txtShipmentNumber->Warning = 'That is a duplicate shipment number.'; } } } if ($this->lstFxServiceType->SelectedValue) { $objtoFxAddress = Address::Load($this->lstToAddress->SelectedValue); if (!$objtoFxAddress || !$objtoFxAddress->PostalCode || !$objtoFxAddress->CountryId || !$objtoFxAddress->Address1) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid To Address."; } $objfromFxAddress = Address::Load($this->lstFromAddress->SelectedValue); if (!$objfromFxAddress || !$objfromFxAddress->PostalCode || !$objfromFxAddress->Address1 || !$objfromFxAddress->CountryId) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Address."; } $objfromFxContact = Contact::Load($this->lstFromContact->SelectedValue); if (!$objfromFxContact) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Contact."; } $objfromFxCompany = Company::Load($this->lstFromCompany->SelectedValue); if (!$objfromFxCompany) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid From Company."; } elseif (!$objfromFxCompany->Telephone) { $blnError = true; $this->lstFxServiceType->Warning = "The Shipping Company must have a telephone number."; } $objShippingAccount = ShippingAccount::Load($this->lstShippingAccount->SelectedValue); if (!$objShippingAccount) { $blnError = true; $this->lstFxServiceType->Warning = "Not a valid Shipping Account."; } /* $fed = new FedExDC($objShippingAccount->Value); $aRet = $fed->subscribe( array( 1 => $this->lblShipmentNumber->Text, // Don't really need this but can be used for ref 4003 => $objfromFxContact->__toString(), 4008 => $objfromFxAddress->Address1, 4009 => $objfromFxAddress->Address2, 4011 => $objfromFxAddress->City, 4012 => $objfromFxAddress->__toStringStateProvinceAbbreviation(), 4013 => $objfromFxAddress->PostalCode, 4014 => $objfromFxAddress->__toStringCountryAbbreviation(), 4015 => $this->FxStrip($objfromFxCompany->Telephone), ) ); if ($error = $fed->getError()) { $blnError = true; $this->lstFxServiceType->Warning = $error; } elseif (!$aRet[498]) { $blnError = true; $this->lstFxServiceType->Warning = "Fedex response is improperly formed."; } else { $this->objShipment->FedexMeterNumber = $aRet[498]; }*/ } if (!$blnError) { if (!$this->blnEditMode) { 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(); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->TransactionTypeId = 6; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Asset) { // Assign different source and destinations depending on transaction type foreach ($this->objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->Asset instanceof Asset) { // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Assign the TransactionId $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Create the new asset if it was scheduled for receipt if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset) { $objReceiptAsset = new Asset(); $objReceiptAsset->AssetModelId = $objAssetTransaction->NewAsset->AssetModelId; $objReceiptAsset->LocationId = $objAssetTransaction->NewAsset->LocationId; //if ($objReceiptAsset->AssetCode == '') { 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; } // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; $objAssetTransaction->Save(); /*$objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetId($objAssetTransaction->Asset->AssetId); if ($objLinkedAssetArray) { foreach ($objLinkedAssetArray as $objLinkedAsset) { $objLinkedAssetTransaction = new AssetTransaction(); $objLinkedAssetTransaction->AssetId = $objLinkedAsset->AssetId; $objLinkedAssetTransaction->SourceLocationId = $objLinkedAsset->LocationId; $objLinkedAssetTransaction->TransactionId = $objAssetTransaction->TransactionId; $objLinkedAssetTransaction->Save(); } }*/ } } } if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) { // Assign different source and destinations depending on transaction type foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // Assign the TransactionId $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; $objInventoryTransaction->Save(); } } $this->UpdateShipmentFields(); $this->objShipment->ShippedFlag = false; $this->objShipment->Save(); 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) { $this->objFedexShipment = new FedexShipment(); $this->objFedexShipment->Shipment = $this->objShipment; $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } $objDatabase->TransactionCommit(); QApplication::Redirect('shipment_list.php'); } catch (QExtendedOptimisticLockingException $objExc) { // Rollback the database $objDatabase->TransactionRollback(); if ($objExc->Class == 'Asset') { // $this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } if ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } elseif ($this->blnEditMode) { 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->objTransaction = Transaction::Load($this->objShipment->TransactionId); $this->objTransaction->EntityQtypeId = $intEntityQtypeId; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->Save(); // Remove AssetTransactions that were removed when editing if ($this->arrAssetTransactionToDelete) { foreach ($this->arrAssetTransactionToDelete as $intAssetTransactionId) { $objAssetTransactionToDelete = AssetTransaction::Load($intAssetTransactionId); // Make sure that it wasn't added and then removed if ($objAssetTransactionToDelete) { // Change back location $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId; $objAssetTransactionToDelete->Asset->Save(); // Delete the asset that was created for a new receipt if ($objAssetTransactionToDelete->NewAsset && $objAssetTransactionToDelete->NewAsset instanceof Asset && $objAssetTransactionToDelete->ScheduleReceiptFlag) { $objAssetTransactionToDelete->NewAsset->Delete(); } // Delete the asset transaction $objAssetTransactionToDelete->Delete(); unset($objAssetTransactionToDelete); } } } // Save new AssetTransactions if ($this->objAssetTransactionArray) { foreach ($this->objAssetTransactionArray as $objAssetTransaction) { // If the AssetTransaction has not been saved if (!$objAssetTransaction->AssetTransactionId) { $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate $objAssetTransaction->Asset->Save(); // Create the new asset if it was scheduled for receipt // $DestinationLocationId = 2; // Shipped // $objAssetTransaction->DestinationLocationId = $DestinationLocationId; // $objAssetTransaction->Asset->LocationId = $DestinationLocationId; // $objAssetTransaction->Asset->Save(); } if ($objAssetTransaction->ScheduleReceiptFlag && $objAssetTransaction->NewAsset && $objAssetTransaction->NewAsset instanceof Asset && !$objAssetTransaction->NewAssetId) { $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; } $objAssetTransaction->Save(); } } // Remove InventoryTransactions if ($this->arrInventoryTransactionToDelete) { foreach ($this->arrInventoryTransactionToDelete as $intInventoryTransactionId) { $objInventoryTransactionToDelete = InventoryTransaction::Load($intInventoryTransactionId); // Make sure that it wasn't added then removed if ($objInventoryTransactionToDelete) { // Change back the quantity $objInventoryTransactionToDelete->InventoryLocation->Quantity += $objInventoryTransactionToDelete->Quantity; $objInventoryTransactionToDelete->InventoryLocation->Save(); // Delete the InventoryTransaction $objInventoryTransactionToDelete->Delete(); unset($objInventoryTransactionToDelete); } } } // Save InventoryTransactions if ($this->objInventoryTransactionArray) { foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) { if (!$objInventoryTransaction->InventoryTransactionId) { // Reload the InventoryLocation. If it was deleted and added in the same save click, then it will throw an Optimistic Locking Exception $objInventoryTransaction->InventoryLocation = InventoryLocation::Load($objInventoryTransaction->InventoryLocationId); $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId; // Save the inventory location just to update the modified_date field so it can triggern an Optimistic Locking Exception when appropriate $objInventoryTransaction->InventoryLocation->Save(); // $DestinationLocationId = 2; // Shipped // $objInventoryTransaction->DestinationLocationId = $DestinationLocationId; // $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity; // $objInventoryTransaction->InventoryLocation->Save(); $objInventoryTransaction->Save(); } } } $this->UpdateShipmentFields(); // $this->objShipment->Save(false, true); $this->objShipment->Save(); 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, save the fedexShipment if ($this->lstCourier->SelectedValue === 1) { if ($this->objFedexShipment) { // FedexShipment already exists, so update it $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } else { // FedexShipment doesn't exist yet, so create it $this->objFedexShipment = new FedexShipment(); $this->objFedexShipment->Shipment = $this->objShipment; $this->UpdateFedexFields(); $this->objFedexShipment->Save(); } } else { if ($this->objFedexShipment) { // FedexShipment exists - delete it because the selected courier is no longer FedEx $this->objFedexShipment->Delete(); $this->objFedexShipment = null; } } $objDatabase->TransactionCommit(); $this->UpdateShipmentLabels(); $this->SetupShipment(); $this->DisplayLabels(); if ($this->objShipment->CourierId == 1) { $this->txtTrackingNumber->Enabled = false; $this->lstPackageType->Enabled = true; } else { $this->txtTrackingNumber->Enabled = true; $this->lstPackageType->Enabled = false; } // Reload lstPackageType $this->lstPackageType->RemoveAllItems(); $this->LoadPackageTypes(); } catch (QExtendedOptimisticLockingException $objExc) { $objDatabase->TransactionRollback(); if ($objExc->Class == 'Shipment') { $this->btnCancel->Warning = sprintf('This shipment has been modified by another user. You must <a href="shipment_edit.php?intShipmentId=%s">Refresh</a> to edit this shipment.', $this->objShipment->ShipmentId); } elseif ($objExc->Class == 'Asset') { //$this->btnRemoveAssetTransaction_Click($this->FormId, 'btnRemoveAsset' . $objExc->EntityId, $objExc->EntityId); $this->btnRemoveAssetTransaction_Click($this->FormId, null, $objExc->EntityId); $objAsset = Asset::Load($objExc->EntityId); if ($objAsset) { $this->btnCancel->Warning = sprintf('The Asset %s has been modified by another user and removed from this shipment. You may add the asset again or save the transaction without it.', $objAsset->AssetCode); } else { $this->btnCancel->Warning = 'An Asset has been deleted by another user and removed from this shipment.'; } } elseif ($objExc->Class == 'InventoryLocation') { $this->btnRemoveInventory_Click($this->FormId, 'btnRemoveInventory' . $objExc->EntityId, $objExc->EntityId); $objInventoryLocation = InventoryLocation::Load($objExc->EntityId); if ($objInventoryLocation) { $this->btnCancel->Warning = sprintf('The Inventory %s has been modified by another user and removed from this shipment. You may add the inventory again or save the shipment without it.', $objInventoryLocation->InventoryModel->InventoryModelCode); } else { $this->btnCancel->Warning = 'Inventory has been deleted by another user and removed from this shipment.'; } } } } } }