40 require
'../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
50 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
68 $langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
71 $langs->load(
'incoterm');
74 $langs->load(
'margins');
77 $langs->load(
'productbatch');
83 $socid =
GETPOST(
'socid',
'int');
84 $action =
GETPOST(
'action',
'aZ09');
85 $cancel =
GETPOST(
'cancel',
'alpha');
86 $confirm =
GETPOST(
'confirm',
'alpha');
87 $lineid =
GETPOST(
'lineid',
'int');
88 $contactid =
GETPOST(
'contactid',
'int');
89 $projectid =
GETPOST(
'projectid',
'int');
90 $origin =
GETPOST(
'origin',
'alpha');
92 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
95 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
96 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
97 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
100 if (!empty($user->socid)) {
101 $socid = $user->socid;
105 $hookmanager->initHooks(array(
'ordercard',
'globalcard'));
113 $extrafields->fetch_name_optionals_label($object->table_element);
116 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
119 $usercanread = $user->hasRight(
"commande",
"lire");
120 $usercancreate = $user->hasRight(
"commande",
"creer");
121 $usercandelete = $user->hasRight(
"commande",
"supprimer");
124 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'close')));
125 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'validate')));
126 $usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'annuler')));
127 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight(
'commande',
'order_advance',
'send'));
128 $usercangeneretedoc = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight(
'commande',
'order_advance',
'generetedoc'));
130 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
131 $usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
133 $permissionnote = $usercancreate;
134 $permissiondellink = $usercancreate;
135 $permissiontoadd = $usercancreate;
140 $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'));
149 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
154 if (empty($reshook)) {
155 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
157 if (empty($backtopage) || ($cancel && empty($id))) {
158 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
159 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
160 $backtopage = $backurlforlist;
162 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
168 if (!empty($backtopageforcancel)) {
169 header(
"Location: ".$backtopageforcancel);
171 } elseif (!empty($backtopage)) {
172 header(
"Location: ".$backtopage);
178 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
180 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
182 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
185 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
186 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
189 if ($object->id > 0) {
191 $orig = clone $object;
193 $result = $object->createFromClone($user, $socid);
195 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
204 } elseif ($action ==
'reopen' && $usercancreate) {
207 $result = $object->set_reopen($user);
214 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
216 $result = $object->delete($user);
218 header(
'Location: list.php?restore_lastsearch_values=1');
223 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
225 $result = $object->deleteline($user, $lineid);
228 $object->line_order(
true);
230 $outputlangs = $langs;
233 $newlang =
GETPOST(
'lang_id',
'aZ09');
236 $newlang = $object->thirdparty->default_lang;
238 if (!empty($newlang)) {
240 $outputlangs->setDefaultLang($newlang);
242 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
243 $ret = $object->fetch($object->id);
244 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
247 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
252 } elseif ($action ==
'classin' && $usercancreate) {
254 $object->setProject(
GETPOST(
'projectid',
'int'));
255 } elseif ($action ==
'add' && $usercancreate) {
258 $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'));
259 $selectedLines =
GETPOST(
'toselect',
'array');
261 if ($datecommande ==
'') {
262 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
268 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
274 $object->socid = $socid;
275 $object->fetch_thirdparty();
279 $object->date_commande = $datecommande;
280 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
281 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
282 $object->source =
GETPOST(
'source_id');
283 $object->fk_project =
GETPOST(
'projectid',
'int');
284 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
285 $object->model_pdf =
GETPOST(
'model');
286 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
287 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
288 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
289 $object->fk_account =
GETPOST(
'fk_account',
'int');
290 $object->availability_id =
GETPOST(
'availability_id');
291 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
292 $object->date_livraison = $date_delivery;
293 $object->delivery_date = $date_delivery;
294 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
295 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
296 $object->fk_delivery_address =
GETPOST(
'fk_address');
297 $object->contact_id =
GETPOST(
'contactid');
298 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
299 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
300 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
301 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
304 $ret = $extrafields->setOptionalsFromPost(
null, $object);
311 if (!empty($origin) && !empty($originid)) {
313 $element = $subelement = $origin;
315 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
316 $element = $regs [1];
317 $subelement = $regs [2];
321 if ($element ==
'order') {
322 $element = $subelement =
'commande';
324 if ($element ==
'propal') {
325 $element =
'comm/propal';
326 $subelement =
'propal';
328 if ($element ==
'contract') {
329 $element = $subelement =
'contrat';
332 $object->origin = $origin;
333 $object->origin_id = $originid;
336 $object->linked_objects [$object->origin] = $object->origin_id;
337 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
338 if (!empty($other_linked_objects)) {
339 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
343 $object_id = $object->create($user);
345 if ($object_id > 0) {
348 $classname = ucfirst($subelement);
349 $srcobject =
new $classname($db);
351 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
352 $result = $srcobject->fetch($object->origin_id);
354 $lines = $srcobject->lines;
355 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
356 $srcobject->fetch_lines();
357 $lines = $srcobject->lines;
361 $num = count($lines);
363 for ($i = 0; $i < $num; $i++) {
364 if (!in_array($lines[$i]->
id, $selectedLines)) {
368 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
369 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
370 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
374 $date_start = $lines[$i]->date_debut_prevue;
375 if ($lines[$i]->date_debut_reel) {
376 $date_start = $lines[$i]->date_debut_reel;
378 if ($lines[$i]->date_start) {
379 $date_start = $lines[$i]->date_start;
381 $date_end = $lines[$i]->date_fin_prevue;
382 if ($lines[$i]->date_fin_reel) {
383 $date_end = $lines[$i]->date_fin_reel;
385 if ($lines[$i]->date_end) {
386 $date_end = $lines[$i]->date_end;
390 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
395 if (method_exists($lines[$i],
'fetch_optionals')) {
396 $lines[$i]->fetch_optionals();
397 $array_options = $lines[$i]->array_options;
400 $tva_tx = $lines[$i]->tva_tx;
401 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
402 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
405 $result = $object->addline(
407 $lines[$i]->subprice,
410 $lines[$i]->localtax1_tx,
411 $lines[$i]->localtax2_tx,
412 $lines[$i]->fk_product,
413 $lines[$i]->remise_percent,
414 $lines[$i]->info_bits,
415 $lines[$i]->fk_remise_except,
422 $lines[$i]->special_code,
424 $lines[$i]->fk_fournprice,
439 if ($result > 0 && $lines[$i]->product_type == 9) {
440 $fk_parent_line = $result;
477 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
492 $object_id = $object->create($user);
497 if ($object_id > 0) {
498 if (
GETPOST(
'contactid',
'int')) {
499 $result = $object->add_contact(
GETPOST(
'contactid',
'int'),
'CUSTOMER',
'external');
511 if ($object_id > 0 && !$error) {
513 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
521 } elseif ($action ==
'classifybilled' && $usercancreate) {
522 $ret = $object->classifyBilled($user);
527 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
528 $ret = $object->classifyUnBilled($user);
532 } elseif ($action ==
'setref_client' && $usercancreate) {
534 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
538 } elseif ($action ==
'setremise' && $usercancreate) {
543 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
545 if ($object->id > 0) {
546 $object->insert_discount(
GETPOST(
'remise_id'));
551 } elseif ($action ==
'setdate' && $usercancreate) {
554 $result = $object->set_date($user, $date);
558 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
559 $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'));
562 $result = $object->setDeliveryDate($user, $date_delivery);
566 } elseif ($action ==
'setmode' && $usercancreate) {
567 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
571 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
573 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
574 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
576 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
577 } elseif ($action ==
'setavailability' && $usercancreate) {
578 $result = $object->availability(
GETPOST(
'availability_id'));
582 } elseif ($action ==
'setdemandreason' && $usercancreate) {
583 $result = $object->demand_reason(
GETPOST(
'demand_reason_id'));
587 } elseif ($action ==
'setconditions' && $usercancreate) {
588 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
592 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
594 $outputlangs = $langs;
595 $newlang =
GETPOST(
'lang_id',
'alpha');
597 $newlang = $object->thirdparty->default_lang;
599 if (!empty($newlang)) {
601 $outputlangs->setDefaultLang($newlang);
604 $ret = $object->fetch($object->id);
605 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
608 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
610 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
614 } elseif ($action ==
'setbankaccount' && $usercancreate) {
616 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
620 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
622 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
626 } elseif ($action ==
'setwarehouse' && $usercancreate) {
628 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
632 } elseif ($action ==
'setremisepercent' && $usercancreate) {
633 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
634 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
635 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
636 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
638 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
639 $vat_rate = str_replace(
'*',
'', $vat_rate);
640 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
641 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
642 foreach ($object->lines as $line) {
643 $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);
645 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
647 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
648 $remise_percent = str_replace(
'*',
'', $remise_percent);
649 foreach ($object->lines as $line) {
650 $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);
652 } elseif ($action ==
'addline' && $usercancreate) {
653 $langs->load(
'errors');
661 $price_ht_devise =
'';
663 $price_ttc_devise =
'';
669 if (
GETPOST(
'price_ht') !==
'') {
672 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
675 if (
GETPOST(
'price_ttc') !==
'') {
678 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
682 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
683 if ($prod_entry_mode ==
'free') {
686 $idprod =
GETPOST(
'idprod',
'int');
689 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
692 $pu_equivalent = $pu_ht;
693 $pu_equivalent_ttc = $pu_ttc;
694 $currency_tx = $object->multicurrency_tx;
698 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
699 $pu_equivalent = $pu_ht_devise * $currency_tx;
701 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
702 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
708 if (empty($remise_percent)) {
713 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
714 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
716 if (is_array($extralabelsline)) {
718 foreach ($extralabelsline as $key => $value) {
719 unset($_POST[
"options_".$key]);
723 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
724 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
727 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
728 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
731 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
732 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
736 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
740 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
743 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
744 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
748 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
749 if ($combinations =
GETPOST(
'combinations',
'array')) {
753 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
754 $idprod = $res->fk_product_child;
756 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
762 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
766 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
771 if (!empty($idprod) && $idprod > 0) {
773 $prod->fetch($idprod);
775 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
784 $pu_ht = $prod->price;
785 $pu_ttc = $prod->price_ttc;
786 $price_min = $prod->price_min;
787 $price_min_ttc = $prod->price_min_ttc;
788 $price_base_type = $prod->price_base_type;
791 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
792 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
793 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
794 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
795 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
796 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
797 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
798 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
799 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
801 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
802 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
805 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
807 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
811 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
813 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
815 if (count($prodcustprice->lines) > 0) {
816 $pu_ht =
price($prodcustprice->lines[0]->price);
817 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
818 $price_min =
price($prodcustprice->lines[0]->price_min);
819 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
820 $price_base_type = $prodcustprice->lines[0]->price_base_type;
821 $tva_tx = $prodcustprice->lines[0]->tva_tx;
822 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
823 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
825 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
826 if (empty($tva_tx)) {
833 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
835 if ($prod->prices_by_qty[0]) {
840 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
841 if ($priceforthequantityarray[
'rowid'] != $pqp) {
845 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
846 $pu_ht = $priceforthequantityarray[
'unitprice'];
848 $pu_ttc = $priceforthequantityarray[
'unitprice'];
854 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
856 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
860 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
861 if ($priceforthequantityarray[
'rowid'] != $pqp) {
865 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
866 $pu_ht = $priceforthequantityarray[
'unitprice'];
868 $pu_ttc = $priceforthequantityarray[
'unitprice'];
876 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
877 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
880 if (!empty($price_ht) || $price_ht ===
'0') {
882 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
883 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
885 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
886 } elseif ($tmpvat != $tmpprodvat) {
888 if ($price_base_type !=
'HT') {
889 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
891 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
898 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
899 $outputlangs = $langs;
901 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
902 $newlang =
GETPOST(
'lang_id',
'aZ09');
904 if (empty($newlang)) {
905 $newlang = $object->thirdparty->default_lang;
907 if (!empty($newlang)) {
909 $outputlangs->setDefaultLang($newlang);
912 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
914 $desc = $prod->description;
918 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
922 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
923 $desc = $product_desc;
925 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
929 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
932 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
933 $outputlangs = $langs;
935 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
936 $newlang =
GETPOST(
'lang_id',
'alpha');
938 if (empty($newlang)) {
939 $newlang = $object->thirdparty->default_lang;
941 if (!empty($newlang)) {
943 $outputlangs->setDefaultLang($newlang);
944 $outputlangs->load(
'products');
946 if (!empty($prod->customcode)) {
947 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
949 if (!empty($prod->customcode) && !empty($prod->country_code)) {
952 if (!empty($prod->country_code)) {
953 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
956 if (!empty($prod->customcode)) {
957 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
959 if (!empty($prod->customcode) && !empty($prod->country_code)) {
962 if (!empty($prod->country_code)) {
963 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
971 $fk_unit = $prod->fk_unit;
975 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
976 $tva_tx = str_replace(
'*',
'', $tva_tx);
977 if (empty($tva_tx)) {
980 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
981 $desc = $product_desc;
983 $fk_unit =
GETPOST(
'units',
'alpha');
984 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
985 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
987 if ($pu_ttc && !$pu_ht) {
988 $price_base_type =
'TTC';
997 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
998 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1007 if ($usermustrespectpricemin) {
1008 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1009 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1012 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1013 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1021 $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);
1024 $ret = $object->fetch($object->id);
1025 $object->fetch_thirdparty();
1027 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1029 $outputlangs = $langs;
1030 $newlang =
GETPOST(
'lang_id',
'alpha');
1032 $newlang = $object->thirdparty->default_lang;
1034 if (!empty($newlang)) {
1035 $outputlangs =
new Translate(
"", $conf);
1036 $outputlangs->setDefaultLang($newlang);
1039 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1042 unset($_POST[
'prod_entry_mode']);
1044 unset($_POST[
'qty']);
1045 unset($_POST[
'type']);
1046 unset($_POST[
'remise_percent']);
1047 unset($_POST[
'price_ht']);
1048 unset($_POST[
'multicurrency_price_ht']);
1049 unset($_POST[
'price_ttc']);
1050 unset($_POST[
'tva_tx']);
1051 unset($_POST[
'product_ref']);
1052 unset($_POST[
'product_label']);
1053 unset($_POST[
'product_desc']);
1054 unset($_POST[
'fournprice']);
1055 unset($_POST[
'buying_price']);
1056 unset($_POST[
'np_marginRate']);
1057 unset($_POST[
'np_markRate']);
1058 unset($_POST[
'dp_desc']);
1059 unset($_POST[
'idprod']);
1060 unset($_POST[
'units']);
1062 unset($_POST[
'date_starthour']);
1063 unset($_POST[
'date_startmin']);
1064 unset($_POST[
'date_startsec']);
1065 unset($_POST[
'date_startday']);
1066 unset($_POST[
'date_startmonth']);
1067 unset($_POST[
'date_startyear']);
1068 unset($_POST[
'date_endhour']);
1069 unset($_POST[
'date_endmin']);
1070 unset($_POST[
'date_endsec']);
1071 unset($_POST[
'date_endday']);
1072 unset($_POST[
'date_endmonth']);
1073 unset($_POST[
'date_endyear']);
1079 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1087 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1088 $vat_rate = str_replace(
'*',
'', $vat_rate);
1099 $pu_equivalent = $pu_ht;
1100 $pu_equivalent_ttc = $pu_ttc;
1101 $currency_tx = $object->multicurrency_tx;
1105 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1106 $pu_equivalent = $pu_ht_devise * $currency_tx;
1108 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1109 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1114 if (preg_match(
'/\*/', $vat_rate)) {
1119 $vat_rate = str_replace(
'*',
'', $vat_rate);
1120 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1121 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1128 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1129 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1131 if (is_array($extralabelsline)) {
1132 foreach ($extralabelsline as $key => $value) {
1133 unset($_POST[
"options_".$key]);
1138 $special_code =
GETPOST(
'special_code');
1146 $productid =
GETPOST(
'productid',
'int');
1147 if (!empty($productid)) {
1149 $product->fetch($productid);
1151 $type = $product->type;
1153 $price_min = $product->price_min;
1154 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1155 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1157 $price_min_ttc = $product->price_min_ttc;
1158 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1159 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1164 if ($usermustrespectpricemin) {
1165 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1166 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1169 $action =
'editline';
1170 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1171 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1174 $action =
'editline';
1179 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1183 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1185 $action =
'editline';
1190 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1192 $action =
'editline';
1196 if (empty($user->rights->margins->creer)) {
1197 foreach ($object->lines as &$line) {
1198 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1199 $fournprice = $line->fk_fournprice;
1200 $buyingprice = $line->pa_ht;
1206 $price_base_type =
'HT';
1208 if (empty($pu) && !empty($pu_ttc)) {
1210 $price_base_type =
'TTC';
1213 $result = $object->updateline(
GETPOST(
'lineid',
'int'), $description, $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $price_base_type, $info_bits, $date_start, $date_end, $type,
GETPOST(
'fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options,
GETPOST(
'units'), $pu_ht_devise);
1216 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);
1231 $ret = $object->fetch($object->id);
1232 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1235 unset($_POST[
'qty']);
1236 unset($_POST[
'type']);
1237 unset($_POST[
'productid']);
1238 unset($_POST[
'remise_percent']);
1239 unset($_POST[
'price_ht']);
1240 unset($_POST[
'multicurrency_price_ht']);
1241 unset($_POST[
'price_ttc']);
1242 unset($_POST[
'tva_tx']);
1243 unset($_POST[
'product_ref']);
1244 unset($_POST[
'product_label']);
1245 unset($_POST[
'product_desc']);
1246 unset($_POST[
'fournprice']);
1247 unset($_POST[
'buying_price']);
1249 unset($_POST[
'date_starthour']);
1250 unset($_POST[
'date_startmin']);
1251 unset($_POST[
'date_startsec']);
1252 unset($_POST[
'date_startday']);
1253 unset($_POST[
'date_startmonth']);
1254 unset($_POST[
'date_startyear']);
1255 unset($_POST[
'date_endhour']);
1256 unset($_POST[
'date_endmin']);
1257 unset($_POST[
'date_endsec']);
1258 unset($_POST[
'date_endday']);
1259 unset($_POST[
'date_endmonth']);
1260 unset($_POST[
'date_endyear']);
1265 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1266 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1268 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1269 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1271 $qualified_for_stock_change = 0;
1272 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1273 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1275 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1279 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1280 if (!$idwarehouse || $idwarehouse == -1) {
1282 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1288 $locationTarget =
'';
1290 $result = $object->valid($user, $idwarehouse);
1295 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1298 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1299 &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
1301 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1304 $forceFields = array();
1307 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1314 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1325 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1326 $outputlangs = $langs;
1329 $newlang =
GETPOST(
'lang_id',
'aZ09');
1332 $newlang = $object->thirdparty->default_lang;
1334 if (!empty($newlang)) {
1335 $outputlangs =
new Translate(
"", $conf);
1336 $outputlangs->setDefaultLang($newlang);
1338 $model = $object->model_pdf;
1339 $ret = $object->fetch($id);
1341 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1344 $deposit->fetch($deposit->id);
1345 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1349 if ($locationTarget) {
1350 header(
'Location: ' . $locationTarget);
1361 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1363 $idwarehouse =
GETPOST(
'idwarehouse');
1365 $qualified_for_stock_change = 0;
1366 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1367 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1369 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1373 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1374 if (!$idwarehouse || $idwarehouse == -1) {
1376 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1382 $result = $object->setDraft($user, $idwarehouse);
1385 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1386 $outputlangs = $langs;
1389 $newlang =
GETPOST(
'lang_id',
'aZ09');
1392 $newlang = $object->thirdparty->default_lang;
1394 if (!empty($newlang)) {
1395 $outputlangs =
new Translate(
"", $conf);
1396 $outputlangs->setDefaultLang($newlang);
1398 $model = $object->model_pdf;
1399 $ret = $object->fetch($id);
1401 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1405 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1406 $result = $object->cloture($user);
1410 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1411 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1413 $qualified_for_stock_change = 0;
1414 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1415 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1417 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1421 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1422 if (!$idwarehouse || $idwarehouse == -1) {
1424 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1430 $result = $object->cancel($idwarehouse);
1438 if ($action ==
'update_extras') {
1442 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1449 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1457 $action =
'edit_extras';
1462 if ($action ==
'import_lines_from_object'
1466 $fromElement =
GETPOST(
'fromelement');
1467 $fromElementid =
GETPOST(
'fromelementid');
1468 $importLines =
GETPOST(
'line_checkbox');
1470 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1471 if ($fromElement ==
'commande') {
1473 $lineClassName =
'OrderLine';
1474 } elseif ($fromElement ==
'propal') {
1475 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1476 $lineClassName =
'PropaleLigne';
1478 $nextRang = count($object->lines) + 1;
1481 foreach ($importLines as $lineId) {
1482 $lineId = intval($lineId);
1483 $originLine =
new $lineClassName($db);
1484 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1485 $originLine->fetch_optionals();
1486 $desc = $originLine->desc;
1487 $pu_ht = $originLine->subprice;
1488 $qty = $originLine->qty;
1489 $txtva = $originLine->tva_tx;
1490 $txlocaltax1 = $originLine->localtax1_tx;
1491 $txlocaltax2 = $originLine->localtax2_tx;
1492 $fk_product = $originLine->fk_product;
1493 $remise_percent = $originLine->remise_percent;
1494 $date_start = $originLine->date_start;
1495 $date_end = $originLine->date_end;
1497 $info_bits = $originLine->info_bits;
1498 $fk_remise_except = $originLine->fk_remise_except;
1499 $price_base_type =
'HT';
1501 $type = $originLine->product_type;
1502 $rang = $nextRang++;
1503 $special_code = $originLine->special_code;
1504 $origin = $originLine->element;
1505 $origin_id = $originLine->id;
1506 $fk_parent_line = 0;
1507 $fk_fournprice = $originLine->fk_fournprice;
1508 $pa_ht = $originLine->pa_ht;
1509 $label = $originLine->label;
1510 $array_options = $originLine->array_options;
1511 $situation_percent = 100;
1513 $fk_unit = $originLine->fk_unit;
1514 $pu_ht_devise = $originLine->multicurrency_subprice;
1516 $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);
1535 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1538 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1539 $permissiontoadd = $usercancreate;
1540 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1543 $triggersendname =
'ORDER_SENTBYMAIL';
1545 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1546 $trackid =
'ord'.$object->id;
1547 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1550 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1551 if ($action ==
'addcontact') {
1552 if ($object->id > 0) {
1555 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1559 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1562 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1563 $langs->load(
"errors");
1564 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1569 } elseif ($action ==
'swapstatut') {
1571 if ($object->id > 0) {
1572 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1576 } elseif ($action ==
'deletecontact') {
1578 $result = $object->delete_contact($lineid);
1581 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1595 $title = $object->ref.
" - ".$langs->trans(
'Card');
1596 if ($action ==
'create') {
1597 $title = $langs->trans(
"NewOrder");
1599 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1612 if ($action ==
'create' && $usercancreate) {
1617 $res = $soc->fetch($socid);
1620 $remise_absolue = 0;
1622 $currency_code = $conf->currency;
1624 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1625 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1626 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1628 if (!empty($origin) && !empty($originid)) {
1630 $element = $subelement = $origin;
1632 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1633 $element = $regs[1];
1634 $subelement = $regs[2];
1637 if ($element ==
'project') {
1638 $projectid = $originid;
1640 if (!$cond_reglement_id) {
1641 $cond_reglement_id = $soc->cond_reglement_id;
1643 if (!$deposit_percent) {
1644 $deposit_percent = $soc->deposit_percent;
1646 if (!$mode_reglement_id) {
1647 $mode_reglement_id = $soc->mode_reglement_id;
1649 if (!$remise_percent) {
1650 $remise_percent = $soc->remise_percent;
1654 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ODER) ?-1 :
'') : $dateorder);
1658 if ($element ==
'order' || $element ==
'commande') {
1659 $element = $subelement =
'commande';
1660 } elseif ($element ==
'propal') {
1661 $element =
'comm/propal';
1662 $subelement =
'propal';
1663 } elseif ($element ==
'contract') {
1664 $element = $subelement =
'contrat';
1669 $classname = ucfirst($subelement);
1670 $objectsrc =
new $classname($db);
1671 $objectsrc->fetch($originid);
1672 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1673 $objectsrc->fetch_lines();
1675 $objectsrc->fetch_thirdparty();
1678 $objectsrc->fetch_optionals();
1679 $object->array_options = $objectsrc->array_options;
1681 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1682 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1684 $soc = $objectsrc->thirdparty;
1685 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1686 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1687 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1688 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1689 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1690 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1691 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1692 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1693 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1694 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1695 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1697 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1698 if (empty($date_delivery)) {
1699 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1703 if (!empty($objectsrc->multicurrency_code)) {
1704 $currency_code = $objectsrc->multicurrency_code;
1706 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1707 $currency_tx = $objectsrc->multicurrency_tx;
1711 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1712 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1715 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1718 $cond_reglement_id = $soc->cond_reglement_id;
1719 $deposit_percent = $soc->deposit_percent;
1720 $mode_reglement_id = $soc->mode_reglement_id;
1721 $fk_account = $soc->fk_account;
1722 $availability_id = 0;
1723 $shipping_method_id = $soc->shipping_method_id;
1724 $warehouse_id = $soc->fk_warehouse;
1725 $demand_reason_id = $soc->demand_reason_id;
1726 $remise_percent = $soc->remise_percent;
1727 $remise_absolue = 0;
1728 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1730 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1731 $currency_code = $soc->multicurrency_code;
1734 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1735 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1739 if ($soc->fk_warehouse > 0) {
1740 $warehouse_id = $soc->fk_warehouse;
1742 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1743 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1744 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1746 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1747 $warehouse_id = $user->fk_warehouse;
1751 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1752 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1753 print
'<input type="hidden" name="action" value="add">';
1754 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1755 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1756 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1757 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1758 if (!empty($currency_tx)) {
1759 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1764 print
'<table class="border centpercent">';
1767 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1770 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1771 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1772 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1774 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1780 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1783 print $soc->getNomUrl(1,
'customer');
1784 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1788 print
img_picto(
'',
'company').$form->select_company(
'',
'socid',
'((s.client = 1 OR s.client = 2 OR s.client = 3) AND s.status=1)',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1790 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1791 print
'<script type="text/javascript">
1792 $(document).ready(function() {
1793 $("#socid").change(function() {
1794 console.log("We have changed the company - Reload page");
1795 var socid = $(this).val();
1797 $("input[name=action]").val("create");
1798 $("form[name=crea_commande]").submit();
1803 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>';
1811 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1812 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1813 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1817 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1819 $absolute_discount = $soc->getAvailableDiscounts();
1823 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1824 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1830 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1831 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1835 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1836 print
'<td colspan="3">';
1837 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1838 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1843 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1844 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1845 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id')?
GETPOST(
'availability_id'):$availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1849 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1850 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1851 print
$form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id')?
GETPOST(
'cond_reglement_id'):$cond_reglement_id),
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1855 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1856 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1857 print
$form->select_types_paiements((
GETPOSTISSET(
'mode_reglement_id')?
GETPOST(
'mode_reglement_id'):$mode_reglement_id),
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1861 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
1862 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1863 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes((
GETPOSTISSET(
'fk_account')?
GETPOST(
'fk_account'):$fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1869 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1870 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
1871 $form->selectShippingMethod((
GETPOSTISSET(
'shipping_method_id')?
GETPOST(
'shipping_method_id'):$shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1876 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1877 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1879 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1880 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses((
GETPOSTISSET(
'warehouse_id')?
GETPOST(
'warehouse_id'):$warehouse_id),
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1885 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1886 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1887 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id')?
GETPOST(
'demand_reason_id'):$demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1894 $langs->load(
"projects");
1896 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1897 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (
GETPOSTISSET(
'projectid')?
GETPOST(
'projectid'):$projectid),
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1898 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>';
1906 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
1907 print
'<td class="maxwidthonsmartphone">';
1908 $incoterm_id =
GETPOST(
'incoterm_id');
1909 $incoterm_location =
GETPOST(
'location_incoterms');
1910 if (empty($incoterm_id)) {
1911 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1912 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1914 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1920 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1926 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1927 print $hookmanager->resPrint;
1928 if (empty($reshook)) {
1929 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1931 $tpExtrafields =
new Extrafields($db);
1932 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1933 if ($soc->fetch_optionals() > 0) {
1934 $object->array_options = array_merge($object->array_options, $soc->array_options);
1938 print $object->showOptionals($extrafields,
'create',
$parameters);
1942 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1944 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1946 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1947 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1948 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1954 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1955 print
'<td class="maxwidthonsmartphone">';
1956 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code')?
GETPOST(
'multicurrency_code'):$currency_code),
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1962 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1965 $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%');
1966 print $doleditor->Create(1);
1971 if (empty($user->socid)) {
1973 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1976 $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%');
1977 print $doleditor->Create(1);
1982 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1984 if ($origin ==
'contrat') {
1986 $objectsrc->remise_absolue = $remise_absolue;
1987 $objectsrc->remise_percent = $remise_percent;
1988 $objectsrc->update_price(1);
1991 print
"\n<!-- ".$classname.
" info -->";
1993 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1994 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1995 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1996 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1997 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1999 switch ($classname) {
2001 $newclassname =
'CommercialProposal';
2004 $newclassname =
'Order';
2007 $newclassname =
'Sending';
2010 $newclassname =
'Contract';
2013 $newclassname = $classname;
2016 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2019 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2020 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2021 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2022 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2025 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2026 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2029 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2032 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2033 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2034 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2042 print
$form->buttonsSaveCancel(
"CreateDraft");
2045 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2046 $title = $langs->trans(
'ProductsAndServices');
2049 print
'<div class="div-table-responsive-no-min">';
2050 print
'<table class="noborder centpercent">';
2052 $objectsrc->printOriginLinesList(
'', $selectedLines);
2063 if ($object->id > 0) {
2064 $product_static =
new Product($db);
2067 $soc->fetch($object->socid);
2069 $author =
new User($db);
2070 $author->fetch($object->user_author_id);
2072 $object->fetch_thirdparty();
2073 $res = $object->fetch_optionals();
2076 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2081 if ($action ==
'delete') {
2082 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2086 if ($action ==
'validate') {
2088 $ref = substr($object->ref, 1, 4);
2089 if ($ref ==
'PROV' || $ref ==
'') {
2090 $numref = $object->getNextNumRef($soc);
2091 if (empty($numref)) {
2096 $numref = $object->ref;
2099 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2101 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2102 $notify =
new Notify($db);
2104 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
2107 $qualified_for_stock_change = 0;
2108 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2109 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2111 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2114 $formquestion = array();
2115 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2116 $langs->load(
"stocks");
2117 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2120 if ($conf->browser->name ==
'ie') {
2123 $formquestion = array(
2127 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))
2133 foreach ($object->lines as $line) {
2134 $res = $line->fetch_product();
2136 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2142 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2144 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2149 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2151 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2152 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2154 $object->fetchObjectLinked();
2156 $eligibleForDepositGeneration =
true;
2158 if (array_key_exists(
'facture', $object->linkedObjects)) {
2159 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2161 $eligibleForDepositGeneration =
false;
2167 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2168 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2169 $proposal->fetchObjectLinked();
2171 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2172 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2174 $eligibleForDepositGeneration =
false;
2182 if ($eligibleForDepositGeneration) {
2183 $formquestion[] = array(
2184 'type' =>
'checkbox',
2186 'name' =>
'generate_deposit',
2187 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2190 $formquestion[] = array(
2192 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2194 'label' => $langs->trans(
'DateInvoice'),
2199 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2200 $formquestion[] = array(
2202 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2203 'name' =>
'date_pointoftax',
2204 'label' => $langs->trans(
'DatePointOfTax'),
2211 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2213 $formquestion[] = array(
2215 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2216 'name' =>
'cond_reglement_id',
2217 'label' => $langs->trans(
'PaymentTerm'),
2218 'value' => $paymentTermsSelect
2221 $formquestion[] = array(
2222 'type' =>
'checkbox',
2223 'tdclass' =>
'showonlyifgeneratedeposit',
2224 'name' =>
'validate_generated_deposit',
2225 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2228 $formquestion[] = array(
2229 'type' =>
'onecolumn',
2232 $(document).ready(function() {
2233 $("[name=generate_deposit]").change(function () {
2234 let $self = $(this);
2235 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2237 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2254 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2259 if ($action ==
'modif') {
2260 $qualified_for_stock_change = 0;
2261 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2262 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2264 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2267 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2268 $formquestion = array();
2269 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2270 $langs->load(
"stocks");
2271 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2274 if ($conf->browser->name ==
'ie') {
2277 $formquestion = array(
2281 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2285 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2291 if ($action ==
'shipped') {
2292 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2298 if ($action ==
'cancel') {
2299 $qualified_for_stock_change = 0;
2300 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2301 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2303 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2306 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2307 $formquestion = array();
2308 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2309 $langs->load(
"stocks");
2310 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2313 if ($conf->browser->name ==
'ie') {
2316 $formquestion = array(
2320 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2324 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2328 if ($action ==
'ask_deleteline') {
2329 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2333 if ($action ==
'clone') {
2335 $formquestion = array(
2336 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'))
2338 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2344 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2345 if (empty($reshook)) {
2347 } elseif ($reshook > 0) {
2357 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2359 $morehtmlref =
'<div class="refidno">';
2361 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2362 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE :
''),
'',
null,
null,
'', 1);
2364 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2365 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2366 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2370 $langs->load(
"projects");
2371 $morehtmlref .=
'<br>';
2372 if ($usercancreate) {
2373 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2374 if ($action !=
'classify') {
2375 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2377 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2379 if (!empty($object->fk_project)) {
2381 $proj->fetch($object->fk_project);
2382 $morehtmlref .= $proj->getNomUrl(1);
2384 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2389 $morehtmlref .=
'</div>';
2392 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2395 print
'<div class="fichecenter">';
2396 print
'<div class="fichehalfleft">';
2397 print
'<div class="underbanner clearboth"></div>';
2399 print
'<table class="border tableforfield centpercent">';
2401 if ($soc->outstanding_limit) {
2403 print
'<tr><td class="titlefield">';
2404 print $langs->trans(
'OutstandingBill');
2405 print
'</td><td class="valuefield">';
2406 $arrayoutstandingbills = $soc->getOutstandingBills();
2407 print
price($arrayoutstandingbills[
'opened']).
' / ';
2408 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2414 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2415 $filterabsolutediscount =
"fk_facture_source IS NULL";
2416 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2418 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2419 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2422 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2423 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2424 $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>';
2426 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2428 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2429 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2430 $absolute_discount =
price2num($absolute_discount,
'MT');
2431 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2435 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2436 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2443 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2444 print
'</td><td class="valuefield">';
2445 if ($action ==
'editdate') {
2446 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2447 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2448 print
'<input type="hidden" name="action" value="setdate">';
2449 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2450 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2453 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2454 if ($object->hasDelay() && empty($object->delivery_date)) {
2455 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2463 $editenable = $usercancreate;
2464 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2465 print
'</td><td class="valuefield">';
2466 if ($action ==
'editdate_livraison') {
2467 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2468 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2469 print
'<input type="hidden" name="action" value="setdate_livraison">';
2470 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2471 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2474 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2475 if ($object->hasDelay() && !empty($object->delivery_date)) {
2476 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2483 print
'<tr class="fielddeliverydelay"><td>';
2484 $editenable = $usercancreate;
2485 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2486 print
'</td><td class="valuefield">';
2487 if ($action ==
'editavailability') {
2488 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2490 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2497 $editenable = $usercancreate;
2498 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2499 print
'</td><td class="valuefield">';
2500 if ($action ==
'editshippingmethod') {
2501 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2503 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2510 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2511 $langs->load(
'stocks');
2512 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2515 $editenable = $usercancreate;
2516 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2517 print
'</td><td class="valuefield">';
2518 if ($action ==
'editwarehouse') {
2519 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2521 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2529 $editenable = $usercancreate;
2530 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2531 print
'</td><td class="valuefield">';
2532 if ($action ==
'editdemandreason') {
2533 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2535 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2541 $editenable = $usercancreate;
2542 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2543 print
'</td><td class="valuefield">';
2544 if ($action ==
'editconditions') {
2545 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2547 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2555 $editenable = $usercancreate;
2556 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2557 print
'</td><td class="valuefield">';
2558 if ($action ==
'editmode') {
2559 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2561 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2571 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2572 print
'</td><td class="valuefield">';
2573 if ($action ==
'editmulticurrencycode') {
2574 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2576 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2581 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2584 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2585 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2586 print
'</td><td class="valuefield">';
2587 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2588 if ($action ==
'actualizemulticurrencyrate') {
2591 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2593 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2594 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2595 print
'<div class="inline-block"> ';
2596 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2618 $tmparray = $object->getTotalWeightVolume();
2619 $totalWeight = $tmparray[
'weight'];
2620 $totalVolume = $tmparray[
'volume'];
2622 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2623 print
'<td class="valuefield">';
2624 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');
2628 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2629 print
'<td class="valuefield">';
2630 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');
2639 $editenable = $usercancreate;
2640 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2642 print
'<td class="valuefield">';
2643 if ($action !=
'editincoterm') {
2644 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2646 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2652 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
2654 $editenable = $usercancreate;
2655 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2656 print
'</td><td class="valuefield">';
2657 if ($action ==
'editbankaccount') {
2658 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2660 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2667 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2672 print
'<div class="fichehalfright">';
2673 print
'<div class="underbanner clearboth"></div>';
2675 print
'<table class="border tableforfield centpercent">';
2677 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
2679 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2680 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>';
2684 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2685 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>';
2689 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2690 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>';
2696 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2697 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2699 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2700 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2703 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>';
2706 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2707 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2708 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2710 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2711 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2712 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2716 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>';
2725 $formmargin->displayMarginInfos($object);
2732 print
'<div class="clearboth"></div><br>';
2734 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2735 $blocname =
'contacts';
2736 $title = $langs->trans(
'ContactsAddresses');
2737 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2740 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2741 $blocname =
'notes';
2742 $title = $langs->trans(
'Notes');
2743 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2751 $result = $object->getLinesArray();
2755 global $inputalsopricewithtax;
2756 $inputalsopricewithtax = 1;
2758 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2759 <input type="hidden" name="token" value="' .
newToken().
'">
2760 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2761 <input type="hidden" name="mode" value="">
2762 <input type="hidden" name="page_y" value="">
2763 <input type="hidden" name="id" value="' . $object->id.
'">';
2766 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2769 print
'<div class="div-table-responsive-no-min">';
2770 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2773 if (!empty($object->lines)) {
2774 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2777 $numlines = count($object->lines);
2783 if ($action !=
'editline') {
2788 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2789 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2790 if (empty($reshook))
2791 $object->formAddObjectLine(1, $mysoc, $soc);
2804 if ($action !=
'presend' && $action !=
'editline') {
2805 print
'<div class="tabsAction">';
2809 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2810 if (empty($reshook)) {
2813 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2817 if (empty($user->socid)) {
2818 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2820 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2822 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2828 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2829 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2833 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2845 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2847 if ($usercancreatepurchaseorder) {
2848 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2855 $langs->load(
"interventions");
2858 if ($user->hasRight(
'ficheinter',
'creer')) {
2859 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2861 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2868 $langs->load(
"contracts");
2870 if ($user->hasRight(
'contrat',
'creer')) {
2871 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2878 $numshipping = $object->countNbOfShipments();
2881 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2882 if ($user->hasRight(
'expedition',
'creer')) {
2883 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2885 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2888 $langs->load(
"errors");
2889 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2896 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2901 if (
isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2902 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,
'');
2904 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2905 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2909 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2910 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2914 if ($usercancreate) {
2915 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2920 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2924 if ($usercandelete) {
2925 if ($numshipping == 0) {
2926 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2928 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2936 if (
GETPOST(
'modelselected')) {
2937 $action =
'presend';
2940 if ($action !=
'presend') {
2941 print
'<div class="fichecenter"><div class="fichehalfleft">';
2942 print
'<a name="builddoc"></a>';
2945 $relativepath = $objref.
'/'.$objref.
'.pdf';
2946 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2947 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2948 $genallowed = $usercanread;
2949 $delallowed = $usercancreate;
2950 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2954 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'order'));
2956 $compatibleImportElementsList =
false;
2959 $compatibleImportElementsList = array(
'commande',
'propal');
2961 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2965 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2966 $useonlinepayment = 0;
2969 print
'<br><!-- Link to pay -->';
2970 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
2971 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
2974 print
'</div><div class="fichehalfright">';
2977 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2979 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
2981 print
'</div></div>';
2985 $modelmail =
'order_send';
2986 $defaulttopic =
'SendOrderRef';
2987 $diroutput = $conf->commande->multidir_output[$object->entity];
2988 $trackid =
'ord'.$object->id;
2990 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';