36 require
'../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
46 if (!empty($conf->supplier_proposal->enabled)) {
47 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
49 if (!empty($conf->product->enabled)) {
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
52 if (!empty($conf->project->enabled)) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
56 require_once NUSOAP_PATH.
'/nusoap.php';
58 if (!empty($conf->variants->enabled)) {
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
62 $langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
63 if (!empty($conf->incoterm->enabled)) {
64 $langs->load(
'incoterm');
69 $action =
GETPOST(
'action',
'alpha');
70 $confirm =
GETPOST(
'confirm',
'alpha');
71 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
72 $backtopage =
GETPOST(
'backtopage',
'alpha');
73 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
75 $socid =
GETPOST(
'socid',
'int');
76 $projectid =
GETPOST(
'projectid',
'int');
77 $cancel =
GETPOST(
'cancel',
'alpha');
78 $lineid =
GETPOST(
'lineid',
'int');
79 $origin =
GETPOST(
'origin',
'alpha');
81 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
84 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
85 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
86 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
88 $datelivraison =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'),
GETPOST(
'liv_sec',
'int'),
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
92 if (!empty($user->socid)) {
93 $socid = $user->socid;
97 $hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
103 $extrafields->fetch_name_optionals_label($object->table_element);
106 $socid = $user->socid;
110 if ($id > 0 || !empty($ref)) {
111 $ret = $object->fetch($id, $ref);
115 $ret = $object->fetch_thirdparty();
119 } elseif (!empty($socid) && $socid > 0) {
121 $ret = $fourn->fetch($socid);
125 $object->socid = $fourn->id;
126 $ret = $object->fetch_thirdparty();
133 $isdraft = (isset($object->statut) && ($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
134 $result =
restrictedArea($user,
'fournisseur', $id,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
137 $usercanread = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire);
138 $usercancreate = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
139 $usercandelete = (($user->rights->fournisseur->commande->supprimer || $user->rights->supplier_order->supprimer) || ($usercancreate && isset($object->statut) && $object->statut == $object::STATUS_DRAFT));
142 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate)));
145 $usercanapprove = !empty($user->rights->fournisseur->commande->approuver) ? $user->rights->fournisseur->commande->approuver : 0;
146 $usercanapprovesecond = !empty($user->rights->fournisseur->commande->approve2) ? $user->rights->fournisseur->commande->approve2 : 0;
147 $usercanorder = !empty($user->rights->fournisseur->commande->commander) ? $user->rights->fournisseur->commande->commander : 0;
148 if (empty($conf->reception->enabled)) {
149 $usercanreceive = $user->rights->fournisseur->commande->receptionner;
151 $usercanreceive = $user->rights->reception->creer;
155 $permissionnote = $usercancreate;
156 $permissiondellink = $usercancreate;
157 $permissiontoedit = $usercancreate;
158 $permissiontoadd = $usercancreate;
161 $caneditproject =
false;
162 if (!empty($conf->project->enabled)) {
163 $caneditproject = empty($conf->global->SUPPLIER_ORDER_FORBID_EDIT_PROJECT) || ($object->statut ==
CommandeFournisseur::STATUS_DRAFT && preg_match(
'/^[\(]?PROV/i', $object->ref));
174 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
179 if (empty($reshook)) {
180 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
182 if (empty($backtopage) || ($cancel && empty($id))) {
183 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
184 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
185 $backtopage = $backurlforlist;
187 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
193 if (!empty($backtopageforcancel)) {
194 header(
"Location: ".$backtopageforcancel);
196 } elseif (!empty($backtopage)) {
197 header(
"Location: ".$backtopage);
203 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
205 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
207 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
209 if ($action ==
'setref_supplier' && $usercancreate) {
210 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
217 if ($action ==
'set_incoterms' && $usercancreate) {
218 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
225 if ($action ==
'setconditions' && $usercancreate) {
226 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
233 if ($action ==
'setmode' && $usercancreate) {
234 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
238 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
240 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
241 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
243 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
247 if ($action ==
'setbankaccount' && $usercancreate) {
248 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
255 if ($action ==
'setdate_livraison' && $usercancreate) {
256 $result = $object->setDeliveryDate($user, $datelivraison);
263 if ($action ==
'classin' && $usercancreate && $caneditproject) {
264 $result = $object->setProject($projectid);
271 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action ==
'set_thirdparty' && $usercancreate && $object->statut ==
CommandeFournisseur::STATUS_DRAFT) {
272 $new_socid =
GETPOST(
'new_socid',
'int');
273 if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
277 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
278 $sql .=
' SET fk_soc = '.((int) $new_socid);
279 $sql .=
' WHERE fk_soc = '.((int) $object->thirdparty->id);
280 $sql .=
' AND rowid = '.((int) $object->id);
282 $res = $db->query($sql);
290 foreach ($object->lines as $l) {
291 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
292 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
293 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
294 $sql .=
' AND fk_soc = '.((int) $new_socid);
295 $sql .=
' ORDER BY unitprice ASC';
297 $resql = $db->query($sql);
299 $num_row = $db->num_rows(
$resql);
300 if (empty($num_row)) {
306 $l->ref_supplier =
'';
310 $obj = $db->fetch_object(
$resql);
311 $l->subprice = $obj->unitprice;
312 $l->total_ht = $obj->price;
313 $l->tva_tx = $obj->tva_tx;
314 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
315 $l->total_ttc = $l->total_ht + $l->total_tva;
316 $l->ref_supplier = $obj->ref_fourn;
324 $object->update_price();
327 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
331 if ($action ==
'setremisepercent' && $usercancreate) {
338 if ($action ==
'reopen') {
339 if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) {
340 if ($object->statut == 1) {
342 } elseif ($object->statut == 2) {
344 } elseif ($object->statut == 3) {
346 } elseif ($object->statut == 4) {
348 } elseif ($object->statut == 5) {
354 } elseif ($object->statut == 6) {
356 } elseif ($object->statut == 7) {
358 } elseif ($object->statut == 9) {
367 $result = $object->setStatus($user, $newstatus);
370 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
371 $sql .=
' SET billed = 0';
372 $sql .=
' WHERE rowid = '.((int) $object->id);
374 $resql = $db->query($sql);
376 if ($newstatus == 0) {
377 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
378 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
379 $sql .=
' WHERE rowid = '.((int) $object->id);
381 $resql = $db->query($sql);
386 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
399 if ($action ==
'classifybilled' && $usercancreate) {
400 $ret = $object->classifyBilled($user);
407 if ($action ==
'addline' && $usercancreate) {
410 $langs->load(
'errors');
419 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
420 if ($prod_entry_mode ==
'free') {
423 $idprod =
GETPOST(
'idprod',
'int');
435 if (empty($remise_percent)) {
440 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
441 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
443 if (is_array($extralabelsline)) {
445 foreach ($extralabelsline as $key => $value) {
446 unset($_POST[
"options_".$key]);
450 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
451 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
454 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
455 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
458 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
459 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
462 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
463 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
466 if (
GETPOST(
'qty',
'alpha') ==
'') {
467 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
471 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
472 if ($combinations =
GETPOST(
'combinations',
'array')) {
476 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
477 $idprod = $res->fk_product_child;
479 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
485 if ($prod_entry_mode !=
'free' && empty($error)) {
489 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
494 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
496 $res = $productsupplier->fetch($idprod);
499 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
501 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
502 if ($productsupplier->fourn_socid != $socid) {
503 $productsupplier->ref_supplier =
'';
506 $fksoctosearch = $object->thirdparty->id;
507 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
509 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
512 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
513 $res = $productsupplier->fetch($idprod);
517 $label = $productsupplier->label;
520 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
521 $outputlangs = $langs;
523 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
524 $newlang =
GETPOST(
'lang_id',
'aZ09');
526 if (empty($newlang)) {
527 $newlang = $object->thirdparty->default_lang;
529 if (!empty($newlang)) {
531 $outputlangs->setDefaultLang($newlang);
533 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
535 $desc = $productsupplier->description;
538 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
539 $desc = $productsupplier->desc_supplier;
543 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
547 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
548 $desc = $product_desc;
550 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
551 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
554 $ref_supplier = $productsupplier->ref_supplier;
558 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
559 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
561 if (empty($tva_tx)) {
564 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
565 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
567 $type = $productsupplier->type;
568 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
569 $price_base_type =
'HT';
571 $pu_devise =
price2num($price_ht_devise,
'CU');
572 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
573 $price_base_type =
'TTC';
575 $pu_devise =
price2num($price_ttc_devise,
'CU');
577 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
578 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
579 $pu = $productsupplier->fourn_pu;
582 $pu = $productsupplier->fourn_pu;
583 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
591 $result = $object->addline(
593 ($price_base_type ==
'HT' ? $pu : 0),
599 $productsupplier->product_fourn_price_id,
603 ($price_base_type ==
'TTC' ? $pu : 0),
610 $productsupplier->fk_unit,
614 min($rank, count($object->lines) + 1)
617 if ($idprod == -99 || $idprod == 0) {
620 $langs->load(
"errors");
621 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
626 $langs->load(
"errors");
627 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
629 } elseif (empty($error)) {
630 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
631 $tva_tx = str_replace(
'*',
'', $tva_tx);
632 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
633 $desc = $product_desc;
635 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
637 $fk_unit =
GETPOST(
'units',
'alpha');
639 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
644 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
645 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
647 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
651 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
653 $price_base_type =
'HT';
654 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
656 $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);
660 if (!$error && $result > 0) {
663 $ret = $object->fetch($object->id);
666 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
667 $outputlangs = $langs;
669 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
670 $newlang =
GETPOST(
'lang_id',
'aZ09');
672 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
673 $newlang = $object->thirdparty->default_lang;
675 if (!empty($newlang)) {
677 $outputlangs->setDefaultLang($newlang);
679 $model = $object->model_pdf;
680 $ret = $object->fetch($id);
682 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
688 unset($_POST [
'prod_entry_mode']);
690 unset($_POST[
'qty']);
691 unset($_POST[
'type']);
692 unset($_POST[
'remise_percent']);
694 unset($_POST[
'price_ht']);
695 unset($_POST[
'multicurrency_price_ht']);
696 unset($_POST[
'price_ttc']);
697 unset($_POST[
'fourn_ref']);
698 unset($_POST[
'tva_tx']);
699 unset($_POST[
'label']);
700 unset($localtax1_tx);
701 unset($localtax2_tx);
702 unset($_POST[
'np_marginRate']);
703 unset($_POST[
'np_markRate']);
704 unset($_POST[
'dp_desc']);
705 unset($_POST[
'idprodfournprice']);
706 unset($_POST[
'units']);
708 unset($_POST[
'date_starthour']);
709 unset($_POST[
'date_startmin']);
710 unset($_POST[
'date_startsec']);
711 unset($_POST[
'date_startday']);
712 unset($_POST[
'date_startmonth']);
713 unset($_POST[
'date_startyear']);
714 unset($_POST[
'date_endhour']);
715 unset($_POST[
'date_endmin']);
716 unset($_POST[
'date_endsec']);
717 unset($_POST[
'date_endday']);
718 unset($_POST[
'date_endmonth']);
719 unset($_POST[
'date_endyear']);
731 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
738 $res = $line->fetch($lineid);
745 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
746 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0,
price2num(
GETPOST(
'qty',
'int')), $line->fk_product,
'none',
GETPOST(
'socid',
'int')) < 0) {
747 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
756 if (preg_match(
'/\*/', $vat_rate)) {
761 $vat_rate = str_replace(
'*',
'', $vat_rate);
762 $localtax1_rate =
get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
763 $localtax2_rate =
get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
765 if (
GETPOST(
'price_ht') !=
'') {
766 $price_base_type =
'HT';
770 $vatratecleaned = $vat_rate;
771 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
772 $vatratecleaned = trim($reg[1]);
773 $vatratecode = $reg[2];
777 $ht = $ttc / (1 + ($vatratecleaned / 100));
778 $price_base_type =
'HT';
784 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
785 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
787 if (is_array($extralabelsline)) {
788 foreach ($extralabelsline as $key => $value) {
789 unset($_POST[
"options_".$key]);
793 $result = $object->updateline(
795 GETPOST(
'product_desc',
'restricthtml'),
813 unset($_POST[
'qty']);
814 unset($_POST[
'type']);
815 unset($_POST[
'idprodfournprice']);
816 unset($_POST[
'remmise_percent']);
817 unset($_POST[
'dp_desc']);
818 unset($_POST[
'np_desc']);
820 unset($_POST[
'fourn_ref']);
821 unset($_POST[
'tva_tx']);
822 unset($_POST[
'date_start']);
823 unset($_POST[
'date_end']);
824 unset($_POST[
'units']);
825 unset($localtax1_tx);
826 unset($localtax2_tx);
828 unset($_POST[
'date_starthour']);
829 unset($_POST[
'date_startmin']);
830 unset($_POST[
'date_startsec']);
831 unset($_POST[
'date_startday']);
832 unset($_POST[
'date_startmonth']);
833 unset($_POST[
'date_startyear']);
834 unset($_POST[
'date_endhour']);
835 unset($_POST[
'date_endmin']);
836 unset($_POST[
'date_endsec']);
837 unset($_POST[
'date_endday']);
838 unset($_POST[
'date_endmonth']);
839 unset($_POST[
'date_endyear']);
843 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
844 $outputlangs = $langs;
846 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
847 $newlang =
GETPOST(
'lang_id',
'aZ09');
849 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
850 $newlang = $object->thirdparty->default_lang;
852 if (!empty($newlang)) {
854 $outputlangs->setDefaultLang($newlang);
856 $model = $object->model_pdf;
857 $ret = $object->fetch($id);
859 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
874 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
877 $result = $object->deleteline($lineid);
880 $object->line_order(
true);
882 $outputlangs = $langs;
884 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
885 $newlang =
GETPOST(
'lang_id',
'aZ09');
887 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
888 $newlang = $object->thirdparty->default_lang;
890 if (!empty($newlang)) {
892 $outputlangs->setDefaultLang($newlang);
894 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
895 $ret = $object->fetch($object->id);
896 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
908 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
916 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
919 $object->date_commande =
dol_now();
920 $result = $object->valid($user);
923 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
924 $outputlangs = $langs;
926 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
927 $newlang =
GETPOST(
'lang_id',
'aZ09');
929 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
930 $newlang = $object->thirdparty->default_lang;
932 if (!empty($newlang)) {
934 $outputlangs->setDefaultLang($newlang);
936 $model = $object->model_pdf;
937 $ret = $object->fetch($id);
939 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
951 if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) {
952 $action =
'confirm_approve';
962 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
965 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
967 $qualified_for_stock_change = 0;
968 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
969 $qualified_for_stock_change = $object->hasProductsOrServices(2);
971 $qualified_for_stock_change = $object->hasProductsOrServices(1);
975 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
976 if (!$idwarehouse || $idwarehouse == -1) {
978 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
984 $result = $object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
986 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
987 $outputlangs = $langs;
989 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
990 $newlang =
GETPOST(
'lang_id',
'aZ09');
992 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
993 $newlang = $object->thirdparty->default_lang;
995 if (!empty($newlang)) {
997 $outputlangs->setDefaultLang($newlang);
999 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1010 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1017 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1019 $object->refuse_note =
GETPOST(
'refuse_note');
1021 $result = $object->refuse($user);
1023 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1031 if ($action ==
'commande') {
1032 $methodecommande =
GETPOST(
'methodecommande',
'int');
1036 } elseif ($methodecommande <= 0) {
1037 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1038 $action =
'makeorder';
1042 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1045 $result = $object->commande($user,
GETPOST(
"datecommande"),
GETPOST(
"methode",
'int'),
GETPOST(
'comment',
'alphanohtml'));
1047 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1048 $outputlangs = $langs;
1050 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1051 $newlang =
GETPOST(
'lang_id',
'aZ09');
1053 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1054 $newlang = $object->thirdparty->default_lang;
1056 if (!empty($newlang)) {
1057 $outputlangs =
new Translate(
"", $conf);
1058 $outputlangs->setDefaultLang($newlang);
1060 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1071 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1079 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1080 $result = $object->delete($user);
1082 header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
1090 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1091 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1092 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1094 if ($object->id > 0) {
1095 $orig = clone $object;
1097 $result = $object->createFromClone($user, $socid);
1099 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1111 if ($action ==
'livraison' && $usercanreceive) {
1120 $result = $object->Livraison($user, $date_liv,
GETPOST(
"type"),
GETPOST(
"comment"));
1122 $langs->load(
"deliveries");
1125 } elseif ($result == -3) {
1134 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1145 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1147 $object->cancel_note =
GETPOST(
'cancel_note');
1149 $result = $object->cancel($user);
1151 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1159 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1162 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1163 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1164 $trackid =
'sord'.$object->id;
1165 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1168 $upload_dir = $conf->fournisseur->commande->dir_output;
1169 $permissiontoadd = $usercancreate;
1170 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1173 if ($action ==
'update_extras') {
1177 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1185 $result = $object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
1194 $action =
'edit_extras';
1201 if ($action ==
'add' && $usercancreate) {
1203 $selectedLines =
GETPOST(
'toselect',
'array');
1205 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1214 $object->ref_supplier =
GETPOST(
'refsupplier');
1215 $object->socid = $socid;
1216 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1217 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1218 $object->fk_account =
GETPOST(
'fk_account',
'int');
1219 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
1220 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
1221 $object->date_livraison = $datelivraison;
1222 $object->delivery_date = $datelivraison;
1223 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1224 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1225 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1226 $object->multicurrency_tx =
price2num(
GETPOST(
'originmulticurrency_tx',
'alpha'));
1227 $object->fk_project =
GETPOST(
'projectid',
'int');
1231 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1239 if (!empty($origin) && !empty($originid)) {
1240 $element = $subelement = $origin;
1241 $classname = ucfirst($subelement);
1242 if ($origin ==
'propal' || $origin ==
'proposal') {
1243 $element =
'comm/propal'; $subelement =
'propal';
1244 $classname =
'Propal';
1246 if ($origin ==
'order' || $origin ==
'commande') {
1247 $element = $subelement =
'commande';
1248 $classname =
'Commande';
1250 if ($origin ==
'supplier_proposal') {
1251 $classname =
'SupplierProposal';
1252 $element =
'supplier_proposal';
1253 $subelement =
'supplier_proposal';
1256 $object->origin = $origin;
1257 $object->origin_id = $originid;
1260 $object->linked_objects [$object->origin] = $object->origin_id;
1261 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1262 if (!empty($other_linked_objects)) {
1263 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
1266 $id = $object->create($user);
1270 $srcobject =
new $classname($db);
1272 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
1273 $result = $srcobject->fetch($object->origin_id);
1275 $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
1276 $object->setDeliveryDate($user, $tmpdate);
1277 $object->set_id_projet($user, $srcobject->fk_project);
1279 $lines = $srcobject->lines;
1280 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1281 $srcobject->fetch_lines();
1282 $lines = $srcobject->lines;
1285 $fk_parent_line = 0;
1286 $num = count($lines);
1288 for ($i = 0; $i < $num; $i++) {
1289 if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines)) {
1293 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1294 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
1295 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1298 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1299 $fk_parent_line = 0;
1303 if (method_exists($lines[$i],
'fetch_optionals')) {
1304 $lines[$i]->fetch_optionals();
1305 $array_option = $lines[$i]->array_options;
1309 $product_fourn_price_id = 0;
1310 if ($origin ==
"commande") {
1312 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
1314 $ref_supplier = $productsupplier->ref_supplier;
1315 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1318 $ref_supplier = $lines[$i]->ref_fourn;
1319 $product_fourn_price_id = 0;
1322 $tva_tx = $lines[$i]->tva_tx;
1324 if ($origin ==
"commande") {
1325 $soc =
new societe($db);
1326 $soc->fetch($socid);
1327 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1330 $object->special_code = $lines[$i]->special_code;
1332 $result = $object->addline(
1334 $lines[$i]->subprice,
1337 $lines[$i]->localtax1_tx,
1338 $lines[$i]->localtax2_tx,
1339 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1340 $product_fourn_price_id,
1342 $lines[$i]->remise_percent,
1345 $lines[$i]->product_type,
1351 $lines[$i]->fk_unit,
1354 !empty($lines[$i]->
id) ? $lines[$i]->
id : $lines[$i]->
rowid
1363 if ($result > 0 && $lines[$i]->product_type == 9) {
1364 $fk_parent_line = $result;
1373 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1388 $id = $object->create($user);
1397 $langs->load(
"errors");
1400 $_GET[
'socid'] = $_POST[
'socid'];
1403 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode($id));
1409 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') ==
"send" && !
GETPOST(
'cancel',
'alpha')) {
1410 $ws_url = $object->thirdparty->webservices_url;
1411 $ws_key = $object->thirdparty->webservices_key;
1412 $ws_user =
GETPOST(
'ws_user',
'alpha');
1413 $ws_password =
GETPOST(
'ws_password',
'alpha');
1414 $ws_entity =
GETPOST(
'ws_entity',
'int');
1415 $ws_thirdparty =
GETPOST(
'ws_thirdparty',
'int');
1418 $ws_ns =
'http://www.dolibarr.org/ns/';
1419 $ws_authentication = array(
1420 'dolibarrkey'=>$ws_key,
1421 'sourceapplication'=>
'DolibarrWebServiceClient',
1423 'password'=>$ws_password,
1424 'entity'=>$ws_entity
1428 if (empty($conf->syncsupplierwebservices->enabled)) {
1429 setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2650Name")),
null,
'mesgs');
1430 } elseif (empty($ws_url) || empty($ws_key)) {
1431 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
1432 } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1436 $soapclient_order =
new nusoap_client($ws_url.
"/webservices/server_order.php");
1437 $soapclient_order->soap_defencoding =
'UTF-8';
1438 $soapclient_order->decodeUTF8(
false);
1441 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
1442 $soapclient_product->soap_defencoding =
'UTF-8';
1443 $soapclient_product->decodeUTF8(
false);
1446 $order_lines = array();
1447 foreach ($object->lines as $line) {
1448 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $line->ref_supplier);
1449 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
1451 if ($result_product[
"result"][
"result_code"] ==
"OK") {
1452 $order_lines[] = array(
1453 'desc' => $line->product_desc,
1454 'type' => $line->product_type,
1455 'product_id' => $result_product[
"product"][
"id"],
1456 'vat_rate' => $line->tva_tx,
1457 'qty' => $line->qty,
1458 'price' => $line->price,
1459 'unitprice' => $line->subprice,
1460 'total_net' => $line->total_ht,
1461 'total_vat' => $line->total_tva,
1462 'total' => $line->total_ttc,
1463 'date_start' => $line->date_start,
1464 'date_end' => $line->date_end,
1471 'thirdparty_id' => $ws_thirdparty,
1473 'total_net' => $object->total_ht,
1474 'total_var' => $object->total_tva,
1475 'total' => $object->total_ttc,
1476 'lines' => $order_lines
1479 $ws_parameters = array(
'authentication'=>$ws_authentication,
'order' => $order);
1480 $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns,
'');
1482 if (empty($result_order[
"result"][
"result_code"])) {
1483 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'",
null,
'errors');
1484 } elseif ($result_order[
"result"][
"result_code"] !=
"OK") {
1485 setEventMessages($langs->trans(
"SOAPError").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'",
null,
'errors');
1487 setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"],
null,
'mesgs');
1492 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1493 if ($action ==
'addcontact') {
1494 if ($object->id > 0) {
1497 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1501 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1504 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1505 $langs->load(
"errors");
1506 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1511 } elseif ($action ==
'swapstatut' && $object->id > 0) {
1513 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1514 } elseif ($action ==
'deletecontact' && $object->id > 0) {
1516 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1519 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1536 $productstatic =
new Product($db);
1537 if (!empty($conf->project->enabled)) {
1541 $title = $langs->trans(
'SupplierOrder').
" - ".$langs->trans(
'Card');
1542 $help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1547 if ($action ==
'create') {
1548 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1552 $currency_code = $conf->currency;
1557 $societe->fetch($socid);
1560 if (!empty($origin) && !empty($originid)) {
1562 $element = $subelement = $origin;
1563 $classname = ucfirst($subelement);
1565 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1566 $element = $regs[1];
1567 $subelement = $regs[2];
1570 if ($origin ==
'propal' || $origin ==
'proposal') {
1571 $classname =
'Propal';
1572 $element =
'comm/propal'; $subelement =
'propal';
1574 if ($origin ==
'order' || $origin ==
'commande') {
1575 $classname =
'Commande';
1576 $element = $subelement =
'commande';
1578 if ($origin ==
'supplier_proposal') {
1579 $classname =
'SupplierProposal';
1580 $element =
'supplier_proposal';
1581 $subelement =
'supplier_proposal';
1588 $objectsrc =
new $classname($db);
1589 $objectsrc->fetch($originid);
1590 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1591 $objectsrc->fetch_lines();
1593 $objectsrc->fetch_thirdparty();
1596 $objectsrc->fetch_optionals();
1597 $object->array_options = $objectsrc->array_options;
1599 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1600 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1602 $soc = $objectsrc->thirdparty;
1604 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1605 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1606 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1607 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1608 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1609 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1610 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1611 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1612 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1614 $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
''));
1616 if (!empty($conf->multicurrency->enabled)) {
1617 if (!empty($objectsrc->multicurrency_code)) {
1618 $currency_code = $objectsrc->multicurrency_code;
1620 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1621 $currency_tx = $objectsrc->multicurrency_tx;
1625 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1626 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1629 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1631 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1632 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1634 if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) {
1635 $currency_code = $societe->multicurrency_code;
1638 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1639 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1643 if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) {
1644 $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
1646 if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) {
1647 $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
1650 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1651 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1652 print
'<input type="hidden" name="action" value="add">';
1653 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1654 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1655 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1657 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1659 if ($backtopageforcancel) {
1660 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1663 if (!empty($currency_tx)) {
1664 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1669 print
'<table class="border centpercent">';
1672 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1675 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1678 if (!empty($societe->id) && $societe->id > 0) {
1679 print $societe->getNomUrl(1,
'supplier');
1680 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1682 print
img_picto(
'',
'company').$form->select_company((empty($socid) ?
'' : $socid),
'socid',
's.fournisseur=1',
'SelectThirdParty', 0, 0,
null, 0,
'minwidth300');
1684 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
1686 $(document).ready(function() {
1687 $("#socid").change(function() {
1688 var socid = $(this).val();
1689 var prjid = $("#projectid").val();
1691 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&projectid="+prjid
1696 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>';
1700 if (!empty($societe->id) && $societe->id > 0) {
1702 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1704 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
1706 $thirdparty = $societe;
1708 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1709 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1715 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1719 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1720 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id');
1724 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1725 $form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
1730 print $langs->trans(
'DateDeliveryPlanned');
1734 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1737 print
$form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin,
'',
"set");
1741 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled)) {
1742 $langs->load(
"bank");
1743 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1744 print
img_picto(
'',
'bank_account',
'class="paddingrightonly"');
1745 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
1750 if (!empty($conf->project->enabled)) {
1753 $langs->load(
'projects');
1754 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1755 print
img_picto(
'',
'project').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
1756 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>';
1761 if (!empty($conf->incoterm->enabled)) {
1762 $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1763 $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1765 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $object->label_incoterms, 1).
'</label></td>';
1766 print
'<td class="maxwidthonsmartphone">';
1767 print
$form->select_incoterms($fkincoterms, $locincoterms);
1772 if (!empty($conf->multicurrency->enabled)) {
1774 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1775 print
'<td class="maxwidthonsmartphone">';
1776 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
1780 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
1782 $doleditor =
new DolEditor(
'note_public', isset($note_public) ? $note_public :
GETPOST(
'note_public',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1783 print $doleditor->Create(1);
1788 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
1790 $doleditor =
new DolEditor(
'note_private', isset($note_private) ? $note_private :
GETPOST(
'note_private',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1791 print $doleditor->Create(1);
1796 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1797 print
"\n<!-- ".$classname.
" info -->";
1799 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1800 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1801 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1802 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1803 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1805 $newclassname = $classname;
1806 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
1807 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1808 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1809 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1810 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1813 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1814 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1817 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1819 if (!empty($conf->multicurrency->enabled)) {
1820 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1821 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
1822 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
1828 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1829 print $hookmanager->resPrint;
1831 if (empty($reshook)) {
1832 print $object->showOptionals($extrafields,
'create');
1840 print
$form->buttonsSaveCancel(
"CreateDraft");
1843 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1844 $title = $langs->trans(
'ProductsAndServices');
1847 print
'<div class="div-table-responsive-no-min">';
1848 print
'<table class="noborder centpercent">';
1850 $selectedLines = array();
1852 $objectsrc->printOriginLinesList(
'', $selectedLines);
1858 } elseif (!empty($object->id)) {
1859 $result = $object->fetch($id, $ref);
1862 $result = $societe->fetch($object->socid);
1867 $author =
new User($db);
1868 $author->fetch($object->user_author_id);
1870 $res = $object->fetch_optionals();
1875 $title = $langs->trans(
"SupplierOrder");
1882 if ($action ==
'delete') {
1883 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 2);
1887 if ($action ==
'clone') {
1889 $formquestion = array(
1890 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.fournisseur=1)'))
1893 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1897 if ($action ==
'valid') {
1898 $object->date_commande =
dol_now();
1901 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
1902 $newref = $object->getNextNumRef($object->thirdparty);
1904 $newref = $object->ref;
1911 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
1912 if (!empty($conf->notification->enabled)) {
1913 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1914 $notify =
new Notify($db);
1916 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
1919 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
1924 if ($action ==
'approve' || $action ==
'approve2') {
1925 $qualified_for_stock_change = 0;
1926 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1927 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1929 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1932 $formquestion = array();
1933 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
1934 $langs->load(
"stocks");
1935 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1938 if ($conf->browser->name ==
'ie') {
1941 $formquestion = array(
1945 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse',
'int'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
1948 $text = $langs->trans(
"ConfirmApproveThisOrder", $object->ref);
1949 if (!empty($conf->notification->enabled)) {
1950 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1951 $notify =
new Notify($db);
1953 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE', $object->socid, $object);
1956 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
1960 if ($action ==
'refuse') {
1961 $formquestion = array(
1964 'name' =>
'refuse_note',
1965 'label' => $langs->trans(
"Reason"),
1967 'morecss' =>
'minwidth300'
1970 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder", $object->ref),
"confirm_refuse", $formquestion, 0, 1);
1974 if ($action ==
'cancel') {
1975 $formquestion = array(
1978 'name' =>
'cancel_note',
1979 'label' => $langs->trans(
"Reason"),
1981 'morecss' =>
'minwidth300'
1984 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder", $object->ref),
"confirm_cancel", $formquestion, 0, 1);
1988 if ($action ==
'commande') {
1990 $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);
1994 if ($action ==
'ask_deleteline') {
1995 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
1999 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2000 if (empty($reshook)) {
2002 } elseif ($reshook > 0) {
2012 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2014 $morehtmlref =
'<div class="refidno">';
2016 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2017 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2019 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty');
2020 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2021 $morehtmlref .=
' : ';
2022 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2023 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2024 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2025 $morehtmlref .=
$form->select_company($object->thirdparty->id,
'new_socid',
's.fournisseur=1',
'', 0, 0, array(), 0,
'minwidth300');
2026 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2027 $morehtmlref .=
'</form>';
2029 if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action !=
'edit_thirdparty') {
2031 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2033 $morehtmlref .=
' : '.$object->thirdparty->getNomUrl(1,
'supplier');
2034 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2035 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2040 if (!empty($conf->project->enabled)) {
2041 $langs->load(
"projects");
2042 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2043 if ($usercancreate) {
2044 if ($action !=
'classify' && $caneditproject) {
2045 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2047 if ($action ==
'classify') {
2049 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2050 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2051 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2052 $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project,
'projectid', 0, 0, 1, 1, 1, 0, 0,
'', 1, 0,
'maxwidth500');
2053 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2054 $morehtmlref .=
'</form>';
2056 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2059 if (!empty($object->fk_project)) {
2061 $proj->fetch($object->fk_project);
2062 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2064 $morehtmlref .=
' - '.$proj->title;
2071 $morehtmlref .=
'</div>';
2074 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2077 print
'<div class="fichecenter">';
2078 print
'<div class="fichehalfleft">';
2079 print
'<div class="underbanner clearboth"></div>';
2081 print
'<table class="border tableforfield centpercent">';
2084 if ($object->methode_commande_id > 0) {
2085 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2086 print $object->date_commande ?
dol_print_date($object->date_commande, $usehourmin ?
'dayhour' :
'day') :
'';
2087 if ($object->hasDelay() && !empty($object->date_delivery) && !empty($object->date_commande)) {
2088 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2092 if ($object->methode_commande) {
2093 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
2098 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2099 print
'<td>'.$author->getNomUrl(1,
'', 0, 0, 0).
'</td>';
2103 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2104 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2105 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2107 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2108 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2111 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2112 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2113 $absolute_discount =
price2num($absolute_discount,
'MT');
2114 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2116 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2118 $thirdparty = $societe;
2120 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2121 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2126 $langs->load(
'bills');
2127 print
'<tr><td class="nowrap">';
2128 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2129 print $langs->trans(
'PaymentConditions');
2131 if ($action !=
'editconditions') {
2132 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>';
2134 print
'</tr></table>';
2136 if ($action ==
'editconditions') {
2137 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
2139 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
2145 $langs->load(
'bills');
2146 print
'<tr><td class="nowrap">';
2147 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2148 print $langs->trans(
'PaymentMode');
2150 if ($action !=
'editmode') {
2151 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>';
2153 print
'</tr></table>';
2155 if ($action ==
'editmode') {
2156 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2158 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2163 if (!empty($conf->multicurrency->enabled)) {
2167 print
'<table class="nobordernopadding centpercent"><tr><td>';
2168 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2170 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
2171 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>';
2173 print
'</tr></table>';
2175 if ($action ==
'editmulticurrencycode') {
2176 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2178 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2183 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2186 print
'<table class="nobordernopadding centpercent"><tr>';
2188 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2190 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2191 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>';
2193 print
'</tr></table>';
2195 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2196 if ($action ==
'actualizemulticurrencyrate') {
2199 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2201 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2202 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2203 print
'<div class="inline-block"> ';
2204 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2213 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled)) {
2214 print
'<tr><td class="nowrap">';
2215 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2216 print $langs->trans(
'BankAccount');
2218 if ($action !=
'editbankaccount' && $usercancreate) {
2219 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>';
2221 print
'</tr></table>';
2223 if ($action ==
'editbankaccount') {
2224 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2226 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2234 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2235 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2240 print
'<table class="nobordernopadding centpercent"><tr><td>';
2241 print $langs->trans(
'DateDeliveryPlanned');
2243 if ($action !=
'editdate_livraison') {
2244 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>';
2246 print
'</tr></table>';
2248 if ($action ==
'editdate_livraison') {
2249 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2250 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2251 print
'<input type="hidden" name="action" value="setdate_livraison">';
2253 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2256 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin,
'',
"setdate_livraison");
2257 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2260 $usehourmin =
'day';
2261 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2262 $usehourmin =
'dayhour';
2264 print $object->delivery_date ?
dol_print_date($object->delivery_date, $usehourmin) :
' ';
2265 if ($object->hasDelay() && !empty($object->delivery_date)) {
2266 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2272 if (!empty($conf->incoterm->enabled)) {
2274 print
'<table class="nobordernopadding centpercent"><tr><td>';
2275 print $langs->trans(
'IncotermLabel');
2276 print
'<td><td class="right">';
2277 if ($usercancreate) {
2278 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2282 print
'</td></tr></table>';
2285 if ($action !=
'editincoterm') {
2288 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2294 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2299 print
'<div class="fichehalfright">';
2300 print
'<div class="underbanner clearboth"></div>';
2302 print
'<table class="border tableforfield centpercent">';
2304 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2306 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2307 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2311 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2312 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2316 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2317 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2323 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
2324 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->supplier_order_min_amount));
2326 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
2327 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).$alert.
'</td>';
2331 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td>';
2332 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2336 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2337 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2338 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2341 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2342 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2343 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2348 print
'<tr><td>'.$langs->trans(
"AmountTTC").
'</td>';
2349 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2363 print
'<div class="clearboth"></div><br>';
2365 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2366 $blocname =
'contacts';
2367 $title = $langs->trans(
'ContactsAddresses');
2368 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2371 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2372 $blocname =
'notes';
2373 $title = $langs->trans(
'Notes');
2374 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2383 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2384 <input type="hidden" name="token" value="'.
newToken().
'">
2385 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2386 <input type="hidden" name="mode" value="">
2387 <input type="hidden" name="page_y" value="">
2388 <input type="hidden" name="id" value="'.$object->id.
'">
2389 <input type="hidden" name="socid" value="'.$societe->id.
'">
2392 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
2393 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2396 print
'<div class="div-table-responsive-no-min">';
2397 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2400 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2401 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
2402 $senderissupplier = 2;
2403 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
2404 $senderissupplier = 1;
2408 if (!empty($object->lines)) {
2409 $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
2412 $num = count($object->lines);
2416 if ($action !=
'editline') {
2420 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2421 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2422 if (empty($reshook))
2423 $object->formAddObjectLine(1, $societe, $mysoc);
2436 if ($user->socid == 0 && $action !=
'editline' && $action !=
'delete') {
2437 print
'<div class="tabsAction">';
2440 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2442 if (empty($reshook)) {
2443 $object->fetchObjectLinked();
2446 if ($object->statut == 0 && $num > 0) {
2447 if ($usercanvalidate) {
2448 $tmpbuttonlabel = $langs->trans(
'Validate');
2449 if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
2450 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2453 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid">';
2454 print $tmpbuttonlabel;
2466 if ($usercanorder) {
2467 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2473 if ($usercanapprove) {
2474 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED && !empty($object->user_approve_id)) {
2475 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2477 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2480 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2485 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
2487 if ($usercanapprovesecond) {
2488 if (!empty($object->user_approve_id2)) {
2489 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2491 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2494 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2501 if ($usercanapprove || $usercanapprovesecond) {
2502 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2504 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2509 if (empty($user->socid)) {
2511 if ($usercanorder) {
2512 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2520 if (!$buttonshown && $usercanapprove) {
2521 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
2522 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) {
2523 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2527 if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
2528 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
2529 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) {
2530 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2534 if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) {
2535 if ($usercanorder) {
2536 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2542 if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) {
2543 $labelofbutton = $langs->trans(
'ReceiveProducts');
2544 if ($conf->reception->enabled) {
2545 $labelofbutton = $langs->trans(
"CreateReception");
2546 if (!empty($object->linkedObjects[
'reception'])) {
2547 foreach ($object->linkedObjects[
'reception'] as $element) {
2548 if ($element->statut >= 0) {
2556 if (in_array($object->statut, array(3, 4, 5))) {
2557 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) && $usercanreceive) {
2558 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.$object->id.
'">'.$labelofbutton.
'</a></div>';
2560 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2566 if ($usercanorder) {
2567 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=makeorder#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
2569 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2575 if ($usercanreceive) {
2576 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>';
2583 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled)) && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1)) {
2584 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2585 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(
"CreateBill").
'</a>';
2591 if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1) {
2593 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2595 if (!empty($object->linkedObjectsIds[
'invoice_supplier'])) {
2596 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2597 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2600 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2606 if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2) {
2607 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=webservice&token='.
newToken().
'&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
2611 if ($usercancreate) {
2612 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=order">'.$langs->trans(
"ToClone").
'</a>';
2617 if ($usercanorder) {
2618 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel">'.$langs->trans(
"CancelOrder").
'</a>';
2623 if (!empty($usercandelete)) {
2624 if ($hasreception) {
2625 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
2627 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2638 print
'<!-- form to record supplier order -->'.
"\n";
2639 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2641 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2642 print
'<input type="hidden" name="action" value="commande">';
2644 print
'<table class="noborder centpercent">';
2646 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2647 $date_com =
dol_mktime(
GETPOST(
'rehour',
'int'),
GETPOST(
'remin',
'int'),
GETPOST(
'resec',
'int'),
GETPOST(
'remonth',
'int'),
GETPOST(
'reday',
'int'),
GETPOST(
'reyear',
'int'));
2648 if (empty($date_com)) {
2651 print
$form->selectDate($date_com,
'', 1, 1,
'',
"commande", 1, 1);
2655 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2656 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2659 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2660 print
'<tr><td class="center" colspan="2">';
2661 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2662 print
' ';
2663 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2671 if ($action !=
'makeorder') {
2672 print
'<div class="fichecenter"><div class="fichehalfleft">';
2676 $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2677 $relativepath = $objref.
'/'.$objref.
'.pdf';
2678 $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
2679 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2680 $genallowed = $usercanread;
2681 $delallowed = $usercancreate;
2682 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
2684 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'', $object->thirdparty->default_lang,
'', $object);
2685 $somethingshown = $formfile->numoffiles;
2688 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'supplier_order',
'order_supplier'));
2689 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2691 print
'</div><div class="fichehalfright">';
2693 if ($action ==
'classifyreception') {
2696 print
'<!-- form to record purchase order received -->'.
"\n";
2697 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2698 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2699 print
'<input type="hidden" name="action" value="livraison">';
2702 print
'<table class="noborder centpercent">';
2704 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2706 print
$form->selectDate($datepreselected,
'', 1, 1,
'',
"commande", 1, 1);
2707 print
"</td></tr>\n";
2709 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2711 $liv[
''] =
' ';
2712 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2713 $liv[
'par'] = $langs->trans(
"PartialWoman");
2714 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2715 $liv[
'can'] = $langs->trans(
"Canceled");
2717 print
$form->selectarray(
"type", $liv);
2720 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment"></td></tr>';
2721 print
'<tr><td class="center" colspan="2">';
2722 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
2723 print
' ';
2724 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2733 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2735 $somethingshown =
$formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2737 print
'</div></div>';
2743 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
2744 $mode =
GETPOST(
'mode',
'alpha');
2745 $ws_url = $object->thirdparty->webservices_url;
2746 $ws_key = $object->thirdparty->webservices_key;
2747 $ws_user =
GETPOST(
'ws_user',
'alpha');
2748 $ws_password =
GETPOST(
'ws_password',
'alpha');
2751 $ws_ns =
'http://www.dolibarr.org/ns/';
2752 $ws_authentication = array(
2753 'dolibarrkey'=>$ws_key,
2754 'sourceapplication'=>
'DolibarrWebServiceClient',
2756 'password'=>$ws_password,
2763 if (empty($ws_url) || empty($ws_key)) {
2764 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
2766 $error_occurred =
true;
2767 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2772 if ($mode ==
"init") {
2774 print
'<table class="border centpercent">';
2775 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2776 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2777 print
'<input type="hidden" name="action" value="webservice">';
2778 print
'<input type="hidden" name="mode" value="check">';
2780 if ($error_occurred) {
2781 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2782 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2784 $textinput_size =
"50";
2786 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2788 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_user"></td></tr>';
2790 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_password"></td></tr>';
2792 print
'<tr><td class="center" colspan="2">';
2793 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2794 print
' ';
2796 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2803 } elseif ($mode ==
"check") {
2805 $ws_thirdparty =
'';
2806 $error_occurred =
false;
2809 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2810 $soapclient_user->soap_defencoding =
'UTF-8';
2811 $soapclient_user->decodeUTF8(
false);
2814 $ws_parameters = array(
'authentication'=>$ws_authentication,
'id' =>
'',
'ref'=>$ws_user);
2815 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2816 $user_status_code = $result_user[
"result"][
"result_code"];
2818 if ($user_status_code ==
"OK") {
2820 $ws_entity = $result_user[
"user"][
"entity"];
2821 $ws_authentication[
'entity'] = $ws_entity;
2822 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2823 if (empty($ws_thirdparty)) {
2824 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"),
null,
'errors');
2825 $error_occurred =
true;
2828 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2829 $soapclient_product->soap_defencoding =
'UTF-8';
2830 $soapclient_product->decodeUTF8(
false);
2834 foreach ($object->lines as $line) {
2836 $ref_supplier = $line->ref_supplier;
2837 $line_id = $i.
"º) ".$line->product_ref.
": ";
2838 if (empty($ref_supplier)) {
2841 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2842 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2843 if (!$result_product) {
2844 setEventMessages($line_id.$langs->trans(
"SOAPError").
" ".$soapclient_product->error_str.
" - ".$soapclient_product->response,
null,
'errors');
2845 $error_occurred =
true;
2850 $status_code = $result_product[
"result"][
"result_code"];
2851 if (empty($status_code)) {
2852 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'",
null,
'errors');
2853 } elseif ($status_code !=
"OK") {
2854 if ($status_code ==
"NOT_FOUND") {
2855 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'",
null,
'warnings');
2857 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'",
null,
'errors');
2858 $error_occurred =
true;
2865 $supplier_price =
price($result_product[
"product"][
"price_net"]);
2866 $local_price =
null;
2869 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2870 if (count($product_fourn_list) > 0) {
2871 foreach ($product_fourn_list as $product_fourn_line) {
2873 if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2874 $local_price =
price($product_fourn_line->fourn_price);
2879 if ($local_price !=
null && $local_price != $supplier_price) {
2880 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price,
null,
'warnings');
2884 if (empty($result_product[
"product"][
"status_tosell"])) {
2885 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'",
null,
'warnings');
2889 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
2890 setEventMessages($langs->trans(
"RemoteUserNotPermission"),
null,
'errors');
2891 $error_occurred =
true;
2892 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
2893 setEventMessages($langs->trans(
"RemoteUserBadCredentials"),
null,
'errors');
2894 $error_occurred =
true;
2896 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'",
null,
'errors');
2897 $error_occurred =
true;
2901 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2902 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2903 print
'<input type="hidden" name="action" value="webservice">';
2904 print
'<input type="hidden" name="mode" value="send">';
2905 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
2906 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
2907 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
2908 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
2909 if ($error_occurred) {
2910 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2912 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
2913 print
' ';
2915 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2921 if (
GETPOST(
'modelselected')) {
2922 $action =
'presend';
2926 $modelmail =
'order_supplier_send';
2927 $defaulttopic =
'SendOrderRef';
2928 $diroutput = $conf->fournisseur->commande->dir_output;
2929 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
2930 $trackid =
'sord'.$object->id;
2932 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';