Browse Source

feat: stock_product master

Muhammad Iqbal Afandi 3 years ago
parent
commit
9268bbf699

+ 20
- 1
app/Http/Controllers/StockProductController.php View File

3
 namespace App\Http\Controllers;
3
 namespace App\Http\Controllers;
4
 
4
 
5
 use App\Models\StockProduct;
5
 use App\Models\StockProduct;
6
+use App\Services\HelperService;
6
 use Illuminate\Http\Request;
7
 use Illuminate\Http\Request;
7
 
8
 
8
 class StockProductController extends Controller
9
 class StockProductController extends Controller
19
      */
20
      */
20
     public function index()
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 View File

4
 
4
 
5
 use App\Models\Ppn;
5
 use App\Models\Ppn;
6
 use App\Services\HelperService;
6
 use App\Services\HelperService;
7
+use Carbon\Carbon;
7
 use Illuminate\Database\Eloquent\Model;
8
 use Illuminate\Database\Eloquent\Model;
8
 use Illuminate\Database\Eloquent\Casts\Attribute;
9
 use Illuminate\Database\Eloquent\Casts\Attribute;
9
 use Illuminate\Database\Eloquent\Factories\HasFactory;
10
 use Illuminate\Database\Eloquent\Factories\HasFactory;
14
 
15
 
15
     protected $fillable = ["price", "qty", "ppn", "product_number"];
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
     protected function price(): Attribute
27
     protected function price(): Attribute
18
     {
28
     {
19
         return Attribute::make(
29
         return Attribute::make(
34
 
44
 
35
     public function scopeFilter($query, array $filters)
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
                     $query
50
                     $query
41
                         ->where("number", "like", "%" . $search . "%")
51
                         ->where("number", "like", "%" . $search . "%")
42
                         ->orWhere("name", "like", "%" . $search . "%");
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 View File

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

+ 35
- 1
resources/js/pages/StockProducts/Index.vue View File

1
 <script setup>
1
 <script setup>
2
+import { indexTable } from './config'
3
+import AppSearch from '@/components/AppSearch.vue'
4
+import AppPagination from '@/components/AppPagination.vue'
2
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
5
 import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
6
+
7
+defineProps({
8
+  stockProducts: Object,
9
+  initialSearch: String,
10
+})
3
 </script>
11
 </script>
4
 
12
 
5
 <template>
13
 <template>
6
   <DashboardLayout title="Daftar Stok Barang">
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
   </DashboardLayout>
42
   </DashboardLayout>
9
 </template>
43
 </template>

+ 7
- 0
resources/js/pages/StockProducts/config.js View File

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
+]