protected function SetupInventoryTransaction()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intInventoryTransactionId = QApplication::QueryString('intInventoryTransactionId');
     if ($intInventoryTransactionId) {
         $this->objInventoryTransaction = InventoryTransaction::Load($intInventoryTransactionId);
         if (!$this->objInventoryTransaction) {
             throw new Exception('Could not find a InventoryTransaction object with PK arguments: ' . $intInventoryTransactionId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objInventoryTransaction = new InventoryTransaction();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
Beispiel #2
0
 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.';
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
 protected function dtgShipmentReceipt_Bind()
 {
     // Get Total Count for Pagination
     $objClauses = array();
     $this->ctlInventoryEdit->dtgShipmentReceipt->TotalItemCount = InventoryTransaction::CountShipmentReceiptByInventoryModelId($this->ctlInventoryEdit->objInventoryModel->InventoryModelId);
     if ($this->ctlInventoryEdit->dtgShipmentReceipt->TotalItemCount === 0) {
         $this->ctlInventoryEdit->lblShipmentReceipt->Display = false;
         $this->ctlInventoryEdit->dtgShipmentReceipt->ShowHeader = false;
     } else {
         $objClauses = array();
         if ($objClause = QQ::OrderBy(QQN::InventoryTransaction()->Transaction->CreationDate, false)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = $this->ctlInventoryEdit->dtgShipmentReceipt->LimitClause) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::InventoryTransaction()->Transaction->Shipment)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::InventoryTransaction()->Transaction->Receipt)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::InventoryTransaction()->SourceLocation)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::InventoryTransaction()->DestinationLocation)) {
             array_push($objClauses, $objClause);
         }
         $objCondition = QQ::AndCondition(QQ::Equal(QQN::InventoryTransaction()->InventoryLocation->InventoryModelId, $this->ctlInventoryEdit->objInventoryModel->InventoryModelId), QQ::OrCondition(QQ::Equal(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 6), QQ::Equal(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 7)));
         $this->ctlInventoryEdit->dtgShipmentReceipt->DataSource = InventoryTransaction::QueryArray($objCondition, $objClauses);
     }
 }
    /**
     * Deletes all associated InventoryTransactionsAsDestination
     * @return void
     */
    public function DeleteAllInventoryTransactionsAsDestination()
    {
        if (is_null($this->intLocationId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateInventoryTransactionAsDestination on this unsaved Location.');
        }
        // Get the Database Object for this Class
        $objDatabase = Location::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (InventoryTransaction::LoadArrayByDestinationLocationId($this->intLocationId) as $objInventoryTransaction) {
                $objInventoryTransaction->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`inventory_transaction`
				WHERE
					`destination_location_id` = ' . $objDatabase->SqlVariable($this->intLocationId) . '
			');
    }
Beispiel #5
0
 /**
  * Load an Reciept Object
  * The method should check for assets or inventory in reciept that is still 'To Be Received' (TBR)
  *
  * @param int $intReceiptId
  * @return Receipt
  */
 public function ReceiptComplete($intReceiptId)
 {
     $objClauses = null;
     $blnAllAssetsReceived = true;
     $blnAllInventoryReceived = true;
     $objReceipt = Receipt::Load($intReceiptId);
     if ($objReceipt) {
         if (!$objReceipt->ReceivedFlag) {
             $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($objReceipt->TransactionId, $objClauses);
             $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($objReceipt->TransactionId, $objClauses);
             foreach ($objAssetTransactionArray as &$objAssetTransaction) {
                 if (!$objAssetTransaction->DestinationLocationId) {
                     $blnAllAssetsReceived = false;
                 }
             }
             if ($blnAllAssetsReceived) {
                 if ($objInventoryTransactionArray) {
                     foreach ($objInventoryTransactionArray as $objInventoryTransaction) {
                         if (!$objInventoryTransaction->DestinationLocationId) {
                             $blnAllInventoryReceived = false;
                         }
                     }
                 }
                 // Set the entire receipt as received if assets and inventory have all been received
                 if ($blnAllInventoryReceived) {
                     $objReceipt->ReceivedFlag = true;
                     $objReceipt->ReceiptDate = new QDateTime(QDateTime::Now);
                     $objReceipt->Save();
                 }
             }
         }
         return $objReceipt;
     } else {
         return false;
     }
 }
 /**
  * Counts all associated InventoryTransactionsAsCreatedBy
  * @return int
  */
 public function CountInventoryTransactionsAsCreatedBy()
 {
     if (is_null($this->intUserAccountId)) {
         return 0;
     }
     return InventoryTransaction::CountByCreatedBy($this->intUserAccountId);
 }
 /**
  * Returns an Account object the created the most recent transaction for this inventory model
  *
  * @return Object Account
  */
 public function GetLastTransactionUser()
 {
     $objExpansionMap[InventoryTransaction::ExpandTransaction][Transaction::ExpandCreatedByObject] = true;
     $strOrderBy = 'inventory_transaction__transaction_id__creation_date DESC';
     $strLimit = '0,1';
     $InventoryTransactionArray = InventoryTransaction::LoadArrayByInventoryModelId($this->InventoryModelId, $strOrderBy, $strLimit, $objExpansionMap);
     $Account = $InventoryTransactionArray[0]->Transaction->CreatedByObject;
     return $Account;
 }
 public function dtgInventoryTransaction_Bind()
 {
     // Get Total Count b/c of Pagination
     $this->dtgInventoryTransaction->TotalItemCount = InventoryTransaction::CountAll();
     $objClauses = array();
     if ($objClause = $this->dtgInventoryTransaction->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     if ($objClause = $this->dtgInventoryTransaction->LimitClause) {
         array_push($objClauses, $objClause);
     }
     $this->dtgInventoryTransaction->DataSource = InventoryTransaction::LoadAll($objClauses);
 }
 /**
  * Main utility method to aid with data binding.  It is used by the default BindAllRows() databinder but
  * could and should be used by any custom databind methods that would be used for instances of this
  * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. 
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  *
  * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself
  * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query		 
  * @return void
  */
 public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null)
 {
     // Setup input parameters to default values if none passed in
     if (!$objCondition) {
         $objCondition = QQ::All();
     }
     $objClauses = $objOptionalClauses ? $objOptionalClauses : array();
     // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = InventoryTransaction::QueryCount($objCondition, $objClauses);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from InventoryTransaction, given the clauses above
     $this->DataSource = InventoryTransaction::QueryArray($objCondition, $objClauses);
 }
 /**
  * Counts all associated InventoryTransactions
  * @return int
  */
 public function CountInventoryTransactions()
 {
     if (is_null($this->intTransactionId)) {
         return 0;
     }
     return InventoryTransaction::CountByTransactionId($this->intTransactionId);
 }
 /**
  * Returns a bool that determines whether or not this transaction has any AssetTransactions or InventoryTransactions associated with it
  *
  * @return bool
  */
 public function IsEmpty()
 {
     $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($this->TransactionId);
     if (empty($objAssetTransactionArray)) {
         $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($this->TransactionId);
         if (empty($objInventoryTransactionArray)) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #12
0
 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.';
                     }
                 }
             }
         }
     }
 }
