diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php
index 9f190bbf26f5..56f8fd662375 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 02700e23301d..44d87429d691 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 c5ed7e5b4154..c281798ecd7c 100644
--- a/app/Http/Controllers/ClientController.php
+++ b/app/Http/Controllers/ClientController.php
@@ -51,57 +51,13 @@ 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', '']),
));
}
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 81dc77fe38ee..c3e3068c43bb 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)
{
@@ -37,48 +37,13 @@ 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', '']),
));
}
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 4f6aefdd46ff..14676624c272 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()
@@ -67,7 +69,7 @@ class InvoiceController extends BaseController
'balance_due',
'due_date',
'status',
- 'action'
+ ''
]),
];
@@ -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 8f4899c1223f..17331f21ac4f 100644
--- a/app/Http/Controllers/PaymentController.php
+++ b/app/Http/Controllers/PaymentController.php
@@ -46,57 +46,13 @@ 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', '']),
));
}
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 ba8fb6b7ae3a..e25f486688d5 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 c3fdf518b5b8..72091326db6f 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 b357f8d8223a..efd8f05bc680 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;
}
/**
@@ -40,75 +43,15 @@ 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', '']),
));
}
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 = '
-
- ';
- }
-
- return $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 656a7b98d84c..85d3c7903383 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 47885fe84066..604b94d576b3 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 84f30ca20bfb..afad67b0d3ec 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 95213fb93966..7f0af9a9893f 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 8b0a148c57cd..836d223162e3 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[] = '';
}
}
@@ -652,12 +654,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 fe1afbc69327..e27a98d772bb 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 909cfbfe1195..dd9a98800535 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 98ad8e064939..6f03676618e1 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 bb74c89f541c..751cdb3205b2 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 000000000000..b61f854f2dc5
--- /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 8b06927418d5..0893bbffdea4 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 a91e8e0ef21c..bec95fb96921 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 f43daea8803b..24e808c3f922 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 000000000000..417b49f23640
--- /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 17a9ef35a892..1b9fa8df773b 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 000000000000..5237eb7a0369
--- /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 000000000000..5305e2ae9108
--- /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 000000000000..61d5a9a80e1c
--- /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 000000000000..b8faadf57792
--- /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 20553ad40bc1..77dbcc65421a 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 fea373d7cb9b..f28e5d25d023 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 d1e23bfb4f75..0ee836ae76bb 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 000000000000..067e5a574d34
--- /dev/null
+++ b/app/Services/DatatableService.php
@@ -0,0 +1,96 @@
+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 = '';
+
+ if (property_exists($model, 'is_deleted') && $model->is_deleted) {
+ $str .= '';
+ } elseif ($model->deleted_at && $model->deleted_at !== '0000-00-00') {
+ $str .= '';
+ } else {
+ $str .= '';
+ }
+
+ $str .= '
+
+
';
+ });
+ }
+
+}
\ No newline at end of file
diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php
index eaa60d999a92..a40d3bb8fec3 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 ce67c3fe5e44..19c95a23bfbf 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 000000000000..a8307f0104cd
--- /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 000000000000..25a9fb12dcb6
--- /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 000000000000..abf49d2d65ef
--- /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 000000000000..38d2867f275c
--- /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 000000000000..5a687a0552aa
--- /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 000000000000..5e8e1b02ad0a
--- /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 3c62d26bf244..154b23025bce 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,18 @@ 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',
+ 'archived' => 'Archived',
-
);
diff --git a/resources/views/accounts/api_tokens.blade.php b/resources/views/accounts/api_tokens.blade.php
index 2f64596a92cf..d9e4b4498bee 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 2a62f7492184..096d29fb0541 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 b0c12ad53538..a44a6292c591 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 831e6358ee64..09df9b04dad4 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 51a0bb8986b8..ed63482f8ae5 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 87f119d41869..7bed68513938 100644
--- a/resources/views/list.blade.php
+++ b/resources/views/list.blade.php
@@ -135,12 +135,17 @@
});
$('tbody tr').mouseover(function() {
- $(this).closest('tr').find('.tr-action').css('visibility','visible');
+ $(this).closest('tr').find('.tr-action').css('display', 'inline-block');
+ $(this).closest('tr').find('.tr-status').css('display', 'none');
}).mouseout(function() {
+ //$(this).closest('tr').find('.tr-action').css('display', 'none');
+
$dropdown = $(this).closest('tr').find('.tr-action');
if (!$dropdown.hasClass('open')) {
- $dropdown.css('visibility','hidden');
- }
+ $dropdown.css('display', 'none');
+ $(this).closest('tr').find('.tr-status').css('display', 'inline-block');
+ }
+
});
}
diff --git a/resources/views/partials/bulk_form.blade.php b/resources/views/partials/bulk_form.blade.php
new file mode 100644
index 000000000000..4138c739bd49
--- /dev/null
+++ b/resources/views/partials/bulk_form.blade.php
@@ -0,0 +1,30 @@
+
+ {!! 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