1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Cleaning up the routes.php file

This commit is contained in:
Hillel Coren 2013-12-07 22:33:07 +02:00
parent 616df18b06
commit b7f09685d0
23 changed files with 292 additions and 222 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/app/config/staging
/bootstrap/compiled.php
/vendor
composer.phar

View File

@ -65,7 +65,7 @@ return array(
|
*/
'key' => 'Zwa83ZM8ZYjEAfHWXl7SvYwVdV9X*oU1',
'key' => 'a2jfy6HtBEdNtJnRSOC7vIM3UVhxZ1BB',
/*
|--------------------------------------------------------------------------

View File

@ -4,8 +4,12 @@ class AccountController extends \BaseController {
public function getStarted()
{
$user = false;
if (Auth::check())
{
return Redirect::to('invoices/create');
}
$user = false;
$guestKey = Input::get('guest_key');
if ($guestKey)
@ -128,7 +132,7 @@ class AccountController extends \BaseController {
$contacts = DB::table('contacts')->whereIn('client_id', function($query){
$query->select('client_id')->from('clients')->where('account_id','=',Auth::user()->account_id);
})->get();
AccountController::exportData($output, toArray($contacts));
AccountController::exportData($output, Utils::toArray($contacts));
$invoices = Invoice::where('account_id','=',Auth::user()->account_id)->get();
AccountController::exportData($output, $invoices->toArray());
@ -136,7 +140,7 @@ class AccountController extends \BaseController {
$invoiceItems = DB::table('invoice_items')->whereIn('invoice_id', function($query){
$query->select('invoice_id')->from('invoices')->where('account_id','=',Auth::user()->account_id);
})->get();
AccountController::exportData($output, toArray($invoiceItems));
AccountController::exportData($output, Utils::toArray($invoiceItems));
$payments = Payment::where('account_id','=',Auth::user()->account_id)->get();
AccountController::exportData($output, $payments->toArray());
@ -251,7 +255,7 @@ class AccountController extends \BaseController {
$client->contacts()->save($contact);
}
$message = pluralize('Successfully created ? client', $count);
$message = Utils::pluralize('Successfully created ? client', $count);
Session::flash('message', $message);
return Redirect::to('clients');
}

View File

@ -7,7 +7,7 @@ class ActivityController extends \BaseController {
$clientId = Client::getPrivateId($clientPublicId);
return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get())
->addColumn('date', function($model) { return timestampToDateString($model->created_at); })
->addColumn('date', function($model) { return Utils::timestampToDateString($model->created_at); })
->addColumn('message', function($model) { return $model->message; })
->addColumn('balance', function($model) { return '$' . $model->balance; })
->orderColumns('date')

View File

@ -26,17 +26,17 @@ class ClientController extends \BaseController {
->where('clients.account_id', '=', Auth::user()->account_id)
->where('clients.deleted_at', '=', null)
->where('contacts.is_primary', '=', true)
->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','contacts.phone','contacts.email');
->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email');
return Datatable::query($query)
->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; })
->addColumn('name', function($model) { return link_to('clients/' . $model->public_id, $model->name); })
->addColumn('first_name', function($model) { return $model->first_name . ' ' . $model->last_name; })
->addColumn('balance', function($model) { return '$' . $model->balance; })
->addColumn('last_login', function($model) { return timestampToDateString($model->last_login); })
->addColumn('created_at', function($model) { return timestampToDateString($model->created_at); })
->addColumn('last_login', function($model) { return Utils::timestampToDateString($model->last_login); })
->addColumn('created_at', function($model) { return Utils::timestampToDateString($model->created_at); })
->addColumn('email', function($model) { return $model->email ? HTML::mailto($model->email, $model->email) : ''; })
->addColumn('phone', function($model) { return $model->phone; })
->addColumn('work_phone', function($model) { return Utils::formatPhoneNumber($model->work_phone); })
->addColumn('dropdown', function($model)
{
return '<div class="btn-group tr-action" style="visibility:hidden;">
@ -92,7 +92,7 @@ class ClientController extends \BaseController {
public function show($publicId)
{
$client = Client::scope($publicId)->with('contacts')->firstOrFail();
trackViewed($client->name, ENTITY_CLIENT);
Utils::trackViewed($client->name, ENTITY_CLIENT);
$data = array(
'client' => $client,
@ -216,7 +216,7 @@ class ClientController extends \BaseController {
}
}
$message = pluralize('Successfully '.$action.'d ? client', count($ids));
$message = Utils::pluralize('Successfully '.$action.'d ? client', count($ids));
Session::flash('message', $message);
return Redirect::to('clients');

View File

@ -36,7 +36,7 @@ class CreditController extends \BaseController {
}
return $table->addColumn('amount', function($model){ return '$' . money_format('%i', $model->amount); })
->addColumn('credit_date', function($model) { return timestampToDateString($model->credit_date); })
->addColumn('credit_date', function($model) { return Utils::timestampToDateString($model->credit_date); })
->addColumn('dropdown', function($model)
{
return '<div class="btn-group tr-action" style="visibility:hidden;">
@ -113,7 +113,7 @@ class CreditController extends \BaseController {
}
$credit->client_id = Input::get('client');
$credit->credit_date = toSqlDate(Input::get('credit_date'));
$credit->credit_date = Utils::toSqlDate(Input::get('credit_date'));
$credit->amount = floatval(Input::get('amount'));
$credit->save();
@ -137,7 +137,7 @@ class CreditController extends \BaseController {
}
}
$message = pluralize('Successfully '.$action.'d ? credit', count($ids));
$message = Utils::pluralize('Successfully '.$action.'d ? credit', count($ids));
Session::flash('message', $message);
return Redirect::to('credits');

View File

@ -43,8 +43,8 @@ class InvoiceController extends \BaseController {
return $table->addColumn('total', function($model){ return '$' . money_format('%i', $model->total); })
->addColumn('balance', function($model) { return '$' . money_format('%i', $model->balance); })
->addColumn('invoice_date', function($model) { return fromSqlDate($model->invoice_date); })
->addColumn('due_date', function($model) { return fromSqlDate($model->due_date); })
->addColumn('invoice_date', function($model) { return Utils::fromSqlDate($model->invoice_date); })
->addColumn('due_date', function($model) { return Utils::fromSqlDate($model->due_date); })
->addColumn('invoice_status_name', function($model) { return $model->invoice_status_name; })
->addColumn('dropdown', function($model)
{
@ -237,7 +237,7 @@ class InvoiceController extends \BaseController {
public function edit($publicId)
{
$invoice = Invoice::scope($publicId)->with('account.country', 'client', 'invoice_items')->firstOrFail();
trackViewed($invoice->invoice_number . ' - ' . $invoice->client->name, ENTITY_INVOICE);
Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->name, ENTITY_INVOICE);
$data = array(
'account' => $invoice->account,
@ -352,8 +352,8 @@ class InvoiceController extends \BaseController {
$invoice->invoice_number = trim(Input::get('invoice_number'));
$invoice->discount = 0;
$invoice->invoice_date = toSqlDate(Input::get('invoice_date'));
$invoice->due_date = toSqlDate(Input::get('due_date'));
$invoice->invoice_date = Utils::toSqlDate(Input::get('invoice_date'));
$invoice->due_date = Utils::toSqlDate(Input::get('due_date'));
$invoice->notes = Input::get('notes');
$client->invoices()->save($invoice);
@ -493,7 +493,7 @@ class InvoiceController extends \BaseController {
}
}
$message = pluralize('Successfully '.$action.'d ? invoice', count($ids));
$message = Utils::pluralize('Successfully '.$action.'d ? invoice', count($ids));
Session::flash('message', $message);
return Redirect::to('invoices');

View File

@ -38,7 +38,7 @@ class PaymentController extends \BaseController
return $table->addColumn('invoice_number', function($model) { return $model->invoice_public_id ? link_to('invoices/' . $model->invoice_public_id . '/edit', $model->invoice_invoice_number) : ''; })
->addColumn('amount', function($model) { return '$' . $model->amount; })
->addColumn('payment_date', function($model) { return timestampToDateString($model->payment_date); })
->addColumn('payment_date', function($model) { return Utils::timestampToDateString($model->payment_date); })
->addColumn('dropdown', function($model)
{
return '<div class="btn-group tr-action" style="visibility:hidden;">
@ -122,7 +122,7 @@ class PaymentController extends \BaseController
$payment->client_id = Input::get('client');
$payment->invoice_id = $invoiceId;
$payment->payment_date = toSqlDate(Input::get('payment_date'));
$payment->payment_date = Utils::toSqlDate(Input::get('payment_date'));
$payment->amount = floatval(Input::get('amount'));
$payment->save();
@ -146,7 +146,7 @@ class PaymentController extends \BaseController
}
}
$message = pluralize('Successfully '.$action.'d ? payment', count($ids));
$message = Utils::pluralize('Successfully '.$action.'d ? payment', count($ids));
Session::flash('message', $message);
return Redirect::to('payments');

View File

@ -74,7 +74,7 @@ class UserController extends BaseController {
{
if( Confide::user() )
{
return Redirect::to('/');
return Redirect::to('/clients');
}
else
{
@ -173,6 +173,14 @@ class UserController extends BaseController {
*/
public function do_forgot_password()
{
Confide::forgotPassword( Input::get( 'email' ) );
$notice_msg = Lang::get('confide::confide.alerts.password_forgot');
return Redirect::action('UserController@login')
->with( 'notice', $notice_msg );
/*
if( Confide::forgotPassword( Input::get( 'email' ) ) )
{
$notice_msg = Lang::get('confide::confide.alerts.password_forgot');
@ -186,6 +194,7 @@ class UserController extends BaseController {
->withInput()
->with( 'error', $error_msg );
}
*/
}
/**

152
app/libraries/utils.php Executable file
View File

@ -0,0 +1,152 @@
<?php
class Utils
{
public static function formatPhoneNumber($phoneNumber)
{
$phoneNumber = preg_replace('/[^0-9]/','',$phoneNumber);
if (!$phoneNumber) {
return '';
}
if(strlen($phoneNumber) > 10) {
$countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
$areaCode = substr($phoneNumber, -10, 3);
$nextThree = substr($phoneNumber, -7, 3);
$lastFour = substr($phoneNumber, -4, 4);
$phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 10) {
$areaCode = substr($phoneNumber, 0, 3);
$nextThree = substr($phoneNumber, 3, 3);
$lastFour = substr($phoneNumber, 6, 4);
$phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour;
}
else if(strlen($phoneNumber) == 7) {
$nextThree = substr($phoneNumber, 0, 3);
$lastFour = substr($phoneNumber, 3, 4);
$phoneNumber = $nextThree.'-'.$lastFour;
}
return $phoneNumber;
}
function pluralize($string, $count)
{
$string = str_replace('?', $count, $string);
return $count == 1 ? $string : $string . 's';
}
function toArray($data)
{
return json_decode(json_encode((array) $data), true);
}
function toSpaceCase($camelStr)
{
return preg_replace('/([a-z])([A-Z])/s','$1 $2', $camelStr);
}
function timestampToDateTimeString($timestamp) {
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date = new Carbon($timestamp);
$date->tz = $tz;
if ($date->year < 1900) {
return '';
}
return $date->format('l M jS, Y g:ia');
}
function timestampToDateString($timestamp) {
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date = new Carbon($timestamp);
$date->tz = $tz;
if ($date->year < 1900) {
return '';
}
return $date->toFormattedDateString();
}
/*
function toDateString($date)
{
if ($date->year < 1900) {
return '';
}
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date->tz = $tz;
return $date->toFormattedDateString();
}
*/
function toSqlDate($date)
{
if (!$date)
{
return '';
}
return DateTime::createFromFormat('m/d/Y', $date);
}
function fromSqlDate($date)
{
if (!$date || $date == '0000-00-00')
{
return '';
}
return DateTime::createFromFormat('Y-m-d', $date)->format('m/d/Y');
}
function trackViewed($name, $type)
{
$url = Request::url();
$viewed = Session::get(RECENTLY_VIEWED);
if (!$viewed)
{
$viewed = [];
}
$object = new stdClass;
$object->url = $url;
$object->name = ucwords($type) . ': ' . $name;
for ($i=0; $i<count($viewed); $i++)
{
$item = $viewed[$i];
if ($object->url == $item->url)
{
array_splice($viewed, $i, 1);
break;
}
}
array_unshift($viewed, $object);
if (count($viewed) > RECENTLY_VIEWED_LIMIT)
{
array_pop($viewed);
}
Session::put(RECENTLY_VIEWED, $viewed);
}
}

