dolibarr 19.0.4
accounting.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
6 * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
38function is_empty($var, $allow_false = false, $allow_ws = false)
39{
40 if (!isset($var) || is_null($var) || ($allow_ws == false && trim($var) == "" && !is_bool($var)) || ($allow_false === false && is_bool($var) && $var === false) || (is_array($var) && empty($var))) {
41 return true;
42 }
43 return false;
44}
45
53{
54 global $langs, $conf;
55
56 $h = 0;
57 $head = array();
58
59 $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$object->id;
60 $head[$h][1] = $langs->trans("AccountAccounting");
61 $head[$h][2] = 'card';
62 $h++;
63
64 // Show more tabs from modules
65 // Entries must be declared in modules descriptor with line
66 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
67 // $this->tabs = array('entity:-tabname); to remove a tab
68 complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
69
70 complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
71
72 return $head;
73}
74
81function clean_account($account)
82{
83 $account = rtrim($account, "0");
84
85 return $account;
86}
87
94function length_accountg($account)
95{
96 global $conf;
97
98 if ($account < 0 || is_empty($account)) {
99 return '';
100 }
101
102 if (getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
103 return $account;
104 }
105
106 $g = getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT');
107 if (!is_empty($g)) {
108 // Clean parameters
109 $i = strlen($account);
110
111 if ($i >= 1) {
112 while ($i < $g) {
113 $account .= '0';
114
115 $i++;
116 }
117
118 return $account;
119 } else {
120 return $account;
121 }
122 } else {
123 return $account;
124 }
125}
126
133function length_accounta($accounta)
134{
135 global $conf;
136
137 if ($accounta < 0 || is_empty($accounta)) {
138 return '';
139 }
140
141 if (getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
142 return $accounta;
143 }
144
145 $a = getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT');
146 if (!is_empty($a)) {
147 // Clean parameters
148 $i = strlen($accounta);
149
150 if ($i >= 1) {
151 while ($i < $a) {
152 $accounta .= '0';
153
154 $i++;
155 }
156
157 return $accounta;
158 } else {
159 return $accounta;
160 }
161 } else {
162 return $accounta;
163 }
164}
165
166
167
183function journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink = '', $moreparam = array(), $calcmode = '', $varlink = '')
184{
185 global $langs;
186
187 print "\n\n<!-- start banner journal -->\n";
188
189 if (!is_empty($varlink)) {
190 $varlink = '?'.$varlink;
191 }
192
193 $head = array();
194 $h = 0;
195 $head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
196 $head[$h][1] = $langs->trans("Journalization");
197 $head[$h][2] = 'journal';
198
199 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">';
200 print '<input type="hidden" name="token" value="'.newToken().'">';
201
202 print dol_get_fiche_head($head, 'journal');
203
204 foreach ($moreparam as $key => $value) {
205 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
206 }
207 print '<table class="border centpercent tableforfield">';
208
209 // Ligne de titre
210 print '<tr>';
211 print '<td class="titlefieldcreate">'.$langs->trans("Name").'</td>';
212 print '<td colspan="3">';
213 print $nom;
214 print '</td>';
215 print '</tr>';
216
217 // Calculation mode
218 if ($calcmode) {
219 print '<tr>';
220 print '<td>'.$langs->trans("CalculationMode").'</td>';
221 if (!$variante) {
222 print '<td colspan="3">';
223 } else {
224 print '<td>';
225 }
226 print $calcmode;
227 if ($variante) {
228 print '</td><td colspan="2">'.$variante;
229 }
230 print '</td>';
231 print '</tr>';
232 }
233
234 // Ligne de la periode d'analyse du rapport
235 print '<tr>';
236 print '<td>'.$langs->trans("ReportPeriod").'</td>';
237 if (!$periodlink) {
238 print '<td colspan="3">';
239 } else {
240 print '<td>';
241 }
242 if ($period) {
243 print $period;
244 }
245 if ($periodlink) {
246 print '</td><td colspan="2">'.$periodlink;
247 }
248 print '</td>';
249 print '</tr>';
250
251 // Ligne de description
252 print '<tr>';
253 print '<td>'.$langs->trans("ReportDescription").'</td>';
254 print '<td colspan="3">'.$description.'</td>';
255 print '</tr>';
256
257 print '</table>';
258
259 print dol_get_fiche_end();
260
261 print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
262
263 print '</form>';
264
265 print "\n<!-- end banner journal -->\n\n";
266}
267
274{
275 global $db, $conf;
276
277 $date_start = '';
278 $date_end = '';
279 $pastmonth = 0;
280 $pastmonthyear = 0;
281
282 // Period by default on transfer (0: previous month | 1: current month | 2: fiscal year)
283 $periodbydefaultontransfer = getDolGlobalInt('ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', 0);
284 if ($periodbydefaultontransfer == 2) { // fiscal year
285 $sql = "SELECT date_start, date_end FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
286 $sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'";
287 $sql .= $db->plimit(1);
288 $res = $db->query($sql);
289 if ($res->num_rows > 0) {
290 $obj = $db->fetch_object($res);
291
292 $date_start = $db->jdate($obj->date_start);
293 $date_end = $db->jdate($obj->date_end);
294 } else {
295 $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
296 $year_start = dol_print_date(dol_now(), '%Y');
297 if ($month_start > dol_print_date(dol_now(), '%m')) {
298 $year_start = $year_start - 1;
299 }
300 $year_end = $year_start + 1;
301 $month_end = $month_start - 1;
302 if ($month_end < 1) {
303 $month_end = 12;
304 $year_end--;
305 }
306 $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
307 $date_end = dol_get_last_day($year_end, $month_end);
308 }
309 } elseif ($periodbydefaultontransfer == 1) { // current month
310 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
311 $pastmonth = (int) dol_print_date(dol_now('gmt'), '%m', 'gmt');
312 $pastmonthyear = $year_current;
313 if ($pastmonth == 0) {
314 $pastmonth = 12;
315 $pastmonthyear--;
316 }
317 } else { // previous month
318 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
319 $pastmonth = (int) dol_print_date(dol_now('gmt'), '%m', 'gmt') - 1;
320 $pastmonthyear = $year_current;
321 if ($pastmonth == 0) {
322 $pastmonth = 12;
323 $pastmonthyear--;
324 }
325 }
326
327 return array(
328 'date_start' => $date_start,
329 'date_end' => $date_end,
330 'pastmonthyear' => $pastmonthyear,
331 'pastmonth' => $pastmonth
332 );
333}
334
343function getCurrentPeriodOfFiscalYear($db, $conf, $from_time = null)
344{
345 $now = dol_now();
346 $now_arr = dol_getdate($now);
347 if ($from_time === null) {
348 $from_time = $now;
349 }
350 $from_db_time = $db->idate($from_time);
351
352 $sql = "SELECT date_start, date_end FROM ".$db->prefix()."accounting_fiscalyear";
353 $sql .= " WHERE date_start <= '".$db->escape($from_db_time)."' AND date_end >= '".$db->escape($from_db_time)."'";
354 $sql .= $db->order('date_start', 'DESC');
355 $sql .= $db->plimit(1);
356 $res = $db->query($sql);
357 if ($db->num_rows($res) > 0) {
358 $obj = $db->fetch_object($res);
359
360 $date_start = $db->jdate($obj->date_start);
361 $date_end = $db->jdate($obj->date_end);
362 } else {
363 $month_start = 1;
364 $conf_fiscal_month_start = (int) $conf->global->SOCIETE_FISCAL_MONTH_START;
365 if ($conf_fiscal_month_start >= 1 && $conf_fiscal_month_start <= 12) {
366 $month_start = $conf_fiscal_month_start;
367 }
368 $year_start = $now_arr['year'];
369 if ($conf_fiscal_month_start > $now_arr['mon']) {
370 $year_start = $year_start - 1;
371 }
372 $year_end = $year_start + 1;
373 $month_end = $month_start - 1;
374 if ($month_end < 1) {
375 $month_end = 12;
376 $year_end--;
377 }
378 $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
379 $date_end = dol_get_last_day($year_end, $month_end);
380 }
381
382 return array(
383 'date_start' => $date_start,
384 'date_end' => $date_end,
385 );
386}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
getCurrentPeriodOfFiscalYear($db, $conf, $from_time=null)
Get current period of fiscal year.
accounting_prepare_head(AccountingAccount $object)
Prepare array with list of tabs.
is_empty($var, $allow_false=false, $allow_ws=false)
Check if a value is empty with some options.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a page used to transfer/dispatch data in accounting.
clean_account($account)
Return accounting account without zero on the right.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Class to manage accounting accounts.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:613
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.