<?php 


/*echo var_dump($tex_master_gst);
die('s-');*/
 ?>

@extends('template.app')

@section('meta')
@endsection

@section('title')
    Car Variant Update
@endsection

@section('styles')
@endsection

@section('content')
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-7 align-self-center">
            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1">Invoice Create</h4>
            <div class="d-flex align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb m-0 p-0">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('car_varient') }}" class="text-muted">Invoice Create</a></li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        @if($orders_data->inventory_id == NULL)
        <div class="col-12">
            <div class="alert alert-danger" role="alert">
              First assign car for this order
            </div>
        </div> 
        @else
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form action="{{ route('order.update') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('POST')
                        <input type="hidden" name="order_id" value="{{ $orders_data->id; }}">
                        <input type="hidden" name="id" value="{{ $orders_data->obf_id; }}">
                        <input type="hidden" name="status" value="invoice_edit">

                        <div class="row">
                            <div class="col-md-12 text-center">
                                <hr>
                                <h2>Vehicle Tax Invoice</h2>
                                <hr>
                            </div>

                            <div class="form-group col-sm-3">
                                <label for="name">Dealer GST</label>
                                <input type="text" class="form-control" disabled="disabled" value="24ABACS4515J1ZH">
                            </div>      

                            <div class="form-group col-sm-3">
                                <label for="name">PAN No</label>
                                <input type="text" class="form-control" disabled="disabled" value="ABACS4515J">
                            </div>   

                            <div class="form-group col-md-3">
                                <label class="control-label">Bill To</label>
                                <textarea name="bill_to" id="bill_to" class="form-control" placeholder="Enter Bill To">{{ $orders_data->bill_to }}</textarea>                                
                                <span class="kt-form__help error bill_to"></span>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="control-label">Address</label>
                                <textarea name="address" id="address" class="form-control" placeholder="Enter Address">{{ $orders_data->address }}</textarea>                                
                                <span class="kt-form__help error address"></span>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="control-label">Ship To</label>
                                <textarea name="ship_to" id="ship_to" class="form-control" placeholder="Enter Ship To">{{ $orders_data->ship_to }}</textarea>                                
                                <span class="kt-form__help error ship_to"></span>
                            </div>

                            <div class="form-group col-sm-3">
                                <label for="name">Financed by/Hypo. by</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->finance_name }}">
                            </div>   

                            @if(isset($orders_data->customer_gst) && $orders_data->customer_gst != NULL && $orders_data->customer_gst == 'corporate')
                            <div class="form-group col-sm-3">
                                <label for="name">Customer GST No</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->customer_gst }}">
                            </div>      
                            @endif

                            <div class="form-group col-sm-3">
                                <label for="name">Customer ID</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->customer_id }}">
                            </div>  

                            <div class="form-group col-sm-3">
                                <label for="name">Invoice No</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->invoice_no }}">
                            </div>   

                            <div class="form-group col-sm-3">
                                <label for="name">Invoice Date</label>
                                <input type="text" class="form-control" disabled="disabled" value='{{date("d/m/Y",strtotime($orders_data->invoice_date))}}'>
                            </div>   

                            <div class="form-group col-sm-3">
                                <label for="name">Phone No</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $data->contact_number}}">
                            </div>   

                            <div class="form-group col-sm-3">
                                <label for="name">PAN No</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->pan_number }}">
                            </div>  

                            <div class="form-group col-sm-3">
                                <label for="name">Place of Supply</label>
                                <input type="text" class="form-control" disabled="disabled" value="GUJARAT">
                            </div>   

                            <div class="form-group col-sm-3">
                                <label for="name">GST No</label>
                                <input type="text" class="form-control" disabled="disabled" value="{{ $orders_data->customer_gst }}">
                            </div> 
                            
                            <div class="form-group col-sm-3">
                                <label for="remark">Remark</label>
                                <textarea name="remark" id="remark" class="form-control" placeholder="Enter Remark">{{ $orders_data->remark }}</textarea>
                                <span class="kt-form__help error remark"></span>
                            </div> 
                            
                            <div class="col-sm-12">
                                <div class="table-responsive">
                                  <table class="table">
                                    <thead>
                                      <tr>
                                        <th><b>PARTICULARS</b></th>
                                        <th><b>AMOUNT(Rs)</b></th>                                       
                                      </tr>
                                    </thead>
                                    <tbody> 
                                      <tr>
                                        <th>{{ $orders_data->product_name }}</th>
                                        <td>{{ $orders_data->on_road_price }}</td>
                                      </tr>
                                      <tr>
                                        <th>Discount</th>
                                        <td>{{ $orders_data->discount }}</td>
                                      </tr>
                                      <tr>
                                        <th>Net Selling Price</th>
                                        <td>{{$orders_data->selling_price}}</td>
                                      </tr>
                                      @if($data->state_id == '7')
                                          <tr>
                                            <th>CGST ({{$tex_master_gst}}%)</th>
                                            <td>{{$orders_data->cgst}}</td>
                                          </tr>
                                          <tr>
                                            <th>SGST ({{$tex_master_gst}}%)</th>
                                            <td>{{$orders_data->sgst}}</td>
                                          </tr>
                                      @else 
                                          <tr>
                                            <th>IGST ({{$tex_master_gst}}%)</th>
                                            <td>{{$orders_data->igst}}</td>
                                          </tr>
                                      @endif
                                      <tr>
                                        <th>Compensation Cess ({{$tex_master_compensation_cess}}%)</th>
                                        <td>{{$orders_data->compensation_cess}}</td>
                                      </tr>
                                      <tr>
                                        <th><b>TOTAL</b></th>
                                        <td>{{$orders_data->total}}</td>
                                      </tr>
                                      <tr>
                                        <th><b>TCS @1%</b></th>
                                       <td>{{ $orders_data->tcs_tax}}</td>
                                      </tr>
                                      <tr>
                                        <th><b>GRAND TOTAL</b></th>
                                        <td>{{$orders_data->grand_total}}</td>
                                      </tr>
                                    </tbody>
                                  </table>
                                </div>
                            </div>

                            <div class="col-sm-12">
                                <h5>Vehicle Particulars</h5>
                                <div class="table-responsive">
                                  <table class="table">
                                    <tbody> 
                                      <tr>
                                        <th><b>Vin No</b></th>
                                        <th><b>Chassis No</b></th>
                                        <th><b>Engine No</b></th>
                                        <th><b>Key No</b></th>
                                        <th><b>HSN No</b></th>
                                      </tr>
                                      <tr>
                                        <td>{{$orders_data->vin_number}}</td>
                                        <td>{{$orders_data->chassis_number}}</td>
                                        <td>{{$orders_data->engine_number}}</td>
                                        <td>{{$orders_data->key_number}}</td>
                                        <td>{{$orders_data->hsn_code}}</td>
                                      </tr>
                                    </tbody>
                                  </table>
                                </div>
                            </div>

                            <div class="form-group col-sm-3">
                                <label for="name"> Applied Promotion</label>
                                <input type="text" class="form-control" disabled="disabled" value="-">
                            </div>  

                        </div>
                        <div class="form
                        -group">
                            <button type="submit" class="btn waves-effect waves-light btn-rounded btn-outline-primary">Submit</button>
                            <a href="{{ route('order') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        @endif
    </div>
