prepare("SELECT t.StoreName, o.CartKey, o.ProductName, o.NAME, o.NUMBER, o.Size, o.JerseySize, o.ShortsSize, o.Price, o.Quantity, (o.Price * o.Quantity) AS TotalPrice, ((o.Price * o.Quantity) * 0.10) AS Tax, o.DateCreated, pd.InvoiceNumber, pd.Payer_Email FROM orders AS o INNER JOIN payment_details AS pd ON pd.CartKey = o.CartKey INNER JOIN teamstores AS t ON t.Id = o.StoreId WHERE o.DateCreated BETWEEN '$dateToday 00:00:00' AND '$dateToday 23:59:00' ORDER BY o.DateCreated"); $q->execute(); $result = $q->rowCount(); if($result > 0){ $invoice_array = array(); $filename = 'daily_order_report_'.$dateToday.'.csv'; $headers = array('StoreName', 'ProductName', 'NAME', 'NUMBER', 'Size', 'JerseySize', 'ShortsSize', 'Price', 'Quantity', 'TotalPrice', 'Tax', 'DateCreated', 'InvoiceNumber', 'Payer_Email'); $fp = fopen('daily_order_reports/'.$filename, 'w'); fputcsv($fp, $headers); while ($row = $q->fetch()) { $value = $row['CartKey'] . "|" . $row['InvoiceNumber']; if(!in_array($value, $invoice_array, true)){ array_push($invoice_array, $value); } $lineData = array($row['StoreName'], $row['ProductName'], $row['NAME'], $row['NUMBER'], $row['Size'], $row['JerseySize'], $row['ShortsSize'], $row['Price'], $row['Quantity'], $row['TotalPrice'], $row['Tax'], $row['DateCreated'], $row['InvoiceNumber'], $row['Payer_Email']); fputcsv($fp, $lineData); } $report_link = "https://www.crewsportswear.com/email_reports/daily_reports_with_image.php?d=". $dateToday; $body = ""; $body .= "
"; $body .= "Please download the attached file for today's order report.
"; $body .= "For the order report with image please click here.
"; $body .= "####################################
"; $body .= "Order Details per Invoice
"; foreach($invoice_array as $invoice){ $v = explode("|", $invoice); $body .= "