 <?php $__env->startSection('content'); ?>
    <?php Fun::lang() ?>
    <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="#">Purchase Order</a></li>
                <li><a href="#">Ajust CEO Approval</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>Ajust Purchase</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-xs-12">

                <div class="form-wrapper">
                    <?php echo Form::model($request_ajust_purchase, ['method' => 'PATCH','route' => ['construction-purchase.ceo_approval_ajust_purchase_store', $request_ajust_purchase->id],'enctype'=>'multipart/form-data']); ?>

                    <div class="row">
                        <?php if(!empty($request_ajust_purchase->boq_id)): ?>
                            <div class="form-group col-sm-4 col-xs-12">
                                <label class="required">BOQ Request</label>
                                <?php echo Form::select('boq_id',$boq, null, array('class' => 'form-control select2 boq','required','readonly'=>true)); ?>

                                
                            </div>
                        <?php endif; ?>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Project</label>
                            <?php echo Form::select('project_id',$projects, null, array('class' => 'form-control select2 project','required')); ?>

                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Request By</label>
                            <?php echo Form::text('request_by', null, array('placeholder' => 'Please Select','class' => 'form-control ','required','readonly')); ?>

                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Stock Position</label>
                            <?php echo Form::text('stock_position', null, array('placeholder' => 'Please Select','class' => 'form-control ','required','readonly')); ?>

                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Supply Company</label>
                            <?php echo Form::select('supplier_id',$supplier, null, array('class' => 'form-control select2')); ?>

                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="">Phone Number</label>
                            <?php echo Form::text('phone_number', null, array('placeholder' => 'Please Select','class' => 'form-control ','readonly')); ?>

                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="">Date</label>
                            <?php echo Form::text('date', date('d-m-Y'), array('placeholder' => 'Date','class' => 'form-control date_picker','autocomplete'=>'off','readonly')); ?>

                        </div>

                        <div class="form-group col-sm-12 col-xs-12">
                            <table class="table boq_detail">
                                <thead>
                                    <th>#</th>
                                    <th>Item Name</th>
                                    <th>Unit</th>
                                    <th>Qty</th>
                                    <th>Retail</th>
                                    <th>Total</th>
                                    <th>Purpose and Location</th>
                                    <th>Check All <input type="checkbox" class="check_all"></th>
                                </thead>
                                <tbody >
                                    <?php
                                        $tbody = "";
                                        foreach($detail as $key=>$values){
                                            $tbody .='<tr>
                                                <td>'.($key+1).'</td>
                                                <td>'.$values->product_name.'</td>
                                                <td>'.$values->unit_name.'<input readonly type="hidden" name="unit_id['.$values->product_id.']" value="'.$values->unit_id.'"></td>
                                                <td><input type="text" readonly class="number-only form-control qty_per_house" name="qty_per_house['.$values->product_id.']" value="'.$values->qty.'"></td>
                                                <td><input type="text" readonly class="number-only form-control retail" name="retail['.$values->product_id.']" value="'.$values->price.'"></td>
                                                <td>$ <span class="total_amount">'.$values->qty*$values->price.'</span></td>
                                                <td><textarea readonly name="pur_location['.$values->product_id.']" id="" class="form-control" rows="2" style="resize: none;">'.$values->purpose_and_location.'</textarea></td>
                                                <td>
                                                    <input type="checkbox" name="checkbox[]" class="check_here" checked value="'.$values->product_id.'">
                                                    <button type="button" class="btn btn-danger btn_remove" style="display: none"><span class="fa fa-times"></span></button>
                                                </td>
                                            </tr>';
                                        }
                                     ?>
                                    <?php echo $tbody; ?>

                                </tbody>
                            </table>
                        </div>

                        <div class="col-sm-12 col-xs-12">
                            <div class="form-group">
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Construction-CEO-Approval-Ajustment-Purchase-Approve')): ?>
                                    <button type="submit" class="button_sm button_success pull-right" id="btn-edit-submit"><span
                                        class="fa fa-chevron-circle-right"></span> Approve
                                    </button>
                                <?php endif; ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Construction-CEO-Approval-Ajustment-Purchase-Reject')): ?>
                                    <button type="button" class="button_sm button_info pull-right btn_submit" data-id="<?php echo e($request_ajust_purchase->id); ?>"><span
                                        class="fa fa-chevron-circle-right"></span> Reject
                                    </button>
                                <?php endif; ?>
                                <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>

                    <?php echo Form::close(); ?>

                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
    <script type="text/javascript">
        var tbody = <?php echo json_encode($tbody); ?>;
        $(document).ready(function () {            
            $(document).on('click','.btn_remove',function () {
                $(this).closest('tr').remove();
            });
            $(document).on('click','.check_all',function () {
                let check_all = $(this).prop('checked');
                $(document).find('.check_here').attr('checked',check_all);
            });
            $(document).on('keyup','.number-only',function () {

                let qty = $(this).closest('tr').find('.qty_per_house').val();
                let price = $(this).closest('tr').find('.retail').val();
                let total = parseFloat(price?price:0)*parseFloat(qty?qty:0);
                $(this).closest('tr').find('.total_amount').text(total.toFixed(2));
            });
            $('.btn_submit').on('click',function () {
                let request_ajust_purchase_id = $(this).data('id');
                
                $.confirm({
                    title:'Are you sure ?',
                    content:`<div style="text-align:left;">
                        <label>Description</label>
                        <textarea name="reject_reason" class="form-control" id="reject_reason"></textarea>
                    </div>`,
                    theme:'modern',
                    buttons:{
                        cancel:{
                            btnClass:'btn btn-warning',
                            text:'Cancel',
                            action:function () {

                            }
                        },
                        submit:{
                            btnClass:'btn btn-danger',
                            text:'Reject',
                            action:function () {
                                    window.location.replace('<?php echo e(route("construction-purchase.ceo_reject_ajust_po")); ?>?request_ajust_purchase_id='+request_ajust_purchase_id+"&&reject_reason="+$("#reject_reason").val());
                            }
                        },
                    },
                });
            });
        });
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>