@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="#">Manage Stock</a></li>
                <li><a href="#">Transfer Item</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>Transfer Item</h3>
                        </div>
                        <div class="pull-right">
                          <button type="button" class="btn btn-warning" id="btn-tra-by-project">By Project</button>
                          <button type="button" class="btn btn-primary" id="btn-tra-by-group">By Group</button>
                          <button type="button" class="btn btn-info" id="btn-tra-by-zoon">By Zoon</button>
                          <button type="button" class="btn btn-success" id="btn-tra-by-item">By Item</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="form-wrapper">
                    {!! Form::open(array('route' => 'transfer_item_store','method'=>'POST')) !!}
                    <div class="row" style="height: 30px !important;">
                      <input type="hidden" name="transfer_type" id="transfer-type">
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Project</label>
                            {!! Form::select('item_projectid',$projects,null, ['class' => 'form-control select2 project_id','required']) !!}
                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Item</label>
                            <select class="form-control select2 item_name" name="item_name">
                                <option value="" disabled selected>Please Choose</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-4 col-xs-12">
                            <label class="required">Transfer To</label>
                            {!! Form::select('transfer_to',$user,null, ['class' => 'form-control select2','required']) !!}
                        </div>
                        <div class="form-group col-sm-12 col-xs-12">
                            <label>Transfer Description</label>
                            {!! Form::textarea('transfer_des', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')) !!}
                        </div>
                        <div class="col-sm-12 col-xs-12">
                            <div class="form-group">
                                <button type="submit" class="button_sm button_primary pull-right"><span class="fa fa-save"></span> Save</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>

                    {!! Form::close() !!}
                </div>
            </div>
        </div>
    </div>

@endsection
@section('js')

    <script type="text/javascript">
        $(document).ready(function(){
          $("#transfer-type").val(1);
          $("#btn-tra-by-project").attr("class","btn btn-danger");
        });
        $(document).on('change','.project_id',function() {
            var project_id = $(this).val();
            $.ajax({
               url:"/realty/get_item_by_project_id/"+project_id,
               dataType:"json",
               data:{"item_projectid":project_id},
               success:function (data) {
                   $('.item_name').empty();
                   $('.item_name').append('<option value="0">All</option>');
                   var b=0;
                   $.each(data,function (i,val) {
                       b=1;
                       if(val != '')
                       {
                           $('.item_name').append('<option value="'+val.id+'">'+val.item_name+'</option>');
                       }
                   });
                   if(b==0){
                       $('.item_name').empty();
                       $('.item_name').append('<option value="">No Item Found</option>');
                   }
               },
               error:function (err) {
                   console.log(err);
               }
            });
        });
    </script>
@endsection