Partitioned account data

This commit is contained in:
Hillel Coren 2013-12-04 18:20:14 +02:00
parent 99800f38dd
commit 4f099c1fa5
28 changed files with 333 additions and 209 deletions

View File

@ -12,8 +12,8 @@ otherwise billable time invested in writing this and other freely available,
open-source software. open-source software.
1. Redistributions of source code, in whole or part and with or without 1. Redistributions of source code, in whole or part and with or without
modification (the "Code"), must prominently display "Powered by InvoiceNinja.com" modification the website must prominently display "Powered by InvoiceNinja"
in verifiable form with a link to said site. in verifiable form with hyperlink to said site.
2. Neither the name nor any trademark of the Author may be used to 2. Neither the name nor any trademark of the Author may be used to
endorse or promote products derived from this software without specific endorse or promote products derived from this software without specific
prior written permission. prior written permission.

View File

@ -23,7 +23,7 @@ class AccountController extends \BaseController {
{ {
$account = new Account; $account = new Account;
$account->ip = Request::getClientIp(); $account->ip = Request::getClientIp();
$account->key = str_random(20); $account->account_key = str_random(20);
$account->save(); $account->save();
$random = str_random(20); $random = str_random(20);
@ -377,6 +377,9 @@ class AccountController extends \BaseController {
$account = Account::findOrFail(Auth::user()->account_id); $account = Account::findOrFail(Auth::user()->account_id);
$account->account_gateways()->forceDelete(); $account->account_gateways()->forceDelete();
$account->invoice_terms = Input::get('invoice_terms');
$account->save();
if ($gatewayId) if ($gatewayId)
{ {
$accountGateway = new AccountGateway; $accountGateway = new AccountGateway;
@ -441,8 +444,8 @@ class AccountController extends \BaseController {
if ($file = Input::file('logo')) if ($file = Input::file('logo'))
{ {
$path = Input::file('logo')->getRealPath(); $path = Input::file('logo')->getRealPath();
File::delete('logo/' . $account->key . '.jpg'); File::delete('logo/' . $account->account_key . '.jpg');
Image::make($path)->resize(150, 100, true, false)->save('logo/' . $account->key . '.jpg'); Image::make($path)->resize(150, 100, true, false)->save('logo/' . $account->account_key . '.jpg');
} }
Session::flash('message', 'Successfully updated details'); Session::flash('message', 'Successfully updated details');

View File

@ -2,8 +2,10 @@
class ActivityController extends \BaseController { class ActivityController extends \BaseController {
public function getDatatable($clientId) public function getDatatable($clientPublicId)
{ {
$clientId = Client::getPrivateId($clientPublicId);
return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get()) return Datatable::collection(Activity::scope()->where('client_id','=',$clientId)->get())
->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); }) ->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); })
->addColumn('message', function($model) { return $model->message; }) ->addColumn('message', function($model) { return $model->message; })

View File

@ -24,8 +24,8 @@ class ClientController extends \BaseController {
$clients = Client::scope()->with('contacts')->get(); $clients = Client::scope()->with('contacts')->get();
return Datatable::collection($clients) return Datatable::collection($clients)
->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; }) ->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; })
->addColumn('name', function($model) { return link_to('clients/' . $model->id, $model->name); }) ->addColumn('name', function($model) { return link_to('clients/' . $model->public_id, $model->name); })
->addColumn('contact', function($model) { return $model->contacts[0]->getFullName(); }) ->addColumn('contact', function($model) { return $model->contacts[0]->getFullName(); })
->addColumn('balance', function($model) { return '$' . $model->balance; }) ->addColumn('balance', function($model) { return '$' . $model->balance; })
->addColumn('last_login', function($model) { return $model->contacts[0]->getLastLogin(); }) ->addColumn('last_login', function($model) { return $model->contacts[0]->getLastLogin(); })
@ -39,11 +39,11 @@ class ClientController extends \BaseController {
Select <span class="caret"></span> Select <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('invoices/create/'.$model->id) . '">New Invoice</a></li> <li><a href="' . URL::to('invoices/create/'.$model->public_id) . '">New Invoice</a></li>
<li><a href="' . URL::to('clients/'.$model->id.'/edit') . '">Edit Client</a></li> <li><a href="' . URL::to('clients/'.$model->public_id.'/edit') . '">Edit Client</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a href="' . URL::to('clients/'.$model->id.'/archive') . '">Archive Client</a></li> <li><a href="' . URL::to('clients/'.$model->public_id.'/archive') . '">Archive Client</a></li>
<li><a href="javascript:deleteEntity(' . $model->id. ')">Delete Client</a></li> <li><a href="javascript:deleteEntity(' . $model->public_id. ')">Delete Client</a></li>
</ul> </ul>
</div>'; </div>';
}) })
@ -84,9 +84,9 @@ class ClientController extends \BaseController {
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function show($id) public function show($publicId)
{ {
$client = Client::scope()->with('contacts')->findOrFail($id); $client = Client::scope($publicId)->with('contacts')->firstOrFail();
trackViewed($client->name); trackViewed($client->name);
$data = array( $data = array(
@ -102,13 +102,13 @@ class ClientController extends \BaseController {
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function edit($id) public function edit($publicId)
{ {
$client = Client::scope()->with('contacts')->findOrFail($id); $client = Client::scope($publicId)->with('contacts')->firstOrFail();
$data = array( $data = array(
'client' => $client, 'client' => $client,
'method' => 'PUT', 'method' => 'PUT',
'url' => 'clients/' . $id, 'url' => 'clients/' . $publicId,
'title' => '- ' . $client->name, 'title' => '- ' . $client->name,
'countries' => Country::orderBy('name')->get()); 'countries' => Country::orderBy('name')->get());
return View::make('clients.edit', $data); return View::make('clients.edit', $data);
@ -120,12 +120,12 @@ class ClientController extends \BaseController {
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function update($id) public function update($publicId)
{ {
return $this->save($id); return $this->save($publicId);
} }
private function save($id = null) private function save($publicId = null)
{ {
$rules = array( $rules = array(
'name' => 'required' 'name' => 'required'
@ -133,15 +133,14 @@ class ClientController extends \BaseController {
$validator = Validator::make(Input::all(), $rules); $validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) { if ($validator->fails()) {
return Redirect::to('clients/' . $id . '/edit') return Redirect::to('clients/' . $publicId . '/edit')
->withErrors($validator) ->withErrors($validator)
->withInput(Input::except('password')); ->withInput(Input::except('password'));
} else { } else {
if ($id) { if ($publicId) {
$client = Client::scope()->findOrFail($id); $client = Client::scope($publicId)->firstOrFail();
} else { } else {
$client = new Client; $client = Client::createNew();
$client->account_id = Auth::user()->account_id;
} }
$client->name = Input::get('name'); $client->name = Input::get('name');
@ -164,11 +163,11 @@ class ClientController extends \BaseController {
{ {
if (isset($contact->id) && $contact->id) if (isset($contact->id) && $contact->id)
{ {
$record = Contact::findOrFail($contact->id); $record = Contact::scope($contact->id)->firstOrFail();
} }
else else
{ {
$record = new Contact; $record = Contact::createNew();
} }
$record->email = $contact->email; $record->email = $contact->email;
@ -189,7 +188,7 @@ class ClientController extends \BaseController {
} }
Session::flash('message', 'Successfully updated client'); Session::flash('message', 'Successfully updated client');
return Redirect::to('clients/' . $client->id); return Redirect::to('clients/' . $client->public_id);
} }
} }
@ -198,7 +197,7 @@ class ClientController extends \BaseController {
{ {
$action = Input::get('action'); $action = Input::get('action');
$ids = Input::get('ids') ? Input::get('ids') : [Input::get('id')]; $ids = Input::get('ids') ? Input::get('ids') : [Input::get('id')];
$clients = Client::scope()->findOrFail($ids); $clients = Client::scope($ids)->get();
foreach ($clients as $client) { foreach ($clients as $client) {
if ($action == 'archive') { if ($action == 'archive') {
@ -214,9 +213,9 @@ class ClientController extends \BaseController {
return Redirect::to('clients'); return Redirect::to('clients');
} }
public function archive($id) public function archive($publicId)
{ {
$client = Client::scope()->findOrFail($id); $client = Client::scope($publicId)->firstOrFail();
$client->delete(); $client->delete();
foreach ($client->invoices as $invoice) foreach ($client->invoices as $invoice)
@ -230,7 +229,7 @@ class ClientController extends \BaseController {
public function delete($id) public function delete($id)
{ {
$client = Client::scope()->findOrFail($id); $client = Client::scope($publicId)->firstOrFail();
$client->forceDelete(); $client->forceDelete();
Session::flash('message', 'Successfully deleted ' . $client->name); Session::flash('message', 'Successfully deleted ' . $client->name);

View File

@ -16,24 +16,25 @@ class CreditController extends \BaseController {
)); ));
} }
public function getDatatable($clientId = null) public function getDatatable($clientPublicId = null)
{ {
$collection = Credit::scope()->with('client'); $collection = Credit::scope()->with('client');
if ($clientId) { if ($clientPublicId) {
$clientId = Client::getPrivateId($clientPublicId);
$collection->where('client_id','=',$clientId); $collection->where('client_id','=',$clientId);
} }
$table = Datatable::collection($collection->get()); $table = Datatable::collection($collection->get());
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; }); $table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
} }
$table->addColumn('credit_number', function($model) { return $model->credit_number; }); $table->addColumn('credit_number', function($model) { return $model->credit_number; });
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); }); $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->public_id, $model->client->name); });
} }
return $table->addColumn('amount', function($model){ return '$' . money_format('%i', $model->amount); }) return $table->addColumn('amount', function($model){ return '$' . money_format('%i', $model->amount); })
@ -42,18 +43,18 @@ class CreditController extends \BaseController {
->make(); ->make();
} }
public function archive($id) public function archive($publicId)
{ {
$credit = Credit::scope()->findOrFail($id); $credit = Credit::scope($publicId)->firstOrFail();
$creidt->delete(); $creidt->delete();
Session::flash('message', 'Successfully archived credit ' . $credit->credit_number); Session::flash('message', 'Successfully archived credit ' . $credit->credit_number);
return Redirect::to('credits'); return Redirect::to('credits');
} }
public function delete($id) public function delete($publicId)
{ {
$credit = Credit::scope()->findOrFail($id); $credit = Credit::scope($publicId)->firstOrFail();
$credit->forceDelete(); $credit->forceDelete();
Session::flash('message', 'Successfully deleted credit ' . $credit->credit_number); Session::flash('message', 'Successfully deleted credit ' . $credit->credit_number);

View File

@ -16,24 +16,25 @@ class InvoiceController extends \BaseController {
)); ));
} }
public function getDatatable($clientId = null) public function getDatatable($clientPublicId = null)
{ {
$collection = Invoice::scope()->with('client','invoice_items','invoice_status'); $collection = Invoice::scope()->with('client','invoice_items','invoice_status');
if ($clientId) { if ($clientPublicId) {
$clientId = Client::getPrivateId($clientPublicId);
$collection->where('client_id','=',$clientId); $collection->where('client_id','=',$clientId);
} }
$table = Datatable::collection($collection->get()); $table = Datatable::collection($collection->get());
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; }); $table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
} }
$table->addColumn('invoice_number', function($model) { return link_to('invoices/' . $model->id . '/edit', $model->invoice_number); }); $table->addColumn('invoice_number', function($model) { return link_to('invoices/' . $model->public_id . '/edit', $model->invoice_number); });
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client->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->getTotal()); }) return $table->addColumn('total', function($model){ return '$' . money_format('%i', $model->getTotal()); })
@ -48,10 +49,10 @@ class InvoiceController extends \BaseController {
Select <span class="caret"></span> Select <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('invoices/'.$model->id.'/edit') . '">Edit Invoice</a></li> <li><a href="' . URL::to('invoices/'.$model->public_id.'/edit') . '">Edit Invoice</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a href="' . URL::to('invoices/'.$model->id.'/archive') . '">Archive Invoice</a></li> <li><a href="' . URL::to('invoices/'.$model->public_id.'/archive') . '">Archive Invoice</a></li>
<li><a href="javascript:deleteEntity(' . $model->id . ')">Delete Invoice</a></li> <li><a href="javascript:deleteEntity(' . $model->public_id . ')">Delete Invoice</a></li>
</ul> </ul>
</div>'; </div>';
}) })
@ -60,10 +61,10 @@ class InvoiceController extends \BaseController {
} }
public function view($key) public function view($invitationKey)
{ {
$invitation = Invitation::with('user', 'invoice.account', 'invoice.invoice_items', 'invoice.client.account.account_gateways') $invitation = Invitation::with('user', 'invoice.account', 'invoice.invoice_items', 'invoice.client.account.account_gateways')
->where('key', '=', $key)->firstOrFail(); ->where('invitation_key', '=', $invitationKey)->firstOrFail();
$user = $invitation->user; $user = $invitation->user;
$invoice = $invitation->invoice; $invoice = $invitation->invoice;
@ -124,9 +125,9 @@ class InvoiceController extends \BaseController {
]; ];
} }
public function show_payment($invoiceKey) public function show_payment($invitationKey)
{ {
$invoice = Invoice::with('invoice_items', 'client.account.account_gateways.gateway')->where('key', '=', $invoiceKey)->firstOrFail(); $invoice = Invoice::with('invoice_items', 'client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$accountGateway = $invoice->client->account->account_gateways[0]; $accountGateway = $invoice->client->account->account_gateways[0];
$gateway = InvoiceController::createGateway($accountGateway); $gateway = InvoiceController::createGateway($accountGateway);
@ -208,32 +209,32 @@ class InvoiceController extends \BaseController {
} }
public function edit($id) public function edit($publicId)
{ {
$invoice = Invoice::scope()->with('account.country', 'client', 'invoice_items')->findOrFail($id); $invoice = Invoice::scope($publicId)->with('account.country', 'client', 'invoice_items')->firstOrFail();
trackViewed($invoice->invoice_number . ' - ' . $invoice->client->name); trackViewed($invoice->invoice_number . ' - ' . $invoice->client->name);
$data = array( $data = array(
'account' => $invoice->account, 'account' => $invoice->account,
'invoice' => $invoice, 'invoice' => $invoice,
'method' => 'PUT', 'method' => 'PUT',
'url' => 'invoices/' . $id, 'url' => 'invoices/' . $publicId,
'title' => '- ' . $invoice->invoice_number, 'title' => '- ' . $invoice->invoice_number,
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->get(array('key','notes','cost','qty')), 'products' => Product::scope()->get(array('product_key','notes','cost','qty')),
'client' => $invoice->client, 'client' => $invoice->client,
'clients' => Client::scope()->orderBy('name')->get()); 'clients' => Client::scope()->orderBy('name')->get());
return View::make('invoices.edit', $data); return View::make('invoices.edit', $data);
} }
public function create($clientId = 0) public function create($clientPublicId = 0)
{ {
$client = null; $client = null;
$invoiceNumber = Auth::user()->account->getNextInvoiceNumber(); $invoiceNumber = Auth::user()->account->getNextInvoiceNumber();
$account = Account::with('country')->findOrFail(Auth::user()->account_id); $account = Account::with('country')->findOrFail(Auth::user()->account_id);
if ($clientId) { if ($clientPublicId) {
$client = Client::scope()->findOrFail($clientId); $client = Client::scope($clientPublicId)->firstOrFail();
} }
$data = array( $data = array(
@ -246,7 +247,7 @@ class InvoiceController extends \BaseController {
'client' => $client, 'client' => $client,
'items' => json_decode(Input::old('items')), 'items' => json_decode(Input::old('items')),
'account' => Auth::user()->account, 'account' => Auth::user()->account,
'products' => Product::scope()->get(array('key','notes','cost','qty')), 'products' => Product::scope()->get(array('product_key','notes','cost','qty')),
'clients' => Client::scope()->orderBy('name')->get()); 'clients' => Client::scope()->orderBy('name')->get());
return View::make('invoices.edit', $data); return View::make('invoices.edit', $data);
} }
@ -261,17 +262,17 @@ class InvoiceController extends \BaseController {
return InvoiceController::save(); return InvoiceController::save();
} }
private function save($id = null) private function save($publicId = null)
{ {
$action = Input::get('action'); $action = Input::get('action');
if ($action == 'archive') if ($action == 'archive')
{ {
return InvoiceController::archive($id); return InvoiceController::archive($publicId);
} }
else if ($action == 'delete') else if ($action == 'delete')
{ {
return InvoiceController::delete($id); return InvoiceController::delete($publicId);
} }
$rules = array( $rules = array(
@ -287,40 +288,38 @@ class InvoiceController extends \BaseController {
->withErrors($validator); ->withErrors($validator);
} else { } else {
$clientId = Input::get('client'); $clientPublicId = Input::get('client');
if ($clientId == "-1") if ($clientPublicId == "-1")
{ {
$client = new Client; $client = Client::createNew();
$client->name = Input::get('client_name'); $client->name = Input::get('client_name');
$client->account_id = Auth::user()->account_id;
$client->save(); $client->save();
$clientId = $client->id; $clientId = $client->id;
$contact = new Contact; $contact = Contact::createNew();
$contact->email = Input::get('client_email'); $contact->email = Input::get('client_email');
$client->contacts()->save($contact); $client->contacts()->save($contact);
} }
else else
{ {
$client = Client::scope()->with('contacts')->findOrFail($clientId); $client = Client::scope($clientPublicId)->with('contacts')->firstOrFail();
$contact = $client->contacts()->first(); $contact = $client->contacts()->first();
} }
if ($id) { if ($publicId) {
$invoice = Invoice::scope()->findOrFail($id); $invoice = Invoice::scope($publicId)->firstOrFail();
$invoice->invoice_items()->forceDelete(); $invoice->invoice_items()->forceDelete();
} else { } else {
$invoice = new Invoice; $invoice = Invoice::createNew();
$invoice->account_id = Auth::user()->account_id;
} }
$invoice->client_id = $clientId;
$invoice->invoice_number = Input::get('invoice_number'); $invoice->invoice_number = Input::get('invoice_number');
$invoice->discount = 0; $invoice->discount = 0;
$invoice->invoice_date = toSqlDate(Input::get('invoice_date')); $invoice->invoice_date = toSqlDate(Input::get('invoice_date'));
$invoice->due_date = toSqlDate(Input::get('due_date')); $invoice->due_date = toSqlDate(Input::get('due_date'));
$invoice->save(); $invoice->notes = Input::get('notes');
$client->invoices()->save($invoice);
$items = json_decode(Input::get('items')); $items = json_decode(Input::get('items'));
foreach ($items as $item) { foreach ($items as $item) {
@ -345,9 +344,8 @@ class InvoiceController extends \BaseController {
if (!$product) if (!$product)
{ {
$product = new Product; $product = Product::createNew();
$product->account_id = Auth::user()->account_id; $product->product_key = $item->product_key;
$product->key = $item->product_key;
} }
/* /*
@ -359,7 +357,7 @@ class InvoiceController extends \BaseController {
$product->save(); $product->save();
} }
$invoiceItem = new InvoiceItem; $invoiceItem = InvoiceItem::createNew();
$invoiceItem->product_id = isset($product) ? $product->id : null; $invoiceItem->product_id = isset($product) ? $product->id : null;
$invoiceItem->product_key = $item->product_key; $invoiceItem->product_key = $item->product_key;
$invoiceItem->notes = $item->notes; $invoiceItem->notes = $item->notes;
@ -380,11 +378,11 @@ class InvoiceController extends \BaseController {
}); });
*/ */
$invitation = new Invitation; $invitation = Invitation::createNew();
$invitation->invoice_id = $invoice->id; $invitation->invoice_id = $invoice->id;
$invitation->user_id = Auth::user()->id; $invitation->user_id = Auth::user()->id;
$invitation->contact_id = $contact->id; $invitation->contact_id = $contact->id;
$invitation->key = str_random(20); $invitation->invitation_key = str_random(20);
$invitation->save(); $invitation->save();
Session::flash('message', 'Successfully emailed invoice'); Session::flash('message', 'Successfully emailed invoice');
@ -392,8 +390,7 @@ class InvoiceController extends \BaseController {
Session::flash('message', 'Successfully saved invoice'); Session::flash('message', 'Successfully saved invoice');
} }
$url = 'invoices/' . $invoice->id . '/edit'; $url = 'invoices/' . $invoice->public_id . '/edit';
processedRequest($url);
return Redirect::to($url); return Redirect::to($url);
} }
} }
@ -404,12 +401,9 @@ class InvoiceController extends \BaseController {
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function show($id) public function show($publicId)
{ {
return Redirect::to('invoices/'.$id.'/edit'); return Redirect::to('invoices/'.$publicId.'/edit');
//$invoice = Invoice::find($id);
//return View::make('invoices.show')->with('invoice', $invoice);
} }
/** /**
@ -418,9 +412,9 @@ class InvoiceController extends \BaseController {
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function update($id) public function update($publicId)
{ {
return InvoiceController::save($id); return InvoiceController::save($publicId);
} }
/** /**
@ -433,7 +427,7 @@ class InvoiceController extends \BaseController {
{ {
$action = Input::get('action'); $action = Input::get('action');
$ids = Input::get('ids'); $ids = Input::get('ids');
$invoices = Invoice::scope()->findOrFail($ids); $invoices = Invoice::scope($ids)->get();
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if ($action == 'archive') { if ($action == 'archive') {
@ -449,18 +443,18 @@ class InvoiceController extends \BaseController {
return Redirect::to('invoices'); return Redirect::to('invoices');
} }
public function archive($id) public function archive($publicId)
{ {
$invoice = Invoice::scope()->findOrFail($id); $invoice = Invoice::scope($publicId)->firstOrFail();
$invoice->delete(); $invoice->delete();
Session::flash('message', 'Successfully archived invoice ' . $invoice->invoice_number); Session::flash('message', 'Successfully archived invoice ' . $invoice->invoice_number);
return Redirect::to('invoices'); return Redirect::to('invoices');
} }
public function delete($id) public function delete($publicId)
{ {
$invoice = Invoice::scope()->findOrFail($id); $invoice = Invoice::scope($publicId)->firstOrFail();
$invoice->forceDelete(); $invoice->forceDelete();
Session::flash('message', 'Successfully deleted invoice ' . $invoice->invoice_number); Session::flash('message', 'Successfully deleted invoice ' . $invoice->invoice_number);

View File

@ -11,24 +11,25 @@ class PaymentController extends \BaseController
)); ));
} }
public function getDatatable($clientId = null) public function getDatatable($clientPublicId = null)
{ {
$collection = Payment::scope()->with('invoice.client'); $collection = Payment::scope()->with('invoice.client');
if ($clientId) { if ($clientPublicId) {
$clientId = Client::getPrivateId($clientPublicId);
$collection->where('client_id','=',$clientId); $collection->where('client_id','=',$clientId);
} }
$table = Datatable::collection($collection->get()); $table = Datatable::collection($collection->get());
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->id . '">'; }); $table->addColumn('checkbox', function($model) { return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">'; });
} }
$table->addColumn('transaction_reference', function($model) { return $model->transaction_reference; }); $table->addColumn('transaction_reference', function($model) { return $model->transaction_reference; });
if (!$clientId) { if (!$clientPublicId) {
$table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); }); $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->public_id, $model->client->name); });
} }
return $table->addColumn('amount', function($model) { return '$' . $model->amount; }) return $table->addColumn('amount', function($model) { return '$' . $model->amount; })
@ -37,18 +38,42 @@ class PaymentController extends \BaseController
->make(); ->make();
} }
public function archive($id)
public function create()
{ {
$payment = Payment::scope()->findOrFail($id); $data = array(
'payment' => null,
'method' => 'POST',
'url' => 'payments',
'title' => '- New Payment');
return View::make('payments.edit', $data);
}
public function edit($publicId)
{
$payment = Payment::scope($publicId)->firstOrFail();
$data = array(
'payment' => $payment,
'method' => 'PUT',
'url' => 'payments/' . $publicId,
'title' => '- Edit Payment');
return View::make('payments.edit', $data);
}
public function archive($publicId)
{
$payment = Payment::scope($publicId)->firstOrFail();
$payment->delete(); $payment->delete();
Session::flash('message', 'Successfully archived payment'); Session::flash('message', 'Successfully archived payment');
return Redirect::to('payments'); return Redirect::to('payments');
} }
public function delete($id) public function delete($publicId)
{ {
$payment = Payment::scope()->findOrFail($id); $payment = Payment::scope($publicId)->firstOrFail();
$payment->forceDelete(); $payment->forceDelete();
Session::flash('message', 'Successfully deleted payment'); Session::flash('message', 'Successfully deleted payment');

View File

@ -64,8 +64,7 @@ class ConfideSetupUsersTable extends Migration {
$t->string('name'); $t->string('name');
$t->string('ip'); $t->string('ip');
$t->string('logo_path'); $t->string('account_key')->unique();
$t->string('key')->unique();
$t->timestamp('last_login'); $t->timestamp('last_login');
$t->string('address1'); $t->string('address1');
@ -74,6 +73,7 @@ class ConfideSetupUsersTable extends Migration {
$t->string('state'); $t->string('state');
$t->string('postal_code'); $t->string('postal_code');
$t->unsignedInteger('country_id')->nullable(); $t->unsignedInteger('country_id')->nullable();
$t->text('invoice_terms');
$t->foreign('timezone_id')->references('id')->on('timezones'); $t->foreign('timezone_id')->references('id')->on('timezones');
$t->foreign('country_id')->references('id')->on('countries'); $t->foreign('country_id')->references('id')->on('countries');
@ -123,6 +123,9 @@ class ConfideSetupUsersTable extends Migration {
$t->boolean('confirmed')->default(false); $t->boolean('confirmed')->default(false);
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('password_reminders', function($t) Schema::create('password_reminders', function($t)
@ -154,11 +157,15 @@ class ConfideSetupUsersTable extends Migration {
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$t->foreign('country_id')->references('id')->on('countries'); $t->foreign('country_id')->references('id')->on('countries');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('contacts', function($t) Schema::create('contacts', function($t)
{ {
$t->increments('id'); $t->increments('id');
$t->unsignedInteger('account_id');
$t->unsignedInteger('client_id'); $t->unsignedInteger('client_id');
$t->timestamps(); $t->timestamps();
$t->softDeletes(); $t->softDeletes();
@ -170,6 +177,9 @@ class ConfideSetupUsersTable extends Migration {
$t->timestamp('last_login'); $t->timestamp('last_login');
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('invoice_statuses', function($t) Schema::create('invoice_statuses', function($t)
@ -192,20 +202,25 @@ class ConfideSetupUsersTable extends Migration {
$t->float('discount'); $t->float('discount');
$t->date('invoice_date'); $t->date('invoice_date');
$t->date('due_date'); $t->date('due_date');
$t->text('notes');
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$t->foreign('account_id')->references('id')->on('accounts'); $t->foreign('account_id')->references('id')->on('accounts');
$t->foreign('invoice_status_id')->references('id')->on('invoice_statuses'); $t->foreign('invoice_status_id')->references('id')->on('invoice_statuses');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('invitations', function($t) Schema::create('invitations', function($t)
{ {
$t->increments('id'); $t->increments('id');
$t->unsignedInteger('account_id');
$t->unsignedInteger('user_id'); $t->unsignedInteger('user_id');
$t->unsignedInteger('contact_id'); $t->unsignedInteger('contact_id');
$t->unsignedInteger('invoice_id'); $t->unsignedInteger('invoice_id');
$t->string('key')->unique(); $t->string('invitation_key')->unique();
$t->timestamps(); $t->timestamps();
$t->softDeletes(); $t->softDeletes();
@ -214,6 +229,9 @@ class ConfideSetupUsersTable extends Migration {
$t->foreign('user_id')->references('id')->on('users'); $t->foreign('user_id')->references('id')->on('users');
$t->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); $t->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade');
$t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('products', function($t) Schema::create('products', function($t)
@ -223,18 +241,22 @@ class ConfideSetupUsersTable extends Migration {
$t->timestamps(); $t->timestamps();
$t->softDeletes(); $t->softDeletes();
$t->string('key'); $t->string('product_key');
$t->string('notes'); $t->string('notes');
$t->decimal('cost', 10, 2); $t->decimal('cost', 10, 2);
$t->integer('qty'); $t->integer('qty');
$t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('invoice_items', function($t) Schema::create('invoice_items', function($t)
{ {
$t->increments('id'); $t->increments('id');
$t->unsignedInteger('account_id');
$t->unsignedInteger('invoice_id'); $t->unsignedInteger('invoice_id');
$t->unsignedInteger('product_id')->nullable(); $t->unsignedInteger('product_id')->nullable();
$t->timestamps(); $t->timestamps();
@ -247,6 +269,9 @@ class ConfideSetupUsersTable extends Migration {
$t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
$t->foreign('product_id')->references('id')->on('products'); $t->foreign('product_id')->references('id')->on('products');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('payments', function($t) Schema::create('payments', function($t)
@ -270,6 +295,9 @@ class ConfideSetupUsersTable extends Migration {
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$t->foreign('contact_id')->references('id')->on('contacts'); $t->foreign('contact_id')->references('id')->on('contacts');
$t->foreign('user_id')->references('id')->on('users'); $t->foreign('user_id')->references('id')->on('users');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('credits', function($t) Schema::create('credits', function($t)
@ -288,6 +316,9 @@ class ConfideSetupUsersTable extends Migration {
$t->foreign('account_id')->references('id')->on('accounts'); $t->foreign('account_id')->references('id')->on('accounts');
$t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$t->foreign('contact_id')->references('id')->on('contacts'); $t->foreign('contact_id')->references('id')->on('contacts');
$t->unsignedInteger('public_id');
$t->unique( array('account_id','public_id') );
}); });
Schema::create('activities', function($t) Schema::create('activities', function($t)

View File

@ -62,7 +62,7 @@ class Account extends Eloquent
public function getLogoPath() public function getLogoPath()
{ {
return 'logo/' . $this->key . '.jpg'; return 'logo/' . $this->account_key . '.jpg';
} }
public function getLogoWidth() public function getLogoWidth()
@ -79,7 +79,7 @@ class Account extends Eloquent
public function getNextInvoiceNumber() public function getNextInvoiceNumber()
{ {
$order = $this->invoices()->orderBy('invoice_number', 'DESC')->first(); $order = Invoice::scope()->orderBy('invoice_number', 'DESC')->first();
if ($order) if ($order)
{ {

View File

@ -18,6 +18,8 @@ define("ACTIVITY_TYPE_DELETE_CREDIT", 14);
class Activity extends Eloquent class Activity extends Eloquent
{ {
protected $hidden = array('id');
public function scopeScope($query) public function scopeScope($query)
{ {
return $query->whereAccountId(Auth::user()->account_id); return $query->whereAccountId(Auth::user()->account_id);

View File

@ -1,9 +1,8 @@
<?php <?php
class Client extends Eloquent implements iEntity class Client extends EntityModel
{ {
protected $softDelete = true; protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at', 'notes', 'last_login');
protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'notes', 'last_login');
public static $fieldName = 'Client - Name'; public static $fieldName = 'Client - Name';
public static $fieldPhone = 'Client - Phone'; public static $fieldPhone = 'Client - Phone';
@ -15,11 +14,6 @@ class Client extends Eloquent implements iEntity
public static $fieldNotes = 'Client - Notes'; public static $fieldNotes = 'Client - Notes';
public static $fieldCountry = 'Client - Country'; public static $fieldCountry = 'Client - Country';
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public function account() public function account()
{ {
return $this->belongsTo('Account'); return $this->belongsTo('Account');

View File

@ -1,8 +1,8 @@
<?php <?php
class Contact extends Eloquent implements iPerson class Contact extends EntityModel
{ {
protected $softDelete = true; protected $hidden = array('id', 'cliend_id', 'created_at', 'updated_at', 'deleted_at', 'last_login');
public static $fieldFirstName = 'Contact - First Name'; public static $fieldFirstName = 'Contact - First Name';
public static $fieldLastName = 'Contact - Last Name'; public static $fieldLastName = 'Contact - Last Name';

View File

@ -1,14 +1,7 @@
<?php <?php
class Credit extends Eloquent implements iEntity class Credit extends EntityModel
{ {
protected $softDelete = true;
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public function invoice() public function invoice()
{ {
return $this->belongsTo('Invoice'); return $this->belongsTo('Invoice');

57
app/models/EntityModel.php Executable file
View File

@ -0,0 +1,57 @@
<?php
class EntityModel extends Eloquent
{
protected $softDelete = true;
protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at');
public static function createNew()
{
$className = get_called_class();
$entity = new $className();
$entity->account_id = Auth::user()->account_id;
$lastEntity = $className::scope()->orderBy('public_id', 'DESC')->first();
if ($lastEntity)
{
$entity->public_id = $lastEntity->public_id + 1;
}
else
{
$entity->public_id = 1;
}
return $entity;
}
public static function getPrivateId($publicId)
{
$className = get_called_class();
return $className::scope($publicId)->pluck('id');
}
public function getNmae()
{
return '';
}
public function scopeScope($query, $publicId = false)
{
$query->whereAccountId(Auth::user()->account_id);
if ($publicId)
{
if (is_array($publicId))
{
$query->whereIn('public_id', $publicId);
}
else
{
$query->wherePublicId($publicId);
}
}
return $query;
}
}

View File

@ -1,14 +1,8 @@
<?php <?php
class Invitation extends Eloquent class Invitation extends EntityModel
{ {
protected $softDelete = true; protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date');
protected $hidden = array('created_at', 'updated_at', 'deleted_at');
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public function invoice() public function invoice()
{ {

View File

@ -1,14 +1,8 @@
<?php <?php
class Invoice extends Eloquent implements iEntity class Invoice extends EntityModel
{ {
protected $softDelete = true; protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date');
protected $hidden = array('created_at', 'updated_at', 'deleted_at', 'viewed_date', 'key');
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public function account() public function account()
{ {

View File

@ -1,10 +1,7 @@
<?php <?php
class InvoiceItem extends Eloquent class InvoiceItem extends EntityModel
{ {
protected $softDelete = true;
protected $hidden = array('created_at', 'updated_at', 'deleted_at');
public function invoice() public function invoice()
{ {
return $this->belongsTo('Invoice'); return $this->belongsTo('Invoice');

View File

@ -1,14 +1,7 @@
<?php <?php
class Payment extends Eloquent implements iEntity class Payment extends EntityModel
{ {
protected $softDelete = true;
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public function invoice() public function invoice()
{ {
return $this->belongsTo('Invoice'); return $this->belongsTo('Invoice');

View File

@ -1,22 +1,15 @@
<?php <?php
class Product extends Eloquent class Product extends EntityModel
{ {
protected $softDelete = true;
public function scopeScope($query)
{
return $query->whereAccountId(Auth::user()->account_id);
}
public static function findProductByKey($key) public static function findProductByKey($key)
{ {
return Product::scope()->where('key','=',$key)->first(); return Product::scope()->where('product_key','=',$key)->first();
} }
public static function getProductKeys($products) public static function getProductKeys($products)
{ {
$products = array_pluck($products, 'key'); $products = array_pluck($products, 'product_key');
$products = array_combine($products, $products); $products = array_combine($products, $products);
return $products; return $products;

View File

@ -11,8 +11,7 @@
| |
*/ */
//dd(Omnipay::getFactory()->find()); //dd(Client::getPrivateId(1));
Route::get('/', 'HomeController@showWelcome'); Route::get('/', 'HomeController@showWelcome');
Route::post('get_started', 'AccountController@getStarted'); Route::post('get_started', 'AccountController@getStarted');
@ -21,6 +20,8 @@ Route::get('view/{invoice_key}', 'InvoiceController@view');
Route::get('payment/{invoice_key}', 'InvoiceController@show_payment'); Route::get('payment/{invoice_key}', 'InvoiceController@show_payment');
Route::get('complete', 'InvoiceController@do_payment'); Route::get('complete', 'InvoiceController@do_payment');
Route::post('signup/validate', 'AccountController@checkEmail');
Route::post('signup/submit', 'AccountController@submitSignup');
Route::filter('auth', function() Route::filter('auth', function()
{ {
@ -35,8 +36,6 @@ Route::group(array('before' => 'auth'), function()
Route::get('home', function() { return View::make('header'); }); Route::get('home', function() { return View::make('header'); });
Route::get('account/{section?}', 'AccountController@showSection'); Route::get('account/{section?}', 'AccountController@showSection');
Route::post('account/{section?}', 'AccountController@doSection'); Route::post('account/{section?}', 'AccountController@doSection');
Route::post('signup/validate', 'AccountController@checkEmail');
Route::post('signup/submit', 'AccountController@submitSignup');
Route::resource('clients', 'ClientController'); Route::resource('clients', 'ClientController');
Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable')); Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable'));
@ -52,16 +51,14 @@ Route::group(array('before' => 'auth'), function()
Route::get('invoices/{client_id}/archive', 'InvoiceController@archive'); Route::get('invoices/{client_id}/archive', 'InvoiceController@archive');
Route::get('invoices/{client_id}/delete', 'InvoiceController@delete'); Route::get('invoices/{client_id}/delete', 'InvoiceController@delete');
Route::get('payments', 'PaymentController@index'); Route::resource('payments', 'PaymentController');
Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable')); Route::get('api/payments/{client_id?}', array('as'=>'api.payments', 'uses'=>'PaymentController@getDatatable'));
Route::post('payments/bulk', 'PaymentController@bulk'); Route::post('payments/bulk', 'PaymentController@bulk');
Route::get('payments/create', function() { return View::make('header'); });
Route::get('payments/{client_id}/archive', 'PaymentController@archive'); Route::get('payments/{client_id}/archive', 'PaymentController@archive');
Route::get('payments/{client_id}/delete', 'PaymentController@delete'); Route::get('payments/{client_id}/delete', 'PaymentController@delete');
Route::get('credits', 'CreditController@index'); Route::resource('credits', 'CreditController');
Route::get('api/credits/{client_id?}', array('as'=>'api.credits', 'uses'=>'CreditController@getDatatable')); Route::get('api/credits/{client_id?}', array('as'=>'api.credits', 'uses'=>'CreditController@getDatatable'));
Route::get('credits/create', function() { return View::make('header'); });
Route::get('credits/{client_id}/archive', 'CreditController@archive'); Route::get('credits/{client_id}/archive', 'CreditController@archive');
Route::get('credits/{client_id}/delete', 'CreditController@delete'); Route::get('credits/{client_id}/delete', 'CreditController@delete');
@ -247,12 +244,12 @@ define("RECENTLY_VIEWED_LIMIT", 8);
interface iPerson interface iPerson
{ {
public function getFullName(); //public function getFullName();
public function getPersonType(); //public function getPersonType();
} }
interface iEntity interface iEntity
{ {
public function getName(); //public function getName();
public function getEntityType(); //public function getEntityType();
} }

View File

@ -4,6 +4,11 @@
@parent @parent
{{ Former::open()->addClass('col-md-10 col-md-offset-1') }} {{ Former::open()->addClass('col-md-10 col-md-offset-1') }}
{{ Former::populate($account) }}
{{ Former::legend('Invoices') }}
{{ Former::textarea('invoice_terms') }}
{{ Former::legend('Payment Gateway') }} {{ Former::legend('Payment Gateway') }}
@if ($accountGateway) @if ($accountGateway)

View File

@ -72,7 +72,7 @@
<center style="margin-top:16px"> <center style="margin-top:16px">
{{ Button::lg_primary_submit('Save') }} &nbsp;|&nbsp; {{ Button::lg_primary_submit('Save') }} &nbsp;|&nbsp;
{{ link_to('clients/' . ($client ? $client->id : ''), 'Cancel') }} {{ link_to('clients/' . ($client ? $client->public_id : ''), 'Cancel') }}
</center> </center>
{{ Former::close() }} {{ Former::close() }}

View File

@ -7,13 +7,13 @@
{{ Former::open('clients/bulk')->addClass('mainForm') }} {{ Former::open('clients/bulk')->addClass('mainForm') }}
<div style="display:none"> <div style="display:none">
{{ Former::text('action') }} {{ Former::text('action') }}
{{ Former::text('id')->value($client->id) }} {{ Former::text('id')->value($client->public_id) }}
</div> </div>
{{ DropdownButton::normal('Edit Client', {{ DropdownButton::normal('Edit Client',
Navigation::links( Navigation::links(
array( array(
array('Edit Client', URL::to('clients/' . $client->id . '/edit')), array('Edit Client', URL::to('clients/' . $client->public_id . '/edit')),
array(Navigation::DIVIDER), array(Navigation::DIVIDER),
array('Archive Client', "javascript:onArchiveClick()"), array('Archive Client', "javascript:onArchiveClick()"),
array('Delete Client', "javascript:onDeleteClick()"), array('Delete Client', "javascript:onDeleteClick()"),
@ -70,7 +70,7 @@
{{ Datatable::table() {{ Datatable::table()
->addColumn('Date', 'Message', 'Balance') ->addColumn('Date', 'Message', 'Balance')
->setUrl(url('api/activities/'. $client->id)) ->setUrl(url('api/activities/'. $client->public_id))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->render() }} ->render() }}
@ -81,7 +81,7 @@
{{ Datatable::table() {{ Datatable::table()
->addColumn('Invoice Number', 'Total', 'Amount Due', 'Invoice Date', 'Due Date', 'Status') ->addColumn('Invoice Number', 'Total', 'Amount Due', 'Invoice Date', 'Due Date', 'Status')
->setUrl(url('api/invoices/' . $client->id)) ->setUrl(url('api/invoices/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->render() }} ->render() }}
@ -91,7 +91,7 @@
{{ Datatable::table() {{ Datatable::table()
->addColumn('Invoice Number', 'Amount', 'Date') ->addColumn('Invoice Number', 'Amount', 'Date')
->setUrl(url('api/payments/' . $client->id)) ->setUrl(url('api/payments/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->render() }} ->render() }}
@ -101,7 +101,7 @@
{{ Datatable::table() {{ Datatable::table()
->addColumn('Credit Number', 'Amount', 'Credit Date') ->addColumn('Credit Number', 'Amount', 'Credit Date')
->setUrl(url('api/credits/' . $client->id)) ->setUrl(url('api/credits/' . $client->public_id))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->render() }} ->render() }}
@ -113,7 +113,7 @@
$(function() { $(function() {
$('#actionDropDown > button:first').click(function() { $('#actionDropDown > button:first').click(function() {
window.location = '{{ URL::to('clients/' . $client->id . '/edit') }}'; window.location = '{{ URL::to('clients/' . $client->public_id . '/edit') }}';
}); });
}); });

View File

@ -234,7 +234,7 @@
<div> <div>
<span style="font-size:30px">Invoice Ninja</span> <span style="font-size:30px">Invoice Ninja</span>
<div style="float:right"> <div style="float:right">
@if (Auth::user()->registered) @if (Auth::check() && Auth::user()->registered)
{{ Auth::user()->email }} &nbsp; {{ Auth::user()->email }} &nbsp;
@else @else
{{ Button::sm_primary('Sign up', array('data-toggle'=>'modal', 'data-target'=>'#signUpModal')) }} {{ Button::sm_primary('Sign up', array('data-toggle'=>'modal', 'data-target'=>'#signUpModal')) }}
@ -317,7 +317,7 @@
</div> </div>
@if (!Auth::user()->registered) @if (!Auth::check() || !Auth::user()->registered)
<div class="modal fade" id="signUpModal" tabindex="-1" role="dialog" aria-labelledby="signUpModalLabel" aria-hidden="true"> <div class="modal fade" id="signUpModal" tabindex="-1" role="dialog" aria-labelledby="signUpModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
@ -328,7 +328,9 @@
<div style="padding-right:20px" id="signUpDiv" onkeyup="validateSignUp()" onkeydown="checkForEnter(event)"> <div style="padding-right:20px" id="signUpDiv" onkeyup="validateSignUp()" onkeydown="checkForEnter(event)">
{{ Former::open('signup/submit')->addClass('signUpForm') }} {{ Former::open('signup/submit')->addClass('signUpForm') }}
{{ Former::populate(Auth::user()) }} @if (Auth::check())
{{ Former::populate(Auth::user()) }}
@endif
{{ Former::hidden('path')->value(Request::path()) }} {{ Former::hidden('path')->value(Request::path()) }}
{{ Former::text('first_name') }} {{ Former::text('first_name') }}
{{ Former::text('last_name') }} {{ Former::text('last_name') }}
@ -382,7 +384,7 @@
<script type="text/javascript"> <script type="text/javascript">
@if (!Auth::user()->registered) @if (!Auth::check() || !Auth::user()->registered)
function validateSignUp(showError) function validateSignUp(showError)
{ {
var isFormValid = true; var isFormValid = true;
@ -444,7 +446,7 @@
function logout(force) function logout(force)
{ {
if (force || {{ Auth::user()->registered ? 'true' : 'false' }}) { if (force || {{ !Auth::check() || Auth::user()->registered ? 'true' : 'false' }}) {
window.location = '{{ URL::to('logout') }}'; window.location = '{{ URL::to('logout') }}';
} else { } else {
$('#logoutModal').modal('show'); $('#logoutModal').modal('show');
@ -454,14 +456,14 @@
$(function() { $(function() {
if (isStorageSupported()) { if (isStorageSupported()) {
@if (!Auth::user()->registered) @if (Auth::check() && !Auth::user()->registered)
localStorage.setItem('guest_key', '{{ Auth::user()->password }}'); localStorage.setItem('guest_key', '{{ Auth::user()->password }}');
@elseif (Session::get('clearGuestKey')) @elseif (Session::get('clearGuestKey'))
localStorage.setItem('guest_key', ''); localStorage.setItem('guest_key', '');
@endif @endif
} }
@if (!Auth::user()->registered) @if (!Auth::check() || !Auth::user()->registered)
validateSignUp(); validateSignUp();
$('#signUpModal').on('shown.bs.modal', function () { $('#signUpModal').on('shown.bs.modal', function () {

View File

@ -24,8 +24,9 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
{{ Former::select('client')->addOption('', '')->fromQuery($clients, 'name', 'id')->select($client ? $client->id : '') {{ Former::select('client')->addOption('', '')->fromQuery($clients, 'name', 'public_id')->select($client ? $client->public_id : '')
->help('<a style="cursor:pointer" data-toggle="modal" data-target="#myModal">Create new client</a>'); }} ->help('<a style="cursor:pointer" data-toggle="modal" data-target="#myModal">Create new client</a>') }}
{{ Former::textarea('notes') }}
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
{{ Former::text('invoice_number')->label('Invoice #') }} {{ Former::text('invoice_number')->label('Invoice #') }}
@ -131,7 +132,7 @@
{{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }} {{ Button::normal('Download PDF', array('onclick' => 'onDownloadClick()')) }}
@endif @endif
{{ Button::primary_submit('Save Invoice', array('onclick' => 'onSaveClick()')) }} {{ Button::primary_submit('Save Invoice') }}
{{ Button::primary('Send Email', array('onclick' => 'onEmailClick()')) }} {{ Button::primary('Send Email', array('onclick' => 'onEmailClick()')) }}
</div> </div>
<p>&nbsp;</p> <p>&nbsp;</p>
@ -268,7 +269,7 @@
var key = $(this).val(); var key = $(this).val();
for (var i=0; i<products.length; i++) { for (var i=0; i<products.length; i++) {
var product = products[i]; var product = products[i];
if (product.key == key) { if (product.product_key == key) {
var model = ko.dataFor(this); var model = ko.dataFor(this);
model.notes(product.notes); model.notes(product.notes);
model.cost(product.cost); model.cost(product.cost);

View File

@ -7,7 +7,7 @@
<div class="clearfix"></div><p>&nbsp;</p> <div class="clearfix"></div><p>&nbsp;</p>
@endif @endif
<iframe frameborder="1" width="100%" height="600" style="display:block;margin: 0 auto"></iframe> <iframe frameborder="1" width="100%" height="650" style="display:block;margin: 0 auto"></iframe>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -0,0 +1,47 @@
@extends('header')
@section('onReady')
$('input#name').focus();
@stop
@section('content')
{{ Former::open($url)->addClass('col-md-10 col-md-offset-1 main_form')->method($method)->rules(array(
'name' => 'required',
'email' => 'email'
)); }}
@if ($payment)
{{ Former::populate($payment) }}
@endif
<div class="row">
<div class="col-md-6">
@if ($payment)
{{ Former::legend('Edit Payment') }}
@else
{{ Former::legend('New Payment') }}
@endif
{{ Former::text('name') }}
{{ Former::text('work_phone')->label('Phone') }}
{{ Former::textarea('notes') }}
</div>
<div class="col-md-6">
</div>
</div>
<center style="margin-top:16px">
{{ Button::lg_primary_submit('Save') }} &nbsp;|&nbsp;
{{ link_to('payments/' . ($payment ? $payment->public_id : ''), 'Cancel') }}
</center>
{{ Former::close() }}
@stop

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB