diff --git a/LICENSE b/LICENSE index 129def0208b1..4d1b69fde2e5 100644 --- a/LICENSE +++ b/LICENSE @@ -12,8 +12,8 @@ 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 (the "Code"), must prominently display "Powered by InvoiceNinja.com" -in verifiable form with a link to said site. +modification the website must prominently display "Powered by InvoiceNinja" +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. diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 0077a72c1950..8f808bfdd9cb 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -23,7 +23,7 @@ class AccountController extends \BaseController { { $account = new Account; $account->ip = Request::getClientIp(); - $account->key = str_random(20); + $account->account_key = str_random(20); $account->save(); $random = str_random(20); @@ -374,9 +374,12 @@ class AccountController extends \BaseController { } else { - $account = Account::findOrFail(Auth::user()->account_id); + $account = Account::findOrFail(Auth::user()->account_id); $account->account_gateways()->forceDelete(); + $account->invoice_terms = Input::get('invoice_terms'); + $account->save(); + if ($gatewayId) { $accountGateway = new AccountGateway; @@ -441,8 +444,8 @@ class AccountController extends \BaseController { if ($file = Input::file('logo')) { $path = Input::file('logo')->getRealPath(); - File::delete('logo/' . $account->key . '.jpg'); - Image::make($path)->resize(150, 100, true, false)->save('logo/' . $account->key . '.jpg'); + File::delete('logo/' . $account->account_key . '.jpg'); + Image::make($path)->resize(150, 100, true, false)->save('logo/' . $account->account_key . '.jpg'); } Session::flash('message', 'Successfully updated details'); diff --git a/app/controllers/ActivityController.php b/app/controllers/ActivityController.php index 79b706685318..31fc5fee468e 100755 --- a/app/controllers/ActivityController.php +++ b/app/controllers/ActivityController.php @@ -2,8 +2,10 @@ 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()) ->addColumn('date', function($model) { return timestampToDateTimeString($model->created_at); }) ->addColumn('message', function($model) { return $model->message; }) diff --git a/app/controllers/ClientController.php b/app/controllers/ClientController.php index 171683155fba..3fc28768d926 100755 --- a/app/controllers/ClientController.php +++ b/app/controllers/ClientController.php @@ -24,8 +24,8 @@ class ClientController extends \BaseController { $clients = Client::scope()->with('contacts')->get(); return Datatable::collection($clients) - ->addColumn('checkbox', function($model) { return ''; }) - ->addColumn('name', function($model) { return link_to('clients/' . $model->id, $model->name); }) + ->addColumn('checkbox', function($model) { return ''; }) + ->addColumn('name', function($model) { return link_to('clients/' . $model->public_id, $model->name); }) ->addColumn('contact', function($model) { return $model->contacts[0]->getFullName(); }) ->addColumn('balance', function($model) { return '$' . $model->balance; }) ->addColumn('last_login', function($model) { return $model->contacts[0]->getLastLogin(); }) @@ -39,11 +39,11 @@ class ClientController extends \BaseController { Select
'; }) @@ -84,9 +84,9 @@ class ClientController extends \BaseController { * @param int $id * @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); $data = array( @@ -102,13 +102,13 @@ class ClientController extends \BaseController { * @param int $id * @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( 'client' => $client, 'method' => 'PUT', - 'url' => 'clients/' . $id, + 'url' => 'clients/' . $publicId, 'title' => '- ' . $client->name, 'countries' => Country::orderBy('name')->get()); return View::make('clients.edit', $data); @@ -120,12 +120,12 @@ class ClientController extends \BaseController { * @param int $id * @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( 'name' => 'required' @@ -133,15 +133,14 @@ class ClientController extends \BaseController { $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { - return Redirect::to('clients/' . $id . '/edit') + return Redirect::to('clients/' . $publicId . '/edit') ->withErrors($validator) ->withInput(Input::except('password')); } else { - if ($id) { - $client = Client::scope()->findOrFail($id); + if ($publicId) { + $client = Client::scope($publicId)->firstOrFail(); } else { - $client = new Client; - $client->account_id = Auth::user()->account_id; + $client = Client::createNew(); } $client->name = Input::get('name'); @@ -159,16 +158,16 @@ class ClientController extends \BaseController { $data = json_decode(Input::get('data')); $contactIds = []; - + foreach ($data->contacts as $contact) { if (isset($contact->id) && $contact->id) { - $record = Contact::findOrFail($contact->id); + $record = Contact::scope($contact->id)->firstOrFail(); } else { - $record = new Contact; + $record = Contact::createNew(); } $record->email = $contact->email; @@ -189,7 +188,7 @@ class ClientController extends \BaseController { } 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'); $ids = Input::get('ids') ? Input::get('ids') : [Input::get('id')]; - $clients = Client::scope()->findOrFail($ids); + $clients = Client::scope($ids)->get(); foreach ($clients as $client) { if ($action == 'archive') { @@ -214,9 +213,9 @@ class ClientController extends \BaseController { return Redirect::to('clients'); } - public function archive($id) + public function archive($publicId) { - $client = Client::scope()->findOrFail($id); + $client = Client::scope($publicId)->firstOrFail(); $client->delete(); foreach ($client->invoices as $invoice) @@ -230,7 +229,7 @@ class ClientController extends \BaseController { public function delete($id) { - $client = Client::scope()->findOrFail($id); + $client = Client::scope($publicId)->firstOrFail(); $client->forceDelete(); Session::flash('message', 'Successfully deleted ' . $client->name); diff --git a/app/controllers/CreditController.php b/app/controllers/CreditController.php index f53af7cbbb16..842a1b84fa3d 100755 --- a/app/controllers/CreditController.php +++ b/app/controllers/CreditController.php @@ -16,24 +16,25 @@ class CreditController extends \BaseController { )); } - public function getDatatable($clientId = null) + public function getDatatable($clientPublicId = null) { $collection = Credit::scope()->with('client'); - if ($clientId) { + if ($clientPublicId) { + $clientId = Client::getPrivateId($clientPublicId); $collection->where('client_id','=',$clientId); } $table = Datatable::collection($collection->get()); - if (!$clientId) { - $table->addColumn('checkbox', function($model) { return ''; }); + if (!$clientPublicId) { + $table->addColumn('checkbox', function($model) { return ''; }); } $table->addColumn('credit_number', function($model) { return $model->credit_number; }); - if (!$clientId) { - $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); }); + if (!$clientPublicId) { + $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); }) @@ -42,18 +43,18 @@ class CreditController extends \BaseController { ->make(); } - public function archive($id) + public function archive($publicId) { - $credit = Credit::scope()->findOrFail($id); + $credit = Credit::scope($publicId)->firstOrFail(); $creidt->delete(); Session::flash('message', 'Successfully archived credit ' . $credit->credit_number); return Redirect::to('credits'); } - public function delete($id) + public function delete($publicId) { - $credit = Credit::scope()->findOrFail($id); + $credit = Credit::scope($publicId)->firstOrFail(); $credit->forceDelete(); Session::flash('message', 'Successfully deleted credit ' . $credit->credit_number); diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 16ed1316550d..e47bf6b9e94e 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -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'); - if ($clientId) { + if ($clientPublicId) { + $clientId = Client::getPrivateId($clientPublicId); $collection->where('client_id','=',$clientId); } $table = Datatable::collection($collection->get()); - if (!$clientId) { - $table->addColumn('checkbox', function($model) { return ''; }); + if (!$clientPublicId) { + $table->addColumn('checkbox', function($model) { return ''; }); } - $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) { - $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); }); + if (!$clientPublicId) { + $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()); }) @@ -48,10 +49,10 @@ class InvoiceController extends \BaseController { Select '; }) @@ -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') - ->where('key', '=', $key)->firstOrFail(); + ->where('invitation_key', '=', $invitationKey)->firstOrFail(); $user = $invitation->user; $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]; $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); $data = array( 'account' => $invoice->account, 'invoice' => $invoice, 'method' => 'PUT', - 'url' => 'invoices/' . $id, + 'url' => 'invoices/' . $publicId, 'title' => '- ' . $invoice->invoice_number, '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, 'clients' => Client::scope()->orderBy('name')->get()); return View::make('invoices.edit', $data); } - public function create($clientId = 0) + public function create($clientPublicId = 0) { $client = null; $invoiceNumber = Auth::user()->account->getNextInvoiceNumber(); $account = Account::with('country')->findOrFail(Auth::user()->account_id); - if ($clientId) { - $client = Client::scope()->findOrFail($clientId); + if ($clientPublicId) { + $client = Client::scope($clientPublicId)->firstOrFail(); } $data = array( @@ -246,7 +247,7 @@ class InvoiceController extends \BaseController { 'client' => $client, 'items' => json_decode(Input::old('items')), '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()); return View::make('invoices.edit', $data); } @@ -261,17 +262,17 @@ class InvoiceController extends \BaseController { return InvoiceController::save(); } - private function save($id = null) + private function save($publicId = null) { $action = Input::get('action'); if ($action == 'archive') { - return InvoiceController::archive($id); + return InvoiceController::archive($publicId); } else if ($action == 'delete') { - return InvoiceController::delete($id); + return InvoiceController::delete($publicId); } $rules = array( @@ -287,41 +288,39 @@ class InvoiceController extends \BaseController { ->withErrors($validator); } 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->account_id = Auth::user()->account_id; $client->save(); $clientId = $client->id; - $contact = new Contact; + $contact = Contact::createNew(); $contact->email = Input::get('client_email'); $client->contacts()->save($contact); } else { - $client = Client::scope()->with('contacts')->findOrFail($clientId); + $client = Client::scope($clientPublicId)->with('contacts')->firstOrFail(); $contact = $client->contacts()->first(); } - if ($id) { - $invoice = Invoice::scope()->findOrFail($id); + if ($publicId) { + $invoice = Invoice::scope($publicId)->firstOrFail(); $invoice->invoice_items()->forceDelete(); } else { - $invoice = new Invoice; - $invoice->account_id = Auth::user()->account_id; + $invoice = Invoice::createNew(); } - $invoice->client_id = $clientId; $invoice->invoice_number = Input::get('invoice_number'); $invoice->discount = 0; $invoice->invoice_date = toSqlDate(Input::get('invoice_date')); - $invoice->due_date = toSqlDate(Input::get('due_date')); - $invoice->save(); - + $invoice->due_date = toSqlDate(Input::get('due_date')); + $invoice->notes = Input::get('notes'); + $client->invoices()->save($invoice); + $items = json_decode(Input::get('items')); foreach ($items as $item) { @@ -345,9 +344,8 @@ class InvoiceController extends \BaseController { if (!$product) { - $product = new Product; - $product->account_id = Auth::user()->account_id; - $product->key = $item->product_key; + $product = Product::createNew(); + $product->product_key = $item->product_key; } /* @@ -359,7 +357,7 @@ class InvoiceController extends \BaseController { $product->save(); } - $invoiceItem = new InvoiceItem; + $invoiceItem = InvoiceItem::createNew(); $invoiceItem->product_id = isset($product) ? $product->id : null; $invoiceItem->product_key = $item->product_key; $invoiceItem->notes = $item->notes; @@ -380,11 +378,11 @@ class InvoiceController extends \BaseController { }); */ - $invitation = new Invitation; + $invitation = Invitation::createNew(); $invitation->invoice_id = $invoice->id; $invitation->user_id = Auth::user()->id; $invitation->contact_id = $contact->id; - $invitation->key = str_random(20); + $invitation->invitation_key = str_random(20); $invitation->save(); Session::flash('message', 'Successfully emailed invoice'); @@ -392,8 +390,7 @@ class InvoiceController extends \BaseController { Session::flash('message', 'Successfully saved invoice'); } - $url = 'invoices/' . $invoice->id . '/edit'; - processedRequest($url); + $url = 'invoices/' . $invoice->public_id . '/edit'; return Redirect::to($url); } } @@ -404,12 +401,9 @@ class InvoiceController extends \BaseController { * @param int $id * @return Response */ - public function show($id) + public function show($publicId) { - return Redirect::to('invoices/'.$id.'/edit'); - - //$invoice = Invoice::find($id); - //return View::make('invoices.show')->with('invoice', $invoice); + return Redirect::to('invoices/'.$publicId.'/edit'); } /** @@ -418,9 +412,9 @@ class InvoiceController extends \BaseController { * @param int $id * @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'); $ids = Input::get('ids'); - $invoices = Invoice::scope()->findOrFail($ids); + $invoices = Invoice::scope($ids)->get(); foreach ($invoices as $invoice) { if ($action == 'archive') { @@ -449,18 +443,18 @@ class InvoiceController extends \BaseController { return Redirect::to('invoices'); } - public function archive($id) + public function archive($publicId) { - $invoice = Invoice::scope()->findOrFail($id); + $invoice = Invoice::scope($publicId)->firstOrFail(); $invoice->delete(); Session::flash('message', 'Successfully archived invoice ' . $invoice->invoice_number); return Redirect::to('invoices'); } - public function delete($id) + public function delete($publicId) { - $invoice = Invoice::scope()->findOrFail($id); + $invoice = Invoice::scope($publicId)->firstOrFail(); $invoice->forceDelete(); Session::flash('message', 'Successfully deleted invoice ' . $invoice->invoice_number); diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 8f2a838eab54..a709a906b132 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -11,24 +11,25 @@ class PaymentController extends \BaseController )); } - public function getDatatable($clientId = null) + public function getDatatable($clientPublicId = null) { $collection = Payment::scope()->with('invoice.client'); - if ($clientId) { + if ($clientPublicId) { + $clientId = Client::getPrivateId($clientPublicId); $collection->where('client_id','=',$clientId); } $table = Datatable::collection($collection->get()); - if (!$clientId) { - $table->addColumn('checkbox', function($model) { return ''; }); + if (!$clientPublicId) { + $table->addColumn('checkbox', function($model) { return ''; }); } $table->addColumn('transaction_reference', function($model) { return $model->transaction_reference; }); - if (!$clientId) { - $table->addColumn('client', function($model) { return link_to('clients/' . $model->client->id, $model->client->name); }); + if (!$clientPublicId) { + $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; }) @@ -37,18 +38,42 @@ class PaymentController extends \BaseController ->make(); } - public function archive($id) + + public function create() + { + $data = array( + 'payment' => null, + 'method' => 'POST', + 'url' => 'payments', + 'title' => '- New Payment'); + + return View::make('payments.edit', $data); + } + + public function edit($publicId) { - $payment = Payment::scope()->findOrFail($id); + $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(); Session::flash('message', 'Successfully archived payment'); return Redirect::to('payments'); } - public function delete($id) + public function delete($publicId) { - $payment = Payment::scope()->findOrFail($id); + $payment = Payment::scope($publicId)->firstOrFail(); $payment->forceDelete(); Session::flash('message', 'Successfully deleted payment'); diff --git a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php index 0d404bbc7bd2..ed4f7a0c02c4 100755 --- a/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php +++ b/app/database/migrations/2013_11_05_180133_confide_setup_users_table.php @@ -64,8 +64,7 @@ class ConfideSetupUsersTable extends Migration { $t->string('name'); $t->string('ip'); - $t->string('logo_path'); - $t->string('key')->unique(); + $t->string('account_key')->unique(); $t->timestamp('last_login'); $t->string('address1'); @@ -74,6 +73,7 @@ class ConfideSetupUsersTable extends Migration { $t->string('state'); $t->string('postal_code'); $t->unsignedInteger('country_id')->nullable(); + $t->text('invoice_terms'); $t->foreign('timezone_id')->references('id')->on('timezones'); $t->foreign('country_id')->references('id')->on('countries'); @@ -123,6 +123,9 @@ class ConfideSetupUsersTable extends Migration { $t->boolean('confirmed')->default(false); $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) @@ -154,11 +157,15 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $t->foreign('country_id')->references('id')->on('countries'); + + $t->unsignedInteger('public_id'); + $t->unique( array('account_id','public_id') ); }); Schema::create('contacts', function($t) { $t->increments('id'); + $t->unsignedInteger('account_id'); $t->unsignedInteger('client_id'); $t->timestamps(); $t->softDeletes(); @@ -170,6 +177,9 @@ class ConfideSetupUsersTable extends Migration { $t->timestamp('last_login'); $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) @@ -192,20 +202,25 @@ class ConfideSetupUsersTable extends Migration { $t->float('discount'); $t->date('invoice_date'); $t->date('due_date'); + $t->text('notes'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('account_id')->references('id')->on('accounts'); $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) { $t->increments('id'); + $t->unsignedInteger('account_id'); $t->unsignedInteger('user_id'); $t->unsignedInteger('contact_id'); $t->unsignedInteger('invoice_id'); - $t->string('key')->unique(); + $t->string('invitation_key')->unique(); $t->timestamps(); $t->softDeletes(); @@ -214,6 +229,9 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('user_id')->references('id')->on('users'); $t->foreign('contact_id')->references('id')->on('contacts')->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) @@ -223,18 +241,22 @@ class ConfideSetupUsersTable extends Migration { $t->timestamps(); $t->softDeletes(); - $t->string('key'); + $t->string('product_key'); $t->string('notes'); $t->decimal('cost', 10, 2); $t->integer('qty'); $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) { $t->increments('id'); + $t->unsignedInteger('account_id'); $t->unsignedInteger('invoice_id'); $t->unsignedInteger('product_id')->nullable(); $t->timestamps(); @@ -247,6 +269,9 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); $t->foreign('product_id')->references('id')->on('products'); + + $t->unsignedInteger('public_id'); + $t->unique( array('account_id','public_id') ); }); 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('contact_id')->references('id')->on('contacts'); $t->foreign('user_id')->references('id')->on('users'); + + $t->unsignedInteger('public_id'); + $t->unique( array('account_id','public_id') ); }); Schema::create('credits', function($t) @@ -288,6 +316,9 @@ class ConfideSetupUsersTable extends Migration { $t->foreign('account_id')->references('id')->on('accounts'); $t->foreign('client_id')->references('id')->on('clients')->onDelete('cascade'); $t->foreign('contact_id')->references('id')->on('contacts'); + + $t->unsignedInteger('public_id'); + $t->unique( array('account_id','public_id') ); }); Schema::create('activities', function($t) diff --git a/app/models/Account.php b/app/models/Account.php index 03ff81764e24..1440541403cd 100755 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -62,7 +62,7 @@ class Account extends Eloquent public function getLogoPath() { - return 'logo/' . $this->key . '.jpg'; + return 'logo/' . $this->account_key . '.jpg'; } public function getLogoWidth() @@ -79,7 +79,7 @@ class Account extends Eloquent public function getNextInvoiceNumber() { - $order = $this->invoices()->orderBy('invoice_number', 'DESC')->first(); + $order = Invoice::scope()->orderBy('invoice_number', 'DESC')->first(); if ($order) { diff --git a/app/models/Activity.php b/app/models/Activity.php index 4ee87ff9705f..39e6494d3ab0 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -18,6 +18,8 @@ define("ACTIVITY_TYPE_DELETE_CREDIT", 14); class Activity extends Eloquent { + protected $hidden = array('id'); + public function scopeScope($query) { return $query->whereAccountId(Auth::user()->account_id); diff --git a/app/models/Client.php b/app/models/Client.php index fad31c3434a2..150f77bd128b 100755 --- a/app/models/Client.php +++ b/app/models/Client.php @@ -1,9 +1,8 @@ whereAccountId(Auth::user()->account_id); - } - public function account() { return $this->belongsTo('Account'); diff --git a/app/models/Contact.php b/app/models/Contact.php index 4e99109cc4ca..e62267af6e6a 100755 --- a/app/models/Contact.php +++ b/app/models/Contact.php @@ -1,8 +1,8 @@ whereAccountId(Auth::user()->account_id); - } - public function invoice() { return $this->belongsTo('Invoice'); diff --git a/app/models/EntityModel.php b/app/models/EntityModel.php new file mode 100755 index 000000000000..163ece8b5b9a --- /dev/null +++ b/app/models/EntityModel.php @@ -0,0 +1,57 @@ +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; + } +} \ No newline at end of file diff --git a/app/models/Invitation.php b/app/models/Invitation.php index c7bafa32e38d..e95e08a30641 100644 --- a/app/models/Invitation.php +++ b/app/models/Invitation.php @@ -1,15 +1,9 @@ whereAccountId(Auth::user()->account_id); - } - + protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date'); + public function invoice() { return $this->belongsTo('Invoice'); diff --git a/app/models/Invoice.php b/app/models/Invoice.php index 188c31eb6e6e..cd7ea93d65b0 100755 --- a/app/models/Invoice.php +++ b/app/models/Invoice.php @@ -1,14 +1,8 @@ whereAccountId(Auth::user()->account_id); - } + protected $hidden = array('id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date'); public function account() { diff --git a/app/models/InvoiceItem.php b/app/models/InvoiceItem.php index 8ce490c8232c..ed322033193b 100755 --- a/app/models/InvoiceItem.php +++ b/app/models/InvoiceItem.php @@ -1,10 +1,7 @@ belongsTo('Invoice'); diff --git a/app/models/Payment.php b/app/models/Payment.php index a96dd15c176c..2a57cf42f63e 100755 --- a/app/models/Payment.php +++ b/app/models/Payment.php @@ -1,14 +1,7 @@ whereAccountId(Auth::user()->account_id); - } - public function invoice() { return $this->belongsTo('Invoice'); diff --git a/app/models/Product.php b/app/models/Product.php index 6aa5b45e3737..b7379d1290b0 100755 --- a/app/models/Product.php +++ b/app/models/Product.php @@ -1,22 +1,15 @@ whereAccountId(Auth::user()->account_id); - } - 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) { - $products = array_pluck($products, 'key'); + $products = array_pluck($products, 'product_key'); $products = array_combine($products, $products); return $products; diff --git a/app/routes.php b/app/routes.php index 5ae083fe5d6e..bf9d33d63ad9 100755 --- a/app/routes.php +++ b/app/routes.php @@ -11,8 +11,7 @@ | */ -//dd(Omnipay::getFactory()->find()); - +//dd(Client::getPrivateId(1)); Route::get('/', 'HomeController@showWelcome'); 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('complete', 'InvoiceController@do_payment'); +Route::post('signup/validate', 'AccountController@checkEmail'); +Route::post('signup/submit', 'AccountController@submitSignup'); Route::filter('auth', function() { @@ -35,9 +36,7 @@ Route::group(array('before' => 'auth'), function() Route::get('home', function() { return View::make('header'); }); Route::get('account/{section?}', 'AccountController@showSection'); Route::post('account/{section?}', 'AccountController@doSection'); - Route::post('signup/validate', 'AccountController@checkEmail'); - Route::post('signup/submit', 'AccountController@submitSignup'); - + Route::resource('clients', 'ClientController'); Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable')); Route::get('api/activities/{client_id?}', array('as'=>'api.activities', 'uses'=>'ActivityController@getDatatable')); @@ -52,16 +51,14 @@ Route::group(array('before' => 'auth'), function() Route::get('invoices/{client_id}/archive', 'InvoiceController@archive'); 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::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}/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('credits/create', function() { return View::make('header'); }); Route::get('credits/{client_id}/archive', 'CreditController@archive'); Route::get('credits/{client_id}/delete', 'CreditController@delete'); @@ -247,12 +244,12 @@ define("RECENTLY_VIEWED_LIMIT", 8); interface iPerson { - public function getFullName(); - public function getPersonType(); + //public function getFullName(); + //public function getPersonType(); } interface iEntity { - public function getName(); - public function getEntityType(); + //public function getName(); + //public function getEntityType(); } \ No newline at end of file diff --git a/app/views/accounts/settings.blade.php b/app/views/accounts/settings.blade.php index dd491f5e6856..933f48344f22 100755 --- a/app/views/accounts/settings.blade.php +++ b/app/views/accounts/settings.blade.php @@ -4,6 +4,11 @@ @parent {{ Former::open()->addClass('col-md-10 col-md-offset-1') }} + {{ Former::populate($account) }} + + {{ Former::legend('Invoices') }} + {{ Former::textarea('invoice_terms') }} + {{ Former::legend('Payment Gateway') }} @if ($accountGateway) diff --git a/app/views/clients/edit.blade.php b/app/views/clients/edit.blade.php index 13e98af46267..3c70bf0e6451 100755 --- a/app/views/clients/edit.blade.php +++ b/app/views/clients/edit.blade.php @@ -72,7 +72,7 @@