dolibarr 24.0.0-beta
paiement_charge.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2016-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
39
40// Load translation files required by the page
41$langs->loadLangs(array("banks", "bills", "compta"));
42
43$action = GETPOST('action', 'aZ09');
44$confirm = GETPOST('confirm', 'alpha');
45$cancel = GETPOST('cancel', 'alpha');
46
47$chid = GETPOSTINT("id");
48$amounts = array();
49
50// Security check
51$socid = 0;
52if ($user->socid > 0) {
53 $socid = $user->socid;
54}
55
56$charge = new ChargeSociales($db);
57
58
59/*
60 * Actions
61 */
62
63if (($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $user->hasRight('tax', 'charges', 'creer')) {
64 $error = 0;
65
66 if ($cancel) {
67 $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
68 header("Location: ".$loc);
69 exit;
70 }
71
72 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
73
74 if (!(GETPOST("paiementtype") > 0)) {
75 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
76 $error++;
77 $action = 'create';
78 }
79 if ($datepaye == '') {
80 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
81 $error++;
82 $action = 'create';
83 }
84 if (isModEnabled("bank") && !(GETPOST("accountid") > 0)) {
85 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
86 $error++;
87 $action = 'create';
88 }
89
90 if (!$error) {
91 $paymentid = 0;
92
93 // Read possible payments
94 foreach ($_POST as $key => $value) {
95 if (substr($key, 0, 7) == 'amount_') {
96 $other_chid = substr($key, 7);
97 $amounts[$other_chid] = (float) price2num(GETPOST($key));
98 }
99 }
100
101 if (empty($amounts)) {
102 $error++;
103 setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
104 $action = 'create';
105 }
106
107 if (!$error) {
108 $db->begin();
109
110 // Create a line of payments
111 $paiement = new PaymentSocialContribution($db);
112 $paiement->chid = $chid;
113 $paiement->datepaye = $datepaye;
114 $paiement->amounts = $amounts; // Amount list
115 $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
116 $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
117 $paiement->note = GETPOST("note", 'restricthtml');
118 $paiement->note_private = GETPOST("note", 'restricthtml');
119
120 if (!$error) {
121 $paymentid = $paiement->create($user, (GETPOST('closepaidcontrib') == 'on' ? 1 : 0));
122 if ($paymentid < 0) {
123 $error++;
124 setEventMessages($paiement->error, $paiement->errors, 'errors');
125 $action = 'create';
126 }
127 }
128
129 if (!$error) {
130 $result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOSTINT('accountid'), '', '');
131 if ($result <= 0) {
132 $error++;
133 setEventMessages($paiement->error, $paiement->errors, 'errors');
134 $action = 'create';
135 }
136 }
137
138 if (!$error) {
139 $db->commit();
140 $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
141 header('Location: '.$loc);
142 exit;
143 } else {
144 $db->rollback();
145 }
146 }
147 }
148}
149
150
151/*
152 * View
153 */
154
155llxHeader();
156
157$form = new Form($db);
158
159
160// Form of charge payment creation
161if ($action == 'create') {
162 $charge->fetch($chid);
163 $charge->accountid = $charge->fk_account ? $charge->fk_account : $charge->accountid;
164 $charge->paiementtype = $charge->mode_reglement_id ? $charge->mode_reglement_id : $charge->paiementtype;
165
166 $total = $charge->amount;
167 if (!empty($conf->use_javascript_ajax)) {
168 print "\n".'<script type="text/javascript">';
169
170 //Add js for AutoFill
171 print ' $(document).ready(function () {';
172 print ' $(".AutoFillAmount").on(\'click touchstart\', function() {
173 console.log("Click on .AutoFillAmount");
174 var amount = $(this).data("value");
175 document.getElementById($(this).data(\'rowid\')).value = amount ;
176 });';
177 print ' });'."\n";
178
179 print ' </script>'."\n";
180 }
181
182 print load_fiche_titre($langs->trans("DoPayment"));
183
184 print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
185 print '<input type="hidden" name="token" value="'.newToken().'">';
186 print '<input type="hidden" name="id" value="'.$chid.'">';
187 print '<input type="hidden" name="chid" value="'.$chid.'">';
188 print '<input type="hidden" name="action" value="add_payment">';
189
190 print dol_get_fiche_head([], '');
191
192 print '<table class="border centpercent">';
193
194 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>';
195 print '<tr><td>'.$langs->trans("Label").'</td><td>'.$charge->label."</td></tr>\n";
196 print '<tr><td>'.$langs->trans("Type")."</td><td>".$charge->type_label."</td></tr>\n";
197 print '<tr><td>'.$langs->trans("Period")."</td><td>".dol_print_date($charge->period, 'day')."</td></tr>\n";
198 /*print '<tr><td>'.$langs->trans("DateDue")."</td><td>".dol_print_date($charge->date_ech,'day')."</td></tr>\n";
199 print '<tr><td>'.$langs->trans("Amount")."</td><td>".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
200
201 $sql = "SELECT sum(p.amount) as total";
202 $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
203 $sql .= " WHERE p.fk_charge = ".((int) $chid);
204 $sumpaid = 0;
205 $resql = $db->query($sql);
206 if ($resql) {
207 $obj = $db->fetch_object($resql);
208 $sumpaid = $obj->total;
209 $db->free($resql);
210 }
211 /*print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td>'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
212 print '<tr><td class="tdtop">'.$langs->trans("RemainderToPay").'</td><td>'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
213
214 print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
215 $datepaye = dol_mktime(12, 0, 0, GETPOSTINT("remonth"), GETPOSTINT("reday"), GETPOSTINT("reyear"));
216 $datepayment = getDolGlobalString('MAIN_AUTOFILL_DATE') ? '' : (GETPOSTISSET("remonth") ? $datepaye : -1);
217 print $form->selectDate($datepayment, '', 0, 0, 0, "add_payment", 1, 1, 0, '', '', $charge->date_ech, '', 1, $langs->trans("DateOfSocialContribution"));
218 print "</td>";
219 print '</tr>';
220
221 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
222 print img_picto('', 'bank', 'class="pictofixedwidth"');
223 print $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $charge->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusxx', 1);
224 print "</td>\n";
225 print '</tr>';
226
227 print '<tr>';
228 print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
229 print '<td>';
230 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
231 print $form->select_comptes(GETPOSTISSET("accountid") ? GETPOSTINT("accountid") : $charge->accountid, "accountid", 0, '', 2, '', 0, 'maxwidth500 widthcentpercentminusx', 1); // Show opened bank account list
232 print '</td></tr>';
233
234 // Number
235 print '<tr><td>'.$langs->trans('Numero');
236 if (empty($conf->dol_optimize_smallscreen)) {
237 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
238 }
239 print '</td>';
240 print '<td><input name="num_payment" class="width100" type="text" value="'.GETPOST('num_payment', 'alphanohtml').'"></td></tr>'."\n";
241
242 print '<tr>';
243 print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
244 print '<td class="tdtop"><textarea class="quatrevingtpercent" name="note" wrap="soft" rows="'.ROWS_3.'">'.GETPOST('note', 'alphanohtml').'</textarea></td>';
245 print '</tr>';
246
247 print '</table>';
248
249 print dol_get_fiche_end();
250
251 print '<br>';
252
253
254 // List of unpaid taxes
255
256 $num = 1;
257 $i = 0;
258
259 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
260 print '<table class="noborder centpercent">';
261 print '<tr class="liste_titre">';
262 //print '<td>'.$langs->trans("SocialContribution").'</td>';
263 print '<td class="left">'.$langs->trans("DateDue").'</td>';
264 print '<td class="right">'.$langs->trans("Amount").'</td>';
265 print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>';
266 print '<td class="right">'.$langs->trans("RemainderToPay").'</td>';
267 print '<td class="center">'.$langs->trans("Amount").'</td>';
268 print "</tr>\n";
269
270 $total = 0;
271 $total_ttc = 0;
272 $totalrecu = 0;
273
274 while ($i < $num) {
275 $objp = $charge;
276
277 print '<tr class="oddeven">';
278
279 if ($objp->date_ech > 0) {
280 print '<td class="left">'.dol_print_date($objp->date_ech, 'day').'</td>'."\n";
281 } else {
282 print "<td align=\"center\"><b>!!!</b></td>\n";
283 }
284
285 print '<td class="right nowraponall"><span class="amount">'.price($objp->amount)."</span></td>";
286
287 print '<td class="right nowraponall"><span class="amount">'.price($sumpaid)."</span></td>";
288
289 print '<td class="right nowraponall"><span class="amount">'.price($objp->amount - $sumpaid)."</span></td>";
290
291 print '<td class="center nowraponall">';
292 if ($sumpaid < $objp->amount) {
293 $namef = "amount_".$objp->id;
294 $nameRemain = "remain_".$objp->id;
295 if (!empty($conf->use_javascript_ajax)) {
296 print img_picto("Auto fill", 'rightarrow.png', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
297 }
298 $remaintopay = $objp->amount - $sumpaid;
299 print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
300 print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'" value="'.GETPOST('amount_'.$objp->id, 'alpha').'">';
301 } else {
302 print '-';
303 }
304 print "</td>";
305
306 print "</tr>\n";
307 $total += $objp->total;
308 $total_ttc += $objp->total_ttc;
309 $totalrecu += $objp->amount;
310 $i++;
311 }
312 if ($i > 1) {
313 // Print total
314 print '<tr class="oddeven">';
315 print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';
316 print '<td class="right"><b>'.price($total_ttc).'</b></td>';
317 print '<td class="right"><b>'.price($totalrecu).'</b></td>';
318 print '<td class="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
319 print '<td align="center">&nbsp;</td>';
320 print "</tr>\n";
321 }
322
323 print "</table>";
324 print '</div>';
325
326 // Save payment button
327 print '<br><div class="center"><input type="checkbox" checked name="closepaidcontrib" id="closepaidcontrib" class="marginrightonly">';
328 print '<label for="closepaidcontrib" class="opacitymedium">'.$langs->trans("ClosePaidContributionsAutomatically").'</label>';
329 print '<br><input type="submit" class="button" name="save" value="'.$langs->trans('ToMakePayment').'">';
330 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
331 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
332 print '</div>';
333
334 print "</form>\n";
335}
336
337llxFooter();
338$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class for managing the social charges.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of social contributions.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:489