// Security check
$socid = GETPOST('socid', 'int');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'tax', $id, 'chargesociales', 'charges');
/* *************************************************************************** */
/*                                                                             */
/* Actions                                                                     */
/*                                                                             */
/* *************************************************************************** */
// Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes') {
    $chargesociales = new ChargeSociales($db);
    $chargesociales->fetch($id);
    $result = $chargesociales->set_paid($user);
}
// Delete social contribution
if ($action == 'confirm_delete' && $confirm == 'yes') {
    $chargesociales = new ChargeSociales($db);
    $chargesociales->fetch($id);
    $result = $chargesociales->delete($user);
    if ($result > 0) {
        header("Location: index.php");
        exit;
    } else {
        $mesg = '<div class="error">' . $chargesociales->error . '</div>';
    }
}
// Add social contribution
if ($action == 'add' && $user->rights->tax->charges->creer) {
     $paiement->amounts = $amount;
     // Tableau de montant
     $paiement->paiementtype = $_POST["paiementtype"];
     $paiement->num_paiement = $_POST["num_paiement"];
     $paiement->note = $_POST["note"];
     if (!$error) {
         $paymentid = $paiement->create($user);
         if ($paymentid < 0) {
             $errmsg = $paiement->error;
             $error++;
         }
     }
     if (!$error) {
         $result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', $_POST['accountid'], '', '');
         if ($charge->amount == $amount[$id]) {
             $charge->set_paid($user);
         }
         if (!$result > 0) {
             $errmsg = $paiement->error;
             $error++;
         }
     }
 }
 if (!$error) {
     $db->commit();
     $loc = DOL_URL_ROOT . '/compta/sociales/index.php?leftmenu=tax_social';
     header('Location: ' . $loc);
     exit;
 } else {
     $db->rollback();
 }