<?php

namespace App\Http\Controllers\Project;
use App\Http\Controllers\Controller;
use App\Models\Project\Expense_type;
use App\Models\Project\Invoice_main;
use PDF;

class CommonController extends Controller
{
    // generating pdf
    public function invoiceDetailPDF($inv_id, $lang) {
        $data['post'] = Invoice_main::where('id',$inv_id)->with('invoice_details','products','customer','vendor')->first();
        $data['language'] = $lang;

        $data['expense_type'] = "";
        if ($data['post']->expense_type) {
            if ($lang == 'en') {
                $data['expense_type'] = Expense_type::where('id', $data['post']->expense_type)->first()->expense_name;
            } else {
                $data['expense_type'] = Expense_type::where('id', $data['post']->expense_type)->first()->expense_name_ar;
            }
        }
        //ddd($data);
        //ddd($data['post']->invoice_type);
        view()->share('data',$data);
        if ($data['post']->invoice_type == 2) {
            $pdf = PDF::loadView('project.orders.simple_inv_detail_pdf', $data);
        } else {
            $pdf = PDF::loadView('project.orders.invoice_detail_pdf', $data);
        }
        return $pdf->download('Invoice.pdf');
    }
}