

<?php $__env->startSection('title'); ?>
    Commission Receivables
<?php $__env->stopSection(); ?>

<?php $__env->startSection('style'); ?>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('/css/jsteps/normalize.css')); ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('/css/jsteps/jquery.steps.css')); ?>">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/select2@4.0.12/dist/css/select2.min.css" rel="stylesheet" />

    <style>
        .select2{
            width: 100% !important;
        }
        .select2-container, .select2-dropdown, .select2-search, .select2-results {
        -webkit-transition: none !important;
        -moz-transition: none !important;
        -ms-transition: none !important;
        -o-transition: none !important;
        transition: none !important;
        }
        /*.wizard > .content {
            min-height: 0;
        }*/
        /*.wizard > .content > .body {
            height: auto;
        }*/

        .wizard > .content
        {
            background: #eee;
            display: block;
            margin: 0.5em;
            min-height: 50em!important; /*50em;*/
            overflow: hidden;
            position: relative;
            width: auto;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
        }

        /*.datetimepicker1{ z-index:99999 !important; }*/

        .dataTables_scroll
        {
            overflow:auto;
        }

        th, td {
            white-space: nowrap;
        }

        tbody {
            height: 75px;
            overflow-y: auto;
            overflow-x: hidden;
        }

    </style>

    <style>
        /*body{width:615px;}*/
        .tbl-qa{width: 98%;font-size:0.9em;background-color: grey;}
        .tbl-qa th.table-header {text-align: left;padding:10px;color: #FFFFFF;}
        .tbl-qa .table-row td {padding:10px;background-color: #FDFDFD;}
        .ajax-action-links {color: #09F; margin: 10px 0px;cursor:pointer;}
        .ajax-action-button {border:#094 1px solid;color: #09F; margin: 10px 0px;cursor:pointer;display: inline-block;padding: 10px 20px;}
    </style>
    <style>
        .modal1  {
            padding-right: 0px;
            background-color: rgba(4, 4, 4, 0.8);
        }
        .modal-dialog1 {
            top: 20%;
            width: 70%;
            /*text-align: center;*/
            
        }
        .modal-content1 {
            border-radius: 0px;
            border: none;
            top: 40%;
        }
        .modal-body1 {
            background-color: #0f8845;
            color: white;
        }
        table.dataTable tr.odd { background-color: #E2E4FF; }
        table.dataTable tr.even { background-color: white; }
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" >
        <?php if($errors->count() > 0): ?>
            <p>The following errors have occurred:</p>
            <ul>
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $message): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <li><?php echo e($message); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        <?php endif; ?>
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-bookmark-o"></span> Receivable
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-bookmark-o"></i> Admin Panel</a></li>
                <li class="active"> Receivable</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 20%;">
            <div class="page-header">
                <a href="<?php echo e(route('receivables')); ?>" class="btn btn-primary"><i class="fa fa-backward"></i> Back</a>
            </div>

           <form id="frmReceive" method="post" action="<?php echo e(route('receivables.update')); ?>" role="form">
                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
                <input type="hidden" id="id_" name="id_" value="<?php echo e($rcvd[0]->rcvd_id); ?>" readonly>
                <div class="form-group">
                    <h3>Receiving Details</h3>
                    <section>
                   
                    <div class="col-md-3">
                        <div class="form-group" style="text-align: left;background:rgba(0,0,0,0);border:none;" id="">
                            <span id="">Client Name : <span class="label label-warning"><?php echo e($rcvd[0]->client_name?? ''); ?></span></span><br>
                            <span id="">Developer   : <?php echo e($rcvd[0]->dev_name ?? ''); ?></span><br>
                            <span id="">Project     : <?php echo e($rcvd[0]->prj_name ?? ''); ?></span><br>
                            <span id="">Blk <?php echo e($rcvd[0]->blk ?? ''); ?> / Lot <?php echo e($rcvd[0]->lot ?? ''); ?></span>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group" style="text-align: left;background:rgba(0,0,0,0);border:none;" id="">
                              <span id="">Selling Price : <?php echo e(number_format($rcvd[0]->net_selling_price, 2) ?? 0); ?></span><br>
                              <span id="">Agent : <span class="label label-primary"><?php echo e($rcvd[0]->agent_name ?? ''); ?></span></span><br>
                              <span id="">Created By : <?php echo e($rcvd[0]->user_name ?? ''); ?></span><br>
                              <span id="">Created At    : <?php echo e(date("d-M-Y", strtotime($rcvd[0]->created_at))); ?></span><br>
                        </div>

                        <div>
                            <?php if($rcvd[0]->sale_status == 'Active'): ?>
                                Status : <span id="sp_status"><span class="label label-success" style="font-size:14px;"><?php echo e($rcvd[0]->sale_status); ?></span></span>
                            <?php else: ?>
                                Status : <span id=""><span class="label label-warning" style="font-size:14px;"><?php echo e($rcvd[0]->sale_status); ?></span></span>
                            <?php endif; ?>
                        </div>
                        
                    </div>

                    <div class="col-md-3">
                        <div class="form-group" style="text-align: left;background:rgba(0,0,0,0);border:none;padding:5px;">
                            <span>Total Received from Developer</span><br><br>
                            <label for="" class="control-label">Manager Total Receivables :</label><span id="m_ttl_rcvd"><?php echo e(number_format($sale_comm->um_com_rate,2) ?? 0); ?></span><br>
                            <label for="" class="control-label">Manager Total to Release :</label><span id="m_ttl_rls"><?php echo e(number_format((float) $ttl_release_mgr ?? 0, 2) ?? 0); ?></span><br>
                            <span>Manager Comm Rate:  <?php echo e(number_format($sale_comm->um_pcg_rate,0) ?? 0); ?>%</span><br>
                            <span>Remaining Receivables : <?php echo e(number_format($u_rem_rcvd,2) ?? 0); ?></span><br>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group" style="text-align: left;background:rgba(0,0,0,0);border:none;" id="">
                            
                            <span>0.00</span><br><br>
                            <label for="" class="control-label">Agent Total Receivables :</label><span id="a_ttl_rcvd"><?php echo e(number_format($sale_comm->agent_com_rate,2) ?? 0); ?></span><br>
                            <label for="" class="control-label">Agent Total to Release :</label><span id="a_ttl_rls"><?php echo e(number_format((float) $rls_release,2) ?? 0); ?></span><br>
                            <span>Agent Comm Rate:  <?php echo e(number_format($sale_comm->agent_pcg_rate,0) ?? 0); ?>%</span><br>
                            <?php if($a_rem_rcvd < 0): ?>
                                <span>Remaining Receivables : 0.00</span><br>
                            <?php else: ?>
                                <span>Remaining Receivables :<?php echo e(number_format($a_rem_rcvd,2) ?? 0); ?></span><br>
                            <?php endif; ?>
                            
                        </div>
                        
                        <input type="hidden" name="cnt_amount" id="cnt_amount" class="form-control" value="<?php echo e(number_format((float) $contract_amount, 2) ?? 0); ?>" style="text-align: right" readonly>
                        <input type="hidden" name="ttl_release" id="ttl_release" class="form-control" value="<?php echo e(number_format((float) $rls_release, 2) ?? 0); ?>" style="text-align: right" readonly>
                        <input type="hidden" name="ttl_receive" id="ttl_receive" class="form-control" value="<?php echo e(number_format((float) $ttl_receive, 2) ?? 0); ?>" style="text-align: right" readonly>
                        <input type="hidden" name="max_release" id="max_release" class="form-control" value="<?php echo e(number_format( $max_rls, 2) ?? 0); ?>" style="text-align: right" readonly>
                    </div>

                    <div style="padding-top:80px;"></div>

                    <div class="col-md-12">
                        <div class="form-group has-feedback <?php if($errors->has('remarks')): ?> has-error <?php endif; ?>">
                            <label for="remarks" class="control-label">Remarks:</label>
                            <textarea class="form-control txt" rows="2" name="remarks" id="remarks" placeholder=""><?php echo e($rcvd[0]->remarks ?? ''); ?></textarea>
                            <?php if($errors->has('remarks')): ?> <span class="help-block"><?php echo e($errors->first('remarks')); ?></span> <?php endif; ?>
                        </div>
                    </div>

                    <div style="padding-top:70px;"></div>

                    <div class="col-md-12"></div>
                    <button type="button" id="addMore" name="addMore" class="btn btn-success btn-s" data-toggle="modal" data-target="#addModal"><i class="fa fa-plus"></i> Add More</button>
                    <div style="float:right;">
                        <a href="<?php echo e(route('reports.releases.vouchers', $rcvd[0]->rcvd_id)); ?>" class="btn btn-primary btn-s"><i class="fa fa-search"></i> Release Voucher</a>
                    </div>
                    
                    <div style=""></div>
                    <br>
                        <table class="table table-hover" id="gross-table" width="100%">
                           <thead>
                           <tr style="background: grey ;color:#fff; font-weight: bold">
                               <th class="table-header" hidden>No</th>
                               <th class="table-header" width="8%" style="text-align: center">No</th>
                               <th class="table-header" width="10%" >Date</th>
                               <th class="table-header" width="20%" style="text-align: center">Pay Mode</th>
                               <th class="table-header" width="12%" style="text-align: center">Amount</th>
                               <th class="table-header" width="20%" style="text-align: center">User</th>
                               <th class="table-header" width="10%" style="text-align: center">Release</th>
                               <th class="table-header" width="12%" style="text-align: center">Actions</th>
                           </tr>
                           </thead>
                           <tbody id="table-body">
                            <?php if(isset($grs)): ?>
                               <?php $__currentLoopData = $grs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $g): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                 <tr class="table-row" id="table-row-<?php echo e($g->id); ?>">
                                   <td hidden>
                                       <?php echo e($g->id); ?>

                                   </td>
                                   <td width="8%" style="text-align: center">
                                       <?php echo e($loop->index+1); ?>

                                   </td>
                                   <td width="15%">
                                       <div class='input-group'> 
                                           <input type='text' class="form-control" id="rcvd_date" name="rcvd_date" value="<?php echo e(date("m/d/Y", strtotime($g->rcvd_date))); ?>"  />
                                           <span class="input-group-addon">
                                               <span class="glyphicon glyphicon-calendar"></span>
                                           </span>
                                       </div>
                                   </td>
                                   <td width="20%" style="text-align: center"><?php echo e($g->pay_mode); ?></td>
                                   <td width="15%" style="text-align: right"><?php echo e(number_format($g->amount,2)); ?></td>
                                   <td width="20%" style="text-align: center"><?php echo e($g->user->full_name); ?></td>
                                   <td width="10%" style="text-align: center">
                                        <?php if($g->is_released == 1): ?>
                                            <span class="label label-success">Yes</span>
                                        <?php else: ?>
                                            <span class="label label-default">No</span>
                                        <?php endif; ?>
                                   </td>
                                   
                                   <td style="text-align: center"><a href="#" data-toggle="modal" id="<?php echo e($g->id); ?>" data-target="#e<?php echo e($g->id); ?>" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> </a>

                                   
                                   <div class="modal fade editModal" id="e<?php echo e($g->id); ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                       <div class="modal-dialog" role="document">
                                           <form method="post" action="">
                                               <div class="modal-content">
                                                   <div class="modal-header">
                                                       <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                       <h4 class="modal-title" id="myModalLabel">Edit Gross Release Info - <?php echo e($g->id); ?></h4>
                                                   </div>
                                                   <div class="modal-body text-left">
                                                       <input type="hidden" id="id" name="id" value="<?php echo e($g->id); ?>">
                                                       <div class="form-group">
                                                           <label for="rcvd_date2" class="control-label">Date</label>
                                                            <div class="input-group date datetimepicker1">
                                                               <input type='text' class="form-control" id="rcvd_date2" name="rcvd_date2" value="<?php echo e(date("m/d/Y", strtotime($g->rcvd_date))); ?>" />
                                                               <span class="input-group-addon">
                                                                   <span class="glyphicon glyphicon-calendar"></span>
                                                               </span>
                                                            </div>
                                                       </div>
                                                       <div class="form-group">
                                                           <label for="pay_mode" class="control-label">Payment Mode</label>
                                                           <select name="pay_mode" id="pay_mode" class="form-control">
                                                               <option value="">Select Paymode</option>
                                                               <?php $__currentLoopData = $paymode; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                   <?php if($g->pay_mode == $pm): ?>
                                                                       <option value="<?php echo e($pm); ?>" selected="selected"><?php echo e($pm); ?></option>
                                                                  <?php else: ?>
                                                                       <option value="<?php echo e($pm); ?>"> <?php echo e($pm); ?> </option>
                                                                  <?php endif; ?>
                                                               <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                           </select>
                                                       </div>
                                                       <div class="form-group">
                                                           <label for="rls_amount" class="control-label">Release Amount</label>
                                                           <input value="<?php echo e($g->amount); ?>" type="number" name="rls_amount" id="rls_amount" class="form-control" style="text-align: right" min="1" step="0.1">
                                                       </div>
                                                       <div class="form-group">
                                                           <label for="particulars" class="control-label">Particulars</label>
                                                           <textarea class="form-control txt" rows="3" name="particulars" id="particulars" placeholder=""><?php echo e($g->particulars); ?></textarea>
                                                       </div>
                                                   </div>
                                                   <div class="modal-footer">
                                                       <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                       <button type="button" id="itemUpdate" name=itemUpdate class="btn btn-primary" data-dismiss="modal">Update</button>
                                                       
                                                   </div>
                                               </div>
                                               <?php echo e(csrf_field()); ?>

                                           </form>
                                       </div>
                                   </div>

                                    
                                    <a href="#" data-toggle="modal" id="<?php echo e($g->id); ?>" name="" onclick="remLine(this.id)" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>

                                    </td>
                                 </tr>
                               <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php else: ?>

                            <?php endif; ?>
                            </tbody>
                             
                           </table>

                    </section>

                    <h3>Releases</h3>
                    <section>
                        <div class="col-md-12">
                            
                            
                            <!--<div class="table-responsive"></div>--><!--style="height:10px;"-->
                            <table class="table table-hover" id="releases_table" width="100%">
                                <thead>
                                    <tr style="background: grey ;color:#fff; font-weight: bold">
                                        
                                        <td width="8%">ID</td>
                                        <td width="10%">Received Date</td>
                                        
                                        <td width="20%">Client</td>
                                        <td width="15%" style="text-align: center">Agent</td>
                                        <td width="15%" style="text-align: center">Unit Manager</td>
                                        <td width="10%" style="text-align: center">Amount</td>
                                        <td width="10%">Release</td>
                                        <td width="10%">Actions</td>
                                    </tr>
                                </thead>
                                <?php if(isset($releases)): ?>
                                    <?php $__currentLoopData = $releases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $release): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        
                                        <td width="8%"><?php echo e($release->gr_id); ?></td>
                                        <td width="20%"><?php echo e(date("d-M-Y", strtotime($release->created_at))); ?></td>
                                        
                                        <td width="20%"><?php echo e($release->client_name); ?></td>
                                        <td width="15%"><?php echo e($release->agent_name); ?></td>
                                        <td width="15%"><?php echo e($release->um_name); ?></td>
                                        <td width="10%"style="text-align: right"><?php echo e(number_format($release->amount,2)); ?></td>
                                        <td width="10%"style="text-align: center">
                                            <?php if($release->is_released == 1): ?>
                                                <span class="label label-success">Yes</span>
                                            <?php else: ?>
                                                <span class="label label-warning">No</span>
                                            <?php endif; ?>
                                        </td>
                                        <td class="" style="text-align: center" width="10%">
                                            <?php if($release->is_released == 0): ?>
                                                
                                                
                                            <?php else: ?>
                                                
                                                
                                                
                                                <a href="<?php echo e(route('releases.editt',[$release->gr_id])); ?>" class="btn btn-default btn-xs"><i class="fa fa-edit"></i> Edit</a>
                                            <?php endif; ?>
                                            <?php if($release->is_released == 1): ?>
                                                
                                            <?php else: ?>
                                                <a href="<?php echo e(route('releases.new',[$release->gr_id, $release->rcvd_id])); ?>" class="btn btn-success btn-xs"><i class="fa fa-bolt"></i> Release</a>
                                                
                                            <?php endif; ?>
                                            
                                            
                                            <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                                <div class="modal-dialog" role="document">
                                                    <form method="post" action="<?php echo e(route('releases.update')); ?>">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                                <h4 class="modal-title" id="myModalLabel2">Edit Release Commission - <?php echo e($release->gr_id); ?></h4>
                                                            </div>

                                                            <div class="modal-body text-left">
                                                                <input type="hidden" id="gl_id" name="gl_id" value="<?php echo e($release->gr_id); ?>">
                                                                <input type="hidden" id="rcvd_id" name="rcvd_id" value="<?php echo e($release->rcvd_id); ?>">
                                                                <input type="hidden" id="comm_amount" name="comm_amount" value="<?php echo e($release->amount); ?>">

                                                            <div style="padding-top:10px;"></div>

                                                            <div class="col-md-12">
                                                                <div class="form-group">
                                                                    <label for="agent_id" class="control-label">Agent Name : </label>
                                                                    <input type="hidden" id="agent_id" name="agent_id" value="<?php echo e($release->agent_id); ?>">
                                                                    <span class="label label-success"><?php echo e($release->agent_name); ?></span>
                                                                    <?php if($errors->has('agent_id')): ?> <span class="help-block"><?php echo e($errors->first('agent_id')); ?></span> <?php endif; ?>
                                                                </div>
                                                                <div class="form-group has-feedback <?php if($errors->has('umanager_id')): ?> has-error <?php endif; ?>">
                                                                    <?php $__currentLoopData = $ums; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $um): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php if($release->unit_manager_id == $um->id): ?>
                                                                            <label for="umanager_id" class="control-label">Unit Manager : </label>
                                                                            <input type="hidden" id="umanager_id" name="umanager_id" value="<?php echo e($release->unit_manager_id); ?>">
                                                                            <span class="label label-default"><?php echo e($um->fullname); ?></span>
                                                                        <?php endif; ?>
                                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($errors->has('umanager_id')): ?> <span class="help-block"><?php echo e($errors->first('umanager_id')); ?></span> <?php endif; ?>
                                                                </div>
                                                                <div class="form-group">
                                                                    <?php $__currentLoopData = $agents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $agent): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php if($release->referrer_id == $agent->id): ?>
                                                                            <label for="referrer_id" class="control-label">Referrer : </label>
                                                                            <input type="hidden" id="referrer_id" name="referrer_id" value="<?php echo e($release->referrer_id); ?>">
                                                                            <span class="label label-default"><?php echo e($agent->fullname); ?></span>
                                                                        <?php else: ?>

                                                                       <?php endif; ?>
                                                                   <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                                    <?php if($errors->has('referrer_id')): ?> <span class="help-block"><?php echo e($errors->first('referrer_id')); ?></span> <?php endif; ?>
                                                                </div>

                                                                <div class="form-group">
                                                                    <label for="remarks" class="control-label">Remarks:</label>
                                                                    <textarea class="form-control txt" rows="2" name="remarks" id="remarks" placeholder="" required></textarea>
                                                                    <?php if($errors->has('remarks')): ?> <span class="help-block"><?php echo e($errors->first('remarks')); ?></span> <?php endif; ?>
                                                                </div>

                                                                <?php $__currentLoopData = $share; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sh): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <div class="form-group">
                                                                        <div class="editor-label">
                                                                            <label for="agent_pcg_rate">Agent Share %</label>
                                                                        </div>
                                                                        <div class="editor-field">
                                                                            <input type="number" name="agent_pcg_rate" id="agent_pcg_rate" value="<?php echo e($sh->shr_agent); ?>" class="form-control "/>

                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group">
                                                                        <div class="editor-label">
                                                                            <label for="um_pcg_rate">Unit Manager Share %</label>
                                                                        </div>
                                                                        <div class="editor-field">
                                                                            <input type="number" name="um_pcg_rate" id="um_pcg_rate" value="<?php echo e($sh->shr_um); ?>" class="form-control comm_rate" />
                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group">
                                                                        <div class="editor-label">
                                                                            <label for="broker_pcg_rate">Broker Share %</label>
                                                                        </div>
                                                                        <div class="editor-field">
                                                                            <input type="number" name="broker_pcg_rate" id="broker_pcg_rate" value="<?php echo e($sh->shr_broker); ?>" class="form-control comm_rate" />
                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group">
                                                                        <div class="editor-label">
                                                                            <label for="referrer_pcg_rate">Referrer Share %</label>
                                                                        </div>
                                                                        <div class="editor-field">
                                                                            <input type="number" name="referrer_pcg_rate" id="referrer_pcg_rate" value="<?php echo e($sh->shr_refer); ?>" class="form-control comm_rate" />
                                                                        </div>
                                                                    </div>

                                                                    <div class="form-group">
                                                                        <div class="editor-label">
                                                                            <label for="tax">Tax %</label>
                                                                        </div>
                                                                        <div class="editor-field">
                                                                            <input type="number" name="tax" id="tax" value="<?php echo e($sh->tax); ?>" class="form-control" />
                                                                        </div>
                                                                    </div>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                                <div class="form-group ">
                                                                    <div class="editor-label">
                                                                        <label for="ca_amount">Agent C/A Payment</label>
                                                                    </div>
                                                                    <div class="editor-field">
                                                                        <input type="number" name="ca_amount" id="ca_amount" value="0.00" class="form-control"/>
                                                                    </div>
                                                                </div>

                                                                <div class="form-group ">
                                                                    <div class="editor-label">
                                                                        <label for="um_ca_amount">Unit Manager C/A Payment</label>
                                                                    </div>
                                                                    <div class="editor-field">
                                                                        <input type="number" name="um_ca_amount" id="um_ca_amount" value="0.00" class="form-control"/>
                                                                    </div>
                                                                </div>

                                                                </div> 

                                                            </div>

                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                                <button type="submit" id="btnSave2" name="btnSave2" class="btn btn-primary">Save</button>
                                                            </div>

                                                        </div>
                                                        <?php echo e(csrf_field()); ?>


                                                    </form>

                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php else: ?>

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

                    <h3>Release Details</h3>
                    <section>
                        <div class="col-md-12">
                        
                        
                        <table class="table table-hover" id="receivables_table" width="100%">
                            <thead>
                                <tr style="background: grey ;color:#fff; font-weight: bold">
                                    <td hidden>No.</td>
                                    <td width="">Received Date</td>
                                    <td width="">Remarks</td>
                                    <td width="">Received Amount</td>
                                    <td style="text-align: center">Agent %</td>
                                    <td style="text-align: center">Agent Comm</td>
                                    <td style="text-align: center">Manager %</td>
                                    <td style="text-align: center">Manager Comm</td>
                                    <td style="text-align: center">Broker %</td>
                                    <td style="text-align: center">Broker Comm</td>
                                    <td style="text-align: center">Action</td>
                                </tr>
                            </thead>
                            <?php if(isset($rdtls)): ?>
                                <?php $__currentLoopData = $rdtls; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dtl): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td hidden><?php echo e($dtl->id); ?></td>
                                        <td><?php echo e(date("d-M-Y", strtotime($dtl->created_at))); ?></td>
                                        <td><?php echo e($dtl->remarks); ?></td>
                                        
                                        <td style="text-align: right"><?php echo e(number_format($dtl->comm_amount,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->agent_pcg_rate,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->agent_com_rate,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->um_pcg_rate,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->um_com_rate,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->broker_pcg_rate,2)); ?></td>
                                        <td style="text-align: right"><?php echo e(number_format($dtl->broker_com_rate,2)); ?></td>
                                        <td style="text-align: center">
                                            <a href="<?php echo e(route('releases.editt',[$dtl->gl_id])); ?>" class="btn btn-default btn-xs"><i class="fa fa-edit"></i> Edit</a>
                                        </td>
                                        
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                            <?php else: ?>
  
                            <?php endif; ?>
                            
                        </table>
                        </div>
                    </section>

                </div>
            </form>

        </section>

        <?php if(Session('info')): ?>
            <div class="row">
            <div class="col-md-6 col-md-offset-3 text-center">
            <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> <?php echo e(Session('info')); ?></div>
            </div>
            </div>
        <?php endif; ?>

        
        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <form method="post" action="">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">Add New line item</h4>
                        </div>
                        <div class="modal-body text-left">
                            <input type="hidden" id="rcvd_id" name="rcvd_id" value="<?php echo e($rcvd[0]->rcvd_id); ?>">
                            <div class="form-group">
                                <label for="rcvddate" class="control-label">Date</label>
                                <div class="input-group date datetimepicker1">
                                    <input type="text" class="form-control" id="rcvddate" name="rcvddate" required="required" />
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pay_mod" class="control-label">Payment Mode</label>
                                <select name="pay_mod" id="pay_mod" class="form-control">
                                    <option value="">Select Paymode</option>
                                    <?php $__currentLoopData = $paymode; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($pm); ?>" selected><?php echo e($pm); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="rls_amt" class="control-label">Release Amount</label>
                                <input value="" type="number" name="rls_amt" id="rls_amt" class="form-control" style="text-align: right" min="1" step="0.1" required="required">
                            </div>
                            <div class="form-group">
                               <label for="particulars" class="control-label">Particulars</label>
                               <textarea class="form-control txt" rows="2" name="particulars" id="particulars" placeholder=""></textarea>
                           </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                            <button type="button" id="itmSave" name="itmSave" class="btn btn-primary">Save</button>
                        </div>
                    </div>
                    <?php echo e(csrf_field()); ?>

                </form>
            </div>
        </div>

        
        <div class="modal fade" id="notifModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <form method="post" action="">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">Add New line item</h4>
                        </div>
                        <div class="modal-body text-left">
                            <div class="form-group">
                                <p class="no-margin">Deletion successful</p>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                        <button type="button"  class="btn btn-primary">Close</button>
                    </div>
                </form>
            </div>
        </div>

        <!--Modal Notif-->
        <div class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" style=" padding-right: 0px;background-color: rgba(4, 4, 4, 0.8);">
          <div class="modal-dialog modal-lg" style="top: 20%;width: 70%;text-align: center;">
            <div class="modal-content" style="border-radius: 0px;border: none;top: 40%;">
              <div class="modal-body" style="background-color: #0f8845;color: white;">
                <h2 id="h22"></h2>
                <h4 id="h44"></h4>
              </div>
            </div>
          </div>
        </div>

    </div>

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