Beispiel #13
0
 /**
  * Counts all associated InventoryTransactionsAsDestination
  * @return int
  */
 public function CountInventoryTransactionsAsDestination()
 {
     if (is_null($this->intLocationId)) {
         return 0;
     }
     return InventoryTransaction::CountByDestinationLocationId($this->intLocationId);
 }
    /**
     * Deletes all associated InventoryTransactionsAsCreatedBy
     * @return void
     */
    public function DeleteAllInventoryTransactionsAsCreatedBy()
    {
        if (is_null($this->intUserAccountId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateInventoryTransactionAsCreatedBy on this unsaved UserAccount.');
        }
        // Get the Database Object for this Class
        $objDatabase = UserAccount::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (InventoryTransaction::LoadArrayByCreatedBy($this->intUserAccountId) as $objInventoryTransaction) {
                $objInventoryTransaction->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`inventory_transaction`
				WHERE
					`created_by` = ' . $objDatabase->SqlVariable($this->intUserAccountId) . '
			');
    }
 /**
  * Count InventoryTransactions
  * by InventoryModelId Index(es), but only those transactions that are Shipments or Receipts
  * @param integer $intAssetId
  * @param boolean $blnInclude - include only shipments and receipts or all other transactions
  * @return int
  */
 public static function CountShipmentReceiptByInventoryModelId($intInventoryModelId, $blnInclude = true)
 {
     // Call AssetTransaction::QueryCount to perform the CountByAssetId query
     if ($blnInclude) {
         $arrToReturn = InventoryTransaction::QueryCount(QQ::AndCondition(QQ::Equal(QQN::InventoryTransaction()->InventoryLocation->InventoryModelId, $intInventoryModelId), QQ::OrCondition(QQ::Equal(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 6), QQ::Equal(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 7))));
     } else {
         $arrToReturn = InventoryTransaction::QueryCount(QQ::AndCondition(QQ::Equal(QQN::InventoryTransaction()->InventoryLocation->InventoryModelId, $intInventoryModelId), QQ::NotEqual(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 6), QQ::NotEqual(QQN::InventoryTransaction()->Transaction->TransactionTypeId, 7)));
     }
     return $arrToReturn;
 }
Beispiel #16
0
 public function receiptDelete(Receipt $receipt)
 {
     $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($receipt->TransactionId);
     $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($receipt->TransactionId);
     // Take out the inventory from the TBR InventoryLocation
     if ($objInventoryTransactionArray) {
         foreach ($objInventoryTransactionArray as $objInventoryTransaction) {
             $objInventoryTransaction->InventoryLocation->Quantity -= $objInventoryTransaction->Quantity;
             $objInventoryTransaction->InventoryLocation->Save();
         }
     }
     // Delete any assets that were created while scheduling this receipt
     if ($objAssetTransactionArray) {
         foreach ($objAssetTransactionArray as $objAssetTransaction) {
             if ($objAssetTransaction->NewAssetFlag) {
                 $objAssetTransaction->Asset->Delete();
             }
         }
     }
     // Load the Transaction
     $objTransaction = Transaction::Load($receipt->TransactionId);
     // Delete the Transaction Object and let it MySQL CASCADE down to asset_transaction, inventory_transaction, and receipt
     $objTransaction->Delete();
 }
 protected function dtgInventoryTransaction_Bind()
 {
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgInventoryTransaction->TotalItemCount = InventoryTransaction::CountAll();
     // Setup the $objClauses Array
     $objClauses = array();
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->dtgInventoryTransaction->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgInventoryTransaction->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all InventoryTransaction objects, given the clauses above
     $this->dtgInventoryTransaction->DataSource = InventoryTransaction::LoadAll($objClauses);
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, InventoryTransaction::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
         $objTransaction = new Transaction();
         $objTransaction->EntityQtypeId = EntityQtype::Inventory;
         $objTransaction->TransactionTypeId = 5;
         // Take Out
         $objTransaction->Save();
         // Assign different source and destinations depending on transaction type
         foreach ($objInventoryLocationArray as $objInventoryLocation) {
             $SourceLocationId = $objInventoryLocation->LocationId;
             // LocationId = 3 - 'Taken Out'
             $DestinationLocationId = 3;
             // Remove the inventory quantity from the source for moves and take outs
             //$objInventoryLocation->Quantity = $objInventoryLocation->Quantity - $objInventoryLocation->intTransactionQuantity;
             $objInventoryLocation->Quantity = $objInventoryLocation->GetVirtualAttribute('actual_quantity') - $objInventoryLocation->intTransactionQuantity;
             $objInventoryLocation->Save();
             // Create the new InventoryTransaction object and save it
             $objInventoryTransaction = new InventoryTransaction();
             $objInventoryTransaction->InventoryLocationId = $objInventoryLocation->InventoryLocationId;
             $objInventoryTransaction->TransactionId = $objTransaction->TransactionId;
             $objInventoryTransaction->Quantity = $objInventoryLocation->intTransactionQuantity;
             $objInventoryTransaction->SourceLocationId = $SourceLocationId;
             $objInventoryTransaction->DestinationLocationId = $DestinationLocationId;
             $objInventoryTransaction->Save();
         }
         $strWarning .= "Your transaction has successfully completed<br /><a href='index.php'>Main Menu</a> | <a href='inventory_menu.php'>Inventory Menu</a><br />";
         //Remove that flag when transaction is compelete or exists some errors
         unset($_SESSION['intUserAccountId']);
         $blnTransactionComplete = true;
         $arrCheckedInventoryCodeLocationQuantity = "";
     }
 }
 if ($blnError) {
 /**
  * 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 InventoryTransactionMetaControl
  * @param integer $intInventoryTransactionId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing InventoryTransaction object creation - defaults to CreateOrEdit
  * @return InventoryTransactionMetaControl
  */
 public static function Create($objParentObject, $intInventoryTransactionId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intInventoryTransactionId)) {
         $objInventoryTransaction = InventoryTransaction::Load($intInventoryTransactionId);
         // InventoryTransaction was found -- return it!
         if ($objInventoryTransaction) {
             return new InventoryTransactionMetaControl($objParentObject, $objInventoryTransaction);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a InventoryTransaction object with PK arguments: ' . $intInventoryTransactionId);
             }
         }
         // 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 InventoryTransactionMetaControl($objParentObject, new InventoryTransaction());
 }
