From 2d771704d0d088af79eb674e7187f822ed7f20f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 9 Apr 2021 00:36:08 +0200 Subject: [PATCH] Better suggestion for data after clone of social contribution --- htdocs/compta/sociales/card.php | 15 ++++++++++++--- .../sociales/class/chargesociales.class.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index b2ac294021c..0f38181e284 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -235,17 +235,26 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->char $object->label = $langs->trans("CopyOf").' '.$object->label; } - if (GETPOST('clone_for_next_month', 'int')) { + if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set $object->periode = dol_time_plus_duree($object->periode, 1, 'm'); $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm'); } else { + // Note dateech is often a little bit higher than dateperiod $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int')); $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int')); if ($newdateperiod) { $object->periode = $newdateperiod; + if (empty($newdateech)) { + $object->date_ech = $object->periode; + } } if ($newdateech) { $object->date_ech = $newdateech; + if (empty($newdateperiod)) { + // TODO We can here get dol_get_last_day of previous month: + // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m) + $object->periode = $object->date_ech; + } } } @@ -410,9 +419,9 @@ if ($id > 0) { // Clone confirmation if ($action === 'clone') { $formquestion = array( - array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), + array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass'=>'fieldrequired'), ); - if (!empty($conf->global->TAX_ADD_CLON_FOR_NEXT_MONTH_CHECKBOX)) { + if (!empty($conf->global->TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX)) { $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1); } else { $formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1); diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index d7fcd9278a9..20cc2c82b0c 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -197,7 +197,7 @@ class ChargeSociales extends CommonObject { $newamount = price2num($this->amount, 'MT'); - // Validation parametres + // Validation of parameters if (!$newamount > 0 || empty($this->date_ech) || empty($this->periode)) { return false; }