<?php  
$date= strtotime($row->date);
$d_time=date('Y-m-d', $date);
$d_time = strtotime($d_time);
$d_time = strtotime("+7 day", $d_time);
$delivery_date= date('M d, Y', $d_time);
?>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>
<div class="middleSec catbyMdl">

  <div class="headingD">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <i class="fa fa-user" aria-hidden="true"></i> Bill Print
            <a href="<?php echo base_url(); ?>product_order/" class="btn btn-warning pull-right">Back</a>&nbsp;
            <button onclick="printDiv('#printArea');" class="btn btn-primary pull-right"><i class="fa fa-print" aria-hidden="true"></i> Print Now</button>
        </div>
  <div class="clearfix"></div>
  </div>

        

  <div class="showPageSec chartPagHgtD catby">

    <div class="container-fluid">

          <div class="row">
                

                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 " id="printArea">
                    <div class="table-responsive catbyMdl">
                        <h4 style="text-align: center;">Tax Invoice</h4>
                        <table class="table" style="width:100%; margin-bottom: 0;" border="1">

                            <tbody>
                                <tr>
                                    <td rowspan="3" style="padding: 2px 8px;font-size: 12px; color: #000;">
                                        <h4 style="margin: 2px 0;font-size: 15px;">Top 10</h4>
                                        <p style="margin: 2px 0;">SHOP NO. 508, 3RD FLOOR, SHREERAM ARCADE, 15A JAWAHARLAL NEHRU ROAD</p>
                                        <p style="margin: 2px 0;">CHOWRINGHEE, Kolkata-700013</p>
                                        <p style="margin: 2px 0;">MOB: 98765 543210</p>
                                        <p style="margin: 2px 0;">GST Number : 19AFJPA2391C1ZR</p>
                                        <p style="margin: 2px 0;">email:info@gaineronline.com</p>
                                        <p style="margin: 2px 0;">State Name: West Bengal, Code: 19</p>

                                    </td>
                                    
                                    <td style="padding: 2px 8px;font-size: 12px; color: #000;">Invoice no.<h5 style="margin: 2px 0;"><?php echo $row->bill_no; ?></h5></td>
                                    <td style="padding: 2px 8px;font-size: 12px; color: #000;">Dated<h5 style="margin: 2px 0;"><?php echo date('F d, Y h:i A', $date); ?></h5></td>
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td style="padding: 2px 8px;">Delivery Note<h5></h5></td>
                                    <td style="padding: 2px 8px;">Mode/Terms of Payment<h5><?php echo $recordSet['0']['mode']; ?></h5></td>
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td style="padding: 2px 8px;">Supply Ref.<h5 style="margin: 2px 0;"></h5></td>
                                    <td style="padding: 2px 8px;">Other Refferance(s)<h5></h5></td>
                                </tr>

                                <tr style="font-size: 12px; color: #000;">
                                    <td rowspan="5" style="padding: 2px 8px;">
                                        <h4 style="margin: 2px 0;font-size: 15px;"><small>Buyer</small><br><?php echo $row->cus_name; ?></h4>
                                        <p style="margin: 2px 0;"><?php echo $row->cus_address; ?></p>
                                        <p style="margin: 2px 0;"><?php echo $row->city; ?>, <?php echo $row->pin; ?></p>
                                        <p style="margin: 2px 0;">MOB: <?php echo $row->cus_phone; ?></p>
                                        <p style="margin: 2px 0;">GST Number : <?php echo $row->gst; ?></p>
                                        <p style="margin: 2px 0;">State Name: <?php echo $row->state; if($row->state_code!='0'){ ?>, Code: <?php echo $row->state_code; ?> <?php } ?></p>
                                    </td>
                                    
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td style="padding: 2px 8px;">Buyer Order no.<h5><?php echo $row->billing_id; ?></h5></td>
                                    <td style="padding: 2px 8px;">Dated<h5><?php echo $delivery_date; ?></h5></td>
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td style="padding: 2px 8px;">Despatch Document No<h5 style="margin: 2px 0;"><?php echo $row->dispath_documence; ?></h5></td>
                                    <td style="padding: 2px 8px;">Delivery Note Date<h5></h5></td>
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td style="padding: 2px 8px;">Despatched through<h5 style="margin: 2px 0;"><?php echo $row->document_through; ?></h5></td>
                                    <td style="padding: 2px 8px;">Destination<h5></h5></td>
                                </tr>
                                <tr style="font-size: 12px; color: #000;">
                                    <td colspan="2" style="padding: 2px 8px;">Terms of Delivery<h5></h5></td>
                                </tr>
                            </tbody>

                        </table>


                        <table class="table" style="width:100%; min-height: 300px;" border="1">
                            <thead>
                                <tr style="font-size: 11px; color: #000;">
                                    <th>Sl. No.</th>
                                    <th>Description of goods</th>
                                    <th>HSN/SAC</th>
                                    <th>Quantity</th>
                                    <th>Rate</th>
                                    <th>Per</th>
                                    <th>Disc</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>
                            <tbody style="font-size: 11px; color: #000;">
                                <?php 
                                $total_quantity=0;
                                $gst_amount=0;
                                $sub_total=0;
                                $bil=$this->db->where('billing_id', $row->billing_id)->get('billing_data')->result_array();
                                $total=0;
                                foreach ($bil as $key_bil) {
                                $rate=$key_bil['price']*$key_bil['quantity'];
                                $s_gst=$rate*6/100;
                                $s_gst=round($s_gst,2);
                                $gst_amount=$gst_amount+$s_gst;
                                $sub_total=$sub_total+$rate;
                                if ($row->tax_type!='Without GST') {
                                $total=$total+$rate+$s_gst*2;
                                }
                                else
                                {
                                $total=$total+$rate;
                                }
                                $discount=$key_bil['mrp']-$key_bil['price'];
                                $total_quantity=$total_quantity+$key_bil['quantity'];
                                ?>
                                <tr>
                                    <td style="padding: 2px 8px;"><?php echo $key_bil['sl_no']; ?>.</td>
                                    <td style="padding: 2px 8px;"><h4 style="margin: 2px 0;font-size: 13px;"><?php echo $key_bil['item_name']; ?></h4></td>
                                    <td style="padding: 2px 8px;"><?php echo $key_bil['hsn']; ?></td>
                                    <td style="padding: 2px 8px;"><?php echo $key_bil['quantity']; ?> pcs</td>
                                    <td style="padding: 2px 8px;"><?php echo $key_bil['mrp']; ?></td>
                                    <td style="padding: 2px 8px;">pcs</td>
                                    <td style="padding: 2px 8px;"><?php echo $discount; ?></td>
                                    <td align="right" style="padding: 2px 8px;"><?php echo $rate; ?></td>
                                </tr>                               
                                <?php } 
                                $grand_total=$sub_total;
                                $delivery_charge='Delivery charges may apply.';
                                            if ($recordSet[0]['pin']!='') 
                                            {
                                            $pindetails = $this->db->where('pin', $recordSet[0]['pin'])->get('active_pin')->result_array();
                                            if ($pindetails) 
                                            {
                                            $delivery_charge=$pindetails['0']['delevery_charge']*$number_of_order; 
                                            $grand_total=$grand_total+$delivery_charge;
                                            } 
                                            else 
                                            {
                                            $delivery_charge='Delivery charges may apply.';
                                            }   
                                            }
                                            if ($delivery_charge=='0') {
                                                $delivery_charge='Free';
                                            }
                                            if ($row->tax_type!='Without GST') {
                                            
                            ?>
                                <tr>
                                    <td></td>
                                    <td style="text-align: right; margin: 2px 0;"><i>CGST</i></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td align="right"><?php echo $s_gst; ?></td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td style="text-align: right; margin: 2px 0;"><i>SGST</i></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td align="right"><?php echo $s_gst; ?></td>
                                </tr>
                            <?php } ?>
                                <tr>
                                    <td></td>
                                    <td><h4 style="text-align: right;font-size: 13px;">Total</h4></td>
                                    <td></td>
                                    <td><?php echo $total_quantity; ?> pcs</td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td align="right"><h4 style="font-size: 13px;">₹ <?php echo $total; ?></h4></td>
                                </tr>
                                <?php
                                  /**
                                   * Created by PhpStorm.
                                   * User: sakthikarthi
                                   * Date: 9/22/14
                                   * Time: 11:26 AM
                                   * Converting Currency Numbers to words currency format
                                   */
                                $number = $sub_total;
                                   $no = floor($number);
                                   $point = round($number - $no, 2) * 100;
                                   $hundred = null;
                                   $digits_1 = strlen($no);
                                   $i = 0;
                                   $str = array();
                                   $words = array('0' => '', '1' => 'one', '2' => 'two',
                                    '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
                                    '7' => 'seven', '8' => 'eight', '9' => 'nine',
                                    '10' => 'ten', '11' => 'eleven', '12' => 'twelve',
                                    '13' => 'thirteen', '14' => 'fourteen',
                                    '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
                                    '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
                                    '30' => 'thirty', '40' => 'forty', '50' => 'fifty',
                                    '60' => 'sixty', '70' => 'seventy',
                                    '80' => 'eighty', '90' => 'ninety');
                                   $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
                                   while ($i < $digits_1) {
                                     $divider = ($i == 2) ? 10 : 100;
                                     $number = floor($no % $divider);
                                     $no = floor($no / $divider);
                                     $i += ($divider == 10) ? 1 : 2;
                                     if ($number) {
                                        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
                                        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
                                        $str [] = ($number < 21) ? $words[$number] .
                                            " " . $digits[$counter] . $plural . " " . $hundred
                                            :
                                            $words[floor($number / 10) * 10]
                                            . " " . $words[$number % 10] . " "
                                            . $digits[$counter] . $plural . " " . $hundred;
                                     } else $str[] = null;
                                  }
                                  $str = array_reverse($str);
                                  $result = implode('', $str);
                                  $points = ($point) ?
                                    "." . $words[$point / 10] . " " . 
                                          $words[$point = $point % 10] : '';
                                  
                                 ?> 
                                <tr>
                                    <td colspan="10" style="padding: 2px 8px;"><h4 class="pull-left" style="font-size: 13px;"><small>Amount Chargble (in word)</small><br>INR <?php echo $result . "Rupees  "; ?> Only</h4><p class="pull-right">E. & O.E.</p></td>
                                </tr>

                                




                               
                                <!-- <tr class="mar0">
                                    <td colspan="3"></td>
                                    <td colspan="7" style="padding: 2px 8px;">
                                        <h5>Company's Bank Details</h5>
                                        <p>Bank Name: <strong>ABC BANK</strong></p>
                                        <p>Acc No.: <strong>0000000</strong></p>
                                        <p>Branch & IFSC Code: <strong>Kolkata & ABC0001</strong></p>
                                    </td>
                                </tr> -->
                                <tr>
                                    <td colspan="3" style="padding: 2px 8px;">
                                        <h5>Declaration</h5>
                                        <p>1. We declare that this invoice shows the actual price of the goods described and that all particulars are true and correct. <br>
                                        2. Product returns accepted within 48 hours of receipt, but please make sure to meet our company's return criteria.
                                         </p>
                                    </td>
                                    <td colspan="7" align="right" style="padding: 2px 8px;">
                                        <p>For TOP10 <?php echo date('Y',strtotime($recordSet['0']['date'])); ?>-<?php echo date('y',strtotime($recordSet['0']['date']))+1; ?></p><br><br>
                                        <p>Authorised Signature</p>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        

                    </div>
                </div>  



      </div>
    </div>
  </div>
