dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
20  */
21 
29 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 
31 
36 {
37 
43  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 = '10';
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  );
116 
117  // Cronjobs
118  $arraydate=dol_getdate(dol_now());
119  $datestart=dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
120  $this->cronjobs = array(
121  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),
122  );
123 
124  // Permissions
125  $this->rights = array();
126  $this->rights_class = 'facture';
127  $r = 0;
128 
129  $r++;
130  $this->rights[$r][0] = 11;
131  $this->rights[$r][1] = 'Read invoices';
132  $this->rights[$r][2] = 'a';
133  $this->rights[$r][3] = 0;
134  $this->rights[$r][4] = 'lire';
135 
136  $r++;
137  $this->rights[$r][0] = 12;
138  $this->rights[$r][1] = 'Create and update invoices';
139  $this->rights[$r][2] = 'a';
140  $this->rights[$r][3] = 0;
141  $this->rights[$r][4] = 'creer';
142 
143  // There is a particular permission for unvalidate because this may be not forbidden by some laws
144  $r++;
145  $this->rights[$r][0] = 13;
146  $this->rights[$r][1] = 'Devalidate invoices';
147  $this->rights[$r][2] = 'a';
148  $this->rights[$r][3] = 0;
149  $this->rights[$r][4] = 'invoice_advance';
150  $this->rights[$r][5] = 'unvalidate';
151 
152  $r++;
153  $this->rights[$r][0] = 14;
154  $this->rights[$r][1] = 'Validate invoices';
155  $this->rights[$r][2] = 'a';
156  $this->rights[$r][3] = 0;
157  $this->rights[$r][4] = 'invoice_advance';
158  $this->rights[$r][5] = 'validate';
159 
160  $r++;
161  $this->rights[$r][0] = 15;
162  $this->rights[$r][1] = 'Send invoices by email';
163  $this->rights[$r][2] = 'a';
164  $this->rights[$r][3] = 0;
165  $this->rights[$r][4] = 'invoice_advance';
166  $this->rights[$r][5] = 'send';
167 
168  $r++;
169  $this->rights[$r][0] = 16;
170  $this->rights[$r][1] = 'Issue payments on invoices';
171  $this->rights[$r][2] = 'a';
172  $this->rights[$r][3] = 0;
173  $this->rights[$r][4] = 'paiement';
174 
175  $r++;
176  $this->rights[$r][0] = 19;
177  $this->rights[$r][1] = 'Delete invoices';
178  $this->rights[$r][2] = 'a';
179  $this->rights[$r][3] = 0;
180  $this->rights[$r][4] = 'supprimer';
181 
182  $r++;
183  $this->rights[$r][0] = 1321;
184  $this->rights[$r][1] = 'Export customer invoices, attributes and payments';
185  $this->rights[$r][2] = 'r';
186  $this->rights[$r][3] = 0;
187  $this->rights[$r][4] = 'facture';
188  $this->rights[$r][5] = 'export';
189 
190  $r++;
191  $this->rights[$r][0] = 1322;
192  $this->rights[$r][1] = 'Re-open a fully paid invoice';
193  $this->rights[$r][2] = 'r';
194  $this->rights[$r][3] = 0;
195  $this->rights[$r][4] = 'invoice_advance';
196  $this->rights[$r][5] = 'reopen';
197 
198 
199  // Menus
200  //-------
201  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
202 
203 
204  // Exports
205  //--------
206  $r = 1;
207 
208  $this->export_code[$r] = $this->rights_class.'_'.$r;
209  $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
210  $this->export_icon[$r] = 'invoice';
211  $this->export_permission[$r] = array(array("facture", "facture", "export", "other"));
212  $this->export_fields_array[$r] = array(
213  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
214  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
215  's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
216  'f.rowid'=>"InvoiceId", 'f.facnumber'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer',
217  'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT",
218  'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus',
219  'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin',
220  'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
221  'fd.subprice'=>"LineUnitPrice", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.total_ht'=>"LineTotalHT", 'fd.total_tva'=>"LineTotalVAT",
222  'fd.total_ttc'=>"LineTotalTTC", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
223  'fd.product_type'=>"TypeOfLineServiceOrProduct", 'fd.fk_product'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel',
224  'p.accountancy_code_sell'=>'ProductAccountancySellCode'
225  );
226  if (! empty($conf->multicurrency->enabled))
227  {
228  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
229  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
230  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
231  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
232  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
233  }
234  $this->export_TypeFields_array[$r] = array(
235  's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text',
236  's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
237  'f.rowid'=>'Numeric', 'f.facnumber'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date",
238  'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>"NumericCompute", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Numeric',
239  'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text',
240  'pj.ref'=>'Text', 'fd.rowid'=>'Numeric', 'fd.label'=>'Text', 'fd.description'=>"Text", 'fd.subprice'=>"Numeric", 'fd.tva_tx'=>"Numeric",
241  'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_tva'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date",
242  'fd.special_code'=>'Numeric', 'fd.product_type'=>"Numeric", 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text',
243  'p.accountancy_code_sell'=>'Text'
244  );
245  $this->export_entities_array[$r] = array(
246  's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
247  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company',
248  's.tva_intra'=>'company', 'pj.ref'=>'project', 'fd.rowid'=>'invoice_line', 'fd.label'=>"invoice_line", 'fd.description'=>"invoice_line",
249  'fd.subprice'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva_tx'=>"invoice_line",
250  'fd.qty'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>'invoice_line',
251  'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_sell'=>'product',
252  'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user'
253  );
254  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
255  $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
256  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
257  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
258  $keyforselect = 'facturedet'; $keyforelement = 'invoice_line'; $keyforaliasextra = 'extra2';
259  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
260  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3';
261  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
262  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
263  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
264  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';
265  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
266  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
267  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
268  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
269  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
270  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
271  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
272  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
273  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
274  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
275  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
276  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('facture').')';
277  if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id;
278  $r++;
279 
280  $this->export_code[$r] = $this->rights_class.'_'.$r;
281  $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
282  $this->export_icon[$r] = 'invoice';
283  $this->export_permission[$r] = array(array("facture", "facture", "export"));
284  $this->export_fields_array[$r] = array(
285  's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
286  's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
287  's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
288  'f.rowid'=>"InvoiceId", 'f.facnumber'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer',
289  'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT",
290  'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus',
291  'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin',
292  'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'p.rowid'=>'PaymentId', 'p.ref'=>'PaymentRef',
293  'p.amount'=>'AmountPayment', 'pf.amount'=>'AmountPaymentDistributedOnInvoice', 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber',
294  'pt.code'=>'CodePaymentMode', 'pt.libelle'=>'LabelPaymentMode', 'p.note'=>'PaymentNote', 'p.fk_bank'=>'IdTransaction', 'ba.ref'=>'AccountRef'
295  );
296  if (! empty($conf->multicurrency->enabled))
297  {
298  $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
299  $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
300  $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
301  $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
302  $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
303  }
304  $this->export_TypeFields_array[$r] = array(
305  's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text',
306  's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
307  'f.rowid'=>"Numeric", 'f.facnumber'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date",
308  'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>'NumericCompute', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status',
309  'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text',
310  'pj.ref'=>'Text', 'p.amount'=>'Numeric', 'pf.amount'=>'Numeric', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric',
311  'p.fk_bank'=>'Numeric', 'p.note'=>'Text', 'pt.code'=>'Text', 'pt.libelle'=>'text', 'ba.ref'=>'Text'
312  );
313  $this->export_entities_array[$r] = array(
314  's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
315  's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company',
316  's.tva_intra'=>'company', 'pj.ref'=>'project', 'p.rowid'=>'payment', 'p.ref'=>'payment', 'p.amount'=>'payment', 'pf.amount'=>'payment', 'p.datep'=>'payment',
317  'p.num_paiement'=>'payment', 'pt.code'=>'payment', 'pt.libelle'=>'payment', 'p.note'=>'payment', 'f.fk_user_author'=>'user', 'uc.login'=>'user',
318  'f.fk_user_valid'=>'user', 'uv.login'=>'user', 'p.fk_bank'=>'account', 'ba.ref'=>'account'
319  );
320  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
321  $this->export_dependencies_array[$r] = array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
322  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
323  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
324  $this->export_sql_start[$r]='SELECT DISTINCT ';
325  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
326  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';
327  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
328  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f';
329  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
330  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
331  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
332  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
333  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
334  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
335  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement';
336  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
337  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
338  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
339  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture').')';
340  if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
341  $r++;
342  }
343 
344 
353  function init($options = '')
354  {
355  global $conf, $langs;
356 
357  // Remove permissions and default values
358  $this->remove($options);
359 
360  //ODT template
361  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
362  $dirodt = DOL_DATA_ROOT.'/doctemplates/invoices';
363  $dest = $dirodt.'/template_invoice.odt';
364 
365  if (file_exists($src) && !file_exists($dest))
366  {
367  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
368  dol_mkdir($dirodt);
369  $result = dol_copy($src, $dest, 0, 0);
370  if ($result < 0)
371  {
372  $langs->load("errors");
373  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
374  return 0;
375  }
376  }
377 
378  $sql = array(
379  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".$conf->entity,
380  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".$conf->entity.")"
381  );
382 
383  return $this->_init($sql, $options);
384  }
385 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
Class DolibarrModules.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
__construct($db)
Constructor.
dol_now($mode='gmt')
Return date for now.
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
Class to describe module customer invoices.
init($options='')
Function called when module is enabled.