diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index 1a0760d1fd3..b90e7cac3cb 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -200,7 +200,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $i++; } print ''.$langs->trans("Total").''; - print ''.price($total).""; + print ''; // A total here has no sense print ' '; print ' '; print ' '; @@ -278,7 +278,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) $i++; } print ''.$langs->trans("Total").''; - print ''.price($total).""; + print ''.price($total).''; print ' '; print ' '; print ''.price($total).""; @@ -463,7 +463,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $i++; } print ''.$langs->trans("Total").''; - print ''.""; + print ''; // A total here has no sense print ' '; print ' '; print ''.price($total).""; diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 2a9894be87a..abcb5e0ad06 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -39,6 +39,7 @@ $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); +$object = new ChargeSociales($db); @@ -49,19 +50,32 @@ $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); /* *************************************************************************** */ // Classify paid -if ($action == 'confirm_paid' && $confirm == 'yes') +if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { - $chargesociales = new ChargeSociales($db); - $chargesociales->fetch($id); - $result = $chargesociales->set_paid($user); + $object->fetch($id); + $result = $object->set_paid($user); +} + +if ($action == 'reopen' && $user->rights->tax->charges->creer) { + $result = $object->fetch($id); + if ($object->paye) + { + $result = $object->set_unpaid($user); + if ($result > 0) + { + header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } } // Delete social contribution if ($action == 'confirm_delete' && $confirm == 'yes') { - $chargesociales=new ChargeSociales($db); - $chargesociales->fetch($id); - $result=$chargesociales->delete($user); + $object->fetch($id); + $result=$object->delete($user); if ($result > 0) { header("Location: index.php"); @@ -69,7 +83,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') } else { - setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -77,8 +91,8 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add social contribution if ($action == 'add' && $user->rights->tax->charges->creer) { - $dateech=@dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); - $dateperiod=@dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); + $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); + $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $amount=price2num(GETPOST('amount')); $actioncode=GETPOST('actioncode'); if (! $dateech) @@ -108,18 +122,16 @@ if ($action == 'add' && $user->rights->tax->charges->creer) } else { - $chargesociales=new ChargeSociales($db); + $object->type=$actioncode; + $object->lib=GETPOST('label'); + $object->date_ech=$dateech; + $object->periode=$dateperiod; + $object->amount=$amount; - $chargesociales->type=$actioncode; - $chargesociales->lib=GETPOST('label'); - $chargesociales->date_ech=$dateech; - $chargesociales->periode=$dateperiod; - $chargesociales->amount=$amount; - - $id=$chargesociales->create($user); + $id=$object->create($user); if ($id <= 0) { - setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $action='create'; } } @@ -153,18 +165,17 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr } else { - $chargesociales=new ChargeSociales($db); - $result=$chargesociales->fetch($id); + $result=$object->fetch($id); - $chargesociales->lib=GETPOST('label'); - $chargesociales->date_ech=$dateech; - $chargesociales->periode=$dateperiod; - $chargesociales->amount=price2num($amount); + $object->lib=GETPOST('label'); + $object->date_ech=$dateech; + $object->periode=$dateperiod; + $object->amount=price2num($amount); - $result=$chargesociales->update($user); + $result=$object->update($user); if ($result <= 0) { - setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -178,7 +189,6 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->char $originalId = $id; - $object = new ChargeSociales($db); $object->fetch($id); if ($object->id > 0) @@ -499,6 +509,12 @@ if ($id > 0) { print "
\n"; + // Reopen + if ($object->paye && $user->rights->tax->charges->creer) + { + print "id&action=reopen\">".$langs->trans("ReOpen").""; + } + // Edit if ($object->paye == 0 && $user->rights->tax->charges->creer) { diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 7712fd09029..1499c79d683 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -339,7 +339,22 @@ class ChargeSociales extends CommonObject if ($return) return 1; else return -1; } - + /** + * Remove tag payed on social contribution + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + function set_unpaid($user) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; + $sql.= " paye = 0"; + $sql.= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + /** * Retourne le libelle du statut d'une charge (impaye, payee) *