Esempio n. 1
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 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();
     }
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
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;
     }
 }
 /**
  * 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 = Receipt::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 Receipt, given the clauses above
     $this->DataSource = Receipt::QueryArray($objCondition, $objClauses);
 }