<?php $__env->startSection('script'); ?>

<script type="text/javascript" src="<?php echo e(asset('js/numeric/jquery.masknumber.js')); ?>" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-steps/1.1.0/jquery.steps.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.12/dist/js/select2.min.js"></script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

<script>
        var form = $("#frmReceive");
        /*form.validate({
            errorPlacement: function errorPlacement(error, element) { element.before(error); },
            rules: {
                confirm: {
                    equalTo: "#password"
                }
            }
        });*/
        form.children("div").steps({
            headerTag: "h3",
            bodyTag: "section",
            transitionEffect: "slideLeft",
            enableAllSteps: true, //disable steps
            /*onStepChanging: function (event, currentIndex, newIndex)
            {
                form.validate().settings.ignore = ":disabled,:hidden";
                return form.valid();
            },*/
            /*: function (event, currentIndex)
            {
                form.validate().settings.ignore = ":disabled";
                return form.valid();
            },*/
            onInit: function(event, currentIndex) {
               if(currentIndex == 0)
                   $('.wizard .content').css("height", '25em');
            },
            onFinished: function (event, currentIndex)
            {
                console.log("ready");
                $("#frmReceive").submit();
                //$("#frmSales").submit();
                 //var form = $(this);
                     //form.submit();
            }

        });
    </script>

    <script>

        $(document).ready(function() {

            $('#developer_id').select2();
            $('#project_id').select2();
            $('#client_id').select2();

            //notifPopup('Delete Notification', 'Record was successfully deleted.');
            //$('#modalConfirmDelete').modal('toggle');

            /*$('#datetimepicker1').datetimepicker({
                 format: 'MM/DD/YYYY'
            });*/

            $('.input-group.date').datetimepicker({
                format: 'MM/DD/YYYY',
                widgetPositioning: {
                    horizontal: "auto",
                    vertical: "auto"
                }
            });

            $('#cnt_amount').maskNumber();

            //$('#project_id option:not(:selected)').prop('disabled', true);
            $('#gross-table').DataTable( {
                bDestroy: true,
                processing: true,
                searching: true,
                bInfo : true,
                lengthChange: false,
                pageLength: 20,
                info: true,
                orderable: true,
                /*sScrollY: "100%",
                scrollCollapse: true,*/
                /*scrollY:        '50vh',*/
                /*scrollCollapse: true,*/
                scrollY:        '250px',
                scrollCollapse: true,
                paging: true,
                order: true,
                 columnDefs: [{
                     targets: "_all",
                     orderable: true
                 }]
                //fixedColumns: true
                /*"order": [[ 0, "desc" ]]*/
            });

            var rcv_table =  $('#receivables_table').DataTable( {
                bDestroy: true,
                scrollY: '350px',
                scrollCollapse: true,
                paging: true,
                bInfo : true,
                lengthChange: false,
                pageLength: 10,
                info: true
            });

            var rtable = $('#releases_table').DataTable( {
                bDestroy: true,
                scrollY: '350px',
                scrollCollapse: true,
                paging: true,
                bInfo : true,
                lengthChange: false,
                pageLength: 10,
                info: true
                //fixedColumns: true
                /*"order": [[ 0, "desc" ]]*/
            });

            autoAdjustColumns(rtable);
            autoAdjustColumns(rcv_table);

            var sp_status   = $('#sp_status').text();
            //alert(sp_status);
            if (sp_status == 'Active') {
                $('#addMore').attr("disabled", false);
            } else {
                $('#addMore').attr("disabled", true);
            }

            var a_rls   = $('#a_ttl_rls').text();
            var a_rcvd  = $('#a_ttl_rcvd').text();
            var m_rls   = $('#m_ttl_rls').text();
            var m_rcvd  = $('#m_ttl_rcvd').text();

            //var a_comm  = $('#agent_com_rate').val();
            //var m_comm  = $('#um_com_rate').val();

            var a_rcvd2 = parseFloat(removeCommas(a_rcvd));
            var m_rcvd2 = parseFloat(removeCommas(m_rcvd));

            var a_rcv   = parseFloat(removeCommas(a_rls)); //+parseFloat(removeCommas(a_comm));
            var m_rcv   = parseFloat(removeCommas(m_rls)); //+parseFloat(removeCommas(m_comm));
            //alert(a_rcv+' '+a_rcvd2);

            check_rcvd(a_rcv, a_rcvd2, m_rcv, m_rcvd2);

            /*if (a_rcv < a_rcvd2 || m_rcv < m_rcvd2) {
                //alert('Okeyy keeyu');
                console.log('check_rcvd: Ok');
            } else {
                //alert('Warning: You have an Overpayment commission.');
                console.log('check_rcvd: X');
            }*/

            $('.comm_rate1').on('change click keyup keydown', function () {
                calculateSum1();
            });


        }); //end document ready

        /*$(".comm_rate").each(function() {
            $(this).keyup(function(){
                calculateSum();
            });
        });*/

        function compute_comm(nsp) {

            //var y = $('#net_selling_price').val();
            //var num = realParseFloat(y);
            //console.log(nsp);

            //var nsp             = $('#net_selling_price').val();
            var agt_pcg_rate    = $('#agent_pcg_rate').val();
            var um_pcg_rate     = $('#um_pcg_rate').val();
            var broker_pcg_rate = $('#broker_pcg_rate').val();
            var ref_pcg_rate    = $('#ref_pcg_rate').val();

            var agt_com_amt     = nsp * (agt_pcg_rate / 100);
            var um_com_amt      = nsp * (um_pcg_rate / 100);
            var broker_com_amt  = nsp * (broker_pcg_rate / 100);
            var ref_com_amt     = nsp * (ref_pcg_rate / 100);

            console.log(agt_com_amt);
            console.log(um_com_amt);
            //console.log(agt_com_amt);
            //console.log(um_com_amt);

            $('#agent_com_rate').val(formatnum(agt_com_amt));
            $('#um_com_rate').val(formatnum(um_com_amt));
            $('#broker_com_rate').val(formatnum(broker_com_amt));
            $('#ref_com_rate').val(formatnum(ref_com_amt));
        }

        function compute_comm2(nsp) {

            //var nsp             = $('#net_selling_price').val();
            var agt_pcg_rate    = $('#a_pcg_rate').val();
            var um_pcg_rate     = $('#um_pcg_rate').val();
            var broker_pcg_rate = $('#bk_pcg_rate').val();
            var ref_pcg_rate    = $('#ref_pcg_rate').val();

            var agt_com_amt     = nsp * (agt_pcg_rate / 100);
            var um_com_amt      = nsp * (um_pcg_rate / 100);
            var broker_com_amt  = nsp * (broker_pcg_rate / 100);
            var ref_com_amt     = nsp * (ref_pcg_rate / 100);

            console.log('agt_com_amt '+ agt_com_amt);
            console.log('um_com_amt '+um_com_amt);
            //console.log(agt_com_amt);
            //console.log(um_com_amt);

            $('#a_com_rate').val(formatnum(agt_com_amt));
            $('#um_com_rate').val(formatnum(um_com_amt));
            $('#bk_com_rate').val(formatnum(broker_com_amt));
            $('#ref_com_rate').val(formatnum(ref_com_amt));
        }

        /*$(document).on("change","#a_pcg_rate",function() {
            //alert("clicked");
            var comm_amt    = $('#comm_amt').val();
            var a_pcg_rate  = $('#a_pcg_rate').val();
            var a_com_rate  = (comm_amt * a_pcg_rate) / 100; //$('#a_com_rate').val();
            $('#a_com_rate').val(a_com_rate);
            alert(comm_amt+' '+a_pcg_rate+' '+a_com_rate);
        });*/

        $('.comm_rate').on('change click keyup keydown', function () {
            calculateSum();
        });



        /*$(".comm_rate2").each(function() {
            $(this).keyup(function(){
                calculateSum2();
            });
        });*/

        function realParseFloat(s)
        {
            s = s.replace(/[^\d,.-]/g, ''); // strip everything except numbers, dots, commas and negative sign
            if (navigator.language.substring(0, 2) !== "de" && /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(s)) // if not in German locale and matches #,###.######
            {
                s = s.replace(/,/g, ''); // strip out commas
                return parseFloat(s); // convert to number
            }
            else if (/^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(s)) // either in German locale or not match #,###.###### and now matches #.###,########
            {
                s = s.replace(/\./g, ''); // strip out dots
                s = s.replace(/,/g, '.'); // replace comma with dot
                return parseFloat(s);
            }
            else // try #,###.###### anyway
            {
                s = s.replace(/,/g, ''); // strip out commas
                return parseFloat(s); // convert to number
            }
        }

        function formatnum(n) {
            return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
        }

        function removeCommas(str) {
            while (str.search(",") >= 0) {
                str = (str + "").replace(',', '');
            }
            return str;
        }

        function check_rcvd(a_rcv, a_rcvd2, m_rcv, m_rcvd2) {
            if (a_rcv > a_rcvd2) {
                //alert('You have an Overpayment agent commission.');
                console.log('overpayment agent');
                console.log('entry: '+a_rcv+' '+a_rcvd2);
                //commented out
                //$('#addMore').attr("disabled", true);
            } else if (m_rcv > m_rcvd2) {
                //alert('You have an Overpayment manager commission.');
                console.log('overpayment manager');
                console.log('entry: '+m_rcv+' '+m_rcvd2);
                //commented out
                //$('#addMore').attr("disabled", true);
            } else {
                $('#addMore').attr("disabled", false);
            }
        }

        function calculateSum() {

            var sum = 0;
            $(".comm_rate").each(function() {
                if(!isNaN(this.value) && this.value.length!=0) {
                    sum += parseFloat(this.value);
                }
            });

            console.log(sum);
            if (sum < 100) {
                console.log('kulang');
                //alert('kulang');
                //notifPopup('Sales Notification', 'New Sales was successfully created.');
                //$('#btnSave').attr("disabled",true);
            } else if (sum > 100) {
                console.log('sobra');
                $('#btnSave2').attr("disabled",true);
                alert('Sharing % distribution exceeded.');
            } else {
                console.log('sakto. daw coke');
                $('#btnSave2').attr("disabled",false);
            }
            //$("#sum").html(sum.toFixed(2));
        }

        function calculateSum1() {

            var sum1 = 0;
            $(".comm_rate1").each(function() {
                if(!isNaN(this.value) && this.value.length!=0) {
                    sum1 += parseFloat(this.value);
                    //$('#share_sum').val(sum1);
                }
            });

            /*$('.comm_rate1').each(function(){
                sum1 = parseFloat(sum1) + parseFloat($(this).text());
            });*/
            //alert(sum1);

            /*$('.comm_rate1').each(function(){
                sum1 += parseInt(this.value);  // Or this.innerHTML, this.innerText
            });*/

            /*$('.comm_rate1').each(function()
            {
                sum1 += parseInt($(this).text());
            });*/

            /*$(".comm_rate1").each(function() {
                var val = $.trim( $(this).text() );

                if ( val ) {
                    val = parseFloat( val.replace( /^\$/, "" ) );

                    sum1 += !isNaN( val ) ? val : 0;
                }
            });*/

            $('#share_sum').val(sum1);
            console.log(sum1);

            var y = $('#comm_amt').val();
            var num = y;

            if (sum1 < 100) {
                console.log('kulang');
                //alert('kulang');
                //notifPopup('Sales Notification', 'New Sales was successfully created.');
                $('#btnConfirm').attr("disabled",true);
            } else if (sum1 > 100) {
                console.log('sobra');
                $('#btnConfirm').attr("disabled",true);
                //alert('Sharing % distribution exceeded.');
            } else {
                console.log('sakto. daw coke');
                //$('#btnSave2').attr("disabled",false);
            }
            //$("#sum").html(sum.toFixed(2));

            compute_comm2(num);

        }

        function calculateSum2() {

            var sum2 = 0;

            $(".comm_rate2").each(function() {
                if(!isNaN(this.value) && this.value.length!=0) {
                    sum2 += parseFloat(this.value);
                    //$('#share_sum').val(sum2);
                }
            });

            console.log(sum2);

            if (sum2 < 100) {
                console.log('kulang');
            } else if (sum2 > 100) {
                console.log('sobra');
                //alert('Sharing % distribution exceeded.');
                $('#btnSave').attr("disabled",true);
            } else {
                console.log('sakto. daw coke');
                $('#btnSave').attr("disabled",false);
            }

            var a_ttl_rcv1  = parseFloat(removeCommas($('#a_ttl_rcvd1').text()));
            var m_ttl_rcv1  = parseFloat(removeCommas($('#m_ttl_rcvd1').text()));

            var a_ttl_rls1  = $('#a_ttl_rls1').text();
            var m_ttl_rls1  = $('#m_ttl_rls1').text();
            //alert(m_ttl_rls1);

            var amt_rls     = $('#comm_amount1').val();
            var a_rate      = $('#agent_pcg_rate1').val();
            var m_rate      = $('#um_pcg_rate1').val();
            var a_ttl_rls   = ((a_rate * amt_rls) / 100);
            var m_ttl_rls   = ((m_rate * amt_rls) / 100);

            var a_ttl       = a_ttl_rls+parseFloat(removeCommas(a_ttl_rls1));
            var m_ttl       = m_ttl_rls+parseFloat(removeCommas(m_ttl_rls1));

            //alert(a_ttl_rls+' '+m_ttl_rls);

            console.log('agent rls: '+a_ttl);
            console.log('manager rls: '+m_ttl);
            console.log(a_ttl_rcv1);


            if (a_ttl > a_ttl_rcv1 || m_ttl > m_ttl_rcv1) {
                //alert('negative');
                $('#btnSave').attr("disabled",true);
            } else {
                $('#btnSave').attr("disabled",false);
            }

        }

        function notifPopup(title,body) {
            $('#h22').text(title);
            $('#h44').text(body);
            $('.bs-modal-lg').modal('show');
            $('.bs-modal-lg').modal();
            //$('#addModal').modal('show');
            setTimeout(function() {$('.bs-modal-lg').modal('hide');}, 3000);
            //location.reload(true);
        }

        /*$('#addRows').on('click', function () {
            $('#addModal').modal('toggle');
        });*/

        /*$('#agent_pcg_rate1').on('change keyup keydown', function () {
            //alert($(this).attr("value"))
            $f = $('#agent_pcg_rate1').val($(this).attr("value"));
            alert($f);
        });*/

        $('#add-more').on('click', function () {
            $('#addModal').modal('show'); //toggle
        });

        $('#addModal').on('shown.bs.modal', function(e) {
            $('.input-group.date').datetimepicker({
                format: 'MM/DD/YYYY'
            });
        });

        /*$('.editModal').on('shown.bs.modal', function(e) {
            $('.input-group.date').datetimepicker({
                //format: 'MM/DD/YYYY'
            });
        });*/

     var count = $(".itemRow").length;

     $("#addRows2").on("click",function(){
         //alert('ready');
        var row_count =  $('#invoiceItem').find('tr').length;
        //alert(row_count);
        $("#itm").val(row_count);

        count++;
        var htmlRows = '';
        htmlRows += '<tr>';
        htmlRows += '<td><input class="itemRow" type="checkbox"></td>';
        htmlRows += '<td><div class="input-group date datetimepicker1"><input type="text" name="rcvddate[]" id="rcvddate_'+count+'" class="form-control rcvddate" autocomplete="off" required>' +
         '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></td>';
        htmlRows += '<td><select id="paymode_'+count+'" name="paymode[]" class="form-control paymode" required>'+
         '<option value="">Select Paymode</option><?php $__currentLoopData = $paymode; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($pm); ?>" selected><?php echo e($pm); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></td>';
        htmlRows += '<td><input type="number" name="amount[]" id="amount_'+count+'" class="form-control amount" autocomplete="off" style="text-align:right;" required></td>';
        htmlRows += '</tr>';

        $('#invoiceItem').append(htmlRows);
            $('.datetimepicker1').datetimepicker({
             format: 'MM/DD/YYYY'
            });

        }); //addRows ends

    $(".delete").on("submit", function(){
        //return confirm("Are you sure?");
        //if(confirm("Are you sure you want to Delete this line?"))
        //{
            $.ajax({
                url:"<?php echo e(route('gross.delete')); ?>",
                method:"post",
                data:{id:id},
                success:function(data)
                {
                    console.log(data);
                    //refresh(data);
                    /*$("#table-row-"+id).remove();
                    $('#gross-table').DataTable( {
                        "bDestroy": true
                        });
                    $('#gross-table').DataTable().ajax.reload();*/
                }
            });
            /*}
            else
            {
                return false;
            }*/
    });

    /*$(document).on('click', '.btnDelete', function(){
        var id = $('#id').val();
        console.log(id);
        $("#table-row-"+id).remove();
    });*/

    function refresh(newData){
        /*var tbl = $('#gross-table').DataTable( {
            "bDestroy": true
        });*/
        var table = $('#gross-table').DataTable();
        tbl.clear().rows.add([newData]).draw();
    }

    function loadTable() {
        $.ajax({
            url: '/tests',
            type: 'GET',
            success: function (data, textStatus, jqXHR) {
                var row = '';
                $.each(data, function (i, item) {
                    row += '<tr><td>' + item.name + '</td><td>' + '<button class="btn btn-xs btn-info editTest" title="edit" data-id="' + item.id + '">edit</button>' + ' <button class="btn btn-xs btn-danger deleteTest" title="delete" data-toggle="modal" data-target="#myModal" data-id="' + item.id + '">Delete</button></td></tr>';

                });
                $('#view').html('');
                $('#view').append(row);
            }
        });
    }

    function TableRows() {
        var row_count =  $('#invoiceItem').find('tr').length;
        //alert(row_count);
        $("#itm").val(row_count);

        count++;
        var htmlRows = '';
        htmlRows += '<tr>';
        htmlRows += '<td><input class="itemRow" type="checkbox"></td>';
        htmlRows += '<td><div class="input-group date datetimepicker1"><input type="text" name="rcvddate[]" id="rcvddate_'+count+'" class="form-control rcvddate" autocomplete="off" required>' +
         '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></td>';
        htmlRows += '<td><select id="paymode_'+count+'" name="paymode[]" class="form-control paymode" required>'+
         '<option value="">Select Paymode</option><?php $__currentLoopData = $paymode; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($pm); ?>" selected><?php echo e($pm); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select></td>';
        htmlRows += '<td><input type="number" name="amount[]" id="amount_'+count+'" class="form-control amount" autocomplete="off" style="text-align:right;" required></td>';
        htmlRows += '</tr>';

        $('#invoiceItem').append(htmlRows);
            $('.datetimepicker1').datetimepicker({
             format: 'MM/DD/YYYY'
            });
    }

    $('#itmSave').on('click', function (event) {
        event.preventDefault();
        /*if (amount == '' || rcvddate == '' || pay_mode == '') {
            alert('Please input required fields.');
            $('#btnSave').attr('disabled', true);
        } else {*/
            var rcvd_id     = $('#rcvd_id').val();
            var amount      = $('#rls_amt').val();
            var pay_mode    = $('#pay_mod').val();
            var rcvddate    = $('#rcvddate').val();
            var particulars = $('#particulars').val();
            //alert('ready');
            $.ajax({
                url:"<?php echo e(route('gross.new')); ?>",
                method: 'post',
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                data:{
                    'rcvd_id':rcvd_id,
                    'rcvddate':rcvddate,
                    'pay_mode':pay_mode,
                    'amount':amount,
                    'particulars':particulars
                },
                 //dataType:'json',
                success:function(data){
                    console.log(data);
                    //$('#addModal').modal('hide');
                    //TableRows();
                    //$("#gross-table").html(data);
                    location.reload(true);
                },
                error: function (data, textStatus, errorThrown) {
                    alert(textStatus);
                }
            });
        //}
    });

    $('#itemUpdate').on('click', function () {

        //event.preventDefault();

        var id = $('#id').val();
        var amount = $('#rls_amount').val();
        var pay_mode = $('#pay_mode').val();
        var rcvddate = $('#rcvd_date2').val();
        var particulars = $('#particulars').val();
        //alert(id);

        /*if (amount == '' || rcvddate == '' || pay_mode == '') {
            alert('Please input required fields.');
            $('#itemUpdate').attr('disabled', true);
        } else {*/

            $.ajax({
               url:"<?php echo e(route('gross.update')); ?>",
               method: 'post',
               headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
               data:{
                    'id':id,
                    'rcvddate':rcvddate,
                    'pay_mode':pay_mode,
                    'amount':amount,
                    'particulars':particulars
               },
                dataType:'json',
               success:function(data){
                   console.log(data);
                   //$('.editModal').modal('toggle');
                   location.reload(true);
                   //notifPopup('Notification', 'Record was successfully updated.');
               },
               error: function (data, textStatus, errorThrown) {
               //error:function(error){
                   console.log(textStatus);
               }
            });
        //}
    });

    function getLineItems(id)  {
        //$('#id_').val(clicked_id);
        //alert(clicked_id);
        $.ajax({
            url:"<?php echo e(route('gross.getitems')); ?>",
            method: 'get',
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
            data:{
                'id':id
            },
             dataType:'json',
            success:function(data){
                console.log(data);
            },
            error: function (data, textStatus, errorThrown) {
            //error:function(error){
                alert(textStatus);
            }
        });
    }


    function refreshTable() {
      $('.gross-table').each(function() {
          dt = $(this).dataTable();
          dt.fnDraw();
      })
    }


    function remLine(id)  {
        //$('#id_').val(clicked_id);
        //alert(id);
        if(confirm("Are you sure you want to delete this line?"))
            {
               $.ajax({
                   url:"<?php echo e(route('gross.delete')); ?>",
                   method: 'post',
                   headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                   data:{
                       'id':id
                   },
                    dataType:'json',
                   success:function(data){
                       console.log(data);
                       //$('.modalConfirmDelete').modal('toggle');
                       //notifPopup('Delete Notification', 'Record was successfully deleted.');
                       location.reload(true);
                   },
                   error: function (data, textStatus, errorThrown) {
                   //error:function(error){
                       alert(textStatus);
                   }
               });
            }
        else
        {
            return false;
        }

    }

    function autoAdjustColumns(table) {
        var container = table.table().container();
        var resizeObserver = new ResizeObserver(function () {
            table.columns.adjust();
        });
        resizeObserver.observe(container);
    }

    </script>

    <script>
        /*function createNew() {
            $("#add-more").hide();
            var data = '<tr class="table-row" id="new_row_ajax">' +
            '<td contenteditable="false" id="txt_title" onBlur="addToHiddenField(this,\'title\')" onClick="editRow(this);"></td>' +
            '<td contenteditable="true" id="txt_title" onBlur="addToHiddenField(this,\'title\')" onClick="editRow(this);"></td>' +
            '<td contenteditable="true" id="txt_title" onBlur="addToHiddenField(this,\'title\')" onClick="editRow(this);"></td>' +
            '<td contenteditable="true" id="txt_title" onBlur="addToHiddenField(this,\'title\')" onClick="editRow(this);"></td>' +
            '<td contenteditable="false" id="txt_description" onBlur="addToHiddenField(this,\'description\')" onClick="editRow(this);"></td>' +
            '<td><input type="hidden" id="title" /><input type="hidden" id="description" /><span id="confirmAdd"><a onClick="addToDatabase()" class="ajax-action-links">Save</a> / <a onclick="cancelAdd();" class="ajax-action-links">Cancel</a></span></td>' +
            '</tr>';
          $("#table-body").append(data);
        }
        function cancelAdd() {
            $("#add-more").show();
            $("#new_row_ajax").remove();
        }
        function editRow(editableObj) {
          $(editableObj).css("background","#FFF");
        }

        function deleteRecord(id) {
        	if(confirm("Are you sure you want to delete this row?")) {
        		$.ajax({
        			url: "",
        			type: "POST",
        			data:'id='+id,
        			success: function(data){
        			  $("#table-row-"+id).remove();
        			}
        		});
        	}
        }*/
    </script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>