<?php

/* 
 * Author       : Jai K
 * Purpose      : The Edit page for Kattalai Archanai
 * Created On   : 2016-09-08 17:22
 */

$bk = $results[0];
foreach( $payments as $k => $pay ) :
    $payments_arr[$pay['pay_type_id']] = $pay;
endforeach;
?>
<?php header('Content-Type: text/html; charset=utf-8'); ?>
<aside class="right-side edit-page" id="kattalai">
    <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;?>" method="post"  enctype="multipart/form-data" method="post" >    
                    <input type="hidden" name="token" value="<?php echo $token; ?>" />    
                    <input type="hidden" name="hidden_id" value="<?php echo $id; ?>" />
                    <input type="hidden" name="hidden_edit_id" value="<?php echo $id; ?>" />
                    <input type="hidden" name="book_status" value="<?php echo $bk['bk_book_status']; ?>" />
                    <div class="box box-danger">
                        <div class="box-body">
                            <?php if( !empty( $success ) || !empty( $error ) ) : ?>
                                <div class="alert alert-<?php echo !empty( $success ) ? 'success' : 'danger'; ?> alert-dismissable">
                                    <i class="fa fa-thumbs-o-<?php echo !empty( $success ) ? 'up' : 'down'; ?>"></i>
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                    <h4><?php echo !empty( $success ) ? $success : $error; ?></h4>
                                </div>
                            <?php endif; ?>
                            
                            <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" placeholder="Auto Generated" readonly value="<?php echo (($general->prefix == 1) ? $service['prefix'] : '') . $bk['bk_rec_no']; ?>"/>
                                    </div>
                                </div>
                                
                                <!--<div class="col-md-6">
                                    <div class="form-group float-clear" style="text-align: right;">
                                        <!-- Currently Disabled <button class="btn btn-success dialog-btn" data-target="#booked-dialog" id="bkd-btn"><i class="fa fa-book"></i> Booked Details</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> Archanai 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>Archanai Type<span class="required">*</span></label>
                                            <div class="input-group" style="width: 66%;">                                                
                                                <input type="text" class="form-control readonly" name="type_name" value="<?php echo $bk['service_name'];?>" readonly />
                                                <input type="hidden" name="fn_type" data-amt="<?php echo $bk['ser_amount']; ?>" value="<?php echo $bk['service_id'];?>" />
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Name 1<span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="name_1" placeholder="Name 01" data-err-target="#ct-details-btn" value="<?php echo $bk['bk_name_1']; ?>"/>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Name 2</label>
                                            <input type="text" class="form-control name" name="name_2" placeholder="Name 02" value="<?php echo $bk['bk_name_2']; ?>"/>
                                        </div>

                                        <div class="form-group float-clear">
                                            <label>Name 3</label>
                                            <input type="text" class="form-control name" name="name_3" placeholder="Name 03" value="<?php echo $bk['bk_name_3']; ?>"/>
                                        </div>

                                        <div class="form-group float-clear">
                                            <label>Contact No</label>
                                            <input type="text" class="form-control contact-no num-pad" name="contact_no" value="<?php echo $bk['contact_no']; ?>" />
                                        </div>
                                        
                                        <div class="form-group">
                                            <label>Star 1</label>
                                            <div class="input-group">
                                                <select name="star_1" class="form-control select2 star">
                                                    <option value="">-- Select Star 1 --</option>
                                                    <?php foreach( $stars as $k => $star ) : ?>
                                                    <option value="<?php echo $star['id']; ?>" <?php echo $star['id'] == $bk['bk_star_1'] ? 'selected' : ''; ?>><?php echo $star['name'] . ' / ' . $star['tamil_name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label>Star 3</label>
                                            <div class="input-group">
                                                <select name="star_3" class="form-control select2 star">
                                                    <option value="">-- Select Star 3 --</option>
                                                    <?php foreach( $stars as $k => $star ) : ?>
                                                    <option value="<?php echo $star['id']; ?>" <?php echo $star['id'] == $bk['bk_star_3'] ? 'selected' : ''; ?>><?php echo $star['name'] . ' / ' . $star['tamil_name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Description</label>
                                            <textarea class="form-control" name="desc"><?php echo $bk['bk_desc']; ?></textarea>
                                        </div>
                                    </div>

                                    <div class="col-md-6">                                    
                                        <div class="form-group" id="deity_input">
                                            <label>Deity</label>
                                            <div class="input-group" style="width: 66%;">
                                                <select name="fn_deity" class="form-control multi-select">
                                                    <option value="">-- Select Deity --</option>
                                                    <?php foreach( $gods as $k => $god ) : ?>
                                                    <option value="<?php echo $god['id']; ?>" data-price="<?php echo $god['price']; ?>"><?php echo $god['name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <?php if(count($prasadams) > 0) { ?>
                                        <div class="form-group" id="prasadam_period">
                                            <label>Period<span class="required">*</span></label>
                                            <div class="input-group" style="width: 66%;">
                                                <select name="pr_period" class="form-control select2 pr_period">
                                                    <option value="1" <?php if($prasadams[0]->period == 1){?> selected="selected"<?php } ?>>Morning</option>
                                                    <option value="2" <?php if($prasadams[0]->period == 2){?> selected="selected"<?php } ?>>Evening</option>
                                                </select>
                                            </div>
                                        </div>
                                        <?php } ?>
                                        
                                        <div class="form-group">
                                            <label>Name 1 (T)</label>
                                            <div class="input-group">
                                                <input class="form-control multi tamil-name input-tamil" type="text" name="tamil_name_1" placeholder="jkpH;bgah;" onclick="set_tamil_keypad(this);" value="<?php echo $bk['bk_tamil_name_1']; ?>" />
                                                <div class="input-group-addon"><i class="fa fa-keyboard-o"></i></div>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group">
                                            <label>Name 2 (T)</label>
                                            <div class="input-group">
                                                <input class="form-control multi tamil-name input-tamil" type="text" name="tamil_name_2" placeholder="jkpH;bgah;" onclick="set_tamil_keypad(this);" value="<?php echo $bk['bk_tamil_name_2']; ?>"/>
                                                <div class="input-group-addon"><i class="fa fa-keyboard-o"></i></div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label>Name 3 (T)</label>
                                            <div class="input-group">
                                                <input class="form-control multi tamil-name input-tamil" type="text" name="tamil_name_3" placeholder="jkpH;bgah;" onclick="set_tamil_keypad(this);" value="<?php echo $bk['bk_tamil_name_3']; ?>"/>
                                                <div class="input-group-addon"><i class="fa fa-keyboard-o"></i></div>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group">
                                            <label>Star 2</label>
                                            <div class="input-group">
                                                <select name="star_2" class="form-control select2 star">
                                                    <option value="">-- Select Star 2 --</option>
                                                    <?php foreach( $stars as $k => $star ) : ?>
                                                    <option value="<?php echo $star['id']; ?>" <?php echo $star['id'] == $bk['bk_star_2'] ? 'selected' : ''; ?>><?php echo $star['name'] . ' / '. $star['tamil_name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                        </div>
                                       <?php if($p_items[0]->bkp_day_type && (($p_items[0]->bkp_day_type == 1) || ($p_items[0]->bkp_day_type == 2))) { ?> 
                                        <div id="dates">                                        	 
                                            <div class="form-group float-clear">
                                                <label>Start Date</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker" id="start-date" placeholder="dd/mm/yyyy" value="<?php echo date("d-m-Y", strtotime($bk['bk_begin_date'])); ?>" />
                                                    <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                                </div>
                                            </div>

                                            <div class="form-group float-clear">
                                                <label>End Date</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker" id="end-date" placeholder="dd/mm/yyyy" value="<?php echo date("d-m-Y", strtotime($bk['bk_end_date'])); ?>" />
                                                    <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                                </div>
                                            </div>
                                        </div>
                                       <?php }elseif($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 3) { ?> 
                                        <div id="multiple-dates">
                                            <div class="form-group float-clear">
                                                <label>Date(s)</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker multiple" name="multi_date" placeholder="dd/mm/yyyy" value="" data-callback="setDayCount();" />
                                                     <?php $multidates	=  explode(",", $p_items[0]->dates); ?>
                                                     <div class="date-preview" id="multiple-multi-date">
                                                     	<?php foreach($multidates as $date){ ?>
                                                        <?php 
															$e 			= explode('-', $date);
															$wos_date	= $e[2].$e[1].$e[0];
														?>
                                                    	<div class="option" id="multiple-multi-date-<?php echo $wos_date; ?>" style="margin-left: 1px !important;">
                                                        	<i class="fa fa-times rm-btn"></i> <?php echo $date; ?><input type="hidden" name="multi_date[]" value="<?php echo $date; ?>">
                                                        </div>
                                                        <?php } ?>
                                                   </div>
                                                </div>
                                            </div>
                                        </div>
                                        <?php }else{ ?>
                                        <div id="dates">                                        	 
                                            <div class="form-group float-clear">
                                                <label>Start Date</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker" id="start-date" placeholder="dd/mm/yyyy" value="<?php echo date("d-m-Y"); ?>" />
                                                    <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                                </div>
                                            </div>

                                            <div class="form-group float-clear">
                                                <label>End Date</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker" id="end-date" placeholder="dd/mm/yyyy" value="<?php echo date("d-m-Y");//, strtotime("+5 Day")); ?>" />
                                                    <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <div id="multiple-dates" style="display: none;">
                                            <div class="form-group float-clear">
                                                <label>Date(s)</label>
                                                <div class="input-group">
                                                    <input type="text" class="form-control date-picker multiple" name="multi_date" placeholder="dd/mm/yyyy" value="" data-callback="setDayCount();" />
                                                </div>
                                            </div>
                                        </div>
                                        <?php } ?>
                                    </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> No of Days/Weeks</h4><i class="ctrl opener fa fa-chevron-up opened" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content row">
                                    <div id="days-wrapper" class="col-xs-12">
                                        <div class="col-md-6">     
                                            <div class="form-group">
                                                <input type="hidden" id="expanded-dates" value="<?php echo date("d-m-Y"); ?>">
                                                <label>Type<span class="required">*</span></label>
                                                <div class="input-group" style="width: 66%;">
                                                    <input type="radio" name="choose-day-type" id="day-type-1" class="day-type" value="1" <?php if($p_items[0]->bkp_day_type) { echo ($p_items[0]->bkp_day_type == 1)? "checked": "disabled"; }else{ echo "checked"; } ?>  >&nbsp;&nbsp;&nbsp;<label for="day-type-1">Daily</label>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label>&nbsp;</label>    
                                                <div class="input-group" style="width: 66%;">    
                                                    <input type="radio" name="choose-day-type" id="day-type-2" class="day-type" value="2" <?php if($p_items[0]->bkp_day_type) { echo ($p_items[0]->bkp_day_type == 2)? "checked": "disabled"; }else{ echo ""; } ?>>&nbsp;&nbsp;&nbsp;<label for="day-type-2">Weekly</label>
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label>&nbsp;</label>    
                                                <div class="input-group" style="width: 66%;">    
                                                    <input type="radio" name="choose-day-type" id="day-type-3" class="day-type" value="3" <?php if($p_items[0]->bkp_day_type) { echo ($p_items[0]->bkp_day_type == 3)? "checked": "disabled"; }else{ echo ""; } ?>>&nbsp;&nbsp;&nbsp;<label for="day-type-3">Multiple Date(s)</label>
                                                </div>
                                            </div>

                                        </div>

                                        <div class="col-md-6">                                    
                                            <div class="form-group float-clear">
                                                <label>Total No. of Days</label>
                                                <input type="text" class="form-control readonly" id="no-of-days" placeholder="0" readonly value="<?php if($p_items[0]->bkp_no_days > 0) { echo $p_items[0]->bkp_no_days; }else{ echo "1"; } ?>"/>
                                            </div>


                                            <div class="form-group" id="week-days" style="display: none;">
                                                <label>Day</label>
                                                <div class="input-group">                                                    
                                                    <select id="weekly-day" class="form-control select2">
                                                        <option value="0" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 0)? "selected": ""; }else{ echo ""; } ?>>Sunday</option>
                                                        <option value="1" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 1)? "selected": ""; }else{ echo "selected"; } ?>>Monday</option>
                                                        <option value="2" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 2)? "selected": ""; }else{ echo ""; } ?>>Tuesday</option>
                                                        <option value="3" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 3)? "selected": ""; }else{ echo ""; } ?>>Wednesday</option>
                                                        <option value="4" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 4)? "selected": ""; }else{ echo ""; } ?>>Thursday</option>
                                                        <option value="5" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 5)? "selected": ""; }else{ echo ""; } ?>>Friday</option>
                                                        <option value="6" <?php if($p_items[0]->bkp_day_type && $p_items[0]->bkp_day_type == 2) { echo ($p_items[0]->bkp_week_day == 6)? "selected": ""; }else{ echo ""; } ?>>Saturday</option>
                                                    </select>
                                                </div>
                                            </div>
                                            
                                            <div class="form-group float-clear">
                                                <label>&nbsp;</label>
                                                <div class="ctrls" id="calculate_btn"><i class="fa fa-crosshairs add-btn"></i></div>
                                            </div>

                                        </div>
                                        
                                        <?php
										/*
										 * Items
										 */
										?>
                                        <div id="days-plot">
                                            <table>
                                                <thead>
                                                    <tr>
                                                        <th width="17%">Type</th>
                                                        <th width="23%">Deity(s)</th>
                                                        <th width="30%">Date(s)</th>
                                                        <th width="14%">No. of Days</th>
                                                        <th>Amount</th>
                                                        <th>Action</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                               <?php
                                                   $total_no_days = $total_amt = 0;
                                                   foreach( $items as $k => $item ) :
                                                       $day_type = $item['bki_day_type'];
                                                       $start_date = date("d-m-Y", strtotime( $item['bki_from_date'] ));
                                                       $to_date = date("d-m-Y", strtotime( $item['bki_to_date'] ));

                                                       $total_no_days  += $item['bki_no_days'];
                                                       $total_amt      += $item['bki_amount']; 
                                                       ?>
                                                    <tr <?php echo $k % 2 != 0 ? 'style="background: #fff; "' : ''; ?>>
                                                        <input type="hidden" name="bki_id[]" class="db-id" value="<?php echo $item['id']; ?>">    
                                                            <td>
                                                                <?php echo $day_type == '1' ? 'Daily' : ($day_type == '2' ? 'Weekly - <b style="font-size: 12px; color: #1ba;">'. $week[$item['bki_week_day']] .'</b>' : 'Multiple Date(s)'); ?>
                                                                <input type="hidden" name="day_type[]" value="<?php echo $day_type; ?>">
                                                                <input type="hidden" name="weekly_day[]" value="<?php echo $item['bki_week_day']; ?>">
                                                            </td>     

                                                            <td>
                                                                <?php echo $item['god_names']; ?>
                                                                <input type="hidden" name="deity[]" value="<?php echo $item['bki_god_ids']; ?>">
                                                                <input type="hidden" name="expand_dates[]" value="<?php echo $item['bki_dates']; ?>">
                                                            </td>

                                                            <td>
                                                                <?php echo $day_type == '3' ? $item['bki_dates'] : $start_date .'<b style="color: #999;"> to </b>'. $to_date; ?>
                                                                <input type="hidden" name="start_date[]" value="<?php echo $start_date; ?>">
                                                                <input type="hidden" name="end_date[]" value="<?php echo $to_date; ?>">
                                                            </td>

                                                            <td align="center"><?php echo $item['bki_no_days']; ?><input type="hidden" name="no_of_days[]" class="no-of-days" value="<?php echo $item['bki_no_days']; ?>"></td>

                                                            <td align="right"><?php echo $item['bki_amount']; ?><input type="hidden" name="days_amt[]" class="days-amt" value="<?php echo $item['bki_amount']; ?>"></td>

                                                            <td class="ctrls"><i class="fa fa-times rm-btn"></i></td>
                                                        </tr>     
                                                   <?php
                                                       endforeach;
                                               ?>
                                                </tbody>
                                                <tfoot>
                                                    <tr>
                                                        <td colspan="3"></td>
                                                        <td id="total-days" align="center"><?php echo $total_no_days; ?></td>
                                                        <td id="net-amt" align="right"><?php echo number_format( $total_amt, 2, '.', ''); ?></td>
                                                        <td>&nbsp;</td>
                                                    </tr>
                                                </tfoot>
                                            </table>
                                        </div> <!-- days-plot -->                                        
                                    </div> <!-- Days Wrapper -->                                    
                                </div> <!-- blck-content -->    
                            </div> <!-- blck -->
                            
                            <!--PRASADAM ITEMS BLCK-->
                            <div class="col-xs-12 blck err-target-wrapper innr-table">
                                <div class="sub-title err-target" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Add Prasadam Items</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-xs-12">                                    
                                        <div class="col-md-3"> 
                                            <label>Deity<span class="required" id="required"></span></label>
                                        </div>
                                        
                                        <div class="col-md-3"> 
                                            <label>Prasadam<span class="required"></span></label>
                                        </div>
                                        
                                        <div class="col-md-1"> 
                                            <label>Quantity<span class="required"></span></label>
                                        </div>
                                        
                                        <div class="col-md-2"> 
                                            <label>Price<span class="required"></span></label>
                                        </div>
                                        <div class="col-md-2"> 
                                            <label>Sub Total</label>
                                        </div>
                                        <div class="col-md-1"> 
                                            <label>&nbsp;</label>
                                        </div>
                                    </div>    
                                    
                                    <?php                                    
                                        $p_items = !empty($p_items) ? $p_items : array('');
										//echo "<pre>"; print_r($p_items); exit;																				
                                        $items_cnt = is_array($p_items) ? count($p_items) : 0;
                                        foreach( $p_items as $ik => $item ) :
                                    ?>
                                            <div class="col-xs-12 row-details" data-strings="<?php echo $item->deity_id .'-' . $item->prasadam;?>">   
                                                <input type="hidden" name="pr_id[]" class="db-id" value="<?php echo $item->id; ?>" />
                                                <input type="hidden" class="form-control low-width pr-day" name="pr_day_type[]" value="<?php echo $item->bkp_day_type; ?>" placeholder="0"/>
                                                <input type="hidden" class="form-control low-width pr-dates" name="pr_expand_dates[]" value="<?php echo $item->dates; ?>" placeholder="0"/>
                                                <input type="hidden" class="form-control low-width pr-week-day" name="pr_weekly_day[]" value="<?php echo $item->bkp_week_day; ?>" placeholder="0"/>
                                                <input type="hidden" class="form-control low-width pr-no-day" name="pr_no_of_days[]"  value="<?php echo $item->bkp_no_days; ?>" placeholder="0"/>
                                                <div class="col-md-3">
                                                    <select name="pr_deity[]" class="form-control select2 pr-deity" onchange="get_deity_name(this);">
                                                        <option value="">-- Select Deity --</option>
                                                        <?php foreach( $gods as $k => $god ) :?>
                                                        <option value="<?php echo $god['id']; ?>" <?php echo $item->deity_id == $god['id'] ? 'selected' : ''; ?>><?php echo $god['name']; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>

                                                <div class="col-md-3">
                                                    <select name="pr_prasadam[]" class="form-control select2 pr-prasadam" onchange="get_prasadam_name(this);">
                                                        <option value="">-- Select Prasadam --</option>
                                                        <?php foreach( $prasadams as $k => $prasadam ) :?>
                                                        <option value="<?php echo $prasadam['id']; ?>" <?php echo $item->prasadam == $prasadam['id'] ? 'selected' : ''; ?>><?php echo $prasadam['name']; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>

                                                <div class="col-md-1">                                    
                                                    <input type="text" class="form-control low-width pr-qty amount num-pad" name="pr_qty[]" placeholder="0"  style="min-width: 60px;" value="<?php echo $item->quantity; ?>"/>
                                                </div>

                                                <div class="col-md-2">                                    
                                                    <input type="text" class="form-control pr-price amount num-pad" name="pr_price[]" placeholder="0.00" style="text-align: right;" value="<?php echo $item->price; ?>" readonly />
                                                </div>

                                                <div class="col-md-2">                                    
                                                    <input type="text" class="form-control readonly stotal" name="pr_stotal[]" placeholder="0.00" style="text-align: right;" readonly value="<?php echo $item->sub_total; ?>"/>
                                                </div>

                                                <div class="col-md-1 ctrls">   
                                                	<?php if( $items_cnt > 1 ) : ?> 
                                                    <i class="fa fa-power-off rm-btn" style="color: #f00;"></i>
                                                   	<?php endif; ?>
                                                    
                                                    <?php if( $ik+1 == $items_cnt ) : ?>
                                                        <i class="fa fa-plus-circle add-btn"></i> 
                                                    <?php endif; ?>
                                                </div>    
                                            </div> <!-- col-xs-12 -->
                                    <?php endforeach; ?>                                    
                                </div> <!-- blck-content -->                                
                            </div> <!-- blck -->
                            
                            <div style="clear:both; height:20px;"></div>
                             <div class="col-xs-12">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>Final Amount</label>
                                        <input type="text" class="form-control amount num-pad amtHide" name="total_amount" placeholder="0.00" value="<?php echo $bk['bk_amount']; ?>"/>
                                    </div>
                                </div>
                            </div>
 
                            
                        </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>
                            <?php /* Currently Disabled if($bk['bk_book_status'] == 2) {?>
                                <button type="submit" class="btn btn-success sbmt-btn" name="book_now" value="book-now" ><i class="fa fa-thumb-tack"></i> Book Now</button>
                            <?php } */?>
                                <button type="button" class="btn btn-danger sbmt-btn" id="payment-btn" data-paid-amt="<?php echo $bk['bk_paid_amount']; ?>"><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" readonly value="<?php echo $bk['bk_amount']; ?>"/>
                                                </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" readonly value="<?php echo $bk['bk_paid_amount']; ?>" />
                                                </div>
                                            </div>

                                        </div>
                                        
                                        <div class="row" id="cheque-box">
                                            <?php foreach( $payment_detail as $k => $ptype ) : 
                                                $paidtype = $this->kattalai_archanai_model->get_paid_type(8,$bk['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( $ptypes as $k => $ptype ) :

                                                        echo '<div class="col-md-'. floor( 12 / $step ) .'">';
                                                        ?> 
                                                        <div class="form-group float-clear blck-content ptype-box" id="ptype-box-<?php echo $ptype['slug']; ?>" style="margin: 0px 10px;">
                                                            <div class="pay-box">
                                                                <div id="pay-preview"><?php if( !empty( $ptype['img_url'] ) && file_exists( $ptype['img_url'] ) ) : ?><img src="<?php echo BASE_URL . $ptype['img_url']; ?>" /><?php endif; ?></div>
                                                                <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 $payments_arr[$ptype['id']]['pay_amount']; ?>" />
                                                        </div>
                                                        <?php
                                                        echo '</div>';

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

                                                    endforeach;
                                                ?>
                                            </div>
                                        </div>-->
                                        
                                        <div style="margin-top: 10px; border-top: 1px dotted #1ba; padding: 20px 0px;">
                                            <div class="row">
                                                <?php
                                                    $step = 4;
                                                    foreach( $payment_detail as $k => $ptype ) :
                                                        $paidtype = $this->kattalai_archanai_model->get_paid_type(8,$bk['id'],$ptype->id);
                                                        echo '<div class="col-md-'. floor( 12 / $step ) .'">';
                                                        $paidID = $this->kattalai_archanai_model->get_paidID(8,$bk['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" name="submit" value="Submit"><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 -->
        
        <!-- Start Modal -->
        <div class="modal fade" id="booked-dialog" role="dialog">
            <div class="modal-dialog" style="width: 90%;">
                <!-- Modal content-->
                <div class="modal-content">

                    <div class="modal-header" style="background-color: #337AB7;">
                        <button type="button" class="close cancel_popup" data-dismiss="modal" style="color: #FFF;">x</button>
                        <h4 class="modal-title" style="color: #FFF;">Booked Details</h4>
                    </div>
                    <div class="modal-body col-xs-12" style="margin-bottom: 30px; border-bottom: 1px dotted #1ba;">
                    
                        
                        <form name="m">
                                                                 
                                <div class="col-xs-3">
                                    <label>Start Date</label>
                                    <input type="text" class="form-control bk_from_date" name="bk_from_date" placeholder="dd/mm/yyyy" value="" />
                                </div>

                                <div class="col-xs-3">
                                    <label>End Date</label>
                                    <input type="text" class="form-control bk_to_date" name="bk_to_date" placeholder="dd/mm/yyyy" value="" />
                                </div>  
                                  
                                <div class="col-xs-4" style="text-align: right; padding: 25px 0px; margin-left: -35px; z-index: 99;">
                                    <button type="button" class="btn btn-primary reset-btn"><i class="fa fa-times"></i> Reset</button>
                                    <button type="button" class="btn btn-danger filter-btn"><i class="fa fa-filter"></i> Filter</button>
                                    <button type="button" class="btn btn-primary cancel_popup" data-dismiss="modal"><i class="fa fa-ban"></i> Cancel</button>

                                </div>
                        </form>

                    </div>

                    <div class="modal-footer" style="padding-right: 30px;">
                        
                    </div>


                </div>   <!-- Modal Content -->     
            </div> 
        </div> <!-- Booked Dialog -->

    <!-- End Modal -->
    </section><!-- /.content -->
</aside>
<script type="text/javascript" src="<?php echo base_url() . 'assets/js/billing/kattalai_archanai.js'?>"></script>