</div>
@endsection

@section('scripts')
<script>
    $("#percentage").keyup(function(e){
        $('.percentage').html('');
        if ($(this).val() > 99){
            $('.percentage').html('');
            $('.percentage').html('Enter Value Between 0 to 100!');
            $(this).val();
            $(this).val(100);
        }else if($(this).val() <= 99){
            $('.percentage').html('');
        }
    });

</script>

<script>
    $(document).ready(function() {
        var form = $('#form');
        $('.kt-form__help').html('');
        form.submit(function(e) {
            $('.help-block').html('');
            $('.m-form__help').html('');
            $.ajax({
                url: form.attr('action'),
                type: form.attr('method'),
                data: new FormData($(this)[0]),
                dataType: 'json',
                async: false,
                processData: false,
                contentType: false,
                success: function(json) {
                    return true;
                },
                error: function(json) {
                    if (json.status === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });

    $('#bill_to_1').on('click', function(){
        $('#bill_to').val($('#customer_name').val());
        $('#bill_to_2').prop('checked',false);
    });

    $('#bill_to_2').on('click', function(){
        $('#bill_to').val($('#company_name').val());
        $('#bill_to_1').prop('checked',false);
    });

    $('#address_ch_1').on('click', function(){
        $('#address').val($('#address_1').val());
        $('#address_ch_2').prop('checked',false);
    });

    $('#address_ch_2').on('click', function(){
        $('#address').val($('#address_2').val());
        $('#address_ch_1').prop('checked',false);
    });

    $('#address_ch_1_s').on('click', function(){
        $('#ship_to').val($('#address_1').val());
        $('#address_ch_2_s').prop('checked',false);
    });

    $('#address_ch_2_s').on('click', function(){
        $('#ship_to').val($('#address_2').val());
        $('#address_ch_1_s').prop('checked',false);
    });
</script>
@endsection