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