dolibarr  16.0.5
paiement_vat.php
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2016-2021 Frédéric France <frederic.france@netlogic.fr>
4  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("banks", "bills"));
33 
34 $chid = GETPOST("id", 'int');
35 $action = GETPOST('action', 'alpha');
36 $cancel = GETPOST('cancel');
37 
38 $amounts = array();
39 
40 // Security check
41 $socid = 0;
42 if ($user->socid > 0) {
43  $socid = $user->socid;
44 }
45 
46 
47 /*
48  * Actions
49  */
50 
51 if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
52  $error = 0;
53 
54  if ($cancel) {
55  $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
56  header("Location: ".$loc);
57  exit;
58  }
59 
60  $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
61 
62  if (!(GETPOST("paiementtype", 'int') > 0)) {
63  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
64  $error++;
65  $action = 'create';
66  }
67  if ($datepaye == '') {
68  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
69  $error++;
70  $action = 'create';
71  }
72  if (isModEnabled('banque') && !(GETPOST("accountid", 'int') > 0)) {
73  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
74  $error++;
75  $action = 'create';
76  }
77 
78  // Read possible payments
79  foreach ($_POST as $key => $value) {
80  if (substr($key, 0, 7) == 'amount_') {
81  $other_chid = substr($key, 7);
82  $amounts[$other_chid] = price2num(GETPOST($key));
83  }
84  }
85 
86  if (empty($amounts[key($amounts)])) {
87  $error++;
88  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
89  $action = 'create';
90  }
91 
92  if (!$error) {
93  $paymentid = 0;
94 
95  if (!$error) {
96  $db->begin();
97 
98  // Create a line of payments
99  $paiement = new PaymentVAT($db);
100  $paiement->chid = $chid;
101  $paiement->datepaye = $datepaye;
102  $paiement->amounts = $amounts; // Tableau de montant
103  $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
104  $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
105  $paiement->note = (string) GETPOST("note", 'restricthtml');
106  $paiement->note_private = (string) GETPOST("note", 'restricthtml');
107 
108  if (!$error) {
109  $paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0));
110  if ($paymentid < 0) {
111  $error++;
112  setEventMessages($paiement->error, null, 'errors');
113  $action = 'create';
114  }
115  }
116 
117  if (!$error) {
118  $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
119  if (!($result > 0)) {
120  $error++;
121  setEventMessages($paiement->error, null, 'errors');
122  $action = 'create';
123  }
124  }
125 
126  if (!$error) {
127  $db->commit();
128  $loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
129  header('Location: '.$loc);
130  exit;
131  } else {
132  $db->rollback();
133  }
134  }
135  }
136 }
137 
138 
139 /*
140  * View
141  */
142 
143 llxHeader();
144 
145 $form = new Form($db);
146 
147 
148 // Formulaire de creation d'un paiement de charge
149 if ($action == 'create') {
150  $tva = new Tva($db);
151  $tva->fetch($chid);
152  $tva->accountid = $tva->fk_account ? $tva->fk_account : $tva->accountid;
153  $tva->paiementtype = $tva->type_payment;
154 
155  $total = $tva->amount;
156  if (!empty($conf->use_javascript_ajax)) {
157  print "\n".'<script type="text/javascript">';
158 
159  //Add js for AutoFill
160  print ' $(document).ready(function () {';
161  print ' $(".AutoFillAmount").on(\'click touchstart\', function(){
162  var amount = $(this).data("value");
163  document.getElementById($(this).data(\'rowid\')).value = amount ;
164  });';
165  print ' });'."\n";
166 
167  print ' </script>'."\n";
168  }
169 
170  print load_fiche_titre($langs->trans("DoPayment"));
171  print "<br>\n";
172 
173  print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
174  print '<input type="hidden" name="token" value="'.newToken().'">';
175  print '<input type="hidden" name="id" value="'.$chid.'">';
176  print '<input type="hidden" name="chid" value="'.$chid.'">';
177  print '<input type="hidden" name="action" value="add_payment">';
178 
179  print dol_get_fiche_head('', '');
180 
181  print '<table class="border centpercent">';
182 
183  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td><a href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid.'">'.$chid.'</a></td></tr>';
184  //print '<tr><td>'.$langs->trans("Type")."</td><td>".$tva->type_label."</td></tr>\n";
185  print '<tr><td>'.$langs->trans("Period")."</td><td>".dol_print_date($tva->datev, 'day')."</td></tr>\n";
186  print '<tr><td>'.$langs->trans("Label").'</td><td>'.$tva->label."</td></tr>\n";
187  /*print '<tr><td>'.$langs->trans("DateDue")."</td><td>".dol_print_date($tva->date_ech,'day')."</td></tr>\n";
188  print '<tr><td>'.$langs->trans("Amount")."</td><td>".price($tva->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
189 
190  $sql = "SELECT sum(p.amount) as total";
191  $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
192  $sql .= " WHERE p.fk_tva = ".((int) $chid);
193  $resql = $db->query($sql);
194  if ($resql) {
195  $obj = $db->fetch_object($resql);
196  $sumpaid = $obj->total;
197  $db->free($resql);
198  }
199  /*print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td>'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
200  print '<tr><td class="tdtop">'.$langs->trans("RemainderToPay").'</td><td>'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';*/
201 
202  print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
203  $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
204  $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (GETPOST("remonth", 'int') ? $datepaye : -1) : 0;
205  print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1);
206  print "</td>";
207  print '</tr>';
208 
209  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
210  $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype", "int") : $tva->paiementtype, "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx');
211  print "</td>\n";
212  print '</tr>';
213 
214  print '<tr>';
215  print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
216  print '<td>';
217  print img_picto('', 'bank_account', 'pictofixedwidth');
218  $form->select_comptes(GETPOST("accountid", "int") ? GETPOST("accountid", "int") : $tva->accountid, "accountid", 0, '', 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // Show opend bank account list
219  print '</td></tr>';
220 
221  // Number
222  print '<tr><td>'.$langs->trans('Numero');
223  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
224  print '</td>';
225  print '<td><input name="num_payment" type="text" value="'.GETPOST('num_payment', 'alphanohtml').'"></td></tr>'."\n";
226 
227  print '<tr>';
228  print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
229  print '<td class="tdtop"><textarea name="note" class="quatrevingtpercent" wrap="soft" rows="'.ROWS_3.'"></textarea></td>';
230  print '</tr>';
231 
232  print '</table>';
233 
234  print dol_get_fiche_end();
235 
236  /*
237  * Autres charges impayees
238  */
239  $num = 1;
240  $i = 0;
241 
242  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
243  print '<table class="noborder centpercent">';
244  print '<tr class="liste_titre">';
245  //print '<td>'.$langs->trans("SocialContribution").'</td>';
246  print '<td class="left">'.$langs->trans("DateDue").'</td>';
247  print '<td class="right">'.$langs->trans("Amount").'</td>';
248  print '<td class="right">'.$langs->trans("AlreadyPaid").'</td>';
249  print '<td class="right">'.$langs->trans("RemainderToPay").'</td>';
250  print '<td class="center">'.$langs->trans("Amount").'</td>';
251  print "</tr>\n";
252 
253  $total = 0;
254  $totalrecu = 0;
255 
256  while ($i < $num) {
257  $objp = $tva;
258 
259  print '<tr class="oddeven">';
260 
261  if ($objp->datev > 0) {
262  print '<td class="left">'.dol_print_date($objp->datev, 'day').'</td>'."\n";
263  } else {
264  print '<td class="center"><b>!!!</b></td>'."\n";
265  }
266 
267  print '<td class="right nowraponall"><span class="amount">'.price($objp->amount)."</span></td>";
268 
269  print '<td class="right nowraponall"><span class="amount">'.price($sumpaid)."</span></td>";
270 
271  print '<td class="right nowraponall"><span class="amount">'.price($objp->amount - $sumpaid)."</span></td>";
272 
273  print '<td class="center">';
274 
275  if ($sumpaid <> $objp->amount) {
276  $namef = "amount_".$objp->id;
277  $nameRemain = "remain_".$objp->id;
278  /* Disabled, we autofil the amount with remain to pay by default
279  if (!empty($conf->use_javascript_ajax)) {
280  print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
281  } */
282  $remaintopay = $objp->amount - $sumpaid;
283  print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
284  print '<input type="text" class="right width75" name="'.$namef.'" id="'.$namef.'" value="'.$remaintopay.'">';
285  } else {
286  print '-';
287  }
288  print "</td>";
289 
290  print "</tr>\n";
291  $total += $objp->total;
292  $total_ttc += $objp->total_ttc;
293  $totalrecu += $objp->amount;
294  $i++;
295  }
296  if ($i > 1) {
297  // Print total
298  print '<tr class="oddeven">';
299  print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';
300  print '<td class="right"><b>'.price($total_ttc).'</b></td>';
301  print '<td class="right"><b>'.price($totalrecu).'</b></td>';
302  print '<td class="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
303  print '<td align="center">&nbsp;</td>';
304  print "</tr>\n";
305  }
306 
307  print "</table>";
308  print '</div>';
309 
310  // Bouton Save payment
311  print '<br><div class="center"><input type="checkbox" checked name="closepaidvat"> '.$langs->trans("ClosePaidVATAutomatically");
312  print '<br><input type="submit" class="button" name="save" value="'.$langs->trans('ToMakePayment').'">';
313  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
314  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
315  print '</div>';
316 
317  print "</form>\n";
318 }
319 
320 llxFooter();
321 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
PaymentVAT
Class to manage payments of social contributions.
Definition: paymentvat.class.php:33
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Tva
Put here description of your class.
Definition: tva.class.php:35