chargesociales.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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@open-dsi.fr>
  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. /**
  60. * @var int ID
  61. */
  62. public $fk_account;
  63. /**
  64. * @var int ID
  65. */
  66. public $fk_project;
  67. /**
  68. * Constructor
  69. *
  70. * @param DoliDB $db Database handler
  71. */
  72. function __construct($db)
  73. {
  74. $this->db = $db;
  75. }
  76. /**
  77. * Retrouve et charge une charge sociale
  78. *
  79. * @param int $id Id
  80. * @param string $ref Ref
  81. * @return int <0 KO >0 OK
  82. */
  83. function fetch($id, $ref = '')
  84. {
  85. $sql = "SELECT cs.rowid, cs.date_ech";
  86. $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
  87. $sql.= ", cs.fk_account, cs.fk_mode_reglement";
  88. $sql.= ", c.libelle";
  89. $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
  90. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
  91. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id";
  92. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id';
  93. $sql.= ' WHERE cs.entity IN ('.getEntity('tax').')';
  94. if ($ref) $sql.= " AND cs.rowid = ".$ref;
  95. else $sql.= " AND cs.rowid = ".$id;
  96. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  97. $resql=$this->db->query($sql);
  98. if ($resql)
  99. {
  100. if ($this->db->num_rows($resql))
  101. {
  102. $obj = $this->db->fetch_object($resql);
  103. $this->id = $obj->rowid;
  104. $this->ref = $obj->rowid;
  105. $this->date_ech = $this->db->jdate($obj->date_ech);
  106. $this->lib = $obj->lib;
  107. $this->type = $obj->fk_type;
  108. $this->type_libelle = $obj->libelle;
  109. $this->fk_account = $obj->fk_account;
  110. $this->mode_reglement_id = $obj->fk_mode_reglement;
  111. $this->mode_reglement_code = $obj->mode_reglement_code;
  112. $this->mode_reglement = $obj->mode_reglement_libelle;
  113. $this->amount = $obj->amount;
  114. $this->fk_project = $obj->fk_project;
  115. $this->paye = $obj->paye;
  116. $this->periode = $this->db->jdate($obj->periode);
  117. $this->import_key = $this->import_key;
  118. $this->db->free($resql);
  119. return 1;
  120. }
  121. else
  122. {
  123. return 0;
  124. }
  125. }
  126. else
  127. {
  128. $this->error=$this->db->lasterror();
  129. return -1;
  130. }
  131. }
  132. /**
  133. * Check if a social contribution can be created into database
  134. *
  135. * @return boolean True or false
  136. */
  137. function check()
  138. {
  139. $newamount=price2num($this->amount,'MT');
  140. // Validation parametres
  141. if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
  142. {
  143. return false;
  144. }
  145. return true;
  146. }
  147. /**
  148. * Create a social contribution into database
  149. *
  150. * @param User $user User making creation
  151. * @return int <0 if KO, id if OK
  152. */
  153. function create($user)
  154. {
  155. global $conf;
  156. $error=0;
  157. $now=dol_now();
  158. // Nettoyage parametres
  159. $newamount=price2num($this->amount,'MT');
  160. if (!$this->check())
  161. {
  162. $this->error="ErrorBadParameter";
  163. return -2;
  164. }
  165. $this->db->begin();
  166. $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)";
  167. $sql.= " VALUES (".$this->type;
  168. $sql.= ", ".($this->fk_account>0 ? $this->fk_account:'NULL');
  169. $sql.= ", ".($this->mode_reglement_id>0 ? $this->mode_reglement_id:"NULL");
  170. $sql.= ", '".$this->db->escape($this->lib)."'";
  171. $sql.= ", '".$this->db->idate($this->date_ech)."'";
  172. $sql.= ", '".$this->db->idate($this->periode)."'";
  173. $sql.= ", '".price2num($newamount)."'";
  174. $sql.= ", ".($this->fk_project>0?$this->fk_project:'NULL');
  175. $sql.= ", ".$conf->entity;
  176. $sql.= ", ".$user->id;
  177. $sql.= ", '".$this->db->idate($now)."'";
  178. $sql.= ")";
  179. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  180. $resql=$this->db->query($sql);
  181. if ($resql)
  182. {
  183. $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."chargesociales");
  184. //dol_syslog("ChargesSociales::create this->id=".$this->id);
  185. $result=$this->call_trigger('SOCIALCONTRIBUTION_CREATE',$user);
  186. if ($result < 0) $error++;
  187. if(empty($error)) {
  188. $this->db->commit();
  189. return $this->id;
  190. }
  191. else {
  192. $this->db->rollback();
  193. return -1*$error;
  194. }
  195. }
  196. else
  197. {
  198. $this->error=$this->db->error();
  199. $this->db->rollback();
  200. return -1;
  201. }
  202. }
  203. /**
  204. * Delete a social contribution
  205. *
  206. * @param User $user Object user making delete
  207. * @return int <0 if KO, >0 if OK
  208. */
  209. function delete($user)
  210. {
  211. $error=0;
  212. $this->db->begin();
  213. // Get bank transaction lines for this social contributions
  214. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  215. $account=new Account($this->db);
  216. $lines_url=$account->get_url('',$this->id,'sc');
  217. // Delete bank urls
  218. foreach ($lines_url as $line_url)
  219. {
  220. if (! $error)
  221. {
  222. $accountline=new AccountLine($this->db);
  223. $accountline->fetch($line_url['fk_bank']);
  224. $result=$accountline->delete_urls($user);
  225. if ($result < 0)
  226. {
  227. $error++;
  228. }
  229. }
  230. }
  231. // Delete payments
  232. if (! $error)
  233. {
  234. $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge=".$this->id;
  235. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  236. $resql=$this->db->query($sql);
  237. if (! $resql)
  238. {
  239. $error++;
  240. $this->error=$this->db->lasterror();
  241. }
  242. }
  243. if (! $error)
  244. {
  245. $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid=".$this->id;
  246. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  247. $resql=$this->db->query($sql);
  248. if (! $resql)
  249. {
  250. $error++;
  251. $this->error=$this->db->lasterror();
  252. }
  253. }
  254. if (! $error)
  255. {
  256. $this->db->commit();
  257. return 1;
  258. }
  259. else
  260. {
  261. $this->db->rollback();
  262. return -1;
  263. }
  264. }
  265. /**
  266. * Met a jour une charge sociale
  267. *
  268. * @param User $user Utilisateur qui modifie
  269. * @return int <0 si erreur, >0 si ok
  270. */
  271. function update($user)
  272. {
  273. $this->db->begin();
  274. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales";
  275. $sql.= " SET libelle='".$this->db->escape($this->lib)."'";
  276. $sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
  277. $sql.= ", periode='".$this->db->idate($this->periode)."'";
  278. $sql.= ", amount='".price2num($this->amount,'MT')."'";
  279. $sql.= ", fk_projet='".$this->db->escape($this->fk_project)."'";
  280. $sql.= ", fk_user_modif=".$user->id;
  281. $sql.= " WHERE rowid=".$this->id;
  282. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  283. $resql=$this->db->query($sql);
  284. if ($resql)
  285. {
  286. $this->db->commit();
  287. return 1;
  288. }
  289. else
  290. {
  291. $this->error=$this->db->error();
  292. $this->db->rollback();
  293. return -1;
  294. }
  295. }
  296. /**
  297. * Calculate amount remaining to pay by year
  298. *
  299. * @param int $year Year
  300. * @return number
  301. */
  302. function solde($year = 0)
  303. {
  304. global $conf;
  305. $sql = "SELECT SUM(f.amount) as amount";
  306. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f";
  307. $sql.= " WHERE f.entity = ".$conf->entity;
  308. $sql.= " AND paye = 0";
  309. if ($year) {
  310. $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' ";
  311. }
  312. $result = $this->db->query($sql);
  313. if ($result)
  314. {
  315. if ($this->db->num_rows($result))
  316. {
  317. $obj = $this->db->fetch_object($result);
  318. $this->db->free($result);
  319. return $obj->amount;
  320. }
  321. else
  322. {
  323. return 0;
  324. }
  325. }
  326. else
  327. {
  328. print $this->db->error();
  329. return -1;
  330. }
  331. }
  332. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  333. /**
  334. * Tag social contribution as payed completely
  335. *
  336. * @param User $user Object user making change
  337. * @return int <0 if KO, >0 if OK
  338. */
  339. function set_paid($user)
  340. {
  341. // phpcs:enable
  342. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
  343. $sql.= " paye = 1";
  344. $sql.= " WHERE rowid = ".$this->id;
  345. $return = $this->db->query($sql);
  346. if ($return) return 1;
  347. else return -1;
  348. }
  349. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  350. /**
  351. * Remove tag payed on social contribution
  352. *
  353. * @param User $user Object user making change
  354. * @return int <0 if KO, >0 if OK
  355. */
  356. function set_unpaid($user)
  357. {
  358. // phpcs:enable
  359. $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
  360. $sql.= " paye = 0";
  361. $sql.= " WHERE rowid = ".$this->id;
  362. $return = $this->db->query($sql);
  363. if ($return) return 1;
  364. else return -1;
  365. }
  366. /**
  367. * Retourne le libelle du statut d'une charge (impaye, payee)
  368. *
  369. * @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
  370. * @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)
  371. * @return string Label
  372. */
  373. function getLibStatut($mode = 0, $alreadypaid = -1)
  374. {
  375. return $this->LibStatut($this->paye,$mode,$alreadypaid);
  376. }
  377. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  378. /**
  379. * Renvoi le libelle d'un statut donne
  380. *
  381. * @param int $statut Id statut
  382. * @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
  383. * @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)
  384. * @return string Label
  385. */
  386. function LibStatut($statut, $mode = 0, $alreadypaid = -1)
  387. {
  388. // phpcs:enable
  389. global $langs;
  390. // Load translation files required by the page
  391. $langs->loadLangs(array("customers","bills"));
  392. if ($mode == 0 || $mode == 1)
  393. {
  394. if ($statut == 0) return $langs->trans("Unpaid");
  395. if ($statut == 1) return $langs->trans("Paid");
  396. }
  397. elseif ($mode == 2)
  398. {
  399. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
  400. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
  401. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
  402. }
  403. elseif ($mode == 3)
  404. {
  405. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1');
  406. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3');
  407. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6');
  408. }
  409. elseif ($mode == 4)
  410. {
  411. if ($statut == 0 && $alreadypaid <= 0) return img_picto($langs->trans("Unpaid"), 'statut1').' '.$langs->trans("Unpaid");
  412. if ($statut == 0 && $alreadypaid > 0) return img_picto($langs->trans("BillStatusStarted"), 'statut3').' '.$langs->trans("BillStatusStarted");
  413. if ($statut == 1) return img_picto($langs->trans("Paid"), 'statut6').' '.$langs->trans("Paid");
  414. }
  415. elseif ($mode == 5)
  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. elseif ($mode == 6)
  422. {
  423. if ($statut == 0 && $alreadypaid <= 0) return $langs->trans("Unpaid").' '.img_picto($langs->trans("Unpaid"), 'statut1');
  424. if ($statut == 0 && $alreadypaid > 0) return $langs->trans("BillStatusStarted").' '.img_picto($langs->trans("BillStatusStarted"), 'statut3');
  425. if ($statut == 1) return $langs->trans("Paid").' '.img_picto($langs->trans("Paid"), 'statut6');
  426. }
  427. else return "Error, mode/status not found";
  428. }
  429. /**
  430. * Return a link to the object card (with optionaly the picto)
  431. *
  432. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  433. * @param int $maxlen Max length of label
  434. * @param int $notooltip 1=Disable tooltip
  435. * @param int $short 1=Return just URL
  436. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  437. * @return string String with link
  438. */
  439. function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $short = 0, $save_lastsearch_value = -1)
  440. {
  441. global $langs, $conf, $user, $form;
  442. if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
  443. $result='';
  444. $url = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$this->id;
  445. if ($short) return $url;
  446. if ($option !== 'nolink')
  447. {
  448. // Add param to save lastsearch_values or not
  449. $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
  450. if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
  451. if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
  452. }
  453. if (empty($this->ref)) $this->ref=$this->lib;
  454. $label = '<u>'.$langs->trans("ShowSocialContribution").'</u>';
  455. if (! empty($this->ref))
  456. $label .= '<br><b>'.$langs->trans('Ref') . ':</b> ' . $this->ref;
  457. if (! empty($this->lib))
  458. $label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->lib;
  459. if (! empty($this->type_libelle))
  460. $label .= '<br><b>'.$langs->trans('Type') . ':</b> ' . $this->type_libelle;
  461. $linkclose='';
  462. if (empty($notooltip) && $user->rights->facture->lire)
  463. {
  464. if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  465. {
  466. $label=$langs->trans("ShowSocialContribution");
  467. $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
  468. }
  469. $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
  470. $linkclose.=' class="classfortooltip"';
  471. }
  472. $linkstart='<a href="'.$url.'"';
  473. $linkstart.=$linkclose.'>';
  474. $linkend='</a>';
  475. $result .= $linkstart;
  476. 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);
  477. if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->ref,$maxlen):$this->ref);
  478. $result .= $linkend;
  479. return $result;
  480. }
  481. /**
  482. * Return amount of payments already done
  483. *
  484. * @return int Amount of payment already done, <0 if KO
  485. */
  486. function getSommePaiement()
  487. {
  488. $table='paiementcharge';
  489. $field='fk_charge';
  490. $sql = 'SELECT sum(amount) as amount';
  491. $sql.= ' FROM '.MAIN_DB_PREFIX.$table;
  492. $sql.= ' WHERE '.$field.' = '.$this->id;
  493. dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
  494. $resql=$this->db->query($sql);
  495. if ($resql)
  496. {
  497. $amount=0;
  498. $obj = $this->db->fetch_object($resql);
  499. if ($obj) $amount=$obj->amount?$obj->amount:0;
  500. $this->db->free($resql);
  501. return $amount;
  502. }
  503. else
  504. {
  505. return -1;
  506. }
  507. }
  508. /**
  509. * Charge les informations d'ordre info dans l'objet entrepot
  510. *
  511. * @param int $id Id of social contribution
  512. * @return int <0 if KO, >0 if OK
  513. */
  514. function info($id)
  515. {
  516. $sql = "SELECT e.rowid, e.tms as datem, e.date_creation as datec, e.date_valid as datev, e.import_key,";
  517. $sql.= " e.fk_user_author, e.fk_user_modif, e.fk_user_valid";
  518. $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as e";
  519. $sql.= " WHERE e.rowid = ".$id;
  520. dol_syslog(get_class($this)."::info", LOG_DEBUG);
  521. $result=$this->db->query($sql);
  522. if ($result)
  523. {
  524. if ($this->db->num_rows($result))
  525. {
  526. $obj = $this->db->fetch_object($result);
  527. $this->id = $obj->rowid;
  528. if ($obj->fk_user_author) {
  529. $cuser = new User($this->db);
  530. $cuser->fetch($obj->fk_user_author);
  531. $this->user_creation = $cuser;
  532. }
  533. if ($obj->fk_user_modif) {
  534. $muser = new User($this->db);
  535. $muser->fetch($obj->fk_user_modif);
  536. $this->user_modification = $muser;
  537. }
  538. if ($obj->fk_user_valid) {
  539. $vuser = new User($this->db);
  540. $vuser->fetch($obj->fk_user_valid);
  541. $this->user_validation = $vuser;
  542. }
  543. $this->date_creation = $this->db->jdate($obj->datec);
  544. $this->date_modification = $this->db->jdate($obj->datem);
  545. $this->date_validation = $this->db->jdate($obj->datev);
  546. $this->import_key = $obj->import_key;
  547. }
  548. $this->db->free($result);
  549. }
  550. else
  551. {
  552. dol_print_error($this->db);
  553. }
  554. }
  555. /**
  556. * Initialise an instance with random values.
  557. * Used to build previews or test instances.
  558. * id must be 0 if object instance is a specimen.
  559. *
  560. * @return void
  561. */
  562. function initAsSpecimen()
  563. {
  564. // Initialize parameters
  565. $this->id=0;
  566. $this->ref = 'SPECIMEN';
  567. $this->specimen=1;
  568. $this->paye = 0;
  569. $this->date = time();
  570. $this->date_ech=$this->date+3600*24*30;
  571. $this->periode=$this->date+3600*24*30;
  572. $this->amount=100;
  573. $this->lib = 0;
  574. $this->type = 1;
  575. $this->type_libelle = 'Social contribution label';
  576. }
  577. }