<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/cartfunctions.php');
include ('../inc/repfunctions.php');
include ('../inc/invfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
$today = strftime("%Y-%m-%d", time());    
$dtnow = date("Y-m-d h:i:s", time());    
}else{
header('Location:../index.php');
exit;    
}
if(isset($_POST['salesinvexpcsv'])){
    $fdate=$_POST['fdate'];
    $tdate=$_POST['tdate'];
    $output='';
    $sql="SELECT id,invno,type,cusid,name,subtot,totdis,vatamo,aitamo,otamo,freight,less,total,ref,apdate FROM tbl_sales WHERE apdate BETWEEN '$fdate' AND '$tdate' ORDER BY apdate,id ASC";
    $result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $output.='<tr><th>SN</th><th>Date</th><th>Invoice</th><th>Vendor</th><th>DIS</th><th>VAT</th><th>AIT</th><th>OTH</th><th>FRE</th><th>LES</th><th>Total</th></tr>';
    while($row = mysqli_fetch_array($result) ){
        if($row['type']!='CU'){ $name=get_fild_data('tbl_supplier',$row['cusid'],'name');}else{if($row['cusid']!='0'){  $name=get_fild_data('tbl_customer',$row['cusid'],'name');}else{ $name=$row['name'];}}
    $output.='<tr><td>'.count_id().'</td><td>'.date("d M Y", strtotime($row['apdate'])).'</td><td>'.$row['invno'].'</td><td>'.$name.'</td><td>'.numtolocal($row['totdis'],'').'</td><td>'.numtolocal($row['vatamo'],'').'</td><td>'.numtolocal($row['aitamo'],'').'</td><td>'.numtolocal($row['otamo'],'').'</td><td>'.numtolocal($row['freight'],'').'</td><td>'.numtolocal($row['less'],'').'</td><td>'.numtolocal($row['total'],'').'</td></tr>';	
    }
    // encoding array to json format
    echo $output;
    }


?>