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') {
687 $idprod =
GETPOST(
'idprod',
'int');
694 if (empty($remise_percent)) {
699 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
700 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
702 if (is_array($extralabelsline)) {
704 foreach ($extralabelsline as $key => $value) {
705 unset($_POST[
"options_".$key]);
709 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
710 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
713 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
714 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
717 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
718 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
722 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
726 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
729 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
730 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
734 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
735 if ($combinations =
GETPOST(
'combinations',
'array')) {
739 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
740 $idprod = $res->fk_product_child;
742 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
748 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
752 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
758 if (!empty($idprod) && $idprod > 0) {
760 $prod->fetch($idprod);
762 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
767 if (empty($tva_tx)) {
771 $pu_ht = $prod->price;
772 $pu_ttc = $prod->price_ttc;
773 $price_min = $prod->price_min;
774 $price_min_ttc = $prod->price_min_ttc;
775 $price_base_type = $prod->price_base_type;
778 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
779 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
780 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
781 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
782 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
783 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
784 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
785 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
786 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
788 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
789 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
792 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
794 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
798 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
800 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
802 if (count($prodcustprice->lines) > 0) {
803 $pu_ht =
price($prodcustprice->lines[0]->price);
804 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
805 $price_min =
price($prodcustprice->lines[0]->price_min);
806 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
807 $price_base_type = $prodcustprice->lines[0]->price_base_type;
808 $tva_tx = $prodcustprice->lines[0]->tva_tx;
809 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
810 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
812 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
813 if (empty($tva_tx)) {
820 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
822 if ($prod->prices_by_qty[0]) {
827 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
828 if ($priceforthequantityarray[
'rowid'] != $pqp) {
832 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
833 $pu_ht = $priceforthequantityarray[
'unitprice'];
835 $pu_ttc = $priceforthequantityarray[
'unitprice'];
841 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
843 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
847 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
848 if ($priceforthequantityarray[
'rowid'] != $pqp) {
852 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
853 $pu_ht = $priceforthequantityarray[
'unitprice'];
855 $pu_ttc = $priceforthequantityarray[
'unitprice'];
863 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
864 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
867 if (!empty($price_ht) || $price_ht ===
'0') {
869 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
870 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
872 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
873 } elseif ($tmpvat != $tmpprodvat) {
875 if ($price_base_type !=
'HT') {
876 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
878 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
885 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
886 $outputlangs = $langs;
888 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
889 $newlang =
GETPOST(
'lang_id',
'aZ09');
891 if (empty($newlang)) {
892 $newlang = $object->thirdparty->default_lang;
894 if (!empty($newlang)) {
896 $outputlangs->setDefaultLang($newlang);
899 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
901 $desc = $prod->description;
905 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
909 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
910 $desc = $product_desc;
912 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
916 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
919 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
920 $outputlangs = $langs;
922 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
923 $newlang =
GETPOST(
'lang_id',
'alpha');
925 if (empty($newlang)) {
926 $newlang = $object->thirdparty->default_lang;
928 if (!empty($newlang)) {
930 $outputlangs->setDefaultLang($newlang);
931 $outputlangs->load(
'products');
933 if (!empty($prod->customcode)) {
934 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
936 if (!empty($prod->customcode) && !empty($prod->country_code)) {
939 if (!empty($prod->country_code)) {
940 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
943 if (!empty($prod->customcode)) {
944 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
946 if (!empty($prod->customcode) && !empty($prod->country_code)) {
949 if (!empty($prod->country_code)) {
950 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
958 $fk_unit = $prod->fk_unit;
962 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
963 $tva_tx = str_replace(
'*',
'', $tva_tx);
964 if (empty($tva_tx)) {
967 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
968 $desc = $product_desc;
970 $fk_unit =
GETPOST(
'units',
'alpha');
971 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
972 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
974 if ($pu_ttc && !$pu_ht) {
975 $price_base_type =
'TTC';
985 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
986 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
993 $pu_equivalent = $pu_ht;
994 $pu_equivalent_ttc = $pu_ttc;
996 $currency_tx = $object->multicurrency_tx;
1000 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1001 $pu_equivalent = $pu_ht_devise * $currency_tx;
1003 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1004 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1021 if ($usermustrespectpricemin) {
1022 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1023 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1026 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1027 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1035 $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);
1038 $ret = $object->fetch($object->id);
1039 $object->fetch_thirdparty();
1041 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1043 $outputlangs = $langs;
1044 $newlang =
GETPOST(
'lang_id',
'alpha');
1046 $newlang = $object->thirdparty->default_lang;
1048 if (!empty($newlang)) {
1049 $outputlangs =
new Translate(
"", $conf);
1050 $outputlangs->setDefaultLang($newlang);
1053 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1056 unset($_POST[
'prod_entry_mode']);
1058 unset($_POST[
'qty']);
1059 unset($_POST[
'type']);
1060 unset($_POST[
'remise_percent']);
1061 unset($_POST[
'price_ht']);
1062 unset($_POST[
'multicurrency_price_ht']);
1063 unset($_POST[
'price_ttc']);
1064 unset($_POST[
'tva_tx']);
1065 unset($_POST[
'product_ref']);
1066 unset($_POST[
'product_label']);
1067 unset($_POST[
'product_desc']);
1068 unset($_POST[
'fournprice']);
1069 unset($_POST[
'buying_price']);
1070 unset($_POST[
'np_marginRate']);
1071 unset($_POST[
'np_markRate']);
1072 unset($_POST[
'dp_desc']);
1073 unset($_POST[
'idprod']);
1074 unset($_POST[
'units']);
1076 unset($_POST[
'date_starthour']);
1077 unset($_POST[
'date_startmin']);
1078 unset($_POST[
'date_startsec']);
1079 unset($_POST[
'date_startday']);
1080 unset($_POST[
'date_startmonth']);
1081 unset($_POST[
'date_startyear']);
1082 unset($_POST[
'date_endhour']);
1083 unset($_POST[
'date_endmin']);
1084 unset($_POST[
'date_endsec']);
1085 unset($_POST[
'date_endday']);
1086 unset($_POST[
'date_endmonth']);
1087 unset($_POST[
'date_endyear']);
1093 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1105 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1110 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1111 $vat_rate = str_replace(
'*',
'', $vat_rate);
1112 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1113 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1123 $pu_equivalent = $pu_ht;
1124 $pu_equivalent_ttc = $pu_ttc;
1126 $currency_tx = $object->multicurrency_tx;
1130 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1131 $pu_equivalent = $pu_ht_devise * $currency_tx;
1133 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1134 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1153 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1154 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1156 if (is_array($extralabelsline)) {
1157 foreach ($extralabelsline as $key => $value) {
1158 unset($_POST[
"options_".$key]);
1163 $special_code =
GETPOST(
'special_code');
1171 $productid =
GETPOST(
'productid',
'int');
1172 if (!empty($productid)) {
1174 $product->fetch($productid);
1176 $type = $product->type;
1178 $price_min = $product->price_min;
1179 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1180 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1182 $price_min_ttc = $product->price_min_ttc;
1183 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1184 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1190 if ($usermustrespectpricemin) {
1191 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1192 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1195 $action =
'editline';
1196 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1197 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1200 $action =
'editline';
1205 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1209 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1211 $action =
'editline';
1216 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1218 $action =
'editline';
1222 if (empty($user->rights->margins->creer)) {
1223 foreach ($object->lines as &$line) {
1224 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1225 $fournprice = $line->fk_fournprice;
1226 $buyingprice = $line->pa_ht;
1232 $price_base_type =
'HT';
1234 if (empty($pu) && !empty($pu_ttc)) {
1236 $price_base_type =
'TTC';
1239 $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);
1242 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1244 $outputlangs = $langs;
1247 $newlang =
GETPOST(
'lang_id',
'aZ09');
1250 $newlang = $object->thirdparty->default_lang;
1252 if (!empty($newlang)) {
1253 $outputlangs =
new Translate(
"", $conf);
1254 $outputlangs->setDefaultLang($newlang);
1257 $ret = $object->fetch($object->id);
1258 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1261 unset($_POST[
'qty']);
1262 unset($_POST[
'type']);
1263 unset($_POST[
'productid']);
1264 unset($_POST[
'remise_percent']);
1265 unset($_POST[
'price_ht']);
1266 unset($_POST[
'multicurrency_price_ht']);
1267 unset($_POST[
'price_ttc']);
1268 unset($_POST[
'tva_tx']);
1269 unset($_POST[
'product_ref']);
1270 unset($_POST[
'product_label']);
1271 unset($_POST[
'product_desc']);
1272 unset($_POST[
'fournprice']);
1273 unset($_POST[
'buying_price']);
1275 unset($_POST[
'date_starthour']);
1276 unset($_POST[
'date_startmin']);
1277 unset($_POST[
'date_startsec']);
1278 unset($_POST[
'date_startday']);
1279 unset($_POST[
'date_startmonth']);
1280 unset($_POST[
'date_startyear']);
1281 unset($_POST[
'date_endhour']);
1282 unset($_POST[
'date_endmin']);
1283 unset($_POST[
'date_endsec']);
1284 unset($_POST[
'date_endday']);
1285 unset($_POST[
'date_endmonth']);
1286 unset($_POST[
'date_endyear']);
1291 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1292 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1294 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1295 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1297 $qualified_for_stock_change = 0;
1298 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1299 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1301 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1305 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1306 if (!$idwarehouse || $idwarehouse == -1) {
1308 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1314 $locationTarget =
'';
1316 $result = $object->valid($user, $idwarehouse);
1321 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1324 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1325 &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
1327 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1330 $forceFields = array();
1333 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1340 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1351 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1352 $outputlangs = $langs;
1355 $newlang =
GETPOST(
'lang_id',
'aZ09');
1358 $newlang = $object->thirdparty->default_lang;
1360 if (!empty($newlang)) {
1361 $outputlangs =
new Translate(
"", $conf);
1362 $outputlangs->setDefaultLang($newlang);
1364 $model = $object->model_pdf;
1365 $ret = $object->fetch($id);
1367 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1370 $deposit->fetch($deposit->id);
1371 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1375 if ($locationTarget) {
1376 header(
'Location: ' . $locationTarget);
1387 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1389 $idwarehouse =
GETPOST(
'idwarehouse');
1391 $qualified_for_stock_change = 0;
1392 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1393 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1395 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1399 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1400 if (!$idwarehouse || $idwarehouse == -1) {
1402 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1408 $result = $object->setDraft($user, $idwarehouse);
1411 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1412 $outputlangs = $langs;
1415 $newlang =
GETPOST(
'lang_id',
'aZ09');
1418 $newlang = $object->thirdparty->default_lang;
1420 if (!empty($newlang)) {
1421 $outputlangs =
new Translate(
"", $conf);
1422 $outputlangs->setDefaultLang($newlang);
1424 $model = $object->model_pdf;
1425 $ret = $object->fetch($id);
1427 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1431 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1432 $result = $object->cloture($user);
1436 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1437 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1439 $qualified_for_stock_change = 0;
1440 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1441 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1443 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1447 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1448 if (!$idwarehouse || $idwarehouse == -1) {
1450 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1456 $result = $object->cancel($idwarehouse);
1464 if ($action ==
'update_extras') {
1468 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1475 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1483 $action =
'edit_extras';
1488 if ($action ==
'import_lines_from_object'
1492 $fromElement =
GETPOST(
'fromelement');
1493 $fromElementid =
GETPOST(
'fromelementid');
1494 $importLines =
GETPOST(
'line_checkbox');
1496 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1497 if ($fromElement ==
'commande') {
1499 $lineClassName =
'OrderLine';
1500 } elseif ($fromElement ==
'propal') {
1501 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1502 $lineClassName =
'PropaleLigne';
1504 $nextRang = count($object->lines) + 1;
1507 foreach ($importLines as $lineId) {
1508 $lineId = intval($lineId);
1509 $originLine =
new $lineClassName($db);
1510 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1511 $originLine->fetch_optionals();
1512 $desc = $originLine->desc;
1513 $pu_ht = $originLine->subprice;
1514 $qty = $originLine->qty;
1515 $txtva = $originLine->tva_tx;
1516 $txlocaltax1 = $originLine->localtax1_tx;
1517 $txlocaltax2 = $originLine->localtax2_tx;
1518 $fk_product = $originLine->fk_product;
1519 $remise_percent = $originLine->remise_percent;
1520 $date_start = $originLine->date_start;
1521 $date_end = $originLine->date_end;
1523 $info_bits = $originLine->info_bits;
1524 $fk_remise_except = $originLine->fk_remise_except;
1525 $price_base_type =
'HT';
1527 $type = $originLine->product_type;
1528 $rang = $nextRang++;
1529 $special_code = $originLine->special_code;
1530 $origin = $originLine->element;
1531 $origin_id = $originLine->id;
1532 $fk_parent_line = 0;
1533 $fk_fournprice = $originLine->fk_fournprice;
1534 $pa_ht = $originLine->pa_ht;
1535 $label = $originLine->label;
1536 $array_options = $originLine->array_options;
1537 $situation_percent = 100;
1539 $fk_unit = $originLine->fk_unit;
1540 $pu_ht_devise = $originLine->multicurrency_subprice;
1542 $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);
1561 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1564 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1565 $permissiontoadd = $usercancreate;
1566 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1569 $triggersendname =
'ORDER_SENTBYMAIL';
1571 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1572 $trackid =
'ord'.$object->id;
1573 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1576 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1577 if ($action ==
'addcontact') {
1578 if ($object->id > 0) {
1581 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1585 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1588 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1589 $langs->load(
"errors");
1590 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1595 } elseif ($action ==
'swapstatut') {
1597 if ($object->id > 0) {
1598 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1602 } elseif ($action ==
'deletecontact') {
1604 $result = $object->delete_contact($lineid);
1607 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1621 $title = $object->ref.
" - ".$langs->trans(
'Card');
1622 if ($action ==
'create') {
1623 $title = $langs->trans(
"NewOrder");
1625 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1638 if ($action ==
'create' && $usercancreate) {
1643 $res = $soc->fetch($socid);
1646 $remise_absolue = 0;
1648 $currency_code = $conf->currency;
1650 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1651 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1652 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1654 if (!empty($origin) && !empty($originid)) {
1656 $element = $subelement = $origin;
1658 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1659 $element = $regs[1];
1660 $subelement = $regs[2];
1663 if ($element ==
'project') {
1664 $projectid = $originid;
1666 if (!$cond_reglement_id) {
1667 $cond_reglement_id = $soc->cond_reglement_id;
1669 if (!$deposit_percent) {
1670 $deposit_percent = $soc->deposit_percent;
1672 if (!$mode_reglement_id) {
1673 $mode_reglement_id = $soc->mode_reglement_id;
1675 if (!$remise_percent) {
1676 $remise_percent = $soc->remise_percent;
1684 if ($element ==
'order' || $element ==
'commande') {
1685 $element = $subelement =
'commande';
1686 } elseif ($element ==
'propal') {
1687 $element =
'comm/propal';
1688 $subelement =
'propal';
1689 } elseif ($element ==
'contract') {
1690 $element = $subelement =
'contrat';
1695 $classname = ucfirst($subelement);
1696 $objectsrc =
new $classname($db);
1697 $objectsrc->fetch($originid);
1698 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1699 $objectsrc->fetch_lines();
1701 $objectsrc->fetch_thirdparty();
1704 $objectsrc->fetch_optionals();
1705 $object->array_options = $objectsrc->array_options;
1707 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1708 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1710 $soc = $objectsrc->thirdparty;
1711 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1712 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1713 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1714 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1715 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1716 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1717 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1718 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1719 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1720 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1721 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1723 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1724 if (empty($date_delivery)) {
1725 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1729 if (!empty($objectsrc->multicurrency_code)) {
1730 $currency_code = $objectsrc->multicurrency_code;
1732 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1733 $currency_tx = $objectsrc->multicurrency_tx;
1737 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1738 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1741 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1744 $cond_reglement_id = $soc->cond_reglement_id;
1745 $deposit_percent = $soc->deposit_percent;
1746 $mode_reglement_id = $soc->mode_reglement_id;
1747 $fk_account = $soc->fk_account;
1748 $availability_id = 0;
1749 $shipping_method_id = $soc->shipping_method_id;
1750 $warehouse_id = $soc->fk_warehouse;
1751 $demand_reason_id = $soc->demand_reason_id;
1752 $remise_percent = $soc->remise_percent;
1753 $remise_absolue = 0;
1754 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1756 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1757 $currency_code = $soc->multicurrency_code;
1760 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1761 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1765 if ($soc->fk_warehouse > 0) {
1766 $warehouse_id = $soc->fk_warehouse;
1768 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1769 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1770 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1772 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1773 $warehouse_id = $user->fk_warehouse;
1777 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1778 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1779 print
'<input type="hidden" name="action" value="add">';
1780 print
'<input type="hidden" name="changecompany" value="0">';
1781 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1782 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1783 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1784 if (!empty($currency_tx)) {
1785 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1790 print
'<table class="border centpercent">';
1793 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1796 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1797 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1798 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1800 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1806 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1809 print $soc->getNomUrl(1,
'customer');
1810 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1814 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');
1816 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1817 print
'<script type="text/javascript">
1818 $(document).ready(function() {
1819 $("#socid").change(function() {
1820 console.log("We have changed the company - Reload page");
1821 var socid = $(this).val();
1823 $("input[name=action]").val("create");
1824 $("input[name=changecompany]").val("1");
1825 $("form[name=crea_commande]").submit();
1830 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>';
1838 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1839 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1840 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1844 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1846 $absolute_discount = $soc->getAvailableDiscounts();
1850 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1851 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1857 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1858 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1862 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1863 print
'<td colspan="3">';
1864 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1865 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1870 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1871 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1872 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id') : $availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1876 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1877 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1878 print
$form->getSelectConditionsPaiements(((
GETPOSTISSET(
'cond_reglement_id') &&
GETPOST(
'cond_reglement_id',
'int') != 0) ?
GETPOST(
'cond_reglement_id') : $cond_reglement_id),
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1882 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1883 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1884 print
$form->select_types_paiements(((
GETPOSTISSET(
'mode_reglement_id') &&
GETPOST(
'mode_reglement_id',
'int') != 0) ?
GETPOST(
'mode_reglement_id') : $mode_reglement_id),
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1888 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
1889 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1890 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes(((
GETPOSTISSET(
'fk_account') &&
GETPOST(
'fk_account',
'int') != 0) ?
GETPOST(
'fk_account') : $fk_account),
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1896 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1897 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
1898 $form->selectShippingMethod(((
GETPOSTISSET(
'shipping_method_id') &&
GETPOST(
'shipping_method_id',
'int') != 0) ?
GETPOST(
'shipping_method_id') : $shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1903 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1904 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1906 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1907 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');
1912 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1913 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1914 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id')?
GETPOST(
'demand_reason_id'):$demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1921 $langs->load(
"projects");
1923 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1924 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');
1925 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>';
1933 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
1934 print
'<td class="maxwidthonsmartphone">';
1935 $incoterm_id =
GETPOST(
'incoterm_id');
1936 $incoterm_location =
GETPOST(
'location_incoterms');
1937 if (empty($incoterm_id)) {
1938 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1939 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1941 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1947 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1953 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1954 print $hookmanager->resPrint;
1955 if (empty($reshook)) {
1956 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1958 $tpExtrafields =
new Extrafields($db);
1959 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1960 if ($soc->fetch_optionals() > 0) {
1961 $object->array_options = array_merge($object->array_options, $soc->array_options);
1965 print $object->showOptionals($extrafields,
'create',
$parameters);
1969 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1971 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1973 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1974 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1975 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1981 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1982 print
'<td class="maxwidthonsmartphone">';
1983 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code')?
GETPOST(
'multicurrency_code'):$currency_code),
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1989 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1992 $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%');
1993 print $doleditor->Create(1);
1998 if (empty($user->socid)) {
2000 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
2003 $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%');
2004 print $doleditor->Create(1);
2009 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2011 if ($origin ==
'contrat') {
2013 $objectsrc->remise_absolue = $remise_absolue;
2014 $objectsrc->remise_percent = $remise_percent;
2015 $objectsrc->update_price(1);
2018 print
"\n<!-- ".$classname.
" info -->";
2020 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2021 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2022 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2023 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2024 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2026 switch ($classname) {
2028 $newclassname =
'CommercialProposal';
2031 $newclassname =
'Order';
2034 $newclassname =
'Sending';
2037 $newclassname =
'Contract';
2040 $newclassname = $classname;
2043 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2046 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2047 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2048 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2049 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2052 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2053 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2056 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2059 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2060 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2061 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2071 print
$form->buttonsSaveCancel(
"CreateDraft");
2074 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2075 $title = $langs->trans(
'ProductsAndServices');
2078 print
'<div class="div-table-responsive-no-min">';
2079 print
'<table class="noborder centpercent">';
2081 $objectsrc->printOriginLinesList(
'', $selectedLines);
2092 if ($object->id > 0) {
2093 $product_static =
new Product($db);
2096 $soc->fetch($object->socid);
2098 $author =
new User($db);
2099 $author->fetch($object->user_author_id);
2101 $object->fetch_thirdparty();
2102 $res = $object->fetch_optionals();
2105 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2110 if ($action ==
'delete') {
2111 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2115 if ($action ==
'validate') {
2117 $ref = substr($object->ref, 1, 4);
2118 if ($ref ==
'PROV' || $ref ==
'') {
2119 $numref = $object->getNextNumRef($soc);
2120 if (empty($numref)) {
2125 $numref = $object->ref;
2128 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2130 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2131 $notify =
new Notify($db);
2133 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
2136 $qualified_for_stock_change = 0;
2137 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2138 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2140 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2143 $formquestion = array();
2144 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2145 $langs->load(
"stocks");
2146 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2149 if ($conf->browser->name ==
'ie') {
2152 $formquestion = array(
2156 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))
2162 foreach ($object->lines as $line) {
2163 $res = $line->fetch_product();
2165 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2171 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2173 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2178 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2180 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2181 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2183 $object->fetchObjectLinked();
2185 $eligibleForDepositGeneration =
true;
2187 if (array_key_exists(
'facture', $object->linkedObjects)) {
2188 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2190 $eligibleForDepositGeneration =
false;
2196 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2197 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2198 $proposal->fetchObjectLinked();
2200 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2201 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2203 $eligibleForDepositGeneration =
false;
2211 if ($eligibleForDepositGeneration) {
2212 $formquestion[] = array(
2213 'type' =>
'checkbox',
2215 'name' =>
'generate_deposit',
2216 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2219 $formquestion[] = array(
2221 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2223 'label' => $langs->trans(
'DateInvoice'),
2228 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2229 $formquestion[] = array(
2231 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2232 'name' =>
'date_pointoftax',
2233 'label' => $langs->trans(
'DatePointOfTax'),
2240 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2242 $formquestion[] = array(
2244 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2245 'name' =>
'cond_reglement_id',
2246 'label' => $langs->trans(
'PaymentTerm'),
2247 'value' => $paymentTermsSelect
2250 $formquestion[] = array(
2251 'type' =>
'checkbox',
2252 'tdclass' =>
'showonlyifgeneratedeposit',
2253 'name' =>
'validate_generated_deposit',
2254 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2257 $formquestion[] = array(
2258 'type' =>
'onecolumn',
2261 $(document).ready(function() {
2262 $("[name=generate_deposit]").change(function () {
2263 let $self = $(this);
2264 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2266 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2283 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2288 if ($action ==
'modif') {
2289 $qualified_for_stock_change = 0;
2290 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2291 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2293 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2296 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2297 $formquestion = array();
2298 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2299 $langs->load(
"stocks");
2300 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2303 if ($conf->browser->name ==
'ie') {
2306 $formquestion = array(
2310 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2314 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2320 if ($action ==
'shipped') {
2321 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2327 if ($action ==
'cancel') {
2328 $qualified_for_stock_change = 0;
2329 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2330 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2332 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2335 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2336 $formquestion = array();
2337 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2338 $langs->load(
"stocks");
2339 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2342 if ($conf->browser->name ==
'ie') {
2345 $formquestion = array(
2349 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2353 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2357 if ($action ==
'ask_deleteline') {
2358 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2362 if ($action ==
'clone') {
2364 $formquestion = array(
2365 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'))
2367 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2373 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2374 if (empty($reshook)) {
2376 } elseif ($reshook > 0) {
2386 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2388 $morehtmlref =
'<div class="refidno">';
2390 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2391 $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);
2393 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2394 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2395 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2399 $langs->load(
"projects");
2400 $morehtmlref .=
'<br>';
2401 if ($usercancreate) {
2402 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2403 if ($action !=
'classify') {
2404 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2406 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2408 if (!empty($object->fk_project)) {
2410 $proj->fetch($object->fk_project);
2411 $morehtmlref .= $proj->getNomUrl(1);
2413 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2418 $morehtmlref .=
'</div>';
2421 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2424 print
'<div class="fichecenter">';
2425 print
'<div class="fichehalfleft">';
2426 print
'<div class="underbanner clearboth"></div>';
2428 print
'<table class="border tableforfield centpercent">';
2430 if ($soc->outstanding_limit) {
2432 print
'<tr><td class="titlefield">';
2433 print $langs->trans(
'OutstandingBill');
2434 print
'</td><td class="valuefield">';
2435 $arrayoutstandingbills = $soc->getOutstandingBills();
2436 print
price($arrayoutstandingbills[
'opened']).
' / ';
2437 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2443 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2444 $filterabsolutediscount =
"fk_facture_source IS NULL";
2445 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2447 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2448 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2451 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2452 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2453 $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>';
2455 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2457 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2458 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2459 $absolute_discount =
price2num($absolute_discount,
'MT');
2460 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2464 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2465 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2472 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2473 print
'</td><td class="valuefield">';
2474 if ($action ==
'editdate') {
2475 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2476 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2477 print
'<input type="hidden" name="action" value="setdate">';
2478 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2479 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2482 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2483 if ($object->hasDelay() && empty($object->delivery_date)) {
2484 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2492 $editenable = $usercancreate;
2493 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2494 print
'</td><td class="valuefield">';
2495 if ($action ==
'editdate_livraison') {
2496 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2497 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2498 print
'<input type="hidden" name="action" value="setdate_livraison">';
2499 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2500 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2503 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2504 if ($object->hasDelay() && !empty($object->delivery_date)) {
2505 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2512 print
'<tr class="fielddeliverydelay"><td>';
2513 $editenable = $usercancreate;
2514 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2515 print
'</td><td class="valuefield">';
2516 if ($action ==
'editavailability') {
2517 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2519 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2526 $editenable = $usercancreate;
2527 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2528 print
'</td><td class="valuefield">';
2529 if ($action ==
'editshippingmethod') {
2530 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2532 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2539 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2540 $langs->load(
'stocks');
2541 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2544 $editenable = $usercancreate;
2545 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2546 print
'</td><td class="valuefield">';
2547 if ($action ==
'editwarehouse') {
2548 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2550 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2558 $editenable = $usercancreate;
2559 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2560 print
'</td><td class="valuefield">';
2561 if ($action ==
'editdemandreason') {
2562 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2564 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2570 $editenable = $usercancreate;
2571 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2572 print
'</td><td class="valuefield">';
2573 if ($action ==
'editconditions') {
2574 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2576 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2584 $editenable = $usercancreate;
2585 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2586 print
'</td><td class="valuefield">';
2587 if ($action ==
'editmode') {
2588 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2590 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2600 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2601 print
'</td><td class="valuefield">';
2602 if ($action ==
'editmulticurrencycode') {
2603 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2605 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2610 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2613 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2614 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2615 print
'</td><td class="valuefield">';
2616 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2617 if ($action ==
'actualizemulticurrencyrate') {
2620 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2622 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2623 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2624 print
'<div class="inline-block"> ';
2625 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2647 $tmparray = $object->getTotalWeightVolume();
2648 $totalWeight = $tmparray[
'weight'];
2649 $totalVolume = $tmparray[
'volume'];
2651 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2652 print
'<td class="valuefield">';
2653 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');
2657 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2658 print
'<td class="valuefield">';
2659 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');
2668 $editenable = $usercancreate;
2669 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2671 print
'<td class="valuefield">';
2672 if ($action !=
'editincoterm') {
2673 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2675 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2681 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
2683 $editenable = $usercancreate;
2684 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2685 print
'</td><td class="valuefield">';
2686 if ($action ==
'editbankaccount') {
2687 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2689 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2696 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2701 print
'<div class="fichehalfright">';
2702 print
'<div class="underbanner clearboth"></div>';
2704 print
'<table class="border tableforfield centpercent">';
2706 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
2708 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2709 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>';
2713 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2714 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>';
2718 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2719 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>';
2725 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2726 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2728 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2729 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2732 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>';
2735 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2736 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2737 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2739 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2740 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2741 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2745 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>';
2754 $formmargin->displayMarginInfos($object);
2761 print
'<div class="clearboth"></div><br>';
2763 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2764 $blocname =
'contacts';
2765 $title = $langs->trans(
'ContactsAddresses');
2766 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2769 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2770 $blocname =
'notes';
2771 $title = $langs->trans(
'Notes');
2772 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2780 $result = $object->getLinesArray();
2784 global $inputalsopricewithtax;
2785 $inputalsopricewithtax = 1;
2787 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2788 <input type="hidden" name="token" value="' .
newToken().
'">
2789 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2790 <input type="hidden" name="mode" value="">
2791 <input type="hidden" name="page_y" value="">
2792 <input type="hidden" name="id" value="' . $object->id.
'">';
2795 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2798 print
'<div class="div-table-responsive-no-min">';
2799 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2802 if (!empty($object->lines)) {
2803 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2806 $numlines = count($object->lines);
2812 if ($action !=
'editline') {
2817 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2818 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2819 if (empty($reshook))
2820 $object->formAddObjectLine(1, $mysoc, $soc);
2833 if ($action !=
'presend' && $action !=
'editline') {
2834 print
'<div class="tabsAction">';
2838 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2839 if (empty($reshook)) {
2842 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2846 if (empty($user->socid)) {
2847 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2849 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2851 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2857 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2858 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2862 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2874 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2876 if ($usercancreatepurchaseorder) {
2877 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id,
'');
2884 $langs->load(
"interventions");
2887 if ($user->hasRight(
'ficheinter',
'creer')) {
2888 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2890 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2897 $langs->load(
"contracts");
2899 if ($user->hasRight(
'contrat',
'creer')) {
2900 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2907 $numshipping = $object->nb_expedition();
2910 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2911 if ($user->hasRight(
'expedition',
'creer')) {
2912 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2914 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2917 $langs->load(
"errors");
2918 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2925 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2930 if (
isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2931 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,
'');
2933 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2934 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2938 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2939 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2943 if ($usercancreate) {
2944 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2949 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2953 if ($usercandelete) {
2954 if ($numshipping == 0) {
2955 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2957 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2965 if (
GETPOST(
'modelselected')) {
2966 $action =
'presend';
2969 if ($action !=
'presend') {
2970 print
'<div class="fichecenter"><div class="fichehalfleft">';
2971 print
'<a name="builddoc"></a>';
2974 $relativepath = $objref.
'/'.$objref.
'.pdf';
2975 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2976 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2977 $genallowed = $usercanread;
2978 $delallowed = $usercancreate;
2979 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2983 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'order'));
2985 $compatibleImportElementsList =
false;
2988 $compatibleImportElementsList = array(
'commande',
'propal');
2990 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2994 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2995 $useonlinepayment = 0;
2998 print
'<br><!-- Link to pay -->';
2999 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3000 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
3003 print
'</div><div class="fichehalfright">';
3006 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3008 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
3010 print
'</div></div>';
3014 $modelmail =
'order_send';
3015 $defaulttopic =
'SendOrderRef';
3016 $diroutput = $conf->commande->multidir_output[$object->entity];
3017 $trackid =
'ord'.$object->id;
3019 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';