Explorar el Código

fix: purchase master

Muhammad Iqbal Afandi hace 3 años
padre
commit
b0760880c1

+ 6
- 0
app/Http/Controllers/PurchaseController.php Ver fichero

7
 use App\Models\Ppn;
7
 use App\Models\Ppn;
8
 use App\Models\Product;
8
 use App\Models\Product;
9
 use App\Models\Purchase;
9
 use App\Models\Purchase;
10
+use App\Models\PurchaseDetail;
10
 use App\Models\StockProduct;
11
 use App\Models\StockProduct;
11
 use App\Models\Supplier;
12
 use App\Models\Supplier;
12
 use App\Services\HelperService;
13
 use App\Services\HelperService;
70
             "products" => Inertia::lazy(
71
             "products" => Inertia::lazy(
71
                 fn() => Product::filter(["search" => request("product")])->get()
72
                 fn() => Product::filter(["search" => request("product")])->get()
72
             ),
73
             ),
74
+            "historyProductPurchase" => Inertia::lazy(
75
+                fn() => PurchaseDetail::historyProductPurchase(
76
+                    request()->only("productNumber", "supplierId")
77
+                )->first()
78
+            ),
73
         ]);
79
         ]);
74
     }
80
     }
75
 
81
 

+ 26
- 2
app/Models/PurchaseDetail.php Ver fichero

2
 
2
 
3
 namespace App\Models;
3
 namespace App\Models;
4
 
4
 
5
-use App\Services\HelperService;
6
-use Illuminate\Database\Eloquent\Casts\Attribute;
7
 use Illuminate\Database\Eloquent\Factories\HasFactory;
5
 use Illuminate\Database\Eloquent\Factories\HasFactory;
8
 use Illuminate\Database\Eloquent\Model;
6
 use Illuminate\Database\Eloquent\Model;
9
 
7
 
17
     {
15
     {
18
         return $this->belongsTo(Product::class, "product_number", "number");
16
         return $this->belongsTo(Product::class, "product_number", "number");
19
     }
17
     }
18
+
19
+    public function supplier()
20
+    {
21
+        return $this->hasOneThrough(
22
+            Supplier::class,
23
+            Purchase::class,
24
+            "number",
25
+            "id",
26
+            "purchase_number",
27
+            "supplier_id"
28
+        );
29
+    }
30
+
31
+    public function scopeHistoryProductPurchase($query, array $filters)
32
+    {
33
+        $query
34
+            ->when($filters["productNumber"] ?? null, function (
35
+                $query,
36
+                $search
37
+            ) {
38
+                $query->whereRelation("product", "number", $search);
39
+            })
40
+            ->when($filters["supplierId"] ?? null, function ($query, $search) {
41
+                $query->whereHas("supplier");
42
+            });
43
+    }
20
 }
44
 }

+ 33
- 1
resources/js/pages/Purchases/Create.vue Ver fichero

1
 <script setup>
1
 <script setup>
2
+import { watch, computed } from 'vue'
3
+import { Inertia } from '@inertiajs/inertia'
2
 import { optionStatus } from './config'
4
 import { optionStatus } from './config'
3
 import { cartTable } from './config'
5
 import { cartTable } from './config'
4
 import Details from './Components/Details.vue'
6
 import Details from './Components/Details.vue'
11
 import AppDropdown from '@/components/AppDropdown.vue'
13
 import AppDropdown from '@/components/AppDropdown.vue'
12
 import AppAutoComplete from '@/components/AppAutoComplete.vue'
14
 import AppAutoComplete from '@/components/AppAutoComplete.vue'
13
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
15
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
14
-import { computed } from '@vue/reactivity'
15
 
16
 
16
 const props = defineProps({
17
 const props = defineProps({
17
   number: String,
18
   number: String,
24
     type: Array,
25
     type: Array,
25
     default: [],
26
     default: [],
26
   },
27
   },
28
+  historyProductPurchase: Object,
27
 })
29
 })
28
 
30
 
29
 const form = useForm({
31
 const form = useForm({
58
   return optionStatus.filter((val) => val.value != 'success')
60
   return optionStatus.filter((val) => val.value != 'success')
59
 })
61
 })
60
 
62
 
63
+watch(
64
+  () => form.product,
65
+  () => {
66
+    if (form.product.id) {
67
+      Inertia.reload({
68
+        data: {
69
+          productNumber: form.product.number,
70
+          supplierId: form.supplier.id,
71
+        },
72
+        only: ['historyProductPurchase'],
73
+      })
74
+    }
75
+  }
76
+)
77
+
78
+const historyProductPrice = computed(() => {
79
+  return props.historyProductPurchase?.price
80
+})
81
+
61
 const {
82
 const {
62
   productCart,
83
   productCart,
63
   onClearProductCart,
84
   onClearProductCart,
175
                     />
196
                     />
176
                   </div>
197
                   </div>
177
 
198
 
199
+                  <div class="col-12 md:col-6">
200
+                    <AppInputNumber
201
+                      disabled
202
+                      label="Harga Sebelumya"
203
+                      placeholder="harga sebelumnya"
204
+                      v-model="historyProductPrice"
205
+                    />
206
+                  </div>
207
+
208
+                  <Divider type="dashed" />
209
+
178
                   <div class="col-12 md:col-6">
210
                   <div class="col-12 md:col-6">
179
                     <AppInputNumber
211
                     <AppInputNumber
180
                       :disabled="!form.supplier?.id"
212
                       :disabled="!form.supplier?.id"