Código de Oracle - Programacion en Oracle - Consulta Dinamica y Ordenada

1

Publicado el 11 de Marzo del 2020gráfica de visualizaciones de la versión: 1
1.810 visualizaciones desde el 11 de Marzo del 2020
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
CREATE OR REPLACE procedure SYSTEXTILRPT.SPGET_PCP_CNTRLAVANUP5_P(
    p_fecha_inicio        date        default null,
    p_fecha_fin           date        default null,
    p_pedido_inicio       number      default null,
    p_pedido_fin          number      default null,
    p_fecha_inicio_ficha  date        default null,
    p_fecha_fin_ficha     date        default null,
    p_ficha_inicio        number      default null,
    p_ficha_fin           number      default null,
    p_grupo_planea        varchar2    default null,
    p_codcancelamiento    number      default null,
    p_pedidoin            number      default null,
    --p_cancelado           int     default null,
  --  p_empresa             number      default null,
    pcursor out sys_refcursor)
-- *********************************************************
-- TMP
-- *********************************************************
is
    /*  Detalle:    CONTROL DE AVANCE UPDATE
        Versión:    001
        Autor:      GIAN CARLOS ALMEYDA AMORETTI
        Fecha:      25/07/2018
    */
    -- Declaramos variables por cada parámetro
    v_fecha_inicio          date            := to_date(p_fecha_inicio,'dd/mm/rrrr');
    v_fecha_fin             date            := to_date(p_fecha_fin,'dd/mm/rrrr');
    v_pedido_inicio         number          := p_pedido_inicio;
    v_pedido_fin            number          := p_pedido_fin;
    v_fecha_inicio_ficha    date            := to_date(p_fecha_inicio_ficha,'dd/mm/rrrr');
    v_fecha_fin_ficha       date            := to_date(p_fecha_fin_ficha,'dd/mm/rrrr');
    v_ficha_inicio          number          := p_ficha_inicio;
    v_ficah_fin             number          := p_ficha_fin;
    v_grupo_planea          varchar2(10)    := p_grupo_planea ;
    v_contador              number          := 0;
    v_bloquedo              number(1)       :=0;
 
   vpartida             varchar2(50):='';
   vfechaobjetivo       date := null;
   vdesctipprenda       varchar2(250):='';
   vcantprogramada      number;
   vcantxcortar         number;
   vccanrcant1era       number;
   vccanrcant2da        number;
   vccanrcant3era       number;
   vfechacorte          date;
   vfechacorte2         date;
   ving_corte_pda_incompleta number;
   vsal_corte_pda_incompleta number;
   vnumerado_1ra             number;
   vnumerado_2da             number;
   vnumerado_recuperacion    number;
   vnumerado_perdida         number;
   vfecha_de_lavado_de_panos    date;
   vstock_panos             number;
   vfecha_estampado_pieza    date;
   vstock_estampado_pieza   number;
   vfecha_bordado_pieza     date;
   vstock_bordado_pieza     number;
   vfecha_despacho_costura  date;
   vfecha_despacho_app      date;
   vfecha_retorno_a_chincha date;
   vstock_app_piezas        number;
   vmodulo_costura          varchar2(100);
   vcanti_estanteria        number;
   vlinea_costura           date;
   ving                     number;
   vstock_costura           number;
   vavance_sal_prenda_costura    number;
   vnombre_servicio         varchar2(200);
   vstock_servicio_lima     number;
   vstock_servicio          number;
   vfecha_ingr_app          date;
   vstock_appprendasc       number;
   vtransito_chincha        number;
   vtransito_lima           number;
   v_embolsado_r            number;
   v_encajado_r             number;
   v_embolsado_r_cant       number;
   v_encajado_r_cant        number;
  ---------AGREGADO 11/02/2020
   v_i_cant_conge_corte_r            number;
   v_i_stock_reestru_acab_r             number;
   v_i_stock_prepack_acab_r            number;
 
   v_i_cant_conge_corte_cant            number;
   v_i_stock_reestru_acab_cant        number;
   v_i_stock_prepack_acab_cant        number;
 ---------PARTE 1------------------------
 ---------------------------------
   vstock_app2_pza          number;
   vstock_app2_pda          number;
   vservicios_especiales    number;
 
 
   vfecha_ingr_bordado      date;
   vstock_bordado           number;
   vfecha_ingr_estampado    date;
   vstock_estampado          number;
   vfecha_ingr_lavanderia    date;
   vstock_lavanderia         number;
   vfecha_ingr_cost_final    date;
   vstock_cost_final         number;
   vfecha_ingr_transito_acabc    date;
   vingtransitoacabchin     number;
   v1 number;
   v2 number;
   v3 number;
   v4 number;
   vstock_transito_ch        number;
   vfecha_ingr_acabados_c    date;
   x1 number;
   x2 number;
   x3 number;
   vingreso_acabados_chin       number;
   vingreso_acabados_11_chin    number;
   y1 number;
   y2 number;
   vingreso_acabados_12_chin    number;
   b1 number;
   b2 number;
   vstock_acabados_primerasc    number;
   vstock_acabados_segundac     number;
   vstock_acabados_tercerasc    number;
   vstock_servicio_acabados_chin    number;
   vqtd_21055                   number;
   vlocalidad                   varchar2(200);
   vsrvacbchn_ih                number;
   vfecha_ingr_transito_acabl   date;
   c1   number;
   c2   number;
   vingtransitoacablim number;
   vstock_transito_lim number;
   vfecha_ingreso_acab_lim  date;
   a1   number;
   a2   number;
   a3   number;
   vingreso_acabados_lim        number;
   vingreso_acabados_38_lim     number;
   a4   number;
   a5   number;
   vingreso_acabados_39_lim     number;
   a6   number;
   a7   number;
   vstock_acabados_primerasl    number;
   vstock_acabados_segundal     number;
   vstock_acabados_tercerasl    number;
   vstock_servicio_lim          number;
 ---------PARTE 2------------------------
 ---------------------------------
 
   vingresoaptchinch            date;
   vstock1rasapt                number;
   vstock2dasapt                number;
   vstock3rasapt                number;
   vkg_prog                     number;
   vusuario_canc                varchar2(200);
   vtipo_pedido                 varchar2(200);
   vtipo_ficha                  varchar2(200);
   a8                           number;
   vestado_ruta                 varchar2(200);
   vstock_corte                 number;
   vstockreestru                number;
   v1rasaptfichas               number;
   v2dasaptfichas               number;
   v3rasaptfichas               number;
   vdespachocomercial           number;
   vsalidaxperdida              number;
   vexportado                   number;
   a9   number;
   a10  number;
   vcodcliente  number;
   vfechaex date;
   vi_cantidad_zonaprepack      number;
   vi_cantidad_cuarentena       number;
   vfechacorten                 date;
   vhoracorten                  varchar(20);
   vfechareal_corte_costura     date;
   vhorareal_corte_costura      varchar(20);
   vhoradespacho_corte_apppzas  varchar(20);
   vestatus_pedido              varchar(20);
 ---------PARTE 3------------------------
 ---------------------------------
   vf_despcort_costu             date; --1
   vq_despcort_costu             number; --2
   vf_devcostu_cort              date; --3
   vq_devcostu_cort              number; --4
   vq_netodespcort_costu         number; --5
 
   vf_despcort_apppza            date;--6
   vq_despcort_apppza            number;--7
   vf_devapppza_corte            date;--8
   vq_devapppza_corte            number;--9
   vq_netodespcorte_apppza       number;--10
 
   vf_despapppza_costuinhouse    date;--11
   vq_despapppza_costu_inhouse   number;--12
   vf_devcostuinhouse_apppza     date;--13
   vq_devcostuinhouse_apppza     number;--14
   vq_netodespapppza_costuinhouse number;--15
 
   ------------------PARTE 4----------------
   -----------------------------------------
 
   vf_desapppza_costext          date;    --16
   vq_depsapppza_costext         number;  --17
   vf_devcostext_apppza          date;    --18
   vq_devcostext_apppza          number;  --19
   vq_netodespapppza_costuext    number;  --20
 
   vf_despapppzachincha_apppzalim  date;   --21
   vq_despapppzachincha_apppzalim  number; --22
   vf_devapppzalima_apppzachincha   date;  --23
   vq_devapppzalima_apppzachincha   number;--24
   vq_netodespapppzachi_apppzalim   number;--25
 
   vf_despapppzalima_costplanlima   date;  --26
   vq_despapppzalima_costplanlima   number;--27
   vf_devcostplanlima_apppzalima    date;  --28
   vq_devcostplanlima_apppzalima    number;--29
   vq_netdespapppzali_costplanli    number;--30
 
   vf_despapppzali_costuinholim     date;  --31
   vq_despapppzali_costuinholi      number;--32
   vf_devcostuinholi_apppzali       date;  --33
   vq_devcostuinholi_apppzali       number;--34
   vq_netodespapppzali_costinholi   number;--35
 
   vf_despapppzalima_costuextlima   date;  --36
   vq_despapppzalima_costuextlima   number;--37
   vf_devcostuextlima_apppzalima    date;  --38
   vq_devcostuextlima_apppzalima    number;--39
   vq_netodespapppzali_costuextli   number;--40
 
   vq_ingresocostura                number;
   vubicacion                       varchar2(100);
 
   vtransito_corte_costura_lima     number;
   vcostura_lima                    number;
   vstock_srv_esta_lima             number;--- PRENDAS
   vcant_depurada                   number;
   vi_serv_corte_completo           number;
   vi_transito_corte_lima           number;
   vi_serv_corte_lima               number;
   vi_stock_fileteo                 number;
   vi_stock_lavado                  number;
   vi_slavpdalim                    number;
   vstraspdalim                     number;
   vi_servreprcost                  number;
   vi_servreprcostlma               number;
   vdt_fechacierre                  date;
   vi_kilosdesp                     number;
   vStock_Srv_Esta_Lima_Pza         number;
   vi_ajuste_ingcbo_ped             number;
   vi_ajuste_salcbo_ped             number;
   vi_ingxcbest                     number;
   vi_salxcbest                     number;
 
   ------
   vcant1   number;
   vcant2   number;
   vcant3   number;
 
   vcant4   number;
   vcant5   number;
   vcant6   number;
   vcant7   number;
   vcant8   number;
   vcant9   number;
 
   vcant10  number;
   vcant11  number;
   vcant12  number;
 
   VI_SALVTALOCAL number;
 
   --VARIABLES CONTADORES
   VCANTSLVTA NUMBER;
 
   -- AGREGADO
   v_SRVBORDADOPDALIM NUMBER;
 
