Total:
- {{ numeral(storeCart.totalPrice).format('0,0') }}
+ {{ numeral(storeCart.cart).format('0,0') }}
@@ -154,12 +104,15 @@
{
storeCart.addItem({
+ id: e.id,
amount: 1,
product_code: e.product_code,
product_name: e.product_name,
price: e.selling_price
})
}" />
+
+
@@ -167,6 +120,7 @@
import numeral from 'numeral'
import { useElementSize, useWindowSize } from '@vueuse/core'
import { useStoreSalesCart } from '~/stores/cart/sales'
+import { NuxtUiModal } from '#components'
definePageMeta({
middleware: 'authentication'
@@ -244,6 +198,7 @@ const handleInputItem = (code: string) => {
}
storeCart.addItem({
+ id: data.id,
product_code: code,
product_name: data.product_name,
price: data.selling_price,
@@ -313,6 +268,7 @@ function actAfterNewProductCreated(newProduct: {
product_category_id: number;
}) {
storeCart.addItem({
+ id: newProduct.id,
price: newProduct.selling_price,
product_code: newProduct.product_code,
product_name: newProduct.product_name,
@@ -335,23 +291,11 @@ function actAfterNewProductCreated(newProduct: {
});
}
+const modalReceiptShown = ref(false)
function saveTransaction() {
// Implementation for saving transaction
// This is a placeholder that you would replace with your actual implementation
- const toast = useToast();
- const { execute } = use$fetchWithAutoReNew('/transactions', {
- method: 'post',
- body: { data: storeCart.cart },
- onResponse() {
- toast.add({
- title: 'Success',
- description: 'Transaction saved successfully',
- color: 'green'
- });
- storeCart.clearCart();
- }
- })
- execute()
+ modalReceiptShown.value = true
}
// Clean up timeout on component unmount
diff --git a/pages/dashboard/restock/index.vue b/pages/dashboard/restock/index.vue
index 1f196aa..913f37d 100644
--- a/pages/dashboard/restock/index.vue
+++ b/pages/dashboard/restock/index.vue
@@ -1,63 +1,13 @@
-
+
-
-
-
- {{ item.product_name }}
-
-
-
-
-
-
- Price:
- {{ numeral(Number(item.price)).format('0,0') }}
-
-
-
Qty:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sub Total:
-
- {{ numeral(calculateSubtotal(item)).format('0,0') }}
-
-
-
-
-
+
{
+ deleteModalId = index;
+ deleteModalShown = true
+ }" v-for="(item, index) in storePurchase.cart" :key="item.product_code + '-' + index"
+ :class="{ 'bg-green-500/50 dark:bg-green-400/50 animate-pulse': item.product_code === productAlreadyExist }" />
{
storePurchase.addItem({
+ id: e.id,
amount: 1,
product_code: e.product_code,
product_name: e.product_name,
@@ -161,6 +112,7 @@
})
}" />
+
@@ -247,6 +199,7 @@ const handleInputItem = (code: string) => {
// Add product to list
storePurchase.addItem({
+ id: data.id,
product_code: code,
product_name: data.product_name,
price: data.buying_price,
@@ -317,6 +270,7 @@ function actAfterNewProductCreated(newProduct: {
}) {
console.log(newProduct)
storePurchase.addItem({
+ id: newProduct.id,
price: newProduct.buying_price,
product_code: newProduct.product_code,
product_name: newProduct.product_name,
@@ -339,21 +293,9 @@ function actAfterNewProductCreated(newProduct: {
});
}
+const modalReceiptShown = ref(false)
function saveTransaction() {
- const toast = useToast();
- const { execute } = use$fetchWithAutoReNew('/restocks', {
- method: 'post',
- body: { data: storePurchase.cart },
- onResponse() {
- toast.add({
- title: 'Success',
- description: 'Transaction saved successfully',
- color: 'green'
- });
- storePurchase.clearCart();
- }
- })
- execute()
+ modalReceiptShown.value = true
}
// Clean up timeout on component unmount
diff --git a/stores/cart/purchase.ts b/stores/cart/purchase.ts
index 177fb64..2f3e167 100644
--- a/stores/cart/purchase.ts
+++ b/stores/cart/purchase.ts
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
type cartItem = {
+ id: number
product_code: string
product_name: string
price: number
diff --git a/stores/cart/sales.ts b/stores/cart/sales.ts
index 49f4c0e..c40f365 100644
--- a/stores/cart/sales.ts
+++ b/stores/cart/sales.ts
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
type cartItem = {
+ id: number
product_code: string
product_name: string
price: number
diff --git a/types/api-response/prediction.ts b/types/api-response/prediction.ts
index 185b99b..752ac1e 100644
--- a/types/api-response/prediction.ts
+++ b/types/api-response/prediction.ts
@@ -27,18 +27,19 @@ type StockPrediction = {
buying_price: number;
stock: number;
low_stock_limit: number;
- prediction: number | null;
- lower_bound: number | null;
- upper_bound: number | null;
+ prediction: number[] | null;
+ lower_bound: number[] | null;
+ upper_bound: number[] | null;
rmse: number | null;
mape: number | null;
- // fake_json: string
+ model: [number, number, number]
}
export type TStockPredictionResponse = TDynamicResponse
export type TStockPredictionListResponse = TDynamicResponse
export type TLatestPredictionListResponse = TDynamicResponse<{
product_name: string;
mape: number;
- prediction: number;
+ stock: number;
+ prediction: number[];
category_name: string;
}[]>
\ No newline at end of file
diff --git a/types/prediction/product-list.ts b/types/prediction/product-list.ts
index 488153c..b9864a8 100644
--- a/types/prediction/product-list.ts
+++ b/types/prediction/product-list.ts
@@ -8,5 +8,5 @@ export type TPredictionProductList = {
mape?: number
rmse?: number
model?: [number, number, number]
- status: 'unpredicted' | 'fetch-prediction' | 'loading' | 'predicted'
+ status: 'unpredicted' | 'fetch-prediction' | 'loading' | 'predicted' | 'invalid'
}[]
\ No newline at end of file
diff --git a/utils/math/getStockDeficitFromPrediction.ts b/utils/math/getStockDeficitFromPrediction.ts
new file mode 100644
index 0000000..0cab496
--- /dev/null
+++ b/utils/math/getStockDeficitFromPrediction.ts
@@ -0,0 +1,16 @@
+export function getStockDeficitFromPrediction(
+ predictionArray: number[],
+ stock: number
+) {
+ if (!Array.isArray(predictionArray)) throw new Error("predictionArray harus berupa array");
+ if (+stock < 1) stock = 0
+
+ const totalPrediction = predictionArray.reduce((sum, value) => {
+ const num = typeof value === 'number' ? value : Number(value);
+ return sum + (isNaN(num) ? 0 : Math.max(0, num));
+ }, 0);
+
+ const shortage = totalPrediction - stock;
+
+ return Math.max(0, shortage);
+}
\ No newline at end of file