42require
'../../main.inc.php';
54require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/fourn.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
62require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/supplier_proposal/class/supplier_proposal.class.php';
71 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
74 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
75 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
77require_once NUSOAP_PATH.
'/nusoap.php';
80 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
84 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
85 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
89$langs->loadLangs(array(
'admin',
'orders',
'sendings',
'companies',
'bills',
'propal',
'receptions',
'supplier_proposal',
'products',
'stocks',
'productbatch'));
91 $langs->load(
'incoterm');
96$action =
GETPOST(
'action',
'alpha');
97$confirm =
GETPOST(
'confirm',
'alpha');
98$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'purchaseordercard';
99$cancel =
GETPOST(
'cancel',
'alpha');
101$backtopage =
GETPOST(
'backtopage',
'alpha');
102$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
109$origin =
GETPOST(
'origin',
'alpha');
112$stockDelete =
GETPOST(
'stockDelete',
'int');
123if ($user->isExternalUser()) {
124 $socid = $user->isExternalUser();
128$hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
133$extrafields->fetch_name_optionals_label(
$object->table_element);
136if ($id > 0 || !empty($ref)) {
137 $ret =
$object->fetch($id, $ref);
139 dol_print_error($db,
$object->error);
141 $ret =
$object->fetch_thirdparty();
143 dol_print_error($db,
$object->error);
145} elseif (!empty($socid) && $socid > 0) {
147 $ret =
$object->fetch_thirdparty();
149 dol_print_error($db,
$object->error);
154$isdraft = (isset(
$object->status) && (
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
155$result =
restrictedArea($user,
'fournisseur', $object,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
158$usercanread = ($user->hasRight(
"fournisseur",
"commande",
"lire") || $user->hasRight(
"supplier_order",
"lire"));
159$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
160$usercandelete = (($user->hasRight(
"fournisseur",
"commande",
"supprimer") || $user->hasRight(
"supplier_order",
"supprimer")) || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT));
163$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate")));
166$usercanapprove = $user->hasRight(
"fournisseur",
"commande",
"approuver");
167$usercanapprovesecond = $user->hasRight(
"fournisseur",
"commande",
"approve2");
168$usercanorder = $user->hasRight(
"fournisseur",
"commande",
"commander");
169$usercanupdateprices = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') ? ($user->hasRight(
"produit",
"creer") || $user->hasRight(
"service",
"creer")) : $user->hasRight(
"product",
"product_advance",
"write_supplier_prices"));
171 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
173 $usercanreceive = $user->hasRight(
"reception",
"creer");
177$permissionnote = $usercancreate;
178$permissiondellink = $usercancreate;
179$permissiontoedit = $usercancreate;
180$permissiontoadd = $usercancreate;
181$permissiontoeditextra = $permissiontoadd;
182if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
184 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
188$caneditproject =
false;
201$parameters = array(
'socid' => $socid);
202$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
204 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
207if (empty($reshook)) {
208 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
210 if (empty($backtopage) || ($cancel && empty($id))) {
211 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
212 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
213 $backtopage = $backurlforlist;
215 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
221 if (!empty($backtopageforcancel)) {
222 header(
"Location: ".$backtopageforcancel);
224 } elseif (!empty($backtopage)) {
225 header(
"Location: ".$backtopage);
231 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
233 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
235 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
237 if ($action ==
'setref_supplier' && $usercancreate) {
238 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
245 if ($action ==
'set_incoterms' && $usercancreate) {
253 if ($action ==
'setconditions' && $usercancreate) {
261 if ($action ==
'setmode' && $usercancreate) {
266 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
268 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
269 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
271 if (!in_array(
GETPOSTINT(
'calculation_mode'), array(1, 2))) {
272 $langs->load(
"compta");
273 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CalculationMode")),
null,
'errors');
274 $action =
'editmulticurrencyrate';
281 if ($action ==
'setbankaccount' && $usercancreate) {
289 if ($action ==
'setwarehouse' && $usercancreate) {
290 $result =
$object->setValueFrom(
'fk_warehouse',
GETPOSTINT(
'fk_warehouse'),
'',
null,
'int',
'', $user,
'ORDER_SUPPLIER_MODIFY');
297 if ($action ==
'setdate_livraison' && $usercancreate) {
298 $result =
$object->setDeliveryDate($user, $datelivraison);
305 if ($action ==
'classin' && $usercancreate && $caneditproject) {
306 $result =
$object->setProject($projectid);
313 if ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
318 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
323 $outputlangs = $langs;
329 $newlang =
$object->thirdparty->default_lang;
331 if (!empty($newlang)) {
333 $outputlangs->setDefaultLang($newlang);
334 $outputlangs->load(
'products');
338 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
341 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
349 if ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
350 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
351 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
355 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
356 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
357 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
363 if ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
373 if (!empty($new_socid) && $new_socid !=
$object->thirdparty->id) {
377 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
378 $sql .=
' SET fk_soc = '.((int) $new_socid);
379 $sql .=
' WHERE fk_soc = '.((int)
$object->thirdparty->id);
380 $sql .=
' AND rowid = '.((int)
$object->id);
382 $res = $db->query($sql);
390 foreach (
$object->lines as $l) {
391 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
392 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
393 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
394 $sql .=
' AND fk_soc = '.((int) $new_socid);
395 $sql .=
' ORDER BY unitprice ASC';
397 $resql = $db->query($sql);
399 $num_row = $db->num_rows($resql);
400 if (empty($num_row)) {
406 $l->ref_supplier =
'';
407 if ($l->update() < 0) {
408 setEventMessages($l->error, $l->errors,
'errors');
412 $obj = $db->fetch_object($resql);
413 $l->subprice = $obj->unitprice;
414 $l->total_ht = $obj->price;
415 $l->tva_tx = $obj->tva_tx;
416 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
417 $l->total_ttc = $l->total_ht + $l->total_tva;
418 $l->ref_supplier = $obj->ref_fourn;
419 if ($l->update() < 0) {
420 setEventMessages($l->error, $l->errors,
'errors');
424 dol_print_error($db);
431 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
435 if ($action ==
'setremisepercent' && $usercancreate) {
442 if ($action ==
'reopen' && $permissiontoadd) {
443 $resSetReopen =
$object->setReopen($user);
445 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
455 if ($action ==
'classifybilled' && $usercancreate) {
456 $ret =
$object->classifyBilled($user);
460 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
461 $ret =
$object->classifyUnBilled($user);
468 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
472 foreach (
$object->lines as $line) {
473 if ($line->product_type == 1) {
475 $line_price_base_type = $line->getPriceBaseType();
476 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
477 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, (
float) $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $line->info_bits, $line->product_type, 0, $alldate_start, $alldate_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
480 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
482 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
483 $remise_percent = str_replace(
'*',
'', $remise_percent);
484 foreach (
$object->lines as $line) {
486 $line_price_base_type = $line->getPriceBaseType();
487 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
488 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, (
float) $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line_price_base_type, $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
490 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
492 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
493 $vat_rate = str_replace(
'*',
'', $vat_rate);
496 foreach (
$object->lines as $line) {
497 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
501 $line_price_base_type = $line->getPriceBaseType();
502 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
503 $result =
$object->updateline($line->id, $line->desc, $line_pu, $line->qty, (
float) $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line_price_base_type, $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
505 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
508 $langs->load(
'subtotals');
510 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
513 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
524 $outputlangs = $langs;
525 $newlang =
GETPOST(
'lang_id',
'alpha');
527 $newlang =
$object->thirdparty->default_lang;
529 if (!empty($newlang)) {
531 $outputlangs->setDefaultLang($newlang);
534 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
539 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
541 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
544 $langs->load(
'subtotals');
546 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
547 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
549 $subtotal_options = array();
551 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
552 $value =
GETPOST($option,
'alphanohtml');
554 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
559 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
570 $outputlangs = $langs;
571 $newlang =
GETPOST(
'lang_id',
'alpha');
573 $newlang =
$object->thirdparty->default_lang;
575 if (!empty($newlang)) {
577 $outputlangs->setDefaultLang($newlang);
580 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
585 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
587 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
590 $langs->load(
'subtotals');
592 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
593 foreach (
$object->lines as $line) {
594 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
596 $depth = -$line->qty;
600 $subtotal_options = array();
602 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
603 $value =
GETPOST($option,
'alphanohtml');
605 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
610 if (isset($desc) && isset($depth)) {
611 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
614 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
623 $outputlangs = $langs;
624 $newlang =
GETPOST(
'lang_id',
'alpha');
626 $newlang =
$object->thirdparty->default_lang;
628 if (!empty($newlang)) {
630 $outputlangs->setDefaultLang($newlang);
633 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
638 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
640 } elseif ($action ==
'addline' && $usercancreate) {
643 $langs->load(
'errors');
652 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
653 if ($prod_entry_mode ==
'free') {
668 if (empty($remise_percent)) {
673 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
674 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
676 if (is_array($extralabelsline)) {
678 foreach ($extralabelsline as $key => $value) {
679 unset($_POST[
"options_".$key]);
683 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
684 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
687 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
688 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
691 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
692 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
695 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
696 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
699 if (
GETPOST(
'qty',
'alpha') ==
'') {
700 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
704 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
705 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
709 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
710 $idprod = $res->fk_product_child;
712 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
718 if ($prod_entry_mode !=
'free' && empty($error)) {
722 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
727 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
728 $idprod = (int) $reg[1];
729 $res = $productsupplier->fetch($idprod);
732 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
734 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
735 if ($productsupplier->fourn_socid != $socid) {
736 $productsupplier->ref_supplier =
'';
739 $fksoctosearch =
$object->thirdparty->id;
740 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
742 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
743 $qtytosearch = (float) $qty;
745 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
746 $res = $productsupplier->fetch($idprod);
750 $label = $productsupplier->label;
754 $outputlangs = $langs;
756 if (
GETPOST(
'lang_id',
'aZ09')) {
757 $newlang =
GETPOST(
'lang_id',
'aZ09');
759 if (empty($newlang)) {
760 $newlang =
$object->thirdparty->default_lang;
762 if (!empty($newlang)) {
764 $outputlangs->setDefaultLang($newlang);
766 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
768 $desc = $productsupplier->description;
771 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
772 $desc = $productsupplier->desc_supplier;
783 $ref_supplier = $productsupplier->ref_supplier;
784 if (empty($ref_supplier) && !empty(
GETPOST(
'fourn_ref',
'alpha'))) {
785 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
791 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
792 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
793 $tmpidprodfournprice = (int) $tmpidprodfournprice;
795 $tmpidprodfournprice = 0;
799 if (empty($tva_tx)) {
807 $type = $productsupplier->type;
808 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
809 $price_base_type =
'HT';
811 $pu_devise =
price2num($price_ht_devise,
'CU');
812 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
813 $price_base_type =
'TTC';
815 $pu_devise =
price2num($price_ttc_devise,
'CU');
817 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
818 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
819 $pu = $productsupplier->fourn_pu;
822 $pu = $productsupplier->fourn_pu;
823 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
833 ($price_base_type ==
'HT' ? $pu : 0),
839 $productsupplier->product_fourn_price_id,
843 ($price_base_type ==
'TTC' ? $pu : 0),
850 $productsupplier->fk_unit,
854 min($rank, count(
$object->lines) + 1)
857 if ($idprod == -99 || $idprod == 0) {
860 $langs->load(
"errors");
861 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
866 $langs->load(
"errors");
867 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
869 } elseif (empty($error)) {
870 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
871 $tva_tx = str_replace(
'*',
'', $tva_tx);
872 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
875 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
879 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
888 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
889 $price_base_type =
'HT';
892 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
894 $price_base_type =
'TTC';
897 $pu_ht_devise =
price2num($price_ttc_devise,
'CU');
900 $result =
$object->addline($desc, (
float) $pu_ht, (
float) $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, (
float) $pu_ttc, $type, 0, 0,
$date_start, $date_end, $array_options, $fk_unit, (
float) $pu_ht_devise);
904 if (!$error && $result > 0) {
912 $outputlangs = $langs;
915 $newlang =
$object->thirdparty->default_lang;
916 if (
GETPOST(
'lang_id',
'aZ09')) {
917 $newlang =
GETPOST(
'lang_id',
'aZ09');
920 if (!empty($newlang)) {
922 $outputlangs->setDefaultLang($newlang);
927 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
933 unset($_POST [
'prod_entry_mode']);
935 unset($_POST[
'qty']);
936 unset($_POST[
'type']);
937 unset($_POST[
'remise_percent']);
939 unset($_POST[
'price_ht']);
940 unset($_POST[
'multicurrency_price_ht']);
941 unset($_POST[
'price_ttc']);
942 unset($_POST[
'fourn_ref']);
943 unset($_POST[
'tva_tx']);
944 unset($_POST[
'label']);
945 unset($localtax1_tx);
946 unset($localtax2_tx);
947 unset($_POST[
'np_marginRate']);
948 unset($_POST[
'np_markRate']);
949 unset($_POST[
'dp_desc']);
950 unset($_POST[
'idprodfournprice']);
951 unset($_POST[
'units']);
953 unset($_POST[
'date_starthour']);
954 unset($_POST[
'date_startmin']);
955 unset($_POST[
'date_startsec']);
956 unset($_POST[
'date_startday']);
957 unset($_POST[
'date_startmonth']);
958 unset($_POST[
'date_startyear']);
959 unset($_POST[
'date_endhour']);
960 unset($_POST[
'date_endmin']);
961 unset($_POST[
'date_endsec']);
962 unset($_POST[
'date_endday']);
963 unset($_POST[
'date_endmonth']);
964 unset($_POST[
'date_endyear']);
966 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
974 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
977 $langs->load(
'subtotals');
979 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
982 $subtotal_options = array();
984 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
985 $value =
GETPOST($option,
'alphanohtml');
987 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
992 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
1003 $outputlangs = $langs;
1004 $newlang =
GETPOST(
'lang_id',
'alpha');
1006 $newlang =
$object->thirdparty->default_lang;
1008 if (!empty($newlang)) {
1010 $outputlangs->setDefaultLang($newlang);
1013 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1018 } elseif ($action ==
'updatetextline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1021 $langs->load(
'subtotals');
1023 $desc =
GETPOST(
'line_desc',
'restricthtml');
1026 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, 0, array());
1037 $outputlangs = $langs;
1038 $newlang =
GETPOST(
'lang_id',
'alpha');
1040 $newlang =
$object->thirdparty->default_lang;
1042 if (!empty($newlang)) {
1044 $outputlangs->setDefaultLang($newlang);
1047 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1052 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1055 $langs->load(
'subtotals');
1057 $desc =
GETPOST(
'line_desc',
'alphanohtml');
1060 $subtotal_options = array();
1062 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
1063 $value =
GETPOST($option,
'alphanohtml');
1065 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
1070 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
1078 $outputlangs = $langs;
1079 $newlang =
GETPOST(
'lang_id',
'alpha');
1081 $newlang =
$object->thirdparty->default_lang;
1083 if (!empty($newlang)) {
1085 $outputlangs->setDefaultLang($newlang);
1088 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1093 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1102 $res = $line->fetch($lineid);
1104 dol_print_error($db);
1109 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1110 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, (
float)
price2num(
GETPOSTFLOAT(
'qty')), $line->fk_product,
'none',
GETPOSTINT(
'socid')) < 0) {
1111 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1120 if (preg_match(
'/\*/', $vat_rate)) {
1125 $vat_rate = str_replace(
'*',
'', $vat_rate);
1136 $price_base_type =
'HT';
1137 if (empty($pu_ht) && !empty($pu_ttc)) {
1139 $price_base_type =
'TTC';
1140 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1141 foreach (
$object->lines as $line_obj) {
1144 if ($line_obj->wasEnteredIncludingTax()) {
1146 $price_base_type =
'TTC';
1157 if (
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' &&
GETPOST(
'multicurrency_subprice') ===
'' &&
GETPOST(
'multicurrency_price_ttc') !==
'') {
1159 $price_base_type =
'TTC';
1164 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1165 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1167 if (is_array($extralabelsline)) {
1168 foreach ($extralabelsline as $key => $value) {
1169 unset($_POST[
"options_".$key]);
1173 $result =
$object->updateline(
1175 GETPOST(
'product_desc',
'restricthtml'),
1190 (float) $pu_ht_devise,
1193 unset($_POST[
'qty']);
1194 unset($_POST[
'type']);
1195 unset($_POST[
'idprodfournprice']);
1196 unset($_POST[
'remmise_percent']);
1197 unset($_POST[
'dp_desc']);
1198 unset($_POST[
'np_desc']);
1199 unset($_POST[
'pu']);
1200 unset($_POST[
'fourn_ref']);
1201 unset($_POST[
'tva_tx']);
1202 unset($_POST[
'date_start']);
1203 unset($_POST[
'date_end']);
1204 unset($_POST[
'units']);
1205 unset($localtax1_tx);
1206 unset($localtax2_tx);
1208 unset($_POST[
'date_starthour']);
1209 unset($_POST[
'date_startmin']);
1210 unset($_POST[
'date_startsec']);
1211 unset($_POST[
'date_startday']);
1212 unset($_POST[
'date_startmonth']);
1213 unset($_POST[
'date_startyear']);
1214 unset($_POST[
'date_endhour']);
1215 unset($_POST[
'date_endmin']);
1216 unset($_POST[
'date_endsec']);
1217 unset($_POST[
'date_endday']);
1218 unset($_POST[
'date_endmonth']);
1219 unset($_POST[
'date_endyear']);
1224 $outputlangs = $langs;
1227 $newlang =
GETPOST(
'lang_id',
'aZ09');
1230 $newlang =
$object->thirdparty->default_lang;
1232 if (!empty($newlang)) {
1234 $outputlangs->setDefaultLang($newlang);
1239 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1254 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
1257 $result =
$object->deleteLine($lineid);
1262 $outputlangs = $langs;
1265 $newlang =
GETPOST(
'lang_id',
'aZ09');
1268 $newlang =
$object->thirdparty->default_lang;
1270 if (!empty($newlang)) {
1272 $outputlangs->setDefaultLang($newlang);
1276 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1298 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
1306 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
1310 $result =
$object->valid($user);
1314 $outputlangs = $langs;
1317 $newlang =
GETPOST(
'lang_id',
'aZ09');
1320 $newlang =
$object->thirdparty->default_lang;
1322 if (!empty($newlang)) {
1324 $outputlangs->setDefaultLang($newlang);
1329 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1342 $action =
'confirm_approve';
1352 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
1357 $qualified_for_stock_change = 0;
1359 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1361 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1366 if (!$idwarehouse || $idwarehouse == -1) {
1368 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1374 $result =
$object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1377 $outputlangs = $langs;
1380 $newlang =
GETPOST(
'lang_id',
'aZ09');
1383 $newlang =
$object->thirdparty->default_lang;
1385 if (!empty($newlang)) {
1387 $outputlangs->setDefaultLang($newlang);
1389 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1400 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1407 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1411 $result =
$object->refuse($user);
1413 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1421 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1422 $methodecommande =
GETPOSTINT(
'methodecommande');
1426 } elseif (!$date_com) {
1427 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderDate")),
null,
'errors');
1428 $action =
'createorder';
1429 } elseif ($methodecommande <= 0 && !
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL')) {
1430 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1431 $action =
'createorder';
1435 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1437 $object->context[
"sendmanualtriggers"] =
GETPOST(
"manual_trigger_send");
1440 if (
GETPOST(
'updatebuyingprice') &&
getDolGlobalString(
'SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_ON_ORDER') && $usercanupdateprices &&
$object->updateProductBuyPrices($user) < 0) {
1444 $elements = array_filter(array(
'propal' =>
GETPOST(
'updatelinked_propal'),
'commande' =>
GETPOST(
'updatelinked_commande'),
'facture' =>
GETPOST(
'updatelinked_facture')));
1445 if ($elements &&
getDolGlobalString(
'SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_ON_ORDER')) {
1446 foreach (
$object->lines as $line) {
1447 if (
$object->updateLinkedBuyPrice($user, $line->id, $elements) < 0) {
1455 $outputlangs = $langs;
1458 $newlang =
GETPOST(
'lang_id',
'aZ09');
1461 $newlang =
$object->thirdparty->default_lang;
1463 if (!empty($newlang)) {
1465 $outputlangs->setDefaultLang($newlang);
1467 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1478 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1486 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1489 $errorsOnDelete = array();
1544 if (empty($errOnDelete)) {
1546 $result =
$object->delete($user);
1549 header(
"Location: " . DOL_URL_ROOT .
'/fourn/commande/list.php?restore_lastsearch_values=1');
1557 setEventMessages(
'', $errorsOnDelete,
'errors');
1562 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1564 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1565 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1570 $result =
$object->createFromClone($user, $socid);
1572 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1584 if ($action ==
'livraison' && $usercanreceive) {
1595 $langs->load(
"sendings");
1596 setEventMessages($langs->trans(
"DeliveryStateSaved"),
null);
1605 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1616 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1620 $result =
$object->cancel($user);
1622 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1630 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1633 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1634 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1635 $trackid =
'sord'.$object->id;
1636 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1640 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1643 if ($action ==
'update_extras' && $permissiontoeditextra) {
1646 $attribute_name =
GETPOST(
'attribute',
'aZ09');
1649 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
1655 $result =
$object->updateExtraField($attribute_name,
'ORDER_SUPPLIER_MODIFY');
1663 $action =
'edit_extras';
1670 if ($action ==
'add' && $permissiontoadd) {
1672 $selectedLines =
GETPOST(
'toselect',
'array:int');
1674 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1691 $object->delivery_date = $datelivraison;
1694 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1695 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1701 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1709 if (!empty($origin) && !empty($originid)) {
1710 $element = $subelement = $origin;
1711 $classname = ucfirst($subelement);
1712 if ($origin ==
'propal' || $origin ==
'proposal') {
1713 $element =
'comm/propal';
1714 $subelement =
'propal';
1715 $classname =
'Propal';
1717 if ($origin ==
'order' || $origin ==
'commande') {
1718 $element = $subelement =
'commande';
1719 $classname =
'Commande';
1721 if ($origin ==
'supplier_proposal') {
1722 $classname =
'SupplierProposal';
1723 $element =
'supplier_proposal';
1724 $subelement =
'supplier_proposal';
1728 $object->origin_type = $origin;
1729 $object->origin_id = $originid;
1733 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1734 if (!empty($other_linked_objects)) {
1735 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
1742 $srcobject =
new $classname($db);
1744 dol_syslog(
"Try to find source object origin=".
$object->origin_type.
" originid=".
$object->origin_id.
" to add lines");
1745 $result = $srcobject->fetch(
$object->origin_id);
1747 if (empty(
$object->delivery_date)) {
1748 $tmpdate = $srcobject->delivery_date;
1749 $object->setDeliveryDate($user, $tmpdate);
1752 $object->set_id_projet($user, $srcobject->fk_project);
1754 $lines = $srcobject->lines;
1755 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1756 $srcobject->fetch_lines();
1757 $lines = $srcobject->lines;
1760 $fk_parent_line = 0;
1761 $num = count($lines);
1763 for ($i = 0; $i < $num; $i++) {
1765 empty($lines[$i]->subprice)
1766 || $lines[$i]->qty < 0
1767 || !in_array($lines[$i]->
id, $selectedLines)
1768 || $lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE
1773 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1774 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1775 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1777 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1778 $fk_parent_line = 0;
1782 if (method_exists($lines[$i],
'fetch_optionals')) {
1783 $lines[$i]->fetch_optionals();
1784 $array_option = $lines[$i]->array_options;
1786 $array_option = array();
1790 $product_fourn_price_id = 0;
1791 if ($origin ==
"commande") {
1793 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty,
$object->socid);
1794 $lines[$i]->subprice = 0;
1796 $ref_supplier = $productsupplier->ref_supplier;
1797 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1799 foreach ($srcobject->lines as $li) {
1800 $sql =
'SELECT price, unitprice, tva_tx, remise_percent, entity, ref_fourn';
1801 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
1802 $sql .=
' WHERE fk_product = '.((int) $li->fk_product);
1803 $sql .=
' AND entity IN ('.getEntity(
'product_fournisseur_price').
')';
1804 $sql .=
' AND fk_soc = '.((int)
$object->socid);
1805 $sql .=
' ORDER BY unitprice ASC';
1807 $resql = $db->query($sql);
1809 $num_row = $db->num_rows($resql);
1810 if (empty($num_row)) {
1811 $li->remise_percent = 0;
1813 $obj = $db->fetch_object($resql);
1814 $li->subprice = $obj->unitprice;
1815 $li->remise_percent = $obj->remise_percent;
1818 dol_print_error($db);
1824 $ref_supplier = $lines[$i]->ref_fourn;
1825 $product_fourn_price_id = 0;
1828 $tva_tx = $lines[$i]->tva_tx;
1830 if ($origin ==
"commande") {
1832 $soc->fetch($socid);
1837 $line_price_base_type = $lines[$i]->getPriceBaseType();
1840 $lines[$i]->subprice,
1843 $lines[$i]->localtax1_tx,
1844 $lines[$i]->localtax2_tx,
1845 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1846 $product_fourn_price_id,
1848 $lines[$i]->remise_percent,
1849 $line_price_base_type,
1850 (float) $lines[$i]->subprice_ttc,
1851 $lines[$i]->product_type,
1857 $lines[$i]->fk_unit,
1860 !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid,
1862 $lines[$i]->special_code,
1873 if ($result > 0 && $lines[$i]->product_type == 9) {
1874 $fk_parent_line = $result;
1882 $parameters = array(
'objFrom' => $srcobject);
1883 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1886 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1890 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
1907 $categories =
GETPOST(
'categories',
'array:int');
1908 if (method_exists($object,
'setCategories')) {
1909 $object->setCategories($categories);
1914 $langs->load(
"errors");
1919 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode((
string) ($id)));
1926 if ($action ==
'addcontact' && $permissiontoadd) {
1930 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1934 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1937 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1938 $langs->load(
"errors");
1939 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1944 } elseif ($action ==
'swapstatut' &&
$object->id > 0 && $permissiontoadd) {
1947 } elseif ($action ==
'deletecontact' &&
$object->id > 0 && $permissiontoadd) {
1952 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1955 dol_print_error($db);
1966$form =
new Form($db);
1969$productstatic =
new Product($db);
1974$title =
$object->ref.
" - ".$langs->trans(
'Card');
1975if ($action ==
'create') {
1976 $title = $langs->trans(
"NewOrderSupplier");
1978$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1979llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-supplier-order page-card');
1983if ($action ==
'create') {
1984 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1988 $currency_code =
$conf->currency;
1995 $societe->fetch($socid);
1998 if (!empty($origin) && !empty($originid)) {
2000 $element = $subelement = $origin;
2001 $classname = ucfirst($subelement);
2003 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
2004 $element = $regs[1];
2005 $subelement = $regs[2];
2008 if ($origin ==
'propal' || $origin ==
'proposal') {
2009 $classname =
'Propal';
2010 $element =
'comm/propal';
2011 $subelement =
'propal';
2013 if ($origin ==
'order' || $origin ==
'commande') {
2014 $classname =
'Commande';
2015 $element = $subelement =
'commande';
2017 if ($origin ==
'supplier_proposal') {
2018 $classname =
'SupplierProposal';
2019 $element =
'supplier_proposal';
2020 $subelement =
'supplier_proposal';
2026 $objectsrc =
new $classname($db);
2027 $objectsrc->fetch($originid);
2028 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
2029 $objectsrc->fetch_lines();
2031 $objectsrc->fetch_thirdparty();
2034 $objectsrc->fetch_optionals();
2035 $object->array_options = $objectsrc->array_options;
2037 $projectid = (int) $objectsrc->fk_project;
2038 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
2040 if ($origin ==
"commande") {
2041 $cond_reglement_id = 0;
2042 $deposit_percent = 0;
2043 $mode_reglement_id = 0;
2044 $objectsrc->note_private =
'';
2045 $objectsrc->note_public =
'';
2046 if ($societe =
$object->thirdparty) {
2047 $cond_reglement_id = $societe->cond_reglement_supplier_id;
2048 $deposit_percent = $societe->deposit_percent;
2049 $mode_reglement_id = $societe->mode_reglement_supplier_id;
2051 $currency_code = $societe->multicurrency_code;
2053 $currency_tx = $societe->multicurrency_tx;
2058 $soc = $objectsrc->thirdparty;
2060 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
2061 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0));
2062 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2063 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2064 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
2065 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
2066 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
2069 $datelivraison = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
2072 if (!empty($objectsrc->multicurrency_code)) {
2073 $currency_code = $objectsrc->multicurrency_code;
2075 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2076 $currency_tx = $objectsrc->multicurrency_tx;
2080 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
2081 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
2084 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
2087 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2088 $deposit_percent = !empty($societe->deposit_percent) ? $societe->deposit_percent : 0;
2089 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2091 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2092 $currency_code = $societe->multicurrency_code;
2095 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
2096 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
2100 if (empty($cond_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID')) {
2103 if (empty($mode_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID')) {
2106 if (
GETPOSTISSET(
'cond_reglement_id_deposit_percent')) {
2107 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
2110 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2111 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2112 print
'<input type="hidden" name="action" value="add">';
2113 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
2114 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2115 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2116 print
'<input type="hidden" name="changecompany" value="0">';
2118 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2120 if ($backtopageforcancel) {
2121 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
2124 if (!empty($currency_tx)) {
2125 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2131 $parameters = array();
2133 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierOrder', $parameters, $object, $action);
2134 if (empty($reshook)) {
2135 print
'<table class="border centpercent">';
2138 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2141 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2144 if (!empty($societe->id) && $societe->id > 0) {
2145 print $societe->getNomUrl(1,
'supplier');
2146 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2148 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2149 print img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company((empty($socid) ?
'' : $socid),
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
2153 $(document).ready(function() {
2154 $("#socid").change(function() {
2155 console.log("We have changed the company - Reload page");
2157 $("input[name=action]").val("create");
2158 $("input[name=changecompany]").val("1");
2159 $("form[name=add]").submit();
2164 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>';
2170 print
'<tr><td>'.$form->textwithpicto($langs->trans(
'RefSupplier'), $langs->trans(
'RefOfOnVendorSide', $langs->transnoentitiesnoconv(
"SupplierOrder")));
2171 print
'</td><td><input name="refsupplier" type="text"></td>';
2175 if (!empty($societe->id) && $societe->id > 0) {
2177 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2179 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2181 $thirdparty = $societe;
2183 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2184 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2190 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2191 print img_picto(
'',
'payment',
'class="pictofixedwidth"');
2192 print $form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id') != 0) ?
GETPOSTINT(
'cond_reglement_id') : $cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
2196 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2197 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
2198 $form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOSTINT(
'mode_reglement_id') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
2203 print $langs->trans(
'DateDeliveryPlanned');
2210 print img_picto(
'',
'action',
'class="pictofixedwidth"');
2211 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin, 0,
"set", 1, 1);
2218 print $form->textwithpicto($langs->trans(
'DefaultWarehouse'), $langs->trans(
'SupplierOrderDefaultWarehouseHelp'));
2221 print img_picto(
'',
'stock',
'class="pictofixedwidth"');
2222 print $formproductcreate->selectWarehouses(
GETPOSTISSET(
'fk_warehouse') ?
GETPOSTINT(
'fk_warehouse') :
'',
'fk_warehouse',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
2228 $langs->load(
"bank");
2229 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2230 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
2231 $form->select_comptes($fk_account ??
'',
'fk_account', 0,
'', 1);
2239 $langs->load(
'projects');
2240 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2241 if (!empty($user->socid)) {
2242 $projSocFilter = $user->socid;
2243 } elseif (
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || (
int) $socid == 0) {
2246 $projSocFilter = -1;
2248 $projSocFilter = $socid;
2250 print img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
2251 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>';
2257 $fkincoterms = (!empty(
$object->fk_incoterms) ?
$object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
2258 $locincoterms = (!empty(
$object->location_incoterms) ?
$object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
2260 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"),
$object->label_incoterms, 1).
'</label></td>';
2261 print
'<td class="maxwidthonsmartphone">';
2262 print img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2263 print $form->select_incoterms($fkincoterms, $locincoterms);
2270 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2271 print
'<td class="maxwidthonsmartphone">';
2272 print img_picto(
'',
'currency',
'class="pictofixedwidth"');
2273 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
2279 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2280 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2284 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2286 $doleditor =
new DolEditor(
'note_public', isset($note_public) ? $note_public :
GETPOST(
'note_public',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2287 print $doleditor->Create(1);
2292 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2294 $doleditor =
new DolEditor(
'note_private', isset($note_private) ? $note_private :
GETPOST(
'note_private',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', false, false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2295 print $doleditor->Create(1);
2300 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && $classname !==
null) {
2301 print
"\n<!-- ".$classname.
" info -->";
2303 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2304 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2305 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2306 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2307 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2309 $newclassname = $classname;
2310 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
2311 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2312 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2313 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2314 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2317 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2318 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2321 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2324 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2325 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2326 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2331 $parameters = array();
2332 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2333 print $hookmanager->resPrint;
2335 if (empty($reshook)) {
2336 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_SUPPLIER_ORDER') && !empty($societe->id)) {
2339 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($societe->table_element);
2340 if ($societe->fetch_optionals() > 0) {
2341 $object->array_options = array_merge(
$object->array_options, $societe->array_options);
2345 print
$object->showOptionals($extrafields,
'create');
2353 print $form->buttonsSaveCancel(
"CreateDraft");
2356 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2357 $title = $langs->trans(
'ProductsAndServices');
2360 print
'<div class="div-table-responsive-no-min">';
2361 print
'<table class="noborder centpercent">';
2363 $selectedLines = array();
2365 $objectsrc->printOriginLinesList(
'', $selectedLines);
2371} elseif (!empty(
$object->id)) {
2373 $result =
$object->fetch($id, $ref);
2378 $societe =
$object->thirdparty;
2380 $author =
new User($db);
2381 $author->fetch(
$object->user_author_id);
2385 $title = $langs->trans(
"SupplierOrder");
2386 print
dol_get_fiche_head($head,
'card', $title, -1,
'order', 0,
'',
'', 0,
'', 1);
2392 if ($action ==
'delete') {
2393 $arrayAjouts = array();
2424 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.((
int)
$object->id), $langs->trans(
'DeleteSupplierOrder'), $langs->trans(
'ConfirmDeleteSupplierOrder'),
'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal);
2428 if ($action ==
'clone') {
2429 $filter =
'(s.fournisseur:=:1)';
2431 $formquestion = array(
2432 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter))
2435 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneSupplierOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2439 if ($action ==
'valid') {
2443 if (preg_match(
'/^[\(]?PROV/i', (
string)
$object->ref) || empty(
$object->ref)) {
2446 $newref = (string)
$object->ref;
2453 $text = $langs->trans(
'ConfirmValidateSupplierOrder', $newref);
2455 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2456 $notify =
new Notify($db);
2458 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE',
$object->socid, $object);
2461 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateSupplierOrder'), $text,
'confirm_valid',
'', 0, 1);
2466 if ($action ==
'approve' || $action ==
'approve2') {
2467 $qualified_for_stock_change = 0;
2469 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2471 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2474 $formquestion = array();
2476 $langs->load(
"stocks");
2477 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2480 if (
$conf->browser->name ==
'ie') {
2483 $formquestion = array(
2487 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2490 $text = $langs->trans(
"ConfirmApproveThisOrder",
$object->ref);
2492 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2493 $notify =
new Notify($db);
2495 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE',
$object->socid, $object);
2498 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
2502 if ($action ==
'refuse') {
2503 $formquestion = array(
2506 'name' =>
'refuse_note',
2507 'label' => $langs->trans(
"Reason"),
2509 'morecss' =>
'minwidth300'
2512 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder",
$object->ref),
"confirm_refuse", $formquestion, 0, 1);
2516 if ($action ==
'cancel') {
2517 $formquestion = array(
2520 'name' =>
'cancel_note',
2521 'label' => $langs->trans(
"Reason"),
2523 'morecss' =>
'minwidth300'
2527 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2528 $notify =
new Notify($db);
2531 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_CANCEL',
$object->socid, $object);
2533 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder",
$object->ref),
"confirm_cancel", $formquestion, 0, 1);
2539 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
'methodecommande', 1);
2540 $inputmethod = ob_get_clean();
2541 $formquestion = array(
2542 array(
'type' =>
'date',
'name' =>
're',
'label' => $langs->trans(
'OrderDate'),
'value' =>
GETPOSTISSET(
'reday') ? ($date_com ?: -1) :
dol_now(),
'datenow' => 1,
'tdclass' =>
'fieldrequired'),
2543 array(
'type' =>
'other',
'name' =>
'methodecommande',
'label' => $langs->trans(
'OrderMode'),
'value' => $inputmethod,
'tdclass' =>
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL') ?
'' :
'fieldrequired'),
2544 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
'Comment'),
'value' =>
dol_escape_htmltag(
GETPOST(
'comment')),
'morecss' =>
'quatrevingtpercent')
2546 if (
getDolGlobalString(
'SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_ON_ORDER') && $usercanupdateprices &&
$object->hasProductsOrServices(1)) {
2547 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'updatebuyingprice',
'label' => $langs->trans(
'UpdateBuyingPriceFromOrder'),
'value' =>
GETPOST(
'updatebuyingprice'));
2550 $labels = array(
'propal' =>
'Proposal',
'commande' =>
'Order',
'facture' =>
'Invoice');
2552 foreach (
$object->lines as $line) {
2553 foreach (
$object->getLinkedBuyPriceDocuments($user, $line->id) as $element => $document) {
2554 $linked[$element] = ($linked[$element] ?? array()) + $document[
'refs'];
2557 foreach ($linked as $element => $refs) {
2558 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'updatelinked_'.$element,
'label' => $langs->trans(
'UpdateLinkedBuyingPrice').
': '.$langs->trans($labels[$element]).
' '.
dol_escape_htmltag(implode(
', ', $refs)),
'value' =>
GETPOST(
'updatelinked_'.$element));
2562 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2563 $notify =
new Notify($db);
2564 $formquestion[
'text'] = $notify->confirmMessage(
'ORDER_SUPPLIER_SUBMIT',
$object->socid, $object);
2567 require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
2568 $targetstatic =
new Target($db);
2569 if ($targetstatic->isTriggerCodeManualTarget(
'ORDER_SUPPLIER_SUBMIT') > 0) {
2570 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'manual_trigger_send',
'label' => $langs->trans(
"QuestionSendManualTrigger"));
2573 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, $langs->trans(
'MakeOrder'),
'',
'confirm_commande', $formquestion, 0, 2, 0, 600, 0,
'ToOrder',
'Cancel');
2577 if ($action ==
'ask_deleteline') {
2578 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2582 if ($action ==
'ask_subtotal_deleteline') {
2583 $langs->load(
'subtotals');
2584 $subtotaltitle =
'DeleteSubtotalLine';
2585 $subtotalquestion =
'ConfirmDeleteSubtotalLine';
2586 $subtotalformquestion = array();
2587 if (
GETPOST(
'type') ==
'title') {
2588 $subtotalformquestion = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
'DeleteCorrespondingSubtotalLine'),
'value' => 0));
2589 $subtotaltitle =
'DeleteTitleLine';
2590 $subtotalquestion =
'ConfirmDeleteTitleLine';
2592 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans($subtotaltitle), $langs->trans($subtotalquestion),
'confirm_delete_subtotalline', $subtotalformquestion,
'no', 1);
2596 if ($action ==
'add_title_line') {
2597 $langs->load(
'subtotals');
2599 $depth_array =
$object->getPossibleLevels($langs);
2600 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2601 } elseif ($action ==
'add_subtotal_line') {
2602 $langs->load(
'subtotals');
2604 $titles =
$object->getPossibleTitles();
2605 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2606 } elseif ($action ==
'add_text_line') {
2607 $langs->load(
'subtotals');
2609 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2613 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2614 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2615 if (empty($reshook)) {
2616 $formconfirm .= $hookmanager->resPrint;
2617 } elseif ($reshook > 0) {
2618 $formconfirm = $hookmanager->resPrint;
2627 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2629 $morehtmlref =
'<div class="refidno">';
2631 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
2632 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, $usercancreate,
'string'.(isset(
$conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
2634 $morehtmlref .=
'<br>';
2635 if (
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2636 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2637 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2638 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2639 $filter =
'(s.fournisseur:=:1)';
2640 $morehtmlref .= $form->select_company(
$object->thirdparty->id,
'new_socid', $filter,
'', 0, 0, array(), 0,
'minwidth300');
2641 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2642 $morehtmlref .=
'</form>';
2644 if (!
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') || $action !=
'edit_thirdparty') {
2646 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.
$object->id.
'">'.img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2648 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'supplier');
2650 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2656 $langs->load(
"projects");
2657 $morehtmlref .=
'<br>';
2658 if ($permissiontoadd) {
2659 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2660 if ($action !=
'classify' && $caneditproject) {
2661 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2663 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (!
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ?
$object->socid : -1), (string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 1, 0, 0, 1,
'',
'maxwidth300');
2665 if (!empty(
$object->fk_project)) {
2667 $proj->fetch(
$object->fk_project);
2668 $morehtmlref .= $proj->getNomUrl(1);
2670 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2675 $morehtmlref .=
'</div>';
2678 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2681 $parameters = array();
2683 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierOrder', $parameters, $object, $action);
2684 if (empty($reshook)) {
2685 print
'<div class="fichecenter">';
2686 print
'<div class="fichehalfleft">';
2687 print
'<div class="underbanner clearboth"></div>';
2689 print
'<table class="border tableforfield centpercent">';
2692 if (
$object->methode_commande_id > 0) {
2697 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2700 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2704 if (
$object->methode_commande) {
2705 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.
$object->getInputMethod().
'</td></tr>';
2710 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2711 print
'<td>'.$author->getNomUrl(-1,
'', 0, 0, 0).
'</td>';
2716 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2717 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2719 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2720 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2723 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
2724 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
2725 $absolute_discount =
price2num($absolute_discount,
'MT');
2726 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2728 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2730 $thirdparty = $societe;
2732 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
2733 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2738 $langs->load(
'bills');
2739 print
'<tr><td class="nowrap">';
2740 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2741 print $langs->trans(
'PaymentConditions');
2743 if ($action !=
'editconditions' && $permissiontoadd) {
2744 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>';
2746 print
'</tr></table>';
2748 if ($action ==
'editconditions') {
2749 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2751 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2757 $langs->load(
'bills');
2758 print
'<tr><td class="nowrap">';
2759 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2760 print $langs->trans(
'PaymentMode');
2762 if ($action !=
'editmode' && $permissiontoadd) {
2763 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>';
2765 print
'</tr></table>';
2767 if ($action ==
'editmode') {
2768 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2770 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
2776 print
'<tr><td class="nowrap">';
2777 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2778 print $langs->trans(
'BankAccount');
2780 if ($action !=
'editbankaccount' && $permissiontoadd) {
2781 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>';
2783 print
'</tr></table>';
2785 if ($action ==
'editbankaccount') {
2786 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
2788 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
2796 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2797 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2804 print
'<table class="nobordernopadding centpercent"><tr><td>';
2805 print $form->textwithpicto($langs->trans(
'DefaultWarehouse'), $langs->trans(
'SupplierOrderDefaultWarehouseHelp'));
2807 if ($action !=
'editwarehouse' && $usercancreate) {
2808 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editwarehouse&token='.
newToken().
'&id='.
$object->id.
'">'.img_edit($langs->trans(
'SetWarehouse'), 1).
'</a></td>';
2810 print
'</tr></table>';
2812 if ($action ==
'editwarehouse') {
2813 print
'<form name="setwarehouse" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2814 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2815 print
'<input type="hidden" name="action" value="setwarehouse">';
2816 print $formproductcard->selectWarehouses(
$object->fk_warehouse,
'fk_warehouse',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth300');
2817 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2819 } elseif (
$object->fk_warehouse > 0) {
2820 $warehousestatic =
new Entrepot($db);
2821 if ($warehousestatic->fetch(
$object->fk_warehouse) > 0) {
2822 print $warehousestatic->getNomUrl(1);
2832 print
'<table class="nobordernopadding centpercent"><tr><td>';
2833 print $langs->trans(
'DateDeliveryPlanned');
2835 if ($action !=
'editdate_livraison') {
2836 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>';
2838 print
'</tr></table>';
2840 if ($action ==
'editdate_livraison') {
2841 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2842 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2843 print
'<input type="hidden" name="action" value="setdate_livraison">';
2848 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin, 0,
"setdate_livraison");
2849 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2852 $usehourmin =
'day';
2854 $usehourmin =
'dayhour';
2857 if (
$object->hasDelay() && !empty(
$object->delivery_date) && (
$object->status == $object::STATUS_ORDERSENT ||
$object->status == $object::STATUS_RECEIVED_PARTIALLY)) {
2858 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2866 print
'<table class="nobordernopadding centpercent"><tr><td>';
2867 print $langs->trans(
'IncotermLabel');
2868 print
'<td><td class="right">';
2869 if ($usercancreate) {
2870 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.img_edit().
'</a>';
2874 print
'</td></tr></table>';
2877 if ($action !=
'editincoterm') {
2880 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2888 print
'<table class="nobordernopadding centpercent"><tr><td>';
2889 print $langs->trans(
"Categories");
2890 print
'<td><td class="right">';
2891 if ($usercancreate) {
2892 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.img_edit().
'</a>';
2896 print
'</td></tr></table>';
2899 if ($action ==
'edittags') {
2900 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2901 print
'<input type="hidden" name="action" value="settags">';
2902 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2903 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2904 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
2907 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_ORDER, 1);
2913 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2918 print
'<div class="fichehalfright">';
2919 print
'<div class="underbanner clearboth"></div>';
2921 print
'<table class="border tableforfield centpercent">';
2923 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2927 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2928 print
'<td class="nowrap amountcard right" data-dol-field="total_ht">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2931 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ht">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2937 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2938 print
'<td class="nowrap amountcard right" data-dol-field="total_tva">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2941 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_tva">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2946 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2948 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
2949 print
'<td class="nowrap amountcard right" data-dol-field="total_localtax1">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2951 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_localtax1">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2955 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2957 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
2958 print
'<td class="nowrap amountcard right" data-dol-field="total_localtax2">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2960 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_localtax2">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2968 $alert =
' ' . img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->supplier_order_min_amount));
2973 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2974 print
'<td class="nowrap amountcard right" data-dol-field="total_ttc">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) . $alert .
'</td>';
2977 print
'<td class="nowrap amountcard right" data-dol-field="multicurrency_total_ttc">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2992 print
'<div class="clearboth"></div><br>';
2995 $blocname =
'contacts';
2996 $title = $langs->trans(
'ContactsAddresses');
2997 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3001 $blocname =
'notes';
3002 $title = $langs->trans(
'Notes');
3003 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
3012 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
3013 <input type="hidden" name="token" value="'.
newToken().
'">
3014 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
3015 <input type="hidden" name="mode" value="">
3016 <input type="hidden" name="page_y" value="">
3017 <input type="hidden" name="id" value="'.
$object->id.
'">
3018 <input type="hidden" name="socid" value="'.$societe->id.
'">
3023 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
3025 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
3029 print
'<div class="div-table-responsive-no-min">';
3030 print
'<table id="tablelines" class="noborder noshadow centpercent">';
3033 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3036 $inputalsopricewithtax = 1;
3037 $senderissupplier = 2;
3039 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY');
3051 if ($action !=
'editline') {
3054 $parameters = array();
3055 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3057 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3059 if (empty($reshook)) {
3075 if ($user->socid == 0 && $action !=
'delete') {
3076 if ($action !=
'createorder' && $action !=
'presend' && $action !=
'editline') {
3077 print
'<div class="tabsAction">';
3079 $parameters = array();
3080 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
3082 if (empty($reshook)) {
3088 $langs->load(
'subtotals');
3090 $url_button = array();
3092 $url_button[] = array(
3093 'lang' =>
'subtotals',
3095 'perm' => (
bool) $usercancreate,
3096 'label' => $langs->trans(
'AddTitleLine'),
3097 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
3100 $url_button[] = array(
3101 'lang' =>
'subtotals',
3103 'perm' => (
bool) $usercancreate,
3104 'label' => $langs->trans(
'AddSubtotalLine'),
3105 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
3108 $url_button[] = array(
3109 'lang' =>
'subtotals',
3111 'perm' => (
bool) $usercancreate,
3112 'label' => $langs->trans(
'AddTextLine'),
3113 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_text_line'],
true)
3116 print dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
3121 if ($usercanvalidate) {
3122 $tmpbuttonlabel = $langs->trans(
'Validate');
3124 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
3127 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'">';
3128 print $tmpbuttonlabel;
3132 $langs->load(
"errors");
3133 print dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"] .
'?action=validate&token=' .
newToken() .
'&id=' .
$object->id, (
string)
$object->id, -1);
3144 if ($usercanorder) {
3145 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
3151 if ($usercanapprove) {
3153 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3155 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve&token='.
newToken().
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3158 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3165 if ($usercanapprovesecond) {
3166 if (!empty(
$object->user_approve_id2)) {
3167 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
3169 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve2&token='.
newToken().
'">'.$langs->trans(
"Approve2Order").
'</a>';
3172 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
3179 if ($usercanapprove || $usercanapprovesecond) {
3180 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=refuse&token='.
newToken().
'">'.$langs->trans(
"RefuseOrder").
'</a>';
3182 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
3187 if (empty($user->socid)) {
3189 if ($usercanorder) {
3190 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
3198 if (!$buttonshown && $usercanapprove) {
3201 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
3205 if (!$buttonshown && $usercanapprovesecond &&
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
3208 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
3212 if (in_array(
$object->status, array(3, 4, 5, 6, 7, 9))) {
3213 if ($usercanorder) {
3214 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
3221 $labelofbutton = $langs->trans(
'ReceiveProducts');
3223 $labelofbutton = $langs->trans(
"CreateReception");
3224 if (!empty(
$object->linkedObjects[
'reception'])) {
3225 foreach (
$object->linkedObjects[
'reception'] as $element) {
3226 if ($element->statut >= 0) {
3239 $dispachedLines =
$object->getDispachedLines(1);
3240 $nbDispachedLines = count($dispachedLines);
3241 if ($nbDispachedLines > 0) {
3246 if (in_array(
$object->status, array(3, 4, 5))) {
3247 if (
isModEnabled(
"supplier_order") && $usercanreceive) {
3248 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.
$object->id.
'">'.$labelofbutton.
'</a></div>';
3250 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
3256 if ($usercanorder) {
3257 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=createorder&token='.
newToken().
'">'.$langs->trans(
"MakeOrder").
'</a></div>';
3259 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
3265 if ($usercanreceive) {
3266 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>';
3273 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3274 print
'<a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->socid.
'">'.$langs->trans(
"SupplierOrderCreateBill").
'</a>';
3282 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3284 if (!empty(
$object->linkedObjectsIds[
'invoice_supplier']) || (empty(
$object->linkedObjectsIds[
'invoice_supplier']) && !
getDolGlobalInt(
'SUPPLIER_ORDER_DISABLE_CLASSIFY_BILLED_FROM_SUPPLIER_ORDER'))) {
3285 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3286 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3289 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3295 if ($usercancreate &&
$object->billed > 0 &&
$object->status > $object::STATUS_DRAFT) {
3296 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifyunbilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyUnbilled").
'</a>';
3300 if ($usercancreate) {
3301 print dolGetButtonAction($langs->trans(
"ToClone"), $langs->trans(
"ToClone"),
'clone', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&socid='.
$object->socid.
'&action=clone&token='.
newToken().
'&object=order',
'',
true, array(
'attr' => array(
'class' =>
'reposition')));
3306 if ($usercanorder) {
3307 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelSupplierOrder").
'</a>';
3312 if (!empty($usercandelete)) {
3313 if ($hasreception) {
3314 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
3316 print dolGetButtonAction($langs->trans(
"Delete"), $langs->trans(
"Delete"),
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'',
true, array(
'attr' => array(
'class' =>
'reposition'))).
"\n";
3325 if (
GETPOST(
'modelselected')) {
3326 $action =
'presend';
3329 if ($action !=
'createorder' && $action !=
'presend') {
3330 print
'<div class="fichecenter"><div class="fichehalfleft">';
3335 $relativepath = $objref.
'/'.$objref.
'.pdf';
3337 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3338 $genallowed = $usercanread;
3339 $delallowed = $usercancreate;
3342 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, (
int) $genallowed, (int) $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'',
$object->thirdparty->default_lang,
'', $object);
3343 $somethingshown = $formfile->numoffiles;
3346 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'supplier_order',
'order_supplier'), 1);
3347 $linktoelem = $tmparray[
'linktoelem'];
3348 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
3349 print $htmltoenteralink;
3351 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3353 print
'</div><div class="fichehalfright">';
3355 if ($action ==
'classifyreception') {
3358 print
'<!-- form to record purchase order received -->'.
"\n";
3359 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
3360 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3361 print
'<input type="hidden" name="action" value="livraison">';
3364 print
'<table class="noborder centpercent">';
3366 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
3368 print $form->selectDate($datepreselected,
'', 1, 1, 0,
"commande", 1, 1);
3369 print
"</td></tr>\n";
3371 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
3373 $liv[
''] =
' ';
3374 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
3375 $liv[
'par'] = $langs->trans(
"PartialWoman");
3376 $liv[
'nev'] = $langs->trans(
"NeverReceived");
3377 $liv[
'can'] = $langs->trans(
"Canceled");
3379 print $form->selectarray(
"type", $liv);
3382 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
3383 print
'<tr><td class="center" colspan="2">';
3384 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
3385 print
' ';
3386 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
3395 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3397 $somethingshown = $formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3399 print
'</div></div>';
3403 $modelmail =
'order_supplier_send';
3404 $defaulttopic =
'SendSupplierOrderRef';
3406 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
3407 $trackid =
'sord'.$object->id;
3409 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_VALIDATED
Validated status.
const STATUS_RECEIVED_COMPLETELY
Received completely.
const STATUS_DRAFT
Draft status.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
Class to manage line orders.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage the table of subscription to notifications.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.