0){ $date = date('d-m-Y'); $artist = Admin::getArtistDetailByCode($artist_code); $mechanical_share = $artist['mechanical_share']; $royalty_share = $artist['royalty_share']; $artist_name = $artist['artist_name']; if($month>0)$file_name =$artist_code."_SaleRecords_".$month."-".$year; else $file_name =$artist_code."_SaleRecords_".$year; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=".$file_name.".xls"); header("Content-Transfer-Encoding: binary "); xlsBOF(); /* Make a top line on your excel sheet at line 1 (starting at 0). The first number is the row number and the second number is the column, both are start at '0' */ $months= array(1=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun', 7=>'Jul',8=>'Aug',9=>'Sep',10=>'Dec',11=>'Nov',12=>'Dec'); if($month>0)$m = $months[$month]; else $m=""; $title ="$artist_name Sale Records of $m $year - Export on ".$date; xlsWriteLabel(0,0,$title); // Make column labels. (at line 3) xlsWriteLabel(2,0,"Track Name"); xlsWriteLabel(2,1,"Artist"); xlsWriteLabel(2,2,"Album"); xlsWriteLabel(2,3,"ISRC"); xlsWriteLabel(2,4,"UPC"); xlsWriteLabel(2,5,"Vendor"); xlsWriteLabel(2,6,"Price"); xlsWriteLabel(2,7,"Quantity"); xlsWriteLabel(2,8,"Mechanical"); xlsWriteLabel(2,9,"Royalty"); xlsWriteLabel(2,10,"Date"); $xlsRow = 3; // Get data records from table. if($month >0) $month_cond = "f.report_month=$month"; else $month_cond="TRUE"; if($artist_code==$general_artist_code) { $query = "SELECT r.artist_alias,r.track_name,r.album_name,r.isrc,r.upc,r.vendor_name,r.unit_price,r.quantity,r.mechanical,(CASE WHEN r.album_name LIKE '%Various%' OR r.album_name LIKE '%Compilation%' OR r.album_name LIKE '%Vol%' THEN (r.royalty+(r.royalty/2)) ELSE (r.royalty) END) AS royalty,f.report_month,f.report_year FROM report r,report_file f WHERE r.file_id = f.id AND f.report_year='$year' AND $month_cond AND r.artist_code='$artist_code' ORDER BY report_year DESC,report_month DESC,track_name ASC"; } else { $query = "SELECT r.artist_alias,r.track_name,r.album_name,r.isrc,r.upc,r.vendor_name,r.unit_price,r.quantity,r.mechanical,(CASE WHEN r.album_name LIKE '%Various%' OR r.album_name LIKE '%Compilation%' OR r.album_name LIKE '%Vol%' THEN (r.royalty/2) ELSE (r.royalty) END) AS royalty,f.report_month,f.report_year FROM report r,report_file f WHERE r.file_id = f.id AND f.report_year='$year' AND $month_cond AND r.artist_code='$artist_code' ORDER BY report_year DESC,report_month DESC,track_name ASC"; } $result=mysqli_query($connect,$query); // Put data records from mysql by while loop. while($row=mysqli_fetch_array($result)){ $share_mechanical = ($row['mechanical'] * $mechanical_share/100); $share_royalty = ($row['royalty'] * $royalty_share/100) + $share_mechanical; xlsWriteLabel($xlsRow,0,$row['track_name']); xlsWriteLabel($xlsRow,1,$row['artist_alias']); xlsWriteLabel($xlsRow,2,$row['album_name']); xlsWriteLabel($xlsRow,3,$row['isrc']); xlsWriteLabel($xlsRow,4,$row['upc']); xlsWriteLabel($xlsRow,5,$row['vendor_name']); xlsWriteNumber($xlsRow,6,$row['unit_price']); xlsWriteNumber($xlsRow,7,$row['quantity']); xlsWriteNumber($xlsRow,8,$share_mechanical); xlsWriteNumber($xlsRow,9,$share_royalty); xlsWriteLabel($xlsRow,10,$row['report_month'].'/'.$row['report_year']); $xlsRow++; } xlsEOF(); exit(); } ?>