proyecto productos matrices -metodos-crud
Java
Publicado el 4 de Febrero del 2021 por Carlos
4.709 visualizaciones desde el 4 de Febrero del 2021
Este código sirve para llevar el inventario en un almacén de productos
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)