Merge pull request #288 from hillelcoren/laravel-5

Laravel 5 Into Master
This commit is contained in:
Jeramy 2015-04-06 17:06:48 +10:00
commit 75e3d080a0
1195 changed files with 20730 additions and 193579 deletions

View File

@ -1,3 +0,0 @@
{
"directory": "./public/vendor"
}

17
.env.example Normal file
View File

@ -0,0 +1,17 @@
APP_ENV=development
APP_DEBUG=true
APP_KEY=
DB_TYPE=mysql
DB_HOST=localhost
DB_DATABASE=ninja
DB_USERNAME=
DB_PASSWORD=
MAIL_DRIVER=smtp
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_HOST=
MAIL_USERNAME=
MAIL_FROM_NAME=
MAIL_PASSWORD=

4
.gitattributes vendored
View File

@ -1 +1,3 @@
* text=auto * text=auto
*.css linguist-vendored
*.less linguist-vendored

24
.gitignore vendored
View File

@ -1,10 +1,9 @@
/app/config/staging /config/staging
/app/config/development /config/development
/app/config/production /config/production
/app/config/fortrabbit /config/fortrabbit
/app/config/ubuntu /config/ubuntu
/app/config/packages/anahkiasen/rocketeer/ /config/packages/anahkiasen/rocketeer/
/app/storage
/public/logo /public/logo
/public/build /public/build
/public/packages /public/packages
@ -12,13 +11,16 @@
/bootstrap/compiled.php /bootstrap/compiled.php
/bootstrap/environment.php /bootstrap/environment.php
/vendor /vendor
/node_modules
.env
/.DS_Store /.DS_Store
/Thumbs.db /Thumbs.db
/ninja.sublime-project
/ninja.sublime-workspace
/tests/_log
.env.development.php .env.development.php
.env.php .env.php
.idea .idea
.project .project
/nbproject/private/ error_log
public/error_log
/ninja.sublime-project
/ninja.sublime-workspace
auth.json

View File

@ -1,124 +0,0 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
process: function(src, filepath) {
var basepath = filepath.substring(7, filepath.lastIndexOf('/') + 1);
// Fix relative paths for css files
if(filepath.indexOf('.css', filepath.length - 4) !== -1) {
return src.replace(/(url\s*[\("']+)\s*([^'"\)]+)(['"\)]+;?)/gi, function(match, start, url, end, offset, string) {
if(url.indexOf('data:') === 0) {
// Skip data urls
return match;
} else if(url.indexOf('/') === 0) {
// Skip absolute urls
return match;
} else {
return start + basepath + url + end;
}
});
// Fix source maps locations
} else if(filepath.indexOf('.js', filepath.length - 4) !== -1) {
return src.replace(/(\/[*\/][#@]\s*sourceMappingURL=)([^\s]+)/gi, function(match, start, url, offset, string) {
if(url.indexOf('/') === 0) {
// Skip absolute urls
return match;
} else {
return start + basepath + url;
}
});
// Don't do anything for unknown file types
} else {
return src;
}
},
},
js: {
src: [
'public/vendor/jquery/dist/jquery.js',
'public/vendor/jquery-ui/jquery-ui.min.js',
'public/vendor/bootstrap/dist/js/bootstrap.min.js',
'public/vendor/datatables/media/js/jquery.dataTables.js',
'public/vendor/datatables-bootstrap3/BS3/assets/js/datatables.js',
'public/vendor/knockout.js/knockout.js',
'public/vendor/knockout-mapping/build/output/knockout.mapping-latest.js',
'public/vendor/knockout-sortable/build/knockout-sortable.min.js',
'public/vendor/underscore/underscore.js',
'public/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js',
'public/vendor/typeahead.js/dist/typeahead.min.js',
'public/vendor/accounting/accounting.min.js',
'public/vendor/spectrum/spectrum.js',
'public/vendor/jspdf/dist/jspdf.min.js',
//'public/vendor/handsontable/dist/jquery.handsontable.full.min.js',
'public/js/lightbox.min.js',
'public/js/bootstrap-combobox.js',
'public/js/script.js',
],
dest: 'public/built.js',
nonull: true
},
js_public: {
src: [
/*
'public/js/simpleexpand.js',
'public/js/valign.js',
'public/js/bootstrap.min.js',
'public/js/simpleexpand.js',
*/
'public/vendor/bootstrap/dist/js/bootstrap.min.js',
],
dest: 'public/js/built.public.js',
nonull: true
},
css: {
src: [
'public/vendor/bootstrap/dist/css/bootstrap.min.css',
'public/vendor/datatables/media/css/jquery.dataTables.css',
'public/vendor/datatables-bootstrap3/BS3/assets/css/datatables.css',
'public/vendor/font-awesome/css/font-awesome.min.css',
'public/vendor/bootstrap-datepicker/css/datepicker.css',
'public/vendor/spectrum/spectrum.css',
'public/css/bootstrap-combobox.css',
'public/css/typeahead.js-bootstrap.css',
'public/css/lightbox.css',
//'public/vendor/handsontable/dist/jquery.handsontable.full.css',
'public/css/style.css',
],
dest: 'public/built.css',
nonull: true,
options: {
process: false
}
},
css_public: {
src: [
'public/vendor/bootstrap/dist/css/bootstrap.min.css',
/*
'public/css/bootstrap.splash.css',
'public/css/splash.css',
*/
'public/vendor/datatables/media/css/jquery.dataTables.css',
'public/vendor/datatables-bootstrap3/BS3/assets/css/datatables.css',
],
dest: 'public/built.public.css',
nonull: true,
options: {
process: false
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('default', ['concat']);
};

40
LICENSE
View File

@ -1,40 +0,0 @@
Attribution Assurance License
Copyright (c) 2014 by Hillel Coren
http://www.hillelcoren.com
All Rights Reserved
ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the conditions below are met.
These conditions require a modest attribution to InvoiceNinja.com. The hope
is that its promotional value may help justify the thousands of dollars in
otherwise billable time invested in writing this and other freely available,
open-source software.
1. Redistributions of source code, in whole or part and with or without
modification requires the express permission of the author and must prominently
display "Powered by InvoiceNinja" or the Invoice Ninja logo in verifiable form
with hyperlink to said site.
2. Neither the name nor any trademark of the Author may be used to
endorse or promote products derived from this software without specific
prior written permission.
3. Users are entirely responsible, to the exclusion of the Author and
any other persons, for compliance with (1) regulations set by owners or
administrators of employed equipment, (2) licensing terms of any other
software, and (3) local regulations regarding use, including those
regarding import, export, and use of encryption software.
THIS FREE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR OR ANY CONTRIBUTOR BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
EFFECTS OF UNAUTHORIZED OR MALICIOUS NETWORK ACCESS;
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

7
app/Commands/Command.php Normal file
View File

@ -0,0 +1,7 @@
<?php namespace App\Commands;
abstract class Command {
//
}

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -0,0 +1,32 @@
<?php namespace InvoiceNinja\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
class Inspire extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'inspire';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
}
}

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -1,9 +1,9 @@
<?php <?php namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use ninja\mailers\ContactMailer as Mailer; use App\Ninja\Mailers\ContactMailer as Mailer;
class SendRecurringInvoices extends Command class SendRecurringInvoices extends Command
{ {

33
app/Console/Kernel.php Normal file
View File

@ -0,0 +1,33 @@
<?php namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\SendRecurringInvoices',
'App\Console\Commands\CreateRandomData',
'App\Console\Commands\ResetData',
'App\Console\Commands\ImportTimesheetData',
'App\Console\Commands\CheckData',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
}

7
app/Events/Event.php Normal file
View File

@ -0,0 +1,7 @@
<?php namespace App\Events;
abstract class Event {
//
}

View File

@ -0,0 +1,23 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class InvoicePaid extends Event {
use SerializesModels;
public $payment;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($payment)
{
$this->payment = $payment;
}
}

View File

@ -0,0 +1,23 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class InvoiceSent extends Event {
use SerializesModels;
public $invoice;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
}
}

View File

@ -0,0 +1,23 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class InvoiceViewed extends Event {
use SerializesModels;
public $invoice;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
}
}

View File

