Bug fixes

This commit is contained in:
Hillel Coren 2013-12-04 00:00:01 +02:00
parent 2142538e15
commit 99800f38dd
23 changed files with 142 additions and 95 deletions

View File

@ -13,7 +13,7 @@ class AccountController extends \BaseController {
//$user = User::where('password', '=', $guestKey)->firstOrFail(); //$user = User::where('password', '=', $guestKey)->firstOrFail();
$user = User::where('password', '=', $guestKey)->first(); $user = User::where('password', '=', $guestKey)->first();
if ($user && !$user->is_guest) if ($user && $user->registered)
{ {
exit; exit;
} }
@ -33,7 +33,7 @@ class AccountController extends \BaseController {
$account->users()->save($user); $account->users()->save($user);
} }
Auth::login($user); Auth::login($user, true);
Session::put('tz', 'US/Eastern'); Session::put('tz', 'US/Eastern');
return Redirect::to('invoices/create'); return Redirect::to('invoices/create');
@ -452,7 +452,7 @@ class AccountController extends \BaseController {
public function checkEmail() public function checkEmail()
{ {
$email = User::where('email', '=', Input::get('email'))->first(); $email = User::where('email', '=', Input::get('email'))->where('id', '<>', Auth::user()->id)->first();
if ($email) { if ($email) {
return "taken"; return "taken";
@ -500,6 +500,6 @@ class AccountController extends \BaseController {
*/ */
Session::flash('message', 'Successfully registered'); Session::flash('message', 'Successfully registered');
return Redirect::to(Input::get('path')); return Redirect::to(Input::get('path'))->with('clearGuestKey', true);
} }
} }

View File

@ -5,7 +5,7 @@ class ActivityController extends \BaseController {
public function getDatatable($clientId) public function getDatatable($clientId)
{ {
return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get()) return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get())
->addColumn('date', function($model) { return $model->created_at->format('m/d/y h:i a'); }) ->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); })
->addColumn('message', function($model) { return $model->message; }) ->addColumn('message', function($model) { return $model->message; })
->addColumn('balance', function($model) { return '$' . $model->balance; }) ->addColumn('balance', function($model) { return '$' . $model->balance; })
->orderColumns('date') ->orderColumns('date')

View File

