dolibarr 21.0.0-beta
modFournisseur.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com>
7 * Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
33include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
34
35
40{
46 public function __construct($db)
47 {
48 global $conf, $langs, $user, $mysoc;
49
50 $this->db = $db;
51 $this->numero = 40;
52
53 // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
54 // It is used to group modules in module setup page
55 $this->family = "srm";
56 $this->module_position = '12';
57 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
58 $this->name = preg_replace('/^mod/i', '', get_class($this));
59 $this->description = "Gestion des fournisseurs";
60
61 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
62 $this->version = 'dolibarr';
63
64 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65 $this->picto = 'company';
66
67 // Data directories to create when module is enabled
68 $this->dirs = array(
69 "/fournisseur/temp",
70 "/fournisseur/commande",
71 "/fournisseur/commande/temp",
72 "/fournisseur/facture",
73 "/fournisseur/facture/temp"
74 );
75
76 // Dependencies
77 $this->depends = array("modSociete");
78 $this->requiredby = array("modSupplierProposal");
79 $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
80
81 // Config pages
82 $this->config_page_url = array("supplier_order.php");
83
84 // Constants
85 $this->const = array();
86 $r = 0;
87
88 $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
89 $this->const[$r][1] = "chaine";
90 $this->const[$r][2] = "cornas";
91 $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
92 $this->const[$r][4] = 0;
93 $r++;
94
95 $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
96 $this->const[$r][1] = "chaine";
97 $this->const[$r][2] = "mod_commande_fournisseur_muguet";
98 $this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
99 $this->const[$r][4] = 0;
100 $r++;
101
102 /* For supplier invoice, we must not have default pdf template on. In most cases, we need to join PDF from supplier, not have a document generated.
103 $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_PDF";
104 $this->const[$r][1] = "chaine";
105 $this->const[$r][2] = "canelle";
106 $this->const[$r][3] = 'Nom du gestionnaire de generation des factures fournisseur en PDF';
107 $this->const[$r][4] = 0;
108 $r++;
109 */
110
111 $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
112 $this->const[$r][1] = "chaine";
113 $this->const[$r][2] = "mod_facture_fournisseur_cactus";
114 $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
115 $this->const[$r][4] = 0;
116 $r++;
117
118 // Add ability ODT for Supplier orders
119 $this->const[$r][0] = "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH";
120 $this->const[$r][1] = "chaine";
121 $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/supplier_orders";
122 $this->const[$r][3] = '';
123 $this->const[$r][4] = 0;
124 $r++;
125
126 // Add ability ODT for Supplier Invoices
127 $this->const[$r][0] = "SUPPLIER_INVOICE_ADDON_PDF_ODT_PATH";
128 $this->const[$r][1] = "chaine";
129 $this->const[$r][2] = "";
130 $this->const[$r][3] = "";
131 $this->const[$r][4] = 0;
132 $r++;
133
134 // Boxes
135 $this->boxes = array(
136 0 => array('file' => 'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton' => 'Home'),
137 1 => array('file' => 'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton' => 'Home'),
138 2 => array('file' => 'box_fournisseurs.php', 'enabledbydefaulton' => 'Home'),
139 3 => array('file' => 'box_factures_fourn_imp.php', 'enabledbydefaulton' => 'Home'),
140 4 => array('file' => 'box_factures_fourn.php', 'enabledbydefaulton' => 'Home'),
141 5 => array('file' => 'box_supplier_orders.php', 'enabledbydefaulton' => 'Home'),
142 6 => array('file' => 'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton' => 'Home'),
143 );
144
145 $arraydate = dol_getdate(dol_now());
146 $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
147 $this->cronjobs = array(
148 0 => array(
149 'label' => 'RecurringSupplierInvoicesJob',
150 'jobtype' => 'method',
151 'class' => 'fourn/class/fournisseur.facture-rec.class.php',
152 'objectname' => 'FactureFournisseurRec',
153 'method' => 'createRecurringInvoices',
154 'parameters' => '',
155 'comment' => 'Generate recurring supplier invoices',
156 'frequency' => 1,
157 'unitfrequency' => 3600 * 24,
158 'priority' => 51,
159 'status' => 1,
160 'test' => 'isModEnabled("supplier_invoice")',
161 'datestart' => $datestart
162 ),
163 1 => array(
164 'label' => 'SendEmailsRemindersOnSupplierInvoiceDueDate',
165 'jobtype' => 'method',
166 'class' => 'fourn/class/fournisseur.facture.class.php',
167 'objectname' => 'FactureFournisseur',
168 'method' => 'sendEmailsRemindersOnSupplierInvoiceDueDate',
169 'parameters' => '10,all,EmailTemplateCode,duedate',
170 '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.',
171 'frequency' => 1,
172 'unitfrequency' => 3600 * 24,
173 'priority' => 50,
174 'status' => 0,
175 'test' => 'isModEnabled("supplier_invoice")',
176 'datestart' => $datestart
177 ));
178
179
180 // Permissions
181 $this->rights = array();
182 $this->rights_class = 'fournisseur';
183 $r = 0;
184
185 $r++;
186 $this->rights[$r][0] = 1181;
187 $this->rights[$r][1] = 'Consulter les fournisseurs';
188 $this->rights[$r][2] = 'r';
189 $this->rights[$r][3] = 0;
190 $this->rights[$r][4] = 'lire';
191
192 $r++;
193 $this->rights[$r][0] = 1182;
194 $this->rights[$r][1] = 'Consulter les commandes fournisseur';
195 $this->rights[$r][2] = 'r';
196 $this->rights[$r][3] = 0;
197 $this->rights[$r][4] = 'commande';
198 $this->rights[$r][5] = 'lire';
199
200 $r++;
201 $this->rights[$r][0] = 1183;
202 $this->rights[$r][1] = 'Creer une commande fournisseur';
203 $this->rights[$r][2] = 'w';
204 $this->rights[$r][3] = 0;
205 $this->rights[$r][4] = 'commande';
206 $this->rights[$r][5] = 'creer';
207
208 $r++;
209 $this->rights[$r][0] = 1184;
210 $this->rights[$r][1] = 'Valider une commande fournisseur';
211 $this->rights[$r][2] = 'w';
212 $this->rights[$r][3] = 0;
213 $this->rights[$r][4] = 'supplier_order_advance';
214 $this->rights[$r][5] = 'validate';
215
216 $r++;
217 $this->rights[$r][0] = 1185;
218 $this->rights[$r][1] = 'Approuver une commande fournisseur';
219 $this->rights[$r][2] = 'w';
220 $this->rights[$r][3] = 0;
221 $this->rights[$r][4] = 'commande';
222 $this->rights[$r][5] = 'approuver';
223
224 $r++;
225 $this->rights[$r][0] = 1186;
226 $this->rights[$r][1] = 'Commander une commande fournisseur';
227 $this->rights[$r][2] = 'w';
228 $this->rights[$r][3] = 0;
229 $this->rights[$r][4] = 'commande';
230 $this->rights[$r][5] = 'commander';
231
232 $r++;
233 $this->rights[$r][0] = 1187;
234 $this->rights[$r][1] = 'Receptionner une commande fournisseur';
235 $this->rights[$r][2] = 'd';
236 $this->rights[$r][3] = 0;
237 $this->rights[$r][4] = 'commande';
238 $this->rights[$r][5] = 'receptionner';
239
240 $r++;
241 $this->rights[$r][0] = 1189;
242 $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
243 $this->rights[$r][2] = 'w';
244 $this->rights[$r][3] = 0;
245 $this->rights[$r][4] = 'commande_advance';
246 $this->rights[$r][5] = 'check';
247
248 $r++;
249 $this->rights[$r][0] = 1188;
250 $this->rights[$r][1] = 'Supprimer une commande fournisseur';
251 $this->rights[$r][2] = 'd';
252 $this->rights[$r][3] = 0;
253 $this->rights[$r][4] = 'commande';
254 $this->rights[$r][5] = 'supprimer';
255
256 if (getDolGlobalString('SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
257 $r++;
258 $this->rights[$r][0] = 1190;
259 $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
260 $this->rights[$r][2] = 'w';
261 $this->rights[$r][3] = 0;
262 $this->rights[$r][4] = 'commande';
263 $this->rights[$r][5] = 'approve2';
264 }
265
266 $r++;
267 $this->rights[$r][0] = 1191;
268 $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
269 $this->rights[$r][2] = 'r';
270 $this->rights[$r][3] = 0;
271 $this->rights[$r][4] = 'commande';
272 $this->rights[$r][5] = 'export';
273
274 $r++;
275 $this->rights[$r][0] = 1231;
276 $this->rights[$r][1] = 'Consulter les factures fournisseur';
277 $this->rights[$r][2] = 'r';
278 $this->rights[$r][3] = 0;
279 $this->rights[$r][4] = 'facture';
280 $this->rights[$r][5] = 'lire';
281
282 $r++;
283 $this->rights[$r][0] = 1232;
284 $this->rights[$r][1] = 'Creer une facture fournisseur';
285 $this->rights[$r][2] = 'w';
286 $this->rights[$r][3] = 0;
287 $this->rights[$r][4] = 'facture';
288 $this->rights[$r][5] = 'creer';
289
290 $r++;
291 $this->rights[$r][0] = 1233;
292 $this->rights[$r][1] = 'Valider une facture fournisseur';
293 $this->rights[$r][2] = 'w';
294 $this->rights[$r][3] = 0;
295 $this->rights[$r][4] = 'supplier_invoice_advance';
296 $this->rights[$r][5] = 'validate';
297
298 $r++;
299 $this->rights[$r][0] = 1234;
300 $this->rights[$r][1] = 'Supprimer une facture fournisseur';
301 $this->rights[$r][2] = 'd';
302 $this->rights[$r][3] = 0;
303 $this->rights[$r][4] = 'facture';
304 $this->rights[$r][5] = 'supprimer';
305
306 $r++;
307 $this->rights[$r][0] = 1235;
308 $this->rights[$r][1] = 'Envoyer les factures par mail';
309 $this->rights[$r][2] = 'a';
310 $this->rights[$r][3] = 0;
311 $this->rights[$r][4] = 'supplier_invoice_advance';
312 $this->rights[$r][5] = 'send';
313
314 $r++;
315 $this->rights[$r][0] = 1236;
316 $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributes et reglements';
317 $this->rights[$r][2] = 'r';
318 $this->rights[$r][3] = 0;
319 $this->rights[$r][4] = 'facture';
320 $this->rights[$r][5] = 'export';
321
322
323 // Menus
324 //-------
325 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
326
327
328 // Exports
329 //--------
330 $uselocaltax1 = (is_object($mysoc) && $mysoc->localtax1_assuj) ? $mysoc->localtax1_assuj : 0;
331 $uselocaltax2 = (is_object($mysoc) && $mysoc->localtax2_assuj) ? $mysoc->localtax2_assuj : 0;
332
333 $r = 0;
334
335 $langs->loadLangs(array("suppliers", "compta", "multicurrency", "bills"));
336
337 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
338
339 $r++;
340 $this->export_code[$r] = $this->rights_class.'_'.$r;
341 $this->export_label[$r] = 'Vendor invoices and lines of invoices';
342 $this->export_icon[$r] = 'invoice';
343 $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
344 $this->export_fields_array[$r] = array(
345 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
346 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
347 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
348 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>'DateMaxPayment',
349 'f.fk_cond_reglement'=>'IdPaymentTerm', 'f.fk_mode_reglement'=>'IdPaymentMode',
350 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT",
351 'f.localtax1'=>"TotalLT1", 'f.localtax2'=>"TotalLT2",
352 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote",
353 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount",
354 'fd.tva_tx'=>"LineVATRate", 'fd.total_ht'=>"LineTotalHT", 'fd.total_ttc'=>"LineTotalTTC", 'fd.tva'=>"LineTotalVAT",
355 'fd.localtax1_tx'=>"LineLT1Rate", 'fd.localtax1_type'=>"LineLT1Type", 'fd.total_localtax1'=>"LineTotalLT1",
356 'fd.localtax2_tx'=>"LineLT2Rate", 'fd.localtax2_type'=>"LineLT2Type", 'fd.total_localtax2'=>"LineTotalLT2",
357 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
358 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.fk_product'=>'ProductId',
359 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', $alias_product_perentity.'.accountancy_code_buy'=>'ProductAccountancyBuyCode', 'project.rowid'=>'ProjectId',
360 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
361 );
362 if (!$uselocaltax1) {
363 unset($this->export_fields_array[$r]['fd.localtax1_tx']);
364 unset($this->export_fields_array[$r]['fd.localtax1_type']);
365 unset($this->export_fields_array[$r]['fd.total_localtax1']);
366 }
367 if (!$uselocaltax2) {
368 unset($this->export_fields_array[$r]['fd.localtax2_tx']);
369 unset($this->export_fields_array[$r]['fd.localtax2_type']);
370 unset($this->export_fields_array[$r]['fd.total_localtax2']);
371 }
372
373 if (isModEnabled("multicurrency")) {
374 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
375 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
376 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
377 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
378 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
379 }
380 if (!$uselocaltax1) {
381 unset($this->export_fields_array[$r]['f.localtax1']);
382 }
383 if (!$uselocaltax2) {
384 unset($this->export_fields_array[$r]['f.localtax2']);
385 }
386
387 //$this->export_TypeFields_array[$r]=array(
388 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text',
389 // 's.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",
390 // 'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",
391 // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
392 //);
393 $this->export_TypeFields_array[$r] = array(
394 's.rowid' => 'Numeric', 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text',
395 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
396 'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>'Date',
397 'f.fk_cond_reglement'=>'Numeric', 'f.fk_mode_reglement'=>'Numeric',
398 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.localtax1'=>"Numeric", 'f.localtax2'=>"Numeric",
399 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text",
400 'fd.rowid'=>'Numeric', 'fd.description'=>"Text", 'fd.tva_tx'=>"Text",
401 'fd.qty'=>"Numeric", 'fd.remise_percent'=>"Numeric",
402 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.tva'=>"Numeric", 'fd.total_localtax1'=>"Numeric", 'fd.total_localtax2'=>"Numeric",
403 'fd.localtax1_tx'=>'Numeric', 'fd.localtax2_tx'=>'Numeric', 'fd.localtax1_type'=>'Numeric', 'fd.localtax2_type'=>'Numeric',
404 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
405 'fd.product_type'=>'Numeric', 'fd.fk_product'=>'List:product:label', $alias_product_perentity . '.accountancy_code_buy'=>'Text',
406 'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text',
407 'f.multicurrency_code' => 'Text',
408 'f.multicurrency_tx' => 'Number', 'f.multicurrency_total_ht' => 'Number', 'f.multicurrency_total_tva' => 'Number', 'f.multicurrency_total_ttc' => 'Number'
409 );
410 $this->export_entities_array[$r] = array(
411 's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company',
412 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'f.rowid'=>"invoice",
413 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.date_lim_reglement'=>'invoice',
414 'f.fk_cond_reglement'=>'invoice', 'f.fk_mode_reglement'=>'invoice',
415 'f.total_ht'=>"invoice", 'f.total_ttc'=>"invoice", 'f.total_tva'=>"invoice",
416 'f.paye'=>"invoice", 'f.fk_statut'=>'invoice', 'f.note_public'=>"invoice", 'fd.rowid'=>'invoice_line', 'fd.description'=>"invoice_line", 'fd.qty'=>"invoice_line",
417 'fd.total_ht'=>"invoice_line", 'fd.tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.total_localtax1'=>"invoice_line", 'fd.total_localtax2'=>"invoice_line",
418 '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",
419 'fd.remise_percent'=>"invoice_line",
420 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>"invoice_line",
421 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product',
422 'p.ref'=>'product', 'p.label'=>'product', $alias_product_perentity.'.accountancy_code_buy'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
423 );
424 $this->export_dependencies_array[$r] = array('invoice_line' => 'fd.rowid', 'product' => 'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
425 // Add extra fields object
426 $keyforselect = 'facture_fourn';
427 $keyforelement = 'invoice';
428 $keyforaliasextra = 'extra';
429 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
430 $keyforselect = 'facture_fourn_det';
431 $keyforelement = 'invoice_line';
432 $keyforaliasextra = 'extraline';
433 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
434 // End add extra fields line
435 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
436 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
437 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
438 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
439 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
440 }
441 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
442 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
443 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
444 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
445 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON f.fk_mode_reglement = cp.id';
446 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid,';
447 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
448 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
449 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
450 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
451 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
452 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
453 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
454 }
455
456 // Invoices and payments
457 $r++;
458 $this->export_code[$r] = $this->rights_class.'_'.$r;
459 $this->export_label[$r] = 'Factures fournisseurs et reglements';
460 $this->export_icon[$r] = 'invoice';
461 $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
462 $this->export_fields_array[$r] = array(
463 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
464 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
465 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
466 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateMaxPayment",
467 'f.fk_cond_reglement'=>'IdPaymentTerm', 'f.fk_mode_reglement'=>'IdPaymentMode',
468 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT",
469 'f.localtax1'=>"TotalLT1", 'f.localtax2'=>"TotalLT2",
470 'f.paye'=>"InvoicePaid",
471 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote", 'p.rowid'=>'PaymentId', 'pf.amount'=>'AmountPayment',
472 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'p.fk_bank'=>'IdTransaction', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
473 );
474 if (!$uselocaltax1) {
475 unset($this->export_fields_array[$r]['f.localtax1']);
476 }
477 if (!$uselocaltax2) {
478 unset($this->export_fields_array[$r]['f.localtax2']);
479 }
480 if (isModEnabled("multicurrency")) {
481 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
482 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
483 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
484 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
485 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
486 }
487 //$this->export_TypeFields_array[$r]=array(
488 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
489 // 's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",
490 // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
491 // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
492 //);
493 $this->export_TypeFields_array[$r] = array(
494 's.rowid'=>'Numeric', 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text',
495 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
496 'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text",
497 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>'Date',
498 'f.fk_cond_reglement'=>'Numeric', 'f.fk_mode_reglement'=>'Numeric',
499 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.localtax1'=>"Numeric", 'f.localtax2'=>"Numeric",
500 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'pf.amount'=>'Numeric',
501 'p.rowid'=>'Numeric', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'project.rowid'=>'Numeric', 'project.ref'=>'Text', 'project.title'=>'Text',
502 'f.multicurrency_code' => 'Text',
503 'f.multicurrency_tx' => 'Number', 'f.multicurrency_total_ht' => 'Number', 'f.multicurrency_total_tva' => 'Number', 'f.multicurrency_total_ttc' => 'Number'
504 );
505 $this->export_entities_array[$r] = array(
506 's.rowid' => "company", 's.nom' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'c.code' => 'company', 's.phone' => 'company',
507 's.siren' => 'company', 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.idprof5' => 'company', 's.idprof6' => 'company',
508 's.code_compta' => 'company', 's.code_compta_fournisseur' => 'company', 's.tva_intra' => 'company',
509 'f.rowid' => "invoice", 'f.ref' => "invoice", 'f.ref_supplier' => "invoice", 'f.datec' => "invoice", 'f.datef' => "invoice", 'f.date_lim_reglement' => 'invoice',
510 'f.fk_cond_reglement' => 'invoice', 'f.fk_mode_reglement' => 'invoice',
511 'f.total_ht' => "invoice", 'f.total_ttc' => "invoice", 'f.total_tva' => "invoice", 'f.paye' => "invoice", 'f.fk_statut' => 'invoice', 'f.note_public' => "invoice", 'p.rowid' => 'payment', 'pf.amount' => 'payment',
512 'p.datep' => 'payment', 'p.num_paiement' => 'payment', 'p.fk_bank' => 'account', 'project.rowid' => 'project', 'project.ref' => 'project', 'project.title' => 'project');
513 $this->export_dependencies_array[$r] = array('payment' => 'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
514 // Add extra fields object
515 $keyforselect = 'facture_fourn';
516 $keyforelement = 'invoice';
517 $keyforaliasextra = 'extra';
518 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
519 // End add extra fields object
520 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
521 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
522 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
523 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
524 }
525 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
526 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
527 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
528 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
529 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
530 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
531 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON f.fk_mode_reglement = cp.id';
532 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cpt ON f.fk_cond_reglement = cpt.rowid';
533 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
534 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
535 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
536 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
537 }
538
539 // Order
540 $r++;
541 $this->export_code[$r] = $this->rights_class.'_'.$r;
542 $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
543 $this->export_icon[$r] = 'order';
544 $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
545 $this->export_fields_array[$r] = array(
546 's.rowid' => "IdCompany", 's.nom' => 'CompanyName', 'ps.nom' => 'ParentCompany', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'c.code' => 'CountryCode', 's.phone' => 'Phone',
547 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 's.idprof5' => 'ProfId5', 's.idprof6' => 'ProfId6', 's.tva_intra' => 'VATIntra',
548 'f.rowid' => "OrderId", 'f.ref' => "Ref", 'f.ref_supplier' => "RefSupplier", 'f.date_creation' => "DateCreation", 'f.date_commande' => "OrderDate", 'f.date_livraison' => "DateDeliveryPlanned",
549 'f.total_ht' => "TotalHT", 'f.total_ttc' => "TotalTTC", 'f.total_tva' => "TotalVAT", 'f.fk_statut' => 'Status', 'f.date_valid' => 'DateValidation', 'f.date_approve' => 'DateApprove', 'f.date_approve2' => 'DateApprove2',
550 'f.note_public' => "NotePublic", 'f.note_private' => "NotePrivate", 'uv.login' => 'UserValidation', 'ua1.login' => 'ApprovedBy', 'ua2.login' => 'ApprovedBy2', 'fd.rowid' => 'LineId', 'fd.description' => "LineDescription",
551 'fd.tva_tx' => "LineVATRate", 'fd.qty' => "LineQty", 'fd.remise_percent' => "Discount", 'fd.total_ht' => "LineTotalHT", 'fd.total_ttc' => "LineTotalTTC",
552 'fd.total_tva' => "LineTotalVAT", 'fd.date_start' => "DateStart", 'fd.date_end' => "DateEnd", 'fd.special_code' => 'SpecialCode',
553 'fd.product_type' => 'TypeOfLineServiceOrProduct', 'fd.ref' => 'SupplierRef', 'fd.fk_product' => 'ProductId',
554 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel', 'project.rowid' => 'ProjectId', 'project.ref' => 'ProjectRef', 'project.title' => 'ProjectLabel'
555 );
556 if (isModEnabled("multicurrency")) {
557 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
558 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
559 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
560 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
561 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
562 }
563 if (!getDolGlobalString('SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
564 unset($this->export_fields_array['f.date_approve2']);
565 unset($this->export_fields_array['ua2.login']);
566 }
567 $this->export_TypeFields_array[$r] = array(
568 's.rowid' => "company", 's.nom' => 'Text', 'ps.nom' => 'Text', 's.address' => 'Text', 's.cp' => 'Text', 's.ville' => 'Text', 'c.code' => 'Text', 's.tel' => 'Text', 's.siren' => 'Text',
569 's.siret' => 'Text', 's.ape' => 'Text', 's.idprof4' => 'Text', 's.idprof5' => 'Text', 's.idprof6' => 'Text', 's.tva_intra' => 'Text', 'f.ref' => "Text", 'f.ref_supplier' => "Text",
570 'f.date_creation' => "Date", 'f.date_commande' => "Date", 'f.date_livraison' => "Date", 'f.total_ht' => "Numeric", 'f.total_ttc' => "Numeric", 'f.total_tva' => "Numeric",
571 'f.fk_statut' => 'Status', 'f.date_valid' => 'Date', 'f.date_approve' => 'Date', 'f.date_approve2' => 'Date', 'f.note_public' => "Text", 'f.note_private' => "Text", 'fd.description' => "Text",
572 'fd.tva_tx' => "Numeric", 'fd.qty' => "Numeric", 'fd.remise_percent' => "Numeric", 'fd.total_ht' => "Numeric", 'fd.total_ttc' => "Numeric", 'fd.total_tva' => "Numeric",
573 'fd.date_start' => "Date", 'fd.date_end' => "Date", 'fd.special_code' => "Numeric",
574 'fd.product_type' => 'Numeric', 'fd.ref' => 'Text', 'fd.fk_product' => 'List:product:label', 'p.ref' => 'Text', 'p.label' => 'Text', 'project.ref' => 'Text', 'project.title' => 'Text'
575 );
576 $this->export_entities_array[$r] = array(
577 's.rowid' => "company", 's.nom' => 'company', 'ps.nom' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'c.code' => 'company', 's.phone' => 'company', 's.siren' => 'company',
578 's.siret' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.idprof5' => 'company', 's.idprof6' => 'company', 's.tva_intra' => 'company', 'uv.login' => 'user', 'ua1.login' => 'user',
579 'ua2.login' => 'user', 'fd.rowid' => 'order_line', 'fd.description' => "order_line", 'fd.tva_tx' => "order_line", 'fd.qty' => "order_line", 'fd.remise_percent' => "order_line",
580 'fd.total_ht' => "order_line", 'fd.total_ttc' => "order_line", 'fd.total_tva' => "order_line", 'fd.date_start' => "order_line", 'fd.date_end' => "order_line", 'fd.special_code' => "order_line",
581 'fd.product_type' => 'order_line', 'fd.ref' => 'order_line', 'fd.fk_product' => 'product',
582 'p.ref' => 'product', 'p.label' => 'product', 'project.rowid' => 'project', 'project.ref' => 'project', 'project.title' => 'project'
583 );
584 $this->export_dependencies_array[$r] = array('order_line' => 'fd.rowid', 'product' => 'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
585 // Add extra fields object
586 $keyforselect = 'commande_fournisseur';
587 $keyforelement = 'order';
588 $keyforaliasextra = 'extra';
589 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
590 // End add extra fields object
591 // Add extra fields line
592 $keyforselect = 'commande_fournisseurdet';
593 $keyforelement = 'order_line';
594 $keyforaliasextra = 'extraline';
595 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
596 // End add extra fields line
597 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
598 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
599 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
600 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
601 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
602 }
603 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
604 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
605 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
606 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON uv.rowid = f.fk_user_valid';
607 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
608 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
609 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
610 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
611 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
612 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
613 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
614 $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')';
615 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
616 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
617 }
618
619 //Import Supplier Invoice
620 //--------
621 $r = 0;
622
623 $r++;
624 $this->import_code[$r] = $this->rights_class.'_'.$r;
625 $this->import_label[$r] = "SupplierInvoices"; // Translation key
626 $this->import_icon[$r] = $this->picto;
627 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
628 $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture_fourn', 'extra' => MAIN_DB_PREFIX.'facture_fourn_extrafields');
629 $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
630 $this->import_fields_array[$r] = array(
631 'f.ref' => 'InvoiceRef*',
632 'f.ref_supplier' => 'RefSupplier',
633 'f.type' => 'Type*',
634 'f.fk_soc' => 'Supplier/Vendor*',
635 'f.datec' => 'InvoiceDateCreation',
636 'f.datef' => 'DateInvoice',
637 'f.date_lim_reglement' => 'DateMaxPayment',
638 'f.total_ht' => 'TotalHT',
639 'f.total_ttc' => 'TotalTTC',
640 'f.total_tva' => 'TotalVAT',
641 'f.paye' => 'InvoicePaid',
642 'f.fk_statut' => 'InvoiceStatus',
643 'f.fk_user_modif' => 'Modifier Id',
644 'f.fk_user_valid' => 'Validator Id',
645 'f.fk_facture_source' => 'Invoice Source Id',
646 'f.fk_projet' => 'Project Id',
647 'f.fk_account' => 'Bank Account*',
648 'f.note_public' => 'InvoiceNote',
649 'f.note_private' => 'NotePrivate',
650 'f.fk_cond_reglement' => 'PaymentTerm',
651 'f.fk_mode_reglement' => 'PaymentMode',
652 'f.model_pdf' => 'Model',
653 'f.date_valid' => 'DateValidation'
654 );
655 if (isModEnabled("multicurrency")) {
656 $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
657 $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
658 $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
659 $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
660 $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
661 }
662 // Add extra fields
663 $import_extrafield_sample = array();
664 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
665 $resql = $this->db->query($sql);
666 if ($resql) {
667 while ($obj = $this->db->fetch_object($resql)) {
668 $fieldname = 'extra.'.$obj->name;
669 $fieldlabel = ucfirst($obj->label);
670 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
671 $import_extrafield_sample[$fieldname] = $fieldlabel;
672 }
673 }
674 // End add extra fields
675 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn');
676 if (empty($conf->multicurrency->enabled)) {
677 $this->import_fieldshidden_array[$r]['f.multicurrency_code'] = 'const-'.$conf->currency;
678 }
679 $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
680 $import_sample = array(
681 'f.ref' => '(PROV001)',
682 'f.ref_supplier' => 'Supplier1',
683 'f.type' => '0',
684 'f.fk_soc' => 'Vendor1',
685 'f.datec' => '2021-01-01',
686 'f.datef' => '',
687 'f.date_lim_reglement' => '2021-01-30',
688 'f.total_ht' => '1000',
689 'f.total_ttc' => '1000',
690 'f.total_tva' => '0',
691 'f.paye' => '0',
692 'f.fk_statut' => '0',
693 'f.fk_user_modif' => '',
694 'f.fk_user_valid' => '',
695 'f.fk_facture_source' => '',
696 'f.fk_projet' => '',
697 'f.fk_account' => 'BANK1',
698 'f.note_public' => 'Note: ',
699 'f.note_private' => '',
700 'f.fk_cond_reglement' => '1',
701 'f.fk_mode_reglement' => '2',
702 'f.model_pdf' => 'crab',
703 'f.date_valid' => '',
704 'f.multicurrency_code' => 'USD',
705 'f.multicurrency_tx' => '1',
706 'f.multicurrency_total_ht' => '1000',
707 'f.multicurrency_total_tva' => '0',
708 'f.multicurrency_total_ttc' => '1000'
709 );
710 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
711 $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
712 $this->import_convertvalue_array[$r] = array(
713 'f.ref' => array(
714 'rule' => 'getrefifauto',
715 'class' => (!getDolGlobalString('INVOICE_SUPPLIER_ADDON_NUMBER') ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
716 'path' => "/core/modules/supplier_invoice/".(!getDolGlobalString('INVOICE_SUPPLIER_ADDON_NUMBER') ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER).'.php',
717 'classobject' => 'FactureFournisseur',
718 'pathobject' => '/fourn/class/fournisseur.facture.class.php',
719 ),
720 'f.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
721 'f.fk_account' => array('rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'),
722 );
723
724 //Import Supplier Invoice Lines
725 $r++;
726 $this->import_code[$r] = $this->rights_class.'_'.$r;
727 $this->import_label[$r] = "SupplierInvoiceLines"; // Translation key
728 $this->import_icon[$r] = $this->picto;
729 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
730 $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facture_fourn_det', 'extra' => MAIN_DB_PREFIX.'facture_fourn_det_extrafields');
731 $this->import_fields_array[$r] = array(
732 'fd.fk_facture_fourn' => 'InvoiceRef*',
733 'fd.fk_parent_line' => 'ParentLine',
734 'fd.fk_product' => 'IdProduct',
735 'fd.description' => 'LineDescription',
736 'fd.pu_ht' => 'PriceUHT',
737 'fd.pu_ttc' => 'PriceUTTC',
738 'fd.qty' => 'LineQty',
739 'fd.remise_percent' => 'Reduc.',
740 'fd.vat_src_code' => 'Vat Source Code',
741 'fd.product_type' => 'TypeOfLineServiceOrProduct',
742 'fd.tva_tx' => 'LineVATRate',
743 'fd.total_ht' => 'LineTotalHT',
744 'fd.tva' => 'LineTotalVAT',
745 'fd.total_ttc' => 'LineTotalTTC',
746 'fd.date_start' => 'Start Date',
747 'fd.date_end' => 'End Date',
748 'fd.fk_unit' => 'Unit'
749 );
750 if (isModEnabled("multicurrency")) {
751 $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
752 $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
753 $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
754 $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
755 $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
756 }
757 // Add extra fields
758 $import_extrafield_sample = array();
759 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
760 $resql = $this->db->query($sql);
761 if ($resql) {
762 while ($obj = $this->db->fetch_object($resql)) {
763 $fieldname = 'extra.'.$obj->name;
764 $fieldlabel = ucfirst($obj->label);
765 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
766 $import_extrafield_sample[$fieldname] = $fieldlabel;
767 }
768 }
769 // End add extra fields
770 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn_det');
771 $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');
772 $import_sample = array(
773 'fd.fk_facture_fourn' => '(PROV001)',
774 'fd.fk_parent_line' => '',
775 'fd.fk_product' => '',
776 'fd.description' => 'Test Product',
777 'fd.pu_ht' => '50000',
778 'fd.pu_ttc' => '50000',
779 'fd.qty' => '1',
780 'fd.remise_percent' => '0',
781 'fd.vat_src_code' => '',
782 'fd.product_type' => '0',
783 'fd.tva_tx' => '0',
784 'fd.total_ht' => '50000',
785 'fd.tva' => '0',
786 'fd.total_ttc' => '50000',
787 'fd.date_start' => '',
788 'fd.date_end' => '',
789 'fd.fk_unit' => '',
790 'fd.multicurrency_code' => 'USD',
791 'fd.multicurrency_tx' => '0',
792 'fd.multicurrency_total_ht' => '50000',
793 'fd.multicurrency_total_tva' => '0',
794 'fd.multicurrency_total_ttc' => '50000'
795 );
796 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
797 $this->import_updatekeys_array[$r] = array('fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id');
798 $this->import_convertvalue_array[$r] = array(
799 'fd.fk_facture_fourn' => array('rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'),
800 );
801
802 //Import Purchase Orders
803 $r++;
804 $this->import_code[$r] = 'commande_fournisseur_'.$r;
805 $this->import_label[$r] = 'SuppliersOrders';
806 $this->import_icon[$r] = $this->picto;
807 $this->import_entities_array[$r] = array();
808 $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande_fournisseur', 'extra' => MAIN_DB_PREFIX.'commande_fournisseur_extrafields');
809 $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
810 $this->import_fields_array[$r] = array(
811 'c.ref' => 'Ref*',
812 'c.ref_supplier' => 'RefSupplier',
813 'c.fk_soc' => 'ThirdPartyName*',
814 'c.fk_projet' => 'ProjectId',
815 'c.date_creation' => 'DateCreation',
816 'c.date_valid' => 'DateValidation',
817 'c.date_approve' => 'DateApprove',
818 'c.date_commande' => 'DateOrder',
819 'c.fk_user_modif' => 'ModifiedById',
820 'c.fk_user_valid' => 'ValidatedById',
821 'c.fk_user_approve' => 'ApprovedById',
822 'c.source' => 'Source',
823 'c.fk_statut' => 'Status*',
824 'c.billed' => 'Billed',
825 'c.total_tva' => 'TotalTVA',
826 'c.total_ht' => 'TotalHT',
827 'c.total_ttc' => 'TotalTTC',
828 'c.note_private' => 'NotePrivate',
829 'c.note_public' => 'Note',
830 'c.date_livraison' => 'DeliveryDate',
831 'c.fk_cond_reglement' => 'Payment Condition',
832 'c.fk_mode_reglement' => 'Payment Mode',
833 'c.model_pdf' => 'Model'
834 );
835
836 if (isModEnabled("multicurrency")) {
837 $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
838 $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
839 $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
840 $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
841 $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
842 }
843
844 // Add extra fields
845 $import_extrafield_sample = array();
846 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
847 $resql = $this->db->query($sql);
848
849 if ($resql) {
850 while ($obj = $this->db->fetch_object($resql)) {
851 $fieldname = 'extra.'.$obj->name;
852 $fieldlabel = ucfirst($obj->label);
853 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
854 $import_extrafield_sample[$fieldname] = $fieldlabel;
855 }
856 }
857 // End add extra fields
858
859 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseur');
860 $this->import_regex_array[$r] = array(
861 'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
862 );
863
864 $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
865 $this->import_convertvalue_array[$r] = array(
866 'c.ref' => array(
867 'rule' => 'getrefifauto',
868 'class' => (!getDolGlobalString('COMMANDE_SUPPLIER_ADDON_NUMBER') ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
869 'path' => "/core/modules/supplier_order/".(!getDolGlobalString('COMMANDE_SUPPLIER_ADDON_NUMBER') ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER).'.php',
870 'classobject' => 'CommandeFournisseur',
871 'pathobject' => '/fourn/class/fournisseur.commande.class.php',
872 ),
873 'c.fk_soc' => array(
874 'rule' => 'fetchidfromref',
875 'file' => '/societe/class/societe.class.php',
876 'class' => 'Societe',
877 'method' => 'fetch',
878 'element' => 'ThirdParty'
879 ),
880 'c.fk_mode_reglement' => array(
881 'rule' => 'fetchidfromcodeorlabel',
882 'file' => '/compta/paiement/class/cpaiement.class.php',
883 'class' => 'Cpaiement',
884 'method' => 'fetch',
885 'element' => 'cpayment'
886 ),
887 'c.source' => array('rule' => 'zeroifnull'),
888 );
889
890 // Import PO Lines
891 $r++;
892 $this->import_code[$r] = 'commande_fournisseurdet_'.$r;
893 $this->import_label[$r] = 'PurchaseOrderLines';
894 $this->import_icon[$r] = $this->picto;
895 $this->import_entities_array[$r] = array();
896 $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX.'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields');
897 $this->import_fields_array[$r] = array(
898 'cd.fk_commande' => 'PurchaseOrder*',
899 'cd.fk_parent_line' => 'ParentLine',
900 'cd.fk_product' => 'IdProduct',
901 'cd.ref' => 'SupplierRef',
902 'cd.description' => 'LineDescription',
903 'cd.tva_tx' => 'LineVATRate',
904 'cd.qty' => 'LineQty',
905 'cd.remise_percent' => 'Reduc. Percent',
906 'cd.subprice' => 'Sub Price',
907 'cd.total_ht' => 'LineTotalHT',
908 'cd.total_tva' => 'LineTotalVAT',
909 'cd.total_ttc' => 'LineTotalTTC',
910 'cd.product_type' => 'TypeOfLineServiceOrProduct',
911 'cd.date_start' => 'Start Date',
912 'cd.date_end' => 'End Date',
913 'cd.info_bits' => 'InfoBits',
914 'cd.special_code' => 'Special Code',
915 'cd.rang' => 'LinePosition',
916 'cd.fk_unit' => 'Unit'
917 );
918
919 if (isModEnabled("multicurrency")) {
920 $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
921 $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
922 $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
923 $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
924 $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
925 }
926
927 // Add extra fields
928 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
929 $resql = $this->db->query($sql);
930 if ($resql) {
931 while ($obj = $this->db->fetch_object($resql)) {
932 $fieldname = 'extra.'.$obj->name;
933 $fieldlabel = ucfirst($obj->label);
934 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
935 }
936 }
937 // End add extra fields
938
939 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseurdet');
940 $this->import_regex_array[$r] = array(
941 'cd.product_type' => '[0|1]$',
942 'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
943 'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
944 );
945 $this->import_updatekeys_array[$r] = array('cd.fk_commande' => 'Purchase Order Id');
946 $this->import_convertvalue_array[$r] = array(
947 'cd.fk_commande' => array(
948 'rule' => 'fetchidfromref',
949 'file' => '/fourn/class/fournisseur.commande.class.php',
950 'class' => 'CommandeFournisseur',
951 'method' => 'fetch',
952 'element' => 'order_supplier'
953 ),
954 'cd.info_bits' => array('rule' => 'zeroifnull'),
955 'cd.special_code' => array('rule' => 'zeroifnull'),
956 );
957 }
958
959
968 public function init($options = '')
969 {
970 global $conf, $langs;
971
972 $this->remove($options);
973
974 //ODT template for Supplier Orders
975 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_orders/template_supplier_order.odt';
976 $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_orders';
977 $dest = $dirodt.'/template_supplier_order.odt';
978
979 if (file_exists($src) && !file_exists($dest)) {
980 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
981 dol_mkdir($dirodt);
982 $result = dol_copy($src, $dest, '0', 0);
983 if ($result < 0) {
984 $langs->load("errors");
985 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
986 return 0;
987 }
988 }
989
990 $sql_order = array(
991 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".((int) $conf->entity),
992 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'order_supplier', ".((int) $conf->entity).")",
993 );
994
995 //ODT template for Supplier Invoice
996 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_invoices/template_supplier_invoices.odt';
997 $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_invoices';
998 $dest = $dirodt.'/template_supplier_invoices.odt';
999
1000 if (file_exists($src) && !file_exists($dest)) {
1001 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1002 dol_mkdir($dirodt);
1003 $result = dol_copy($src, $dest, '0', 0);
1004 if ($result < 0) {
1005 $langs->load("errors");
1006 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
1007 return 0;
1008 }
1009 }
1010
1011 /*
1012 $sql_invoice = array(
1013 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'invoice_supplier' AND entity = ".((int) $conf->entity),
1014 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."', 'invoice_supplier', ".((int) $conf->entity).")",
1015 );
1016
1017 $sql = array_merge($sql_order, $sql_invoice);
1018 */
1019
1020 $sql = $sql_order;
1021
1022 return $this->_init($sql, $options);
1023 }
1024}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Description and activation class for module Fournisseur.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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, $testvirus=0, $indexdatabase=0)
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 information (by default a local PHP server timestamp) Rep...
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152