<?php 
    $this->load->view('templates/header');
    $disabled = empty($master_data) ? '' : "disabled";
?>
<script>
     var link       = "voucher";
     var sub_link   = "payment";
</script>

<!-- Content Header (Page header) -->
<section class="content-header">
    <div class="row">
        <div class="col-sm-12 col-md-8">
            <p style="font-size: 20px;font-weight: bold;"><?php echo empty($master_data) ? 'ADD NEW' : 'EDIT'; ?>
                <small>PAYMENT VOUCHER</small>
            </p>

            <div class="alert_msg_popup"></div>
        </div>
        <div class="col-sm-12 col-md-4">
            <a href="<?php echo base_url('voucher/payment?action=view');?>" type="button" class="btn btn-danger pull-right" tabindex="9" style="margin-left: 10px;">PAYMENT</a>
            <?php if(!empty($master_data)): ?>
                <?php if(empty($trans_data)): ?>
                <button type="button" class="btn btn-success master_block_btn pull-right" id="sbt_btn" onClick="add_update_payment(<?php echo $master_data[0]['vm_id']; ?>)" tabindex="9">UPDATE</button>
                <?php endif; ?>
            <?php else: ?>
                <button type="button" class="btn btn-success master_block_btn pull-right" id="sbt_btn" onClick="add_update_payment(0)" disabled="disabled" tabindex="8">SUMBIT</button>
            <?php endif; ?>
        </div>
    </div>    
</section>


