akaunting 3.0 (the last dance)
This commit is contained in:
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Portal;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Charts;
|
||||
use App\Traits\DateTime;
|
||||
use App\Utilities\Chartjs;
|
||||
use Date;
|
||||
|
||||
class Dashboard
|
||||
@ -38,82 +37,10 @@ class Dashboard
|
||||
|
||||
//$invoices = Document::invoice()->accrued()->where('contact_id', $contact->id)->get();
|
||||
$invoices = Document::invoice()->accrued()->whereBetween('due_at', [$start, $end])->where('contact_id', $contact->id)->get();
|
||||
|
||||
$start_month = $start->month;
|
||||
$end_month = $end->month;
|
||||
|
||||
// look cashFlow widget
|
||||
$end_month = $end->diffInMonths($start);
|
||||
$start_month = 0;
|
||||
// Monthly
|
||||
$labels = [];
|
||||
|
||||
$s = clone $start;
|
||||
|
||||
for ($j = $end_month; $j >= $start_month; $j--) {
|
||||
$labels[$end_month - $j] = $s->format('M Y');
|
||||
|
||||
$s->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$amounts = $this->calculateAmounts($invoices, $start, $end);
|
||||
|
||||
$grand = array_sum($amounts['unpaid']) + array_sum($amounts['paid']) + array_sum($amounts['overdue']);
|
||||
|
||||
$totals = [
|
||||
'paid' => money(array_sum($amounts['paid']), setting('default.currency'), true),
|
||||
'unpaid' => money(array_sum($amounts['unpaid']), setting('default.currency'), true),
|
||||
'overdue' => money(array_sum($amounts['overdue']), setting('default.currency'), true),
|
||||
];
|
||||
|
||||
$progress = [
|
||||
'paid' => !empty($grand) ? (100 / $grand) * array_sum($amounts['paid']) : '0',
|
||||
'unpaid' => !empty($grand) ? (100 / $grand) * array_sum($amounts['unpaid']) : '0',
|
||||
'overdue' => !empty($grand) ? (100 / $grand) * array_sum($amounts['overdue']) : '0',
|
||||
];
|
||||
|
||||
$chart = new Chartjs();
|
||||
$chart->type('line')
|
||||
->width(0)
|
||||
->height(300)
|
||||
->options($this->getLineChartOptions())
|
||||
->labels(array_values($labels));
|
||||
|
||||
$chart->dataset(trans('general.paid'), 'line', array_values($amounts['paid']))
|
||||
->backgroundColor('#6da252')
|
||||
->color('#6da252')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$chart->dataset(trans('general.unpaid'), 'line', array_values($amounts['unpaid']))
|
||||
->backgroundColor('#efad32')
|
||||
->color('#efad32')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$chart->dataset(trans('general.overdue'), 'line', array_values($amounts['overdue']))
|
||||
->backgroundColor('#ef3232')
|
||||
->color('#ef3232')
|
||||
->options([
|
||||
'borderWidth' => 4,
|
||||
'pointStyle' => 'line',
|
||||
])
|
||||
->fill(false);
|
||||
|
||||
$date_picker_shortcuts = $this->getDatePickerShortcuts();
|
||||
|
||||
if (!request()->has('start_date')) {
|
||||
request()->merge(['start_date' => $date_picker_shortcuts[trans('reports.this_year')]['start']]);
|
||||
request()->merge(['end_date' => $date_picker_shortcuts[trans('reports.this_year')]['end']]);
|
||||
}
|
||||
|
||||
return view('portal.dashboard.index', compact('contact', 'invoices', 'totals', 'progress', 'chart', 'date_picker_shortcuts'));
|
||||
return view('portal.dashboard.index', compact('contact', 'invoices'));
|
||||
}
|
||||
|
||||
private function calculateAmounts($invoices, $start, $end)
|
||||
|
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Portal;
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Http\Requests\Portal\InvoiceShow as Request;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Documents;
|
||||
@ -33,11 +32,7 @@ class Invoices extends Controller
|
||||
->accrued()->where('contact_id', user()->contact->id)
|
||||
->collect(['document_number'=> 'desc']);
|
||||
|
||||
$categories = collect(Category::income()->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
|
||||
$statuses = $this->getDocumentStatuses(Document::INVOICE_TYPE);
|
||||
|
||||
return $this->response('portal.invoices.index', compact('invoices', 'categories', 'statuses'));
|
||||
return $this->response('portal.invoices.index', compact('invoices'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,6 +51,20 @@ class Invoices extends Controller
|
||||
return view('portal.invoices.show', compact('invoice', 'payment_methods'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
* @param Document $invoice
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function finish(Document $invoice, Request $request)
|
||||
{
|
||||
$layout = $request->isPortal($invoice->company_id) ? 'portal' : 'signed';
|
||||
|
||||
return view('portal.invoices.finish', compact('invoice', 'layout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
@ -98,6 +107,27 @@ class Invoices extends Controller
|
||||
return $pdf->download($file_name);
|
||||
}
|
||||
|
||||
public function preview(Document $invoice)
|
||||
{
|
||||
if (empty($invoice)) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$payment_actions = [];
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
foreach ($payment_methods as $payment_method_key => $payment_method_value) {
|
||||
$codes = explode('.', $payment_method_key);
|
||||
|
||||
if (!isset($payment_actions[$codes[0]])) {
|
||||
$payment_actions[$codes[0]] = URL::signedRoute('signed.' . $codes[0] . '.invoices.show', [$invoice->id]);
|
||||
}
|
||||
}
|
||||
|
||||
return view('portal.invoices.preview', compact('invoice', 'payment_methods', 'payment_actions'));
|
||||
}
|
||||
|
||||
public function signed(Document $invoice)
|
||||
{
|
||||
if (empty($invoice)) {
|
||||
@ -119,7 +149,10 @@ class Invoices extends Controller
|
||||
$print_action = URL::signedRoute('signed.invoices.print', [$invoice->id]);
|
||||
$pdf_action = URL::signedRoute('signed.invoices.pdf', [$invoice->id]);
|
||||
|
||||
event(new \App\Events\Document\DocumentViewed($invoice));
|
||||
// Guest or Invoice contact user track the invoice viewed.
|
||||
if (empty(user()) || user()->id == $invoice->contact->user_id) {
|
||||
event(new \App\Events\Document\DocumentViewed($invoice));
|
||||
}
|
||||
|
||||
return view('portal.invoices.signed', compact('invoice', 'payment_methods', 'payment_actions', 'print_action', 'pdf_action'));
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Events\Banking\TransactionPrinting;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Http\Requests\Portal\PaymentShow as Request;
|
||||
@ -65,10 +66,10 @@ class Payments extends Controller
|
||||
*/
|
||||
public function printPayment(Transaction $payment, Request $request)
|
||||
{
|
||||
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||
event(new TransactionPrinting($payment));
|
||||
|
||||
$revenue = $payment;
|
||||
$view = view($payment->template_path, compact('revenue'));
|
||||
$transaction = $payment;
|
||||
$view = view('banking.transactions.print_default', compact('transaction'));
|
||||
|
||||
return mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
|
||||
}
|
||||
@ -82,12 +83,12 @@ class Payments extends Controller
|
||||
*/
|
||||
public function pdfPayment(Transaction $payment, Request $request)
|
||||
{
|
||||
event(new \App\Events\Banking\TransactionPrinting($payment));
|
||||
event(new TransactionPrinting($payment));
|
||||
|
||||
$currency_style = true;
|
||||
|
||||
$revenue = $payment;
|
||||
$view = view($payment->template_path, compact('revenue', 'currency_style'))->render();
|
||||
$transaction = $payment;
|
||||
$view = view('banking.transactions.print_default', compact('transaction', 'currency_style'))->render();
|
||||
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
|
||||
|
||||
$pdf = app('dompdf.wrapper');
|
||||
@ -100,6 +101,15 @@ class Payments extends Controller
|
||||
return $pdf->download($file_name);
|
||||
}
|
||||
|
||||
public function preview(Transaction $payment)
|
||||
{
|
||||
if (empty($payment)) {
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
return view('portal.payments.preview', compact('payment'));
|
||||
}
|
||||
|
||||
public function signed(Transaction $payment)
|
||||
{
|
||||
if (empty($payment)) {
|
||||
|
@ -47,6 +47,7 @@ class Profile extends Controller
|
||||
|
||||
// Do not reset password if not entered/changed
|
||||
if (empty($request['password'])) {
|
||||
unset($request['current_password']);
|
||||
unset($request['password']);
|
||||
unset($request['password_confirmation']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user