PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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['newtoken'].'">';
  1285. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1286. }
  1287. foreach($extrafields->attribute_label as $key=>$label)
  1288. {
  1289. if ($action == 'edit_extras') {
  1290. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
  1291. } else {
  1292. $value=$object->array_options["options_".$key];
  1293. }
  1294. if ($extrafields->attribute_type[$key] == 'separate')
  1295. {
  1296. print $extrafields->showSeparator($key);
  1297. }
  1298. else
  1299. {
  1300. print '<tr><td';
  1301. if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
  1302. print '>'.$label.'</td><td colspan="5">';
  1303. // Convert date into timestamp format
  1304. if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
  1305. {
  1306. $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]);
  1307. }
  1308. if ($action == 'edit_extras' && $user->rights->fournisseur->commande->creer)
  1309. {
  1310. print $extrafields->showInputField($key,$value);
  1311. }
  1312. else
  1313. {
  1314. print $extrafields->showOutputField($key,$value);
  1315. }
  1316. print '</td></tr>'."\n";
  1317. }
  1318. }
  1319. if(count($extrafields->attribute_label) > 0)
  1320. {
  1321. if ($action == 'edit_extras' && $user->rights->fournisseur->commande->creer)
  1322. {
  1323. print '<tr><td></td><td colspan="5">';
  1324. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1325. print '</form>';
  1326. print '</td></tr>';
  1327. }
  1328. else
  1329. {
  1330. if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
  1331. {
  1332. print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
  1333. }
  1334. }
  1335. }
  1336. }
  1337. // Ligne de 3 colonnes
  1338. print '<tr><td>'.$langs->trans("AmountHT").'</td>';
  1339. print '<td align="right"><b>'.price($object->total_ht).'</b></td>';
  1340. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1341. print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($object->total_tva).'</td>';
  1342. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1343. // Amount Local Taxes
  1344. if ($mysoc->localtax1_assuj=="1" || $object->total_localtax1 != 0) //Localtax1
  1345. {
  1346. print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
  1347. print '<td align="right">'.price($object->total_localtax1).'</td>';
  1348. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1349. }
  1350. if ($mysoc->localtax2_assuj=="1" || $object->total_localtax2 != 0) //Localtax2
  1351. {
  1352. print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
  1353. print '<td align="right">'.price($object->total_localtax2).'</td>';
  1354. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1355. }
  1356. print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right">'.price($object->total_ttc).'</td>';
  1357. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1358. print "</table><br>";
  1359. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  1360. {
  1361. $blocname = 'contacts';
  1362. $title = $langs->trans('ContactsAddresses');
  1363. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1364. }
  1365. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1366. {
  1367. $blocname = 'notes';
  1368. $title = $langs->trans('Notes');
  1369. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1370. }
  1371. /*
  1372. * Lines
  1373. */
  1374. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?etat=1&id='.$object->id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST">
  1375. <input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">
  1376. <input type="hidden" name="action" value="'.(($action != 'edit_line')?'addline':'update_line').'">
  1377. <input type="hidden" name="mode" value="">
  1378. <input type="hidden" name="id" value="'.$object->id.'">
  1379. <input type="hidden" name="facid" value="'.$object->id.'">
  1380. <input type="hidden" name="socid" value="'.$societe->id.'">
  1381. ';
  1382. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  1383. $num = count($object->lines);
  1384. $i = 0; $total = 0;
  1385. if ($num)
  1386. {
  1387. print '<tr class="liste_titre">';
  1388. print '<td>'.$langs->trans('Label').'</td>';
  1389. print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
  1390. print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
  1391. print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
  1392. print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
  1393. print '<td align="right" width="50">'.$langs->trans('TotalHTShort').'</td>';
  1394. print '<td width="48" colspan="3">&nbsp;</td>';
  1395. print "</tr>\n";
  1396. }
  1397. $var=true;
  1398. while ($i < $num)
  1399. {
  1400. $line = $object->lines[$i];
  1401. $var=!$var;
  1402. // Show product and description
  1403. $type=(! empty($line->product_type)?$line->product_type:(! empty($line->fk_product_type)?$line->fk_product_type:0));
  1404. // Try to enhance type detection using date_start and date_end for free lines where type
  1405. // was not saved.
  1406. $date_start='';
  1407. $date_end='';
  1408. if (! empty($line->date_start))
  1409. {
  1410. $date_start=$line->date_start;
  1411. $type=1;
  1412. }
  1413. if (! empty($line->date_end))
  1414. {
  1415. $date_end=$line->date_end;
  1416. $type=1;
  1417. }
  1418. // Edit line
  1419. if ($action != 'edit_line' || $_GET['rowid'] != $line->id)
  1420. {
  1421. print '<tr id="row-'.$line->id.'" '.$bc[$var].'>';
  1422. // Show product and description
  1423. print '<td>';
  1424. if ($line->fk_product > 0)
  1425. {
  1426. print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
  1427. $product_static=new ProductFournisseur($db);
  1428. $product_static->fetch($line->fk_product);
  1429. $text=$product_static->getNomUrl(1,'supplier');
  1430. $text.= ' - '.$product_static->libelle;
  1431. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
  1432. print $form->textwithtooltip($text,$description,3,'','',$i);
  1433. // Show range
  1434. print_date_range($date_start,$date_end);
  1435. // Add description in form
  1436. if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print ($line->description && $line->description!=$product_static->libelle)?'<br>'.dol_htmlentitiesbr($line->description):'';
  1437. }
  1438. // Description - Editor wysiwyg
  1439. if (! $line->fk_product)
  1440. {
  1441. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  1442. else $text = img_object($langs->trans('Product'),'product');
  1443. print $text.' '.nl2br($line->description);
  1444. // Show range
  1445. print_date_range($date_start,$date_end);
  1446. }
  1447. print '</td>';
  1448. print '<td align="right" class="nowrap">'.vatrate($line->tva_tx).'%</td>';
  1449. print '<td align="right" class="nowrap">'.price($line->subprice)."</td>\n";
  1450. print '<td align="right" class="nowrap">'.$line->qty.'</td>';
  1451. if ($line->remise_percent > 0)
  1452. {
  1453. print '<td align="right" class="nowrap">'.dol_print_reduction($line->remise_percent,$langs)."</td>\n";
  1454. }
  1455. else
  1456. {
  1457. print '<td>&nbsp;</td>';
  1458. }
  1459. print '<td align="right" class="nowrap">'.price($line->total_ht).'</td>';
  1460. if (is_object($hookmanager))
  1461. {
  1462. $parameters=array('line'=>$line,'num'=>$num,'i'=>$i);
  1463. $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action);
  1464. }
  1465. if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
  1466. {
  1467. print '<td align="center" width="16"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit_line&amp;rowid='.$line->id.'#'.$line->id.'">';
  1468. print img_edit();
  1469. print '</a></td>';
  1470. $actiondelete='delete_product_line';
  1471. print '<td align="center" width="16"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$actiondelete.'&amp;lineid='.$line->id.'">';
  1472. print img_delete();
  1473. print '</a></td>';
  1474. }
  1475. else
  1476. {
  1477. print '<td>&nbsp;</td><td>&nbsp;</td>';
  1478. }
  1479. print "</tr>";
  1480. }
  1481. // Edit line
  1482. if ($action == 'edit_line' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id))
  1483. {
  1484. print "\n";
  1485. print '<tr '.$bc[$var].'>';
  1486. print '<td>';
  1487. print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">';
  1488. print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
  1489. if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $line->fk_product > 0)
  1490. {
  1491. $product_static=new ProductFournisseur($db);
  1492. $product_static->fetch($line->fk_product);
  1493. $text=$product_static->getNomUrl(1,'supplier');
  1494. $text.= ' - '.$product_static->libelle;
  1495. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
  1496. print $form->textwithtooltip($text,$description,3,'','',$i);
  1497. // Show range
  1498. print_date_range($date_start,$date_end);
  1499. print '<br>';
  1500. }
  1501. else
  1502. {
  1503. $forceall=1; // For suppliers, we always show all types
  1504. print $form->select_type_of_lines($line->product_type,'type',1,0,$forceall);
  1505. if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled))
  1506. || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '<br>';
  1507. }
  1508. if (is_object($hookmanager))
  1509. {
  1510. $parameters=array('fk_parent_line'=>$line->fk_parent_line, 'line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i);
  1511. $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$object,$action);
  1512. }
  1513. $nbrows=ROWS_2;
  1514. if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
  1515. $doleditor=new DolEditor('eldesc',$line->description,'',200,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
  1516. $doleditor->Create();
  1517. print '</td>';
  1518. print '<td>';
  1519. print $form->load_tva('tva_tx',$line->tva_tx,$object->thirdparty,$mysoc);
  1520. print '</td>';
  1521. print '<td align="right"><input size="5" type="text" name="pu" value="'.price($line->subprice).'"></td>';
  1522. print '<td align="right"><input size="2" type="text" name="qty" value="'.$line->qty.'"></td>';
  1523. print '<td align="right" class="nowrap"><input size="1" type="text" name="remise_percent" value="'.$line->remise_percent.'"><span class="hideonsmartphone">%</span></td>';
  1524. print '<td align="center" colspan="4"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  1525. print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>';
  1526. print '</tr>' . "\n";
  1527. }
  1528. $i++;
  1529. }
  1530. // Form to add new line
  1531. if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action != 'edit_line')
  1532. {
  1533. // Add free products/services form
  1534. global $forceall, $senderissupplier, $dateSelector;
  1535. $forceall=1; $senderissupplier=1; $dateSelector=0;
  1536. $var = true;
  1537. // Add free products/services
  1538. $object->formAddObjectLine(1, $societe, $mysoc);
  1539. $parameters = array();
  1540. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1541. }
  1542. print '</table>';
  1543. print '</form>';
  1544. dol_fiche_end();
  1545. if ($action != 'presend')
  1546. {
  1547. /**
  1548. * Boutons actions
  1549. */
  1550. if ($user->societe_id == 0 && $action != 'edit_line' && $action != 'delete')
  1551. {
  1552. print '<div class="tabsAction">';
  1553. // Validate
  1554. if ($object->statut == 0 && $num > 0)
  1555. {
  1556. if ($user->rights->fournisseur->commande->valider)
  1557. {
  1558. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"';
  1559. print '>'.$langs->trans('Validate').'</a>';
  1560. }
  1561. }
  1562. // Modify
  1563. if ($object->statut == 1)
  1564. {
  1565. if ($user->rights->fournisseur->commande->commander)
  1566. {
  1567. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("Modify").'</a>';
  1568. }
  1569. }
  1570. // Approve
  1571. if ($object->statut == 1)
  1572. {
  1573. if ($user->rights->fournisseur->commande->approuver)
  1574. {
  1575. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=approve">'.$langs->trans("ApproveOrder").'</a>';
  1576. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=refuse">'.$langs->trans("RefuseOrder").'</a>';
  1577. }
  1578. else
  1579. {
  1580. print '<a class="butActionRefused" href="#">'.$langs->trans("ApproveOrder").'</a>';
  1581. print '<a class="butActionRefused" href="#">'.$langs->trans("RefuseOrder").'</a>';
  1582. }
  1583. }
  1584. // Send
  1585. if (in_array($object->statut, array(2, 3, 4, 5)))
  1586. {
  1587. if ($user->rights->fournisseur->commande->commander)
  1588. {
  1589. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
  1590. }
  1591. }
  1592. // Reopen
  1593. if (in_array($object->statut, array(5, 6, 7, 9)))
  1594. {
  1595. if ($user->rights->fournisseur->commande->commander)
  1596. {
  1597. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  1598. }
  1599. }
  1600. // Create bill
  1601. if (! empty($conf->fournisseur->enabled) && $object->statut >= 2) // 2 means accepted
  1602. {
  1603. if ($user->rights->fournisseur->facture->creer)
  1604. {
  1605. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  1606. }
  1607. //if ($user->rights->fournisseur->commande->creer && $object->statut > 2)
  1608. //{
  1609. // print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
  1610. //}
  1611. }
  1612. // Cancel
  1613. if ($object->statut == 2)
  1614. {
  1615. if ($user->rights->fournisseur->commande->commander)
  1616. {
  1617. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans("CancelOrder").'</a>';
  1618. }
  1619. }
  1620. // Clone
  1621. if ($user->rights->fournisseur->commande->creer)
  1622. {
  1623. 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>';
  1624. }
  1625. // Delete
  1626. if ($user->rights->fournisseur->commande->supprimer)
  1627. {
  1628. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  1629. }
  1630. print "</div>";
  1631. }
  1632. print "<br>";
  1633. print '<div class="fichecenter"><div class="fichehalfleft">';
  1634. /*
  1635. * Documents generes
  1636. */
  1637. $comfournref = dol_sanitizeFileName($object->ref);
  1638. $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf';
  1639. $relativepath = $comfournref.'/'.$comfournref.'.pdf';
  1640. $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref;
  1641. $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
  1642. $genallowed=$user->rights->fournisseur->commande->creer;
  1643. $delallowed=$user->rights->fournisseur->commande->supprimer;
  1644. print $formfile->showdocuments('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,0,0,'','','',$object->thirdparty->default_lang);
  1645. $somethingshown=$formfile->numoffiles;
  1646. /*
  1647. * Linked object block
  1648. */
  1649. $somethingshown=$object->showLinkedObjectBlock();
  1650. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  1651. // List of actions on element
  1652. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1653. $formactions=new FormActions($db);
  1654. $somethingshown=$formactions->showactions($object,'order_supplier',$socid);
  1655. if ($user->rights->fournisseur->commande->commander && $object->statut == 2)
  1656. {
  1657. /*
  1658. * Commander (action=commande)
  1659. */
  1660. print '<br>';
  1661. print '<form name="commande" action="fiche.php?id='.$object->id.'&amp;action=commande" method="post">';
  1662. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1663. print '<input type="hidden" name="action" value="commande">';
  1664. print '<table class="border" width="100%">';
  1665. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("ToOrder").'</td></tr>';
  1666. print '<tr><td>'.$langs->trans("OrderDate").'</td><td>';
  1667. $date_com = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  1668. print $form->select_date($date_com,'','','','',"commande");
  1669. print '</td></tr>';
  1670. print '<tr><td>'.$langs->trans("OrderMode").'</td><td>';
  1671. $formorder->selectInputMethod(GETPOST('methodecommande'), "methodecommande", 1);
  1672. print '</td></tr>';
  1673. print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="40" type="text" name="comment" value="'.GETPOST('comment').'"></td></tr>';
  1674. print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans("ToOrder").'"></td></tr>';
  1675. print '</table>';
  1676. print '</form>';
  1677. }
  1678. if ($user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4))
  1679. {
  1680. /*
  1681. * Receptionner (action=livraison)
  1682. */
  1683. print '<br>';
  1684. print '<form action="fiche.php?id='.$object->id.'" method="post">';
  1685. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1686. print '<input type="hidden" name="action" value="livraison">';
  1687. print '<table class="border" width="100%">';
  1688. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Receive").'</td></tr>';
  1689. print '<tr><td>'.$langs->trans("DeliveryDate").'</td><td>';
  1690. print $form->select_date('','','','','',"commande");
  1691. print "</td></tr>\n";
  1692. print "<tr><td>".$langs->trans("Delivery")."</td><td>\n";
  1693. $liv = array();
  1694. $liv[''] = '&nbsp;';
  1695. $liv['tot'] = $langs->trans("TotalWoman");
  1696. $liv['par'] = $langs->trans("PartialWoman");
  1697. $liv['nev'] = $langs->trans("NeverReceived");
  1698. $liv['can'] = $langs->trans("Canceled");
  1699. print $form->selectarray("type",$liv);
  1700. print '</td></tr>';
  1701. print '<tr><td>'.$langs->trans("Comment").'</td><td><input size="40" type="text" name="comment"></td></tr>';
  1702. print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans("Receive").'"></td></tr>';
  1703. print "</table>\n";
  1704. print "</form>\n";
  1705. }
  1706. // List of actions on element
  1707. /* Hidden because" available into "Log" tab
  1708. print '<br>';
  1709. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1710. $formactions=new FormActions($db);
  1711. $somethingshown=$formactions->showactions($object,'order_supplier',$socid);
  1712. */
  1713. print '</div></div></div>';
  1714. }
  1715. /*
  1716. * Action presend
  1717. */
  1718. if ($action == 'presend')
  1719. {
  1720. $ref = dol_sanitizeFileName($object->ref);
  1721. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1722. $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
  1723. $file=$fileparams['fullname'];
  1724. // Define output language
  1725. $outputlangs = $langs;
  1726. $newlang = '';
  1727. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
  1728. $newlang = $_REQUEST['lang_id'];
  1729. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1730. $newlang = $object->client->default_lang;
  1731. if (!empty($newlang))
  1732. {
  1733. $outputlangs = new Translate('', $conf);
  1734. $outputlangs->setDefaultLang($newlang);
  1735. $outputlangs->load('commercial');
  1736. }
  1737. // Build document if it not exists
  1738. if (! $file || ! is_readable($file))
  1739. {
  1740. $result=supplier_order_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1741. if ($result <= 0)
  1742. {
  1743. dol_print_error($db,$result);
  1744. exit;
  1745. }
  1746. $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
  1747. $file=$fileparams['fullname'];
  1748. }
  1749. print '<br>';
  1750. print_titre($langs->trans('SendOrderByMail'));
  1751. // Cree l'objet formulaire mail
  1752. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1753. $formmail = new FormMail($db);
  1754. $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
  1755. $formmail->fromtype = 'user';
  1756. $formmail->fromid = $user->id;
  1757. $formmail->fromname = $user->getFullName($langs);
  1758. $formmail->frommail = $user->email;
  1759. $formmail->withfrom=1;
  1760. $liste=array();
  1761. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
  1762. $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
  1763. $formmail->withtocc=$liste;
  1764. $formmail->withtoccc=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false);
  1765. $formmail->withtopic=$outputlangs->trans('SendOrderRef','__ORDERREF__');
  1766. $formmail->withfile=2;
  1767. $formmail->withbody=1;
  1768. $formmail->withdeliveryreceipt=1;
  1769. $formmail->withcancel=1;
  1770. // Tableau des substitutions
  1771. $formmail->substit['__ORDERREF__']=$object->ref;
  1772. $formmail->substit['__SIGNATURE__']=$user->signature;
  1773. $formmail->substit['__PERSONALIZED__']='';
  1774. $formmail->substit['__CONTACTCIVNAME__']='';
  1775. //Find the good contact adress
  1776. $custcontact='';
  1777. $contactarr=array();
  1778. $contactarr=$object->liste_contact(-1,'external');
  1779. if (is_array($contactarr) && count($contactarr)>0) {
  1780. foreach($contactarr as $contact) {
  1781. if ($contact['libelle']==$langs->trans('TypeContact_order_supplier_external_BILLING')) {
  1782. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  1783. $contactstatic=new Contact($db);
  1784. $contactstatic->fetch($contact['id']);
  1785. $custcontact=$contactstatic->getFullName($langs,1);
  1786. }
  1787. }
  1788. if (!empty($custcontact)) {
  1789. $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
  1790. }
  1791. }
  1792. // Tableau des parametres complementaires
  1793. $formmail->param['action']='send';
  1794. $formmail->param['models']='order_supplier_send';
  1795. $formmail->param['orderid']=$object->id;
  1796. $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  1797. // Init list of files
  1798. if (GETPOST("mode")=='init')
  1799. {
  1800. $formmail->clear_attached_files();
  1801. $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
  1802. }
  1803. // Show form
  1804. print $formmail->get_form();
  1805. print '<br>';
  1806. }
  1807. print '</td></tr></table>';
  1808. }
  1809. // End of page
  1810. llxFooter();
  1811. $db->close();