41require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
49require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
52if (isModEnabled(
'supplier_proposal')) {
53 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
55if (isModEnabled(
"product")) {
56 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
58if (isModEnabled(
'project')) {
59 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
62require_once NUSOAP_PATH.
'/nusoap.php';
64if (isModEnabled(
'variants')) {
65 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
70$langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
71if (isModEnabled(
'incoterm')) {
72 $langs->load(
'incoterm');
79$action =
GETPOST(
'action',
'alpha');
80$confirm =
GETPOST(
'confirm',
'alpha');
81$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
82$backtopage =
GETPOST(
'backtopage',
'alpha');
83$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
87$cancel =
GETPOST(
'cancel',
'alpha');
89$origin =
GETPOST(
'origin',
'alpha');
102if (!empty($user->socid)) {
103 $socid = $user->socid;
107$hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
113$extrafields->fetch_name_optionals_label(
$object->table_element);
116 $socid = $user->socid;
120if ($id > 0 || !empty($ref)) {
121 $ret =
$object->fetch($id, $ref);
125 $ret =
$object->fetch_thirdparty();
129} elseif (!empty($socid) && $socid > 0) {
131 $ret =
$object->fetch_thirdparty();
138$isdraft = (isset(
$object->statut) && (
$object->statut == $object::STATUS_DRAFT) ? 1 : 0);
139$result =
restrictedArea($user,
'fournisseur',
$object,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
142$usercanread = ($user->hasRight(
"fournisseur",
"commande",
"lire") || $user->hasRight(
"supplier_order",
"lire"));
143$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
144$usercandelete = (($user->hasRight(
"fournisseur",
"commande",
"supprimer") || $user->hasRight(
"supplier_order",
"supprimer")) || ($usercancreate && isset(
$object->statut) &&
$object->statut == $object::STATUS_DRAFT));
147$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate")));
150$usercanapprove = $user->hasRight(
"fournisseur",
"commande",
"approuver");
151$usercanapprovesecond = $user->hasRight(
"fournisseur",
"commande",
"approve2");
152$usercanorder = $user->hasRight(
"fournisseur",
"commande",
"commander");
153if (!isModEnabled(
'reception')) {
154 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
156 $usercanreceive = $user->hasRight(
"reception",
"creer");
160$permissionnote = $usercancreate;
161$permissiondellink = $usercancreate;
162$permissiontoedit = $usercancreate;
163$permissiontoadd = $usercancreate;
166$caneditproject =
false;
167if (isModEnabled(
'project')) {
178$parameters = array(
'socid' => $socid);
179$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
184if (empty($reshook)) {
185 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
187 if (empty($backtopage) || ($cancel && empty($id))) {
188 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
189 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
190 $backtopage = $backurlforlist;
192 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
198 if (!empty($backtopageforcancel)) {
199 header(
"Location: ".$backtopageforcancel);
201 } elseif (!empty($backtopage)) {
202 header(
"Location: ".$backtopage);
208 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
210 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
212 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
214 if ($action ==
'setref_supplier' && $usercancreate) {
215 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
222 if ($action ==
'set_incoterms' && $usercancreate) {
230 if ($action ==
'setconditions' && $usercancreate) {
238 if ($action ==
'setmode' && $usercancreate) {
243 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
245 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
246 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
252 if ($action ==
'setbankaccount' && $usercancreate) {
260 if ($action ==
'setdate_livraison' && $usercancreate) {
261 $result =
$object->setDeliveryDate($user, $datelivraison);
268 if ($action ==
'classin' && $usercancreate && $caneditproject) {
269 $result =
$object->setProject($projectid);
278 if (!empty($new_socid) && $new_socid !=
$object->thirdparty->id) {
282 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
283 $sql .=
' SET fk_soc = '.((int) $new_socid);
284 $sql .=
' WHERE fk_soc = '.((int)
$object->thirdparty->id);
285 $sql .=
' AND rowid = '.((int)
$object->id);
287 $res = $db->query($sql);
295 foreach (
$object->lines as $l) {
296 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
297 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
298 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
299 $sql .=
' AND fk_soc = '.((int) $new_socid);
300 $sql .=
' ORDER BY unitprice ASC';
302 $resql = $db->query($sql);
304 $num_row = $db->num_rows($resql);
305 if (empty($num_row)) {
311 $l->ref_supplier =
'';
315 $obj = $db->fetch_object($resql);
316 $l->subprice = $obj->unitprice;
317 $l->total_ht = $obj->price;
318 $l->tva_tx = $obj->tva_tx;
319 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
320 $l->total_ttc = $l->total_ht + $l->total_tva;
321 $l->ref_supplier = $obj->ref_fourn;
332 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
336 if ($action ==
'setremisepercent' && $usercancreate) {
343 if ($action ==
'reopen') {
344 if (in_array(
$object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) {
347 } elseif (
$object->statut == 2) {
349 } elseif (
$object->statut == 3) {
351 } elseif (
$object->statut == 4) {
353 } elseif (
$object->statut == 5) {
359 } elseif (
$object->statut == 6) {
361 } elseif (
$object->statut == 7) {
363 } elseif (
$object->statut == 9) {
372 $result =
$object->setStatus($user, $newstatus);
375 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
376 $sql .=
' SET billed = 0';
377 $sql .=
' WHERE rowid = '.((int)
$object->id);
379 $resql = $db->query($sql);
381 if ($newstatus == 0) {
382 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
383 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
384 $sql .=
' WHERE rowid = '.((int)
$object->id);
386 $resql = $db->query($sql);
391 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
404 if ($action ==
'classifybilled' && $usercancreate) {
405 $ret =
$object->classifyBilled($user);
412 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
416 foreach (
$object->lines as $line) {
417 if ($line->product_type == 1) {
418 $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);
421 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
423 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
424 $vat_rate = str_replace(
'*',
'', $vat_rate);
427 foreach (
$object->lines as $line) {
428 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $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);
430 } elseif ($action ==
'addline' && $usercancreate) {
433 $langs->load(
'errors');
438 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
442 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
443 if ($prod_entry_mode ==
'free') {
457 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
458 if (empty($remise_percent)) {
463 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
464 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
466 if (is_array($extralabelsline)) {
468 foreach ($extralabelsline as $key => $value) {
469 unset($_POST[
"options_".$key]);
473 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
474 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
477 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
478 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
481 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
482 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
485 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
486 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
489 if (
GETPOST(
'qty',
'alpha') ==
'') {
490 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
494 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
495 if ($combinations =
GETPOST(
'combinations',
'array')) {
499 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
500 $idprod = $res->fk_product_child;
502 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
508 if ($prod_entry_mode !=
'free' && empty($error)) {
512 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
517 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
519 $res = $productsupplier->fetch($idprod);
522 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
524 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
525 if ($productsupplier->fourn_socid != $socid) {
526 $productsupplier->ref_supplier =
'';
529 $fksoctosearch =
$object->thirdparty->id;
530 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
532 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
535 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
536 $res = $productsupplier->fetch($idprod);
540 $label = $productsupplier->label;
544 $outputlangs = $langs;
546 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
547 $newlang =
GETPOST(
'lang_id',
'aZ09');
549 if (empty($newlang)) {
550 $newlang =
$object->thirdparty->default_lang;
552 if (!empty($newlang)) {
554 $outputlangs->setDefaultLang($newlang);
556 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
558 $desc = $productsupplier->description;
561 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
562 $desc = $productsupplier->desc_supplier;
566 if (trim($product_desc) == trim($desc) &&
getDolGlobalString(
'PRODUIT_AUTOFILL_DESC')) {
571 $desc = $product_desc;
573 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
577 $ref_supplier = $productsupplier->ref_supplier;
581 if (!GETPOSTISSET(
'tva_tx')) {
584 if (empty($tva_tx)) {
592 $type = $productsupplier->type;
593 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
594 $price_base_type =
'HT';
596 $pu_devise =
price2num($price_ht_devise,
'CU');
597 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
598 $price_base_type =
'TTC';
600 $pu_devise =
price2num($price_ttc_devise,
'CU');
602 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
603 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
604 $pu = $productsupplier->fourn_pu;
607 $pu = $productsupplier->fourn_pu;
608 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
618 ($price_base_type ==
'HT' ? $pu : 0),
624 $productsupplier->product_fourn_price_id,
628 ($price_base_type ==
'TTC' ? $pu : 0),
635 $productsupplier->fk_unit,
639 min($rank, count(
$object->lines) + 1)
642 if ($idprod == -99 || $idprod == 0) {
645 $langs->load(
"errors");
646 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
651 $langs->load(
"errors");
652 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
654 } elseif (empty($error)) {
655 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
656 $tva_tx = str_replace(
'*',
'', $tva_tx);
657 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
658 $desc = $product_desc;
660 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
662 $fk_unit =
GETPOST(
'units',
'alpha');
664 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
672 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
676 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
678 $price_base_type =
'HT';
679 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
681 $result =
$object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type,
'',
'', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
685 if (!$error && $result > 0) {
692 $outputlangs = $langs;
695 $newlang =
$object->thirdparty->default_lang;
696 if (
GETPOST(
'lang_id',
'aZ09')) {
697 $newlang =
GETPOST(
'lang_id',
'aZ09');
700 if (!empty($newlang)) {
702 $outputlangs->setDefaultLang($newlang);
707 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
713 unset($_POST [
'prod_entry_mode']);
715 unset($_POST[
'qty']);
716 unset($_POST[
'type']);
717 unset($_POST[
'remise_percent']);
719 unset($_POST[
'price_ht']);
720 unset($_POST[
'multicurrency_price_ht']);
721 unset($_POST[
'price_ttc']);
722 unset($_POST[
'fourn_ref']);
723 unset($_POST[
'tva_tx']);
724 unset($_POST[
'label']);
725 unset($localtax1_tx);
726 unset($localtax2_tx);
727 unset($_POST[
'np_marginRate']);
728 unset($_POST[
'np_markRate']);
729 unset($_POST[
'dp_desc']);
730 unset($_POST[
'idprodfournprice']);
731 unset($_POST[
'units']);
733 unset($_POST[
'date_starthour']);
734 unset($_POST[
'date_startmin']);
735 unset($_POST[
'date_startsec']);
736 unset($_POST[
'date_startday']);
737 unset($_POST[
'date_startmonth']);
738 unset($_POST[
'date_startyear']);
739 unset($_POST[
'date_endhour']);
740 unset($_POST[
'date_endmin']);
741 unset($_POST[
'date_endsec']);
742 unset($_POST[
'date_endday']);
743 unset($_POST[
'date_endmonth']);
744 unset($_POST[
'date_endyear']);
756 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
763 $res = $line->fetch($lineid);
771 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0,
price2num(
GETPOSTINT(
'qty')), $line->fk_product,
'none',
GETPOSTINT(
'socid')) < 0) {
772 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
781 if (preg_match(
'/\*/', $vat_rate)) {
786 $vat_rate = str_replace(
'*',
'', $vat_rate);
790 if (
GETPOST(
'price_ht') !=
'') {
791 $price_base_type =
'HT';
795 $vatratecleaned = $vat_rate;
796 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
797 $vatratecleaned = trim($reg[1]);
798 $vatratecode = $reg[2];
802 $ht = (float) $ttc / (1 + ($vatratecleaned / 100));
803 $price_base_type =
'HT';
809 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
810 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
812 if (is_array($extralabelsline)) {
813 foreach ($extralabelsline as $key => $value) {
814 unset($_POST[
"options_".$key]);
820 GETPOST(
'product_desc',
'restricthtml'),
829 GETPOSTISSET(
"type") ?
GETPOST(
"type") : $line->product_type,
838 unset($_POST[
'qty']);
839 unset($_POST[
'type']);
840 unset($_POST[
'idprodfournprice']);
841 unset($_POST[
'remmise_percent']);
842 unset($_POST[
'dp_desc']);
843 unset($_POST[
'np_desc']);
845 unset($_POST[
'fourn_ref']);
846 unset($_POST[
'tva_tx']);
847 unset($_POST[
'date_start']);
848 unset($_POST[
'date_end']);
849 unset($_POST[
'units']);
850 unset($localtax1_tx);
851 unset($localtax2_tx);
853 unset($_POST[
'date_starthour']);
854 unset($_POST[
'date_startmin']);
855 unset($_POST[
'date_startsec']);
856 unset($_POST[
'date_startday']);
857 unset($_POST[
'date_startmonth']);
858 unset($_POST[
'date_startyear']);
859 unset($_POST[
'date_endhour']);
860 unset($_POST[
'date_endmin']);
861 unset($_POST[
'date_endsec']);
862 unset($_POST[
'date_endday']);
863 unset($_POST[
'date_endmonth']);
864 unset($_POST[
'date_endyear']);
869 $outputlangs = $langs;
872 $newlang =
GETPOST(
'lang_id',
'aZ09');
875 $newlang =
$object->thirdparty->default_lang;
877 if (!empty($newlang)) {
879 $outputlangs->setDefaultLang($newlang);
884 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
899 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
902 $result =
$object->deleteLine($lineid);
907 $outputlangs = $langs;
910 $newlang =
GETPOST(
'lang_id',
'aZ09');
913 $newlang =
$object->thirdparty->default_lang;
915 if (!empty($newlang)) {
917 $outputlangs->setDefaultLang($newlang);
921 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
943 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
951 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
955 $result =
$object->valid($user);
959 $outputlangs = $langs;
962 $newlang =
GETPOST(
'lang_id',
'aZ09');
965 $newlang =
$object->thirdparty->default_lang;
967 if (!empty($newlang)) {
969 $outputlangs->setDefaultLang($newlang);
974 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
987 $action =
'confirm_approve';
997 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
1002 $qualified_for_stock_change = 0;
1004 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1006 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1010 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') && $qualified_for_stock_change) {
1011 if (!$idwarehouse || $idwarehouse == -1) {
1013 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1019 $result =
$object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1022 $outputlangs = $langs;
1025 $newlang =
GETPOST(
'lang_id',
'aZ09');
1028 $newlang =
$object->thirdparty->default_lang;
1030 if (!empty($newlang)) {
1031 $outputlangs =
new Translate(
"", $conf);
1032 $outputlangs->setDefaultLang($newlang);
1034 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1045 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1052 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1056 $result =
$object->refuse($user);
1058 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1066 if ($action ==
'commande') {
1067 $methodecommande =
GETPOSTINT(
'methodecommande');
1071 } elseif ($methodecommande <= 0 && !
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL')) {
1072 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1073 $action =
'createorder';
1077 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1083 $outputlangs = $langs;
1086 $newlang =
GETPOST(
'lang_id',
'aZ09');
1089 $newlang =
$object->thirdparty->default_lang;
1091 if (!empty($newlang)) {
1092 $outputlangs =
new Translate(
"", $conf);
1093 $outputlangs->setDefaultLang($newlang);
1095 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1106 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1114 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1115 $result =
$object->delete($user);
1117 header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
1125 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1126 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1127 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1132 $result =
$object->createFromClone($user, $socid);
1134 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1146 if ($action ==
'livraison' && $usercanreceive) {
1157 $langs->load(
"deliveries");
1167 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1178 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1182 $result =
$object->cancel($user);
1184 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1192 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1195 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1196 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1197 $trackid =
'sord'.$object->id;
1198 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1201 $upload_dir = $conf->fournisseur->commande->dir_output;
1202 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1205 if ($action ==
'update_extras' && $permissiontoadd) {
1209 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
1217 $result =
$object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
1226 $action =
'edit_extras';
1233 if ($action ==
'add' && $permissiontoadd) {
1235 $selectedLines =
GETPOST(
'toselect',
'array');
1237 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1253 $object->delivery_date = $datelivraison;
1255 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1256 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1262 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
1270 if (!empty($origin) && !empty($originid)) {
1271 $element = $subelement = $origin;
1272 $classname = ucfirst($subelement);
1273 if ($origin ==
'propal' || $origin ==
'proposal') {
1274 $element =
'comm/propal';
1275 $subelement =
'propal';
1276 $classname =
'Propal';
1278 if ($origin ==
'order' || $origin ==
'commande') {
1279 $element = $subelement =
'commande';
1280 $classname =
'Commande';
1282 if ($origin ==
'supplier_proposal') {
1283 $classname =
'SupplierProposal';
1284 $element =
'supplier_proposal';
1285 $subelement =
'supplier_proposal';
1289 $object->origin_id = $originid;
1293 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1294 if (!empty($other_linked_objects)) {
1295 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
1302 $srcobject =
new $classname($db);
1305 $result = $srcobject->fetch(
$object->origin_id);
1307 $tmpdate = $srcobject->delivery_date;
1308 $object->setDeliveryDate($user, $tmpdate);
1309 $object->set_id_projet($user, $srcobject->fk_project);
1311 $lines = $srcobject->lines;
1312 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1313 $srcobject->fetch_lines();
1314 $lines = $srcobject->lines;
1317 $fk_parent_line = 0;
1318 $num = count($lines);
1320 for ($i = 0; $i < $num; $i++) {
1321 if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines)) {
1325 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1326 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1327 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1330 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1331 $fk_parent_line = 0;
1335 if (method_exists($lines[$i],
'fetch_optionals')) {
1336 $lines[$i]->fetch_optionals();
1337 $array_option = $lines[$i]->array_options;
1341 $product_fourn_price_id = 0;
1342 if ($origin ==
"commande") {
1344 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty,
$object->socid);
1345 $lines[$i]->subprice = 0;
1347 $ref_supplier = $productsupplier->ref_supplier;
1348 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1350 foreach ($srcobject->lines as $li) {
1351 $sql =
'SELECT price, unitprice, tva_tx, remise_percent, entity, ref_fourn';
1352 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
1353 $sql .=
' WHERE fk_product = '.((int) $li->fk_product);
1354 $sql .=
' AND entity IN ('.getEntity(
'product_fournisseur_price').
')';
1355 $sql .=
' AND fk_soc = '.((int)
$object->socid);
1356 $sql .=
' ORDER BY unitprice ASC';
1358 $resql = $db->query($sql);
1360 $num_row = $db->num_rows($resql);
1361 if (empty($num_row)) {
1362 $li->remise_percent = 0;
1364 $obj = $db->fetch_object($resql);
1365 $li->subprice = $obj->unitprice;
1366 $li->remise_percent = $obj->remise_percent;
1375 $ref_supplier = $lines[$i]->ref_fourn;
1376 $product_fourn_price_id = 0;
1379 $tva_tx = $lines[$i]->tva_tx;
1381 if ($origin ==
"commande") {
1383 $soc->fetch($socid);
1384 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1389 $lines[$i]->subprice,
1392 $lines[$i]->localtax1_tx,
1393 $lines[$i]->localtax2_tx,
1394 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1395 $product_fourn_price_id,
1397 $lines[$i]->remise_percent,
1400 $lines[$i]->product_type,
1406 $lines[$i]->fk_unit,
1409 !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->
rowid,
1411 $lines[$i]->special_code
1421 if ($result > 0 && $lines[$i]->product_type == 9) {
1422 $fk_parent_line = $result;
1430 $parameters = array(
'objFrom' => $srcobject);
1431 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1455 $langs->load(
"errors");
1460 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode((
string) ($id)));
1466 if ($action ==
'webservice' && $permissiontoadd &&
GETPOST(
'mode',
'alpha') ==
"send" && !
GETPOST(
'cancel',
'alpha')) {
1467 $ws_url =
$object->thirdparty->webservices_url;
1468 $ws_key =
$object->thirdparty->webservices_key;
1469 $ws_user =
GETPOST(
'ws_user',
'alpha');
1470 $ws_password =
GETPOST(
'ws_password',
'alpha');
1472 $ws_thirdparty =
GETPOSTINT(
'ws_thirdparty');
1475 $ws_ns =
'http://www.dolibarr.org/ns/';
1476 $ws_authentication = array(
1477 'dolibarrkey' => $ws_key,
1478 'sourceapplication' =>
'DolibarrWebServiceClient',
1479 'login' => $ws_user,
1480 'password' => $ws_password,
1481 'entity' => $ws_entity
1485 if (isModEnabled(
'webservicesclient')) {
1486 setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2660Name")),
null,
'mesgs');
1487 } elseif (empty($ws_url) || empty($ws_key)) {
1488 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
1489 } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1493 $soapclient_order =
new nusoap_client($ws_url.
"/webservices/server_order.php");
1494 $soapclient_order->soap_defencoding =
'UTF-8';
1495 $soapclient_order->decodeUTF8(
false);
1498 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
1499 $soapclient_product->soap_defencoding =
'UTF-8';
1500 $soapclient_product->decodeUTF8(
false);
1503 $order_lines = array();
1504 foreach (
$object->lines as $line) {
1505 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $line->ref_supplier);
1506 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
1508 if ($result_product[
"result"][
"result_code"] ==
"OK") {
1509 $order_lines[] = array(
1510 'desc' => $line->product_desc,
1511 'type' => $line->product_type,
1512 'product_id' => $result_product[
"product"][
"id"],
1513 'vat_rate' => $line->tva_tx,
1514 'qty' => $line->qty,
1515 'price' => $line->price,
1516 'unitprice' => $line->subprice,
1517 'total_net' => $line->total_ht,
1518 'total_vat' => $line->total_tva,
1519 'total' => $line->total_ttc,
1520 'date_start' => $line->date_start,
1521 'date_end' => $line->date_end,
1528 'thirdparty_id' => $ws_thirdparty,
1530 'total_net' =>
$object->total_ht,
1531 'total_var' =>
$object->total_tva,
1532 'total' =>
$object->total_ttc,
1533 'lines' => $order_lines
1536 $ws_parameters = array(
'authentication' => $ws_authentication,
'order' => $order);
1537 $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns,
'');
1539 if (empty($result_order[
"result"][
"result_code"])) {
1540 setEventMessages($langs->trans(
"Error").
" '".$soapclient_order->error_str.
"'",
null,
'errors');
1541 } elseif ($result_order[
"result"][
"result_code"] !=
"OK") {
1542 setEventMessages($langs->trans(
"Error").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'",
null,
'errors');
1544 setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"],
null,
'mesgs');
1550 if ($action ==
'addcontact') {
1554 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1558 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1561 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1562 $langs->load(
"errors");
1563 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1568 } elseif ($action ==
'swapstatut' &&
$object->id > 0) {
1571 } elseif ($action ==
'deletecontact' &&
$object->id > 0) {
1576 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1590$form =
new Form($db);
1593$productstatic =
new Product($db);
1594if (isModEnabled(
'project')) {
1598$title =
$object->ref.
" - ".$langs->trans(
'Card');
1599if ($action ==
'create') {
1600 $title = $langs->trans(
"NewOrderSupplier");
1602$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1603llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-supplier-order page-card');
1607if ($action ==
'create') {
1608 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1612 $currency_code = $conf->currency;
1617 $societe->fetch($socid);
1620 if (!empty($origin) && !empty($originid)) {
1622 $element = $subelement = $origin;
1623 $classname = ucfirst($subelement);
1625 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1626 $element = $regs[1];
1627 $subelement = $regs[2];
1630 if ($origin ==
'propal' || $origin ==
'proposal') {
1631 $classname =
'Propal';
1632 $element =
'comm/propal';
1633 $subelement =
'propal';
1635 if ($origin ==
'order' || $origin ==
'commande') {
1636 $classname =
'Commande';
1637 $element = $subelement =
'commande';
1639 if ($origin ==
'supplier_proposal') {
1640 $classname =
'SupplierProposal';
1641 $element =
'supplier_proposal';
1642 $subelement =
'supplier_proposal';
1648 $objectsrc =
new $classname($db);
1649 $objectsrc->fetch($originid);
1650 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1651 $objectsrc->fetch_lines();
1653 $objectsrc->fetch_thirdparty();
1656 $objectsrc->fetch_optionals();
1657 $object->array_options = $objectsrc->array_options;
1659 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1660 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1661 if ($origin ==
"commande") {
1662 $cond_reglement_id = 0;
1663 $mode_reglement_id = 0;
1664 $delivery_date =
'';
1665 $objectsrc->note_private =
'';
1666 $objectsrc->note_public =
'';
1667 if ($societe =
$object->thirdparty) {
1668 $cond_reglement_id = $societe->cond_reglement_supplier_id;
1669 $mode_reglement_id = $societe->mode_reglement_supplier_id;
1670 if (isModEnabled(
"multicurrency")) {
1671 $currency_code = $societe->multicurrency_code;
1673 $currency_tx = $societe->multicurrency_tx;
1678 $soc = $objectsrc->thirdparty;
1680 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1681 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1682 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1683 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1684 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1685 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1690 $datedelivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1692 if (isModEnabled(
"multicurrency")) {
1693 if (!empty($objectsrc->multicurrency_code)) {
1694 $currency_code = $objectsrc->multicurrency_code;
1696 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1697 $currency_tx = $objectsrc->multicurrency_tx;
1701 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1702 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1705 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1708 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1709 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1711 if (isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1712 $currency_code = $societe->multicurrency_code;
1715 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1716 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1720 if (empty($cond_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID')) {
1723 if (empty($mode_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID')) {
1727 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1728 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1729 print
'<input type="hidden" name="action" value="add">';
1730 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1731 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1732 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1734 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1736 if ($backtopageforcancel) {
1737 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1740 if (!empty($currency_tx)) {
1741 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1747 $parameters = array();
1749 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierOrder', $parameters,
$object, $action);
1750 if (empty($reshook)) {
1751 print
'<table class="border centpercent">';
1754 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1757 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1760 if (!empty($societe->id) && $societe->id > 0) {
1761 print $societe->getNomUrl(1,
'supplier');
1762 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1764 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
1765 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company((empty($socid) ?
'' : $socid),
'socid', $filter,
'SelectThirdParty', 1, 0, null, 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1769 $(document).ready(function() {
1770 $("#socid").change(function() {
1771 console.log("We have changed the company - Reload page");
1773 $("input[name=action]").val("create");
1774 $("form[name=add]").submit();
1779 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>';
1783 if (!empty($societe->id) && $societe->id > 0) {
1785 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1787 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
1789 $thirdparty = $societe;
1791 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1792 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1798 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1802 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1803 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1804 print $form->getSelectConditionsPaiements((GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id') != 0) ?
GETPOST(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id', -1, 1);
1808 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1809 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1810 $form->select_types_paiements((GETPOSTISSET(
'mode_reglement_id') &&
GETPOSTINT(
'mode_reglement_id') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
1815 print $langs->trans(
'DateDeliveryPlanned');
1822 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1823 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin, 0,
"set");
1827 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER') && isModEnabled(
"bank")) {
1828 $langs->load(
"bank");
1829 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1830 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
1831 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
1836 if (isModEnabled(
'project')) {
1839 $langs->load(
'projects');
1840 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1841 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');
1842 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>';
1847 if (isModEnabled(
'incoterm')) {
1848 $fkincoterms = (!empty(
$object->fk_incoterms) ?
$object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1849 $locincoterms = (!empty(
$object->location_incoterms) ?
$object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1851 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"),
$object->label_incoterms, 1).
'</label></td>';
1852 print
'<td class="maxwidthonsmartphone">';
1853 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
1854 print $form->select_incoterms($fkincoterms, $locincoterms);
1859 if (isModEnabled(
"multicurrency")) {
1861 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0).
'</td>';
1862 print
'<td class="maxwidthonsmartphone">';
1863 print
img_picto(
'',
'currency',
'class="pictofixedwidth"');
1864 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
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', 0, 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', 0, 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 print
$object->showOptionals($extrafields,
'create');
1928 print $form->buttonsSaveCancel(
"CreateDraft");
1931 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1932 $title = $langs->trans(
'ProductsAndServices');
1935 print
'<div class="div-table-responsive-no-min">';
1936 print
'<table class="noborder centpercent">';
1938 $selectedLines = array();
1940 $objectsrc->printOriginLinesList(
'', $selectedLines);
1946} elseif (!empty(
$object->id)) {
1948 $result =
$object->fetch($id, $ref);
1951 $societe =
$object->thirdparty;
1953 $author =
new User($db);
1954 $author->fetch(
$object->user_author_id);
1958 $title = $langs->trans(
"SupplierOrder");
1965 if ($action ==
'delete') {
1966 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 2);
1970 if ($action ==
'clone') {
1971 $filter =
'(s.fournisseur:=:1)';
1973 $formquestion = array(
1974 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter))
1977 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1981 if ($action ==
'valid') {
1985 if (preg_match(
'/^[\(]?PROV/i',
$object->ref) || empty(
$object->ref)) {
1995 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
1996 if (isModEnabled(
'notification')) {
1997 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1998 $notify =
new Notify($db);
2000 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE',
$object->socid,
$object);
2003 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
2008 if ($action ==
'approve' || $action ==
'approve2') {
2009 $qualified_for_stock_change = 0;
2011 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2013 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2016 $formquestion = array();
2017 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') && $qualified_for_stock_change) {
2018 $langs->load(
"stocks");
2019 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2022 if ($conf->browser->name ==
'ie') {
2025 $formquestion = array(
2029 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2032 $text = $langs->trans(
"ConfirmApproveThisOrder",
$object->ref);
2033 if (isModEnabled(
'notification')) {
2034 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2035 $notify =
new Notify($db);
2037 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE',
$object->socid,
$object);
2040 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
2044 if ($action ==
'refuse') {
2045 $formquestion = array(
2048 'name' =>
'refuse_note',
2049 'label' => $langs->trans(
"Reason"),
2051 'morecss' =>
'minwidth300'
2054 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder",
$object->ref),
"confirm_refuse", $formquestion, 0, 1);
2058 if ($action ==
'cancel') {
2059 $formquestion = array(
2062 'name' =>
'cancel_note',
2063 'label' => $langs->trans(
"Reason"),
2065 'morecss' =>
'minwidth300'
2068 if (!empty($conf->notification->enabled)) {
2069 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2070 $notify =
new Notify($db);
2072 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_CANCEL',
$object->socid,
$object);
2074 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder",
$object->ref),
"confirm_cancel", $formquestion, 0, 1);
2078 if ($action ==
'commande') {
2080 if (!empty($conf->notification->enabled)) {
2081 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2082 $notify =
new Notify($db);
2084 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_SUBMIT',
$object->socid,
$object);
2086 $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",
'', 0, 2);
2090 if ($action ==
'ask_deleteline') {
2091 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2094 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2095 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
2096 if (empty($reshook)) {
2097 $formconfirm .= $hookmanager->resPrint;
2098 } elseif ($reshook > 0) {
2099 $formconfirm = $hookmanager->resPrint;
2108 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2110 $morehtmlref =
'<div class="refidno">';
2112 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, $usercancreate,
'string',
'', 0, 1);
2113 $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);
2115 $morehtmlref .=
'<br>';
2116 if (
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2117 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2118 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2119 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2120 $filter =
'(s.fournisseur:=:1)';
2121 $morehtmlref .= $form->select_company(
$object->thirdparty->id,
'new_socid', $filter,
'', 0, 0, array(), 0,
'minwidth300');
2122 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2123 $morehtmlref .=
'</form>';
2125 if (!
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') || $action !=
'edit_thirdparty') {
2127 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2129 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'supplier');
2131 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.
$object->thirdparty->id.
'&search_company='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2136 if (isModEnabled(
'project')) {
2137 $langs->load(
"projects");
2138 $morehtmlref .=
'<br>';
2139 if ($permissiontoadd) {
2140 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2141 if ($action !=
'classify' && $caneditproject) {
2142 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2144 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1),
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 1, 0, 0, 1,
'',
'maxwidth300');
2146 if (!empty(
$object->fk_project)) {
2148 $proj->fetch(
$object->fk_project);
2149 $morehtmlref .= $proj->getNomUrl(1);
2151 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2156 $morehtmlref .=
'</div>';
2159 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2162 $parameters = array();
2164 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierOrder', $parameters,
$object, $action);
2165 if (empty($reshook)) {
2166 print
'<div class="fichecenter">';
2167 print
'<div class="fichehalfleft">';
2168 print
'<div class="underbanner clearboth"></div>';
2170 print
'<table class="border tableforfield centpercent">';
2173 if (
$object->methode_commande_id > 0) {
2178 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2181 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2185 if (
$object->methode_commande) {
2186 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.
$object->getInputMethod().
'</td></tr>';
2191 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2192 print
'<td>'.$author->getNomUrl(-1,
'', 0, 0, 0).
'</td>';
2197 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2198 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2200 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2201 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2204 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2205 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2206 $absolute_discount =
price2num($absolute_discount,
'MT');
2207 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2209 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2211 $thirdparty = $societe;
2213 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
2214 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2219 $langs->load(
'bills');
2220 print
'<tr><td class="nowrap">';
2221 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2222 print $langs->trans(
'PaymentConditions');
2224 if ($action !=
'editconditions' && $permissiontoadd) {
2225 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>';
2227 print
'</tr></table>';
2229 if ($action ==
'editconditions') {
2230 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id');
2232 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'none');
2238 $langs->load(
'bills');
2239 print
'<tr><td class="nowrap">';
2240 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2241 print $langs->trans(
'PaymentMode');
2243 if ($action !=
'editmode' && $permissiontoadd) {
2244 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>';
2246 print
'</tr></table>';
2248 if ($action ==
'editmode') {
2249 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2251 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'none');
2256 if (isModEnabled(
"multicurrency")) {
2260 print
'<table class="nobordernopadding centpercent"><tr><td>';
2261 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'',
$object, 0);
2263 if ($action !=
'editmulticurrencycode' &&
$object->statut == $object::STATUS_DRAFT && $permissiontoadd) {
2264 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2266 print
'</tr></table>';
2268 if ($action ==
'editmulticurrencycode') {
2269 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code,
'multicurrency_code');
2271 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_code,
'none');
2276 if (
$object->multicurrency_code != $conf->currency ||
$object->multicurrency_tx != 1) {
2279 print
'<table class="nobordernopadding centpercent"><tr>';
2281 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'',
$object, 0);
2283 if ($action !=
'editmulticurrencyrate' &&
$object->statut == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
2284 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2286 print
'</tr></table>';
2288 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2289 if ($action ==
'actualizemulticurrencyrate') {
2292 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'multicurrency_tx',
$object->multicurrency_code);
2294 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->multicurrency_tx,
'none',
$object->multicurrency_code);
2295 if (
$object->statut == $object::STATUS_DRAFT &&
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency) {
2296 print
'<div class="inline-block"> ';
2297 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
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,
$object->fk_account,
'fk_account', 1);
2319 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$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->statut == $object::STATUS_ORDERSENT ||
$object->statut == $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 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2392 print
'<div class="fichehalfright">';
2393 print
'<div class="underbanner clearboth"></div>';
2395 print
'<table class="border tableforfield centpercent">';
2399 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2400 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2401 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2403 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2409 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2410 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2411 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2413 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2418 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2420 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2421 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2422 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2423 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2427 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2429 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2430 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2431 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2432 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2440 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->supplier_order_min_amount));
2445 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2446 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . $alert .
'</td>';
2447 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2449 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2464 print
'<div class="clearboth"></div><br>';
2467 $blocname =
'contacts';
2468 $title = $langs->trans(
'ContactsAddresses');
2469 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2473 $blocname =
'notes';
2474 $title = $langs->trans(
'Notes');
2475 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2484 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2485 <input type="hidden" name="token" value="'.
newToken().
'">
2486 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2487 <input type="hidden" name="mode" value="">
2488 <input type="hidden" name="page_y" value="">
2489 <input type="hidden" name="id" value="'.
$object->id.
'">
2490 <input type="hidden" name="socid" value="'.$societe->id.
'">
2493 if (!empty($conf->use_javascript_ajax) &&
$object->statut == 0) {
2494 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2497 print
'<div class="div-table-responsive-no-min">';
2498 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2501 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2504 $inputalsopricewithtax = 1;
2505 $senderissupplier = 2;
2507 $senderissupplier = 1;
2512 $object->printObjectLines($action,
$object->thirdparty, $mysoc, $lineid, 1);
2519 if ($action !=
'editline') {
2522 $parameters = array();
2523 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2527 if (empty($reshook)) {
2528 $object->formAddObjectLine(1, $societe, $mysoc);
2543 if ($user->socid == 0 && $action !=
'delete') {
2544 if ($action !=
'createorder' && $action !=
'presend' && $action !=
'editline') {
2545 print
'<div class="tabsAction">';
2547 $parameters = array();
2548 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2550 if (empty($reshook)) {
2554 if (
$object->statut == 0 && $num > 0) {
2555 if ($usercanvalidate) {
2556 $tmpbuttonlabel = $langs->trans(
'Validate');
2558 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2561 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'">';
2562 print $tmpbuttonlabel;
2574 if ($usercanorder) {
2575 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2581 if ($usercanapprove) {
2582 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') &&
$object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED && !empty(
$object->user_approve_id)) {
2583 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2585 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2588 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2593 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') &&
$object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
2595 if ($usercanapprovesecond) {
2596 if (!empty(
$object->user_approve_id2)) {
2597 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2599 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2602 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2609 if ($usercanapprove || $usercanapprovesecond) {
2610 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2612 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2617 if (empty($user->socid)) {
2619 if ($usercanorder) {
2620 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2628 if (!$buttonshown && $usercanapprove) {
2631 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2635 if (!$buttonshown && $usercanapprovesecond &&
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
2638 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2642 if (in_array(
$object->statut, array(3, 4, 5, 6, 7, 9))) {
2643 if ($usercanorder) {
2644 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2651 $labelofbutton = $langs->trans(
'ReceiveProducts');
2652 if (isModEnabled(
'reception')) {
2653 $labelofbutton = $langs->trans(
"CreateReception");
2654 if (!empty(
$object->linkedObjects[
'reception'])) {
2655 foreach (
$object->linkedObjects[
'reception'] as $element) {
2656 if ($element->statut >= 0) {
2664 if (in_array(
$object->statut, array(3, 4, 5))) {
2665 if (isModEnabled(
"supplier_order") && $usercanreceive) {
2666 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.
$object->id.
'">'.$labelofbutton.
'</a></div>';
2668 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2674 if ($usercanorder) {
2675 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>';
2677 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2683 if ($usercanreceive) {
2684 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>';
2691 if (isModEnabled(
"supplier_invoice") && (
$object->statut >= 2 &&
$object->statut != 7 &&
$object->billed != 1)) {
2692 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
2693 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>';
2700 if (!isModEnabled(
'invoice')) {
2701 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2703 if (!empty(
$object->linkedObjectsIds[
'invoice_supplier']) || (empty(
$object->linkedObjectsIds[
'invoice_supplier']) && !
getDolGlobalInt(
'SUPPLIER_ORDER_DISABLE_CLASSIFY_BILLED_FROM_SUPPLIER_ORDER'))) {
2704 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
2705 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2708 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2714 if (isModEnabled(
'webservicesclient') &&
$object->statut >= 2) {
2715 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=webservice&token='.
newToken().
'&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
2719 if ($usercancreate) {
2720 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&socid='.
$object->socid.
'&action=clone&token='.
newToken().
'&object=order">'.$langs->trans(
"ToClone").
'</a>';
2725 if ($usercanorder) {
2726 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
2731 if (!empty($usercandelete)) {
2732 if ($hasreception) {
2733 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
2735 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2745 print
'<!-- form to record supplier order -->'.
"\n";
2746 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2748 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2749 print
'<input type="hidden" name="action" value="commande">';
2751 print
'<table class="noborder centpercent">';
2753 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2755 print $form->selectDate($date_com ?:
'',
'', 0, 0, 0,
"commande", 1, 1);
2759 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2760 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2763 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2765 print
'<tr><td class="center" colspan="2">';
2766 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2767 print
' ';
2768 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2777 if (
GETPOST(
'modelselected')) {
2778 $action =
'presend';
2781 if ($action !=
'createorder' && $action !=
'presend') {
2782 print
'<div class="fichecenter"><div class="fichehalfleft">';
2786 $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2787 $relativepath = $objref.
'/'.$objref.
'.pdf';
2788 $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
2789 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2790 $genallowed = $usercanread;
2791 $delallowed = $usercancreate;
2792 $modelpdf = (!empty(
$object->model_pdf) ?
$object->model_pdf : (!
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF') ?
'' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
2794 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'',
$object->thirdparty->default_lang,
'',
$object);
2795 $somethingshown = $formfile->numoffiles;
2798 $linktoelem = $form->showLinkToObjectBlock(
$object,
null, array(
'supplier_order',
'order_supplier'));
2799 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
2801 print
'</div><div class="fichehalfright">';
2803 if ($action ==
'classifyreception') {
2806 print
'<!-- form to record purchase order received -->'.
"\n";
2807 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2808 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2809 print
'<input type="hidden" name="action" value="livraison">';
2812 print
'<table class="noborder centpercent">';
2814 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2816 print $form->selectDate($datepreselected,
'', 1, 1, 0,
"commande", 1, 1);
2817 print
"</td></tr>\n";
2819 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2821 $liv[
''] =
' ';
2822 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2823 $liv[
'par'] = $langs->trans(
"PartialWoman");
2824 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2825 $liv[
'can'] = $langs->trans(
"Canceled");
2827 print $form->selectarray(
"type", $liv);
2830 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
2831 print
'<tr><td class="center" colspan="2">';
2832 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
2833 print
' ';
2834 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2843 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2845 $somethingshown = $formactions->showactions(
$object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2847 print
'</div></div>';
2853 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
2854 $mode =
GETPOST(
'mode',
'alpha');
2855 $ws_url =
$object->thirdparty->webservices_url;
2856 $ws_key =
$object->thirdparty->webservices_key;
2857 $ws_user =
GETPOST(
'ws_user',
'alpha');
2858 $ws_password =
GETPOST(
'ws_password',
'alpha');
2861 $ws_ns =
'http://www.dolibarr.org/ns/';
2862 $ws_authentication = array(
2863 'dolibarrkey' => $ws_key,
2864 'sourceapplication' =>
'DolibarrWebServiceClient',
2865 'login' => $ws_user,
2866 'password' => $ws_password,
2873 if (empty($ws_url) || empty($ws_key)) {
2874 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
2876 $error_occurred =
true;
2877 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2882 if ($mode ==
"init") {
2884 print
'<table class="border centpercent">';
2885 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2886 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2887 print
'<input type="hidden" name="action" value="webservice">';
2888 print
'<input type="hidden" name="mode" value="check">';
2890 if ($error_occurred) {
2891 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2892 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2895 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2897 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input class="width100" type="text" name="ws_user"></td></tr>';
2899 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input class="width100" type="text" name="ws_password"></td></tr>';
2901 print
'<tr><td class="center" colspan="2">';
2902 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2903 print
' ';
2905 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2912 } elseif ($mode ==
"check") {
2914 $ws_thirdparty =
'';
2915 $error_occurred =
false;
2918 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2919 $soapclient_user->soap_defencoding =
'UTF-8';
2920 $soapclient_user->decodeUTF8(
false);
2923 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ws_user);
2924 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2925 $user_status_code = $result_user[
"result"][
"result_code"];
2927 if ($user_status_code ==
"OK") {
2929 $ws_entity = $result_user[
"user"][
"entity"];
2930 $ws_authentication[
'entity'] = $ws_entity;
2931 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2932 if (empty($ws_thirdparty)) {
2933 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"),
null,
'errors');
2934 $error_occurred =
true;
2937 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2938 $soapclient_product->soap_defencoding =
'UTF-8';
2939 $soapclient_product->decodeUTF8(
false);
2943 foreach (
$object->lines as $line) {
2945 $ref_supplier = $line->ref_supplier;
2946 $line_id = $i.
"º) ".$line->product_ref.
": ";
2947 if (empty($ref_supplier)) {
2950 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2951 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2952 if (!$result_product) {
2953 setEventMessages($line_id.$langs->trans(
"Error").
" SOAP ".$soapclient_product->error_str.
" - ".$soapclient_product->response,
null,
'errors');
2954 $error_occurred =
true;
2959 $status_code = $result_product[
"result"][
"result_code"];
2960 if (empty($status_code)) {
2961 setEventMessages($langs->trans(
"Error").
" SOAP '".$soapclient_order->error_str.
"'",
null,
'errors');
2962 } elseif ($status_code !=
"OK") {
2963 if ($status_code ==
"NOT_FOUND") {
2964 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'",
null,
'warnings');
2966 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'",
null,
'errors');
2967 $error_occurred =
true;
2974 $supplier_price =
price($result_product[
"product"][
"price_net"]);
2975 $local_price =
null;
2978 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2979 if (count($product_fourn_list) > 0) {
2980 foreach ($product_fourn_list as $product_fourn_line) {
2982 if ($product_fourn_line->fourn_id ==
$object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2983 $local_price =
price($product_fourn_line->fourn_price);
2988 if ($local_price !=
null && $local_price != $supplier_price) {
2989 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price,
null,
'warnings');
2993 if (empty($result_product[
"product"][
"status_tosell"])) {
2994 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'",
null,
'warnings');
2998 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
2999 setEventMessages($langs->trans(
"RemoteUserNotPermission"),
null,
'errors');
3000 $error_occurred =
true;
3001 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
3002 setEventMessages($langs->trans(
"RemoteUserBadCredentials"),
null,
'errors');
3003 $error_occurred =
true;
3005 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'",
null,
'errors');
3006 $error_occurred =
true;
3010 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
3011 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3012 print
'<input type="hidden" name="action" value="webservice">';
3013 print
'<input type="hidden" name="mode" value="send">';
3014 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
3015 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
3016 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
3017 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
3018 if ($error_occurred) {
3019 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
3021 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
3022 print
' ';
3024 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
3030 $modelmail =
'order_supplier_send';
3031 $defaulttopic =
'SendOrderRef';
3032 $diroutput = $conf->fournisseur->commande->dir_output;
3033 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
3034 $trackid =
'sord'.$object->id;
3036 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
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_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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return 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...
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid