From bb560778af3f39f8debb6365a0ac9d3b273dc782 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 30 Jul 2014 10:08:01 +0300 Subject: [PATCH] Working on API --- .env.development.php | 2 +- app/controllers/AccountController.php | 2 +- app/controllers/ClientApiController.php | 22 ++++++--- app/controllers/HomeController.php | 5 ++ app/controllers/InvoiceApiController.php | 2 +- app/controllers/PaymentApiController.php | 2 +- app/controllers/QuoteApiController.php | 2 +- app/models/Activity.php | 4 ++ app/ninja/repositories/ClientRepository.php | 12 +++-- app/ninja/repositories/CreditRepository.php | 2 +- app/ninja/repositories/InvoiceRepository.php | 6 +-- app/ninja/repositories/PaymentRepository.php | 2 +- app/routes.php | 6 +-- app/views/invoices/edit.blade.php | 49 ++++++++++---------- app/views/list.blade.php | 2 +- app/views/public/header.blade.php | 2 + public/built.js | 6 +-- public/built.public.css | 26 +++++++++++ public/css/splash.css | 26 +++++++++++ public/js/script.js | 6 +-- 20 files changed, 130 insertions(+), 56 deletions(-) diff --git a/.env.development.php b/.env.development.php index eea3783a74..ecc9ff2b5a 100644 --- a/.env.development.php +++ b/.env.development.php @@ -4,6 +4,6 @@ return array( //'TAG_MANAGER_KEY' => '', //'ANALYTICS_KEY' => '', - //'NINJA_DEV' => true, + 'NINJA_DEV' => true, ); diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 18190f417b..ac80dcda84 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -67,7 +67,7 @@ class AccountController extends \BaseController { public function setTrashVisible($entityType, $visible) { - Session::put('show_trash', $visible == 'true'); + Session::put("show_trash:{$entityType}", $visible == 'true'); return Redirect::to("{$entityType}s"); } diff --git a/app/controllers/ClientApiController.php b/app/controllers/ClientApiController.php index e1e6f3afc2..7ed6c9fce9 100644 --- a/app/controllers/ClientApiController.php +++ b/app/controllers/ClientApiController.php @@ -21,7 +21,7 @@ class ClientApiController extends Controller { public function index() { if (!Utils::isPro()) { - Redirect::to('/'); + return Redirect::to('/'); } $clients = Client::scope()->with('contacts')->orderBy('created_at', 'desc')->get(); @@ -35,14 +35,24 @@ class ClientApiController extends Controller { public function store() { if (!Utils::isPro()) { - Redirect::to('/'); + return Redirect::to('/'); } $data = Input::all(); - $client = $this->clientRepo->save(false, $data, false); + $error = $this->clientRepo->getErrors($data); + + if ($error) + { + $headers = Utils::getApiHeaders(); + return Response::make($error, 500, $headers); + } + else + { + $client = $this->clientRepo->save(false, $data, false); + $response = json_encode($client, JSON_PRETTY_PRINT); + $headers = Utils::getApiHeaders(); + return Response::make($response, 200, $headers); + } - $response = json_encode($client, JSON_PRETTY_PRINT); - $headers = Utils::getApiHeaders(); - return Response::make($response, 200, $headers); } } \ No newline at end of file diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index d05a1a9b75..b9415d58bf 100755 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -111,6 +111,11 @@ class HomeController extends BaseController { return View::make('secure_payment'); } + public function showCompare() + { + return View::make('public.compare'); + } + public function invoiceNow() { if (Auth::check()) diff --git a/app/controllers/InvoiceApiController.php b/app/controllers/InvoiceApiController.php index ea37bbace2..a35dca8535 100644 --- a/app/controllers/InvoiceApiController.php +++ b/app/controllers/InvoiceApiController.php @@ -15,7 +15,7 @@ class InvoiceApiController extends Controller { public function index() { if (!Utils::isPro()) { - Redirect::to('/'); + return Redirect::to('/'); } $invoices = Invoice::scope()->where('invoices.is_quote', '=', false)->orderBy('created_at', 'desc')->get(); diff --git a/app/controllers/PaymentApiController.php b/app/controllers/PaymentApiController.php index f244ad83b0..9e49974dee 100644 --- a/app/controllers/PaymentApiController.php +++ b/app/controllers/PaymentApiController.php @@ -15,7 +15,7 @@ class PaymentApiController extends Controller { public function index() { if (!Utils::isPro()) { - Redirect::to('/'); + return Redirect::to('/'); } $payments = Payment::scope()->orderBy('created_at', 'desc')->get(); diff --git a/app/controllers/QuoteApiController.php b/app/controllers/QuoteApiController.php index d5f9e1cd68..fdefbe2f79 100644 --- a/app/controllers/QuoteApiController.php +++ b/app/controllers/QuoteApiController.php @@ -15,7 +15,7 @@ class QuoteApiController extends Controller { public function index() { if (!Utils::isPro()) { - Redirect::to('/'); + return Redirect::to('/'); } $invoices = Invoice::scope()->where('invoices.is_quote', '=', true)->orderBy('created_at', 'desc')->get(); diff --git a/app/models/Activity.php b/app/models/Activity.php index 517c2bd516..30edee0c0e 100755 --- a/app/models/Activity.php +++ b/app/models/Activity.php @@ -441,6 +441,10 @@ class Activity extends Eloquent private static function checkSubscriptions($event, $data) { + if (!Auth::check()) { + return; + } + $subscription = Auth::user()->account->getSubscription($event); if ($subscription) diff --git a/app/ninja/repositories/ClientRepository.php b/app/ninja/repositories/ClientRepository.php index cce8175f71..b665b0e335 100755 --- a/app/ninja/repositories/ClientRepository.php +++ b/app/ninja/repositories/ClientRepository.php @@ -13,7 +13,7 @@ class ClientRepository ->where('contacts.is_primary', '=', true) ->select('clients.public_id','clients.name','contacts.first_name','contacts.last_name','clients.balance','clients.last_login','clients.created_at','clients.work_phone','contacts.email','clients.currency_id'); - if (!\Session::get('show_trash')) + if (!\Session::get('show_trash:client')) { $query->where('clients.deleted_at', '=', null); } @@ -32,15 +32,19 @@ class ClientRepository return $query; } - public function save($publicId, $data, $notify = true) + public function getErrors($data) { $contact = isset($data['contacts']) ? (array)$data['contacts'][0] : (isset($data['contact']) ? $data['contact'] : []); $validator = \Validator::make($contact, ['email' => 'required|email']); if ($validator->fails()) { - dd($validator->messages()); - return false; + return $validator->messages(); } + + return false; + } + public function save($publicId, $data, $notify = true) + { if (!$publicId || $publicId == "-1") { $client = Client::createNew(); diff --git a/app/ninja/repositories/CreditRepository.php b/app/ninja/repositories/CreditRepository.php index ca3f03ac13..704ebc54c1 100755 --- a/app/ninja/repositories/CreditRepository.php +++ b/app/ninja/repositories/CreditRepository.php @@ -22,7 +22,7 @@ class CreditRepository $query->where('clients.public_id', '=', $clientPublicId); } - if (!\Session::get('show_trash')) + if (!\Session::get('show_trash:credit')) { $query->where('credits.deleted_at', '=', null); } diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index f64546d973..66923e4157 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -22,7 +22,7 @@ class InvoiceRepository ->where('contacts.is_primary', '=', true) ->select('clients.public_id as client_public_id', 'invoice_number', 'clients.name as client_name', 'invoices.public_id', 'amount', 'invoices.balance', 'invoice_date', 'due_date', 'invoice_statuses.name as invoice_status_name', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email', 'quote_id', 'quote_invoice_id'); - if (!\Session::get('show_trash')) + if (!\Session::get('show_trash:invoice')) { $query->where('invoices.deleted_at', '=', null); } @@ -65,8 +65,8 @@ class InvoiceRepository { $query->where('clients.public_id', '=', $clientPublicId); } - - if (!\Session::get('show_trash')) + + if (!\Session::get('show_trash:invoice')) { $query->where('invoices.deleted_at', '=', null); } diff --git a/app/ninja/repositories/PaymentRepository.php b/app/ninja/repositories/PaymentRepository.php index f252aede93..2cf96ceeae 100755 --- a/app/ninja/repositories/PaymentRepository.php +++ b/app/ninja/repositories/PaymentRepository.php @@ -20,7 +20,7 @@ class PaymentRepository ->where('contacts.is_primary', '=', true) ->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', 'clients.currency_id', 'contacts.first_name', 'contacts.last_name', 'contacts.email', 'payment_types.name as payment_type', 'payments.account_gateway_id'); - if (!\Session::get('show_trash')) + if (!\Session::get('show_trash:payment')) { $query->where('payments.deleted_at', '=', null); } diff --git a/app/routes.php b/app/routes.php index cd7309d5cb..e5685f90fb 100755 --- a/app/routes.php +++ b/app/routes.php @@ -1,6 +1,5 @@ 'api/v1', 'before' => 'auth.basic'), function() Route::resource('invoices', 'InvoiceApiController'); Route::resource('quotes', 'QuoteApiController'); Route::resource('payments', 'PaymentApiController'); -}); - -Route::group(array('before' => 'auth.basic'), function() -{ Route::post('api/hooks', 'IntegrationController@subscribe'); }); diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index cdca7041b7..094bb7d728 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -725,24 +725,30 @@ function onEmailClick() { @if (Auth::user()->confirmed) if (confirm('Are you sure you want to email this {{ $entityType }}?')) { - $('#action').val('email'); - $('#submitButton').click(); + submitAction('email'); } @else - $('#action').val('email'); - $('#submitButton').click(); + submitAction('email'); @endif } function onSaveClick() { - $('#action').val(''); - $('#submitButton').click(); + submitAction(''); + } + + function submitAction(value) { + if (!isSaveValid()) { + model.showClientForm(); + return; + } + $('#action').val(value); + $('#submitButton').click(); } function isSaveValid() { var isValid = false; - for (var i=0; i= 0; - } + if (client) { // in case it's deleted + for (var i=0; i= 0; + } + } model.invoice().addItem(); //model.addTaxRate(); @else diff --git a/app/views/list.blade.php b/app/views/list.blade.php index 9ef342e790..49960dd31e 100755 --- a/app/views/list.blade.php +++ b/app/views/list.blade.php @@ -19,7 +19,7 @@  
diff --git a/app/views/public/header.blade.php b/app/views/public/header.blade.php index 2a8497c660..cdde1bffae 100644 --- a/app/views/public/header.blade.php +++ b/app/views/public/header.blade.php @@ -45,6 +45,8 @@ .hero-testi { background-image: url({{ asset('/images/hero-bg-testi.jpg') }}); } + + @stop diff --git a/public/built.js b/public/built.js index c61a9284ff..1dcc8bcbd5 100644 --- a/public/built.js +++ b/public/built.js @@ -47488,7 +47488,7 @@ function displayInvoiceHeader(doc, invoice, layout) { doc.text(layout.marginLeft, layout.tableTop, invoiceLabels.item); doc.text(layout.descriptionLeft, layout.tableTop, invoiceLabels.description); doc.text(costX, layout.tableTop, invoiceLabels.unit_cost); - if (invoice.account.hide_quantity === '0') { + if (invoice.account.hide_quantity != '1') { doc.text(qtyX, layout.tableTop, invoiceLabels.quantity); } doc.text(totalX, layout.tableTop, invoiceLabels.line_total); @@ -47507,7 +47507,7 @@ function displayInvoiceItems(doc, invoice, layout) { var shownItem = false; var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1; var tableTop = layout.tableTop; - var hideQuantity = invoice.account.hide_quantity === '1'; + var hideQuantity = invoice.account.hide_quantity == '1'; doc.setFontSize(8); for (var i=0; i span { background-color: transparent; border: none; } + +.compare-table .glyphicon, .plans-table .glyphicon { color: #fff; border-radius: 50px; padding: 5px; font-size: 10px; } +.compare-table .glyphicon-remove, .plans-table .glyphicon-remove { background-color: #da4830; } +.compare-table .glyphicon-ok, .plans-table .glyphicon-ok { background-color: #35c156; } @@ -1350,6 +1354,28 @@ div.fb_iframe_widget > span { background: #1e84a5; } + +table.compare-table td { + height: 70px; + vertical-align: middle !important; +} +table.compare-table th { + height: 70px; + vertical-align: middle !important; + text-align: center; + color: white; +} +table.compare-table td:first-child { + text-align: left; +} +table.compare-table-free th { + background-color: #0b4d78; +} +table.compare-table-paid th { + background-color: #e37329; +} + + @media (min-width: 992px) { .hide-desktop {display: none !important;} } diff --git a/public/css/splash.css b/public/css/splash.css index bff37eabf2..92e632dfd7 100644 --- a/public/css/splash.css +++ b/public/css/splash.css @@ -1275,15 +1275,19 @@ div.fb_iframe_widget > span { background-color: transparent; border: none; } + +.compare-table .glyphicon, .plans-table .glyphicon { color: #fff; border-radius: 50px; padding: 5px; font-size: 10px; } +.compare-table .glyphicon-remove, .plans-table .glyphicon-remove { background-color: #da4830; } +.compare-table .glyphicon-ok, .plans-table .glyphicon-ok { background-color: #35c156; } @@ -1332,6 +1336,28 @@ div.fb_iframe_widget > span { background: #1e84a5; } + +table.compare-table td { + height: 70px; + vertical-align: middle !important; +} +table.compare-table th { + height: 70px; + vertical-align: middle !important; + text-align: center; + color: white; +} +table.compare-table td:first-child { + text-align: left; +} +table.compare-table-free th { + background-color: #0b4d78; +} +table.compare-table-paid th { + background-color: #e37329; +} + + @media (min-width: 992px) { .hide-desktop {display: none !important;} } diff --git a/public/js/script.js b/public/js/script.js index f9bbf91b32..410c68d3bc 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1563,7 +1563,7 @@ function displayInvoiceHeader(doc, invoice, layout) { doc.text(layout.marginLeft, layout.tableTop, invoiceLabels.item); doc.text(layout.descriptionLeft, layout.tableTop, invoiceLabels.description); doc.text(costX, layout.tableTop, invoiceLabels.unit_cost); - if (invoice.account.hide_quantity === '0') { + if (invoice.account.hide_quantity != '1') { doc.text(qtyX, layout.tableTop, invoiceLabels.quantity); } doc.text(totalX, layout.tableTop, invoiceLabels.line_total); @@ -1582,7 +1582,7 @@ function displayInvoiceItems(doc, invoice, layout) { var shownItem = false; var currencyId = invoice && invoice.client ? invoice.client.currency_id : 1; var tableTop = layout.tableTop; - var hideQuantity = invoice.account.hide_quantity === '1'; + var hideQuantity = invoice.account.hide_quantity == '1'; doc.setFontSize(8); for (var i=0; i