[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/SalesOrder/ -> SalesOrder.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  
  24  include_once ('config.php');
  25  require_once ('include/logging.php');
  26  require_once ('include/database/PearDatabase.php');
  27  require_once ('data/SugarBean.php');
  28  require_once ('data/CRMEntity.php');
  29  require_once ('include/utils/utils.php');
  30  require_once ('user_privileges/default_module_view.php');
  31  
  32  // Account is used to store vtiger_account information.
  33  class SalesOrder extends CRMEntity {
  34      var $log;
  35      var $db;
  36  
  37      var $table_name = "vtiger_salesorder";
  38      var $tab_name = Array('vtiger_crmentity','vtiger_salesorder','vtiger_sobillads','vtiger_soshipads','vtiger_salesordercf');
  39      var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_salesorder'=>'salesorderid','vtiger_sobillads'=>'sobilladdressid','vtiger_soshipads'=>'soshipaddressid','vtiger_salesordercf'=>'salesorderid');
  40      
  41      var $entity_table = "vtiger_crmentity";
  42      
  43      var $billadr_table = "vtiger_sobillads";
  44  
  45      var $object_name = "SalesOrder";
  46  
  47      var $new_schema = true;
  48      
  49      var $module_id = "salesorderid";
  50  
  51      var $column_fields = Array();
  52  
  53      var $sortby_fields = Array('subject','smownerid');        
  54  
  55      // This is used to retrieve related vtiger_fields from form posts.
  56      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' );
  57  
  58      // This is the list of vtiger_fields that are in the lists.
  59      var $list_fields = Array(
  60                  'Order Id'=>Array('crmentity'=>'crmid'),
  61                  'Subject'=>Array('salesorder'=>'subject'),
  62                  'Account Name'=>Array('account'=>'accountid'), 
  63                  'Quote Name'=>Array('quotes'=>'quoteid'), 
  64                  'Total'=>Array('salesorder'=>'total'),
  65                  'Assigned To'=>Array('crmentity'=>'smownerid')
  66                  );
  67      
  68      var $list_fields_name = Array(
  69                          'Order Id'=>'',
  70                          'Subject'=>'subject',
  71                          'Account Name'=>'account_id',
  72                          'Quote Name'=>'quote_id',
  73                      'Total'=>'hdnGrandTotal',
  74                          'Assigned To'=>'assigned_user_id'
  75                        );
  76      var $list_link_field= 'subject';
  77  
  78      var $search_fields = Array(
  79                  'Order Id'=>Array('crmentity'=>'crmid'),
  80                  'Subject'=>Array('salesorder'=>'subject'),
  81                  'Account Name'=>Array('account'=>'accountid'),
  82                  'Quote Name'=>Array('salesorder'=>'quoteid') 
  83                  );
  84      
  85      var $search_fields_name = Array(
  86                      'Order Id'=>'',
  87                          'Subject'=>'subject',
  88                          'Account Name'=>'account_id',
  89                          'Quote Name'=>'quote_id'
  90                        );
  91  
  92      // This is the list of vtiger_fields that are required.
  93      var $required_fields =  array("accountname"=>1);
  94  
  95      //Added these variables which are used as default order by and sortorder in ListView
  96      var $default_order_by = 'subject';
  97      var $default_sort_order = 'ASC';
  98  
  99  
 100      /** Constructor Function for SalesOrder class
 101       *  This function creates an instance of LoggerManager class using getLogger method
 102       *  creates an instance for PearDatabase class and get values for column_fields array of SalesOrder class.
 103       */
 104  	function SalesOrder() {
 105          $this->log =LoggerManager::getLogger('SalesOrder');
 106          $this->db = new PearDatabase();
 107          $this->column_fields = getColumnFields('SalesOrder');
 108      }
 109  
 110  	function save_module($module)
 111      {
 112      
 113          //Checking if quote_id is present and updating the quote status
 114          if($this->column_fields["quote_id"] != '')
 115          {
 116                  $qt_id = $this->column_fields["quote_id"];
 117                  $query1 = "update vtiger_quotes set quotestage='Accepted' where quoteid=".$qt_id;
 118                  $this->db->query($query1);
 119          }
 120  
 121          //Based on the total Number of rows we will save the product relationship with this entity
 122          saveInventoryProductDetails(&$this, 'SalesOrder');    
 123  
 124          
 125      }    
 126      
 127      /**    Function used to get the sort order for Sales Order listview
 128       *    @return string    $sorder    - first check the $_REQUEST['sorder'] if request value is empty then check in the $_SESSION['SALESORDER_SORT_ORDER'] if this session value is empty then default sort order will be returned. 
 129       */
 130  	function getSortOrder()
 131      {
 132          global $log;
 133                  $log->debug("Entering getSortOrder() method ...");    
 134          if(isset($_REQUEST['sorder'])) 
 135              $sorder = $_REQUEST['sorder'];
 136          else
 137              $sorder = (($_SESSION['SALESORDER_SORT_ORDER'] != '')?($_SESSION['SALESORDER_SORT_ORDER']):($this->default_sort_order));
 138          $log->debug("Exiting getSortOrder() method ...");
 139          return $sorder;
 140      }
 141  
 142      /**    Function used to get the order by value for Sales Order listview
 143       *    @return string    $order_by  - first check the $_REQUEST['order_by'] if request value is empty then check in the $_SESSION['SALESORDER_ORDER_BY'] if this session value is empty then default order by will be returned. 
 144       */
 145  	function getOrderBy()
 146      {
 147          global $log;
 148                  $log->debug("Entering getOrderBy() method ...");
 149          if (isset($_REQUEST['order_by'])) 
 150              $order_by = $_REQUEST['order_by'];
 151          else
 152              $order_by = (($_SESSION['SALESORDER_ORDER_BY'] != '')?($_SESSION['SALESORDER_ORDER_BY']):($this->default_order_by));
 153          $log->debug("Exiting getOrderBy method ...");
 154          return $order_by;
 155      }    
 156  
 157      /** Function to get activities associated with the Sales Order
 158       *  This function accepts the id as arguments and execute the MySQL query using the id
 159       *  and sends the query and the id as arguments to renderRelatedActivities() method
 160       */
 161  	function get_activities($id)
 162      {
 163          global $log,$singlepane_view;
 164          $log->debug("Entering get_activities(".$id.") method ...");
 165          global $app_strings;
 166                 require_once ('modules/Calendar/Activity.php'); 
 167          $focus = new Activity();
 168  
 169          $button = '';
 170  
 171          if($singlepane_view == 'true')
 172              $returnset = '&return_module=SalesOrder&return_action=DetailView&return_id='.$id;
 173          else
 174              $returnset = '&return_module=SalesOrder&return_action=CallRelatedList&return_id='.$id;
 175  
 176          $query = "SELECT vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_contactdetails.contactid, vtiger_activity.*,vtiger_seactivityrel.*,vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_users.user_name from vtiger_activity inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_seactivityrel.crmid=".$id." and activitytype='Task' and vtiger_crmentity.deleted=0 and (vtiger_activity.status is not NULL && vtiger_activity.status != 'Completed') and (vtiger_activity.status is not NULL && vtiger_activity.status !='Deferred')";
 177          $log->debug("Exiting get_activities method ...");
 178          return GetRelatedList('SalesOrder','Calendar',$focus,$query,$button,$returnset);
 179      }
 180  
 181      /** Function to get the activities history associated with the Sales Order
 182       *  This function accepts the id as arguments and execute the MySQL query using the id
 183       *  and sends the query and the id as arguments to renderRelatedHistory() method
 184       */
 185  	function get_history($id)
 186      {
 187          global $log;
 188          $log->debug("Entering get_history(".$id.") method ...");
 189          $query = "SELECT vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_contactdetails.contactid,
 190              vtiger_activity.*, vtiger_seactivityrel.*, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime,
 191              vtiger_crmentity.createdtime, vtiger_crmentity.description, vtiger_users.user_name
 192              from vtiger_activity
 193                  inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid
 194                  inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
 195                  left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid
 196                  left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid
 197                  inner join vtiger_users on vtiger_crmentity.smcreatorid=vtiger_users.id
 198                  left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_activity.activityid
 199                                  left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname
 200              where activitytype='Task'
 201                  and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred')
 202                  and vtiger_seactivityrel.crmid=".$id;
 203          //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
 204  
 205          $log->debug("Exiting get_history method ...");
 206          return getHistory('SalesOrder',$query,$id);
 207      }
 208  
 209      /** Function to get vtiger_attachments associated with the Sales Order
 210       *  This function accepts the id as arguments and execute the MySQL query using the id
 211       *  and sends the query and the id as arguments to renderRelatedAttachments() method.
 212       */
 213  	function get_attachments($id)
 214      {
 215          global $log;
 216          $log->debug("Entering get_attachments(".$id.") method ...");
 217  
 218          $query = "select vtiger_notes.title,'Notes      ' as ActivityType, vtiger_notes.filename,
 219           vtiger_attachments.type as FileType,crm2.modifiedtime as lastmodified,
 220           vtiger_seattachmentsrel.attachmentsid as attachmentsid, vtiger_notes.notesid as crmid,
 221           vtiger_crmentity.createdtime, vtiger_notes.notecontent as description, vtiger_users.user_name
 222          from vtiger_notes
 223              inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid
 224              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid
 225              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0
 226              left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid
 227              left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
 228              inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id
 229          where vtiger_crmentity.crmid=".$id;
 230  
 231          $query .= ' union all ';
 232  
 233          $query .= "select vtiger_attachments.description as title ,'Attachments' as ActivityType,
 234           vtiger_attachments.name as filename, vtiger_attachments.type as FileType, crm2.modifiedtime as lastmodified,
 235           vtiger_attachments.attachmentsid as attachmentsid, vtiger_seattachmentsrel.attachmentsid as crmid,
 236          vtiger_crmentity.createdtime, vtiger_attachments.description, vtiger_users.user_name
 237          from vtiger_attachments
 238              inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid
 239              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid
 240              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid
 241              inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id
 242          where vtiger_crmentity.crmid=".$id."
 243          order by createdtime desc";
 244  
 245          $log->debug("Exiting get_attachments method ...");
 246          return getAttachmentsAndNotes('SalesOrder',$query,$id,$sid='salesorderid');
 247      }
 248  
 249      /** Function to get the invoices associated with the Sales Order
 250       *  This function accepts the id as arguments and execute the MySQL query using the id
 251       *  and sends the query and the id as arguments to renderRelatedInvoices() method.
 252       */
 253  	function get_invoices($id)
 254      {
 255          global $log,$singlepane_view;    
 256          $log->debug("Entering get_invoices(".$id.") method ...");
 257          require_once ('modules/Invoice/Invoice.php');
 258  
 259          $focus = new Invoice();
 260      
 261          $button = '';
 262          if($singlepane_view == 'true')
 263              $returnset = '&return_module=SalesOrder&return_action=DetailView&return_id='.$id;
 264          else
 265              $returnset = '&return_module=SalesOrder&return_action=CallRelatedList&return_id='.$id;
 266  
 267  
 268          $query = "select vtiger_crmentity.*, vtiger_invoice.*, vtiger_account.accountname, vtiger_salesorder.subject as salessubject from vtiger_invoice inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_invoice.invoiceid left outer join vtiger_account on vtiger_account.accountid=vtiger_invoice.accountid inner join vtiger_salesorder on vtiger_salesorder.salesorderid=vtiger_invoice.salesorderid left join vtiger_invoicegrouprelation on vtiger_invoice.invoiceid=vtiger_invoicegrouprelation.invoiceid left join vtiger_groups on vtiger_groups.groupname=vtiger_invoicegrouprelation.groupname where vtiger_crmentity.deleted=0 and vtiger_salesorder.salesorderid=".$id;
 269          $log->debug("Exiting get_invoices method ...");
 270          return GetRelatedList('SalesOrder','Invoice',$focus,$query,$button,$returnset);
 271      
 272      }
 273  
 274      /**    Function used to get the Status history of the Sales Order
 275       *    @param $id - salesorder id
 276       *    @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
 277       */
 278  	function get_sostatushistory($id)
 279      {    
 280          global $log;
 281          $log->debug("Entering get_sostatushistory(".$id.") method ...");
 282  
 283          global $adb;
 284          global $mod_strings;
 285          global $app_strings;
 286  
 287          $query = 'select vtiger_sostatushistory.*, vtiger_salesorder.subject from vtiger_sostatushistory inner join vtiger_salesorder on vtiger_salesorder.salesorderid = vtiger_sostatushistory.salesorderid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_salesorder.salesorderid where vtiger_crmentity.deleted = 0 and vtiger_salesorder.salesorderid = '.$id;
 288          $result=$adb->query($query);
 289          $noofrows = $adb->num_rows($result);
 290  
 291          $header[] = $app_strings['Order Id'];
 292          $header[] = $app_strings['LBL_ACCOUNT_NAME'];
 293          $header[] = $app_strings['LBL_AMOUNT'];
 294          $header[] = $app_strings['LBL_SO_STATUS'];
 295          $header[] = $app_strings['LBL_LAST_MODIFIED'];
 296  
 297          while($row = $adb->fetch_array($result))
 298          {
 299              $entries = Array();
 300  
 301              $entries[] = $row['salesorderid'];
 302              $entries[] = $row['accountname'];
 303              $entries[] = $row['total'];
 304              $entries[] = $row['sostatus'];
 305              $entries[] = getDisplayDate($row['lastmodified']);
 306  
 307              $entries_list[] = $entries;
 308          }
 309  
 310          $return_data = Array('header'=>$header,'entries'=>$entries_list);
 311  
 312           $log->debug("Exiting get_sostatushistory method ...");
 313  
 314          return $return_data;
 315      }
 316  
 317      
 318  }
 319  
 320  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7