<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/invfunctions.php');
include ('../inc/repfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){    
$_SESSION['cuPages']='sel_sinvlist.php';   
$cuPage='sel_sinvlist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
?>
<div class="printableArea">    
<style>
	  html, body {
        height: 100%;
      }
      body {
        background: #dfdfdf;
      }
      .fixed-top {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        padding: 0 20px;
        background: white;
        margin: 0;
        z-index: 10;
      }
    .font-weight-bold {
    font-weight: 700 !important;
}
    .text-invright{    
    padding: 10px;
    font-size: 12px;
    text-align: right;
    min-height: 120px; 
    }
</style>
<style>

  body{
    -webkit-print-color-adjust:exact;
    print-color-adjust:exact;
  }
  
@page {
size: 21cm 29.7cm
}
   @page {
    margin: 0;
    padding: 0;
    margin-left: 0px;
    margin-right: 0px;
    margin-top: 0px;
    margin-bottom: 0px;
  }
  
 #wrap_invoice {
    background: white;
    padding: 0.5cm;
    margin: 2mm auto;
    border: 1px #D3D3D3 solid;
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
  }
  
  #wrap_invoice,
  .text-color{
    color: #555;
  }
  #wrap_invoice .page{
    background: white;
    font-family: sans-serif;
    page-break-after: always;
  }
  #wrap_invoice .page:last-child {
    page-break-after: avoid;
  }
  #wrap_invoice h3{
    font-size: 24px;
    font-weight: bold;
    color: #3785B1;
  }
  #wrap_invoice h4{
    font-size: 15px;
    font-weight: bold;
    color: #3785B1;
  }
  #wrap_invoice p{
    font-size: 12px;
  }    
    
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
    float: left;
}
.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
    position: relative;
    min-height: 1px;
    padding-left: 0.9375rem;
    padding-right: 0.9375rem;	
}  

.col-xs-pull-0 {
  right: auto; }

.col-xs-pull-1 {
  right: 8.33333%; }

.col-xs-pull-2 {
  right: 16.66667%; }

.col-xs-pull-3 {
  right: 25%; }

.col-xs-pull-4 {
  right: 33.33333%; }

.col-xs-pull-5 {
  right: 41.66667%; }

.col-xs-pull-6 {
  right: 50%; }

.col-xs-pull-7 {
  right: 58.33333%; }

.col-xs-pull-8 {
  right: 66.66667%; }

.col-xs-pull-9 {
  right: 75%; }

.col-xs-pull-10 {
  right: 83.33333%; }

.col-xs-pull-11 {
  right: 91.66667%; }

.col-xs-pull-12 {
  right: 100%; }

.col-xs-push-0 {
  left: auto; }

.col-xs-push-1 {
  left: 8.33333%; }

.col-xs-push-2 {
  left: 16.66667%; }

.col-xs-push-3 {
  left: 25%; }

.col-xs-push-4 {
  left: 33.33333%; }

.col-xs-push-5 {
  left: 41.66667%; }

.col-xs-push-6 {
  left: 50%; }

.col-xs-push-7 {
  left: 58.33333%; }

.col-xs-push-8 {
  left: 66.66667%; }

.col-xs-push-9 {
  left: 75%; }

.col-xs-push-10 {
  left: 83.33333%; }

.col-xs-push-11 {
  left: 91.66667%; }

.col-xs-push-12 {
  left: 100%; }

.col-xs-offset-0 {
  margin-left: 0%; }

.col-xs-offset-1 {
  margin-left: 8.33333%; }

.col-xs-offset-2 {
  margin-left: 16.66667%; }

.col-xs-offset-3 {
  margin-left: 25%; }

.col-xs-offset-4 {
  margin-left: 33.33333%; }

.col-xs-offset-5 {
  margin-left: 41.66667%; }

.col-xs-offset-6 {
  margin-left: 50%; }

.col-xs-offset-7 {
  margin-left: 58.33333%; }

.col-xs-offset-8 {
  margin-left: 66.66667%; }

.col-xs-offset-9 {
  margin-left: 75%; }

.col-xs-offset-10 {
  margin-left: 83.33333%; }

.col-xs-offset-11 {
  margin-left: 91.66667%; }

.col-xs-offset-12 {
  margin-left: 100%; }
  
