@extends('adminlte::page') @section('content')
    <?php Fun::lang() ?>
    <style>
        .table-inv-head td {
            border: none;
        }

        .table th {
            vertical-align: middle !important;
        }

        table tr:nth-child(even), table tr:hover {
            background: none;
        }

        .table > thead > tr > th {
            border: 1px solid white;
            text-align: center;
        }

        .footer-box {
            width: 100%;
            border: 1px solid black;
            height: 200px;
            position: relative;
        }

        .footer-box span {
            margin-left: 10px
        }

        .footer-box span:last-child {
            position: absolute;
            bottom: 35px;
            left: 0px;
        }

        .footer-box span:first-child {
            position: absolute;
            top: 10px;
        }

        @media print {
            .title-page, .main-footer, button {
                display: none;
            }

            .footer-box {
                height: 150px;
            }
        }
    </style>
    <div class="title-page">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
                <li><a href="#">Construction</a></li>
                <li><a href="#">BOQ & Purchase Order</a></li>
                <li><a href="#">Purchase Order</a></li>
                <li><a href="#">Show</a></li>
            </ul>
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-page">
                        <div class="pull-left">
                            <h3>Show</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="form-wrapper">
                    <form>
                        <div class="row">
                            <div style="border: 1px solid rgb(179, 130, 130);padding: 15px;margin:15px;" id="boq-table-form">
                                <p style="color: #045FB4 !important;font-size: 90%;margin-top: -25px;background-color: white !important;
                            width: 90px !important;text-align: center;font-family: 'Khmer OS Muol Light'">
                                    Purchase Order
                                </p>
                                <br/>
                                <div class="form-box" id="DivIdToPrint">
                                    {{-- <div class="text-center">
                                        <h4><b>បុរី ថៃ ឈុនគ្រី </b></h4>
                                        <h4>Borey Thai Chhunkry</h4>
                                    </div> --}}
                                    <h4 class="text-center" style="margin-top: 25px"><u><b>របាយការណ៍ស្នើសុំទិញសំភារៈ</b></u>
                                    </h4>
                                    <table width="50%" class="table-inv-head">
                                        <tr>
                                            @php $project = \App\ProjectModel::find($purchase->project_id); @endphp
                                            <td>លេខ <span style="margin-left:35px">៖ {{str_pad($purchase->id,6,"0",STR_PAD_LEFT)}}</span></td>
                                            <td>ឈ្មោះគម្រោង <span style="margin-left:7.5px">៖ {{$project->project_name}}</span></td>
                                        </tr>
                                        <tr>
                                            <td>ស្នើសុំដោយ <span>៖ {{$purchase->request_by}}</span></td>
                                            <td>តួនាទី <span style="margin-left:45px">៖ {{$purchase->stock_position}}</span></td>
                                        </tr>
                                    </table>

                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="col-sm-6">
                                                <div class="col-sm-3"></div>
                                                <div class="col-sm-3"></div>
                                                <div class="col-sm-3"></div>
                                            </div>
                                            <div class="col-sm-6"></div>
                                        </div>
                                    </div>

                                    <table style="margin-top: 30px" class="table">
                                        <thead>
                                        <tr>
                                            <th rowspan="2">លរ</th>
                                            <th rowspan="2">បរិយាយមុខទំនិញ</th>
                                            <th rowspan="2">ខ្នាត</th>
                                            <th rowspan="2">ចំនួន</th>
                                            <th colspan="2">តម្លៃ</th>
                                            <th>ក្រុមហ៊ុន</th>
                                            <th>គោលបំណង និង</th>
                                        </tr>
                                        <tr>
                                            <th>រាយ</th>
                                            <th>សរុប</th>
                                            <th>ផ្គត់ផ្គង់</th>
                                            <th>ទីតាំងការងារ</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @php
                                            $g_total = 0;
                                            $table_row = 10;
                                            $count = count($detail);
                                            $row_span = $table_row;
                                            $left_row = $table_row-$count;
                                            if($count>$left_row){
                                                $row_span = $count;
                                            }
                                        @endphp
                                        @foreach($detail as $key => $row)
                                            @php
                                                $product = \App\ConstructionModel\ProductModel::find($row->product_id);  
                                                $unit = \Illuminate\Support\Facades\DB::table('nso007_unit_construction')->where('id',$product->unit_id)->first();
                                                $sup = \App\ConstuctionModel\SuppliersModel::find($purchase->supplier_id);
                                                $total=$row->price*$row->qty;
                                                $g_total+=$total;
                                            @endphp
                                            <tr>
                                                <td>{{$key+1}}</td>
                                                <td>{{$product->name}}</td>
                                                <td>{{optional($unit)->name}}</td>
                                                <td>{{$row->qty}}</td>
                                                <td>$ {{number_format($row->price,2)}}</td>
                                                <td>$ {{number_format($total,2)}}</td>
                                                @if($key==0)
                                                    <td rowspan="{{$row_span}}"
                                                        style="vertical-align: middle!important;text-align: center">{{$sup->name}}<br/>
                                                        {{!empty($supplier_phone)?("លេខទូរស័ព្ទ៖".$supplier_phone):""}}
                                                    </td>
                                                @endif
                                                <td>{{$row->purpose_and_location}}</td>
                                            </tr>
                                        @endforeach
                                        @if(($left_row>0))
                                            @for($i = 0;$i<$left_row;$i++)
                                                    <tr>
                                                        <td>&nbsp;</td>
                                                        <td></td>
                                                        <td></td>
                                                        <td></td>
                                                        <td></td>
                                                        <td></td>
                                                        <td></td>
                                                    </tr>
                                            @endfor
                                        @endif
                                        <tr>
                                            <td colspan="4" class="text-center"><b><u>ចំនួនសរុប</u></b></td>
                                            <td colspan="2" class="text-center">
                                                <b><u>$ {{number_format($g_total,2)}}</u></b></td>
                                            <td colspan="2" class="text-center"></td>
                                        </tr>
                                        </tbody>
                                    </table>

                                    {{-- <div class="row" style="margin-top: 50px">
                                        <div class="col-sm-12 col-xs-12">
                                            <div class="col-sm-3 col-xs-3">
                                                <div class="footer-box">
                                                    <span>ស្នើសុំដោយ:</span>
                                                    <span>កាលបរិច្ឆេទ:</span>
                                                </div>
                                            </div>
                                            <div class="col-sm-3 col-xs-3">
                                                <div class="footer-box">
                                                    <span>ត្រួតពិនិត្យដោយ:</span>
                                                    <span>កាលបរិច្ឆេទ:</span>
                                                </div>
                                            </div>
                                            <div class="col-sm-3 col-xs-3">
                                                <div class="footer-box">
                                                    <span>បានឃើញ:</span>
                                                    <span>កាលបរិច្ឆេទ:</span>
                                                </div>
                                            </div>
                                            <div class="col-sm-3 col-xs-3">
                                                <div class="footer-box">
                                                    <span>ឯកភាពដោយ:</span>
                                                    <span>កាលបរិច្ឆេទ:</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div> --}}
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12 col-xs-12">
                                <div class="form-group">
                                    <button type="button" data-purchase_id = "{{ $purchase->id }}" class="button_sm button_primary pull-right btn_print"><span
                                                class="fa fa-save"></span> Print
                                    </button>
                                    <button type="button" onClick="javascript:history.go(-1)"
                                            class="button_sm button_warning pull-right">
                                        <span class=" fa fa-arrow-circle-left"></span> Back
                                    </button>
                                </div>
                            </div>
                        </div>
                        <br/>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection @section('js')
    <script>
        $(document).ready(function () {
            $('.btn_print').on('click', function () {
                window.location.replace('{{route("construction-purchase.show_print")}}?purchase_id='+$(this).data('purchase_id'));
            });
        });
    </script>
@endsection