@ -14,6 +14,7 @@ class ClientController extends \BaseController {
return View::make('list', array( return View::make('list', array(
'entityType'=>ENTITY_CLIENT, 'entityType'=>ENTITY_CLIENT,
'title' => '- Clients',
'columns'=>['checkbox', 'Client', 'Contact', 'Balance', 'Last Login', 'Date Created', 'Email', 'Phone', 'Action'] 'columns'=>['checkbox', 'Client', 'Contact', 'Balance', 'Last Login', 'Date Created', 'Email', 'Phone', 'Action']
)); ));
} }
@ -61,7 +62,7 @@ class ClientController extends \BaseController {
'client' => null, 'client' => null,
'method' => 'POST', 'method' => 'POST',
'url' => 'clients', 'url' => 'clients',
'title' => 'New', 'title' => '- New Client',
'countries' => Country::orderBy('name')->get()); 'countries' => Country::orderBy('name')->get());
return View::make('clients.edit', $data); return View::make('clients.edit', $data);
@ -88,7 +89,11 @@ class ClientController extends \BaseController {
$client = Client::scope()->with('contacts')->findOrFail($id); $client = Client::scope()->with('contacts')->findOrFail($id);
trackViewed($client->name); trackViewed($client->name);
return View::make('clients.show')->with('client', $client); $data = array(
'client' => $client,
'title' => '- ' . $client->name);
return View::make('clients.show', $data);
} }
/** /**
@ -104,7 +109,7 @@ class ClientController extends \BaseController {
'client' => $client, 'client' => $client,
'method' => 'PUT', 'method' => 'PUT',
'url' => 'clients/' . $id, 'url' => 'clients/' . $id,
'title' => 'Edit', 'title' => '- ' . $client->name,
'countries' => Country::orderBy('name')->get()); 'countries' => Country::orderBy('name')->get());
return View::make('clients.edit', $data); return View::make('clients.edit', $data);
} }

View File

@ -11,6 +11,7 @@ class CreditController extends \BaseController {
{ {
return View::make('list', array( return View::make('list', array(
'entityType'=>ENTITY_CREDIT, 'entityType'=>ENTITY_CREDIT,
'title' => '- Credits',
'columns'=>['checkbox', 'Credit Number', 'Client', 'Amount', 'Credit Date'] 'columns'=>['checkbox', 'Credit Number', 'Client', 'Amount', 'Credit Date']
)); ));
} }

View File

@ -11,6 +11,7 @@ class InvoiceController extends \BaseController {
{ {
return View::make('list', array( return View::make('list', array(
'entityType'=>ENTITY_INVOICE, 'entityType'=>ENTITY_INVOICE,
'title' => '- Invoices',
'columns'=>['checkbox', 'Invoice Number', 'Client', 'Total', 'Amount Due', 'Invoice Date', 'Due Date', 'Status', 'Action'] 'columns'=>['checkbox', 'Invoice Number', 'Client', 'Total', 'Amount Due', 'Invoice Date', 'Due Date', 'Status', 'Action']
)); ));
} }
@ -61,7 +62,8 @@ class InvoiceController extends \BaseController {
public function view($key) public function view($key)
{ {
$invitation = Invitation::with('user', 'invoice.account', 'invoice.invoice_items', 'invoice.client.account.account_gateways')->where('key', '=', $key)->firstOrFail(); $invitation = Invitation::with('user', 'invoice.account', 'invoice.invoice_items', 'invoice.client.account.account_gateways')
->where('key', '=', $key)->firstOrFail();
$user = $invitation->user; $user = $invitation->user;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
@ -216,9 +218,9 @@ class InvoiceController extends \BaseController {
'invoice' => $invoice, 'invoice' => $invoice,
'method' => 'PUT', 'method' => 'PUT',
'url' => 'invoices/' . $id, 'url' => 'invoices/' . $id,
'title' => 'Edit', 'title' => '- ' . $invoice->invoice_number,
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->get(), 'products' => Product::scope()->get(array('key','notes','cost','qty')),
'client' => $invoice->client, 'client' => $invoice->client,
'clients' => Client::scope()->orderBy('name')->get()); 'clients' => Client::scope()->orderBy('name')->get());
return View::make('invoices.edit', $data); return View::make('invoices.edit', $data);
@ -240,11 +242,11 @@ class InvoiceController extends \BaseController {
'invoiceNumber' => $invoiceNumber, 'invoiceNumber' => $invoiceNumber,
'method' => 'POST', 'method' => 'POST',
'url' => 'invoices', 'url' => 'invoices',
'title' => 'New', 'title' => '- New Invoice',
'client' => $client, 'client' => $client,
'items' => json_decode(Input::old('items')), 'items' => json_decode(Input::old('items')),
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->get(), 'products' => Product::scope()->get(array('key','notes','cost','qty')),
'clients' => Client::scope()->orderBy('name')->get()); 'clients' => Client::scope()->orderBy('name')->get());
return View::make('invoices.edit', $data); return View::make('invoices.edit', $data);
} }

View File

@ -4,7 +4,11 @@ class PaymentController extends \BaseController
{ {
public function index() public function index()
{ {
return View::make('payments.index'); return View::make('list', array(
'entityType'=>ENTITY_PAYMENT,
'title' => '- Payments',
'columns'=>['checkbox', 'Transaction Reference', 'Client', 'Amount', 'Payment Date']
));
} }
public function getDatatable($clientId = null) public function getDatatable($clientId = null)
@ -18,24 +22,17 @@ class PaymentController extends \BaseController
$table = Datatable::collection($collection->get()); $table = Datatable::collection($collection->get());
if (!$clientId) { if (!$clientId) {
$table->addColumn('client', function($model) $table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; });
{
return link_to('clients/' . $model->invoice->client->id, $model->invoice->client->name);
});
} }
return $table->addColumn('invoice', function($model) $table->addColumn('transaction_reference', function($model) { return $model->transaction_reference; });
{
return link_to('invoices/' . $model->invoice->id . '/edit', $model->invoice->number); if (!$clientId) {
}) $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); });
->addColumn('amount', function($model) }
{
return '$' . $model->amount; return $table->addColumn('amount', function($model) { return '$' . $model->amount; })
}) ->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); })
->addColumn('date', function($model)
{
return $model->created_at->format('m/d/y h:i a');
})
->orderColumns('client') ->orderColumns('client')
->make(); ->make();
} }

View File

@ -219,9 +219,14 @@ class UserController extends BaseController {
*/ */
public function logout() public function logout()
{ {
Confide::logout(); if (!Auth::user()->registered)
{
return Redirect::to('/'); $account = Auth::user()->account;
$account->forceDelete();
} }
Confide::logout();
return Redirect::to('/')->with('clearGuestKey', true);
}
} }

