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