Subscription calculations

This commit is contained in:
David Bomba 2021-10-21 21:44:18 +11:00
parent e02dace9cc
commit 0444c96a47
4 changed files with 18 additions and 23 deletions

View File

@ -32,7 +32,7 @@ class ClientRegistrationFields
], ],
[ [
'key' => 'phone', 'key' => 'phone',
'required' => true 'required' => false
], ],
[ [
'key' => 'password', 'key' => 'password',

View File

@ -260,14 +260,14 @@ class LoginController extends BaseController
->increment() ->increment()
->batch(); ->batch();
SystemLogger::dispatch( // SystemLogger::dispatch(
json_encode(['ip' => request()->getClientIp()]), // json_encode(['ip' => request()->getClientIp()]),
SystemLog::CATEGORY_SECURITY, // SystemLog::CATEGORY_SECURITY,
SystemLog::EVENT_USER, // SystemLog::EVENT_USER,
SystemLog::TYPE_LOGIN_FAILURE, // SystemLog::TYPE_LOGIN_FAILURE,
null, // null,
Company::first(), // Company::first(),
); // );
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);

View File

@ -499,7 +499,7 @@ class CompanyController extends BaseController
$account->delete(); $account->delete();
if(Ninja::isHosted() && $request->has('cancellation_message') && strlen($request->input('cancellation_message')) > 1) if(Ninja::isHosted())
\Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key, $request->all()); \Modules\Admin\Jobs\Account\NinjaDeletedAccount::dispatch($account_key, $request->all());
LightLogs::create(new AccountDeleted()) LightLogs::create(new AccountDeleted())

View File

@ -6,8 +6,9 @@
* *
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://opensource.org/licenses/AAL * @license https://www.elastic.co/licensing/elastic-license
*/ */
namespace Tests\Unit; namespace Tests\Unit;
use App\Helpers\Invoice\ProRata; use App\Helpers\Invoice\ProRata;
@ -30,7 +31,7 @@ class SubscriptionsCalcTest extends TestCase
* *
* No method can guarantee against false positives. * No method can guarantee against false positives.
*/ */
public function setUp() :void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -39,7 +40,7 @@ class SubscriptionsCalcTest extends TestCase
public function testCalcUpgradePrice() public function testCalcUpgradePrice()
{ {
$subscription = Subscription::factory()->create([ $subscription = Subscription::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'user_id' => $this->user->id, 'user_id' => $this->user->id,
@ -67,7 +68,7 @@ class SubscriptionsCalcTest extends TestCase
'discount' => 0, 'discount' => 0,
'subscription_id' => $subscription->id, 'subscription_id' => $subscription->id,
'date' => '2021-01-01', 'date' => '2021-01-01',
]); ]);
$invoice = $invoice->calc()->getInvoice(); $invoice = $invoice->calc()->getInvoice();
@ -89,23 +90,17 @@ class SubscriptionsCalcTest extends TestCase
$this->assertEquals(10, $invoice->amount); $this->assertEquals(10, $invoice->amount);
$this->assertEquals(0, $invoice->balance); $this->assertEquals(0, $invoice->balance);
$pro_rata = new ProRata(); $pro_rata = new ProRata;
$refund = $pro_rata->refund($invoice->amount, Carbon::parse('2021-01-01'), Carbon::parse('2021-01-06'), $subscription->frequency_id); $refund = $pro_rata->refund($invoice->amount, Carbon::parse('2021-01-01'), Carbon::parse('2021-01-06'), $subscription->frequency_id);
$this->assertEquals(1.61, $refund); $this->assertEquals(1.61, $refund);
$pro_rata = new ProRata(); $pro_rata = new ProRata;
$upgrade = $pro_rata->charge($target->price, Carbon::parse('2021-01-01'), Carbon::parse('2021-01-06'), $subscription->frequency_id); $upgrade = $pro_rata->charge($target->price, Carbon::parse('2021-01-01'), Carbon::parse('2021-01-06'), $subscription->frequency_id);
$this->assertEquals(3.23, $upgrade); $this->assertEquals(3.23, $upgrade);
// $net_upgrade_price = $sub_calculator->calcUpgradePlan();
// $this->assertEquals(1.62, $net_upgrade_price);
} }
}
}