-
Notifications
You must be signed in to change notification settings - Fork 1
/
burger.sol
101 lines (70 loc) · 3.2 KB
/
burger.sol
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
// SPDX-License-Identifier : MIT
pragma solidity ^0.8.17;
contract Burger{
address payable public owner;
address public customer;
struct Order{
uint ID;
string burgerMenu;
uint quantity;
uint price;
uint safePayment;
uint orderDate;
uint deliveryDate;
bool created;
}
struct Invoice{
uint ID;
uint orderNo;
bool created;
}
mapping(uint => Order) orders;
mapping(uint => Invoice) invoices;
uint orderseq;
uint invoiceseq;
constructor(address _buyerAddress) public payable{
owner == msg.sender;
customer = _buyerAddress;
}
function sendOrder(string memory burgerMenu, uint quantity) public payable{
require(customer == msg.sender, "Only the customers can call this function");
orderseq++;
// we passed the needed members of the struct as params so we can call them
orders[orderseq] = Order (orderseq, burgerMenu, quantity, 0, 0, 0, 0, true);
}
function checkOrder(uint ID) public view returns(address customer, string memory burgerMenu, uint quantity, uint price, uint safePayment) {
require(orders[ID].created, "The order does not exist ab initio");
return(customer, orders[ID].burgerMenu, orders[ID].quantity, orders[ID].price, orders[ID].safePayment);
}
function sendPrice(uint orderNo, uint price) public payable{
require(owner == msg.sender, "only the owner can do this, bruh");
require(orders[orderNo].created, "The specific order does not exist");
orders[orderNo].price = price;
}
function sendSafepayment(uint orderNo) public payable {
require(customer == msg.sender, "Only customers call this");
require(orders[orderNo].created, "The specific order does not exist");
orders[orderNo].safePayment = msg.value;
}
function sendInvoice(uint orderNo, uint order_date) public payable {
require(owner == msg.sender, "only the owner can do this, bruh");
require(orders[orderNo].created, "The specific order does not exist");
invoiceseq++;
invoices[invoiceseq] = Invoice(invoiceseq, orderNo, true);
orders[orderNo].orderDate = order_date;
}
function getInvoice(uint invoiceID) public view returns (address customer, uint orderNo, uint invoice_date) {
require(invoices[invoiceID].created, "The invoice doesn't exist");
Invoice storage _invoice = invoices[invoiceID];
Order storage _order = orders[_invoice.orderNo];
return(customer, _order.ID, _order.orderDate);
}
function markOrderDelivered(uint invoiceID, uint deliveryDate) public payable{
require(customer == msg.sender, "Only customers can mark orders as delivered");
require(invoices[invoiceID].created, "The invoice doesn't exist");
Invoice storage _invoice = invoices[invoiceID];
Order storage _order = orders[_invoice.orderNo];
_order.deliveryDate = deliveryDate;
owner.transfer(_order.safePayment);
}
}