0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { $orgName = $row["org_name"]; } } else { echo "0 results"; } #======================================= Build the Page Header $tblPageHeader = <<
Details Full Year Projected Black Volume and Cost 50% Pre-Billing Black Volume and Cost Full Year Projected Color Volume and Cost 50% Pre-Billing Color Volume and Cost TOTAL Pre-Bill
Volume and Cost
HTML; #======================================= Star PDF # create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); # set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Robert Dutil'); $pdf->SetTitle('Prebill'); $pdf->SetSubject('Pre-Billing'); $pdf->SetKeywords('PDF'); # set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE,'', PDF_HEADER_STRING); #PDF_HEADER_TITLE # # set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); # set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); # set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); # set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); # set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); # add a page $pdf->AddPage('L'); # Set the Title font. $pdf->SetFont('helvetica', 'B', 18); # Title Name of Organization. $pdf->Write(0, $orgName, '', 0, 'C', true, 0, false, false, 0); # $img = file_get_contents('https:# www.spcstardoc.com/dmstest10/images/spcHeader.png'); # $pdf->Image('@' . $img); # Set the font for the for the data. # set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } $sql=("SELECT bd.building_id_ma AS buildingId , b.building_name , bd.room_name , concat(Make,'', model) AS MakeModel , bd.serial_number , bd.vendor_mach_id , bd.projected_volume_black , bd.billed_projected_volume_black , bd.projected_volume_black*bd.cpc_black AS 'Projected Full Year Cost' , bd.cpc_black , bd.client_black_charge , bd.projected_volume_color , bd.billed_projected_volume_color , bd.cpc_color , bd.client_color_charge , o.org_name FROM ((billing_data bd INNER JOIN organization o ON bd.org_id_ma = o.id) INNER JOIN buildings b ON bd.building_id_ma = b.id) INNER JOIN machines m ON bd.model_id = m.id ORDER BY bd.building_id_ma"); # Set the variables. $bName = null; # Total Black and Color Volumes $TotalBlackVol = 0; $TotalPBBlackVol = 0; $TotalColorVol = 0; $TotalPBColorVol = 0; $TotalPBVolume = 0; # Total Black and Color Cost $TotalBlackCost = 0; $TotalPBBlackCost = 0; $TotalColorCost = 0; $TotalPBColorCost = 0; $TPBCost = 0; $countRows = 0; # $countRows = mysqli_num_rows(); # for($x = 0; $x <= $countRows/5; $x++){ ##======================================= Print Page Header Here $pdf->SetFont('helvetica', '', 10); # $CountPg = 0; # $CountPg = $pdf->$getNumPages(); # for($x = 0; $x <= $CountPg; $x++){ $pdf->writeHTML($tblPageHeader, false, true, false, false, ''); # } #======================================= End Page Header # #======================================= Loop through data #Query results. $result= $dbc->query($sql); # Fetch the data and assign and format to variables while($row = $result->fetch_assoc()) { $orgName = $row['org_name']; $buildingName = $row['building_name']; $room = $row['room_name']; $makeModel = $row['MakeModel']; $serialNum = $row['serial_number']; $vendorMa = $row['vendor_mach_id']; # Volume $projBlkVol = number_format($row['projected_volume_black']); $billProjBlkVol = number_format($row['billed_projected_volume_black']); $projColVol = number_format($row['projected_volume_color']); $billProjColVol = number_format($row['billed_projected_volume_color']); $totalBillVol = number_format($row['billed_projected_volume_black']+$row['billed_projected_volume_color']); # Cost $projFYBlkCost = '$'.number_format($row['client_black_charge'],2); $billBlkCost = '$'.number_format($row['billed_projected_volume_black']*$row['cpc_black'],2); $projFYColorCost = '$'.number_format($row['client_color_charge'],2); $billColorCost = '$'.number_format($row['billed_projected_volume_color']*$row['cpc_color'],2); $totalBillCost = '$'.number_format(($row['billed_projected_volume_black']*$row['cpc_black'])+($row['billed_projected_volume_color']*$row['cpc_color']),2); # cpc $cpcBlk = $row['cpc_black']; $cpcColor = $row['cpc_color']; # Sub Total # First row Total Volumes for Building Footer. $TotalBlackVol = number_format($TotalBlackVol + $projBlkVol); $TotalPBBlackVol = number_format($TotalPBBlackVol + $billProjBlkVol); $TotalColorVol = number_format($TotalColorVol + $projColVol); $TotalPBColorVol = number_format($TotalPBColorVol + $billProjColVol); $TotalVolumes = number_format($TotalPBBlackVol + $TotalPBColorVol); # Second row Total Cost for Building Footer. $TotalBlackCost = '$'.number_format($TotalBlackCost + $projFYBlkCost); $TotalPBBlackCost = '$'.number_format($TotalPBBlackCost + $billBlkCost); $TotalColorCost = '$'.number_format($TotalColorCost + $projFYColorCost); $TotalPBColorCost = '$'.number_format($TotalPBColorCost + $billColorCost); $TPBCost = '$'.number_format($TotalPBBlackCost + $TotalPBColorCost); #======================================= Print the Page Header # Start the loop and set up variables for the HTML. If($result->num_rows > 0){ #======================================= Print Group Building Name if( $buildingName != $bName ){ $tblBldgNameHeader = <<
$buildingName
HTML; $pdf->writeHTML($tblBldgNameHeader, false, true, false, false, ''); $bName = $buildingName; } #======================================= Machine Data # Step 3: If the building name equals the variable $bName then start filling in each machine for this building. if( $buildingName == $bName ){ # Set the font for the for the data. $pdf->SetFont('helvetica', '', 10); $tblMachineData = << $buildingName $projBlkVol $billProjBlkVol $projColVol $billProjColVol $totalBillVol $room - $makeModel $projFYBlkCost $billBlkCost $projFYColorCost $billColorCost $totalBillCost $serialNum - $vendorMa $cpcBlk $cpcColor HTML; $pdf->writeHTML($tblMachineData, true, true, false, false, ''); $bName = $buildingName; } # Step 4: If the building name does not equal the variable $bName then print the footer totals for this building. if($bName != $buildingName){ $tblFooter = << Sub Total: $bName $TotalBlackVol
$TotalBlackCost $TotalPBBlackVol
$TotalPBBlackCost $TotalColorVol
$TotalColorCost $TotalPBColorVol
$TotalPBColorCost $TotalVolumes
$TPBCost HTML; $pdf->writeHTML($tblFooter, false, true, false, false, ''); $bName = $buildingName; # Reset to zero after each building loop. $TotalBlackVol = 0; # Total Projected full year volume for the building. $TotalPBBlackVol = 0; # Total Pre-Bill Black Volume. $TotalColorVol = 0; # Total Full Year black cost. $TotalPBColorVol = 0; # Total Pre Bill cost for the building $TotalVolumes = 0; # Total Black and Color Volumes. # Total Black and Color Cost $TotalBlackCost = 0; $TotalPBBlackCost = 0; $TotalColorCost = 0; $TotalPBColorCost = 0; $TPBCost = 0; } } } mysqli_close($dbc); # Close and output PDF document ob_end_clean(); $pdf->Output('prebillTest.pdf', 'I');