-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
256 lines (195 loc) · 7.18 KB
/
index.php
File metadata and controls
256 lines (195 loc) · 7.18 KB
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
<?php
require_once("funciones.php");
if(!permiso($perfil,"inicio")){
echo "Permisos insuficientes";
exit;
}
// CONFIRMAR REGISTRO DE ENTREGA
if( validar($_POST["confirmar-entrega"]) ) {
$id = validar($_POST["confirmar-entrega"]);
$sql="UPDATE movimientos_entregas set confirmado = NOW(),
user_confirma = '$userid'
where id = '$id' AND
user_salida = '$userid'; ";
$Result = mysqli_query($mysqli_link,$sql);
if(mysqli_affected_rows($mysqli_link)>0){
$mensajeok = "Registro confirmado correctamente<br>";
}else{
$mensaje = "Error confirmando registro";
}
}
// ELIMINAR REGISTRO ENTRADA/SALIDA
if( validar($_POST["eliminar-ingreso"]) ){
$id = validar($_POST["eliminar-ingreso"]);
$sql="DELETE from movimientos where id='$id' AND
confirmado is NULL AND
user_id='$userid' ";
$Result = mysqli_query($mysqli_link,$sql);
if(mysqli_affected_rows($mysqli_link)>0){
$mensajeok = "Registro eliminado correctamente<br>";
}else{
$mensaje = "Error eliminando registro";
}
}
// CONFIRMAR REGISTRO ENTRADA/SALIDA
if( validar($_POST["confirmar-ingreso"]) ){
$id = validar($_POST["confirmar-ingreso"]);
if($perfil>0){
// Admin
$sql="UPDATE movimientos set confirmado = NOW(),
user_confirma = '$userid'
where id = '$id' AND
IF(user_entrada = user_salida, user_id != $userid, 1); ";
}else{
// user
$sql="UPDATE movimientos set confirmado = NOW(),
user_confirma = '$userid'
where id = '$id' AND
user_id != '$userid' ";
}
$Result = mysqli_query($mysqli_link,$sql);
if(mysqli_affected_rows($mysqli_link)>0){
$mensajeok = "Registro confirmado correctamente<br>";
$sql = "select U.perfil,M.insumo_id,M.user_entrada,M.cantidad
from movimientos as M,
users as U
where M.id='$id' and
M.user_salida = U.id ";
$Result = mysqli_query($mysqli_link,$sql);
$Reg = mysqli_fetch_row($Result);
if( $Reg[0] == 1 or $Reg[0] == 2 or $Reg[0] == 3 ) {
// 1 = Zonal
// 2 = PERFIL administrador de stock
// 3 = reparto
// genero registro salida de insumo
$sql2 = "insert into movimientos_insumos (insumo_id,user_id,cantidad,comentario)
values ('".$Reg[1]."','".$Reg[2]."','-".$Reg[3]."','Salida de insumo')";
$Result2 = mysqli_query($mysqli_link,$sql2);
// descuento insumo del stok
$sql3 = "update insumos set cantidad = cantidad - ".$Reg[3]."
where id='".$Reg[1]."';";
$Result3 = mysqli_query($mysqli_link,$sql3);
$mensajeok.= "El insumo fue descontado del STOCK.";
}
}else{
$mensaje = "Error, no se puede confirmar el registro";
}
}
// AGREGA REGISTRO DE ENTRADA
if( validar($_POST["confirmar-entrada"]) ){
$remitente = validar($_POST["remitente"]);
$insumo = validar($_POST["insumo"]);
$unidades = validar($_POST["unidades"]);
$comentario = validar($_POST["comentario"]);
if( ($remitente == $userid) and $perfil < 1 ){
$mensaje = "Error: usuario origen y destino no pueden ser iguales";
}
if( floatval($unidades) == 0 ){
$mensaje = "Error: unidades debe ser mayor que cero";
}
if(!isset($mensaje)){
$sql = "INSERT into movimientos (user_id,user_entrada,user_salida,insumo_id,cantidad,confirmado,comentario)
values('$userid','$userid','$remitente','$insumo','$unidades',NULL,'$comentario') ";
$Result = mysqli_query($mysqli_link,$sql);
if($Result){
$mensajeok = "Datos registrados";
}else{
$mensaje = "Error: no fue posible registrar los datos";
}
}
}
// AGREGA REGISTRO DE SALIDA
if( $_POST["confirmar-salida"] ){
$destinatario = validar($_POST["destinatario"]);
$insumo = validar($_POST["insumo"]);
$unidades = validar($_POST["unidades"]);
$comentario = validar($_POST["comentario"]);
if( ($destinatario == $userid) and $perfil < 1 ){
$mensaje = "Error: usuario origen y destino no pueden ser iguales";
}
if( floatval($unidades) == 0 ){
$mensaje = "Error: unidades debe ser mayor que cero";
}
if(!isset($mensaje)){
$sql = "INSERT into movimientos (user_id,user_entrada,user_salida,insumo_id,cantidad,confirmado,comentario)
values('$userid','$destinatario','$userid','$insumo','$unidades',NULL,'$comentario') ";
$Result = mysqli_query($mysqli_link,$sql);
if($Result){
$mensajeok = "Datos registrados";
}else{
$mensaje = "Error: no fue posible registrar los datos";
}
}
}
Mostrar();
exit;
// *******************************************************************************
// *******************************************************************************
function mostrar(){
global $userid, $perfil;
global $mysqli_link;
global $googleEmail,$googleImage,$googleName;
global $mensajeok,$mensaje;
include("header.inc.php");
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<?php include("principal.php"); ?>
</div>
<!-- /.content-wrapper -->
<?php
include("footer.inc.php");
?>
<script src="AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
<script src="AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
<script src="AdminLTE/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="AdminLTE/plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="AdminLTE/plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="AdminLTE/plugins/pdfmake/pdfmake.min.js"></script>
<script src="AdminLTE/plugins/pdfmake/vfs_fonts.js"></script>
<script src="AdminLTE/plugins/jszip/jszip.min.js"></script>
<script>
$(function () {
$('#tableingresos').DataTable({
"ordering": true,
dom: 'Bftip',
/* buttons: [
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
*/
});
$('#tableegresos').DataTable({
"ordering": true,
dom: 'Bftip',
/* buttons: [
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
*/
});
});
$(document).ready(function(){
$(document).on('click', '.del-ingreso', function(){
var id = $(this).attr("id");
$('#eliminar-ingreso').val(id);
});
$(document).on('click', '.conf-ingreso', function(){
var id = $(this).attr("id");
$('#confirmar-ingreso').val(id);
});
$(document).on('click', '.conf-entrega', function(){
var id = $(this).attr("id");
$('#confirmar-entrega').val(id);
});
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
</script>
<?php
}
?>