2
include('funciones.php');
5
/*! Listado de boletas contado */
6
/* Entrada: deposito_id, cliente_id */
7
$deposito_id = $_GET['deposito_id'];
8
$caja_id = $_GET['caja_id'];
9
$cliente_id = $_GET['cliente_id'];
10
$boleta_id = $_GET['boleta_id'];
11
$cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id&boleta_id=$boleta_id";
12
/* ----------------------------------------- */
13
$fil_dep = buscar_registro("depositos","id",$deposito_id);
14
$sucursal = $fil_dep['deposito'];
15
encabezado("Alianza $sucursal: boleta contado");
17
$fil_bol = buscar_registro("bol_cont","id",$boleta_id);
18
$fil_cli = buscar_registro("clientes","id",$cliente_id);
19
$nombre = $fil_cli['nombre'];
20
$direccion = $fil_cli['direccion'];
21
echo '<table><tr><td>';
22
/* Datos del cliente */
23
echo '<table><tbody><tr><td>Fecha:</td><td align="right">';
25
echo "</td></tr><tr><td>Nombre:</td><td>$nombre</td></tr><tr><td>Domicilio:</td><td>$domicilio</td></tr></tbody></table>";
28
boton("Cuota","bolcuo.php?accion=cuota&id&$cola");
29
boton("Libros","bollib.php?accion=editar&$cola");
30
boton("Recargos","bolrec.php?accion=editar&$cola");
31
boton("Matricula","bolmat.php?accion=editar&$cola");
32
//boton("Módulo","bolmod.php?accion=editar&$cola");
33
//boton("Imprimir","bolcon.php?accion=imprimir&$cola");
34
boton("Volver","bolcon.php?accion=cancelar&$cola");
35
/* si salgo de la boleta, no se graba eliminar toda la boleta y sus movimientos */
36
echo '</td></tr></table>';
37
/* Listado de movimientos */
38
encabezado_tabla(array("Cantidad","Detalle","P.Unitario","Total","Acciones"));
39
$sql_det = "SELECT * FROM bol_det WHERE bol_cont_id='$boleta_id'";
40
$res_det = mysql_query($sql_det);
42
while ($fil = mysql_fetch_array($res_det)){
44
celda($fil['cantidad']);
45
celda($fil['detalle']);
46
linea_moneda($fil['unitario']);
47
linea_moneda($fil['total']);
48
$total = $total + $fil['total'];
50
boton("Editar","bolcon?accion=editar");
51
boton("Borrar","bolcon?accion=borrar");
55
/* rutina de verificación para que no se guarde si no pagó está en el javascript*/
56
$formac = "bolcon.php?accion=guardar&$cola";
57
echo '<form id="bol" name="bol" action="'.$formac.'" method="POST">';
58
echo "<input type='hidden' id='cola' value='$cola'>";
59
echo '<h2>TOTAL: $<input type="text" id="to" name="total" value="'.$total.'" readonly="1" /></h2>';
60
echo '<h3>Forma de pago</h3>';
61
echo '<table><tbody><tr><td>Efectivo</td><td>Cheques</td><td>Vouchers</td><td>Otros</td></tr>';
63
echo '<td align="right"><input align="right" type="text" id="ef" name="efectivo" value="0" onchange="recalcular('."'ef'".');"></td>';
64
echo '<td align="right"><input align="right" type="text" id="ch" name="cheques" value="0" onchange="recalcular('."'ch'".');"></td>';
65
echo '<td align="right"><input align="right" type="text" id="vo" name="vouchers" value="0" onchange="recalcular('."'vo'".');"></td>';
66
echo '<td align="right"><input align="right" type="text" id="ot" name="otros" value="0" onchange="recalcular('."'ot'".');"></td>';
69
echo '<table><tbody><tr><td>Vuelto:</td><td><h3>$<input type="text" id="vu" name="vu" value="'.$vuelto.'" readonly="1" /></h3></td></tr>';
71
echo '<span id="boton"></td><tr></span>';
73
echo '<script type="text/javascript">
74
function recalcular(campo){
75
var caracteresPermitidos ="0123456789.,-";
76
var ef=0; var ch=0; var vo=0; var ot=0;var total=0;
77
ef = parseFloat(document.getElementById("ef").value);
78
ch = parseFloat(document.getElementById("ch").value);
79
vo = parseFloat(document.getElementById("vo").value);
80
ot = parseFloat(document.getElementById("ot").value);
81
pago = ef + ch + vo + ot;
82
total = parseFloat(document.getElementById("to").value);
84
var str = document.getElementById(campo).value;
86
for(index=0;index<str.length;index++){
87
myChar = str.charAt(index);
88
if(caracteresPermitidos.indexOf(myChar)==-1){
93
alert("Hay letras en los campos numericos");
97
document.getElementById("boton").innerHTML = "";
99
document.getElementById("boton").innerHTML =
100
"<input type='."'submit'"." value="."'Aceptar'".'>
101
<input type='."'button'"." value="."'Imprimir'"."onClick=parent.location="."'bolcon.php?accion=imprimir&".$cola."'>".';
103
document.getElementById("vu").value = vuelto;
109
$deposito_id = $_GET['deposito_id'];
110
$caja_id = $_GET['caja_id'];
111
$cliente_id = $_GET['cliente_id'];
112
$boleta_id = $_GET['boleta_id'];
113
$cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id&boleta_id=$boleta_id";
114
/* ----------------------------------------- */
115
//si salgo de la boleta, borrar la boleta con todos los movimientos
116
// borrar los bol_det
117
$sql = "DELETE FROM bol_det WHERE bol_cont_id = '$boleta_id'";
118
$res = mysql_query($sql);
120
$sql = "DELETE FROM bol_cont WHERE id = '$boleta_id'";
121
$res = mysql_query($sql);
122
redirigir("caja_ver.php?accion=listado&$cola");
125
/* Entrada: deposito_id, cliente_id */
126
/* Viene de bolcon */
127
/* Actualiza datos de una boleta contado */
128
$deposito_id = $_GET['deposito_id'];
129
$caja_id = $_GET['caja_id'];
130
$cliente_id = $_GET['cliente_id'];
131
$boleta_id = $_GET['boleta_id'];
132
$cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id&boleta_id=$boleta_id";
133
/* campos: id caja_id fecha cliente_id efe che vou otr total flag */
134
$efectivo = $_POST['efectivo'];
135
$cheques = $_POST['cheques'];
136
$vouchers = $_POST['vouchers'];
137
$otros = $_POST['otros'];
138
$total = $_POST['total'];
139
$vuelto = $_POST['vu'];
140
$efectivo = $efectivo - $vuelto;
141
$fecha = fecha_a_mysql(date('d/m/Y'));
143
$fil_cli = buscar_registro("clientes","id",$cliente_id);
144
$nombre = $fil_cli['nombre'];
145
$detalle = "Boleta contado Nº interno: $boleta_id, $nombre";
146
$sql = "UPDATE bol_cont SET caja_id='$caja_id', fecha='$fecha',
147
cliente_id='$cliente_id', efectivo = '$efectivo', cheques='$cheques',
148
vouchers='$vouchers', otros='$otros', total='$total'
149
WHERE id='$boleta_id'";
150
$resultado = mysql_query($sql);
151
/* Guarda linea en caja del dia */
152
$sql = "INSERT INTO mov_caja SET caja_id ='$caja_id',
153
detalle = '$detalle', efectivo = '$efectivo',
154
cheques = '$cheques', vouchers = '$vouchers',
156
$result = mysql_query($sql) or die('SQL inválido: ' . mysql_error());
157
// Ciclar x movimientos para generar asientos y demás
158
$sql_mov = "SELECT * FROM bol_det WHERE bol_cont_id='$boleta_id'";
159
$res_mov = mysql_query($sql_mov);
161
while ($row = mysql_fetch_array($res_mov)){
162
// para cada mov_bol dentro de ese boleta
163
$monto = $row['total'];
164
$tot_mov = $tot_mov + $monto;
165
$rubro_haber = $row['rubro'];
166
$subrub = substr($rubro_haber,0,3);
167
$producto_id = $row['producto_id'];
168
$extra_id = $row['extra_id'];
170
$cantidad = $row['cantidad'];
171
// graba transaccion en otros como rubro $rubro_debe es la caja de origen
172
switch ($deposito_id){
174
$rubro_debe = 111018;
177
$rubro_debe = 111025;
180
$rubro_debe = 111026;
183
// pasar el monto a OTROS como rubro
184
asiento_doble($fecha,$detalle,$rubro_debe,$rubro_haber,$monto,$boleta_id);
185
// Genera movimientos específicos según el producto
186
switch($producto_id){
188
// el producto es una cuota
189
// asignar una cuota paga al alumno
190
// guardar linea en cuenta corriente del cliente
191
$detalle_cuota = $row['detalle'];
192
cta_cli_add($cliente_id,$detalle_cuota,0,$monto,$fecha);
193
// agregar al alumno la cuota paga
194
$fil_alu = buscar_registro("alumnos","id",$alumno_id);
195
$pagos = $fil_alu['pago'];
197
$alumno_id = $extra_id;
198
$sql_alu = "UPDATE alumnos SET pago='$pagos' WHERE id='$alumno_id'";
199
$res = mysql_query($sql_alu) or die("Error: ".mysql_error());
202
//El producto es un libro
203
// Para detectar existencias: biecam_id y deposito_id
204
// biecam_id es el extra_id
205
$biecam_id = $extra_id;
206
$sql_exi = "SELECT * FROM existencias WHERE deposito_id='$deposito_id' AND biecam_id='$biecam_id'";
207
$res_exi = mysql_query($sql_exi);
208
// OJO: es probable que no esté ingresado en existencias
209
if(mysql_num_rows($res_exi)==0){
210
// en ese caso tener previsto crear una línea en existencias
211
// Descontarlo del stock correspondiente en existencias
212
$cant_lib = -$cantidad;
213
// y asignarle una cantidad negativa al stock
214
// para que después se pueda corregir
215
$sql_ins = "INSERT INTO existencias SET biecam_id='$biecam_id',
216
deposito_id='$deposito_id', cantidad='$cant_lib'";
218
$fil_exi = mysql_fetch_array($res_exi);
219
$cant_lib = $fil_exi['cantidad'] - $cantidad;
220
$sql_ins = "UPDATE existencias SET biecam_id='$biecam_id',
221
deposito_id='$deposito_id', cantidad='$cant_lib'";
223
$res = mysql_query($sql_ins);
227
// despues de terminar el bucle, ciclar x transacciones con ese documento_id
228
/* al final del ciclo, sacar de otros y pasar a EF CH VO */
229
$rubro_otros = $rubro_debe;
230
switch ($deposito_id){
247
// Hacer que no se procesen asientos con cifra 0
250
asiento_doble($fecha,$detalle,$rubro_ef,$rubro_otros,$efectivo,$boleta_id);
254
asiento_doble($fecha,$detalle,$rubro_ch,$rubro_otros,$cheques,$boleta_id);
258
asiento_doble($fecha,$detalle,$rubro_vo,$rubro_otros,$vouchers,$boleta_id);
260
// No se toma en cuenta el rubro OTROS porque se supone que ya queda
261
redirigir("bolcon.php?accion=imprimir&$cola");
264
$fecha = fecha_a_mysql(date('d/m/Y'));
265
$deposito_id=$_GET['deposito_id'];
266
$caja_id = $_GET['caja_id'];
267
$cliente_id = $_GET['cliente_id'];
268
$cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id";
269
$sql_bol = "INSERT INTO bol_cont SET caja_id = '$caja_id', cliente_id='$cliente_id', fecha='$fecha'";
270
$result = mysql_query($sql_bol) or die('Invalid query: ' . mysql_error());
271
/* Ultimo registro insertado */
272
$boleta_id=mysql_insert_id();
273
redirigir("bolcon.php?accion=listado&boleta_id=$boleta_id&$cola");
275
function buscar_cliente(){
276
/* Entrada: caja_id, cliente_id, deposito_id */
277
$deposito_id=$_GET['deposito_id'];
278
$caja_id = $_GET['caja_id'];
279
$cola = "deposito_id=$deposito_id&caja_id=$caja_id";
280
encabezado("Buscar cliente (boleta contado)");
281
echo '<table><tr><td>';
282
boton("Volver","alianza.php?accion=recepcion&$cola");
284
formulario("bolcon.php?accion=buscar_cliente&$cola");
285
echo '<input type="text" name="busqueda">
286
<input type="submit" VALUE="Buscar"></form>';
287
echo '</td></tr></table>';
289
if ($_POST['busqueda']<>''){
290
$sql1='SELECT * from clientes where nombre like "%' .$_POST['busqueda'] .'%" order by nombre';
293
$sql1='select * from clientes order by nombre LIMIT 20';
295
$res1 = mysql_query($sql1);
297
echo 'Error ' . mysql_error();
300
encabezado_tabla(array("Nombre","Teléfono","eMail","Categoría","Acciones"));
301
for ($i = 0; $i < mysql_num_rows($res1); $i++){
303
$fil1 = mysql_fetch_array($res1);
304
celda($fil1['nombre']);
305
celda($fil1['telefono']);
306
celda($fil1['email']);
308
$sql2 = 'SELECT * FROM cat_clientes WHERE id="' . $fil1['categoria_id'] . '"';
309
$res2 = mysql_query($sql2);
314
$fil2 = mysql_fetch_array($res2);
315
$categoria=$fil2['categoria'];
319
$cliente_id = $fil1['id'];
320
boton("Seleccionar","bolcon.php?accion=nuevo&cliente_id=$cliente_id&$cola");
326
boton("Volver",'alianza.php?accion=recepcion');
329
function buscar_sucursal(){
330
encabezado("Caja: seleccionar sucursal");
331
boton("Central","bolcon.php?accion=listado&deposito_id=1");
332
boton("Costa de Oro","bolcon.php?accion=listado&deposito_id=2");
333
boton("Carrasco","bolcon.php?accion=listado&deposito_id=3");
334
boton("Volver","alianza.php?accion=recepcion");
338
$deposito_id = $_GET['deposito_id'];
339
$caja_id = $_GET['caja_id'];
340
$cliente_id = $_GET['cliente_id'];
341
$boleta_id = $_GET['boleta_id'];
342
$cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id&boleta_id=$boleta_id";
343
/* ----------------------------------------- */
344
$fil_bol = buscar_registro("bol_cont","id",$boleta_id);
345
$fecha = mysql_a_fecha($fil_bol['fecha']);
346
$cliente_id = $fil_bol['cliente_id'];
347
$fil_cli = buscar_registro("clientes","id",$cliente_id);
348
$nombre = $fil_cli['nombre'];
349
$direccion = $fil_cli['direccion'];
351
$lin = str_repeat(' ',90);
352
for($i=0;$i<=70;$i++){
356
$hoja[0]=substr_replace($hoja[0],$fecha,80);
357
$hoja[0+$desp]=substr_replace($hoja[0+$desp],$fecha,80);
358
$hoja[3]=substr_replace($hoja[3],$nombre,20);
359
$hoja[3+$desp]=substr_replace($hoja[3+$desp],$nombre,20);
360
$hoja[5]=substr_replace($hoja[5],$direccion,20);
361
$hoja[5+$desp]=substr_replace($hoja[5+$desp],$direccion,20);
362
$sql_det = "SELECT * FROM bol_det WHERE bol_cont_id='$boleta_id'";
363
$res_det = mysql_query($sql_det);
364
$hoja[8] = substr_replace($hoja[8],"Cantidad",4,8);
365
$hoja[8] = substr_replace($hoja[8],"Detalle",13,7);
366
$hoja[8] = substr_replace($hoja[8],"Precio",79-6,6);
367
$hoja[8] = substr_replace($hoja[8],"Total",95-5,5);
368
$hoja[8+$desp] = substr_replace($hoja[8+$desp],"Cantidad",4,8);
369
$hoja[8+$desp] = substr_replace($hoja[8+$desp],"Detalle",13,7);
370
$hoja[8+$desp] = substr_replace($hoja[8+$desp],"Precio",79-6,6);
371
$hoja[8+$desp] = substr_replace($hoja[8+$desp],"Total",95-5,5);
374
while($fila = mysql_fetch_array($res_det)){
375
$cantidad = trim($fila['cantidad']);
376
$detalle = trim($fila['detalle']);
377
$unitario = moneda($fila['unitario']);
378
$total = moneda($fila['total']);
379
if (strlen($detalle)>57) $detalle=substr($detalle,0,57);
380
$hoja[$conta]= substr_replace($hoja[$conta],$cantidad,6,strlen($cantidad));
381
$hoja[$conta]= substr_replace($hoja[$conta],$detalle,13,strlen($detalle));
382
$hoja[$conta]= substr_replace($hoja[$conta],$unitario,80-strlen($unitario),strlen($unitario));
383
$hoja[$conta]= substr_replace($hoja[$conta],$total,96-strlen($total),strlen($total));
385
$hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$cantidad,6,strlen($cantidad));
386
$hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$detalle,13,strlen($detalle));
387
$hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$unitario,80-strlen($unitario),strlen($unitario));
388
$hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$total,96-strlen($total),strlen($total));
390
$totbol=$totbol + $fila['total'];
393
$total_boleta = moneda($totbol);
394
$hoja[19] = substr_replace($hoja[20],$total_boleta,96-strlen($total_boleta),strlen($total_boleta));
395
$hoja[19+$desp] = substr_replace($hoja[20+$desp],$total_boleta,96-strlen($total_boleta),strlen($total_boleta));
396
/* Cargar linea desde archivo */
397
$pie_bol = 'pie_bol.txt';
398
$fh = fopen($pie_bol, 'r');
401
$hoja[22] = substr_replace($hoja[22],$linea,6,strlen($linea));
402
$hoja[22+$desp] = substr_replace($hoja[22+$desp],$linea,6,strlen($linea));
404
for($i=0;$i<=70;$i++){
405
echo $hoja[$i]."</br>";
408
//boton("IMPRIMIR","bolcon.php?accion=guardar&$cola");
409
echo '<script type="text/javascript">
412
redirigir("caja_ver.php?accion=listado&$cola");
413
//redirigir("bolcon.php?accion=guardar&$cola");
416
/* INICIO DE BUCLE PRINCIPAL */
418
if (!$_GET["accion"]){
422
$accion=$_GET["accion"];
424
if(!$_GET['deposito_id']){
425
//@annotation cambiar esto seleccionar_sucursal();
428
if(!$_GET['cliente_id']){
439
case 'buscar_cliente':