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');
100$backtopage =
GETPOST(
'backtopage',
'alpha');
101$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
108$origin =
GETPOST(
'origin',
'alpha');
111$stockDelete =
GETPOST(
'stockDelete',
'int');
122if ($user->isExternalUser()) {
123 $socid = $user->isExternalUser();
127$hookmanager->initHooks(array(
'ordersuppliercard',
'globalcard'));
132$extrafields->fetch_name_optionals_label(
$object->table_element);
135if ($id > 0 || !empty($ref)) {
136 $ret =
$object->fetch($id, $ref);
138 dol_print_error($db,
$object->error);
140 $ret =
$object->fetch_thirdparty();
142 dol_print_error($db,
$object->error);
144} elseif (!empty($socid) && $socid > 0) {
146 $ret =
$object->fetch_thirdparty();
148 dol_print_error($db,
$object->error);
153$isdraft = (isset(
$object->status) && (
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
154$result =
restrictedArea($user,
'fournisseur', $object,
'commande_fournisseur',
'commande',
'fk_soc',
'rowid', $isdraft);
157$usercanread = ($user->hasRight(
"fournisseur",
"commande",
"lire") || $user->hasRight(
"supplier_order",
"lire"));
158$usercancreate = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
159$usercandelete = (($user->hasRight(
"fournisseur",
"commande",
"supprimer") || $user->hasRight(
"supplier_order",
"supprimer")) || ($usercancreate && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT));
162$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate")));
165$usercanapprove = $user->hasRight(
"fournisseur",
"commande",
"approuver");
166$usercanapprovesecond = $user->hasRight(
"fournisseur",
"commande",
"approve2");
167$usercanorder = $user->hasRight(
"fournisseur",
"commande",
"commander");
169 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
171 $usercanreceive = $user->hasRight(
"reception",
"creer");
175$permissionnote = $usercancreate;
176$permissiondellink = $usercancreate;
177$permissiontoedit = $usercancreate;
178$permissiontoadd = $usercancreate;
179$permissiontoeditextra = $permissiontoadd;
180if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
182 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
186$caneditproject =
false;
199$parameters = array(
'socid' => $socid);
200$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
202 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
205if (empty($reshook)) {
206 $backurlforlist = DOL_URL_ROOT.
'/fourn/commande/list.php'.($socid > 0 ?
'?socid='.((int) $socid) :
'');
208 if (empty($backtopage) || ($cancel && empty($id))) {
209 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
210 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
211 $backtopage = $backurlforlist;
213 $backtopage = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
219 if (!empty($backtopageforcancel)) {
220 header(
"Location: ".$backtopageforcancel);
222 } elseif (!empty($backtopage)) {
223 header(
"Location: ".$backtopage);
229 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
231 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
233 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
235 if ($action ==
'setref_supplier' && $usercancreate) {
236 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'ORDER_SUPPLIER_MODIFY');
243 if ($action ==
'set_incoterms' && $usercancreate) {
251 if ($action ==
'setconditions' && $usercancreate) {
259 if ($action ==
'setmode' && $usercancreate) {
264 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
266 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
267 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
273 if ($action ==
'setbankaccount' && $usercancreate) {
281 if ($action ==
'setwarehouse' && $usercancreate) {
282 $result =
$object->setValueFrom(
'fk_warehouse',
GETPOSTINT(
'fk_warehouse'),
'',
null,
'int',
'', $user,
'ORDER_SUPPLIER_MODIFY');
289 if ($action ==
'setdate_livraison' && $usercancreate) {
290 $result =
$object->setDeliveryDate($user, $datelivraison);
297 if ($action ==
'classin' && $usercancreate && $caneditproject) {
298 $result =
$object->setProject($projectid);
305 if ($action ==
'confirm_delete_subtotalline' && $confirm ==
'yes' && $usercancreate) {
310 $result =
$object->deleteSubtotalLine($langs,
GETPOSTINT(
'lineid'), (
bool)
GETPOST(
'deletecorrespondingsubtotalline'));
315 $outputlangs = $langs;
321 $newlang =
$object->thirdparty->default_lang;
323 if (!empty($newlang)) {
325 $outputlangs->setDefaultLang($newlang);
326 $outputlangs->load(
'products');
330 $result =
$object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
333 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
341 if ($action ==
'addline' &&
GETPOST(
'updateallvatlinesblock',
'alpha') &&
GETPOST(
'vatforblocklines',
'alpha') !==
'' && $usercancreate) {
342 $tx_tva =
GETPOST(
'vatforblocklines') ?
GETPOST(
'vatforblocklines') : 0;
343 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'tva', $tx_tva);
347 } elseif ($action ==
'addline' &&
GETPOST(
'updatealldiscountlinesblock',
'alpha') &&
GETPOST(
'discountforblocklines',
'alpha') !==
'' && $usercancreate) {
348 $discount =
GETPOST(
'discountforblocklines') ?
GETPOST(
'discountforblocklines') : 0;
349 $result =
$object->updateSubtotalLineBlockLines($langs,
$object->getRangOfLine($lineid),
'discount', $discount);
355 if ($action ==
'settags' &&
isModEnabled(
'category') && $usercancreate) {
365 if (!empty($new_socid) && $new_socid !=
$object->thirdparty->id) {
369 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
370 $sql .=
' SET fk_soc = '.((int) $new_socid);
371 $sql .=
' WHERE fk_soc = '.((int)
$object->thirdparty->id);
372 $sql .=
' AND rowid = '.((int)
$object->id);
374 $res = $db->query($sql);
382 foreach (
$object->lines as $l) {
383 $sql =
'SELECT price, unitprice, tva_tx, ref_fourn';
384 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
385 $sql .=
' WHERE fk_product = '.((int) $l->fk_product);
386 $sql .=
' AND fk_soc = '.((int) $new_socid);
387 $sql .=
' ORDER BY unitprice ASC';
389 $resql = $db->query($sql);
391 $num_row = $db->num_rows($resql);
392 if (empty($num_row)) {
398 $l->ref_supplier =
'';
399 if ($l->update() < 0) {
400 setEventMessages($l->error, $l->errors,
'errors');
404 $obj = $db->fetch_object($resql);
405 $l->subprice = $obj->unitprice;
406 $l->total_ht = $obj->price;
407 $l->tva_tx = $obj->tva_tx;
408 $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
409 $l->total_ttc = $l->total_ht + $l->total_tva;
410 $l->ref_supplier = $obj->ref_fourn;
411 if ($l->update() < 0) {
412 setEventMessages($l->error, $l->errors,
'errors');
416 dol_print_error($db);
423 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
427 if ($action ==
'setremisepercent' && $usercancreate) {
434 if ($action ==
'reopen' && $permissiontoadd) {
435 $resSetReopen =
$object->setReopen($user);
437 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
447 if ($action ==
'classifybilled' && $usercancreate) {
448 $ret =
$object->classifyBilled($user);
452 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
453 $ret =
$object->classifyUnBilled($user);
460 if ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
464 foreach (
$object->lines as $line) {
465 if ($line->product_type == 1) {
467 $line_price_base_type = $line->getPriceBaseType();
468 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
469 $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);
472 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
474 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
475 $remise_percent = str_replace(
'*',
'', $remise_percent);
476 foreach (
$object->lines as $line) {
478 $line_price_base_type = $line->getPriceBaseType();
479 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
480 $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);
482 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
484 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
485 $vat_rate = str_replace(
'*',
'', $vat_rate);
488 foreach (
$object->lines as $line) {
489 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
493 $line_price_base_type = $line->getPriceBaseType();
494 $line_pu = ($line_price_base_type ===
'TTC') ? (
float) $line->subprice_ttc : (float) $line->subprice;
495 $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);
497 } elseif ($action ==
'confirm_addtextline' && $usercancreate) {
500 $langs->load(
'subtotals');
502 $desc =
GETPOST(
'subtotaltextcontent',
'restricthtml');
505 $result =
$object->addSubtotalLine($langs, $desc, 0, array());
516 $outputlangs = $langs;
517 $newlang =
GETPOST(
'lang_id',
'alpha');
519 $newlang =
$object->thirdparty->default_lang;
521 if (!empty($newlang)) {
523 $outputlangs->setDefaultLang($newlang);
526 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
531 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
533 } elseif ($action ==
'confirm_addtitleline' && $usercancreate) {
536 $langs->load(
'subtotals');
538 $desc =
GETPOST(
'subtotallinedesc',
'alphanohtml');
539 $depth =
GETPOSTINT(
'subtotallinelevel') ?? 1;
541 $subtotal_options = array();
543 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
544 $value =
GETPOST($option,
'alphanohtml');
546 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
551 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
562 $outputlangs = $langs;
563 $newlang =
GETPOST(
'lang_id',
'alpha');
565 $newlang =
$object->thirdparty->default_lang;
567 if (!empty($newlang)) {
569 $outputlangs->setDefaultLang($newlang);
572 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
577 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
579 } elseif ($action ==
'confirm_addsubtotalline' && $usercancreate) {
582 $langs->load(
'subtotals');
584 $choosen_line =
GETPOST(
'subtotaltitleline',
'alphanohtml');
585 foreach (
$object->lines as $line) {
586 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
588 $depth = -$line->qty;
592 $subtotal_options = array();
594 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
595 $value =
GETPOST($option,
'alphanohtml');
597 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
602 if (isset($desc) && isset($depth)) {
603 $result =
$object->addSubtotalLine($langs, $desc, (
int) $depth, $subtotal_options);
606 $object->errors[] = $langs->trans(
"CorrespondingTitleNotFound");
615 $outputlangs = $langs;
616 $newlang =
GETPOST(
'lang_id',
'alpha');
618 $newlang =
$object->thirdparty->default_lang;
620 if (!empty($newlang)) {
622 $outputlangs->setDefaultLang($newlang);
625 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
630 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
632 } elseif ($action ==
'addline' && $usercancreate) {
635 $langs->load(
'errors');
644 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
645 if ($prod_entry_mode ==
'free') {
660 if (empty($remise_percent)) {
665 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
666 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
668 if (is_array($extralabelsline)) {
670 foreach ($extralabelsline as $key => $value) {
671 unset($_POST[
"options_".$key]);
675 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') < 0 && $qty < 0) {
676 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPrice'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
679 if ($prod_entry_mode ==
'free' && !
GETPOST(
'idprodfournprice') &&
GETPOST(
'type') < 0) {
680 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
683 if ($prod_entry_mode ==
'free' &&
GETPOST(
'price_ht') ===
'' &&
GETPOST(
'price_ttc') ===
'' && $price_ht_devise ===
'') {
684 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'UnitPrice')),
null,
'errors');
687 if ($prod_entry_mode ==
'free' && !
GETPOST(
'dp_desc')) {
688 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
691 if (
GETPOST(
'qty',
'alpha') ==
'') {
692 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
696 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
697 if ($combinations =
GETPOST(
'combinations',
'array:alphanohtml')) {
701 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
702 $idprod = $res->fk_product_child;
704 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
710 if ($prod_entry_mode !=
'free' && empty($error)) {
714 if (
GETPOST(
'idprodfournprice',
'alpha') == -1 ||
GETPOST(
'idprodfournprice',
'alpha') ==
'') {
719 if (preg_match(
'/^idprod_([0-9]+)$/',
GETPOST(
'idprodfournprice',
'alpha'), $reg)) {
720 $idprod = (int) $reg[1];
721 $res = $productsupplier->fetch($idprod);
724 if (
getDolGlobalString(
'SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
726 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
727 if ($productsupplier->fourn_socid != $socid) {
728 $productsupplier->ref_supplier =
'';
731 $fksoctosearch =
$object->thirdparty->id;
732 $productsupplier->get_buyprice(0, -1, $idprod,
'none', $fksoctosearch);
734 } elseif (
GETPOSTINT(
'idprodfournprice') > 0) {
735 $qtytosearch = (float) $qty;
737 $idprod = $productsupplier->get_buyprice(
GETPOSTINT(
'idprodfournprice'), $qtytosearch);
738 $res = $productsupplier->fetch($idprod);
742 $label = $productsupplier->label;
746 $outputlangs = $langs;
748 if (
GETPOST(
'lang_id',
'aZ09')) {
749 $newlang =
GETPOST(
'lang_id',
'aZ09');
751 if (empty($newlang)) {
752 $newlang =
$object->thirdparty->default_lang;
754 if (!empty($newlang)) {
756 $outputlangs->setDefaultLang($newlang);
758 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang][
"description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang][
"description"] : $productsupplier->
description;
760 $desc = $productsupplier->description;
763 if (!empty($productsupplier->desc_supplier) &&
getDolGlobalString(
'PRODUIT_FOURN_TEXTS')) {
764 $desc = $productsupplier->desc_supplier;
775 $ref_supplier = $productsupplier->ref_supplier;
776 if (empty($ref_supplier) && !empty(
GETPOST(
'fourn_ref',
'alpha'))) {
777 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
783 $tmpidprodfournprice =
GETPOST(
'idprodfournprice',
'alpha');
784 if (is_numeric($tmpidprodfournprice) && (
int) $tmpidprodfournprice > 0) {
785 $tmpidprodfournprice = (int) $tmpidprodfournprice;
787 $tmpidprodfournprice = 0;
791 if (empty($tva_tx)) {
799 $type = $productsupplier->type;
800 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
801 $price_base_type =
'HT';
803 $pu_devise =
price2num($price_ht_devise,
'CU');
804 } elseif (
GETPOST(
'price_ttc') !=
'' ||
GETPOST(
'multicurrency_price_ttc') !=
'') {
805 $price_base_type =
'TTC';
807 $pu_devise =
price2num($price_ttc_devise,
'CU');
809 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type :
'HT');
810 if (empty(
$object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code !=
$object->multicurrency_code)) {
811 $pu = $productsupplier->fourn_pu;
814 $pu = $productsupplier->fourn_pu;
815 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
825 ($price_base_type ==
'HT' ? $pu : 0),
831 $productsupplier->product_fourn_price_id,
835 ($price_base_type ==
'TTC' ? $pu : 0),
842 $productsupplier->fk_unit,
846 min($rank, count(
$object->lines) + 1)
849 if ($idprod == -99 || $idprod == 0) {
852 $langs->load(
"errors");
853 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
858 $langs->load(
"errors");
859 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'errors');
861 } elseif (empty($error)) {
862 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
863 $tva_tx = str_replace(
'*',
'', $tva_tx);
864 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
867 $ref_supplier =
GETPOST(
'fourn_ref',
'alpha');
871 if (!preg_match(
'/\((.*)\)/', $tva_tx)) {
880 if (
GETPOST(
'price_ht') !=
'' ||
GETPOST(
'multicurrency_price_ht') !=
'') {
881 $price_base_type =
'HT';
884 $pu_ht_devise =
price2num($price_ht_devise,
'CU');
886 $price_base_type =
'TTC';
889 $pu_ht_devise =
price2num($price_ttc_devise,
'CU');
892 $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);
896 if (!$error && $result > 0) {
904 $outputlangs = $langs;
907 $newlang =
$object->thirdparty->default_lang;
908 if (
GETPOST(
'lang_id',
'aZ09')) {
909 $newlang =
GETPOST(
'lang_id',
'aZ09');
912 if (!empty($newlang)) {
914 $outputlangs->setDefaultLang($newlang);
919 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
925 unset($_POST [
'prod_entry_mode']);
927 unset($_POST[
'qty']);
928 unset($_POST[
'type']);
929 unset($_POST[
'remise_percent']);
931 unset($_POST[
'price_ht']);
932 unset($_POST[
'multicurrency_price_ht']);
933 unset($_POST[
'price_ttc']);
934 unset($_POST[
'fourn_ref']);
935 unset($_POST[
'tva_tx']);
936 unset($_POST[
'label']);
937 unset($localtax1_tx);
938 unset($localtax2_tx);
939 unset($_POST[
'np_marginRate']);
940 unset($_POST[
'np_markRate']);
941 unset($_POST[
'dp_desc']);
942 unset($_POST[
'idprodfournprice']);
943 unset($_POST[
'units']);
945 unset($_POST[
'date_starthour']);
946 unset($_POST[
'date_startmin']);
947 unset($_POST[
'date_startsec']);
948 unset($_POST[
'date_startday']);
949 unset($_POST[
'date_startmonth']);
950 unset($_POST[
'date_startyear']);
951 unset($_POST[
'date_endhour']);
952 unset($_POST[
'date_endmin']);
953 unset($_POST[
'date_endsec']);
954 unset($_POST[
'date_endday']);
955 unset($_POST[
'date_endmonth']);
956 unset($_POST[
'date_endyear']);
958 header(
'Location: '.
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
966 } elseif ($action ==
'updatetitleline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
969 $langs->load(
'subtotals');
971 $desc =
GETPOST(
'line_desc',
'alphanohtml') ?? $langs->trans(
"Title");
974 $subtotal_options = array();
976 foreach (CommandeFournisseur::$TITLE_OPTIONS as $option) {
977 $value =
GETPOST($option,
'alphanohtml');
979 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
984 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
995 $outputlangs = $langs;
996 $newlang =
GETPOST(
'lang_id',
'alpha');
998 $newlang =
$object->thirdparty->default_lang;
1000 if (!empty($newlang)) {
1002 $outputlangs->setDefaultLang($newlang);
1005 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1010 } elseif ($action ==
'updatetextline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1013 $langs->load(
'subtotals');
1015 $desc =
GETPOST(
'line_desc',
'restricthtml');
1018 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, 0, array());
1029 $outputlangs = $langs;
1030 $newlang =
GETPOST(
'lang_id',
'alpha');
1032 $newlang =
$object->thirdparty->default_lang;
1034 if (!empty($newlang)) {
1036 $outputlangs->setDefaultLang($newlang);
1039 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1044 } elseif ($action ==
'updatesubtotalline' &&
GETPOSTISSET(
"save") && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1047 $langs->load(
'subtotals');
1049 $desc =
GETPOST(
'line_desc',
'alphanohtml');
1052 $subtotal_options = array();
1054 foreach (CommandeFournisseur::$SUBTOTAL_OPTIONS as $option) {
1055 $value =
GETPOST($option,
'alphanohtml');
1057 $subtotal_options[$option] = $value ==
'on' ? 1 : $value;
1062 $result =
$object->updateSubtotalLine($langs,
GETPOSTINT(
'lineid'), $desc, $depth, $subtotal_options);
1070 $outputlangs = $langs;
1071 $newlang =
GETPOST(
'lang_id',
'alpha');
1073 $newlang =
$object->thirdparty->default_lang;
1075 if (!empty($newlang)) {
1077 $outputlangs->setDefaultLang($newlang);
1080 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1085 } elseif ($action ==
'updateline' && $usercancreate && !
GETPOST(
'cancel',
'alpha')) {
1094 $res = $line->fetch($lineid);
1096 dol_print_error($db);
1101 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
1102 if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, (
float)
price2num(
GETPOSTFLOAT(
'qty')), $line->fk_product,
'none',
GETPOSTINT(
'socid')) < 0) {
1103 setEventMessages($langs->trans(
"ErrorQtyTooLowForThisSupplier"),
null,
'warnings');
1112 if (preg_match(
'/\*/', $vat_rate)) {
1117 $vat_rate = str_replace(
'*',
'', $vat_rate);
1128 $price_base_type =
'HT';
1129 if (empty($pu_ht) && !empty($pu_ttc)) {
1131 $price_base_type =
'TTC';
1132 } elseif (!empty($pu_ht) && !empty($pu_ttc)) {
1133 foreach (
$object->lines as $line_obj) {
1136 if ($line_obj->wasEnteredIncludingTax()) {
1138 $price_base_type =
'TTC';
1148 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1149 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1151 if (is_array($extralabelsline)) {
1152 foreach ($extralabelsline as $key => $value) {
1153 unset($_POST[
"options_".$key]);
1157 $result =
$object->updateline(
1159 GETPOST(
'product_desc',
'restricthtml'),
1174 (float) $pu_ht_devise,
1177 unset($_POST[
'qty']);
1178 unset($_POST[
'type']);
1179 unset($_POST[
'idprodfournprice']);
1180 unset($_POST[
'remmise_percent']);
1181 unset($_POST[
'dp_desc']);
1182 unset($_POST[
'np_desc']);
1183 unset($_POST[
'pu']);
1184 unset($_POST[
'fourn_ref']);
1185 unset($_POST[
'tva_tx']);
1186 unset($_POST[
'date_start']);
1187 unset($_POST[
'date_end']);
1188 unset($_POST[
'units']);
1189 unset($localtax1_tx);
1190 unset($localtax2_tx);
1192 unset($_POST[
'date_starthour']);
1193 unset($_POST[
'date_startmin']);
1194 unset($_POST[
'date_startsec']);
1195 unset($_POST[
'date_startday']);
1196 unset($_POST[
'date_startmonth']);
1197 unset($_POST[
'date_startyear']);
1198 unset($_POST[
'date_endhour']);
1199 unset($_POST[
'date_endmin']);
1200 unset($_POST[
'date_endsec']);
1201 unset($_POST[
'date_endday']);
1202 unset($_POST[
'date_endmonth']);
1203 unset($_POST[
'date_endyear']);
1208 $outputlangs = $langs;
1211 $newlang =
GETPOST(
'lang_id',
'aZ09');
1214 $newlang =
$object->thirdparty->default_lang;
1216 if (!empty($newlang)) {
1218 $outputlangs->setDefaultLang($newlang);
1223 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1238 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
1241 $result =
$object->deleteLine($lineid);
1246 $outputlangs = $langs;
1249 $newlang =
GETPOST(
'lang_id',
'aZ09');
1252 $newlang =
$object->thirdparty->default_lang;
1254 if (!empty($newlang)) {
1256 $outputlangs->setDefaultLang($newlang);
1260 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1282 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
1290 if ($action ==
'confirm_valid' && $confirm ==
'yes' && $usercanvalidate) {
1294 $result =
$object->valid($user);
1298 $outputlangs = $langs;
1301 $newlang =
GETPOST(
'lang_id',
'aZ09');
1304 $newlang =
$object->thirdparty->default_lang;
1306 if (!empty($newlang)) {
1308 $outputlangs->setDefaultLang($newlang);
1313 $result =
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1326 $action =
'confirm_approve';
1336 if (($action ==
'confirm_approve' || $action ==
'confirm_approve2') && $confirm ==
'yes' && $usercanapprove) {
1341 $qualified_for_stock_change = 0;
1343 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1345 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1350 if (!$idwarehouse || $idwarehouse == -1) {
1352 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1358 $result =
$object->approve($user, $idwarehouse, ($action ==
'confirm_approve2' ? 1 : 0));
1361 $outputlangs = $langs;
1364 $newlang =
GETPOST(
'lang_id',
'aZ09');
1367 $newlang =
$object->thirdparty->default_lang;
1369 if (!empty($newlang)) {
1371 $outputlangs->setDefaultLang($newlang);
1373 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1384 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1391 if ($action ==
'confirm_refuse' && $confirm ==
'yes' && $usercanapprove) {
1395 $result =
$object->refuse($user);
1397 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1405 if ($action ==
'commande') {
1406 $methodecommande =
GETPOSTINT(
'methodecommande');
1410 } elseif ($methodecommande <= 0 && !
getDolGlobalInt(
'SUPPLIER_ORDER_MODE_OPTIONAL')) {
1411 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"OrderMode")),
null,
'errors');
1412 $action =
'createorder';
1416 if ($action ==
'confirm_commande' && $confirm ==
'yes' && $usercanorder) {
1418 $object->context[
"sendmanualtriggers"] =
GETPOST(
"manual_trigger_send");
1422 $outputlangs = $langs;
1425 $newlang =
GETPOST(
'lang_id',
'aZ09');
1428 $newlang =
$object->thirdparty->default_lang;
1430 if (!empty($newlang)) {
1432 $outputlangs->setDefaultLang($newlang);
1434 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1445 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1453 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
1456 $errorsOnDelete = array();
1511 if (empty($errOnDelete)) {
1513 $result =
$object->delete($user);
1516 header(
"Location: " . DOL_URL_ROOT .
'/fourn/commande/list.php?restore_lastsearch_values=1');
1524 setEventMessages(
'', $errorsOnDelete,
'errors');
1529 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
1531 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
1532 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1537 $result =
$object->createFromClone($user, $socid);
1539 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1551 if ($action ==
'livraison' && $usercanreceive) {
1562 $langs->load(
"sendings");
1563 setEventMessages($langs->trans(
"DeliveryStateSaved"),
null);
1572 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Delivery")),
null,
'errors');
1583 if ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanorder) {
1587 $result =
$object->cancel($user);
1589 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
$object->id);
1597 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1600 $triggersendname =
'ORDER_SUPPLIER_SENTBYMAIL';
1601 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1602 $trackid =
'sord'.$object->id;
1603 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1607 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1610 if ($action ==
'update_extras' && $permissiontoeditextra) {
1613 $attribute_name =
GETPOST(
'attribute',
'aZ09');
1616 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
1622 $result =
$object->updateExtraField($attribute_name,
'ORDER_SUPPLIER_MODIFY');
1630 $action =
'edit_extras';
1637 if ($action ==
'add' && $permissiontoadd) {
1639 $selectedLines =
GETPOST(
'toselect',
'array:int');
1641 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Supplier')),
null,
'errors');
1658 $object->delivery_date = $datelivraison;
1661 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
1662 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
1668 $ret = $extrafields->setOptionalsFromPost(
null, $object);
1676 if (!empty($origin) && !empty($originid)) {
1677 $element = $subelement = $origin;
1678 $classname = ucfirst($subelement);
1679 if ($origin ==
'propal' || $origin ==
'proposal') {
1680 $element =
'comm/propal';
1681 $subelement =
'propal';
1682 $classname =
'Propal';
1684 if ($origin ==
'order' || $origin ==
'commande') {
1685 $element = $subelement =
'commande';
1686 $classname =
'Commande';
1688 if ($origin ==
'supplier_proposal') {
1689 $classname =
'SupplierProposal';
1690 $element =
'supplier_proposal';
1691 $subelement =
'supplier_proposal';
1695 $object->origin_type = $origin;
1696 $object->origin_id = $originid;
1700 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
1701 if (!empty($other_linked_objects)) {
1702 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
1709 $srcobject =
new $classname($db);
1711 dol_syslog(
"Try to find source object origin=".
$object->origin_type.
" originid=".
$object->origin_id.
" to add lines");
1712 $result = $srcobject->fetch(
$object->origin_id);
1714 if (empty(
$object->delivery_date)) {
1715 $tmpdate = $srcobject->delivery_date;
1716 $object->setDeliveryDate($user, $tmpdate);
1719 $object->set_id_projet($user, $srcobject->fk_project);
1721 $lines = $srcobject->lines;
1722 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
1723 $srcobject->fetch_lines();
1724 $lines = $srcobject->lines;
1727 $fk_parent_line = 0;
1728 $num = count($lines);
1730 for ($i = 0; $i < $num; $i++) {
1732 empty($lines[$i]->subprice)
1733 || $lines[$i]->qty < 0
1734 || !in_array($lines[$i]->
id, $selectedLines)
1735 || $lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE
1740 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
1741 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
1742 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1744 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1745 $fk_parent_line = 0;
1749 if (method_exists($lines[$i],
'fetch_optionals')) {
1750 $lines[$i]->fetch_optionals();
1751 $array_option = $lines[$i]->array_options;
1753 $array_option = array();
1757 $product_fourn_price_id = 0;
1758 if ($origin ==
"commande") {
1760 $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty,
$object->socid);
1761 $lines[$i]->subprice = 0;
1763 $ref_supplier = $productsupplier->ref_supplier;
1764 $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1766 foreach ($srcobject->lines as $li) {
1767 $sql =
'SELECT price, unitprice, tva_tx, remise_percent, entity, ref_fourn';
1768 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price';
1769 $sql .=
' WHERE fk_product = '.((int) $li->fk_product);
1770 $sql .=
' AND entity IN ('.getEntity(
'product_fournisseur_price').
')';
1771 $sql .=
' AND fk_soc = '.((int)
$object->socid);
1772 $sql .=
' ORDER BY unitprice ASC';
1774 $resql = $db->query($sql);
1776 $num_row = $db->num_rows($resql);
1777 if (empty($num_row)) {
1778 $li->remise_percent = 0;
1780 $obj = $db->fetch_object($resql);
1781 $li->subprice = $obj->unitprice;
1782 $li->remise_percent = $obj->remise_percent;
1785 dol_print_error($db);
1791 $ref_supplier = $lines[$i]->ref_fourn;
1792 $product_fourn_price_id = 0;
1795 $tva_tx = $lines[$i]->tva_tx;
1797 if ($origin ==
"commande") {
1799 $soc->fetch($socid);
1804 $line_price_base_type = $lines[$i]->getPriceBaseType();
1807 $lines[$i]->subprice,
1810 $lines[$i]->localtax1_tx,
1811 $lines[$i]->localtax2_tx,
1812 $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1813 $product_fourn_price_id,
1815 $lines[$i]->remise_percent,
1816 $line_price_base_type,
1817 (float) $lines[$i]->subprice_ttc,
1818 $lines[$i]->product_type,
1824 $lines[$i]->fk_unit,
1827 !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid,
1829 $lines[$i]->special_code,
1840 if ($result > 0 && $lines[$i]->product_type == 9) {
1841 $fk_parent_line = $result;
1849 $parameters = array(
'objFrom' => $srcobject);
1850 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
1853 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1857 setEventMessages($srcobject->error, $srcobject->errors,
'errors');
1874 $categories =
GETPOST(
'categories',
'array:int');
1875 if (method_exists($object,
'setCategories')) {
1876 $object->setCategories($categories);
1881 $langs->load(
"errors");
1886 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".urlencode((
string) ($id)));
1893 if ($action ==
'addcontact' && $permissiontoadd) {
1897 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1901 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1904 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1905 $langs->load(
"errors");
1906 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1911 } elseif ($action ==
'swapstatut' &&
$object->id > 0 && $permissiontoadd) {
1914 } elseif ($action ==
'deletecontact' &&
$object->id > 0 && $permissiontoadd) {
1919 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1922 dol_print_error($db);
1933$form =
new Form($db);
1936$productstatic =
new Product($db);
1941$title =
$object->ref.
" - ".$langs->trans(
'Card');
1942if ($action ==
'create') {
1943 $title = $langs->trans(
"NewOrderSupplier");
1945$help_url =
'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1946llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-supplier-order page-card');
1950if ($action ==
'create') {
1951 print
load_fiche_titre($langs->trans(
'NewOrderSupplier'),
'',
'supplier_order');
1955 $currency_code =
$conf->currency;
1962 $societe->fetch($socid);
1965 if (!empty($origin) && !empty($originid)) {
1967 $element = $subelement = $origin;
1968 $classname = ucfirst($subelement);
1970 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1971 $element = $regs[1];
1972 $subelement = $regs[2];
1975 if ($origin ==
'propal' || $origin ==
'proposal') {
1976 $classname =
'Propal';
1977 $element =
'comm/propal';
1978 $subelement =
'propal';
1980 if ($origin ==
'order' || $origin ==
'commande') {
1981 $classname =
'Commande';
1982 $element = $subelement =
'commande';
1984 if ($origin ==
'supplier_proposal') {
1985 $classname =
'SupplierProposal';
1986 $element =
'supplier_proposal';
1987 $subelement =
'supplier_proposal';
1993 $objectsrc =
new $classname($db);
1994 $objectsrc->fetch($originid);
1995 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1996 $objectsrc->fetch_lines();
1998 $objectsrc->fetch_thirdparty();
2001 $objectsrc->fetch_optionals();
2002 $object->array_options = $objectsrc->array_options;
2004 $projectid = (int) $objectsrc->fk_project;
2005 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
2007 if ($origin ==
"commande") {
2008 $cond_reglement_id = 0;
2009 $deposit_percent = 0;
2010 $mode_reglement_id = 0;
2011 $objectsrc->note_private =
'';
2012 $objectsrc->note_public =
'';
2013 if ($societe =
$object->thirdparty) {
2014 $cond_reglement_id = $societe->cond_reglement_supplier_id;
2015 $deposit_percent = $societe->deposit_percent;
2016 $mode_reglement_id = $societe->mode_reglement_supplier_id;
2018 $currency_code = $societe->multicurrency_code;
2020 $currency_tx = $societe->multicurrency_tx;
2025 $soc = $objectsrc->thirdparty;
2027 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
2028 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : 0));
2029 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
2030 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
2031 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
2032 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
2033 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
2036 $datelivraison = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
2039 if (!empty($objectsrc->multicurrency_code)) {
2040 $currency_code = $objectsrc->multicurrency_code;
2042 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
2043 $currency_tx = $objectsrc->multicurrency_tx;
2047 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
2048 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
2051 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
2054 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2055 $deposit_percent = !empty($societe->deposit_percent) ? $societe->deposit_percent : 0;
2056 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2058 if (
isModEnabled(
"multicurrency") && !empty($societe->multicurrency_code)) {
2059 $currency_code = $societe->multicurrency_code;
2062 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
2063 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
2067 if (empty($cond_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID')) {
2070 if (empty($mode_reglement_id) &&
getDolGlobalString(
'SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID')) {
2073 if (
GETPOSTISSET(
'cond_reglement_id_deposit_percent')) {
2074 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
2077 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
2078 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2079 print
'<input type="hidden" name="action" value="add">';
2080 print
'<input type="hidden" name="remise_percent" value="'.(empty($soc->remise_supplier_percent) ?
'' : $soc->remise_supplier_percent).
'">';
2081 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
2082 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
2083 print
'<input type="hidden" name="changecompany" value="0">';
2085 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2087 if ($backtopageforcancel) {
2088 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
2091 if (!empty($currency_tx)) {
2092 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
2098 $parameters = array();
2100 $reshook = $hookmanager->executeHooks(
'tabContentCreateSupplierOrder', $parameters, $object, $action);
2101 if (empty($reshook)) {
2102 print
'<table class="border centpercent">';
2105 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
'Draft').
'</td></tr>';
2108 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Supplier').
'</td>';
2111 if (!empty($societe->id) && $societe->id > 0) {
2112 print $societe->getNomUrl(1,
'supplier');
2113 print
'<input type="hidden" name="socid" value="'.$societe->id.
'">';
2115 $filter =
'((s.fournisseur:=:1) AND (s.status:=:1))';
2116 print img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company((empty($socid) ?
'' : $socid),
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
2120 $(document).ready(function() {
2121 $("#socid").change(function() {
2122 console.log("We have changed the company - Reload page");
2124 $("input[name=action]").val("create");
2125 $("input[name=changecompany]").val("1");
2126 $("form[name=add]").submit();
2131 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>';
2137 print
'<tr><td>'.$form->textwithpicto($langs->trans(
'RefSupplier'), $langs->trans(
'RefOfOnVendorSide', $langs->transnoentitiesnoconv(
"SupplierOrder")));
2138 print
'</td><td><input name="refsupplier" type="text"></td>';
2142 if (!empty($societe->id) && $societe->id > 0) {
2144 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2146 $absolute_discount = $societe->getAvailableDiscounts(
null,
'', 0, 1);
2148 $thirdparty = $societe;
2150 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
2151 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2157 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2158 print img_picto(
'',
'payment',
'class="pictofixedwidth"');
2159 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);
2163 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2164 print img_picto(
'',
'bank',
'class="pictofixedwidth"');
2165 $form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOSTINT(
'mode_reglement_id') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id,
'mode_reglement_id');
2170 print $langs->trans(
'DateDeliveryPlanned');
2177 print img_picto(
'',
'action',
'class="pictofixedwidth"');
2178 print $form->selectDate($datelivraison ? $datelivraison : -1,
'liv_', $usehourmin, $usehourmin, 0,
"set", 1, 1);
2185 print $form->textwithpicto($langs->trans(
'DefaultWarehouse'), $langs->trans(
'SupplierOrderDefaultWarehouseHelp'));
2188 print img_picto(
'',
'stock',
'class="pictofixedwidth"');
2189 print $formproductcreate->selectWarehouses(
GETPOSTISSET(
'fk_warehouse') ?
GETPOSTINT(
'fk_warehouse') :
'',
'fk_warehouse',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
2195 $langs->load(
"bank");
2196 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2197 print img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
2198 $form->select_comptes($fk_account ??
'',
'fk_account', 0,
'', 1);
2206 $langs->load(
'projects');
2207 print
'<tr><td>'.$langs->trans(
'Project').
'</td><td>';
2208 if (!empty($user->socid)) {
2209 $projSocFilter = $user->socid;
2210 } elseif (
getDolGlobalString(
'PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') || (
int) $socid == 0) {
2213 $projSocFilter = -1;
2215 $projSocFilter = $socid;
2217 print img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects($projSocFilter, $projectid,
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500');
2218 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>';
2224 $fkincoterms = (!empty(
$object->fk_incoterms) ?
$object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms :
''));
2225 $locincoterms = (!empty(
$object->location_incoterms) ?
$object->location_incoterms : ($socid > 0 ? $societe->location_incoterms :
''));
2227 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"),
$object->label_incoterms, 1).
'</label></td>';
2228 print
'<td class="maxwidthonsmartphone">';
2229 print img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2230 print $form->select_incoterms($fkincoterms, $locincoterms);
2237 print
'<td>'.$form->editfieldkey(
'Currency',
'multicurrency_code',
'', $object, 0).
'</td>';
2238 print
'<td class="maxwidthonsmartphone">';
2239 print img_picto(
'',
'currency',
'class="pictofixedwidth"');
2240 print $form->selectMultiCurrency($currency_code,
'multicurrency_code');
2246 print
'<tr><td>'.$langs->trans(
"Categories").
'</td><td colspan="3">';
2247 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2251 print
'<tr><td>'.$langs->trans(
'NotePublic').
'</td>';
2253 $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%');
2254 print $doleditor->Create(1);
2259 print
'<tr><td>'.$langs->trans(
'NotePrivate').
'</td>';
2261 $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%');
2262 print $doleditor->Create(1);
2267 if (!empty($origin) && !empty($originid) && is_object($objectsrc) && $classname !==
null) {
2268 print
"\n<!-- ".$classname.
" info -->";
2270 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2271 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2272 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2273 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2274 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2276 $newclassname = $classname;
2277 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1,
'supplier').
'</td></tr>';
2278 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2279 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2280 if (
$mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2281 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2284 if (
$mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2285 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2288 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2291 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2292 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2293 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc, 0, $langs, 1, -1, -1, $objectsrc->multicurrency_code).
'</td></tr>';
2298 $parameters = array();
2299 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2300 print $hookmanager->resPrint;
2302 if (empty($reshook)) {
2303 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_SUPPLIER_ORDER') && !empty($societe->id)) {
2306 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($societe->table_element);
2307 if ($societe->fetch_optionals() > 0) {
2308 $object->array_options = array_merge(
$object->array_options, $societe->array_options);
2312 print
$object->showOptionals($extrafields,
'create');
2320 print $form->buttonsSaveCancel(
"CreateDraft");
2323 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2324 $title = $langs->trans(
'ProductsAndServices');
2327 print
'<div class="div-table-responsive-no-min">';
2328 print
'<table class="noborder centpercent">';
2330 $selectedLines = array();
2332 $objectsrc->printOriginLinesList(
'', $selectedLines);
2338} elseif (!empty(
$object->id)) {
2340 $result =
$object->fetch($id, $ref);
2345 $societe =
$object->thirdparty;
2347 $author =
new User($db);
2348 $author->fetch(
$object->user_author_id);
2352 $title = $langs->trans(
"SupplierOrder");
2353 print
dol_get_fiche_head($head,
'card', $title, -1,
'order', 0,
'',
'', 0,
'', 1);
2359 if ($action ==
'delete') {
2360 $arrayAjouts = array();
2391 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.((
int)
$object->id), $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal);
2395 if ($action ==
'clone') {
2396 $filter =
'(s.fournisseur:=:1)';
2398 $formquestion = array(
2399 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter))
2402 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2406 if ($action ==
'valid') {
2410 if (preg_match(
'/^[\(]?PROV/i', (
string)
$object->ref) || empty(
$object->ref)) {
2413 $newref = (string)
$object->ref;
2420 $text = $langs->trans(
'ConfirmValidateOrder', $newref);
2422 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2423 $notify =
new Notify($db);
2425 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_VALIDATE',
$object->socid, $object);
2428 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_valid',
'', 0, 1);
2433 if ($action ==
'approve' || $action ==
'approve2') {
2434 $qualified_for_stock_change = 0;
2436 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2438 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2441 $formquestion = array();
2443 $langs->load(
"stocks");
2444 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2447 if (
$conf->browser->name ==
'ie') {
2450 $formquestion = array(
2454 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse'),
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2457 $text = $langs->trans(
"ConfirmApproveThisOrder",
$object->ref);
2459 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2460 $notify =
new Notify($db);
2462 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_APPROVE',
$object->socid, $object);
2465 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ApproveThisOrder"), $text,
"confirm_".$action, $formquestion, 1, 1, 240);
2469 if ($action ==
'refuse') {
2470 $formquestion = array(
2473 'name' =>
'refuse_note',
2474 'label' => $langs->trans(
"Reason"),
2476 'morecss' =>
'minwidth300'
2479 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"DenyingThisOrder"), $langs->trans(
"ConfirmDenyingThisOrder",
$object->ref),
"confirm_refuse", $formquestion, 0, 1);
2483 if ($action ==
'cancel') {
2484 $formquestion = array(
2487 'name' =>
'cancel_note',
2488 'label' => $langs->trans(
"Reason"),
2490 'morecss' =>
'minwidth300'
2494 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2495 $notify =
new Notify($db);
2498 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_CANCEL',
$object->socid, $object);
2500 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=$object->id", $langs->trans(
"Cancel"), $langs->trans(
"ConfirmCancelThisOrder",
$object->ref),
"confirm_cancel", $formquestion, 0, 1);
2504 if ($action ==
'commande') {
2505 $formquestion = array();
2508 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2509 $notify =
new Notify($db);
2512 $text .= $notify->confirmMessage(
'ORDER_SUPPLIER_SUBMIT',
$object->socid, $object);
2515 require_once DOL_DOCUMENT_ROOT.
'/webhook/class/target.class.php';
2516 $targetstatic =
new Target($db);
2517 if ($targetstatic->isTriggerCodeManualTarget(
'ORDER_SUPPLIER_SUBMIT') > 0) {
2518 $formquestion[] = array(
'type' =>
'checkbox',
'name' =>
'manual_trigger_send',
'label' => $langs->trans(
"QuestionSendManualTrigger"));
2521 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id.
"&datecommande=".$date_com.
"&methode=".
GETPOST(
"methodecommande").
"&comment=".urlencode(
GETPOST(
"comment")), $langs->trans(
"MakeOrder"), $langs->trans(
"ConfirmMakeOrder",
dol_print_date($date_com,
'day')),
"confirm_commande", $formquestion, 0, 2);
2525 if ($action ==
'ask_deleteline') {
2526 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2530 if ($action ==
'ask_subtotal_deleteline') {
2531 $langs->load(
'subtotals');
2532 $subtotaltitle =
'DeleteSubtotalLine';
2533 $subtotalquestion =
'ConfirmDeleteSubtotalLine';
2534 $subtotalformquestion = array();
2535 if (
GETPOST(
'type') ==
'title') {
2536 $subtotalformquestion = array(array(
'type' =>
'checkbox',
'name' =>
'deletecorrespondingsubtotalline',
'label' => $langs->trans(
'DeleteCorrespondingSubtotalLine'),
'value' => 0));
2537 $subtotaltitle =
'DeleteTitleLine';
2538 $subtotalquestion =
'ConfirmDeleteTitleLine';
2540 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans($subtotaltitle), $langs->trans($subtotalquestion),
'confirm_delete_subtotalline', $subtotalformquestion,
'no', 1);
2544 if ($action ==
'add_title_line') {
2545 $langs->load(
'subtotals');
2547 $depth_array =
$object->getPossibleLevels($langs);
2548 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2549 } elseif ($action ==
'add_subtotal_line') {
2550 $langs->load(
'subtotals');
2552 $titles =
$object->getPossibleTitles();
2553 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2554 } elseif ($action ==
'add_text_line') {
2555 $langs->load(
'subtotals');
2557 require DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_create.tpl.php';
2561 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2562 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2563 if (empty($reshook)) {
2564 $formconfirm .= $hookmanager->resPrint;
2565 } elseif ($reshook > 0) {
2566 $formconfirm = $hookmanager->resPrint;
2575 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2577 $morehtmlref =
'<div class="refidno">';
2579 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier, $object, (
int) $usercancreate,
'string',
'', 0, 1);
2580 $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);
2582 $morehtmlref .=
'<br>';
2583 if (
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') && !empty($usercancreate) && $action ==
'edit_thirdparty') {
2584 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2585 $morehtmlref .=
'<input type="hidden" name="action" value="set_thirdparty">';
2586 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2587 $filter =
'(s.fournisseur:=:1)';
2588 $morehtmlref .= $form->select_company(
$object->thirdparty->id,
'new_socid', $filter,
'', 0, 0, array(), 0,
'minwidth300');
2589 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2590 $morehtmlref .=
'</form>';
2592 if (!
getDolGlobalString(
'MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER') || $action !=
'edit_thirdparty') {
2594 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit_thirdparty&token='.
newToken().
'&id='.
$object->id.
'">'.img_edit($langs->transnoentitiesnoconv(
'SetThirdParty')).
'</a>';
2596 $morehtmlref .=
$object->thirdparty->getNomUrl(1,
'supplier');
2598 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/fourn/commande/list.php?socid='.
$object->thirdparty->id.
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2604 $langs->load(
"projects");
2605 $morehtmlref .=
'<br>';
2606 if ($permissiontoadd) {
2607 $morehtmlref .= img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2608 if ($action !=
'classify' && $caneditproject) {
2609 $morehtmlref .=
'<a class="editfielda" href="'.dolBuildUrl($_SERVER[
'PHP_SELF'], [
'action' =>
'classify',
'id' =>
$object->id],
true).
'">'.img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2611 $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');
2613 if (!empty(
$object->fk_project)) {
2615 $proj->fetch(
$object->fk_project);
2616 $morehtmlref .= $proj->getNomUrl(1);
2618 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2623 $morehtmlref .=
'</div>';
2626 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2629 $parameters = array();
2631 $reshook = $hookmanager->executeHooks(
'tabContentViewSupplierOrder', $parameters, $object, $action);
2632 if (empty($reshook)) {
2633 print
'<div class="fichecenter">';
2634 print
'<div class="fichehalfleft">';
2635 print
'<div class="underbanner clearboth"></div>';
2637 print
'<table class="border tableforfield centpercent">';
2640 if (
$object->methode_commande_id > 0) {
2645 print
'<tr><td class="titlefield">'.$langs->trans(
"Date").
'</td><td>';
2648 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2652 if (
$object->methode_commande) {
2653 print
'<tr><td>'.$langs->trans(
"Method").
'</td><td>'.
$object->getInputMethod().
'</td></tr>';
2658 print
'<tr><td class="titlefield">'.$langs->trans(
"AuthorRequest").
'</td>';
2659 print
'<td>'.$author->getNomUrl(-1,
'', 0, 0, 0).
'</td>';
2664 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL";
2665 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL";
2667 $filterabsolutediscount =
"fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2668 $filtercreditnote =
"fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2671 $absolute_discount = $societe->getAvailableDiscounts(
null, $filterabsolutediscount, 0, 1);
2672 $absolute_creditnote = $societe->getAvailableDiscounts(
null, $filtercreditnote, 0, 1);
2673 $absolute_discount =
price2num($absolute_discount,
'MT');
2674 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2676 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td>';
2678 $thirdparty = $societe;
2680 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
2681 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2686 $langs->load(
'bills');
2687 print
'<tr><td class="nowrap">';
2688 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2689 print $langs->trans(
'PaymentConditions');
2691 if ($action !=
'editconditions' && $permissiontoadd) {
2692 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>';
2694 print
'</tr></table>';
2696 if ($action ==
'editconditions') {
2697 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2699 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id, (
string)
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2705 $langs->load(
'bills');
2706 print
'<tr><td class="nowrap">';
2707 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2708 print $langs->trans(
'PaymentMode');
2710 if ($action !=
'editmode' && $permissiontoadd) {
2711 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>';
2713 print
'</tr></table>';
2715 if ($action ==
'editmode') {
2716 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'mode_reglement_id',
'DBIT', 1, 1);
2718 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->mode_reglement_id,
'none');
2724 print
'<tr><td class="nowrap">';
2725 print
'<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2726 print $langs->trans(
'BankAccount');
2728 if ($action !=
'editbankaccount' && $permissiontoadd) {
2729 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>';
2731 print
'</tr></table>';
2733 if ($action ==
'editbankaccount') {
2734 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'fk_account', 1);
2736 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, (
string)
$object->fk_account,
'none');
2744 print
'<td>'.$langs->trans(
'NbDaysToDelivery').
' '.img_picto($langs->trans(
'DescNbDaysToDelivery'),
'info',
'style="cursor:help"').
'</td>';
2745 print
'<td>'.$object->getMaxDeliveryTimeDay($langs).
'</td>';
2752 print
'<table class="nobordernopadding centpercent"><tr><td>';
2753 print $form->textwithpicto($langs->trans(
'DefaultWarehouse'), $langs->trans(
'SupplierOrderDefaultWarehouseHelp'));
2755 if ($action !=
'editwarehouse' && $usercancreate) {
2756 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>';
2758 print
'</tr></table>';
2760 if ($action ==
'editwarehouse') {
2761 print
'<form name="setwarehouse" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2762 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2763 print
'<input type="hidden" name="action" value="setwarehouse">';
2764 print $formproductcard->selectWarehouses(
$object->fk_warehouse,
'fk_warehouse',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth300');
2765 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2767 } elseif (
$object->fk_warehouse > 0) {
2768 $warehousestatic =
new Entrepot($db);
2769 if ($warehousestatic->fetch(
$object->fk_warehouse) > 0) {
2770 print $warehousestatic->getNomUrl(1);
2780 print
'<table class="nobordernopadding centpercent"><tr><td>';
2781 print $langs->trans(
'DateDeliveryPlanned');
2783 if ($action !=
'editdate_livraison') {
2784 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>';
2786 print
'</tr></table>';
2788 if ($action ==
'editdate_livraison') {
2789 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2790 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2791 print
'<input type="hidden" name="action" value="setdate_livraison">';
2796 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', $usehourmin, $usehourmin, 0,
"setdate_livraison");
2797 print
'<input type="submit" class="button button-edit smallpaddingimp valign middle" value="'.$langs->trans(
'Modify').
'">';
2800 $usehourmin =
'day';
2802 $usehourmin =
'dayhour';
2805 if (
$object->hasDelay() && !empty(
$object->delivery_date) && (
$object->status == $object::STATUS_ORDERSENT ||
$object->status == $object::STATUS_RECEIVED_PARTIALLY)) {
2806 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2814 print
'<table class="nobordernopadding centpercent"><tr><td>';
2815 print $langs->trans(
'IncotermLabel');
2816 print
'<td><td class="right">';
2817 if ($usercancreate) {
2818 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=editincoterm&token='.
newToken().
'">'.img_edit().
'</a>';
2822 print
'</td></tr></table>';
2825 if ($action !=
'editincoterm') {
2828 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2836 print
'<table class="nobordernopadding centpercent"><tr><td>';
2837 print $langs->trans(
"Categories");
2838 print
'<td><td class="right">';
2839 if ($usercancreate) {
2840 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/fourn/commande/card.php?id='.
$object->id.
'&action=edittags&token='.
newToken().
'">'.img_edit().
'</a>';
2844 print
'</td></tr></table>';
2847 if ($action ==
'edittags') {
2848 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
2849 print
'<input type="hidden" name="action" value="settags">';
2850 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2851 print $form->selectCategories(Categorie::TYPE_SUPPLIER_ORDER,
'categories', $object);
2852 print
'<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
2855 print $form->showCategories(
$object->id, Categorie::TYPE_SUPPLIER_ORDER, 1);
2861 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2866 print
'<div class="fichehalfright">';
2867 print
'<div class="underbanner clearboth"></div>';
2869 print
'<table class="border tableforfield centpercent">';
2871 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2875 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2876 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2879 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2885 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2886 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2889 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2894 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2896 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1",
$mysoc->country_code) .
'</td>';
2897 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2899 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2903 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2905 print
'<td>' . $langs->transcountry(
"AmountLT2",
$mysoc->country_code) .
'</td>';
2906 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2908 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2916 $alert =
' ' . img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->supplier_order_min_amount));
2921 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2922 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency) . $alert .
'</td>';
2925 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ttc, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2940 print
'<div class="clearboth"></div><br>';
2943 $blocname =
'contacts';
2944 $title = $langs->trans(
'ContactsAddresses');
2945 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2949 $blocname =
'notes';
2950 $title = $langs->trans(
'Notes');
2951 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2960 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2961 <input type="hidden" name="token" value="'.
newToken().
'">
2962 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2963 <input type="hidden" name="mode" value="">
2964 <input type="hidden" name="page_y" value="">
2965 <input type="hidden" name="id" value="'.
$object->id.
'">
2966 <input type="hidden" name="socid" value="'.$societe->id.
'">
2971 include DOL_DOCUMENT_ROOT .
'/core/tpl/subtotal_ajaxrow.tpl.php';
2973 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
2977 print
'<div class="div-table-responsive-no-min">';
2978 print
'<table id="tablelines" class="noborder noshadow centpercent">';
2981 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2984 $inputalsopricewithtax = 1;
2985 $senderissupplier = 2;
2987 $senderissupplier =
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY');
2999 if ($action !=
'editline') {
3002 $parameters = array();
3003 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
3005 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
3007 if (empty($reshook)) {
3023 if ($user->socid == 0 && $action !=
'delete') {
3024 if ($action !=
'createorder' && $action !=
'presend' && $action !=
'editline') {
3025 print
'<div class="tabsAction">';
3027 $parameters = array();
3028 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
3030 if (empty($reshook)) {
3036 $langs->load(
'subtotals');
3038 $url_button = array();
3040 $url_button[] = array(
3041 'lang' =>
'subtotals',
3043 'perm' => (
bool) $usercancreate,
3044 'label' => $langs->trans(
'AddTitleLine'),
3045 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_title_line'],
true)
3048 $url_button[] = array(
3049 'lang' =>
'subtotals',
3051 'perm' => (
bool) $usercancreate,
3052 'label' => $langs->trans(
'AddSubtotalLine'),
3053 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_subtotal_line'],
true)
3056 $url_button[] = array(
3057 'lang' =>
'subtotals',
3059 'perm' => (
bool) $usercancreate,
3060 'label' => $langs->trans(
'AddTextLine'),
3061 'url' =>
dolBuildUrl($_SERVER[
'PHP_SELF'], [
'id' =>
$object->id,
'action' =>
'add_text_line'],
true)
3064 print dolGetButtonAction(
'', $langs->trans(
'SubTotal'),
'default', $url_button,
'',
true);
3069 if ($usercanvalidate) {
3070 $tmpbuttonlabel = $langs->trans(
'Validate');
3072 $tmpbuttonlabel = $langs->trans(
"ValidateAndApprove");
3075 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken().
'">';
3076 print $tmpbuttonlabel;
3080 $langs->load(
"errors");
3081 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);
3092 if ($usercanorder) {
3093 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
3099 if ($usercanapprove) {
3101 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"FirstApprovalAlreadyDone")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3103 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve&token='.
newToken().
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3106 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"ApproveOrder").
'</a>';
3113 if ($usercanapprovesecond) {
3114 if (!empty(
$object->user_approve_id2)) {
3115 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"SecondApprovalAlreadyDone")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
3117 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=approve2&token='.
newToken().
'">'.$langs->trans(
"Approve2Order").
'</a>';
3120 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"Approve2Order").
'</a>';
3127 if ($usercanapprove || $usercanapprovesecond) {
3128 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=refuse&token='.
newToken().
'">'.$langs->trans(
"RefuseOrder").
'</a>';
3130 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
"RefuseOrder").
'</a>';
3135 if (empty($user->socid)) {
3137 if ($usercanorder) {
3138 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
3146 if (!$buttonshown && $usercanapprove) {
3149 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
3153 if (!$buttonshown && $usercanapprovesecond &&
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED')) {
3156 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"Disapprove").
'</a>';
3160 if (in_array(
$object->status, array(3, 4, 5, 6, 7, 9))) {
3161 if ($usercanorder) {
3162 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>';
3169 $labelofbutton = $langs->trans(
'ReceiveProducts');
3171 $labelofbutton = $langs->trans(
"CreateReception");
3172 if (!empty(
$object->linkedObjects[
'reception'])) {
3173 foreach (
$object->linkedObjects[
'reception'] as $element) {
3174 if ($element->statut >= 0) {
3187 $dispachedLines =
$object->getDispachedLines(1);
3188 $nbDispachedLines = count($dispachedLines);
3189 if ($nbDispachedLines > 0) {
3194 if (in_array(
$object->status, array(3, 4, 5))) {
3195 if (
isModEnabled(
"supplier_order") && $usercanreceive) {
3196 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/fourn/commande/dispatch.php?id='.
$object->id.
'">'.$labelofbutton.
'</a></div>';
3198 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$labelofbutton.
'</a></div>';
3204 if ($usercanorder) {
3205 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=createorder&token='.
newToken().
'#makeorder">'.$langs->trans(
"MakeOrder").
'</a></div>';
3207 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans(
"MakeOrder").
'</a></div>';
3213 if ($usercanreceive) {
3214 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>';
3221 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3222 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>';
3230 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3232 if (!empty(
$object->linkedObjectsIds[
'invoice_supplier']) || (empty(
$object->linkedObjectsIds[
'invoice_supplier']) && !
getDolGlobalInt(
'SUPPLIER_ORDER_DISABLE_CLASSIFY_BILLED_FROM_SUPPLIER_ORDER'))) {
3233 if ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"creer")) {
3234 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifybilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3237 print
'<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans(
"NeedAtLeastOneInvoice")).
'">'.$langs->trans(
"ClassifyBilled").
'</a>';
3243 if ($usercancreate &&
$object->billed > 0 &&
$object->status > $object::STATUS_DRAFT) {
3244 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=classifyunbilled&token='.
newToken().
'">'.$langs->trans(
"ClassifyUnbilled").
'</a>';
3248 if ($usercancreate) {
3249 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')));
3254 if ($usercanorder) {
3255 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3260 if (!empty($usercandelete)) {
3261 if ($hasreception) {
3262 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"ReceptionExist").
'">'.$langs->trans(
"Delete").
'</a>';
3264 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";
3274 print
'<!-- form to record supplier order -->'.
"\n";
3275 print
'<form name="commande" id="makeorder" action="card.php?id='.$object->id.
'&action=commande" method="POST">';
3277 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3278 print
'<input type="hidden" name="action" value="commande">';
3280 print
'<table class="noborder centpercent">';
3282 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderDate").
'</td><td>';
3284 print $form->selectDate($date_com ?:
'',
'', 0, 0, 0,
"commande", 1, 1);
3288 print
'<tr><td class="fieldrequired">'.$langs->trans(
"OrderMode").
'</td><td>';
3289 $formorder->selectInputMethod(
GETPOST(
'methodecommande'),
"methodecommande", 1);
3292 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment" value="'.
GETPOST(
'comment').
'"></td></tr>';
3294 print
'<tr><td class="center" colspan="2">';
3295 print
'<input type="submit" name="makeorder" class="button" value="'.$langs->trans(
"ToOrder").
'">';
3296 print
' ';
3297 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
3306 if (
GETPOST(
'modelselected')) {
3307 $action =
'presend';
3310 if ($action !=
'createorder' && $action !=
'presend') {
3311 print
'<div class="fichecenter"><div class="fichehalfleft">';
3316 $relativepath = $objref.
'/'.$objref.
'.pdf';
3318 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3319 $genallowed = $usercanread;
3320 $delallowed = $usercancreate;
3323 print $formfile->showdocuments(
'commande_fournisseur', $objref, $filedir, $urlsource, (
int) $genallowed, (int) $delallowed, $modelpdf, 1, 0, 0, 0, 0,
'',
'',
'',
$object->thirdparty->default_lang,
'', $object);
3324 $somethingshown = $formfile->numoffiles;
3327 $tmparray = $form->showLinkToObjectBlock($object, array(), array(
'supplier_order',
'order_supplier'), 1);
3328 $linktoelem = $tmparray[
'linktoelem'];
3329 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
3330 print $htmltoenteralink;
3332 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3334 print
'</div><div class="fichehalfright">';
3336 if ($action ==
'classifyreception') {
3339 print
'<!-- form to record purchase order received -->'.
"\n";
3340 print
'<form id="classifyreception" action="card.php?id='.$object->id.
'" method="post">';
3341 print
'<input type="hidden" name="token" value="'.newToken().
'">';
3342 print
'<input type="hidden" name="action" value="livraison">';
3345 print
'<table class="noborder centpercent">';
3347 print
'<tr><td>'.$langs->trans(
"DeliveryDate").
'</td><td>';
3349 print $form->selectDate($datepreselected,
'', 1, 1, 0,
"commande", 1, 1);
3350 print
"</td></tr>\n";
3352 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Delivery").
"</td><td>\n";
3354 $liv[
''] =
' ';
3355 $liv[
'tot'] = $langs->trans(
"CompleteOrNoMoreReceptionExpected");
3356 $liv[
'par'] = $langs->trans(
"PartialWoman");
3357 $liv[
'nev'] = $langs->trans(
"NeverReceived");
3358 $liv[
'can'] = $langs->trans(
"Canceled");
3360 print $form->selectarray(
"type", $liv);
3363 print
'<tr><td>'.$langs->trans(
"Comment").
'</td><td><input class="quatrevingtpercent" type="text" name="comment"></td></tr>';
3364 print
'<tr><td class="center" colspan="2">';
3365 print
'<input type="submit" name="receive" class="button" value="'.$langs->trans(
"Receive").
'">';
3366 print
' ';
3367 print
'<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans(
"Cancel").
'">';
3376 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3378 $somethingshown = $formactions->showactions($object,
'order_supplier', $socid, 1,
'listaction'.($genallowed ?
'largetitle' :
''));
3380 print
'</div></div>';
3384 $modelmail =
'order_supplier_send';
3385 $defaulttopic =
'SendOrderRef';
3387 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
3388 $trackid =
'sord'.$object->id;
3390 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.
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)
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.