Código de Java - proyecto productos matrices -metodos-crud

javaConsola
estrellaestrellaestrellaestrellaestrella(1)

Publicado el 4 de Febrero del 2021gráfica de visualizaciones de la versión: javaConsola
4.469 visualizaciones desde el 4 de Febrero del 2021
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
package paquete;
 
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
import java.util.Scanner;
 
public class MATRICES_PRODUCTOS1 {
    //CREO 3 AREGLOS modificador acceso static
 
    static String[][] productos;
    static String[][] ventas;
    static String[][] ventasDetalles;
    //CREO 3 ACUMULADORES; modificcador acceso static
    static int cantidadProductos;
    static int cantidadVentas;
    static int cantidadVetasDetalles;
    //CREO 1 OBJETO ESCANNER modificador acceso static
    static Scanner entrada = new Scanner(System.in);
 
    public static void main(String args[]) {
        //USO EL OBJETO SCCANER
        entrada = new Scanner(System.in);
        //ESTABLEZCO LA CUADRICULA DE LAS 3 MATRICES
        productos = new String[100][6];
        ventas = new String[100][4];
        ventasDetalles = new String[100][5];
        //INICIALIZO LOS 3 ACUMULADORES;
        cantidadProductos = 0;
        cantidadVentas = 0;
        cantidadVetasDetalles = 0;
        //FUNCION CARGAR DATOS
        cargarDatos();
        //CREAR EL MENÚ PRINCIPAL
        int opciones;
        do {
            System.out.println("");
            System.out.println("MENU PRINCIPAL");
            System.out.println("1.GESTION PRODUCTOS");
            System.out.println("2.GESTION VENTAS");
            System.out.println("3.REPORTES");
            System.out.print("Seleccione una opción: ");
            opciones = entrada.nextInt();
            switch (opciones) {
                case 1:
                    gestionarProductos();
                    break;
                case 2:
                    gestionarVentas();
                    break;
                case 3:
                    gestionarReportes();
                    break;
                default:
                    System.out.println("Opción no disponible, vuelve a intentar...");
            }
        } while (opciones != 0);
    }
 
    private static void cargarDatos() {
        cantidadProductos = 6;
        productos[0][0] = "1"; //REFERENCIA
        productos[0][1] = "plancha"; //NOMBRE
        productos[0][2] = "1000"; //STOCK
        productos[0][3] = "10"; //STOCK MINIMO
        productos[0][4] = "1010"; //STOCK MÁXIMO
        productos[0][5] = "50000"; // VALOR UNITARIO
 
        productos[1][0] = "2";
        productos[1][1] = "DVD";
        productos[1][2] = "2000";
        productos[1][3] = "10";
        productos[1][4] = "2010";
        productos[1][5] = "100000";
 
        productos[2][0] = "3";
        productos[2][1] = "estufa";
        productos[2][2] = "3000";
        productos[2][3] = "10";
        productos[2][4] = "3010";
        productos[2][5] = "600000";
 
        productos[3][0] = "4";
        productos[3][1] = "nevera";
        productos[3][2] = "4000";
        productos[3][3] = "10";
        productos[3][4] = "4010";
        productos[3][5] = "800000";
 
        productos[4][0] = "5";
        productos[4][1] = "microondas";
        productos[4][2] = "5000";
        productos[4][3] = "10";
        productos[4][4] = "5010";
        productos[4][5] = "30000";
 
        productos[5][0] = "6";
        productos[5][1] = "batidora";
        productos[5][2] = "6000";
        productos[5][3] = "10";
        productos[5][4] = "6010";
        productos[5][5] = "70000";
 
        cantidadVentas = 6;
        ventas[0][0] = "1"; //NUMERO DE FACTURA
        ventas[0][1] = "01-01-2020 08:08:08"; //FECHA Y HORA
        ventas[0][2] = "Mauricio Cardona"; //NOMBRE CLIENTE
        ventas[0][3] = "Cali"; //DIRECCIÓN
 
        ventas[1][0] = "2";
        ventas[1][1] = "01-01-2020 09:09:09";
        ventas[1][2] = "José Rivera";
        ventas[1][3] = "Barranquilla";
 
        ventas[2][0] = "3";
        ventas[2][1] = "01-01-2020 10:10:10";
        ventas[2][2] = "Jorge Guzman";
        ventas[2][3] = "Bogota";
 
        ventas[3][0] = "4";
        ventas[3][1] = "01-01-2020 11:11:11";
        ventas[3][2] = "Fernando Rodriguez";
        ventas[3][3] = "Medellin";
 
        ventas[4][0] = "5";
        ventas[4][1] = "01-01-2020 12:12:12";
        ventas[4][2] = "Luis Sanchez";
        ventas[4][3] = "Tunja";
 
        ventas[5][0] = "6";
        ventas[5][1] = "01-01-2020 13:13:13";
        ventas[5][2] = "Ernesto Garcia";
        ventas[5][3] = "Cartagena";
 
        cantidadVetasDetalles = 12;
        ventasDetalles[0][0] = "1"; //CÓDIGO FACTURA
        ventasDetalles[0][1] = "1"; //CÓDIGO PRODUCTO
        ventasDetalles[0][2] = "2"; //CANTIDAD VENDIDA
        ventasDetalles[0][3] = "50000"; //VALOR UNITARIO
        ventasDetalles[0][4] = "100000"; //SUBTOTAL
 
        ventasDetalles[1][0] = "1";
        ventasDetalles[1][1] = "5";
        ventasDetalles[1][2] = "2";
        ventasDetalles[1][3] = "30000";
        ventasDetalles[1][4] = "60000";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ventasDetalles[2][0] = "2";
        ventasDetalles[2][1] = "5";
        ventasDetalles[2][2] = "2";
        ventasDetalles[2][3] = "30000";
        ventasDetalles[2][4] = "60000";
 
        ventasDetalles[3][0] = "2";
        ventasDetalles[3][1] = "2";
        ventasDetalles[3][2] = "3";
        ventasDetalles[3][3] = "100000";
        ventasDetalles[3][4] = "300000";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ventasDetalles[4][0] = "3";
        ventasDetalles[4][1] = "2";
        ventasDetalles[4][2] = "3";
        ventasDetalles[4][3] = "100000";
        ventasDetalles[4][4] = "300000";
 
        ventasDetalles[5][0] = "3";
        ventasDetalles[5][1] = "3";
        ventasDetalles[5][2] = "5";
        ventasDetalles[5][3] = "600000";
        ventasDetalles[5][4] = "3000000";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ventasDetalles[6][0] = "4";
        ventasDetalles[6][1] = "4";
        ventasDetalles[6][2] = "10";
        ventasDetalles[6][3] = "800000";
        ventasDetalles[6][4] = "8000000";
 
        ventasDetalles[7][0] = "4";
        ventasDetalles[7][1] = "5";
        ventasDetalles[7][2] = "10";
        ventasDetalles[7][3] = "30000";
        ventasDetalles[7][4] = "300000";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ventasDetalles[8][0] = "5";
        ventasDetalles[8][1] = "6";
        ventasDetalles[8][2] = "4";
        ventasDetalles[8][3] = "70000";
        ventasDetalles[8][4] = "280000";
 
        ventasDetalles[9][0] = "5";
        ventasDetalles[9][1] = "3";
        ventasDetalles[9][2] = "5";
        ventasDetalles[9][3] = "600000";
        ventasDetalles[9][4] = "3000000";
////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ventasDetalles[10][0] = "6";
        ventasDetalles[10][1] = "4";
        ventasDetalles[10][2] = "10";
        ventasDetalles[10][3] = "800000";
        ventasDetalles[10][4] = "8000000";
 
        ventasDetalles[11][0] = "6";
        ventasDetalles[11][1] = "5";
        ventasDetalles[11][2] = "10";
        ventasDetalles[11][3] = "30000";
        ventasDetalles[11][4] = "300000";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    }
 
