diff --git a/app/Http/Controllers/Customers/Invoices.php b/app/Http/Controllers/Customers/Invoices.php index b1efe7a0a..0e02e9a6e 100644 --- a/app/Http/Controllers/Customers/Invoices.php +++ b/app/Http/Controllers/Customers/Invoices.php @@ -6,7 +6,6 @@ use App\Http\Controllers\Controller; 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; @@ -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')); } /** @@ -50,31 +55,15 @@ class Invoices extends Controller */ public function show(Invoice $invoice) { - $paid = 0; + $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id'); - 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(); - } - - $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(); @@ -106,7 +95,9 @@ class Invoices extends Controller { $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'); diff --git a/resources/views/customers/invoices/index.blade.php b/resources/views/customers/invoices/index.blade.php index a2aa941d3..633bcdcf2 100644 --- a/resources/views/customers/invoices/index.blade.php +++ b/resources/views/customers/invoices/index.blade.php @@ -7,10 +7,12 @@
@sortablelink('invoice_number', trans('invoices.invoice_number')) | -@sortablelink('amount', trans('general.amount')) | -@sortablelink('invoiced_at', trans('invoices.invoice_date')) | -@sortablelink('due_at', trans('invoices.due_date')) | -@sortablelink('status.name', trans_choice('general.statuses', 1)) | -||||
---|---|---|---|---|---|---|---|---|
@sortablelink('invoice_number', trans_choice('general.numbers', 1)) | +@sortablelink('amount', trans('general.amount')) | +@sortablelink('invoiced_at', trans('invoices.invoice_date')) | +@sortablelink('due_at', trans('invoices.due_date')) | +@sortablelink('invoice_status_code', trans_choice('general.statuses', 1)) | +||||
{{ $item->invoice_number }} | -@money($item->amount, $item->currency_code, true) | -{{ Date::parse($item->invoiced_at)->format($date_format) }} | -{{ Date::parse($item->due_at)->format($date_format) }} | -{{ trans('invoices.status.' . $item->status->code) }} | +@money($item->amount, $item->currency_code, true) | +{{ Date::parse($item->invoiced_at)->format($date_format) }} | +{{ Date::parse($item->due_at)->format($date_format) }} | +{{ trans('invoices.status.' . $item->status->code) }} |