-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.upload.ventes.js
42 lines (41 loc) · 1.34 KB
/
action.upload.ventes.js
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
// Upload sales
function uploadSaleRange() {
try {
// Request line range
var betweenLine = _prompt("What range, or lines, to upload?", "Format: [START_LINE, END_LINE]").split(",");
// sales data
var data = spreadsheetToJson({
sheetName: "VENTES",
rowBetween: [parseInt(betweenLine[0], 10), parseInt(betweenLine[1], 10)]
});
// Getting our sales into receipt
var receipts = data.map((sale) => _createReceiptFromVentes(sale))
// filter out empty sale lines.
.filter((receipt) => {
return (receipt.customer_account_id && receipt.customer_account_id.length) || (receipt.quantity && receipt.total) || (receipt.receipt_uuid && receipt.receipt_uuid.length);
});
// Upload receipts to sema
var _receipts = _fetch("POST", API_POST_SALE_ENDPOINT, receipts);
// TODO: Test Log uuid of each receipt on success
_receipts.forEach(function (receipt, index) {
// update uuid
updatePosition({
sheetName: "VENTES",
data: receipt.uuid,
x: receipts[index].line_number,
y: 16
});
// update updated_at
updatePosition({
sheetName: "VENTES",
data: receipt.updated_at,
x: receipts[index].line_number,
y: 17
});
});
console.log(data);
} catch (err) {
_log(err.message);
_toast(err.message);
}
}