@extends('backend.layouts.master')
@section('title','Purchase 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="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('production.list')}}" calss="btn" ><h2><i class="fa fa-mail-reply"></i></h2></a>
                            <h2>Purchase List</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-" onclick="printDiv('printableArea')" ><i class="fa fa-print fa-2x green"></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>Purchase Details Report</h4>
                                                </div>
                                            </div>
                                            <div class="col-xs-2"></div>
                                        </div>
                                        <hr/>
                                        <div class="ro">
                                            <div class="customer">
                                                <table class="table table-bordered">
                                                    <tr class="cus">
                                                        <td>
                                                            <b>Name:  {{ $production->worker->name}}</b>
                                                        </td>
                                                        <td>
                                                            <b>Phone: {{ $production->worker->phone}}</b>
                                                        </td>
                                                    </tr>
                                                    <tr class="cus">
                                                        <td>
                                                            <b>Address :  {{ $production->worker->address}}</b>
                                                        </td>
                                                        <td>
                                                            <b>Date :{{date('d-M-Y', strtotime($production->production_date))  }}</b>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                        <table class="table table-condensed table-bordered">
                                            <thead>
                                                <tr>
                                                    <th class="center">SL</th>
                                                    <th>Product</th>
                                                    <th>Code No</th>
                                                    <th>Unit</th>
                                                    <th>Quantity</th>
                                                    <th>Rate</th>
                                                    <th>Pro.Cost</th>
                                                    <th>Unit Wage</th>
                                                    <th>Wage Total</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            @php
                                                $total = 0;
                                                $tsqf = 0;
                                            @endphp
                                            @foreach($production->pd as $key=>$detail)
                                                @php
                                                    $total = $total + ( $detail->quantity * $detail->rate);
                                                    $tsqf = $detail->product->square_foot * $detail->quantity;
                                                @endphp
                                                <tr>
                                                    <td class="center">{{$key + 1}}</td>
                                                    <td>{{$detail->product->product_name}}</td>
                                                    <td>{{$detail->product->code}}</td>
                                                    <td>{{$detail->unit->name}}</td>
                                                    <td>{{$detail->quantity}}</td>
                                                    <td>{{$detail->rate}}</td>
                                                    <td>{{$detail->quantity * $detail->rate}}</td>
                                                    <td>{{$detail->wage}}</td>
                                                    <td>{{$detail->quantity * $detail->wage}}</td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="hr hr8 hr-double hr-dotted"></div>
                                    <div class="ro">
                                        <div class="col-sm-5 pull-right">
                                            <h4 class="pull-right">
                                                Total amount :
                                                <span class="red">{{$production->grand_total}}</span>
                                            </h4>
                                        </div>
                                        <div class="col-sm-7 pull-left"> 
                                            Previous Due: <b class="red">{{$production->worker->production->sum('due_amount') -  $production->due_amount}} </b>
                                            <br/>
                                            Total Due: <b class="red">{{$production->worker->production->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="ro">
                                        <div class="col-sm-12">Note: {{$production->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