@extends('layouts.master')

@push('css')
@endpush

@section('content')
<?php //echo "<pre>"; print_r($po_data); exit(); ?>
<style type="text/css">
    .tborder {border: 1px solid black !important;}
    table.customtble tbody tr td{
        padding: 0px 5px 0px 5px;
        /*border:1px solid #000;*/
        font-size: 11px;

    }
    table.customtble thead tr th{
        padding: 0px 5px 0px 5px;
        /*border:1px solid #000;*/
        font-size: 12px;
        font-weight: bold;
    }
    @media print{
        table.customtble thead tr th{
            font-size: 11px;
        }
        table.customtble tbody tr td{
            font-size: 10px;
        }
        body * { visibility: hidden; margin-top: 0px !important;}
        .printableArea, .printableArea *{ visibility: visible !important; }
        table{ border-collapse: collapse;}
        @page {size: landscape}
    }
</style>
<div class="container-fluid">
    <div class="printableArea" id="printableArea">  
        <form id="FormId" class="form-horizontal" method="POST" action="{{ route('dailySale') }}">   
            {{ csrf_field() }}
            <div class="form-horizontal form-body hidden-print">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">

                            <div class="panel-body">
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label for="saledate" class="col-sm-3 control-label"> Date</label>
                                            <div class="col-sm-8">
                                                <input type="text" name="saledate" id="saledate" class="form-control" autocomplete="false" placeholder="dd/mm/yyyy" value="<?php echo date('d-m-Y', strtotime($saledate)); ?>" />
                                            </div>

                                        </div>
                                    </div>
                                   
                                    <div class="col-md-1 ">
                                        <button  type="submit" class="btn btn-primary"><i class="fa fa-search"></i> Run</button>
                                    </div>
                                    <div class="col-md-1 col-lg-1 col-sm-1 col-xs-12">
                                        <span class="spin-loader"></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">

                    <div class="panel-body">
                        <div class="clearfix">
                            <div class="pull-left ">
                                <!-- <h3 class="logo invoice-logo"><img src='{{asset('plugins/images/'.$business->business_logo)}}' width="200" alt='logo here' /></h3> -->
                            </div>
                        </div>
                        <hr class="hidden">
                        <div class="row">
                            <div class="col-md-12"><h3 class="text-center">Daily Sales</h3></div>
                        </div>
                        <div class="row hidden">
                            <div class="col-md-12">
                                <table style=" width: 100%;" cellspacing="0" id="podetailstbl" class="customtble">
                                    <tr>
                                        <td style="width: 50% ">
                                            <p><strong>Date </strong>: <span id="saledateshow"><?php echo date('d-M-Y', strtotime($saledate)); ?></span>
                                                <br>
                                                <strong></strong> <span id="mode">&nbsp;</span>
                                            </p>

                                        </td>
                                        <td style="width: 0.5%; border-bottom: none !important; border-top: none !important;"></td>
                                        <td style="width: 50%">
                                            <p><strong>Statement Date: </strong> <?php echo date('d-M-Y'); ?>
                                                <br>
                                                <strong></strong> <span id="mode">&nbsp;</span>
                                                <br>
                                                <strong></strong> <span id="mode">&nbsp;</span>
                                            </p>

                                        </td>
                                    </tr>
                                </table>

                            </div><!-- end col -->
                        </div>
                        <!-- end row -->

                        <div class="m-h-50">&nbsp;</div>

                        <div class="row">
                            <div class="col-md-12">
                                <div class="table-responsive">
                                    <!-- <table class="table table-bordered m-t-30" id="tblproducts"> -->
                                    <table id="tblreport" class="table-bordered display nowrap" style="width: 100%;">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th class="text-center">Customer</th>
                                                <th class="text-center">Sale Order</th>
                                                <th class="text-center">Invoice</th>
                                                <th class="text-center">Receivable </th>
                                                <th class="text-center">Received</th>
                                                
                                            </tr>
                                        </thead>
                                        <tbody>
                                        @if($saleReport && !empty($saleReport))
                                        <?php $totalPending = 0;  $totalRecieved = 0; $counter =0; ?>
                                            @foreach($saleReport as $row)   
                                                <?php  $totalPending += $row['pending'];  $totalRecieved += $row['recieved']; $counter++; ?>
                                                <tr>
                                                <td>{{ $counter }}</td>
                                                <td >{{ $row['customer_name'] }}</td>
                                                <td >{{ $row['sale_order_number'] }}</td>
                                                <td >{{ $row['invoice_number'] }}</td>                                                
                                                <td >{{ number_format($row['pending'],2) }}</td>
                                                <td >{{ number_format($row['recieved'],2) }}</td>
                                                </tr>
                                            @endforeach
                                           
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                        <td></td>
                                        <td></td><td></td>
                                            <td><strong>Total</strong></td>
                                            <td><strong> {{ number_format($totalPending,2) }}</strong></td>
                                            <td><strong>{{ number_format($totalRecieved,2) }}</strong></td>
                                        </tr>
                                        </tfoot>
                                        @endif
                                    </table>
                                </div>
                            </div>
                        </div>

                        <hr>
                        <div class="hidden-print">
                            <div class="pull-right">
                                <a id="printbutton" href="#" class="btn btn-inverse waves-effect waves-light hidden" onclick='window.print();'  ><i class="fa fa-print"></i></a>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>    
    <!-- end row -->
</div>
<script>
    $(document).ready(function(){
        $('#saledate').datepicker({
                autoclose: true,
                todayHighlight: true,
                format: "dd-mm-yyyy",
//                viewMode: "months", 
//                minViewMode: "months"
        });

        
        $('#tblreport').DataTable({
            lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
//                            stateSave: true, 
            fixedHeader: {header: true},
            "bSort" : false,
            dom: "Bfrtlip",
            buttons: [
                {extend: "excel", title: 'Sale Summary', filename: 'saleSummary'}, 
//                                {extend: "pdf", title: 'Sale Summary', orientation: 'landscape'}
            ],
            responsive: !0
        });
        
     
    });
    function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
</script>
@endsection

