34 require
'../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
44 if (!empty($conf->supplier_proposal->enabled))
45 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
46 if (!empty($conf->product->enabled))
47 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
48 if (!empty($conf->projet->enabled)) {
49 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
52 require_once NUSOAP_PATH.
'/nusoap.php';
54 if (!empty($conf->variants->enabled)) {
55 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
58 $langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
59 if (!empty($conf->incoterm->enabled)) $langs->load(
'incoterm');
63 $action =
GETPOST(
'action',
'alpha');
64 $confirm =
GETPOST(
'confirm',
'alpha');
65 $socid =
GETPOST(
'socid',
'int');
66 $projectid =
GETPOST(
'projectid',
'int');
67 $cancel =
GETPOST(
'cancel',
'alpha');
68 $lineid =
GETPOST(
'lineid',
'int');
70 $lineid =
GETPOST(
'lineid',
'int');
71 $origin =
GETPOST(
'origin',
'alpha');
75 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
76 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
77 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
79 $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'));
83 if ($user->socid) $socid = $user->socid;
84 $result =
restrictedArea($user,
'fournisseur', $id,
'commande_fournisseur',
'commande');
87 $hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
93 $extrafields->fetch_name_optionals_label($object->table_element);
96 if ($id > 0 || !empty($ref))
98 $ret = $object->fetch($id, $ref);
100 $ret = $object->fetch_thirdparty();
102 } elseif (!empty($socid) && $socid > 0)
105 $ret = $fourn->fetch($socid);
107 $object->socid = $fourn->id;
108 $ret = $object->fetch_thirdparty();
113 $usercanread = $user->rights->fournisseur->commande->lire;
114 $usercancreate = $user->rights->fournisseur->commande->creer;
115 $usercandelete = $user->rights->fournisseur->commande->supprimer;
118 $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)));
121 $usercanapprove = $user->rights->fournisseur->commande->approuver;
122 $usercanapprovesecond = $user->rights->fournisseur->commande->approve2;
123 $usercanorder = $user->rights->fournisseur->commande->commander;
124 $usercanreceived = $user->rights->fournisseur->commande->receptionner;
127 $permissionnote = $usercancreate;
128 $permissiondellink = $usercancreate;
129 $permissiontoedit = $usercancreate;
130 $permissiontoadd = $usercancreate;
137 $parameters = array(
'socid'=>$socid);
138 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
139 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
145 if (!empty($backtopage))
147 header(
"Location: ".$backtopage);
153 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
155 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
157 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
159 if ($action ==
'setref_supplier' && $usercancreate)
161 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'', null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
162 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
166 if ($action ==
'set_incoterms' && $usercancreate)
168 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
169 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
173 if ($action ==
'setconditions' && $usercancreate)
175 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
176 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
180 if ($action ==
'setmode' && $usercancreate)
182 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
183 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
187 elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
188 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
192 elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
193 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
197 if ($action ==
'setbankaccount' && $usercancreate)
199 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
200 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
204 if ($action ==
'setdate_livraison' && $usercancreate)
206 $result = $object->setDeliveryDate($user, $datelivraison);
207 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
211 if ($action ==
'classin' && $usercancreate)
213 $result = $object->setProject($projectid);
214 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
218 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action ==
'set_thirdparty' && $usercancreate && $object->statut ==
CommandeFournisseur::STATUS_DRAFT)
220 $new_socid =
GETPOST(
'new_socid',
'int');
221 if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
225 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
226 $sql .=
' SET fk_soc='.$new_socid;
227 $sql .=
' WHERE fk_soc='.$object->thirdparty->id;
228 $sql .=
' AND rowid='.$object->id;
230 $res = $db->query($sql);
232 if (!$res) $db->rollback();
237 foreach ($object->lines as $l) {
238 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
239 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
240 $sql .=
' WHERE fk_product='.$l->fk_product;
241 $sql .=
' AND fk_soc='.$new_socid;
242 $sql .=
' ORDER BY unitprice ASC';
244 $resql = $db->query($sql);
246 $num_row = $db->num_rows(
$resql);
247 if (empty($num_row)) {
253 $l->ref_supplier =
'';
257 $obj = $db->fetch_object(
$resql);
258 $l->subprice = $obj->unitprice;
259 $l->total_ht = $obj->price;
260 $l->tva_tx = $obj->tva_tx;
261 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
262 $l->total_ttc = $l->total_ht + $l->total_tva;
263 $l->ref_supplier = $obj->ref_fourn;
271 $object->update_price();
274 header(
'Location: '.
$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
278 if ($action ==
'setremisepercent' && $usercancreate)
280 $result = $object->set_remise($user, $_POST[
'remise_percent']);
281 if ($result < 0)
setEventMessages($object->error, $object->errors,
'errors');
284 if ($action ==
'reopen')
286 if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9)))
288 if ($object->statut == 1) $newstatus = 0;
289 elseif ($object->statut == 2) $newstatus = 0;
290 elseif ($object->
statut == 3) $newstatus = 2;
291 elseif ($object->
statut == 4) $newstatus = 3;
292 elseif ($object->
statut == 5)
299 } elseif ($object->statut == 6) $newstatus = 2;
300 elseif ($object->
statut == 7) $newstatus = 3;
301 elseif ($object->
statut == 9) $newstatus = 1;
307 $result = $object->setStatus($user, $newstatus);
311 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
312 $sql .=
' SET billed = 0';
313 $sql .=
' WHERE rowid = '.$object->id;
315 $resql = $db->query($sql);
319 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
320 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
321 $sql .=
' WHERE rowid = '.$object->id;
323 $resql = $db->query($sql);
328 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
341 if ($action ==
'classifybilled' && $usercancreate)
343 $ret = $object->classifyBilled($user);
350 if ($action ==
'addline' && $usercancreate)
354 $langs->load(
'errors');
362 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
363 if ($prod_entry_mode ==
'free')
369 $idprod =
GETPOST(
'idprod',
'int');
375 $remise_percent =
GETPOST(
'remise_percent'.$predef);
379 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
380 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
382 if (is_array($extralabelsline)) {
384 foreach ($extralabelsline as $key => $value) {
385 unset($_POST[
"options_".$key]);
389 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0)
391 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
394 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0)
396 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
399 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'')
401 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')), null,
'errors');
404 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc'))
406 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
409 if (
GETPOST(
'qty',
'int') ==
'')
411 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
415 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
416 if ($combinations =
GETPOST(
'combinations',
'array')) {
420 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
421 $idprod = $res->fk_product_child;
423 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
429 if ($prod_entry_mode !=
'free' && empty($error))
434 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') $idprod = -99;
437 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg))
440 $res = $productsupplier->fetch($idprod);
443 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER))
446 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
447 if ($productsupplier->fourn_socid != $socid)
449 $productsupplier->ref_supplier =
'';
452 $fksoctosearch = $object->thirdparty->id;
453 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
455 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0)
459 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
460 $res = $productsupplier->fetch($idprod);
465 $label = $productsupplier->label;
467 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
468 $outputlangs = $langs;
470 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
471 $newlang =
GETPOST(
'lang_id',
'aZ09');
473 $newlang = $object->thirdparty->default_lang;
474 if (!empty($newlang)) {
476 $outputlangs->setDefaultLang($newlang);
478 $desc = (!empty($productsupplier->multilangs [$outputlangs->defaultlang] [
"description"])) ? $productsupplier->multilangs [$outputlangs->defaultlang] [
"description"] : $productsupplier->description;
480 $desc = $productsupplier->description;
483 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
484 $desc = $productsupplier->desc_supplier;
487 if (trim($product_desc) != trim($desc)) $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
489 $type = $productsupplier->type;
490 if ($price_ht !=
'' || $price_ht_devise !=
'') {
491 $price_base_type =
'HT';
493 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
495 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
496 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
497 $pu = $productsupplier->fourn_pu;
500 $pu = $productsupplier->fourn_pu;
501 $pu_ht_devise = $productsupplier->fourn_multicurrency_unitprice;
507 $ref_supplier = $productsupplier->ref_supplier;
509 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
510 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
511 if (empty($tva_tx)) $tva_npr = 0;
512 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
513 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
515 if (empty($pu)) $pu = 0;
517 $result = $object->addline(
536 $productsupplier->fk_unit,
542 if ($idprod == -99 || $idprod == 0)
546 $langs->load(
"errors");
547 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")), null,
'errors');
553 $langs->load(
"errors");
554 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'errors');
556 } elseif (empty($error))
558 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
559 $tva_tx = str_replace(
'*',
'', $tva_tx);
560 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
561 $desc = $product_desc;
563 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
565 $fk_unit =
GETPOST(
'units',
'alpha');
567 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
572 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
573 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
575 if ($price_ht !==
'')
580 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
582 $price_base_type =
'HT';
583 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
585 $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);
589 if (!$error && $result > 0)
593 $ret = $object->fetch($object->id);
596 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
598 $outputlangs = $langs;
600 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
601 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
602 if (!empty($newlang)) {
604 $outputlangs->setDefaultLang($newlang);
606 $model = $object->model_pdf;
607 $ret = $object->fetch($id);
609 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
613 unset($_POST [
'prod_entry_mode']);
615 unset($_POST[
'qty']);
616 unset($_POST[
'type']);
617 unset($_POST[
'remise_percent']);
619 unset($_POST[
'price_ht']);
620 unset($_POST[
'multicurrency_price_ht']);
621 unset($_POST[
'price_ttc']);
622 unset($_POST[
'fourn_ref']);
623 unset($_POST[
'tva_tx']);
624 unset($_POST[
'label']);
625 unset($localtax1_tx);
626 unset($localtax2_tx);
627 unset($_POST[
'np_marginRate']);
628 unset($_POST[
'np_markRate']);
629 unset($_POST[
'dp_desc']);
630 unset($_POST[
'idprodfournprice']);
632 unset($_POST[
'date_starthour']);
633 unset($_POST[
'date_startmin']);
634 unset($_POST[
'date_startsec']);
635 unset($_POST[
'date_startday']);
636 unset($_POST[
'date_startmonth']);
637 unset($_POST[
'date_startyear']);
638 unset($_POST[
'date_endhour']);
639 unset($_POST[
'date_endmin']);
640 unset($_POST[
'date_endsec']);
641 unset($_POST[
'date_endday']);
642 unset($_POST[
'date_endmonth']);
643 unset($_POST[
'date_endyear']);
655 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha'))
664 $res = $line->fetch($lineid);
669 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
670 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0,
price2num(
GETPOST(
'qty',
'int')), $line->fk_product,
'none',
GETPOST(
'socid',
'int')) < 0) {
671 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'warnings');
680 if (preg_match(
'/\*/', $vat_rate)) {
685 $vat_rate = str_replace(
'*',
'', $vat_rate);
686 $localtax1_rate =
get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
687 $localtax2_rate =
get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
691 $price_base_type =
'HT';
694 $vatratecleaned = $vat_rate;
695 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg))
697 $vatratecleaned = trim($reg[1]);
698 $vatratecode = $reg[2];
702 $ht = $ttc / (1 + ($vatratecleaned / 100));
703 $price_base_type =
'HT';
709 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
710 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
712 if (is_array($extralabelsline)) {
713 foreach ($extralabelsline as $key => $value) {
714 unset($_POST[
"options_".$key]);
718 $result = $object->updateline(
720 $_POST[
'product_desc'],
723 $_POST[
'remise_percent'],
729 isset($_POST[
"type"]) ? $_POST[
"type"] : $line->product_type,
738 unset($_POST[
'qty']);
739 unset($_POST[
'type']);
740 unset($_POST[
'idprodfournprice']);
741 unset($_POST[
'remmise_percent']);
742 unset($_POST[
'dp_desc']);
743 unset($_POST[
'np_desc']);
745 unset($_POST[
'fourn_ref']);
746 unset($_POST[
'tva_tx']);
747 unset($_POST[
'date_start']);
748 unset($_POST[
'date_end']);
749 unset($_POST[
'units']);
750 unset($localtax1_tx);
751 unset($localtax2_tx);
753 unset($_POST[
'date_starthour']);
754 unset($_POST[
'date_startmin']);
755 unset($_POST[
'date_startsec']);
756 unset($_POST[
'date_startday']);
757 unset($_POST[
'date_startmonth']);
758 unset($_POST[
'date_startyear']);
759 unset($_POST[
'date_endhour']);
760 unset($_POST[
'date_endmin']);
761 unset($_POST[
'date_endsec']);
762 unset($_POST[
'date_endday']);
763 unset($_POST[
'date_endmonth']);
764 unset($_POST[
'date_endyear']);
769 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
771 $outputlangs = $langs;
773 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
774 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
775 if (!empty($newlang)) {
777 $outputlangs->setDefaultLang($newlang);
779 $model = $object->model_pdf;
780 $ret = $object->fetch($id);
782 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
796 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate)
800 $result = $object->deleteline($lineid);
804 $outputlangs = $langs;
806 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
807 $newlang =
GETPOST(
'lang_id',
'aZ09');
808 if ($conf->global->MAIN_MULTILANGS && empty($newlang))
809 $newlang = $object->thirdparty->default_lang;
810 if (!empty($newlang)) {
812 $outputlangs->setDefaultLang($newlang);
814 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
815 $ret = $object->fetch($object->id);
816 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
828 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
836 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate)
840 $object->date_commande =
dol_now();
841 $result = $object->valid($user);
845 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
847 $outputlangs = $langs;
849 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
850 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
851 if (!empty($newlang)) {
853 $outputlangs->setDefaultLang($newlang);
855 $model = $object->model_pdf;
856 $ret = $object->fetch($id);
858 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
870 if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
872 $action =
'confirm_approve';
882 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove)
886 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
888 $qualified_for_stock_change = 0;
889 if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
891 $qualified_for_stock_change = $object->hasProductsOrServices(2);
893 $qualified_for_stock_change = $object->hasProductsOrServices(1);
897 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
899 if (!$idwarehouse || $idwarehouse == -1)
902 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
909 $result = $object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
912 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
913 $outputlangs = $langs;
915 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
916 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
917 if (!empty($newlang)) {
919 $outputlangs->setDefaultLang($newlang);
921 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
932 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
939 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove)
941 $result = $object->refuse($user);
944 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
952 if ($action ==
'commande') {
953 $methodecommande =
GETPOST(
'methodecommande',
'int');
955 if ($methodecommande <= 0) {
956 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")), null,
'errors');
957 $action =
'makeorder';
961 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder)
965 $result = $object->commande($user,
GETPOST(
"datecommande"),
GETPOST(
"methode",
'int'),
GETPOST(
'comment',
'alphanohtml'));
968 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
970 $outputlangs = $langs;
972 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
973 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
974 if (!empty($newlang)) {
976 $outputlangs->setDefaultLang($newlang);
978 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
989 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
997 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete)
999 $result = $object->delete($user);
1002 header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
1010 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate)
1012 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers'))
1014 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"), null,
'errors');
1016 if ($object->id > 0)
1018 $orig = clone $object;
1020 $result = $object->createFromClone($user, $socid);
1023 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?id='.$result);
1035 if ($action ==
'livraison' && $usercanreceived)
1043 $result = $object->Livraison($user, $date_liv,
GETPOST(
"type"),
GETPOST(
"comment"));
1046 $langs->load(
"deliveries");
1049 } elseif ($result == -3)
1059 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")), null,
'errors');
1069 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder)
1071 $result = $object->cancel($user);
1074 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1082 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1085 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1086 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1087 $trackid =
'sord'.$object->id;
1088 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1091 $upload_dir = $conf->fournisseur->commande->dir_output;
1092 $permissiontoadd = $usercancreate;
1093 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1096 if ($action ==
'update_extras')
1101 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
1102 if ($ret < 0) $error++;
1109 $result = $object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
1119 $action =
'edit_extras';
1125 if ($action ==
'add' && $usercancreate)
1128 $selectedLines =
GETPOST(
'toselect',
'array');
1131 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')), null,
'errors');
1141 $object->ref_supplier =
GETPOST(
'refsupplier');
1142 $object->socid = $socid;
1143 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
1144 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
1145 $object->fk_account =
GETPOST(
'fk_account',
'int');
1146 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
1147 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
1148 $object->date_livraison = $datelivraison;
1149 $object->delivery_date = $datelivraison;
1150 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1151 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1152 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1153 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
1154 $object->fk_project =
GETPOST(
'projectid');
1159 $ret = $extrafields->setOptionalsFromPost(null, $object);
1160 if ($ret < 0) $error++;
1166 if (!empty($origin) && !empty($originid))
1168 if ($origin ==
'propal' || $origin ==
'proposal')
1170 $classname =
'Propal';
1171 $element =
'comm/propal'; $subelement =
'propal';
1172 } elseif ($origin ==
'order' || $origin ==
'commande')
1174 $classname =
'Commande';
1175 $element = $subelement =
'commande';
1177 $classname =
'SupplierProposal';
1178 $element =
'supplier_proposal';
1179 $subelement =
'supplier_proposal';
1182 $object->origin = $origin;
1183 $object->origin_id = $originid;
1186 $object->linked_objects [$object->origin] = $object->origin_id;
1187 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1188 if (!empty($other_linked_objects)) {
1189 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
1192 $id = $object->create($user);
1197 $srcobject =
new $classname($db);
1199 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
1200 $result = $srcobject->fetch($object->origin_id);
1203 $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
1204 $object->setDeliveryDate($user, $tmpdate);
1205 $object->set_id_projet($user, $srcobject->fk_project);
1207 $lines = $srcobject->lines;
1208 if (empty($lines) && method_exists($srcobject,
'fetch_lines'))
1210 $srcobject->fetch_lines();
1211 $lines = $srcobject->lines;
1214 $fk_parent_line = 0;
1215 $num = count($lines);
1217 for ($i = 0; $i < $num; $i++)
1219 if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines))
1222 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1223 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
1224 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1227 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1228 $fk_parent_line = 0;
1232 if (method_exists($lines[$i],
'fetch_optionals'))
1234 $lines[$i]->fetch_optionals();
1235 $array_option = $lines[$i]->array_options;
1239 $product_fourn_price_id = 0;
1240 if ($origin ==
"commande")
1243 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
1246 $ref_supplier = $productsupplier->ref_supplier;
1247 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1250 $ref_supplier = $lines[$i]->ref_fourn;
1251 $product_fourn_price_id = 0;
1254 $tva_tx = $lines[$i]->tva_tx;
1256 if ($origin ==
"commande")
1258 $soc =
new societe($db);
1259 $soc->fetch($socid);
1260 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1263 $result = $object->addline(
1265 $lines[$i]->subprice,
1268 $lines[$i]->localtax1_tx,
1269 $lines[$i]->localtax2_tx,
1270 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1271 $product_fourn_price_id,
1273 $lines[$i]->remise_percent,
1276 $lines[$i]->product_type,
1282 $lines[$i]->fk_unit,
1285 !empty($lines[$i]->
id) ? $lines[$i]->
id : $lines[$i]->
rowid
1294 if ($result > 0 && $lines[$i]->product_type == 9) {
1295 $fk_parent_line = $result;
1303 $parameters = array(
'objFrom' => $srcobject);
1304 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1317 $id = $object->create($user);
1328 $langs->load(
"errors");
1331 $_GET[
'socid'] = $_POST[
'socid'];
1334 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$id);
1340 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') ==
"send" && !
GETPOST(
'cancel',
'alpha'))
1342 $ws_url = $object->thirdparty->webservices_url;
1343 $ws_key = $object->thirdparty->webservices_key;
1344 $ws_user =
GETPOST(
'ws_user',
'alpha');
1345 $ws_password =
GETPOST(
'ws_password',
'alpha');
1346 $ws_entity =
GETPOST(
'ws_entity',
'int');
1347 $ws_thirdparty =
GETPOST(
'ws_thirdparty',
'int');
1350 $ws_ns =
'http://www.dolibarr.org/ns/';
1351 $ws_authentication = array(
1352 'dolibarrkey'=>$ws_key,
1353 'sourceapplication'=>
'DolibarrWebServiceClient',
1355 'password'=>$ws_password,
1356 'entity'=>$ws_entity
1360 if (empty($conf->syncsupplierwebservices->enabled)) {
1361 setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2650Name")), null,
'mesgs');
1362 } elseif (empty($ws_url) || empty($ws_key)) {
1363 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), null,
'errors');
1364 } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1368 $soapclient_order =
new nusoap_client($ws_url.
"/webservices/server_order.php");
1369 $soapclient_order->soap_defencoding =
'UTF-8';
1370 $soapclient_order->decodeUTF8(
false);
1373 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
1374 $soapclient_product->soap_defencoding =
'UTF-8';
1375 $soapclient_product->decodeUTF8(
false);
1378 $order_lines = array();
1379 foreach ($object->lines as $line)
1381 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $line->ref_supplier);
1382 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
1384 if ($result_product[
"result"][
"result_code"] ==
"OK")
1386 $order_lines[] = array(
1387 'desc' => $line->product_desc,
1388 'type' => $line->product_type,
1389 'product_id' => $result_product[
"product"][
"id"],
1390 'vat_rate' => $line->tva_tx,
1391 'qty' => $line->qty,
1392 'price' => $line->price,
1393 'unitprice' => $line->subprice,
1394 'total_net' => $line->total_ht,
1395 'total_vat' => $line->total_tva,
1396 'total' => $line->total_ttc,
1397 'date_start' => $line->date_start,
1398 'date_end' => $line->date_end,
1405 'thirdparty_id' => $ws_thirdparty,
1407 'total_net' => $object->total_ht,
1408 'total_var' => $object->total_tva,
1409 'total' => $object->total_ttc,
1410 'lines' => $order_lines
1413 $ws_parameters = array(
'authentication'=>$ws_authentication,
'order' => $order);
1414 $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns,
'');
1416 if (empty($result_order[
"result"][
"result_code"]))
1418 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", null,
'errors');
1419 } elseif ($result_order[
"result"][
"result_code"] !=
"OK")
1421 setEventMessages($langs->trans(
"SOAPError").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'", null,
'errors');
1423 setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"], null,
'mesgs');
1428 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate)
1430 if ($action ==
'addcontact')
1432 if ($object->id > 0)
1436 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1441 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1444 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
1446 $langs->load(
"errors");
1447 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
1455 elseif ($action ==
'swapstatut' && $object->id > 0)
1457 $result = $object->swapContactStatus(
GETPOST(
'ligne'));
1461 elseif ($action ==
'deletecontact' && $object->id > 0)
1463 $result = $object->delete_contact($_GET[
"lineid"]);
1467 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1481 $form =
new Form($db);
1484 $productstatic =
new Product($db);
1485 if (!empty($conf->projet->enabled)) { $formproject =
new FormProjets($db); }
1487 $help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1488 llxHeader(
'', $langs->trans(
"Order"), $help_url);
1492 if ($action ==
'create')
1498 $currency_code = $conf->currency;
1504 $societe->fetch($socid);
1507 if (!empty($origin) && !empty($originid))
1510 $element = $subelement = $origin;
1512 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1513 $element = $regs[1];
1514 $subelement = $regs[2];
1517 if ($origin ==
'propal' || $origin ==
'proposal')
1519 $classname =
'Propal';
1520 $element =
'comm/propal'; $subelement =
'propal';
1521 } elseif ($origin ==
'order' || $origin ==
'commande')
1523 $classname =
'Commande';
1524 $element = $subelement =
'commande';
1526 $classname =
'SupplierProposal';
1527 $element =
'supplier_proposal';
1528 $subelement =
'supplier_proposal';
1533 $objectsrc =
new $classname($db);
1534 $objectsrc->fetch($originid);
1535 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines'))
1536 $objectsrc->fetch_lines();
1537 $objectsrc->fetch_thirdparty();
1540 $objectsrc->fetch_optionals();
1541 $object->array_options = $objectsrc->array_options;
1543 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1544 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1546 $soc = $objectsrc->client;
1547 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1548 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1549 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1550 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1551 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1552 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1553 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1554 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1555 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1557 $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
''));
1559 if (!empty($conf->multicurrency->enabled))
1561 if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
1562 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
1565 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1566 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1569 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1571 $cond_reglement_id = $societe->cond_reglement_supplier_id;
1572 $mode_reglement_id = $societe->mode_reglement_supplier_id;
1574 if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code;
1576 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1577 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1581 if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
1582 if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
1584 print '<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1585 print '<input type="hidden" name="token" value="'.newToken().
'">';
1586 print '<input type="hidden" name="action" value="add">';
1587 print '<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1588 print '<input type="hidden" name="remise_percent" value="'.$soc->remise_supplier_percent.
'">';
1589 print '<input type="hidden" name="origin" value="'.$origin.
'">';
1590 print '<input type="hidden" name="originid" value="'.$originid.
'">';
1591 if (!empty($currency_tx))
print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1595 print '<table class="border centpercent">';
1598 print '<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1601 print '<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1606 print $societe->getNomUrl(1);
1607 print '<input type="hidden" name="socid" value="'.$socid.
'">';
1609 print img_picto(
'',
'company').$form->select_company((empty($socid) ?
'' : $socid),
'socid',
's.fournisseur=1',
'SelectThirdParty', 0, 0, null, 0,
'minwidth300');
1611 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE))
1614 $(document).ready(function() {
1615 $("#socid").change(function() {
1616 var socid = $(this).val();
1618 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid;
1623 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>';
1627 if ($societe->id > 0)
1630 print '<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1632 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
1634 $thirdparty = $societe;
1636 $backtopage = urlencode(
$_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1637 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1643 print '<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1647 print '<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1648 $form->select_conditions_paiements(isset($_POST[
'cond_reglement_id']) ? $_POST[
'cond_reglement_id'] : $cond_reglement_id,
'cond_reglement_id');
1652 print '<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1653 $form->select_types_paiements(isset($_POST[
'mode_reglement_id']) ? $_POST[
'mode_reglement_id'] : $mode_reglement_id,
'mode_reglement_id');
1658 print $langs->trans(
'DateDeliveryPlanned');
1662 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin = 1;
1663 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin,
'',
"set");
1667 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled))
1669 $langs->load(
"bank");
1670 print '<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1672 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
1677 if (!empty($conf->projet->enabled))
1681 $langs->load(
'projects');
1682 print '<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1683 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');
1684 print ' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode(
$_SERVER[
"PHP_SELF"].
'?action=create&socid='.$societe->id).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
1689 if (!empty($conf->incoterm->enabled))
1691 $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1692 $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1694 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $object->label_incoterms, 1).
'</label></td>';
1695 print '<td class="maxwidthonsmartphone">';
1696 print $form->select_incoterms($fkincoterms, $locincoterms);
1701 if (!empty($conf->multicurrency->enabled))
1704 print '<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1705 print '<td class="maxwidthonsmartphone">';
1706 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
1710 print '<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
1712 $doleditor =
new DolEditor(
'note_public', isset($note_public) ? $note_public :
GETPOST(
'note_public',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1713 print $doleditor->Create(1);
1718 print '<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
1720 $doleditor =
new DolEditor(
'note_private', isset($note_private) ? $note_private :
GETPOST(
'note_private',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1721 print $doleditor->Create(1);
1726 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1727 print "\n<!-- ".$classname.
" info -->";
1729 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1730 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1731 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1732 print '<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1733 print '<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1735 $newclassname = $classname;
1736 print '<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1737 print '<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1738 print '<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1739 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0)
1741 print '<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1744 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0)
1746 print '<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1749 print '<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1751 if (!empty($conf->multicurrency->enabled))
1753 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1754 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
1755 print '<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
1760 $parameters = array();
1761 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1762 print $hookmanager->resPrint;
1764 if (empty($reshook))
1766 print $object->showOptionals($extrafields,
'edit');
1774 print '<div class="center">';
1775 print '<input type="submit" class="button" name="bouton" value="'.$langs->trans(
'CreateDraft').
'">';
1776 print ' ';
1777 print '<input type="button" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'" onClick="javascript:history.go(-1)">';
1783 if (!empty($origin) && !empty($originid) && is_object($objectsrc))
1785 $title = $langs->trans(
'ProductsAndServices');
1788 print '<table class="noborder centpercent">';
1790 $objectsrc->printOriginLinesList(
'', $selectedLines);
1795 } elseif (!empty($object->id)) {
1796 $result = $object->fetch($id, $ref);
1799 $result = $societe->fetch($object->socid);
1802 $author =
new User($db);
1803 $author->fetch($object->user_author_id);
1805 $res = $object->fetch_optionals();
1810 $title = $langs->trans(
"SupplierOrder");
1817 if ($action ==
'delete')
1819 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 2);
1823 if ($action ==
'clone')
1826 $formquestion = array(
1827 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.fournisseur=1)'))
1830 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1834 if ($action ==
'valid')
1836 $object->date_commande =
dol_now();
1839 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref))
1841 $newref = $object->getNextNumRef($object->thirdparty);
1842 }
else $newref = $object->ref;
1849 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
1850 if (!empty($conf->notification->enabled))
1852 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1853 $notify =
new Notify($db);
1855 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
1858 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
1863 if ($action ==
'approve' || $action ==
'approve2')
1865 $qualified_for_stock_change = 0;
1866 if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
1868 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1870 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1873 $formquestion = array();
1874 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
1876 $langs->load(
"stocks");
1877 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1880 if ($conf->browser->name ==
'ie') $forcecombo = 1;
1881 $formquestion = array(
1885 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse',
'int'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
1888 $text = $langs->trans(
"ConfirmApproveThisOrder", $object->ref);
1889 if (!empty($conf->notification->enabled))
1891 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1892 $notify =
new Notify($db);
1894 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE', $object->socid, $object);
1897 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
1901 if ($action ==
'refuse')
1903 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder", $object->ref),
"confirm_refuse",
'', 0, 1);
1907 if ($action ==
'cancel')
1909 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder", $object->ref),
"confirm_cancel",
'', 0, 1);
1913 if ($action ==
'commande')
1916 $formconfirm = $form->formconfirm(
$_SERVER[
'PHP_SELF'].
"?id=".$object->id.
"&datecommande=".$date_com.
"&methode=".$_POST[
"methodecommande"].
"&comment=".urlencode($_POST[
"comment"]), $langs->trans(
"MakeOrder"), $langs->trans(
"ConfirmMakeOrder",
dol_print_date($date_com,
'day')),
"confirm_commande",
'', 0, 2);
1920 if ($action ==
'ask_deleteline')
1922 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
1925 $parameters = array(
'formConfirm' => $formconfirm,
'lineid'=>$lineid);
1926 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1927 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
1928 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
1936 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1938 $morehtmlref = '<div class="refidno">';
1940 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, '
string', '', 0, 1);
1941 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, '
string', '', null, null, '', 1);
1943 $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
1944 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action == 'edit_thirdparty') {
1945 $morehtmlref .=
' : ';
1946 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
1947 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
1948 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1949 $morehtmlref .= $form->select_company($object->thirdparty->id,
'new_socid',
's.fournisseur=1',
'', 0, 0, array(), 0,
'minwidth300');
1950 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
1951 $morehtmlref .=
'</form>';
1953 if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action !=
'edit_thirdparty') {
1955 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
1957 $morehtmlref .=
' : '.$object->thirdparty->getNomUrl(1);
1958 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
1962 if (!empty($conf->projet->enabled)) {
1963 $langs->load(
"projects");
1964 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
1965 if ($usercancreate) {
1966 if ($action !=
'classify')
1967 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
1968 if ($action ==
'classify') {
1970 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
1971 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
1972 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1973 $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project,
'projectid', 0, 0, 1, 0, 1, 0, 0,
'', 1, 0,
'maxwidth500');
1974 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
1975 $morehtmlref .=
'</form>';
1977 $morehtmlref .= $form->form_project(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
1980 if (!empty($object->fk_project)) {
1982 $proj->fetch($object->fk_project);
1983 $morehtmlref .=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$object->fk_project.
'" title="'.$langs->trans(
'ShowProject').
'">';
1984 $morehtmlref .= $proj->ref;
1985 $morehtmlref .=
'</a>';
1991 $morehtmlref .=
'</div>';
1994 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1997 print '<div class="fichecenter">';
1998 print '<div class="fichehalfleft">';
1999 print '<div class="underbanner clearboth"></div>';
2001 print '<table class="border tableforfield centpercent">';
2004 if ($object->methode_commande_id > 0)
2006 print '<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2008 if ($object->hasDelay() && !empty($object->date_delivery) && !empty($object->date_commande)) {
2009 print ' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2013 if ($object->methode_commande)
2015 print '<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
2020 print '<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2021 print '<td>'.$author->getNomUrl(1,
'', 0, 0, 0).
'</td>';
2025 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2026 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2027 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2029 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2030 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2033 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2034 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2035 $absolute_discount =
price2num($absolute_discount,
'MT');
2036 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2038 print '<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2040 $thirdparty = $societe;
2042 $backtopage = urlencode(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2043 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2048 $langs->load(
'bills');
2049 print '<tr><td class="nowrap">';
2050 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2051 print $langs->trans(
'PaymentConditions');
2053 if ($action !=
'editconditions')
print '<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
2054 print '</tr></table>';
2056 if ($action ==
'editconditions')
2058 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
2060 $form->form_conditions_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
2066 $langs->load(
'bills');
2067 print
'<tr><td class="nowrap">';
2068 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2069 print $langs->trans(
'PaymentMode');
2071 if ($action !=
'editmode') print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
2072 print
'</tr></table>';
2074 if ($action ==
'editmode')
2076 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2078 $form->form_modes_reglement(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2083 if (!empty($conf->multicurrency->enabled))
2088 print
'<table class="nobordernopadding centpercent"><tr><td>';
2089 print $form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2091 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT)
2092 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2093 print
'</tr></table>';
2095 if ($action ==
'editmulticurrencycode') {
2096 $form->form_multicurrency_code(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2098 $form->form_multicurrency_code(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2103 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
2107 print
'<table class="nobordernopadding centpercent"><tr>';
2109 print $form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2111 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
2112 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2113 print
'</tr></table>';
2115 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2116 if ($action ==
'actualizemulticurrencyrate') {
2119 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2121 $form->form_multicurrency_rate(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2122 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2123 print
'<div class="inline-block"> ';
2124 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2133 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled))
2135 print
'<tr><td class="nowrap">';
2136 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2137 print $langs->trans(
'BankAccount');
2139 if ($action !=
'editbankaccount' && $usercancreate)
2140 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
2141 print
'</tr></table>';
2143 if ($action ==
'editbankaccount') {
2144 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2146 $form->formSelectAccount(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2154 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2155 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2160 print
'<table class="nobordernopadding centpercent"><tr><td>';
2161 print $langs->trans(
'DateDeliveryPlanned');
2163 if ($action !=
'editdate_livraison') print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_livraison&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetDeliveryDate'), 1).
'</a></td>';
2164 print
'</tr></table>';
2166 if ($action ==
'editdate_livraison')
2168 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2169 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2170 print
'<input type="hidden" name="action" value="setdate_livraison">';
2172 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin = 1;
2173 print $form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin,
'',
"setdate_livraison");
2174 print
'<input type="submit" class="button" value="'.$langs->trans(
'Modify').
'">';
2177 $usehourmin =
'day';
2178 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin =
'dayhour';
2179 print $object->delivery_date ?
dol_print_date($object->delivery_date, $usehourmin) :
' ';
2180 if ($object->hasDelay() && !empty($object->delivery_date)) {
2181 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2187 if (!empty($conf->incoterm->enabled))
2190 print
'<table class="nobordernopadding centpercent"><tr><td>';
2191 print $langs->trans(
'IncotermLabel');
2192 print
'<td><td class="right">';
2193 if ($usercancreate) print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$object->id.
'&action=editincoterm">'.
img_edit().
'</a>';
2194 else print
' ';
2195 print
'</td></tr></table>';
2198 if ($action !=
'editincoterm')
2200 print $form->textwithpicto(
dol_escape_htmltag($object->display_incoterms()), $object->label_incoterms, 1);
2202 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''),
$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2208 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2213 print
'<div class="fichehalfright">';
2214 print
'<div class="ficheaddleft">';
2215 print
'<div class="underbanner clearboth"></div>';
2217 print
'<table class="border tableforfield centpercent">';
2219 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
2222 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2223 print
'<td class="nowrap">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2227 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2228 print
'<td class="nowrap">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2232 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2233 print
'<td class="nowrap">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2239 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
2240 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->supplier_order_min_amount));
2242 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
2243 print
'<td>'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).$alert.
'</td>';
2247 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td><td>'.
price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2251 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0)
2253 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2254 print
'<td>'.price($object->total_localtax1,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2257 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0)
2259 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2260 print
'<td>'.price($object->total_localtax2,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2265 print
'<tr><td>'.$langs->trans(
"AmountTTC").
'</td><td>'.
price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2280 print
'<div class="clearboth"></div><br>';
2282 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
2284 $blocname =
'contacts';
2285 $title = $langs->trans(
'ContactsAddresses');
2286 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2289 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB))
2291 $blocname =
'notes';
2292 $title = $langs->trans(
'Notes');
2293 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2302 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#addline' :
'#line_'.
GETPOST(
'lineid')).
'" method="POST">
2303 <input type="hidden" name="token" value="'.
newToken().
'">
2304 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2305 <input type="hidden" name="mode" value="">
2306 <input type="hidden" name="id" value="'.$object->id.
'">
2307 <input type="hidden" name="socid" value="'.$societe->id.
'">
2310 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
2311 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2314 print
'<div class="div-table-responsive-no-min">';
2315 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2318 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2319 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
2320 $senderissupplier = 2;
2321 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier = 1;
2324 if (!empty($object->lines))
2325 $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
2327 $num = count($object->lines);
2332 if ($action !=
'editline')
2335 $object->formAddObjectLine(1, $societe, $mysoc);
2337 $parameters = array();
2338 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2351 if ($user->socid == 0 && $action !=
'editline' && $action !=
'delete')
2353 print
'<div class="tabsAction">';
2355 $parameters = array();
2356 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2358 if (empty($reshook))
2360 $object->fetchObjectLinked();
2363 if ($object->statut == 0 && $num > 0)
2365 if ($usercanvalidate)
2367 $tmpbuttonlabel = $langs->trans(
'Validate');
2368 if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2370 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid">';
2371 print $tmpbuttonlabel;
2386 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen">'.$langs->trans(
"Modify").
'</a>';
2393 if ($usercanapprove)
2395 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))
2397 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2399 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2402 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2407 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)
2411 if ($usercanapprovesecond)
2413 if (!empty($object->user_approve_id2))
2415 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2417 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2420 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2428 if ($usercanapprove || $usercanapprovesecond)
2430 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2432 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2437 if (empty($user->socid)) {
2442 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2451 if (!$buttonshown && $usercanapprove)
2453 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
2454 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id))
2456 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen">'.$langs->trans(
"Disapprove").
'</a>';
2460 if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
2462 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
2463 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2))
2465 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen">'.$langs->trans(
"Disapprove").
'</a>';
2469 if (in_array($object->statut, array(3, 4, 5, 6, 7, 9)))
2473 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen">'.$langs->trans(
"ReOpen").
'</a>';
2479 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)))
2481 $labelofbutton = $langs->trans(
'ReceiveProducts');
2482 if ($conf->reception->enabled) $labelofbutton = $langs->trans(
"CreateReception");
2484 if (in_array($object->statut, array(3, 4, 5))) {
2485 if ($conf->fournisseur->enabled && $usercanreceived) {
2486 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.$object->id.
'">'.$labelofbutton.
'</a></div>';
2488 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2497 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=makeorder#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
2499 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2506 if ($usercanreceived)
2508 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifyreception#classifyreception">'.$langs->trans(
"ClassifyReception").
'</a></div>';
2515 if (!empty($conf->fournisseur->enabled) && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1))
2517 if ($user->rights->fournisseur->facture->creer)
2519 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>';
2525 if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1)
2527 if (empty($conf->facture->enabled))
2529 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled">'.$langs->trans(
"ClassifyBilled").
'</a>';
2531 if (!empty($object->linkedObjectsIds[
'invoice_supplier']))
2533 if ($user->rights->fournisseur->facture->creer)
2535 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled">'.$langs->trans(
"ClassifyBilled").
'</a>';
2538 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2544 if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2)
2546 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=webservice&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
2552 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=order">'.$langs->trans(
"ToClone").
'</a>';
2556 if ($object->statut == 2)
2560 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel">'.$langs->trans(
"CancelOrder").
'</a>';
2567 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2578 print
'<!-- form to record supplier order -->'.
"\n";
2579 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2581 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2582 print
'<input type="hidden" name="action" value="commande">';
2584 print
'<table class="noborder centpercent">';
2586 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2587 $date_com =
dol_mktime(
GETPOST(
'rehour',
'int'),
GETPOST(
'remin',
'int'),
GETPOST(
'resec',
'int'),
GETPOST(
'remonth',
'int'),
GETPOST(
'reday',
'int'),
GETPOST(
'reyear',
'int'));
2588 if (empty($date_com)) $date_com =
dol_now();
2589 print $form->selectDate($date_com,
'', 1, 1,
'',
"commande", 1, 1);
2593 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2594 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2597 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2598 print
'<tr><td class="center" colspan="2">';
2599 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2600 print
' ';
2601 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2609 if ($action !=
'makeorder')
2611 print
'<div class="fichecenter"><div class="fichehalfleft">';
2615 $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2616 $relativepath = $objref.
'/'.$objref.
'.pdf';
2617 $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
2618 $urlsource =
$_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2619 $genallowed = $usercanread;
2620 $delallowed = $usercancreate;
2622 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 0, 0,
'',
'',
'', $object->thirdparty->default_lang);
2623 $somethingshown = $formfile->numoffiles;
2626 $linktoelem = $form->showLinkToObjectBlock($object, null, array(
'supplier_order',
'order_supplier'));
2627 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2629 print
'</div><div class="fichehalfright"><div class="ficheaddleft">';
2631 if ($action ==
'classifyreception')
2636 print
'<!-- form to record purchase order received -->'.
"\n";
2637 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2638 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2639 print
'<input type="hidden" name="action" value="livraison">';
2642 print
'<table class="noborder centpercent">';
2644 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2646 print $form->selectDate($datepreselected,
'', 1, 1,
'',
"commande", 1, 1);
2647 print
"</td></tr>\n";
2649 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2651 $liv[
''] =
' ';
2652 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2653 $liv[
'par'] = $langs->trans(
"PartialWoman");
2654 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2655 $liv[
'can'] = $langs->trans(
"Canceled");
2657 print $form->selectarray(
"type", $liv);
2660 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment"></td></tr>';
2661 print
'<tr><td class="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans(
"Receive").
'"></td></tr>';
2669 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2671 $somethingshown =
$formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2673 print
'</div></div></div>';
2679 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha'))
2681 $mode =
GETPOST(
'mode',
'alpha');
2682 $ws_url = $object->thirdparty->webservices_url;
2683 $ws_key = $object->thirdparty->webservices_key;
2684 $ws_user =
GETPOST(
'ws_user',
'alpha');
2685 $ws_password =
GETPOST(
'ws_password',
'alpha');
2688 $ws_ns =
'http://www.dolibarr.org/ns/';
2689 $ws_authentication = array(
2690 'dolibarrkey'=>$ws_key,
2691 'sourceapplication'=>
'DolibarrWebServiceClient',
2693 'password'=>$ws_password,
2700 if (empty($ws_url) || empty($ws_key)) {
2701 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), null,
'errors');
2703 $error_occurred =
true;
2704 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2709 if ($mode ==
"init")
2712 print
'<table class="border centpercent">';
2713 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2714 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2715 print
'<input type="hidden" name="action" value="webservice">';
2716 print
'<input type="hidden" name="mode" value="check">';
2718 if ($error_occurred)
2720 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2721 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2723 $textinput_size =
"50";
2725 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2727 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_user"></td></tr>';
2729 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_password"></td></tr>';
2731 print
'<tr><td class="center" colspan="2">';
2732 print
'<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2733 print
' ';
2735 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2742 } elseif ($mode ==
"check")
2745 $ws_thirdparty =
'';
2746 $error_occurred =
false;
2749 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2750 $soapclient_user->soap_defencoding =
'UTF-8';
2751 $soapclient_user->decodeUTF8(
false);
2754 $ws_parameters = array(
'authentication'=>$ws_authentication,
'id' =>
'',
'ref'=>$ws_user);
2755 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2756 $user_status_code = $result_user[
"result"][
"result_code"];
2758 if ($user_status_code ==
"OK")
2761 $ws_entity = $result_user[
"user"][
"entity"];
2762 $ws_authentication[
'entity'] = $ws_entity;
2763 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2764 if (empty($ws_thirdparty))
2766 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"), null,
'errors');
2767 $error_occurred =
true;
2770 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2771 $soapclient_product->soap_defencoding =
'UTF-8';
2772 $soapclient_product->decodeUTF8(
false);
2776 foreach ($object->lines as $line) {
2778 $ref_supplier = $line->ref_supplier;
2779 $line_id = $i.
"º) ".$line->product_ref.
": ";
2780 if (empty($ref_supplier)) {
2783 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2784 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2785 if (!$result_product)
2787 setEventMessages($line_id.$langs->trans(
"SOAPError").
" ".$soapclient_product->error_str.
" - ".$soapclient_product->response, null,
'errors');
2788 $error_occurred =
true;
2793 $status_code = $result_product[
"result"][
"result_code"];
2794 if (empty($status_code))
2796 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", null,
'errors');
2797 } elseif ($status_code !=
"OK")
2799 if ($status_code ==
"NOT_FOUND")
2801 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'", null,
'warnings');
2803 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'", null,
'errors');
2804 $error_occurred =
true;
2811 $supplier_price =
price($result_product[
"product"][
"price_net"]);
2812 $local_price = null;
2815 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2816 if (count($product_fourn_list) > 0)
2818 foreach ($product_fourn_list as $product_fourn_line)
2821 if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2822 $local_price =
price($product_fourn_line->fourn_price);
2827 if ($local_price != null && $local_price != $supplier_price) {
2828 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price, null,
'warnings');
2832 if (empty($result_product[
"product"][
"status_tosell"])) {
2833 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'", null,
'warnings');
2837 } elseif ($user_status_code ==
"PERMISSION_DENIED")
2839 setEventMessages($langs->trans(
"RemoteUserNotPermission"), null,
'errors');
2840 $error_occurred =
true;
2841 } elseif ($user_status_code ==
"BAD_CREDENTIALS")
2843 setEventMessages($langs->trans(
"RemoteUserBadCredentials"), null,
'errors');
2844 $error_occurred =
true;
2846 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'", null,
'errors');
2847 $error_occurred =
true;
2851 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2852 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2853 print
'<input type="hidden" name="action" value="webservice">';
2854 print
'<input type="hidden" name="mode" value="send">';
2855 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
2856 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
2857 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
2858 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
2859 if ($error_occurred)
2861 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2863 print
'<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
2864 print
' ';
2866 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2872 if (
GETPOST(
'modelselected')) {
2873 $action =
'presend';
2877 $modelmail =
'order_supplier_send';
2878 $defaulttopic =
'SendOrderRef';
2879 $diroutput = $conf->fournisseur->commande->dir_output;
2880 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
2881 $trackid =
'sord'.$object->id;
2883 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
const STATUS_ACCEPTED
Accepted.
const STATUS_DRAFT
Draft status.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
ordersupplier_prepare_head($object)
Prepare array with list of tabs.
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
dol_print_url($url, $target= '_blank', $max=32, $withpicto=0)
Show Url link.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
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...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
Class to manage suppliers.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
const STATUS_RECEIVED_PARTIALLY
Received partially.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_VALIDATED
Validated status.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_ORDERSENT
Order sent, shipment on process.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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) Si ...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage predefined suppliers products.
Class to manage line orders.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...