@extends('backend.layouts.master')
@section('title','Invoice Details')

@push('css')
    <style type="text/css">
        .cus>t{
            border-bottom: 2px dotted;
        }
    </style>
@endpush
<!-- page content -->
@section('content')
    <div class="right_col" role="main">
        <div class="">
           <!-- <div class="page-title">
                <div class="title_left">
                    <h3>Sales Management</h3>
                </div>
                <div class="title_right">
                    <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
                        <div class="col-md-5 col-sm-5 col-xs-12 form-group top_search" style="padding-left: 100px;">
                            <div class="input-group">
                                <a href="{{route('sales.create')}}" class="btn btn-success">Make New Sales</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>-->
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <a href="{{ route('sales.list')}}" calss="btn" ><h2><i class="fa fa-mail-reply"></i></h2></a>
                            <h2>Invoices List</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="btn-primary" onclick="printDiv('printableArea')" ><i class="fa fa-print fa-x"></i></a>
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div class="" id="printableArea">
                                <div class="row">
                                    <div class="col-xs-12 col-sm-12">
                                        <div class="row">
                                            <div class="col-xs-1"></div>
                                            <div class="col-xs-1">
                                                <img src="{{ asset('storage/about/'.about()->logo)}}" class="img-responsive img-thumbnail" alt="logo" width="85px" height="75px" >
                                            </div>
                                            <div class="col-xs-8">
                                                <div class="text-center">
                                                    <h4>{{about()->english_name}}</h4>
                                                    <p>Phone:  {{about()->phone}}, Email: {{about()->email}}</p>
                                                    <p>Address: {{about()->address }} </p>
                                                    <h4>Sales Details Report</h4>
                                                </div>
                                            </div>
                                            <div class="col-xs-2"></div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-3 col-xs-3">
                                                <b>INVOICE NO: {{$sale->invoice_no}}</b>
                                            </div>
                                            <div class="col-sm-6 col-xs-6"></div>
                                            <div class="col-sm-3 col-xs-3">
                                                 <b>Sale Date: {{date('d-m-Y',strtotime($sale->sale_date))}}</b>
                                            </div>
                                        </div>
                                        <hr/>
                                        <div class="row">
                                            <div class="customer">
                                                <table class="table table-bordered table-condensed">
                                                    <tr class="customer-detail">
                                                        <td><b>Customer Name: </b> {{$sale->customer->name}}</td>
                                                        <td><b>Customer Phone: </b> {{$sale->customer->phone}}</td>
                                                    </tr>
                                                    <tr class="customer-detail">
                                                        <td colspan="2"><b>Customer Address: </b>{{$sale->customer->address}} </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <table class="table table-bordered table-condensed">
                                                <thead>
                                                    <tr class="bg-primary">
                                                        <th>SL</th>
                                                        <th>DESCRIPTION</th>
                                                        <th>UNIT PRICE</th>
                                                        <th>SIZE</th>
                                                        <th>TSQF</th>
                                                        <th>TOTAL</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                @foreach($sale->details as $i=>$detail)
                                                    <tr>
                                                        <td class="no">{{$i+1}}</td>
                                                        <td class="text-left">
                                                            {{$detail->product->product_name}}
                                                            ( {{$detail->height}}x{{$detail->width}})
                                                        </td>
                                                        <td class="unit">{{$detail->unit_price}}</td>
                                                        <td class="qty">{{$detail->size}}</td>
                                                        <td class="qty">{{$detail->tsqf}}</td>
                                                        <td class="total">{{$detail->tsqf * $detail->unit_price}}</td>
                                                    </tr>
                                                @endforeach
                                                 <!--@if($sale->other_cost != '')-->
                                                 <!--   <tr>-->
                                                 <!--       <td class="no">{{$i+2}}</td>-->
                                                 <!--       <td colspan="3">{{$sale->note}}</td>-->
                                                 <!--       <td >{{$sale->other_cost}}</td>-->
                                                 <!--       <td >{{$sale->other_cost}}</td>-->
                                                 <!--   </tr>-->
                                                 <!--   @endif-->
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="hr hr8 hr-double hr-dotted"></div>
                                    <div class="row">
                                        <div class="col-sm-5 pull-right">
                                            <h4 class="pull-right">
                                                Total amount :
                                                <span class="red">{{$sale->total_price}}</span>
                                            </h4>
                                        </div>
                                        <div class="col-sm-7 pull-left"> 
                                            Previous Due: <b class="red">{{$sale->customer->sales->sum('due_amount') -  $sale->due_amount}} </b>
                                            <br/>
                                            Total Due: <b class="red">{{$sale->customer->sales->sum('due_amount')}} </b>
                                        </div>
                                    </div>
                                    <div class="space-6"></div>
                                    <div class="">
                                        {{--<b>In Word:</b> {{Terbilang::make($total,'Taka Only')}}.--}}
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-12">Note: {{$sale->note}}</div>
                                    </div>
                                    <hr/>
                                    <div class="text-center">
                                        <small>
                                            Thank you for choosing our Company products.We believe you will be satisfied by our services.
                                        </small>
                                    </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection
@push('js')
    <script type="text/javascript">
        function printDiv(divName) {
         var printContents = document.getElementById(divName).innerHTML;
         var originalContents = document.body.innerHTML;

         document.body.innerHTML = printContents;

         window.print();

         document.body.innerHTML = originalContents;
        }
    </script>
    
@endpush