    private static void gestionarProductos() {
        System.out.println("");
        int opcion;
        do {
            System.out.println("MENÚ PRODUCTOS");
            System.out.println("1. Ingresar producto");
            System.out.println("2. Consultar producto");
            System.out.println("3. Modificar producto");
            System.out.println("4. Eliminar producto");
            System.out.println("5. Listar productos");
            System.out.println("0. Salir");
            System.out.print("Seleccione una opción: ");
            opcion = entrada.nextInt();
            if (opcion == 1) {
                ingresarProducto();
            }
            if (opcion == 2) {
                consultarProducto();
            }
            if (opcion == 3) {
                modificarProducto();
            }
            if (opcion == 4) {
                eliminarProducto();
            }
            if (opcion == 5) {
                listarProducto();
            }
            if (opcion != 1 && opcion != 2 && opcion != 3 && opcion != 4 && opcion != 5 && opcion != 0) {
                System.out.println("Opcion no disponible");
            }
            if (opcion == 0) {
                System.out.println("Saliendo al menu principal...");
            }
        } while (opcion != 0);
        System.out.println("");
    }
 
    private static void gestionarVentas() {
        System.out.println("");
        int opciones;
        do {
            System.out.println("MENÚ VENTAS");
            System.out.println("1.Registrar factura");
            System.out.println("2.Consultar factura");
            System.out.println("3.Eliminar factura");
            System.out.println("4.Listar facturas");
            System.out.println("0.Salir");
            System.out.print("Selecciona una opción: ");
            opciones = entrada.nextInt();
            if (opciones == 1) {
                registrarFactura();
            }
            if (opciones == 2) {
                consultarFactura();
            }
            if (opciones == 3) {
                eliminarFactura();
            }
            if (opciones == 4) {
                listarFacturas();
            }
            if (opciones != 1 && opciones != 2 && opciones != 3 && opciones != 4 && opciones != 0) {
                System.out.println("Opcion no disponible");
            }
            if (opciones == 0) {
                System.out.println("Saliendo al menu principal...");
            }
        } while (opciones != 0);
        System.out.println("");
    }
 
