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');
693 $pu_equivalent = $pu_ht;
694 $pu_equivalent_ttc = $pu_ttc;
695 $currency_tx = $object->multicurrency_tx;
699 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
700 $pu_equivalent = $pu_ht_devise * $currency_tx;
702 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
703 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
709 if (empty($remise_percent)) {
714 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
715 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
717 if (is_array($extralabelsline)) {
719 foreach ($extralabelsline as $key => $value) {
720 unset($_POST[
"options_".$key]);
724 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
725 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
728 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
729 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
732 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
733 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
737 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
741 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
744 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
745 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
749 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
750 if ($combinations =
GETPOST(
'combinations',
'array')) {
754 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
755 $idprod = $res->fk_product_child;
757 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
763 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
767 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
773 if (!empty($idprod) && $idprod > 0) {
775 $prod->fetch($idprod);
777 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
782 if (empty($tva_tx)) {
786 $pu_ht = $prod->price;
787 $pu_ttc = $prod->price_ttc;
788 $price_min = $prod->price_min;
789 $price_min_ttc = $prod->price_min_ttc;
790 $price_base_type = $prod->price_base_type;
793 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
794 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
795 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
796 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
797 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
798 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
799 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
800 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
801 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
803 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
804 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
807 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
809 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
813 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
815 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
817 if (count($prodcustprice->lines) > 0) {
818 $pu_ht =
price($prodcustprice->lines[0]->price);
819 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
820 $price_min =
price($prodcustprice->lines[0]->price_min);
821 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
822 $price_base_type = $prodcustprice->lines[0]->price_base_type;
823 $tva_tx = $prodcustprice->lines[0]->tva_tx;
824 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
825 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
827 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
828 if (empty($tva_tx)) {
835 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
837 if ($prod->prices_by_qty[0]) {
842 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
843 if ($priceforthequantityarray[
'rowid'] != $pqp) {
847 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
848 $pu_ht = $priceforthequantityarray[
'unitprice'];
850 $pu_ttc = $priceforthequantityarray[
'unitprice'];
856 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
858 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
862 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
863 if ($priceforthequantityarray[
'rowid'] != $pqp) {
867 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
868 $pu_ht = $priceforthequantityarray[
'unitprice'];
870 $pu_ttc = $priceforthequantityarray[
'unitprice'];
878 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
879 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
882 if (!empty($price_ht) || $price_ht ===
'0') {
884 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
885 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
887 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
888 } elseif ($tmpvat != $tmpprodvat) {
890 if ($price_base_type !=
'HT') {
891 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
893 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
900 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
901 $outputlangs = $langs;
903 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
904 $newlang =
GETPOST(
'lang_id',
'aZ09');
906 if (empty($newlang)) {
907 $newlang = $object->thirdparty->default_lang;
909 if (!empty($newlang)) {
911 $outputlangs->setDefaultLang($newlang);
914 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
916 $desc = $prod->description;
920 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
924 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
925 $desc = $product_desc;
927 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
931 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
934 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
935 $outputlangs = $langs;
937 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
938 $newlang =
GETPOST(
'lang_id',
'alpha');
940 if (empty($newlang)) {
941 $newlang = $object->thirdparty->default_lang;
943 if (!empty($newlang)) {
945 $outputlangs->setDefaultLang($newlang);
946 $outputlangs->load(
'products');
948 if (!empty($prod->customcode)) {
949 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
951 if (!empty($prod->customcode) && !empty($prod->country_code)) {
954 if (!empty($prod->country_code)) {
955 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
958 if (!empty($prod->customcode)) {
959 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
961 if (!empty($prod->customcode) && !empty($prod->country_code)) {
964 if (!empty($prod->country_code)) {
965 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
973 $fk_unit = $prod->fk_unit;
977 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
978 $tva_tx = str_replace(
'*',
'', $tva_tx);
979 if (empty($tva_tx)) {
982 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
983 $desc = $product_desc;
985 $fk_unit =
GETPOST(
'units',
'alpha');
986 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
987 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
989 if ($pu_ttc && !$pu_ht) {
990 $price_base_type =
'TTC';
999 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1000 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1009 if ($usermustrespectpricemin) {
1010 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1011 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1014 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1015 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1023 $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);
1026 $ret = $object->fetch($object->id);
1027 $object->fetch_thirdparty();
1029 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1031 $outputlangs = $langs;
1032 $newlang =
GETPOST(
'lang_id',
'alpha');
1034 $newlang = $object->thirdparty->default_lang;
1036 if (!empty($newlang)) {
1037 $outputlangs =
new Translate(
"", $conf);
1038 $outputlangs->setDefaultLang($newlang);
1041 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1044 unset($_POST[
'prod_entry_mode']);
1046 unset($_POST[
'qty']);
1047 unset($_POST[
'type']);
1048 unset($_POST[
'remise_percent']);
1049 unset($_POST[
'price_ht']);
1050 unset($_POST[
'multicurrency_price_ht']);
1051 unset($_POST[
'price_ttc']);
1052 unset($_POST[
'tva_tx']);
1053 unset($_POST[
'product_ref']);
1054 unset($_POST[
'product_label']);
1055 unset($_POST[
'product_desc']);
1056 unset($_POST[
'fournprice']);
1057 unset($_POST[
'buying_price']);
1058 unset($_POST[
'np_marginRate']);
1059 unset($_POST[
'np_markRate']);
1060 unset($_POST[
'dp_desc']);
1061 unset($_POST[
'idprod']);
1062 unset($_POST[
'units']);
1064 unset($_POST[
'date_starthour']);
1065 unset($_POST[
'date_startmin']);
1066 unset($_POST[
'date_startsec']);
1067 unset($_POST[
'date_startday']);
1068 unset($_POST[
'date_startmonth']);
1069 unset($_POST[
'date_startyear']);
1070 unset($_POST[
'date_endhour']);
1071 unset($_POST[
'date_endmin']);
1072 unset($_POST[
'date_endsec']);
1073 unset($_POST[
'date_endday']);
1074 unset($_POST[
'date_endmonth']);
1075 unset($_POST[
'date_endyear']);
1081 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1089 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1090 $vat_rate = str_replace(
'*',
'', $vat_rate);
1101 $pu_equivalent = $pu_ht;
1102 $pu_equivalent_ttc = $pu_ttc;
1103 $currency_tx = $object->multicurrency_tx;
1107 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1108 $pu_equivalent = $pu_ht_devise * $currency_tx;
1110 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1111 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1116 if (preg_match(
'/\*/', $vat_rate)) {
1121 $vat_rate = str_replace(
'*',
'', $vat_rate);
1122 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1123 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1130 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1131 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1133 if (is_array($extralabelsline)) {
1134 foreach ($extralabelsline as $key => $value) {
1135 unset($_POST[
"options_".$key]);
1140 $special_code =
GETPOST(
'special_code');
1148 $productid =
GETPOST(
'productid',
'int');
1149 if (!empty($productid)) {
1151 $product->fetch($productid);
1153 $type = $product->type;
1155 $price_min = $product->price_min;
1156 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1157 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1159 $price_min_ttc = $product->price_min_ttc;
1160 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1161 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1166 if ($usermustrespectpricemin) {
1167 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1168 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1171 $action =
'editline';
1172 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1173 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1176 $action =
'editline';
1181 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1185 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1187 $action =
'editline';
1192 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1194 $action =
'editline';
1198 if (empty($user->rights->margins->creer)) {
1199 foreach ($object->lines as &$line) {
1200 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1201 $fournprice = $line->fk_fournprice;
1202 $buyingprice = $line->pa_ht;
1208 $price_base_type =
'HT';
1210 if (empty($pu) && !empty($pu_ttc)) {
1212 $price_base_type =
'TTC';
1215 $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);
1218 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1220 $outputlangs = $langs;
1223 $newlang =
GETPOST(
'lang_id',
'aZ09');
1226 $newlang = $object->thirdparty->default_lang;
1228 if (!empty($newlang)) {
1229 $outputlangs =
new Translate(
"", $conf);
1230 $outputlangs->setDefaultLang($newlang);
1233 $ret = $object->fetch($object->id);
1234 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1237 unset($_POST[
'qty']);
1238 unset($_POST[
'type']);
1239 unset($_POST[
'productid']);
1240 unset($_POST[
'remise_percent']);
1241 unset($_POST[
'price_ht']);
1242 unset($_POST[
'multicurrency_price_ht']);
1243 unset($_POST[
'price_ttc']);
1244 unset($_POST[
'tva_tx']);
1245 unset($_POST[
'product_ref']);
1246 unset($_POST[
'product_label']);
1247 unset($_POST[
'product_desc']);
1248 unset($_POST[
'fournprice']);
1249 unset($_POST[
'buying_price']);
1251 unset($_POST[
'date_starthour']);
1252 unset($_POST[
'date_startmin']);
1253 unset($_POST[
'date_startsec']);
1254 unset($_POST[
'date_startday']);
1255 unset($_POST[
'date_startmonth']);
1256 unset($_POST[
'date_startyear']);
1257 unset($_POST[
'date_endhour']);
1258 unset($_POST[
'date_endmin']);
1259 unset($_POST[
'date_endsec']);
1260 unset($_POST[
'date_endday']);
1261 unset($_POST[
'date_endmonth']);
1262 unset($_POST[
'date_endyear']);
1267 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1268 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1270 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1271 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1273 $qualified_for_stock_change = 0;
1274 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1275 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1277 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1281 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1282 if (!$idwarehouse || $idwarehouse == -1) {
1284 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1290 $locationTarget =
'';
1292 $result = $object->valid($user, $idwarehouse);
1297 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1300 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1301 &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
1303 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1306 $forceFields = array();
1309 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1316 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1327 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1328 $outputlangs = $langs;
1331 $newlang =
GETPOST(
'lang_id',
'aZ09');
1334 $newlang = $object->thirdparty->default_lang;
1336 if (!empty($newlang)) {
1337 $outputlangs =
new Translate(
"", $conf);
1338 $outputlangs->setDefaultLang($newlang);
1340 $model = $object->model_pdf;
1341 $ret = $object->fetch($id);
1343 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1346 $deposit->fetch($deposit->id);
1347 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1351 if ($locationTarget) {
1352 header(
'Location: ' . $locationTarget);
1363 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1365 $idwarehouse =
GETPOST(
'idwarehouse');
1367 $qualified_for_stock_change = 0;
1368 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1369 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1371 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1375 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1376 if (!$idwarehouse || $idwarehouse == -1) {
1378 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1384 $result = $object->setDraft($user, $idwarehouse);
1387 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1388 $outputlangs = $langs;
1391 $newlang =
GETPOST(
'lang_id',
'aZ09');
1394 $newlang = $object->thirdparty->default_lang;
1396 if (!empty($newlang)) {
1397 $outputlangs =
new Translate(
"", $conf);
1398 $outputlangs->setDefaultLang($newlang);
1400 $model = $object->model_pdf;
1401 $ret = $object->fetch($id);
1403 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1407 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1408 $result = $object->cloture($user);
1412 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1413 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1415 $qualified_for_stock_change = 0;
1416 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1417 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1419 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1423 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1424 if (!$idwarehouse || $idwarehouse == -1) {
1426 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1432 $result = $object->cancel($idwarehouse);
1440 if ($action ==
'update_extras') {
1444 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1451 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1459 $action =
'edit_extras';
1464 if ($action ==
'import_lines_from_object'
1468 $fromElement =
GETPOST(
'fromelement');
1469 $fromElementid =
GETPOST(
'fromelementid');
1470 $importLines =
GETPOST(
'line_checkbox');
1472 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1473 if ($fromElement ==
'commande') {
1475 $lineClassName =
'OrderLine';
1476 } elseif ($fromElement ==
'propal') {
1477 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1478 $lineClassName =
'PropaleLigne';
1480 $nextRang = count($object->lines) + 1;
1483 foreach ($importLines as $lineId) {
1484 $lineId = intval($lineId);
1485 $originLine =
new $lineClassName($db);
1486 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1487 $originLine->fetch_optionals();
1488 $desc = $originLine->desc;
1489 $pu_ht = $originLine->subprice;
1490 $qty = $originLine->qty;
1491 $txtva = $originLine->tva_tx;
1492 $txlocaltax1 = $originLine->localtax1_tx;
1493 $txlocaltax2 = $originLine->localtax2_tx;
1494 $fk_product = $originLine->fk_product;
1495 $remise_percent = $originLine->remise_percent;
1496 $date_start = $originLine->date_start;
1497 $date_end = $originLine->date_end;
1499 $info_bits = $originLine->info_bits;
1500 $fk_remise_except = $originLine->fk_remise_except;
1501 $price_base_type =
'HT';
1503 $type = $originLine->product_type;
1504 $rang = $nextRang++;
1505 $special_code = $originLine->special_code;
1506 $origin = $originLine->element;
1507 $origin_id = $originLine->id;
1508 $fk_parent_line = 0;
1509 $fk_fournprice = $originLine->fk_fournprice;
1510 $pa_ht = $originLine->pa_ht;
1511 $label = $originLine->label;
1512 $array_options = $originLine->array_options;
1513 $situation_percent = 100;
1515 $fk_unit = $originLine->fk_unit;
1516 $pu_ht_devise = $originLine->multicurrency_subprice;
1518 $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);
1537 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1540 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1541 $permissiontoadd = $usercancreate;
1542 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1545 $triggersendname =
'ORDER_SENTBYMAIL';
1547 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1548 $trackid =
'ord'.$object->id;
1549 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1552 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1553 if ($action ==
'addcontact') {
1554 if ($object->id > 0) {
1557 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1561 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1564 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1565 $langs->load(
"errors");
1566 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1571 } elseif ($action ==
'swapstatut') {
1573 if ($object->id > 0) {
1574 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1578 } elseif ($action ==
'deletecontact') {
1580 $result = $object->delete_contact($lineid);
1583 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1597 $title = $object->ref.
" - ".$langs->trans(
'Card');
1598 if ($action ==
'create') {
1599 $title = $langs->trans(
"NewOrder");
1601 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1614 if ($action ==
'create' && $usercancreate) {
1619 $res = $soc->fetch($socid);
1622 $remise_absolue = 0;
1624 $currency_code = $conf->currency;
1626 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1627 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1628 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1630 if (!empty($origin) && !empty($originid)) {
1632 $element = $subelement = $origin;
1634 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1635 $element = $regs[1];
1636 $subelement = $regs[2];
1639 if ($element ==
'project') {
1640 $projectid = $originid;
1642 if (!$cond_reglement_id) {
1643 $cond_reglement_id = $soc->cond_reglement_id;
1645 if (!$deposit_percent) {
1646 $deposit_percent = $soc->deposit_percent;
1648 if (!$mode_reglement_id) {
1649 $mode_reglement_id = $soc->mode_reglement_id;
1651 if (!$remise_percent) {
1652 $remise_percent = $soc->remise_percent;
1656 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ODER) ?-1 :
'') : $dateorder);
1660 if ($element ==
'order' || $element ==
'commande') {
1661 $element = $subelement =
'commande';
1662 } elseif ($element ==
'propal') {
1663 $element =
'comm/propal';
1664 $subelement =
'propal';
1665 } elseif ($element ==
'contract') {
1666 $element = $subelement =
'contrat';
1671 $classname = ucfirst($subelement);
1672 $objectsrc =
new $classname($db);
1673 $objectsrc->fetch($originid);
1674 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1675 $objectsrc->fetch_lines();
1677 $objectsrc->fetch_thirdparty();
1680 $objectsrc->fetch_optionals();
1681 $object->array_options = $objectsrc->array_options;
1683 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1684 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1686 $soc = $objectsrc->thirdparty;
1687 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1688 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1689 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1690 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1691 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1692 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1693 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1694 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1695 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1696 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1697 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1699 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1700 if (empty($date_delivery)) {
1701 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1705 if (!empty($objectsrc->multicurrency_code)) {
1706 $currency_code = $objectsrc->multicurrency_code;
1708 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1709 $currency_tx = $objectsrc->multicurrency_tx;
1713 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1714 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1717 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1720 $cond_reglement_id = $soc->cond_reglement_id;
1721 $deposit_percent = $soc->deposit_percent;
1722 $mode_reglement_id = $soc->mode_reglement_id;
1723 $fk_account = $soc->fk_account;
1724 $availability_id = 0;
1725 $shipping_method_id = $soc->shipping_method_id;
1726 $warehouse_id = $soc->fk_warehouse;
1727 $demand_reason_id = $soc->demand_reason_id;
1728 $remise_percent = $soc->remise_percent;
1729 $remise_absolue = 0;
1730 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1732 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1733 $currency_code = $soc->multicurrency_code;
1736 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1737 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1741 if ($soc->fk_warehouse > 0) {
1742 $warehouse_id = $soc->fk_warehouse;
1744 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1745 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1746 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1748 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1749 $warehouse_id = $user->fk_warehouse;
1753 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1754 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1755 print
'<input type="hidden" name="action" value="add">';
1756 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1757 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1758 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1759 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1760 if (!empty($currency_tx)) {
1761 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1766 print
'<table class="border centpercent">';
1769 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1772 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1773 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1774 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1776 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1782 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1785 print $soc->getNomUrl(1,
'customer');
1786 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1790 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');
1792 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1793 print
'<script type="text/javascript">
1794 $(document).ready(function() {
1795 $("#socid").change(function() {
1796 console.log("We have changed the company - Reload page");
1797 var socid = $(this).val();
1799 $("input[name=action]").val("create");
1800 $("form[name=crea_commande]").submit();
1805 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>';
1813 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1814 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1815 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1819 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1821 $absolute_discount = $soc->getAvailableDiscounts();
1825 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1826 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1832 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1833 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1837 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1838 print
'<td colspan="3">';
1839 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1840 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1845 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1846 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1847 $form->selectAvailabilityDelay((
GETPOSTISSET(
'availability_id')?
GETPOST(
'availability_id'):$availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1851 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1852 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1853 print
$form->getSelectConditionsPaiements((
GETPOSTISSET(
'cond_reglement_id')?
GETPOST(
'cond_reglement_id'):$cond_reglement_id),
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1857 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1858 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1859 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);
1863 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
1864 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1865 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);
1871 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1872 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
1873 $form->selectShippingMethod((
GETPOSTISSET(
'shipping_method_id')?
GETPOST(
'shipping_method_id'):$shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1878 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1879 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1881 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1882 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');
1887 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1888 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1889 $form->selectInputReason((
GETPOSTISSET(
'demand_reason_id')?
GETPOST(
'demand_reason_id'):$demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1896 $langs->load(
"projects");
1898 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1899 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');
1900 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>';
1908 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
1909 print
'<td class="maxwidthonsmartphone">';
1910 $incoterm_id =
GETPOST(
'incoterm_id');
1911 $incoterm_location =
GETPOST(
'location_incoterms');
1912 if (empty($incoterm_id)) {
1913 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1914 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1916 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1922 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1928 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1929 print $hookmanager->resPrint;
1930 if (empty($reshook)) {
1931 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1933 $tpExtrafields =
new Extrafields($db);
1934 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1935 if ($soc->fetch_optionals() > 0) {
1936 $object->array_options = array_merge($object->array_options, $soc->array_options);
1940 print $object->showOptionals($extrafields,
'create',
$parameters);
1944 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1946 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1948 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1949 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1950 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1956 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1957 print
'<td class="maxwidthonsmartphone">';
1958 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency((
GETPOSTISSET(
'multicurrency_code')?
GETPOST(
'multicurrency_code'):$currency_code),
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1964 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1967 $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%');
1968 print $doleditor->Create(1);
1973 if (empty($user->socid)) {
1975 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1978 $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%');
1979 print $doleditor->Create(1);
1984 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1986 if ($origin ==
'contrat') {
1988 $objectsrc->remise_absolue = $remise_absolue;
1989 $objectsrc->remise_percent = $remise_percent;
1990 $objectsrc->update_price(1);
1993 print
"\n<!-- ".$classname.
" info -->";
1995 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1996 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1997 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1998 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1999 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2001 switch ($classname) {
2003 $newclassname =
'CommercialProposal';
2006 $newclassname =
'Order';
2009 $newclassname =
'Sending';
2012 $newclassname =
'Contract';
2015 $newclassname = $classname;
2018 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2021 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2022 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2023 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2024 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2027 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2028 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2031 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2034 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2035 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2036 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2044 print
$form->buttonsSaveCancel(
"CreateDraft");
2047 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2048 $title = $langs->trans(
'ProductsAndServices');
2051 print
'<div class="div-table-responsive-no-min">';
2052 print
'<table class="noborder centpercent">';
2054 $objectsrc->printOriginLinesList(
'', $selectedLines);
2065 if ($object->id > 0) {
2066 $product_static =
new Product($db);
2069 $soc->fetch($object->socid);
2071 $author =
new User($db);
2072 $author->fetch($object->user_author_id);
2074 $object->fetch_thirdparty();
2075 $res = $object->fetch_optionals();
2078 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2083 if ($action ==
'delete') {
2084 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2088 if ($action ==
'validate') {
2090 $ref = substr($object->ref, 1, 4);
2091 if ($ref ==
'PROV' || $ref ==
'') {
2092 $numref = $object->getNextNumRef($soc);
2093 if (empty($numref)) {
2098 $numref = $object->ref;
2101 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2103 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2104 $notify =
new Notify($db);
2106 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
2109 $qualified_for_stock_change = 0;
2110 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2111 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2113 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2116 $formquestion = array();
2117 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2118 $langs->load(
"stocks");
2119 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2122 if ($conf->browser->name ==
'ie') {
2125 $formquestion = array(
2129 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))
2135 foreach ($object->lines as $line) {
2136 $res = $line->fetch_product();
2138 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2144 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2146 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2151 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2153 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2154 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2156 $object->fetchObjectLinked();
2158 $eligibleForDepositGeneration =
true;
2160 if (array_key_exists(
'facture', $object->linkedObjects)) {
2161 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2163 $eligibleForDepositGeneration =
false;
2169 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2170 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2171 $proposal->fetchObjectLinked();
2173 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2174 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2176 $eligibleForDepositGeneration =
false;
2184 if ($eligibleForDepositGeneration) {
2185 $formquestion[] = array(
2186 'type' =>
'checkbox',
2188 'name' =>
'generate_deposit',
2189 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2192 $formquestion[] = array(
2194 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2196 'label' => $langs->trans(
'DateInvoice'),
2201 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2202 $formquestion[] = array(
2204 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2205 'name' =>
'date_pointoftax',
2206 'label' => $langs->trans(
'DatePointOfTax'),
2213 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2215 $formquestion[] = array(
2217 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2218 'name' =>
'cond_reglement_id',
2219 'label' => $langs->trans(
'PaymentTerm'),
2220 'value' => $paymentTermsSelect
2223 $formquestion[] = array(
2224 'type' =>
'checkbox',
2225 'tdclass' =>
'showonlyifgeneratedeposit',
2226 'name' =>
'validate_generated_deposit',
2227 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2230 $formquestion[] = array(
2231 'type' =>
'onecolumn',
2234 $(document).ready(function() {
2235 $("[name=generate_deposit]").change(function () {
2236 let $self = $(this);
2237 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2239 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2256 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2261 if ($action ==
'modif') {
2262 $qualified_for_stock_change = 0;
2263 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2264 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2266 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2269 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2270 $formquestion = array();
2271 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2272 $langs->load(
"stocks");
2273 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2276 if ($conf->browser->name ==
'ie') {
2279 $formquestion = array(
2283 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2287 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2293 if ($action ==
'shipped') {
2294 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2300 if ($action ==
'cancel') {
2301 $qualified_for_stock_change = 0;
2302 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2303 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2305 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2308 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2309 $formquestion = array();
2310 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2311 $langs->load(
"stocks");
2312 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2315 if ($conf->browser->name ==
'ie') {
2318 $formquestion = array(
2322 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2326 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2330 if ($action ==
'ask_deleteline') {
2331 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2335 if ($action ==
'clone') {
2337 $formquestion = array(
2338 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'))
2340 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2346 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2347 if (empty($reshook)) {
2349 } elseif ($reshook > 0) {
2359 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2361 $morehtmlref =
'<div class="refidno">';
2363 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2364 $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);
2366 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2367 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2368 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2372 $langs->load(
"projects");
2373 $morehtmlref .=
'<br>';
2374 if ($usercancreate) {
2375 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2376 if ($action !=
'classify') {
2377 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2379 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2381 if (!empty($object->fk_project)) {
2383 $proj->fetch($object->fk_project);
2384 $morehtmlref .= $proj->getNomUrl(1);
2386 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2391 $morehtmlref .=
'</div>';
2394 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2397 print
'<div class="fichecenter">';
2398 print
'<div class="fichehalfleft">';
2399 print
'<div class="underbanner clearboth"></div>';
2401 print
'<table class="border tableforfield centpercent">';
2403 if ($soc->outstanding_limit) {
2405 print
'<tr><td class="titlefield">';
2406 print $langs->trans(
'OutstandingBill');
2407 print
'</td><td class="valuefield">';
2408 $arrayoutstandingbills = $soc->getOutstandingBills();
2409 print
price($arrayoutstandingbills[
'opened']).
' / ';
2410 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2416 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2417 $filterabsolutediscount =
"fk_facture_source IS NULL";
2418 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2420 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2421 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2424 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2425 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2426 $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>';
2428 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2430 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2431 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2432 $absolute_discount =
price2num($absolute_discount,
'MT');
2433 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2437 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2438 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2445 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2446 print
'</td><td class="valuefield">';
2447 if ($action ==
'editdate') {
2448 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2449 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2450 print
'<input type="hidden" name="action" value="setdate">';
2451 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2452 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2455 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2456 if ($object->hasDelay() && empty($object->delivery_date)) {
2457 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2465 $editenable = $usercancreate;
2466 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2467 print
'</td><td class="valuefield">';
2468 if ($action ==
'editdate_livraison') {
2469 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2470 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2471 print
'<input type="hidden" name="action" value="setdate_livraison">';
2472 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2473 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2476 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2477 if ($object->hasDelay() && !empty($object->delivery_date)) {
2478 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2485 print
'<tr class="fielddeliverydelay"><td>';
2486 $editenable = $usercancreate;
2487 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2488 print
'</td><td class="valuefield">';
2489 if ($action ==
'editavailability') {
2490 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2492 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2499 $editenable = $usercancreate;
2500 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2501 print
'</td><td class="valuefield">';
2502 if ($action ==
'editshippingmethod') {
2503 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2505 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2512 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2513 $langs->load(
'stocks');
2514 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2517 $editenable = $usercancreate;
2518 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2519 print
'</td><td class="valuefield">';
2520 if ($action ==
'editwarehouse') {
2521 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2523 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2531 $editenable = $usercancreate;
2532 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2533 print
'</td><td class="valuefield">';
2534 if ($action ==
'editdemandreason') {
2535 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2537 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2543 $editenable = $usercancreate;
2544 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2545 print
'</td><td class="valuefield">';
2546 if ($action ==
'editconditions') {
2547 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2549 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2557 $editenable = $usercancreate;
2558 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2559 print
'</td><td class="valuefield">';
2560 if ($action ==
'editmode') {
2561 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2563 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2573 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2574 print
'</td><td class="valuefield">';
2575 if ($action ==
'editmulticurrencycode') {
2576 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2578 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2583 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2586 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2587 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2588 print
'</td><td class="valuefield">';
2589 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2590 if ($action ==
'actualizemulticurrencyrate') {
2593 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2595 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2596 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2597 print
'<div class="inline-block"> ';
2598 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2620 $tmparray = $object->getTotalWeightVolume();
2621 $totalWeight = $tmparray[
'weight'];
2622 $totalVolume = $tmparray[
'volume'];
2624 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2625 print
'<td class="valuefield">';
2626 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');
2630 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2631 print
'<td class="valuefield">';
2632 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');
2641 $editenable = $usercancreate;
2642 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2644 print
'<td class="valuefield">';
2645 if ($action !=
'editincoterm') {
2646 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2648 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2654 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
2656 $editenable = $usercancreate;
2657 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2658 print
'</td><td class="valuefield">';
2659 if ($action ==
'editbankaccount') {
2660 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2662 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2669 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2674 print
'<div class="fichehalfright">';
2675 print
'<div class="underbanner clearboth"></div>';
2677 print
'<table class="border tableforfield centpercent">';
2679 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
2681 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2682 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>';
2686 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2687 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>';
2691 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2692 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>';
2698 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2699 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2701 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2702 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2705 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>';
2708 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2709 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2710 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2712 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2713 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2714 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2718 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>';
2727 $formmargin->displayMarginInfos($object);
2734 print
'<div class="clearboth"></div><br>';
2736 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2737 $blocname =
'contacts';
2738 $title = $langs->trans(
'ContactsAddresses');
2739 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2742 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2743 $blocname =
'notes';
2744 $title = $langs->trans(
'Notes');
2745 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2753 $result = $object->getLinesArray();
2757 global $inputalsopricewithtax;
2758 $inputalsopricewithtax = 1;
2760 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2761 <input type="hidden" name="token" value="' .
newToken().
'">
2762 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2763 <input type="hidden" name="mode" value="">
2764 <input type="hidden" name="page_y" value="">
2765 <input type="hidden" name="id" value="' . $object->id.
'">';
2768 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2771 print
'<div class="div-table-responsive-no-min">';
2772 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2775 if (!empty($object->lines)) {
2776 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2779 $numlines = count($object->lines);
2785 if ($action !=
'editline') {
2790 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2791 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2792 if (empty($reshook))
2793 $object->formAddObjectLine(1, $mysoc, $soc);
2806 if ($action !=
'presend' && $action !=
'editline') {
2807 print
'<div class="tabsAction">';
2811 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2812 if (empty($reshook)) {
2815 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2819 if (empty($user->socid)) {
2820 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2822 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2824 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2830 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2831 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2835 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2847 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2849 if ($usercancreatepurchaseorder) {
2850 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2857 $langs->load(
"interventions");
2860 if ($user->hasRight(
'ficheinter',
'creer')) {
2861 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2863 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2870 $langs->load(
"contracts");
2872 if ($user->hasRight(
'contrat',
'creer')) {
2873 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2880 $numshipping = $object->nb_expedition();
2883 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2884 if ($user->hasRight(
'expedition',
'creer')) {
2885 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2887 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2890 $langs->load(
"errors");
2891 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2898 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2903 if (
isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2904 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,
'');
2906 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2907 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2911 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2912 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2916 if ($usercancreate) {
2917 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2922 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2926 if ($usercandelete) {
2927 if ($numshipping == 0) {
2928 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2930 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2938 if (
GETPOST(
'modelselected')) {
2939 $action =
'presend';
2942 if ($action !=
'presend') {
2943 print
'<div class="fichecenter"><div class="fichehalfleft">';
2944 print
'<a name="builddoc"></a>';
2947 $relativepath = $objref.
'/'.$objref.
'.pdf';
2948 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2949 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2950 $genallowed = $usercanread;
2951 $delallowed = $usercancreate;
2952 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2956 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'order'));
2958 $compatibleImportElementsList =
false;
2961 $compatibleImportElementsList = array(
'commande',
'propal');
2963 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2967 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2968 $useonlinepayment = 0;
2971 print
'<br><!-- Link to pay -->';
2972 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
2973 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
2976 print
'</div><div class="fichehalfright">';
2979 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2981 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
2983 print
'</div></div>';
2987 $modelmail =
'order_send';
2988 $defaulttopic =
'SendOrderRef';
2989 $diroutput = $conf->commande->multidir_output[$object->entity];
2990 $trackid =
'ord'.$object->id;
2992 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';