View File

@ -86,7 +86,7 @@ class Client extends EntityModel
if ($this->work_phone)
{
$str .= '<i class="fa fa-phone" style="width: 20px"></i>' . $this->work_phone;
$str .= '<i class="fa fa-phone" style="width: 20px"></i>' . Utils::formatPhoneNumber($this->work_phone);
}
return $str;

View File

@ -63,7 +63,7 @@ class Contact extends EntityModel
if ($this->phone)
{
$str .= '<i class="fa fa-phone" style="width: 20px"></i>' . $this->phone;
$str .= '<i class="fa fa-phone" style="width: 20px"></i>' . Utils::formatPhoneNumber($this->phone);
}
if ($str)

View File

@ -4,7 +4,7 @@ use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Zizaco\Confide\ConfideUser;
class User extends ConfideUser implements UserInterface, RemindableInterface, iPerson
class User extends ConfideUser implements UserInterface, RemindableInterface
{
protected $softDelete = true;

View File

@ -39,7 +39,7 @@ Route::filter('auth', function()
{
if (!Auth::check())
{
return Redirect::to('/');
return Redirect::to('/login');
}
});
@ -105,142 +105,6 @@ HTML::macro('image_data', function($imagePath) {
});
function pluralize($string, $count)
{
$string = str_replace('?', $count, $string);
return $count == 1 ? $string : $string . 's';
}
function toArray($data)
{
return json_decode(json_encode((array) $data), true);
}
function toSpaceCase($camelStr)
{
return preg_replace('/([a-z])([A-Z])/s','$1 $2', $camelStr);
}
function timestampToDateTimeString($timestamp) {
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date = new Carbon($timestamp);
$date->tz = $tz;
if ($date->year < 1900) {
return '';
}
return $date->format('l M jS, Y g:ia');
}
function timestampToDateString($timestamp) {
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date = new Carbon($timestamp);
$date->tz = $tz;
if ($date->year < 1900) {
return '';
}
return $date->toFormattedDateString();
}
function toDateString($date)
{
if ($date->year < 1900) {
return '';
}
$tz = Session::get('tz');
if (!$tz) {
$tz = 'US/Eastern';
}
$date->tz = $tz;
return $date->toFormattedDateString();
}
function toDateTimeString($date)
{
}
function toSqlDate($date)
{
if (!$date)
{
return '';
}
return DateTime::createFromFormat('m/d/Y', $date);
}
function fromSqlDate($date)
{
if (!$date || $date == '0000-00-00')
{
return '';
}
return DateTime::createFromFormat('Y-m-d', $date)->format('m/d/Y');
}
function fromSqlTimestamp($date)
{
if (!$date || $date == '0000-00-00 00:00:00')
{
return '';
}
return DateTime::createFromFormat('Y-m-d H:i:s', $date)->format('m/d/Y h:ia');
}
function processedRequest($url)
{
//Session::put(Input::get('_token'), $url);
//Session::put('_token', md5(microtime()));
}
function trackViewed($name, $type)
{
$url = Request::url();
$viewed = Session::get(RECENTLY_VIEWED);
if (!$viewed)
{
$viewed = [];
}
$object = new stdClass;
$object->url = $url;
$object->name = ucwords($type) . ': ' . $name;
for ($i=0; $i<count($viewed); $i++)
{
$item = $viewed[$i];
if ($object->url == $item->url)
{
array_splice($viewed, $i, 1);
break;
}
}
array_unshift($viewed, $object);
if (count($viewed) > RECENTLY_VIEWED_LIMIT)
{
array_pop($viewed);
}
Session::put(RECENTLY_VIEWED, $viewed);
}
define("ENV_DEVELOPMENT", "local");
define("ENV_STAGING", "staging");
@ -264,23 +128,8 @@ define("ACCOUNT_EXPORT", "export");
define("DEFAULT_INVOICE_NUMBER", "0001");
define("RECENTLY_VIEWED_LIMIT", 8);
define('INVOICE_STATUS_DRAFT', 1);
define('INVOICE_STATUS_SENT', 2);
define('INVOICE_STATUS_VIEWED', 3);
define('INVOICE_STATUS_PARTIAL', 4);
define('INVOICE_STATUS_PAID', 5);
interface iPerson
{
//public function getFullName();
//public function getPersonType();
}
interface iEntity
{
//public function getName();
//public function getEntityType();
}
define('INVOICE_STATUS_PAID', 5);

View File

@ -28,9 +28,9 @@
@if ($field == 'solutionType' || $field == 'landingPage')
{{-- do nothing --}}
@elseif ($field == 'testMode' || $field == 'developerMode')
{{ Former::checkbox($gateway->id.'_'.$field)->label(toSpaceCase($field))->text('Enable') }}
{{ Former::checkbox($gateway->id.'_'.$field)->label(Utils::toSpaceCase($field))->text('Enable') }}
@else
{{ Former::text($gateway->id.'_'.$field)->label(toSpaceCase($field)) }}
{{ Former::text($gateway->id.'_'.$field)->label(Utils::toSpaceCase($field)) }}
@endif
@endforeach

View File

@ -28,7 +28,7 @@
<h2>{{ $client->name }}</h2>
@if ($client->last_login > 0)
<h3 style="margin-top:0px"><small>
Last logged in {{ timestampToDateTimeString($client->last_login); }}
Last logged in {{ Utils::timestampToDateTimeString($client->last_login); }}
</small></h3>
@endif

View File

@ -35,7 +35,7 @@
@if (!Auth::check() || Auth::user()->showGreyBackground())
body {
background-color: #EEEEEE;
background-color: #F6F6F6;
}
@endif

View File

@ -5,7 +5,7 @@
<p>&nbsp;</p>
{{ Former::open($url)->method($method)->addClass('main_form')->rules(array(
'invoice_number' => 'required',
'invoice_number' => 'required',
'invoice_date' => 'required',
'product_key' => 'max:14',
)); }}
@ -15,8 +15,8 @@
@if ($invoice)
{{ Former::populate($invoice); }}
{{ Former::populateField('id', $invoice->public_id); }}
{{ Former::populateField('invoice_date', fromSqlDate($invoice->invoice_date)); }}
{{ Former::populateField('due_date', fromSqlDate($invoice->due_date)); }}
{{ Former::populateField('invoice_date', Utils::fromSqlDate($invoice->invoice_date)); }}
{{ Former::populateField('due_date', Utils::fromSqlDate($invoice->due_date)); }}
@else
{{ Former::populateField('invoice_number', $invoiceNumber) }}
{{ Former::populateField('invoice_date', date('m/d/Y')) }}

View File

@ -0,0 +1,76 @@
@extends('master')
@section('head')
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee !important;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin .checkbox {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>
@stop
@section('body')
<div class="container">
{{ Former::open('forgot_password')->addClass('form-signin') }}
<h2 class="form-signin-heading">Passord Recovery</h2>
<p>
{{ Form::text('email', Input::old('email'), array('placeholder' => 'Email address')) }}
</p>
<p>{{ Button::primary_submit('Send email', array('class' => 'btn-lg'))->block() }}</p>
<!-- if there are login errors, show them here -->
@if ( Session::get('error') )
<div class="alert alert-error">{{{ Session::get('error') }}}</div>
@endif
@if ( Session::get('notice') )
<div class="alert">{{{ Session::get('notice') }}}</div>
@endif
{{ Former::close() }}
</div>
@stop

View File

@ -1,20 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">
@extends('master')
<title></title>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
@section('head')
<style type="text/css">
body {
@ -59,18 +45,12 @@
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js" type="text/javascript"></script>
{{ Basset::show('bootstrapper.css') }}
{{ Basset::show('bootstrapper.js') }}
</head>
<body>
@stop
@section('body')
<div class="container">
{{ Form::open(array('url' => 'login', 'class' => 'form-signin')) }}
{{ Former::open('login')->addClass('form-signin') }}
<h2 class="form-signin-heading">Please sign in</h2>
<p>
@ -85,8 +65,8 @@
<p>{{ Button::primary_submit('Sign In', array('class' => 'btn-lg'))->block() }}</p>
{{ link_to('user/forgot_password', 'Recover your password') }}
{{ link_to('forgot_password', 'Recover your password') }}
<!-- if there are login errors, show them here -->
@if ( Session::get('error') )
<div class="alert alert-error">{{{ Session::get('error') }}}</div>
@ -97,12 +77,8 @@
@endif
{{ Form::close() }}
{{ Former::close() }}
</div>
</body>
</html>
@stop

View File

@ -29,6 +29,7 @@ $app->redirectIfTrailingSlash();
$env = $app->detectEnvironment(array(
'local' => array('precise64'),
'staging' => array('host107.hostmonster.com')
));

View File

@ -22,7 +22,8 @@
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
"app/tests/TestCase.php",
"app/libraries"
]
},
"scripts": {

View File

@ -93,6 +93,7 @@
this.$element.attr('class', this.$source.attr('class'));
this.$element.attr('tabindex', this.$source.attr('tabindex'));
this.$source.removeAttr('tabindex');
this.$source.removeAttr('required');
}
, select: function () {