31 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
52 $this->family =
"financial";
53 $this->module_position =
'11';
55 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
59 $this->version =
'dolibarr';
61 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
62 $this->picto =
'bill';
65 $this->dirs = array(
"/facture/temp");
68 $this->depends = array(
'always'=>
"modSociete");
69 $this->requiredby = array(
"modComptabilite",
"modAccounting");
70 $this->conflictwith = array();
71 $this->langfiles = array(
"bills",
"companies",
"compta",
"products");
72 $this->warnings_activation = array();
73 $this->warnings_activation_ext = array();
76 $this->config_page_url = array(
"facture.php");
79 $this->
const = array();
82 $this->
const[$r][0] =
"FACTURE_ADDON";
83 $this->
const[$r][1] =
"chaine";
84 $this->
const[$r][2] =
"mod_facture_terre";
85 $this->
const[$r][3] =
'Name of numbering numerotation rules of invoice';
86 $this->
const[$r][4] = 0;
89 $this->
const[$r][0] =
"FACTURE_ADDON_PDF";
90 $this->
const[$r][1] =
"chaine";
91 $this->
const[$r][2] =
"sponge";
92 $this->
const[$r][3] =
'Name of PDF model of invoice';
93 $this->
const[$r][4] = 0;
96 $this->
const[$r][0] =
"FACTURE_ADDON_PDF_ODT_PATH";
97 $this->
const[$r][1] =
"chaine";
98 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/invoices";
99 $this->
const[$r][3] =
"";
100 $this->
const[$r][4] = 0;
105 $this->boxes = array(
106 0=>array(
'file'=>
'box_factures_imp.php',
'enabledbydefaulton'=>
'Home'),
107 1=>array(
'file'=>
'box_factures.php',
'enabledbydefaulton'=>
'Home'),
108 2=>array(
'file'=>
'box_graph_invoices_permonth.php',
'enabledbydefaulton'=>
'Home'),
109 3=>array(
'file'=>
'box_customers_outstanding_bill_reached.php',
'enabledbydefaulton'=>
'Home')
114 $datestart =
dol_mktime(23, 0, 0, $arraydate[
'mon'], $arraydate[
'mday'], $arraydate[
'year']);
115 $this->cronjobs = array(
117 'label'=>
'RecurringInvoicesJob',
119 'class'=>
'compta/facture/class/facture-rec.class.php',
120 'objectname'=>
'FactureRec',
121 'method'=>
'createRecurringInvoices',
123 'comment'=>
'Generate recurring invoices',
125 'unitfrequency'=>3600 * 24,
128 'test'=>
'$conf->facture->enabled',
129 'datestart'=>$datestart
132 'label'=>
'SendEmailsRemindersOnInvoiceDueDate',
134 'class'=>
'compta/facture/class/facture.class.php',
135 'objectname'=>
'Facture',
136 'method'=>
'sendEmailsRemindersOnInvoiceDueDate',
137 'parameters'=>
"10,all,EmailTemplateCode",
138 'comment'=>
'Send an emails when the unpaid invoices reach a due date + n days = today. First param is the offset n of days, second parameter is "all" or a payment mode code, last parameter is the code of email template to use (an email template with EmailTemplateCode must exists. The version in the language of the thirdparty will be used in priority to update the PDF of the sent invoice).',
140 'unitfrequency'=>3600 * 24,
143 'test'=>
'$conf->facture->enabled',
144 'datestart'=>$datestart
149 $this->rights = array();
150 $this->rights_class =
'facture';
154 $this->rights[$r][0] = 11;
155 $this->rights[$r][1] =
'Read invoices';
156 $this->rights[$r][2] =
'a';
157 $this->rights[$r][3] = 0;
158 $this->rights[$r][4] =
'lire';
161 $this->rights[$r][0] = 12;
162 $this->rights[$r][1] =
'Create and update invoices';
163 $this->rights[$r][2] =
'a';
164 $this->rights[$r][3] = 0;
165 $this->rights[$r][4] =
'creer';
169 $this->rights[$r][0] = 13;
170 $this->rights[$r][1] =
'Devalidate invoices';
171 $this->rights[$r][2] =
'a';
172 $this->rights[$r][3] = 0;
173 $this->rights[$r][4] =
'invoice_advance';
174 $this->rights[$r][5] =
'unvalidate';
177 $this->rights[$r][0] = 14;
178 $this->rights[$r][1] =
'Validate invoices';
179 $this->rights[$r][2] =
'a';
180 $this->rights[$r][3] = 0;
181 $this->rights[$r][4] =
'invoice_advance';
182 $this->rights[$r][5] =
'validate';
185 $this->rights[$r][0] = 15;
186 $this->rights[$r][1] =
'Send invoices by email';
187 $this->rights[$r][2] =
'a';
188 $this->rights[$r][3] = 0;
189 $this->rights[$r][4] =
'invoice_advance';
190 $this->rights[$r][5] =
'send';
193 $this->rights[$r][0] = 16;
194 $this->rights[$r][1] =
'Issue payments on invoices';
195 $this->rights[$r][2] =
'a';
196 $this->rights[$r][3] = 0;
197 $this->rights[$r][4] =
'paiement';
200 $this->rights[$r][0] = 19;
201 $this->rights[$r][1] =
'Delete invoices';
202 $this->rights[$r][2] =
'a';
203 $this->rights[$r][3] = 0;
204 $this->rights[$r][4] =
'supprimer';
207 $this->rights[$r][0] = 1321;
208 $this->rights[$r][1] =
'Export customer invoices, attributes and payments';
209 $this->rights[$r][2] =
'r';
210 $this->rights[$r][3] = 0;
211 $this->rights[$r][4] =
'facture';
212 $this->rights[$r][5] =
'export';
215 $this->rights[$r][0] = 1322;
216 $this->rights[$r][1] =
'Re-open a fully paid invoice';
217 $this->rights[$r][2] =
'r';
218 $this->rights[$r][3] = 0;
219 $this->rights[$r][4] =
'invoice_advance';
220 $this->rights[$r][5] =
'reopen';
233 $this->import_code[$r] = $this->rights_class.
'_'.$r;
234 $this->import_label[$r] =
"Invoices";
235 $this->import_icon[$r] = $this->picto;
236 $this->import_entities_array[$r] = array();
237 $this->import_tables_array[$r] = array(
'f' => MAIN_DB_PREFIX.
'facture',
'extra' => MAIN_DB_PREFIX.
'facture_extrafields');
238 $this->import_tables_creator_array[$r] = array(
'f' =>
'fk_user_author');
239 $this->import_fields_array[$r] = array(
240 'f.ref' =>
'InvoiceRef*',
241 'f.ref_ext' =>
'ExternalRef',
242 'f.ref_client' =>
'CustomerRef',
244 'f.fk_soc' =>
'Customer*',
245 'f.datec' =>
'InvoiceDateCreation',
246 'f.datef' =>
'DateInvoice',
247 'f.date_valid' =>
'Validation Date',
248 'f.paye' =>
'InvoicePaid',
249 'f.remise_percent' =>
'RemisePercent',
250 'f.remise_absolue' =>
'RemiseAbsolue',
251 'f.remise' =>
'Remise',
252 'f.total_tva' =>
'TotalVAT',
253 'f.total_ht' =>
'TotalHT',
254 'f.total_ttc' =>
'TotalTTC',
255 'f.fk_statut' =>
'InvoiceStatus',
256 'f.fk_user_modif' =>
'Modifier Id',
257 'f.fk_user_valid' =>
'Validator Id',
258 'f.fk_user_closing' =>
'Closer Id',
259 'f.fk_facture_source' =>
'Invoice Source Id',
260 'f.fk_projet' =>
'Project Id',
261 'f.fk_account' =>
'Bank Account',
262 'f.fk_currency' =>
'Currency*',
263 'f.fk_cond_reglement' =>
'Payment Condition',
264 'f.fk_mode_reglement' =>
'Payment Mode',
265 'f.date_lim_reglement' =>
'DateMaxPayment',
266 'f.note_public' =>
'InvoiceNote',
267 'f.note_private' =>
'NotePrivate',
268 'f.model_pdf' =>
'Model'
271 $this->import_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
272 $this->import_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
273 $this->import_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
274 $this->import_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
275 $this->import_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
278 $import_extrafield_sample = array();
279 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture' AND entity IN (0, ".$conf->entity.
")";
282 while ($obj = $this->
db->fetch_object(
$resql)) {
283 $fieldname =
'extra.'.$obj->name;
284 $fieldlabel = ucfirst($obj->label);
285 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
286 $import_extrafield_sample[$fieldname] = $fieldlabel;
290 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facture');
291 $this->import_regex_array[$r] = array(
'f.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency');
292 $import_sample = array(
293 'f.ref' =>
'(PROV0001)',
295 'f.ref_client' =>
'',
297 'f.fk_soc' =>
'80LIMIT',
298 'f.datec' =>
'2021-11-24',
299 'f.datef' =>
'2021-11-24',
300 'f.date_valid' =>
'2021-11-24',
302 'f.remise_percent' =>
'0',
303 'f.remise_absolue' =>
'0',
305 'f.total_tva' =>
'21',
306 'f.total_ht' =>
'100',
307 'f.total_ttc' =>
'121',
308 'f.fk_statut' =>
'1',
309 'f.fk_user_modif' =>
'',
310 'f.fk_user_valid' =>
'',
311 'f.fk_user_closing' =>
'',
312 'f.fk_facture_source' =>
'',
314 'f.fk_account' =>
'',
315 'f.fk_currency' =>
'EUR',
316 'f.fk_cond_reglement' =>
'30D',
317 'f.fk_mode_reglement' =>
'VIR',
318 'f.date_lim_reglement' =>
'2021-12-24',
319 'f.note_public' =>
'',
320 'f.note_private' =>
'',
321 'f.model_pdf' =>
'crabe',
322 'f.multicurrency_code' =>
'EUR',
323 'f.multicurrency_tx' =>
'1',
324 'f.multicurrency_total_ht' =>
'100',
325 'f.multicurrency_total_tva' =>
'21',
326 'f.multicurrency_total_ttc' =>
'121'
328 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
329 $this->import_updatekeys_array[$r] = array(
'f.ref' =>
'Ref');
330 $this->import_convertvalue_array[$r] = array(
332 'rule' =>
'fetchidfromref',
333 'file' =>
'/societe/class/societe.class.php',
334 'class' =>
'Societe',
336 'element' =>
'ThirdParty'
338 'f.fk_projet' => array(
339 'rule' =>
'fetchidfromref',
340 'file' =>
'/projet/class/project.class.php',
341 'class' =>
'Project',
343 'element' =>
'facture'
345 'f.fk_cond_reglement' => array(
346 'rule' =>
'fetchidfromcodeorlabel',
347 'file' =>
'/compta/facture/class/paymentterm.class.php',
348 'class' =>
'PaymentTerm',
350 'element' =>
'c_payment_term'
356 $this->import_code[$r] = $this->rights_class.
'_'.$r;
357 $this->import_label[$r] =
"InvoiceLine";
358 $this->import_icon[$r] = $this->picto;
359 $this->import_entities_array[$r] = array();
360 $this->import_tables_array[$r] = array(
'fd' => MAIN_DB_PREFIX.
'facturedet',
'extra' => MAIN_DB_PREFIX.
'facturedet_extrafields');
361 $this->import_fields_array[$r] = array(
362 'fd.fk_facture' =>
'InvoiceRef*',
363 'fd.fk_parent_line' =>
'FacParentLine',
364 'fd.fk_product' =>
'IdProduct',
365 'fd.label' =>
'Label',
366 'fd.description' =>
'LineDescription*',
367 'fd.vat_src_code' =>
'Vat Source Code',
368 'fd.tva_tx' =>
'LineVATRate*',
373 'fd.qty' =>
'LineQty',
374 'fd.remise_percent' =>
'Reduc. (%)',
379 'fd.total_ht' =>
'LineTotalHT',
380 'fd.total_tva' =>
'LineTotalVAT',
383 'fd.total_ttc' =>
'LineTotalTTC',
384 'fd.product_type' =>
'TypeOfLineServiceOrProduct',
385 'fd.date_start' =>
'Start Date',
386 'fd.date_end' =>
'End Date',
393 'fd.fk_unit' =>
'Unit',
402 $this->import_fields_array[$r][
'fd.multicurrency_code'] =
'Currency';
403 $this->import_fields_array[$r][
'fd.multicurrency_subprice'] =
'CurrencyRate';
404 $this->import_fields_array[$r][
'fd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
405 $this->import_fields_array[$r][
'fd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
406 $this->import_fields_array[$r][
'fd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
409 $import_extrafield_sample = array();
410 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture_det' AND entity IN (0, ".$conf->entity.
")";
413 while ($obj = $this->
db->fetch_object(
$resql)) {
414 $fieldname =
'extra.'.$obj->name;
415 $fieldlabel = ucfirst($obj->label);
416 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
417 $import_extrafield_sample[$fieldname] = $fieldlabel;
421 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facturedet');
422 $this->import_regex_array[$r] = array(
423 'fd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
424 'fd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
426 $import_sample = array(
427 'fd.fk_facture' =>
'(PROV00001)',
428 'fd.fk_parent_line' =>
'',
429 'fd.fk_product' =>
'',
431 'fd.description' =>
'Test product',
432 'fd.vat_src_code' =>
'',
439 'fd.remise_percent' =>
'0',
444 'fd.total_ht' =>
'100',
445 'fd.total_tva' =>
'21',
448 'fd.total_ttc' =>
'121',
449 'fd.product_type' =>
'0',
450 'fd.date_start' =>
'',
465 'fd.multicurrency_code' =>
'EUR',
466 'fd.multicurrency_tx' =>
'21',
467 'fd.multicurrency_total_ht' =>
'100',
468 'fd.multicurrency_total_tva' =>
'21',
469 'fd.multicurrency_total_ttc' =>
'121'
471 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
472 $this->import_updatekeys_array[$r] = array(
473 'fd.rowid' =>
'Row Id',
474 'fd.fk_facture' =>
'Invoice Id'
476 $this->import_convertvalue_array[$r] = array(
477 'fd.fk_facture' => array(
478 'rule' =>
'fetchidfromref',
479 'file' =>
'/compta/facture/class/facture.class.php',
480 'class' =>
'Facture',
482 'element' =>
'facture'
484 'fd.fk_projet' => array(
485 'rule' =>
'fetchidfromref',
486 'file' =>
'/projet/class/project.class.php',
487 'class' =>
'Project',
489 'element' =>
'facture'
498 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
500 $this->export_code[$r] = $this->rights_class.
'_'.$r;
501 $this->export_label[$r] =
'CustomersInvoicesAndInvoiceLines';
502 $this->export_icon[$r] =
'invoice';
503 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export",
"other"));
505 $this->export_fields_array[$r] = array(
506 's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
'ps.nom' =>
'ParentCompany',
's.code_client'=>
'CustomerCode',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'c.code'=>
'CountryCode',
'cd.nom'=>
'State',
508 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
509 's.code_compta'=>
'CustomerAccountancyCode',
510 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
511 's.tva_intra'=>
'VATIntra',
512 't.libelle'=>
"ThirdPartyType",
513 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
514 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
'f.total_ht'=>
"TotalHT",
515 'f.total_ttc'=>
"TotalTTC",
'f.total_tva'=>
"TotalVAT",
'f.localtax1'=>
'LT1',
'f.localtax2'=>
'LT2',
'f.paye'=>
"InvoicePaidCompletely",
'f.fk_statut'=>
'InvoiceStatus',
'f.close_code'=>
'EarlyClosingReason',
'f.close_note'=>
'EarlyClosingComment',
517 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic"
521 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
522 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
523 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
524 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
525 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
528 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
529 $this->export_fields_array[$r][
'f.module_source'] =
'Module';
530 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
532 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
533 'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
534 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
535 'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel'
538 if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
539 $nbofallowedentities = count(explode(
',',
getEntity(
'invoice')));
540 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
541 $this->export_fields_array[$r][
'f.entity'] =
'Entity';
544 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
545 'fd.rowid'=>
'LineId',
'fd.description'=>
"LineDescription",
546 'fd.subprice'=>
"LineUnitPrice",
'fd.tva_tx'=>
"LineVATRate",
'fd.qty'=>
"LineQty",
'fd.total_ht'=>
"LineTotalHT",
'fd.total_tva'=>
"LineTotalVAT",
547 'fd.total_ttc'=>
"LineTotalTTC",
'fd.date_start'=>
"DateStart",
'fd.date_end'=>
"DateEnd",
'fd.special_code'=>
'SpecialCode',
548 'fd.product_type'=>
"TypeOfLineServiceOrProduct",
'fd.fk_product'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel',
549 $alias_product_perentity .
'.accountancy_code_sell'=>
'ProductAccountancySellCode',
550 'aa.account_number' =>
'AccountingAffectation'
552 $this->export_TypeFields_array[$r] = array(
553 's.rowid'=>
'Numeric',
's.nom'=>
'Text',
'ps.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',
554 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
556 'f.rowid'=>
'Numeric',
'f.ref'=>
"Text",
'f.ref_client'=>
'Text',
'f.type'=>
"Numeric",
'f.datec'=>
"Date",
'f.datef'=>
"Date",
'f.date_lim_reglement'=>
"Date",
'f.fk_mode_reglement'=>
'Numeric',
557 'f.total_ht'=>
"Numeric",
'f.total_ttc'=>
"Numeric",
'f.total_tva'=>
"Numeric",
'f.localtax1'=>
'Numeric',
'f.localtax2'=>
'Numeric',
'f.paye'=>
"Boolean",
'f.fk_statut'=>
'Numeric',
'f.close_code'=>
'Text',
'f.close_note'=>
'Text',
558 'none.rest'=>
"NumericCompute",
559 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
560 'f.module_source' =>
'Text',
561 'f.pos_source' =>
'Text',
562 'f.entity'=>
'List:entity:label:rowid',
563 'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
564 'pj.ref'=>
'Text',
'pj.title'=>
'Text',
'fd.rowid'=>
'Numeric',
'fd.description'=>
"Text",
'fd.subprice'=>
"Numeric",
'fd.tva_tx'=>
"Numeric",
565 'fd.qty'=>
"Numeric",
'fd.total_ht'=>
"Numeric",
'fd.total_tva'=>
"Numeric",
'fd.total_ttc'=>
"Numeric",
'fd.date_start'=>
"Date",
'fd.date_end'=>
"Date",
566 'fd.special_code'=>
'Numeric',
'fd.product_type'=>
"Numeric",
'fd.fk_product'=>
'List:product:label',
'p.ref'=>
'Text',
'p.label'=>
'Text',
567 $alias_product_perentity .
'.accountancy_code_sell'=>
'Text',
568 'aa.account_number' =>
'Text'
570 $this->export_entities_array[$r] = array(
571 's.rowid'=>
"company",
's.nom'=>
'company',
'ps.nom'=>
'company',
's.code_client'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
's.town'=>
'company',
'c.code'=>
'company',
'cd.nom'=>
'company',
's.phone'=>
'company',
572 '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',
573 't.libelle'=>
'company',
574 'pj.ref'=>
'project',
'pj.title'=>
'project',
'fd.rowid'=>
'invoice_line',
'fd.description'=>
"invoice_line",
575 'fd.subprice'=>
"invoice_line",
'fd.total_ht'=>
"invoice_line",
'fd.total_tva'=>
"invoice_line",
'fd.total_ttc'=>
"invoice_line",
'fd.tva_tx'=>
"invoice_line",
576 'fd.qty'=>
"invoice_line",
'fd.date_start'=>
"invoice_line",
'fd.date_end'=>
"invoice_line",
'fd.special_code'=>
'invoice_line',
577 'fd.product_type'=>
'invoice_line',
'fd.fk_product'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product', $alias_product_perentity .
'.accountancy_code_sell'=>
'product',
578 'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
579 'aa.account_number' =>
"invoice_line",
581 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
582 $this->export_dependencies_array[$r] = array(
'invoice_line'=>
'fd.rowid',
'product'=>
'fd.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
583 $keyforselect =
'facture';
584 $keyforelement =
'invoice';
585 $keyforaliasextra =
'extra';
586 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
587 $keyforselect =
'facturedet';
588 $keyforelement =
'invoice_line';
589 $keyforaliasextra =
'extra2';
590 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
591 $keyforselect =
'product';
592 $keyforelement =
'product';
593 $keyforaliasextra =
'extra3';
594 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
595 $keyforselect =
'societe';
596 $keyforelement =
'company';
597 $keyforaliasextra =
'extra4';
598 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
599 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
600 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
601 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
602 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
603 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as t ON s.fk_typent = t.id';
604 if (empty($user->rights->societe->client->voir)) {
605 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
607 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
608 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
609 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
610 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
611 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
612 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
613 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
614 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'facturedet as fd';
615 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
616 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (fd.fk_product = p.rowid)';
617 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
618 $this->export_sql_end[$r] .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
620 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
621 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
622 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
623 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
624 if (empty($user->rights->societe->client->voir)) {
625 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
630 $this->export_code[$r] = $this->rights_class.
'_'.$r;
631 $this->export_label[$r] =
'CustomersInvoicesAndPayments';
632 $this->export_icon[$r] =
'invoice';
633 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export"));
634 $this->export_fields_array[$r] = array(
635 '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',
637 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
's.code_compta'=>
'CustomerAccountancyCode',
638 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
's.tva_intra'=>
'VATIntra',
639 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
640 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
'f.total_ht'=>
"TotalHT",
641 'f.total_ttc'=>
"TotalTTC",
'f.total_tva'=>
"TotalVAT",
'f.localtax1'=>
'LT1',
'f.localtax2'=>
'LT2',
'f.paye'=>
"InvoicePaidCompletely",
'f.fk_statut'=>
'InvoiceStatus',
'f.close_code'=>
'EarlyClosingReason',
'f.close_note'=>
'EarlyClosingComment',
643 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic",
'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
644 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel',
'p.rowid'=>
'PaymentId',
'p.ref'=>
'PaymentRef',
645 'p.amount'=>
'AmountPayment',
'pf.amount'=>
'AmountPaymentDistributedOnInvoice',
'p.datep'=>
'DatePayment',
'p.num_paiement'=>
'PaymentNumber',
646 'pt.code'=>
'CodePaymentMode',
'pt.libelle'=>
'LabelPaymentMode',
'p.note'=>
'PaymentNote',
'p.fk_bank'=>
'IdTransaction',
'ba.ref'=>
'AccountRef'
648 $this->export_help_array[$r] = array(
'f.paye'=>
'InvoicePaidCompletelyHelp');
650 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
651 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
652 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
653 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
654 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
655 $this->export_examplevalues_array[$r][
'f.multicurrency_code'] =
'EUR';
657 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
658 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
659 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
661 $this->export_TypeFields_array[$r] = array(
662 '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',
663 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
664 'f.rowid'=>
"Numeric",
'f.ref'=>
"Text",
'f.ref_client'=>
'Text',
'f.type'=>
"Numeric",
'f.datec'=>
"Date",
'f.datef'=>
"Date",
'f.date_lim_reglement'=>
"Date",
665 'f.total_ht'=>
"Numeric",
'f.total_ttc'=>
"Numeric",
'f.total_tva'=>
"Numeric",
'f.localtax1'=>
'Numeric',
'f.localtax2'=>
'Numeric',
'f.paye'=>
"Boolean",
'f.fk_statut'=>
'Status',
'f.close_code'=>
'Text',
'f.close_note'=>
'Text',
666 'none.rest'=>
'NumericCompute',
667 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
668 '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',
669 'p.fk_bank'=>
'Numeric',
'p.note'=>
'Text',
'pt.code'=>
'Text',
'pt.libelle'=>
'text',
'ba.ref'=>
'Text'
671 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
672 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
673 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
675 $this->export_entities_array[$r] = array(
676 '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',
677 's.siren'=>
'company',
's.siret'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.code_compta'=>
'company',
's.code_compta_fournisseur'=>
'company',
678 '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',
679 'p.num_paiement'=>
'payment',
'pt.code'=>
'payment',
'pt.libelle'=>
'payment',
'p.note'=>
'payment',
'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
680 'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
'p.fk_bank'=>
'account',
'ba.ref'=>
'account'
682 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
683 $this->export_dependencies_array[$r] = array(
'payment'=>
'p.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
684 $keyforselect =
'facture';
685 $keyforelement =
'invoice';
686 $keyforaliasextra =
'extra';
687 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
688 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
689 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
690 if (empty($user->rights->societe->client->voir)) {
691 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
693 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
694 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
695 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
696 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
697 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
698 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
699 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
700 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement_facture as pf ON pf.fk_facture = f.rowid';
701 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement as p ON pf.fk_paiement = p.rowid';
702 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as pt ON pt.id = p.fk_paiement';
703 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON b.rowid = p.fk_bank';
704 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON ba.rowid = b.fk_account';
705 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid';
706 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
707 if (empty($user->rights->societe->client->voir)) {
708 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
722 public function init($options =
'')
724 global $conf, $langs;
727 $this->
remove($options);
730 $src = DOL_DOCUMENT_ROOT.
'/install/doctemplates/invoices/template_invoice.odt';
731 $dirodt = DOL_DATA_ROOT.
'/doctemplates/invoices';
732 $dest = $dirodt.
'/template_invoice.odt';
734 if (file_exists($src) && !file_exists($dest)) {
735 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
737 $result =
dol_copy($src, $dest, 0, 0);
739 $langs->load(
"errors");
740 $this->error = $langs->trans(
'ErrorFailToCopyFile', $src, $dest);
746 "DELETE FROM ".MAIN_DB_PREFIX.
"document_model WHERE nom = '".$this->db->escape($this->const[1][2]).
"' AND type = 'invoice' AND entity = ".((
int) $conf->entity),
747 "INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2]).
"','invoice',".((
int) $conf->entity).
")"
750 return $this->
_init($sql, $options);
_init($array_sql, $options='')
Enables a module.
Class to describe module customer invoices.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
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...
dol_now($mode='auto')
Return date for now.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.