Pārlūkot izejas kodu

fix: update purchases

Muhammad Iqbal Afandi 3 gadus atpakaļ
vecāks
revīzija
3d721847a6

+ 11
- 14
app/Http/Controllers/PurchaseController.php Parādīt failu

17
 use App\Http\Requests\Purchase\UpdatePurchaseRequest;
17
 use App\Http\Requests\Purchase\UpdatePurchaseRequest;
18
 use App\Models\Company;
18
 use App\Models\Company;
19
 use App\Models\User;
19
 use App\Models\User;
20
-use App\Policies\PurchasePolicy;
21
 use App\Services\FunctionService;
20
 use App\Services\FunctionService;
22
 use App\Services\PurchaseService;
21
 use App\Services\PurchaseService;
23
 
22
 
224
      */
223
      */
225
     public function update(UpdatePurchaseRequest $request, Purchase $purchase)
224
     public function update(UpdatePurchaseRequest $request, Purchase $purchase)
226
     {
225
     {
226
+        // dd($request);
227
+
227
         DB::beginTransaction();
228
         DB::beginTransaction();
228
 
229
 
229
         try {
230
         try {
244
                 ];
245
                 ];
245
 
246
 
246
                 if (!empty($product["label"])) {
247
                 if (!empty($product["label"])) {
247
-                    if ($product["label"] == "add") {
248
-                        $purchase->purchaseDetail()->create($validated);
249
-                    }
250
-
251
-                    if ($product["label"] == "edit") {
252
-                        $purchase->purchaseDetail
248
+                    match ($product["label"]) {
249
+                        "add" => $purchase
250
+                            ->purchaseDetail()
251
+                            ->create($validated),
252
+                        "edit" => $purchase->purchaseDetail
253
                             ->find($product["id"])
253
                             ->find($product["id"])
254
-                            ->update($validated);
255
-                    }
256
-
257
-                    if ($product["label"] == "delete") {
258
-                        $purchase->purchaseDetail
254
+                            ->update($validated),
255
+                        "delete" => $purchase->purchaseDetail
259
                             ->find($product["id"])
256
                             ->find($product["id"])
260
-                            ->delete();
261
-                    }
257
+                            ->delete(),
258
+                    };
262
                 }
259
                 }
263
 
260
 
264
                 if ($request->status == "success") {
261
                 if ($request->status == "success") {

+ 4
- 0
resources/js/pages/Composables/useCart.js Parādīt failu

39
 
39
 
40
       if (itemExists) {
40
       if (itemExists) {
41
         itemExists.qty += Number(form.qty)
41
         itemExists.qty += Number(form.qty)
42
+
43
+        if (initialProducts.length && itemExists?.label === undefined) {
44
+          itemExists['label'] = 'edit'
45
+        }
42
       } else {
46
       } else {
43
         cart.push({
47
         cart.push({
44
           label: 'add',
48
           label: 'add',

+ 8
- 1
resources/js/pages/Purchases/Edit.vue Parādīt failu

14
 import AppAutoComplete from '@/components/AppAutoComplete.vue'
14
 import AppAutoComplete from '@/components/AppAutoComplete.vue'
15
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
15
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
16
 import { provide } from 'vue'
16
 import { provide } from 'vue'
17
+import { Inertia } from '@inertiajs/inertia'
17
 
18
 
18
 const props = defineProps({
19
 const props = defineProps({
19
   id: Number,
20
   id: Number,
48
       products: [...cart, ...cartDeleted],
49
       products: [...cart, ...cartDeleted],
49
     }))
50
     }))
50
     .put(route('purchases.update', props.id), {
51
     .put(route('purchases.update', props.id), {
51
-      onSuccess: () => onClearCartDelete(),
52
+      onSuccess: () => {
53
+        onClearCartDelete()
54
+
55
+        Inertia.visit(route('purchases.edit', props.id), {
56
+          only: ['purchaseDetail'],
57
+        })
58
+      },
52
     })
59
     })
53
 }
60
 }
54
 
61