From 436b8be8d9387c614a11719a0bee45559511d647 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 6 Nov 2015 00:37:04 +0200 Subject: [PATCH 1/3] Refactoring datatable code --- .../Controllers/AccountGatewayController.php | 52 ++---- app/Http/Controllers/ActivityController.php | 35 +--- app/Http/Controllers/ClientController.php | 46 +---- app/Http/Controllers/CreditController.php | 39 +---- app/Http/Controllers/InvoiceController.php | 48 +----- app/Http/Controllers/PaymentController.php | 46 +---- app/Http/Controllers/ProductController.php | 52 ++---- app/Http/Controllers/QuoteController.php | 6 +- app/Http/Controllers/TaskController.php | 67 +------ app/Http/Controllers/TaxRateController.php | 40 ++--- app/Http/Controllers/TokenController.php | 65 ++----- app/Http/Controllers/UserController.php | 67 ++----- app/Http/routes.php | 16 +- app/Libraries/Utils.php | 12 +- app/Models/AccountGateway.php | 5 + app/Models/AccountToken.php | 5 + app/Models/Product.php | 5 + app/Models/TaxRate.php | 5 + .../Repositories/AccountGatewayRepository.php | 24 +++ app/Ninja/Repositories/ActivityRepository.php | 37 ++-- app/Ninja/Repositories/BaseRepository.php | 15 +- app/Ninja/Repositories/InvoiceRepository.php | 103 +---------- app/Ninja/Repositories/ProductRepository.php | 32 ++++ app/Ninja/Repositories/TaxRateRepository.php | 19 +- app/Ninja/Repositories/TokenRepository.php | 27 +++ app/Ninja/Repositories/UserRepository.php | 30 ++++ app/Services/AccountGatewayService.php | 68 ++++++++ app/Services/ActivityService.php | 65 +++++++ app/Services/BaseService.php | 19 ++ app/Services/ClientService.php | 105 ++++++++++- app/Services/CreditService.php | 62 ++++++- app/Services/DatatableService.php | 86 +++++++++ app/Services/InvoiceService.php | 163 +++++++++++++++++- app/Services/PaymentService.php | 69 +++++++- app/Services/ProductService.php | 84 +++++++++ app/Services/RecurringInvoiceService.php | 73 ++++++++ app/Services/TaskService.php | 134 ++++++++++++++ app/Services/TaxRateService.php | 68 ++++++++ app/Services/TokenService.php | 67 +++++++ app/Services/UserService.php | 82 +++++++++ resources/lang/en/texts.php | 28 ++- resources/views/accounts/api_tokens.blade.php | 19 +- resources/views/accounts/payments.blade.php | 26 +-- resources/views/accounts/products.blade.php | 4 +- resources/views/accounts/tax_rates.blade.php | 2 + .../views/accounts/user_management.blade.php | 16 +- resources/views/list.blade.php | 6 +- resources/views/partials/bulk_form.blade.php | 27 +++ 48 files changed, 1506 insertions(+), 665 deletions(-) create mode 100644 app/Ninja/Repositories/AccountGatewayRepository.php create mode 100644 app/Ninja/Repositories/ProductRepository.php create mode 100644 app/Ninja/Repositories/TokenRepository.php create mode 100644 app/Ninja/Repositories/UserRepository.php create mode 100644 app/Services/AccountGatewayService.php create mode 100644 app/Services/ActivityService.php create mode 100644 app/Services/DatatableService.php create mode 100644 app/Services/ProductService.php create mode 100644 app/Services/RecurringInvoiceService.php create mode 100644 app/Services/TaskService.php create mode 100644 app/Services/TaxRateService.php create mode 100644 app/Services/TokenService.php create mode 100644 app/Services/UserService.php create mode 100644 resources/views/partials/bulk_form.blade.php diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 9f190bbf26..56f8fd6623 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -16,9 +16,19 @@ use App\Models\Account; use App\Models\AccountGateway; use App\Ninja\Repositories\AccountRepository; +use App\Services\AccountGatewayService; class AccountGatewayController extends BaseController { + protected $accountGatewayService; + + public function __construct(AccountGatewayService $accountGatewayService) + { + parent::__construct(); + + $this->accountGatewayService = $accountGatewayService; + } + public function index() { return Redirect::to('settings/' . ACCOUNT_PAYMENTS); @@ -26,35 +36,7 @@ class AccountGatewayController extends BaseController public function getDatatable() { - $query = DB::table('account_gateways') - ->join('gateways', 'gateways.id', '=', 'account_gateways.gateway_id') - ->where('account_gateways.deleted_at', '=', null) - ->where('account_gateways.account_id', '=', Auth::user()->account_id) - ->select('account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at', 'account_gateways.gateway_id'); - - return Datatable::query($query) - ->addColumn('name', function ($model) { return link_to('gateways/'.$model->public_id.'/edit', $model->name); }) - ->addColumn('payment_type', function ($model) { return Gateway::getPrettyPaymentType($model->gateway_id); }) - ->addColumn('dropdown', function ($model) { - $actions = ''; - - return $actions; - }) - ->orderColumns(['name']) - ->make(); + return $this->accountGatewayService->getDatatable(Auth::user()->account_id); } public function edit($publicId) @@ -165,14 +147,14 @@ class AccountGatewayController extends BaseController ]; } - public function delete() + + public function bulk() { - $accountGatewayPublicId = Input::get('accountGatewayPublicId'); - $gateway = AccountGateway::scope($accountGatewayPublicId)->firstOrFail(); + $action = Input::get('bulk_action'); + $ids = Input::get('bulk_public_id'); + $count = $this->accountGatewayService->bulk($ids, $action); - $gateway->delete(); - - Session::flash('message', trans('texts.deleted_gateway')); + Session::flash('message', trans('texts.archived_account_gateway')); return Redirect::to('settings/' . ACCOUNT_PAYMENTS); } diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 02700e2330..44d87429d6 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -7,46 +7,21 @@ use Utils; use View; use App\Models\Client; use App\Models\Activity; -use App\Ninja\Repositories\ActivityRepository; +use App\Services\ActivityService; class ActivityController extends BaseController { - protected $activityRepo; + protected $activityService; - public function __construct(ActivityRepository $activityRepo) + public function __construct(ActivityService $activityService) { parent::__construct(); - $this->activityRepo = $activityRepo; + $this->activityService = $activityService; } public function getDatatable($clientPublicId) { - $clientId = Client::getPrivateId($clientPublicId); - - if ( ! $clientId) { - app()->abort(404); - } - - $query = $this->activityRepo->findByClientId($clientId); - - return Datatable::query($query) - ->addColumn('activities.id', function ($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); }) - ->addColumn('activity_type_id', function ($model) { - $data = [ - 'client' => link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)), - 'user' => $model->is_system ? '' . trans('texts.system') . '' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), - 'invoice' => $model->invoice ? link_to('/invoices/' . $model->invoice_public_id, $model->is_recurring ? trans('texts.recurring_invoice') : $model->invoice) : null, - 'quote' => $model->invoice ? link_to('/quotes/' . $model->invoice_public_id, $model->invoice) : null, - 'contact' => $model->contact_id ? link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)) : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), - 'payment' => $model->payment ?: '', - 'credit' => Utils::formatMoney($model->credit, $model->currency_id) - ]; - - return trans("texts.activity_{$model->activity_type_id}", $data); - }) - ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) - ->addColumn('adjustment', function ($model) { return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id) : ''; }) - ->make(); + return $this->activityService->getDatatable($clientPublicId); } } diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index c5ed7e5b41..7482ed3559 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -57,51 +57,7 @@ class ClientController extends BaseController public function getDatatable() { - $clients = $this->clientRepo->find(Input::get('sSearch')); - - return Datatable::query($clients) - ->addColumn('checkbox', function ($model) { return ''; }) - ->addColumn('name', function ($model) { return link_to('clients/'.$model->public_id, $model->name); }) - ->addColumn('first_name', function ($model) { return link_to('clients/'.$model->public_id, $model->first_name.' '.$model->last_name); }) - ->addColumn('email', function ($model) { return link_to('clients/'.$model->public_id, $model->email); }) - ->addColumn('clients.created_at', function ($model) { return Utils::timestampToDateString(strtotime($model->created_at)); }) - ->addColumn('last_login', function ($model) { return Utils::timestampToDateString(strtotime($model->last_login)); }) - ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) - ->addColumn('dropdown', function ($model) { - - $str = ''; - } - - return $str.'
  • '.trans('texts.delete_client').'
  • - '; - }) - ->make(); + return $this->clientService->getDatatable(Input::get('sSearch')); } /** diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 81dc77fe38..83f5b9dc57 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -16,7 +16,7 @@ use App\Http\Requests\CreateCreditRequest; class CreditController extends BaseController { protected $creditRepo; - protected $CreditService; + protected $creditService; public function __construct(CreditRepository $creditRepo, CreditService $creditService) { @@ -43,42 +43,7 @@ class CreditController extends BaseController public function getDatatable($clientPublicId = null) { - $credits = $this->creditRepo->find($clientPublicId, Input::get('sSearch')); - - $table = Datatable::query($credits); - - if (!$clientPublicId) { - $table->addColumn('checkbox', function ($model) { return ''; }) - ->addColumn('client_name', function ($model) { return link_to('clients/'.$model->client_public_id, Utils::getClientDisplayName($model)); }); - } - - return $table->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id).''; }) - ->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id); }) - ->addColumn('credit_date', function ($model) { return Utils::fromSqlDate($model->credit_date); }) - ->addColumn('private_notes', function ($model) { return $model->private_notes; }) - ->addColumn('dropdown', function ($model) { - if ($model->is_deleted) { - return '
    '; - } - - $str = ''; - }) - ->make(); + return $this->creditService->getDatatable($clientPublicId, Input::get('sSearch')); } public function create($clientPublicId = 0) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 4f6aefdd46..b24022cfcd 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -32,8 +32,8 @@ use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\ClientRepository; use App\Events\InvoiceInvitationWasViewed; use App\Events\QuoteInvitationWasViewed; - use App\Services\InvoiceService; +use App\Services\RecurringInvoiceService; use App\Http\Requests\SaveInvoiceRequest; class InvoiceController extends BaseController @@ -42,8 +42,9 @@ class InvoiceController extends BaseController protected $invoiceRepo; protected $clientRepo; protected $invoiceService; + protected $recurringInvoiceService; - public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService) + public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService, RecurringInvoiceService $recurringInvoiceService) { parent::__construct(); @@ -51,6 +52,7 @@ class InvoiceController extends BaseController $this->invoiceRepo = $invoiceRepo; $this->clientRepo = $clientRepo; $this->invoiceService = $invoiceService; + $this->recurringInvoiceService = $recurringInvoiceService; } public function index() @@ -79,49 +81,15 @@ class InvoiceController extends BaseController $accountId = Auth::user()->account_id; $search = Input::get('sSearch'); - return $this->invoiceRepo->getDatatable($accountId, $clientPublicId, ENTITY_INVOICE, $search); + return $this->invoiceService->getDatatable($accountId, $clientPublicId, ENTITY_INVOICE, $search); } public function getRecurringDatatable($clientPublicId = null) { - $query = $this->invoiceRepo->getRecurringInvoices(Auth::user()->account_id, $clientPublicId, Input::get('sSearch')); - $table = Datatable::query($query); + $accountId = Auth::user()->account_id; + $search = Input::get('sSearch'); - if (!$clientPublicId) { - $table->addColumn('checkbox', function ($model) { return ''; }); - } - - $table->addColumn('frequency', function ($model) { return link_to('invoices/'.$model->public_id, $model->frequency); }); - - if (!$clientPublicId) { - $table->addColumn('client_name', function ($model) { return link_to('clients/'.$model->client_public_id, Utils::getClientDisplayName($model)); }); - } - - return $table->addColumn('start_date', function ($model) { return Utils::fromSqlDate($model->start_date); }) - ->addColumn('end_date', function ($model) { return Utils::fromSqlDate($model->end_date); }) - ->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); }) - ->addColumn('dropdown', function ($model) { - - $str = ''; - - }) - ->make(); + return $this->recurringInvoiceService->getDatatable($accountId, $clientPublicId, ENTITY_RECURRING_INVOICE, $search); } public function view($invitationKey) diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 8f4899c122..f716d2f2a4 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -52,51 +52,7 @@ class PaymentController extends BaseController public function getDatatable($clientPublicId = null) { - $payments = $this->paymentRepo->find($clientPublicId, Input::get('sSearch')); - $table = Datatable::query($payments); - - if (!$clientPublicId) { - $table->addColumn('checkbox', function ($model) { return ''; }); - } - - $table->addColumn('invoice_number', function ($model) { return $model->invoice_public_id ? link_to('invoices/'.$model->invoice_public_id.'/edit', $model->invoice_number, ['class' => Utils::getEntityRowClass($model)]) : ''; }); - - if (!$clientPublicId) { - $table->addColumn('client_name', function ($model) { return link_to('clients/'.$model->client_public_id, Utils::getClientDisplayName($model)); }); - } - - $table->addColumn('transaction_reference', function ($model) { return $model->transaction_reference ? $model->transaction_reference : 'Manual entry'; }) - ->addColumn('payment_type', function ($model) { return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? $model->gateway_name : ''); }); - - return $table->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); }) - ->addColumn('payment_date', function ($model) { return Utils::dateToString($model->payment_date); }) - ->addColumn('dropdown', function ($model) { - if ($model->invoice_is_deleted) { - return '
    '; - } - - $str = ''; - }) - ->make(); + return $this->paymentService->getDatatable($clientPublicId, Input::get('sSearch')); } public function create($clientPublicId = 0, $invoicePublicId = 0) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index ba8fb6b7ae..e25f486688 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -13,9 +13,19 @@ use Redirect; use App\Models\Product; use App\Models\TaxRate; +use App\Services\ProductService; class ProductController extends BaseController { + protected $productService; + + public function __construct(ProductService $productService) + { + parent::__construct(); + + $this->productService = $productService; + } + public function index() { return Redirect::to('settings/' . ACCOUNT_PRODUCTS); @@ -23,40 +33,7 @@ class ProductController extends BaseController public function getDatatable() { - $account = Auth::user()->account; - - $query = DB::table('products') - ->leftJoin('tax_rates', function($join){ - $join->on('tax_rates.id', '=', 'products.default_tax_rate_id') - ->whereNull('tax_rates.deleted_at'); - }) - ->where('products.account_id', '=', Auth::user()->account_id) - ->where('products.deleted_at', '=', null) - ->select('products.public_id', 'products.product_key', 'products.notes', 'products.cost', 'tax_rates.name as tax_name', 'tax_rates.rate as tax_rate'); - - $datatable = Datatable::query($query) - ->addColumn('product_key', function ($model) { return link_to('products/'.$model->public_id.'/edit', $model->product_key); }) - ->addColumn('notes', function ($model) { return nl2br(Str::limit($model->notes, 100)); }) - ->addColumn('cost', function ($model) { return Utils::formatMoney($model->cost); }); - - if ($account->invoice_item_taxes) { - $datatable->addColumn('tax_rate', function ($model) { return $model->tax_rate ? ($model->tax_name . ' ' . $model->tax_rate . '%') : ''; }); - } - - return $datatable->addColumn('dropdown', function ($model) { - return ''; - }) - ->orderColumns(['cost', 'product_key', 'cost']) - ->make(); + return $this->productService->getDatatable(Auth::user()->account_id); } public function edit($publicId) @@ -122,10 +99,11 @@ class ProductController extends BaseController return Redirect::to('settings/' . ACCOUNT_PRODUCTS); } - public function archive($publicId) + public function bulk() { - $product = Product::scope($publicId)->firstOrFail(); - $product->delete(); + $action = Input::get('bulk_action'); + $ids = Input::get('bulk_public_id'); + $count = $this->productService->bulk($ids, $action); Session::flash('message', trans('texts.archived_product')); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index c3fdf518b5..72091326db 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -73,7 +73,7 @@ class QuoteController extends BaseController $accountId = Auth::user()->account_id; $search = Input::get('sSearch'); - return $this->invoiceRepo->getDatatable($accountId, $clientPublicId, ENTITY_QUOTE, $search); + return $this->invoiceService->getDatatable($accountId, $clientPublicId, ENTITY_QUOTE, $search); } public function create($clientPublicId = 0) @@ -126,16 +126,16 @@ class QuoteController extends BaseController public function bulk() { $action = Input::get('bulk_action') ?: Input::get('action');; + $ids = Input::get('bulk_public_id') ?: (Input::get('public_id') ?: Input::get('ids')); if ($action == 'convert') { - $invoice = Invoice::with('invoice_items')->scope(Input::get('id'))->firstOrFail(); + $invoice = Invoice::with('invoice_items')->scope($ids)->firstOrFail(); $clone = $this->invoiceService->approveQuote($invoice); Session::flash('message', trans('texts.converted_to_invoice')); return Redirect::to('invoices/'.$clone->public_id); } - $ids = Input::get('bulk_public_id') ?: (Input::get('public_id') ?: Input::get('ids')); $count = $this->invoiceService->bulk($ids, $action); if ($count > 0) { diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index b357f8d822..b0e2c9a2cc 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -16,17 +16,20 @@ use App\Models\Client; use App\Models\Task; use App\Ninja\Repositories\TaskRepository; use App\Ninja\Repositories\InvoiceRepository; +use App\Services\TaskService; class TaskController extends BaseController { protected $taskRepo; + protected $taskService; - public function __construct(TaskRepository $taskRepo, InvoiceRepository $invoiceRepo) + public function __construct(TaskRepository $taskRepo, InvoiceRepository $invoiceRepo, TaskService $taskService) { parent::__construct(); $this->taskRepo = $taskRepo; $this->invoiceRepo = $invoiceRepo; + $this->taskService = $taskService; } /** @@ -46,69 +49,9 @@ class TaskController extends BaseController public function getDatatable($clientPublicId = null) { - $tasks = $this->taskRepo->find($clientPublicId, Input::get('sSearch')); - - $table = Datatable::query($tasks); - - if (!$clientPublicId) { - $table->addColumn('checkbox', function ($model) { return ''; }) - ->addColumn('client_name', function ($model) { return $model->client_public_id ? link_to('clients/'.$model->client_public_id, Utils::getClientDisplayName($model)) : ''; }); - } - - return $table->addColumn('created_at', function($model) { return link_to("tasks/{$model->public_id}/edit", Task::calcStartTime($model)); }) - ->addColumn('time_log', function($model) { return Utils::formatTime(Task::calcDuration($model)); }) - ->addColumn('description', function($model) { return $model->description; }) - ->addColumn('invoice_number', function($model) { return self::getStatusLabel($model); }) - ->addColumn('dropdown', function ($model) { - $str = ''; - }) - ->make(); + return $this->taskService->getDatatable($clientPublicId, Input::get('sSearch')); } - private function getStatusLabel($model) { - if ($model->invoice_number) { - $class = 'success'; - $label = trans('texts.invoiced'); - } elseif ($model->is_running) { - $class = 'primary'; - $label = trans('texts.running'); - } else { - $class = 'default'; - $label = trans('texts.logged'); - } - return "

    $label

    "; - } - - /** * Store a newly created resource in storage. * diff --git a/app/Http/Controllers/TaxRateController.php b/app/Http/Controllers/TaxRateController.php index 656a7b98d8..85d3c79033 100644 --- a/app/Http/Controllers/TaxRateController.php +++ b/app/Http/Controllers/TaxRateController.php @@ -12,9 +12,19 @@ use Session; use Redirect; use App\Models\TaxRate; +use App\Services\TaxRateService; class TaxRateController extends BaseController { + protected $taxRateService; + + public function __construct(TaxRateService $taxRateService) + { + parent::__construct(); + + $this->taxRateService = $taxRateService; + } + public function index() { return Redirect::to('settings/' . ACCOUNT_TAX_RATES); @@ -22,28 +32,7 @@ class TaxRateController extends BaseController public function getDatatable() { - $query = DB::table('tax_rates') - ->where('tax_rates.account_id', '=', Auth::user()->account_id) - ->where('tax_rates.deleted_at', '=', null) - ->select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate'); - - return Datatable::query($query) - ->addColumn('name', function ($model) { return link_to('tax_rates/'.$model->public_id.'/edit', $model->name); }) - ->addColumn('rate', function ($model) { return $model->rate . '%'; }) - ->addColumn('dropdown', function ($model) { - return ''; - }) - ->orderColumns(['name', 'rate']) - ->make(); + return $this->taxRateService->getDatatable(Auth::user()->account_id); } public function edit($publicId) @@ -98,10 +87,11 @@ class TaxRateController extends BaseController return Redirect::to('settings/' . ACCOUNT_TAX_RATES); } - public function archive($publicId) + public function bulk() { - $tax_rate = TaxRate::scope($publicId)->firstOrFail(); - $tax_rate->delete(); + $action = Input::get('bulk_action'); + $ids = Input::get('bulk_public_id'); + $count = $this->taxRateService->bulk($ids, $action); Session::flash('message', trans('texts.archived_tax_rate')); diff --git a/app/Http/Controllers/TokenController.php b/app/Http/Controllers/TokenController.php index 47885fe840..604b94d576 100644 --- a/app/Http/Controllers/TokenController.php +++ b/app/Http/Controllers/TokenController.php @@ -1,13 +1,4 @@ tokenService = $tokenService; + } + public function index() { return Redirect::to('settings/' . ACCOUNT_API_TOKENS); @@ -32,38 +32,7 @@ class TokenController extends BaseController public function getDatatable() { - $query = DB::table('account_tokens') - ->where('account_tokens.account_id', '=', Auth::user()->account_id); - - if (!Session::get('show_trash:token')) { - $query->where('account_tokens.deleted_at', '=', null); - } - - $query->select('account_tokens.public_id', 'account_tokens.name', 'account_tokens.token', 'account_tokens.public_id', 'account_tokens.deleted_at'); - - return Datatable::query($query) - ->addColumn('name', function ($model) { return link_to('tokens/'.$model->public_id.'/edit', $model->name); }) - ->addColumn('token', function ($model) { return $model->token; }) - ->addColumn('dropdown', function ($model) { - $actions = ''; - - return $actions; - }) - ->orderColumns(['name', 'token']) - ->make(); + return $this->tokenService->getDatatable(Auth::user()->account_id); } public function edit($publicId) @@ -107,15 +76,13 @@ class TokenController extends BaseController return View::make('accounts.token', $data); } - public function delete() + public function bulk() { - $tokenPublicId = Input::get('tokenPublicId'); - $token = AccountToken::where('account_id', '=', Auth::user()->account_id) - ->where('public_id', '=', $tokenPublicId)->firstOrFail(); + $action = Input::get('bulk_action'); + $ids = Input::get('bulk_public_id'); + $count = $this->tokenService->bulk($ids, $action); - $token->delete(); - - Session::flash('message', trans('texts.deleted_token')); + Session::flash('message', trans('texts.archived_token')); return Redirect::to('settings/' . ACCOUNT_API_TOKENS); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 84f30ca20b..afad67b0d3 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -19,20 +19,23 @@ use App\Http\Requests; use App\Ninja\Repositories\AccountRepository; use App\Ninja\Mailers\ContactMailer; use App\Ninja\Mailers\UserMailer; +use App\Services\UserService; class UserController extends BaseController { protected $accountRepo; protected $contactMailer; protected $userMailer; + protected $userService; - public function __construct(AccountRepository $accountRepo, ContactMailer $contactMailer, UserMailer $userMailer) + public function __construct(AccountRepository $accountRepo, ContactMailer $contactMailer, UserMailer $userMailer, UserService $userService) { parent::__construct(); $this->accountRepo = $accountRepo; $this->contactMailer = $contactMailer; $this->userMailer = $userMailer; + $this->userService = $userService; } public function index() @@ -42,47 +45,7 @@ class UserController extends BaseController public function getDatatable() { - $query = DB::table('users') - ->where('users.account_id', '=', Auth::user()->account_id); - - if (!Session::get('show_trash:user')) { - $query->where('users.deleted_at', '=', null); - } - - $query->where('users.public_id', '>', 0) - ->select('users.public_id', 'users.first_name', 'users.last_name', 'users.email', 'users.confirmed', 'users.public_id', 'users.deleted_at'); - - return Datatable::query($query) - ->addColumn('first_name', function ($model) { return link_to('users/'.$model->public_id.'/edit', $model->first_name.' '.$model->last_name); }) - ->addColumn('email', function ($model) { return $model->email; }) - ->addColumn('confirmed', function ($model) { return $model->deleted_at ? trans('texts.deleted') : ($model->confirmed ? trans('texts.active') : trans('texts.pending')); }) - ->addColumn('dropdown', function ($model) { - $actions = ''; - - return $actions; - }) - ->orderColumns(['first_name', 'email', 'confirmed']) - ->make(); + return $this->userService->getDatatable(Auth::user()->account_id); } public function setTheme() @@ -139,7 +102,7 @@ class UserController extends BaseController if (!Auth::user()->registered) { Session::flash('error', trans('texts.register_to_add_user')); return Redirect::to('settings/' . ACCOUNT_USER_MANAGEMENT); - } + } if (!Auth::user()->confirmed) { Session::flash('error', trans('texts.confirmation_required')); return Redirect::to('settings/' . ACCOUNT_USER_MANAGEMENT); @@ -163,15 +126,23 @@ class UserController extends BaseController return View::make('users.edit', $data); } - public function delete() + public function bulk() { - $userPublicId = Input::get('userPublicId'); + $action = Input::get('bulk_action'); + $id = Input::get('bulk_public_id'); + $user = User::where('account_id', '=', Auth::user()->account_id) - ->where('public_id', '=', $userPublicId)->firstOrFail(); + ->where('public_id', '=', $id) + ->withTrashed() + ->firstOrFail(); - $user->delete(); + if ($action === 'archive') { + $user->delete(); + } else { + $user->restore(); + } - Session::flash('message', trans('texts.deleted_user')); + Session::flash('message', trans("texts.{$action}d_user")); return Redirect::to('settings/' . ACCOUNT_USER_MANAGEMENT); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 95213fb939..7f0af9a989 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -98,7 +98,7 @@ Route::group(['middleware' => 'auth'], function() { Route::get('api/users', array('as'=>'api.users', 'uses'=>'UserController@getDatatable')); Route::resource('users', 'UserController'); - Route::post('users/delete', 'UserController@delete'); + Route::post('users/bulk', 'UserController@bulk'); Route::get('send_confirmation/{user_id}', 'UserController@sendConfirmation'); Route::get('restore_user/{user_id}', 'UserController@restoreUser'); Route::post('users/change_password', 'UserController@changePassword'); @@ -108,15 +108,15 @@ Route::group(['middleware' => 'auth'], function() { Route::get('api/tokens', array('as'=>'api.tokens', 'uses'=>'TokenController@getDatatable')); Route::resource('tokens', 'TokenController'); - Route::post('tokens/delete', 'TokenController@delete'); + Route::post('tokens/bulk', 'TokenController@bulk'); Route::get('api/products', array('as'=>'api.products', 'uses'=>'ProductController@getDatatable')); Route::resource('products', 'ProductController'); - Route::get('products/{product_id}/archive', 'ProductController@archive'); + Route::post('products/bulk', 'ProductController@bulk'); Route::get('api/tax_rates', array('as'=>'api.tax_rates', 'uses'=>'TaxRateController@getDatatable')); Route::resource('tax_rates', 'TaxRateController'); - Route::get('tax_rates/{tax_rates_id}/archive', 'TaxRateController@archive'); + Route::post('tax_rates/bulk', 'TaxRateController@bulk'); Route::get('company/{section}/{subSection?}', 'AccountController@redirectLegacy'); Route::get('settings/data_visualizations', 'ReportController@d3'); @@ -134,7 +134,7 @@ Route::group(['middleware' => 'auth'], function() { Route::resource('gateways', 'AccountGatewayController'); Route::get('api/gateways', array('as'=>'api.gateways', 'uses'=>'AccountGatewayController@getDatatable')); - Route::post('gateways/delete', 'AccountGatewayController@delete'); + Route::post('account_gateways/bulk', 'AccountGatewayController@bulk'); Route::resource('clients', 'ClientController'); Route::get('api/clients', array('as'=>'api.clients', 'uses'=>'ClientController@getDatatable')); @@ -253,6 +253,12 @@ if (!defined('CONTACT_EMAIL')) { define('ENTITY_CREDIT', 'credit'); define('ENTITY_QUOTE', 'quote'); define('ENTITY_TASK', 'task'); + define('ENTITY_ACCOUNT_GATEWAY', 'account_gateway'); + define('ENTITY_USER', 'user'); + define('ENTITY_TOKEN', 'token'); + define('ENTITY_TAX_RATE', 'tax_rate'); + define('ENTITY_PRODUCT', 'product'); + define('ENTITY_ACTIVITY', 'activity'); define('PERSON_CONTACT', 'contact'); define('PERSON_USER', 'user'); diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 8b0a148c57..bf00184da9 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -652,12 +652,16 @@ class Utils public static function getEntityRowClass($model) { - $str = $model->is_deleted || ($model->deleted_at && $model->deleted_at != '0000-00-00') ? 'DISABLED ' : ''; + $str = ''; - if ($model->is_deleted) { - $str .= 'ENTITY_DELETED '; + if (property_exists($model, 'is_deleted')) { + $str = $model->is_deleted || ($model->deleted_at && $model->deleted_at != '0000-00-00') ? 'DISABLED ' : ''; + + if ($model->is_deleted) { + $str .= 'ENTITY_DELETED '; + } } - + if ($model->deleted_at && $model->deleted_at != '0000-00-00') { $str .= 'ENTITY_ARCHIVED '; } diff --git a/app/Models/AccountGateway.php b/app/Models/AccountGateway.php index fe1afbc693..e27a98d772 100644 --- a/app/Models/AccountGateway.php +++ b/app/Models/AccountGateway.php @@ -9,6 +9,11 @@ class AccountGateway extends EntityModel use SoftDeletes; protected $dates = ['deleted_at']; + public function getEntityType() + { + return ENTITY_ACCOUNT_GATEWAY; + } + public function gateway() { return $this->belongsTo('App\Models\Gateway'); diff --git a/app/Models/AccountToken.php b/app/Models/AccountToken.php index 909cfbfe11..dd9a988005 100644 --- a/app/Models/AccountToken.php +++ b/app/Models/AccountToken.php @@ -7,6 +7,11 @@ class AccountToken extends EntityModel use SoftDeletes; protected $dates = ['deleted_at']; + public function getEntityType() + { + return ENTITY_TOKEN; + } + public function account() { return $this->belongsTo('App\Models\Account'); diff --git a/app/Models/Product.php b/app/Models/Product.php index 98ad8e0649..6f03676618 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -7,6 +7,11 @@ class Product extends EntityModel use SoftDeletes; protected $dates = ['deleted_at']; + public function getEntityType() + { + return ENTITY_PRODUCT; + } + public static function findProductByKey($key) { return Product::scope()->where('product_key', '=', $key)->first(); diff --git a/app/Models/TaxRate.php b/app/Models/TaxRate.php index bb74c89f54..751cdb3205 100644 --- a/app/Models/TaxRate.php +++ b/app/Models/TaxRate.php @@ -6,4 +6,9 @@ class TaxRate extends EntityModel { use SoftDeletes; protected $dates = ['deleted_at']; + + public function getEntityType() + { + return ENTITY_TAX_RATE; + } } diff --git a/app/Ninja/Repositories/AccountGatewayRepository.php b/app/Ninja/Repositories/AccountGatewayRepository.php new file mode 100644 index 0000000000..b61f854f2d --- /dev/null +++ b/app/Ninja/Repositories/AccountGatewayRepository.php @@ -0,0 +1,24 @@ +join('gateways', 'gateways.id', '=', 'account_gateways.gateway_id') + ->where('account_gateways.deleted_at', '=', null) + ->where('account_gateways.account_id', '=', $accountId) + ->select('account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at', 'account_gateways.gateway_id'); + } +} diff --git a/app/Ninja/Repositories/ActivityRepository.php b/app/Ninja/Repositories/ActivityRepository.php index 8b06927418..0893bbffde 100644 --- a/app/Ninja/Repositories/ActivityRepository.php +++ b/app/Ninja/Repositories/ActivityRepository.php @@ -61,7 +61,7 @@ class ActivityRepository return $activity; } - public function findByClientId($clientId) + public function findByClientPublicId($clientPublicId) { return DB::table('activities') ->join('users', 'users.id', '=', 'activities.user_id') @@ -70,33 +70,34 @@ class ActivityRepository ->leftJoin('invoices', 'invoices.id', '=', 'activities.invoice_id') ->leftJoin('payments', 'payments.id', '=', 'activities.payment_id') ->leftJoin('credits', 'credits.id', '=', 'activities.credit_id') - ->where('activities.client_id', '=', $clientId) + ->where('clients.public_id', '=', $clientPublicId) ->where('contacts.is_primary', '=', 1) ->whereNull('contacts.deleted_at') ->select( - 'activities.id', - 'activities.created_at', - 'activities.contact_id', - 'activities.activity_type_id', - 'activities.is_system', - 'clients.currency_id', + 'activities.id', + 'activities.created_at', + 'activities.contact_id', + 'activities.activity_type_id', + 'activities.is_system', + 'clients.currency_id', 'activities.balance', - 'activities.adjustment', - 'users.first_name as user_first_name', - 'users.last_name as user_last_name', - 'users.email as user_email', - 'invoices.invoice_number as invoice', - 'invoices.public_id as invoice_public_id', - 'invoices.is_recurring', + 'activities.adjustment', + 'users.first_name as user_first_name', + 'users.last_name as user_last_name', + 'users.email as user_email', + 'invoices.invoice_number as invoice', + 'invoices.public_id as invoice_public_id', + 'invoices.is_recurring', 'clients.currency_id', 'clients.name as client_name', 'clients.public_id as client_public_id', - 'contacts.id as contact', - 'contacts.first_name as first_name', + 'contacts.id as contact', + 'contacts.first_name as first_name', 'contacts.last_name as last_name', 'contacts.email as email', 'payments.transaction_reference as payment', - 'credits.amount as credit'); + 'credits.amount as credit' + ); } } \ No newline at end of file diff --git a/app/Ninja/Repositories/BaseRepository.php b/app/Ninja/Repositories/BaseRepository.php index a91e8e0ef2..bec95fb969 100644 --- a/app/Ninja/Repositories/BaseRepository.php +++ b/app/Ninja/Repositories/BaseRepository.php @@ -23,7 +23,10 @@ class BaseRepository $entity->delete(); $className = $this->getEventClass($entity, 'Archived'); - event(new $className($entity)); + + if (class_exists($className)) { + event(new $className($entity)); + } } public function restore($entity) @@ -38,7 +41,10 @@ class BaseRepository } $className = $this->getEventClass($entity, 'Restored'); - event(new $className($entity, $fromDeleted)); + + if (class_exists($className)) { + event(new $className($entity, $fromDeleted)); + } } public function delete($entity) @@ -49,7 +55,10 @@ class BaseRepository $entity->delete(); $className = $this->getEventClass($entity, 'Deleted'); - event(new $className($entity)); + + if (class_exists($className)) { + event(new $className($entity)); + } } public function findByPublicIds($ids) diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index f43daea880..24e808c3f9 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -75,7 +75,7 @@ class InvoiceRepository extends BaseRepository $query->where('clients.public_id', '=', $clientPublicId); } - if (!\Session::get('show_trash:invoice')) { + if (!\Session::get('show_trash:recurring_invoice')) { $query->where('invoices.deleted_at', '=', null); } @@ -119,107 +119,6 @@ class InvoiceRepository extends BaseRepository ->make(); } - public function getDatatable($accountId, $clientPublicId = null, $entityType, $search) - { - $query = $this->getInvoices($accountId, $clientPublicId, $entityType, $search) - ->where('invoices.is_quote', '=', $entityType == ENTITY_QUOTE ? true : false); - - $table = \Datatable::query($query); - - if (!$clientPublicId) { - $table->addColumn('checkbox', function ($model) { return ''; }); - } - - $table->addColumn("invoice_number", function ($model) use ($entityType) { return link_to("{$entityType}s/".$model->public_id.'/edit', $model->invoice_number, ['class' => Utils::getEntityRowClass($model)]); }); - - if (!$clientPublicId) { - $table->addColumn('client_name', function ($model) { return link_to('clients/'.$model->client_public_id, Utils::getClientDisplayName($model)); }); - } - - $table->addColumn("invoice_date", function ($model) { return Utils::fromSqlDate($model->invoice_date); }) - ->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); }); - - if ($entityType == ENTITY_INVOICE) { - $table->addColumn('balance', function ($model) { - return $model->partial > 0 ? - trans('texts.partial_remaining', ['partial' => Utils::formatMoney($model->partial, $model->currency_id), 'balance' => Utils::formatMoney($model->balance, $model->currency_id)]) : - Utils::formatMoney($model->balance, $model->currency_id); - }); - } - - return $table->addColumn('due_date', function ($model) { return Utils::fromSqlDate($model->due_date); }) - ->addColumn('invoice_status_name', function ($model) { return $model->quote_invoice_id ? link_to("invoices/{$model->quote_invoice_id}/edit", trans('texts.converted')) : self::getStatusLabel($model->invoice_status_id, $model->invoice_status_name); }) - ->addColumn('dropdown', function ($model) use ($entityType) { - - $str = ''; - }) - ->make(); - } - - private function getStatusLabel($statusId, $statusName) { - $label = trans("texts.status_" . strtolower($statusName)); - $class = 'default'; - switch ($statusId) { - case INVOICE_STATUS_SENT: - $class = 'info'; - break; - case INVOICE_STATUS_VIEWED: - $class = 'warning'; - break; - case INVOICE_STATUS_PARTIAL: - $class = 'primary'; - break; - case INVOICE_STATUS_PAID: - $class = 'success'; - break; - } - return "

    $label

    "; - } - public function save($data) { $account = \Auth::user()->account; diff --git a/app/Ninja/Repositories/ProductRepository.php b/app/Ninja/Repositories/ProductRepository.php new file mode 100644 index 0000000000..417b49f236 --- /dev/null +++ b/app/Ninja/Repositories/ProductRepository.php @@ -0,0 +1,32 @@ +leftJoin('tax_rates', function($join) { + $join->on('tax_rates.id', '=', 'products.default_tax_rate_id') + ->whereNull('tax_rates.deleted_at'); + }) + ->where('products.account_id', '=', $accountId) + ->where('products.deleted_at', '=', null) + ->select( + 'products.public_id', + 'products.product_key', + 'products.notes', + 'products.cost', + 'tax_rates.name as tax_name', + 'tax_rates.rate as tax_rate', + 'products.deleted_at' + ); + } +} \ No newline at end of file diff --git a/app/Ninja/Repositories/TaxRateRepository.php b/app/Ninja/Repositories/TaxRateRepository.php index 17a9ef35a8..1b9fa8df77 100644 --- a/app/Ninja/Repositories/TaxRateRepository.php +++ b/app/Ninja/Repositories/TaxRateRepository.php @@ -1,10 +1,25 @@ where('tax_rates.account_id', '=', $accountId) + ->where('tax_rates.deleted_at', '=', null) + ->select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate', 'tax_rates.deleted_at'); + } + /* public function save($taxRates) { diff --git a/app/Ninja/Repositories/TokenRepository.php b/app/Ninja/Repositories/TokenRepository.php new file mode 100644 index 0000000000..5237eb7a03 --- /dev/null +++ b/app/Ninja/Repositories/TokenRepository.php @@ -0,0 +1,27 @@ +where('account_tokens.account_id', '=', $accountId); + + if (!Session::get('show_trash:token')) { + $query->where('account_tokens.deleted_at', '=', null); + } + + return $query->select('account_tokens.public_id', 'account_tokens.name', 'account_tokens.token', 'account_tokens.public_id', 'account_tokens.deleted_at'); + } +} diff --git a/app/Ninja/Repositories/UserRepository.php b/app/Ninja/Repositories/UserRepository.php new file mode 100644 index 0000000000..5305e2ae91 --- /dev/null +++ b/app/Ninja/Repositories/UserRepository.php @@ -0,0 +1,30 @@ +where('users.account_id', '=', $accountId); + + if (!Session::get('show_trash:user')) { + $query->where('users.deleted_at', '=', null); + } + + $query->where('users.public_id', '>', 0) + ->select('users.public_id', 'users.first_name', 'users.last_name', 'users.email', 'users.confirmed', 'users.public_id', 'users.deleted_at'); + + return $query; + } +} diff --git a/app/Services/AccountGatewayService.php b/app/Services/AccountGatewayService.php new file mode 100644 index 0000000000..61d5a9a80e --- /dev/null +++ b/app/Services/AccountGatewayService.php @@ -0,0 +1,68 @@ +accountGatewayRepo = $accountGatewayRepo; + $this->datatableService = $datatableService; + } + + protected function getRepo() + { + return $this->accountGatewayRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($accountId) + { + $query = $this->accountGatewayRepo->find($accountId); + + return $this->createDatatable(ENTITY_ACCOUNT_GATEWAY, $query, false); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'name', + function ($model) { + return link_to("gateways/{$model->public_id}/edit", $model->name); + } + ], + [ + 'payment_type', + function ($model) { + return Gateway::getPrettyPaymentType($model->gateway_id); + } + ], + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + uctrans('texts.edit_gateway'), + function ($model) { + return URL::to("gateways/{$model->public_id}/edit"); + } + ] + ]; + } + +} \ No newline at end of file diff --git a/app/Services/ActivityService.php b/app/Services/ActivityService.php new file mode 100644 index 0000000000..b8faadf577 --- /dev/null +++ b/app/Services/ActivityService.php @@ -0,0 +1,65 @@ +activityRepo = $activityRepo; + $this->datatableService = $datatableService; + } + + public function getDatatable($clientPublicId = null) + { + $query = $this->activityRepo->findByClientPublicId($clientPublicId); + + return $this->createDatatable(ENTITY_ACTIVITY, $query); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'activities.id', + function ($model) { + return Utils::timestampToDateTimeString(strtotime($model->created_at)); + } + ], + [ + 'activity_type_id', + function ($model) { + $data = [ + 'client' => link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)), + 'user' => $model->is_system ? '' . trans('texts.system') . '' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), + 'invoice' => $model->invoice ? link_to('/invoices/' . $model->invoice_public_id, $model->is_recurring ? trans('texts.recurring_invoice') : $model->invoice) : null, + 'quote' => $model->invoice ? link_to('/quotes/' . $model->invoice_public_id, $model->invoice) : null, + 'contact' => $model->contact_id ? link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)) : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), + 'payment' => $model->payment ?: '', + 'credit' => Utils::formatMoney($model->credit, $model->currency_id) + ]; + + return trans("texts.activity_{$model->activity_type_id}", $data); + } + ], + [ + 'balance', + function ($model) { + return Utils::formatMoney($model->balance, $model->currency_id); + } + ], + [ + 'adjustment', + function ($model) { + return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id) : ''; + } + ] + ]; + } +} \ No newline at end of file diff --git a/app/Services/BaseService.php b/app/Services/BaseService.php index 20553ad40b..77dbcc6542 100644 --- a/app/Services/BaseService.php +++ b/app/Services/BaseService.php @@ -1,6 +1,7 @@ getDatatableColumns($entityType, $hideClient); + $actions = $this->getDatatableActions($entityType); + + return $this->datatableService->createDatatable($entityType, $query, $columns, $actions, $showCheckbox); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return []; + } + + protected function getDatatableActions($entityType) + { + return []; + } } diff --git a/app/Services/ClientService.php b/app/Services/ClientService.php index fea373d7cb..f28e5d25d0 100644 --- a/app/Services/ClientService.php +++ b/app/Services/ClientService.php @@ -1,5 +1,8 @@ clientRepo = $clientRepo; + $this->datatableService = $datatableService; } protected function getRepo() @@ -22,4 +27,100 @@ class ClientService extends BaseService { return $this->clientRepo->save($data); } -} \ No newline at end of file + + public function getDatatable($search) + { + $query = $this->clientRepo->find($search); + + return $this->createDatatable(ENTITY_CLIENT, $query); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'name', + function ($model) { + return link_to("clients/{$model->public_id}", $model->name); + } + ], + [ + 'first_name', + function ($model) { + return link_to("clients/{$model->public_id}", $model->first_name.' '.$model->last_name); + } + ], + [ + 'email', + function ($model) { + return link_to("clients/{$model->public_id}", $model->email); + } + ], + [ + 'clients.created_at', + function ($model) { + return Utils::timestampToDateString(strtotime($model->created_at)); + } + ], + [ + 'last_login', + function ($model) { + return Utils::timestampToDateString(strtotime($model->last_login)); + } + ], + [ + 'balance', + function ($model) { + return Utils::formatMoney($model->balance, $model->currency_id); + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans('texts.edit_client'), + function ($model) { + return URL::to("clients/{$model->public_id}/edit"); + } + ], + [], + [ + trans('texts.new_task'), + function ($model) { + return URL::to("tasks/create/{$model->public_id}"); + } + ], + [ + trans('texts.new_invoice'), + function ($model) { + return URL::to("invoices/create/{$model->public_id}"); + } + ], + [ + trans('texts.new_quote'), + function ($model) { + return URL::to("quotes/create/{$model->public_id}"); + }, + function ($model) { + return Auth::user()->isPro(); + } + ], + [], + [ + trans('texts.enter_payment'), + function ($model) { + return URL::to("payments/create/{$model->public_id}"); + } + ], + [ + trans('texts.enter_credit'), + function ($model) { + return URL::to("credits/create/{$model->public_id}"); + } + ] + ]; + } +} diff --git a/app/Services/CreditService.php b/app/Services/CreditService.php index d1e23bfb4f..0ee836ae76 100644 --- a/app/Services/CreditService.php +++ b/app/Services/CreditService.php @@ -1,5 +1,7 @@ creditRepo = $creditRepo; + $this->datatableService = $datatableService; } protected function getRepo() @@ -22,4 +26,60 @@ class CreditService extends BaseService { return $this->creditRepo->save($data); } + + public function getDatatable($clientPublicId, $search) + { + $query = $this->creditRepo->find($clientPublicId, $search); + + return $this->createDatatable(ENTITY_CREDIT, $query, !$clientPublicId); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'client_name', + function ($model) { + return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)) : ''; + }, + ! $hideClient + ], + [ + 'amount', + function ($model) { + return Utils::formatMoney($model->amount, $model->currency_id) . ''; + } + ], + [ + 'balance', + function ($model) { + return Utils::formatMoney($model->balance, $model->currency_id); + } + ], + [ + 'credit_date', + function ($model) { + return Utils::fromSqlDate($model->credit_date); + } + ], + [ + 'private_notes', + function ($model) { + return $model->private_notes; + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans('texts.apply_credit'), + function ($model) { + return URL::to("payments/create/{$model->client_public_id}") . '?paymentTypeId=1'; + } + ] + ]; + } } \ No newline at end of file diff --git a/app/Services/DatatableService.php b/app/Services/DatatableService.php new file mode 100644 index 0000000000..345f937720 --- /dev/null +++ b/app/Services/DatatableService.php @@ -0,0 +1,86 @@ +addColumn('checkbox', function ($model) { + return ''; + }); + } + + foreach ($columns as $column) { + // set visible to true by default + if (count($column) == 2) { + $column[] = true; + } + + list($field, $value, $visible) = $column; + + if ($visible) { + $table->addColumn($field, $value); + $orderColumns[] = $field; + } + } + + if ($actions) { + $this->createDropdown($entityType, $table, $actions); + } + + return $table->orderColumns($orderColumns)->make(); + } + + private function createDropdown($entityType, $table, $actions) + { + $table->addColumn('dropdown', function ($model) use ($entityType, $actions) { + $str = ''; + }); + } + +} \ No newline at end of file diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index eaa60d999a..a40d3bb8fe 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -1,5 +1,7 @@ clientRepo = $clientRepo; $this->invoiceRepo = $invoiceRepo; + $this->datatableService = $datatableService; } protected function getRepo() @@ -77,5 +81,160 @@ class InvoiceService extends BaseService return $invoiceInvitation->invitation_key; } } - } + } + + public function getDatatable($accountId, $clientPublicId = null, $entityType, $search) + { + $query = $this->invoiceRepo->getInvoices($accountId, $clientPublicId, $entityType, $search) + ->where('invoices.is_quote', '=', $entityType == ENTITY_QUOTE ? true : false); + + return $this->createDatatable($entityType, $query, !$clientPublicId); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'invoice_number', + function ($model) use ($entityType) { + return link_to("{$entityType}s/{$model->public_id}/edit", $model->invoice_number, ['class' => Utils::getEntityRowClass($model)]); + } + ], + [ + 'client_name', + function ($model) { + return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)); + }, + ! $hideClient + ], + [ + 'invoice_date', + function ($model) { + return Utils::fromSqlDate($model->invoice_date); + } + ], + [ + 'amount', + function ($model) { + return Utils::formatMoney($model->amount, $model->currency_id); + } + ], + [ + 'balance', + function ($model) { + return $model->partial > 0 ? + trans('texts.partial_remaining', [ + 'partial' => Utils::formatMoney($model->partial, $model->currency_id), + 'balance' => Utils::formatMoney($model->balance, $model->currency_id)] + ) : + Utils::formatMoney($model->balance, $model->currency_id); + }, + $entityType == ENTITY_INVOICE + ], + [ + 'due_date', + function ($model) { + return Utils::fromSqlDate($model->due_date); + }, + ], + [ + 'invoice_status_name', + function ($model) { + return $model->quote_invoice_id ? link_to("invoices/{$model->quote_invoice_id}/edit", trans('texts.converted')) : self::getStatusLabel($model->invoice_status_id, $model->invoice_status_name); + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans("texts.edit_{$entityType}"), + function ($model) use ($entityType) { + return URL::to("{$entityType}s/{$model->public_id}/edit"); + } + ], + [ + trans("texts.clone_{$entityType}"), + function ($model) use ($entityType) { + return URL::to("{$entityType}s/{$model->public_id}/clone"); + } + ], + [ + trans("texts.view_history"), + function ($model) use ($entityType) { + return URL::to("{$entityType}s/{$entityType}_history/{$model->public_id}"); + } + ], + [], + [ + trans("texts.mark_sent"), + function ($model) { + return "javascript:markEntity({$model->public_id})"; + }, + function ($model) { + return $model->invoice_status_id < INVOICE_STATUS_SENT; + } + ], + [ + trans('texts.enter_payment'), + function ($model) { + return URL::to("payments/create/{$model->client_public_id}/{$model->public_id}"); + }, + function ($model) use ($entityType) { + return $entityType == ENTITY_INVOICE && $model->balance > 0; + } + ], + [ + trans("texts.view_quote"), + function ($model) { + return URL::to("quotes/{$model->quote_id}/edit"); + }, + function ($model) use ($entityType) { + return $entityType == ENTITY_INVOICE && $model->quote_id; + } + ], + [ + trans("texts.view_invoice"), + function ($model) { + return URL::to("invoices/{$model->quote_invoice_id}/edit"); + }, + function ($model) use ($entityType) { + return $entityType == ENTITY_QUOTE && $model->quote_invoice_id; + } + ], + [ + trans("texts.convert_to_invoice"), + function ($model) { + return "javascript:convertEntity({$model->public_id})"; + }, + function ($model) use ($entityType) { + return $entityType == ENTITY_QUOTE && ! $model->quote_invoice_id; + } + ] + ]; + } + + private function getStatusLabel($statusId, $statusName) + { + $label = trans("texts.status_" . strtolower($statusName)); + $class = 'default'; + switch ($statusId) { + case INVOICE_STATUS_SENT: + $class = 'info'; + break; + case INVOICE_STATUS_VIEWED: + $class = 'warning'; + break; + case INVOICE_STATUS_PARTIAL: + $class = 'primary'; + break; + case INVOICE_STATUS_PAID: + $class = 'success'; + break; + } + return "

    $label

    "; + } + } \ No newline at end of file diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index ce67c3fe5e..19c95a23bf 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -1,5 +1,6 @@ datatableService = $datatableService; $this->paymentRepo = $paymentRepo; $this->accountRepo = $accountRepo; } @@ -243,4 +246,68 @@ class PaymentService extends BaseService // create payment record return $this->createPayment($invitation, $ref); } + + public function getDatatable($clientPublicId, $search) + { + $query = $this->paymentRepo->find($clientPublicId, $search); + + return $this->createDatatable(ENTITY_PAYMENT, $query, !$clientPublicId); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'invoice_number', + function ($model) { + return link_to("invoices/{$model->invoice_public_id}/edit", $model->invoice_number, ['class' => Utils::getEntityRowClass($model)]); + } + ], + [ + 'client_name', + function ($model) { + return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)) : ''; + }, + ! $hideClient + ], + [ + 'transaction_reference', + function ($model) { + return $model->transaction_reference ? $model->transaction_reference : 'Manual entry'; + } + ], + [ + 'payment_type', + function ($model) { + return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? $model->gateway_name : ''); + } + ], + [ + 'amount', + function ($model) { + return Utils::formatMoney($model->amount, $model->currency_id); + } + ], + [ + 'payment_date', + function ($model) { + return Utils::dateToString($model->payment_date); + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans('texts.edit_payment'), + function ($model) { + return URL::to("payments/{$model->public_id}/edit"); + } + ] + ]; + } + + } diff --git a/app/Services/ProductService.php b/app/Services/ProductService.php new file mode 100644 index 0000000000..a8307f0104 --- /dev/null +++ b/app/Services/ProductService.php @@ -0,0 +1,84 @@ +datatableService = $datatableService; + $this->productRepo = $productRepo; + } + + protected function getRepo() + { + return $this->productRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($accountId) + { + $query = $this->productRepo->find($accountId); + + return $this->createDatatable(ENTITY_PRODUCT, $query, false); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'product_key', + function ($model) { + return link_to('products/'.$model->public_id.'/edit', $model->product_key); + } + ], + [ + 'notes', + function ($model) { + return nl2br(Str::limit($model->notes, 100)); + } + ], + [ + 'cost', + function ($model) { + return Utils::formatMoney($model->cost); + } + ], + [ + 'tax_rate', + function ($model) { + return $model->tax_rate ? ($model->tax_name . ' ' . $model->tax_rate . '%') : ''; + }, + Auth::user()->account->invoice_item_taxes + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + uctrans('texts.edit_product'), + function ($model) { + return URL::to("products/{$model->public_id}/edit"); + } + ] + ]; + } + +} \ No newline at end of file diff --git a/app/Services/RecurringInvoiceService.php b/app/Services/RecurringInvoiceService.php new file mode 100644 index 0000000000..25a9fb12dc --- /dev/null +++ b/app/Services/RecurringInvoiceService.php @@ -0,0 +1,73 @@ +invoiceRepo = $invoiceRepo; + $this->datatableService = $datatableService; + } + + public function getDatatable($accountId, $clientPublicId = null, $entityType, $search) + { + $query = $this->invoiceRepo->getRecurringInvoices($accountId, $clientPublicId, $search); + + return $this->createDatatable(ENTITY_RECURRING_INVOICE, $query, !$clientPublicId); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'frequency', + function ($model) { + return link_to("invoices/{$model->public_id}", $model->frequency); + } + ], + [ + 'client_name', + function ($model) { + return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)); + }, + ! $hideClient + ], + [ + 'start_date', + function ($model) { + return Utils::fromSqlDate($model->start_date); + } + ], + [ + 'end_date', + function ($model) { + return Utils::fromSqlDate($model->end_date); + } + ], + [ + 'amount', + function ($model) { + return Utils::formatMoney($model->amount, $model->currency_id); + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans('texts.edit_invoice'), + function ($model) { + return URL::to("invoices/{$model->public_id}/edit"); + } + ] + ]; + } +} \ No newline at end of file diff --git a/app/Services/TaskService.php b/app/Services/TaskService.php new file mode 100644 index 0000000000..abf49d2d65 --- /dev/null +++ b/app/Services/TaskService.php @@ -0,0 +1,134 @@ +taskRepo = $taskRepo; + $this->datatableService = $datatableService; + } + + protected function getRepo() + { + return $this->taskRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($clientPublicId, $search) + { + $query = $this->taskRepo->find($clientPublicId, $search); + + return $this->createDatatable(ENTITY_TASK, $query, !$clientPublicId); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'client_name', + function ($model) { + return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model)) : ''; + }, + ! $hideClient + ], + [ + 'created_at', + function ($model) { + return link_to("tasks/{$model->public_id}/edit", Task::calcStartTime($model)); + } + ], + [ + 'time_log', + function($model) { + return Utils::formatTime(Task::calcDuration($model)); + } + ], + [ + 'description', + function ($model) { + return $model->description; + } + ], + [ + 'invoice_number', + function ($model) { + return self::getStatusLabel($model); + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + trans('texts.edit_task'), + function ($model) { + return URL::to('tasks/'.$model->public_id.'/edit'); + }, + function ($model) { + return !$model->deleted_at || $model->deleted_at == '0000-00-00'; + } + ], + [ + trans('texts.view_invoice'), + function ($model) { + return URL::to("/invoices/{$model->invoice_public_id}/edit"); + }, + function ($model) { + return $model->invoice_number; + } + ], + [ + trans('texts.stop_task'), + function ($model) { + return "javascript:stopTask({$model->public_id})"; + }, + function ($model) { + return $model->is_running; + } + ], + [ + trans('texts.invoice_task'), + function ($model) { + return "javascript:invoiceTask({$model->public_id})"; + }, + function ($model) { + return ! $model->invoice_number && (!$model->deleted_at || $model->deleted_at == '0000-00-00'); + } + ] + ]; + } + + private function getStatusLabel($model) + { + if ($model->invoice_number) { + $class = 'success'; + $label = trans('texts.invoiced'); + } elseif ($model->is_running) { + $class = 'primary'; + $label = trans('texts.running'); + } else { + $class = 'default'; + $label = trans('texts.logged'); + } + + return "

    $label

    "; + } + +} \ No newline at end of file diff --git a/app/Services/TaxRateService.php b/app/Services/TaxRateService.php new file mode 100644 index 0000000000..38d2867f27 --- /dev/null +++ b/app/Services/TaxRateService.php @@ -0,0 +1,68 @@ +taxRateRepo = $taxRateRepo; + $this->datatableService = $datatableService; + } + + protected function getRepo() + { + return $this->taxRateRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($accountId) + { + $query = $this->taxRateRepo->find($accountId); + + return $this->createDatatable(ENTITY_TAX_RATE, $query, false); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'name', + function ($model) { + return link_to("tax_rates/{$model->public_id}/edit", $model->name); + } + ], + [ + 'rate', + function ($model) { + return $model->rate . '%'; + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + uctrans('texts.edit_tax_rate'), + function ($model) { + return URL::to("tax_rates/{$model->public_id}/edit"); + } + ] + ]; + } + +} \ No newline at end of file diff --git a/app/Services/TokenService.php b/app/Services/TokenService.php new file mode 100644 index 0000000000..5a687a0552 --- /dev/null +++ b/app/Services/TokenService.php @@ -0,0 +1,67 @@ +tokenRepo = $tokenRepo; + $this->datatableService = $datatableService; + } + + protected function getRepo() + { + return $this->tokenRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($accountId) + { + $query = $this->tokenRepo->find($accountId); + + return $this->createDatatable(ENTITY_TOKEN, $query, false); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'name', + function ($model) { + return link_to("tokens/{$model->public_id}/edit", $model->name); + } + ], + [ + 'token', + function ($model) { + return $model->token; + } + ] + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + uctrans('texts.edit_token'), + function ($model) { + return URL::to("tokens/{$model->public_id}/edit"); + } + ] + ]; + } + +} \ No newline at end of file diff --git a/app/Services/UserService.php b/app/Services/UserService.php new file mode 100644 index 0000000000..5e8e1b02ad --- /dev/null +++ b/app/Services/UserService.php @@ -0,0 +1,82 @@ +userRepo = $userRepo; + $this->datatableService = $datatableService; + } + + protected function getRepo() + { + return $this->userRepo; + } + + /* + public function save() + { + return null; + } + */ + + public function getDatatable($accountId) + { + $query = $this->userRepo->find($accountId); + + return $this->createDatatable(ENTITY_USER, $query, false); + } + + protected function getDatatableColumns($entityType, $hideClient) + { + return [ + [ + 'first_name', + function ($model) { + return link_to('users/'.$model->public_id.'/edit', $model->first_name.' '.$model->last_name); + } + ], + [ + 'email', + function ($model) { + return $model->email; + } + ], + [ + 'confirmed', + function ($model) { + return $model->deleted_at ? trans('texts.deleted') : ($model->confirmed ? trans('texts.active') : trans('texts.pending')); + } + ], + ]; + } + + protected function getDatatableActions($entityType) + { + return [ + [ + uctrans('texts.edit_user'), + function ($model) { + return URL::to("users/{$model->public_id}/edit"); + } + ], + [ + uctrans('texts.send_invite'), + function ($model) { + return URL::to("send_confirmation/{$model->public_id}"); + }, + function ($model) { + return !$model->confirmed; + } + ] + ]; + } + +} \ No newline at end of file diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3c62d26bf2..2aae6615b0 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -125,12 +125,12 @@ return array( // list pages 'archive' => 'Archive', 'delete' => 'Delete', - 'archive_client' => 'Archive client', - 'delete_client' => 'Delete client', - 'archive_payment' => 'Archive payment', - 'delete_payment' => 'Delete payment', - 'archive_credit' => 'Archive credit', - 'delete_credit' => 'Delete credit', + 'archive_client' => 'Archive Client', + 'delete_client' => 'Delete Client', + 'archive_payment' => 'Archive Payment', + 'delete_payment' => 'Delete Payment', + 'archive_credit' => 'Archive Credit', + 'delete_credit' => 'Delete Credit', 'show_archived_deleted' => 'Show archived/deleted', 'filter' => 'Filter', 'new_client' => 'New Client', @@ -835,7 +835,7 @@ return array( 'updated_tax_rate' => 'Successfully updated tax rate', 'created_tax_rate' => 'Successfully created tax rate', 'edit_tax_rate' => 'Edit tax rate', - 'archive_tax_rate' => 'Archive tax rate', + 'archive_tax_rate' => 'Archive Tax Rate', 'archived_tax_rate' => 'Successfully archived the tax rate', 'default_tax_rate_id' => 'Default Tax Rate', 'tax_rate' => 'Tax Rate', @@ -894,6 +894,16 @@ return array( 'quote_is_approved' => 'This quote is approved', 'apply_credit' => 'Apply Credit', 'system_settings' => 'System Settings', - - + 'archive_token' => 'Archive Token', + 'archived_token' => 'Successfully archived token', + 'archive_user' => 'Archive User', + 'archived_user' => 'Successfully archived user', + 'archive_account_gateway' => 'Archive Gateway', + 'archived_account_gateway' => 'Successfully archived gateway', + 'archive_recurring_invoice' => 'Archive Recurring Invoice', + 'archived_recurring_invoice' => 'Successfully archived recurring invoice', + 'delete_recurring_invoice' => 'Delete Recurring Invoice', + 'deleted_recurring_invoice' => 'Successfully deleted recurring invoice', + 'restore_recurring_invoice' => 'Restore Recurring Invoice', + 'restored_recurring_invoice' => 'Successfully restored recurring invoice', ); diff --git a/resources/views/accounts/api_tokens.blade.php b/resources/views/accounts/api_tokens.blade.php index 2f64596a92..d9e4b4498b 100644 --- a/resources/views/accounts/api_tokens.blade.php +++ b/resources/views/accounts/api_tokens.blade.php @@ -4,14 +4,6 @@ @parent @include('accounts.nav', ['selected' => ACCOUNT_API_TOKENS, 'advanced' => true]) - {!! Former::open('tokens/delete')->addClass('user-form') !!} - -
    - {!! Former::text('tokenPublicId') !!} -
    - {!! Former::close() !!} - -
    {!! Button::normal(trans('texts.documentation'))->asLinkTo(NINJA_WEB_URL.'/knowledgebase/api-documentation/')->withAttributes(['target' => '_blank'])->appendIcon(Icon::create('info-sign')) !!} @if (Utils::isNinja()) @@ -29,6 +21,8 @@ --> + @include('partials.bulk_form', ['entityType' => ENTITY_TOKEN]) + {!! Datatable::table() ->addColumn( trans('texts.name'), @@ -58,15 +52,6 @@ var checked = $('#trashed').is(':checked'); window.location = '{!! URL::to('view_archive/token') !!}' + (checked ? '/true' : '/false'); } - - function deleteToken(id) { - if (!confirm("{!! trans('texts.are_you_sure') !!}")) { - return; - } - - $('#tokenPublicId').val(id); - $('form.user-form').submit(); - } @stop diff --git a/resources/views/accounts/payments.blade.php b/resources/views/accounts/payments.blade.php index 2a62f74921..096d29fb05 100644 --- a/resources/views/accounts/payments.blade.php +++ b/resources/views/accounts/payments.blade.php @@ -4,14 +4,6 @@ @parent @include('accounts.nav', ['selected' => ACCOUNT_PAYMENTS]) - {!! Former::open('gateways/delete')->addClass('user-form') !!} - -
    - {!! Former::text('accountGatewayPublicId') !!} -
    - {!! Former::close() !!} - - @if ($showAdd) {!! Button::primary(trans('texts.add_gateway')) ->asLinkTo(URL::to('/gateways/create')) @@ -19,6 +11,8 @@ ->appendIcon(Icon::create('plus-sign')) !!} @endif + @include('partials.bulk_form', ['entityType' => ENTITY_ACCOUNT_GATEWAY]) + {!! Datatable::table() ->addColumn( trans('texts.name'), @@ -43,22 +37,6 @@ } }); } - - /* - function setTrashVisible() { - var checked = $('#trashed').is(':checked'); - window.location = '{{ URL::to('view_archive/token') }}' + (checked ? '/true' : '/false'); - } - */ - - function deleteAccountGateway(id) { - if (!confirm("{!! trans('texts.are_you_sure') !!}")) { - return; - } - - $('#accountGatewayPublicId').val(id); - $('form.user-form').submit(); - } @stop \ No newline at end of file diff --git a/resources/views/accounts/products.blade.php b/resources/views/accounts/products.blade.php index b0c12ad535..a44a6292c5 100644 --- a/resources/views/accounts/products.blade.php +++ b/resources/views/accounts/products.blade.php @@ -29,6 +29,8 @@ ->withAttributes(['class' => 'pull-right']) ->appendIcon(Icon::create('plus-sign')) !!} + @include('partials.bulk_form', ['entityType' => ENTITY_PRODUCT]) + {!! Datatable::table() ->addColumn($columns) ->setUrl(url('api/products/')) @@ -49,7 +51,7 @@ $dropdown.css('visibility','hidden'); } }); - } + } diff --git a/resources/views/accounts/tax_rates.blade.php b/resources/views/accounts/tax_rates.blade.php index 831e6358ee..09df9b04da 100644 --- a/resources/views/accounts/tax_rates.blade.php +++ b/resources/views/accounts/tax_rates.blade.php @@ -49,6 +49,8 @@ ->withAttributes(['class' => 'pull-right']) ->appendIcon(Icon::create('plus-sign')) !!} + @include('partials.bulk_form', ['entityType' => ENTITY_TAX_RATE]) + {!! Datatable::table() ->addColumn( trans('texts.name'), diff --git a/resources/views/accounts/user_management.blade.php b/resources/views/accounts/user_management.blade.php index 51a0bb8986..ed63482f8a 100644 --- a/resources/views/accounts/user_management.blade.php +++ b/resources/views/accounts/user_management.blade.php @@ -4,13 +4,6 @@ @parent @include('accounts.nav', ['selected' => ACCOUNT_USER_MANAGEMENT, 'advanced' => true]) - {!! Former::open('users/delete')->addClass('user-form') !!} - -
    - {!! Former::text('userPublicId') !!} -
    - {!! Former::close() !!} -
    @if (Utils::isPro()) @@ -24,6 +17,7 @@ {!! Session::get('show_trash:user') ? 'checked' : ''!!}/> {!! trans('texts.show_deleted_users')!!} + @include('partials.bulk_form', ['entityType' => ENTITY_USER]) {!! Datatable::table() ->addColumn( @@ -56,14 +50,6 @@ window.location = '{!! URL::to('view_archive/user') !!}' + (checked ? '/true' : '/false'); } - function deleteUser(id) { - if (!confirm("{!! trans('texts.are_you_sure') !!}")) { - return; - } - - $('#userPublicId').val(id); - $('form.user-form').submit(); - } @stop diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 87f119d418..62c43929bf 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -135,12 +135,12 @@ }); $('tbody tr').mouseover(function() { - $(this).closest('tr').find('.tr-action').css('visibility','visible'); + $(this).closest('tr').find('.tr-action').css('visibility', 'visible'); }).mouseout(function() { $dropdown = $(this).closest('tr').find('.tr-action'); if (!$dropdown.hasClass('open')) { - $dropdown.css('visibility','hidden'); - } + $dropdown.css('visibility', 'hidden'); + } }); } diff --git a/resources/views/partials/bulk_form.blade.php b/resources/views/partials/bulk_form.blade.php new file mode 100644 index 0000000000..fcffcd589b --- /dev/null +++ b/resources/views/partials/bulk_form.blade.php @@ -0,0 +1,27 @@ +
    + {!! Former::open($entityType . 's/bulk')->addClass('bulk-form') !!} + {!! Former::text('bulk_action') !!} + {!! Former::text('bulk_public_id') !!} + {!! Former::close() !!} +
    + + \ No newline at end of file From d147dba542229376da22955dcbacaf70e9eb7506 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 6 Nov 2015 00:46:02 +0200 Subject: [PATCH 2/3] Refactoring datatable code --- resources/views/partials/bulk_form.blade.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/views/partials/bulk_form.blade.php b/resources/views/partials/bulk_form.blade.php index fcffcd589b..4138c739bd 100644 --- a/resources/views/partials/bulk_form.blade.php +++ b/resources/views/partials/bulk_form.blade.php @@ -24,4 +24,7 @@ function restoreEntity(id) { submitBulkForm('restore', id); } + function deleteEntity(id) { + submitBulkForm('delete', id); + } \ No newline at end of file From 002c994c0b090df4da0c0e5efa624f5f3625afc1 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 6 Nov 2015 01:14:00 +0200 Subject: [PATCH 3/3] Refactoring datatable code --- app/Http/Controllers/ClientController.php | 2 +- app/Http/Controllers/CreditController.php | 2 +- app/Http/Controllers/InvoiceController.php | 2 +- app/Http/Controllers/PaymentController.php | 2 +- app/Http/Controllers/TaskController.php | 2 +- app/Libraries/Utils.php | 4 +++- app/Services/DatatableService.php | 14 ++++++++++++-- resources/lang/en/texts.php | 2 ++ resources/views/list.blade.php | 9 +++++++-- 9 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 7482ed3559..c281798ecd 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -51,7 +51,7 @@ class ClientController extends BaseController 'entityType' => ENTITY_CLIENT, 'title' => trans('texts.clients'), 'sortCol' => '4', - 'columns' => Utils::trans(['checkbox', 'client', 'contact', 'email', 'date_created', 'last_login', 'balance', 'action']), + 'columns' => Utils::trans(['checkbox', 'client', 'contact', 'email', 'date_created', 'last_login', 'balance', '']), )); } diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 83f5b9dc57..c3e3068c43 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -37,7 +37,7 @@ class CreditController extends BaseController 'entityType' => ENTITY_CREDIT, 'title' => trans('texts.credits'), 'sortCol' => '4', - 'columns' => Utils::trans(['checkbox', 'client', 'credit_amount', 'credit_balance', 'credit_date', 'private_notes', 'action']), + 'columns' => Utils::trans(['checkbox', 'client', 'credit_amount', 'credit_balance', 'credit_date', 'private_notes', '']), )); } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index b24022cfcd..14676624c2 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -69,7 +69,7 @@ class InvoiceController extends BaseController 'balance_due', 'due_date', 'status', - 'action' + '' ]), ]; diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index f716d2f2a4..17331f21ac 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -46,7 +46,7 @@ class PaymentController extends BaseController return View::make('list', array( 'entityType' => ENTITY_PAYMENT, 'title' => trans('texts.payments'), - 'columns' => Utils::trans(['checkbox', 'invoice', 'client', 'transaction_reference', 'method', 'payment_amount', 'payment_date', 'action']), + 'columns' => Utils::trans(['checkbox', 'invoice', 'client', 'transaction_reference', 'method', 'payment_amount', 'payment_date', '']), )); } diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index b0e2c9a2cc..efd8f05bc6 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -43,7 +43,7 @@ class TaskController extends BaseController 'entityType' => ENTITY_TASK, 'title' => trans('texts.tasks'), 'sortCol' => '2', - 'columns' => Utils::trans(['checkbox', 'client', 'date', 'duration', 'description', 'status', 'action']), + 'columns' => Utils::trans(['checkbox', 'client', 'date', 'duration', 'description', 'status', '']), )); } diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index bf00184da9..836d223162 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -150,8 +150,10 @@ class Utils foreach ($input as $field) { if ($field == "checkbox") { $data[] = $field; - } else { + } elseif ($field) { $data[] = trans("texts.$field"); + } else { + $data[] = ''; } } diff --git a/app/Services/DatatableService.php b/app/Services/DatatableService.php index 345f937720..067e5a574d 100644 --- a/app/Services/DatatableService.php +++ b/app/Services/DatatableService.php @@ -40,8 +40,18 @@ class DatatableService private function createDropdown($entityType, $table, $actions) { $table->addColumn('dropdown', function ($model) use ($entityType, $actions) { - $str = '