Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@sentry/vue": "7.91.0",
"axios": "0.27.2",
"bootstrap": "5.3.2",
"core-js": "3.35.0",
"npm-check-updates": "16.3.25",
"qrcode.vue": "3.4.1",
"vue": "3.4.3",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">

<meta name="apple-mobile-web-app-title" content="Thadmin">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-startup-image" href="apple-splash-2048-2732.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="apple-splash-2732-2048.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<div id="page-container">
<Header />
<RouterView class="route-view" />
<RouterView />
</div>
</template>

Expand Down
45 changes: 37 additions & 8 deletions src/common/sales.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AxiosResponse } from "axios";
import Paginated from "@/models/paginated.model";
import Shift from "@/models/shift.model";
import Order from "@/models/order.model";
import _Order from "@/models/_order.model";
import Member from "@/models/member.model";
import Payable from "@/models/payable.model";
import OrderItem from "@/models/orderitem.model";
Expand All @@ -29,41 +28,71 @@ class SalesService {
const data: { order_items: OrderItem[] } = order?.getAPIData() ?? {
order_items: [],
};
const result: AxiosResponse<_Order> = await this.apiService.post(
const result: AxiosResponse = await this.apiService.post(
`/admin/sales/shifts/${shift}/orders/`,
data
);
const parsedData = {
...result.data,
subtotal: parseFloat(result.data.subtotal),
total_amount: parseFloat(result.data.total_amount),
discount: parseFloat(result.data.discount),
order_items: result.data.order_items.map((i: { total: string }) => ({
...i,
total: parseFloat(i.total),
})),
};
if (order !== null) {
order.updateFromAPI(result.data);
order.updateFromAPI(parsedData);
return order;
}
return Order.orderFromAPI(result.data);
return Order.orderFromAPI(parsedData);
}

async updateOrder(order: Order, shift: number | null = null): Promise<Order> {
if (order._o === null && shift !== null) {
order = await this.newOrder(shift, order);
return order;
}
const result: AxiosResponse<_Order> = await this.apiService.put(
const result: AxiosResponse = await this.apiService.put(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`/admin/sales/orders/${order._o.pk}/`,
// eslint-disable-next-line @typescript-eslint/ban-types
order.getAPIData() as {}
);
order.updateFromAPI(result.data);
const parsedData = {
...result.data,
subtotal: parseFloat(result.data.subtotal),
total_amount: parseFloat(result.data.total_amount),
discount: parseFloat(result.data.discount),
order_items: result.data.order_items.map((i: { total: string }) => ({
...i,
total: parseFloat(i.total),
})),
};
order.updateFromAPI(parsedData);
return order;
}

async getOrderDetails(order: Order): Promise<Order> {
const result: AxiosResponse<_Order> = await this.apiService.get(
const result: AxiosResponse = await this.apiService.get(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`/admin/sales/orders/${order._o.pk}/`
);
const parsedData = {
...result.data,
subtotal: parseFloat(result.data.subtotal),
total_amount: parseFloat(result.data.total_amount),
discount: parseFloat(result.data.discount),
order_items: result.data.order_items.map((i: { total: string }) => ({
...i,
total: parseFloat(i.total),
})),
};
if (order.synced) {
order.updateFromAPI(result.data);
order.updateFromAPI(parsedData);
}
return order;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ManualPaymentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
</template>

<script>
import Order from "@/common/sales.service";
import Order from "@/models/order.model";
import SalesService from "@/common/sales.service";

let salesService = new SalesService();

export default {
name: "OrderCard",
name: "ManualPaymentModal",
props: {
order: Order,
paymentMethod: String,
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrderCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
</template>

<script>
import Order from "@/common/sales.service";
import Order from "@/models/order.model";
import QrcodeVue from "qrcode.vue";
import ManualPaymentModal from "@/components/ManualPaymentModal";

Expand Down
18 changes: 10 additions & 8 deletions src/models/order.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Order {
}
if (this.items) {
return this.items.reduce(
(partialSum, i) => partialSum + (i.total ?? 0),
0
(partialSum, i) => partialSum + (i.total ?? 0.0),
0.0
);
}
return null;
Expand Down Expand Up @@ -183,12 +183,14 @@ class Order {
}
}

public getAPIData(): { order_items: OrderItem[] } {
let data = this.items;
if (data !== null) {
data.forEach((i) => delete i.total);
}
if (data === null) {
public getAPIData(): { order_items: { amount: number; product: string }[] } {
let data: { amount: number; product: string }[];
if (this.items !== null) {
data = this.items?.map((i: OrderItem) => ({
amount: i.amount,
product: i.product,
}));
} else {
data = [];
}
return { order_items: data };
Expand Down
2 changes: 1 addition & 1 deletion src/views/Shift.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default {
},
fetchOrderUpdates: async function () {
if (this.order.isPaid()) return;
if (!(this.orderBeingUpdated || this.updateOrderToServer != null)) {
if (!(this.orderBeingUpdated || this.updateOrderToServer != null || this.order.getPK()=== null)) {
// Do not GET if we're waiting for the response of a PUT
const order = await salesService.getOrderDetails(this.order);
if (this.order.getPK() === order._o.pk) {
Expand Down
Loading
Loading