<div class="row topRow2 mb-3">
    <div class="col-sm-6 col-md-6 col-lg-6">
        <div class="form-group">
            <label for="customer_id">@lang('quickadmin.order.fields.customer')<span class="text-danger">*</span></label>
            <div class="input-group">
                <select name="customer_id" class="form-control select2" id="customer_id">
                    <option value="" disabled selected>@lang('quickadmin.order.fields.select_customer')</option>
                    @foreach($allcustomer as $customer)
                        <option value="{{ $customer->id }}"  {{ isset($order) ? $order->customer_id == $customer->id ? 'selected' :'' :'' }} >{{ $customer->full_name ??'' }} </option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>
    <div class="col-sm-6 col-md-6 col-lg-6">
        <div class="form-group">
            <label for="invoice_date">@lang('quickadmin.order.fields.invoice_date')<span class="text-danger">*</span></label>
            <div class="input-group">
                <input type="text" class="form-control" name="invoice_date" max="<?= date('Y-m-d'); ?>" value="{{ isset($order) ? $order->invoice_date : old('invoice_date') }}" id="invoice_date" >
            </div>
        </div>
    </div>
</div>

<div class="invoiceBelowData add_new_invoice_wrap">
    <div class=" row topRow2">
        <div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
            <div class="form-group">
                <label for="product_id">@lang('quickadmin.order.fields.product')<span class="text-danger">*</span></label>
                <div class="input-group">                
                    <select name="product_id" class="form-control select2" id="product_id">
                        <option value="" disabled selected>@lang('quickadmin.order.fields.select_product')</option>
                        @foreach($allproduct as $product)
                            <option value="{{ $product->id }}"  {{ isset($order) ? $order->product_id == $product->id ? 'selected' :'' :'' }} data-brand="{{$product->brands ? $product->brands->name : ''}}" data-unit="{{$product->product_unit ? $product->product_unit->name : ''}}" data-calculation="{{ $product->calculation }}" >{{ $product->full_name ??'' }} </option>                        
                        @endforeach
                    </select>
                </div>
            </div>
        </div>

        <div class="col-sm-6 col-md-6 col-lg-6 col-xl-3">
            <div class="place_dispatch">
                <div class="form-group">
                    <label for="dispatch_place">@lang('quickadmin.order.fields.place_of_dispatch')<span class="text-danger">*</span></label>
                    <div class="input-group">
                        <select name="dispatch_place" class="form-control select2" id="dispatch_place">
                            @foreach(config('app.product_place') as $key => $place)
                                <option value="{{$key }}"  {{ isset($order) ? $order->dispatch_place == $key? 'selected' :'' :'' }} >{{ $place ?? '' }} </option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
        </div>
        
        <input type="hidden" id="original_quantity" value="0">
    
        <div class="col-md-12 col-lg-12 col-xl-6">
            <div class="flex-box-wrap">
                <div class="form-group">
                    <label for="quantity">@lang('quickadmin.order.fields.quantity')<span class="text-danger">*</span></label>
                    <div class="input-group">
                        <input type="text" class="w-100 form-control" name="quantity" id="quantity" min="1" step="1" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); if(this.value.includes('-')) this.value = this.value.replace('-', ''); if(this.value.indexOf('.') !== -1) { var parts = this.value.split('.'); this.value = parts[0] + '.' + parts[1].slice(0, 2); }" placeholder="@lang('quickadmin.qa_enter') @lang('quickadmin.inventory.fields.quantity')">
                    </div>
                </div>
                <div class="form-group">
                    <label for="price">@lang('quickadmin.order.fields.price')</label>
                    <div class="input-group">
                        <input type="text" placeholder="0.00" id="price" class="form-control" name="price" tabindex="1">
                    </div>
                </div>
                <div class="form-group">
                    <label for="total_price">@lang('quickadmin.order.fields.amount')<span class="text-danger">*</span></label>
                    <div class="input-group">
                        <input type="text" placeholder="0.00" id="total_price" class="form-control" name="total_price" tabindex="1" readonly>
                    </div>
                </div>
        
                <div class=" add-invoice-list">
                    <button type="button" class="add_invoiceBtn btn btn-success addProductBtn" id="addProductBtn">
                        <i class="fas fa-plus"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>




<div class="pt-3 pb-4">
    <div class="table-responsive">
        <table class="table custom_table" id="orderProductTable">
            <thead>
                <tr>
                    <th>@lang('quickadmin.qa_sn')</th>
                    <th>@lang('quickadmin.order.fields.product_name')</th>
                    <th>@lang('quickadmin.order.fields.quantity')</th>
                    <th>@lang('quickadmin.order.fields.price')</th>
                    <th>@lang('quickadmin.order.fields.amount')</th>
                    <th style="text-align: center;">@lang('quickadmin.qa_action')</th>
                </tr>
            </thead>
            <tbody>
                
            </tbody>               
        </table>
    </div>
</div>
<div class="row">
    <div class="col-md-6 col-lg-6 col-xl-4">
        {{-- <div class="form-group">
            <div class="custom-control custom-checkbox">
                <input type="checkbox" name="is_round_off" class="custom-control-input" tabindex="3" id="is_round_off" value="{{ isset($order) ?? $order->is_round_off == 1 }}"  {{ isset($order) ? $order->is_round_off == 1 ? 'checked' :'' :'' }}>
                <label class="custom-control-label" for="is_round_off">@lang('quickadmin.order.fields.round_off')</label>
            </div>
        </div> --}}
        <div class="form-group mt-4 remark_options">
            <label for="remark">@lang('quickadmin.order.fields.remark')</label>
            <div class="input-group">
                <input type="text" placeholder="Enter Remark" id="remark" class="form-control" name="remark" tabindex="1">
            </div>
        </div>
    </div>
    <div class="col-md-6 col-lg-6 col-xl-8">
        <ul class="sub_total_area">
            <li><label>@lang('quickadmin.order.fields.sub_total_amount')</label><span id="sub_total">0</span></li>
            <li><label>@lang('quickadmin.order.fields.labour_bhada')</label>
                <span><input type="text" class="form-control" placeholder="0.00" name="labour_bhada" id="labour_bhada" min="1" step="1" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); if(this.value.includes('-')) this.value = this.value.replace('-', ''); if(this.value.indexOf('.') !== -1) { var parts = this.value.split('.'); this.value = parts[0] + '.' + parts[1].slice(0, 2); }">
                </span>
            </li>
            <li><label>@lang('quickadmin.order.fields.gadi_bhada')</label>
                <span>
                    <input type="text" class="form-control" placeholder="0.00" name="gadi_bhada" id="gadi_bhada" min="1" step="1" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); if(this.value.includes('-')) this.value = this.value.replace('-', ''); if(this.value.indexOf('.') !== -1) { var parts = this.value.split('.'); this.value = parts[0] + '.' + parts[1].slice(0, 2); }">
                </span>
            </li>
            <li><label>@lang('quickadmin.order.fields.grand_total')</label><span id="grand_total">0</span></li>
        </ul>
        <div class="text-right pt-3">
            <button type="submit" class="btn btn-submit-block btn-lg btn-block ml-auto" title="@lang('quickadmin.qa_save_invoice')">@lang('quickadmin.qa_save_invoice')</button>
        </div>
    </div>
</div>