dolibarr 21.0.0-beta
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
30$now = dol_now();
31$current_date = dol_getdate($now);
32if (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START')) {
33 $conf->global->SOCIETE_FISCAL_MONTH_START = 1;
34}
35
36// Date range
37$year = GETPOSTINT("year");
38if (empty($year)) {
39 $year_current = $current_date['year'];
40 $year_start = $year_current;
41} else {
42 $year_current = $year;
43 $year_start = $year;
44}
45$date_start = dol_mktime(0, 0, 0, GETPOSTINT("date_startmonth"), GETPOSTINT("date_startday"), GETPOSTINT("date_startyear"), 'tzserver');
46$date_end = dol_mktime(23, 59, 59, GETPOSTINT("date_endmonth"), GETPOSTINT("date_endday"), GETPOSTINT("date_endyear"), 'tzserver');
47// Set default period if not defined
48if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
49 $q = GETPOSTINT("q");
50 if (empty($q)) {
51 if (GETPOSTINT("month")) {
52 $date_start = dol_get_first_day($year_start, GETPOSTINT("month"), 'tzserver');
53 $date_end = dol_get_last_day($year_start, GETPOSTINT("month"), 'tzserver');
54 } else {
55 if (!getDolGlobalString('MAIN_INFO_VAT_RETURN') || getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 2) { // quaterly vat, we take last past complete quarter
56 $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');
57 $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
58 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 3) { // yearly vat
59 if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) {
60 if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year
61 $year_start--;
62 }
63 } else {
64 if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year
65 $year_start--;
66 }
67 }
68 $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, 'tzserver');
69 $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
70 } elseif (getDolGlobalInt('MAIN_INFO_VAT_RETURN') == 1) { // monthly vat, we take last past complete month
71 $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm');
72 $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
73 }
74 }
75 } else {
76 if ($q == 1) {
77 $date_start = dol_get_first_day($year_start, 1, 'tzserver');
78 $date_end = dol_get_last_day($year_start, 3, 'tzserver');
79 }
80 if ($q == 2) {
81 $date_start = dol_get_first_day($year_start, 4, 'tzserver');
82 $date_end = dol_get_last_day($year_start, 6, 'tzserver');
83 }
84 if ($q == 3) {
85 $date_start = dol_get_first_day($year_start, 7, 'tzserver');
86 $date_end = dol_get_last_day($year_start, 9, 'tzserver');
87 }
88 if ($q == 4) {
89 $date_start = dol_get_first_day($year_start, 10, 'tzserver');
90 $date_end = dol_get_last_day($year_start, 12, 'tzserver');
91 }
92 }
93}
94
95//print dol_print_date($date_start, 'day').' '.dol_print_date($date_end, 'day');
96
97$tmp = dol_getdate($date_start);
98$date_start_day = $tmp['mday'];
99$date_start_month = $tmp['mon'];
100$date_start_year = $tmp['year'];
101$tmp = dol_getdate($date_end);
102$date_end_day = $tmp['mday'];
103$date_end_month = $tmp['mon'];
104$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:600
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: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...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79