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;
1123 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1124 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
1126 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1127 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
1144 if ($usermustrespectpricemin) {
1145 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
1146 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1149 } 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') {
1150 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1158 $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);
1166 $outputlangs = $langs;
1167 $newlang =
GETPOST(
'lang_id',
'alpha');
1169 $newlang =
$object->thirdparty->default_lang;
1171 if (!empty($newlang)) {
1173 $outputlangs->setDefaultLang($newlang);
1176 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1179 unset($_POST[
'prod_entry_mode']);
1181 unset($_POST[
'qty']);
1182 unset($_POST[
'type']);
1183 unset($_POST[
'remise_percent']);
1184 unset($_POST[
'price_ht']);
1185 unset($_POST[
'multicurrency_price_ht']);
1186 unset($_POST[
'price_ttc']);
1187 unset($_POST[
'tva_tx']);
1188 unset($_POST[
'product_ref']);
1189 unset($_POST[
'product_label']);
1190 unset($_POST[
'product_desc']);
1191 unset($_POST[
'fournprice']);
1192 unset($_POST[
'buying_price']);
1193 unset($_POST[
'np_marginRate']);
1194 unset($_POST[
'np_markRate']);
1195 unset($_POST[
'dp_desc']);
1196 unset($_POST[
'idprod']);
1197 unset($_POST[
'units']);
1199 unset($_POST[
'date_starthour']);
1200 unset($_POST[
'date_startmin']);
1201 unset($_POST[
'date_startsec']);
1202 unset($_POST[
'date_startday']);
1203 unset($_POST[
'date_startmonth']);
1204 unset($_POST[
'date_startyear']);
1205 unset($_POST[
'date_endhour']);
1206 unset($_POST[
'date_endmin']);
1207 unset($_POST[
'date_endsec']);
1208 unset($_POST[
'date_endday']);
1209 unset($_POST[
'date_endmonth']);
1210 unset($_POST[
'date_endyear']);
1216 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1228 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1233 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1234 $vat_rate = str_replace(
'*',
'', $vat_rate);
1246 $pu_equivalent = $pu_ht;
1247 $pu_equivalent_ttc = $pu_ttc;
1249 $currency_tx =
$object->multicurrency_tx;
1256 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1257 $pu_equivalent = (float) $pu_ht_devise / (
float) $currency_tx;
1259 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1260 $pu_equivalent_ttc = (float) $pu_ttc_devise / (
float) $currency_tx;
1279 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1280 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1282 if (is_array($extralabelsline)) {
1283 foreach ($extralabelsline as $key => $value) {
1284 unset($_POST[
"options_".$key]);
1289 $special_code =
GETPOST(
'special_code');
1298 if (!empty($productid)) {
1300 $product->fetch($productid);
1302 $type = $product->type;
1304 $price_min = $product->price_min;
1306 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
1308 $price_min_ttc = $product->price_min_ttc;
1310 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
1316 if ($usermustrespectpricemin) {
1317 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
1318 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1321 $action =
'editline';
1322 } 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') {
1323 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
1326 $action =
'editline';
1331 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1335 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1337 $action =
'editline';
1342 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1344 $action =
'editline';
1349 if ($qty < $object->expeditions[
GETPOST(
'lineid',
'int')]) {
1350 setEventMessages($langs->trans(
'ErrorQtyOrderedLessQtyShipped'),
null,
'errors');
1352 $action =
'editline';
1357 if (!$user->hasRight(
'margins',
'creer')) {
1358 foreach (
$object->lines as &$line) {
1360 $fournprice = $line->fk_fournprice;
1361 $buyingprice = $line->pa_ht;
1367 $price_base_type =
'HT';
1369 if (empty($pu) && !empty($pu_ttc)) {
1371 $price_base_type =
'TTC';
1374 $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);
1379 $outputlangs = $langs;
1382 $newlang =
GETPOST(
'lang_id',
'aZ09');
1385 $newlang =
$object->thirdparty->default_lang;
1387 if (!empty($newlang)) {
1389 $outputlangs->setDefaultLang($newlang);
1393 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1396 unset($_POST[
'qty']);
1397 unset($_POST[
'type']);
1398 unset($_POST[
'productid']);
1399 unset($_POST[
'remise_percent']);
1400 unset($_POST[
'price_ht']);
1401 unset($_POST[
'multicurrency_price_ht']);
1402 unset($_POST[
'price_ttc']);
1403 unset($_POST[
'tva_tx']);
1404 unset($_POST[
'product_ref']);
1405 unset($_POST[
'product_label']);
1406 unset($_POST[
'product_desc']);
1407 unset($_POST[
'fournprice']);
1408 unset($_POST[
'buying_price']);
1410 unset($_POST[
'date_starthour']);
1411 unset($_POST[
'date_startmin']);
1412 unset($_POST[
'date_startsec']);
1413 unset($_POST[
'date_startday']);
1414 unset($_POST[
'date_startmonth']);
1415 unset($_POST[
'date_startyear']);
1416 unset($_POST[
'date_endhour']);
1417 unset($_POST[
'date_endmin']);
1418 unset($_POST[
'date_endsec']);
1419 unset($_POST[
'date_endday']);
1420 unset($_POST[
'date_endmonth']);
1421 unset($_POST[
'date_endyear']);
1426 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1427 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
1429 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1432 $qualified_for_stock_change = 0;
1434 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1436 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1440 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1441 if (!$idwarehouse || $idwarehouse == -1) {
1443 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1449 $locationTarget =
'';
1453 $result =
$object->valid($user, $idwarehouse);
1458 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
1461 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1462 && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')
1464 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1467 $forceFields = array();
1469 if (GETPOSTISSET(
'date_pointoftax')) {
1477 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1489 $outputlangs = $langs;
1492 $newlang =
GETPOST(
'lang_id',
'aZ09');
1495 $newlang =
$object->thirdparty->default_lang;
1497 if (!empty($newlang)) {
1499 $outputlangs->setDefaultLang($newlang);
1504 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1507 $deposit->fetch($deposit->id);
1508 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1512 if ($locationTarget) {
1513 header(
'Location: ' . $locationTarget);
1524 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1526 $idwarehouse =
GETPOST(
'idwarehouse');
1528 $qualified_for_stock_change = 0;
1530 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1532 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1536 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1537 if (!$idwarehouse || $idwarehouse == -1) {
1539 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1545 $result =
$object->setDraft($user, $idwarehouse);
1549 $outputlangs = $langs;
1552 $newlang =
GETPOST(
'lang_id',
'aZ09');
1555 $newlang =
$object->thirdparty->default_lang;
1557 if (!empty($newlang)) {
1559 $outputlangs->setDefaultLang($newlang);
1564 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1570 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1571 $result =
$object->cloture($user);
1575 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1578 $qualified_for_stock_change = 0;
1580 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1582 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1586 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1587 if (!$idwarehouse || $idwarehouse == -1) {
1589 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1595 $result =
$object->cancel($idwarehouse);
1603 if ($action ==
'update_extras' && $usercancreate) {
1605 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
1608 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
1615 $result =
$object->updateExtraField($attribute_name,
'ORDER_MODIFY');
1623 $action =
'edit_extras';
1628 if ($action ==
'import_lines_from_object'
1632 $fromElement =
GETPOST(
'fromelement');
1633 $fromElementid =
GETPOST(
'fromelementid');
1634 $importLines =
GETPOST(
'line_checkbox');
1636 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1637 if ($fromElement ==
'commande') {
1639 $lineClassName =
'OrderLine';
1640 } elseif ($fromElement ==
'propal') {
1641 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1642 $lineClassName =
'PropaleLigne';
1643 } elseif ($fromElement ==
'facture') {
1644 dol_include_once(
'/compta/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1645 $lineClassName =
'FactureLigne';
1647 $nextRang = count(
$object->lines) + 1;
1650 foreach ($importLines as $lineId) {
1651 $lineId = intval($lineId);
1652 $originLine =
new $lineClassName($db);
1653 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1654 $originLine->fetch_optionals();
1655 $desc = $originLine->desc;
1656 $pu_ht = $originLine->subprice;
1657 $qty = $originLine->qty;
1658 $txtva = $originLine->tva_tx;
1659 $txlocaltax1 = $originLine->localtax1_tx;
1660 $txlocaltax2 = $originLine->localtax2_tx;
1661 $fk_product = $originLine->fk_product;
1662 $remise_percent = $originLine->remise_percent;
1663 $date_start = $originLine->date_start;
1664 $date_end = $originLine->date_end;
1665 $fk_code_ventilation = 0;
1666 $info_bits = $originLine->info_bits;
1667 $fk_remise_except = $originLine->fk_remise_except;
1668 $price_base_type =
'HT';
1670 $type = $originLine->product_type;
1671 $rang = $nextRang++;
1672 $special_code = $originLine->special_code;
1673 $origin = $originLine->element;
1674 $origin_id = $originLine->id;
1675 $fk_parent_line = 0;
1676 $fk_fournprice = $originLine->fk_fournprice;
1677 $pa_ht = $originLine->pa_ht;
1678 $label = $originLine->label;
1679 $array_options = $originLine->array_options;
1680 $situation_percent = 100;
1682 $fk_unit = $originLine->fk_unit;
1683 $pu_ht_devise = $originLine->multicurrency_subprice;
1685 $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);
1704 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1707 $upload_dir = !empty(
$conf->commande->multidir_output[
$object->entity]) ?
$conf->commande->multidir_output[
$object->entity] :
$conf->commande->dir_output;
1708 $permissiontoadd = $usercancreate;
1709 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1712 $triggersendname =
'ORDER_SENTBYMAIL';
1714 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1715 $trackid =
'ord'.$object->id;
1716 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1720 if ($action ==
'addcontact' && $usercancreate) {
1724 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1728 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1731 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1732 $langs->load(
"errors");
1733 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1738 } elseif ($action ==
'swapstatut' && $usercancreate) {
1745 } elseif ($action ==
'deletecontact' && $usercancreate) {
1747 $result =
$object->delete_contact($lineid);
1750 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1764$title =
$object->ref.
" - ".$langs->trans(
'Card');
1765if ($action ==
'create') {
1766 $title = $langs->trans(
"NewOrder");
1768$help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1770llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-order page-card');
1772$form =
new Form($db);
1776if (isModEnabled(
'project')) {
1781if ($action ==
'create' && $usercancreate) {
1786 $res = $soc->fetch($socid);
1791 $currency_code =
$conf->currency;
1793 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1794 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
1795 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1798 if (!empty($origin) && !empty($originid)) {
1800 $element = $subelement = $origin;
1802 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1803 $element = $regs[1];
1804 $subelement = $regs[2];
1807 if ($element ==
'project') {
1808 $projectid = $originid;
1810 if (!$cond_reglement_id) {
1811 $cond_reglement_id = $soc->cond_reglement_id;
1813 if (!$deposit_percent) {
1814 $deposit_percent = $soc->deposit_percent;
1816 if (!$mode_reglement_id) {
1817 $mode_reglement_id = $soc->mode_reglement_id;
1819 if (!$remise_percent) {
1820 $remise_percent = $soc->remise_percent;
1828 if ($element ==
'order' || $element ==
'commande') {
1829 $element = $subelement =
'commande';
1830 } elseif ($element ==
'propal') {
1831 $element =
'comm/propal';
1832 $subelement =
'propal';
1833 } elseif ($element ==
'contract') {
1834 $element = $subelement =
'contrat';
1839 $classname = ucfirst($subelement);
1840 $objectsrc =
new $classname($db);
1841 '@phan-var-force Commande|Propal|Contrat $objectsrc';
1842 $objectsrc->fetch($originid);
1843 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1844 $objectsrc->fetch_lines();
1846 $objectsrc->fetch_thirdparty();
1849 $objectsrc->fetch_optionals();
1850 $object->array_options = $objectsrc->array_options;
1852 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1853 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1855 $soc = $objectsrc->thirdparty;
1856 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1857 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1858 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1859 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1860 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1861 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1862 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1863 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1868 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1870 if (isModEnabled(
"multicurrency")) {
1871 if (!empty($objectsrc->multicurrency_code)) {
1872 $currency_code = $objectsrc->multicurrency_code;
1874 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1875 $currency_tx = $objectsrc->multicurrency_tx;
1879 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1880 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1883 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1886 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1887 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1888 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1889 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1890 $availability_id = 0;
1891 $shipping_method_id = $soc->shipping_method_id;
1892 $warehouse_id = $soc->fk_warehouse;
1893 $demand_reason_id = $soc->demand_reason_id;
1898 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1899 $currency_code = $soc->multicurrency_code;
1902 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1903 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1907 if (!
GETPOST(
'changecompany')) {
1908 if (GETPOSTISSET(
'cond_reglement_id')) {
1909 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1911 if (GETPOSTISSET(
'deposit_percent')) {
1914 if (GETPOSTISSET(
'mode_reglement_id')) {
1915 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1917 if (GETPOSTISSET(
'cond_reglement_id')) {
1923 if ($soc->fk_warehouse > 0) {
1924 $warehouse_id = $soc->fk_warehouse;
1926 if (isModEnabled(
'stock') && empty($warehouse_id) &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1931 $warehouse_id = $user->fk_warehouse;
1935 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1936 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1937 print
'<input type="hidden" name="action" value="add">';
1938 print
'<input type="hidden" name="changecompany" value="0">';
1939 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1940 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1941 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1942 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1943 if (!empty($currency_tx)) {
1944 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1950 $parameters = array();
1952 $reshook = $hookmanager->executeHooks(
'tabContentCreateOrder', $parameters,
$object, $action);
1953 if (empty($reshook)) {
1954 print
'<table class="border centpercent">';
1957 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1960 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1961 if (
getDolGlobalString(
'MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1962 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1964 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1970 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1973 print $soc->getNomUrl(1,
'customer');
1974 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1977 print
'<td class="valuefieldcreate">';
1978 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
1979 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1983 $(document).ready(function() {
1984 $("#socid").change(function() {
1985 console.log("We have changed the company - Reload page");
1986 var socid = $(this).val();
1988 $("input[name=action]").val("create");
1989 $("input[name=changecompany]").val("1");
1990 $("form[name=crea_commande]").submit();
1995 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>';
2003 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
2004 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
2006 print $form->select_contact($soc->id, $contactid,
'contactid', 1, empty($srccontactslist) ?
"" : $srccontactslist,
'', 1,
'maxwidth300 widthcentpercentminusx', true);
2010 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
2012 $absolute_discount = $soc->getAvailableDiscounts();
2016 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
2017 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2023 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
2024 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2025 print $form->selectDate(
'',
're', 0, 0, 0,
"crea_commande", 1, 1);
2029 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
2030 print
'<td colspan="3">';
2031 $date_delivery = ($date_delivery ? $date_delivery :
$object->delivery_date);
2032 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2033 print $form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
2038 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
2039 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
2040 $form->selectAvailabilityDelay((GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id') : $availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2044 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2045 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2046 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
2050 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2051 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2052 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
2056 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2057 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2058 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2063 if (isModEnabled(
'shipping')) {
2064 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
2065 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
2066 $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');
2071 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2072 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2074 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
2075 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');
2080 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
2081 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
2082 $form->selectInputReason((GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id') : $demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2088 if (isModEnabled(
'project')) {
2089 $langs->load(
"projects");
2091 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
2092 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');
2093 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>';
2099 if (isModEnabled(
'incoterm')) {
2101 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
2102 print
'<td class="maxwidthonsmartphone">';
2103 $incoterm_id =
GETPOST(
'incoterm_id');
2104 $location_incoterms =
GETPOST(
'location_incoterms');
2105 if (empty($incoterm_id)) {
2106 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
2107 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
2109 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2110 print $form->select_incoterms($incoterm_id, $location_incoterms);
2115 $parameters = array();
2116 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2117 $parameters[
'objectsrc'] = $objectsrc;
2119 $parameters[
'socid'] = $socid;
2122 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
2123 print $hookmanager->resPrint;
2124 if (empty($reshook)) {
2125 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2128 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2129 if ($soc->fetch_optionals() > 0) {
2130 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
2134 print
$object->showOptionals($extrafields,
'create', $parameters);
2138 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
2140 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2143 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
2144 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
2148 if (isModEnabled(
"multicurrency")) {
2150 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'',
$object, 0).
'</td>';
2151 print
'<td class="maxwidthonsmartphone">';
2152 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', 0,
'maxwidth200 widthcentpercentminusx');
2158 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
2161 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2162 print $doleditor->Create(1);
2167 if (empty($user->socid)) {
2169 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
2172 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2173 print $doleditor->Create(1);
2178 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2180 if ($origin ==
'contrat') {
2184 $objectsrc->update_price(1);
2187 print
"\n<!-- ".$classname.
" info -->";
2189 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2190 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2191 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2192 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2193 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2195 switch ($classname) {
2197 $newclassname =
'CommercialProposal';
2200 $newclassname =
'Order';
2203 $newclassname =
'Sending';
2206 $newclassname =
'Contract';
2209 $newclassname = $classname;
2212 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2215 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2216 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2217 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2218 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2221 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2222 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2225 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2227 if (isModEnabled(
"multicurrency")) {
2228 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2229 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2230 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2241 print $form->buttonsSaveCancel(
"CreateDraft");
2244 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2245 $title = $langs->trans(
'ProductsAndServices');
2248 print
'<div class="div-table-responsive-no-min">';
2249 print
'<table class="noborder centpercent">';
2251 $objectsrc->printOriginLinesList(
'', $selectedLines);
2263 $product_static =
new Product($db);
2268 $author =
new User($db);
2269 $author->fetch(
$object->user_author_id);
2272 $res =
$object->fetch_optionals();
2275 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2280 if ($action ==
'delete') {
2281 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2285 if ($action ==
'validate') {
2287 $ref = substr(
$object->ref, 1, 4);
2288 if ($ref ==
'PROV' || $ref ==
'') {
2289 $numref =
$object->getNextNumRef($soc);
2290 if (empty($numref)) {
2298 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2299 if (isModEnabled(
'notification')) {
2300 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2301 $notify =
new Notify($db);
2303 $text .= $notify->confirmMessage(
'ORDER_VALIDATE',
$object->socid,
$object);
2306 $qualified_for_stock_change = 0;
2308 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2310 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2313 $formquestion = array();
2314 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2315 $langs->load(
"stocks");
2316 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2319 if (
$conf->browser->name ==
'ie') {
2322 $formquestion = array(
2326 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockDecrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse') ?
GETPOSTINT(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2332 foreach (
$object->lines as $line) {
2333 $res = $line->fetch_product();
2335 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2341 if ($nbMandated > 0) {
2343 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
2346 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2350 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2355 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
2357 if (!empty($deposit_percent_from_payment_terms) && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')) {
2358 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2362 $eligibleForDepositGeneration =
true;
2364 if (array_key_exists(
'facture',
$object->linkedObjects)) {
2365 foreach (
$object->linkedObjects[
'facture'] as $invoice) {
2366 '@phan-var-force Facture $invoice';
2368 $eligibleForDepositGeneration =
false;
2374 if ($eligibleForDepositGeneration && array_key_exists(
'propal',
$object->linkedObjects)) {
2375 foreach (
$object->linkedObjects[
'propal'] as $proposal) {
2376 $proposal->fetchObjectLinked();
2378 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2379 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2380 '@phan-var-force Facture $invoice';
2382 $eligibleForDepositGeneration =
false;
2390 if ($eligibleForDepositGeneration) {
2391 $formquestion[] = array(
2392 'type' =>
'checkbox',
2394 'name' =>
'generate_deposit',
2395 'label' => $form->textwithpicto($langs->trans(
'GenerateDeposit',
$object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2398 $formquestion[] = array(
2400 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2402 'label' => $langs->trans(
'DateInvoice'),
2408 $formquestion[] = array(
2410 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2411 'name' =>
'date_pointoftax',
2412 'label' => $langs->trans(
'DatePointOfTax'),
2419 $paymentTermsSelect = $form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2421 $formquestion[] = array(
2423 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2424 'name' =>
'cond_reglement_id',
2425 'label' => $langs->trans(
'PaymentTerm'),
2426 'value' => $paymentTermsSelect
2429 $formquestion[] = array(
2430 'type' =>
'checkbox',
2431 'tdclass' =>
'showonlyifgeneratedeposit',
2432 'name' =>
'validate_generated_deposit',
2433 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2436 $formquestion[] = array(
2437 'type' =>
'onecolumn',
2440 $(document).ready(function() {
2441 $("[name=generate_deposit]").change(function () {
2442 let $self = $(this);
2443 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2445 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2462 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 240);
2467 if ($action ==
'modif') {
2468 $qualified_for_stock_change = 0;
2470 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2472 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2475 $text = $langs->trans(
'ConfirmUnvalidateOrder',
$object->ref);
2476 $formquestion = array();
2477 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2478 $langs->load(
"stocks");
2479 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2482 if (
$conf->browser->name ==
'ie') {
2485 $formquestion = array(
2489 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2493 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2499 if ($action ==
'shipped') {
2500 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2506 if ($action ==
'cancel') {
2507 $qualified_for_stock_change = 0;
2509 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2511 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2514 $text = $langs->trans(
'ConfirmCancelOrder',
$object->ref);
2515 $formquestion = array();
2516 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2517 $langs->load(
"stocks");
2518 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2521 if (
$conf->browser->name ==
'ie') {
2524 $formquestion = array(
2528 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2532 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2536 if ($action ==
'ask_deleteline') {
2537 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2541 if ($action ==
'clone') {
2542 $filter =
'(s.client:IN:1,2,3)';
2544 $formquestion = array(
2545 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter,
'', 0, 0, array(), 0,
'maxwidth300'))
2547 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2551 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2553 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
2554 if (empty($reshook)) {
2555 $formconfirm .= $hookmanager->resPrint;
2556 } elseif ($reshook > 0) {
2557 $formconfirm = $hookmanager->resPrint;
2566 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2568 $morehtmlref =
'<div class="refidno">';
2570 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_client,
$object, $usercancreate,
'string',
'', 0, 1);
2571 $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);
2573 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2575 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2578 if (isModEnabled(
'project')) {
2579 $langs->load(
"projects");
2580 $morehtmlref .=
'<br>';
2581 if ($usercancreate) {
2582 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2583 if ($action !=
'classify') {
2584 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2586 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2588 if (!empty(
$object->fk_project)) {
2590 $proj->fetch(
$object->fk_project);
2591 $morehtmlref .= $proj->getNomUrl(1);
2593 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2598 $morehtmlref .=
'</div>';
2601 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2604 $parameters = array();
2606 $reshook = $hookmanager->executeHooks(
'tabContentViewOrder', $parameters,
$object, $action);
2607 if (empty($reshook)) {
2608 print
'<div class="fichecenter">';
2609 print
'<div class="fichehalfleft">';
2610 print
'<div class="underbanner clearboth"></div>';
2612 print
'<table class="border tableforfield centpercent">';
2614 if ($soc->outstanding_limit) {
2616 print
'<tr><td class="titlefield">';
2617 print $langs->trans(
'OutstandingBill');
2618 print
'</td><td class="valuefield">';
2619 $arrayoutstandingbills = $soc->getOutstandingBills();
2620 print
price($arrayoutstandingbills[
'opened']).
' / ';
2621 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1,
$conf->currency);
2628 $filterabsolutediscount =
"fk_facture_source IS NULL";
2629 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2631 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2632 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2635 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2636 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2637 $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>';
2639 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2641 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
2642 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
2643 $absolute_discount =
price2num($absolute_discount,
'MT');
2644 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2648 $backtopage = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
2649 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2656 print $form->editfieldkey(
"Date",
'date',
'',
$object, $editenable);
2657 print
'</td><td class="valuefield">';
2658 if ($action ==
'editdate') {
2659 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2660 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2661 print
'<input type="hidden" name="action" value="setdate">';
2662 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2663 print $form->selectDate(
$object->date,
'order_', 0, 0, 0,
"setdate");
2664 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2669 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2677 $editenable = $usercancreate;
2678 print $form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'',
$object, $editenable);
2679 print
'</td><td class="valuefield">';
2680 if ($action ==
'editdate_livraison') {
2681 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2682 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2683 print
'<input type="hidden" name="action" value="setdate_livraison">';
2684 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2685 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', 1, 1, 0,
"setdate_livraison", 1, 0);
2686 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2691 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2698 print
'<tr class="fielddeliverydelay"><td>';
2699 $editenable = $usercancreate;
2700 print $form->editfieldkey(
"AvailabilityPeriod",
'availability',
'',
$object, $editenable);
2701 print
'</td><td class="valuefield">';
2702 if ($action ==
'editavailability') {
2703 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'availability_id', 1);
2705 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'none', 1);
2710 if (isModEnabled(
'shipping')) {
2712 $editenable = $usercancreate;
2713 print $form->editfieldkey(
"SendingMethod",
'shippingmethod',
'',
$object, $editenable);
2714 print
'</td><td class="valuefield">';
2715 if ($action ==
'editshippingmethod') {
2716 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'shipping_method_id', 1);
2718 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'none');
2725 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2726 $langs->load(
'stocks');
2727 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2730 $editenable = $usercancreate;
2731 print $form->editfieldkey(
"Warehouse",
'warehouse',
'',
$object, $editenable);
2732 print
'</td><td class="valuefield">';
2733 if ($action ==
'editwarehouse') {
2734 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'warehouse_id', 1);
2736 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'none');
2744 $editenable = $usercancreate;
2745 print $form->editfieldkey(
"Source",
'demandreason',
'',
$object, $editenable);
2746 print
'</td><td class="valuefield">';
2747 if ($action ==
'editdemandreason') {
2748 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'demand_reason_id', 1);
2750 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'none');
2756 $editenable = $usercancreate;
2757 print $form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'',
$object, $editenable);
2758 print
'</td><td class="valuefield">';
2759 if ($action ==
'editconditions') {
2760 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2762 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2770 $editenable = $usercancreate;
2771 print $form->editfieldkey(
"PaymentMode",
'mode',
'',
$object, $editenable);
2772 print
'</td><td class="valuefield">';
2773 if ($action ==
'editmode') {
2774 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2776 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'none');
2794 $tmparray =
$object->getTotalWeightVolume();
2795 $totalWeight = $tmparray[
'weight'];
2796 $totalVolume = $tmparray[
'volume'];
2798 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2799 print
'<td class="valuefield">';
2804 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2805 print
'<td class="valuefield">';
2813 if (isModEnabled(
'incoterm')) {
2815 $editenable = $usercancreate;
2816 print $form->editfieldkey(
"IncotermLabel",
'incoterm',
'',
$object, $editenable);
2818 print
'<td class="valuefield">';
2819 if ($action !=
'editincoterm') {
2820 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
2822 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2828 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2830 $editenable = $usercancreate;
2831 print $form->editfieldkey(
"BankAccount",
'bankaccount',
'',
$object, $editenable);
2832 print
'</td><td class="valuefield">';
2833 if ($action ==
'editbankaccount') {
2834 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
2836 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
2843 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2848 print
'<div class="fichehalfright">';
2849 print
'<div class="underbanner clearboth"></div>';
2851 print
'<table class="border tableforfield centpercent">';
2853 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2857 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->order_min_amount));
2861 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2862 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2863 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2865 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2870 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2871 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2872 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2874 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2879 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2881 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2882 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2883 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2886 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2892 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2894 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2895 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1,
$conf->currency) .
'</td>';
2896 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2899 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2905 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2906 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency) .
'</td>';
2907 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code !=
$conf->currency)) {
2909 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->multicurrency_total_ttc, 1,
'', 1, -1, -1,
$object->multicurrency_code) .
'</td>';
2919 if (isModEnabled(
'margin')) {
2920 $formmargin->displayMarginInfos(
$object);
2927 print
'<div class="clearboth"></div><br>';
2930 $blocname =
'contacts';
2931 $title = $langs->trans(
'ContactsAddresses');
2932 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2936 $blocname =
'notes';
2937 $title = $langs->trans(
'Notes');
2938 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2946 $result =
$object->getLinesArray();
2950 global $inputalsopricewithtax;
2951 $inputalsopricewithtax = 1;
2953 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
2954 <input type="hidden" name="token" value="' .
newToken().
'">
2955 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2956 <input type="hidden" name="mode" value="">
2957 <input type="hidden" name="page_y" value="">
2958 <input type="hidden" name="id" value="' .
$object->id.
'">
2959 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2963 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2966 print
'<div class="div-table-responsive-no-min">';
2967 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2971 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2978 if ($action !=
'editline') {
2981 $parameters = array();
2983 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2987 if (empty($reshook)) {
2988 $object->formAddObjectLine(1, $mysoc, $soc);
2991 $parameters = array();
2992 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
3006 if ($action !=
'presend' && $action !=
'editline') {
3007 print
'<div class="tabsAction">';
3009 $parameters = array();
3011 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
3012 if (empty($reshook)) {
3013 $numlines = count(
$object->lines);
3021 if (empty($user->socid)) {
3024 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.
$object->id.
'&mode=init#formmailbeforetitle',
'');
3026 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3033 if ($numlines > 0) {
3036 $langs->load(
"errors");
3037 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.
$object->id,
$object->id, -1);
3045 $arrayforbutaction = array();
3049 $arrayforbutaction[] = array(
3052 'perm' => $usercancreatepurchaseorder,
3053 'label' =>
'AddPurchaseOrder',
3054 'url' =>
'/fourn/commande/card.php?action=create&origin=' . urlencode(
$object->element) .
'&originid=' . ((
int)
$object->id)
3065 $arrayforbutaction[] = array(
3066 'lang' =>
'interventions',
3068 'perm' => ($user->hasRight(
'ficheinter',
'creer') == 1),
3069 'label' =>
'AddIntervention',
3070 'url' =>
'/fichinter/card.php?action=create&origin=' . urlencode(
$object->element) .
'&originid=' . ((
int)
$object->id) .
'&socid=' . ((
int)
$object->socid),
3085 $arrayforbutaction[] = array(
3086 'lang' =>
'contracts',
3088 'perm' => ($user->hasRight(
'contrat',
'creer') == 1),
3089 'label' =>
'AddContract',
3090 'url' =>
'/contrat/card.php?action=create&origin=' .
$object->element .
'&originid=' .
$object->id .
'&socid=' .
$object->socid,
3103 if (isModEnabled(
'shipping')) {
3104 $numshipping =
$object->countNbOfShipments();
3107 if ((
getDolGlobalInt(
'MAIN_SUBMODULE_EXPEDITION') && $user->hasRight(
'expedition',
'creer')) || (
getDolGlobalInt(
'MAIN_SUBMODULE_DELIVERY') && $user->hasRight(
'expedition',
'delivery',
'creer'))) {
3109 $arrayforbutaction[] = array(
3110 'lang' =>
'sendings',
3112 'perm' => $user->hasRight(
'expedition',
'creer'),
3113 'label' =>
'CreateShipment',
3114 'url' =>
'/expedition/shipment.php?id=' .
$object->id
3119 $arrayforbutaction[] = array(
3120 'lang' =>
'sendings',
3123 'label' =>
'CreateShipment',
3124 'url' =>
'/expedition/shipment.php?id=' .
$object->id
3131 $arrayforbutaction[] = array(
3134 'perm' => ($user->hasRight(
'facture',
'creer') && !
getDolGlobalInt(
'WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3135 'label' =>
'CreateBill',
3136 'url' =>
'/compta/facture/card.php?action=create&token=' .
newToken() .
'&origin=' . urlencode(
$object->element) .
'&originid=' .
$object->id .
'&socid=' .
$object->socid
3145 $actionButtonsParameters = [
3146 "areDropdownButtons" => !
getDolGlobalInt(
"MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_ORDER")
3149 if ($numlines > 0) {
3150 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 1, $actionButtonsParameters);
3152 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 0, $actionButtonsParameters);
3157 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.
$object->id,
'');
3164 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.
$object->id,
'');
3169 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.
$object->id,
'');
3174 if ($usercancreate) {
3180 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3184 if ($usercandelete) {
3185 if ($numshipping == 0) {
3188 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3196 if (
GETPOST(
'modelselected')) {
3197 $action =
'presend';
3200 if ($action !=
'presend') {
3201 print
'<div class="fichecenter"><div class="fichehalfleft">';
3202 print
'<a name="builddoc"></a>';
3205 $relativepath = $objref.
'/'.$objref.
'.pdf';
3206 $filedir =
$conf->commande->multidir_output[
$object->entity].
'/'.$objref;
3207 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3208 $genallowed = $usercanread;
3209 $delallowed = $usercancreate;
3210 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed,
$object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'',
$object);
3214 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'order'), 1);
3215 $linktoelem = $tmparray[
'linktoelem'];
3216 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
3217 print $htmltoenteralink;
3219 $compatibleImportElementsList =
false;
3222 $compatibleImportElementsList = array(
'commande',
'propal',
'facture');
3224 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
3228 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3229 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
3230 $useonlinepayment = count($validpaymentmethod);
3233 $useonlinepayment = 0;
3236 print
'<br><!-- Link to pay -->';
3237 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3238 print showOnlinePaymentUrl(
'order',
$object->ref).
'<br>';
3241 print
'</div><div class="fichehalfright">';
3245 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/agenda.php?id='.
$object->id);
3248 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3250 $somethingshown = $formactions->showactions(
$object,
'order', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
3252 print
'</div></div>';
3256 $modelmail =
'order_send';
3257 $defaulttopic =
'SendOrderRef';
3259 $trackid =
'ord'.$object->id;
3261 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.