protected function SetupReceipt() { // Lookup Object PK information from Query String (if applicable) // Set mode to Edit or New depending on what's found $intReceiptId = QApplication::QueryString('intReceiptId'); if ($intReceiptId) { $this->objReceipt = Receipt::Load($intReceiptId); if (!$this->objReceipt) { throw new Exception('Could not find a Receipt object with PK arguments: ' . $intReceiptId); } $this->strTitleVerb = QApplication::Translate('Edit'); $this->blnEditMode = true; } else { $this->objReceipt = new Receipt(); $this->strTitleVerb = QApplication::Translate('Create'); $this->blnEditMode = false; } }
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); } } } } }
protected function UpdateTransactionFields() { $this->objTransaction->EntityQtypeId = $this->lstEntityQtype->SelectedValue; $this->objTransaction->TransactionTypeId = $this->lstTransactionType->SelectedValue; $this->objTransaction->Note = $this->txtNote->Text; $this->objTransaction->CreatedBy = $this->lstCreatedByObject->SelectedValue; $this->objTransaction->CreationDate = $this->calCreationDate->DateTime; $this->objTransaction->ModifiedBy = $this->lstModifiedByObject->SelectedValue; $this->objTransaction->Receipt = Receipt::Load($this->lstReceipt->SelectedValue); $this->objTransaction->Shipment = Shipment::Load($this->lstShipment->SelectedValue); }
/** * 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 ReceiptMetaControl * @param integer $intReceiptId primary key value * @param QMetaControlCreateType $intCreateType rules governing Receipt object creation - defaults to CreateOrEdit * @return ReceiptMetaControl */ public static function Create($objParentObject, $intReceiptId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intReceiptId)) { $objReceipt = Receipt::Load($intReceiptId); // Receipt was found -- return it! if ($objReceipt) { return new ReceiptMetaControl($objParentObject, $objReceipt); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a Receipt object with PK arguments: ' . $intReceiptId); } } // 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 ReceiptMetaControl($objParentObject, new Receipt()); }
public function btnEdit_Click($strFormId, $strControlId, $strParameter) { $strParameterArray = explode(',', $strParameter); $objReceipt = Receipt::Load($strParameterArray[0]); $objEditPanel = new ReceiptEditPanel($this, $this->strCloseEditPanelMethod, $objReceipt); $strMethodName = $this->strSetEditPanelMethod; $this->objForm->{$strMethodName}($objEditPanel); }
/** * 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; } }
public function btnApply_Click($strFormId, $strControlId, $strParameter) { $this->clearWarnings(); $blnError = false; // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); if (count($this->arrCustomFields) > 0) { $customFieldIdArray = array(); // preparing data to edit foreach ($this->arrCustomFields as $field) { if ($this->arrCheckboxes[$field['input']->strControlId]->Checked) { if ($field['input'] instanceof QTextBox && $field['input']->Required && $field['input']->Text == null || $field['input'] instanceof QListBox && $field['input']->Required && $field['input']->SelectedValue == null) { $blnError = true; $field['input']->Warning = "Required."; } else { $this->arrCustomFieldsToEdit[] = $field; $customFieldIdArray[] = (int) str_replace('cf', '', $field['input']->strControlId); } } } } // Apply checked main_table fields $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId)); if ($this->chkToCompany->Checked) { if ($this->lstToContact->SelectedValue) { $set[] = sprintf('`to_contact_id`="%s"', $this->lstToContact->SelectedValue); } else { $this->lstToContact->Warning = 'Contact name must be chosen'; $blnError = true; } if ($this->lstToAddress->SelectedValue) { $set[] = sprintf('`to_address_id`="%s"', $this->lstToAddress->SelectedValue); } else { $this->lstToAddress->Warning = 'Address name must be chosen'; $blnError = true; } } if ($this->chkFromCompany->Checked) { if ($this->lstFromCompany->SelectedValue) { $set[] = sprintf('`from_company_id`="%s"', $this->lstFromCompany->SelectedValue); } else { $this->lstFromCompany->Warning = 'Company name must be chosen'; $blnError = true; } if ($this->lstFromContact->SelectedValue) { $set[] = sprintf('`from_contact_id`="%s"', $this->lstFromContact->SelectedValue); } else { $this->lstFromContact->Warning = 'Contact name must be chosen'; $blnError = true; } } if ($this->chkDateReceived->Checked && $this->calDateReceived->DateTime) { // Check all receipts are completed if (Receipt::QueryCount(QQ::AndCondition(QQ::Equal(QQN::Receipt()->ReceivedFlag, 0), QQ::In(QQN::Receipt()->ReceiptId, $this->arrReceiptToEdit))) > 0) { $this->calDateReceived->Warning = 'Can be set only for completed receipts'; $blnError = true; } else { $set[] = sprintf('`receipt_date`="%s"', $this->calDateReceived->DateTime->__toString('YYYY-MM-DD')); } } if ($this->chkDateDue->Checked && $this->calDateDue->DateTime) { $set[] = sprintf('`due_date`="%s"', $this->calDateDue->DateTime->__toString('YYYY-MM-DD')); } if (!$blnError) { try { // Modifying transactions foreach ($this->arrReceiptToEdit as $intReceiptId) { $objTransaction = Transaction::Load(Receipt::Load($intReceiptId)->Transaction->TransactionId); $objTransaction->ModifiedBy = QApplication::$objUserAccount->UserAccountId; if ($this->chkNote->Checked) { $objTransaction->Note = $this->txtNote->Text; } $objTransaction->Save(); } if (count($this->arrCustomFieldsToEdit) > 0) { // Save the values from all of the custom field controls to save the asset foreach ($this->arrReceiptToEdit as $intReceiptId) { $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::Receipt, false); $selectedCustomFieldsArray = array(); foreach ($objCustomFieldsArray as $objCustomField) { if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) { $selectedCustomFieldsArray[] = $objCustomField; } } CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intReceiptId, EntityQtype::Receipt); } $this->arrCustomFieldsToEdit = array(); } // Update Transaction // Update main table $strQuery = sprintf("UPDATE `receipt`\n SET " . implode(",", $set) . "\n WHERE `receipt_id` IN (%s)", implode(",", $this->arrReceiptToEdit)); $objDatabase->NonQuery($strQuery); $objDatabase->TransactionCommit(); QApplication::Redirect(''); } catch (QMySqliDatabaseException $objExc) { $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } else { $objDatabase->TransactionRollback(); $this->arrCustomFieldsToEdit = array(); $this->uncheck(); } }
protected function btnMassDelete_Click() { $items = $this->dtgReceipt->getSelected('ReceiptId'); if (count($items) > 0) { $this->lblWarning->Text = ""; $arrToSkip = array(); // Separating items able to be deleted foreach ($items as $item) { $receiptToDelete = Receipt::Load($item); $objAssetTransactionArray = AssetTransaction::LoadArrayByTransactionId($receiptToDelete->TransactionId); $objInventoryTransactionArray = InventoryTransaction::LoadArrayByTransactionId($receiptToDelete->TransactionId); $blnError = false; if ($objAssetTransactionArray) { foreach ($objAssetTransactionArray as $objAssetTransaction) { if ($objAssetTransaction->blnReturnReceivedStatus()) { $blnError = true; } } } if ($objInventoryTransactionArray) { foreach ($objInventoryTransactionArray as $objInventoryTransaction) { if ($objInventoryTransaction->blnReturnReceivedStatus()) { $blnError = true; } } } if ($blnError) { $arrToSkip[] = $receiptToDelete->ReceiptNumber; } else { $this->arrToDelete[] = $receiptToDelete; // objects stored in array! } } if (count($arrToSkip) > 0) { if (count($arrToSkip) == 1) { $toBe = 'is'; $ending = ''; } else { $toBe = 'are'; $ending = 's'; } $this->dlgMassDelete->Text = sprintf("There %s %s Receipt%s that %s not able to be deleted.\n Would you like to continue the deletion process,\n skipping these item%s?<br />", $toBe, count($arrToSkip), $ending, $toBe, $ending); $this->dlgMassDelete->ShowDialogBox(); } else { if (count($this->arrToDelete) > 0) { try { // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); foreach ($this->arrToDelete as $receipt) { $this->receiptDelete($receipt); } $objDatabase->TransactionCommit(); $this->arrToDelete = array(); QApplication::Redirect(''); } catch (QMySqliDatabaseException $objExc) { $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } } } else { $this->lblWarning->Text = "You haven't chosen any Receipt to Delete"; } }
/** * This will save this object's Transaction instance, * updating only the fields which have had a control created for it. */ public function SaveTransaction() { try { // Update any fields for controls that have been created if ($this->lstEntityQtype) { $this->objTransaction->EntityQtypeId = $this->lstEntityQtype->SelectedValue; } if ($this->lstTransactionType) { $this->objTransaction->TransactionTypeId = $this->lstTransactionType->SelectedValue; } if ($this->txtNote) { $this->objTransaction->Note = $this->txtNote->Text; } if ($this->lstCreatedByObject) { $this->objTransaction->CreatedBy = $this->lstCreatedByObject->SelectedValue; } if ($this->calCreationDate) { $this->objTransaction->CreationDate = $this->calCreationDate->DateTime; } if ($this->lstModifiedByObject) { $this->objTransaction->ModifiedBy = $this->lstModifiedByObject->SelectedValue; } // Update any UniqueReverseReferences (if any) for controls that have been created for it if ($this->lstReceipt) { $this->objTransaction->Receipt = Receipt::Load($this->lstReceipt->SelectedValue); } if ($this->lstShipment) { $this->objTransaction->Shipment = Shipment::Load($this->lstShipment->SelectedValue); } // Save the Transaction object $this->objTransaction->Save(); // Finally, update any ManyToManyReferences (if any) } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } }
/** * Reload this Receipt from the database. * @return void */ public function Reload() { // Make sure we are actually Restored from the database if (!$this->__blnRestored) { throw new QCallerException('Cannot call Reload() on a new, unsaved Receipt object.'); } // Reload the Object $objReloaded = Receipt::Load($this->intReceiptId); // Update $this's local variables to match $this->TransactionId = $objReloaded->TransactionId; $this->FromCompanyId = $objReloaded->FromCompanyId; $this->FromContactId = $objReloaded->FromContactId; $this->ToContactId = $objReloaded->ToContactId; $this->ToAddressId = $objReloaded->ToAddressId; $this->strReceiptNumber = $objReloaded->strReceiptNumber; $this->dttDueDate = $objReloaded->dttDueDate; $this->dttReceiptDate = $objReloaded->dttReceiptDate; $this->blnReceivedFlag = $objReloaded->blnReceivedFlag; $this->CreatedBy = $objReloaded->CreatedBy; $this->dttCreationDate = $objReloaded->dttCreationDate; $this->ModifiedBy = $objReloaded->ModifiedBy; $this->strModifiedDate = $objReloaded->strModifiedDate; }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'ReceiptId': // Gets the value for intReceiptId (PK) // @return integer return $this->intReceiptId; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Receipt': // Gets the value for the Receipt object referenced by intReceiptId (PK) // @return Receipt try { if (!$this->objReceipt && !is_null($this->intReceiptId)) { $this->objReceipt = Receipt::Load($this->intReceiptId); } return $this->objReceipt; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }