Restaurant Management System ( Part 12 )

Published Date: 08-Feb-2018 | Tags: Laravel 5.5  Bootstrap 3  Project  

This tutorial I want to show you how to make all reports in Admin screen.

  • Stock Balance
  • Daily Summary
  • Sale History
  • Sale Detail
  • Deleted Item
  • Sale Stock
  • Sale Discount
  • Sale Graph Report

Note: I recommend you to check all pervious tutorials before coming to this step. Because some tutorials have relationship with others

 

Step 1: Create View

Create view daily_summary.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h2 class="page-header">Daily Summary Report</h2>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"
                   id="report_from"/>
        </div>
    </div>
    <div class="form-group col-sm-3">
        <a href="javascript:window.open('report/print-daily-summary?report_from='+$('#report_from').val(),'_blank');"
           class="btn btn-primary"><i class="glyphicon glyphicon-print"></i> Print</a>
    </div>
</div>
<h2 style="text-align: center;padding: 10px;background: whitesmoke">
    $ {{number_format($orders['Total']['total'],2)}}</h2>
<div class="row">
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th style="text-align: center">Category</th>
                <th style="text-align: center">Total</th>
            </tr>
            </thead>
            <tbody>
            @foreach($sale as $key=>$value)
                @if($key!='Total')
                    <tr style="font-size: 14px">
                        <td>{{$key}}</td>
                        <td align="right">$ {{number_format($value['total'],2)}}</td>
                    </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead>
            <tr style="font-size:14px">
                <th style="text-align: center">Period</th>
                <th style="text-align: center">Total</th>
            </tr>
            </thead>
            <tbody>
            @foreach($orders as $key=>$value)
                @if($key!='Total')
                    <tr style="font-size: 14px">
                        <td>{{$key}}</td>
                        <td align="right">$ {{number_format($value['total'],2)}}</td>
                    </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>
</div>
<script>
    var old_date = $('#report_from').val();
    $('#report_from').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
        onOpen: function () {
            old_date = $('#report_from').val();
        },
        onClose: function () {
            if (this.get('select', 'dd-mmm-yyyy') != old_date)
                ajaxLoad('report/daily-summary?report_from=' + this.get('select', 'yyyy-mm-dd'));
        }
    });
</script>

 

Create view print_daily_summary.blade.php in /resources/views/report. (create folder report if it does not exist) 

<center>
    <h1 style="font-size:20px;margin:0">SOURKEA RESTAURANT</h1>
    <h4 style="margin: 0">Daily Summary Report</h4>
    <h5 style="margin: 5px">{{date('d-M-Y',strtotime(Session::get('report_from')))}}</h5>
</center>
<hr style="size:2px;border:inset">
<h2 style="text-align: center;padding: 10px;background: whitesmoke">
    $ {{number_format($orders['Total']['total'],2)}}</h2>
<table style="width:100%;margin-top:10px" border="1px solid" cellspacing="0" cellpadding="5px">
    <tr style="font-size:14px">
        <th>Category</th>
        <th>Total</th>
    </tr>
    @foreach($sale as $key=>$value)
        @if($key!='Total')
            <tr style="font-size: 14px">
                <td>{{$key}}</td>
                <td align="right">$ {{number_format($value['total'],2)}}</td>
            </tr>
        @endif
    @endforeach
</table>
<table style="width:100%;margin-top:10px" border="1px solid" cellspacing="0" cellpadding="5px">
    <tr style="font-size:14px">
        <th>Period</th>
        <th>Total</th>
    </tr>
    @foreach($orders as $key=>$value)
        @if($key!='Total')
            <tr style="font-size: 14px">
                <td>{{$key}}</td>
                <td align="right">$ {{number_format($value['total'],2)}}</td>
            </tr>
        @endif
    @endforeach
</table>
</body>
<script>
//    window.print();
//    window.close();
</script>

 

Create view sale_deleted_report.blade.php in /resources/views/report. (create folder report if it does not exist)  

<h1 class="page-header">Sale Deleted Report</h1>
<div class="modal fade " id="modal" tabindex="-1" role="dialog" aria-labelledby="modal"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content container-fluid">
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_from"
                   value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_to"
                   value="{{date('d-M-Y',strtotime(Session::get('report_to')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        {!! Form::select('cashier',['-1'=>'All Cashiers']+\App\User::where('role','Cashier')->orderBy('username')->pluck('username','id')->toArray() ,Session::get('report_user'),['class'=>'form-control','style'=>'height:auto','onChange'=>"ajaxLoad('report/sale-deleted-report?report_user='+this.value)"]) !!}
    </div>
    <div class="form-group col-sm-1">
        <a href="javascript:ajaxLoad('report/sale-deleted-report?report_from='+$('#report_from').val()+'&report_to='+$('#report_to').val())"
           class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<table class="table table-bordered" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th> Ordered_Date</th>
        <th> Deleted_Date</th>
        <th> Invoice #</th>
        <th style="text-align: center"> Table #</th>
        <th> Product</th>
        <th style="text-align: center"> Quantity</th>
        <th style="text-align: right"> Unitprice</th>
        <th> Cashier</th>
    </tr>
    </thead>
    <tbody>
    @foreach($orders as $order)
        <tr>
            <td>{{date("d-M-Y H:i",strtotime($order->created_at))}}</td>
            <td>{{date("d-M-Y H:i",strtotime($order->deleted_at))}}</td>
            <td><a title="Table" data-toggle="modal" data-target="#modal"
                   href="report/view-detail/{{$order->order_id}}">
                    {{str_pad($order->order_id,6,0,0)}}
                </a></td>
            <td align="center">{{$order->table?$order->table->name:''}}</td>
            <td>{{$order->description}}</td>
            <td align="center">{{$order->quantity}}</td>
            <td align="right">{{$order->price}}</td>
            <td>{{$order->user?$order->user->username:''}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
<div class="pull-right">{!! str_replace('/?','?',$orders->render()) !!}</div>
<div class="row">
    <i class="col-sm-12">
        Total: {{$orders->total()}} records
    </i>
</div>
<script>
    $('#modal').on('shown.bs.modal', function () {
        $('#focus').focus().select();
    });
    $('#modal').on('hidden.bs.modal', function (e) {
        $(this).removeData('bs.modal');
    });
    $('#report_from, #report_to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
    });
</script>

 

Create view sale_detail.blade.php in /resources/views/report. (create folder report if it does not exist)  

<h2 class="page-header">Sale Detail Report
    <div class="pull-right">
        <a href="{{url('report/export-detail-report')}}" class="btn btn-primary"><i
                    class="glyphicon glyphicon-export"></i> Export to Excel</a>
    </div>
</h2>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_from"
                   value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_to"
                   value="{{date('d-M-Y',strtotime(Session::get('report_to')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        {!! Form::select('category',['-1'=>'All Categories']+\App\ProductCategory::orderBy('name')->pluck('name','id')->toArray() ,Session::get('report_category'),['class'=>'form-control','style'=>'height:auto','id'=>'report_category']) !!}
    </div>
    <div class="form-group col-sm-1">
        <a href="javascript:ajaxLoad('report/sale-detail?report_from='+$('#report_from').val()+'&report_to='+$('#report_to').val()+'&report_category='+$('#report_category').val())"
           class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<table class="table" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th style="text-align: center"> No</th>
        <th> Description</th>
        <th> Category</th>
        <th style="text-align: center"> Quantity</th>
        <th style="text-align: right"> Unitprice</th>
        <th style="text-align: right"> Total</th>
    </tr>
    </thead>
    <tbody>
    <?php $total = 0;$discount = 0;$i = 1;?>
    @foreach($orderDetails as $orderDetail)
        <tr>
            <td align="center">{{$i++}}</td>
            <td>{!! $orderDetail->product_id?$orderDetail->description:'<b>'.$orderDetail->description.'</b>'!!}</td>
            @php
                $category=\App\ProductCategory::find($orderDetail->product_category_id);
            @endphp
            <td>{{$category?$category->name:''}}</td>
            <td align="center">{{$orderDetail->total}}</td>
            <td align="right">$ {{$orderDetail->price}}</td>
            <td align="right">$ {{$orderDetail->price * $orderDetail->total}}</td>
        </tr>
        <?php
        $total += $orderDetail->price * $orderDetail->total;
        $discount += $orderDetail->discount;
        ?>
    @endforeach
    </tbody>