@ -0,0 +1,21 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class UserLoggedIn extends Event {
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -0,0 +1,21 @@
<?php namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
class UserSettingsChanged extends Event {
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -0,0 +1,42 @@
<?php namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler {
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
return parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
return parent::render($request, $e);
}
}

View File

View File

View File

@ -1,7 +1,7 @@
<?php <?php namespace App\Handlers;
use ninja\mailers\UserMailer; use App\Ninja\Mailers\UserMailer;
use ninja\mailers\ContactMailer; use App\Ninja\Mailers\ContactMailer;
class InvoiceEventHandler class InvoiceEventHandler
{ {

View File

@ -1,10 +1,36 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\AccountRepository; use Auth;
use ninja\mailers\UserMailer; use Event;
use ninja\mailers\ContactMailer; use File;
use Image;
use Input;
use Redirect;
use Session;
use Utils;
use Validator;
use View;
use stdClass;
class AccountController extends \BaseController use App\Models\User;
use App\Models\Activity;
use App\Models\Account;
use App\Models\Country;
use App\Models\Currency;
use App\Models\DateFormat;
use App\Models\DatetimeFormat;
use App\Models\Language;
use App\Models\Size;
use App\Models\Timezone;
use App\Models\Industry;
use App\Models\InvoiceDesign;
use App\Ninja\Repositories\AccountRepository;
use App\Ninja\Mailers\UserMailer;
use App\Ninja\Mailers\ContactMailer;
use App\Events\UserLoggedIn;
use App\Events\UserSettingsChanged;
class AccountController extends BaseController
{ {
protected $accountRepo; protected $accountRepo;
protected $userMailer; protected $userMailer;
@ -62,7 +88,7 @@ class AccountController extends \BaseController
} }
Auth::login($user, true); Auth::login($user, true);
Event::fire('user.login'); Event::fire(new UserLoggedIn());
return Redirect::to('invoices/create')->with('sign_up', Input::get('sign_up')); return Redirect::to('invoices/create')->with('sign_up', Input::get('sign_up'));
} }
@ -103,6 +129,7 @@ class AccountController extends \BaseController
public function showSection($section = ACCOUNT_DETAILS, $subSection = false) public function showSection($section = ACCOUNT_DETAILS, $subSection = false)
{ {
if ($section == ACCOUNT_DETAILS) { if ($section == ACCOUNT_DETAILS) {
/* Update Remember Function
$data = [ $data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
@ -115,6 +142,19 @@ class AccountController extends \BaseController
'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id, 'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
]; ];
*/
$data = [
'account' => Account::with('users')->findOrFail(Auth::user()->account_id),
'countries' => Country::orderBy('name')->get(),
'sizes' => Size::orderBy('id')->get(),
'industries' => Industry::orderBy('name')->get(),
'timezones' => Timezone::orderBy('location')->get(),
'dateFormats' => DateFormat::get(),
'datetimeFormats' => DatetimeFormat::get(),
'currencies' => Currency::orderBy('name')->get(),
'languages' => Language::orderBy('name')->get(),
'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id,
];
return View::make('accounts.details', $data); return View::make('accounts.details', $data);
} elseif ($section == ACCOUNT_PAYMENTS) { } elseif ($section == ACCOUNT_PAYMENTS) {
@ -170,8 +210,9 @@ class AccountController extends \BaseController
$invoice->invoice_items = [$invoiceItem]; $invoice->invoice_items = [$invoiceItem];
$data['invoice'] = $invoice; $data['invoice'] = $invoice;
$data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId()) //$data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_'.Auth::user()->maxInvoiceDesignId())
->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(); // ->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
$data['invoiceDesigns'] = InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
} else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) { } else if ($subSection == ACCOUNT_EMAIL_TEMPLATES) {
$data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE); $data['invoiceEmail'] = $account->getEmailTemplate(ENTITY_INVOICE);
$data['quoteEmail'] = $account->getEmailTemplate(ENTITY_QUOTE); $data['quoteEmail'] = $account->getEmailTemplate(ENTITY_QUOTE);
@ -263,7 +304,7 @@ class AccountController extends \BaseController
$account->invoice_number_counter = Input::get('invoice_number_counter'); $account->invoice_number_counter = Input::get('invoice_number_counter');
$account->quote_number_prefix = Input::get('quote_number_prefix'); $account->quote_number_prefix = Input::get('quote_number_prefix');
$account->share_counter = Input::get('share_counter') ? true : false; $account->share_counter = Input::get('share_counter') ? true : false;
$account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false; $account->pdf_email_attachment = Input::get('pdf_email_attachment') ? true : false;
if (!$account->share_counter) { if (!$account->share_counter) {
@ -426,7 +467,7 @@ class AccountController extends \BaseController
$name = $file->getRealPath(); $name = $file->getRealPath();
require_once app_path().'/includes/parsecsv.lib.php'; require_once app_path().'/Includes/parsecsv.lib.php';
$csv = new parseCSV(); $csv = new parseCSV();
$csv->heading = false; $csv->heading = false;
$csv->auto($name); $csv->auto($name);
@ -591,19 +632,18 @@ class AccountController extends \BaseController
$image = Image::make($path); $image = Image::make($path);
$mimeType = $file->getMimeType(); $mimeType = $file->getMimeType();
if ($image->width == 200 && $mimeType == 'image/jpeg') { if ($image->width() == 200 && $mimeType == 'image/jpeg') {
$file->move('logo/', $account->account_key . '.jpg'); $file->move('logo/', $account->account_key . '.jpg');
} else { } else {
$image->resize(200, 120, true, false); $image->resize(200, 120, function ($constraint) {
Image::canvas($image->width, $image->height, '#FFFFFF')->insert($image)->save($account->getLogoPath()); $constraint->aspectRatio();
});
Image::canvas($image->width(), $image->height(), '#FFFFFF')->insert($image)->save($account->getLogoPath());
} }
//$image = Image::make($path)->resize(200, 120, true, false);
//Image::canvas($image->width, $image->height, '#FFFFFF')->insert($image)->save($account->getLogoPath());
} }
Event::fire('user.refresh'); Event::fire(new UserSettingsChanged());
Session::flash('message', trans('texts.updated_settings')); Session::flash('message', trans('texts.updated_settings'));
return Redirect::to('company/details'); return Redirect::to('company/details');
@ -651,9 +691,8 @@ class AccountController extends \BaseController
$user->email = trim(strtolower(Input::get('new_email'))); $user->email = trim(strtolower(Input::get('new_email')));
$user->username = $user->email; $user->username = $user->email;
$user->password = trim(Input::get('new_password')); $user->password = trim(Input::get('new_password'));
$user->password_confirmation = trim(Input::get('new_password'));
$user->registered = true; $user->registered = true;
$user->amend(); $user->save();
if (Utils::isNinja()) { if (Utils::isNinja()) {
$this->userMailer->sendConfirmation($user); $this->userMailer->sendConfirmation($user);
@ -710,7 +749,7 @@ class AccountController extends \BaseController
$account = Auth::user()->account; $account = Auth::user()->account;
$account->forceDelete(); $account->forceDelete();
Confide::logout(); Auth::logout();
return Redirect::to('/')->with('clearGuestKey', true); return Redirect::to('/')->with('clearGuestKey', true);
} }

View File

@ -1,24 +1,30 @@
<?php <?php namespace App\Http\Controllers;
/*
|--------------------------------------------------------------------------
| Confide Controller Template
|--------------------------------------------------------------------------
|
| This is the default Confide controller template for controlling user
| authentication. Feel free to change to your needs.
|
*/
use ninja\repositories\AccountRepository; use Auth;
use Datatable;
use DB;
use Input;
use Redirect;
use Session;
use View;
use Validator;
use stdClass;
use URL;
use App\Models\Gateway;
use App\Models\Account;
use App\Models\AccountGateway;
use App\Ninja\Repositories\AccountRepository;
class AccountGatewayController extends BaseController class AccountGatewayController extends BaseController
{ {
public function getDatatable() public function getDatatable()
{ {
$query = \DB::table('account_gateways') $query = DB::table('account_gateways')
->join('gateways', 'gateways.id', '=', 'account_gateways.gateway_id') ->join('gateways', 'gateways.id', '=', 'account_gateways.gateway_id')
->where('account_gateways.deleted_at', '=', null) ->where('account_gateways.deleted_at', '=', null)
->where('account_gateways.account_id', '=', \Auth::user()->account_id) ->where('account_gateways.account_id', '=', Auth::user()->account_id)
->select('account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at'); ->select('account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at');
return Datatable::query($query) return Datatable::query($query)
@ -95,8 +101,9 @@ class AccountGatewayController extends BaseController
$selectedCards = $accountGateway ? $accountGateway->accepted_credit_cards : 0; $selectedCards = $accountGateway ? $accountGateway->accepted_credit_cards : 0;
$account = Auth::user()->account; $account = Auth::user()->account;
$recommendedGateways = Gateway::remember(DEFAULT_QUERY_CACHE) // $recommendedGateways = Gateway::remember(DEFAULT_QUERY_CACHE)
->where('recommended', '=', '1') // ->where('recommended', '=', '1')
$recommendedGateways = Gateway::where('recommended', '=', '1')
->orderBy('sort_order') ->orderBy('sort_order')
->get(); ->get();
$recommendedGatewayArray = array(); $recommendedGatewayArray = array();

View File

@ -1,6 +1,11 @@
<?php <?php namespace App\Http\Controllers;
class ActivityController extends \BaseController use Auth;
use DB;
use Datatable;
use Utils;
class ActivityController extends BaseController
{ {
public function getDatatable($clientPublicId) public function getDatatable($clientPublicId)
{ {

View File

@ -1,7 +1,18 @@
<?php <?php namespace App\Http\Controllers;
use ninja\mailers\Mailer; use Auth;
use ninja\repositories\AccountRepository; use Artisan;
use Cache;
use Config;
use DB;
use Exception;
use Input;
use Utils;
use View;
use App\Models\User;
use App\Ninja\Mailers\Mailer;
use App\Ninja\Repositories\AccountRepository;
use Redirect;
class AppController extends BaseController class AppController extends BaseController
{ {
@ -36,12 +47,10 @@ class AppController extends BaseController
$app = Input::get('app'); $app = Input::get('app');
$app['key'] = str_random(RANDOM_KEY_LENGTH); $app['key'] = str_random(RANDOM_KEY_LENGTH);
$app['debug'] = false;
$database = Input::get('database'); $database = Input::get('database');
$dbType = $database['default']; $dbType = $database['default'];
$database['connections'] = [$dbType => $database['type']]; $database['connections'] = [$dbType => $database['type']];
unset($database['type']);
$mail = Input::get('mail'); $mail = Input::get('mail');
$email = $mail['username']; $email = $mail['username'];
@ -58,43 +67,44 @@ class AppController extends BaseController
} elseif (!$valid) { } elseif (!$valid) {
return Redirect::to('/setup')->withInput(); return Redirect::to('/setup')->withInput();
} }
// == ENV Settings (Production) == //
$config = "APP_ENV=development\n".
"APP_DEBUG=true\n".
"APP_KEY={$app['key']}\n\n".
"DB_TYPE={$dbType}\n".
"DB_HOST={$database['type']['host']}\n".
"DB_DATABASE={$database['type']['database']}\n".
"DB_USERNAME={$database['type']['username']}\n".
"DB_PASSWORD={$database['type']['password']}\n\n".
"MAIL_DRIVER={$mail['driver']}\n".
"MAIL_PORT={$mail['port']}\n".
"MAIL_ENCRYPTION={$mail['encryption']}\n".
"MAIL_HOST={$mail['host']}\n".
"MAIL_USERNAME={$mail['username']}\n".
"MAIL_FROM_NAME={$mail['from']['name']}\n".
"MAIL_PASSWORD={$mail['password']}\n";
$content = "<?php return 'production';"; // Write Config Settings
$fp = fopen(base_path()."/bootstrap/environment.php", 'w'); $fp = fopen(base_path()."/.env", 'w');
fwrite($fp, $content); fwrite($fp, $config);
fclose($fp); fclose($fp);
$configDir = app_path().'/config/production'; // == DB Migrate & Seed == //
if (!file_exists($configDir)) { // Artisan::call('migrate:rollback', array('--force' => true)); // Debug Purposes
mkdir($configDir); Artisan::call('migrate', array('--force' => true));
} Artisan::call('db:seed', array('--force' => true));
foreach (['app' => $app, 'database' => $database, 'mail' => $mail] as $key => $config) { $firstName = trim(Input::get('first_name'));
$content = '<?php return '.var_export($config, true).';'; $lastName = trim(Input::get('last_name'));
$fp = fopen(app_path()."/config/production/{$key}.php", 'w'); $email = trim(strtolower(Input::get('email')));
fwrite($fp, $content); $password = trim(Input::get('password'));
fclose($fp); $account = $this->accountRepo->create($firstName, $lastName, $email, $password);
}
Artisan::call('migrate');
Artisan::call('db:seed');
$account = $this->accountRepo->create();
$user = $account->users()->first(); $user = $account->users()->first();
$user->first_name = trim(Input::get('first_name'));
$user->last_name = trim(Input::get('last_name'));
$user->email = trim(strtolower(Input::get('email')));
$user->username = $user->email;
$user->password = trim(Input::get('password'));
$user->password_confirmation = trim(Input::get('password'));
$user->registered = true;
$user->amend();
//Auth::login($user, true); //Auth::login($user, true);
$this->accountRepo->registerUser($user);
return Redirect::to('/invoices/create'); return Redirect::to('/login');
} }
private function testDatabase($database) private function testDatabase($database)
@ -102,7 +112,7 @@ class AppController extends BaseController
$dbType = $database['default']; $dbType = $database['default'];
Config::set('database.default', $dbType); Config::set('database.default', $dbType);
foreach ($database['connections'][$dbType] as $key => $val) { foreach ($database['connections'][$dbType] as $key => $val) {
Config::set("database.connections.{$dbType}.{$key}", $val); Config::set("database.connections.{$dbType}.{$key}", $val);
} }
@ -145,8 +155,8 @@ class AppController extends BaseController
{ {
if (!Utils::isNinja() && !Utils::isDatabaseSetup()) { if (!Utils::isNinja() && !Utils::isDatabaseSetup()) {
try { try {
Artisan::call('migrate'); Artisan::call('migrate', array('--force' => true));
Artisan::call('db:seed'); Artisan::call('db:seed', array('--force' => true));
} catch (Exception $e) { } catch (Exception $e) {
Response::make($e->getMessage(), 500); Response::make($e->getMessage(), 500);
} }
@ -159,7 +169,7 @@ class AppController extends BaseController
{ {
if (!Utils::isNinja()) { if (!Utils::isNinja()) {
try { try {
Artisan::call('migrate'); Artisan::call('migrate', array('--force' => true));
Cache::flush(); Cache::flush();
} catch (Exception $e) { } catch (Exception $e) {
Response::make($e->getMessage(), 500); Response::make($e->getMessage(), 500);

View File

@ -0,0 +1,57 @@
<?php namespace App\Http\Controllers\Auth;
use Auth;
use Event;
use Illuminate\Http\Request;
use App\Events\UserLoggedIn;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller {
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers;
protected $loginPath = '/login';
protected $redirectTo = '/dashboard';
/**
* Create a new authentication controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
* @param \Illuminate\Contracts\Auth\Registrar $registrar
* @return void
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => 'getLogout']);
}
public function postLoginWrapper(Request $request)
{
$response = self::postLogin($request);
if (Auth::check()) {
Event::fire(new UserLoggedIn());
}
return $response;
}
}

View File

@ -0,0 +1,40 @@
<?php namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller {
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
protected $redirectTo = '/dashboard';
/**
* Create a new password controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
* @param \Illuminate\Contracts\Auth\PasswordBroker $passwords
* @return void
*/
public function __construct(Guard $auth, PasswordBroker $passwords)
{
$this->auth = $auth;
$this->passwords = $passwords;
$this->middleware('guest');
}
}

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Http\Controllers;
class BaseController extends Controller class BaseController extends Controller
{ {

View File

@ -1,6 +1,6 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\ClientRepository; use App\Ninja\Repositories\ClientRepository;
class ClientApiController extends Controller class ClientApiController extends Controller
{ {

View File

@ -1,8 +1,28 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\ClientRepository; use Auth;
use Datatable;
use Utils;
use View;
use URL;
use Validator;
use Input;
use Session;
use Redirect;
class ClientController extends \BaseController use App\Models\Activity;
use App\Models\Client;
use App\Models\Contact;
use App\Models\Invoice;
use App\Models\Size;
use App\Models\PaymentTerm;
use App\Models\Industry;
use App\Models\Currency;
use App\Models\Country;
use App\Ninja\Repositories\ClientRepository;
class ClientController extends BaseController
{ {
protected $clientRepo; protected $clientRepo;
@ -90,13 +110,13 @@ class ClientController extends \BaseController
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT); Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT);
$actionLinks = [ $actionLinks = [
[trans('texts.create_invoice'), URL::to('invoices/create/'.$client->public_id)], ['label' => trans('texts.create_invoice'), 'url' => URL::to('invoices/create/'.$client->public_id)],
[trans('texts.enter_payment'), URL::to('payments/create/'.$client->public_id)], ['label' => trans('texts.enter_payment'), 'url' => URL::to('payments/create/'.$client->public_id)],
[trans('texts.enter_credit'), URL::to('credits/create/'.$client->public_id)], ['label' => trans('texts.enter_credit'), 'url' => URL::to('credits/create/'.$client->public_id)],
]; ];
if (Utils::isPro()) { if (Utils::isPro()) {
array_unshift($actionLinks, [trans('texts.create_quote'), URL::to('quotes/create/'.$client->public_id)]); array_unshift($actionLinks, ['label' => trans('texts.create_quote'), 'url' => URL::to('quotes/create/'.$client->public_id)]);
} }
$data = array( $data = array(
@ -158,6 +178,7 @@ class ClientController extends \BaseController
private static function getViewModel() private static function getViewModel()
{ {
/* Remember function no longer works
return [ return [
'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']),
@ -167,6 +188,16 @@ class ClientController extends \BaseController
'customLabel1' => Auth::user()->account->custom_client_label1, 'customLabel1' => Auth::user()->account->custom_client_label1,
'customLabel2' => Auth::user()->account->custom_client_label2, 'customLabel2' => Auth::user()->account->custom_client_label2,
]; ];
*/
return [
'sizes' => Size::orderBy('id')->get(),
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::orderBy('name')->get(),
'currencies' => Currency::orderBy('name')->get(),
'countries' => Country::orderBy('name')->get(),
'customLabel1' => Auth::user()->account->custom_client_label1,
'customLabel2' => Auth::user()->account->custom_client_label2,
];
} }
/** /**

View File

@ -0,0 +1,11 @@
<?php namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
abstract class Controller extends BaseController {
use DispatchesCommands, ValidatesRequests;
}

View File

@ -1,8 +1,18 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\CreditRepository; use Datatable;
use Input;
use Redirect;
use Session;
use Utils;
use View;
use Validator;
class CreditController extends \BaseController use App\Models\Client;
use App\Ninja\Repositories\CreditRepository;
class CreditController extends BaseController
{ {
protected $creditRepo; protected $creditRepo;

View File

@ -1,6 +1,12 @@
<?php <?php namespace App\Http\Controllers;
class DashboardController extends \BaseController use Auth;
use DB;
use View;
use App\Models\Activity;
use App\Models\Invoice;
class DashboardController extends BaseController
{ {
public function index() public function index()
{ {

View File

@ -1,6 +1,12 @@
<?php <?php namespace App\Http\Controllers;
use ninja\mailers\Mailer; use App\Libraries\Utils;
use App\Ninja\Mailers\Mailer;
use Redirect;
use App\Models\Account;
use Auth;
use View;
use Input;
class HomeController extends BaseController class HomeController extends BaseController
{ {

View File

@ -1,4 +1,6 @@
<?php <?php namespace App\Http\Controllers;
use Utils;
class IntegrationController extends Controller class IntegrationController extends Controller
{ {

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\InvoiceRepository; use Utils;
use ninja\mailers\ContactMailer as Mailer; use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Mailers\ContactMailer as Mailer;
class InvoiceApiController extends Controller class InvoiceApiController extends Controller
{ {

View File

@ -1,11 +1,38 @@
<?php <?php namespace App\Http\Controllers;
use ninja\mailers\ContactMailer as Mailer; use Auth;
use ninja\repositories\InvoiceRepository; use Session;
use ninja\repositories\ClientRepository; use Utils;
use ninja\repositories\TaxRateRepository; use View;
use Input;
use Cache;
use Redirect;
use DB;
use Event;
use URL;
class InvoiceController extends \BaseController use App\Models\Invoice;
use App\Models\Invitation;
use App\Models\Client;
use App\Models\Account;
use App\Models\Product;
use App\Models\Country;
use App\Models\TaxRate;
use App\Models\Currency;
use App\Models\Size;
use App\Models\Industry;
use App\Models\PaymentTerm;
use App\Models\InvoiceDesign;
use App\Models\AccountGateway;
use App\Models\Activity;
use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\ClientRepository;
use App\Ninja\Repositories\TaxRateRepository;
use App\Events\InvoiceViewed;
class InvoiceController extends BaseController
{ {
protected $mailer; protected $mailer;
protected $invoiceRepo; protected $invoiceRepo;
@ -156,7 +183,7 @@ class InvoiceController extends \BaseController
if (!Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) { if (!Session::has($invitationKey) && (!Auth::check() || Auth::user()->account_id != $invoice->account_id)) {
Activity::viewInvoice($invitation); Activity::viewInvoice($invitation);
Event::fire('invoice.viewed', $invoice); Event::fire(new InvoiceViewed($invoice));
} }
Session::set($invitationKey, true); Session::set($invitationKey, true);
@ -294,6 +321,7 @@ class InvoiceController extends \BaseController
} }
} }
/*
return [ return [
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
@ -317,6 +345,31 @@ class InvoiceController extends \BaseController
), ),
'recurringHelp' => $recurringHelp 'recurringHelp' => $recurringHelp
]; ];
*/
return [
'account' => Auth::user()->account,
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
'countries' => Country::orderBy('name')->get(),
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
'currencies' => Cache::get('currencies'),
'sizes' => Size::orderBy('id')->get(),
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::orderBy('name')->get(),
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
'frequencies' => array(
1 => 'Weekly',
2 => 'Two weeks',
3 => 'Four weeks',
4 => 'Monthly',
5 => 'Three months',
6 => 'Six months',
7 => 'Annually',
),
'recurringHelp' => $recurringHelp
];
} }
/** /**
@ -396,11 +449,13 @@ class InvoiceController extends \BaseController
$url = URL::to('clients/'.$client->public_id); $url = URL::to('clients/'.$client->public_id);
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url); Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url);
} }
/*
This causes an error message. Commenting out. will return later.
if (!empty(Input::get('pdfupload')) && strpos(Input::get('pdfupload'), 'data:application/pdf;base64,') === 0) { if (!empty(Input::get('pdfupload')) && strpos(Input::get('pdfupload'), 'data:application/pdf;base64,') === 0) {
$this->storePDF(Input::get('pdfupload'), $invoice->id); $this->storePDF(Input::get('pdfupload'), $invoice->id);
} }
*/
if ($action == 'clone') { if ($action == 'clone') {
return $this->cloneInvoice($publicId); return $this->cloneInvoice($publicId);
} elseif ($action == 'convert') { } elseif ($action == 'convert') {

View File

@ -1,6 +1,7 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\PaymentRepository; use Utils;
use App\Ninja\Repositories\PaymentRepository;
class PaymentApiController extends Controller class PaymentApiController extends Controller
{ {

View File

@ -1,11 +1,29 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\PaymentRepository; use Datatable;
use ninja\repositories\InvoiceRepository; use Input;
use ninja\repositories\AccountRepository; use Redirect;
use ninja\mailers\ContactMailer; use Session;
use Utils;
use View;
use Validator;
use Omnipay;
use CreditCard;
use URL;
class PaymentController extends \BaseController use App\Models\Invoice;
use App\Models\Invitation;
use App\Models\Client;
use App\Models\PaymentType;
use App\Models\Country;
use App\Ninja\Repositories\PaymentRepository;
use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\AccountRepository;
use App\Ninja\Mailers\ContactMailer;
use App\Events\InvoicePaid;
class PaymentController extends BaseController
{ {
protected $creditRepo; protected $creditRepo;
@ -133,8 +151,8 @@ class PaymentController extends \BaseController
'method' => 'POST', 'method' => 'POST',
'url' => "payments", 'url' => "payments",
'title' => trans('texts.new_payment'), 'title' => trans('texts.new_payment'),
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), //'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTypes' => PaymentType::orderBy('id')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
return View::make('payments.edit', $data); return View::make('payments.edit', $data);
@ -154,8 +172,8 @@ class PaymentController extends \BaseController
'method' => 'PUT', 'method' => 'PUT',
'url' => 'payments/'.$publicId, 'url' => 'payments/'.$publicId,
'title' => trans('texts.edit_payment'), 'title' => trans('texts.edit_payment'),
//'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), //'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(),
'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTypes' => PaymentType::orderBy('id')->get(),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), ); 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), );
return View::make('payments.edit', $data); return View::make('payments.edit', $data);
@ -350,7 +368,8 @@ class PaymentController extends \BaseController
'paymentLibrary' => $paymentLibrary, 'paymentLibrary' => $paymentLibrary,
'gateway' => $gateway, 'gateway' => $gateway,
'acceptedCreditCardTypes' => $acceptedCreditCardTypes, 'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), //'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'countries' => Country::orderBy('name')->get(),
'currencyId' => $client->currency_id, 'currencyId' => $client->currency_id,
'account' => $client->account 'account' => $client->account
]; ];
@ -399,7 +418,8 @@ class PaymentController extends \BaseController
'paymentLibrary' => $paymentLibrary, 'paymentLibrary' => $paymentLibrary,
'gateway' => $gateway, 'gateway' => $gateway,
'acceptedCreditCardTypes' => $acceptedCreditCardTypes, 'acceptedCreditCardTypes' => $acceptedCreditCardTypes,
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), //'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
'countries' => Country::orderBy('name')->get(),
'currencyId' => 1, 'currencyId' => 1,
'paymentTitle' => $affiliate->payment_title, 'paymentTitle' => $affiliate->payment_title,
'paymentSubtitle' => $affiliate->payment_subtitle, 'paymentSubtitle' => $affiliate->payment_subtitle,
@ -658,7 +678,7 @@ class PaymentController extends \BaseController
$payment->save(); $payment->save();
Event::fire('invoice.paid', $payment); Event::fire(new InvoicePaid($payment));
return $payment; return $payment;
} }

View File

@ -1,6 +1,13 @@
<?php <?php namespace App\Http\Controllers;
class ProductController extends \BaseController use Auth;
use Str;
use DB;
use Datatable;
use Utils;
use URL;
class ProductController extends BaseController
{ {
public function getDatatable() public function getDatatable()
{ {

View File

@ -1,6 +1,7 @@
<?php <?php namespace App\Http\Controllers;
use ninja\repositories\InvoiceRepository; use Utils;
use App\Ninja\Repositories\InvoiceRepository;
class QuoteApiController extends Controller class QuoteApiController extends Controller
{ {

View File

@ -1,11 +1,27 @@
<?php <?php namespace App\Http\Controllers;
use ninja\mailers\ContactMailer as Mailer; use Auth;
use ninja\repositories\InvoiceRepository; use Input;
use ninja\repositories\ClientRepository; use Redirect;
use ninja\repositories\TaxRateRepository; use Utils;
use View;
class QuoteController extends \BaseController use App\Models\Account;
use App\Models\Client;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Industry;
use App\Models\InvoiceDesign;
use App\Models\PaymentTerm;
use App\Models\Product;
use App\Models\Size;
use App\Models\TaxRate;
use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\ClientRepository;
use App\Ninja\Repositories\TaxRateRepository;
class QuoteController extends BaseController
{ {
protected $mailer; protected $mailer;
protected $invoiceRepo; protected $invoiceRepo;
@ -123,6 +139,7 @@ class QuoteController extends \BaseController
private static function getViewModel() private static function getViewModel()
{ {
/*
return [ return [
'entityType' => ENTITY_QUOTE, 'entityType' => ENTITY_QUOTE,
'account' => Auth::user()->account, 'account' => Auth::user()->account,
@ -138,6 +155,22 @@ class QuoteController extends \BaseController
->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(), ->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels() 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
]; ];
*/
// TODO: Add Remember Cache
return [
'entityType' => ENTITY_QUOTE,
'account' => Auth::user()->account,
'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')),
'countries' => Country::orderBy('name')->get(),
'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(),
'taxRates' => TaxRate::scope()->orderBy('name')->get(),
'currencies' => Currency::orderBy('name')->get(),
'sizes' => Size::orderBy('id')->get(),
'paymentTerms' => PaymentTerm::orderBy('num_days')->get(['name', 'num_days']),
'industries' => Industry::orderBy('name')->get(),
'invoiceDesigns' => InvoiceDesign::where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(),
'invoiceLabels' => Auth::user()->account->getInvoiceLabels()
];
} }
public function bulk() public function bulk()

View File

@ -1,6 +1,17 @@
<?php <?php namespace App\Http\Controllers;
class ReportController extends \BaseController use Auth;
use Input;
use Utils;
use DB;
use DateInterval;
use DatePeriod;
use Session;
use View;
use App\Models\Account;
class ReportController extends BaseController
{ {
public function d3() public function d3()
{ {

View File

@ -1,6 +1,6 @@
<?php <?php namespace App\Http\Controllers;
class TimesheetController extends \BaseController { class TimesheetController extends BaseController {
/** /**
* Display a listing of the resource. * Display a listing of the resource.

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Http\Controllers;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Confide Controller Template | Confide Controller Template
@ -9,7 +9,19 @@
| |
*/ */
use ninja\repositories\AccountRepository; use Auth;
use Session;
use DB;
use Validator;
use Input;
use View;
use Redirect;
use Datatable;
use URL;
use App\Models\AccountToken;
use App\Ninja\Repositories\AccountRepository;
class TokenController extends BaseController class TokenController extends BaseController
{ {

View File

@ -1,17 +1,23 @@
<?php <?php namespace App\Http\Controllers;
/*
|--------------------------------------------------------------------------
| Confide Controller Template
|--------------------------------------------------------------------------
|
| This is the default Confide controller template for controlling user
| authentication. Feel free to change to your needs.
|
*/
use ninja\repositories\AccountRepository; use Auth;
use ninja\mailers\ContactMailer; use Config;
use ninja\mailers\UserMailer; use Datatable;
use DB;
use Event;
use Input;
use View;
use Redirect;
use Session;
use URL;
use Utils;
use Validator;
use App\Models\User;
use App\Http\Requests;
use App\Ninja\Repositories\AccountRepository;
use App\Ninja\Mailers\ContactMailer;
use App\Ninja\Mailers\UserMailer;
class UserController extends BaseController class UserController extends BaseController
{ {
@ -88,7 +94,7 @@ class UserController extends BaseController
$user->force_pdfjs = true; $user->force_pdfjs = true;
$user->save(); $user->save();
Session::flash('message', trans('texts.confide.updated_settings')); Session::flash('message', trans('texts.security.updated_settings'));
return Redirect::to('/dashboard'); return Redirect::to('/dashboard');
} }
@ -221,7 +227,7 @@ class UserController extends BaseController
$user->email = trim(Input::get('email')); $user->email = trim(Input::get('email'));
$user->registered = true; $user->registered = true;
$user->password = str_random(RANDOM_KEY_LENGTH); $user->password = str_random(RANDOM_KEY_LENGTH);
$user->password_confirmation = $user->password; $user->confirmation_code = str_random(RANDOM_KEY_LENGTH);
$user->public_id = $lastUser->public_id + 1; $user->public_id = $lastUser->public_id + 1;
} }
@ -251,81 +257,6 @@ class UserController extends BaseController
return Redirect::to('company/advanced_settings/user_management'); return Redirect::to('company/advanced_settings/user_management');
} }
/**
* Displays the login form
*
*/
public function login()
{
if (Confide::user()) {
Event::fire('user.login');
Session::reflash();
return Redirect::to('/dashboard');
/*
$invoice = Invoice::scope()->orderBy('id', 'desc')->first();
if ($invoice)
{
return Redirect::to('/invoices/' . $invoice->public_id);
}
else
{
return Redirect::to('/dashboard');
}
*/
} else {
return View::make(Config::get('confide::login_form'));
}
}
/**
* Attempt to do login
*
*/
public function do_login()
{
$input = array(
'email' => Input::get('login_email'), // May be the username too
'username' => Input::get('login_email'), // so we have to pass both
'password' => Input::get('login_password'),
'remember' => true,
);
// If you wish to only allow login from confirmed users, call logAttempt
// with the second parameter as true.
// logAttempt will check if the 'email' perhaps is the username.
// Get the value from the config file instead of changing the controller
if (Input::get('login_email') && Confide::logAttempt($input, false)) {
Event::fire('user.login');
// Redirect the user to the URL they were trying to access before
// caught by the authentication filter IE Redirect::guest('user/login').
// Otherwise fallback to '/'
// Fix pull #145
return Redirect::intended('/dashboard'); // change it to '/admin', '/dashboard' or something
} else {
//$user = new User;
// Check if there was too many login attempts
if (Confide::isThrottled($input)) {
$err_msg = trans('texts.confide.too_many_attempts');
}
/*
elseif( $user->checkUserExists( $input ) and ! $user->isConfirmed( $input ) )
{
$err_msg = Lang::get('confide::confide.alerts.not_confirmed');
}
*/
else {
$err_msg = trans('texts.confide.wrong_credentials');
}
return Redirect::action('UserController@login')
->withInput(Input::except('login_password'))
->with('error', $err_msg);
}
}
/** /**
* Attempt to confirm account with code * Attempt to confirm account with code
@ -334,10 +265,12 @@ class UserController extends BaseController
*/ */
public function confirm($code) public function confirm($code)
{ {
if (Confide::confirm($code)) { $user = User::where('confirmation_code', '=', $code)->get()->first();
$notice_msg = trans('texts.confide.confirmation');
if ($user) {
$notice_msg = trans('texts.security.confirmation');
$user = User::where('confirmation_code', '=', $code)->get()->first(); $user->confirmed = true;
$user->confirmation_code = ''; $user->confirmation_code = '';
$user->save(); $user->save();
@ -352,109 +285,13 @@ class UserController extends BaseController
return Redirect::to($invitation->getLink()); return Redirect::to($invitation->getLink());
} else { } else {
return Redirect::action('UserController@login')->with('message', $notice_msg); return Redirect::to(Auth::check() ? '/dashboard' : '/login')->with('message', $notice_msg);
} }
} }
} else { } else {
$error_msg = trans('texts.confide.wrong_confirmation'); $error_msg = trans('texts.security.wrong_confirmation');
return Redirect::action('UserController@login')->with('error', $error_msg); return Redirect::to('/login')->with('error', $error_msg);
}
}
/**
* Displays the forgot password form
*
*/
public function forgot_password()
{
return View::make(Config::get('confide::forgot_password_form'));
}
/**
* Attempt to send change password link to the given email
*
*/
public function do_forgot_password()
{
Confide::forgotPassword(Input::get('email'));
$notice_msg = trans('texts.confide.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');
return Redirect::action('UserController@login')
->with( 'notice', $notice_msg );
}
else
{
$error_msg = Lang::get('confide::confide.alerts.wrong_password_forgot');
return Redirect::action('UserController@forgot_password')
->withInput()
->with( 'error', $error_msg );
}
*/
}
/**
* Shows the change password form with the given token
*
*/
public function reset_password($token = false)
{
return View::make(Config::get('confide::reset_password_form'))
->with('token', $token);
}
/**
* Attempt change password of the user
*
*/
public function do_reset_password()
{
if (Auth::check()) {
$rules = [
'password' => 'required|between:4,11|confirmed',
'password_confirmation' => 'between:4,11',
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('user/reset')->withInput()->withErrors($validator);
}
$user = Auth::user();
$user->password = Input::get('password');
$user->save();
Session::flash('message', trans('texts.confide.password_reset'));
return Redirect::to('/dashboard');
} else {
$input = array(
'token' => Input::get('token'),
'password' => Input::get('password'),
'password_confirmation' => Input::get('password_confirmation'),
);
// By passing an array with the token, password and confirmation
if (Confide::resetPassword($input)) {
$notice_msg = trans('texts.confide.password_reset');
return Redirect::action('UserController@login')
->with('notice', $notice_msg);
} else {
$error_msg = trans('texts.confide.wrong_password_reset');
return Redirect::action('UserController@reset_password', array('token' => $input['token']))
->withInput()
->with('error', $error_msg);
}
} }
} }
@ -474,7 +311,7 @@ class UserController extends BaseController
Session::forget('news_feed_id'); Session::forget('news_feed_id');
Session::forget('news_feed_message'); Session::forget('news_feed_message');
Confide::logout(); Auth::logout();
return Redirect::to('/')->with('clearGuestKey', true); return Redirect::to('/')->with('clearGuestKey', true);
} }

View File

@ -0,0 +1,36 @@
<?php namespace InvoiceNinja\Http\Controllers;
class HomeController extends Controller {
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
return view('home');
}
}

View File

@ -0,0 +1,36 @@
<?php namespace InvoiceNinja\Http\Controllers;
class WelcomeController extends Controller {
/*
|--------------------------------------------------------------------------
| Welcome Controller
|--------------------------------------------------------------------------
|
| This controller renders the "marketing page" for the application and
| is configured to only allow guests. Like most of the other sample
| controllers, you are free to modify or remove it as you desire.
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function index()
{
return view('welcome');
}
}

34
app/Http/Kernel.php Normal file
View File

@ -0,0 +1,34 @@
<?php namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel {
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
'App\Http\Middleware\StartupCheck',
];
/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'api' => 'App\Http\Middleware\ApiCheck',
];
}

View File

@ -0,0 +1,75 @@
<?php namespace App\Http\Middleware;
use Closure;
use Utils;
use Request;
use Session;
use Response;
use App\Models\AccountToken;
class ApiCheck {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$headers = Utils::getApiHeaders();
// check for a valid token
$token = AccountToken::where('token', '=', Request::header('X-Ninja-Token'))->first(['id', 'user_id']);
if ($token) {
Auth::loginUsingId($token->user_id);
Session::set('token_id', $token->id);
} else {
sleep(3);
return Response::make('Invalid token', 403, $headers);
}
if (!Utils::isNinja()) {
return null;
}
if (!Utils::isPro()) {
return Response::make('API requires pro plan', 403, $headers);
} else {
$accountId = Auth::user()->account->id;
// http://stackoverflow.com/questions/1375501/how-do-i-throttle-my-sites-api-users
$hour = 60 * 60;
$hour_limit = 100; # users are limited to 100 requests/hour
$hour_throttle = Cache::get("hour_throttle:{$accountId}", null);
$last_api_request = Cache::get("last_api_request:{$accountId}", 0);
$last_api_diff = time() - $last_api_request;
if (is_null($hour_throttle)) {
$new_hour_throttle = 0;
} else {
$new_hour_throttle = $hour_throttle - $last_api_diff;
$new_hour_throttle = $new_hour_throttle < 0 ? 0 : $new_hour_throttle;
$new_hour_throttle += $hour / $hour_limit;
$hour_hits_remaining = floor(( $hour - $new_hour_throttle ) * $hour_limit / $hour);
$hour_hits_remaining = $hour_hits_remaining >= 0 ? $hour_hits_remaining : 0;
}
if ($new_hour_throttle > $hour) {
$wait = ceil($new_hour_throttle - $hour);
sleep(1);
return Response::make("Please wait {$wait} second(s)", 403, $headers);
}
Cache::put("hour_throttle:{$accountId}", $new_hour_throttle, 10);
Cache::put("last_api_request:{$accountId}", time(), 10);
}
return $next($request);
}
}

View File

@ -0,0 +1,50 @@
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate {
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
return response('Unauthorized.', 401);
}
else
{
return redirect()->guest('/login');
}
}
return $next($request);
}
}

View File

@ -0,0 +1,44 @@
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\RedirectResponse;
class RedirectIfAuthenticated {
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->check())
{
return new RedirectResponse(url('/dashboard'));
}
return $next($request);
}
}

View File

@ -0,0 +1,159 @@
<?php namespace App\Http\Middleware;
use Closure;
use Utils;
use App;
use Auth;
use Input;
use Redirect;
use Cache;
use Session;
use Event;
use App\Models\Currency;
use App\Events\UserSettingsChanged;
class StartupCheck {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Ensure all request are over HTTPS in production
if (App::environment() == ENV_PRODUCTION)
{
if (!Request::secure())
{
return Redirect::secure(Request::getRequestUri());
}
}
// If the database doens't yet exist we'll skip the rest
if (!Utils::isNinja() && !Utils::isDatabaseSetup())
{
return $next($request);
}
// Check currency data has been cached
if (!Cache::has('currencies'))
{
Cache::forever('currencies', Currency::orderBy('name')->get());
}
// check the application is up to date and for any news feed messages
if (Auth::check())
{
$count = Session::get(SESSION_COUNTER, 0);
Session::put(SESSION_COUNTER, ++$count);
if (!Utils::startsWith($_SERVER['REQUEST_URI'], '/news_feed') && !Session::has('news_feed_id')) {
$data = false;
if (Utils::isNinja()) {
$data = Utils::getNewsFeedResponse();
} else {
$file = @file_get_contents(NINJA_APP_URL . '/news_feed/' . Utils::getUserType() . '/' . NINJA_VERSION);
$data = @json_decode($file);
}
if ($data) {
if ($data->version != NINJA_VERSION) {
$params = [
'user_version' => NINJA_VERSION,
'latest_version'=> $data->version,
'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank'])
];
Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
Session::put('news_feed_message', trans('texts.new_version_available', $params));
} else {
Session::put('news_feed_id', $data->id);
if ($data->message && $data->id > Auth::user()->news_feed_id) {
Session::put('news_feed_message', $data->message);
}
}
} else {
Session::put('news_feed_id', true);
}
}
}
// Check if we're requesting to change the account's language
if (Input::has('lang'))
{
$locale = Input::get('lang');
App::setLocale($locale);
Session::set(SESSION_LOCALE, $locale);
if (Auth::check())
{
if ($language = Language::whereLocale($locale)->first())
{
$account = Auth::user()->account;
$account->language_id = $language->id;
$account->save();
}
}
}
else if (Auth::check())
{
$locale = Session::get(SESSION_LOCALE, DEFAULT_LOCALE);
App::setLocale($locale);
}
// Make sure the account/user localization settings are in the session
if (Auth::check() && !Session::has(SESSION_TIMEZONE))
{
Event::fire(new UserSettingsChanged());
}
// Check if the user is claiming a license (ie, additional invoices, white label, etc.)
$claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license');
if (!$claimingLicense && Input::has('license_key') && Input::has('product_id'))
{
$licenseKey = Input::get('license_key');
$productId = Input::get('product_id');
$data = trim(file_get_contents((Utils::isNinjaDev() ? 'http://ninja.dev' : NINJA_APP_URL) . "/claim_license?license_key={$licenseKey}&product_id={$productId}"));
if ($productId == PRODUCT_INVOICE_DESIGNS)
{
if ($data = json_decode($data))
{
foreach ($data as $item)
{
$design = new InvoiceDesign();
$design->id = $item->id;
$design->name = $item->name;
$design->javascript = $item->javascript;
$design->save();
}
if (!Utils::isNinjaProd()) {
Cache::forget('invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId());
}
Session::flash('message', trans('texts.bought_designs'));
}
}
else if ($productId == PRODUCT_WHITE_LABEL)
{
if ($data == 'valid')
{
$account = Auth::user()->account;
$account->pro_plan_paid = NINJA_DATE;
$account->save();
Session::flash('message', trans('texts.bought_white_label'));
}
}
}
return $next($request);
}
}

View File

@ -0,0 +1,20 @@
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return parent::handle($request, $next);
}
}

View File

@ -0,0 +1,9 @@
<?php namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
abstract class Request extends FormRequest {
//
}

30
app/routes.php → app/Http/routes.php Executable file → Normal file
View File

@ -16,7 +16,6 @@
//dd(DB::getQueryLog()); //dd(DB::getQueryLog());
//dd(Client::getPrivateId(1)); //dd(Client::getPrivateId(1));
//dd(new DateTime()); //dd(new DateTime());
//Event::fire('user.signup');
//dd(App::environment()); //dd(App::environment());
//dd(gethostname()); //dd(gethostname());
//Log::error('test'); //Log::error('test');
@ -54,23 +53,44 @@ Route::get('claim_license', 'PaymentController@claim_license');
Route::post('signup/validate', 'AccountController@checkEmail'); Route::post('signup/validate', 'AccountController@checkEmail');
Route::post('signup/submit', 'AccountController@submitSignup'); Route::post('signup/submit', 'AccountController@submitSignup');
// Laravel auth routes
/*
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
*/
get('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@getRegister'));
post('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@postRegister'));
get('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@getLogin'));
post('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@postLoginWrapper'));
get('/logout', array('as' => 'logout', 'uses' => 'Auth\AuthController@getLogout'));
get('/forgot', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@getEmail'));
post('/forgot', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@postEmail'));
get('/password/reset', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@getReset'));
post('/password/reset', array('as' => 'forgot', 'uses' => 'Auth\PasswordController@postReset'));
get('user/confirm/{code}', 'UserController@confirm');
/*
// Confide routes // Confide routes
Route::get('login', 'UserController@login'); Route::get('login', 'UserController@login');
Route::post('login', 'UserController@do_login'); Route::post('login', 'UserController@do_login');
Route::get('user/confirm/{code}', 'UserController@confirm');
Route::get('forgot_password', 'UserController@forgot_password'); Route::get('forgot_password', 'UserController@forgot_password');
Route::post('forgot_password', 'UserController@do_forgot_password'); Route::post('forgot_password', 'UserController@do_forgot_password');
Route::get('user/reset/{token?}', 'UserController@reset_password'); Route::get('user/reset/{token?}', 'UserController@reset_password');
Route::post('user/reset', 'UserController@do_reset_password'); Route::post('user/reset', 'UserController@do_reset_password');
Route::get('logout', 'UserController@logout'); Route::get('logout', 'UserController@logout');
*/
if (Utils::isNinja()) { if (\App\Libraries\Utils::isNinja()) {
Route::post('/signup/register', 'AccountController@doRegister'); Route::post('/signup/register', 'AccountController@doRegister');
Route::get('/news_feed/{user_type}/{version}/', 'HomeController@newsFeed'); Route::get('/news_feed/{user_type}/{version}/', 'HomeController@newsFeed');
Route::get('/demo', 'AccountController@demo'); Route::get('/demo', 'AccountController@demo');
} }
Route::group(array('before' => 'auth'), function() { Route::group(['middleware' => 'auth'], function() {
Route::get('dashboard', 'DashboardController@index'); Route::get('dashboard', 'DashboardController@index');
Route::get('view_archive/{entity_type}/{visible}', 'AccountController@setTrashVisible'); Route::get('view_archive/{entity_type}/{visible}', 'AccountController@setTrashVisible');
Route::get('hide_message', 'HomeController@hideMessage'); Route::get('hide_message', 'HomeController@hideMessage');
@ -151,7 +171,7 @@ Route::group(array('before' => 'auth'), function() {
}); });
// Route group for API // Route group for API
Route::group(array('prefix' => 'api/v1', 'before' => ['api.access']), function() Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
{ {
Route::resource('ping', 'ClientApiController@ping'); Route::resource('ping', 'ClientApiController@ping');
Route::resource('clients', 'ClientApiController'); Route::resource('clients', 'ClientApiController');

View File

43
app/libraries/Utils.php → app/Libraries/Utils.php Executable file → Normal file
View File

@ -1,4 +1,20 @@
<?php <?php namespace App\Libraries;
use Auth;
use Cache;
use DB;
use Schema;
use Session;
use Request;
use View;
use DateTimeZone;
use Input;
use Log;
use DateTime;
use stdClass;
use Carbon;
use App\Models\Currency;
class Utils class Utils
{ {
@ -18,7 +34,7 @@ class Utils
if (Schema::hasTable('accounts')) { if (Schema::hasTable('accounts')) {
return true; return true;
} }
} catch (Exception $e) { } catch (\Exception $e) {
return false; return false;
} }
} }
@ -217,12 +233,14 @@ class Utils
$currencyId = Session::get(SESSION_CURRENCY); $currencyId = Session::get(SESSION_CURRENCY);
} }
$currency = Currency::remember(DEFAULT_QUERY_CACHE)->find($currencyId); $currency = Currency::find($currencyId);
if (!$currency) { if(!$currency){
$currency = Currency::remember(DEFAULT_QUERY_CACHE)->find(1); $currency = Currency::find(1);
} }
Cache::add('currency', $currency, DEFAULT_QUERY_CACHE);
return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator); return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
} }
@ -291,8 +309,8 @@ class Utils
return; return;
} }
$timezone = Session::get(SESSION_TIMEZONE); $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
$format = Session::get(SESSION_DATE_FORMAT); $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
$dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone)); $dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone));
@ -305,8 +323,8 @@ class Utils
return ''; return '';
} }
$timezone = Session::get(SESSION_TIMEZONE); $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
$format = Session::get(SESSION_DATE_FORMAT); $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
$dateTime = DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone)); $dateTime = DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone));
@ -315,8 +333,9 @@ class Utils
public static function today($formatResult = true) public static function today($formatResult = true)
{ {
$timezone = Session::get(SESSION_TIMEZONE); $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
$format = Session::get(SESSION_DATE_FORMAT); $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
$date = date_create(null, new DateTimeZone($timezone)); $date = date_create(null, new DateTimeZone($timezone));
if ($formatResult) { if ($formatResult) {

0
app/libraries/entity.php → app/Libraries/entity.php Executable file → Normal file
View File

View File

@ -0,0 +1,46 @@
<?php namespace App\Listeners;
use App\Events\InvoicePaid;
use App\Ninja\Mailers\UserMailer;
use App\Ninja\Mailers\ContactMailer;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class HandleInvoicePaid {
protected $userMailer;
protected $contactMailer;
/**
* Create the event handler.
*
* @return void
*/
public function __construct(UserMailer $userMailer, ContactMailer $contactMailer)
{
$this->userMailer = $userMailer;
$this->contactMailer = $contactMailer;
}
/**
* Handle the event.
*
* @param InvoicePaid $event
* @return void
*/
public function handle(InvoicePaid $event)
{
$this->contactMailer->sendPaymentConfirmation($payment);
$invoice = $payment->invoice;
foreach ($invoice->account->users as $user)
{
if ($user->{'notify_paid'})
{
$this->userMailer->sendNotification($user, $invoice, 'paid', $payment);
}
}
}
}

View File

@ -0,0 +1,42 @@
<?php namespace App\Listeners;
use App\Events\InvoiceSent;
use App\Ninja\Mailers\UserMailer;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class HandleInvoiceSent {
protected $userMailer;
/**
* Create the event handler.
*
* @return void
*/
public function __construct(UserMailer $userMailer)
{
$this->userMailer = $userMailer;
}
/**
* Handle the event.
*
* @param InvoiceSent $event
* @return void
*/
public function handle(InvoiceSent $event)
{
$invoice = $event->invoice;
foreach ($invoice->account->users as $user)
{
if ($user->{'notify_sent'})
{
$this->userMailer->sendNotification($user, $invoice, 'sent');
}
}
}
}

View File

@ -0,0 +1,42 @@
<?php namespace App\Listeners;
use App\Events\InvoiceViewed;
use App\Ninja\Mailers\UserMailer;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class HandleInvoiceViewed {
protected $userMailer;
/**
* Create the event handler.
*
* @return void
*/
public function __construct(UserMailer $userMailer)
{
$this->userMailer = $userMailer;
}
/**
* Handle the event.
*
* @param InvoiceViewed $event
* @return void
*/
public function handle(InvoiceViewed $event)
{
$invoice = $event->invoice;
foreach ($invoice->account->users as $user)
{
if ($user->{'notify_viewed'})
{
$this->userMailer->sendNotification($user, $invoice, 'viewed', $payment);
}
}
}
}

View File

@ -0,0 +1,37 @@
<?php namespace App\Listeners;
use Auth;
use Carbon;
use App\Events\UserLoggedIn;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class HandleUserLoggedIn {
/**
* Create the event handler.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserLoggedIn $event
* @return void
*/
public function handle(UserLoggedIn $event)
{
$account = Auth::user()->account;
$account->last_login = Carbon::now()->toDateTimeString();
$account->save();
$account->loadLocalizationSettings();
}
}

View File

@ -0,0 +1,34 @@
<?php namespace App\Listeners;
use Auth;
use App\Events\UserSettingsChanged;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class HandleUserSettingsChanged {
/**
* Create the event handler.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserSettingsChanged $event
* @return void
*/
public function handle(UserSettingsChanged $event)
{
$account = Auth::user()->account;
$account->loadLocalizationSettings();
}
}

45
app/models/Account.php → app/Models/Account.php Executable file → Normal file
View File

@ -1,72 +1,79 @@
<?php <?php namespace App\Models;
use Eloquent;
use Utils;
use Session;
use Illuminate\Database\Eloquent\SoftDeletes;
class Account extends Eloquent class Account extends Eloquent
{ {
protected $softDelete = true; use SoftDeletes;
protected $dates = ['deleted_at'];
public function users() public function users()
{ {
return $this->hasMany('User'); return $this->hasMany('App\Models\User');
} }
public function clients() public function clients()
{ {
return $this->hasMany('Client'); return $this->hasMany('App\Models\Client');
} }
public function invoices() public function invoices()
{ {
return $this->hasMany('Invoice'); return $this->hasMany('App\Models\Invoice');
} }
public function account_gateways() public function account_gateways()
{ {
return $this->hasMany('AccountGateway'); return $this->hasMany('App\Models\AccountGateway');
} }
public function tax_rates() public function tax_rates()
{ {
return $this->hasMany('TaxRate'); return $this->hasMany('App\Models\TaxRate');
} }
public function country() public function country()
{ {
return $this->belongsTo('Country'); return $this->belongsTo('App\Models\Country');
} }
public function timezone() public function timezone()
{ {
return $this->belongsTo('Timezone'); return $this->belongsTo('App\Models\Timezone');
} }
public function language() public function language()
{ {
return $this->belongsTo('Language'); return $this->belongsTo('App\Models\Language');
} }
public function date_format() public function date_format()
{ {
return $this->belongsTo('DateFormat'); return $this->belongsTo('App\Models\DateFormat');
} }
public function datetime_format() public function datetime_format()
{ {
return $this->belongsTo('DatetimeFormat'); return $this->belongsTo('App\Models\DatetimeFormat');
}
public function currency()
{
return $this->belongsTo('Currency');
} }
public function size() public function size()
{ {
return $this->belongsTo('Size'); return $this->belongsTo('App\Models\Size');
}
public function currency()
{
return $this->belongsTo('App\Models\Currency');
} }
public function industry() public function industry()
{ {
return $this->belongsTo('Industry'); return $this->belongsTo('App\Models\Industry');
} }
public function isGatewayConfigured($gatewayId = 0) public function isGatewayConfigured($gatewayId = 0)

View File

@ -1,10 +1,15 @@
<?php <?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class AccountGateway extends EntityModel class AccountGateway extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public function gateway() public function gateway()
{ {
return $this->belongsTo('Gateway'); return $this->belongsTo('App\Models\Gateway');
} }
public function getCreditcardTypes() public function getCreditcardTypes()

View File

@ -0,0 +1,10 @@
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class AccountGatewayToken extends Eloquent
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public $timestamps = true;
}

View File

@ -0,0 +1,14 @@
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class AccountToken extends EntityModel
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public function account()
{
return $this->belongsTo('App\Models\Account');
}
}

14
app/models/Activity.php → app/Models/Activity.php Executable file → Normal file
View File

@ -1,9 +1,15 @@
<?php <?php namespace App\Models;
use Auth;
use Eloquent;
use Utils;
use Session;
use Request;
use Carbon;
class Activity extends Eloquent class Activity extends Eloquent
{ {
public $timestamps = true; public $timestamps = true;
protected $softDelete = false;
public function scopeScope($query) public function scopeScope($query)
{ {
@ -12,12 +18,12 @@ class Activity extends Eloquent
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('App\Models\Account');
} }
public function user() public function user()
{ {
return $this->belongsTo('User'); return $this->belongsTo('App\Models\User');
} }
private static function getBlank($entity = false) private static function getBlank($entity = false)

View File

@ -1,4 +1,4 @@
<?php <?php namespace App\Models;
class Affiliate extends Eloquent class Affiliate extends Eloquent
{ {

135
app/models/Client.php → app/Models/Client.php Executable file → Normal file
View File

@ -1,7 +1,14 @@
<?php <?php namespace App\Models;
use DB;
use Illuminate\Database\Eloquent\SoftDeletes;
class Client extends EntityModel class Client extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public static $fieldName = 'Client - Name'; public static $fieldName = 'Client - Name';
public static $fieldPhone = 'Client - Phone'; public static $fieldPhone = 'Client - Phone';
public static $fieldAddress1 = 'Client - Street'; public static $fieldAddress1 = 'Client - Street';
@ -14,47 +21,47 @@ class Client extends EntityModel
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('App\Models\Account');
} }
public function invoices() public function invoices()
{ {
return $this->hasMany('Invoice'); return $this->hasMany('App\Models\Invoice');
} }
public function payments() public function payments()
{ {
return $this->hasMany('Payment'); return $this->hasMany('App\Models\Payment');
} }
public function contacts() public function contacts()
{ {
return $this->hasMany('Contact'); return $this->hasMany('App\Models\Contact');
} }
public function projects() public function projects()
{ {
return $this->hasMany('Project'); return $this->hasMany('App\Models\Project');
} }
public function country() public function country()
{ {
return $this->belongsTo('Country'); return $this->belongsTo('App\Models\Country');
} }
public function currency() public function currency()
{ {
return $this->belongsTo('Currency'); return $this->belongsTo('App\Models\Currency');
} }
public function size() public function size()
{ {
return $this->belongsTo('Size'); return $this->belongsTo('App\Models\Size');
} }
public function industry() public function industry()
{ {
return $this->belongsTo('Industry'); return $this->belongsTo('App\Models\Industry');
} }
public function getTotalCredit() public function getTotalCredit()
@ -87,111 +94,6 @@ class Client extends EntityModel
return ENTITY_CLIENT; return ENTITY_CLIENT;
} }
public function getAddress()
{
$str = '';
if ($this->address1) {
$str .= $this->address1.'<br/>';
}
if ($this->address2) {
$str .= $this->address2.'<br/>';
}
if ($this->city) {
$str .= $this->city.', ';
}
if ($this->state) {
$str .= $this->state.' ';
}
if ($this->postal_code) {
$str .= $this->postal_code;
}
if ($this->country) {
$str .= '<br/>'.$this->country->name;
}
if ($str) {
$str = '<p>'.$str.'</p>';
}
return $str;
}
public function getPhone()
{
$str = '';
if ($this->work_phone) {
$str .= '<i class="fa fa-phone" style="width: 20px"></i>'.Utils::formatPhoneNumber($this->work_phone);
}
return $str;
}
public function getIdNumber()
{
$str = '';
if ($this->id_number) {
$str .= '<i class="fa fa-id-number" style="width: 20px"></i>'.trans('texts.id_number').': '.$this->id_number;
}
return $str;
}
public function getVatNumber()
{
$str = '';
if ($this->vat_number) {
$str .= '<i class="fa fa-vat-number" style="width: 20px"></i>'.trans('texts.vat_number').': '.$this->vat_number;
}
return $str;
}
public function getNotes()
{
$str = '';
if ($this->private_notes) {
$str .= '<i>'.$this->private_notes.'</i>';
}
return $str;
}
public function getIndustry()
{
$str = '';
if ($this->client_industry) {
$str .= $this->client_industry->name.' ';
}
if ($this->client_size) {
$str .= $this->client_size->name;
}
return $str;
}
public function getCustomFields()
{
$str = '';
$account = $this->account;
if ($account->custom_client_label1 && $this->custom_value1) {
$str .= "{$account->custom_client_label1}: {$this->custom_value1}<br/>";
}
if ($account->custom_client_label2 && $this->custom_value2) {
$str .= "{$account->custom_client_label2}: {$this->custom_value2}<br/>";
}
return $str;
}
public function getWebsite() public function getWebsite()
{ {
if (!$this->website) { if (!$this->website) {
@ -263,6 +165,7 @@ Client::deleting(function ($client) {
Activity::archiveClient($client); Activity::archiveClient($client);
}); });
Client::restoring(function ($client) { /*Client::restoring(function ($client) {
Activity::restoreClient($client); Activity::restoreClient($client);
}); });
*/

34
app/models/Contact.php → app/Models/Contact.php Executable file → Normal file
View File

@ -1,7 +1,14 @@
<?php <?php namespace App\Models;
use HTML;
use Illuminate\Database\Eloquent\SoftDeletes;
class Contact extends EntityModel class Contact extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public static $fieldFirstName = 'Contact - First Name'; public static $fieldFirstName = 'Contact - First Name';
public static $fieldLastName = 'Contact - Last Name'; public static $fieldLastName = 'Contact - Last Name';
public static $fieldEmail = 'Contact - Email'; public static $fieldEmail = 'Contact - Email';
@ -9,7 +16,7 @@ class Contact extends EntityModel
public function client() public function client()
{ {
return $this->belongsTo('Client'); return $this->belongsTo('App\Models\Client');
} }
public function getPersonType() public function getPersonType()
@ -48,27 +55,4 @@ class Contact extends EntityModel
return ''; return '';
} }
} }
public function getDetails()
{
$str = '';
if ($this->first_name || $this->last_name) {
$str .= '<b>'.$this->first_name.' '.$this->last_name.'</b><br/>';
}
if ($this->email) {
$str .= '<i class="fa fa-envelope" style="width: 20px"></i>'.HTML::mailto($this->email, $this->email).'<br/>';
}
if ($this->phone) {
$str .= '<i class="fa fa-phone" style="width: 20px"></i>'.Utils::formatPhoneNumber($this->phone);
}
if ($str) {
$str = '<p>'.$str.'</p>';
}
return $str;
}
} }

10
app/Models/Country.php Normal file
View File

@ -0,0 +1,10 @@
<?php namespace App\Models;
use Eloquent;
class Country extends Eloquent
{
public $timestamps = false;
protected $visible = ['id', 'name'];
}

11
app/models/Credit.php → app/Models/Credit.php Executable file → Normal file
View File

@ -1,15 +1,20 @@
<?php <?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Credit extends EntityModel class Credit extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public function invoice() public function invoice()
{ {
return $this->belongsTo('Invoice')->withTrashed(); return $this->belongsTo('App\Models\Invoice')->withTrashed();
} }
public function client() public function client()
{ {
return $this->belongsTo('Client')->withTrashed(); return $this->belongsTo('App\Models\Client')->withTrashed();
} }
public function getName() public function getName()

5
app/models/Currency.php → app/Models/Currency.php Executable file → Normal file
View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class Currency extends Eloquent class Currency extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class DateFormat extends Eloquent class DateFormat extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class DatetimeFormat extends Eloquent class DatetimeFormat extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

View File

@ -1,10 +1,12 @@
<?php <?php namespace App\Models;
use Auth;
use Eloquent;
use Utils;
class EntityModel extends Eloquent class EntityModel extends Eloquent
{ {
protected $softDelete = true;
public $timestamps = true; public $timestamps = true;
protected $hidden = ['id']; protected $hidden = ['id'];
public static function createNew($parent = false) public static function createNew($parent = false)

5
app/models/Frequency.php → app/Models/Frequency.php Executable file → Normal file
View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class Frequency extends Eloquent class Frequency extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

8
app/models/Gateway.php → app/Models/Gateway.php Executable file → Normal file
View File

@ -1,13 +1,15 @@
<?php <?php namespace App\Models;
use Eloquent;
use Omnipay;
class Gateway extends Eloquent class Gateway extends Eloquent
{ {
public $timestamps = true; public $timestamps = true;
protected $softDelete = false;
public function paymentlibrary() public function paymentlibrary()
{ {
return $this->belongsTo('PaymentLibrary', 'payment_library_id'); return $this->belongsTo('\App\Models\PaymentLibrary', 'payment_library_id');
} }
public function getLogoUrl() public function getLogoUrl()

5
app/models/Industry.php → app/Models/Industry.php Executable file → Normal file
View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class Industry extends Eloquent class Industry extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

34
app/Models/Invitation.php Normal file
View File

@ -0,0 +1,34 @@
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Invitation extends EntityModel
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public function invoice()
{
return $this->belongsTo('App\Models\Invoice');
}
public function contact()
{
return $this->belongsTo('App\Models\Contact')->withTrashed();
}
public function user()
{
return $this->belongsTo('App\Models\User')->withTrashed();
}
public function account()
{
return $this->belongsTo('App\Models\Account');
}
public function getLink()
{
return SITE_URL.'/view/'.$this->invitation_key;
}
}

25
app/models/Invoice.php → app/Models/Invoice.php Executable file → Normal file
View File

@ -1,40 +1,45 @@
<?php <?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Invoice extends EntityModel class Invoice extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('App\Models\Account');
} }
public function user() public function user()
{ {
return $this->belongsTo('User'); return $this->belongsTo('App\Models\User');
} }
public function client() public function client()
{ {
return $this->belongsTo('Client')->withTrashed(); return $this->belongsTo('App\Models\Client')->withTrashed();
} }
public function invoice_items() public function invoice_items()
{ {
return $this->hasMany('InvoiceItem')->orderBy('id'); return $this->hasMany('App\Models\InvoiceItem')->orderBy('id');
} }
public function invoice_status() public function invoice_status()
{ {
return $this->belongsTo('InvoiceStatus'); return $this->belongsTo('App\Models\InvoiceStatus');
} }
public function invoice_design() public function invoice_design()
{ {
return $this->belongsTo('InvoiceDesign'); return $this->belongsTo('App\Models\InvoiceDesign');
} }
public function invitations() public function invitations()
{ {
return $this->hasMany('Invitation')->orderBy('invitations.contact_id'); return $this->hasMany('App\Models\Invitation')->orderBy('invitations.contact_id');
} }
public function getName() public function getName()
@ -231,6 +236,8 @@ Invoice::deleting(function ($invoice) {
Activity::archiveInvoice($invoice); Activity::archiveInvoice($invoice);
}); });
Invoice::restoring(function ($invoice) { // TODO: Fix for L5
/*Invoice::restoring(function ($invoice) {
Activity::restoreInvoice($invoice); Activity::restoreInvoice($invoice);
}); });
*/

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class InvoiceDesign extends Eloquent class InvoiceDesign extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

View File

@ -0,0 +1,19 @@
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class InvoiceItem extends EntityModel
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public function invoice()
{
return $this->belongsTo('App\Models\Invoice');
}
public function product()
{
return $this->belongsTo('App\Models\Product');
}
}

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class InvoiceStatus extends Eloquent class InvoiceStatus extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

5
app/models/Language.php → app/Models/Language.php Executable file → Normal file
View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class Language extends Eloquent class Language extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

10
app/Models/License.php Normal file
View File

@ -0,0 +1,10 @@
<?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class License extends Eloquent
{
public $timestamps = true;
use SoftDeletes;
protected $dates = ['deleted_at'];
}

17
app/models/Payment.php → app/Models/Payment.php Executable file → Normal file
View File

@ -1,30 +1,35 @@
<?php <?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Payment extends EntityModel class Payment extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public function invoice() public function invoice()
{ {
return $this->belongsTo('Invoice')->withTrashed(); return $this->belongsTo('App\Models\Invoice')->withTrashed();
} }
public function invitation() public function invitation()
{ {
return $this->belongsTo('Invitation'); return $this->belongsTo('App\Models\Invitation');
} }
public function client() public function client()
{ {
return $this->belongsTo('Client')->withTrashed(); return $this->belongsTo('App\Models\Client')->withTrashed();
} }
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('App\Models\Account');
} }
public function contact() public function contact()
{ {
return $this->belongsTo('Contact'); return $this->belongsTo('App\Models\Contact');
} }
public function getAmount() public function getAmount()

View File

@ -1,4 +1,6 @@
<?php <?php namespace App\Models;
use Eloquent;
class PaymentLibrary extends Eloquent class PaymentLibrary extends Eloquent
{ {
@ -7,6 +9,6 @@ class PaymentLibrary extends Eloquent
public function gateways() public function gateways()
{ {
return $this->hasMany('Gateway', 'payment_library_id'); return $this->hasMany('App\Models\Gateway', 'payment_library_id');
} }
} }

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class PaymentTerm extends Eloquent class PaymentTerm extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

View File

@ -1,7 +1,8 @@
<?php <?php namespace App\Models;
use Eloquent;
class PaymentType extends Eloquent class PaymentType extends Eloquent
{ {
public $timestamps = false; public $timestamps = false;
protected $softDelete = false;
} }

7
app/models/Product.php → app/Models/Product.php Executable file → Normal file
View File

@ -1,7 +1,12 @@
<?php <?php namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends EntityModel class Product extends EntityModel
{ {
use SoftDeletes;
protected $dates = ['deleted_at'];
public static function findProductByKey($key) public static function findProductByKey($key)
{ {
return Product::scope()->where('product_key', '=', $key)->first(); return Product::scope()->where('product_key', '=', $key)->first();

Some files were not shown because too many files have changed in this diff Show More