Beispiel #21
0
 public 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 nor inventory in this receipt.';
     }
     if (QApplication::$TracmorSettings->CustomReceiptNumbers) {
         if (trim($this->txtReceiptNumber->Text) == '') {
             $blnError = true;
             $this->txtReceiptNumber->Warning = 'Receipt number is a required field.';
         } else {
             if ($objReceipt = Receipt::LoadByReceiptNumber($this->txtReceiptNumber->Text)) {
                 if ($objReceipt->ReceiptId != $this->objReceipt->ReceiptId) {
                     $blnError = true;
                     $this->txtReceiptNumber->Warning = 'That is a duplicate receipt number.';
                 }
             }
         }
     }
     if (!$this->lstFromCompany->SelectedValue) {
         $blnError = true;
         $this->lstFromCompany->Warning = 'You must select a From Company';
     }
     if (!$this->lstFromContact->SelectedValue) {
         $blnError = true;
         $this->lstFromContact->Warning = 'You must select a From Contact';
     }
     if (!$this->lstToContact->SelectedValue) {
         $blnError = true;
         $this->lstToContact->Warning = 'You must select a To Contact';
     }
     if (!$this->lstToAddress->SelectedValue) {
         $blnError = true;
         $this->lstToAddress->Warning = 'You must select a To Address';
     }
     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 = 7;
                 // Receive
                 $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) {
                         // Save the asset just to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate
                         if ($objAssetTransaction->Asset instanceof Asset) {
                             // Save the asset to update the modified_date field so it can trigger an Optimistic Locking Exception when appropriate
                             // Also set the location to 5 (TBR). This is in case the current LocationId is 2 (Shipped), because they can be received.
                             $objAssetTransaction->Asset->LocationId = 5;
                             // If the AssetId==0, then it is a newly created asset that hasn't been saved to the db yet
                             // We have to create a new asset object and assign it to the AssetTransaction
                             // Just resetting the values for the existing asset object won't work for some reason (not sure why).
                             if ($objAssetTransaction->Asset->AssetId == 0) {
                                 $objNewAsset = new Asset();
                                 $objNewAsset->AssetModelId = $objAssetTransaction->Asset->AssetModelId;
                                 $objNewAsset->TempId = $objAssetTransaction->Asset->TempId;
                                 $objNewAsset->LocationId = $objAssetTransaction->Asset->LocationId;
                                 // If the asset was selected for autogeneration, it will be blank, so create the asset code here (right before save)
                                 if ($objAssetTransaction->Asset->AssetCode == '') {
                                     $objAssetTransaction->Asset->AssetCode = Asset::GenerateAssetCode();
                                 }
                                 $objNewAsset->AssetCode = $objAssetTransaction->Asset->AssetCode;
                                 // Save the new asset
                                 $objNewAsset->Save();
                                 // Assign any default custom field values
                                 CustomField::AssignNewEntityDefaultValues(1, $objNewAsset->AssetId);
                                 // Assign the new asset to the AssetTransaction
                                 $objAssetTransaction->Asset = $objNewAsset;
                                 $objAssetTransaction->NewAssetFlag = true;
                             } else {
                                 $objAssetTransaction->NewAssetFlag = false;
                                 $objAssetTransaction->Asset->Save();
                             }
                             // Create the new assettransaction object and save it
                             $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId;
                             $objAssetTransaction->Save();
                         }
                     }
                 }
                 if ($intEntityQtypeId == EntityQtype::AssetInventory || $intEntityQtypeId == EntityQtype::Inventory) {
                     // Assign different source and destinations depending on transaction type
                     foreach ($this->objInventoryTransactionArray as &$objInventoryTransaction) {
                         // Finish the InventoryTransaction and save it
                         $objInventoryTransaction->InventoryLocation->Quantity += $objInventoryTransaction->Quantity;
                         $objInventoryTransaction->InventoryLocation->Save();
                         $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId;
                         $objInventoryTransaction->Save();
                     }
                 }
                 $this->UpdateReceiptFields();
                 $this->objReceipt->ReceivedFlag = false;
                 $this->objReceipt->Save();
                 if ($this->arrCustomFields) {
                     // Save the values from all of the custom field controls to save the shipment
                     CustomField::SaveControls($this->objReceipt->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objReceipt->ReceiptId, EntityQtype::Receipt);
                 }
                 $objDatabase->TransactionCommit();
                 QApplication::Redirect('receipt_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 == 'AssetTransaction') {
                     $this->btnCancel->Warning = 'This asset transaction has been modified by another user. You may reload the receipt and try your modifications again.';
                 }
                 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 should probably be changed to $this->objReceipt->Transaction
                 $this->objTransaction = Transaction::Load($this->objReceipt->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) {
                             // If a new asset was created in this receipt, it needs to be deleted
                             if ($objAssetTransactionToDelete->NewAssetFlag) {
                                 $intAssetIdToDelete = $objAssetTransactionToDelete->Asset->AssetId;
                                 //$objAssetTransactionToDelete->Asset->Delete();
                             } else {
                                 // Change back location
                                 $objAssetTransactionToDelete->Asset->LocationId = $objAssetTransactionToDelete->SourceLocationId;
                                 $objAssetTransactionToDelete->Asset->Save();
                             }
                             // Delete the asset transaction
                             $objAssetTransactionToDelete->Delete();
                             // If a new asset,  delete it
                             if (isset($intAssetIdToDelete)) {
                                 $objAssetToDelete = Asset::LoadByAssetId($intAssetIdToDelete);
                                 $objAssetToDelete->Delete();
                             }
                             unset($objAssetTransactionToDelete);
                         }
                     }
                 }
                 // Save existing AssetTransactions
                 if ($this->objAssetTransactionArray) {
                     foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                         if (!$objAssetTransaction->AssetTransactionId) {
                             $objAssetTransaction->TransactionId = $this->objTransaction->TransactionId;
                             // This is done in case the original location is 'Shipped'(2), not 'To Be Received'(5)
                             $objAssetTransaction->SourceLocationId = $objAssetTransaction->Asset->LocationId;
                             $objAssetTransaction->Asset->LocationId = 5;
                             // To Be Received
                             // If the AssetId is 0 (it hasn't been saved to the database yet), then create a new Asset in the conventional way
                             // We have to create a new asset object and assign it to the AssetTransaction
                             // Just resetting the values for the existing asset object won't work for some reason (not sure why).
                             if ($objAssetTransaction->Asset->AssetId == 0) {
                                 $objNewAsset = new Asset();
                                 $objNewAsset->AssetModelId = $objAssetTransaction->Asset->AssetModelId;
                                 $objNewAsset->TempId = $objAssetTransaction->Asset->TempId;
                                 $objNewAsset->LocationId = $objAssetTransaction->Asset->LocationId;
                                 // If the asset was selected for autogeneration, it will be blank, so create the asset code here (right before save)
                                 if ($objAssetTransaction->Asset->AssetCode == '') {
                                     $objAssetTransaction->Asset->AssetCode = Asset::GenerateAssetCode();
                                 }
                                 $objNewAsset->AssetCode = $objAssetTransaction->Asset->AssetCode;
                                 // Save the new asset
                                 $objNewAsset->Save();
                                 // Assign any default custom field values
                                 CustomField::AssignNewEntityDefaultValues(1, $objNewAsset->AssetId);
                                 // Associate the new asset with the AssetTransaction
                                 $objAssetTransaction->Asset = $objNewAsset;
                                 $objAssetTransaction->NewAssetFlag = true;
                             } else {
                                 $objAssetTransaction->NewAssetFlag = false;
                                 $objAssetTransaction->Asset->Save();
                             }
                         }
                         // Always save the asset transaction, to generate an Optimistic Locking Exception when appropriate
                         $objAssetTransaction->Save();
                         // Reload AssetTransaction to avoid Optimistic Locking Exception if this receipt is edited and saved.
                         $objAssetTransaction = AssetTransaction::Load($objAssetTransaction->AssetTransactionId);
                     }
                 }
                 // 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->InventoryLocation->Quantity += $objInventoryTransaction->Quantity;
                             $objInventoryTransaction->TransactionId = $this->objTransaction->TransactionId;
                             $objInventoryTransaction->InventoryLocation->Save();
                             $SourceLocationId = 5;
                             // To Be Received
                             $objInventoryTransaction->SourceLocationId = $SourceLocationId;
                         }
                         // Always save the InventoryTransaction, to generate an Optimistic Locking Exception when appropriate
                         $objInventoryTransaction->Save();
                         // Reload the InventoryTransaction to get the new timestamp so that it doesn't generate an optimistic locking exception
                         $objInventoryTransaction = InventoryTransaction::Load($objInventoryTransaction->InventoryTransactionId);
                     }
                 }
                 // Check to see if all Inventory and Assets have been received (if the final entity was removed from the receipt without receiving it).
                 // Only if it hasn't already been received
                 if (!$this->objReceipt->ReceivedFlag) {
                     // Check to see if all assets have been received
                     $blnAllAssetsReceived = true;
                     if ($this->objAssetTransactionArray) {
                         foreach ($this->objAssetTransactionArray as $objAssetTransaction) {
                             if (!$objAssetTransaction->DestinationLocationId) {
                                 $blnAllAssetsReceived = false;
                             }
                         }
                     }
                     // Check to see if all inventory have been received
                     $blnAllInventoryReceived = true;
                     if ($this->objInventoryTransactionArray) {
                         foreach ($this->objInventoryTransactionArray as $objInventoryTransaction) {
                             if (!$objInventoryTransaction->DestinationLocationId) {
                                 $blnAllInventoryReceived = false;
                             }
                         }
                     }
                     // If all Inventory and Assets have been received
                     if ($blnAllAssetsReceived && $blnAllInventoryReceived) {
                         // Flip the received flag for the entire Receipt
                         $this->objReceipt->ReceivedFlag = true;
                         $this->objReceipt->ReceiptDate = new QDateTime(QDateTime::Now);
                     }
                 } else {
                     if ($this->objReceipt->ReceiptDate != $this->calDateReceived->DateTime) {
                         $this->objReceipt->ReceiptDate = $this->calDateReceived->DateTime;
                     }
                 }
                 $this->UpdateReceiptFields();
                 $this->UpdateReceiptLabels();
                 $this->objReceipt->Save();
                 if ($this->arrCustomFields) {
                     // Save the values from all of the custom field controls to save the shipment
                     CustomField::SaveControls($this->objReceipt->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objReceipt->ReceiptId, EntityQtype::Receipt);
                 }
                 // Reload to get new timestamp to avoid optimistic locking if edited/saved again without reload
                 $this->objReceipt = Receipt::Load($this->objReceipt->ReceiptId);
                 $this->DisplayLabels();
                 $objDatabase->TransactionCommit();
             } catch (QExtendedOptimisticLockingException $objExc) {
                 $objDatabase->TransactionRollback();
                 if ($objExc->Class == 'Receipt' || $objExc->Class == 'AssetTransaction' || $objExc->Class == 'InventoryTransaction') {
                     $this->btnCancel->Warning = sprintf('This receipt has been modified by another user. You must <a href="receipt_edit.php?intReceiptId=%s">Refresh</a> to edit this receipt.', $this->objReceipt->ReceiptId);
                 } 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.';
                     }
                 } else {
                     throw new QOptimisticLockingException($objExc->Class);
                 }
             }
         }
     }
 }
