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';
69$langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
71if (isModEnabled(
'incoterm')) {
72 $langs->load(
'incoterm');
74if (isModEnabled(
'margin')) {
75 $langs->load(
'margins');
77if (isModEnabled(
'productbatch')) {
78 $langs->load(
'productbatch');
85$action =
GETPOST(
'action',
'aZ09');
86$cancel =
GETPOST(
'cancel',
'alpha');
87$confirm =
GETPOST(
'confirm',
'alpha');
88$backtopage =
GETPOST(
'backtopage',
'alpha');
93$origin =
GETPOST(
'origin',
'alpha');
103if (!empty($user->socid)) {
104 $socid = $user->socid;
109$price_base_type =
null;
110$lineClassName =
null;
111$remise_percent =
null;
113$availability_id =
null;
114$shipping_method_id =
null;
116$demand_reason_id =
null;
123$hookmanager->initHooks(array(
'ordercard',
'globalcard'));
131$extrafields->fetch_name_optionals_label(
$object->table_element);
134include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
137$usercanread = $user->hasRight(
"commande",
"lire");
138$usercancreate = $user->hasRight(
"commande",
"creer");
139$usercandelete = $user->hasRight(
"commande",
"supprimer");
142$usercanclose = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'close')));
143$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'validate')));
144$usercancancel = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'annuler')));
145$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'send'));
146$usercangeneretedoc = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'generetedoc'));
148$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance')) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
149$usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
151$permissionnote = $usercancreate;
152$permissiondellink = $usercancreate;
153$permissiontoadd = $usercancreate;
160$selectedLines = array();
167$parameters = array(
'socid' => $socid);
169$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
174if (empty($reshook)) {
175 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
177 if (empty($backtopage) || ($cancel && empty($id))) {
178 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
179 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
180 $backtopage = $backurlforlist;
182 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
187 $selectedLines =
GETPOST(
'toselect',
'array');
190 if (!empty($backtopageforcancel)) {
191 header(
"Location: ".$backtopageforcancel);
193 } elseif (!empty($backtopage)) {
194 header(
"Location: ".$backtopage);
200 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
202 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
204 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
207 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
209 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'IdThirdParty')),
null,
'errors');
215 $result =
$object->createFromClone($user, $socid);
217 $warningMsgLineList = array();
219 foreach (
$object->lines as $line) {
220 if (!is_object($line->product)) {
221 $line->fetch_product();
223 if (is_object($line->product) && $line->product->id > 0) {
224 if (empty($line->product->status)) {
225 $warningMsgLineList[$line->id] = $langs->trans(
'WarningLineProductNotToSell', $line->product->ref);
229 if (!empty($warningMsgLineList)) {
233 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
242 } elseif ($action ==
'reopen' && $usercancreate) {
247 $result =
$object->setDraft($user, $idwarehouse);
252 $result =
$object->set_reopen($user);
260 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
262 $result =
$object->delete($user);
264 header(
'Location: list.php?restore_lastsearch_values=1');
269 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
271 $result =
$object->deleteLine($user, $lineid);
276 $outputlangs = $langs;
279 $newlang =
GETPOST(
'lang_id',
'aZ09');
282 $newlang =
$object->thirdparty->default_lang;
284 if (!empty($newlang)) {
286 $outputlangs->setDefaultLang($newlang);
290 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
293 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id);
298 } elseif ($action ==
'classin' && $usercancreate) {
301 } elseif ($action ==
'add' && $usercancreate) {
306 if ($datecommande ==
'') {
307 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
313 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
324 $object->date_commande = $datecommande;
337 $object->delivery_date = $date_delivery;
343 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
344 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
348 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
355 if (!empty($origin) && !empty($originid)) {
357 $element = $subelement = $origin;
359 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
360 $element = $regs [1];
361 $subelement = $regs [2];
365 if ($element ==
'order') {
366 $element = $subelement =
'commande';
368 if ($element ==
'propal') {
369 $element =
'comm/propal';
370 $subelement =
'propal';
372 if ($element ==
'contract') {
373 $element = $subelement =
'contrat';
377 $object->origin_id = $originid;
381 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
382 if (!empty($other_linked_objects)) {
383 $object->linked_objects = array_merge(
$object->linked_objects, $other_linked_objects);
387 $object_id =
$object->create($user);
389 if ($object_id > 0) {
392 $classname = ucfirst($subelement);
393 $srcobject =
new $classname($db);
394 '@phan-var-force Commande|Propal|Contrat $srcobject';
397 $result = $srcobject->fetch(
$object->origin_id);
399 $lines = $srcobject->lines;
400 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
401 $srcobject->fetch_lines();
402 $lines = $srcobject->lines;
406 $num = count($lines);
408 for ($i = 0; $i < $num; $i++) {
409 if (!in_array($lines[$i]->
id, $selectedLines)) {
413 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
414 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
415 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
419 $date_start = $lines[$i]->date_debut_prevue;
420 if ($lines[$i]->date_debut_reel) {
421 $date_start = $lines[$i]->date_debut_reel;
423 if ($lines[$i]->date_start) {
424 $date_start = $lines[$i]->date_start;
426 $date_end = $lines[$i]->date_fin_prevue;
427 if ($lines[$i]->date_fin_reel) {
428 $date_end = $lines[$i]->date_fin_reel;
430 if ($lines[$i]->date_end) {
431 $date_end = $lines[$i]->date_end;
435 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
440 if (method_exists($lines[$i],
'fetch_optionals')) {
441 $lines[$i]->fetch_optionals();
442 $array_options = $lines[$i]->array_options;
445 $tva_tx = $lines[$i]->tva_tx;
446 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
447 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
452 $lines[$i]->subprice,
455 $lines[$i]->localtax1_tx,
456 $lines[$i]->localtax2_tx,
457 $lines[$i]->fk_product,
458 $lines[$i]->remise_percent,
459 $lines[$i]->info_bits,
460 $lines[$i]->fk_remise_except,
467 $lines[$i]->special_code,
469 $lines[$i]->fk_fournprice,
484 if ($result > 0 && $lines[$i]->product_type == 9) {
485 $fk_parent_line = $result;
520 $parameters = array(
'objFrom' => $srcobject);
522 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
537 $object_id =
$object->create($user);
542 if ($object_id > 0) {
556 if ($object_id > 0 && !$error) {
558 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
566 } elseif ($action ==
'classifybilled' && $usercancreate) {
567 $ret =
$object->classifyBilled($user);
572 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
573 $ret =
$object->classifyUnBilled($user);
577 } elseif ($action ==
'setref_client' && $usercancreate) {
583 } elseif ($action ==
'setremise' && $usercancreate) {
588 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
596 } elseif ($action ==
'setdate' && $usercancreate) {
599 $result =
$object->set_date($user, $date);
603 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
607 $result =
$object->setDeliveryDate($user, $date_delivery);
611 } elseif ($action ==
'setmode' && $usercancreate) {
616 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
618 $result =
$object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
619 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
622 } elseif ($action ==
'setavailability' && $usercancreate) {
627 } elseif ($action ==
'setdemandreason' && $usercancreate) {
632 } elseif ($action ==
'setconditions' && $usercancreate) {
639 $outputlangs = $langs;
640 $newlang =
GETPOST(
'lang_id',
'alpha');
642 $newlang =
$object->thirdparty->default_lang;
644 if (!empty($newlang)) {
646 $outputlangs->setDefaultLang($newlang);
650 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
653 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm') && $usercancreate) {
659 } elseif ($action ==
'setbankaccount' && $usercancreate) {
665 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
671 } elseif ($action ==
'setwarehouse' && $usercancreate) {
681 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'aZ09') && (
GETPOST(
'alldate_start',
'alpha') ||
GETPOST(
'alldate_end',
'alpha')) && $usercancreate) {
685 foreach (
$object->lines as $line) {
686 if ($line->product_type == 1) {
687 $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);
690 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'' && $usercancreate) {
692 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
693 $vat_rate = str_replace(
'*',
'', $vat_rate);
696 foreach (
$object->lines as $line) {
697 $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);
699 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
701 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
702 $remise_percent = str_replace(
'*',
'', $remise_percent);
703 foreach (
$object->lines as $line) {
704 $tvatx = $line->tva_tx;
705 if (!empty($line->vat_src_code)) {
706 $tvatx .=
' ('.$line->vat_src_code.
')';
708 $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);
710 } elseif ($action ==
'addline' && !
GETPOST(
'submitforalllines',
'alpha') && $usercancreate) {
711 $langs->load(
'errors');
716 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
719 $price_ht_devise =
'';
721 $price_ttc_devise =
'';
727 if (
GETPOST(
'price_ht') !==
'') {
730 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
733 if (
GETPOST(
'price_ttc') !==
'') {
736 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
740 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
741 if ($prod_entry_mode ==
'free') {
747 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
752 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
756 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
757 if (empty($remise_percent)) {
762 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
763 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
765 if (is_array($extralabelsline)) {
767 foreach ($extralabelsline as $key => $value) {
768 unset($_POST[
"options_".$key]);
772 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
773 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
776 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
777 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
780 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
781 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
785 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
789 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
792 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
793 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
797 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
798 if ($combinations =
GETPOST(
'combinations',
'array')) {
802 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
803 $idprod = $res->fk_product_child;
805 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
811 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
815 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
817 $price_min = $price_min_ttc = 0;
823 if (!empty($idprod) && $idprod > 0) {
825 $prod->fetch($idprod);
827 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
836 $pu_ht = $prod->price;
837 $pu_ttc = $prod->price_ttc;
838 $price_min = $prod->price_min;
839 $price_min_ttc = $prod->price_min_ttc;
840 $price_base_type = $prod->price_base_type;
844 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
848 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' =>
$object->thirdparty->id);
851 $pricebycustomerexist =
false;
852 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
854 if (count($prodcustprice->lines) > 0) {
855 $pricebycustomerexist =
true;
856 $pu_ht =
price($prodcustprice->lines[0]->price);
857 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
858 $price_min =
price($prodcustprice->lines[0]->price_min);
859 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
860 $price_base_type = $prodcustprice->lines[0]->price_base_type;
861 $tva_tx = $prodcustprice->lines[0]->tva_tx;
862 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
863 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
865 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
866 if (empty($tva_tx)) {
874 if ( !$pricebycustomerexist && !empty(
$object->thirdparty->price_level)) {
875 $pu_ht = $prod->multiprices[
$object->thirdparty->price_level];
876 $pu_ttc = $prod->multiprices_ttc[
$object->thirdparty->price_level];
877 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
878 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
879 $price_base_type = $prod->multiprices_base_type[
$object->thirdparty->price_level];
881 if (isset($prod->multiprices_tva_tx[
$object->thirdparty->price_level])) {
882 $tva_tx = $prod->multiprices_tva_tx[
$object->thirdparty->price_level];
884 if (isset($prod->multiprices_recuperableonly[
$object->thirdparty->price_level])) {
885 $tva_npr = $prod->multiprices_recuperableonly[
$object->thirdparty->price_level];
892 $pu_ht = $prod->multiprices[
$object->thirdparty->price_level];
893 $pu_ttc = $prod->multiprices_ttc[
$object->thirdparty->price_level];
894 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
895 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
896 $price_base_type = $prod->multiprices_base_type[
$object->thirdparty->price_level];
898 if (isset($prod->multiprices_tva_tx[
$object->thirdparty->price_level])) {
899 $tva_tx = $prod->multiprices_tva_tx[
$object->thirdparty->price_level];
901 if (isset($prod->multiprices_recuperableonly[
$object->thirdparty->price_level])) {
902 $tva_npr = $prod->multiprices_recuperableonly[
$object->thirdparty->price_level];
907 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
911 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' =>
$object->thirdparty->id);
913 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
915 if (count($prodcustprice->lines) > 0) {
916 $pu_ht =
price($prodcustprice->lines[0]->price);
917 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
918 $price_min =
price($prodcustprice->lines[0]->price_min);
919 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
920 $price_base_type = $prodcustprice->lines[0]->price_base_type;
921 $tva_tx = $prodcustprice->lines[0]->tva_tx;
922 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
923 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
925 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
926 if (empty($tva_tx)) {
935 if ($prod->prices_by_qty[0]) {
940 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
941 if ($priceforthequantityarray[
'rowid'] != $pqp) {
945 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
946 $pu_ht = $priceforthequantityarray[
'unitprice'];
948 $pu_ttc = $priceforthequantityarray[
'unitprice'];
956 if ($prod->prices_by_qty[
$object->thirdparty->price_level]) {
960 foreach ($prod->prices_by_qty_list[
$object->thirdparty->price_level] as $priceforthequantityarray) {
961 if ($priceforthequantityarray[
'rowid'] != $pqp) {
965 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
966 $pu_ht = $priceforthequantityarray[
'unitprice'];
968 $pu_ttc = $priceforthequantityarray[
'unitprice'];
976 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
977 $tmpprodvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
980 if (!empty($price_ht) || $price_ht ===
'0') {
982 $pu_ttc =
price2num((
float) $pu_ht * (1 + ($tmpvat / 100)),
'MU');
983 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
985 $pu_ht =
price2num((
float) $pu_ttc / (1 + ($tmpvat / 100)),
'MU');
986 } elseif ($tmpvat != $tmpprodvat) {
988 if ($price_base_type !=
'HT') {
989 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
991 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
999 $outputlangs = $langs;
1001 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1002 $newlang =
GETPOST(
'lang_id',
'aZ09');
1004 if (empty($newlang)) {
1005 $newlang =
$object->thirdparty->default_lang;
1007 if (!empty($newlang)) {
1008 $outputlangs =
new Translate(
"", $conf);
1009 $outputlangs->setDefaultLang($newlang);
1012 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->
description;
1014 $desc = $prod->description;
1023 $desc = $product_desc;
1029 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
1033 $outputlangs = $langs;
1035 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
1036 $newlang =
GETPOST(
'lang_id',
'alpha');
1038 if (empty($newlang)) {
1039 $newlang =
$object->thirdparty->default_lang;
1041 if (!empty($newlang)) {
1042 $outputlangs =
new Translate(
"", $conf);
1043 $outputlangs->setDefaultLang($newlang);
1044 $outputlangs->load(
'products');
1046 if (!empty($prod->customcode)) {
1047 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1049 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1052 if (!empty($prod->country_code)) {
1053 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $outputlangs, 0);
1056 if (!empty($prod->customcode)) {
1057 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
1059 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1062 if (!empty($prod->country_code)) {
1063 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code,
'', $db, $langs, 0);
1070 $type = $prod->type;
1071 $fk_unit = $prod->fk_unit;
1075 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
1076 $tva_tx = str_replace(
'*',
'', $tva_tx);
1077 if (empty($tva_tx)) {
1080 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1081 $desc = $product_desc;
1083 $fk_unit =
GETPOST(
'units',
'alpha');
1084 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
1085 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
1087 if ($pu_ttc && !$pu_ht) {
1088 $price_base_type =
'TTC';
1106 $pu_equivalent = $pu_ht;
1107 $pu_equivalent_ttc = $pu_ttc;
1109 $currency_tx =
$object->multicurrency_tx;
1113 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1114 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
1116 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1117 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
1134 if ($usermustrespectpricemin) {
1135 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (
float)
price2num($price_min)) && $price_base_type ==
'HT') {
1136 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1139 } 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') {
1140 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1148 $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);
1156 $outputlangs = $langs;
1157 $newlang =
GETPOST(
'lang_id',
'alpha');
1159 $newlang =
$object->thirdparty->default_lang;
1161 if (!empty($newlang)) {
1162 $outputlangs =
new Translate(
"", $conf);
1163 $outputlangs->setDefaultLang($newlang);
1166 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1169 unset($_POST[
'prod_entry_mode']);
1171 unset($_POST[
'qty']);
1172 unset($_POST[
'type']);
1173 unset($_POST[
'remise_percent']);
1174 unset($_POST[
'price_ht']);
1175 unset($_POST[
'multicurrency_price_ht']);
1176 unset($_POST[
'price_ttc']);
1177 unset($_POST[
'tva_tx']);
1178 unset($_POST[
'product_ref']);
1179 unset($_POST[
'product_label']);
1180 unset($_POST[
'product_desc']);
1181 unset($_POST[
'fournprice']);
1182 unset($_POST[
'buying_price']);
1183 unset($_POST[
'np_marginRate']);
1184 unset($_POST[
'np_markRate']);
1185 unset($_POST[
'dp_desc']);
1186 unset($_POST[
'idprod']);
1187 unset($_POST[
'units']);
1189 unset($_POST[
'date_starthour']);
1190 unset($_POST[
'date_startmin']);
1191 unset($_POST[
'date_startsec']);
1192 unset($_POST[
'date_startday']);
1193 unset($_POST[
'date_startmonth']);
1194 unset($_POST[
'date_startyear']);
1195 unset($_POST[
'date_endhour']);
1196 unset($_POST[
'date_endmin']);
1197 unset($_POST[
'date_endsec']);
1198 unset($_POST[
'date_endday']);
1199 unset($_POST[
'date_endmonth']);
1200 unset($_POST[
'date_endyear']);
1206 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1218 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1223 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1224 $vat_rate = str_replace(
'*',
'', $vat_rate);
1236 $pu_equivalent = $pu_ht;
1237 $pu_equivalent_ttc = $pu_ttc;
1239 $currency_tx =
$object->multicurrency_tx;
1243 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1244 $pu_equivalent = (float) $pu_ht_devise * (
float) $currency_tx;
1246 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1247 $pu_equivalent_ttc = (float) $pu_ttc_devise * (
float) $currency_tx;
1266 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
1267 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line);
1269 if (is_array($extralabelsline)) {
1270 foreach ($extralabelsline as $key => $value) {
1271 unset($_POST[
"options_".$key]);
1276 $special_code =
GETPOST(
'special_code');
1285 if (!empty($productid)) {
1287 $product->fetch($productid);
1289 $type = $product->type;
1291 $price_min = $product->price_min;
1293 $price_min = $product->multiprices_min[
$object->thirdparty->price_level];
1295 $price_min_ttc = $product->price_min_ttc;
1297 $price_min_ttc = $product->multiprices_min_ttc[
$object->thirdparty->price_level];
1303 if ($usermustrespectpricemin) {
1304 if ($pu_equivalent && $price_min && (((
float)
price2num($pu_equivalent) * (1 - $remise_percent / 100)) < (float)
price2num($price_min)) && $price_base_type ==
'HT') {
1305 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1308 $action =
'editline';
1309 } 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') {
1310 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1313 $action =
'editline';
1318 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1322 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1324 $action =
'editline';
1329 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1331 $action =
'editline';
1335 if (!$user->hasRight(
'margins',
'creer')) {
1336 foreach (
$object->lines as &$line) {
1338 $fournprice = $line->fk_fournprice;
1339 $buyingprice = $line->pa_ht;
1345 $price_base_type =
'HT';
1347 if (empty($pu) && !empty($pu_ttc)) {
1349 $price_base_type =
'TTC';
1352 $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);
1357 $outputlangs = $langs;
1360 $newlang =
GETPOST(
'lang_id',
'aZ09');
1363 $newlang =
$object->thirdparty->default_lang;
1365 if (!empty($newlang)) {
1366 $outputlangs =
new Translate(
"", $conf);
1367 $outputlangs->setDefaultLang($newlang);
1371 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1374 unset($_POST[
'qty']);
1375 unset($_POST[
'type']);
1376 unset($_POST[
'productid']);
1377 unset($_POST[
'remise_percent']);
1378 unset($_POST[
'price_ht']);
1379 unset($_POST[
'multicurrency_price_ht']);
1380 unset($_POST[
'price_ttc']);
1381 unset($_POST[
'tva_tx']);
1382 unset($_POST[
'product_ref']);
1383 unset($_POST[
'product_label']);
1384 unset($_POST[
'product_desc']);
1385 unset($_POST[
'fournprice']);
1386 unset($_POST[
'buying_price']);
1388 unset($_POST[
'date_starthour']);
1389 unset($_POST[
'date_startmin']);
1390 unset($_POST[
'date_startsec']);
1391 unset($_POST[
'date_startday']);
1392 unset($_POST[
'date_startmonth']);
1393 unset($_POST[
'date_startyear']);
1394 unset($_POST[
'date_endhour']);
1395 unset($_POST[
'date_endmin']);
1396 unset($_POST[
'date_endsec']);
1397 unset($_POST[
'date_endday']);
1398 unset($_POST[
'date_endmonth']);
1399 unset($_POST[
'date_endyear']);
1404 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1405 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
1407 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1410 $qualified_for_stock_change = 0;
1412 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1414 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1418 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1419 if (!$idwarehouse || $idwarehouse == -1) {
1421 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1427 $locationTarget =
'';
1431 $result =
$object->valid($user, $idwarehouse);
1436 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
1439 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1440 && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')
1442 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1445 $forceFields = array();
1447 if (GETPOSTISSET(
'date_pointoftax')) {
1455 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1467 $outputlangs = $langs;
1470 $newlang =
GETPOST(
'lang_id',
'aZ09');
1473 $newlang =
$object->thirdparty->default_lang;
1475 if (!empty($newlang)) {
1476 $outputlangs =
new Translate(
"", $conf);
1477 $outputlangs->setDefaultLang($newlang);
1482 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1485 $deposit->fetch($deposit->id);
1486 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1490 if ($locationTarget) {
1491 header(
'Location: ' . $locationTarget);
1502 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1504 $idwarehouse =
GETPOST(
'idwarehouse');
1506 $qualified_for_stock_change = 0;
1508 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1510 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1514 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1515 if (!$idwarehouse || $idwarehouse == -1) {
1517 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1523 $result =
$object->setDraft($user, $idwarehouse);
1527 $outputlangs = $langs;
1530 $newlang =
GETPOST(
'lang_id',
'aZ09');
1533 $newlang =
$object->thirdparty->default_lang;
1535 if (!empty($newlang)) {
1536 $outputlangs =
new Translate(
"", $conf);
1537 $outputlangs->setDefaultLang($newlang);
1542 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1548 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1549 $result =
$object->cloture($user);
1553 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1556 $qualified_for_stock_change = 0;
1558 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
1560 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
1564 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1565 if (!$idwarehouse || $idwarehouse == -1) {
1567 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1573 $result =
$object->cancel($idwarehouse);
1581 if ($action ==
'update_extras' && $usercancreate) {
1583 $attribute_name =
GETPOST(
'attribute',
'restricthtml');
1586 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute_name);
1593 $result =
$object->updateExtraField($attribute_name,
'ORDER_MODIFY');
1601 $action =
'edit_extras';
1606 if ($action ==
'import_lines_from_object'
1610 $fromElement =
GETPOST(
'fromelement');
1611 $fromElementid =
GETPOST(
'fromelementid');
1612 $importLines =
GETPOST(
'line_checkbox');
1614 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1615 if ($fromElement ==
'commande') {
1617 $lineClassName =
'OrderLine';
1618 } elseif ($fromElement ==
'propal') {
1619 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1620 $lineClassName =
'PropaleLigne';
1621 } elseif ($fromElement ==
'facture') {
1622 dol_include_once(
'/compta/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1623 $lineClassName =
'FactureLigne';
1625 $nextRang = count(
$object->lines) + 1;
1628 foreach ($importLines as $lineId) {
1629 $lineId = intval($lineId);
1630 $originLine =
new $lineClassName($db);
1631 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1632 $originLine->fetch_optionals();
1633 $desc = $originLine->desc;
1634 $pu_ht = $originLine->subprice;
1635 $qty = $originLine->qty;
1636 $txtva = $originLine->tva_tx;
1637 $txlocaltax1 = $originLine->localtax1_tx;
1638 $txlocaltax2 = $originLine->localtax2_tx;
1639 $fk_product = $originLine->fk_product;
1640 $remise_percent = $originLine->remise_percent;
1641 $date_start = $originLine->date_start;
1642 $date_end = $originLine->date_end;
1643 $fk_code_ventilation = 0;
1644 $info_bits = $originLine->info_bits;
1645 $fk_remise_except = $originLine->fk_remise_except;
1646 $price_base_type =
'HT';
1648 $type = $originLine->product_type;
1649 $rang = $nextRang++;
1650 $special_code = $originLine->special_code;
1651 $origin = $originLine->element;
1652 $origin_id = $originLine->id;
1653 $fk_parent_line = 0;
1654 $fk_fournprice = $originLine->fk_fournprice;
1655 $pa_ht = $originLine->pa_ht;
1656 $label = $originLine->label;
1657 $array_options = $originLine->array_options;
1658 $situation_percent = 100;
1660 $fk_unit = $originLine->fk_unit;
1661 $pu_ht_devise = $originLine->multicurrency_subprice;
1663 $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);
1682 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1685 $upload_dir = !empty($conf->commande->multidir_output[
$object->entity]) ? $conf->commande->multidir_output[
$object->entity] : $conf->commande->dir_output;
1686 $permissiontoadd = $usercancreate;
1687 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1690 $triggersendname =
'ORDER_SENTBYMAIL';
1692 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1693 $trackid =
'ord'.$object->id;
1694 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1698 if ($action ==
'addcontact' && $usercancreate) {
1702 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1706 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1709 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1710 $langs->load(
"errors");
1711 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1716 } elseif ($action ==
'swapstatut' && $usercancreate) {
1723 } elseif ($action ==
'deletecontact' && $usercancreate) {
1725 $result =
$object->delete_contact($lineid);
1728 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1742$title =
$object->ref.
" - ".$langs->trans(
'Card');
1743if ($action ==
'create') {
1744 $title = $langs->trans(
"NewOrder");
1746$help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1748llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-order page-card');
1750$form =
new Form($db);
1754if (isModEnabled(
'project')) {
1759if ($action ==
'create' && $usercancreate) {
1764 $res = $soc->fetch($socid);
1769 $currency_code = $conf->currency;
1771 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1772 $deposit_percent =
GETPOSTFLOAT(
'cond_reglement_id_deposit_percent');
1773 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1776 if (!empty($origin) && !empty($originid)) {
1778 $element = $subelement = $origin;
1780 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1781 $element = $regs[1];
1782 $subelement = $regs[2];
1785 if ($element ==
'project') {
1786 $projectid = $originid;
1788 if (!$cond_reglement_id) {
1789 $cond_reglement_id = $soc->cond_reglement_id;
1791 if (!$deposit_percent) {
1792 $deposit_percent = $soc->deposit_percent;
1794 if (!$mode_reglement_id) {
1795 $mode_reglement_id = $soc->mode_reglement_id;
1797 if (!$remise_percent) {
1798 $remise_percent = $soc->remise_percent;
1806 if ($element ==
'order' || $element ==
'commande') {
1807 $element = $subelement =
'commande';
1808 } elseif ($element ==
'propal') {
1809 $element =
'comm/propal';
1810 $subelement =
'propal';
1811 } elseif ($element ==
'contract') {
1812 $element = $subelement =
'contrat';
1817 $classname = ucfirst($subelement);
1818 $objectsrc =
new $classname($db);
1819 '@phan-var-force Commande|Propal|Contrat $objectsrc';
1820 $objectsrc->fetch($originid);
1821 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1822 $objectsrc->fetch_lines();
1824 $objectsrc->fetch_thirdparty();
1827 $objectsrc->fetch_optionals();
1828 $object->array_options = $objectsrc->array_options;
1830 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1831 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1833 $soc = $objectsrc->thirdparty;
1834 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1835 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1836 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1837 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1838 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1839 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1840 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1841 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1846 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1848 if (isModEnabled(
"multicurrency")) {
1849 if (!empty($objectsrc->multicurrency_code)) {
1850 $currency_code = $objectsrc->multicurrency_code;
1852 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1853 $currency_tx = $objectsrc->multicurrency_tx;
1857 $note_private =
$object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1858 $note_public =
$object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1861 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1864 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1865 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1866 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1867 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1868 $availability_id = 0;
1869 $shipping_method_id = $soc->shipping_method_id;
1870 $warehouse_id = $soc->fk_warehouse;
1871 $demand_reason_id = $soc->demand_reason_id;
1876 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1877 $currency_code = $soc->multicurrency_code;
1880 $note_private =
$object->getDefaultCreateValueFor(
'note_private');
1881 $note_public =
$object->getDefaultCreateValueFor(
'note_public');
1885 if (!
GETPOST(
'changecompany')) {
1886 if (GETPOSTISSET(
'cond_reglement_id')) {
1887 $cond_reglement_id =
GETPOSTINT(
'cond_reglement_id');
1889 if (GETPOSTISSET(
'deposit_percent')) {
1892 if (GETPOSTISSET(
'mode_reglement_id')) {
1893 $mode_reglement_id =
GETPOSTINT(
'mode_reglement_id');
1895 if (GETPOSTISSET(
'cond_reglement_id')) {
1901 if ($soc->fk_warehouse > 0) {
1902 $warehouse_id = $soc->fk_warehouse;
1904 if (isModEnabled(
'stock') && empty($warehouse_id) &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1909 $warehouse_id = $user->fk_warehouse;
1913 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1914 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1915 print
'<input type="hidden" name="action" value="add">';
1916 print
'<input type="hidden" name="changecompany" value="0">';
1917 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1918 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1919 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1920 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1921 if (!empty($currency_tx)) {
1922 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1928 $parameters = array();
1930 $reshook = $hookmanager->executeHooks(
'tabContentCreateOrder', $parameters,
$object, $action);
1931 if (empty($reshook)) {
1932 print
'<table class="border centpercent">';
1935 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1938 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1939 if (
getDolGlobalString(
'MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1940 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1942 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1948 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1951 print $soc->getNomUrl(1,
'customer');
1952 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1955 print
'<td class="valuefieldcreate">';
1956 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
1957 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 1, 0, array(), 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1961 $(document).ready(function() {
1962 $("#socid").change(function() {
1963 console.log("We have changed the company - Reload page");
1964 var socid = $(this).val();
1966 $("input[name=action]").val("create");
1967 $("input[name=changecompany]").val("1");
1968 $("form[name=crea_commande]").submit();
1973 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1981 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1982 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1984 print $form->select_contact($soc->id, $contactid,
'contactid', 1, empty($srccontactslist) ?
"" : $srccontactslist,
'', 1,
'maxwidth300 widthcentpercentminusx', true);
1988 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1990 $absolute_discount = $soc->getAvailableDiscounts();
1994 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode((
string) (
GETPOST(
'origin'))).
'&originid='.urlencode((
string) (
GETPOSTINT(
'originid')));
1995 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2001 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
2002 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2003 print $form->selectDate(
'',
're', 0, 0, 0,
"crea_commande", 1, 1);
2007 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
2008 print
'<td colspan="3">';
2009 $date_delivery = ($date_delivery ? $date_delivery :
$object->delivery_date);
2010 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
2011 print $form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
2016 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
2017 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
2018 $form->selectAvailabilityDelay((GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id') : $availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2022 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
2023 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
2024 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
2028 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
2029 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
2030 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
2034 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2035 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
2036 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
2041 if (isModEnabled(
'shipping')) {
2042 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
2043 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
2044 $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');
2049 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2050 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2052 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
2053 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');
2058 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
2059 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
2060 $form->selectInputReason((GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id') : $demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
2066 if (isModEnabled(
'project')) {
2067 $langs->load(
"projects");
2069 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
2070 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');
2071 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>';
2077 if (isModEnabled(
'incoterm')) {
2079 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
2080 print
'<td class="maxwidthonsmartphone">';
2081 $incoterm_id =
GETPOST(
'incoterm_id');
2082 $location_incoterms =
GETPOST(
'location_incoterms');
2083 if (empty($incoterm_id)) {
2084 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
2085 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
2087 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
2088 print $form->select_incoterms($incoterm_id, $location_incoterms);
2093 $parameters = array();
2094 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2095 $parameters[
'objectsrc'] = $objectsrc;
2097 $parameters[
'socid'] = $socid;
2100 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
2101 print $hookmanager->resPrint;
2102 if (empty($reshook)) {
2103 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2106 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2107 if ($soc->fetch_optionals() > 0) {
2108 $object->array_options = array_merge(
$object->array_options, $soc->array_options);
2112 print
$object->showOptionals($extrafields,
'create', $parameters);
2116 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
2118 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2121 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
2122 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
2126 if (isModEnabled(
"multicurrency")) {
2128 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'',
$object, 0).
'</td>';
2129 print
'<td class="maxwidthonsmartphone">';
2130 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', 0,
'maxwidth200 widthcentpercentminusx');
2136 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
2139 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2140 print $doleditor->Create(1);
2145 if (empty($user->socid)) {
2147 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
2150 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2151 print $doleditor->Create(1);
2156 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2158 if ($origin ==
'contrat') {
2162 $objectsrc->update_price(1);
2165 print
"\n<!-- ".$classname.
" info -->";
2167 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2168 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2169 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2170 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2171 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2173 switch ($classname) {
2175 $newclassname =
'CommercialProposal';
2178 $newclassname =
'Order';
2181 $newclassname =
'Sending';
2184 $newclassname =
'Contract';
2187 $newclassname = $classname;
2190 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2193 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2194 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2195 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2196 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2199 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2200 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2203 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2205 if (isModEnabled(
"multicurrency")) {
2206 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2207 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2208 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2219 print $form->buttonsSaveCancel(
"CreateDraft");
2222 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2223 $title = $langs->trans(
'ProductsAndServices');
2226 print
'<div class="div-table-responsive-no-min">';
2227 print
'<table class="noborder centpercent">';
2229 $objectsrc->printOriginLinesList(
'', $selectedLines);
2241 $product_static =
new Product($db);
2246 $author =
new User($db);
2247 $author->fetch(
$object->user_author_id);
2250 $res =
$object->fetch_optionals();
2253 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2258 if ($action ==
'delete') {
2259 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2263 if ($action ==
'validate') {
2265 $ref = substr(
$object->ref, 1, 4);
2266 if ($ref ==
'PROV' || $ref ==
'') {
2267 $numref =
$object->getNextNumRef($soc);
2268 if (empty($numref)) {
2276 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2277 if (isModEnabled(
'notification')) {
2278 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2279 $notify =
new Notify($db);
2281 $text .= $notify->confirmMessage(
'ORDER_VALIDATE',
$object->socid,
$object);
2284 $qualified_for_stock_change = 0;
2286 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2288 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2291 $formquestion = array();
2292 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2293 $langs->load(
"stocks");
2294 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2297 if ($conf->browser->name ==
'ie') {
2300 $formquestion = array(
2304 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockDecrease"),
'value' => $formproduct->selectWarehouses(
GETPOSTINT(
'idwarehouse') ?
GETPOSTINT(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2310 foreach (
$object->lines as $line) {
2311 $res = $line->fetch_product();
2313 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2319 if ($nbMandated > 0) {
2321 setEventMessages($langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate"),
null,
'errors');
2324 $text .=
'<div><span class="clearboth nowraponall warning">'.img_warning().$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2328 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2333 $deposit_percent_from_payment_terms = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent',
$object->cond_reglement_id);
2335 if (!empty($deposit_percent_from_payment_terms) && isModEnabled(
'invoice') && $user->hasRight(
'facture',
'creer')) {
2336 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2340 $eligibleForDepositGeneration =
true;
2342 if (array_key_exists(
'facture',
$object->linkedObjects)) {
2343 foreach (
$object->linkedObjects[
'facture'] as $invoice) {
2344 '@phan-var-force Facture $invoice';
2346 $eligibleForDepositGeneration =
false;
2352 if ($eligibleForDepositGeneration && array_key_exists(
'propal',
$object->linkedObjects)) {
2353 foreach (
$object->linkedObjects[
'propal'] as $proposal) {
2354 $proposal->fetchObjectLinked();
2356 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2357 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2358 '@phan-var-force Facture $invoice';
2360 $eligibleForDepositGeneration =
false;
2368 if ($eligibleForDepositGeneration) {
2369 $formquestion[] = array(
2370 'type' =>
'checkbox',
2372 'name' =>
'generate_deposit',
2373 'label' => $form->textwithpicto($langs->trans(
'GenerateDeposit',
$object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2376 $formquestion[] = array(
2378 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2380 'label' => $langs->trans(
'DateInvoice'),
2386 $formquestion[] = array(
2388 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2389 'name' =>
'date_pointoftax',
2390 'label' => $langs->trans(
'DatePointOfTax'),
2397 $paymentTermsSelect = $form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2399 $formquestion[] = array(
2401 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2402 'name' =>
'cond_reglement_id',
2403 'label' => $langs->trans(
'PaymentTerm'),
2404 'value' => $paymentTermsSelect
2407 $formquestion[] = array(
2408 'type' =>
'checkbox',
2409 'tdclass' =>
'showonlyifgeneratedeposit',
2410 'name' =>
'validate_generated_deposit',
2411 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2414 $formquestion[] = array(
2415 'type' =>
'onecolumn',
2418 $(document).ready(function() {
2419 $("[name=generate_deposit]").change(function () {
2420 let $self = $(this);
2421 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2423 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2440 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 240);
2445 if ($action ==
'modif') {
2446 $qualified_for_stock_change = 0;
2448 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2450 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2453 $text = $langs->trans(
'ConfirmUnvalidateOrder',
$object->ref);
2454 $formquestion = array();
2455 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2456 $langs->load(
"stocks");
2457 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2460 if ($conf->browser->name ==
'ie') {
2463 $formquestion = array(
2467 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2471 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2477 if ($action ==
'shipped') {
2478 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2484 if ($action ==
'cancel') {
2485 $qualified_for_stock_change = 0;
2487 $qualified_for_stock_change =
$object->hasProductsOrServices(2);
2489 $qualified_for_stock_change =
$object->hasProductsOrServices(1);
2492 $text = $langs->trans(
'ConfirmCancelOrder',
$object->ref);
2493 $formquestion = array();
2494 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2495 $langs->load(
"stocks");
2496 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2499 if ($conf->browser->name ==
'ie') {
2502 $formquestion = array(
2506 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2510 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2514 if ($action ==
'ask_deleteline') {
2515 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2519 if ($action ==
'clone') {
2520 $filter =
'(s.client:IN:1,2,3)';
2522 $formquestion = array(
2523 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter,
'', 0, 0, array(), 0,
'maxwidth300'))
2525 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2529 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2531 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
2532 if (empty($reshook)) {
2533 $formconfirm .= $hookmanager->resPrint;
2534 } elseif ($reshook > 0) {
2535 $formconfirm = $hookmanager->resPrint;
2544 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2546 $morehtmlref =
'<div class="refidno">';
2548 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client',
$object->ref_client,
$object, $usercancreate,
'string',
'', 0, 1);
2549 $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);
2551 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2553 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.
$object->thirdparty->id.
'&search_societe='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2556 if (isModEnabled(
'project')) {
2557 $langs->load(
"projects");
2558 $morehtmlref .=
'<br>';
2559 if ($usercancreate) {
2560 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2561 if ($action !=
'classify') {
2562 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2564 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2566 if (!empty(
$object->fk_project)) {
2568 $proj->fetch(
$object->fk_project);
2569 $morehtmlref .= $proj->getNomUrl(1);
2571 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2576 $morehtmlref .=
'</div>';
2579 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2582 $parameters = array();
2584 $reshook = $hookmanager->executeHooks(
'tabContentViewOrder', $parameters,
$object, $action);
2585 if (empty($reshook)) {
2586 print
'<div class="fichecenter">';
2587 print
'<div class="fichehalfleft">';
2588 print
'<div class="underbanner clearboth"></div>';
2590 print
'<table class="border tableforfield centpercent">';
2592 if ($soc->outstanding_limit) {
2594 print
'<tr><td class="titlefield">';
2595 print $langs->trans(
'OutstandingBill');
2596 print
'</td><td class="valuefield">';
2597 $arrayoutstandingbills = $soc->getOutstandingBills();
2598 print
price($arrayoutstandingbills[
'opened']).
' / ';
2599 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2606 $filterabsolutediscount =
"fk_facture_source IS NULL";
2607 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2609 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2610 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2613 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2614 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.
$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2615 $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>';
2617 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2619 $absolute_discount = $soc->getAvailableDiscounts(
null, $filterabsolutediscount);
2620 $absolute_creditnote = $soc->getAvailableDiscounts(
null, $filtercreditnote);
2621 $absolute_discount =
price2num($absolute_discount,
'MT');
2622 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2626 $backtopage = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id;
2627 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2634 print $form->editfieldkey(
"Date",
'date',
'',
$object, $editenable);
2635 print
'</td><td class="valuefield">';
2636 if ($action ==
'editdate') {
2637 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="post">';
2638 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2639 print
'<input type="hidden" name="action" value="setdate">';
2640 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2641 print $form->selectDate(
$object->date,
'order_', 0, 0, 0,
"setdate");
2642 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2647 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2655 $editenable = $usercancreate;
2656 print $form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'',
$object, $editenable);
2657 print
'</td><td class="valuefield">';
2658 if ($action ==
'editdate_livraison') {
2659 print
'<form name="setdate_livraison" 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_livraison">';
2662 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2663 print $form->selectDate(
$object->delivery_date ?
$object->delivery_date : -1,
'liv_', 1, 1, 0,
"setdate_livraison", 1, 0);
2664 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2669 print
' '.img_picto($langs->trans(
"Late").
' : '.
$object->showDelay(),
"warning");
2676 print
'<tr class="fielddeliverydelay"><td>';
2677 $editenable = $usercancreate;
2678 print $form->editfieldkey(
"AvailabilityPeriod",
'availability',
'',
$object, $editenable);
2679 print
'</td><td class="valuefield">';
2680 if ($action ==
'editavailability') {
2681 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'availability_id', 1);
2683 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->availability_id,
'none', 1);
2688 if (isModEnabled(
'shipping')) {
2690 $editenable = $usercancreate;
2691 print $form->editfieldkey(
"SendingMethod",
'shippingmethod',
'',
$object, $editenable);
2692 print
'</td><td class="valuefield">';
2693 if ($action ==
'editshippingmethod') {
2694 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'shipping_method_id', 1);
2696 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->shipping_method_id,
'none');
2703 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2704 $langs->load(
'stocks');
2705 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2708 $editenable = $usercancreate;
2709 print $form->editfieldkey(
"Warehouse",
'warehouse',
'',
$object, $editenable);
2710 print
'</td><td class="valuefield">';
2711 if ($action ==
'editwarehouse') {
2712 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'warehouse_id', 1);
2714 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->warehouse_id,
'none');
2722 $editenable = $usercancreate;
2723 print $form->editfieldkey(
"Source",
'demandreason',
'',
$object, $editenable);
2724 print
'</td><td class="valuefield">';
2725 if ($action ==
'editdemandreason') {
2726 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'demand_reason_id', 1);
2728 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->demand_reason_id,
'none');
2734 $editenable = $usercancreate;
2735 print $form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'',
$object, $editenable);
2736 print
'</td><td class="valuefield">';
2737 if ($action ==
'editconditions') {
2738 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1,
$object->deposit_percent);
2740 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->cond_reglement_id,
'none', 1,
'', 1,
$object->deposit_percent);
2748 $editenable = $usercancreate;
2749 print $form->editfieldkey(
"PaymentMode",
'mode',
'',
$object, $editenable);
2750 print
'</td><td class="valuefield">';
2751 if ($action ==
'editmode') {
2752 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2754 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->mode_reglement_id,
'none');
2772 $tmparray =
$object->getTotalWeightVolume();
2773 $totalWeight = $tmparray[
'weight'];
2774 $totalVolume = $tmparray[
'volume'];
2776 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2777 print
'<td class="valuefield">';
2778 print
showDimensionInBestUnit($totalWeight, 0,
"weight", $langs,
getDolGlobalInt(
'MAIN_WEIGHT_DEFAULT_ROUND', -1), isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT :
'no');
2782 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2783 print
'<td class="valuefield">';
2784 print
showDimensionInBestUnit($totalVolume, 0,
"volume", $langs,
getDolGlobalInt(
'MAIN_VOLUME_DEFAULT_ROUND', -1), isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT :
'no');
2791 if (isModEnabled(
'incoterm')) {
2793 $editenable = $usercancreate;
2794 print $form->editfieldkey(
"IncotermLabel",
'incoterm',
'',
$object, $editenable);
2796 print
'<td class="valuefield">';
2797 if ($action !=
'editincoterm') {
2798 print $form->textwithpicto(
$object->display_incoterms(),
$object->label_incoterms, 1);
2800 print $form->select_incoterms((!empty(
$object->fk_incoterms) ?
$object->fk_incoterms :
''), (!empty(
$object->location_incoterms) ?
$object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.
$object->id);
2806 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"bank")) {
2808 $editenable = $usercancreate;
2809 print $form->editfieldkey(
"BankAccount",
'bankaccount',
'',
$object, $editenable);
2810 print
'</td><td class="valuefield">';
2811 if ($action ==
'editbankaccount') {
2812 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'fk_account', 1);
2814 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->fk_account,
'none');
2821 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2826 print
'<div class="fichehalfright">';
2827 print
'<div class="underbanner clearboth"></div>';
2829 print
'<table class="border tableforfield centpercent">';
2831 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_currency_amount.tpl.php';
2835 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price(
$object->thirdparty->order_min_amount));
2839 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2840 print
'<td class="nowrap amountcard right">' .
price(
$object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2841 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2843 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_ht, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2848 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2849 print
'<td class="nowrap amountcard right">' .
price(
$object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2850 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2852 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_tva, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2857 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2859 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2860 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2861 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2864 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2870 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2872 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2873 print
'<td class="nowrap amountcard right">' .
price(
$object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) .
'</td>';
2874 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2877 print
'<td class="nowrap amountcard right">' .
price(
$object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1,
$object->multicurrency_code) .
'</td>';
2883 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2884 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->total_ttc, 1,
'', 1, -1, -1, $conf->currency) .
'</td>';
2885 if (isModEnabled(
"multicurrency") && (
$object->multicurrency_code &&
$object->multicurrency_code != $conf->currency)) {
2887 print
'<td class="valuefield nowrap right amountcard">' .
price(
$object->multicurrency_total_ttc, 1,
'', 1, -1, -1,
$object->multicurrency_code) .
'</td>';
2897 if (isModEnabled(
'margin')) {
2898 $formmargin->displayMarginInfos(
$object);
2905 print
'<div class="clearboth"></div><br>';
2908 $blocname =
'contacts';
2909 $title = $langs->trans(
'ContactsAddresses');
2910 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2914 $blocname =
'notes';
2915 $title = $langs->trans(
'Notes');
2916 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2924 $result =
$object->getLinesArray();
2928 global $inputalsopricewithtax;
2929 $inputalsopricewithtax = 1;
2931 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">
2932 <input type="hidden" name="token" value="' .
newToken().
'">
2933 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2934 <input type="hidden" name="mode" value="">
2935 <input type="hidden" name="page_y" value="">
2936 <input type="hidden" name="id" value="' .
$object->id.
'">
2937 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2941 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2944 print
'<div class="div-table-responsive-no-min">';
2945 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2949 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2956 if ($action !=
'editline') {
2959 $parameters = array();
2961 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2965 if (empty($reshook)) {
2966 $object->formAddObjectLine(1, $mysoc, $soc);
2969 $parameters = array();
2970 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters,
$object, $action);
2984 if ($action !=
'presend' && $action !=
'editline') {
2985 print
'<div class="tabsAction">';
2987 $parameters = array();
2989 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2990 if (empty($reshook)) {
2991 $numlines = count(
$object->lines);
2999 if (empty($user->socid)) {
3002 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.
$object->id.
'&mode=init#formmailbeforetitle',
'');
3004 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3011 if ($numlines > 0) {
3014 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.
$object->id,
$object->id, 0);
3022 $arrayforbutaction = array();
3026 $arrayforbutaction[] = array(
'lang' =>
'orders',
'enabled' => (isModEnabled(
"supplier_order") &&
$object->statut >
Commande::STATUS_DRAFT),
'perm' => $usercancreatepurchaseorder,
'label' =>
'AddPurchaseOrder',
'url' =>
'/fourn/commande/card.php?action=create&origin='.urlencode(
$object->element).
'&originid='.((
int)
$object->id));
3036 $arrayforbutaction[] = array(
'lang' =>
'interventions',
'enabled' => (isModEnabled(
"intervention") &&
$object->statut >
Commande::STATUS_DRAFT &&
$object->statut <
Commande::STATUS_CLOSED &&
$object->getNbOfServicesLines() > 0),
'perm' => $user->hasRight(
'ficheinter',
'creer'),
'label' =>
'AddIntervention',
'url' =>
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.
$object->id.
'&socid='.
$object->socid);
3060 if (isModEnabled(
'shipping')) {
3061 $numshipping =
$object->countNbOfShipments();
3066 if ((
getDolGlobalInt(
'MAIN_SUBMODULE_EXPEDITION') && $user->hasRight(
'expedition',
'creer')) || (
getDolGlobalInt(
'MAIN_SUBMODULE_DELIVERY') && $user->hasRight(
'expedition',
'delivery',
'creer'))) {
3075 $langs->load(
"errors");
3076 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3081 $arrayforbutaction[] = array(
3084 'perm' => ($user->hasRight(
'facture',
'creer') && !
getDolGlobalInt(
'WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3085 'label' =>
'CreateBill',
3086 'url' =>
'/compta/facture/card.php?action=create&token='.
newToken().
'&origin='.urlencode(
$object->element).
'&originid='.
$object->id.
'&socid='.
$object->socid
3095 $actionButtonsParameters = [
3096 "areDropdownButtons" => !
getDolGlobalInt(
"MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_ORDER")
3099 if ($numlines > 0) {
3100 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 1, $actionButtonsParameters);
3102 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated",
$object->ref), $langs->trans(
"Create"),
'default', $arrayforbutaction,
$object->id, 0, $actionButtonsParameters);
3107 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.
$object->id,
'');
3114 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.
$object->id,
'');
3119 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.
$object->id,
'');
3124 if ($usercancreate) {
3130 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3134 if ($usercandelete) {
3135 if ($numshipping == 0) {
3138 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3146 if (
GETPOST(
'modelselected')) {
3147 $action =
'presend';
3150 if ($action !=
'presend') {
3151 print
'<div class="fichecenter"><div class="fichehalfleft">';
3152 print
'<a name="builddoc"></a>';
3155 $relativepath = $objref.
'/'.$objref.
'.pdf';
3156 $filedir = $conf->commande->multidir_output[
$object->entity].
'/'.$objref;
3157 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3158 $genallowed = $usercanread;
3159 $delallowed = $usercancreate;
3160 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed,
$object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'',
$object);
3164 $linktoelem = $form->showLinkToObjectBlock(
$object, array(), array(
'order'));
3166 $compatibleImportElementsList =
false;
3169 $compatibleImportElementsList = array(
'commande',
'propal',
'facture');
3171 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem, $compatibleImportElementsList);
3175 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3176 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
3177 $useonlinepayment = count($validpaymentmethod);
3180 $useonlinepayment = 0;
3183 print
'<br><!-- Link to pay -->';
3184 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3185 print showOnlinePaymentUrl(
'order',
$object->ref).
'<br>';
3188 print
'</div><div class="fichehalfright">';
3192 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/agenda.php?id='.
$object->id);
3195 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3197 $somethingshown = $formactions->showactions(
$object,
'order', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
3199 print
'</div></div>';
3203 $modelmail =
'order_send';
3204 $defaulttopic =
'SendOrderRef';
3206 $trackid =
'ord'.$object->id;
3208 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.