Пример #1
0
 /**
  * Count Shipments
  * by FromCompanyId Index(es)
  * @param integer $intFromCompanyId
  * @return int
  */
 public static function CountByFromCompanyId($intFromCompanyId)
 {
     // Call Shipment::QueryCount to perform the CountByFromCompanyId query
     return Shipment::QueryCount(QQ::Equal(QQN::Shipment()->FromCompanyId, $intFromCompanyId));
 }
 public function btnApply_Click($strFormId, $strControlId, $strParameter)
 {
     $this->clearWarnings();
     $blnError = false;
     $objDatabase = QApplication::$Database[1];
     // Begin a MySQL Transaction to be either committed or rolled back
     $objDatabase->TransactionBegin();
     // Check "Contact To", "Contact From", "Coutrier" wasn't changed for shipped items
     if (Shipment::QueryCount(QQ::AndCondition(QQ::Equal(QQN::Shipment()->ShippedFlag, 1), QQ::In(QQN::Shipment()->ShipmentId, $this->arrShipmentToEdit))) > 0 && ($this->chkToCompany->Checked || $this->chkFromCompany->Checked || $this->chkCourier->Checked)) {
         $this->lblWarning->Text = '"To Company", "From Company", "Courier" shouldn\'t be changed for already
                                     Shipped items';
         $blnError = true;
     }
     if (!$blnError) {
         // Apply checked main_table fields
         $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId));
         if ($this->chkToCompany->Checked) {
             if ($this->lstToCompany->SelectedValue) {
                 $set[] = sprintf('`to_company_id`="%s"', $this->lstToCompany->SelectedValue);
             } else {
                 $this->lstToCompany->Warning = 'Company name must be chosen';
                 $blnError = true;
             }
             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->lstToContact->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->lstFromAddress->SelectedValue) {
                 $set[] = sprintf('`from_address_id`="%s"', $this->lstFromAddress->SelectedValue);
             } else {
                 $this->lstFromAddress->Warning = 'Address name must be chosen';
                 $blnError = true;
             }
         }
         if ($this->chkCourier->Checked) {
             $set[] = sprintf('`courier_id`="%s"', $this->lstCourier->SelectedValue);
         }
         if ($this->chkShipDate->Checked && $this->calShipDate->DateTime) {
             $set[] = sprintf('`ship_date`="%s"', $this->calShipDate->DateTime->__toString('YYYY-MM-DD'));
         }
     }
     if (count($this->arrCustomFields) > 0) {
         $customFieldIdArray = array();
         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);
                 }
             }
         }
     }
     // Apdate main table
     if (!$blnError) {
         try {
             // Edit Transactions
             foreach ($this->arrShipmentToEdit as $intShipmetId) {
                 $objTransaction = Transaction::Load(Shipment::Load($intShipmetId)->Transaction->TransactionId);
                 $objTransaction->ModifiedBy = QApplication::$objUserAccount->UserAccountId;
                 if ($this->chkNote->Checked) {
                     $objTransaction->Note = $this->txtNote->Text;
                 }
                 $objTransaction->Save();
             }
             if (count($this->arrCustomFieldsToEdit) > 0) {
                 // preparing data to edit
                 // Save the values from all of the custom field controls to save the asset
                 foreach ($this->arrShipmentToEdit as $intShipmentId) {
                     $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::Shipment, false);
                     $selectedCustomFieldsArray = array();
                     foreach ($objCustomFieldsArray as $objCustomField) {
                         if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) {
                             $selectedCustomFieldsArray[] = $objCustomField;
                         }
                     }
                     CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intShipmentId, EntityQtype::Shipment);
                 }
             }
             $strQuery = sprintf("UPDATE `shipment`\n                                     SET " . implode(",", $set) . "\n                                     WHERE `shipment_id` IN (%s)", implode(",", $this->arrShipmentToEdit));
             $objDatabase->NonQuery($strQuery);
             $objDatabase->TransactionCommit();
             $this->ParentControl->HideDialogBox();
             QApplication::Redirect('');
         } catch (QMySqliDatabaseException $objExc) {
             $objDatabase->TransactionRollback();
             throw new QDatabaseException();
         }
     } else {
         $objDatabase->TransactionRollback();
         $this->arrCustomFieldsToEdit = array();
         $this->uncheck();
     }
 }
 /**
  * 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 = Shipment::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 Shipment, given the clauses above
     $this->DataSource = Shipment::QueryArray($objCondition, $objClauses);
 }
Пример #4
0
 /**
  * Check if Shipment contains company
  * by CompanyId Index(es)
  * @param integer $intCompanyId
  * @return bool
  */
 public static function hasCompany($intCompanyId)
 {
     try {
         $intShipments = Shipment::QueryCount(QQ::OrCondition(QQ::Equal(QQN::Shipment()->FromCompanyId, $intCompanyId), QQ::Equal(QQN::Shipment()->ToCompanyId, $intCompanyId)));
         return $intShipments > 0 ? true : false;
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }