38 require
'../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
43 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
48 if (!empty($conf->propal->enabled)) {
49 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
51 if (!empty($conf->project->enabled)) {
52 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
58 if (!empty($conf->variants->enabled)) {
59 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
63 $langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
64 if (!empty($conf->incoterm->enabled)) {
65 $langs->load(
'incoterm');
67 if (!empty($conf->margin->enabled)) {
68 $langs->load(
'margins');
70 if (!empty($conf->productbatch->enabled)) {
71 $langs->load(
"productbatch");
76 $socid =
GETPOST(
'socid',
'int');
77 $action =
GETPOST(
'action',
'aZ09');
78 $cancel =
GETPOST(
'cancel',
'alpha');
79 $confirm =
GETPOST(
'confirm',
'alpha');
80 $lineid =
GETPOST(
'lineid',
'int');
81 $contactid =
GETPOST(
'contactid',
'int');
82 $projectid =
GETPOST(
'projectid',
'int');
83 $origin =
GETPOST(
'origin',
'alpha');
85 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
88 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
89 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
90 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
93 if (!empty($user->socid)) {
94 $socid = $user->socid;
98 $hookmanager->initHooks(array(
'ordercard',
'globalcard'));
106 $extrafields->fetch_name_optionals_label($object->table_element);
109 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
111 $usercanread = $user->hasRight(
"commande",
"lire");
112 $usercancreate = $user->hasRight(
"commande",
"creer");
113 $usercandelete = $user->hasRight(
"commande",
"supprimer");
115 $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)));
116 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->order_advance->validate)));
117 $usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->commande->order_advance->annuler)));
118 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send);
120 $usercancreatepurchaseorder = ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer"));
122 $permissionnote = $usercancreate;
123 $permissiondellink = $usercancreate;
124 $permissiontoadd = $usercancreate;
128 $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'));
135 $parameters = array(
'socid' => $socid);
137 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
142 if (empty($reshook)) {
143 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
145 if (empty($backtopage) || ($cancel && empty($id))) {
146 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
147 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
148 $backtopage = $backurlforlist;
150 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
156 if (!empty($backtopageforcancel)) {
157 header(
"Location: ".$backtopageforcancel);
159 } elseif (!empty($backtopage)) {
160 header(
"Location: ".$backtopage);
166 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
168 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
170 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
173 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
174 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
177 if ($object->id > 0) {
179 $orig = clone $object;
181 $result = $object->createFromClone($user, $socid);
183 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
192 } elseif ($action ==
'reopen' && $usercancreate) {
195 $result = $object->set_reopen($user);
202 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
204 $result = $object->delete($user);
206 header(
'Location: list.php?restore_lastsearch_values=1');
211 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
213 $result = $object->deleteline($user, $lineid);
216 $object->line_order(
true);
218 $outputlangs = $langs;
220 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
221 $newlang =
GETPOST(
'lang_id',
'aZ09');
223 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
224 $newlang = $object->thirdparty->default_lang;
226 if (!empty($newlang)) {
228 $outputlangs->setDefaultLang($newlang);
230 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
231 $ret = $object->fetch($object->id);
232 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
235 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
240 } elseif ($action ==
'classin' && $usercancreate) {
242 $object->setProject(
GETPOST(
'projectid',
'int'));
243 } elseif ($action ==
'add' && $usercancreate) {
246 $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'));
247 $selectedLines =
GETPOST(
'toselect',
'array');
249 if ($datecommande ==
'') {
250 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')), null,
'errors');
256 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")), null,
'errors');
262 $object->socid = $socid;
263 $object->fetch_thirdparty();
267 $object->date_commande = $datecommande;
268 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
269 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
270 $object->source =
GETPOST(
'source_id');
271 $object->fk_project =
GETPOST(
'projectid',
'int');
272 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
273 $object->model_pdf =
GETPOST(
'model');
274 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
275 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
276 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
277 $object->fk_account =
GETPOST(
'fk_account',
'int');
278 $object->availability_id =
GETPOST(
'availability_id');
279 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
280 $object->date_livraison = $date_delivery;
281 $object->delivery_date = $date_delivery;
282 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
283 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
284 $object->fk_delivery_address =
GETPOST(
'fk_address');
285 $object->contact_id =
GETPOST(
'contactid');
286 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
287 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
288 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
289 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
292 $ret = $extrafields->setOptionalsFromPost(null, $object);
299 if (!empty($origin) && !empty($originid)) {
301 $element = $subelement = $origin;
303 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
304 $element = $regs [1];
305 $subelement = $regs [2];
309 if ($element ==
'order') {
310 $element = $subelement =
'commande';
312 if ($element ==
'propal') {
313 $element =
'comm/propal';
314 $subelement =
'propal';
316 if ($element ==
'contract') {
317 $element = $subelement =
'contrat';
320 $object->origin = $origin;
321 $object->origin_id = $originid;
324 $object->linked_objects [$object->origin] = $object->origin_id;
325 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
326 if (!empty($other_linked_objects)) {
327 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
331 $object_id = $object->create($user);
333 if ($object_id > 0) {
336 $classname = ucfirst($subelement);
337 $srcobject =
new $classname($db);
339 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
340 $result = $srcobject->fetch($object->origin_id);
342 $lines = $srcobject->lines;
343 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
344 $srcobject->fetch_lines();
345 $lines = $srcobject->lines;
349 $num = count($lines);
351 for ($i = 0; $i < $num; $i++) {
352 if (!in_array($lines[$i]->
id, $selectedLines)) {
356 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
357 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
358 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
362 $date_start = $lines[$i]->date_debut_prevue;
363 if ($lines[$i]->date_debut_reel) {
364 $date_start = $lines[$i]->date_debut_reel;
366 if ($lines[$i]->date_start) {
367 $date_start = $lines[$i]->date_start;
369 $date_end = $lines[$i]->date_fin_prevue;
370 if ($lines[$i]->date_fin_reel) {
371 $date_end = $lines[$i]->date_fin_reel;
373 if ($lines[$i]->date_end) {
374 $date_end = $lines[$i]->date_end;
378 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
383 if (method_exists($lines[$i],
'fetch_optionals')) {
384 $lines[$i]->fetch_optionals();
385 $array_options = $lines[$i]->array_options;
388 $tva_tx = $lines[$i]->tva_tx;
389 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
390 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
393 $result = $object->addline(
395 $lines[$i]->subprice,
398 $lines[$i]->localtax1_tx,
399 $lines[$i]->localtax2_tx,
400 $lines[$i]->fk_product,
401 $lines[$i]->remise_percent,
402 $lines[$i]->info_bits,
403 $lines[$i]->fk_remise_except,
410 $lines[$i]->special_code,
412 $lines[$i]->fk_fournprice,
427 if ($result > 0 && $lines[$i]->product_type == 9) {
428 $fk_parent_line = $result;
463 $parameters = array(
'objFrom' => $srcobject);
465 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
479 $object_id = $object->create($user);
484 if ($object_id > 0) {
485 if (
GETPOST(
'contactid',
'int')) {
486 $result = $object->add_contact(
GETPOST(
'contactid',
'int'),
'CUSTOMER',
'external');
498 if ($object_id > 0 && !$error) {
500 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
508 } elseif ($action ==
'classifybilled' && $usercancreate) {
509 $ret = $object->classifyBilled($user);
514 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
515 $ret = $object->classifyUnBilled($user);
519 } elseif ($action ==
'setref_client' && $usercancreate) {
521 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
525 } elseif ($action ==
'setremise' && $usercancreate) {
530 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
532 if ($object->id > 0) {
533 $object->insert_discount(
GETPOST(
'remise_id'));
538 } elseif ($action ==
'setdate' && $usercancreate) {
541 $result = $object->set_date($user, $date);
545 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
546 $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'));
549 $result = $object->setDeliveryDate($user, $date_delivery);
553 } elseif ($action ==
'setmode' && $usercancreate) {
554 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
558 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
560 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
561 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
563 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
564 } elseif ($action ==
'setavailability' && $usercancreate) {
565 $result = $object->availability(
GETPOST(
'availability_id'));
569 } elseif ($action ==
'setdemandreason' && $usercancreate) {
570 $result = $object->demand_reason(
GETPOST(
'demand_reason_id'));
574 } elseif ($action ==
'setconditions' && $usercancreate) {
575 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
579 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
581 $outputlangs = $langs;
582 $newlang =
GETPOST(
'lang_id',
'alpha');
583 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
584 $newlang = $object->thirdparty->default_lang;
586 if (!empty($newlang)) {
588 $outputlangs->setDefaultLang($newlang);
591 $ret = $object->fetch($object->id);
592 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
595 } elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled)) {
597 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
601 } elseif ($action ==
'setbankaccount' && $usercancreate) {
603 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
607 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
609 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
613 } elseif ($action ==
'setwarehouse' && $usercancreate) {
615 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
619 } elseif ($action ==
'setremisepercent' && $usercancreate) {
620 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
621 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
622 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
623 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
625 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
626 $vat_rate = str_replace(
'*',
'', $vat_rate);
627 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
628 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
629 foreach ($object->lines as $line) {
630 $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);
632 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
634 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
635 $remise_percent = str_replace(
'*',
'', $remise_percent);
636 foreach ($object->lines as $line) {
637 $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);
639 } elseif ($action ==
'addline' && $usercancreate) {
640 $langs->load(
'errors');
648 $prod_entry_mode =
GETPOST(
'prod_entry_mode');
649 if ($prod_entry_mode ==
'free') {
653 $idprod =
GETPOST(
'idprod',
'int');
660 if (empty($remise_percent)) {
665 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
666 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
668 if (is_array($extralabelsline)) {
670 foreach ($extralabelsline as $key => $value) {
671 unset($_POST[
"options_".$key]);
675 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
676 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
679 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
680 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')), null,
'errors');
683 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ==
'' && $price_ht_devise ==
'') {
684 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")), null,
'errors');
688 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
692 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
695 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
696 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')), null,
'errors');
700 if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode !=
'free') {
701 if ($combinations =
GETPOST(
'combinations',
'array')) {
705 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
706 $idprod = $res->fk_product_child;
708 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'), null,
'errors');
714 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
718 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
724 if (!empty($idprod) && $idprod > 0) {
726 $prod->fetch($idprod);
728 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
733 if (empty($tva_tx)) {
737 $pu_ht = $prod->price;
738 $pu_ttc = $prod->price_ttc;
739 $price_min = $prod->price_min;
740 $price_base_type = $prod->price_base_type;
743 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
744 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
745 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
746 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
747 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
748 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
749 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
750 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
752 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
753 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
756 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
758 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
762 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
764 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
766 if (count($prodcustprice->lines) > 0) {
767 $pu_ht =
price($prodcustprice->lines[0]->price);
768 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
769 $price_min =
price($prodcustprice->lines[0]->price_min);
770 $price_base_type = $prodcustprice->lines[0]->price_base_type;
771 $tva_tx = $prodcustprice->lines[0]->tva_tx;
772 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
773 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
775 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
776 if (empty($tva_tx)) {
783 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
785 if ($prod->prices_by_qty[0]) {
790 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
791 if ($priceforthequantityarray[
'rowid'] != $pqp) {
795 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
796 $pu_ht = $priceforthequantityarray[
'unitprice'];
798 $pu_ttc = $priceforthequantityarray[
'unitprice'];
804 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
806 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
810 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
811 if ($priceforthequantityarray[
'rowid'] != $pqp) {
815 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
816 $pu_ht = $priceforthequantityarray[
'unitprice'];
818 $pu_ttc = $priceforthequantityarray[
'unitprice'];
826 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
827 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
830 if (!empty($price_ht) || $price_ht ===
'0') {
832 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
833 } elseif ($tmpvat != $tmpprodvat) {
836 if ($price_base_type !=
'HT') {
837 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
839 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
846 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
847 $outputlangs = $langs;
849 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
850 $newlang =
GETPOST(
'lang_id',
'aZ09');
852 if (empty($newlang)) {
853 $newlang = $object->thirdparty->default_lang;
855 if (!empty($newlang)) {
857 $outputlangs->setDefaultLang($newlang);
860 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
862 $desc = $prod->description;
866 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
870 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
871 $desc = $product_desc;
873 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
877 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
880 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
881 $outputlangs = $langs;
883 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
884 $newlang =
GETPOST(
'lang_id',
'alpha');
886 if (empty($newlang)) {
887 $newlang = $object->thirdparty->default_lang;
889 if (!empty($newlang)) {
891 $outputlangs->setDefaultLang($newlang);
892 $outputlangs->load(
'products');
894 if (!empty($prod->customcode)) {
895 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
897 if (!empty($prod->customcode) && !empty($prod->country_code)) {
900 if (!empty($prod->country_code)) {
901 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
904 if (!empty($prod->customcode)) {
905 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
907 if (!empty($prod->customcode) && !empty($prod->country_code)) {
910 if (!empty($prod->country_code)) {
911 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
919 $fk_unit = $prod->fk_unit;
923 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
924 $tva_tx = str_replace(
'*',
'', $tva_tx);
925 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
926 $desc = $product_desc;
928 $fk_unit =
GETPOST(
'units',
'alpha');
929 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
937 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
938 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
947 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)))) {
948 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
952 $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);
955 $ret = $object->fetch($object->id);
956 $object->fetch_thirdparty();
958 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
960 $outputlangs = $langs;
961 $newlang =
GETPOST(
'lang_id',
'alpha');
962 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
963 $newlang = $object->thirdparty->default_lang;
965 if (!empty($newlang)) {
967 $outputlangs->setDefaultLang($newlang);
970 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
973 unset($_POST[
'prod_entry_mode']);
975 unset($_POST[
'qty']);
976 unset($_POST[
'type']);
977 unset($_POST[
'remise_percent']);
978 unset($_POST[
'price_ht']);
979 unset($_POST[
'multicurrency_price_ht']);
980 unset($_POST[
'price_ttc']);
981 unset($_POST[
'tva_tx']);
982 unset($_POST[
'product_ref']);
983 unset($_POST[
'product_label']);
984 unset($_POST[
'product_desc']);
985 unset($_POST[
'fournprice']);
986 unset($_POST[
'buying_price']);
987 unset($_POST[
'np_marginRate']);
988 unset($_POST[
'np_markRate']);
989 unset($_POST[
'dp_desc']);
990 unset($_POST[
'idprod']);
991 unset($_POST[
'units']);
993 unset($_POST[
'date_starthour']);
994 unset($_POST[
'date_startmin']);
995 unset($_POST[
'date_startsec']);
996 unset($_POST[
'date_startday']);
997 unset($_POST[
'date_startmonth']);
998 unset($_POST[
'date_startyear']);
999 unset($_POST[
'date_endhour']);
1000 unset($_POST[
'date_endmin']);
1001 unset($_POST[
'date_endsec']);
1002 unset($_POST[
'date_endday']);
1003 unset($_POST[
'date_endmonth']);
1004 unset($_POST[
'date_endyear']);
1010 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1019 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1026 if (preg_match(
'/\*/', $vat_rate)) {
1031 $vat_rate = str_replace(
'*',
'', $vat_rate);
1032 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1033 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1040 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1041 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1043 if (is_array($extralabelsline)) {
1044 foreach ($extralabelsline as $key => $value) {
1045 unset($_POST[
"options_".$key]);
1050 $special_code =
GETPOST(
'special_code');
1058 $productid =
GETPOST(
'productid',
'int');
1059 if (!empty($productid)) {
1061 $product->fetch($productid);
1063 $type = $product->type;
1065 $price_min = $product->price_min;
1066 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1067 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1072 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)))) {
1073 setEventMessages($langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null,
'errors');
1075 $action =
'editline';
1079 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1083 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
1085 $action =
'editline';
1090 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')), null,
'errors');
1092 $action =
'editline';
1096 if (empty($user->rights->margins->creer)) {
1097 foreach ($object->lines as &$line) {
1098 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1099 $fournprice = $line->fk_fournprice;
1100 $buyingprice = $line->pa_ht;
1105 $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);
1108 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1110 $outputlangs = $langs;
1112 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1113 $newlang =
GETPOST(
'lang_id',
'aZ09');
1115 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1116 $newlang = $object->thirdparty->default_lang;
1118 if (!empty($newlang)) {
1119 $outputlangs =
new Translate(
"", $conf);
1120 $outputlangs->setDefaultLang($newlang);
1123 $ret = $object->fetch($object->id);
1124 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1127 unset($_POST[
'qty']);
1128 unset($_POST[
'type']);
1129 unset($_POST[
'productid']);
1130 unset($_POST[
'remise_percent']);
1131 unset($_POST[
'price_ht']);
1132 unset($_POST[
'multicurrency_price_ht']);
1133 unset($_POST[
'price_ttc']);
1134 unset($_POST[
'tva_tx']);
1135 unset($_POST[
'product_ref']);
1136 unset($_POST[
'product_label']);
1137 unset($_POST[
'product_desc']);
1138 unset($_POST[
'fournprice']);
1139 unset($_POST[
'buying_price']);
1141 unset($_POST[
'date_starthour']);
1142 unset($_POST[
'date_startmin']);
1143 unset($_POST[
'date_startsec']);
1144 unset($_POST[
'date_startday']);
1145 unset($_POST[
'date_startmonth']);
1146 unset($_POST[
'date_startyear']);
1147 unset($_POST[
'date_endhour']);
1148 unset($_POST[
'date_endmin']);
1149 unset($_POST[
'date_endsec']);
1150 unset($_POST[
'date_endday']);
1151 unset($_POST[
'date_endmonth']);
1152 unset($_POST[
'date_endyear']);
1157 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1158 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1160 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1161 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1163 $qualified_for_stock_change = 0;
1164 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1165 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1167 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1171 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1172 if (!$idwarehouse || $idwarehouse == -1) {
1174 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
1180 $locationTarget =
'';
1182 $result = $object->valid($user, $idwarehouse);
1187 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1190 GETPOST(
'generate_deposit',
'alpha') ==
'on' && ! empty($deposit_percent_from_payment_terms)
1191 && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)
1193 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1196 $forceFields = array();
1199 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1206 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1217 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1218 $outputlangs = $langs;
1221 $newlang =
GETPOST(
'lang_id',
'aZ09');
1224 $newlang = $object->thirdparty->default_lang;
1226 if (!empty($newlang)) {
1227 $outputlangs =
new Translate(
"", $conf);
1228 $outputlangs->setDefaultLang($newlang);
1230 $model = $object->model_pdf;
1231 $ret = $object->fetch($id);
1233 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1236 $deposit->fetch($deposit->id);
1237 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1241 if ($locationTarget) {
1242 header(
'Location: ' . $locationTarget);
1253 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1255 $idwarehouse =
GETPOST(
'idwarehouse');
1257 $qualified_for_stock_change = 0;
1258 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1259 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1261 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1265 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1266 if (!$idwarehouse || $idwarehouse == -1) {
1268 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
1274 $result = $object->setDraft($user, $idwarehouse);
1277 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1278 $outputlangs = $langs;
1280 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1281 $newlang =
GETPOST(
'lang_id',
'aZ09');
1283 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1284 $newlang = $object->thirdparty->default_lang;
1286 if (!empty($newlang)) {
1287 $outputlangs =
new Translate(
"", $conf);
1288 $outputlangs->setDefaultLang($newlang);
1290 $model = $object->model_pdf;
1291 $ret = $object->fetch($id);
1293 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1297 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1298 $result = $object->cloture($user);
1302 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1303 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1305 $qualified_for_stock_change = 0;
1306 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1307 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1309 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1313 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1314 if (!$idwarehouse || $idwarehouse == -1) {
1316 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")), null,
'errors');
1322 $result = $object->cancel($idwarehouse);
1330 if ($action ==
'update_extras') {
1334 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
1341 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1349 $action =
'edit_extras';
1354 if ($action ==
'import_lines_from_object'
1358 $fromElement =
GETPOST(
'fromelement');
1359 $fromElementid =
GETPOST(
'fromelementid');
1360 $importLines =
GETPOST(
'line_checkbox');
1362 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1363 if ($fromElement ==
'commande') {
1365 $lineClassName =
'OrderLine';
1366 } elseif ($fromElement ==
'propal') {
1367 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1368 $lineClassName =
'PropaleLigne';
1370 $nextRang = count($object->lines) + 1;
1373 foreach ($importLines as $lineId) {
1374 $lineId = intval($lineId);
1375 $originLine =
new $lineClassName($db);
1376 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1377 $originLine->fetch_optionals();
1378 $desc = $originLine->desc;
1379 $pu_ht = $originLine->subprice;
1380 $qty = $originLine->qty;
1381 $txtva = $originLine->tva_tx;
1382 $txlocaltax1 = $originLine->localtax1_tx;
1383 $txlocaltax2 = $originLine->localtax2_tx;
1384 $fk_product = $originLine->fk_product;
1385 $remise_percent = $originLine->remise_percent;
1386 $date_start = $originLine->date_start;
1387 $date_end = $originLine->date_end;
1389 $info_bits = $originLine->info_bits;
1390 $fk_remise_except = $originLine->fk_remise_except;
1391 $price_base_type =
'HT';
1393 $type = $originLine->product_type;
1394 $rang = $nextRang++;
1395 $special_code = $originLine->special_code;
1396 $origin = $originLine->element;
1397 $origin_id = $originLine->id;
1398 $fk_parent_line = 0;
1399 $fk_fournprice = $originLine->fk_fournprice;
1400 $pa_ht = $originLine->pa_ht;
1401 $label = $originLine->label;
1402 $array_options = $originLine->array_options;
1403 $situation_percent = 100;
1405 $fk_unit = $originLine->fk_unit;
1406 $pu_ht_devise = $originLine->multicurrency_subprice;
1408 $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);
1427 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1430 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1431 $permissiontoadd = $usercancreate;
1432 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1435 $triggersendname =
'ORDER_SENTBYMAIL';
1437 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1438 $trackid =
'ord'.$object->id;
1439 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1442 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1443 if ($action ==
'addcontact') {
1444 if ($object->id > 0) {
1447 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1451 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1454 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1455 $langs->load(
"errors");
1456 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"), null,
'errors');
1461 } elseif ($action ==
'swapstatut') {
1463 if ($object->id > 0) {
1464 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1468 } elseif ($action ==
'deletecontact') {
1470 $result = $object->delete_contact($lineid);
1473 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1487 $title = $langs->trans(
'Order').
" - ".$langs->trans(
'Card');
1488 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1495 if (!empty($conf->project->enabled)) {
1500 if ($action ==
'create' && $usercancreate) {
1505 $res = $soc->fetch($socid);
1508 $remise_absolue = 0;
1510 $currency_code = $conf->currency;
1512 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1513 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1514 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1516 if (!empty($origin) && !empty($originid)) {
1518 $element = $subelement = $origin;
1520 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1521 $element = $regs[1];
1522 $subelement = $regs[2];
1525 if ($element ==
'project') {
1526 $projectid = $originid;
1528 if (!$cond_reglement_id) {
1529 $cond_reglement_id = $soc->cond_reglement_id;
1531 if (!$deposit_percent) {
1532 $deposit_percent = $soc->deposit_percent;
1534 if (!$mode_reglement_id) {
1535 $mode_reglement_id = $soc->mode_reglement_id;
1537 if (!$remise_percent) {
1538 $remise_percent = $soc->remise_percent;
1542 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ODER) ?-1 :
'') : $dateorder);
1546 if ($element ==
'order' || $element ==
'commande') {
1547 $element = $subelement =
'commande';
1548 } elseif ($element ==
'propal') {
1549 $element =
'comm/propal';
1550 $subelement =
'propal';
1551 } elseif ($element ==
'contract') {
1552 $element = $subelement =
'contrat';
1557 $classname = ucfirst($subelement);
1558 $objectsrc =
new $classname($db);
1559 $objectsrc->fetch($originid);
1560 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1561 $objectsrc->fetch_lines();
1563 $objectsrc->fetch_thirdparty();
1566 $objectsrc->fetch_optionals();
1567 $object->array_options = $objectsrc->array_options;
1569 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1570 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1572 $soc = $objectsrc->thirdparty;
1573 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1574 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : null));
1575 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1576 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1577 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1578 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1579 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1580 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1581 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1582 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1583 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1585 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1586 if (empty($date_delivery)) {
1587 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1590 if (!empty($conf->multicurrency->enabled)) {
1591 if (!empty($objectsrc->multicurrency_code)) {
1592 $currency_code = $objectsrc->multicurrency_code;
1594 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1595 $currency_tx = $objectsrc->multicurrency_tx;
1599 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1600 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1603 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1606 $cond_reglement_id = $soc->cond_reglement_id;
1607 $deposit_percent = $soc->deposit_percent;
1608 $mode_reglement_id = $soc->mode_reglement_id;
1609 $fk_account = $soc->fk_account;
1610 $availability_id = 0;
1611 $shipping_method_id = $soc->shipping_method_id;
1612 $warehouse_id = $soc->fk_warehouse;
1613 $demand_reason_id = $soc->demand_reason_id;
1614 $remise_percent = $soc->remise_percent;
1615 $remise_absolue = 0;
1616 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1618 if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) {
1619 $currency_code = $soc->multicurrency_code;
1622 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1623 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1627 if ($soc->fk_warehouse > 0) {
1628 $warehouse_id = $soc->fk_warehouse;
1630 if (!empty($conf->stock->enabled) && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1631 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1632 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1634 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1635 $warehouse_id = $user->fk_warehouse;
1639 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1640 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1641 print
'<input type="hidden" name="action" value="add">';
1642 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1643 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1644 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1645 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1646 if (!empty($currency_tx)) {
1647 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1652 print
'<table class="border centpercent">';
1655 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1658 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1659 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1660 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1662 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1668 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1671 print $soc->getNomUrl(1,
'customer');
1672 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1676 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');
1678 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1679 print
'<script type="text/javascript">
1680 $(document).ready(function() {
1681 $("#socid").change(function() {
1682 console.log("We have changed the company - Reload page");
1683 var socid = $(this).val();
1685 $("input[name=action]").val("create");
1686 $("form[name=crea_commande]").submit();
1691 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>';
1699 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1700 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1701 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1705 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1707 $absolute_discount = $soc->getAvailableDiscounts();
1711 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1712 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1718 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1719 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1723 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1724 print
'<td colspan="3">';
1725 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1726 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1731 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1732 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1733 $form->selectAvailabilityDelay($availability_id,
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1737 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1738 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1739 $form->select_conditions_paiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1743 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1744 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1745 $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx');
1749 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && !empty($conf->banque->enabled)) {
1750 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1751 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1757 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1758 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"').$form->selectShippingMethod($shipping_method_id,
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1763 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1764 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1766 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1767 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1772 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1773 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1774 $form->selectInputReason($demand_reason_id,
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1780 if (!empty($conf->project->enabled)) {
1781 $langs->load(
"projects");
1783 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1784 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1785 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>';
1791 if (!empty($conf->incoterm->enabled)) {
1793 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $objectsrc->label_incoterms, 1).
'</label></td>';
1794 print
'<td class="maxwidthonsmartphone">';
1795 $incoterm_id =
GETPOST(
'incoterm_id');
1796 $incoterm_location =
GETPOST(
'location_incoterms');
1797 if (empty($incoterm_id)) {
1798 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1799 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1801 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1806 $parameters = array();
1807 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1808 $parameters[
'objectsrc'] = $objectsrc;
1810 $parameters[
'socid'] = $socid;
1813 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1814 print $hookmanager->resPrint;
1815 if (empty($reshook)) {
1816 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1818 $tpExtrafields =
new Extrafields($db);
1819 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1820 if ($soc->fetch_optionals() > 0) {
1821 $object->array_options = array_merge($object->array_options, $soc->array_options);
1825 print $object->showOptionals($extrafields,
'create', $parameters);
1829 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1831 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1833 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1834 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1835 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1839 if (!empty($conf->multicurrency->enabled)) {
1841 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1842 print
'<td class="maxwidthonsmartphone">';
1843 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1849 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1852 $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%');
1853 print $doleditor->Create(1);
1858 if (empty($user->socid)) {
1860 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1863 $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%');
1864 print $doleditor->Create(1);
1869 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1871 if ($origin ==
'contrat') {
1873 $objectsrc->remise_absolue = $remise_absolue;
1874 $objectsrc->remise_percent = $remise_percent;
1875 $objectsrc->update_price(1);
1878 print
"\n<!-- ".$classname.
" info -->";
1880 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1881 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1882 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1883 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1884 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1886 switch ($classname) {
1888 $newclassname =
'CommercialProposal';
1891 $newclassname =
'Order';
1894 $newclassname =
'Sending';
1897 $newclassname =
'Contract';
1900 $newclassname = $classname;
1903 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
1906 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
1907 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
1908 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
1909 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
1912 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
1913 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
1916 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
1918 if (!empty($conf->multicurrency->enabled)) {
1919 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
1920 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
1921 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
1929 print
$form->buttonsSaveCancel(
"CreateDraft");
1932 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1933 $title = $langs->trans(
'ProductsAndServices');
1936 print
'<div class="div-table-responsive-no-min">';
1937 print
'<table class="noborder centpercent">';
1939 $objectsrc->printOriginLinesList(
'', $selectedLines);
1950 if ($object->id > 0) {
1951 $product_static =
new Product($db);
1954 $soc->fetch($object->socid);
1956 $author =
new User($db);
1957 $author->fetch($object->user_author_id);
1959 $object->fetch_thirdparty();
1960 $res = $object->fetch_optionals();
1963 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
1968 if ($action ==
'delete') {
1969 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
1973 if ($action ==
'validate') {
1975 $ref = substr($object->ref, 1, 4);
1976 if ($ref ==
'PROV' || $ref ==
'') {
1977 $numref = $object->getNextNumRef($soc);
1978 if (empty($numref)) {
1983 $numref = $object->ref;
1986 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
1987 if (!empty($conf->notification->enabled)) {
1988 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1989 $notify =
new Notify($db);
1991 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
1994 $qualified_for_stock_change = 0;
1995 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1996 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1998 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2001 $formquestion = array();
2002 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2003 $langs->load(
"stocks");
2004 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2007 if ($conf->browser->name ==
'ie') {
2010 $formquestion = array(
2014 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))
2020 foreach ($object->lines as $line) {
2021 $res = $line->fetch_product();
2023 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2029 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2032 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2034 if (! empty($deposit_percent_from_payment_terms) && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)) {
2035 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2037 $object->fetchObjectLinked();
2039 $eligibleForDepositGeneration =
true;
2041 if (array_key_exists(
'facture', $object->linkedObjects)) {
2042 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2044 $eligibleForDepositGeneration =
false;
2050 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2051 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2052 $proposal->fetchObjectLinked();
2054 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2055 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2057 $eligibleForDepositGeneration =
false;
2066 if ($eligibleForDepositGeneration) {
2067 $formquestion[] = array(
2068 'type' =>
'checkbox',
2070 'name' =>
'generate_deposit',
2071 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2074 $formquestion[] = array(
2076 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2078 'label' => $langs->trans(
'DateInvoice'),
2083 if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2084 $formquestion[] = array(
2086 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2087 'name' =>
'date_pointoftax',
2088 'label' => $langs->trans(
'DatePointOfTax'),
2095 $form->select_conditions_paiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2096 $paymentTermsSelect = ob_get_clean();
2098 $formquestion[] = array(
2100 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2101 'name' =>
'cond_reglement_id',
2102 'label' => $langs->trans(
'PaymentTerm'),
2103 'value' => $paymentTermsSelect
2106 $formquestion[] = array(
2107 'type' =>
'checkbox',
2108 'tdclass' =>
'showonlyifgeneratedeposit',
2109 'name' =>
'validate_generated_deposit',
2110 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2113 $formquestion[] = array(
2114 'type' =>
'onecolumn',
2117 $(document).ready(function() {
2118 $("[name=generate_deposit]").change(function () {
2119 let $self = $(this);
2120 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2122 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2138 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2143 if ($action ==
'modif') {
2144 $qualified_for_stock_change = 0;
2145 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2146 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2148 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2151 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2152 $formquestion = array();
2153 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2154 $langs->load(
"stocks");
2155 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2158 if ($conf->browser->name ==
'ie') {
2161 $formquestion = array(
2165 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2169 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2175 if ($action ==
'shipped') {
2176 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2182 if ($action ==
'cancel') {
2183 $qualified_for_stock_change = 0;
2184 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2185 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2187 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2190 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2191 $formquestion = array();
2192 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2193 $langs->load(
"stocks");
2194 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2197 if ($conf->browser->name ==
'ie') {
2200 $formquestion = array(
2204 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2208 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2212 if ($action ==
'ask_deleteline') {
2213 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2217 if ($action ==
'clone') {
2219 $formquestion = array(
2220 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'))
2222 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2226 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2228 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2229 if (empty($reshook)) {
2230 $formconfirm .= $hookmanager->resPrint;
2231 } elseif ($reshook > 0) {
2232 $formconfirm = $hookmanager->resPrint;
2241 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2243 $morehtmlref =
'<div class="refidno">';
2245 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2246 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', null, null,
'', 1);
2248 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$soc->getNomUrl(1,
'customer');
2249 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2250 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2253 if (!empty($conf->project->enabled)) {
2254 $langs->load(
"projects");
2255 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
2256 if ($usercancreate) {
2257 if ($action !=
'classify') {
2258 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
2260 if ($action ==
'classify') {
2262 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
2263 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
2264 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
2265 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', 0, 0, 1, 0, 1, 0, 0,
'', 1, 0,
'maxwidth500');
2266 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
2267 $morehtmlref .=
'</form>';
2269 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
2272 if (!empty($object->fk_project)) {
2274 $proj->fetch($object->fk_project);
2275 $morehtmlref .=
' : '.$proj->getNomUrl(1);
2277 $morehtmlref .=
' - '.$proj->title;
2284 $morehtmlref .=
'</div>';
2287 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2290 print
'<div class="fichecenter">';
2291 print
'<div class="fichehalfleft">';
2292 print
'<div class="underbanner clearboth"></div>';
2294 print
'<table class="border tableforfield centpercent">';
2296 if ($soc->outstanding_limit) {
2298 print
'<tr><td class="titlefield">';
2299 print $langs->trans(
'OutstandingBill');
2300 print
'</td><td class="valuefield">';
2301 $arrayoutstandingbills = $soc->getOutstandingBills();
2302 print
price($arrayoutstandingbills[
'opened']).
' / ';
2303 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2309 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2310 $filterabsolutediscount =
"fk_facture_source IS NULL";
2311 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2313 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2314 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2317 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2318 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2319 $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>';
2321 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2323 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2324 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2325 $absolute_discount =
price2num($absolute_discount,
'MT');
2326 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2330 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2331 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2338 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2339 print
'</td><td class="valuefield">';
2340 if ($action ==
'editdate') {
2341 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2342 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2343 print
'<input type="hidden" name="action" value="setdate">';
2344 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2345 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2348 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2349 if ($object->hasDelay() && empty($object->delivery_date)) {
2350 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2358 $editenable = $usercancreate;
2359 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2360 print
'</td><td class="valuefield">';
2361 if ($action ==
'editdate_livraison') {
2362 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2363 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2364 print
'<input type="hidden" name="action" value="setdate_livraison">';
2365 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2366 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2369 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2370 if ($object->hasDelay() && !empty($object->delivery_date)) {
2371 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2378 print
'<tr class="fielddeliverydelay"><td>';
2379 $editenable = $usercancreate;
2380 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2381 print
'</td><td class="valuefield">';
2382 if ($action ==
'editavailability') {
2383 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2385 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2392 $editenable = $usercancreate;
2393 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2394 print
'</td><td class="valuefield">';
2395 if ($action ==
'editshippingmethod') {
2396 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2398 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2405 if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2406 $langs->load(
'stocks');
2407 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2410 $editenable = $usercancreate;
2411 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2412 print
'</td><td class="valuefield">';
2413 if ($action ==
'editwarehouse') {
2414 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2416 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2424 $editenable = $usercancreate;
2425 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2426 print
'</td><td class="valuefield">';
2427 if ($action ==
'editdemandreason') {
2428 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2430 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2436 $editenable = $usercancreate;
2437 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2438 print
'</td><td class="valuefield">';
2439 if ($action ==
'editconditions') {
2440 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2442 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2450 $editenable = $usercancreate;
2451 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2452 print
'</td><td class="valuefield">';
2453 if ($action ==
'editmode') {
2454 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2456 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2461 if (!empty($conf->multicurrency->enabled)) {
2466 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2467 print
'</td><td class="valuefield">';
2468 if ($action ==
'editmulticurrencycode') {
2469 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2471 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2476 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2479 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2480 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2481 print
'</td><td class="valuefield">';
2482 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2483 if ($action ==
'actualizemulticurrencyrate') {
2486 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2488 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2489 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2490 print
'<div class="inline-block"> ';
2491 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2513 $tmparray = $object->getTotalWeightVolume();
2514 $totalWeight = $tmparray[
'weight'];
2515 $totalVolume = $tmparray[
'volume'];
2517 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2518 print
'<td class="valuefield">';
2519 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');
2523 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2524 print
'<td class="valuefield">';
2525 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');
2532 if (!empty($conf->incoterm->enabled)) {
2534 $editenable = $usercancreate;
2535 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2537 print
'<td class="valuefield">';
2538 if ($action !=
'editincoterm') {
2539 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2541 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2547 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && !empty($conf->banque->enabled)) {
2549 $editenable = $usercancreate;
2550 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2551 print
'</td><td class="valuefield">';
2552 if ($action ==
'editbankaccount') {
2553 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2555 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2562 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2567 print
'<div class="fichehalfright">';
2568 print
'<div class="underbanner clearboth"></div>';
2570 print
'<table class="border tableforfield centpercent">';
2572 if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
2574 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2575 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>';
2579 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2580 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>';
2584 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2585 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>';
2591 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2592 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2594 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2595 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2598 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>';
2601 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2602 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2603 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2605 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2606 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2607 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2611 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>';
2619 if (!empty($conf->margin->enabled)) {
2620 $formmargin->displayMarginInfos($object);
2627 print
'<div class="clearboth"></div><br>';
2629 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2630 $blocname =
'contacts';
2631 $title = $langs->trans(
'ContactsAddresses');
2632 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2635 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2636 $blocname =
'notes';
2637 $title = $langs->trans(
'Notes');
2638 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2644 $result = $object->getLinesArray();
2646 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2647 <input type="hidden" name="token" value="' .
newToken().
'">
2648 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2649 <input type="hidden" name="mode" value="">
2650 <input type="hidden" name="page_y" value="">
2651 <input type="hidden" name="id" value="' . $object->id.
'">';
2654 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2657 print
'<div class="div-table-responsive-no-min">';
2658 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2661 if (!empty($object->lines)) {
2662 $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2665 $numlines = count($object->lines);
2671 if ($action !=
'editline') {
2674 $parameters = array();
2676 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2677 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2678 if (empty($reshook))
2679 $object->formAddObjectLine(1, $mysoc, $soc);
2692 if ($action !=
'presend' && $action !=
'editline') {
2693 print
'<div class="tabsAction">';
2695 $parameters = array();
2697 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2698 if (empty($reshook)) {
2701 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2705 if (empty($user->socid)) {
2706 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2708 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2710 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2716 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2717 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2721 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2733 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2734 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) {
2735 if ($usercancreatepurchaseorder) {
2736 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2742 if (!empty($conf->ficheinter->enabled)) {
2743 $langs->load(
"interventions");
2746 if ($user->rights->ficheinter->creer) {
2747 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2749 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2756 $langs->load(
"contracts");
2758 if ($user->rights->contrat->creer) {
2759 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2766 $numshipping = $object->nb_expedition();
2769 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2770 if ($user->rights->expedition->creer) {
2771 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2773 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2776 $langs->load(
"errors");
2777 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2784 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2789 if (
isModEnabled(
'facture') && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2790 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,
'');
2792 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2793 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2797 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2798 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2802 if ($usercancreate) {
2803 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2808 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2812 if ($usercandelete) {
2813 if ($numshipping == 0) {
2814 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2816 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2824 if (
GETPOST(
'modelselected')) {
2825 $action =
'presend';
2828 if ($action !=
'presend') {
2829 print
'<div class="fichecenter"><div class="fichehalfleft">';
2830 print
'<a name="builddoc"></a>';
2833 $relativepath = $objref.
'/'.$objref.
'.pdf';
2834 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2835 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2836 $genallowed = $usercanread;
2837 $delallowed = $usercancreate;
2838 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2842 $linktoelem =
$form->showLinkToObjectBlock($object, null, array(
'order'));
2844 $compatibleImportElementsList =
false;
2847 $compatibleImportElementsList = array(
'commande',
'propal');
2849 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2852 $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
2853 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2854 $useonlinepayment = 0;
2857 print
'<br><!-- Link to pay -->';
2858 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
2859 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
2862 print
'</div><div class="fichehalfright">';
2865 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2867 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
2869 print
'</div></div>';
2873 $modelmail =
'order_send';
2874 $defaulttopic =
'SendOrderRef';
2875 $diroutput = $conf->commande->multidir_output[$object->entity];
2876 $trackid =
'ord'.$object->id;
2878 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
File of class to manage predefined price products or services by customer.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield= 'rowid')
Return the value of a filed into a dictionary for the record $id.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
const STATUS_CLOSED
Closed (Sent, billed or not)
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
dolGetButtonAction($label, $html= '', $actionType= 'default', $url= '', $id= '', $userRight=1, $params=array())
Function dolGetButtonAction.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
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...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
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...
static getIdAndTxFromCode($dbs, $code, $date_document= '')
Get id and rate of currency from code.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput= 'no', $use_short_label=0)
Output a dimension with best unit.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class ProductCombination Used to represent a product combination.
restrictedArea($user, $features, $objectid=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.
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
const STATUS_VALIDATED
Validated status.
const TYPE_DEPOSIT
Deposit invoice.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage a WYSIWYG editor.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
$formconfirm
if ($action == 'delbookkeepingyear') {
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
const STATUS_CANCELED
Canceled status.