53 $this->family =
"financial";
54 $this->module_position =
'11';
56 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
60 $this->version =
'dolibarr';
62 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
63 $this->picto =
'bill';
66 $this->dirs = array(
"/facture/temp");
69 $this->depends = array(
'always'=>
"modSociete");
70 $this->requiredby = array(
"modComptabilite",
"modAccounting");
71 $this->conflictwith = array();
72 $this->langfiles = array(
"bills",
"companies",
"compta",
"products");
73 $this->warnings_activation = array();
74 $this->warnings_activation_ext = array();
77 $this->config_page_url = array(
"facture.php");
80 $this->
const = array();
83 $this->
const[$r][0] =
"FACTURE_ADDON";
84 $this->
const[$r][1] =
"chaine";
85 $this->
const[$r][2] =
"mod_facture_terre";
86 $this->
const[$r][3] =
'Name of numbering numerotation rules of invoice';
87 $this->
const[$r][4] = 0;
90 $this->
const[$r][0] =
"FACTURE_ADDON_PDF";
91 $this->
const[$r][1] =
"chaine";
92 $this->
const[$r][2] =
"sponge";
93 $this->
const[$r][3] =
'Name of PDF model of invoice';
94 $this->
const[$r][4] = 0;
97 $this->
const[$r][0] =
"FACTURE_ADDON_PDF_ODT_PATH";
98 $this->
const[$r][1] =
"chaine";
99 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/invoices";
100 $this->
const[$r][3] =
"";
101 $this->
const[$r][4] = 0;
106 $this->boxes = array(
107 0=>array(
'file'=>
'box_factures_imp.php',
'enabledbydefaulton'=>
'Home'),
108 1=>array(
'file'=>
'box_factures.php',
'enabledbydefaulton'=>
'Home'),
109 2=>array(
'file'=>
'box_graph_invoices_permonth.php',
'enabledbydefaulton'=>
'Home'),
110 3=>array(
'file'=>
'box_customers_outstanding_bill_reached.php',
'enabledbydefaulton'=>
'Home')
115 $datestart =
dol_mktime(23, 0, 0, $arraydate[
'mon'], $arraydate[
'mday'], $arraydate[
'year']);
116 $this->cronjobs = array(
118 'label'=>
'RecurringInvoicesJob',
120 'class'=>
'compta/facture/class/facture-rec.class.php',
121 'objectname'=>
'FactureRec',
122 'method'=>
'createRecurringInvoices',
124 'comment'=>
'Generate recurring invoices',
126 'unitfrequency'=>3600 * 24,
129 'test'=>
'$conf->facture->enabled',
130 'datestart'=>$datestart
133 'label'=>
'SendEmailsRemindersOnInvoiceDueDate',
135 'class'=>
'compta/facture/class/facture.class.php',
136 'objectname'=>
'Facture',
137 'method'=>
'sendEmailsRemindersOnInvoiceDueDate',
138 'parameters'=>
"10,all,EmailTemplateCode,duedate",
139 '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.',
141 'unitfrequency'=>3600 * 24,
144 'test'=>
'$conf->facture->enabled',
145 'datestart'=>$datestart
150 $this->rights = array();
151 $this->rights_class =
'facture';
155 $this->rights[$r][0] = 11;
156 $this->rights[$r][1] =
'Read invoices';
157 $this->rights[$r][2] =
'a';
158 $this->rights[$r][3] = 0;
159 $this->rights[$r][4] =
'lire';
162 $this->rights[$r][0] = 12;
163 $this->rights[$r][1] =
'Create and update invoices';
164 $this->rights[$r][2] =
'a';
165 $this->rights[$r][3] = 0;
166 $this->rights[$r][4] =
'creer';
170 $this->rights[$r][0] = 13;
171 $this->rights[$r][1] =
'Devalidate invoices';
172 $this->rights[$r][2] =
'a';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] =
'invoice_advance';
175 $this->rights[$r][5] =
'unvalidate';
178 $this->rights[$r][0] = 14;
179 $this->rights[$r][1] =
'Validate invoices';
180 $this->rights[$r][2] =
'a';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] =
'invoice_advance';
183 $this->rights[$r][5] =
'validate';
186 $this->rights[$r][0] = 15;
187 $this->rights[$r][1] =
'Send invoices by email';
188 $this->rights[$r][2] =
'a';
189 $this->rights[$r][3] = 0;
190 $this->rights[$r][4] =
'invoice_advance';
191 $this->rights[$r][5] =
'send';
194 $this->rights[$r][0] = 16;
195 $this->rights[$r][1] =
'Issue payments on invoices';
196 $this->rights[$r][2] =
'a';
197 $this->rights[$r][3] = 0;
198 $this->rights[$r][4] =
'paiement';
201 $this->rights[$r][0] = 19;
202 $this->rights[$r][1] =
'Delete invoices';
203 $this->rights[$r][2] =
'a';
204 $this->rights[$r][3] = 0;
205 $this->rights[$r][4] =
'supprimer';
208 $this->rights[$r][0] = 1321;
209 $this->rights[$r][1] =
'Export customer invoices, attributes and payments';
210 $this->rights[$r][2] =
'r';
211 $this->rights[$r][3] = 0;
212 $this->rights[$r][4] =
'facture';
213 $this->rights[$r][5] =
'export';
216 $this->rights[$r][0] = 1322;
217 $this->rights[$r][1] =
'Re-open a fully paid invoice';
218 $this->rights[$r][2] =
'r';
219 $this->rights[$r][3] = 0;
220 $this->rights[$r][4] =
'invoice_advance';
221 $this->rights[$r][5] =
'reopen';
234 $this->import_code[$r] = $this->rights_class.
'_'.$r;
235 $this->import_label[$r] =
"Invoices";
236 $this->import_icon[$r] = $this->picto;
237 $this->import_entities_array[$r] = array();
238 $this->import_tables_array[$r] = array(
'f' => MAIN_DB_PREFIX.
'facture',
'extra' => MAIN_DB_PREFIX.
'facture_extrafields');
239 $this->import_tables_creator_array[$r] = array(
'f' =>
'fk_user_author');
240 $this->import_fields_array[$r] = array(
241 'f.ref' =>
'InvoiceRef*',
242 'f.ref_ext' =>
'ExternalRef',
243 'f.ref_client' =>
'RefCustomer',
245 'f.fk_soc' =>
'Customer*',
246 'f.datec' =>
'InvoiceDateCreation',
247 'f.datef' =>
'DateInvoice',
248 'f.date_valid' =>
'Validation Date',
249 'f.paye' =>
'InvoicePaid',
250 'f.remise_percent' =>
'RemisePercent',
251 'f.remise_absolue' =>
'RemiseAbsolue',
252 'f.remise' =>
'Remise',
253 'f.total_tva' =>
'TotalVAT',
254 'f.total_ht' =>
'TotalHT',
255 'f.total_ttc' =>
'TotalTTC',
256 'f.fk_statut' =>
'InvoiceStatus',
257 'f.fk_user_modif' =>
'Modifier Id',
258 'f.fk_user_valid' =>
'Validator Id',
259 'f.fk_user_closing' =>
'Closer Id',
260 'f.fk_facture_source' =>
'Invoice Source Id',
261 'f.fk_projet' =>
'Project Id',
262 'f.fk_account' =>
'Bank Account',
263 'f.fk_currency' =>
'Currency*',
264 'f.fk_cond_reglement' =>
'Payment Condition',
265 'f.fk_mode_reglement' =>
'Payment Mode',
266 'f.date_lim_reglement' =>
'DateMaxPayment',
267 'f.note_public' =>
'InvoiceNote',
268 'f.note_private' =>
'NotePrivate',
269 'f.model_pdf' =>
'Model'
271 if (isModEnabled(
"multicurrency")) {
272 $this->import_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
273 $this->import_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
274 $this->import_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
275 $this->import_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
276 $this->import_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
279 $import_extrafield_sample = array();
280 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture' AND entity IN (0, ".$conf->entity.
")";
281 $resql = $this->db->query($sql);
283 while ($obj = $this->db->fetch_object($resql)) {
284 $fieldname =
'extra.'.$obj->name;
285 $fieldlabel = ucfirst($obj->label);
286 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
287 $import_extrafield_sample[$fieldname] = $fieldlabel;
291 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facture');
292 $this->import_regex_array[$r] = array(
'f.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency');
293 $import_sample = array(
294 'f.ref' =>
'(PROV0001)',
296 'f.ref_client' =>
'',
298 'f.fk_soc' =>
'80LIMIT',
299 'f.datec' =>
'2021-11-24',
300 'f.datef' =>
'2021-11-24',
301 'f.date_valid' =>
'2021-11-24',
303 'f.remise_percent' =>
'0',
304 'f.remise_absolue' =>
'0',
306 'f.total_tva' =>
'21',
307 'f.total_ht' =>
'100',
308 'f.total_ttc' =>
'121',
309 'f.fk_statut' =>
'1',
310 'f.fk_user_modif' =>
'',
311 'f.fk_user_valid' =>
'',
312 'f.fk_user_closing' =>
'',
313 'f.fk_facture_source' =>
'',
315 'f.fk_account' =>
'',
316 'f.fk_currency' =>
'EUR',
317 'f.fk_cond_reglement' =>
'30D',
318 'f.fk_mode_reglement' =>
'VIR',
319 'f.date_lim_reglement' =>
'2021-12-24',
320 'f.note_public' =>
'',
321 'f.note_private' =>
'',
322 'f.model_pdf' =>
'sponge',
323 'f.multicurrency_code' =>
'EUR',
324 'f.multicurrency_tx' =>
'1',
325 'f.multicurrency_total_ht' =>
'100',
326 'f.multicurrency_total_tva' =>
'21',
327 'f.multicurrency_total_ttc' =>
'121'
329 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
330 $this->import_updatekeys_array[$r] = array(
'f.ref' =>
'Ref');
331 $this->import_convertvalue_array[$r] = array(
333 'rule' =>
'fetchidfromref',
334 'file' =>
'/societe/class/societe.class.php',
335 'class' =>
'Societe',
337 'element' =>
'ThirdParty'
339 'f.fk_projet' => array(
340 'rule' =>
'fetchidfromref',
341 'file' =>
'/projet/class/project.class.php',
342 'class' =>
'Project',
344 'element' =>
'facture'
346 'f.fk_cond_reglement' => array(
347 'rule' =>
'fetchidfromcodeorlabel',
348 'file' =>
'/compta/facture/class/paymentterm.class.php',
349 'class' =>
'PaymentTerm',
351 'element' =>
'c_payment_term'
357 $this->import_code[$r] = $this->rights_class.
'_'.$r;
358 $this->import_label[$r] =
"InvoiceLine";
359 $this->import_icon[$r] = $this->picto;
360 $this->import_entities_array[$r] = array();
361 $this->import_tables_array[$r] = array(
'fd' => MAIN_DB_PREFIX.
'facturedet',
'extra' => MAIN_DB_PREFIX.
'facturedet_extrafields');
362 $this->import_fields_array[$r] = array(
363 'fd.fk_facture' =>
'InvoiceRef*',
364 'fd.fk_parent_line' =>
'FacParentLine',
365 'fd.fk_product' =>
'IdProduct',
366 'fd.label' =>
'Label',
367 'fd.description' =>
'LineDescription*',
368 'fd.vat_src_code' =>
'Vat Source Code',
369 'fd.tva_tx' =>
'LineVATRate*',
374 'fd.qty' =>
'LineQty',
375 'fd.remise_percent' =>
'Reduc. (%)',
380 'fd.total_ht' =>
'LineTotalHT',
381 'fd.total_tva' =>
'LineTotalVAT',
384 'fd.total_ttc' =>
'LineTotalTTC',
385 'fd.product_type' =>
'TypeOfLineServiceOrProduct',
386 'fd.date_start' =>
'Start Date',
387 'fd.date_end' =>
'End Date',
394 'fd.fk_unit' =>
'Unit',
402 if (isModEnabled(
"multicurrency")) {
403 $this->import_fields_array[$r][
'fd.multicurrency_code'] =
'Currency';
404 $this->import_fields_array[$r][
'fd.multicurrency_subprice'] =
'CurrencyRate';
405 $this->import_fields_array[$r][
'fd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
406 $this->import_fields_array[$r][
'fd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
407 $this->import_fields_array[$r][
'fd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
410 $import_extrafield_sample = array();
411 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'facture_det' AND entity IN (0, ".$conf->entity.
")";
412 $resql = $this->db->query($sql);
414 while ($obj = $this->db->fetch_object($resql)) {
415 $fieldname =
'extra.'.$obj->name;
416 $fieldlabel = ucfirst($obj->label);
417 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
418 $import_extrafield_sample[$fieldname] = $fieldlabel;
422 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'facturedet');
423 $this->import_regex_array[$r] = array(
424 'fd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
425 'fd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
427 $import_sample = array(
428 'fd.fk_facture' =>
'(PROV00001)',
429 'fd.fk_parent_line' =>
'',
430 'fd.fk_product' =>
'',
432 'fd.description' =>
'Test product',
433 'fd.vat_src_code' =>
'',
440 'fd.remise_percent' =>
'0',
445 'fd.total_ht' =>
'100',
446 'fd.total_tva' =>
'21',
449 'fd.total_ttc' =>
'121',
450 'fd.product_type' =>
'0',
451 'fd.date_start' =>
'',
466 'fd.multicurrency_code' =>
'EUR',
467 'fd.multicurrency_tx' =>
'21',
468 'fd.multicurrency_total_ht' =>
'100',
469 'fd.multicurrency_total_tva' =>
'21',
470 'fd.multicurrency_total_ttc' =>
'121'
472 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
473 $this->import_updatekeys_array[$r] = array(
474 'fd.rowid' =>
'Row Id',
475 'fd.fk_facture' =>
'Invoice Id'
477 $this->import_convertvalue_array[$r] = array(
478 'fd.fk_facture' => array(
479 'rule' =>
'fetchidfromref',
480 'file' =>
'/compta/facture/class/facture.class.php',
481 'class' =>
'Facture',
483 'element' =>
'facture'
485 'fd.fk_projet' => array(
486 'rule' =>
'fetchidfromref',
487 'file' =>
'/projet/class/project.class.php',
488 'class' =>
'Project',
490 'element' =>
'facture'
499 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ?
"p" :
"ppe";
501 $this->export_code[$r] = $this->rights_class.
'_'.$r;
502 $this->export_label[$r] =
'CustomersInvoicesAndInvoiceLines';
503 $this->export_icon[$r] =
'invoice';
504 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export",
"other"));
506 $this->export_fields_array[$r] = array(
507 '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',
509 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
510 's.code_compta'=>
'CustomerAccountancyCode',
511 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
512 's.tva_intra'=>
'VATIntra',
513 't.libelle'=>
"ThirdPartyType",
514 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
'f.fk_facture_source'=>
'SourceInvoiceId',
515 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
'f.total_ht'=>
"TotalHT",
516 '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',
518 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic"
521 if (isModEnabled(
"multicurrency")) {
522 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
523 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
524 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
525 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
526 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
529 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
530 $this->export_fields_array[$r][
'f.module_source'] =
'Module';
531 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
533 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
534 'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
535 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
536 'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel'
539 if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED)) {
540 $nbofallowedentities = count(explode(
',',
getEntity(
'invoice')));
541 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
542 $this->export_fields_array[$r][
'f.entity'] =
'Entity';
545 $this->export_fields_array[$r] = $this->export_fields_array[$r] + array(
546 'fd.rowid'=>
'LineId',
'fd.description'=>
"LineDescription",
547 'fd.subprice'=>
"LineUnitPrice",
'fd.tva_tx'=>
"LineVATRate",
'fd.qty'=>
"LineQty",
'fd.total_ht'=>
"LineTotalHT",
'fd.total_tva'=>
"LineTotalVAT",
548 'fd.total_ttc'=>
"LineTotalTTC",
'fd.buy_price_ht'=>
'BuyingPrice',
'fd.date_start'=>
"DateStart",
'fd.date_end'=>
"DateEnd",
'fd.special_code'=>
'SpecialCode',
549 'fd.product_type'=>
"TypeOfLineServiceOrProduct",
'fd.fk_product'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel',
550 $alias_product_perentity .
'.accountancy_code_sell'=>
'ProductAccountancySellCode',
551 'aa.account_number' =>
'AccountingAffectation'
553 $this->export_TypeFields_array[$r] = array(
554 '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',
555 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
557 '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",
'f.fk_mode_reglement'=>
'Numeric',
558 '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',
559 'none.rest'=>
"NumericCompute",
560 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
561 'f.module_source' =>
'Text',
562 'f.pos_source' =>
'Text',
563 'f.entity'=>
'List:entity:label:rowid',
564 'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
565 'pj.ref'=>
'Text',
'pj.title'=>
'Text',
'fd.rowid'=>
'Numeric',
'fd.description'=>
"Text",
'fd.subprice'=>
"Numeric",
'fd.tva_tx'=>
"Numeric",
566 'fd.qty'=>
"Numeric",
'fd.total_ht'=>
"Numeric",
'fd.total_tva'=>
"Numeric",
'fd.total_ttc'=>
"Numeric",
'fd.buy_price_ht'=>
"Numeric",
'fd.date_start'=>
"Date",
'fd.date_end'=>
"Date",
567 'fd.special_code'=>
'Numeric',
'fd.product_type'=>
"Numeric",
'fd.fk_product'=>
'List:product:label',
'p.ref'=>
'Text',
'p.label'=>
'Text',
568 $alias_product_perentity .
'.accountancy_code_sell'=>
'Text',
569 'aa.account_number' =>
'Text'
571 $this->export_entities_array[$r] = array(
572 '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',
573 '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',
574 't.libelle'=>
'company',
575 'pj.ref'=>
'project',
'pj.title'=>
'project',
'fd.rowid'=>
'invoice_line',
'fd.description'=>
"invoice_line",
576 'fd.subprice'=>
"invoice_line",
'fd.total_ht'=>
"invoice_line",
'fd.total_tva'=>
"invoice_line",
'fd.total_ttc'=>
"invoice_line",
'fd.buy_price_ht'=>
'invoice_line',
'fd.tva_tx'=>
"invoice_line",
577 'fd.qty'=>
"invoice_line",
'fd.date_start'=>
"invoice_line",
'fd.date_end'=>
"invoice_line",
'fd.special_code'=>
'invoice_line',
578 'fd.product_type'=>
'invoice_line',
'fd.fk_product'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product', $alias_product_perentity .
'.accountancy_code_sell'=>
'product',
579 'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
580 'aa.account_number' =>
"invoice_line",
582 $this->export_help_array[$r] = array(
'fd.buy_price_ht'=>
'CostPriceUsage');
583 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
584 $this->export_dependencies_array[$r] = array(
'invoice_line'=>
'fd.rowid',
'product'=>
'fd.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
585 $keyforselect =
'facture';
586 $keyforelement =
'invoice';
587 $keyforaliasextra =
'extra';
588 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
589 $keyforselect =
'facturedet';
590 $keyforelement =
'invoice_line';
591 $keyforaliasextra =
'extra2';
592 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
593 $keyforselect =
'product';
594 $keyforelement =
'product';
595 $keyforaliasextra =
'extra3';
596 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
597 $keyforselect =
'societe';
598 $keyforelement =
'company';
599 $keyforaliasextra =
'extra4';
600 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
601 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
602 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
603 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
604 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
605 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_typent as t ON s.fk_typent = t.id';
606 if (empty($user->rights->societe->client->voir)) {
607 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
609 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
610 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
611 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
612 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
613 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
614 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
615 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
616 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'facturedet as fd';
617 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
618 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on (fd.fk_product = p.rowid)';
619 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
620 $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);
622 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
623 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
624 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
625 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
626 if (empty($user->rights->societe->client->voir)) {
627 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
632 $this->export_code[$r] = $this->rights_class.
'_'.$r;
633 $this->export_label[$r] =
'CustomersInvoicesAndPayments';
634 $this->export_icon[$r] =
'invoice';
635 $this->export_permission[$r] = array(array(
"facture",
"facture",
"export"));
636 $this->export_fields_array[$r] = array(
637 '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',
639 's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
's.code_compta'=>
'CustomerAccountancyCode',
640 's.code_compta_fournisseur'=>
'SupplierAccountancyCode',
's.tva_intra'=>
'VATIntra',
641 'f.rowid'=>
"InvoiceId",
'f.ref'=>
"InvoiceRef",
'f.ref_client'=>
'RefCustomer',
'f.fk_facture_source'=>
'SourceInvoiceId',
642 'f.type'=>
"Type",
'f.datec'=>
"InvoiceDateCreation",
'f.datef'=>
"DateInvoice",
'f.date_lim_reglement'=>
"DateDue",
'f.total_ht'=>
"TotalHT",
643 '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',
645 'f.note_private'=>
"NotePrivate",
'f.note_public'=>
"NotePublic",
'f.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
646 'f.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
'pj.ref'=>
'ProjectRef',
'pj.title'=>
'ProjectLabel',
'p.rowid'=>
'PaymentId',
'p.ref'=>
'PaymentRef',
647 'p.amount'=>
'AmountPayment',
'pf.amount'=>
'AmountPaymentDistributedOnInvoice',
'p.datep'=>
'DatePayment',
'p.num_paiement'=>
'PaymentNumber',
648 'pt.code'=>
'CodePaymentMode',
'pt.libelle'=>
'LabelPaymentMode',
'p.note'=>
'PaymentNote',
'p.fk_bank'=>
'IdTransaction',
'ba.ref'=>
'AccountRef'
650 $this->export_help_array[$r] = array(
'f.paye'=>
'InvoicePaidCompletelyHelp');
651 if (isModEnabled(
"multicurrency")) {
652 $this->export_fields_array[$r][
'f.multicurrency_code'] =
'Currency';
653 $this->export_fields_array[$r][
'f.multicurrency_tx'] =
'CurrencyRate';
654 $this->export_fields_array[$r][
'f.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
655 $this->export_fields_array[$r][
'f.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
656 $this->export_fields_array[$r][
'f.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
657 $this->export_examplevalues_array[$r][
'f.multicurrency_code'] =
'EUR';
659 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
660 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
661 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
663 $this->export_TypeFields_array[$r] = array(
664 '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',
665 's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
's.code_compta'=>
'Text',
's.code_compta_fournisseur'=>
'Text',
's.tva_intra'=>
'Text',
666 '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",
667 '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',
668 'none.rest'=>
'NumericCompute',
669 'f.note_private'=>
"Text",
'f.note_public'=>
"Text",
'f.fk_user_author'=>
'Numeric',
'uc.login'=>
'Text',
'f.fk_user_valid'=>
'Numeric',
'uv.login'=>
'Text',
670 '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',
671 'p.fk_bank'=>
'Numeric',
'p.note'=>
'Text',
'pt.code'=>
'Text',
'pt.libelle'=>
'text',
'ba.ref'=>
'Text'
673 if (!empty($conf->cashdesk->enabled) || !empty($conf->takepos->enabled) || !empty($conf->global->INVOICE_SHOW_POS)) {
674 $this->export_fields_array[$r][
'f.module_source'] =
'POSModule';
675 $this->export_fields_array[$r][
'f.pos_source'] =
'POSTerminal';
677 $this->export_entities_array[$r] = array(
678 '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',
679 's.siren'=>
'company',
's.siret'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.code_compta'=>
'company',
's.code_compta_fournisseur'=>
'company',
680 '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',
681 'p.num_paiement'=>
'payment',
'pt.code'=>
'payment',
'pt.libelle'=>
'payment',
'p.note'=>
'payment',
'f.fk_user_author'=>
'user',
'uc.login'=>
'user',
682 'f.fk_user_valid'=>
'user',
'uv.login'=>
'user',
'p.fk_bank'=>
'account',
'ba.ref'=>
'account'
684 $this->export_special_array[$r] = array(
'none.rest'=>
'getRemainToPay');
685 $this->export_dependencies_array[$r] = array(
'payment'=>
'p.rowid',
'none.rest'=>array(
'f.rowid',
'f.total_ttc',
'f.close_code'));
686 $keyforselect =
'facture';
687 $keyforelement =
'invoice';
688 $keyforaliasextra =
'extra';
689 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
690 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
691 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
692 if (empty($user->rights->societe->client->voir)) {
693 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
695 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c on s.fk_pays = c.rowid';
696 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as cd on s.fk_departement = cd.rowid,';
697 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'facture as f';
698 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON f.fk_projet = pj.rowid';
699 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON f.fk_user_author = uc.rowid';
700 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON f.fk_user_valid = uv.rowid';
701 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'facture_extrafields as extra ON f.rowid = extra.fk_object';
702 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement_facture as pf ON pf.fk_facture = f.rowid';
703 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'paiement as p ON pf.fk_paiement = p.rowid';
704 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as pt ON pt.id = p.fk_paiement';
705 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON b.rowid = p.fk_bank';
706 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON ba.rowid = b.fk_account';
707 $this->export_sql_end[$r] .=
' WHERE f.fk_soc = s.rowid';
708 $this->export_sql_end[$r] .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
709 if (empty($user->rights->societe->client->voir)) {
710 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);