1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Controllers/PublicClientController.php

197 lines
6.8 KiB
PHP
Raw Normal View History

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-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-15 18:23:45 +01:00
$query = $this->activityRepo->findByClientPublicId($invoice->client->public_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-10-28 20:22:07 +01:00
->addColumn('message', function ($model) {
$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-10-13 17:44:01 +02:00
->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();
}
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(),
'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()) {
return false;
}
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(),
'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>' : ''); })
->addColumn('amount', function ($model) { return Utils::formatMoney($model->amount, $model->currency_id); })
->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(),
'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-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;
}
}