Está en la página 1de 6

#include "stdafx.

h"
#include "Windows.h"

#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <iomanip>

using namespace std;

string moneda[] = { "Soles", "Dolares", "Euros" };


double IGV = 18.0;
double ganancia = 0;

struct Comprador {
string nombre;
string apellidos;
string direccion;

};

struct Producto {
string codigo;

string descripcion;
double precio;
};

struct Fecha {
int dia;
int mes;
int anho;

int hor;
int min;
};

struct Detalle {
Producto prod;

int cantidad;
double costo;
};

struct Venta {
Fecha f;
Comprador comp;
double total;
double igv;

int nProds ;
Detalle prod[128];

int tipoMoneda ;
};
Venta venta[128];
int nVentas = 0;
Producto prod[128];
int nProds = 0;

bool hayVenta = false;

string verFecha(Fecha f) {
return "" + to_string(f.dia) + "-" + to_string(f.mes) + "-" +
to_string(f.anho) + " "
+ to_string(f.hor) + ":" + to_string(f.min);
}

string verComprador(Comprador comp) {


return comp.apellidos + " " + comp.nombre;
}

void llenarFecha(int idx) {


time_t t = time(0);
tm now;

localtime_s(&now, &t);
venta[idx].f.min = now.tm_min;
venta[idx].f.hor = now.tm_hour;
venta[idx].f.dia = now.tm_mday;
venta[idx].f.mes = now.tm_mon + 1;
venta[idx].f.anho = now.tm_year + 1900;
}

char menu() {
system("CLS");
char op;

cout << " MENU PRINCIPAL" << endl;


cout << " IGV: " << IGV << "%" << endl;
cout << " Ganancias: S/. " << ganancia << endl
<< endl;

if (!hayVenta)
cout << " 1. Nueva venta." << endl;
else
cout << " 1. Ver venta actual." << endl;
cout << " 2. Historial de Ventas." << endl;
cout << " 3. Nuevo producto." << endl;
cout << " 4. Ver productos." << endl;
cout << " 5. Cambiar IGV." << endl;
cout << " 6. Salir." << endl << endl;

cout << " Opcion: ";


cin >> op;

return op;
}

int buscarProducto(string codigo) {


for (int i = 0; i < nProds; i++) {
if (prod[i].codigo == codigo) return i;
}
return -1;
}

int buscarProducto(int idVenta, string codigo) {


for (int i = 0; i < venta[idVenta].nProds; i++) {
if (venta[idVenta].prod[i].prod.codigo == codigo) return i;
}
return -1;
}

void verDetalleVenta(int idx) {


system("CLS");

int op;

cout << " DETALLE DE VENTA" << endl << endl;


cout << " Fecha: " << verFecha(venta[idx].f) << endl;
cout << " Comprador: " << verComprador(venta[idx].comp) << endl;
cout << " Direccion: " << venta[idx].comp.direccion << endl;
cout << " Moneda de Pago: " << moneda[venta[idx].tipoMoneda] << endl;
cout << " IGV: " << venta[idx].igv << "%" << endl << endl;

cout << "Lista de Productos: " << endl;

cout << "Codigo \t Descripcion \t Precio U. (S/.) \t Cantidad \t SubTotal


(S/.)" << endl;
double total = 0;
for (int i = 0; i < venta[idx].nProds; i++) {
Detalle d = venta[idx].prod[i];
Producto p = d.prod;
total += d.costo;
cout << p.codigo << "\t" << p.descripcion << "\t" << p.precio << "\t"
<< d.cantidad << "\t" << d.costo << endl;
}
cout << endl << "Total: " << total << endl;
cout << "Total con IGV: " << venta[idx].total << endl;

if (hayVenta && idx == nVentas - 1) {


cout << endl << " Desea cerrar venta? (SI = 1 / NO = 0) : ";
cin >> op;
if (op) {
hayVenta = false;
ganancia += venta[idx].total;
}
}
}

