
<?php $__env->startSection('title','Edit Journal Entry'); ?>
<?php $__env->startSection('main'); ?>
<div class="container d-flex justify-content-center mt-3">    
    <div class="card text-left" style="width: 50rem;">
        <div class="card-header">
            Edit Record
        </div>
        
        <form action="<?php echo e(url('/journal/update')); ?>/<?php echo e($record->id); ?>" method="post">

                <?php echo csrf_field(); ?>
        
        <div class="card-body">
            <h5 class="card-title pb-2">Journal Entry</h5>
                <div class="row g-1">
                    <div class="col-6">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Date:</span>
                          </div>
                              <input type="date" value="<?php if(isset($record->jv_date)): ?><?php echo e($record->jv_date); ?><?php else: ?> <?php echo e(now()->format('Y-m-d')); ?> <?php endif; ?>" class="form-control" name="date" placeholder="Enter Your Date Here">
                                <span class="text-danger">
                                    <?php $__errorArgs = ['date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <?php echo e($message); ?>

                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </span>
                        </div>

                    </div>
                    <div class="col-1">
                        <input type="text" id="projectid" name="projectid" value="<?php echo e($record->project_id); ?>" class="form-control" placeholder="type id here">                    
                    </div>
                    <div class="col-5">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Project:</span>
                          </div>
                          <select class="form-control m-bot15" id="project_name" name="project_name">
                        <option value=" <?php echo e($record->project_name); ?>" selected><?php echo e($record->project_name); ?></option>

                        <?php $__currentLoopData = $projectdata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option data-id="<?php echo e($data->id); ?>" value="<?php echo e($data->project_name); ?>"><?php echo e($data->project_name); ?></option> 
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <span class="text-danger">
                            <?php $__errorArgs = ['projectid'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <p>Please select your Project</p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </span>
                        </div>
                        
                    </div>
                </div>
            
                <div class="row g-1 pt-2">
                    <div class="col-1">
                    <input type="text" id="headercode" value=" <?php echo e($record->header_code); ?>" name="headercode" class="form-control ">
                    </div>
                    <div class="col-1">
                    <input type="text" id="accountid" value=" <?php echo e($record->account_id); ?>" name="accountid" class="form-control ">
                    </div>
                    <div class="col-4">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Account:</span>
                          </div>
                           <select class="form-control " id="account_name" name="account_name" >
                        <option value=" <?php echo e($record->account_name); ?>" selected> <?php echo e($record->account_name); ?></option>
                        <?php $__currentLoopData = $accountdata; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option data-accountid="<?php echo e($data->account_id); ?>" data-headercode="<?php echo e($data->header_code); ?>" value="<?php echo e($data->account_name); ?>"><?php echo e($data->account_name); ?></option> 
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <span class="text-danger">
                            <?php $__errorArgs = ['accountid'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <p>Please select your Account</p>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </span>
                         </div>
                       
                    </div>
                    <div class="col-6">
                    <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Description:</span>
                          </div>
                        <textarea class="form-control" name="desc" id="exampleFormControlTextarea1" rows="1"><?php echo e($record->description); ?></textarea>
                    </div>
                    
                    </div>
                    
                </div>
                <div class="row g-1 pt-2">
                    <div class="col-6">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Debit:</span>
                          </div>
                          <input type="text" class="form-control form-control-sm" value=" <?php echo e($record->debit); ?>" name="debit">
                        </div>
                     </div>
                     <div class="col-6">
                        <div class="input-group mb-3">
                          <div class="input-group-prepend">
                            <span class="input-group-text" id="basic-addon1">Credit:</span>
                          </div>
                          <input type="text" class="form-control form-control-sm" value=" <?php echo e($record->credit); ?>" name="credit">
                         </div>
                     </div>
                    

                    
                </div>                
            
        </div>
        <div class="card-footer">
        
            <button type="submit" class="btn btn-primary btn-sm">Save/Close</button>          
            <a href="<?php echo e(url('/journal/index')); ?>">
            <button type="button" class="btn btn-info btn-sm">Cancel/Close</button>        
            </a>
            
        </div>
        </form>  
    </div>
</div>


<script>


$('#project_name').change(function(){

    
     var selected = $(this).find('option:selected');    
     var projectid = selected.data('id');
     $('#projectid').val( projectid );


     //append into account dropdown start here
     var pid=jQuery(this).val();
            $.ajax({
                url: '<?php echo e(route("Pvoucher.accounts")); ?>',
                type: 'POST',
                data: 'projectid='+projectid+'&_token=<?php echo e(csrf_token()); ?>',

                success:function(result){
                    $('#account_name').html('<option value="">Select Your Account</option>');
                        $.each(result.accounts, function (key, value) {
                            $("#account_name").append('<option data-headercode="' + value.header_code + '" data-accountid="' + value.id + '" value="' + value.customer_name + '">' + value.customer_name + '</option>');
                        });


                }
            });
        //end 
    
});


$('#account_name').change(function(){
    var selected = $(this).find('option:selected');
    var headercode = selected.data('headercode');
    var selected = $(this).find('option:selected');
    var accountid = selected.data('accountid');

    $('#headercode').val( headercode );
    $('#accountid').val( accountid );
    //alert(headercode + accountid)

});


</script>




<?php $__env->stopSection(); ?>

<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/alameenb/public_html/resources/views/journal/edit.blade.php ENDPATH**/ ?>