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
|
void orderItem( Inventory *& inven , OrderList *& order , int &index , int &orderIndex , int &itemIndex ){
system( "cls" );
displayItem(inven,index);
bool matchItem = false;
bool again = false;
bool matchQuantity = false;
bool matchAll = false;
string status = "";
string name = "";
string item = "";
string model = "";
char date[9];
double price = 0.00;
double warranty = 0.00;
int quan = 0;
itemIndex = 0;
char choice = 'a';
char continueBuy ='a';
ifstream inFile;
ofstream outFile;
cin.ignore();
cout << "Enter company name : ";
getline( cin , name );
stringtoUpper( name );
order[orderIndex].setCompanyName( name );
do{
cout << "Do you want add an order [y / n] : ";
cin >> choice;
switch( choice ){
case 'y':
case 'Y':
do{
cin.ignore();
do{
do{
if( itemIndex == 0 ){}
else{
itemIndex++;
}
cout << "Enter item name : ";
getline( cin , item );
stringtoUpper(item);
for( int i = 0 ; i < index ; i++ ){
if( item != inven[i].getItemName() )
matchItem = false;
else{
matchItem = true;
break;
}
}
if( !matchItem )
cout << "Item Does not exist!" << endl;
}while(!matchItem);
order[orderIndex].orderItem[itemIndex].itemName = item;
for( int i = 0 ; i < index ; i++ ){
if( item == inven[i].getItemName() ){
if(inven[i].getQuantity() <= 0){
cout << "Item sold out ! Need to wait stock" << endl;
matchAll = false;
}
else
matchAll = true;
}
}
if( matchAll == true ){
do{
cout << "Enter quantity : ";
cin >> quan;
while( cin.fail() ){
cin.clear();
cin.ignore(100,'\n');
cout << "You cannot enter character , only number" << endl;
cout << "Enter quantity : ";
cin >> quan;
}
for( int i = 0 ; i < index ; i++ ){
if( item == inven[i].getItemName() ){
if( quan > inven[i].getQuantity()){
cout << "Invalid input ! Item quantity exceed" << endl;
matchQuantity = false;
}
else{
int remainQuantity = inven[i].getQuantity();
remainQuantity -= quan;
inven[i].setQuantity(remainQuantity);
matchQuantity = true;
}
}
}
}while( matchQuantity == false);
order[orderIndex].orderItem[itemIndex].quantity = quan;
for( int i = 0 ; i < index ; i++ ){
if( item == inven[i].getItemName() ){
price = quan * inven[i].getPrice();
model = inven[i].getModel();
warranty = inven[i].getWarranty();
}
}
cout << "Total Price : RM" << price << endl;
order[orderIndex].orderItem[itemIndex].price = price;
order[orderIndex].orderItem[itemIndex].modelName = model;
order[orderIndex].orderItem[itemIndex].warranty = warranty;
status = "pending";
stringtoUpper(status);
order[orderIndex].setOrderStatus(status);
itemIndex++;//to increase 1 array, if not array will not be save and output error
displayItem(inven,index);
cout << "\n\nDo you still want to continue [y/n] ? : ";
cin >> continueBuy;
do{
switch( continueBuy ){
case 'y':
case 'Y':
again = true;
break;
case 'n':
case 'N':
again = false;
_strdate(date);
order[orderIndex].setDate(date);
orderIndex++;
saveOrder(order,outFile,orderIndex,itemIndex);
saveOrderTrack(order,outFile,orderIndex,itemIndex);
saveInventory(inven,index);
break;
default:
cout << "Invalid input !" << endl;
break;
}
}while( choice != 'Y'&&choice != 'y'&&choice != 'n'&& choice!='N' );
}
}while( matchAll != true );
}while(again == true);
break;
case 'N':
case'n':
cout << "You cancel order item" << endl;
break;
default:
cout << "Invalid input ! Please re-enter" << endl;
break;
}
}while( choice != 'Y' && choice != 'y' && choice != 'N' && choice !='n');
}
|