Skip to content

Commit

Permalink
close #799 Fixed: Customer Login - Invoice Sorting not working
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Mar 25, 2019
1 parent 575557d commit b6da292
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
43 changes: 17 additions & 26 deletions app/Http/Controllers/Customers/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Events\InvoicePrinting;
use App\Models\Banking\Account;
use App\Models\Income\Customer;
use App\Models\Income\Revenue;
use App\Models\Income\Invoice;
use App\Models\Income\InvoiceStatus;
use App\Models\Setting\Category;
Expand All @@ -33,12 +32,18 @@ class Invoices extends Controller
*/
public function index()
{
$invoices = Invoice::with('status')->accrued()->where('customer_id', auth()->user()->customer->id)->paginate();
$invoices = Invoice::with(['customer', 'status', 'items', 'payments', 'histories'])
->accrued()->where('customer_id', auth()->user()->customer->id)
->collect(['invoice_number'=> 'desc']);

$status = collect(InvoiceStatus::all()->pluck('name', 'code'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.statuses', 2)]), '');
$categories = collect(Category::enabled()->type('income')->orderBy('name')->pluck('name', 'id'));

return view('customers.invoices.index', compact('invoices', 'status'));
$statuses = collect(InvoiceStatus::get()->each(function ($item) {
$item->name = trans('invoices.status.' . $item->code);
return $item;
})->pluck('name', 'code'));

return view('customers.invoices.index', compact('invoices', 'categories', 'statuses'));
}

/**
Expand All @@ -50,31 +55,15 @@ public function index()
*/
public function show(Invoice $invoice)
{
$paid = 0;

foreach ($invoice->payments as $item) {
$amount = $item->amount;

if ($invoice->currency_code != $item->currency_code) {
$item->default_currency_code = $invoice->currency_code;

$amount = $item->getDynamicConvertedAmount();
}
$accounts = Account::enabled()->orderBy('name')->pluck('name', 'id');

$paid += $amount;
}

$invoice->paid = $paid;

$accounts = Account::enabled()->pluck('name', 'id');

$currencies = Currency::enabled()->pluck('name', 'code')->toArray();
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();

$account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first();

$customers = Customer::enabled()->pluck('name', 'id');
$customers = Customer::enabled()->orderBy('name')->pluck('name', 'id');

$categories = Category::enabled()->type('income')->pluck('name', 'id');
$categories = Category::enabled()->type('income')->orderBy('name')->pluck('name', 'id');

$payment_methods = Modules::getPaymentMethods();

Expand Down Expand Up @@ -106,7 +95,9 @@ public function pdfInvoice(Invoice $invoice)
{
$invoice = $this->prepareInvoice($invoice);

$view = view($invoice->template_path, compact('invoice'))->render();
$currency_style = true;

$view = view($invoice->template_path, compact('invoice', 'currency_style'))->render();
$html = mb_convert_encoding($view, 'HTML-ENTITIES');

$pdf = \App::make('dompdf.wrapper');
Expand Down
57 changes: 44 additions & 13 deletions resources/views/customers/invoices/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
<div class="box box-success">
<div class="box-header with-border">
{!! Form::open(['url' => 'customers/invoices', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<div id="items" class="pull-left box-filter">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
{!! Form::text('search', request('search'), ['class' => 'form-control input-filter input-sm', 'placeholder' => trans('general.search_placeholder')]) !!}
{!! Form::select('status', $status, request('status'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('categories[]', $categories, request('categories'), ['id' => 'filter-categories', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! Form::dateRange('invoice_date', trans('invoices.invoice_date'), 'calendar', []) !!}
{!! Form::select('statuses[]', $statuses, request('statuses'), ['id' => 'filter-statuses', 'class' => 'form-control input-filter input-lg', 'multiple' => 'multiple']) !!}
{!! Form::button('<span class="fa fa-filter"></span> &nbsp;' . trans('general.filter'), ['type' => 'submit', 'class' => 'btn btn-sm btn-default btn-filter']) !!}
</div>
<div class="pull-right">
Expand All @@ -24,22 +26,23 @@
<div class="table table-responsive">
<table class="table table-striped table-hover" id="tbl-invoices">
<thead>
<tr>
<th class="col-md-2">@sortablelink('invoice_number', trans('invoices.invoice_number'))</th>
<th class="col-md-2 text-right">@sortablelink('amount', trans('general.amount'))</th>
<th class="col-md-3 text-right">@sortablelink('invoiced_at', trans('invoices.invoice_date'))</th>
<th class="col-md-3 text-right">@sortablelink('due_at', trans('invoices.due_date'))</th>
<th class="col-md-2 text-center">@sortablelink('status.name', trans_choice('general.statuses', 1))</th>
</tr>
<tr>
<th class="col-md-2">@sortablelink('invoice_number', trans_choice('general.numbers', 1))</th>
<th class="col-md-2 text-right amount-space">@sortablelink('amount', trans('general.amount'))</th>
<th class="col-md-3">@sortablelink('invoiced_at', trans('invoices.invoice_date'))</th>
<th class="col-md-3">@sortablelink('due_at', trans('invoices.due_date'))</th>
<th class="col-md-2">@sortablelink('invoice_status_code', trans_choice('general.statuses', 1))</th>
</tr>
</thead>
<tbody>
@foreach($invoices as $item)
@php $paid = $item->paid; @endphp
<tr>
<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">{{ 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-center"><span class="label {{ $item->status->label }}">{{ trans('invoices.status.' . $item->status->code) }}</span></td>
<td class="text-right amount-space">@money($item->amount, $item->currency_code, true)</td>
<td>{{ Date::parse($item->invoiced_at)->format($date_format) }}</td>
<td>{{ Date::parse($item->due_at)->format($date_format) }}</td>
<td><span class="label {{ $item->status->label }}">{{ trans('invoices.status.' . $item->status->code) }}</span></td>
</tr>
@endforeach
</tbody>
Expand All @@ -54,3 +57,31 @@
</div>
<!-- /.box -->
@endsection

@push('js')
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/daterangepicker/moment.js') }}"></script>
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/daterangepicker/daterangepicker.js') }}"></script>
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/datepicker/bootstrap-datepicker.js') }}"></script>
@if (language()->getShortCode() != 'en')
<script src="{{ asset('vendor/almasaeed2010/adminlte/plugins/datepicker/locales/bootstrap-datepicker.' . language()->getShortCode() . '.js') }}"></script>
@endif
@endpush

@push('css')
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/daterangepicker/daterangepicker.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/almasaeed2010/adminlte/plugins/datepicker/datepicker3.css') }}">
@endpush

@push('scripts')
<script type="text/javascript">
$(document).ready(function(){
$("#filter-categories").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)]) }}"
});
$("#filter-statuses").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.statuses', 1)]) }}"
});
});
</script>
@endpush

0 comments on commit b6da292

Please sign in to comment.