prelevement.lib.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/lib/prelevement.lib.php
  22. * \brief Ensemble de fonctions de base pour le module prelevement
  23. * \ingroup propal
  24. */
  25. /**
  26. * Prepare array with list of tabs
  27. *
  28. * @param BonPrelevement $object Object related to tabs
  29. * @return array Array of tabs to show
  30. */
  31. function prelevement_prepare_head(BonPrelevement $object)
  32. {
  33. global $langs, $conf;
  34. $salary = $object->checkIfSalaryBonPrelevement();
  35. $langs->loadLangs(array("bills", "withdrawals"));
  36. $h = 0;
  37. $head = array();
  38. $titleoftab = "WithdrawalsReceipts";
  39. if ($object->type == 'bank-transfer') {
  40. $titleoftab = "BankTransferReceipts";
  41. }
  42. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$object->id;
  43. $head[$h][1] = $langs->trans($titleoftab);
  44. $head[$h][2] = 'prelevement';
  45. $h++;
  46. $titleoftab = $langs->trans("Bills");
  47. if ($object->type == 'bank-transfer') {
  48. $titleoftab = $langs->trans("SupplierBills");
  49. }
  50. if ($salary > 0) {
  51. $titleoftab = $langs->trans("Salaries");
  52. }
  53. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id;
  54. $head[$h][1] = $titleoftab;
  55. $head[$h][2] = 'invoices';
  56. $h++;
  57. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$object->id;
  58. $head[$h][1] = $langs->trans("Rejects");
  59. $head[$h][2] = 'rejects';
  60. $h++;
  61. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$object->id;
  62. $head[$h][1] = $langs->trans("Statistics");
  63. $head[$h][2] = 'statistics';
  64. $h++;
  65. // Show more tabs from modules
  66. // Entries must be declared in modules descriptor with line
  67. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  68. // $this->tabs = array('entity:-tabname); to remove a tab
  69. complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement');
  70. complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement', 'remove');
  71. return $head;
  72. }
  73. /**
  74. * Check need data to create standigns orders receipt file
  75. *
  76. * @param string $type 'bank-transfer' or 'direct-debit'
  77. *
  78. * @return int -1 if ko 0 if ok
  79. */
  80. function prelevement_check_config($type = 'direct-debit')
  81. {
  82. global $conf, $db;
  83. if ($type == 'bank-transfer') {
  84. if (!getDolGlobalString('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT')) {
  85. return -1;
  86. }
  87. //if (empty($conf->global->PRELEVEMENT_ICS)) return -1;
  88. if (!getDolGlobalString('PAYMENTBYBANKTRANSFER_USER')) {
  89. return -1;
  90. }
  91. } else {
  92. if (!getDolGlobalString('PRELEVEMENT_ID_BANKACCOUNT')) {
  93. return -1;
  94. }
  95. //if (empty($conf->global->PRELEVEMENT_ICS)) return -1;
  96. if (!getDolGlobalString('PRELEVEMENT_USER')) {
  97. return -1;
  98. }
  99. }
  100. return 0;
  101. }
  102. /**
  103. * Return array head with list of tabs to view object informations
  104. *
  105. * @param BonPrelevement $object Member
  106. * @param int $nbOfInvoices No of invoices
  107. * @param int $nbOfSalaryInvoice No of salary invoices
  108. * @return array head
  109. */
  110. function bon_prelevement_prepare_head(BonPrelevement $object, $nbOfInvoices, $nbOfSalaryInvoice)
  111. {
  112. global $langs, $conf;
  113. $h = 0;
  114. $head = array();
  115. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer';
  116. $head[$h][1] = ($nbOfInvoices <= 0 ? $langs->trans("Invoices") : $langs->trans("Invoices").'<span class="badge marginleftonlyshort">'.$nbOfInvoices.'</span>');
  117. $head[$h][2] = 'invoice';
  118. $h++;
  119. // Salaries
  120. $head[$h][0] = DOL_URL_ROOT."/compta/prelevement/create.php?type=bank-transfer&sourcetype=salary";
  121. $head[$h][1] = ($nbOfSalaryInvoice <= 0 ? $langs->trans("Salaries") : $langs->trans("Salaries").'<span class="badge marginleftonlyshort">'.$nbOfSalaryInvoice.'</span>');
  122. $head[$h][2] = 'salary';
  123. $h++;
  124. // Show more tabs from modules
  125. // Entries must be declared in modules descriptor with line
  126. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  127. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  128. complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement');
  129. complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement', 'remove');
  130. return $head;
  131. }