salary.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. /* Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/salaries/class/salary.class.php
  21. * \ingroup salaries
  22. * \brief Class for salaries module payment
  23. */
  24. // Put here all includes required by your class file
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  26. /**
  27. * Class to manage salary payments
  28. */
  29. class Salary extends CommonObject
  30. {
  31. /**
  32. * @var string ID to identify managed object
  33. */
  34. public $element = 'salary';
  35. /**
  36. * @var string Name of table without prefix where object is stored
  37. */
  38. public $table_element = 'salary';
  39. /**
  40. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  41. */
  42. public $picto = 'salary';
  43. public $tms;
  44. /**
  45. * @var int User ID
  46. */
  47. public $fk_user;
  48. public $datep;
  49. public $datev;
  50. public $salary;
  51. public $amount;
  52. /**
  53. * @var int ID
  54. */
  55. public $fk_project;
  56. public $type_payment;
  57. /**
  58. * @var string salary payments label
  59. */
  60. public $label;
  61. public $datesp;
  62. public $dateep;
  63. /**
  64. * @var int ID
  65. */
  66. public $fk_bank;
  67. /**
  68. * @var int ID
  69. */
  70. public $fk_user_author;
  71. /**
  72. * @var int ID
  73. */
  74. public $fk_user_modif;
  75. /**
  76. * @var user User
  77. */
  78. public $user;
  79. /**
  80. * 1 if salary paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
  81. */
  82. public $paye;
  83. const STATUS_UNPAID = 0;
  84. const STATUS_PAID = 1;
  85. /**
  86. * Constructor
  87. *
  88. * @param DoliDB $db Database handler
  89. */
  90. public function __construct($db)
  91. {
  92. $this->db = $db;
  93. $this->element = 'salary';
  94. $this->table_element = 'salary';
  95. }
  96. /**
  97. * Update database
  98. *
  99. * @param User $user User that modify
  100. * @param int $notrigger 0=no, 1=yes (no update trigger)
  101. * @return int <0 if KO, >0 if OK
  102. */
  103. public function update($user = null, $notrigger = 0)
  104. {
  105. global $conf, $langs;
  106. $error = 0;
  107. // Clean parameters
  108. $this->amount = trim($this->amount);
  109. $this->label = trim($this->label);
  110. $this->note = trim($this->note);
  111. // Check parameters
  112. if (empty($this->fk_user) || $this->fk_user < 0) {
  113. $this->error = 'ErrorBadParameter';
  114. return -1;
  115. }
  116. $this->db->begin();
  117. // Update request
  118. $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
  119. $sql .= " tms='".$this->db->idate(dol_now())."',";
  120. $sql .= " fk_user=".((int) $this->fk_user).",";
  121. /*$sql .= " datep='".$this->db->idate($this->datep)."',";
  122. $sql .= " datev='".$this->db->idate($this->datev)."',";*/
  123. $sql .= " amount=".price2num($this->amount).",";
  124. $sql .= " fk_projet=".((int) $this->fk_project).",";
  125. $sql .= " fk_typepayment=".((int) $this->type_payment).",";
  126. $sql .= " label='".$this->db->escape($this->label)."',";
  127. $sql .= " datesp='".$this->db->idate($this->datesp)."',";
  128. $sql .= " dateep='".$this->db->idate($this->dateep)."',";
  129. $sql .= " note='".$this->db->escape($this->note)."',";
  130. $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
  131. $sql .= " fk_user_author=".((int) $this->fk_user_author).",";
  132. $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
  133. $sql .= " WHERE rowid=".((int) $this->id);
  134. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  135. $resql = $this->db->query($sql);
  136. if (!$resql) {
  137. $this->error = "Error ".$this->db->lasterror();
  138. return -1;
  139. }
  140. // Update extrafield
  141. if (!$error) {
  142. if (!$error) {
  143. $result = $this->insertExtraFields();
  144. if ($result < 0) {
  145. $error++;
  146. }
  147. }
  148. }
  149. if (!$notrigger) {
  150. // Call trigger
  151. $result = $this->call_trigger('SALARY_MODIFY', $user);
  152. if ($result < 0) $error++;
  153. // End call triggers
  154. }
  155. if (!$error) {
  156. $this->db->commit();
  157. return 1;
  158. } else {
  159. $this->db->rollback();
  160. return -1;
  161. }
  162. }
  163. /**
  164. * Load object in memory from database
  165. *
  166. * @param int $id id object
  167. * @param User $user User that load
  168. * @return int <0 if KO, >0 if OK
  169. */
  170. public function fetch($id, $user = null)
  171. {
  172. global $langs;
  173. $sql = "SELECT";
  174. $sql .= " s.rowid,";
  175. $sql .= " s.tms,";
  176. $sql .= " s.fk_user,";
  177. $sql .= " s.datep,";
  178. $sql .= " s.datev,";
  179. $sql .= " s.amount,";
  180. $sql .= " s.fk_projet as fk_project,";
  181. $sql .= " s.fk_typepayment,";
  182. $sql .= " s.label,";
  183. $sql .= " s.datesp,";
  184. $sql .= " s.dateep,";
  185. $sql .= " s.note,";
  186. $sql .= " s.paye,";
  187. $sql .= " s.fk_bank,";
  188. $sql .= " s.fk_user_author,";
  189. $sql .= " s.fk_user_modif,";
  190. $sql .= " s.fk_account";
  191. $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
  192. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
  193. $sql .= " WHERE s.rowid = ".((int) $id);
  194. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  195. $resql = $this->db->query($sql);
  196. if ($resql) {
  197. if ($this->db->num_rows($resql)) {
  198. $obj = $this->db->fetch_object($resql);
  199. $this->id = $obj->rowid;
  200. $this->ref = $obj->rowid;
  201. $this->tms = $this->db->jdate($obj->tms);
  202. $this->fk_user = $obj->fk_user;
  203. $this->datep = $this->db->jdate($obj->datep);
  204. $this->datev = $this->db->jdate($obj->datev);
  205. $this->amount = $obj->amount;
  206. $this->fk_project = $obj->fk_project;
  207. $this->type_payment = $obj->fk_typepayment;
  208. $this->label = $obj->label;
  209. $this->datesp = $this->db->jdate($obj->datesp);
  210. $this->dateep = $this->db->jdate($obj->dateep);
  211. $this->note = $obj->note;
  212. $this->paye = $obj->paye;
  213. $this->fk_bank = $obj->fk_bank;
  214. $this->fk_user_author = $obj->fk_user_author;
  215. $this->fk_user_modif = $obj->fk_user_modif;
  216. $this->fk_account = $this->accountid = $obj->fk_account;
  217. // Retrieve all extrafield
  218. // fetch optionals attributes and labels
  219. $this->fetch_optionals();
  220. }
  221. $this->db->free($resql);
  222. return 1;
  223. } else {
  224. $this->error = "Error ".$this->db->lasterror();
  225. return -1;
  226. }
  227. }
  228. /**
  229. * Delete object in database
  230. *
  231. * @param User $user User that delete
  232. * @return int <0 if KO, >0 if OK
  233. */
  234. public function delete($user)
  235. {
  236. global $conf, $langs;
  237. $error = 0;
  238. // Call trigger
  239. $result = $this->call_trigger('SALARY_DELETE', $user);
  240. if ($result < 0) return -1;
  241. // End call triggers
  242. // Delete extrafields
  243. /*if (!$error)
  244. {
  245. $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary_extrafields";
  246. $sql .= " WHERE fk_object = ".((int) $this->id);
  247. $resql = $this->db->query($sql);
  248. if (!$resql)
  249. {
  250. $this->errors[] = $this->db->lasterror();
  251. $error++;
  252. }
  253. }*/
  254. $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary";
  255. $sql .= " WHERE rowid=".((int) $this->id);
  256. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  257. $resql = $this->db->query($sql);
  258. if (!$resql) {
  259. $this->error = "Error ".$this->db->lasterror();
  260. return -1;
  261. }
  262. return 1;
  263. }
  264. /**
  265. * Initialise an instance with random values.
  266. * Used to build previews or test instances.
  267. * id must be 0 if object instance is a specimen.
  268. *
  269. * @return void
  270. */
  271. public function initAsSpecimen()
  272. {
  273. $this->id = 0;
  274. $this->tms = '';
  275. $this->fk_user = '';
  276. $this->datep = '';
  277. $this->datev = '';
  278. $this->amount = '';
  279. $this->label = '';
  280. $this->datesp = '';
  281. $this->dateep = '';
  282. $this->note = '';
  283. $this->fk_bank = '';
  284. $this->fk_user_author = '';
  285. $this->fk_user_modif = '';
  286. }
  287. /**
  288. * Create in database
  289. *
  290. * @param User $user User that create
  291. * @return int <0 if KO, >0 if OK
  292. */
  293. public function create($user)
  294. {
  295. global $conf, $langs;
  296. $error = 0;
  297. $now = dol_now();
  298. // Clean parameters
  299. $this->amount = price2num(trim($this->amount));
  300. $this->label = trim($this->label);
  301. $this->note = trim($this->note);
  302. $this->fk_bank = trim($this->fk_bank);
  303. $this->fk_user_author = trim($this->fk_user_author);
  304. $this->fk_user_modif = trim($this->fk_user_modif);
  305. $this->accountid = trim($this->accountid);
  306. $this->paye = trim($this->paye);
  307. // Check parameters
  308. if (!$this->label) {
  309. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  310. return -3;
  311. }
  312. if ($this->fk_user < 0 || $this->fk_user == '') {
  313. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
  314. return -4;
  315. }
  316. if ($this->amount == '') {
  317. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  318. return -5;
  319. }
  320. /* if (isModEnabled("banque") && (empty($this->accountid) || $this->accountid <= 0))
  321. {
  322. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
  323. return -6;
  324. }
  325. if (isModEnabled("banque") && (empty($this->type_payment) || $this->type_payment <= 0))
  326. {
  327. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  328. return -7;
  329. }*/
  330. $this->db->begin();
  331. // Insert into llx_salary
  332. $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
  333. //$sql .= ", datep";
  334. //$sql .= ", datev";
  335. $sql .= ", amount";
  336. $sql .= ", fk_projet";
  337. $sql .= ", salary";
  338. $sql .= ", fk_typepayment";
  339. $sql .= ", fk_account";
  340. if ($this->note) $sql .= ", note";
  341. $sql .= ", label";
  342. $sql .= ", datesp";
  343. $sql .= ", dateep";
  344. $sql .= ", fk_user_author";
  345. $sql .= ", datec";
  346. $sql .= ", fk_bank";
  347. $sql .= ", entity";
  348. $sql .= ") ";
  349. $sql .= " VALUES (";
  350. $sql .= "'".$this->db->escape($this->fk_user)."'";
  351. //$sql .= ", '".$this->db->idate($this->datep)."'";
  352. //$sql .= ", '".$this->db->idate($this->datev)."'";
  353. $sql .= ", ".((double) $this->amount);
  354. $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
  355. $sql .= ", ".($this->salary > 0 ? ((double) $this->salary) : "null");
  356. $sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
  357. $sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
  358. if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'";
  359. $sql .= ", '".$this->db->escape($this->label)."'";
  360. $sql .= ", '".$this->db->idate($this->datesp)."'";
  361. $sql .= ", '".$this->db->idate($this->dateep)."'";
  362. $sql .= ", '".$this->db->escape($user->id)."'";
  363. $sql .= ", '".$this->db->idate($now)."'";
  364. $sql .= ", NULL";
  365. $sql .= ", ".((int) $conf->entity);
  366. $sql .= ")";
  367. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  368. $result = $this->db->query($sql);
  369. if ($result) {
  370. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
  371. if ($this->id > 0) {
  372. // Update extrafield
  373. if (!$error) {
  374. if (!$error) {
  375. $result = $this->insertExtraFields();
  376. if ($result < 0) {
  377. $error++;
  378. }
  379. }
  380. }
  381. // Call trigger
  382. $result = $this->call_trigger('SALARY_CREATE', $user);
  383. if ($result < 0) $error++;
  384. // End call triggers
  385. } else $error++;
  386. if (!$error) {
  387. $this->db->commit();
  388. return $this->id;
  389. } else {
  390. $this->db->rollback();
  391. return -2;
  392. }
  393. } else {
  394. $this->error = $this->db->error();
  395. $this->db->rollback();
  396. return -1;
  397. }
  398. }
  399. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  400. /**
  401. * Update link between payment salary and line generate into llx_bank
  402. *
  403. * @param int $id_bank Id bank account
  404. * @return int <0 if KO, >0 if OK
  405. */
  406. public function update_fk_bank($id_bank)
  407. {
  408. // phpcs:enable
  409. $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
  410. $sql .= " WHERE rowid = ".((int) $this->id);
  411. $result = $this->db->query($sql);
  412. if ($result) {
  413. return 1;
  414. } else {
  415. dol_print_error($this->db);
  416. return -1;
  417. }
  418. }
  419. /**
  420. * Send name clicable (with possibly the picto)
  421. *
  422. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  423. * @param string $option link option
  424. * @param int $notooltip 1=Disable tooltip
  425. * @param string $morecss Add more css on link
  426. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  427. * @return string Chaine with URL
  428. */
  429. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  430. {
  431. global $db, $conf, $langs, $hookmanager;
  432. global $dolibarr_main_authentication, $dolibarr_main_demo;
  433. global $menumanager;
  434. if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
  435. $result = '';
  436. $label = '<u>'.$langs->trans("Salary").'</u>';
  437. $label .= '<br>';
  438. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  439. if ($this->label) {
  440. $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
  441. }
  442. if ($this->datesp && $this->dateep) {
  443. $label .= '<br><b>'.$langs->trans('Period').':</b> '.dol_print_date($this->datesp, 'day').' - '.dol_print_date($this->dateep, 'day');
  444. }
  445. if (isset($this->amount)) {
  446. $label .= '<br><b>'.$langs->trans('Amount').':</b> '.price($this->amount);
  447. }
  448. $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
  449. if ($option != 'nolink') {
  450. // Add param to save lastsearch_values or not
  451. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  452. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
  453. if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
  454. }
  455. $linkclose = '';
  456. if (empty($notooltip)) {
  457. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  458. $label = $langs->trans("ShowMyObject");
  459. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  460. }
  461. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  462. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  463. /*
  464. $hookmanager->initHooks(array('myobjectdao'));
  465. $parameters=array('id'=>$this->id);
  466. $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  467. if ($reshook > 0) $linkclose = $hookmanager->resPrint;
  468. */
  469. } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  470. $linkstart = '<a href="'.$url.'"';
  471. $linkstart .= $linkclose.'>';
  472. $linkend = '</a>';
  473. $result .= $linkstart;
  474. if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright pictofixedwidth"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip pictofixedwidth"'), 0, 0, $notooltip ? 0 : 1);
  475. if ($withpicto != 2) $result .= $this->ref;
  476. $result .= $linkend;
  477. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  478. global $action, $hookmanager;
  479. $hookmanager->initHooks(array('salarypayment'));
  480. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  481. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  482. if ($reshook > 0) $result = $hookmanager->resPrint;
  483. else $result .= $hookmanager->resPrint;
  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. public function getSommePaiement()
  492. {
  493. $table = 'payment_salary';
  494. $field = 'fk_salary';
  495. $sql = 'SELECT sum(amount) as amount';
  496. $sql .= ' FROM '.MAIN_DB_PREFIX.$table;
  497. $sql .= " WHERE ".$field." = ".((int) $this->id);
  498. dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
  499. $resql = $this->db->query($sql);
  500. if ($resql) {
  501. $amount = 0;
  502. $obj = $this->db->fetch_object($resql);
  503. if ($obj) $amount = $obj->amount ? $obj->amount : 0;
  504. $this->db->free($resql);
  505. return $amount;
  506. } else {
  507. return -1;
  508. }
  509. }
  510. /**
  511. * Information on record
  512. *
  513. * @param int $id Id of record
  514. * @return void
  515. */
  516. public function info($id)
  517. {
  518. $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
  519. $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
  520. $sql .= ' WHERE ps.rowid = '.((int) $id);
  521. dol_syslog(get_class($this).'::info', LOG_DEBUG);
  522. $result = $this->db->query($sql);
  523. if ($result) {
  524. if ($this->db->num_rows($result)) {
  525. $obj = $this->db->fetch_object($result);
  526. $this->id = $obj->rowid;
  527. $this->user_creation_id = $obj->fk_user_author;
  528. $this->user_modification_id = $obj->fk_user_modif;
  529. $this->date_creation = $this->db->jdate($obj->datec);
  530. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  531. }
  532. $this->db->free($result);
  533. } else {
  534. dol_print_error($this->db);
  535. }
  536. }
  537. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  538. /**
  539. * Tag social contribution as payed completely
  540. *
  541. * @param User $user Object user making change
  542. * @return int <0 if KO, >0 if OK
  543. */
  544. public function set_paid($user)
  545. {
  546. // phpcs:enable
  547. $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
  548. $sql .= " paye = 1";
  549. $sql .= " WHERE rowid = ".((int) $this->id);
  550. $return = $this->db->query($sql);
  551. if ($return) return 1;
  552. else return -1;
  553. }
  554. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  555. /**
  556. * Remove tag payed on social contribution
  557. *
  558. * @param User $user Object user making change
  559. * @return int <0 if KO, >0 if OK
  560. */
  561. public function set_unpaid($user)
  562. {
  563. // phpcs:enable
  564. $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
  565. $sql .= " paye = 0";
  566. $sql .= " WHERE rowid = ".((int) $this->id);
  567. $return = $this->db->query($sql);
  568. if ($return) return 1;
  569. else return -1;
  570. }
  571. /**
  572. * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  573. *
  574. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  575. * @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)
  576. * @return string Label
  577. */
  578. public function getLibStatut($mode = 0, $alreadypaid = -1)
  579. {
  580. return $this->LibStatut($this->paye, $mode, $alreadypaid);
  581. }
  582. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  583. /**
  584. * Renvoi le libelle d'un statut donne
  585. *
  586. * @param int $status Id status
  587. * @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
  588. * @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)
  589. * @return string Label
  590. */
  591. public function LibStatut($status, $mode = 0, $alreadypaid = -1)
  592. {
  593. // phpcs:enable
  594. global $langs;
  595. // Load translation files required by the page
  596. $langs->loadLangs(array("customers", "bills"));
  597. // We reinit status array to force to redefine them because label may change according to properties values.
  598. $this->labelStatus = array();
  599. $this->labelStatusShort = array();
  600. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  601. global $langs;
  602. //$langs->load("mymodule");
  603. $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
  604. $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
  605. if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
  606. $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
  607. $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
  608. if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
  609. }
  610. $statusType = 'status1';
  611. if ($status == 0 && $alreadypaid <> 0) $statusType = 'status3';
  612. if ($status == 1) $statusType = 'status6';
  613. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  614. }
  615. }