chargesociales.class.php 21 KB

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