@extends(branchMenu())
@section('content')
    <?php Fun::lang()?>
  
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.report_sale_detail')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group paddin-0">
                      
                           <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.customer')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('customer_id',$customer,null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control']) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.product')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('product_id',$product,null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.from_date')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::text('from_date',null, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','autocomplete' => 'off','')) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.to_date')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::text('to_date', null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','')) !!}
                                </div>
                            </div>
                            <div class=" col-sm-12">
                                {!! Form::open(array('route' => 'reportsales_print','method'=>'GET')) !!}
                                <button class=" button_success pull-right print_button" type="button" ><i class="fa fa-print "></i> {{__('administrator.print')}}</button>
                                {!! Form::close() !!}
                                <button class=" button_primary pull-right" id="search" type="submit"> {{__('administrator.search')}}</button>
                            </div>
                           
                    
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" width="100%" class="table table-striped table-hover ">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>{{__('administrator.type')}}</th>
                            <th>{{__('administrator.sale_date')}}</th>
                            <th>{{__('administrator.invoice')}}</th>
                            <th>{{__('administrator.seller')}}</th>
                            <th>{{__('administrator.customer_name')}}</th>
                            <th>{{__('administrator.products')}}</th>
                            <th>{{__('administrator.sale_price')}}</th>
                            <th>{{__('administrator.discount')}}</th>
                            <th>{{__('administrator.sale_qty')}}</th>
                            <th>{{__('administrator.total')}}</th>
                        </tr>
                    </thead>
                    <tbody class="tbody">

                    </tbody>
                    <tfoot class="tfoot">
                        <tr>
                            <th colspan="9" class="text-right"></th>
                            <th class="text-right"></th>
                            <th class="green"></th>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $(document).ready(function () {
            dataTableFilter()
        });
        function dataTableFilter(customer_id ='',product_id='',start_date = '', end_date = '') {
            $('#print_table').DataTable({
                "oLanguage": {
                    "sSearch": "{{__('administrator.search')}}:",
                    "sLengthMenu": "{{__('administrator.display')}} _MENU_ {{__('administrator.record_per_page')}}",
                    "sZeroRecords": "{{__('administrator.Nothing_foundsorry')}}",
                    "sInfo": "{{__('administrator.showing')}} _START_ {{__('administrator.to')}} _END_ {{__('administrator.of')}} _TOTAL_ {{__('administrator.record')}}",
                    "sInfoEmpty": "{{__('administrator.showing')}} 0 {{__('administrator.to')}} 0 {{__('administrator.of')}} 0 {{__('administrator.record')}}",
                    "sInfoFiltered": "({{__('administrator.filter_form')}} _MAX_ {{__('administrator.total_records')}})",
                    "oPaginate": {
                        "sFirst": "{{__('administrator.first')}}",
                        "sLast": "{{__('administrator.last')}}",
                        "sNext": "{{__('administrator.next')}}",
                        "sPrevious": "{{__('administrator.previous')}}"
                    },
                },

                ordering: false,
                serverSide: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax:{
                    url: "{{ route('get-report-sale-detail') }}",
                    data: {
                        
                       
                        customer_id:customer_id,
                        product_id:product_id,
                        start_date: start_date,
                        end_date: end_date,
                    }
                },

                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'sale_type', 'name': 'nso007_sales.sale_type'},
                        {data: 'sale_date', 'name': 'nso007_sales.sale_date'},
                        {data: 'invoice_number', 'name': 'nso007_sales.invoice_number'},
                        {data: 'user_id', 'searchable': false},
                        {data: 'customer_id', 'searchable': false},
                        {data: 'product_id', 'searchable': false},
                        {data: 'sale_price', 'searchable': false},
                        {data: 'dis', 'searchable': false},
                        {data: 'qty', 'searchable': false},
                        {data: 'amount', 'searchable': false},

                    ],
                "footerCallback": function (row, data, start, end, display) {
                    var api = this.api(), data;
                    var intVal = function (i) {
                        return typeof i === 'string' ?
                            i.replace(/[\{{user_currency()->symbol}},]/g, '') * 1 :
                            typeof i === 'number' ?
                                i : 0;
                        
                    };
                    var cost_Total = api
                        .column(10)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);


                    var numFormat = $.fn.dataTable.render.number('\,', '.', 2, '{{user_currency()->symbol}}').display;
                    $(api.column(10).footer()).html(numFormat(cost_Total));
                },
            });

            $.fn.dataTable.ext.errMode = 'throw';
        }
        $(document).on('click', '#search', function () {
            let customer_id = $('select[name="customer_id"]').val();
            let product_id = $('select[name="product_id"]').val();
            let start_date = $('input[name="from_date"]').val();
            let end_date = $('input[name="to_date"]').val();
            $('#print_table').DataTable().destroy();
            dataTableFilter(customer_id,product_id, start_date, end_date);
        });
    </script>
@stop

    