</div>



<?php  

include "layout/footer.php";

?>
<script>



$(document).ready(function() {

    $('#myTable').DataTable({

    //"bPaginate": false,

     "bLengthChange": false,

    // "bFilter": false,

     "bInfo": false,

    "bAutoWidth": false,

    "bSort" : false

    });

} );

</script>



<style type="text/css">

  table.dataTable thead .sorting, 

table.dataTable thead .sorting_asc, 

table.dataTable thead .sorting_desc {

    background : none;

}

</style>


<script>
     function printDiv() {
   //  //$("input[id='ivnn']").each(function(){
   //    var shiping_id = document.getElementById("service").value;
   //    //qtyarray.push(qtyVal);
   //    //console.log(shipping_id);
   //  //});
  

   // $.ajax({
   //     url: 'server_pdf.php',
   //     type: 'POST',
   //     data: {service : shiping_id},
   //     success: function(data) {
   //        //$("#total"+id).html(data);
   //     }
   //  });
   
   var divToPrint = document.getElementById('printArea').innerHTML;
//alert(divToPrint);
   //console.log(divToPrint);
   var newWin = window.open();
   newWin.document.write('<html><head><title>Gainer</title>');
   newWin.document.write('</head><body >');
   newWin.document.write(divToPrint);
   newWin.document.write('</body></html>');
   console.log(divToPrint);
   newWin.document.close();
   newWin.print();
   //newWin.close();
   //window.print();
   }
$(document).ready(function(){

      $('#sendEmail').click(function(){
        window.open('bill-send.php?service=<?php echo $_GET['service']; ?>','popup','width=100,height=100');
        // var service='<?php echo $service_feedback_new['se_id']; ?>';
         // $.ajax({
             // type: 'POST',
             // url: 'bill-send.php',
             // data: { service: service},
             // success: function(data){
                swal("Thankyou ", "Successfully Invoice Sent To Customer", "success", { button: "ok",});
             // }
         // });
      });

    });
</script>

