@extends('layouts.app')
@section('title', __( 'report.sale_discount_report' ))

@section('content')

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>@lang( 'report.sale_discount_report' )
        <small>@lang( 'report.sale_discount_report' )</small>
    </h1>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            @component('components.filters', ['title' => __('report.filters')])
                
                <div class="col-md-12">
                <div class="col-md-6">
                    <div class="form-group">
                        {!! Form::label('tax_report_date_range', __('report.date_range') . ':') !!}
                        {!! Form::text('tax_report_date_range', @format_datetime('now'), ['placeholder' => __('lang_v1.select_a_date_range'), 'class' => 'form-control', 'id' => 'tax_report_date_range', 'readonly']); !!}
                    </div>
                </div>
                </div>
                <div class="col-md-12">
                    <div class="form-group">
					<button type="button" id="reload" class="btn btn-primary pull-right"><i class="fa fa-search"></i> @lang( 'report.load_report' )</button>
                    </div>
                </div>
            @endcomponent
        </div>
    </div> 
  
    <div class="row">
        <div class="col-md-12">
           <!-- Custom Tabs -->
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs"> 
                    <li class="active">
                        <a href="#attendant_shift_tab" data-toggle="tab" aria-expanded="true"><i class="fa fas fa-arrow-circle-right" aria-hidden="true"></i> @lang( 'report.sale_discount_report' )</a>
                    </li> 
                </ul>

                <div class="tab-content"> 
				
                    <div class="tab-pane active" id="attendant_shift_tab">
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped" id="attendant_shift_table">
                            <thead> 
                                <tr>
                                    <th>@lang('report.date')</th>
                                    <th>@lang('report.day')</th>
                                    <th>@lang('report.client_name')</th>
                                    <th>@lang('report.invoice_no')</th>
                                    <th>@lang('report.invoice_amt')</th>
                                    <th>@lang('report.discount_amt')</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr class="bg-gray font-17 text-center footer-total">
                                    <td colspan="4"><strong>@lang('report.totals'):</strong></td>
                                    <td><span class="display_currency" id="invoice_total" data-currency_symbol ="false"></span></td>
                                    <td><span class="display_currency" id="discount_total" data-currency_symbol ="false"></span></td>
                                </tr>
                            </tfoot>
                        </table>
                   
				   </div>
				   </div>
					
                </div>
            </div>
        </div>
    </div>
    

</section>
<!-- /.content -->
@stop
@section('javascript')
<script type="text/javascript">
    $(document).ready(function() {
		
	var dateRangeSettings = {
		ranges: ranges,
		startDate: moment(),
		endDate: moment(),
		locale: {
			cancelLabel: LANG.clear,
			applyLabel: LANG.apply,
			customRangeLabel: LANG.custom_range,
			format: moment_date_format,
			toLabel: '~',
		},
	};
        $('#tax_report_date_range').daterangepicker(
            dateRangeSettings, 
            function(start, end) {
                $('#tax_report_date_range').val(
                    start.format(moment_date_format) + ' ~ ' + end.format(moment_date_format)
                );
            }
        );
		
			attendant_shift_table=$('#attendant_shift_table').DataTable({
            processing: true,
            serverSide: true,
            ajax: {
                url: '/reports/sale-discount-report',
                data: function(d) {
                    var start = $('input#tax_report_date_range')
                        .data('daterangepicker')
                        .startDate.format('YYYY-MM-DD');
                    var end = $('input#tax_report_date_range')
                        .data('daterangepicker')
                        .endDate.format('YYYY-MM-DD');
                    d.start_date = start;
                    d.end_date = end;
                }
            },
            columns: [
                { data: 'transaction_date', name: 'transaction_date' },
                { data: 'day', name: 'day' },
                { data: 'client_name', name: 'client_name', },				
                { data: 'invoice_no', name: 'invoice_no',searchable:false, },
                { data: 'invoice_amt', name: 'invoice_amt',searchable:false, },
                { data: 'discount_amt', name: 'discount_amt',searchable:false, },
            ],
								
			
            fnDrawCallback: function(oSettings) {
				 
                $('#invoice_total').text(
                    sum_table_col($('#attendant_shift_table'), 'invoice_amt')
                );
                $('#discount_total').text(
                    sum_table_col($('#attendant_shift_table'), 'discount_amt')
                );
                __currency_convert_recursively($('#attendant_shift_table'));
            },
			}); 
	 
       
	   $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { 
			if ($("#attendant_shift_tab").hasClass('active')) {
				attendant_shift_table.ajax.reload();
			} 
           
        });
		
        $('#reload').on('click', function(){ 
				attendant_shift_table.ajax.reload();
			
		});
    });
</script>
<script src="{{ asset('js/report.js?v=' . $asset_v) }}"></script>
@endsection