dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2016 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
8  * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
10  * Copyright (C) 2014 Ion Agorria <ion@agorria.com>
11  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  * or see https://www.gnu.org/
26  */
27 
34 require '../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
38 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
44 if (!empty($conf->supplier_proposal->enabled))
45  require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
46 if (!empty($conf->product->enabled))
47  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
48 if (!empty($conf->projet->enabled)) {
49  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
50  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
51 }
52 require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
53 
54 if (!empty($conf->variants->enabled)) {
55  require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
56 }
57 
58 $langs->loadLangs(array('admin', 'orders', 'sendings', 'companies', 'bills', 'propal', 'receptions', 'supplier_proposal', 'deliveries', 'products', 'stocks', 'productbatch'));
59 if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
60 
61 $id = GETPOST('id', 'int');
62 $ref = GETPOST('ref', 'alpha');
63 $action = GETPOST('action', 'alpha');
64 $confirm = GETPOST('confirm', 'alpha');
65 $socid = GETPOST('socid', 'int');
66 $projectid = GETPOST('projectid', 'int');
67 $cancel = GETPOST('cancel', 'alpha');
68 $lineid = GETPOST('lineid', 'int');
69 
70 $lineid = GETPOST('lineid', 'int');
71 $origin = GETPOST('origin', 'alpha');
72 $originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
73 
74 //PDF
75 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
76 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
77 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
78 
79 $datelivraison = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), GETPOST('liv_sec', 'int'), GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
80 
81 
82 // Security check
83 if ($user->socid) $socid = $user->socid;
84 $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
85 
86 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87 $hookmanager->initHooks(array('ordersuppliercard', 'globalcard'));
88 
89 $object = new CommandeFournisseur($db);
90 $extrafields = new ExtraFields($db);
91 
92 // fetch optionals attributes and labels
93 $extrafields->fetch_name_optionals_label($object->table_element);
94 
95 // Load object
96 if ($id > 0 || !empty($ref))
97 {
98  $ret = $object->fetch($id, $ref);
99  if ($ret < 0) dol_print_error($db, $object->error);
100  $ret = $object->fetch_thirdparty();
101  if ($ret < 0) dol_print_error($db, $object->error);
102 } elseif (!empty($socid) && $socid > 0)
103 {
104  $fourn = new Fournisseur($db);
105  $ret = $fourn->fetch($socid);
106  if ($ret < 0) dol_print_error($db, $object->error);
107  $object->socid = $fourn->id;
108  $ret = $object->fetch_thirdparty();
109  if ($ret < 0) dol_print_error($db, $object->error);
110 }
111 
112 // Common permissions
113 $usercanread = $user->rights->fournisseur->commande->lire;
114 $usercancreate = $user->rights->fournisseur->commande->creer;
115 $usercandelete = $user->rights->fournisseur->commande->supprimer;
116 
117 // Advanced permissions
118 $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate)));
119 
120 // Additional area permissions
121 $usercanapprove = $user->rights->fournisseur->commande->approuver;
122 $usercanapprovesecond = $user->rights->fournisseur->commande->approve2;
123 $usercanorder = $user->rights->fournisseur->commande->commander;
124 $usercanreceived = $user->rights->fournisseur->commande->receptionner;
125 
126 // Permissions for includes
127 $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
128 $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
129 $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
130 $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
131 
132 
133 /*
134  * Actions
135  */
136 
137 $parameters = array('socid'=>$socid);
138 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
139 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140 
141 if (empty($reshook))
142 {
143  if ($cancel)
144  {
145  if (!empty($backtopage))
146  {
147  header("Location: ".$backtopage);
148  exit;
149  }
150  $action = '';
151  }
152 
153  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
154 
155  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
156 
157  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
158 
159  if ($action == 'setref_supplier' && $usercancreate)
160  {
161  $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'ORDER_SUPPLIER_MODIFY');
162  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
163  }
164 
165  // Set incoterm
166  if ($action == 'set_incoterms' && $usercancreate)
167  {
168  $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
169  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
170  }
171 
172  // payment conditions
173  if ($action == 'setconditions' && $usercancreate)
174  {
175  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
176  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
177  }
178 
179  // payment mode
180  if ($action == 'setmode' && $usercancreate)
181  {
182  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
183  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
184  }
185 
186  // Multicurrency Code
187  elseif ($action == 'setmulticurrencycode' && $usercancreate) {
188  $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
189  }
190 
191  // Multicurrency rate
192  elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
193  $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
194  }
195 
196  // bank account
197  if ($action == 'setbankaccount' && $usercancreate)
198  {
199  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
200  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
201  }
202 
203  // date of delivery
204  if ($action == 'setdate_livraison' && $usercancreate)
205  {
206  $result = $object->setDeliveryDate($user, $datelivraison);
207  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
208  }
209 
210  // Set project
211  if ($action == 'classin' && $usercancreate)
212  {
213  $result = $object->setProject($projectid);
214  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
215  }
216 
217  // Edit Thirdparty
218  if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action == 'set_thirdparty' && $usercancreate && $object->statut == CommandeFournisseur::STATUS_DRAFT)
219  {
220  $new_socid = GETPOST('new_socid', 'int');
221  if (!empty($new_socid) && $new_socid != $object->thirdparty->id) {
222  $db->begin();
223 
224  // Update supplier
225  $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur';
226  $sql .= ' SET fk_soc='.$new_socid;
227  $sql .= ' WHERE fk_soc='.$object->thirdparty->id;
228  $sql .= ' AND rowid='.$object->id;
229 
230  $res = $db->query($sql);
231 
232  if (!$res) $db->rollback();
233  else {
234  $db->commit();
235 
236  // Replace prices for each lines by new supplier prices
237  foreach ($object->lines as $l) {
238  $sql = 'SELECT price, unitprice, tva_tx, ref_fourn';
239  $sql .= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
240  $sql .= ' WHERE fk_product='.$l->fk_product;
241  $sql .= ' AND fk_soc='.$new_socid;
242  $sql .= ' ORDER BY unitprice ASC';
243 
244  $resql = $db->query($sql);
245  if ($resql) {
246  $num_row = $db->num_rows($resql);
247  if (empty($num_row)) {
248  // No product price for this supplier !
249  $l->subprice = 0;
250  $l->total_ht = 0;
251  $l->total_tva = 0;
252  $l->total_ttc = 0;
253  $l->ref_supplier = '';
254  $l->update();
255  } else {
256  // No need for loop to keep best supplier price
257  $obj = $db->fetch_object($resql);
258  $l->subprice = $obj->unitprice;
259  $l->total_ht = $obj->price;
260  $l->tva_tx = $obj->tva_tx;
261  $l->total_tva = $l->total_ht * ($obj->tva_tx / 100);
262  $l->total_ttc = $l->total_ht + $l->total_tva;
263  $l->ref_supplier = $obj->ref_fourn;
264  $l->update();
265  }
266  } else {
267  dol_print_error($db);
268  }
269  $db->free($resql);
270  }
271  $object->update_price();
272  }
273  }
274  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
275  exit;
276  }
277 
278  if ($action == 'setremisepercent' && $usercancreate)
279  {
280  $result = $object->set_remise($user, $_POST['remise_percent']);
281  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
282  }
283 
284  if ($action == 'reopen') // no test on permission here, permission to use will depends on status
285  {
286  if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9)))
287  {
288  if ($object->statut == 1) $newstatus = 0; // Validated->Draft
289  elseif ($object->statut == 2) $newstatus = 0; // Approved->Draft
290  elseif ($object->statut == 3) $newstatus = 2; // Ordered->Approved
291  elseif ($object->statut == 4) $newstatus = 3;
292  elseif ($object->statut == 5)
293  {
294  //$newstatus=2; // Ordered
295  // TODO Can we set it to submited ?
296  //$newstatus=3; // Submited
297  // TODO If there is at least one reception, we can set to Received->Received partially
298  $newstatus = 4; // Received partially
299  } elseif ($object->statut == 6) $newstatus = 2; // Canceled->Approved
300  elseif ($object->statut == 7) $newstatus = 3; // Canceled->Process running
301  elseif ($object->statut == 9) $newstatus = 1; // Refused->Validated
302  else $newstatus = 2;
303 
304  //print "old status = ".$object->statut.' new status = '.$newstatus;
305  $db->begin();
306 
307  $result = $object->setStatus($user, $newstatus);
308  if ($result > 0)
309  {
310  // Currently the "Re-open" also remove the billed flag because there is no button "Set unpaid" yet.
311  $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur';
312  $sql .= ' SET billed = 0';
313  $sql .= ' WHERE rowid = '.$object->id;
314 
315  $resql = $db->query($sql);
316 
317  if ($newstatus == 0)
318  {
319  $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur';
320  $sql .= ' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
321  $sql .= ' WHERE rowid = '.$object->id;
322 
323  $resql = $db->query($sql);
324  }
325 
326  $db->commit();
327 
328  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
329  exit;
330  } else {
331  $db->rollback();
332 
333  setEventMessages($object->error, $object->errors, 'errors');
334  }
335  }
336  }
337 
338  /*
339  * Classify supplier order as billed
340  */
341  if ($action == 'classifybilled' && $usercancreate)
342  {
343  $ret = $object->classifyBilled($user);
344  if ($ret < 0) {
345  setEventMessages($object->error, $object->errors, 'errors');
346  }
347  }
348 
349  // Add a product line
350  if ($action == 'addline' && $usercancreate)
351  {
352  $db->begin();
353 
354  $langs->load('errors');
355  $error = 0;
356 
357  // Set if we used free entry or predefined product
358  $predef = '';
359  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
360  $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
361  $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
362  $prod_entry_mode = GETPOST('prod_entry_mode');
363  if ($prod_entry_mode == 'free')
364  {
365  $idprod = 0;
366  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
367  $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
368  } else {
369  $idprod = GETPOST('idprod', 'int');
370  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
371  $tva_tx = '';
372  }
373 
374  $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
375  $remise_percent = GETPOST('remise_percent'.$predef);
376  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
377 
378  // Extrafields
379  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
380  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
381  // Unset extrafield
382  if (is_array($extralabelsline)) {
383  // Get extra fields
384  foreach ($extralabelsline as $key => $value) {
385  unset($_POST["options_".$key]);
386  }
387  }
388 
389  if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0)
390  {
391  setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
392  $error++;
393  }
394  if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0)
395  {
396  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
397  $error++;
398  }
399  if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') // Unit price can be 0 but not ''
400  {
401  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice')), null, 'errors');
402  $error++;
403  }
404  if ($prod_entry_mode == 'free' && !GETPOST('dp_desc'))
405  {
406  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
407  $error++;
408  }
409  if (GETPOST('qty', 'int') == '')
410  {
411  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
412  $error++;
413  }
414 
415  if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode != 'free') {
416  if ($combinations = GETPOST('combinations', 'array')) {
417  //Check if there is a product with the given combination
418  $prodcomb = new ProductCombination($db);
419 
420  if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
421  $idprod = $res->fk_product_child;
422  } else {
423  setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
424  $error++;
425  }
426  }
427  }
428 
429  if ($prod_entry_mode != 'free' && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
430  {
431  $productsupplier = new ProductFournisseur($db);
432 
433  $idprod = 0;
434  if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
435 
436  $reg = array();
437  if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg))
438  {
439  $idprod = $reg[1];
440  $res = $productsupplier->fetch($idprod); // Load product from its id
441  // Call to init some price properties of $productsupplier
442  // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
443  if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER))
444  {
445  $fksoctosearch = 0;
446  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
447  if ($productsupplier->fourn_socid != $socid) // The price we found is for another supplier, so we clear supplier price
448  {
449  $productsupplier->ref_supplier = '';
450  }
451  } else {
452  $fksoctosearch = $object->thirdparty->id;
453  $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
454  }
455  } elseif (GETPOST('idprodfournprice', 'alpha') > 0)
456  {
457  $qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat.
458  //$qtytosearch=-1; // We force qty to -1 to be sure to find if a supplier price exist
459  $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
460  $res = $productsupplier->fetch($idprod);
461  }
462 
463  if ($idprod > 0)
464  {
465  $label = $productsupplier->label;
466  // Define output language
467  if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
468  $outputlangs = $langs;
469  $newlang = '';
470  if (empty($newlang) && GETPOST('lang_id', 'aZ09'))
471  $newlang = GETPOST('lang_id', 'aZ09');
472  if (empty($newlang))
473  $newlang = $object->thirdparty->default_lang;
474  if (!empty($newlang)) {
475  $outputlangs = new Translate("", $conf);
476  $outputlangs->setDefaultLang($newlang);
477  }
478  $desc = (!empty($productsupplier->multilangs [$outputlangs->defaultlang] ["description"])) ? $productsupplier->multilangs [$outputlangs->defaultlang] ["description"] : $productsupplier->description;
479  } else {
480  $desc = $productsupplier->description;
481  }
482  // if we use supplier description of the products
483  if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
484  $desc = $productsupplier->desc_supplier;
485  }
486 
487  if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
488 
489  $type = $productsupplier->type;
490  if ($price_ht != '' || $price_ht_devise != '') {
491  $price_base_type = 'HT';
492  $pu = price2num($price_ht, 'MU');
493  $pu_ht_devise = price2num($price_ht_devise, 'MU');
494  } else {
495  $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
496  if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
497  $pu = $productsupplier->fourn_pu;
498  $pu_ht_devise = 0;
499  } else {
500  $pu = $productsupplier->fourn_pu;
501  $pu_ht_devise = $productsupplier->fourn_multicurrency_unitprice;
502  /*var_dump($pu);
503  var_dump($pu_ht_devise);exit;*/
504  }
505  }
506 
507  $ref_supplier = $productsupplier->ref_supplier;
508 
509  $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
510  $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
511  if (empty($tva_tx)) $tva_npr = 0;
512  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
513  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
514 
515  if (empty($pu)) $pu = 0; // If pu is '' or null, we force to have a numeric value
516 
517  $result = $object->addline(
518  $desc,
519  $pu,
520  $qty,
521  $tva_tx,
522  $localtax1_tx,
523  $localtax2_tx,
524  $idprod,
525  0, // We already have the $idprod always defined
526  $ref_supplier,
527  $remise_percent,
528  $price_base_type,
529  $pu_ttc,
530  $type,
531  $tva_npr,
532  '',
533  $date_start,
534  $date_end,
535  $array_options,
536  $productsupplier->fk_unit,
537  $pu_ht_devise,
538  '',
539  0
540  );
541  }
542  if ($idprod == -99 || $idprod == 0)
543  {
544  // Product not selected
545  $error++;
546  $langs->load("errors");
547  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
548  }
549  if ($idprod == -1)
550  {
551  // Quantity too low
552  $error++;
553  $langs->load("errors");
554  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
555  }
556  } elseif (empty($error)) // $price_ht is already set
557  {
558  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
559  $tva_tx = str_replace('*', '', $tva_tx);
560  $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
561  $desc = $product_desc;
562  $type = GETPOST('type');
563  $ref_supplier = GETPOST('fourn_ref', 'alpha');
564 
565  $fk_unit = GETPOST('units', 'alpha');
566 
567  if (!preg_match('/\((.*)\)/', $tva_tx)) {
568  $tva_tx = price2num($tva_tx); // When vat is text input field
569  }
570 
571  // Local Taxes
572  $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
573  $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
574 
575  if ($price_ht !== '')
576  {
577  $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
578  } else {
579  $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
580  $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
581  }
582  $price_base_type = 'HT';
583  $pu_ht_devise = price2num($price_ht_devise, 'MU');
584 
585  $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, '', '', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
586  }
587 
588  //print "xx".$tva_tx; exit;
589  if (!$error && $result > 0)
590  {
591  $db->commit();
592 
593  $ret = $object->fetch($object->id); // Reload to get new records
594 
595  // Define output language
596  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
597  {
598  $outputlangs = $langs;
599  $newlang = '';
600  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
601  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
602  if (!empty($newlang)) {
603  $outputlangs = new Translate("", $conf);
604  $outputlangs->setDefaultLang($newlang);
605  }
606  $model = $object->model_pdf;
607  $ret = $object->fetch($id); // Reload to get new records
608 
609  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
610  if ($result < 0) dol_print_error($db, $result);
611  }
612 
613  unset($_POST ['prod_entry_mode']);
614 
615  unset($_POST['qty']);
616  unset($_POST['type']);
617  unset($_POST['remise_percent']);
618  unset($_POST['pu']);
619  unset($_POST['price_ht']);
620  unset($_POST['multicurrency_price_ht']);
621  unset($_POST['price_ttc']);
622  unset($_POST['fourn_ref']);
623  unset($_POST['tva_tx']);
624  unset($_POST['label']);
625  unset($localtax1_tx);
626  unset($localtax2_tx);
627  unset($_POST['np_marginRate']);
628  unset($_POST['np_markRate']);
629  unset($_POST['dp_desc']);
630  unset($_POST['idprodfournprice']);
631 
632  unset($_POST['date_starthour']);
633  unset($_POST['date_startmin']);
634  unset($_POST['date_startsec']);
635  unset($_POST['date_startday']);
636  unset($_POST['date_startmonth']);
637  unset($_POST['date_startyear']);
638  unset($_POST['date_endhour']);
639  unset($_POST['date_endmin']);
640  unset($_POST['date_endsec']);
641  unset($_POST['date_endday']);
642  unset($_POST['date_endmonth']);
643  unset($_POST['date_endyear']);
644  } else {
645  $db->rollback();
646  setEventMessages($object->error, $object->errors, 'errors');
647  }
648 
649  $action = '';
650  }
651 
652  /*
653  * Updating a line in the order
654  */
655  if ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha'))
656  {
657  $db->begin();
658 
659  $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
660 
661  if ($lineid)
662  {
663  $line = new CommandeFournisseurLigne($db);
664  $res = $line->fetch($lineid);
665  if (!$res) dol_print_error($db);
666  }
667 
668  $productsupplier = new ProductFournisseur($db);
669  if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
670  if ($line->fk_product > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty', 'int')), $line->fk_product, 'none', GETPOST('socid', 'int')) < 0) {
671  setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
672  }
673  }
674 
675  $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
676  $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
677 
678  // Define info_bits
679  $info_bits = 0;
680  if (preg_match('/\*/', $vat_rate)) {
681  $info_bits |= 0x01;
682  }
683 
684  // Define vat_rate
685  $vat_rate = str_replace('*', '', $vat_rate);
686  $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
687  $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
688 
689  if (GETPOST('price_ht') != '')
690  {
691  $price_base_type = 'HT';
692  $ht = price2num(GETPOST('price_ht'), '', 2);
693  } else {
694  $vatratecleaned = $vat_rate;
695  if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)"
696  {
697  $vatratecleaned = trim($reg[1]);
698  $vatratecode = $reg[2];
699  }
700 
701  $ttc = price2num(GETPOST('price_ttc'), '', 2);
702  $ht = $ttc / (1 + ($vatratecleaned / 100));
703  $price_base_type = 'HT';
704  }
705 
706  $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
707 
708  // Extrafields Lines
709  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
710  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
711  // Unset extrafield POST Data
712  if (is_array($extralabelsline)) {
713  foreach ($extralabelsline as $key => $value) {
714  unset($_POST["options_".$key]);
715  }
716  }
717 
718  $result = $object->updateline(
719  $lineid,
720  $_POST['product_desc'],
721  $ht,
722  GETPOST('qty', 'int'),
723  $_POST['remise_percent'],
724  $vat_rate,
725  $localtax1_rate,
726  $localtax2_rate,
727  $price_base_type,
728  0,
729  isset($_POST["type"]) ? $_POST["type"] : $line->product_type,
730  false,
731  $date_start,
732  $date_end,
733  $array_options,
734  $_POST['units'],
735  $pu_ht_devise,
736  GETPOST('fourn_ref', 'alpha')
737  );
738  unset($_POST['qty']);
739  unset($_POST['type']);
740  unset($_POST['idprodfournprice']);
741  unset($_POST['remmise_percent']);
742  unset($_POST['dp_desc']);
743  unset($_POST['np_desc']);
744  unset($_POST['pu']);
745  unset($_POST['fourn_ref']);
746  unset($_POST['tva_tx']);
747  unset($_POST['date_start']);
748  unset($_POST['date_end']);
749  unset($_POST['units']);
750  unset($localtax1_tx);
751  unset($localtax2_tx);
752 
753  unset($_POST['date_starthour']);
754  unset($_POST['date_startmin']);
755  unset($_POST['date_startsec']);
756  unset($_POST['date_startday']);
757  unset($_POST['date_startmonth']);
758  unset($_POST['date_startyear']);
759  unset($_POST['date_endhour']);
760  unset($_POST['date_endmin']);
761  unset($_POST['date_endsec']);
762  unset($_POST['date_endday']);
763  unset($_POST['date_endmonth']);
764  unset($_POST['date_endyear']);
765 
766  if ($result >= 0)
767  {
768  // Define output language
769  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
770  {
771  $outputlangs = $langs;
772  $newlang = '';
773  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
774  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
775  if (!empty($newlang)) {
776  $outputlangs = new Translate("", $conf);
777  $outputlangs->setDefaultLang($newlang);
778  }
779  $model = $object->model_pdf;
780  $ret = $object->fetch($id); // Reload to get new records
781 
782  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
783  if ($result < 0) dol_print_error($db, $result);
784  }
785 
786  $db->commit();
787  } else {
788  $db->rollback();
789 
790  dol_print_error($db, $object->error);
791  exit;
792  }
793  }
794 
795  // Remove a product line
796  if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate)
797  {
798  $db->begin();
799 
800  $result = $object->deleteline($lineid);
801  if ($result > 0)
802  {
803  // Define output language
804  $outputlangs = $langs;
805  $newlang = '';
806  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09'))
807  $newlang = GETPOST('lang_id', 'aZ09');
808  if ($conf->global->MAIN_MULTILANGS && empty($newlang))
809  $newlang = $object->thirdparty->default_lang;
810  if (!empty($newlang)) {
811  $outputlangs = new Translate("", $conf);
812  $outputlangs->setDefaultLang($newlang);
813  }
814  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
815  $ret = $object->fetch($object->id); // Reload to get new records
816  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
817  }
818  } else {
819  $error++;
820  setEventMessages($object->error, $object->errors, 'errors');
821  // Reset action to avoid asking again confirmation on failure
822  $action = '';
823  }
824 
825  if (!$error) {
826  $db->commit();
827 
828  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
829  exit;
830  } else {
831  $db->rollback();
832  }
833  }
834 
835  // Validate
836  if ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate)
837  {
838  $db->begin();
839 
840  $object->date_commande = dol_now();
841  $result = $object->valid($user);
842  if ($result >= 0)
843  {
844  // Define output language
845  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
846  {
847  $outputlangs = $langs;
848  $newlang = '';
849  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
850  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
851  if (!empty($newlang)) {
852  $outputlangs = new Translate("", $conf);
853  $outputlangs->setDefaultLang($newlang);
854  }
855  $model = $object->model_pdf;
856  $ret = $object->fetch($id); // Reload to get new records
857 
858  $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
859  if ($result < 0) {
860  $error++;
861  dol_print_error($db, $result);
862  }
863  }
864  } else {
865  $error++;
866  setEventMessages($object->error, $object->errors, 'errors');
867  }
868 
869  // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
870  if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
871  {
872  $action = 'confirm_approve'; // can make standard or first level approval also if permission is set
873  }
874 
875  if (!$error) {
876  $db->commit();
877  } else {
878  $db->rollback();
879  }
880  }
881 
882  if (($action == 'confirm_approve' || $action == 'confirm_approve2') && $confirm == 'yes' && $usercanapprove)
883  {
884  $db->begin();
885 
886  $idwarehouse = GETPOST('idwarehouse', 'int');
887 
888  $qualified_for_stock_change = 0;
889  if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
890  {
891  $qualified_for_stock_change = $object->hasProductsOrServices(2);
892  } else {
893  $qualified_for_stock_change = $object->hasProductsOrServices(1);
894  }
895 
896  // Check parameters
897  if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) // warning name of option should be STOCK_CALCULATE_ON_SUPPLIER_APPROVE_ORDER
898  {
899  if (!$idwarehouse || $idwarehouse == -1)
900  {
901  $error++;
902  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
903  $action = '';
904  }
905  }
906 
907  if (!$error)
908  {
909  $result = $object->approve($user, $idwarehouse, ($action == 'confirm_approve2' ? 1 : 0));
910  if ($result > 0)
911  {
912  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
913  $outputlangs = $langs;
914  $newlang = '';
915  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
916  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
917  if (!empty($newlang)) {
918  $outputlangs = new Translate("", $conf);
919  $outputlangs->setDefaultLang($newlang);
920  }
921  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
922  }
923  } else {
924  $error++;
925  setEventMessages($object->error, $object->errors, 'errors');
926  }
927  }
928 
929  if (!$error) {
930  $db->commit();
931 
932  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
933  exit;
934  } else {
935  $db->rollback();
936  }
937  }
938 
939  if ($action == 'confirm_refuse' && $confirm == 'yes' && $usercanapprove)
940  {
941  $result = $object->refuse($user);
942  if ($result > 0)
943  {
944  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
945  exit;
946  } else {
947  setEventMessages($object->error, $object->errors, 'errors');
948  }
949  }
950 
951  // Force mandatory order method
952  if ($action == 'commande') {
953  $methodecommande = GETPOST('methodecommande', 'int');
954 
955  if ($methodecommande <= 0) {
956  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("OrderMode")), null, 'errors');
957  $action = 'makeorder';
958  }
959  }
960 
961  if ($action == 'confirm_commande' && $confirm == 'yes' && $usercanorder)
962  {
963  $db->begin();
964 
965  $result = $object->commande($user, GETPOST("datecommande"), GETPOST("methode", 'int'), GETPOST('comment', 'alphanohtml'));
966  if ($result > 0)
967  {
968  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
969  {
970  $outputlangs = $langs;
971  $newlang = '';
972  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
973  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
974  if (!empty($newlang)) {
975  $outputlangs = new Translate("", $conf);
976  $outputlangs->setDefaultLang($newlang);
977  }
978  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
979  }
980  $action = '';
981  } else {
982  $error++;
983  setEventMessages($object->error, $object->errors, 'errors');
984  }
985 
986  if (!$error) {
987  $db->commit();
988 
989  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
990  exit;
991  } else {
992  $db->rollback();
993  }
994  }
995 
996 
997  if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete)
998  {
999  $result = $object->delete($user);
1000  if ($result > 0)
1001  {
1002  header("Location: ".DOL_URL_ROOT.'/fourn/commande/list.php?restore_lastsearch_values=1');
1003  exit;
1004  } else {
1005  setEventMessages($object->error, $object->errors, 'errors');
1006  }
1007  }
1008 
1009  // Action clone object
1010  if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate)
1011  {
1012  if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
1013  {
1014  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
1015  } else {
1016  if ($object->id > 0)
1017  {
1018  $orig = clone $object;
1019 
1020  $result = $object->createFromClone($user, $socid);
1021  if ($result > 0)
1022  {
1023  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
1024  exit;
1025  } else {
1026  setEventMessages($object->error, $object->errors, 'errors');
1027  $object = $orig;
1028  $action = '';
1029  }
1030  }
1031  }
1032  }
1033 
1034  // Set status of reception (complete, partial, ...)
1035  if ($action == 'livraison' && $usercanreceived)
1036  {
1037  $db->begin();
1038 
1039  if (GETPOST("type") != '')
1040  {
1041  $date_liv = dol_mktime(GETPOST('rehour'), GETPOST('remin'), GETPOST('resec'), GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear"));
1042 
1043  $result = $object->Livraison($user, $date_liv, GETPOST("type"), GETPOST("comment")); // GETPOST("type") is 'tot', 'par', 'nev', 'can'
1044  if ($result > 0)
1045  {
1046  $langs->load("deliveries");
1047  setEventMessages($langs->trans("DeliveryStateSaved"), null);
1048  $action = '';
1049  } elseif ($result == -3)
1050  {
1051  $error++;
1052  setEventMessages($object->error, $object->errors, 'errors');
1053  } else {
1054  $error++;
1055  setEventMessages($object->error, $object->errors, 'errors');
1056  }
1057  } else {
1058  $error++;
1059  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Delivery")), null, 'errors');
1060  }
1061 
1062  if (!$error) {
1063  $db->commit();
1064  } else {
1065  $db->rollback();
1066  }
1067  }
1068 
1069  if ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanorder)
1070  {
1071  $result = $object->cancel($user);
1072  if ($result > 0)
1073  {
1074  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
1075  exit;
1076  } else {
1077  setEventMessages($object->error, $object->errors, 'errors');
1078  }
1079  }
1080 
1081  // Actions when printing a doc from card
1082  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1083 
1084  // Actions to send emails
1085  $triggersendname = 'ORDER_SUPPLIER_SENTBYMAIL';
1086  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
1087  $trackid = 'sord'.$object->id;
1088  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1089 
1090  // Actions to build doc
1091  $upload_dir = $conf->fournisseur->commande->dir_output;
1092  $permissiontoadd = $usercancreate;
1093  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1094 
1095 
1096  if ($action == 'update_extras')
1097  {
1098  $object->oldcopy = dol_clone($object);
1099 
1100  // Fill array 'array_options' with data from add form
1101  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1102  if ($ret < 0) $error++;
1103 
1104  if (!$error)
1105  {
1106  // Actions on extra fields
1107  if (!$error)
1108  {
1109  $result = $object->insertExtraFields('ORDER_SUPPLIER_MODIFY');
1110  if ($result < 0)
1111  {
1112  $error++;
1113  setEventMessages($object->error, $object->errors, 'errors');
1114  }
1115  }
1116  }
1117 
1118  if ($error)
1119  $action = 'edit_extras';
1120  }
1121 
1122  /*
1123  * Create an order
1124  */
1125  if ($action == 'add' && $usercancreate)
1126  {
1127  $error = 0;
1128  $selectedLines = GETPOST('toselect', 'array');
1129  if ($socid < 1)
1130  {
1131  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors');
1132  $action = 'create';
1133  $error++;
1134  }
1135 
1136  if (!$error)
1137  {
1138  $db->begin();
1139 
1140  // Creation commande
1141  $object->ref_supplier = GETPOST('refsupplier');
1142  $object->socid = $socid;
1143  $object->cond_reglement_id = GETPOST('cond_reglement_id');
1144  $object->mode_reglement_id = GETPOST('mode_reglement_id');
1145  $object->fk_account = GETPOST('fk_account', 'int');
1146  $object->note_private = GETPOST('note_private', 'restricthtml');
1147  $object->note_public = GETPOST('note_public', 'restricthtml');
1148  $object->date_livraison = $datelivraison; // deprecated
1149  $object->delivery_date = $datelivraison;
1150  $object->fk_incoterms = GETPOST('incoterm_id', 'int');
1151  $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
1152  $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
1153  $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
1154  $object->fk_project = GETPOST('projectid');
1155 
1156  // Fill array 'array_options' with data from add form
1157  if (!$error)
1158  {
1159  $ret = $extrafields->setOptionalsFromPost(null, $object);
1160  if ($ret < 0) $error++;
1161  }
1162 
1163  if (!$error)
1164  {
1165  // If creation from another object of another module (Example: origin=propal, originid=1)
1166  if (!empty($origin) && !empty($originid))
1167  {
1168  if ($origin == 'propal' || $origin == 'proposal')
1169  {
1170  $classname = 'Propal';
1171  $element = 'comm/propal'; $subelement = 'propal';
1172  } elseif ($origin == 'order' || $origin == 'commande')
1173  {
1174  $classname = 'Commande';
1175  $element = $subelement = 'commande';
1176  } else {
1177  $classname = 'SupplierProposal';
1178  $element = 'supplier_proposal';
1179  $subelement = 'supplier_proposal';
1180  }
1181 
1182  $object->origin = $origin;
1183  $object->origin_id = $originid;
1184 
1185  // Possibility to add external linked objects with hooks
1186  $object->linked_objects [$object->origin] = $object->origin_id;
1187  $other_linked_objects = GETPOST('other_linked_objects', 'array');
1188  if (!empty($other_linked_objects)) {
1189  $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
1190  }
1191 
1192  $id = $object->create($user);
1193  if ($id > 0)
1194  {
1195  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1196 
1197  $srcobject = new $classname($db);
1198 
1199  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
1200  $result = $srcobject->fetch($object->origin_id);
1201  if ($result > 0)
1202  {
1203  $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison);
1204  $object->setDeliveryDate($user, $tmpdate);
1205  $object->set_id_projet($user, $srcobject->fk_project);
1206 
1207  $lines = $srcobject->lines;
1208  if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
1209  {
1210  $srcobject->fetch_lines();
1211  $lines = $srcobject->lines;
1212  }
1213 
1214  $fk_parent_line = 0;
1215  $num = count($lines);
1216 
1217  for ($i = 0; $i < $num; $i++)
1218  {
1219  if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->id, $selectedLines))
1220  continue;
1221 
1222  $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
1223  $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc);
1224  $product_type = (!empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0);
1225 
1226  // Reset fk_parent_line for no child products and special product
1227  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
1228  $fk_parent_line = 0;
1229  }
1230 
1231  // Extrafields
1232  if (method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if
1233  {
1234  $lines[$i]->fetch_optionals();
1235  $array_option = $lines[$i]->array_options;
1236  }
1237 
1238  $ref_supplier = '';
1239  $product_fourn_price_id = 0;
1240  if ($origin == "commande")
1241  {
1242  $productsupplier = new ProductFournisseur($db);
1243  $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid);
1244  if ($result > 0)
1245  {
1246  $ref_supplier = $productsupplier->ref_supplier;
1247  $product_fourn_price_id = $productsupplier->product_fourn_price_id;
1248  }
1249  } else {
1250  $ref_supplier = $lines[$i]->ref_fourn;
1251  $product_fourn_price_id = 0;
1252  }
1253 
1254  $tva_tx = $lines[$i]->tva_tx;
1255 
1256  if ($origin == "commande")
1257  {
1258  $soc = new societe($db);
1259  $soc->fetch($socid);
1260  $tva_tx = get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
1261  }
1262 
1263  $result = $object->addline(
1264  $desc,
1265  $lines[$i]->subprice,
1266  $lines[$i]->qty,
1267  $tva_tx,
1268  $lines[$i]->localtax1_tx,
1269  $lines[$i]->localtax2_tx,
1270  $lines[$i]->fk_product > 0 ? $lines[$i]->fk_product : 0,
1271  $product_fourn_price_id,
1272  $ref_supplier,
1273  $lines[$i]->remise_percent,
1274  'HT',
1275  0,
1276  $lines[$i]->product_type,
1277  '',
1278  '',
1279  null,
1280  null,
1281  $array_option,
1282  $lines[$i]->fk_unit,
1283  0,
1284  $element,
1285  !empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid
1286  );
1287 
1288  if ($result < 0) {
1289  $error++;
1290  break;
1291  }
1292 
1293  // Defined the new fk_parent_line
1294  if ($result > 0 && $lines[$i]->product_type == 9) {
1295  $fk_parent_line = $result;
1296  }
1297  }
1298 
1299  // Add link between elements
1300 
1301 
1302  // Hooks
1303  $parameters = array('objFrom' => $srcobject);
1304  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
1305 
1306  if ($reshook < 0)
1307  $error++;
1308  } else {
1309  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
1310  $error++;
1311  }
1312  } else {
1313  setEventMessages($object->error, $object->errors, 'errors');
1314  $error++;
1315  }
1316  } else {
1317  $id = $object->create($user);
1318  if ($id < 0)
1319  {
1320  $error++;
1321  setEventMessages($object->error, $object->errors, 'errors');
1322  }
1323  }
1324  }
1325 
1326  if ($error)
1327  {
1328  $langs->load("errors");
1329  $db->rollback();
1330  $action = 'create';
1331  $_GET['socid'] = $_POST['socid'];
1332  } else {
1333  $db->commit();
1334  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
1335  exit;
1336  }
1337  }
1338  }
1339 
1340  if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && !GETPOST('cancel', 'alpha'))
1341  {
1342  $ws_url = $object->thirdparty->webservices_url;
1343  $ws_key = $object->thirdparty->webservices_key;
1344  $ws_user = GETPOST('ws_user', 'alpha');
1345  $ws_password = GETPOST('ws_password', 'alpha');
1346  $ws_entity = GETPOST('ws_entity', 'int');
1347  $ws_thirdparty = GETPOST('ws_thirdparty', 'int');
1348 
1349  // NS and Authentication parameters
1350  $ws_ns = 'http://www.dolibarr.org/ns/';
1351  $ws_authentication = array(
1352  'dolibarrkey'=>$ws_key,
1353  'sourceapplication'=>'DolibarrWebServiceClient',
1354  'login'=>$ws_user,
1355  'password'=>$ws_password,
1356  'entity'=>$ws_entity
1357  );
1358 
1359  //Is sync supplier web services module activated? and everything filled?
1360  if (empty($conf->syncsupplierwebservices->enabled)) {
1361  setEventMessages($langs->trans("WarningModuleNotActive", $langs->transnoentities("Module2650Name")), null, 'mesgs');
1362  } elseif (empty($ws_url) || empty($ws_key)) {
1363  setEventMessages($langs->trans("ErrorWebServicesFieldsRequired"), null, 'errors');
1364  } elseif (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
1365  setEventMessages($langs->trans("ErrorFieldsRequired"), null, 'errors');
1366  } else {
1367  //Create SOAP client and connect it to order
1368  $soapclient_order = new nusoap_client($ws_url."/webservices/server_order.php");
1369  $soapclient_order->soap_defencoding = 'UTF-8';
1370  $soapclient_order->decodeUTF8(false);
1371 
1372  //Create SOAP client and connect it to product/service
1373  $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
1374  $soapclient_product->soap_defencoding = 'UTF-8';
1375  $soapclient_product->decodeUTF8(false);
1376 
1377  //Prepare the order lines from order
1378  $order_lines = array();
1379  foreach ($object->lines as $line)
1380  {
1381  $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $line->ref_supplier);
1382  $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
1383 
1384  if ($result_product["result"]["result_code"] == "OK")
1385  {
1386  $order_lines[] = array(
1387  'desc' => $line->product_desc,
1388  'type' => $line->product_type,
1389  'product_id' => $result_product["product"]["id"],
1390  'vat_rate' => $line->tva_tx,
1391  'qty' => $line->qty,
1392  'price' => $line->price,
1393  'unitprice' => $line->subprice,
1394  'total_net' => $line->total_ht,
1395  'total_vat' => $line->total_tva,
1396  'total' => $line->total_ttc,
1397  'date_start' => $line->date_start,
1398  'date_end' => $line->date_end,
1399  );
1400  }
1401  }
1402 
1403  //Prepare the order header
1404  $order = array(
1405  'thirdparty_id' => $ws_thirdparty,
1406  'date' => dol_print_date(dol_now(), 'dayrfc'),
1407  'total_net' => $object->total_ht,
1408  'total_var' => $object->total_tva,
1409  'total' => $object->total_ttc,
1410  'lines' => $order_lines
1411  );
1412 
1413  $ws_parameters = array('authentication'=>$ws_authentication, 'order' => $order);
1414  $result_order = $soapclient_order->call("createOrder", $ws_parameters, $ws_ns, '');
1415 
1416  if (empty($result_order["result"]["result_code"])) //No result, check error str
1417  {
1418  setEventMessages($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", null, 'errors');
1419  } elseif ($result_order["result"]["result_code"] != "OK") //Something went wrong
1420  {
1421  setEventMessages($langs->trans("SOAPError")." '".$result_order["result"]["result_code"]."' - '".$result_order["result"]["result_label"]."'", null, 'errors');
1422  } else {
1423  setEventMessages($langs->trans("RemoteOrderRef")." ".$result_order["ref"], null, 'mesgs');
1424  }
1425  }
1426  }
1427 
1428  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate)
1429  {
1430  if ($action == 'addcontact')
1431  {
1432  if ($object->id > 0)
1433  {
1434  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1435  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1436  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1437  }
1438 
1439  if ($result >= 0)
1440  {
1441  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1442  exit;
1443  } else {
1444  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1445  {
1446  $langs->load("errors");
1447  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1448  } else {
1449  setEventMessages($object->error, $object->errors, 'errors');
1450  }
1451  }
1452  }
1453 
1454  // bascule du statut d'un contact
1455  elseif ($action == 'swapstatut' && $object->id > 0)
1456  {
1457  $result = $object->swapContactStatus(GETPOST('ligne'));
1458  }
1459 
1460  // Efface un contact
1461  elseif ($action == 'deletecontact' && $object->id > 0)
1462  {
1463  $result = $object->delete_contact($_GET["lineid"]);
1464 
1465  if ($result >= 0)
1466  {
1467  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1468  exit;
1469  } else {
1470  dol_print_error($db);
1471  }
1472  }
1473  }
1474 }
1475 
1476 
1477 /*
1478  * View
1479  */
1480 
1481 $form = new Form($db);
1482 $formfile = new FormFile($db);
1483 $formorder = new FormOrder($db);
1484 $productstatic = new Product($db);
1485 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
1486 
1487 $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
1488 llxHeader('', $langs->trans("Order"), $help_url);
1489 
1490 $now = dol_now();
1491 
1492 if ($action == 'create')
1493 {
1494  print load_fiche_titre($langs->trans('NewOrderSupplier'), '', 'supplier_order');
1495 
1497 
1498  $currency_code = $conf->currency;
1499 
1500  $societe = '';
1501  if ($socid > 0)
1502  {
1503  $societe = new Societe($db);
1504  $societe->fetch($socid);
1505  }
1506 
1507  if (!empty($origin) && !empty($originid))
1508  {
1509  // Parse element/subelement (ex: project_task)
1510  $element = $subelement = $origin;
1511  $regs = array();
1512  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
1513  $element = $regs[1];
1514  $subelement = $regs[2];
1515  }
1516 
1517  if ($origin == 'propal' || $origin == 'proposal')
1518  {
1519  $classname = 'Propal';
1520  $element = 'comm/propal'; $subelement = 'propal';
1521  } elseif ($origin == 'order' || $origin == 'commande')
1522  {
1523  $classname = 'Commande';
1524  $element = $subelement = 'commande';
1525  } else {
1526  $classname = 'SupplierProposal';
1527  $element = 'supplier_proposal';
1528  $subelement = 'supplier_proposal';
1529  }
1530 
1531  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1532 
1533  $objectsrc = new $classname($db);
1534  $objectsrc->fetch($originid);
1535  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
1536  $objectsrc->fetch_lines();
1537  $objectsrc->fetch_thirdparty();
1538 
1539  // Replicate extrafields
1540  $objectsrc->fetch_optionals();
1541  $object->array_options = $objectsrc->array_options;
1542 
1543  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1544  $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
1545 
1546  $soc = $objectsrc->client;
1547  $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0));
1548  $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
1549  $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
1550  $availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
1551  $shipping_method_id = (!empty($objectsrc->shipping_method_id) ? $objectsrc->shipping_method_id : (!empty($soc->shipping_method_id) ? $soc->shipping_method_id : 0));
1552  $demand_reason_id = (!empty($objectsrc->demand_reason_id) ? $objectsrc->demand_reason_id : (!empty($soc->demand_reason_id) ? $soc->demand_reason_id : 0));
1553  $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_supplier_percent) ? $soc->remise_supplier_percent : 0));
1554  $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
1555  $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '';
1556 
1557  $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : ''));
1558 
1559  if (!empty($conf->multicurrency->enabled))
1560  {
1561  if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
1562  if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
1563  }
1564 
1565  $note_private = $object->getDefaultCreateValueFor('note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null));
1566  $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc->note_public) ? $objectsrc->note_public : null));
1567 
1568  // Object source contacts list
1569  $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1570  } else {
1571  $cond_reglement_id = $societe->cond_reglement_supplier_id;
1572  $mode_reglement_id = $societe->mode_reglement_supplier_id;
1573 
1574  if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code;
1575 
1576  $note_private = $object->getDefaultCreateValueFor('note_private');
1577  $note_public = $object->getDefaultCreateValueFor('note_public');
1578  }
1579 
1580  // If not defined, set default value from constant
1581  if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID;
1582  if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID;
1583 
1584  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1585  print '<input type="hidden" name="token" value="'.newToken().'">';
1586  print '<input type="hidden" name="action" value="add">';
1587  print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
1588  print '<input type="hidden" name="remise_percent" value="'.$soc->remise_supplier_percent.'">';
1589  print '<input type="hidden" name="origin" value="'.$origin.'">';
1590  print '<input type="hidden" name="originid" value="'.$originid.'">';
1591  if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">';
1592 
1594 
1595  print '<table class="border centpercent">';
1596 
1597  // Ref
1598  print '<tr><td class="titlefieldcreate">'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
1599 
1600  // Third party
1601  print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
1602  print '<td>';
1603 
1604  if ($socid > 0)
1605  {
1606  print $societe->getNomUrl(1);
1607  print '<input type="hidden" name="socid" value="'.$socid.'">';
1608  } else {
1609  print img_picto('', 'company').$form->select_company((empty($socid) ? '' : $socid), 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
1610  // reload page to retrieve customer informations
1611  if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE))
1612  {
1613  print '<script>
1614  $(document).ready(function() {
1615  $("#socid").change(function() {
1616  var socid = $(this).val();
1617  // reload page
1618  window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid;
1619  });
1620  });
1621  </script>';
1622  }
1623  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1624  }
1625  print '</td>';
1626 
1627  if ($societe->id > 0)
1628  {
1629  // Discounts for third party
1630  print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1631 
1632  $absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
1633 
1634  $thirdparty = $societe;
1635  $discount_type = 1;
1636  $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
1637  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
1638 
1639  print '</td></tr>';
1640  }
1641 
1642  // Ref supplier
1643  print '<tr><td>'.$langs->trans('RefSupplier').'</td><td><input name="refsupplier" type="text"></td>';
1644  print '</tr>';
1645 
1646  // Payment term
1647  print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
1648  $form->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id');
1649  print '</td></tr>';
1650 
1651  // Payment mode
1652  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
1653  $form->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id');
1654  print '</td></tr>';
1655 
1656  // Planned delivery date
1657  print '<tr><td>';
1658  print $langs->trans('DateDeliveryPlanned');
1659  print '</td>';
1660  print '<td>';
1661  $usehourmin = 0;
1662  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin = 1;
1663  print $form->selectDate($datelivraison ? $datelivraison : -1, 'liv_', $usehourmin, $usehourmin, '', "set");
1664  print '</td></tr>';
1665 
1666  // Bank Account
1667  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled))
1668  {
1669  $langs->load("bank");
1670  print '<tr><td>'.$langs->trans('BankAccount').'</td><td>';
1671  print img_picto('', 'bank_account', 'class="paddingrightonly"');
1672  $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
1673  print '</td></tr>';
1674  }
1675 
1676  // Project
1677  if (!empty($conf->projet->enabled))
1678  {
1679  $formproject = new FormProjets($db);
1680 
1681  $langs->load('projects');
1682  print '<tr><td>'.$langs->trans('Project').'</td><td>';
1683  print img_picto('', 'project').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
1684  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$societe->id).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
1685  print '</td></tr>';
1686  }
1687 
1688  // Incoterms
1689  if (!empty($conf->incoterm->enabled))
1690  {
1691  $fkincoterms = (!empty($object->fk_incoterms) ? $object->fk_incoterms : ($socid > 0 ? $societe->fk_incoterms : ''));
1692  $locincoterms = (!empty($object->location_incoterms) ? $object->location_incoterms : ($socid > 0 ? $societe->location_incoterms : ''));
1693  print '<tr>';
1694  print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
1695  print '<td class="maxwidthonsmartphone">';
1696  print $form->select_incoterms($fkincoterms, $locincoterms);
1697  print '</td></tr>';
1698  }
1699 
1700  // Multicurrency
1701  if (!empty($conf->multicurrency->enabled))
1702  {
1703  print '<tr>';
1704  print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
1705  print '<td class="maxwidthonsmartphone">';
1706  print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
1707  print '</td></tr>';
1708  }
1709 
1710  print '<tr><td>'.$langs->trans('NotePublic').'</td>';
1711  print '<td>';
1712  $doleditor = new DolEditor('note_public', isset($note_public) ? $note_public : GETPOST('note_public', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1713  print $doleditor->Create(1);
1714  print '</td>';
1715  //print '<textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea>';
1716  print '</tr>';
1717 
1718  print '<tr><td>'.$langs->trans('NotePrivate').'</td>';
1719  print '<td>';
1720  $doleditor = new DolEditor('note_private', isset($note_private) ? $note_private : GETPOST('note_private', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1721  print $doleditor->Create(1);
1722  print '</td>';
1723  //print '<td><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
1724  print '</tr>';
1725 
1726  if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
1727  print "\n<!-- ".$classname." info -->";
1728  print "\n";
1729  print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
1730  print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
1731  print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
1732  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1733  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1734 
1735  $newclassname = $classname;
1736  print '<tr><td>'.$langs->trans($newclassname).'</td><td>'.$objectsrc->getNomUrl(1).'</td></tr>';
1737  print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht).'</td></tr>';
1738  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva)."</td></tr>";
1739  if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
1740  {
1741  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1)."</td></tr>";
1742  }
1743 
1744  if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
1745  {
1746  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2)."</td></tr>";
1747  }
1748 
1749  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc)."</td></tr>";
1750 
1751  if (!empty($conf->multicurrency->enabled))
1752  {
1753  print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
1754  print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva).'</td></tr>';
1755  print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc).'</td></tr>';
1756  }
1757  }
1758 
1759  // Other options
1760  $parameters = array();
1761  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1762  print $hookmanager->resPrint;
1763 
1764  if (empty($reshook))
1765  {
1766  print $object->showOptionals($extrafields, 'edit');
1767  }
1768 
1769  // Bouton "Create Draft"
1770  print "</table>\n";
1771 
1773 
1774  print '<div class="center">';
1775  print '<input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'">';
1776  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1777  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
1778  print '</div>';
1779 
1780 
1781 
1782  // Show origin lines
1783  if (!empty($origin) && !empty($originid) && is_object($objectsrc))
1784  {
1785  $title = $langs->trans('ProductsAndServices');
1786  print load_fiche_titre($title);
1787 
1788  print '<table class="noborder centpercent">';
1789 
1790  $objectsrc->printOriginLinesList('', $selectedLines);
1791 
1792  print '</table>';
1793  }
1794  print "</form>\n";
1795 } elseif (!empty($object->id)) {
1796  $result = $object->fetch($id, $ref);
1797 
1798  $societe = new Fournisseur($db);
1799  $result = $societe->fetch($object->socid);
1800  if ($result < 0) dol_print_error($db);
1801 
1802  $author = new User($db);
1803  $author->fetch($object->user_author_id);
1804 
1805  $res = $object->fetch_optionals();
1806 
1807 
1808  $head = ordersupplier_prepare_head($object);
1809 
1810  $title = $langs->trans("SupplierOrder");
1811  print dol_get_fiche_head($head, 'card', $title, -1, 'order');
1812 
1813 
1814  $formconfirm = '';
1815 
1816  // Confirmation de la suppression de la commande
1817  if ($action == 'delete')
1818  {
1819  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
1820  }
1821 
1822  // Clone confirmation
1823  if ($action == 'clone')
1824  {
1825  // Create an array for form
1826  $formquestion = array(
1827  array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.fournisseur=1)'))
1828  );
1829  // Paiement incomplet. On demande si motif = escompte ou autre
1830  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneOrder', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1831  }
1832 
1833  // Confirmation de la validation
1834  if ($action == 'valid')
1835  {
1836  $object->date_commande = dol_now();
1837 
1838  // We check if number is temporary number
1839  if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) // empty should not happened, but when it occurs, the test save life
1840  {
1841  $newref = $object->getNextNumRef($object->thirdparty);
1842  } else $newref = $object->ref;
1843 
1844  if ($newref < 0)
1845  {
1846  setEventMessages($object->error, $object->errors, 'errors');
1847  $action = '';
1848  } else {
1849  $text = $langs->trans('ConfirmValidateOrder', $newref);
1850  if (!empty($conf->notification->enabled))
1851  {
1852  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1853  $notify = new Notify($db);
1854  $text .= '<br>';
1855  $text .= $notify->confirmMessage('ORDER_SUPPLIER_VALIDATE', $object->socid, $object);
1856  }
1857 
1858  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
1859  }
1860  }
1861 
1862  // Confirm approval
1863  if ($action == 'approve' || $action == 'approve2')
1864  {
1865  $qualified_for_stock_change = 0;
1866  if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
1867  {
1868  $qualified_for_stock_change = $object->hasProductsOrServices(2);
1869  } else {
1870  $qualified_for_stock_change = $object->hasProductsOrServices(1);
1871  }
1872 
1873  $formquestion = array();
1874  if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
1875  {
1876  $langs->load("stocks");
1877  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1878  $formproduct = new FormProduct($db);
1879  $forcecombo = 0;
1880  if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
1881  $formquestion = array(
1882  //'text' => $langs->trans("ConfirmClone"),
1883  //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
1884  //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
1885  array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse', 'int'), 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
1886  );
1887  }
1888  $text = $langs->trans("ConfirmApproveThisOrder", $object->ref);
1889  if (!empty($conf->notification->enabled))
1890  {
1891  require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1892  $notify = new Notify($db);
1893  $text .= '<br>';
1894  $text .= $notify->confirmMessage('ORDER_SUPPLIER_APPROVE', $object->socid, $object);
1895  }
1896 
1897  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ApproveThisOrder"), $text, "confirm_".$action, $formquestion, 1, 1, 240);
1898  }
1899 
1900  // Confirmation de la desapprobation
1901  if ($action == 'refuse')
1902  {
1903  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("DenyingThisOrder"), $langs->trans("ConfirmDenyingThisOrder", $object->ref), "confirm_refuse", '', 0, 1);
1904  }
1905 
1906  // Confirmation de l'annulation
1907  if ($action == 'cancel')
1908  {
1909  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("Cancel"), $langs->trans("ConfirmCancelThisOrder", $object->ref), "confirm_cancel", '', 0, 1);
1910  }
1911 
1912  // Confirmation de l'envoi de la commande
1913  if ($action == 'commande')
1914  {
1915  $date_com = dol_mktime(GETPOST('rehour'), GETPOST('remin'), GETPOST('resec'), GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear"));
1916  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"), $langs->trans("ConfirmMakeOrder", dol_print_date($date_com, 'day')), "confirm_commande", '', 0, 2);
1917  }
1918 
1919  // Confirmation to delete line
1920  if ($action == 'ask_deleteline')
1921  {
1922  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
1923  }
1924 
1925  $parameters = array('formConfirm' => $formconfirm, 'lineid'=>$lineid);
1926  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1927  if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
1928  elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
1929 
1930  // Print form confirm
1931  print $formconfirm;
1932 
1933 
1934  // Supplier order card
1935 
1936  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1937 
1938  $morehtmlref = '<div class="refidno">';
1939  // Ref supplier
1940  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', 0, 1);
1941  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', null, null, '', 1);
1942  // Thirdparty
1943  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
1944  if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && !empty($usercancreate) && $action == 'edit_thirdparty') {
1945  $morehtmlref .= ' : ';
1946  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1947  $morehtmlref .= '<input type="hidden" name="action" value="set_thirdparty">';
1948  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
1949  $morehtmlref .= $form->select_company($object->thirdparty->id, 'new_socid', 's.fournisseur=1', '', 0, 0, array(), 0, 'minwidth300');
1950  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1951  $morehtmlref .= '</form>';
1952  }
1953  if (empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) || $action != 'edit_thirdparty') {
1954  if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $object->statut == CommandeFournisseur::STATUS_DRAFT) {
1955  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=edit_thirdparty&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty')).'</a>';
1956  }
1957  $morehtmlref .= ' : '.$object->thirdparty->getNomUrl(1);
1958  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
1959  }
1960 
1961  // Project
1962  if (!empty($conf->projet->enabled)) {
1963  $langs->load("projects");
1964  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
1965  if ($usercancreate) {
1966  if ($action != 'classify')
1967  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
1968  if ($action == 'classify') {
1969  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1970  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1971  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1972  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
1973  $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500');
1974  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1975  $morehtmlref .= '</form>';
1976  } else {
1977  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1978  }
1979  } else {
1980  if (!empty($object->fk_project)) {
1981  $proj = new Project($db);
1982  $proj->fetch($object->fk_project);
1983  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
1984  $morehtmlref .= $proj->ref;
1985  $morehtmlref .= '</a>';
1986  } else {
1987  $morehtmlref .= '';
1988  }
1989  }
1990  }
1991  $morehtmlref .= '</div>';
1992 
1993 
1994  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1995 
1996 
1997  print '<div class="fichecenter">';
1998  print '<div class="fichehalfleft">';
1999  print '<div class="underbanner clearboth"></div>';
2000 
2001  print '<table class="border tableforfield centpercent">';
2002 
2003  // Date
2004  if ($object->methode_commande_id > 0)
2005  {
2006  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>';
2007  print $object->date_commande ? dol_print_date($object->date_commande, $usehourmin) : '';
2008  if ($object->hasDelay() && !empty($object->date_delivery) && !empty($object->date_commande)) {
2009  print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2010  }
2011  print "</td></tr>";
2012 
2013  if ($object->methode_commande)
2014  {
2015  print '<tr><td>'.$langs->trans("Method").'</td><td>'.$object->getInputMethod().'</td></tr>';
2016  }
2017  }
2018 
2019  // Author
2020  print '<tr><td class="titlefield">'.$langs->trans("AuthorRequest").'</td>';
2021  print '<td>'.$author->getNomUrl(1, '', 0, 0, 0).'</td>';
2022  print '</tr>';
2023 
2024  // Relative and absolute discounts
2025  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
2026  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2027  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2028  } else {
2029  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2030  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2031  }
2032 
2033  $absolute_discount = $societe->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
2034  $absolute_creditnote = $societe->getAvailableDiscounts('', $filtercreditnote, 0, 1);
2035  $absolute_discount = price2num($absolute_discount, 'MT');
2036  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2037 
2038  print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
2039 
2040  $thirdparty = $societe;
2041  $discount_type = 1;
2042  $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
2043  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2044 
2045  print '</td></tr>';
2046 
2047  // Default terms of the settlement
2048  $langs->load('bills');
2049  print '<tr><td class="nowrap">';
2050  print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2051  print $langs->trans('PaymentConditions');
2052  print '<td>';
2053  if ($action != 'editconditions') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
2054  print '</tr></table>';
2055  print '</td><td>';
2056  if ($action == 'editconditions')
2057  {
2058  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
2059  } else {
2060  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
2061  }
2062  print "</td>";
2063  print '</tr>';
2064 
2065  // Mode of payment
2066  $langs->load('bills');
2067  print '<tr><td class="nowrap">';
2068  print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2069  print $langs->trans('PaymentMode');
2070  print '</td>';
2071  if ($action != 'editmode') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
2072  print '</tr></table>';
2073  print '</td><td>';
2074  if ($action == 'editmode')
2075  {
2076  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
2077  } else {
2078  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
2079  }
2080  print '</td></tr>';
2081 
2082  // Multicurrency
2083  if (!empty($conf->multicurrency->enabled))
2084  {
2085  // Multicurrency code
2086  print '<tr>';
2087  print '<td>';
2088  print '<table class="nobordernopadding centpercent"><tr><td>';
2089  print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
2090  print '</td>';
2091  if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT)
2092  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
2093  print '</tr></table>';
2094  print '</td><td>';
2095  if ($action == 'editmulticurrencycode') {
2096  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
2097  } else {
2098  $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
2099  }
2100  print '</td></tr>';
2101 
2102  // Multicurrency rate
2103  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
2104  {
2105  print '<tr>';
2106  print '<td>';
2107  print '<table class="nobordernopadding centpercent"><tr>';
2108  print '<td>';
2109  print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
2110  print '</td>';
2111  if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency)
2112  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
2113  print '</tr></table>';
2114  print '</td><td>';
2115  if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
2116  if ($action == 'actualizemulticurrencyrate') {
2117  list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
2118  }
2119  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
2120  } else {
2121  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
2122  if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
2123  print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
2124  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
2125  print '</div>';
2126  }
2127  }
2128  print '</td></tr>';
2129  }
2130  }
2131 
2132  // Bank Account
2133  if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && !empty($conf->banque->enabled))
2134  {
2135  print '<tr><td class="nowrap">';
2136  print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
2137  print $langs->trans('BankAccount');
2138  print '<td>';
2139  if ($action != 'editbankaccount' && $usercancreate)
2140  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
2141  print '</tr></table>';
2142  print '</td><td>';
2143  if ($action == 'editbankaccount') {
2144  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
2145  } else {
2146  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
2147  }
2148  print '</td>';
2149  print '</tr>';
2150  }
2151 
2152  // Delivery delay (in days)
2153  print '<tr>';
2154  print '<td>'.$langs->trans('NbDaysToDelivery').'&nbsp;'.img_picto($langs->trans('DescNbDaysToDelivery'), 'info', 'style="cursor:help"').'</td>';
2155  print '<td>'.$object->getMaxDeliveryTimeDay($langs).'</td>';
2156  print '</tr>';
2157 
2158  // Delivery date planed
2159  print '<tr><td>';
2160  print '<table class="nobordernopadding centpercent"><tr><td>';
2161  print $langs->trans('DateDeliveryPlanned');
2162  print '</td>';
2163  if ($action != 'editdate_livraison') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
2164  print '</tr></table>';
2165  print '</td><td>';
2166  if ($action == 'editdate_livraison')
2167  {
2168  print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2169  print '<input type="hidden" name="token" value="'.newToken().'">';
2170  print '<input type="hidden" name="action" value="setdate_livraison">';
2171  $usehourmin = 0;
2172  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin = 1;
2173  print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', $usehourmin, $usehourmin, '', "setdate_livraison");
2174  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
2175  print '</form>';
2176  } else {
2177  $usehourmin = 'day';
2178  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin = 'dayhour';
2179  print $object->delivery_date ? dol_print_date($object->delivery_date, $usehourmin) : '&nbsp;';
2180  if ($object->hasDelay() && !empty($object->delivery_date)) {
2181  print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");
2182  }
2183  }
2184  print '</td></tr>';
2185 
2186  // Incoterms
2187  if (!empty($conf->incoterm->enabled))
2188  {
2189  print '<tr><td>';
2190  print '<table class="nobordernopadding centpercent"><tr><td>';
2191  print $langs->trans('IncotermLabel');
2192  print '<td><td class="right">';
2193  if ($usercancreate) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
2194  else print '&nbsp;';
2195  print '</td></tr></table>';
2196  print '</td>';
2197  print '<td>';
2198  if ($action != 'editincoterm')
2199  {
2200  print $form->textwithpicto(dol_escape_htmltag($object->display_incoterms()), $object->label_incoterms, 1);
2201  } else {
2202  print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2203  }
2204  print '</td></tr>';
2205  }
2206 
2207  // Other attributes
2208  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2209 
2210  print '</table>';
2211 
2212  print '</div>';
2213  print '<div class="fichehalfright">';
2214  print '<div class="ficheaddleft">';
2215  print '<div class="underbanner clearboth"></div>';
2216 
2217  print '<table class="border tableforfield centpercent">';
2218 
2219  if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1)
2220  {
2221  // Multicurrency Amount HT
2222  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
2223  print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2224  print '</tr>';
2225 
2226  // Multicurrency Amount VAT
2227  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
2228  print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2229  print '</tr>';
2230 
2231  // Multicurrency Amount TTC
2232  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
2233  print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
2234  print '</tr>';
2235  }
2236 
2237  // Total
2238  $alert = '';
2239  if (!empty($conf->global->ORDER_MANAGE_MIN_AMOUNT) && $object->total_ht < $object->thirdparty->supplier_order_min_amount) {
2240  $alert = ' '.img_warning($langs->trans('OrderMinAmount').': '.price($object->thirdparty->supplier_order_min_amount));
2241  }
2242  print '<tr><td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
2243  print '<td>'.price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency).$alert.'</td>';
2244  print '</tr>';
2245 
2246  // Total VAT
2247  print '<tr><td>'.$langs->trans("AmountVAT").'</td><td>'.price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency).'</td>';
2248  print '</tr>';
2249 
2250  // Amount Local Taxes
2251  if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) //Localtax1
2252  {
2253  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
2254  print '<td>'.price($object->total_localtax1, '', $langs, 1, -1, -1, $conf->currency).'</td>';
2255  print '</tr>';
2256  }
2257  if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) //Localtax2
2258  {
2259  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
2260  print '<td>'.price($object->total_localtax2, '', $langs, 1, -1, -1, $conf->currency).'</td>';
2261  print '</tr>';
2262  }
2263 
2264  // Total TTC
2265  print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->total_ttc, '', $langs, 1, -1, -1, $conf->currency).'</td>';
2266  print '</tr>';
2267 
2268  print '</table>';
2269 
2270  // Margin Infos
2271  /*if (! empty($conf->margin->enabled)) {
2272  $formmargin->displayMarginInfos($object);
2273  }*/
2274 
2275 
2276  print '</div>';
2277  print '</div>';
2278  print '</div>';
2279 
2280  print '<div class="clearboth"></div><br>';
2281 
2282  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
2283  {
2284  $blocname = 'contacts';
2285  $title = $langs->trans('ContactsAddresses');
2286  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2287  }
2288 
2289  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB))
2290  {
2291  $blocname = 'notes';
2292  $title = $langs->trans('Notes');
2293  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
2294  }
2295 
2296  /*
2297  * Lines
2298  */
2299  //$result = $object->getLinesArray();
2300 
2301 
2302  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid')).'" method="POST">
2303  <input type="hidden" name="token" value="'.newToken().'">
2304  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2305  <input type="hidden" name="mode" value="">
2306  <input type="hidden" name="id" value="'.$object->id.'">
2307  <input type="hidden" name="socid" value="'.$societe->id.'">
2308  ';
2309 
2310  if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
2311  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
2312  }
2313 
2314  print '<div class="div-table-responsive-no-min">';
2315  print '<table id="tablelines" class="noborder noshadow centpercent">';
2316 
2317  // Add free products/services form
2318  global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
2319  $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
2320  $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum.
2321  if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) $senderissupplier = 1;
2322 
2323  // Show object lines
2324  if (!empty($object->lines))
2325  $ret = $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
2326 
2327  $num = count($object->lines);
2328 
2329  // Form to add new line
2330  if ($object->statut == CommandeFournisseur::STATUS_DRAFT && $usercancreate)
2331  {
2332  if ($action != 'editline')
2333  {
2334  // Add free products/services
2335  $object->formAddObjectLine(1, $societe, $mysoc);
2336 
2337  $parameters = array();
2338  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2339  }
2340  }
2341  print '</table>';
2342  print '</div>';
2343  print '</form>';
2344 
2345  print dol_get_fiche_end();
2346 
2351  if ($user->socid == 0 && $action != 'editline' && $action != 'delete')
2352  {
2353  print '<div class="tabsAction">';
2354 
2355  $parameters = array();
2356  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2357  // modified by hook
2358  if (empty($reshook))
2359  {
2360  $object->fetchObjectLinked(); // Links are used to show or not button, so we load them now.
2361 
2362  // Validate
2363  if ($object->statut == 0 && $num > 0)
2364  {
2365  if ($usercanvalidate)
2366  {
2367  $tmpbuttonlabel = $langs->trans('Validate');
2368  if ($usercanapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) $tmpbuttonlabel = $langs->trans("ValidateAndApprove");
2369 
2370  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">';
2371  print $tmpbuttonlabel;
2372  print '</a>';
2373  }
2374  }
2375  // Create event
2376  /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
2377  {
2378  print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddAction") . '</a></div>';
2379  }*/
2380 
2381  // Modify
2382  if ($object->statut == CommandeFournisseur::STATUS_VALIDATED)
2383  {
2384  if ($usercanorder)
2385  {
2386  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("Modify").'</a>';
2387  }
2388  }
2389 
2390  // Approve
2391  if ($object->statut == CommandeFournisseur::STATUS_VALIDATED)
2392  {
2393  if ($usercanapprove)
2394  {
2395  if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED && !empty($object->user_approve_id))
2396  {
2397  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("FirstApprovalAlreadyDone")).'">'.$langs->trans("ApproveOrder").'</a>';
2398  } else {
2399  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
2400  }
2401  } else {
2402  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans("ApproveOrder").'</a>';
2403  }
2404  }
2405 
2406  // Second approval (if option SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED is set)
2407  if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $object->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)
2408  {
2409  if ($object->statut == CommandeFournisseur::STATUS_VALIDATED)
2410  {
2411  if ($usercanapprovesecond)
2412  {
2413  if (!empty($object->user_approve_id2))
2414  {
2415  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SecondApprovalAlreadyDone")).'">'.$langs->trans("Approve2Order").'</a>';
2416  } else {
2417  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=approve2">'.$langs->trans("Approve2Order").'</a>';
2418  }
2419  } else {
2420  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans("Approve2Order").'</a>';
2421  }
2422  }
2423  }
2424 
2425  // Refuse
2426  if ($object->statut == CommandeFournisseur::STATUS_VALIDATED)
2427  {
2428  if ($usercanapprove || $usercanapprovesecond)
2429  {
2430  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
2431  } else {
2432  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans("RefuseOrder").'</a>';
2433  }
2434  }
2435 
2436  // Send
2437  if (empty($user->socid)) {
2438  if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED, 3, 4, 5)) || !empty($conf->global->SUPPLIER_ORDER_SENDBYEMAIL_FOR_ALL_STATUS))
2439  {
2440  if ($usercanorder)
2441  {
2442  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
2443  }
2444  }
2445  }
2446 
2447  // Reopen
2448  if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED)))
2449  {
2450  $buttonshown = 0;
2451  if (!$buttonshown && $usercanapprove)
2452  {
2453  if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY)
2454  || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id))
2455  {
2456  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("Disapprove").'</a>';
2457  $buttonshown++;
2458  }
2459  }
2460  if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED))
2461  {
2462  if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY)
2463  || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2))
2464  {
2465  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("Disapprove").'</a>';
2466  }
2467  }
2468  }
2469  if (in_array($object->statut, array(3, 4, 5, 6, 7, 9)))
2470  {
2471  if ($usercanorder)
2472  {
2473  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
2474  }
2475  }
2476 
2477  // Ship
2478 
2479  if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)))
2480  {
2481  $labelofbutton = $langs->trans('ReceiveProducts');
2482  if ($conf->reception->enabled) $labelofbutton = $langs->trans("CreateReception");
2483 
2484  if (in_array($object->statut, array(3, 4, 5))) {
2485  if ($conf->fournisseur->enabled && $usercanreceived) {
2486  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id.'">'.$labelofbutton.'</a></div>';
2487  } else {
2488  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$labelofbutton.'</a></div>';
2489  }
2490  }
2491  }
2492 
2493  if ($object->statut == CommandeFournisseur::STATUS_ACCEPTED)
2494  {
2495  if ($usercanorder)
2496  {
2497  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=makeorder#makeorder">'.$langs->trans("MakeOrder").'</a></div>';
2498  } else {
2499  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("MakeOrder").'</a></div>';
2500  }
2501  }
2502 
2503  // Classify received (this does not record reception)
2505  {
2506  if ($usercanreceived)
2507  {
2508  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifyreception#classifyreception">'.$langs->trans("ClassifyReception").'</a></div>';
2509  }
2510  }
2511 
2512  // Create bill
2513  //if (! empty($conf->facture->enabled))
2514  //{
2515  if (!empty($conf->fournisseur->enabled) && ($object->statut >= 2 && $object->statut != 7 && $object->billed != 1)) // statut 2 means approved, 7 means canceled
2516  {
2517  if ($user->rights->fournisseur->facture->creer)
2518  {
2519  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
2520  }
2521  }
2522  //}
2523 
2524  // Classify billed manually (need one invoice if module invoice is on, no condition on invoice if not)
2525  if ($usercancreate && $object->statut >= 2 && $object->statut != 7 && $object->billed != 1) // statut 2 means approved
2526  {
2527  if (empty($conf->facture->enabled))
2528  {
2529  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
2530  } else {
2531  if (!empty($object->linkedObjectsIds['invoice_supplier']))
2532  {
2533  if ($user->rights->fournisseur->facture->creer)
2534  {
2535  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
2536  }
2537  } else {
2538  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NeedAtLeastOneInvoice")).'">'.$langs->trans("ClassifyBilled").'</a>';
2539  }
2540  }
2541  }
2542 
2543  // Create a remote order using WebService only if module is activated
2544  if (!empty($conf->syncsupplierwebservices->enabled) && $object->statut >= 2) // 2 means accepted
2545  {
2546  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=webservice&amp;mode=init">'.$langs->trans('CreateRemoteOrder').'</a>';
2547  }
2548 
2549  // Clone
2550  if ($usercancreate)
2551  {
2552  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a>';
2553  }
2554 
2555  // Cancel
2556  if ($object->statut == 2)
2557  {
2558  if ($usercanorder)
2559  {
2560  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
2561  }
2562  }
2563 
2564  // Delete
2565  if (!empty($usercandelete) || ($object->statut == CommandeFournisseur::STATUS_DRAFT && !empty($usercancreate)))
2566  {
2567  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a>';
2568  }
2569  }
2570 
2571  print "</div>";
2572 
2573 
2574 
2575  if ($usercanorder && $object->statut == CommandeFournisseur::STATUS_ACCEPTED && $action == 'makeorder')
2576  {
2577  // Set status to ordered (action=commande)
2578  print '<!-- form to record supplier order -->'."\n";
2579  print '<form name="commande" id="makeorder" action="card.php?id='.$object->id.'&amp;action=commande" method="POST">';
2580 
2581  print '<input type="hidden" name="token" value="'.newToken().'">';
2582  print '<input type="hidden" name="action" value="commande">';
2583  print load_fiche_titre($langs->trans("ToOrder"), '', '');
2584  print '<table class="noborder centpercent">';
2585  //print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("ToOrder").'</td></tr>';
2586  print '<tr><td class="fieldrequired">'.$langs->trans("OrderDate").'</td><td>';
2587  $date_com = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
2588  if (empty($date_com)) $date_com = dol_now();
2589  print $form->selectDate($date_com, '', 1, 1, '', "commande", 1, 1);
2590  print '</td></tr>';
2591 
2592  // Force mandatory order method
2593  print '<tr><td class="fieldrequired">'.$langs->trans("OrderMode").'</td><td>';
2594  $formorder->selectInputMethod(GETPOST('methodecommande'), "methodecommande", 1);
2595  print '</td></tr>';
2596 
2597  print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="40" type="text" name="comment" value="'.GETPOST('comment').'"></td></tr>';
2598  print '<tr><td class="center" colspan="2">';
2599  print '<input type="submit" name="makeorder" class="button" value="'.$langs->trans("ToOrder").'">';
2600  print ' &nbsp; &nbsp; ';
2601  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
2602  print '</td></tr>';
2603  print '</table>';
2604 
2605  print '</form>';
2606  print "<br>";
2607  }
2608 
2609  if ($action != 'makeorder')
2610  {
2611  print '<div class="fichecenter"><div class="fichehalfleft">';
2612 
2613  // Generated documents
2614  $objref = dol_sanitizeFileName($object->ref);
2615  $file = $conf->fournisseur->dir_output.'/commande/'.$objref.'/'.$objref.'.pdf';
2616  $relativepath = $objref.'/'.$objref.'.pdf';
2617  $filedir = $conf->fournisseur->dir_output.'/commande/'.$objref;
2618  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2619  $genallowed = $usercanread;
2620  $delallowed = $usercancreate;
2621 
2622  print $formfile->showdocuments('commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 0, 0, '', '', '', $object->thirdparty->default_lang);
2623  $somethingshown = $formfile->numoffiles;
2624 
2625  // Show links to link elements
2626  $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_order', 'order_supplier'));
2627  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2628 
2629  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2630 
2631  if ($action == 'classifyreception')
2632  {
2633  if ($usercanreceived && ($object->statut == CommandeFournisseur::STATUS_ORDERSENT || $object->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY))
2634  {
2635  // Set status to received (action=livraison)
2636  print '<!-- form to record purchase order received -->'."\n";
2637  print '<form id="classifyreception" action="card.php?id='.$object->id.'" method="post">';
2638  print '<input type="hidden" name="token" value="'.newToken().'">';
2639  print '<input type="hidden" name="action" value="livraison">';
2640  print load_fiche_titre($langs->trans("Receive"), '', '');
2641 
2642  print '<table class="noborder centpercent">';
2643  //print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Receive").'</td></tr>';
2644  print '<tr><td>'.$langs->trans("DeliveryDate").'</td><td>';
2645  $datepreselected = dol_now();
2646  print $form->selectDate($datepreselected, '', 1, 1, '', "commande", 1, 1);
2647  print "</td></tr>\n";
2648 
2649  print '<tr><td class="fieldrequired">'.$langs->trans("Delivery")."</td><td>\n";
2650  $liv = array();
2651  $liv[''] = '&nbsp;';
2652  $liv['tot'] = $langs->trans("CompleteOrNoMoreReceptionExpected");
2653  $liv['par'] = $langs->trans("PartialWoman");
2654  $liv['nev'] = $langs->trans("NeverReceived");
2655  $liv['can'] = $langs->trans("Canceled");
2656 
2657  print $form->selectarray("type", $liv);
2658 
2659  print '</td></tr>';
2660  print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="40" type="text" name="comment"></td></tr>';
2661  print '<tr><td class="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans("Receive").'"></td></tr>';
2662  print "</table>\n";
2663  print "</form>\n";
2664  print "<br>";
2665  }
2666  }
2667 
2668  // List of actions on element
2669  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2670  $formactions = new FormActions($db);
2671  $somethingshown = $formactions->showactions($object, 'order_supplier', $socid, 1, 'listaction'.($genallowed ? 'largetitle' : ''));
2672 
2673  print '</div></div></div>';
2674  }
2675 
2676  /*
2677  * Action webservice
2678  */
2679  if ($action == 'webservice' && GETPOST('mode', 'alpha') != "send" && !GETPOST('cancel', 'alpha'))
2680  {
2681  $mode = GETPOST('mode', 'alpha');
2682  $ws_url = $object->thirdparty->webservices_url;
2683  $ws_key = $object->thirdparty->webservices_key;
2684  $ws_user = GETPOST('ws_user', 'alpha');
2685  $ws_password = GETPOST('ws_password', 'alpha');
2686 
2687  // NS and Authentication parameters
2688  $ws_ns = 'http://www.dolibarr.org/ns/';
2689  $ws_authentication = array(
2690  'dolibarrkey'=>$ws_key,
2691  'sourceapplication'=>'DolibarrWebServiceClient',
2692  'login'=>$ws_user,
2693  'password'=>$ws_password,
2694  'entity'=>''
2695  );
2696 
2697  print load_fiche_titre($langs->trans('CreateRemoteOrder'), '');
2698 
2699  //Is everything filled?
2700  if (empty($ws_url) || empty($ws_key)) {
2701  setEventMessages($langs->trans("ErrorWebServicesFieldsRequired"), null, 'errors');
2702  $mode = "init";
2703  $error_occurred = true; //Don't allow to set the user/pass if thirdparty fields are not filled
2704  } elseif ($mode != "init" && (empty($ws_user) || empty($ws_password))) {
2705  setEventMessages($langs->trans("ErrorFieldsRequired"), null, 'errors');
2706  $mode = "init";
2707  }
2708 
2709  if ($mode == "init")
2710  {
2711  //Table/form header
2712  print '<table class="border centpercent">';
2713  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2714  print '<input type="hidden" name="token" value="'.newToken().'">';
2715  print '<input type="hidden" name="action" value="webservice">';
2716  print '<input type="hidden" name="mode" value="check">';
2717 
2718  if ($error_occurred)
2719  {
2720  print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
2721  print '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2722  } else {
2723  $textinput_size = "50";
2724  // Webservice url
2725  print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td colspan="3">'.dol_print_url($ws_url).'</td></tr>';
2726  //Remote User
2727  print '<tr><td>'.$langs->trans("User").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_user"></td></tr>';
2728  //Remote Password
2729  print '<tr><td>'.$langs->trans("Password").'</td><td><input size="'.$textinput_size.'" type="text" name="ws_password"></td></tr>';
2730  //Submit button
2731  print '<tr><td class="center" colspan="2">';
2732  print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("CreateRemoteOrder").'">';
2733  print ' &nbsp; &nbsp; ';
2734  //Cancel button
2735  print '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2736  print '</td></tr>';
2737  }
2738 
2739  //End table/form
2740  print '</form>';
2741  print '</table>';
2742  } elseif ($mode == "check")
2743  {
2744  $ws_entity = '';
2745  $ws_thirdparty = '';
2746  $error_occurred = false;
2747 
2748  //Create SOAP client and connect it to user
2749  $soapclient_user = new nusoap_client($ws_url."/webservices/server_user.php");
2750  $soapclient_user->soap_defencoding = 'UTF-8';
2751  $soapclient_user->decodeUTF8(false);
2752 
2753  //Get the thirdparty associated to user
2754  $ws_parameters = array('authentication'=>$ws_authentication, 'id' => '', 'ref'=>$ws_user);
2755  $result_user = $soapclient_user->call("getUser", $ws_parameters, $ws_ns, '');
2756  $user_status_code = $result_user["result"]["result_code"];
2757 
2758  if ($user_status_code == "OK")
2759  {
2760  //Fill the variables
2761  $ws_entity = $result_user["user"]["entity"];
2762  $ws_authentication['entity'] = $ws_entity;
2763  $ws_thirdparty = $result_user["user"]["fk_thirdparty"];
2764  if (empty($ws_thirdparty))
2765  {
2766  setEventMessages($langs->trans("RemoteUserMissingAssociatedSoc"), null, 'errors');
2767  $error_occurred = true;
2768  } else {
2769  //Create SOAP client and connect it to product/service
2770  $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
2771  $soapclient_product->soap_defencoding = 'UTF-8';
2772  $soapclient_product->decodeUTF8(false);
2773 
2774  // Iterate each line and get the reference that uses the supplier of that product/service
2775  $i = 0;
2776  foreach ($object->lines as $line) {
2777  $i = $i + 1;
2778  $ref_supplier = $line->ref_supplier;
2779  $line_id = $i."º) ".$line->product_ref.": ";
2780  if (empty($ref_supplier)) {
2781  continue;
2782  }
2783  $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $ref_supplier);
2784  $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
2785  if (!$result_product)
2786  {
2787  setEventMessages($line_id.$langs->trans("SOAPError")." ".$soapclient_product->error_str." - ".$soapclient_product->response, null, 'errors');
2788  $error_occurred = true;
2789  break;
2790  }
2791 
2792  // Check the result code
2793  $status_code = $result_product["result"]["result_code"];
2794  if (empty($status_code)) //No result, check error str
2795  {
2796  setEventMessages($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", null, 'errors');
2797  } elseif ($status_code != "OK") //Something went wrong
2798  {
2799  if ($status_code == "NOT_FOUND")
2800  {
2801  setEventMessages($line_id.$langs->trans("SupplierMissingRef")." '".$ref_supplier."'", null, 'warnings');
2802  } else {
2803  setEventMessages($line_id.$langs->trans("ResponseNonOK")." '".$status_code."' - '".$result_product["result"]["result_label"]."'", null, 'errors');
2804  $error_occurred = true;
2805  break;
2806  }
2807  }
2808 
2809 
2810  // Ensure that price is equal and warn user if it's not
2811  $supplier_price = price($result_product["product"]["price_net"]); //Price of client tab in supplier dolibarr
2812  $local_price = null; //Price of supplier as stated in product suppliers tab on this dolibarr, NULL if not found
2813 
2814  $product_fourn = new ProductFournisseur($db);
2815  $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
2816  if (count($product_fourn_list) > 0)
2817  {
2818  foreach ($product_fourn_list as $product_fourn_line)
2819  {
2820  //Only accept the line where the supplier is the same at this order and has the same ref
2821  if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
2822  $local_price = price($product_fourn_line->fourn_price);
2823  }
2824  }
2825  }
2826 
2827  if ($local_price != null && $local_price != $supplier_price) {
2828  setEventMessages($line_id.$langs->trans("RemotePriceMismatch")." ".$supplier_price." - ".$local_price, null, 'warnings');
2829  }
2830 
2831  // Check if is in sale
2832  if (empty($result_product["product"]["status_tosell"])) {
2833  setEventMessages($line_id.$langs->trans("ProductStatusNotOnSellShort")." '".$ref_supplier."'", null, 'warnings');
2834  }
2835  }
2836  }
2837  } elseif ($user_status_code == "PERMISSION_DENIED")
2838  {
2839  setEventMessages($langs->trans("RemoteUserNotPermission"), null, 'errors');
2840  $error_occurred = true;
2841  } elseif ($user_status_code == "BAD_CREDENTIALS")
2842  {
2843  setEventMessages($langs->trans("RemoteUserBadCredentials"), null, 'errors');
2844  $error_occurred = true;
2845  } else {
2846  setEventMessages($langs->trans("ResponseNonOK")." '".$user_status_code."'", null, 'errors');
2847  $error_occurred = true;
2848  }
2849 
2850  //Form
2851  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2852  print '<input type="hidden" name="token" value="'.newToken().'">';
2853  print '<input type="hidden" name="action" value="webservice">';
2854  print '<input type="hidden" name="mode" value="send">';
2855  print '<input type="hidden" name="ws_user" value="'.$ws_user.'">';
2856  print '<input type="hidden" name="ws_password" value="'.$ws_password.'">';
2857  print '<input type="hidden" name="ws_entity" value="'.$ws_entity.'">';
2858  print '<input type="hidden" name="ws_thirdparty" value="'.$ws_thirdparty.'">';
2859  if ($error_occurred)
2860  {
2861  print "<br>".$langs->trans("ErrorOccurredReviseAndRetry")."<br>";
2862  } else {
2863  print '<input class="button" type="submit" id="ws_submit" name="ws_submit" value="'.$langs->trans("Confirm").'">';
2864  print ' &nbsp; &nbsp; ';
2865  }
2866  print '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2867  print '</form>';
2868  }
2869  }
2870 
2871  // Select mail models is same action as presend
2872  if (GETPOST('modelselected')) {
2873  $action = 'presend';
2874  }
2875 
2876  // Presend form
2877  $modelmail = 'order_supplier_send';
2878  $defaulttopic = 'SendOrderRef';
2879  $diroutput = $conf->fournisseur->commande->dir_output;
2880  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO';
2881  $trackid = 'sord'.$object->id;
2882 
2883  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2884  }
2885 }
2886 
2887 // End of page
2888 llxFooter();
2889 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
const STATUS_DRAFT
Draft status.
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...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
Definition: list.php:632
Class to manage building of HTML components.
ordersupplier_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:124
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
dol_print_url($url, $target= '_blank', $max=32, $withpicto=0)
Show Url link.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller Note: This function applies same rules than get_default_tva.
Class to manage suppliers.
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...
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage HTML output components for orders Before adding component here, check they are not in...
Class to manage building of HTML components.
const STATUS_RECEIVED_PARTIALLY
Received partially.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_VALIDATED
Validated status.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_ORDERSENT
Order sent, shipment on process.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage predefined suppliers products.
Class to manage line orders.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...