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