dolibarr 25.0.0-alpha
modSupplierOrder.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-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
34include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php';
35
40{
46 public function __construct($db)
47 {
48 global $conf, $langs, $user, $mysoc;
49
50 $this->db = $db;
51 $this->numero = 39;
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 = "Manage supplier order";
60
61 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
62 $this->version = 'dolibarr';
63 $this->hidden = !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD');
64
65 $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
66 $this->picto = 'supplier_order';
67
68 // Data directories to create when module is enabled
69 $this->dirs = array(
70 "/fournisseur/temp",
71 "/fournisseur/commande",
72 "/fournisseur/commande/temp",
73 );
74
75 // Dependencies
76 $this->depends = array("modSociete");
77 $this->requiredby = array("modSupplierProposal");
78 $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
79
80 // Config pages
81 $this->config_page_url = array("supplier_order.php@supplier_order");
82
83 // Constants
84 $this->const = [
85 [
86 "COMMANDE_SUPPLIER_ADDON_PDF",
87 "chaine",
88 "cornas",
89 "Name of the PDF purchase order generation manager",
90 0,
91 ],
92 [
93 "COMMANDE_SUPPLIER_ADDON_NUMBER",
94 "chaine",
95 "mod_commande_fournisseur_muguet",
96 "Name of the supplier invoice numbering manager",
97 0,
98 ],
99 // Add ability ODT for Supplier orders
100 [
101 "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH",
102 "chaine",
103 "DOL_DATA_ROOT" . ($conf->entity > 1 ? '/' . $conf->entity : '') . "/doctemplates/supplier_orders",
104 "",
105 0,
106 ],
107 ];
108
109 // Boxes
110 $this->boxes = [
111 ['file' => 'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton' => 'Home'],
112 ['file' => 'box_fournisseurs.php', 'enabledbydefaulton' => 'Home'],
113 ['file' => 'box_supplier_orders.php', 'enabledbydefaulton' => 'Home'],
114 ['file' => 'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton' => 'Home'],
115 ];
116
117 // Permissions
118 $this->rights = array();
119 $this->rights_class = 'supplier_order';
120 $r = 0;
121
122 $r++;
123 $this->rights[$r][0] = 1152;
124 $this->rights[$r][1] = 'Read purchase orders';
125 $this->rights[$r][2] = 'r';
126 $this->rights[$r][3] = 0;
127 $this->rights[$r][4] = 'lire';
128
129 $r++;
130 $this->rights[$r][0] = 1153;
131 $this->rights[$r][1] = 'Create a purchase order';
132 $this->rights[$r][2] = 'w';
133 $this->rights[$r][3] = 0;
134 $this->rights[$r][4] = 'creer';
135
136 $r++;
137 $this->rights[$r][0] = 1154;
138 $this->rights[$r][1] = 'Validate purchase orders'; // Advance permission because useless. "Validate" in dolibarr means "Create really" vs "Create as draft only".;
139 $this->rights[$r][2] = 'w';
140 $this->rights[$r][3] = 0;
141 $this->rights[$r][4] = 'supplier_order_advance';
142 $this->rights[$r][5] = 'validate';
143
144 $r++;
145 $this->rights[$r][0] = 1155;
146 $this->rights[$r][1] = 'Approve purchase orders';
147 $this->rights[$r][2] = 'w';
148 $this->rights[$r][3] = 0;
149 $this->rights[$r][4] = 'approuver';
150
151 $r++;
152 $this->rights[$r][0] = 1156;
153 $this->rights[$r][1] = 'Order a purchase order';
154 $this->rights[$r][2] = 'w';
155 $this->rights[$r][3] = 0;
156 $this->rights[$r][4] = 'commander';
157
158 $r++;
159 $this->rights[$r][0] = 1157;
160 $this->rights[$r][1] = 'Receive a purchase order';
161 $this->rights[$r][2] = 'd';
162 $this->rights[$r][3] = 0;
163 $this->rights[$r][4] = 'receptionner';
164
165 $r++;
166 $this->rights[$r][0] = 1159;
167 $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
168 $this->rights[$r][2] = 'w';
169 $this->rights[$r][3] = 0;
170 $this->rights[$r][4] = 'supplier_order_advance';
171 $this->rights[$r][5] = 'check';
172
173 $r++;
174 $this->rights[$r][0] = 1158;
175 $this->rights[$r][1] = 'Delete a purchase order';
176 $this->rights[$r][2] = 'd';
177 $this->rights[$r][3] = 0;
178 $this->rights[$r][4] = 'supprimer';
179
180 if (getDolGlobalString('SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
181 $r++;
182 $this->rights[$r][0] = 1160;
183 $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
184 $this->rights[$r][2] = 'w';
185 $this->rights[$r][3] = 0;
186 $this->rights[$r][4] = 'approve2';
187 }
188
189 $r++;
190 $this->rights[$r][0] = 1161;
191 $this->rights[$r][1] = 'Export purchase orders';
192 $this->rights[$r][2] = 'r';
193 $this->rights[$r][3] = 0;
194 $this->rights[$r][4] = 'export';
195
196 // Menus
197 //-------
198 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
199
200
201 // Exports
202 //--------
203 $r++;
204 $this->export_code[$r] = $this->rights_class . '_' . $r;
205 $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
206 $this->export_icon[$r] = 'supplier_order';
207 $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
208 $this->export_fields_array[$r] = array(
209 's.rowid' => "IdCompany",
210 's.nom' => 'CompanyName',
211 'ps.nom' => 'ParentCompany',
212 's.address' => 'Address',
213 's.zip' => 'Zip',
214 's.town' => 'Town',
215 'c.code' => 'CountryCode',
216 's.phone' => 'Phone',
217 's.siren' => 'ProfId1',
218 's.siret' => 'ProfId2',
219 's.ape' => 'ProfId3',
220 's.idprof4' => 'ProfId4',
221 's.idprof5' => 'ProfId5',
222 's.idprof6' => 'ProfId6',
223 's.tva_intra' => 'VATIntra',
224 'f.rowid' => "OrderId",
225 'f.ref' => "Ref",
226 'f.ref_supplier' => "RefSupplier",
227 'f.date_creation' => "DateCreation",
228 'f.date_commande' => "OrderDate",
229 'f.date_livraison' => "DateDeliveryPlanned",
230 'f.total_ht' => "TotalHT",
231 'f.total_ttc' => "TotalTTC",
232 'f.total_tva' => "TotalVAT",
233 'f.fk_statut' => 'Status',
234 'f.date_valid' => 'DateValidation',
235 'f.date_approve' => 'DateApprove',
236 'f.date_approve2' => 'DateApprove2',
237 'f.note_public' => "NotePublic",
238 'f.note_private' => "NotePrivate",
239 'uv.login' => 'UserValidation',
240 'ua1.login' => 'ApprovedBy',
241 'ua2.login' => 'ApprovedBy2',
242 'f.source' => 'Source',
243 'fd.rowid' => 'LineId',
244 'fd.description' => "LineDescription",
245 'fd.tva_tx' => "LineVATRate",
246 'fd.qty' => "LineQty",
247 'fd.remise_percent' => "Discount",
248 'fd.total_ht' => "LineTotalHT",
249 'fd.total_ttc' => "LineTotalTTC",
250 'fd.total_tva' => "LineTotalVAT",
251 'fd.date_start' => "DateStart",
252 'fd.date_end' => "DateEnd",
253 'fd.special_code' => 'SpecialCode',
254 'fd.product_type' => 'TypeOfLineServiceOrProduct',
255 'fd.ref' => 'SupplierRef',
256 'fd.fk_product' => 'ProductId',
257 'p.ref' => 'ProductRef',
258 'p.label' => 'ProductLabel',
259 'project.rowid' => 'ProjectId',
260 'project.ref' => 'ProjectRef',
261 'project.title' => 'ProjectLabel'
262 );
263 if (isModEnabled("multicurrency")) {
264 $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
265 $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
266 $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
267 $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
268 $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
269 }
270 if (!getDolGlobalString('SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
271 unset($this->export_fields_array['f.date_approve2']);
272 unset($this->export_fields_array['ua2.login']);
273 }
274 $this->export_TypeFields_array[$r] = array(
275 's.rowid' => "company",
276 's.nom' => 'Text',
277 'ps.nom' => 'Text',
278 's.address' => 'Text',
279 's.cp' => 'Text',
280 's.ville' => 'Text',
281 'c.code' => 'Text',
282 's.tel' => 'Text',
283 's.siren' => 'Text',
284 's.siret' => 'Text',
285 's.ape' => 'Text',
286 's.idprof4' => 'Text',
287 's.idprof5' => 'Text',
288 's.idprof6' => 'Text',
289 's.tva_intra' => 'Text',
290 'f.ref' => "Text",
291 'f.ref_supplier' => "Text",
292 'f.date_creation' => "Date",
293 'f.date_commande' => "Date",
294 'f.date_livraison' => "Date",
295 'f.total_ht' => "Numeric",
296 'f.total_ttc' => "Numeric",
297 'f.total_tva' => "Numeric",
298 'f.fk_statut' => 'Status',
299 'f.date_valid' => 'Date',
300 'f.date_approve' => 'Date',
301 'f.date_approve2' => 'Date',
302 'f.note_public' => "Text",
303 'f.note_private' => "Text",
304 'f.source' => 'Numeric',
305 'fd.description' => "Text",
306 'fd.tva_tx' => "Numeric",
307 'fd.qty' => "Numeric",
308 'fd.remise_percent' => "Numeric",
309 'fd.total_ht' => "Numeric",
310 'fd.total_ttc' => "Numeric",
311 'fd.total_tva' => "Numeric",
312 'fd.date_start' => "Date",
313 'fd.date_end' => "Date",
314 'fd.special_code' => "Numeric",
315 'fd.product_type' => 'Numeric',
316 'fd.ref' => 'Text',
317 'fd.fk_product' => 'List:product:label',
318 'p.ref' => 'Text',
319 'p.label' => 'Text',
320 'project.ref' => 'Text',
321 'project.title' => 'Text'
322 );
323 $this->export_entities_array[$r] = array(
324 's.rowid' => "company",
325 's.nom' => 'company',
326 'ps.nom' => 'company',
327 's.address' => 'company',
328 's.zip' => 'company',
329 's.town' => 'company',
330 'c.code' => 'company',
331 's.phone' => 'company',
332 's.siren' => 'company',
333 's.siret' => 'company',
334 's.ape' => 'company',
335 's.idprof4' => 'company',
336 's.idprof5' => 'company',
337 's.idprof6' => 'company',
338 's.tva_intra' => 'company',
339 'uv.login' => 'user',
340 'ua1.login' => 'user',
341 'ua2.login' => 'user',
342 'f.source' => 'order',
343 'fd.rowid' => 'order_line',
344 'fd.description' => "order_line",
345 'fd.tva_tx' => "order_line",
346 'fd.qty' => "order_line",
347 'fd.remise_percent' => "order_line",
348 'fd.total_ht' => "order_line",
349 'fd.total_ttc' => "order_line",
350 'fd.total_tva' => "order_line",
351 'fd.date_start' => "order_line",
352 'fd.date_end' => "order_line",
353 'fd.special_code' => "order_line",
354 'fd.product_type' => 'order_line',
355 'fd.ref' => 'order_line',
356 'fd.fk_product' => 'product',
357 'p.ref' => 'product',
358 'p.label' => 'product',
359 'project.rowid' => 'project',
360 'project.ref' => 'project',
361 'project.title' => 'project'
362 );
363 $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
364 // Add extra fields object
365 $keyforselect = 'commande_fournisseur';
366 $keyforelement = 'order';
367 $keyforaliasextra = 'extra';
368 include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
369 // End add extra fields object
370 // Add extra fields line
371 $keyforselect = 'commande_fournisseurdet';
372 $keyforelement = 'order_line';
373 $keyforaliasextra = 'extraline';
374 include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php';
375 // End add extra fields line
376 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
377 $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'societe as s';
378 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as ps ON ps.rowid = s.parent';
379 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
380 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
381 }
382 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid,';
383 $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseur as f';
384 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet as project on (f.fk_projet = project.rowid)';
385 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as uv ON uv.rowid = f.fk_user_valid';
386 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as ua1 ON ua1.rowid = f.fk_user_approve';
387 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as ua2 ON ua2.rowid = f.fk_user_approve2';
388 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
389 $this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseurdet as fd';
390 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
391 $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on (fd.fk_product = p.rowid)';
392 $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
393 $this->export_sql_end[$r] .= ' AND f.entity IN (' . getEntity('supplier_order') . ')';
394 if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
395 $this->export_sql_end[$r] .= ' AND sc.fk_user = ' . ((int) $user->id);
396 }
397
398 // Imports
399 //--------
400 $r = 0;
401
402 $r++;
403 $this->import_code[$r] = 'commande_fournisseur_' . $r;
404 $this->import_label[$r] = 'SuppliersOrders';
405 $this->import_icon[$r] = 'supplier_order';
406 $this->import_entities_array[$r] = array();
407 $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX . 'commande_fournisseur', 'extra' => MAIN_DB_PREFIX . 'commande_fournisseur_extrafields');
408 $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
409 $this->import_fields_array[$r] = array(
410 'c.ref' => 'Ref*',
411 'c.ref_supplier' => 'RefSupplier',
412 'c.fk_soc' => 'ThirdPartyName*',
413 'c.fk_projet' => 'ProjectId',
414 'c.date_creation' => 'DateCreation',
415 'c.date_valid' => 'DateValidation',
416 'c.date_approve' => 'DateApprove',
417 'c.date_commande' => 'DateOrder',
418 'c.fk_user_modif' => 'ModifiedById',
419 'c.fk_user_valid' => 'ValidatedById',
420 'c.fk_user_approve' => 'ApprovedById',
421 'c.source' => 'Source',
422 'c.fk_statut' => 'Status*',
423 'c.billed' => 'Billed',
424 'c.total_tva' => 'TotalTVA',
425 'c.total_ht' => 'TotalHT',
426 'c.total_ttc' => 'TotalTTC',
427 'c.note_private' => 'NotePrivate',
428 'c.note_public' => 'Note',
429 'c.date_livraison' => 'DeliveryDate',
430 'c.fk_cond_reglement' => 'Payment Condition',
431 'c.fk_mode_reglement' => 'Payment Mode',
432 'c.model_pdf' => 'Model'
433 );
434
435 if (isModEnabled("multicurrency")) {
436 $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
437 $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
438 $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
439 $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
440 $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
441 }
442
443 // Add extra fields
444 $import_extrafield_sample = array();
445 $keyforselect = 'commande_fournisseur';
446 $keyforelement = 'supplier_order';
447 $keyforaliasextra = 'extra';
448 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
449
450 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'commande_fournisseur');
451 $this->import_regex_array[$r] = array(
452 'c.multicurrency_code' => 'code@' . MAIN_DB_PREFIX . 'multicurrency'
453 );
454
455 $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
456 $this->import_convertvalue_array[$r] = array(
457 'c.ref' => array(
458 'rule' => 'getrefifauto',
459 'class' => (!getDolGlobalString('COMMANDE_SUPPLIER_ADDON_NUMBER') ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
460 'path' => "/core/modules/supplier_order/" . (!getDolGlobalString('COMMANDE_SUPPLIER_ADDON_NUMBER') ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) . '.php',
461 'classobject' => 'CommandeFournisseur',
462 'pathobject' => '/fourn/class/fournisseur.commande.class.php',
463 ),
464 'c.fk_soc' => array(
465 'rule' => 'fetchidfromref',
466 'file' => '/societe/class/societe.class.php',
467 'class' => 'Societe',
468 'method' => 'fetch',
469 'element' => 'ThirdParty'
470 ),
471 'c.fk_mode_reglement' => array(
472 'rule' => 'fetchidfromcodeorlabel',
473 'file' => '/compta/paiement/class/cpaiement.class.php',
474 'class' => 'Cpaiement',
475 'method' => 'fetch',
476 'element' => 'cpayment'
477 ),
478 'c.source' => array('rule' => 'zeroifnull'),
479 );
480
481 // Import PO Lines
482 $r++;
483 $this->import_code[$r] = 'commande_fournisseurdet_' . $r;
484 $this->import_label[$r] = 'PurchaseOrderLines';
485 $this->import_icon[$r] = 'supplier_order';
486 $this->import_entities_array[$r] = array();
487 $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX . 'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX . 'commande_fournisseurdet_extrafields');
488 $this->import_fields_array[$r] = array(
489 'cd.fk_commande' => 'PurchaseOrder*',
490 'cd.fk_parent_line' => 'ParentLine',
491 'cd.fk_product' => 'IdProduct',
492 'cd.ref' => 'SupplierRef',
493 'cd.description' => 'LineDescription',
494 'cd.tva_tx' => 'LineVATRate',
495 'cd.qty' => 'LineQty',
496 'cd.remise_percent' => 'Reduc. Percent',
497 'cd.subprice' => 'Sub Price',
498 'cd.total_ht' => 'LineTotalHT',
499 'cd.total_tva' => 'LineTotalVAT',
500 'cd.total_ttc' => 'LineTotalTTC',
501 'cd.product_type' => 'TypeOfLineServiceOrProduct',
502 'cd.date_start' => 'Start Date',
503 'cd.date_end' => 'End Date',
504 'cd.info_bits' => 'InfoBits',
505 'cd.special_code' => 'Special Code',
506 'cd.rang' => 'LinePosition',
507 'cd.fk_unit' => 'Unit'
508 );
509
510 if (isModEnabled("multicurrency")) {
511 $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
512 $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
513 $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
514 $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
515 $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
516 }
517
518 // Add extra fields
519 $keyforselect = 'commande_fournisseurdet';
520 $keyforelement = 'supplier_order';
521 $keyforaliasextra = 'extra';
522 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
523
524 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'commande_fournisseurdet');
525 $this->import_regex_array[$r] = array(
526 'cd.product_type' => '[0|1]$',
527 'cd.fk_product' => 'rowid@' . MAIN_DB_PREFIX . 'product',
528 'cd.multicurrency_code' => 'code@' . MAIN_DB_PREFIX . 'multicurrency'
529 );
530 $this->import_updatekeys_array[$r] = array('cd.fk_commande' => 'Purchase Order Id', 'cd.rang' => 'LinePosition');
531 $this->import_convertvalue_array[$r] = array(
532 'cd.fk_commande' => array(
533 'rule' => 'fetchidfromref',
534 'file' => '/fourn/class/fournisseur.commande.class.php',
535 'class' => 'CommandeFournisseur',
536 'method' => 'fetch',
537 'element' => 'order_supplier'
538 ),
539 'cd.info_bits' => array('rule' => 'zeroifnull'),
540 'cd.special_code' => array('rule' => 'zeroifnull'),
541 );
542 }
543
544
553 public function init($options = '')
554 {
555 global $conf, $langs;
556
557 $this->remove($options);
558
559 $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/supplier_orders/template_supplier_order.odt';
560 $dirodt = DOL_DATA_ROOT . ($conf->entity > 1 ? '/' . $conf->entity : '') . '/doctemplates/supplier_orders';
561 $dest = $dirodt . '/template_supplier_order.odt';
562
563 if (file_exists($src) && !file_exists($dest)) {
564 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
565 dol_mkdir($dirodt);
566 $result = dol_copy($src, $dest, '0', 0);
567 if ($result < 0) {
568 $langs->load("errors");
569 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
570 return 0;
571 }
572 }
573
574 $sql_order = array(
575 "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),
576 "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[0][2]) . "', 'order_supplier', " . ((int) $conf->entity) . ")",
577 );
578
579 $sql = $sql_order;
580
581 return $this->_init($sql, $options);
582 }
583}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Description and activation class for module supplier order.
__construct($db)
Constructor.
global $mysoc
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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:133