PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/contrat/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1586 lines | 1145 code | 236 blank | 205 comment | 353 complexity | 9a6986c8f466377237f769b6a3b5314b 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) 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-2012 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/contrat/fiche.php
  23. * \ingroup contrat
  24. * \brief Page of a contract
  25. */
  26. require ("../main.inc.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/price.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php');
  31. require_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/core/modules/contract/modules_contract.php");
  33. if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  34. if (! empty($conf->propal->enabled)) require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  35. if ($conf->projet->enabled) {
  36. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  37. require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  38. }
  39. $langs->load("contracts");
  40. $langs->load("orders");
  41. $langs->load("companies");
  42. $langs->load("bills");
  43. $langs->load("products");
  44. $action=GETPOST('action','alpha');
  45. $confirm=GETPOST('confirm','alpha');
  46. $socid = GETPOST('socid','int');
  47. $id = GETPOST('id','int');
  48. $ref=GETPOST('ref','alpha');
  49. $datecontrat='';
  50. // Security check
  51. if ($user->societe_id) $socid=$user->societe_id;
  52. $result=restrictedArea($user,'contrat',$id);
  53. $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0);
  54. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  55. $hookmanager->initHooks(array('contractcard'));
  56. $object = new Contrat($db);
  57. /*
  58. * Actions
  59. */
  60. if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer)
  61. {
  62. $object->fetch($id);
  63. $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment'));
  64. if ($result > 0)
  65. {
  66. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  67. exit;
  68. }
  69. else {
  70. $mesg=$object->error;
  71. }
  72. }
  73. else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer)
  74. {
  75. $object->fetch($id);
  76. $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment')));
  77. if ($result > 0)
  78. {
  79. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  80. exit;
  81. }
  82. else {
  83. $mesg=$object->error;
  84. }
  85. }
  86. // Si ajout champ produit predefini
  87. if (GETPOST('mode')=='predefined')
  88. {
  89. $date_start='';
  90. $date_end='';
  91. if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
  92. {
  93. $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  94. }
  95. if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
  96. {
  97. $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  98. }
  99. }
  100. // Si ajout champ produit libre
  101. if (GETPOST('mode')=='libre')
  102. {
  103. $date_start_sl='';
  104. $date_end_sl='';
  105. if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
  106. {
  107. $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'));
  108. }
  109. if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
  110. {
  111. $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'));
  112. }
  113. }
  114. // Param dates
  115. $date_contrat='';
  116. $date_start_update='';
  117. $date_end_update='';
  118. $date_start_real_update='';
  119. $date_end_real_update='';
  120. if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear'))
  121. {
  122. $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'));
  123. }
  124. if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear'))
  125. {
  126. $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'));
  127. }
  128. if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear'))
  129. {
  130. $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'));
  131. }
  132. if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear'))
  133. {
  134. $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'));
  135. }
  136. if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear'))
  137. {
  138. $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  139. }
  140. if ($action == 'add' && $user->rights->contrat->creer)
  141. {
  142. $object->socid = $socid;
  143. $object->date_contrat = $datecontrat;
  144. $object->commercial_suivi_id = GETPOST('commercial_suivi_id','int');
  145. $object->commercial_signature_id = GETPOST('commercial_signature_id','int');
  146. $object->note = GETPOST('note','alpha');
  147. $object->fk_project = GETPOST('projectid','int');
  148. $object->remise_percent = GETPOST('remise_percent','alpha');
  149. $object->ref = GETPOST('ref','alpha');
  150. // Get extra fields
  151. foreach($_POST as $key => $value)
  152. {
  153. if (preg_match("/^options_/",$key))
  154. {
  155. $object->array_options[$key]=$_POST[$key];
  156. }
  157. }
  158. // Check
  159. if (empty($datecontrat))
  160. {
  161. $error++;
  162. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
  163. $action='create';
  164. }
  165. if (! $error)
  166. {
  167. $result = $object->create($user,$langs,$conf);
  168. if ($result > 0)
  169. {
  170. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  171. exit;
  172. }
  173. else {
  174. $mesg='<div class="error">'.$object->error.'</div>';
  175. }
  176. $action='create';
  177. }
  178. }
  179. if ($action == 'update')
  180. {
  181. if ($_POST["cancel"])
  182. {
  183. Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$contratid);
  184. exit;
  185. }
  186. $object->fetch($contratid);
  187. $object->date_contrat = $datecontrat;
  188. $object->note = trim($_POST["note"]);
  189. $object->fk_project = trim($_POST["projectid"]);
  190. $object->remise_percent = trim($_POST["remise_percent"]);
  191. $object->id = $contratid;
  192. // Get extra fields
  193. foreach($_POST as $key => $value)
  194. {
  195. if (preg_match("/^options_/",$key))
  196. {
  197. $object->array_options[$key]=$_POST[$key];
  198. }
  199. }
  200. $result = $object->update($user,$langs,$conf);
  201. if ($result > 0)
  202. {
  203. Header("Location: fiche.php?id=".$object->id);
  204. exit;
  205. }
  206. else {
  207. $mesg='<div class="error">'.$object->error.'</div>';
  208. }
  209. $_GET["id"]=$_POST["id"];
  210. $action='edit';
  211. }
  212. else if ($action == 'classin' && $user->rights->contrat->creer)
  213. {
  214. $object->fetch($id);
  215. $object->setProject(GETPOST('projectid'));
  216. }
  217. else if ($action == 'addline' && $user->rights->contrat->creer)
  218. {
  219. if (GETPOST('pqty') && ((GETPOST('pu') != '' && GETPOST('desc')) || GETPOST('idprod')))
  220. {
  221. $ret=$object->fetch($id);
  222. if ($ret < 0)
  223. {
  224. dol_print_error($db,$object->error);
  225. exit;
  226. }
  227. $ret=$object->fetch_thirdparty();
  228. $date_start='';
  229. $date_end='';
  230. // Si ajout champ produit libre
  231. if (GETPOST('mode') == 'libre')
  232. {
  233. if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
  234. {
  235. $date_start=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
  236. }
  237. if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
  238. {
  239. $date_end=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
  240. }
  241. }
  242. // Si ajout champ produit predefini
  243. if (GETPOST('mode') == 'predefined')
  244. {
  245. if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
  246. {
  247. $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  248. }
  249. if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
  250. {
  251. $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  252. }
  253. }
  254. // Ecrase $pu par celui du produit
  255. // Ecrase $desc par celui du produit
  256. // Ecrase $txtva par celui du produit
  257. // Ecrase $base_price_type par celui du produit
  258. if (GETPOST('idprod'))
  259. {
  260. $prod = new Product($db);
  261. $prod->fetch(GETPOST('idprod'));
  262. $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id);
  263. $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id);
  264. // On defini prix unitaire
  265. if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level)
  266. {
  267. $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
  268. $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
  269. $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
  270. $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
  271. }
  272. else
  273. {
  274. $pu_ht = $prod->price;
  275. $pu_ttc = $prod->price_ttc;
  276. $price_min = $prod->price_min;
  277. $price_base_type = $prod->price_base_type;
  278. }
  279. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  280. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  281. if ($tva_tx != $prod->tva_tx)
  282. {
  283. if ($price_base_type != 'HT')
  284. {
  285. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
  286. }
  287. else
  288. {
  289. $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
  290. }
  291. }
  292. $desc = $prod->description;
  293. $desc.= $prod->description && GETPOST('desc') ? "\n" : "";
  294. $desc.= GETPOST('desc');
  295. }
  296. else
  297. {
  298. $pu_ht=GETPOST('pu');
  299. $price_base_type = 'HT';
  300. $tva_tx=str_replace('*','',GETPOST('tva_tx'));
  301. $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0;
  302. $desc=GETPOST('desc');
  303. }
  304. $localtax1_tx=get_localtax($tva_tx,1,$object->societe);
  305. $localtax2_tx=get_localtax($tva_tx,2,$object->societe);
  306. $info_bits=0;
  307. if ($tva_npr) $info_bits |= 0x01;
  308. if($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
  309. {
  310. $object->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
  311. $result = -1 ;
  312. }
  313. else
  314. {
  315. // Insert line
  316. $result = $object->addline(
  317. $desc,
  318. $pu_ht,
  319. GETPOST('pqty'),
  320. $tva_tx,
  321. $localtax1_tx,
  322. $localtax2_tx,
  323. GETPOST('idprod'),
  324. GETPOST('premise'),
  325. $date_start,
  326. $date_end,
  327. $price_base_type,
  328. $pu_ttc,
  329. $info_bits
  330. );
  331. }
  332. if ($result > 0)
  333. {
  334. /*
  335. // Define output language
  336. $outputlangs = $langs;
  337. $newlang='';
  338. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  339. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  340. if (! empty($newlang))
  341. {
  342. $outputlangs = new Translate();
  343. $outputlangs->setDefaultLang($newlang);
  344. }
  345. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  346. {
  347. $ret=$object->fetch($id); // Reload to get new records
  348. contrat_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
  349. }
  350. */
  351. }
  352. else
  353. {
  354. $mesg='<div class="error">'.$object->error.'</div>';
  355. }
  356. }
  357. }
  358. else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST('cancel'))
  359. {
  360. $ret=$object->fetch($id);
  361. if ($ret < 0)
  362. {
  363. dol_print_error($db,$object->error);
  364. exit;
  365. }
  366. $object->fetch_thirdparty();
  367. $objectline = new ContratLigne($db);
  368. if ($objectline->fetch(GETPOST('elrowid')))
  369. {
  370. $db->begin();
  371. if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
  372. if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture;
  373. $localtax1_tx=get_localtax(GETPOST('eltva_tx'),1,$object->thirdparty);
  374. $localtax2_tx=get_localtax(GETPOST('eltva_tx'),2,$object->thirdparty);
  375. $objectline->description=GETPOST('eldesc');
  376. $objectline->price_ht=GETPOST('elprice');
  377. $objectline->subprice=GETPOST('elprice');
  378. $objectline->qty=GETPOST('elqty');
  379. $objectline->remise_percent=GETPOST('elremise_percent');
  380. $objectline->tva_tx=GETPOST('eltva_tx');
  381. $objectline->localtax1_tx=$localtax1_tx;
  382. $objectline->localtax2_tx=$localtax2_tx;
  383. $objectline->date_ouverture_prevue=$date_start_update;
  384. $objectline->date_ouverture=$date_start_real_update;
  385. $objectline->date_fin_validite=$date_end_update;
  386. $objectline->date_cloture=$date_end_real_update;
  387. $objectline->fk_user_cloture=$user->id;
  388. // TODO verifier price_min si fk_product et multiprix
  389. $result=$objectline->update($user);
  390. if ($result > 0)
  391. {
  392. $db->commit();
  393. }
  394. else
  395. {
  396. dol_print_error($db,'Failed to update contrat_det');
  397. $db->rollback();
  398. }
  399. }
  400. else
  401. {
  402. dol_print_error($db);
  403. }
  404. }
  405. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)
  406. {
  407. $object->fetch($id);
  408. $result = $object->deleteline(GETPOST('lineid'),$user);
  409. if ($result >= 0)
  410. {
  411. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  412. exit;
  413. }
  414. else
  415. {
  416. $mesg=$object->error;
  417. }
  418. }
  419. else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer)
  420. {
  421. $object->fetch($id);
  422. $result = $object->validate($user);
  423. }
  424. // Close all lines
  425. else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
  426. {
  427. $object->fetch($id);
  428. $result = $object->cloture($user);
  429. }
  430. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)
  431. {
  432. $object->fetch($id);
  433. $object->fetch_thirdparty();
  434. $result=$object->delete($user);
  435. if ($result >= 0)
  436. {
  437. header("Location: index.php");
  438. return;
  439. }
  440. else
  441. {
  442. $mesg='<div class="error">'.$object->error.'</div>';
  443. }
  444. }
  445. else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer)
  446. {
  447. if (GETPOST('newcid') > 0)
  448. {
  449. $contractline = new ContratLigne($db);
  450. $result=$contractline->fetch(GETPOST('lineid'));
  451. $contractline->fk_contrat = GETPOST('newcid');
  452. $result=$contractline->update($user,1);
  453. if ($result >= 0)
  454. {
  455. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  456. return;
  457. }
  458. else
  459. {
  460. $mesg='<div class="error">'.$object->error.'</div>';
  461. }
  462. }
  463. else
  464. {
  465. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'</div>';
  466. }
  467. }
  468. else if ($action == 'setnote_public' && $user->rights->contrat->creer)
  469. {
  470. $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
  471. if ($result < 0) dol_print_error($db,$object->error);
  472. }
  473. else if ($action == 'setnote' && $user->rights->contrat->creer)
  474. {
  475. $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
  476. if ($result < 0) dol_print_error($db,$object->error);
  477. }
  478. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer)
  479. {
  480. if ($action == 'addcontact')
  481. {
  482. $result = $object->fetch($id);
  483. if ($result > 0 && $id > 0)
  484. {
  485. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  486. $result = $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
  487. }
  488. if ($result >= 0)
  489. {
  490. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  491. exit;
  492. }
  493. else
  494. {
  495. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  496. {
  497. $langs->load("errors");
  498. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  499. }
  500. else
  501. {
  502. $mesg = '<div class="error">'.$object->error.'</div>';
  503. }
  504. }
  505. }
  506. // bascule du statut d'un contact
  507. else if ($action == 'swapstatut')
  508. {
  509. if ($object->fetch($id))
  510. {
  511. $result=$object->swapContactStatus(GETPOST('ligne'));
  512. }
  513. else
  514. {
  515. dol_print_error($db);
  516. }
  517. }
  518. // Efface un contact
  519. else if ($action == 'deletecontact')
  520. {
  521. $object->fetch($id);
  522. $result = $object->delete_contact(GETPOST('lineid'));
  523. if ($result >= 0)
  524. {
  525. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  526. exit;
  527. }
  528. else {
  529. dol_print_error($db);
  530. }
  531. }
  532. }
  533. /*
  534. * Generate document
  535. */
  536. if (GETPOST('action') == 'builddoc') // En get ou en post
  537. {
  538. $object->fetch($contratid);
  539. $object->fetch_thirdparty();
  540. if (GETPOST('model'))
  541. {
  542. $object->setDocModel($user, GETPOST('model'));
  543. }
  544. // Define output language
  545. $outputlangs = $langs;
  546. $newlang='';
  547. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  548. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  549. if (! empty($newlang))
  550. {
  551. $outputlangs = new Translate();
  552. $outputlangs->setDefaultLang($newlang);
  553. }
  554. $result=contrat_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('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. /*
  567. * View
  568. */
  569. llxHeader('',$langs->trans("ContractCard"),"Contrat");
  570. $form = new Form($db);
  571. $formfile = new FormFile($db);
  572. $objectlignestatic=new ContratLigne($db);
  573. /*********************************************************************
  574. *
  575. * Mode creation
  576. *
  577. *********************************************************************/
  578. if ($action == 'create')
  579. {
  580. dol_fiche_head('', '', $langs->trans("AddContract"), 0, 'contract');
  581. dol_htmloutput_errors($mesg,'');
  582. $soc = new Societe($db);
  583. $soc->fetch($socid);
  584. $object->date_contrat = dol_now();
  585. if ($contratid) $result=$object->fetch($contratid);
  586. $numct = $object->getNextNumRef($soc);
  587. print '<form name="form_contract" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  588. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  589. print '<input type="hidden" name="action" value="add">';
  590. print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
  591. print '<input type="hidden" name="remise_percent" value="0">';
  592. print '<table class="border" width="100%">';
  593. // Ref
  594. print '<tr><td>'.$langs->trans("Ref").'</td>';
  595. print '<td><input type="text" maxlength="30" name="ref" size="20" value="'.$numct.'"></td></tr>';
  596. // Customer
  597. print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
  598. // Ligne info remises tiers
  599. print '<tr><td>'.$langs->trans('Discount').'</td><td>';
  600. if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
  601. else print $langs->trans("CompanyHasNoRelativeDiscount");
  602. $absolute_discount=$soc->getAvailableDiscounts();
  603. print '. ';
  604. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
  605. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  606. print '.';
  607. print '</td></tr>';
  608. // Commercial suivi
  609. print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
  610. print $form->select_users(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,'');
  611. print '</td></tr>';
  612. // Commercial signature
  613. print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
  614. print $form->select_users(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,'');
  615. print '</td></tr>';
  616. print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
  617. $form->select_date($datecontrat,'',0,0,'',"contrat");
  618. print "</td></tr>";
  619. if (! empty($conf->projet->enabled))
  620. {
  621. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  622. select_projects($soc->id,GETPOST("projectid"),"projectid");
  623. print "</td></tr>";
  624. }
  625. print '<tr><td>'.$langs->trans("NotePublic").'</td><td valign="top">';
  626. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  627. $doleditor=new DolEditor('note_public', GETPOST('note_public'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
  628. print $doleditor->Create(1);
  629. /*
  630. print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
  631. print GETPOST("note_public");
  632. print '</textarea></td></tr>';
  633. */
  634. if (! $user->societe_id)
  635. {
  636. print '<tr><td>'.$langs->trans("NotePrivate").'</td><td valign="top">';
  637. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  638. $doleditor=new DolEditor('note', GETPOST('note'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
  639. print $doleditor->Create(1);
  640. /*
  641. print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
  642. print GETPOST("note");
  643. print '</textarea>';*/
  644. print '</td></tr>';
  645. }
  646. print "</table>\n";
  647. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
  648. print "</form>\n";
  649. dol_fiche_end();
  650. }
  651. elseif ($action == 'edit')
  652. {
  653. /*
  654. * Edition
  655. */
  656. print_fiche_titre($langs->trans("EditContract"));
  657. if ($contratid)
  658. {
  659. dol_fiche_head($head, $a, $langs->trans("AddContract"), 0, 'contract');
  660. dol_htmloutput_errors($mesg,'');
  661. $object->date_contrat = dol_now();
  662. $object->fetch($contratid);
  663. $soc=new Societe($db);
  664. $soc->fetch($object->socid);
  665. print '<form name="contrat" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  666. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  667. print '<input type="hidden" name="action" value="update">';
  668. print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
  669. print '<input type="hidden" name="remise_percent" value="0">';
  670. print '<table class="border" width="100%">';
  671. // Ref
  672. print '<tr><td>'.$langs->trans("Ref").'</td>';
  673. print '<td>'.$object->ref.'</td></tr>';
  674. // Customer
  675. print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
  676. // Ligne info remises tiers
  677. print '<tr><td>'.$langs->trans('Discount').'</td><td>';
  678. if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
  679. else print $langs->trans("CompanyHasNoRelativeDiscount");
  680. $absolute_discount=$soc->getAvailableDiscounts();
  681. print '. ';
  682. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
  683. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  684. print '.';
  685. print '</td></tr>';
  686. // Commercial suivi
  687. //print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
  688. //print $form->select_users(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,'');
  689. //print '</td></tr>';
  690. // Commercial signature
  691. //print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
  692. //print $form->select_users(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,'');
  693. //print '</td></tr>';
  694. print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
  695. $form->select_date($datecontrat,'',0,0,'',"contrat");
  696. print "</td></tr>";
  697. // Other attributes
  698. $parameters=array('colspan' => ' colspan="3"');
  699. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  700. print "</table>\n";
  701. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
  702. print "</form>\n";
  703. dol_fiche_end();
  704. }
  705. }
  706. else
  707. /* *************************************************************************** */
  708. /* */
  709. /* Mode vue et edition */
  710. /* */
  711. /* *************************************************************************** */
  712. {
  713. $now=dol_now();
  714. if ($id > 0 || ! empty($ref))
  715. {
  716. $result=$object->fetch($id,$ref);
  717. if ($result > 0)
  718. {
  719. $result=$object->fetch_lines();
  720. }
  721. if ($result < 0)
  722. {
  723. dol_print_error($db,$object->error);
  724. exit;
  725. }
  726. dol_htmloutput_errors($mesg,'');
  727. $object->fetch_thirdparty();
  728. $nbofservices=count($object->lines);
  729. $author = new User($db);
  730. $author->fetch($object->user_author_id);
  731. $commercial_signature = new User($db);
  732. $commercial_signature->fetch($object->commercial_signature_id);
  733. $commercial_suivi = new User($db);
  734. $commercial_suivi->fetch($object->commercial_suivi_id);
  735. $head = contract_prepare_head($object);
  736. $hselected = 0;
  737. dol_fiche_head($head, $hselected, $langs->trans("Contract"), 0, 'contract');
  738. /*
  739. * Confirmation de la suppression du contrat
  740. */
  741. if ($action == 'delete')
  742. {
  743. $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1);
  744. if ($ret == 'html') print '<br>';
  745. }
  746. /*
  747. * Confirmation de la validation
  748. */
  749. if ($action == 'valid')
  750. {
  751. //$numfa = contrat_get_num($soc);
  752. $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$langs->trans("ConfirmValidateContract"),"confirm_valid",'',0,1);
  753. if ($ret == 'html') print '<br>';
  754. }
  755. /*
  756. * Confirmation de la fermeture
  757. */
  758. if ($action == 'close')
  759. {
  760. $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1);
  761. if ($ret == 'html') print '<br>';
  762. }
  763. /*
  764. * Contrat
  765. */
  766. if (! empty($object->brouillon) && $user->rights->contrat->creer)
  767. {
  768. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">';
  769. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  770. print '<input type="hidden" name="action" value="setremise">';
  771. }
  772. print '<table class="border" width="100%">';
  773. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  774. // Ref du contrat
  775. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  776. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  777. print "</td></tr>";
  778. // Customer
  779. print "<tr><td>".$langs->trans("Customer")."</td>";
  780. print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
  781. // Ligne info remises tiers
  782. print '<tr><td>'.$langs->trans('Discount').'</td><td colspan="3">';
  783. if ($object->thirdparty->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_client);
  784. else print $langs->trans("CompanyHasNoRelativeDiscount");
  785. $absolute_discount=$object->thirdparty->getAvailableDiscounts();
  786. print '. ';
  787. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
  788. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  789. print '.';
  790. print '</td></tr>';
  791. // Statut contrat
  792. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
  793. if ($object->statut==0) print $object->getLibStatut(2);
  794. else print $object->getLibStatut(4);
  795. print "</td></tr>";
  796. // Date
  797. print '<tr><td>'.$langs->trans("Date").'</td>';
  798. print '<td colspan="3">'.dol_print_date($object->date_contrat,"dayhour")."</td></tr>\n";
  799. // Other attributes
  800. $parameters=array('id'=>$object->id, 'colspan' => ' colspan="3"');
  801. $reshook=$hookmanager->executeHooks('showOutputFields',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  802. // Projet
  803. if (! empty($conf->projet->enabled))
  804. {
  805. $langs->load("projects");
  806. print '<tr><td>';
  807. print '<table width="100%" class="nobordernopadding"><tr><td>';
  808. print $langs->trans("Project");
  809. print '</td>';
  810. 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>';
  811. print '</tr></table>';
  812. print '</td><td colspan="3">';
  813. if ($action == "classify")
  814. {
  815. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"projectid");
  816. }
  817. else
  818. {
  819. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"none");
  820. }
  821. print "</td></tr>";
  822. }
  823. // Other attributes
  824. $parameters=array('colspan' => ' colspan="3"');
  825. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  826. print "</table>";
  827. if (! empty($object->brouillon) && $user->rights->contrat->creer)
  828. {
  829. print '</form>';
  830. }
  831. echo '<br>';
  832. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  833. {
  834. $blocname = 'contacts';
  835. $title = $langs->trans('ContactsAddresses');
  836. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  837. }
  838. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  839. {
  840. $blocname = 'notes';
  841. $title = $langs->trans('Notes');
  842. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  843. }
  844. $servicepos=(GETPOST('servicepos')?GETPOST('servicepos'):1); // FIXME : not used ?
  845. $colorb='666666';
  846. $arrayothercontracts=$object->getListOfContracts('others');
  847. /*
  848. * Lines of contracts
  849. */
  850. $productstatic=new Product($db);
  851. // TODO move css and DAO
  852. // Title line for service
  853. print '<table class="notopnoleft allwidth">'; // Array with (n*2)+1 lines
  854. $cursorline=1;
  855. while ($cursorline <= $nbofservices)
  856. {
  857. print '<tr height="16" '.$bc[false].'>';
  858. print '<td class="liste_titre" width="90" style="border-left: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';">';
  859. print $langs->trans("ServiceNb",$cursorline).'</td>';
  860. print '<td class="tab" style="border-right: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';" rowspan="2">';
  861. // Area with common detail of line
  862. print '<table class="notopnoleft" width="100%">';
  863. $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty,";
  864. $sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,";
  865. $sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";
  866. $sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";
  867. $sql.= " cd.commentaire as comment,";
  868. $sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype";
  869. $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
  870. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  871. $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id;
  872. $result = $db->query($sql);
  873. if ($result)
  874. {
  875. $total = 0;
  876. print '<tr class="liste_titre">';
  877. print '<td>'.$langs->trans("Service").'</td>';
  878. print '<td width="50" align="center">'.$langs->trans("VAT").'</td>';
  879. print '<td width="50" align="right">'.$langs->trans("PriceUHT").'</td>';
  880. print '<td width="30" align="center">'.$langs->trans("Qty").'</td>';
  881. print '<td width="50" align="right">'.$langs->trans("ReductionShort").'</td>';
  882. print '<td width="30">&nbsp;</td>';
  883. print "</tr>\n";
  884. $var=true;
  885. $objp = $db->fetch_object($result);
  886. $var=!$var;
  887. if ($action != 'editline' || GETPOST('rowid') != $objp->rowid)
  888. {
  889. print '<tr '.$bc[$var].' valign="top">';
  890. // Libelle
  891. if ($objp->fk_product > 0)
  892. {
  893. print '<td>';
  894. $productstatic->id=$objp->fk_product;
  895. $productstatic->type=$objp->ptype;
  896. $productstatic->ref=$objp->pref;
  897. print $productstatic->getNomUrl(1,'',20);
  898. print $objp->label?' - '.dol_trunc($objp->label,16):'';
  899. if ($objp->description) print '<br>'.dol_nl2br($objp->description);
  900. print '</td>';
  901. }
  902. else
  903. {
  904. print "<td>".nl2br($objp->description)."</td>\n";
  905. }
  906. // TVA
  907. print '<td align="center">'.vatrate($objp->tva_tx,'%',$objp->info_bits).'</td>';
  908. // Prix
  909. print '<td align="right">'.price($objp->subprice)."</td>\n";
  910. // Quantite
  911. print '<td align="center">'.$objp->qty.'</td>';
  912. // Remise
  913. if ($objp->remise_percent > 0)
  914. {
  915. print '<td align="right">'.$objp->remise_percent."%</td>\n";
  916. }
  917. else
  918. {
  919. print '<td>&nbsp;</td>';
  920. }
  921. // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)
  922. print '<td align="right" nowrap="nowrap">';
  923. if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0))
  924. {
  925. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
  926. print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
  927. print '</a>';
  928. }
  929. else {
  930. print '&nbsp;';
  931. }
  932. if ($user->rights->contrat->creer && ($object->statut >= 0))
  933. {
  934. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
  935. print img_edit();
  936. print '</a>';
  937. }
  938. else {
  939. print '&nbsp;';
  940. }
  941. if ( $user->rights->contrat->creer && ($object->statut >= 0))
  942. {
  943. print '&nbsp;';
  944. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
  945. print img_delete();
  946. print '</a>';
  947. }
  948. print '</td>';
  949. print "</tr>\n";
  950. // Dates de en service prevues et effectives
  951. if ($objp->subprice >= 0)
  952. {
  953. print '<tr '.$bc[$var].'>';
  954. print '<td colspan="6">';
  955. // Date planned
  956. print $langs->trans("DateStartPlanned").': ';
  957. if ($objp->date_debut)
  958. {
  959. print dol_print_date($db->jdate($objp->date_debut));
  960. // Warning si date prevu passee et pas en service
  961. if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { print " ".img_warning($langs->trans("Late")); }
  962. }
  963. else print $langs->trans("Unknown");
  964. print ' &nbsp;-&nbsp; ';
  965. print $langs->trans("DateEndPlanned").': ';
  966. if ($objp->date_fin)
  967. {
  968. print dol_print_date($db->jdate($objp->date_fin));
  969. if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { print " ".img_warning($langs->trans("Late")); }
  970. }
  971. else print $langs->trans("Unknown");
  972. print '</td>';
  973. print '</tr>';
  974. }
  975. }
  976. // Ligne en mode update
  977. else
  978. {
  979. print '<form name="update" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
  980. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  981. print '<input type="hidden" name="action" value="updateligne">';
  982. print '<input type="hidden" name="elrowid" value="'.GETPOST('rowid').'">';
  983. // Ligne carac
  984. print "<tr $bc[$var]>";
  985. print '<td>';
  986. if ($objp->fk_product)
  987. {
  988. $productstatic->id=$objp->fk_product;
  989. $productstatic->type=$objp->ptype;
  990. $productstatic->ref=$objp->pref;
  991. print $productstatic->getNomUrl(1,'',20);
  992. print $objp->label?' - '.dol_trunc($objp->label,16):'';
  993. print '<br>';
  994. }
  995. else
  996. {
  997. print $objp->label?$objp->label.'<br>':'';
  998. }
  999. print '<textarea name="eldesc" cols="70" rows="1">'.$objp->description.'</textarea></td>';
  1000. print '<td align="right">';
  1001. print $form->load_tva("eltva_tx",$objp->tva_tx,$mysoc,$object->thirdparty);
  1002. print '</td>';
  1003. print '<td align="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
  1004. print '<td align="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.'"></td>';
  1005. print '<td align="right" nowrap="nowrap"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
  1006. print '<td align="center" rowspan="2" valign="middle"><input type="submit" class="button" name="save" value="'.$langs->trans("Modify").'">';
  1007. print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  1008. print '</td>';
  1009. // Ligne dates prevues
  1010. print "<tr $bc[$var]>";
  1011. print '<td colspan="5">';
  1012. print $langs->trans("DateStartPlanned").' ';
  1013. $form->select_date($db->jdate($objp->date_debut),"date_start_update",$usehm,$usehm,($db->jdate($objp->date_debut)>0?0:1),"update");
  1014. print '<br>'.$langs->trans("DateEndPlanned").' ';
  1015. $form->select_date($db->jdate($objp->date_fin),"date_end_update",$usehm,$usehm,($db->jdate($objp->date_fin)>0?0:1),"update");
  1016. print '</td>';
  1017. print '</tr>';
  1018. print "</form>\n";
  1019. }
  1020. $db->free($result);
  1021. }
  1022. else
  1023. {
  1024. dol_print_error($db);
  1025. }
  1026. if ($object->statut > 0)
  1027. {
  1028. print '<tr '.$bc[false].'>';
  1029. print '<td colspan="6"><hr></td>';
  1030. print "</tr>\n";
  1031. }
  1032. print "</table>";
  1033. /*
  1034. * Confirmation to delete service line of contract
  1035. */
  1036. if ($action == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid'))
  1037. {
  1038. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1);
  1039. if ($ret == 'html') print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
  1040. }
  1041. /*
  1042. * Confirmation to move service toward another contract
  1043. */
  1044. if ($action == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid'))
  1045. {
  1046. $arraycontractid=array();
  1047. foreach($arrayothercontracts as $contractcursor)
  1048. {
  1049. $arraycontractid[$contractcursor->id]=$contractcursor->ref;
  1050. }
  1051. //var_dump($arraycontractid);
  1052. // Cree un tableau formulaire
  1053. $formquestion=array(
  1054. 'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"),
  1055. array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid));
  1056. $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion);
  1057. print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
  1058. }
  1059. /*
  1060. * Confirmation de la validation activation
  1061. */
  1062. if ($action == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne'))
  1063. {
  1064. $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  1065. $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  1066. $comment = GETPOST('comment');
  1067. $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1);
  1068. print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
  1069. }
  1070. /*
  1071. * Confirmation de la validation fermeture
  1072. */
  1073. if ($action == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne'))
  1074. {
  1075. $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  1076. $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  1077. $comment = GETPOST('comment');
  1078. $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1);
  1079. print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
  1080. }
  1081. // Area with status and activation info of line
  1082. if ($object->statut > 0)
  1083. {
  1084. print '<table class="notopnoleft" width="100%">';
  1085. print '<tr '.$bc[false].'>';
  1086. print '<td>'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline-1]->getLibStatut(4).'</td>';
  1087. print '<td width="30" align="right">';
  1088. if ($user->societe_id == 0)
  1089. {
  1090. if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline')
  1091. {
  1092. $tmpaction='activateline';
  1093. if ($objp->statut == 4) $tmpaction='unactivateline';
  1094. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline-1]->id.'&amp;action='.$tmpaction.'">';
  1095. print img_edit();
  1096. print '</a>';
  1097. }
  1098. }

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