Skip to content

Commit

Permalink
Merge pull request #7 from awaismohammad23/AwaisTasks
Browse files Browse the repository at this point in the history
Awais tasks
  • Loading branch information
awaismohammad23 authored Jan 6, 2024
2 parents 6ac7627 + 149b148 commit fa8ab85
Show file tree
Hide file tree
Showing 23 changed files with 65,322 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Project2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.16+commit.07a7930e"
}
4,962 changes: 4,962 additions & 0 deletions Project2/build/contracts/ERC20.json

Large diffs are not rendered by default.

10,255 changes: 10,255 additions & 0 deletions Project2/build/contracts/FASTCOIN.json

Large diffs are not rendered by default.

16,804 changes: 16,804 additions & 0 deletions Project2/build/contracts/OrderProcessingContract.json

Large diffs are not rendered by default.

17,104 changes: 17,104 additions & 0 deletions Project2/build/contracts/discountsAndPromotions.json

Large diffs are not rendered by default.

12,620 changes: 12,620 additions & 0 deletions Project2/build/contracts/menuManagement.json

Large diffs are not rendered by default.

3,133 changes: 3,133 additions & 0 deletions Project2/build/contracts/rewardsAndLoyalty.json

Large diffs are not rendered by default.

Empty file added Project2/contracts/.gitkeep
Empty file.
85 changes: 85 additions & 0 deletions Project2/contracts/FASTCOIN.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.10 <0.8.20;
import "./rewardsAndLoyalty.sol";
interface ERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address from, address to, uint256 value);
event Approval(address owner, address spender, uint256 value);
}

