@extends('admin.index')
@section('content')

    <title>{{$title}}</title>

    <main id="js-page-content" role="main" class="page-content">
        <ol class="breadcrumb page-breadcrumb">
            <li class="breadcrumb-item"><a href="javascript:void(0);">{{trans('admin.Purchases')}} </a></li>
            <li class="breadcrumb-item active">{{$title}} </li>
            <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
        </ol>

        <form id="form" action="{{$urll}}" method="post" enctype="multipart/form-data">
            {!! csrf_field() !!}
            @honeypot

            <input type="hidden" name="ID" value="{{$item->id}}">

            @if($Place == 'Shortcomings')
                <input type="hidden" name="TYPE" value="Short">
            @else


                <input type="hidden" name="TYPE" value="Order">
            @endif



            <div class="row">
                <div class="col-lg-12">
                    <div id="panel-2" class="panel">
                        <div class="panel-hdr">
                            <h2>
                                <span class="fw-300"><i> {{$title}} </i></span>
                            </h2>
                        </div>
                        <div class="panel-container show">
                            <span id="ex"> @include('admin.layouts.messages')</span>
                            <div class="panel-content">
                                <div class="form-row">
                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="simpleinput">{{trans('admin.Code')}} </label>
                                        <input type="text" value="{{$item->Code}}" name="Old_Code" class="form-control " readonly>
                                        <input type="hidden" name="Code" value="{{$Code}}" class="form-control">
                                    </div>
                                    @if(auth()->guard('admin')->user()->emp == 0)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                                            <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required>
                                        </div>
                                    @else

                                        @if(auth()->guard('admin')->user()->Date == 1)
                                            <div class="form-group col-lg-2">
                                                <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                                                <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required>
                                            </div>
                                        @else
                                            <div class="form-group col-lg-2">
                                                <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                                                <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required readonly>
                                            </div>
                                        @endif

                                    @endif

                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="">{{trans('admin.Store')}}</label>
                                        <select class="select2 form-control w-100" id="store"  disabled>

                                            @foreach($Stores as $stor)
                                                <option value="{{$stor->id}}" @if($item->Store == $stor->id) selected @endif>
                                                    {{app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn}}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <input type="hidden"  name="Store"  value="{{$item->Store}}">
                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="">{{trans('admin.Safe')}}</label>
                                        <select class="select2 form-control w-100" name="Safe" required>

                                            @foreach($Safes as $safe)
                                                <option value="{{$safe->id}}" @if($item->Safe == $safe->id) selected @endif>
                                                    {{app()->getLocale() == 'ar' ?$safe->Name :$safe->NameEn}}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>

                                    @if($show->Coin == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Coin')}}</label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                <option value=""> {{trans('admin.Coin')}}</option>
                                                @foreach($Coins as $coin)
                                                    <option value="{{$coin->id}}" @if($item->Coin == $coin->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="">{{trans('admin.Coin')}}</label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                <option value=""> {{trans('admin.Coin')}}</option>
                                                @foreach($Coins as $coin)
                                                    <option value="{{$coin->id}}" @if($item->Coin == $coin->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @endif

                                    @if($show->Draw == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Draw')}}</label>
                                            <input type="text" name="Draw" value="{{$item->Draw}}" class="form-control" required>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Draw')}}</label>
                                            <input type="text" name="Draw" value="{{$item->Draw}}" class="form-control" required>
                                        </div>
                                    @endif


                                    @if(auth()->guard('admin')->user()->emp != 0)



                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> {{trans('admin.Payment_Method')}}</label>
                                            <select class="select2 form-control w-100" name="Payment_Method" id="Payment_Method" onchange="Statuss()" required>
                                                @if(auth()->guard('admin')->user()->Cash == 1)
                                                    <option value="Cash" @if($item->Payment_Method == 'Cash') selected @endif>{{trans('admin.Cash')}} </option>
                                                @endif
                                                @if(auth()->guard('admin')->user()->Later == 1)
                                                    <option value="Later" @if($item->Payment_Method == 'Later') selected @endif>{{trans('admin.Later')}}</option>
                                                @endif
                                                @if(auth()->guard('admin')->user()->Check == 1)
                                                    <option value="Check" @if($item->Payment_Method == 'Check') selected @endif>{{trans('admin.Check')}}</option>
                                                @endif
                                            </select>
                                        </div>

                                    @else
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> {{trans('admin.Payment_Method')}}</label>
                                            <select class="select2 form-control w-100" name="Payment_Method" id="Payment_Method" onchange="Statuss()" required>
                                                <option value="Cash" @if($item->Payment_Method == 'Cash') selected @endif>{{trans('admin.Cash')}} </option>
                                                <option value="Later" @if($item->Payment_Method == 'Later') selected @endif>{{trans('admin.Later')}}</option>
                                                <option value="Check" @if($item->Payment_Method == 'Check') selected @endif>{{trans('admin.Check')}}</option>
                                            </select>
                                        </div>

                                    @endif

                                    <div class="form-group col-lg-2" id="LaterDate">
                                        <label class="form-label" for="simpleinput">{{trans('admin.Later_Due')}}</label>
                                        <input type="date" name="Later_Due" value="{{$item->Later_Due}}" class="form-control">
                                    </div>

                                    @if($show->Status == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Status')}}</label>
                                            <select class="select2 form-control w-100" name="Status" onchange="Statuss()" id="Status" required>
                                                <option value="1" @if($item->Status == 1) selected @endif>{{trans('admin.Recived')}} </option>
                                                <option value="0" @if($item->Status == 0) selected @endif>{{trans('admin.Pending')}}</option>
                                            </select>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="">{{trans('admin.Status')}}</label>
                                            <select class="select2 form-control w-100" name="Status" onchange="Statuss()" id="Status" required>
                                                <option value="1" @if($item->Status == 1) selected @endif>{{trans('admin.Recived')}} </option>
                                                <option value="0" @if($item->Status == 0) selected @endif>{{trans('admin.Pending')}}</option>
                                            </select>
                                        </div>
                                    @endif

                                    @if($show->Cost_Center == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> {{trans('admin.Cost_Center')}} </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                                <option value=""> {{trans('admin.Cost_Center')}}</option>
                                                @foreach($CostCenters as $cost)
                                                    <option value="{{$cost->id}}" @if($item->Cost_Center == $cost->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for=""> {{trans('admin.Cost_Center')}} </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                                <option value=""> {{trans('admin.Cost_Center')}}</option>
                                                @foreach($CostCenters as $cost)
                                                    <option value="{{$cost->id}}" @if($item->Cost_Center == $cost->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @endif

                                    @if($show->Delegate_Purchase == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Delegate')}}</label>
                                            <select class="select2 form-control w-100" name="Delegate">
                                                <option value=""> {{trans('admin.Delegate')}}</option>
                                                @foreach($Employess as $emp)
                                                    <option value="{{$emp->id}}" @if($item->Delegate == $emp->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="">{{trans('admin.Delegate')}}</label>
                                            <select class="select2 form-control w-100" name="Delegate">
                                                <option value=""> {{trans('admin.Delegate')}}</option>
                                                @foreach($Employess as $emp)
                                                    <option value="{{$emp->id}}" @if($item->Delegate == $emp->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @endif

                                    @if($show->Vendor_Date == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Vendor_Bill_Date')}}</label>
                                            <input type="date" name="Vendor_Bill_Date" value="{{$item->Vendor_Bill_Date}}" class="form-control">
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Vendor_Bill_Date')}}</label>
                                            <input type="date" name="Vendor_Bill_Date" value="{{$item->Vendor_Bill_Date}}" class="form-control">
                                        </div>
                                    @endif


                                    @if($show->Refrence_Number == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Refrence_Number')}}</label>
                                            <input type="text" name="Refernce_Number" value="{{$item->Refernce_Number}}" class="form-control">
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Refrence_Number')}}</label>
                                            <input type="text" name="Refernce_Number" value="{{$item->Refernce_Number}}" class="form-control">
                                        </div>
                                    @endif


                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="">{{trans('admin.Account')}} ({{trans('admin.Vendor')}})</label>
                                        <select class="select2 form-control w-100" id="vendor" name="Vendor" required>
                                            <option value="{{$item->Vendor()->first()->id}}">

                                                {{app()->getLocale() == 'ar' ?$item->Vendor()->first()->Name :$item->Vendor()->first()->NameEn}}
                                            </option>
                                        </select>
                                    </div>


                                    @can('خانه رصيد حساب مورد') @php $credStyle="block"; @endphp @endcan

                                    <div class="form-group col-lg-2" style="display: {{$credStyle}}">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Account_Credit')}} </label>
                                        <input type="hidden" id="AccountCredit" name="Current_Credit"  value="0" class="form-control " readonly>

                                    </div>




                                @if($show->Shipping_Company == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Shipping_Compaines')}}</label>
                                            <select class="select2 form-control w-100" name="Ship">
                                                <option value=""> {{trans('admin.Shipping_Compaines')}}</option>
                                                @foreach($Shippings as $ship)
                                                    <option value="{{$ship->id}}" @if($item->Ship == $ship->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$ship->Name :$ship->NameEn}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="">{{trans('admin.Shipping_Compaines')}}</label>
                                            <select class="select2 form-control w-100" name="Ship">
                                                <option value=""> {{trans('admin.Shipping_Compaines')}}</option>
                                                @foreach($Shippings as $ship)
                                                    <option value="{{$ship->id}}" @if($item->Ship == $ship->id) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$ship->Name :$ship->NameEn}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>

                                    @endif


                                    <div class="form-group col-lg-2">
                                        <label class="form-label" for="simpleinput">{{trans('admin.Purchases')}}  ({{trans('admin.Code')}})  </label>
                                        <input type="text"  value="{{$Code}}" class="form-control" disabled>
                                        <input type="hidden" name="P_Order_Num" value="{{$item->Code}}" class="form-control" >
                                    </div>

                                    @if($show->Note == 1)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Notes')}} </label>
                                            <input type="text" name="Note" value="{{$item->Note}}" class="form-control">
                                        </div>
                                    @else
                                        <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Notes')}} </label>
                                            <input type="text" name="Note" value="{{$item->Note}}" class="form-control">
                                        </div>
                                    @endif


                                    <input type="hidden" name="Files" value="{{$item->File}}">
                                    @if($show->Show_File_Purchases == 1)
                                        <div class="form-group col-lg-12">
                                            <label class="form-label" for="simpleinput">{{trans('admin.File')}}</label>
                                            <input type="file" name="File" class="form-control">
                                        </div>
                                    @endif

                                </div>

                                <div id="CHECK" style="display: none">
                                    <div class="row">
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="">{{trans('admin.Check_Type')}}</label>
                                            <select class="select2 form-control w-100" name="Check_Type" id="Check_Type">
                                                <option value=""> {{trans('admin.Check_Type')}}</option>
                                                @foreach($ChecksTypes as $type)
                                                    <option value="{{$type->id}}" @if($type->id == $item->Check_Type) selected @endif>
                                                        {{app()->getLocale() == 'ar' ?$type->Arabic_Name :$type->English_Name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>


                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Due_Date')}} </label>
                                            <input type="date" value="{{$item->Due_Date}}" class="form-control" name="Due_Date" id="Due_Date">
                                        </div>


                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Check_Number')}} </label>
                                            <input type="number" step="any" value="{{$item->Check_Number}}" class="form-control" name="Check_Number" id="Check_Number">
                                        </div>
                                    </div>

                                </div>
                            </div>

                            <div class="form-row">

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xl-12">
                    <div id="panel-1" class="panel">

                        <div class="panel-container show">
                            <div class="panel-content">


                                <!-- datatable start -->
                                <div id="mobile-overflow">
                                    <table id="dt" class="table table-bordered table-hover table-striped w-100 mobile-width table-color2">
                                        <thead>
                                        <tr>
                                            <th>{{trans('admin.Name')}}</th>
                                            @if($show->Show_Unit == 1)
                                                <th>{{trans('admin.Unit')}}</th>
                                            @endif

                                            @if($show->Show_Barcode == 1)
                                                <th>{{trans('admin.Code')}}</th>
                                            @endif


                                        @if($Place == 'Shortcomings')
                                                <th>{{trans('admin.AvQty')}}</th>
                                            @endif
                                            <th>{{trans('admin.Qty')}}</th>
                                            <th>{{trans('admin.Price')}}</th>
                                            @if($show->Disc == 1)
                                                <th>{{trans('admin.Discount')}}</th>
                                            @endif
                                            @if($show->TotalBfTax == 1)
                                                <th>{{trans('admin.Total_Bf_Taxes')}}</th>
                                            @endif
                                            @if($show->Tax == 1)
                                                <th>{{trans('admin.Tax')}}</th>
                                            @endif
                                            @if($show->Show_Total == 1)
                                                <th>{{trans('admin.Total')}}</th>
                                            @endif

                                            @if($show->Show_Net == 1)
                                                <th>{{trans('admin.The_Net')}}</th>
                                            @endif


                                        @if($show->Store == 1)
                                                <th>{{trans('admin.Store')}}</th>
                                            @endif
                                            @if($show->Expire_Date == 1)
                                                <th>{{trans('admin.Exp_Date')}}</th>
                                            @endif
                                            <th>{{trans('admin.Actions')}}</th>
                                        </tr>
                                        </thead>
                                        <tbody id="data-dt">

                                        @if($show->Disc == 1)
                                            @php $disshow=''; @endphp
                                        @else
                                            @php $disshow='none'; @endphp
                                        @endif


                                        @if($show->TotalBfTax == 1)
                                            @php $totbfhow=''; @endphp
                                        @else
                                            @php $totbfhow='none'; @endphp
                                        @endif


                                        @if($show->Tax == 1)
                                            @php $taxshow=''; @endphp
                                        @else
                                            @php $taxshow='none'; @endphp
                                        @endif


                                        @if($show->Store == 1)
                                            @php $storeshow=''; @endphp
                                        @else
                                            @php $storeshow='none'; @endphp
                                        @endif


                                        @if($Place == 'RecivedPurchases')


                                            @foreach($details as $pro)
                                                <tr>
                                                    <td>

                                                        {{app()->getLocale() == 'ar' ?$pro->Product()->first()->P_Ar_Name :$pro->Product()->first()->P_En_Name}}
                                                        <input type='hidden' name='P_Ar_Name[]' value='{{$pro->Product()->first()->P_Ar_Name}}'>
                                                        <input type='hidden' name='P_En_Name[]' value='{{$pro->Product()->first()->P_En_Name}}'>

                                                        @if(!empty($pro->V1))
                                                            ( {{app()->getLocale() == 'ar' ?$pro->V1()->first()->Name :$pro->V1()->first()->NameEn}} )

                                                            <input type='hidden' name='VOne[]' value='{{$pro->V1}}'>
                                                            <input type='hidden' name='V_Name[]' value='{{$pro->V_Name}}'>

                                                        @else
                                                            <input type='hidden' name='VOne[]' value=''>
                                                            <input type='hidden' name='V_Name[]' value=''>
                                                        @endif

                                                        @if(!empty($pro->V2))
                                                            ( {{app()->getLocale() == 'ar' ?$pro->V2()->first()->Name :$pro->V2()->first()->NameEn}} )
                                                            <input type='hidden' name='VTwo[]' value='{{$pro->V2}}'>
                                                            <input type='hidden' name='VV_Name[]' value='{{$pro->VV_Name}}'>
                                                        @else
                                                            <input type='hidden' name='VTwo[]' value=''>
                                                            <input type='hidden' name='VV_Name[]' value=''>
                                                        @endif

                                                    </td>

                                                    @if($show->Show_Unit == 1)

                                                        <td><input type='hidden' name='Unit[]' value='{{$pro->Unit}}'>{{app()->getLocale() == 'ar' ?$pro->Unit()->first()->Name :$pro->Unit()->first()->NameEn}}</td>

                                                    @else
                                                        <input type='hidden' name='Unit[]' value='{{$pro->Unit}}'>
                                                    @endif

                                                    @if($show->Show_Barcode == 1)
                                                        <td><input type='hidden' name='P_Code[]' value='{{$pro->Product_Code}}'>

                                                            {{$pro->Product_Code}}
                                                        </td>
                                                    @else
                                                        <input type='hidden' name='P_Code[]' value='{{$pro->Product_Code}}'>

                                                    @endif


                                                    <td><input class='Qun' id="QuntD{{$pro->id}}" type='hidden' name='Qty[]' value='{{$pro->Qty}}'>{{$pro->Qty}}</td>
                                                    <td>
                                                        <input type='text' class="form-control" onclick="TotD({{$pro->id}})" onkeyup="TotD({{$pro->id}})" id="PriD{{$pro->id}}" name='Price[]' value='{{$pro->Price}}'>
                                                        <input type='hidden' name='Price_Sale[]' value='{{$pro->Price_Sale}}'>
                                                    </td>
                                                    <td style="display: {{$disshow}}"><input class='Disc' id="DiscD{{$pro->id}}" type='hidden' name='Discount[]' value='{{$pro->Discount}}'>
                                                        <input type='hidden' class='TDISCOOO'  id="TDiscProEdit{{$pro->id}}"  name='TDiscPro[]' value='{{$pro->TDiscount}}'>{{$pro->Discount}}

                                                    </td>
                                                    <td style="display: {{$totbfhow}}"><input class='TotalBFTax form-control' type='text' name='TotalBFTax[]' id="TotBFTaxD{{$pro->id}}" value='{{$pro->Total_Bf_Tax}}' readonly></td>
                                                    <td style="display: {{$taxshow}}"><input class='TotalTax form-control' type='text' name='TotalTax[]' id="TaxD{{$pro->id}}" value='{{$pro->Total_Tax}}' readonly></td>

                                                    @if($show->Show_Total == 1)
                                                        <td><input class='Tot form-control' id="TotD{{$pro->id}}" type='text' name='Total[]' value='{{$pro->Total}}' readonly></td>
                                                    @else
                                                        <input class='Tot form-control' id="TotD{{$pro->id}}" type='hidden' name='Total[]' value='{{$pro->Total}}'>
                                                    @endif

                                                    @if($show->Show_Net == 1)
                                                        <td><input type='text' class="form-control" id="NetD{{$pro->id}}" name='Total_Net[]' value='{{$pro->Total_Net}}' readonly ></td>
                                                    @else
                                                        <input type='hidden' name='Total_Net[]' id="NetD{{$pro->id}}" value='{{$pro->Total_Net}}'>
                                                    @endif

                                                    <td style="display: {{$storeshow}}"><input type='hidden' name='StorePurch[]' value='{{$pro->Store}}'> {{app()->getLocale() == 'ar' ?$pro->Store()->first()->Name :$pro->Store()->first()->NameEn}} </td>

                                                    @if($show->Expire_Date == 1)

                                                        <td>
                                                            <input type='date' name='Exp_Date[]' class="form-control" value='{{$pro->Exp_Date}}'>
                                                        </td>

                                                    @else

                                                        <input type='hidden' name='Exp_Date[]' value='{{$pro->Exp_Date}}'>
                                                    @endif
                                                    <td>

                                                        <input type='hidden' name='Product[]' value='{{$pro->Product}}'>

                                                        <input type='hidden' name='PurchTax[]' value='{{$pro->Tax}}'>
                                                        <input type='hidden' id='TaxRateD{{$pro->id}}' value='{{$pro->Tax()->first()->Rate}}'>
                                                        <input type='hidden' id='TaxTypeD{{$pro->id}}' value='{{$pro->Tax()->first()->Type}}'>

                                                        <input type='hidden' id='TotBFTaxDHide{{$pro->id}}' value='{{$pro->Total_Bf_Tax}}' >
                                                        <input type='hidden' id='TaxDHide{{$pro->id}}' value='{{$pro->Total_Tax}}' >
                                                        <input type='hidden' id='TotDHide{{$pro->id}}' value='{{$pro->Total}}' >
                                                    </td>
                                                </tr>
                                            @endforeach


                                        @else

                                        @foreach($details as $pro)
                                            <tr>
                                                <td>

                                                    {{app()->getLocale() == 'ar' ?$pro->Product()->first()->P_Ar_Name :$pro->Product()->first()->P_En_Name}}
                                                    <input type='hidden' name='P_Ar_Name[]' value='{{$pro->Product()->first()->P_Ar_Name}}'>
                                                    <input type='hidden' name='P_En_Name[]' value='{{$pro->Product()->first()->P_En_Name}}'>

                                                    @if(!empty($pro->V1))
                                                        ( {{app()->getLocale() == 'ar' ?$pro->V1()->first()->Name :$pro->V1()->first()->NameEn}} )

                                                        <input type='hidden' name='VOne[]' value='{{$pro->V1}}'>
                                                        <input type='hidden' name='V_Name[]' value='{{$pro->V_Name}}'>

                                                    @else
                                                        <input type='hidden' name='VOne[]' value=''>
                                                        <input type='hidden' name='V_Name[]' value=''>
                                                    @endif

                                                    @if(!empty($pro->V2))
                                                        ( {{app()->getLocale() == 'ar' ?$pro->V2()->first()->Name :$pro->V2()->first()->NameEn}} )
                                                        <input type='hidden' name='VTwo[]' value='{{$pro->V2}}'>
                                                        <input type='hidden' name='VV_Name[]' value='{{$pro->VV_Name}}'>
                                                    @else
                                                        <input type='hidden' name='VTwo[]' value=''>
                                                        <input type='hidden' name='VV_Name[]' value=''>
                                                    @endif

                                                </td>

                                                @if($show->Show_Unit == 1)

                                                    <td><input type='hidden' name='Unit[]' value='{{$pro->Unit}}'>{{app()->getLocale() == 'ar' ?$pro->Unit()->first()->Name :$pro->Unit()->first()->NameEn}}</td>

                                                @else
                                                    <input type='hidden' name='Unit[]' value='{{$pro->Unit}}'>
                                                @endif

                                                @if($show->Show_Barcode == 1)
                                                    <td><input type='hidden' name='P_Code[]' value='{{$pro->Product_Code}}'>

                                                        {{$pro->Product_Code}}
                                                    </td>
                                                @else
                                                    <input type='hidden' name='P_Code[]' value='{{$pro->Product_Code}}'>

                                                @endif




                                            @if($Place == 'Shortcomings')
                                                    <td><input  type='hidden' name='AvQty[]' value='{{$pro->Av_Qty}}'>{{$pro->Av_Qty}}</td>
                                                @endif

                                                <td><input class='Qun' type='hidden' name='Qty[]' value='{{$pro->Qty}}'>{{$pro->Qty}}</td>
                                                <td>
                                                    <input type='hidden' name='Price[]' value='{{$pro->Price}}'>
                                                    <input type='hidden' name='Price_Sale[]' value='{{$pro->Price_Sale}}'>

                                                    {{$pro->Price}}

                                                </td>
                                                <td style="display: {{$disshow}}"><input class='Disc' type='hidden' name='Discount[]' value='{{$pro->Discount}}'><input type='hidden' class='TDISCOOO' name='TDiscPro[]' value='{{$pro->TDiscount}}'>{{$pro->Discount}}</td>
                                                <td style="display: {{$totbfhow}}"><input class='TotalBFTax' type='hidden' name='TotalBFTax[]' value='{{$pro->Total_Bf_Tax}}'>{{$pro->Total_Bf_Tax}}</td>
                                                <td style="display: {{$taxshow}}"><input class='TotalTax' type='hidden' name='TotalTax[]' value='{{$pro->Total_Tax}}'>{{$pro->Total_Tax}}</td>

                                                @if($show->Show_Total == 1)
                                                    <td><input class='Tot' type='hidden' name='Total[]' value='{{$pro->Total}}'>{{$pro->Total}}</td>
                                                @else
                                                    <input class='Tot' type='hidden' name='Total[]' value='{{$pro->Total}}'>
                                                @endif

                                                @if($show->Show_Net == 1)
                                                    <td><input type='hidden' name='Total_Net[]' value='{{$pro->Total_Net}}'>{{$pro->Total_Net}}</td>
                                                @else
                                                    <input type='hidden' name='Total_Net[]' value='{{$pro->Total_Net}}'>
                                                @endif

                                                <td style="display: {{$storeshow}}"><input type='hidden' name='StorePurch[]' value='{{$pro->Store}}'> {{app()->getLocale() == 'ar' ?$pro->Store()->first()->Name :$pro->Store()->first()->NameEn}} </td>

                                                @if($show->Expire_Date == 1)

                                                    <td>
                                                        <input type='date' name='Exp_Date[]' class="form-control" value='{{$pro->Exp_Date}}'>
                                                    </td>

                                                @else

                                                    <input type='hidden' name='Exp_Date[]' value='{{$pro->Exp_Date}}'>
                                                @endif
                                                <td>

                                                    <input type='hidden' name='Product[]' value='{{$pro->Product}}'>

                                                    <input type='hidden' name='PurchTax[]' value='{{$pro->Tax}}'>
                                                </td>
                                            </tr>
                                        @endforeach

                                        @endif

                                        </tbody>
                                    </table>

                                    <div class="DataDD"></div>
                                </div>
                                <!-- datatable end -->
                                <div class="form-row">
                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Product_Numbers')}} </label>
                                        <input type="text" id="Product_Numbers" disabled class="form-control">
                                        <input type="hidden" id="Product_NumbersHide" name="Product_Numbers">
                                    </div>
                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Qty')}} </label>
                                        <input type="text" id="Total_Qty" disabled class="form-control">
                                        <input type="hidden" id="Total_QtyHide" name="Total_Qty">
                                        <input type="hidden" id="Total_Discount" disabled class="form-control">
                                        <input type="hidden" id="Total_DiscountHide" name="Total_Discount">
                                        <input type="hidden" id="Total_Bf_Taxes" disabled class="form-control">
                                        <input type="hidden" id="Total_Bf_TaxesHide" name="Total_BF_Taxes">
                                    </div>
                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Price')}}</label>
                                        <input type="text" id="Total_Price" disabled class="form-control">
                                        <input type="hidden" id="Total_PriceHide" name="Total_Price">
                                    </div>

                                    <div class="form-group col-lg-3">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Discount')}} </label>
                                        <input type="text" id="Total_DiscountTT" disabled class="form-control">
                                        <input type="hidden" id="Total_DiscountHideTT" name="Total_Discount">
                                    </div>




                                    <div class="form-group col-lg-3">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_af_Discount')}} </label>
                                        <input type="text" class="form-control" id="TAFterD" disabled>

                                    </div>

                                    <div class="form-group col-lg-3">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Taxes')}}</label>
                                        <input type="text" id="Total_Taxes" disabled class="form-control">
                                        <input type="hidden" id="Total_TaxesHide" name="Total_Taxes">
                                    </div>


                                    <div class="form-group col-lg-3">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Bill')}} </label>

                                        <input type="text" id="Total_Bill" disabled class="form-control">
                                    </div>



                                    @if(auth()->guard('admin')->user()->emp == 0)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"> {{trans('admin.Discount_Bill')}} </label>
                                            <input type="text" class="form-control" id="resdiual" name="DiscountBill" value="{{$item->DiscountBill}}" onkeyup="Statuss()">
                                        </div>
                                    @else

                                        <div class="form-group col-lg-2" @if(auth()->guard('admin')->user()->bill_discount == 0) style="display: none" @endif >
                                            <label class="form-label" for="simpleinput"> {{trans('admin.Discount_Bill')}} </label>
                                            <input type="text" class="form-control" id="resdiual" name="DiscountBill" value="{{$item->DiscountBill}}" onkeyup="Statuss()">
                                        </div>

                                    @endif



                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Total_Net')}} </label>

                                        <input type="text" id="Total_PriceW" disabled class="form-control">
                                    </div>


                                    <div class="form-group col-lg-4">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Paid')}} </label>
                                        <input type="text" name="Pay" id="paid" onchange="PaidCheck()" onkeyup="PaidCheck()" class="form-control">

                                    </div>

                                </div>
                                <div class="buttons mt-3" id="Submit" style="display: none">
                                    <input type="hidden" id="sp" name="SP">
                                    <button type="button" class="btn btn-primary" onclick="SPS()"> <i class="fal fa-folder"></i> {{trans('admin.SaveChanges')}} </button>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>



            </div>

        </form>
        @if($Def->Discount == 0)
            <input type="hidden" id="DIS" value="0"> <!-- Number -->
        @else
            <input type="hidden" id="DIS" value="1"> <!-- Precent -->
        @endif
        <input type="hidden" id="ED" value="{{$show->Expire_Date}}">
        <input type="hidden" id="DISCSHOW" value="{{$show->Disc}}">
        <input type="hidden" id="TOTBFSHOW" value="{{$show->TotalBfTax}}">
        <input type="hidden" id="TAXSHOW" value="{{$show->Tax}}">
        <input type="hidden" id="STORESHOW" value="{{$show->Store}}">
        <input type="hidden" id="ALLOFDISC" value="{{$item->Total_Discount}}">
        <input type="hidden" id="Show_Unit" value="{{$show->Show_Unit}}">
        <input type="hidden" id="Show_Barcode" value="{{$show->Show_Barcode}}">
        <input type="hidden" id="Show_Total" value="{{$show->Show_Total}}">
        <input type="hidden" id="Show_Net" value="{{$show->Show_Net}}">

        <!--         Recipt Voucher modal -->
        <div class="modal fade" id="Recipt" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">
                            {{trans('admin.Receipt_Voucher')}}
                        </h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true"><i class="fal fa-times"></i></span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-3">
                                <label>{{trans('admin.Creditor')}}</label>
                                <input type="number" step="any" class="form-control" id="Creditor">
                            </div>
                            <div class="col-md-3">
                                <label>{{trans('admin.Account')}}</label>
                                <select class="select2 form-control w-100" id="AccountCodeF">
                                </select>
                            </div>
                            <div class="form-group col-lg-3">
                                <label class="form-label" for="">{{trans('admin.Store')}}</label>
                                <select class="select2 form-control w-100" id="STOREF">
                                    @foreach($Stores as $stor)
                                        <option value="{{$stor->id}}" @if($Def->Store == $stor->id) selected @endif>
                                            {{app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn}}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="form-group col-lg-3">
                                <label class="form-label" for="">{{trans('admin.Safe')}}</label>
                                <select class="select2 form-control w-100" id="SafeF">
                                    @foreach($Safes as $safe)
                                        <option value="{{$safe->id}}" @if($Def->Safe == $safe->id) selected @endif>
                                            {{app()->getLocale() == 'ar' ?$safe->Name :$safe->NameEn}}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <input type="hidden" id="CoinF" value="{{$Def->Coin}}">
                            <input type="hidden" id="DrawF" value="{{$Def->Draw}}">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal"> {{trans('admin.Close')}}</button>
                        <button type="button" class="btn btn-secondary" id="ReciptVoucher"> {{trans('admin.Save')}}</button>
                    </div>
                </div>
            </div>
        </div>
        <!--         Payment Voucher modal -->
        <div class="modal fade" id="PayVouch" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">
                            {{trans('admin.Payment_Voucher')}}
                        </h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true"><i class="fal fa-times"></i></span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-3">
                                <label>{{trans('admin.Debitor')}}</label>
                                <input type="number" step="any" class="form-control" id="Debitor">
                            </div>
                            <div class="col-md-3">
                                <label>{{trans('admin.Account')}}</label>
                                <select class="select2 form-control w-100" id="AccountCodee">
                                </select>
                            </div>
                            <div class="form-group col-lg-3">
                                <label class="form-label" for="">{{trans('admin.Store')}}</label>
                                <select class="select2 form-control w-100" id="STOREP">
                                    @foreach($Stores as $stor)
                                        <option value="{{$stor->id}}" @if($Def->Store == $stor->id) selected @endif>
                                            {{app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn}}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="form-group col-lg-3">
                                <label class="form-label" for="">{{trans('admin.Safe')}}</label>
                                <select class="select2 form-control w-100" id="SafeP">
                                    @foreach($Safes as $safe)
                                        <option value="{{$safe->id}}" @if($Def->Safe == $safe->id) selected @endif>
                                            {{app()->getLocale() == 'ar' ?$safe->Name :$safe->NameEn}}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <input type="hidden" id="CoinP" value="{{$Def->Coin}}">
                            <input type="hidden" id="DrawP" value="{{$Def->Draw}}">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal"> {{trans('admin.Close')}}</button>
                        <button type="button" class="btn btn-secondary" id="PaymentVoucher"> {{trans('admin.Save')}}</button>
                    </div>
                </div>
            </div>
        </div>


    </main>
    @if(app()->getLocale() == 'ar' )
        <input type="hidden" id="LANG" value="ar">
    @else
        <input type="hidden" id="LANG" value="en">
    @endif


    <input type="hidden" id="SHOWHIDEPRO" value="{{$Def->Hide_Product}}">

@endsection

@push('js')

    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/datagrid/datatables/datatables.bundle.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/summernote/summernote.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/select2/select2.bundle.css')}}">
    <script src="{{asset('Admin/js/datagrid/datatables/datatables.bundle.js')}}"></script>
    <script src="{{asset('Admin/js/datagrid/datatables/datatables.export.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/summernote/summernote.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/select2/select2.bundle.js')}}"></script>



    @if($Place == 'Shortcomings')
        <script src="{{asset('Admin/js/ERP/EditPurchasesShort.js')}}"></script>
    @else
        <script src="{{asset('Admin/js/ERP/EditPurchases.js')}}"></script>
    @endif

@endpush
