dolibarr  13.0.2
modFacture.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
29 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 
31 
36 {
37 
43  public function __construct($db)
44  {
45  global $conf, $user;
46 
47  $this->db = $db;
48  $this->numero = 30;
49 
50  $this->family = "financial";
51  $this->module_position = '11';
52  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53  $this->name = preg_replace('/^mod/i', '', get_class($this));
54  $this->description = "Gestion des factures";
55 
56  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57  $this->version = 'dolibarr';
58 
59  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60  $this->picto = 'bill';
61 
62  // Data directories to create when module is enabled
63  $this->dirs = array("/facture/temp");
64 
65  // Dependencies
66  $this->depends = array('always'=>"modSociete");
67  $this->requiredby = array("modComptabilite", "modAccounting");
68  $this->conflictwith = array();
69  $this->langfiles = array("bills", "companies", "compta", "products");
70  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='text')
71  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text')
72 
73  // Config pages
74  $this->config_page_url = array("facture.php");
75 
76  // Constants
77  $this->const = array();
78  $r = 0;
79 
80  $this->const[$r][0] = "FACTURE_ADDON";
81  $this->const[$r][1] = "chaine";
82  $this->const[$r][2] = "mod_facture_terre";
83  $this->const[$r][3] = 'Name of numbering numerotation rules of invoice';
84  $this->const[$r][4] = 0;
85  $r++;
86 
87  $this->const[$r][0] = "FACTURE_ADDON_PDF";
88  $this->const[$r][1] = "chaine";
89  $this->const[$r][2] = "crabe";
90  $this->const[$r][3] = 'Name of PDF model of invoice';
91  $this->const[$r][4] = 0;
92  $r++;
93 
94  $this->const[$r][0] = "FACTURE_ADDON_PDF_ODT_PATH";
95  $this->const[$r][1] = "chaine";
96  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/invoices";
97  $this->const[$r][3] = "";
98  $this->const[$r][4] = 0;
99  $r++;
100 
101  /*$this->const[$r][0] = "FACTURE_DRAFT_WATERMARK";
102  $this->const[$r][1] = "chaine";
103  $this->const[$r][2] = "__(Draft)__";
104  $this->const[$r][3] = 'Watermark to show on draft invoices';
105  $this->const[$r][4] = 0;
106  $r++;*/
107 
108 
109  // Boxes
110  //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php'));
111  $this->boxes = array(
112  0=>array('file'=>'box_factures_imp.php', 'enabledbydefaulton'=>'Home'),
113  1=>array('file'=>'box_factures.php', 'enabledbydefaulton'=>'Home'),
114  2=>array('file'=>'box_graph_invoices_permonth.php', 'enabledbydefaulton'=>'Home'),
115  3=>array('file'=>'box_customers_outstanding_bill_reached.php', 'enabledbydefaulton'=>'Home')
116  );
117 
118  // Cronjobs
119  $arraydate = dol_getdate(dol_now());
120  $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
121  $this->cronjobs = array(
122  0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart),
123  );
124 
125  // Permissions
126  $this->rights = array();
127  $this->rights_class = 'facture';
128  $r = 0;
129 
130  $r++;
131  $this->rights[$r][0] = 11;
132  $this->rights[$r][1] = 'Read invoices';
133  $this->rights[$r][2] = 'a';
134  $this->rights[$r][3] = 0;
135  $this->rights[$r][4] = 'lire';
136 
137  $r++;
138  $this->rights[$r][0] = 12;
139  $this->rights[$r][1] = 'Create and update invoices';
140  $this->rights[$r][2] = 'a';
141  $this->rights[$r][3] = 0;
142  $this->rights[$r][4] = 'creer';
143 
144  // There is a particular permission for unvalidate because this may be not forbidden by some laws
145  $r++;
146  $this->rights[$r][0] = 13;
147  $this->rights[$r][1] = 'Devalidate invoices';
148  $this->rights[$r][2] = 'a';
149  $this->rights[$r][3] = 0;
150  $this->rights[$r][4] = 'invoice_advance';
151  $this->rights[$r][5] = 'unvalidate';
152 
153  $r++;
154  $this->rights[$r][0] = 14;
155  $this->rights[$r][1] = 'Validate invoices';
156  $this->rights[$r][2] = 'a';
157  $this->rights[$r][3] = 0;
158  $this->rights[$r][4] = 'invoice_advance';
159  $this->rights[$r][5] = 'validate';
160 
161  $r++;
162  $this->rights[$r][0] = 15;
163  $this->rights[$r][1] = 'Send invoices by email';
164  $this->rights[$r][2] = 'a';
165  $this->rights[$r][3] = 0;
166  $this->rights[$r][4] = 'invoice_advance';
167  $this->rights[$r][5] = 'send';
168 
169  $r++;
170  $this->rights[$r][0] = 16;
171  $this->rights[$r][1] = 'Issue payments on invoices';
172  $this->rights[$r][2] = 'a';
173  $this->rights[$r][3] = 0;
174  $this->rights[$r][4] = 'paiement';
175 
176  $r++;
177  $this->rights[$r][0] = 19;
178  $this->rights[$r][1] = 'Delete invoices';
179  $this->rights[$r][2] = 'a';
180  $this->rights[$r][3] = 0;
181  $this->rights[$r][4] = 'supprimer';
182 
183  $r++;
184  $this->rights[$r][0] = 1321;
185  $this->rights[$r][1] = 'Export customer invoices, attributes and payments';
186  $this->rights[$r][2] = 'r';
187  $this->rights[$r][3] = 0;
188  $this->rights[$r][4] = 'facture';
189  $this->rights[$r][5] = 'export';
190 
191  $r++;
192  $this->rights[$r][0] = 1322;
193  $this->rights[$r][1] = 'Re-open a fully paid invoice';
194  $this->rights[$r][2] = 'r';
195  $this->rights[$r][3] = 0;
196  $this->rights[$r][4] = 'invoice_advance';
197  $this->rights[$r][5] = 'reopen';
198 
199 
200  // Menus
201  //-------
202  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
203 
204 
205  // Exports
206  //--------
207  $r = 1;
208 
209  $this->export_code[$r] = $this->rights_class.'_'.$r;
210  $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
211  $this->export_icon[$r] = 'invoice';
212  $this->export_permission[$r] = array(array("facture", "facture", "export", "other"));
213  $this->export_fields_array[$r] = array(
214  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 'cd.nom'=>'State',
215  's.phone'=>'Phone',
216  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4',
217  's.code_compta'=>'CustomerAccountancyCode',
218  's.code_compta_fournisseur'=>'SupplierAccountancyCode',
219  's.tva_intra'=>'VATIntra',
220  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer',
221  'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT",
222  'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'f.localtax1'=>'LT1', 'f.localtax2'=>'LT2', 'f.paye'=>"InvoicePaidCompletely", 'f.fk_statut'=>'InvoiceStatus', 'f.close_code'=>'EarlyClosingReason', 'f.close_note'=>'EarlyClosingComment',
223  'none.rest'=>'Rest',
224  'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin',
225  'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'pj.title'=>'ProjectLabel', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
226  'fd.subprice'=>"LineUnitPrice", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.total_ht'=>"LineTotalHT", 'fd.total_tva'=>"LineTotalVAT",
227  'fd.total_ttc'=>"LineTotalTTC", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
228  'fd.product_type'=>"TypeOfLineServiceOrProduct", 'fd.fk_product'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel',
229  'p.accountancy_code_sell'=>'ProductAccountancySellCode'
230  );
231  if (!empty($conf->multicurrency->enabled))
232  {
233  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
234  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
235  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
236  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
237  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
238  }
239  if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS))
240  {
241  $this->export_fields_array[$r]['f.module_source'] = 'Module';
242  $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
243  }
244  $this->export_TypeFields_array[$r] = array(
245  's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 'cd.nom'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text',
246  's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
247  'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date",
248  'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'f.localtax1'=>'Numeric', 'f.localtax2'=>'Numeric', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Numeric', 'f.close_code'=>'Text', 'f.close_note'=>'Text',
249  'none.rest'=>"NumericCompute",
250  'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text',
251  'pj.ref'=>'Text', 'pj.title'=>'Text', 'fd.rowid'=>'Numeric', 'fd.label'=>'Text', 'fd.description'=>"Text", 'fd.subprice'=>"Numeric", 'fd.tva_tx'=>"Numeric",
252  'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_tva'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date",
253  'fd.special_code'=>'Numeric', 'fd.product_type'=>"Numeric", 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text',
254  'p.accountancy_code_sell'=>'Text'
255  );
256  if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS))
257  {
258  $this->export_TypeFields_array[$r]['f.module_source'] = 'Text';
259  $this->export_TypeFields_array[$r]['f.pos_source'] = 'Text';
260  }
261  $this->export_entities_array[$r] = array(
262  's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 'cd.nom'=>'company', 's.phone'=>'company',
263  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company',
264  's.tva_intra'=>'company', 'pj.ref'=>'project', 'pj.title'=>'project', 'fd.rowid'=>'invoice_line', 'fd.label'=>"invoice_line", 'fd.description'=>"invoice_line",
265  'fd.subprice'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva_tx'=>"invoice_line",
266  'fd.qty'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>'invoice_line',
267  'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_sell'=>'product',
268  'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user'
269  );
270  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
271  $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc', 'f.close_code')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
272  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
273  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
274  $keyforselect = 'facturedet'; $keyforelement = 'invoice_line'; $keyforaliasextra = 'extra2';
275  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
276  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3';
277  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
278  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
279  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
280  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
281  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
282  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
283  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
284  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
285  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
286  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
287  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
288  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
289  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
290  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
291  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
292  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
293  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
294  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
295  $r++;
296 
297 
298  $this->export_code[$r] = $this->rights_class.'_'.$r;
299  $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
300  $this->export_icon[$r] = 'invoice';
301  $this->export_permission[$r] = array(array("facture", "facture", "export"));
302  $this->export_fields_array[$r] = array(
303  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 'cd.nom'=>'State',
304  's.phone'=>'Phone',
305  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
306  's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
307  'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer',
308  'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT",
309  'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'f.localtax1'=>'LT1', 'f.localtax2'=>'LT2', 'f.paye'=>"InvoicePaidCompletely", 'f.fk_statut'=>'InvoiceStatus', 'f.close_code'=>'EarlyClosingReason', 'f.close_note'=>'EarlyClosingComment',
310  'none.rest'=>'Rest',
311  'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin',
312  'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'pj.title'=>'ProjectLabel', 'p.rowid'=>'PaymentId', 'p.ref'=>'PaymentRef',
313  'p.amount'=>'AmountPayment', 'pf.amount'=>'AmountPaymentDistributedOnInvoice', 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber',
314  'pt.code'=>'CodePaymentMode', 'pt.libelle'=>'LabelPaymentMode', 'p.note'=>'PaymentNote', 'p.fk_bank'=>'IdTransaction', 'ba.ref'=>'AccountRef'
315  );
316  $this->export_help_array[$r] = array('f.paye'=>'InvoicePaidCompletelyHelp');
317  if (!empty($conf->multicurrency->enabled))
318  {
319  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
320  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
321  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
322  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
323  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
324  $this->export_examplevalues_array[$r]['f.multicurrency_code'] = 'EUR';
325  }
326  if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS))
327  {
328  $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
329  $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
330  }
331  $this->export_TypeFields_array[$r] = array(
332  's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 'cd.nom'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text',
333  's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
334  'f.rowid'=>"Numeric", 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date",
335  'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'f.localtax1'=>'Numeric', 'f.localtax2'=>'Numeric', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.close_code'=>'Text', 'f.close_note'=>'Text',
336  'none.rest'=>'NumericCompute',
337  'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text',
338  'pj.ref'=>'Text', 'pj.title'=>'Text', 'p.amount'=>'Numeric', 'pf.amount'=>'Numeric', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.title'=>'Text', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric',
339  'p.fk_bank'=>'Numeric', 'p.note'=>'Text', 'pt.code'=>'Text', 'pt.libelle'=>'text', 'ba.ref'=>'Text'
340  );
341  if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS))
342  {
343  $this->export_fields_array[$r]['f.module_source'] = 'POSModule';
344  $this->export_fields_array[$r]['f.pos_source'] = 'POSTerminal';
345  }
346  $this->export_entities_array[$r] = array(
347  's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 'cd.nom'=>'company', 's.phone'=>'company',
348  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company',
349  's.tva_intra'=>'company', 'pj.ref'=>'project', 'pj.title'=>'project', 'p.rowid'=>'payment', 'p.ref'=>'payment', 'p.amount'=>'payment', 'pf.amount'=>'payment', 'p.datep'=>'payment',
350  'p.num_paiement'=>'payment', 'pt.code'=>'payment', 'pt.libelle'=>'payment', 'p.note'=>'payment', 'f.fk_user_author'=>'user', 'uc.login'=>'user',
351  'f.fk_user_valid'=>'user', 'uv.login'=>'user', 'p.fk_bank'=>'account', 'ba.ref'=>'account'
352  );
353  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
354  $this->export_dependencies_array[$r] = array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc', 'f.close_code')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them, or just to have field we need
355  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
356  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
357  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
358  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
359  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
360  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
361  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as cd on s.fk_departement = cd.rowid,';
362  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
363  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
364  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
365  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
366  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
367  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
368  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
369  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement';
370  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
371  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
372  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
373  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')';
374  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
375  $r++;
376  }
377 
378 
387  public function init($options = '')
388  {
389  global $conf, $langs;
390 
391  // Remove permissions and default values
392  $this->remove($options);
393 
394  //ODT template
395  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
396  $dirodt = DOL_DATA_ROOT.'/doctemplates/invoices';
397  $dest = $dirodt.'/template_invoice.odt';
398 
399  if (file_exists($src) && !file_exists($dest))
400  {
401  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
402  dol_mkdir($dirodt);
403  $result = dol_copy($src, $dest, 0, 0);
404  if ($result < 0)
405  {
406  $langs->load("errors");
407  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
408  return 0;
409  }
410  }
411 
412  $sql = array(
413  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".$conf->entity,
414  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".$conf->entity.")"
415  );
416 
417  return $this->_init($sql, $options);
418  }
419 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
dol_now($mode= 'auto')
Return date for now.
init($options= '')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
_init($array_sql, $options= '')
Enables a module.
Class to describe module customer invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)