<?php

/* 
 * Author       : Jai K
 * Purpose      : The edit page for Billing - Wedding Hall Booking
 * Created On   : 2016-08-12 10:38    
 */
$bwh = $results[0];

foreach( $payments as $k => $pay ) :
    $payments_arr[$pay['pay_type_id']] = $pay;
endforeach;

?>
<aside class="right-side" id="edit-page">
    <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();
        $part_pay_rec_no = $this->wedding_booking_model->get_part_pay_rec_no($bwh['id']);
        $rec_no = explode(',',$part_pay_rec_no->receipt_no);  $Receipt = '';
        foreach($rec_no as $no) {
            if(!empty($no)) {
                $Receipt .= ((($general->prefix == 1) ? $service['prefix'] : '') . trim($no));
                $Receipt .= ',';
            }
        }
        $Rec = rtrim($Receipt,',');  
        $receipt = (!empty($Rec)) ? ' (' . $Rec .')' : '';    
    ?>
    <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; ?>" />                    
                    <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; ?>
                            
                            <div class="col-xs-12">
                                <div class="col-md-4">
                                    <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'] : '') . $bwh['bwh_rec_no']) . $receipt; ?>"/>
                                    </div>
                                </div>
                                
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label>Type<span class="required">*</span></label>
                                        <div class="input-group">
                                            <!--<select name="fn_type" class="form-control select2 req">
                                                <option value="">-- Select Type --</option>
                                                <?php 
                                                    foreach( $fn_types as $k => $fn_type ) :
                                                        ?>
                                                            <option value="<?php echo $fn_type['id']; ?>" data-amt="<?php echo $fn_type['amount']; ?>" data-prefix="<?php echo $fn_type['prefix']; ?>" <?php echo $bwh['service_id'] == $fn_type['id'] ? 'selected' : ''; ?>><?php echo $fn_type['name']; ?></option>
                                                        <?php
                                                    endforeach;
                                                ?>
                                            </select>-->
                                            
                                            <input type="text" class="form-control readonly" name="type_name" value="<?php echo $bwh['service_name'];?>" readonly />
                                            <input type="hidden" name="fn_type" data-amt="<?php echo $bwh['ser_amount']; ?>" value="<?php echo $bwh['service_id'];?>" />
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-md-4">
                                    <div class="form-group float-clear" style="text-align: right;">
                                        <button class="btn btn-success dialog-btn" data-target="#avail-dialog" id="avail-btn"><i class="fa fa-clock-o" style="color: #fff;"></i> Availability</button>
                                        <button class="btn btn-success dialog-btn" data-target="#pay-details-dialog" id="pay-details-btn"><i class="fa fa-book"></i> Payment Details</button>
                                    </div>
                                </div>
                            </div>    
                                    
                            <div class="col-xs-12 blck">
                                <div class="sub-title" id="per-details-btn" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Wedding 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 float-clear">
                                            <label>Groom Name<span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="groom_name" placeholder="Groom Name" data-err-target="#per-details-btn" value="<?php echo $bwh['bwh_groom_name']; ?>"/>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Wedding Date</label>
                                            <div class="input-group">
                                                <input type="text" class="form-control date-picker" name="fn_date" placeholder="dd/mm/yyyy" value="<?php echo date("d-m-Y", strtotime( $bwh['bwh_from_date'] )); ?>" data-err-target="#per-details-btn"/>
                                                <div class="input-group-addon"><i class="fa fa-calendar"></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 Address" data-err-target="#per-details-btn" value="<?php echo $bwh['bwh_email']; ?>"/>
                                                <div class="input-group-addon"><i class="fa fa-envelope"></i></div>
                                            </div>
                                        </div>
                                        
                                    </div>

                                    <div class="col-md-6">                                    
                                        <div class="form-group float-clear">
                                            <label>Bride Name<span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="bride_name" placeholder="Bride Name" data-err-target="#per-details-btn" value="<?php echo $bwh['bwh_bride_name']; ?>" />
                                        </div>
                                        
                                        <div class="form-group float-clear" style="padding: 3px 0px 33px 0px;">
                                            <label class="leftcol">Time</label>
                                            <label><input type="text" class="form-ctrl time-picker" style="text-align: right;" name="fn_from_time" placeholder="13:00" value="<?php echo date("H:i", strtotime($bwh['bwh_from_date'])); ?>" data-err-target="#per-details-btn" /> &nbsp;&nbsp;</label> 
                                            <label>&nbsp;To&nbsp;<input type="text" class="form-ctrl time-picker" style="text-align: right;" name="fn_to_time" placeholder="14:30" value="<?php echo date("H:i", strtotime($bwh['bwh_to_date'])); ?>" data-err-target="#per-details-btn"/></label>
                                        </div>
                                        
                                        <div class="form-group">
                                            <label>Period<span class="required">*</span></label>
                                            <div class="input-group">
                                                <select name="fn_period" class="form-control select2">
                                                    <option value="1" <?php echo $bwh['bwh_period'] == "1" ? 'selected' : ''; ?>>Morning</option>
                                                    <option value="2" <?php echo $bwh['bwh_period'] == "2" ? 'selected' : ''; ?>>Evening</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Address</label>
                                            <textarea class="form-control address" name="address"><?php echo $bwh['bwh_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> Document Details</h4><i class="ctrl opener fa fa-chevron-up opened" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label for="proof_1"><input type="checkbox" name="proof_1" value="1" <?php echo $bwh['bwh_groom_proof'] == "1" ? 'checked' : ''; ?>/> &nbsp;&nbsp;Groom ID Proof</label> 
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label for="proof_2"><input type="checkbox" name="proof_2" value="1" <?php echo $bwh['bwh_bride_proof'] == "1" ? 'checked' : ''; ?>/> &nbsp;&nbsp;Bride ID Proof</label> 
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label for="proof_3"><input type="checkbox" name="proof_3" value="1"  <?php echo $bwh['bwh_invitation_proof'] == "1" ? 'checked' : ''; ?>/> &nbsp;&nbsp;Wedding Invitation</label> 
                                        </div>
                                    </div>
                                        
                                </div>
                            </div> <!-- Doc. details -->    
                            
                            
                            <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-up opened" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12">
                                    <div class="col-md-6">     
                                        <div class="form-group float-clear">
                                            <label>Contact Name<span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="contact_name" placeholder="Contact Name" data-err-target="#per-details-btn" value="<?php echo $bwh['bwh_contact_name']; ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-6">     
                                        <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="#per-details-btn" value="<?php echo $bwh['bwh_contact_no']; ?>"/>
                                                <div class="input-group-addon"><i class="fa fa-phone"></i></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div> <!-- Contact details -->    
                            
                            <?php 
                            // Balance
                                $bal_amt = $bwh['bwh_amount'] - $bwh['bwh_paid_amount'];
                            ?>
                            <div class="col-xs-12 blck">
                                <div class="sub-title" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Payment Details</h4><i class="ctrl opener fa fa-chevron-up opened" style="float: right; margin-top: -25px;"></i></div>
                                <div class="blck-content col-xs-12">
                                    <div class="col-md-6">     
                                        <div class="form-group float-clear">
                                            <label>Total Amount</label>
                                            <input type="text" class="form-control amount readonly" name="amount" placeholder="0.00" readonly value="<?php echo $bwh['bwh_amount']; ?>"/>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Deposit Amount</label>
                                            <input type="text" class="form-control amount readonly" name="dep_amount" placeholder="0.00" readonly value="<?php echo $bwh['bwh_paid_amount']; ?>"/>
                                        </div>
                                        
                                    </div>

                                    <div class="col-md-6">      
                                        <div class="form-group float-clear">
                                            <label>Balance Amount</label>
                                            <input type="text" class="form-control readonly" placeholder="0.00" readonly value="<?php echo number_format( $bal_amt, 2); ?>"/>
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Description</label>
                                            <textarea class="form-control" name="desc"><?php echo $bwh['bwh_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="submit" class="btn btn-danger" id="payment-btn" name="submit" value="Submit"><i class="fa fa-undo"></i> Update</button>
                            
                        </div>
                    </div><!-- /.box -->
                    <?php /*
                    <!-- Payment types Modal -->
                    <div class="modal fade partial" 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><?php echo $bh['bwh_paid_amount'] > 0 ? 'Balance' : 'Amount'; ?> To Pay</label>
                                                    <input type="text" class="form-control readonly" name="pay_amount" placeholder="0.00" readonly  value="<?php echo $bal_amt; ?>"/>
                                                </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 $bal_amt; ?>"/>
                                                </div>
                                            </div>

                                        </div> 
                                        
                                        <div class="row" id="cheque-box" style="display: none;">
    
                                            <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="" />
                                                            </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;">
                                        <div id="pay-preview" style="float: left; box-shadow: 3px 3px 9px #ccc; border: 1px solid #eee; background: none;"><img src="<?php echo BASE_URL . 'assets/images/logo.png'?>" /></div>
                                        <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 -->
                     * */?>
                     
                    
                    <!-- Availability Modal -->
                    <div class="modal fade" id="avail-dialog" role="dialog">
                        <div class="modal-dialog" style="width: 80%;">
                            <!-- 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;">Availability</h4>
                                    </div>
                                    <div class="modal-body">
                                        <ul class="error_container"></ul>
                                        <div class=" col-xs-12 filter-box">
                                            <div class=" col-xs-10 col-xs-offset-1">
                                                <div class="col-md-4">                                    
                                                    <div class="form-group float-clear">
                                                        <label>From Date<span class="required">*</span></label>
                                                        <input type="text" class="form-control date-picker ignore req" name="a_from_date" placeholder="dd-mm-yyyy" value="" />
                                                    </div>
                                                </div>
                                                <div class="col-md-4">                                    
                                                    <div class="form-group float-clear">
                                                        <label>To Date<span class="required">*</span></label>
                                                        <input type="text" class="form-control date-picker ignore req" name="a_to_date" placeholder="dd-mm-yyyy" value="" />
                                                    </div>
                                                </div> 
                                                
                                                <div class="col-md-4" style="text-align: right;">                                    
                                                    <div class="form-group float-clear">
                                                        <label>&nbsp;</label>
                                                        <div style="float: left;">
                                                            <button type="button" class="btn btn-danger" id="chk-btn"><i class="fa fa-check"></i> Check</button>
                                                            <button type="button" class="btn btn-primary cancel_popup" data-dismiss="modal"><i class="fa fa-ban"></i> Close</button>
                                                        </div>    
                                                    </div>
                                                </div> 
                                            </div>
                                        </div>
                                    </div>

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

                            </div>   <!-- Modal Content -->     
                        </div> 
                    </div> <!-- Prasadam Dialog -->
                    
                    
                    
                </form>
            </div><!-- /.col-xs-12 -->
        </div><!-- /.row -->
        
        <!-- Start Modal -->
        
        
        
        <div class="modal fade" id="pay-details-dialog" role="dialog">
            <div class="modal-dialog">
                <!-- 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;">Payment Details</h4>
                    </div>
                    
                    <form>
                    <div class="modal-body ">
                        <div class="col-xs-12" style="padding-bottom: 30px; margin-bottom: 30px; border-bottom: 1px dotted #1ba;">
                            <div class="col-xs-10 col-xs-offset-1">
                                <div class="form-group">
                                    <label>Type<span class="required">*</span></label>
                                    <div class="input-group">
                                        <select name="p_fn_type" class="form-control select2">
                                            <option value="">-- Select Type --</option>
                                            <?php 
                                                foreach( $fn_types as $k => $fn_type ) :
                                                    ?>
                                                        <option value="<?php echo $fn_type['id']; ?>" data-amt="<?php echo $fn_type['amount']; ?>" data-prefix="<?php echo $fn_type['prefix']; ?>" ><?php echo $fn_type['name']; ?></option>
                                                    <?php
                                                endforeach;
                                            ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group m-h30">
                                    <label class="leftcol">Search By</label>
                                    <div>
                                        <label for="p_search_by" style="width: 32%;"><input type="radio" name="p_search_by" value="1"  checked/> &nbsp;&nbsp;Ref No</label> 
                                        <label for="p_search_by" style="width: 32%;"><input type="radio" name="p_search_by" value="0" /> &nbsp;&nbsp;Contact No</label> 
                                    </div>
                                </div>


                                <div class="form-group" id="p-ref-no-wrap">
                                    <label>Ref No<span class="required">*</span></label>
                                    <div class="input-group">
                                        <select name="p_ref_no" class="form-control select2">
                                            <option value="">-- Select Ref. No --</option>
                                        </select>
                                    </div>
                                </div>


                                <div class="form-group" id="p-cnt-no-wrap" style="display: none;">
                                    <label>Contact No<span class="required">*</span></label>
                                    <div class="input-group">
                                        <select name="p_contact_no" class="form-control select2">
                                            <option value="">-- Select Contact No --</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group float-clear">
                                    <label>Total Amount</label>
                                    <input type="text" class="form-control readonly amount num-pad" name="p_amount" placeholder="0.00" value="" disabled />
                                </div>

                                <div class="form-group float-clear">
                                    <label>Deposit Amount</label>
                                    <input type="text" class="form-control readonly amount num-pad" name="p_dep_amount" placeholder="0.00" value="" disabled />
                                </div>

                                <div class="form-group float-clear">
                                    <label>Payable Amount</label>
                                    <input type="text" class="form-control readonly amount num-pad" name="p_pay_amount" placeholder="0.00" value="" disabled />
                                </div>
                                
                                <div class="form-group">
                                    <label>Payment Mode<span class="required">*</span></label>
                                    <div class="input-group">
                                        <select name="p_mode" class="form-control select2">
                                            <?php foreach( $ptypes as $k => $ptype ) : ?>
                                                <option value="<?php echo $ptype['id'];?>" data-id="pay-<?php echo $ptype['slug']; ?>"><?php echo $ptype['name'];?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div> 
                            
                            <div class="col-xs-12" id="payment-cheque" style="display:none;">
                                <div class="row">
                                    <div class="col-xs-4">                                    
                                        <div class="form-group float-clear">
                                            <label>Bank Name<span class="required">*</span></label>
                                            <input type="text" class="form-control input"  name="bnk_name" placeholder="Bank Name" value=""/>
                                        </div>
                                    </div>
            
                                    <div class="col-xs-4">                                    
                                        <div class="form-group float-clear">
                                            <label>No<span class="required">*</span></label>
                                            <input type="text" class="form-control input"  name="cheque_no" placeholder="No" value=""/>
                                        </div>
                                    </div>
                                    
                                    <div class="col-xs-4">                                    
                                        <div class="form-group float-clear">
                                            <label>Date<span class="required">*</span></label>
                                            <input type="text" class="form-control input date-picker"  name="cheque_date" placeholder="dd/mm/YYYY" value="<?php echo date('d-m-Y');?>"/>
                                        </div>
                                    </div>
            
                                </div>
                            </div>

                        </div>

                    </div>

                    <div class="modal-footer" style="padding-right: 30px;">
                        <div id="p-ctrls">
                            <button type="button" class="btn btn-primary reset-btn"><i class="fa fa-times"></i> Reset</button>
                            <button type="button" class="btn btn-danger" id="pay-btn"><i class="fa fa-money"></i> Pay Now</button>
                            <button type="button" class="btn btn-primary cancel_popup" data-dismiss="modal"><i class="fa fa-ban"></i> Close</button>
                        </div>
                    </div>

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

