[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/PriceBooks/models/ -> Module.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  class PriceBooks_Module_Model extends Vtiger_Module_Model {
  12  
  13      /**
  14       * Function returns query for PriceBook-Product relation
  15       * @param <Vtiger_Record_Model> $recordModel
  16       * @param <Vtiger_Record_Model> $relatedModuleModel
  17       * @return <String>
  18       */
  19  	function get_pricebook_products($recordModel, $relatedModuleModel) {
  20          $query = 'SELECT vtiger_products.productid, vtiger_products.productname, vtiger_products.productcode, vtiger_products.commissionrate,
  21                          vtiger_products.qty_per_unit, vtiger_products.unit_price, vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  22                          vtiger_pricebookproductrel.listprice
  23                  FROM vtiger_products
  24                  INNER JOIN vtiger_pricebookproductrel ON vtiger_products.productid = vtiger_pricebookproductrel.productid
  25                  INNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_products.productid
  26                  INNER JOIN vtiger_pricebook on vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid
  27                  INNER JOIN vtiger_productcf on vtiger_productcf.productid = vtiger_products.productid
  28                  LEFT JOIN vtiger_users ON vtiger_users.id=vtiger_crmentity.smownerid
  29                  LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid '
  30                  . Users_Privileges_Model::getNonAdminAccessControlQuery($relatedModuleModel->getName()) .'
  31                  WHERE vtiger_pricebook.pricebookid = '.$recordModel->getId().' and vtiger_crmentity.deleted = 0';
  32          return $query;
  33      }
  34  
  35  
  36      /**
  37       * Function returns query for PriceBooks-Services Relationship
  38       * @param <Vtiger_Record_Model> $recordModel
  39       * @param <Vtiger_Record_Model> $relatedModuleModel
  40       * @return <String>
  41       */
  42  	function get_pricebook_services($recordModel, $relatedModuleModel) {
  43          $query = 'SELECT vtiger_service.serviceid, vtiger_service.servicename, vtiger_service.service_no, vtiger_service.commissionrate,
  44                      vtiger_service.qty_per_unit, vtiger_service.unit_price, vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
  45                      vtiger_pricebookproductrel.listprice
  46              FROM vtiger_service
  47              INNER JOIN vtiger_pricebookproductrel on vtiger_service.serviceid = vtiger_pricebookproductrel.productid
  48              INNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_service.serviceid
  49              INNER JOIN vtiger_pricebook on vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid
  50              INNER JOIN vtiger_servicecf on vtiger_servicecf.serviceid = vtiger_service.serviceid
  51              LEFT JOIN vtiger_users ON vtiger_users.id=vtiger_crmentity.smownerid
  52              LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid '
  53              . Users_Privileges_Model::getNonAdminAccessControlQuery($relatedModuleModel->getName()) .'
  54              WHERE vtiger_pricebook.pricebookid = '.$recordModel->getId().' and vtiger_crmentity.deleted = 0';
  55          return $query;
  56      }
  57  
  58      /**
  59       * Function to get list view query for popup window
  60       * @param <String> $sourceModule Parent module
  61       * @param <String> $field parent fieldname
  62       * @param <Integer> $record parent id
  63       * @param <String> $listQuery
  64       * @return <String> Listview Query
  65       */
  66  	public function getQueryByModuleField($sourceModule, $field, $record, $listQuery, $currencyId = false) {
  67          $relatedModulesList = array('Products', 'Services');
  68          if (in_array($sourceModule, $relatedModulesList)) {
  69              $pos = stripos($listQuery, ' where ');
  70              if ($currencyId && in_array($field, array('productid', 'serviceid'))) {
  71                  $condition = " vtiger_pricebook.pricebookid IN (SELECT pricebookid FROM vtiger_pricebookproductrel WHERE productid = $record)
  72                                  AND vtiger_pricebook.currency_id = $currencyId AND vtiger_pricebook.active = 1";
  73              } else if($field == 'productsRelatedList') {
  74                  $condition = "vtiger_pricebook.pricebookid NOT IN (SELECT pricebookid FROM vtiger_pricebookproductrel WHERE productid = $record)
  75                                  AND vtiger_pricebook.active = 1";
  76              }
  77              if ($pos) {
  78                  $split = spliti(' where ', $listQuery);
  79                  $overRideQuery = $split[0] . ' WHERE ' . $split[1] . ' AND ' . $condition;
  80              } else {
  81                  $overRideQuery = $listQuery . ' WHERE ' . $condition;
  82              }
  83              return $overRideQuery;
  84          }
  85      }
  86      
  87      /**
  88       * Function to check whether the module is summary view supported
  89       * @return <Boolean> - true/false
  90       */
  91  	public function isSummaryViewSupported() {
  92          return false;
  93      }
  94      
  95      /**
  96       * Funtion that returns fields that will be showed in the record selection popup
  97       * @return <Array of fields>
  98       */
  99  	public function getPopupViewFieldsList() {
 100          $popupFileds = $this->getSummaryViewFieldsList();
 101          $reqPopUpFields = array('Currency' => 'currency_id'); 
 102          foreach ($reqPopUpFields as $fieldLabel => $fieldName) {
 103              $fieldModel = Vtiger_Field_Model::getInstance($fieldName,$this); 
 104              if ($fieldModel->getPermissions('readwrite')) { 
 105                  $popupFileds[$fieldName] = $fieldModel; 
 106              }
 107          }
 108          return array_keys($popupFileds);
 109      }
 110  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1