dolibarr/htdocs/compta/paiement_charge.php

347 lines
11 KiB
PHP
Raw Normal View History

<?php
2018-09-09 09:36:12 +02:00
/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2016-2018 Frédéric France <frederic.france@netlogic.fr>
*
* 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
2011-08-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
2018-09-09 09:36:12 +02:00
* \file htdocs/compta/paiement_charge.php
* \ingroup tax
* \brief Page to add payment of a tax
2010-02-10 18:07:25 +01:00
*/
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';
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs->load("bills");
$chid=GETPOST("id", 'int');
$action=GETPOST('action', 'alpha');
2010-09-09 03:26:07 +02:00
$amounts = array();
2010-09-09 03:26:07 +02:00
// Security check
$socid=0;
2009-03-03 00:09:03 +01:00
if ($user->societe_id > 0)
{
2010-02-10 18:07:25 +01:00
$socid = $user->societe_id;
}
/*
* Actions
*/
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm=='yes'))
{
2010-09-30 22:06:37 +02:00
$error=0;
if ($_POST["cancel"])
{
2016-08-22 13:43:49 +02:00
$loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
2012-08-31 05:58:38 +02:00
header("Location: ".$loc);
exit;
}
2011-09-20 11:59:08 +02:00
$datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
2009-03-03 00:09:03 +01:00
2010-02-10 18:07:25 +01:00
if (! $_POST["paiementtype"] > 0)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
2010-02-10 18:07:25 +01:00
$error++;
2017-10-07 21:27:18 +02:00
$action = 'create';
2010-02-10 18:07:25 +01:00
}
if ($datepaye == '')
2010-02-10 18:07:25 +01:00
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
2010-02-10 18:07:25 +01:00
$error++;
2017-10-07 21:27:18 +02:00
$action = 'create';
2010-02-10 18:07:25 +01:00
}
2012-09-15 11:21:22 +02:00
if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
$error++;
2017-10-07 21:27:18 +02:00
$action = 'create';
}
2010-02-10 18:07:25 +01:00
if (! $error)
{
2010-05-22 08:38:26 +02:00
$paymentid = 0;
2010-02-10 18:07:25 +01:00
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_')
2010-02-10 18:07:25 +01:00
{
$other_chid = substr($key, 7);
2010-09-09 03:26:07 +02:00
$amounts[$other_chid] = price2num($_POST[$key]);
2010-02-10 18:07:25 +01:00
}
}
2011-09-17 21:49:50 +02:00
if (count($amounts) <= 0)
{
$error++;
2017-10-07 21:27:18 +02:00
setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
$action='create';
}
2010-09-09 03:26:07 +02:00
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, (GETPOST('closepaidcontrib')=='on'?1:0));
if ($paymentid < 0)
{
2017-10-07 21:27:18 +02:00
$error++;
setEventMessages($paiement->error, null, 'errors');
$action='create';
}
}
if (! $error)
2010-09-09 03:26:07 +02:00
{
$result=$paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOST('accountid', 'int'), '', '');
2017-10-07 21:27:18 +02:00
if (! ($result > 0))
{
2017-10-07 21:27:18 +02:00
$error++;
setEventMessages($paiement->error, null, 'errors');
$action='create';
}
2010-09-09 03:26:07 +02:00
}
if (! $error)
{
$db->commit();
2016-08-22 13:43:49 +02:00
$loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
2012-08-31 05:58:38 +02:00
header('Location: '.$loc);
exit;
}
else
{
$db->rollback();
}
2010-09-09 03:26:07 +02:00
}
2010-02-10 18:07:25 +01:00
}
}
/*
* View
*/
llxHeader();
$form=new Form($db);
// Formulaire de creation d'un paiement de charge
if ($action == 'create')
{
2010-02-10 18:07:25 +01:00
$charge = new ChargeSociales($db);
$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;
2010-02-10 18:07:25 +01:00
$total = $charge->amount;
if (! empty($conf->use_javascript_ajax))
{
print "\n".'<script type="text/javascript" language="javascript">';
//Add js for AutoFill
print ' $(document).ready(function () {';
print ' $(".AutoFillAmount").on(\'click touchstart\', function(){
var amount = $(this).data("value");
document.getElementById($(this).data(\'rowid\')).value = amount ;
});';
print ' });'."\n";
print ' </script>'."\n";
}
print load_fiche_titre($langs->trans("DoPayment"));
2010-02-10 18:07:25 +01:00
print "<br>\n";
if ($mesg)
{
print "<div class=\"error\">$mesg</div>";
}
print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
2010-02-10 18:07:25 +01:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$chid.'">';
print '<input type="hidden" name="chid" value="'.$chid.'">';
print '<input type="hidden" name="action" value="add_payment">';
2009-03-03 00:09:03 +01:00
dol_fiche_head('', '');
print '<table class="border" width="100%">';
2017-10-16 20:53:23 +02:00
print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td><a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid.'">'.$chid.'</a></td></tr>';
print '<tr><td>'.$langs->trans("Type")."</td><td>".$charge->type_libelle."</td></tr>\n";
print '<tr><td>'.$langs->trans("Period")."</td><td>".dol_print_date($charge->periode, 'day')."</td></tr>\n";
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$charge->lib."</td></tr>\n";
2017-10-16 20:53:23 +02:00
/*print '<tr><td>'.$langs->trans("DateDue")."</td><td>".dol_print_date($charge->date_ech,'day')."</td></tr>\n";
print '<tr><td>'.$langs->trans("Amount")."</td><td>".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
2010-02-10 18:07:25 +01:00
$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();
}
2017-10-16 20:53:23 +02:00
/*print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td>'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
print '<tr><td class="tdtop">'.$langs->trans("RemainderToPay").'</td><td>'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
2010-02-10 18:07:25 +01:00
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
2011-09-20 11:59:08 +02:00
$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;
2018-09-08 13:00:39 +02:00
print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1);
2010-02-10 18:07:25 +01:00
print "</td>";
print '</tr>';
2010-02-10 18:07:25 +01:00
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
$form->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype");
2010-02-10 18:07:25 +01:00
print "</td>\n";
print '</tr>';
2010-02-10 18:07:25 +01:00
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td>';
$form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '', 1); // Show opend bank account list
2010-02-10 18:07:25 +01:00
print '</td></tr>';
// Number
2010-02-10 18:07:25 +01:00
print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>';
print '<td><input name="num_paiement" type="text" value="'.GETPOST('num_paiement').'"></td></tr>'."\n";
print '<tr>';
2017-01-22 12:13:32 +01:00
print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>';
print '</table>';
dol_fiche_end();
2010-02-10 18:07:25 +01:00
/*
* Autres charges impayees
*/
$num = 1;
$i = 0;
print '<table class="noborder" width="100%">';
2010-02-10 18:07:25 +01:00
print '<tr class="liste_titre">';
//print '<td>'.$langs->trans("SocialContribution").'</td>';
2019-01-18 10:18:18 +01:00
print '<td class="left">'.$langs->trans("DateDue").'</td>';
print '<td align="right">'.$langs->trans("Amount").'</td>';
2010-02-10 18:07:25 +01:00
print '<td align="right">'.$langs->trans("AlreadyPaid").'</td>';
print '<td align="right">'.$langs->trans("RemainderToPay").'</td>';
2014-03-23 16:33:05 +01:00
print '<td align="center">'.$langs->trans("Amount").'</td>';
2010-02-10 18:07:25 +01:00
print "</tr>\n";
$total=0;
$totalrecu=0;
while ($i < $num)
{
$objp = $charge;
print '<tr class="oddeven">';
2010-02-10 18:07:25 +01:00
if ($objp->date_ech > 0)
{
print "<td align=\"left\">".dol_print_date($objp->date_ech, 'day')."</td>\n";
2010-02-10 18:07:25 +01:00
}
else
{
print "<td align=\"center\"><b>!!!</b></td>\n";
}
print '<td align="right">'.price($objp->amount)."</td>";
print '<td align="right">'.price($sumpaid)."</td>";
print '<td align="right">'.price($objp->amount - $sumpaid)."</td>";
2010-02-10 18:07:25 +01:00
2014-03-23 16:33:05 +01:00
print '<td align="center">';
2010-02-10 18:07:25 +01:00
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 '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
2010-02-10 18:07:25 +01:00
}
else
{
print '-';
}
print "</td>";
print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
}
if ($i > 1)
{
// Print total
2018-06-17 14:33:29 +02:00
print '<tr class="oddeven">';
print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>';
2010-02-10 18:07:25 +01:00
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
print "<td align=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>";
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
}
print "</table>";
// Bouton Save payment
print '<br><div class="center"><input type="checkbox" checked name="closepaidcontrib"> '.$langs->trans("ClosePaidContributionsAutomatically");
print '<br><input type="submit" class="button" name="save" value="'.$langs->trans('ToMakePayment').'">';
2014-11-25 20:13:43 +01:00
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
2010-02-10 18:07:25 +01:00
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
2014-11-25 20:13:43 +01:00
print '</div>';
2010-02-10 18:07:25 +01:00
print "</form>\n";
2009-03-03 00:09:03 +01:00
}
llxFooter();
$db->close();