64 lines
2.5 KiB
PHP
64 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use Illuminate\Contracts\View\View;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class InvoicesExport implements FromView
|
||
|
|
{
|
||
|
|
protected $request;
|
||
|
|
|
||
|
|
public function __construct(Request $request)
|
||
|
|
{
|
||
|
|
$this->request = $request;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function view(): View
|
||
|
|
{
|
||
|
|
$request = $this->request;
|
||
|
|
|
||
|
|
$invoices = DB::table('invoices')
|
||
|
|
->leftJoin('containers', 'containers.id', '=', 'invoices.container_id')
|
||
|
|
->leftJoin('mark_list', 'mark_list.mark_no', '=', 'invoices.mark_no')
|
||
|
|
->select(
|
||
|
|
'invoices.invoice_number',
|
||
|
|
'invoices.invoice_date',
|
||
|
|
'invoices.mark_no',
|
||
|
|
'containers.container_number',
|
||
|
|
'containers.container_date',
|
||
|
|
DB::raw('COALESCE(invoices.company_name, mark_list.company_name) as company_name'),
|
||
|
|
DB::raw('COALESCE(invoices.customer_name, mark_list.customer_name) as customer_name'),
|
||
|
|
'invoices.final_amount',
|
||
|
|
'invoices.final_amount_with_gst',
|
||
|
|
'invoices.status as invoice_status'
|
||
|
|
)
|
||
|
|
->when($request->filled('search'), function ($q) use ($request) {
|
||
|
|
$search = trim($request->search);
|
||
|
|
$q->where(function ($qq) use ($search) {
|
||
|
|
$qq->where('invoices.invoice_number', 'like', "%{$search}%")
|
||
|
|
->orWhere('invoices.mark_no', 'like', "%{$search}%")
|
||
|
|
->orWhere('containers.container_number', 'like', "%{$search}%")
|
||
|
|
->orWhere('mark_list.company_name', 'like', "%{$search}%")
|
||
|
|
->orWhere('mark_list.customer_name', 'like', "%{$search}%");
|
||
|
|
});
|
||
|
|
})
|
||
|
|
->when($request->filled('status'), function ($q) use ($request) {
|
||
|
|
$q->where('invoices.status', $request->status);
|
||
|
|
})
|
||
|
|
->when($request->filled('from_date'), function ($q) use ($request) {
|
||
|
|
$q->whereDate('invoices.invoice_date', '>=', $request->from_date);
|
||
|
|
})
|
||
|
|
->when($request->filled('to_date'), function ($q) use ($request) {
|
||
|
|
$q->whereDate('invoices.invoice_date', '<=', $request->to_date);
|
||
|
|
})
|
||
|
|
->orderByDesc('containers.container_date')
|
||
|
|
->orderByDesc('invoices.id')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
return view('admin.pdf.invoices_excel', compact('invoices'));
|
||
|
|
}
|
||
|
|
}
|