paymentvat.class.php 21 KB

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