mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 15:34:30 -04:00
Working on new pricing
This commit is contained in:
parent
d2d70eb12a
commit
431f596d1d
@ -183,13 +183,6 @@ class AccountController extends BaseController
|
||||
$refund_deadline->modify('+30 days');
|
||||
|
||||
if ($plan == PLAN_FREE && $refund_deadline >= date_create()) {
|
||||
// Refund
|
||||
$company->plan = null;
|
||||
$company->plan_term = null;
|
||||
$company->plan_started = null;
|
||||
$company->plan_expires = null;
|
||||
$company->plan_paid = null;
|
||||
|
||||
if ($payment = $account->company->payment) {
|
||||
$ninjaAccount = $this->accountRepo->getNinjaAccount();
|
||||
$paymentDriver = $ninjaAccount->paymentDriver();
|
||||
@ -199,8 +192,6 @@ class AccountController extends BaseController
|
||||
} else {
|
||||
Session::flash('message', trans('texts.updated_plan'));
|
||||
}
|
||||
|
||||
$account->company->save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,16 +214,24 @@ class AccountController extends BaseController
|
||||
return Redirect::to('view/' . $invitation->invitation_key);
|
||||
} else {
|
||||
|
||||
$company->plan = $plan;
|
||||
$company->plan_term = $term;
|
||||
$company->plan_price = $newPlan['price'];
|
||||
$company->num_users = $numUsers;
|
||||
$company->plan_expires = DateTime::createFromFormat('Y-m-d', $company->plan_paid)->modify($term == PLAN_TERM_MONTHLY ? '+1 month' : '+1 year')->format('Y-m-d');
|
||||
// create a credit
|
||||
$credit = $credit - $newPlan['price'];
|
||||
if ($credit > 0) {
|
||||
$client = $this->accountRepo->getNinjaClient($account, $credit);
|
||||
$this->accountRepo->createNinjaCredit();
|
||||
}
|
||||
|
||||
// TODO change plan
|
||||
var_dump($newPlan);
|
||||
var_dump($credit);
|
||||
dd('0');
|
||||
if ($plan != PLAN_FREE) {
|
||||
$company->plan_term = $term;
|
||||
$company->plan_price = $newPlan['price'];
|
||||
$company->num_users = $numUsers;
|
||||
$company->plan_expires = date_create()->modify($term == PLAN_TERM_MONTHLY ? '+1 month' : '+1 year')->format('Y-m-d');
|
||||
}
|
||||
|
||||
$company->plan = $plan;
|
||||
$company->save();
|
||||
|
||||
return Redirect::to('settings/account_management');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ use App\Models\Invitation;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Language;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Account;
|
||||
@ -238,6 +239,24 @@ class AccountRepository
|
||||
return $invitation;
|
||||
}
|
||||
|
||||
public function createNinjaCredit($client, $amount)
|
||||
{
|
||||
$account = $this->getNinjaAccount();
|
||||
|
||||
$lastCredit = Credit::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first();
|
||||
$publicId = $lastCredit ? ($lastCredit->public_id + 1) : 1;
|
||||
|
||||
$credit = new Credit();
|
||||
$credit->public_id = $publicId;
|
||||
$credit->account_id = $account->id;
|
||||
$credit->user_id = $account->users()->first()->id;
|
||||
$credit->client_id = $client->id;
|
||||
$credit->amount = $amount;
|
||||
$credit->save();
|
||||
|
||||
return $credit;
|
||||
}
|
||||
|
||||
public function createNinjaInvoice($client, $clientAccount, $plan, $credit = 0)
|
||||
{
|
||||
$term = $plan['term'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user