Added and applied updatePricing function

Added and applied updatePricing function
This commit is contained in:
cp6 2022-05-15 00:43:36 +10:00
parent 9204a05654
commit 18c73aca95
6 changed files with 23 additions and 67 deletions

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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 () {