Home > C++ > C++ Project on Sales Management System

C++ Project on Sales Management System

Download Project
Share Facebook Twitter Orkut SMS

Sales Management

/*		****************************
		*  SALES MANAGEMENT SYSTEM *
		****************************
*/
#include<fstream .h>
#include<stdio .h>
#include<conio .h>
#include<string .h>
#include<dos .h>
#include<iomanip .h>
#include<ctype .h>
#include<stdlib .h>
 
struct date_rec	//	record to get date
{
short int day;
short int month;
int year;
}current_date;
 
struct node	//	structure to make an index of the record nos.
{
int rec_no;
node *link;
};
node *start,*ptr;
 
//	DECLAIRING CLASS HERE
//      this class defines data related to items
 
class item_list
{
private:
int item_code,qty_in_stock; //item code and quantity in stock
char item_name[30];
float item_rate;
public:
item_list()	//no argument constructor
{
item_code=0;
memset(item_name,0,30);
item_rate=0.0;
qty_in_stock=0;
}
void get_item();	//this function reads the private member of item file
int vallidate(int item_code,int qty);
//this function verifies item code correponding qty in stock
float update_on_sale(int ic1,int ic2,int ic3,int ic4,int ic5,
		     int iq1,int iq2,int iq3,int iq4,int iq5);
//this function updates the qty whenever item is purchased
 
void update_on_purchase(item_list temp_item);
void purchase_order();
//to generate purchase order list if stock is less than 20
 
node* create_list();  	//create an index of objects
void items_available();	//display the item available
}item;           	//object list
 
//      this class defines the data and member function related to
//	sales of an item.
 
class sales_list
{
private:
int cash_memo_num;
date_rec cash_memo_date;
int item_code1,i_qty1;
int item_code2,i_qty2;
int item_code3,i_qty3;
int item_code4,i_qty4;
int item_code5,i_qty5;
float total_amount;
 
public:
char ch;
sales_list()	//	constructor
{
item_code1=i_qty1=0;
item_code2=i_qty2=0;
item_code3=i_qty3=0;
item_code4=i_qty4=0;
item_code5=i_qty5=0;
total_amount=0.0;
}
 
//  this function checks for availability of an item and its quantity
int vallidate_item(int item_code,int qty);
 
//  this function generates record number automatically
int get_memo_no(struct date_rec current_date);
//  this function collects information to prepare cash memo
void get_chmo_info();
void show_data();	//  this function displays data
 
//   this function adds a record to the master file
void update_sales_file(int memo_num,int ic1,int ic2,int ic3,int ic4,int ic5,
		       int iq1,int iq2,int iq3,int iq4,int iq5,float amount);
void daily_sales_report(struct date_rec current_date);
}cash_memo;	//  object list
 
//  DECLARING MEMBER FUNCTIONS HERE
 
//  this member function reads the private members of class itemfile
void item_list::get_item()
{
gotoxy(20,5);
cout< <"ENTER THE ITEM CODE ------------>";
cin>>item_code;
gotoxy(20,6);
cout< <"ENTER THE ITEM NAME ------------>";
gets(item_name);
gotoxy(20,7);
cout< <"ENTER THE ITEM RATE ------------>";
cin>>item_rate;
gotoxy(20,8);
cout< <"ENTER THE QUANTITY ------------->";
cin>>qty_in_stock;
}
 
//  this member function enters a new item in itemfile, calls get_item();
 
void item_list::update_on_purchase(item_list temp_item)
{
fstream item_file;
//item.get_item();
item_file.open("itemfile.dat",ios::app | ios::in | ios::out);
// open file in append mode
int found=0;
item_file.seekg(0);
item_file.read((char*)&item,sizeof(item));
int n=item_file.tellg();
while(!item_file.eof())
   {
     if(item.item_code==temp_item.item_code)
	{
	   item.item_rate=temp_item.item_rate;
	   item.qty_in_stock=item.qty_in_stock+temp_item.qty_in_stock;
	   item_file.seekg(n-sizeof(item));
	   item_file.write((char*)&item,sizeof(item));
	   found=1;
	}
     item_file.read((char*)&item,sizeof(item));	// write in the file
     n=item_file.tellg();
   }
item_file.close();
if(found==0)
   {
   item_file.open("itemfile.dat",ios::app,ios::out);
   item_file.seekg(0,ios::end);
   item_file.write((char*)&temp_item,sizeof(temp_item));
   item_file.close();
   }
}
 
//  this member function checks for the availability of item and quantity
 
