@extends('adminlte::page') @section('content')
@include("administrator.items.create_new_project")
@include("administrator.items.create_new_category")
<?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="#">Operation</a></li>
            <li><a href="#">Manage Product</a></li>
            <li><a href="#">Item</a></li>
            <li><a href="#">Create Condo</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>Create Item (Condo)</h3>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="form-wrapper">
                    {!! Form::open(array('route' => 'items.save_create_condo','method'=>'POST','enctype'=>'multipart/form-data')) !!}
                    @csrf
                    <div class="row" style="height: 30px !important;">
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Project ( <a href="javascript:void(0)" onclick="create_new_project()">Add New</a> )</label>
                            {!! Form::select('item_projectid', $projects, null, ['class' => 'form-control project_id select2 change_prefix_code change_group_house_code','required']) !!}
    
                        </div>
                        <div class="form-group col-sm-3 col-xs-12">
                            <label class="required">Category ( <a href="javascript:void(0)" onclick="create_new_category()">Add New</a> )</label>
                            {!! Form::select('category_type', $categories, null, ['class' => 'form-control category_id select2 change_prefix_code change_group_code','required']) !!}
                        </div>
                        <!-- <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Group Item</label>
                            {!! Form::select('item_groupid', $item_group, null, ['class' => 'form-control group_id select2','required']) !!}

                        </div> -->
                        {!! Form::hidden('item_name', null, array('placeholder' => 'Prefix Code','class' => 'form-control profix_code','id'=>'profix_code')) !!}
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Prefix Code Start From</label>
                            {!! Form::text('code_start_from', null, array('placeholder' => 'Prefix Code Start From','class' => 'form-control code_start_from','readonly')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Block Time</label>
                            {!! Form::text('item_block_time', null, array('placeholder' => 'Block Time : 4...','class' => 'form-control number-only')) !!}

                        </div>

                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Title</label>
                            {!! Form::text('item_title', null, array('placeholder' => 'Title','class' => 'form-control item_title','required')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label >Item Cost</label>
                            {!! Form::text('item_cost', 0, array('placeholder' => 'Item Cost','class' => 'form-control sale_price number-only','required')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Sale Price</label>
                            {!! Form::text('item_price', null, array('placeholder' => 'Sale Price','class' => 'form-control price number-only','required')) !!}

                        </div>


                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Floor Area (m<sup>2</sup>)</label>
                            {!! Form::text('item_size', null, array('placeholder' => 'Size','class' => 'form-control size_house number-only','required','id'=>'size_house')) !!}

                        </div>

                        <div class="form-group col-sm-3 col-xs-12">

                            <label for="">Number of Bedroom</label>
                            {!! Form::text('item_bedroom', null, array('placeholder' => 'Number of Bedroom','class' => 'form-control item_bedroom number-only')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">
                            <label for="">Number of Bathroom</label>
                            {!! Form::text('item_bathroom', null, array('placeholder' => 'Number of bathroom','class' => 'form-control item_bathroom number-only')) !!}
                        </div>

                        <div class="form-group col-sm-3 col-xs-12">

                            <label for="">Sq FP</label>
                            {!! Form::text('item_sq_fp', null, array('placeholder' => 'Sq FP','class' => 'form-control item_sq_fp number-only')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label for="">Parking</label>
                            {!! Form::text('item_parking', null, array('placeholder' => 'Parking','class' => 'form-control item_parking number-only')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label for="">Floor</label>
                            {!! Form::text('item_floor', null, array('placeholder' => 'Number of floor','class' => 'form-control item_floor number-only')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Develop By</label>
                            {!! Form::text('item_develop_by', null, array('placeholder' => 'Develop By','class' => 'form-control item_develop_by')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Type</label>
                            {{ Form::select('item_type', ['Sales' => 'Sales', 'Rent' => 'Rent'],null, ['class' => 'form-control select2']) }}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="">Commission type</label>
                            {!! Form::select('commission_type', array('1'=>'Amount($)','2'=>" Percentage(%)"), null, ['class' => 'form-control select2 comm_type','']) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12 commission_amount_con">

                            <label class="commission_amount_con">Commission Amount($)</label>
                            {!! Form::text('commission_amount', 0, array('placeholder' => 'commission amount','class' => 'form-control commission_amount commission_amount_con number-only','id' => 'commission_amount commission_amount_con','')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12 commission_con">

                            <label class="commission_con">Commission(%)(/sale price)</label>
                            {!! Form::text('commission_percentage', 0, array('placeholder' => 'commission percentage','class' => 'form-control commission commission_con number-only','')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="">Commission Condition</label>
                            {!! Form::text('commission_condition', 0, array('placeholder' => 'commission condition','class' => 'form-control commission_condition number-only','')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Complatation</label>
                            {{ Form::select('item_omplatation', ['YES' => 'YES', 'NO' => 'NO'],null, ['class' => 'form-control select2']) }}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">
                            <label class="required">Prefix No </label><span class="text-danger">(A letter placed before another.)</span>
                            {!! Form::text('prefix_house', null, array('placeholder' => 'House Prefix Number','class' => 'form-control prefix_house')) !!}

                        </div>
                        <div class="form-group col-sm-3 col-xs-12">
                            <label class="required">Start No </label><span class="text-danger">( <input type="radio" name="start_house_type" value="3" id="even-id" checked> Odd or Even , <input type="radio" name="start_house_type" value="3" id="sequence-id" checked> Sequence )</span>
                            {!! Form::text('item_house', null, array('placeholder' => 'Start House Number','class' => 'form-control item_house number-only')) !!}
                        </div>
                        <div class="form-group col-sm-3 col-xs-12">

                            <label class="required">Number of Item </label><!-- <span class="text-danger">(we are allow create small than 161 Items)</span> -->
                            {!! Form::text('number_of_properties', null, array('placeholder' => 'Number of item','class' => 'form-control number_of_properties number-only')) !!}

                        </div>
                        <!-- <div class="col-xs-12 col-sm-12 col-md-12">
                            <div class="form-group">
                                <input id="file-1" type="file" name="gallery[]" multiple class="file" data-overwrite-initial="false" data-min-file-count="2">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </div>
                        </div> -->
                        <div class="col-xs-12 col-sm-12 col-md-12">
                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <div class="bgc-midnightblue padding5 fontc-white">
                                    <label class="checkbox-list">
                                        <input type="checkbox" class="" id="select_allb" value="checked" name="checkbox_1[]"> Check All
                                        <span class="checkmark"></span>
                                    </label>
                                </div>
                                <div class="form-group">
                                    @if(!$assessories->isEmpty()) @foreach($assessories as $value)
                                    <label class="checkbox-list">{{ Form::checkbox('accessory[]', $value->id, false, array('class' => 'name checkbox')) }} {{$value->title}}
                                        <span class="checkmark"></span>
                                    </label>
                                    @endforeach @endif
                                </div>

                            </div>
                        </div>
                        <div class="col-sm-12 form-group">

                            <label for="required">Description</label>
                            {!! Form::textarea('item_des', null, array('placeholder' => 'Description','class' => 'form-control summernote','rows'=>'2')) !!}

                        </div>
                        <div class="col-sm-12 col-xs-12 form-group">
                            <div class="form-group">
                                <input type="button" value="Generate" class="Generate button_warning pull-right">
                            </div>
                        </div>
                        <div class="col-sm-12 col-xs-12 generate_item">
                        <div class="row">
                            <div class="col-sm-1">
                                <label>Item Code</label>
                            </div>
                            {{--<div class="col-sm-1">--}}
                                {{--<label>Street No</label>--}}
                            {{--</div>--}}
                            <div class="col-sm-1">
                                <label>Condo No</label>
                            </div>
                            <div class="col-sm-1">
                                <label>Item Cost</label>
                            </div>
                            <div class="col-sm-1">
                                <label>Sale Price</label>
                            </div>
                            <div class="col-sm-2" id="com_am">
                                <label>commission($)</label>
                            </div>
                            <div class="col-sm-2" id="com_co">
                                <label>condition</label>
                            </div>
                            <div class="col-sm-1">
                                <label>Floor Area</label>
                            </div>
                            <div class="col-sm-1">
                                <label>Available</label>
                            </div>
                            <div class="col-sm-1">
                                <label>Remove</label>
                            </div>
                        </div>
                    </div>
                </div>

                {!! Form::close() !!}
            </div>
        </div>
    </div>
    </div>
    @endsection
    @section('js')
    <script type="text/javascript" src="{{asset('assets/controller/condo.js')}}"></script>
    <script type="text/javascript">
        $(document).on("submit","#form-create-category",function(e){
            e.preventDefault();
            var category_code = $("input[name=category_code]").val();
            var category_name = $("input[name=category_name]").val();
            var description = $(".create-new-category-des").val();
            var route = "{{ route('items.create_category') }}";
            $("#main-spinner").show();
            $.ajax({
                url:route,
                type:"POST",
                dataType:"JSON",
                data:{
                    "_token":"{{ csrf_token() }}",
                    category_code:category_code,
                    category_name:category_name,
                    description:description
                },
                success:function(data){
                    var opt = `<option value="${data.id}">${data.category_name}</option>`;
                    $(".category_id").html(opt);
                    $("#create-category").modal("hide");
                },
                complete:function(){
                    $("#main-spinner").hide();
                }
            });
        });
        function create_new_category(){
            $("#create-category").modal("show");
        }
        $(document).on("submit","#form-create-project",function(e){
            e.preventDefault();
            var project_code = $("input[name=project_code]").val();
            var project_name = $("input[name=project_name]").val();
            var branch_id = $("select[name=branch_id]").val();
            var description = $(".create-new-project-des").val();
            var route = "{{ route('items.create_new_project') }}";
            $("#main-spinner").show();
            $.ajax({
                url:route,
                type:"POST",
                dataType:"JSON",
                data:{
                    "_token":"{{ csrf_token() }}",
                    project_code:project_code,
                    project_name:project_name,
                    branch_id:branch_id,
                    description:description
                },
                success:function(data){
                    var opt = `<option value="${data.id}">${data.project_name}</option>`;
                    $(".project_id").html(opt);
                    $("#create-project").modal("hide");
                },
                complete:function(){
                    $("#main-spinner").hide();
                }
            });
        });
        
        function create_new_project(){
            $("#create-project").modal("show");
        }
        $(document).ready(function(){
            $(".commission_con").hide();
            $("#length_house").keyup(function(){
                var length_house = Number($(this).val());
                var width_house = Number($('#width_house').val());
                var total=width_house*length_house;
                $('#size_house').val(total);

            });
            $("#width_house").keyup(function(){
                var width_house = Number($(this).val());
                var length_house = Number($('#length_house').val());
                var total=width_house*length_house;
                $('#size_house').val(total);

            });

            $("#length_land").keyup(function(){
                var length_land = Number($(this).val());
                var width_land = Number($('#width_land').val());
                var total=width_land*length_land;
                $('#size_land').val(total);

            });
            $("#width_land").keyup(function(){
                var width_land = Number($(this).val());
                var length_land = Number($('#length_land').val());
                var total=width_land*length_land;
                $('#size_land').val(total);

            });
        });
        // $(document).on("change",".comm_type",function(){
        //
        //     var type=1;
        //     type=$(this).val();
        //     if(type==1)
        //     {
        //         $(".commission_amount_con").show();
        //         $(".commission_con").hide();
        //     }
        //     else{
        //         $(".commission_amount_con").hide();
        //         $(".commission_con").show();
        //     }
        // });
        // $(document).on("keyup",".commission_amount",function(){
        //     $(".commission").val(0);
        // });
        // $(document).on("keyup",".commission",function(){
        //     $(".commission_amount").val(0);
        // });



    </script>
    @endsection