Преглед изворни кода

feat: stock_product master

Muhammad Iqbal Afandi пре 3 година
родитељ
комит
9268bbf699

+ 20
- 1
app/Http/Controllers/StockProductController.php Прегледај датотеку

@@ -3,6 +3,7 @@
3 3
 namespace App\Http\Controllers;
4 4
 
5 5
 use App\Models\StockProduct;
6
+use App\Services\HelperService;
6 7
 use Illuminate\Http\Request;
7 8
 
8 9
 class StockProductController extends Controller
@@ -19,7 +20,25 @@ class StockProductController extends Controller
19 20
      */
20 21
     public function index()
21 22
     {
22
-        return inertia("StockProducts/Index");
23
+        return inertia("StockProducts/Index", [
24
+            "initialSearch" => request("search"),
25
+            "stockProducts" => StockProduct::filter(request()->only("search"))
26
+                ->latest()
27
+                ->paginate(10)
28
+                ->withQueryString()
29
+                ->through(
30
+                    fn($stockProduct) => [
31
+                        "id" => $stockProduct->id,
32
+                        "updatedAt" => $stockProduct->updated_at,
33
+                        "name" => $stockProduct->product->name,
34
+                        "price" => HelperService::setRupiahFormat(
35
+                            $stockProduct->price
36
+                        ),
37
+                        "qty" => $stockProduct->qty,
38
+                        "unit" => $stockProduct->product->unit,
39
+                    ]
40
+                ),
41
+        ]);
23 42
     }
24 43
 
25 44
     /**

+ 16
- 6
app/Models/StockProduct.php Прегледај датотеку

@@ -4,6 +4,7 @@ namespace App\Models;
4 4
 
5 5
 use App\Models\Ppn;
6 6
 use App\Services\HelperService;
7
+use Carbon\Carbon;
7 8
 use Illuminate\Database\Eloquent\Model;
8 9
 use Illuminate\Database\Eloquent\Casts\Attribute;
9 10
 use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -14,6 +15,15 @@ class StockProduct extends Model
14 15
 
15 16
     protected $fillable = ["price", "qty", "ppn", "product_number"];
16 17
 
18
+    protected function updatedAt(): Attribute
19
+    {
20
+        return Attribute::make(
21
+            get: fn($value) => Carbon::parse($value)->translatedFormat(
22
+                "l d/m/y"
23
+            )
24
+        );
25
+    }
26
+
17 27
     protected function price(): Attribute
18 28
     {
19 29
         return Attribute::make(
@@ -34,14 +44,14 @@ class StockProduct extends Model
34 44
 
35 45
     public function scopeFilter($query, array $filters)
36 46
     {
37
-        $query->when($filters["search"] ?? null, function ($query, $search) {
38
-            $query
39
-                ->whereHas("product", function ($query) use ($search) {
47
+        $query
48
+            ->when($filters["search"] ?? null, function ($query, $search) {
49
+                $query->whereHas("product", function ($query) use ($search) {
40 50
                     $query
41 51
                         ->where("number", "like", "%" . $search . "%")
42 52
                         ->orWhere("name", "like", "%" . $search . "%");
43
-                })
44
-                ->where("qty", ">", 0);
45
-        });
53
+                });
54
+            })
55
+            ->where("qty", ">", 0);
46 56
     }
47 57
 }

+ 2
- 2
resources/js/pages/Sales/Index.vue Прегледај датотеку

@@ -14,8 +14,8 @@ defineProps({
14 14
 <template>
15 15
   <DashboardLayout title="Daftar Penjualan">
16 16
     <DataTable
17
-      responsiveLayout="scroll"
18
-      columnResizeMode="expand"
17
+      responsive-layout="scroll"
18
+      column-resize-mode="expand"
19 19
       :value="sales.data"
20 20
       :rowHover="true"
21 21
       :stripedRows="true"

+ 35
- 1
resources/js/pages/StockProducts/Index.vue Прегледај датотеку

@@ -1,9 +1,43 @@
1 1
 <script setup>
2
+import { indexTable } from './config'
3
+import AppSearch from '@/components/AppSearch.vue'
4
+import AppPagination from '@/components/AppPagination.vue'
2 5
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
6
+
7
+defineProps({
8
+  stockProducts: Object,
9
+  initialSearch: String,
10
+})
3 11
 </script>
4 12
 
5 13
 <template>
6 14
   <DashboardLayout title="Daftar Stok Barang">
7
-    <h1>Soon</h1>
15
+    <DataTable
16
+      responsive-layout="scroll"
17
+      column-resize-mode="expand"
18
+      :value="stockProducts.data"
19
+      :rowHover="true"
20
+      :stripedRows="true"
21
+    >
22
+      <template #header>
23
+        <h1>Stok Produk</h1>
24
+
25
+        <AppSearch
26
+          class="w-full md:w-27rem"
27
+          placeholder="nama"
28
+          url="/stock-products"
29
+          :initial-search="initialSearch"
30
+        />
31
+      </template>
32
+
33
+      <Column
34
+        v-for="value in indexTable"
35
+        :field="value.field"
36
+        :header="value.header"
37
+        :key="value.field"
38
+      />
39
+    </DataTable>
40
+
41
+    <AppPagination :links="stockProducts.links" />
8 42
   </DashboardLayout>
9 43
 </template>

+ 7
- 0
resources/js/pages/StockProducts/config.js Прегледај датотеку

@@ -0,0 +1,7 @@
1
+export const indexTable = [
2
+  { field: 'updatedAt', header: 'Terakhir Diperbaharui' },
3
+  { field: 'name', header: 'Nama Produk' },
4
+  { field: 'price', header: 'Harga' },
5
+  { field: 'qty', header: 'Kuantitas' },
6
+  { field: 'unit', header: 'Satuan' },
7
+]