function exportCSV($artistid)
{
    global $tableprefix;
    $adminCurrency = GetAdminCurrency();
    $currencycode = getSellerCurrencySybol($artistid);
    $currencySymbol = getCurrencySybol($currencycode);
    $csv = new CSV(array('Order #', 'Order Total', 'Commission (%)', 'Total Tax Amount', 'Total Shipping Amount', 'Product Total Amount', 'Amount Received [ Product Total Amount - Admin Commision  + Product Shipping + Tax ]', 'Date Paid(mm/dd/yyyy)', 'Payment Status'), ";");
    $qryopt = "";
    $qrybtw = "";
    $sql = " SELECT sp.*,s.artist_name FROM " . $tableprefix . "artist_payments sp\n\t\tINNER JOIN  " . $tableprefix . "artists s ON sp.artist_id = s.artist_id\n                INNER JOIN  " . $tableprefix . "orders o ON o.order_id = sp.order_id" . $qryopt . "\n\t\tWHERE sp.artist_id = '" . addslashes($artistid) . "' AND o.vpayment_status='C'" . $qrybtw . "order by sp.artist_payment_id DESC   ";
    $rs = mysql_query($sql) or die("qqqq" . mysql_error());
    $result = mysql_query($sql) or die("www" . mysql_error());
    if (mysql_num_rows($result) > 0) {
        $i = 1;
        $total = 0;
        while ($row = mysql_fetch_array($rs)) {
            $txtPaymentDate = isNotNull($row["payment_date"] and $row["payment_date"] != "0000-00-00") ? dateFormat($row["payment_date"], "Y-m-d", "m/d/Y") : " Not Yet Settled;";
            if ($row['payment_status'] == 'P') {
                $Paymentstatus = 'Pending';
            } else {
                $Paymentstatus = 'Paid';
            }
            $qryopt1 = " ";
            $taxtotal = 0;
            $sql1 = "SELECT o.*, u.user_name, u.email, od.product_discount,sum( (od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as total,sum(od.product_tax)as taxtotal\n\t\tFROM " . $tableprefix . "orders o\n\t\tINNER JOIN " . $tableprefix . "users u ON o.user_id = u.user_id\n\t\tINNER JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id\n\t\tWHERE od.artist_id = '" . $artistid . "'\n                AND o.order_id = " . $row['order_id'] . "\n\t\tAND o.vpayment_status != 'P'" . $qryopt1 . " GROUP BY o.order_id ORDER BY o.order_date,o.order_id DESC ";
            $sellerCurrency = getSellerCurrencySybol($artistid);
            $result1 = mysql_query($sql1);
            if (mysql_num_rows($result1) != 0) {
                $row1 = mysql_fetch_array($result1);
                $ordernumber = $row1["order_id"];
                $username = $row1["user_name"];
                if ($row1['vorder_currency'] != $sellerCurrency and $row1['vorder_currency'] != "USD") {
                    $get_conversion_price = getCurrencyrate($sellerCurrency);
                    $ordertotal = $row1["total"];
                } else {
                    $ordertotal = $row1["total"];
                }
                $taxtotal = $row1["taxtotal"];
            }
            $select_shipping_cost = "SELECT sd.vshipping_name, sd.nshipping_cost,od.product_name\n                           FROM " . $tableprefix . "shipping_details sd," . $tableprefix . "order_details  od\n                          WHERE od.product_id=sd.nshp_productid\n                            AND norder_id = " . $row['order_id'] . "\n                            AND nshp_status = 'C'\n                            AND od.artist_id = '" . $artistid . "'\n                       GROUP BY sd.nshp_productid order by  od.product_name";
            $result_shipping_cost = mysql_query($select_shipping_cost);
            if (mysql_num_rows($result_shipping_cost) > 0) {
                $totalshippingcost = 0;
                while ($shipping_row = mysql_fetch_array($result_shipping_cost)) {
                    $totalshippingcost += $shipping_row['nshipping_cost'];
                }
            }
            $csv->addRow(array($row["order_id"], html_entity_decode($adminCurrency['currency_symbol']) . " " . number_format($row["seller_order_total_amount"], 2, '.', ''), $row["commission_percentage"], html_entity_decode($adminCurrency['currency_symbol']) . " " . number_format($taxtotal, 2, '.', ''), html_entity_decode($adminCurrency['currency_symbol']) . " " . number_format($totalshippingcost, 2, '.', ''), html_entity_decode($adminCurrency['currency_symbol']) . " " . number_format($row["total_amount"], 2, '.', ''), html_entity_decode($adminCurrency['currency_symbol']) . " " . number_format($row["amount_paid"], 2, '.', ''), $txtPaymentDate, $Paymentstatus));
            $artistName = $row["artist_name"];
            $i++;
            $total += $row["amount_paid"];
        }
        if ($total > 0) {
            $csv->addRow(array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '));
            $csv->addRow(array(' ', ' ', ' ', ' ', ' ', ' ', 'Total Seller Amount Received', html_entity_decode($currencySymbol) . " " . number_format($total, 2, '.', ''), ' '));
        }
    }
    // export csv as a download
    $filename = 'order_payment_details_' . $artistName;
    //$filename = 'order_payment_details'.$artistid;
    $csv->export($filename);
    // *or* pass the csv data to a variable as a string
    //$string = $csv;
}
		INNER JOIN ".$tableprefix."shipping_details sd ON sd.norder_id = od.order_id
		WHERE od.artist_id = '".addslashes($artistid)."' 
		 AND o.vorder_currency = cm.vcurrency_code
		 AND o.order_id = '".addslashes($orderid)."'
		" . $qryopt . "GROUP BY o.order_id ORDER BY o.order_date DESC";*/
$taxtotal = 0;
$sql = "SELECT o.*, u.user_name, u.email, od.product_discount,sum( (od.product_price-(od.product_price*product_discount/100)) * od.product_quantity) as total,sum(od.product_tax)as taxtotal\n\t\tFROM " . $tableprefix . "orders o\n\t\tINNER JOIN " . $tableprefix . "users u ON o.user_id = u.user_id\n\t\tINNER JOIN " . $tableprefix . "order_details od ON o.order_id = od.order_id\n\t\tWHERE od.artist_id = '" . addslashes($artistid) . "'\n                AND o.order_id = '" . addslashes($orderid) . "'\n\t\tAND o.vpayment_status != 'P'" . $qryopt1 . " GROUP BY o.order_id ORDER BY o.order_date,o.order_id DESC ";
//exit;
//echo $sql;
$result = mysql_query($sql);
if (mysql_num_rows($result) != 0) {
    $row = mysql_fetch_array($result);
    $ordernumber = $row["order_id"];
    $username = $row["user_name"];
    if ($row['vorder_currency'] != $sellerCurrency and $row['vorder_currency'] != "USD") {
        $get_conversion_price = getCurrencyrate($sellerCurrency);
        $ordertotal = $row["total"];
    } else {
        $ordertotal = $row["total"];
    }
    $taxtotal = $row["taxtotal"];
    //$ordertotal+=$row["taxrate"];
    $orderstatus = getArtistOrderStatus($orderid, $artistid);
    $orderdate = $row["order_date"];
    $orderdate = dateFormat($orderdate, "Y-m-d", "m/d/Y");
    $userid = $row["user_id"];
}
//$statlist= getStatusList();
$statlist = array();
if ($orderstatus == "Cancelled") {
    $statlist[2] = "Cancelled";
                if (!empty($_SESSION["SHIPPING_DETAILS"])) {
                    $product_price = $product_price + $_SESSION["SHIPPING_DETAILS"][$product_option_id]['rate'];
                }
                $taxrate = $product_price * ($taxpercentage / 100);
            }
        }
        if ($enable_tax == "2") {
            $taxrate = $product_price * ($taxpercentage / 100);
        }
    }
    $_SESSION["TAX_DETAILS"][$product_option_id] = number_format($taxrate, 2, ".", "");
    $_SESSION["TAX_TOTAL"] += $_SESSION["TAX_DETAILS"][$product_option_id];
}
// End Tax
//=========================If rate per state is not activated and default rate is activated
$exchangeRate = getCurrencyrate($currency_attributes[2]);
//===========================================
if ($_SESSION["TAX_TOTAL"] != 0) {
    // if tax rate is not null include tax rate
    $taxrates = $_SESSION["TAX_TOTAL"];
}
$_SESSION['session_taxrate'] = $taxrates;
// if Gift Certificate Order placed
if (checkGiftProductsExistsinCart($userid)) {
    $_SESSION['session_taxrate'] = '';
    $_SESSION['SHIPPING_TOTAL'] = '';
    cartClearDigital($userid);
}
//===============================End Tax Calulation===================================
/*function call to fetch details from site settings*/
//echo "hi".$_SESSION['SESS_digital_product'];exit;