accounting.lib.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  4. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/lib/accounting.lib.php
  21. * \ingroup Advanced accountancy
  22. * \brief Library of accountancy functions
  23. */
  24. /**
  25. * Prepare array with list of admin tabs
  26. *
  27. * @param AccountingAccount $object Object instance we show card
  28. * @return array Array of tabs to show
  29. */
  30. function admin_accounting_prepare_head(AccountingAccount $object=null)
  31. {
  32. global $langs, $conf;
  33. $h = 0;
  34. $head = array ();
  35. $head[$h][0] = dol_buildpath('/accountancy/admin/index.php', 1);
  36. $head[$h][1] = $langs->trans("Miscellaneous");
  37. $head[$h][2] = 'general';
  38. $h ++;
  39. $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/export.php';
  40. $head[$h][1] = $langs->trans("ExportOptions");
  41. $head[$h][2] = 'export';
  42. $h ++;
  43. // Show more tabs from modules
  44. // Entries must be declared in modules descriptor with line
  45. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  46. // $this->tabs = array('entity:-tabname); to remove a tab
  47. complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_admin');
  48. complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_admin', 'remove');
  49. return $head;
  50. }
  51. /**
  52. * Prepare array with list of tabs
  53. *
  54. * @param AccountingAccount $object Accounting account
  55. * @return array Array of tabs to show
  56. */
  57. function accounting_prepare_head(AccountingAccount $object)
  58. {
  59. global $langs, $conf;
  60. $h = 0;
  61. $head = array ();
  62. $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id;
  63. $head[$h][1] = $langs->trans("Card");
  64. $head[$h][2] = 'card';
  65. $h ++;
  66. // Show more tabs from modules
  67. // Entries must be declared in modules descriptor with line
  68. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  69. // $this->tabs = array('entity:-tabname); to remove a tab
  70. complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
  71. complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
  72. return $head;
  73. }
  74. /**
  75. * Return accounting account without zero on the right
  76. *
  77. * @param string $account Accounting account
  78. * @return string String without zero on the right
  79. */
  80. function clean_account($account)
  81. {
  82. $account = rtrim($account,"0");
  83. return $account;
  84. }
  85. /**
  86. * Return General accounting account with defined length (used for product and miscellaneous)
  87. *
  88. * @param string $account General accounting account
  89. * @return string String with defined length
  90. */
  91. function length_accountg($account)
  92. {
  93. global $conf;
  94. if ($account < 0 || empty($account)) return '';
  95. if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
  96. $g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
  97. if (! empty($g)) {
  98. // Clean parameters
  99. $i = strlen($account);
  100. if ($i >= 1) {
  101. while ( $i < $g ) {
  102. $account .= '0';
  103. $i ++;
  104. }
  105. return $account;
  106. } else {
  107. return $account;
  108. }
  109. } else {
  110. return $account;
  111. }
  112. }
  113. /**
  114. * Return Auxiliary accounting account of thirdparties with defined length
  115. *
  116. * @param string $accounta Auxiliary accounting account
  117. * @return string String with defined length
  118. */
  119. function length_accounta($accounta)
  120. {
  121. global $conf, $langs;
  122. if ($accounta < 0 || empty($accounta)) return '';
  123. if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
  124. $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
  125. if (! empty($a)) {
  126. // Clean parameters
  127. $i = strlen($accounta);
  128. if ($i >= 1) {
  129. while ( $i < $a ) {
  130. $accounta .= '0';
  131. $i ++;
  132. }
  133. return $accounta;
  134. } else {
  135. return $accounta;
  136. }
  137. } else {
  138. return $accounta;
  139. }
  140. }
  141. /**
  142. * Show header of a VAT report
  143. *
  144. * @param string $nom Name of report
  145. * @param string $variante Link for alternate report
  146. * @param string $period Period of report
  147. * @param string $periodlink Link to switch period
  148. * @param string $description Description
  149. * @param timestamp|integer $builddate Date generation
  150. * @param string $exportlink Link for export or ''
  151. * @param array $moreparam Array with list of params to add into form
  152. * @param string $calcmode Calculation mode
  153. * @param string $varlink Add a variable into the address of the page
  154. * @return void
  155. */
  156. function journalHead($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='')
  157. {
  158. global $langs;
  159. if (empty($hselected)) $hselected='report';
  160. print "\n\n<!-- debut cartouche journal -->\n";
  161. if(! empty($varlink)) $varlink = '?'.$varlink;
  162. $h=0;
  163. $head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
  164. $head[$h][1] = $langs->trans("Journalization");
  165. $head[$h][2] = 'journal';
  166. dol_fiche_head($head, 'journal');
  167. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">';
  168. foreach($moreparam as $key => $value)
  169. {
  170. print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
  171. }
  172. print '<table width="100%" class="border">';
  173. // Ligne de titre
  174. print '<tr>';
  175. print '<td width="110">'.$langs->trans("Name").'</td>';
  176. if (! $variantexxx) print '<td colspan="3">';
  177. else print '<td>';
  178. print $nom;
  179. if ($variantexxx) print '</td><td colspan="2">'.$variantexxx;
  180. print '</td>';
  181. print '</tr>';
  182. // Calculation mode
  183. if ($calcmode)
  184. {
  185. print '<tr>';
  186. print '<td width="110">'.$langs->trans("CalculationMode").'</td>';
  187. if (! $variante) print '<td colspan="3">';
  188. else print '<td>';
  189. print $calcmode;
  190. if ($variante) print '</td><td colspan="2">'.$variante;
  191. print '</td>';
  192. print '</tr>';
  193. }
  194. // Ligne de la periode d'analyse du rapport
  195. print '<tr>';
  196. print '<td>'.$langs->trans("ReportPeriod").'</td>';
  197. if (! $periodlink) print '<td colspan="3">';
  198. else print '<td>';
  199. if ($period) print $period;
  200. if ($periodlink) print '</td><td colspan="2">'.$periodlink;
  201. print '</td>';
  202. print '</tr>';
  203. // Ligne de description
  204. print '<tr>';
  205. print '<td>'.$langs->trans("ReportDescription").'</td>';
  206. print '<td colspan="3">'.$description.'</td>';
  207. print '</tr>';
  208. print '</table>';
  209. print '<br><div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
  210. print '</form>';
  211. dol_fiche_end();
  212. print "\n<!-- fin cartouche journal -->\n\n";
  213. }