</table>
<div style="text-align: right;float: right;border-top: solid 1px whitesmoke;margin-top: 10px;">
    <table width="100%" style="margin-top: 10px;margin-bottom: 10px">
        <tr>
            <th style="text-align: right;padding-right: 20px">Total:</th>
            <th style="text-align: right">$ {{number_format($total,2)}}</th>
        </tr>
        <tr>
            <th style="text-align: right;padding-right: 20px">Discount:</th>
            <th style="text-align: right">$ {{number_format($discount,2)}}</th>
        </tr>
        <tr>
            <th style="text-align: right;padding-right: 20px">Net Amount:</th>
            <th style="text-align: right">$ {{number_format($total-$discount,2)}}</th>
        </tr>
    </table>
</div>
<script>
    $('#report_from, #report_to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
    });
</script>

 

Create view sale_discount.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h2 class="page-header">Sale Discount Report </h2>

<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_from"
                   value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_to"
                   value="{{date('d-M-Y',strtotime(Session::get('report_to')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        {!! Form::select('customer',['-1'=>'ALL','0'=>'Customer']+\App\Customer::orderBy('name')->pluck('name','id')->toArray() ,Session::get('report_customer'),['class'=>'form-control','style'=>'height:auto','id'=>'report_customer']) !!}
    </div>
    <div class="form-group col-sm-1">
        <a href="javascript:ajaxLoad('report/sale-discount?report_from='+$('#report_from').val()+'&report_to='+$('#report_to').val()+'&report_customer='+$('#report_customer').val())"
           class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<table class="table" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th style="text-align: center" width="100px"> No</th>
        <th> Customer</th>
        <th style="text-align: right"> Total</th>
    </tr>
    </thead>
    <tbody>
    <?php $total = 0; $i = 1;?>
    @foreach($discount as $s)
        <tr>
            <td align="center">{{$i++}}</td>
            <td>{{$s->customer_id==0?'Customer':$s->customer->name}}</td>
            <td align="right">${{number_format($s->total,2)}}</td>
        </tr>
        <?php $total += $s->total; ?>
    @endforeach
    </tbody>
</table>
<div style="text-align: right;float: right;border-top: solid 1px whitesmoke;margin-top: 10px;">
    <table width="100%" style="margin-top: 10px;margin-bottom: 10px">
        <tr>
            <th style="text-align: right;padding-right: 20px">Total:</th>
            <th style="text-align: right">$ {{number_format($total,2)}}</th>
        </tr>
    </table>
</div>
<script>
    $('#report_from, #report_to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
    });
</script>

 

Create view sale_graph.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h2 class="page-header">Sale Graph Report </h2>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="from"
                   value="{{date('d-M-Y',strtotime(Session::get('from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="to"
                   value="{{date('d-M-Y',strtotime(Session::get('to')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <select class="form-control" onchange="ajaxLoad('report/sale-graph?dm='+this.value)">
            <option {{Session::get('dm')=='Day'?'selected':''}} value="Day">Day</option>
            <option {{Session::get('dm')=='Month'?'selected':''}} value="Month">Month</option>
        </select>
    </div>
    <div class="col-sm-2 form-group">
        <a href="javascript:ajaxLoad('report/sale-graph?from='+$('#from').val()+'&to='+$('#to').val())"
           class="btn btn-primary"><i
                    class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<div class="row">
    <div id="line"></div>
</div>
</div>
<script>
    $('#line').highcharts({
        colors: ['#058DC7', '#50B432', '#cc00cc', 'red', '#cc0033', '#DDDF00', '#64E572', '#24CBE5', '#FFF263', '#FF9655'],
        title: {
            text: 'Sale Summary Report',
            x: -20 //center
        },
        subtitle: {
            text: '',
            x: -20
        },
        xAxis: {
            categories: <?php echo json_encode($iv); ?>

        },
        yAxis: {
            title: {
                text: 'Cash in hand ($)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true,
                    formatter: function () {
                        return Highcharts.numberFormat(this.y, 2);
                    }
                },
                enableMouseTracking: false
            }
        },
        tooltip: {
            headerFormat: '',
            valuePrefix: '$'
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [
            {
                name: 'Breakfast',
                marker: {symbol: "circle"},
                data:<?php echo json_encode($morning); ?>
            },
            {
                name: 'Lunch',
                marker: {symbol: "circle"},
                data:<?php echo json_encode($afternoon); ?>
            },
            {
                name: 'Dinner',
                marker: {symbol: "circle"},
                data:<?php echo json_encode($evening); ?>
            },
            {
                name: 'Daily',
                marker: {symbol: "circle"},
                data:<?php echo json_encode($daily); ?>
            }
        ]
    });
    $('#from, #to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true
    });
</script>

 

