
<?php $this->load->view("common/header"); ?>
<!-- start: BODY -->
<body>
<!-- start: HEADER -->
<div class="navbar navbar-inverse navbar-fixed-top"> 
  <!-- start: TOP NAVIGATION CONTAINER -->
  <div class="container">
    <div class="navbar-header"> 
      <!-- start: RESPONSIVE MENU TOGGLER -->
      <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button"> <span class="fa fa-list"></span> </button>
      <!-- end: RESPONSIVE MENU TOGGLER --> 
      <!-- start: LOGO -->
      <?php $this->load->view("common/logo"); ?>
      <!-- end: LOGO --> 
    </div>
    <div class="navbar-tools"> 
      <!-- start: TOP NAVIGATION MENU -->
      <?php $this->load->view("common/notifications.php"); ?>
      <!-- end: TOP NAVIGATION MENU --> 
    </div>
  </div>
  <!-- end: TOP NAVIGATION CONTAINER --> 
</div>
<!-- end: HEADER --> 
<!-- start: MAIN CONTAINER -->
<div class="main-container">
  <div class="navbar-content"> 
    <!-- start: SIDEBAR -->
    <?php $this->load->view("common/navigation"); ?>
    <!-- end: SIDEBAR --> 
  </div>
  <!-- start: PAGE -->
  <div class="main-content"> 
    <!-- end: SPANEL CONFIGURATION MODAL FORM -->
    <div class="container"> 
      <!-- start: PAGE HEADER -->
      <div class="row">
        <div class="col-sm-12"> 
          <!-- start: PAGE TITLE & BREADCRUMB -->
          <ol class="breadcrumb">
            <li> <a href="<?php echo base_url('dashboard'); ?>"> Dashboard </a> </li>
            <li> <a href="<?php echo base_url('pos/hw_list'); ?>"> Sales </a> </li>
            <li class="active"> View </li>
            <li class="search-box">
              <form class="sidebar-search">
                <div class="form-group">
                  <input type="text" placeholder="Start Searching...">
                  <button class="submit"> <i class="fa fa-search"></i> </button>
                </div>
              </form>
            </li>
          </ol>
          <div class="page-header">
            <?php
                            $message = $this->session->flashdata('message');
                            if ($message) {
                                ?>
            <div class="alert alert-success">
              <button type="button" class="close" data-dismiss="alert">×</button>
              <?php echo $message ?> </div>
            <?php
                            }
            ?>
          </div>
        </div>
      </div>
      <!-- end: PAGE HEADER --> 
      <!-- start: PAGE CONTENT 
                <!-- start grid -->
      <div class="row">
        <div class="col-md-12"> 
          <!-- start: DYNAMIC TABLE PANEL -->
          <div class="panel panel-default">
            <div class="panel-heading"> <i class="fas fa-external-link-square-alt"></i> HW Sale Number -> <?php echo $sale_id ?>
              <div class="panel-tools" style="top:2px;">
                <button class="btn btn-blue dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-list"></i> </button>
                <ul class="dropdown-menu dropdown-light pull-right">
                  <li> <a id="" data-toggle="modal" href="<?php echo base_url('bar'); ?>"> <i class="fa fa-plus"></i> Add Sales </a> </li>
                </ul>
              </div>
              <!--panel-tools--> 
            </div>
            <!--panel-heading-->
            <div class="panel-body">
              <div class="well well-sm">
                <div class="col-xs-4 border-right">
                  <div class="col-xs-2"><i class="fa fa-3x fa-file-text-o padding010 text-muted"></i></div>
                  <div class="col-xs-10">
                    <h4 class="">Invoice No : <?php echo $sale_details['sale_reference_no']; ?></h4>
                    <p>Date: <?php echo display_date_time_format($sale_details['sale_datetime']) ?></p>
                    <?php
                                           
                                            if (empty($total_paid_amount)) {
                                                $pay_st = 'Pending';
                                            } else {
                                                if ($total_paid_amount >= $sale_details['sale_total']) {
                                                    $pay_st = 'Paid';
                                                } else {
                                                    $pay_st = 'Partial';
                                                }
                                            }
                                            ?>
                    <p>Sales Terms: <?php echo $sale_details['in_type']; ?></p>
                    <p>Payment Status : <?php echo $pay_st ?></p>
                    <?php if ($sale_details['sale_note']) { ?>
                    <p>Note : <?php echo $sale_details['sale_note']; ?></p>
                    <?php } ?>
                  </div>
                  <div class="clearfix"></div>
                </div>
                <div class="col-xs-4 border-right">
                  <div class="col-xs-2"><i class="fa fa-3x fa-user padding010 text-muted"></i></div>
                  <div class="col-xs-10">
                    <input type="hidden" id="cus_id" value="<?php echo $customer_details['cus_id']; ?>">
                    <h4 class=""><?php echo $customer_details['cus_name']; ?></h4>
                    <?php echo $customer_details['cus_address']; ?><br>
                    <p></p>
                    Tel: <?php echo $customer_details['cus_phone']; ?><br>
                    Email: <?php echo $customer_details['cus_email']; ?> </div>
                  <div class="clearfix"></div>
                </div>
                <div class="col-xs-4">
                  <div class="col-xs-2"><i class="fa fa-3x fa-building-o padding010 text-muted"></i></div>
                  <div class="col-xs-10">
                    <h4 class=""><?php echo $warehouse_details['name']; ?></h4>
                    <?php echo $warehouse_details['address']; ?>
                    <p></p>
                    Tel: <?php echo $warehouse_details['phone']; ?><br>
                    Email: <?php echo $warehouse_details['email']; ?> </div>
                  <div class="clearfix"></div>
                </div>
                <div class="clearfix"></div>
              </div>
              <!--col-xs-4-->
              
              <div class="col-xs-5">
                <input name="sale_id" type="hidden" id="sale_id" value="<?php echo $sale_id ?>">
                <input type="hidden" id="sale_type" name="sale_type" value="hw_sale">
                <input type="hidden" id="user_id" value="<?php echo $this->session->userdata('ss_user_id'); ?>">
                <div class="clearfix"></div>
              </div>
              <!--col-xs-4"-->
              <div class="clearfix"></div>
              <div class="table-responsive">
                <table class="table table-bordered table-hover table-striped print-table order-table">
                  <thead>
                    <tr class="report_view_th">
                      <th>No</th>
                      <th>Description (Code)</th>
                      <th>Quantity</th>
                      <th style="text-align:center; vertical-align:middle;">Unite Price</th>
                      <th style="padding-right:20px;">Discount</th>
                      <th style="padding-right:20px;">Subtotal</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                                            $tmpcount = 0;
                                            $tmptot = 0;
                                            foreach ($sale_item_list as $row) {
                                                $tmpcount++;

                                                $tmptot = $tmptot + $row['gross_total'];
                                                ?>
                    <tr>
                      <td style="text-align:center; width:40px; vertical-align:middle;"><?php echo $tmpcount ?></td>
                      <td style="vertical-align:middle;"><?php echo $row['product_name']; ?> (<?php echo $row['product_code']; ?>)
                        <?php if ($row['product_part_no']) echo ", Part No.:" . $row['product_part_no']; ?>
                        <?php if ($row['product_oem_part_number']) echo ", OEM Part No.:" . $row['product_oem_part_number']; ?></td>
                      <td style="width: 100px; text-align:center; vertical-align:middle;"><?php echo number_format($row['quantity'], 2, '.', ',') ?></td>
                      <td><?php echo number_format($row['unit_price'], 2, '.', ',') ?></td>
                      <td style="text-align:right; width:120px; padding-right:10px;">(<?php echo $row['discount'] ?>) <?php echo number_format($row['discount_val'], 2, '.', ',') ?></td>
                      <td style="text-align:right; width:120px; padding-right:10px;"><?php echo $row['gross_total']; ?></td>
                    </tr>
                    <?php } ?>
                  </tbody>
                  <tfoot>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Sub Total RS</td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($tmptot, 2, '.', ',') ?></td>
                    </tr>
                    <?php //$sale_details['sale_total']-$sale_details['cr_interest_amt']  ?>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Delivery Charge</td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['delivery_charge'], 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Order Discount (<?php echo $sale_details['sale_inv_discount'] ?>)</td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_inv_discount_amount'], 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">After Discount Sub Total RS</td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_total'] - $sale_details['cr_interest_amt'], 2, '.', ',') ?></td>
                    </tr>
                    <?php //if ($sale_details['cr_interest'])
                                            {
                                                ?>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Credit Sur Charge RS (<?php echo $sale_details['cr_interest'] ?>%) </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['cr_interest_amt'], 2, '.', ',') ?></td>
                    </tr>
                    <?php //if ($sale_details['customer_id']!=1)
                                            }
                                            ?>
                    <?php //if ($sale_details['customer_id']!=1)
{
    ?>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Grand Total </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_total'], 2, '.', ',') ?>
                        <input type="hidden" value="<?php echo $sale_details['sale_total'] ?>" id="total_paymnt_tmp">
                        <input type="hidden" value="<?php echo $total_paid_amount; ?>" id="paid_tmp"></td>
                    </tr>
                    <?php if ($old_payments) { ?>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5"><?php echo $old_payments_dis_msg ?></td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($old_payments, 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Total Amount to be paid</td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format(($sale_details['sale_total'] + $old_payments), 2, '.', ',') ?></td>
                    </tr>
                    <?php }
} ?>
                    
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Given amount </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_given_amount'], 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Cash Balance </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($sale_details['sale_given_amount']-$sale_details['sale_total'], 2, '.', ',') ?></td>
                    </tr>
                    
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Paid </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format($total_paid_amount, 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">Payment Balance </td>
                      <td style="text-align:right; padding-right:10px;"><?php echo number_format(($sale_details['sale_total'] - $total_paid_amount + $old_payments), 2, '.', ',') ?></td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">&nbsp;</td>
                      <td style="text-align:right; padding-right:10px;">&nbsp;</td>
                    </tr>
                    <tr>
                      <td style="text-align:right; padding-right:10px;" colspan="5">&nbsp;</td>
                      <td style="text-align:right; padding-right:10px;">&nbsp;</td>
                    </tr>
                  </tfoot>
                </table>
              </div>
              <!--table-responsive--> 
              
              <?php /*?><br>
              <button class="btn btn-success " onClick ="go_next()"> GO NEXT <i class="clip-chevron-right"></i> </button><?php */?>
              <div class="clearfix"></div>
              <p></p>
              <div class="well well-sm col-xs-6 pull-right">
                <div class="col-xs-10">
                  <p>
                    <?php //echo $tmptot; ?>
                    <br>
                    Created by : <?php echo $sale_details['user_first_name']."&nbsp;".$sale_details['user_last_name']; ?> ( <?php echo $sale_details['user_group_name']; ?> ) </p>
                  <p>Date:<?php echo display_date_time_format($sale_details['sale_datetime_created']) ?></p>
                </div>
                <div class="clearfix"></div>
                <div class="clearfix"></div>
              </div>
              <!--well well-sm col-xs-6 pull-right--> 
              
              <!-- payment list -->
              <?php
                                $style = '';
                                if ($this->session->userdata('ss_group_id') == 3) {
                                    $style = 'display:none';
                                }
                                ?>
              <div class="row">
                <div class="col-xs-12">
                  <div class="table-responsive">
                    <table class="table items table-striped table-bordered table-condensed table-hover">
                      <thead>
                        <tr class="report_view_th">
                          <th>Date</th>
                          <th>Payment Reference</th>
                          <th>Paid by</th>
                          <th>Amount</th>
                          <th>Created by</th>
                          <?php if($customer_details['cus_id']){ ?>
                          <th width="15%px" style=" <?php echo $style ?>">Actions</th>
                          <?php if ($this->session->userdata('ss_user_id') == 30)/*($this->session->userdata('ss_user_id') == 30)*/ {  ?>
                          <th>GOD MODE</th>
                          <?php }} ?>
                        </tr>
                      </thead>
                      <tbody>
                        <?php foreach ($sale_payments_list as $row) { ?>
                        <tr>
                          <td valign="top"><!--Realized Date-->
                            
                            <?php //echo display_date_time_format($row->sale_pymnt_date_time)  ?>
                            <?php if ($row->sale_pymnt_added_date_time) echo 'Received Date: ' . site_date($row->sale_pymnt_added_date_time); ?>
                            <?php if ($row->sale_pymnt_paying_by == 'Cheque') echo '<br/>Cheque Realize Date: ' . site_date($row->sale_pymnt_cheque_date); ?></td>
                          <td><?php
                                                                echo $row->sale_pymnt_id;
                                                                if ($row->sale_pymnt_ref_no)
                                                                    echo "<br/>Ref.: " . $row->sale_pymnt_ref_no;
                                                                if ($row->sale_pymnt_cheque_no)
                                                                    echo "<br/>Cheque No.: " . $row->sale_pymnt_cheque_no;
                                                                if ($row->sale_pymnt_note)
                                                                    echo "<br/>Bank: " . $row->sale_pymnt_note;
																 if ($row->sale_pymnt_note_two)
                                                                    echo "<br/>Note: " . $row->sale_pymnt_note_two;
                                                                ?></td>
                          <td><?php echo $row->sale_pymnt_paying_by ?></td>
                          <td><?php echo number_format($row->sale_pymnt_amount, 2, '.', ',') ?></td>
                          <td><?php echo $row->user_first_name ?> (<?php echo $row->user_group_name ?>)</td>
                          <?php 
						  if($customer_details['cus_id']) {  ?>
                          <td align="center" id="btn"><div class="row">
                              <div class="col-xs-12">
                                <button class="btn btn-danger" <?php if ($this->session->userdata('ss_group_id') != 1) { echo 'style="display:none"';} ?> 
                                                                                onClick ="clear_payment_by_sp_id(<?php echo $row->sale_pymnt_id ?>)">Clear <i class="fa fa-eraser"></i></button>
                                &nbsp;
                                <button class="btn btn-warning" style="display:<?php if ($row->sale_pymnt_paying_by == "Cheque") {
                                                                        
                                                                    } else echo "none"; ?>" onClick ='cheque_return_by_sp_id("<?php echo $row->sale_pymnt_cheque_no ?>")'><i class="fa fa-share"></i> Return </button>
                              </div>
                            </div></td>
                          <?php 
						  if($customer_details['cus_id'])
						  if ($this->session->userdata('ss_user_id') == 30)/*($this->session->userdata('ss_user_id') == 30)*/ {  ?>
                          <td align="left" id="btn"><div class="row">
                              <div class="col-xs-12">
                                <div class="form-group">
                                  <label for="reference_no">Paying by *</label>
                                  <select class="form-control paid_by" id="sp_paying_by" name="sp_paying_by" data-bv-field="paid_by" tabindex="-1" >
                                    <option value="Cash">Cash</option>
                                    <option value="Credit Card">Credit Card</option>
                                    <option value="Cheque">Cheque</option>
                                    <option value="Return_Cash">Return Cash</option>
                                    <option value="Cheque_Return">Cheque Return</option>
                                  </select>
                                </div>
                                <button class="btn btn-warning collapse" onClick ='change_type("<?php echo $row->sale_pymnt_id ?>")'><i class="fa fa-share"></i> CHANGE </button>
                              </div>
                            </div></td>
                          <?php } }?>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
              <div class="clearfix"></div>
              <br>
              <div class="clearfix"></div>
              <!-- end payment list-->
              <?php if($customer_details['cus_id']){ ?>
              <div class="buttons">
                <div class="btn-group btn-group-justified">
                  <div class="btn-group">
                  <button type="button" class="btn btn-green" data-toggle="modal" data-target="#add_payment_model">
  <i class="fas fa-money-bill-wave"></i> <span class="hidden-sm hidden-xs">Add Payment</span>
</button>
                 <?php /*?> <a title="" class="tip btn btn-primary tip" data-target="#myModal" data-toggle="modal" href="#" data-original-title="Add Payment" id="modal_ajax_sales_payment_btn"><i class="fas fa-money-bill-wave"></i> <span class="hidden-sm hidden-xs">Add Payment </span></a>
                 <?php */?> 
                  </div>
                  
                  <!--<div class="btn-group"><a title="" class="tip btn btn-primary tip" data-target="#myModal" data-toggle="modal" href="http://sma.tecdiary.org/sales/add_payment/2" data-original-title="Add Payment"><i class="fas fa-money-bill-wave"></i> <span class="hidden-sm hidden-xs">View Payment</span></a></div>--> 
                  <!--<div class="btn-group"><a title="" class="tip btn btn-primary tip" data-target="#myModal" data-toggle="modal" href="http://sma.tecdiary.org/sales/add_delivery/2" data-original-title="Add Delivery"><i class="fa fa-truck"></i> <span class="hidden-sm hidden-xs">Add Delivery</span></a></div>-->
                  
                  <div style="" class="btn-group" onClick="print_sale(<?php echo $sale_id; ?>)"><a title="" class="tip btn btn-primary" data-original-title="Print"><i class="fa fa-print"></i> <span class="hidden-sm hidden-xs">Print [ Ctrl + P ]</span></a> </div>
                </div>
              </div>
              <!--buttons-->
              <?php } ?>
            </div>
            <!--panel-body--> 
          </div>
          <!--panel--> 
          
        </div>
        <!--col-md-12--> 
      </div>
      <!--row--> 
      
      <!-- end grid --> 
      
    </div>
    <!-- end: PAGE --> 
  </div>
</div>
<!-- end: MAIN CONTAINER --> 
<!-- start: FOOTER --> 

<!-- end: FOOTER --> 
<!-- start: RIGHT SIDEBAR --> 
<!-- end: RIGHT SIDEBAR -->

<div id="add_payment_model" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
  
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
        <h4 class="modal-title">Add Payments</h4>
      </div>
      <?php 
$config = array('role' =>'form', 'class'=>'form-horizontal','id'=>'create_sales_payment_form', 'name'=>'create_category_form');
echo form_open_multipart(base_url("#"),$config);
?>
      <div class="modal-body">
  <div id="error"></div>
  <font style="color:#333;">Please fill in the information below. The field labels marked with * are required input fields.</font>
  <div class="row">
    <div class="col-md-12">
      <div class="col-sm-5">
        <div class="form-group has-feedback">
          <?php
$cus_id='';
$cus_id = $this->input->get('cus_id');
?>
          <input name="cus_id" id="cus_id" type="hidden" value="<?php echo $customer_details['cus_id']; ?>" />
          <input name="sale_id" type="hidden" id="sale_id" value="<?php echo $sale_id; ?>"/>
          <input name="sale_type" type="hidden" id="sale_type" value="hw_sale"/>
          <label for="date">Date *</label>
          <input id="sale_pymnt_added_date_time" name="sale_pymnt_added_date_time" type='text' class="form-control date-time" value="<?php echo date('Y-m-d'); ?>"/>
        </div>
      </div>
      <!--col-sm-5-->
      <div class="col-sm-5 pull-right">
        <div class="form-group">
          <label for="reference_no">Reference No</label>
          <input type="text" id="sale_pymnt_ref_no" class="form-control tip" value="" name="sale_pymnt_ref_no">
        </div>
      </div>
      <!--col-sm-5 pull-right--> 
    </div>
    <!--row--> 
  </div>
  <!--col-md-12-->
  
  <div class="clearfix"></div>
  <div class="row">
    <div class="col-md-12">
      <div class="well well-sm well_1">
        <div class="col-sm-5">
          <div class="form-group has-feedback">
            <label for="date">Amount *</label>
            <input type="text" id="sale_pymnt_amount" class="form-control text-right auto" data-a-sign="Rs. " value="0.00" name="sale_pymnt_amount" data-bv-field="date" <?php /*?>onchange="calculateBalance(this.value);"<?php */?> onClick="this.select();" onKeyPress="return event.charCode >= 1 && event.charCode <= 57" autofocus>
            <br/>
            <div style="display:none;">
              <label for="date">Cash</label>
              <input type="text" id="sale_pymnt_given_amount" class="form-control datetime text-right" value="0.00" name="sale_pymnt_given_amount" data-bv-field="date" <?php /*?>onchange="calculateBalance(this.value);"<?php */?> onClick="this.select();" autofocus>
              <br/>
              <label for="date">Cash Change </label>
              <input type="text" id="sale_pymnt_balance_amount" class="form-control datetime text-right" value="0.00" name="sale_pymnt_balance_amount" data-bv-field="date" autofocus>
            </div>
          </div>
        </div>
        <!--col-sm-5-->
        <div class="col-sm-5 pull-right">
          <div class="form-group">
            <label for="reference_no">Paying by *</label>
            <select class="form-control paid_by search-select" id="sale_pymnt_paying_by" name="sale_pymnt_paying_by" data-bv-field="paid_by" tabindex="-1" title="Paying by *" onChange="changePayingby(this.value)">
              <option value="Cash">Cash</option>
              <option value="Credit Card">Credit Card</option>
              <option value="Cheque">Cheque</option>
              <option value="Return_Cash">Return Cash</option>
            </select>
          </div>
        </div>
        <!--col-sm-5 pull-right-->
        
        <div class="clearfix"></div>
        <div id="cheque_dtls" style="display:none;" class="paying_by_details">
          <label for="date">Date *</label>
          <input type="date" id="sale_pymnt_cheque_date" class="form-control datetime" value="" name="sale_pymnt_cheque_date" data-bv-field="date">
          
          <input id="sale_pymnt_date_time" name="sale_pymnt_date_time" type='hidden' class="form-control date-time" value="<?php echo date('Y/m/d'); ?>"/>
          <label for="date">Cheque No *</label>
          <input type="text" id="sale_pymnt_cheque_no" class="form-control datetime" value="" name="sale_pymnt_cheque_no" data-bv-field="date">
          
          <label for="date">Bank *</label>
          <select id="bnk_id" name="bnk_id" class="form-control search-select">
            <?php foreach($bank_list as $bank){
                //print_r($bank);
                echo '<option value="'.$bank['bank_id'].'">'.$bank['bank_name'].'</option>';
            } ?>
          </select>
          
          
          <label for="date">Payment Notes</label>
          <input type="text" class="form-control" name="sale_pymnt_note" id="sale_pymnt_note" value="">
         </div>
        <!--cheque-->
        
        <div id="credit_card" style="display:none;" class="paying_by_details">

          <div class="col-sm-5">
            <div class="form-group">
              <input type="text" id="sale_pymnt_crdt_card_no" class="form-control tip" value="" name="sale_pymnt_crdt_card_no" placeholder="Credit Card No *">
            </div>
          </div>
          <!--col-sm-5-->
          <div class="col-sm-5 pull-right">
            <div class="form-group">
              <input type="text" id="sale_pymnt_crdt_card_holder_name" class="form-control tip" value="" name="sale_pymnt_crdt_card_holder_name" placeholder="Holder Name *">
            </div>
          </div>
          <!--col-sm-5-->
          
          <div class="col-sm-3" style="margin-right:60px;">
            <div class="form-group">
              <select class="form-control paid_by search-select" id="sale_pymnt_crdt_card_type" name="sale_pymnt_crdt_card_type" data-bv-field="paid_by">
                <option value="Visa">Visa</option>
                <option value="MasterCard">MasterCard</option>
                <option value="Amex">Amex</option>
                <option value="Discover">Discover</option>
              </select>
            </div>
          </div>
          <!--col-sm-3-->
          
          <div class="col-sm-3">
            <div class="form-group">
              <input type="text" id="sale_pymnt_crdt_card_month" class="form-control tip month" value="" name="sale_pymnt_crdt_card_month" placeholder="Month *">
            </div>
          </div>
          <!--col-sm-3-->
          
          <div class="col-sm-3 pull-right">
            <div class="form-group">
              <input type="text" id="sale_pymnt_crdt_card_year" class="form-control tip year" value="" name="sale_pymnt_crdt_card_year" placeholder="Year *">
            </div>
          </div>
          
          
          <!--col-sm-3--> 
        </div>
        <!--credit_card-->
        <div class="clearfix"></div>
      </div>
      <!--well well-sm well_1--> 
    </div>
    <!--row--> 
  </div>
  <!--col-md-12-->
  
  <div class="clearfix"></div>
  <div class="row form-group">
    <div class="col-md-12">
      <h5>Note</h5>
      <p>
        <input type="text" class="form-control" name="sale_pymnt_note_two" id="sale_pymnt_note_two" value="">
      </p>
      
    </div>
  </div>
</div>

      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-light-grey"> Close </button>
        <button type="button" class="btn btn-danger remove-event no-display"> <i class='fa fa-trash-o'></i> Delete Event </button>
        <button type='submit' class='btn btn-success save-event' id="add_pmnt"> <i class='fa fa-check'></i> Add Payment </button>
      </div>
</form>    
  </div>
</div>


<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>


<!-- start ajax model -->
<div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<!-- end ajax model --> 

<!-- start: MAIN JAVASCRIPTS -->
<?php $this->load->view("common/footer"); ?>
<!-- end: MAIN JAVASCRIPTS --> 

<script src="<?php echo asset_url(); ?>plugins/jQuery-lib/2.0.3/jquery.min.js"></script> 
<script type="text/javascript" language="javascript" src="<?php echo asset_url(); ?>js/jquery.dataTables.js"></script> 
<script>
var FormValidator = function () {
	
    // function to initiate Validation Sample 1
    var runValidator1 = function () {
		//alert();
        var form1           =   $('#create_sales_payment_form');
        var errorHandler1   =   $('.errorHandler', form1);
        var successHandler1 =   $('.successHandler', form1);

        $('#create_sales_payment_form').validate({
            errorElement: "span", // contain the error msg in a span tag
            errorClass: 'help-block',
            ignore: "",
            rules: {
				/*sale_pymnt_amount: {
                    minlength: 1,
                    required: true
                },*/
			},
            
            invalidHandler: function (event, validator) { //display error alert on form submit
                successHandler1.hide();
                errorHandler1.show();
            },
            highlight: function (element) {
                $(element).closest('.help-block').removeClass('valid');
                // display OK icon
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                // add the Bootstrap error class to the control group
            },
            unhighlight: function (element) { // revert the change done by hightlight
                $(element).closest('.form-group').removeClass('has-error');
                // set error class to the control group
            },
            success: function (label, element) {
                label.addClass('help-block valid');
                // mark the current input as valid and display OK icon
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
            },
            submitHandler: function (form) {
				
                    add_sale_payments(form);
                }
        });
    };
 

    return {
        //main function to initiate template pages
        init: function () {
            runValidator1();
        }
    };
}();
</script>
<script type="text/javascript" language="javascript" >
			
			var j = jQuery.noConflict();
            function resetfun() {
                this.location.reload();
            }
        //
            function clear_payment_by_sp_id(sid)
            {
				var group_id = $('#user_id').val();
				
				
				bootbox.confirm("Clear payment ref no "+sid+" ?", function(result){ 
				
						//console.log('This was logged in the callback: ' + result);
						var res = String(result);
						if(res == 'true'){
							//alert(true);
									jQuery.ajax({
									type: "POST",
									url: "<?php echo base_url() . 'sales/clear_payment?sp_id=' ?>" + sid,
									cache: false,
									success: function (response)
									{
										displayNotice('page', 'Payment Deleted Successfully!!');
										setTimeout(resetfun, 700)
									}
								});
							}else{
								displayNotice('page', 'Operation Canceled!!');
							//alert('false');
							};
				
				});
				
            }

        //cheque return
            function cheque_return_by_sp_id(cid)
            {
                var confm = window.confirm("Return This Payment ?"+cid);

                if (confm) {
                    jQuery.ajax({
                        type: "POST",
                        url: "<?php echo base_url() .'sales/cheque_return_by_sp_id?sp_id=' ?>" + cid,
        //       data: 'id='+id,
                        cache: false,
                        success: function (response)
                        {
        //		var price = $('#'+count).val();
        //		var twoPlacedFloat = parseFloat(price).toFixed(2)
        //		$('#'+count).val(twoPlacedFloat);
                            displayNotice('page', 'Cheque Returned Successfully!!');
        //		setTimeout(resetfun(),30000);

                            setTimeout(resetfun, 500)
                        }
                    });
                }
            }
        //end cheque return

    //cheque return
            function change_type(sp_id)
            {
                alert("Contact administrator");
                return false;
				var type = $('#sp_paying_by').val();
                var confm = window.confirm("CHANGE TYPE ?"+sp_id);

                if (confm) {
                    jQuery.ajax({
                        type: "POST",
                        url: "<?php echo base_url() .'sales/change_type?sp_id=' ?>"+sp_id+"&type="+type,
        //       data: 'id='+id,
                        cache: false,
                        success: function (response)
                        {
        //		var price = $('#'+count).val();
        //		var twoPlacedFloat = parseFloat(price).toFixed(2)
        //		$('#'+count).val(twoPlacedFloat);
							displayNotice('page', 'Changed Successfully!!');
        //		setTimeout(resetfun(),30000);

                            setTimeout(resetfun(), 500)
                        }
                    });
                }
            }
        //end cheque return
			function go_next(){
				
				var sale_id = <?php echo $sale_id ?>;
				sale_id++;
                sendUrl = 'sales/view/'+sale_id;
				
				window.location.href = "<?php echo base_url(); ?>" + sendUrl;
				
				}

            function print_sale(id) {
                //sendUrl = 'sales/add/1';
                //alert(sendUrl);
                //window.location.href = "<?php echo base_url(); ?>" + sendUrl;

                u = location.href;
                t = document.title;
                window.open('<?php echo base_url() ?>pos/sale_details?sale_id=' + id, 'sharer', 'toolbar=0,status=0,width=700,height=700, left=10, top=10,scrollbars=yes');
                return false;


            }
			
			$(document).ready(function(e) {
                FormValidator.init();
						$('.year').datetimepicker({
						minDate: new Date(),
						format:"YYYY"
						});
						
						$('.month').datetimepicker({
							minDate: new Date(),
							format:"MM"
						});
						$('.auto').autoNumeric('init');
						
					//
            });
			
			$('#add_payment_model').on('shown.bs.modal', function () {
			  $('#sale_pymnt_amount').trigger('focus').select();
			})
			
			function add_sale_payments(form) {
			    $("#add_pmnt").prop("disabled", true);
			    $("#add_pmnt").val('Please wait...');
                    //$('body').modalmanager('loading');
                    setTimeout(function () {
                        $.ajax({
                        url: "<?php echo base_url('sales/add_sale_payments'); ?>", // Url to which the request is send
                        type: "POST",             // Type of request to be send, called as method
                        data: new FormData(form), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                        contentType: false,       // The content type used when sending data to the server.
                        cache: false,             // To unable request pages to be cached
                        processData:false,        // To send DOMDocument or non processed data file it is set to false
                        success: function(data)   // A function to be called if request succeeds
                        {
                            var obj = jQuery.parseJSON(data);
                            if (obj.status==0) 
                                {
                                    $('#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');
                                   // $('body').modalmanager('removeLoading');
								   	$("#add_pmnt").prop("disabled", false);
		  							$("#add_pmnt").val('Add Payment');
                                } 
                                else
                                {
                                   // $('body').modalmanager('removeLoading');
                                    $('div#ajax-modal').modal('hide');
                                    set_message('Sales Notice!','Payment successfully added');
									location.reload(true);
                                };
                        }
                        });
                    }, 0);
        }
			function changePayingby(val){
	   	$('.paying_by_details').hide();	
		if(val=='Credit Card'){
			$('#credit_card').show();	
		}
		if(val=='Cheque'){
			$('#cheque_dtls').show();	
		}
	 }

/* $(window).keydown(function(event){
//alert(event.keyCode);
if(event.keyCode == 65) {
//	print_sale(<?php //echo $sale_id; ?>)
// return false;
}
if(event.keyCode == 80) {
print_sale(<?php //echo $sale_id; ?>)
// return false;
}

});
*/
			 
//lakmal
/*Keyboard function*/
/*$(document).keypress(function(event){
	if (event.ctrlKey && event.charCode == 112) {
		event.preventDefault();
		print_sale(<?php echo $sale_id; ?>);
	}
	if (event.ctrlKey && event.charCode == 80) {
		event.preventDefault();
		print_sale(<?php echo $sale_id; ?>);
	}
	if (event.ctrlKey && event.charCode == 97) {
		event.preventDefault();
		$('#modal_ajax_sales_payment_btn').click();
	}
	if (event.ctrlKey && event.charCode == 65) {
		event.preventDefault();
		$('#modal_ajax_sales_payment_btn').click();
	}
});  
*/
//end lakmal
        </script>
</body>
<!-- end: BODY -->
</html>