dolibarr  7.0.0-beta
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-2013 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@capnetworks.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->special = 0;
61  $this->picto = 'bill';
62 
63  // Data directories to create when module is enabled
64  $this->dirs = array("/facture/temp");
65 
66  // Dependencies
67  $this->depends = array('always'=>"modSociete");
68  $this->requiredby = array("modComptabilite", "modAccounting");
69  $this->conflictwith = array();
70  $this->langfiles = array("bills", "companies", "compta", "products");
71  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='text')
72  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text')
73 
74  // Config pages
75  $this->config_page_url = array("facture.php");
76 
77  // Constants
78  $this->const = array();
79  $r = 0;
80 
81  $this->const[$r][0] = "FACTURE_ADDON";
82  $this->const[$r][1] = "chaine";
83  $this->const[$r][2] = "mod_facture_terre";
84  $this->const[$r][3] = 'Name of numbering numerotation rules of invoice';
85  $this->const[$r][4] = 0;
86  $r++;
87 
88  $this->const[$r][0] = "FACTURE_ADDON_PDF";
89  $this->const[$r][1] = "chaine";
90  $this->const[$r][2] = "crabe";
91  $this->const[$r][3] = 'Name of PDF model of invoice';
92  $this->const[$r][4] = 0;
93  $r++;
94 
95  $this->const[$r][0] = "FACTURE_ADDON_PDF_ODT_PATH";
96  $this->const[$r][1] = "chaine";
97  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/invoices";
98  $this->const[$r][3] = "";
99  $this->const[$r][4] = 0;
100  $r++;
101 
102  /*$this->const[$r][0] = "FACTURE_DRAFT_WATERMARK";
103  $this->const[$r][1] = "chaine";
104  $this->const[$r][2] = "__(Draft)__";
105  $this->const[$r][3] = 'Watermark to show on draft invoices';
106  $this->const[$r][4] = 0;
107  $r++;*/
108 
109 
110  // Boxes
111  //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php'));
112  $this->boxes = array(
113  0=>array('file'=>'box_factures_imp.php', 'enabledbydefaulton'=>'Home'),
114  1=>array('file'=>'box_factures.php', 'enabledbydefaulton'=>'Home'),
115  2=>array('file'=>'box_graph_invoices_permonth.php', 'enabledbydefaulton'=>'Home')
116  );
117 
118  // Cronjobs
119  $this->cronjobs = array(
120  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'=>true),
121  // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
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('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', 'f.rowid'=>"InvoiceId", 'f.facnumber'=>"InvoiceRef", 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.subprice'=>"LineUnitPrice", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.total_ht'=>"LineTotalHT", 'fd.total_tva'=>"LineTotalVAT", 'fd.total_ttc'=>"LineTotalTTC", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode', 'fd.product_type'=>"TypeOfLineServiceOrProduct", 'fd.fk_product'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.accountancy_code_sell'=>'ProductAccountancySellCode');
213  $this->export_TypeFields_array[$r] = array('s.rowid'=>'Numeric', 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.rowid'=>'Numeric', 'f.facnumber'=>"Text", 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>"NumericCompute", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Numeric', 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', 'pj.ref'=>'Text', 'fd.rowid'=>'Numeric', 'fd.label'=>'Text', 'fd.description'=>"Text", 'fd.subprice'=>"Numeric", 'fd.tva_tx'=>"Numeric", 'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_tva'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>'Numeric', 'fd.product_type'=>"Numeric", 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text', 'p.accountancy_code_sell'=>'Text');
214  $this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'pj.ref'=>'project', 'fd.rowid'=>'invoice_line', 'fd.label'=>"invoice_line", 'fd.description'=>"invoice_line", 'fd.subprice'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva_tx'=>"invoice_line", 'fd.qty'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>'invoice_line', 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_sell'=>'product', 'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user');
215  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
216  $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
217  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
218  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
219  $keyforselect = 'facturedet'; $keyforelement = 'invoice_line'; $keyforaliasextra = 'extra2';
220  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
221  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3';
222  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
223  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
224  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
225  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';
226  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
227  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f';
228  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
229  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
230  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
231  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
232  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd';
233  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
234  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
235  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
236  $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
237  $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('facture').')';
238  if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id;
239  $r++;
240 
241  $this->export_code[$r] = $this->rights_class.'_'.$r;
242  $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found)
243  $this->export_icon[$r] = 'invoice';
244  $this->export_permission[$r] = array(array("facture", "facture", "export"));
245  $this->export_fields_array[$r] = array('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', 'f.rowid'=>"InvoiceId", 'f.facnumber'=>"InvoiceRef", 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'p.rowid'=>'PaymentId', 'p.ref'=>'PaymentRef', 'p.amount'=>'AmountPayment', 'pf.amount'=>'AmountPaymentDistributedOnInvoice', 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'pt.code'=>'CodePaymentMode', 'pt.libelle'=>'LabelPaymentMode', 'p.note'=>'PaymentNote', 'p.fk_bank'=>'IdTransaction', 'ba.ref'=>'AccountRef');
246  $this->export_TypeFields_array[$r] = array('s.rowid'=>'Numeric', 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.rowid'=>"Numeric", 'f.facnumber'=>"Text", 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>'NumericCompute', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', 'pj.ref'=>'Text', 'p.amount'=>'Numeric', 'pf.amount'=>'Numeric', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'p.note'=>'Text', 'pt.code'=>'Text', 'pt.libelle'=>'text', 'ba.ref'=>'Text');
247  $this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'pj.ref'=>'project', 'p.rowid'=>'payment', 'p.ref'=>'payment', 'p.amount'=>'payment', 'pf.amount'=>'payment', 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'pt.code'=>'payment', 'pt.libelle'=>'payment', 'p.note'=>'payment', 'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user', 'p.fk_bank'=>'account', 'ba.ref'=>'account');
248  $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay');
249  $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
250  $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra';
251  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
252  $this->export_sql_start[$r]='SELECT DISTINCT ';
253  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
254  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';
255  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
256  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f';
257  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
258  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid';
259  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid';
260  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object';
261  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
262  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid';
263  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement AND pt.entity IN ('.getEntity('c_paiement').')';
264  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank';
265  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account';
266  $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid';
267  $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture').')';
268  if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
269  $r++;
270  }
271 
272 
281  function init($options = '')
282  {
283  global $conf, $langs;
284 
285  // Remove permissions and default values
286  $this->remove($options);
287 
288  //ODT template
289  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt';
290  $dirodt = DOL_DATA_ROOT.'/doctemplates/invoices';
291  $dest = $dirodt.'/template_invoice.odt';
292 
293  if (file_exists($src) && !file_exists($dest))
294  {
295  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
296  dol_mkdir($dirodt);
297  $result = dol_copy($src, $dest, 0, 0);
298  if ($result < 0)
299  {
300  $langs->load("errors");
301  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
302  return 0;
303  }
304  }
305 
306  $sql = array(
307  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".$conf->entity,
308  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".$conf->entity.")"
309  );
310 
311  return $this->_init($sql, $options);
312  }
313 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></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:554
init($options= '')
Function called when module is enabled.
__construct($db)
Constructor.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to describe module customer invoices.