56 $this->family =
"srm";
57 $this->module_position =
'13';
59 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
63 $this->version =
'dolibarr';
66 $this->const_name =
'MAIN_MODULE_' . strtoupper($this->
name);
67 $this->picto =
'supplier_invoice';
72 "/fournisseur/facture",
73 "/fournisseur/facture/temp"
77 $this->depends = array(
"modSociete");
78 $this->requiredby = array(
"modSupplierProposal");
79 $this->langfiles = array(
'bills',
'companies',
'suppliers',
'orders',
'sendings');
82 $this->config_page_url = array(
"supplier_invoice.php@supplier_invoice");
95 "INVOICE_SUPPLIER_ADDON_NUMBER",
97 "mod_facture_fournisseur_cactus",
98 "Name of the supplier invoice numbering manager",
103 "SUPPLIER_INVOICE_ADDON_PDF_ODT_PATH",
105 "DOL_DATA_ROOT" . ($conf->entity > 1 ?
'/' .
$conf->entity :
'') .
"/doctemplates/supplier_invoices",
113 [
'file' =>
'box_graph_invoices_supplier_permonth.php',
'enabledbydefaulton' =>
'Home'],
114 [
'file' =>
'box_fournisseurs.php',
'enabledbydefaulton' =>
'Home'],
115 [
'file' =>
'box_factures_fourn_imp.php',
'enabledbydefaulton' =>
'Home'],
116 [
'file' =>
'box_factures_fourn.php',
'enabledbydefaulton' =>
'Home'],
120 $datestart =
dol_mktime(23, 0, 0, $arraydate[
'mon'], $arraydate[
'mday'], $arraydate[
'year']);
121 $this->cronjobs = array(
123 'label' =>
'RecurringSupplierInvoicesJob',
124 'jobtype' =>
'method',
125 'class' =>
'fourn/class/fournisseur.facture-rec.class.php',
126 'objectname' =>
'FactureFournisseurRec',
127 'method' =>
'createRecurringInvoices',
129 'comment' =>
'Generate recurring supplier invoices',
131 'unitfrequency' => 3600 * 24,
134 'test' =>
'isModEnabled("supplier_invoice")',
135 'datestart' => $datestart
138 'label' =>
'SendEmailsRemindersOnSupplierInvoiceDueDate',
139 'jobtype' =>
'method',
140 'class' =>
'fourn/class/fournisseur.facture.class.php',
141 'objectname' =>
'FactureFournisseur',
142 'method' =>
'sendEmailsRemindersOnSupplierInvoiceDueDate',
143 'parameters' =>
'10,all,EmailTemplateCode,duedate',
144 'comment' =>
'Send an email when we reach the supplier invoice due date (or supplier invoice date) - n days. First param is n, the number of days before due date (or supplier 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 supplier invoice). The fourth parameter is the string "duedate" (default) or "invoicedate" to define which date of the supplier invoice to use.',
146 'unitfrequency' => 3600 * 24,
149 'test' =>
'isModEnabled("supplier_invoice")',
150 'datestart' => $datestart
156 $this->rights = array();
157 $this->rights_class =
'supplier_invoice';
161 $this->rights[$r][0] = 1171;
162 $this->rights[$r][1] =
'Consulter les factures fournisseur';
163 $this->rights[$r][2] =
'r';
164 $this->rights[$r][3] = 0;
165 $this->rights[$r][4] =
'lire';
168 $this->rights[$r][0] = 1172;
169 $this->rights[$r][1] =
'Creer une facture fournisseur';
170 $this->rights[$r][2] =
'w';
171 $this->rights[$r][3] = 0;
172 $this->rights[$r][4] =
'creer';
175 $this->rights[$r][0] = 1173;
176 $this->rights[$r][1] =
'Valider une facture fournisseur';
177 $this->rights[$r][2] =
'w';
178 $this->rights[$r][3] = 0;
179 $this->rights[$r][4] =
'supplier_invoice_advance';
180 $this->rights[$r][5] =
'validate';
183 $this->rights[$r][0] = 1174;
184 $this->rights[$r][1] =
'Supprimer une facture fournisseur';
185 $this->rights[$r][2] =
'd';
186 $this->rights[$r][3] = 0;
187 $this->rights[$r][4] =
'supprimer';
190 $this->rights[$r][0] = 1175;
191 $this->rights[$r][1] =
'Envoyer les factures par mail';
192 $this->rights[$r][2] =
'a';
193 $this->rights[$r][3] = 0;
194 $this->rights[$r][4] =
'supplier_invoice_advance';
195 $this->rights[$r][5] =
'send';
198 $this->rights[$r][0] = 1176;
199 $this->rights[$r][1] =
'Exporter les factures fournisseurs, attributes et reglements';
200 $this->rights[$r][2] =
'r';
201 $this->rights[$r][3] = 0;
202 $this->rights[$r][4] =
'export';
212 $uselocaltax1 = (is_object(
$mysoc) &&
$mysoc->localtax1_assuj) ?
$mysoc->localtax1_assuj : 0;
213 $uselocaltax2 = (is_object(
$mysoc) &&
$mysoc->localtax2_assuj) ?
$mysoc->localtax2_assuj : 0;
217 $langs->loadLangs(array(
"suppliers",
"compta",
"multicurrency",
"bills"));
219 $alias_product_perentity = !
getDolGlobalString(
'MAIN_PRODUCT_PERENTITY_SHARED') ?
"p" :
"ppe";
222 $this->export_code[$r] = $this->rights_class .
'_' . $r;
223 $this->export_label[$r] =
'Vendor invoices and lines of invoices';
224 $this->export_icon[$r] =
'invoice';
225 $this->export_permission[$r] = array(array(
"fournisseur",
"facture",
"export"));
226 $this->export_fields_array[$r] = array(
227 's.rowid' =>
"IdCompany",
228 's.nom' =>
'CompanyName',
229 'ps.nom' =>
'ParentCompany',
230 's.address' =>
'Address',
233 'c.code' =>
'CountryCode',
234 's.phone' =>
'Phone',
235 's.siren' =>
'ProfId1',
236 's.siret' =>
'ProfId2',
237 's.ape' =>
'ProfId3',
238 's.idprof4' =>
'ProfId4',
239 's.idprof5' =>
'ProfId5',
240 's.idprof6' =>
'ProfId6',
241 's.code_compta' =>
'CustomerAccountancyCode',
242 's.code_compta_fournisseur' =>
'SupplierAccountancyCode',
243 's.tva_intra' =>
'VATIntra',
244 'f.rowid' =>
"InvoiceId",
245 'f.ref' =>
"InvoiceRef",
246 'f.ref_supplier' =>
"RefSupplier",
247 'f.datec' =>
"InvoiceDateCreation",
248 'f.datef' =>
"DateInvoice",
249 'f.date_lim_reglement' =>
'DateMaxPayment',
250 'f.fk_cond_reglement' =>
'IdPaymentTerm',
251 'f.fk_mode_reglement' =>
'IdPaymentMode',
252 'f.total_ht' =>
"TotalHT",
253 'f.total_ttc' =>
"TotalTTC",
254 'f.total_tva' =>
"TotalVAT",
255 'f.localtax1' =>
"TotalLT1",
256 'f.localtax2' =>
"TotalLT2",
257 'f.paye' =>
"InvoicePaid",
258 'f.fk_statut' =>
'InvoiceStatus',
259 'f.note_public' =>
"InvoiceNote",
260 'fd.rowid' =>
'LineId',
261 'fd.description' =>
"LineDescription",
262 'fd.qty' =>
"LineQty",
263 'fd.remise_percent' =>
"Discount",
264 'fd.tva_tx' =>
"LineVATRate",
265 'fd.total_ht' =>
"LineTotalHT",
266 'fd.total_ttc' =>
"LineTotalTTC",
267 'fd.tva' =>
"LineTotalVAT",
268 'fd.localtax1_tx' =>
"LineLT1Rate",
269 'fd.localtax1_type' =>
"LineLT1Type",
270 'fd.total_localtax1' =>
"LineTotalLT1",
271 'fd.localtax2_tx' =>
"LineLT2Rate",
272 'fd.localtax2_type' =>
"LineLT2Type",
273 'fd.total_localtax2' =>
"LineTotalLT2",
274 'fd.date_start' =>
"DateStart",
275 'fd.date_end' =>
"DateEnd",
276 'fd.special_code' =>
'SpecialCode',
277 'fd.product_type' =>
'TypeOfLineServiceOrProduct',
278 'fd.fk_product' =>
'ProductId',
279 'p.ref' =>
'ProductRef',
280 'p.label' =>
'ProductLabel',
281 $alias_product_perentity .
'.accountancy_code_buy' =>
'ProductAccountancyBuyCode',
282 'project.rowid' =>
'ProjectId',
283 'project.ref' =>
'ProjectRef',
284 'project.title' =>
'ProjectLabel'
286 if (!$uselocaltax1) {
287 unset($this->export_fields_array[$r][
'fd.localtax1_tx']);
288 unset($this->export_fields_array[$r][
'fd.localtax1_type']);
289 unset($this->export_fields_array[$r][
'fd.total_localtax1']);
291 if (!$uselocaltax2) {
292 unset($this->export_fields_array[$r][
'fd.localtax2_tx']);
293 unset($this->export_fields_array[$r][
'fd.localtax2_type']);
294 unset($this->export_fields_array[$r][
'fd.total_localtax2']);
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';
304 if (!$uselocaltax1) {
305 unset($this->export_fields_array[$r][
'f.localtax1']);
307 if (!$uselocaltax2) {
308 unset($this->export_fields_array[$r][
'f.localtax2']);
317 $this->export_TypeFields_array[$r] = array(
318 's.rowid' =>
'Numeric',
321 's.address' =>
'Text',
329 's.idprof4' =>
'Text',
330 's.idprof5' =>
'Text',
331 's.idprof6' =>
'Text',
332 's.code_compta' =>
'Text',
333 's.code_compta_fournisseur' =>
'Text',
334 's.tva_intra' =>
'Text',
335 'f.rowid' =>
'Numeric',
337 'f.ref_supplier' =>
"Text",
340 'f.date_lim_reglement' =>
'Date',
341 'f.fk_cond_reglement' =>
'Numeric',
342 'f.fk_mode_reglement' =>
'Numeric',
343 'f.total_ht' =>
"Numeric",
344 'f.total_ttc' =>
"Numeric",
345 'f.total_tva' =>
"Numeric",
346 'f.localtax1' =>
"Numeric",
347 'f.localtax2' =>
"Numeric",
348 'f.paye' =>
"Boolean",
349 'f.fk_statut' =>
'Status',
350 'f.note_public' =>
"Text",
351 'fd.rowid' =>
'Numeric',
352 'fd.description' =>
"Text",
353 'fd.tva_tx' =>
"Text",
354 'fd.qty' =>
"Numeric",
355 'fd.remise_percent' =>
"Numeric",
356 'fd.total_ht' =>
"Numeric",
357 'fd.total_ttc' =>
"Numeric",
358 'fd.tva' =>
"Numeric",
359 'fd.total_localtax1' =>
"Numeric",
360 'fd.total_localtax2' =>
"Numeric",
361 'fd.localtax1_tx' =>
'Numeric',
362 'fd.localtax2_tx' =>
'Numeric',
363 'fd.localtax1_type' =>
'Numeric',
364 'fd.localtax2_type' =>
'Numeric',
365 'fd.date_start' =>
"Date",
366 'fd.date_end' =>
"Date",
367 'fd.special_code' =>
"Numeric",
368 'fd.product_type' =>
'Numeric',
369 'fd.fk_product' =>
'List:product:label',
370 $alias_product_perentity .
'.accountancy_code_buy' =>
'Text',
373 'project.ref' =>
'Text',
374 'project.title' =>
'Text',
375 'f.multicurrency_code' =>
'Text',
376 'f.multicurrency_tx' =>
'Number',
377 'f.multicurrency_total_ht' =>
'Number',
378 'f.multicurrency_total_tva' =>
'Number',
379 'f.multicurrency_total_ttc' =>
'Number'
381 $this->export_entities_array[$r] = array(
382 's.rowid' =>
"company",
383 's.nom' =>
'company',
384 'ps.nom' =>
'company',
385 's.address' =>
'company',
386 's.zip' =>
'company',
387 's.town' =>
'company',
388 'c.code' =>
'company',
389 's.phone' =>
'company',
390 's.siren' =>
'company',
391 's.siret' =>
'company',
392 's.ape' =>
'company',
393 's.idprof4' =>
'company',
394 's.idprof5' =>
'company',
395 's.idprof6' =>
'company',
396 's.code_compta' =>
'company',
397 's.code_compta_fournisseur' =>
'company',
398 's.tva_intra' =>
'company',
399 'f.rowid' =>
"invoice",
400 'f.ref' =>
"invoice",
401 'f.ref_supplier' =>
"invoice",
402 'f.datec' =>
"invoice",
403 'f.datef' =>
"invoice",
404 'f.date_lim_reglement' =>
'invoice',
405 'f.fk_cond_reglement' =>
'invoice',
406 'f.fk_mode_reglement' =>
'invoice',
407 'f.total_ht' =>
"invoice",
408 'f.total_ttc' =>
"invoice",
409 'f.total_tva' =>
"invoice",
410 'f.paye' =>
"invoice",
411 'f.fk_statut' =>
'invoice',
412 'f.note_public' =>
"invoice",
413 'fd.rowid' =>
'invoice_line',
414 'fd.description' =>
"invoice_line",
415 'fd.qty' =>
"invoice_line",
416 'fd.total_ht' =>
"invoice_line",
417 'fd.tva' =>
"invoice_line",
418 'fd.total_ttc' =>
"invoice_line",
419 'fd.total_localtax1' =>
"invoice_line",
420 'fd.total_localtax2' =>
"invoice_line",
421 'fd.tva_tx' =>
"invoice_line",
422 'fd.localtax1_tx' =>
"invoice_line",
423 'fd.localtax2_tx' =>
"invoice_line",
424 'fd.localtax1_type' =>
"invoice_line",
425 'fd.localtax2_type' =>
"invoice_line",
426 'fd.remise_percent' =>
"invoice_line",
427 'fd.date_start' =>
"invoice_line",
428 'fd.date_end' =>
"invoice_line",
429 'fd.special_code' =>
"invoice_line",
430 'fd.product_type' =>
'invoice_line',
431 'fd.fk_product' =>
'product',
432 'p.ref' =>
'product',
433 'p.label' =>
'product',
434 $alias_product_perentity .
'.accountancy_code_buy' =>
'product',
435 'project.rowid' =>
'project',
436 'project.ref' =>
'project',
437 'project.title' =>
'project'
439 $this->export_dependencies_array[$r] = array(
'invoice_line' =>
'fd.rowid',
'product' =>
'fd.rowid');
441 $keyforselect =
'facture_fourn';
442 $keyforelement =
'invoice';
443 $keyforaliasextra =
'extra';
444 include DOL_DOCUMENT_ROOT .
'/core/extrafieldsinexport.inc.php';
445 $keyforselect =
'facture_fourn_det';
446 $keyforelement =
'invoice_line';
447 $keyforaliasextra =
'extraline';
448 include DOL_DOCUMENT_ROOT .
'/core/extrafieldsinexport.inc.php';
450 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
451 $this->export_sql_end[$r] =
' FROM ' . MAIN_DB_PREFIX .
'societe as s';
452 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe as ps ON ps.rowid = s.parent';
453 if (is_object($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
454 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
456 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_country as c ON s.fk_pays = c.rowid,';
457 $this->export_sql_end[$r] .=
' ' . MAIN_DB_PREFIX .
'facture_fourn as f';
458 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'projet as project on (f.fk_projet = project.rowid)';
459 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
460 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_paiement as cp ON f.fk_mode_reglement = cp.id';
461 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid,';
462 $this->export_sql_end[$r] .=
' ' . MAIN_DB_PREFIX .
'facture_fourn_det as fd';
463 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
464 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'product as p on (fd.fk_product = p.rowid)';
465 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
466 $this->export_sql_end[$r] .=
' AND f.entity IN (' .
getEntity(
'supplier_invoice') .
')';
467 if (is_object($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
468 $this->export_sql_end[$r] .=
' AND sc.fk_user = ' . ((int) $user->id);
473 $this->export_code[$r] = $this->rights_class .
'_' . $r;
474 $this->export_label[$r] =
'Factures fournisseurs et reglements';
475 $this->export_icon[$r] =
'invoice';
476 $this->export_permission[$r] = array(array(
"fournisseur",
"facture",
"export"));
477 $this->export_fields_array[$r] = array(
478 's.rowid' =>
"IdCompany",
479 's.nom' =>
'CompanyName',
480 's.address' =>
'Address',
483 'c.code' =>
'CountryCode',
484 's.phone' =>
'Phone',
485 's.siren' =>
'ProfId1',
486 's.siret' =>
'ProfId2',
487 's.ape' =>
'ProfId3',
488 's.idprof4' =>
'ProfId4',
489 's.idprof5' =>
'ProfId5',
490 's.idprof6' =>
'ProfId6',
491 's.code_compta' =>
'CustomerAccountancyCode',
492 's.code_compta_fournisseur' =>
'SupplierAccountancyCode',
493 's.tva_intra' =>
'VATIntra',
494 'f.rowid' =>
"InvoiceId",
495 'f.ref' =>
"InvoiceRef",
496 'f.ref_supplier' =>
"RefSupplier",
497 'f.datec' =>
"InvoiceDateCreation",
498 'f.datef' =>
"DateInvoice",
499 'f.date_lim_reglement' =>
"DateMaxPayment",
500 'f.fk_cond_reglement' =>
'IdPaymentTerm',
501 'f.fk_mode_reglement' =>
'IdPaymentMode',
502 'f.total_ht' =>
"TotalHT",
503 'f.total_ttc' =>
"TotalTTC",
504 'f.total_tva' =>
"TotalVAT",
505 'f.localtax1' =>
"TotalLT1",
506 'f.localtax2' =>
"TotalLT2",
507 'f.paye' =>
"InvoicePaid",
508 'f.fk_statut' =>
'InvoiceStatus',
509 'f.note_public' =>
"InvoiceNote",
510 'p.rowid' =>
'PaymentId',
511 'pf.amount' =>
'AmountPayment',
512 'p.datep' =>
'DatePayment',
513 'p.num_paiement' =>
'PaymentNumber',
514 'p.fk_bank' =>
'IdTransaction',
515 'project.rowid' =>
'ProjectId',
516 'project.ref' =>
'ProjectRef',
517 'project.title' =>
'ProjectLabel'
519 if (!$uselocaltax1) {
520 unset($this->export_fields_array[$r][
'f.localtax1']);
522 if (!$uselocaltax2) {
523 unset($this->export_fields_array[$r][
'f.localtax2']);
526 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
527 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
528 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
529 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
530 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
538 $this->export_TypeFields_array[$r] = array(
539 's.rowid' =>
'Numeric',
541 's.address' =>
'Text',
549 's.idprof4' =>
'Text',
550 's.idprof5' =>
'Text',
551 's.idprof6' =>
'Text',
552 's.code_compta' =>
'Text',
553 's.code_compta_fournisseur' =>
'Text',
554 's.tva_intra' =>
'Text',
555 'f.rowid' =>
'Numeric',
557 'f.ref_supplier' =>
"Text",
560 'f.date_lim_reglement' =>
'Date',
561 'f.fk_cond_reglement' =>
'Numeric',
562 'f.fk_mode_reglement' =>
'Numeric',
563 'f.total_ht' =>
"Numeric",
564 'f.total_ttc' =>
"Numeric",
565 'f.total_tva' =>
"Numeric",
566 'f.localtax1' =>
"Numeric",
567 'f.localtax2' =>
"Numeric",
568 'f.paye' =>
"Boolean",
569 'f.fk_statut' =>
'Status',
570 'f.note_public' =>
"Text",
571 'pf.amount' =>
'Numeric',
572 'p.rowid' =>
'Numeric',
574 'p.num_paiement' =>
'Numeric',
575 'p.fk_bank' =>
'Numeric',
576 'project.rowid' =>
'Numeric',
577 'project.ref' =>
'Text',
578 'project.title' =>
'Text',
579 'f.multicurrency_code' =>
'Text',
580 'f.multicurrency_tx' =>
'Number',
581 'f.multicurrency_total_ht' =>
'Number',
582 'f.multicurrency_total_tva' =>
'Number',
583 'f.multicurrency_total_ttc' =>
'Number'
585 $this->export_entities_array[$r] = array(
586 's.rowid' =>
"company",
587 's.nom' =>
'company',
588 's.address' =>
'company',
589 's.zip' =>
'company',
590 's.town' =>
'company',
591 'c.code' =>
'company',
592 's.phone' =>
'company',
593 's.siren' =>
'company',
594 's.siret' =>
'company',
595 's.ape' =>
'company',
596 's.idprof4' =>
'company',
597 's.idprof5' =>
'company',
598 's.idprof6' =>
'company',
599 's.code_compta' =>
'company',
600 's.code_compta_fournisseur' =>
'company',
601 's.tva_intra' =>
'company',
602 'f.rowid' =>
"invoice",
603 'f.ref' =>
"invoice",
604 'f.ref_supplier' =>
"invoice",
605 'f.datec' =>
"invoice",
606 'f.datef' =>
"invoice",
607 'f.date_lim_reglement' =>
'invoice',
608 'f.fk_cond_reglement' =>
'invoice',
609 'f.fk_mode_reglement' =>
'invoice',
610 'f.total_ht' =>
"invoice",
611 'f.total_ttc' =>
"invoice",
612 'f.total_tva' =>
"invoice",
613 'f.paye' =>
"invoice",
614 'f.fk_statut' =>
'invoice',
615 'f.note_public' =>
"invoice",
616 'p.rowid' =>
'payment',
617 'pf.amount' =>
'payment',
618 'p.datep' =>
'payment',
619 'p.num_paiement' =>
'payment',
620 'p.fk_bank' =>
'account',
621 'project.rowid' =>
'project',
622 'project.ref' =>
'project',
623 'project.title' =>
'project'
625 $this->export_dependencies_array[$r] = array(
'payment' =>
'p.rowid');
627 $keyforselect =
'facture_fourn';
628 $keyforelement =
'invoice';
629 $keyforaliasextra =
'extra';
630 include DOL_DOCUMENT_ROOT .
'/core/extrafieldsinexport.inc.php';
632 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
633 $this->export_sql_end[$r] =
' FROM ' . MAIN_DB_PREFIX .
'societe as s';
634 if (is_object($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
635 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
637 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_country as c ON s.fk_pays = c.rowid,';
638 $this->export_sql_end[$r] .=
' ' . MAIN_DB_PREFIX .
'facture_fourn as f';
639 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'projet as project on (f.fk_projet = project.rowid)';
640 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
641 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
642 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
643 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_paiement as cp ON f.fk_mode_reglement = cp.id';
644 $this->export_sql_end[$r] .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid';
645 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid';
646 $this->export_sql_end[$r] .=
' AND f.entity IN (' .
getEntity(
'supplier_invoice') .
')';
647 if (is_object($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
648 $this->export_sql_end[$r] .=
' AND sc.fk_user = ' . ((int) $user->id);
656 $this->import_code[$r] = $this->rights_class .
'_' . $r;
657 $this->import_label[$r] =
"SupplierInvoices";
658 $this->import_icon[$r] =
'supplier_invoice';
659 $this->import_entities_array[$r] = array();
660 $this->import_tables_array[$r] = array(
'f' => MAIN_DB_PREFIX .
'facture_fourn',
'extra' => MAIN_DB_PREFIX .
'facture_fourn_extrafields');
661 $this->import_tables_creator_array[$r] = array(
'f' =>
'fk_user_author');
662 $this->import_fields_array[$r] = array(
663 'f.ref' =>
'InvoiceRef*',
664 'f.ref_supplier' =>
'RefSupplier',
666 'f.fk_soc' =>
'Supplier/Vendor*',
667 'f.datec' =>
'InvoiceDateCreation',
668 'f.datef' =>
'DateInvoice',
669 'f.date_lim_reglement' =>
'DateMaxPayment',
670 'f.total_ht' =>
'TotalHT',
671 'f.total_ttc' =>
'TotalTTC',
672 'f.total_tva' =>
'TotalVAT',
673 'f.paye' =>
'InvoicePaid',
674 'f.fk_statut' =>
'InvoiceStatus',
675 'f.fk_user_modif' =>
'Modifier Id',
676 'f.fk_user_valid' =>
'Validator Id',
677 'f.fk_facture_source' =>
'Invoice Source Id',
678 'f.fk_projet' =>
'Project Id',
679 'f.fk_account' =>
'Bank Account*',
680 'f.note_public' =>
'InvoiceNote',
681 'f.note_private' =>
'NotePrivate',
682 'f.fk_cond_reglement' =>
'PaymentTerm',
683 'f.fk_mode_reglement' =>
'PaymentMode',
684 'f.model_pdf' =>
'Model',
685 'f.date_valid' =>
'DateValidation'
688 $this->import_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
689 $this->import_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
690 $this->import_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
691 $this->import_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
692 $this->import_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
695 $import_extrafield_sample = array();
696 $sql =
"SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX .
"extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, " .
$conf->entity .
")";
697 $resql = $this->db->query($sql);
699 while ($obj = $this->db->fetch_object($resql)) {
700 $fieldname =
'extra.' . $obj->name;
701 $fieldlabel = ucfirst($obj->label);
702 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ?
'*' :
'');
703 $import_extrafield_sample[$fieldname] = $fieldlabel;
707 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-' . MAIN_DB_PREFIX .
'facture_fourn');
708 if (empty(
$conf->multicurrency->enabled)) {
709 $this->import_fieldshidden_array[$r][
'f.multicurrency_code'] =
'const-' .
$conf->currency;
711 $this->import_regex_array[$r] = array(
'f.multicurrency_code' =>
'code@' . MAIN_DB_PREFIX .
'multicurrency');
712 $import_sample = array(
713 'f.ref' =>
'(PROV001)',
714 'f.ref_supplier' =>
'Supplier1',
716 'f.fk_soc' =>
'Vendor1',
717 'f.datec' =>
'2021-01-01',
719 'f.date_lim_reglement' =>
'2021-01-30',
720 'f.total_ht' =>
'1000',
721 'f.total_ttc' =>
'1000',
722 'f.total_tva' =>
'0',
724 'f.fk_statut' =>
'0',
725 'f.fk_user_modif' =>
'',
726 'f.fk_user_valid' =>
'',
727 'f.fk_facture_source' =>
'',
729 'f.fk_account' =>
'BANK1',
730 'f.note_public' =>
'Note: ',
731 'f.note_private' =>
'',
732 'f.fk_cond_reglement' =>
'1',
733 'f.fk_mode_reglement' =>
'2',
734 'f.model_pdf' =>
'crab',
735 'f.date_valid' =>
'',
736 'f.multicurrency_code' =>
'USD',
737 'f.multicurrency_tx' =>
'1',
738 'f.multicurrency_total_ht' =>
'1000',
739 'f.multicurrency_total_tva' =>
'0',
740 'f.multicurrency_total_ttc' =>
'1000'
742 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
743 $this->import_updatekeys_array[$r] = array(
'f.ref' =>
'Ref');
744 $this->import_convertvalue_array[$r] = array(
746 'rule' =>
'getrefifauto',
747 'class' => (!
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_NUMBER') ?
'mod_facture_fournisseur_cactus' :
$conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
748 'path' =>
"/core/modules/supplier_invoice/" . (!
getDolGlobalString(
'INVOICE_SUPPLIER_ADDON_NUMBER') ?
'mod_facture_fournisseur_cactus' :
$conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) .
'.php',
749 'classobject' =>
'FactureFournisseur',
750 'pathobject' =>
'/fourn/class/fournisseur.facture.class.php',
752 'f.fk_soc' => array(
'rule' =>
'fetchidfromref',
'file' =>
'/societe/class/societe.class.php',
'class' =>
'Societe',
'method' =>
'fetch',
'element' =>
'ThirdParty'),
753 'f.fk_account' => array(
'rule' =>
'fetchidfromref',
'file' =>
'/compta/bank/class/account.class.php',
'class' =>
'Account',
'method' =>
'fetch',
'element' =>
'bank_account'),
758 $this->import_code[$r] = $this->rights_class .
'_' . $r;
759 $this->import_label[$r] =
"SupplierInvoiceLines";
760 $this->import_icon[$r] =
'supplier_invoice';
761 $this->import_entities_array[$r] = array();
762 $this->import_tables_array[$r] = array(
'fd' => MAIN_DB_PREFIX .
'facture_fourn_det',
'extra' => MAIN_DB_PREFIX .
'facture_fourn_det_extrafields');
763 $this->import_fields_array[$r] = array(
764 'fd.fk_facture_fourn' =>
'InvoiceRef*',
765 'fd.fk_parent_line' =>
'ParentLine',
766 'fd.fk_product' =>
'IdProduct',
767 'fd.description' =>
'LineDescription',
768 'fd.pu_ht' =>
'PriceUHT',
769 'fd.pu_ttc' =>
'PriceUTTC',
770 'fd.qty' =>
'LineQty',
771 'fd.remise_percent' =>
'Reduc.',
772 'fd.vat_src_code' =>
'Vat Source Code',
773 'fd.product_type' =>
'TypeOfLineServiceOrProduct',
774 'fd.tva_tx' =>
'LineVATRate',
775 'fd.total_ht' =>
'LineTotalHT',
776 'fd.tva' =>
'LineTotalVAT',
777 'fd.total_ttc' =>
'LineTotalTTC',
778 'fd.date_start' =>
'Start Date',
779 'fd.date_end' =>
'End Date',
780 'fd.fk_unit' =>
'Unit'
783 $this->import_fields_array[$r][
'fd.multicurrency_code'] =
'Currency';
784 $this->import_fields_array[$r][
'fd.multicurrency_subprice'] =
'CurrencyRate';
785 $this->import_fields_array[$r][
'fd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
786 $this->import_fields_array[$r][
'fd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
787 $this->import_fields_array[$r][
'fd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
790 $import_extrafield_sample = array();
791 $sql =
"SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX .
"extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, " .
$conf->entity .
")";
792 $resql = $this->db->query($sql);
794 while ($obj = $this->db->fetch_object($resql)) {
795 $fieldname =
'extra.' . $obj->name;
796 $fieldlabel = ucfirst($obj->label);
797 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ?
'*' :
'');
798 $import_extrafield_sample[$fieldname] = $fieldlabel;
802 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-' . MAIN_DB_PREFIX .
'facture_fourn_det');
803 $this->import_regex_array[$r] = array(
'fd.product_type' =>
'[0|1]$',
'fd.fk_product' =>
'rowid@' . MAIN_DB_PREFIX .
'product',
'fd.multicurrency_code' =>
'code@' . MAIN_DB_PREFIX .
'multicurrency');
804 $import_sample = array(
805 'fd.fk_facture_fourn' =>
'(PROV001)',
806 'fd.fk_parent_line' =>
'',
807 'fd.fk_product' =>
'',
808 'fd.description' =>
'Test Product',
809 'fd.pu_ht' =>
'50000',
810 'fd.pu_ttc' =>
'50000',
812 'fd.remise_percent' =>
'0',
813 'fd.vat_src_code' =>
'',
814 'fd.product_type' =>
'0',
816 'fd.total_ht' =>
'50000',
818 'fd.total_ttc' =>
'50000',
819 'fd.date_start' =>
'',
822 'fd.multicurrency_code' =>
'USD',
823 'fd.multicurrency_tx' =>
'0',
824 'fd.multicurrency_total_ht' =>
'50000',
825 'fd.multicurrency_total_tva' =>
'0',
826 'fd.multicurrency_total_ttc' =>
'50000'
828 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
829 $this->import_updatekeys_array[$r] = array(
'fd.rowid' =>
'Row Id',
'fd.fk_facture_fourn' =>
'Invoice Id',
'fd.fk_product' =>
'Product Id');
830 $this->import_convertvalue_array[$r] = array(
831 'fd.fk_facture_fourn' => array(
'rule' =>
'fetchidfromref',
'file' =>
'/fourn/class/fournisseur.facture.class.php',
'class' =>
'FactureFournisseur',
'method' =>
'fetch'),