1 |
<?php |
<?php |
2 |
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> |
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> |
3 |
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> |
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> |
4 |
* |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
22 |
*/ |
*/ |
23 |
|
|
24 |
/** |
/** |
25 |
\file htdocs/compta/paiement.php |
\file htdocs/compta/paiement.php |
26 |
\ingroup compta |
\ingroup compta |
27 |
\brief Page de création d'un paiement |
\brief Page de création d'un paiement |
28 |
\version $Revision$ |
\version $Revision$ |
29 |
*/ |
*/ |
30 |
|
|
31 |
include_once("./pre.inc.php"); |
include_once("./pre.inc.php"); |
46 |
*/ |
*/ |
47 |
if ($_POST["action"] == 'add_paiement') |
if ($_POST["action"] == 'add_paiement') |
48 |
{ |
{ |
49 |
if ($_POST["paiementid"] > 0) |
$error = 0; |
50 |
|
|
51 |
|
if ($_POST["paiementid"] > 0) |
52 |
{ |
{ |
53 |
$datepaye = $db->idate(mktime(12, 0 , 0, |
$datepaye = $db->idate(mktime(12, 0 , 0, |
54 |
$_POST["remonth"], |
$_POST["remonth"], |
55 |
$_POST["reday"], |
$_POST["reday"], |
56 |
$_POST["reyear"])); |
$_POST["reyear"])); |
57 |
|
|
58 |
$paiement_id = 0; |
$paiement_id = 0; |
59 |
$amounts = array(); |
$amounts = array(); |
60 |
foreach ($_POST as $key => $value) |
foreach ($_POST as $key => $value) |
61 |
{ |
{ |
62 |
if (substr($key,0,7) == 'amount_') |
if (substr($key,0,7) == 'amount_') |
63 |
{ |
{ |
64 |
$other_facid = substr($key,7); |
$other_facid = substr($key,7); |
65 |
|
|
66 |
$amounts[$other_facid] = $_POST[$key]; |
$amounts[$other_facid] = $_POST[$key]; |
67 |
} |
} |
68 |
} |
} |
69 |
|
|
70 |
|
$db->begin(); |
71 |
|
|
72 |
|
// Creation de la ligne paiement |
73 |
|
$paiement = new Paiement($db); |
74 |
|
$paiement->datepaye = $datepaye; |
75 |
|
$paiement->amounts = $amounts; // Tableau de montant |
76 |
|
$paiement->paiementid = $_POST["paiementid"]; |
77 |
|
$paiement->num_paiement = $_POST["num_paiement"]; |
78 |
|
$paiement->note = $_POST["comment"]; |
79 |
|
|
80 |
|
$paiement_id = $paiement->create($user); |
81 |
|
|
82 |
$db->begin(); |
if ($paiement_id > 0) |
|
|
|
|
// Creation de la ligne paiement |
|
|
$paiement = new Paiement($db); |
|
|
$paiement->datepaye = $datepaye; |
|
|
$paiement->amounts = $amounts; // Tableau de montant |
|
|
$paiement->paiementid = $_POST["paiementid"]; |
|
|
$paiement->num_paiement = $_POST["num_paiement"]; |
|
|
$paiement->note = $_POST["comment"]; |
|
|
|
|
|
$paiement_id = $paiement->create($user); |
|
|
if ($paiement_id > 0) |
|
83 |
{ |
{ |
84 |
// On determine le montant total du paiement |
// On determine le montant total du paiement |
85 |
$total=0; |
$total=0; |
86 |
foreach ($paiement->amounts as $key => $value) |
foreach ($paiement->amounts as $key => $value) |
87 |
{ |
{ |
88 |
$facid = $key; |
$facid = $key; |
89 |
$value = trim($value); |
$value = trim($value); |
90 |
$amount = round(ereg_replace(",",".",$value), 2); |
$amount = round(ereg_replace(",",".",$value), 2); |
91 |
if (is_numeric($amount)) |
if (is_numeric($amount)) |
92 |
{ |
{ |
93 |
$total += $amount; |
$total += $amount; |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
97 |
|
if ($conf->banque->enabled && $_POST["accountid"]) |
98 |
|
{ |
99 |
|
// Insertion dans llx_bank |
100 |
|
$label = "Règlement facture"; |
101 |
|
$acc = new Account($db, $_POST["accountid"]); |
102 |
|
//paiementid contient "CHQ ou VIR par exemple" |
103 |
|
$bank_line_id = $acc->addline($paiement->datepaye, |
104 |
|
$paiement->paiementid, |
105 |
|
$label, |
106 |
|
$total, |
107 |
|
$paiement->num_paiement, |
108 |
|
'', |
109 |
|
$user); |
110 |
|
|
111 |
|
|
112 |
|
// Mise a jour fk_bank dans llx_paiement. |
113 |
|
// On connait ainsi le paiement qui a généré l'écriture bancaire |
114 |
|
if ($bank_line_id > 0) |
115 |
|
{ |
116 |
|
$paiement->update_fk_bank($bank_line_id); |
117 |
|
|
118 |
|
// Mise a jour liens (pour chaque facture concernées par le paiement) |
119 |
|
foreach ($paiement->amounts as $key => $value) |
120 |
|
{ |
121 |
|
$facid = $key; |
122 |
|
$fac = new Facture($db); |
123 |
|
$fac->fetch($facid); |
124 |
|
$fac->fetch_client(); |
125 |
|
$acc->add_url_line($bank_line_id, |
126 |
|
$paiement_id, |
127 |
|
DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', |
128 |
|
"(paiement)"); |
129 |
|
$acc->add_url_line($bank_line_id, |
130 |
|
$fac->client->id, |
131 |
|
DOL_URL_ROOT.'/compta/fiche.php?socid=', |
132 |
|
$fac->client->nom); |
133 |
|
} |
134 |
|
|
135 |
|
} |
136 |
|
else |
137 |
|
{ |
138 |
|
$error++; |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
} |
143 |
|
else |
144 |
|
{ |
145 |
|
$error++; |
146 |
|
} |
147 |
|
|
|
// Insertion dans llx_bank |
|
|
$label = "Règlement facture"; |
|
|
$acc = new Account($db, $_POST["accountid"]); |
|
|
//paiementid contient "CHQ ou VIR par exemple" |
|
|
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementid, $label, $total, $paiement->num_paiement, '', $user); |
|
|
|
|
|
// Mise a jour fk_bank dans llx_paiement. On connait ainsi le paiement qui a généré l'écriture bancaire |
|
|
if ($bank_line_id > 0) |
|
|
{ |
|
|
$paiement->update_fk_bank($bank_line_id); |
|
148 |
|
|
149 |
// Mise a jour liens (pour chaque facture concernées par le paiement) |
if ($error == 0) |
150 |
foreach ($paiement->amounts as $key => $value) |
{ |
|
{ |
|
|
$facid = $key; |
|
|
$fac = new Facture($db); |
|
|
$fac->fetch($facid); |
|
|
$fac->fetch_client(); |
|
|
$acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); |
|
|
$acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); |
|
|
} |
|
151 |
|
|
152 |
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; |
$loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; |
153 |
|
|
154 |
|
$db->commit(); |
155 |
|
|
156 |
|
Header("Location: $loc"); |
157 |
|
|
158 |
$db->commit(); |
} |
159 |
|
else |
160 |
|
{ |
161 |
|
// Il y a eu erreur |
162 |
|
$db->rollback(); |
163 |
|
$fiche_erreur_message = $langs->trans("ErrorUnknown"); |
164 |
|
} |
165 |
|
|
|
Header("Location: $loc"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Il y a eu erreur |
|
|
$db->rollback(); |
|
|
$fiche_erreur_message = $langs->trans("ErrorUnknown"); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
// Il y a eu erreur |
|
|
$db->rollback(); |
|
|
$fiche_erreur_message = $langs->trans("ErrorUnknown"); |
|
|
} |
|
166 |
} |
} |
167 |
else |
else |
168 |
{ |
{ |
169 |
$fiche_erreur_message = '<div class="error">Vous devez sélectionner un mode de paiement</div>'; |
$fiche_erreur_message = '<div class="error">Vous devez sélectionner un mode de paiement</div>'; |
170 |
} |
} |
171 |
} |
} |
172 |
|
|
202 |
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; |
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = s.idp"; |
203 |
$sql .= " AND f.rowid = $facid"; |
$sql .= " AND f.rowid = $facid"; |
204 |
|
|
205 |
$result = $db->query($sql); |
$resql = $db->query($sql); |
206 |
if ($result) |
if ($resql) |
207 |
{ |
{ |
208 |
$num = $db->num_rows($result); |
$num = $db->num_rows($resql); |
209 |
if ($num) |
if ($num) |
210 |
{ |
{ |
211 |
$obj = $db->fetch_object($result); |
$obj = $db->fetch_object($resql); |
212 |
|
|
213 |
$total = $obj->total; |
$total = $obj->total; |
214 |
|
|
234 |
|
|
235 |
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY id"; |
$sql = "SELECT id, libelle FROM ".MAIN_DB_PREFIX."c_paiement ORDER BY id"; |
236 |
|
|
237 |
$result = $db->query($sql); |
$resql = $db->query($sql); |
238 |
if ($result) |
if ($resql) |
239 |
{ |
{ |
240 |
$num = $db->num_rows($result); |
$num = $db->num_rows($resql); |
241 |
$i = 0; |
$i = 0; |
242 |
while ($i < $num) |
while ($i < $num) |
243 |
{ |
{ |
244 |
$objopt = $db->fetch_object($result); |
$objopt = $db->fetch_object($resql); |
245 |
print "<option value=\"$objopt->id\">$objopt->libelle</option>\n"; |
print "<option value=\"$objopt->id\">$objopt->libelle</option>\n"; |
246 |
$i++; |
$i++; |
247 |
} |
} |
250 |
print "</td>\n"; |
print "</td>\n"; |
251 |
|
|
252 |
print '<td rowspan="3" valign="top">'; |
print '<td rowspan="3" valign="top">'; |
253 |
print '<textarea name="comment" wrap="soft" cols="40" rows="6"></textarea></td></tr>'; |
print '<textarea name="comment" wrap="soft" cols="40" rows="4"></textarea></td></tr>'; |
254 |
|
|
255 |
print "<tr><td>Numéro :</td><td><input name=\"num_paiement\" type=\"text\"><br><em>Numéro du chèque / virement</em></td></tr>\n"; |
print "<tr><td>Numéro :</td><td><input name=\"num_paiement\" type=\"text\"><br><em>Numéro du chèque / virement</em></td></tr>\n"; |
256 |
|
|
257 |
print "<tr><td>Compte à créditer :</td><td><select name=\"accountid\">\n"; |
|
258 |
|
if ($conf->banque->enabled) |
|
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account ORDER BY rowid"; |
|
|
|
|
|
$result = $db->query($sql); |
|
|
if ($result) |
|
259 |
{ |
{ |
260 |
$num = $db->num_rows(); |
|
261 |
$i = 0; |
print "<tr><td>Compte à créditer :</td><td><select name=\"accountid\">\n"; |
262 |
while ($i < $num) |
|
263 |
|
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_account ORDER BY rowid"; |
264 |
|
|
265 |
|
$resql = $db->query($sql); |
266 |
|
if ($resql) |
267 |
{ |
{ |
268 |
$objopt = $db->fetch_object($result); |
$num = $db->num_rows(); |
269 |
print '<option value="'.$objopt->rowid.'"'; |
$i = 0; |
270 |
if (defined("FACTURE_RIB_NUMBER") && FACTURE_RIB_NUMBER == $objopt->rowid) |
while ($i < $num) |
271 |
{ |
{ |
272 |
print ' selected'; |
$objopt = $db->fetch_object($resql); |
273 |
|
print '<option value="'.$objopt->rowid.'"'; |
274 |
|
if (defined("FACTURE_RIB_NUMBER") && FACTURE_RIB_NUMBER == $objopt->rowid) |
275 |
|
{ |
276 |
|
print ' selected'; |
277 |
|
} |
278 |
|
print '>'.$objopt->label.'</option>'; |
279 |
|
$i++; |
280 |
} |
} |
281 |
print '>'.$objopt->label.'</option>'; |
$db->free($resql); |
|
$i++; |
|
282 |
} |
} |
283 |
|
print "</select>"; |
284 |
|
print "</td></tr>\n"; |
285 |
|
|
286 |
} |
} |
287 |
print "</select>"; |
else |
288 |
print "</td></tr>\n"; |
{ |
289 |
|
print '<tr><td colspan="2"> </td></tr>'; |
290 |
|
} |
291 |
|
|
292 |
/* |
/* |
293 |
* Autres factures impayées |
* Autres factures impayées |
294 |
*/ |
*/ |
302 |
$sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée |
$sql .= " AND f.fk_statut = 1"; // Statut=0 => non validée, Statut=2 => annulée |
303 |
$sql .= " GROUP BY f.facnumber"; |
$sql .= " GROUP BY f.facnumber"; |
304 |
|
|
305 |
if ($db->query($sql)) |
$resql = $db->query($sql); |
306 |
|
|
307 |
|
if ($resql) |
308 |
{ |
{ |
309 |
$num = $db->num_rows(); |
$num = $db->num_rows($resql); |
310 |
|
|
311 |
if ($num > 0) |
if ($num > 0) |
312 |
{ |
{ |
327 |
|
|
328 |
while ($i < $num) |
while ($i < $num) |
329 |
{ |
{ |
330 |
$objp = $db->fetch_object(); |
$objp = $db->fetch_object($resql); |
331 |
$var=!$var; |
$var=!$var; |
332 |
|
|
333 |
print "<tr $bc[$var]>"; |
print "<tr $bc[$var]>"; |
373 |
} |
} |
374 |
print "</table></td></tr>\n"; |
print "</table></td></tr>\n"; |
375 |
} |
} |
376 |
$db->free(); |
$db->free($resql); |
377 |
} |
} |
378 |
else |
else |
379 |
{ |
{ |
416 |
|
|
417 |
$sql .= " ORDER BY $sortfield $sortorder"; |
$sql .= " ORDER BY $sortfield $sortorder"; |
418 |
$sql .= $db->plimit( $limit +1 ,$offset); |
$sql .= $db->plimit( $limit +1 ,$offset); |
419 |
$result = $db->query($sql); |
$resql = $db->query($sql); |
420 |
|
|
421 |
if ($result) |
if ($resql) |
422 |
{ |
{ |
423 |
$num = $db->num_rows(); |
$num = $db->num_rows($resql); |
424 |
$i = 0; |
$i = 0; |
425 |
$var=True; |
$var=True; |
426 |
|
|
437 |
|
|
438 |
while ($i < min($num,$limit)) |
while ($i < min($num,$limit)) |
439 |
{ |
{ |
440 |
$objp = $db->fetch_object(); |
$objp = $db->fetch_object($resql); |
441 |
$var=!$var; |
$var=!$var; |
442 |
print "<tr $bc[$var]>"; |
print "<tr $bc[$var]>"; |
443 |
print "<td><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n"; |
print "<td><a href=\"facture.php?facid=$objp->facid\">$objp->facnumber</a></td>\n"; |