From db8596743c7c081674420aa3a53edc68c75dd851 Mon Sep 17 00:00:00 2001 From: Vaadasch Date: Thu, 7 May 2020 22:09:55 +0200 Subject: [PATCH 1/3] Update facture.class.php Auto-update dates (if not empty) of services when cloning facture. Actual code is only for month by month. If empty (start or end) => do nothing If set, update for next month if there is only 1d between what had been set and the start (or end) of the month. If there is more than one day from start or end of the month => do nothing, because we're not sure the service is by month Worst case scenario : the facture is cloned, the service is updated with new unwanted dates User need to manually updates date : he would have done that either way --- htdocs/compta/facture/class/facture.class.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 90ed560b3cf..395de47d443 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1177,6 +1177,30 @@ class Facture extends CommonInvoice { unset($object->lines[$i]); unset($object->products[$i]); // Tant que products encore utilise + } + // Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month) + // If it's a service with start and end dates + if ($line->product_type == 1 && !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']); + + // 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) { + $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']); + $object->lines[$i]->date_start = $newFirst; + $object->lines[$i]->date_end = $newLast; + } } } From 7514a625fdb17a9226185ddc9a7fda64b84f625e Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 7 May 2020 20:11:59 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/compta/facture/class/facture.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 395de47d443..ffa96fe5237 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1184,7 +1184,7 @@ class Facture extends CommonInvoice // 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']); @@ -1196,8 +1196,8 @@ class Facture extends CommonInvoice // If there is <= 1d (or 2?) of start/or/end of month if ($diffFirst <= 2 && $diffLast <= 2) { $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']); + $newFirst = dol_get_first_day($nextMonth['year'], $nextMonth['month']); + $newLast = dol_get_last_day($nextMonth['year'], $nextMonth['month']); $object->lines[$i]->date_start = $newFirst; $object->lines[$i]->date_end = $newLast; } From f23451e1c986143235b7aea6750293b878f0e1f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 May 2020 23:04:52 +0200 Subject: [PATCH 3/3] Update facture.class.php --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ffa96fe5237..fd6a6d32642 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1180,7 +1180,7 @@ class Facture extends CommonInvoice } // Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month) // If it's a service with start and end dates - if ($line->product_type == 1 && !empty($line->date_start) && !empty($line->date_end) ) { + if (!empty($line->date_start) && !empty($line->date_end) ) { // Get the dates $start = dol_getdate($line->date_start); $end = dol_getdate($line->date_end);