This commit is contained in:
Laurent Destailleur 2021-01-28 09:59:13 +01:00
parent 0b393676e6
commit f462e353e9
2 changed files with 30 additions and 19 deletions

View File

@ -1191,23 +1191,23 @@ class Facture extends CommonInvoice
{
unset($object->lines[$i]);
}
// Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month)
// Bloc to update dates of service (month by month only if previously filled and similare to start and end of month)
// If it's a service with start and end dates
if (!empty($line->date_start) && !empty($line->date_end)) {
if (!empty($conf->global->INVOICE_AUTO_NEXT_MONTH_ON_LINES) && !empty($line->date_start) && !empty($line->date_end)) {
// Get the dates
$start = dol_getdate($line->date_start);
$end = dol_getdate($line->date_end);
// Get the first and last day of the month
$first = dol_get_first_day($start['year'], $start['mon']);
$last = dol_get_first_day($end['year'], $end['mon']);
$last = dol_get_last_day($end['year'], $end['mon']);
// Get diff betweend start/end of month and previously filled
$diffFirst = num_between_day($first, dol_mktime($start['hours'], $start['minutes'], $start['seconds'], $start['mon'], $start['mday'], $start['year'], 'user'));
$diffLast = num_between_day(dol_mktime($end['hours'], $end['minutes'], $end['seconds'], $end['mon'], $end['mday'], $end['year'], 'user'), $last);
// If there is <= 1d (or 2?) of start/or/end of month
if ($diffFirst <= 2 && $diffLast <= 2) {
//print dol_print_date(dol_mktime(0, 0, 0, $start['mon'], $start['mday'], $start['year'], 'gmt'), 'dayhour').' '.dol_print_date($first, 'dayhour').'<br>';
//print dol_mktime(23, 59, 59, $end['mon'], $end['mday'], $end['year'], 'gmt').' '.$last.'<br>';exit;
// If start date is first date of month and end date is last date of month
if (dol_mktime(0, 0, 0, $start['mon'], $start['mday'], $start['year'], 'gmt') == $first
&& dol_mktime(23, 59, 59, $end['mon'], $end['mday'], $end['year'], 'gmt') == $last) {
$nextMonth = dol_get_next_month($end['mon'], $end['year']);
$newFirst = dol_get_first_day($nextMonth['year'], $nextMonth['month']);
$newLast = dol_get_last_day($nextMonth['year'], $nextMonth['month']);

View File

@ -356,7 +356,8 @@ function dol_stringtotime($string, $gm = 1)
}
/** Return previous day
/**
* Return previous day
*
* @param int $day Day
* @param int $month Month
@ -371,7 +372,8 @@ function dol_get_prev_day($day, $month, $year)
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return next day
/**
* Return next day
*
* @param int $day Day
* @param int $month Month
@ -386,7 +388,8 @@ function dol_get_next_day($day, $month, $year)
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return previous month
/**
* Return previous month
*
* @param int $month Month
* @param int $year Year
@ -405,7 +408,8 @@ function dol_get_prev_month($month, $year)
return array('year' => $prev_year, 'month' => $prev_month);
}
/** Return next month
/**
* Return next month
*
* @param int $month Month
* @param int $year Year
@ -424,7 +428,8 @@ function dol_get_next_month($month, $year)
return array('year' => $next_year, 'month' => $next_month);
}
/** Return previous week
/**
* Return previous week
*
* @param int $day Day
* @param int $week Week
@ -442,7 +447,8 @@ function dol_get_prev_week($day, $week, $month, $year)
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return next week
/**
* Return next week
*
* @param int $day Day
* @param int $week Week
@ -461,7 +467,8 @@ function dol_get_next_week($day, $week, $month, $year)
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return GMT time for first day of a month or year
/**
* Return GMT time for first day of a month or year
*
* @param int $year Year
* @param int $month Month
@ -478,7 +485,9 @@ function dol_get_first_day($year, $month = 1, $gm = false)
}
/** Return GMT time for last day of a month or year
/**
* Return GMT time for last day of a month or year.
* Note: The timestamp contains last day and last hours (23:59:59)
*
* @param int $year Year
* @param int $month Month
@ -504,7 +513,8 @@ function dol_get_last_day($year, $month = 12, $gm = false)
return $datelim;
}
/** Return GMT time for last hour of a given GMT date (it removes hours, min and second part)
/**
* Return GMT time for last hour of a given GMT date (it removes hours, min and second part)
*
* @param int $date Date
* @return int Date for last hour of a given date
@ -515,7 +525,8 @@ function dol_get_last_hour($date)
return dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], false);
}
/** Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
/**
* Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
*
* @param int $date Date
* @return int Date for last hour of a given date