paymentvarious.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. <?php
  2. /* Copyright (C) 2017-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2018-2023 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 = 'payment_various';
  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. * @var int Type of bank account if the payment is on a bank account
  109. */
  110. public $fk_type;
  111. /**
  112. * @var int 1 if the payment is on a bank account line that is conciliated
  113. */
  114. public $rappro;
  115. /**
  116. * @var string ID of bank receipt
  117. */
  118. public $bank_num_releve;
  119. /**
  120. * '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')
  121. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  122. * 'label' the translation key.
  123. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
  124. * 'position' is the sort order of field.
  125. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  126. * '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)
  127. * 'noteditable' says if field is not editable (1 or 0)
  128. * '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.
  129. * 'index' if we want an index in database.
  130. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  131. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  132. * '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).
  133. * 'css' is the CSS style to use on field. For example: 'maxwidth200'
  134. * 'help' is a string visible as a tooltip on field
  135. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  136. * '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.
  137. * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  138. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  139. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  140. *
  141. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  142. */
  143. // BEGIN MODULEBUILDER PROPERTIES
  144. /**
  145. * @var array fields definition
  146. */
  147. public $fields = array(
  148. // TODO: fill this array
  149. );
  150. // END MODULEBUILDER PROPERTIES
  151. /**
  152. * Draft status
  153. */
  154. const STATUS_DRAFT = 0;
  155. /**
  156. * Constructor
  157. *
  158. * @param DoliDB $db Database handler
  159. */
  160. public function __construct(DoliDB $db)
  161. {
  162. $this->db = $db;
  163. }
  164. /**
  165. * Update database
  166. *
  167. * @param User $user User that modify
  168. * @param int $notrigger 0=no, 1=yes (no update trigger)
  169. * @return int <0 if KO, >0 if OK
  170. */
  171. public function update($user = null, $notrigger = 0)
  172. {
  173. global $conf, $langs;
  174. $error = 0;
  175. // Clean parameters
  176. $this->amount = trim($this->amount);
  177. $this->label = trim($this->label);
  178. $this->note = trim($this->note);
  179. $this->fk_bank = (int) $this->fk_bank;
  180. $this->fk_user_author = (int) $this->fk_user_author;
  181. $this->fk_user_modif = (int) $this->fk_user_modif;
  182. $this->db->begin();
  183. // Update request
  184. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_various SET";
  185. if ($this->tms) {
  186. $sql .= " tms='".$this->db->idate($this->tms)."',";
  187. }
  188. $sql .= " datep='".$this->db->idate($this->datep)."',";
  189. $sql .= " datev='".$this->db->idate($this->datev)."',";
  190. $sql .= " sens=".(int) $this->sens.",";
  191. $sql .= " amount=".price2num($this->amount).",";
  192. $sql .= " fk_typepayment=".(int) $this->type_payment.",";
  193. $sql .= " num_payment='".$this->db->escape($this->num_payment)."',";
  194. $sql .= " label='".$this->db->escape($this->label)."',";
  195. $sql .= " note='".$this->db->escape($this->note)."',";
  196. $sql .= " accountancy_code='".$this->db->escape($this->accountancy_code)."',";
  197. $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',";
  198. $sql .= " fk_projet='".$this->db->escape($this->fk_project)."',";
  199. $sql .= " fk_bank=".($this->fk_bank > 0 ? $this->fk_bank : "null").",";
  200. $sql .= " fk_user_author=".(int) $this->fk_user_author.",";
  201. $sql .= " fk_user_modif=".(int) $this->fk_user_modif;
  202. $sql .= " WHERE rowid=".((int) $this->id);
  203. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  204. $resql = $this->db->query($sql);
  205. if (!$resql) {
  206. $this->error = "Error ".$this->db->lasterror();
  207. return -1;
  208. }
  209. if (!$notrigger) {
  210. // Call trigger
  211. $result = $this->call_trigger('PAYMENT_VARIOUS_MODIFY', $user);
  212. if ($result < 0) {
  213. $error++;
  214. }
  215. // End call triggers
  216. }
  217. if (!$error) {
  218. $this->db->commit();
  219. return 1;
  220. } else {
  221. $this->db->rollback();
  222. return -1;
  223. }
  224. }
  225. /**
  226. * Load object in memory from database
  227. *
  228. * @param int $id id object
  229. * @param User $user User that load
  230. * @return int <0 if KO, >0 if OK
  231. */
  232. public function fetch($id, $user = null)
  233. {
  234. $sql = "SELECT";
  235. $sql .= " v.rowid,";
  236. $sql .= " v.tms,";
  237. $sql .= " v.datep,";
  238. $sql .= " v.datev,";
  239. $sql .= " v.sens,";
  240. $sql .= " v.amount,";
  241. $sql .= " v.fk_typepayment,";
  242. $sql .= " v.num_payment,";
  243. $sql .= " v.label,";
  244. $sql .= " v.note as note_private,";
  245. $sql .= " v.accountancy_code,";
  246. $sql .= " v.subledger_account,";
  247. $sql .= " v.fk_projet as fk_project,";
  248. $sql .= " v.fk_bank,";
  249. $sql .= " v.fk_user_author,";
  250. $sql .= " v.fk_user_modif,";
  251. $sql .= " b.fk_account,";
  252. $sql .= " b.fk_type,";
  253. $sql .= " b.rappro,";
  254. $sql .= " b.num_releve as bank_num_releve";
  255. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  256. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  257. $sql .= " WHERE v.rowid = ".((int) $id);
  258. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  259. $resql = $this->db->query($sql);
  260. if ($resql) {
  261. if ($this->db->num_rows($resql)) {
  262. $obj = $this->db->fetch_object($resql);
  263. $this->id = $obj->rowid;
  264. $this->ref = $obj->rowid;
  265. $this->tms = $this->db->jdate($obj->tms);
  266. $this->datep = $this->db->jdate($obj->datep);
  267. $this->datev = $this->db->jdate($obj->datev);
  268. $this->sens = $obj->sens;
  269. $this->amount = $obj->amount;
  270. $this->type_payment = $obj->fk_typepayment;
  271. $this->num_payment = $obj->num_payment;
  272. $this->label = $obj->label;
  273. $this->note = $obj->note_private; // For backward compatibility
  274. $this->note_private = $obj->note_private;
  275. $this->subledger_account = $obj->subledger_account;
  276. $this->accountancy_code = $obj->accountancy_code;
  277. $this->fk_project = $obj->fk_project;
  278. $this->fk_bank = $obj->fk_bank;
  279. $this->fk_user_author = $obj->fk_user_author;
  280. $this->fk_user_modif = $obj->fk_user_modif;
  281. $this->fk_account = $obj->fk_account;
  282. $this->fk_type = $obj->fk_type;
  283. $this->rappro = $obj->rappro;
  284. $this->bank_num_releve = $obj->bank_num_releve;
  285. }
  286. $this->db->free($resql);
  287. return 1;
  288. } else {
  289. $this->error = "Error ".$this->db->lasterror();
  290. return -1;
  291. }
  292. }
  293. /**
  294. * Delete object in database
  295. *
  296. * @param User $user User that delete
  297. * @return int <0 if KO, >0 if OK
  298. */
  299. public function delete($user)
  300. {
  301. global $conf, $langs;
  302. $error = 0;
  303. // Call trigger
  304. $result = $this->call_trigger('PAYMENT_VARIOUS_DELETE', $user);
  305. if ($result < 0) {
  306. return -1;
  307. }
  308. // End call triggers
  309. $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_various";
  310. $sql .= " WHERE rowid=".((int) $this->id);
  311. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  312. $resql = $this->db->query($sql);
  313. if (!$resql) {
  314. $this->error = "Error ".$this->db->lasterror();
  315. return -1;
  316. }
  317. return 1;
  318. }
  319. /**
  320. * Initialise an instance with random values.
  321. * Used to build previews or test instances.
  322. * id must be 0 if object instance is a specimen.
  323. *
  324. * @return void
  325. */
  326. public function initAsSpecimen()
  327. {
  328. $this->id = 0;
  329. $this->tms = '';
  330. $this->datep = '';
  331. $this->datev = '';
  332. $this->sens = '';
  333. $this->amount = '';
  334. $this->label = '';
  335. $this->accountancy_code = '';
  336. $this->subledger_account = '';
  337. $this->note = '';
  338. $this->fk_bank = '';
  339. $this->fk_user_author = '';
  340. $this->fk_user_modif = '';
  341. }
  342. /**
  343. * Check if a miscellaneous payment can be created into database
  344. *
  345. * @return boolean True or false
  346. */
  347. public function check()
  348. {
  349. $newamount = price2num($this->amount, 'MT');
  350. // Validation of parameters
  351. if (!($newamount) > 0 || empty($this->datep)) {
  352. return false;
  353. }
  354. return true;
  355. }
  356. /**
  357. * Create in database
  358. *
  359. * @param User $user User that create
  360. * @return int <0 if KO, >0 if OK
  361. */
  362. public function create($user)
  363. {
  364. global $conf, $langs;
  365. $error = 0;
  366. $now = dol_now();
  367. // Clean parameters
  368. $this->amount = price2num(trim($this->amount));
  369. $this->label = trim($this->label);
  370. $this->note = trim($this->note);
  371. $this->fk_bank = (int) $this->fk_bank;
  372. $this->fk_user_author = (int) $this->fk_user_author;
  373. $this->fk_user_modif = (int) $this->fk_user_modif;
  374. $this->fk_account = (int) $this->fk_account;
  375. if (empty($this->fk_account) && isset($this->accountid)) { // For compatibility
  376. $this->fk_account = $this->accountid;
  377. }
  378. // Check parameters
  379. if (!$this->label) {
  380. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  381. return -3;
  382. }
  383. if ($this->amount < 0 || $this->amount == '') {
  384. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  385. return -5;
  386. }
  387. if (isModEnabled("banque") && (empty($this->fk_account) || $this->fk_account <= 0)) {
  388. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
  389. return -6;
  390. }
  391. if (isModEnabled("banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
  392. $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  393. return -7;
  394. }
  395. $this->db->begin();
  396. // Insert into llx_payment_various
  397. $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_various (";
  398. $sql .= " datep";
  399. $sql .= ", datev";
  400. $sql .= ", sens";
  401. $sql .= ", amount";
  402. $sql .= ", fk_typepayment";
  403. $sql .= ", num_payment";
  404. if ($this->note) {
  405. $sql .= ", note";
  406. }
  407. $sql .= ", label";
  408. $sql .= ", accountancy_code";
  409. $sql .= ", subledger_account";
  410. $sql .= ", fk_projet";
  411. $sql .= ", fk_user_author";
  412. $sql .= ", datec";
  413. $sql .= ", fk_bank";
  414. $sql .= ", entity";
  415. $sql .= ")";
  416. $sql .= " VALUES (";
  417. $sql .= "'".$this->db->idate($this->datep)."'";
  418. $sql .= ", '".$this->db->idate($this->datev)."'";
  419. $sql .= ", '".$this->db->escape($this->sens)."'";
  420. $sql .= ", ".price2num($this->amount);
  421. $sql .= ", '".$this->db->escape($this->type_payment)."'";
  422. $sql .= ", '".$this->db->escape($this->num_payment)."'";
  423. if ($this->note) {
  424. $sql .= ", '".$this->db->escape($this->note)."'";
  425. }
  426. $sql .= ", '".$this->db->escape($this->label)."'";
  427. $sql .= ", '".$this->db->escape($this->accountancy_code)."'";
  428. $sql .= ", '".$this->db->escape($this->subledger_account)."'";
  429. $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
  430. $sql .= ", ".((int) $user->id);
  431. $sql .= ", '".$this->db->idate($now)."'";
  432. $sql .= ", NULL"; // Filled later
  433. $sql .= ", ".((int) $conf->entity);
  434. $sql .= ")";
  435. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  436. $result = $this->db->query($sql);
  437. if ($result) {
  438. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_various");
  439. $this->ref = $this->id;
  440. if ($this->id > 0) {
  441. if (isModEnabled("banque") && !empty($this->amount)) {
  442. // Insert into llx_bank
  443. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  444. $acc = new Account($this->db);
  445. $result = $acc->fetch($this->fk_account);
  446. if ($result <= 0) {
  447. dol_print_error($this->db);
  448. }
  449. // Insert payment into llx_bank
  450. // Add link 'payment_various' in bank_url between payment and bank transaction
  451. $sign = 1;
  452. if ($this->sens == '0') {
  453. $sign = -1;
  454. }
  455. $bank_line_id = $acc->addline(
  456. $this->datep,
  457. $this->type_payment,
  458. $this->label,
  459. $sign * abs($this->amount),
  460. $this->num_payment,
  461. ($this->category_transaction > 0 ? $this->category_transaction : 0),
  462. $user,
  463. $this->chqemetteur,
  464. $this->chqbank,
  465. '',
  466. $this->datev
  467. );
  468. // Update fk_bank into llx_payment_various
  469. // So we know the payment which has generate the banking ecriture
  470. if ($bank_line_id > 0) {
  471. $this->update_fk_bank($bank_line_id);
  472. } else {
  473. $this->error = $acc->error;
  474. $error++;
  475. }
  476. if (!$error) {
  477. // Add link 'payment_various' in bank_url between payment and bank transaction
  478. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id=';
  479. $result = $acc->add_url_line($bank_line_id, $this->id, $url, "(VariousPayment)", "payment_various");
  480. if ($result <= 0) {
  481. $this->error = $acc->error;
  482. $error++;
  483. }
  484. }
  485. if ($result <= 0) {
  486. $this->error = $acc->error;
  487. $error++;
  488. }
  489. }
  490. // Call trigger
  491. $result = $this->call_trigger('PAYMENT_VARIOUS_CREATE', $user);
  492. if ($result < 0) {
  493. $error++;
  494. }
  495. // End call triggers
  496. } else {
  497. $error++;
  498. }
  499. if (!$error) {
  500. $this->db->commit();
  501. return $this->id;
  502. } else {
  503. $this->db->rollback();
  504. return -2;
  505. }
  506. } else {
  507. $this->error = $this->db->error();
  508. $this->db->rollback();
  509. return -1;
  510. }
  511. }
  512. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  513. /**
  514. * Update link between payment various and line generate into llx_bank
  515. *
  516. * @param int $id_bank Id bank account
  517. * @return int <0 if KO, >0 if OK
  518. */
  519. public function update_fk_bank($id_bank)
  520. {
  521. // phpcs:enable
  522. $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.((int) $id_bank);
  523. $sql .= " WHERE rowid = ".((int) $this->id);
  524. $result = $this->db->query($sql);
  525. if ($result) {
  526. return 1;
  527. } else {
  528. dol_print_error($this->db);
  529. return -1;
  530. }
  531. }
  532. /**
  533. * Return the label of the status
  534. *
  535. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  536. * @return string Label of status
  537. */
  538. public function getLibStatut($mode = 0)
  539. {
  540. return $this->LibStatut($this->statut, $mode);
  541. }
  542. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  543. /**
  544. * Return the label of a given status
  545. *
  546. * @param int $status Id status
  547. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  548. * @return string Label of status
  549. */
  550. public function LibStatut($status, $mode = 0)
  551. {
  552. // phpcs:enable
  553. global $langs;
  554. if (empty($status)) {
  555. $status = 0;
  556. }
  557. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  558. $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  559. //$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
  560. //$this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  561. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
  562. //$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
  563. //$this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  564. }
  565. $statusType = 'status'.$status;
  566. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  567. }
  568. /**
  569. * Send name clicable (with possibly the picto)
  570. *
  571. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  572. * @param string $option link option
  573. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  574. * @param int $notooltip 1=Disable tooltip
  575. * @param string $morecss morecss string
  576. * @return string String with URL
  577. */
  578. public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
  579. {
  580. global $db, $conf, $langs, $hookmanager;
  581. global $langs;
  582. if (!empty($conf->dol_no_mouse_hover)) {
  583. $notooltip = 1; // Force disable tooltips
  584. }
  585. $result = '';
  586. $label = '<u>'.$langs->trans("ShowVariousPayment").'</u>';
  587. $label .= '<br>';
  588. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  589. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$this->id;
  590. if ($option != 'nolink') {
  591. // Add param to save lastsearch_values or not
  592. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  593. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  594. $add_save_lastsearch_values = 1;
  595. }
  596. if ($add_save_lastsearch_values) {
  597. $url .= '&save_lastsearch_values=1';
  598. }
  599. }
  600. $linkclose = '';
  601. if (empty($notooltip)) {
  602. if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  603. $label = $langs->trans("ShowMyObject");
  604. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  605. }
  606. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  607. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  608. } else {
  609. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  610. }
  611. $linkstart = '<a href="'.$url.'"';
  612. $linkstart .= $linkclose.'>';
  613. $linkend = '</a>';
  614. $result .= $linkstart;
  615. if ($withpicto) {
  616. $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);
  617. }
  618. if ($withpicto != 2) {
  619. $result .= $this->ref;
  620. }
  621. $result .= $linkend;
  622. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  623. global $action;
  624. $hookmanager->initHooks(array('variouspayment'));
  625. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  626. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  627. if ($reshook > 0) {
  628. $result = $hookmanager->resPrint;
  629. } else {
  630. $result .= $hookmanager->resPrint;
  631. }
  632. return $result;
  633. }
  634. /**
  635. * Information on record
  636. *
  637. * @param int $id Id of record
  638. * @return void
  639. */
  640. public function info($id)
  641. {
  642. $sql = 'SELECT v.rowid, v.datec, v.fk_user_author';
  643. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
  644. $sql .= ' WHERE v.rowid = '.((int) $id);
  645. dol_syslog(get_class($this).'::info', LOG_DEBUG);
  646. $result = $this->db->query($sql);
  647. if ($result) {
  648. if ($this->db->num_rows($result)) {
  649. $obj = $this->db->fetch_object($result);
  650. $this->id = $obj->rowid;
  651. $this->user_creation = $obj->fk_user_author;
  652. $this->user_modification_id = $obj->fk_user_modif;
  653. $this->date_creation = $this->db->jdate($obj->datec);
  654. $this->date_modification = $this->db->jdate($obj->tms);
  655. }
  656. $this->db->free($result);
  657. } else {
  658. dol_print_error($this->db);
  659. }
  660. }
  661. /**
  662. * Return if a various payment linked to a bank line id was dispatched into bookkeeping
  663. *
  664. * @return int <0 if KO, 0=no, 1=yes
  665. */
  666. public function getVentilExportCompta()
  667. {
  668. $banklineid = $this->fk_bank;
  669. $alreadydispatched = 0;
  670. $type = 'bank';
  671. $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);
  672. $resql = $this->db->query($sql);
  673. if ($resql) {
  674. $obj = $this->db->fetch_object($resql);
  675. if ($obj) {
  676. $alreadydispatched = $obj->nb;
  677. }
  678. } else {
  679. $this->error = $this->db->lasterror();
  680. return -1;
  681. }
  682. if ($alreadydispatched) {
  683. return 1;
  684. }
  685. return 0;
  686. }
  687. /**
  688. * Return clicable link of object (with eventually picto)
  689. *
  690. * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
  691. * @param array $arraydata Array of data
  692. * @return string HTML Code for Kanban thumb.
  693. */
  694. public function getKanbanView($option = '', $arraydata = null)
  695. {
  696. global $langs;
  697. $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
  698. $return = '<div class="box-flex-item box-flex-grow-zero">';
  699. $return .= '<div class="info-box info-box-sm">';
  700. $return .= '<span class="info-box-icon bg-infobox-action">';
  701. $return .= img_picto('', $this->picto);
  702. $return .= '</span>';
  703. $return .= '<div class="info-box-content">';
  704. $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
  705. if ($selected >= 0) {
  706. $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
  707. }
  708. if (property_exists($this, 'fk_bank')) {
  709. $return .= ' | <span class="info-box-status ">'.$this->fk_bank.'</span>';
  710. }
  711. if (property_exists($this, 'datep')) {
  712. $return .= '<br><span class="opacitymedium">'.$langs->trans("Date").'</span> : <span class="info-box-label">'.dol_print_date($this->db->jdate($this->datep), 'day').'</span>';
  713. }
  714. if (property_exists($this, 'type_payment') && !empty($this->type_payment)) {
  715. $return .= '<br><span class="opacitymedium">'.$langs->trans("Payment", $this->type_payment).'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
  716. }
  717. if (property_exists($this, 'accountancy_code')) {
  718. $return .= '<br><span class="opacitymedium">'.$langs->trans("Account").'</span> : <span class="info-box-label" title="'.$this->accountancy_code.'">'.$this->accountancy_code.'</span>';
  719. }
  720. if (property_exists($this, 'amount')) {
  721. $return .= '<br><span class="opacitymedium">'.$langs->trans("Debit").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
  722. }
  723. $return .= '</div>';
  724. $return .= '</div>';
  725. $return .= '</div>';
  726. return $return;
  727. }
  728. /**
  729. * Return General accounting account with defined length (used for product and miscellaneous)
  730. *
  731. * @param string $account General accounting account
  732. * @return string String with defined length
  733. */
  734. public function lengthAccountg($account)
  735. {
  736. include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  737. /*
  738. if (isModEnabled('accounting')) {
  739. $accountingaccount = new AccountingAccount($db);
  740. $accountingaccount->fetch('', $valuetoshow, 1);
  741. }*/
  742. return length_accountg($account);
  743. }
  744. /**
  745. * Return Auxiliary accounting account of thirdparties with defined length
  746. *
  747. * @param string $account Auxiliary accounting account
  748. * @return string String with defined length
  749. */
  750. public function lengthAccounta($account)
  751. {
  752. include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  753. return length_accounta($account);
  754. }
  755. }