From bc9746891dc3473f965eeeb2f801d0845329e0da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Sep 2024 16:09:06 +0200 Subject: [PATCH] NEW Can change the type of a social contribution if no payment --- .../codespell/codespell-lines-ignore.txt | 2 +- htdocs/compta/sociales/card.php | 34 +++++++++++++------ .../sociales/class/chargesociales.class.php | 24 +++++++------ htdocs/core/tpl/commonfields_view.tpl.php | 2 +- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/dev/tools/codespell/codespell-lines-ignore.txt b/dev/tools/codespell/codespell-lines-ignore.txt index e2acab0de53..b3557522702 100644 --- a/dev/tools/codespell/codespell-lines-ignore.txt +++ b/dev/tools/codespell/codespell-lines-ignore.txt @@ -81,7 +81,7 @@ $sql .= " OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; $sql .= ", '".$this->db->idate($this->periode)."'"; $sql .= ", cs.libelle as label, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode as period, cs.import_key"; - $sql .= ", periode='".$this->db->idate($this->periode)."'"; + $sql .= ", periode = '".$this->db->idate($this->period ? $this->period : $this->periode)."'"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, fk_user, date_creation)"; $sql = "SELECT id_users, nom as name, id_sondage, reponses"; $sql = "SELECT id_users, nom as name, reponses"; diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index debeab8a681..4bebe93f086 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -55,6 +55,7 @@ $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); + $lineid = GETPOSTINT('lineid'); $fk_project = (GETPOST('fk_project') ? GETPOSTINT('fk_project') : 0); @@ -215,7 +216,6 @@ if (empty($reshook)) { } } - if ($action == 'update' && !$cancel && $permissiontoadd) { $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); @@ -234,15 +234,23 @@ if (empty($reshook)) { } else { $result = $object->fetch($id); + $object->oldcopy = dol_clone($object, 2); + + $object->type = $actioncode; $object->date_ech = $dateech; - $object->periode = $dateperiod; $object->period = $dateperiod; + $object->periode = $dateperiod; $object->amount = $amount; $object->fk_user = $fk_user; $result = $object->update($user); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); + } else { + // Reload object to get new value of some properties + if ($object->oldcopy->type != $object->type) { + $object->fetch($id); + } } } } @@ -272,15 +280,13 @@ if (empty($reshook)) { } if (GETPOSTINT('clone_for_next_month')) { // 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->period = dol_time_plus_duree($object->periode, 1, 'm'); + $object->period = dol_time_plus_duree($object->period, 1, 'm'); $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm'); } else { // Note date_ech is often a little bit higher than dateperiod $newdateperiod = dol_mktime(0, 0, 0, GETPOSTINT('clone_periodmonth'), GETPOSTINT('clone_periodday'), GETPOSTINT('clone_periodyear')); $newdateech = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_echmonth'), GETPOSTINT('clone_date_echday'), GETPOSTINT('clone_date_echyear')); if ($newdateperiod) { - $object->periode = $newdateperiod; $object->period = $newdateperiod; if (empty($newdateech)) { $object->date_ech = $object->periode; @@ -290,8 +296,7 @@ if (empty($reshook)) { $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; + // $object->period = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m) $object->period = $object->date_ech; } } @@ -579,8 +584,15 @@ if ($id > 0) { print ''; // Type - print '"; + print '"; + print ""; // Date @@ -596,9 +608,9 @@ if ($id > 0) { print ""; print ""; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 73247ac0f4f..8e7f63f8e6c 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -351,13 +351,17 @@ class ChargeSociales extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; - $sql .= " SET libelle='".$this->db->escape($this->label ? $this->label : $this->lib)."'"; - $sql .= ", date_ech='".$this->db->idate($this->date_ech)."'"; - $sql .= ", periode='".$this->db->idate($this->periode)."'"; - $sql .= ", amount='".price2num($this->amount, 'MT')."'"; - $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "NULL"); - $sql .= ", fk_user=".($this->fk_user > 0 ? $this->db->escape($this->fk_user) : "NULL"); - $sql .= ", fk_user_modif=".$user->id; + $sql .= " SET libelle = '".$this->db->escape($this->label ? $this->label : $this->lib)."'"; + $sql .= ", date_ech = '".$this->db->idate($this->date_ech)."'"; + $sql .= ", periode = '".$this->db->idate($this->period ? $this->period : $this->periode)."'"; + $sql .= ", amount = ".((float) price2num($this->amount, 'MT')); + $sql .= ", fk_projet=".($this->fk_project > 0 ? ((int) $this->fk_project) : "NULL"); + $sql .= ", fk_user=".($this->fk_user > 0 ? ((int) $this->fk_user) : "NULL"); + $sql .= ", fk_user_modif=".((int) $user->id); + if ($this->type > 0) { + $sql .= ", fk_type = ".((int) $this->type); + } + $sql .= ", fk_user_modif=".((int) $user->id); $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -401,14 +405,12 @@ class ChargeSociales extends CommonObject */ public function solde($year = 0) { - global $conf; - $sql = "SELECT SUM(f.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; - $sql .= " WHERE f.entity = ".$conf->entity; + $sql .= " WHERE f.entity = ".((int) $conf->entity); $sql .= " AND paye = 0"; - if ($year) { + if ($year) { // TODO Fix to use date function $sql .= " AND f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' "; } diff --git a/htdocs/core/tpl/commonfields_view.tpl.php b/htdocs/core/tpl/commonfields_view.tpl.php index 90e4f80065c..a988d842c2b 100644 --- a/htdocs/core/tpl/commonfields_view.tpl.php +++ b/htdocs/core/tpl/commonfields_view.tpl.php @@ -58,7 +58,7 @@ foreach ($object->fields as $key => $val) { $value = $object->$key; print ' 0) print ' fieldrequired'; // No fieldrequired on the view output if ($val['type'] == 'text' || $val['type'] == 'html') { print ' tdtop';
'; - print $langs->trans("Type")."".$object->type_label."
'; + print $langs->trans("Type").""; + if ($action == 'edit' && $object->getSommePaiement() == 0) { + $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha') ? GETPOST("actioncode", 'alpha') : $object->type, 'actioncode', 1); + } else { + print $object->type_label; + } + print "
".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).""; if ($action == 'edit') { - print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1); + print $form->selectDate($object->period, 'period', 0, 0, 0, 'charge', 1); } else { - print dol_print_date($object->periode, "day"); + print dol_print_date($object->period, "day"); } print "