PageRenderTime 85ms CodeModel.GetById 43ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/fourn/commande/fiche.php

https://github.com/abhimanyumohan/dolibarr
PHP | 2095 lines | 1571 code | 284 blank | 240 comment | 462 complexity | 987a393ff01a8bfeb4296ed01f9d35c8 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-4.0, Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. * or see http://www.gnu.org/
  24. */
  25. /**
  26. * \file htdocs/fourn/commande/fiche.php
  27. * \ingroup supplier, order
  28. * \brief Card supplier order
  29. */
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  34. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  40. if (!empty($conf->produit->enabled))
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  42. if (!empty($conf->projet->enabled))
  43. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  44. $langs->load('orders');
  45. $langs->load('sendings');
  46. $langs->load('companies');
  47. $langs->load('bills');
  48. $langs->load('propal');
  49. $langs->load('deliveries');
  50. $langs->load('products');
  51. $langs->load('stocks');
  52. $id = GETPOST('id','int');
  53. $ref = GETPOST('ref','alpha');
  54. $action = GETPOST('action','alpha');
  55. $confirm = GETPOST('confirm','alpha');
  56. $comclientid = GETPOST('comid','int');
  57. $socid = GETPOST('socid','int');
  58. $projectid = GETPOST('projectid','int');
  59. //PDF
  60. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  61. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  62. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  63. // Security check
  64. if ($user->societe_id) $socid=$user->societe_id;
  65. $result = restrictedArea($user, 'fournisseur', $id, '', 'commande');
  66. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  67. $hookmanager->initHooks(array('ordersuppliercard'));
  68. $object = new CommandeFournisseur($db);
  69. $extrafields = new ExtraFields($db);
  70. // fetch optionals attributes and labels
  71. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  72. // Load object
  73. if ($id > 0 || ! empty($ref))
  74. {
  75. $ret = $object->fetch($id, $ref);
  76. if ($ret < 0) dol_print_error($db,$object->error);
  77. $ret = $object->fetch_thirdparty();
  78. if ($ret < 0) dol_print_error($db,$object->error);
  79. }
  80. else if (! empty($socid) && $socid > 0)
  81. {
  82. $fourn = new Fournisseur($db);
  83. $ret=$fourn->fetch($socid);
  84. if ($ret < 0) dol_print_error($db,$object->error);
  85. $object->socid = $fourn->id;
  86. $ret = $object->fetch_thirdparty();
  87. if ($ret < 0) dol_print_error($db,$object->error);
  88. }
  89. $permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php
  90. /*
  91. * Actions
  92. */
  93. $parameters=array('socid'=>$socid);
  94. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  95. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
  96. if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
  97. {
  98. $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
  99. if ($result < 0) dol_print_error($db, $object->error);
  100. }
  101. // conditions de reglement
  102. if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
  103. {
  104. $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  105. }
  106. // mode de reglement
  107. else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
  108. {
  109. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
  110. }
  111. // bank account
  112. else if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer) {
  113. $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
  114. }
  115. // date de livraison
  116. if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer)
  117. {
  118. $datelivraison=dol_mktime(0, 0, 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'),GETPOST('liv_year','int'));
  119. $result=$object->set_date_livraison($user,$datelivraison);
  120. if ($result < 0)
  121. {
  122. setEventMessage($object->error, 'errors');
  123. }
  124. }
  125. // Set project
  126. else if ($action == 'classin' && $user->rights->fournisseur->commande->creer)
  127. {
  128. $object->setProject($projectid);
  129. }
  130. else if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
  131. {
  132. $result = $object->set_remise($user, $_POST['remise_percent']);
  133. }
  134. else if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
  135. {
  136. if (in_array($object->statut, array(1, 5, 6, 7, 9)))
  137. {
  138. if ($object->statut == 1) $newstatus=0; // Validated->Draft
  139. else if ($object->statut == 5) $newstatus=4; // Received->Received partially
  140. else if ($object->statut == 6) $newstatus=2; // Canceled->Approved
  141. else if ($object->statut == 7) $newstatus=3; // Canceled->Process running
  142. else if ($object->statut == 9) $newstatus=1; // Refused->Validated
  143. $result = $object->setStatus($user, $newstatus);
  144. if ($result > 0)
  145. {
  146. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  147. exit;
  148. }
  149. else
  150. {
  151. setEventMessage($object->error, 'errors');
  152. }
  153. }
  154. }
  155. /*
  156. * Add a line into product
  157. */
  158. else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
  159. {
  160. $langs->load('errors');
  161. $error = 0;
  162. // Set if we used free entry or predefined product
  163. $predef='';
  164. $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
  165. if (GETPOST('prod_entry_mode') == 'free')
  166. {
  167. $idprod=0;
  168. $price_ht = GETPOST('price_ht');
  169. $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
  170. }
  171. else
  172. {
  173. $idprod=GETPOST('idprod', 'int');
  174. $price_ht = '';
  175. $tva_tx = '';
  176. }
  177. $qty = GETPOST('qty'.$predef);
  178. $remise_percent=GETPOST('remise_percent'.$predef);
  179. if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
  180. {
  181. setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
  182. $error++;
  183. }
  184. if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('idprodfournprice') && GETPOST('type') < 0)
  185. {
  186. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
  187. $error++;
  188. }
  189. if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='') // Unit price can be 0 but not ''
  190. {
  191. setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
  192. $error++;
  193. }
  194. if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('dp_desc'))
  195. {
  196. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
  197. $error++;
  198. }
  199. if (! GETPOST('qty'))
  200. {
  201. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
  202. $error++;
  203. }
  204. // Ecrase $pu par celui du produit
  205. // Ecrase $desc par celui du produit
  206. // Ecrase $txtva par celui du produit
  207. if ((GETPOST('prod_entry_mode') != 'free') && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
  208. {
  209. $idprod=0;
  210. $productsupplier = new ProductFournisseur($db);
  211. if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') $idprod=-2; // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -1)
  212. if (GETPOST('idprodfournprice') > 0)
  213. {
  214. $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat.
  215. }
  216. if ($idprod > 0)
  217. {
  218. $res=$productsupplier->fetch($idprod);
  219. $label = $productsupplier->libelle;
  220. $desc = $productsupplier->description;
  221. if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
  222. $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
  223. $type = $productsupplier->type;
  224. // Local Taxes
  225. $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
  226. $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
  227. $result=$object->addline(
  228. $desc,
  229. $productsupplier->fourn_pu,
  230. $qty,
  231. $tva_tx,
  232. $localtax1_tx,
  233. $localtax2_tx,
  234. $productsupplier->id,
  235. GETPOST('idprodfournprice'),
  236. $productsupplier->fourn_ref,
  237. $remise_percent,
  238. 'HT',
  239. $type
  240. );
  241. }
  242. if ($idprod == -2 || $idprod == 0)
  243. {
  244. // Product not selected
  245. $error++;
  246. $langs->load("errors");
  247. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ProductOrService")), 'errors');
  248. }
  249. if ($idprod == -1)
  250. {
  251. // Quantity too low
  252. $error++;
  253. $langs->load("errors");
  254. setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors');
  255. }
  256. }
  257. else if((GETPOST('price_ht')!=='' || GETPOST('price_ttc')!=='') && empty($error))
  258. {
  259. $pu_ht = price2num($price_ht, 'MU');
  260. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  261. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  262. $tva_tx = str_replace('*', '', $tva_tx);
  263. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  264. $desc = $product_desc;
  265. $type = GETPOST('type');
  266. $tva_tx = price2num($tva_tx); // When vat is text input field
  267. // Local Taxes
  268. $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
  269. $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
  270. if (!empty($_POST['price_ht']))
  271. {
  272. $price_base_type = 'HT';
  273. $ht = price2num($_POST['price_ht']);
  274. $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type);
  275. }
  276. else
  277. {
  278. $ttc = price2num($_POST['price_ttc']);
  279. $ht = $ttc / (1 + ($tauxtva / 100));
  280. $price_base_type = 'HT';
  281. $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type);
  282. }
  283. }
  284. //print "xx".$tva_tx; exit;
  285. if (! $error && $result > 0)
  286. {
  287. $ret=$object->fetch($object->id); // Reload to get new records
  288. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  289. {
  290. // Define output language
  291. $outputlangs = $langs;
  292. $newlang=GETPOST('lang_id','alpha');
  293. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  294. if (! empty($newlang))
  295. {
  296. $outputlangs = new Translate("",$conf);
  297. $outputlangs->setDefaultLang($newlang);
  298. }
  299. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  300. }
  301. unset($_POST ['prod_entry_mode']);
  302. unset($_POST['qty']);
  303. unset($_POST['type']);
  304. unset($_POST['remise_percent']);
  305. unset($_POST['pu']);
  306. unset($_POST['price_ht']);
  307. unset($_POST['price_ttc']);
  308. unset($_POST['tva_tx']);
  309. unset($_POST['label']);
  310. unset($localtax1_tx);
  311. unset($localtax2_tx);
  312. unset($_POST['np_marginRate']);
  313. unset($_POST['np_markRate']);
  314. unset($_POST['dp_desc']);
  315. unset($_POST['idprodfournprice']);
  316. unset($_POST['date_starthour']);
  317. unset($_POST['date_startmin']);
  318. unset($_POST['date_startsec']);
  319. unset($_POST['date_startday']);
  320. unset($_POST['date_startmonth']);
  321. unset($_POST['date_startyear']);
  322. unset($_POST['date_endhour']);
  323. unset($_POST['date_endmin']);
  324. unset($_POST['date_endsec']);
  325. unset($_POST['date_endday']);
  326. unset($_POST['date_endmonth']);
  327. unset($_POST['date_endyear']);
  328. }
  329. else
  330. {
  331. setEventMessage($object->error, 'errors');
  332. }
  333. }
  334. /*
  335. * Mise a jour d'une ligne dans la commande
  336. */
  337. else if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
  338. {
  339. if ($_POST["elrowid"])
  340. {
  341. $line = new CommandeFournisseurLigne($db);
  342. $res = $line->fetch($_POST["elrowid"]);
  343. if (!$res) dol_print_error($db);
  344. }
  345. $localtax1_tx=get_localtax($_POST['tva_tx'],1,$mysoc,$object->thirdparty);
  346. $localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty);
  347. $result = $object->updateline(
  348. $_POST['elrowid'],
  349. $_POST['eldesc'],
  350. $_POST['pu'],
  351. $_POST['qty'],
  352. $_POST['remise_percent'],
  353. $_POST['tva_tx'],
  354. $localtax1_tx,
  355. $localtax2_tx,
  356. 'HT',
  357. 0,
  358. isset($_POST["type"])?$_POST["type"]:$line->product_type
  359. );
  360. unset($_POST['qty']);
  361. unset($_POST['type']);
  362. unset($_POST['idprodfournprice']);
  363. unset($_POST['remmise_percent']);
  364. unset($_POST['dp_desc']);
  365. unset($_POST['np_desc']);
  366. unset($_POST['pu']);
  367. unset($_POST['tva_tx']);
  368. unset($localtax1_tx);
  369. unset($localtax2_tx);
  370. if ($result >= 0)
  371. {
  372. $outputlangs = $langs;
  373. if (GETPOST('lang_id'))
  374. {
  375. $outputlangs = new Translate("",$conf);
  376. $outputlangs->setDefaultLang(GETPOST('lang_id'));
  377. }
  378. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  379. {
  380. $ret=$object->fetch($object->id); // Reload to get new records
  381. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  382. }
  383. }
  384. else
  385. {
  386. dol_print_error($db,$object->error);
  387. exit;
  388. }
  389. }
  390. else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
  391. {
  392. $result = $object->deleteline(GETPOST('lineid'));
  393. if ($result >= 0)
  394. {
  395. $outputlangs = $langs;
  396. if (GETPOST('lang_id'))
  397. {
  398. $outputlangs = new Translate("",$conf);
  399. $outputlangs->setDefaultLang(GETPOST('lang_id'));
  400. }
  401. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  402. {
  403. $ret=$object->fetch($object->id); // Reload to get new records
  404. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  405. }
  406. }
  407. else
  408. {
  409. $error++;
  410. setEventMessage($object->error, 'errors');
  411. }
  412. if (! $error)
  413. {
  414. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  415. exit;
  416. }
  417. }
  418. else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider)
  419. {
  420. $object->date_commande=dol_now();
  421. $result = $object->valid($user);
  422. if ($result >= 0)
  423. {
  424. $outputlangs = $langs;
  425. if (GETPOST('lang_id'))
  426. {
  427. $outputlangs = new Translate("",$conf);
  428. $outputlangs->setDefaultLang(GETPOST('lang_id'));
  429. }
  430. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  431. {
  432. $ret=$object->fetch($object->id); // Reload to get new records
  433. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  434. }
  435. }
  436. else
  437. {
  438. setEventMessage($object->error, 'errors');
  439. }
  440. // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
  441. if ($user->rights->fournisseur->commande->approuver && ! (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
  442. {
  443. $action='confirm_approve';
  444. }
  445. }
  446. else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
  447. {
  448. $idwarehouse=GETPOST('idwarehouse', 'int');
  449. $qualified_for_stock_change=0;
  450. if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
  451. {
  452. $qualified_for_stock_change=$object->hasProductsOrServices(2);
  453. }
  454. else
  455. {
  456. $qualified_for_stock_change=$object->hasProductsOrServices(1);
  457. }
  458. // Check parameters
  459. if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
  460. {
  461. if (! $idwarehouse || $idwarehouse == -1)
  462. {
  463. $error++;
  464. setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")), 'errors');
  465. $action='';
  466. }
  467. }
  468. if (! $error)
  469. {
  470. $result = $object->approve($user, $idwarehouse);
  471. if ($result > 0)
  472. {
  473. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  474. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  475. }
  476. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  477. exit;
  478. }
  479. else
  480. {
  481. setEventMessage($object->error, 'errors');
  482. }
  483. }
  484. }
  485. else if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
  486. {
  487. $result = $object->refuse($user);
  488. if ($result > 0)
  489. {
  490. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  491. exit;
  492. }
  493. else
  494. {
  495. setEventMessage($object->error, 'errors');
  496. }
  497. }
  498. else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
  499. {
  500. $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
  501. if ($result > 0)
  502. {
  503. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  504. supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  505. }
  506. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  507. exit;
  508. }
  509. else
  510. {
  511. setEventMessage($object->error, 'errors');
  512. }
  513. }
  514. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
  515. {
  516. $result=$object->delete($user);
  517. if ($result > 0)
  518. {
  519. header("Location: ".DOL_URL_ROOT.'/fourn/commande/liste.php');
  520. exit;
  521. }
  522. else
  523. {
  524. setEventMessage($object->error, 'errors');
  525. }
  526. }
  527. // Action clone object
  528. else if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
  529. {
  530. if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
  531. {
  532. setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
  533. }
  534. else
  535. {
  536. if ($object->id > 0)
  537. {
  538. $result=$object->createFromClone();
  539. if ($result > 0)
  540. {
  541. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  542. exit;
  543. }
  544. else
  545. {
  546. setEventMessage($object->error, 'errors');
  547. $action='';
  548. }
  549. }
  550. }
  551. }
  552. // Receive
  553. else if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
  554. {
  555. if ($_POST["type"])
  556. {
  557. $date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
  558. $result = $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]);
  559. if ($result > 0)
  560. {
  561. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  562. exit;
  563. }
  564. else if($result == -3)
  565. {
  566. setEventMessage($langs->trans("NotAuthorized"), 'errors');
  567. }
  568. else
  569. {
  570. dol_print_error($db,$object->error);
  571. exit;
  572. }
  573. }
  574. else
  575. {
  576. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")), 'errors');
  577. }
  578. }
  579. else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
  580. {
  581. $result = $object->cancel($user);
  582. if ($result > 0)
  583. {
  584. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  585. exit;
  586. }
  587. else
  588. {
  589. setEventMessage($object->error, 'errors');
  590. }
  591. }
  592. // Line ordering
  593. else if ($action == 'up' && $user->rights->fournisseur->commande->creer)
  594. {
  595. $object->line_up($_GET['rowid']);
  596. $outputlangs = $langs;
  597. if (! empty($_REQUEST['lang_id']))
  598. {
  599. $outputlangs = new Translate("",$conf);
  600. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  601. }
  602. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  603. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
  604. exit;
  605. }
  606. else if ($action == 'down' && $user->rights->fournisseur->commande->creer)
  607. {
  608. $object->line_down($_GET['rowid']);
  609. $outputlangs = $langs;
  610. if (! empty($_REQUEST['lang_id']))
  611. {
  612. $outputlangs = new Translate("",$conf);
  613. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  614. }
  615. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  616. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
  617. exit;
  618. }
  619. else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
  620. {
  621. // Build document
  622. // Save last template used to generate document
  623. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  624. $outputlangs = $langs;
  625. if (GETPOST('lang_id'))
  626. {
  627. $outputlangs = new Translate("",$conf);
  628. $outputlangs->setDefaultLang(GETPOST('lang_id'));
  629. }
  630. $result=supplier_order_pdf_create($db, $object,$object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref);
  631. if ($result <= 0)
  632. {
  633. dol_print_error($db,$result);
  634. exit;
  635. }
  636. }
  637. // Delete file in doc form
  638. else if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer)
  639. {
  640. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  641. $langs->load("other");
  642. $upload_dir = $conf->fournisseur->commande->dir_output;
  643. $file = $upload_dir . '/' . GETPOST('file');
  644. $ret=dol_delete_file($file,0,0,0,$object);
  645. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  646. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  647. }
  648. elseif ($action == 'update_extras')
  649. {
  650. // Fill array 'array_options' with data from add form
  651. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  652. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  653. if($ret < 0) $error++;
  654. if (!$error)
  655. {
  656. // Actions on extra fields (by external module or standard code)
  657. // FIXME le hook fait double emploi avec le trigger !!
  658. $hookmanager->initHooks(array('supplierorderdao'));
  659. $parameters=array('id'=>$object->id);
  660. $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  661. if (empty($reshook))
  662. {
  663. if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
  664. {
  665. $result=$object->insertExtraFields();
  666. if ($result < 0)
  667. {
  668. $error++;
  669. }
  670. }
  671. }
  672. else if ($reshook < 0) $error++;
  673. }
  674. else
  675. {
  676. $action = 'edit_extras';
  677. }
  678. }
  679. /*
  680. * Create an order
  681. */
  682. else if ($action == 'add' && $user->rights->fournisseur->commande->creer)
  683. {
  684. $error=0;
  685. if ($socid <1)
  686. {
  687. setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('Supplier')), 'errors');
  688. $action='create';
  689. $error++;
  690. }
  691. if (! $error)
  692. {
  693. $db->begin();
  694. // Creation commande
  695. $object->ref_supplier = GETPOST('refsupplier');
  696. $object->socid = $socid;
  697. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  698. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  699. $object->fk_account = GETPOST('fk_account', 'int');
  700. $object->note_private = GETPOST('note_private');
  701. $object->note_public = GETPOST('note_public');
  702. // Fill array 'array_options' with data from add form
  703. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  704. $id = $object->create($user);
  705. if ($id < 0)
  706. {
  707. $error++;
  708. }
  709. if ($error)
  710. {
  711. $langs->load("errors");
  712. $db->rollback();
  713. setEventMessage($langs->trans($object->error), 'errors');
  714. $action='create';
  715. $_GET['socid']=$_POST['socid'];
  716. }
  717. else
  718. {
  719. $db->commit();
  720. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  721. exit;
  722. }
  723. }
  724. }
  725. /*
  726. * Add file in email form
  727. */
  728. if (GETPOST('addfile'))
  729. {
  730. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  731. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  732. $vardir=$conf->user->dir_output."/".$user->id;
  733. $upload_dir_tmp = $vardir.'/temp';
  734. dol_add_file_process($upload_dir_tmp,0,0);
  735. $action='presend';
  736. }
  737. /*
  738. * Remove file in email form
  739. */
  740. if (GETPOST('removedfile'))
  741. {
  742. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  743. // Set tmp user directory
  744. $vardir=$conf->user->dir_output."/".$user->id;
  745. $upload_dir_tmp = $vardir.'/temp';
  746. // TODO Delete only files that was uploaded from email form
  747. dol_remove_file_process($_POST['removedfile'],0);
  748. $action='presend';
  749. }
  750. /*
  751. * Send mail
  752. */
  753. if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
  754. {
  755. $langs->load('mails');
  756. if ($object->id > 0)
  757. {
  758. // $ref = dol_sanitizeFileName($object->ref);
  759. // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
  760. // if (is_readable($file))
  761. // {
  762. if (GETPOST('sendto','alpha'))
  763. {
  764. // Le destinataire a ete fourni via le champ libre
  765. $sendto = GETPOST('sendto','alpha');
  766. $sendtoid = 0;
  767. }
  768. elseif (GETPOST('receiver','alpha') != '-1')
  769. {
  770. // Recipient was provided from combo list
  771. if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
  772. {
  773. $sendto = $object->client->email;
  774. $sendtoid = 0;
  775. }
  776. else // Id du contact
  777. {
  778. $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
  779. $sendtoid = GETPOST('receiver','alpha');
  780. }
  781. }
  782. if (dol_strlen($sendto))
  783. {
  784. $langs->load("commercial");
  785. $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
  786. $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
  787. $message = GETPOST('message');
  788. $sendtocc = GETPOST('sendtocc','alpha');
  789. $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
  790. if ($action == 'send')
  791. {
  792. if (dol_strlen(GETPOST('subject'))) $subject=GETPOST('subject');
  793. else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
  794. $actiontypecode='AC_SUP_ORD';
  795. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  796. if ($message)
  797. {
  798. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  799. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  800. $actionmsg.=$message;
  801. }
  802. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  803. }
  804. // Create form object
  805. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  806. $formmail = new FormMail($db);
  807. $attachedfiles=$formmail->get_attached_files();
  808. $filepath = $attachedfiles['paths'];
  809. $filename = $attachedfiles['names'];
  810. $mimetype = $attachedfiles['mimes'];
  811. // Send mail
  812. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  813. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
  814. if ($mailfile->error)
  815. {
  816. setEventMessage($mailfile->error, 'errors');
  817. }
  818. else
  819. {
  820. $result=$mailfile->sendfile();
  821. if ($result)
  822. {
  823. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
  824. setEventMessage($mesg);
  825. $error=0;
  826. // Initialisation donnees
  827. $object->sendtoid = $sendtoid;
  828. $object->actiontypecode = $actiontypecode;
  829. $object->actionmsg = $actionmsg;
  830. $object->actionmsg2 = $actionmsg2;
  831. $object->fk_element = $object->id;
  832. $object->elementtype = $object->element;
  833. // Appel des triggers
  834. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  835. $interface=new Interfaces($db);
  836. $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
  837. if ($result < 0) { $error++; $errors=$interface->errors; }
  838. // Fin appel triggers
  839. if ($error)
  840. {
  841. setEventMessage($object->error, 'errors');
  842. }
  843. else
  844. {
  845. // Redirect here
  846. // This avoid sending mail twice if going out and then back to page
  847. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  848. exit;
  849. }
  850. }
  851. else
  852. {
  853. $langs->load("other");
  854. if ($mailfile->error)
  855. {
  856. $mesg = $langs->trans('ErrorFailedToSendMail',$from,$sendto);
  857. $mesg.= '<br>'.$mailfile->error;
  858. }
  859. else
  860. {
  861. $mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  862. }
  863. setEventMessage($mesg, 'errors');
  864. }
  865. }
  866. /* }
  867. else
  868. {
  869. $langs->load("other");
  870. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  871. $action='presend';
  872. dol_syslog('Recipient email is empty');
  873. }*/
  874. }
  875. else
  876. {
  877. $langs->load("errors");
  878. setEventMessage($langs->trans('ErrorCantReadFile',$file), 'errors');
  879. dol_syslog('Failed to read file: '.$file);
  880. }
  881. }
  882. else
  883. {
  884. $langs->load("other");
  885. setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors');
  886. dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
  887. }
  888. }
  889. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer)
  890. {
  891. if ($action == 'addcontact')
  892. {
  893. if ($object->id > 0)
  894. {
  895. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  896. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  897. }
  898. if ($result >= 0)
  899. {
  900. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  901. exit;
  902. }
  903. else
  904. {
  905. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  906. {
  907. $langs->load("errors");
  908. setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
  909. }
  910. else
  911. {
  912. setEventMessage($object->error, 'errors');
  913. }
  914. }
  915. }
  916. // bascule du statut d'un contact
  917. else if ($action == 'swapstatut' && $object->id > 0)
  918. {
  919. $result=$object->swapContactStatus(GETPOST('ligne'));
  920. }
  921. // Efface un contact
  922. else if ($action == 'deletecontact' && $object->id > 0)
  923. {
  924. $result = $object->delete_contact($_GET["lineid"]);
  925. if ($result >= 0)
  926. {
  927. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  928. exit;
  929. }
  930. else {
  931. dol_print_error($db);
  932. }
  933. }
  934. }
  935. /*
  936. * View
  937. */
  938. llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur");
  939. $form = new Form($db);
  940. $formfile = new FormFile($db);
  941. $formorder = new FormOrder($db);
  942. $productstatic = new Product($db);
  943. /* *************************************************************************** */
  944. /* */
  945. /* Mode vue et edition */
  946. /* */
  947. /* *************************************************************************** */
  948. $now=dol_now();
  949. if ($action=="create")
  950. {
  951. print_fiche_titre($langs->trans('NewOrder'));
  952. dol_htmloutput_events();
  953. $societe='';
  954. if ($socid>0)
  955. {
  956. $societe=new Societe($db);
  957. $societe->fetch($socid);
  958. }
  959. $cond_reglement_id = $societe->cond_reglement_supplier_id;
  960. $mode_reglement_id = $societe->mode_reglement_supplier_id;
  961. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  962. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  963. print '<input type="hidden" name="action" value="add">';
  964. print '<table class="border" width="100%">';
  965. // Ref
  966. print '<tr><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
  967. // Third party
  968. print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
  969. print '<td>';
  970. if ($socid > 0)
  971. {
  972. print $societe->getNomUrl(1);
  973. print '<input type="hidden" name="socid" value="'.$socid.'">';
  974. }
  975. else
  976. {
  977. print $form->select_company((empty($socid)?'':$socid),'socid','s.fournisseur = 1',1);
  978. }
  979. print '</td>';
  980. // Ref supplier
  981. print '<tr><td>'.$langs->trans('RefSupplier').'</td><td><input name="refsupplier" type="text"></td>';
  982. print '</tr>';
  983. print '</td></tr>';
  984. // Payment term
  985. print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
  986. $form->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
  987. print '</td></tr>';
  988. // Payment mode
  989. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
  990. $form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
  991. print '</td></tr>';
  992. // Bank Account
  993. print '<tr><td>' . $langs->trans('BankAccount') . '</td><td colspan="2">';
  994. $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
  995. print '</td></tr>';
  996. print '<tr><td>'.$langs->trans('NotePublic').'</td>';
  997. print '<td>';
  998. $doleditor = new DolEditor('note_public', GETPOST('note_public'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  999. print $doleditor->Create(1);
  1000. print '</td>';
  1001. //print '<textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea>';
  1002. print '</tr>';
  1003. print '<tr><td>'.$langs->trans('NotePrivate').'</td>';
  1004. print '<td>';
  1005. $doleditor = new DolEditor('note_private', GETPOST('note_private'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  1006. print $doleditor->Create(1);
  1007. print '</td>';
  1008. //print '<td><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
  1009. print '</tr>';
  1010. // Other options
  1011. $parameters=array();
  1012. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1013. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1014. {
  1015. print $object->showOptionals($extrafields,'edit');
  1016. }
  1017. // Bouton "Create Draft"
  1018. print "</table>\n";
  1019. print '<br><center><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'"></center>';
  1020. print "</form>\n";
  1021. }
  1022. elseif (! empty($object->id))
  1023. {
  1024. $author = new User($db);
  1025. $author->fetch($object->user_author_id);
  1026. $societe = new Fournisseur($db);
  1027. $result=$societe->fetch($object->socid);
  1028. if ($result < 0) dol_print_error($db);
  1029. $head = ordersupplier_prepare_head($object);
  1030. $title=$langs->trans("SupplierOrder");
  1031. dol_fiche_head($head, 'card', $title, 0, 'order');
  1032. $res=$object->fetch_optionals($object->id,$extralabels);
  1033. /*
  1034. * Confirmation de la suppression de la commande
  1035. */
  1036. if ($action == 'delete')
  1037. {
  1038. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
  1039. }
  1040. // Clone confirmation
  1041. if ($action == 'clone')
  1042. {
  1043. // Create an array for form
  1044. $formquestion=array(
  1045. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1)
  1046. );
  1047. // Paiement incomplet. On demande si motif = escompte ou autre
  1048. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
  1049. }
  1050. /*
  1051. * Confirmation de la validation
  1052. */
  1053. if ($action == 'valid')
  1054. {
  1055. $object->date_commande=dol_now();
  1056. // We check if number is temporary number
  1057. if (preg_match('/^[\(]?PROV/i',$object->ref)) $newref = $object->getNextNumRef($object->thirdparty);
  1058. else $newref = $object->ref;
  1059. $text=$langs->trans('ConfirmValidateOrder',$newref);
  1060. if (! empty($conf->notification->enabled))
  1061. {
  1062. require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
  1063. $notify=new Notify($db);
  1064. $text.='<br>';
  1065. $text.=$notify->confirmMessage('ORDER_SUPPLIER_APPROVE', $object->socid);
  1066. }
  1067. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
  1068. }
  1069. /*
  1070. * Confirmation de l'approbation
  1071. */
  1072. if ($action == 'approve')
  1073. {
  1074. $qualified_for_stock_change=0;
  1075. if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1076. {
  1077. $qualified_for_stock_change=$object->hasProductsOrServices(2);
  1078. }
  1079. else
  1080. {
  1081. $qualified_for_stock_change=$object->hasProductsOrServices(1);
  1082. }
  1083. $formquestion=array();
  1084. if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
  1085. {
  1086. $langs->load("stocks");
  1087. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  1088. $formproduct=new FormProduct($db);
  1089. $formquestion=array(
  1090. //'text' => $langs->trans("ConfirmClone"),
  1091. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1092. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  1093. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))
  1094. );
  1095. }
  1096. print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
  1097. }
  1098. /*
  1099. * Confirmation de la desapprobation
  1100. */
  1101. if ($action == 'refuse')
  1102. {
  1103. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
  1104. }
  1105. /*
  1106. * Confirmation de l'annulation
  1107. */
  1108. if ($action == 'cancel')
  1109. {
  1110. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
  1111. }
  1112. /*
  1113. * Confirmation de l'envoi de la commande
  1114. */
  1115. if ($action == 'commande')
  1116. {
  1117. $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
  1118. print $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);
  1119. }
  1120. /*
  1121. * Confirmation de la suppression d'une ligne produit
  1122. */
  1123. if ($action == 'delete_product_line')
  1124. {
  1125. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2);
  1126. }
  1127. /*
  1128. * Commande
  1129. */
  1130. $nbrow=8;
  1131. if (! empty($conf->projet->enabled)) $nbrow++;
  1132. //Local taxes
  1133. if($mysoc->localtax1_assuj=="1") $nbrow++;
  1134. if($mysoc->localtax2_assuj=="1") $nbrow++;
  1135. print '<table class="border" width="100%">';
  1136. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1137. // Ref
  1138. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  1139. print '<td colspan="2">';
  1140. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  1141. print '</td>';
  1142. print '</tr>';
  1143. // Ref supplier
  1144. print '<tr><td>';
  1145. print $form->editfieldkey("RefSupplier",'ref_supplier',$object->ref_supplier,$object,$user->rights->fournisseur->commande->creer);
  1146. print '</td><td colspan="2">';
  1147. print $form->editfieldval("RefSupplier",'ref_supplier',$object->ref_supplier,$object,$user->rights->fournisseur->commande->creer);
  1148. print '</td></tr>';
  1149. // Fournisseur
  1150. print '<tr><td>'.$langs->trans("Supplier")."</td>";
  1151. print '<td colspan="2">'.$object->thirdparty->getNomUrl(1,'supplier').'</td>';
  1152. print '</tr>';
  1153. // Statut
  1154. print '<tr>';
  1155. print '<td>'.$langs->trans("Status").'</td>';
  1156. print '<td colspan="2">';
  1157. print $object->getLibStatut(4);
  1158. print "</td></tr>";
  1159. // Date
  1160. if ($object->methode_commande_id > 0)
  1161. {
  1162. print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">';
  1163. if ($object->date_commande)
  1164. {
  1165. print dol_print_date($object->date_commande,"dayhourtext")."\n";
  1166. }
  1167. print "</td></tr>";
  1168. if ($object->methode_commande)
  1169. {
  1170. print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$object->getInputMethod().'</td></tr>';
  1171. }
  1172. }
  1173. // Author
  1174. print '<tr><td>'.$langs->trans("AuthorRequest").'</td>';
  1175. print '<td colspan="2">'.$author->getNomUrl(1).'</td>';
  1176. print '</tr>';
  1177. // Conditions de reglement par defaut
  1178. $langs->load('bills');
  1179. print '<tr><td class="nowrap">';
  1180. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1181. print $langs->trans('PaymentConditions');
  1182. print '<td>';
  1183. if ($action != 'editconditions') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
  1184. print '</tr></table>';
  1185. print '</td><td colspan="2">';
  1186. if ($action == 'editconditions')
  1187. {
  1188. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'cond_reglement_id');
  1189. }
  1190. else
  1191. {
  1192. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none');
  1193. }
  1194. print "</td>";
  1195. print '</tr>';
  1196. // Mode of payment
  1197. $langs->load('bills');
  1198. print '<tr><td class="nowrap">';
  1199. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1200. print $langs->trans('PaymentMode');
  1201. print '</td>';
  1202. if ($action != 'editmode') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  1203. print '</tr></table>';
  1204. print '</td><td colspan="2">';
  1205. if ($action == 'editmode')
  1206. {
  1207. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
  1208. }
  1209. else
  1210. {
  1211. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
  1212. }
  1213. print '</td></tr>';
  1214. // Bank Account
  1215. print '<tr><td class="nowrap">';
  1216. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1217. print $langs->trans('BankAccount');
  1218. print '<td>';
  1219. if ($action != 'editbankaccount' && $user->rights->fournisseur->commande->creer)
  1220. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  1221. print '</tr></table>';
  1222. print '</td><td colspan="3">';
  1223. if ($action == 'editbankaccount') {
  1224. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  1225. } else {
  1226. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  1227. }
  1228. print '</td>';
  1229. print '</tr>';
  1230. // Delivery date planed
  1231. print '<tr><td height="10">';
  1232. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1233. print $langs->trans('DateDeliveryPlanned');
  1234. print '</td>';
  1235. if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
  1236. print '</tr></table>';
  1237. print '</td><td colspan="2">';
  1238. if ($action == 'editdate_livraison')
  1239. {
  1240. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1241. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1242. print '<input type="hidden" name="action" value="setdate_livraison">';
  1243. $form->select_date($object->date_livraison?$object->date_livraison:-1,'liv_','','','',"setdate_livraison");
  1244. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1245. print '</form>';
  1246. }
  1247. else
  1248. {
  1249. print $object->date_livraison ? dol_print_date($object->date_livraison,'daytext') : '&nbsp;';
  1250. }
  1251. print '</td>';
  1252. // Project
  1253. if (! empty($conf->projet->enabled))
  1254. {
  1255. $langs->load('projects');
  1256. print '<tr><td height="10">';
  1257. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1258. print $langs->trans('Project');
  1259. print '</td>';
  1260. if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
  1261. print '</tr></table>';
  1262. print '</td><td colspan="2">';
  1263. //print "$object->id, $object->socid, $object->fk_project";
  1264. if ($action == 'classify')
  1265. {
  1266. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1', $object->fk_project, 'projectid');
  1267. }
  1268. else
  1269. {
  1270. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
  1271. }
  1272. print '</td>';
  1273. print '</tr>';
  1274. }
  1275. // Other attributes
  1276. $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
  1277. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1278. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1279. {
  1280. if ($action == 'edit_extras')
  1281. {
  1282. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
  1283. print '<input type="hidden" name="action" value="update_extras">';
  1284. print '<input type="hidden" name="token" value="'.$_SESSION['n…

Large files files are truncated, but you can click here to view the full file