paymentsocialcontribution.class.php 22 KB

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