From 8bea9fd9ea8df3b7f609b5563802e25db80ab495 Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Tue, 6 Jun 2023 07:11:29 +0700 Subject: [PATCH] sale partial --- app/Http/Controllers/SaleController.php | 26 +++++ app/Models/Sale.php | 5 + database/seeders/PermissionSeeder.php | 6 +- resources/js/Layouts/Partials/routes.js | 8 +- resources/js/Pages/Customer/Index.jsx | 2 +- resources/js/Pages/Sale/Detail.jsx | 125 +++++++++++++++++++++++ resources/js/Pages/Sale/Index.jsx | 129 ++++++++++++++++++++++++ routes/admin.php | 5 + 8 files changed, 298 insertions(+), 8 deletions(-) create mode 100644 app/Http/Controllers/SaleController.php create mode 100644 resources/js/Pages/Sale/Detail.jsx create mode 100644 resources/js/Pages/Sale/Index.jsx diff --git a/app/Http/Controllers/SaleController.php b/app/Http/Controllers/SaleController.php new file mode 100644 index 0000000..4735389 --- /dev/null +++ b/app/Http/Controllers/SaleController.php @@ -0,0 +1,26 @@ +withCount(['items']); + + return inertia('Sale/Index', [ + 'query' => $query->paginate(), + ]); + } + + public function show(Sale $sale) + { + return inertia('Sale/Detail', [ + 'sale' => $sale->load(['items.voucher', 'customer.level']), + ]); + } +} diff --git a/app/Models/Sale.php b/app/Models/Sale.php index e4ef796..a6ffbb5 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -42,6 +42,11 @@ class Sale extends Model return $this->hasMany(SaleItem::class); } + public function customer() + { + return $this->belongsTo(Customer::class); + } + public function formatHumanCreatedAt(): Attribute { return Attribute::make(get: function () { diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index 8b0d2de..49c1080 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -64,10 +64,10 @@ class PermissionSeeder extends Seeder ['id' => Str::ulid(), 'label' => 'View Coin', 'name' => 'view-coin'], ['id' => Str::ulid(), 'label' => 'Update Coin', 'name' => 'update-coin'], - ['id' => Str::ulid(), 'label' => 'Create Sale', 'name' => 'create-sale'], - ['id' => Str::ulid(), 'label' => 'Update Sale', 'name' => 'update-sale'], + // ['id' => Str::ulid(), 'label' => 'Create Sale', 'name' => 'create-sale'], + // ['id' => Str::ulid(), 'label' => 'Update Sale', 'name' => 'update-sale'], ['id' => Str::ulid(), 'label' => 'View Sale', 'name' => 'view-sale'], - ['id' => Str::ulid(), 'label' => 'Delete Sale', 'name' => 'delete-sale'], + // ['id' => Str::ulid(), 'label' => 'Delete Sale', 'name' => 'delete-sale'], ['id' => Str::ulid(), 'label' => 'Create Coin Reward', 'name' => 'create-coin-reward'], ['id' => Str::ulid(), 'label' => 'Update Coin Reward', 'name' => 'update-coin-reward'], diff --git a/resources/js/Layouts/Partials/routes.js b/resources/js/Layouts/Partials/routes.js index 5f6792e..6561bd6 100644 --- a/resources/js/Layouts/Partials/routes.js +++ b/resources/js/Layouts/Partials/routes.js @@ -45,12 +45,12 @@ export default [ permission: 'view-voucher', }, { - name: 'Sale', //TODO + name: 'Sale', show: true, icon: HiCreditCard, - route: route('deposit.index'), - active: 'deposit.*', - permission: 'view-deposit', + route: route('sale.index'), + active: 'sale.*', + permission: 'view-sale', }, { name: 'Deposit', diff --git a/resources/js/Pages/Customer/Index.jsx b/resources/js/Pages/Customer/Index.jsx index 8348c15..180c621 100644 --- a/resources/js/Pages/Customer/Index.jsx +++ b/resources/js/Pages/Customer/Index.jsx @@ -111,7 +111,7 @@ export default function Customer(props) { scope="col" className="py-3 px-6" > - Referal Code + Referral Code import('@/Components/TinyMCE')) + +export default function Form(props) { + const { banner } = props + + const { data, setData, post, processing, errors } = useForm({ + title: '', + description: '', + image: '', + image_url: '', + }) + + const handleOnChange = (event) => { + setData( + event.target.name, + event.target.type === 'checkbox' + ? event.target.checked + ? 1 + : 0 + : event.target.value + ) + } + const handleSubmit = () => { + if (isEmpty(banner) === false) { + post(route('banner.update', banner)) + return + } + post(route('banner.store')) + } + + useEffect(() => { + if (isEmpty(banner) === false) { + setData({ + title: banner.title, + description: banner.description, + image_url: banner.image_url, + }) + } + }, [banner]) + + return ( + + + +
+
+
+
Banner
+ + + setData('image', e.target.files[0]) + } + error={errors.image} + preview={ + isEmpty(data.image_url) === false && ( + preview + ) + } + /> + +
+ Loading...
}> + { + setData( + 'description', + editor.getContent() + ) + }} + /> + +
+
+ +
+
+
+ +
+ ) +} diff --git a/resources/js/Pages/Sale/Index.jsx b/resources/js/Pages/Sale/Index.jsx new file mode 100644 index 0000000..abb9389 --- /dev/null +++ b/resources/js/Pages/Sale/Index.jsx @@ -0,0 +1,129 @@ +import React from 'react' +import { Head, router } from '@inertiajs/react' +import { HiEye } from 'react-icons/hi' + +import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' +import Pagination from '@/Components/Pagination' +import { formatIDR } from '@/utils' + +export default function Info(props) { + const { + query: { links, data }, + } = props + + return ( + + + +
+
+
+
+ {/* {canCreate && ( + + + + )} */} +
+
+
+ + + + + + + + + + + + {data.map((sale) => ( + + + + + + + + + ))} + +
+ # + + Customer + + Tanggal + + Voucher + + Total + +
+ {sale.code} + + {sale.customer.name} + + {sale.format_created_at} + + {formatIDR( + sale.items_count + )} + + {formatIDR(sale.amount)} + + router.get( + route( + 'sale.show', + sale + ) + ) + } + > + +
Lihat
+
+
+
+ +
+
+
+
+
+
+ ) +} diff --git a/routes/admin.php b/routes/admin.php index 63461e4..82f0da0 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -13,6 +13,7 @@ use App\Http\Controllers\InfoController; use App\Http\Controllers\LocationController; use App\Http\Controllers\ProfileController; use App\Http\Controllers\RoleController; +use App\Http\Controllers\SaleController; use App\Http\Controllers\SettingController; use App\Http\Controllers\UserController; use App\Http\Controllers\VoucherController; @@ -122,5 +123,9 @@ Route::middleware(['http_secure_aware', 'inertia.admin']) Route::post('/bonus-coin', [CoinRewardController::class, 'store'])->name('coin-reward.store'); Route::put('/bonus-coin/{reward}', [CoinRewardController::class, 'update'])->name('coin-reward.update'); Route::delete('/bonus-coin/{reward}', [CoinRewardController::class, 'destroy'])->name('coin-reward.destroy'); + + // sale + Route::get('/sales', [SaleController::class, 'index'])->name('sale.index'); + Route::get('/sales/{sale}', [SaleController::class, 'show'])->name('sale.show'); }); });