Muhammad Iqbal Afandi 3 лет назад
Родитель
Сommit
0ca0022582

+ 22
- 12
app/Http/Controllers/PurchaseController.php Просмотреть файл

191
                     "qty" => $product["qty"],
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
                     StockProduct::create($validated);
219
                     StockProduct::create($validated);
210
                 }
220
                 }
211
             }
221
             }

+ 1
- 1
app/Http/Controllers/SalesController.php Просмотреть файл

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

+ 5
- 5
resources/js/pages/Purchases/Components/Cart.vue Просмотреть файл

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

+ 16
- 2
resources/js/pages/Purchases/Composables/useProductCart.js Просмотреть файл

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

+ 1
- 1
resources/js/pages/Purchases/Create.vue Просмотреть файл

209
           <div class="col-12">
209
           <div class="col-12">
210
             <Cart
210
             <Cart
211
               title="Keranjang Produk"
211
               title="Keranjang Produk"
212
-              :value-table="productCart"
212
+              :product-cart="productCart"
213
               :header-table="cartTable"
213
               :header-table="cartTable"
214
               v-model:checked-ppn="form.checkedPpn"
214
               v-model:checked-ppn="form.checkedPpn"
215
               @delete="onDeleteProduct"
215
               @delete="onDeleteProduct"

+ 3
- 2
resources/js/pages/Purchases/Edit.vue Просмотреть файл

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

+ 1
- 1
resources/js/pages/Sales/Components/Cart.vue Просмотреть файл

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