2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2022-05-16 06:43:33 +02:00
|
|
|
use App\Models\Home;
|
2022-03-05 16:02:12 +01:00
|
|
|
use App\Models\Misc;
|
|
|
|
use App\Models\Pricing;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class MiscController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2022-07-20 06:35:12 +02:00
|
|
|
$misc = Misc::allMisc();
|
2022-03-05 16:02:12 +01:00
|
|
|
return view('misc.index', compact(['misc']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('misc.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Misc $misc)
|
|
|
|
{
|
2022-09-22 05:20:23 +02:00
|
|
|
$misc_data = Misc::misc($misc->id);
|
2022-07-20 06:35:12 +02:00
|
|
|
return view('misc.show', compact(['misc_data']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'name' => 'required|string|min:3',
|
2022-03-05 16:02:12 +01:00
|
|
|
'price' => 'required|numeric',
|
2022-10-20 02:06:44 +02:00
|
|
|
'payment_term' => 'required|integer',
|
|
|
|
'currency' => 'required|string|size:3',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
2022-03-05 16:02:12 +01:00
|
|
|
'next_due_date' => 'required|date'
|
|
|
|
]);
|
|
|
|
|
2022-07-20 06:35:12 +02:00
|
|
|
$misc_id = Str::random(8);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
$pricing = new Pricing();
|
2022-08-30 15:37:05 +02:00
|
|
|
$pricing->insertPricing(5, $misc_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Misc::create([
|
2022-07-20 06:35:12 +02:00
|
|
|
'id' => $misc_id,
|
2022-05-09 06:35:07 +02:00
|
|
|
'name' => $request->name,
|
|
|
|
'owned_since' => $request->owned_since
|
|
|
|
]);
|
|
|
|
|
2022-07-20 06:35:12 +02:00
|
|
|
Cache::forget("all_misc");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('misc.index')
|
|
|
|
->with('success', 'Misc service created Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Misc $misc)
|
|
|
|
{
|
2022-09-22 05:20:23 +02:00
|
|
|
$misc_data = Misc::misc($misc->id);
|
2022-07-20 06:35:12 +02:00
|
|
|
return view('misc.edit', compact('misc_data'));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, Misc $misc)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'name' => 'required|string|min:3',
|
|
|
|
'price' => 'required|numeric',
|
|
|
|
'payment_term' => 'required|integer',
|
|
|
|
'currency' => 'required|string|size:3',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
|
|
|
'next_due_date' => 'required|date'
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
2022-10-20 02:06:44 +02:00
|
|
|
$misc->update([
|
|
|
|
'name' => $request->name,
|
|
|
|
'owned_since' => $request->owned_since,
|
|
|
|
'active' => (isset($request->is_active)) ? 1 : 0
|
|
|
|
]);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
$pricing = new Pricing();
|
2022-10-20 02:17:34 +02:00
|
|
|
$pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-07-20 06:35:12 +02:00
|
|
|
Cache::forget("all_misc");
|
|
|
|
Cache::forget("misc.{$misc->id}");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('misc.index')
|
|
|
|
->with('success', 'Misc service updated Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Misc $misc)
|
|
|
|
{
|
|
|
|
$items = Misc::find($misc->id);
|
|
|
|
$items->delete();
|
|
|
|
|
|
|
|
$p = new Pricing();
|
|
|
|
$p->deletePricing($misc->id);
|
|
|
|
|
2022-07-20 06:35:12 +02:00
|
|
|
Cache::forget("all_misc");
|
|
|
|
Cache::forget("misc.{$misc->id}");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('misc.index')
|
|
|
|
->with('success', 'Misc service was deleted Successfully.');
|
|
|
|
}
|
|
|
|
}
|