1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Working on pro plan

This commit is contained in:
Hillel Coren 2014-04-12 21:55:40 +03:00
parent 3cfa9a5ce5
commit 944ef2ccd3
13 changed files with 147 additions and 59 deletions

View File

@ -6,10 +6,12 @@
Most online invoicing sites are expensive. They shouldn't be. The aim of this project is to provide a free, open-source alternative. Additionally, the hope is the codebase will serve as a sample site for Laravel as well as other JavaScript technologies.
The high level instructions for setting up the site are below but there's also a [setup guide](http://hillelcoren.com/invoice-ninja/laravel-ubuntu-virtualbox/). If you'd like to translate the site please use [caouecs/Laravel4-long](https://github.com/caouecs/Laravel4-lang) for the starter files.
The high level instructions for setting up the site are below but there's also a [setup guide](http://hillelcoren.com/invoice-ninja/laravel-ubuntu-virtualbox/).
For updates follow [@invoiceninja](https://twitter.com/invoiceninja) or join the [Facebook Group](https://www.facebook.com/invoiceninja). For discussion of the code please use the [Google Group](https://groups.google.com/d/forum/invoiceninja).
If you'd like to translate the site please use [caouecs/Laravel4-long](https://github.com/caouecs/Laravel4-lang) for the starter files.
Site design by [kantorp-wegl.in](http://kantorp-wegl.in/)

View File

@ -114,7 +114,6 @@ return array(
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
'Illuminate\Remote\RemoteServiceProvider',
'Basset\BassetServiceProvider',
'Bootstrapper\BootstrapperServiceProvider',
'Zizaco\Confide\ConfideServiceProvider',
'Former\FormerServiceProvider',
@ -187,7 +186,6 @@ return array(
'Validator' => 'Illuminate\Support\Facades\Validator',
'View' => 'Illuminate\Support\Facades\View',
'SSH' => 'Illuminate\Support\Facades\SSH',
'Basset' => 'Basset\Facade',
'Alert' => 'Bootstrapper\Alert',
'Badge' => 'Bootstrapper\Badge',
'Breadcrumb' => 'Bootstrapper\Breadcrumb',

View File

@ -1,19 +1,22 @@
<?php
use ninja\repositories\AccountRepository;
use ninja\mailers\UserMailer as Mailer;
use ninja\mailers\UserMailer;
use ninja\mailers\ContactMailer;
class AccountController extends \BaseController {
protected $accountRepo;
protected $mailer;
protected $userMailer;
protected $contactMailer;
public function __construct(AccountRepository $accountRepo, Mailer $mailer)
public function __construct(AccountRepository $accountRepo, UserMailer $userMailer, ContactMailer $contactMailer)
{
parent::__construct();
$this->accountRepo = $accountRepo;
$this->mailer = $mailer;
$this->userMailer = $userMailer;
$this->contactMailer = $contactMailer;
}
public function getStarted()
@ -28,7 +31,6 @@ class AccountController extends \BaseController {
if ($guestKey)
{
//$user = User::where('password', '=', $guestKey)->firstOrFail();
$user = User::where('password', '=', $guestKey)->first();
if ($user && $user->registered)
@ -62,9 +64,48 @@ class AccountController extends \BaseController {
$ninjaAccount = $this->getNinjaAccount();
$ninjaClient = $this->getNinjaClient($ninjaAccount);
$invoice = $this->createNinjaInvoice($ninjaAccount, $ninjaClient);
//$invoice = new Invoice();
//$ninjaClient->invoices()->save($invoice);
$this->contactMailer->sendInvoice($invoice);
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->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()
@ -87,6 +128,8 @@ class AccountController extends \BaseController {
$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;
@ -103,12 +146,8 @@ class AccountController extends \BaseController {
{
$client = Client::whereAccountId($ninjaAccount->id)->wherePublicId(Auth::user()->account_id)->first();
if ($client)
if (!$client)
{
return $client;
}
else
{
$client = new Client;
$client->public_id = Auth::user()->account_id;
$client->user_id = $ninjaAccount->users()->first()->id;
@ -125,8 +164,10 @@ class AccountController extends \BaseController {
{
$contact->$field = Auth::user()->$field;
}
$client->contacts()->save($contact);
$client->contacts()->save($contact);
}
return $client;
}
public function setTrashVisible($entityType, $visible)
@ -662,7 +703,7 @@ class AccountController extends \BaseController {
$user->registered = true;
$user->amend();
$this->mailer->sendConfirmation($user);
$this->userMailer->sendConfirmation($user);
$activities = Activity::scope()->get();
foreach ($activities as $activity)

View File

@ -88,6 +88,9 @@ class UserController extends BaseController {
Event::fire('user.login');
Session::reflash();
return Redirect::to('/dashboard');
/*
$invoice = Invoice::scope()->orderBy('id', 'desc')->first();
if ($invoice)
@ -98,6 +101,7 @@ class UserController extends BaseController {
{
return Redirect::to('/dashboard');
}
*/
}
else
{

View File

@ -306,5 +306,8 @@ return array(
'erase_data' => 'This will permanently erase your data.',
'password' => 'Password',
'pro_plan_product' => 'Pro Plan',
'pro_plan_description' => 'One year enrollment in the Invoice Ninja Pro Plan',
'pro_plan_succes' => 'We\'ve sent you an invoice. Once paid the kfeatures will be enabled.',
);

View File

@ -213,4 +213,30 @@ class Account extends Eloquent
return $data;
}
public function isPro()
{
if ($this->account_key == NINJA_ACCOUNT_KEY)
{
return true;
}
if (!Auth::check())
{
return false;
}
$datePaid = $this->pro_plan_paid;
if (!$datePaid || $datePaid == '0000-00-00')
{
return false;
}
$today = new DateTime('now');
$datePaid = DateTime::createFromFormat('Y-m-d', $datePaid);
$interval = $today->diff($datePaid);
return $interval->y == 0;
}
}

View File

@ -75,6 +75,11 @@ class User extends ConfideUser implements UserInterface, RemindableInterface
return $this->email;
}
public function isPro()
{
return $this->account->isPro();
}
public function getDisplayName()
{
if ($this->getFullName())
@ -104,27 +109,6 @@ class User extends ConfideUser implements UserInterface, RemindableInterface
}
}
public function isPro()
{
if (!Auth::check())
{
return false;
}
$datePaid = $this->account->pro_plan_paid;
if (!$datePaid || $datePaid == '0000-00-00')
{
return false;
}
$today = new DateTime('now');
$datePaid = DateTime::createFromFormat('Y-m-d', $datePaid);
$interval = $today->diff($datePaid);
return $interval->y == 0;
}
public function showGreyBackground()
{
return !$this->theme_id || in_array($this->theme_id, [2, 3, 5, 6, 7, 8, 10, 11, 12]);

View File

@ -10,10 +10,8 @@ class Mailer {
'emails.'.$view.'_html',
'emails.'.$view.'_text'
];
//$view = 'emails.' . $view;
Mail::queue($views, $data, function($message) use ($toEmail, $fromEmail, $fromName, $subject)
Mail::send($views, $data, function($message) use ($toEmail, $fromEmail, $fromName, $subject)
{
$message->to($toEmail)->from($fromEmail, $fromName)->sender($fromEmail, $fromName)
->replyTo($fromEmail, $fromName)->returnPath($fromEmail)->subject($subject);

View File

@ -21,7 +21,7 @@ class UserMailer extends Mailer {
$data = [
'user' => $user
];
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}

View File

@ -136,7 +136,7 @@ class InvoiceRepository
$invoice->po_number = trim($data['po_number']);
$invoice->invoice_design_id = $data['invoice_design_id'];
if (isset($data['tax_rate']) && Utils::parseFloat($data['tax_rate']) > 0)
if (isset($data['tax_name']) && isset($data['tax_rate']) && Utils::parseFloat($data['tax_rate']) > 0)
{
$invoice->tax_rate = Utils::parseFloat($data['tax_rate']);
$invoice->tax_name = trim($data['tax_name']);

View File

@ -231,8 +231,13 @@ define('DEFAULT_DATETIME_FORMAT', 'F j, Y, g:i a');
define('DEFAULT_QUERY_CACHE', 120); // minutes
define('DEFAULT_LOCALE', 'en');
define('RESULT_SUCCESS', 'success');
define('RESULT_FAILURE', 'failure');
define('GATEWAY_PAYPAL_EXPRESS', 17);
define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h');
define('PRO_PLAN_PRICE', 40);
if (Auth::check() && !Session::has(SESSION_TIMEZONE))

View File

@ -274,9 +274,8 @@
<iframe id="theFrame" style="display:none" frameborder="1" width="100%" height="1180"></iframe>
<canvas id="theCanvas" style="display:none;width:100%;border:solid 1px #CCCCCC;"></canvas>
@if (!Auth::user()->isPro())
<a href="#" onclick="showProPlan()">{{ trans('texts.pro_plan.remove_logo_link') }}</a>
{{ trans('texts.pro_plan.remove_logo') }}
@if (!Auth::user()->account->isPro())
{{ trans('texts.pro_plan.remove_logo', ['link'=>'<a href="#" onclick="showProPlan()">'.trans('texts.pro_plan.remove_logo_link').'</a>']) }}
@endif
<div class="modal fade" id="clientModal" tabindex="-1" role="dialog" aria-labelledby="clientModalLabel" aria-hidden="true">
@ -434,7 +433,6 @@
{{ Former::close() }}
{{ Former::open('account/go_pro') }}
<div class="modal fade" id="proPlanModal" tabindex="-1" role="dialog" aria-labelledby="proPlanModalLabel" aria-hidden="true">
<div class="modal-dialog" style="min-width:150px">
<div class="modal-content">
@ -443,20 +441,34 @@
<h4 class="modal-title" id="proPlanModalLabel">{{ trans('texts.sign_up') }}</h4>
</div>
<div style="background-color: #fff; padding-left: 16px; padding-right: 16px">
<div style="background-color: #fff; padding-left: 16px; padding-right: 16px" id="proPlanDiv">
&nbsp;
&nbsp;
</div>
<div class="modal-footer" style="margin-top: 0px">
<div style="padding-left:40px;padding-right:40px;display:none;min-height:130px" id="proPlanWorking">
<h3>{{ trans('texts.working') }}...</h3>
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>
</div>
<div style="background-color: #fff; padding-right:20px;padding-left:20px; display:none" id="proPlanSuccessDiv">
<br/>
<h3>{{ trans('texts.success') }}</h3>
{{ trans('texts.pro_plan_succes') }}<br/>&nbsp;
</div>
<div class="modal-footer" style="margin-top: 0px" id="proPlanFooter">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.close') }}</button>
{{ Button::primary_submit(trans('texts.sign_up')) }}
<button type="button" class="btn btn-primary" data-dismiss="modal" id="proPlanButton" onclick="submitProPlan()">{{ trans('texts.sign_up') }}</button>
</div>
</div>
</div>
</div>
{{ Former::close() }}
</div>
@ -474,6 +486,22 @@
$('#proPlanModal').modal('show');
}
function submitProPlan() {
$('#proPlanDiv, #proPlanFooter').hide();
$('#proPlanWorking').show();
$.ajax({
type: 'POST',
url: '{{ URL::to('account/go_pro') }}',
success: function(result) {
$('#proPlanSuccessDiv, #proPlanFooter').show();
$('#proPlanWorking, #proPlanButton').hide();
}
});
}
$(function() {
$('#country_id').combobox().on('change', function(e) {

View File

@ -3,15 +3,14 @@
"description": "An open-source invoicing site built with Laravel",
"keywords": ["invoice", "laravel"],
"license": "Attribution Assurance License",
"authors": [
{
"name": "Hillel Coren",
"email": "hillelcoren@gmail.com"
}
],
"authors": [
{
"name": "Hillel Coren",
"email": "hillelcoren@gmail.com"
}
],
"require": {
"laravel/framework": "4.1.*",
"jasonlewis/basset": "dev-master",
"patricktalmadge/bootstrapper": "dev-develop",
"zizaco/confide": "3.1.x",
"anahkiasen/former": "dev-master",