NEW Can change the type of a social contribution if no payment

This commit is contained in:
Laurent Destailleur 2024-09-20 16:09:06 +02:00
parent a2edb28f5d
commit bc9746891d
4 changed files with 38 additions and 24 deletions

View File

@ -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";

View File

@ -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 '<table class="border centpercent tableforfield">';
// Type
print '<tr><td class="titlefield">';
print $langs->trans("Type")."</td><td>".$object->type_label."</td>";
print '<tr><td class="titlefieldmiddle">';
print $langs->trans("Type")."</td><td>";
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 "</td>";
print "</tr>";
// Date
@ -596,9 +608,9 @@ if ($id > 0) {
print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
print "<td>";
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 "</td></tr>";

View File

@ -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' ";
}

View File

@ -58,7 +58,7 @@ foreach ($object->fields as $key => $val) {
$value = $object->$key;
print '<tr class="field_'.$key.'"><td';
print ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
print ' class="'.(empty($val['tdcss']) ? 'titlefieldmiddle' : $val['tdcss']).' fieldname_'.$key;
//if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
if ($val['type'] == 'text' || $val['type'] == 'html') {
print ' tdtop';