Create view sale_history.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h1 class="page-header">Sale History Report</h1>
<div class="modal fade " id="modal" tabindex="-1" role="dialog" aria-labelledby="modal"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content container-fluid">
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_from"
                   value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_to"
                   value="{{date('d-M-Y',strtotime(Session::get('report_to')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        {!! Form::select('customer',['-1'=>'All Customers']+\App\Customer::orderBy('name')->pluck('name','id')->toArray() ,Session::get('report_customer'),['class'=>'form-control','style'=>'height:auto','onChange'=>"ajaxLoad('report/sale-history?report_customer='+this.value)"]) !!}
    </div>
    <div class="form-group col-sm-1">
        <a href="javascript:ajaxLoad('report/sale-history?report_from='+$('#report_from').val()+'&report_to='+$('#report_to').val())"
           class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<table class="table table-bordered" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th> Date</th>
        <th> Invoice #</th>
        <th> Table #</th>
        <th style="text-align: right"> Amount</th>
        <th style="text-align: right"> Discount</th>
        <th style="text-align: right"> Total</th>
        <th> Customer</th>
        <th> Cashier</th>
    </tr>
    </thead>
    <tbody>
    @foreach($orders as $order)
        <tr>
            <td>{{$order->created_at}}</td>
            <td><a title="Table" data-toggle="modal" data-target="#modal"
                   href="report/view-detail/{{$order->id}}">
                    {{str_pad($order->id,6,0,0)}}
                </a></td>
            <td align="center">{{$order->table?$order->table->name:''}}</td>
            <td align="right">
                <?php $amount = $order->order_details()->select(DB::raw('sum(quantity*price) as  total,sum(quantity*price*discount/100) as  discount'))->first();?>
                $ {{number_format($amount->total,2)}}</td>
            <td align="right">{{$order->discount}}%</td>
            <td align="right">
                $ {{number_format(($amount->total - $amount->discount) * (1-$order->discount/100),2)}}</td>
            <td>{{$order->customer_id && $order->customer?$order->customer->name:''}}</td>
            <td>{{$order->user?$order->user->username:''}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
<div class="pull-right">{!! str_replace('/?','?',$orders->render()) !!}</div>
<div class="row">
    <i class="col-sm-12">
        Total: {{$orders->total()}} records
    </i>
</div>
<script>
    $('#modal').on('shown.bs.modal', function () {
        $('#focus').focus().select();
    });
    $('#modal').on('hidden.bs.modal', function (e) {
        $(this).removeData('bs.modal');
    });
    $('#report_from, #report_to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
    });
</script>

 

Create view sale_stock.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h2 class="page-header">Sale Stock Report </h2>
<div class="row">
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_from"
                   value="{{date('d-M-Y',strtotime(Session::get('report_from')))}}"/>
        </div>
    </div>
    <div class="col-sm-3 form-group">
        <div class='input-group date'>
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
            <input type='text' class="form-control" id="report_to"
                   value="{{date('d-M-Y',strtotime(Session::get('report_to')))}}"/>
        </div>
    </div>
    <div class="form-group col-sm-1">
        <a href="javascript:ajaxLoad('report/sale-stock?report_from='+$('#report_from').val()+'&report_to='+$('#report_to').val())"
           class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> </a>
    </div>
