47 global $conf, $langs, $user, $mysoc;
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(
"invoice.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,duedate",
138 'comment'=>
'Send an email when we reach the invoice due date (or invoice date) - n days. First param is n, the number of days before due date (or invoice date) to send the remind (or after if value is negative), second parameter is "all" or a payment mode code, third parameter is the code of the email template to use (an email template with the EmailTemplateCode must exists. The version of the email template in the language of the thirdparty will be used in priority. Language of the thirdparty will be also used to update the PDF of the sent invoice). The fourth parameter is the string "duedate" (default) or "invoicedate" to define which date of the invoice to use.',
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' =>
'RefCustomer',
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.total_tva' =>
'TotalVAT',
250 'f.total_ht' =>
'TotalHT',
251 'f.total_ttc' =>
'TotalTTC',
252 'f.fk_statut' =>
'InvoiceStatus',
253 'f.fk_user_modif' =>
'Modifier Id',
254 'f.fk_user_valid' =>
'Validator Id',
255 'f.fk_user_closing' =>
'Closer Id',
256 'f.fk_facture_source' =>
'Invoice Source Id',
257 'f.fk_projet' =>
'Project Id',
258 'f.fk_account' =>
'Bank Account',
259 'f.fk_currency' =>
'Currency*',
260 'f.fk_cond_reglement' =>
'PaymentTerm',
261 'f.fk_mode_reglement' =>
'PaymentMode',
262 'f.date_lim_reglement' =>
'DateMaxPayment',
263 'f.note_public' =>
'InvoiceNote',
264 'f.note_private' =>
'NotePrivate',
265 'f.model_pdf' =>
'Model'
267 if (isModEnabled(
"multicurrency")) {
268 $this->import_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
269 $this->import_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
270 $this->import_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
271 $this->import_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
272 $this->import_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
275 $import_extrafield_sample = array();
276 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture' AND entity IN (0, ".$conf->entity.
")";
277 $resql = $this->db->query($sql);
279 while ($obj = $this->db->fetch_object($resql)) {
280 $fieldname =
'extra.'.$obj->name;
281 $fieldlabel = ucfirst($obj->label);
282 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
283 $import_extrafield_sample[$fieldname] = $fieldlabel;
287 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facture');
288 $this->import_regex_array[$r] = array(
'f.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency');
289 $import_sample = array(
290 'f.ref' =>
'(PROV0001)',
292 'f.ref_client' =>
'',
294 'f.fk_soc' =>
'80LIMIT',
295 'f.datec' =>
'2021-11-24',
296 'f.datef' =>
'2021-11-24',
297 'f.date_valid' =>
'2021-11-24',
299 'f.total_tva' =>
'21',
300 'f.total_ht' =>
'100',
301 'f.total_ttc' =>
'121',
302 'f.fk_statut' =>
'1',
303 'f.fk_user_modif' =>
'',
304 'f.fk_user_valid' =>
'',
305 'f.fk_user_closing' =>
'',
306 'f.fk_facture_source' =>
'',
308 'f.fk_account' =>
'',
309 'f.fk_currency' =>
'EUR',
310 'f.fk_cond_reglement' =>
'30D',
311 'f.fk_mode_reglement' =>
'VIR',
312 'f.date_lim_reglement' =>
'2021-12-24',
313 'f.note_public' =>
'',
314 'f.note_private' =>
'',
315 'f.model_pdf' =>
'sponge',
316 'f.multicurrency_code' =>
'EUR',
317 'f.multicurrency_tx' =>
'1',
318 'f.multicurrency_total_ht' =>
'100',
319 'f.multicurrency_total_tva' =>
'21',
320 'f.multicurrency_total_ttc' =>
'121'
322 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
323 $this->import_updatekeys_array[$r] = array(
'f.ref' =>
'Ref');
324 $this->import_convertvalue_array[$r] = array(
326 'rule' =>
'fetchidfromref',
327 'file' =>
'/societe/class/societe.class.php',
328 'class' =>
'Societe',
330 'element' =>
'ThirdParty'
332 'f.fk_projet' => array(
333 'rule' =>
'fetchidfromref',
334 'file' =>
'/projet/class/project.class.php',
335 'class' =>
'Project',
337 'element' =>
'facture'
339 'f.fk_cond_reglement' => array(
340 'rule' =>
'fetchidfromcodeorlabel',
341 'file' =>
'/compta/facture/class/paymentterm.class.php',
342 'class' =>
'PaymentTerm',
344 'element' =>
'c_payment_term'
350 $this->import_code[$r] = $this->rights_class.
'_'.$r;
351 $this->import_label[$r] =
"InvoiceLine";
352 $this->import_icon[$r] = $this->picto;
353 $this->import_entities_array[$r] = array();
354 $this->import_tables_array[$r] = array(
'fd' => MAIN_DB_PREFIX.
'facturedet',
'extra' => MAIN_DB_PREFIX.
'facturedet_extrafields');
355 $this->import_fields_array[$r] = array(
356 'fd.fk_facture' =>
'InvoiceRef*',
357 'fd.fk_parent_line' =>
'FacParentLine',
358 'fd.fk_product' =>
'IdProduct',
359 'fd.label' =>
'Label',
360 'fd.description' =>
'LineDescription*',
361 'fd.vat_src_code' =>
'Vat Source Code',
362 'fd.tva_tx' =>
'LineVATRate*',
367 'fd.qty' =>
'LineQty',
368 'fd.remise_percent' =>
'Reduc. (%)',
371 'fd.subprice' =>
'UnitPriceHT',
373 'fd.total_ht' =>
'LineTotalHT',
374 'fd.total_tva' =>
'LineTotalVAT',
377 'fd.total_ttc' =>
'LineTotalTTC',
378 'fd.product_type' =>
'TypeOfLineServiceOrProduct',
379 'fd.date_start' =>
'Start Date',
380 'fd.date_end' =>
'End Date',
387 'fd.fk_unit' =>
'Unit',
395 if (isModEnabled(
"multicurrency")) {
396 $this->import_fields_array[$r][
'fd.multicurrency_code'] =
'Currency';
397 $this->import_fields_array[$r][
'fd.multicurrency_subprice'] =
'CurrencyRate';
398 $this->import_fields_array[$r][
'fd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
399 $this->import_fields_array[$r][
'fd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
400 $this->import_fields_array[$r][
'fd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
403 $import_extrafield_sample = array();
404 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture_det' AND entity IN (0, ".$conf->entity.
")";
405 $resql = $this->db->query($sql);
407 while ($obj = $this->db->fetch_object($resql)) {
408 $fieldname =
'extra.'.$obj->name;
409 $fieldlabel = ucfirst($obj->label);
410 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
411 $import_extrafield_sample[$fieldname] = $fieldlabel;
415 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facturedet');
416 $this->import_regex_array[$r] = array(
417 'fd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
418 'fd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
420 $import_sample = array(
421 'fd.fk_facture' =>
'(PROV00001)',
422 'fd.fk_parent_line' =>
'',
423 'fd.fk_product' =>
'',
425 'fd.description' =>
'Test product',
426 'fd.vat_src_code' =>
'',
433 'fd.remise_percent' =>
'0',
436 'fd.subprice' =>
'100',
438 'fd.total_ht' =>
'100',
439 'fd.total_tva' =>
'21',
442 'fd.total_ttc' =>
'121',
443 'fd.product_type' =>
'0',
444 'fd.date_start' =>
'',
459 'fd.multicurrency_code' =>
'EUR',
460 'fd.multicurrency_tx' =>
'21',
461 'fd.multicurrency_total_ht' =>
'100',
462 'fd.multicurrency_total_tva' =>
'21',
463 'fd.multicurrency_total_ttc' =>
'121'
465 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
466 $this->import_updatekeys_array[$r] = array(
467 'fd.rowid' =>
'Row Id',
468 'fd.fk_facture' =>
'Invoice Id'
470 $this->import_convertvalue_array[$r] = array(
471 'fd.fk_facture' => array(
472 'rule' =>
'fetchidfromref',
473 'file' =>
'/compta/facture/class/facture.class.php',
474 'class' =>
'Facture',
476 'element' =>
'facture'
478 'fd.fk_projet' => array(
479 'rule' =>
'fetchidfromref',
480 'file' =>
'/projet/class/project.class.php',
481 'class' =>
'Project',
483 'element' =>
'facture'
490 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
491 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
495 $langs->loadLangs(array(
"suppliers",
"multicurrency",
"bills"));
497 $uselocaltax1 = $mysoc->localtax1_assuj ?? 0;
498 $uselocaltax2 = $mysoc->localtax2_assuj ?? 0;
500 $alias_product_perentity = !
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p" :
"ppe";
503 $this->export_code[$r] = $this->rights_class.
'_'.$r;
504 $this->export_label[$r] =
'CustomersInvoicesAndInvoiceLines';
505 $this->export_icon[$r] =
'invoice';
506 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export",
"other"));
508 $this->export_fields_array[$r] = array(
509 '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',
511 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
512 's.code_compta'=>
'CustomerAccountancyCode',
513 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
514 's.tva_intra'=>
'VATIntra',
515 't.libelle'=>
"ThirdPartyType",
516 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
'f.fk_facture_source'=>
'SourceInvoiceId',
517 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
518 'f.fk_cond_reglement'=>
'IdPaymentTerm',
'f.fk_mode_reglement'=>
'IdPaymentMode',
519 'f.total_ht'=>
"TotalHT",
'f.total_ttc'=>
"TotalTTC",
'f.total_tva'=>
"TotalVAT",
520 'f.localtax1'=>
"TotalLT1",
'f.localtax2'=>
"TotalLT2",
521 'f.paye'=>
"InvoicePaidCompletely",
'f.fk_statut'=>
'InvoiceStatus',
'f.close_code'=>
'EarlyClosingReason',
'f.close_note'=>
'EarlyClosingComment',
523 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic"
525 if (!$uselocaltax1) {
526 unset($this->export_fields_array[$r][
'f.localtax1']);
528 if (!$uselocaltax2) {
529 unset($this->export_fields_array[$r][
'f.localtax2']);
533 if (isModEnabled(
"multicurrency")) {
534 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
535 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
536 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
537 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
538 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
541 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) ||
getDolGlobalString(
'INVOICE_SHOW_POS')) {
542 $this->export_fields_array[$r][
'f.module_source'] =
'Module';
543 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
545 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
546 'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
547 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
548 'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel'
552 $nbofallowedentities = count(explode(
',',
getEntity(
'invoice')));
553 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
554 $this->export_fields_array[$r][
'f.entity'] =
'Entity';
557 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
558 'fd.rowid'=>
'LineId',
'fd.description'=>
"LineDescription",
559 'fd.subprice'=>
"LineUnitPrice",
'fd.qty'=>
"LineQty",
560 'fd.tva_tx'=>
"LineVATRate",
561 'fd.total_ht'=>
"LineTotalHT",
'fd.total_tva'=>
"LineTotalVAT",
'fd.total_ttc'=>
"LineTotalTTC",
562 'fd.localtax1_tx'=>
"LineLT1Rate",
'fd.localtax1_type'=>
"LineLT1Type",
'fd.total_localtax1'=>
"LineTotalLT1",
563 'fd.localtax2_tx'=>
"LineLT2Rate",
'fd.localtax2_type'=>
"LineLT2Type",
'fd.total_localtax2'=>
"LineTotalLT2",
564 'fd.buy_price_ht'=>
'BuyingPrice',
'fd.date_start'=>
"DateStart",
'fd.date_end'=>
"DateEnd",
'fd.special_code'=>
'SpecialCode',
565 'fd.product_type'=>
"TypeOfLineServiceOrProduct",
'fd.fk_product'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel',
566 $alias_product_perentity .
'.accountancy_code_sell'=>
'ProductAccountancySellCode',
567 'aa.account_number' =>
'AccountingAffectation'
569 if (!$uselocaltax1) {
570 unset($this->export_fields_array[$r][
'fd.localtax1_tx']);
571 unset($this->export_fields_array[$r][
'fd.localtax1_type']);
572 unset($this->export_fields_array[$r][
'fd.total_localtax1']);
574 if (!$uselocaltax2) {
575 unset($this->export_fields_array[$r][
'fd.localtax2_tx']);
576 unset($this->export_fields_array[$r][
'fd.localtax2_type']);
577 unset($this->export_fields_array[$r][
'fd.total_localtax2']);
580 $this->export_TypeFields_array[$r] = array(
581 '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',
582 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
584 'f.rowid'=>
'Numeric',
'f.ref'=>
"Text",
'f.ref_client'=>
'Text',
'f.fk_facture_source'=>
'Numeric',
'f.type'=>
"Numeric",
'f.datec'=>
"Date",
'f.datef'=>
"Date",
'f.date_lim_reglement'=>
"Date",
585 'f.fk_cond_reglement'=>
'Numeric',
'f.fk_mode_reglement'=>
'Numeric',
586 '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',
587 'none.rest'=>
"NumericCompute",
588 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
589 'f.module_source' =>
'Text',
590 'f.pos_source' =>
'Text',
591 'f.entity'=>
'List:entity:label:rowid',
592 'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
593 'pj.ref'=>
'Text',
'pj.title'=>
'Text',
'fd.rowid'=>
'Numeric',
'fd.description'=>
"Text",
'fd.subprice'=>
"Numeric",
'fd.tva_tx'=>
"Numeric",
594 'fd.qty'=>
"Numeric",
'fd.buy_price_ht'=>
"Numeric",
'fd.date_start'=>
"Date",
'fd.date_end'=>
"Date",
595 'fd.total_ht'=>
"Numeric",
'fd.total_tva'=>
"Numeric",
'fd.total_ttc'=>
"Numeric",
'fd.total_localtax1'=>
"Numeric",
'fd.total_localtax2'=>
"Numeric",
596 'fd.localtax1_tx'=>
'Numeric',
'fd.localtax2_tx'=>
'Numeric',
'fd.localtax1_type'=>
'Numeric',
'fd.localtax2_type'=>
'Numeric',
597 'fd.special_code'=>
'Numeric',
'fd.product_type'=>
"Numeric",
'fd.fk_product'=>
'List:product:label',
'p.ref'=>
'Text',
'p.label'=>
'Text',
598 $alias_product_perentity .
'.accountancy_code_sell'=>
'Text',
599 'aa.account_number' =>
'Text',
600 'f.multicurrency_code' =>
'Text',
601 'f.multicurrency_tx' =>
'Number',
'f.multicurrency_total_ht' =>
'Number',
'f.multicurrency_total_tva' =>
'Number',
'f.multicurrency_total_ttc' =>
'Number'
603 $this->export_entities_array[$r] = array(
604 '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',
605 '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',
606 't.libelle'=>
'company',
607 'pj.ref'=>
'project',
'pj.title'=>
'project',
'fd.rowid'=>
'invoice_line',
'fd.description'=>
"invoice_line",
608 'fd.subprice'=>
"invoice_line",
'fd.buy_price_ht'=>
'invoice_line',
609 'fd.total_ht'=>
"invoice_line",
'fd.total_tva'=>
"invoice_line",
'fd.total_ttc'=>
"invoice_line",
'fd.total_localtax1'=>
"invoice_line",
'fd.total_localtax2'=>
"invoice_line",
610 'fd.tva_tx'=>
"invoice_line",
'fd.localtax1_tx'=>
"invoice_line",
'fd.localtax2_tx'=>
"invoice_line",
'fd.localtax1_type'=>
"invoice_line",
'fd.localtax2_type'=>
"invoice_line",
611 'fd.qty'=>
"invoice_line",
'fd.date_start'=>
"invoice_line",
'fd.date_end'=>
"invoice_line",
'fd.special_code'=>
'invoice_line',
612 'fd.product_type'=>
'invoice_line',
'fd.fk_product'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product', $alias_product_perentity .
'.accountancy_code_sell'=>
'product',
613 'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
614 'aa.account_number' =>
"invoice_line",
616 $this->export_help_array[$r] = array(
'fd.buy_price_ht'=>
'CostPriceUsage');
617 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
618 $this->export_dependencies_array[$r] = array(
'invoice_line'=>
'fd.rowid',
'product'=>
'fd.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
619 $keyforselect =
'facture';
620 $keyforelement =
'invoice';
621 $keyforaliasextra =
'extra';
622 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
623 $keyforselect =
'facturedet';
624 $keyforelement =
'invoice_line';
625 $keyforaliasextra =
'extra2';
626 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
627 $keyforselect =
'product';
628 $keyforelement =
'product';
629 $keyforaliasextra =
'extra3';
630 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
631 $keyforselect =
'societe';
632 $keyforelement =
'company';
633 $keyforaliasextra =
'extra4';
634 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
635 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
636 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
637 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
638 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
639 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as t ON s.fk_typent = t.id';
640 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
641 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
643 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
644 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
645 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
646 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
647 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
648 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
649 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
650 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'facturedet as fd';
651 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
652 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (fd.fk_product = p.rowid)';
654 $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);
656 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
657 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
658 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
659 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
660 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
661 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
666 $this->export_code[$r] = $this->rights_class.
'_'.$r;
667 $this->export_label[$r] =
'CustomersInvoicesAndPayments';
668 $this->export_icon[$r] =
'invoice';
669 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export"));
670 $this->export_fields_array[$r] = array(
671 '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',
673 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
's.code_compta'=>
'CustomerAccountancyCode',
674 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
's.tva_intra'=>
'VATIntra',
675 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
'f.fk_facture_source'=>
'SourceInvoiceId',
676 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
677 'f.fk_cond_reglement'=>
'IdPaymentTerm',
'f.fk_mode_reglement'=>
'IdPaymentMode',
678 'f.total_ht'=>
"TotalHT",
'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',
680 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic",
'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
681 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel',
'p.rowid'=>
'PaymentId',
'p.ref'=>
'PaymentRef',
682 'p.amount'=>
'AmountPayment',
'pf.amount'=>
'AmountPaymentDistributedOnInvoice',
'p.datep'=>
'DatePayment',
'p.num_paiement'=>
'PaymentNumber',
683 'pt.code'=>
'CodePaymentMode',
'pt.libelle'=>
'LabelPaymentMode',
'p.note'=>
'PaymentNote',
'p.fk_bank'=>
'IdTransaction',
'ba.ref'=>
'AccountRef'
685 if (!$uselocaltax1) {
686 unset($this->export_fields_array[$r][
'f.localtax1']);
688 if (!$uselocaltax2) {
689 unset($this->export_fields_array[$r][
'f.localtax2']);
692 $this->export_help_array[$r] = array(
'f.paye'=>
'InvoicePaidCompletelyHelp');
693 if (isModEnabled(
"multicurrency")) {
694 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
695 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
696 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
697 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
698 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
699 $this->export_examplevalues_array[$r][
'f.multicurrency_code'] =
'EUR';
701 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) ||
getDolGlobalString(
'INVOICE_SHOW_POS')) {
702 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
703 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
705 $this->export_TypeFields_array[$r] = array(
706 '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',
707 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
708 'f.rowid'=>
"Numeric",
'f.ref'=>
"Text",
'f.ref_client'=>
'Text',
'f.fk_facture_source'=>
'Numeric',
'f.type'=>
"Numeric",
'f.datec'=>
"Date",
'f.datef'=>
"Date",
'f.date_lim_reglement'=>
"Date",
709 'f.fk_cond_reglement'=>
'Numeric',
'f.fk_mode_reglement'=>
'Numeric',
710 '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',
711 'none.rest'=>
'NumericCompute',
712 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
713 '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',
714 'p.fk_bank'=>
'Numeric',
'p.note'=>
'Text',
'pt.code'=>
'Text',
'pt.libelle'=>
'text',
'ba.ref'=>
'Text'
716 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) ||
getDolGlobalString(
'INVOICE_SHOW_POS')) {
717 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
718 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
720 $this->export_entities_array[$r] = array(
721 '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',
722 's.siren'=>
'company',
's.siret'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.code_compta'=>
'company',
's.code_compta_fournisseur'=>
'company',
723 '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',
724 'p.num_paiement'=>
'payment',
'pt.code'=>
'payment',
'pt.libelle'=>
'payment',
'p.note'=>
'payment',
'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
725 'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
'p.fk_bank'=>
'account',
'ba.ref'=>
'account'
727 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
728 $this->export_dependencies_array[$r] = array(
'payment'=>
'p.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
729 $keyforselect =
'facture';
730 $keyforelement =
'invoice';
731 $keyforaliasextra =
'extra';
732 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
733 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
734 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
735 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
736 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
738 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
739 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
740 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
741 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
742 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
743 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
744 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
745 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement_facture as pf ON pf.fk_facture = f.rowid';
746 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement as p ON pf.fk_paiement = p.rowid';
747 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as pt ON pt.id = p.fk_paiement';
748 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON b.rowid = p.fk_bank';
749 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON ba.rowid = b.fk_account';
750 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid';
751 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
752 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
753 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);