<?php

/* 
 * Author       : Kowsalya K
 * Purpose      : The edit page for Temple Institution
 * Created On   : 2016-08-02   
 */
?>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/billing/temple_institution.js"></script>
<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color"><a href="<?php echo get_bill_list_url(); ?>" class="list-btn"><i class="fa fa-list" title="Go to Listing"></i></a><?php echo $title; ?> - Edit</h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <?php $general = get_general_setting();?>
    <section class="content">
        <div class="row" id="main-content">
            <div class="col-xs-12">
                <form action="<?php echo $form_action;?>" name="temple_institute" method="post"  enctype="multipart/form-data" method="post" onsubmit="return autoValidate();">
                    <input type="hidden" name="hidden_id" value="<?php echo $temple_institute->id;?>" />
                    <input type="hidden" name="service_type_id" value="<?php echo $temple_institute->type_id;?>" />
                    <div class="box box-danger">
                        <div class="box-body">
                            <ul class="error_container"></ul>
                            <div class="col-xs-12">
                                <div class="col-md-6">
                                    <div class="form-group float-clear">
                                        <label>Receipt No</label>
                                        <input type="text" class="form-control readonly" name="rec_no" value="<?php echo (($general->prefix == 1) ? $temple_institute->prefix : '') . $temple_institute->receipt_no;?>" placeholder="Auto Generated" readonly />
                                    </div>
                                                           
                                    <div class="form-group">
                                        <label>Type<span class="required">*</span></label>
                                        <div class="input-group">
                                            <!--<select name="service_type" class="form-control select2 req" data-err-target=".sub-title">
                                                <option value="">-- Select Type --</option>
                                                <?php foreach($service_type as $key=>$type) {?>
                                                    <option value="<?php echo $type->id;?>" <?php echo ($type->id == $temple_institute->service_id) ? 'selected' : '';?>><?php echo $type->name;?></option>
                                                <?php } ?>
                                            </select>-->
                                            <input type="text" class="form-control readonly" name="type_name" value="<?php echo $temple_institute->service;?>" readonly />
                                            <input type="hidden" name="service_type" data-amt="<?php echo $temple_institute->ser_amount; ?>" value="<?php echo $temple_institute->service_id;?>" />
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group float-clear" style="text-align: right;">
                                        <button class="btn btn-success dialog-btn" data-target="#student-dialog" id="student-btn"><i class="fa fa-user" style="color: #fff;"></i> Student Registration</button>
                                        <button class="btn btn-success" data-target="#student-dialog" id="get-student-btn"><i class="fa fa-search" style="color: #fff;"></i> Student Search</button>
                                    </div>
                                </div>
                            </div>    
                                    
                            <div class="col-xs-12 blck">
                                <div class="sub-title" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Class Details</h4><i class="ctrl opener opened fa fa-chevron-up" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12">
                                    <div class="col-md-6">        
                                        <div class="form-group">
                                            <label>Term</label>
                                            <div class="input-group">
                                                <select name="term" class="form-control select2" data-err-target=".sub-title">
                                                    <option value="">-- Select Term --</option>
                                                    <option value="1" <?php echo ($temple_institute->term == 1) ? 'selected' : '';?>>Yearly</option>
                                                    <option value="2" <?php echo ($temple_institute->term == 2) ? 'selected' : '';?>>Monthly</option>
                                                    <option value="3" <?php echo ($temple_institute->term == 3) ? 'selected' : '';?>>Weekly</option>
                                                    <option value="4" <?php echo ($temple_institute->term == 4) ? 'selected' : '';?>>Daily</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group m-h30">
                                            <label class="leftcol">Transport Facility</label>
                                            <div>
                                                <label for="transport_facility" style="width: 32%;"><input type="radio" name="transport_facility" value="1" <?php echo ($temple_institute->transport_facility == 1) ? 'checked' : '';?> /> &nbsp;&nbsp;Yes</label> 
                                                <label for="transport_facility" style="width: 32%;"><input type="radio" name="transport_facility" value="0" <?php echo ($temple_institute->transport_facility == 0) ? 'checked' : '';?> /> &nbsp;&nbsp;No</label>
                                            </div>                                                
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Bus No</label>
                                            <input type="text" class="form-control" name="bus_no" value="<?php echo ($temple_institute->bus_no != 0) ? $temple_institute->bus_no : '';?>" <?php echo ($temple_institute->transport_facility == 0) ? 'disabled' : '';?> />
                                        </div>

                                    </div>

                                    <div class="col-md-6">                                    
                                        <div class="form-group">
                                            <label>Class Type</label>
                                            <div class="input-group">
                                                <select name="class_type" class="form-control select2" data-err-target=".sub-title">
                                                    <option value="">-- Select Class Type --</option>
                                                    <?php foreach($class_types as $key=>$type) {?>
                                                        <option value="<?php echo $key;?>" <?php echo ($key == $temple_institute->class_type) ? 'selected' : '';?>><?php echo $type;?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="form-group">
                                            <label>Class</label>
                                            <div class="input-group">
                                                <select name="class" class="form-control select2" data-err-target=".sub-title">
                                                    <option value="1" <?php echo ($temple_institute->class == 1) ? 'selected' : '';?>>Morning</option>
                                                    <option value="2" <?php echo ($temple_institute->class == 2) ? 'selected' : '';?>>Evening</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Fee</label>
                                            <!--<div class="input-group">
                                                <div class="input-group-addon">$</div>-->
                                                <input type="text" class="form-control float_value readonly" name="fee" value="<?php echo $temple_institute->fee;?>" readonly />
                                            <!--</div>-->
                                        </div>
                                    </div>
                                </div> <!-- blck-content -->    
                            </div> <!-- blck -->
                            
                            
                            <div class="col-xs-12 blck">
                                <div class="sub-title" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Contact Details</h4><i class="ctrl opener fa fa-chevron-down" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12" style="display: none;">
                                    <div class="col-md-6">        
                                        <div class="form-group float-clear">
                                            <label>Name<span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="devotee_name" placeholder="Name" data-err-target=".sub-title" value="<?php echo $temple_institute->devotee_name;?>" />
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Contact No</label>
                                            <div class="input-group">
                                                <input type="text" class="form-control contact-no num-pad" name="contact_no" placeholder="Contact No" data-err-target=".sub-title" value="<?php echo $temple_institute->contact_no;?>" />
                                                <div class="input-group-addon"><i class="fa fa-phone"></i></div>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Email Id</label>
                                            <div class="input-group">
                                                <input type="text" class="form-control email" name="email" placeholder="Email Id" data-err-target=".sub-title" value="<?php echo $temple_institute->email;?>" />
                                                <div class="input-group-addon"><i class="fa fa-envelope"></i></div>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label class="leftcol">Sex</label>
                                            <div>
                                                <label for="sex" style="width: 32%;"><input type="radio" name="sex" value="1" class="sex_male"  data-err-target=".sub-title" <?php echo ($temple_institute->sex == 1) ? 'checked' : '';?> /> &nbsp;&nbsp;Male</label> 
                                                <label for="sex" style="width: 32%;"><input type="radio" name="sex" value="2" <?php echo ($temple_institute->sex == 2) ? 'checked' : '';?> class="sex_female" /> &nbsp;&nbsp;Female</label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>Name (T)</label>
                                            <div class="input-group">
                                                <input class="form-control multi tamil-name input-tamil" type="text" name="tamil_devotee_name" placeholder="jkpH;bgah;" onclick="set_tamil_keypad(this);" value="<?php echo $temple_institute->tamil_name;?>" />
                                                <div class="input-group-addon"><i class="fa fa-keyboard-o"></i></div>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Address</label>
                                            <textarea class="form-control address" name="address"><?php echo $temple_institute->address;?></textarea>
                                        </div>
                                    </div>
                                    
                                </div> <!-- blck-content -->    
                            </div> <!-- blck -->
                            
                            
                            <div class="col-xs-12 blck">
                                <div class="sub-title" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Cost Details</h4><i class="ctrl opener fa fa-chevron-down" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12" style="display: none;">
                                    
                                    <div class="col-md-6">
                                        <div class="form-group float-clear">
                                            <label>Amount</label>
                                                <input type="text" class="form-control amount num-pad" name="amount" value="<?php echo $temple_institute->ti_amount;?>" />
                                                <input type="hidden" class="form-control readonly" name="hidden_amount" value="<?php echo $temple_institute->ti_amount;?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">        
                                        <div class="form-group float-clear">
                                            <label>Description</label>
                                            <textarea class="form-control" name="desc"><?php echo $temple_institute->desc;?></textarea>
                                        </div>
                                    </div>
                                    
                                </div> <!-- blck-content -->    
                            </div> <!-- blck -->
                            
                        </div>
                        
                        
                        <div class="box-footer form-actions float-clear" style="text-align: right; padding-right: 30px;">
                            <button class="btn btn-primary" type="reset"><i class="fa fa-trash"></i> Clear</button>
                            <button type="button" class="btn btn-danger" id="payment-btn"><i class="fa fa-credit-card"></i> Payment</button>
                        </div>
                    </div><!-- /.box -->
                    
                    <!-- Payment types Modal -->
                    <div class="modal fade" id="ptypes-dialog" role="dialog">
                        <div class="modal-dialog">
                            <!-- Modal content-->
                            <div class="modal-content">
                                    <div class="modal-header" style="background-color: #337AB7;">
                                        <h4 class="modal-title" style="color: #FFF;">Payment Details</h4>
                                    </div>
                                    <div class="modal-body col-xs-12">
                                        <div class="err-blck" style="margin-top: -20px;"></div>
                                        <div class="row" id="pay-amounts-box">

                                            <div class="col-md-6">                                    
                                                <div class="form-group float-clear">
                                                    <label>Amount To Pay</label>
                                                    <input type="text" class="form-control readonly" name="pay_amount" placeholder="0.00" value="<?php echo $paid_amount->paidAmount;?>"readonly />
                                                </div>
                                            </div>

                                            <div class="col-md-6">                                    
                                                <div class="form-group float-clear">
                                                    <label>Now Paying</label>
                                                    <input type="text" class="form-control readonly" name="paid_amount" placeholder="0.00" value="<?php echo $paid_amount->paidAmount;?>" readonly />
                                                </div>
                                            </div>

                                        </div>
                                 
                                        <div class="row" id="cheque-box">
                                            <?php foreach( $payments as $k => $ptype ) : 
                                                $paidtype = $this->temple_institution_model->get_paid_type($temple_institute->type_id,$temple_institute->id,$ptype->id);
                                               
                                               if($ptype->slug == 'cheque' && $paidtype->pay_type_id == $ptype->id) :
                                                
                                                $pay_details   = !empty($paidtype->pay_details) ? json_decode($paidtype->pay_details) : '';
                                                $pay_details   = !is_array($pay_details) ? get_object_vars($pay_details) : $pay_details; ?>
                                                
                                                <input type="hidden" class="hidden_bank_name"  name="hidden_bank_name" value="<?php echo (!empty($pay_details['name'])) ? $pay_details['name'] : '';?>"/>
                                                <input type="hidden" class="hidden_chq_no"  name="hidden_chq_no" value="<?php echo (!empty($pay_details['no'])) ?  $pay_details['no'] : '';?>"/>
                                                <input type="hidden" class="hidden_chq_date"  name="hidden_chq_date" value="<?php echo (!empty($pay_details['date'])) ? (date('d-m-Y',strtotime($pay_details['date']))) : date('d-m-Y');?>"/>
                                                <?php endif;
                                            endforeach;
                                            ?>
                                            <div class="col-xs-4">                                    
                                                <div class="form-group float-clear">
                                                    <label>Bank Name</label>
                                                    <input type="text" class="form-control input"  name="chq_bnk_name" placeholder="Bank Name" value=""/>
                                                </div>
                                            </div>
                    
                                            <div class="col-xs-4">                                    
                                                <div class="form-group float-clear">
                                                    <label>No</label>
                                                    <input type="text" class="form-control input"  name="chq_no" placeholder="No" value=""/>
                                                </div>
                                            </div>
                                            
                                            <div class="col-xs-4">                                    
                                                <div class="form-group float-clear">
                                                    <label>Date</label>
                                                    <input type="text" class="form-control input date-picker"  name="chq_date" placeholder="dd/mm/YYYY" value="<?php echo date('d-m-Y');?>"/>
                                                </div>
                                            </div>
                    
                                        </div>                                 
                                        
                                        <div style="margin-top: 10px; border-top: 1px dotted #1ba; padding: 20px 0px;">
                                            <div class="row">
                                                <?php
                                                    $step = 4;
                                                    foreach( $payments as $k => $ptype ) :
                                                        $paidtype = $this->temple_institution_model->get_paid_type($temple_institute->type_id,$temple_institute->id,$ptype->id);
                                                        echo '<div class="col-md-'. floor( 12 / $step ) .'">';
                                                        $paidID = $this->temple_institution_model->get_paidID($temple_institute->type_id,$temple_institute->id,$ptype->id);
                                                        foreach($paidID as $i=>$paidid) { ?>
                                                            <input type="hidden" class="paid_hidden_id" name="paid_hidden_id[]" value="<?php echo $paidid->id;?>" />
                                                        <?php } ?>
                                                            <div class="form-group float-clear blck-content ptype-box" id="ptype-box-<?php echo $ptype->slug; ?>" style="margin: 10px 10px;">
                                                                <div class="pay-box">
                                                                    <?php if( !empty( $ptype->img_url ) && file_exists( DIR_PAY_TYPE . $ptype->img_url ) ) : ?><div id="pay-preview"><img src="<?php echo BASE_URL . DIR_PAY_TYPE . $ptype->img_url; ?>" /></div><?php endif; ?>
                                                                    <label><?php echo $ptype->name; ?></label>
                                                                </div>
                                                                <input type="text" class="input pay-type amount num-pad" data-id="<?php echo $ptype->id; ?>" name="pay_type[<?php echo $ptype->id; ?>]" value="<?php echo ((!empty($paidtype)) && $ptype->id == $paidtype->pay_type_id) ? $paidtype->pay_amount : ''; ?>" />
                                                            </div>
                                                        <?php
                                                        echo '</div>';

                                                        if( ($k+1) % $step == 0 ) :
                                                            echo '</div><div class="row">';
                                                        endif;

                                                    endforeach;
                                                ?>
                                            </div>
                                        </div>
                                        

                                    </div>

                                    <div class="modal-footer" style="padding-right: 30px;">
                                        <button type="button" class="btn btn-primary cancel_popup" id="sbmt-cancel-btn" data-dismiss="modal"><i class="fa fa-chevron-left"></i> Go Back</button>
                                        <button type="submit" id="sbmt-btn" class="btn btn-danger"><i class="fa fa-floppy-o"></i> Submit</button>
                                    </div>
                            </div>   <!-- Modal Content -->     
                        </div> 
                    </div> <!-- Payment Types Dialog -->
                </form>
            </div><!-- /.col-xs-12 -->
        </div><!-- /.row -->
    </section><!-- /.content -->
</aside>


