<?php 
define('DOCUMENT_ROOT_CLASS','../../');
define('DOCUMENT_ROOT_INC_FOLDER','inc/');
$filepath = realpath(dirname(__FILE__));

require "../../inc/header.php";
$msg = Session::get('msg');
Session::set("msg", NULL);
$deliveryInvoiceData = $commonFunctions->getRowData('sys_erp_sales_delivery_note'," WHERE id = '".@$_GET['delivery_note_id']."' ");
?>
	
  <!-- Page-Title -->
  <div class="row">
      <div class="col-sm-12">
          <div class="page-title-box">
              <div class="row">
                  <div class="col form-row">
                  	<div class="col-sm-10">
                        <h4 class="page-title">Delivery Note #<?php echo @$deliveryInvoiceData['delivery_note_no'];?></h4>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Sales & Purchases</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Sales & Invoices</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Delivery Note #<?php echo @$deliveryInvoiceData['delivery_note_no'];?></a></li>
                        </ol>
                    </div>
                      <div class="col-sm-2" style="text-align: end;">
                        <a href="invoice.php?state=list"><button type="button" class="btn btn-sm btn-secondary clear_form">Back to Delivery Note List</button></a>
                    </div>
                  </div><!--end col-->
              </div><!--end row-->                                                              
          </div><!--end page-title-box-->
      </div><!--end col-->
  </div><!--end row-->
  <!-- end page title end breadcrumb -->

  <div class="row">
      <div class="col-md-12">
        	<div class="row card ">
        		  <div class="card-body col-lg-12 mx-auto">
                <div class="card">
                   <div class="card-body invoice-head">
                      <div class="row">
                         <div class="col-md-4 align-self-center">
                            <p class="mt-2 mb-0 text-muted">If account is not paid within 7 days the credits details supplied as confirmation.</p>
                         </div>
                         <?php $bill_to = $commonFunctions->getname($deliveryInvoiceData['invoice_id'],"sys_erp_sales_invoice","bill_to","id");
                         $ship_to = $commonFunctions->getname($deliveryInvoiceData['invoice_id'],"sys_erp_sales_invoice","ship_to","id");
                         $invoiceData = $commonFunctions->getRowData('sys_erp_sales_invoice'," WHERE id = '".@$deliveryInvoiceData['invoice_id']."' ");
                          ?>
                         <!--end col-->    
                         <div class="col-md-8">
                            <ul class="list-inline mb-0 contact-detail float-right">
                               <li class="list-inline-item">
                                  <div class="pl-3">
                                     <i class="mdi mdi-web"></i>
                                     <?php echo $commonFunctions->getname($bill_to,'crm_cust_details','email','id'); ?>
                                     
                                  </div>
                               </li>
                               <li class="list-inline-item">
                                  <div class="pl-3">
                                     <?php echo $commonFunctions->getname($bill_to,'crm_cust_details','phone','id'); ?>
                                  </div>
                               </li>
                               <li class="list-inline-item">
                                  <div class="pl-3">
                                     <i class="mdi mdi-map-marker"></i>
                                     <?php echo $commonFunctions->getname($bill_to,'crm_cust_details','address','id'); ?>
                                  </div>
                               </li>
                            </ul>
                         </div>
                         <!--end col-->    
                      </div>
                      <!--end row-->     
                   </div>
                   <!--end card-body-->
                   <div class="card-body">
                    <div class="row">
                         <div class="col-md-3">
                            <div class="float-left">
                               <address class="font-13">
                                  <strong class="font-14">Invoice No :</strong> <?php echo $deliveryInvoiceData['invoice_no']; ?>
                               </address>
                            </div>
                         </div>
                      </div>

                      <div class="row">
                         <div class="col-md-3">
                            <div class="float-left">
                               <address class="font-13">
                                  <strong class="font-14">Billed To :</strong><br>
                                  <?php echo $commonFunctions->getname($bill_to,'crm_cust_details','address','id'); ?>
                               </address>
                            </div>
                         </div>
                         <!--end col--> 
                         <div class="col-md-3">
                            <div class="">
                               <address class="font-13">
                                  <strong class="font-14">Shipped To :</strong><br>
                                  <?php echo $commonFunctions->getname($ship_to,'crm_cust_details','address','id'); ?>
                               </address>
                            </div>
                         </div>
                         <!--end col-->
                         <div class="col-md-2">
                         </div>
                         <!--end col-->  
                         <div class="col-md-4">
                            <table id="" class="table table-bordered dt-responsive nowrap dataTable no-footer dtr-inline" style="border-collapse: collapse; border-spacing: 0px; width: 100%;" role="grid" aria-describedby="datatable_info">
                               <thead class="thead-light">
                                  <tr>
                                     <th>Delivery Note Number :</th>
                                     <th><?php echo @$deliveryInvoiceData['delivery_note_no'];?></th>
                                  </tr>
                                  <!--end tr-->
                                  <tr>
                                     <th>DN Created :</th>
                                     <th> <?php echo date("d M Y",strtotime(@$deliveryInvoiceData['created_date']));?>
                                     </th>
                                  </tr>
                                  <!--end tr-->
                                  <tr>
                                     <th>Delivery Date :</th>
                                     <th> <?php echo date("d M Y",strtotime(@$deliveryInvoiceData['delivery_date']));?>
                                     </th>
                                  </tr>
                                  <!--end tr-->
                               </thead>
                            </table>
                         </div>
                         <!--end col-->                       
                      </div>
                      <!--end row-->
                      <div class="row">
                         <div class="col-lg-12">
                            <div class="">
                               <table class="table table-bordered mb-0">
                                  <thead class="thead-light">
                                     <tr>
                                        <th>PO Number</th>
                                        <th>Payment Mode</th>
                                        <th>Payment Type</th>
                                        <th>Project ID</th>
                                     </tr>
                                     <!--end tr-->
                                  </thead>
                                  <tbody>
                                     <tr>
                                        <td>CUS PO#<span class="cust_po"><?php echo @$invoiceData['po_number'];?></span></td>
                                        <td><?php echo $commonFunctions->getname($invoiceData['payment_mode'],'fin_accnt_payment_mode','label','id'); ?></td>
                                        <td><?php echo $commonFunctions->getname($invoiceData['payment_terms'],'fin_accnt_payment_trems','label','id'); ?></td>
                                        <td>CUS PID#
                                          <?php echo @$invoiceData['project_number'];?></td>
                                     </tr>
                                     <!--end tr-->
                                  </tbody>
                               </table>
                               <!--end table-->
                            </div>
                            <!--end /div-->                                          
                         </div>
                         <!--end col-->                                      
                      </div>
                      <!--end row-->
                      <p></p>
                      <div class="row">
                         <div class="col-lg-12">
                            <div class="">
                               <table class="table table-bordered mb-0">
                                  <thead class="thead-light">
                                     <tr>
                                        <th>Product</th>
                                        <th>Unit Price</th>
                                        <th>Quantity</th>
                                        <th>Total</th>
                                     </tr>
                                     <!--end tr-->
                                  </thead>
                                  <tbody>
                                  	<?php $invoiceProductData = $commonFunctions->getData('sys_erp_sales_delivery_note_prdct_details'," WHERE delivery_note_id = '".@$_GET['delivery_note_id']."' "); 
                                    foreach ($invoiceProductData as $rw) {
                                    ?>
                                       <tr class="after-add-more">
                                          <td>
                                            <label class="form-control"> <?php echo $commonFunctions->getname($rw['product_id'],'invty_pdt_details','label','id'); ?></label>
                                          </td>
                                          <td>
                                          	<label class="form-control"> <?php echo $rw['unit_price']; ?></label>
                                          </td>
                                          <td>
                                            <label class="form-control"> <?php echo $rw['quantity']; ?></label>
                                          </td>
                                          <td>
                                          	<label class="form-control"> <?php echo $rw['total_amt']; ?></label>
                                            <!-- <input type="text" name="total_pro_amt[]" class="total_pro_amt form-control total_pro_amt1" readonly=""> -->
                                          </td>
                                          
                                       </tr>
                                     <?php } ?>
                                     <!--end tr-->
                                     <tr>
                                        <td colspan="2" class="border-0"></td>
                                        <td class="border-0 font-14 text-dark"><b>Sub Total</b></td>
                                        <td class="border-0 font-14 text-dark"><b>
                                          <input type="hidden" name="sub_total_amt" class="sub_total_amt" value="0">
                                          <span class="sub_total_amt"><?php echo @$deliveryInvoiceData['sub_total'];?></span></b></td>
                                     </tr>
                                     <!--end tr-->
                                     <tr>
                                        <th colspan="2" class="border-0"></th>
                                        <td class="border-0 font-14 text-dark"><b>Tax Rate</b></td>
                                        <td class="border-0 font-14 text-dark"><b>$0.00%</b></td>
                                     </tr>
                                     <!--end tr-->
                                     <tr class="bg-black text-white">
                                        <th colspan="2" class="border-0"></th>
                                        <td class="border-0 font-14"><b>Total</b></td>
                                        <td class="border-0 font-14"><b><label class="form-control"><?php echo @$deliveryInvoiceData['total'];?></label></b></td>
                                     </tr>
                                     <!--end tr-->
                                  </tbody>
                               </table>
                               <!--end table-->
                            </div>
                            <!--end /div-->                                          
                         </div>
                         <!--end col-->                                      
                      </div>
                      <!--end row-->
                      <div class="row justify-content-center">
                         <div class="col-lg-6">
                            <h5 class="mt-4">Terms And Condition :</h5>
                            <ul class="pl-3">
                               <li><small class="font-12">All accounts are to be paid within 7 days from receipt of invoice. </small></li>
                               <li><small class="font-12">To be paid by cheque or credit card or direct payment online.</small></li>
                               <li><small class="font-12"> If account is not paid within 7 days the credits details supplied as confirmation of work undertaken will be charged the agreed quoted fee noted above.</small></li>
                            </ul>
                         </div>
                         <!--end col-->                                       
                         <div class="col-lg-6 align-self-end">
                            <div class="float-right" style="width: 30%;">
                               <small>Account Manager</small>
                               <img src="assets/images/signature.png" alt="" class="mt-2 mb-1" height="26">
                               <p class="border-top">Signature</p>
                            </div>
                         </div>
                         <!--end col-->
                      </div>
                      <!--end row-->
                      <hr>
                      <div class="row d-flex justify-content-center">
                         <div class="col-lg-12 col-xl-4 ml-auto align-self-center">
                            <div class="text-center"><small class="font-12">Thank you very much for doing business with us.</small></div>
                         </div>
                         <!--end col-->
                         <div class="col-lg-12 col-xl-4">
                            <div class="float-right d-print-none">
                               <!-- <a href="#" class="btn btn-soft-primary btn-sm">
                               <i class="fas fa-save align-self-center icon-xs"></i> Save
                               </a> -->
                              <a href="delivery-note.php?state=list"><button type="button" class="btn btn-soft-secondary btn-sm">Back <<</button></a>
                              <!-- <button type="button" class="btn btn-soft-success btn-sm" id="save_form">
                              <i class="fa fa-file-invoice align-self-center icon-xs"></i> Create Invoice
                              </button> -->
                            </div>
                         </div>
                         <!--end col-->
                      </div>
                      <!--end row-->
                   </div>
                   <!--end card-body-->
                </div>
                <!--end card-->
             </div>
             <!--end col-->
          </div>  
      </div><!--end col-->
  </div><!--end row-->
  

<?php require "../../inc/footer.php"; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script type="text/javascript">
$("#save_form").click(function(){
  $("#invoice_form").validate();  
    if($("#invoice_form").valid()){
      $.ajax({
        type: 'POST',
        url: "",
        data: $('#invoice_form').serialize()+"&action=ajax_call_1",
        success: function(response) { 
          window.location.href = response;
        }
    });
  }
});
</script>