PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/contrat/fiche.php

https://github.com/abhimanyumohan/dolibarr
PHP | 1828 lines | 1373 code | 265 blank | 190 comment | 419 complexity | ac45deb5ecfef880b12303953696ccbf MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-4.0, Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception

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

  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  6. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
  8. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  9. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  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 3 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. */
  24. /**
  25. * \file htdocs/contrat/fiche.php
  26. * \ingroup contrat
  27. * \brief Page of a contract
  28. */
  29. require ("../main.inc.php");
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  36. if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  38. if (! empty($conf->projet->enabled)) {
  39. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  41. }
  42. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  43. $langs->load("contracts");
  44. $langs->load("orders");
  45. $langs->load("companies");
  46. $langs->load("bills");
  47. $langs->load("products");
  48. $langs->load('compta');
  49. $action=GETPOST('action','alpha');
  50. $confirm=GETPOST('confirm','alpha');
  51. $socid = GETPOST('socid','int');
  52. $id = GETPOST('id','int');
  53. $ref=GETPOST('ref','alpha');
  54. $datecontrat='';
  55. // Security check
  56. if ($user->societe_id) $socid=$user->societe_id;
  57. $result=restrictedArea($user,'contrat',$id);
  58. $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0);
  59. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  60. $hookmanager->initHooks(array('contractcard'));
  61. $object = new Contrat($db);
  62. $extrafields = new ExtraFields($db);
  63. // fetch optionals attributes and labels
  64. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  65. $permissionnote=$user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php
  66. /*
  67. * Actions
  68. */
  69. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
  70. if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer)
  71. {
  72. $object->fetch($id);
  73. $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment'));
  74. if ($result > 0)
  75. {
  76. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  77. exit;
  78. }
  79. else {
  80. setEventMessage($object->error,'errors');
  81. }
  82. }
  83. else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer)
  84. {
  85. if (! GETPOST('dateend'))
  86. {
  87. $error++;
  88. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")),'errors');
  89. }
  90. if (! $error)
  91. {
  92. $object->fetch($id);
  93. $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment')));
  94. if ($result > 0)
  95. {
  96. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  97. exit;
  98. }
  99. else {
  100. setEventMessage($object->error,'errors');
  101. }
  102. }
  103. }
  104. // Si ajout champ produit predefini
  105. if (GETPOST('mode')=='predefined')
  106. {
  107. $date_start='';
  108. $date_end='';
  109. if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
  110. {
  111. $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  112. }
  113. if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
  114. {
  115. $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  116. }
  117. }
  118. // Si ajout champ produit libre
  119. if (GETPOST('mode')=='libre')
  120. {
  121. $date_start_sl='';
  122. $date_end_sl='';
  123. if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
  124. {
  125. $date_start_sl=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
  126. }
  127. if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
  128. {
  129. $date_end_sl=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
  130. }
  131. }
  132. // Param dates
  133. $date_contrat='';
  134. $date_start_update='';
  135. $date_end_update='';
  136. $date_start_real_update='';
  137. $date_end_real_update='';
  138. if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear'))
  139. {
  140. $date_start_update=dol_mktime(GETPOST('date_start_updatehour'), GETPOST('date_start_updatemin'), 0, GETPOST('date_start_updatemonth'), GETPOST('date_start_updateday'), GETPOST('date_start_updateyear'));
  141. }
  142. if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear'))
  143. {
  144. $date_end_update=dol_mktime(GETPOST('date_end_updatehour'), GETPOST('date_end_updatemin'), 0, GETPOST('date_end_updatemonth'), GETPOST('date_end_updateday'), GETPOST('date_end_updateyear'));
  145. }
  146. if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear'))
  147. {
  148. $date_start_real_update=dol_mktime(GETPOST('date_start_real_updatehour'), GETPOST('date_start_real_updatemin'), 0, GETPOST('date_start_real_updatemonth'), GETPOST('date_start_real_updateday'), GETPOST('date_start_real_updateyear'));
  149. }
  150. if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear'))
  151. {
  152. $date_end_real_update=dol_mktime(GETPOST('date_end_real_updatehour'), GETPOST('date_end_real_updatemin'), 0, GETPOST('date_end_real_updatemonth'), GETPOST('date_end_real_updateday'), GETPOST('date_end_real_updateyear'));
  153. }
  154. if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear'))
  155. {
  156. $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  157. }
  158. // Add contract
  159. if ($action == 'add' && $user->rights->contrat->creer)
  160. {
  161. // Check
  162. if (empty($datecontrat))
  163. {
  164. $error++;
  165. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
  166. $action='create';
  167. }
  168. if ($socid<1)
  169. {
  170. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Customer")),'errors');
  171. $action='create';
  172. $error++;
  173. }
  174. if (! $error)
  175. {
  176. $object->socid = $socid;
  177. $object->date_contrat = $datecontrat;
  178. $object->commercial_suivi_id = GETPOST('commercial_suivi_id','int');
  179. $object->commercial_signature_id = GETPOST('commercial_signature_id','int');
  180. $object->note_private = GETPOST('note_private','alpha');
  181. $object->note_public = GETPOST('note_public','alpha');
  182. $object->fk_project = GETPOST('projectid','int');
  183. $object->remise_percent = GETPOST('remise_percent','alpha');
  184. $object->ref = GETPOST('ref','alpha');
  185. $object->ref_ext = GETPOST('ref_ext','alpha');
  186. // If creation from another object of another module (Example: origin=propal, originid=1)
  187. if ($_POST['origin'] && $_POST['originid'])
  188. {
  189. // Parse element/subelement (ex: project_task)
  190. $element = $subelement = $_POST['origin'];
  191. if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
  192. {
  193. $element = $regs[1];
  194. $subelement = $regs[2];
  195. }
  196. // For compatibility
  197. if ($element == 'order') { $element = $subelement = 'commande'; }
  198. if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
  199. $object->origin = $_POST['origin'];
  200. $object->origin_id = $_POST['originid'];
  201. // Possibility to add external linked objects with hooks
  202. $object->linked_objects[$object->origin] = $object->origin_id;
  203. if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
  204. {
  205. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  206. }
  207. $id = $object->create($user);
  208. if ($id < 0) {
  209. setEventMessage($object->error,'errors');
  210. }
  211. if ($id > 0)
  212. {
  213. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  214. $classname = ucfirst($subelement);
  215. $srcobject = new $classname($db);
  216. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  217. $result=$srcobject->fetch($object->origin_id);
  218. if ($result > 0)
  219. {
  220. $srcobject->fetch_thirdparty();
  221. $lines = $srcobject->lines;
  222. if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
  223. $fk_parent_line=0;
  224. $num=count($lines);
  225. for ($i=0;$i<$num;$i++)
  226. {
  227. $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
  228. if ($product_type == 1) { //only services // TODO Exclude also deee
  229. // service prédéfini
  230. if ($lines[$i]->fk_product > 0)
  231. {
  232. $product_static = new Product($db);
  233. // Define output language
  234. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  235. {
  236. $prod = new Product($db);
  237. $prod->id=$lines[$i]->fk_product;
  238. $prod->getMultiLangs();
  239. $outputlangs = $langs;
  240. $newlang='';
  241. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  242. if (empty($newlang)) $newlang=$srcobject->thirdparty->default_lang;
  243. if (! empty($newlang))
  244. {
  245. $outputlangs = new Translate("",$conf);
  246. $outputlangs->setDefaultLang($newlang);
  247. }
  248. $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
  249. }
  250. else
  251. {
  252. $label = $lines[$i]->product_label;
  253. }
  254. if ($conf->global->PRODUIT_DESC_IN_FORM)
  255. $desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?dol_htmlentitiesbr($lines[$i]->desc):'';
  256. }
  257. else {
  258. $desc = dol_htmlentitiesbr($lines[$i]->desc);
  259. }
  260. $result = $object->addline(
  261. $desc,
  262. $lines[$i]->subprice,
  263. $lines[$i]->qty,
  264. $lines[$i]->tva_tx,
  265. $lines[$i]->localtax1_tx,
  266. $lines[$i]->localtax2_tx,
  267. $lines[$i]->fk_product,
  268. $lines[$i]->remise_percent,
  269. $lines[$i]->date_start,
  270. $lines[$i]->date_end,
  271. 'HT',
  272. 0,
  273. $lines[$i]->info_bits,
  274. $lines[$i]->fk_fournprice,
  275. $lines[$i]->pa_ht
  276. );
  277. if ($result < 0)
  278. {
  279. $error++;
  280. break;
  281. }
  282. }
  283. }
  284. }
  285. else
  286. {
  287. setEventMessage($srcobject->error,'errors');
  288. $error++;
  289. }
  290. }
  291. else
  292. {
  293. setEventMessage($object->error,'errors');
  294. $error++;
  295. }
  296. }
  297. else
  298. {
  299. // Fill array 'array_options' with data from add form
  300. $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  301. $result = $object->create($user);
  302. if ($result > 0)
  303. {
  304. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  305. exit;
  306. }
  307. else {
  308. setEventMessage($object->error,'errors');
  309. }
  310. $action='create';
  311. }
  312. }
  313. }
  314. else if ($action == 'classin' && $user->rights->contrat->creer)
  315. {
  316. $object->fetch($id);
  317. $object->setProject(GETPOST('projectid'));
  318. }
  319. // Add a new line
  320. else if ($action == 'addline' && $user->rights->contrat->creer)
  321. {
  322. // Set if we used free entry or predefined product
  323. $predef='';
  324. $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
  325. if (GETPOST('prod_entry_mode') == 'free')
  326. {
  327. $idprod=0;
  328. $price_ht = GETPOST('price_ht');
  329. $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
  330. }
  331. else
  332. {
  333. $idprod=GETPOST('idprod', 'int');
  334. $price_ht = '';
  335. $tva_tx = '';
  336. }
  337. $qty = GETPOST('qty'.$predef);
  338. $remise_percent=GETPOST('remise_percent'.$predef);
  339. if ($qty == '')
  340. {
  341. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")),'errors');
  342. $error++;
  343. }
  344. if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc))
  345. {
  346. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")),'errors');
  347. $error++;
  348. }
  349. if (! $error)
  350. {
  351. $ret=$object->fetch($id);
  352. if ($ret < 0)
  353. {
  354. setEventMessage($object->error,'errors');
  355. exit;
  356. }
  357. $ret=$object->fetch_thirdparty();
  358. // Clean parameters
  359. $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
  360. $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
  361. $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT');
  362. // Ecrase $pu par celui du produit
  363. // Ecrase $desc par celui du produit
  364. // Ecrase $txtva par celui du produit
  365. // Ecrase $base_price_type par celui du produit
  366. if ($idprod > 0)
  367. {
  368. $prod = new Product($db);
  369. $prod->fetch($idprod);
  370. $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id);
  371. $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id);
  372. $pu_ht = $prod->price;
  373. $pu_ttc = $prod->price_ttc;
  374. $price_min = $prod->price_min;
  375. $price_base_type = $prod->price_base_type;
  376. // On defini prix unitaire
  377. if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level)
  378. {
  379. $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
  380. $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
  381. $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
  382. $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
  383. }
  384. elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
  385. {
  386. require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
  387. $prodcustprice = new Productcustomerprice($db);
  388. $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id);
  389. $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
  390. if ($result) {
  391. if (count($prodcustprice->lines) > 0) {
  392. $pu_ht = price($prodcustprice->lines [0]->price);
  393. $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
  394. $price_base_type = $prodcustprice->lines [0]->price_base_type;
  395. $prod->tva_tx = $prodcustprice->lines [0]->tva_tx;
  396. }
  397. }
  398. }
  399. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  400. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  401. if ($tva_tx != $prod->tva_tx)
  402. {
  403. if ($price_base_type != 'HT')
  404. {
  405. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
  406. }
  407. else
  408. {
  409. $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
  410. }
  411. }
  412. $desc=$prod->description;
  413. $desc=dol_concatdesc($desc,$product_desc);
  414. }
  415. else
  416. {
  417. $pu_ht=GETPOST('price_ht');
  418. $price_base_type = 'HT';
  419. $tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0
  420. $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0;
  421. $desc=$product_desc;
  422. }
  423. $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty);
  424. $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty);
  425. // ajout prix achat
  426. $fk_fournprice = $_POST['fournprice'];
  427. if ( ! empty($_POST['buying_price']) )
  428. $pa_ht = $_POST['buying_price'];
  429. else
  430. $pa_ht = null;
  431. $info_bits=0;
  432. if ($tva_npr) $info_bits |= 0x01;
  433. if($price_min && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min)))
  434. {
  435. $object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency));
  436. $result = -1 ;
  437. }
  438. else
  439. {
  440. // Insert line
  441. $result = $object->addline(
  442. $desc,
  443. $pu_ht,
  444. $qty,
  445. $tva_tx,
  446. $localtax1_tx,
  447. $localtax2_tx,
  448. $idprod,
  449. $remise_percent,
  450. $date_start,
  451. $date_end,
  452. $price_base_type,
  453. $pu_ttc,
  454. $info_bits,
  455. $fk_fournprice,
  456. $pa_ht
  457. );
  458. }
  459. if ($result > 0)
  460. {
  461. /*
  462. // Define output language
  463. $outputlangs = $langs;
  464. $newlang='';
  465. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  466. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  467. if (! empty($newlang))
  468. {
  469. $outputlangs = new Translate("",$conf);
  470. $outputlangs->setDefaultLang($newlang);
  471. }
  472. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  473. {
  474. $ret=$object->fetch($id); // Reload to get new records
  475. contrat_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
  476. }
  477. */
  478. unset($_POST ['prod_entry_mode']);
  479. unset($_POST['qty']);
  480. unset($_POST['type']);
  481. unset($_POST['remise_percent']);
  482. unset($_POST['price_ht']);
  483. unset($_POST['price_ttc']);
  484. unset($_POST['tva_tx']);
  485. unset($_POST['product_ref']);
  486. unset($_POST['product_label']);
  487. unset($_POST['product_desc']);
  488. unset($_POST['fournprice']);
  489. unset($_POST['buying_price']);
  490. unset($_POST ['np_marginRate']);
  491. unset($_POST ['np_markRate']);
  492. unset($_POST['dp_desc']);
  493. unset($_POST['idprod']);
  494. unset($_POST['date_starthour']);
  495. unset($_POST['date_startmin']);
  496. unset($_POST['date_startsec']);
  497. unset($_POST['date_startday']);
  498. unset($_POST['date_startmonth']);
  499. unset($_POST['date_startyear']);
  500. unset($_POST['date_endhour']);
  501. unset($_POST['date_endmin']);
  502. unset($_POST['date_endsec']);
  503. unset($_POST['date_endday']);
  504. unset($_POST['date_endmonth']);
  505. unset($_POST['date_endyear']);
  506. }
  507. else
  508. {
  509. setEventMessage($object->error,'errors');
  510. }
  511. }
  512. }
  513. else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST('cancel'))
  514. {
  515. $ret=$object->fetch($id);
  516. if ($ret < 0)
  517. {
  518. dol_print_error($db,$object->error);
  519. exit;
  520. }
  521. $object->fetch_thirdparty();
  522. $objectline = new ContratLigne($db);
  523. if ($objectline->fetch(GETPOST('elrowid')))
  524. {
  525. $db->begin();
  526. if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
  527. if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture;
  528. $localtax1_tx=get_localtax(GETPOST('eltva_tx'),1,$object->thirdparty);
  529. $localtax2_tx=get_localtax(GETPOST('eltva_tx'),2,$object->thirdparty);
  530. // ajout prix d'achat
  531. $fk_fournprice = $_POST['fournprice'];
  532. if ( ! empty($_POST['buying_price']) )
  533. $pa_ht = $_POST['buying_price'];
  534. else
  535. $pa_ht = null;
  536. $objectline->description=GETPOST('product_desc');
  537. $objectline->price_ht=GETPOST('elprice');
  538. $objectline->subprice=GETPOST('elprice');
  539. $objectline->qty=GETPOST('elqty');
  540. $objectline->remise_percent=GETPOST('elremise_percent');
  541. $objectline->tva_tx=GETPOST('eltva_tx')?GETPOST('eltva_tx'):0; // Field may be disabled, so we use vat rate 0
  542. $objectline->localtax1_tx=$localtax1_tx;
  543. $objectline->localtax2_tx=$localtax2_tx;
  544. $objectline->date_ouverture_prevue=$date_start_update;
  545. $objectline->date_ouverture=$date_start_real_update;
  546. $objectline->date_fin_validite=$date_end_update;
  547. $objectline->date_cloture=$date_end_real_update;
  548. $objectline->fk_user_cloture=$user->id;
  549. $objectline->fk_fournprice=$fk_fournprice;
  550. $objectline->pa_ht=$pa_ht;
  551. // TODO verifier price_min si fk_product et multiprix
  552. $result=$objectline->update($user);
  553. if ($result > 0)
  554. {
  555. $db->commit();
  556. }
  557. else
  558. {
  559. setEventMessage($objectline->error,'errors');
  560. $db->rollback();
  561. }
  562. }
  563. else
  564. {
  565. setEventMessage($objectline->error,'errors');
  566. }
  567. }
  568. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)
  569. {
  570. $object->fetch($id);
  571. $result = $object->deleteline(GETPOST('lineid'),$user);
  572. if ($result >= 0)
  573. {
  574. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  575. exit;
  576. }
  577. else
  578. {
  579. setEventMessage($object->error,'errors');
  580. }
  581. }
  582. else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer)
  583. {
  584. $object->fetch($id);
  585. $result = $object->validate($user);
  586. }
  587. // Close all lines
  588. else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
  589. {
  590. $object->fetch($id);
  591. $result = $object->cloture($user);
  592. }
  593. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)
  594. {
  595. $object->fetch($id);
  596. $object->fetch_thirdparty();
  597. $result=$object->delete($user);
  598. if ($result >= 0)
  599. {
  600. header("Location: index.php");
  601. return;
  602. }
  603. else
  604. {
  605. setEventMessage($object->error,'errors');
  606. }
  607. }
  608. else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer)
  609. {
  610. if (GETPOST('newcid') > 0)
  611. {
  612. $contractline = new ContratLigne($db);
  613. $result=$contractline->fetch(GETPOST('lineid'));
  614. $contractline->fk_contrat = GETPOST('newcid');
  615. $result=$contractline->update($user,1);
  616. if ($result >= 0)
  617. {
  618. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  619. return;
  620. }
  621. else
  622. {
  623. setEventMessage($object->error,'errors');
  624. }
  625. }
  626. else
  627. {
  628. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")),'errors');
  629. }
  630. } else if ($action == 'update_extras') {
  631. // Fill array 'array_options' with data from update form
  632. $object->fetch($id);
  633. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  634. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
  635. if ($ret < 0)
  636. $error ++;
  637. if (! $error) {
  638. $result = $object->insertExtraFields();
  639. if ($result < 0) {
  640. $error ++;
  641. }
  642. } else if ($reshook < 0)
  643. $error ++;
  644. if ($error) {
  645. $action = 'edit_extras';
  646. setEventMessage($object->error,'errors');
  647. }
  648. } elseif ($action=='setref_ext') {
  649. $result = $object->fetch($id);
  650. if ($result < 0) {
  651. setEventMessage($object->errors,'errors');
  652. }
  653. $object->ref_ext=GETPOST('ref_ext','alpha');
  654. $result = $object->update($user);
  655. if ($result < 0) {
  656. setEventMessage($object->errors,'errors');
  657. $action='editref_ext';
  658. } else {
  659. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  660. exit;
  661. }
  662. }
  663. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer)
  664. {
  665. if ($action == 'addcontact')
  666. {
  667. $result = $object->fetch($id);
  668. if ($result > 0 && $id > 0)
  669. {
  670. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  671. $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
  672. }
  673. if ($result >= 0)
  674. {
  675. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  676. exit;
  677. }
  678. else
  679. {
  680. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  681. {
  682. $langs->load("errors");
  683. setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"),'errors');
  684. }
  685. else
  686. {
  687. setEventMessage($object->error,'errors');
  688. }
  689. }
  690. }
  691. // bascule du statut d'un contact
  692. else if ($action == 'swapstatut')
  693. {
  694. if ($object->fetch($id))
  695. {
  696. $result=$object->swapContactStatus(GETPOST('ligne'));
  697. }
  698. else
  699. {
  700. setEventMessage($object->error,'errors');
  701. }
  702. }
  703. // Efface un contact
  704. else if ($action == 'deletecontact')
  705. {
  706. $object->fetch($id);
  707. $result = $object->delete_contact(GETPOST('lineid'));
  708. if ($result >= 0)
  709. {
  710. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  711. exit;
  712. }
  713. else {
  714. setEventMessage($object->error,'errors');
  715. }
  716. }
  717. }
  718. /*
  719. * View
  720. */
  721. llxHeader('',$langs->trans("ContractCard"),"Contrat");
  722. $form = new Form($db);
  723. $objectlignestatic=new ContratLigne($db);
  724. /*********************************************************************
  725. *
  726. * Mode creation
  727. *
  728. *********************************************************************/
  729. if ($action == 'create')
  730. {
  731. print_fiche_titre($langs->trans('AddContract'));
  732. $soc = new Societe($db);
  733. if ($socid>0) $soc->fetch($socid);
  734. if (GETPOST('origin') && GETPOST('originid'))
  735. {
  736. // Parse element/subelement (ex: project_task)
  737. $element = $subelement = GETPOST('origin');
  738. if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs))
  739. {
  740. $element = $regs[1];
  741. $subelement = $regs[2];
  742. }
  743. if ($element == 'project')
  744. {
  745. $projectid=GETPOST('originid');
  746. }
  747. else
  748. {
  749. // For compatibility
  750. if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
  751. if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
  752. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  753. $classname = ucfirst($subelement);
  754. $objectsrc = new $classname($db);
  755. $objectsrc->fetch(GETPOST('originid'));
  756. if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
  757. $objectsrc->fetch_thirdparty();
  758. $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
  759. $soc = $objectsrc->client;
  760. $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : '');
  761. $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
  762. // Object source contacts list
  763. $srccontactslist = $objectsrc->liste_contact(-1,'external',1);
  764. }
  765. }
  766. else {
  767. $projectid = GETPOST('projectid','int');
  768. $note_private = GETPOST("note_private");
  769. $note_public = GETPOST("note_public");
  770. }
  771. $object->date_contrat = dol_now();
  772. $numct = $object->getNextNumRef($soc);
  773. print '<form name="form_contract" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  774. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  775. print '<input type="hidden" name="action" value="add">';
  776. print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
  777. print '<input type="hidden" name="remise_percent" value="0">';
  778. print '<table class="border" width="100%">';
  779. // Ref
  780. print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
  781. // Ref Int
  782. print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
  783. print '<td colspan="2"><input type="text" siez="5" name="ref_ext" id="ref_ext" value="'.GETPOST('ref_ext','alpha').'"></td></tr>';
  784. // Customer
  785. print '<tr>';
  786. print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
  787. if($socid>0)
  788. {
  789. print '<td colspan="2">';
  790. print $soc->getNomUrl(1);
  791. print '<input type="hidden" name="socid" value="'.$soc->id.'">';
  792. print '</td>';
  793. }
  794. else
  795. {
  796. print '<td colspan="2">';
  797. print $form->select_company('','socid','s.client = 1 OR s.client = 3',1);
  798. print '</td>';
  799. }
  800. print '</tr>'."\n";
  801. if($socid>0)
  802. {
  803. // Ligne info remises tiers
  804. print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
  805. if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_percent);
  806. else print $langs->trans("CompanyHasNoRelativeDiscount");
  807. print '. ';
  808. $absolute_discount=$soc->getAvailableDiscounts();
  809. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
  810. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  811. print '.';
  812. print '</td></tr>';
  813. }
  814. // Commercial suivi
  815. print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
  816. print $form->select_dolusers(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,'');
  817. print '</td></tr>';
  818. // Commercial signature
  819. print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
  820. print $form->select_dolusers(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,'');
  821. print '</td></tr>';
  822. print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
  823. $form->select_date($datecontrat,'',0,0,'',"contrat");
  824. print "</td></tr>";
  825. if (! empty($conf->projet->enabled))
  826. {
  827. $formproject=new FormProjets($db);
  828. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  829. $formproject->select_projects($soc->id,$projectid,"projectid");
  830. print "</td></tr>";
  831. }
  832. print '<tr><td>'.$langs->trans("NotePublic").'</td><td valign="top">';
  833. $doleditor=new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
  834. print $doleditor->Create(1);
  835. if (empty($user->societe_id))
  836. {
  837. print '<tr><td>'.$langs->trans("NotePrivate").'</td><td valign="top">';
  838. $doleditor=new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
  839. print $doleditor->Create(1);
  840. print '</td></tr>';
  841. }
  842. // Other attributes
  843. $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"');
  844. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  845. // Other attributes
  846. if (empty($reshook) && ! empty($extrafields->attribute_label)) {
  847. print $object->showOptionals($extrafields, 'edit');
  848. }
  849. print "</table>\n";
  850. if (is_object($objectsrc))
  851. {
  852. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  853. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  854. }
  855. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
  856. print "</form>\n";
  857. dol_fiche_end();
  858. }
  859. else
  860. /* *************************************************************************** */
  861. /* */
  862. /* Mode vue et edition */
  863. /* */
  864. /* *************************************************************************** */
  865. {
  866. $now=dol_now();
  867. if ($id > 0 || ! empty($ref))
  868. {
  869. $result=$object->fetch($id,$ref);
  870. if ($result < 0) dol_print_error($db,$object->error);
  871. $result=$object->fetch_lines(); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed
  872. if ($result < 0) dol_print_error($db,$object->error);
  873. $result=$object->fetch_thirdparty();
  874. if ($result < 0) dol_print_error($db,$object->error);
  875. $nbofservices=count($object->lines);
  876. $author = new User($db);
  877. $author->fetch($object->user_author_id);
  878. $commercial_signature = new User($db);
  879. $commercial_signature->fetch($object->commercial_signature_id);
  880. $commercial_suivi = new User($db);
  881. $commercial_suivi->fetch($object->commercial_suivi_id);
  882. $head = contract_prepare_head($object);
  883. $hselected = 0;
  884. dol_fiche_head($head, $hselected, $langs->trans("Contract"), 0, 'contract');
  885. /*
  886. * Confirmation de la suppression du contrat
  887. */
  888. if ($action == 'delete')
  889. {
  890. print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1);
  891. }
  892. /*
  893. * Confirmation de la validation
  894. */
  895. if ($action == 'valid')
  896. {
  897. $ref = substr($object->ref, 1, 4);
  898. if ($ref == 'PROV')
  899. {
  900. $numref = $object->getNextNumRef($soc);
  901. }
  902. else
  903. {
  904. $numref = $object->ref;
  905. }
  906. $text=$langs->trans('ConfirmValidateContract',$numref);
  907. print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$text,"confirm_valid",'',0,1);
  908. }
  909. /*
  910. * Confirmation de la fermeture
  911. */
  912. if ($action == 'close')
  913. {
  914. print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1);
  915. }
  916. /*
  917. * Contrat
  918. */
  919. if (! empty($object->brouillon) && $user->rights->contrat->creer)
  920. {
  921. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">';
  922. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  923. print '<input type="hidden" name="action" value="setremise">';
  924. }
  925. print '<table class="border" width="100%">';
  926. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  927. // Ref du contrat
  928. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  929. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  930. print "</td></tr>";
  931. print '<tr>';
  932. print '<td width="20%">';
  933. print $form->editfieldkey("RefCustomer",'ref_ext',$object->ref_ext,$object,$user->rights->contrat->creer);
  934. print '</td><td>';
  935. print $form->editfieldval("RefCustomer",'ref_ext',$object->ref_ext,$object,$user->rights->contrat->creer);
  936. print '</td>';
  937. print '</tr>';
  938. // Customer
  939. print "<tr><td>".$langs->trans("Customer")."</td>";
  940. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  941. // Ligne info remises tiers
  942. print '<tr><td>'.$langs->trans('Discount').'</td><td colspan="3">';
  943. if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent);
  944. else print $langs->trans("CompanyHasNoRelativeDiscount");
  945. $absolute_discount=$object->thirdparty->getAvailableDiscounts();
  946. print '. ';
  947. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
  948. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  949. print '.';
  950. print '</td></tr>';
  951. // Statut contrat
  952. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
  953. if ($object->statut==0) print $object->getLibStatut(2);
  954. else print $object->getLibStatut(4);
  955. print "</td></tr>";
  956. // Date
  957. print '<tr><td>'.$langs->trans("Date").'</td>';
  958. print '<td colspan="3">'.dol_print_date($object->date_contrat,"dayhour")."</td></tr>\n";
  959. // Projet
  960. if (! empty($conf->projet->enabled))
  961. {
  962. $langs->load("projects");
  963. print '<tr><td>';
  964. print '<table width="100%" class="nobordernopadding"><tr><td>';
  965. print $langs->trans("Project");
  966. print '</td>';
  967. if ($action != "classify" && $user->rights->projet->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans("SetProject")).'</a></td>';
  968. print '</tr></table>';
  969. print '</td><td colspan="3">';
  970. if ($action == "classify")
  971. {
  972. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"projectid");
  973. }
  974. else
  975. {
  976. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"none");
  977. }
  978. print "</td></tr>";
  979. }
  980. // Other attributes
  981. $parameters=array('colspan' => ' colspan="3"');
  982. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  983. $res = $object->fetch_optionals($object->id, $extralabels);
  984. if (empty($reshook) && ! empty($extrafields->attribute_label)) {
  985. foreach ($extrafields->attribute_label as $key => $label) {
  986. if ($action == 'edit_extras') {
  987. $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
  988. } else {
  989. $value = $object->array_options ["options_" . $key];
  990. }
  991. if ($extrafields->attribute_type [$key] == 'separate') {
  992. print $extrafields->showSeparator($key);
  993. } else {
  994. print '<tr><td';
  995. if (! empty($extrafields->attribute_required [$key]))
  996. print ' class="fieldrequired"';
  997. print '>' . $label . '</td><td colspan="5">';
  998. // Convert date into timestamp format
  999. if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
  1000. $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]);
  1001. }
  1002. if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
  1003. print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formcontract">';
  1004. print '<input type="hidden" name="action" value="update_extras">';
  1005. print '<input type="hidden" name="attribute" value="' . $key . '">';
  1006. print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  1007. print '<input type="hidden" name="id" value="' . $object->id . '">';
  1008. print $extrafields->showInputField($key, $value);
  1009. print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1010. print '</form>';
  1011. } else {
  1012. print $extrafields->showOutputField($key, $value);
  1013. if ($object->statut == 0 && $user->rights->commande->creer)
  1014. print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . '</a>';
  1015. }
  1016. print '</td></tr>' . "\n";
  1017. }
  1018. }
  1019. }
  1020. print "</table>";
  1021. if (! empty($object->brouillon) && $user->rights->contrat->creer)
  1022. {
  1023. print '</form>';
  1024. }
  1025. echo '<br>';
  1026. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  1027. {
  1028. $blocname = 'contacts';
  1029. $title = $langs->trans('ContactsAddresses');
  1030. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1031. }
  1032. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1033. {
  1034. $blocname = 'notes';
  1035. $title = $langs->trans('Notes');
  1036. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1037. }
  1038. $colorb='666666';
  1039. $arrayothercontracts=$object->getListOfContracts('others');
  1040. /*
  1041. * Lines of contracts
  1042. */
  1043. $productstatic=new Product($db);
  1044. $usemargins=0;
  1045. if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
  1046. // Title line for service
  1047. $cursorline=1;
  1048. while ($cursorline <= $nbofservices)
  1049. {
  1050. print '<form name="update" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
  1051. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1052. print '<input type="hidden" name="action" value="updateligne">';
  1053. print '<input type="hidden" name="elrowid" value="'.GETPOST('rowid').'">';
  1054. print '<input type="hidden" name="idprod" value="'.($objp->fk_product?$objp->fk_product:'0').'">';
  1055. print '<input type="hidden" name="fournprice" value="'.($objp->fk_fournprice?$objp->fk_fournprice:'0').'">';
  1056. // Area with common detail of line
  1057. print '<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
  1058. $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty,";
  1059. $sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,";
  1060. $sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";
  1061. $sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";
  1062. $sql.= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
  1063. $sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype";
  1064. $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
  1065. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  1066. $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id;
  1067. $result = $db->query($sql);
  1068. if ($result)
  1069. {
  1070. $total = 0;
  1071. print '<tr class="liste_titre">';
  1072. print '<td>'.$langs->trans("ServiceNb",$cursorline).'</td>';
  1073. print '<td width="50" align="center">'.$langs->trans("VAT").'</td>';
  1074. print '<td width="50" align="right">'.$langs->trans("PriceUHT").'</td>';
  1075. print '<td width="30" align="center">'.$langs->trans("Qty").'</td>';
  1076. print '<td width="50" align="right">'.$langs->trans("ReductionShort").'</td>';
  1077. if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print '<td width="50" align="right">'.$langs->trans("BuyingPrice").'</td>';
  1078. print '<td width="30">&nbsp;</td>';
  1079. print "</tr>\n";
  1080. $var=true;
  1081. $objp = $db->fetch_object($result);
  1082. $var=!$var;
  1083. if ($action != 'editline' || GETPOST('rowid') != $objp->rowid)
  1084. {
  1085. print '<tr '.$bc[$var].' valign="top">';
  1086. // Libelle
  1087. if ($objp->fk_product > 0)
  1088. {
  1089. print '<td>';
  1090. $productstatic->id=$objp->fk_product;
  1091. $productstatic->type=$objp->ptype;
  1092. $productstatic->ref=$objp->pref;
  1093. print $productstatic->getNomUrl(1,'',20);
  1094. if ($objp->label)
  1095. {
  1096. print ' - ';
  1097. $productstatic->ref=$objp->label;
  1098. print $productstatic->getNomUrl(0,'',16);
  1099. }
  1100. if ($objp->description) print '<br>'.dol_nl2br($objp->description);
  1101. print '</td>';
  1102. }
  1103. else
  1104. {
  1105. print "<td>".dol_htmlentitiesbr($objp->description)."</td>\n";
  1106. }
  1107. // TVA
  1108. print '<td align="center">'.vatrate($objp->tva_tx,'%',$objp->info_bits).'</td>';
  1109. // Prix
  1110. print '<td align="right">'.price($objp->subprice)."</td>\n";
  1111. // Quantite
  1112. print '<td align="center">'.$objp->qty.'</td>';
  1113. // Remise
  1114. if ($objp->remise_percent > 0)
  1115. {
  1116. print '<td align="right">'.$objp->remise_percent."%</td>\n";
  1117. }
  1118. else
  1119. {
  1120. print '<td>&nbsp;</td>';
  1121. }
  1122. // Margin
  1123. if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print '<td align="right" class="nowrap">'.price($objp->pa_ht).'</td>';
  1124. // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)
  1125. print '<td align="right" class="nowrap">';
  1126. if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0))
  1127. {
  1128. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
  1129. print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
  1130. print '</a>';
  1131. }
  1132. else {
  1133. print '&nbsp;';
  1134. }
  1135. if ($user->rights->contrat->creer && ($object->statut >= 0))
  1136. {
  1137. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
  1138. print img_edit();
  1139. print '</a>';
  1140. }
  1141. else {
  1142. print '&nbsp;';
  1143. }
  1144. if ( $user->rights->contrat->creer && ($object->statut >= 0))
  1145. {
  1146. print '&nbsp;';
  1147. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
  1148. print img_delete();
  1149. print '</a>';
  1150. }
  1151. print '</td>';
  1152. print "</tr>\n";
  1153. // Dates de en service prevues et effectives
  1154. if ($objp->subprice >= 0)
  1155. {
  1156. print '<tr '.$bc[$var].'>';
  1157. print '<td colspan="'.($conf->margin->enabled?7:6).'">';
  1158. // Date planned
  1159. print $langs->trans("DateStartPlanned").': ';
  1160. if ($objp->date_debut)

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