accrued()->where('customer_id', auth()->user()->customer->id)->paginate(); $status = collect(InvoiceStatus::all()->pluck('name', 'code')) ->prepend(trans('general.all_type', ['type' => trans_choice('general.statuses', 2)]), ''); return view('customers.invoices.index', compact('invoices', 'status')); } /** * Show the form for viewing the specified resource. * * @param Invoice $invoice * * @return Response */ 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(); } $paid += $amount; } $invoice->paid = $paid; $accounts = Account::enabled()->pluck('name', 'id'); $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); $account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first(); $customers = Customer::enabled()->pluck('name', 'id'); $categories = Category::enabled()->type('income')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); return view('customers.invoices.show', compact('invoice', 'accounts', 'currencies', 'account_currency_code', 'customers', 'categories', 'payment_methods')); } /** * Show the form for viewing the specified resource. * * @param Invoice $invoice * * @return Response */ public function printInvoice(Invoice $invoice) { $invoice = $this->prepareInvoice($invoice); return view($invoice->template_path, compact('invoice')); } /** * Show the form for viewing the specified resource. * * @param Invoice $invoice * * @return Response */ public function pdfInvoice(Invoice $invoice) { $invoice = $this->prepareInvoice($invoice); $view = view($invoice->template_path, compact('invoice'))->render(); $html = mb_convert_encoding($view, 'HTML-ENTITIES'); $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML($html); //$pdf->setPaper('A4', 'portrait'); $file_name = 'invoice_' . time() . '.pdf'; return $pdf->download($file_name); } protected function prepareInvoice(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(); } $paid += $amount; } $invoice->paid = $paid; $invoice->template_path = 'incomes.invoices.invoice'; event(new InvoicePrinting($invoice)); return $invoice; } public function link(Invoice $invoice, Request $request) { if (empty($invoice)) { redirect()->route('login'); } $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(); } $paid += $amount; } $invoice->paid = $paid; $accounts = Account::enabled()->pluck('name', 'id'); $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); $account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first(); $customers = Customer::enabled()->pluck('name', 'id'); $categories = Category::enabled()->type('income')->pluck('name', 'id'); $payment_methods = Modules::getPaymentMethods(); $payment_actions = []; 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]] = SignedUrl::sign(url('signed/invoices/' . $invoice->id . '/' . $codes[0]), 1); } } $print_action = SignedUrl::sign(route('signed.invoices.print', $invoice->id), 1); $pdf_action = SignedUrl::sign(route('signed.invoices.pdf', $invoice->id), 1); return view('customers.invoices.link', compact('invoice', 'accounts', 'currencies', 'account_currency_code', 'customers', 'categories', 'payment_methods', 'payment_actions', 'print_action', 'pdf_action')); } }