36 require
'../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
46 if (!empty($conf->supplier_proposal->enabled)) {
47 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
49 if (!empty($conf->product->enabled)) {
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
52 if (!empty($conf->project->enabled)) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
56 require_once NUSOAP_PATH.
'/nusoap.php';
58 if (!empty($conf->variants->enabled)) {
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
62 $langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'deliveries',
'products',
'stocks',
'productbatch'));
63 if (!empty($conf->incoterm->enabled)) {
64 $langs->load(
'incoterm');
69 $action =
GETPOST(
'action',
'alpha');
70 $confirm =
GETPOST(
'confirm',
'alpha');
71 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
73 $backtopage =
GETPOST(
'backtopage',
'alpha');
74 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
76 $socid =
GETPOST(
'socid',
'int');
77 $projectid =
GETPOST(
'projectid',
'int');
78 $cancel =
GETPOST(
'cancel',
'alpha');
79 $lineid =
GETPOST(
'lineid',
'int');
80 $origin =
GETPOST(
'origin',
'alpha');
82 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
85 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
86 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
87 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
89 $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'));
93 if (!empty($user->socid)) {
94 $socid = $user->socid;
98 $hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
104 $extrafields->fetch_name_optionals_label($object->table_element);
107 $socid = $user->socid;
111 if ($id > 0 || !empty($ref)) {
112 $ret = $object->fetch($id, $ref);
116 $ret = $object->fetch_thirdparty();
120 } elseif (!empty($socid) && $socid > 0) {
122 $ret = $fourn->fetch($socid);
126 $object->socid = $fourn->id;
127 $ret = $object->fetch_thirdparty();
134 $isdraft = (isset($object->statut) && ($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
135 $result =
restrictedArea($user,
'fournisseur', $id,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
138 $usercanread = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire);
139 $usercancreate = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
140 $usercandelete = (($user->rights->fournisseur->commande->supprimer || $user->rights->supplier_order->supprimer) || ($usercancreate && isset($object->statut) && $object->statut == $object::STATUS_DRAFT));
143 $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)));
146 $usercanapprove = !empty($user->rights->fournisseur->commande->approuver) ? $user->rights->fournisseur->commande->approuver : 0;
147 $usercanapprovesecond = !empty($user->rights->fournisseur->commande->approve2) ? $user->rights->fournisseur->commande->approve2 : 0;
148 $usercanorder = !empty($user->rights->fournisseur->commande->commander) ? $user->rights->fournisseur->commande->commander : 0;
149 if (empty($conf->reception->enabled)) {
150 $usercanreceive = $user->rights->fournisseur->commande->receptionner;
152 $usercanreceive = $user->rights->reception->creer;
156 $permissionnote = $usercancreate;
157 $permissiondellink = $usercancreate;
158 $permissiontoedit = $usercancreate;
159 $permissiontoadd = $usercancreate;
162 $caneditproject =
false;
163 if (!empty($conf->project->enabled)) {
164 $caneditproject = empty($conf->global->SUPPLIER_ORDER_FORBID_EDIT_PROJECT) || ($object->statut ==
CommandeFournisseur::STATUS_DRAFT && preg_match(
'/^[\(]?PROV/i', $object->ref));
174 $parameters = array(
'socid'=>$socid);
175 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
180 if (empty($reshook)) {
181 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
183 if (empty($backtopage) || ($cancel && empty($id))) {
184 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
185 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
186 $backtopage = $backurlforlist;
188 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
194 if (!empty($backtopageforcancel)) {
195 header(
"Location: ".$backtopageforcancel);
197 } elseif (!empty($backtopage)) {
198 header(
"Location: ".$backtopage);
204 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
206 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
208 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
210 if ($action ==
'setref_supplier' && $usercancreate) {
211 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'', null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
218 if ($action ==
'set_incoterms' && $usercancreate) {
219 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
226 if ($action ==
'setconditions' && $usercancreate) {
227 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'));
234 if ($action ==
'setmode' && $usercancreate) {
235 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
239 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
241 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
242 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
244 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
248 if ($action ==
'setbankaccount' && $usercancreate) {
249 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
256 if ($action ==
'setdate_livraison' && $usercancreate) {
257 $result = $object->setDeliveryDate($user, $datelivraison);
264 if ($action ==
'classin' && $usercancreate && $caneditproject) {
265 $result = $object->setProject($projectid);
272 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action ==
'set_thirdparty' && $usercancreate && $object->statut ==
CommandeFournisseur::STATUS_DRAFT) {
273 $new_socid =
GETPOST(
'new_socid',
'int');
274 if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
278 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
279 $sql .=
' SET fk_soc = '.((int) $new_socid);
280 $sql .=
' WHERE fk_soc = '.((int) $object->thirdparty->id);
281 $sql .=
' AND rowid = '.((int) $object->id);
283 $res = $db->query($sql);
291 foreach ($object->lines as $l) {
292 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
293 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
294 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
295 $sql .=
' AND fk_soc = '.((int) $new_socid);
296 $sql .=
' ORDER BY unitprice ASC';
298 $resql = $db->query($sql);
300 $num_row = $db->num_rows(
$resql);
301 if (empty($num_row)) {
307 $l->ref_supplier =
'';
311 $obj = $db->fetch_object(
$resql);
312 $l->subprice = $obj->unitprice;
313 $l->total_ht = $obj->price;
314 $l->tva_tx = $obj->tva_tx;
315 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
316 $l->total_ttc = $l->total_ht + $l->total_tva;
317 $l->ref_supplier = $obj->ref_fourn;
325 $object->update_price();
328 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
332 if ($action ==
'setremisepercent' && $usercancreate) {
339 if ($action ==
'reopen') {
340 if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) {
341 if ($object->statut == 1) {
343 } elseif ($object->statut == 2) {
345 } elseif ($object->statut == 3) {
347 } elseif ($object->statut == 4) {
349 } elseif ($object->statut == 5) {
355 } elseif ($object->statut == 6) {
357 } elseif ($object->statut == 7) {
359 } elseif ($object->statut == 9) {
368 $result = $object->setStatus($user, $newstatus);
371 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
372 $sql .=
' SET billed = 0';
373 $sql .=
' WHERE rowid = '.((int) $object->id);
375 $resql = $db->query($sql);
377 if ($newstatus == 0) {
378 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
379 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
380 $sql .=
' WHERE rowid = '.((int) $object->id);
382 $resql = $db->query($sql);
387 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
400 if ($action ==
'classifybilled' && $usercancreate) {
401 $ret = $object->classifyBilled($user);
408 if ($action ==
'addline' && $usercancreate) {
411 $langs->load(
'errors');
420 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
421 if ($prod_entry_mode ==
'free') {
424 $idprod =
GETPOST(
'idprod',
'int');
436 if (empty($remise_percent)) {
441 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
442 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
444 if (is_array($extralabelsline)) {
446 foreach ($extralabelsline as $key => $value) {
447 unset($_POST[
"options_".$key]);
451 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
452 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
455 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
456 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
459 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
460 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')), null,
'errors');
463 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
464 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
467 if (
GETPOST(
'qty',
'alpha') ==
'') {
468 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
472 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
473 if ($combinations =
GETPOST(
'combinations',
'array')) {
477 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
478 $idprod = $res->fk_product_child;
480 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
486 if ($prod_entry_mode !=
'free' && empty($error)) {
490 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
495 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
497 $res = $productsupplier->fetch($idprod);
500 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
502 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
503 if ($productsupplier->fourn_socid != $socid) {
504 $productsupplier->ref_supplier =
'';
507 $fksoctosearch = $object->thirdparty->id;
508 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
510 } elseif (
GETPOST(
'idprodfournprice',
'alpha') > 0) {
513 $idprod = $productsupplier->get_buyprice(
GETPOST(
'idprodfournprice',
'alpha'), $qtytosearch);
514 $res = $productsupplier->fetch($idprod);
518 $label = $productsupplier->label;
521 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
522 $outputlangs = $langs;
524 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
525 $newlang =
GETPOST(
'lang_id',
'aZ09');
527 if (empty($newlang)) {
528 $newlang = $object->thirdparty->default_lang;
530 if (!empty($newlang)) {
532 $outputlangs->setDefaultLang($newlang);
534 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->description;
536 $desc = $productsupplier->description;
539 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
540 $desc = $productsupplier->desc_supplier;
544 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
548 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
549 $desc = $product_desc;
551 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
552 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
555 $ref_supplier = $productsupplier->ref_supplier;
559 $tva_tx =
get_default_tva($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
560 $tva_npr =
get_default_npr($object->thirdparty, $mysoc, $productsupplier->id,
GETPOST(
'idprodfournprice',
'alpha'));
562 if (empty($tva_tx)) {
565 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
566 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
568 $type = $productsupplier->type;
569 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
570 $price_base_type =
'HT';
572 $pu_devise =
price2num($price_ht_devise,
'CU');
573 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'price_ttc_devise') !=
'') {
574 $price_base_type =
'TTC';
576 $pu_devise =
price2num($price_ttc_devise,
'CU');
578 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
579 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) {
580 $pu = $productsupplier->fourn_pu;
583 $pu = $productsupplier->fourn_pu;
584 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
592 $result = $object->addline(
594 ($price_base_type ==
'HT' ? $pu : 0),
600 $productsupplier->product_fourn_price_id,
604 ($price_base_type ==
'TTC' ? $pu : 0),
611 $productsupplier->fk_unit,
615 min($rank, count($object->lines) + 1)
618 if ($idprod == -99 || $idprod == 0) {
621 $langs->load(
"errors");
622 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")), null,
'errors');
627 $langs->load(
"errors");
628 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'errors');
630 } elseif (empty($error)) {
631 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
632 $tva_tx = str_replace(
'*',
'', $tva_tx);
633 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
634 $desc = $product_desc;
636 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
638 $fk_unit =
GETPOST(
'units',
'alpha');
640 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
645 $localtax1_tx =
get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
646 $localtax2_tx =
get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
648 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'price_ht_devise') !=
'') {
652 $pu_ht =
price2num($pu_ttc / (1 + ($tva_tx / 100)),
'MU');
654 $price_base_type =
'HT';
655 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
657 $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);
661 if (!$error && $result > 0) {
664 $ret = $object->fetch($object->id);
667 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
668 $outputlangs = $langs;
670 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
671 $newlang =
GETPOST(
'lang_id',
'aZ09');
673 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
674 $newlang = $object->thirdparty->default_lang;
676 if (!empty($newlang)) {
678 $outputlangs->setDefaultLang($newlang);
680 $model = $object->model_pdf;
681 $ret = $object->fetch($id);
683 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
689 unset($_POST [
'prod_entry_mode']);
691 unset($_POST[
'qty']);
692 unset($_POST[
'type']);
693 unset($_POST[
'remise_percent']);
695 unset($_POST[
'price_ht']);
696 unset($_POST[
'multicurrency_price_ht']);
697 unset($_POST[
'price_ttc']);
698 unset($_POST[
'fourn_ref']);
699 unset($_POST[
'tva_tx']);
700 unset($_POST[
'label']);
701 unset($localtax1_tx);
702 unset($localtax2_tx);
703 unset($_POST[
'np_marginRate']);
704 unset($_POST[
'np_markRate']);
705 unset($_POST[
'dp_desc']);
706 unset($_POST[
'idprodfournprice']);
707 unset($_POST[
'units']);
709 unset($_POST[
'date_starthour']);
710 unset($_POST[
'date_startmin']);
711 unset($_POST[
'date_startsec']);
712 unset($_POST[
'date_startday']);
713 unset($_POST[
'date_startmonth']);
714 unset($_POST[
'date_startyear']);
715 unset($_POST[
'date_endhour']);
716 unset($_POST[
'date_endmin']);
717 unset($_POST[
'date_endsec']);
718 unset($_POST[
'date_endday']);
719 unset($_POST[
'date_endmonth']);
720 unset($_POST[
'date_endyear']);
732 if ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
739 $res = $line->fetch($lineid);
746 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
747 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0,
price2num(
GETPOST(
'qty',
'int')), $line->fk_product,
'none',
GETPOST(
'socid',
'int')) < 0) {
748 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"), null,
'warnings');
757 if (preg_match(
'/\*/', $vat_rate)) {
762 $vat_rate = str_replace(
'*',
'', $vat_rate);
763 $localtax1_rate =
get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
764 $localtax2_rate =
get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
766 if (
GETPOST(
'price_ht') !=
'') {
767 $price_base_type =
'HT';
771 $vatratecleaned = $vat_rate;
772 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) {
773 $vatratecleaned = trim($reg[1]);
774 $vatratecode = $reg[2];
778 $ht = $ttc / (1 + ($vatratecleaned / 100));
779 $price_base_type =
'HT';
785 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
786 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
788 if (is_array($extralabelsline)) {
789 foreach ($extralabelsline as $key => $value) {
790 unset($_POST[
"options_".$key]);
794 $result = $object->updateline(
796 GETPOST(
'product_desc',
'restricthtml'),
814 unset($_POST[
'qty']);
815 unset($_POST[
'type']);
816 unset($_POST[
'idprodfournprice']);
817 unset($_POST[
'remmise_percent']);
818 unset($_POST[
'dp_desc']);
819 unset($_POST[
'np_desc']);
821 unset($_POST[
'fourn_ref']);
822 unset($_POST[
'tva_tx']);
823 unset($_POST[
'date_start']);
824 unset($_POST[
'date_end']);
825 unset($_POST[
'units']);
826 unset($localtax1_tx);
827 unset($localtax2_tx);
829 unset($_POST[
'date_starthour']);
830 unset($_POST[
'date_startmin']);
831 unset($_POST[
'date_startsec']);
832 unset($_POST[
'date_startday']);
833 unset($_POST[
'date_startmonth']);
834 unset($_POST[
'date_startyear']);
835 unset($_POST[
'date_endhour']);
836 unset($_POST[
'date_endmin']);
837 unset($_POST[
'date_endsec']);
838 unset($_POST[
'date_endday']);
839 unset($_POST[
'date_endmonth']);
840 unset($_POST[
'date_endyear']);
844 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
845 $outputlangs = $langs;
847 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
848 $newlang =
GETPOST(
'lang_id',
'aZ09');
850 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
851 $newlang = $object->thirdparty->default_lang;
853 if (!empty($newlang)) {
855 $outputlangs->setDefaultLang($newlang);
857 $model = $object->model_pdf;
858 $ret = $object->fetch($id);
860 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
875 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
878 $result = $object->deleteline($lineid);
881 $object->line_order(
true);
883 $outputlangs = $langs;
885 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
886 $newlang =
GETPOST(
'lang_id',
'aZ09');
888 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
889 $newlang = $object->thirdparty->default_lang;
891 if (!empty($newlang)) {
893 $outputlangs->setDefaultLang($newlang);
895 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
896 $ret = $object->fetch($object->id);
897 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
909 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
917 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
920 $object->date_commande =
dol_now();
921 $result = $object->valid($user);
924 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
925 $outputlangs = $langs;
927 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
928 $newlang =
GETPOST(
'lang_id',
'aZ09');
930 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
931 $newlang = $object->thirdparty->default_lang;
933 if (!empty($newlang)) {
935 $outputlangs->setDefaultLang($newlang);
937 $model = $object->model_pdf;
938 $ret = $object->fetch($id);
940 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
952 if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) {
953 $action =
'confirm_approve';
963 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
966 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
968 $qualified_for_stock_change = 0;
969 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
970 $qualified_for_stock_change = $object->hasProductsOrServices(2);
972 $qualified_for_stock_change = $object->hasProductsOrServices(1);
976 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
977 if (!$idwarehouse || $idwarehouse == -1) {
979 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
985 $result = $object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
987 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
988 $outputlangs = $langs;
990 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
991 $newlang =
GETPOST(
'lang_id',
'aZ09');
993 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
994 $newlang = $object->thirdparty->default_lang;
996 if (!empty($newlang)) {
998 $outputlangs->setDefaultLang($newlang);
1000 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1011 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1018 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1020 $object->refuse_note =
GETPOST(
'refuse_note');
1022 $result = $object->refuse($user);
1024 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1032 if ($action ==
'commande') {
1033 $methodecommande =
GETPOST(
'methodecommande',
'int');
1037 } elseif ($methodecommande <= 0) {
1038 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")), null,
'errors');
1039 $action =
'makeorder';
1043 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1046 $result = $object->commande($user,
GETPOST(
"datecommande"),
GETPOST(
"methode",
'int'),
GETPOST(
'comment',
'alphanohtml'));
1048 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1049 $outputlangs = $langs;
1051 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1052 $newlang =
GETPOST(
'lang_id',
'aZ09');
1054 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1055 $newlang = $object->thirdparty->default_lang;
1057 if (!empty($newlang)) {
1058 $outputlangs =
new Translate(
"", $conf);
1059 $outputlangs->setDefaultLang($newlang);
1061 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1072 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1080 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1081 $result = $object->delete($user);
1083 header(
"Location: ".DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1');
1091 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1092 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1093 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"), null,
'errors');
1095 if ($object->id > 0) {
1096 $orig = clone $object;
1098 $result = $object->createFromClone($user, $socid);
1100 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1112 if ($action ==
'livraison' && $usercanreceive) {
1121 $result = $object->Livraison($user, $date_liv,
GETPOST(
"type"),
GETPOST(
"comment"));
1123 $langs->load(
"deliveries");
1126 } elseif ($result == -3) {
1135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")), null,
'errors');
1146 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1148 $object->cancel_note =
GETPOST(
'cancel_note');
1150 $result = $object->cancel($user);
1152 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
1160 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1163 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1164 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1165 $trackid =
'sord'.$object->id;
1166 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1169 $upload_dir = $conf->fournisseur->commande->dir_output;
1170 $permissiontoadd = $usercancreate;
1171 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1174 if ($action ==
'update_extras') {
1178 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
1186 $result = $object->insertExtraFields(
'ORDER_SUPPLIER_MODIFY');
1195 $action =
'edit_extras';
1202 if ($action ==
'add' && $usercancreate) {
1204 $selectedLines =
GETPOST(
'toselect',
'array');
1206 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')), null,
'errors');
1215 $object->ref_supplier =
GETPOST(
'refsupplier');
1216 $object->socid = $socid;
1217 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1218 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1219 $object->fk_account =
GETPOST(
'fk_account',
'int');
1220 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
1221 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
1222 $object->date_livraison = $datelivraison;
1223 $object->delivery_date = $datelivraison;
1224 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
1225 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1226 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1227 $object->multicurrency_tx =
price2num(
GETPOST(
'originmulticurrency_tx',
'alpha'));
1228 $object->fk_project =
GETPOST(
'projectid',
'int');
1232 $ret = $extrafields->setOptionalsFromPost(null, $object);
1240 if (!empty($origin) && !empty($originid)) {
1241 $element = $subelement = $origin;
1242 $classname = ucfirst($subelement);
1243 if ($origin ==
'propal' || $origin ==
'proposal') {
1244 $element =
'comm/propal'; $subelement =
'propal';
1245 $classname =
'Propal';
1247 if ($origin ==
'order' || $origin ==
'commande') {
1248 $element = $subelement =
'commande';
1249 $classname =
'Commande';
1251 if ($origin ==
'supplier_proposal') {
1252 $classname =
'SupplierProposal';
1253 $element =
'supplier_proposal';
1254 $subelement =
'supplier_proposal';
1257 $object->origin = $origin;
1258 $object->origin_id = $originid;
1261 $object->linked_objects [$object->origin] = $object->origin_id;
1262 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1263 if (!empty($other_linked_objects)) {
1264 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
1267 $id = $object->create($user);
1271 $srcobject =
new $classname($db);
1273 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
1274 $result = $srcobject->fetch($object->origin_id);
1276 $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
1277 $object->setDeliveryDate($user, $tmpdate);
1278 $object->set_id_projet($user, $srcobject->fk_project);
1280 $lines = $srcobject->lines;
1281 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1282 $srcobject->fetch_lines();
1283 $lines = $srcobject->lines;
1286 $fk_parent_line = 0;
1287 $num = count($lines);
1289 for ($i = 0; $i < $num; $i++) {
1290 if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->
id, $selectedLines)) {
1294 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1295 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
1296 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1299 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1300 $fk_parent_line = 0;
1304 if (method_exists($lines[$i],
'fetch_optionals')) {
1305 $lines[$i]->fetch_optionals();
1306 $array_option = $lines[$i]->array_options;
1310 $product_fourn_price_id = 0;
1311 if ($origin ==
"commande") {
1313 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
1315 $ref_supplier = $productsupplier->ref_supplier;
1316 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1319 $ref_supplier = $lines[$i]->ref_fourn;
1320 $product_fourn_price_id = 0;
1323 $tva_tx = $lines[$i]->tva_tx;
1325 if ($origin ==
"commande") {
1326 $soc =
new societe($db);
1327 $soc->fetch($socid);
1328 $tva_tx =
get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1331 $object->special_code = $lines[$i]->special_code;
1333 $result = $object->addline(
1335 $lines[$i]->subprice,
1338 $lines[$i]->localtax1_tx,
1339 $lines[$i]->localtax2_tx,
1340 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1341 $product_fourn_price_id,
1343 $lines[$i]->remise_percent,
1346 $lines[$i]->product_type,
1352 $lines[$i]->fk_unit,
1355 !empty($lines[$i]->
id) ? $lines[$i]->
id : $lines[$i]->
rowid
1364 if ($result > 0 && $lines[$i]->product_type == 9) {
1365 $fk_parent_line = $result;
1373 $parameters = array(
'objFrom' => $srcobject);
1374 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1388 $id = $object->create($user);
1397 $langs->load(
"errors");
1400 $_GET[
'socid'] = $_POST[
'socid'];
1403 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode($id));
1409 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') ==
"send" && !
GETPOST(
'cancel',
'alpha')) {
1410 $ws_url = $object->thirdparty->webservices_url;
1411 $ws_key = $object->thirdparty->webservices_key;
1412 $ws_user =
GETPOST(
'ws_user',
'alpha');
1413 $ws_password =
GETPOST(
'ws_password',
'alpha');
1414 $ws_entity =
GETPOST(
'ws_entity',
'int');
1415 $ws_thirdparty =
GETPOST(
'ws_thirdparty',
'int');
1418 $ws_ns =
'http://www.dolibarr.org/ns/';
1419 $ws_authentication = array(
1420 'dolibarrkey'=>$ws_key,
1421 'sourceapplication'=>
'DolibarrWebServiceClient',
1423 'password'=>$ws_password,
1424 'entity'=>$ws_entity
1428 if (empty($conf->syncsupplierwebservices->enabled)) {
1429 setEventMessages($langs->trans(
"WarningModuleNotActive", $langs->transnoentities(
"Module2650Name")), null,
'mesgs');
1430 } elseif (empty($ws_url) || empty($ws_key)) {
1431 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), null,
'errors');
1432 } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1436 $soapclient_order =
new nusoap_client($ws_url.
"/webservices/server_order.php");
1437 $soapclient_order->soap_defencoding =
'UTF-8';
1438 $soapclient_order->decodeUTF8(
false);
1441 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
1442 $soapclient_product->soap_defencoding =
'UTF-8';
1443 $soapclient_product->decodeUTF8(
false);
1446 $order_lines = array();
1447 foreach ($object->lines as $line) {
1448 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $line->ref_supplier);
1449 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
1451 if ($result_product[
"result"][
"result_code"] ==
"OK") {
1452 $order_lines[] = array(
1453 'desc' => $line->product_desc,
1454 'type' => $line->product_type,
1455 'product_id' => $result_product[
"product"][
"id"],
1456 'vat_rate' => $line->tva_tx,
1457 'qty' => $line->qty,
1458 'price' => $line->price,
1459 'unitprice' => $line->subprice,
1460 'total_net' => $line->total_ht,
1461 'total_vat' => $line->total_tva,
1462 'total' => $line->total_ttc,
1463 'date_start' => $line->date_start,
1464 'date_end' => $line->date_end,
1471 'thirdparty_id' => $ws_thirdparty,
1473 'total_net' => $object->total_ht,
1474 'total_var' => $object->total_tva,
1475 'total' => $object->total_ttc,
1476 'lines' => $order_lines
1479 $ws_parameters = array(
'authentication'=>$ws_authentication,
'order' => $order);
1480 $result_order = $soapclient_order->call(
"createOrder", $ws_parameters, $ws_ns,
'');
1482 if (empty($result_order[
"result"][
"result_code"])) {
1483 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", null,
'errors');
1484 } elseif ($result_order[
"result"][
"result_code"] !=
"OK") {
1485 setEventMessages($langs->trans(
"SOAPError").
" '".$result_order[
"result"][
"result_code"].
"' - '".$result_order[
"result"][
"result_label"].
"'", null,
'errors');
1487 setEventMessages($langs->trans(
"RemoteOrderRef").
" ".$result_order[
"ref"], null,
'mesgs');
1492 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1493 if ($action ==
'addcontact') {
1494 if ($object->id > 0) {
1497 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1501 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1504 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1505 $langs->load(
"errors");
1506 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
1511 } elseif ($action ==
'swapstatut' && $object->id > 0) {
1513 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1514 } elseif ($action ==
'deletecontact' && $object->id > 0) {
1516 $result = $object->delete_contact(
GETPOST(
"lineid",
'int'));
1519 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1536 $productstatic =
new Product($db);
1537 if (!empty($conf->project->enabled)) {
1541 $title = $langs->trans(
'SupplierOrder').
" - ".$langs->trans(
'Card');
1542 $help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1547 if ($action ==
'create') {
1548 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1552 $currency_code = $conf->currency;
1557 $societe->fetch($socid);
1560 if (!empty($origin) && !empty($originid)) {
1562 $element = $subelement = $origin;
1563 $classname = ucfirst($subelement);
1565 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1566 $element = $regs[1];
1567 $subelement = $regs[2];
1570 if ($origin ==
'propal' || $origin ==
'proposal') {
1571 $classname =
'Propal';
1572 $element =
'comm/propal'; $subelement =
'propal';
1574 if ($origin ==
'order' || $origin ==
'commande') {
1575 $classname =
'Commande';
1576 $element = $subelement =
'commande';
1578 if ($origin ==
'supplier_proposal') {
1579 $classname =
'SupplierProposal';
1580 $element =
'supplier_proposal';
1581 $subelement =
'supplier_proposal';
1588 $objectsrc =
new $classname($db);
1589 $objectsrc->fetch($originid);
1590 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1591 $objectsrc->fetch_lines();
1593 $objectsrc->fetch_thirdparty();
1596 $objectsrc->fetch_optionals();
1597 $object->array_options = $objectsrc->array_options;
1599 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1600 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1602 $soc = $objectsrc->client;
1603 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1604 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1605 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1606 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1607 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1608 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1609 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1610 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1611 $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
'';
1613 $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
''));
1615 if (!empty($conf->multicurrency->enabled)) {
1616 if (!empty($objectsrc->multicurrency_code)) {
1617 $currency_code = $objectsrc->multicurrency_code;
1619 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1620 $currency_tx = $objectsrc->multicurrency_tx;
1624 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1625 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1628 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1630 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
1631 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
1633 if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) {
1634 $currency_code = $societe->multicurrency_code;
1637 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1638 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1642 if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) {
1643 $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
1645 if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) {
1646 $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
1649 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1650 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1651 print
'<input type="hidden" name="action" value="add">';
1652 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
1653 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1654 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1656 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1658 if ($backtopageforcancel) {
1659 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
1662 if (!empty($currency_tx)) {
1663 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1668 print
'<table class="border centpercent">';
1671 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
1674 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
1677 if (!empty($societe->id) && $societe->id > 0) {
1678 print $societe->getNomUrl(1,
'supplier');
1679 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
1681 print
img_picto(
'',
'company').$form->select_company((empty($socid) ?
'' : $socid),
'socid',
's.fournisseur=1',
'SelectThirdParty', 0, 0, null, 0,
'minwidth300');
1683 if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) {
1685 $(document).ready(function() {
1686 $("#socid").change(function() {
1687 var socid = $(this).val();
1688 var prjid = $("#projectid").val();
1690 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?action=create&socid="+socid+"&projectid="+prjid
1695 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>';
1699 if (!empty($societe->id) && $societe->id > 0) {
1701 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1703 $absolute_discount = $societe->getAvailableDiscounts(
'',
'', 0, 1);
1705 $thirdparty = $societe;
1707 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1708 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1714 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td><td><input name="refsupplier" type="text"></td>';
1718 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1719 $form->select_conditions_paiements(
GETPOSTISSET(
'cond_reglement_id') ?
GETPOST(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id');
1723 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1724 $form->select_types_paiements(
GETPOSTISSET(
'mode_reglement_id') ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
1729 print $langs->trans(
'DateDeliveryPlanned');
1733 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1736 print
$form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin,
'',
"set");
1740 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled)) {
1741 $langs->load(
"bank");
1742 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1743 print
img_picto(
'',
'bank_account',
'class="paddingrightonly"');
1744 $form->select_comptes($fk_account,
'fk_account', 0,
'', 1);
1749 if (!empty($conf->project->enabled)) {
1752 $langs->load(
'projects');
1753 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
1754 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');
1755 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>';
1760 if (!empty($conf->incoterm->enabled)) {
1761 $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
1762 $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
1764 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $object->label_incoterms, 1).
'</label></td>';
1765 print
'<td class="maxwidthonsmartphone">';
1766 print
$form->select_incoterms($fkincoterms, $locincoterms);
1771 if (!empty($conf->multicurrency->enabled)) {
1773 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
1774 print
'<td class="maxwidthonsmartphone">';
1775 print
$form->selectMultiCurrency($currency_code,
'multicurrency_code');
1779 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
1781 $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%');
1782 print $doleditor->Create(1);
1787 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
1789 $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%');
1790 print $doleditor->Create(1);
1795 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1796 print
"\n<!-- ".$classname.
" info -->";
1798 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1799 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1800 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1801 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1802 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1804 $newclassname = $classname;
1805 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
1806 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1807 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1808 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1809 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1812 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1813 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1816 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1818 if (!empty($conf->multicurrency->enabled)) {
1819 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1820 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
'</td></tr>';
1821 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
'</td></tr>';
1826 $parameters = array();
1827 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1828 print $hookmanager->resPrint;
1830 if (empty($reshook)) {
1831 print $object->showOptionals($extrafields,
'create');
1839 print
$form->buttonsSaveCancel(
"CreateDraft");
1842 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1843 $title = $langs->trans(
'ProductsAndServices');
1846 print
'<div class="div-table-responsive-no-min">';
1847 print
'<table class="noborder centpercent">';
1849 $objectsrc->printOriginLinesList(
'', $selectedLines);
1855 } elseif (!empty($object->id)) {
1856 $result = $object->fetch($id, $ref);
1859 $result = $societe->fetch($object->socid);
1864 $author =
new User($db);
1865 $author->fetch($object->user_author_id);
1867 $res = $object->fetch_optionals();
1872 $title = $langs->trans(
"SupplierOrder");
1879 if ($action ==
'delete') {
1880 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 2);
1884 if ($action ==
'clone') {
1886 $formquestion = array(
1887 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.fournisseur=1)'))
1890 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1894 if ($action ==
'valid') {
1895 $object->date_commande =
dol_now();
1898 if (preg_match(
'/^[\(]?PROV/i', $object->ref) || empty($object->ref)) {
1899 $newref = $object->getNextNumRef($object->thirdparty);
1901 $newref = $object->ref;
1908 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
1909 if (!empty($conf->notification->enabled)) {
1910 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1911 $notify =
new Notify($db);
1913 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
1916 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
1921 if ($action ==
'approve' || $action ==
'approve2') {
1922 $qualified_for_stock_change = 0;
1923 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1924 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1926 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1929 $formquestion = array();
1930 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) {
1931 $langs->load(
"stocks");
1932 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1935 if ($conf->browser->name ==
'ie') {
1938 $formquestion = array(
1942 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse',
'int'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
1945 $text = $langs->trans(
"ConfirmApproveThisOrder", $object->ref);
1946 if (!empty($conf->notification->enabled)) {
1947 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1948 $notify =
new Notify($db);
1950 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE', $object->socid, $object);
1953 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
1957 if ($action ==
'refuse') {
1958 $formquestion = array(
1961 'name' =>
'refuse_note',
1962 'label' => $langs->trans(
"Reason"),
1964 'morecss' =>
'minwidth300'
1967 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder", $object->ref),
"confirm_refuse", $formquestion, 0, 1);
1971 if ($action ==
'cancel') {
1972 $formquestion = array(
1975 'name' =>
'cancel_note',
1976 'label' => $langs->trans(
"Reason"),
1978 'morecss' =>
'minwidth300'
1981 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder", $object->ref),
"confirm_cancel", $formquestion, 0, 1);
1985 if ($action ==
'commande') {
1987 $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);
1991 if ($action ==
'ask_deleteline') {
1992 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
1995 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid'=>$lineid);
1996 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1997 if (empty($reshook)) {
1999 } elseif ($reshook > 0) {
2009 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2011 $morehtmlref =
'<div class="refidno">';
2013 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', 0, 1);
2014 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $usercancreate,
'string',
'', null, null,
'', 1);
2016 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty');
2017 if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2018 $morehtmlref .=
' : ';
2019 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2020 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2021 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2022 $morehtmlref .=
$form->select_company($object->thirdparty->id,
'new_socid',
's.fournisseur=1',
'', 0, 0, array(), 0,
'minwidth300');
2023 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2024 $morehtmlref .=
'</form>';
2026 if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action !=
'edit_thirdparty') {
2028 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2030 $morehtmlref .=
' : '.$object->thirdparty->getNomUrl(1,
'supplier');
2031 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2032 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.$object->thirdparty->id.
'&search_company='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2037 if (!empty($conf->project->enabled)) {
2038 $langs->load(
"projects");
2039 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2040 if ($usercancreate) {
2041 if ($action !=
'classify' && $caneditproject) {
2042 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2044 if ($action ==
'classify') {
2046 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2047 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2048 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2049 $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project,
'projectid', 0, 0, 1, 1, 1, 0, 0,
'', 1, 0,
'maxwidth500');
2050 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2051 $morehtmlref .=
'</form>';
2053 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2056 if (!empty($object->fk_project)) {
2058 $proj->fetch($object->fk_project);
2059 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2061 $morehtmlref .=
' - '.$proj->title;
2068 $morehtmlref .=
'</div>';
2071 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2074 print
'<div class="fichecenter">';
2075 print
'<div class="fichehalfleft">';
2076 print
'<div class="underbanner clearboth"></div>';
2078 print
'<table class="border tableforfield centpercent">';
2081 if ($object->methode_commande_id > 0) {
2082 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2083 print $object->date_commande ?
dol_print_date($object->date_commande, $usehourmin ?
'dayhour' :
'day') :
'';
2084 if ($object->hasDelay() && !empty($object->date_delivery) && !empty($object->date_commande)) {
2085 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2089 if ($object->methode_commande) {
2090 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.$object->getInputMethod().
'</td></tr>';
2095 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2096 print
'<td>'.$author->getNomUrl(1,
'', 0, 0, 0).
'</td>';
2100 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2101 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2102 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2104 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2105 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2108 $absolute_discount = $societe->getAvailableDiscounts(
'', $filterabsolutediscount, 0, 1);
2109 $absolute_creditnote = $societe->getAvailableDiscounts(
'', $filtercreditnote, 0, 1);
2110 $absolute_discount =
price2num($absolute_discount,
'MT');
2111 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2113 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2115 $thirdparty = $societe;
2117 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2118 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2123 $langs->load(
'bills');
2124 print
'<tr><td class="nowrap">';
2125 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2126 print $langs->trans(
'PaymentConditions');
2128 if ($action !=
'editconditions') {
2129 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>';
2131 print
'</tr></table>';
2133 if ($action ==
'editconditions') {
2134 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id');
2136 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none');
2142 $langs->load(
'bills');
2143 print
'<tr><td class="nowrap">';
2144 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2145 print $langs->trans(
'PaymentMode');
2147 if ($action !=
'editmode') {
2148 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>';
2150 print
'</tr></table>';
2152 if ($action ==
'editmode') {
2153 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2155 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2160 if (!empty($conf->multicurrency->enabled)) {
2164 print
'<table class="nobordernopadding centpercent"><tr><td>';
2165 print
$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0);
2167 if ($action !=
'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
2168 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>';
2170 print
'</tr></table>';
2172 if ($action ==
'editmulticurrencycode') {
2173 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2175 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2180 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2183 print
'<table class="nobordernopadding centpercent"><tr>';
2185 print
$form->editfieldkey(
'CurrencyRate',
'multicurrency_tx',
'', $object, 0);
2187 if ($action !=
'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2188 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>';
2190 print
'</tr></table>';
2192 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2193 if ($action ==
'actualizemulticurrencyrate') {
2196 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2198 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2199 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2200 print
'<div class="inline-block"> ';
2201 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2210 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled)) {
2211 print
'<tr><td class="nowrap">';
2212 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2213 print $langs->trans(
'BankAccount');
2215 if ($action !=
'editbankaccount' && $usercancreate) {
2216 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>';
2218 print
'</tr></table>';
2220 if ($action ==
'editbankaccount') {
2221 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2223 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2231 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.
img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2232 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2237 print
'<table class="nobordernopadding centpercent"><tr><td>';
2238 print $langs->trans(
'DateDeliveryPlanned');
2240 if ($action !=
'editdate_livraison') {
2241 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>';
2243 print
'</tr></table>';
2245 if ($action ==
'editdate_livraison') {
2246 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2247 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2248 print
'<input type="hidden" name="action" value="setdate_livraison">';
2250 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2253 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin,
'',
"setdate_livraison");
2254 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2257 $usehourmin =
'day';
2258 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
2259 $usehourmin =
'dayhour';
2261 print $object->delivery_date ?
dol_print_date($object->delivery_date, $usehourmin) :
' ';
2262 if ($object->hasDelay() && !empty($object->delivery_date)) {
2263 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2269 if (!empty($conf->incoterm->enabled)) {
2271 print
'<table class="nobordernopadding centpercent"><tr><td>';
2272 print $langs->trans(
'IncotermLabel');
2273 print
'<td><td class="right">';
2274 if ($usercancreate) {
2275 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
2279 print
'</td></tr></table>';
2282 if ($action !=
'editincoterm') {
2285 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2291 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2296 print
'<div class="fichehalfright">';
2297 print
'<div class="underbanner clearboth"></div>';
2299 print
'<table class="border tableforfield centpercent">';
2301 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2303 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2304 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>';
2308 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2309 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>';
2313 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2314 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>';
2320 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
2321 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->supplier_order_min_amount));
2323 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
2324 print
'<td class="nowrap right amountcard">'.price($object->total_ht,
'', $langs, 1, -1, -1, $conf->currency).$alert.
'</td>';
2328 print
'<tr><td>'.$langs->trans(
"AmountVAT").
'</td>';
2329 print
'<td class="nowrap right amountcard">'.price($object->total_tva,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2333 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2334 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2335 print
'<td class="nowrap right amountcard">'.price($object->total_localtax1,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2338 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2339 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2340 print
'<td class="nowrap right amountcard">'.price($object->total_localtax2,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2345 print
'<tr><td>'.$langs->trans(
"AmountTTC").
'</td>';
2346 print
'<td class="nowrap right amountcard">'.price($object->total_ttc,
'', $langs, 1, -1, -1, $conf->currency).
'</td>';
2360 print
'<div class="clearboth"></div><br>';
2362 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2363 $blocname =
'contacts';
2364 $title = $langs->trans(
'ContactsAddresses');
2365 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2368 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2369 $blocname =
'notes';
2370 $title = $langs->trans(
'Notes');
2371 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2380 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2381 <input type="hidden" name="token" value="'.
newToken().
'">
2382 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2383 <input type="hidden" name="mode" value="">
2384 <input type="hidden" name="page_y" value="">
2385 <input type="hidden" name="id" value="'.$object->id.
'">
2386 <input type="hidden" name="socid" value="'.$societe->id.
'">
2389 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
2390 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2393 print
'<div class="div-table-responsive-no-min">';
2394 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2397 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2398 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
2399 $senderissupplier = 2;
2400 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
2401 $senderissupplier = 1;
2405 if (!empty($object->lines)) {
2406 $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
2409 $num = count($object->lines);
2413 if ($action !=
'editline') {
2416 $parameters = array();
2417 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2418 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2419 if (empty($reshook))
2420 $object->formAddObjectLine(1, $societe, $mysoc);
2433 if ($user->socid == 0 && $action !=
'editline' && $action !=
'delete') {
2434 print
'<div class="tabsAction">';
2436 $parameters = array();
2437 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2439 if (empty($reshook)) {
2440 $object->fetchObjectLinked();
2443 if ($object->statut == 0 && $num > 0) {
2444 if ($usercanvalidate) {
2445 $tmpbuttonlabel = $langs->trans(
'Validate');
2446 if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
2447 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
2450 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid">';
2451 print $tmpbuttonlabel;
2463 if ($usercanorder) {
2464 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
2470 if ($usercanapprove) {
2471 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)) {
2472 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2474 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve">'.$langs->trans(
"ApproveOrder").
'</a>';
2477 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
2482 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
2484 if ($usercanapprovesecond) {
2485 if (!empty($object->user_approve_id2)) {
2486 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2488 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=approve2">'.$langs->trans(
"Approve2Order").
'</a>';
2491 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
2498 if ($usercanapprove || $usercanapprovesecond) {
2499 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse">'.$langs->trans(
"RefuseOrder").
'</a>';
2501 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
2506 if (empty($user->socid)) {
2508 if ($usercanorder) {
2509 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
2517 if (!$buttonshown && $usercanapprove) {
2518 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
2519 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) {
2520 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2524 if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
2525 if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
2526 || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) {
2527 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
2531 if (in_array($object->statut, array(3, 4, 5, 6, 7, 9))) {
2532 if ($usercanorder) {
2533 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
2539 if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) {
2540 $labelofbutton = $langs->trans(
'ReceiveProducts');
2541 if ($conf->reception->enabled) {
2542 $labelofbutton = $langs->trans(
"CreateReception");
2543 if (!empty($object->linkedObjects[
'reception'])) {
2544 foreach ($object->linkedObjects[
'reception'] as $element) {
2545 if ($element->statut >= 0) {
2553 if (in_array($object->statut, array(3, 4, 5))) {
2554 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) && $usercanreceive) {
2555 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.$object->id.
'">'.$labelofbutton.
'</a></div>';
2557 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
2563 if ($usercanorder) {
2564 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=makeorder#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
2566 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
2572 if ($usercanreceive) {
2573 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>';
2580 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled)) && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1)) {
2581 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2582 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>';
2588 if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1) {
2590 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2592 if (!empty($object->linkedObjectsIds[
'invoice_supplier'])) {
2593 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
2594 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2597 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
2603 if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2) {
2604 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=webservice&token='.
newToken().
'&mode=init">'.$langs->trans(
'CreateRemoteOrder').
'</a>';
2608 if ($usercancreate) {
2609 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=order">'.$langs->trans(
"ToClone").
'</a>';
2614 if ($usercanorder) {
2615 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel">'.$langs->trans(
"CancelOrder").
'</a>';
2620 if (!empty($usercandelete)) {
2621 if ($hasreception) {
2622 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
2624 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a>';
2635 print
'<!-- form to record supplier order -->'.
"\n";
2636 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
2638 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2639 print
'<input type="hidden" name="action" value="commande">';
2641 print
'<table class="noborder centpercent">';
2643 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
2644 $date_com =
dol_mktime(
GETPOST(
'rehour',
'int'),
GETPOST(
'remin',
'int'),
GETPOST(
'resec',
'int'),
GETPOST(
'remonth',
'int'),
GETPOST(
'reday',
'int'),
GETPOST(
'reyear',
'int'));
2645 if (empty($date_com)) {
2648 print
$form->selectDate($date_com,
'', 1, 1,
'',
"commande", 1, 1);
2652 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
2653 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
2656 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
2657 print
'<tr><td class="center" colspan="2">';
2658 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
2659 print
' ';
2660 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2668 if ($action !=
'makeorder') {
2669 print
'<div class="fichecenter"><div class="fichehalfleft">';
2673 $file = $conf->fournisseur->dir_output.
'/commande/'.$objref.
'/'.$objref.
'.pdf';
2674 $relativepath = $objref.
'/'.$objref.
'.pdf';
2675 $filedir = $conf->fournisseur->dir_output.
'/commande/'.$objref;
2676 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2677 $genallowed = $usercanread;
2678 $delallowed = $usercancreate;
2679 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) ?
'' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF));
2681 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'', $object->thirdparty->default_lang,
'', $object);
2682 $somethingshown = $formfile->numoffiles;
2685 $linktoelem =
$form->showLinkToObjectBlock($object, null, array(
'supplier_order',
'order_supplier'));
2686 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2688 print
'</div><div class="fichehalfright">';
2690 if ($action ==
'classifyreception') {
2693 print
'<!-- form to record purchase order received -->'.
"\n";
2694 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
2695 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2696 print
'<input type="hidden" name="action" value="livraison">';
2699 print
'<table class="noborder centpercent">';
2701 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
2703 print
$form->selectDate($datepreselected,
'', 1, 1,
'',
"commande", 1, 1);
2704 print
"</td></tr>\n";
2706 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
2708 $liv[
''] =
' ';
2709 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
2710 $liv[
'par'] = $langs->trans(
"PartialWoman");
2711 $liv[
'nev'] = $langs->trans(
"NeverReceived");
2712 $liv[
'can'] = $langs->trans(
"Canceled");
2714 print
$form->selectarray(
"type", $liv);
2717 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input size="40" type="text" name="comment"></td></tr>';
2718 print
'<tr><td class="center" colspan="2">';
2719 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
2720 print
' ';
2721 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
2730 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2732 $somethingshown =
$formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
2734 print
'</div></div>';
2740 if ($action ==
'webservice' &&
GETPOST(
'mode',
'alpha') !=
"send" && !
GETPOST(
'cancel',
'alpha')) {
2741 $mode =
GETPOST(
'mode',
'alpha');
2742 $ws_url = $object->thirdparty->webservices_url;
2743 $ws_key = $object->thirdparty->webservices_key;
2744 $ws_user =
GETPOST(
'ws_user',
'alpha');
2745 $ws_password =
GETPOST(
'ws_password',
'alpha');
2748 $ws_ns =
'http://www.dolibarr.org/ns/';
2749 $ws_authentication = array(
2750 'dolibarrkey'=>$ws_key,
2751 'sourceapplication'=>
'DolibarrWebServiceClient',
2753 'password'=>$ws_password,
2760 if (empty($ws_url) || empty($ws_key)) {
2761 setEventMessages($langs->trans(
"ErrorWebServicesFieldsRequired"), null,
'errors');
2763 $error_occurred =
true;
2764 } elseif ($mode !=
"init" && (empty($ws_user) || empty($ws_password))) {
2769 if ($mode ==
"init") {
2771 print
'<table class="border centpercent">';
2772 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2773 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2774 print
'<input type="hidden" name="action" value="webservice">';
2775 print
'<input type="hidden" name="mode" value="check">';
2777 if ($error_occurred) {
2778 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2779 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2781 $textinput_size =
"50";
2783 print
'<tr><td>'.$langs->trans(
"WebServiceURL").
'</td><td colspan="3">'.
dol_print_url($ws_url).
'</td></tr>';
2785 print
'<tr><td>'.$langs->trans(
"User").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_user"></td></tr>';
2787 print
'<tr><td>'.$langs->trans(
"Password").
'</td><td><input size="'.$textinput_size.
'" type="text" name="ws_password"></td></tr>';
2789 print
'<tr><td class="center" colspan="2">';
2790 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"CreateRemoteOrder").
'">';
2791 print
' ';
2793 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2800 } elseif ($mode ==
"check") {
2802 $ws_thirdparty =
'';
2803 $error_occurred =
false;
2806 $soapclient_user =
new nusoap_client($ws_url.
"/webservices/server_user.php");
2807 $soapclient_user->soap_defencoding =
'UTF-8';
2808 $soapclient_user->decodeUTF8(
false);
2811 $ws_parameters = array(
'authentication'=>$ws_authentication,
'id' =>
'',
'ref'=>$ws_user);
2812 $result_user = $soapclient_user->call(
"getUser", $ws_parameters, $ws_ns,
'');
2813 $user_status_code = $result_user[
"result"][
"result_code"];
2815 if ($user_status_code ==
"OK") {
2817 $ws_entity = $result_user[
"user"][
"entity"];
2818 $ws_authentication[
'entity'] = $ws_entity;
2819 $ws_thirdparty = $result_user[
"user"][
"fk_thirdparty"];
2820 if (empty($ws_thirdparty)) {
2821 setEventMessages($langs->trans(
"RemoteUserMissingAssociatedSoc"), null,
'errors');
2822 $error_occurred =
true;
2825 $soapclient_product =
new nusoap_client($ws_url.
"/webservices/server_productorservice.php");
2826 $soapclient_product->soap_defencoding =
'UTF-8';
2827 $soapclient_product->decodeUTF8(
false);
2831 foreach ($object->lines as $line) {
2833 $ref_supplier = $line->ref_supplier;
2834 $line_id = $i.
"º) ".$line->product_ref.
": ";
2835 if (empty($ref_supplier)) {
2838 $ws_parameters = array(
'authentication' => $ws_authentication,
'id' =>
'',
'ref' => $ref_supplier);
2839 $result_product = $soapclient_product->call(
"getProductOrService", $ws_parameters, $ws_ns,
'');
2840 if (!$result_product) {
2841 setEventMessages($line_id.$langs->trans(
"SOAPError").
" ".$soapclient_product->error_str.
" - ".$soapclient_product->response, null,
'errors');
2842 $error_occurred =
true;
2847 $status_code = $result_product[
"result"][
"result_code"];
2848 if (empty($status_code)) {
2849 setEventMessages($langs->trans(
"SOAPError").
" '".$soapclient_order->error_str.
"'", null,
'errors');
2850 } elseif ($status_code !=
"OK") {
2851 if ($status_code ==
"NOT_FOUND") {
2852 setEventMessages($line_id.$langs->trans(
"SupplierMissingRef").
" '".$ref_supplier.
"'", null,
'warnings');
2854 setEventMessages($line_id.$langs->trans(
"ResponseNonOK").
" '".$status_code.
"' - '".$result_product[
"result"][
"result_label"].
"'", null,
'errors');
2855 $error_occurred =
true;
2862 $supplier_price =
price($result_product[
"product"][
"price_net"]);
2863 $local_price = null;
2866 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2867 if (count($product_fourn_list) > 0) {
2868 foreach ($product_fourn_list as $product_fourn_line) {
2870 if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2871 $local_price =
price($product_fourn_line->fourn_price);
2876 if ($local_price != null && $local_price != $supplier_price) {
2877 setEventMessages($line_id.$langs->trans(
"RemotePriceMismatch").
" ".$supplier_price.
" - ".$local_price, null,
'warnings');
2881 if (empty($result_product[
"product"][
"status_tosell"])) {
2882 setEventMessages($line_id.$langs->trans(
"ProductStatusNotOnSellShort").
" '".$ref_supplier.
"'", null,
'warnings');
2886 } elseif ($user_status_code ==
"PERMISSION_DENIED") {
2887 setEventMessages($langs->trans(
"RemoteUserNotPermission"), null,
'errors');
2888 $error_occurred =
true;
2889 } elseif ($user_status_code ==
"BAD_CREDENTIALS") {
2890 setEventMessages($langs->trans(
"RemoteUserBadCredentials"), null,
'errors');
2891 $error_occurred =
true;
2893 setEventMessages($langs->trans(
"ResponseNonOK").
" '".$user_status_code.
"'", null,
'errors');
2894 $error_occurred =
true;
2898 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2899 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2900 print
'<input type="hidden" name="action" value="webservice">';
2901 print
'<input type="hidden" name="mode" value="send">';
2902 print
'<input type="hidden" name="ws_user" value="'.$ws_user.
'">';
2903 print
'<input type="hidden" name="ws_password" value="'.$ws_password.
'">';
2904 print
'<input type="hidden" name="ws_entity" value="'.$ws_entity.
'">';
2905 print
'<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.
'">';
2906 if ($error_occurred) {
2907 print
"<br>".$langs->trans(
"ErrorOccurredReviseAndRetry").
"<br>";
2909 print
'<input type="submit" class="button" id="ws_submit" name="ws_submit" value="'.$langs->trans(
"Confirm").
'">';
2910 print
' ';
2912 print
'<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2918 if (
GETPOST(
'modelselected')) {
2919 $action =
'presend';
2923 $modelmail =
'order_supplier_send';
2924 $defaulttopic =
'SendOrderRef';
2925 $diroutput = $conf->fournisseur->commande->dir_output;
2926 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
2927 $trackid =
'sord'.$object->id;
2929 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
const STATUS_ACCEPTED
Accepted.
const STATUS_DRAFT
Draft status.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_url($url, $target= '_blank', $max=32, $withpicto=0)
Show Url link.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_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...
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
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.
Class to manage suppliers.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
static getIdAndTxFromCode($dbs, $code, $date_document= '')
Get id and rate of currency from code.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
const STATUS_RECEIVED_PARTIALLY
Received partially.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_VALIDATED
Validated status.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
restrictedArea($user, $features, $objectid=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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_ORDERSENT
Order sent, shipment on process.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
$formconfirm
if ($action == 'delbookkeepingyear') {
Class to manage predefined suppliers products.
Class to manage line orders.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid