<?php
	$this->load->view('templates/header');
    $user_id = $this->session->userdata('user_id');
    $role = $this->session->userdata('user_role_id');
?>
    <script>
        var link = "voucher";
        var sub_link = "voucher_payment";
    
    </script>

 <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>Add New Payment Voucher</h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Add New Payment Voucher</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-basic">
                        <div class="box-body">
                            <div class="alert_msg"></div>
                            <form class="form-horizontal" id="payment_edit_voucher_form">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">Voucher Details</h3>
                                    </div>
                                    <div class="panel-body remove-bottom">
                                <!-- <div class="box-body "> -->

                                    <div class="form-group floating-form">
                                        <div class="col-md-1 floating-label">
                                            <input type="text" class="form-control floating-input" id="vc_entry_no" name="vc_entry_no" value="<?php echo (empty($voucher_data)?$entry_no:$voucher_data[0]['vc_entry_no'])?>" placeholder=" " autocomplete="off" readonly />
                                            <label>Voucher No.</label>
                                        </div>
                                        <div class="col-md-1 floating-label">
                                            <?php $readonly = ($role == 1) ? 'tabindex=1' : 'readonly'; ?>
                                            <input type="text" class="form-control floating-input" id="vc_entry_date" name="vc_entry_date" value="<?php echo (empty($voucher_data) ? date("d-m-Y") : date('d-m-Y',strtotime($voucher_data[0]['vc_entry_date'])))?>" placeholder=" " autocomplete="off" <?php echo $readonly ?> />
                                            <label>Voucher Date</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">
                                            <?Php
                                                if($voucher_type == 'PAYMENT'):
                                            ?>
                                            <input type="hidden" name="vc_voucher_type" id="vc_voucher_type" value="1" />
                                            <?Php
                                                else:
                                            ?>
                                            <input type="hidden" name="vc_voucher_type" id="vc_voucher_type" value="2" />
                                            <?php
                                                endif;
                                            ?>
                                            
                                            <input type="text" class="form-control floating-input" value="<?php echo $account_data[$voucher_data[0]['vc_cash_acc_id']]; ?>" placeholder=" "readonly/>
                                            <input type="hidden" value="<?php echo $voucher_data[0]['vc_cash_acc_id']; ?>" id="vc_cash_acc_id" name="vc_cash_acc_id"/>
                                            <label>Cash Account</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">
                                            <input type="text" class="form-control floating-input" value="<?php echo $group_data[$voucher_data[0]['vc_grp_id']]; ?>" placeholder=" "readonly/>
                                            <input type="hidden" value="<?php echo $voucher_data[0]['vc_grp_id']; ?>" id="vc_grp_id" name="vc_grp_id"/>

                                            <label>Group</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">
                                            <input type="text" class="form-control floating-input" value="<?php echo $party_data[$voucher_data[0]['vc_party_id']]; ?>" placeholder=" "readonly/>
                                            <input type="hidden" value="<?php echo $voucher_data[0]['vc_party_id']; ?>" id="vc_party_id" name="vc_party_id"/> 
                                            <label>Party Name</label>                                        
                                        </div>
                                        <?php if($voucher_data[0]['vc_cash_acc_id'] == 73): ?>
                                        <div class="col-md-1 floating-label">
                                            <input type="text" name="vc_cheque_no" class="form-control floating-input" id="vc_cheque_no"  placeholder=" " value="<?php echo $voucher_data[0]['vc_cheque_no']; ?>" readonly />
                                            <label id="vc_cheque_no_label" >Cheque no</label>
                                        </div>
                                        <div class="col-md-1 floating-label">
                                            <input type="text" name="vc_cheque_date" class="form-control floating-input" id=""  placeholder=" " value="<?php echo date('d-m-Y', strtotime($voucher_data[0]['vc_cheque_date'])); ?>" readonly/>
                                            <label id="" >Cheque Date</label>
                                        </div>
                                        <?php endif; ?>
                                        <?php if(empty($voucher_trans) && $voucher_data[0]['vc_grp_id'] != 23): ?>
                                         <div class="col-md-1">
                                            <button type="button" class="btn btn-primary" id="sbt_btn" onClick="update_payment_voucher(<?php echo $voucher_data[0]['vc_id'] ?>)" style="width:100%;"><?php echo (empty($voucher_data)?"Submit":"Update")?></button>
                                        </div>
                                        <?php endif; ?>
                                        <div class="col-md-1">
                                            <a href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=view');?>" type="button" class="btn btn-danger" >Cancel</a>
                                        </div>
                                    </div>
                                    <div class="form-group floating-form">
                                        <div class="col-md-2 floating-label">
                                            <input type="text" name="" class="form-control floating-input" id="vc_payment_status"  placeholder=" " value="" readonly />
                                            <label>Balance</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">
                                            <?Php
                                                if($voucher_type == 'PAYMENT'):
                                            ?>
                                            <input type="hidden" name="op_trans_type" class="form-control" id="op_trans_type" value="DR" />
                                            <?php
                                                else:
                                            ?>
                                            <input type="hidden" name="op_trans_type" class="form-control" id="op_trans_type" value="CR" />
                                            <?php
                                                endif;
                                            ?>
                                            <input type="number" name="vc_amount" class="form-control floating-input" id="vc_amount" value="<?php echo (empty($voucher_data)?0:$voucher_data[0]['vc_amount'])?>" placeholder=" " oninput="this.value = Math.abs(this.value)"  onkeyup="set_voucher_trans_amt()" readonly/>
                                            <label>Amount</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">
                                            <input type="number" name="vc_round_off" class="form-control floating-input" id="vc_round_off" value="<?php echo (empty($voucher_data)?0:$voucher_data[0]['vc_round_off'])?>" onkeyup="check_round_off_amt();" placeholder=" " oninput="this.value = Math.abs(this.value)" onkeyup="set_voucher_trans_amt()" readonly />
                                            <label>Round off</label>                                        
                                        </div>
                                        <div class="col-md-2 floating-label">                                            
                                            <textarea name="vc_notes" class="form-control floating-input" id="vc_notes"  placeholder=" "rows="3"><?php echo (empty($voucher_data)?"":$voucher_data[0]['vc_notes'])?></textarea>
                                            <label>Notes</label>
                                        </div>
                                       <?php if(empty($voucher_trans) && $voucher_data[0]['vc_grp_id'] != 23): ?>
                                        <div class="col-md-2 col-md-offset-1">                                           
                                            <button type="button" class="btn btn-primary" onClick="get_party_purchase_details_for_payment_voucher_update()" style="width:100%;">Outstanding bill</button>
                                        </div>
                                        <?php endif; ?>                                      
                                    </div>
                                <!-- </div> -->
                            </div>
                                </div>

                                <?php
                                    if(!empty($voucher_trans)):
                                ?>
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">Voucher Details</h3>
                                    </div>

                                    <div class="panel-body">
                                        <table class="table">
                                            <tr>
                                                <th width="5%">Entry No.</th>
                                                <th width="10%">Entry Date</th>
                                                <th width="5%">Bill No</th>
                                                <th width="10%">Bill Date</th>
                                                <th width="5%">Total Qty</th>
                                                <th width="10%">Final Total</th>
                                                <th width="10%">Adjust Amt</th>
                                                <th width="10%">Adjust Round off Amt</th>
                                                
                                            </tr>

                                            <?php
                                                $voucher_cnt = 1;
                                                foreach ($voucher_trans as $key => $value) :
                                                    // echo"<pre>";print_r($value);exit;
                                            ?>

                                            <tr>
                                                <td>
                                                    <input type="hidden" class="form-control" name="pm_id[]" id="pm_id_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_pm_id']?>"/>
                                                    <input type="text" class="form-control" name="pm_entry_no[]" id="pm_entry_no_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_entry_no']?>" readonly/>
                                                </td>

                                                <td>
                                                    <input type="text" class="form-control" name="pm_entry_date[]" id="pm_entry_date_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_entry_date']?>" readonly/>
                                                </td>

                                                <td>
                                                    <input type="text" class="form-control" name="pm_bill_no[]" id="pm_bill_no_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_bill_no']?>" readonly/>
                                                </td>

                                                <td>
                                                    <input type="text" class="form-control" name="pm_bill_date[]" id="pm_bill_date_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_bill_date']?>" readonly/>
                                                </td>

                                                <td>
                                                    <input type="text" class="form-control" name="pm_total_qty[]" id="pm_total_qty_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_total_qty']?>" readonly/>
                                                </td>

                                                <td>
                                                    <input type="text" class="form-control" name="pm_final_total[]" id="pm_final_total_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_final_total']?>" readonly/>
                                                </td>                                                
                                               
                                                <td>
                                                    <input type="text" class="form-control" name="pm_adjust_amt[]" id="pm_adjust_amt_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_adjust_amt']?>" readonly/>
                                                </td>
                                                
                                                <td>
                                                    <input type="text" class="form-control" name="pm_adjust_round_off[]" id="pm_adjust_round_off_<?php echo $voucher_cnt?>" value="<?php echo $value['vt_adjust_round_off']?>" readonly/>
                                                </td>
                                            </tr>

                                            <?php
                                                $voucher_cnt++;
                                                endforeach;
                                            ?>
                                        </table>
                                    </div>
                                </div>
                                <?php
                                    else:
                                ?>
                                <div id="bal_purchase_details">
                                </div>
                                
                                <?php
                                    endif;
                                ?>
                                
                               
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </section>
       </div>

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

    if(!empty($voucher_trans))
    {
         echo "<script>";
         echo "voucher_cnt = $voucher_cnt";
         echo "</script>";
    }
?>

