Created
April 24, 2021 00:43
-
-
Save ahmetozlu/df0d11d1eb349dc1460331b396f97f5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to send order | |
function sendOrder(string memory burgerMenu, uint quantity) payable public { | |
// only the customer can use this function | |
require(msg.sender == customerAddress); | |
// increase the order index | |
orderseq++; | |
// create the order | |
orders[orderseq] = Order(orderseq, burgerMenu, quantity, 0, 0, 0, 0, true); | |
// trigger OrderSent event | |
emit OrderSent(msg.sender, burgerMenu, quantity, orderseq); | |
} | |
// function to check orders | |
function checkOrder(uint ID) view public returns (address customer, string memory burgerMenu, uint quantity, uint price, uint safePayment) { | |
// check the order exists | |
require(orders[ID].created); | |
// return the order | |
return(customerAddress, orders[ID].burgerMenu, orders[ID].quantity, orders[ID].price, orders[ID].safePayment); | |
} | |
// function to send price | |
function sendPrice(uint orderNo, uint price) payable public { | |
// only the owner can use this function | |
require(msg.sender == owner); | |
// check the order exists | |
require(orders[orderNo].created); | |
// set the order price | |
orders[orderNo].price = price; | |
// trigger PriceSent event | |
emit PriceSent(customerAddress, orderNo, price); | |
} | |
// function to send safe payment | |
function sendSafePayment(uint orderNo) payable public { | |
// only the customer can use this function | |
require(customerAddress == msg.sender); | |
// check the order exists | |
require(orders[orderNo].created); | |
// payout | |
orders[orderNo].safePayment = msg.value; | |
// trigger SafePaymentSent event | |
emit SafePaymentSent(msg.sender, orderNo, msg.value, now); | |
} | |
// function to send invoice | |
function sendInvoice(uint orderNo, uint order_date) payable public { | |
// only the owner can use this function | |
require(owner == msg.sender); | |
// check the order exists | |
require(orders[orderNo].created); | |
// increase the invoice index | |
invoiceseq++; | |
// create the invoice | |
invoices[invoiceseq] = Invoice(invoiceseq, orderNo, true); | |
// set the order date | |
orders[orderNo].orderDate = order_date; | |
// trigger InvoiceSent event | |
emit InvoiceSent(customerAddress, invoiceseq, orderNo, order_date); | |
} | |
// function to get invoice | |
function getInvoice(uint invoiceID) view public returns (address customer, uint orderNo, uint invoice_date){ | |
// check the invoice exists | |
require(invoices[invoiceID].created); | |
// get the related invoice info | |
Invoice storage _invoice = invoices[invoiceID]; | |
// get the related order info | |
Order storage _order = orders[_invoice.orderNo]; | |
// return the invoice | |
return (customerAddress, _order.ID, _order.orderDate); | |
} | |
// function to mark the order as delivered | |
function markOrderDelivered(uint invoiceID, uint delivery_date) payable public { | |
// only the customer can use this function | |
require(customerAddress == msg.sender); | |
// check the invoice exists | |
require(invoices[invoiceID].created); | |
// get the related invoice info | |
Invoice storage _invoice = invoices[invoiceID]; | |
// get the related order info | |
Order storage _order = orders[_invoice.orderNo]; | |
// set the delivery date | |
_order.deliveryDate = delivery_date; | |
// trigger OrderDelivered event | |
emit OrderDelivered(customerAddress, invoiceID, _order.ID, delivery_date); | |
// payout | |
owner.transfer(_order.safePayment); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment