chargesociales.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <?php
  2. /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
  5. * Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/sociales/class/chargesociales.class.php
  22. * \ingroup facture
  23. * \brief Fichier de la classe des charges sociales
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  26. /**
  27. * Classe permettant la gestion des paiements des charges
  28. * La tva collectee n'est calculee que sur les factures payees.
  29. */
  30. class ChargeSociales extends CommonObject
  31. {
  32. /**
  33. * @var string ID to identify managed object
  34. */
  35. public $element='chargesociales';
  36. public $table='chargesociales';
  37. /**
  38. * @var string Name of table without prefix where object is stored
  39. */
  40. public $table_element='chargesociales';
  41. /**
  42. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  43. */
  44. public $picto = 'bill';
  45. /**
  46. * {@inheritdoc}
  47. */
  48. protected $table_ref_field = 'ref';
  49. public $date_ech;
  50. public $lib;
  51. public $type;
  52. public $type_libelle;
  53. public $amount;
  54. public $paye;
  55. public $periode;
  56. public $date_creation;
  57. public $date_modification;
  58. public $date_validation;
  59. public $fk_account;
  60. public $fk_project;
  61. /**
  62. * Constructor
  63. *
  64. * @param DoliDB $db Database handler
  65. */
  66. function __construct($db)
  67. {
  68. $this->db = $db;
  69. }
  70. /**
  71. * Retrouve et charge une charge sociale
  72. *
  73. * @param int $id Id
  74. * @param string $ref Ref
  75. * @return int <0 KO >0 OK
  76. */
  77. function fetch($id, $ref='')
  78. {
  79. $sql = "SELECT cs.rowid, cs.date_ech";
  80. $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
  81. $sql.= ", cs.fk_account, cs.fk_mode_reglement";
  82. $sql.= ", c.libelle";
  83. $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
  84. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
  85. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
  86. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id';
  87. $sql.= ' WHERE cs.entity IN ('.getEntity('tax').')';
  88. if ($ref) $sql.= " AND cs.rowid = ".$ref;
  89. else $sql.= " AND cs.rowid = ".$id;
  90. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  91. $resql=$this->db->query($sql);
  92. if ($resql)
  93. {
  94. if ($this->db->num_rows($resql))
  95. {
  96. $obj = $this->db->fetch_object($resql);
  97. $this->id = $obj->rowid;
  98. $this->ref = $obj->rowid;
  99. $this->date_ech = $this->db->jdate($obj->date_ech);
  100. $this->lib = $obj->lib;
  101. $this->type = $obj->fk_type;
  102. $this->type_libelle = $obj->libelle;
  103. $this->fk_account = $obj->fk_account;
  104. $this->mode_reglement_id = $obj->fk_mode_reglement;
  105. $this->mode_reglement_code = $obj->mode_reglement_code;
  106. $this->mode_reglement = $obj->mode_reglement_libelle;
  107. $this->amount = $obj->amount;
  108. $this->fk_project = $obj->fk_project;
  109. $this->paye = $obj->paye;
  110. $this->periode = $this->db->jdate($obj->periode);
  111. $this->import_key = $this->import_key;
  112. $this->db->free($resql);
  113. return 1;
  114. }
  115. else
  116. {
  117. return 0;
  118. }
  119. }
  120. else
  121. {
  122. $this->error=$this->db->lasterror();
  123. return -1;
  124. }
  125. }
  126. /**
  127. * Check if a social contribution can be created into database
  128. *
  129. * @return boolean True or false
  130. */
  131. function check()
  132. {
  133. $newamount=price2num($this->amount,'MT');
  134. // Validation parametres
  135. if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
  136. {
  137. return false;
  138. }
  139. return true;
  140. }
  141. /**
  142. * Create a social contribution into database
  143. *
  144. * @param User $user User making creation
  145. * @return int <0 if KO, id if OK
  146. */
  147. function create($user)
  148. {
  149. global $conf;
  150. $error=0;
  151. $now=dol_now();
  152. // Nettoyage parametres
  153. $newamount=price2num($this->amount,'MT');
  154. if (!$this->check())
  155. {
  156. $this->error="ErrorBadParameter";
  157. return -2;
  158. }
  159. $this->db->begin();
  160. $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)";
  161. $sql.= " VALUES (".$this->type;
  162. $sql.= ", ".($this->fk_account>0 ? $this->fk_account:'NULL');
  163. $sql.= ", ".($this->mode_reglement_id>0 ? $this->mode_reglement_id:"NULL");
  164. $sql.= ", '".$this->db->escape($this->lib)."'";
  165. $sql.= ", '".$this->db->idate($this->date_ech)."'";
  166. $sql.= ", '".$this->db->idate($this->periode)."'";
  167. $sql.= ", '".price2num($newamount)."'";
  168. $sql.= ", ".($this->fk_project>0?$this->fk_project:'NULL');
  169. $sql.= ", ".$conf->entity;
  170. $sql.= ", ".$user->id;
  171. $sql.= ", '".$this->db->idate($now)."'";
  172. $sql.= ")";
  173. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  174. $resql=$this->db->query($sql);
  175. if ($resql)
  176. {
  177. $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
  178. //dol_syslog("ChargesSociales::create this->id=".$this->id);
  179. $result=$this->call_trigger('SOCIALCONTRIBUTION_CREATE',$user);
  180. if ($result < 0) $error++;
  181. if(empty($error)) {
  182. $this->db->commit();
  183. return $this->id;
  184. }
  185. else {
  186. $this->db->rollback();
  187. return -1*$error;
  188. }
  189. }
  190. else
  191. {
  192. $this->error=$this->db->error();
  193. $this->db->rollback();
  194. return -1;
  195. }
  196. }
  197. /**
  198. * Delete a social contribution
  199. *
  200. * @param User $user Object user making delete
  201. * @return int <0 if KO, >0 if OK
  202. */
  203. function delete($user)
  204. {
  205. $error=0;
  206. $this->db->begin();
  207. // Get bank transaction lines for this social contributions
  208. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  209. $account=new Account($this->db);
  210. $lines_url=$account->get_url('',$this->id,'sc');
  211. // Delete bank urls
  212. foreach ($lines_url as $line_url)
  213. {
  214. if (! $error)
  215. {
  216. $accountline=new AccountLine($this->db);
  217. $accountline->fetch($line_url['fk_bank']);
  218. $result=$accountline->delete_urls($user);
  219. if ($result < 0)
  220. {
  221. $error++;
  222. }
  223. }
  224. }
  225. // Delete payments
  226. if (! $error)
  227. {
  228. $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id;
  229. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  230. $resql=$this->db->query($sql);
  231. if (! $resql)
  232. {
  233. $error++;
  234. $this->error=$this->db->lasterror();
  235. }
  236. }
  237. if (! $error)
  238. {
  239. $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id;
  240. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  241. $resql=$this->db->query($sql);
  242. if (! $resql)
  243. {
  244. $error++;
  245. $this->error=$this->db->lasterror();
  246. }
  247. }
  248. if (! $error)
  249. {
  250. $this->db->commit();
  251. return 1;
  252. }
  253. else
  254. {
  255. $this->db->rollback();
  256. return -1;
  257. }
  258. }
  259. /**
  260. * Met a jour une charge sociale
  261. *
  262. * @param User $user Utilisateur qui modifie
  263. * @return int <0 si erreur, >0 si ok
  264. */
  265. function update($user)
  266. {
  267. $this->db->begin();
  268. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
  269. $sql.= " SET libelle='".$this->db->escape($this->lib)."'";
  270. $sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
  271. $sql.= ", periode='".$this->db->idate($this->periode)."'";
  272. $sql.= ", amount='".price2num($this->amount,'MT')."'";
  273. $sql.= ", fk_projet='".$this->db->escape($this->fk_project)."'";
  274. $sql.= ", fk_user_modif=".$user->id;
  275. $sql.= " WHERE rowid=".$this->id;
  276. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  277. $resql=$this->db->query($sql);
  278. if ($resql)
  279. {
  280. $this->db->commit();
  281. return 1;
  282. }
  283. else
  284. {
  285. $this->error=$this->db->error();
  286. $this->db->rollback();
  287. return -1;
  288. }
  289. }
  290. /**
  291. * Calculate amount remaining to pay by year
  292. *
  293. * @param int $year Year
  294. * @return number
  295. */
  296. function solde($year = 0)
  297. {
  298. global $conf;
  299. $sql = "SELECT SUM(f.amount) as amount";
  300. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
  301. $sql.= " WHERE f.entity = ".$conf->entity;
  302. $sql.= " AND paye = 0";
  303. if ($year) {
  304. $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
  305. }
  306. $result = $this->db->query($sql);
  307. if ($result)
  308. {
  309. if ($this->db->num_rows($result))
  310. {
  311. $obj = $this->db->fetch_object($result);
  312. $this->db->free($result);
  313. return $obj->amount;
  314. }
  315. else
  316. {
  317. return 0;
  318. }
  319. }
  320. else
  321. {
  322. print $this->db->error();
  323. return -1;
  324. }
  325. }
  326. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  327. /**
  328. * Tag social contribution as payed completely
  329. *
  330. * @param User $user Object user making change
  331. * @return int <0 if KO, >0 if OK
  332. */
  333. function set_paid($user)
  334. {
  335. // phpcs:enable
  336. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
  337. $sql.= " paye = 1";
  338. $sql.= " WHERE rowid = ".$this->id;
  339. $return = $this->db->query($sql);
  340. if ($return) return 1;
  341. else return -1;
  342. }
  343. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  344. /**
  345. * Remove tag payed on social contribution
  346. *
  347. * @param User $user Object user making change
  348. * @return int <0 if KO, >0 if OK
  349. */
  350. function set_unpaid($user)
  351. {
  352. // phpcs:enable
  353. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
  354. $sql.= " paye = 0";
  355. $sql.= " WHERE rowid = ".$this->id;
  356. $return = $this->db->query($sql);
  357. if ($return) return 1;
  358. else return -1;
  359. }
  360. /**
  361. * Retourne le libelle du statut d'une charge (impaye, payee)
  362. *
  363. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
  364. * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
  365. * @return string Label
  366. */
  367. function getLibStatut($mode=0,$alreadypaid=-1)
  368. {
  369. return $this->LibStatut($this->paye,$mode,$alreadypaid);
  370. }
  371. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  372. /**
  373. * Renvoi le libelle d'un statut donne
  374. *
  375. * @param int $statut Id statut
  376. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto
  377. * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
  378. * @return string Label
  379. */
  380. function LibStatut($statut,$mode=0,$alreadypaid=-1)
  381. {
  382. // phpcs:enable
  383. global $langs;
  384. $langs->load('customers');
  385. $langs->load('bills');
  386. if ($mode == 0 || $mode == 1)
  387. {
  388. if ($statut == 0) return $langs->trans("Unpaid");
  389. if ($statut == 1) return $langs->trans("Paid");
  390. }
  391. elseif ($mode == 2)
  392. {
  393. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
  394. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
  395. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
  396. }
  397. elseif ($mode == 3)
  398. {
  399. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
  400. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
  401. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
  402. }
  403. elseif ($mode == 4)
  404. {
  405. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
  406. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
  407. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
  408. }
  409. elseif ($mode == 5)
  410. {
  411. if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
  412. if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
  413. if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
  414. }
  415. elseif ($mode == 6)
  416. {
  417. if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
  418. if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
  419. if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
  420. }
  421. else return "Error, mode/status not found";
  422. }
  423. /**
  424. * Return a link to the object card (with optionaly the picto)
  425. *
  426. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  427. * @param int $maxlen Max length of label
  428. * @param int $notooltip 1=Disable tooltip
  429. * @param int $short 1=Return just URL
  430. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  431. * @return string String with link
  432. */
  433. function getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $short=0, $save_lastsearch_value=-1)
  434. {
  435. global $langs, $conf, $user, $form;
  436. if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
  437. $result='';
  438. $url = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id;
  439. if ($short) return $url;
  440. if ($option !== 'nolink')
  441. {
  442. // Add param to save lastsearch_values or not
  443. $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
  444. if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
  445. if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
  446. }
  447. if (empty($this->ref)) $this->ref=$this->lib;
  448. $label = '<u>'.$langs->trans("ShowSocialContribution").'</u>';
  449. if (! empty($this->ref))
  450. $label .= '<br><b>'.$langs->trans('Ref') . ':</b> ' . $this->ref;
  451. if (! empty($this->lib))
  452. $label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->lib;
  453. if (! empty($this->type_libelle))
  454. $label .= '<br><b>'.$langs->trans('Type') . ':</b> ' . $this->type_libelle;
  455. $linkclose='';
  456. if (empty($notooltip) && $user->rights->facture->lire)
  457. {
  458. if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  459. {
  460. $label=$langs->trans("ShowSocialContribution");
  461. $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
  462. }
  463. $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
  464. $linkclose.=' class="classfortooltip"';
  465. }
  466. $linkstart='<a href="'.$url.'"';
  467. $linkstart.=$linkclose.'>';
  468. $linkend='</a>';
  469. $result .= $linkstart;
  470. if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
  471. if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->ref,$maxlen):$this->ref);
  472. $result .= $linkend;
  473. return $result;
  474. }
  475. /**
  476. * Return amount of payments already done
  477. *
  478. * @return int Amount of payment already done, <0 if KO
  479. */
  480. function getSommePaiement()
  481. {
  482. $table='paiementcharge';
  483. $field='fk_charge';
  484. $sql = 'SELECT sum(amount) as amount';
  485. $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
  486. $sql.= ' WHERE '.$field.' = '.$this->id;
  487. dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
  488. $resql=$this->db->query($sql);
  489. if ($resql)
  490. {
  491. $amount=0;
  492. $obj = $this->db->fetch_object($resql);
  493. if ($obj) $amount=$obj->amount?$obj->amount:0;
  494. $this->db->free($resql);
  495. return $amount;
  496. }
  497. else
  498. {
  499. return -1;
  500. }
  501. }
  502. /**
  503. * Charge les informations d'ordre info dans l'objet entrepot
  504. *
  505. * @param int $id Id of social contribution
  506. * @return int <0 if KO, >0 if OK
  507. */
  508. function info($id)
  509. {
  510. $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
  511. $sql.= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
  512. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
  513. $sql.= " WHERE e.rowid = ".$id;
  514. dol_syslog(get_class($this)."::info", LOG_DEBUG);
  515. $result=$this->db->query($sql);
  516. if ($result)
  517. {
  518. if ($this->db->num_rows($result))
  519. {
  520. $obj = $this->db->fetch_object($result);
  521. $this->id = $obj->rowid;
  522. if ($obj->fk_user_author) {
  523. $cuser = new User($this->db);
  524. $cuser->fetch($obj->fk_user_author);
  525. $this->user_creation = $cuser;
  526. }
  527. if ($obj->fk_user_modif) {
  528. $muser = new User($this->db);
  529. $muser->fetch($obj->fk_user_modif);
  530. $this->user_modification = $muser;
  531. }
  532. if ($obj->fk_user_valid) {
  533. $vuser = new User($this->db);
  534. $vuser->fetch($obj->fk_user_valid);
  535. $this->user_validation = $vuser;
  536. }
  537. $this->date_creation = $this->db->jdate($obj->datec);
  538. $this->date_modification = $this->db->jdate($obj->datem);
  539. $this->date_validation = $this->db->jdate($obj->datev);
  540. $this->import_key = $obj->import_key;
  541. }
  542. $this->db->free($result);
  543. }
  544. else
  545. {
  546. dol_print_error($this->db);
  547. }
  548. }
  549. /**
  550. * Initialise an instance with random values.
  551. * Used to build previews or test instances.
  552. * id must be 0 if object instance is a specimen.
  553. *
  554. * @return void
  555. */
  556. function initAsSpecimen()
  557. {
  558. // Initialize parameters
  559. $this->id=0;
  560. $this->ref = 'SPECIMEN';
  561. $this->specimen=1;
  562. $this->paye = 0;
  563. $this->date = time();
  564. $this->date_ech=$this->date+3600*24*30;
  565. $this->periode=$this->date+3600*24*30;
  566. $this->amount=100;
  567. $this->lib = 0;
  568. $this->type = 1;
  569. $this->type_libelle = 'Social contribution label';
  570. }
  571. }