paymentvarious.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <?php
  2. /* Copyright (C) 2017-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/bank/class/paymentvarious.class.php
  20. * \ingroup bank
  21. * \brief Class for various payment
  22. */
  23. // Put here all includes required by your class file
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  25. /**
  26. * Class to manage various payments
  27. */
  28. class PaymentVarious extends CommonObject
  29. {
  30. /**
  31. * @var string ID to identify managed object
  32. */
  33. public $element = 'variouspayment';
  34. /**
  35. * @var string Name of table without prefix where object is stored
  36. */
  37. public $table_element = 'payment_various';
  38. /**
  39. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  40. */
  41. public $picto = 'payment';
  42. /**
  43. * @var int ID
  44. */
  45. public $id;
  46. /**
  47. * @var string Ref
  48. */
  49. public $ref;
  50. /**
  51. * @var int timestamp
  52. */
  53. public $tms;
  54. public $datep;
  55. public $datev;
  56. /**
  57. * @var int sens of operation
  58. */
  59. public $sens;
  60. public $amount;
  61. public $type_payment;
  62. public $num_payment;
  63. public $chqemetteur;
  64. public $chqbank;
  65. public $category_transaction;
  66. /**
  67. * @var string various payments label
  68. */
  69. public $label;
  70. /**
  71. * @var string accountancy code
  72. */
  73. public $accountancy_code;
  74. /**
  75. * @var string subledger account
  76. */
  77. public $subledger_account;
  78. /**
  79. * @var int ID
  80. */
  81. public $fk_project;
  82. /**
  83. * @var int Bank account ID
  84. */
  85. public $fk_account;
  86. /**
  87. * @var int Bank account ID
  88. * @deprecated See fk_account
  89. */
  90. public $accountid;
  91. /**
  92. * @var int ID record into llx_bank
  93. */
  94. public $fk_bank;
  95. /**
  96. * @var int transaction category
  97. */
  98. public $categorie_transaction;
  99. /**
  100. * @var int ID
  101. */
  102. public $fk_user_author;
  103. /**
  104. * @var int ID
  105. */
  106. public $fk_user_modif;
  107. /**
  108. * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
  109. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  110. * 'label' the translation key.
  111. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
  112. * 'position' is the sort order of field.
  113. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  114. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
  115. * 'noteditable' says if field is not editable (1 or 0)
  116. * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
  117. * 'index' if we want an index in database.
  118. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  119. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  120. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  121. * 'css' is the CSS style to use on field. For example: 'maxwidth200'
  122. * 'help' is a string visible as a tooltip on field
  123. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  124. * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
  125. * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  126. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  127. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  128. *
  129. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  130. */
  131. // BEGIN MODULEBUILDER PROPERTIES
  132. /**
  133. * @var array fields definition
  134. */
  135. public $fields = array(
  136. // TODO: fill this array
  137. );
  138. // END MODULEBUILDER PROPERTIES
  139. /**
  140. * Constructor
  141. *
  142. * @param DoliDB $db Database handler
  143. */
  144. public function __construct($db)
  145. {
  146. $this->db = $db;
  147. $this->element = 'payment_various';
  148. $this->table_element = 'payment_various';
  149. }
  150. /**
  151. * Update database
  152. *
  153. * @param User $user User that modify
  154. * @param int $notrigger 0=no, 1=yes (no update trigger)
  155. * @return int <0 if KO, >0 if OK
  156. */
  157. public function update($user = null, $notrigger = 0)
  158. {
  159. global $conf, $langs;
  160. $error = 0;
  161. // Clean parameters
  162. $this->amount = trim($this->amount);
  163. $this->label = trim($this->label);
  164. $this->note = trim($this->note);
  165. $this->fk_bank = (int) $this->fk_bank;
  166. $this->fk_user_author = (int) $this->fk_user_author;
  167. $this->fk_user_modif = (int) $this->fk_user_modif;
  168. $this->db->begin();
  169. // Update request
  170. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_various SET";
  171. if ($this->tms) {
  172. $sql .= " tms='".$this->db->idate($this->tms)."',";
  173. }
  174. $sql .= " datep='".$this->db->idate($this->datep)."',";
  175. $sql .= " datev='".$this->db->idate($this->datev)."',";
  176. $sql .= " sens=".(int) $this->sens.",";
  177. $sql .= " amount=".price2num($this->amount).",";
  178. $sql .= " fk_typepayment=".(int) $this->type_payment.",";
  179. $sql .= " num_payment='".$this->db->escape($this->num_payment)."',";
  180. $sql .= " label='".$this->db->escape($this->label)."',";
  181. $sql .= " note='".$this->db->escape($this->note)."',";
  182. $sql .= " accountancy_code='".$this->db->escape($this->accountancy_code)."',";
  183. $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',";
  184. $sql .= " fk_projet='".$this->db->escape($this->fk_project)."',";
  185. $sql .= " fk_bank=".($this->fk_bank > 0 ? $this->fk_bank : "null").",";
  186. $sql .= " fk_user_author=".(int) $this->fk_user_author.",";
  187. $sql .= " fk_user_modif=".(int) $this->fk_user_modif;
  188. $sql .= " WHERE rowid=".((int) $this->id);
  189. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  190. $resql = $this->db->query($sql);
  191. if (!$resql) {
  192. $this->error = "Error ".$this->db->lasterror();
  193. return -1;
  194. }
  195. if (!$notrigger) {
  196. // Call trigger
  197. $result = $this->call_trigger('PAYMENT_VARIOUS_MODIFY', $user);
  198. if ($result < 0) {
  199. $error++;
  200. }
  201. // End call triggers
  202. }
  203. if (!$error) {
  204. $this->db->commit();
  205. return 1;
  206. } else {
  207. $this->db->rollback();
  208. return -1;
  209. }
  210. }
  211. /**
  212. * Load object in memory from database
  213. *
  214. * @param int $id id object
  215. * @param User $user User that load
  216. * @return int <0 if KO, >0 if OK
  217. */
  218. public function fetch($id, $user = null)
  219. {
  220. global $langs;
  221. $sql = "SELECT";
  222. $sql .= " v.rowid,";
  223. $sql .= " v.tms,";
  224. $sql .= " v.datep,";
  225. $sql .= " v.datev,";
  226. $sql .= " v.sens,";
  227. $sql .= " v.amount,";
  228. $sql .= " v.fk_typepayment,";
  229. $sql .= " v.num_payment,";
  230. $sql .= " v.label,";
  231. $sql .= " v.note,";
  232. $sql .= " v.accountancy_code,";
  233. $sql .= " v.subledger_account,";
  234. $sql .= " v.fk_projet as fk_project,";
  235. $sql .= " v.fk_bank,";
  236. $sql .= " v.fk_user_author,";
  237. $sql .= " v.fk_user_modif,";
  238. $sql .= " b.fk_account,";
  239. $sql .= " b.fk_type,";
  240. $sql .= " b.rappro";
  241. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  242. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  243. $sql .= " WHERE v.rowid = ".((int) $id);
  244. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  245. $resql = $this->db->query($sql);
  246. if ($resql) {
  247. if ($this->db->num_rows($resql)) {
  248. $obj = $this->db->fetch_object($resql);
  249. $this->id = $obj->rowid;
  250. $this->ref = $obj->rowid;
  251. $this->tms = $this->db->jdate($obj->tms);
  252. $this->datep = $this->db->jdate($obj->datep);
  253. $this->datev = $this->db->jdate($obj->datev);
  254. $this->sens = $obj->sens;
  255. $this->amount = $obj->amount;
  256. $this->type_payment = $obj->fk_typepayment;
  257. $this->num_payment = $obj->num_payment;
  258. $this->label = $obj->label;
  259. $this->note = $obj->note;
  260. $this->subledger_account = $obj->subledger_account;
  261. $this->accountancy_code = $obj->accountancy_code;
  262. $this->fk_project = $obj->fk_project;
  263. $this->fk_bank = $obj->fk_bank;
  264. $this->fk_user_author = $obj->fk_user_author;
  265. $this->fk_user_modif = $obj->fk_user_modif;
  266. $this->fk_account = $obj->fk_account;
  267. $this->fk_type = $obj->fk_type;
  268. $this->rappro = $obj->rappro;
  269. }
  270. $this->db->free($resql);
  271. return 1;
  272. } else {
  273. $this->error = "Error ".$this->db->lasterror();
  274. return -1;
  275. }
  276. }
  277. /**
  278. * Delete object in database
  279. *
  280. * @param User $user User that delete
  281. * @return int <0 if KO, >0 if OK
  282. */
  283. public function delete($user)
  284. {
  285. global $conf, $langs;
  286. $error = 0;
  287. // Call trigger
  288. $result = $this->call_trigger('PAYMENT_VARIOUS_DELETE', $user);
  289. if ($result < 0) {
  290. return -1;
  291. }
  292. // End call triggers
  293. $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_various";
  294. $sql .= " WHERE rowid=".((int) $this->id);
  295. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  296. $resql = $this->db->query($sql);
  297. if (!$resql) {
  298. $this->error = "Error ".$this->db->lasterror();
  299. return -1;
  300. }
  301. return 1;
  302. }
  303. /**
  304. * Initialise an instance with random values.
  305. * Used to build previews or test instances.
  306. * id must be 0 if object instance is a specimen.
  307. *
  308. * @return void
  309. */
  310. public function initAsSpecimen()
  311. {
  312. $this->id = 0;
  313. $this->tms = '';
  314. $this->datep = '';
  315. $this->datev = '';
  316. $this->sens = '';
  317. $this->amount = '';
  318. $this->label = '';
  319. $this->accountancy_code = '';
  320. $this->subledger_account = '';
  321. $this->note = '';
  322. $this->fk_bank = '';
  323. $this->fk_user_author = '';
  324. $this->fk_user_modif = '';
  325. }
  326. /**
  327. * Check if a miscellaneous payment can be created into database
  328. *
  329. * @return boolean True or false
  330. */
  331. public function check()
  332. {
  333. $newamount = price2num($this->amount, 'MT');
  334. // Validation of parameters
  335. if (!($newamount) > 0 || empty($this->datep)) {
  336. return false;
  337. }
  338. return true;
  339. }
  340. /**
  341. * Create in database
  342. *
  343. * @param User $user User that create
  344. * @return int <0 if KO, >0 if OK
  345. */
  346. public function create($user)
  347. {
  348. global $conf, $langs;
  349. $error = 0;
  350. $now = dol_now();
  351. // Clean parameters
  352. $this->amount = price2num(trim($this->amount));
  353. $this->label = trim($this->label);
  354. $this->note = trim($this->note);
  355. $this->fk_bank = (int) $this->fk_bank;
  356. $this->fk_user_author = (int) $this->fk_user_author;
  357. $this->fk_user_modif = (int) $this->fk_user_modif;
  358. $this->fk_account = (int) $this->fk_account;
  359. if (empty($this->fk_account) && isset($this->accountid)) { // For compatibility
  360. $this->fk_account = $this->accountid;
  361. }
  362. // Check parameters
  363. if (!$this->label) {
  364. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  365. return -3;
  366. }
  367. if ($this->amount < 0 || $this->amount == '') {
  368. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  369. return -5;
  370. }
  371. if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0)) {
  372. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
  373. return -6;
  374. }
  375. if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) {
  376. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  377. return -7;
  378. }
  379. $this->db->begin();
  380. // Insert into llx_payment_various
  381. $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_various (";
  382. $sql .= " datep";
  383. $sql .= ", datev";
  384. $sql .= ", sens";
  385. $sql .= ", amount";
  386. $sql .= ", fk_typepayment";
  387. $sql .= ", num_payment";
  388. if ($this->note) {
  389. $sql .= ", note";
  390. }
  391. $sql .= ", label";
  392. $sql .= ", accountancy_code";
  393. $sql .= ", subledger_account";
  394. $sql .= ", fk_projet";
  395. $sql .= ", fk_user_author";
  396. $sql .= ", datec";
  397. $sql .= ", fk_bank";
  398. $sql .= ", entity";
  399. $sql .= ")";
  400. $sql .= " VALUES (";
  401. $sql .= "'".$this->db->idate($this->datep)."'";
  402. $sql .= ", '".$this->db->idate($this->datev)."'";
  403. $sql .= ", '".$this->db->escape($this->sens)."'";
  404. $sql .= ", ".price2num($this->amount);
  405. $sql .= ", '".$this->db->escape($this->type_payment)."'";
  406. $sql .= ", '".$this->db->escape($this->num_payment)."'";
  407. if ($this->note) {
  408. $sql .= ", '".$this->db->escape($this->note)."'";
  409. }
  410. $sql .= ", '".$this->db->escape($this->label)."'";
  411. $sql .= ", '".$this->db->escape($this->accountancy_code)."'";
  412. $sql .= ", '".$this->db->escape($this->subledger_account)."'";
  413. $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0);
  414. $sql .= ", ".$user->id;
  415. $sql .= ", '".$this->db->idate($now)."'";
  416. $sql .= ", NULL"; // Filled later
  417. $sql .= ", ".$conf->entity;
  418. $sql .= ")";
  419. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  420. $result = $this->db->query($sql);
  421. if ($result) {
  422. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_various");
  423. $this->ref = $this->id;
  424. if ($this->id > 0) {
  425. if (!empty($conf->banque->enabled) && !empty($this->amount)) {
  426. // Insert into llx_bank
  427. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  428. $acc = new Account($this->db);
  429. $result = $acc->fetch($this->fk_account);
  430. if ($result <= 0) {
  431. dol_print_error($this->db);
  432. }
  433. // Insert payment into llx_bank
  434. // Add link 'payment_various' in bank_url between payment and bank transaction
  435. $sign = 1;
  436. if ($this->sens == '0') {
  437. $sign = -1;
  438. }
  439. $bank_line_id = $acc->addline(
  440. $this->datep,
  441. $this->type_payment,
  442. $this->label,
  443. $sign * abs($this->amount),
  444. $this->num_payment,
  445. ($this->category_transaction > 0 ? $this->category_transaction : 0),
  446. $user,
  447. $this->chqemetteur,
  448. $this->chqbank,
  449. '',
  450. $this->datev
  451. );
  452. // Update fk_bank into llx_payment_various
  453. // So we know the payment which has generate the banking ecriture
  454. if ($bank_line_id > 0) {
  455. $this->update_fk_bank($bank_line_id);
  456. } else {
  457. $this->error = $acc->error;
  458. $error++;
  459. }
  460. if (!$error) {
  461. // Add link 'payment_various' in bank_url between payment and bank transaction
  462. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id=';
  463. $result = $acc->add_url_line($bank_line_id, $this->id, $url, "(VariousPayment)", "payment_various");
  464. if ($result <= 0) {
  465. $this->error = $acc->error;
  466. $error++;
  467. }
  468. }
  469. if ($result <= 0) {
  470. $this->error = $acc->error;
  471. $error++;
  472. }
  473. }
  474. // Call trigger
  475. $result = $this->call_trigger('PAYMENT_VARIOUS_CREATE', $user);
  476. if ($result < 0) {
  477. $error++;
  478. }
  479. // End call triggers
  480. } else {
  481. $error++;
  482. }
  483. if (!$error) {
  484. $this->db->commit();
  485. return $this->id;
  486. } else {
  487. $this->db->rollback();
  488. return -2;
  489. }
  490. } else {
  491. $this->error = $this->db->error();
  492. $this->db->rollback();
  493. return -1;
  494. }
  495. }
  496. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  497. /**
  498. * Update link between payment various and line generate into llx_bank
  499. *
  500. * @param int $id_bank Id bank account
  501. * @return int <0 if KO, >0 if OK
  502. */
  503. public function update_fk_bank($id_bank)
  504. {
  505. // phpcs:enable
  506. $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.((int) $id_bank);
  507. $sql .= ' WHERE rowid = '.$this->id;
  508. $result = $this->db->query($sql);
  509. if ($result) {
  510. return 1;
  511. } else {
  512. dol_print_error($this->db);
  513. return -1;
  514. }
  515. }
  516. /**
  517. * Retourne le libelle du statut
  518. *
  519. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
  520. * @return string Libelle
  521. */
  522. public function getLibStatut($mode = 0)
  523. {
  524. return $this->LibStatut($this->statut, $mode);
  525. }
  526. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  527. /**
  528. * Renvoi le libelle d'un statut donne
  529. *
  530. * @param int $status Id status
  531. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
  532. * @return string Libelle
  533. */
  534. public function LibStatut($status, $mode = 0)
  535. {
  536. // phpcs:enable
  537. global $langs;
  538. if ($mode == 0) {
  539. return $langs->trans($this->statuts[$status]);
  540. } elseif ($mode == 1) {
  541. return $langs->trans($this->statuts_short[$status]);
  542. } elseif ($mode == 2) {
  543. if ($status == 0) {
  544. return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
  545. } elseif ($status == 1) {
  546. return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
  547. } elseif ($status == 2) {
  548. return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
  549. }
  550. } elseif ($mode == 3) {
  551. if ($status == 0 && !empty($this->statuts_short[$status])) {
  552. return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
  553. } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
  554. return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
  555. } elseif ($status == 2 && !empty($this->statuts_short[$status])) {
  556. return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
  557. }
  558. } elseif ($mode == 4) {
  559. if ($status == 0 && !empty($this->statuts_short[$status])) {
  560. return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
  561. } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
  562. return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
  563. } elseif ($status == 2 && !empty($this->statuts_short[$status])) {
  564. return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
  565. }
  566. } elseif ($mode == 5) {
  567. if ($status == 0 && !empty($this->statuts_short[$status])) {
  568. return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
  569. } elseif ($status == 1 && !empty($this->statuts_short[$status])) {
  570. return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
  571. } elseif ($status == 2 && !empty($this->statuts_short[$status])) {
  572. return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
  573. }
  574. }
  575. }
  576. /**
  577. * Send name clicable (with possibly the picto)
  578. *
  579. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  580. * @param string $option link option
  581. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  582. * @param int $notooltip 1=Disable tooltip
  583. * @param string $morecss morecss string
  584. * @return string String with URL
  585. */
  586. public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
  587. {
  588. global $db, $conf, $langs, $hookmanager;
  589. global $langs;
  590. if (!empty($conf->dol_no_mouse_hover)) {
  591. $notooltip = 1; // Force disable tooltips
  592. }
  593. $result = '';
  594. $label = '<u>'.$langs->trans("ShowVariousPayment").'</u>';
  595. $label .= '<br>';
  596. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  597. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$this->id;
  598. if ($option != 'nolink') {
  599. // Add param to save lastsearch_values or not
  600. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  601. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  602. $add_save_lastsearch_values = 1;
  603. }
  604. if ($add_save_lastsearch_values) {
  605. $url .= '&save_lastsearch_values=1';
  606. }
  607. }
  608. $linkclose = '';
  609. if (empty($notooltip)) {
  610. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  611. $label = $langs->trans("ShowMyObject");
  612. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  613. }
  614. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  615. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  616. /*
  617. $hookmanager->initHooks(array('myobjectdao'));
  618. $parameters=array('id'=>$this->id);
  619. $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  620. if ($reshook > 0) $linkclose = $hookmanager->resPrint;
  621. */
  622. } else {
  623. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  624. }
  625. $linkstart = '<a href="'.$url.'"';
  626. $linkstart .= $linkclose.'>';
  627. $linkend = '</a>';
  628. $result .= $linkstart;
  629. if ($withpicto) {
  630. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
  631. }
  632. if ($withpicto != 2) {
  633. $result .= $this->ref;
  634. }
  635. $result .= $linkend;
  636. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  637. global $action;
  638. $hookmanager->initHooks(array('variouspayment'));
  639. $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
  640. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  641. if ($reshook > 0) {
  642. $result = $hookmanager->resPrint;
  643. } else {
  644. $result .= $hookmanager->resPrint;
  645. }
  646. return $result;
  647. }
  648. /**
  649. * Information on record
  650. *
  651. * @param int $id Id of record
  652. * @return void
  653. */
  654. public function info($id)
  655. {
  656. $sql = 'SELECT v.rowid, v.datec, v.fk_user_author';
  657. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
  658. $sql .= ' WHERE v.rowid = '.((int) $id);
  659. dol_syslog(get_class($this).'::info', LOG_DEBUG);
  660. $result = $this->db->query($sql);
  661. if ($result) {
  662. if ($this->db->num_rows($result)) {
  663. $obj = $this->db->fetch_object($result);
  664. $this->id = $obj->rowid;
  665. if ($obj->fk_user_author) {
  666. $cuser = new User($this->db);
  667. $cuser->fetch($obj->fk_user_author);
  668. $this->user_creation = $cuser;
  669. }
  670. $this->date_creation = $this->db->jdate($obj->datec);
  671. if ($obj->fk_user_modif) {
  672. $muser = new User($this->db);
  673. $muser->fetch($obj->fk_user_modif);
  674. $this->user_modif = $muser;
  675. }
  676. $this->date_modif = $this->db->jdate($obj->tms);
  677. }
  678. $this->db->free($result);
  679. } else {
  680. dol_print_error($this->db);
  681. }
  682. }
  683. /**
  684. * Return if a various payment linked to a bank line id was dispatched into bookkeeping
  685. *
  686. * @return int <0 if KO, 0=no, 1=yes
  687. */
  688. public function getVentilExportCompta()
  689. {
  690. $banklineid = $this->fk_bank;
  691. $alreadydispatched = 0;
  692. $type = 'bank';
  693. $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) $banklineid);
  694. $resql = $this->db->query($sql);
  695. if ($resql) {
  696. $obj = $this->db->fetch_object($resql);
  697. if ($obj) {
  698. $alreadydispatched = $obj->nb;
  699. }
  700. } else {
  701. $this->error = $this->db->lasterror();
  702. return -1;
  703. }
  704. if ($alreadydispatched) {
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. }