 
<?php $__env->startSection('title', 'Form Components'); ?>
<?php $__env->startSection('content'); ?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css"/>  
  <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">  
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
  <link href='https://fonts.googleapis.com/css?family=Josefin Sans' rel='stylesheet'>
<?php
    $adminuserid = auth()->user()->id;
    $adminstatecode = auth()->user()->state_code;
    $admindistcode = auth()->user()->dist_code;
    $adminname = auth()->user()->name;
    $adminserialno = auth()->user()->serial_number;
    
    $uidarr = [];
    $matformdata = DB::table('master_fields_table')->where('form_name','=','mat_form')->where('section_name','=','main_section')->where('status','=','1')->get();
    
    $getuidmatintake = DB::table('mat_form_entry')->select('uidnum')->get();
    
    if(!empty($showdata))
    {
        $uidarr[] = $showdata[0]->uidnum;
    }
    
    foreach($getuidmatintake as $getuidmat){
        $uidarr[] = $getuidmat->uidnum;
    }
    $getsernodata = DB::table('client_register_form_entry')->where('catprimary','=','1) PWID')->whereNotIn('serialno', $uidarr)->where('formstatus','=','success')->get();
    echo count($uidarr);
    $hpnamelist = DB::table('mat_form_entry')->select('hostpotname')->groupBy('hostpotname')->get();
    
