Codigo php - abono
Publicado por Jose Gonzalez (2 intervenciones) el 04/11/2014 04:58:05
Hola a todos, quisiera saber quien me puede ayudar con un codigo en php para realizar un abono.
El objetivo de mi codigo es realizar el pago de distintos meses, verificar cuanto se esta abonando y pagar el o los meses correspondientes.
Les dejo el codigo que he estado haciendo:
Espero sus respuestas. Estoy desesperado :(
El objetivo de mi codigo es realizar el pago de distintos meses, verificar cuanto se esta abonando y pagar el o los meses correspondientes.
Les dejo el codigo que he estado haciendo:
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
require_once("../funciones/comprobarsession.php");
include ("../funciones/libreria2.php");
encabezado();
nav();
conectar();
$query = mysql_query("SELECT * FROM propietario where status='1' ") or die(mysql_error());
$resultado = mysql_query("SELECT * FROM mensualidad ");
?>
<section id="main"><!-- #main content and sidebar area -->
<section id="content">
<h2 align="center">Pago de mensualidad</h2><br />
<form id="pago" action="enviarform_pago.php" method="post" name="form1">
<div id="formulario">
<table width="550px" height="60" align="center">
<tr>
<td align="right" >
<label>C.I Propietario: </label>
<select name="ci_p" onchange="carga_datos('pago')" >
<option value="<?php echo $_REQUEST['ci_p']; ?>"><?php echo $fila['cedula_p']; ?></option>
<?php while ($data = mysql_fetch_array($query)): ?>
<option value="<?php echo $data['id_propietario']; ?>"><?php echo $data['nombre_p'].' '.$data['apellido_p'].' '.$data['cedula_p'] ?></option>
<?php endwhile; ?>
</select>
</td>
</tr>
</table>
<?php
if(isset($_REQUEST['ci_p']) && !empty($_REQUEST['ci_p'])){
$query1 = mysql_query("SELECT * FROM propietario where id_propietario=".$_REQUEST['ci_p']." ") or die(mysql_error());
$fila=mysql_fetch_array($query1);
?>
<?php
$arreglo_pagos=array();
$q="SELECT `id_c_p`,sum(abono) as abono FROM `capital` WHERE `id_propietario`=".$_REQUEST['ci_p']." group by `id_c_p`";
$datos_pago_usuario = mysql_query($q);
while ($fila_pago= mysql_fetch_array($datos_pago_usuario)) {
$arreglo_pagos[$fila_pago['id_c_p']]=$fila_pago;
}
?>
<label>Propietario: </label><?php echo $fila["cedula_p"].' '.$fila["nombre_p"].' '.$fila["apellido_p"] ?><br/>
<br><table width="500px" class="bordered" height="600" align="center">
<tr>
<th align="center" height="10" width="10">Mes</th>
<th align="center" height="10" width="15">Monto</th>
<th align="center" height="10" width="15">Abono</th>
<th align="center" height="10" width="30">Pagar</th>
</tr>
<?php
while ($fila = mysql_fetch_array($resultado)) {
?>
<tr>
<td name="motivo_<?php echo $fila["id_c_p"]; ?>" height="10" width="50"><?php echo $fila["motivo"];
echo "\n"; ?> </td>
<td id="monto_<?php echo $fila["id_c_p"]; ?>" name="monto" height="10"align="center" width="15"> <?php echo $fila["monto"];
echo "\n"; ?></td>
<td align="center" width="15" height="10"><?php echo $arreglo_pagos[$fila["id_c_p"]]['abono'] ?></td>
<td align="center" width="15" height="10">
<?php if($fila["monto"] - $arreglo_pagos[$fila["id_c_p"]]['abono'] > 0)
{
$deuda= $fila["monto"] - $arreglo_pagos[$fila["id_c_p"]]['abono'];
?>
<input type="checkbox" id="<?php echo $fila["id_c_p"]; ?>" class="pagomes" height="10" name="pago_mes[<?php echo $fila["id_c_p"]; ?>]" value="<?php echo $deuda; ?>"/> <?php echo $deuda; ?>
</td>
<?php } else { ?>
</tr>
<?php
}
}
}
?>
<script>
$(document).ready(function() {
carga_datos=function (form){
$('#'+form).attr("action","pago.php");
$("#"+form).submit();
}
$(".pagomes").click(function(){
var total=0;
$('.pagomes').each(function(){
if(this.checked){
total=total+parseInt(this.value);
}
}
);
$('#total').text(total);
}
)
$("#no3").click(function(){
$("#formno3").hide("slow");
});
$("#si3").click(function(){
$("#formno3").show("slow");
});
});
</script>
<script>
$(document).ready(function() {
$("#si1").click(function(){
$("#formno1").toggle("slow");
});
$("#si2").click(function(){
$("#formno2").toggle("slow");
});
});
</script>
</table>
<br /><br />
<table width="500px" height="180" align="center">
<tr>
<td align="left" height="10" width="50">
<label>Total a cancelar: </label>
</td>
<td id="total" height="10" width="10">
</td>
</tr>
<tr>
<td align="left" width="150">
<label>Forma de pago: </label>
</td>
<td width="400">
<input type="radio" name="forma_pago" id="no3" value="todo" />Cancelar todo
<input type="radio" name="forma_pago" id="si3" value="abono" />Abono
<td id="formno3" width="100" style="display:none">
<input type="text" name="abono" size="15" maxlength="30" value="" />
</td>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="efectivo"id="si1" VALUE="transferencia">Transferencia <br />
<td id="formno1" width="100" style="display:none">
<label >Banco: </label>
<input type="text" name="banco" size="15" maxlength="30" value="" />
</td>
<td width="100">
<input type="checkbox" name="efectivo" VALUE="efectivo">Efectivo <br />
</td>
<tr>
<td>
<input type="checkbox" name="efectivo" id="si2" VALUE="deposito"> Deposito <br />
<td id="formno2" width="500" style="display:none">
<label >Nro. Comprobante: </label>
<input type="text" name="n_comprobante" size="15" maxlength="30" value="" />
</td>
<td width="100">
<input type="checkbox" name="efectivo" VALUE="cheque">Cheque <br />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<button type="submit" value="Registrar" onclick="validar()" name="registrar" title="Hacer Clic para Registrar" /><a >Registrar</a> </button>
<button type="reset" value="Cancelar" name="cancelar" title="Hacer Clic para Cancelar" /><a href="servicios.php" >Cancelar</a></button>
</td>
</tr>
</div>
</form>
</table>
</section>
<aside id="sidebar">
<h3>Servicios</h3><br>
<ul>
<li><?php if($_SESSION['nivel']=='1') {
echo "<a href='egresos.php'>Pago de Servicios</a>";
} ?></li>
<li><a href="list_ingresos.php">Listado de Ingresos</a></li>
<li><a href="list_egresos.php">Listado de Egresos</a></li>
<li><a href="total.php">Capital General</a></li>
<li> <?php if($_SESSION['nivel']=='1') {
echo "<a href='pago.php'>Pago de Mensualidad</a>";
} ?></li>
<li><a href="list_morosos.php">Morosos</a></li>
</ul>
</aside>
</section>
<?php
footer();
?> <------------------Aqui es donde selecciono lo que voy a pagar y el monto a abonar.
Con esta funcion proceso el monto a abonar y respectivamente realizo el pago el mes seleccionado.
<?php
conectar();
$me1="SELECT * FROM mensualidad where id_c_p='1' ";
$mes1=mysql_query($me1);
$arraymes1 = mysql_fetch_array($mes1);
$a_mes1=$arraymes1['monto'];
$me2="SELECT * FROM mensualidad where id_c_p='2'";
$mes2=mysql_query($me2);
$arraymes2 = mysql_fetch_array($mes2);
$a_mes2=$arraymes2['monto'];
$me3="SELECT * FROM mensualidad where id_c_p='3'";
$mes3=mysql_query($me3);
$arraymes3 = mysql_fetch_array($mes3);
$a_mes3=$arraymes3['monto'];
$me4="SELECT * FROM mensualidad where id_c_p='4'";
$mes4=mysql_query($me4);
$arraymes4 = mysql_fetch_array($mes4);
$a_mes4=$arraymes4['monto'];
$me5="SELECT * FROM mensualidad where id_c_p='5'";
$mes5=mysql_query($me5);
$arraymes5 = mysql_fetch_array($mes5);
$a_mes5=$arraymes5['monto'];
$me6="SELECT * FROM mensualidad where id_c_p='6'";
$mes6=mysql_query($me6);
$arraymes6 = mysql_fetch_array($mes6);
$a_mes6=$arraymes6['monto'];
$me7="SELECT * FROM mensualidad where id_c_p='7'";
$mes7=mysql_query($me7);
$arraymes7 = mysql_fetch_array($mes7);
$a_mes7=$arraymes7['monto'];
$me8="SELECT * FROM mensualidad where id_c_p='8'";
$mes8=mysql_query($me8);
$arraymes8 = mysql_fetch_array($mes8);
$a_mes8=$arraymes8['monto'];
$me9="SELECT * FROM mensualidad where id_c_p='9'";
$mes9=mysql_query($me9);
$arraymes9 = mysql_fetch_array($mes9);
$a_mes9=$arraymes9['monto'];
$me10="SELECT * FROM mensualidad where id_c_p='10'";
$mes10=mysql_query($me10);
$arraymes10 = mysql_fetch_array($mes10);
$a_mes10=$arraymes10['monto'];
$me11="SELECT * FROM mensualidad where id_c_p='11'";
$mes11=mysql_query($me11);
$arraymes11 = mysql_fetch_array($mes11);
$a_mes11=$arraymes11['monto'];
$me12="SELECT * FROM mensualidad where id_c_p='12'";
$mes12=mysql_query($me12);
$arraymes12 = mysql_fetch_array($mes12);
$a_mes12=$arraymes12['monto'];
function abono($abono,$a_mes1,$a_mes2,$a_mes3,$a_mes4,$a_mes5,$a_mes6,$a_mes7,$a_mes8,$a_mes9,$a_mes10,$a_mes11,$a_mes12,$ci_p,$banco,$n_comprobante,$forma_pago,$fecha,$efectivo,$array_nuevo,$pago_mes)
{
$mes=0;
$respuesta='';
while($abono!==0)
{
$mes=$mes+1;
switch($mes)
{
case 1:$resta=$a_mes1-$abono; $restaM=$a_mes1.''.$arraymes['id_c_p'];break;
case 2:$resta=$a_mes2-$abono; $restaM=$a_mes2.''.$arraymes['id_c_p'];break;
case 3:$resta=$a_mes3-$abono; $restaM=$a_mes3.''.$arraymes['id_c_p'];break;
case 4:$resta=$a_mes4-$abono; $restaM=$a_mes4.''.$arraymes['id_c_p'];break;
case 5:$resta=$a_mes5-$abono; $restaM=$a_mes5.''.$arraymes['id_c_p'];break;
case 6:$resta=$a_mes6-$abono; $restaM=$a_mes6.''.$arraymes['id_c_p'];break;
case 7:$resta=$a_mes7-$abono; $restaM=$a_mes7.''.$arraymes['id_c_p'];break;
case 8:$resta=$a_mes8-$abono; $restaM=$a_mes8.''.$arraymes['id_c_p'];break;
case 9:$resta=$a_mes9-$abono; $restaM=$a_mes9.''.$arraymes['id_c_p'];break;
case 10:$resta=$a_mes10-$abono; $restaM=$a_mes10.''.$arraymes['id_c_p'];break;
case 11:$resta=$a_mes11-$abono; $restaM=$a_mes11.''.$arraymes['id_c_p'];break;
case 12:$resta=$a_mes12-$abono; $restaM=$a_mes12.''.$arraymes['id_c_p'];break;
default:$abono=0; break;
}
if($abono>$restaM){
/*$bus_a="SELECT * FROM capital where id_c_p='$mes' ";
$busq=mysql_query($bus_a);
$busq_a=mysql_fetch_array($busq);
$res_bus=$busq_a['abono'];*/
$bus="SELECT * FROM mensualidad where id_c_p='$array_nuevo' ";
$mes_bus=mysql_query($bus);
$mes_i=mysql_fetch_array($mes_bus);
$mes_id=$mes_i['monto'];
$res_bus-$mes_id=$resta1;
$resta_db=abs($resta1)-$abono;
$general='SI';
$respuesta='<br>'.$respuesta.'mes '.$mes.' PAGADO<br>';
$sql="INSERT INTO `capital`(`id_c_pp`,`id_propietario`, `id_c_p`, `id_servicio`, `abono`,`forma_pago`, `efectivo`, `banco`, `comprobante`, `cancelado`, `fecha_pago`)
VALUES ('','$ci_p','".$mes."','','".abs($resta_db)."','$forma_pago','$efectivo','$banco','$n_comprobante','$general','".date("y-m-d")."')";
$sq=mysql_query($sql);
}
else
{
$general='NO';
$respuesta='<br>'.$respuesta.'mes '.$mes.' MOROSO<br>';
$sql="INSERT INTO `capital`(`id_c_pp`,`id_propietario`, `id_c_p`, `id_servicio`, `abono`,`forma_pago`, `efectivo`, `banco`, `comprobante`, `cancelado`, `fecha_pago`)
VALUES ('','$ci_p','".$mes."','','".$abono."','$forma_pago','$efectivo','$banco','$n_comprobante','$general','".date("y-m-d")."')";
$sq=mysql_query($sql);
}
if($general==='NO'){$abono=0;}else{$abono=$abono-$restaM;}
}//while
if($sq==1){
return $respuesta=$respuesta."<br>Registro Exitoso.!!";
}
else
{
return $respuesta= "Fallo El Registro de los Datos...".mysql_error();
}
}//funcion fin
?>
Espero sus respuestas. Estoy desesperado :(
Valora esta pregunta


0