dolibarr 19.0.3
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
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
39if (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}
43if (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
77if (empty($action) && empty($id) && empty($ref)) {
78 $action = 'view';
79}
80
81// Load object
82if ($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');
95if ($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
108if ($reshook < 0) {
109 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110}
111
112if (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->hasRight('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->period = $dateperiod;
205 $object->amount = $amount;
206 $object->fk_user = $fk_user;
207 $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int');
208 $object->fk_account = (int) GETPOST('fk_account', 'int');
209 $object->fk_project = (int) GETPOST('fk_project', 'int');
210
211 $id = $object->create($user);
212 if ($id <= 0) {
213 setEventMessages($object->error, $object->errors, 'errors');
214 $action = 'create';
215 }
216 }
217 }
218
219
220 if ($action == 'update' && !$cancel && $permissiontoadd) {
221 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
222
223 if (!$dateech) {
224 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
225 $action = 'edit';
226 } elseif (!$dateperiod) {
227 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
228 $action = 'edit';
229 } elseif (empty($amount)) {
230 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
231 $action = 'edit';
232 } elseif (!is_numeric($amount)) {
233 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
234 $action = 'create';
235 } else {
236 $result = $object->fetch($id);
237
238 $object->date_ech = $dateech;
239 $object->periode = $dateperiod;
240 $object->period = $dateperiod;
241 $object->amount = $amount;
242 $object->fk_user = $fk_user;
243
244 $result = $object->update($user);
245 if ($result <= 0) {
246 setEventMessages($object->error, $object->errors, 'errors');
247 }
248 }
249 }
250
251 // Action clone object
252 if ($action == 'confirm_clone' && $confirm != 'yes') {
253 $action = '';
254 }
255
256 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
257 $db->begin();
258
259 $originalId = $object->id;
260
261 if ($object->id > 0) {
262 $object->id = $object->ref = null;
263 $object->paye = 0;
264 if (GETPOST('amount', 'alphanohtml')) {
265 $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
266 }
267
268 if (GETPOST('clone_label', 'alphanohtml')) {
269 $object->label = GETPOST('clone_label', 'alphanohtml');
270 } else {
271 $object->label = $langs->trans("CopyOf").' '.$object->label;
272 }
273
274 if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
275 $object->periode = dol_time_plus_duree($object->periode, 1, 'm');
276 $object->period = dol_time_plus_duree($object->periode, 1, 'm');
277 $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
278 } else {
279 // Note date_ech is often a little bit higher than dateperiod
280 $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
281 $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int'));
282 if ($newdateperiod) {
283 $object->periode = $newdateperiod;
284 $object->period = $newdateperiod;
285 if (empty($newdateech)) {
286 $object->date_ech = $object->periode;
287 }
288 }
289 if ($newdateech) {
290 $object->date_ech = $newdateech;
291 if (empty($newdateperiod)) {
292 // TODO We can here get dol_get_last_day of previous month:
293 // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
294 $object->periode = $object->date_ech;
295 $object->period = $object->date_ech;
296 }
297 }
298 }
299
300 $resultcheck = $object->check();
301 if ($resultcheck) {
302 $id = $object->create($user);
303 if ($id > 0) {
304 $db->commit();
305 $db->close();
306
307 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
308 exit;
309 } else {
310 $id = $originalId;
311 $db->rollback();
312
313 setEventMessages($object->error, $object->errors, 'errors');
314 }
315 }
316 } else {
317 $db->rollback();
318 dol_print_error($db, $object->error);
319 }
320 }
321
322 // Actions to build doc
323 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
324}
325
326
327/*
328 * View
329 */
330
331$form = new Form($db);
332$formfile = new FormFile($db);
333$formsocialcontrib = new FormSocialContrib($db);
334$bankaccountstatic = new Account($db);
335if (isModEnabled('project')) {
336 $formproject = new FormProjets($db);
337}
338
339$now = dol_now();
340
341$title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
342$help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module_Taxes_et_charges_spéciales|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
343llxHeader("", $title, $help_url);
344
345
346// Form to create a social contribution
347if ($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 tableforfieldcreate">';
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('', '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="history.go(-1)">';
444 print '</div>';
445
446 print '</form>';
447}
448
449// View mode
450if ($id > 0) {
451 $formconfirm = '';
452
453 if ($result > 0) {
454 $head = tax_prepare_head($object);
455
456 $totalpaid = $object->getSommePaiement();
457
458 // Clone confirmation
459 if ($action === 'clone') {
460 $formquestion = array(
461 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass'=>'fieldrequired'),
462 );
463 if (getDolGlobalString('TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX')) {
464 $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
465 } else {
466 $formquestion[] = array('type' => 'date', 'datenow'=>1, 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
467 $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
468 $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
469 }
470
471 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280);
472 }
473
474
475 if ($action == 'paid') {
476 $text = $langs->trans('ConfirmPaySocialContribution');
477 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
478 }
479
480 // Confirmation of the removal of the Social Contribution
481 if ($action == 'delete') {
482 $text = $langs->trans('ConfirmDeleteSocialContribution');
483 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
484 }
485
486 if ($action == 'edit') {
487 print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
488 print '<input type="hidden" name="token" value="'.newToken().'">';
489 print '<input type="hidden" name="action" value="update">';
490 }
491 // Call Hook formConfirm
492 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
493 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
494 if (empty($reshook)) {
495 $formconfirm .= $hookmanager->resPrint;
496 } elseif ($reshook > 0) {
497 $formconfirm = $hookmanager->resPrint;
498 }
499
500 /*
501 * View card
502 */
503 print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill', 0, '', '', 0, '', 1);
504
505 // Print form confirm
506 print $formconfirm;
507
508
509 // Social contribution card
510 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
511
512 $morehtmlref = '<div class="refidno">';
513 // Ref customer
514 $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', 0, 1);
515 $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', null, null, '', 1);
516
517 // Employee
518 if ($action != 'editfk_user') {
519 if ($object->getSommePaiement() > 0 && $object->fk_user > 0) {
520 $userstatic = new User($db);
521 $result = $userstatic->fetch($object->fk_user);
522 if ($result > 0) {
523 $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
524 }
525 } else {
526 $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
527 if ($object->fk_user > 0) {
528 $userstatic = new User($db);
529 $result = $userstatic->fetch($object->fk_user);
530 if ($result > 0) {
531 $morehtmlref .= $userstatic->getNomUrl(1);
532 } else {
533 dol_print_error($db);
534 exit();
535 }
536 }
537 }
538 } else {
539 $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
540 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
541 $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
542 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
543 $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
544 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
545 $morehtmlref .= '</form>';
546 }
547
548 // Project
549 if (isModEnabled('project')) {
550 $langs->load("projects");
551 $morehtmlref .= '<br>';
552 if ($permissiontoadd) {
553 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
554 if ($action != 'classify') {
555 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
556 }
557 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'fk_project' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
558 } else {
559 if (!empty($object->fk_project)) {
560 $proj = new Project($db);
561 $proj->fetch($object->fk_project);
562 $morehtmlref .= $proj->getNomUrl(1);
563 if ($proj->title) {
564 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
565 }
566 }
567 }
568 }
569 $morehtmlref .= '</div>';
570
571 $morehtmlright = '';
572
573 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
574
575 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
576
577 print '<div class="fichecenter">';
578 print '<div class="fichehalfleft">';
579 print '<div class="underbanner clearboth"></div>';
580
581 print '<table class="border centpercent tableforfield">';
582
583 // Type
584 print '<tr><td class="titlefield">';
585 print $langs->trans("Type")."</td><td>".$object->type_label."</td>";
586 print "</tr>";
587
588 // Date
589 if ($action == 'edit') {
590 print '<tr><td>'.$langs->trans("Date")."</td><td>";
591 print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1, 1);
592 print "</td></tr>";
593 } else {
594 print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
595 }
596
597 // Period end date
598 print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
599 print "<td>";
600 if ($action == 'edit') {
601 print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1);
602 } else {
603 print dol_print_date($object->periode, "day");
604 }
605 print "</td></tr>";
606
607 // Amount
608 if ($action == 'edit') {
609 print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
610 print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
611 print "</td></tr>";
612 } else {
613 print '<tr><td>'.$langs->trans("AmountTTC").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
614 }
615
616 // Mode of payment
617 print '<tr><td>';
618 print '<table class="nobordernopadding" width="100%"><tr><td>';
619 print $langs->trans('DefaultPaymentMode');
620 print '</td>';
621 if ($action != 'editmode') {
622 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>';
623 }
624 print '</tr></table>';
625 print '</td><td>';
626 if ($action == 'editmode') {
627 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', '', 1, 1);
628 } else {
629 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
630 }
631 print '</td></tr>';
632
633 // Bank account
634 if (isModEnabled("banque")) {
635 print '<tr><td class="nowrap">';
636 print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
637 print $langs->trans('DefaultBankAccount');
638 print '<td>';
639 if ($action != 'editbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
640 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>';
641 }
642 print '</tr></table>';
643 print '</td><td>';
644 if ($action == 'editbankaccount') {
645 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
646 } else {
647 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
648 }
649 print '</td>';
650 print '</tr>';
651 }
652
653 // Other attributes
654 $parameters = array();
655 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
656 print $hookmanager->resPrint;
657
658 print '</table>';
659
660 print '</div>';
661 print '<div class="fichehalfright">';
662
663 print '<div class="underbanner clearboth"></div>';
664
665 $nbcols = 3;
666 if (isModEnabled("banque")) {
667 $nbcols++;
668 }
669
670 /*
671 * Payments
672 */
673 $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
674 $sql .= " c.code as type_code,c.libelle as paiement_type,";
675 $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';
676 $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
677 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
678 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
679 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
680 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
681 $sql .= " WHERE p.fk_charge = ".((int) $id);
682 $sql .= " AND p.fk_charge = cs.rowid";
683 $sql .= " AND cs.entity IN (".getEntity('sc').")";
684 $sql .= " ORDER BY dp DESC";
685
686 //print $sql;
687 $resql = $db->query($sql);
688 if ($resql) {
689 $totalpaid = 0;
690
691 $num = $db->num_rows($resql);
692 $i = 0;
693 $total = 0;
694
695 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
696 print '<table class="noborder paymenttable">';
697 print '<tr class="liste_titre">';
698 print '<td>'.$langs->trans("RefPayment").'</td>';
699 print '<td>'.$langs->trans("Date").'</td>';
700 print '<td>'.$langs->trans("Type").'</td>';
701 if (isModEnabled("banque")) {
702 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
703 }
704 print '<td class="right">'.$langs->trans("Amount").'</td>';
705 print '</tr>';
706
707 $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
708
709 if ($num > 0) {
710 while ($i < $num) {
711 $objp = $db->fetch_object($resql);
712
713 $paymentsocialcontributiontmp->id = $objp->rowid;
714 $paymentsocialcontributiontmp->ref = $objp->rowid;
715 $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
716
717 print '<tr class="oddeven"><td>';
718 print $paymentsocialcontributiontmp->getNomUrl(1);
719 print '</td>';
720
721 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
722 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
723 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
724 if (isModEnabled("banque")) {
725 $bankaccountstatic->id = $objp->baid;
726 $bankaccountstatic->ref = $objp->baref;
727 $bankaccountstatic->label = $objp->baref;
728 $bankaccountstatic->number = $objp->banumber;
729 $bankaccountstatic->currency_code = $objp->bacurrency_code;
730
731 if (isModEnabled('accounting')) {
732 $bankaccountstatic->account_number = $objp->account_number;
733
734 $accountingjournal = new AccountingJournal($db);
735 $accountingjournal->fetch($objp->fk_accountancy_journal);
736 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
737 }
738
739 print '<td class="right">';
740 if ($bankaccountstatic->id) {
741 print $bankaccountstatic->getNomUrl(1, 'transactions');
742 }
743 print '</td>';
744 }
745 print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
746 print "</tr>";
747 $totalpaid += $objp->amount;
748 $i++;
749 }
750 } else {
751 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
752 print '<td></td><td></td><td></td><td></td>';
753 print '</tr>';
754 }
755
756 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowraponall">'.price($totalpaid)."</td></tr>\n";
757 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowraponall">'.price($object->amount)."</td></tr>\n";
758
759 $resteapayer = $object->amount - $totalpaid;
760 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
761
762 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
763 print '<td class="right nowraponall'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
764
765 print "</table>";
766 print '</div>';
767
768 $db->free($resql);
769 } else {
770 dol_print_error($db);
771 }
772
773 print '</div>';
774 print '</div>';
775
776 print '<div class="clearboth"></div>';
777
778 print dol_get_fiche_end();
779
780 if ($action == 'edit') {
781 print $form->buttonsSaveCancel();
782
783 print "</form>\n";
784 }
785
786
787
788 // Buttons for actions
789
790 if ($action != 'edit') {
791 print '<div class="tabsAction">'."\n";
792
793 // Reopen
794 if ($object->paye && $user->hasRight('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=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a></div>';
796 }
797
798 // Edit
799 if ($object->paye == 0 && $user->hasRight('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=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>';
801 }
802
803 // Emit payment
804 if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->hasRight('tax', 'charges', 'creer')) {
805 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>";
806 }
807
808 // Classify 'paid'
809 if ($object->paye == 0 && round($resteapayer) <= 0 && $user->hasRight('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=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
811 }
812
813 // Clone
814 if ($user->hasRight('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=clone&token='.newToken().'">'.$langs->trans("ToClone")."</a></div>";
816 }
817
818 // Delete
819 if ($user->hasRight('tax', 'charges', 'supprimer') && empty($totalpaid)) {
820 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>';
821 } else {
822 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
823 }
824
825 print "</div>";
826 }
827
828
829 // Select mail models is same action as presend
830 if (GETPOST('modelselected')) {
831 $action = 'presend';
832 }
833
834 if ($action != 'presend') {
835 print '<div class="fichecenter"><div class="fichehalfleft">';
836 print '<a name="builddoc"></a>'; // ancre
837
838 $includedocgeneration = 1;
839
840 // Documents
841 if ($includedocgeneration) {
842 $objref = dol_sanitizeFileName($object->ref);
843 $relativepath = $objref.'/'.$objref.'.pdf';
844 $filedir = $conf->tax->dir_output.'/'.$objref;
845 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
846 //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
847 $genallowed = 0;
848 $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
849 print $formfile->showdocuments('tax', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
850 }
851
852 // Show links to link elements
853 //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
854 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
855
856
857 print '</div><div class="fichehalfright">';
858
859 /*
860 $MAXEVENT = 10;
861
862 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
863
864 // List of actions on element
865 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
866 $formactions = new FormActions($db);
867 $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
868 */
869
870 print '</div></div>';
871 }
872
873 //Select mail models is same action as presend
874 if (GETPOST('modelselected')) {
875 $action = 'presend';
876 }
877
878 // Presend form
879 $modelmail = 'sc';
880 $defaulttopic = 'InformationMessage';
881 $diroutput = $conf->tax->dir_output;
882 $trackid = 'sc'.$object->id;
883
884 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
885 } else {
886 /* Social contribution not found */
887 dol_print_error('', $object->error);
888 }
889}
890
891// End of page
892llxFooter();
893$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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)
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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