* * 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 */ 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'; $langs->load("bills"); $chid=GETPOST("id"); $action=GETPOST('action'); $amounts = array(); // Security check $socid=0; if ($user->societe_id > 0) { $socid = $user->societe_id; } /* * Actions */ if ($action == 'add_payment') { $error=0; if ($_POST["cancel"]) { $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; header("Location: ".$loc); exit; } $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); if (! $_POST["paiementtype"] > 0) { $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); $error++; } if ($datepaye == '') { $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); $error++; } if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0) { $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")); $error++; } 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] = price2num($_POST[$key]); } } if (count($amounts) <= 0) { $error++; $errmsg='ErrorNoPaymentDefined'; } if (! $error) { $db->begin(); // Create a line of payments $paiement = new PaymentSocialContribution($db); $paiement->chid = $chid; $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // 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 (! $result > 0) { $errmsg=$paiement->error; $error++; } } if (! $error) { $db->commit(); $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; header('Location: '.$loc); exit; } else { $db->rollback(); } } } $_GET["action"]='create'; } /* * View */ llxHeader(); $form=new Form($db); // Formulaire de creation d'un paiement de charge if ($_GET["action"] == 'create') { $charge = new ChargeSociales($db); $charge->fetch($chid); $total = $charge->amount; print_fiche_titre($langs->trans("DoPayment")); print "
\n"; if ($mesg) { print "
$mesg
"; } print '
'; print ''; print ''; print ''; print ''; dol_fiche_head('', ''); print ''; 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 = ".$chid; $resql = $db->query($sql); if ($resql) { $obj=$db->fetch_object($resql); $sumpaid = $obj->total; $db->free(); } print ''; print ''; print ''; print "'; print ''; print '"; print ''; print '\n"; print ''; print ''; print ''; print ''; // Number print ''; print ''."\n"; print ''; print ''; print ''; print ''; print '
".$langs->trans("SocialContribution")."
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Type")."".$charge->type_libelle."
'.$langs->trans("Period")."".dol_print_date($charge->periode,'day')."
'.$langs->trans("Label").''.$charge->lib."
'.$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("Payment").'
'.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; $form->select_date($datepayment,'','','','',"add_payment",1,1); print "
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype"); print "
'.$langs->trans('AccountToDebit').''; $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("Comments").'
'; dol_fiche_end(); /* * Autres charges impayees */ $num = 1; $i = 0; print ''; print ''; //print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=true; $total=0; $totalrecu=0; while ($i < $num) { $objp = $charge; $var=!$var; 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->am; $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; print ''; } else { print '-'; } print "
'.$langs->trans("Total").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; print '
'; print ''; print '     '; print ''; print '
'; print "
\n"; } $db->close(); llxFooter();