contract FASTCOIN is ERC20 {
uint numTokens;
mapping(address=>uint) balance;
mapping(address=>uint) paymenttime;
mapping(address=> mapping(address=>uint)) approvalLimit;
mapping(address=>uint)daystreak;
rewardsAndLoyalty public RAL;
constructor (uint _numTokens) {
numTokens = _numTokens;
balance[msg.sender] = numTokens;
}


function totalSupply() external view returns (uint256){
return numTokens;
}

function balanceOf(address account) external view returns (uint256){
return balance[account];
}

function transfer(address recipient, uint256 amount) external returns (bool){
require (balance[msg.sender] >= amount) ;
balance[msg.sender] -= amount;
balance[recipient] += amount;
}

function approve(address spender, uint256 value) external returns (bool){
require (balance[msg.sender] >= value);
approvalLimit[msg.sender][spender] = value;
}

function allowance(address owner, address spender) external view returns
(uint256){
return approvalLimit[owner][spender];
}

function transferFrom(address sender, address recipient, uint256 amount) external returns
(bool){
require (amount <= balance[sender]);
require (amount <= approvalLimit[sender][msg.sender]);
paymenttime[sender]=(block.timestamp - paymenttime[sender]) ;
if (paymenttime[sender] > 24 hours){
daystreak[sender]=0;
} else {
uint [] memory stamt = RAL.getsentamount();
uint [] memory rwd = RAL.getreward();
uint [] memory bdystk = RAL.getbuydaysstreak();
uint [] memory rwdbdystk = RAL.getrewardforbuydays();
for (uint i = 0 ; i < stamt.length ; i++){
if (amount > stamt[i]){
balance[sender]+=rwd[i];
break;
}
}

for (uint i = 0 ; i < bdystk.length ; i++){
if (daystreak[sender] > bdystk[i]){
balance[sender]+=rwdbdystk[i];
break;
}
}
}
balance[sender] -= amount;
balance[recipient] += amount;
approvalLimit[sender][msg.sender] -= amount;
paymenttime[sender]=block.timestamp;
daystreak[sender]+=1;
}

}
48 changes: 48 additions & 0 deletions Project2/contracts/OrderProcessingContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.10 <0.8.20;
import "./menuManagement.sol";
import "./discountsAndPromotions.sol";
contract OrderProcessingContract{
menuManagement public mn;
discountsAndPromotions public discAPro;

function setmenuanddiscountsandpromotions(address _addrmenu , address _addrdiscandpro)public{
mn=menuManagement(_addrmenu);
discAPro=discountsAndPromotions(_addrdiscandpro);
}

function CheckinAvailability()public view returns(bool){
return mn.CheckAvailability("Pizza");
}

function getMenuItems() public view returns(string [] memory , uint [] memory, uint [] memory){
string [] memory names = mn.getItemNames();
uint [] memory price = mn.getMenuPrice();
uint [] memory quantity = mn.getMenuQuantity();
return (names , price , quantity);
}

function CalculateOrderAmount(string [] memory itemnames , uint [] memory quantities) external returns(uint){
uint totalAmount;
string [] memory names = mn.getItemNames();
uint [] memory price = mn.getMenuPrice();
uint [] memory quantity = mn.getMenuQuantity();
uint j = 0;
for (uint i = 0 ; i < names.length ; i++){
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(itemnames[j]))) {
string memory nm;
uint typs; uint qt ; uint prcper ; uint dur;
(nm , typs , qt , prcper , dur) = discAPro.PromotionsandDiscounts(names[i]);
if (typs == 1){
mn.setQuantity(quantity[i] - quantities[j] - quantities[j]/qt, i);
totalAmount += quantities[j] * price[i];
} else if (typs == 2) {
mn.setQuantity(quantity[i] - quantities[j] - quantities[j]/qt, i);
totalAmount += quantities[j] * (prcper / 100 * price[i]);
}
j++;
}
}
return totalAmount;
}
}
56 changes: 56 additions & 0 deletions Project2/contracts/discountsAndPromotions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.10 <0.8.20;
import "./menuManagement.sol";
contract discountsAndPromotions {
menuManagement public mn;
string [] names ;
uint [] prices;
uint [] quantities;
function setMenu(address _addrmenu) public{
mn=menuManagement(_addrmenu);
}
struct PromAndDisc {
string name;
uint types;
uint quantity;
uint pricepercentagededuction;
uint duration;
}
mapping(string=> PromAndDisc) public PromotionsandDiscounts;

//The Quantity here is the quantity
//after which the customer will be eligible for free meal.
function AddBuyAndGetFreePromotion (string [] memory items , uint quantity , uint _duration) public {
require(quantity > 0 && _duration > 0 , "Quantity or duration cannot be zero.");
names = mn.getItemNames();
prices = mn.getMenuPrice() ;
quantities = mn.getMenuQuantity();//OPC.getMenuItems();//Tuples in solidity
uint j = 0;
for (uint i = 0 ; i < names.length ; i++){
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(items[j]))){
PromotionsandDiscounts[names[i]].quantity=quantity;
PromotionsandDiscounts[names[i]].name=names[i];
PromotionsandDiscounts[names[i]].types=1;
PromotionsandDiscounts[names[i]].duration= block.timestamp + _duration;
j++;
}
}
}

