39 require
'../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
44 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
49 if (!empty($conf->propal->enabled)) {
50 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
52 if (!empty($conf->project->enabled)) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
59 if (!empty($conf->variants->enabled)) {
60 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
64 $langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
65 if (!empty($conf->incoterm->enabled)) {
66 $langs->load(
'incoterm');
68 if (!empty($conf->margin->enabled)) {
69 $langs->load(
'margins');
71 if (!empty($conf->productbatch->enabled)) {
72 $langs->load(
"productbatch");
77 $socid =
GETPOST(
'socid',
'int');
78 $action =
GETPOST(
'action',
'aZ09');
79 $cancel =
GETPOST(
'cancel',
'alpha');
80 $confirm =
GETPOST(
'confirm',
'alpha');
81 $lineid =
GETPOST(
'lineid',
'int');
82 $contactid =
GETPOST(
'contactid',
'int');
83 $projectid =
GETPOST(
'projectid',
'int');
84 $origin =
GETPOST(
'origin',
'alpha');
86 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
89 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
90 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
91 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
94 if (!empty($user->socid)) {
95 $socid = $user->socid;
99 $hookmanager->initHooks(array(
'ordercard',
'globalcard'));
107 $extrafields->fetch_name_optionals_label($object->table_element);
110 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
112 $usercanread = $user->hasRight(
"commande",
"lire");
113 $usercancreate = $user->hasRight(
"commande",
"creer");
114 $usercandelete = $user->hasRight(
"commande",
"supprimer");
116 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->creer)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->order_advance->close)));
117 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->order_advance->validate)));
118 $usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->order_advance->annuler)));
119 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send);
121 $usercancreatepurchaseorder = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
123 $permissionnote = $usercancreate;
124 $permissiondellink = $usercancreate;
125 $permissiontoadd = $usercancreate;
129 $date_delivery =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'), 0,
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
138 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
143 if (empty($reshook)) {
144 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
146 if (empty($backtopage) || ($cancel && empty($id))) {
147 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
148 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
149 $backtopage = $backurlforlist;
151 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
157 if (!empty($backtopageforcancel)) {
158 header(
"Location: ".$backtopageforcancel);
160 } elseif (!empty($backtopage)) {
161 header(
"Location: ".$backtopage);
167 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
169 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
171 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
174 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
175 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
178 if ($object->id > 0) {
180 $orig = clone $object;
182 $result = $object->createFromClone($user, $socid);
184 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
193 } elseif ($action ==
'reopen' && $usercancreate) {
196 $result = $object->set_reopen($user);
203 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
205 $result = $object->delete($user);
207 header(
'Location: list.php?restore_lastsearch_values=1');
212 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
214 $result = $object->deleteline($user, $lineid);
217 $object->line_order(
true);
219 $outputlangs = $langs;
221 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
222 $newlang =
GETPOST(
'lang_id',
'aZ09');
224 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
225 $newlang = $object->thirdparty->default_lang;
227 if (!empty($newlang)) {
229 $outputlangs->setDefaultLang($newlang);
231 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
232 $ret = $object->fetch($object->id);
233 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
236 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
241 } elseif ($action ==
'classin' && $usercancreate) {
243 $object->setProject(
GETPOST(
'projectid',
'int'));
244 } elseif ($action ==
'add' && $usercancreate) {
247 $date_delivery =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'), 0,
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
248 $selectedLines =
GETPOST(
'toselect',
'array');
250 if ($datecommande ==
'') {
251 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
257 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
263 $object->socid = $socid;
264 $object->fetch_thirdparty();
268 $object->date_commande = $datecommande;
269 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
270 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
271 $object->source =
GETPOST(
'source_id');
272 $object->fk_project =
GETPOST(
'projectid',
'int');
273 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
274 $object->model_pdf =
GETPOST(
'model');
275 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
276 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
277 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
278 $object->fk_account =
GETPOST(
'fk_account',
'int');
279 $object->availability_id =
GETPOST(
'availability_id');
280 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
281 $object->date_livraison = $date_delivery;
282 $object->delivery_date = $date_delivery;
283 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
284 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
285 $object->fk_delivery_address =
GETPOST(
'fk_address');
286 $object->contact_id =
GETPOST(
'contactid');
287 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
288 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
289 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
290 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
293 $ret = $extrafields->setOptionalsFromPost(
null, $object);
300 if (!empty($origin) && !empty($originid)) {
302 $element = $subelement = $origin;
304 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
305 $element = $regs [1];
306 $subelement = $regs [2];
310 if ($element ==
'order') {
311 $element = $subelement =
'commande';
313 if ($element ==
'propal') {
314 $element =
'comm/propal';
315 $subelement =
'propal';
317 if ($element ==
'contract') {
318 $element = $subelement =
'contrat';
321 $object->origin = $origin;
322 $object->origin_id = $originid;
325 $object->linked_objects [$object->origin] = $object->origin_id;
326 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
327 if (!empty($other_linked_objects)) {
328 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
332 $object_id = $object->create($user);
334 if ($object_id > 0) {
337 $classname = ucfirst($subelement);
338 $srcobject =
new $classname($db);
340 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
341 $result = $srcobject->fetch($object->origin_id);
343 $lines = $srcobject->lines;
344 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
345 $srcobject->fetch_lines();
346 $lines = $srcobject->lines;
350 $num = count($lines);
352 for ($i = 0; $i < $num; $i++) {
353 if (!in_array($lines[$i]->
id, $selectedLines)) {
357 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
358 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
359 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
363 $date_start = $lines[$i]->date_debut_prevue;
364 if ($lines[$i]->date_debut_reel) {
365 $date_start = $lines[$i]->date_debut_reel;
367 if ($lines[$i]->date_start) {
368 $date_start = $lines[$i]->date_start;
370 $date_end = $lines[$i]->date_fin_prevue;
371 if ($lines[$i]->date_fin_reel) {
372 $date_end = $lines[$i]->date_fin_reel;
374 if ($lines[$i]->date_end) {
375 $date_end = $lines[$i]->date_end;
379 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
384 if (method_exists($lines[$i],
'fetch_optionals')) {
385 $lines[$i]->fetch_optionals();
386 $array_options = $lines[$i]->array_options;
389 $tva_tx = $lines[$i]->tva_tx;
390 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
391 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
394 $result = $object->addline(
396 $lines[$i]->subprice,
399 $lines[$i]->localtax1_tx,
400 $lines[$i]->localtax2_tx,
401 $lines[$i]->fk_product,
402 $lines[$i]->remise_percent,
403 $lines[$i]->info_bits,
404 $lines[$i]->fk_remise_except,
411 $lines[$i]->special_code,
413 $lines[$i]->fk_fournprice,
428 if ($result > 0 && $lines[$i]->product_type == 9) {
429 $fk_parent_line = $result;
466 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
481 $object_id = $object->create($user);
486 if ($object_id > 0) {
487 if (
GETPOST(
'contactid',
'int')) {
488 $result = $object->add_contact(
GETPOST(
'contactid',
'int'),
'CUSTOMER',
'external');
500 if ($object_id > 0 && !$error) {
502 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
510 } elseif ($action ==
'classifybilled' && $usercancreate) {
511 $ret = $object->classifyBilled($user);
516 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
517 $ret = $object->classifyUnBilled($user);
521 } elseif ($action ==
'setref_client' && $usercancreate) {
523 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
527 } elseif ($action ==
'setremise' && $usercancreate) {
532 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
534 if ($object->id > 0) {
535 $object->insert_discount(
GETPOST(
'remise_id'));
540 } elseif ($action ==
'setdate' && $usercancreate) {
543 $result = $object->set_date($user, $date);
547 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
548 $date_delivery =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'), 0,
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
551 $result = $object->setDeliveryDate($user, $date_delivery);
555 } elseif ($action ==
'setmode' && $usercancreate) {
556 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
560 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
562 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
563 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
565 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
566 } elseif ($action ==
'setavailability' && $usercancreate) {
567 $result = $object->availability(
GETPOST(
'availability_id'));
571 } elseif ($action ==
'setdemandreason' && $usercancreate) {
572 $result = $object->demand_reason(
GETPOST(
'demand_reason_id'));
576 } elseif ($action ==
'setconditions' && $usercancreate) {
577 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
581 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
583 $outputlangs = $langs;
584 $newlang =
GETPOST(
'lang_id',
'alpha');
585 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
586 $newlang = $object->thirdparty->default_lang;
588 if (!empty($newlang)) {
590 $outputlangs->setDefaultLang($newlang);
593 $ret = $object->fetch($object->id);
594 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
597 } elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled)) {
599 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
603 } elseif ($action ==
'setbankaccount' && $usercancreate) {
605 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
609 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
611 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
615 } elseif ($action ==
'setwarehouse' && $usercancreate) {
617 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
621 } elseif ($action ==
'setremisepercent' && $usercancreate) {
622 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
623 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
624 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
625 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
627 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
628 $vat_rate = str_replace(
'*',
'', $vat_rate);
629 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
630 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
631 foreach ($object->lines as $line) {
632 $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);
634 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
636 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
637 $remise_percent = str_replace(
'*',
'', $remise_percent);
638 foreach ($object->lines as $line) {
639 $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $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);
641 } elseif ($action ==
'addline' && $usercancreate) {
642 $langs->load(
'errors');
650 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
651 if ($prod_entry_mode ==
'free') {
655 $idprod =
GETPOST(
'idprod',
'int');
662 if (empty($remise_percent)) {
667 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
668 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
670 if (is_array($extralabelsline)) {
672 foreach ($extralabelsline as $key => $value) {
673 unset($_POST[
"options_".$key]);
677 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
678 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
681 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
682 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
685 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ==
'' && $price_ht_devise ==
'') {
686 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
690 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
694 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
697 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
698 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
702 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
703 if ($combinations =
GETPOST(
'combinations',
'array')) {
707 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
708 $idprod = $res->fk_product_child;
710 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
716 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
720 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
726 if (!empty($idprod) && $idprod > 0) {
728 $prod->fetch($idprod);
730 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
735 if (empty($tva_tx)) {
739 $pu_ht = $prod->price;
740 $pu_ttc = $prod->price_ttc;
741 $price_min = $prod->price_min;
742 $price_base_type = $prod->price_base_type;
745 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
746 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
747 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
748 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
749 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
750 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
751 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
752 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
754 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
755 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
758 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
760 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
764 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
766 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
768 if (count($prodcustprice->lines) > 0) {
769 $pu_ht =
price($prodcustprice->lines[0]->price);
770 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
771 $price_min =
price($prodcustprice->lines[0]->price_min);
772 $price_base_type = $prodcustprice->lines[0]->price_base_type;
773 $tva_tx = $prodcustprice->lines[0]->tva_tx;
774 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
775 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
777 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
778 if (empty($tva_tx)) {
785 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
787 if ($prod->prices_by_qty[0]) {
792 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
793 if ($priceforthequantityarray[
'rowid'] != $pqp) {
797 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
798 $pu_ht = $priceforthequantityarray[
'unitprice'];
800 $pu_ttc = $priceforthequantityarray[
'unitprice'];
806 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
808 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
812 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
813 if ($priceforthequantityarray[
'rowid'] != $pqp) {
817 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
818 $pu_ht = $priceforthequantityarray[
'unitprice'];
820 $pu_ttc = $priceforthequantityarray[
'unitprice'];
828 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
829 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
832 if (!empty($price_ht) || $price_ht ===
'0') {
834 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
835 } elseif ($tmpvat != $tmpprodvat) {
838 if ($price_base_type !=
'HT') {
839 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
841 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
848 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
849 $outputlangs = $langs;
851 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
852 $newlang =
GETPOST(
'lang_id',
'aZ09');
854 if (empty($newlang)) {
855 $newlang = $object->thirdparty->default_lang;
857 if (!empty($newlang)) {
859 $outputlangs->setDefaultLang($newlang);
862 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
864 $desc = $prod->description;
868 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
872 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
873 $desc = $product_desc;
875 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
879 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
882 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
883 $outputlangs = $langs;
885 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
886 $newlang =
GETPOST(
'lang_id',
'alpha');
888 if (empty($newlang)) {
889 $newlang = $object->thirdparty->default_lang;
891 if (!empty($newlang)) {
893 $outputlangs->setDefaultLang($newlang);
894 $outputlangs->load(
'products');
896 if (!empty($prod->customcode)) {
897 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
899 if (!empty($prod->customcode) && !empty($prod->country_code)) {
902 if (!empty($prod->country_code)) {
903 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
906 if (!empty($prod->customcode)) {
907 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
909 if (!empty($prod->customcode) && !empty($prod->country_code)) {
912 if (!empty($prod->country_code)) {
913 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
921 $fk_unit = $prod->fk_unit;
925 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
926 $tva_tx = str_replace(
'*',
'', $tva_tx);
927 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
928 $desc = $product_desc;
930 $fk_unit =
GETPOST(
'units',
'alpha');
931 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
939 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
940 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
949 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
950 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
954 $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);
957 $ret = $object->fetch($object->id);
958 $object->fetch_thirdparty();
960 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
962 $outputlangs = $langs;
963 $newlang =
GETPOST(
'lang_id',
'alpha');
964 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
965 $newlang = $object->thirdparty->default_lang;
967 if (!empty($newlang)) {
969 $outputlangs->setDefaultLang($newlang);
972 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
975 unset($_POST[
'prod_entry_mode']);
977 unset($_POST[
'qty']);
978 unset($_POST[
'type']);
979 unset($_POST[
'remise_percent']);
980 unset($_POST[
'price_ht']);
981 unset($_POST[
'multicurrency_price_ht']);
982 unset($_POST[
'price_ttc']);
983 unset($_POST[
'tva_tx']);
984 unset($_POST[
'product_ref']);
985 unset($_POST[
'product_label']);
986 unset($_POST[
'product_desc']);
987 unset($_POST[
'fournprice']);
988 unset($_POST[
'buying_price']);
989 unset($_POST[
'np_marginRate']);
990 unset($_POST[
'np_markRate']);
991 unset($_POST[
'dp_desc']);
992 unset($_POST[
'idprod']);
993 unset($_POST[
'units']);
995 unset($_POST[
'date_starthour']);
996 unset($_POST[
'date_startmin']);
997 unset($_POST[
'date_startsec']);
998 unset($_POST[
'date_startday']);
999 unset($_POST[
'date_startmonth']);
1000 unset($_POST[
'date_startyear']);
1001 unset($_POST[
'date_endhour']);
1002 unset($_POST[
'date_endmin']);
1003 unset($_POST[
'date_endsec']);
1004 unset($_POST[
'date_endday']);
1005 unset($_POST[
'date_endmonth']);
1006 unset($_POST[
'date_endyear']);
1012 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1021 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1028 if (preg_match(
'/\*/', $vat_rate)) {
1033 $vat_rate = str_replace(
'*',
'', $vat_rate);
1034 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1035 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1042 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1043 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1045 if (is_array($extralabelsline)) {
1046 foreach ($extralabelsline as $key => $value) {
1047 unset($_POST[
"options_".$key]);
1052 $special_code =
GETPOST(
'special_code');
1060 $productid =
GETPOST(
'productid',
'int');
1061 if (!empty($productid)) {
1063 $product->fetch($productid);
1065 $type = $product->type;
1067 $price_min = $product->price_min;
1068 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1069 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1074 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 - $remise_percent / 100) <
price2num($price_min)))) {
1075 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)),
null,
'errors');
1077 $action =
'editline';
1081 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1085 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1087 $action =
'editline';
1092 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1094 $action =
'editline';
1098 if (empty($user->rights->margins->creer)) {
1099 foreach ($object->lines as &$line) {
1100 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1101 $fournprice = $line->fk_fournprice;
1102 $buyingprice = $line->pa_ht;
1107 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $description, $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate,
'HT', $info_bits, $date_start, $date_end, $type,
GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options,
GETPOST(
'units'), $pu_ht_devise);
1110 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1112 $outputlangs = $langs;
1114 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1115 $newlang =
GETPOST(
'lang_id',
'aZ09');
1117 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1118 $newlang = $object->thirdparty->default_lang;
1120 if (!empty($newlang)) {
1121 $outputlangs =
new Translate(
"", $conf);
1122 $outputlangs->setDefaultLang($newlang);
1125 $ret = $object->fetch($object->id);
1126 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1129 unset($_POST[
'qty']);
1130 unset($_POST[
'type']);
1131 unset($_POST[
'productid']);
1132 unset($_POST[
'remise_percent']);
1133 unset($_POST[
'price_ht']);
1134 unset($_POST[
'multicurrency_price_ht']);
1135 unset($_POST[
'price_ttc']);
1136 unset($_POST[
'tva_tx']);
1137 unset($_POST[
'product_ref']);
1138 unset($_POST[
'product_label']);
1139 unset($_POST[
'product_desc']);
1140 unset($_POST[
'fournprice']);
1141 unset($_POST[
'buying_price']);
1143 unset($_POST[
'date_starthour']);
1144 unset($_POST[
'date_startmin']);
1145 unset($_POST[
'date_startsec']);
1146 unset($_POST[
'date_startday']);
1147 unset($_POST[
'date_startmonth']);
1148 unset($_POST[
'date_startyear']);
1149 unset($_POST[
'date_endhour']);
1150 unset($_POST[
'date_endmin']);
1151 unset($_POST[
'date_endsec']);
1152 unset($_POST[
'date_endday']);
1153 unset($_POST[
'date_endmonth']);
1154 unset($_POST[
'date_endyear']);
1159 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1160 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1162 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1163 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1165 $qualified_for_stock_change = 0;
1166 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1167 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1169 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1173 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1174 if (!$idwarehouse || $idwarehouse == -1) {
1176 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1182 $locationTarget =
'';
1184 $result = $object->valid($user, $idwarehouse);
1189 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1192 GETPOST(
'generate_deposit',
'alpha') ==
'on' && ! empty($deposit_percent_from_payment_terms)
1193 && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)
1195 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1198 $forceFields = array();
1201 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1208 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1219 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1220 $outputlangs = $langs;
1223 $newlang =
GETPOST(
'lang_id',
'aZ09');
1226 $newlang = $object->thirdparty->default_lang;
1228 if (!empty($newlang)) {
1229 $outputlangs =
new Translate(
"", $conf);
1230 $outputlangs->setDefaultLang($newlang);
1232 $model = $object->model_pdf;
1233 $ret = $object->fetch($id);
1235 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1238 $deposit->fetch($deposit->id);
1239 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1243 if ($locationTarget) {
1244 header(
'Location: ' . $locationTarget);
1255 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1257 $idwarehouse =
GETPOST(
'idwarehouse');
1259 $qualified_for_stock_change = 0;
1260 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1261 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1263 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1267 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1268 if (!$idwarehouse || $idwarehouse == -1) {
1270 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1276 $result = $object->setDraft($user, $idwarehouse);
1279 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1280 $outputlangs = $langs;
1282 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1283 $newlang =
GETPOST(
'lang_id',
'aZ09');
1285 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1286 $newlang = $object->thirdparty->default_lang;
1288 if (!empty($newlang)) {
1289 $outputlangs =
new Translate(
"", $conf);
1290 $outputlangs->setDefaultLang($newlang);
1292 $model = $object->model_pdf;
1293 $ret = $object->fetch($id);
1295 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1299 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1300 $result = $object->cloture($user);
1304 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1305 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1307 $qualified_for_stock_change = 0;
1308 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1309 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1311 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1315 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1316 if (!$idwarehouse || $idwarehouse == -1) {
1318 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1324 $result = $object->cancel($idwarehouse);
1332 if ($action ==
'update_extras') {
1336 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1343 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1351 $action =
'edit_extras';
1356 if ($action ==
'import_lines_from_object'
1360 $fromElement =
GETPOST(
'fromelement');
1361 $fromElementid =
GETPOST(
'fromelementid');
1362 $importLines =
GETPOST(
'line_checkbox');
1364 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1365 if ($fromElement ==
'commande') {
1367 $lineClassName =
'OrderLine';
1368 } elseif ($fromElement ==
'propal') {
1369 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1370 $lineClassName =
'PropaleLigne';
1372 $nextRang = count($object->lines) + 1;
1375 foreach ($importLines as $lineId) {
1376 $lineId = intval($lineId);
1377 $originLine =
new $lineClassName($db);
1378 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1379 $originLine->fetch_optionals();
1380 $desc = $originLine->desc;
1381 $pu_ht = $originLine->subprice;
1382 $qty = $originLine->qty;
1383 $txtva = $originLine->tva_tx;
1384 $txlocaltax1 = $originLine->localtax1_tx;
1385 $txlocaltax2 = $originLine->localtax2_tx;
1386 $fk_product = $originLine->fk_product;
1387 $remise_percent = $originLine->remise_percent;
1388 $date_start = $originLine->date_start;
1389 $date_end = $originLine->date_end;
1391 $info_bits = $originLine->info_bits;
1392 $fk_remise_except = $originLine->fk_remise_except;
1393 $price_base_type =
'HT';
1395 $type = $originLine->product_type;
1396 $rang = $nextRang++;
1397 $special_code = $originLine->special_code;
1398 $origin = $originLine->element;
1399 $origin_id = $originLine->id;
1400 $fk_parent_line = 0;
1401 $fk_fournprice = $originLine->fk_fournprice;
1402 $pa_ht = $originLine->pa_ht;
1403 $label = $originLine->label;
1404 $array_options = $originLine->array_options;
1405 $situation_percent = 100;
1407 $fk_unit = $originLine->fk_unit;
1408 $pu_ht_devise = $originLine->multicurrency_subprice;
1410 $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);
1429 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1432 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1433 $permissiontoadd = $usercancreate;
1434 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1437 $triggersendname =
'ORDER_SENTBYMAIL';
1439 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1440 $trackid =
'ord'.$object->id;
1441 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1444 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1445 if ($action ==
'addcontact') {
1446 if ($object->id > 0) {
1449 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1453 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1456 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1457 $langs->load(
"errors");
1458 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1463 } elseif ($action ==
'swapstatut') {
1465 if ($object->id > 0) {
1466 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1470 } elseif ($action ==
'deletecontact') {
1472 $result = $object->delete_contact($lineid);
1475 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1489 $title = $langs->trans(
'Order').
" - ".$langs->trans(
'Card');
1490 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1497 if (!empty($conf->project->enabled)) {
1502 if ($action ==
'create' && $usercancreate) {
1507 $res = $soc->fetch($socid);
1510 $remise_absolue = 0;
1512 $currency_code = $conf->currency;
1514 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1515 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1516 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1518 if (!empty($origin) && !empty($originid)) {
1520 $element = $subelement = $origin;
1522 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1523 $element = $regs[1];
1524 $subelement = $regs[2];
1527 if ($element ==
'project') {
1528 $projectid = $originid;
1530 if (!$cond_reglement_id) {
1531 $cond_reglement_id = $soc->cond_reglement_id;
1533 if (!$deposit_percent) {
1534 $deposit_percent = $soc->deposit_percent;
1536 if (!$mode_reglement_id) {
1537 $mode_reglement_id = $soc->mode_reglement_id;
1539 if (!$remise_percent) {
1540 $remise_percent = $soc->remise_percent;
1544 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ODER) ?-1 :
'') : $dateorder);
1548 if ($element ==
'order' || $element ==
'commande') {
1549 $element = $subelement =
'commande';
1550 } elseif ($element ==
'propal') {
1551 $element =
'comm/propal';
1552 $subelement =
'propal';
1553 } elseif ($element ==
'contract') {
1554 $element = $subelement =
'contrat';
1559 $classname = ucfirst($subelement);
1560 $objectsrc =
new $classname($db);
1561 $objectsrc->fetch($originid);
1562 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1563 $objectsrc->fetch_lines();
1565 $objectsrc->fetch_thirdparty();
1568 $objectsrc->fetch_optionals();
1569 $object->array_options = $objectsrc->array_options;
1571 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1572 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1574 $soc = $objectsrc->thirdparty;
1575 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1576 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1577 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1578 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1579 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1580 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1581 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1582 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1583 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1584 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1585 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1587 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1588 if (empty($date_delivery)) {
1589 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1592 if (!empty($conf->multicurrency->enabled)) {
1593 if (!empty($objectsrc->multicurrency_code)) {
1594 $currency_code = $objectsrc->multicurrency_code;
1596 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1597 $currency_tx = $objectsrc->multicurrency_tx;
1601 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1602 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1605 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1608 $cond_reglement_id = $soc->cond_reglement_id;
1609 $deposit_percent = $soc->deposit_percent;
1610 $mode_reglement_id = $soc->mode_reglement_id;
1611 $fk_account = $soc->fk_account;
1612 $availability_id = 0;
1613 $shipping_method_id = $soc->shipping_method_id;
1614 $warehouse_id = $soc->fk_warehouse;
1615 $demand_reason_id = $soc->demand_reason_id;
1616 $remise_percent = $soc->remise_percent;
1617 $remise_absolue = 0;
1618 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1620 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1621 $currency_code = $soc->multicurrency_code;
1624 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1625 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1629 if ($soc->fk_warehouse > 0) {
1630 $warehouse_id = $soc->fk_warehouse;
1632 if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1633 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1634 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1636 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1637 $warehouse_id = $user->fk_warehouse;
1641 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1642 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1643 print
'<input type="hidden" name="action" value="add">';
1644 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1645 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1646 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1647 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1648 if (!empty($currency_tx)) {
1649 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1654 print
'<table class="border centpercent">';
1657 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1660 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1661 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1662 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1664 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1670 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1673 print $soc->getNomUrl(1,
'customer');
1674 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1678 print
img_picto(
'',
'company').$form->select_company(
'',
'socid',
'((s.client = 1 OR s.client = 2 OR s.client = 3) AND s.status=1)',
'SelectThirdParty', 0, 0,
null, 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1680 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1681 print
'<script type="text/javascript">
1682 $(document).ready(function() {
1683 $("#socid").change(function() {
1684 console.log("We have changed the company - Reload page");
1685 var socid = $(this).val();
1687 $("input[name=action]").val("create");
1688 $("form[name=crea_commande]").submit();
1693 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>';
1701 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1702 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1703 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1707 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1709 $absolute_discount = $soc->getAvailableDiscounts();
1713 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1714 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1720 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1721 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1725 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1726 print
'<td colspan="3">';
1727 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1728 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1733 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1734 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1735 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id')?
GETPOST(
'availability_id'):$availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1739 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1740 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1741 $form->select_conditions_paiements((
GETPOSTISSET(
'cond_reglement_id')?
GETPOST(
'cond_reglement_id'):$cond_reglement_id),
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1745 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1746 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1747 $form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id')?
GETPOST(
'mode_reglement_id'):$mode_reglement_id),
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
1751 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && !empty($conf->banque->enabled)) {
1752 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1753 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
GETPOSTISSET(
'fk_account')?
GETPOST(
'fk_account'):$fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1759 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1760 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"').$form->selectShippingMethod((
GETPOSTISSET(
'shipping_method_id')?
GETPOST(
'shipping_method_id'):$shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1765 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1766 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1768 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1769 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');
1774 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1775 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1776 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id')?
GETPOST(
'demand_reason_id'):$demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1782 if (!empty($conf->project->enabled)) {
1783 $langs->load(
"projects");
1785 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1786 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (
GETPOSTISSET(
'projectid')?
GETPOST(
'projectid'):$projectid),
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1787 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>';
1793 if (!empty($conf->incoterm->enabled)) {
1795 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $objectsrc->label_incoterms, 1).
'</label></td>';
1796 print
'<td class="maxwidthonsmartphone">';
1797 $incoterm_id =
GETPOST(
'incoterm_id');
1798 $incoterm_location =
GETPOST(
'location_incoterms');
1799 if (empty($incoterm_id)) {
1800 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1801 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1803 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1809 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1815 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1816 print $hookmanager->resPrint;
1817 if (empty($reshook)) {
1818 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1820 $tpExtrafields =
new Extrafields($db);
1821 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1822 if ($soc->fetch_optionals() > 0) {
1823 $object->array_options = array_merge($object->array_options, $soc->array_options);
1827 print $object->showOptionals($extrafields,
'create',
$parameters);
1831 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1833 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1835 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1836 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1837 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1841 if (!empty($conf->multicurrency->enabled)) {
1843 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1844 print
'<td class="maxwidthonsmartphone">';
1845 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code')?
GETPOST(
'multicurrency_code'):$currency_code),
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1851 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1854 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1855 print $doleditor->Create(1);
1860 if (empty($user->socid)) {
1862 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1865 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1866 print $doleditor->Create(1);
1871 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1873 if ($origin ==
'contrat') {
1875 $objectsrc->remise_absolue = $remise_absolue;
1876 $objectsrc->remise_percent = $remise_percent;
1877 $objectsrc->update_price(1);
1880 print
"\n<!-- ".$classname.
" info -->";
1882 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1883 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1884 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1885 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1886 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1888 switch ($classname) {
1890 $newclassname =
'CommercialProposal';
1893 $newclassname =
'Order';
1896 $newclassname =
'Sending';
1899 $newclassname =
'Contract';
1902 $newclassname = $classname;
1905 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1908 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1909 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1910 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1911 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1914 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1915 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1918 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1920 if (!empty($conf->multicurrency->enabled)) {
1921 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1922 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
1923 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
1931 print
$form->buttonsSaveCancel(
"CreateDraft");
1934 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1935 $title = $langs->trans(
'ProductsAndServices');
1938 print
'<div class="div-table-responsive-no-min">';
1939 print
'<table class="noborder centpercent">';
1941 $objectsrc->printOriginLinesList(
'', $selectedLines);
1952 if ($object->id > 0) {
1953 $product_static =
new Product($db);
1956 $soc->fetch($object->socid);
1958 $author =
new User($db);
1959 $author->fetch($object->user_author_id);
1961 $object->fetch_thirdparty();
1962 $res = $object->fetch_optionals();
1965 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
1970 if ($action ==
'delete') {
1971 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
1975 if ($action ==
'validate') {
1977 $ref = substr($object->ref, 1, 4);
1978 if ($ref ==
'PROV' || $ref ==
'') {
1979 $numref = $object->getNextNumRef($soc);
1980 if (empty($numref)) {
1985 $numref = $object->ref;
1988 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
1989 if (!empty($conf->notification->enabled)) {
1990 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1991 $notify =
new Notify($db);
1993 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
1996 $qualified_for_stock_change = 0;
1997 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1998 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2000 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2003 $formquestion = array();
2004 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2005 $langs->load(
"stocks");
2006 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2009 if ($conf->browser->name ==
'ie') {
2012 $formquestion = array(
2016 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockDecrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse',
'int') ?
GETPOST(
'idwarehouse',
'int') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2022 foreach ($object->lines as $line) {
2023 $res = $line->fetch_product();
2025 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2031 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2034 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2036 if (! empty($deposit_percent_from_payment_terms) && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)) {
2037 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2039 $object->fetchObjectLinked();
2041 $eligibleForDepositGeneration =
true;
2043 if (array_key_exists(
'facture', $object->linkedObjects)) {
2044 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2046 $eligibleForDepositGeneration =
false;
2052 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2053 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2054 $proposal->fetchObjectLinked();
2056 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2057 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2059 $eligibleForDepositGeneration =
false;
2068 if ($eligibleForDepositGeneration) {
2069 $formquestion[] = array(
2070 'type' =>
'checkbox',
2072 'name' =>
'generate_deposit',
2073 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2076 $formquestion[] = array(
2078 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2080 'label' => $langs->trans(
'DateInvoice'),
2085 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2086 $formquestion[] = array(
2088 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2089 'name' =>
'date_pointoftax',
2090 'label' => $langs->trans(
'DatePointOfTax'),
2097 $form->select_conditions_paiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2098 $paymentTermsSelect = ob_get_clean();
2100 $formquestion[] = array(
2102 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2103 'name' =>
'cond_reglement_id',
2104 'label' => $langs->trans(
'PaymentTerm'),
2105 'value' => $paymentTermsSelect
2108 $formquestion[] = array(
2109 'type' =>
'checkbox',
2110 'tdclass' =>
'showonlyifgeneratedeposit',
2111 'name' =>
'validate_generated_deposit',
2112 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2115 $formquestion[] = array(
2116 'type' =>
'onecolumn',
2119 $(document).ready(function() {
2120 $("[name=generate_deposit]").change(function () {
2121 let $self = $(this);
2122 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2124 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2140 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2145 if ($action ==
'modif') {
2146 $qualified_for_stock_change = 0;
2147 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2148 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2150 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2153 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2154 $formquestion = array();
2155 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2156 $langs->load(
"stocks");
2157 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2160 if ($conf->browser->name ==
'ie') {
2163 $formquestion = array(
2167 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2171 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2177 if ($action ==
'shipped') {
2178 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2184 if ($action ==
'cancel') {
2185 $qualified_for_stock_change = 0;
2186 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2187 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2189 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2192 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2193 $formquestion = array();
2194 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2195 $langs->load(
"stocks");
2196 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2199 if ($conf->browser->name ==
'ie') {
2202 $formquestion = array(
2206 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2210 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2214 if ($action ==
'ask_deleteline') {
2215 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2219 if ($action ==
'clone') {
2221 $formquestion = array(
2222 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.client=1 OR s.client = 2 OR s.client=3)',
'', 0, 0,
null, 0,
'maxwidth300'))
2224 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2230 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2231 if (empty($reshook)) {
2233 } elseif ($reshook > 0) {
2243 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2245 $morehtmlref =
'<div class="refidno">';
2247 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2248 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'',
null,
null,
'', 1);
2250 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$soc->getNomUrl(1,
'customer');
2251 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2252 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2255 if (!empty($conf->project->enabled)) {
2256 $langs->load(
"projects");
2257 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2258 if ($usercancreate) {
2259 if ($action !=
'classify') {
2260 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2262 if ($action ==
'classify') {
2264 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2265 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2266 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2267 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', 0, 0, 1, 0, 1, 0, 0,
'', 1, 0,
'maxwidth500');
2268 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2269 $morehtmlref .=
'</form>';
2271 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2274 if (!empty($object->fk_project)) {
2276 $proj->fetch($object->fk_project);
2277 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2279 $morehtmlref .=
' - '.$proj->title;
2286 $morehtmlref .=
'</div>';
2289 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2292 print
'<div class="fichecenter">';
2293 print
'<div class="fichehalfleft">';
2294 print
'<div class="underbanner clearboth"></div>';
2296 print
'<table class="border tableforfield centpercent">';
2298 if ($soc->outstanding_limit) {
2300 print
'<tr><td class="titlefield">';
2301 print $langs->trans(
'OutstandingBill');
2302 print
'</td><td class="valuefield">';
2303 $arrayoutstandingbills = $soc->getOutstandingBills();
2304 print
price($arrayoutstandingbills[
'opened']).
' / ';
2305 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2311 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2312 $filterabsolutediscount =
"fk_facture_source IS NULL";
2313 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2315 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2316 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2319 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2320 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2321 $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>';
2323 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2325 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2326 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2327 $absolute_discount =
price2num($absolute_discount,
'MT');
2328 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2332 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2333 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2340 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2341 print
'</td><td class="valuefield">';
2342 if ($action ==
'editdate') {
2343 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2344 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2345 print
'<input type="hidden" name="action" value="setdate">';
2346 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2347 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2350 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2351 if ($object->hasDelay() && empty($object->delivery_date)) {
2352 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2360 $editenable = $usercancreate;
2361 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2362 print
'</td><td class="valuefield">';
2363 if ($action ==
'editdate_livraison') {
2364 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2365 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2366 print
'<input type="hidden" name="action" value="setdate_livraison">';
2367 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2368 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2371 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2372 if ($object->hasDelay() && !empty($object->delivery_date)) {
2373 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2380 print
'<tr class="fielddeliverydelay"><td>';
2381 $editenable = $usercancreate;
2382 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2383 print
'</td><td class="valuefield">';
2384 if ($action ==
'editavailability') {
2385 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2387 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2394 $editenable = $usercancreate;
2395 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2396 print
'</td><td class="valuefield">';
2397 if ($action ==
'editshippingmethod') {
2398 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2400 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2407 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2408 $langs->load(
'stocks');
2409 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2412 $editenable = $usercancreate;
2413 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2414 print
'</td><td class="valuefield">';
2415 if ($action ==
'editwarehouse') {
2416 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2418 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2426 $editenable = $usercancreate;
2427 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2428 print
'</td><td class="valuefield">';
2429 if ($action ==
'editdemandreason') {
2430 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2432 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2438 $editenable = $usercancreate;
2439 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2440 print
'</td><td class="valuefield">';
2441 if ($action ==
'editconditions') {
2442 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2444 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2452 $editenable = $usercancreate;
2453 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2454 print
'</td><td class="valuefield">';
2455 if ($action ==
'editmode') {
2456 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2458 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2463 if (!empty($conf->multicurrency->enabled)) {
2468 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2469 print
'</td><td class="valuefield">';
2470 if ($action ==
'editmulticurrencycode') {
2471 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2473 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2478 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2481 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2482 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2483 print
'</td><td class="valuefield">';
2484 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2485 if ($action ==
'actualizemulticurrencyrate') {
2488 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2490 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2491 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2492 print
'<div class="inline-block"> ';
2493 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2515 $tmparray = $object->getTotalWeightVolume();
2516 $totalWeight = $tmparray[
'weight'];
2517 $totalVolume = $tmparray[
'volume'];
2519 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2520 print
'<td class="valuefield">';
2521 print
showDimensionInBestUnit($totalWeight, 0,
"weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT :
'no');
2525 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2526 print
'<td class="valuefield">';
2527 print
showDimensionInBestUnit($totalVolume, 0,
"volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT :
'no');
2534 if (!empty($conf->incoterm->enabled)) {
2536 $editenable = $usercancreate;
2537 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2539 print
'<td class="valuefield">';
2540 if ($action !=
'editincoterm') {
2541 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2543 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2549 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && !empty($conf->banque->enabled)) {
2551 $editenable = $usercancreate;
2552 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2553 print
'</td><td class="valuefield">';
2554 if ($action ==
'editbankaccount') {
2555 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2557 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2564 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2569 print
'<div class="fichehalfright">';
2570 print
'<div class="underbanner clearboth"></div>';
2572 print
'<table class="border tableforfield centpercent">';
2574 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
2576 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2577 print
'<td class="valuefield nowrap right amountcard">'.price($object->multicurrency_total_ht,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2581 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2582 print
'<td class="valuefield nowrap right amountcard">'.price($object->multicurrency_total_tva,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2586 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2587 print
'<td class="valuefield nowrap right amountcard">'.price($object->multicurrency_total_ttc,
'', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).
'</td>';
2593 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2594 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2596 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2597 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2600 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td class="valuefield nowrap right amountcard">'.
price($object->total_tva, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2603 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2604 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2605 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2607 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2608 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2609 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2613 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td class="valuefield nowrap right amountcard">'.
price($object->total_ttc, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2621 if (!empty($conf->margin->enabled)) {
2622 $formmargin->displayMarginInfos($object);
2629 print
'<div class="clearboth"></div><br>';
2631 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2632 $blocname =
'contacts';
2633 $title = $langs->trans(
'ContactsAddresses');
2634 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2637 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2638 $blocname =
'notes';
2639 $title = $langs->trans(
'Notes');
2640 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2646 $result = $object->getLinesArray();
2648 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2649 <input type="hidden" name="token" value="' .
newToken().
'">
2650 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2651 <input type="hidden" name="mode" value="">
2652 <input type="hidden" name="page_y" value="">
2653 <input type="hidden" name="id" value="' . $object->id.
'">';
2656 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2659 print
'<div class="div-table-responsive-no-min">';
2660 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2663 if (!empty($object->lines)) {
2664 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2667 $numlines = count($object->lines);
2673 if ($action !=
'editline') {
2678 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2679 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2680 if (empty($reshook))
2681 $object->formAddObjectLine(1, $mysoc, $soc);
2694 if ($action !=
'presend' && $action !=
'editline') {
2695 print
'<div class="tabsAction">';
2699 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2700 if (empty($reshook)) {
2703 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2707 if (empty($user->socid)) {
2708 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2710 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2712 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2718 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2719 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2723 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2735 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2736 if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) && $object->statut >
Commande::STATUS_DRAFT && $object->statut <
Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) {
2737 if ($usercancreatepurchaseorder) {
2738 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2744 if (!empty($conf->ficheinter->enabled)) {
2745 $langs->load(
"interventions");
2748 if ($user->rights->ficheinter->creer) {
2749 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2751 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2758 $langs->load(
"contracts");
2760 if ($user->rights->contrat->creer) {
2761 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2768 $numshipping = $object->nb_expedition();
2771 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2772 if ($user->rights->expedition->creer) {
2773 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2775 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2778 $langs->load(
"errors");
2779 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2786 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2791 if (
isModEnabled(
'facture') && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2792 print
dolGetButtonAction(
'', $langs->trans(
'CreateBill'),
'default', DOL_URL_ROOT.
'/compta/facture/card.php?action=create&token='.
newToken().
'&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2794 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2795 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2799 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2800 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2804 if ($usercancreate) {
2805 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2810 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2814 if ($usercandelete) {
2815 if ($numshipping == 0) {
2816 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2818 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2826 if (
GETPOST(
'modelselected')) {
2827 $action =
'presend';
2830 if ($action !=
'presend') {
2831 print
'<div class="fichecenter"><div class="fichehalfleft">';
2832 print
'<a name="builddoc"></a>';
2835 $relativepath = $objref.
'/'.$objref.
'.pdf';
2836 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2837 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2838 $genallowed = $usercanread;
2839 $delallowed = $usercancreate;
2840 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2844 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'order'));
2846 $compatibleImportElementsList =
false;
2849 $compatibleImportElementsList = array(
'commande',
'propal');
2851 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2854 $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
2855 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2856 $useonlinepayment = 0;
2859 print
'<br><!-- Link to pay -->';
2860 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
2861 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
2864 print
'</div><div class="fichehalfright">';
2867 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2869 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
2871 print
'</div></div>';
2875 $modelmail =
'order_send';
2876 $defaulttopic =
'SendOrderRef';
2877 $diroutput = $conf->commande->multidir_output[$object->entity];
2878 $trackid =
'ord'.$object->id;
2880 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';