mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Working on pro plan
This commit is contained in:
parent
1f64a81300
commit
c557276a6e
@ -71,4 +71,5 @@ Configure config/database.php and then initialize the database
|
|||||||
* [nnnick/Chart.js](https://github.com/nnnick/Chart.js) - Simple HTML5 Charts using the <canvas> tag
|
* [nnnick/Chart.js](https://github.com/nnnick/Chart.js) - Simple HTML5 Charts using the <canvas> tag
|
||||||
* [josscrowcroft/accounting.js](https://github.com/josscrowcroft/accounting.js) - A lightweight JavaScript library for number, money and currency formatting
|
* [josscrowcroft/accounting.js](https://github.com/josscrowcroft/accounting.js) - A lightweight JavaScript library for number, money and currency formatting
|
||||||
* [jashkenas/underscore](https://github.com/jashkenas/underscore) - JavaScript's utility _ belt
|
* [jashkenas/underscore](https://github.com/jashkenas/underscore) - JavaScript's utility _ belt
|
||||||
* [caouecs/Laravel4-long](https://github.com/caouecs/Laravel4-lang) - List of languages for Laravel4
|
* [caouecs/Laravel4-long](https://github.com/caouecs/Laravel4-lang) - List of languages for Laravel4
|
||||||
|
* [calvinfroedge/PHP-Payments](https://github.com/calvinfroedge/PHP-Payments) - A uniform payments interface for PHP
|
@ -55,124 +55,16 @@ class AccountController extends \BaseController {
|
|||||||
|
|
||||||
public function enableProPlan()
|
public function enableProPlan()
|
||||||
{
|
{
|
||||||
if (Auth::user()->isPro())
|
$invoice = $this->accountRepo->enableProPlan();
|
||||||
|
|
||||||
|
if ($invoice)
|
||||||
{
|
{
|
||||||
return Redirect::to('/dashboard');
|
$this->contactMailer->sendInvoice($invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = Auth::user()->account;
|
|
||||||
|
|
||||||
$ninjaAccount = $this->getNinjaAccount();
|
|
||||||
$ninjaClient = $this->getNinjaClient($ninjaAccount);
|
|
||||||
$invoice = $this->createNinjaInvoice($ninjaAccount, $ninjaClient);
|
|
||||||
|
|
||||||
$this->contactMailer->sendInvoice($invoice);
|
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createNinjaInvoice($account, $client)
|
|
||||||
{
|
|
||||||
$lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first();
|
|
||||||
$publicId = $lastInvoice ? ($lastInvoice->public_id + 1) : 1;
|
|
||||||
|
|
||||||
$invoice = new Invoice();
|
|
||||||
$invoice->account_id = $account->id;
|
|
||||||
$invoice->user_id = $account->users()->first()->id;
|
|
||||||
$invoice->public_id = $publicId;
|
|
||||||
$invoice->client_id = $client->id;
|
|
||||||
$invoice->invoice_number = $account->getNextInvoiceNumber();
|
|
||||||
$invoice->invoice_date = date_create()->format('Y-m-d');
|
|
||||||
$invoice->amount = PRO_PLAN_PRICE;
|
|
||||||
$invoice->balance = PRO_PLAN_PRICE;
|
|
||||||
$invoice->save();
|
|
||||||
|
|
||||||
$item = new InvoiceItem();
|
|
||||||
$item->account_id = $account->id;
|
|
||||||
$item->user_id = $account->users()->first()->id;
|
|
||||||
$item->public_id = $publicId;
|
|
||||||
$item->qty = 1;
|
|
||||||
$item->cost = PRO_PLAN_PRICE;
|
|
||||||
$item->notes = trans('texts.pro_plan_description');
|
|
||||||
$item->product_key = trans('texts.pro_plan_product');
|
|
||||||
$invoice->invoice_items()->save($item);
|
|
||||||
|
|
||||||
$invitation = new Invitation();
|
|
||||||
$invitation->account_id = $account->id;
|
|
||||||
$invitation->user_id = $account->users()->first()->id;
|
|
||||||
$invitation->public_id = $publicId;
|
|
||||||
$invitation->invoice_id = $invoice->id;
|
|
||||||
$invitation->contact_id = $client->contacts()->first()->id;
|
|
||||||
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
|
|
||||||
$invitation->save();
|
|
||||||
|
|
||||||
return $invoice;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getNinjaAccount()
|
|
||||||
{
|
|
||||||
$account = Account::whereAccountKey(NINJA_ACCOUNT_KEY)->first();
|
|
||||||
|
|
||||||
if ($account)
|
|
||||||
{
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$account = new Account();
|
|
||||||
$account->name = 'Invoice Ninja';
|
|
||||||
$account->work_email = 'contact@invoiceninja.com';
|
|
||||||
$account->work_phone = '(800) 763-1948';
|
|
||||||
$account->account_key = NINJA_ACCOUNT_KEY;
|
|
||||||
$account->save();
|
|
||||||
|
|
||||||
$random = str_random(RANDOM_KEY_LENGTH);
|
|
||||||
|
|
||||||
$user = new User();
|
|
||||||
$user->registered = true;
|
|
||||||
$user->confirmed = true;
|
|
||||||
$user->email = 'contact@invoiceninja.com';
|
|
||||||
$user->password = $random;
|
|
||||||
$user->password_confirmation = $random;
|
|
||||||
$user->username = $random;
|
|
||||||
$user->first_name = 'Invoice';
|
|
||||||
$user->last_name = 'Ninja';
|
|
||||||
$user->notify_sent = false;
|
|
||||||
$user->notify_paid = false;
|
|
||||||
$account->users()->save($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getNinjaClient($ninjaAccount)
|
|
||||||
{
|
|
||||||
$client = Client::whereAccountId($ninjaAccount->id)->wherePublicId(Auth::user()->account_id)->first();
|
|
||||||
|
|
||||||
if (!$client)
|
|
||||||
{
|
|
||||||
$client = new Client;
|
|
||||||
$client->public_id = Auth::user()->account_id;
|
|
||||||
$client->user_id = $ninjaAccount->users()->first()->id;
|
|
||||||
foreach (['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'country_id', 'work_phone'] as $field)
|
|
||||||
{
|
|
||||||
$client->$field = Auth::user()->account->$field;
|
|
||||||
}
|
|
||||||
$ninjaAccount->clients()->save($client);
|
|
||||||
|
|
||||||
$contact = new Contact;
|
|
||||||
$contact->user_id = $ninjaAccount->users()->first()->id;
|
|
||||||
$contact->is_primary = true;
|
|
||||||
foreach (['first_name', 'last_name', 'email', 'phone'] as $field)
|
|
||||||
{
|
|
||||||
$contact->$field = Auth::user()->$field;
|
|
||||||
}
|
|
||||||
$client->contacts()->save($contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTrashVisible($entityType, $visible)
|
public function setTrashVisible($entityType, $visible)
|
||||||
{
|
{
|
||||||
Session::put('show_trash', $visible == 'true');
|
Session::put('show_trash', $visible == 'true');
|
||||||
@ -770,6 +662,11 @@ class AccountController extends \BaseController {
|
|||||||
$activity->save();
|
$activity->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input::get('go_pro') == 'true')
|
||||||
|
{
|
||||||
|
Session::set(REQUESTED_PRO_PLAN, true);
|
||||||
|
}
|
||||||
|
|
||||||
return "{$user->first_name} {$user->last_name}";
|
return "{$user->first_name} {$user->last_name}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,8 +9,22 @@
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use ninja\repositories\AccountRepository;
|
||||||
|
use ninja\mailers\ContactMailer;
|
||||||
|
|
||||||
class UserController extends BaseController {
|
class UserController extends BaseController {
|
||||||
|
|
||||||
|
protected $accountRepo;
|
||||||
|
protected $contactMailer;
|
||||||
|
|
||||||
|
public function __construct(AccountRepository $accountRepo, ContactMailer $contactMailer)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->accountRepo = $accountRepo;
|
||||||
|
$this->contactMailer = $contactMailer;
|
||||||
|
}
|
||||||
|
|
||||||
public function setTheme()
|
public function setTheme()
|
||||||
{
|
{
|
||||||
$user = User::find(Auth::user()->id);
|
$user = User::find(Auth::user()->id);
|
||||||
@ -171,6 +185,18 @@ class UserController extends BaseController {
|
|||||||
if ( Confide::confirm( $code ) )
|
if ( Confide::confirm( $code ) )
|
||||||
{
|
{
|
||||||
$notice_msg = trans('texts.confide.confirmation');
|
$notice_msg = trans('texts.confide.confirmation');
|
||||||
|
|
||||||
|
if (Session::has(REQUESTED_PRO_PLAN))
|
||||||
|
{
|
||||||
|
Session::forget(REQUESTED_PRO_PLAN);
|
||||||
|
|
||||||
|
if ($invoice = $this->accountRepo->enableProPlan())
|
||||||
|
{
|
||||||
|
$this->contactMailer->sendInvoice($invoice);
|
||||||
|
$notice_msg = trans('texts.pro_plan_succes');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Redirect::action('UserController@login')->with( 'message', $notice_msg );
|
return Redirect::action('UserController@login')->with( 'message', $notice_msg );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
public static function isRegistered()
|
||||||
|
{
|
||||||
|
return Auth::check() && Auth::user()->registered;
|
||||||
|
}
|
||||||
|
|
||||||
public static function isProd()
|
public static function isProd()
|
||||||
{
|
{
|
||||||
return App::environment() == ENV_PRODUCTION;
|
return App::environment() == ENV_PRODUCTION;
|
||||||
|
@ -7,6 +7,10 @@ use Request;
|
|||||||
use Session;
|
use Session;
|
||||||
use Language;
|
use Language;
|
||||||
use User;
|
use User;
|
||||||
|
use Auth;
|
||||||
|
use Invitation;
|
||||||
|
use Invoice;
|
||||||
|
use InvoiceItem;
|
||||||
|
|
||||||
class AccountRepository
|
class AccountRepository
|
||||||
{
|
{
|
||||||
@ -90,4 +94,124 @@ class AccountRepository
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function enableProPlan()
|
||||||
|
{
|
||||||
|
if (Auth::user()->isPro())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$account = Auth::user()->account;
|
||||||
|
|
||||||
|
$ninjaAccount = $this->getNinjaAccount();
|
||||||
|
$ninjaClient = $this->getNinjaClient($ninjaAccount);
|
||||||
|
$invoice = $this->createNinjaInvoice($ninjaAccount, $ninjaClient);
|
||||||
|
|
||||||
|
return $invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createNinjaInvoice($account, $client)
|
||||||
|
{
|
||||||
|
$lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first();
|
||||||
|
$publicId = $lastInvoice ? ($lastInvoice->public_id + 1) : 1;
|
||||||
|
|
||||||
|
$invoice = new Invoice();
|
||||||
|
$invoice->account_id = $account->id;
|
||||||
|
$invoice->user_id = $account->users()->first()->id;
|
||||||
|
$invoice->public_id = $publicId;
|
||||||
|
$invoice->client_id = $client->id;
|
||||||
|
$invoice->invoice_number = $account->getNextInvoiceNumber();
|
||||||
|
$invoice->invoice_date = date_create()->format('Y-m-d');
|
||||||
|
$invoice->amount = PRO_PLAN_PRICE;
|
||||||
|
$invoice->balance = PRO_PLAN_PRICE;
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
$item = new InvoiceItem();
|
||||||
|
$item->account_id = $account->id;
|
||||||
|
$item->user_id = $account->users()->first()->id;
|
||||||
|
$item->public_id = $publicId;
|
||||||
|
$item->qty = 1;
|
||||||
|
$item->cost = PRO_PLAN_PRICE;
|
||||||
|
$item->notes = trans('texts.pro_plan_description');
|
||||||
|
$item->product_key = trans('texts.pro_plan_product');
|
||||||
|
$invoice->invoice_items()->save($item);
|
||||||
|
|
||||||
|
$invitation = new Invitation();
|
||||||
|
$invitation->account_id = $account->id;
|
||||||
|
$invitation->user_id = $account->users()->first()->id;
|
||||||
|
$invitation->public_id = $publicId;
|
||||||
|
$invitation->invoice_id = $invoice->id;
|
||||||
|
$invitation->contact_id = $client->contacts()->first()->id;
|
||||||
|
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
|
||||||
|
$invitation->save();
|
||||||
|
|
||||||
|
return $invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getNinjaAccount()
|
||||||
|
{
|
||||||
|
$account = Account::whereAccountKey(NINJA_ACCOUNT_KEY)->first();
|
||||||
|
|
||||||
|
if ($account)
|
||||||
|
{
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$account = new Account();
|
||||||
|
$account->name = 'Invoice Ninja';
|
||||||
|
$account->work_email = 'contact@invoiceninja.com';
|
||||||
|
$account->work_phone = '(800) 763-1948';
|
||||||
|
$account->account_key = NINJA_ACCOUNT_KEY;
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
$random = str_random(RANDOM_KEY_LENGTH);
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->registered = true;
|
||||||
|
$user->confirmed = true;
|
||||||
|
$user->email = 'contact@invoiceninja.com';
|
||||||
|
$user->password = $random;
|
||||||
|
$user->password_confirmation = $random;
|
||||||
|
$user->username = $random;
|
||||||
|
$user->first_name = 'Invoice';
|
||||||
|
$user->last_name = 'Ninja';
|
||||||
|
$user->notify_sent = false;
|
||||||
|
$user->notify_paid = false;
|
||||||
|
$account->users()->save($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getNinjaClient($ninjaAccount)
|
||||||
|
{
|
||||||
|
$client = Client::whereAccountId($ninjaAccount->id)->wherePublicId(Auth::user()->account_id)->first();
|
||||||
|
|
||||||
|
if (!$client)
|
||||||
|
{
|
||||||
|
$client = new Client;
|
||||||
|
$client->public_id = Auth::user()->account_id;
|
||||||
|
$client->user_id = $ninjaAccount->users()->first()->id;
|
||||||
|
foreach (['name', 'address1', 'address2', 'city', 'state', 'postal_code', 'country_id', 'work_phone'] as $field)
|
||||||
|
{
|
||||||
|
$client->$field = Auth::user()->account->$field;
|
||||||
|
}
|
||||||
|
$ninjaAccount->clients()->save($client);
|
||||||
|
|
||||||
|
$contact = new Contact;
|
||||||
|
$contact->user_id = $ninjaAccount->users()->first()->id;
|
||||||
|
$contact->is_primary = true;
|
||||||
|
foreach (['first_name', 'last_name', 'email', 'phone'] as $field)
|
||||||
|
{
|
||||||
|
$contact->$field = Auth::user()->$field;
|
||||||
|
}
|
||||||
|
$client->contacts()->save($contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,6 +11,8 @@
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//apc_clear_cache();
|
//apc_clear_cache();
|
||||||
//Cache::flush();
|
//Cache::flush();
|
||||||
|
|
||||||
@ -237,7 +239,7 @@ define('RESULT_FAILURE', 'failure');
|
|||||||
define('GATEWAY_PAYPAL_EXPRESS', 17);
|
define('GATEWAY_PAYPAL_EXPRESS', 17);
|
||||||
define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h');
|
define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h');
|
||||||
define('PRO_PLAN_PRICE', 40);
|
define('PRO_PLAN_PRICE', 40);
|
||||||
|
define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN');
|
||||||
|
|
||||||
define('PAYMENT_LIBRARY_OMNIPAY', 1);
|
define('PAYMENT_LIBRARY_OMNIPAY', 1);
|
||||||
define('PAYMENT_LIBRARY_PHP_PAYMENTS', 2);
|
define('PAYMENT_LIBRARY_PHP_PAYMENTS', 2);
|
||||||
@ -304,3 +306,5 @@ if (Auth::check() && Auth::user()->id === 1)
|
|||||||
Auth::loginUsingId(1);
|
Auth::loginUsingId(1);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//dd(Session::has(REQUESTED_PRO_PLAN));
|
@ -256,7 +256,11 @@ Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice
|
|||||||
{{ Former::populateField('new_email', Auth::user()->email); }}
|
{{ Former::populateField('new_email', Auth::user()->email); }}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
{{ Former::hidden('path')->value(Request::path()) }}
|
<div style="display:none">
|
||||||
|
{{ Former::text('path')->value(Request::path()) }}
|
||||||
|
{{ Former::text('go_pro') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
{{ Former::text('new_first_name')->label(trans('texts.first_name')) }}
|
{{ Former::text('new_first_name')->label(trans('texts.first_name')) }}
|
||||||
{{ Former::text('new_last_name')->label(trans('texts.last_name')) }}
|
{{ Former::text('new_last_name')->label(trans('texts.last_name')) }}
|
||||||
{{ Former::text('new_email')->label(trans('texts.email')) }}
|
{{ Former::text('new_email')->label(trans('texts.email')) }}
|
||||||
@ -396,7 +400,8 @@ Want something changed? We're {{ link_to('https://github.com/hillelcoren/invoice
|
|||||||
data: 'new_email=' + encodeURIComponent($('form.signUpForm #new_email').val()) +
|
data: 'new_email=' + encodeURIComponent($('form.signUpForm #new_email').val()) +
|
||||||
'&new_password=' + encodeURIComponent($('form.signUpForm #new_password').val()) +
|
'&new_password=' + encodeURIComponent($('form.signUpForm #new_password').val()) +
|
||||||
'&new_first_name=' + encodeURIComponent($('form.signUpForm #new_first_name').val()) +
|
'&new_first_name=' + encodeURIComponent($('form.signUpForm #new_first_name').val()) +
|
||||||
'&new_last_name=' + encodeURIComponent($('form.signUpForm #new_last_name').val()),
|
'&new_last_name=' + encodeURIComponent($('form.signUpForm #new_last_name').val()) +
|
||||||
|
'&go_pro=' + $('#go_pro').val(),
|
||||||
success: function(result) {
|
success: function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
localStorage.setItem('guest_key', '');
|
localStorage.setItem('guest_key', '');
|
||||||
|
@ -438,7 +438,7 @@
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
<h4 class="modal-title" id="proPlanModalLabel">{{ trans('texts.sign_up') }}</h4>
|
<h4 class="modal-title" id="proPlanModalLabel">{{ trans('texts.pro_plan_product') }}</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="background-color: #fff; padding-left: 16px; padding-right: 16px" id="proPlanDiv">
|
<div style="background-color: #fff; padding-left: 16px; padding-right: 16px" id="proPlanDiv">
|
||||||
@ -487,18 +487,23 @@
|
|||||||
|
|
||||||
function submitProPlan() {
|
function submitProPlan() {
|
||||||
|
|
||||||
$('#proPlanDiv, #proPlanFooter').hide();
|
if ({{ Utils::isRegistered() ? 'true' : 'false' }}) {
|
||||||
$('#proPlanWorking').show();
|
$('#proPlanDiv, #proPlanFooter').hide();
|
||||||
|
$('#proPlanWorking').show();
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: '{{ URL::to('account/go_pro') }}',
|
|
||||||
success: function(result) {
|
|
||||||
$('#proPlanSuccess, #proPlanFooter').show();
|
|
||||||
$('#proPlanWorking, #proPlanButton').hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '{{ URL::to('account/go_pro') }}',
|
||||||
|
success: function(result) {
|
||||||
|
$('#proPlanSuccess, #proPlanFooter').show();
|
||||||
|
$('#proPlanWorking, #proPlanButton').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$('#proPlanModal').modal('hide');
|
||||||
|
$('#go_pro').val('true');
|
||||||
|
showSignUp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user