void verVentas() {
system("CLS");
int op, nro;

cout << "Nro \t Comprador \t Fecha \t Cant. Productos \t Moneda \t Costo


Total (S/.)" << endl;
for (int i = 0; i < nVentas; i++) {
cout << i + 1 << "\t" << verComprador(venta[i].comp) << "\t" <<
verFecha(venta[i].f) << "\t"
<< venta[i].nProds << "\t" << moneda[venta[i].tipoMoneda] <<
"\t" << venta[i].total << endl;
}
cout << endl;
cout << "Deseas detalle de una venta? (SI = 1 / NO = 0) : ";
cin >> op;
if (op) {
cout << " Ingrese Numero de Venta: ";
cin >> nro;
if (nro <= nVentas) verDetalleVenta(nro - 1);
}
}

void nuevoProducto() {
system("CLS");

cout << " NUEVO PRODUCTO" << endl << endl;

cout << " Codigo: ";


cin >> prod[nProds].codigo;

cin.ignore();
cout << " Descripcion: ";
getline(cin, prod[nProds].descripcion);

cout << " Precio (S/.): ";


cin >> prod[nProds].precio;

nProds++;
}

void nuevaVenta() {
system("CLS");

cout << " NUEVA VENTA" << endl << endl;


llenarFecha(nVentas);

cin.ignore();
cout << "Datos del Comprador: " << endl;
cout << " Apellidos: ";
getline(cin, venta[nVentas].comp.apellidos);

cout << " Nombres: ";


getline(cin, venta[nVentas].comp.nombre);

cout << " Direccion: ";


getline(cin, venta[nVentas].comp.direccion);

cout << endl;


cout << "Tipo de moneda: " << endl;
cout << " 1. Soles." << endl;
cout << " 2. Dolares." << endl;
cout << " 3. Euros." << endl;

cout << " Ingrese opcion: ";


cin >> venta[nVentas].tipoMoneda;
venta[nVentas].tipoMoneda--;

venta[nVentas].total = 0;
venta[nVentas].igv = IGV;
nVentas++;
hayVenta = true;

cout << endl;


cout << " >> PARA AGREGAR PRODUCTOS, INGRESE A LA OPCION Ver Productos <<" <<
endl << endl;
system("PAUSE");
}

void verProductos() {
system("CLS");

int op, cant;


string codigo;

cout << " LISTA DE PRODUCTOS" << endl << endl;

cout << "Codigo \t Descripcion \t Precio (S/.)" << endl;


for (int i = 0; i < nProds; i++) {
cout << prod[i].codigo << "\t" << prod[i].descripcion << "\t" <<
prod[i].precio << endl;
}

if (hayVenta) {
cout << endl << " Deseas seleccionar producto? (SI = 1 / No = 0) : ";
cin >> op;
if (op) {
cout << " Ingrese codigo: ";
cin >> codigo;
int idx = buscarProducto(codigo);
if (idx != -1) {
cout << " Ingrese cantidad: ";
cin >> cant;
int i = buscarProducto(nVentas - 1, codigo);
double v = cant * prod[idx].precio;
if (i == -1) {
venta[nVentas - 1].prod[venta[nVentas -
1].nProds].prod = prod[idx];
venta[nVentas - 1].prod[venta[nVentas -
1].nProds].cantidad = cant;
venta[nVentas - 1].prod[venta[nVentas -
1].nProds].costo = v;

venta[nVentas - 1].nProds++;
}
else {
venta[nVentas - 1].prod[i].cantidad += cant;
venta[nVentas - 1].prod[i].costo += v;
}
venta[nVentas - 1].total += (1.0 + venta[nVentas - 1].igv
/ 100.0) * v;
}
}
}
cout << endl;
system("PAUSE");
}
void cambiarIGV() {
system("CLS");
cout << " Valor IGV actual: " << IGV << "%" << endl;
cout << " Nuevo valor (%) : ";
cin >> IGV;
}

int main() {
char op;

cout << setprecision(2) << fixed;


while ((op = menu()) != '6') {
switch (op) {
case '1':
if (!hayVenta) nuevaVenta();
else verDetalleVenta(nVentas - 1);
break;
case '2':
if (nVentas > 0) verVentas();
break;
case '3':
nuevoProducto();
break;
case '4':
if (nProds > 0) verProductos();
break;
case '5':
cambiarIGV();
break;
}
}

return 0;
}

También podría gustarte