Más contenido relacionado La actualidad más candente (20) Similar a Factura en borland c++ (20) Factura en borland c++1. #include <ctype.h> // isdigit
#include <stdlib.h> // atoi
#include <string.h> // strlen
#include <stdio.h> // printf, fgets, stdin, BUFSIZ
#include<iostream> //cout, cin
#include<fstream>
#include<stdlib> //system()
#include<stdio>
#include<conio> //gotoxy
#include<cstring>
//funciones
int nuevaFactura();
void menu();
int BDFactura();
int Buscar_Factura();
int Buscar_Clientes();
int Ingreso_Menu(char buffer[BUFSIZ]);
int demeNumero(int y,int x);
bool ingreso_cadena_con_espacio(char letras2[]);
bool ingreso_cadena(char letras[]);
//Estructura para el detalle
struct
{
int nProducto[30];//es el numero de producto osea Num.
int numFactura; //numero de la factura
int cantidad[30];//se puede almacenar hasta 30 cantidades
char nomProducto[30][30]; //almaceno caracteres con espacio; es el nombre
del producto
char medida[10][30]; //almaceno caracteres con espacio; es la medida
del producto
int numProductos; //es cuantos productos voy a ingresar
double precioUnitario[30];
double precioTotal[30];
double SubTotal;
double IVA;
double Total;
} Detalle;
//Estructura para la factura
struct
{
int numFactura;
char nombre[30];
char apellido[30];
int cedula;
char direccion[70];
int telefono;
char fecha[12];
char vendedor[30];
double total;
} Facturas;
int main(void)
{
int opcion;
do //ciclo repetir asta que
{
system("cls");//borrar pantalla
menu();//menu de opciones
char buffer[BUFSIZ];//hacemos el nuevaFactura numerico con buffer
opcion=Ingreso_Menu(buffer);//en la funcion Ingreso_Menu(buffer) se hace
el nuevaFactura
2. system("cls");//borrar pantalla
switch(opcion)//seleccion de en caso que respuesta se
{
case 1:
nuevaFactura();
break;//sea uno llama al procedimiento nuevaFactura arriba
case 2:
Buscar_Factura();
system("pause");
break;//llama ala funcion ver datos
case 3:
Buscar_Clientes();
system("pause");
break;//llama ala funcion ver datos
case 4:
BDFactura();
system("pause");
break;//llama ala funcion ver datos
case 5:
system("cls");
cout<<"nnnntQue tenga buenos diasnnn";
system("pause");
exit(1);
break;//cierra el programa
default:
cout<<"nn numero incorrecto intente nuevamente!nn";
system("pause");
break;//lanza un mensaje y vuelve a mostrar los datos
}
}
while(opcion!=5);
system("pause");
return 0;
}
//Menu
void menu(){
//menu para que el usuario se guie.
gotoxy(19,19);printf("%c", 201);//esquina superior izquierda
gotoxy(61,19);printf("%c", 187);//esquina superior derecha
gotoxy(19,39);printf("%c", 200);//esquina inferior izquierda
gotoxy(61,39);printf("%c", 188);//esquina inferior derecha
for(int k=20; k<61; k++){//dibujamos las lineas horizontales
gotoxy(k,19);printf("%c", 205);
gotoxy(k,39);printf("%c", 205);
}
for(int k=20; k<39; k++){//dijumos las lineas verticales
gotoxy(19,k);printf("%c", 186);
gotoxy(61,k);printf("%c", 186);
}
gotoxy(22,22);cout<<" * La tienda xxxxxxxx S.A. * ";
for(int k=20; k<61; k++){//dibujamos linea horizontal
gotoxy(k,24);printf("%c", 205);
}
gotoxy(24,26);cout<<" FACTURACION ";
gotoxy(20,27);cout<<"_________________________________________";
gotoxy(26,30);cout<<"1 - Nueva Factura ";
gotoxy(26,31);cout<<"2 - Buscar numero de factura ";
gotoxy(26,32);cout<<"3 - Buscar apellido de Cliente";
gotoxy(26,33);cout<<"4 - Base de datos ";
gotoxy(26,34);cout<<"5 - Exit ";
gotoxy(27,36);printf("Ingrese opcion %c ", 175 );//solicitud de su
respuesta
}
3. //opcion 1
int nuevaFactura()
{
char numero[10];
system("cls");//borrar pantalla
gotoxy(1,1); printf("%c", 201);//esquina superior izquierda
gotoxy(80,1); printf("%c", 187);//esquina superior derecha
gotoxy(1,44); printf("%c", 200);//esquina inferior izquierda
gotoxy(80,44);printf("%c", 188);//esquina inferior derecha
for(int k=2; k<80; k++){//dibujamos las lineas horizontales
gotoxy(k,1); printf("%c", 205);
gotoxy(k,6); printf("%c", 205);
gotoxy(k,44);printf("%c", 205);
gotoxy(k,9); printf("_");
gotoxy(k,14);printf("_");
}
for(int k=2; k<44; k++){//dijumos las lineas verticales
gotoxy(1,k); printf("%c", 186);
gotoxy(80,k);printf("%c", 186);
}
gotoxy(25,4);cout<<" * La tienda xxxxxxxx S.A. * ";
gotoxy(34,8);cout<<" NUEVA FACTURA ";
// captura de campos
gotoxy(10,12);cout << "Fecha : ";
gotoxy(37,12);cout << "Vendedor : ";
gotoxy(10,13);cout << "Factura No: ";
gotoxy(18,12);cin >> Facturas.fecha;
char letras[10];
do{
gotoxy(48,12);gets(letras);
if(ingreso_cadena_con_espacio(letras)==true){
strcpy(Facturas.vendedor,letras);
}else{
gotoxy(48,12);clreol();
}
}while(ingreso_cadena_con_espacio(letras)==false);
gotoxy(22,13);Facturas.numFactura=demeNumero(22,13);
gotoxy(30,14);cout << " DATOS DEL CLIENTE ";
gotoxy(10,16);cout << "Nombre : ";
gotoxy(37,16);cout << "Apellido : ";
gotoxy(37,17);cout << "Cedula : " ;
gotoxy(10,17);cout << "Direccion : ";
gotoxy(10,18);cout << "Telefono : ";
do{
gotoxy(19,16);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Facturas.nombre,letras);
}else{
gotoxy(19,16);clreol();
gotoxy(37,16);cout << "Apellido : ";
}
}while(ingreso_cadena(letras)==false);
do{
gotoxy(48,16);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Facturas.apellido,letras);
}else{
gotoxy(48,16);clreol();
}
}while(ingreso_cadena(letras)==false);
do{
gotoxy(22,17);gets(letras);
4. if(ingreso_cadena_con_espacio(letras)==true){
strcpy(Facturas.direccion,letras);
}else{
gotoxy(22,17);clreol();
gotoxy(37,17);cout << "Cedula : " ;
}
}while(ingreso_cadena_con_espacio(letras)==false);
gotoxy(46,17);Facturas.cedula=demeNumero(46,17);
gotoxy(21,18);Facturas.telefono=demeNumero(21,18);
Detalle.numFactura = Facturas.numFactura;
gotoxy(3,21);printf("Ingrese el numero de productos: ");
gotoxy(35,21);Detalle.numProductos=demeNumero(35,21);
//aqui estan las lineas del nembrete del detalle
gotoxy(2,22);
printf("________________________________________________________________________
______");
gotoxy(2,25);
printf("________________________________________________________________________
______");
//dibujo las lineas verticales del nembrete del detalle
for(int i=0; i<4; i++){
gotoxy(8,23+i); printf("%c", 179);
gotoxy(28,23+i);printf("%c", 179);
gotoxy(39,23+i);printf("%c", 179);
gotoxy(49,23+i);printf("%c", 179);
gotoxy(64,23+i);printf("%c", 179);//espacio para P. Total
}
//ubicamos en pantalla los rotulos del detalle
gotoxy(3,24);printf("Num.");
gotoxy(10,24);cout << "DETALLE PRODUCTO";
gotoxy(30,24);cout << "CANTIDAD";
gotoxy(40,24);cout << "Kg,lbs..";
gotoxy(52,24);cout << "P. Unitario";
gotoxy(67,24);cout << "P. Total";
int i=27,j=0;//posiciones en pantalla
Detalle.SubTotal= Detalle.nProducto[j];//acumula el preciototal
while(j<Detalle.numProductos)
{
gotoxy(3,i);printf(" %d ",j+1); Detalle.nProducto[j]=j+1;//numero
de articulo
char nombreProducto[30],medida_kg_lts[10];
gotoxy(11,i);gets(nombreProducto);strcpy(Detalle.nomProducto[j],nombreProducto);
gotoxy(33,i);Detalle.cantidad[j]=demeNumero(33,i);
do{
gotoxy(44,i);gets(letras);
if(ingreso_cadena(letras)==true){
strcpy(Detalle.medida[j],letras);
}else{
gotoxy(44,i);clreol();
}
}while(ingreso_cadena(letras)==false);
gotoxy(57,i); cin>> Detalle.precioUnitario[j]; //puede ser entero o
flotante hay que hacer validacion
Detalle.precioTotal[j]= Detalle.cantidad[j] *
Detalle.precioUnitario[j];//calculo del subtotal
gotoxy(70,i);printf("%5.2f",Detalle.precioTotal[j]);
Detalle.SubTotal= Detalle.precioTotal[j] +
Detalle.SubTotal;//acumulo en SubTotal los precios Totales
gotoxy(2,i+1);printf("- - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - ");
gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle
5. gotoxy(28,i); printf("%c", 179);
gotoxy(39,i); printf("%c", 179);
gotoxy(49,i); printf("%c", 179);
gotoxy(64,i); printf("%c", 179);
i=i+1; //contador para las posiciones de las lineas en pantalla
gotoxy(8,i); printf("%c", 179);//lineas verticales del detalle
gotoxy(28,i); printf("%c", 179);
gotoxy(39,i); printf("%c", 179);
gotoxy(49,i); printf("%c", 179);
gotoxy(64,i); printf("%c", 179);
i=i+1;
j=j+1; //acumulador para el numero de productos
}
gotoxy(2,i-
1);printf("_____________________________________________________________________
_________");
i=i+2;
Detalle.IVA=Detalle.SubTotal*0.12;
Detalle.Total= Detalle.SubTotal+Detalle.IVA;
Facturas.total=Detalle.Total;
gotoxy(52,i); printf("Subtotal : $ %5.2f",Detalle.SubTotal);
gotoxy(52,i+2);cout <<"IVA. 12% : ";printf("$ %5.2f",Detalle.IVA);
gotoxy(52,i+4);printf("- - - - - - - - - -n");
gotoxy(52,i+6); printf(" Total -> $ %5.2f",Detalle.Total);
gotoxy(2,i+8);printf("__________________________________________________________
____________________");
getch();
//Grabamos a disco la estructura factura
FILE *archdisco_factura;
archdisco_factura = fopen("c:factura.txt","at+");
fwrite(&Facturas,sizeof(Facturas),1,archdisco_factura);
fclose(archdisco_factura);
//avisando usuario
// cout << "nntfactura insertada " << endl;
//Grabamos a disco la estructura detalle
FILE *archdisco_detalle;
archdisco_detalle = fopen("c:detalle.txt","at+");
fwrite(&Detalle,sizeof(Detalle),1,archdisco_detalle);
fclose(archdisco_detalle);
//avisando usuario
cout << "tFactura guardada con exito n" << endl;
system("pause");
return 0;
}
//opcion 2
int Buscar_Factura()
{
int factura;
cout << "nnIngrese numero de factura a buscar: ";
gotoxy(37,3);factura=demeNumero(37,3);
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_detalles;
archdisco_open_detalles = fopen("c:detalle.txt","r");
//leemos el archivo de datos
bool encontrado = false;
cout << "n"<< endl;
while(fread(&Detalle,sizeof(Detalle),1,archdisco_open_detalles)==1)
{
if (factura == Detalle.numFactura)
{
cout << "|| Factura No = " << Detalle.numFactura << endl;
for(int j=0; j <Detalle.nProducto[j]; j++){
6. cout << "|| Num." << Detalle.nProducto[j] << endl;
cout << "|| "<<endl;
cout << "|| Producto = " << Detalle.nomProducto[j] << endl;
cout << "|| Cantidad = " << Detalle.cantidad[j] << endl;
cout << "|| Medida = " << Detalle.medida[j] << endl;
printf("|| P. Unit. = %5.2f",Detalle.precioUnitario[j]);
printf("n");
printf("|| P. Total = %5.2f",Detalle.precioUnitario[j]);
printf("n");
}
cout << "||"<<endl;
cout << "|| SUBTOTAL = " << Detalle.SubTotal << endl;
cout << "|| IVA. 12% = ";printf("$ %5.2f",Detalle.IVA);
printf("n");
printf("|| TOTAL -> $ %5.2f",Detalle.Total);
cout << "n________________________________________________________n"
<< endl;
encontrado = true;
}
};
if (encontrado==false)
{
cout <<"nnLa factura: " << factura << " no fue hallada" << endl;
}
//Cerramos el archivo.
fclose(archdisco_open_detalles);
return 0;
}
//opcion 3
int Buscar_Clientes()
{
char apellido_a_buscar[30];
char * pch;
int caracter;
bool encontrado = false;
char texto_a_buscar[30];
cout << "nnIngrese parte del Apellido a buscar: ";
do{
gotoxy(38,3);gets(texto_a_buscar);
if(ingreso_cadena(texto_a_buscar)==false){
gotoxy(38,3);clreol();
}
}while(ingreso_cadena(texto_a_buscar)==false);
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_Facturas;
archdisco_open_Facturas = fopen("c:factura.txt","r");
//leemos el archivo de datos e informamos
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
strcpy (apellido_a_buscar, Facturas.apellido);
pch = strstr (apellido_a_buscar, texto_a_buscar);
caracter = pch - apellido_a_buscar + 1;
if (caracter >= 0)
{
cout << " nnApellido : " << texto_a_buscar << " fue encontrado..."
<< endl;
cout <<
"n________________________________________________________n" << endl;
cout << "|| - Fecha = " << Facturas.fecha << endl;
cout << "|| Fact. No = " << Facturas.numFactura << endl;
cout << "|| Apellido = " << Facturas.apellido << endl;
cout << "|| Nombre = " << Facturas.nombre << endl;
cout << "|| Cedula = " << Facturas.cedula << endl;
7. cout << "|| Direccion = " << Facturas.direccion << endl;
cout << "|| Telefono = " << Facturas.telefono << endl;
cout << "|| "<<endl;
printf(" || TOTAL -> $ %5.2f",Facturas.total);
cout <<
"n________________________________________________________n" << endl;
encontrado=true;
}
};
if (encontrado==false)
{
cout <<"nnEl apellido buscado: " << texto_a_buscar << " no fue
encontrado" << endl;
}
//Cerramos el archivo.
fclose(archdisco_open_Facturas);
return 0;
}
//opcion 4
int BDFactura()
{
int cantidad = 0;
//abrimos el archivo que contiene la estructura
FILE *archdisco_open_Facturas;
archdisco_open_Facturas = fopen("c:factura.txt","r");
//verificamos el numero de elementos de la misma.
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
cantidad++;
};
//Lo informamos al usuario
cout << "nn" << endl;
printf("La base de datos contiene %d facturasn", cantidad);
cout << "nn" << endl;
system("pause");
rewind(archdisco_open_Facturas);
//volvemos a leer el archivo de datos e informamos
while(fread(&Facturas,sizeof(Facturas),1,archdisco_open_Facturas)==1)
{
cout << "|| - Fecha = " << Facturas.fecha << endl;
cout << "|| Fact. No = " << Facturas.numFactura << endl;
cout << "|| Nombre = " << Facturas.nombre << endl;
cout << "|| Apellido = " << Facturas.apellido << endl;
cout << "|| Cedula = " << Facturas.cedula << endl;
cout << "|| Direccion = " << Facturas.direccion << endl;
cout << "|| Telefono = " << Facturas.telefono << endl;
cout << "|| Vendedor = " << Facturas.vendedor << endl;
cout << "||"<<endl;
printf("|| Total -> $ %5.2f",Facturas.total);
cout << "n________________________________________________________n"
<< endl;
};
//Cerramos el archivo.
fclose(archdisco_open_Facturas);
return 0;
}
int Ingreso_Menu(char buffer[BUFSIZ]){
int number;
unsigned n;
bool found_nondigit, valid;
valid = false;
8. while (!valid) {
//printf ( "Enter an integer: " );
if (fgets (buffer, sizeof buffer, stdin) != NULL) {
buffer[strlen(buffer)-1] = '0';
found_nondigit = false;
if (strlen(buffer) == 0)
found_nondigit = true;
for (n=0; n<strlen(buffer); n++)
if (!isdigit(buffer[n]))
found_nondigit = true;
if (!found_nondigit) {
number = atoi(buffer);
//printf ("%dn", number);
valid = true;
} else{
system("cls");//borrar pantalla
menu();
gotoxy(26,36);
cout<< "Re-ingrese numero -> ";
}
}
}
// system("pause");
return number;
}
int demeNumero(int y,int x){
int t,valcomplex;
bool valida=false;
int digito=0,i=0,a=0;
do{
while ((t = getchar()) != 'n'){
if(isdigit(t)){
valcomplex=t-'0';
t=getchar();
digito++;
while(isdigit(t)){
valcomplex=valcomplex*10+t-'0';
t=getchar();
digito++;
i++;
}
ungetc(t,stdin);
}
i++;
}
if(i==digito){
valida =true;
}else{
digito=0;
i=0;
valida =false;
gotoxy(y,x);
clreol();
}
}while(valida==false);
return valcomplex;
}
bool ingreso_cadena(char letras[]){
int i=0,abc=0;
while(letras[i]){
if (isalpha(letras[i])){
abc++;
9. }
i++;
}
if(i==abc){
return true; //esta bien ingresado el numero
}else{
return false;
}
}
bool ingreso_cadena_con_espacio(char letras2[]){
int i=0,abc=0,blanco=0;
while(letras2[i]){
if (isalpha(letras2[i])){
abc++;
}
else
{
if(letras2[i]=' ');
blanco++;
}
i++;
}
if(blanco==0){
if(abc==i)
return true; //esta bien ingresado el numero
}
else
{
if(blanco==1){
if(i==(blanco+abc))
return true; //esta bien ingresado el numero
}
else
{
return false;
}
}
}
10. }
i++;
}
if(i==abc){
return true; //esta bien ingresado el numero
}else{
return false;
}
}
bool ingreso_cadena_con_espacio(char letras2[]){
int i=0,abc=0,blanco=0;
while(letras2[i]){
if (isalpha(letras2[i])){
abc++;
}
else
{
if(letras2[i]=' ');
blanco++;
}
i++;
}
if(blanco==0){
if(abc==i)
return true; //esta bien ingresado el numero
}
else
{
if(blanco==1){
if(i==(blanco+abc))
return true; //esta bien ingresado el numero
}
else
{
return false;
}
}
}