<!-- Main content -->
<section class="content">
    <div class="row">
        <form class="form-horizontal" id="payment_form">
            <div class="col-md-6 col-sm-12">
                <div class="panel panel-default" style="border-radius: 20px;">
                    <div class="panel-heading" style="border-top-left-radius: 20px; border-top-right-radius: 20px;">
                        <b> VOUCHER DETAILS</b>
                    </div>
                    <div class="panel panel-body">
                        <div class="form-group floating-form">
                            <div class="col-md-3 col-sm-12">
                                <label>Voucher No.</label>
                                <input type="text" class="form-control floating-input" id="vm_entry_no" name="vm_entry_no" value="<?php echo empty($master_data) ? $vm_entry_no : $master_data[0]['vm_entry_no']; ?>" placeholder=" " autocomplete="off" readonly />
                            </div>
                            <div class="col-md-3 col-sm-12">
                                <label>Voucher Date</label>                                        
                                <input type="text" class="form-control floating-input" id="vm_entry_date" name="vm_entry_date" value="<?php echo empty($master_data) ? date("d-m-Y") : date('d-m-Y', strtotime($master_data[0]['vm_entry_date'])); ?>" placeholder=" " autocomplete="off" readonly />
                            </div>
                            <!-- <div class="col-md-3 col-sm-12">
                                <label>Group</label>                                        
                                <?php echo form_dropdown('', $groups, empty($master_data) ? 'SUPPLIER': $master_data[0]['vm_group'],'id="vm_group" name="vm_group" class="form-control floating-select" tabindex="1" onchange="get_type(this.value)"'.$disabled);?>
                                <?php if(!empty($master_data)): ?>
                                    <input type="hidden" name="vm_group" value="<?php echo $master_data[0]['vm_group']?>" />
                                <?php endif; ?>
                            </div> -->

                            <input type="hidden" class="form-control floating-input" id="vm_group" name="vm_group" value="SUPPLIER" />

                            <!-- <div class="col-md-3 col-sm-12">
                                <label>Type</label>                                        
                                <?php echo form_dropdown('', $accounts, empty($master_data) ? 1 : $master_data[0]['vm_acc_id'],'id="vm_acc_id" name="vm_acc_id" class="form-control floating-select" tabindex="2" onchange="get_account_balance()"');?> 
                            </div> -->

                            <input type="hidden" class="form-control floating-input" id="vm_acc_id" name="vm_acc_id" value="1" />

                            <div class="col-sm-6">
                                <label>Name</label>              
                                <select class="form-control floating-select" id="vm_party_id" name="vm_party_id" placeholder="" tabindex="3" <?php echo $disabled; ?>>
                                    <?php if(!empty($master_data)): ?>
                                        <option value="<?php echo $master_data[0]['vm_party_id'] ?>">
                                            <?php echo $master_data[0]['vm_group'] == 'SUPPLIER' ? $master_data[0]['supplier_name'] : $master_data[0]['client_name']; ?>
                                        </option>
                                        <input type="hidden" name="vm_party_id" value="<?php echo $master_data[0]['vm_party_id'] ?>" />
                                    <?php endif; ?>                                                
                                </select>
                            </div>
                        </div>    
                        <div class="form-group floating-form">
                            <div class="col-md-3 col-sm-12">
                                <label>Payment Mode</label>                                        
                                <?php echo form_dropdown('', $modes, empty($master_data) ? 'CASH' : $master_data[0]['vm_mode'],'id="vm_mode" name="vm_mode" class="form-control floating-select" tabindex="4" ');?> 
                            </div>
                            
                            <div class="col-sm-9 ">                                            
                                <label>Notes</label>
                                <textarea name="vm_notes" class="form-control floating-input" id="vm_notes"  placeholder=" " tabindex="4" rows="1"><?php echo (empty($master_data)?"":$master_data[0]['vm_notes'])?></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-sm-12">
                <div class="panel panel-default" style="border-radius: 20px;">
                    <div class="panel-heading"><b> AMOUNT DETAILS</b></div>
                    <div class="panel panel-body">
                        <div class="form-group floating-form">
                            <div class="col-md-3 col-sm-12">
                                <label>Total Amt.</label>
                                <input type="number" class="form-control floating-input" id="vm_credit_amt" name="vm_credit_amt" value="0" placeholder=" " autocomplete="off" readonly style="border:none;" />
                            </div>
                            <div class="col-md-3 col-sm-12">
                                <label>Total Amt Received</label>                                        
                                <input type="number" class="form-control floating-input" id="vm_credited_amt" name="vm_credited_amt" value="0" placeholder=" " autocomplete="off" readonly style="border:none;" />
                            </div>
                            <div class="col-md-3 col-sm-12">
                                <label>Amt To Pay</label>
                                <input type="number" class="form-control floating-input" id="vm_total_amt" name="vm_total_amt"  placeholder=" " autocomplete="off" value="<?php echo empty($master_data) ? 0 : $master_data[0]['vm_total_amt']; ?>" min="0" oninput="this.value = Math.abs(this.value)" onkeyup="calculate_master_balance()" tabindex="5" />
                            </div>
                            <div class="col-md-3 col-sm-12">
                                <label>Bal Amt</label>                                        
                                <input type="hidden" name="vm_type" value="PAYMENT">
                                <input type="hidden" id="vm_balance" value="">
                                <input type="hidden" id="vm_balance_type" value="">
                                <input type="text" class="form-control" id="vm_balance_show" value="<?php echo (empty($order_data)?'0 TO PAY':'')?>" placeholder="" autocomplete="off" readonly style="border:none; font-size: 1.5rem;"/>
                            </div>
                        </div>
                        <div class="form-group floating-form">

                            <div class="col-md-3 col-sm-12">
                                <label>Dollar Rate</label>                                        
                                <input type="number" class="form-control floating-input" id="vm_dollar_rate" name="vm_dollar_rate" value="<?php echo empty($master_data) ? 0 : $master_data[0]['vm_dollar_rate']; ?>" placeholder=" " autocomplete="off" />
                            </div>

                            <div class="col-md-3 col-sm-12">
                                <label>USD Amt</label>                                        
                                <input type="number" class="form-control floating-input" id="vm_usd_amt" name="vm_usd_amt" value="<?php echo empty($master_data) ? 0 : $master_data[0]['vm_usd_amt']; ?>" placeholder=" " autocomplete="off" />
                            </div>

                            <div class="col-md-3 col-sm-12">
                                <label for="inputEmail3">PREPARED BY</label>
                                <?php echo form_dropdown('', $users, empty($master_data) ? $_SESSION['user_id'] : $master_data[0]['vm_prepared_id'],'id="vm_prepared_id" name="vm_prepared_id" class="form-control floating-select" tabindex="6" ');?>
                            </div>
                            <div class="col-md-3 col-sm-12">
                                <label for="inputEmail3">CHECKED BY</label>
                                <?php echo form_dropdown('', $users, empty($master_data) ? 0 : $master_data[0]['vm_checked_id'],'id="vm_checked_id" name="vm_checked_id" class="form-control floating-select" tabindex="7" ');?>
                            </div>
                        </div>        
                    </div>
                </div>
            </div>


            <div class="col-md-12 col-sm-12">
                <div class="panel panel-default" style="border-radius: 20px;">
                    <div class="panel-heading" style="border-top-left-radius: 20px; border-top-right-radius: 20px;">
                        <b> SUPPLIER DETAILS</b>
                    </div>
                    <div class="panel panel-body">
                        <table class="table table-hover table-sm table-responsive" id="voucher_material_wrapper">
                            <?php if(!empty($trans_data)): ?>
                                <thead>
                                    <tr style="font-size: 15px;">
                                        <th width="2%"></th>
                                        <th width="8%">SUPPLIER NO</th>
                                        <th width="10%">SUPPLIER DATE</th>
                                        <th width="10%">DOLLAR RATE</th>
                                        <th width="10%">BALANCE AMT</th>
                                        <th width="10%">ALLOCATED AMT</th>
                                        <th width="10%">CURRENT BAL. AMT</th>
                                    </tr>
                                </thead>
                                <tbody id="receipt_material_wrapper">
                                    <?php
                                        $sr_no = 1;
                                        foreach ($trans_data as $key => $value):?>
                                        <tr id="rowid_<?php echo $sr_no ?>" class="floating-form">
                                            <td>
                                                <input type="hidden" id="vt_id_<?php echo $sr_no ?>" name="vt_id[]" value="<?php echo $value['vt_id'] ?>" />
                                                <input type="hidden" id="vt_bill_clear_<?php echo $sr_no ?>" name="vt_bill_clear[]" value="YES" />
                                            </td>
                                            <td>
                                                <input type="hidden" id="vt_purchase_id_<?php echo $sr_no ?>" name="vt_purchase_id[]" value="<?php echo $value['vt_purchase_id'] ?>" />
                                                <input type="hidden" id="vt_am_id_<?php echo $sr_no ?>" name="vt_am_id[]" value="<?php echo $value['vt_am_id'] ?>" />
                                                <input type="text" class="form-control floating-input" name="vt_entry_no[]" id="vt_entry_no_<?php echo $sr_no ?>" value="<?php echo $value['vt_entry_no'] ?>" readonly />
                                            </td>
                                            <td>
                                                <input type="text" class="form-control floating-input" name="vt_entry_date[]" id="vt_entry_date_<?php echo $sr_no ?>" value="<?php echo date('d-m-Y', strtotime($value['vt_entry_date'])) ?>" readonly />
                                            </td>
                                             <td>
                                                <input type="number" class="form-control floating-input" name="vt_dollar_rate[]" id="vt_dollar_rate_<?php echo $sr_no ?>" value="<?php echo $value['vt_dollar_rate'] ?>" readonly />
                                            </td>
                                            <td>
                                                <input type="number" class="form-control floating-input" name="vt_total_amt[]" id="vt_total_amt_<?php echo $sr_no ?>" value="<?php echo $value['vt_total_amt'] ?>" readonly />
                                            </td>
                                            <td>
                                                <input type="number" class="form-control floating-input" name="vt_allocated_amt[]" id="vt_allocated_amt_<?php echo $sr_no ?>" value="<?php echo ($value['vt_adjust_amt'] + $value['vt_adjust_round_off']) ?>" readonly />
                                                <input type="hidden" name="vt_adjust_amt[]" id="vt_adjust_amt_<?php echo $sr_no ?>" value="0"/>
                                                <input type="hidden" name="vt_adjust_round_off[]" id="vt_adjust_round_off_<?php echo $sr_no ?>" value="0"/>
                                            </td>
                                            <td>
                                                <input type="number" class="form-control floating-input" id="vt_balance_amt_show_<?php echo $sr_no ?>" value="<?php echo ($value['vt_total_amt'] - ($value['vt_adjust_amt'] + $value['vt_adjust_round_off'])) ?>" readonly />
                                            </td>
                                        </tr>
                                    <?php 
                                            $sr_no++;
                                        endforeach;
                                    ?>
                                </tbody>
                            <?php endif; ?>
                        </table>
                    </div>
                </div>
            </div>
        </form>
    </div>
</section>
<!-- Main content -->


<?php 
    $this->load->view('templates/footer');
?>
<script src="<?php echo assets('js/voucher/payment.js')?>"></script>

</body>
</html>