41require
'../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
51require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
54if (isModEnabled(
"propal")) {
55 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
58if (isModEnabled(
'project')) {
59 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
60 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63if (isModEnabled(
'variants')) {
64 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
78$langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
80if (isModEnabled(
'incoterm')) {
81 $langs->load(
'incoterm');
83if (isModEnabled(
'margin')) {
84 $langs->load(
'margins');
86if (isModEnabled(
'productbatch')) {
87 $langs->load(
'productbatch');
94$action =
GETPOST(
'action',
'aZ09');
95$cancel =
GETPOST(
'cancel',
'alpha');
96$confirm =
GETPOST(
'confirm',
'alpha');
97$backtopage =
GETPOST(
'backtopage',
'alpha');
102$origin =
GETPOST(
'origin',
'alpha');
112if (!empty($user->socid)) {
113 $socid = $user->socid;
118$price_base_type =
null;
119$lineClassName =
null;
120$remise_percent =
null;
122$availability_id =
null;
123$shipping_method_id =
null;
125$demand_reason_id =
null;
132$hookmanager->initHooks(array(
'ordercard',
'globalcard'));
140$extrafields->fetch_name_optionals_label(
$object->table_element);
143include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
146$usercanread = $user->hasRight(
"commande",
"lire");
147$usercancreate = $user->hasRight(
"commande",
"creer");
148$usercandelete = $user->hasRight(
"commande",
"supprimer");
151$usercanclose = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'close')));
152$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'validate')));
153$usercancancel = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'annuler')));
154$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'send'));
155$usercangeneretedoc = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'generetedoc'));
157$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
158$usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
160$permissionnote = $usercancreate;
161$permissiondellink = $usercancreate;
162$permissiontoadd = $usercancreate;
169$selectedLines = array();
176$parameters = array(
'socid' => $socid);
178$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
183if (empty($reshook)) {
184 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
186 if (empty($backtopage) || ($cancel && empty($id))) {
187 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
188 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
189 $backtopage = $backurlforlist;
191 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
196 $selectedLines =
GETPOST(
'toselect',
'array');
199 if (!empty($backtopageforcancel)) {
200 header(
"Location: ".$backtopageforcancel);
202 } elseif (!empty($backtopage)) {
203 header(
"Location: ".$backtopage);
209 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
211 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
213 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
216 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
218 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
224 $result = $objectutil->createFromClone($user, $socid);
226 $warningMsgLineList = array();
228 foreach (
$object->lines as $line) {
229 if (!is_object($line->product)) {
230 $line->fetch_product();
232 if (is_object($line->product) && $line->product->id > 0) {
233 if (empty($line->product->status)) {
234 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
238 if (!empty($warningMsgLineList)) {
242 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
250 } elseif ($action ==
'reopen' && $usercancreate) {
255 $result =
$object->setDraft($user, $idwarehouse);
260 $result =
$object->set_reopen($user);
268 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
270 $result =
$object->delete($user);
272 header(
'Location: list.php?restore_lastsearch_values=1');
277 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
279 $result =
$object->deleteLine($user, $lineid);
284 $outputlangs = $langs;
287 $newlang =
GETPOST(
'lang_id',
'aZ09');
290 $newlang =
$object->thirdparty->default_lang;
292 if (!empty($newlang)) {
294 $outputlangs->setDefaultLang($newlang);
298 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
301 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
306 } elseif ($action ==
'classin' && $usercancreate) {
309 } elseif ($action ==
'add' && $usercancreate) {
314 if ($datecommande ==
'') {
315 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
321 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
332 $object->date_commande = $datecommande;
345 $object->delivery_date = $date_delivery;
351 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
352 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
356 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
363 if (!empty($origin) && !empty($originid)) {
365 $element = $subelement = $origin;
367 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
368 $element = $regs [1];
369 $subelement = $regs [2];
373 if ($element ==
'order') {
374 $element = $subelement =
'commande';
376 if ($element ==
'propal') {
377 $element =
'comm/propal';
378 $subelement =
'propal';
380 if ($element ==
'contract') {
381 $element = $subelement =
'contrat';
385 $object->origin_id = $originid;
389 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
390 if (!empty($other_linked_objects)) {
391 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
395 $object_id =
$object->create($user);
397 if ($object_id > 0) {
400 $classname = ucfirst($subelement);
401 $srcobject =
new $classname($db);
402 '@phan-var-force Commande|Propal|Contrat $srcobject';
405 $result = $srcobject->fetch(
$object->origin_id);
407 $lines = $srcobject->lines;
408 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
409 $srcobject->fetch_lines();
410 $lines = $srcobject->lines;
414 $num = count($lines);
416 for ($i = 0; $i < $num; $i++) {
417 if (!in_array($lines[$i]->
id, $selectedLines)) {
421 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
422 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
423 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
427 $date_start = $lines[$i]->date_debut_prevue;
428 if ($lines[$i]->date_debut_reel) {
429 $date_start = $lines[$i]->date_debut_reel;
431 if ($lines[$i]->date_start) {
432 $date_start = $lines[$i]->date_start;
434 $date_end = $lines[$i]->date_fin_prevue;
435 if ($lines[$i]->date_fin_reel) {
436 $date_end = $lines[$i]->date_fin_reel;
438 if ($lines[$i]->date_end) {
439 $date_end = $lines[$i]->date_end;
443 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
448 if (method_exists($lines[$i],
'fetch_optionals')) {
449 $lines[$i]->fetch_optionals();
450 $array_options = $lines[$i]->array_options;
453 $tva_tx = $lines[$i]->tva_tx;
454 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
455 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
460 $lines[$i]->subprice,
463 $lines[$i]->localtax1_tx,
464 $lines[$i]->localtax2_tx,
465 $lines[$i]->fk_product,
466 $lines[$i]->remise_percent,
467 $lines[$i]->info_bits,
468 $lines[$i]->fk_remise_except,
475 $lines[$i]->special_code,
477 $lines[$i]->fk_fournprice,
492 if ($result > 0 && $lines[$i]->product_type == 9) {
493 $fk_parent_line = $result;
527 $parameters = array(
'objFrom' => $srcobject);
529 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
544 $object_id =
$object->create($user);
549 if ($object_id > 0) {
563 if ($object_id > 0 && !$error) {
565 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
573 } elseif ($action ==
'classifybilled' && $usercancreate) {
574 $ret =
$object->classifyBilled($user);
579 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
580 $ret =
$object->classifyUnBilled($user);
584 } elseif ($action ==
'setref_client' && $usercancreate) {
590 } elseif ($action ==
'setremise' && $usercancreate) {
595 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
603 } elseif ($action ==
'setdate' && $usercancreate) {
606 $result =
$object->set_date($user, $date);
610 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
614 $result =
$object->setDeliveryDate($user, $date_delivery);
618 } elseif ($action ==
'setmode' && $usercancreate) {
623 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
625 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
626 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
629 } elseif ($action ==
'setavailability' && $usercancreate) {
634 } elseif ($action ==
'setdemandreason' && $usercancreate) {
639 } elseif ($action ==
'setconditions' && $usercancreate) {
646 $outputlangs = $langs;
647 $newlang =
GETPOST(
'lang_id',
'alpha');
649 $newlang =
$object->thirdparty->default_lang;
651 if (!empty($newlang)) {
653 $outputlangs->setDefaultLang($newlang);
657 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
660 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
666 } elseif ($action ==
'setbankaccount' && $usercancreate) {
672 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
678 } elseif ($action ==
'setwarehouse' && $usercancreate) {
688 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
692 foreach (
$object->lines as $line) {
693 if ($line->product_type == 1) {
694 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $alldate_start, $alldate_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
697 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
699 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
700 $vat_rate = str_replace(
'*',
'', $vat_rate);
703 foreach (
$object->lines as $line) {
704 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
706 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
708 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
709 $remise_percent = str_replace(
'*',
'', $remise_percent);
710 foreach (
$object->lines as $line) {
711 $tvatx = $line->tva_tx;
712 if (!empty($line->vat_src_code)) {
713 $tvatx .=
' ('.$line->vat_src_code.
')';
715 $result =
$object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $tvatx, $line->localtax1_tx, $line->localtax2_tx,
'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
717 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && $usercancreate) {
718 $langs->load(
'errors');
723 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
726 $price_ht_devise =
'';
728 $price_ttc_devise =
'';
734 if (
GETPOST(
'price_ht') !==
'') {
737 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
740 if (
GETPOST(
'price_ttc') !==
'') {
743 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
747 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
748 if ($prod_entry_mode ==
'free') {
754 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
759 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
763 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
764 if (empty($remise_percent)) {
769 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
770 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
772 if (is_array($extralabelsline)) {
774 foreach ($extralabelsline as $key => $value) {
775 unset($_POST[
"options_".$key]);
779 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
780 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
783 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
784 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
787 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
788 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
792 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
796 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
799 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
800 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
804 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
805 if ($combinations =
GETPOST(
'combinations',
'array')) {
809 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
810 $idprod = $res->fk_product_child;
812 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
818 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
822 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
824 $price_min = $price_min_ttc = 0;
830 if (!empty($idprod) && $idprod > 0) {
832 $prod->fetch($idprod);
834 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
843 $pu_ht = $prod->price;
844 $pu_ttc = $prod->price_ttc;
845 $price_min = $prod->price_min;
846 $price_min_ttc = $prod->price_min_ttc;
847 $price_base_type = $prod->price_base_type;
851 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
855 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' =>
$object->thirdparty->id);
858 $pricebycustomerexist =
false;
859 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
861 if (count($prodcustprice->lines) > 0) {
862 $pricebycustomerexist =
true;
863 $pu_ht =
price($prodcustprice->lines[0]->price);
864 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
865 $price_min =
price($prodcustprice->lines[0]->price_min);
866 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
867 $price_base_type = $prodcustprice->lines[0]->price_base_type;
868 $tva_tx = $prodcustprice->lines[0]->tva_tx;
869 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', (
string) $tva_tx)) {
870 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
872 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
873 if (empty($tva_tx)) {
881 if (!$pricebycustomerexist && !empty(
$object->thirdparty->price_level)) {
882 $pu_ht = $prod->multiprices[
$object->thirdparty->price_level];
883 $pu_ttc = $prod->multiprices_ttc[
$object->thirdparty->price_level];
884 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
885 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
886 $price_base_type = $prod->multiprices_base_type[
$object->thirdparty->price_level];
888 if (isset($prod->multiprices_tva_tx[
$object->thirdparty->price_level])) {
889 $tva_tx = $prod->multiprices_tva_tx[
$object->thirdparty->price_level];
891 if (isset($prod->multiprices_recuperableonly[
$object->thirdparty->price_level])) {
892 $tva_npr = $prod->multiprices_recuperableonly[
$object->thirdparty->price_level];
899 $pu_ht = $prod->multiprices[
$object->thirdparty->price_level];
900 $pu_ttc = $prod->multiprices_ttc[
$object->thirdparty->price_level];
901 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
902 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
903 $price_base_type = $prod->multiprices_base_type[
$object->thirdparty->price_level];
905 if (isset($prod->multiprices_tva_tx[
$object->thirdparty->price_level])) {
906 $tva_tx = $prod->multiprices_tva_tx[
$object->thirdparty->price_level];
908 if (isset($prod->multiprices_recuperableonly[
$object->thirdparty->price_level])) {
909 $tva_npr = $prod->multiprices_recuperableonly[
$object->thirdparty->price_level];
914 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
918 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' =>
$object->thirdparty->id);
920 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
922 if (count($prodcustprice->lines) > 0) {
923 $pu_ht =
price($prodcustprice->lines[0]->price);
924 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
925 $price_min =
price($prodcustprice->lines[0]->price_min);
926 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
927 $price_base_type = $prodcustprice->lines[0]->price_base_type;
928 $tva_tx = $prodcustprice->lines[0]->tva_tx;
929 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
930 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
932 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
933 if (empty($tva_tx)) {
942 if ($prod->prices_by_qty[0]) {
947 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
948 if ($priceforthequantityarray[
'rowid'] != $pqp) {
952 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
953 $pu_ht = $priceforthequantityarray[
'unitprice'];
955 $pu_ttc = $priceforthequantityarray[
'unitprice'];
963 if ($prod->prices_by_qty[
$object->thirdparty->price_level]) {
967 foreach ($prod->prices_by_qty_list[
$object->thirdparty->price_level] as $priceforthequantityarray) {
968 if ($priceforthequantityarray[
'rowid'] != $pqp) {
972 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
973 $pu_ht = $priceforthequantityarray[
'unitprice'];
975 $pu_ttc = $priceforthequantityarray[
'unitprice'];
983 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
984 $tmpprodvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
987 if (!empty($price_ht) || $price_ht ===
'0') {
988 $pu_ht = (float)
price2num($price_ht,
'MU');
989 $pu_ttc = (float)
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
990 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
991 $pu_ttc = (float)
price2num($price_ttc,
'MU');
992 $pu_ht = (float)
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
993 } elseif ($tmpvat != $tmpprodvat) {
995 if ($price_base_type !=
'HT') {
996 $pu_ht = (float)
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
998 $pu_ttc = (float)
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
1006 $outputlangs = $langs;
1008 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1009 $newlang =
GETPOST(
'lang_id',
'aZ09');
1011 if (empty($newlang)) {
1012 $newlang =
$object->thirdparty->default_lang;
1014 if (!empty($newlang)) {
1016 $outputlangs->setDefaultLang($newlang);
1019 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->
description;
1021 $desc = $prod->description;
1030 $desc = $product_desc;
1036 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
1040 $outputlangs = $langs;
1042 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1043 $newlang =
GETPOST(
'lang_id',
'alpha');
1045 if (empty($newlang)) {
1046 $newlang =
$object->thirdparty->default_lang;
1048 if (!empty($newlang)) {
1050 $outputlangs->setDefaultLang($newlang);
1051 $outputlangs->load(
'products');
1053 if (!empty($prod->customcode)) {
1054 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1056 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1059 if (!empty($prod->country_code)) {
1060 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
1063 if (!empty($prod->customcode)) {
1064 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1066 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1069 if (!empty($prod->country_code)) {
1070 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
1077 $type = $prod->type;
1078 $fk_unit = $prod->fk_unit;
1082 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1083 $tva_tx = str_replace(
'*',
'', $tva_tx);
1084 if (empty($tva_tx)) {
1087 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1088 $desc = $product_desc;
1090 $fk_unit =
GETPOST(
'units',
'alpha');
1091 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1092 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
1094 if ($pu_ttc && !$pu_ht) {
1095 $price_base_type =
'TTC';
1113 $pu_equivalent = $pu_ht;
1114 $pu_equivalent_ttc = $pu_ttc;
1116 $currency_tx =
$object->multicurrency_tx;
1120 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1121 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
1123 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1124 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
1141 if ($usermustrespectpricemin) {
1142 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
1143 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1146 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1147 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1155 $result =
$object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count(
$object->lines) + 1), 0,
GETPOST(
'fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit,
'', 0, $pu_ht_devise);
1163 $outputlangs = $langs;
1164 $newlang =
GETPOST(
'lang_id',
'alpha');
1166 $newlang =
$object->thirdparty->default_lang;
1168 if (!empty($newlang)) {
1170 $outputlangs->setDefaultLang($newlang);
1173 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1176 unset($_POST[
'prod_entry_mode']);
1178 unset($_POST[
'qty']);
1179 unset($_POST[
'type']);
1180 unset($_POST[
'remise_percent']);
1181 unset($_POST[
'price_ht']);
1182 unset($_POST[
'multicurrency_price_ht']);
1183 unset($_POST[
'price_ttc']);
1184 unset($_POST[
'tva_tx']);
1185 unset($_POST[
'product_ref']);
1186 unset($_POST[
'product_label']);
1187 unset($_POST[
'product_desc']);
1188 unset($_POST[
'fournprice']);
1189 unset($_POST[
'buying_price']);
1190 unset($_POST[
'np_marginRate']);
1191 unset($_POST[
'np_markRate']);
1192 unset($_POST[
'dp_desc']);
1193 unset($_POST[
'idprod']);
1194 unset($_POST[
'units']);
1196 unset($_POST[
'date_starthour']);
1197 unset($_POST[
'date_startmin']);
1198 unset($_POST[
'date_startsec']);
1199 unset($_POST[
'date_startday']);
1200 unset($_POST[
'date_startmonth']);
1201 unset($_POST[
'date_startyear']);
1202 unset($_POST[
'date_endhour']);
1203 unset($_POST[
'date_endmin']);
1204 unset($_POST[
'date_endsec']);
1205 unset($_POST[
'date_endday']);
1206 unset($_POST[
'date_endmonth']);
1207 unset($_POST[
'date_endyear']);
1213 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1225 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1230 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1231 $vat_rate = str_replace(
'*',
'', $vat_rate);
1243 $pu_equivalent = $pu_ht;
1244 $pu_equivalent_ttc = $pu_ttc;
1246 $currency_tx =
$object->multicurrency_tx;
1250 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1251 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
1253 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1254 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
1273 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1274 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1276 if (is_array($extralabelsline)) {
1277 foreach ($extralabelsline as $key => $value) {
1278 unset($_POST[
"options_".$key]);
1283 $special_code =
GETPOST(
'special_code');
1292 if (!empty($productid)) {
1294 $product->fetch($productid);
1296 $type = $product->type;
1298 $price_min = $product->price_min;
1300 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
1302 $price_min_ttc = $product->price_min_ttc;
1304 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
1310 if ($usermustrespectpricemin) {
1311 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
1312 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1315 $action =
'editline';
1316 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((
float)
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1317 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1320 $action =
'editline';
1325 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1329 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1331 $action =
'editline';
1336 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1338 $action =
'editline';
1343 if ($qty < $object->expeditions[
GETPOST(
'lineid',
'int')]) {
1344 setEventMessages($langs->trans(
'ErrorQtyOrderedLessQtyShipped'),
null,
'errors');
1346 $action =
'editline';
1351 if (!$user->hasRight(
'margins',
'creer')) {
1352 foreach (
$object->lines as &$line) {
1354 $fournprice = $line->fk_fournprice;
1355 $buyingprice = $line->pa_ht;
1361 $price_base_type =
'HT';
1363 if (empty($pu) && !empty($pu_ttc)) {
1365 $price_base_type =
'TTC';
1368 $result =
$object->updateline(
GETPOSTINT(
'lineid'), $description, $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $price_base_type, $info_bits, $date_start, $date_end, $type,
GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options,
GETPOST(
'units'), $pu_ht_devise);
1373 $outputlangs = $langs;
1376 $newlang =
GETPOST(
'lang_id',
'aZ09');
1379 $newlang =
$object->thirdparty->default_lang;
1381 if (!empty($newlang)) {
1383 $outputlangs->setDefaultLang($newlang);
1387 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1390 unset($_POST[
'qty']);
1391 unset($_POST[
'type']);
1392 unset($_POST[
'productid']);
1393 unset($_POST[
'remise_percent']);
1394 unset($_POST[
'price_ht']);
1395 unset($_POST[
'multicurrency_price_ht']);
1396 unset($_POST[
'price_ttc']);
1397 unset($_POST[
'tva_tx']);
1398 unset($_POST[
'product_ref']);
1399 unset($_POST[
'product_label']);
1400 unset($_POST[
'product_desc']);
1401 unset($_POST[
'fournprice']);
1402 unset($_POST[
'buying_price']);
1404 unset($_POST[
'date_starthour']);
1405 unset($_POST[
'date_startmin']);
1406 unset($_POST[
'date_startsec']);
1407 unset($_POST[
'date_startday']);
1408 unset($_POST[
'date_startmonth']);
1409 unset($_POST[
'date_startyear']);
1410 unset($_POST[
'date_endhour']);
1411 unset($_POST[
'date_endmin']);
1412 unset($_POST[
'date_endsec']);
1413 unset($_POST[
'date_endday']);
1414 unset($_POST[
'date_endmonth']);
1415 unset($_POST[
'date_endyear']);
1420 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1421 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
1423 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1426 $qualified_for_stock_change = 0;
1428 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1430 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1434 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1435 if (!$idwarehouse || $idwarehouse == -1) {
1437 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1443 $locationTarget =
'';
1447 $result =
$object->valid($user, $idwarehouse);
1452 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
1455 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1456 && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')
1458 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1461 $forceFields = array();
1463 if (GETPOSTISSET(
'date_pointoftax')) {
1471 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1483 $outputlangs = $langs;
1486 $newlang =
GETPOST(
'lang_id',
'aZ09');
1489 $newlang =
$object->thirdparty->default_lang;
1491 if (!empty($newlang)) {
1493 $outputlangs->setDefaultLang($newlang);
1498 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1501 $deposit->fetch($deposit->id);
1502 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1506 if ($locationTarget) {
1507 header(
'Location: ' . $locationTarget);
1518 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1520 $idwarehouse =
GETPOST(
'idwarehouse');
1522 $qualified_for_stock_change = 0;
1524 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1526 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1530 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1531 if (!$idwarehouse || $idwarehouse == -1) {
1533 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1539 $result =
$object->setDraft($user, $idwarehouse);
1543 $outputlangs = $langs;
1546 $newlang =
GETPOST(
'lang_id',
'aZ09');
1549 $newlang =
$object->thirdparty->default_lang;
1551 if (!empty($newlang)) {
1553 $outputlangs->setDefaultLang($newlang);
1558 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1564 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1565 $result =
$object->cloture($user);
1569 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1572 $qualified_for_stock_change = 0;
1574 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1576 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1580 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1581 if (!$idwarehouse || $idwarehouse == -1) {
1583 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1589 $result =
$object->cancel($idwarehouse);
1597 if ($action ==
'update_extras' && $usercancreate) {
1599 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
1602 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
1609 $result =
$object->updateExtraField($attribute_name,
'ORDER_MODIFY');
1617 $action =
'edit_extras';
1622 if ($action ==
'import_lines_from_object'
1626 $fromElement =
GETPOST(
'fromelement');
1627 $fromElementid =
GETPOST(
'fromelementid');
1628 $importLines =
GETPOST(
'line_checkbox');
1630 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1631 if ($fromElement ==
'commande') {
1633 $lineClassName =
'OrderLine';
1634 } elseif ($fromElement ==
'propal') {
1635 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1636 $lineClassName =
'PropaleLigne';
1637 } elseif ($fromElement ==
'facture') {
1638 dol_include_once(
'/compta/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1639 $lineClassName =
'FactureLigne';
1641 $nextRang = count(
$object->lines) + 1;
1644 foreach ($importLines as $lineId) {
1645 $lineId = intval($lineId);
1646 $originLine =
new $lineClassName($db);
1647 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1648 $originLine->fetch_optionals();
1649 $desc = $originLine->desc;
1650 $pu_ht = $originLine->subprice;
1651 $qty = $originLine->qty;
1652 $txtva = $originLine->tva_tx;
1653 $txlocaltax1 = $originLine->localtax1_tx;
1654 $txlocaltax2 = $originLine->localtax2_tx;
1655 $fk_product = $originLine->fk_product;
1656 $remise_percent = $originLine->remise_percent;
1657 $date_start = $originLine->date_start;
1658 $date_end = $originLine->date_end;
1659 $fk_code_ventilation = 0;
1660 $info_bits = $originLine->info_bits;
1661 $fk_remise_except = $originLine->fk_remise_except;
1662 $price_base_type =
'HT';
1664 $type = $originLine->product_type;
1665 $rang = $nextRang++;
1666 $special_code = $originLine->special_code;
1667 $origin = $originLine->element;
1668 $origin_id = $originLine->id;
1669 $fk_parent_line = 0;
1670 $fk_fournprice = $originLine->fk_fournprice;
1671 $pa_ht = $originLine->pa_ht;
1672 $label = $originLine->label;
1673 $array_options = $originLine->array_options;
1674 $situation_percent = 100;
1676 $fk_unit = $originLine->fk_unit;
1677 $pu_ht_devise = $originLine->multicurrency_subprice;
1679 $res =
$object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $date_start, $date_end, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise);
1698 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1701 $upload_dir = !empty(
$conf->commande->multidir_output[
$object->entity]) ?
$conf->commande->multidir_output[
$object->entity] :
$conf->commande->dir_output;
1702 $permissiontoadd = $usercancreate;
1703 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1706 $triggersendname =
'ORDER_SENTBYMAIL';
1708 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1709 $trackid =
'ord'.$object->id;
1710 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1714 if ($action ==
'addcontact' && $usercancreate) {
1718 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1722 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1725 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1726 $langs->load(
"errors");
1727 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1732 } elseif ($action ==
'swapstatut' && $usercancreate) {
1739 } elseif ($action ==
'deletecontact' && $usercancreate) {
1741 $result =
$object->delete_contact($lineid);
1744 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1758$title =
$object->ref.
" - ".$langs->trans(
'Card');
1759if ($action ==
'create') {
1760 $title = $langs->trans(
"NewOrder");
1762$help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1764llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-order page-card');
1766$form =
new Form($db);
1770if (isModEnabled(
'project')) {
1775if ($action ==
'create' && $usercancreate) {
1780 $res = $soc->fetch($socid);
1785 $currency_code =
$conf->currency;
1787 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1788 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
1789 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1792 if (!empty($origin) && !empty($originid)) {
1794 $element = $subelement = $origin;
1796 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1797 $element = $regs[1];
1798 $subelement = $regs[2];
1801 if ($element ==
'project') {
1802 $projectid = $originid;
1804 if (!$cond_reglement_id) {
1805 $cond_reglement_id = $soc->cond_reglement_id;
1807 if (!$deposit_percent) {
1808 $deposit_percent = $soc->deposit_percent;
1810 if (!$mode_reglement_id) {
1811 $mode_reglement_id = $soc->mode_reglement_id;
1813 if (!$remise_percent) {
1814 $remise_percent = $soc->remise_percent;
1822 if ($element ==
'order' || $element ==
'commande') {
1823 $element = $subelement =
'commande';
1824 } elseif ($element ==
'propal') {
1825 $element =
'comm/propal';
1826 $subelement =
'propal';
1827 } elseif ($element ==
'contract') {
1828 $element = $subelement =
'contrat';
1833 $classname = ucfirst($subelement);
1834 $objectsrc =
new $classname($db);
1835 '@phan-var-force Commande|Propal|Contrat $objectsrc';
1836 $objectsrc->fetch($originid);
1837 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1838 $objectsrc->fetch_lines();
1840 $objectsrc->fetch_thirdparty();
1843 $objectsrc->fetch_optionals();
1844 $object->array_options = $objectsrc->array_options;
1846 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1847 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1849 $soc = $objectsrc->thirdparty;
1850 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1851 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1852 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1853 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1854 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1855 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1856 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1857 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1862 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1864 if (isModEnabled(
"multicurrency")) {
1865 if (!empty($objectsrc->multicurrency_code)) {
1866 $currency_code = $objectsrc->multicurrency_code;
1868 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1869 $currency_tx = $objectsrc->multicurrency_tx;
1873 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1874 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1877 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1880 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1881 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1882 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1883 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1884 $availability_id = 0;
1885 $shipping_method_id = $soc->shipping_method_id;
1886 $warehouse_id = $soc->fk_warehouse;
1887 $demand_reason_id = $soc->demand_reason_id;
1892 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1893 $currency_code = $soc->multicurrency_code;
1896 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1897 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1901 if (!
GETPOST(
'changecompany')) {
1902 if (GETPOSTISSET(
'cond_reglement_id')) {
1903 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1905 if (GETPOSTISSET(
'deposit_percent')) {
1908 if (GETPOSTISSET(
'mode_reglement_id')) {
1909 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1911 if (GETPOSTISSET(
'cond_reglement_id')) {
1917 if ($soc->fk_warehouse > 0) {
1918 $warehouse_id = $soc->fk_warehouse;
1920 if (isModEnabled(
'stock') && empty($warehouse_id) &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1925 $warehouse_id = $user->fk_warehouse;
1929 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1930 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1931 print
'<input type="hidden" name="action" value="add">';
1932 print
'<input type="hidden" name="changecompany" value="0">';
1933 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1934 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1935 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1936 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1937 if (!empty($currency_tx)) {
1938 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1944 $parameters = array();
1946 $reshook = $hookmanager->executeHooks(
'tabContentCreateOrder', $parameters,
$object, $action);
1947 if (empty($reshook)) {
1948 print
'<table class="border centpercent">';
1951 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1954 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1955 if (
getDolGlobalString(
'MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1956 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1958 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1964 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1967 print $soc->getNomUrl(1,
'customer');
1968 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1971 print
'<td class="valuefieldcreate">';
1972 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
1973 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1977 $(document).ready(function() {
1978 $("#socid").change(function() {
1979 console.log("We have changed the company - Reload page");
1980 var socid = $(this).val();
1982 $("input[name=action]").val("create");
1983 $("input[name=changecompany]").val("1");
1984 $("form[name=crea_commande]").submit();
1989 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&customer=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1997 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1998 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
2000 print $form->select_contact($soc->id, $contactid,
'contactid', 1, empty($srccontactslist) ?
"" : $srccontactslist,
'', 1,
'maxwidth300 widthcentpercentminusx', true);
2004 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2006 $absolute_discount = $soc->getAvailableDiscounts();
2010 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
2011 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2017 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
2018 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2019 print $form->selectDate(
'',
're', 0, 0, 0,
"crea_commande", 1, 1);
2023 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
2024 print
'<td colspan="3">';
2025 $date_delivery = ($date_delivery ? $date_delivery :
$object->delivery_date);
2026 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2027 print $form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
2032 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
2033 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
2034 $form->selectAvailabilityDelay((GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id') : $availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2038 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2039 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2040 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
2044 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2045 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2046 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
2050 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2051 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2052 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2057 if (isModEnabled(
'shipping')) {
2058 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
2059 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
2060 $form->selectShippingMethod(((GETPOSTISSET(
'shipping_method_id') &&
GETPOSTINT(
'shipping_method_id') != 0) ?
GETPOST(
'shipping_method_id') : $shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
2065 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2066 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2068 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
2069 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses((GETPOSTISSET(
'warehouse_id') ?
GETPOST(
'warehouse_id') : $warehouse_id),
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
2074 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
2075 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
2076 $form->selectInputReason((GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id') : $demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2082 if (isModEnabled(
'project')) {
2083 $langs->load(
"projects");
2085 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
2086 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (GETPOSTISSET(
'projectid') ?
GETPOST(
'projectid') : $projectid),
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
2087 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.$soc->id).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
2093 if (isModEnabled(
'incoterm')) {
2095 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
2096 print
'<td class="maxwidthonsmartphone">';
2097 $incoterm_id =
GETPOST(
'incoterm_id');
2098 $location_incoterms =
GETPOST(
'location_incoterms');
2099 if (empty($incoterm_id)) {
2100 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
2101 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
2103 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2104 print $form->select_incoterms($incoterm_id, $location_incoterms);
2109 $parameters = array();
2110 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2111 $parameters[
'objectsrc'] = $objectsrc;
2113 $parameters[
'socid'] = $socid;
2116 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
2117 print $hookmanager->resPrint;
2118 if (empty($reshook)) {
2119 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2122 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2123 if ($soc->fetch_optionals() > 0) {
2124 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
2128 print
$object->showOptionals($extrafields,
'create', $parameters);
2132 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
2134 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2137 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
2138 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
2142 if (isModEnabled(
"multicurrency")) {
2144 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'',
$object, 0).
'</td>';
2145 print
'<td class="maxwidthonsmartphone">';
2146 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', 0,
'maxwidth200 widthcentpercentminusx');
2152 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
2155 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2156 print $doleditor->Create(1);
2161 if (empty($user->socid)) {
2163 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
2166 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2167 print $doleditor->Create(1);
2172 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2174 if ($origin ==
'contrat') {
2178 $objectsrc->update_price(1);
2181 print
"\n<!-- ".$classname.
" info -->";
2183 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2184 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2185 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2186 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2187 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2189 switch ($classname) {
2191 $newclassname =
'CommercialProposal';
2194 $newclassname =
'Order';
2197 $newclassname =
'Sending';
2200 $newclassname =
'Contract';
2203 $newclassname = $classname;
2206 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2209 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2210 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2211 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2212 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2215 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2216 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2219 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2221 if (isModEnabled(
"multicurrency")) {
2222 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2223 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2224 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2235 print $form->buttonsSaveCancel(
"CreateDraft");
2238 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2239 $title = $langs->trans(
'ProductsAndServices');
2242 print
'<div class="div-table-responsive-no-min">';
2243 print
'<table class="noborder centpercent">';
2245 $objectsrc->printOriginLinesList(
'', $selectedLines);
2257 $product_static =
new Product($db);
2262 $author =
new User($db);
2263 $author->fetch(
$object->user_author_id);
2266 $res =
$object->fetch_optionals();
2269 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2274 if ($action ==
'delete') {
2275 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2279 if ($action ==
'validate') {
2281 $ref = substr(
$object->ref, 1, 4);
2282 if ($ref ==
'PROV' || $ref ==
'') {
2283 $numref =
$object->getNextNumRef($soc);
2284 if (empty($numref)) {
2292 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2293 if (isModEnabled(
'notification')) {
2294 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2295 $notify =
new Notify($db);
2297 $text .= $notify->confirmMessage(
'ORDER_VALIDATE',
$object->socid,
$object);
2300 $qualified_for_stock_change = 0;
2302 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2304 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2307 $formquestion = array();
2308 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2309 $langs->load(
"stocks");
2310 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2313 if (
$conf->browser->name ==
'ie') {
2316 $formquestion = array(
2320 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockDecrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse') ?
GETPOSTINT(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2326 foreach (
$object->lines as $line) {
2327 $res = $line->fetch_product();
2329 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2335 if ($nbMandated > 0) {
2337 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
2340 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2344 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2349 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
2351 if (!empty($deposit_percent_from_payment_terms) && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')) {
2352 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2356 $eligibleForDepositGeneration =
true;
2358 if (array_key_exists(
'facture',
$object->linkedObjects)) {
2359 foreach (
$object->linkedObjects[
'facture'] as $invoice) {
2360 '@phan-var-force Facture $invoice';
2362 $eligibleForDepositGeneration =
false;
2368 if ($eligibleForDepositGeneration && array_key_exists(
'propal',
$object->linkedObjects)) {
2369 foreach (
$object->linkedObjects[
'propal'] as $proposal) {
2370 $proposal->fetchObjectLinked();
2372 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2373 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2374 '@phan-var-force Facture $invoice';
2376 $eligibleForDepositGeneration =
false;
2384 if ($eligibleForDepositGeneration) {
2385 $formquestion[] = array(
2386 'type' =>
'checkbox',
2388 'name' =>
'generate_deposit',
2389 'label' => $form->textwithpicto($langs->trans(
'GenerateDeposit',
$object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2392 $formquestion[] = array(
2394 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2396 'label' => $langs->trans(
'DateInvoice'),
2402 $formquestion[] = array(
2404 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2405 'name' =>
'date_pointoftax',
2406 'label' => $langs->trans(
'DatePointOfTax'),
2413 $paymentTermsSelect = $form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2415 $formquestion[] = array(
2417 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2418 'name' =>
'cond_reglement_id',
2419 'label' => $langs->trans(
'PaymentTerm'),
2420 'value' => $paymentTermsSelect
2423 $formquestion[] = array(
2424 'type' =>
'checkbox',
2425 'tdclass' =>
'showonlyifgeneratedeposit',
2426 'name' =>
'validate_generated_deposit',
2427 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2430 $formquestion[] = array(
2431 'type' =>
'onecolumn',
2434 $(document).ready(function() {
2435 $("[name=generate_deposit]").change(function () {
2436 let $self = $(this);
2437 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2439 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2456 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 240);
2461 if ($action ==
'modif') {
2462 $qualified_for_stock_change = 0;
2464 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2466 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2469 $text = $langs->trans(
'ConfirmUnvalidateOrder',
$object->ref);
2470 $formquestion = array();
2471 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2472 $langs->load(
"stocks");
2473 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2476 if (
$conf->browser->name ==
'ie') {
2479 $formquestion = array(
2483 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2487 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2493 if ($action ==
'shipped') {
2494 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2500 if ($action ==
'cancel') {
2501 $qualified_for_stock_change = 0;
2503 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2505 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2508 $text = $langs->trans(
'ConfirmCancelOrder',
$object->ref);
2509 $formquestion = array();
2510 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2511 $langs->load(
"stocks");
2512 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2515 if (
$conf->browser->name ==
'ie') {
2518 $formquestion = array(
2522 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2526 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2530 if ($action ==
'ask_deleteline') {
2531 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2535 if ($action ==
'clone') {
2536 $filter =
'(s.client:IN:1,2,3)';
2538 $formquestion = array(
2539 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter,
'', 0, 0, array(), 0,
'maxwidth300'))
2541 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2545 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2547 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
2548 if (empty($reshook)) {
2549 $formconfirm .= $hookmanager->resPrint;
2550 } elseif ($reshook > 0) {
2551 $formconfirm = $hookmanager->resPrint;
2560 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2562 $morehtmlref =
'<div class="refidno">';
2564 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_client,
$object, $usercancreate,
'string',
'', 0, 1);
2565 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client',
$object->ref_client,
$object, $usercancreate,
'string'.(isset(
$conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
2567 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2569 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2572 if (isModEnabled(
'project')) {
2573 $langs->load(
"projects");
2574 $morehtmlref .=
'<br>';
2575 if ($usercancreate) {
2576 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2577 if ($action !=
'classify') {
2578 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2580 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2582 if (!empty(
$object->fk_project)) {
2584 $proj->fetch(
$object->fk_project);
2585 $morehtmlref .= $proj->getNomUrl(1);
2587 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2592 $morehtmlref .=
'</div>';
2595 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2598 $parameters = array();
2600 $reshook = $hookmanager->executeHooks(
'tabContentViewOrder', $parameters,
$object, $action);
2601 if (empty($reshook)) {
2602 print
'<div class="fichecenter">';
2603 print
'<div class="fichehalfleft">';
2604 print
'<div class="underbanner clearboth"></div>';
2606 print
'<table class="border tableforfield centpercent">';
2608 if ($soc->outstanding_limit) {
2610 print
'<tr><td class="titlefield">';
2611 print $langs->trans(
'OutstandingBill');
2612 print
'</td><td class="valuefield">';
2613 $arrayoutstandingbills = $soc->getOutstandingBills();
2614 print
price($arrayoutstandingbills[
'opened']).
' / ';
2615 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1,
$conf->currency);
2622 $filterabsolutediscount =
"fk_facture_source IS NULL";
2623 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2625 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2626 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2629 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2630 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2631 $addcreditnote =
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?action=create&socid='.$soc->id.
'&type=2&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"AddCreditNote").
'</a>';
2633 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2635 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
2636 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
2637 $absolute_discount =
price2num($absolute_discount,
'MT');
2638 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2642 $backtopage = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
2643 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2650 print $form->editfieldkey(
"Date",
'date',
'',
$object, $editenable);
2651 print
'</td><td class="valuefield">';
2652 if ($action ==
'editdate') {
2653 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2654 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2655 print
'<input type="hidden" name="action" value="setdate">';
2656 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2657 print $form->selectDate(
$object->date,
'order_', 0, 0, 0,
"setdate");
2658 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2663 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2671 $editenable = $usercancreate;
2672 print $form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'',
$object, $editenable);
2673 print
'</td><td class="valuefield">';
2674 if ($action ==
'editdate_livraison') {
2675 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2676 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2677 print
'<input type="hidden" name="action" value="setdate_livraison">';
2678 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2679 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', 1, 1, 0,
"setdate_livraison", 1, 0);
2680 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2685 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2692 print
'<tr class="fielddeliverydelay"><td>';
2693 $editenable = $usercancreate;
2694 print $form->editfieldkey(
"AvailabilityPeriod",
'availability',
'',
$object, $editenable);
2695 print
'</td><td class="valuefield">';
2696 if ($action ==
'editavailability') {
2697 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'availability_id', 1);
2699 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'none', 1);
2704 if (isModEnabled(
'shipping')) {
2706 $editenable = $usercancreate;
2707 print $form->editfieldkey(
"SendingMethod",
'shippingmethod',
'',
$object, $editenable);
2708 print
'</td><td class="valuefield">';
2709 if ($action ==
'editshippingmethod') {
2710 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'shipping_method_id', 1);
2712 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'none');
2719 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2720 $langs->load(
'stocks');
2721 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2724 $editenable = $usercancreate;
2725 print $form->editfieldkey(
"Warehouse",
'warehouse',
'',
$object, $editenable);
2726 print
'</td><td class="valuefield">';
2727 if ($action ==
'editwarehouse') {
2728 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'warehouse_id', 1);
2730 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'none');
2738 $editenable = $usercancreate;
2739 print $form->editfieldkey(
"Source",
'demandreason',
'',
$object, $editenable);
2740 print
'</td><td class="valuefield">';
2741 if ($action ==
'editdemandreason') {
2742 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'demand_reason_id', 1);
2744 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'none');
2750 $editenable = $usercancreate;
2751 print $form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'',
$object, $editenable);
2752 print
'</td><td class="valuefield">';
2753 if ($action ==
'editconditions') {
2754 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2756 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2764 $editenable = $usercancreate;
2765 print $form->editfieldkey(
"PaymentMode",
'mode',
'',
$object, $editenable);
2766 print
'</td><td class="valuefield">';
2767 if ($action ==
'editmode') {
2768 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2770 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'none');
2788 $tmparray =
$object->getTotalWeightVolume();
2789 $totalWeight = $tmparray[
'weight'];
2790 $totalVolume = $tmparray[
'volume'];
2792 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2793 print
'<td class="valuefield">';
2798 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2799 print
'<td class="valuefield">';
2807 if (isModEnabled(
'incoterm')) {
2809 $editenable = $usercancreate;
2810 print $form->editfieldkey(
"IncotermLabel",
'incoterm',
'',
$object, $editenable);
2812 print
'<td class="valuefield">';
2813 if ($action !=
'editincoterm') {
2814 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
2816 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2822 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2824 $editenable = $usercancreate;
2825 print $form->editfieldkey(
"BankAccount",
'bankaccount',
'',
$object, $editenable);
2826 print
'</td><td class="valuefield">';
2827 if ($action ==
'editbankaccount') {
2828 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
2830 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
2837 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2842 print
'<div class="fichehalfright">';
2843 print
'<div class="underbanner clearboth"></div>';
2845 print
'<table class="border tableforfield centpercent">';
2847 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2851 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->order_min_amount));
2855 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2856 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2857 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2859 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2864 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2865 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2866 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2868 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2873 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2875 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2876 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2877 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2880 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2886 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2888 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2889 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2890 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2893 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2899 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2900 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency) .
'</td>';
2901 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2903 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->multicurrency_total_ttc, 1,
'', 1, -1, -1,
$object->multicurrency_code) .
'</td>';
2913 if (isModEnabled(
'margin')) {
2914 $formmargin->displayMarginInfos(
$object);
2921 print
'<div class="clearboth"></div><br>';
2924 $blocname =
'contacts';
2925 $title = $langs->trans(
'ContactsAddresses');
2926 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2930 $blocname =
'notes';
2931 $title = $langs->trans(
'Notes');
2932 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2940 $result =
$object->getLinesArray();
2944 global $inputalsopricewithtax;
2945 $inputalsopricewithtax = 1;
2947 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
2948 <input type="hidden" name="token" value="' .
newToken().
'">
2949 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2950 <input type="hidden" name="mode" value="">
2951 <input type="hidden" name="page_y" value="">
2952 <input type="hidden" name="id" value="' .
$object->id.
'">
2953 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2957 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2960 print
'<div class="div-table-responsive-no-min">';
2961 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2965 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2972 if ($action !=
'editline') {
2975 $parameters = array();
2977 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2981 if (empty($reshook)) {
2982 $object->formAddObjectLine(1, $mysoc, $soc);
2985 $parameters = array();
2986 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
3000 if ($action !=
'presend' && $action !=
'editline') {
3001 print
'<div class="tabsAction">';
3003 $parameters = array();
3005 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
3006 if (empty($reshook)) {
3007 $numlines = count(
$object->lines);
3015 if (empty($user->socid)) {
3018 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.
$object->id.
'&mode=init#formmailbeforetitle',
'');
3020 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3027 if ($numlines > 0) {
3030 $langs->load(
"errors");
3031 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.
$object->id,
$object->id, -1);
3039 $arrayforbutaction = array();
3043 $arrayforbutaction[] = array(
3046 'perm' => $usercancreatepurchaseorder,
3047 'label' =>
'AddPurchaseOrder',
3048 'url' =>
'/fourn/commande/card.php?action=create&origin=' . urlencode(
$object->element) .
'&originid=' . ((
int)
$object->id)
3059 $arrayforbutaction[] = array(
3060 'lang' =>
'interventions',
3062 'perm' => ($user->hasRight(
'ficheinter',
'creer') == 1),
3063 'label' =>
'AddIntervention',
3064 'url' =>
'/fichinter/card.php?action=create&origin=' . urlencode(
$object->element) .
'&originid=' . ((
int)
$object->id) .
'&socid=' . ((
int)
$object->socid),
3079 $arrayforbutaction[] = array(
3080 'lang' =>
'contracts',
3082 'perm' => ($user->hasRight(
'contrat',
'creer') == 1),
3083 'label' =>
'AddContract',
3084 'url' =>
'/contrat/card.php?action=create&origin=' .
$object->element .
'&originid=' .
$object->id .
'&socid=' .
$object->socid,
3097 if (isModEnabled(
'shipping')) {
3098 $numshipping =
$object->countNbOfShipments();
3101 if ((
getDolGlobalInt(
'MAIN_SUBMODULE_EXPEDITION') && $user->hasRight(
'expedition',
'creer')) || (
getDolGlobalInt(
'MAIN_SUBMODULE_DELIVERY') && $user->hasRight(
'expedition',
'delivery',
'creer'))) {
3103 $arrayforbutaction[] = array(
3104 'lang' =>
'sendings',
3106 'perm' => $user->hasRight(
'expedition',
'creer'),
3107 'label' =>
'CreateShipment',
3108 'url' =>
'/expedition/shipment.php?id=' .
$object->id
3113 $arrayforbutaction[] = array(
3114 'lang' =>
'sendings',
3117 'label' =>
'CreateShipment',
3118 'url' =>
'/expedition/shipment.php?id=' .
$object->id
3125 $arrayforbutaction[] = array(
3128 'perm' => ($user->hasRight(
'facture',
'creer') && !
getDolGlobalInt(
'WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3129 'label' =>
'CreateBill',
3130 'url' =>
'/compta/facture/card.php?action=create&token=' .
newToken() .
'&origin=' . urlencode(
$object->element) .
'&originid=' .
$object->id .
'&socid=' .
$object->socid
3139 $actionButtonsParameters = [
3140 "areDropdownButtons" => !
getDolGlobalInt(
"MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_ORDER")
3143 if ($numlines > 0) {
3144 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 1, $actionButtonsParameters);
3146 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 0, $actionButtonsParameters);
3151 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.
$object->id,
'');
3158 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.
$object->id,
'');
3163 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.
$object->id,
'');
3168 if ($usercancreate) {
3174 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3178 if ($usercandelete) {
3179 if ($numshipping == 0) {
3182 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3190 if (
GETPOST(
'modelselected')) {
3191 $action =
'presend';
3194 if ($action !=
'presend') {
3195 print
'<div class="fichecenter"><div class="fichehalfleft">';
3196 print
'<a name="builddoc"></a>';
3199 $relativepath = $objref.
'/'.$objref.
'.pdf';
3200 $filedir =
$conf->commande->multidir_output[
$object->entity].
'/'.$objref;
3201 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3202 $genallowed = $usercanread;
3203 $delallowed = $usercancreate;
3204 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed,
$object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'',
$object);
3208 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'order'), 1);
3209 $linktoelem = $tmparray[
'linktoelem'];
3210 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
3211 print $htmltoenteralink;
3213 $compatibleImportElementsList =
false;
3216 $compatibleImportElementsList = array(
'commande',
'propal',
'facture');
3218 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
3222 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3223 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
3224 $useonlinepayment = count($validpaymentmethod);
3227 $useonlinepayment = 0;
3230 print
'<br><!-- Link to pay -->';
3231 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3232 print showOnlinePaymentUrl(
'order',
$object->ref).
'<br>';
3235 print
'</div><div class="fichehalfright">';
3239 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/agenda.php?id='.
$object->id);
3242 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3244 $somethingshown = $formactions->showactions(
$object,
'order', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
3246 print
'</div></div>';
3250 $modelmail =
'order_send';
3251 $defaulttopic =
'SendOrderRef';
3253 $trackid =
'ord'.$object->id;
3255 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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 customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage a WYSIWYG editor.
static createDepositFromOrigin(CommonObject $origin, $date, $payment_terms_id, User $user, $notrigger=0, $autoValidateDeposit=false, $overrideFields=array())
Creates a deposit from a proposal or an order by grouping lines by VAT rates.
const TYPE_DEPOSIT
Deposit invoice.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
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.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) 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.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.