paymentsalary.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <?php
  2. /* Copyright (C) 2011-2019 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/paymentsalary.class.php
  21. * \ingroup salaries
  22. * \brief File of class to manage payment of salaries
  23. */
  24. // Put here all includes required by your class file
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  27. /**
  28. * Class to manage payments of salaries
  29. */
  30. class PaymentSalary extends CommonObject
  31. {
  32. /**
  33. * @var string ID to identify managed object
  34. */
  35. public $element = 'payment_salary';
  36. /**
  37. * @var string Name of table without prefix where object is stored
  38. */
  39. public $table_element = 'payment_salary';
  40. /**
  41. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  42. */
  43. public $picto = 'payment';
  44. /**
  45. * @var int ID
  46. */
  47. public $fk_salary;
  48. public $datec = '';
  49. public $tms = '';
  50. public $datep = '';
  51. /**
  52. * @deprecated
  53. * @see $amount
  54. */
  55. public $total;
  56. public $amount; // Total amount of payment
  57. public $amounts = array(); // Array of amounts
  58. /**
  59. * @var int ID
  60. */
  61. public $fk_typepayment;
  62. /**
  63. * @var string
  64. * @deprecated
  65. */
  66. public $num_paiement;
  67. /**
  68. * @var string
  69. */
  70. public $num_payment;
  71. /**
  72. * @var int ID
  73. */
  74. public $fk_bank;
  75. /**
  76. * @var int ID
  77. */
  78. public $fk_user_author;
  79. /**
  80. * @var int ID
  81. */
  82. public $fk_user_modif;
  83. /**
  84. * @var array
  85. */
  86. public $fields = array(
  87. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
  88. );
  89. /**
  90. * Constructor
  91. *
  92. * @param DoliDB $db Database handler
  93. */
  94. public function __construct($db)
  95. {
  96. $this->db = $db;
  97. }
  98. /**
  99. * Create payment of salary into database.
  100. * Use this->amounts to have list of lines for the payment
  101. *
  102. * @param User $user User making payment
  103. * @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more
  104. * @return int <0 if KO, id of payment if OK
  105. */
  106. public function create($user, $closepaidcontrib = 0)
  107. {
  108. global $conf, $langs;
  109. $error = 0;
  110. $now = dol_now();
  111. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  112. // Validate parametres
  113. if (!$this->datepaye) {
  114. $this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
  115. return -1;
  116. }
  117. // Clean parameters
  118. if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
  119. if (isset($this->amount)) $this->amount = trim($this->amount);
  120. if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment;
  121. if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
  122. if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
  123. if (isset($this->note)) $this->note = trim($this->note);
  124. if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
  125. if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author;
  126. if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
  127. $totalamount = 0;
  128. foreach ($this->amounts as $key => $value) { // How payment is dispatch
  129. $newvalue = price2num($value, 'MT');
  130. $this->amounts[$key] = $newvalue;
  131. $totalamount += $newvalue;
  132. }
  133. $totalamount = price2num($totalamount);
  134. // Check parameters
  135. if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
  136. $this->db->begin();
  137. if ($totalamount != 0) {
  138. $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (entity, fk_salary, datec, datep, amount,";
  139. $sql .= " fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
  140. $sql .= " VALUES (".((int) $conf->entity).", ".((int) $this->chid).", '".$this->db->idate($now)."',";
  141. $sql .= " '".$this->db->idate($this->datepaye)."',";
  142. $sql .= " ".price2num($totalamount).",";
  143. $sql .= " ".((int) $this->paiementtype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".((int) $user->id).",";
  144. $sql .= " 0)";
  145. $resql = $this->db->query($sql);
  146. if ($resql) {
  147. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
  148. // Insere tableau des montants / factures
  149. foreach ($this->amounts as $key => $amount) {
  150. $contribid = $key;
  151. if (is_numeric($amount) && $amount <> 0) {
  152. $amount = price2num($amount);
  153. // If we want to closed payed invoices
  154. if ($closepaidcontrib) {
  155. $contrib = new Salary($this->db);
  156. $contrib->fetch($contribid);
  157. $paiement = $contrib->getSommePaiement();
  158. //$creditnotes=$contrib->getSumCreditNotesUsed();
  159. $creditnotes = 0;
  160. //$deposits=$contrib->getSumDepositsUsed();
  161. $deposits = 0;
  162. $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
  163. $remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT');
  164. if ($remaintopay == 0) {
  165. $result = $contrib->set_paid($user);
  166. } else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
  167. }
  168. }
  169. }
  170. } else {
  171. $error++;
  172. }
  173. }
  174. $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
  175. if ($result < 0) $error++;
  176. if ($totalamount != 0 && !$error) {
  177. $this->amount = $totalamount;
  178. $this->total = $totalamount; // deprecated
  179. $this->db->commit();
  180. return $this->id;
  181. } else {
  182. $this->error = $this->db->error();
  183. $this->db->rollback();
  184. return -1;
  185. }
  186. }
  187. /**
  188. * Load object in memory from database
  189. *
  190. * @param int $id Id object
  191. * @return int <0 if KO, >0 if OK
  192. */
  193. public function fetch($id)
  194. {
  195. global $langs;
  196. $sql = "SELECT";
  197. $sql .= " t.rowid,";
  198. $sql .= " t.fk_salary,";
  199. $sql .= " t.datec,";
  200. $sql .= " t.tms,";
  201. $sql .= " t.datep,";
  202. $sql .= " t.amount,";
  203. $sql .= " t.fk_typepayment,";
  204. $sql .= " t.num_payment as num_payment,";
  205. $sql .= " t.note,";
  206. $sql .= " t.fk_bank,";
  207. $sql .= " t.fk_user_author,";
  208. $sql .= " t.fk_user_modif,";
  209. $sql .= " pt.code as type_code, pt.libelle as type_label,";
  210. $sql .= ' b.fk_account';
  211. $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
  212. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
  213. $sql .= " WHERE t.rowid = ".((int) $id);
  214. // TODO link on entity of tax;
  215. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  216. $resql = $this->db->query($sql);
  217. if ($resql) {
  218. if ($this->db->num_rows($resql)) {
  219. $obj = $this->db->fetch_object($resql);
  220. $this->id = $obj->rowid;
  221. $this->ref = $obj->rowid;
  222. $this->fk_salary = $obj->fk_salary;
  223. $this->datec = $this->db->jdate($obj->datec);
  224. $this->tms = $this->db->jdate($obj->tms);
  225. $this->datep = $this->db->jdate($obj->datep);
  226. $this->amount = $obj->amount;
  227. $this->fk_typepayment = $obj->fk_typepayment;
  228. $this->num_paiement = $obj->num_payment;
  229. $this->num_payment = $obj->num_payment;
  230. $this->note = $obj->note;
  231. $this->fk_bank = $obj->fk_bank;
  232. $this->fk_user_author = $obj->fk_user_author;
  233. $this->fk_user_modif = $obj->fk_user_modif;
  234. $this->type_code = $obj->type_code;
  235. $this->type_label = $obj->type_label;
  236. $this->bank_account = $obj->fk_account;
  237. $this->bank_line = $obj->fk_bank;
  238. }
  239. $this->db->free($resql);
  240. return 1;
  241. } else {
  242. $this->error = "Error ".$this->db->lasterror();
  243. return -1;
  244. }
  245. }
  246. /**
  247. * Update database
  248. *
  249. * @param User $user User that modify
  250. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  251. * @return int <0 if KO, >0 if OK
  252. */
  253. public function update($user = null, $notrigger = 0)
  254. {
  255. global $conf, $langs;
  256. $error = 0;
  257. // Clean parameters
  258. if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
  259. if (isset($this->amount)) $this->amount = trim($this->amount);
  260. if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment;
  261. if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
  262. if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
  263. if (isset($this->note)) $this->note = trim($this->note);
  264. if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
  265. if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author;
  266. if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
  267. // Check parameters
  268. // Put here code to add control on parameters values
  269. // Update request
  270. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
  271. $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").",";
  272. $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
  273. $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
  274. $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
  275. $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
  276. $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
  277. $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
  278. $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
  279. $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").",";
  280. $sql .= " fk_user_author=".(isset($this->fk_user_author) ? $this->fk_user_author : "null").",";
  281. $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null")."";
  282. $sql .= " WHERE rowid=".((int) $this->id);
  283. $this->db->begin();
  284. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  285. $resql = $this->db->query($sql);
  286. if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
  287. // Commit or rollback
  288. if ($error) {
  289. foreach ($this->errors as $errmsg) {
  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. } else {
  296. $this->db->commit();
  297. return 1;
  298. }
  299. }
  300. /**
  301. * Delete object in database
  302. *
  303. * @param User $user User that delete
  304. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  305. * @return int <0 if KO, >0 if OK
  306. */
  307. public function delete($user, $notrigger = 0)
  308. {
  309. global $conf, $langs;
  310. $error = 0;
  311. dol_syslog(get_class($this)."::delete");
  312. $this->db->begin();
  313. if ($this->bank_line > 0) {
  314. $accline = new AccountLine($this->db);
  315. $accline->fetch($this->bank_line);
  316. $result = $accline->delete();
  317. if ($result < 0) {
  318. $this->errors[] = $accline->error;
  319. $error++;
  320. }
  321. }
  322. if (!$error) {
  323. $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
  324. $sql .= " WHERE rowid=".((int) $this->id);
  325. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  326. $resql = $this->db->query($sql);
  327. if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
  328. }
  329. // Commit or rollback
  330. if ($error) {
  331. foreach ($this->errors as $errmsg) {
  332. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  333. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  334. }
  335. $this->db->rollback();
  336. return -1 * $error;
  337. } else {
  338. $this->db->commit();
  339. return 1;
  340. }
  341. }
  342. /**
  343. * Load an object from its id and create a new one in database
  344. *
  345. * @param User $user User making the clone
  346. * @param int $fromid Id of object to clone
  347. * @return int New id of clone
  348. */
  349. public function createFromClone(User $user, $fromid)
  350. {
  351. $error = 0;
  352. $object = new PaymentSalary($this->db);
  353. $this->db->begin();
  354. // Load source object
  355. $object->fetch($fromid);
  356. $object->id = 0;
  357. $object->statut = 0;
  358. // Clear fields
  359. // ...
  360. // Create clone
  361. $object->context['createfromclone'] = 'createfromclone';
  362. $result = $object->create($user);
  363. // Other options
  364. if ($result < 0) {
  365. $this->error = $object->error;
  366. $error++;
  367. }
  368. unset($object->context['createfromclone']);
  369. // End
  370. if (!$error) {
  371. $this->db->commit();
  372. return $object->id;
  373. } else {
  374. $this->db->rollback();
  375. return -1;
  376. }
  377. }
  378. /**
  379. * Initialise an instance with random values.
  380. * Used to build previews or test instances.
  381. * id must be 0 if object instance is a specimen.
  382. *
  383. * @return void
  384. */
  385. public function initAsSpecimen()
  386. {
  387. $this->id = 0;
  388. $this->fk_salary = '';
  389. $this->datec = '';
  390. $this->tms = '';
  391. $this->datep = '';
  392. $this->amount = '';
  393. $this->fk_typepayment = '';
  394. $this->num_payment = '';
  395. $this->note_private = '';
  396. $this->note_public = '';
  397. $this->fk_bank = '';
  398. $this->fk_user_author = '';
  399. $this->fk_user_modif = '';
  400. }
  401. /**
  402. * Add record into bank for payment with links between this bank record and invoices of payment.
  403. * All payment properties must have been set first like after a call to create().
  404. *
  405. * @param User $user Object of user making payment
  406. * @param string $mode 'payment_salary'
  407. * @param string $label Label to use in bank record
  408. * @param int $accountid Id of bank account to do link with
  409. * @param string $emetteur_nom Name of transmitter
  410. * @param string $emetteur_banque Name of bank
  411. * @return int <0 if KO, >0 if OK
  412. */
  413. public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
  414. {
  415. global $conf;
  416. // Clean data
  417. $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
  418. $error = 0;
  419. if (!empty($conf->banque->enabled)) {
  420. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  421. $acc = new Account($this->db);
  422. $acc->fetch($accountid);
  423. $total = $this->amount;
  424. // Insert payment into llx_bank
  425. $bank_line_id = $acc->addline(
  426. $this->datepaye,
  427. $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
  428. $label,
  429. -$total,
  430. $this->num_payment,
  431. '',
  432. $user,
  433. $emetteur_nom,
  434. $emetteur_banque,
  435. '',
  436. $this->datev
  437. );
  438. // Update fk_bank into llx_paiement_salary.
  439. // so we know the payment that was used to generated the bank entry.
  440. if ($bank_line_id > 0) {
  441. $result = $this->update_fk_bank($bank_line_id);
  442. if ($result <= 0) {
  443. $error++;
  444. dol_print_error($this->db);
  445. }
  446. // Add link 'payment_salary' in bank_url between payment and bank transaction
  447. $url = '';
  448. if ($mode == 'payment_salary') {
  449. $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
  450. }
  451. if ($url) {
  452. $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
  453. if ($result <= 0) {
  454. $error++;
  455. dol_print_error($this->db);
  456. }
  457. }
  458. // Add link 'user' in bank_url between user and bank transaction
  459. foreach ($this->amounts as $key => $value) {
  460. if (!$error) {
  461. if ($mode == 'payment_salary') {
  462. $salary = new Salary($this->db);
  463. $salary->fetch($key);
  464. $salary->fetch_user($salary->fk_user);
  465. $fuser = $salary->user;
  466. if ($fuser->id > 0) {
  467. $result = $acc->add_url_line(
  468. $bank_line_id,
  469. $fuser->id,
  470. DOL_URL_ROOT.'/user/card.php?id=',
  471. $fuser->getFullName($langs),
  472. 'user'
  473. );
  474. }
  475. if ($result <= 0) {
  476. $this->error = $this->db->lasterror();
  477. dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
  478. $error++;
  479. }
  480. }
  481. }
  482. }
  483. } else {
  484. $this->error = $acc->error;
  485. $error++;
  486. }
  487. }
  488. if (!$error) {
  489. return 1;
  490. } else {
  491. return -1;
  492. }
  493. }
  494. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  495. /**
  496. * Mise a jour du lien entre le paiement de salaire et la ligne dans llx_bank generee
  497. *
  498. * @param int $id_bank Id if bank
  499. * @return int >0 if OK, <=0 if KO
  500. */
  501. public function update_fk_bank($id_bank)
  502. {
  503. // phpcs:enable
  504. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
  505. dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
  506. $result = $this->db->query($sql);
  507. if ($result) {
  508. return 1;
  509. } else {
  510. $this->error = $this->db->error();
  511. return 0;
  512. }
  513. }
  514. /**
  515. * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  516. *
  517. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  518. * @return string Libelle
  519. */
  520. public function getLibStatut($mode = 0)
  521. {
  522. return $this->LibStatut($this->statut, $mode);
  523. }
  524. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  525. /**
  526. * Renvoi le libelle d'un statut donne
  527. *
  528. * @param int $status Statut
  529. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  530. * @return string Libelle du statut
  531. */
  532. public function LibStatut($status, $mode = 0)
  533. {
  534. // phpcs:enable
  535. global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
  536. $langs->load('compta');
  537. /*if ($mode == 0)
  538. {
  539. if ($status == 0) return $langs->trans('ToValidate');
  540. if ($status == 1) return $langs->trans('Validated');
  541. }
  542. if ($mode == 1)
  543. {
  544. if ($status == 0) return $langs->trans('ToValidate');
  545. if ($status == 1) return $langs->trans('Validated');
  546. }
  547. if ($mode == 2)
  548. {
  549. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
  550. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  551. }
  552. if ($mode == 3)
  553. {
  554. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
  555. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
  556. }
  557. if ($mode == 4)
  558. {
  559. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
  560. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  561. }
  562. if ($mode == 5)
  563. {
  564. if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
  565. if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
  566. }
  567. if ($mode == 6)
  568. {
  569. if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
  570. if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
  571. }*/
  572. return '';
  573. }
  574. /**
  575. * Return clicable name (with picto eventually)
  576. *
  577. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  578. * @param int $maxlen Longueur max libelle
  579. * @return string Chaine avec URL
  580. */
  581. public function getNomUrl($withpicto = 0, $maxlen = 0)
  582. {
  583. global $langs;
  584. $result = '';
  585. if (empty($this->ref)) $this->ref = $this->lib;
  586. $label = img_picto('', $this->picto).' <u>'.$langs->trans("SalaryPayment").'</u>';
  587. $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
  588. if (!empty($this->label)) {
  589. $labeltoshow = $this->label;
  590. $reg = array();
  591. if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) {
  592. // Label generique car entre parentheses. On l'affiche en le traduisant
  593. if ($reg[1] == 'paiement') $reg[1] = 'Payment';
  594. $labeltoshow = $langs->trans($reg[1]);
  595. }
  596. $label .= '<br><b>'.$langs->trans('Label').':</b> '.$labeltoshow;
  597. }
  598. if ($this->datep) {
  599. $label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'day');
  600. }
  601. if (!empty($this->id)) {
  602. $link = '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
  603. $linkend = '</a>';
  604. if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
  605. if ($withpicto && $withpicto != 2) $result .= ' ';
  606. if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
  607. }
  608. return $result;
  609. }
  610. }