.row.row-equal [class*="col-"] {
    padding-right: 0.46875rem;
    padding-left: 0.46875rem;
}  
.row.row-equal {
    padding-right: 0.46875rem;
    padding-left: 0.46875rem;
    margin-right: -0.9375rem;
    margin-left: -0.9375rem;
}  
  .invoice_status {
    display: block;
    width: 250px;
    background: gray;
    text-align: center;
    color: white;
    text-transform: uppercase;
    padding: 5px 10px;
    font-weight: bold;
    transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    position: absolute;
    right: -70px;
    top: 40px;
	}
  
  .table_invoice{
    border-radius: 0px;
    font-size: 12px;
    width: 100% !important;
  }
  
  .table_invoice thead th{
    vertical-align: middle;
    text-align:center;
    padding: 5px 0;
  }
  
  .table_invoice th, .table_invoice td {
    padding: 2px 8px;
    border-radius: 0px !important;
    width: inherit !important;
  }
  .table_invoice tfoot{
    display: table-footer-group;
  }
  
  .A5 .table_invoice *{
    font-size: 10px !important;
  }
  
  .A5 .table_invoice th, .A5 .table_invoice td {
    line-height: 14px;
    padding: 3px 0;
  }
  
  .A5 p{
    font-size: 10px !important;
    margin: 0;
  }
  
  #wrap_invoice.A5 .inv{
    font-size: 10px !important;
  }
  .A5 .invoice-logo-center,
  .A5 .invoice-logo{
    height: 80px;
    line-height: 80px;
  }
  #wrap_invoice.A5 .A4_info{
    display: none;
  }
  #wrap_invoice hr{
    display:block;
    border-top-color: #dfdfdf;
    margin:10px 0;
  }
  #wrap_invoice .inv{
    vertical-align: middle;
    font-size: 12px;
  }
  #wrap_invoice .inv.col{
    line-height: 25px;
    margin: 10px 0 0 0;
    font-weight: normal;
  }
  #wrap_invoice .inv.col b{
    color: #363636;
  }
  #wrap_invoice .page-title{
    font-size: 18px;
    font-weight: bold;
    color: #3785B1 !important;
    margin: 10px auto 10px;
    line-height: 24px;
  }
  #wrap_invoice .pagging{
    position: absolute;
    right: 10px;
    bottom: 10px;
    padding: 0 10px;
    font-size: 9px;
    font-weight: bold;
  }

  #wrap_invoice,
  #wrap_invoice.portrait{
    width: 21cm;
    max-width: 21cm;
    min-height: 29.6cm;
  }
  #wrap_invoice.landscape{
    width: 29.7cm;
    max-width: 29.7cm;
    min-height: 20.9cm;
  }
  #wrap_invoice.A5,
  #wrap_invoice.A5.portrait{
    width: 14.85cm;
    max-width: 14.85cm;
    min-height: 20.9cm;
  }
  #wrap_invoice.A5.landscape{
    width: 21cm;
    max-width: 21cm;
    min-height: 14.75cm;
  }
  #wrap_invoice.Letter,
  #wrap_invoice.Letter.portrait{
    width: 21.6cm;
    max-width: 21.6cm;
    min-height: 27.8cm;
  }
  #wrap_invoice.Letter.landscape{
    width: 27.9cm;
    max-width: 27.9cm;
    min-height: 21.5cm;
  }
  #wrap_invoice.Legal,
  #wrap_invoice.Legal.portrait{
    width: 21.6cm;
    max-width: 21.6cm;
    min-height: 35.5cm;
  }
  #wrap_invoice.Legal.landscape{
    width: 35.6cm;
    max-width: 35.6cm;
    min-height: 21.5cm;
  }
 
  #wrap_invoice .text-bold{
    font-weight: bold;
  }
  
  #wrap_invoice .float-none{
    float: none !important;
  }
  
  #wrap_invoice .float-left{
    float: left !important;
  }
  
  #wrap_invoice .float-right{
    float: right !important;
  }
  
  #wrap_invoice .bordered{
    border: 1px solid #E0E0E0;
  }
  
  #wrap_invoice .overflow-hidden{
    overflow: hidden;
  }
  
  #wrap_invoice input.trans {
    width: inherit;
    margin: 0px;
    font-size: inherit;
    border: none;
    background: none;
    text-align: center;
    padding: 2px 8px;
  }
  
  .invoice_header .invoice-logo{
    height: 120px;
    line-height: 120px;
    text-align: center;
  }
  
  .invoice_header .invoice-logo-center{
    height: 90px;
    line-height: 90px;
    text-align: center;
  }
  
  .invoice_header .invoice-logo img{
    margin: auto !important;
  }
  
  .invoice_header .invoice-header-invoice{
    padding:10px;
    font-size:12px;
	text-align:right;
    min-height: 120px;
  }
  
  .invoice_header .model1 .invoice-header-invoice{
    border-left: 3px solid #dfdfdf;
  }
  
  .invoice_header .invoice-header-info{
    padding:10px;
    font-size:12px;
    min-height: 120px;
  }
 
  .invoice_header .model1 .invoice-logo{
    min-width: 120px;
    max-width: 240px;
  }
  
  .invoice_header .model1 .invoice-header-info{
    border-left: 3px solid #dfdfdf;
  }
  
  .invoice_header .model2 .invoice-header-info{
    border-right: 3px solid #dfdfdf;
  }
  
  .invoice_header .model2 .invoice-logo{
    text-align: center;
  }
  
  .invoice_header .model3{
    text-align: center;
  }
  
  .invoice_header .model3 .invoice-header-info{
    height: inherit;
  }
  
  .A5.portrait .invoice-header-info{
   max-width:310px;	
  }
  
  .invoice_header .model3 .invoice-logo{
    height: 60px;
    width: inherit;
    line-height: 60px;
    margin: 10px 0 0 0;
  }
  
  .invoice_header .model4 .invoice-logo,
  .invoice_header .model3 .invoice-logo{
    max-width: inherit;
  }
  
  .invoice_header .model3 .invoice-logo img{
    height: inherit;
  }
  
  .invoice_header .model4{
    text-align: center;
  }
  
  .invoice_header .model4 .invoice-logo{
    height: 60px;
    width: inherit;
    line-height: 60px;
    margin: 30px 0;
  }
  
  .invoice_header .model4 .invoice-logo img{
    height: inherit;
  }
  
  .invoice_header{
    background: white;
    color: black;
  }
  
  .invoice_footer{
    text-align: center;
    font-size: 10px;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 20px;
  }



  table {
    background-color: transparent;
  }
  
  th {
    text-align: left;
  }
  
  .table_invoice {
    width: 100%;
    max-width: 100%;
    margin-bottom: 20px;
  }
  
  .table_invoice > thead > tr > th,
  .table_invoice > tbody > tr > th,
  .table_invoice > tfoot > tr > th,
  .table_invoice > thead > tr > td,
  .table_invoice > tbody > tr > td,
  .table_invoice > tfoot > tr > td {
    padding: 8px;
    line-height: 1.42857143;
    vertical-align: center;
    border-top: 1px solid #dddddd;
  }
  
  .table_invoice > thead > tr > th {
    vertical-align: middle;
    border-bottom: 2px solid #dddddd;
  }
  .table_invoice > tfoot > tr > th,
  .table_invoice > tfoot > tr > td{
    border-top: 2px solid #aaaaaa;
  }
  .table_invoice > caption + thead > tr:first-child > th,
  .table_invoice > colgroup + thead > tr:first-child > th,
  .table_invoice > thead:first-child > tr:first-child > th,
  .table_invoice > caption + thead > tr:first-child > td,
  .table_invoice > colgroup + thead > tr:first-child > td,
  .table_invoice > thead:first-child > tr:first-child > td {
    border-top: 0;
  }
  .table_invoice > tbody + tbody {
    border-top: 2px solid #dddddd;
  }
  .table_invoice .table_invoice {
    background-color: #ffffff;
  }
  .table_invoice-condensed > thead > tr > th,
  .table_invoice-condensed > tbody > tr > th,
  .table_invoice-condensed > tfoot > tr > th,
  .table_invoice-condensed > thead > tr > td,
  .table_invoice-condensed > tbody > tr > td,
  .table_invoice-condensed > tfoot > tr > td {
    padding: 0 5px;
  }
  .table_invoice-bordered {
    border: 1px solid #dddddd;
  }
  .table_invoice-bordered > thead > tr > th,
  .table_invoice-bordered > tbody > tr > th,
  .table_invoice-bordered > tfoot > tr > th,
  .table_invoice-bordered > thead > tr > td,
  .table_invoice-bordered > tbody > tr > td,
  .table_invoice-bordered > tfoot > tr > td {
    border: 1px solid #dddddd;
  }
  .table_invoice-bordered > thead > tr > th,
  .table_invoice-bordered > thead > tr > td {
    border-bottom-width: 2px;
  }
  .table_invoice-striped > tbody > tr:nth-child(odd) > td,
  .table_invoice-striped > tbody > tr:nth-child(odd) > th {
    background-color: #f9f9f9;
  }
  table col[class*="col-"] {
    position: static;
    float: none;
    display: table-column;
  }
  table td[class*="col-"],
  table th[class*="col-"] {
    position: static;
    float: none;
    display: table-cell;
  }
  .table_invoice > thead > tr > td.active,
  .table_invoice > tbody > tr > td.active,
  .table_invoice > tfoot > tr > td.active,
  .table_invoice > thead > tr > th.active,
  .table_invoice > tbody > tr > th.active,
  .table_invoice > tfoot > tr > th.active,
  .table_invoice > thead > tr.active > td,
  .table_invoice > tbody > tr.active > td,
  .table_invoice > tfoot > tr.active > td,
  .table_invoice > thead > tr.active > th,
  .table_invoice > tbody > tr.active > th,
  .table_invoice > tfoot > tr.active > th {
    background-color: #f5f5f5;
  }
  .table_invoice > thead > tr > td.success,
  .table_invoice > tbody > tr > td.success,
  .table_invoice > tfoot > tr > td.success,
  .table_invoice > thead > tr > th.success,
  .table_invoice > tbody > tr > th.success,
  .table_invoice > tfoot > tr > th.success,
  .table_invoice > thead > tr.success > td,
  .table_invoice > tbody > tr.success > td,
  .table_invoice > tfoot > tr.success > td,
  .table_invoice > thead > tr.success > th,
  .table_invoice > tbody > tr.success > th,
  .table_invoice > tfoot > tr.success > th {
    background-color: #dff0d8;
  }
  .table_invoice > thead > tr > td.info,
  .table_invoice > tbody > tr > td.info,
  .table_invoice > tfoot > tr > td.info,
  .table_invoice > thead > tr > th.info,
  .table_invoice > tbody > tr > th.info,
  .table_invoice > tfoot > tr > th.info,
  .table_invoice > thead > tr.info > td,
  .table_invoice > tbody > tr.info > td,
  .table_invoice > tfoot > tr.info > td,
  .table_invoice > thead > tr.info > th,
  .table_invoice > tbody > tr.info > th,
  .table_invoice > tfoot > tr.info > th {
    background-color: #d9edf7;
  }
  .table_invoice > thead > tr > td.warning,
  .table_invoice > tbody > tr > td.warning,
  .table_invoice > tfoot > tr > td.warning,
  .table_invoice > thead > tr > th.warning,
  .table_invoice > tbody > tr > th.warning,
  .table_invoice > tfoot > tr > th.warning,
  .table_invoice > thead > tr.warning > td,
  .table_invoice > tbody > tr.warning > td,
  .table_invoice > tfoot > tr.warning > td,
  .table_invoice > thead > tr.warning > th,
  .table_invoice > tbody > tr.warning > th,
  .table_invoice > tfoot > tr.warning > th {
    background-color: #fcf8e3;
  }
  .table_invoice > thead > tr > td.danger,
  .table_invoice > tbody > tr > td.danger,
  .table_invoice > tfoot > tr > td.danger,
  .table_invoice > thead > tr > th.danger,
  .table_invoice > tbody > tr > th.danger,
  .table_invoice > tfoot > tr > th.danger,
  .table_invoice > thead > tr.danger > td,
  .table_invoice > tbody > tr.danger > td,
  .table_invoice > tfoot > tr.danger > td,
  .table_invoice > thead > tr.danger > th,
  .table_invoice > tbody > tr.danger > th,
  .table_invoice > tfoot > tr.danger > th {
    background-color: #f2dede;
  }
  .text-danger {
    color: #DD0703 !important;
  }
  a.text-danger:hover {
    color: #843534;
  }

  .vertical-middle{
    vertical-align: middle;
  }
  .control-label{
    width: 27%;
    display: inline-block;
    line-height: 20px;
    font-weight: bold;
    vertical-align: top;
  }
  .control-p{
    width: 65%;
    display: inline-block;
    line-height: 20px;
  }
  .col-sm-6 > .control-label{
    width: 42%;
  }
  .col-sm-6 > .control-p{
    width: 50%;
  }
  .column-border {
    border-right: 1px solid #ddd;
  }
  text[text-anchor="end"] {
    display:none;
  }
	
