[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Import/ -> ImportOpportunity.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   ********************************************************************************/
  20  
  21  include_once ('config.php');
  22  require_once ('include/logging.php');
  23  require_once ('include/database/PearDatabase.php');
  24  require_once ('data/SugarBean.php');
  25  require_once ('modules/Contacts/Contacts.php');
  26  require_once ('modules/Potentials/Potentials.php');
  27  require_once ('modules/Notes/Notes.php');
  28  require_once ('modules/Emails/Emails.php');
  29  require_once ('modules/Accounts/Accounts.php');
  30  require_once ('include/ComboUtil.php');
  31  
  32  // Get _dom arrays from Database
  33  $comboFieldNames = Array('leadsource'=>'lead_source_dom'
  34                        ,'opportunity_type'=>'opportunity_type_dom'
  35                        ,'sales_stage'=>'sales_stage_dom');
  36  $comboFieldArray = getComboArray($comboFieldNames);
  37  
  38  // Account is used to store vtiger_account information.
  39  class ImportOpportunity extends Potentials {
  40       var $db;
  41  
  42      // This is the list of vtiger_fields that are required.
  43      /*
  44      var $required_fields =  array(
  45                      "potentialname"=>1,
  46                      "account_id"=>1,
  47                      "closingdate"=>1,
  48                      "sales_stage"=>1,
  49                      "amount"=>1
  50                       );
  51      */
  52  
  53      // This is the list of the functions to run when importing
  54      var $special_functions =  array(
  55                          "add_create_account",
  56                          //"add_lead_source",
  57                          //"add_opportunity_type",
  58                              //"add_date_closed"
  59                              //"add_sales_stage"
  60                         );
  61      /*
  62          function add_lead_source()
  63          {
  64                  if ( isset($this->lead_source) &&
  65                          ! isset( $comboFieldArray['lead_source_dom'][ $this->lead_source ]) )
  66                  {
  67                          $this->lead_source = '';
  68                  }
  69  
  70          }
  71  
  72          function add_sales_stage()
  73          {
  74                  if ( isset($this->sales_stage) &&
  75                          ! isset( $comboFieldArray['sales_stage_dom'][ $this->sales_stage ]) )
  76                  {
  77                          $this->sales_stage = 'Prospecting';
  78                  }
  79  
  80  
  81      }
  82  
  83          function add_opportunity_type()
  84          {
  85                  if ( isset($this->opportunity_type) &&
  86                          ! isset( $comboFieldArray['opportunity_type_dom'][ $this->opportunity_type ]) )
  87                  {
  88                          $this->opportunity_type = '';
  89                  }
  90  
  91          }
  92  
  93          function add_date_closed()
  94          {
  95                  if ( isset($this->date_closed))
  96                  {
  97                          if ( preg_match('/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/',$this->date_closed,$match))
  98                          {
  99                                  $this->date_closed = $match[3]."-".$match[1]."-".$match[2];
 100                          }
 101  
 102                          if (! preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/',$this->date_closed))
 103                          {
 104                                  $this->date_closed = '';
 105                          }
 106                  }
 107  
 108          }
 109      */
 110  
 111      //exactly the same function from ImportAccount.php
 112      // lets put this in one place.. 
 113  
 114      /**     function used to create or map with existing account if the potential is map with an account during import
 115           */
 116  	function add_create_account()
 117          {
 118          global $adb;
 119          // global is defined in UsersLastImport.php
 120          global $imported_ids;
 121                  global $current_user;
 122  
 123          $acc_name = $this->column_fields['account_id'];
 124          $adb->println("oppor add_create acc=".$acc_name);
 125  
 126          if ((! isset($acc_name) || $acc_name == '') )
 127          {
 128              return; 
 129          }
 130  
 131                  $arr = array();
 132  
 133          // check if it already exists
 134                  $focus = new Accounts();
 135  
 136          $query = '';
 137  
 138          // if user is defining the vtiger_account id to be associated with this contact..
 139          $acc_name = trim(addslashes($acc_name));
 140  
 141          //Modified the query to get the available account only ie., which is not deleted
 142          $query = "select vtiger_crmentity.deleted, vtiger_account.* from vtiger_account, vtiger_crmentity WHERE accountname='{$acc_name}' and vtiger_crmentity.crmid =vtiger_account.accountid and vtiger_crmentity.deleted=0";
 143  
 144                  $this->log->info($query);
 145  
 146                  $result = $adb->query($query);
 147  
 148                  $row = $this->db->fetchByAssoc($result, -1, false);
 149  
 150          $adb->println("fetched account");
 151          $adb->println($row);
 152  
 153          // we found a row with that id
 154                  if (isset($row['accountid']) && $row['accountid'] != -1)
 155                  {
 156              $focus->id = $row['accountid'];
 157              $adb->println("Account row exists - using same id=".$focus->id);
 158                  }
 159  
 160          // if we didnt find the vtiger_account, so create it
 161                  if (! isset($focus->id) || $focus->id == '')
 162                  {
 163              $adb->println("Createing new vtiger_account");
 164                          $focus->column_fields['accountname'] = $acc_name;
 165                          $focus->column_fields['assigned_user_id'] = $current_user->id;
 166                          $focus->column_fields['modified_user_id'] = $current_user->id;
 167  
 168              $focus->save("Accounts");
 169              $acc_id = $focus->id;
 170  
 171              $adb->println("New Account created id=".$focus->id);
 172  
 173              // avoid duplicate mappings:
 174              if (! isset( $imported_ids[$acc_id]) )
 175              {
 176                  $adb->println("inserting vtiger_users last import for vtiger_accounts");
 177                  // save the new vtiger_account as a vtiger_users_last_import
 178                          $last_import = new UsersLastImport();
 179                          $last_import->assigned_user_id = $current_user->id;
 180                          $last_import->bean_type = "Accounts";
 181                          $last_import->bean_id = $focus->id;
 182                          $last_import->save();
 183                  $imported_ids[$acc_id] = 1;
 184              }
 185                  }
 186  
 187          $adb->println("prev contact accid=".$this->column_fields["account_id"]);
 188          // now just link the vtiger_account
 189                  $this->column_fields["account_id"] = $focus->id;
 190          $adb->println("curr contact accid=".$this->column_fields["account_id"]);
 191  
 192          }    
 193  
 194      /*
 195      function fix_website()
 196      {
 197          if ( isset($this->website) &&
 198              preg_match("/^http:\/\//",$this->website) )
 199          {
 200              $this->website = substr($this->website,7);
 201          }    
 202      }
 203      */
 204      
 205      // This is the list of vtiger_fields that are importable.
 206      // some if these do not map directly to database columns
 207      /*var $importable_fields = Array(
 208          "id"=>1
 209                  , "name"=>1
 210                  , "account_id"=>1
 211                  , "account_name"=>1
 212                  , "opportunity_type"=>1
 213                  , "lead_source"=>1
 214                  , "amount"=>1
 215                  , "date_entered"=>1
 216                  , "date_closed"=>1
 217                  , "next_step"=>1
 218                  , "sales_stage"=>1
 219                  , "probability"=>1
 220                  , "description"=>1
 221          );*/
 222  
 223      var $importable_fields = Array();
 224  
 225      /** Constructor which will set the importable_fields as $this->importable_fields[$key]=1 in this object where key is the fieldname in the field table
 226       */
 227  	function ImportOpportunity() {
 228          $this->log = LoggerManager::getLogger('import_opportunity');
 229          $this->db = new PearDatabase();
 230  
 231          $this->db->println("IMP ImportOpportunity");
 232          $colf = getColumnFields("Potentials");
 233          foreach($colf as $key=>$value)
 234              $this->importable_fields[$key]=1;
 235          
 236          
 237          $this->db->println($this->importable_fields);
 238      }
 239  
 240  }
 241  
 242  
 243  
 244  ?>


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