41require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
50require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
53if (isModEnabled(
'supplier_proposal')) {
54 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
56if (isModEnabled(
"product")) {
57 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
59if (isModEnabled(
'project')) {
60 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
63require_once NUSOAP_PATH.
'/nusoap.php';
65if (isModEnabled(
'variants')) {
66 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
69if (isModEnabled(
'stock')) {
70 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
71 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
84$langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
85if (isModEnabled(
'incoterm')) {
86 $langs->load(
'incoterm');
91$action =
GETPOST(
'action',
'alpha');
92$confirm =
GETPOST(
'confirm',
'alpha');
93$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
94$cancel =
GETPOST(
'cancel',
'alpha');
95$backtopage =
GETPOST(
'backtopage',
'alpha');
96$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
103$origin =
GETPOST(
'origin',
'alpha');
106$stockDelete =
GETPOST(
'stockDelete',
'int');
117if (!empty($user->socid)) {
118 $socid = $user->socid;
122$hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
128$extrafields->fetch_name_optionals_label(
$object->table_element);
131 $socid = $user->socid;
135if ($id > 0 || !empty($ref)) {
136 $ret =
$object->fetch($id, $ref);
140 $ret =
$object->fetch_thirdparty();
144} elseif (!empty($socid) && $socid > 0) {
146 $ret =
$object->fetch_thirdparty();
153$isdraft = (isset(
$object->status) && (
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
154$result =
restrictedArea($user,
'fournisseur',
$object,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
157$usercanread = ($user->hasRight(
"fournisseur",
"commande",
"lire") || $user->hasRight(
"supplier_order",
"lire"));
158$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
159$usercandelete = (($user->hasRight(
"fournisseur",
"commande",
"supprimer") || $user->hasRight(
"supplier_order",
"supprimer")) || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT));
162$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate")));
165$usercanapprove = $user->hasRight(
"fournisseur",
"commande",
"approuver");
166$usercanapprovesecond = $user->hasRight(
"fournisseur",
"commande",
"approve2");
167$usercanorder = $user->hasRight(
"fournisseur",
"commande",
"commander");
168if (!isModEnabled(
'reception')) {
169 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
171 $usercanreceive = $user->hasRight(
"reception",
"creer");
175$permissionnote = $usercancreate;
176$permissiondellink = $usercancreate;
177$permissiontoedit = $usercancreate;
178$permissiontoadd = $usercancreate;
179$permissiontoeditextra = $permissiontoadd;
180if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
182 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
186$caneditproject =
false;
187if (isModEnabled(
'project')) {
198$parameters = array(
'socid' => $socid);
199$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
204if (empty($reshook)) {
205 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
207 if (empty($backtopage) || ($cancel && empty($id))) {
208 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
209 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
210 $backtopage = $backurlforlist;
212 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
218 if (!empty($backtopageforcancel)) {
219 header(
"Location: ".$backtopageforcancel);
221 } elseif (!empty($backtopage)) {
222 header(
"Location: ".$backtopage);
228 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
230 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
232 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
234 if ($action ==
'setref_supplier' && $usercancreate) {
235 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
242 if ($action ==
'set_incoterms' && $usercancreate) {
250 if ($action ==
'setconditions' && $usercancreate) {
258 if ($action ==
'setmode' && $usercancreate) {
263 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
265 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
266 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
272 if ($action ==
'setbankaccount' && $usercancreate) {
280 if ($action ==
'setdate_livraison' && $usercancreate) {
281 $result =
$object->setDeliveryDate($user, $datelivraison);
288 if ($action ==
'classin' && $usercancreate && $caneditproject) {
289 $result =
$object->setProject($projectid);
296 if ($action ==
'settags' && isModEnabled(
'category') && $usercancreate) {
306 if (!empty($new_socid) && $new_socid !=
$object->thirdparty->id) {
310 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
311 $sql .=
' SET fk_soc = '.((int) $new_socid);
312 $sql .=
' WHERE fk_soc = '.((int)
$object->thirdparty->id);
313 $sql .=
' AND rowid = '.((int)
$object->id);
315 $res = $db->query($sql);
323 foreach (
$object->lines as $l) {
324 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
325 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
326 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
327 $sql .=
' AND fk_soc = '.((int) $new_socid);
328 $sql .=
' ORDER BY unitprice ASC';
330 $resql = $db->query($sql);
332 $num_row = $db->num_rows($resql);
333 if (empty($num_row)) {
339 $l->ref_supplier =
'';
343 $obj = $db->fetch_object($resql);
344 $l->subprice = $obj->unitprice;
345 $l->total_ht = $obj->price;
346 $l->tva_tx = $obj->tva_tx;
347 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
348 $l->total_ttc = $l->total_ht + $l->total_tva;
349 $l->ref_supplier = $obj->ref_fourn;
360 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
364 if ($action ==
'setremisepercent' && $usercancreate) {
371 if ($action ==
'reopen' && $permissiontoadd) {
372 $resSetReopen =
$object->setReopen($user);
374 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
384 if ($action ==
'classifybilled' && $usercancreate) {
385 $ret =
$object->classifyBilled($user);
391 if ($action ==
'classifyunbilled' && $usercancreate) {
392 $ret =
$object->classifyUnBilled($user);
399 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
403 foreach (
$object->lines as $line) {
404 if ($line->product_type == 1) {
405 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $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);
408 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
410 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
411 $vat_rate = str_replace(
'*',
'', $vat_rate);
414 foreach (
$object->lines as $line) {
415 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, (
float) $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);
417 } elseif ($action ==
'addline' && $usercancreate) {
420 $langs->load(
'errors');
425 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
429 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
430 if ($prod_entry_mode ==
'free') {
444 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
445 if (empty($remise_percent)) {
450 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
451 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
453 if (is_array($extralabelsline)) {
455 foreach ($extralabelsline as $key => $value) {
456 unset($_POST[
"options_".$key]);
460 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
461 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
464 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
465 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
468 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
469 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
472 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
473 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
476 if (
GETPOST(
'qty',
'alpha') ==
'') {
477 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
481 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
482 if ($combinations =
GETPOST(
'combinations',
'array')) {
486 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
487 $idprod = $res->fk_product_child;
489 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
495 if ($prod_entry_mode !=
'free' && empty($error)) {
499 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
504 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
505 $idprod = (int) $reg[1];
506 $res = $productsupplier->fetch($idprod);
509 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
511 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
512 if ($productsupplier->fourn_socid != $socid) {
513 $productsupplier->ref_supplier =
'';
516 $fksoctosearch =
$object->thirdparty->id;
517 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
519 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
520 $qtytosearch = (float) $qty;
522 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
523 $res = $productsupplier->fetch($idprod);
527 $label = $productsupplier->label;
531 $outputlangs = $langs;
533 if (
GETPOST(
'lang_id',
'aZ09')) {
534 $newlang =
GETPOST(
'lang_id',
'aZ09');
536 if (empty($newlang)) {
537 $newlang =
$object->thirdparty->default_lang;
539 if (!empty($newlang)) {
541 $outputlangs->setDefaultLang($newlang);
543 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
545 $desc = $productsupplier->description;
548 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
549 $desc = $productsupplier->desc_supplier;
560 $ref_supplier = $productsupplier->ref_supplier;
564 if (!GETPOSTISSET(
'tva_tx')) {
565 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
566 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
567 $tmpidprodfournprice = (int) $tmpidprodfournprice;
569 $tmpidprodfournprice = 0;
573 if (empty($tva_tx)) {
581 $type = $productsupplier->type;
582 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
583 $price_base_type =
'HT';
585 $pu_devise =
price2num($price_ht_devise,
'CU');
586 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
587 $price_base_type =
'TTC';
589 $pu_devise =
price2num($price_ttc_devise,
'CU');
591 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
592 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
593 $pu = $productsupplier->fourn_pu;
596 $pu = $productsupplier->fourn_pu;
597 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
607 ($price_base_type ==
'HT' ? $pu : 0),
613 $productsupplier->product_fourn_price_id,
617 ($price_base_type ==
'TTC' ? $pu : 0),
624 $productsupplier->fk_unit,
628 min($rank, count(
$object->lines) + 1)
631 if ($idprod == -99 || $idprod == 0) {
634 $langs->load(
"errors");
635 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
640 $langs->load(
"errors");
641 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
643 } elseif (empty($error)) {
644 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
645 $tva_tx = str_replace(
'*',
'', $tva_tx);
646 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
649 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
653 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
661 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
666 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tva_tx / 100)),
'MU');
668 $price_base_type =
'HT';
669 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
671 $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);
675 if (!$error && $result > 0) {
682 $outputlangs = $langs;
685 $newlang =
$object->thirdparty->default_lang;
686 if (
GETPOST(
'lang_id',
'aZ09')) {
687 $newlang =
GETPOST(
'lang_id',
'aZ09');
690 if (!empty($newlang)) {
692 $outputlangs->setDefaultLang($newlang);
697 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
703 unset($_POST [
'prod_entry_mode']);
705 unset($_POST[
'qty']);
706 unset($_POST[
'type']);
707 unset($_POST[
'remise_percent']);
709 unset($_POST[
'price_ht']);
710 unset($_POST[
'multicurrency_price_ht']);
711 unset($_POST[
'price_ttc']);
712 unset($_POST[
'fourn_ref']);
713 unset($_POST[
'tva_tx']);
714 unset($_POST[
'label']);
715 unset($localtax1_tx);
716 unset($localtax2_tx);
717 unset($_POST[
'np_marginRate']);
718 unset($_POST[
'np_markRate']);
719 unset($_POST[
'dp_desc']);
720 unset($_POST[
'idprodfournprice']);
721 unset($_POST[
'units']);
723 unset($_POST[
'date_starthour']);
724 unset($_POST[
'date_startmin']);
725 unset($_POST[
'date_startsec']);
726 unset($_POST[
'date_startday']);
727 unset($_POST[
'date_startmonth']);
728 unset($_POST[
'date_startyear']);
729 unset($_POST[
'date_endhour']);
730 unset($_POST[
'date_endmin']);
731 unset($_POST[
'date_endsec']);
732 unset($_POST[
'date_endday']);
733 unset($_POST[
'date_endmonth']);
734 unset($_POST[
'date_endyear']);
746 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
753 $res = $line->fetch($lineid);
760 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
761 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, (
float)
price2num(
GETPOSTFLOAT(
'qty')), $line->fk_product,
'none',
GETPOSTINT(
'socid')) < 0) {
762 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
771 if (preg_match(
'/\*/', $vat_rate)) {
776 $vat_rate = str_replace(
'*',
'', $vat_rate);
780 if (
GETPOST(
'price_ht') !=
'') {
781 $price_base_type =
'HT';
785 $vatratecleaned = $vat_rate;
786 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
787 $vatratecleaned = trim($reg[1]);
788 $vatratecode = $reg[2];
792 $ht = (float) $ttc / (1 + ((
float) $vatratecleaned / 100));
793 $price_base_type =
'HT';
799 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
800 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
802 if (is_array($extralabelsline)) {
803 foreach ($extralabelsline as $key => $value) {
804 unset($_POST[
"options_".$key]);
810 GETPOST(
'product_desc',
'restricthtml'),
819 GETPOSTISSET(
"type") ?
GETPOST(
"type") : $line->product_type,
825 (float) $pu_ht_devise,
828 unset($_POST[
'qty']);
829 unset($_POST[
'type']);
830 unset($_POST[
'idprodfournprice']);
831 unset($_POST[
'remmise_percent']);
832 unset($_POST[
'dp_desc']);
833 unset($_POST[
'np_desc']);
835 unset($_POST[
'fourn_ref']);
836 unset($_POST[
'tva_tx']);
837 unset($_POST[
'date_start']);
838 unset($_POST[
'date_end']);
839 unset($_POST[
'units']);
840 unset($localtax1_tx);
841 unset($localtax2_tx);
843 unset($_POST[
'date_starthour']);
844 unset($_POST[
'date_startmin']);
845 unset($_POST[
'date_startsec']);
846 unset($_POST[
'date_startday']);
847 unset($_POST[
'date_startmonth']);
848 unset($_POST[
'date_startyear']);
849 unset($_POST[
'date_endhour']);
850 unset($_POST[
'date_endmin']);
851 unset($_POST[
'date_endsec']);
852 unset($_POST[
'date_endday']);
853 unset($_POST[
'date_endmonth']);
854 unset($_POST[
'date_endyear']);
859 $outputlangs = $langs;
862 $newlang =
GETPOST(
'lang_id',
'aZ09');
865 $newlang =
$object->thirdparty->default_lang;
867 if (!empty($newlang)) {
869 $outputlangs->setDefaultLang($newlang);
874 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
889 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
892 $result =
$object->deleteLine($lineid);
897 $outputlangs = $langs;
900 $newlang =
GETPOST(
'lang_id',
'aZ09');
903 $newlang =
$object->thirdparty->default_lang;
905 if (!empty($newlang)) {
907 $outputlangs->setDefaultLang($newlang);
911 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
933 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
941 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
945 $result =
$object->valid($user);
949 $outputlangs = $langs;
952 $newlang =
GETPOST(
'lang_id',
'aZ09');
955 $newlang =
$object->thirdparty->default_lang;
957 if (!empty($newlang)) {
959 $outputlangs->setDefaultLang($newlang);
964 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
977 $action =
'confirm_approve';
987 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
992 $qualified_for_stock_change = 0;
994 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
996 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1000 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') && $qualified_for_stock_change) {
1001 if (!$idwarehouse || $idwarehouse == -1) {
1003 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1009 $result =
$object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1012 $outputlangs = $langs;
1015 $newlang =
GETPOST(
'lang_id',
'aZ09');
1018 $newlang =
$object->thirdparty->default_lang;
1020 if (!empty($newlang)) {
1022 $outputlangs->setDefaultLang($newlang);
1024 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1035 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1042 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1046 $result =
$object->refuse($user);
1048 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1056 if ($action ==
'commande') {
1057 $methodecommande =
GETPOSTINT(
'methodecommande');
1061 } elseif ($methodecommande <= 0 && !
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL')) {
1062 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1063 $action =
'createorder';
1067 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1069 $object->context[
"sendmanualtriggers"] =
GETPOST(
"manual_trigger_send");
1073 $outputlangs = $langs;
1076 $newlang =
GETPOST(
'lang_id',
'aZ09');
1079 $newlang =
$object->thirdparty->default_lang;
1081 if (!empty($newlang)) {
1083 $outputlangs->setDefaultLang($newlang);
1085 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1096 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1104 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1107 $errorsOnDelete = array();
1162 if (empty($errOnDelete)) {
1163 $result =
$object->delete($user);
1166 header(
"Location: " . DOL_URL_ROOT .
'/fourn/commande/list.php?restore_lastsearch_values=1');
1179 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1181 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1182 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1187 $result =
$object->createFromClone($user, $socid);
1189 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1201 if ($action ==
'livraison' && $usercanreceive) {
1212 $langs->load(
"deliveries");
1222 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1233 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1237 $result =
$object->cancel($user);
1239 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1247 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1250 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1251 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1252 $trackid =
'sord'.$object->id;
1253 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1256 $upload_dir =
$conf->fournisseur->commande->dir_output;
1257 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1260 if ($action ==
'update_extras' && $permissiontoeditextra) {
1263 $attribute_name =
GETPOST(
'attribute',
'aZ09');
1266 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
1272 $result =
$object->updateExtraField($attribute_name,
'ORDER_SUPPLIER_MODIFY');
1280 $action =
'edit_extras';
1287 if ($action ==
'add' && $permissiontoadd) {
1289 $selectedLines =
GETPOST(
'toselect',
'array');
1291 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1307 $object->delivery_date = $datelivraison;
1309 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1310 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1316 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1324 if (!empty($origin) && !empty($originid)) {
1325 $element = $subelement = $origin;
1326 $classname = ucfirst($subelement);
1327 if ($origin ==
'propal' || $origin ==
'proposal') {
1328 $element =
'comm/propal';
1329 $subelement =
'propal';
1330 $classname =
'Propal';
1332 if ($origin ==
'order' || $origin ==
'commande') {
1333 $element = $subelement =
'commande';
1334 $classname =
'Commande';
1336 if ($origin ==
'supplier_proposal') {
1337 $classname =
'SupplierProposal';
1338 $element =
'supplier_proposal';
1339 $subelement =
'supplier_proposal';
1343 $object->origin_id = $originid;
1347 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1348 if (!empty($other_linked_objects)) {
1349 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
1356 $srcobject =
new $classname($db);
1359 $result = $srcobject->fetch(
$object->origin_id);
1361 if (empty(
$object->delivery_date)) {
1362 $tmpdate = $srcobject->delivery_date;
1363 $object->setDeliveryDate($user, $tmpdate);
1365 $object->set_id_projet($user, $srcobject->fk_project);
1367 $lines = $srcobject->lines;
1368 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1369 $srcobject->fetch_lines();
1370 $lines = $srcobject->lines;
1373 $fk_parent_line = 0;
1374 $num = count($lines);
1376 for ($i = 0; $i < $num; $i++) {
1378 empty($lines[$i]->subprice)
1379 || $lines[$i]->qty < 0
1380 || !in_array($lines[$i]->
id, $selectedLines)
1381 || $lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE
1386 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1387 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1388 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1390 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1391 $fk_parent_line = 0;
1395 if (method_exists($lines[$i],
'fetch_optionals')) {
1396 $lines[$i]->fetch_optionals();
1397 $array_option = $lines[$i]->array_options;
1399 $array_option = array();
1403 $product_fourn_price_id = 0;
1404 if ($origin ==
"commande") {
1406 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty,
$object->socid);
1407 $lines[$i]->subprice = 0;
1409 $ref_supplier = $productsupplier->ref_supplier;
1410 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1412 foreach ($srcobject->lines as $li) {
1413 $sql =
'SELECT price, unitprice, tva_tx, remise_percent, entity, ref_fourn';
1414 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
1415 $sql .=
' WHERE fk_product = '.((int) $li->fk_product);
1416 $sql .=
' AND entity IN ('.getEntity(
'product_fournisseur_price').
')';
1417 $sql .=
' AND fk_soc = '.((int)
$object->socid);
1418 $sql .=
' ORDER BY unitprice ASC';
1420 $resql = $db->query($sql);
1422 $num_row = $db->num_rows($resql);
1423 if (empty($num_row)) {
1424 $li->remise_percent = 0;
1426 $obj = $db->fetch_object($resql);
1427 $li->subprice = $obj->unitprice;
1428 $li->remise_percent = $obj->remise_percent;
1437 $ref_supplier = $lines[$i]->ref_fourn;
1438 $product_fourn_price_id = 0;
1441 $tva_tx = $lines[$i]->tva_tx;
1443 if ($origin ==
"commande") {
1445 $soc->fetch($socid);
1446 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1451 $lines[$i]->subprice,
1454 $lines[$i]->localtax1_tx,
1455 $lines[$i]->localtax2_tx,
1456 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1457 $product_fourn_price_id,
1459 $lines[$i]->remise_percent,
1462 $lines[$i]->product_type,
1468 $lines[$i]->fk_unit,
1471 !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid,
1473 $lines[$i]->special_code
1483 if ($result > 0 && $lines[$i]->product_type == 9) {
1484 $fk_parent_line = $result;
1492 $parameters = array(
'objFrom' => $srcobject);
1493 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1516 if (isModEnabled(
'category')) {
1517 $categories =
GETPOST(
'categories',
'array');
1518 if (method_exists(
$object,
'setCategories')) {
1519 $object->setCategories($categories);
1524 $langs->load(
"errors");
1529 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode((
string) ($id)));
1536 if ($action ==
'addcontact' && $permissiontoadd) {
1540 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1544 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1547 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1548 $langs->load(
"errors");
1549 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1554 } elseif ($action ==
'swapstatut' &&
$object->id > 0 && $permissiontoadd) {
1557 } elseif ($action ==
'deletecontact' &&
$object->id > 0 && $permissiontoadd) {
1562 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1576$form =
new Form($db);
1579$productstatic =
new Product($db);
1580if (isModEnabled(
'project')) {
1584$title =
$object->ref.
" - ".$langs->trans(
'Card');
1585if ($action ==
'create') {
1586 $title = $langs->trans(
"NewOrderSupplier");
1588$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1589llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-supplier-order page-card');
1593if ($action ==
'create') {
1594 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1598 $currency_code =
$conf->currency;
1605 $societe->fetch($socid);
1608 if (!empty($origin) && !empty($originid)) {
1610 $element = $subelement = $origin;
1611 $classname = ucfirst($subelement);
1613 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1614 $element = $regs[1];
1615 $subelement = $regs[2];
1618 if ($origin ==
'propal' || $origin ==
'proposal') {
1619 $classname =
'Propal';
1620 $element =
'comm/propal';
1621 $subelement =
'propal';
1623 if ($origin ==
'order' || $origin ==
'commande') {
1624 $classname =
'Commande';
1625 $element = $subelement =
'commande';
1627 if ($origin ==
'supplier_proposal') {
1628 $classname =
'SupplierProposal';
1629 $element =
'supplier_proposal';
1630 $subelement =
'supplier_proposal';
1636 $objectsrc =
new $classname($db);
1637 $objectsrc->fetch($originid);
1638 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1639 $objectsrc->fetch_lines();
1641 $objectsrc->fetch_thirdparty();
1644 $objectsrc->fetch_optionals();
1645 $object->array_options = $objectsrc->array_options;
1647 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1648 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1650 if ($origin ==
"commande") {
1651 $cond_reglement_id = 0;
1652 $mode_reglement_id = 0;
1653 $datelivraison =
'';
1654 $objectsrc->note_private =
'';
1655 $objectsrc->note_public =
'';
1656 if ($societe =
$object->thirdparty) {
1657 $cond_reglement_id = $societe->cond_reglement_supplier_id;
1658 $mode_reglement_id = $societe->mode_reglement_supplier_id;
1659 if (isModEnabled(
"multicurrency")) {
1660 $currency_code = $societe->multicurrency_code;
1662 $currency_tx = $societe->multicurrency_tx;
1667 $soc = $objectsrc->thirdparty;
1669 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1670 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1671 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1672 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1673 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1674 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1679 $datelivraison = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1681 if (isModEnabled(
"multicurrency")) {
1682 if (!empty($objectsrc->multicurrency_code)) {
1683 $currency_code = $objectsrc->multicurrency_code;
1685 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1686 $currency_tx = $objectsrc->multicurrency_tx;
1690 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1691 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1694 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1697 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1698 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1700 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1701 $currency_code = $societe->multicurrency_code;
1704 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1705 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1709 if (empty($cond_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID')) {
1712 if (empty($mode_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID')) {
1716 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1717 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1718 print
'<input type="hidden" name="action" value="add">';
1719 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1720 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1721 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1722 print
'<input type="hidden" name="changecompany" value="0">';
1724 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1726 if ($backtopageforcancel) {
1727 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1730 if (!empty($currency_tx)) {
1731 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1737 $parameters = array();
1739 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierOrder', $parameters,
$object, $action);
1740 if (empty($reshook)) {
1741 print
'<table class="border centpercent">';
1744 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1747 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1750 if (!empty($societe->id) && $societe->id > 0) {
1751 print $societe->getNomUrl(1,
'supplier');
1752 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1754 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
1755 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company((empty($socid) ?
'' : $socid),
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1759 $(document).ready(function() {
1760 $("#socid").change(function() {
1761 console.log("We have changed the company - Reload page");
1763 $("input[name=action]").val("create");
1764 $("input[name=changecompany]").val("1");
1765 $("form[name=add]").submit();
1770 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>';
1774 if (!empty($societe->id) && $societe->id > 0) {
1776 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1778 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
1780 $thirdparty = $societe;
1782 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1783 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1789 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1793 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1794 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1795 print $form->getSelectConditionsPaiements((GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id') != 0) ?
GETPOSTINT(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id', -1, 1);
1799 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1800 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1801 $form->select_types_paiements((GETPOSTISSET(
'mode_reglement_id') &&
GETPOSTINT(
'mode_reglement_id') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
1806 print $langs->trans(
'DateDeliveryPlanned');
1813 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1815 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin, 0,
"set");
1820 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER') && isModEnabled(
"bank")) {
1821 $langs->load(
"bank");
1822 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1823 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
1824 $form->select_comptes($fk_account ??
'',
'fk_account', 0,
'', 1);
1829 if (isModEnabled(
'project')) {
1832 $langs->load(
'projects');
1833 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1834 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects((!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
1835 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>';
1840 if (isModEnabled(
'incoterm')) {
1841 $fkincoterms = (!empty(
$object->fk_incoterms) ?
$object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1842 $locincoterms = (!empty(
$object->location_incoterms) ?
$object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1844 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"),
$object->label_incoterms, 1).
'</label></td>';
1845 print
'<td class="maxwidthonsmartphone">';
1846 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
1847 print $form->select_incoterms($fkincoterms, $locincoterms);
1852 if (isModEnabled(
"multicurrency")) {
1854 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
1855 print
'<td class="maxwidthonsmartphone">';
1856 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
1857 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
1862 if (isModEnabled(
"category")) {
1863 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
1864 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories',
$object);
1868 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
1870 $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%');
1871 print $doleditor->Create(1);
1876 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
1878 $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%');
1879 print $doleditor->Create(1);
1884 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1885 print
"\n<!-- ".$classname.
" info -->";
1887 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1888 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1889 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1890 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1891 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1893 $newclassname = $classname;
1894 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
1895 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1896 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1897 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1898 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1901 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1902 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1905 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1907 if (isModEnabled(
"multicurrency")) {
1908 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1909 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
1910 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
1915 $parameters = array();
1916 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1917 print $hookmanager->resPrint;
1919 if (empty($reshook)) {
1920 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_SUPPLIER_ORDER') && !empty($societe->id)) {
1923 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($societe->table_element);
1924 if ($societe->fetch_optionals() > 0) {
1925 $object->array_options = array_merge(
$object->array_options, $societe->array_options);
1929 print
$object->showOptionals($extrafields,
'create');
1937 print $form->buttonsSaveCancel(
"CreateDraft");
1940 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1941 $title = $langs->trans(
'ProductsAndServices');
1944 print
'<div class="div-table-responsive-no-min">';
1945 print
'<table class="noborder centpercent">';
1947 $selectedLines = array();
1949 $objectsrc->printOriginLinesList(
'', $selectedLines);
1955} elseif (!empty(
$object->id)) {
1957 $result =
$object->fetch($id, $ref);
1960 $societe =
$object->thirdparty;
1962 $author =
new User($db);
1963 $author->fetch(
$object->user_author_id);
1967 $title = $langs->trans(
"SupplierOrder");
1974 if ($action ==
'delete') {
1975 $arrayAjouts = array();
2006 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.((
int)
$object->id), $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal);
2010 if ($action ==
'clone') {
2011 $filter =
'(s.fournisseur:=:1)';
2013 $formquestion = array(
2014 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter))
2017 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2021 if ($action ==
'valid') {
2025 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
2035 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
2036 if (isModEnabled(
'notification')) {
2037 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2038 $notify =
new Notify($db);
2040 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE',
$object->socid,
$object);
2043 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
2048 if ($action ==
'approve' || $action ==
'approve2') {
2049 $qualified_for_stock_change = 0;
2051 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2053 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2056 $formquestion = array();
2057 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') && $qualified_for_stock_change) {
2058 $langs->load(
"stocks");
2059 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2062 if (
$conf->browser->name ==
'ie') {
2065 $formquestion = array(
2069 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2072 $text = $langs->trans(
"ConfirmApproveThisOrder",
$object->ref);
2073 if (isModEnabled(
'notification')) {
2074 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2075 $notify =
new Notify($db);
2077 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE',
$object->socid,
$object);
2080 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
2084 if ($action ==
'refuse') {
2085 $formquestion = array(
2088 'name' =>
'refuse_note',
2089 'label' => $langs->trans(
"Reason"),
2091 'morecss' =>
'minwidth300'
2094 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder",
$object->ref),
"confirm_refuse", $formquestion, 0, 1);
2098 if ($action ==
'cancel') {
2099 $formquestion = array(
2102 'name' =>
'cancel_note',
2103 'label' => $langs->trans(
"Reason"),
2105 'morecss' =>
'minwidth300'
2108 if (isModEnabled(
'notification')) {
2109 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2110 $notify =
new Notify($db);
2113 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_CANCEL',
$object->socid,
$object);
2115 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder",
$object->ref),
"confirm_cancel", $formquestion, 0, 1);
2119 if ($action ==
'commande') {
2120 $formquestion = array();
2122 if (isModEnabled(
'notification')) {
2123 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2124 $notify =
new Notify($db);
2127 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_SUBMIT',
$object->socid,
$object);
2129 if (isModEnabled(
'webhook')) {
2130 require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
2131 $targetstatic =
new Target($db);
2132 if ($targetstatic->isTriggerCodeManualTarget(
'ORDER_SUPPLIER_SUBMIT') > 0) {
2133 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'manual_trigger_send',
'label' => $langs->trans(
"QuestionSendManualTrigger"));
2136 $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);
2140 if ($action ==
'ask_deleteline') {
2141 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2144 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2145 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
2146 if (empty($reshook)) {
2147 $formconfirm .= $hookmanager->resPrint;
2148 } elseif ($reshook > 0) {
2149 $formconfirm = $hookmanager->resPrint;
2158 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2160 $morehtmlref =
'<div class="refidno">';
2162 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, (
int) $usercancreate,
'string',
'', 0, 1);
2163 $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);
2165 $morehtmlref .=
'<br>';
2166 if (
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2167 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2168 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2169 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2170 $filter =
'(s.fournisseur:=:1)';
2171 $morehtmlref .= $form->select_company(
$object->thirdparty->id,
'new_socid', $filter,
'', 0, 0, array(), 0,
'minwidth300');
2172 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2173 $morehtmlref .=
'</form>';
2175 if (!
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') || $action !=
'edit_thirdparty') {
2177 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2179 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'supplier');
2181 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.
$object->thirdparty->id.
'&search_company='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2186 if (isModEnabled(
'project')) {
2187 $langs->load(
"projects");
2188 $morehtmlref .=
'<br>';
2189 if ($permissiontoadd) {
2190 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2191 if ($action !=
'classify' && $caneditproject) {
2192 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2194 $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');
2196 if (!empty(
$object->fk_project)) {
2198 $proj->fetch(
$object->fk_project);
2199 $morehtmlref .= $proj->getNomUrl(1);
2201 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2206 $morehtmlref .=
'</div>';
2209 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2212 $parameters = array();
2214 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierOrder', $parameters,
$object, $action);
2215 if (empty($reshook)) {
2216 print
'<div class="fichecenter">';
2217 print
'<div class="fichehalfleft">';
2218 print
'<div class="underbanner clearboth"></div>';
2220 print
'<table class="border tableforfield centpercent">';
2223 if (
$object->methode_commande_id > 0) {
2228 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2231 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2235 if (
$object->methode_commande) {
2236 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.
$object->getInputMethod().
'</td></tr>';
2241 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2242 print
'<td>'.$author->getNomUrl(-1,
'', 0, 0, 0).
'</td>';
2247 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2248 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2250 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2251 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2254 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
2255 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
2256 $absolute_discount =
price2num($absolute_discount,
'MT');
2257 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2259 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2261 $thirdparty = $societe;
2263 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
2264 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2269 $langs->load(
'bills');
2270 print
'<tr><td class="nowrap">';
2271 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2272 print $langs->trans(
'PaymentConditions');
2274 if ($action !=
'editconditions' && $permissiontoadd) {
2275 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>';
2277 print
'</tr></table>';
2279 if ($action ==
'editconditions') {
2280 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id');
2282 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->cond_reglement_id,
'none');
2288 $langs->load(
'bills');
2289 print
'<tr><td class="nowrap">';
2290 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2291 print $langs->trans(
'PaymentMode');
2293 if ($action !=
'editmode' && $permissiontoadd) {
2294 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>';
2296 print
'</tr></table>';
2298 if ($action ==
'editmode') {
2299 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2301 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
2306 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER') && isModEnabled(
"bank")) {
2307 print
'<tr><td class="nowrap">';
2308 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2309 print $langs->trans(
'BankAccount');
2311 if ($action !=
'editbankaccount' && $permissiontoadd) {
2312 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>';
2314 print
'</tr></table>';
2316 if ($action ==
'editbankaccount') {
2317 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
2319 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
2327 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2328 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2333 print
'<table class="nobordernopadding centpercent"><tr><td>';
2334 print $langs->trans(
'DateDeliveryPlanned');
2336 if ($action !=
'editdate_livraison') {
2337 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>';
2339 print
'</tr></table>';
2341 if ($action ==
'editdate_livraison') {
2342 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2343 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2344 print
'<input type="hidden" name="action" value="setdate_livraison">';
2349 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin, 0,
"setdate_livraison");
2350 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2353 $usehourmin =
'day';
2355 $usehourmin =
'dayhour';
2358 if (
$object->hasDelay() && !empty(
$object->delivery_date) && (
$object->status == $object::STATUS_ORDERSENT ||
$object->status == $object::STATUS_RECEIVED_PARTIALLY)) {
2359 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2365 if (isModEnabled(
'incoterm')) {
2367 print
'<table class="nobordernopadding centpercent"><tr><td>';
2368 print $langs->trans(
'IncotermLabel');
2369 print
'<td><td class="right">';
2370 if ($usercancreate) {
2371 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2375 print
'</td></tr></table>';
2378 if ($action !=
'editincoterm') {
2381 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2387 if (isModEnabled(
'category')) {
2389 print
'<table class="nobordernopadding centpercent"><tr><td>';
2390 print $langs->trans(
"Categories");
2391 print
'<td><td class="right">';
2392 if ($usercancreate) {
2393 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.
img_edit().
'</a>';
2397 print
'</td></tr></table>';
2400 if ($action ==
'edittags') {
2401 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2402 print
'<input type="hidden" name="action" value="settags">';
2403 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2404 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories',
$object);
2405 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
2408 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_ORDER, 1);
2414 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2419 print
'<div class="fichehalfright">';
2420 print
'<div class="underbanner clearboth"></div>';
2422 print
'<table class="border tableforfield centpercent">';
2424 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2428 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2429 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2430 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2432 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2438 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2439 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2440 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2442 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2447 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2449 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2450 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2451 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2452 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2456 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2458 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2459 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2460 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2461 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2469 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->supplier_order_min_amount));
2474 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2475 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) . $alert .
'</td>';
2476 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2478 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2493 print
'<div class="clearboth"></div><br>';
2496 $blocname =
'contacts';
2497 $title = $langs->trans(
'ContactsAddresses');
2498 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2502 $blocname =
'notes';
2503 $title = $langs->trans(
'Notes');
2504 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2513 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2514 <input type="hidden" name="token" value="'.
newToken().
'">
2515 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2516 <input type="hidden" name="mode" value="">
2517 <input type="hidden" name="page_y" value="">
2518 <input type="hidden" name="id" value="'.
$object->id.
'">
2519 <input type="hidden" name="socid" value="'.$societe->id.
'">
2522 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
2523 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2526 print
'<div class="div-table-responsive-no-min">';
2527 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2530 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2533 $inputalsopricewithtax = 1;
2534 $senderissupplier = 2;
2536 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY');
2541 $object->printObjectLines($action,
$object->thirdparty, $mysoc, $lineid, 1);
2548 if ($action !=
'editline') {
2551 $parameters = array();
2552 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2556 if (empty($reshook)) {
2557 $object->formAddObjectLine(1, $societe, $mysoc);
2572 if ($user->socid == 0 && $action !=
'delete') {
2573 if ($action !=
'createorder' && $action !=
'presend' && $action !=
'editline') {
2574 print
'<div class="tabsAction">';
2576 $parameters = array();
2577 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2579 if (empty($reshook)) {
2583 if (
$object->status == 0 && $num > 0) {
2584 if ($usercanvalidate) {
2585 $tmpbuttonlabel = $langs->trans(
'Validate');
2587 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2590 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'">';
2591 print $tmpbuttonlabel;
2603 if ($usercanorder) {
2604 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2610 if ($usercanapprove) {
2612 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2614 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2617 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2624 if ($usercanapprovesecond) {
2625 if (!empty(
$object->user_approve_id2)) {
2626 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2628 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2631 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2638 if ($usercanapprove || $usercanapprovesecond) {
2639 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2641 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2646 if (empty($user->socid)) {
2648 if ($usercanorder) {
2649 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2657 if (!$buttonshown && $usercanapprove) {
2660 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2664 if (!$buttonshown && $usercanapprovesecond &&
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
2667 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2671 if (in_array(
$object->status, array(3, 4, 5, 6, 7, 9))) {
2672 if ($usercanorder) {
2673 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2680 $labelofbutton = $langs->trans(
'ReceiveProducts');
2681 if (isModEnabled(
'reception')) {
2682 $labelofbutton = $langs->trans(
"CreateReception");
2683 if (!empty(
$object->linkedObjects[
'reception'])) {
2684 foreach (
$object->linkedObjects[
'reception'] as $element) {
2685 if ($element->statut >= 0) {
2698 $dispachedLines =
$object->getDispachedLines(1);
2699 $nbDispachedLines = count($dispachedLines);
2700 if ($nbDispachedLines > 0) {
2705 if (in_array(
$object->status, array(3, 4, 5))) {
2706 if (isModEnabled(
"supplier_order") && $usercanreceive) {
2707 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.
$object->id.
'">'.$labelofbutton.
'</a></div>';
2709 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2715 if ($usercanorder) {
2716 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>';
2718 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2724 if ($usercanreceive) {
2725 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>';
2732 if (isModEnabled(
"supplier_invoice") && (
$object->status >= 2 &&
$object->status != 7 &&
$object->billed != 1)) {
2733 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
2734 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>';
2741 if (!isModEnabled(
'invoice')) {
2742 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2744 if (!empty(
$object->linkedObjectsIds[
'invoice_supplier']) || (empty(
$object->linkedObjectsIds[
'invoice_supplier']) && !
getDolGlobalInt(
'SUPPLIER_ORDER_DISABLE_CLASSIFY_BILLED_FROM_SUPPLIER_ORDER'))) {
2745 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
2746 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2749 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2755 if ($usercancreate &&
$object->billed > 0 &&
$object->status > $object::STATUS_DRAFT) {
2756 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifyunbilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyUnbilled").
'</a>';
2760 if ($usercancreate) {
2761 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&socid='.
$object->socid.
'&action=clone&token='.
newToken().
'&object=order">'.$langs->trans(
"ToClone").
'</a>';
2766 if ($usercanorder) {
2767 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
2772 if (!empty($usercandelete)) {
2773 if ($hasreception) {
2774 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
2776 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2786 print
'<!-- form to record supplier order -->'.
"\n";
2787 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2789 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2790 print
'<input type="hidden" name="action" value="commande">';
2792 print
'<table class="noborder centpercent">';
2794 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2796 print $form->selectDate($date_com ?:
'',
'', 0, 0, 0,
"commande", 1, 1);
2800 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2801 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2804 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2806 print
'<tr><td class="center" colspan="2">';
2807 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2808 print
' ';
2809 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2818 if (
GETPOST(
'modelselected')) {
2819 $action =
'presend';
2822 if ($action !=
'createorder' && $action !=
'presend') {
2823 print
'<div class="fichecenter"><div class="fichehalfleft">';
2827 $file =
$conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2828 $relativepath = $objref.
'/'.$objref.
'.pdf';
2829 $filedir =
$conf->fournisseur->dir_output.
'/commande/'.$objref;
2830 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2831 $genallowed = $usercanread;
2832 $delallowed = $usercancreate;
2835 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, (
int) $genallowed, (int) $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'',
$object->thirdparty->default_lang,
'',
$object);
2836 $somethingshown = $formfile->numoffiles;
2839 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'supplier_order',
'order_supplier'), 1);
2840 $linktoelem = $tmparray[
'linktoelem'];
2841 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
2842 print $htmltoenteralink;
2844 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
2846 print
'</div><div class="fichehalfright">';
2848 if ($action ==
'classifyreception') {
2851 print
'<!-- form to record purchase order received -->'.
"\n";
2852 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2853 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2854 print
'<input type="hidden" name="action" value="livraison">';
2857 print
'<table class="noborder centpercent">';
2859 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2861 print $form->selectDate($datepreselected,
'', 1, 1, 0,
"commande", 1, 1);
2862 print
"</td></tr>\n";
2864 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2866 $liv[
''] =
' ';
2867 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2868 $liv[
'par'] = $langs->trans(
"PartialWoman");
2869 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2870 $liv[
'can'] = $langs->trans(
"Canceled");
2872 print $form->selectarray(
"type", $liv);
2875 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
2876 print
'<tr><td class="center" colspan="2">';
2877 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
2878 print
' ';
2879 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2888 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2890 $somethingshown = $formactions->showactions(
$object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2892 print
'</div></div>';
2898 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
2899 $mode =
GETPOST(
'mode',
'alpha');
2900 $ws_url =
$object->thirdparty->webservices_url;
2901 $ws_key =
$object->thirdparty->webservices_key;
2902 $ws_user =
GETPOST(
'ws_user',
'alpha');
2903 $ws_password =
GETPOST(
'ws_password',
'alpha');
2904 $error_occurred =
false;
2907 $ws_ns =
'http://www.dolibarr.org/ns/';
2908 $ws_authentication = array(
2909 'dolibarrkey' => $ws_key,
2910 'sourceapplication' =>
'DolibarrWebServiceClient',
2911 'login' => $ws_user,
2912 'password' => $ws_password,
2919 if (empty($ws_url) || empty($ws_key)) {
2920 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
2922 $error_occurred =
true;
2923 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2928 if ($mode ==
"init") {
2930 print
'<table class="border centpercent">';
2931 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2932 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2933 print
'<input type="hidden" name="action" value="webservice">';
2934 print
'<input type="hidden" name="mode" value="check">';
2936 if ($error_occurred) {
2937 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2938 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2941 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2943 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input class="width100" type="text" name="ws_user"></td></tr>';
2945 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input class="width100" type="text" name="ws_password"></td></tr>';
2947 print
'<tr><td class="center" colspan="2">';
2948 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2949 print
' ';
2951 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2958 } elseif ($mode ==
"check") {
2960 $ws_thirdparty =
'';
2961 $error_occurred =
false;
2964 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2965 $soapclient_user->soap_defencoding =
'UTF-8';
2966 $soapclient_user->decodeUTF8(
false);
2969 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ws_user);
2970 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2971 $user_status_code = $result_user[
"result"][
"result_code"];
2973 if ($user_status_code ==
"OK") {
2975 $ws_entity = $result_user[
"user"][
"entity"];
2976 $ws_authentication[
'entity'] = $ws_entity;
2977 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2978 if (empty($ws_thirdparty)) {
2979 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"),
null,
'errors');
2980 $error_occurred =
true;
2983 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2984 $soapclient_product->soap_defencoding =
'UTF-8';
2985 $soapclient_product->decodeUTF8(
false);
2989 foreach (
$object->lines as $line) {
2991 $ref_supplier = $line->ref_supplier;
2992 $line_id = $i.
"º) ".$line->product_ref.
": ";
2993 if (empty($ref_supplier)) {
2996 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2997 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2998 if (!$result_product) {
2999 setEventMessages($line_id.$langs->trans(
"Error").
" SOAP ".$soapclient_product->error_str.
" - ".$soapclient_product->response,
null,
'errors');
3000 $error_occurred =
true;
3005 $status_code = $result_product[
"result"][
"result_code"];
3006 if (empty($status_code)) {
3007 setEventMessages($langs->trans(
"Error").
" SOAP '".$soapclient_product->error_str.
"'",
null,
'errors');
3008 } elseif ($status_code !=
"OK") {
3009 if ($status_code ==
"NOT_FOUND") {
3010 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'",
null,
'warnings');
3012 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'",
null,
'errors');
3013 $error_occurred =
true;
3020 $supplier_price =
price($result_product[
"product"][
"price_net"]);
3021 $local_price =
null;
3024 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
3025 if (count($product_fourn_list) > 0) {
3026 foreach ($product_fourn_list as $product_fourn_line) {
3028 if ($product_fourn_line->fourn_id ==
$object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
3029 $local_price =
price($product_fourn_line->fourn_price);
3034 if ($local_price !=
null && $local_price != $supplier_price) {
3035 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price,
null,
'warnings');
3039 if (empty($result_product[
"product"][
"status_tosell"])) {
3040 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'",
null,
'warnings');
3044 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
3045 setEventMessages($langs->trans(
"RemoteUserNotPermission"),
null,
'errors');
3046 $error_occurred =
true;
3047 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
3048 setEventMessages($langs->trans(
"RemoteUserBadCredentials"),
null,
'errors');
3049 $error_occurred =
true;
3051 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'",
null,
'errors');
3052 $error_occurred =
true;
3056 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
3057 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3058 print
'<input type="hidden" name="action" value="webservice">';
3059 print
'<input type="hidden" name="mode" value="send">';
3060 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
3061 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
3062 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
3063 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
3064 if ($error_occurred) {
3065 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
3067 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
3068 print
' ';
3070 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
3076 $modelmail =
'order_supplier_send';
3077 $defaulttopic =
'SendOrderRef';
3078 $diroutput =
$conf->fournisseur->commande->dir_output;
3079 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
3080 $trackid =
'sord'.$object->id;
3082 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
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.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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, 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.