</div>
<table class="table" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th> Product</th>
        <th> Category</th>
        <th> Unit</th>
        <th style="text-align: center"> Quantity</th>
    </tr>
    </thead>
    <tbody>
    @foreach($stock as $s)
        <tr>
            <td>{{$s->name}}</td>
            <td>{{$s->item_category_id?\App\ItemCategory::find($s->item_category_id)->name:''}}</td>
            <td>{{$s->unit}}</td>
            <td align="center">{{number_format($s->total,2)}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
<script>
    $('#report_from, #report_to').pickadate({
        format: "dd-mmm-yyyy",
        selectMonths: true,
        selectYears: true,
    });
</script>

 

Create view stock_balance.blade.php in /resources/views/report. (create folder report if it does not exist) 

<h1 class="page-header">Stock Balance Report</h1>
<div class="col-md-3 form-group">
    {!! Form::select('category',['-1'=>'All Categories']+App\ItemCategory::orderBy('name')->pluck('name','id')->toArray() ,Session::get('item_category'),['class'=>'form-control','style'=>'height:auto','onChange'=>'ajaxLoad("'.url("report/stock-balance").'?category="+this.value)']) !!}
</div>
<div class="col-sm-4 form-group">
    <div class="input-group">
        <input class="form-control" id="search" value="{{ Session::get('item_search') }}"
               onkeydown="if (event.keyCode == 13) ajaxLoad('{{url('report/stock-balance')}}?ok=1&search='+this.value)"
               placeholder="Search..."
               type="text">

        <div class="input-group-btn">
            <button type="button" class="btn btn-default"
                    onclick="ajaxLoad('{{url('report/stock-balance')}}?ok=1&search='+$('#search').val())"><i
                        class="glyphicon glyphicon-search"></i>
            </button>
        </div>
    </div>
</div>
<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th width="50px" style="text-align: center">No</th>
        <th>
            <a href="javascript:ajaxLoad('report/stock-balance?field=name&sort={{Session::get("item_sort")=="asc"?"desc":"asc"}}')">
                Name
            </a>
            <i style="font-size: 12px"
               class="glyphicon  {{ Session::get('item_field')=='name'?(Session::get('item_sort')=='asc'?'glyphicon-sort-by-alphabet':'glyphicon-sort-by-alphabet-alt'):'' }}">
            </i>
        </th>
        <th>Category</th>
        <th style="text-align: center">Unit</th>
        <th style="text-align: center">Quantity</th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1;?>
    @foreach($items as $key=>$item)
        <tr>
            <td align="center">{{$i++}}</td>
            <td>{{$item->name}}</td>
            <td>{{$item->item_category_id?$item->item_category->name:''}}</td>
            <td align="center">{{$item->unit}}</td>
            <td style="text-align: center">
                {{$item->quantity}}
            </td>
        </tr>
    @endforeach
    </tbody>
</table>
<div class="pull-right">{!! str_replace('/?','?',$items->render()) !!}</div>
<div class="row">
    <i class="col-sm-12">
        Total: {{$items->total()}} records
    </i>
</div>

 

Create view view.blade.php in /resources/views/report. (create folder report if it does not exist)

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
    </button>
    <h4 class="modal-title">View Order Detail</h4>
</div>
<div class="modal-body">
    <div class="row">
        <div class="col-md-5">
            <table class="table">
                <tr>
                    <th style="text-align: right;border-top: none">Invoice:</th>
                    <th style="border-top: none">{{str_pad($order->id,6,0,0)}}</th>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Table:</th>
                    <td style="border-top: none">{{$order->table->name}}</td>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Checked in:</th>
                    <td style="border-top: none">{{date('d-M-Y H:i',strtotime($order->checked_in))}}</td>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Checked out:</th>
                    <td style="border-top: none">{{date('d-M-Y H:i',strtotime($order->checked_out))}}</td>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Cashier:</th>
                    <td style="border-top: none">{{$order->user?$order->user->username:''}}</td>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Customer:</th>
                    <td style="border-top: none">{{$order->customer_id && $order->customer?$order->customer->name:''}}</td>
                </tr>
                <tr>
                    <th style="text-align: right;border-top: none">Cash in:</th>
                    <td style="border-top: none">$ {{$order->usd}}</td>
                </tr>
            </table>
        </div>
        <div class="col-md-7">
            <table class="table" cellspacing="0" width="100%">
                <thead>
                <tr>
                    <th width="50px" style="text-align: center">
                        No
                    </th>
                    <th> Description</th>
                    <th> Qty</th>
                    <th> U.Price</th>
                    <th> D.C</th>
                    <th> Total</th>
                </tr>
                </thead>
                <tbody>
                <?php $total = 0; $i = 1;?>
                @foreach($order->order_details()->withTrashed()->get() as $sale)
                    <tr @if(!empty($sale->deleted_at)) style="text-decoration: line-through" @endif>
                        <td style="text-align: center">{{$i++}}
                        </td>
                        <td>{{$sale->description}}</td>
                        <td width="10px">{{$sale->quantity}}</td>
                        <td align="right" width="40px">$ {{number_format($sale->price,2)}}</td>
                        <td align="center" width="30px">{{$sale->discount}}%</td>
                        <td align="right" width="70px">
                            $ {{number_format($sale->quantity * $sale->price *(1-$sale->discount/100),2)}}</td>
                    </tr>
                    <?php if (empty($sale->deleted_at)) $total += ($sale->price * $sale->quantity * (1 - $sale->discount / 100)); ?>
                @endforeach
                </tbody>
            </table>
            <div style="text-align: right;float: right;border-top: solid 1px whitesmoke;">
                <table width="100%">
                    <tr>
                        <th style="text-align: right;padding-right: 20px">Discount:</th>
                        <th style="text-align: right">{{$order->discount}} %</th>
                    </tr>
                    <tr>
                        <th style="text-align: right;padding-right: 20px">Total:</th>
                        <th style="text-align: right">$ {{number_format($total*(1-$order->discount/100),2)}}</th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>

 

Step 3: Create Controller

Create controller ReportController.php in /demo/app/Http/Cotrollers.

<?php
namespace App\Http\Controllers;

use App\Item;
use App\ProductCategory;
use App\Order;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Maatwebsite\Excel\Facades\Excel;

class ReportController extends Controller
{
    public function dailySummary()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        $order['Breakfast'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['00:00', '10:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Lunch'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['11:00', '14:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Dinner'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['15:00', '23:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Total'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        // sale by food type
        foreach (ProductCategory::orderBy('name')->pluck('name', 'id') as $key => $value) {
            $sale[$value] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                ->join('products', 'products.id', '=', 'order_details.product_id')
                ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
                ->where('products.product_category_id', $key)
                ->where('orders.status', 'Completed')
                ->where('order_details.deleted_at', NULL)
                ->groupBy(DB::raw("date(orders.created_at)"))
                ->first();
        }
        $sale['Open'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereNull('order_details.product_id')
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        return view('report.daily_summary', ['orders' => $order, 'sale' => $sale]);
    }

    public function printDailySummary()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        $order['Breakfast'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['00:00', '10:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Lunch'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['11:00', '14:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Dinner'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['15:00', '23:59'])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        $order['Total'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        // sale by food type
        foreach (ProductCategory::orderBy('name')->pluck('name', 'id') as $key => $value) {
            $sale[$value] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                ->join('products', 'products.id', '=', 'order_details.product_id')
                ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
                ->where('products.product_type_id', $key)
                ->where('orders.status', 'Completed')
                ->where('order_details.deleted_at', NULL)
                ->groupBy(DB::raw("date(orders.created_at)"))
                ->first();
        }
        $sale['Open'] = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
            ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime(Session::get('report_from'))))
            ->whereNull('order_details.product_id')
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy(DB::raw("date(orders.created_at)"))
            ->first();
        return view('report.print_daily_summary', ['orders' => $order, 'sale' => $sale]);
    }

    public function saleHistory()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        Session::put('report_customer', Input::has('report_customer') ? Input::get('report_customer') : (Session::has('report_customer') ? Session::get('report_customer') : '-1'));
        Session::put('report_user', Input::has('report_user') ? Input::get('report_user') : (Session::has('report_user') ? Session::get('report_user') : '-1'));
        $orders = Order::whereBetween(DB::raw("date(created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))]);
        if (Session::get('report_user') != -1)
            $orders = $orders->where('user_id', Session::get('report_user'));
        if (Session::get('report_customer') != -1)
            $orders = $orders->where('customer_id', Session::get('report_customer'));
        $orders = $orders->paginate(20);
        return view('report.sale_history', ['orders' => $orders]);
    }

    public function saleDeletedReport()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        Session::put('report_user', Input::has('report_user') ? Input::get('report_user') : (Session::has('report_user') ? Session::get('report_user') : '-1'));
        $orders = Order::join('order_details', 'order_details.order_id', '=', 'orders.id')
            ->select(['order_details.*', 'orders.table_id'])
            ->whereBetween(DB::raw("date(orders.created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))]);
        if (Session::get('report_user') != -1)
            $orders = $orders->where('orders.user_id', Session::get('report_user'));
        $orders = $orders->where('deleted_at', '!=', null)->paginate(20);
        return view('report.sale_deleted_report', ['orders' => $orders]);
    }

    public function viewDetail($id)
    {
        return view('report.view_detail', ['order' => Order::find($id)]);
    }

    public function saleDetail()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        Session::put('report_category', Input::has('report_category') ? Input::get('report_category') : (Session::has('report_category') ? Session::get('report_category') : '-1'));
        $orderDetails = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->leftJoin('products', 'products.id', '=', 'order_details.product_id')
            ->select(DB::raw("product_id,description,products.product_category_id, products.product_type_id,sum(order_details.quantity) as total,order_details.price,sum(order_details.quantity * order_details.price*orders.discount/100) as discount"))
            ->whereBetween(DB::raw("date(orders.created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))]);
        if (Session::get('report_category') != -1)
            $orderDetails = $orderDetails->where('products.product_category_id', Session::get('report_category'));
        $orderDetails = $orderDetails->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy('order_details.product_id')
            ->groupBy('order_details.description')
            ->groupBy('order_details.price')
            ->orderBy('total', 'desc')
            ->get();
        return view('report.sale_detail', ['orderDetails' => $orderDetails]);
    }

    public function saleGraph()
    {
        Session::put('from', Input::has('from') ? Input::get('from') : (Session::has('from') ? Session::get('from') : date("d-M-Y", strtotime("-7 days"))));
        Session::put('to', Input::has('to') ? Input::get('to') : (Session::has('to') ? Session::get('to') : date("d-M-Y")));
        Session::put('dm', Input::has('dm') ? Input::get('dm') : (Session::has('dm') ? Session::get('dm') : 'Day'));
        $d1 = strtotime(Session::get('from'));
        $d2 = strtotime(Session::get('to'));
        $iv = array();
        $morning = array();
        $afternoon = array();
        $evening = array();
        $daily = array();
        $interval = $d2 - $d1;
        if (Session::get('dm') == 'Day') {
            $count = date('d', $interval);
        } else {
            $d1 = strtotime(date("Y-n", $d1));
            $d2 = strtotime(date("Y-n", $d2));
            $interval = $d2 - $d1;
            $count = date('n', $interval);
        }
        for ($i = 1; $i <= $count; $i++) {
            if (Session::get('dm') == 'Day') {
                $current = gmdate("d-M-Y", strtotime("+$i day", $d1));
                $iv[$i - 1] = intVal(date("d", strtotime($current)));
            } else {
                $current = gmdate("M-Y", strtotime("+$i month", $d1));
                $iv[$i - 1] = date("M", strtotime($current));
            }
            if (Session::get('dm') == 'Day') {
                $m = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['00:00', '10:59'])
                    ->first();
                $a = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['11:00', '14:59'])
                    ->first();
                $e = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['15:00', '23:59'])
                    ->first();
                $d = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date(orders.created_at)"), date('Y-m-d', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->first();
            } else {
                $m = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date_format(orders.created_at,'%Y-%m')"), date('Y-m', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['00:00', '10:59'])
                    ->first();
                $a = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date_format(orders.created_at,'%Y-%m')"), date('Y-m', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['11:00', '14:59'])
                    ->first();
                $e = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date_format(orders.created_at,'%Y-%m')"), date('Y-m', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->whereBetween(DB::raw("date_format(orders.created_at,'%H:%i')"), ['15:00', '23:59'])
                    ->first();
                $d = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
                    ->select(DB::raw('sum(order_details.quantity * order_details.price * (1-order_details.discount/100) * (1-orders.discount/100)) as total'))
                    ->where(DB::raw("date_format(orders.created_at,'%Y-%m')"), date('Y-m', strtotime($current)))
                    ->where('orders.status', 'Completed')
                    ->where('order_details.deleted_at', NULL)
                    ->first();
            }
            $morning[$i - 1] = floatval($m->total ? $m->total : 0);
            $afternoon[$i - 1] = floatval($a->total ? $a->total : 0);
            $evening[$i - 1] = floatval($e->total ? $e->total : 0);
            $daily[$i - 1] = floatval($d->total ? $d->total : 0);
        }
        return view('report.sale_graph', ['iv' => $iv, 'morning' => $morning, 'afternoon' => $afternoon, 'evening' => $evening, 'daily' => $daily]);
    }

    public function saleStock()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        $stock = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->join('products', 'products.id', '=', 'order_details.product_id')
            ->join('recipes', 'recipes.product_id', '=', 'products.id')
            ->join('items', 'items.id', '=', 'recipes.item_id')
            ->select(DB::raw("items.name,items.item_category_id,items.unit,sum(recipes.quantity * order_details.quantity) as total"))
            ->whereBetween(DB::raw("date(orders.created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy('recipes.item_id')
            ->orderBy('total', 'desc')
            ->get();
        return view('report.sale_stock', ['stock' => $stock]);
    }

    public function saleDiscount()
    {
        Session::put('page', 'report/sale-discount');
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        Session::put('report_customer', Input::has('report_customer') ? Input::get('report_customer') : (Session::has('report_customer') ? Session::get('report_customer') : '-1'));
        $discount = Order::join('order_details', 'orders.id', '=', 'order_details.order_id');
        if (Session::get('report_customer') == 0)
            $discount = $discount->whereNull('orders.customer_id');
        elseif (Session::get('report_customer') != -1)
            $discount = $discount->where('orders.customer_id', Session::get('report_customer'));
        $discount = $discount->select(DB::raw("orders.customer_id,sum(((order_details.quantity * order_details.price * (1-order_details.discount/100))*orders.discount/100)+(order_details.quantity * order_details.price * order_details.discount/100)) as total"))
            ->whereBetween(DB::raw("date(orders.created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))])
            ->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
//            ->where('orders.customer_id', '!=', -1)
            ->groupBy('orders.customer_id')
            ->get();
        return view('report.sale_discount', ['discount' => $discount]);
    }

    public function exportDetailReport()
    {
        Session::put('report_from', Input::has('report_from') ? Input::get('report_from') : (Session::has('report_from') ? Session::get('report_from') : date("Y-m-d")));
        Session::put('report_to', Input::has('report_to') ? Input::get('report_to') : (Session::has('report_to') ? Session::get('report_to') : date("Y-m-d")));
        Session::put('report_category', Input::has('report_category') ? Input::get('report_category') : (Session::has('report_category') ? Session::get('report_category') : '-1'));
        $orderDetails = Order::join('order_details', 'orders.id', '=', 'order_details.order_id')
            ->leftJoin('products', 'products.id', '=', 'order_details.product_id')
            ->select(DB::raw("product_id,description,products.product_category_id, products.product_type_id,sum(order_details.quantity) as total,order_details.price,sum(order_details.quantity * order_details.price*orders.discount/100) as discount"))
            ->whereBetween(DB::raw("date(orders.created_at)"), [date('Y-m-d', strtotime(Session::get('report_from'))), date('Y-m-d', strtotime(Session::get('report_to')))]);
        if (Session::get('report_category') != -1)
            $orderDetails = $orderDetails->where('products.product_category_id', Session::get('report_category'));
        $orderDetails = $orderDetails->where('orders.status', 'Completed')
            ->where('order_details.deleted_at', NULL)
            ->groupBy('order_details.product_id')
            ->groupBy('order_details.description')
            ->groupBy('order_details.price')
            ->orderBy('total', 'desc')
            ->get();
        Excel::create('Sale Detail Report from' . date('d-M-Y', strtotime(Session::get('report_from'))) . ' to ' . date('d-M-Y', strtotime(Session::get('report_from'))), function ($excel) use ($orderDetails) {
            $excel->sheet('Detail Report', function ($sheet) use ($orderDetails) {
                $sheet->appendRow(['Code', 'Description', 'Category', 'Quantity', 'Unitprice', 'Total']);
                foreach ($orderDetails as $orderDetail) {
                    $sheet->appendRow([
                        $orderDetail->product_id,
                        $orderDetail->description,
                        empty($orderDetail->product_category_id) ? '' : ProductCategory::find($orderDetail->product_category_id)->name,
                        $orderDetail->total,
                        $orderDetail->price,
                        $orderDetail->total * $orderDetail->price,
                    ]);
                }
            });
        })->export('xlsx');
    }

    public function stockBalance()
    {
        Session::put('item_search', Input::has('ok') ? Input::get('search') : (Session::has('item_search') ? Session::get('item_search') : ''));
        Session::put('item_category', Input::has('category') ? Input::get('category') : (Session::has('item_category') ? Session::get('item_category') : -1));
        Session::put('item_field', Input::has('field') ? Input::get('field') : (Session::has('item_field') ? Session::get('item_field') : 'name'));
        Session::put('item_sort', Input::has('sort') ? Input::get('sort') : (Session::has('item_sort') ? Session::get('item_sort') : 'asc'));
        $items = new Item();
        if (Session::get('item_category') != -1)
            $items = $items->where('item_category_id', Session::get('item_category'));
        $items = $items->where('name', 'like', '%' . Session::get('item_search') . '%')->orderBy(Session::get('item_field'), Session::get('item_sort'))->paginate(20);
        return view('report.stock_balance', ['items' => $items]);
    }
}

 

Step 4: How to Test?

After login to admin screen, you will be able to access all report options on the left side menu. Cannot describe, so please go to play around by yourself.

sale-graph

sale-deleted-item

sale-summary

Hope you can do it.


Demo


Related Posts

© 2018 All Rights Reserved.