Updated updatePricing() to not need as_usd parameter

Updated updatePricing() to not need as_usd parameter
This commit is contained in:
cp6 2022-10-20 11:17:34 +11:00
parent 736b6c9479
commit 2139629077
7 changed files with 10 additions and 18 deletions

View File

@ -100,8 +100,7 @@ class DomainsController extends Controller
]); ]);
$pricing = new Pricing(); $pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($domain->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
$pricing->updatePricing($domain->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
$domain->update([ $domain->update([
'domain' => $request->domain, 'domain' => $request->domain,

View File

@ -82,8 +82,7 @@ class MiscController extends Controller
]); ]);
$pricing = new Pricing(); $pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
$pricing->updatePricing($misc->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
Cache::forget("all_misc"); Cache::forget("all_misc");
Cache::forget("misc.{$misc->id}"); Cache::forget("misc.{$misc->id}");

View File

@ -150,8 +150,7 @@ class ResellerController extends Controller
]); ]);
$pricing = new Pricing(); $pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($request->id, $request->currency, $request->price, $request->payment_term, $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); Labels::deleteLabelsAssignedTo($request->id);
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id); Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id);

View File

@ -130,8 +130,7 @@ class SeedBoxesController extends Controller
]); ]);
$pricing = new Pricing(); $pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($seedbox->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
$pricing->updatePricing($seedbox->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
Labels::deleteLabelsAssignedTo($seedbox->id); Labels::deleteLabelsAssignedTo($seedbox->id);
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $seedbox->id); Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $seedbox->id);

View File

@ -179,10 +179,7 @@ class ServerController extends Controller
$server_id = $request->server_id; $server_id = $request->server_id;
$pricing = new Pricing(); $pricing = new Pricing();
$pricing->updatePricing($server_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
$pricing->updatePricing($server_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
Labels::deleteLabelsAssignedTo($server_id); Labels::deleteLabelsAssignedTo($server_id);

View File

@ -147,8 +147,7 @@ class SharedController extends Controller
]); ]);
$pricing = new Pricing(); $pricing = new Pricing();
$as_usd = $pricing->convertToUSD($request->price, $request->currency); $pricing->updatePricing($request->id, $request->currency, $request->price, $request->payment_term, $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); Labels::deleteLabelsAssignedTo($request->id);
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id); Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $request->id);

View File

@ -125,8 +125,9 @@ 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): int public function updatePricing(string $service_id, string $currency, float $price, int $term, string $next_due_date, int $is_active = 1): int
{ {
$as_usd = $this->convertToUSD($price, $currency);
return DB::table('pricings') return DB::table('pricings')
->where('service_id', $service_id) ->where('service_id', $service_id)
->update([ ->update([
@ -136,15 +137,14 @@ class Pricing extends Model
'as_usd' => $as_usd, 'as_usd' => $as_usd,
'usd_per_month' => $this->costAsPerMonth($as_usd, $term), 'usd_per_month' => $this->costAsPerMonth($as_usd, $term),
'next_due_date' => $next_due_date, 'next_due_date' => $next_due_date,
'active' => ($is_active) ? 1 : 0 'active' => $is_active
]); ]);
} }
public static function allPricing() public static function allPricing()
{ {
return Cache::remember('all_pricing', now()->addWeek(1), function () { return Cache::remember('all_pricing', now()->addWeek(1), function () {
return DB::table('pricings') return Pricing::get();
->get();
}); });
} }