[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Quotes/ -> Quotes.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header$
  17   * Description:  Defines the Account SugarBean Account entity with the necessary
  18   * methods and variables.
  19   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  20   * All Rights Reserved.
  21   * Contributor(s): ______________________________________..
  22   ********************************************************************************/
  23  class Quotes extends CRMEntity {
  24      var $log;
  25      var $db;
  26  
  27      var $table_name = "vtiger_quotes";
  28      var $table_index= 'quoteid';
  29      var $tab_name = Array('vtiger_crmentity','vtiger_quotes','vtiger_quotesbillads','vtiger_quotesshipads','vtiger_quotescf','vtiger_inventoryproductrel');
  30      var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_quotes'=>'quoteid','vtiger_quotesbillads'=>'quotebilladdressid','vtiger_quotesshipads'=>'quoteshipaddressid','vtiger_quotescf'=>'quoteid','vtiger_inventoryproductrel'=>'id');
  31      /**
  32       * Mandatory table for supporting custom fields.
  33       */
  34      var $customFieldTable = Array('vtiger_quotescf', 'quoteid');
  35      var $entity_table = "vtiger_crmentity";
  36  
  37      var $billadr_table = "vtiger_quotesbillads";
  38  
  39      var $object_name = "Quote";
  40  
  41      var $new_schema = true;
  42  
  43      var $column_fields = Array();
  44  
  45      var $sortby_fields = Array('subject','crmid','smownerid','accountname','lastname');
  46  
  47      // This is used to retrieve related vtiger_fields from form posts.
  48      var $additional_column_fields = Array('assigned_user_name', 'smownerid', 'opportunity_id', 'case_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id', 'parent_name', 'member_id' );
  49  
  50      // This is the list of vtiger_fields that are in the lists.
  51      var $list_fields = Array(
  52                  //'Quote No'=>Array('crmentity'=>'crmid'),
  53                  // Module Sequence Numbering
  54                  'Quote No'=>Array('quotes'=>'quote_no'),
  55                  // END
  56                  'Subject'=>Array('quotes'=>'subject'),
  57                  'Quote Stage'=>Array('quotes'=>'quotestage'),
  58                  'Potential Name'=>Array('quotes'=>'potentialid'),
  59                  'Account Name'=>Array('account'=> 'accountid'),
  60                  'Total'=>Array('quotes'=> 'total'),
  61                  'Assigned To'=>Array('crmentity'=>'smownerid')
  62                  );
  63  
  64      var $list_fields_name = Array(
  65                          'Quote No'=>'quote_no',
  66                          'Subject'=>'subject',
  67                          'Quote Stage'=>'quotestage',
  68                          'Potential Name'=>'potential_id',
  69                      'Account Name'=>'account_id',
  70                      'Total'=>'hdnGrandTotal',
  71                          'Assigned To'=>'assigned_user_id'
  72                        );
  73      var $list_link_field= 'subject';
  74  
  75      var $search_fields = Array(
  76                  'Quote No'=>Array('quotes'=>'quote_no'),
  77                  'Subject'=>Array('quotes'=>'subject'),
  78                  'Account Name'=>Array('quotes'=>'accountid'),
  79                  'Quote Stage'=>Array('quotes'=>'quotestage'),
  80                  );
  81  
  82      var $search_fields_name = Array(
  83                      'Quote No'=>'quote_no',
  84                          'Subject'=>'subject',
  85                          'Account Name'=>'account_id',
  86                          'Quote Stage'=>'quotestage',
  87                        );
  88  
  89      // This is the list of vtiger_fields that are required.
  90      var $required_fields =  array("accountname"=>1);
  91  
  92      //Added these variables which are used as default order by and sortorder in ListView
  93      var $default_order_by = 'crmid';
  94      var $default_sort_order = 'ASC';
  95      //var $groupTable = Array('vtiger_quotegrouprelation','quoteid');
  96  
  97      var $mandatory_fields = Array('subject','createdtime' ,'modifiedtime', 'assigned_user_id');
  98  
  99      // For Alphabetical search
 100      var $def_basicsearch_col = 'subject';
 101  
 102      // For workflows update field tasks is deleted all the lineitems.
 103      var $isLineItemUpdate = true;
 104  
 105      /**    Constructor which will set the column_fields in this object
 106       */
 107  	function Quotes() {
 108          $this->log =LoggerManager::getLogger('quote');
 109          $this->db = PearDatabase::getInstance();
 110          $this->column_fields = getColumnFields('Quotes');
 111      }
 112  
 113  	function save_module()
 114      {
 115          global $adb;
 116          //in ajax save we should not call this function, because this will delete all the existing product values
 117          if($_REQUEST['action'] != 'QuotesAjax' && $_REQUEST['ajxaction'] != 'DETAILVIEW'
 118                  && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates'
 119                  && $_REQUEST['action'] != 'SaveAjax' && $this->isLineItemUpdate != false) {
 120              //Based on the total Number of rows we will save the product relationship with this entity
 121              saveInventoryProductDetails($this, 'Quotes');
 122          }
 123  
 124          // Update the currency id and the conversion rate for the quotes
 125          $update_query = "update vtiger_quotes set currency_id=?, conversion_rate=? where quoteid=?";
 126          $update_params = array($this->column_fields['currency_id'], $this->column_fields['conversion_rate'], $this->id);
 127          $adb->pquery($update_query, $update_params);
 128      }
 129  
 130      /**    function used to get the list of sales orders which are related to the Quotes
 131       *    @param int $id - quote id
 132       *    @return array - return an array which will be returned from the function GetRelatedList
 133       */
 134  	function get_salesorder($id)
 135      {
 136          global $log,$singlepane_view;
 137          $log->debug("Entering get_salesorder(".$id.") method ...");
 138          require_once ('modules/SalesOrder/SalesOrder.php');
 139              $focus = new SalesOrder();
 140  
 141          $button = '';
 142  
 143          if($singlepane_view == 'true')
 144              $returnset = '&return_module=Quotes&return_action=DetailView&return_id='.$id;
 145          else
 146              $returnset = '&return_module=Quotes&return_action=CallRelatedList&return_id='.$id;
 147  
 148          $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>
 149                              'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 150          $query = "select vtiger_crmentity.*, vtiger_salesorder.*, vtiger_quotes.subject as quotename
 151              , vtiger_account.accountname,case when (vtiger_users.user_name not like '') then
 152              $userNameSql else vtiger_groups.groupname end as user_name
 153          from vtiger_salesorder
 154          inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_salesorder.salesorderid
 155          left outer join vtiger_quotes on vtiger_quotes.quoteid=vtiger_salesorder.quoteid
 156          left outer join vtiger_account on vtiger_account.accountid=vtiger_salesorder.accountid
 157          left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid
 158          LEFT JOIN vtiger_salesordercf ON vtiger_salesordercf.salesorderid = vtiger_salesorder.salesorderid
 159          LEFT JOIN vtiger_invoice_recurring_info ON vtiger_invoice_recurring_info.start_period = vtiger_salesorder.salesorderid
 160          LEFT JOIN vtiger_sobillads ON vtiger_sobillads.sobilladdressid = vtiger_salesorder.salesorderid
 161          LEFT JOIN vtiger_soshipads ON vtiger_soshipads.soshipaddressid = vtiger_salesorder.salesorderid
 162          left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid
 163          where vtiger_crmentity.deleted=0 and vtiger_salesorder.quoteid = ".$id;
 164          $log->debug("Exiting get_salesorder method ...");
 165          return GetRelatedList('Quotes','SalesOrder',$focus,$query,$button,$returnset);
 166      }
 167  
 168      /**    function used to get the list of activities which are related to the Quotes
 169       *    @param int $id - quote id
 170       *    @return array - return an array which will be returned from the function GetRelatedList
 171       */
 172  	function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) {
 173          global $log, $singlepane_view,$currentModule,$current_user;
 174          $log->debug("Entering get_activities(".$id.") method ...");
 175          $this_module = $currentModule;
 176  
 177          $related_module = vtlib_getModuleNameById($rel_tab_id);
 178          require_once("modules/$related_module/Activity.php");
 179          $other = new Activity();
 180          vtlib_setup_modulevars($related_module, $other);
 181          $singular_modname = vtlib_toSingular($related_module);
 182  
 183          $parenttab = getParentTab();
 184  
 185          if($singlepane_view == 'true')
 186              $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id;
 187          else
 188              $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id;
 189  
 190          $button = '';
 191  
 192          $button .= '<input type="hidden" name="activity_mode">';
 193  
 194          if($actions) {
 195              if(is_string($actions)) $actions = explode(',', strtoupper($actions));
 196              if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') {
 197                  if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id', 'readwrite') == '0') {
 198                      $button .= "<input title='".getTranslatedString('LBL_NEW'). " ". getTranslatedString('LBL_TODO', $related_module) ."' class='crmbutton small create'" .
 199                          " onclick='this.form.action.value=\"EditView\";this.form.module.value=\"$related_module\";this.form.return_module.value=\"$this_module\";this.form.activity_mode.value=\"Task\";' type='submit' name='button'" .
 200                          " value='". getTranslatedString('LBL_ADD_NEW'). " " . getTranslatedString('LBL_TODO', $related_module) ."'>&nbsp;";
 201                  }
 202              }
 203          }
 204  
 205          $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>
 206                              'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 207          $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else
 208          vtiger_groups.groupname end as user_name, vtiger_contactdetails.contactid,
 209          vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_activity.*,
 210          vtiger_seactivityrel.crmid as parent_id,vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
 211          vtiger_crmentity.modifiedtime,vtiger_recurringevents.recurringtype
 212          from vtiger_activity
 213          inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=
 214          vtiger_activity.activityid
 215          inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
 216          left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=
 217          vtiger_activity.activityid
 218          left join vtiger_contactdetails on vtiger_contactdetails.contactid =
 219          vtiger_cntactivityrel.contactid
 220          left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid
 221          left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=
 222          vtiger_activity.activityid
 223          left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid
 224          where vtiger_seactivityrel.crmid=".$id." and vtiger_crmentity.deleted=0 and
 225              activitytype='Task' and (vtiger_activity.status is not NULL and
 226              vtiger_activity.status != 'Completed') and (vtiger_activity.status is not NULL and
 227              vtiger_activity.status != 'Deferred')";
 228  
 229          $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset);
 230  
 231          if($return_value == null) $return_value = Array();
 232          $return_value['CUSTOM_BUTTON'] = $button;
 233  
 234          $log->debug("Exiting get_activities method ...");
 235          return $return_value;
 236      }
 237  
 238      /**    function used to get the the activity history related to the quote
 239       *    @param int $id - quote id
 240       *    @return array - return an array which will be returned from the function GetHistory
 241       */
 242  	function get_history($id)
 243      {
 244          global $log;
 245          $log->debug("Entering get_history(".$id.") method ...");
 246          $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>
 247                              'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 248          $query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status,
 249              vtiger_activity.eventstatus, vtiger_activity.activitytype,vtiger_activity.date_start,
 250              vtiger_activity.due_date,vtiger_activity.time_start, vtiger_activity.time_end,
 251              vtiger_contactdetails.contactid,
 252              vtiger_contactdetails.firstname,vtiger_contactdetails.lastname, vtiger_crmentity.modifiedtime,
 253              vtiger_crmentity.createdtime, vtiger_crmentity.description, case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name
 254              from vtiger_activity
 255                  inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid
 256                  inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
 257                  left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid
 258                  left join vtiger_contactdetails on vtiger_contactdetails.contactid= vtiger_cntactivityrel.contactid
 259                                  left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid
 260                  left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid
 261                  where vtiger_activity.activitytype='Task'
 262                    and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred')
 263                       and vtiger_seactivityrel.crmid=".$id."
 264                                  and vtiger_crmentity.deleted = 0";
 265          //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
 266  
 267          $log->debug("Exiting get_history method ...");
 268          return getHistory('Quotes',$query,$id);
 269      }
 270  
 271  
 272  
 273  
 274  
 275      /**    Function used to get the Quote Stage history of the Quotes
 276       *    @param $id - quote id
 277       *    @return $return_data - array with header and the entries in format Array('header'=>$header,'entries'=>$entries_list) where as $header and $entries_list are arrays which contains header values and all column values of all entries
 278       */
 279  	function get_quotestagehistory($id)
 280      {
 281          global $log;
 282          $log->debug("Entering get_quotestagehistory(".$id.") method ...");
 283  
 284          global $adb;
 285          global $mod_strings;
 286          global $app_strings;
 287  
 288          $query = 'select vtiger_quotestagehistory.*, vtiger_quotes.quote_no from vtiger_quotestagehistory inner join vtiger_quotes on vtiger_quotes.quoteid = vtiger_quotestagehistory.quoteid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_quotes.quoteid where vtiger_crmentity.deleted = 0 and vtiger_quotes.quoteid = ?';
 289          $result=$adb->pquery($query, array($id));
 290          $noofrows = $adb->num_rows($result);
 291  
 292          $header[] = $app_strings['Quote No'];
 293          $header[] = $app_strings['LBL_ACCOUNT_NAME'];
 294          $header[] = $app_strings['LBL_AMOUNT'];
 295          $header[] = $app_strings['Quote Stage'];
 296          $header[] = $app_strings['LBL_LAST_MODIFIED'];
 297  
 298          //Getting the field permission for the current user. 1 - Not Accessible, 0 - Accessible
 299          //Account Name , Total are mandatory fields. So no need to do security check to these fields.
 300          global $current_user;
 301  
 302          //If field is accessible then getFieldVisibilityPermission function will return 0 else return 1
 303          $quotestage_access = (getFieldVisibilityPermission('Quotes', $current_user->id, 'quotestage') != '0')? 1 : 0;
 304          $picklistarray = getAccessPickListValues('Quotes');
 305  
 306          $quotestage_array = ($quotestage_access != 1)? $picklistarray['quotestage']: array();
 307          //- ==> picklist field is not permitted in profile
 308          //Not Accessible - picklist is permitted in profile but picklist value is not permitted
 309          $error_msg = ($quotestage_access != 1)? 'Not Accessible': '-';
 310  
 311          while($row = $adb->fetch_array($result))
 312          {
 313              $entries = Array();
 314  
 315              // Module Sequence Numbering
 316              //$entries[] = $row['quoteid'];
 317              $entries[] = $row['quote_no'];
 318              // END
 319              $entries[] = $row['accountname'];
 320              $entries[] = $row['total'];
 321              $entries[] = (in_array($row['quotestage'], $quotestage_array))? $row['quotestage']: $error_msg;
 322              $date = new DateTimeField($row['lastmodified']);
 323              $entries[] = $date->getDisplayDateTimeValue();
 324  
 325              $entries_list[] = $entries;
 326          }
 327  
 328          $return_data = Array('header'=>$header,'entries'=>$entries_list);
 329  
 330           $log->debug("Exiting get_quotestagehistory method ...");
 331  
 332          return $return_data;
 333      }
 334  
 335      // Function to get column name - Overriding function of base class
 336  	function get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype='') {
 337          if ($columname == 'potentialid' || $columname == 'contactid') {
 338              if ($fldvalue == '') return null;
 339          }
 340          return parent::get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
 341      }
 342  
 343      /*
 344       * Function to get the secondary query part of a report
 345       * @param - $module primary module name
 346       * @param - $secmodule secondary module name
 347       * returns the query string formed on fetching the related data for report for secondary module
 348       */
 349  	function generateReportsSecQuery($module,$secmodule,$queryPlanner){
 350          $matrix = $queryPlanner->newDependencyMatrix();
 351          $matrix->setDependency('vtiger_crmentityQuotes', array('vtiger_usersQuotes', 'vtiger_groupsQuotes', 'vtiger_lastModifiedByQuotes'));
 352          $matrix->setDependency('vtiger_inventoryproductrelQuotes', array('vtiger_productsQuotes', 'vtiger_serviceQuotes'));
 353          $matrix->setDependency('vtiger_quotes',array('vtiger_crmentityQuotes', "vtiger_currency_info$secmodule",
 354                  'vtiger_quotescf', 'vtiger_potentialRelQuotes', 'vtiger_quotesbillads','vtiger_quotesshipads',
 355                  'vtiger_inventoryproductrelQuotes', 'vtiger_contactdetailsQuotes', 'vtiger_accountQuotes',
 356                  'vtiger_invoice_recurring_info','vtiger_quotesQuotes','vtiger_usersRel1'));
 357  
 358          if (!$queryPlanner->requireTable('vtiger_quotes', $matrix)) {
 359              return '';
 360          }
 361  
 362          $query = $this->getRelationQuery($module,$secmodule,"vtiger_quotes","quoteid", $queryPlanner);
 363          if ($queryPlanner->requireTable("vtiger_crmentityQuotes", $matrix)){
 364              $query .= " left join vtiger_crmentity as vtiger_crmentityQuotes on vtiger_crmentityQuotes.crmid=vtiger_quotes.quoteid and vtiger_crmentityQuotes.deleted=0";
 365          }
 366          if ($queryPlanner->requireTable("vtiger_quotescf")){
 367              $query .= " left join vtiger_quotescf on vtiger_quotes.quoteid = vtiger_quotescf.quoteid";
 368          }
 369          if ($queryPlanner->requireTable("vtiger_quotesbillads")){
 370              $query .= " left join vtiger_quotesbillads on vtiger_quotes.quoteid=vtiger_quotesbillads.quotebilladdressid";
 371          }
 372          if ($queryPlanner->requireTable("vtiger_quotesshipads")){
 373              $query .= " left join vtiger_quotesshipads on vtiger_quotes.quoteid=vtiger_quotesshipads.quoteshipaddressid";
 374          }
 375          if ($queryPlanner->requireTable("vtiger_currency_info$secmodule")){
 376              $query .= " left join vtiger_currency_info as vtiger_currency_info$secmodule on vtiger_currency_info$secmodule.id = vtiger_quotes.currency_id";
 377          }
 378          if ($queryPlanner->requireTable("vtiger_inventoryproductrelQuotes",$matrix)){
 379              $query .= " left join vtiger_inventoryproductrel as vtiger_inventoryproductrelQuotes on vtiger_quotes.quoteid = vtiger_inventoryproductrelQuotes.id";
 380              // To Eliminate duplicates in reports
 381              if(($module == 'Products' || $module == 'Services') && $secmodule == "Quotes"){
 382                  if($module == 'Products'){
 383                      $query .= " and vtiger_inventoryproductrelQuotes.productid = vtiger_products.productid ";    
 384                  }else if($module== 'Services'){
 385                      $query .= " and vtiger_inventoryproductrelQuotes.productid = vtiger_service.serviceid ";
 386                  }
 387              }
 388          }
 389          if ($queryPlanner->requireTable("vtiger_productsQuotes")){
 390              $query .= " left join vtiger_products as vtiger_productsQuotes on vtiger_productsQuotes.productid = vtiger_inventoryproductrelQuotes.productid";
 391          }
 392          if ($queryPlanner->requireTable("vtiger_serviceQuotes")){
 393              $query .= " left join vtiger_service as vtiger_serviceQuotes on vtiger_serviceQuotes.serviceid = vtiger_inventoryproductrelQuotes.productid";
 394          }
 395          if ($queryPlanner->requireTable("vtiger_groupsQuotes")){
 396              $query .= " left join vtiger_groups as vtiger_groupsQuotes on vtiger_groupsQuotes.groupid = vtiger_crmentityQuotes.smownerid";
 397          }
 398          if ($queryPlanner->requireTable("vtiger_usersQuotes")){
 399              $query .= " left join vtiger_users as vtiger_usersQuotes on vtiger_usersQuotes.id = vtiger_crmentityQuotes.smownerid";
 400          }
 401          if ($queryPlanner->requireTable("vtiger_usersRel1")){
 402              $query .= " left join vtiger_users as vtiger_usersRel1 on vtiger_usersRel1.id = vtiger_quotes.inventorymanager";
 403          }
 404          if ($queryPlanner->requireTable("vtiger_potentialRelQuotes")){
 405              $query .= " left join vtiger_potential as vtiger_potentialRelQuotes on vtiger_potentialRelQuotes.potentialid = vtiger_quotes.potentialid";
 406          }
 407          if ($queryPlanner->requireTable("vtiger_contactdetailsQuotes")){
 408              $query .= " left join vtiger_contactdetails as vtiger_contactdetailsQuotes on vtiger_contactdetailsQuotes.contactid = vtiger_quotes.contactid";
 409          }
 410          if ($queryPlanner->requireTable("vtiger_accountQuotes")){
 411              $query .= " left join vtiger_account as vtiger_accountQuotes on vtiger_accountQuotes.accountid = vtiger_quotes.accountid";
 412          }
 413          if ($queryPlanner->requireTable("vtiger_lastModifiedByQuotes")){
 414              $query .= " left join vtiger_users as vtiger_lastModifiedByQuotes on vtiger_lastModifiedByQuotes.id = vtiger_crmentityQuotes.modifiedby ";
 415          }
 416          if ($queryPlanner->requireTable("vtiger_createdbyQuotes")){
 417              $query .= " left join vtiger_users as vtiger_createdbyQuotes on vtiger_createdbyQuotes.id = vtiger_crmentityQuotes.smcreatorid ";
 418          }
 419          return $query;
 420      }
 421  
 422      /*
 423       * Function to get the relation tables for related modules
 424       * @param - $secmodule secondary module name
 425       * returns the array with table names and fieldnames storing relations between module and this module
 426       */
 427  	function setRelationTables($secmodule){
 428          $rel_tables = array (
 429              "SalesOrder" =>array("vtiger_salesorder"=>array("quoteid","salesorderid"),"vtiger_quotes"=>"quoteid"),
 430              "Calendar" =>array("vtiger_seactivityrel"=>array("crmid","activityid"),"vtiger_quotes"=>"quoteid"),
 431              "Documents" => array("vtiger_senotesrel"=>array("crmid","notesid"),"vtiger_quotes"=>"quoteid"),
 432              "Accounts" => array("vtiger_quotes"=>array("quoteid","accountid")),
 433              "Contacts" => array("vtiger_quotes"=>array("quoteid","contactid")),
 434              "Potentials" => array("vtiger_quotes"=>array("quoteid","potentialid")),
 435          );
 436          return $rel_tables[$secmodule];
 437      }
 438  
 439      // Function to unlink an entity with given Id from another entity
 440  	function unlinkRelationship($id, $return_module, $return_id) {
 441          global $log;
 442          if(empty($return_module) || empty($return_id)) return;
 443  
 444          if($return_module == 'Accounts' ) {
 445              $this->trash('Quotes',$id);
 446          } elseif($return_module == 'Potentials') {
 447              $relation_query = 'UPDATE vtiger_quotes SET potentialid=? WHERE quoteid=?';
 448              $this->db->pquery($relation_query, array(null, $id));
 449          } elseif($return_module == 'Contacts') {
 450              $relation_query = 'UPDATE vtiger_quotes SET contactid=? WHERE quoteid=?';
 451              $this->db->pquery($relation_query, array(null, $id));
 452          } else {
 453              $sql = 'DELETE FROM vtiger_crmentityrel WHERE (crmid=? AND relmodule=? AND relcrmid=?) OR (relcrmid=? AND module=? AND crmid=?)';
 454              $params = array($id, $return_module, $return_id, $id, $return_module, $return_id);
 455              $this->db->pquery($sql, $params);
 456          }
 457      }
 458  
 459  	function insertIntoEntityTable($table_name, $module, $fileid = '')  {
 460          //Ignore relation table insertions while saving of the record
 461          if($table_name == 'vtiger_inventoryproductrel') {
 462              return;
 463          }
 464          parent::insertIntoEntityTable($table_name, $module, $fileid);
 465      }
 466  
 467      /*Function to create records in current module.
 468      **This function called while importing records to this module*/
 469  	function createRecords($obj) {
 470          $createRecords = createRecords($obj);
 471          return $createRecords;
 472      }
 473  
 474      /*Function returns the record information which means whether the record is imported or not
 475      **This function called while importing records to this module*/
 476  	function importRecord($obj, $inventoryFieldData, $lineItemDetails) {
 477          $entityInfo = importRecord($obj, $inventoryFieldData, $lineItemDetails);
 478          return $entityInfo;
 479      }
 480  
 481      /*Function to return the status count of imported records in current module.
 482      **This function called while importing records to this module*/
 483  	function getImportStatusCount($obj) {
 484          $statusCount = getImportStatusCount($obj);
 485          return $statusCount;
 486      }
 487  
 488  	function undoLastImport($obj, $user) {
 489          $undoLastImport = undoLastImport($obj, $user);
 490      }
 491  
 492      /** Function to export the lead records in CSV Format
 493      * @param reference variable - where condition is passed when the query is executed
 494      * Returns Export Quotes Query.
 495      */
 496  	function create_export_query($where)
 497      {
 498          global $log;
 499          global $current_user;
 500          $log->debug("Entering create_export_query(".$where.") method ...");
 501  
 502          include ("include/utils/ExportUtils.php");
 503  
 504          //To get the Permitted fields query and the permitted fields list
 505          $sql = getPermittedFieldsQuery("Quotes", "detail_view");
 506          $fields_list = getFieldsListFromQuery($sql);
 507          $fields_list .= getInventoryFieldsForExport($this->table_name);
 508          $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
 509  
 510          $query = "SELECT $fields_list FROM ".$this->entity_table."
 511                  INNER JOIN vtiger_quotes ON vtiger_quotes.quoteid = vtiger_crmentity.crmid
 512                  LEFT JOIN vtiger_quotescf ON vtiger_quotescf.quoteid = vtiger_quotes.quoteid
 513                  LEFT JOIN vtiger_quotesbillads ON vtiger_quotesbillads.quotebilladdressid = vtiger_quotes.quoteid
 514                  LEFT JOIN vtiger_quotesshipads ON vtiger_quotesshipads.quoteshipaddressid = vtiger_quotes.quoteid
 515                  LEFT JOIN vtiger_inventoryproductrel ON vtiger_inventoryproductrel.id = vtiger_quotes.quoteid
 516                  LEFT JOIN vtiger_products ON vtiger_products.productid = vtiger_inventoryproductrel.productid
 517                  LEFT JOIN vtiger_service ON vtiger_service.serviceid = vtiger_inventoryproductrel.productid
 518                  LEFT JOIN vtiger_contactdetails ON vtiger_contactdetails.contactid = vtiger_quotes.contactid
 519                  LEFT JOIN vtiger_potential ON vtiger_potential.potentialid = vtiger_quotes.potentialid
 520                  LEFT JOIN vtiger_account ON vtiger_account.accountid = vtiger_quotes.accountid
 521                  LEFT JOIN vtiger_currency_info ON vtiger_currency_info.id = vtiger_quotes.currency_id
 522                  LEFT JOIN vtiger_users AS vtiger_inventoryManager ON vtiger_inventoryManager.id = vtiger_quotes.inventorymanager
 523                  LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid
 524                  LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid";
 525  
 526          $query .= $this->getNonAdminAccessControlQuery('Quotes',$current_user);
 527          $where_auto = " vtiger_crmentity.deleted=0";
 528  
 529          if($where != "") {
 530              $query .= " where ($where) AND ".$where_auto;
 531          } else {
 532              $query .= " where ".$where_auto;
 533          }
 534  
 535          $log->debug("Exiting create_export_query method ...");
 536          return $query;
 537      }
 538  
 539  }
 540  
 541  ?>


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