* Copyright (C) 2016-2024 Frédéric France * Copyright (C) 2022 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/paiement_charge.php * \ingroup tax * \brief Page to add payment of a tax */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array("banks", "bills", "compta")); $chid = GETPOSTINT("id"); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel'); $amounts = array(); // Security check $socid = 0; if ($user->socid > 0) { $socid = $user->socid; } $charge = new ChargeSociales($db); /* * Actions */ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) { $error = 0; if ($cancel) { $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid; header("Location: ".$loc); exit; } $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear")); if (!(GETPOST("paiementtype") > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); $error++; $action = 'create'; } if ($datepaye == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); $error++; $action = 'create'; } if (isModEnabled("bank") && !(GETPOST("accountid") > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); $error++; $action = 'create'; } if (!$error) { $paymentid = 0; // Read possible payments foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { $other_chid = substr($key, 7); $amounts[$other_chid] = (float) price2num(GETPOST($key)); } } if (count($amounts) <= 0) { $error++; setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors'); $action = 'create'; } if (!$error) { $db->begin(); // Create a line of payments $paiement = new PaymentSocialContribution($db); $paiement->chid = $chid; $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Amount list $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); $paiement->note = GETPOST("note", 'restricthtml'); $paiement->note_private = GETPOST("note", 'restricthtml'); if (!$error) { $paymentid = $paiement->create($user, (GETPOST('closepaidcontrib') == 'on' ? 1 : 0)); if ($paymentid < 0) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOSTINT('accountid'), '', ''); if (!($result > 0)) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $db->commit(); $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid; header('Location: '.$loc); exit; } else { $db->rollback(); } } } } /* * View */ llxHeader(); $form = new Form($db); // Form of charge payment creation if ($action == 'create') { $charge->fetch($chid); $charge->accountid = $charge->fk_account ? $charge->fk_account : $charge->accountid; $charge->paiementtype = $charge->mode_reglement_id ? $charge->mode_reglement_id : $charge->paiementtype; $total = $charge->amount; if (!empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print load_fiche_titre($langs->trans("DoPayment")); print '
'; print ''; print ''; print ''; print ''; print dol_get_fiche_head('', ''); print ''; print ''; print '\n"; print '\n"; print '\n"; /*print '\n"; print '';*/ $sql = "SELECT sum(p.amount) as total"; $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; $sql .= " WHERE p.fk_charge = ".((int) $chid); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); $sumpaid = $obj->total; $db->free($resql); } /*print ''; print '';*/ print '"; print ''; print '\n"; print ''; print ''; print ''; print ''; // Number print ''; print ''."\n"; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Label").''.$charge->label."
'.$langs->trans("Type")."".$charge->type_label."
'.$langs->trans("Period")."".dol_print_date($charge->periode, 'day')."
'.$langs->trans("DateDue")."".dol_print_date($charge->date_ech,'day')."
'.$langs->trans("Amount")."".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear")); $datepayment = !getDolGlobalString('MAIN_AUTOFILL_DATE') ? (GETPOSTISSET("remonth") ? $datepaye : -1) : ''; print $form->selectDate($datepayment, '', 0, 0, 0, "add_payment", 1, 1, 0, '', '', $charge->date_ech, '', 1, $langs->trans("DateOfSocialContribution")); print "
'.$langs->trans("PaymentMode").''; print img_picto('', 'bank', 'class="pictofixedwidth"'); print $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $charge->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusxx', 1); print "
'.$langs->trans('AccountToDebit').''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); print $form->select_comptes(GETPOSTISSET("accountid") ? GETPOSTINT("accountid") : $charge->accountid, "accountid", 0, '', 2, '', 0, 'maxwidth500 widthcentpercentminusx', 1); // Show opend bank account list print '
'.$langs->trans('Numero'); if (empty($conf->dol_optimize_smallscreen)) { print ' ('.$langs->trans("ChequeOrTransferNumber").')'; } print '
'.$langs->trans("Comments").'
'; print dol_get_fiche_end(); /* * Other unpaid charges */ $num = 1; $i = 0; print '
'; // You can use div-table-responsive-no-min if you don't need reserved height for your table print ''; print ''; //print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $total = 0; $total_ttc = 0; $totalrecu = 0; while ($i < $num) { $objp = $charge; print ''; if ($objp->date_ech > 0) { print ''."\n"; } else { print "\n"; } print '"; print '"; print '"; print '"; print "\n"; $total += $objp->total; $total_ttc += $objp->total_ttc; $totalrecu += $objp->amount; $i++; } if ($i > 1) { // Print total print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } print "
'.$langs->trans("SocialContribution").''.$langs->trans("DateDue").''.$langs->trans("Amount").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.dol_print_date($objp->date_ech, 'day').'!!!'.price($objp->amount)."'.price($sumpaid)."'.price($objp->amount - $sumpaid)."'; if ($sumpaid < $objp->amount) { $namef = "amount_".$objp->id; $nameRemain = "remain_".$objp->id; if (!empty($conf->use_javascript_ajax)) { print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'"); } $remaintopay = $objp->amount - $sumpaid; print ''; print ''; } else { print '-'; } print "
'.$langs->trans("Total").':'.price($total_ttc).''.price($totalrecu).''.price($total_ttc - $totalrecu).' 
"; print '
'; // Save payment button print '
'.$langs->trans("ClosePaidContributionsAutomatically"); print '
'; print '     '; print ''; print '
'; print "
\n"; } llxFooter(); $db->close();