dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2016-2018 Frédéric France <frederic.france@netlogic.fr>
5  * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 if (!empty($conf->projet->enabled)) {
35  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
37 }
38 if (!empty($conf->accounting->enabled)) {
39  include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40 }
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array('compta', 'bills', 'banks'));
44 
45 $id = GETPOST('id', 'int');
46 $action = GETPOST('action', 'aZ09');
47 $confirm = GETPOST('confirm');
48 $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
49 
50 $dateech = dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), GETPOST('echmonth'), GETPOST('echday'), GETPOST('echyear'));
51 $dateperiod = dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear'));
52 $label = GETPOST('label', 'alpha');
53 $actioncode = GETPOST('actioncode');
54 
55 // Security check
56 $socid = GETPOST('socid', 'int');
57 if ($user->socid) $socid = $user->socid;
58 $result = restrictedArea($user, 'tax', $id, 'chargesociales', 'charges');
59 
60 $object = new ChargeSociales($db);
61 
62 /* *************************************************************************** */
63 /* */
64 /* Actions */
65 /* */
66 /* *************************************************************************** */
67 
68 // Classify paid
69 if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes')
70 {
71  $object->fetch($id);
72  $result = $object->set_paid($user);
73 }
74 
75 if ($action == 'reopen' && $user->rights->tax->charges->creer) {
76  $result = $object->fetch($id);
77  if ($object->paye)
78  {
79  $result = $object->set_unpaid($user);
80  if ($result > 0)
81  {
82  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
83  exit();
84  } else {
85  setEventMessages($object->error, $object->errors, 'errors');
86  }
87  }
88 }
89 
90 // Link to a project
91 if ($action == 'classin' && $user->rights->tax->charges->creer)
92 {
93  $object->fetch($id);
94  $object->setProject(GETPOST('projectid'));
95 }
96 
97 if ($action == 'setlib' && $user->rights->tax->charges->creer)
98 {
99  $object->fetch($id);
100  $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY');
101  if ($result < 0)
102  setEventMessages($object->error, $object->errors, 'errors');
103 }
104 
105 // payment mode
106 if ($action == 'setmode' && $user->rights->tax->charges->creer) {
107  $object->fetch($id);
108  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
109  if ($result < 0)
110  setEventMessages($object->error, $object->errors, 'errors');
111 }
112 
113 // bank account
114 if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
115  $object->fetch($id);
116  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
117  if ($result < 0) {
118  setEventMessages($object->error, $object->errors, 'errors');
119  }
120 }
121 
122 // Delete social contribution
123 if ($action == 'confirm_delete' && $confirm == 'yes')
124 {
125  $object->fetch($id);
126  $result = $object->delete($user);
127  if ($result > 0) {
128  header("Location: list.php");
129  exit;
130  } else {
131  setEventMessages($object->error, $object->errors, 'errors');
132  }
133 }
134 
135 
136 // Add social contribution
137 if ($action == 'add' && $user->rights->tax->charges->creer)
138 {
139  $amount = price2num(GETPOST('amount'), 'MT');
140 
141  if (!$dateech)
142  {
143  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
144  $action = 'create';
145  } elseif (!$dateperiod)
146  {
147  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
148  $action = 'create';
149  } elseif (!$actioncode > 0)
150  {
151  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
152  $action = 'create';
153  } elseif (empty($amount))
154  {
155  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
156  $action = 'create';
157  } elseif (!is_numeric($amount)) {
158  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
159  $action = 'create';
160  } else {
161  $object->type = $actioncode;
162  $object->label = GETPOST('label', 'alpha');
163  $object->date_ech = $dateech;
164  $object->periode = $dateperiod;
165  $object->amount = $amount;
166  $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int');
167  $object->fk_account = (int) GETPOST('fk_account', 'int');
168  $object->fk_project = (int) GETPOST('fk_project', 'int');
169 
170  $id = $object->create($user);
171  if ($id <= 0) {
172  setEventMessages($object->error, $object->errors, 'errors');
173  $action = 'create';
174  }
175  }
176 }
177 
178 
179 if ($action == 'update' && !$_POST["cancel"] && $user->rights->tax->charges->creer)
180 {
181  $amount = price2num(GETPOST('amount'), 'MT');
182 
183  if (!$dateech)
184  {
185  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
186  $action = 'edit';
187  } elseif (!$dateperiod)
188  {
189  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
190  $action = 'edit';
191  } elseif (empty($amount))
192  {
193  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
194  $action = 'edit';
195  } elseif (!is_numeric($amount))
196  {
197  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
198  $action = 'create';
199  } else {
200  $result = $object->fetch($id);
201 
202  $object->date_ech = $dateech;
203  $object->periode = $dateperiod;
204  $object->amount = $amount;
205 
206  $result = $object->update($user);
207  if ($result <= 0) {
208  setEventMessages($object->error, $object->errors, 'errors');
209  }
210  }
211 }
212 
213 // Action clone object
214 if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
215 
216 if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer))
217 {
218  $db->begin();
219 
220  $originalId = $id;
221 
222  $object->fetch($id);
223 
224  if ($object->id > 0)
225  {
226  $object->paye = 0;
227  $object->id = $object->ref = null;
228 
229  if (GETPOST('clone_label', 'alphanohtml')) {
230  $object->label = GETPOST('clone_label', 'alphanohtml');
231  } else {
232  $object->label = $langs->trans("CopyOf").' '.$object->label;
233  }
234 
235  if (GETPOST('clone_for_next_month', 'int')) {
236  $object->periode = dol_time_plus_duree($object->periode, 1, 'm');
237  $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
238  } else {
239  $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
240  $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int'));
241  if ($newdateperiod) $object->periode = $newdateperiod;
242  if ($newdateech) $object->date_ech = $newdateech;
243  }
244 
245  if ($object->check())
246  {
247  $id = $object->create($user);
248  if ($id > 0)
249  {
250  $db->commit();
251  $db->close();
252 
253  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
254  exit;
255  } else {
256  $id = $originalId;
257  $db->rollback();
258 
259  setEventMessages($object->error, $object->errors, 'errors');
260  }
261  }
262  } else {
263  $db->rollback();
264  dol_print_error($db, $object->error);
265  }
266 }
267 
268 
269 
270 
271 
272 /*
273  * View
274  */
275 
276 $form = new Form($db);
277 $formsocialcontrib = new FormSocialContrib($db);
278 $bankaccountstatic = new Account($db);
279 if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
280 
281 $title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
282 $help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
283 llxHeader("", $title, $help_url);
284 
285 
286 // Mode creation
287 if ($action == 'create')
288 {
289  print load_fiche_titre($langs->trans("NewSocialContribution"));
290 
291  print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
292  print '<input type="hidden" name="token" value="'.newToken().'">';
293  print '<input type="hidden" name="action" value="add">';
294 
296 
297  print '<table class="border centpercent">';
298 
299  // Label
300  print "<tr>";
301  print '<td class="titlefieldcreate fieldrequired">';
302  print $langs->trans("Label");
303  print '</td>';
304  print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'" autofocus></td>';
305  print '</tr>';
306  print '<tr>';
307 
308  // Type
309  print '<td class="fieldrequired">';
310  print $langs->trans("Type");
311  print '</td>';
312  print '<td>';
313  $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha') ?GETPOST("actioncode", 'alpha') : '', 'actioncode', 1);
314  print '</td>';
315  print '</tr>';
316 
317  // Date
318  print '<tr>';
319  print '<td class="fieldrequired">';
320  print $langs->trans("Date");
321  print '</td>';
322  print '<td>';
323  print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1, 1);
324  print '</td>';
325  print "</tr>\n";
326 
327  // Date end period
328  print '<tr>';
329  print '<td class="fieldrequired">';
330  print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
331  print '</td>';
332  print '<td>';
333  print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1);
334  print '</td>';
335  print '</tr>';
336 
337  // Amount
338  print '<tr>';
339  print '<td class="fieldrequired">';
340  print $langs->trans("Amount");
341  print '</td>';
342  print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount', 'alpha')).'"></td>';
343  print '</tr>';
344 
345  // Project
346  if (!empty($conf->projet->enabled))
347  {
348  $formproject = new FormProjets($db);
349 
350  // Associated project
351  $langs->load("projects");
352 
353  print '<tr><td>'.$langs->trans("Project").'</td><td>';
354 
355  $numproject = $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1);
356 
357  print '</td></tr>';
358  }
359 
360  // Payment Mode
361  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
362  $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id');
363  print '</td></tr>';
364 
365  // Bank Account
366  if (!empty($conf->banque->enabled))
367  {
368  print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
369  $form->select_comptes($fk_account, 'fk_account', 0, '', 2);
370  print '</td></tr>';
371  }
372 
373  print '</table>';
374 
376 
377  print '<div class="center">';
378  print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
379  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
380  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
381  print '</div>';
382 
383  print '</form>';
384 }
385 
386 /* *************************************************************************** */
387 /* */
388 /* Card Mode */
389 /* */
390 /* *************************************************************************** */
391 if ($id > 0)
392 {
393  $object = new ChargeSociales($db);
394  $result = $object->fetch($id);
395 
396  if ($result > 0)
397  {
398  $head = tax_prepare_head($object);
399 
400  $totalpaye = $object->getSommePaiement();
401 
402  // Clone confirmation
403  if ($action === 'clone')
404  {
405  $formquestion = array(
406  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
407  );
408  if (!empty($conf->global->TAX_ADD_CLON_FOR_NEXT_MONTH_CHECKBOX))
409  {
410  $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
411  } else {
412  $formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
413  $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
414  }
415 
416  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
417  }
418 
419 
420  if ($action == 'paid')
421  {
422  $text = $langs->trans('ConfirmPaySocialContribution');
423  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
424  }
425 
426  // Confirmation of the removal of the Social Contribution
427  if ($action == 'delete')
428  {
429  $text = $langs->trans('ConfirmDeleteSocialContribution');
430  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
431  }
432 
433  if ($action == 'edit')
434  {
435  print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
436  print '<input type="hidden" name="token" value="'.newToken().'">';
437  }
438 
439  print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill');
440 
441  $morehtmlref = '<div class="refidno">';
442  // Ref customer
443  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
444  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
445  // Project
446  if (!empty($conf->projet->enabled))
447  {
448  $langs->load("projects");
449  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
450  if ($user->rights->tax->charges->creer)
451  {
452  if ($action != 'classify') {
453  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
454  }
455  if ($action == 'classify') {
456  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
457  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
458  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
459  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
460  $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
461  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
462  $morehtmlref .= '</form>';
463  } else {
464  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
465  }
466  } else {
467  if (!empty($object->fk_project)) {
468  $proj = new Project($db);
469  $proj->fetch($object->fk_project);
470  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
471  $morehtmlref .= $proj->ref;
472  $morehtmlref .= '</a>';
473  } else {
474  $morehtmlref .= '';
475  }
476  }
477  }
478  $morehtmlref .= '</div>';
479 
480  $morehtmlright = '';
481 
482  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
483 
484  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
485 
486  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
487 
488  print '<div class="fichecenter">';
489  print '<div class="fichehalfleft">';
490  print '<div class="underbanner clearboth"></div>';
491 
492  print '<table class="border centpercent">';
493 
494  // Type
495  print '<tr><td class="titlefield">';
496  print $langs->trans("Type")."</td><td>".$object->type_label."</td>";
497  print "</tr>";
498 
499  // Date
500  if ($action == 'edit')
501  {
502  print '<tr><td>'.$langs->trans("Date")."</td><td>";
503  print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
504  print "</td></tr>";
505  } else {
506  print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
507  }
508 
509  // Period end date
510  print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
511  print "<td>";
512  if ($action == 'edit')
513  {
514  print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1);
515  } else {
516  print dol_print_date($object->periode, "day");
517  }
518  print "</td></tr>";
519 
520  // Amount
521  if ($action == 'edit')
522  {
523  print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
524  print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
525  print "</td></tr>";
526  } else {
527  print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
528  }
529 
530  // Mode of payment
531  print '<tr><td>';
532  print '<table class="nobordernopadding" width="100%"><tr><td>';
533  print $langs->trans('PaymentMode');
534  print '</td>';
535  if ($action != 'editmode')
536  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
537  print '</tr></table>';
538  print '</td><td>';
539  if ($action == 'editmode') {
540  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id');
541  } else {
542  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
543  }
544  print '</td></tr>';
545 
546  // Bank Account
547  if (!empty($conf->banque->enabled))
548  {
549  print '<tr><td class="nowrap">';
550  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
551  print $langs->trans('BankAccount');
552  print '<td>';
553  if ($action != 'editbankaccount' && $user->rights->tax->charges->creer)
554  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
555  print '</tr></table>';
556  print '</td><td>';
557  if ($action == 'editbankaccount') {
558  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
559  } else {
560  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
561  }
562  print '</td>';
563  print '</tr>';
564  }
565 
566  print '</table>';
567 
568  print '</div>';
569  print '<div class="fichehalfright">';
570  print '<div class="ficheaddleft">';
571 
572  $nbcols = 3;
573  if (!empty($conf->banque->enabled)) {
574  $nbcols++;
575  }
576 
577  /*
578  * Payments
579  */
580  $sql = "SELECT p.rowid, p.num_paiement as num_payment, datep as dp, p.amount,";
581  $sql .= " c.code as type_code,c.libelle as paiement_type,";
582  $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
583  $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
584  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
585  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
586  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
587  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
588  $sql .= " WHERE p.fk_charge = ".$id;
589  $sql .= " AND p.fk_charge = cs.rowid";
590  $sql .= " AND cs.entity IN (".getEntity('tax').")";
591  $sql .= " ORDER BY dp DESC";
592 
593  //print $sql;
594  $resql = $db->query($sql);
595  if ($resql)
596  {
597  $totalpaye = 0;
598 
599  $num = $db->num_rows($resql);
600  $i = 0; $total = 0;
601 
602  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
603  print '<table class="noborder paymenttable">';
604  print '<tr class="liste_titre">';
605  print '<td>'.$langs->trans("RefPayment").'</td>';
606  print '<td>'.$langs->trans("Date").'</td>';
607  print '<td>'.$langs->trans("Type").'</td>';
608  if (!empty($conf->banque->enabled)) {
609  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
610  }
611  print '<td class="right">'.$langs->trans("Amount").'</td>';
612  print '</tr>';
613 
614  $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
615 
616  if ($num > 0)
617  {
618  while ($i < $num)
619  {
620  $objp = $db->fetch_object($resql);
621 
622  $paymentsocialcontributiontmp->id = $objp->rowid;
623  $paymentsocialcontributiontmp->ref = $objp->rowid;
624  $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
625 
626  print '<tr class="oddeven"><td>';
627  print $paymentsocialcontributiontmp->getNomUrl(1);
628  print '</td>';
629 
630  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
631  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
632  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
633  if (!empty($conf->banque->enabled))
634  {
635  $bankaccountstatic->id = $objp->baid;
636  $bankaccountstatic->ref = $objp->baref;
637  $bankaccountstatic->label = $objp->baref;
638  $bankaccountstatic->number = $objp->banumber;
639  $bankaccountstatic->currency_code = $objp->bacurrency_code;
640 
641  if (!empty($conf->accounting->enabled)) {
642  $bankaccountstatic->account_number = $objp->account_number;
643 
644  $accountingjournal = new AccountingJournal($db);
645  $accountingjournal->fetch($objp->fk_accountancy_journal);
646  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
647  }
648 
649  print '<td class="right">';
650  if ($bankaccountstatic->id)
651  print $bankaccountstatic->getNomUrl(1, 'transactions');
652  print '</td>';
653  }
654  print '<td class="right">'.price($objp->amount)."</td>\n";
655  print "</tr>";
656  $totalpaye += $objp->amount;
657  $i++;
658  }
659  } else {
660  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
661  print '<td></td><td></td><td></td><td></td>';
662  print '</tr>';
663  }
664 
665  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaye)."</td></tr>\n";
666  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
667 
668  $resteapayer = $object->amount - $totalpaye;
669  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
670 
671  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
672  print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
673 
674  print "</table>";
675  print '</div>';
676 
677  $db->free($resql);
678  } else {
679  dol_print_error($db);
680  }
681 
682  print '</div>';
683  print '</div>';
684  print '</div>';
685 
686  print '<div class="clearboth"></div>';
687 
688  print dol_get_fiche_end();
689 
690  if ($action == 'edit')
691  {
692  print '<div align="center">';
693  print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
694  print ' &nbsp; ';
695  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
696  print '</div>';
697  }
698 
699  if ($action == 'edit') print "</form>\n";
700 
701 
702 
703  /*
704  * Actions buttons
705  */
706  if ($action != 'edit')
707  {
708  print "<div class=\"tabsAction\">\n";
709 
710  // Reopen
711  if ($object->paye && $user->rights->tax->charges->creer)
712  {
713  print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/sociales/card.php", 1).'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a></div>';
714  }
715 
716  // Edit
717  if ($object->paye == 0 && $user->rights->tax->charges->creer)
718  {
719  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>';
720  }
721 
722  // Emit payment
723  if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer)
724  {
725  print "<div class=\"inline-block divButAction\"><a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$object->id&amp;action=create\">".$langs->trans("DoPayment")."</a></div>";
726  }
727 
728  // Classify 'paid'
729  if ($object->paye == 0 && round($resteapayer) <= 0 && $user->rights->tax->charges->creer)
730  {
731  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&amp;action=paid&amp;token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
732  }
733 
734  // Clone
735  if ($user->rights->tax->charges->creer)
736  {
737  print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/sociales/card.php", 1).'?id='.$object->id.'&amp;action=clone">'.$langs->trans("ToClone")."</a></div>";
738  }
739 
740  // Delete
741  if ($user->rights->tax->charges->supprimer)
742  {
743  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
744  }
745 
746  print "</div>";
747  }
748  } else {
749  /* Social contribution not found */
750  dol_print_error('', $object->error);
751  }
752 }
753 
754 // End of page
755 llxFooter();
756 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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...
Class to manage payments of social contributions.
Class to manage bank accounts.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage building of HTML components.
Class to manage generation of HTML components for social contributions management.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
tax_prepare_head(ChargeSociales $object)
Prepare array with list of tabs.
Definition: tax.lib.php:37
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage accounting accounts.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:114
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...