From 18c73aca9556bd87353d5b6920ef92c317fbd6a2 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sun, 15 May 2022 00:43:36 +1000 Subject: [PATCH] Added and applied updatePricing function Added and applied updatePricing function --- app/Http/Controllers/DomainsController.php | 13 +----------- app/Http/Controllers/MiscController.php | 23 ++------------------- app/Http/Controllers/ResellerController.php | 11 +--------- app/Http/Controllers/ServerController.php | 13 +----------- app/Http/Controllers/SharedController.php | 11 +--------- app/Models/Pricing.php | 19 +++++++++++++++-- 6 files changed, 23 insertions(+), 67 deletions(-) diff --git a/app/Http/Controllers/DomainsController.php b/app/Http/Controllers/DomainsController.php index 3823f7e..976d54f 100644 --- a/app/Http/Controllers/DomainsController.php +++ b/app/Http/Controllers/DomainsController.php @@ -114,18 +114,7 @@ class DomainsController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - DB::table('pricings') - ->where('service_id', $domain->id) - ->update([ - 'service_type' => 4, - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - 'active' => (isset($request->is_active)) ? 1 : 0 - ]); + $pricing->updatePricing($domain->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); $domain->update([ 'domain' => $request->domain, diff --git a/app/Http/Controllers/MiscController.php b/app/Http/Controllers/MiscController.php index a57a4a6..f52f06c 100644 --- a/app/Http/Controllers/MiscController.php +++ b/app/Http/Controllers/MiscController.php @@ -50,16 +50,7 @@ class MiscController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - Pricing::create([ - 'service_id' => $ms_id, - 'service_type' => 5, - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - ]); + $pricing->insertPricing(5, $ms_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Misc::create([ 'id' => $ms_id, @@ -104,17 +95,7 @@ class MiscController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - DB::table('pricings') - ->where('service_id', $misc->id) - ->update([ - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - 'active' => (isset($request->is_active)) ? 1 : 0 - ]); + $pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache diff --git a/app/Http/Controllers/ResellerController.php b/app/Http/Controllers/ResellerController.php index 190cf08..1faea48 100644 --- a/app/Http/Controllers/ResellerController.php +++ b/app/Http/Controllers/ResellerController.php @@ -194,16 +194,7 @@ class ResellerController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - DB::table('pricings') - ->where('service_id', $request->id) - ->update([ - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - ]); + $pricing->updatePricing($request->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Labels::deleteLabelsAssignedTo($request->id); diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 20deb31..9bfa2cc 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -244,18 +244,7 @@ class ServerController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - DB::table('pricings') - ->where('service_id', $server_id) - ->update([ - 'service_type' => 1, - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - 'active' => (isset($request->is_active)) ? 1 : 0 - ]); + $pricing->updatePricing($server_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Labels::deleteLabelsAssignedTo($server_id); diff --git a/app/Http/Controllers/SharedController.php b/app/Http/Controllers/SharedController.php index 92c82e2..2f9dd78 100644 --- a/app/Http/Controllers/SharedController.php +++ b/app/Http/Controllers/SharedController.php @@ -193,16 +193,7 @@ class SharedController extends Controller $as_usd = $pricing->convertToUSD($request->price, $request->currency); - DB::table('pricings') - ->where('service_id', $request->id) - ->update([ - 'currency' => $request->currency, - 'price' => $request->price, - 'term' => $request->payment_term, - 'as_usd' => $as_usd, - 'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term), - 'next_due_date' => $request->next_due_date, - ]); + $pricing->updatePricing($request->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); Labels::deleteLabelsAssignedTo($request->id); diff --git a/app/Models/Pricing.php b/app/Models/Pricing.php index d089654..3f56ed9 100644 --- a/app/Models/Pricing.php +++ b/app/Models/Pricing.php @@ -78,11 +78,11 @@ class Pricing extends Model DB::table('pricings')->where('service_id', '=', $id)->delete(); } - public function insertPricing(int $type, string $server_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1) + public function insertPricing(int $type, string $service_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1) { return self::create([ 'service_type' => $type, - 'service_id' => $server_id, + 'service_id' => $service_id, 'currency' => $currency, 'price' => $price, 'term' => $term, @@ -93,6 +93,21 @@ class Pricing extends Model ]); } + public function updatePricing(string $service_id, string $currency, float $price, int $term, float $as_usd, string $next_due_date, int $is_active = 1) + { + return DB::table('pricings') + ->where('service_id', $service_id) + ->update([ + 'currency' => $currency, + 'price' => $price, + 'term' => $term, + 'as_usd' => $as_usd, + 'usd_per_month' => $this->costAsPerMonth($as_usd, $term), + 'next_due_date' => $next_due_date, + 'active' => ($is_active) ? 1 : 0 + ]); + } + public static function allPricing() { return Cache::remember('all_pricing', now()->addWeek(1), function () {