feat : setelah create data bisa langsung print
This commit is contained in:
parent
65a02c7c6c
commit
41f3d0d642
@ -44,14 +44,18 @@ public function create(): View
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(TransactionRequest $request): RedirectResponse
|
||||
public function store(TransactionRequest $request): View
|
||||
{
|
||||
$validatedData = $request->validated();
|
||||
$findCustomer = Customer::find($validatedData['customer']);
|
||||
DB::transaction(function () use ($validatedData, $findCustomer) {
|
||||
|
||||
$newTransaction = null;
|
||||
|
||||
DB::transaction(function () use ($validatedData, $findCustomer, &$newTransaction) {
|
||||
$customer = null;
|
||||
$userId = Auth::id();
|
||||
$barbershopId = Auth::user()->barbershop_id;
|
||||
|
||||
if (! $findCustomer) {
|
||||
$customer = Customer::create([
|
||||
'user_id' => $userId,
|
||||
@ -59,20 +63,33 @@ public function store(TransactionRequest $request): RedirectResponse
|
||||
'name' => $validatedData['customer'],
|
||||
]);
|
||||
}
|
||||
|
||||
$newTransaction = Transaction::create(array_merge($validatedData, [
|
||||
'user_id' => $validatedData['barber'],
|
||||
'barbershop_id' => $barbershopId,
|
||||
'service_id' => $validatedData['service'],
|
||||
'customer_id' => $customer ? $customer->id : $validatedData['customer'],
|
||||
]));
|
||||
|
||||
if (isset($validatedData['image'])) {
|
||||
$this->uploadAttachment($validatedData['image'], 'transactions', Transaction::class, $newTransaction->id, 'transaction');
|
||||
}
|
||||
});
|
||||
|
||||
if (! $newTransaction) {
|
||||
notify()->error('Transaction could not be created', 'Error');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
$transactionData = $newTransaction->load(['user', 'user.biography', 'customer', 'service', 'barbershop']);
|
||||
|
||||
notify()->success('Data berhasil ditambahkan', 'Berhasil');
|
||||
|
||||
return redirect('dashboard/manage/transactions');
|
||||
return view('pages.admin.manage.transaction.print', [
|
||||
'transaction' => $transactionData,
|
||||
'url' => route('manage.transactions'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Transaction $transaction): View
|
||||
@ -140,6 +157,7 @@ public function print(Transaction $transaction): View
|
||||
{
|
||||
return view('pages.admin.manage.transaction.print', [
|
||||
'transaction' => $transaction->load(['user', 'user.biography', 'customer', 'service', 'barbershop']),
|
||||
'url' => route('manage.transactions'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,12 @@
|
||||
<p class="thank-you">Terima kasih atas kunjungan Anda!</p>
|
||||
</div>
|
||||
<script>
|
||||
window.print();
|
||||
window.onload = function() {
|
||||
window.print();
|
||||
window.onafterprint = function() {
|
||||
window.location.href = "{{ $url }}";
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
use App\Http\Controllers\Admin\Setting\AccountController;
|
||||
use App\Http\Controllers\Admin\Setting\ApplicationController;
|
||||
use App\Http\Controllers\Client\HomepageController;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('auth')->group(function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user