Beispiel #22
0
 /**
  * Returns the HTML needed for a shipment datagrid to show asset and inventory icons, with hovertips.
  *
  * @param QDatagrid Object $objControl
  * @return string
  */
 public function __toStringHoverTips($objControl)
 {
     // Create the Asset Image label, with corresponding assets hovertip
     if ($this->Transaction->EntityQtypeId == EntityQtype::AssetInventory || $this->Transaction->EntityQtypeId == EntityQtype::Asset) {
         $lblAssetImage = new QLabelExt($objControl);
         $lblAssetImage->HtmlEntities = false;
         $lblAssetImage->Text = sprintf('<img src="%s/icons/asset_datagrid.png" style="vertical-align:middle;">', __IMAGE_ASSETS__);
         // create
         $objHoverTip = new QHoverTip($lblAssetImage);
         $objHoverTip->Template = __DOCROOT__ . __SUBDIRECTORY__ . '/shipping/hovertip_assets.tpl.php';
         $lblAssetImage->HoverTip = $objHoverTip;
         // Load the AssetTransaction Array on the form so that it can be used by the hovertip panel
         $objClauses = array();
         if ($objClause = QQ::LimitInfo(11, 0)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::AssetTransaction()->Asset->AssetModel)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::AssetTransaction()->SourceLocation)) {
         }
         array_push($objClauses, $objClause);
         $objControl->Form->objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($this->TransactionId, $objClauses);
         $objClauses = null;
     }
     // Create the Inventory Image label with corresponding inventory hovertip
     if ($this->Transaction->EntityQtypeId == EntityQtype::AssetInventory || $this->Transaction->EntityQtypeId == EntityQtype::Inventory) {
         $lblInventoryImage = new QLabelExt($objControl);
         $lblInventoryImage->HtmlEntities = false;
         $lblInventoryImage->Text = sprintf('<img src="%s/icons/inventory_datagrid.png" style="vertical-align:middle;"', __IMAGE_ASSETS__);
         // Create the inventory hovertip
         $objHoverTip = new QHoverTip($lblInventoryImage);
         $objHoverTip->Template = __DOCROOT__ . __SUBDIRECTORY__ . '/shipping/hovertip_inventory.tpl.php';
         $lblInventoryImage->HoverTip = $objHoverTip;
         // Load the InventoryTransaction Array on the form so that it can be used by the hovertip panel
         $objClauses = array();
         if ($objClause = QQ::LimitInfo(11, 0)) {
             array_push($objClauses, $objClause);
         }
         if ($objClause = QQ::Expand(QQN::InventoryTransaction()->InventoryLocation->InventoryModel)) {
         }
         array_push($objClauses, $objClause);
         $objControl->Form->objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($this->TransactionId, $objClauses);
         $objClauses = null;
     }
     // Display the appropriate images
     if ($this->Transaction->EntityQtypeId == EntityQtype::AssetInventory) {
         $strToReturn = $lblAssetImage->Render(false) . '&nbsp;' . $lblInventoryImage->Render(false);
     } elseif ($this->Transaction->EntityQtypeId == EntityQtype::Asset) {
         $strToReturn = $lblAssetImage->Render(false);
     } elseif ($this->Transaction->EntityQtypeId == EntityQtype::Inventory) {
         $strToReturn = $lblInventoryImage->Render(false);
     }
     return $strToReturn;
 }