paymentvarious.class.php 25 KB

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