<?php

namespace App\Exports;

use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
use Illuminate\Support\Facades\Session;
use App\Models\{
	User
};
use App\Models\accounting\AccountItem;

class ItemExport implements FromCollection, WithHeadings
{
	/**
	 * @return \Illuminate\Support\Collection
	 */
    private $admin_id;

    public function __construct($admin_id,)
    {
        $this->admin_id = $admin_id;
        
    }
    
	public function collection()
	{
        
        //return $admin_id;
		$query = AccountItem::where("account_items.admin_id","=",$this->admin_id)
        ->leftJoin("account_item_units","account_item_units.id","=","account_items.unit_id")
        ->leftJoin("account_item_categories","account_item_categories.id","=","account_items.category_id");
        
		
		$customer =  $query->select(  
                "account_items.name",
                "account_items.item_code",
                "account_items.description",
                "account_item_units.name as unit_name",
                "account_item_categories.name as category_name",
                "account_items.tax",
                "account_items.sales_unit_price",
                "account_items.sales_currency",
                "account_items.sales_cess_percentage",
                "account_items.sales_cess_plus",
                "account_items.purchase_unit_price",
                "account_items.purchase_currency",
                "account_items.purchase_cess_percentage",
                "account_items.purchase_cess_plus",
                "account_items.quantity",
                "account_items.remaining",
                "account_items.type"

            )->orderBy('account_items.created_at', 'DESC')->get();

           
            return $customer;
        
	}

	public function headings(): array
	{
		return [
            "Name",
            "Item Code",
            "Description",
            "Unit Name",
            "Category Name",
            "Tax",
            "Sales Unit Price",
            "Sales Currency",
            "Sales Cess Percentage",
            "Sales Cess Plus",
            "Purchase Unit Price",
            "Purchase Currency",
            "Purchase Cess Percentage",
            "Purchase Cess Plus",
            "Quantity",
            "Remaining",
            "Type"
        ];
	}
}
