protected function Form_Create()
 {
     // Setup DataGrid Columns
     $this->colEditLinkColumn = new QDataGridColumn(QApplication::Translate('Edit'), '<?= $_FORM->dtgReceipt_EditLinkColumn_Render($_ITEM) ?>');
     $this->colEditLinkColumn->HtmlEntities = false;
     $this->colReceiptId = new QDataGridColumn(QApplication::Translate('Receipt Id'), '<?= $_ITEM->ReceiptId; ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptId), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptId, false)));
     $this->colTransactionId = new QDataGridColumn(QApplication::Translate('Transaction Id'), '<?= $_FORM->dtgReceipt_Transaction_Render($_ITEM); ?>');
     $this->colFromCompanyId = new QDataGridColumn(QApplication::Translate('From Company Id'), '<?= $_FORM->dtgReceipt_FromCompany_Render($_ITEM); ?>');
     $this->colFromContactId = new QDataGridColumn(QApplication::Translate('From Contact Id'), '<?= $_FORM->dtgReceipt_FromContact_Render($_ITEM); ?>');
     $this->colToContactId = new QDataGridColumn(QApplication::Translate('To Contact Id'), '<?= $_FORM->dtgReceipt_ToContact_Render($_ITEM); ?>');
     $this->colToAddressId = new QDataGridColumn(QApplication::Translate('To Address Id'), '<?= $_FORM->dtgReceipt_ToAddress_Render($_ITEM); ?>');
     $this->colReceiptNumber = new QDataGridColumn(QApplication::Translate('Receipt Number'), '<?= QString::Truncate($_ITEM->ReceiptNumber, 200); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptNumber), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptNumber, false)));
     $this->colDueDate = new QDataGridColumn(QApplication::Translate('Due Date'), '<?= $_FORM->dtgReceipt_DueDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->DueDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->DueDate, false)));
     $this->colReceiptDate = new QDataGridColumn(QApplication::Translate('Receipt Date'), '<?= $_FORM->dtgReceipt_ReceiptDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptDate, false)));
     $this->colReceivedFlag = new QDataGridColumn(QApplication::Translate('Received Flag'), '<?= ($_ITEM->ReceivedFlag) ? "true" : "false" ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceivedFlag), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceivedFlag, false)));
     $this->colCreatedBy = new QDataGridColumn(QApplication::Translate('Created By'), '<?= $_FORM->dtgReceipt_CreatedByObject_Render($_ITEM); ?>');
     $this->colCreationDate = new QDataGridColumn(QApplication::Translate('Creation Date'), '<?= $_FORM->dtgReceipt_CreationDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->CreationDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->CreationDate, false)));
     $this->colModifiedBy = new QDataGridColumn(QApplication::Translate('Modified By'), '<?= $_FORM->dtgReceipt_ModifiedByObject_Render($_ITEM); ?>');
     $this->colModifiedDate = new QDataGridColumn(QApplication::Translate('Modified Date'), '<?= QString::Truncate($_ITEM->ModifiedDate, 200); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ModifiedDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ModifiedDate, false)));
     $this->colReceiptCustomFieldHelper = new QDataGridColumn(QApplication::Translate('Receipt Custom Field Helper'), '<?= $_FORM->dtgReceipt_ReceiptCustomFieldHelper_Render($_ITEM); ?>');
     // Setup DataGrid
     $this->dtgReceipt = new QDataGrid($this);
     $this->dtgReceipt->CellSpacing = 0;
     $this->dtgReceipt->CellPadding = 4;
     $this->dtgReceipt->BorderStyle = QBorderStyle::Solid;
     $this->dtgReceipt->BorderWidth = 1;
     $this->dtgReceipt->GridLines = QGridLines::Both;
     // Datagrid Paginator
     $this->dtgReceipt->Paginator = new QPaginator($this->dtgReceipt);
     $this->dtgReceipt->ItemsPerPage = 10;
     // Specify Whether or Not to Refresh using Ajax
     $this->dtgReceipt->UseAjax = false;
     // Specify the local databind method this datagrid will use
     $this->dtgReceipt->SetDataBinder('dtgReceipt_Bind');
     $this->dtgReceipt->AddColumn($this->colEditLinkColumn);
     $this->dtgReceipt->AddColumn($this->colReceiptId);
     $this->dtgReceipt->AddColumn($this->colTransactionId);
     $this->dtgReceipt->AddColumn($this->colFromCompanyId);
     $this->dtgReceipt->AddColumn($this->colFromContactId);
     $this->dtgReceipt->AddColumn($this->colToContactId);
     $this->dtgReceipt->AddColumn($this->colToAddressId);
     $this->dtgReceipt->AddColumn($this->colReceiptNumber);
     $this->dtgReceipt->AddColumn($this->colDueDate);
     $this->dtgReceipt->AddColumn($this->colReceiptDate);
     $this->dtgReceipt->AddColumn($this->colReceivedFlag);
     $this->dtgReceipt->AddColumn($this->colCreatedBy);
     $this->dtgReceipt->AddColumn($this->colCreationDate);
     $this->dtgReceipt->AddColumn($this->colModifiedBy);
     $this->dtgReceipt->AddColumn($this->colModifiedDate);
     $this->dtgReceipt->AddColumn($this->colReceiptCustomFieldHelper);
 }
Exemple #2
0
 /**
  * Count Receipts
  * by ModifiedBy Index(es)
  * @param integer $intModifiedBy
  * @return int
  */
 public static function CountByModifiedBy($intModifiedBy)
 {
     // Call Receipt::QueryCount to perform the CountByModifiedBy query
     return Receipt::QueryCount(QQ::Equal(QQN::Receipt()->ModifiedBy, $intModifiedBy));
 }
 public function __construct($objParentObject, $strSetEditPanelMethod, $strCloseEditPanelMethod, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     // Record Method Callbacks
     $this->strSetEditPanelMethod = $strSetEditPanelMethod;
     $this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
     // Setup DataGrid Columns
     $this->colEditLinkColumn = new QDataGridColumn(QApplication::Translate('Edit'), '<?= $_CONTROL->ParentControl->dtgReceipt_EditLinkColumn_Render($_ITEM) ?>');
     $this->colEditLinkColumn->HtmlEntities = false;
     $this->colReceiptId = new QDataGridColumn(QApplication::Translate('Receipt Id'), '<?= $_ITEM->ReceiptId; ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptId), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptId, false)));
     $this->colTransactionId = new QDataGridColumn(QApplication::Translate('Transaction Id'), '<?= $_CONTROL->ParentControl->dtgReceipt_Transaction_Render($_ITEM); ?>');
     $this->colFromCompanyId = new QDataGridColumn(QApplication::Translate('From Company Id'), '<?= $_CONTROL->ParentControl->dtgReceipt_FromCompany_Render($_ITEM); ?>');
     $this->colFromContactId = new QDataGridColumn(QApplication::Translate('From Contact Id'), '<?= $_CONTROL->ParentControl->dtgReceipt_FromContact_Render($_ITEM); ?>');
     $this->colToContactId = new QDataGridColumn(QApplication::Translate('To Contact Id'), '<?= $_CONTROL->ParentControl->dtgReceipt_ToContact_Render($_ITEM); ?>');
     $this->colToAddressId = new QDataGridColumn(QApplication::Translate('To Address Id'), '<?= $_CONTROL->ParentControl->dtgReceipt_ToAddress_Render($_ITEM); ?>');
     $this->colReceiptNumber = new QDataGridColumn(QApplication::Translate('Receipt Number'), '<?= QString::Truncate($_ITEM->ReceiptNumber, 200); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptNumber), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptNumber, false)));
     $this->colDueDate = new QDataGridColumn(QApplication::Translate('Due Date'), '<?= $_CONTROL->ParentControl->dtgReceipt_DueDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->DueDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->DueDate, false)));
     $this->colReceiptDate = new QDataGridColumn(QApplication::Translate('Receipt Date'), '<?= $_CONTROL->ParentControl->dtgReceipt_ReceiptDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceiptDate, false)));
     $this->colReceivedFlag = new QDataGridColumn(QApplication::Translate('Received Flag'), '<?= ($_ITEM->ReceivedFlag) ? "true" : "false" ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceivedFlag), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ReceivedFlag, false)));
     $this->colCreatedBy = new QDataGridColumn(QApplication::Translate('Created By'), '<?= $_CONTROL->ParentControl->dtgReceipt_CreatedByObject_Render($_ITEM); ?>');
     $this->colCreationDate = new QDataGridColumn(QApplication::Translate('Creation Date'), '<?= $_CONTROL->ParentControl->dtgReceipt_CreationDate_Render($_ITEM); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->CreationDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->CreationDate, false)));
     $this->colModifiedBy = new QDataGridColumn(QApplication::Translate('Modified By'), '<?= $_CONTROL->ParentControl->dtgReceipt_ModifiedByObject_Render($_ITEM); ?>');
     $this->colModifiedDate = new QDataGridColumn(QApplication::Translate('Modified Date'), '<?= QString::Truncate($_ITEM->ModifiedDate, 200); ?>', array('OrderByClause' => QQ::OrderBy(QQN::Receipt()->ModifiedDate), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Receipt()->ModifiedDate, false)));
     // Setup DataGrid
     $this->dtgReceipt = new QDataGrid($this);
     $this->dtgReceipt->CellSpacing = 0;
     $this->dtgReceipt->CellPadding = 4;
     $this->dtgReceipt->BorderStyle = QBorderStyle::Solid;
     $this->dtgReceipt->BorderWidth = 1;
     $this->dtgReceipt->GridLines = QGridLines::Both;
     // Datagrid Paginator
     $this->dtgReceipt->Paginator = new QPaginator($this->dtgReceipt);
     $this->dtgReceipt->ItemsPerPage = 10;
     // Specify Whether or Not to Refresh using Ajax
     $this->dtgReceipt->UseAjax = true;
     // Specify the local databind method this datagrid will use
     $this->dtgReceipt->SetDataBinder('dtgReceipt_Bind', $this);
     $this->dtgReceipt->AddColumn($this->colEditLinkColumn);
     $this->dtgReceipt->AddColumn($this->colReceiptId);
     $this->dtgReceipt->AddColumn($this->colTransactionId);
     $this->dtgReceipt->AddColumn($this->colFromCompanyId);
     $this->dtgReceipt->AddColumn($this->colFromContactId);
     $this->dtgReceipt->AddColumn($this->colToContactId);
     $this->dtgReceipt->AddColumn($this->colToAddressId);
     $this->dtgReceipt->AddColumn($this->colReceiptNumber);
     $this->dtgReceipt->AddColumn($this->colDueDate);
     $this->dtgReceipt->AddColumn($this->colReceiptDate);
     $this->dtgReceipt->AddColumn($this->colReceivedFlag);
     $this->dtgReceipt->AddColumn($this->colCreatedBy);
     $this->dtgReceipt->AddColumn($this->colCreationDate);
     $this->dtgReceipt->AddColumn($this->colModifiedBy);
     $this->dtgReceipt->AddColumn($this->colModifiedDate);
     // Setup the Create New button
     $this->btnCreateNew = new QButton($this);
     $this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('Receipt');
     $this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
 }
 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();
     }
 }
Exemple #5
0
 /**
  * Check if Receipt contains company
  * by FromContactId Index(es)
  * @param integer $intContactId
  * @return bool
  */
 public static function hasCompany($intCompanyId)
 {
     try {
         $intReceipts = Receipt::QueryCount(QQ::OrCondition(QQ::Equal(QQN::Receipt()->FromCompanyId, $intCompanyId), QQ::Equal(QQN::Receipt()->ToContact->CompanyId, $intCompanyId)));
         return $intReceipts > 0 ? true : false;
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }
 /**
  * Count Receipts
  * by ModifiedBy Index(es)
  * @param integer $intModifiedBy
  * @return int
  */
 public static function CountByModifiedBy($intModifiedBy, $objOptionalClauses = null)
 {
     // Call Receipt::QueryCount to perform the CountByModifiedBy query
     return Receipt::QueryCount(QQ::Equal(QQN::Receipt()->ModifiedBy, $intModifiedBy), $objOptionalClauses);
 }
 /**
  * Used internally by the Meta-based Add Column tools.
  *
  * Given a QQNode or a Text String, this will return a Receipt-based QQNode.
  * It will also verify that it is a proper Receipt-based QQNode, and will throw an exception otherwise.
  *
  * @param mixed $mixContent
  * @return QQNode
  */
 protected function ResolveContentItem($mixContent)
 {
     if ($mixContent instanceof QQNode) {
         if (!$mixContent->_ParentNode) {
             throw new QCallerException('Content QQNode cannot be a Top Level Node');
         }
         if ($mixContent->_RootTableName == 'receipt') {
             if ($mixContent instanceof QQReverseReferenceNode && !$mixContent->_PropertyName) {
                 throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
             }
             $objCurrentNode = $mixContent;
             while ($objCurrentNode = $objCurrentNode->_ParentNode) {
                 if (!$objCurrentNode instanceof QQNode) {
                     throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
                 }
                 if ($objCurrentNode instanceof QQReverseReferenceNode && !$objCurrentNode->_PropertyName) {
                     throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
                 }
             }
             return $mixContent;
         } else {
             throw new QCallerException('Content QQNode has a root table of "' . $mixContent->_RootTableName . '". Must be a root of "receipt".');
         }
     } else {
         if (is_string($mixContent)) {
             switch ($mixContent) {
                 case 'ReceiptId':
                     return QQN::Receipt()->ReceiptId;
                 case 'TransactionId':
                     return QQN::Receipt()->TransactionId;
                 case 'Transaction':
                     return QQN::Receipt()->Transaction;
                 case 'FromCompanyId':
                     return QQN::Receipt()->FromCompanyId;
                 case 'FromCompany':
                     return QQN::Receipt()->FromCompany;
                 case 'FromContactId':
                     return QQN::Receipt()->FromContactId;
                 case 'FromContact':
                     return QQN::Receipt()->FromContact;
                 case 'ToContactId':
                     return QQN::Receipt()->ToContactId;
                 case 'ToContact':
                     return QQN::Receipt()->ToContact;
                 case 'ToAddressId':
                     return QQN::Receipt()->ToAddressId;
                 case 'ToAddress':
                     return QQN::Receipt()->ToAddress;
                 case 'ReceiptNumber':
                     return QQN::Receipt()->ReceiptNumber;
                 case 'DueDate':
                     return QQN::Receipt()->DueDate;
                 case 'ReceiptDate':
                     return QQN::Receipt()->ReceiptDate;
                 case 'ReceivedFlag':
                     return QQN::Receipt()->ReceivedFlag;
                 case 'CreatedBy':
                     return QQN::Receipt()->CreatedBy;
                 case 'CreatedByObject':
                     return QQN::Receipt()->CreatedByObject;
                 case 'CreationDate':
                     return QQN::Receipt()->CreationDate;
                 case 'ModifiedBy':
                     return QQN::Receipt()->ModifiedBy;
                 case 'ModifiedByObject':
                     return QQN::Receipt()->ModifiedByObject;
                 case 'ModifiedDate':
                     return QQN::Receipt()->ModifiedDate;
                 case 'ReceiptCustomFieldHelper':
                     return QQN::Receipt()->ReceiptCustomFieldHelper;
                 default:
                     throw new QCallerException('Simple Property not found in ReceiptDataGrid content: ' . $mixContent);
             }
         } else {
             if ($mixContent instanceof QQAssociationNode) {
                 throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.');
             } else {
                 throw new QCallerException('Invalid Content type');
             }
         }
     }
 }