<?php

namespace App\Http\Resources;


use App\Models\ProductSalesOrder;
use Illuminate\Http\Resources\Json\JsonResource;
use DB;
use Auth;

class ProductSalesResources extends JsonResource
{
    public function toArray($request)
    {

        $lang = $request->header('lang', '');

        if($lang == 'ar'){

            $GROUP=$this ->Product()->first()->Group()->first()->Name;

            if(!empty($this ->Product()->first()->Brand()->first()->Name)){
                $BRAND=$this ->Product()->first()->Brand()->first()->Name;
            }else{
                $BRAND='';
            }


        }else{

            $GROUP=$this ->Product()->first()->Group()->first()->NameEn;
            if(!empty($this ->Product()->first()->Brand()->first()->NameEn)){
                $BRAND=$this ->Product()->first()->Brand()->first()->NameEn;
            }else{
                $BRAND='';
            }


        }

        $data = [

            'id'=>$this ->id,
            'product_code'=>$this ->Product_Code,
            'product_ar_name'=>$this ->P_Ar_Name,
            'product_en_name'=>$this ->P_En_Name,
            'virable_one_name'=>$this ->V_Name,
            'virable_two_name'=>$this ->VV_Name,
            'group'=>$GROUP,
            'brand'=>$BRAND,
            'qty'=>$this ->Qty,
            'avalible_qty'=>$this ->AvQty,
            'original_qty'=>$this ->Original_Qty,
            'price'=>$this ->Price,
            'cost_price'=>$this ->CostPrice,
            'discount'=>$this ->Discount,
            'total_discount'=>$this ->TDiscount,
            'tax'=>$this ->Tax,
            'total_bf_taxes'=>$this ->Total_Bf_Tax,
            'total_taxes'=>$this ->Total_Tax,
            'total'=>$this ->Total,
            'store'=>$this ->Store,
            'product'=>$this ->Product,
            'exp_date'=>$this ->Exp_Date,
            'veriable_1'=>$this ->V1,
            'veriable_2'=>$this ->V2,
            'unit_id'=>$this ->Unit,
            'patch_number'=>$this ->Patch_Number,
            'pro_note'=>$this ->Pro_Note,
            'total_wight'=>$this ->Total_Wight,
            'unit_rate'=>$this ->UnitRate,
            'unit_name'=>$this ->Unit()->first()->Name,
            'weight'=>$this ->weight,
            'sales_pro_desc'=>$this ->SalesProDesc,
            'total_cost_new'=>$this ->TotCostNew,
            'small_qty'=>$this ->SmallQty,
            'small_code'=>$this ->SmallCode,
            'total_net'=>$this ->Total_Net,
            'sub_v_id'=>$this ->SubVID,
        ];


        return $data ;
    }

}