?>
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">
    
    <div class="container-fluid" style="font-family:'Josefin Sans';">
        <div class="page-header">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                        <i class="ik ik-edit bg-blue"></i>
                        <div class="d-inline">
                            <h5><?php echo e(__('MAT Intake Form')); ?></h5>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="<?php echo e(route('dashboard')); ?>"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item"><a href="#"><?php echo e(__('Forms')); ?></a></li>
                        </ol>
                    </nav>
                </div>
                <?php if(session()->has('errormsg')): ?>
                    <div class="alert alert-danger" style='margin-left: 1%;
    margin-top: 25px;'>
                        <?php echo e(session()->get('errormsg')); ?>

                    </div>
                <?php endif; ?>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <!--<div class="card-header"><h3><?php echo e(__('MAT Intake Form')); ?></h3></div>-->
                    <div class="card-body">
                        <form class="forms-sample" method='POST' <?php if(!empty($showdata)): ?> action='<?php echo e(url('updatemat')); ?>' <?php else: ?> action='<?php echo e(url('matinsert')); ?>' <?php endif; ?> name='matmaster'>
                            <?php echo csrf_field(); ?>
                            
                            <?php if(!empty($showdata)): ?>
                            <input type='hidden' name='matformid' value='<?php echo e($showdata[0]->id); ?>'>
                            <?php endif; ?>
                            
                            <div class="form-group">
                                <label for="uidnum"><?php echo e($matformdata[4]->questions); ?></label>
                                <select name='uidnum' id='uidnum' class='form-control' required>
                                    <option value=""><?php echo e(__('Select UID No')); ?></option>
                                    <?php if(!empty($showdata)): ?>
                                    <option class='uidnum' value='<?php echo e($showdata[0]->uidnum); ?>' selected><?php echo $showdata[0]->state_code.'-'.$showdata[0]->dist_code.'-' ?><?php echo e($showdata[0]->uidnum); ?></option>
                                    <?php endif; ?>
                                    <?php $__currentLoopData = $getsernodata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $getserno): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option class='uidnum' value='<?php echo e($getserno->serialno); ?>' <?php if(!empty($showdata)): ?> <?php echo e($showdata[0]->uidnum == $getserno->serialno ? 'selected' : ''); ?>  <?php endif; ?>><?php echo $getserno->state.'-'.$getserno->district.'-' ?><?php echo e($getserno->serialno); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <input type='hidden' name='clientregdate' id='clientregdate' value=''>
                            <div class="form-group">
                                <label for="dateofentry"><?php echo e($matformdata[0]->questions); ?></label>
                                <div class='input-group date datetimepicker' >
                                    <input type='text' id='matregdate' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->dateofentry); ?>' <?php endif; ?> class="form-control" name="dateofentry" placeholder="yyyy-mm-dd" required/>
                                    <span class="input-group-addon">
                                      <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                                <span id="check-date" style='color:red;'></span>
                            </div>
                            <div class="form-group">
                                <label for="state_code"><?php echo e($matformdata[1]->questions); ?></label>
                                <input style="text-transform: uppercase" type='text' class="form-control" name='state_code' id='state_code' value='<?php echo e($adminstatecode); ?>' readonly>
                            </div>
                            <div class="form-group">
                                <label for="dist_code"><?php echo e($matformdata[2]->questions); ?></label>
                                <input style="text-transform: uppercase" type='text' class="form-control" name='dist_code' id='dist_code' value='<?php echo e($admindistcode); ?>' readonly>
                            </div>
                            <div class="form-group">
                                <label for="reportingpname"><?php echo e($matformdata[3]->questions); ?></label>
                                <input style="text-transform: uppercase" type='text' class="form-control" name='reportingpname' value='<?php echo e($adminname); ?>' readonly>
                            </div>
                            <div class="form-group">
                                <label for="clientname"><?php echo e($matformdata[5]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="clientname" name='clientname' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->clientname); ?>' <?php } ?> placeholder="Enter Client Name" readonly>
                            </div>
                            <div class="form-group">
                                <label for="gender"><?php echo e($matformdata[6]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="gender" name='gender' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->gender); ?>' <?php } ?> readonly>
                            </div>
                            <div class="form-group">
                                <label for="age"><?php echo e($matformdata[7]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="age" name='age' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->age); ?>' <?php } ?> placeholder="Enter Age" readonly>
                            </div>
                            <div class="form-group">
                                <label for="kpgroup"><?php echo e($matformdata[8]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="kpgroup" name='kpgroup' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->kpgroup); ?>' <?php } ?> placeholder="Enter KP Group" readonly>
                            </div>
                            <div class="form-group">
                                <label for="typeofclient"><?php echo e($matformdata[9]->questions); ?></label>
                                <select style="text-transform: uppercase" name='typeofclient'  class='form-control' value=''>
                                    <option value=''><?php echo e(__('SELECT')); ?></option>
                                    <?php $typeofclients = explode('|',$matformdata[9]->answer); ?>
                                    
                                        <?php foreach($typeofclients as $typeofclient){ ?>
                                        <option style="text-transform: uppercase" value='<?php echo e($typeofclient); ?>' <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->typeofclient == $typeofclient)? "selected" : ""); ?> <?php endif; ?>><?php echo e($typeofclient); ?></option>
                                        <br>
                                        <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="hostpotname"><?php echo e($matformdata[10]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" list='hpname' class="form-control" id="hostpotname" name='hostpotname' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->hostpotname); ?>' <?php } ?>  required>
                                <datalist id="hpname">
                                    <?php foreach($hpnamelist as $hpnl){ ?>
                                        <option value="<?php echo $hpnl->hostpotname; ?>" ><?php echo $hpnl->hostpotname; ?></option>
                                    <?php } ?>
                                </datalist>
                            </div>
                            <div class="form-group">
                                <label for="ostinidate"><?php echo e($matformdata[11]->questions); ?></label>
                                <div class='input-group date datetimepicker' >
                                    <input type='text' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->ostinidate); ?>' <?php endif; ?> class="form-control" name="ostinidate" placeholder="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                      <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ostcname"><?php echo e($matformdata[12]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="ostcname" name='ostcname' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->ostcname); ?>' <?php } ?>  required>
                            </div>
                            <div class="form-group">
                                <label for="ostregno"><?php echo e($matformdata[13]->questions); ?></label>
                                <input style="text-transform: uppercase" type="text" class="form-control" id="ostregno" name='ostregno' <?php if(!empty($showdata)){ ?> value='<?php echo e($showdata[0]->ostregno); ?>' <?php } ?>  required>
                            </div>
                            <div class="form-group">
                                <label for="currentostc"><?php echo e($matformdata[14]->questions); ?></label>
                                <select style="text-transform: uppercase" name='currentostc' id='currentostc' class='form-control' value=''>
                                    <option value=''><?php echo e(__('SELECT')); ?></option>
                                    <?php $currentostcs = explode('|',$matformdata[14]->answer); ?>
                                    
                                        <?php foreach($currentostcs as $currentostc){ ?>
                                        <option style="text-transform: uppercase" value='<?php echo e($currentostc); ?>' <?php if(!empty($showdata)): ?><?php echo e(($showdata[0]->currentostc == $currentostc)? "selected" : ""); ?> <?php endif; ?>><?php echo e($currentostc); ?></option>
                                        <br>
                                        <?php } ?>
                                </select>
                            </div>
                            <div class="form-group q8">
                                <label for="lstatusdate"><?php echo e($matformdata[16]->questions); ?></label>
                                <div class='input-group date datetimepicker' >
                                    <input type='text' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->dropoutdate); ?>' <?php endif; ?> class="form-control" id="dropoutdate" name="dropoutdate" placeholder="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                      <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="lstatusdate"><?php echo e($matformdata[15]->questions); ?></label>
                                <div class='input-group date datetimepicker' >
                                    <input type='text' <?php if(!empty($showdata)): ?> value='<?php echo e($showdata[0]->lstatusdate); ?>' <?php endif; ?> class="form-control" name="lstatusdate" placeholder="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                      <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                            
                            <br><br>
                            <button type="submit" class="btn btn-primary mr-2"><?php echo e(__('Submit')); ?></button>
                            <?php if(empty($showdata)): ?>
                            <a href='<?php echo e('mat-form'); ?>' class="btn btn-light"><?php echo e(__('Cancel')); ?></a>
                            <?php endif; ?>
                          </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>

    <script type="text/javascript">
        $(function() {
            var default_date=  new Date();
            $('.datetimepicker').datetimepicker({  
               format: 'YYYY-MM-DD', 
                useCurrent:false, 
                maxDate: new Date(),
                defaultDate: default_date
            });
            
            $(".q8").hide();
            var currentostc = $("#currentostc option:selected").val();
            if(currentostc == "Dropped Out" || currentostc == "Transferred Out" || currentostc == "Imprisonment")
            {
                $(".q8").show();
            }
            else
            {
                $(".q8").hide();
            }
        });
        
        $('#uidnum').on("change",function(){
            var uidnumber = $("#uidnum option:selected").val();
            // alert(dataid);
            
            $.ajax({
                type: "POST",
                url: "<?php echo e(url('getuidnumberdata')); ?>",
                data: {uidnumber:uidnumber, _token: '<?php echo e(csrf_token()); ?>' },
                dataType: "json",
                success: function(data) { 
                    //console.log(data.serialdata);
                    console.log(data.serialdata[0]['catprimary']);
                    $('#state_code').val(data.serialdata[0]['state']);
                    $('#dist_code').val(data.serialdata[0]['district']);
                    $('#clientname').val(data.serialdata[0]['clientname']);
                    $('#gender').val(data.serialdata[0]['gender']);
                    $('#age').val(data.serialdata[0]['age']);
                    $('#kpgroup').val('1) PWID');
                    
                    $('#typeofclient').val(data.serialdata[0]['enrollintarget']);
                    $('#clientregdate').val(data.serialdata[0]['registerdate']);
                },
                error: function (jqXHR, exception) {
    
                }
            });
        });
        
        $('#currentostc').on("change",function(){
            var currentostc = $("#currentostc option:selected").val();
            if(currentostc == "Dropped Out" || currentostc == "Transferred Out" || currentostc == "Imprisonment")
            {
                $(".q8").show();
            }
            else
            {
                $(".q8").hide();
            }
        });
        
        $( "#matregdate" ).blur(function() { 
            var regdate = $('#clientregdate').val();
            var matregdate = $('#matregdate').val();
            
            var d1 = new Date(regdate);
            var d2 = new Date(matregdate);
            
            // console.log(d1.getTime() > d2.getTime())
            if(d1.getTime() > d2.getTime()){
                $('#check-date').text('Data Entry date can not be lesser then client registration date');
                $('#matregdate').val('');
            }else{
                $('#check-date').text('');
            }
        });
        
        
    </script> 
    
    <!-- push external js -->
    <?php $__env->startPush('script'); ?>
        <script src="<?php echo e(asset('js/form-components.js')); ?>"></script>
    <?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/viruxyz/public_html/ejaf/resources/views/pages/mat-form.blade.php ENDPATH**/ ?>