* Copyright (C) 2016-2021 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * * 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/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.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")); $chid = GETPOST("id", 'int'); $action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel'); $amounts = array(); // Security check $socid = 0; if ($user->socid > 0) { $socid = $user->socid; } /* * Actions */ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) { $error = 0; if ($cancel) { $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid; header("Location: ".$loc); exit; } $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); if (!(GETPOST("paiementtype", 'int') > 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("banque") && !(GETPOST("accountid", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); $error++; $action = 'create'; } // Read possible payments foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { $other_chid = substr($key, 7); $amounts[$other_chid] = price2num(GETPOST($key)); } } if (empty($amounts[key($amounts)])) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } if (!$error) { $paymentid = 0; if (!$error) { $db->begin(); // Create a line of payments $paiement = new PaymentVAT($db); $paiement->chid = $chid; $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Tableau de montant $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); $paiement->note = (string) GETPOST("note", 'restricthtml'); $paiement->note_private = (string) GETPOST("note", 'restricthtml'); if (!$error) { $paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0)); if ($paymentid < 0) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', ''); if (!($result > 0)) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $db->commit(); $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid; header('Location: '.$loc); exit; } else { $db->rollback(); } } } } /* * View */ llxHeader(); $form = new Form($db); // Formulaire de creation d'un paiement de charge if ($action == 'create') { $tva = new Tva($db); $tva->fetch($chid); $tva->accountid = $tva->fk_account ? $tva->fk_account : $tva->accountid; $tva->paiementtype = $tva->type_payment; $total = $tva->amount; if (!empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print load_fiche_titre($langs->trans("DoPayment")); print "
\n"; 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."payment_vat as p"; $sql .= " WHERE p.fk_tva = ".((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("Type")."".$tva->type_label."
'.$langs->trans("Period")."".dol_print_date($tva->datev, 'day')."
'.$langs->trans("Label").''.$tva->label."
'.$langs->trans("DateDue")."".dol_print_date($tva->date_ech,'day')."
'.$langs->trans("Amount")."".price($tva->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, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (GETPOST("remonth", 'int') ? $datepaye : -1) : 0; print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print "
'.$langs->trans("PaymentMode").''; print $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype", "int") : $tva->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1); print "
'.$langs->trans('AccountToDebit').''; print img_picto('', 'bank_account', 'pictofixedwidth'); $form->select_comptes(GETPOST("accountid", "int") ? GETPOST("accountid", "int") : $tva->accountid, "accountid", 0, '', 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("Comments").'
'; print dol_get_fiche_end(); /* * Autres charges impayees */ $num = 1; $i = 0; print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; //print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $total = 0; $totalrecu = 0; while ($i < $num) { $objp = $tva; print ''; if ($objp->datev > 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->datev, 'day').'!!!'.price($objp->amount)."'.price($sumpaid)."'.price($objp->amount - $sumpaid)."'; if ($sumpaid <> $objp->amount) { $namef = "amount_".$objp->id; $nameRemain = "remain_".$objp->id; /* Disabled, we autofil the amount with remain to pay by default 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 '
'; // Bouton Save payment print '
'.$langs->trans("ClosePaidVATAutomatically"); print '
'; print '     '; print ''; print '
'; print "
\n"; } llxFooter(); $db->close();