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-07-20 06:35:12 +02:00
|
|
|
$misc_data = Misc::misc($misc->id)[0];
|
|
|
|
return view('misc.show', compact(['misc_data']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'name' => 'required|min:3',
|
|
|
|
'price' => 'required|numeric',
|
|
|
|
'owned_since' => 'date',
|
|
|
|
'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();
|
|
|
|
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
2022-07-20 06:35:12 +02:00
|
|
|
$pricing->insertPricing(5, $misc_id, $request->currency, $request->price, $request->payment_term, $as_usd, $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-07-20 06:35:12 +02:00
|
|
|
$misc_data = Misc::misc($misc->id)[0];
|
|
|
|
return view('misc.edit', compact('misc_data'));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, Misc $misc)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'name' => 'required',
|
|
|
|
'owned_since' => 'date',
|
|
|
|
]);
|
|
|
|
|
|
|
|
DB::table('misc_services')
|
|
|
|
->where('id', $misc->id)
|
|
|
|
->update([
|
|
|
|
'name' => $request->name,
|
|
|
|
'owned_since' => $request->owned_since,
|
|
|
|
'active' => (isset($request->is_active)) ? 1 : 0
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pricing = new Pricing();
|
|
|
|
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
2022-05-14 16:43:36 +02:00
|
|
|
$pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $as_usd, $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.');
|
|
|
|
}
|
|
|
|
}
|