    private static void gestionarReportes() {
        System.out.println("");
        int opcion;
        do {
            System.out.println("MENÚ REPORTES");
            System.out.println("1.Lista de facturas de mayores montos a menores montos");
            System.out.println("2.Lista de facturas de menores montos a mayores montos");
            System.out.println("3.Boletín general de facturas");
            System.out.println("4.Monto total de dinero en facturas");
            System.out.println("5.Productos escasos");
            System.out.println("6.Consultar factura superiores a una factura existente");
            System.out.println("0.Salir al menu principal");
            System.out.print("Selecciona una opción: ");
            opcion = entrada.nextInt();
            if (opcion == 1) {
                facturasMayoresAMenores();
            }
            if (opcion == 2) {
                facturasMenoresAMayores();
            }
            if (opcion == 3) {
                boletinGeneralFacturas();
            }
            if (opcion == 4) {
                montoTotalDineroEnFacturas();
            }
            if (opcion == 5) {
                productosEscasos();
                boolean bandera = false;
                int contador = 0;
                bandera = funcion_MensajeDeProductosEscasos(contador);
                if (bandera == false) {
                    productosEscasos();
                } else {
                    productosEscasos2();
                }
            }
            if (opcion == 6) {
                consultarFacturasSuperiores();
            }
            if (opcion != 1 && opcion != 2 && opcion != 3 && opcion != 4 && opcion != 5 && opcion != 6 && opcion != 0) {
                System.out.println("Opcion no disponible");
            }
            if (opcion == 0) {
                System.out.println("Saliendo al menu principal...");
            }
        } while (opcion != 0);
        System.out.println("");
    }
 
    private static void ingresarProducto() {
        System.out.println("------------------");
        System.out.println("INGRESAR PRODUCTOS");
        char opciones;
        do {
            System.out.print("Ingrese la referencia del producto: ");
            productos[cantidadProductos][0] = entrada.next();
            int referencia = buscarIndiceDelProducto(productos[cantidadProductos][0]);
            if (referencia >= 0) {
                System.out.println("El código ya se encuentra registrado, desea intentar con otro código?[s/n]: ");
                opciones = entrada.next().charAt(0);
            } else {
                System.out.print("Nombre del producto: ");
                productos[cantidadProductos][1] = entrada.next();
                System.out.print("Stock: ");
                productos[cantidadProductos][2] = entrada.next();
                System.out.print("Stock máximo: ");
                productos[cantidadProductos][3] = entrada.next();
                System.out.print("Stock mínimo: ");
                productos[cantidadProductos][4] = entrada.next();
                System.out.print("Valor unitario: ");
                productos[cantidadProductos][5] = entrada.next();
                cantidadProductos++;
                System.out.print("Desea agreagar otro producto?[s/n]: ");
                opciones = entrada.next().charAt(0);
            }
        } while (opciones == 's' || opciones == 'S');
        System.out.println("------------------");
    }
 
    private static void MostrarProducto(int indice) {
        System.out.println("Nombre: " + productos[indice][1]);
        System.out.println("Valor unitario: " + productos[indice][2]);
        System.out.println("Stock: " + productos[indice][3]);
        System.out.println("Stock maximo: " + productos[indice][4]);
        System.out.println("Stock minimo: " + productos[indice][5]);
    }
 
    private static void consultarProducto() {
        System.out.println("___________________________");
        System.out.println("_________CONSULTAR_________");
        char opciones = 's';
        do {
            System.out.print("Ingrese codigo del producto: ");
            String codigodigitado = entrada.next();
            int indice = buscarIndiceDelProducto(codigodigitado);
            if (indice == -1) {
                System.out.println("...error el codigo del producto no existe!!!");
                System.out.print("Desea usted consultar otro producto?[S/N]: ");
                opciones = entrada.next().charAt(0);
            } else {
                System.out.println("___Datos del producto___");
                MostrarProducto(indice);
                System.out.print("Desea usted consultar otro producto?[S/N]: ");
                opciones = entrada.next().charAt(0);
                System.out.println("________________________________________");
            }
        } while (opciones == 's' || opciones == 'S');
    }
 
