@@ -123,7 +126,7 @@ class CreditController extends \BaseController {
public function bulk()
{
$action = Input::get('action');
- $ids = Input::get('ids');
+ $ids = Input::get('id') ? Input::get('id') : Input::get('ids');
$credits = Credit::scope($ids)->get();
foreach ($credits as $credit) {
diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php
index 57456651b78b..537115f435c1 100755
--- a/app/controllers/InvoiceController.php
+++ b/app/controllers/InvoiceController.php
@@ -20,18 +20,16 @@ class InvoiceController extends \BaseController {
{
$query = DB::table('invoices')
->join('clients', 'clients.id', '=','invoices.client_id')
- ->join('invoice_statuses', 'invoice_statuses.id', '=', 'invoices.invoice_status_id');
- //->select('clients.public_id as client_public_id', 'invoice_number', 'clients.name', 'invoices.public_id', 'total', 'invoices.balance', 'invoice_date', 'due_date');
- //dd($query->get());
+ ->join('invoice_statuses', 'invoice_statuses.id', '=', 'invoices.invoice_status_id')
+ ->where('invoices.account_id', '=', Auth::user()->account_id)
+ ->where('invoices.deleted_at', '=', null)
+ ->select('clients.public_id as client_public_id', 'invoice_number', 'clients.name as client_name', 'invoices.public_id', 'total', 'invoices.balance', 'invoice_date', 'due_date', 'invoice_statuses.name as invoice_status_name');
if ($clientPublicId) {
$query->where('clients.public_id', '=', $clientPublicId);
- //$clientId = Client::getPrivateId($clientPublicId);
- //$collection->where('client_id','=',$clientId);
}
- $table = Datatable::query($query);
-
+ $table = Datatable::query($query);
if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '
'; });
@@ -40,17 +38,17 @@ class InvoiceController extends \BaseController {
$table->addColumn('invoice_number', function($model) { return link_to('invoices/' . $model->public_id . '/edit', $model->invoice_number); });
if (!$clientPublicId) {
- //$table->addColumn('client', function($model) { dd($model); return link_to('clients/' . $model->client_public_id, $model->client_name); });
+ $table->addColumn('client', function($model) { return link_to('clients/' . $model->client_public_id, $model->client_name); });
}
return $table->addColumn('total', function($model){ return '$' . money_format('%i', $model->total); })
- ->addColumn('invoices.balance', function($model) { return '$' . money_format('%i', $model->balance); })
+ ->addColumn('balance', function($model) { return '$' . money_format('%i', $model->balance); })
->addColumn('invoice_date', function($model) { return fromSqlDate($model->invoice_date); })
->addColumn('due_date', function($model) { return fromSqlDate($model->due_date); })
- //->addColumn('status', function($model) { return $model->invoice_status->name; })
+ ->addColumn('invoice_status_name', function($model) { return $model->invoice_status_name; })
->addColumn('dropdown', function($model)
{
- return '
+ return '
@@ -62,7 +60,7 @@ class InvoiceController extends \BaseController {
';
})
- ->orderColumns('number')
+ ->orderColumns('invoice_number','client','total','balance','invoice_date','due_date','invoice_status_name')
->make();
}
@@ -228,6 +226,7 @@ class InvoiceController extends \BaseController {
'title' => '- ' . $invoice->invoice_number,
'account' => Auth::user()->account,
'products' => Product::scope()->get(array('product_key','notes','cost','qty')),
+ 'countries' => Country::orderBy('name')->get(),
'client' => $invoice->client,
'clients' => Client::scope()->orderBy('name')->get());
return View::make('invoices.edit', $data);
@@ -252,6 +251,7 @@ class InvoiceController extends \BaseController {
'title' => '- New Invoice',
'client' => $client,
'items' => json_decode(Input::old('items')),
+ 'countries' => Country::orderBy('name')->get(),
'account' => Auth::user()->account,
'products' => Product::scope()->get(array('product_key','notes','cost','qty')),
'clients' => Client::scope()->orderBy('name')->get());
@@ -272,13 +272,9 @@ class InvoiceController extends \BaseController {
{
$action = Input::get('action');
- if ($action == 'archive')
+ if ($action == 'archive' || $action == 'delete')
{
- return InvoiceController::archive($publicId);
- }
- else if ($action == 'delete')
- {
- return InvoiceController::delete($publicId);
+ return InvoiceController::bulk();
}
$rules = array(
@@ -299,12 +295,25 @@ class InvoiceController extends \BaseController {
if ($clientPublicId == "-1")
{
$client = Client::createNew();
- $client->name = Input::get('client_name');
+ $client->name = Input::get('name');
+ $client->work_phone = Input::get('work_phone');
+ $client->address1 = Input::get('address1');
+ $client->address2 = Input::get('address2');
+ $client->city = Input::get('city');
+ $client->state = Input::get('state');
+ $client->postal_code = Input::get('postal_code');
+ if (Input::get('country_id')) {
+ $client->country_id = Input::get('country_id');
+ }
$client->save();
$clientId = $client->id;
$contact = Contact::createNew();
- $contact->email = Input::get('client_email');
+ $contact->is_primary = true;
+ $contact->first_name = Input::get('first_name');
+ $contact->last_name = Input::get('last_name');
+ $contact->phone = Input::get('phone');
+ $contact->email = Input::get('email');
$client->contacts()->save($contact);
}
else
@@ -328,14 +337,12 @@ class InvoiceController extends \BaseController {
$client->invoices()->save($invoice);
$items = json_decode(Input::get('items'));
- foreach ($items as $item) {
-
- if (!isset($item->cost))
- {
+ foreach ($items as $item)
+ {
+ if (!isset($item->cost)) {
$item->cost = 0;
}
- if (!isset($item->qty))
- {
+ if (!isset($item->qty)) {
$item->qty = 0;
}
@@ -432,7 +439,7 @@ class InvoiceController extends \BaseController {
public function bulk()
{
$action = Input::get('action');
- $ids = Input::get('ids');
+ $ids = Input::get('id') ? Input::get('id') : Input::get('ids');
$invoices = Invoice::scope($ids)->get();
foreach ($invoices as $invoice) {
@@ -448,3 +455,4 @@ class InvoiceController extends \BaseController {
return Redirect::to('invoices');
}
+}
\ No newline at end of file
diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php
index fa2c49a1bafd..fd9b92345324 100755
--- a/app/controllers/PaymentController.php
+++ b/app/controllers/PaymentController.php
@@ -13,14 +13,18 @@ class PaymentController extends \BaseController
public function getDatatable($clientPublicId = null)
{
- $collection = Payment::scope()->with('invoice', 'client');
+ $query = DB::table('payments')
+ ->join('clients', 'clients.id', '=','payments.client_id')
+ ->leftJoin('invoices', 'invoices.id', '=','payments.invoice_id')
+ ->where('payments.account_id', '=', Auth::user()->account_id)
+ ->where('payments.deleted_at', '=', null)
+ ->select('payments.public_id', 'payments.transaction_reference', 'clients.name as client_name', 'clients.public_id as client_public_id', 'payments.amount', 'payments.payment_date', 'invoices.public_id as invoice_public_id', 'invoices.invoice_number');
if ($clientPublicId) {
- $clientId = Client::getPrivateId($clientPublicId);
- $collection->where('client_id','=',$clientId);
+ $query->where('clients.public_id', '=', $clientPublicId);
}
- $table = Datatable::collection($collection->get());
+ $table = Datatable::query($query);
if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '
'; });
@@ -29,15 +33,15 @@ class PaymentController extends \BaseController
$table->addColumn('transaction_reference', function($model) { return $model->transaction_reference ? $model->transaction_reference : '
Manual entry'; });
if (!$clientPublicId) {
- $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->public_id, $model->client->name); });
+ $table->addColumn('client_name', function($model) { return link_to('clients/' . $model->client_public_id, $model->client_name); });
}
- return $table->addColumn('invoice_number', function($model) { return $model->invoice ? link_to('invoices/' . $model->invoice->public_id . '/edit', $model->invoice->invoice_number) : ''; })
+ return $table->addColumn('invoice_number', function($model) { return $model->invoice_public_id ? link_to('invoices/' . $model->invoice_public_id . '/edit', $model->invoice_invoice_number) : ''; })
->addColumn('amount', function($model) { return '$' . $model->amount; })
- ->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); })
+ ->addColumn('payment_date', function($model) { return timestampToDateString($model->payment_date); })
->addColumn('dropdown', function($model)
{
- return '
+ return '
@@ -49,7 +53,7 @@ class PaymentController extends \BaseController
';
})
- ->orderColumns('client')
+ ->orderColumns('transaction_reference', 'client_name', 'invoice_number', 'amount', 'payment_date')
->make();
}
@@ -131,7 +135,7 @@ class PaymentController extends \BaseController
public function bulk()
{
$action = Input::get('action');
- $ids = Input::get('ids');
+ $ids = Input::get('id') ? Input::get('id') : Input::get('ids');
$payments = Payment::scope($ids)->get();
foreach ($payments as $payment) {
diff --git a/app/models/Account.php b/app/models/Account.php
index 1440541403cd..adae333536d6 100755
--- a/app/models/Account.php
+++ b/app/models/Account.php
@@ -79,7 +79,7 @@ class Account extends Eloquent
public function getNextInvoiceNumber()
{
- $order = Invoice::scope()->orderBy('invoice_number', 'DESC')->first();
+ $order = Invoice::withTrashed()->scope()->orderBy('invoice_number', 'DESC')->first();
if ($order)
{
diff --git a/app/routes.php b/app/routes.php
index 537e1bf92864..aedae406cea3 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -11,6 +11,7 @@
|
*/
+//dd(DB::getQueryLog());
//dd(Client::getPrivateId(1));
Route::get('/', 'HomeController@showWelcome');
@@ -48,14 +49,16 @@ Route::group(array('before' => 'auth'), function()
Route::get('invoices/create/{client_id}', 'InvoiceController@create');
Route::post('invoices/bulk', 'InvoiceController@bulk');
+ Route::get('payments/{id}/edit', function() { return View::make('header'); });
Route::resource('payments', 'PaymentController');
Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable'));
Route::post('payments/bulk', 'PaymentController@bulk');
-
+
+ Route::get('credits/{id}/edit', function() { return View::make('header'); });
Route::resource('credits', 'CreditController');
Route::get('api/credits/{client_id?}', array('as'=>'api.credits', 'uses'=>'CreditController@getDatatable'));
Route::post('credits/bulk', 'PaymentController@bulk');
-
+
Route::get('reports', function() { return View::make('header'); });
});
diff --git a/app/views/client.blade.php b/app/views/client.blade.php
new file mode 100755
index 000000000000..5eb30ac51eb8
--- /dev/null
+++ b/app/views/client.blade.php
@@ -0,0 +1,97 @@
+
+
+
+
+ {{ Former::legend('Organization') }}
+ {{ Former::text('name') }}
+ {{ Former::text('work_phone')->label('Phone') }}
+ {{ Former::textarea('notes') }}
+
+
+ {{ Former::legend('Address') }}
+ {{ Former::text('address1')->label('Street') }}
+ {{ Former::text('address2')->label('Apt/Floor') }}
+ {{ Former::text('city') }}
+ {{ Former::text('state') }}
+ {{ Former::text('postal_code') }}
+ {{ Former::select('country_id')->addOption('','')->label('Country')
+ ->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }}
+
+
+
+
+
+ {{ Former::legend('Contacts') }}
+
+ {{ Former::hidden('public_id')->data_bind("value: public_id, valueUpdate: 'afterkeydown'") }}
+ {{ Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown'") }}
+ {{ Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown'") }}
+ {{ Former::text('email')->data_bind("value: email, valueUpdate: 'afterkeydown'") }}
+ {{ Former::text('phone')->data_bind("value: phone, valueUpdate: 'afterkeydown'") }}
+
+
+
+
+
+
+
+
+
+{{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }}
+
+
+
diff --git a/app/views/clients/edit.blade.php b/app/views/clients/edit.blade.php
index 75912ed095c5..7ec8de565213 100755
--- a/app/views/clients/edit.blade.php
+++ b/app/views/clients/edit.blade.php
@@ -18,7 +18,7 @@
{{ Former::populate($client) }}
@endif
-
+
@@ -70,13 +70,6 @@
{{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }}
-
- {{ Button::lg_primary_submit('Save') }} |
- {{ link_to('clients/' . ($client ? $client->public_id : ''), 'Cancel') }}
-
-
- {{ Former::close() }}
-
+
+
+
+ {{ Button::lg_primary_submit('Save') }} |
+ {{ link_to('clients/' . ($client ? $client->public_id : ''), 'Cancel') }}
+
+
+ {{ Former::close() }}
+
@stop
\ No newline at end of file
diff --git a/app/views/clients/show.blade.php b/app/views/clients/show.blade.php
index 0d5b76032878..c7d371f7bb73 100755
--- a/app/views/clients/show.blade.php
+++ b/app/views/clients/show.blade.php
@@ -73,7 +73,7 @@
->setUrl(url('api/activities/'. $client->public_id))
->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false)
- ->render() }}
+ ->render('datatable') }}
@@ -84,7 +84,7 @@
->setUrl(url('api/invoices/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false)
- ->render() }}
+ ->render('datatable') }}
@@ -94,7 +94,7 @@
->setUrl(url('api/payments/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false)
- ->render() }}
+ ->render('datatable') }}
@@ -104,7 +104,7 @@
->setUrl(url('api/credits/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false)
- ->render() }}
+ ->render('datatable') }}
diff --git a/app/views/datatable.blade.php b/app/views/datatable.blade.php
index 165c82cab8c6..cdf061671bd1 100755
--- a/app/views/datatable.blade.php
+++ b/app/views/datatable.blade.php
@@ -8,7 +8,7 @@
@foreach($columns as $i => $c)
- @if ($c == 'checkbox' && $haeCheckboxes = true)
+ @if ($c == 'checkbox' && $hasCheckboxes = true)
@else
{{ $c }}
@@ -32,7 +32,7 @@
// dynamic table
jQuery('.{{ $class }}').dataTable({
// Disable sorting on the first column
- @if ($haeCheckboxes)
+ @if (isset($haeCheckboxes) && $hasCheckboxes)
"aoColumnDefs" : [ {
'bSortable' : false,
'aTargets' : [ 0 ]
diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php
index 40021141789d..d6885947d524 100755
--- a/app/views/invoices/edit.blade.php
+++ b/app/views/invoices/edit.blade.php
@@ -4,7 +4,6 @@
-
{{ Former::open($url)->method($method)->addClass('main_form')->rules(array(
'invoice_number' => 'required',
'invoice_date' => 'required',
@@ -15,6 +14,7 @@
@if ($invoice)
{{ Former::populate($invoice); }}
+ {{ Former::populateField('id', $invoice->public_id); }}
{{ Former::populateField('invoice_date', fromSqlDate($invoice->invoice_date)); }}
{{ Former::populateField('due_date', fromSqlDate($invoice->due_date)); }}
@else
@@ -25,7 +25,7 @@
{{ Former::select('client')->addOption('', '')->fromQuery($clients, 'name', 'public_id')->select($client ? $client->public_id : '')
- ->help(' Create new client') }}
+ ->help(' Create new client') }}
{{ Former::textarea('notes') }}
|