<?php

ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');



$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);



$getpmain = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS mydt FROM `pursacn` WHERE purvouch = 0 group by vouchno ")or die(mysqli_error($conn));
$get = mysqli_num_rows($getpmain);

$contents.="Sr.,Voucher,Date,Barcode,Product,Amount\n";


$ctr = 0;
while ($pmain = mysqli_fetch_array($getpmain)) {


    $ctr++;
    $vouchno = $pmain[vouchno];
    $mydt = $pmain[mydt];
    $barcode = $pmain[barcode];
    $prodtype = $pmain[prodtype];
    $amount = $pmain[amount];

    
    if($prodtype  == 'O'){
        $product = "Textile";
    }else{
        $product = 'Perfume';
    }
    
    
    $contents.=$ctr . ",";
    $contents.=$vouchno . ",";
    $contents.=$mydt . ",";
    $contents.=$barcode . ",";
    $contents.=$product  . ",";
    $contents.=$amount . "\n";

}

    $contents = strip_tags($contents);

    header("Content-Disposition: attachment; filename=salevouch" . date('d-m-Y') . ".csv");

    print $contents;

?>