<?php

/* 
 * Author       : Govind M
 * Purpose      : The edit page for Temple Shop Sales Billing
 * Created On   : 2017-01-28 
 */
?>
<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;?>" method="post"  enctype="multipart/form-data" method="post" >    
                    <input type="hidden" name="hidden_id" value="<?php echo $templeshopsale->id;?>" />
                    <input type="hidden" name="type_id" value="<?php echo $templeshopsale->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" placeholder="Auto Generated" readonly value="<?php echo (($general->prefix == 1) ? $templeshopsale->prefix : '') . $templeshopsale->receipt_no;?>" />
                                    </div>
                                     <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 ($fn_type['id'] == $templeshopsale->service_id) ? 'selected' : '';?> ><?php echo $fn_type['name']; ?></option>
                                                <?php endforeach;?>
                                            </select>-->
                                            <input type="text" class="form-control readonly" name="type_name" value="<?php echo $templeshopsale->service;?>" readonly />
                                            <input type="hidden" name="fn_type" data-amt="<?php echo $templeshopsale->ser_amount; ?>" value="<?php echo $templeshopsale->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="#prasadam-dialog" id="prasadam-btn"><i class="fa fa-leaf"></i> Item <span>(<?php echo count($items); ?>)</span></button>
                                        <button class="btn btn-success dialog-btn" data-target="#retrieve-dialog" id="bkd-btn"><i class="fa fa-file-text"></i> Retrieve 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> Contact 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>Name <span class="required">*</span></label>
                                            <input type="text" class="form-control req name" name="ct_dev_name_1" placeholder="Name 01" data-err-target=".sub-title" value="<?php echo $templeshopsale->devotee_name1;?>" />
                                        </div>
                                        
                                        <div class="form-group float-clear">
                                            <label>Contact No <span class="required">*</span></label>
                                            <div class="input-group">
                                                <input type="text" class="form-control contact-no req num-pad" name="ct_contact_no" placeholder="Contact No" value="<?php echo $templeshopsale->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="ct_email" placeholder="Email Address" value="<?php echo $templeshopsale->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>Address</label>
                                            <textarea class="form-control address" name="ct_address"><?php echo $templeshopsale->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 amtHide" name="cs_amount" placeholder="0.00" value="<?php echo $templeshopsale->f_amount;?>" />
                                            <input type="hidden" name="prev_paid_amount" value="<?php echo $templeshopsale->f_amount; ?>" />
                                            <input type="hidden" class="form-control amount num-pad hidden_amount amtShow" name="hidden_amount" placeholder="0.00" value="<?php echo $templeshopsale->f_amount;?>" />
                                        </div>
                                    </div>

                                    <div class="col-md-6">                                    
                                        <div class="form-group float-clear">
                                            <label>Description</label>
                                            <textarea class="form-control" name="cs_desc"><?php echo $templeshopsale->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" readonly value="<?php echo $templeshopsale->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 $paid_amount->paidAmount;?>" />
                                                </div>
                                            </div>

                                        </div>

                                        <div class="row" id="cheque-box">
                                            <?php foreach( $ptypes as $k => $ptype ) : 
                                                $paidtype = $this->temple_shop_sales_model->get_paid_type($templeshopsale->type_id,$templeshopsale->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 ) :
                                                        $paidtype = $this->temple_shop_sales_model->get_paid_type($templeshopsale->type_id,$templeshopsale->id,$ptype['id']);
                                                        echo '<div class="col-md-'. floor( 12 / $step ) .'">';
                                                        $paidID = $this->temple_shop_sales_model->get_paidID($templeshopsale->type_id,$templeshopsale->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 -->
                    
                    <!-- Prasadam Modal -->
                    <div class="modal fade" id="prasadam-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;">Add Item</h4>
                                    </div>
                                    <div class="modal-body col-xs-12">
                                        <ul class="error_container"></ul>

                                              <div class="col-md-6">                                    
                                                <div class="form-group">
                                                    <label>Item<span class="required">*</span></label>
                                                    <div class="input-group">
                                                        <select id="pr_item" class="form-control select2 ignore req">
                                                            <option value="" data-sellprice="">-- Select Item --</option>
                                                            <?php foreach( $inventory_item as $k => $row ) :?>
                                                                <option value="<?php echo $row['item_id']; ?>" data-sbqty="<?php echo $row['total_quantity']; ?>" data-sellprice="<?php echo $row['selling_price']; ?>"><?php echo $row['item_name']; ?></option>
                                                            <?php endforeach;?>
                                                        </select>
                                                    </div>
                                                </div>
                                                  
                                                <div class="form-group float-clear">
                                                    <label>Price<span class="required">*</span></label>
                                                    <input type="text" class="form-control ignore req pr_price amount num-pad" id="pr_price" placeholder="0.00" />
                                                </div>  
                                                
                                            </div>

                                            <div class="col-md-6">                                    

                                                <div class="form-group float-clear">
                                                    <label>Quantity<span class="required">*</span></label>
                                                    <input type="text" class="form-control ignore req amount num-pad" id="pr_qty" placeholder="Quantity" value="" />
                                                </div>

                                            </div> 


                                    </div>

                                    <div class="modal-footer" style="padding-right: 30px;">
                                        <?php
                                            $itm_details = array();
                                            foreach( $items as $k => $item ) :
                                                $itm_details[] = array(
                                                    'id'    => $item['id'],
                                                    'inventory_item_id'=> $item['inventory_item_id'],
                                                    'quantity'=> $item['quantity'],
                                                    'price'=> $item['price'],
                                                );
                                            endforeach;
                                        ?>
                                        <input type="hidden" id="prasadam-hidden-details" value='<?php echo json_encode( $itm_details ); ?>' />
                                        <button type="button" class="btn btn-primary new-btn can-btn"><i class="fa fa-plus"></i> Add</button>
                                        <button type="button" class="btn btn-danger save-btn can-btn"><i class="fa fa-floppy-o"></i> Save<span> (<?php echo count($items); ?>)</span></button>
                                        <button type="button" class="btn btn-primary can-btn cancel_popup" data-dismiss="modal"><i class="fa fa-ban"></i> Cancel</button>
                                    </div>
                                

                            </div>   <!-- Modal Content -->     
                        </div> 
                    </div> <!-- Prasadam Dialog -->
                    
                    
                    
                </form>
            </div><!-- /.col-xs-12 -->
        </div><!-- /.row -->
        
        <!-- Start Modal -->
        
        <div class="modal fade" id="retrieve-dialog" role="dialog">
            <div class="modal-dialog" style="width:60%;">
                <!-- 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;">Retrieve Details</h4>
                    </div>
                    
                    <div class="modal-body ">
                        <form name="m">
                            <div class="col-xs-12" style="padding-bottom: 10px; margin-bottom: 20px;">
                                <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 p_fn_type ignore 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 $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" class="p_search_by_ref" name="p_search_by" value="1"  checked /> &nbsp;&nbsp;Name</label> 
                                            <label for="p_search_by" style="width: 32%;"><input type="radio" class="p_search_by_con" name="p_search_by" value="0" /> &nbsp;&nbsp;Contact No</label> 
                                        </div>
                                    </div>


                                    <div class="form-group search_devotee_name">
                                        <label>Name<span class="required">*</span></label>
                                        <div class="input-group">
                                            <select name="p_devotee_name" class="form-control select2 ignore req">
                                                <option value="">-- Select Name --</option>
                                            </select>
                                        </div>
                                    </div>


                                    <div class="form-group search_contact_no" style="display: none;">
                                        <label>Contact No<span class="required">*</span></label>
                                        <div class="input-group">
                                            <select name="p_contact_no" class="form-control select2 ignore req">
                                                <option value="">-- Select Contact No --</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group float-clear">
                                        <label>Name</label>
                                        <input type="text" class="form-control readonly name" name="p_name" value="" />
                                    </div>

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

                            </div>
                            <div class="col-xs-12">
                                <div style="text-align: center;">
                                    <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>
                            </div>
                        </form>
                    </div>
                        
                    <div class="modal-footer">
                        
                    </div>

                    
                </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/temple_shop.js'?>"></script>

