<?php

namespace App\Imports;

use App\Models\accounting\AccountCustomer;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class CustomerImport implements ToModel,WithHeadingRow
{
       
    private $admin_id,$type;

    public function __construct($adminId,$type)
    {
        $this->admin_id = $adminId;
        $this->type = $type;
    }

    public function model(array $row)
    {
        //dd($row);
        
        $mainArray = array();       

		$rowArray = array( 
            "admin_id" => $this->admin_id,
            "name" => $row["company_name"],
            "email" => $row["email"],
            "mobile" => $row["mobile"],
            "billing_address" => $row["billing_address"],
            "billing_city" => $row["billing_city"],
            "billing_state" => $row["billing_state"],
            "billing_country" => $row["billing_country"],
            "billing_zip" => $row["billing_zip"],
            "shipping_address" => $row["shipping_address"],
            "shipping_city" => $row["shipping_city"],
            "shipping_state" => $row["shipping_state"], 
            "shipping_zip" => $row["shipping_zip"],
            "gstin" => $row["gstin"],
            "gst_treatment" => $row["gst_treatment"], 
            "pan" => $row["pan"],
            "note" => $row["note"],
            "opening_balance" => $row["opening_balance"],  
            "status"=> "active",
            "type"=> $this->type,              
            'created_at' => date('Y-m-d H:i:s')
        );  
                   
		array_push($mainArray,$rowArray);

        //dd($mainArray);
        foreach($mainArray as $user)
        { 
            $res = AccountCustomer::create($user);        

        }
    }
    
}
