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; }