[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

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


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