PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fourn/commande/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1841 lines | 1390 code | 234 blank | 217 comment | 418 complexity | 86e91cc064a66e1d0ccb8f26e6fd966c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

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

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