~marcelo-escobal/geined/Alianza

« back to all changes in this revision

Viewing changes to bol.php

  • Committer: Cualquier Desarrollador
  • Date: 2010-01-29 21:15:22 UTC
  • Revision ID: desarrollo@marte-20100129211522-u97qh9o90mhdap04
Importación inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* BOLETAS */
 
3
include('funciones.php');
 
4
include('datos.php');
 
5
function listado(){
 
6
    encabezado('Listado de boletas');
 
7
    boton("Eliminar boletas vacías","bol.php?accion=limpiar");
 
8
    boton("Volver",'alianza.py?accion=recepcion');
 
9
    $sql1='select * from bol_cont ORDER BY id DESC';
 
10
    $res1 = mysql_query($sql1);    
 
11
    encabezado_tabla(array("Nº","Caja Nº","Fecha","Cliente","Total","Acciones"));
 
12
    $i=0;
 
13
    while ($fil1 = mysql_fetch_array($res1)){
 
14
        fila_alterna($i);
 
15
        $id = $fil1['id'];
 
16
        celda($id);
 
17
        celda($fil1['caja_id']);
 
18
        celda(mysql_a_fecha($fil1['fecha']));
 
19
        $fil_cli = buscar_registro("clientes","id",$fil1['cliente_id']);
 
20
        celda($fil_cli['nombre']);
 
21
        linea_moneda($fil1['total']);
 
22
        echo '<td>';
 
23
        boton("Detalles","bol.php?accion=detalles&id=$id");
 
24
        boton("Imprimir","bol.php?accion=imprimir&id=$id");
 
25
        //boton("Borrar",'cli.php?accion=confirmar&id=' .$fil1['id']);
 
26
        echo '</td></tr>';
 
27
        $i = $i +1 ;
 
28
    }
 
29
    fin_tabla();
 
30
    boton("Volver",'alianza.py?accion=recepcion');
 
31
    fin();
 
32
}
 
33
function imprimir(){
 
34
    $boleta_id = $_GET['id'];
 
35
    $fil_bol = buscar_registro("bol_cont","id",$boleta_id);
 
36
    $caja_id = $fil_bol['caja_id'];
 
37
    $fil_caj = buscar_registro("cajas","id",$caja_id);
 
38
    $deposito_id = $fil_caj['deposito_id'];
 
39
    $cliente_id = $fil_bol['cliente_id'];
 
40
    $cola = "deposito_id=$deposito_id&caja_id=$caja_id&cliente_id=$cliente_id&boleta_id=$boleta_id";
 
41
    /* ----------------------------------------- */
 
42
    $fecha = mysql_a_fecha($fil_bol['fecha']);
 
43
    $fil_cli = buscar_registro("clientes","id",$cliente_id);
 
44
    $nombre = $fil_cli['nombre'];
 
45
    $direccion = $fil_cli['direccion'];
 
46
    encabezado_boleta();
 
47
    $lin = str_repeat(' ',90);
 
48
    for($i=0;$i<=70;$i++){
 
49
        $hoja[$i]=$lin;
 
50
    }
 
51
    $desp = 40;
 
52
    $hoja[0]=substr_replace($hoja[0],$fecha,80);
 
53
    $hoja[0+$desp]=substr_replace($hoja[0+$desp],$fecha,80);
 
54
    $hoja[3]=substr_replace($hoja[3],$nombre,20);
 
55
    $hoja[3+$desp]=substr_replace($hoja[3+$desp],$nombre,20);
 
56
    $hoja[5]=substr_replace($hoja[5],$direccion,20);
 
57
    $hoja[5+$desp]=substr_replace($hoja[5+$desp],$direccion,20);
 
58
    $sql_det = "SELECT * FROM bol_det WHERE bol_cont_id='$boleta_id'";
 
59
    $res_det = mysql_query($sql_det);
 
60
    $hoja[8] = substr_replace($hoja[8],"Cantidad",4,8);
 
61
    $hoja[8] = substr_replace($hoja[8],"Detalle",13,7);
 
62
    $hoja[8] = substr_replace($hoja[8],"Precio",79-6,6);
 
63
    $hoja[8] = substr_replace($hoja[8],"Total",95-5,5);
 
64
    $hoja[8+$desp] = substr_replace($hoja[8+$desp],"Cantidad",4,8);
 
65
    $hoja[8+$desp] = substr_replace($hoja[8+$desp],"Detalle",13,7);
 
66
    $hoja[8+$desp] = substr_replace($hoja[8+$desp],"Precio",79-6,6);
 
67
    $hoja[8+$desp] = substr_replace($hoja[8+$desp],"Total",95-5,5);
 
68
    $conta = 9;
 
69
    $totbol=0;
 
70
    while($fila = mysql_fetch_array($res_det)){
 
71
        $cantidad = trim($fila['cantidad']);
 
72
        $detalle = trim($fila['detalle']);
 
73
        $unitario = moneda($fila['unitario']);
 
74
        $total = moneda($fila['total']);
 
75
        if (strlen($detalle)>57) $detalle=substr($detalle,0,57);
 
76
        $hoja[$conta]= substr_replace($hoja[$conta],$cantidad,6,strlen($cantidad));
 
77
        $hoja[$conta]= substr_replace($hoja[$conta],$detalle,13,strlen($detalle));
 
78
        $hoja[$conta]= substr_replace($hoja[$conta],$unitario,80-strlen($unitario),strlen($unitario));
 
79
        $hoja[$conta]= substr_replace($hoja[$conta],$total,96-strlen($total),strlen($total));
 
80
        // Segunda hoja
 
81
        $hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$cantidad,6,strlen($cantidad));
 
82
        $hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$detalle,13,strlen($detalle));
 