.col-xs-offset-8 {
    margin-left: 66.66667%;
}	
.demo_invoice{
  color: rgba(0,0,0,0.2);
  position: absolute;
  font-size: 9rem;
  top: 25%;
  left: 15%;
  transform: rotate(-45deg);
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

.text-md-center {
    text-align: center !important;
}
.text-md-left {
    text-align: left !important;
}
.text-md-right {
    text-align: right !important;
}
			
@media print {
    @page{
	  size: A4;	
      margin: 0.7cm;
    }
		
    #wrap_invoice {
      margin: 0;
      padding: 0.5cm;
      border: initial;
      border-radius: initial;
      box-shadow: initial;
      overflow: hidden;
      transform: inherit !important;
      -webkit-transform: inherit !important;
      transform-origin: inherit !important;
      -webkit-transform-origin: inherit !important;
    }
	
    #wrap_invoice {
      page-break-after: always;
    }
	
    #wrap_invoice:last-child {
      page-break-after: avoid;
    }
	
    #not-printed{
      display: none;
    }
  }
</style>
<div id="css_script">
<style type="text/css" id="pageInit">@page{size: 21cm 29.7cm}</style>
<style type="text/css">
        #wrap_invoice.page {
            font-family: Arial, Helvetica, sans-serif;
            background-color: #ffffff;
            padding: 0.5cm 0.5cm 0.5cm 0.5cm;
            z-index: 1;
        }

        #wrap_invoice::after {
            content: "";
            display: block;
            background-repeat: no-repeat;
            /*background-image: url(http://localhost/sis/storage/logo14.png);*/
            background-position: center center;
            background-size: initial;
            opacity: 0.4;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            position: absolute;
            z-index: -1;
        }

        #wrap_invoice h3 {
            color: #009be1;
        }

        #wrap_invoice h4 {
            color: #009be1;
        }

        .invoice_header .invoice-logo img {
            height: 100% !important;
            width: auto !important;
            max-width: 100%;
        }

		.A5 .invoice-logo img {
            height: auto !important;
			width: 100% !important;
			max-height: 100%;
        }
	
        #wrap_invoice,
        #wrap_invoice p,
        #wrap_invoice .text-color,
        #wrap_invoice .inv.col b,
        #wrap_invoice .table_invoice {
            font-size: 12px;
            color: #2e2e2e;
        }

        #wrap_invoice .table_invoice thead th {
            border: none;
			border-top: 1px solid red;
			border-left: 1px solid #dddddd;
			border-bottom: 1px solid black;
			line-height: 24px;
			height: 24px;
        }

        #wrap_invoice .table_invoice td {
            line-height: 23px;
            height: 23px;
        }

        #wrap_invoice .page-title {
            color: #009be1;
            text-align: center;
        }

        #wrap_invoice .invoice_header {
            background: #ffffff;
            color: #000000 !important;
            margin: -0.5cm -0.5cm 0 -0.5cm;
            padding: 0.5cm 0.5cm 0 0.5cm;
        }

        #wrap_invoice .invoice_header * {
            color: #000000 !important;
            margin: 0;
        }

        #wrap_invoice .invoice_footer,
        #wrap_invoice .invoice_footer p,
        #wrap_invoice .invoice_footer .pagging {
            background: #ffffff;
            color: #2e2e2e;
        }
    </style>
</div>    
<?php

function get_cbamo($invno){
global $con;
$sql="SELECT SUM(ofamo) AS cbamo FROM tbl_traproduct WHERE invno='$invno'";
$admin=mysqli_query($con,$sql) or die(mysqli_error($con));    
$adm=mysqli_fetch_array($admin);
return $adm['cbamo'];    
}
    
