瀏覽代碼

fix: purchase master

Muhammad Iqbal Afandi 3 年之前
父節點
當前提交
0ca0022582

+ 22
- 12
app/Http/Controllers/PurchaseController.php 查看文件

@@ -191,21 +191,31 @@ class PurchaseController extends Controller
191 191
                     "qty" => $product["qty"],
192 192
                 ];
193 193
 
194
-                if (empty($product["id"])) {
195
-                    $purchase->purchaseDetail()->create($validated);
196
-                } else {
197
-                    $purchase->purchaseDetail
198
-                        ->find($product["id"])
199
-                        ->update($validated);
194
+                if (!empty($product["label"])) {
195
+                    if ($product["label"] == "add") {
196
+                        $purchase->purchaseDetail()->create($validated);
197
+                    }
198
+
199
+                    if ($product["label"] == "edit") {
200
+                        $purchase->purchaseDetail
201
+                            ->find($product["id"])
202
+                            ->update($validated);
203
+                    }
204
+
205
+                    if ($product["label"] == "delete") {
206
+                        $purchase->purchaseDetail
207
+                            ->find($product["id"])
208
+                            ->delete();
209
+                    }
200 210
                 }
201 211
 
202
-                $validated = [
203
-                    "purchase_number" => $purchase->number,
204
-                    "qty" => $product["qty"],
205
-                    "product_number" => $product["number"],
206
-                ];
212
+                if ($request->status == "success") {
213
+                    $validated = [
214
+                        "purchase_number" => $purchase->number,
215
+                        "qty" => $product["qty"],
216
+                        "product_number" => $product["number"],
217
+                    ];
207 218
 
208
-                if ($request->status === "success") {
209 219
                     StockProduct::create($validated);
210 220
                 }
211 221
             }

+ 1
- 1
app/Http/Controllers/SalesController.php 查看文件

@@ -166,7 +166,7 @@ class SalesController extends Controller
166 166
 
167 167
             $sale->saleDetail()->update($request->safe()->except("status"));
168 168
 
169
-            if ($request->status === "success") {
169
+            if ($request->status == "success") {
170 170
                 StockProduct::create([
171 171
                     "sale_number" => $sale->number,
172 172
                     "qty" => -$request->qty,

+ 5
- 5
resources/js/pages/Purchases/Components/Cart.vue 查看文件

@@ -10,7 +10,7 @@ defineProps({
10 10
     required: true,
11 11
     type: Array,
12 12
   },
13
-  valueTable: {
13
+  productCart: {
14 14
     required: true,
15 15
     type: Array,
16 16
   },
@@ -26,7 +26,7 @@ const editingRows = ref([])
26 26
     columnResizeMode="expand"
27 27
     edit-mode="row"
28 28
     data-key="number"
29
-    :value="valueTable"
29
+    :value="productCart"
30 30
     :rowHover="true"
31 31
     :stripedRows="true"
32 32
     v-model:editing-rows="editingRows"
@@ -55,7 +55,7 @@ const editingRows = ref([])
55 55
       :header="value.header"
56 56
     >
57 57
       <template #body="{ data, field }">
58
-        <template v-if="field === 'price'">
58
+        <template v-if="field == 'price'">
59 59
           {{ IDRCurrencyFormat(data[field]) }}
60 60
         </template>
61 61
 
@@ -64,14 +64,14 @@ const editingRows = ref([])
64 64
 
65 65
       <template #editor="{ data, field }">
66 66
         <AppInputNumber
67
-          v-if="field === 'price'"
67
+          v-if="field == 'price'"
68 68
           label="Harga"
69 69
           placeholder="harga"
70 70
           v-model="data[field]"
71 71
         />
72 72
 
73 73
         <AppInputText
74
-          v-if="field === 'qty'"
74
+          v-if="field == 'qty'"
75 75
           label="Kuantitas"
76 76
           placeholder="kuantitas"
77 77
           type="number"

+ 16
- 2
resources/js/pages/Purchases/Composables/useProductCart.js 查看文件

@@ -1,9 +1,11 @@
1
-import FormValidationError from '@/utils/FormValidationError'
2 1
 import { reactive } from 'vue'
2
+import FormValidationError from '@/utils/FormValidationError'
3 3
 
4 4
 export function useProductCart(form, initialProducts = []) {
5 5
   const productCart = reactive(initialProducts)
6 6
 
7
+  const productCartDeleted = reactive([])
8
+
7 9
   const productValidation = () => {
8 10
     const existProduct = productCart.find(
9 11
       (product) => product.number === form.product.number
@@ -21,6 +23,7 @@ export function useProductCart(form, initialProducts = []) {
21 23
       productValidation()
22 24
 
23 25
       productCart.push({
26
+        label: 'add',
24 27
         number: form.product.number,
25 28
         name: form.product.name,
26 29
         price: form.price,
@@ -35,6 +38,13 @@ export function useProductCart(form, initialProducts = []) {
35 38
   }
36 39
 
37 40
   const onDeleteProduct = (index) => {
41
+    if (productCart[index]?.id) {
42
+      productCartDeleted.push({
43
+        ...productCart[index],
44
+        label: 'delete',
45
+      })
46
+    }
47
+
38 48
     productCart.splice(index, 1)
39 49
   }
40 50
 
@@ -57,11 +67,15 @@ export function useProductCart(form, initialProducts = []) {
57 67
   const onEditProduct = (event) => {
58 68
     const { newData, index } = event
59 69
 
60
-    productCart[index] = newData
70
+    productCart[index] = {
71
+      ...newData,
72
+      label: 'edit',
73
+    }
61 74
   }
62 75
 
63 76
   return {
64 77
     productCart,
78
+    productCartDeleted,
65 79
     onAddProduct,
66 80
     onDeleteProduct,
67 81
     onEditProduct,

+ 1
- 1
resources/js/pages/Purchases/Create.vue 查看文件

@@ -209,7 +209,7 @@ const { onShowCreateProduct, onShowCreateSupplier } = onShowDialog()
209 209
           <div class="col-12">
210 210
             <Cart
211 211
               title="Keranjang Produk"
212
-              :value-table="productCart"
212
+              :product-cart="productCart"
213 213
               :header-table="cartTable"
214 214
               v-model:checked-ppn="form.checkedPpn"
215 215
               @delete="onDeleteProduct"

+ 3
- 2
resources/js/pages/Purchases/Edit.vue 查看文件

@@ -40,13 +40,14 @@ const onSubmit = () => {
40 40
     .transform((data) => ({
41 41
       status: data.status,
42 42
       ppn: data.checkedPpn,
43
-      products: productCart,
43
+      products: [...productCart, ...productCartDeleted],
44 44
     }))
45 45
     .put(route('purchases.update', props.id))
46 46
 }
47 47
 
48 48
 const {
49 49
   productCart,
50
+  productCartDeleted,
50 51
   onAddProduct,
51 52
   onDeleteProduct,
52 53
   onEditProduct,
@@ -177,7 +178,7 @@ const { onShowCreateProduct } = onShowDialog()
177 178
           <div class="col-12">
178 179
             <Cart
179 180
               title="Keranjang Produk"
180
-              :value-table="productCart"
181
+              :product-cart="productCart"
181 182
               :header-table="cartTable"
182 183
               v-model:checked-ppn="form.checkedPpn"
183 184
               @delete="onDeleteProduct"

+ 1
- 1
resources/js/pages/Sales/Components/Cart.vue 查看文件

@@ -50,7 +50,7 @@ defineProps({
50 50
       :key="value.field"
51 51
     >
52 52
       <template #body="{ data, field }">
53
-        <template v-if="field === 'price'">
53
+        <template v-if="field == 'price'">
54 54
           {{ IDRCurrencyFormat(data[field]) }}
55 55
         </template>
56 56