@extends('adminlte::page') @section('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="#">Construction</a></li>
                <li><a href="#">CEO Approvals</a></li>
                <li><a href="#">Purchase Order</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>Purchase Order</h3>
                        </div>
                    </div>
                    <div class="pull-right">
                        <a class="button_sm button_info" href="javascript:void(0)" id="filter-toggle-search"><span class="fa fa-plus"></span>  Filter Toggle</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
            <div class="row" id="toggle-seaching">
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Request by :</strong>
                        {!! Form::text('prepare_by',null, array('class' => 'form-control')) !!}
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Supplier Name :</strong>
                        {!! Form::select('supplier_id',$supplers,null, array('class' => 'form-control select2')) !!}
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Project :</strong>
                        {!! Form::select('project',$projects,null, array('class' => 'form-control select2')) !!}
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Stock Position :</strong>
                        {!! Form::text('stock_position',null, array('class' => 'form-control')) !!}
                    </div>
                </div>
                <div class="col-md-12" style="text-align:right;margin-bottom:40px !important;">
                    <a class="button_sm button_success" href="javascript:void(0)" id="search-submit" onclick="searching()"><span class="fa fa-search"></span> Search</a>
                </div>
            </div>  
            <table id="datatable_purchase_order" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                <tr>
                    <th>NO</th>
                    <th>Date</th>
                    <th>Request By</th>
                    <th>Project</th>
                    <th>Supplier</th>
                    <th>Phone</th>
                    <th>Stock Position</th>
                    <th>Amount</th>
                    <th>Status</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>

        </div>
    </div>

@endsection
@section('js')
    <script type="text/javascript">
            function searching(){
                $("#datatable_purchase_order").DataTable().draw(true);
            }
            let table = $('#datatable_purchase_order').DataTable({
                ordering: false,
                "serverSide": true,
                "scrollY":"600px",
                "scrollCollapse": true,
                "scrollX": true,
                "lengthMenu": [
                    [20, 25, 50, 100, 500],
                    [20, 25, 50, 100, 500]
                ],
                ajax: {
                    url:"{{ route('construction-purchase.ceo_approval_index') }}",
                    type:"GET",
                    data:function(d){
                        d.request_name = $("input[name=prepare_by]").val();
                        d.supplier_id = $("select[name=supplier_id]").val();
                        d.stock_position = $("input[name=stock_position]").val();
                        d.project_id = $("select[name=project]").val();
                    },
                },
                columns: [
                    {data: 'DT_RowIndex'},
                    {data: 'date'},
                    {data: 'request_by'},
                    {data: 'project_name'},
                    {data: 'supplier_id'},
                    {data: 'phone_number'},
                    {data: 'stock_position'},
                    {data: 'amount'},
                    {data: 'status'},
                    {data: 'action'},
                ],
                "initComplete": function (settings, json) {
                    $('#main-spinner').hide();
                }
            });

            $.fn.dataTable.ext.errMode = 'throw';
        
        function display_form_approval(purchase_id)
        {
            $.confirm({
                title:'Are you sure ?',
                content:'',
                theme:'modern',
                buttons:{
                    cancel:{
                        btnClass:'btn btn-warning',
                        text:'Cancel',
                        action:function () {

                        }
                    },
                    submit:{
                        btnClass:'btn btn-success',
                        text:'Approve',
                        action:function () {
                                window.location.replace('{{route("construction-purchase.ceo_approval_store")}}?purchase_id='+purchase_id);
                        }
                    },
                },
            });
        }

        function display_reject(purchase_id)
        {
            $.confirm({
                title:'Are you sure ?',
                content:''+'<form action="" class="formName">' +
                                '<div class="form-group" style="text-align:left;">' +
                                    '<label>Description</label>' +
                                    '<textarea type="text" placeholder="Description" class="description form-control"></textarea>' +
                                '</div>' +
                            '</form>',
                theme:'modern',
                buttons:{
                    cancel:{
                        btnClass:'btn btn-warning',
                        text:'Cancel',
                        action:function () {

                        }
                    },
                    submit:{
                        btnClass:'btn btn-danger',
                        text:'Reject',
                        action:function () {
                            var description = this.$content.find('.description').val();
                            window.location.replace('{{route("construction-purchase.ceo_reject_store")}}?purchase_id='+purchase_id+'&description='+description);
                        }
                    },
                },
            });
        }

    </script>
@endsection