/
class.documento.php
executable file
·1333 lines (1093 loc) · 38.8 KB
/
class.documento.php
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
class Documento{
var $_id;
var $_codigo;
var $_tipo;
var $_numero;
var $_referencia;
var $_anexo;
var $_numero_folio;
var $_fecha;
var $_fecha_registro;
var $_asunto;
var $_observacion;
var $_prioridad;
var $_destino;
var $_remitente;
var $_estado;
var $_historial;
var $_historiala;
var $_borradores_respuesta;
var $_escaneos;
function Documento($id = 0 ){
$this->_id = $id;
if( $this->_id > 0 ){
$sql = "SELECT * FROM documentos WHERE id_documento = '".$this->_id."'";
$query = new Consulta($sql);
if($query->NumeroRegistros()){
$row = $query->VerRegistro();
$this->_codigo = $row['codigo_documento'];
$this->_tipo = new TipoDocumento($row['id_tipo_documento']);
$this->_remitente = new Remitente($row['id_remitente']);
$this->_estado = new Estado($row['id_estado']);
$this->_prioridad = new Prioridad($row['id_prioridad']);
$this->_numero = $row['numero_documento'];
$this->_asunto = $row['asunto_documento'];
$this->_referencia = $row['referencia_documento'] ;
$this->_anexo = $row['anexo_documento'] ;
$this->_numero_folio = $row['numero_folio_documento'] ;
$this->_fecha = $row['fecha_documento'] ;
$this->_fecha_registro = $row['fecha_registro_documento'] ;
$this->_observacion= $row['observacion_documento'] ;
$this->_destino = $row['destino_documento'] ;
$sql_historial = "SELECT * FROM historial_documentos WHERE id_documento = '".$this->_id."' ";
$query_historial = new Consulta($sql_historial);
while($rowh = $query_historial->VerRegistro()){
$this->_historial[] = array(
'id' => $rowh['id_historial_documento'],
'area' => new Area($rowh['id_area']),
'destino' => new Usuario($rowh['id_usuario_destino']),
'fecha' => $rowh['fecha_historial_documento'] ,
'original' => $rowh['original_historial_documento'] ,
'accion' => new Accion($rowh['id_accion']) ,
'estado' => new Estado($rowh['id_estado']),
'observacion' => $rowh['observacion_historial_documento'],
'usuario' => new Usuario($rowh['id_usuario'])
);
}
$sql_ahistorial = "SELECT * FROM historial_atencion WHERE id_documento = '".$this->_id."' ";
$query_ahistorial = new Consulta($sql_ahistorial);
while($rowha = $query_ahistorial->VerRegistro()){
$this->_historiala[] = array(
'id' => $rowha['id_historial_atencion'],
'area' => new Area($rowha['id_area']),
'destino' => new Usuario($rowha['id_usuario_destino']),
'fecha' => date('d-m-Y H:i:s',strtotime($rowha['fecha_historial_atencion'])),
'original' => $rowha['original_historial_atencion'] ,
'accion' => new Accion($rowha['id_accion']) ,
'estado' => new Estado($rowha['id_estado']),
'usuario' => new Usuario($rowha['id_usuario'])
);
}
$sql_br = "SELECT * FROM borradores_respuesta WHERE id_documento = '".$this->_id."' ";
$query_br = new Consulta($sql_br);
while($rowbr = $query_br->VerRegistro()){
$this->_borradores_respuesta[] = array(
'id' => $rowbr['id_borrador_respuesta'],
'fecha' => $rowbr['fecha_borrador_respuesta'] ,
'aprobacion'=> $rowbr['aprobacion_borrador_respuesta'] ,
'fecha' => $rowbr['vobo_borrador_respuesta'] ,
'descripcion'=> $rowbr['descripcion_borrador_respuesta'] ,
'usuario' => new Usuario($rowbr['id_usuario'])
);
}
$sql_de = "SELECT * FROM documentos_escaneados WHERE id_documento = '".$this->_id."' ";
$query_de = new Consulta($sql_de);
while($rowde = $query_de->VerRegistro()){
$this->_escaneos[] = array(
'id' => $rowde['id_documento_escaneado'],
'nombre' => $rowde['nombre_documento_escaneado']
);
}
}
}
}
function getFechaRespuesta(){
$fecha_exacta = strtotime($this->_fecha_registro);
$tiempo_extra = ($this->_prioridad->getTiempoHorasRespuesta() * 3600);
$fecha_respuesta = date("d/m/Y H:i",$fecha_exacta + $tiempo_extra);
return $fecha_respuesta;
}
function setFechaRespuesta($horas){
$fecha_exacta = strtotime($this->_fecha_registro);
$tiempo_extra = ($horas * 3600);
$fecha_respuesta = date("d/m/Y H:i",$fecha_exacta + $tiempo_extra);
return $fecha_respuesta;
}
function getId(){
return $this->_id;
}
function getTipoDocumento(){
return $this->_tipo;
}
function getEscaneos(){
return $this->_escaneos;
}
function getPrioridad(){
return $this->_prioridad;
}
function getAccion(){
return $this->_accion;
}
function getEstado(){
return $this->_estado;
}
function getAsunto(){
return $this->_asunto;
}
function getNumero(){
return $this->_numero;
}
function getNumeroFolio(){
return $this->_numero_folio;
}
function getRemitente(){
return $this->_remitente;
}
function getHistorial(){
return $this->_historial;
}
function getHistorialAtencion(){
return $this->_historiala;
}
function getCodigo(){
return $this->_codigo;
}
function getReferencia(){
return $this->_referencia;
}
function getAnexo(){
return $this->_anexo;
}
function getFecha(){
return date('d/m/Y',strtotime($this->_fecha));
}
function getFechaRegistro(){
return date('d/m/Y',strtotime($this->_fecha_registro));
}
function getHoraRegistro(){
return date('H:i:s',strtotime($this->_fecha_registro));
}
function getFechaCompletaRegistro(){
return $this->_fecha_registro;
}
function getBorradoresRespuesta(){
return $this->_borradores_respuesta;
}
function getObservacion(){
return $this->_observacion;
}
function isOriginalCopia($original){
$return;
if( $original == 1){
$return = "Original";
}else{
$return = "Copia";
}
return $return;
}
function ActivarDocumento($usuario){
$sql = "INSERT INTO documentos_usuario VALUES( '".$this->_id."', '".$usuario->getId()."', '','".date('Y-m-d H:i:s')."')";
$query = new Consulta($sql);
}
function getAtencion($usuario, $id_documento){
if( $usuario->verificarDocumentoAtendido($id_documento) == TRUE ){
echo "Activado";
}else{
echo "<a href='".$_SERVER['PHP_SELF']."?opcion=activar&id=".$id_documento."'>Activar</a>";
}
}
function AprobarDocumento($com){
$a_destino = new Area($_SESSION['session'][5]);
$fecha_actual = time()-3600;
$fecha=date("Y-m-d H:i:s",$fecha_actual);
if($_REQUEST['accion']==35){
$estado=16;
$est="AA";
$esta="ARCHIVO APROBADO";
}else{
$estado=17;
$est="DRA";
$esta="DERIVACION APROBADA";
}
$sql_atencion ="INSERT INTO historial_atencion
VALUES('','','".$this->_id."',
'',
'".$_SESSION['session'][5]."',
'".$_SESSION['session'][5]."',
'".$fecha."',
'1',
'".$_REQUEST['accion']."',
'".$_SESSION['session'][0]."',
'".$estado."',
'$com','2')";
$query_atencion = new Consulta($sql_atencion);
$aten = $query_atencion->NuevoId();
//Para el id del reporte
$sqlrep = "SELECT id_documento_reporte as id
FROM documentos_reporte
WHERE id_documento=".$this->_id;
$qrep=new Consulta($sqlrep);
$rowrep=$qrep->VerRegistro();
$accion = new Accion($_REQUEST['accion']);
$u_origen = new Usuario($_SESSION['session'][0]);
$origen = $u_origen->getNombreCompleto();
$n_destino = $a_destino->getNombre();
$ubicacion = $a_destino->getAbreviatura();
//Para el reporte
$sha_r = "Insert INTO
movimientos values('',
'".$rowrep['id']."',
'".$aten."',
'".$origen."',
'".$n_destino."',
'".$accion->getNombre()."',
'1',
'".$u_origen->getLogin()."',
'$com',
'".$fecha."',
'".$esta."',
'".$ubicacion."',
'4')";
$qha_r =new Consulta($sha_r);
$s_mov="Update documentos_reporte SET
ubicacion='".$ubicacion."'
WHERE id_documento=".$this->_id;
$qact_mov=new Consulta($s_mov);
$this->actualizarEstado($estado);
return $aten;
}
function addTramitePendiente(){
$fecha_actual = time()-3600;
$fecha=date("Y-m-d H:i:s",$fecha_actual);
$sql_atencion ="INSERT INTO historial_atencion
VALUES('','','".$this->_id."',
'".$_REQUEST['user']."',
'".$_REQUEST['area']."',
'".$_REQUEST['area']."',
'".$fecha."',
'1',
'".$_REQUEST['accion']."',
'".$_REQUEST['user']."',
'18',
'".$_REQUEST['comentario']."','5')";
$query_atencion = new Consulta($sql_atencion);
$aten = $query_atencion->NuevoId();
//Para el id del reporte
$sqlrep = "SELECT id_documento_reporte as id
FROM documentos_reporte
WHERE id_documento=".$this->_id;
$qrep=new Consulta($sqlrep);
$rowrep=$qrep->VerRegistro();
$accion = new Accion($_REQUEST['accion']);
$u_origen = new Usuario($_REQUEST['user']);
$origen = $u_origen->getNombreCompleto();
$n_destino = $origen;
$a_destino = $u_origen->getArea();
$ubicacion = $a_destino->getAbreviatura()."-".$u_origen->getLogin();
$est="TP";
$esta="TRAMITE PENDIENTE";
//Para el reporte
$sha_r = "Insert INTO
movimientos values('',
'".$rowrep['id']."',
'".$aten."',
'".$origen."',
'".$n_destino."',
'".$accion->getNombre()."',
'1',
'".$u_origen->getLogin()."',
'".$_REQUEST['comentario']."',
'".$fecha."',
'".$esta."',
'".$ubicacion."',
'7')";
$qha_r =new Consulta($sha_r);
$this->actualizarEstado(18);
return $aten;
}
function addHistorialAtencion(){
$fecha_actual = time()-3600;
$fecha=date("Y-m-d H:i:s",$fecha_actual);
$a_destino = new Area($_REQUEST['area']);
$sql_atencion ="INSERT INTO historial_atencion
VALUES('','','".$this->_id."',
'".$a_destino->getIdResponsable()."',
'".$_REQUEST['area']."',
'".$_REQUEST['area']."',
'".$fecha."',
'".$_REQUEST['categoria']."',
'".$_REQUEST['accion']."',
'".$_REQUEST['user']."',
'".$_REQUEST['estado']."',
'".$_REQUEST['comentario']."','4')";
$query_atencion = new Consulta($sql_atencion);
$aten = $query_atencion->NuevoId();
//Para el id del reporte
$sqlrep = "SELECT id_documento_reporte as id
FROM documentos_reporte
WHERE id_documento=".$this->_id;
$qrep=new Consulta($sqlrep);
$rowrep=$qrep->VerRegistro();
$accion = new Accion($_REQUEST['accion']);
$u_origen = new Usuario($_REQUEST['user']);
$origen = $u_origen->getNombreCompleto();
$u_destino = new Usuario($a_destino->getIdResponsable());
$n_destino = $u_destino->getNombreCompleto();
$a_destino = $u_destino->getArea();
$ubicacion = $a_destino->getAbreviatura()."-".$u_destino->getLogin();
if($_REQUEST['estado']==14){
$est="AP";
$esta="ARCHIVO PROPUESTO";
}else{
$est="DRP";
$esta="DERIVACION PROPUESTA";
}
//Para el reporte
$sha_r = "Insert INTO
movimientos values('',
'".$rowrep['id']."',
'".$aten."',
'".$origen."',
'".$n_destino."',
'".$accion->getNombre()."',
'".$_REQUEST['categoria']."',
'".$u_origen->getLogin()."',
'".$_REQUEST['comentario']."',
'".$fecha."',
'".$esta."',
'".$ubicacion."',
'4')";
$qha_r =new Consulta($sha_r);
$s_mov="Update documentos_reporte SET
ubicacion='".$ubicacion."'
WHERE id_documento=".$this->_id;
$qact_mov=new Consulta($s_mov);
$this->actualizarEstado($_REQUEST['estado']);
return $aten;
}
function addHistorialBorrador(){
$fecha_actual = time()-3600;
$fecha=date("Y-m-d H:i:s",$fecha_actual);
$sql_borrador = "INSERT INTO borradores_respuesta
VALUES('','".$this->_id.
"','','".$_REQUEST['user'].
"','".$_REQUEST['usuario'].
"','".$_REQUEST['area']."','".
$_REQUEST['accion']."','".
$_REQUEST['categoria']."','".
$fecha."','".
$_REQUEST['comentario']."','','".
$_REQUEST['adicional']."')";
$query_borrador = new Consulta($sql_borrador);
$borr = $query_borrador->NuevoId();
//Para el id del reporte
$sqlrep = "SELECT id_documento_reporte as id
FROM documentos_reporte
WHERE id_documento=$this->_id";
$qrep=new Consulta($sqlrep);
$rowrep=$qrep->VerRegistro();
//Obtenermos el ultimo estado
$sql_e = "SELECT
m.estado AS estado
FROM
movimientos m
WHERE
m.id_documento_reporte = '".$rowrep['id']."' AND
m.categoria = '1'
ORDER BY
m.fecha_movimiento DESC
LIMIT 0, 1";
$query_e = new Consulta ($sql_e);
$row_e = $query_e->VerRegistro();
$accion = new Accion($_REQUEST['accion']);
$u_origen = new Usuario($_REQUEST['user']);
$origen = $u_origen->getNombreCompleto();
$u_destino = new Usuario($_REQUEST['usuario']);
$n_destino = $u_destino->getNombreCompleto();
$area_actual = $u_destino->getArea();
$ubicacion = $area_actual->getAbreviatura()."-".$u_destino->getLogin();
//if($_REQUEST['categoria']==1){
$est="B";
$esta="BORRADOR";
//}else{
//$est = $row_e['estado'];
//}
//Para el reporte
$sha_r = "Insert INTO
movimientos values('',
'".$rowrep['id']."',
'".$borr."',
'".$origen."',
'".$n_destino."',
'".$accion->getNombre()."',
'".$_REQUEST['categoria']."',
'".$u_origen->getLogin()."',
'".$_REQUEST['adicional']."',
'".$fecha."',
'".$esta."',
'".$ubicacion."',
'3')";
$qha_r =new Consulta($sha_r);
if($_REQUEST['categoria']==1){
$s_mov="Update documentos_reporte SET
ubicacion='".$ubicacion."'
WHERE id_documento=".$this->_id;
$qact_mov=new Consulta($s_mov);
$this->actualizarEstado(6);
}
//Destinatario, Asunto y referencia del documento
if($this->ExisteFinalizado()){
$sqlfin = "UPDATE documento_finalizado
SET asunto = '".$_REQUEST['asunto']."',
destinatario = '".$_REQUEST['destinatario']."',
cargo = '".$_REQUEST['cargo']."',
referencia = '".$_REQUEST['referencia']."'
WHERE id_documento=".$this->_id;
}else{
$sqlfin = "INSERT into documento_finalizado values
('',null,
$this->_id,'',
'".$_REQUEST['asunto']."',
'".$_REQUEST['referencia']."',
'".$_REQUEST['destinatario']."',
'".$_REQUEST['cargo']."',
null,
null)";
}
$qfin=new Consulta($sqlfin);
return $borr;
}
function ExisteFinalizado(){
$Sql = "SELECT
df.id_documento_finalizado
FROM
documento_finalizado AS df
WHERE
df.id_documento = ".$this->_id;
$query = new Consulta($Sql);
if($query->NumeroRegistros()==0){
return false;
}
else{
return true;
}
}
function deleteHistorialAtencion($id_historial){
$sql = "DELETE FROM historial_atencion where id_historial_atencion=".$id_historial;
$query = new Consulta($sql);
}
function deleteHistorialBorrador($id_historial){
//Solo le pudo llegar de despacho de area o de otro atencion de documentos
if($_REQUEST["tipo"]==3){
$sql2 = "DELETE FROM borradores_respuesta
where id_borrador_respuesta=".$id_historial;
$sst_r="DELETE FROM movimientos where id_historial='".$id_historial."'
AND tipo=3";
}else{
$sql2 = "DELETE FROM historial_atencion
where id_historial_atencion=".$id_historial;
$sst_r="DELETE FROM movimientos where id_historial='".$id_historial."'
AND tipo=2 OR tipo = 4";
}
$query2 = new Consulta($sql2);
$qt_r=new Consulta($sst_r);
$ultimo_estado = $this->UltimoEstadoMovimientos();
$this->ActualizaUbicacion();
$this->actualizarEstado($ultimo_estado);
}
function UltimoEstadoMovimientos(){
$sql = "SELECT
e.id_estado AS estado
FROM
movimientos AS m
Inner Join estados AS e ON m.estado = e.nombre_estado
WHERE
m.id_documento_reporte = ".$this->ObtenerIdReporte()." AND
m.categoria = '1'
ORDER BY
m.id_movimiento DESC
LIMIT 0, 1";
$query = new Consulta ($sql);
$row = $query->VerRegistro();
return $row["estado"];
}
function ActualizaUbicacion(){
$s_mov="Update documentos_reporte SET
ubicacion='".$this->UltimaUbicacionMovimientos()."'
WHERE id_documento=".$this->_id;
$qact_mov=new Consulta($s_mov);
}
function ActualizaUbicacionArchivo($ubicacion){
$s_mov="Update documentos_reporte SET
ubicacion='".$ubicacion."'
WHERE id_documento=".$this->_id;
$qact_mov=new Consulta($s_mov);
}
function UltimaUbicacionMovimientos(){
$sql = "SELECT
m.ubicacion AS ubicacion
FROM
movimientos AS m
WHERE
m.id_documento_reporte = ".$this->ObtenerIdReporte()." AND
m.categoria = '1'
ORDER BY
m.id_movimiento DESC
LIMIT 0, 1";
$query = new Consulta ($sql);
$row = $query->VerRegistro();
return $row["ubicacion"];
}
function UltimaUbicacionReporte(){
$sql = "SELECT
d.ubicacion AS ubicacion
FROM
documentos_reporte AS d
WHERE
d.id_documento_reporte = ".$this->ObtenerIdReporte();
$query = new Consulta ($sql);
$row = $query->VerRegistro();
return $row["ubicacion"];
}
function getNumeroBorradores(){
$sql = "SELECT * FROM borradores_respuesta WHERE id_documento = '".$this->_id."'";
$query = new Consulta($sql);
return $query->NumeroRegistros();
}
function getNumeroBorradoresOriginales(){
$sql = "SELECT * FROM borradores_respuesta WHERE id_documento = '".$this->_id."'
AND categoria = 1";
$query = new Consulta($sql);
return $query->NumeroRegistros();
}
function actualizarEstado($estado){
$fecha=date("Y-m-d H:i");
$sql3 = "Update documentos set id_estado=$estado where id_documento= ".$this->_id;
$sql_hist_doc = "Update historial_documentos set id_estado=$estado where id_documento = ".$this->_id;
$sql_hist_ate = "Update historial_atencion set id_estado=$estado where id_documento = ".$this->_id;
$c_estado = new Estado($estado);
$s_ma = "Update documentos_reporte SET estado='".$c_estado->getAbreviatura()."'
WHERE id_documento='".$this->_id."'";
$query3 = new Consulta($sql3);
$query4 = new Consulta($sql_hist_doc);
$query5 = new Consulta($sql_hist_ate);
$sma=new Consulta($s_ma);
}
function finalizarDocumento($id_borrador){
//borrador como elegido
$sql_borr = "Update borradores_respuesta
set aprobacion_respuesta_borrador = 1
where id_borrador_respuesta= ".$id_borrador;
//modificar documento
$sql_doc = "Update documentos set id_estado=12 where id_documento = ".$this->_id;
//modificar historial_documentos
$sql_hist_doc = "Update historial_documentos set id_estado=12 where id_documento = ".$this->_id;
//modificar historial_atencion
$sql_hist_ate = "Update historial_atencion set id_estado=12 where id_documento = ".$this->_id;
//Reportes documento
$sql_reporte = "UPDATE documentos_reporte set estado='F'
WHERE id_documento = ".$this->_id;
$query1 = new Consulta($sql_borr);
$query2 = new Consulta($sql_doc);
$query3 = new Consulta($sql_hist_doc);
$query4 = new Consulta($sql_hist_ate);
$query5 = new Consulta($sql_reporte);
}
function getHistorialBorradores($doc){
$sql_borradores = " SELECT
b.id_borrador_respuesta as id,
b.id_usuario as usuario,
b.id_destino as destino,
b.id_area as area,
b.id_accion as accion,
b.categoria as categoria,
b.fecha_borrador_respuesta as fecha,
b.descripcion_borrador_respuesta as respuesta
FROM
borradores_respuesta AS b
WHERE
b.id_documento = $doc
order by fecha";
$query_borradores = new Consulta($sql_borradores);
while($rowha = $query_borradores->VerRegistro()){
$historial_b[] = array(
'id' => $rowha['id'],
'usuario' => new Usuario($rowha['usuario']),
'destino' => new Usuario($rowha['destino']),
'area' => new Area($rowha['area']),
'accion' => new Accion($rowha['accion']),
'original' => $rowha['categoria'] ,
'fecha' => date('d-m-Y H:i:s',strtotime($rowha['fecha'])),
'respuesta' => $rowha['respuesta']
);
}
return $historial_b;
}
function getHistorialHastaBorradores($doc){
$sql_base = "SELECT
ha.id_historial_atencion AS id,
ha.id_usuario AS usuario,
ha.id_area AS area,
ha.id_usuario_destino AS destino,
ha.id_area_destino AS area_destino,
ha.observacion_historial_atencion AS observacion,
ha.fecha_historial_atencion AS fecha,
ha.original_historial_atencion AS categoria,
ha.id_accion AS accion,
ha.tipo_historial_atencion AS tipo
FROM
historial_atencion AS ha
WHERE
ha.id_documento = '$doc' AND
((ha.id_usuario_destino = '".$_SESSION['session'][0]."' AND ha.tipo_historial_atencion = '0') OR
(ha.tipo_historial_atencion > '1' AND ha.id_area_destino = '".$_SESSION['session'][5]."'))";
$query_base = new Consulta($sql_base);
while($rowhb = $query_base->VerRegistro()){
$historial_b[] = array(
'id' => $rowha['id'],
'usuario' => new Usuario($rowhb['usuario']),
'area' => new Area($rowhb['area']),
'destino' => new Usuario($rowhb['destino']),
'area_destino' => new Area($rowhb['area_destino']),
'observacion' => $rowhb['observacion'],
'accion' => new Accion($rowhb['accion']),
'original' => $rowhb['categoria'] ,
'fecha' => date('d-m-Y H:i:s',strtotime($rowhb['fecha'])),
'tipo' => $rowhb['tipo']
);
}
return $historial_b;
}
function getHistorialAtencionDocumentos(){
$sql= " SELECT
hd.id_historial_documento AS id,
'6' AS tipo,
null AS usuario,
null AS area,
null AS destino,
hd.id_area AS area_destino,
hd.id_accion AS accion,
hd.original_historial_documento AS categoria,
null AS observacion,
hd.observacion_historial_documento AS comentario,
DATE_FORMAT(hd.fecha_historial_documento, '%Y-%m-%d %H:%i') AS fecha
FROM
historial_documentos AS hd
WHERE
hd.id_documento = $this->_id
UNION
SELECT
ha.id_historial_atencion AS id,
ha.tipo_historial_atencion AS tipo,
ha.id_usuario AS usuario,
ha.id_area AS area,
ha.id_usuario_destino AS destino,
ha.id_area_destino AS area_destino,
ha.id_accion AS accion,
ha.original_historial_atencion AS categoria,
null AS observacion,
ha.observacion_historial_atencion AS comentario,
DATE_FORMAT(ha.fecha_historial_atencion, '%Y-%m-%d %H:%i') AS fecha
FROM
historial_atencion AS ha
WHERE
ha.id_documento = $this->_id AND
(ha.tipo_historial_atencion = 0 OR ha.tipo_historial_atencion = 1
OR ha.tipo_historial_atencion = 2 OR ha.tipo_historial_atencion = 4)
UNION
SELECT
b.id_borrador_respuesta AS id,
3 AS tipo,
b.id_usuario AS usuario,
b.id_area AS area,
b.id_destino AS destino,
null AS area_destino,
b.id_accion AS accion,
b.categoria AS categoria,
b.descripcion_borrador_respuesta AS observacion,
b.comentario_adicional AS comentario,
DATE_FORMAT(b.fecha_borrador_respuesta, '%Y-%m-%d %H:%i') AS fecha
FROM
borradores_respuesta AS b
WHERE
b.id_documento = $this->_id
UNION
SELECT
d.id_devuelto AS id,
'7' AS tipo,
d.id_usuario AS usuario,
d.id_area AS area,
null AS destino,
null AS area_destino,
null AS accion,
'1' AS categoria,
null AS observacion,
d.descripcion AS comentario,
DATE_FORMAT(d.fecha_devolucion, '%Y-%m-%d %H:%i') AS fecha
FROM
devuelto AS d
WHERE
d.id_documento = $this->_id
ORDER BY
fecha ASC,
categoria ASC";
$query = new Consulta($sql);
while($rowhb = $query->VerRegistro()){
$historial[] = array(
'id' => $rowhb['id'],
'usuario' => new Usuario($rowhb['usuario']),
'area' => new Area($rowhb['area']),
'destino' => new Usuario($rowhb['destino']),
'area_destino' => new Area($rowhb['area_destino']),
'observacion' => $rowhb['observacion'],
'comentario' => $rowhb['comentario'],
'accion' => new Accion($rowhb['accion']),
'original' => $rowhb['categoria'] ,
'fecha' => date('d-m-Y H:i',strtotime($rowhb['fecha'])),
'tipo' => $rowhb['tipo']
);
}
return $historial;
}
function obtenerBorradoresEscaneados($borr){
$sql = "SELECT a.nombre_archivo
FROM
borrador_escaneado AS a
WHERE a.id_borrador_respuesta =".$borr;
$query_sql=new Consulta($sql);
$borrador = array();
$index = 0;
while($row = $query_sql->ConsultaVerRegistro()){
$borrador[$index++] = $row['nombre_archivo'];
}
return $borrador;
}
function obtenerJustificacionesEscaneadas($hist){
$sql = "SELECT a.nombre_archivo
FROM
justificado_escaneado AS a
WHERE a.id_historial_atencion=".$hist;
$query_sql=new Consulta($sql);
$archivo = array();
$index=0;
while($row = $query_sql->ConsultaVerRegistro()){
$archivo[$index++] = $row['nombre_archivo'];
}
return $archivo;
}
function TengoElBorradorOriginal($usu){
$sql = "SELECT
id_destino AS destino,
b.fecha_borrador_respuesta
FROM
borradores_respuesta AS b
WHERE
b.id_documento = '".$this->_id."' AND
b.categoria = '1'
ORDER BY
b.fecha_borrador_respuesta DESC
LIMIT 1";
$query_sql=new Consulta($sql);
$row=$query_sql->VerRegistro();
if($row["destino"]==$usu)
return true;
else
return false;
}
function TengoElDocDAOriginal($usu){
$sql = "SELECT
ha.id_usuario_destino
FROM
historial_atencion AS ha
WHERE
ha.id_documento = '".$this->_id."' AND
ha.original_historial_atencion = '1'
ORDER BY
ha.id_historial_atencion DESC
LIMIT 1";
$query_sql=new Consulta($sql);
$row=$query_sql->VerRegistro();
if($row["id_usuario_destino"]==$usu)
return true;
else
return false;
}
function DespachoAreaTieneOriginal(){
$sql = "SELECT
ha.id_area_destino AS destino,
ha.fecha_historial_atencion AS fecha
FROM
historial_atencion AS ha
WHERE
ha.id_documento = '".$this->_id."' AND
ha.original_historial_atencion = '1'
UNION
SELECT