40require
'../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formorder.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/order.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
53if (isModEnabled(
"propal")) {
54 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
57if (isModEnabled(
'project')) {
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
62if (isModEnabled(
'variants')) {
63 require_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
68$langs->loadLangs(array(
'orders',
'sendings',
'companies',
'bills',
'propal',
'deliveries',
'products',
'other'));
70if (isModEnabled(
'incoterm')) {
71 $langs->load(
'incoterm');
73if (isModEnabled(
'margin')) {
74 $langs->load(
'margins');
76if (isModEnabled(
'productbatch')) {
77 $langs->load(
'productbatch');
83$socid =
GETPOST(
'socid',
'int');
84$action =
GETPOST(
'action',
'aZ09');
85$cancel =
GETPOST(
'cancel',
'alpha');
86$confirm =
GETPOST(
'confirm',
'alpha');
87$backtopage =
GETPOST(
'backtopage',
'alpha');
89$lineid =
GETPOST(
'lineid',
'int');
90$contactid =
GETPOST(
'contactid',
'int');
91$projectid =
GETPOST(
'projectid',
'int');
92$origin =
GETPOST(
'origin',
'alpha');
102if (!empty($user->socid)) {
103 $socid = $user->socid;
107$hookmanager->initHooks(array(
'ordercard',
'globalcard'));
115$extrafields->fetch_name_optionals_label($object->table_element);
118include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
121$usercanread = $user->hasRight(
"commande",
"lire");
122$usercancreate = $user->hasRight(
"commande",
"creer");
123$usercandelete = $user->hasRight(
"commande",
"supprimer");
126$usercanclose = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'close')));
127$usercanvalidate = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'validate')));
128$usercancancel = ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'annuler')));
129$usercansend = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'send'));
130$usercangeneretedoc = (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'commande',
'order_advance',
'generetedoc'));
132$usermustrespectpricemin = ((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && empty($user->rights->produit->ignore_price_min_advance)) || !
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS'));
133$usercancreatepurchaseorder = ($user->hasRight(
'fournisseur',
'commande',
'creer') || $user->hasRight(
'supplier_order',
'creer'));
135$permissionnote = $usercancreate;
136$permissiondellink = $usercancreate;
137$permissiontoadd = $usercancreate;
142$date_delivery =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'), 0,
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
149$parameters = array(
'socid' => $socid);
151$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
156if (empty($reshook)) {
157 $backurlforlist = DOL_URL_ROOT.
'/commande/list.php';
159 if (empty($backtopage) || ($cancel && empty($id))) {
160 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
161 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
162 $backtopage = $backurlforlist;
164 $backtopage = DOL_URL_ROOT.
'/commande/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
169 $selectedLines =
GETPOST(
'toselect',
'array');
172 if (!empty($backtopageforcancel)) {
173 header(
"Location: ".$backtopageforcancel);
175 } elseif (!empty($backtopage)) {
176 header(
"Location: ".$backtopage);
182 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
184 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
186 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
189 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $usercancreate) {
190 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers')) {
193 if ($object->id > 0) {
195 $orig = clone $object;
197 $result = $object->createFromClone($user, $socid);
199 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
208 } elseif ($action ==
'reopen' && $usercancreate) {
212 $result = $object->setDraft($user, $idwarehouse);
217 $result = $object->set_reopen($user);
225 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $usercandelete) {
227 $result = $object->delete($user);
229 header(
'Location: list.php?restore_lastsearch_values=1');
234 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $usercancreate) {
236 $result = $object->deleteline($user, $lineid);
239 $object->line_order(
true);
241 $outputlangs = $langs;
244 $newlang =
GETPOST(
'lang_id',
'aZ09');
247 $newlang = $object->thirdparty->default_lang;
249 if (!empty($newlang)) {
251 $outputlangs->setDefaultLang($newlang);
254 $ret = $object->fetch($object->id);
255 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
258 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
263 } elseif ($action ==
'classin' && $usercancreate) {
265 $object->setProject(
GETPOST(
'projectid',
'int'));
266 } elseif ($action ==
'add' && $usercancreate) {
269 $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'));
271 if ($datecommande ==
'') {
272 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Date')),
null,
'errors');
278 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Customer")),
null,
'errors');
284 $object->socid = $socid;
285 $object->fetch_thirdparty();
289 $object->date_commande = $datecommande;
290 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
291 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
292 $object->source =
GETPOST(
'source_id',
'int');
293 $object->fk_project =
GETPOST(
'projectid',
'int');
294 $object->ref_client =
GETPOST(
'ref_client',
'alpha');
295 $object->model_pdf =
GETPOST(
'model');
296 $object->cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
297 $object->deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
298 $object->mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
299 $object->fk_account =
GETPOST(
'fk_account',
'int');
300 $object->availability_id =
GETPOST(
'availability_id');
301 $object->demand_reason_id =
GETPOST(
'demand_reason_id',
'int');
302 $object->delivery_date = $date_delivery;
303 $object->shipping_method_id =
GETPOST(
'shipping_method_id',
'int');
304 $object->warehouse_id =
GETPOST(
'warehouse_id',
'int');
305 $object->fk_delivery_address =
GETPOST(
'fk_address',
'int');
306 $object->contact_id =
GETPOST(
'contactid',
'int');
307 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
308 $object->location_incoterms =
GETPOST(
'location_incoterms',
'alpha');
309 $object->multicurrency_code =
GETPOST(
'multicurrency_code',
'alpha');
310 $object->multicurrency_tx =
GETPOST(
'originmulticurrency_tx',
'int');
313 $ret = $extrafields->setOptionalsFromPost(
null, $object);
320 if (!empty($origin) && !empty($originid)) {
322 $element = $subelement = $origin;
324 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
325 $element = $regs [1];
326 $subelement = $regs [2];
330 if ($element ==
'order') {
331 $element = $subelement =
'commande';
333 if ($element ==
'propal') {
334 $element =
'comm/propal';
335 $subelement =
'propal';
337 if ($element ==
'contract') {
338 $element = $subelement =
'contrat';
341 $object->origin = $origin;
342 $object->origin_id = $originid;
345 $object->linked_objects [$object->origin] = $object->origin_id;
346 $other_linked_objects =
GETPOST(
'other_linked_objects',
'array');
347 if (!empty($other_linked_objects)) {
348 $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
352 $object_id = $object->create($user);
354 if ($object_id > 0) {
357 $classname = ucfirst($subelement);
358 $srcobject =
new $classname($db);
360 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
361 $result = $srcobject->fetch($object->origin_id);
363 $lines = $srcobject->lines;
364 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
365 $srcobject->fetch_lines();
366 $lines = $srcobject->lines;
370 $num = count($lines);
372 for ($i = 0; $i < $num; $i++) {
373 if (!in_array($lines[$i]->
id, $selectedLines)) {
377 $label = (!empty($lines[$i]->label) ? $lines[$i]->label :
'');
378 $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc :
'');
379 $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
383 $date_start = $lines[$i]->date_debut_prevue;
384 if ($lines[$i]->date_debut_reel) {
385 $date_start = $lines[$i]->date_debut_reel;
387 if ($lines[$i]->date_start) {
388 $date_start = $lines[$i]->date_start;
390 $date_end = $lines[$i]->date_fin_prevue;
391 if ($lines[$i]->date_fin_reel) {
392 $date_end = $lines[$i]->date_fin_reel;
394 if ($lines[$i]->date_end) {
395 $date_end = $lines[$i]->date_end;
399 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
404 if (method_exists($lines[$i],
'fetch_optionals')) {
405 $lines[$i]->fetch_optionals();
406 $array_options = $lines[$i]->array_options;
409 $tva_tx = $lines[$i]->tva_tx;
410 if (!empty($lines[$i]->vat_src_code) && !preg_match(
'/\(/', $tva_tx)) {
411 $tva_tx .=
' ('.$lines[$i]->vat_src_code.
')';
414 $result = $object->addline(
416 $lines[$i]->subprice,
419 $lines[$i]->localtax1_tx,
420 $lines[$i]->localtax2_tx,
421 $lines[$i]->fk_product,
422 $lines[$i]->remise_percent,
423 $lines[$i]->info_bits,
424 $lines[$i]->fk_remise_except,
431 $lines[$i]->special_code,
433 $lines[$i]->fk_fournprice,
448 if ($result > 0 && $lines[$i]->product_type == 9) {
449 $fk_parent_line = $result;
484 $parameters = array(
'objFrom' => $srcobject);
486 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
501 $object_id = $object->create($user);
506 if ($object_id > 0) {
507 if (
GETPOST(
'contactid',
'int')) {
508 $result = $object->add_contact(
GETPOST(
'contactid',
'int'),
'CUSTOMER',
'external');
520 if ($object_id > 0 && !$error) {
522 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object_id);
530 } elseif ($action ==
'classifybilled' && $usercancreate) {
531 $ret = $object->classifyBilled($user);
536 } elseif ($action ==
'classifyunbilled' && $usercancreate) {
537 $ret = $object->classifyUnBilled($user);
541 } elseif ($action ==
'setref_client' && $usercancreate) {
543 $result = $object->set_ref_client($user,
GETPOST(
'ref_client'));
547 } elseif ($action ==
'setremise' && $usercancreate) {
552 } elseif ($action ==
'setabsolutediscount' && $usercancreate) {
554 if ($object->id > 0) {
555 $object->insert_discount(
GETPOST(
'remise_id'));
560 } elseif ($action ==
'setdate' && $usercancreate) {
563 $result = $object->set_date($user, $date);
567 } elseif ($action ==
'setdate_livraison' && $usercancreate) {
568 $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'));
571 $result = $object->setDeliveryDate($user, $date_delivery);
575 } elseif ($action ==
'setmode' && $usercancreate) {
576 $result = $object->setPaymentMethods(
GETPOST(
'mode_reglement_id',
'int'));
580 } elseif ($action ==
'setmulticurrencycode' && $usercancreate) {
582 $result = $object->setMulticurrencyCode(
GETPOST(
'multicurrency_code',
'alpha'));
583 } elseif ($action ==
'setmulticurrencyrate' && $usercancreate) {
585 $result = $object->setMulticurrencyRate(
price2num(
GETPOST(
'multicurrency_tx')),
GETPOST(
'calculation_mode',
'int'));
586 } elseif ($action ==
'setavailability' && $usercancreate) {
587 $result = $object->availability(
GETPOST(
'availability_id'));
591 } elseif ($action ==
'setdemandreason' && $usercancreate) {
592 $result = $object->demand_reason(
GETPOST(
'demand_reason_id'));
596 } elseif ($action ==
'setconditions' && $usercancreate) {
597 $result = $object->setPaymentTerms(
GETPOST(
'cond_reglement_id',
'int'),
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha'));
603 $outputlangs = $langs;
604 $newlang =
GETPOST(
'lang_id',
'alpha');
606 $newlang = $object->thirdparty->default_lang;
608 if (!empty($newlang)) {
610 $outputlangs->setDefaultLang($newlang);
613 $ret = $object->fetch($object->id);
614 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
617 } elseif ($action ==
'set_incoterms' && isModEnabled(
'incoterm')) {
619 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
623 } elseif ($action ==
'setbankaccount' && $usercancreate) {
625 $result = $object->setBankAccount(
GETPOST(
'fk_account',
'int'));
629 } elseif ($action ==
'setshippingmethod' && $usercancreate) {
631 $result = $object->setShippingMethod(
GETPOST(
'shipping_method_id',
'int'));
635 } elseif ($action ==
'setwarehouse' && $usercancreate) {
637 $result = $object->setWarehouse(
GETPOST(
'warehouse_id',
'int'));
645 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'vatforalllines',
'alpha') !==
'') {
647 $vat_rate = (
GETPOST(
'vatforalllines') ?
GETPOST(
'vatforalllines') : 0);
648 $vat_rate = str_replace(
'*',
'', $vat_rate);
649 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
650 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
651 foreach ($object->lines as $line) {
652 $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);
654 } elseif ($action ==
'addline' &&
GETPOST(
'submitforalllines',
'alpha') &&
GETPOST(
'remiseforalllines',
'alpha') !==
'' && $usercancreate) {
656 $remise_percent = (
GETPOST(
'remiseforalllines') ?
GETPOST(
'remiseforalllines') : 0);
657 $remise_percent = str_replace(
'*',
'', $remise_percent);
658 foreach ($object->lines as $line) {
659 $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);
661 } elseif ($action ==
'addline' && $usercancreate) {
662 $langs->load(
'errors');
667 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
670 $price_ht_devise =
'';
672 $price_ttc_devise =
'';
678 if (
GETPOST(
'price_ht') !==
'') {
681 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
684 if (
GETPOST(
'price_ttc') !==
'') {
687 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
691 $prod_entry_mode =
GETPOST(
'prod_entry_mode',
'aZ09');
692 if ($prod_entry_mode ==
'free') {
695 $idprod =
GETPOST(
'idprod',
'int');
698 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
703 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
707 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef,
'alpha'),
'', 2) : 0);
708 if (empty($remise_percent)) {
713 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
714 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
716 if (is_array($extralabelsline)) {
718 foreach ($extralabelsline as $key => $value) {
719 unset($_POST[
"options_".$key]);
723 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
724 setEventMessages($langs->trans(
'ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv(
'UnitPriceHT'), $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
727 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) &&
GETPOST(
'type') < 0) {
728 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Type')),
null,
'errors');
731 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && $price_ht ===
'' && $price_ht_devise ===
'' && $price_ttc ===
'' && $price_ttc_devise ===
'') {
732 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"UnitPriceHT")),
null,
'errors');
736 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
740 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
743 if ($prod_entry_mode ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
744 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Description')),
null,
'errors');
748 if (!$error && isModEnabled(
'variants') && $prod_entry_mode !=
'free') {
749 if ($combinations =
GETPOST(
'combinations',
'array')) {
753 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
754 $idprod = $res->fk_product_child;
756 setEventMessages($langs->trans(
'ErrorProductCombinationNotFound'),
null,
'errors');
762 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
766 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
768 $price_min = $price_min_ttc = 0;
773 if (!empty($idprod) && $idprod > 0) {
775 $prod->fetch($idprod);
777 $label = ((
GETPOST(
'product_label') &&
GETPOST(
'product_label') != $prod->label) ?
GETPOST(
'product_label') :
'');
786 $pu_ht = $prod->price;
787 $pu_ttc = $prod->price_ttc;
788 $price_min = $prod->price_min;
789 $price_min_ttc = $prod->price_min_ttc;
790 $price_base_type = $prod->price_base_type;
793 if (
getDolGlobalString(
'PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
794 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
795 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
796 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
797 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
798 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
800 if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
801 $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
803 if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
804 $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
809 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
813 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
815 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
817 if (count($prodcustprice->lines) > 0) {
818 $pu_ht =
price($prodcustprice->lines[0]->price);
819 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
820 $price_min =
price($prodcustprice->lines[0]->price_min);
821 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
822 $price_base_type = $prodcustprice->lines[0]->price_base_type;
823 $tva_tx = $prodcustprice->lines[0]->tva_tx;
824 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
825 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
827 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
828 if (empty($tva_tx)) {
837 if ($prod->prices_by_qty[0]) {
842 foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
843 if ($priceforthequantityarray[
'rowid'] != $pqp) {
847 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
848 $pu_ht = $priceforthequantityarray[
'unitprice'];
850 $pu_ttc = $priceforthequantityarray[
'unitprice'];
858 if ($prod->prices_by_qty[$object->thirdparty->price_level]) {
862 foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
863 if ($priceforthequantityarray[
'rowid'] != $pqp) {
867 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
868 $pu_ht = $priceforthequantityarray[
'unitprice'];
870 $pu_ttc = $priceforthequantityarray[
'unitprice'];
878 $tmpvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
879 $tmpprodvat = (float)
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
882 if (!empty($price_ht) || $price_ht ===
'0') {
884 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
885 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
887 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
888 } elseif ($tmpvat != $tmpprodvat) {
890 if ($price_base_type !=
'HT') {
891 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
893 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
901 $outputlangs = $langs;
903 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
904 $newlang =
GETPOST(
'lang_id',
'aZ09');
906 if (empty($newlang)) {
907 $newlang = $object->thirdparty->default_lang;
909 if (!empty($newlang)) {
911 $outputlangs->setDefaultLang($newlang);
914 $desc = (!empty($prod->multilangs[$outputlangs->defaultlang][
"description"])) ? $prod->multilangs[$outputlangs->defaultlang][
"description"] : $prod->
description;
916 $desc = $prod->description;
925 $desc = $product_desc;
931 if (!
getDolGlobalString(
'MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
935 $outputlangs = $langs;
937 if (empty($newlang) &&
GETPOST(
'lang_id',
'alpha')) {
938 $newlang =
GETPOST(
'lang_id',
'alpha');
940 if (empty($newlang)) {
941 $newlang = $object->thirdparty->default_lang;
943 if (!empty($newlang)) {
945 $outputlangs->setDefaultLang($newlang);
946 $outputlangs->load(
'products');
948 if (!empty($prod->customcode)) {
949 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
951 if (!empty($prod->customcode) && !empty($prod->country_code)) {
954 if (!empty($prod->country_code)) {
955 $tmptxt .= $outputlangs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $outputlangs, 0);
958 if (!empty($prod->customcode)) {
959 $tmptxt .= $langs->transnoentitiesnoconv(
"CustomCode").
': '.$prod->customcode;
961 if (!empty($prod->customcode) && !empty($prod->country_code)) {
964 if (!empty($prod->country_code)) {
965 $tmptxt .= $langs->transnoentitiesnoconv(
"CountryOrigin").
': '.
getCountry($prod->country_code, 0, $db, $langs, 0);
973 $fk_unit = $prod->fk_unit;
977 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
978 $tva_tx = str_replace(
'*',
'', $tva_tx);
979 if (empty($tva_tx)) {
982 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
983 $desc = $product_desc;
985 $fk_unit =
GETPOST(
'units',
'alpha');
986 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
987 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
989 if ($pu_ttc && !$pu_ht) {
990 $price_base_type =
'TTC';
1000 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty);
1001 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty);
1008 $pu_equivalent = $pu_ht;
1009 $pu_equivalent_ttc = $pu_ttc;
1011 $currency_tx = $object->multicurrency_tx;
1015 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1016 $pu_equivalent = $pu_ht_devise * $currency_tx;
1018 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1019 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1036 if ($usermustrespectpricemin) {
1037 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1038 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1041 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1042 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1050 $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);
1053 $ret = $object->fetch($object->id);
1054 $object->fetch_thirdparty();
1058 $outputlangs = $langs;
1059 $newlang =
GETPOST(
'lang_id',
'alpha');
1061 $newlang = $object->thirdparty->default_lang;
1063 if (!empty($newlang)) {
1064 $outputlangs =
new Translate(
"", $conf);
1065 $outputlangs->setDefaultLang($newlang);
1068 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1071 unset($_POST[
'prod_entry_mode']);
1073 unset($_POST[
'qty']);
1074 unset($_POST[
'type']);
1075 unset($_POST[
'remise_percent']);
1076 unset($_POST[
'price_ht']);
1077 unset($_POST[
'multicurrency_price_ht']);
1078 unset($_POST[
'price_ttc']);
1079 unset($_POST[
'tva_tx']);
1080 unset($_POST[
'product_ref']);
1081 unset($_POST[
'product_label']);
1082 unset($_POST[
'product_desc']);
1083 unset($_POST[
'fournprice']);
1084 unset($_POST[
'buying_price']);
1085 unset($_POST[
'np_marginRate']);
1086 unset($_POST[
'np_markRate']);
1087 unset($_POST[
'dp_desc']);
1088 unset($_POST[
'idprod']);
1089 unset($_POST[
'units']);
1091 unset($_POST[
'date_starthour']);
1092 unset($_POST[
'date_startmin']);
1093 unset($_POST[
'date_startsec']);
1094 unset($_POST[
'date_startday']);
1095 unset($_POST[
'date_startmonth']);
1096 unset($_POST[
'date_startyear']);
1097 unset($_POST[
'date_endhour']);
1098 unset($_POST[
'date_endmin']);
1099 unset($_POST[
'date_endsec']);
1100 unset($_POST[
'date_endday']);
1101 unset($_POST[
'date_endmonth']);
1102 unset($_POST[
'date_endyear']);
1108 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'save')) {
1120 if (preg_match(
'/\*/',
GETPOST(
'tva_tx'))) {
1125 $vat_rate = (
GETPOST(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0);
1126 $vat_rate = str_replace(
'*',
'', $vat_rate);
1127 $localtax1_rate =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1128 $localtax2_rate =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1138 $pu_equivalent = $pu_ht;
1139 $pu_equivalent_ttc = $pu_ttc;
1141 $currency_tx = $object->multicurrency_tx;
1145 if ($pu_ht ==
'' && $pu_ht_devise !=
'' && $currency_tx !=
'') {
1146 $pu_equivalent = $pu_ht_devise * $currency_tx;
1148 if ($pu_ttc ==
'' && $pu_ttc_devise !=
'' && $currency_tx !=
'') {
1149 $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
1168 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1169 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1171 if (is_array($extralabelsline)) {
1172 foreach ($extralabelsline as $key => $value) {
1173 unset($_POST[
"options_".$key]);
1178 $special_code =
GETPOST(
'special_code');
1186 $productid =
GETPOST(
'productid',
'int');
1187 if (!empty($productid)) {
1189 $product->fetch($productid);
1191 $type = $product->type;
1193 $price_min = $product->price_min;
1195 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1197 $price_min_ttc = $product->price_min_ttc;
1199 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1205 if ($usermustrespectpricemin) {
1206 if ($pu_equivalent && $price_min && ((
price2num($pu_equivalent) * (1 - $remise_percent / 100)) <
price2num($price_min)) && $price_base_type ==
'HT') {
1207 $mesg = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1210 $action =
'editline';
1211 } elseif ($pu_equivalent_ttc && $price_min_ttc && ((
price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) <
price2num($price_min_ttc)) && $price_base_type ==
'TTC') {
1212 $mesg = $langs->trans(
"CantBeLessThanMinPriceInclTax",
price(
price2num($price_min_ttc,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1215 $action =
'editline';
1220 $label = (
GETPOST(
'product_label') ?
GETPOST(
'product_label') :
'');
1224 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1226 $action =
'editline';
1231 setEventMessages($langs->trans(
'FieldCannotBeNegative', $langs->transnoentitiesnoconv(
'Qty')),
null,
'errors');
1233 $action =
'editline';
1237 if (!$user->hasRight(
'margins',
'creer')) {
1238 foreach ($object->lines as &$line) {
1239 if ($line->id ==
GETPOST(
'lineid',
'int')) {
1240 $fournprice = $line->fk_fournprice;
1241 $buyingprice = $line->pa_ht;
1247 $price_base_type =
'HT';
1249 if (empty($pu) && !empty($pu_ttc)) {
1251 $price_base_type =
'TTC';
1254 $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);
1259 $outputlangs = $langs;
1262 $newlang =
GETPOST(
'lang_id',
'aZ09');
1265 $newlang = $object->thirdparty->default_lang;
1267 if (!empty($newlang)) {
1268 $outputlangs =
new Translate(
"", $conf);
1269 $outputlangs->setDefaultLang($newlang);
1272 $ret = $object->fetch($object->id);
1273 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1276 unset($_POST[
'qty']);
1277 unset($_POST[
'type']);
1278 unset($_POST[
'productid']);
1279 unset($_POST[
'remise_percent']);
1280 unset($_POST[
'price_ht']);
1281 unset($_POST[
'multicurrency_price_ht']);
1282 unset($_POST[
'price_ttc']);
1283 unset($_POST[
'tva_tx']);
1284 unset($_POST[
'product_ref']);
1285 unset($_POST[
'product_label']);
1286 unset($_POST[
'product_desc']);
1287 unset($_POST[
'fournprice']);
1288 unset($_POST[
'buying_price']);
1290 unset($_POST[
'date_starthour']);
1291 unset($_POST[
'date_startmin']);
1292 unset($_POST[
'date_startsec']);
1293 unset($_POST[
'date_startday']);
1294 unset($_POST[
'date_startmonth']);
1295 unset($_POST[
'date_startyear']);
1296 unset($_POST[
'date_endhour']);
1297 unset($_POST[
'date_endmin']);
1298 unset($_POST[
'date_endsec']);
1299 unset($_POST[
'date_endday']);
1300 unset($_POST[
'date_endmonth']);
1301 unset($_POST[
'date_endyear']);
1306 } elseif ($action ==
'updateline' && $usercancreate &&
GETPOST(
'cancel',
'alpha')) {
1307 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
1309 } elseif ($action ==
'confirm_validate' && $confirm ==
'yes' && $usercanvalidate) {
1310 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1312 $qualified_for_stock_change = 0;
1314 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1316 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1320 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1321 if (!$idwarehouse || $idwarehouse == -1) {
1323 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1329 $locationTarget =
'';
1333 $result = $object->valid($user, $idwarehouse);
1338 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
1341 GETPOST(
'generate_deposit',
'alpha') ==
'on' && !empty($deposit_percent_from_payment_terms)
1342 && isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer')
1344 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1347 $forceFields = array();
1349 if (GETPOSTISSET(
'date_pointoftax')) {
1350 $forceFields[
'date_pointoftax'] =
dol_mktime(0, 0, 0,
GETPOST(
'date_pointoftaxmonth',
'int'),
GETPOST(
'date_pointoftaxday',
'int'),
GETPOST(
'date_pointoftaxyear',
'int'));
1357 $locationTarget = DOL_URL_ROOT .
'/compta/facture/card.php?id=' . $deposit->id;
1369 $outputlangs = $langs;
1372 $newlang =
GETPOST(
'lang_id',
'aZ09');
1375 $newlang = $object->thirdparty->default_lang;
1377 if (!empty($newlang)) {
1378 $outputlangs =
new Translate(
"", $conf);
1379 $outputlangs->setDefaultLang($newlang);
1381 $model = $object->model_pdf;
1382 $ret = $object->fetch($id);
1384 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1387 $deposit->fetch($deposit->id);
1388 $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1392 if ($locationTarget) {
1393 header(
'Location: ' . $locationTarget);
1404 } elseif ($action ==
'confirm_modif' && $usercancreate) {
1406 $idwarehouse =
GETPOST(
'idwarehouse');
1408 $qualified_for_stock_change = 0;
1410 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1412 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1416 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1417 if (!$idwarehouse || $idwarehouse == -1) {
1419 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1425 $result = $object->setDraft($user, $idwarehouse);
1429 $outputlangs = $langs;
1432 $newlang =
GETPOST(
'lang_id',
'aZ09');
1435 $newlang = $object->thirdparty->default_lang;
1437 if (!empty($newlang)) {
1438 $outputlangs =
new Translate(
"", $conf);
1439 $outputlangs->setDefaultLang($newlang);
1441 $model = $object->model_pdf;
1442 $ret = $object->fetch($id);
1444 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1450 } elseif ($action ==
'confirm_shipped' && $confirm ==
'yes' && $usercanclose) {
1451 $result = $object->cloture($user);
1455 } elseif ($action ==
'confirm_cancel' && $confirm ==
'yes' && $usercanvalidate) {
1456 $idwarehouse =
GETPOST(
'idwarehouse',
'int');
1458 $qualified_for_stock_change = 0;
1460 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1462 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1466 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
1467 if (!$idwarehouse || $idwarehouse == -1) {
1469 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Warehouse")),
null,
'errors');
1475 $result = $object->cancel($idwarehouse);
1483 if ($action ==
'update_extras') {
1484 $object->oldcopy =
dol_clone($object, 2);
1487 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
1494 $result = $object->insertExtraFields(
'ORDER_MODIFY');
1502 $action =
'edit_extras';
1507 if ($action ==
'import_lines_from_object'
1511 $fromElement =
GETPOST(
'fromelement');
1512 $fromElementid =
GETPOST(
'fromelementid');
1513 $importLines =
GETPOST(
'line_checkbox');
1515 if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
1516 if ($fromElement ==
'commande') {
1518 $lineClassName =
'OrderLine';
1519 } elseif ($fromElement ==
'propal') {
1520 dol_include_once(
'/comm/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1521 $lineClassName =
'PropaleLigne';
1522 } elseif ($fromElement ==
'facture') {
1523 dol_include_once(
'/compta/'.$fromElement.
'/class/'.$fromElement.
'.class.php');
1524 $lineClassName =
'FactureLigne';
1526 $nextRang = count($object->lines) + 1;
1529 foreach ($importLines as $lineId) {
1530 $lineId = intval($lineId);
1531 $originLine =
new $lineClassName($db);
1532 if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
1533 $originLine->fetch_optionals();
1534 $desc = $originLine->desc;
1535 $pu_ht = $originLine->subprice;
1536 $qty = $originLine->qty;
1537 $txtva = $originLine->tva_tx;
1538 $txlocaltax1 = $originLine->localtax1_tx;
1539 $txlocaltax2 = $originLine->localtax2_tx;
1540 $fk_product = $originLine->fk_product;
1541 $remise_percent = $originLine->remise_percent;
1542 $date_start = $originLine->date_start;
1543 $date_end = $originLine->date_end;
1545 $info_bits = $originLine->info_bits;
1546 $fk_remise_except = $originLine->fk_remise_except;
1547 $price_base_type =
'HT';
1549 $type = $originLine->product_type;
1550 $rang = $nextRang++;
1551 $special_code = $originLine->special_code;
1552 $origin = $originLine->element;
1553 $origin_id = $originLine->id;
1554 $fk_parent_line = 0;
1555 $fk_fournprice = $originLine->fk_fournprice;
1556 $pa_ht = $originLine->pa_ht;
1557 $label = $originLine->label;
1558 $array_options = $originLine->array_options;
1559 $situation_percent = 100;
1561 $fk_unit = $originLine->fk_unit;
1562 $pu_ht_devise = $originLine->multicurrency_subprice;
1564 $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);
1583 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1586 $upload_dir = !empty($conf->commande->multidir_output[$object->entity]) ? $conf->commande->multidir_output[$object->entity] : $conf->commande->dir_output;
1587 $permissiontoadd = $usercancreate;
1588 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1591 $triggersendname =
'ORDER_SENTBYMAIL';
1593 $autocopy =
'MAIN_MAIL_AUTOCOPY_ORDER_TO';
1594 $trackid =
'ord'.$object->id;
1595 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1599 if ($action ==
'addcontact') {
1600 if ($object->id > 0) {
1603 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1607 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1610 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1611 $langs->load(
"errors");
1612 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1617 } elseif ($action ==
'swapstatut') {
1619 if ($object->id > 0) {
1620 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1624 } elseif ($action ==
'deletecontact') {
1626 $result = $object->delete_contact($lineid);
1629 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1643$title = $object->ref.
" - ".$langs->trans(
'Card');
1644if ($action ==
'create') {
1645 $title = $langs->trans(
"NewOrder");
1647$help_url =
'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
1651$form =
new Form($db);
1655if (isModEnabled(
'project')) {
1660if ($action ==
'create' && $usercancreate) {
1665 $res = $soc->fetch($socid);
1670 $currency_code = $conf->currency;
1672 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1673 $deposit_percent =
GETPOST(
'cond_reglement_id_deposit_percent',
'alpha');
1674 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1675 $fk_account =
GETPOST(
'fk_account',
'int');
1677 if (!empty($origin) && !empty($originid)) {
1679 $element = $subelement = $origin;
1681 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1682 $element = $regs[1];
1683 $subelement = $regs[2];
1686 if ($element ==
'project') {
1687 $projectid = $originid;
1689 if (!$cond_reglement_id) {
1690 $cond_reglement_id = $soc->cond_reglement_id;
1692 if (!$deposit_percent) {
1693 $deposit_percent = $soc->deposit_percent;
1695 if (!$mode_reglement_id) {
1696 $mode_reglement_id = $soc->mode_reglement_id;
1698 if (!$remise_percent) {
1699 $remise_percent = $soc->remise_percent;
1707 if ($element ==
'order' || $element ==
'commande') {
1708 $element = $subelement =
'commande';
1709 } elseif ($element ==
'propal') {
1710 $element =
'comm/propal';
1711 $subelement =
'propal';
1712 } elseif ($element ==
'contract') {
1713 $element = $subelement =
'contrat';
1718 $classname = ucfirst($subelement);
1719 $objectsrc =
new $classname($db);
1720 $objectsrc->fetch($originid);
1721 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1722 $objectsrc->fetch_lines();
1724 $objectsrc->fetch_thirdparty();
1727 $objectsrc->fetch_optionals();
1728 $object->array_options = $objectsrc->array_options;
1730 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1731 $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client :
'');
1733 $soc = $objectsrc->thirdparty;
1734 $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1735 $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent :
null));
1736 $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1737 $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1738 $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
1739 $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1740 $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
1741 $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1746 $date_delivery = (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date :
'');
1748 if (isModEnabled(
"multicurrency")) {
1749 if (!empty($objectsrc->multicurrency_code)) {
1750 $currency_code = $objectsrc->multicurrency_code;
1752 if (
getDolGlobalString(
'MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
1753 $currency_tx = $objectsrc->multicurrency_tx;
1757 $note_private = $object->getDefaultCreateValueFor(
'note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1758 $note_public = $object->getDefaultCreateValueFor(
'note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1761 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1764 $cond_reglement_id = empty($soc->cond_reglement_id) ? $cond_reglement_id : $soc->cond_reglement_id;
1765 $deposit_percent = empty($soc->deposit_percent) ? $deposit_percent : $soc->deposit_percent;
1766 $mode_reglement_id = empty($soc->mode_reglement_id) ? $mode_reglement_id : $soc->mode_reglement_id;
1767 $fk_account = empty($soc->mode_reglement_id) ? $fk_account : $soc->fk_account;
1768 $availability_id = 0;
1769 $shipping_method_id = $soc->shipping_method_id;
1770 $warehouse_id = $soc->fk_warehouse;
1771 $demand_reason_id = $soc->demand_reason_id;
1776 if (isModEnabled(
"multicurrency") && !empty($soc->multicurrency_code)) {
1777 $currency_code = $soc->multicurrency_code;
1780 $note_private = $object->getDefaultCreateValueFor(
'note_private');
1781 $note_public = $object->getDefaultCreateValueFor(
'note_public');
1785 if (!
GETPOST(
'changecompany')) {
1786 if (GETPOSTISSET(
'cond_reglement_id')) {
1787 $cond_reglement_id =
GETPOST(
'cond_reglement_id',
'int');
1789 if (GETPOSTISSET(
'deposit_percent')) {
1792 if (GETPOSTISSET(
'mode_reglement_id')) {
1793 $mode_reglement_id =
GETPOST(
'mode_reglement_id',
'int');
1795 if (GETPOSTISSET(
'cond_reglement_id')) {
1796 $fk_account =
GETPOST(
'fk_account',
'int');
1801 if ($soc->fk_warehouse > 0) {
1802 $warehouse_id = $soc->fk_warehouse;
1804 if (isModEnabled(
'stock') && empty($warehouse_id) &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1806 $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
1808 if (empty($object->warehouse_id) &&
getDolGlobalString(
'MAIN_DEFAULT_WAREHOUSE_USER')) {
1809 $warehouse_id = $user->fk_warehouse;
1813 print
'<form name="crea_commande" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1814 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1815 print
'<input type="hidden" name="action" value="add">';
1816 print
'<input type="hidden" name="changecompany" value="0">';
1817 print
'<input type="hidden" name="remise_percent" value="'.$soc->remise_percent.
'">';
1818 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
1819 print
'<input type="hidden" name="originid" value="'.$originid.
'">';
1820 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1821 if (!empty($currency_tx)) {
1822 print
'<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.
'">';
1828 $parameters = array();
1830 $reshook = $hookmanager->executeHooks(
'tabContentCreateOrder', $parameters, $object, $action);
1831 if (empty($reshook)) {
1832 print
'<table class="border centpercent">';
1835 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>'.$langs->trans(
"Draft").
'</td></tr>';
1838 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td><td>';
1839 if (
getDolGlobalString(
'MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER') && !empty($origin) && !empty($originid)) {
1840 print
'<input type="text" name="ref_client" value="'.$ref_client.
'"></td>';
1842 print
'<input type="text" name="ref_client" value="'.GETPOST(
'ref_client').
'"></td>';
1848 print
'<td class="fieldrequired">'.$langs->trans(
'Customer').
'</td>';
1851 print $soc->getNomUrl(1,
'customer');
1852 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1855 print
'<td class="valuefieldcreate">';
1856 $filter =
'((s.client:IN:1,2,3) AND (s.status:=:1))';
1857 print
img_picto(
'',
'company',
'class="pictofixedwidth"').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 1, 0,
null, 0,
'minwidth175 maxwidth500 widthcentpercentminusxx');
1861 $(document).ready(function() {
1862 $("#socid").change(function() {
1863 console.log("We have changed the company - Reload page");
1864 var socid = $(this).val();
1866 $("input[name=action]").val("create");
1867 $("input[name=changecompany]").val("1");
1868 $("form[name=crea_commande]").submit();
1873 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>';
1881 print
"<tr><td>".$langs->trans(
"DefaultContact").
'</td><td>';
1882 print
img_picto(
'',
'contact',
'class="pictofixedwidth"');
1883 print $form->selectcontacts($soc->id, $contactid,
'contactid', 1, !empty($srccontactslist) ? $srccontactslist :
"",
'', 1,
'maxwidth200 widthcentpercentminusx');
1887 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1889 $absolute_discount = $soc->getAvailableDiscounts();
1893 $backtopage = $_SERVER[
"PHP_SELF"].
'?socid='.$thirdparty->id.
'&action='.$action.
'&origin='.urlencode(
GETPOST(
'origin')).
'&originid='.urlencode(
GETPOSTINT(
'originid'));
1894 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
1900 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Date').
'</td><td>';
1901 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1902 print $form->selectDate(
'',
're',
'',
'',
'',
"crea_commande", 1, 1);
1906 print
'<tr><td>'.$langs->trans(
"DateDeliveryPlanned").
'</td>';
1907 print
'<td colspan="3">';
1908 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date);
1909 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1910 print $form->selectDate($date_delivery ? $date_delivery : -1,
'liv_', 1, 1, 1);
1915 print
'<tr class="fielddeliverydelay"><td>'.$langs->trans(
'AvailabilityPeriod').
'</td><td>';
1916 print
img_picto(
'',
'clock',
'class="pictofixedwidth"');
1917 $form->selectAvailabilityDelay((GETPOSTISSET(
'availability_id') ?
GETPOST(
'availability_id') : $availability_id),
'availability_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1921 print
'<tr><td class="nowrap">'.$langs->trans(
'PaymentConditionsShort').
'</td><td>';
1922 print
img_picto(
'',
'payment',
'class="pictofixedwidth"');
1923 print $form->getSelectConditionsPaiements($cond_reglement_id,
'cond_reglement_id', 1, 1, 0,
'maxwidth200 widthcentpercentminusx', $deposit_percent);
1927 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>';
1928 print
img_picto(
'',
'bank',
'class="pictofixedwidth"');
1929 print $form->select_types_paiements($mode_reglement_id,
'mode_reglement_id',
'CRDT', 0, 1, 0, 0, 1,
'maxwidth200 widthcentpercentminusx', 1);
1933 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"banque")) {
1934 print
'<tr><td>'.$langs->trans(
'BankAccount').
'</td><td>';
1935 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"').$form->select_comptes($fk_account,
'fk_account', 0,
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx', 1);
1940 if (isModEnabled(
'expedition')) {
1941 print
'<tr><td>'.$langs->trans(
'SendingMethod').
'</td><td>';
1942 print
img_picto(
'',
'object_dolly',
'class="pictofixedwidth"');
1943 $form->selectShippingMethod(((GETPOSTISSET(
'shipping_method_id') &&
GETPOST(
'shipping_method_id',
'int') != 0) ?
GETPOST(
'shipping_method_id') : $shipping_method_id),
'shipping_method_id',
'', 1,
'', 0,
'maxwidth200 widthcentpercentminusx');
1948 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1949 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
1951 print
'<tr><td>'.$langs->trans(
'Warehouse').
'</td><td>';
1952 print
img_picto(
'',
'stock',
'class="pictofixedwidth"').$formproduct->selectWarehouses((GETPOSTISSET(
'warehouse_id') ?
GETPOST(
'warehouse_id') : $warehouse_id),
'warehouse_id',
'', 1, 0, 0,
'', 0, 0, array(),
'maxwidth500 widthcentpercentminusxx');
1957 print
'<tr><td>'.$langs->trans(
'Source').
'</td><td>';
1958 print
img_picto(
'',
'question',
'class="pictofixedwidth"');
1959 $form->selectInputReason((GETPOSTISSET(
'demand_reason_id') ?
GETPOST(
'demand_reason_id') : $demand_reason_id),
'demand_reason_id',
'', 1,
'maxwidth200 widthcentpercentminusx');
1965 if (isModEnabled(
'project')) {
1966 $langs->load(
"projects");
1968 print
'<td>'.$langs->trans(
"Project").
'</td><td>';
1969 print
img_picto(
'',
'project',
'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), (GETPOSTISSET(
'projectid') ?
GETPOST(
'projectid') : $projectid),
'projectid', 0, 0, 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth500 widthcentpercentminusxx');
1970 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>';
1976 if (isModEnabled(
'incoterm')) {
1978 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), !empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms, 1).
'</label></td>';
1979 print
'<td class="maxwidthonsmartphone">';
1980 $incoterm_id =
GETPOST(
'incoterm_id');
1981 $location_incoterms =
GETPOST(
'location_incoterms');
1982 if (empty($incoterm_id)) {
1983 $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms);
1984 $location_incoterms = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms);
1986 print
img_picto(
'',
'incoterm',
'class="pictofixedwidth"');
1987 print $form->select_incoterms($incoterm_id, $location_incoterms);
1992 $parameters = array();
1993 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1994 $parameters[
'objectsrc'] = $objectsrc;
1996 $parameters[
'socid'] = $socid;
1999 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
2000 print $hookmanager->resPrint;
2001 if (empty($reshook)) {
2002 if (
getDolGlobalString(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER') && !empty($soc->id)) {
2005 $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element);
2006 if ($soc->fetch_optionals() > 0) {
2007 $object->array_options = array_merge($object->array_options, $soc->array_options);
2011 print $object->showOptionals($extrafields,
'create', $parameters);
2015 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
2017 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2019 $preselected = $conf->global->COMMANDE_ADDON_PDF;
2020 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
2021 print $form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
2025 if (isModEnabled(
"multicurrency")) {
2027 print
'<td>'.$form->editfieldkey(
"Currency",
'multicurrency_code',
'', $object, 0).
'</td>';
2028 print
'<td class="maxwidthonsmartphone">';
2029 print
img_picto(
'',
'currency',
'class="pictofixedwidth"').$form->selectMultiCurrency(((GETPOSTISSET(
'multicurrency_code') && !
GETPOST(
'changecompany')) ?
GETPOST(
'multicurrency_code') : $currency_code),
'multicurrency_code', 0,
'', false,
'maxwidth200 widthcentpercentminusx');
2035 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
2038 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
2039 print $doleditor->Create(1);
2044 if (empty($user->socid)) {
2046 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
2049 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
2050 print $doleditor->Create(1);
2055 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2057 if ($origin ==
'contrat') {
2061 $objectsrc->update_price(1);
2064 print
"\n<!-- ".$classname.
" info -->";
2066 print
'<input type="hidden" name="amount" value="'.$objectsrc->total_ht.
'">'.
"\n";
2067 print
'<input type="hidden" name="total" value="'.$objectsrc->total_ttc.
'">'.
"\n";
2068 print
'<input type="hidden" name="tva" value="'.$objectsrc->total_tva.
'">'.
"\n";
2069 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
2070 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
2072 switch ($classname) {
2074 $newclassname =
'CommercialProposal';
2077 $newclassname =
'Order';
2080 $newclassname =
'Sending';
2083 $newclassname =
'Contract';
2086 $newclassname = $classname;
2089 print
'<tr><td>'.$langs->trans($newclassname).
'</td><td>'.$objectsrc->getNomUrl(1).
'</td></tr>';
2092 print
'<tr><td>'.$langs->trans(
'AmountHT').
'</td><td>'.
price($objectsrc->total_ht).
'</td></tr>';
2093 print
'<tr><td>'.$langs->trans(
'AmountVAT').
'</td><td>'.
price($objectsrc->total_tva).
"</td></tr>";
2094 if ($mysoc->localtax1_assuj ==
"1" || $objectsrc->total_localtax1 != 0) {
2095 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax1).
"</td></tr>";
2098 if ($mysoc->localtax2_assuj ==
"1" || $objectsrc->total_localtax2 != 0) {
2099 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td><td>'.
price($objectsrc->total_localtax2).
"</td></tr>";
2102 print
'<tr><td>'.$langs->trans(
'AmountTTC').
'</td><td>'.
price($objectsrc->total_ttc).
"</td></tr>";
2104 if (isModEnabled(
"multicurrency")) {
2105 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountHT').
'</td><td>'.
price($objectsrc->multicurrency_total_ht).
'</td></tr>';
2106 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountVAT').
'</td><td>'.
price($objectsrc->multicurrency_total_tva).
"</td></tr>";
2107 print
'<tr><td>'.$langs->trans(
'MulticurrencyAmountTTC').
'</td><td>'.
price($objectsrc->multicurrency_total_ttc).
"</td></tr>";
2118 print $form->buttonsSaveCancel(
"CreateDraft");
2121 if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
2122 $title = $langs->trans(
'ProductsAndServices');
2125 print
'<div class="div-table-responsive-no-min">';
2126 print
'<table class="noborder centpercent">';
2128 $objectsrc->printOriginLinesList(
'', $selectedLines);
2139 if ($object->id > 0) {
2140 $product_static =
new Product($db);
2143 $soc->fetch($object->socid);
2145 $author =
new User($db);
2146 $author->fetch($object->user_author_id);
2148 $object->fetch_thirdparty();
2149 $res = $object->fetch_optionals();
2152 print
dol_get_fiche_head($head,
'order', $langs->trans(
"CustomerOrder"), -1,
'order');
2157 if ($action ==
'delete') {
2158 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteOrder'), $langs->trans(
'ConfirmDeleteOrder'),
'confirm_delete',
'', 0, 1);
2162 if ($action ==
'validate') {
2164 $ref = substr($object->ref, 1, 4);
2165 if ($ref ==
'PROV' || $ref ==
'') {
2166 $numref = $object->getNextNumRef($soc);
2167 if (empty($numref)) {
2172 $numref = $object->ref;
2175 $text = $langs->trans(
'ConfirmValidateOrder', $numref);
2176 if (isModEnabled(
'notification')) {
2177 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
2178 $notify =
new Notify($db);
2180 $text .= $notify->confirmMessage(
'ORDER_VALIDATE', $object->socid, $object);
2183 $qualified_for_stock_change = 0;
2185 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2187 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2190 $formquestion = array();
2191 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2192 $langs->load(
"stocks");
2193 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2196 if ($conf->browser->name ==
'ie') {
2199 $formquestion = array(
2203 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))
2209 foreach ($object->lines as $line) {
2210 $res = $line->fetch_product();
2212 if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end))) {
2218 if ($nbMandated > 0) {
2219 $text .=
'<div><span class="clearboth nowraponall warning">'.$langs->trans(
"mandatoryPeriodNeedTobeSetMsgValidate").
'</span></div>';
2222 if (
getDolGlobalInt(
'SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
2227 $deposit_percent_from_payment_terms =
getDictionaryValue(
'c_payment_term',
'deposit_percent', $object->cond_reglement_id);
2229 if (!empty($deposit_percent_from_payment_terms) && isModEnabled(
'facture') && $user->hasRight(
'facture',
'creer')) {
2230 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2232 $object->fetchObjectLinked();
2234 $eligibleForDepositGeneration =
true;
2236 if (array_key_exists(
'facture', $object->linkedObjects)) {
2237 foreach ($object->linkedObjects[
'facture'] as $invoice) {
2239 $eligibleForDepositGeneration =
false;
2245 if ($eligibleForDepositGeneration && array_key_exists(
'propal', $object->linkedObjects)) {
2246 foreach ($object->linkedObjects[
'propal'] as $proposal) {
2247 $proposal->fetchObjectLinked();
2249 if (array_key_exists(
'facture', $proposal->linkedObjects)) {
2250 foreach ($proposal->linkedObjects[
'facture'] as $invoice) {
2252 $eligibleForDepositGeneration =
false;
2260 if ($eligibleForDepositGeneration) {
2261 $formquestion[] = array(
2262 'type' =>
'checkbox',
2264 'name' =>
'generate_deposit',
2265 'label' => $form->textwithpicto($langs->trans(
'GenerateDeposit', $object->deposit_percent), $langs->trans(
'DepositGenerationPermittedByThePaymentTermsSelected'))
2268 $formquestion[] = array(
2270 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2272 'label' => $langs->trans(
'DateInvoice'),
2278 $formquestion[] = array(
2280 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2281 'name' =>
'date_pointoftax',
2282 'label' => $langs->trans(
'DatePointOfTax'),
2289 $paymentTermsSelect = $form->getSelectConditionsPaiements(0,
'cond_reglement_id', -1, 0, 0,
'minwidth200');
2291 $formquestion[] = array(
2293 'tdclass' =>
'fieldrequired showonlyifgeneratedeposit',
2294 'name' =>
'cond_reglement_id',
2295 'label' => $langs->trans(
'PaymentTerm'),
2296 'value' => $paymentTermsSelect
2299 $formquestion[] = array(
2300 'type' =>
'checkbox',
2301 'tdclass' =>
'showonlyifgeneratedeposit',
2302 'name' =>
'validate_generated_deposit',
2303 'label' => $langs->trans(
'ValidateGeneratedDeposit')
2306 $formquestion[] = array(
2307 'type' =>
'onecolumn',
2310 $(document).ready(function() {
2311 $("[name=generate_deposit]").change(function () {
2312 let $self = $(this);
2313 let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
2315 if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
2332 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ValidateOrder'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
2337 if ($action ==
'modif') {
2338 $qualified_for_stock_change = 0;
2340 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2342 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2345 $text = $langs->trans(
'ConfirmUnvalidateOrder', $object->ref);
2346 $formquestion = array();
2347 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2348 $langs->load(
"stocks");
2349 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2352 if ($conf->browser->name ==
'ie') {
2355 $formquestion = array(
2359 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2363 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'UnvalidateOrder'), $text,
'confirm_modif', $formquestion,
"yes", 1, 220);
2369 if ($action ==
'shipped') {
2370 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'CloseOrder'), $langs->trans(
'ConfirmCloseOrder'),
'confirm_shipped',
'', 0, 1);
2376 if ($action ==
'cancel') {
2377 $qualified_for_stock_change = 0;
2379 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2381 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2384 $text = $langs->trans(
'ConfirmCancelOrder', $object->ref);
2385 $formquestion = array();
2386 if (isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') && $qualified_for_stock_change) {
2387 $langs->load(
"stocks");
2388 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2391 if ($conf->browser->name ==
'ie') {
2394 $formquestion = array(
2398 array(
'type' =>
'other',
'name' =>
'idwarehouse',
'label' => $langs->trans(
"SelectWarehouseForStockIncrease"),
'value' => $formproduct->selectWarehouses(
GETPOST(
'idwarehouse') ?
GETPOST(
'idwarehouse') :
'ifone',
'idwarehouse',
'', 1, 0, 0,
'', 0, $forcecombo))
2402 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"Cancel"), $text,
'confirm_cancel', $formquestion, 0, 1);
2406 if ($action ==
'ask_deleteline') {
2407 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteProductLine'), $langs->trans(
'ConfirmDeleteProductLine'),
'confirm_deleteline',
'', 0, 1);
2411 if ($action ==
'clone') {
2412 $filter =
'(s.client:IN:1,2,3)';
2414 $formquestion = array(
2415 array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOST(
'socid',
'int'),
'socid', $filter,
'', 0, 0,
null, 0,
'maxwidth300'))
2417 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneOrder', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
2421 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
2423 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
2424 if (empty($reshook)) {
2425 $formconfirm .= $hookmanager->resPrint;
2426 } elseif ($reshook > 0) {
2427 $formconfirm = $hookmanager->resPrint;
2436 $linkback =
'<a href="'.DOL_URL_ROOT.
'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
2438 $morehtmlref =
'<div class="refidno">';
2440 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string',
'', 0, 1);
2441 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_client', $object->ref_client, $object, $usercancreate,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1);
2443 $morehtmlref .=
'<br>'.$soc->getNomUrl(1,
'customer');
2445 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
2448 if (isModEnabled(
'project')) {
2449 $langs->load(
"projects");
2450 $morehtmlref .=
'<br>';
2451 if ($usercancreate) {
2452 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
2453 if ($action !=
'classify') {
2454 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
2456 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
2458 if (!empty($object->fk_project)) {
2460 $proj->fetch($object->fk_project);
2461 $morehtmlref .= $proj->getNomUrl(1);
2463 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
2468 $morehtmlref .=
'</div>';
2471 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
2474 $parameters = array();
2476 $reshook = $hookmanager->executeHooks(
'tabContentViewOrder', $parameters, $object, $action);
2477 if (empty($reshook)) {
2478 print
'<div class="fichecenter">';
2479 print
'<div class="fichehalfleft">';
2480 print
'<div class="underbanner clearboth"></div>';
2482 print
'<table class="border tableforfield centpercent">';
2484 if ($soc->outstanding_limit) {
2486 print
'<tr><td class="titlefield">';
2487 print $langs->trans(
'OutstandingBill');
2488 print
'</td><td class="valuefield">';
2489 $arrayoutstandingbills = $soc->getOutstandingBills();
2490 print
price($arrayoutstandingbills[
'opened']).
' / ';
2491 print
price($soc->outstanding_limit, 0,
'', 1, - 1, - 1, $conf->currency);
2498 $filterabsolutediscount =
"fk_facture_source IS NULL";
2499 $filtercreditnote =
"fk_facture_source IS NOT NULL";
2501 $filterabsolutediscount =
"fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
2502 $filtercreditnote =
"fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
2505 $addrelativediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remise.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditRelativeDiscounts").
'</a>';
2506 $addabsolutediscount =
'<a href="'.DOL_URL_ROOT.
'/comm/remx.php?id='.$soc->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'?facid='.$object->id.
'">'.$langs->trans(
"EditGlobalDiscounts").
'</a>';
2507 $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>';
2509 print
'<tr><td class="titlefield">'.$langs->trans(
'Discounts').
'</td><td class="valuefield">';
2511 $absolute_discount = $soc->getAvailableDiscounts(
'', $filterabsolutediscount);
2512 $absolute_creditnote = $soc->getAvailableDiscounts(
'', $filtercreditnote);
2513 $absolute_discount =
price2num($absolute_discount,
'MT');
2514 $absolute_creditnote =
price2num($absolute_creditnote,
'MT');
2518 $backtopage = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
2519 include DOL_DOCUMENT_ROOT.
'/core/tpl/object_discounts.tpl.php';
2526 print $form->editfieldkey(
"Date",
'date',
'', $object, $editenable);
2527 print
'</td><td class="valuefield">';
2528 if ($action ==
'editdate') {
2529 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2530 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2531 print
'<input type="hidden" name="action" value="setdate">';
2532 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2533 print $form->selectDate($object->date,
'order_',
'',
'',
'',
"setdate");
2534 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2537 print $object->date ?
dol_print_date($object->date,
'day') :
' ';
2538 if ($object->hasDelay() && empty($object->delivery_date)) {
2539 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2547 $editenable = $usercancreate;
2548 print $form->editfieldkey(
"DateDeliveryPlanned",
'date_livraison',
'', $object, $editenable);
2549 print
'</td><td class="valuefield">';
2550 if ($action ==
'editdate_livraison') {
2551 print
'<form name="setdate_livraison" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
2552 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2553 print
'<input type="hidden" name="action" value="setdate_livraison">';
2554 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2555 print $form->selectDate($object->delivery_date ? $object->delivery_date : -1,
'liv_', 1, 1,
'',
"setdate_livraison", 1, 0);
2556 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
2559 print $object->delivery_date ?
dol_print_date($object->delivery_date,
'dayhour') :
' ';
2560 if ($object->hasDelay() && !empty($object->delivery_date)) {
2561 print
' '.img_picto($langs->trans(
"Late").
' : '.$object->showDelay(),
"warning");
2568 print
'<tr class="fielddeliverydelay"><td>';
2569 $editenable = $usercancreate;
2570 print $form->editfieldkey(
"AvailabilityPeriod",
'availability',
'', $object, $editenable);
2571 print
'</td><td class="valuefield">';
2572 if ($action ==
'editavailability') {
2573 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'availability_id', 1);
2575 $form->form_availability($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->availability_id,
'none', 1);
2580 if (isModEnabled(
'expedition')) {
2582 $editenable = $usercancreate;
2583 print $form->editfieldkey(
"SendingMethod",
'shippingmethod',
'', $object, $editenable);
2584 print
'</td><td class="valuefield">';
2585 if ($action ==
'editshippingmethod') {
2586 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'shipping_method_id', 1);
2588 $form->formSelectShippingMethod($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->shipping_method_id,
'none');
2595 if (isModEnabled(
'stock') &&
getDolGlobalString(
'WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
2596 $langs->load(
'stocks');
2597 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
2600 $editenable = $usercancreate;
2601 print $form->editfieldkey(
"Warehouse",
'warehouse',
'', $object, $editenable);
2602 print
'</td><td class="valuefield">';
2603 if ($action ==
'editwarehouse') {
2604 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'warehouse_id', 1);
2606 $formproduct->formSelectWarehouses($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->warehouse_id,
'none');
2614 $editenable = $usercancreate;
2615 print $form->editfieldkey(
"Source",
'demandreason',
'', $object, $editenable);
2616 print
'</td><td class="valuefield">';
2617 if ($action ==
'editdemandreason') {
2618 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'demand_reason_id', 1);
2620 $form->formInputReason($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->demand_reason_id,
'none');
2626 $editenable = $usercancreate;
2627 print $form->editfieldkey(
"PaymentConditionsShort",
'conditions',
'', $object, $editenable);
2628 print
'</td><td class="valuefield">';
2629 if ($action ==
'editconditions') {
2630 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'cond_reglement_id', 1,
'', 1, $object->deposit_percent);
2632 $form->form_conditions_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->cond_reglement_id,
'none', 1,
'', 1, $object->deposit_percent);
2640 $editenable = $usercancreate;
2641 print $form->editfieldkey(
"PaymentMode",
'mode',
'', $object, $editenable);
2642 print
'</td><td class="valuefield">';
2643 if ($action ==
'editmode') {
2644 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'mode_reglement_id',
'CRDT', 1, 1);
2646 $form->form_modes_reglement($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->mode_reglement_id,
'none');
2651 if (isModEnabled(
"multicurrency")) {
2656 print $form->editfieldkey(
"Currency",
'multicurrencycode',
'', $object, $editenable);
2657 print
'</td><td class="valuefield">';
2658 if ($action ==
'editmulticurrencycode') {
2659 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'multicurrency_code');
2661 $form->form_multicurrency_code($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_code,
'none');
2666 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
2669 $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == $object::STATUS_DRAFT;
2670 print $form->editfieldkey(
"CurrencyRate",
'multicurrencyrate',
'', $object, $editenable);
2671 print
'</td><td class="valuefield">';
2672 if ($action ==
'editmulticurrencyrate' || $action ==
'actualizemulticurrencyrate') {
2673 if ($action ==
'actualizemulticurrencyrate') {
2676 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'multicurrency_tx', $object->multicurrency_code);
2678 $form->form_multicurrency_rate($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->multicurrency_tx,
'none', $object->multicurrency_code);
2679 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2680 print
'<div class="inline-block"> ';
2681 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=actualizemulticurrencyrate">'.$langs->trans(
"ActualizeCurrency").
'</a>';
2703 $tmparray = $object->getTotalWeightVolume();
2704 $totalWeight = $tmparray[
'weight'];
2705 $totalVolume = $tmparray[
'volume'];
2707 print
'<tr><td>'.$langs->trans(
"CalculatedWeight").
'</td>';
2708 print
'<td class="valuefield">';
2709 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');
2713 print
'<tr><td>'.$langs->trans(
"CalculatedVolume").
'</td>';
2714 print
'<td class="valuefield">';
2715 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');
2722 if (isModEnabled(
'incoterm')) {
2724 $editenable = $usercancreate;
2725 print $form->editfieldkey(
"IncotermLabel",
'incoterm',
'', $object, $editenable);
2727 print
'<td class="valuefield">';
2728 if ($action !=
'editincoterm') {
2729 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2731 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
2737 if (
getDolGlobalString(
'BANK_ASK_PAYMENT_BANK_DURING_ORDER') && isModEnabled(
"banque")) {
2739 $editenable = $usercancreate;
2740 print $form->editfieldkey(
"BankAccount",
'bankaccount',
'', $object, $editenable);
2741 print
'</td><td class="valuefield">';
2742 if ($action ==
'editbankaccount') {
2743 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'fk_account', 1);
2745 $form->formSelectAccount($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->fk_account,
'none');
2752 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
2757 print
'<div class="fichehalfright">';
2758 print
'<div class="underbanner clearboth"></div>';
2760 print
'<table class="border tableforfield centpercent">';
2763 if (
getDolGlobalString(
'ORDER_MANAGE_MIN_AMOUNT') && $object->total_ht < $object->thirdparty->order_min_amount) {
2764 $alert =
' ' .
img_warning($langs->trans(
'OrderMinAmount') .
': ' .
price($object->thirdparty->order_min_amount));
2768 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountHT') .
'</td>';
2769 print
'<td class="nowrap amountcard right">' .
price($object->total_ht,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
2770 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2772 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_ht,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
2777 print
'<td class="titlefieldmiddle">' . $langs->trans(
'AmountVAT') .
'</td>';
2778 print
'<td class="nowrap amountcard right">' .
price($object->total_tva,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
2779 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2781 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_tva,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
2786 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
2788 print
'<td class="titlefieldmiddle">' . $langs->transcountry(
"AmountLT1", $mysoc->country_code) .
'</td>';
2789 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax1,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
2790 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2791 $object->multicurrency_total_localtax1 =
price2num($object->total_localtax1 * $object->multicurrency_tx,
'MT');
2793 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_localtax1,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
2799 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
2801 print
'<td>' . $langs->transcountry(
"AmountLT2", $mysoc->country_code) .
'</td>';
2802 print
'<td class="nowrap amountcard right">' .
price($object->total_localtax2,
'', $langs, 0, -1, -1, $conf->currency) .
'</td>';
2803 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2804 $object->multicurrency_total_localtax2 =
price2num($object->total_localtax2 * $object->multicurrency_tx,
'MT');
2806 print
'<td class="nowrap amountcard right">' .
price($object->multicurrency_total_localtax2,
'', $langs, 0, -1, -1, $object->multicurrency_code) .
'</td>';
2812 print
'<td>' . $langs->trans(
'AmountTTC') .
'</td>';
2813 print
'<td class="valuefield nowrap right amountcard">' .
price($object->total_ttc, 1,
'', 1, -1, -1, $conf->currency) .
'</td>';
2814 if (isModEnabled(
"multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2816 print
'<td class="valuefield nowrap right amountcard">' .
price($object->multicurrency_total_ttc, 1,
'', 1, -1, -1, $object->multicurrency_code) .
'</td>';
2826 if (isModEnabled(
'margin')) {
2827 $formmargin->displayMarginInfos($object);
2834 print
'<div class="clearboth"></div><br>';
2837 $blocname =
'contacts';
2838 $title = $langs->trans(
'ContactsAddresses');
2839 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2843 $blocname =
'notes';
2844 $title = $langs->trans(
'Notes');
2845 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
2853 $result = $object->getLinesArray();
2857 global $inputalsopricewithtax;
2858 $inputalsopricewithtax = 1;
2860 print
'<form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">
2861 <input type="hidden" name="token" value="' . newToken().
'">
2862 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
2863 <input type="hidden" name="mode" value="">
2864 <input type="hidden" name="page_y" value="">
2865 <input type="hidden" name="id" value="' . $object->id.
'">
2866 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2870 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
2873 print
'<div class="div-table-responsive-no-min">';
2874 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2877 if (!empty($object->lines)) {
2878 $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
2885 if ($action !=
'editline') {
2888 $parameters = array();
2890 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2894 if (empty($reshook)) {
2895 $object->formAddObjectLine(1, $mysoc, $soc);
2898 $parameters = array();
2899 $reshook = $hookmanager->executeHooks(
'formEditObjectLine', $parameters, $object, $action);
2913 if ($action !=
'presend' && $action !=
'editline') {
2914 print
'<div class="tabsAction">';
2916 $parameters = array();
2918 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2919 if (empty($reshook)) {
2920 $numlines = count($object->lines);
2924 print
dolGetButtonAction(
'', $langs->trans(
'ReOpen'),
'default', $_SERVER[
"PHP_SELF"].
'?action=reopen&token='.newToken().
'&id='.$object->id,
'');
2928 if (empty($user->socid)) {
2931 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
"PHP_SELF"].
'?action=presend&token='.newToken().
'&id='.$object->id.
'&mode=init#formmailbeforetitle',
'');
2933 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
2940 if ($numlines > 0) {
2941 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.newToken().
'&id='.$object->id, $object->id, 1);
2943 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $object->ref), $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=validate&token='.newToken().
'&id='.$object->id, $object->id, 0);
2948 print
dolGetButtonAction(
'', $langs->trans(
'Modify'),
'default', $_SERVER[
"PHP_SELF"].
'?action=modif&token='.newToken().
'&id='.$object->id,
'');
2951 $arrayforbutaction = array();
2954 $arrayforbutaction[] = array(
'lang'=>
'orders',
'enabled'=>(isModEnabled(
"supplier_order") && $object->statut >
Commande::STATUS_DRAFT ),
'perm'=>$usercancreatepurchaseorder,
'label'=>
'AddPurchaseOrder',
'url'=>
'/fourn/commande/card.php?action=create&origin='.$object->element.
'&originid='.$object->id);
2963 $arrayforbutaction[] = array(
'lang'=>
'interventions',
'enabled'=>(isModEnabled(
"ficheinter") && $object->statut >
Commande::STATUS_DRAFT && $object->statut <
Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0),
'perm'=>$user->hasRight(
'ficheinter',
'creer'),
'label'=>
'AddIntervention',
'url'=>
'/fichinter/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid);
2977 $arrayforbutaction[] = array(
'lang'=>
'contracts',
'enabled'=>(isModEnabled(
"contrat") && ($object->statut ==
Commande::STATUS_VALIDATED || $object->statut ==
Commande::STATUS_SHIPMENTONPROCESS || $object->statut ==
Commande::STATUS_CLOSED)),
'perm'=>$user->hasRight(
'contrat',
'creer'),
'label'=>
'AddContract',
'url'=>
'/contrat/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->socid);
2987 if (isModEnabled(
'expedition')) {
2988 $numshipping = $object->countNbOfShipments();
2993 if ((
getDolGlobalInt(
'MAIN_SUBMODULE_EXPEDITION') && $user->hasRight(
'expedition',
'creer')) || (
getDolGlobalInt(
'MAIN_SUBMODULE_DELIVERY') && $user->hasRight(
'expedition',
'delivery',
'creer'))) {
2994 $arrayforbutaction[] = array(
'lang'=>
'sendings',
'enabled'=>(isModEnabled(
"expedition") && ($object->statut >
Commande::STATUS_DRAFT && $object->statut <
Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES')))),
'perm'=>$user->hasRight(
'expedition',
'creer'),
'label'=>
'CreateShipment',
'url'=>
'/expedition/shipment.php?id='.$object->id);
3002 $langs->load(
"errors");
3003 print
dolGetButtonAction($langs->trans(
'ErrorModuleSetupNotComplete'), $langs->trans(
'CreateShipment'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3008 $arrayforbutaction[] = array(
3010 'enabled'=>(isModEnabled(
'facture') && $object->statut >
Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0),
3011 'perm'=>($user->hasRight(
'facture',
'creer') && !
getDolGlobalInt(
'WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')),
3012 'label'=>
'CreateBill',
3013 'url'=>
'/compta/facture/card.php?action=create&token='.newToken().
'&origin='.urlencode($object->element).
'&originid='.$object->id.
'&socid='.$object->socid
3022 if ($numlines > 0) {
3023 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayforbutaction, $object->id, 1);
3025 print
dolGetButtonAction($langs->trans(
"ErrorObjectMustHaveLinesToBeValidated", $object->ref), $langs->trans(
"Create"),
'default', $arrayforbutaction, $object->id, 0);
3030 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyShipped'),
'default', $_SERVER[
"PHP_SELF"].
'?action=shipped&token='.newToken().
'&id='.$object->id,
'');
3037 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyBilled'),
'default', $_SERVER[
"PHP_SELF"].
'?action=classifybilled&token='.newToken().
'&id='.$object->id,
'');
3042 print
dolGetButtonAction(
'', $langs->trans(
'ClassifyUnBilled'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=classifyunbilled&token='.newToken().
'&id='.$object->id,
'');
3047 if ($usercancreate) {
3048 print
dolGetButtonAction(
'', $langs->trans(
'ToClone'),
'default', $_SERVER[
"PHP_SELF"].
'?action=clone&token='.newToken().
'&id='.$object->id.
'&socid='.$object->socid,
'');
3053 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.newToken().
'">'.$langs->trans(
"CancelOrder").
'</a>';
3057 if ($usercandelete) {
3058 if ($numshipping == 0) {
3059 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&id='.$object->id,
'');
3061 print
dolGetButtonAction($langs->trans(
'ShippingExist'), $langs->trans(
'Delete'),
'default', $_SERVER[
'PHP_SELF'].
'#',
'',
false);
3069 if (
GETPOST(
'modelselected')) {
3070 $action =
'presend';
3073 if ($action !=
'presend') {
3074 print
'<div class="fichecenter"><div class="fichehalfleft">';
3075 print
'<a name="builddoc"></a>';
3078 $relativepath = $objref.
'/'.$objref.
'.pdf';
3079 $filedir = $conf->commande->multidir_output[$object->entity].
'/'.$objref;
3080 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
3081 $genallowed = $usercanread;
3082 $delallowed = $usercancreate;
3083 print $formfile->showdocuments(
'commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang,
'', $object);
3087 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'order'));
3089 $compatibleImportElementsList =
false;
3092 $compatibleImportElementsList = array(
'commande',
'propal',
'facture');
3094 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
3097 $useonlinepayment = (isModEnabled(
'paypal') || isModEnabled(
'stripe') || isModEnabled(
'paybox'));
3099 $useonlinepayment = 0;
3102 print
'<br><!-- Link to pay -->';
3103 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
3104 print showOnlinePaymentUrl(
'order', $object->ref).
'<br>';
3107 print
'</div><div class="fichehalfright">';
3111 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/commande/agenda.php?id='.$object->id);
3114 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3116 $somethingshown =
$formactions->showactions($object,
'order', $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
3118 print
'</div></div>';
3122 $modelmail =
'order_send';
3123 $defaulttopic =
'SendOrderRef';
3125 $trackid =
'ord'.$object->id;
3127 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
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.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message 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).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a 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)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages 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.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) getMultidirOutput($object, $module='')
Return the full path of the directory where a module (or an object of a module) stores its files.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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.
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.