55 $this->family =
"srm";
56 $this->module_position =
'12';
58 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
62 $this->version =
'dolibarr';
65 $this->const_name =
'MAIN_MODULE_' . strtoupper($this->
name);
66 $this->picto =
'supplier_order';
71 "/fournisseur/commande",
72 "/fournisseur/commande/temp",
76 $this->depends = array(
"modSociete");
77 $this->requiredby = array(
"modSupplierProposal");
78 $this->langfiles = array(
'bills',
'companies',
'suppliers',
'orders',
'sendings');
81 $this->config_page_url = array(
"supplier_order.php@supplier_order");
86 "COMMANDE_SUPPLIER_ADDON_PDF",
89 "Name of the PDF purchase order generation manager",
93 "COMMANDE_SUPPLIER_ADDON_NUMBER",
95 "mod_commande_fournisseur_muguet",
96 "Name of the supplier invoice numbering manager",
101 "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH",
103 "DOL_DATA_ROOT" . ($conf->entity > 1 ?
'/' .
$conf->entity :
'') .
"/doctemplates/supplier_orders",
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'],
118 $this->rights = array();
119 $this->rights_class =
'supplier_order';
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';
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';
137 $this->rights[$r][0] = 1154;
138 $this->rights[$r][1] =
'Validate purchase orders';
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';
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';
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';
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';
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';
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';
182 $this->rights[$r][0] = 1160;
183 $this->rights[$r][1] =
'Approve supplier order (second level)';
184 $this->rights[$r][2] =
'w';
185 $this->rights[$r][3] = 0;
186 $this->rights[$r][4] =
'approve2';
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';
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',
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",
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'
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';
271 unset($this->export_fields_array[
'f.date_approve2']);
272 unset($this->export_fields_array[
'ua2.login']);
274 $this->export_TypeFields_array[$r] = array(
275 's.rowid' =>
"company",
278 's.address' =>
'Text',
286 's.idprof4' =>
'Text',
287 's.idprof5' =>
'Text',
288 's.idprof6' =>
'Text',
289 's.tva_intra' =>
'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',
317 'fd.fk_product' =>
'List:product:label',
320 'project.ref' =>
'Text',
321 'project.title' =>
'Text'
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'
363 $this->export_dependencies_array[$r] = array(
'order_line' =>
'fd.rowid',
'product' =>
'fd.rowid');
365 $keyforselect =
'commande_fournisseur';
366 $keyforelement =
'order';
367 $keyforaliasextra =
'extra';
368 include DOL_DOCUMENT_ROOT .
'/core/extrafieldsinexport.inc.php';
371 $keyforselect =
'commande_fournisseurdet';
372 $keyforelement =
'order_line';
373 $keyforaliasextra =
'extraline';
374 include DOL_DOCUMENT_ROOT .
'/core/extrafieldsinexport.inc.php';
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';
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);
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');
409 $this->import_fields_array[$r] = array(
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'
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';
444 $import_extrafield_sample = array();
445 $sql =
"SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX .
"extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseur' AND entity IN (0, " .
$conf->entity .
")";
446 $resql = $this->db->query($sql);
449 while ($obj = $this->db->fetch_object($resql)) {
450 $fieldname =
'extra.' . $obj->name;
451 $fieldlabel = ucfirst($obj->label);
452 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ?
'*' :
'');
453 $import_extrafield_sample[$fieldname] = $fieldlabel;
458 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-' . MAIN_DB_PREFIX .
'commande_fournisseur');
459 $this->import_regex_array[$r] = array(
460 'c.multicurrency_code' =>
'code@' . MAIN_DB_PREFIX .
'multicurrency'
463 $this->import_updatekeys_array[$r] = array(
'c.ref' =>
'Ref');
464 $this->import_convertvalue_array[$r] = array(
466 'rule' =>
'getrefifauto',
467 'class' => (!
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_NUMBER') ?
'mod_commande_fournisseur_muguet' :
$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
468 'path' =>
"/core/modules/supplier_order/" . (!
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_NUMBER') ?
'mod_commande_fournisseur_muguet' :
$conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) .
'.php',
469 'classobject' =>
'CommandeFournisseur',
470 'pathobject' =>
'/fourn/class/fournisseur.commande.class.php',
473 'rule' =>
'fetchidfromref',
474 'file' =>
'/societe/class/societe.class.php',
475 'class' =>
'Societe',
477 'element' =>
'ThirdParty'
479 'c.fk_mode_reglement' => array(
480 'rule' =>
'fetchidfromcodeorlabel',
481 'file' =>
'/compta/paiement/class/cpaiement.class.php',
482 'class' =>
'Cpaiement',
484 'element' =>
'cpayment'
486 'c.source' => array(
'rule' =>
'zeroifnull'),
491 $this->import_code[$r] =
'commande_fournisseurdet_' . $r;
492 $this->import_label[$r] =
'PurchaseOrderLines';
493 $this->import_icon[$r] =
'supplier_order';
494 $this->import_entities_array[$r] = array();
495 $this->import_tables_array[$r] = array(
'cd' => MAIN_DB_PREFIX .
'commande_fournisseurdet',
'extra' => MAIN_DB_PREFIX .
'commande_fournisseurdet_extrafields');
496 $this->import_fields_array[$r] = array(
497 'cd.fk_commande' =>
'PurchaseOrder*',
498 'cd.fk_parent_line' =>
'ParentLine',
499 'cd.fk_product' =>
'IdProduct',
500 'cd.ref' =>
'SupplierRef',
501 'cd.description' =>
'LineDescription',
502 'cd.tva_tx' =>
'LineVATRate',
503 'cd.qty' =>
'LineQty',
504 'cd.remise_percent' =>
'Reduc. Percent',
505 'cd.subprice' =>
'Sub Price',
506 'cd.total_ht' =>
'LineTotalHT',
507 'cd.total_tva' =>
'LineTotalVAT',
508 'cd.total_ttc' =>
'LineTotalTTC',
509 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
510 'cd.date_start' =>
'Start Date',
511 'cd.date_end' =>
'End Date',
512 'cd.info_bits' =>
'InfoBits',
513 'cd.special_code' =>
'Special Code',
514 'cd.rang' =>
'LinePosition',
515 'cd.fk_unit' =>
'Unit'
519 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
520 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
521 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
522 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
523 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
527 $sql =
"SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX .
"extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseurdet' AND entity IN (0, " .
$conf->entity .
")";
528 $resql = $this->db->query($sql);
530 while ($obj = $this->db->fetch_object($resql)) {
531 $fieldname =
'extra.' . $obj->name;
532 $fieldlabel = ucfirst($obj->label);
533 $this->import_fields_array[$r][$fieldname] = $fieldlabel . ($obj->fieldrequired ?
'*' :
'');
538 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-' . MAIN_DB_PREFIX .
'commande_fournisseurdet');
539 $this->import_regex_array[$r] = array(
540 'cd.product_type' =>
'[0|1]$',
541 'cd.fk_product' =>
'rowid@' . MAIN_DB_PREFIX .
'product',
542 'cd.multicurrency_code' =>
'code@' . MAIN_DB_PREFIX .
'multicurrency'
544 $this->import_updatekeys_array[$r] = array(
'cd.fk_commande' =>
'Purchase Order Id',
'cd.rang' =>
'LinePosition');
545 $this->import_convertvalue_array[$r] = array(
546 'cd.fk_commande' => array(
547 'rule' =>
'fetchidfromref',
548 'file' =>
'/fourn/class/fournisseur.commande.class.php',
549 'class' =>
'CommandeFournisseur',
551 'element' =>
'order_supplier'
553 'cd.info_bits' => array(
'rule' =>
'zeroifnull'),
554 'cd.special_code' => array(
'rule' =>
'zeroifnull'),