dolibarr  19.0.0-dev
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-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
39 if (isModEnabled('project')) {
40  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
41  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
42 }
43 if (isModEnabled('accounting')) {
44  include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
45 }
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array('compta', 'bills', 'banks', 'hrm'));
49 
50 $id = GETPOST('id', 'int');
51 $ref = GETPOST('ref', 'alpha');
52 $action = GETPOST('action', 'aZ09');
53 $confirm = GETPOST('confirm', 'alpha');
54 $cancel = GETPOST('cancel', 'aZ09');
55 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
56 $backtopage = GETPOST('backtopage', 'alpha');
57 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
58 $lineid = GETPOST('lineid', 'int');
59 
60 $fk_project = (GETPOST('fk_project') ? GETPOST('fk_project', 'int') : 0);
61 
62 $dateech = dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), GETPOST('echmonth'), GETPOST('echday'), GETPOST('echyear'));
63 $dateperiod = dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear'));
64 $label = GETPOST('label', 'alpha');
65 $actioncode = GETPOST('actioncode');
66 $fk_user = GETPOST('userid', 'int') > 0 ? GETPOST('userid', 'int') : 0;
67 
68 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
69 $hookmanager->initHooks(array('taxcard', 'globalcard'));
70 
71 // Initialize technical objects
72 $object = new ChargeSociales($db);
73 $extrafields = new ExtraFields($db);
74 $diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
75 $hookmanager->initHooks(array('taxsocialcontributioncard', 'globalcard'));
76 
77 if (empty($action) && empty($id) && empty($ref)) {
78  $action = 'view';
79 }
80 
81 // Load object
82 if ($id > 0 || $ref) {
83  $object->fetch($id, $ref);
84 }
85 
86 $permissiontoread = $user->rights->tax->charges->lire;
87 $permissiontoadd = $user->rights->tax->charges->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
88 $permissiontodelete = $user->rights->tax->charges->supprimer || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
89 $permissionnote = $user->rights->tax->charges->creer; // Used by the include of actions_setnotes.inc.php
90 $permissiondellink = $user->rights->tax->charges->creer; // Used by the include of actions_dellink.inc.php
91 $upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1];
92 
93 // Security check
94 $socid = GETPOST('socid', 'int');
95 if ($user->socid) {
96  $socid = $user->socid;
97 }
98 $result = restrictedArea($user, 'tax', $object->id, 'chargesociales', 'charges');
99 
100 
101 
102 /*
103  * Actions
104  */
105 
106 $parameters = array('socid' => $socid);
107 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
108 if ($reshook < 0) {
109  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 }
111 
112 if (empty($reshook)) {
113  // Classify paid
114  if ($action == 'confirm_paid' && $permissiontoadd && $confirm == 'yes') {
115  $result = $object->setPaid($user);
116  }
117 
118  if ($action == 'reopen' && $user->rights->tax->charges->creer) {
119  if ($object->paye) {
120  $result = $object->setUnpaid($user);
121  if ($result > 0) {
122  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
123  exit();
124  } else {
125  setEventMessages($object->error, $object->errors, 'errors');
126  }
127  }
128  }
129 
130  // Link to a project
131  if ($action == 'classin' && $permissiontoadd) {
132  $object->setProject(GETPOST('fk_project'));
133  }
134 
135  if ($action == 'setfk_user' && $permissiontoadd) {
136  $object->fk_user = $fk_user;
137  $object->update($user);
138  }
139 
140  if ($action == 'setlib' && $permissiontoadd) {
141  $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY');
142  if ($result < 0) {
143  setEventMessages($object->error, $object->errors, 'errors');
144  }
145  }
146 
147  // payment mode
148  if ($action == 'setmode' && $permissiontoadd) {
149  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
150  if ($result < 0) {
151  setEventMessages($object->error, $object->errors, 'errors');
152  }
153  }
154 
155  // Bank account
156  if ($action == 'setbankaccount' && $permissiontoadd) {
157  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
158  if ($result < 0) {
159  setEventMessages($object->error, $object->errors, 'errors');
160  }
161  }
162 
163  // Delete social contribution
164  if ($action == 'confirm_delete' && $permissiontodelete && $confirm == 'yes') {
165  $totalpaid = $object->getSommePaiement();
166  if (empty($totalpaid)) {
167  $result = $object->delete($user);
168  if ($result > 0) {
169  header("Location: list.php");
170  exit;
171  } else {
172  setEventMessages($object->error, $object->errors, 'errors');
173  }
174  } else {
175  setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
176  }
177  }
178 
179 
180  // Add social contribution
181  if ($action == 'add' && $permissiontoadd) {
182  $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
183 
184  if (!$dateech) {
185  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
186  $action = 'create';
187  } elseif (!$dateperiod) {
188  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
189  $action = 'create';
190  } elseif (!($actioncode > 0)) {
191  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
192  $action = 'create';
193  } elseif (empty($amount)) {
194  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
195  $action = 'create';
196  } elseif (!is_numeric($amount)) {
197  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
198  $action = 'create';
199  } else {
200  $object->type = $actioncode;
201  $object->label = GETPOST('label', 'alpha');
202  $object->date_ech = $dateech;
203  $object->periode = $dateperiod;
204  $object->amount = $amount;
205  $object->fk_user = $fk_user;
206  $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int');
207  $object->fk_account = (int) GETPOST('fk_account', 'int');
208  $object->fk_project = (int) GETPOST('fk_project', 'int');
209 
210  $id = $object->create($user);
211  if ($id <= 0) {
212  setEventMessages($object->error, $object->errors, 'errors');
213  $action = 'create';
214  }
215  }
216  }
217 
218 
219  if ($action == 'update' && !$cancel && $permissiontoadd) {
220  $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
221 
222  if (!$dateech) {
223  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
224  $action = 'edit';
225  } elseif (!$dateperiod) {
226  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
227  $action = 'edit';
228  } elseif (empty($amount)) {
229  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
230  $action = 'edit';
231  } elseif (!is_numeric($amount)) {
232  setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
233  $action = 'create';
234  } else {
235  $result = $object->fetch($id);
236 
237  $object->date_ech = $dateech;
238  $object->periode = $dateperiod;
239  $object->amount = $amount;
240  $object->fk_user = $fk_user;
241 
242  $result = $object->update($user);
243  if ($result <= 0) {
244  setEventMessages($object->error, $object->errors, 'errors');
245  }
246  }
247  }
248 
249  // Action clone object
250  if ($action == 'confirm_clone' && $confirm != 'yes') {
251  $action = '';
252  }
253 
254  if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
255  $db->begin();
256 
257  $originalId = $object->id;
258 
259  if ($object->id > 0) {
260  $object->id = $object->ref = null;
261  $object->paye = 0;
262  if (GETPOST('amount', 'alphanohtml')) {
263  $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
264  }
265 
266  if (GETPOST('clone_label', 'alphanohtml')) {
267  $object->label = GETPOST('clone_label', 'alphanohtml');
268  } else {
269  $object->label = $langs->trans("CopyOf").' '.$object->label;
270  }
271 
272  if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
273  $object->periode = dol_time_plus_duree($object->periode, 1, 'm');
274  $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
275  } else {
276  // Note date_ech is often a little bit higher than dateperiod
277  $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
278  $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int'));
279  if ($newdateperiod) {
280  $object->periode = $newdateperiod;
281  if (empty($newdateech)) {
282  $object->date_ech = $object->periode;
283  }
284  }
285  if ($newdateech) {
286  $object->date_ech = $newdateech;
287  if (empty($newdateperiod)) {
288  // TODO We can here get dol_get_last_day of previous month:
289  // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
290  $object->periode = $object->date_ech;
291  }
292  }
293  }
294 
295  $resultcheck = $object->check();
296  if ($resultcheck) {
297  $id = $object->create($user);
298  if ($id > 0) {
299  $db->commit();
300  $db->close();
301 
302  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
303  exit;
304  } else {
305  $id = $originalId;
306  $db->rollback();
307 
308  setEventMessages($object->error, $object->errors, 'errors');
309  }
310  }
311  } else {
312  $db->rollback();
313  dol_print_error($db, $object->error);
314  }
315  }
316 
317  // Actions to build doc
318  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
319 }
320 
321 
322 /*
323  * View
324  */
325 
326 $form = new Form($db);
327 $formfile = new FormFile($db);
328 $formsocialcontrib = new FormSocialContrib($db);
329 $bankaccountstatic = new Account($db);
330 if (isModEnabled('project')) {
331  $formproject = new FormProjets($db);
332 }
333 
334 $now = dol_now();
335 
336 $title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
337 $help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
338 llxHeader("", $title, $help_url);
339 
340 
341 // Form to create a social contribution
342 if ($action == 'create') {
343  print load_fiche_titre($langs->trans("NewSocialContribution"));
344 
345  print '<form name="charge" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
346  print '<input type="hidden" name="token" value="'.newToken().'">';
347  print '<input type="hidden" name="action" value="add">';
348 
349  print dol_get_fiche_head();
350 
351  print '<table class="border centpercent tableforfieldcreate">';
352 
353  // Label
354  print "<tr>";
355  print '<td class="titlefieldcreate fieldrequired">';
356  print $langs->trans("Label");
357  print '</td>';
358  print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'" autofocus></td>';
359  print '</tr>';
360  print '<tr>';
361 
362  // Type
363  print '<td class="fieldrequired">';
364  print $langs->trans("Type");
365  print '</td>';
366  print '<td>';
367  $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha') ?GETPOST("actioncode", 'alpha') : '', 'actioncode', 1);
368  print '</td>';
369  print '</tr>';
370 
371  // Date
372  print '<tr>';
373  print '<td class="fieldrequired">';
374  print $langs->trans("Date");
375  print '</td>';
376  print '<td>';
377  print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1, 1);
378  print '</td>';
379  print "</tr>\n";
380 
381  // Date end period
382  print '<tr>';
383  print '<td class="fieldrequired">';
384  print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
385  print '</td>';
386  print '<td>';
387  print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1);
388  print '</td>';
389  print '</tr>';
390 
391  // Amount
392  print '<tr>';
393  print '<td class="fieldrequired">';
394  print $langs->trans("Amount");
395  print '</td>';
396  print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount', 'alpha')).'"></td>';
397  print '</tr>';
398 
399  // Employee
400  print '<tr><td>';
401  print $langs->trans('Employee');
402  print '</td>';
403  print '<td>'.img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($fk_user, 'userid', 1).'</td></tr>';
404 
405  // Project
406  if (isModEnabled('project')) {
407  $formproject = new FormProjets($db);
408 
409  // Associated project
410  $langs->load("projects");
411 
412  print '<tr><td>'.$langs->trans("Project").'</td><td>';
413 
414  print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
415 
416  print '</td></tr>';
417  }
418 
419  // Payment Mode
420  print '<tr><td>'.$langs->trans('DefaultPaymentMode').'</td><td colspan="2">';
421  $form->select_types_paiements(GETPOST('mode_reglement_id', 'int'), 'mode_reglement_id');
422  print '</td></tr>';
423 
424  // Bank Account
425  if (isModEnabled("banque")) {
426  print '<tr><td>'.$langs->trans('DefaultBankAccount').'</td><td colspan="2">';
427  print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes(GETPOST('fk_account', 'int'), 'fk_account', 0, '', 2, '', 0, '', 1);
428  print '</td></tr>';
429  }
430 
431  print '</table>';
432 
433  print dol_get_fiche_end();
434 
435  print '<div class="center">';
436  print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
437  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
438  print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="history.go(-1)">';
439  print '</div>';
440 
441  print '</form>';
442 }
443 
444 // View mode
445 if ($id > 0) {
446  $formconfirm = '';
447 
448  if ($result > 0) {
449  $head = tax_prepare_head($object);
450 
451  $totalpaid = $object->getSommePaiement();
452 
453  // Clone confirmation
454  if ($action === 'clone') {
455  $formquestion = array(
456  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass'=>'fieldrequired'),
457  );
458  if (!empty($conf->global->TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX)) {
459  $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
460  } else {
461  $formquestion[] = array('type' => 'date', 'datenow'=>1, 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
462  $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
463  $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
464  }
465 
466  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280);
467  }
468 
469 
470  if ($action == 'paid') {
471  $text = $langs->trans('ConfirmPaySocialContribution');
472  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
473  }
474 
475  // Confirmation of the removal of the Social Contribution
476  if ($action == 'delete') {
477  $text = $langs->trans('ConfirmDeleteSocialContribution');
478  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
479  }
480 
481  if ($action == 'edit') {
482  print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
483  print '<input type="hidden" name="token" value="'.newToken().'">';
484  print '<input type="hidden" name="action" value="update">';
485  }
486  // Call Hook formConfirm
487  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
488  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
489  if (empty($reshook)) {
490  $formconfirm .= $hookmanager->resPrint;
491  } elseif ($reshook > 0) {
492  $formconfirm = $hookmanager->resPrint;
493  }
494 
495  /*
496  * View card
497  */
498  print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill', 0, '', '', 0, '', 1);
499 
500  // Print form confirm
501  print $formconfirm;
502 
503 
504  // Social contribution card
505  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
506 
507  $morehtmlref = '<div class="refidno">';
508  // Ref customer
509  $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
510  $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
511 
512  // Employee
513  if ($action != 'editfk_user') {
514  if ($object->getSommePaiement() > 0 && $object->fk_user > 0) {
515  $userstatic = new User($db);
516  $result = $userstatic->fetch($object->fk_user);
517  if ($result > 0) {
518  $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
519  }
520  } else {
521  $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
522  if ($object->fk_user > 0) {
523  $userstatic = new User($db);
524  $result = $userstatic->fetch($object->fk_user);
525  if ($result > 0) {
526  $morehtmlref .= $userstatic->getNomUrl(1);
527  } else {
528  dol_print_error($db);
529  exit();
530  }
531  }
532  }
533  } else {
534  $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
535  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
536  $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
537  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
538  $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
539  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
540  $morehtmlref .= '</form>';
541  }
542 
543  // Project
544  if (isModEnabled('project')) {
545  $langs->load("projects");
546  $morehtmlref .= '<br>';
547  if ($permissiontoadd) {
548  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
549  if ($action != 'classify') {
550  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
551  }
552  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'fk_project' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
553  } else {
554  if (!empty($object->fk_project)) {
555  $proj = new Project($db);
556  $proj->fetch($object->fk_project);
557  $morehtmlref .= $proj->getNomUrl(1);
558  if ($proj->title) {
559  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
560  }
561  }
562  }
563  }
564  $morehtmlref .= '</div>';
565 
566  $morehtmlright = '';
567 
568  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
569 
570  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
571 
572  print '<div class="fichecenter">';
573  print '<div class="fichehalfleft">';
574  print '<div class="underbanner clearboth"></div>';
575 
576  print '<table class="border centpercent tableforfield">';
577 
578  // Type
579  print '<tr><td class="titlefield">';
580  print $langs->trans("Type")."</td><td>".$object->type_label."</td>";
581  print "</tr>";
582 
583  // Date
584  if ($action == 'edit') {
585  print '<tr><td>'.$langs->trans("Date")."</td><td>";
586  print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1, 1);
587  print "</td></tr>";
588  } else {
589  print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
590  }
591 
592  // Period end date
593  print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
594  print "<td>";
595  if ($action == 'edit') {
596  print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1);
597  } else {
598  print dol_print_date($object->periode, "day");
599  }
600  print "</td></tr>";
601 
602  // Amount
603  if ($action == 'edit') {
604  print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
605  print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
606  print "</td></tr>";
607  } else {
608  print '<tr><td>'.$langs->trans("AmountTTC").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
609  }
610 
611  // Mode of payment
612  print '<tr><td>';
613  print '<table class="nobordernopadding" width="100%"><tr><td>';
614  print $langs->trans('DefaultPaymentMode');
615  print '</td>';
616  if ($action != 'editmode') {
617  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
618  }
619  print '</tr></table>';
620  print '</td><td>';
621  if ($action == 'editmode') {
622  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', '', 1, 1);
623  } else {
624  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
625  }
626  print '</td></tr>';
627 
628  // Bank account
629  if (isModEnabled("banque")) {
630  print '<tr><td class="nowrap">';
631  print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
632  print $langs->trans('DefaultBankAccount');
633  print '<td>';
634  if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) {
635  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
636  }
637  print '</tr></table>';
638  print '</td><td>';
639  if ($action == 'editbankaccount') {
640  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
641  } else {
642  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
643  }
644  print '</td>';
645  print '</tr>';
646  }
647 
648  // Other attributes
649  $parameters = array();
650  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
651  print $hookmanager->resPrint;
652 
653  print '</table>';
654 
655  print '</div>';
656  print '<div class="fichehalfright">';
657 
658  print '<div class="underbanner clearboth"></div>';
659 
660  $nbcols = 3;
661  if (isModEnabled("banque")) {
662  $nbcols++;
663  }
664 
665  /*
666  * Payments
667  */
668  $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
669  $sql .= " c.code as type_code,c.libelle as paiement_type,";
670  $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';
671  $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
672  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
673  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
674  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
675  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
676  $sql .= " WHERE p.fk_charge = ".((int) $id);
677  $sql .= " AND p.fk_charge = cs.rowid";
678  $sql .= " AND cs.entity IN (".getEntity('sc').")";
679  $sql .= " ORDER BY dp DESC";
680 
681  //print $sql;
682  $resql = $db->query($sql);
683  if ($resql) {
684  $totalpaid = 0;
685 
686  $num = $db->num_rows($resql);
687  $i = 0;
688  $total = 0;
689 
690  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
691  print '<table class="noborder paymenttable">';
692  print '<tr class="liste_titre">';
693  print '<td>'.$langs->trans("RefPayment").'</td>';
694  print '<td>'.$langs->trans("Date").'</td>';
695  print '<td>'.$langs->trans("Type").'</td>';
696  if (isModEnabled("banque")) {
697  print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
698  }
699  print '<td class="right">'.$langs->trans("Amount").'</td>';
700  print '</tr>';
701 
702  $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
703 
704  if ($num > 0) {
705  while ($i < $num) {
706  $objp = $db->fetch_object($resql);
707 
708  $paymentsocialcontributiontmp->id = $objp->rowid;
709  $paymentsocialcontributiontmp->ref = $objp->rowid;
710  $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
711 
712  print '<tr class="oddeven"><td>';
713  print $paymentsocialcontributiontmp->getNomUrl(1);
714  print '</td>';
715 
716  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
717  $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
718  print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
719  if (isModEnabled("banque")) {
720  $bankaccountstatic->id = $objp->baid;
721  $bankaccountstatic->ref = $objp->baref;
722  $bankaccountstatic->label = $objp->baref;
723  $bankaccountstatic->number = $objp->banumber;
724  $bankaccountstatic->currency_code = $objp->bacurrency_code;
725 
726  if (isModEnabled('accounting')) {
727  $bankaccountstatic->account_number = $objp->account_number;
728 
729  $accountingjournal = new AccountingJournal($db);
730  $accountingjournal->fetch($objp->fk_accountancy_journal);
731  $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
732  }
733 
734  print '<td class="right">';
735  if ($bankaccountstatic->id) {
736  print $bankaccountstatic->getNomUrl(1, 'transactions');
737  }
738  print '</td>';
739  }
740  print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
741  print "</tr>";
742  $totalpaid += $objp->amount;
743  $i++;
744  }
745  } else {
746  print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
747  print '<td></td><td></td><td></td><td></td>';
748  print '</tr>';
749  }
750 
751  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right">'.price($totalpaid)."</td></tr>\n";
752  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right">'.price($object->amount)."</td></tr>\n";
753 
754  $resteapayer = $object->amount - $totalpaid;
755  $cssforamountpaymentcomplete = 'amountpaymentcomplete';
756 
757  print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
758  print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
759 
760  print "</table>";
761  print '</div>';
762 
763  $db->free($resql);
764  } else {
765  dol_print_error($db);
766  }
767 
768  print '</div>';
769  print '</div>';
770 
771  print '<div class="clearboth"></div>';
772 
773  print dol_get_fiche_end();
774 
775  if ($action == 'edit') {
776  print $form->buttonsSaveCancel();
777 
778  print "</form>\n";
779  }
780 
781 
782 
783  // Buttons for actions
784 
785  if ($action != 'edit') {
786  print '<div class="tabsAction">'."\n";
787 
788  // Reopen
789  if ($object->paye && $user->rights->tax->charges->creer) {
790  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a></div>';
791  }
792 
793  // Edit
794  if ($object->paye == 0 && $user->rights->tax->charges->creer) {
795  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>';
796  }
797 
798  // Emit payment
799  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) {
800  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement_charge.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment")."</a></div>";
801  }
802 
803  // Classify 'paid'
804  if ($object->paye == 0 && round($resteapayer) <= 0 && $user->rights->tax->charges->creer) {
805  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
806  }
807 
808  // Clone
809  if ($user->rights->tax->charges->creer) {
810  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=clone&token='.newToken().'">'.$langs->trans("ToClone")."</a></div>";
811  }
812 
813  // Delete
814  if ($user->rights->tax->charges->supprimer && empty($totalpaid)) {
815  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
816  } else {
817  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
818  }
819 
820  print "</div>";
821  }
822 
823 
824  // Select mail models is same action as presend
825  if (GETPOST('modelselected')) {
826  $action = 'presend';
827  }
828 
829  if ($action != 'presend') {
830  print '<div class="fichecenter"><div class="fichehalfleft">';
831  print '<a name="builddoc"></a>'; // ancre
832 
833  $includedocgeneration = 1;
834 
835  // Documents
836  if ($includedocgeneration) {
837  $objref = dol_sanitizeFileName($object->ref);
838  $relativepath = $objref.'/'.$objref.'.pdf';
839  $filedir = $conf->tax->dir_output.'/'.$objref;
840  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
841  //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
842  $genallowed = 0;
843  $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
844  print $formfile->showdocuments('tax', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
845  }
846 
847  // Show links to link elements
848  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
849  //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
850 
851 
852  print '</div><div class="fichehalfright">';
853 
854  /*
855  $MAXEVENT = 10;
856 
857  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
858 
859  // List of actions on element
860  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
861  $formactions = new FormActions($db);
862  $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
863  */
864 
865  print '</div></div>';
866  }
867 
868  //Select mail models is same action as presend
869  if (GETPOST('modelselected')) {
870  $action = 'presend';
871  }
872 
873  // Presend form
874  $modelmail = 'sc';
875  $defaulttopic = 'InformationMessage';
876  $diroutput = $conf->tax->dir_output;
877  $trackid = 'sc'.$object->id;
878 
879  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
880  } else {
881  /* Social contribution not found */
882  dol_print_error('', $object->error);
883  }
884 }
885 
886 // End of page
887 llxFooter();
888 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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 bank accounts.
Class to manage accounting journals.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage generation of HTML components for social contributions management.
Class to manage payments of social contributions.
Class to manage projects.
Class to manage Dolibarr users.
Definition: user.class.php:48
$parameters
Actions.
Definition: card.php:83
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->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') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
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.
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
$formconfirm
if ($action == 'delbookkeepingyear') {
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
tax_prepare_head(ChargeSociales $object)
Prepare array with list of tabs.
Definition: tax.lib.php:38