if(isset($_POST['print'])){
$invid=$_POST['print'];
$key=$_POST['key'];     
$sql="SELECT * FROM tbl_sales WHERE id='".$invid."' LIMIT 1";     
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
$rowadd=mysqli_fetch_array($query);
$id=$rowadd['id'];
$invno=$rowadd['invno'];     
}
$user= get_fild_data('tbl_user',$rowadd['uid'],'name');//user_name($aid)['funame'];
?>
<?php if($key=='invonly'){?>    
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div class="col-xs-3 invoice-logo">
<img src="../img/<?php if(empty(get_cominfo('1','logo'))){echo "no_logo.png";}else{echo get_cominfo('1','logo');}?>" alt="<?php echo get_cominfo('1','name');?>" style="vertical-align:middle; width: 100%;">
</div>
<div class="col-xs-5 invoice-header-info" id="adheight">
<h4><?php echo get_cominfo('1','name');?></h4>
<?php echo get_cominfo('1','',$rowadd['brid']);?>
</div>
<div class="col-xs-4 invoice-header-invoice" id="inheight" style="height: 140px;">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>
<?php if (strlen($rowadd['selp'])>0){ ?>
<?php echo "<br><strong>S.Person:</strong> ".get_fild_data('tbl_employe',$rowadd['selp'],'name');?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>  
</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">SALES INVOICE</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<?php if(strlen(tender_address('tbl_sales',$invid))>5){?>
<div class="col-4 col-xs-4">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<?php }else{ ?>    
<div class="col-6 col-xs-6">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-6 col-xs-6">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<?php } ?>    
<div class="clearfix"></div>    
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:52.5% !important;">Description(Code)</th>
<th style="width:12.5% !important;">Price</th>
<th style="width:10% !important;">Qty</th>
<th style="width:7.5% !important;">Dis</th>
<th style="width:12.5% !important;">Total</th>
</tr>
</thead>
<tbody>
<?php
$rspan=0;
$tqty=0;
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,SUM(tbl_traproduct.p_out+tbl_traproduct.p_loc) AS qty,tbl_traproduct.disp AS disc,tbl_traproduct.disamo,tbl_traproduct.price,SUM(tbl_traproduct.subtot) AS total,tbl_traproduct.wday AS warenDays,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid,tbl_item.pmod AS reimei,tbl_unit.name AS unit,(SELECT GROUP_CONCAT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mserial,(SELECT COUNT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mcount,tbl_country.name AS country,tbl_traproduct.pnote,tbl_traproduct.wday FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid LEFT JOIN tbl_unit On tbl_unit.id=tbl_item.unid LEFT JOIN tbl_country ON tbl_country.id=tbl_item.couid WHERE invno='".$rowadd['invno']."' GROUP BY tbl_traproduct.pid,tbl_traproduct.price";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';    
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];

if($rows['pnote']!='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=2;
}else{
$espan=3;
}
$rspan=3;	
}elseif($rows['pnote']=='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=0;
}else{
$espan=2;
}
$rspan=2;
}elseif($rows['pnote']!='' && $rows['mserial']==''){
$espan=2;
$rspan=2;	
}else{
$espan=0;	
$rspan=0;	
}    
    
if($rows['mserial']!=''){
if($rows['reimei']==0 || $rows['reimei']==1){
$type='SL#';
}else{
$type='IMEI#';	
}
}
?>
<?php if($rspan>0){ ?>
<tr>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>    
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>
    
<?php if($rspan>2){ ?>
<tr>
<td class="text-md-left"><?php echo $rows['pnote']; ?></td>
</tr>
<tr>
<td class="text-md-left beak-line"><?php if($rows['wday']>0){
$wday=$rows['wday'];
echo $type.sl_break($rows['mserial'],',').' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));}else{echo $type.$rows['mserial'];} ?></td>
</tr>
<?php }else{ 
$ecdata='';
if($rows['mserial']!=''){
$ecdata=$type.sl_break($rows['mserial'],',');
if($rows['wday']>0){
$wday=$rows['wday'];    
$ecdata.=' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));    
}
}else{
$ecdata=$rows['pnote'];	
}
?>
<tr>
<td class="text-md-left beak-line"><?php echo $ecdata; ?></td>
</tr>
<?php } ?>
    
<?php }else{ ?>
<tr>
<td class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>    
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>	
<?php } ?> 

<?php } ?>			
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Sub Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['subtot'],''); ?></td>
</tr>
<?php if($rowadd['itemdis']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Item Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['itemdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Invoice Discount (<?php echo floatval($rowadd['disp']).'%';?>)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['disamo'],''); ?></td>
</tr>
<?php } ?>    
<?php if($rowadd['itemdis']>0 && $rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php if($rowadd['totdis']>0 && $rowadd['disamo']>0){echo 'Total ';} ?>Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['totdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['vatamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">VAT (<?php echo floatval($rowadd['vatp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['vatamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['aitamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">AIT (<?php echo floatval($rowadd['aitp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['aitamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['otamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php echo $rowadd['otname'];?></td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['otamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['freight']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Freight</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['freight'],''); ?></td>
</tr>
<?php } ?>
<?php if(get_cbamo($invno)>0){?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Cash Back</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_cbamo($invno),''); ?></td>
</tr>    
<?php } ?>    
<?php if($rowadd['less']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Amount Less</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['less'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Gross Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['total'],''); ?></td>
</tr>
<?php if($rowadd['adamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Advance Adjust</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['adamo'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" class="text-md-center"><?php if(($rowadd['changes'])>0){echo '<strong>Pay: '.numtolocal($rowadd['rawcash'],'').', Return: '.numtolocal($rowadd['changes'],'').'</strong>';}?></td>
<td colspan="2" class="text-md-right font-weight-bold">Paid Amount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_invcash($invno,'S','Y'),''); ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Outstanding</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo'])),''); ?></td>
</tr>
</tbody>
</table>
<!-- AMOUNT IN WORDS -->
<p>
<b>Amount in words: 
</b>
<span style="text-transform: uppercase;">
<?php echo numtoword(ABS($rowadd['total'])).'';?>		
<?php echo '<b>'.get_fild_data('tbl_currency','1','name').'</b> Only'; ?>
</span>
</p>
<?php
$did=$rowadd['type'].$rowadd['cusid'];                                                 
$ldebit=get_ledgerval($did,'D','O',$rowadd['apdate']);
$lcredit=get_ledgerval($did,'C','O',$rowadd['apdate']);
if($rowadd['cusid']!=0){
$lnet=($ldebit-$lcredit);    
}else{
$lnet=0;    
}
$outst=($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo']));
if($lnet>0){
$fdue=($lnet+$outst);     
}else{
$fdue=$outst;     
}
   
if(get_fild_data('tbl_setting','5','sval')==0){
if($lnet>0){    
?>
<div class="row">
<div class="col-xs-5">    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="text-center" colspan="2">Previous Balance</th>   
</tr>    
</thead>
<tbody>
<tr>
<td>Previous Due</td>
<td class="text-md-right"><?php if($lnet>0){echo numtolocal($lnet,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td>Invoice Due</td>
<td class="text-md-right"><?php if($outst>0){echo numtolocal($outst,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td><strong>Total Due</strong></td>
<td class="text-md-right"><strong><?php if($fdue>0){echo numtolocal($fdue,'');}else{echo numtolocal(0,'');}?></strong></td>    
</tr>    
</tbody>
</table>
</div>
</div>    
<?php }} ?>     
</div>    
</div>
<?php if(get_fild_data('tbl_setting','7','sval')==0){?>    
<div class="col-xs-12 inv"><strong>Terms &amp; Conditions</strong>
<?php echo get_fild_data('tbl_setting','6','sval'); ?>
</div>
<?php } ?>    
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
<div class="invoice_footer">
<hr>
<p style="margin-top: -5px;"><?php echo get_cominfo('1','name');?>. © <?php echo date('Y');?></p>
</div>
<div style="clear: both;"></div>
</div>
</div>
<?php } ?>
<?php if($key=='chaonly'){?>
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div class="col-xs-3 invoice-logo">
<img src="../img/<?php if(empty(get_cominfo('1','logo'))){echo "no_logo.png";}else{echo get_cominfo('1','logo');}?>" alt="<?php echo get_cominfo('1','name');?>" style="vertical-align:middle; width: 100%;">
</div>
<div class="col-xs-5 invoice-header-info" id="adheight">
<h4><?php echo get_cominfo('1','name');?></h4>
<?php echo get_cominfo('1','',$rowadd['brid']);?>
</div>
<div class="col-xs-4 invoice-header-invoice" id="inheight" style="height: 140px;">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".str_replace('SEL','CHS',$rowadd['invno']);?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>  
</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">DELIVERY CHALLAN</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<?php if(strlen(tender_address('tbl_sales',$invid))>5){?>
<div class="col-4 col-xs-4">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<?php }else{ ?>    
<div class="col-6 col-xs-6">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-6 col-xs-6">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<?php } ?>
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:85% !important;">Description(Code)</th>
<th style="width:10% !important;">Qty</th>
</tr>
</thead>
<tbody>
<?php
$s=0;                           
$rspan=0;
$tqty=0;   
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,tbl_traproduct.p_out AS qty,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid WHERE invno='".$rowadd['invno']."'";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];
$s+=1;    
?>
<tr>
<td class="text-md-center"><?php echo $s; ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>    
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-center"><?php echo $rows['qty']; ?></td>
</tr>    
<?php } ?>			
<tr>
<td colspan="2" class="text-md-center">-Total Quantity-</td>
<td class="text-md-center font-weight-bold"><?php echo $tqty; ?></td>
</tr>
</tbody>
</table>   
</div>    
</div>
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
<div class="invoice_footer">
<hr>
<p style="margin-top: -5px;"><?php echo get_cominfo('1','name');?>. © <?php echo date('Y');?></p>
</div>
<div style="clear: both;"></div>
</div>
</div>    
<?php } ?>
<?php if($key=='chainv'){?>
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div class="col-xs-3 invoice-logo">
<img src="../img/<?php if(empty(get_cominfo('1','logo'))){echo "no_logo.png";}else{echo get_cominfo('1','logo');}?>" alt="<?php echo get_cominfo('1','name');?>" style="vertical-align:middle; width: 100%;">
</div>
<div class="col-xs-5 invoice-header-info" id="adheight">
<h4><?php echo get_cominfo('1','name');?></h4>
<?php echo get_cominfo('1','',$rowadd['brid']);?>
</div>
<div class="col-xs-4 invoice-header-invoice" id="inheight" style="height: 140px;">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>
<?php if (strlen($rowadd['selp'])>0){ ?>
<?php echo "<br><strong>S.Person:</strong> ".get_fild_data('tbl_employe',$rowadd['selp'],'name');?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>  
</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">SALES INVOICE</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<?php if(strlen(tender_address('tbl_sales',$invid))>5){?>
<div class="col-4 col-xs-4">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<?php }else{ ?>    
<div class="col-6 col-xs-6">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-6 col-xs-6">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<?php } ?>
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:52.5% !important;">Description(Code)</th>
<th style="width:12.5% !important;">Price</th>
<th style="width:10% !important;">Qty</th>
<th style="width:7.5% !important;">Dis</th>
<th style="width:12.5% !important;">Total</th>
</tr>
</thead>
<tbody>
<?php
$rspan=0;
$tqty=0;
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,SUM(tbl_traproduct.p_out+tbl_traproduct.p_loc) AS qty,tbl_traproduct.disp AS disc,tbl_traproduct.disamo,tbl_traproduct.price,SUM(tbl_traproduct.subtot) AS total,tbl_traproduct.wday AS warenDays,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid,tbl_item.pmod AS reimei,tbl_unit.name AS unit,(SELECT GROUP_CONCAT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mserial,(SELECT COUNT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mcount,tbl_country.name AS country,tbl_traproduct.pnote,tbl_traproduct.wday FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid LEFT JOIN tbl_unit On tbl_unit.id=tbl_item.unid LEFT JOIN tbl_country ON tbl_country.id=tbl_item.couid WHERE invno='".$rowadd['invno']."' GROUP BY tbl_traproduct.pid,tbl_traproduct.price";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];

if($rows['pnote']!='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=2;
}else{
$espan=3;
}
$rspan=3;	
}elseif($rows['pnote']=='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=0;
}else{
$espan=2;
}
$rspan=2;
}elseif($rows['pnote']!='' && $rows['mserial']==''){
$espan=2;
$rspan=2;	
}else{
$espan=0;	
$rspan=0;	
}    
    
if($rows['mserial']!=''){
if($rows['reimei']==0 || $rows['reimei']==1){
$type='SL#';
}else{
$type='IMEI#';	
}
}
?>
<?php if($rspan>0){ ?>
<tr>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>
    
<?php if($rspan>2){ ?>
<tr>
<td class="text-md-left"><?php echo $rows['pnote']; ?></td>
</tr>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php if($rows['wday']>0){
$wday=$rows['wday'];
echo $type.$rows['mserial'].' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));}else{echo $type.$rows['mserial'];} ?></td>
</tr>
<?php }else{ 
$ecdata='';
if($rows['mserial']!=''){
$ecdata=$type.$rows['mserial'];
if($rows['wday']>0){
$wday=$rows['wday'];    
$ecdata.=' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));    
}
}else{
$ecdata=$rows['pnote'];	
}
?>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php echo $ecdata; ?></td>
</tr>
<?php } ?>
    
<?php }else{ ?>
<tr>
<td class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>	
<?php } ?> 

<?php } ?>			
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Sub Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['subtot'],''); ?></td>
</tr>
<?php if($rowadd['itemdis']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Item Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['itemdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Invoice Discount (<?php echo floatval($rowadd['disp']).'%';?>)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['disamo'],''); ?></td>
</tr>
<?php } ?>    
<?php if($rowadd['itemdis']>0 && $rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php if($rowadd['totdis']>0 && $rowadd['disamo']>0){echo 'Total ';} ?>Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['totdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['vatamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">VAT (<?php echo floatval($rowadd['vatp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['vatamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['aitamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">AIT (<?php echo floatval($rowadd['aitp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['aitamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['otamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php echo $rowadd['otname'];?></td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['otamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['freight']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Freight</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['freight'],''); ?></td>
</tr>
<?php } ?>
<?php if(get_cbamo($invno)>0){?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Cash Back</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_cbamo($invno),''); ?></td>
</tr>    
<?php } ?>    
<?php if($rowadd['less']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Amount Less</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['less'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Gross Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['total'],''); ?></td>
</tr>
<?php if($rowadd['adamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Advance Adjust</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['adamo'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" class="text-md-center"><?php if(($rowadd['changes'])>0){echo '<strong>Pay: '.numtolocal($rowadd['rawcash'],'').', Return: '.numtolocal($rowadd['changes'],'').'</strong>';}?></td>
<td colspan="2" class="text-md-right font-weight-bold">Paid Amount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_invcash($invno,'S','Y'),''); ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Outstanding</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo'])),''); ?></td>
</tr>
</tbody>
</table>
<!-- AMOUNT IN WORDS -->
<p>
<b>Amount in words: 
</b>
<span style="text-transform: uppercase;">
<?php echo numtoword(ABS($rowadd['total'])).'';?>		
<?php echo '<b>'.get_fild_data('tbl_currency','1','name').'</b> Only'; ?>
</span>
</p>
<?php
$did=$rowadd['type'].$rowadd['cusid'];                                                 
$ldebit=get_ledgerval($did,'D','O',$rowadd['apdate']);
$lcredit=get_ledgerval($did,'C','O',$rowadd['apdate']);
if($rowadd['cusid']!=0){
$lnet=($ldebit-$lcredit);    
}else{
$lnet=0;    
}
$outst=($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo']));
if($lnet>0){
$fdue=($lnet+$outst);     
}else{
$fdue=$outst;     
}
   
if(get_fild_data('tbl_setting','5','sval')==0){
if($lnet>0){    
?>
<div class="row">
<div class="col-xs-5">    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="text-center" colspan="2">Previous Balance</th>   
</tr>    
</thead>
<tbody>
<tr>
<td>Previous Due</td>
<td class="text-md-right"><?php if($lnet>0){echo numtolocal($lnet,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td>Invoice Due</td>
<td class="text-md-right"><?php if($outst>0){echo numtolocal($outst,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td><strong>Total Due</strong></td>
<td class="text-md-right"><strong><?php if($fdue>0){echo numtolocal($fdue,'');}else{echo numtolocal(0,'');}?></strong></td>    
</tr>    
</tbody>
</table>
</div>
</div>    
<?php }} ?>     
</div>    
</div>
<?php if(get_fild_data('tbl_setting','7','sval')==0){?>    
<div class="col-xs-12 inv"><strong>Terms &amp; Conditions</strong>
<?php echo get_fild_data('tbl_setting','6','sval'); ?>
</div>
<?php } ?>    
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
<div class="invoice_footer">
<hr>
<p style="margin-top: -5px;"><?php echo get_cominfo('1','name');?>. © <?php echo date('Y');?></p>
</div>
<div style="clear: both;"></div>
</div>
</div>
       
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div class="col-xs-3 invoice-logo">
<img src="../img/<?php if(empty(get_cominfo('1','logo'))){echo "no_logo.png";}else{echo get_cominfo('1','logo');}?>" alt="<?php echo get_cominfo('1','name');?>" style="vertical-align:middle; width: 100%;">
</div>
<div class="col-xs-5 invoice-header-info" id="adheight">
<h4><?php echo get_cominfo('1','name');?></h4>
<?php echo get_cominfo('1','',$rowadd['brid']);?>
</div>
<div class="col-xs-4 invoice-header-invoice" id="inheight" style="height: 140px;">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".str_replace('SEL','CHS',$rowadd['invno']);?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>  
</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">DELIVERY CHALLAN</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<?php if(strlen(tender_address('tbl_sales',$invid))>5){?>
<div class="col-4 col-xs-4">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-4 col-xs-4">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<?php }else{ ?>    
<div class="col-6 col-xs-6">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-6 col-xs-6">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<?php } ?>
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:85% !important;">Description(Code)</th>
<th style="width:10% !important;">Qty</th>
</tr>
</thead>
<tbody>
<?php
$s=0;                           
$rspan=0;
$tqty=0;   
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,tbl_traproduct.p_out AS qty,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid WHERE invno='".$rowadd['invno']."'";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];
$s+=1;    
?>
<tr>
<td class="text-md-center"><?php echo $s; ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-center"><?php echo $rows['qty']; ?></td>
</tr>    
<?php } ?>			
<tr>
<td colspan="2" class="text-md-center">-Total Quantity-</td>
<td class="text-md-center font-weight-bold"><?php echo $tqty; ?></td>
</tr>
</tbody>
</table>   
</div>    
</div>
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
<div class="invoice_footer">
<hr>
<p style="margin-top: -5px;"><?php echo get_cominfo('1','name');?>. © <?php echo date('Y');?></p>
</div>
<div style="clear: both;"></div>
</div>
</div>    
<?php } ?>
<?php if($key=='padonly'){?>
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div style="margin-top:3.81cm;">&nbsp;</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">SALES INVOICE</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<div class="col-3 col-xs-3">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<div class="col-3 col-xs-3 text-invright">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>
</div>    
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:52.5% !important;">Description(Code)</th>
<th style="width:12.5% !important;">Price</th>
<th style="width:10% !important;">Qty</th>
<th style="width:7.5% !important;">Dis</th>
<th style="width:12.5% !important;">Total</th>
</tr>
</thead>
<tbody>
<?php
$rspan=0;
$tqty=0;
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,SUM(tbl_traproduct.p_out+tbl_traproduct.p_loc) AS qty,tbl_traproduct.disp AS disc,tbl_traproduct.disamo,tbl_traproduct.price,SUM(tbl_traproduct.subtot) AS total,tbl_traproduct.wday AS warenDays,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid,tbl_item.pmod AS reimei,tbl_unit.name AS unit,(SELECT GROUP_CONCAT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mserial,(SELECT COUNT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mcount,tbl_country.name AS country,tbl_traproduct.pnote,tbl_traproduct.wday FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid LEFT JOIN tbl_unit On tbl_unit.id=tbl_item.unid LEFT JOIN tbl_country ON tbl_country.id=tbl_item.couid WHERE invno='".$rowadd['invno']."' GROUP BY tbl_traproduct.pid,tbl_traproduct.price";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];

if($rows['pnote']!='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=2;
}else{
$espan=3;
}
$rspan=3;	
}elseif($rows['pnote']=='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=0;
}else{
$espan=2;
}
$rspan=2;
}elseif($rows['pnote']!='' && $rows['mserial']==''){
$espan=2;
$rspan=2;	
}else{
$espan=0;	
$rspan=0;	
}    
    
if($rows['mserial']!=''){
if($rows['reimei']==0 || $rows['reimei']==1){
$type='SL#';
}else{
$type='IMEI#';	
}
}
?>
<?php if($rspan>0){ ?>
<tr>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>
    
<?php if($rspan>2){ ?>
<tr>
<td class="text-md-left"><?php echo $rows['pnote']; ?></td>
</tr>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php if($rows['wday']>0){
$wday=$rows['wday'];
echo $type.$rows['mserial'].' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));}else{echo $type.$rows['mserial'];} ?></td>
</tr>
<?php }else{ 
$ecdata='';
if($rows['mserial']!=''){
$ecdata=$type.$rows['mserial'];
if($rows['wday']>0){
$wday=$rows['wday'];    
$ecdata.=' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));    
}
}else{
$ecdata=$rows['pnote'];	
}
?>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php echo $ecdata; ?></td>
</tr>
<?php } ?>
    
<?php }else{ ?>
<tr>
<td class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>	
<?php } ?> 

<?php } ?>			
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Sub Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['subtot'],''); ?></td>
</tr>
<?php if($rowadd['itemdis']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Item Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['itemdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Invoice Discount (<?php echo floatval($rowadd['disp']).'%';?>)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['disamo'],''); ?></td>
</tr>
<?php } ?>    
<?php if($rowadd['itemdis']>0 && $rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php if($rowadd['totdis']>0 && $rowadd['disamo']>0){echo 'Total ';} ?>Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['totdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['vatamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">VAT (<?php echo floatval($rowadd['vatp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['vatamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['aitamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">AIT (<?php echo floatval($rowadd['aitp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['aitamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['otamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php echo $rowadd['otname'];?></td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['otamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['freight']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Freight</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['freight'],''); ?></td>
</tr>
<?php } ?>
<?php if(get_cbamo($invno)>0){?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Cash Back</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_cbamo($invno),''); ?></td>
</tr>    
<?php } ?>    
<?php if($rowadd['less']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Amount Less</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['less'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Gross Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['total'],''); ?></td>
</tr>
<?php if($rowadd['adamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Advance Adjust</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['adamo'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" class="text-md-center"><?php if(($rowadd['changes'])>0){echo '<strong>Pay: '.numtolocal($rowadd['rawcash'],'').', Return: '.numtolocal($rowadd['changes'],'').'</strong>';}?></td>
<td colspan="2" class="text-md-right font-weight-bold">Paid Amount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_invcash($invno,'S','Y'),''); ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Outstanding</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo'])),''); ?></td>
</tr>
</tbody>
</table>
<!-- AMOUNT IN WORDS -->
<p>
<b>Amount in words: 
</b>
<span style="text-transform: uppercase;">
<?php echo numtoword(ABS($rowadd['total'])).'';?>		
<?php echo '<b>'.get_fild_data('tbl_currency','1','name').'</b> Only'; ?>
</span>
</p>
<?php
$did=$rowadd['type'].$rowadd['cusid'];                                                 
$ldebit=get_ledgerval($did,'D','O',$rowadd['apdate']);
$lcredit=get_ledgerval($did,'C','O',$rowadd['apdate']);
if($rowadd['cusid']!=0){
$lnet=($ldebit-$lcredit);    
}else{
$lnet=0;    
}
$outst=($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo']));
if($lnet>0){
$fdue=($lnet+$outst);     
}else{
$fdue=$outst;     
}
   
if(get_fild_data('tbl_setting','5','sval')==0){
if($lnet>0){    
?>
<div class="row">
<div class="col-xs-5">    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="text-center" colspan="2">Previous Balance</th>   
</tr>    
</thead>
<tbody>
<tr>
<td>Previous Due</td>
<td class="text-md-right"><?php if($lnet>0){echo numtolocal($lnet,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td>Invoice Due</td>
<td class="text-md-right"><?php if($outst>0){echo numtolocal($outst,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td><strong>Total Due</strong></td>
<td class="text-md-right"><strong><?php if($fdue>0){echo numtolocal($fdue,'');}else{echo numtolocal(0,'');}?></strong></td>    
</tr>    
</tbody>
</table>
</div>
</div>    
<?php }} ?>     
</div>    
</div>
<?php if(get_fild_data('tbl_setting','7','sval')==0){?>    
<div class="col-xs-12 inv"><strong>Terms &amp; Conditions</strong>
<?php echo get_fild_data('tbl_setting','6','sval'); ?>
</div>
<?php } ?>    
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
</div>
</div>
<?php } ?>
<?php if($key=='padcha'){?>
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div style="margin-top:3.81cm;">&nbsp;</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">DELIVERY CHALLAN</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<div class="col-3 col-xs-3">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<div class="col-3 col-xs-3 text-invright">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>
</div>    
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:85% !important;">Description(Code)</th>
<th style="width:10% !important;">Qty</th>
</tr>
</thead>
<tbody>
<?php
$s=0;                           
$rspan=0;
$tqty=0;   
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,tbl_traproduct.p_out AS qty,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid WHERE invno='".$rowadd['invno']."'";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];
$s+=1;    
?>
<tr>
<td class="text-md-center"><?php echo $s; ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-center"><?php echo $rows['qty']; ?></td>
</tr>    
<?php } ?>			
<tr>
<td colspan="2" class="text-md-center">-Total Quantity-</td>
<td class="text-md-center font-weight-bold"><?php echo $tqty; ?></td>
</tr>
</tbody>
</table>   
</div>    
</div>
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
</div>
</div>    
<?php } ?> 
<?php if($key=='padchainv'){?>
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div style="margin-top:3.81cm;">&nbsp;</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">SALES INVOICE</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<div class="col-3 col-xs-3">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<div class="col-3 col-xs-3 text-invright">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>
</div>   
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:52.5% !important;">Description(Code)</th>
<th style="width:12.5% !important;">Price</th>
<th style="width:10% !important;">Qty</th>
<th style="width:7.5% !important;">Dis</th>
<th style="width:12.5% !important;">Total</th>
</tr>
</thead>
<tbody>
<?php
$rspan=0;
$tqty=0;
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,SUM(tbl_traproduct.p_out+tbl_traproduct.p_loc) AS qty,tbl_traproduct.disp AS disc,tbl_traproduct.disamo,tbl_traproduct.price,SUM(tbl_traproduct.subtot) AS total,tbl_traproduct.wday AS warenDays,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid,tbl_item.pmod AS reimei,tbl_unit.name AS unit,(SELECT GROUP_CONCAT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mserial,(SELECT COUNT(serial) FROM tbl_serialsale WHERE invno=tbl_traproduct.invno AND tbl_serialsale.pid=tbl_traproduct.pid) AS mcount,tbl_country.name AS country,tbl_traproduct.pnote,tbl_traproduct.wday FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid LEFT JOIN tbl_unit On tbl_unit.id=tbl_item.unid LEFT JOIN tbl_country ON tbl_country.id=tbl_item.couid WHERE invno='".$rowadd['invno']."' GROUP BY tbl_traproduct.pid,tbl_traproduct.price";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];

if($rows['pnote']!='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=2;
}else{
$espan=3;
}
$rspan=3;	
}elseif($rows['pnote']=='' && $rows['mserial']!=''){
if($rows['mcount']>1){
$espan=0;
}else{
$espan=2;
}
$rspan=2;
}elseif($rows['pnote']!='' && $rows['mserial']==''){
$espan=2;
$rspan=2;	
}else{
$espan=0;	
$rspan=0;	
}    
    
if($rows['mserial']!=''){
if($rows['reimei']==0 || $rows['reimei']==1){
$type='SL#';
}else{
$type='IMEI#';	
}
}
?>
<?php if($rspan>0){ ?>
<tr>
<td rowspan="<?php echo $rspan; ?>" class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td <?php if($espan>0){echo 'rowspan="'.$espan.'"';}?> class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td rowspan="<?php echo $rspan; ?>" class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>
    
<?php if($rspan>2){ ?>
<tr>
<td class="text-md-left"><?php echo $rows['pnote']; ?></td>
</tr>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php if($rows['wday']>0){
$wday=$rows['wday'];
echo $type.$rows['mserial'].' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));}else{echo $type.$rows['mserial'];} ?></td>
</tr>
<?php }else{ 
$ecdata='';
if($rows['mserial']!=''){
$ecdata=$type.$rows['mserial'];
if($rows['wday']>0){
$wday=$rows['wday'];    
$ecdata.=' Exp.Date: '.date('Y-m-d', strtotime('+'.$wday.' days',strtotime($rowadd['apdate'])));    
}
}else{
$ecdata=$rows['pnote'];	
}
?>
<tr>
<td class="text-md-left beak-line" <?php if($rows['mcount']>1){echo 'colspan="4"';} ?>><?php echo $ecdata; ?></td>
</tr>
<?php } ?>
    
<?php }else{ ?>
<tr>
<td class="text-md-center"><?php echo count_id(); ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-right"><?php echo numtolocal($rows['price'],''); ?></td>
<td class="text-md-center"><?php echo $rows['qty'].' '.$rows['unit']; ?></td>
<td class="text-md-center"><?php if($rows['disc']>0){echo $rows['disc'].'%';}else{echo '';}?></td>
<td class="text-md-right"><?php echo numtolocal($rows['total'],''); ?></td>
</tr>	
<?php } ?> 

<?php } ?>			
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Sub Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['subtot'],''); ?></td>
</tr>
<?php if($rowadd['itemdis']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Item Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['itemdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Invoice Discount (<?php echo floatval($rowadd['disp']).'%';?>)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['disamo'],''); ?></td>
</tr>
<?php } ?>    
<?php if($rowadd['itemdis']>0 && $rowadd['disamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php if($rowadd['totdis']>0 && $rowadd['disamo']>0){echo 'Total ';} ?>Discount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['totdis'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['vatamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">VAT (<?php echo floatval($rowadd['vatp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['vatamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['aitamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">AIT (<?php echo floatval($rowadd['aitp']);?>%)</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['aitamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['otamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold"><?php echo $rowadd['otname'];?></td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['otamo'],''); ?></td>
</tr>
<?php } ?>
<?php if($rowadd['freight']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Freight</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['freight'],''); ?></td>
</tr>
<?php } ?>
<?php if(get_cbamo($invno)>0){?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Cash Back</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_cbamo($invno),''); ?></td>
</tr>    
<?php } ?>    
<?php if($rowadd['less']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Amount Less</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['less'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Gross Total</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['total'],''); ?></td>
</tr>
<?php if($rowadd['adamo']>0){ ?>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Advance Adjust</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal($rowadd['adamo'],''); ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2" class="text-md-center"><?php if(($rowadd['changes'])>0){echo '<strong>Pay: '.numtolocal($rowadd['rawcash'],'').', Return: '.numtolocal($rowadd['changes'],'').'</strong>';}?></td>
<td colspan="2" class="text-md-right font-weight-bold">Paid Amount</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(get_invcash($invno,'S','Y'),''); ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2" class="text-md-right font-weight-bold">Outstanding</td>
<td colspan="2" class="text-md-right font-weight-bold text-nowrap"><?php echo numtolocal(($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo'])),''); ?></td>
</tr>
</tbody>
</table>
<!-- AMOUNT IN WORDS -->
<p>
<b>Amount in words: 
</b>
<span style="text-transform: uppercase;">
<?php echo numtoword(ABS($rowadd['total'])).'';?>		
<?php echo '<b>'.get_fild_data('tbl_currency','1','name').'</b> Only'; ?>
</span>
</p>
<?php
$did=$rowadd['type'].$rowadd['cusid'];                                                 
$ldebit=get_ledgerval($did,'D','O',$rowadd['apdate']);
$lcredit=get_ledgerval($did,'C','O',$rowadd['apdate']);
if($rowadd['cusid']!=0){
$lnet=($ldebit-$lcredit);    
}else{
$lnet=0;    
}
$outst=($rowadd['total']-(get_invcash($invno,'S','Y')+$rowadd['adamo']));
if($lnet>0){
$fdue=($lnet+$outst);     
}else{
$fdue=$outst;     
}
   
if(get_fild_data('tbl_setting','5','sval')==0){
if($lnet>0){    
?>
<div class="row">
<div class="col-xs-5">    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="text-center" colspan="2">Previous Balance</th>   
</tr>    
</thead>
<tbody>
<tr>
<td>Previous Due</td>
<td class="text-md-right"><?php if($lnet>0){echo numtolocal($lnet,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td>Invoice Due</td>
<td class="text-md-right"><?php if($outst>0){echo numtolocal($outst,'');}else{echo numtolocal(0,'');}?></td>    
</tr>
<tr>
<td><strong>Total Due</strong></td>
<td class="text-md-right"><strong><?php if($fdue>0){echo numtolocal($fdue,'');}else{echo numtolocal(0,'');}?></strong></td>    
</tr>    
</tbody>
</table>
</div>
</div>    
<?php }} ?>     
</div>    
</div>
<?php if(get_fild_data('tbl_setting','7','sval')==0){?>    
<div class="col-xs-12 inv"><strong>Terms &amp; Conditions</strong>
<?php echo get_fild_data('tbl_setting','6','sval'); ?>
</div>
<?php } ?>    
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
</div>
</div>    
    
<div class="wrapper" style="background: none;">    
<div id="wrap_invoice" class="page A4 portrait">
<div class="invoice_header etat_header">
<div class="row model1">
<div style="margin-top:3.81cm;">&nbsp;</div>
</div>
<hr>
<div class="clearfix"></div>
</div>
<center>
<h3 class="page-title">DELIVERY CHALLAN</h3>
</center>
<div class="etat_content">
<div class="page_split">
<hr>
<div class="row-cols row">
<div class="col-3 col-xs-3">
<h4>Customer</h4>    
<?php if($rowadd['type']=='CU'){if($rowadd['cusid']!=0){echo get_csinfogen($rowadd['cusid'],'tbl_customer');}else{echo get_walkcus($invid,'tbl_sales');}}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Address</h4>
<?php if($rowadd['type']=='CU'){echo get_csinfogen($rowadd['cusid'],'tbl_customer','address');}else{echo get_csinfogen($rowadd['cusid'],'tbl_supplier','address');}?>    
</div>
<div class="col-3 col-xs-3">
<h4>Attention</h4>
<?php echo tender_address('tbl_sales',$invid); ?>    
</div>    
<div class="col-3 col-xs-3 text-invright">
<?php echo "<img src = '../inc/barcode.php?text=".$rowadd['invno']."&codetype=code128&orientation=horizontal&size=30&print=false' style='margin-right: -10px;padding-bottom: 5px;'/>"; ?>
<?php echo "<br><strong>Invoice N°:</strong> ".$rowadd['invno'];?>
<?php if(strlen($rowadd['refinv'])>1){?>
<?php echo "<br><strong>Ref N°:</strong> ".strtoupper($rowadd['refinv']);?>    
<?php } ?>
<?php if (strlen($rowadd['ref'])>1){ ?>
<?php echo "<br><strong>ORD. N°:</strong> ".$rowadd['ref'];?>    
<?php } ?>    
<?php echo "<br><strong>Date:</strong> ".date("d M Y", strtotime($rowadd['apdate']));?>
</div>   
<div class="clearfix"></div>
</div>
<br>
    
<table class="table_invoice table_invoice-condensed table_invoice-bordered table_invoice-striped" style="margin-bottom: 5px;" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th style="width:5% !important;">N°</th>
<th style="width:85% !important;">Description(Code)</th>
<th style="width:10% !important;">Qty</th>
</tr>
</thead>
<tbody>
<?php
$s=0;                           
$rspan=0;
$tqty=0;   
$sql="SELECT tbl_traproduct.pid,tbl_traproduct.colid,tbl_traproduct.sizid,tbl_traproduct.p_out AS qty,tbl_item.name,tbl_item.description AS details,tbl_item.brid AS brnid,tbl_item.couid FROM tbl_traproduct LEFT JOIN tbl_item ON tbl_item.id=tbl_traproduct.pid WHERE invno='".$rowadd['invno']."'";
$querys=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($rows=mysqli_fetch_array($querys)){   
$name='';
$name=$rows['name'];
if($rows['colid']!='0'){$name.=' - '.get_fild_data('tbl_color',$rows['colid'],'name');}
if($rows['sizid']!='0'){$name.=' - '.get_fild_data('tbl_size',$rows['sizid'],'sval');}
$brco='';    
if($rows['brnid']!=''){$brco = 'Brand: '.get_fild_data('tbl_brand',$rows['brnid'],'name');}
if($rows['couid']!=''){if(strlen($brco)>3){$brco.=', Origin: '.get_fild_data('tbl_country',$rows['couid'],'name');}else{$brco='Orgin: '.get_fild_data('tbl_country',$rows['couid'],'name');}}    
$tqty+=$rows['qty'];
$s+=1;    
?>
<tr>
<td class="text-md-center"><?php echo $s; ?></td>
<td class="text-md-left">
<?php echo $name; ?>
<?php if(get_fild_data('tbl_setting','10','sval')==0){?>    
<?php if($brco!=''){echo '<br>'.$brco;} ?>
<?php } ?>     
<?php if($rows['details']!=''){echo '<br>'.$rows['details'];} ?>    
</td>
<td class="text-md-center"><?php echo $rows['qty']; ?></td>
</tr>    
<?php } ?>			
<tr>
<td colspan="2" class="text-md-center">-Total Quantity-</td>
<td class="text-md-center font-weight-bold"><?php echo $tqty; ?></td>
</tr>
</tbody>
</table>   
</div>    
</div>
<div style="clear: both;"></div>
<div class="etat_footer">
<div class="row">
<div class="col-xs-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Customer Singnature</p>
</div>    
<div class="col-xs-4 col-xs-offset-4">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="border-bottom: 1px solid #666;">&nbsp;</p>
<p class="text-md-center">Authorized Singnature</p>
</div>
</div>
<p>&nbsp;</p>
<div style="clear: both;"></div>
</div>
</div>
</div>    
<?php } ?>    
</div>    
