38 require
'../../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
46 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
47 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once NUSOAP_PATH.
'/nusoap.php';
62 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
67 $langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
69 $langs->load(
'incoterm');
76 $action =
GETPOST(
'action',
'alpha');
77 $confirm =
GETPOST(
'confirm',
'alpha');
78 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
79 $backtopage =
GETPOST(
'backtopage',
'alpha');
80 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
82 $socid =
GETPOST(
'socid',
'int');
83 $projectid =
GETPOST(
'projectid',
'int');
84 $cancel =
GETPOST(
'cancel',
'alpha');
85 $lineid =
GETPOST(
'lineid',
'int');
86 $origin =
GETPOST(
'origin',
'alpha');
88 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
91 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
92 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
93 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
95 $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'));
99 if (!empty($user->socid)) {
100 $socid = $user->socid;
104 $hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
110 $extrafields->fetch_name_optionals_label($object->table_element);
113 $socid = $user->socid;
117 if ($id > 0 || !empty($ref)) {
118 $ret = $object->fetch($id, $ref);
122 $ret = $object->fetch_thirdparty();
126 } elseif (!empty($socid) && $socid > 0) {
128 $ret = $fourn->fetch($socid);
132 $object->socid = $fourn->id;
133 $ret = $object->fetch_thirdparty();
140 $isdraft = (isset($object->statut) && ($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
141 $result =
restrictedArea($user,
'fournisseur', $id,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
144 $usercanread = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire);
145 $usercancreate = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
146 $usercandelete = (($user->rights->fournisseur->commande->supprimer || $user->rights->supplier_order->supprimer) || ($usercancreate && isset($object->statut) && $object->statut == $object::STATUS_DRAFT));
149 $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)));
152 $usercanapprove = !empty($user->rights->fournisseur->commande->approuver) ? $user->rights->fournisseur->commande->approuver : 0;
153 $usercanapprovesecond = !empty($user->rights->fournisseur->commande->approve2) ? $user->rights->fournisseur->commande->approve2 : 0;
154 $usercanorder = !empty($user->rights->fournisseur->commande->commander) ? $user->rights->fournisseur->commande->commander : 0;
155 if (empty($conf->reception->enabled)) {
156 $usercanreceive = $user->rights->fournisseur->commande->receptionner;
158 $usercanreceive = $user->rights->reception->creer;
162 $permissionnote = $usercancreate;
163 $permissiondellink = $usercancreate;
164 $permissiontoedit = $usercancreate;
165 $permissiontoadd = $usercancreate;
168 $caneditproject =
false;
170 $caneditproject = empty($conf->global->SUPPLIER_ORDER_FORBID_EDIT_PROJECT) || ($object->statut ==
CommandeFournisseur::STATUS_DRAFT && preg_match(
'/^[\(]?PROV/i', $object->ref));
181 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
186 if (empty($reshook)) {
187 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
189 if (empty($backtopage) || ($cancel && empty($id))) {
190 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
191 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
192 $backtopage = $backurlforlist;
194 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
200 if (!empty($backtopageforcancel)) {
201 header(
"Location: ".$backtopageforcancel);
203 } elseif (!empty($backtopage)) {
204 header(
"Location: ".$backtopage);
210 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
212 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
214 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
216 if ($action ==
'setref_supplier' && $usercancreate) {
217 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
224 if ($action ==
'set_incoterms' && $usercancreate) {
225 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
232 if ($action ==
'setconditions' && $usercancreate) {
233 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
240 if ($action ==
'setmode' && $usercancreate) {
241 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
245 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
247 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
248 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
250 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
254 if ($action ==
'setbankaccount' && $usercancreate) {
255 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
262 if ($action ==
'setdate_livraison' && $usercancreate) {
263 $result = $object->setDeliveryDate($user, $datelivraison);
270 if ($action ==
'classin' && $usercancreate && $caneditproject) {
271 $result = $object->setProject($projectid);
278 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action ==
'set_thirdparty' && $usercancreate && $object->statut ==
CommandeFournisseur::STATUS_DRAFT) {
279 $new_socid =
GETPOST(
'new_socid',
'int');
280 if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
284 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
285 $sql .=
' SET fk_soc = '.((int) $new_socid);
286 $sql .=
' WHERE fk_soc = '.((int) $object->thirdparty->id);
287 $sql .=
' AND rowid = '.((int) $object->id);
289 $res = $db->query($sql);
297 foreach ($object->lines as $l) {
298 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
299 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
300 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
301 $sql .=
' AND fk_soc = '.((int) $new_socid);
302 $sql .=
' ORDER BY unitprice ASC';
304 $resql = $db->query($sql);
306 $num_row = $db->num_rows(
$resql);
307 if (empty($num_row)) {
313 $l->ref_supplier =
'';
317 $obj = $db->fetch_object(
$resql);
318 $l->subprice = $obj->unitprice;
319 $l->total_ht = $obj->price;
320 $l->tva_tx = $obj->tva_tx;
321 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
322 $l->total_ttc = $l->total_ht + $l->total_tva;
323 $l->ref_supplier = $obj->ref_fourn;
331 $object->update_price();
334 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
338 if ($action ==
'setremisepercent' && $usercancreate) {
345 if ($action ==
'reopen') {
346 if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) {
347 if ($object->statut == 1) {
349 } elseif ($object->statut == 2) {
351 } elseif ($object->statut == 3) {
353 } elseif ($object->statut == 4) {
355 } elseif ($object->statut == 5) {
361 } elseif ($object->statut == 6) {
363 } elseif ($object->statut == 7) {
365 } elseif ($object->statut == 9) {
374 $result = $object->setStatus($user, $newstatus);
377 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
378 $sql .=
' SET billed = 0';
379 $sql .=
' WHERE rowid = '.((int) $object->id);
381 $resql = $db->query($sql);
383 if ($newstatus == 0) {
384 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
385 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
386 $sql .=
' WHERE rowid = '.((int) $object->id);
388 $resql = $db->query($sql);
393 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
406 if ($action ==
'classifybilled' && $usercancreate) {
407 $ret = $object->classifyBilled($user);
414 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
416 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
417 $vat_rate = str_replace(
'*',
'', $vat_rate);
418 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
419 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
420 foreach ($object->lines as $line) {
421 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
423 } elseif ($action ==
'addline' && $usercancreate) {
426 $langs->load(
'errors');
435 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
436 if ($prod_entry_mode ==
'free') {
439 $idprod =
GETPOST(
'idprod',
'int');
451 if (empty($remise_percent)) {
456 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
457 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
459 if (is_array($extralabelsline)) {
461 foreach ($extralabelsline as $key => $value) {
462 unset($_POST[
"options_".$key]);
466 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
467 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
470 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
471 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
474 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
475 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
478 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
479 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
482 if (
GETPOST(
'qty',
'alpha') ==
'') {
483 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
487 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
488 if ($combinations =
GETPOST(
'combinations',
'array')) {
492 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
493 $idprod = $res->fk_product_child;
495 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
501 if ($prod_entry_mode !=
'free' && empty($error)) {
505 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
510 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
512 $res = $productsupplier->fetch($idprod);
515 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
517 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
518 if ($productsupplier->fourn_socid != $socid) {
519 $productsupplier->ref_supplier =
'';
522 $fksoctosearch = $object->thirdparty->id;
523 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
525 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
528 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
529 $res = $productsupplier->fetch($idprod);
533 $label = $productsupplier->label;
536 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
537 $outputlangs = $langs;
539 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
540 $newlang =
GETPOST(
'lang_id',
'aZ09');
542 if (empty($newlang)) {
543 $newlang = $object->thirdparty->default_lang;
545 if (!empty($newlang)) {
547 $outputlangs->setDefaultLang($newlang);
549 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
551 $desc = $productsupplier->description;
554 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
555 $desc = $productsupplier->desc_supplier;
559 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
563 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
564 $desc = $product_desc;
566 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
567 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
570 $ref_supplier = $productsupplier->ref_supplier;
575 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
576 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
577 if (empty($tva_tx)) {
582 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
583 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
585 $type = $productsupplier->type;
586 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
587 $price_base_type =
'HT';
589 $pu_devise =
price2num($price_ht_devise,
'CU');
590 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
591 $price_base_type =
'TTC';
593 $pu_devise =
price2num($price_ttc_devise,
'CU');
595 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
596 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
597 $pu = $productsupplier->fourn_pu;
600 $pu = $productsupplier->fourn_pu;
601 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
609 $result = $object->addline(
611 ($price_base_type ==
'HT' ? $pu : 0),
617 $productsupplier->product_fourn_price_id,
621 ($price_base_type ==
'TTC' ? $pu : 0),
628 $productsupplier->fk_unit,
632 min($rank, count($object->lines) + 1)
635 if ($idprod == -99 || $idprod == 0) {
638 $langs->load(
"errors");
639 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
644 $langs->load(
"errors");
645 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
647 } elseif (empty($error)) {
648 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
649 $tva_tx = str_replace(
'*',
'', $tva_tx);
650 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
651 $desc = $product_desc;
653 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
655 $fk_unit =
GETPOST(
'units',
'alpha');
657 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
662 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
663 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
665 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
669 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
671 $price_base_type =
'HT';
672 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
674 $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);
678 if (!$error && $result > 0) {
681 $ret = $object->fetch($object->id);
684 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
685 $outputlangs = $langs;
688 $newlang = $object->thirdparty->default_lang;
689 if (
GETPOST(
'lang_id',
'aZ09'))
690 $newlang =
GETPOST(
'lang_id',
'aZ09');
692 if (!empty($newlang)) {
694 $outputlangs->setDefaultLang($newlang);
696 $model = $object->model_pdf;
697 $ret = $object->fetch($id);
699 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
705 unset($_POST [
'prod_entry_mode']);
707 unset($_POST[
'qty']);
708 unset($_POST[
'type']);
709 unset($_POST[
'remise_percent']);
711 unset($_POST[
'price_ht']);
712 unset($_POST[
'multicurrency_price_ht']);
713 unset($_POST[
'price_ttc']);
714 unset($_POST[
'fourn_ref']);
715 unset($_POST[
'tva_tx']);
716 unset($_POST[
'label']);
717 unset($localtax1_tx);
718 unset($localtax2_tx);
719 unset($_POST[
'np_marginRate']);
720 unset($_POST[
'np_markRate']);
721 unset($_POST[
'dp_desc']);
722 unset($_POST[
'idprodfournprice']);
723 unset($_POST[
'units']);
725 unset($_POST[
'date_starthour']);
726 unset($_POST[
'date_startmin']);
727 unset($_POST[
'date_startsec']);
728 unset($_POST[
'date_startday']);
729 unset($_POST[
'date_startmonth']);
730 unset($_POST[
'date_startyear']);
731 unset($_POST[
'date_endhour']);
732 unset($_POST[
'date_endmin']);
733 unset($_POST[
'date_endsec']);
734 unset($_POST[
'date_endday']);
735 unset($_POST[
'date_endmonth']);
736 unset($_POST[
'date_endyear']);
748 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
755 $res = $line->fetch($lineid);
762 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
763 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0,
price2num(
GETPOST(
'qty',
'int')), $line->fk_product,
'none',
GETPOST(
'socid',
'int')) < 0) {
764 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
773 if (preg_match(
'/\*/', $vat_rate)) {
778 $vat_rate = str_replace(
'*',
'', $vat_rate);
779 $localtax1_rate =
get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
780 $localtax2_rate =
get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
782 if (
GETPOST(
'price_ht') !=
'') {
783 $price_base_type =
'HT';
787 $vatratecleaned = $vat_rate;
788 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
789 $vatratecleaned = trim($reg[1]);
790 $vatratecode = $reg[2];
794 $ht = $ttc / (1 + ($vatratecleaned / 100));
795 $price_base_type =
'HT';
801 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
802 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
804 if (is_array($extralabelsline)) {
805 foreach ($extralabelsline as $key => $value) {
806 unset($_POST[
"options_".$key]);
810 $result = $object->updateline(
812 GETPOST(
'product_desc',
'restricthtml'),
830 unset($_POST[
'qty']);
831 unset($_POST[
'type']);
832 unset($_POST[
'idprodfournprice']);
833 unset($_POST[
'remmise_percent']);
834 unset($_POST[
'dp_desc']);
835 unset($_POST[
'np_desc']);
837 unset($_POST[
'fourn_ref']);
838 unset($_POST[
'tva_tx']);
839 unset($_POST[
'date_start']);
840 unset($_POST[
'date_end']);
841 unset($_POST[
'units']);
842 unset($localtax1_tx);
843 unset($localtax2_tx);
845 unset($_POST[
'date_starthour']);
846 unset($_POST[
'date_startmin']);
847 unset($_POST[
'date_startsec']);
848 unset($_POST[
'date_startday']);
849 unset($_POST[
'date_startmonth']);
850 unset($_POST[
'date_startyear']);
851 unset($_POST[
'date_endhour']);
852 unset($_POST[
'date_endmin']);
853 unset($_POST[
'date_endsec']);
854 unset($_POST[
'date_endday']);
855 unset($_POST[
'date_endmonth']);
856 unset($_POST[
'date_endyear']);
860 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
861 $outputlangs = $langs;
864 $newlang =
GETPOST(
'lang_id',
'aZ09');
867 $newlang = $object->thirdparty->default_lang;
869 if (!empty($newlang)) {
871 $outputlangs->setDefaultLang($newlang);
873 $model = $object->model_pdf;
874 $ret = $object->fetch($id);
876 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
891 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
894 $result = $object->deleteline($lineid);
897 $object->line_order(
true);
899 $outputlangs = $langs;
902 $newlang =
GETPOST(
'lang_id',
'aZ09');
905 $newlang = $object->thirdparty->default_lang;
907 if (!empty($newlang)) {
909 $outputlangs->setDefaultLang($newlang);
911 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
912 $ret = $object->fetch($object->id);
913 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
925 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
933 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
936 $object->date_commande =
dol_now();
937 $result = $object->valid($user);
940 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
941 $outputlangs = $langs;
944 $newlang =
GETPOST(
'lang_id',
'aZ09');
947 $newlang = $object->thirdparty->default_lang;
949 if (!empty($newlang)) {
951 $outputlangs->setDefaultLang($newlang);
953 $model = $object->model_pdf;
954 $ret = $object->fetch($id);
956 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
968 if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) {
969 $action =
'confirm_approve';
979 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
982 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
984 $qualified_for_stock_change = 0;
985 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
986 $qualified_for_stock_change = $object->hasProductsOrServices(2);
988 $qualified_for_stock_change = $object->hasProductsOrServices(1);
992 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
993 if (!$idwarehouse || $idwarehouse == -1) {
995 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1001 $result = $object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1003 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1004 $outputlangs = $langs;
1007 $newlang =
GETPOST(
'lang_id',
'aZ09');
1010 $newlang = $object->thirdparty->default_lang;
1012 if (!empty($newlang)) {
1013 $outputlangs =
new Translate(
"", $conf);
1014 $outputlangs->setDefaultLang($newlang);
1016 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1027 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1034 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1036 $object->refuse_note =
GETPOST(
'refuse_note');
1038 $result = $object->refuse($user);
1040 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1048 if ($action ==
'commande') {
1049 $methodecommande =
GETPOST(
'methodecommande',
'int');
1053 } elseif ($methodecommande <= 0) {
1054 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1055 $action =
'makeorder';
1059 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1062 $result = $object->commande($user,
GETPOST(
"datecommande"),
GETPOST(
"methode",
'int'),
GETPOST(
'comment',
'alphanohtml'));
1064 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1065 $outputlangs = $langs;
1068 $newlang =
GETPOST(
'lang_id',
'aZ09');
1071 $newlang = $object->thirdparty->default_lang;
1073 if (!empty($newlang)) {
1074 $outputlangs =
new Translate(
"", $conf);
1075 $outputlangs->setDefaultLang($newlang);
1077 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1088 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1096 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1097 $result = $object->delete($user);
1099 header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
1107 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1108 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1109 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1111 if ($object->id > 0) {
1112 $orig = clone $object;
1114 $result = $object->createFromClone($user, $socid);
1116 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1128 if ($action ==
'livraison' && $usercanreceive) {
1137 $result = $object->Livraison($user, $date_liv,
GETPOST(
"type"),
GETPOST(
"comment"));
1139 $langs->load(
"deliveries");
1142 } elseif ($result == -3) {
1151 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1162 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1164 $object->cancel_note =
GETPOST(
'cancel_note');
1166 $result = $object->cancel($user);
1168 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1176 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1179 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1180 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1181 $trackid =
'sord'.$object->id;
1182 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1185 $upload_dir = $conf->fournisseur->commande->dir_output;
1186 $permissiontoadd = $usercancreate;
1187 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1190 if ($action ==
'update_extras') {
1194 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1202 $result = $object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
1211 $action =
'edit_extras';
1218 if ($action ==
'add' && $usercancreate) {
1220 $selectedLines =
GETPOST(
'toselect',
'array');
1222 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1231 $object->ref_supplier =
GETPOST(
'refsupplier');
1232 $object->socid = $socid;
1233 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1234 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1235 $object->fk_account =
GETPOST(
'fk_account',
'int');
1236 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
1237 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
1238 $object->date_livraison = $datelivraison;
1239 $object->delivery_date = $datelivraison;
1240 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1241 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1242 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1243 $object->multicurrency_tx =
price2num(
GETPOST(
'originmulticurrency_tx',
'alpha'));
1244 $object->fk_project =
GETPOST(
'projectid',
'int');
1248 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1256 if (!empty($origin) && !empty($originid)) {
1257 $element = $subelement = $origin;
1258 $classname = ucfirst($subelement);
1259 if ($origin ==
'propal' || $origin ==
'proposal') {
1260 $element =
'comm/propal'; $subelement =
'propal';
1261 $classname =
'Propal';
1263 if ($origin ==
'order' || $origin ==
'commande') {
1264 $element = $subelement =
'commande';
1265 $classname =
'Commande';
1267 if ($origin ==
'supplier_proposal') {
1268 $classname =
'SupplierProposal';
1269 $element =
'supplier_proposal';
1270 $subelement =
'supplier_proposal';
1273 $object->origin = $origin;
1274 $object->origin_id = $originid;
1277 $object->linked_objects [$object->origin] = $object->origin_id;
1278 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1279 if (!empty($other_linked_objects)) {
1280 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
1283 $id = $object->create($user);
1287 $srcobject =
new $classname($db);
1289 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
1290 $result = $srcobject->fetch($object->origin_id);
1292 $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
1293 $object->setDeliveryDate($user, $tmpdate);
1294 $object->set_id_projet($user, $srcobject->fk_project);
1296 $lines = $srcobject->lines;
1297 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1298 $srcobject->fetch_lines();
1299 $lines = $srcobject->lines;
1302 $fk_parent_line = 0;
1303 $num = count($lines);
1305 for ($i = 0; $i < $num; $i++) {
1306 if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines)) {
1310 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1311 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
1312 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1315 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1316 $fk_parent_line = 0;
1320 if (method_exists($lines[$i],
'fetch_optionals')) {
1321 $lines[$i]->fetch_optionals();
1322 $array_option = $lines[$i]->array_options;
1326 $product_fourn_price_id = 0;
1327 if ($origin ==
"commande") {
1329 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
1331 $ref_supplier = $productsupplier->ref_supplier;
1332 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1335 $ref_supplier = $lines[$i]->ref_fourn;
1336 $product_fourn_price_id = 0;
1339 $tva_tx = $lines[$i]->tva_tx;
1341 if ($origin ==
"commande") {
1342 $soc =
new societe($db);
1343 $soc->fetch($socid);
1344 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1347 $object->special_code = $lines[$i]->special_code;
1349 $result = $object->addline(
1351 $lines[$i]->subprice,
1354 $lines[$i]->localtax1_tx,
1355 $lines[$i]->localtax2_tx,
1356 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1357 $product_fourn_price_id,
1359 $lines[$i]->remise_percent,
1362 $lines[$i]->product_type,
1368 $lines[$i]->fk_unit,
1371 !empty($lines[$i]->
id) ? $lines[$i]->
id : $lines[$i]->
rowid
1381 if ($result > 0 && $lines[$i]->product_type == 9) {
1382 $fk_parent_line = $result;
1391 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
1406 $id = $object->create($user);
1415 $langs->load(
"errors");
1418 $_GET[
'socid'] = $_POST[
'socid'];
1421 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode($id));
1427 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') ==
"send" && !
GETPOST(
'cancel',
'alpha')) {
1428 $ws_url = $object->thirdparty->webservices_url;
1429 $ws_key = $object->thirdparty->webservices_key;
1430 $ws_user =
GETPOST(
'ws_user',
'alpha');
1431 $ws_password =
GETPOST(
'ws_password',
'alpha');
1432 $ws_entity =
GETPOST(
'ws_entity',
'int');
1433 $ws_thirdparty =
GETPOST(
'ws_thirdparty',
'int');
1436 $ws_ns =
'http://www.dolibarr.org/ns/';
1437 $ws_authentication = array(
1438 'dolibarrkey'=>$ws_key,
1439 'sourceapplication'=>
'DolibarrWebServiceClient',
1441 'password'=>$ws_password,
1442 'entity'=>$ws_entity
1446 if (empty($conf->syncsupplierwebservices->enabled)) {
1447 setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2650Name")),
null,
'mesgs');
1448 } elseif (empty($ws_url) || empty($ws_key)) {
1449 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
1450 } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1454 $soapclient_order =
new nusoap_client($ws_url.
"/webservices/server_order.php");
1455 $soapclient_order->soap_defencoding =
'UTF-8';
1456 $soapclient_order->decodeUTF8(
false);
1459 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
1460 $soapclient_product->soap_defencoding =
'UTF-8';
1461 $soapclient_product->decodeUTF8(
false);
1464 $order_lines = array();
1465 foreach ($object->lines as $line) {
1466 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $line->ref_supplier);
1467 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
1469 if ($result_product[
"result"][
"result_code"] ==
"OK") {
1470 $order_lines[] = array(
1471 'desc' => $line->product_desc,
1472 'type' => $line->product_type,
1473 'product_id' => $result_product[
"product"][
"id"],
1474 'vat_rate' => $line->tva_tx,
1475 'qty' => $line->qty,
1476 'price' => $line->price,
1477 'unitprice' => $line->subprice,
1478 'total_net' => $line->total_ht,
1479 'total_vat' => $line->total_tva,
1480 'total' => $line->total_ttc,
1481 'date_start' => $line->date_start,
1482 'date_end' => $line->date_end,
1489 'thirdparty_id' => $ws_thirdparty,
1491 'total_net' => $object->total_ht,
1492 'total_var' => $object->total_tva,
1493 'total' => $object->total_ttc,
1494 'lines' => $order_lines
1497 $ws_parameters = array(
'authentication'=>$ws_authentication,
'order' => $order);
1498 $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns,
'');
1500 if (empty($result_order[
"result"][
"result_code"])) {
1501 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'",
null,
'errors');
1502 } elseif ($result_order[
"result"][
"result_code"] !=
"OK") {
1503 setEventMessages($langs->trans(
"SOAPError").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'",
null,
'errors');
1505 setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"],
null,
'mesgs');
1510 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1511 if ($action ==
'addcontact') {
1512 if ($object->id > 0) {
1515 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1519 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1522 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1523 $langs->load(
"errors");
1524 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1529 } elseif ($action ==
'swapstatut' && $object->id > 0) {
1531 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1532 } elseif ($action ==
'deletecontact' && $object->id > 0) {
1534 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1537 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1554 $productstatic =
new Product($db);
1559 $title = $object->ref.
" - ".$langs->trans(
'Card');
1560 if ($action ==
'create') {
1561 $title = $langs->trans(
"NewOrderSupplier");
1563 $help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1568 if ($action ==
'create') {
1569 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1573 $currency_code = $conf->currency;
1578 $societe->fetch($socid);
1581 if (!empty($origin) && !empty($originid)) {
1583 $element = $subelement = $origin;
1584 $classname = ucfirst($subelement);
1586 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1587 $element = $regs[1];
1588 $subelement = $regs[2];
1591 if ($origin ==
'propal' || $origin ==
'proposal') {
1592 $classname =
'Propal';
1593 $element =
'comm/propal'; $subelement =
'propal';
1595 if ($origin ==
'order' || $origin ==
'commande') {
1596 $classname =
'Commande';
1597 $element = $subelement =
'commande';
1599 if ($origin ==
'supplier_proposal') {
1600 $classname =
'SupplierProposal';
1601 $element =
'supplier_proposal';
1602 $subelement =
'supplier_proposal';
1609 $objectsrc =
new $classname($db);
1610 $objectsrc->fetch($originid);
1611 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1612 $objectsrc->fetch_lines();
1614 $objectsrc->fetch_thirdparty();
1617 $objectsrc->fetch_optionals();
1618 $object->array_options = $objectsrc->array_options;
1620 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1621 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1623 $soc = $objectsrc->thirdparty;
1625 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1626 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1627 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1628 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1629 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1630 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1631 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1632 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1633 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1635 $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
''));
1638 if (!empty($objectsrc->multicurrency_code)) {
1639 $currency_code = $objectsrc->multicurrency_code;
1641 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1642 $currency_tx = $objectsrc->multicurrency_tx;
1646 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1647 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1650 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1652 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1653 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1655 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
1656 $currency_code = $societe->multicurrency_code;
1659 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1660 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1664 if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) {
1665 $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
1667 if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) {
1668 $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
1671 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1672 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1673 print
'<input type="hidden" name="action" value="add">';
1674 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1675 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1676 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1678 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1680 if ($backtopageforcancel) {
1681 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1684 if (!empty($currency_tx)) {
1685 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1690 print
'<table class="border centpercent">';
1693 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1696 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1699 if (!empty($societe->id) && $societe->id > 0) {
1700 print $societe->getNomUrl(1,
'supplier');
1701 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1703 print
img_picto(
'',
'company').$form->select_company((empty($socid) ?
'' : $socid),
'socid',
'(s.fournisseur=1 AND s.status=1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1705 if (empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED)) {
1707 $(document).ready(function() {
1708 $("#socid").change(function() {
1709 console.log("We have changed the company - Reload page");
1711 $("input[name=action]").val("create");
1712 $("form[name=add]").submit();
1717 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>';
1721 if (!empty($societe->id) && $societe->id > 0) {
1723 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1725 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
1727 $thirdparty = $societe;
1729 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1730 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1736 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1740 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1741 print
$form->getSelectConditionsPaiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id');
1745 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1746 $form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
1751 print $langs->trans(
'DateDeliveryPlanned');
1755 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1758 print
$form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin,
'',
"set");
1762 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) &&
isModEnabled(
"banque")) {
1763 $langs->load(
"bank");
1764 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1765 print
img_picto(
'',
'bank_account',
'class="paddingrightonly"');
1766 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
1774 $langs->load(
'projects');
1775 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1776 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');
1777 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?action=create&status=1'.(!empty($societe->id) ?
'&socid='.$societe->id :
"").
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create'.(!empty($societe->id) ?
'&socid='.$societe->id :
"")).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
1783 $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1784 $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1786 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $object->label_incoterms, 1).
'</label></td>';
1787 print
'<td class="maxwidthonsmartphone">';
1788 print
$form->select_incoterms($fkincoterms, $locincoterms);
1795 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1796 print
'<td class="maxwidthonsmartphone">';
1797 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
1801 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
1803 $doleditor =
new DolEditor(
'note_public', isset($note_public) ? $note_public :
GETPOST(
'note_public',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1804 print $doleditor->Create(1);
1809 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
1811 $doleditor =
new DolEditor(
'note_private', isset($note_private) ? $note_private :
GETPOST(
'note_private',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1812 print $doleditor->Create(1);
1817 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1818 print
"\n<!-- ".$classname.
" info -->";
1820 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1821 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1822 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1823 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1824 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1826 $newclassname = $classname;
1827 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
1828 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1829 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1830 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1831 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1834 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1835 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1838 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1841 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1842 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
1843 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
1849 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1850 print $hookmanager->resPrint;
1852 if (empty($reshook)) {
1853 print $object->showOptionals($extrafields,
'create');
1861 print
$form->buttonsSaveCancel(
"CreateDraft");
1864 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1865 $title = $langs->trans(
'ProductsAndServices');
1868 print
'<div class="div-table-responsive-no-min">';
1869 print
'<table class="noborder centpercent">';
1871 $selectedLines = array();
1873 $objectsrc->printOriginLinesList(
'', $selectedLines);
1879 } elseif (!empty($object->id)) {
1880 $result = $object->fetch($id, $ref);
1883 $result = $societe->fetch($object->socid);
1888 $author =
new User($db);
1889 $author->fetch($object->user_author_id);
1891 $res = $object->fetch_optionals();
1896 $title = $langs->trans(
"SupplierOrder");
1903 if ($action ==
'delete') {
1904 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 2);
1908 if ($action ==
'clone') {
1910 $formquestion = array(
1911 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.fournisseur=1)'))
1914 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1918 if ($action ==
'valid') {
1919 $object->date_commande =
dol_now();
1922 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
1923 $newref = $object->getNextNumRef($object->thirdparty);
1925 $newref = $object->ref;
1932 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
1934 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1935 $notify =
new Notify($db);
1937 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
1940 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
1945 if ($action ==
'approve' || $action ==
'approve2') {
1946 $qualified_for_stock_change = 0;
1947 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1948 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1950 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1953 $formquestion = array();
1954 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
1955 $langs->load(
"stocks");
1956 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1959 if ($conf->browser->name ==
'ie') {
1962 $formquestion = array(
1966 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse',
'int'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
1969 $text = $langs->trans(
"ConfirmApproveThisOrder", $object->ref);
1971 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1972 $notify =
new Notify($db);
1974 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE', $object->socid, $object);
1977 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
1981 if ($action ==
'refuse') {
1982 $formquestion = array(
1985 'name' =>
'refuse_note',
1986 'label' => $langs->trans(
"Reason"),
1988 'morecss' =>
'minwidth300'
1991 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder", $object->ref),
"confirm_refuse", $formquestion, 0, 1);
1995 if ($action ==
'cancel') {
1996 $formquestion = array(
1999 'name' =>
'cancel_note',
2000 'label' => $langs->trans(
"Reason"),
2002 'morecss' =>
'minwidth300'
2005 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder", $object->ref),
"confirm_cancel", $formquestion, 0, 1);
2009 if ($action ==
'commande') {
2011 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id.
"&datecommande=".$date_com.
"&methode=".
GETPOST(
"methodecommande").
"&comment=".urlencode(
GETPOST(
"comment")), $langs->trans(
"MakeOrder"), $langs->trans(
"ConfirmMakeOrder",
dol_print_date($date_com,
'day')),
"confirm_commande",
'', 0, 2);
2015 if ($action ==
'ask_deleteline') {
2016 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2020 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2021 if (empty($reshook)) {
2023 } elseif ($reshook > 0) {
2033 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2035 $morehtmlref =
'<div class="refidno">';
2037 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2038 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE :
''),
'',
null,
null,
'', 1);
2040 $morehtmlref .=
'<br>';
2041 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2042 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2043 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2044 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2045 $morehtmlref .=
$form->select_company($object->thirdparty->id,
'new_socid',
's.fournisseur=1',
'', 0, 0, array(), 0,
'minwidth300');
2046 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2047 $morehtmlref .=
'</form>';
2049 if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action !=
'edit_thirdparty') {
2051 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2053 $morehtmlref .= $object->thirdparty->getNomUrl(1,
'supplier');
2054 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2055 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2061 $langs->load(
"projects");
2062 $morehtmlref .=
'<br>';
2063 if ($permissiontoadd) {
2064 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2065 if ($action !=
'classify' && $caneditproject) {
2066 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2068 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2070 if (!empty($object->fk_project)) {
2072 $proj->fetch($object->fk_project);
2073 $morehtmlref .= $proj->getNomUrl(1);
2075 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2080 $morehtmlref .=
'</div>';
2083 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2086 print
'<div class="fichecenter">';
2087 print
'<div class="fichehalfleft">';
2088 print
'<div class="underbanner clearboth"></div>';
2090 print
'<table class="border tableforfield centpercent">';
2093 if ($object->methode_commande_id > 0) {
2095 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2098 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2099 print $object->date_commande ?
dol_print_date($object->date_commande, $usehourmin ?
'dayhour' :
'day') :
'';
2100 if ($object->hasDelay() && !empty($object->delivery_date) && !empty($object->date_commande)) {
2101 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2105 if ($object->methode_commande) {
2106 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
2111 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2112 print
'<td>'.$author->getNomUrl(1,
'', 0, 0, 0).
'</td>';
2116 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
2117 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2118 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2120 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2121 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2124 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2125 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2126 $absolute_discount =
price2num($absolute_discount,
'MT');
2127 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2129 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2131 $thirdparty = $societe;
2133 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2134 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2139 $langs->load(
'bills');
2140 print
'<tr><td class="nowrap">';
2141 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2142 print $langs->trans(
'PaymentConditions');
2144 if ($action !=
'editconditions') {
2145 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editconditions&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetConditions'), 1).
'</a></td>';
2147 print
'</tr></table>';
2149 if ($action ==
'editconditions') {
2150 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
2152 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
2158 $langs->load(
'bills');
2159 print
'<tr><td class="nowrap">';
2160 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2161 print $langs->trans(
'PaymentMode');
2163 if ($action !=
'editmode') {
2164 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetMode'), 1).
'</a></td>';
2166 print
'</tr></table>';
2168 if ($action ==
'editmode') {
2169 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2171 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2180 print
'<table class="nobordernopadding centpercent"><tr><td>';
2181 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2183 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
2184 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencycode&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2186 print
'</tr></table>';
2188 if ($action ==
'editmulticurrencycode') {
2189 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2191 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2196 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2199 print
'<table class="nobordernopadding centpercent"><tr>';
2201 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2203 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2204 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editmulticurrencyrate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetMultiCurrencyCode'), 1).
'</a></td>';
2206 print
'</tr></table>';
2208 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2209 if ($action ==
'actualizemulticurrencyrate') {
2212 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2214 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2215 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2216 print
'<div class="inline-block"> ';
2217 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2226 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) &&
isModEnabled(
"banque")) {
2227 print
'<tr><td class="nowrap">';
2228 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2229 print $langs->trans(
'BankAccount');
2231 if ($action !=
'editbankaccount' && $usercancreate) {
2232 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editbankaccount&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetBankAccount'), 1).
'</a></td>';
2234 print
'</tr></table>';
2236 if ($action ==
'editbankaccount') {
2237 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2239 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2247 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2248 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2253 print
'<table class="nobordernopadding centpercent"><tr><td>';
2254 print $langs->trans(
'DateDeliveryPlanned');
2256 if ($action !=
'editdate_livraison') {
2257 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate_livraison&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetDeliveryDate'), 1).
'</a></td>';
2259 print
'</tr></table>';
2261 if ($action ==
'editdate_livraison') {
2262 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2263 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2264 print
'<input type="hidden" name="action" value="setdate_livraison">';
2266 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2269 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin,
'',
"setdate_livraison");
2270 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2273 $usehourmin =
'day';
2274 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2275 $usehourmin =
'dayhour';
2277 print $object->delivery_date ?
dol_print_date($object->delivery_date, $usehourmin) :
' ';
2278 if ($object->hasDelay() && !empty($object->delivery_date) && ($object->statut == $object::STATUS_ORDERSENT || $object->statut == $object::STATUS_RECEIVED_PARTIALLY)) {
2279 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2287 print
'<table class="nobordernopadding centpercent"><tr><td>';
2288 print $langs->trans(
'IncotermLabel');
2289 print
'<td><td class="right">';
2290 if ($usercancreate) {
2291 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2295 print
'</td></tr></table>';
2298 if ($action !=
'editincoterm') {
2301 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2307 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2312 print
'<div class="fichehalfright">';
2313 print
'<div class="underbanner clearboth"></div>';
2315 print
'<table class="border tableforfield centpercent">';
2317 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2319 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2320 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2324 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2325 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2329 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2330 print
'<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc,
'', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2336 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
2337 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->supplier_order_min_amount));
2339 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
2340 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).$alert.
'</td>';
2344 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td>';
2345 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2349 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2350 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2351 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2354 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2355 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2356 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2361 print
'<tr><td>'.$langs->trans(
"AmountTTC").
'</td>';
2362 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2376 print
'<div class="clearboth"></div><br>';
2378 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2379 $blocname =
'contacts';
2380 $title = $langs->trans(
'ContactsAddresses');
2381 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2384 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2385 $blocname =
'notes';
2386 $title = $langs->trans(
'Notes');
2387 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2396 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2397 <input type="hidden" name="token" value="'.
newToken().
'">
2398 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2399 <input type="hidden" name="mode" value="">
2400 <input type="hidden" name="page_y" value="">
2401 <input type="hidden" name="id" value="'.$object->id.
'">
2402 <input type="hidden" name="socid" value="'.$societe->id.
'">
2405 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
2406 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2409 print
'<div class="div-table-responsive-no-min">';
2410 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2413 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2414 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
2415 $senderissupplier = 2;
2416 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
2417 $senderissupplier = 1;
2421 if (!empty($object->lines)) {
2422 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
2425 $num = count($object->lines);
2429 if ($action !=
'editline') {
2433 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2434 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2435 if (empty($reshook))
2436 $object->formAddObjectLine(1, $societe, $mysoc);
2449 if ($user->socid == 0 && $action !=
'delete') {
2450 if ($action !=
'makeorder' && $action !=
'presend' && $action !=
'editline') {
2451 print
'<div class="tabsAction">';
2454 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2456 if (empty($reshook)) {
2457 $object->fetchObjectLinked();
2460 if ($object->statut == 0 && $num > 0) {
2461 if ($usercanvalidate) {
2462 $tmpbuttonlabel = $langs->trans(
'Validate');
2463 if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
2464 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2467 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid">';
2468 print $tmpbuttonlabel;
2480 if ($usercanorder) {
2481 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2487 if ($usercanapprove) {
2488 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)) {
2489 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2491 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2494 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2499 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
2501 if ($usercanapprovesecond) {
2502 if (!empty($object->user_approve_id2)) {
2503 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2505 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2508 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2515 if ($usercanapprove || $usercanapprovesecond) {
2516 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2518 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2523 if (empty($user->socid)) {
2525 if ($usercanorder) {
2526 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2534 if (!$buttonshown && $usercanapprove) {
2535 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
2536 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) {
2537 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2541 if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
2542 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
2543 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) {
2544 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2548 if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) {
2549 if ($usercanorder) {
2550 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2556 if (
isModEnabled(
'stock') && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) {
2557 $labelofbutton = $langs->trans(
'ReceiveProducts');
2558 if ($conf->reception->enabled) {
2559 $labelofbutton = $langs->trans(
"CreateReception");
2560 if (!empty($object->linkedObjects[
'reception'])) {
2561 foreach ($object->linkedObjects[
'reception'] as $element) {
2562 if ($element->statut >= 0) {
2570 if (in_array($object->statut, array(3, 4, 5))) {
2571 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order")) && $usercanreceive) {
2572 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.$object->id.
'">'.$labelofbutton.
'</a></div>';
2574 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2580 if ($usercanorder) {
2581 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=makeorder#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
2583 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2589 if ($usercanreceive) {
2590 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&token='.
newToken().
'&action=classifyreception#classifyreception">'.$langs->trans(
"ClassifyReception").
'</a></div>';
2597 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_invoice")) && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1)) {
2598 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2599 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>';
2605 if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1) {
2607 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2609 if (!empty($object->linkedObjectsIds[
'invoice_supplier'])) {
2610 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2611 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2614 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2620 if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2) {
2621 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=webservice&token='.
newToken().
'&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
2625 if ($usercancreate) {
2626 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=order">'.$langs->trans(
"ToClone").
'</a>';
2631 if ($usercanorder) {
2632 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel">'.$langs->trans(
"CancelOrder").
'</a>';
2637 if (!empty($usercandelete)) {
2638 if ($hasreception) {
2639 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
2641 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2651 print
'<!-- form to record supplier order -->'.
"\n";
2652 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2654 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2655 print
'<input type="hidden" name="action" value="commande">';
2657 print
'<table class="noborder centpercent">';
2659 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2660 $date_com =
dol_mktime(
GETPOST(
'rehour',
'int'),
GETPOST(
'remin',
'int'),
GETPOST(
'resec',
'int'),
GETPOST(
'remonth',
'int'),
GETPOST(
'reday',
'int'),
GETPOST(
'reyear',
'int'));
2661 if (empty($date_com)) {
2664 print
$form->selectDate($date_com,
'', 1, 1,
'',
"commande", 1, 1);
2668 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2669 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2672 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2673 print
'<tr><td class="center" colspan="2">';
2674 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2675 print
' ';
2676 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2685 if (
GETPOST(
'modelselected')) {
2686 $action =
'presend';
2689 if ($action !=
'makeorder' && $action !=
'presend' ) {
2690 print
'<div class="fichecenter"><div class="fichehalfleft">';
2694 $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2695 $relativepath = $objref.
'/'.$objref.
'.pdf';
2696 $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
2697 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2698 $genallowed = $usercanread;
2699 $delallowed = $usercancreate;
2700 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
2702 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'', $object->thirdparty->default_lang,
'', $object);
2703 $somethingshown = $formfile->numoffiles;
2706 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'supplier_order',
'order_supplier'));
2707 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2709 print
'</div><div class="fichehalfright">';
2711 if ($action ==
'classifyreception') {
2714 print
'<!-- form to record purchase order received -->'.
"\n";
2715 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2716 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2717 print
'<input type="hidden" name="action" value="livraison">';
2720 print
'<table class="noborder centpercent">';
2722 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2724 print
$form->selectDate($datepreselected,
'', 1, 1,
'',
"commande", 1, 1);
2725 print
"</td></tr>\n";
2727 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2729 $liv[
''] =
' ';
2730 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2731 $liv[
'par'] = $langs->trans(
"PartialWoman");
2732 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2733 $liv[
'can'] = $langs->trans(
"Canceled");
2735 print
$form->selectarray(
"type", $liv);
2738 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment"></td></tr>';
2739 print
'<tr><td class="center" colspan="2">';
2740 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
2741 print
' ';
2742 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2751 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2753 $somethingshown =
$formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2755 print
'</div></div>';
2761 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
2762 $mode =
GETPOST(
'mode',
'alpha');
2763 $ws_url = $object->thirdparty->webservices_url;
2764 $ws_key = $object->thirdparty->webservices_key;
2765 $ws_user =
GETPOST(
'ws_user',
'alpha');
2766 $ws_password =
GETPOST(
'ws_password',
'alpha');
2769 $ws_ns =
'http://www.dolibarr.org/ns/';
2770 $ws_authentication = array(
2771 'dolibarrkey'=>$ws_key,
2772 'sourceapplication'=>
'DolibarrWebServiceClient',
2774 'password'=>$ws_password,
2781 if (empty($ws_url) || empty($ws_key)) {
2782 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"),
null,
'errors');
2784 $error_occurred =
true;
2785 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2790 if ($mode ==
"init") {
2792 print
'<table class="border centpercent">';
2793 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2794 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2795 print
'<input type="hidden" name="action" value="webservice">';
2796 print
'<input type="hidden" name="mode" value="check">';
2798 if ($error_occurred) {
2799 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2800 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2802 $textinput_size =
"50";
2804 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2806 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_user"></td></tr>';
2808 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_password"></td></tr>';
2810 print
'<tr><td class="center" colspan="2">';
2811 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2812 print
' ';
2814 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2821 } elseif ($mode ==
"check") {
2823 $ws_thirdparty =
'';
2824 $error_occurred =
false;
2827 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2828 $soapclient_user->soap_defencoding =
'UTF-8';
2829 $soapclient_user->decodeUTF8(
false);
2832 $ws_parameters = array(
'authentication'=>$ws_authentication,
'id' =>
'',
'ref'=>$ws_user);
2833 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2834 $user_status_code = $result_user[
"result"][
"result_code"];
2836 if ($user_status_code ==
"OK") {
2838 $ws_entity = $result_user[
"user"][
"entity"];
2839 $ws_authentication[
'entity'] = $ws_entity;
2840 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2841 if (empty($ws_thirdparty)) {
2842 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"),
null,
'errors');
2843 $error_occurred =
true;
2846 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2847 $soapclient_product->soap_defencoding =
'UTF-8';
2848 $soapclient_product->decodeUTF8(
false);
2852 foreach ($object->lines as $line) {
2854 $ref_supplier = $line->ref_supplier;
2855 $line_id = $i.
"º) ".$line->product_ref.
": ";
2856 if (empty($ref_supplier)) {
2859 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2860 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2861 if (!$result_product) {
2862 setEventMessages($line_id.$langs->trans(
"SOAPError").
" ".$soapclient_product->error_str.
" - ".$soapclient_product->response,
null,
'errors');
2863 $error_occurred =
true;
2868 $status_code = $result_product[
"result"][
"result_code"];
2869 if (empty($status_code)) {
2870 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'",
null,
'errors');
2871 } elseif ($status_code !=
"OK") {
2872 if ($status_code ==
"NOT_FOUND") {
2873 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'",
null,
'warnings');
2875 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'",
null,
'errors');
2876 $error_occurred =
true;
2883 $supplier_price =
price($result_product[
"product"][
"price_net"]);
2884 $local_price =
null;
2887 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2888 if (count($product_fourn_list) > 0) {
2889 foreach ($product_fourn_list as $product_fourn_line) {
2891 if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2892 $local_price =
price($product_fourn_line->fourn_price);
2897 if ($local_price !=
null && $local_price != $supplier_price) {
2898 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price,
null,
'warnings');
2902 if (empty($result_product[
"product"][
"status_tosell"])) {
2903 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'",
null,
'warnings');
2907 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
2908 setEventMessages($langs->trans(
"RemoteUserNotPermission"),
null,
'errors');
2909 $error_occurred =
true;
2910 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
2911 setEventMessages($langs->trans(
"RemoteUserBadCredentials"),
null,
'errors');
2912 $error_occurred =
true;
2914 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'",
null,
'errors');
2915 $error_occurred =
true;
2919 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2920 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2921 print
'<input type="hidden" name="action" value="webservice">';
2922 print
'<input type="hidden" name="mode" value="send">';
2923 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
2924 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
2925 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
2926 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
2927 if ($error_occurred) {
2928 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2930 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
2931 print
' ';
2933 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2939 $modelmail =
'order_supplier_send';
2940 $defaulttopic =
'SendOrderRef';
2941 $diroutput = $conf->fournisseur->commande->dir_output;
2942 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
2943 $trackid =
'sord'.$object->id;
2945 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
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.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
Class to manage line orders.
Class to manage a WYSIWYG editor.
Class to manage suppliers.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage notifications.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
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.
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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_print_url($url, $target='_blank', $max=32, $withpicto=0)
Show Url link.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
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...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$formconfirm
if ($action == 'delbookkeepingyear') {
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.