diff --git a/index.html b/index.html index db5792f..9fa6e50 100644 --- a/index.html +++ b/index.html @@ -803,7 +803,7 @@ //for cloud apps subAdmins: [], - application: "eCommerce", + application: "eCommerce_test1", vectorClock: {}, appObjects: {}, generalData: {}, @@ -972,7 +972,8 @@
Product Image:
`; t += `Product Selling Price:
`; t += `Product Location:
`; - t += `Items Available :
`; t += `On Sale:
`; t += `UPI Txid: ${bo.payment_to_vendor_txid} Item: ${product_dynamic_info.product_name}: ${bo.buy_order_data.quantity[product_dynamic_info.product_name]} Item: ${product_dynamic_info.product_name}: ${bo.buy_order_data.quantity[product_static_info.product_flo_id]} Total Price: ${bo.buy_order_data.final_price} Product: ${_list.product_info.product_dynamic_information.product_name} Price: ${sp} Quantity: ${qty} Total: ${Math.floor(sp*qty)} Product: ${this.shopping_bill.shopping_list[0].product_info.product_dynamic_information.product_name} Price: ${this.shopping_bill.shopping_list[0].product_info.product_dynamic_information.selling_price} Quantity: ${this.shopping_bill.quantity[this.shopping_bill.shopping_list[0].product_info.product_dynamic_information.product_name]}
`;
@@ -10982,30 +10983,27 @@ Bitcoin.Util = {
const product_details = latest_buy_orders[0].buy_order_data.shopping_list[0].product_info;
const buyer = latest_buy_orders[0].buy_order_data.buyer_flo_id;
let product = product_details.product_dynamic_information.product;
+ let expected_delivery = + new Date() + 24*60*60*1000;
+ let vendor_txid = latest_buy_orders[0].payment_to_vendor_txid;
+ let commodity = ``;
+ let seller_sig = ``;
+ let signed_item = ``;
+ let item_sent = ``;
+ let item_info = ``;
+
if(product_details.product_static_information.product_type==="DIGITAL") {
switch (product) {
case "MOVIE_TICKETS":
- let ticket = `
+ let item_info = `
Buy_Txid: ${buy_txid}
Buyer Id: ${buyer}
Movie: ${product_details.product_dynamic_information.product_name}
- Movie DateTime: ${product_details.product_dynamic_information.movie_datetime}
- `;
-
- let seller_sig = floCrypto.signData(ticket, myPrivKey)
-
- let signed_ticket = ticket+' VendorSignature: '+seller_sig;
-
- let ticket_sent = await floCloudAPI.sendGeneralData(signed_ticket, ecommerce.master_configurations.DATA_TYPE.PURCHASED_ITEMS,
- { receiverID: buyer })
-
- console.log(ticket_sent);
- if(typeof ticket_sent == "object") {
- // add buy_txid to dispatched items table
- }
+ DateTime: ${product_details.product_dynamic_information.movie_datetime}
+ Cashier_To_Seller_TXID: ${vendor_txid}
+ `;
break;
@@ -11015,7 +11013,52 @@ Bitcoin.Util = {
} else if(product_details.product_static_information.product_type==="PHYSICAL") {
+ let delivery_datetime = prompt('Enter expected delivery time: ', expected_delivery);
+
+ switch (product) {
+ case "Milko":
+ item_info = `
+ Buy_Txid: ${buy_txid}
+ Buyer Id: ${buyer}
+ Product: ${product_details.product_dynamic_information.product_name}
+ DateTime: ${product_details.product_dynamic_information.datetime}
+ Expected Delivery: ${delivery_datetime}
+ Cashier_To_Seller_TXID: ${vendor_txid}
+ `;
+
+ break;
+
+ case "Pencil":
+ item_info = `
+ Buy_Txid: ${buy_txid}
+ Buyer Id: ${buyer}
+ Product: ${product_details.product_dynamic_information.product_name}
+ DateTime: ${product_details.product_dynamic_information.datetime}
+ Expected Delivery: ${delivery_datetime}
+ Cashier_To_Seller_TXID: ${vendor_txid}
+ `;
+
+ break;
+
+ default:
+ break;
+
+ }
+
}
+
+ seller_sig = floCrypto.signData(item_info, myPrivKey)
+ signed_item = item_info+' VendorSignature: '+seller_sig;
+
+ // Inform buyer
+ floCloudAPI.sendGeneralData(signed_item, ecommerce.master_configurations.DATA_TYPE.PURCHASED_ITEMS,
+ { receiverID: buyer });
+
+ // Keep a record
+ floCloudAPI.sendGeneralData(latest_buy_orders, ecommerce.master_configurations.DATA_TYPE.PROCESSED_PURCHASED_ITEMS,
+ { receiverID: myFloID });
+
+ showMessage('Item successfully processed (by Seller).');
} catch (error) {
throw new Error(error)
@@ -11057,6 +11100,11 @@ Bitcoin.Util = {
_id);
this.preview_shopping_bill();
+
+
+ // let pay_using_wallet = confirm('Do you want to pay using rupee token?');
+ // console.log(pay_using_wallet);
+ // this.checkout(pay_using_wallet);
} catch (error) {
throw new Error(error)
@@ -11123,6 +11171,8 @@ Bitcoin.Util = {
// Reset buy price
this.total_buying_price = 0;
let bill_preview = [];
+ let billPreviewUI = ``;
+ console.log(this.buy_list);
for (const buying_product_info in this.buy_list) {
if (this.buy_list.hasOwnProperty(buying_product_info)) {
const item = this.buy_list[buying_product_info];
@@ -11138,15 +11188,17 @@ Bitcoin.Util = {
)) {
let item_name = product_details.product_info.product_dynamic_information.product_name;
-
+ let item_flo_id = product_details.product_info.product_static_information.product_flo_id;
+
// Prevent duplicate registration of products in shopping_list
if(!this.shopping_bill.shopping_list.some(s=>s.product_info.product_static_information.product_flo_id
===product_details.product_info.product_static_information.product_flo_id)) {
this.shopping_bill.shopping_list.push(product_details);
+ this.shopping_bill.quantity[item_flo_id] = Number(item.buying_units);
+ } else {
+ this.shopping_bill.quantity[item_flo_id] = this.buy_list.filter(m=>m.product_flo_id===item_flo_id).length;
}
-
- this.shopping_bill.quantity[item_name] = Number(item.buying_units);
-
+
bill_preview.push({
"product": item_name,
"price": product_details.product_info.product_dynamic_information.selling_price,
@@ -11160,6 +11212,7 @@ Bitcoin.Util = {
);
}
}
+
} else {
console.error(`Product with id ${item.product_flo_id} not found`);
continue;
@@ -11173,15 +11226,19 @@ Bitcoin.Util = {
this.final_price = to_fiat_number(this.total_buying_price);
this.shopping_bill.final_price = this.final_price;
console.log(this.shopping_bill);
- //return this.shopping_bill;
+
+ for (const _list of this.shopping_bill.shopping_list) {
+ let sp = _list.product_info.product_dynamic_information.selling_price;
+ let qty = this.shopping_bill.quantity[_list.product_info.product_static_information.product_flo_id];
+ billPreviewUI += `
+
+ `;
+ }
- //billPreview
- let billPreviewUI = `
- Total: ${this.shopping_bill.final_price}
- `;
+ billPreviewUI += `Total: ${this.shopping_bill.final_price}
`;
document.getElementById('billPreview').innerHTML=billPreviewUI;
document.getElementById('item_delivery_addr').innerHTML=localStorage.getItem("FloECommerceUserAddress");
@@ -11189,6 +11246,7 @@ Bitcoin.Util = {
} catch (error) {
showMessage('Failed to preview shopping list', 'ERROR');
+ this.reset_bucket_list();
throw new Error(error);
}
},
@@ -11305,15 +11363,19 @@ Bitcoin.Util = {
// Store info in local history
compactIDB.addData('my_orders_history', buy_order_object, buy_order_object.txid);
- floCloudAPI.sendGeneralData(buy_order_object, ecommerce.master_configurations.DATA_TYPE.BUY_ORDERS,
+ let send_payment_info = await floCloudAPI.sendGeneralData(buy_order_object, ecommerce.master_configurations.DATA_TYPE.BUY_ORDERS,
{receiverID:cashier});
+ console.log(send_payment_info);
+
+ showMessage('Payment request sent to cashier.')
+
// const payment_info_data = {
// payment_amount: this.final_price,
// cashier: cashier,
// }
- //this.proceed_to_payment(payment_info_data);
+ // this.proceed_to_payment(payment_info_data);
this.reset_bucket_list();
}
@@ -11363,8 +11425,7 @@ Bitcoin.Util = {
try {
const myProducts = ecommerce.approved_products_list;
const mySellingProducts = myProducts.filter(f=>
- (f.product_info.product_dynamic_information.onSale===true
- && f.product_info.product_dynamic_information.items_available>0));
+ (f.product_info.product_dynamic_information.onSale===true));
console.table(mySellingProducts);
let t = ``;
for (const product of mySellingProducts) {
@@ -11406,10 +11467,9 @@ Bitcoin.Util = {
},
display_purchased_items: function() {
try {
- const my_purchased_items = floGlobals.generalData[JSON.stringify(
- { application: floGlobals.application,
- type: ecommerce.master_configurations.DATA_TYPE.PURCHASED_ITEMS
- })];
+ const my_purchased_items = floDapps.getNextGeneralData(ecommerce.master_configurations.DATA_TYPE.PURCHASED_ITEMS, "0");
+
+ my_purchased_items.reverse();
const myPurchasedItemsList = document.getElementById('myPurchasedItemsList')
@@ -11438,24 +11498,23 @@ Bitcoin.Util = {
// Start ecommerce in a new city
create_new_city_ecommerce: function() {
- if(typeof ecommerce.master_configurations.SUBJECT!=="string" || ecommerce.master_configurations.SUBJECT.length<2) {
+ if(typeof floGlobals.application!=="string" || floGlobals.application.length<2) {
showMessage('Error: Please provide a subject in master configuration.', 'error');
return false;
}
const flo_ecommerce = {};
- flo_ecommerce[ecommerce.master_configurations.SUBJECT] = {};
// Master configurations should come from here
- flo_ecommerce[ecommerce.master_configurations.SUBJECT].master_configurations = '';
+ flo_ecommerce.master_configurations = '';
- flo_ecommerce[ecommerce.master_configurations.SUBJECT].Orders = {};
- flo_ecommerce[ecommerce.master_configurations.SUBJECT].Orders.buy_orders = {};
+ flo_ecommerce.Orders = {};
+ flo_ecommerce.Orders.buy_orders = {};
// Every approved product is for sale
//flo_ecommerce[cityname].Orders.sell_orders = {};
- flo_ecommerce[ecommerce.master_configurations.SUBJECT].Products = {};
+ flo_ecommerce.Products = {};
// Messages should be in general object
// flo_ecommerce[cityname].Messages = {};
@@ -11464,17 +11523,17 @@ Bitcoin.Util = {
// flo_ecommerce[cityname].Messages["cashier_messages"] = {}
// flo_ecommerce[cityname].Messages["delivery_messages"] = {}
// flo_ecommerce[cityname].Messages["manager_messages"] = {}
- floGlobals.appObjects[ecommerce.master_configurations.SUBJECT] = flo_ecommerce;
+ floGlobals.appObjects[floGlobals.application] = flo_ecommerce;
- floCloudAPI.resetObjectData(ecommerce.master_configurations.SUBJECT);
+ floCloudAPI.resetObjectData(floGlobals.application);
},
// Load ecommerce data relevent to an admin
get_general_data: async function() {
await floCloudAPI.requestGeneralData(ecommerce.master_configurations.DATA_TYPE.SELLING_PRODUCTS,
{ senderIDs:Object.keys(ecommerce.master_configurations.sellers_list) })
- const new_generalData = floGlobals.generalData[JSON.stringify({ application: floGlobals.application, type: ecommerce.master_configurations.DATA_TYPE.SELLING_PRODUCTS })];
-
+ const new_generalData = floDapps.getNextGeneralData(
+ ecommerce.master_configurations.DATA_TYPE.SELLING_PRODUCTS, "0");
for (const new_data of new_generalData) {
if(!Object.keys(ecommerce.master_configurations.sellers_list).includes(new_data.sender)) continue;
@@ -11516,7 +11575,6 @@ Bitcoin.Util = {
for (const elem in ui_data) {
if (ui_data.hasOwnProperty(elem)) {
if(0) t += ``;
-
t += `