int item_list::vallidate(int i_code,int i_qty)
{
  item_list temp_item;
  fstream item_file;
  int ret=0;
  item_file.open("itemfile.dat",ios::in);
  item_file.seekg(0);
  item_file.read((char*)&temp_item,sizeof(temp_item));
while(!item_file.eof())
  {
    if(temp_item.item_code==i_code&&temp_item.qty_in_stock>=i_qty)
	ret=1;
    item_file.read((char*)&temp_item,sizeof(temp_item));
  }
item_file.close();
return ret;
}
 
float item_list::update_on_sale(int ic1,int ic2,int ic3,int ic4,int ic5,
				int iq1,int iq2,int iq3,int iq4,int iq5)
{
fstream item_file;
float amount=0;
item_file.open("itemfile.dat",ios::in);
item_file.seekg(0);//set file pointer to the begining of the file
item_file.read((char*)&item,sizeof(item));
int n=item_file.tellg();
while(!item_file.eof())
  {
    if(item.item_code==ic1)
    {
      if(item.vallidate(ic1,iq1))
      {
       gotoxy(59,9);
       cout< <setiosflags(ios::fixed)   //fixed
       <<setiosflags(ios::showpoint)   //always show point
       <<setprecision(2)           //two decimal places
       <<item.item_rate;
       item.qty_in_stock=item.qty_in_stock-iq1;
       if(item.qty_in_stock<=0)
	  item.qty_in_stock=0;
       amount=amount+(item.item_rate*iq1);
       item_file.seekg(n-sizeof(item));
       item_file.write((char*)&item,sizeof(item));
       }
     else
     {
       gotoxy(59,9);
       cout<<"NOT AVAILABLE";
       }
      }
    if(item.item_code==ic2)
    {
      if(item.vallidate(ic2,iq2))
	{
	gotoxy(59,10);
	cout<<setiosflags(ios::fixed)
	<<setiosflags(ios::showpoint)<<setprecision(2)<<item.item_rate;
	item.qty_in_stock=item.qty_in_stock-iq2;
	if(item.qty_in_stock<=0)
	item.qty_in_stock=0;
	amount=amount+(item.item_rate*iq2);
	item_file.seekg(n-sizeof(item));
	item_file.write((char*)&item,sizeof(item));
	     }
	     else
	     {
	     gotoxy(59,10);
	     cout<<"NOT AVAILABLE";
	     }
	   }
      if(item.item_code==ic3)
    {
      if(item.vallidate(ic3,iq3))
	{
	gotoxy(59,11);
	cout<<setiosflags(ios::fixed)
	<<setiosflags(ios::showpoint)<<setprecision(2)<<item.item_rate;
	item.qty_in_stock=item.qty_in_stock-iq3;
	if(item.qty_in_stock<=0)
	item.qty_in_stock=0;
	amount=amount+(item.item_rate*iq3);
	item_file.seekg(n-sizeof(item));
	item_file.write((char*)&item,sizeof(item));
	     }
	else
	   {
	    gotoxy(59,11);
	    cout<<"NOT AVAILABLE";
	    }
	  }
	  if(item.item_code==ic4)
	  {
	    if(item.vallidate(ic4,iq4))
	   {
	   gotoxy(59,12);
	   cout<<setiosflags(ios::fixed)  //fixed
	       <<setiosflags(ios::showpoint)//always show point
	       <<setprecision(2)//two decimal places
	       <<item.item_rate;
	       item.qty_in_stock=item.qty_in_stock-iq4;
	       if(item.qty_in_stock<=0)
	       item.qty_in_stock=0;
	       amount=amount+(item.item_rate*iq4);
	       item_file.seekg(n-sizeof(item));
	       item_file.write((char*)&item,sizeof(item));
	     }
	     else
	     {
	     gotoxy(59,12);
	     cout<<"NOT AVAILABLE";
	     }
	  }
	  if(item.item_code==ic5)
	  {
	  if(item.vallidate(ic5,iq5))
	  {
	  gotoxy(59,13);
	  cout<<setiosflags(ios::fixed)
	      <<setiosflags(ios::showpoint)
	      <<setprecision(2)
	      <<item.item_rate;
	  item.qty_in_stock=item.qty_in_stock-iq5;
	  if(item.qty_in_stock<=0)
	     item.qty_in_stock=0;
	  amount=amount+(item.item_rate*iq5);
	  item_file.seekg(n-sizeof(item));
	  item_file.write((char*)&item,sizeof(item));
	  }
	  else
	  {
	  gotoxy(59,13);
	  cout<<"NOT AVAILABLE";
	  }
	}
	   item_file.read((char*)&item,sizeof(item));
	   n=item_file.tellg();
	   }
	   item_file.close();
	   return amount;
	    }
     void item_list::purchase_order()
       {
       fstream item_file;
       int found=0;
       gotoxy(20,2);
       cout<<"PURCHASE ORDER LIST ON:"<<current_date.day<<"-"<<
       current_date.month<<"-"<<current_date.year;
       gotoxy(20,3);
       cout<<"--------------------------------------";
       gotoxy(22,5);
       cout<<"ITEM CODE";
       gotoxy(22,6);
       cout<<"--------------------";
       gotoxy(40,5);
       cout<<"CURRENT STOCK";
       gotoxy(40,6);
       cout<<"--------------------";
       int y=7;
       item_file.open("itemfile.date",ios::in);
       item_file.seekg(0);
       item_file.read((char*)&item,sizeof(item));
       while(!item_file.eof())
	{
	 if(item.qty_in_stock&lt;20)
	  {
	   gotoxy(25,y);
	   cout<<item.item_code;
	   gotoxy(43,y);
	   cout<<item.qty_in_stock;
	   y++;
	   found=1;
	  }
	 item_file.read((char*)&item,sizeof(item));
       }
       item_file.close();
       if(found==0)
	{
	 gotoxy(15,15);
	 cout<<"NONE OF THE ITEMS ARE LESS THAN 20 IN STOCK";
	 gotoxy(20,16);
	 cout<<"NO PURCHASE ORDER";
	}
       }
       node*item_list::create_list()
       {
       fstream item_file;
       item_file.open("itemfile.dat",ios::in);	//open file in input mode
       item_file.seekg(0);	//set the pointer to the begining of the file
       start=ptr=new node;	//get new node from operating system
       item_file.read((char*)&item,sizeof(item));	//read first record
       while(!item_file.eof())
	{
	ptr->rec_no=item.item_code;	//save record no. in the index
	ptr->link=new node;	//get new node for the record
	ptr=ptr->link;
	item_file.read((char*)&item,sizeof(item));    //read the next record
	}
	ptr->link=NULL;		//end of the list
	item_file.close();
	return start;
	}
	void item_list::items_available()
	{
	fstream item_file;
	clrscr();
	gotoxy(20,2);
	cout< <"ITEM AVAILABLE";
	gotoxy(20,3);
	cout<<"--------------";
	gotoxy(10,5);
	cout<<"ITEM CODE";
	gotoxy(10,6);
	cout<<"---------";
	gotoxy(20,5);
	cout<<"STOCK";
	gotoxy(20,6);
	cout<<"-----";
	gotoxy(30,5);
	cout<<"ITEM NAME";
	gotoxy(30,6);
	cout<<"---------";
	gotoxy(40,5);
	cout<<"ITEM RATE";
	gotoxy(40,6);
	cout<<"---------";
	int y=7;
	item_file.open("itemfile.dat",ios::in);
	item_file.seekg(0);
	item_file.read((char*)&item,sizeof(item));
	while(!item_file.eof())
	{
	gotoxy(10,y);
	cout<<item.item_code;
	gotoxy(20,y);
	cout<<item.qty_in_stock;
	gotoxy(30,y);
	cout<<item.item_name;
	gotoxy(40,y);
	cout<<item.item_rate;
	y++;
	item_file.read((char*)&item,sizeof(item));
	}
	item_file.close();
	}
	int sales_list::get_memo_no(date_rec current_date)
		{
		fstream sales_file;
		int num;
		sales_file.open("cashmemo.dat",ios::in);
		sales_file.seekg(-sizeof(cash_memo),ios::end);
		sales_file.read((char*)&cash_memo,sizeof(cash_memo));
		if (cash_memo.cash_memo_date.day==current_date.day
		&&cash_memo.cash_memo_date.month==current_date.month
		&&cash_memo.cash_memo_date.year==current_date.year)
		num=cash_memo_num+1;
		else
		num=1;
		sales_file.close();
		return num;
		}
	//this function enters an new item into a itemfile, calls gets_item()
	void sales_list::update_sales_file(int memo_num,int ic1,int ic2,
	int ic3,int ic4,int ic5,int iq1,int iq2,int iq3,int iq4,int iq5,float amount)
	{
	fstream sales_file;
	cash_memo.cash_memo_num=memo_num;
	cash_memo.cash_memo_date=current_date;
	cash_memo.item_code1=ic1;
	cash_memo.item_code2=ic2;
	cash_memo.item_code3=ic3;
	cash_memo.item_code4=ic4;
	cash_memo.item_code5=ic5;
	cash_memo.i_qty1=iq1;
	cash_memo.i_qty2=iq2;
	cash_memo.i_qty3=iq3;
	cash_memo.i_qty4=iq4;
	cash_memo.i_qty5=iq5;
	cash_memo.total_amount=amount;
	sales_file.open("cashmemo.dat",ios::out | ios::app);
			//open file in attend mode
	sales_file.seekg(0,ios::end);
	sales_file.write((char*)&cash_memo,sizeof(cash_memo));
			//write in the file
	sales_file.close();	//close file
	}
 
	void sales_list::daily_sales_report(struct date_rec current_date)
	{
	fstream sales_file;
	gotoxy(20,2);
	cout<<"------------------";
	gotoxy(20,3);
	cout<<"SALES ON:"<<current_date.day<<"-"<<current_date.month<<" -"
	<<current_date.year;
	gotoxy(20,4);
	cout<<"---------------------------";
	gotoxy(20,6);
	cout<<"ITEM CODE";
	gotoxy(20,7);
	cout<<"-----------";
	gotoxy(40,6);
	cout<<"QUANTITY SOLD";
	gotoxy(40,7);
	cout<<"---------------";
	int y=8;
	//sales_file.open("cashmemo.dat",ios::in);
	ptr=start;
	while(ptr->link!=NULL)
	{
	int qty=0;
	sales_file.open("cashmemo.dat",ios::in);
	sales_file.seekg(0,ios::beg);
	sales_file.read((char*)&cash_memo,sizeof(cash_memo));
	while(!sales_file.eof())
	{
	if(current_date.day==cash_memo_date.day&&current_date.month==
	cash_memo_date.month&&current_date.year==cash_memo_date.year)
		{
		if(ptr->rec_no==cash_memo.item_code1)
		  qty=qty+cash_memo.i_qty1;
		if (ptr->rec_no==cash_memo.item_code2)
		  qty=qty+cash_memo.i_qty2;
		if(ptr->rec_no==cash_memo.item_code3)
		  qty=qty+cash_memo.i_qty3;
		if (ptr->rec_no==cash_memo.item_code4)
		  qty=qty+cash_memo.i_qty4;
		if(ptr->rec_no==cash_memo.item_code5)
		  qty=qty+cash_memo.i_qty5;
		}
		sales_file.read((char*)&cash_memo,sizeof(cash_memo));
		}
		sales_file.close();
		gotoxy(20,y);
		cout< <ptr->rec_no;
		gotoxy(40,y);
		cout< <qty;
		y++;
		ptr=ptr->link;
		}
		//sales_file.close();
		}
 
 
//		MAIN FUNCTION
void main()
{
char ch;
int key,main_choice,valid=0;
	do
	{
		clrscr();	//clear screen
		if (valid!=0)
		{
		gotoxy(25,11);
		cout< <"INVALID DATE";
		gotoxy(25,12);
		cout<<"PRESS ANY KEY TO TRY AGAIN";
		getch();
		clrscr();
		}
		gotoxy(22,10);
		cout<<"ENTER CURRENT DATE(dd/mm/yyyy)";
		gotoxy(25,11);
		cin>>current_date.day>>ch>>current_date.month>>
		ch>>current_date.year;
		valid=(current_date.day&lt;0)||(current_date.day>31)
		  ||(current_date.month>12)||(current_date.month< =0)
		  ||(current_date.year&lt;1998);	//validate date
		}while(valid !=0);
 
		do
		{
		clrscr();
		gotoxy(20,5);
		cout<<"ABC DEPARTMENTAL STORE";
		gotoxy(20,7);
		cout<<"----------------";
		gotoxy(20,7);
		cout<<"-----------------";
		gotoxy(22,10);
		cout<<"SUPERVISOR	..........S";
		gotoxy(22,12);
		cout<<"CASHMEMO		...........C";
		gotoxy(22,14);
		cout<<"QUIT		...........Q";
		main_choice=toupper(getch());
		switch(main_choice)
			{
			case 'S':int s_choice;
				do
				{
				clrscr();
				gotoxy(28,2);
				cout<<"---------------";
				gotoxy(28,3);
				cout<<"SUPERVISOR MODE";
				gotoxy(28,4);
				cout<<"----------------";
				gotoxy(20,6);
				cout<<"UPDATE STOCK ON PURCHASE	     .....1";
				gotoxy(20,8);
				cout<<"TODAY'S SALES REPORT	     .....2";
				gotoxy(20,10);
				cout<<"LIST OF ITEM AVAILABLE	     .....3";
				gotoxy(20,12);
				cout<<"PURCHASE ORDER LIST	     .....4";
				gotoxy(20,14);
				cout<<"EXIT SUPERVISOR MODE	     .....5";
				gotoxy(20,16);
				cout<<"ENTER YOUR CHOICE ----------------->";
				cin>>s_choice;
				switch(s_choice)
				{
				case 1:int key;
					do
					{
					item_list temp_item;
					clrscr();
					temp_item.get_item();
					temp_item.update_on_purchase(temp_item);
					gotoxy(18,24);
					cout< <"CONTINUE:C	QUIT:Q";
					key=toupper(getch());
					}
					while(key!='Q');
					break;
				case 2: clrscr();
					item.create_list();
					cash_memo.daily_sales_report(current_date);
					getch();
					break;
				case 3: item.items_available();
					getch();
					break;
				case 4: clrscr();
					item.purchase_order();
					getch();
					break;
				case 5: break;
				}
			}
		while(s_choice !=5);
		break;
	case 'C': do
		{
		int memo_num;
		memo_num=cash_memo.get_memo_no(current_date);
		clrscr();
		gotoxy(24,1);
		cout<<"------------------------------";
		gotoxy(24,2);
		cout<<"ABC DEPARTMENTAL STORE";
		gotoxy(24,3);
		cout<<"------------------------------";
		gotoxy(30,5);
		cout<<"CASHMEMO";
		gotoxy(30,6);
		cout<<"--------------------------------";
		gotoxy(10,7);
		textbackground(RED+BLINK);
		cprintf("DATE:");
		cout<<current_date.day<<"/"<<current_date.month<<"/"
		<<current_date.year;
		gotoxy(52,7);
		cout<<"NO:"<<memo_num;
		gotoxy(10,9);
		cout<<"ITEM CODE  1:";
		gotoxy(35,9);
		cout<<"QTY:";
		gotoxy(52,9);
		cout<<"RATE";
		gotoxy(10,10);
		cout<<"ITEM CODE  2:";
		gotoxy(35,10);
		cout<<"QTY:";
		gotoxy(52,10);
		cout<<"RATE";
		gotoxy(10,11);
		cout<<"ITEM CODE  3:";
		gotoxy(35,11);
		cout<<"QTY:";
		gotoxy(52,11);
		cout<<"RATE:";
		gotoxy(10,12);
		cout<<"ITEM CODE  4:";
		gotoxy(35,12);
		cout<<"QTY:";
		gotoxy(52,12);
		cout<<"RATE:";
		gotoxy(10,13);
		cout<<"ITEM CODE  5:";
		gotoxy(35,13);
		cout<<"QTY:";
		gotoxy(52,13);
		cout<<"RATE:";
		gotoxy(10,15);
		cout<<"TOTAL AMOUNT:";
		int ic1,ic2,ic3,ic4,ic5;
		int iq1,iq2,iq3,iq4,iq5;
		ic1=ic2=ic3=ic4=ic5=0;
		iq1=iq2=iq3=iq4=iq5=0;
		gotoxy(24,9);
		cin>>ic1;
		gotoxy(41,9);
		cin>>iq1;
		gotoxy(24,10);
		cin>>ic2;
		gotoxy(41,10);
		cin>>iq2;
		gotoxy(24,11);
		cin>>ic3;
		gotoxy(41,11);
		cin>>iq3;
		gotoxy(24,12);
		cin>>ic4;
		gotoxy(41,12);
		cin>>iq4;
		gotoxy(24,13);
		cin>>ic5;
		gotoxy(41,13);
		cin>>iq5;
		float total_amount=0;
		total_amount=
		total_amount=item.update_on_sale(ic1,ic2,ic3,ic4,ic5,
					       iq1,iq2,iq3,iq4,iq5);
		gotoxy(25,15);
		cout< <setiosflags(ios::fixed)
		<<setiosflags(ios::showpoint)
		<<setprecision(2)<<total_amount;
		cash_memo.update_sales_file(memo_num,ic1,ic2,ic3,ic4,
			       ic5,iq1,iq2,iq3,iq4,iq5,total_amount);
		gotoxy(22,24);
		cout<<"QUIT CASHMEMO:Q    CONTINUE:C";
		key=toupper(getch());
		}
		while(key!='Q');
		break;
		case'Q':  exit(0);
		break;
		}
		}
		while(main_choice!='Q');
		getch();
		}

  1. No comments yet.
  1. No trackbacks yet.