83
        $hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$unitario,80-strlen($unitario),strlen($unitario));
 
84
        $hoja[$conta+$desp]= substr_replace($hoja[$conta+$desp],$total,96-strlen($total),strlen($total));
 
85
        // Total
 
86
        $totbol=$totbol + $fila['total'];
 
87
        $conta = $conta + 1;
 
88
    }
 
89
    $total_boleta = moneda($totbol);
 
90
    $hoja[19] = substr_replace($hoja[20],$total_boleta,96-strlen($total_boleta),strlen($total_boleta));
 
91
    $hoja[19+$desp] = substr_replace($hoja[20+$desp],$total_boleta,96-strlen($total_boleta),strlen($total_boleta));
 
92
    echo "<pre>";
 
93
    for($i=0;$i<=70;$i++){
 
94
        echo $hoja[$i]."</br>";
 
95
    }
 
96
    echo "</pre>"   ;
 
97
    boton("...","bol.php?accion=listado");
 
98
    fin();
 
99
}
 
100
function limpiar(){
 
101
    $sql_bol = "SELECT * FROM bol_cont";
 
102
    $res_bol = mysql_query($sql_bol);
 
103
    while($fila = mysql_fetch_array($res_bol)){
 
104
        $id = $fila['id'];
 
105
        $sql_mov = "SELECT COUNT(*) AS num FROM bol_det WHERE bol_cont_id='$id'";
 
106
        $res_mov = mysql_query($sql_mov);
 
107
        $fil_mov = mysql_fetch_array($res_mov);
 
108
        $num_fil = $fil_mov['num'];
 
109
        if($num_fil == 0){
 
110
            $sql_del = "DELETE FROM bol_cont WHERE id='$id'";
 
111
            $res = mysql_query($sql_del);
 
112
        }
 
113
    }
 
114
    redirigir("bol.php?accion=listado");
 
115
}
 
116
function detalles(){
 
117
    $bol_id = $_GET['id'];
 
118
    encabezado("Detalles de boleta Nº: $bol_id");
 
119
    boton("Volver","bol.php?accion=listado");
 
120
    $fil_bol = buscar_registro("bol_cont","id",$bol_id);
 
121
    $fil_cli = buscar_registro("clientes","id",$fil_bol['cliente_id']);
 
122
    echo '<table><tr><td>';
 
123
    echo 'Nombre: '.$fil_cli['nombre'];
 
124
    echo '</td></tr><tr><td>';
 
125
    echo 'Direccion: '.$fil_cli['direccion'];
 
126
    echo '</td></tr></table>';
 
127
    $sql_mov = "SELECT * FROM bol_det WHERE bol_cont_id ='$bol_id'";
 
128
    $res_mov = mysql_query($sql_mov);
 
129
    $i=0;
 
130
    encabezado_tabla(array("Nº","Cantidad","Detalle","Unitario","Total","Rubro"));
 
131
    while($fil_mov = mysql_fetch_array($res_mov)){
 
132
        fila_alterna($i);
 
133
        celda($fil_mov['id']);
 
134
        celda($fil_mov['cantidad']);
 
135
        celda($fil_mov['detalle']);
 
136
        celda($fil_mov['unitario']);
 
137
        celda($fil_mov['total']);
 
138
        celda($fil_mov['rubro']);
 
139
        $i = $i +1;
 
140
    }
 
141
    fin_tabla();
 
142
    boton("Volver","bol.php?accion=listado");
 
143
    fin();
 
144
}
 
145
autorizacion(5);
 
146
if (!$_GET['accion']) $accion='listado';
 
147
else $accion=$_GET['accion'];
 
148
switch($accion){
 
149
    case 'listado':
 
150
        listado();
 
151
        break;
 
152
    case 'editar':
 
153
        editar();
 
154
        break;
 
155
    case 'actualizar':
 
156
        actualizar();
 
157
        break;
 
158
    case 'imprimir':
 
159
        imprimir();
 
160
        break;
 
161
    case 'detalles':
 
162
        detalles();
 
163
        break;
 
164
    case 'limpiar':
 
165
        limpiar();
 
166
    case 'confirmar':
 
167
        confirmar_borrar($_GET['id'],'bol.php');
 
168
        boton("Volver",'bol.php?accion=listado');
 
169
        break;
 
170
    case 'eliminar':
 
171
        borrar('bol_cont',$_POST['id'],'bol.php?accion=listado');
 
172
        /* @annotation TODO: al eliminar boleta, eliminar sus movimientos */
 
173
        break;
 
174
}
 
175
?>
 
176