
PK 
<?php
include("connexion.php");
function getColumn($table, $field, $val, $col, $orderby=""){
if($orderby!=""){
$or=" order by ".$orderby;
}
$q="select $col from $table where $field='$val' $or";
$q=mysql_query($q) or die(mysql_error());
if($r=mysql_fetch_array($q)){
return $r[0];
}else{
return false;
}
}
$csv_output="";
$sql = "SELECT * From invoices where dtd >= '$_GET[sdt]' and dtd <= '$_GET[edt]' order by dtd asc";
$result = mysql_query($sql) or die(mysql_error().' - error in invoiceno');
if (mysql_num_rows($result) == 0) {
$csv_output .= "No Result found in Invoices.";
}else{
$csv_output .= "GSTIN, Invoice No, Invoice Date, Invoice Value, State, Reverse Charge, Invoice Type, E-Commerce GSTIN, Rate, Taxable Value";
$csv_output .= "\n";
while ($row = mysql_fetch_array($result)) {
$round = round($row['grandtotal'] - $row['amount']);
$clnid=explode(",", $row[clnid]);
$gst=getColumn("head", "headid", $clnid[0], "gst");
$csv_output .= $gst.", ";
$csv_output .= $row['invid'].", ";
$csv_output .= date("d-m-Y", strtotime($row['dtd'])).", ";
$csv_output .= $row['amount']+$row['servicetax'].", ";
$csv_output .= "03".", ";
$csv_output .= "NIL".", ";
$csv_output .= "REGULAR".", ";
$csv_output .= "NA".", ";
$csv_output .= "18%".", ";
$csv_output .= $row['amount'].", ";
$csv_output .= "\n";
}
}
$filename = "INV_".date("d-m-Y_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
//$csv_output=str_replace("\n","<br>",$csv_output);
print $csv_output;
?>


PK 99