@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('saleSummary') }}">   
            {{ csrf_field() }}
            <div class="form-horizontal form-body hidden-print">
                
            </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">Sales Summary Product Wise</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>From </strong>: <span id="fromdateshow"><?php echo date('d-M-Y', strtotime($fromdate)); ?></span>
                                                <br>
                                                <strong>To </strong>: <span id="todateshow"><?php echo date('d-M-Y', strtotime($todate)); ?></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">Product Name</th>
                                                <th class="text-center">Qty</th>
                                                <th class="text-center">Returned Qty</th>
                                                <th class="text-center">Return Total</th>
                                                <th class="text-center">Total</th>
                                                <th class="text-center">Grand Total</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $total = 0; $grand_total = 0; $total_delivered = 0; $total_return = 0;  $total_return_amount = 0; $i = 1;?>
                                            @if($saleSummaryProductWise)
                                            <tr><td><strong>From</strong>: <?php echo $fromdate; ?> <strong>To</strong>: <?php echo $todate; ?></td><td><strong>Customer</strong>: <?php echo isset($saleSummaryProductWise) && !empty($saleSummaryProductWise) ? $saleSummaryProductWise[0]['customer_name'] : "";  ?> </td><td><strong>Brand</strong>: <?php echo isset($saleSummaryProductWise) && !empty($saleSummaryProductWise) ? $saleSummaryProductWise[0]['brand_name'] : "";  ?></td><td></td><td></td><td></td><td></td></tr>
                                            @foreach($saleSummaryProductWise as $row)
                                            <?php $total += $row['total']; $grand_total += $row['grand_total']; $total_delivered += $row['delivered_qty']; $total_return += $row['returned_qty'];  $total_return_amount += $row['return_total'];   ?>
                                            <tr>
                                                <td>{{ $i++ }}</td>
                                                <td>{{ $row['product_name'] }}</td>
                                                <td class="text-right">{{ number_format($row['delivered_qty'], 2) }}</td>
                                                <td class="text-right">{{ number_format($row['returned_qty'], 2) }}</td>
                                                <td class="text-right">{{ number_format($row['return_total'], 2) }}</td>
                                                <td class="text-right">{{ number_format($row['total'], 2) }}</td>
                                                <td class="text-right">{{ number_format($row['grand_total'] - $row['return_total'], 2) }}</td>
                                            </tr>
                                            @endforeach
                                            <tr><td></td><td class="text-right"><strong>Total:</strong></td><td class="text-right"><?php echo number_format($total_delivered, 2); ?><td class="text-right"><?php echo number_format($total_return, 2); ?></td><td class="text-right"><?php echo number_format($total_return_amount, 2); ?></td><td class="text-right"><?php echo number_format($total, 2); ?></td><td class="text-right"><?php echo number_format($grand_total -$total_return_amount, 2); ?></td></tr>
                                            @endif
                                        </tbody>
                                    </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(){
        $('#tblreport').DataTable({
            lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
//                            stateSave: true, 
            fixedHeader: {header: true},
            "bSort" : false,
            dom: "Bfrtlip",
            stateSave: true, 
            buttons: [
                {
                    extend: "excel", 
                    title: 'Sale Summary Product Wise', 
                    filename: 'saleSummaryProductWise',
                }, 
                //{extend: "pdf", title: 'Sale Summary', orientation: 'landscape'}
            ],
            responsive: !0
        });
                        
        $('#fromdate').datepicker({
                autoclose: true,
                todayHighlight: true,
                format: "dd-mm-yyyy",
//                viewMode: "months", 
//                minViewMode: "months"
        });

        $('#todate').datepicker({
            autoclose: true,
            todayHighlight: true,
            format: "dd-mm-yyyy",
        });
       
    });
    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

