dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
39function is_empty($var, $allow_false = false, $allow_ws = false)
40{
41 if (is_null($var) || !isset($var) || ($allow_ws == false && trim($var) == "" && !is_bool($var)) || ($allow_false === false && $var === false) || (is_array($var) && empty($var))) {
42 return true;
43 }
44 return false;
45}
46
54{
55 global $langs, $conf;
56
57 $h = 0;
58 $head = array();
59
60 $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$object->id;
61 $head[$h][1] = $langs->trans("AccountAccounting");
62 $head[$h][2] = 'card';
63 $h++;
64
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, 'accounting_account');
70
71 complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
72
73 return $head;
74}
75
82function clean_account($account)
83{
84 $account = rtrim($account, "0");
85
86 return $account;
87}
88
95function length_accountg($account)
96{
97 if ($account < 0 || is_empty($account)) {
98 return '';
99 }
100
101 if (getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
102 return $account;
103 }
104
105 $g = getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT');
106 if (!is_empty($g)) {
107 // Clean parameters
108 $i = strlen($account);
109
110 if ($i >= 1) {
111 while ($i < $g) {
112 $account .= '0';
113
114 $i++;
115 }
116
117 return $account;
118 } else {
119 return $account;
120 }
121 } else {
122 return $account;
123 }
124}
125
132function length_accounta($accounta)
133{
134 global $conf;
135
136 if ($accounta < 0 || is_empty($accounta)) {
137 return '';
138 }
139
140 if (getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) {
141 return $accounta;
142 }
143
144 $a = getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT');
145 if (!is_empty($a)) {
146 // Clean parameters
147 $i = strlen($accounta);
148
149 if ($i >= 1) {
150 while ($i < $a) {
151 $accounta .= '0';
152
153 $i++;
154 }
155
156 return $accounta;
157 } else {
158 return $accounta;
159 }
160 } else {
161 return $accounta;
162 }
163}
164
165
166
183function journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink = '', $moreparam = array(), $calcmode = '', $varlink = '', $moreoptions = array())
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 (!$variant) {
222 print '<td colspan="3">';
223 } else {
224 print '<td>';
225 }
226 print $calcmode;
227 if ($variant) {
228 print '</td><td colspan="2">'.$variant;
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
258 // more options
259 foreach ($moreoptions as $key => $value) {
260 print '<tr>';
261 print '<td>'.$langs->trans($key).'</td>';
262 print '<td colspan="3">'.$value.'</td>';
263 print '</tr>';
264 }
265
266 print '</table>';
267
268 print dol_get_fiche_end();
269
270 print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
271
272 print '</form>';
273
274 print "\n<!-- end banner journal -->\n\n";
275}
276
283{
284 global $db, $conf;
285
286 $date_start = '';
287 $date_end = '';
288 $pastmonth = 0;
289 $pastmonthyear = 0;
290
291 // Period by default on transfer (0: previous month | 1: current month | 2: fiscal year)
292 $periodbydefaultontransfer = getDolGlobalInt('ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER', 0);
293 if ($periodbydefaultontransfer == 2) { // fiscal year
294 $sql = "SELECT date_start, date_end FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
295 $sql .= " WHERE date_start < '".$db->idate(dol_now())."' AND date_end > '".$db->idate(dol_now())."'";
296 $sql .= $db->plimit(1);
297 $res = $db->query($sql);
298 if ($res->num_rows > 0) {
299 $obj = $db->fetch_object($res);
300
301 $date_start = $db->jdate($obj->date_start);
302 $date_end = $db->jdate($obj->date_end);
303 } else {
304 $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
305 $year_start = (int) dol_print_date(dol_now(), '%Y');
306 if ($month_start > (int) dol_print_date(dol_now(), '%m')) {
307 $year_start -= 1;
308 }
309 $year_end = $year_start + 1;
310 $month_end = $month_start - 1;
311 if ($month_end < 1) {
312 $month_end = 12;
313 $year_end--;
314 }
315 $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
316 $date_end = dol_get_last_day($year_end, $month_end);
317 }
318 } elseif ($periodbydefaultontransfer == 1) { // current month
319 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
320 $pastmonth = (int) dol_print_date(dol_now('gmt'), '%m', 'gmt');
321 $pastmonthyear = $year_current;
322 if ($pastmonth == 0) {
323 $pastmonth = 12;
324 $pastmonthyear--;
325 }
326 } else { // previous month
327 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
328 $pastmonth = (int) dol_print_date(dol_now('gmt'), '%m', 'gmt') - 1;
329 $pastmonthyear = $year_current;
330 if ($pastmonth == 0) {
331 $pastmonth = 12;
332 $pastmonthyear--;
333 }
334 }
335 return array(
336 'date_start' => $date_start,
337 'date_end' => $date_end,
338 'pastmonthyear' => $pastmonthyear,
339 'pastmonth' => $pastmonth
340 );
341}
342
353function getCurrentPeriodOfFiscalYear($db, $conf, $from_time = null, $gm = 'tzserver', $withenddateonly = 1)
354{
355 $now = dol_now();
356 $now_arr = dol_getdate($now);
357 if ($from_time === null) {
358 $from_time = $now;
359 } else {
360 $now_arr = dol_getdate($from_time);
361 }
362
363 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
364
365 // Take the first period found
366 $sql = "SELECT date_start, date_end FROM ".$db->prefix()."accounting_fiscalyear";
367 $sql .= " WHERE date_start <= '".$db->idate($from_time, $gm)."'";
368 if ($withenddateonly) {
369 $sql .= " AND (date_end >= '".$db->idate($from_time, $gm)."')";
370 } else {
371 $sql .= " AND (date_end >= '".$db->idate($from_time, $gm)."' OR date_end IS NULL)";
372 }
373 //$sql .= " AND statut = 0"
374 $sql .= " AND entity IN (".getEntity('accounting_fiscalyear').")";
375 $sql .= $db->order('date_start', 'DESC');
376 $sql .= $db->plimit(1);
377
378 $res = $db->query($sql);
379
380 if ($db->num_rows($res) > 0) {
381 // If found
382 $obj = $db->fetch_object($res);
383
384 $date_start = $db->jdate($obj->date_start, $gm);
385 $date_end = dol_get_last_hour($db->jdate($obj->date_end, $gm), $gm);
386 } else {
387 // If not found, we generate a period
388 $month_start = 1;
389 $conf_fiscal_month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START');
390 if ($conf_fiscal_month_start >= 1 && $conf_fiscal_month_start <= 12) {
391 $month_start = $conf_fiscal_month_start;
392 }
393 $year_start = $now_arr['year'];
394 if ($conf_fiscal_month_start > $now_arr['mon']) {
395 $year_start -= 1;
396 }
397 $year_end = $year_start + 1;
398 $month_end = $month_start - 1;
399 if ($month_end < 1) {
400 $month_end = 12;
401 $year_end--;
402 }
403 $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start, $gm);
404 $date_end = dol_get_last_day($year_end, $month_end, $gm);
405 }
406
407 return array(
408 'date_start' => $date_start,
409 'date_end' => $date_end,
410 );
411}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
accounting_prepare_head(AccountingAccount $object)
Prepare array with list of tabs.
getCurrentPeriodOfFiscalYear($db, $conf, $from_time=null, $gm='tzserver', $withenddateonly=1)
Get current period of fiscal year?
journalHead($nom, $variant, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='', $moreoptions=array())
Show header of a page used to transfer/dispatch data in accounting.
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.
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_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Definition date.lib.php:646
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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 a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79