2015-10-13 17:44:01 +02:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use DB;
|
|
|
|
use Input;
|
|
|
|
use Utils;
|
|
|
|
use Datatable;
|
|
|
|
use App\Models\Invitation;
|
|
|
|
use App\Ninja\Repositories\InvoiceRepository;
|
|
|
|
use App\Ninja\Repositories\PaymentRepository;
|
2015-10-28 20:22:07 +01:00
|
|
|
use App\Ninja\Repositories\ActivityRepository;
|
2015-10-13 17:44:01 +02:00
|
|
|
|
|
|
|
class PublicClientController extends BaseController
|
|
|
|
{
|
|
|
|
private $invoiceRepo;
|
|
|
|
private $paymentRepo;
|
|
|
|
|
2015-10-28 20:22:07 +01:00
|
|
|
public function __construct(InvoiceRepository $invoiceRepo, PaymentRepository $paymentRepo, ActivityRepository $activityRepo)
|
2015-10-13 17:44:01 +02:00
|
|
|
{
|
|
|
|
$this->invoiceRepo = $invoiceRepo;
|
|
|
|
$this->paymentRepo = $paymentRepo;
|
2015-10-28 20:22:07 +01:00
|
|
|
$this->activityRepo = $activityRepo;
|
2015-10-13 17:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function dashboard()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return $this->returnError();
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$account = $invitation->account;
|
|
|
|
$invoice = $invitation->invoice;
|
|
|
|
$client = $invoice->client;
|
|
|
|
$color = $account->primary_color ? $account->primary_color : '#0b4d78';
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'color' => $color,
|
|
|
|
'account' => $account,
|
|
|
|
'client' => $client,
|
2015-10-14 22:56:17 +02:00
|
|
|
'hideLogo' => $account->isWhiteLabel(),
|
2015-12-30 19:11:51 +01:00
|
|
|
'clientViewCSS' => $account->clientViewCSS(),
|
2015-10-13 17:44:01 +02:00
|
|
|
];
|
2016-01-06 21:46:11 +01:00
|
|
|
|
2015-10-13 17:44:01 +02:00
|
|
|
return response()->view('invited.dashboard', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function activityDatatable()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$invoice = $invitation->invoice;
|
|
|
|
|
2015-11-16 13:30:44 +01:00
|
|
|
$query = $this->activityRepo->findByClientId($invoice->client_id);
|
2015-10-28 20:22:07 +01:00
|
|
|
$query->where('activities.adjustment', '!=', 0);
|
2015-10-13 17:44:01 +02:00
|
|
|
|
|
|
|
return Datatable::query($query)
|
|
|
|
->addColumn('activities.id', function ($model) { return Utils::timestampToDateTimeString(strtotime($model->created_at)); })
|
2015-12-31 12:31:50 +01:00
|
|
|
->addColumn('activity_type_id', function ($model) {
|
2015-10-28 20:22:07 +01:00
|
|
|
$data = [
|
|
|
|
'client' => Utils::getClientDisplayName($model),
|
|
|
|
'user' => $model->is_system ? ('<i>' . trans('texts.system') . '</i>') : ($model->user_first_name . ' ' . $model->user_last_name),
|
|
|
|
'invoice' => trans('texts.invoice') . ' ' . $model->invoice,
|
|
|
|
'contact' => Utils::getClientDisplayName($model),
|
|
|
|
'payment' => trans('texts.payment') . ($model->payment ? ' ' . $model->payment : ''),
|
|
|
|
];
|
|
|
|
|
|
|
|
return trans("texts.activity_{$model->activity_type_id}", $data);
|
|
|
|
})
|
2015-12-07 14:34:55 +01:00
|
|
|
->addColumn('balance', function ($model) { return Utils::formatMoney($model->balance, $model->currency_id, $model->country_id); })
|
2015-12-14 22:05:17 +01:00
|
|
|
->addColumn('adjustment', function ($model) { return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id, $model->country_id) : ''; })
|
2015-10-13 17:44:01 +02:00
|
|
|
->make();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function invoiceIndex()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return $this->returnError();
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$account = $invitation->account;
|
|
|
|
$color = $account->primary_color ? $account->primary_color : '#0b4d78';
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'color' => $color,
|
|
|
|
'hideLogo' => $account->isWhiteLabel(),
|
2015-12-30 19:11:51 +01:00
|
|
|
'clientViewCSS' => $account->clientViewCSS(),
|
2015-10-13 17:44:01 +02:00
|
|
|
'title' => trans('texts.invoices'),
|
|
|
|
'entityType' => ENTITY_INVOICE,
|
|
|
|
'columns' => Utils::trans(['invoice_number', 'invoice_date', 'invoice_total', 'balance_due', 'due_date']),
|
|
|
|
];
|
|
|
|
|
|
|
|
return response()->view('public_list', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function invoiceDatatable()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
2015-12-27 12:08:58 +01:00
|
|
|
return '';
|
2015-10-20 19:12:34 +02:00
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
|
|
|
|
return $this->invoiceRepo->getClientDatatable($invitation->contact_id, ENTITY_INVOICE, Input::get('sSearch'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function paymentIndex()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return $this->returnError();
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$account = $invitation->account;
|
|
|
|
$color = $account->primary_color ? $account->primary_color : '#0b4d78';
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'color' => $color,
|
|
|
|
'hideLogo' => $account->isWhiteLabel(),
|
2015-12-30 19:11:51 +01:00
|
|
|
'clientViewCSS' => $account->clientViewCSS(),
|
2015-10-13 17:44:01 +02:00
|
|
|
'entityType' => ENTITY_PAYMENT,
|
|
|
|
'title' => trans('texts.payments'),
|
|
|
|
'columns' => Utils::trans(['invoice', 'transaction_reference', 'method', 'payment_amount', 'payment_date'])
|
|
|
|
];
|
|
|
|
|
|
|
|
return response()->view('public_list', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function paymentDatatable()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$payments = $this->paymentRepo->findForContact($invitation->contact->id, Input::get('sSearch'));
|
|
|
|
|
|
|
|
return Datatable::query($payments)
|
|
|
|
->addColumn('invoice_number', function ($model) { return $model->invitation_key ? link_to('/view/'.$model->invitation_key, $model->invoice_number) : $model->invoice_number; })
|
|
|
|
->addColumn('transaction_reference', function ($model) { return $model->transaction_reference ? $model->transaction_reference : '<i>Manual entry</i>'; })
|
|
|
|
->addColumn('payment_type', function ($model) { return $model->payment_type ? $model->payment_type : ($model->account_gateway_id ? '<i>Online payment</i>' : ''); })
|
2015-12-07 14:34:55 +01:00
|
|
|
->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id); })
|
2015-10-13 17:44:01 +02:00
|
|
|
->addColumn('payment_date', function ($model) { return Utils::dateToString($model->payment_date); })
|
|
|
|
->make();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function quoteIndex()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return $this->returnError();
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
$account = $invitation->account;
|
|
|
|
$color = $account->primary_color ? $account->primary_color : '#0b4d78';
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'color' => $color,
|
|
|
|
'hideLogo' => $account->isWhiteLabel(),
|
2015-12-30 19:11:51 +01:00
|
|
|
'clientViewCSS' => $account->clientViewCSS(),
|
2015-10-13 17:44:01 +02:00
|
|
|
'title' => trans('texts.quotes'),
|
|
|
|
'entityType' => ENTITY_QUOTE,
|
|
|
|
'columns' => Utils::trans(['quote_number', 'quote_date', 'quote_total', 'due_date']),
|
|
|
|
];
|
|
|
|
|
|
|
|
return response()->view('public_list', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function quoteDatatable()
|
|
|
|
{
|
2015-10-20 19:12:34 +02:00
|
|
|
if (!$invitation = $this->getInvitation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-13 17:44:01 +02:00
|
|
|
|
|
|
|
return $this->invoiceRepo->getClientDatatable($invitation->contact_id, ENTITY_QUOTE, Input::get('sSearch'));
|
|
|
|
}
|
|
|
|
|
2015-10-20 19:12:34 +02:00
|
|
|
private function returnError()
|
|
|
|
{
|
|
|
|
return response()->view('error', [
|
|
|
|
'error' => trans('texts.invoice_not_found'),
|
|
|
|
'hideHeader' => true,
|
2015-12-30 19:11:51 +01:00
|
|
|
'clientViewCSS' => $account->clientViewCSS(),
|
2015-10-20 19:12:34 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-10-13 17:44:01 +02:00
|
|
|
private function getInvitation()
|
|
|
|
{
|
|
|
|
$invitationKey = session('invitation_key');
|
|
|
|
|
|
|
|
if (!$invitationKey) {
|
2015-10-20 19:12:34 +02:00
|
|
|
return false;
|
2015-10-13 17:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$invitation = Invitation::where('invitation_key', '=', $invitationKey)->first();
|
|
|
|
|
|
|
|
if (!$invitation || $invitation->is_deleted) {
|
2015-10-20 19:12:34 +02:00
|
|
|
return false;
|
2015-10-13 17:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$invoice = $invitation->invoice;
|
|
|
|
|
|
|
|
if (!$invoice || $invoice->is_deleted) {
|
2015-10-20 19:12:34 +02:00
|
|
|
return false;
|
2015-10-13 17:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $invitation;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|