bananas-commerce-admin 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extensions/pos/components/ReceiptTable.js +106 -96
- package/dist/cjs/extensions/pos/components/ReceiptTable.js.map +1 -1
- package/dist/esm/extensions/pos/components/ReceiptTable.js +105 -95
- package/dist/esm/extensions/pos/components/ReceiptTable.js.map +1 -1
- package/dist/types/extensions/pos/components/ReceiptTable.d.ts +1 -0
- package/package.json +1 -1
- package/src/extensions/pos/components/ReceiptTable.tsx +163 -134
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ReceiptTable = void 0;
|
|
26
|
+
exports.ReceiptTable = exports.HIDDEN_ITEM_TYPES = void 0;
|
|
27
27
|
var react_1 = __importDefault(require("react"));
|
|
28
28
|
var Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
|
|
29
29
|
var Input_1 = __importDefault(require("@mui/material/Input"));
|
|
@@ -35,11 +35,23 @@ var TableContainer_1 = __importDefault(require("@mui/material/TableContainer"));
|
|
|
35
35
|
var TableHead_1 = __importDefault(require("@mui/material/TableHead"));
|
|
36
36
|
var TableRow_1 = __importDefault(require("@mui/material/TableRow"));
|
|
37
37
|
var Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
38
|
+
exports.HIDDEN_ITEM_TYPES = ["SHIPPING", "PICKUP"];
|
|
38
39
|
var ReceiptTable = function (_a) {
|
|
39
40
|
var lines = _a.lines, currency = _a.currency, editable = _a.editable, onSelect = _a.onSelect;
|
|
40
41
|
var _b = react_1.default.useState([]), selected = _b[0], setSelected = _b[1];
|
|
41
42
|
var theme = (0, useTheme_1.default)();
|
|
42
|
-
var refundableLines = lines.filter(function (line) {
|
|
43
|
+
var refundableLines = lines.filter(function (line) {
|
|
44
|
+
return Boolean(line.adjustments.reduce(function (t, v) { return t + v.quantity; }, line.quantity));
|
|
45
|
+
});
|
|
46
|
+
var sortedLines = lines.sort(function (a, b) { return a.line_number - b.line_number; });
|
|
47
|
+
// Group lines by their whole number part, sorted by their decimal part
|
|
48
|
+
var groupedLines = sortedLines.reduce(function (lines, line) {
|
|
49
|
+
var _a;
|
|
50
|
+
var lineNumber = Math.floor(line.line_number);
|
|
51
|
+
(_a = lines[lineNumber]) !== null && _a !== void 0 ? _a : (lines[lineNumber] = []);
|
|
52
|
+
lines[lineNumber].push(line);
|
|
53
|
+
return lines;
|
|
54
|
+
}, []);
|
|
43
55
|
var toggleSelectAll = function (_, checked) {
|
|
44
56
|
setSelected(checked ? refundableLines : []);
|
|
45
57
|
};
|
|
@@ -82,105 +94,103 @@ var ReceiptTable = function (_a) {
|
|
|
82
94
|
["Quantity", "Unit Price", "Total", "Debit"].map(function (v) {
|
|
83
95
|
return (react_1.default.createElement(TableCell_1.default, { align: "right", sx: { fontWeight: "bold" } }, v));
|
|
84
96
|
}))),
|
|
85
|
-
react_1.default.createElement(TableBody_1.default, null,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
} },
|
|
102
|
-
editable ? (react_1.default.createElement(TableCell_1.default, { sx: { verticalAlign: "top" }, padding: "checkbox", align: "left" }, disabled ? null : (react_1.default.createElement(Checkbox_1.default, { color: "secondary", checked: isSelected && currentQuantity !== 0, onChange: function (_, checked) {
|
|
103
|
-
return toggleLine(__assign(__assign({}, line), { quantity: currentQuantity }), checked);
|
|
104
|
-
} })))) : null,
|
|
105
|
-
react_1.default.createElement(TableCell_1.default, { align: "left" },
|
|
106
|
-
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" }, line.title)),
|
|
107
|
-
react_1.default.createElement(TableCell_1.default, { align: "left" }, line.item_type == "SHIPPING" ? null : line.reference),
|
|
108
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
109
|
-
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" }, line.quantity)),
|
|
110
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
111
|
-
line.unit_price,
|
|
112
|
-
" ",
|
|
113
|
-
currency),
|
|
114
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
115
|
-
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" },
|
|
116
|
-
line.total_amount,
|
|
117
|
-
" ",
|
|
118
|
-
currency)),
|
|
119
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
120
|
-
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" },
|
|
121
|
-
line.total_amount,
|
|
122
|
-
" ",
|
|
123
|
-
currency))));
|
|
124
|
-
var adjustmentsRows = line.adjustments.map(function (adjustment, i) {
|
|
125
|
-
var lastRow = !editable && i == line.adjustments.length - 1;
|
|
126
|
-
var typeNameMap = {
|
|
127
|
-
CANCELLATION: "Cancellation",
|
|
128
|
-
RETURN: "Return",
|
|
129
|
-
REFUND: "Refund",
|
|
130
|
-
DISCOUNT: "Discount",
|
|
97
|
+
react_1.default.createElement(TableBody_1.default, null, groupedLines.flatMap(function (lines) {
|
|
98
|
+
return lines.flatMap(function (line, index) {
|
|
99
|
+
var isSelected = selected
|
|
100
|
+
.map(function (_a) {
|
|
101
|
+
var line_number = _a.line_number;
|
|
102
|
+
return line_number;
|
|
103
|
+
})
|
|
104
|
+
.includes(line.line_number);
|
|
105
|
+
var currentQuantity = line.adjustments.reduce(function (t, v) { return t + v.quantity; }, line.quantity);
|
|
106
|
+
var firstLine = index === 0;
|
|
107
|
+
var subLine = !firstLine;
|
|
108
|
+
var finalLine = index === lines.length - 1;
|
|
109
|
+
var borderBottom = {
|
|
110
|
+
borderBottomStyle: !finalLine ? "dotted" : undefined,
|
|
111
|
+
borderBottomWidth: !finalLine ? 2 : undefined,
|
|
131
112
|
};
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return typeNameMap[name];
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
var pending = adjustment.receipt_number === null;
|
|
141
|
-
return (react_1.default.createElement(TableRow_1.default, { key: line.line_number + String(i), sx: {
|
|
142
|
-
"& td": {
|
|
143
|
-
borderBottom: lastRow ? undefined : "none",
|
|
144
|
-
color: theme.palette.grey[600],
|
|
145
|
-
fontStyle: pending ? "italic" : undefined,
|
|
146
|
-
paddingY: 0,
|
|
147
|
-
paddingBottom: lastRow ? 1 : undefined,
|
|
148
|
-
},
|
|
113
|
+
var disabled = currentQuantity === 0;
|
|
114
|
+
var firstRow = (react_1.default.createElement(TableRow_1.default, { key: line.line_number, sx: {
|
|
115
|
+
"& td": __assign(__assign({}, borderBottom), { borderBottom: editable || line.adjustments.length ? "none" : undefined, paddingY: 0, paddingTop: 1, paddingBottom: line.adjustments.length ? undefined : 1 }),
|
|
149
116
|
} },
|
|
150
|
-
editable ? (react_1.default.createElement(TableCell_1.default, { sx: {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
react_1.default.createElement(TableCell_1.default,
|
|
154
|
-
|
|
155
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
156
|
-
react_1.default.createElement(TableCell_1.default, {
|
|
157
|
-
|
|
117
|
+
editable ? (react_1.default.createElement(TableCell_1.default, { sx: { verticalAlign: "top" }, padding: "checkbox", align: "left" }, disabled ? null : (react_1.default.createElement(Checkbox_1.default, { color: "secondary", checked: isSelected && currentQuantity !== 0, onChange: function (_, checked) {
|
|
118
|
+
return toggleLine(__assign(__assign({}, line), { quantity: currentQuantity }), checked);
|
|
119
|
+
} })))) : null,
|
|
120
|
+
react_1.default.createElement(TableCell_1.default, { align: "left" },
|
|
121
|
+
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem", paddingLeft: subLine ? 2 : undefined }, line.title)),
|
|
122
|
+
react_1.default.createElement(TableCell_1.default, { align: "left" }, line.item_type == "SHIPPING" ? null : line.reference),
|
|
123
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
124
|
+
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" }, line.quantity)),
|
|
125
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
126
|
+
line.unit_price,
|
|
158
127
|
" ",
|
|
159
128
|
currency),
|
|
160
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
129
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
130
|
+
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" },
|
|
131
|
+
line.total_amount,
|
|
132
|
+
" ",
|
|
133
|
+
currency)),
|
|
134
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" },
|
|
135
|
+
react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" },
|
|
136
|
+
line.total_amount,
|
|
137
|
+
" ",
|
|
138
|
+
currency))));
|
|
139
|
+
var adjustmentsRows = line.adjustments.map(function (adjustment, i) {
|
|
140
|
+
var lastRow = !editable && i == line.adjustments.length - 1;
|
|
141
|
+
var typeNameMap = {
|
|
142
|
+
CANCELLATION: "Cancellation",
|
|
143
|
+
RETURN: "Return",
|
|
144
|
+
REFUND: "Refund",
|
|
145
|
+
DISCOUNT: "Discount",
|
|
146
|
+
};
|
|
147
|
+
var withTitle = function (name, title) {
|
|
148
|
+
if (title) {
|
|
149
|
+
return "".concat(typeNameMap[name], ": ").concat(title);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return typeNameMap[name];
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var pending = adjustment.receipt_number === null;
|
|
156
|
+
return (react_1.default.createElement(TableRow_1.default, { key: line.line_number + String(i), sx: {
|
|
157
|
+
"& td": __assign(__assign({}, borderBottom), { borderBottom: lastRow ? undefined : "none", color: theme.palette.grey[600], fontStyle: pending ? "italic" : undefined, paddingY: 0, paddingBottom: lastRow ? 1 : undefined }),
|
|
158
|
+
} },
|
|
159
|
+
editable ? (react_1.default.createElement(TableCell_1.default, { sx: { paddingTop: 0.7 }, align: "left", padding: "checkbox" })) : null,
|
|
160
|
+
react_1.default.createElement(TableCell_1.default, null,
|
|
161
|
+
react_1.default.createElement(Typography_1.default, { paddingLeft: subLine ? 4 : 2, fontSize: "0.875rem" }, withTitle(adjustment.adjustment_type, adjustment.title))),
|
|
162
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
163
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" }, adjustment.quantity),
|
|
164
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
165
|
+
react_1.default.createElement(TableCell_1.default, { style: { verticalAlign: "top" }, align: "right" },
|
|
166
|
+
adjustment.total_amount,
|
|
167
|
+
" ",
|
|
168
|
+
currency),
|
|
169
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" }, lastRow && line.remaining_amount != line.total_amount ? (react_1.default.createElement(Typography_1.default, { fontSize: "0.875rem" },
|
|
170
|
+
"(",
|
|
171
|
+
line.remaining_amount,
|
|
172
|
+
" ",
|
|
173
|
+
currency,
|
|
174
|
+
")")) : null)));
|
|
175
|
+
});
|
|
176
|
+
var rows = __spreadArray([firstRow], adjustmentsRows, true);
|
|
177
|
+
if (editable) {
|
|
178
|
+
rows.push(react_1.default.createElement(TableRow_1.default, { sx: { "& td": { paddingTop: 0, paddingBottom: 1 } } },
|
|
179
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
180
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
181
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
182
|
+
react_1.default.createElement(TableCell_1.default, { align: "right" }, !disabled ? (react_1.default.createElement(Input_1.default, { type: "number", defaultValue: currentQuantity * -1, inputProps: {
|
|
183
|
+
max: Math.max(currentQuantity * -1, -1),
|
|
184
|
+
min: currentQuantity * -1,
|
|
185
|
+
}, disabled: !isSelected, onChange: function (event) {
|
|
186
|
+
return lineQuantityChange(__assign(__assign({}, line), { quantity: parseInt(event.target.value) * -1 }));
|
|
187
|
+
} })) : null),
|
|
188
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
189
|
+
react_1.default.createElement(TableCell_1.default, null),
|
|
190
|
+
react_1.default.createElement(TableCell_1.default, null)));
|
|
191
|
+
}
|
|
192
|
+
return rows;
|
|
166
193
|
});
|
|
167
|
-
var rows = __spreadArray([firstRow], adjustmentsRows, true);
|
|
168
|
-
if (editable) {
|
|
169
|
-
rows.push(react_1.default.createElement(TableRow_1.default, { sx: { "& td": { paddingTop: 0, paddingBottom: 1 } } },
|
|
170
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
171
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
172
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
173
|
-
react_1.default.createElement(TableCell_1.default, { align: "right" }, !disabled ? (react_1.default.createElement(Input_1.default, { type: "number", defaultValue: currentQuantity * -1, inputProps: {
|
|
174
|
-
max: Math.max(currentQuantity * -1, -1),
|
|
175
|
-
min: currentQuantity * -1,
|
|
176
|
-
}, disabled: !isSelected, onChange: function (event) {
|
|
177
|
-
return lineQuantityChange(__assign(__assign({}, line), { quantity: parseInt(event.target.value) * -1 }));
|
|
178
|
-
} })) : null),
|
|
179
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
180
|
-
react_1.default.createElement(TableCell_1.default, null),
|
|
181
|
-
react_1.default.createElement(TableCell_1.default, null)));
|
|
182
|
-
}
|
|
183
|
-
return rows;
|
|
184
194
|
})))));
|
|
185
195
|
};
|
|
186
196
|
exports.ReceiptTable = ReceiptTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceiptTable.js","sourceRoot":"","sources":["../../../../../src/extensions/pos/components/ReceiptTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAE1B,oEAA8C;AAC9C,8DAAwC;AACxC,2EAAqD;AACrD,8DAAwC;AACxC,sEAAgD;AAChD,sEAAgD;AAChD,gFAA0D;AAC1D,sEAAgD;AAChD,oEAA8C;AAC9C,wEAAkD;
|
|
1
|
+
{"version":3,"file":"ReceiptTable.js","sourceRoot":"","sources":["../../../../../src/extensions/pos/components/ReceiptTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAE1B,oEAA8C;AAC9C,8DAAwC;AACxC,2EAAqD;AACrD,8DAAwC;AACxC,sEAAgD;AAChD,sEAAgD;AAChD,gFAA0D;AAC1D,sEAAgD;AAChD,oEAA8C;AAC9C,wEAAkD;AAIrC,QAAA,iBAAiB,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AASjD,IAAM,YAAY,GAAgC,UAAC,EAKzD;QAJC,KAAK,WAAA,EACL,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,QAAQ,cAAA;IAEF,IAAA,KAA0B,eAAK,CAAC,QAAQ,CAAS,EAAE,CAAC,EAAnD,QAAQ,QAAA,EAAE,WAAW,QAA8B,CAAC;IAC3D,IAAM,KAAK,GAAG,IAAA,kBAAQ,GAAE,CAAC;IACzB,IAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,UAAC,IAAI;QACxC,OAAA,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAd,CAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAAzE,CAAyE,CAC1E,CAAC;IACF,IAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAA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I,CACP,8BAAC,kBAAQ,IAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE;4BAC3D,8BAAC,mBAAS,OAAa;4BACvB,8BAAC,mBAAS,OAAG;4BACb,8BAAC,mBAAS,OAAG;4BACb,8BAAC,mBAAS,IAAC,KAAK,EAAC,OAAO,IACrB,CAAC,QAAQ,CAAC,CAAC,CAAC,CACX,8BAAC,eAAK,IACJ,IAAI,EAAC,QAAQ,EACb,YAAY,EAAE,eAAe,GAAG,CAAC,CAAC,EAClC,UAAU,EAAE;oCACV,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oCACvC,GAAG,EAAE,eAAe,GAAG,CAAC,CAAC;iCAC1B,EACD,QAAQ,EAAE,CAAC,UAAU,EACrB,QAAQ,EAAE,UAAC,KAAK;oCACd,OAAA,kBAAkB,uBACb,IAAI,KACP,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAC3C;gCAHF,CAGE,GAEJ,CACH,CAAC,CAAC,CAAC,IAAI,CACE;4BACZ,8BAAC,mBAAS,OAAG;4BACb,8BAAC,mBAAS,OAAG;4BACb,8BAAC,mBAAS,OAAG,CACJ,CACZ,CAAC;qBACH;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YA7KF,CA6KE,CACH,CACS,CACN,CACO,CAClB,CAAC;AACJ,CAAC,CAAC;AAnQW,QAAA,YAAY,gBAmQvB"}
|
|
@@ -29,11 +29,23 @@ import TableContainer from "@mui/material/TableContainer";
|
|
|
29
29
|
import TableHead from "@mui/material/TableHead";
|
|
30
30
|
import TableRow from "@mui/material/TableRow";
|
|
31
31
|
import Typography from "@mui/material/Typography";
|
|
32
|
+
export var HIDDEN_ITEM_TYPES = ["SHIPPING", "PICKUP"];
|
|
32
33
|
export var ReceiptTable = function (_a) {
|
|
33
34
|
var lines = _a.lines, currency = _a.currency, editable = _a.editable, onSelect = _a.onSelect;
|
|
34
35
|
var _b = React.useState([]), selected = _b[0], setSelected = _b[1];
|
|
35
36
|
var theme = useTheme();
|
|
36
|
-
var refundableLines = lines.filter(function (line) {
|
|
37
|
+
var refundableLines = lines.filter(function (line) {
|
|
38
|
+
return Boolean(line.adjustments.reduce(function (t, v) { return t + v.quantity; }, line.quantity));
|
|
39
|
+
});
|
|
40
|
+
var sortedLines = lines.sort(function (a, b) { return a.line_number - b.line_number; });
|
|
41
|
+
// Group lines by their whole number part, sorted by their decimal part
|
|
42
|
+
var groupedLines = sortedLines.reduce(function (lines, line) {
|
|
43
|
+
var _a;
|
|
44
|
+
var lineNumber = Math.floor(line.line_number);
|
|
45
|
+
(_a = lines[lineNumber]) !== null && _a !== void 0 ? _a : (lines[lineNumber] = []);
|
|
46
|
+
lines[lineNumber].push(line);
|
|
47
|
+
return lines;
|
|
48
|
+
}, []);
|
|
37
49
|
var toggleSelectAll = function (_, checked) {
|
|
38
50
|
setSelected(checked ? refundableLines : []);
|
|
39
51
|
};
|
|
@@ -76,105 +88,103 @@ export var ReceiptTable = function (_a) {
|
|
|
76
88
|
["Quantity", "Unit Price", "Total", "Debit"].map(function (v) {
|
|
77
89
|
return (React.createElement(TableCell, { align: "right", sx: { fontWeight: "bold" } }, v));
|
|
78
90
|
}))),
|
|
79
|
-
React.createElement(TableBody, null,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
} },
|
|
96
|
-
editable ? (React.createElement(TableCell, { sx: { verticalAlign: "top" }, padding: "checkbox", align: "left" }, disabled ? null : (React.createElement(Checkbox, { color: "secondary", checked: isSelected && currentQuantity !== 0, onChange: function (_, checked) {
|
|
97
|
-
return toggleLine(__assign(__assign({}, line), { quantity: currentQuantity }), checked);
|
|
98
|
-
} })))) : null,
|
|
99
|
-
React.createElement(TableCell, { align: "left" },
|
|
100
|
-
React.createElement(Typography, { fontSize: "0.875rem" }, line.title)),
|
|
101
|
-
React.createElement(TableCell, { align: "left" }, line.item_type == "SHIPPING" ? null : line.reference),
|
|
102
|
-
React.createElement(TableCell, { align: "right" },
|
|
103
|
-
React.createElement(Typography, { fontSize: "0.875rem" }, line.quantity)),
|
|
104
|
-
React.createElement(TableCell, { align: "right" },
|
|
105
|
-
line.unit_price,
|
|
106
|
-
" ",
|
|
107
|
-
currency),
|
|
108
|
-
React.createElement(TableCell, { align: "right" },
|
|
109
|
-
React.createElement(Typography, { fontSize: "0.875rem" },
|
|
110
|
-
line.total_amount,
|
|
111
|
-
" ",
|
|
112
|
-
currency)),
|
|
113
|
-
React.createElement(TableCell, { align: "right" },
|
|
114
|
-
React.createElement(Typography, { fontSize: "0.875rem" },
|
|
115
|
-
line.total_amount,
|
|
116
|
-
" ",
|
|
117
|
-
currency))));
|
|
118
|
-
var adjustmentsRows = line.adjustments.map(function (adjustment, i) {
|
|
119
|
-
var lastRow = !editable && i == line.adjustments.length - 1;
|
|
120
|
-
var typeNameMap = {
|
|
121
|
-
CANCELLATION: "Cancellation",
|
|
122
|
-
RETURN: "Return",
|
|
123
|
-
REFUND: "Refund",
|
|
124
|
-
DISCOUNT: "Discount",
|
|
91
|
+
React.createElement(TableBody, null, groupedLines.flatMap(function (lines) {
|
|
92
|
+
return lines.flatMap(function (line, index) {
|
|
93
|
+
var isSelected = selected
|
|
94
|
+
.map(function (_a) {
|
|
95
|
+
var line_number = _a.line_number;
|
|
96
|
+
return line_number;
|
|
97
|
+
})
|
|
98
|
+
.includes(line.line_number);
|
|
99
|
+
var currentQuantity = line.adjustments.reduce(function (t, v) { return t + v.quantity; }, line.quantity);
|
|
100
|
+
var firstLine = index === 0;
|
|
101
|
+
var subLine = !firstLine;
|
|
102
|
+
var finalLine = index === lines.length - 1;
|
|
103
|
+
var borderBottom = {
|
|
104
|
+
borderBottomStyle: !finalLine ? "dotted" : undefined,
|
|
105
|
+
borderBottomWidth: !finalLine ? 2 : undefined,
|
|
125
106
|
};
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return typeNameMap[name];
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var pending = adjustment.receipt_number === null;
|
|
135
|
-
return (React.createElement(TableRow, { key: line.line_number + String(i), sx: {
|
|
136
|
-
"& td": {
|
|
137
|
-
borderBottom: lastRow ? undefined : "none",
|
|
138
|
-
color: theme.palette.grey[600],
|
|
139
|
-
fontStyle: pending ? "italic" : undefined,
|
|
140
|
-
paddingY: 0,
|
|
141
|
-
paddingBottom: lastRow ? 1 : undefined,
|
|
142
|
-
},
|
|
107
|
+
var disabled = currentQuantity === 0;
|
|
108
|
+
var firstRow = (React.createElement(TableRow, { key: line.line_number, sx: {
|
|
109
|
+
"& td": __assign(__assign({}, borderBottom), { borderBottom: editable || line.adjustments.length ? "none" : undefined, paddingY: 0, paddingTop: 1, paddingBottom: line.adjustments.length ? undefined : 1 }),
|
|
143
110
|
} },
|
|
144
|
-
editable ? (React.createElement(TableCell, { sx: {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
React.createElement(TableCell,
|
|
148
|
-
|
|
149
|
-
React.createElement(TableCell, null),
|
|
150
|
-
React.createElement(TableCell, {
|
|
151
|
-
|
|
111
|
+
editable ? (React.createElement(TableCell, { sx: { verticalAlign: "top" }, padding: "checkbox", align: "left" }, disabled ? null : (React.createElement(Checkbox, { color: "secondary", checked: isSelected && currentQuantity !== 0, onChange: function (_, checked) {
|
|
112
|
+
return toggleLine(__assign(__assign({}, line), { quantity: currentQuantity }), checked);
|
|
113
|
+
} })))) : null,
|
|
114
|
+
React.createElement(TableCell, { align: "left" },
|
|
115
|
+
React.createElement(Typography, { fontSize: "0.875rem", paddingLeft: subLine ? 2 : undefined }, line.title)),
|
|
116
|
+
React.createElement(TableCell, { align: "left" }, line.item_type == "SHIPPING" ? null : line.reference),
|
|
117
|
+
React.createElement(TableCell, { align: "right" },
|
|
118
|
+
React.createElement(Typography, { fontSize: "0.875rem" }, line.quantity)),
|
|
119
|
+
React.createElement(TableCell, { align: "right" },
|
|
120
|
+
line.unit_price,
|
|
152
121
|
" ",
|
|
153
122
|
currency),
|
|
154
|
-
React.createElement(TableCell, { align: "right" },
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
123
|
+
React.createElement(TableCell, { align: "right" },
|
|
124
|
+
React.createElement(Typography, { fontSize: "0.875rem" },
|
|
125
|
+
line.total_amount,
|
|
126
|
+
" ",
|
|
127
|
+
currency)),
|
|
128
|
+
React.createElement(TableCell, { align: "right" },
|
|
129
|
+
React.createElement(Typography, { fontSize: "0.875rem" },
|
|
130
|
+
line.total_amount,
|
|
131
|
+
" ",
|
|
132
|
+
currency))));
|
|
133
|
+
var adjustmentsRows = line.adjustments.map(function (adjustment, i) {
|
|
134
|
+
var lastRow = !editable && i == line.adjustments.length - 1;
|
|
135
|
+
var typeNameMap = {
|
|
136
|
+
CANCELLATION: "Cancellation",
|
|
137
|
+
RETURN: "Return",
|
|
138
|
+
REFUND: "Refund",
|
|
139
|
+
DISCOUNT: "Discount",
|
|
140
|
+
};
|
|
141
|
+
var withTitle = function (name, title) {
|
|
142
|
+
if (title) {
|
|
143
|
+
return "".concat(typeNameMap[name], ": ").concat(title);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return typeNameMap[name];
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var pending = adjustment.receipt_number === null;
|
|
150
|
+
return (React.createElement(TableRow, { key: line.line_number + String(i), sx: {
|
|
151
|
+
"& td": __assign(__assign({}, borderBottom), { borderBottom: lastRow ? undefined : "none", color: theme.palette.grey[600], fontStyle: pending ? "italic" : undefined, paddingY: 0, paddingBottom: lastRow ? 1 : undefined }),
|
|
152
|
+
} },
|
|
153
|
+
editable ? (React.createElement(TableCell, { sx: { paddingTop: 0.7 }, align: "left", padding: "checkbox" })) : null,
|
|
154
|
+
React.createElement(TableCell, null,
|
|
155
|
+
React.createElement(Typography, { paddingLeft: subLine ? 4 : 2, fontSize: "0.875rem" }, withTitle(adjustment.adjustment_type, adjustment.title))),
|
|
156
|
+
React.createElement(TableCell, null),
|
|
157
|
+
React.createElement(TableCell, { align: "right" }, adjustment.quantity),
|
|
158
|
+
React.createElement(TableCell, null),
|
|
159
|
+
React.createElement(TableCell, { style: { verticalAlign: "top" }, align: "right" },
|
|
160
|
+
adjustment.total_amount,
|
|
161
|
+
" ",
|
|
162
|
+
currency),
|
|
163
|
+
React.createElement(TableCell, { align: "right" }, lastRow && line.remaining_amount != line.total_amount ? (React.createElement(Typography, { fontSize: "0.875rem" },
|
|
164
|
+
"(",
|
|
165
|
+
line.remaining_amount,
|
|
166
|
+
" ",
|
|
167
|
+
currency,
|
|
168
|
+
")")) : null)));
|
|
169
|
+
});
|
|
170
|
+
var rows = __spreadArray([firstRow], adjustmentsRows, true);
|
|
171
|
+
if (editable) {
|
|
172
|
+
rows.push(React.createElement(TableRow, { sx: { "& td": { paddingTop: 0, paddingBottom: 1 } } },
|
|
173
|
+
React.createElement(TableCell, null),
|
|
174
|
+
React.createElement(TableCell, null),
|
|
175
|
+
React.createElement(TableCell, null),
|
|
176
|
+
React.createElement(TableCell, { align: "right" }, !disabled ? (React.createElement(Input, { type: "number", defaultValue: currentQuantity * -1, inputProps: {
|
|
177
|
+
max: Math.max(currentQuantity * -1, -1),
|
|
178
|
+
min: currentQuantity * -1,
|
|
179
|
+
}, disabled: !isSelected, onChange: function (event) {
|
|
180
|
+
return lineQuantityChange(__assign(__assign({}, line), { quantity: parseInt(event.target.value) * -1 }));
|
|
181
|
+
} })) : null),
|
|
182
|
+
React.createElement(TableCell, null),
|
|
183
|
+
React.createElement(TableCell, null),
|
|
184
|
+
React.createElement(TableCell, null)));
|
|
185
|
+
}
|
|
186
|
+
return rows;
|
|
160
187
|
});
|
|
161
|
-
var rows = __spreadArray([firstRow], adjustmentsRows, true);
|
|
162
|
-
if (editable) {
|
|
163
|
-
rows.push(React.createElement(TableRow, { sx: { "& td": { paddingTop: 0, paddingBottom: 1 } } },
|
|
164
|
-
React.createElement(TableCell, null),
|
|
165
|
-
React.createElement(TableCell, null),
|
|
166
|
-
React.createElement(TableCell, null),
|
|
167
|
-
React.createElement(TableCell, { align: "right" }, !disabled ? (React.createElement(Input, { type: "number", defaultValue: currentQuantity * -1, inputProps: {
|
|
168
|
-
max: Math.max(currentQuantity * -1, -1),
|
|
169
|
-
min: currentQuantity * -1,
|
|
170
|
-
}, disabled: !isSelected, onChange: function (event) {
|
|
171
|
-
return lineQuantityChange(__assign(__assign({}, line), { quantity: parseInt(event.target.value) * -1 }));
|
|
172
|
-
} })) : null),
|
|
173
|
-
React.createElement(TableCell, null),
|
|
174
|
-
React.createElement(TableCell, null),
|
|
175
|
-
React.createElement(TableCell, null)));
|
|
176
|
-
}
|
|
177
|
-
return rows;
|
|
178
188
|
})))));
|
|
179
189
|
};
|
|
180
190
|
//# sourceMappingURL=ReceiptTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceiptTable.js","sourceRoot":"","sources":["../../../../../src/extensions/pos/components/ReceiptTable.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,QAAQ,MAAM,+BAA+B,CAAC;AACrD,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,cAAc,MA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AEH,IAAM,IAAI,kBAAI,QAAQ,GAAK,eAAe,OAAC,CAAC;oBAE5C,IAAI,QAAQ,EAAE;wBACZ,IAAI,CAAC,IAAI,CACP,oBAAC,QAAQ,IAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE;4BAC3D,oBAAC,SAAS,OAAa;4BACvB,oBAAC,SAAS,OAAG;4BACb,oBAAC,SAAS,OAAG;4BACb,oBAAC,SAAS,IAAC,KAAK,EAAC,OAAO,IACrB,CAAC,QAAQ,CAAC,CAAC,CAAC,CACX,oBAAC,KAAK,IACJ,IAAI,EAAC,QAAQ,EACb,YAAY,EAAE,eAAe,GAAG,CAAC,CAAC,EAClC,UAAU,EAAE;oCACV,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oCACvC,GAAG,EAAE,eAAe,GAAG,CAAC,CAAC;iCAC1B,EACD,QAAQ,EAAE,CAAC,UAAU,EACrB,QAAQ,EAAE,UAAC,KAAK;oCACd,OAAA,kBAAkB,uBACb,IAAI,KACP,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAC3C;gCAHF,CAGE,GAEJ,CACH,CAAC,CAAC,CAAC,IAAI,CACE;4BACZ,oBAAC,SAAS,OAAG;4BACb,oBAAC,SAAS,OAAG;4BACb,oBAAC,SAAS,OAAG,CACJ,CACZ,CAAC;qBACH;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YA7KF,CA6KE,CACH,CACS,CACN,CACO,CAClB,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -13,6 +13,8 @@ import Typography from "@mui/material/Typography";
|
|
|
13
13
|
|
|
14
14
|
import { Adjustment, Line } from "../types/purchase";
|
|
15
15
|
|
|
16
|
+
export const HIDDEN_ITEM_TYPES = ["SHIPPING", "PICKUP"];
|
|
17
|
+
|
|
16
18
|
export interface ReceiptTableProps {
|
|
17
19
|
currency: string;
|
|
18
20
|
lines: Line[];
|
|
@@ -28,9 +30,17 @@ export const ReceiptTable: React.FC<ReceiptTableProps> = ({
|
|
|
28
30
|
}) => {
|
|
29
31
|
const [selected, setSelected] = React.useState<Line[]>([]);
|
|
30
32
|
const theme = useTheme();
|
|
31
|
-
const refundableLines = lines.filter(
|
|
32
|
-
(line
|
|
33
|
+
const refundableLines = lines.filter((line) =>
|
|
34
|
+
Boolean(line.adjustments.reduce((t, v) => t + v.quantity, line.quantity))
|
|
33
35
|
);
|
|
36
|
+
const sortedLines = lines.sort((a, b) => a.line_number - b.line_number);
|
|
37
|
+
// Group lines by their whole number part, sorted by their decimal part
|
|
38
|
+
const groupedLines = sortedLines.reduce<Line[][]>((lines, line) => {
|
|
39
|
+
const lineNumber = Math.floor(line.line_number);
|
|
40
|
+
lines[lineNumber] ??= [];
|
|
41
|
+
lines[lineNumber].push(line);
|
|
42
|
+
return lines;
|
|
43
|
+
}, []);
|
|
34
44
|
|
|
35
45
|
const toggleSelectAll = (_: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {
|
|
36
46
|
setSelected(checked ? refundableLines : []);
|
|
@@ -91,163 +101,182 @@ export const ReceiptTable: React.FC<ReceiptTableProps> = ({
|
|
|
91
101
|
</TableRow>
|
|
92
102
|
</TableHead>
|
|
93
103
|
<TableBody>
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const currentQuantity = line.adjustments.reduce(
|
|
100
|
-
(t, v) => t + v.quantity,
|
|
101
|
-
line.quantity
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const disabled = currentQuantity === 0;
|
|
105
|
-
|
|
106
|
-
const firstRow = (
|
|
107
|
-
<TableRow
|
|
108
|
-
key={line.line_number}
|
|
109
|
-
sx={{
|
|
110
|
-
"& td": {
|
|
111
|
-
borderBottom: editable || line.adjustments.length ? "none" : undefined,
|
|
112
|
-
paddingY: 0,
|
|
113
|
-
paddingTop: 1,
|
|
114
|
-
paddingBottom: line.adjustments.length ? undefined : 1,
|
|
115
|
-
},
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
{editable ? (
|
|
119
|
-
<TableCell sx={{ verticalAlign: "top" }} padding="checkbox" align="left">
|
|
120
|
-
{disabled ? null : (
|
|
121
|
-
<Checkbox
|
|
122
|
-
color="secondary"
|
|
123
|
-
checked={isSelected && currentQuantity !== 0}
|
|
124
|
-
onChange={(_, checked) =>
|
|
125
|
-
toggleLine({ ...line, quantity: currentQuantity }, checked)
|
|
126
|
-
}
|
|
127
|
-
/>
|
|
128
|
-
)}
|
|
129
|
-
</TableCell>
|
|
130
|
-
) : null}
|
|
131
|
-
|
|
132
|
-
<TableCell align="left">
|
|
133
|
-
<Typography fontSize="0.875rem">{line.title}</Typography>
|
|
134
|
-
</TableCell>
|
|
135
|
-
<TableCell align="left">
|
|
136
|
-
{line.item_type == "SHIPPING" ? null : line.reference}
|
|
137
|
-
</TableCell>
|
|
138
|
-
<TableCell align="right">
|
|
139
|
-
<Typography fontSize="0.875rem">{line.quantity}</Typography>
|
|
140
|
-
</TableCell>
|
|
141
|
-
<TableCell align="right">
|
|
142
|
-
{line.unit_price} {currency}
|
|
143
|
-
</TableCell>
|
|
144
|
-
<TableCell align="right">
|
|
145
|
-
<Typography fontSize="0.875rem">
|
|
146
|
-
{line.total_amount} {currency}
|
|
147
|
-
</Typography>
|
|
148
|
-
</TableCell>
|
|
149
|
-
<TableCell align="right">
|
|
150
|
-
<Typography fontSize="0.875rem">
|
|
151
|
-
{line.total_amount} {currency}
|
|
152
|
-
</Typography>
|
|
153
|
-
</TableCell>
|
|
154
|
-
</TableRow>
|
|
155
|
-
);
|
|
104
|
+
{groupedLines.flatMap((lines) =>
|
|
105
|
+
lines.flatMap((line, index) => {
|
|
106
|
+
const isSelected = selected
|
|
107
|
+
.map(({ line_number }) => line_number)
|
|
108
|
+
.includes(line.line_number);
|
|
156
109
|
|
|
157
|
-
|
|
158
|
-
|
|
110
|
+
const currentQuantity = line.adjustments.reduce(
|
|
111
|
+
(t, v) => t + v.quantity,
|
|
112
|
+
line.quantity
|
|
113
|
+
);
|
|
159
114
|
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
REFUND: "Refund",
|
|
164
|
-
DISCOUNT: "Discount",
|
|
165
|
-
};
|
|
115
|
+
const firstLine = index === 0;
|
|
116
|
+
const subLine = !firstLine;
|
|
117
|
+
const finalLine = index === lines.length - 1;
|
|
166
118
|
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return typeNameMap[name];
|
|
172
|
-
}
|
|
173
|
-
};
|
|
119
|
+
const borderBottom = {
|
|
120
|
+
borderBottomStyle: !finalLine ? "dotted" : undefined,
|
|
121
|
+
borderBottomWidth: !finalLine ? 2 : undefined,
|
|
122
|
+
} as const;
|
|
174
123
|
|
|
175
|
-
const
|
|
124
|
+
const disabled = currentQuantity === 0;
|
|
176
125
|
|
|
177
|
-
|
|
126
|
+
const firstRow = (
|
|
178
127
|
<TableRow
|
|
179
|
-
key={line.line_number
|
|
128
|
+
key={line.line_number}
|
|
180
129
|
sx={{
|
|
181
130
|
"& td": {
|
|
182
|
-
borderBottom
|
|
183
|
-
|
|
184
|
-
fontStyle: pending ? "italic" : undefined,
|
|
131
|
+
...borderBottom,
|
|
132
|
+
borderBottom: editable || line.adjustments.length ? "none" : undefined,
|
|
185
133
|
paddingY: 0,
|
|
186
|
-
|
|
134
|
+
paddingTop: 1,
|
|
135
|
+
paddingBottom: line.adjustments.length ? undefined : 1,
|
|
187
136
|
},
|
|
188
137
|
}}
|
|
189
138
|
>
|
|
190
139
|
{editable ? (
|
|
191
|
-
<TableCell sx={{
|
|
140
|
+
<TableCell sx={{ verticalAlign: "top" }} padding="checkbox" align="left">
|
|
141
|
+
{disabled ? null : (
|
|
142
|
+
<Checkbox
|
|
143
|
+
color="secondary"
|
|
144
|
+
checked={isSelected && currentQuantity !== 0}
|
|
145
|
+
onChange={(_, checked) =>
|
|
146
|
+
toggleLine({ ...line, quantity: currentQuantity }, checked)
|
|
147
|
+
}
|
|
148
|
+
/>
|
|
149
|
+
)}
|
|
150
|
+
</TableCell>
|
|
192
151
|
) : null}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
152
|
+
|
|
153
|
+
<TableCell align="left">
|
|
154
|
+
<Typography fontSize="0.875rem" paddingLeft={subLine ? 2 : undefined}>
|
|
155
|
+
{line.title}
|
|
196
156
|
</Typography>
|
|
197
157
|
</TableCell>
|
|
198
|
-
<TableCell
|
|
199
|
-
|
|
200
|
-
<TableCell />
|
|
201
|
-
<TableCell style={{ verticalAlign: "top" }} align="right">
|
|
202
|
-
{adjustment.total_amount} {currency}
|
|
158
|
+
<TableCell align="left">
|
|
159
|
+
{line.item_type == "SHIPPING" ? null : line.reference}
|
|
203
160
|
</TableCell>
|
|
204
161
|
<TableCell align="right">
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
162
|
+
<Typography fontSize="0.875rem">{line.quantity}</Typography>
|
|
163
|
+
</TableCell>
|
|
164
|
+
<TableCell align="right">
|
|
165
|
+
{line.unit_price} {currency}
|
|
166
|
+
</TableCell>
|
|
167
|
+
<TableCell align="right">
|
|
168
|
+
<Typography fontSize="0.875rem">
|
|
169
|
+
{line.total_amount} {currency}
|
|
170
|
+
</Typography>
|
|
171
|
+
</TableCell>
|
|
172
|
+
<TableCell align="right">
|
|
173
|
+
<Typography fontSize="0.875rem">
|
|
174
|
+
{line.total_amount} {currency}
|
|
175
|
+
</Typography>
|
|
210
176
|
</TableCell>
|
|
211
177
|
</TableRow>
|
|
212
178
|
);
|
|
213
|
-
});
|
|
214
179
|
|
|
215
|
-
|
|
180
|
+
const adjustmentsRows = line.adjustments.map((adjustment, i) => {
|
|
181
|
+
const lastRow = !editable && i == line.adjustments.length - 1;
|
|
216
182
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
183
|
+
const typeNameMap: Record<Adjustment["title"], string> = {
|
|
184
|
+
CANCELLATION: "Cancellation",
|
|
185
|
+
RETURN: "Return",
|
|
186
|
+
REFUND: "Refund",
|
|
187
|
+
DISCOUNT: "Discount",
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const withTitle = (name: string, title: string) => {
|
|
191
|
+
if (title) {
|
|
192
|
+
return `${typeNameMap[name]}: ${title}`;
|
|
193
|
+
} else {
|
|
194
|
+
return typeNameMap[name];
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const pending = adjustment.receipt_number === null;
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<TableRow
|
|
202
|
+
key={line.line_number + String(i)}
|
|
203
|
+
sx={{
|
|
204
|
+
"& td": {
|
|
205
|
+
...borderBottom,
|
|
206
|
+
borderBottom: lastRow ? undefined : "none",
|
|
207
|
+
color: theme.palette.grey[600],
|
|
208
|
+
fontStyle: pending ? "italic" : undefined,
|
|
209
|
+
paddingY: 0,
|
|
210
|
+
paddingBottom: lastRow ? 1 : undefined,
|
|
211
|
+
},
|
|
212
|
+
}}
|
|
213
|
+
>
|
|
214
|
+
{editable ? (
|
|
215
|
+
<TableCell
|
|
216
|
+
sx={{ paddingTop: 0.7 }}
|
|
217
|
+
align="left"
|
|
218
|
+
padding="checkbox"
|
|
219
|
+
></TableCell>
|
|
240
220
|
) : null}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
221
|
+
<TableCell>
|
|
222
|
+
<Typography paddingLeft={subLine ? 4 : 2} fontSize="0.875rem">
|
|
223
|
+
{withTitle(adjustment.adjustment_type, adjustment.title)}
|
|
224
|
+
</Typography>
|
|
225
|
+
</TableCell>
|
|
226
|
+
<TableCell />
|
|
227
|
+
<TableCell align="right">{adjustment.quantity}</TableCell>
|
|
228
|
+
<TableCell />
|
|
229
|
+
<TableCell style={{ verticalAlign: "top" }} align="right">
|
|
230
|
+
{adjustment.total_amount} {currency}
|
|
231
|
+
</TableCell>
|
|
232
|
+
<TableCell align="right">
|
|
233
|
+
{lastRow && line.remaining_amount != line.total_amount ? (
|
|
234
|
+
<Typography fontSize="0.875rem">
|
|
235
|
+
({line.remaining_amount} {currency})
|
|
236
|
+
</Typography>
|
|
237
|
+
) : null}
|
|
238
|
+
</TableCell>
|
|
239
|
+
</TableRow>
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const rows = [firstRow, ...adjustmentsRows];
|
|
244
|
+
|
|
245
|
+
if (editable) {
|
|
246
|
+
rows.push(
|
|
247
|
+
<TableRow sx={{ "& td": { paddingTop: 0, paddingBottom: 1 } }}>
|
|
248
|
+
<TableCell></TableCell>
|
|
249
|
+
<TableCell />
|
|
250
|
+
<TableCell />
|
|
251
|
+
<TableCell align="right">
|
|
252
|
+
{!disabled ? (
|
|
253
|
+
<Input
|
|
254
|
+
type="number"
|
|
255
|
+
defaultValue={currentQuantity * -1}
|
|
256
|
+
inputProps={{
|
|
257
|
+
max: Math.max(currentQuantity * -1, -1),
|
|
258
|
+
min: currentQuantity * -1,
|
|
259
|
+
}}
|
|
260
|
+
disabled={!isSelected}
|
|
261
|
+
onChange={(event) =>
|
|
262
|
+
lineQuantityChange({
|
|
263
|
+
...line,
|
|
264
|
+
quantity: parseInt(event.target.value) * -1,
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
/>
|
|
268
|
+
) : null}
|
|
269
|
+
</TableCell>
|
|
270
|
+
<TableCell />
|
|
271
|
+
<TableCell />
|
|
272
|
+
<TableCell />
|
|
273
|
+
</TableRow>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
248
276
|
|
|
249
|
-
|
|
250
|
-
|
|
277
|
+
return rows;
|
|
278
|
+
})
|
|
279
|
+
)}
|
|
251
280
|
</TableBody>
|
|
252
281
|
</Table>
|
|
253
282
|
</TableContainer>
|