-
Notifications
You must be signed in to change notification settings - Fork 2
/
gestion.php
277 lines (222 loc) · 9.46 KB
/
gestion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
require_once 'config.php';
dol_include_once('/compta/sociales/class/chargesociales.class.php');
dol_include_once('/recurrence/class/recurrence.class.php');
$langs->load('recurrence@recurrence');
$action = __get('action', 'view');
$page = __get('page', 0);
if ($page < 0) $page = 0;
$limit = GETPOST('limit') ? GETPOST('limit') : $conf->liste_limit;
$offset = $limit * $page;
if (!$user->rights->recurrence->all->read) {
accessforbidden();
}
$newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken'];
/*
* HEADER
*/
llxHeader('', 'Récurrence des charges sociales');
print_fiche_titre('Récurrence des charges sociales', '', 'report.png@report');
print dol_get_fiche_head(array(
array(dol_buildpath('/recurrence/gestion.php?action=view&token='.$newToken, 1), 'Liste des récurrences', 'view'),
array(dol_buildpath('/recurrence/gestion.php?action=add&token='.$newToken, 1), 'Enregistrer une tâche récurrente', 'add')
) , $action, '');
_liste_charges_sociales( $action, $page, $limit, $offset);
if ($user->rights->tax->charges->creer) {
if ($action == 'add') {
if ($user->rights->tax->charges->creer) {
echo '<div class="tabsAction">';
$url = (float)DOL_VERSION>=5 ? '/compta/sociales/card.php?leftmenu=tax_social&action=create&token='.$newToken : '/compta/sociales/charges.php?leftmenu=tax_social&action=create&token='.$newToken;
$urlPage = 'charges.php';
if(version_compare(DOL_VERSION, '5.0', '>=')) {
$urlPage = 'card.php';
}
echo '
<div class="inline-block divButAction">
<a class="butAction" href="' . DOL_URL_ROOT . $url .'">
Ajouter une charge sociale
</a>
</div>';
echo '</div>';
}
} else {
echo '<div class="tabsAction">';
echo '
<div class="inline-block divButAction">
<input type="submit" class="butAction" value="Payer les récurrences sélectionnées" />
</div>';
echo '<div class="inline-block divButAction"><a class="butAction" href="gestion.php?action=add&token='.$newToken.'">Ajouter une récurrence</a></div>';
echo '</div>';
}
}
echo '</form>';
echo '<div style="clear: both;"></div>';
?>
<script>
$(document).ready(function() {
$(".date").datepicker({
dateFormat: 'dd/mm/yy',
defaultDate: null
}).val();
$('.update-recurrence, .delete-recurrence').click(function(e) {
e.preventDefault();
$(this).text("...").prop("disabled",1);
var type = $(this).attr('class');
var id_charge = $(this).data('chargesociale');
var periode = $('#periode_' + id_charge + ' option:selected').val();
var date_fin_rec = $('#date_fin_rec_' + id_charge).datepicker().val();
var nb_prev_rec = $('#nb_prev_rec_' + id_charge).val();
var montant = $('#montant_' + id_charge).val();
$.ajax({
type: 'POST',
url: 'script/update-recurrence.php',
data: {
type: type,
id_charge: id_charge,
periode: periode,
date_fin_rec: date_fin_rec,
nb_prev_rec: nb_prev_rec,
montant: montant
}
}).done(function(data) {
document.location.reload(true);
});
});
});
</script>
<?php
llxfooter();
/*
* Liste des charges sociales
*/
function _liste_charges_sociales( $action, $page, $limit, $offset) {
global $conf, $db, $user, $bc, $langs;
$newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken'];
$charge_sociale = new ChargeSociales($db);
$sql = "
SELECT cs.rowid as id, cs.fk_type as type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle as type_lib, SUM(pc.amount) as alreadypayed,
(SELECT r.montant FROM " . MAIN_DB_PREFIX . "recurrence as r WHERE r.fk_chargesociale = cs.rowid) montant_reccur
FROM " . MAIN_DB_PREFIX . "c_chargesociales as c
INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as cs ON c.id = cs.fk_type
LEFT JOIN " . MAIN_DB_PREFIX . "paiementcharge as pc ON pc.fk_charge = cs.rowid
WHERE cs.fk_type = c.id
AND cs.entity = " . $conf->entity . "
AND cs.rowid NOT IN (SELECT fk_target FROM " . MAIN_DB_PREFIX . "element_element WHERE sourcetype = 'chargesociales' AND targettype = 'chargesociales')
";
if ($action == 'add')
$sql .= "AND cs.rowid NOT IN (SELECT fk_chargesociale FROM " . MAIN_DB_PREFIX . "recurrence)";
else
$sql .= "AND cs.rowid IN (SELECT fk_chargesociale FROM " . MAIN_DB_PREFIX . "recurrence)";
$sql .= 'GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle ';
$sql .= 'ORDER BY cs.periode DESC ';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
$sql .= 'LIMIT ' . $offset . ', ' . ($limit + 1);
$res = $db->query($sql);
$num = $db->num_rows($res);
if(empty($nbtotalofrecords)) $nbtotalofrecords = $num;
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; // Formulaire pour la gestion des paiements
print '<input type="hidden" name="token" value="'.$newToken.'">';
$param = '&action=' . $action;
print_barre_liste('Liste', $page, $_SERVER["PHP_SELF"], $param, '', '', '', $num, $nbtotalofrecords, 'title_generic.png', 0, '', '', $limit);
print '</form>';
echo '<form method="POST" action="paiement.php">'; // Formulaire pour la gestion des paiements
print '<input type="hidden" name="token" value="'.$newToken.'">';
$form = new TFormCore($db);
echo '<table class="noborder" width="100%">';
_print_head_tab_charges_sociales($action);
$var = true;
echo '<tbody>';
while($obj = $db->fetch_object($res)) {
$var = !$var;
$charge_sociale->id = $obj->id;
$charge_sociale->lib = $obj->id;
$charge_sociale->ref = $obj->id;
if ($action != 'add') {
$recurrence = Recurrence::get_recurrence($charge_sociale->id);
}
$TNextCharges = Recurrence::get_prochaines_charges($charge_sociale->id);
echo '<tr ' . $bc[$var] . '>';
if ($action != 'add') {
echo '<td><input type="checkbox" name="recurrences[]" value="' . $charge_sociale->id . '" style="margin: 0 0 0 4px;" /></td>';
} else {
echo '<td></td>';
}
echo '<td>' . $charge_sociale->getNomUrl(1,'20') . '</td>';
echo '<td>' . $obj->libelle . '</td>';
echo '<td>' . $obj->type_lib . '</td>'; // Type
echo '<td>' . dol_print_date($obj->periode, 'day') . '</td>';
if ($action != 'add') {
// Affiche la date de la prochaine charge créée à partir de cette récurrence
if (!empty($TNextCharges)) {
echo '<td>' . dol_print_date($TNextCharges[0]->periode, 'day') . '</td>';
} else {
echo '<td></td>';
}
}
echo '<td><input type="text" id="montant_' . $obj->id . '" name="montant" value="'.(($obj->montant_reccur > 0) ? $obj->montant_reccur : $obj->amount).'" /></td>';
echo '<td>';
if ($action == 'add') {
Recurrence::get_liste_periodes( 'periode_' . $obj->id, 'fk_periode', 'mensuel');
} else {
Recurrence::get_liste_periodes( 'periode_' . $obj->id, 'fk_periode', $recurrence->periode);
}
echo '</td>';
if ($action == 'add') {
echo '<td><input type="text" class="date" id="date_fin_rec_' . $obj->id . '" name="date_fin_rec" /></td>';
echo '<td><input type="text" id="nb_prev_rec_' . $obj->id . '" name="nb_previsionnel_rec" /></td>';
} else {
$date = '';
if ($recurrence->date_fin > 0)
$date = date('d/m/Y', $recurrence->date_fin);
echo '<td><input type="text" class="date" id="date_fin_rec_' . $obj->id . '" name="date_fin_rec" value="' . $date . '"/></td>';
echo '<td><input type="text" id="nb_prev_rec_' . $obj->id . '" name="nb_previsionnel_rec" value="' . $recurrence->nb_previsionnel . '"/></td>';
}
if ($user->rights->tax->charges->creer) {
if ($action == 'add') {
echo '<td><button class="update-recurrence" data-chargesociale="' . $obj->id . '" style="margin: 2px 4px; padding: 2px;">Ajouter</button></td>';
} else {
echo '<td>
<button class="update-recurrence" data-chargesociale="' . $obj->id . '" style="margin: 2px 4px; padding: 2px;">Modifier</button>
<button class="delete-recurrence" title="'.$langs->trans('helpRemoveRecurence').'" data-chargesociale="' . $obj->id . '" style="margin: 2px 4px; padding: 2px;">'.$langs->trans('Remove').'</button>
</td>';
}
} else {
echo '<td>Droits requis</td>';
}
echo '</tr>';
}
if (is_array($num) && count($num) <= 0) {
echo '<tr>';
if ($action == 'add') {
echo '<td style="text-align: center;" colspan="9">Aucune récurrence enregistrée. (<a href="gestion.php?action=add">Créer une récurrence</a>)</td>';
} else {
echo '<td style="text-align: center;" colspan="10">Aucune récurrence enregistrée. (<a href="gestion.php?action=add">Créer une récurrence</a>)</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}
function _print_head_tab_charges_sociales($action) {
echo '<thead>';
echo '<tr class="liste_titre">';
echo '<th class="liste_titre"></th>';
print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'id');
print_liste_field_titre('Libellé', $_SERVER['PHP_SELF'], 'libelle');
print_liste_field_titre('Type', $_SERVER['PHP_SELF'], 'type_lib');
print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'periode');
if ($action != 'add') {
print_liste_field_titre('Prochaine charge à payer', $_SERVER['PHP_SELF'], 'periode');
}
print_liste_field_titre('Montant', $_SERVER['PHP_SELF'], 'amount');
print_liste_field_titre('Récurrence', $_SERVER['PHP_SELF'], 'fk_recurrence');
print_liste_field_titre('Date de fin', $_SERVER['PHP_SELF'], 'fk_recurrence');
print_liste_field_titre('Nb. prévisionnel', $_SERVER['PHP_SELF'], 'fk_recurrence');
print_liste_field_titre('Action', $_SERVER['PHP_SELF'], 'fk_recurrence');
echo '</tr>';
echo '</thead>';
}