    private static void modificarProducto() {
        System.out.println("___________________________");
        System.out.println("_________MODIFICAR PRODUCTO_________");
        char opcion = 's';
        do {
            System.out.print("Degite codigo de producto: ");
            String codigoProducto;
            codigoProducto = entrada.next();
            int codigo = buscarIndiceDelProducto(codigoProducto);
            if (codigo == -1) {
                System.out.println("Error el código no se encuentra");
                System.out.print("Desea usted intentar con otra referencia?[s/n:] ");
                opcion = entrada.next().charAt(0);
            } else {
                System.out.print("Código actual: ( " + productos[codigo][0] + " )Nuevo código: ");
                String dato = entrada.nextLine();
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][0] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Nombre actual: ( " + productos[codigo][1] + " )Nuevo nombre: ");
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][1] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Stock actual: ( " + productos[codigo][2] + " )Nuevo Stock: ");
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][2] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Stock mínimo actual: ( " + productos[codigo][3] + " )Nuevo mínimo Stock: ");
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][3] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Stock máximo actual: ( " + productos[codigo][4] + " )Nuevo Stock máximo: ");
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][4] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Valor unitario actual: ( " + productos[codigo][5] + " )Nuevo valor unitario: ");
                dato = entrada.nextLine();
                if (!dato.equals("")) {
                    productos[codigo][5] = dato; //GUARDANDO LA VARIBLE DATO DENTRO DE LA MATRIZ PRODUCTOS
                }
                System.out.print("Desea usted modificar otro producto?[s/n]: ");
                opcion = entrada.next().charAt(0);
            }
        } while (opcion == 'S' || opcion == 's');//este do-while está en condicion verdadera esto hace que se siga repitendo, HAY QUE BUSCARLE LA CONDICION FALSA PARA QUE YA NO SE REPITA
    }
 
    private static void eliminarProducto() {
        System.out.println("__ELIMINAR PRODUCTO__");
        char opciones = 's';
        do {
            System.out.print("ingrese referencia del producto: ");
            String codigoDigitado = entrada.next();
            int indice = buscarIndiceDelProducto(codigoDigitado);
            if (indice == -1) { //NO ESTÁ EL PRODUCTO EN LA MATRIZ productos
                System.out.println("referencia NO existe");
                System.out.print(" Desea intentar con otra referencia? [s/n]: ");
                opciones = entrada.next().charAt(0);
            } else { //SÍ ESTÁ EL PRODUCTO EN LA MATRIZ productos
                MostrarProducto(indice);
                int ventasAsociadasAlProducto = buscarReferenciaDelProductoEnVentasDetalles(codigoDigitado);
                if (ventasAsociadasAlProducto < 0) { //NO ESTÁ EL PRODUCTO EN LA MATRIZ ventasDetalles
                    System.out.println("El producto actualmente no tiene ventas asociadas a ninguna factura...");
                    System.out.println(" por ello SI puede ser eliminado del inventario...!");
                    System.out.print(" Confirme si deesea eliminar el producto? [s/n]: ");
                    char opc = entrada.next().charAt(0);
                    if (opc == 's' || opc == 'S') {
                        for (int i = indice; i < cantidadProductos; i++) {
                            productos[i] = productos[i + 1]; // SE LE MONTA EL INDICE QUE ESTÁ DESPUES DE ÉL
                        }
                        cantidadProductos--;
                        System.out.println("Este producto ha sido eliminado con exito...!");
                        System.out.print(" Desea eliminar otro producto? [s/n]: ");
                        opciones = entrada.next().charAt(0);
                    }
 
                } else { //SÍ ESTÁ EL PRODUCTO EN LA MATRIZ ventasDetalles por lo tanto no puede ser eliminado
                    System.out.println("El producto actualmente presenta ventas asociadas a alguna factura, ");
                    System.out.println(" por ello NO puede ser eliminado del inventario...!");
                    System.out.print(" Desea eliminar otro producto? [s/n]: ");
                    opciones = entrada.next().charAt(0);
                }
            }
        } while (opciones == 's' || opciones == 'S');
        System.out.println("________________________________________________________________________________");
    }
 
    private static void listarProducto() {
        System.out.println("______________________________________________________");
        System.out.println("____________________LISTAR PRODUCTOS__________________");
        System.out.println("__________________________________________________________________________________________________________________");
 
        String format = "%-20s%-20s%-20s%-20s%-20s%-20s%n";
 
        System.out.printf(format, "codigo", "producto", "stock", "stock_minimo", "stock_maximo", "valor_producto");
        for (int i = 0; i < cantidadProductos; i++) {
            System.out.printf(format, productos[i][0], productos[i][1], productos[i][2], productos[i][3], productos[i][4], productos[i][5]);
 
        }
        System.out.println("___________________________________________________________________________________________________________________");
    }
 
    private static void registrarFactura() {
        System.out.println("__________________________________");
        System.out.println("___REGISTRAR FACTURA ENCABEZADO___");
        int acumulador = 0;
        Date fecha = new Date();
        SimpleDateFormat formatoFecha = new SimpleDateFormat("Y/M/d H:M:S");
        String fechaActual = formatoFecha.format(fecha);
        String numeroFactura = (ReferenciaFacturaAutomatico()) + ""; //AQUÍ ESTOY INVOCANDO A LA FUNCIÓN numeroFactura, PUESTO QUE NECESITO QUE SE GENERE AUTOMÁTICAMENTE
        char opcion;
        int contadorItem = 1;//ESTE CONTADOR ES PARA EL ITEM DE LOS ARTICULOS
        int subtotal;
        ventas[cantidadVentas][0] = numeroFactura;
        ventas[cantidadVentas][1] = fechaActual;
 
        System.out.println("Registro de factura"
                + "\nCodigo de factura: " + numeroFactura + "\nFecha y hora: " + fechaActual);
        System.out.print("Cliente: ");
        ventas[cantidadVentas][2] = entrada.nextLine();
        ventas[cantidadVentas][2] = entrada.nextLine();
        System.out.print("Dirección: ");
        ventas[cantidadVentas][3] = entrada.nextLine();
        cantidadVentas++;
 
        System.out.println("___REGISTRAR FACTURA DETALLE___");
 
        do {
            System.out.println("Producto " + contadorItem);
            System.out.print("Referencia: ");
            String referencia = entrada.next();
            int indice = buscarIndiceDelProducto(referencia);
            if (indice == -1) { //EL PRODUCTO NO EXISTE
                System.out.println("La referencia del producto es inexistente!!!"
                        + "\n Desea intentar nuevamente con otra referencia? (S/N): ");
                opcion = entrada.next().charAt(0);
            } else { //EL PRODUCTO SÍ EXISTE
                int cantidadIngresado;
                System.out.println("Producto: " + productos[indice][1]);
                System.out.println(" Stock: " + productos[indice][2]);
                System.out.println(" Stock_min: " + productos[indice][3]);
                System.out.println(" Stock_max: " + productos[indice][4]);
                System.out.println("Vlr unitario: " + productos[indice][5]);
                System.out.print("Cantidad: ");
                cantidadIngresado = entrada.nextInt();
                //validando la cantidad menor o igual al stock actual y si es mayor al stock
                //actual toca validar si repetir el ingreso?
 
                if (cantidadIngresado <= Integer.parseInt(productos[indice][2])) { //SÍ LA CANTTIDAD ES MENOR O IGUAL A LO QUE HAY EN STOCK, SE PODRÁ RESTAR
                    subtotal = Integer.parseInt(productos[indice][5]) * cantidadIngresado;
                    System.out.println("Subtotal: " + subtotal);
                    acumulador += subtotal;
                    System.out.print("TOTAL AL MOMENTO: " + acumulador);
                    System.out.print("\n--------------------...------------------");
 
                    //lleno la matriz de VentasDetalles
                    ventasDetalles[cantidadVetasDetalles][0] = numeroFactura;
                    ventasDetalles[cantidadVetasDetalles][1] = referencia;
                    ventasDetalles[cantidadVetasDetalles][2] = cantidadIngresado + ""; //LAS COMILLAS DOBLES SON PARA CONVERTIR LA VARIABLE ENTERA EN UNA VARIABLE STRING PORQUEE LA MATRIZVENTASDETALLES ES STRING
                    ventasDetalles[cantidadVetasDetalles][3] = productos[indice][5]; //VALOR UNITARIO DEL PRODUCTO DE LA MATRIZ VENTAS DETALLES = VALOR UNITARIO DEL PRODUCTO DE LA MATRIZ PRODUCTOS
 
                    //resta al stock de productos
                    productos[indice][2] = Integer.parseInt(productos[indice][2]) - cantidadIngresado + ""; ///STOCK DE LA MATRIZ PRODUCTOS = STOCK MATRIZ PRODUCTOS - CANTIDAD INGRESADA. SE HACE LA OPERACION Y SE CONVIERTE EN STRING
 
                    cantidadVetasDetalles++;
                } else { //DE LO CONTRARIO NO SE PODRÁ RESTAR
                    System.out.println("No hay esa cantidad en existencia!!");
                }
 
                System.out.print("\ndesea agregar otro producto? [S/N]: ");
                opcion = entrada.next().charAt(0);
                contadorItem++;
            }
        } while (opcion == 's' || opcion == 'S');
        System.out.println("");
        System.out.print("\tTOTAL AL MOMENTO: " + acumulador);
 
        System.out.println("\n___________________________________");
 
    }
 
    private static void consultarFactura() {
        System.out.println("____________________________");
        System.out.println("____CONSULTAR FACTURA_______");
        System.out.println("----ENCABEZADO DE FACTURA---");
        char opciones = 's';
        do {
            System.out.print("ingrese referencia de factura: ");
            String numeroFactura = entrada.next();
            int indiceFactura = buscarIndiceDeLaFactura(numeroFactura);
            if (indiceFactura == -1) {
                System.out.println("Error numero de factura no existe...!!!");
                System.out.print("Desea consultar otra factura? [s/n]: ");
                opciones = entrada.next().charAt(0);
            } else {
                System.out.println("Codigo de factura: " + ventas[indiceFactura][0]);
                System.out.println("Fecha Y hora: " + ventas[indiceFactura][1]);
                System.out.println("Nombre del cliente: " + ventas[indiceFactura][2]);
                System.out.println("Dirección del cliente: " + ventas[indiceFactura][3]);
                System.out.println("--------------------------------------------------");
                mostrarVentasDetallesPorFactura(numeroFactura);
                System.out.print("Deseas consultar otra factura? [s/n]: ");
                opciones = entrada.next().charAt(0);
            }
        } while (opciones == 's' || opciones == 'S');
    }
 
    private static void mostrarVentasDetallesPorFactura(String numeroFactura) {
        int indiceProducto;
        int subtotal;
        System.out.println("----DETALLES DE FACTURA---");
        String formato = "%-20s%-20s%-20s%-20s%-30s%n";
        System.out.printf(formato, "codigo_producto", "producto", "cantidad", "valor_Unitario", "subtotal");
        for (int i = 0; i < cantidadVetasDetalles; i++) {
            subtotal = Integer.parseInt(ventasDetalles[i][3]) * Integer.parseInt(ventasDetalles[i][2]);
            if (numeroFactura.equals(ventasDetalles[i][0])) {  //<<<QUE HAY AQUÍ? NÚMERO DE FACTURA
                indiceProducto = buscarIndiceDelProducto(ventasDetalles[i][1]);  //<<<QUE HAY AQUÍ? REFERENCIA DEL PRODUCTO
                System.out.printf(formato, ventasDetalles[i][1], productos[indiceProducto][1], ventasDetalles[i][2], ventasDetalles[i][3], subtotal);
            }
        }
        System.out.println("\nTotal factura: " + totalPorReferenciaDeFactura(Integer.parseInt(numeroFactura)) + "\n");
    }
 
    private static void mostrarFactura(int indiceFactura, String numeroFactura) { //PROCEDIMIENTO PORQUE NO RETORNA NINGÚN VALOR PERO TIENE ARGUMENTOS. . ES static PORQUE PUEDE SER INVOCADO SIN NECESIDAD DE EXISTIR OTRA CLASE
        System.out.println("DATOS DE FACTURA A ELIMINAR:");
        int acum = 0;
        System.out.println("numero de factura: " + ventas[indiceFactura][0]);
        System.out.println("fecha:          " + ventas[indiceFactura][1]);
        System.out.println("cliente:        " + ventas[indiceFactura][2]);
        System.out.println("direccion:      " + ventas[indiceFactura][3]);
        String format = "%-30s%-30s%-30s%-30s%n";
        System.out.printf(format, "codigo", "producto", "cantidad", "Vlr unitario", "subtotal");
        for (int i = 0; i < cantidadVetasDetalles; i++) {
            int indice = buscarIndiceDelProducto(ventasDetalles[i][1]); //<<<QUE HAY AQUÍ? CÓDIGO DEL PRODUCTO
            if (ventasDetalles[i][0].equals(numeroFactura)) {
                System.out.printf(format, productos[indice][0], productos[indice][1], ventasDetalles[i][2], ventasDetalles[i][3], Integer.parseInt(ventasDetalles[i][3]) * Integer.parseInt(ventasDetalles[i][2]));
                int subtotal = Integer.parseInt(ventasDetalles[i][3]) * Integer.parseInt(ventasDetalles[i][2]);
                acum = acum + subtotal;
            }
        }
        System.out.println("TOTAL DE LA FACTURA: $" + acum);
    }//FIN MOSTRAR FACTURA
 
    private static void eliminarFactura() {
        System.out.println("__________________________");
        System.out.println("____ELIMINAR FACTURA______");
        char opcion = 's';
        do {
            System.out.print("Ingrese la referencia de factura a eliminar: ");
            String numeroFactura = entrada.next();
            int indiceFactura = buscarIndiceDeLaFactura(numeroFactura);
            if (indiceFactura == -1) { //ES PORQUE LA FACTURA NO ESTÁ
//                System.out.println("error el codigo de factura no existe...!!!");
                System.out.print("Desea usted volver a intentar con otra referencia de factura?[S/N]: ");
                opcion = entrada.next().charAt(0);
            } else { //ES PORQUE LA FACTURA SÍ ESTÁ
                mostrarFactura(indiceFactura, numeroFactura); //AQUÍ ESTOY ENVIANDO EL NUMERO DE FACTURA       ¡PENDIENTE POR REVISAR!
                System.out.println("Advertimos!... si utd elimina este codigo_factura, ");
                System.out.println(" igualmente se eliminarán todos los registros de ventas_detalle ");
                System.out.println(" que esten presentes en esta factura... ");
                System.out.print(" Realmente desea eliminar la factura Nro." + numeroFactura + " [S/N] ?");
 
                char opcion2 = 's';
                opcion2 = entrada.next().charAt(0);
                if (opcion2 == 's' || opcion2 == 'S') {
//                    //1.SUMARÉ LOS PRODUCTOS QUE CONTENGA LA FACTURAVENTASDETALLES CON LA CANTIDAD DEL STOCK
                    sumarCantidadDeFacturaConCantidadDelStock(indiceFactura, numeroFactura);
//                    //2.ELIMINARÉ LA FACTURA DE LA MATRIZ VENTAS
                    int contador = 0;
                    for (int i = 0; i < cantidadVentas; i++) {
                        if (i <= indiceFactura) {
                            contador++;
                        }
                    }
 
                    ventas[contador - 1][0] = "-1";//no se le pudo colocar eliminado aqui
                    ventas[contador - 1][1] = "eliminado";
                    ventas[contador - 1][2] = "eliminado";
                    ventas[contador - 1][3] = "eliminado";
                    System.out.println("Factura No. " + numeroFactura + " ha sido eliminada correctamente");
                    System.out.print("Desea eliminar otra factura?[S/N]: ");
                    opcion = entrada.next().charAt(0);
                } else {
                    opcion = 'n';
                }
            }
        } while (opcion == 's' || opcion == 'S');
    }
 
    private static void sumarCantidadDeFacturaConCantidadDelStock(int indiceFactura, String numeroFactura) { //PROCEDIMIENTO PORQUE NO RETORNA NINGÚN VALOR PERO TIENE ARGUMENTOS. . ES static PORQUE PUEDE SER INVOCADO SIN NECESIDAD DE EXISTIR OTRA CLASE
        for (int i = 0; i < cantidadVetasDetalles; i++) {
            int indice = buscarIndiceDelProducto(ventasDetalles[i][1]); //<<<QUE HAY AQUÍ? CÓDIGO DEL PRODUCTO
            if (ventasDetalles[i][0].equals(numeroFactura)) {
                productos[indice][2] = Integer.parseInt(productos[indice][2]) + Integer.parseInt(ventasDetalles[i][2]) + "";
            }
        }
    }//FIN MOSTRAR FACTURA
 
    private static void listarFacturas() {
        System.out.println("___________________________");
        System.out.println("_____LISTA DE FACTURAS_____");
        String formato = "%-30s%-30s%-30s%-30s%-30s%n";
        System.out.printf(formato, "fecha_hora", "codigo_factura", "cliente", "direccion", "total");
        int acumulador = 0;
        for (int i = 0; i < cantidadVentas; i++) {
            System.out.println("=====================================================================================================================================");
            //ventas[cantidadVentas][0] = numeroFactura;
            //ventas[cantidadVentas][1] = fechaActual;
            if (ventas[i][0] != "-1") {
                System.out.printf(formato, ventas[i][1], ventas[i][0], ventas[i][2], ventas[i][3], "$" + totalPorReferenciaDeFactura(Integer.parseInt(ventas[i][0])));
                acumulador += totalPorReferenciaDeFactura(Integer.parseInt(ventas[i][0]));
            } else {
                System.out.println("");
            }
        }
        System.out.println("=========================================================================================================================================");
        System.out.print("TOTAL AL MOMENTO: $" + acumulador);
        System.out.println("");
    }
 
    private static void OrdenFacturasSegunTotal(String condicionFactura) {
        for (int i = 0; i < cantidadVentas; i++) {
            for (int j = i + 1; j < cantidadVentas; j++) {
                double var1 = Integer.parseInt(ventas[i][0]);//1,2
                double var2 = Integer.parseInt(ventas[j][0]);//2,1
                boolean bandera = false;
                if (condicionFactura.equals(condicionFactura)) {
                    if (var1 < var2) {
                        bandera = true;
                    }
                }
 
                if (condicionFactura.equals(condicionFactura)) {
                    if (var1 > var2) {
                        bandera = true;
                    }
                }
 
                if (bandera == true) {
                    String Auxiliar[] = ventas[i];//Auxiliar = 1, Auxiliar = 2
                    ventas[i] = ventas[j];//2,1
                    ventas[j] = Auxiliar;//1,2
                }
            }
        }
    }
 
    private static void facturasMayoresAMenores() {
        System.out.println("____________________________________________");
        System.out.println("   FACTURAS DE MAYOR MONTO A MENOR MONTO");
        String ventas = "VentasSuperiores";
        OrdenFacturasSegunTotal(ventas);
        listarFacturas();
    }
 
    private static void facturasMenoresAMayores() {
        System.out.println("____________________________________________");
        System.out.println("    FACTURAS DE MENOR MONTO A MAYOR MONTO   ");
        String ventas = "VentaInferiores";
        OrdenFacturasSegunTotal(ventas);
        listarFacturas();
    }
 
    private static void consultarFacturasSuperiores() {
        String format = "%-25s%-25s%-25s%-25s%n";
        System.out.println("____________________________________________________________________________________________________");
        System.out.print("Digite un valor cualquiera: ");
        int valor = entrada.nextInt();
        System.out.printf(format, "Fecha", "No. factura", "Cliente", "Total");
        for (int i = 0; i < cantidadVentas; i++) {
            if (calcularTotalFactura(ventas[i][0]) > valor) {
                System.out.printf(format, ventas[i][1], ventas[i][0], ventas[i][2], calcularTotalFactura(ventas[i][0]));
            }
        }
        System.out.println("____________________________________________________________________________________________________");
    }
 
    private static void boletinGeneralFacturas() {
        System.out.println("Boletin de ventas de todos los totales");
        int acumTotalMomento = 0;
        int acumTotalAuxiliar = 0;
        for (int i = 0; i < cantidadVentas; i++) {
            System.out.println("____________________________________________________________________");
            int indice;
            System.out.println("Codigo_factura      ==>" + ventas[i][0]);
            System.out.println("Hora y fecha:          " + ventas[i][1]);
            System.out.println("Cliente:            ==>" + ventas[i][2]);
            System.out.println("Direccion:             " + ventas[i][3]);
            String codigoFac = ventas[i][0];
            for (int j = 0; j < cantidadVetasDetalles; j++) {
                if (codigoFac.equals(ventasDetalles[j][0])) {
                    indice = buscarIndiceDelProducto(ventasDetalles[j][1]);
                    System.out.println("");
                    System.out.println("Codigo_produto:        " + productos[indice][0]);
                    System.out.println("Producto:              " + productos[indice][1] + " ------->Stock_actual: " + productos[indice][2]);
                    System.out.println("Cantidad:              " + ventasDetalles[j][2]);//es la cantidad del producto q se vendió
                    System.out.println("Vlr_Unitario_Producto: " + productos[indice][5]);
                    int cantidad = Integer.parseInt(ventasDetalles[j][2]);
                    int vlrUnitario = Integer.parseInt(ventasDetalles[j][3]);
                    int subtotal = cantidad * vlrUnitario;
                    System.out.println("subtotal= $" + subtotal);
                    System.out.println("");
                    acumTotalMomento += subtotal;
                }//cierro if
            }//cierro for
            System.out.println("Totalidades $: " + acumTotalMomento);
            acumTotalAuxiliar += acumTotalMomento;//estoy salvando la cantidad que haya guardado el acumulador
            acumTotalMomento = 0;//estoy inicializando en cero este acumulador
            System.out.println("____________________________________________________________________");
        }//cierro for
        System.out.print("MONTO TOTAL AL MOMENTO: " + acumTotalAuxiliar);//$23700000
        System.out.println("");
        System.out.println("");
    }
 
    private static void montoTotalDineroEnFacturas() { //PROCEDIMIENTO PORQUE NO RETORNA NINGÚN VALOR. . ES static PORQUE PUEDE SER INVOCADO SIN NECESIDAD DE EXISTIR OTRA CLASE
        System.out.println("____________________________");
        System.out.println("_____MONTO TOTAL EN CAJA____");
        int acumuladorDinero = 0;//acumulador supremo facturas totalesa
        String formato = "%-20s%-20s%n";
        System.out.printf(formato, "No.Factura", "Valor");
        System.out.println("============================");
        for (int i = 0; i < cantidadVentas; i++) {
            System.out.printf(formato, ventas[i][0], "$" + totalPorReferenciaDeFactura(Integer.parseInt(ventas[i][0])));
            acumuladorDinero += totalPorReferenciaDeFactura(Integer.parseInt(ventas[i][0]));
        }
        System.out.println("<========================> TOTAL EN PESOS : $" + acumuladorDinero + "<========================>");
    }//FIN MONTO DINERO TOTAL DE VENTAS
 
    private static void productosEscasos() { //PROCEDIMIENTO PORQUE NO RETORNA NINGÚN VALOR. . ES static PORQUE PUEDE SER INVOCADO SIN NECESIDAD DE EXISTIR OTRA CLASE
        System.out.println("____________________________________________________________________________________________________");
        System.out.println("                        PRODUCTOS ESCASOS");
        System.out.println("                     ------------------------");
        String format = "%-30s%-30s%-30s%-30s%-30s%-30s%n";
        System.out.printf(format, "codigo_producto", "producto", "stock", "stock_min", "Stock_max", "Vlr_unitario");
 
        for (int i = 0; i < cantidadProductos; i++) {
            if (Integer.parseInt(productos[i][2]) <= Integer.parseInt(productos[i][3])) {
                System.out.printf(format, productos[i][0], productos[i][1], productos[i][2], productos[i][3], productos[i][4], productos[i][5]);
            }
        }
        System.out.println("____________________________________________________________________________________________________");
    }
 
    private static void productosEscasos2() {
        System.out.println("                        PRODUCTOS ESCASOS");
        System.out.println("                     ------------------------");
        System.out.println("No hay productos escasos por el momento...!");
        System.out.println("____________________________________________________________________________________________________");
        System.out.println("");
    }
 
    private static int buscarIndiceDelProducto(String referenciaProducto) {
        int indice = -1;//1ro creo una variable y lo inicializo en -1. Este -1 es cuando no se encuentra el indice solicitado
        int contador = 0;//2do creo un contador y lo inicializo en 0. Este 0 es un contador que sabe la posicion de la referencia del producto
        while (indice == -1 && contador < cantidadProductos) {
            if (referenciaProducto.equals(productos[contador][0])) { //contador solo permite desplazarse en la matriz
                indice = contador;
            } else {
                indice = -1;
            }
            contador++;
        }
        return indice;
    }//FUNCION 1
 
    private static int buscarReferenciaDelProductoEnVentasDetalles(String referenciaProducto) {
        int indice = -1;
        int contador = 0;
        while (indice == -1 && contador < cantidadVetasDetalles) {
            if (referenciaProducto.equals(ventasDetalles[contador][1])) {
                indice = contador;
            } else {
                indice = -1;
            }
            contador++;
        }
        return indice;
    }//FUNCION 2
 
    private static int ReferenciaFacturaAutomatico() {
        int var = cantidadVentas;
        if (var == 0) {
            var = var + 1;
        }
        if (var > 0) {
            var = cantidadVentas + 1;
        }
        return var;
    }//FUNCION 3
 
    private static int totalPorReferenciaDeFactura(int ReferenciaFactura) {
        int total = 0;
        for (int j = 0; j < cantidadVetasDetalles; j++) {
            if ((ReferenciaFactura + "").equals(ventasDetalles[j][0])) {
                total += Integer.parseInt(ventasDetalles[j][3]) * Integer.parseInt(ventasDetalles[j][2]);
            }
        }
        return total;
    }//FUNCION 4
 
    private static int buscarIndiceDeLaFactura(String referenciaFactura) {
        int indice = -1;
        int contador = 0;
        while (indice == -1 && contador < cantidadVentas) {
            if (referenciaFactura.equals(ventas[contador][0])) {
                indice = contador;
            } else {
                indice = -1;
            }
            contador++;
        }
        return indice;
    }//FUNCION 5
 
    private static int calcularTotalFactura(String referenciaFactura) {
        int acumulador = 0;
        int resultado;
        for (int i = 0; i < cantidadVetasDetalles; i++) {
            if (ventasDetalles[i][0].equals(referenciaFactura)) {
                resultado = Integer.parseInt(ventasDetalles[i][2]) * Integer.parseInt(ventasDetalles[i][3]);
                acumulador = acumulador + resultado;
            }
        }
        return acumulador;
    }//FUNCION 6
 
    private static boolean funcion_MensajeDeProductosEscasos(int contador) {
        boolean banderaAux = false;
        for (int i = 0; i < cantidadProductos; i++) {
            if (Integer.parseInt(productos[i][2]) <= Integer.parseInt(productos[i][3])) {
                contador++;
            }
        }
        if (contador > 0) {
            banderaAux = false;
        } else {
            banderaAux = true;
        }
        return banderaAux;
    }
}//FUNCION 7



Comentarios sobre la versión: javaConsola (1)

asfafs
7 de Octubre del 2021
estrellaestrellaestrellaestrellaestrella
1
2
3
Reemplace este t[b]Reemplace este texto[[ind

='editor_line'>

Reemplace este texto
ent]Reemplace este texto[/indent]/b]exto
Responder

Comentar la versión: javaConsola

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/s6862