dolibarr 23.0.3
initdatesforvat.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.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 * or see https://www.gnu.org/
18 */
19
29$now = dol_now();
30$current_date = dol_getdate($now);
31if (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START')) {
32 $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
33}
34
35// Date range
36$year = GETPOSTINT("year");
37if (empty($year)) {
38 $year_current = $current_date['year'];
39 $year_start = $year_current;
40} else {
41 $year_current = $year;
42 $year_start = $year;
43}
44$date_start = dol_mktime(0, 0, 0, GETPOSTINT("date_startmonth"), GETPOSTINT("date_startday"), GETPOSTINT("date_startyear"), 'tzserver');
45$date_end = dol_mktime(23, 59, 59, GETPOSTINT("date_endmonth"), GETPOSTINT("date_endday"), GETPOSTINT("date_endyear"), 'tzserver');
46// Set default period if not defined
47if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
48 $q = GETPOSTINT("q");
49 if (empty($q)) {
50 if (GETPOSTINT("month")) {
51 $date_start = dol_get_first_day($year_start, GETPOSTINT("month"), 'tzserver');
52 $date_end = dol_get_last_day($year_start, GETPOSTINT("month"), 'tzserver');
53 } else {
54 if (!getDolGlobalString('MAIN_INFO_VAT_RETURN') || getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 2) { // quaterly vat, we take last past complete quarter
55 $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm');
56 $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
57 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 3) { // yearly vat
58 if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) {
59 if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year
60 $year_start--;
61 }
62 } else {
63 if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year
64 $year_start--;
65 }
66 }
67 $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, 'tzserver');
68 $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
69 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 1) { // monthly vat, we take last past complete month
70 $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm');
71 $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
72 }
73 }
74 } else {
75 if ($q == 1) {
76 $date_start = dol_get_first_day($year_start, 1, 'tzserver');
77 $date_end = dol_get_last_day($year_start, 3, 'tzserver');
78 }
79 if ($q == 2) {
80 $date_start = dol_get_first_day($year_start, 4, 'tzserver');
81 $date_end = dol_get_last_day($year_start, 6, 'tzserver');
82 }
83 if ($q == 3) {
84 $date_start = dol_get_first_day($year_start, 7, 'tzserver');
85 $date_end = dol_get_last_day($year_start, 9, 'tzserver');
86 }
87 if ($q == 4) {
88 $date_start = dol_get_first_day($year_start, 10, 'tzserver');
89 $date_end = dol_get_last_day($year_start, 12, 'tzserver');
90 }
91 }
92}
93
94//print dol_print_date($date_start, 'day').' '.dol_print_date($date_end, 'day');
95
96$tmp = dol_getdate($date_start);
97$date_start_day = $tmp['mday'];
98$date_start_month = $tmp['mon'];
99$date_start_year = $tmp['year'];
100$tmp = dol_getdate($date_end);
101$date_end_day = $tmp['mday'];
102$date_end_month = $tmp['mon'];
103$date_end_year = $tmp['year'];
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:603
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:622
dol_now($mode='gmt')
Return date for now.
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...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.