function AddSimpleDiscount(string [] memory items , uint percentage , uint _duration) public {
require(percentage <= 90 , "Percentage cannot exceeed 90");
names = mn.getItemNames();
prices = mn.getMenuPrice() ;
quantities = mn.getMenuQuantity();//OPC.getMenuItems();//Tuples in solidity
uint j = 0;
for (uint i = 0 ; i < names.length ; i++){
if (keccak256(abi.encodePacked(names[i])) == keccak256(abi.encodePacked(items[j]))){
PromotionsandDiscounts[names[i]].name=names[i];
PromotionsandDiscounts[names[i]].types=2;
PromotionsandDiscounts[names[i]].pricepercentagededuction=percentage;
PromotionsandDiscounts[names[i]].duration= block.timestamp + _duration;
j++;
}
}
}
}
65 changes: 65 additions & 0 deletions Project2/contracts/menuManagement.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.10 <0.8.20;
contract menuManagement{
struct Item {
string name;
uint price;
uint quantity;
bool availability;
}
mapping (string => Item)public itms;
string [] public names;
uint [] public prices;
uint [] public quantities;
address public admin;
constructor(){
admin = msg.sender;
}

mapping(string => bool) itemExists;

modifier exists(string memory name) {
require(itemExists[name], "Item does not exist");
_;
}

function addItem(string memory name , uint price, uint qty) public {
names.push(name);
prices.push(price);
quantities.push(qty);
itms[name].name=name;
itms[name].price=price;
itms[name].quantity=qty;
itms[name].availability=qty > 0;
itemExists[name] = true;
}

function getItemNames() external view returns (string [] memory){
return names;
}

function setQuantity(uint qty , uint i) external{
quantities[i]=qty;
}

function UpdatePrice(string memory name, uint price) private exists(name) {
require(price > 0, "Price cannot be 0");
itms[name].price=price;
}

function CheckAvailability(string memory name) exists(name) public view returns (bool) {
return itms[name].availability;
}

function getMenuPrice() public view returns(uint [] memory){
return prices;
}

function getMenuQuantity() public view returns(uint [] memory){
/*uint [] memory qty1 = new uint[](1000);
for (uint i = 0 ; i < names.length ; i++){
qty1[i] = itms[names[i]].quantity;
}*/
return quantities;
}
}
20 changes: 20 additions & 0 deletions Project2/contracts/rewardsAndLoyalty.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.10 <0.8.20;
contract rewardsAndLoyalty {
uint [] public sentamount = [10 , 50 , 100 , 200 , 250 , 500 , 750 , 1000 , 1500 , 2000 , 3000 , 5000 , 7500 , 10000];
uint [] public reward = [3 , 5 , 10 , 15 , 20 , 30 , 40 , 70 , 150 , 180 , 220 , 350 , 500 , 800];
uint [] public buydaysstreak = [3 , 5 , 10 , 30 , 60 , 90 , 180 , 365];
uint [] public rewardforbuydays = [1 , 2 , 3 , 10 , 30 , 50 , 70 , 100];
function getreward() public view returns(uint[] memory){
return reward;
}
function getsentamount() public view returns(uint[] memory){
return sentamount;
}
function getbuydaysstreak() public view returns(uint[] memory){
return buydaysstreak;
}
function getrewardforbuydays() public view returns(uint[] memory){
return rewardforbuydays;
}
}
Empty file added Project2/migrations/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions Project2/migrations/1_menuManagement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const menuManagement = artifacts.require("./menuManagement.sol");

module.exports = function(deployer){
deployer.deploy(menuManagement);
}
5 changes: 5 additions & 0 deletions Project2/migrations/2_rewardsAndLoyalty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const RAL = artifacts.require("rewardsAndLoyalty");

module.exports = function(deployer){
deployer.deploy(RAL);
}
6 changes: 6 additions & 0 deletions Project2/migrations/3_FASTCOIN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const FASTCOIN = artifacts.require("FASTCOIN");

module.exports = function(deployer){
const initialoffering = 1000000;
deployer.deploy(FASTCOIN , initialoffering);
}
4 changes: 4 additions & 0 deletions Project2/migrations/4_discountsAndPromotions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const DiscPro = artifacts.require("discountsAndPromotions");
module.exports=function(deployer){
deployer.deploy(DiscPro);
}
5 changes: 5 additions & 0 deletions Project2/migrations/5_OrderProcessingContract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const OPC = artifacts.require("./OrderProcessingContract.sol");

module.exports = function(deployer){
deployer.deploy(OPC);
}
1 change: 1 addition & 0 deletions Project2/project2
Submodule project2 added at bc3e5c
Empty file added Project2/test/.gitkeep
Empty file.
Loading

0 comments on commit fa8ab85

Please sign in to comment.