View File

@ -212,7 +212,7 @@ class ConfideSetupUsersTable extends Migration {
$t->timestamp('viewed_date'); $t->timestamp('viewed_date');
$t->foreign('user_id')->references('id')->on('users'); $t->foreign('user_id')->references('id')->on('users');
$t->foreign('contact_id')->references('id')->on('contacts'); $t->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade');
$t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
}); });

View File

@ -3,6 +3,7 @@
class Account extends Eloquent class Account extends Eloquent
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('ip', 'timezone_id', 'created_at', 'updated_at', 'deleted_at', 'key', 'last_login');
public function users() public function users()
{ {

View File

@ -2,6 +2,8 @@
class AccountGateway extends Eloquent class AccountGateway extends Eloquent
{ {
protected $hidden = array('config');
public function gateway() public function gateway()
{ {
return $this->belongsTo('Gateway'); return $this->belongsTo('Gateway');

View File

@ -3,6 +3,7 @@
class Client extends Eloquent implements iEntity class Client extends Eloquent implements iEntity
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'notes', 'last_login');
public static $fieldName = 'Client - Name'; public static $fieldName = 'Client - Name';
public static $fieldPhone = 'Client - Phone'; public static $fieldPhone = 'Client - Phone';

View File

@ -3,6 +3,7 @@
class Invitation extends Eloquent class Invitation extends Eloquent
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at');
public function scopeScope($query) public function scopeScope($query)
{ {

View File

@ -3,6 +3,7 @@
class Invoice extends Eloquent implements iEntity class Invoice extends Eloquent implements iEntity
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'viewed_date', 'key');
public function scopeScope($query) public function scopeScope($query)
{ {

View File

@ -3,6 +3,7 @@
class InvoiceItem extends Eloquent class InvoiceItem extends Eloquent
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at');
public function invoice() public function invoice()
{ {

View File

@ -8,6 +8,7 @@ class User extends ConfideUser implements UserInterface, RemindableInterface, iP
{ {
protected $softDelete = true; protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'password', 'confirmation_code', 'registered', 'confirmed');
public static $rules = array( public static $rules = array(
/* /*
@ -25,13 +26,6 @@ class User extends ConfideUser implements UserInterface, RemindableInterface, iP
*/ */
protected $table = 'users'; protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('Account');

View File

@ -11,7 +11,7 @@
</style> </style>
{{ Former::open_for_files()->addClass('col-md-9 col-md-offset-1')->rules(array( {{ Former::open_for_files()->addClass('col-md-10 col-md-offset-1')->rules(array(
'name' => 'required', 'name' => 'required',
'email' => 'email|required' 'email' => 'email|required'
)); }} )); }}
@ -58,7 +58,10 @@
</div> </div>
</div> </div>
{{ Former::actions( Button::lg_primary_submit('Save') ) }} <center>
{{ Button::lg_primary_submit('Save') }}
</center>
{{ Former::close() }} {{ Former::close() }}
<script type="text/javascript"> <script type="text/javascript">

View File

@ -3,7 +3,7 @@
@section('content') @section('content')
@parent @parent
{{ Former::open()->addClass('col-md-9 col-md-offset-1') }} {{ Former::open()->addClass('col-md-10 col-md-offset-1') }}
{{ Former::legend('Payment Gateway') }} {{ Former::legend('Payment Gateway') }}
@if ($accountGateway) @if ($accountGateway)

View File

@ -5,12 +5,11 @@
$('input#name').focus(); $('input#name').focus();
@stop @stop
@section('content') @section('content')
<!--<h3>{{ $title }} Client</h3>--> <!--<h3>{{ $title }} Client</h3>-->
{{ Former::open($url)->addClass('col-md-9 col-md-offset-1 main_form')->method($method)->rules(array( {{ Former::open($url)->addClass('col-md-10 col-md-offset-1 main_form')->method($method)->rules(array(
'name' => 'required', 'name' => 'required',
'email' => 'email' 'email' => 'email'
)); }} )); }}
@ -71,7 +70,11 @@
{{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }} {{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }}
{{ Former::actions( Button::lg_primary_submit('Save') ) }} <center style="margin-top:16px">
{{ Button::lg_primary_submit('Save') }} &nbsp;|&nbsp;
{{ link_to('clients/' . ($client ? $client->id : ''), 'Cancel') }}
</center>
{{ Former::close() }} {{ Former::close() }}
<script type="text/javascript"> <script type="text/javascript">

View File

@ -8,7 +8,7 @@
<meta name="author" content=""> <meta name="author" content="">
<meta name="csrf-token" content="<?= csrf_token() ?>"> <meta name="csrf-token" content="<?= csrf_token() ?>">
<title>Invoice Ninja</title> <title>Invoice Ninja {{ isset($title) ? $title : '' }}</title>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
@ -237,7 +237,7 @@
@if (Auth::user()->registered) @if (Auth::user()->registered)
{{ Auth::user()->email }} &nbsp; {{ Auth::user()->email }} &nbsp;
@else @else
{{ Button::sm_primary('Sign up', array('data-toggle'=>'modal', 'data-target'=>'#signUpModal')); }} {{ Button::sm_primary('Sign up', array('data-toggle'=>'modal', 'data-target'=>'#signUpModal')) }}
@endif @endif
<div class="btn-group"> <div class="btn-group">
@ -245,12 +245,12 @@
My Account <span class="caret"></span> My Account <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li>{{ link_to('account/details', 'Details'); }}</li> <li>{{ link_to('account/details', 'Details') }}</li>
<li>{{ link_to('account/settings', 'Settings'); }}</li> <li>{{ link_to('account/settings', 'Settings') }}</li>
<li>{{ link_to('account/import', 'Import'); }}</li> <li>{{ link_to('account/import', 'Import') }}</li>
<li>{{ link_to('account/export', 'Export'); }}</li> <li>{{ link_to('account/export', 'Export') }}</li>
<li class="divider"></li> <li class="divider"></li>
<li><a href="#">Logout</a></li> <li>{{ link_to('#', 'Logout', array('onclick'=>'logout()')) }}</li>
</ul> </ul>
</div> </div>
</div> </div>
@ -352,6 +352,28 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="logoutModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Logout</h4>
</div>
<div class="container">
<h3>Are you sure?</h3>
<p>This will erase all of your data.</p>
</div>
<div class="modal-footer" id="signUpFooter">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" onclick="logout(true)">Logout</button>
</div>
</div>
</div>
</div>
@endif @endif
@ -398,7 +420,6 @@
url: '{{ URL::to('signup/validate') }}', url: '{{ URL::to('signup/validate') }}',
data: 'email=' + $('form.signUpForm #email').val() + '&path={{ Request::path() }}', data: 'email=' + $('form.signUpForm #email').val() + '&path={{ Request::path() }}',
success: function(result) { success: function(result) {
console.log(result)
if (result == 'available') { if (result == 'available') {
$('.signUpForm').submit(); $('.signUpForm').submit();
} else { } else {
@ -421,13 +442,24 @@
} }
@endif @endif
function logout(force)
{
if (force || {{ Auth::user()->registered ? 'true' : 'false' }}) {
window.location = '{{ URL::to('logout') }}';
} else {
$('#logoutModal').modal('show');
}
}
$(function() { $(function() {
@if (Auth::user()->is_guest)
if (isStorageSupported()) { if (isStorageSupported()) {
@if (!Auth::user()->registered)
localStorage.setItem('guest_key', '{{ Auth::user()->password }}'); localStorage.setItem('guest_key', '{{ Auth::user()->password }}');
} @elseif (Session::get('clearGuestKey'))
localStorage.setItem('guest_key', '');
@endif @endif
}
@if (!Auth::user()->registered) @if (!Auth::user()->registered)
validateSignUp(); validateSignUp();
@ -436,12 +468,19 @@
$(['first_name','last_name','email','password']).each(function(i, field) { $(['first_name','last_name','email','password']).each(function(i, field) {
var $input = $('form.signUpForm #'+field); var $input = $('form.signUpForm #'+field);
if (!$input.val()) { if (!$input.val()) {
console.log('focus: %s', field);
$input.focus(); $input.focus();
return false; return false;
} }
}); });
}) })
/*
$(window).on('beforeunload', function() {
return true;
});
$('form').submit(function() { $(window).off('beforeunload') });
$('a[rel!=ext]').click(function() { $(window).off('beforeunload') });
*/
@endif @endif
@yield('onReady') @yield('onReady')

View File

@ -131,7 +131,7 @@
{{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }} {{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }}
@endif @endif
{{ Button::primary('Save Invoice', array('onclick' => 'onSaveClick()')) }} {{ Button::primary_submit('Save Invoice', array('onclick' => 'onSaveClick()')) }}
{{ Button::primary('Send Email', array('onclick' => 'onEmailClick()')) }} {{ Button::primary('Send Email', array('onclick' => 'onEmailClick()')) }}
</div> </div>
<p>&nbsp;</p> <p>&nbsp;</p>
@ -343,10 +343,6 @@
} }
} }
function onSaveClick() {
$('.main_form').submit();
}
function onArchiveClick() { function onArchiveClick() {
$('#action').val('archive'); $('#action').val('archive');
$('.main_form').submit(); $('.main_form').submit();

View File

@ -1,9 +0,0 @@
@extends('header')
@section('content')
<h3>View Invoice</h3>
{{ $invoice->number }} - {{ $invoice->client->name }}
@stop

View File

@ -116,9 +116,14 @@
} }
if (isStorageSupported()) { if (isStorageSupported()) {
@if (Session::get('clearGuestKey'))
localStorage.setItem('guest_key', '');
@else
$('[name="guest_key"]').val(localStorage.getItem('guest_key')); $('[name="guest_key"]').val(localStorage.getItem('guest_key'));
@endif
} }
}); });
</script> </script>

View File

@ -171,19 +171,18 @@ function generatePDF(invoice) {
} }
function formatNumber(num) { function formatNumber(num) {
if (!num) { num = parseFloat(num);
return ""; if (!num) return '';
} var p = num.toFixed(2).split(".");
return parseFloat(num).toFixed(2); return p[0].split("").reverse().reduce(function(acc, num, i, orig) {
return num + (i && !(i % 3) ? "," : "") + acc;
}, "") + "." + p[1];
} }
function formatMoney(num) { function formatMoney(num) {
num = parseFloat(num); num = parseFloat(num);
if (!num) return '$0.00'; if (!num) return '$0.00';
var p = num.toFixed(2).split("."); return '$' + formatNumber(num);
return "$" + p[0].split("").reverse().reduce(function(acc, num, i, orig) {
return num + (i && !(i % 3) ? "," : "") + acc;
}, "") + "." + p[1];
} }