This commit is contained in:
denisdulici 2017-12-11 11:01:44 +03:00
parent 9d7ace396c
commit 962ac5cff9
5 changed files with 14 additions and 39 deletions

View File

@ -3,8 +3,7 @@
namespace App\Http\Controllers\Customers; namespace App\Http\Controllers\Customers;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Income\Invoice;
use Auth;
class Dashboard extends Controller class Dashboard extends Controller
{ {
@ -16,8 +15,10 @@ class Dashboard extends Controller
*/ */
public function index() public function index()
{ {
$user = Auth::user()->customer; $customer = auth()->user()->customer;
return view('customers.dashboard.index', compact('user')); $invoices = Invoice::with('status')->accrued()->where('customer_id', $customer->id)->get();
return view('customers.dashboard.index', compact('customer', 'invoices'));
} }
} }

View File

@ -12,8 +12,6 @@ use App\Models\Setting\Currency;
use App\Traits\Currencies; use App\Traits\Currencies;
use App\Traits\DateTime; use App\Traits\DateTime;
use App\Traits\Uploads; use App\Traits\Uploads;
use Auth;
use App\Utilities\Modules; use App\Utilities\Modules;
class Invoices extends Controller class Invoices extends Controller
@ -27,19 +25,7 @@ class Invoices extends Controller
*/ */
public function index() public function index()
{ {
$invoices = Invoice::with('status')->where('customer_id', '=', Auth::user()->customer->id)->paginate(); $invoices = Invoice::with('status')->accrued()->where('customer_id', auth()->user()->customer->id)->paginate();
foreach ($invoices as $invoice) {
$paid = 0;
foreach ($invoice->payments as $item) {
$item->default_currency_code = $invoice->currency_code;
$paid += $item->getDynamicConvertedAmount();
}
$invoice->amount = $invoice->amount - $paid;
}
$status = collect(InvoiceStatus::all()->pluck('name', 'code')) $status = collect(InvoiceStatus::all()->pluck('name', 'code'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.statuses', 2)]), ''); ->prepend(trans('general.all_type', ['type' => trans_choice('general.statuses', 2)]), '');
@ -94,7 +80,7 @@ class Invoices extends Controller
/** /**
* Show the form for viewing the specified resource. * Show the form for viewing the specified resource.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */
@ -126,7 +112,7 @@ class Invoices extends Controller
/** /**
* Show the form for viewing the specified resource. * Show the form for viewing the specified resource.
* *
* @param int $invoice_id * @param Invoice $invoice
* *
* @return Response * @return Response
*/ */

View File

@ -17,7 +17,7 @@
</div> </div>
</div> </div>
<div class="box-body"> <div class="box-body">
@if ($user->invoices->count()) @if ($invoices->count())
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
@ -29,13 +29,13 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($user->invoices as $item) @foreach($invoices as $item)
<tr> <tr>
<td><a href="{{ url('customers/invoices/' . $item->id) }}">{{ $item->invoice_number }}</a></td> <td><a href="{{ url('customers/invoices/' . $item->id) }}">{{ $item->invoice_number }}</a></td>
<td class="text-right">@money($item->amount, $item->currency_code, true)</td> <td class="text-right">@money($item->amount, $item->currency_code, true)</td>
<td class="text-right">{{ Date::parse($item->invoiced_at)->format($date_format) }}</td> <td class="text-right">{{ Date::parse($item->invoiced_at)->format($date_format) }}</td>
<td class="text-right">{{ Date::parse($item->due_at)->format($date_format) }}</td> <td class="text-right">{{ Date::parse($item->due_at)->format($date_format) }}</td>
<td class="text-center">{{ $item->status->name }}</td> <td class="text-center"><span class="label {{ $item->status->label }}">{{ $item->status->name }}</span></td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
@ -62,7 +62,7 @@
</div> </div>
</div> </div>
<div class="box-body"> <div class="box-body">
@if ($user->revenues->count()) @if ($customer->revenues->count())
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
@ -73,7 +73,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($user->revenues as $item) @foreach($customer->revenues as $item)
<tr> <tr>
<td><a href="{{ url('customers/payments/' . $item->id . '') }}">{{ Date::parse($item->paid_at)->format($date_format) }}</a></td> <td><a href="{{ url('customers/payments/' . $item->id . '') }}">{{ Date::parse($item->paid_at)->format($date_format) }}</a></td>
<td>@money($item->amount, $item->currency_code, true)</td> <td>@money($item->amount, $item->currency_code, true)</td>

View File

@ -2,12 +2,6 @@
@section('title', trans_choice('general.invoices', 2)) @section('title', trans_choice('general.invoices', 2))
@permission('create-customers-invoices')
@section('new_button')
<span class="new-button"><a href="{{ url('customers/invoices/create') }}" class="btn btn-success btn-sm"><span class="fa fa-plus"></span> &nbsp;{{ trans('general.add_new') }}</a></span>
@endsection
@endpermission
@section('content') @section('content')
<!-- Default box --> <!-- Default box -->
<div class="box box-success"> <div class="box box-success">
@ -45,7 +39,7 @@
<td class="text-right">@money($item->amount, $item->currency_code, true)</td> <td class="text-right">@money($item->amount, $item->currency_code, true)</td>
<td class="text-right">{{ Date::parse($item->invoiced_at)->format($date_format) }}</td> <td class="text-right">{{ Date::parse($item->invoiced_at)->format($date_format) }}</td>
<td class="text-right">{{ Date::parse($item->due_at)->format($date_format) }}</td> <td class="text-right">{{ Date::parse($item->due_at)->format($date_format) }}</td>
<td class="text-center">{{ $item->status->name }}</td> <td class="text-center"><span class="label {{ $item->status->label }}">{{ $item->status->name }}</span></td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>

View File

@ -2,12 +2,6 @@
@section('title', trans_choice('general.payments', 1)) @section('title', trans_choice('general.payments', 1))
@permission('create-customers-revenues')
@section('new_button')
<span class="new-button"><a href="{{ url('incomes/revenues/create') }}" class="btn btn-success btn-sm"><span class="fa fa-plus"></span> &nbsp;{{ trans('general.add_new') }}</a></span>
@endsection
@endpermission
@section('content') @section('content')
<!-- Default box --> <!-- Default box -->
<div class="box box-success"> <div class="box box-success">