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