41require
'../../main.inc.php';
53require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
61require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
62require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
71 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
72 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
74require_once NUSOAP_PATH.
'/nusoap.php';
77 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
81 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
82 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
86$langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'products',
'stocks',
'productbatch'));
88 $langs->load(
'incoterm');
93$action =
GETPOST(
'action',
'alpha');
94$confirm =
GETPOST(
'confirm',
'alpha');
95$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
96$cancel =
GETPOST(
'cancel',
'alpha');
97$backtopage =
GETPOST(
'backtopage',
'alpha');
98$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
105$origin =
GETPOST(
'origin',
'alpha');
108$stockDelete =
GETPOST(
'stockDelete',
'int');
119if ($user->isExternalUser()) {
120 $socid = $user->isExternalUser();
124$hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
129$extrafields->fetch_name_optionals_label(
$object->table_element);
132if ($id > 0 || !empty($ref)) {
133 $ret =
$object->fetch($id, $ref);
137 $ret =
$object->fetch_thirdparty();
141} elseif (!empty($socid) && $socid > 0) {
143 $ret =
$object->fetch_thirdparty();
150$isdraft = (isset(
$object->status) && (
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
151$result =
restrictedArea($user,
'fournisseur', $object,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
154$usercanread = ($user->hasRight(
"fournisseur",
"commande",
"lire") || $user->hasRight(
"supplier_order",
"lire"));
155$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
156$usercandelete = (($user->hasRight(
"fournisseur",
"commande",
"supprimer") || $user->hasRight(
"supplier_order",
"supprimer")) || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT));
159$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate")));
162$usercanapprove = $user->hasRight(
"fournisseur",
"commande",
"approuver");
163$usercanapprovesecond = $user->hasRight(
"fournisseur",
"commande",
"approve2");
164$usercanorder = $user->hasRight(
"fournisseur",
"commande",
"commander");
166 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
168 $usercanreceive = $user->hasRight(
"reception",
"creer");
172$permissionnote = $usercancreate;
173$permissiondellink = $usercancreate;
174$permissiontoedit = $usercancreate;
175$permissiontoadd = $usercancreate;
176$permissiontoeditextra = $permissiontoadd;
177if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
179 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
183$caneditproject =
false;
196$parameters = array(
'socid' => $socid);
197$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
202if (empty($reshook)) {
203 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
205 if (empty($backtopage) || ($cancel && empty($id))) {
206 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
207 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
208 $backtopage = $backurlforlist;
210 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
216 if (!empty($backtopageforcancel)) {
217 header(
"Location: ".$backtopageforcancel);
219 } elseif (!empty($backtopage)) {
220 header(
"Location: ".$backtopage);
226 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
228 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
230 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
232 if ($action ==
'setref_supplier' && $usercancreate) {
233 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
240 if ($action ==
'set_incoterms' && $usercancreate) {
248 if ($action ==
'setconditions' && $usercancreate) {
256 if ($action ==
'setmode' && $usercancreate) {
261 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
263 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
264 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
270 if ($action ==
'setbankaccount' && $usercancreate) {
278 if ($action ==
'setdate_livraison' && $usercancreate) {
279 $result =
$object->setDeliveryDate($user, $datelivraison);
286 if ($action ==
'classin' && $usercancreate && $caneditproject) {
287 $result =
$object->setProject($projectid);
294 if ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
299 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
304 $outputlangs = $langs;
310 $newlang =
$object->thirdparty->default_lang;
312 if (!empty($newlang)) {
314 $outputlangs->setDefaultLang($newlang);
315 $outputlangs->load(
'products');
319 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
322 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
330 if ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
331 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
332 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
336 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
337 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
338 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
344 if ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
354 if (!empty($new_socid) && $new_socid !=
$object->thirdparty->id) {
358 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
359 $sql .=
' SET fk_soc = '.((int) $new_socid);
360 $sql .=
' WHERE fk_soc = '.((int)
$object->thirdparty->id);
361 $sql .=
' AND rowid = '.((int)
$object->id);
363 $res =
$db->query($sql);
371 foreach (
$object->lines as $l) {
372 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
373 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
374 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
375 $sql .=
' AND fk_soc = '.((int) $new_socid);
376 $sql .=
' ORDER BY unitprice ASC';
378 $resql =
$db->query($sql);
380 $num_row =
$db->num_rows($resql);
381 if (empty($num_row)) {
387 $l->ref_supplier =
'';
391 $obj =
$db->fetch_object($resql);
392 $l->subprice = $obj->unitprice;
393 $l->total_ht = $obj->price;
394 $l->tva_tx = $obj->tva_tx;
395 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
396 $l->total_ttc = $l->total_ht + $l->total_tva;
397 $l->ref_supplier = $obj->ref_fourn;
408 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
412 if ($action ==
'setremisepercent' && $usercancreate) {
419 if ($action ==
'reopen' && $permissiontoadd) {
420 $resSetReopen =
$object->setReopen($user);
422 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
432 if ($action ==
'classifybilled' && $usercancreate) {
433 $ret =
$object->classifyBilled($user);
437 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
438 $ret =
$object->classifyUnBilled($user);
445 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
449 foreach (
$object->lines as $line) {
450 if ($line->product_type == 1) {
451 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, 0, $alldate_start, $alldate_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
454 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
456 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
457 $remise_percent = str_replace(
'*',
'', $remise_percent);
458 foreach (
$object->lines as $line) {
459 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
461 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
463 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
464 $vat_rate = str_replace(
'*',
'', $vat_rate);
467 foreach (
$object->lines as $line) {
468 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
471 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, (
float) $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
473 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
476 $langs->load(
'subtotals');
478 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
479 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
481 $subtotal_options = array();
483 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
484 $value =
GETPOST($option,
'alphanohtml');
486 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
491 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
502 $outputlangs = $langs;
503 $newlang =
GETPOST(
'lang_id',
'alpha');
505 $newlang =
$object->thirdparty->default_lang;
507 if (!empty($newlang)) {
509 $outputlangs->setDefaultLang($newlang);
512 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
517 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
519 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
522 $langs->load(
'subtotals');
524 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
525 foreach (
$object->lines as $line) {
526 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
528 $depth = -$line->qty;
532 $subtotal_options = array();
534 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
535 $value =
GETPOST($option,
'alphanohtml');
537 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
542 if (isset($desc) && isset($depth)) {
543 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
546 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
555 $outputlangs = $langs;
556 $newlang =
GETPOST(
'lang_id',
'alpha');
558 $newlang =
$object->thirdparty->default_lang;
560 if (!empty($newlang)) {
562 $outputlangs->setDefaultLang($newlang);
565 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
570 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
572 } elseif ($action ==
'addline' && $usercancreate) {
575 $langs->load(
'errors');
584 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
585 if ($prod_entry_mode ==
'free') {
600 if (empty($remise_percent)) {
605 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
606 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
608 if (is_array($extralabelsline)) {
610 foreach ($extralabelsline as $key => $value) {
611 unset($_POST[
"options_".$key]);
615 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
616 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
619 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
620 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
623 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
624 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
627 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
628 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
631 if (
GETPOST(
'qty',
'alpha') ==
'') {
632 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
636 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
637 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
641 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
642 $idprod = $res->fk_product_child;
644 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
650 if ($prod_entry_mode !=
'free' && empty($error)) {
654 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
659 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
660 $idprod = (int) $reg[1];
661 $res = $productsupplier->fetch($idprod);
664 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
666 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
667 if ($productsupplier->fourn_socid != $socid) {
668 $productsupplier->ref_supplier =
'';
671 $fksoctosearch =
$object->thirdparty->id;
672 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
674 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
675 $qtytosearch = (float) $qty;
677 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
678 $res = $productsupplier->fetch($idprod);
682 $label = $productsupplier->label;
686 $outputlangs = $langs;
688 if (
GETPOST(
'lang_id',
'aZ09')) {
689 $newlang =
GETPOST(
'lang_id',
'aZ09');
691 if (empty($newlang)) {
692 $newlang =
$object->thirdparty->default_lang;
694 if (!empty($newlang)) {
696 $outputlangs->setDefaultLang($newlang);
698 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
700 $desc = $productsupplier->description;
703 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
704 $desc = $productsupplier->desc_supplier;
715 $ref_supplier = $productsupplier->ref_supplier;
720 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
721 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
722 $tmpidprodfournprice = (int) $tmpidprodfournprice;
724 $tmpidprodfournprice = 0;
728 if (empty($tva_tx)) {
736 $type = $productsupplier->type;
737 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
738 $price_base_type =
'HT';
740 $pu_devise =
price2num($price_ht_devise,
'CU');
741 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
742 $price_base_type =
'TTC';
744 $pu_devise =
price2num($price_ttc_devise,
'CU');
746 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
747 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
748 $pu = $productsupplier->fourn_pu;
751 $pu = $productsupplier->fourn_pu;
752 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
762 ($price_base_type ==
'HT' ? $pu : 0),
768 $productsupplier->product_fourn_price_id,
772 ($price_base_type ==
'TTC' ? $pu : 0),
779 $productsupplier->fk_unit,
783 min($rank, count(
$object->lines) + 1)
786 if ($idprod == -99 || $idprod == 0) {
789 $langs->load(
"errors");
790 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
795 $langs->load(
"errors");
796 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
798 } elseif (empty($error)) {
799 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
800 $tva_tx = str_replace(
'*',
'', $tva_tx);
801 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
804 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
808 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
816 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
821 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
823 $price_base_type =
'HT';
824 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
826 $result =
$object->addline($desc, (
float) $pu_ht, (
float) $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, (
float) $pu_ttc, $type, 0, 0,
$date_start, $date_end, $array_options, $fk_unit, (
float) $pu_ht_devise);
830 if (!$error && $result > 0) {
837 $outputlangs = $langs;
840 $newlang =
$object->thirdparty->default_lang;
841 if (
GETPOST(
'lang_id',
'aZ09')) {
842 $newlang =
GETPOST(
'lang_id',
'aZ09');
845 if (!empty($newlang)) {
847 $outputlangs->setDefaultLang($newlang);
852 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
858 unset($_POST [
'prod_entry_mode']);
860 unset($_POST[
'qty']);
861 unset($_POST[
'type']);
862 unset($_POST[
'remise_percent']);
864 unset($_POST[
'price_ht']);
865 unset($_POST[
'multicurrency_price_ht']);
866 unset($_POST[
'price_ttc']);
867 unset($_POST[
'fourn_ref']);
868 unset($_POST[
'tva_tx']);
869 unset($_POST[
'label']);
870 unset($localtax1_tx);
871 unset($localtax2_tx);
872 unset($_POST[
'np_marginRate']);
873 unset($_POST[
'np_markRate']);
874 unset($_POST[
'dp_desc']);
875 unset($_POST[
'idprodfournprice']);
876 unset($_POST[
'units']);
878 unset($_POST[
'date_starthour']);
879 unset($_POST[
'date_startmin']);
880 unset($_POST[
'date_startsec']);
881 unset($_POST[
'date_startday']);
882 unset($_POST[
'date_startmonth']);
883 unset($_POST[
'date_startyear']);
884 unset($_POST[
'date_endhour']);
885 unset($_POST[
'date_endmin']);
886 unset($_POST[
'date_endsec']);
887 unset($_POST[
'date_endday']);
888 unset($_POST[
'date_endmonth']);
889 unset($_POST[
'date_endyear']);
896 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
899 $langs->load(
'subtotals');
901 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
904 $subtotal_options = array();
906 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
907 $value =
GETPOST($option,
'alphanohtml');
909 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
914 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
925 $outputlangs = $langs;
926 $newlang =
GETPOST(
'lang_id',
'alpha');
928 $newlang =
$object->thirdparty->default_lang;
930 if (!empty($newlang)) {
932 $outputlangs->setDefaultLang($newlang);
935 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
940 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
943 $langs->load(
'subtotals');
945 $desc =
GETPOST(
'line_desc',
'alphanohtml');
948 $subtotal_options = array();
950 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
951 $value =
GETPOST($option,
'alphanohtml');
953 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
958 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
966 $outputlangs = $langs;
967 $newlang =
GETPOST(
'lang_id',
'alpha');
969 $newlang =
$object->thirdparty->default_lang;
971 if (!empty($newlang)) {
973 $outputlangs->setDefaultLang($newlang);
976 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
981 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
990 $res = $line->fetch($lineid);
997 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
998 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, (
float)
price2num(
GETPOSTFLOAT(
'qty')), $line->fk_product,
'none',
GETPOSTINT(
'socid')) < 0) {
999 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1008 if (preg_match(
'/\*/', $vat_rate)) {
1013 $vat_rate = str_replace(
'*',
'', $vat_rate);
1017 if (
GETPOST(
'price_ht') !=
'') {
1018 $price_base_type =
'HT';
1022 $vatratecleaned = $vat_rate;
1023 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
1024 $vatratecleaned = trim($reg[1]);
1025 $vatratecode = $reg[2];
1029 $ht = (float) $ttc / (1 + ((
float) $vatratecleaned / 100));
1030 $price_base_type =
'HT';
1036 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1037 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1039 if (is_array($extralabelsline)) {
1040 foreach ($extralabelsline as $key => $value) {
1041 unset($_POST[
"options_".$key]);
1045 $result =
$object->updateline(
1047 GETPOST(
'product_desc',
'restricthtml'),
1062 (float) $pu_ht_devise,
1065 unset($_POST[
'qty']);
1066 unset($_POST[
'type']);
1067 unset($_POST[
'idprodfournprice']);
1068 unset($_POST[
'remmise_percent']);
1069 unset($_POST[
'dp_desc']);
1070 unset($_POST[
'np_desc']);
1071 unset($_POST[
'pu']);
1072 unset($_POST[
'fourn_ref']);
1073 unset($_POST[
'tva_tx']);
1074 unset($_POST[
'date_start']);
1075 unset($_POST[
'date_end']);
1076 unset($_POST[
'units']);
1077 unset($localtax1_tx);
1078 unset($localtax2_tx);
1080 unset($_POST[
'date_starthour']);
1081 unset($_POST[
'date_startmin']);
1082 unset($_POST[
'date_startsec']);
1083 unset($_POST[
'date_startday']);
1084 unset($_POST[
'date_startmonth']);
1085 unset($_POST[
'date_startyear']);
1086 unset($_POST[
'date_endhour']);
1087 unset($_POST[
'date_endmin']);
1088 unset($_POST[
'date_endsec']);
1089 unset($_POST[
'date_endday']);
1090 unset($_POST[
'date_endmonth']);
1091 unset($_POST[
'date_endyear']);
1096 $outputlangs = $langs;
1099 $newlang =
GETPOST(
'lang_id',
'aZ09');
1102 $newlang =
$object->thirdparty->default_lang;
1104 if (!empty($newlang)) {
1106 $outputlangs->setDefaultLang($newlang);
1111 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1126 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
1129 $result =
$object->deleteLine($lineid);
1134 $outputlangs = $langs;
1137 $newlang =
GETPOST(
'lang_id',
'aZ09');
1140 $newlang =
$object->thirdparty->default_lang;
1142 if (!empty($newlang)) {
1144 $outputlangs->setDefaultLang($newlang);
1148 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1170 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
1178 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
1182 $result =
$object->valid($user);
1186 $outputlangs = $langs;
1189 $newlang =
GETPOST(
'lang_id',
'aZ09');
1192 $newlang =
$object->thirdparty->default_lang;
1194 if (!empty($newlang)) {
1196 $outputlangs->setDefaultLang($newlang);
1201 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1214 $action =
'confirm_approve';
1224 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
1229 $qualified_for_stock_change = 0;
1231 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1233 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1238 if (!$idwarehouse || $idwarehouse == -1) {
1240 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1246 $result =
$object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1249 $outputlangs = $langs;
1252 $newlang =
GETPOST(
'lang_id',
'aZ09');
1255 $newlang =
$object->thirdparty->default_lang;
1257 if (!empty($newlang)) {
1259 $outputlangs->setDefaultLang($newlang);
1261 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1272 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1279 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1283 $result =
$object->refuse($user);
1285 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1293 if ($action ==
'commande') {
1294 $methodecommande =
GETPOSTINT(
'methodecommande');
1298 } elseif ($methodecommande <= 0 && !
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL')) {
1299 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1300 $action =
'createorder';
1304 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1306 $object->context[
"sendmanualtriggers"] =
GETPOST(
"manual_trigger_send");
1310 $outputlangs = $langs;
1313 $newlang =
GETPOST(
'lang_id',
'aZ09');
1316 $newlang =
$object->thirdparty->default_lang;
1318 if (!empty($newlang)) {
1320 $outputlangs->setDefaultLang($newlang);
1322 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1333 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1341 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1344 $errorsOnDelete = array();
1399 if (empty($errOnDelete)) {
1400 $result =
$object->delete($user);
1403 header(
"Location: " . DOL_URL_ROOT .
'/fourn/commande/list.php?restore_lastsearch_values=1');
1416 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1418 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1419 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1424 $result =
$object->createFromClone($user, $socid);
1426 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1438 if ($action ==
'livraison' && $usercanreceive) {
1449 $langs->load(
"sendings");
1459 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1470 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1474 $result =
$object->cancel($user);
1476 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1484 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1487 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1488 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1489 $trackid =
'sord'.$object->id;
1490 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1494 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1497 if ($action ==
'update_extras' && $permissiontoeditextra) {
1500 $attribute_name =
GETPOST(
'attribute',
'aZ09');
1503 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
1509 $result =
$object->updateExtraField($attribute_name,
'ORDER_SUPPLIER_MODIFY');
1517 $action =
'edit_extras';
1524 if ($action ==
'add' && $permissiontoadd) {
1526 $selectedLines =
GETPOST(
'toselect',
'array:int');
1528 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1545 $object->delivery_date = $datelivraison;
1547 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1548 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1554 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1562 if (!empty($origin) && !empty($originid)) {
1563 $element = $subelement = $origin;
1564 $classname = ucfirst($subelement);
1565 if ($origin ==
'propal' || $origin ==
'proposal') {
1566 $element =
'comm/propal';
1567 $subelement =
'propal';
1568 $classname =
'Propal';
1570 if ($origin ==
'order' || $origin ==
'commande') {
1571 $element = $subelement =
'commande';
1572 $classname =
'Commande';
1574 if ($origin ==
'supplier_proposal') {
1575 $classname =
'SupplierProposal';
1576 $element =
'supplier_proposal';
1577 $subelement =
'supplier_proposal';
1581 $object->origin_type = $origin;
1582 $object->origin_id = $originid;
1586 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1587 if (!empty($other_linked_objects)) {
1588 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
1595 $srcobject =
new $classname(
$db);
1597 dol_syslog(
"Try to find source object origin=".
$object->origin_type.
" originid=".
$object->origin_id.
" to add lines");
1598 $result = $srcobject->fetch(
$object->origin_id);
1600 if (empty(
$object->delivery_date)) {
1601 $tmpdate = $srcobject->delivery_date;
1602 $object->setDeliveryDate($user, $tmpdate);
1605 $object->set_id_projet($user, $srcobject->fk_project);
1607 $lines = $srcobject->lines;
1608 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1609 $srcobject->fetch_lines();
1610 $lines = $srcobject->lines;
1613 $fk_parent_line = 0;
1614 $num = count($lines);
1616 for ($i = 0; $i < $num; $i++) {
1618 empty($lines[$i]->subprice)
1619 || $lines[$i]->qty < 0
1620 || !in_array($lines[$i]->
id, $selectedLines)
1621 || $lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE
1626 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1627 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1628 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1630 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1631 $fk_parent_line = 0;
1635 if (method_exists($lines[$i],
'fetch_optionals')) {
1636 $lines[$i]->fetch_optionals();
1637 $array_option = $lines[$i]->array_options;
1639 $array_option = array();
1643 $product_fourn_price_id = 0;
1644 if ($origin ==
"commande") {
1646 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty,
$object->socid);
1647 $lines[$i]->subprice = 0;
1649 $ref_supplier = $productsupplier->ref_supplier;
1650 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1652 foreach ($srcobject->lines as $li) {
1653 $sql =
'SELECT price, unitprice, tva_tx, remise_percent, entity, ref_fourn';
1654 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
1655 $sql .=
' WHERE fk_product = '.((int) $li->fk_product);
1656 $sql .=
' AND entity IN ('.getEntity(
'product_fournisseur_price').
')';
1657 $sql .=
' AND fk_soc = '.((int)
$object->socid);
1658 $sql .=
' ORDER BY unitprice ASC';
1660 $resql =
$db->query($sql);
1662 $num_row =
$db->num_rows($resql);
1663 if (empty($num_row)) {
1664 $li->remise_percent = 0;
1666 $obj =
$db->fetch_object($resql);
1667 $li->subprice = $obj->unitprice;
1668 $li->remise_percent = $obj->remise_percent;
1677 $ref_supplier = $lines[$i]->ref_fourn;
1678 $product_fourn_price_id = 0;
1681 $tva_tx = $lines[$i]->tva_tx;
1683 if ($origin ==
"commande") {
1685 $soc->fetch($socid);
1691 $lines[$i]->subprice,
1694 $lines[$i]->localtax1_tx,
1695 $lines[$i]->localtax2_tx,
1696 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1697 $product_fourn_price_id,
1699 $lines[$i]->remise_percent,
1702 $lines[$i]->product_type,
1708 $lines[$i]->fk_unit,
1711 !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid,
1713 $lines[$i]->special_code,
1724 if ($result > 0 && $lines[$i]->product_type == 9) {
1725 $fk_parent_line = $result;
1733 $parameters = array(
'objFrom' => $srcobject);
1734 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1758 $categories =
GETPOST(
'categories',
'array:int');
1759 if (method_exists($object,
'setCategories')) {
1760 $object->setCategories($categories);
1765 $langs->load(
"errors");
1770 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode((
string) ($id)));
1777 if ($action ==
'addcontact' && $permissiontoadd) {
1781 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1785 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1788 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1789 $langs->load(
"errors");
1790 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1795 } elseif ($action ==
'swapstatut' &&
$object->id > 0 && $permissiontoadd) {
1798 } elseif ($action ==
'deletecontact' &&
$object->id > 0 && $permissiontoadd) {
1803 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1825$title =
$object->ref.
" - ".$langs->trans(
'Card');
1826if ($action ==
'create') {
1827 $title = $langs->trans(
"NewOrderSupplier");
1829$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1830llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-supplier-order page-card');
1834if ($action ==
'create') {
1835 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1839 $currency_code =
$conf->currency;
1846 $societe->fetch($socid);
1849 if (!empty($origin) && !empty($originid)) {
1851 $element = $subelement = $origin;
1852 $classname = ucfirst($subelement);
1854 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1855 $element = $regs[1];
1856 $subelement = $regs[2];
1859 if ($origin ==
'propal' || $origin ==
'proposal') {
1860 $classname =
'Propal';
1861 $element =
'comm/propal';
1862 $subelement =
'propal';
1864 if ($origin ==
'order' || $origin ==
'commande') {
1865 $classname =
'Commande';
1866 $element = $subelement =
'commande';
1868 if ($origin ==
'supplier_proposal') {
1869 $classname =
'SupplierProposal';
1870 $element =
'supplier_proposal';
1871 $subelement =
'supplier_proposal';
1877 $objectsrc =
new $classname(
$db);
1878 $objectsrc->fetch($originid);
1879 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1880 $objectsrc->fetch_lines();
1882 $objectsrc->fetch_thirdparty();
1885 $objectsrc->fetch_optionals();
1886 $object->array_options = $objectsrc->array_options;
1888 $projectid = (int) $objectsrc->fk_project;
1889 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1891 if ($origin ==
"commande") {
1892 $cond_reglement_id = 0;
1893 $deposit_percent = 0;
1894 $mode_reglement_id = 0;
1895 $objectsrc->note_private =
'';
1896 $objectsrc->note_public =
'';
1897 if ($societe =
$object->thirdparty) {
1898 $cond_reglement_id = $societe->cond_reglement_supplier_id;
1899 $deposit_percent = $societe->deposit_percent;
1900 $mode_reglement_id = $societe->mode_reglement_supplier_id;
1902 $currency_code = $societe->multicurrency_code;
1904 $currency_tx = $societe->multicurrency_tx;
1909 $soc = $objectsrc->thirdparty;
1911 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1912 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0));
1913 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1914 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1915 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1916 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1917 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1920 $datelivraison = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1923 if (!empty($objectsrc->multicurrency_code)) {
1924 $currency_code = $objectsrc->multicurrency_code;
1926 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1927 $currency_tx = $objectsrc->multicurrency_tx;
1931 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1932 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1935 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1938 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1939 $deposit_percent = !empty($societe->deposit_percent) ? $societe->deposit_percent : 0;
1940 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1942 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1943 $currency_code = $societe->multicurrency_code;
1946 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1947 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1951 if (empty($cond_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID')) {
1954 if (empty($mode_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID')) {
1957 if (
GETPOSTISSET(
'cond_reglement_id_deposit_percent')) {
1958 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
1961 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1962 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1963 print
'<input type="hidden" name="action" value="add">';
1964 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1965 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1966 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1967 print
'<input type="hidden" name="changecompany" value="0">';
1969 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1971 if ($backtopageforcancel) {
1972 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1975 if (!empty($currency_tx)) {
1976 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1982 $parameters = array();
1984 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierOrder', $parameters, $object, $action);
1985 if (empty($reshook)) {
1986 print
'<table class="border centpercent">';
1989 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1992 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1995 if (!empty($societe->id) && $societe->id > 0) {
1996 print $societe->getNomUrl(1,
'supplier');
1997 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1999 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2000 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company((empty($socid) ?
'' : $socid),
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
2004 $(document).ready(function() {
2005 $("#socid").change(function() {
2006 console.log("We have changed the company - Reload page");
2008 $("input[name=action]").val("create");
2009 $("input[name=changecompany]").val("1");
2010 $("form[name=add]").submit();
2015 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
2021 print
'<tr><td>'.$form->textwithpicto($langs->trans(
'RefSupplier'), $langs->trans(
'RefOfOnVendorSide', $langs->transnoentitiesnoconv(
"SupplierOrder")));
2022 print
'</td><td><input name="refsupplier" type="text"></td>';
2026 if (!empty($societe->id) && $societe->id > 0) {
2028 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2030 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2032 $thirdparty = $societe;
2034 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2035 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2041 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2042 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2043 print $form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id') != 0) ?
GETPOSTINT(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
2047 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2048 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2049 $form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOSTINT(
'mode_reglement_id') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
2054 print $langs->trans(
'DateDeliveryPlanned');
2061 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2062 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin, 0,
"set", 1, 1);
2067 $langs->load(
"bank");
2068 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2069 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
2070 $form->select_comptes($fk_account ??
'',
'fk_account', 0,
'', 1);
2078 $langs->load(
'projects');
2079 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2081 $projSocFilter = $socid;
2082 } elseif ((
int) $socid == 0 ||
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS')) {
2083 $projSocFilter = -1;
2085 $projSocFilter = $socid;
2087 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
2088 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?action=create&status=1'.(!empty($societe->id) ?
'&socid='.$societe->id :
"").
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create'.(!empty($societe->id) ?
'&socid='.$societe->id :
"")).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
2094 $fkincoterms = (!empty(
$object->fk_incoterms) ?
$object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
2095 $locincoterms = (!empty(
$object->location_incoterms) ?
$object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
2097 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"),
$object->label_incoterms, 1).
'</label></td>';
2098 print
'<td class="maxwidthonsmartphone">';
2099 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2100 print $form->select_incoterms($fkincoterms, $locincoterms);
2107 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2108 print
'<td class="maxwidthonsmartphone">';
2109 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
2110 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
2116 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2117 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2121 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2123 $doleditor =
new DolEditor(
'note_public', isset($note_public) ? $note_public :
GETPOST(
'note_public',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2124 print $doleditor->Create(1);
2129 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2131 $doleditor =
new DolEditor(
'note_private', isset($note_private) ? $note_private :
GETPOST(
'note_private',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2132 print $doleditor->Create(1);
2137 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && $classname !==
null) {
2138 print
"\n<!-- ".$classname.
" info -->";
2140 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2141 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2142 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2143 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2144 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2146 $newclassname = $classname;
2147 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
2148 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2149 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2150 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2151 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2154 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2155 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2158 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2161 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2162 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
2163 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
2168 $parameters = array();
2169 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2170 print $hookmanager->resPrint;
2172 if (empty($reshook)) {
2173 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_SUPPLIER_ORDER') && !empty($societe->id)) {
2176 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($societe->table_element);
2177 if ($societe->fetch_optionals() > 0) {
2178 $object->array_options = array_merge(
$object->array_options, $societe->array_options);
2182 print
$object->showOptionals($extrafields,
'create');
2190 print $form->buttonsSaveCancel(
"CreateDraft");
2193 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2194 $title = $langs->trans(
'ProductsAndServices');
2197 print
'<div class="div-table-responsive-no-min">';
2198 print
'<table class="noborder centpercent">';
2200 $selectedLines = array();
2202 $objectsrc->printOriginLinesList(
'', $selectedLines);
2208} elseif (!empty(
$object->id)) {
2210 $result =
$object->fetch($id, $ref);
2215 $societe =
$object->thirdparty;
2218 $author->fetch(
$object->user_author_id);
2222 $title = $langs->trans(
"SupplierOrder");
2223 print
dol_get_fiche_head($head,
'card', $title, -1,
'order', 0,
'',
'', 0,
'', 1);
2229 if ($action ==
'delete') {
2230 $arrayAjouts = array();
2261 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.((
int)
$object->id), $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal);
2265 if ($action ==
'clone') {
2266 $filter =
'(s.fournisseur:=:1)';
2268 $formquestion = array(
2269 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter))
2272 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2276 if ($action ==
'valid') {
2280 if (preg_match(
'/^[\(]?PROV/i', (
string)
$object->ref) || empty(
$object->ref)) {
2290 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
2292 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2295 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE',
$object->socid, $object);
2298 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
2303 if ($action ==
'approve' || $action ==
'approve2') {
2304 $qualified_for_stock_change = 0;
2306 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2308 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2311 $formquestion = array();
2313 $langs->load(
"stocks");
2314 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2317 if (
$conf->browser->name ==
'ie') {
2320 $formquestion = array(
2324 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2327 $text = $langs->trans(
"ConfirmApproveThisOrder",
$object->ref);
2329 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2332 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE',
$object->socid, $object);
2335 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
2339 if ($action ==
'refuse') {
2340 $formquestion = array(
2343 'name' =>
'refuse_note',
2344 'label' => $langs->trans(
"Reason"),
2346 'morecss' =>
'minwidth300'
2349 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder",
$object->ref),
"confirm_refuse", $formquestion, 0, 1);
2353 if ($action ==
'cancel') {
2354 $formquestion = array(
2357 'name' =>
'cancel_note',
2358 'label' => $langs->trans(
"Reason"),
2360 'morecss' =>
'minwidth300'
2364 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2368 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_CANCEL',
$object->socid, $object);
2370 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder",
$object->ref),
"confirm_cancel", $formquestion, 0, 1);
2374 if ($action ==
'commande') {
2375 $formquestion = array();
2378 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2382 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_SUBMIT',
$object->socid, $object);
2385 require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
2387 if ($targetstatic->isTriggerCodeManualTarget(
'ORDER_SUPPLIER_SUBMIT') > 0) {
2388 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'manual_trigger_send',
'label' => $langs->trans(
"QuestionSendManualTrigger"));
2391 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id.
"&datecommande=".$date_com.
"&methode=".
GETPOST(
"methodecommande").
"&comment=".urlencode(
GETPOST(
"comment")), $langs->trans(
"MakeOrder"), $langs->trans(
"ConfirmMakeOrder",
dol_print_date($date_com,
'day')),
"confirm_commande", $formquestion, 0, 2);
2395 if ($action ==
'ask_deleteline') {
2396 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2400 if ($action ==
'add_title_line') {
2401 $langs->load(
'subtotals');
2403 $depth_array =
$object->getPossibleLevels($langs);
2404 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2405 } elseif ($action ==
'add_subtotal_line') {
2406 $langs->load(
'subtotals');
2408 $titles =
$object->getPossibleTitles();
2409 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2413 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2414 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2415 if (empty($reshook)) {
2416 $formconfirm .= $hookmanager->resPrint;
2417 } elseif ($reshook > 0) {
2418 $formconfirm = $hookmanager->resPrint;
2427 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2429 $morehtmlref =
'<div class="refidno">';
2431 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
2432 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string'.(isset(
$conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
2434 $morehtmlref .=
'<br>';
2435 if (
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2436 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2437 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2438 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2439 $filter =
'(s.fournisseur:=:1)';
2440 $morehtmlref .= $form->select_company(
$object->thirdparty->id,
'new_socid', $filter,
'', 0, 0, array(), 0,
'minwidth300');
2441 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2442 $morehtmlref .=
'</form>';
2444 if (!
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') || $action !=
'edit_thirdparty') {
2446 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2448 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'supplier');
2450 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2456 $langs->load(
"projects");
2457 $morehtmlref .=
'<br>';
2458 if ($permissiontoadd) {
2459 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2460 if ($action !=
'classify' && $caneditproject) {
2461 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2463 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1), (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 1, 0, 0, 1,
'',
'maxwidth300');
2465 if (!empty(
$object->fk_project)) {
2467 $proj->fetch(
$object->fk_project);
2468 $morehtmlref .= $proj->getNomUrl(1);
2470 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2475 $morehtmlref .=
'</div>';
2478 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2481 $parameters = array();
2483 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierOrder', $parameters, $object, $action);
2484 if (empty($reshook)) {
2485 print
'<div class="fichecenter">';
2486 print
'<div class="fichehalfleft">';
2487 print
'<div class="underbanner clearboth"></div>';
2489 print
'<table class="border tableforfield centpercent">';
2492 if (
$object->methode_commande_id > 0) {
2497 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2500 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2504 if (
$object->methode_commande) {
2505 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.
$object->getInputMethod().
'</td></tr>';
2510 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2511 print
'<td>'.$author->getNomUrl(-1,
'', 0, 0, 0).
'</td>';
2516 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2517 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2519 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2520 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2523 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
2524 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
2525 $absolute_discount =
price2num($absolute_discount,
'MT');
2526 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2528 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2530 $thirdparty = $societe;
2532 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
2533 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2538 $langs->load(
'bills');
2539 print
'<tr><td class="nowrap">';
2540 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2541 print $langs->trans(
'PaymentConditions');
2543 if ($action !=
'editconditions' && $permissiontoadd) {
2544 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
2546 print
'</tr></table>';
2548 if ($action ==
'editconditions') {
2549 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2551 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2557 $langs->load(
'bills');
2558 print
'<tr><td class="nowrap">';
2559 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2560 print $langs->trans(
'PaymentMode');
2562 if ($action !=
'editmode' && $permissiontoadd) {
2563 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
2565 print
'</tr></table>';
2567 if ($action ==
'editmode') {
2568 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2570 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
2576 print
'<tr><td class="nowrap">';
2577 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2578 print $langs->trans(
'BankAccount');
2580 if ($action !=
'editbankaccount' && $permissiontoadd) {
2581 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
2583 print
'</tr></table>';
2585 if ($action ==
'editbankaccount') {
2586 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
2588 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
2596 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2597 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2602 print
'<table class="nobordernopadding centpercent"><tr><td>';
2603 print $langs->trans(
'DateDeliveryPlanned');
2605 if ($action !=
'editdate_livraison') {
2606 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_livraison&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'SetDeliveryDate'), 1).
'</a></td>';
2608 print
'</tr></table>';
2610 if ($action ==
'editdate_livraison') {
2611 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2612 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2613 print
'<input type="hidden" name="action" value="setdate_livraison">';
2618 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin, 0,
"setdate_livraison");
2619 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2622 $usehourmin =
'day';
2624 $usehourmin =
'dayhour';
2627 if (
$object->hasDelay() && !empty(
$object->delivery_date) && (
$object->status == $object::STATUS_ORDERSENT ||
$object->status == $object::STATUS_RECEIVED_PARTIALLY)) {
2628 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2636 print
'<table class="nobordernopadding centpercent"><tr><td>';
2637 print $langs->trans(
'IncotermLabel');
2638 print
'<td><td class="right">';
2639 if ($usercancreate) {
2640 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2644 print
'</td></tr></table>';
2647 if ($action !=
'editincoterm') {
2650 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2658 print
'<table class="nobordernopadding centpercent"><tr><td>';
2659 print $langs->trans(
"Categories");
2660 print
'<td><td class="right">';
2661 if ($usercancreate) {
2662 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
2666 print
'</td></tr></table>';
2669 if ($action ==
'edittags') {
2670 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2671 print
'<input type="hidden" name="action" value="settags">';
2672 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2673 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2674 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
2677 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_ORDER, 1);
2683 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2688 print
'<div class="fichehalfright">';
2689 print
'<div class="underbanner clearboth"></div>';
2691 print
'<table class="border tableforfield centpercent">';
2693 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2697 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2698 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2701 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2707 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2708 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2711 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2716 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2718 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
2719 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2721 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2725 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2727 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
2728 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2730 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2738 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->supplier_order_min_amount));
2743 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2744 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) . $alert .
'</td>';
2747 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2762 print
'<div class="clearboth"></div><br>';
2765 $blocname =
'contacts';
2766 $title = $langs->trans(
'ContactsAddresses');
2767 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2771 $blocname =
'notes';
2772 $title = $langs->trans(
'Notes');
2773 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2782 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2783 <input type="hidden" name="token" value="'.
newToken().
'">
2784 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2785 <input type="hidden" name="mode" value="">
2786 <input type="hidden" name="page_y" value="">
2787 <input type="hidden" name="id" value="'.
$object->id.
'">
2788 <input type="hidden" name="socid" value="'.$societe->id.
'">
2793 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
2795 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
2799 print
'<div class="div-table-responsive-no-min">';
2800 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2803 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2806 $inputalsopricewithtax = 1;
2807 $senderissupplier = 2;
2809 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY');
2821 if ($action !=
'editline') {
2824 $parameters = array();
2825 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2829 if (empty($reshook)) {
2845 if ($user->socid == 0 && $action !=
'delete') {
2846 if ($action !=
'createorder' && $action !=
'presend' && $action !=
'editline') {
2847 print
'<div class="tabsAction">';
2849 $parameters = array();
2850 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2852 if (empty($reshook)) {
2857 $langs->load(
'subtotals');
2859 $url_button = array();
2861 $url_button[] = array(
2862 'lang' =>
'subtotals',
2864 'perm' => (
bool) $usercancreate,
2865 'label' => $langs->trans(
'AddTitleLine'),
2866 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
2869 $url_button[] = array(
2870 'lang' =>
'subtotals',
2872 'perm' => (
bool) $usercancreate,
2873 'label' => $langs->trans(
'AddSubtotalLine'),
2874 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
2877 print
dolGetButtonAction(
'', $langs->trans(
'Subtotal'),
'default', $url_button,
'',
true);
2882 if ($usercanvalidate) {
2883 $tmpbuttonlabel = $langs->trans(
'Validate');
2885 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2888 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'">';
2889 print $tmpbuttonlabel;
2893 $langs->load(
"errors");
2894 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"] .
'?action=validate&token=' .
newToken() .
'&id=' .
$object->id, (
string)
$object->id, -1);
2905 if ($usercanorder) {
2906 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2912 if ($usercanapprove) {
2914 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2916 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2919 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2926 if ($usercanapprovesecond) {
2927 if (!empty(
$object->user_approve_id2)) {
2928 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2930 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2933 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2940 if ($usercanapprove || $usercanapprovesecond) {
2941 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2943 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2948 if (empty($user->socid)) {
2950 if ($usercanorder) {
2951 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
2959 if (!$buttonshown && $usercanapprove) {
2962 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2966 if (!$buttonshown && $usercanapprovesecond &&
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
2969 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2973 if (in_array(
$object->status, array(3, 4, 5, 6, 7, 9))) {
2974 if ($usercanorder) {
2975 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2982 $labelofbutton = $langs->trans(
'ReceiveProducts');
2984 $labelofbutton = $langs->trans(
"CreateReception");
2985 if (!empty(
$object->linkedObjects[
'reception'])) {
2986 foreach (
$object->linkedObjects[
'reception'] as $element) {
2987 if ($element->statut >= 0) {
3000 $dispachedLines =
$object->getDispachedLines(1);
3001 $nbDispachedLines = count($dispachedLines);
3002 if ($nbDispachedLines > 0) {
3007 if (in_array(
$object->status, array(3, 4, 5))) {
3008 if (
isModEnabled(
"supplier_order") && $usercanreceive) {
3009 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.
$object->id.
'">'.$labelofbutton.
'</a></div>';
3011 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
3017 if ($usercanorder) {
3018 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=createorder&token='.
newToken().
'#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
3020 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
3026 if ($usercanreceive) {
3027 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&token='.
newToken().
'&action=classifyreception#classifyreception">'.$langs->trans(
"ClassifyReception").
'</a></div>';
3034 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3035 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->socid.
'">'.$langs->trans(
"SupplierOrderCreateBill").
'</a>';
3043 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3045 if (!empty(
$object->linkedObjectsIds[
'invoice_supplier']) || (empty(
$object->linkedObjectsIds[
'invoice_supplier']) && !
getDolGlobalInt(
'SUPPLIER_ORDER_DISABLE_CLASSIFY_BILLED_FROM_SUPPLIER_ORDER'))) {
3046 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3047 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3050 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3056 if ($usercancreate &&
$object->billed > 0 &&
$object->status > $object::STATUS_DRAFT) {
3057 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifyunbilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyUnbilled").
'</a>';
3061 if ($usercancreate) {
3062 print
'<a class="butAction butActionClone" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&socid='.
$object->socid.
'&action=clone&token='.
newToken().
'&object=order">'.$langs->trans(
"ToClone").
'</a>';
3067 if ($usercanorder) {
3068 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3073 if (!empty($usercandelete)) {
3074 if ($hasreception) {
3075 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
3077 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
3087 print
'<!-- form to record supplier order -->'.
"\n";
3088 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
3090 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3091 print
'<input type="hidden" name="action" value="commande">';
3093 print
'<table class="noborder centpercent">';
3095 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
3097 print $form->selectDate($date_com ?:
'',
'', 0, 0, 0,
"commande", 1, 1);
3101 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
3102 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
3105 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
3107 print
'<tr><td class="center" colspan="2">';
3108 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
3109 print
' ';
3110 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
3119 if (
GETPOST(
'modelselected')) {
3120 $action =
'presend';
3123 if ($action !=
'createorder' && $action !=
'presend') {
3124 print
'<div class="fichecenter"><div class="fichehalfleft">';
3129 $relativepath = $objref.
'/'.$objref.
'.pdf';
3131 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3132 $genallowed = $usercanread;
3133 $delallowed = $usercancreate;
3136 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, (
int) $genallowed, (int) $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'',
$object->thirdparty->default_lang,
'', $object);
3137 $somethingshown = $formfile->numoffiles;
3140 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'supplier_order',
'order_supplier'), 1);
3141 $linktoelem = $tmparray[
'linktoelem'];
3142 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
3143 print $htmltoenteralink;
3145 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3147 print
'</div><div class="fichehalfright">';
3149 if ($action ==
'classifyreception') {
3152 print
'<!-- form to record purchase order received -->'.
"\n";
3153 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
3154 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3155 print
'<input type="hidden" name="action" value="livraison">';
3158 print
'<table class="noborder centpercent">';
3160 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
3162 print $form->selectDate($datepreselected,
'', 1, 1, 0,
"commande", 1, 1);
3163 print
"</td></tr>\n";
3165 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
3167 $liv[
''] =
' ';
3168 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
3169 $liv[
'par'] = $langs->trans(
"PartialWoman");
3170 $liv[
'nev'] = $langs->trans(
"NeverReceived");
3171 $liv[
'can'] = $langs->trans(
"Canceled");
3173 print $form->selectarray(
"type", $liv);
3176 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
3177 print
'<tr><td class="center" colspan="2">';
3178 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
3179 print
' ';
3180 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
3189 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3191 $somethingshown = $formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3193 print
'</div></div>';
3199 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
3200 $mode =
GETPOST(
'mode',
'alpha');
3201 $ws_url =
$object->thirdparty->webservices_url;
3202 $ws_key =
$object->thirdparty->webservices_key;
3203 $ws_user =
GETPOST(
'ws_user',
'alpha');
3204 $ws_password =
GETPOST(
'ws_password',
'alpha');
3205 $error_occurred =
false;
3208 $ws_ns =
'http://www.dolibarr.org/ns/';
3209 $ws_authentication = array(
3210 'dolibarrkey' => $ws_key,
3211 'sourceapplication' =>
'DolibarrWebServiceClient',
3212 'login' => $ws_user,
3213 'password' => $ws_password,
3220 if (empty($ws_url) || empty($ws_key)) {
3221 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
3223 $error_occurred =
true;
3224 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
3229 if ($mode ==
"init") {
3231 print
'<table class="border centpercent">';
3232 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
3233 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3234 print
'<input type="hidden" name="action" value="webservice">';
3235 print
'<input type="hidden" name="mode" value="check">';
3237 if ($error_occurred) {
3238 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
3239 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
3242 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
3244 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input class="width100" type="text" name="ws_user"></td></tr>';
3246 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input class="width100" type="text" name="ws_password"></td></tr>';
3248 print
'<tr><td class="center" colspan="2">';
3249 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
3250 print
' ';
3252 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
3259 } elseif ($mode ==
"check") {
3261 $ws_thirdparty =
'';
3262 $error_occurred =
false;
3265 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
3266 $soapclient_user->soap_defencoding =
'UTF-8';
3267 $soapclient_user->decodeUTF8(
false);
3270 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ws_user);
3271 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
3272 $user_status_code = $result_user[
"result"][
"result_code"];
3274 if ($user_status_code ==
"OK") {
3276 $ws_entity = $result_user[
"user"][
"entity"];
3277 $ws_authentication[
'entity'] = $ws_entity;
3278 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
3279 if (empty($ws_thirdparty)) {
3280 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"),
null,
'errors');
3281 $error_occurred =
true;
3284 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
3285 $soapclient_product->soap_defencoding =
'UTF-8';
3286 $soapclient_product->decodeUTF8(
false);
3291 foreach (
$object->lines as $line) {
3293 $ref_supplier = $line->ref_supplier;
3294 $line_id = $i.
"º) ".$line->product_ref.
": ";
3295 if (empty($ref_supplier)) {
3298 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
3299 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
3300 if (!$result_product) {
3301 setEventMessages($line_id.$langs->trans(
"Error").
" SOAP ".$soapclient_product->error_str.
" - ".$soapclient_product->response,
null,
'errors');
3302 $error_occurred =
true;
3307 $status_code = $result_product[
"result"][
"result_code"];
3308 if (empty($status_code)) {
3309 setEventMessages($langs->trans(
"Error").
" SOAP '".$soapclient_product->error_str.
"'",
null,
'errors');
3310 } elseif ($status_code !=
"OK") {
3311 if ($status_code ==
"NOT_FOUND") {
3312 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'",
null,
'warnings');
3314 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'",
null,
'errors');
3315 $error_occurred =
true;
3322 $supplier_price =
price($result_product[
"product"][
"price_net"]);
3323 $local_price =
null;
3326 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
3327 if (count($product_fourn_list) > 0) {
3328 foreach ($product_fourn_list as $product_fourn_line) {
3330 if ($product_fourn_line->fourn_id ==
$object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
3331 $local_price =
price($product_fourn_line->fourn_price);
3336 if ($local_price !=
null && $local_price != $supplier_price) {
3337 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price,
null,
'warnings');
3341 if (empty($result_product[
"product"][
"status_tosell"])) {
3342 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'",
null,
'warnings');
3346 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
3347 setEventMessages($langs->trans(
"RemoteUserNotPermission"),
null,
'errors');
3348 $error_occurred =
true;
3349 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
3350 setEventMessages($langs->trans(
"RemoteUserBadCredentials"),
null,
'errors');
3351 $error_occurred =
true;
3353 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'",
null,
'errors');
3354 $error_occurred =
true;
3358 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
3359 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3360 print
'<input type="hidden" name="action" value="webservice">';
3361 print
'<input type="hidden" name="mode" value="send">';
3362 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
3363 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
3364 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
3365 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
3366 if ($error_occurred) {
3367 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
3369 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
3370 print
' ';
3372 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
3378 $modelmail =
'order_supplier_send';
3379 $defaulttopic =
'SendOrderRef';
3381 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
3382 $trackid =
'sord'.$object->id;
3384 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_VALIDATED
Validated status.
const STATUS_RECEIVED_COMPLETELY
Received completely.
const STATUS_DRAFT
Draft status.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
Class to manage line orders.
Class to manage a WYSIWYG editor.
Class to manage the table of subscription to notifications.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
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.
$date_start
Variables from include:
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.