39 require
'../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
49 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
53 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
67 $langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
70 $langs->load(
'incoterm');
73 $langs->load(
'margins');
76 $langs->load(
'productbatch');
82 $socid =
GETPOST(
'socid',
'int');
83 $action =
GETPOST(
'action',
'aZ09');
84 $cancel =
GETPOST(
'cancel',
'alpha');
85 $confirm =
GETPOST(
'confirm',
'alpha');
86 $lineid =
GETPOST(
'lineid',
'int');
87 $contactid =
GETPOST(
'contactid',
'int');
88 $projectid =
GETPOST(
'projectid',
'int');
89 $origin =
GETPOST(
'origin',
'alpha');
91 $rank = (
GETPOST(
'rank',
'int') > 0) ?
GETPOST(
'rank',
'int') : -1;
94 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
95 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
96 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
99 if (!empty($user->socid)) {
100 $socid = $user->socid;
104 $hookmanager->initHooks(array(
'ordercard',
'globalcard'));
112 $extrafields->fetch_name_optionals_label($object->table_element);
115 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
118 $usercanread = $user->hasRight(
"commande",
"lire");
119 $usercancreate = $user->hasRight(
"commande",
"creer");
120 $usercandelete = $user->hasRight(
"commande",
"supprimer");
123 $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'close')));
124 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'validate')));
125 $usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
'commande',
'order_advance',
'annuler')));
126 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight(
'commande',
'order_advance',
'send'));
127 $usercangeneretedoc = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight(
'commande',
'order_advance',
'generetedoc'));
129 $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
130 $usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
132 $permissionnote = $usercancreate;
133 $permissiondellink = $usercancreate;
134 $permissiontoadd = $usercancreate;
139 $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'));
148 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
153 if (empty($reshook)) {
154 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
156 if (empty($backtopage) || ($cancel && empty($id))) {
157 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
158 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
159 $backtopage = $backurlforlist;
161 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
167 if (!empty($backtopageforcancel)) {
168 header(
"Location: ".$backtopageforcancel);
170 } elseif (!empty($backtopage)) {
171 header(
"Location: ".$backtopage);
177 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
179 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
181 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
184 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
185 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
188 if ($object->id > 0) {
190 $orig = clone $object;
192 $result = $object->createFromClone($user, $socid);
194 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
203 } elseif ($action ==
'reopen' && $usercancreate) {
206 $result = $object->set_reopen($user);
213 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
215 $result = $object->delete($user);
217 header(
'Location: list.php?restore_lastsearch_values=1');
222 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
224 $result = $object->deleteline($user, $lineid);
227 $object->line_order(
true);
229 $outputlangs = $langs;
232 $newlang =
GETPOST(
'lang_id',
'aZ09');
235 $newlang = $object->thirdparty->default_lang;
237 if (!empty($newlang)) {
239 $outputlangs->setDefaultLang($newlang);
241 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
242 $ret = $object->fetch($object->id);
243 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
246 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
251 } elseif ($action ==
'classin' && $usercancreate) {
253 $object->setProject(
GETPOST(
'projectid',
'int'));
254 } elseif ($action ==
'add' && $usercancreate) {
257 $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'));
258 $selectedLines =
GETPOST(
'toselect',
'array');
260 if ($datecommande ==
'') {
261 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
267 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
273 $object->socid = $socid;
274 $object->fetch_thirdparty();
278 $object->date_commande = $datecommande;
279 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
280 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
281 $object->source =
GETPOST(
'source_id');
282 $object->fk_project =
GETPOST(
'projectid',
'int');
283 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
284 $object->model_pdf =
GETPOST(
'model');
285 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id');
286 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
287 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id');
288 $object->fk_account =
GETPOST(
'fk_account',
'int');
289 $object->availability_id =
GETPOST(
'availability_id');
290 $object->demand_reason_id =
GETPOST(
'demand_reason_id');
291 $object->date_livraison = $date_delivery;
292 $object->delivery_date = $date_delivery;
293 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
294 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
295 $object->fk_delivery_address =
GETPOST(
'fk_address');
296 $object->contact_id =
GETPOST(
'contactid');
297 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
298 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
299 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
300 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
303 $ret = $extrafields->setOptionalsFromPost(
null, $object);
310 if (!empty($origin) && !empty($originid)) {
312 $element = $subelement = $origin;
314 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
315 $element = $regs [1];
316 $subelement = $regs [2];
320 if ($element ==
'order') {
321 $element = $subelement =
'commande';
323 if ($element ==
'propal') {
324 $element =
'comm/propal';
325 $subelement =
'propal';
327 if ($element ==
'contract') {
328 $element = $subelement =
'contrat';
331 $object->origin = $origin;
332 $object->origin_id = $originid;
335 $object->linked_objects [$object->origin] = $object->origin_id;
336 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
337 if (!empty($other_linked_objects)) {
338 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
342 $object_id = $object->create($user);
344 if ($object_id > 0) {
347 $classname = ucfirst($subelement);
348 $srcobject =
new $classname($db);
350 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
351 $result = $srcobject->fetch($object->origin_id);
353 $lines = $srcobject->lines;
354 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
355 $srcobject->fetch_lines();
356 $lines = $srcobject->lines;
360 $num = count($lines);
362 for ($i = 0; $i < $num; $i++) {
363 if (!in_array($lines[$i]->
id, $selectedLines)) {
367 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
368 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
369 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
373 $date_start = $lines[$i]->date_debut_prevue;
374 if ($lines[$i]->date_debut_reel) {
375 $date_start = $lines[$i]->date_debut_reel;
377 if ($lines[$i]->date_start) {
378 $date_start = $lines[$i]->date_start;
380 $date_end = $lines[$i]->date_fin_prevue;
381 if ($lines[$i]->date_fin_reel) {
382 $date_end = $lines[$i]->date_fin_reel;
384 if ($lines[$i]->date_end) {
385 $date_end = $lines[$i]->date_end;
389 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
394 if (method_exists($lines[$i],
'fetch_optionals')) {
395 $lines[$i]->fetch_optionals();
396 $array_options = $lines[$i]->array_options;
399 $tva_tx = $lines[$i]->tva_tx;
400 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
401 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
404 $result = $object->addline(
406 $lines[$i]->subprice,
409 $lines[$i]->localtax1_tx,
410 $lines[$i]->localtax2_tx,
411 $lines[$i]->fk_product,
412 $lines[$i]->remise_percent,
413 $lines[$i]->info_bits,
414 $lines[$i]->fk_remise_except,
421 $lines[$i]->special_code,
423 $lines[$i]->fk_fournprice,
438 if ($result > 0 && $lines[$i]->product_type == 9) {
439 $fk_parent_line = $result;
476 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
490 $object_id = $object->create($user);
495 if ($object_id > 0) {
496 if (
GETPOST(
'contactid',
'int')) {
497 $result = $object->add_contact(
GETPOST(
'contactid',
'int'),
'CUSTOMER',
'external');
509 if ($object_id > 0 && !$error) {
511 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
519 } elseif ($action ==
'classifybilled' && $usercancreate) {
520 $ret = $object->classifyBilled($user);
525 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
526 $ret = $object->classifyUnBilled($user);
530 } elseif ($action ==
'setref_client' && $usercancreate) {
532 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
536 } elseif ($action ==
'setremise' && $usercancreate) {
541 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
543 if ($object->id > 0) {
544 $object->insert_discount(
GETPOST(
'remise_id'));
549 } elseif ($action ==
'setdate' && $usercancreate) {
552 $result = $object->set_date($user, $date);
556 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
557 $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'));
560 $result = $object->setDeliveryDate($user, $date_delivery);
564 } elseif ($action ==
'setmode' && $usercancreate) {
565 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
569 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
571 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
572 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
574 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
575 } elseif ($action ==
'setavailability' && $usercancreate) {
576 $result = $object->availability(
GETPOST(
'availability_id'));
580 } elseif ($action ==
'setdemandreason' && $usercancreate) {
581 $result = $object->demand_reason(
GETPOST(
'demand_reason_id'));
585 } elseif ($action ==
'setconditions' && $usercancreate) {
586 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
590 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
592 $outputlangs = $langs;
593 $newlang =
GETPOST(
'lang_id',
'alpha');
595 $newlang = $object->thirdparty->default_lang;
597 if (!empty($newlang)) {
599 $outputlangs->setDefaultLang($newlang);
602 $ret = $object->fetch($object->id);
603 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
606 } elseif ($action ==
'set_incoterms' &&
isModEnabled(
'incoterm')) {
608 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
612 } elseif ($action ==
'setbankaccount' && $usercancreate) {
614 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
618 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
620 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
624 } elseif ($action ==
'setwarehouse' && $usercancreate) {
626 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
630 } elseif ($action ==
'setremisepercent' && $usercancreate) {
631 $result = $object->setDiscount($user,
price2num(
GETPOST(
'remise_percent'),
'', 2));
632 } elseif ($action ==
'setremiseabsolue' && $usercancreate) {
633 $result = $object->set_remise_absolue($user,
price2num(
GETPOST(
'remise_absolue'),
'MU', 2));
634 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
636 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
637 $vat_rate = str_replace(
'*',
'', $vat_rate);
638 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
639 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
640 foreach ($object->lines as $line) {
641 $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);
643 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
645 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
646 $remise_percent = str_replace(
'*',
'', $remise_percent);
647 foreach ($object->lines as $line) {
648 $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);
650 } elseif ($action ==
'addline' && $usercancreate) {
651 $langs->load(
'errors');
659 $price_ht_devise =
'';
661 $price_ttc_devise =
'';
663 if (
GETPOST(
'price_ht') !==
'') {
666 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
669 if (
GETPOST(
'price_ttc') !==
'') {
672 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
676 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
677 if ($prod_entry_mode ==
'free') {
679 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
price2num(preg_replace(
'/\s*\(.*\)/',
'',
GETPOST(
'tva_tx',
'alpha'))) : 0);
681 $idprod =
GETPOST(
'idprod',
'int');
687 $pu_equivalent = $pu_ht;
688 $pu_equivalent_ttc = $pu_ttc;
689 $currency_tx = $object->multicurrency_tx;
693 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
694 $pu_equivalent = $pu_ht_devise * $currency_tx;
696 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
697 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
703 if (empty($remise_percent)) {
708 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
709 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
711 if (is_array($extralabelsline)) {
713 foreach ($extralabelsline as $key => $value) {
714 unset($_POST[
"options_".$key]);
718 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
719 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
722 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
723 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
726 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
727 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
731 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
735 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
738 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
739 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
743 if (!$error &&
isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
744 if ($combinations =
GETPOST(
'combinations',
'array')) {
748 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
749 $idprod = $res->fk_product_child;
751 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
757 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
761 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
767 if (!empty($idprod) && $idprod > 0) {
769 $prod->fetch($idprod);
771 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
776 if (empty($tva_tx)) {
780 $pu_ht = $prod->price;
781 $pu_ttc = $prod->price_ttc;
782 $price_min = $prod->price_min;
783 $price_min_ttc = $prod->price_min_ttc;
784 $price_base_type = $prod->price_base_type;
787 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
788 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
789 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
790 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
791 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
792 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
793 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
794 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
795 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
797 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
798 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
801 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
803 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
807 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
809 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
811 if (count($prodcustprice->lines) > 0) {
812 $pu_ht =
price($prodcustprice->lines[0]->price);
813 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
814 $price_min =
price($prodcustprice->lines[0]->price_min);
815 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
816 $price_base_type = $prodcustprice->lines[0]->price_base_type;
817 $tva_tx = $prodcustprice->lines[0]->tva_tx;
818 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
819 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
821 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
822 if (empty($tva_tx)) {
829 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
831 if ($prod->prices_by_qty[0]) {
836 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
837 if ($priceforthequantityarray[
'rowid'] != $pqp) {
841 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
842 $pu_ht = $priceforthequantityarray[
'unitprice'];
844 $pu_ttc = $priceforthequantityarray[
'unitprice'];
850 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
852 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
856 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
857 if ($priceforthequantityarray[
'rowid'] != $pqp) {
861 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
862 $pu_ht = $priceforthequantityarray[
'unitprice'];
864 $pu_ttc = $priceforthequantityarray[
'unitprice'];
872 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
873 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
876 if (!empty($price_ht) || $price_ht ===
'0') {
878 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
879 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
881 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
882 } elseif ($tmpvat != $tmpprodvat) {
884 if ($price_base_type !=
'HT') {
885 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
887 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
894 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
895 $outputlangs = $langs;
897 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
898 $newlang =
GETPOST(
'lang_id',
'aZ09');
900 if (empty($newlang)) {
901 $newlang = $object->thirdparty->default_lang;
903 if (!empty($newlang)) {
905 $outputlangs->setDefaultLang($newlang);
908 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->description;
910 $desc = $prod->description;
914 if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
918 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
919 $desc = $product_desc;
921 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
925 if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
928 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
929 $outputlangs = $langs;
931 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
932 $newlang =
GETPOST(
'lang_id',
'alpha');
934 if (empty($newlang)) {
935 $newlang = $object->thirdparty->default_lang;
937 if (!empty($newlang)) {
939 $outputlangs->setDefaultLang($newlang);
940 $outputlangs->load(
'products');
942 if (!empty($prod->customcode)) {
943 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
945 if (!empty($prod->customcode) && !empty($prod->country_code)) {
948 if (!empty($prod->country_code)) {
949 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
952 if (!empty($prod->customcode)) {
953 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
955 if (!empty($prod->customcode) && !empty($prod->country_code)) {
958 if (!empty($prod->country_code)) {
959 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
967 $fk_unit = $prod->fk_unit;
971 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
972 $tva_tx = str_replace(
'*',
'', $tva_tx);
973 if (empty($tva_tx)) {
976 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
977 $desc = $product_desc;
979 $fk_unit =
GETPOST(
'units',
'alpha');
980 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
981 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
983 if ($pu_ttc && !$pu_ht) {
984 $price_base_type =
'TTC';
993 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
994 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1003 if ($usermustrespectpricemin) {
1004 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1005 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1008 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1009 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1017 $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);
1020 $ret = $object->fetch($object->id);
1021 $object->fetch_thirdparty();
1023 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1025 $outputlangs = $langs;
1026 $newlang =
GETPOST(
'lang_id',
'alpha');
1028 $newlang = $object->thirdparty->default_lang;
1030 if (!empty($newlang)) {
1031 $outputlangs =
new Translate(
"", $conf);
1032 $outputlangs->setDefaultLang($newlang);
1035 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1038 unset($_POST[
'prod_entry_mode']);
1040 unset($_POST[
'qty']);
1041 unset($_POST[
'type']);
1042 unset($_POST[
'remise_percent']);
1043 unset($_POST[
'price_ht']);
1044 unset($_POST[
'multicurrency_price_ht']);
1045 unset($_POST[
'price_ttc']);
1046 unset($_POST[
'tva_tx']);
1047 unset($_POST[
'product_ref']);
1048 unset($_POST[
'product_label']);
1049 unset($_POST[
'product_desc']);
1050 unset($_POST[
'fournprice']);
1051 unset($_POST[
'buying_price']);
1052 unset($_POST[
'np_marginRate']);
1053 unset($_POST[
'np_markRate']);
1054 unset($_POST[
'dp_desc']);
1055 unset($_POST[
'idprod']);
1056 unset($_POST[
'units']);
1058 unset($_POST[
'date_starthour']);
1059 unset($_POST[
'date_startmin']);
1060 unset($_POST[
'date_startsec']);
1061 unset($_POST[
'date_startday']);
1062 unset($_POST[
'date_startmonth']);
1063 unset($_POST[
'date_startyear']);
1064 unset($_POST[
'date_endhour']);
1065 unset($_POST[
'date_endmin']);
1066 unset($_POST[
'date_endsec']);
1067 unset($_POST[
'date_endday']);
1068 unset($_POST[
'date_endmonth']);
1069 unset($_POST[
'date_endyear']);
1075 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1083 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1084 $vat_rate = str_replace(
'*',
'', $vat_rate);
1095 $pu_equivalent = $pu_ht;
1096 $pu_equivalent_ttc = $pu_ttc;
1097 $currency_tx = $object->multicurrency_tx;
1101 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1102 $pu_equivalent = $pu_ht_devise * $currency_tx;
1104 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1105 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1110 if (preg_match(
'/\*/', $vat_rate)) {
1115 $vat_rate = str_replace(
'*',
'', $vat_rate);
1116 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1117 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1124 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1125 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1127 if (is_array($extralabelsline)) {
1128 foreach ($extralabelsline as $key => $value) {
1129 unset($_POST[
"options_".$key]);
1134 $special_code =
GETPOST(
'special_code');
1142 $productid =
GETPOST(
'productid',
'int');
1143 if (!empty($productid)) {
1145 $product->fetch($productid);
1147 $type = $product->type;
1149 $price_min = $product->price_min;
1150 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1151 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1153 $price_min_ttc = $product->price_min_ttc;
1154 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
1155 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1160 if ($usermustrespectpricemin) {
1161 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min))) {
1162 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1165 $action =
'editline';
1166 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc))) {
1167 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1170 $action =
'editline';
1175 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1179 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1181 $action =
'editline';
1186 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1188 $action =
'editline';
1192 if (empty($user->rights->margins->creer)) {
1193 foreach ($object->lines as &$line) {
1194 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1195 $fournprice = $line->fk_fournprice;
1196 $buyingprice = $line->pa_ht;
1202 $price_base_type =
'HT';
1204 if (empty($pu) && !empty($pu_ttc)) {
1206 $price_base_type =
'TTC';
1209 $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);
1212 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1214 $outputlangs = $langs;
1217 $newlang =
GETPOST(
'lang_id',
'aZ09');
1220 $newlang = $object->thirdparty->default_lang;
1222 if (!empty($newlang)) {
1223 $outputlangs =
new Translate(
"", $conf);
1224 $outputlangs->setDefaultLang($newlang);
1227 $ret = $object->fetch($object->id);
1228 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1231 unset($_POST[
'qty']);
1232 unset($_POST[
'type']);
1233 unset($_POST[
'productid']);
1234 unset($_POST[
'remise_percent']);
1235 unset($_POST[
'price_ht']);
1236 unset($_POST[
'multicurrency_price_ht']);
1237 unset($_POST[
'price_ttc']);
1238 unset($_POST[
'tva_tx']);
1239 unset($_POST[
'product_ref']);
1240 unset($_POST[
'product_label']);
1241 unset($_POST[
'product_desc']);
1242 unset($_POST[
'fournprice']);
1243 unset($_POST[
'buying_price']);
1245 unset($_POST[
'date_starthour']);
1246 unset($_POST[
'date_startmin']);
1247 unset($_POST[
'date_startsec']);
1248 unset($_POST[
'date_startday']);
1249 unset($_POST[
'date_startmonth']);
1250 unset($_POST[
'date_startyear']);
1251 unset($_POST[
'date_endhour']);
1252 unset($_POST[
'date_endmin']);
1253 unset($_POST[
'date_endsec']);
1254 unset($_POST[
'date_endday']);
1255 unset($_POST[
'date_endmonth']);
1256 unset($_POST[
'date_endyear']);
1261 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1262 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1264 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1265 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1267 $qualified_for_stock_change = 0;
1268 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1269 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1271 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1275 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1276 if (!$idwarehouse || $idwarehouse == -1) {
1278 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1284 $locationTarget =
'';
1286 $result = $object->valid($user, $idwarehouse);
1291 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1294 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1295 &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)
1297 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1300 $forceFields = array();
1303 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1310 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1321 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1322 $outputlangs = $langs;
1325 $newlang =
GETPOST(
'lang_id',
'aZ09');
1328 $newlang = $object->thirdparty->default_lang;
1330 if (!empty($newlang)) {
1331 $outputlangs =
new Translate(
"", $conf);
1332 $outputlangs->setDefaultLang($newlang);
1334 $model = $object->model_pdf;
1335 $ret = $object->fetch($id);
1337 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1340 $deposit->fetch($deposit->id);
1341 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1345 if ($locationTarget) {
1346 header(
'Location: ' . $locationTarget);
1357 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1359 $idwarehouse =
GETPOST(
'idwarehouse');
1361 $qualified_for_stock_change = 0;
1362 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1363 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1365 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1369 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1370 if (!$idwarehouse || $idwarehouse == -1) {
1372 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1378 $result = $object->setDraft($user, $idwarehouse);
1381 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1382 $outputlangs = $langs;
1385 $newlang =
GETPOST(
'lang_id',
'aZ09');
1388 $newlang = $object->thirdparty->default_lang;
1390 if (!empty($newlang)) {
1391 $outputlangs =
new Translate(
"", $conf);
1392 $outputlangs->setDefaultLang($newlang);
1394 $model = $object->model_pdf;
1395 $ret = $object->fetch($id);
1397 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1401 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1402 $result = $object->cloture($user);
1406 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1407 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1409 $qualified_for_stock_change = 0;
1410 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1411 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1413 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1417 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
1418 if (!$idwarehouse || $idwarehouse == -1) {
1420 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1426 $result = $object->cancel($idwarehouse);
1434 if ($action ==
'update_extras') {
1438 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1445 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1453 $action =
'edit_extras';
1458 if ($action ==
'import_lines_from_object'
1462 $fromElement =
GETPOST(
'fromelement');
1463 $fromElementid =
GETPOST(
'fromelementid');
1464 $importLines =
GETPOST(
'line_checkbox');
1466 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1467 if ($fromElement ==
'commande') {
1469 $lineClassName =
'OrderLine';
1470 } elseif ($fromElement ==
'propal') {
1471 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1472 $lineClassName =
'PropaleLigne';
1474 $nextRang = count($object->lines) + 1;
1477 foreach ($importLines as $lineId) {
1478 $lineId = intval($lineId);
1479 $originLine =
new $lineClassName($db);
1480 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1481 $originLine->fetch_optionals();
1482 $desc = $originLine->desc;
1483 $pu_ht = $originLine->subprice;
1484 $qty = $originLine->qty;
1485 $txtva = $originLine->tva_tx;
1486 $txlocaltax1 = $originLine->localtax1_tx;
1487 $txlocaltax2 = $originLine->localtax2_tx;
1488 $fk_product = $originLine->fk_product;
1489 $remise_percent = $originLine->remise_percent;
1490 $date_start = $originLine->date_start;
1491 $date_end = $originLine->date_end;
1493 $info_bits = $originLine->info_bits;
1494 $fk_remise_except = $originLine->fk_remise_except;
1495 $price_base_type =
'HT';
1497 $type = $originLine->product_type;
1498 $rang = $nextRang++;
1499 $special_code = $originLine->special_code;
1500 $origin = $originLine->element;
1501 $origin_id = $originLine->id;
1502 $fk_parent_line = 0;
1503 $fk_fournprice = $originLine->fk_fournprice;
1504 $pa_ht = $originLine->pa_ht;
1505 $label = $originLine->label;
1506 $array_options = $originLine->array_options;
1507 $situation_percent = 100;
1509 $fk_unit = $originLine->fk_unit;
1510 $pu_ht_devise = $originLine->multicurrency_subprice;
1512 $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);
1531 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1534 $upload_dir = !empty($conf->commande->multidir_output[$object->entity])?$conf->commande->multidir_output[$object->entity]:$conf->commande->dir_output;
1535 $permissiontoadd = $usercancreate;
1536 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1539 $triggersendname =
'ORDER_SENTBYMAIL';
1541 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1542 $trackid =
'ord'.$object->id;
1543 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1546 if (!$error && !empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1547 if ($action ==
'addcontact') {
1548 if ($object->id > 0) {
1551 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1555 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1558 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1559 $langs->load(
"errors");
1560 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1565 } elseif ($action ==
'swapstatut') {
1567 if ($object->id > 0) {
1568 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1572 } elseif ($action ==
'deletecontact') {
1574 $result = $object->delete_contact($lineid);
1577 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1591 $title = $object->ref.
" - ".$langs->trans(
'Card');
1592 if ($action ==
'create') {
1593 $title = $langs->trans(
"NewOrder");
1595 $help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1608 if ($action ==
'create' && $usercancreate) {
1613 $res = $soc->fetch($socid);
1616 $remise_absolue = 0;
1618 $currency_code = $conf->currency;
1620 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1621 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1622 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1624 if (!empty($origin) && !empty($originid)) {
1626 $element = $subelement = $origin;
1628 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1629 $element = $regs[1];
1630 $subelement = $regs[2];
1633 if ($element ==
'project') {
1634 $projectid = $originid;
1636 if (!$cond_reglement_id) {
1637 $cond_reglement_id = $soc->cond_reglement_id;
1639 if (!$deposit_percent) {
1640 $deposit_percent = $soc->deposit_percent;
1642 if (!$mode_reglement_id) {
1643 $mode_reglement_id = $soc->mode_reglement_id;
1645 if (!$remise_percent) {
1646 $remise_percent = $soc->remise_percent;
1650 $dateorder = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE_ODER) ?-1 :
'') : $dateorder);
1654 if ($element ==
'order' || $element ==
'commande') {
1655 $element = $subelement =
'commande';
1656 } elseif ($element ==
'propal') {
1657 $element =
'comm/propal';
1658 $subelement =
'propal';
1659 } elseif ($element ==
'contract') {
1660 $element = $subelement =
'contrat';
1665 $classname = ucfirst($subelement);
1666 $objectsrc =
new $classname($db);
1667 $objectsrc->fetch($originid);
1668 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1669 $objectsrc->fetch_lines();
1671 $objectsrc->fetch_thirdparty();
1674 $objectsrc->fetch_optionals();
1675 $object->array_options = $objectsrc->array_options;
1677 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1678 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1680 $soc = $objectsrc->thirdparty;
1681 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1682 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1683 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1684 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1685 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1686 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1687 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1688 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1689 $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
1690 $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1691 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ? -1 :
'';
1693 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1694 if (empty($date_delivery)) {
1695 $date_delivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison :
'');
1699 if (!empty($objectsrc->multicurrency_code)) {
1700 $currency_code = $objectsrc->multicurrency_code;
1702 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
1703 $currency_tx = $objectsrc->multicurrency_tx;
1707 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private :
null));
1708 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public :
null));
1711 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1714 $cond_reglement_id = $soc->cond_reglement_id;
1715 $deposit_percent = $soc->deposit_percent;
1716 $mode_reglement_id = $soc->mode_reglement_id;
1717 $fk_account = $soc->fk_account;
1718 $availability_id = 0;
1719 $shipping_method_id = $soc->shipping_method_id;
1720 $warehouse_id = $soc->fk_warehouse;
1721 $demand_reason_id = $soc->demand_reason_id;
1722 $remise_percent = $soc->remise_percent;
1723 $remise_absolue = 0;
1724 $dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER) ?-1 :
'';
1726 if (
isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1727 $currency_code = $soc->multicurrency_code;
1730 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1731 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1735 if ($soc->fk_warehouse > 0) {
1736 $warehouse_id = $soc->fk_warehouse;
1738 if (
isModEnabled(
'stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1739 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
1740 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1742 if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1743 $warehouse_id = $user->fk_warehouse;
1747 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1748 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1749 print
'<input type="hidden" name="action" value="add">';
1750 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1751 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1752 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1753 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1754 if (!empty($currency_tx)) {
1755 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1760 print
'<table class="border centpercent">';
1763 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1766 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1767 if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && !empty($origin) && !empty($originid)) {
1768 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1770 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1776 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1779 print $soc->getNomUrl(1,
'customer');
1780 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1784 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');
1786 if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
1787 print
'<script type="text/javascript">
1788 $(document).ready(function() {
1789 $("#socid").change(function() {
1790 console.log("We have changed the company - Reload page");
1791 var socid = $(this).val();
1793 $("input[name=action]").val("create");
1794 $("form[name=crea_commande]").submit();
1799 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>';
1807 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1808 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1809 print
$form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist)?$srccontactslist:
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1813 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1815 $absolute_discount = $soc->getAvailableDiscounts();
1819 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.
GETPOST(
'origin').
'&originid='.
GETPOST(
'originid'));
1820 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1826 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1827 print
$form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1831 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1832 print
'<td colspan="3">';
1833 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1834 print
$form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1839 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1840 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1841 $form->selectAvailabilityDelay($availability_id,
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1845 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1846 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1847 print
$form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1851 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1852 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1853 print
$form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1857 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
1858 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1859 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1865 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1866 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
1867 $form->selectShippingMethod($shipping_method_id,
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1872 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1873 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1875 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1876 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id,
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1881 print
'<tr><td>'.$langs->trans(
'Channel').
'</td><td>';
1882 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1883 $form->selectInputReason($demand_reason_id,
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1890 $langs->load(
"projects");
1892 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1893 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
'projectid', 0, 0, 1, 0, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1894 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>';
1902 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
1903 print
'<td class="maxwidthonsmartphone">';
1904 $incoterm_id =
GETPOST(
'incoterm_id');
1905 $incoterm_location =
GETPOST(
'location_incoterms');
1906 if (empty($incoterm_id)) {
1907 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1908 $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1910 print
$form->select_incoterms($incoterm_id, $incoterm_location);
1916 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1922 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1923 print $hookmanager->resPrint;
1924 if (empty($reshook)) {
1925 if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER) && !empty($soc->id)) {
1927 $tpExtrafields =
new Extrafields($db);
1928 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
1929 if ($soc->fetch_optionals() > 0) {
1930 $object->array_options = array_merge($object->array_options, $soc->array_options);
1934 print $object->showOptionals($extrafields,
'create',
$parameters);
1938 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
1940 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
1942 $preselected = $conf->global->COMMANDE_ADDON_PDF;
1943 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
1944 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
1950 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
1951 print
'<td class="maxwidthonsmartphone">';
1952 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code,
'multicurrency_code', 0,
'',
false,
'maxwidth200 widthcentpercentminusx');
1958 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1961 $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%');
1962 print $doleditor->Create(1);
1967 if (empty($user->socid)) {
1969 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1972 $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%');
1973 print $doleditor->Create(1);
1978 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1980 if ($origin ==
'contrat') {
1982 $objectsrc->remise_absolue = $remise_absolue;
1983 $objectsrc->remise_percent = $remise_percent;
1984 $objectsrc->update_price(1);
1987 print
"\n<!-- ".$classname.
" info -->";
1989 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
1990 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
1991 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
1992 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1993 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1995 switch ($classname) {
1997 $newclassname =
'CommercialProposal';
2000 $newclassname =
'Order';
2003 $newclassname =
'Sending';
2006 $newclassname =
'Contract';
2009 $newclassname = $classname;
2012 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2015 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2016 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2017 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2018 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2021 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2022 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2025 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2028 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2029 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2030 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2038 print
$form->buttonsSaveCancel(
"CreateDraft");
2041 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2042 $title = $langs->trans(
'ProductsAndServices');
2045 print
'<div class="div-table-responsive-no-min">';
2046 print
'<table class="noborder centpercent">';
2048 $objectsrc->printOriginLinesList(
'', $selectedLines);
2059 if ($object->id > 0) {
2060 $product_static =
new Product($db);
2063 $soc->fetch($object->socid);
2065 $author =
new User($db);
2066 $author->fetch($object->user_author_id);
2068 $object->fetch_thirdparty();
2069 $res = $object->fetch_optionals();
2072 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2077 if ($action ==
'delete') {
2078 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2082 if ($action ==
'validate') {
2084 $ref = substr($object->ref, 1, 4);
2085 if ($ref ==
'PROV' || $ref ==
'') {
2086 $numref = $object->getNextNumRef($soc);
2087 if (empty($numref)) {
2092 $numref = $object->ref;
2095 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2097 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2098 $notify =
new Notify($db);
2100 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
2103 $qualified_for_stock_change = 0;
2104 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2105 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2107 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2110 $formquestion = array();
2111 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2112 $langs->load(
"stocks");
2113 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2116 if ($conf->browser->name ==
'ie') {
2119 $formquestion = array(
2123 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))
2129 foreach ($object->lines as $line) {
2130 $res = $line->fetch_product();
2132 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
2138 if ($nbMandated > 0 ) $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2140 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2145 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2147 if (!empty($deposit_percent_from_payment_terms) &&
isModEnabled(
'facture') && !empty($user->rights->facture->creer)) {
2148 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2150 $object->fetchObjectLinked();
2152 $eligibleForDepositGeneration =
true;
2154 if (array_key_exists(
'facture', $object->linkedObjects)) {
2155 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2157 $eligibleForDepositGeneration =
false;
2163 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2164 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2165 $proposal->fetchObjectLinked();
2167 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2168 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2170 $eligibleForDepositGeneration =
false;
2178 if ($eligibleForDepositGeneration) {
2179 $formquestion[] = array(
2180 'type' =>
'checkbox',
2182 'name' =>
'generate_deposit',
2183 'label' =>
$form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2186 $formquestion[] = array(
2188 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2190 'label' => $langs->trans(
'DateInvoice'),
2195 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2196 $formquestion[] = array(
2198 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2199 'name' =>
'date_pointoftax',
2200 'label' => $langs->trans(
'DatePointOfTax'),
2207 $paymentTermsSelect =
$form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2209 $formquestion[] = array(
2211 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2212 'name' =>
'cond_reglement_id',
2213 'label' => $langs->trans(
'PaymentTerm'),
2214 'value' => $paymentTermsSelect
2217 $formquestion[] = array(
2218 'type' =>
'checkbox',
2219 'tdclass' =>
'showonlyifgeneratedeposit',
2220 'name' =>
'validate_generated_deposit',
2221 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2224 $formquestion[] = array(
2225 'type' =>
'onecolumn',
2228 $(document).ready(function() {
2229 $("[name=generate_deposit]").change(function () {
2230 let $self = $(this);
2231 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2233 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2250 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2255 if ($action ==
'modif') {
2256 $qualified_for_stock_change = 0;
2257 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2258 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2260 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2263 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2264 $formquestion = array();
2265 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2266 $langs->load(
"stocks");
2267 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2270 if ($conf->browser->name ==
'ie') {
2273 $formquestion = array(
2277 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2281 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2287 if ($action ==
'shipped') {
2288 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2294 if ($action ==
'cancel') {
2295 $qualified_for_stock_change = 0;
2296 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2297 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2299 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2302 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2303 $formquestion = array();
2304 if (
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $qualified_for_stock_change) {
2305 $langs->load(
"stocks");
2306 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2309 if ($conf->browser->name ==
'ie') {
2312 $formquestion = array(
2316 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2320 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2324 if ($action ==
'ask_deleteline') {
2325 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2329 if ($action ==
'clone') {
2331 $formquestion = array(
2332 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'))
2334 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2340 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
2341 if (empty($reshook)) {
2343 } elseif ($reshook > 0) {
2353 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2355 $morehtmlref =
'<div class="refidno">';
2357 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2358 $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);
2360 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2361 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
2362 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2366 $langs->load(
"projects");
2367 $morehtmlref .=
'<br>';
2368 if ($usercancreate) {
2369 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2370 if ($action !=
'classify') {
2371 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2373 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, ($action ==
'classify' ? 1 : 0), 0, 1,
'');
2375 if (!empty($object->fk_project)) {
2377 $proj->fetch($object->fk_project);
2378 $morehtmlref .= $proj->getNomUrl(1);
2380 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2385 $morehtmlref .=
'</div>';
2388 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2391 print
'<div class="fichecenter">';
2392 print
'<div class="fichehalfleft">';
2393 print
'<div class="underbanner clearboth"></div>';
2395 print
'<table class="border tableforfield centpercent">';
2397 if ($soc->outstanding_limit) {
2399 print
'<tr><td class="titlefield">';
2400 print $langs->trans(
'OutstandingBill');
2401 print
'</td><td class="valuefield">';
2402 $arrayoutstandingbills = $soc->getOutstandingBills();
2403 print
price($arrayoutstandingbills[
'opened']).
' / ';
2404 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2410 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2411 $filterabsolutediscount =
"fk_facture_source IS NULL";
2412 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2414 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2415 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2418 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2419 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2420 $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>';
2422 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2424 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2425 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2426 $absolute_discount =
price2num($absolute_discount,
'MT');
2427 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2431 $backtopage = urlencode($_SERVER[
"PHP_SELF"].
'?id='.$object->id);
2432 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2439 print
$form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2440 print
'</td><td class="valuefield">';
2441 if ($action ==
'editdate') {
2442 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2443 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2444 print
'<input type="hidden" name="action" value="setdate">';
2445 print
$form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2446 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2449 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2450 if ($object->hasDelay() && empty($object->delivery_date)) {
2451 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2459 $editenable = $usercancreate;
2460 print
$form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2461 print
'</td><td class="valuefield">';
2462 if ($action ==
'editdate_livraison') {
2463 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2464 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2465 print
'<input type="hidden" name="action" value="setdate_livraison">';
2466 print
$form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2467 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2470 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2471 if ($object->hasDelay() && !empty($object->delivery_date)) {
2472 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2479 print
'<tr class="fielddeliverydelay"><td>';
2480 $editenable = $usercancreate;
2481 print
$form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2482 print
'</td><td class="valuefield">';
2483 if ($action ==
'editavailability') {
2484 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2486 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2493 $editenable = $usercancreate;
2494 print
$form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2495 print
'</td><td class="valuefield">';
2496 if ($action ==
'editshippingmethod') {
2497 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2499 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2506 if (
isModEnabled(
'stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
2507 $langs->load(
'stocks');
2508 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2511 $editenable = $usercancreate;
2512 print
$form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2513 print
'</td><td class="valuefield">';
2514 if ($action ==
'editwarehouse') {
2515 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2517 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2525 $editenable = $usercancreate;
2526 print
$form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2527 print
'</td><td class="valuefield">';
2528 if ($action ==
'editdemandreason') {
2529 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2531 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2537 $editenable = $usercancreate;
2538 print
$form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2539 print
'</td><td class="valuefield">';
2540 if ($action ==
'editconditions') {
2541 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2543 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2551 $editenable = $usercancreate;
2552 print
$form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2553 print
'</td><td class="valuefield">';
2554 if ($action ==
'editmode') {
2555 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2557 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2567 print
$form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2568 print
'</td><td class="valuefield">';
2569 if ($action ==
'editmulticurrencycode') {
2570 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2572 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2577 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2580 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2581 print
$form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2582 print
'</td><td class="valuefield">';
2583 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2584 if ($action ==
'actualizemulticurrencyrate') {
2587 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2589 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2590 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2591 print
'<div class="inline-block"> ';
2592 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2614 $tmparray = $object->getTotalWeightVolume();
2615 $totalWeight = $tmparray[
'weight'];
2616 $totalVolume = $tmparray[
'volume'];
2618 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2619 print
'<td class="valuefield">';
2620 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');
2624 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2625 print
'<td class="valuefield">';
2626 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');
2635 $editenable = $usercancreate;
2636 print
$form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2638 print
'<td class="valuefield">';
2639 if ($action !=
'editincoterm') {
2640 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2642 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2648 if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) &&
isModEnabled(
"banque")) {
2650 $editenable = $usercancreate;
2651 print
$form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2652 print
'</td><td class="valuefield">';
2653 if ($action ==
'editbankaccount') {
2654 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2656 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2663 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2668 print
'<div class="fichehalfright">';
2669 print
'<div class="underbanner clearboth"></div>';
2671 print
'<table class="border tableforfield centpercent">';
2673 if (
isModEnabled(
"multicurrency") && ($object->multicurrency_code != $conf->currency)) {
2675 print
'<tr><td class="titlefieldmiddle">'.$form->editfieldkey(
'MulticurrencyAmountHT',
'multicurrency_total_ht',
'', $object, 0).
'</td>';
2676 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>';
2680 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountVAT',
'multicurrency_total_tva',
'', $object, 0).
'</td>';
2681 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>';
2685 print
'<tr><td>'.$form->editfieldkey(
'MulticurrencyAmountTTC',
'multicurrency_total_ttc',
'', $object, 0).
'</td>';
2686 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>';
2692 if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->order_min_amount) {
2693 $alert =
' '.img_warning($langs->trans(
'OrderMinAmount').
': '.
price($object->thirdparty->order_min_amount));
2695 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
'AmountHT').
'</td>';
2696 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_ht, 1,
'', 1, -1, -1, $conf->currency).$alert.
'</td>';
2699 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>';
2702 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2703 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
2704 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2706 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2707 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
2708 print
'<td class="valuefield nowrap right amountcard">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
2712 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>';
2721 $formmargin->displayMarginInfos($object);
2728 print
'<div class="clearboth"></div><br>';
2730 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
2731 $blocname =
'contacts';
2732 $title = $langs->trans(
'ContactsAddresses');
2733 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2736 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
2737 $blocname =
'notes';
2738 $title = $langs->trans(
'Notes');
2739 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2747 $result = $object->getLinesArray();
2751 global $inputalsopricewithtax;
2752 $inputalsopricewithtax = 1;
2754 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2755 <input type="hidden" name="token" value="' .
newToken().
'">
2756 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2757 <input type="hidden" name="mode" value="">
2758 <input type="hidden" name="page_y" value="">
2759 <input type="hidden" name="id" value="' . $object->id.
'">';
2762 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2765 print
'<div class="div-table-responsive-no-min">';
2766 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2769 if (!empty($object->lines)) {
2770 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2773 $numlines = count($object->lines);
2779 if ($action !=
'editline') {
2784 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2785 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2786 if (empty($reshook))
2787 $object->formAddObjectLine(1, $mysoc, $soc);
2800 if ($action !=
'presend' && $action !=
'editline') {
2801 print
'<div class="tabsAction">';
2805 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2806 if (empty($reshook)) {
2809 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.
newToken().
'&id='.$object->id,
'');
2813 if (empty($user->socid)) {
2814 if ($object->statut >
Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) {
2816 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.
newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2818 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2824 if ($object->statut ==
Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) {
2825 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.$object->id,
'');
2829 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.
newToken().
'&id='.$object->id,
'');
2841 if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) {
2843 if ($usercancreatepurchaseorder) {
2844 print
dolGetButtonAction(
'', $langs->trans(
'AddPurchaseOrder'),
'default', DOL_URL_ROOT.
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2851 $langs->load(
"interventions");
2854 if ($user->hasRight(
'ficheinter',
'creer')) {
2855 print
dolGetButtonAction(
'', $langs->trans(
'AddIntervention'),
'default', DOL_URL_ROOT.
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2857 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'AddIntervention'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2864 $langs->load(
"contracts");
2866 if ($user->hasRight(
'contrat',
'creer')) {
2867 print
dolGetButtonAction(
'', $langs->trans(
'AddContract'),
'default', DOL_URL_ROOT.
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid,
'');
2874 $numshipping = $object->nb_expedition();
2877 if ((
isModEnabled(
'expedition_bon') && $user->rights->expedition->creer) || ($conf->delivery_note->enabled && $user->rights->expedition->delivery->creer)) {
2878 if ($user->hasRight(
'expedition',
'creer')) {
2879 print
dolGetButtonAction(
'', $langs->trans(
'CreateShipment'),
'default', DOL_URL_ROOT.
'/expedition/shipment.php?id='.$object->id,
'');
2881 print
dolGetButtonAction($langs->trans(
'NotAllowed'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2884 $langs->load(
"errors");
2885 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2892 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.
newToken().
'&id='.$object->id,
'');
2897 if (
isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer') && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
2898 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,
'');
2900 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2901 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.
newToken().
'&id='.$object->id,
'');
2905 if ($usercancreate && $object->statut >=
Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) {
2906 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.
newToken().
'&id='.$object->id,
'');
2910 if ($usercancreate) {
2911 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.
newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
2916 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>';
2920 if ($usercandelete) {
2921 if ($numshipping == 0) {
2922 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
2924 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2932 if (
GETPOST(
'modelselected')) {
2933 $action =
'presend';
2936 if ($action !=
'presend') {
2937 print
'<div class="fichecenter"><div class="fichehalfleft">';
2938 print
'<a name="builddoc"></a>';
2941 $relativepath = $objref.
'/'.$objref.
'.pdf';
2942 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
2943 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2944 $genallowed = $usercanread;
2945 $delallowed = $usercancreate;
2946 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
2950 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'order'));
2952 $compatibleImportElementsList =
false;
2955 $compatibleImportElementsList = array(
'commande',
'propal');
2957 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
2961 if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) {
2962 $useonlinepayment = 0;
2965 print
'<br><!-- Link to pay -->';
2966 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
2967 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
2970 print
'</div><div class="fichehalfright">';
2973 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2975 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1);
2977 print
'</div></div>';
2981 $modelmail =
'order_send';
2982 $defaulttopic =
'SendOrderRef';
2983 $diroutput = $conf->commande->multidir_output[$object->entity];
2984 $trackid =
'ord'.$object->id;
2986 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage a WYSIWYG editor.
static createDepositFromOrigin(CommonObject $origin, $date, $payment_terms_id, User $user, $notrigger=0, $autoValidateDeposit=false, $overrideFields=array())
Creates a deposit from a proposal or an order by grouping lines by VAT rates.
const TYPE_DEPOSIT
Deposit invoice.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage notifications.
Class ProductCombination Used to represent a product combination.
Class to manage products or services.
File of class to manage predefined price products or services by customer.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$formconfirm
if ($action == 'delbookkeepingyear') {
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.