begin
       begin
             declare
            nsql        clob;
            curingreso sys_refcursor;
 
            type inst is record
            (
             pedido                     number          default 0,
             data_emis_venda            date,
             data_entr_venda            date,
             pocliente                  varchar2(30)    ,
             cod_cliente                varchar2(50)    ,
             via                        varchar2(20)    ,
             cd_it_pe_nivel99           varchar2(2)    ,
             estilotsc                  varchar2(5)    ,
             ficha                      number,
             data_programacao           date,
             alternativa_prenda         number,
             ruta_prenda                number,
             codigo_color               varchar2(6)    ,
             descricolor                varchar2(250)    ,
             grupo_planeamiento         varchar2(10)    ,
             partida                    varchar2(20)    ,
             cliente                    varchar2(250)    ,
             destino                    varchar2(250)    ,
             estilo_cliente             varchar2(30)    ,
             descripcion_articulo       varchar2(250)    ,
             ruta                       varchar2(350)    ,
             codigo_tela                varchar2(150)    ,
             minutospremda_corte        number(9,4)    default 0,
             minutospremda_costura      number(9,4)    default 0,
             minutospremda_acabados     number(9,4)    default 0,
             narrativa                  varchar2(255)     ,
             fecha_anulacion            date ,
             mov_baja                   varchar2(255)     ,
             canticolores               number    default 0
            );
            type vinst is table of inst;
            vsx vinst;
 
        begin
 
        -- dinamic query
         nsql :='
                select
                             tbl.pedido_venda              ,tbl.data_emis_venda       ,tbl.data_entr_venda             ,tbl.cod_ped_cliente
                            ,tbl.cod_cliente               ,tbl.via                   ,tbl.cd_it_pe_nivel99            ,tbl.referencia_peca
                            ,tbl.ordem_producao            ,tbl.data_programacao      ,tbl.alternativa                 ,tbl.roterio
                            ,tbl.cod_color                 ,tbl.desc_color            ,tbl.grupo_planejamento          ,tbl.partida
                            ,tbl.nome_cliente              ,tbl.nome_pais             ,tbl.produto_cliente             ,tbl.descr_referencia
                            ,tbl.ruta                      ,tbl.codigo_tela           ,tbl.minutospremda_costura       ,tbl.minutospremda_corte
                            ,tbl.minutospremda_acabados    ,t2.narrativa              ,tbl.fecha_baja                  ,tbl.motivo_baja
                            ,tbl.cantidadcolores
                        from
                        (
                          select
                                t1.pedido_venda                  ,
                                t2.data_emis_venda               ,
                                t2.data_entr_venda               ,
                                t2.cod_ped_cliente,
                                t2.cli_ped_cgc_cli9 ||''.''||
                                t2.cli_ped_cgc_cli4 ||''.''||
                                t2.cli_ped_cgc_cli2   cod_cliente           ,
                                 upper
                                (
                                 decode (t2.cod_via_transp,
                                         1, ''terrestre'',
                                         2, ''aéreo'',
                                         3, ''maritimo'',
                                         4, ''ferroviario'',
                                         5, ''fluvial'')
                                ) via  ,
                                1  cd_it_pe_nivel99,
                                t1.referencia_peca,
                                t1.ordem_producao,
                                t1.data_programacao,
                                t1.alternativa_peca         alternativa,
                                t1.roteiro_peca         roterio,
                                 (
                                 select distinct sortimento from pcpc_021
                                 where ordem_producao = t1.ordem_producao
                                 )                 cod_color,
                                 (
                                  select distinct substr(t5.descricao_15,0,30)
                                     from basi_010 t5
                                        where  t5.nivel_estrutura  = 1
                                        and t5.grupo_estrutura  = t1.referencia_peca
                                        and t5.item_estrutura   in
                                        (
                                            select distinct sortimento from pcpc_021
                                             where ordem_producao = t1.ordem_producao
                                        )
                                 )                                                      desc_color,
                                t4.grupo_planejamento,
                                usystex.fx_plan_paridasfichas(t1.ordem_producao)        partida,
                                t3.nome_cliente                                         ,
                                t11.nome_pais,
                                t12.produto_cliente,
                                t13.descr_referencia,
                                 (select  systextilrpt.fx_rutasprenda(''1'',t1.referencia_peca ,decode (t1.alternativa_peca, 0, 1, t1.alternativa_peca),decode (t1.roteiro_peca, 0, 1, t1.roteiro_peca)) from dual)
                                  ruta,
                                 ((
                                  select USYSTEX.FX_PLAN_TELAPRINCIPALPEDIDO(t1.pedido_venda , (select distinct sortimento from pcpc_021
                                 where ordem_producao = t1.ordem_producao) )codigo_tela from dual
                                            )
                                  ) codigo_tela,
                                  (
                                  select sum (tmp.minutos_homem)
                                     from mqop_050 tmp
                                    where     tmp.nivel_estrutura = ''1''
                                          and tmp.grupo_estrutura = t1.referencia_peca
                                          and tmp.numero_alternati =
                                                 decode (t1.alternativa_peca, 0, 1, t1.alternativa_peca)
                                          and tmp.numero_roteiro =
                                                 decode (t1.roteiro_peca, 0, 1, t1.roteiro_peca)
                                          and tmp.codigo_estagio in (1, 10, 13)
                                  )
                                 minutospremda_corte ,
                                  (
                                  select sum (tmp.minutos_homem)
                                     from mqop_050 tmp                                                  --> TABLA DE OPERACIONES
                                    where     tmp.nivel_estrutura = ''1''
                                          and tmp.grupo_estrutura = t1.referencia_peca
                                          and tmp.numero_alternati =
                                                 decode (t1.alternativa_peca, 0, 1, t1.alternativa_peca)
                                          and tmp.numero_roteiro =
                                                 decode ( t1.roteiro_peca, 0, 1, t1.roteiro_peca)
                                          and tmp.codigo_estagio in(2,14,17, 21)
                                  )
                                  minutospremda_costura,
                                  (
                                  select sum (tmp.minutos_homem)
                                     from mqop_050 tmp                                                  --> TABLA DE OPERACIONES
                                    where     tmp.nivel_estrutura = ''1''
                                          and tmp.grupo_estrutura = t1.referencia_peca
                                          and tmp.numero_alternati =
                                                 decode (t1.alternativa_peca, 0, 1, t1.alternativa_peca)
                                          and tmp.numero_roteiro =
                                                 decode (t1.roteiro_peca, 0, 1, t1.roteiro_peca)
                                          and tmp.codigo_estagio = 6
                                  )
                                  minutospremda_acabados,
                                  t1.dt_cancelamento fecha_baja,
                                  t16.descricao motivo_baja,
                                  0 cantidadcolores
                            from pcpc_020 t1
                                inner join pedi_100 t2
                                    on t1.pedido_venda = t2.pedido_venda
                                inner join pedi_010 t3
                                    on t3.cgc_9 = t2.cli_ped_cgc_cli9
                                    and t3.cgc_4 = t2.cli_ped_cgc_cli4
                                    and t3.cgc_2 = t2.cli_ped_cgc_cli2
                                left join systextilrpt.vw_grupo_planeamentto t4
                                    on t4.pedido_venda      = t1.pedido_venda
                                  left join pedi_150 t9                                                 --> TAbla de pedido alternativa
                                        on t9.cd_cli_cgc_cli9   = t2.cli_ped_cgc_cli9
                                        and t9.cd_cli_cgc_cli4  = t2.cli_ped_cgc_cli4
                                        and t9.cd_cli_cgc_cli2  = t2.cli_ped_cgc_cli2
                                        and t9.seq_endereco     = t2.seq_end_entrega
                                left join basi_160 t10
                                        on t10.cod_cidade       = t9.cid_entr_cobr
                                left join basi_165 t11
                                        on t11.codigo_pais      = t10.codigo_pais
                                left join basi_001 t12                                                --> tabla de Proyecto
                                        on t12.nivel_produto    = 1
                                        and t12.grupo_produto   = t1.referencia_peca
                                left join basi_030 t13
                                        on t13.nivel_estrutura  = 1
                                        and t13.referencia      =  t1.referencia_peca
                                left join pcpt_050 t16
                                     on t16.cod_cancelamento    = t1.cod_cancelamento
                            where
                               (t1.ordem_mestre    <> 0 or t1.tipo_ordem = 3 or t1.tipo_ordem = 2)
                                and  t2.status_pedido              <> ''5''
                                 ' ;
 
                        -- filtro por fecha
                    if v_fecha_inicio is not null then
                        nsql := nsql ||' and  TO_DATE(t2.data_emis_venda,''DD/MM/RRRR'') between to_date('''||v_fecha_inicio||''',''DD/MM/RRRR'') and to_date('''||v_fecha_fin||''',''DD/MM/RRRR'')';
                    end if;
 
 
                    --filtro por pedidos
                     if v_pedido_inicio is not null then
                        nsql := nsql ||' and   t1.pedido_venda  between '|| v_pedido_inicio ||' and  ' || v_pedido_fin ;
                    end if;
 
 
                    -- AGREGADO
                    --filtro por pedidos
                     if p_pedidoin = 1 then
                        nsql := nsql ||' and   t1.pedido_venda  in (select distinct pedido from SYSTEXTILRPT.TMP_JULIO)';
                    end if;
 
 
                      --filtro por fecha de fichas
                     if v_fecha_inicio_ficha is not null then
                        nsql := nsql ||' and   TO_DATE(t1.data_programacao,''DD/MM/RRRR'') between to_date('''||v_fecha_inicio_ficha||''',''DD/MM/RRRR'') and to_date('''||v_fecha_fin_ficha||''',''DD/MM/RRRR'')';
                    end if;
 
                          --filtro por fichas
                     if v_ficha_inicio is not null then
                        nsql := nsql ||' and  t1.ordem_producao  between ' || v_ficha_inicio ||' and  ' || v_ficah_fin ;
                    end if;
 
                     if p_codcancelamiento is not null then
                        --NO MUESTRA LOS CANCELADOS
                        if p_codcancelamiento = 10 then
                            nsql := nsql ||' and  t1.cod_cancelamento  = 0 ';
                        else
                            nsql := nsql ||' and  t1.codigo_motivo  = ' || p_codcancelamiento ;
                        end if;
 
                    end if;
 
                    --  and t3.codigo_motivo = nvl(p_codcancelamiento,t3.codigo_motivo)
                     nsql :=nsql|| ')
                        tbl
                        left join basi_010 t2
                            on
                                (t2.nivel_estrutura||''.''||t2.grupo_estrutura||''.''||t2.subgru_estrutura ||''.''||t2.item_estrutura)
                                =
                                tbl.codigo_tela';
 
           open curingreso for nsql;
            loop
                fetch curingreso bulk collect into vsx limit 1000;
                exit when vsx.count = 0;
                --modificando la tabla
               for x in 1 .. vsx.count loop
 
                    begin
 
                      select  systextilrpt.fx_obpartida(vsx(x).ficha) into vpartida from dual;
                     exception when  others then
                        vpartida := '';
                     end;
 
                    begin
                         select distinct fecha into vfechaobjetivo  from plan_fecobjplan
                            where pedido = vsx(x).pedido;
                    exception when  others then
                        vfechaobjetivo := null;
                    end;
 
                    begin
                        select  descricao into vdesctipprenda
                            from systextilrpt.vw_pcp_tipo
                            where grupo_produto = vsx(x).estilotsc;
                    exception when  others then
                        vdesctipprenda := null;
                    end;
 
                    begin
                          select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,1,4)into vcantprogramada from dual;
                          select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,1,1)into vccanrcant1era from dual;
                          select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,1,2)into vccanrcant2da from dual;
                          select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,1,3)into vccanrcant3era from dual;
 
                          vcantxcortar := vcantprogramada - (nvl(vccanrcant1era,0) + nvl(vccanrcant2da,0) + nvl(vccanrcant3era,0) );
                    exception when  others then
                        vcantprogramada := 0 ;
                        vccanrcant1era :=0;
                        vccanrcant2da   :=0;
                        vccanrcant3era :=0;
                        vcantprogramada := 0;
                    end;
 
                    begin
                        if vccanrcant1era = 0 then
                           vfechacorte :=null;
                        else
                         select  min (t1.data_producao) into  vfechacorte from   pcpc_045 t1
                            where t1.pcpc040_estconf = 1
                            and t1.ordem_producao = vsx(x).ficha;
                        end if;
 
                    exception when  others then
                        vfechacorte :=null;
                    end;
 
                    begin
                         select  min (t1.data_producao) into  vfechacorte2 from   pcpc_045 t1
                            where t1.pcpc040_estconf = 1
                            and t1.ordem_producao = vsx(x).ficha;
                    exception  when  others then
                        vfechacorte2 :=null;
                    end;
 
                    begin
                      select systextilrpt.fx_cantmovxalma80 (vsx(x).ficha,31,141,'E', vsx(x).codigo_color) into ving_corte_pda_incompleta from dual;
                      select systextilrpt.fx_cantmovxalma80 (vsx(x).ficha,31,141,'S', vsx(x).codigo_color) into vsal_corte_pda_incompleta from dual;
                      select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,8,1) into  vnumerado_1ra from dual;
                      select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,8,2) into  vnumerado_2da from dual;
                      select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,8,5) into  vnumerado_recuperacion from dual;
                      select systextilrpt.fx_canregprodxetapas (vsx(x).ficha,8,2) into  vnumerado_perdida from dual;
                    exception when  others then
                        ving_corte_pda_incompleta :=0;
                        vsal_corte_pda_incompleta :=0;
                        vnumerado_1ra :=0;
                        vnumerado_2da :=0;
                        vnumerado_recuperacion :=0;
                        vnumerado_perdida :=0;
                    end;
 
                    begin
                        select min (t1.data_producao) into vfecha_de_lavado_de_panos
                           from  pcpc_045 t1
                           where t1.pcpc040_estconf = 5
                           and t1.ordem_producao = vsx(x).ficha ;
                     exception when  others then
                        vfecha_de_lavado_de_panos :=null;
                    end;
 
                    begin
                        select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,5) into vstock_panos from dual;
                        select systextilrpt.fx_fechxregproda80 (vsx(x).ficha,6) into vfecha_estampado_pieza from dual;
                        select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,6) into vstock_estampado_pieza from dual;
                        select systextilrpt.fx_fechxregproda80 (vsx(x).ficha,7) into vfecha_bordado_pieza from dual;
                        select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,7) into vstock_bordado_pieza from dual;
                        select systextilrpt.fx_ultima_fecha_corte_2(vsx(x).ficha,'1',vsx(x).estilotsc,null,vsx(x).codigo_color) into vfecha_despacho_costura from dual;
                        select fx_ultima_fecha_corte_app(vsx(x).ficha,'1',vsx(x).estilotsc,null,vsx(x).codigo_color) into vfecha_despacho_app from dual;
                        select fx_ultima_retorno_corte_app_x(vsx(x).ficha,'1',vsx(x).estilotsc,null,vsx(x).codigo_color) into vfecha_retorno_a_chincha from dual;
                        select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,8) into vstock_app_piezas from dual;
                    exception when  others then
                        vstock_panos :=0;
                        vfecha_estampado_pieza :=null;
                        vstock_estampado_pieza :=0;
                        vfecha_bordado_pieza :=null;
                        vstock_bordado_pieza :=0;
                        vfecha_despacho_costura :=null;
                        vfecha_despacho_app :=null;
                        vfecha_retorno_a_chincha :=null;
                        vstock_app_piezas :=0;
                    end;
 
                    begin
                        select descricao into vmodulo_costura  from vw_modulo_costuraf
                        where
                                grupo_estrutura         =  vsx(x).estilotsc
                            and item_estrutura      =  vsx(x).codigo_color
                            and numero_lote         =  vsx(x).ficha    ;
                    exception when  others then
                        vmodulo_costura := '';
                    end;
 
                    begin
                        select nvl(sum(t1.qtde_estoque_atu),0) into vcanti_estanteria from estq_040 t1
                           where
                                t1.cditem_nivel99 = '1'
                            and t1.lote_acomp = vsx(x).ficha
                            and t1.deposito between 401 and 499
                            and t1.qtde_estoque_atu != 0;
                    exception when  others then
                        vcanti_estanteria :=0;
                    end;
 
                    begin
                      select min (tmp.data_movimento) into vlinea_costura
                           from  estq_300_estq_310 tmp
                          where     tmp.nivel_estrutura = '1'
                                and tmp.numero_lote = vsx(x).ficha
                                and tmp.codigo_transacao = 55
                                and tmp.entrada_saida = 'E'
                                and tmp.codigo_deposito in (301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,330,350,46);
                    exception when  others then
                        vlinea_costura :=null;
                    end;
 
                    begin
                        select sum (t1.quantidade) into ving from estq_300_estq_310 t1
                           where
                                   t1.codigo_deposito between 301 and 320
                               and t1.numero_lote = vsx(x).ficha
                               and t1.codigo_transacao in (55);
                     exception when  others then
                        ving :=0;
                     end;
 
                    begin
                        select sum(t1.qtde_estoque_atu) into vstock_costura from estq_040 t1
                            where
                                    t1.cditem_nivel99 = '1'
                                and t1.lote_acomp = vsx(x).ficha
                                and t1.deposito  in(301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320)
                                and t1.qtde_estoque_atu >0  ;
                     exception when  others then
                        vstock_costura :=0;
                     end;
 
                    begin
                        select sum (t1.quantidade) into vavance_sal_prenda_costura
                            from  estq_300_estq_310 t1
                           where
                                t1.numero_lote = vsx(x).ficha
                            and t1.codigo_transacao in (54)
                            and t1.codigo_deposito between 301 and 320  ;
                    exception when  others then
                        vavance_sal_prenda_costura :=0;
                    end;
 
 
 
 
                    begin
                         select fx_servicio_nombre (vsx(x).ficha) into vnombre_servicio from dual;
                         select systextilrpt.fx_stock_serv_stockapplima1f(vsx(x).ficha) into vstock_servicio_lima from dual;
                         select systextilrpt.fx_stock_serv_stockapp1f(vsx(x).ficha) into vstock_servicio from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,324) into  vfecha_ingr_app  from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,324) into vstock_appprendasc from dual;
                         select fx_stock_servicio_chincha(vsx(x).ficha) into vtransito_chincha from dual;
                         select fx_stock_servicio_lima(vsx(x).ficha) into vtransito_lima from dual;
 
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,34) into vstock_app2_pza from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,35) into vstock_app2_pda from dual;
                         select fx_stock_servicio_especiales (vsx(x).ficha)  into vservicios_especiales from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,322) into  vfecha_ingr_bordado  from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,322) into vstock_bordado from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,323) into  vfecha_ingr_estampado  from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,323) into vstock_estampado from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,321) into  vfecha_ingr_lavanderia  from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,321) into vstock_lavanderia from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,9) into  vfecha_ingr_cost_final  from dual;
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,9) into  vstock_cost_final  from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,26) into  vfecha_ingr_transito_acabc  from dual;
 
                    exception when  others then
                        vstock_servicio_lima :=0;
                        vstock_servicio :=0;
                        vnombre_servicio :='';
                        vfecha_ingr_app :=null;
                        vstock_appprendasc :=0;
                        vtransito_chincha :=0;
                        vtransito_lima :=0;
                        vstock_app2_pza :=0;
                        vstock_app2_pda :=0;
                        vservicios_especiales :=0;
                        vfecha_ingr_bordado :=null;
                        vstock_bordado :=0;
                        vfecha_ingr_estampado :=null;
                        vstock_estampado :=0;
                        vfecha_ingr_lavanderia := null;
                        vstock_lavanderia :=0;
                        vfecha_ingr_cost_final:= null;
                        vstock_cost_final :=0;
                        vfecha_ingr_transito_acabc := null;
                    end;
 
                    begin
                          select nvl(sum(t1.quantidade),0) into v1 from  estq_300_estq_310 t1
                              where  t1.codigo_deposito in(11,12,210)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(62,55,57)
                                    and t1.entrada_saida = 'E';
 
                            select nvl(sum(t1.quantidade),0)  into v2 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(11,12,210)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(61,56)
                                    and t1.entrada_saida = 'S';
 
                            select nvl(sum(t1.quantidade),0) into v3  from  estq_300_estq_310 t1
                                 where  t1.codigo_deposito in(210)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(54)
                                    and t1.entrada_saida = 'S';
 
                            select nvl(sum(t1.qtde_estoque_atu),0)  into v4 from estq_040 t1
                                  where   t1.lote_acomp = vsx(x).ficha
                                    and t1.cditem_nivel99 = '1'
                                    and t1.cditem_grupo =   vsx(x).estilotsc
                                    and t1.cditem_item =   vsx(x).codigo_color
                                    and t1.deposito in(26);
                       vingtransitoacabchin := (v1 - (v2+v3)) + v4;
                    exception when  others then
                        vingtransitoacabchin :=0;
                    end;
 
                    begin
                        select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,26) into  vstock_transito_ch  from dual;
                        select systextilrpt.fx_fechxregproda80(vsx(x).ficha,210) into  vfecha_ingr_acabados_c  from dual;
                    exception when  others then
                        vstock_transito_ch :=0;
                        vfecha_ingr_acabados_c :=null;
                    end;
 
                    begin
 
                       select nvl(sum(t1.quantidade),0) into x1 from  estq_300_estq_310 t1
                            where  t1.codigo_deposito in(210)
                                and  t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura = '1'
                                and t1.grupo_estrutura  = vsx(x).estilotsc
                                and t1.item_estrutura =  vsx(x).codigo_color
                                and t1.codigo_transacao   in(55,62,147)
                                and t1.entrada_saida = 'E';
 
                          select nvl(sum(t1.quantidade),0) into x2 from estq_300_estq_310 t1
                            where  t1.codigo_deposito in(210)
                                and  t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura = '1'
                                and t1.grupo_estrutura  = vsx(x).estilotsc
                                and t1.item_estrutura =  vsx(x).codigo_color
                                and t1.codigo_transacao   in(56,61,54)
                                and t1.entrada_saida = 'S';
 
                         select nvl(sum(t1.quantidade),0) into x3 from estq_300_estq_310 t1
                            where  t1.codigo_deposito in(210)
                                and  t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura =  '1'
                                and t1.grupo_estrutura  = vsx(x).estilotsc
                                and t1.item_estrutura = vsx(x).codigo_color
                                and t1.codigo_transacao   in(148);
 
                        vingreso_acabados_chin := (x1-x2) - x3 ;
                    exception when  others then
                        vingreso_acabados_chin :=0;
                    end;
 
                    begin
                        select nvl(sum(t1.quantidade),0)into y1 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(11)
                                and  t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura =  '1'
                                and t1.grupo_estrutura  =vsx(x).estilotsc
                                and t1.item_estrutura = vsx(x).codigo_color
                                and t1.codigo_transacao   in(62,55)
                                and t1.entrada_saida = 'E';
 
 
                             select nvl(sum(t1.quantidade),0) into y2 from  estq_300_estq_310 t1
                                        where  t1.codigo_deposito in(11)
                                        and  t1.numero_lote = vsx(x).ficha
                                        and t1.nivel_estrutura =  '1'
                                        and t1.grupo_estrutura  = vsx(x).estilotsc
                                        and t1.item_estrutura = vsx(x).codigo_color
                                        and t1.codigo_transacao   in(61,56)
                                        and t1.entrada_saida = 'S';
 
                            vingreso_acabados_11_chin := y1-y2;
 
                    exception when  others then
                    vingreso_acabados_11_chin :=0;
                    end;
 
                   begin
                        select nvl(sum(t1.quantidade),0)into b1 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(12)
                                and  t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura =  '1'
                                and t1.grupo_estrutura  =vsx(x).estilotsc
                                and t1.item_estrutura = vsx(x).codigo_color
                                and t1.codigo_transacao   in(62,55)
                                and t1.entrada_saida = 'E';
 
 
                             select nvl(sum(t1.quantidade),0) into b2 from  estq_300_estq_310 t1
                                        where  t1.codigo_deposito in(12)
                                        and  t1.numero_lote = vsx(x).ficha
                                        and t1.nivel_estrutura =  '1'
                                        and t1.grupo_estrutura  = vsx(x).estilotsc
                                        and t1.item_estrutura = vsx(x).codigo_color
                                        and t1.codigo_transacao   in(61,56)
                                        and t1.entrada_saida = 'S';
 
                            vingreso_acabados_12_chin := b1-b2;
 
                    exception when  others then
                    vingreso_acabados_12_chin :=0;
                    end;
 
                    begin
                        select nvl(sum(nvl(stock_acabados_primerasc,0)),0) into vcant10 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido          = vsx(x).pedido
                        and codigo_color    = vsx(x).codigo_color;
 
                        if vcant10 > 0 then
                            vstock_acabados_primerasc :=0;
                        else
                           select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,210) into  vstock_acabados_primerasc  from dual;
                        end if;
 
                        select nvl(sum(nvl(stock_acabados_segundac,0)),0) into vcant11 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido          = vsx(x).pedido
                        and codigo_color    = vsx(x).codigo_color;
 
                        if vcant11 > 0 then
                            vstock_acabados_segundac :=0;
                        else
                           select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,11) into  vstock_acabados_segundac  from dual;
                        end if;
 
                        select nvl(sum(nvl(stock_acabados_tercerasc,0)),0) into vcant12 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido          = vsx(x).pedido
                        and codigo_color    = vsx(x).codigo_color;
 
                        if vcant12 > 0 then
                           vstock_acabados_tercerasc :=0;
                        else
                            select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,12) into  vstock_acabados_tercerasc  from dual;
 
                        end if;
 
                    exception  when  others then
                        vcant10 :=0;
                        vcant11 :=0;
                        vcant12 :=0;
                        vstock_acabados_primerasc :=0;
                        vstock_acabados_segundac :=0;
                        vstock_acabados_tercerasc :=0;
 
                    end;
 
                    begin
                          --> SERVICIO ACABADOS CHN - IN HOUSE -- Mostrar los despachos guía del tránsito de acabados (26) o acabados (210) con operación 55 DESPACHO SERVICIO ACABADO, menos los retornos al acabados 1ra 210 con operación 054 - RECEPCION SERVICIO ACABADO.
                        vlocalidad  := '';
                        vlocalidad  := usystex.inter_fn_localidad(vsx(x).ficha,210,55);
                        vqtd_21055  := usystex.inter_fn_desp_guia(vsx(x).ficha,210,55) - nvl(usystex.inter_fn_ing_guia(vsx(x).ficha,210,54),0)  ;
                        vsrvacbchn_ih := 0;
                        vstock_servicio_acabados_chin := 0;
 
                        if vlocalidad = 'CHINCHA/INHOUSE' then
                            vsrvacbchn_ih   := vqtd_21055;
                        else
                            vstock_servicio_acabados_chin   := 0;
                        end if;
 
                        if vlocalidad = 'CHINCHA/EXTERNO' then
                            vstock_servicio_acabados_chin   := vqtd_21055;
                        else
                        vsrvacbchn_ih   := 0;
                        end if;
                    exception  when  others then
                         vstock_servicio_acabados_chin :=0;
                    end;
 
                    begin
                        select systextilrpt.fx_fechxregproda80(vsx(x).ficha,36) into  vfecha_ingr_transito_acabl  from dual;
 
                        select nvl(sum(t1.quantidade),0)into c1 from  estq_300_estq_310 t1
                                where
                                    t1.codigo_deposito in(36,37,38,39)
                                and t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura =  '1'
                                and t1.grupo_estrutura  =vsx(x).estilotsc
                                and t1.item_estrutura = vsx(x).codigo_color
                                and t1.codigo_transacao   in(62,55,57)
                                and t1.entrada_saida = 'E';
 
 
                        select nvl(sum(t1.quantidade),0) into c2 from  estq_300_estq_310 t1
                                where
                                    t1.codigo_deposito in(36,37,38,39)
                                and t1.numero_lote = vsx(x).ficha
                                and t1.nivel_estrutura =  '1'
                                and t1.grupo_estrutura  = vsx(x).estilotsc
                                and t1.item_estrutura = vsx(x).codigo_color
                                and t1.codigo_transacao   in(61,56)
                                and t1.entrada_saida = 'S';
 
                        vingtransitoacablim := c1 - c2;
                    exception  when  others then
                         vfecha_ingr_transito_acabl :=null;
 
                    end;
 
                    begin
                         select systextilrpt.fx_cantxalmacena80(vsx(x).ficha,vsx(x).estilotsc,vsx(x).codigo_color,36) into  vstock_transito_lim  from dual;
                         select systextilrpt.fx_fechxregproda80(vsx(x).ficha,37) into  vfecha_ingreso_acab_lim  from dual;
                    exception  when  others then
                        vstock_transito_lim :=0;
                        vfecha_ingreso_acab_lim :=null;
                    end;
 
                    begin
                        select nvl(sum(t1.quantidade),0) into a1 from  estq_300_estq_310 t1
                              where  t1.codigo_deposito in(37)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(55,62,165)
                                    and t1.entrada_saida = 'E';
 
                            select nvl(sum(t1.quantidade),0)  into a2 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(37)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(56,61)
                                    and t1.entrada_saida = 'S';
 
                            select nvl(sum(t1.quantidade),0) into a3  from  estq_300_estq_310 t1
                                 where  t1.codigo_deposito in(37)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(166);
                         vingreso_acabados_lim := (a1-a2) -a3;
                    exception  when  others then
                        vingreso_acabados_lim :=0;
                        a1 :=0;
                        a2 :=0;
                        a3 :=0;
                    end;
 
 
                    begin
                         select nvl(sum(t1.quantidade),0) into a4 from  estq_300_estq_310 t1
                              where  t1.codigo_deposito in(38)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(62,55)
                                    and t1.entrada_saida = 'E';
 
                         select nvl(sum(t1.quantidade),0)  into a5 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(38)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(61,56)
                                    and t1.entrada_saida = 'S';
 
                           vingreso_acabados_38_lim := a4-a5;
                     exception  when  others then
                        vingreso_acabados_38_lim :=0;
                        a4 :=0;
                        a5 :=0;
                    end;
 
                    begin
                         select nvl(sum(t1.quantidade),0) into a6 from  estq_300_estq_310 t1
                              where  t1.codigo_deposito in(39)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(62,55)
                                    and t1.entrada_saida = 'E';
 
                         select nvl(sum(t1.quantidade),0)  into a7 from  estq_300_estq_310 t1
                                where  t1.codigo_deposito in(39)
                                    and  t1.numero_lote = vsx(x).ficha
                                    and t1.nivel_estrutura = '1'
                                    and t1.grupo_estrutura  = vsx(x).estilotsc
                                    and t1.item_estrutura =  vsx(x).codigo_color
                                    and t1.codigo_transacao   in(61,56)
                                    and t1.entrada_saida = 'S';
 
                           vingreso_acabados_39_lim := a6-a7;
                     exception  when  others then
                        vingreso_acabados_39_lim :=0;
                        a6 :=0;
                        a7 :=0;
                    end;
 
                      begin
                        select nvl(sum(nvl(stock_acabados_primerasl,0)),0) into vcant1 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color
                        --and mov_baja <>'.'
                        ;
 
                        if vcant1 > 0 then
                            vstock_acabados_primerasl :=0;
                        else
                            select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,37) into  vstock_acabados_primerasl  from dual;
                       end if;
                    exception  when  others then
                    vstock_acabados_primerasl :=0;
                    vcant1 :=0;
                    end;
 
                    begin
                        select nvl(sum(nvl(stock_acabados_segundal,0)),0) into vcant2 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color
                        --and mov_baja <>'.'
                        ;
 
                        if vcant2 > 0 then
                            vstock_acabados_segundal :=0;
                        else
                            select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,38) into vstock_acabados_segundal   from dual;
                       end if;
                    exception  when  others then
                    vstock_acabados_segundal :=0;
                    vcant2 :=0;
                    end;
 
                     begin
                        select nvl(sum(nvl(stock_acabados_tercerasl,0)),0) into vcant3 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color
                        --and mov_baja <>'.'
                        ;
 
                        if vcant3 > 0 then
                            vstock_acabados_tercerasl :=0;
                        else
                            select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,39) into vstock_acabados_tercerasl   from dual;
                       end if;
                    exception  when  others then
                    vstock_acabados_tercerasl :=0;
                    vcant3 :=0;
                    end;
 
                    begin
                        select systextilrpt.fx_stockf_serv_stockacablim(vsx(x).ficha,'1',vsx(x).estilotsc,vsx(x).codigo_color) into vstock_servicio_lim from dual;
                        select systextilrpt.fx_fechxregprodxpedia80(vsx(x).pedido,vsx(x).codigo_color,211) into  vingresoaptchinch  from dual;
                    exception  when  others then
                        vstock_servicio_lim :=0;
                        vingresoaptchinch :=null;
                    end;
 
                    begin
                        select nvl(sum(nvl(stock1rasapt,0)),0) into vcant4 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if vcant4 >0 then
                            vstock1rasapt :=0;
                        else
                        select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,211) +
                               systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,40) into vstock1rasapt  from dual;
                        end if;
                    exception  when  others then
                        vstock1rasapt :=0;
                        vcant4          :=0;
                     end;
 
                     begin
                         select nvl(sum(nvl(stock2dasapt,0)),0) into vcant5 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if vcant5 >0 then
                            vstock2dasapt :=0;
                        else
                        select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,213) +
                               systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,42) into vstock2dasapt  from dual;
                        end if;
 
                     exception  when  others then
                         vstock2dasapt :=0;
                         vcant5          :=0;
                     end;
                     --------------------------------RESULTADO DE ENCAJADO Y EMBOLSADO  20/01/2019
                      begin
                         select nvl(sum(nvl(I_EMBOLSADO_R,0)),0) into v_embolsado_r from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if v_embolsado_r >0 then
                            v_embolsado_r_cant :=0;
                        else
                               select SYSTEXTILRPT.FX_CANTXREGISTRO_ACABADOS(vsx(x).pedido,vsx(x).codigo_color,'EMBOLSADO') into v_embolsado_r_cant  from dual;
                        end if;
 
                     exception  when  others then
                         v_embolsado_r_cant :=0;
                         v_embolsado_r          :=0;
                     end;
                     ---------
                          begin
                             select nvl(sum(nvl(I_ENCAJADO_R,0)),0) into v_encajado_r from TMP_CRTLAVUPDATE_VS3  x1
                            where
                                pedido = vsx(x).pedido
                            and codigo_color = vsx(x).codigo_color;
 
                            if v_encajado_r >0 then
                                v_encajado_r_cant :=0;
                            else
                            select SYSTEXTILRPT.FX_CANTXREGISTRO_ACABADOS(vsx(x).pedido,vsx(x).codigo_color,'ENCAJADO') into v_encajado_r_cant  from dual;
                            end if;
 
                         exception  when  others then
                             v_encajado_r_cant :=0;
                             v_encajado_r          :=0;
                         end;
 
                      ---modificacion 11/02/2020
                        ---------CANTIDAD PROGRAMA
 
                        begin
 
 
                          select nvl(sum(nvl(I_CON_PROG,0)),0) into v_i_cant_conge_corte_r from TMP_CRTLAVUPDATE_VS3  x1
                            where
                                pedido = vsx(x).pedido
                            and codigo_color = vsx(x).codigo_color;
 
 
                        if v_i_cant_conge_corte_r >0 then
                            v_i_cant_conge_corte_cant :=0;
                        else
                               select sum(pcpc_021_log.QUANTIDADE) into v_i_cant_conge_corte_cant  from pcpc_021_log
                               Where  PCPC_021_LOG.ORDEM_PRODUCAO =   vsx(x).ficha ;
                        end if;
 
                     exception  when  others then
                         v_i_cant_conge_corte_cant :=0;
                         v_i_cant_conge_corte_r          :=0;
                     end;
                     ---------------------ZONA PREPACK
                        begin
                         select nvl(sum(nvl(I_PREPACK_ACAB,0)),0) into v_i_stock_prepack_acab_r from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if v_i_stock_prepack_acab_r >0 then
                            v_i_stock_prepack_acab_cant :=0;
                        else
                           select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,63) into v_i_stock_prepack_acab_cant  from dual;
                        end if;
 
                     exception  when  others then
                         v_i_stock_prepack_acab_cant :=0;
                         v_i_stock_prepack_acab_r          :=0;
                     end;
                     -------ZONA DE REESTRU
                        begin
                         select nvl(sum(nvl(I_RESTRU_ACAB,0)),0) into v_i_stock_reestru_acab_r from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if v_i_stock_reestru_acab_r >0 then
                            v_i_stock_reestru_acab_cant :=0;
                        else
                          select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,27) into v_i_stock_reestru_acab_cant  from dual;
                        end if;
 
                     exception  when  others then
                         v_i_stock_reestru_acab_cant :=0;
                         v_i_stock_reestru_acab_r          :=0;
                     end;
 
                     -------------------------RESULTADO DE ENCAJADO Y EMBOLSADO
 
                    begin
                        select nvl(sum(nvl(stock3rasapt,0)),0) into vcant6 from TMP_CRTLAVUPDATE_VS3
                        where
                            pedido = vsx(x).pedido
                        and codigo_color = vsx(x).codigo_color;
 
                        if vcant6 >0 then
                            vstock3rasapt :=0;
                        else
 
                        select systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,214) +
                               systextilrpt.fx_cantxalmacena80(vsx(x).pedido,vsx(x).estilotsc,vsx(x).codigo_color,43) into vstock3rasapt  from dual;
                        end if;
                    exception  when  others then
                        vstock3rasapt :=0;
                        vcant6          :=0;
                    end;
 
 
 
                    begin
                        select kg into vkg_prog  from vw_pcp_kg_ficha where pcpc0302_orprocor= vsx(x).ficha;
                        select usuario into vusuario_canc  from vw_pcpc_usu



Comentarios sobre la versión: 1 (0)


No hay comentarios
 

Comentar la versión: 1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s6019