setHeaderMargin(50);
#Example Quarterly or Semi-Annual
$billing_cycle = '';
$topLine = '';
$recordId = $_GET['id'];/*This is the billing_id */
$grpBy = $_GET['sortBy'];/* This will be either Department or Building */
$schoolYear = '';#This will come from the billing_data table based on the billing_id
$billing_type = $_GET['billing_type']; /* This will be Client or Vendor */
$addCoverLetter = 'N';
$thisVendor = 0;
if(isset($_GET['vend'])){
$thisVendor = $_GET['vend']; /* This will be the vendor running the report IF the billing_type = Vendor */
$addCoverLetter = 'N';
}
$ttl = 'Summary by ' . $grpBy;
$hdrTitle = '';
/*******************************BEGIN MULTI USE ARRAYS******************************/
/* These 2 arrays will be used for the Total Pre-Billing Invoice footer on Summary by Building and Summary by Vendor pages. */
$formatArrayInvF = array("col_0"=>'style="margin-top:0px; margin-bottom:0px; padding:1px;"',
"col_1"=>'style="background-color:rgb(205, 220, 175);"', "col_2"=>'style="background-color:rgb(205, 220, 175);"',
"col_3"=>'style="background-color:rgb(205, 220, 175);"', "col_4"=>'style="background-color:rgb(205, 220, 175);"');
$rowStyleInvF = 'style="font-size:15px; font-weight:bold;"';
/* These 2 arrays will be used for the Black Prints Totals and Color Prints Totals Footers */
$formatArrayTotalsF = array("col_0"=>'style="border-bottom:1px solid black; text-align:right;"',
"col_1"=>'style="border-bottom:1px solid black; text-align:right;"',
"col_2"=>'style="border-bottom:1px solid black; text-align:right;"',
"col_3"=>'style="border-bottom:1px solid black; text-align:right;"',
"col_4"=>'style="border-bottom:1px solid black; text-align:right;"');
$rowStyleTotalsF = 'style="background-color:rgb(198, 209, 222);"';
/* These 2 arrays will be used for the Black and Color Group Headers */
$formatArrayGrpHeadBk = array("col_0"=>'style="margin-top:0px; margin-bottom:0px; padding:1px; text-align:left; font-size:12px; font-weight:bold;"');
$formatArrayGrpHeadCol = array("col_0"=>'style="color:rgb(35, 114, 239); text-align:left; font-size:12px; font-weight:bold;"');
/* This array will be used for the black and color header, body, and footer for the summary by building table,
and for the invoice totals footer*/
$widthArrayTableBk = array("col_0"=>175, "col_1"=>150, "col_2"=>150, "col_3"=>150, "col_4"=>150);
/* This array will be used for the black and color header, body, and footer for the summary by vendor/model type table,
and for the invoice totals footer when the report is for a vendor.*/
$widthArrayVend = array("col_0"=>320, "col_1"=>160, "col_2"=>160, "col_3"=>160, "col_4"=>160);
/* This array will be used for the black and color header and body for the summary by vendor/model type table,
but NOT the footer or the invoice totals footer. These footers have a larger first column to compensate
for the extra column (model type) that is in the body, but not in the footer.*/
$widthArrayClient = array("col_0"=>240, "col_1"=>"200", "col_2"=>"130", "col_3"=>"130", "col_4"=>"130", "col_5"=>"130");
/* This array will be used for the black and color totals footer and the invoice totals footer
for the summary by vendor/model type table. These footers have a larger first column to compensate
for the extra column (model type) that is in the body, but not in the footer.*/
$widthArrayClient2 = array("col_0"=>"370", "col_1"=>"200", "col_2"=>"130", "col_3"=>"130", "col_4"=>"130");
/************************BEGIN SPACER ROW ******************/
$widthArraySpc = array("col_0"=>750);
$rowStyleSpc = 'style="font-size:5px;"';
$spacerVals = array("numOthCols"=>"0", "col_0"=>" ", "rowStyle"=>$rowStyleSpc,
"fArray"=>"", "multiCols"=>$widthArraySpc);
$spacerRow = getHtmlStr('GTMULTIW2', $spacerVals);
/************************END SPACER ROW ******************/
/*************************** END MULTI USE ARRAYS *****************************/
/**************************** CONSTRUCT PAGE TITLE **************************/
$sqlB = '';
if($billing_type === 'Vendor'){
/*If report is for a vendor, make sure the title is for the correct vendor */
$sqlB = ' AND vendOrg.id = ? ';
}
/*Query for the org_name, school year and billing type. The last 2 go in the page title and the footer */
$sql = "SELECT org.org_name, looksy.school_year, bd.billing_type, lookbill.billing_cycle_name,
tbc.`First Name` contactName, vendOrg.org_name vendor_org
FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN billing_report_todo brtd ON brtd.org_id = org.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
INNER JOIN lkp_school_year looksy ON looksy.yr_id = brtd.school_year
INNER JOIN lkp_billing_cycle lookbill ON lookbill.billing_cycle_id = bd.billing_cycle
LEFT JOIN tblContacts tbc ON tbc.org_id_contact = bd.org_id_ma AND tbc.decision_maker = 'Yes'
WHERE bd.billing_id = ? " . $sqlB . "
GROUP BY org.org_name;";
/*prepare stmt*/
$stmta = $dbLink->prepare($sql);
/*Bind the criteria param*/
if($billing_type === 'Vendor'){
$stmta->bind_param('ii', $recordId, $thisVendor);
}
else{
$stmta->bind_param('i', $recordId);
}
/*Execute the stmt*/
$stmta->execute();
/*Store result*/
$stmta->store_result();
/*Check success*/
if($stmta->num_rows > 0){
/*Bind results*/
$stmta->bind_result($orgName, $schoolYear, $billing_type, $billing_cycle, $thisContact, $thisVendorName);
while($stmta->fetch()){
if($billing_type === 'Vendor'){
$footerSuffix = ' ' . $orgName . ' / ' . $thisVendorName;
$topLine = $thisVendorName . ' for ' . $orgName;
}
else{
$footerSuffix = ' ' . $orgName . ' ';
$topLine = $orgName;
}
/* Concat the string for the left side of the page footer */
$footerInformation = $schoolYear . ' / ' . $billing_cycle . ' / ' . $footerSuffix;
}#end while
}#end if num_rows
else {
$pdf->Write(0, 'There were no records returned for these criteria.', '', 0, 'C', true, 0, false, false, 0);
}#end else num_rows
/****************************BEGIN COVER LETTER ****************************/
$pdf->SetPrintFooter(false);
if($addCoverLetter === 'Y'){
#The page following the cover letter should be page 1, so set this page to 0.
$pdf->setStartingPageNumber(0);
# set image scale factor. This is needed for all table columns to be shown.
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->addNoFooterHeaderPg('P');
$pdf->Image('images/spc_logo.png', 4, 2, 43, 24, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false);
# SJH 6/30/2020 - changed param 3, the vertical position, from 235 to 175 because the letter body was shortened.
$pdf->Image('images/skip.png', 48, 175, 50, 30, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false);
$coverLetter = getCoverPg($thisContact);
$coverLetterPage = <<writeHTML($coverLetterPage, false, true, false, false, '');
}#end if $addCoverLetter = 'Y'
$pdf->setImageScale(1.00);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->startPage('L');
/******************************END COVER LETTER **************************/
/************************* BEGIN LOGO HEADER *****************************/
$pdf->Image('images/mst_Header.png', 0, 0, 300, 15, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false);
/************************* END LOGO HEADER ******************************/
/*************************BEGIN PAGE HEADER********************************/
$formatArray = array("col_0"=>'style="text-align:center; margin-top:0px; padding-top:0px; font-size:12px; font-weight:bold;"');
$rowStyle = '';
$widthArray = array("col_0"=>800);
$phVals = array("numOthCols"=>"0", "col_0"=>$topLine . "
" . $schoolYear . " / " . $billing_cycle . "
" .
$ttl, "rowStyle"=>$rowStyle, "fArray"=>$formatArray, "multiCols"=>$widthArray);
$pgHeader = getHtmlStr('GTMULTIW2', $phVals);
$pageHeader = <<writeHTML($pageHeader, true, true, false, false, '');
/************************ END PAGE HEADER *******************************/
/********************** BEGIN BLACK GROUP HEADER ************************/
$headString = "Black Prints";
$gVals = array("numOthCols"=>"0", "col_0"=>$headString,
"rowStyle"=>$rowStyle, "fArray"=>$formatArrayGrpHeadBk, "multiCols"=>$widthArray);
$grpHeadBk = getHtmlStr('GTMULTIW2', $gVals);
/********************** END BLACK GROUP HEADER *********************/
/********************** BEGIN BLACK TABLE HEADER *********************/
$formatArrayHdr = array("col_0"=>'style="color:rgb(0, 0, 0); text-align:left; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_1"=>'style="color:rgb(0, 0, 0); text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_2"=>'style="color:rgb(0, 0, 0); text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_3"=>'style="color:rgb(0, 0, 0); text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_4"=>'style="color:rgb(0, 0, 0); text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"');
$rowStyle = '';
$gVals = array("numOthCols"=>"4", "col_0"=>$grpBy, "col_1"=>"Projected Volume", "col_2"=>"Projected Charges",
"col_3"=>"Pre-Billing Volume", "col_4"=>"Pre-Billing Charges",
"rowStyle"=>$rowStyle, "fArray"=>$formatArrayHdr, "multiCols"=>$widthArrayTableBk);
$blkTabHdr = getHtmlStr('GTMULTIW2', $gVals);
$groupName = <<writeHTML($groupName, true, true, false, false, '');
/********************** END BLACK TABLE HEADER *********************/
/********************** GET DATA FOR BLACK AND COLOR BEGIN *********************/
$q = ''; #Query specific to group by building or dept.
$qA = ''; #Query part that is specific to Vendor or Client
$qB = ''; #Query part that is required ONLY when billing_type = Vendor
if($billing_type === 'Vendor'){
$qA = ' SUM(bd.projected_volume_black * bd.vendor_cpc_black) proj_bk_chg,
SUM(bd.billed_projected_volume_black * bd.vendor_cpc_black) pb_bk_chg,
SUM(bd.projected_volume_color * bd.vendor_cpc_color) proj_col_chg,
SUM(bd.billed_projected_volume_color * bd.vendor_cpc_color) pb_col_chg';
/*If report is for a vendor, ONLY machines owned by that vendor should be in report */
$qB = ' AND vendOrg.id = ? ';
}
else{
$qA = ' SUM(bd.projected_volume_black * bd.cpc_black) proj_bk_chg,
SUM(bd.billed_projected_volume_black * bd.cpc_black) pb_bk_chg,
SUM(bd.projected_volume_color * bd.cpc_color) proj_col_chg,
SUM(bd.billed_projected_volume_color * bd.cpc_color) pb_col_chg';
}
if($grpBy === 'Building'){
$q = 'SELECT orgs.org_name,
bldg.building_name,
SUM(bd.projected_volume_black) proj_bk_vol,
SUM(bd.billed_projected_volume_black) pb_bk_vol,
SUM(bd.projected_volume_color) proj_col_vol,
SUM(bd.billed_projected_volume_color) pb_col_vol,' . $qA .
' FROM billing_data bd
INNER JOIN buildings bldg ON bd.building_id_ma = bldg.id
INNER JOIN organization orgs ON bd.org_id_ma = orgs.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = ? ' . $qB .
' GROUP BY bldg.building_name;';
}
else{
$q = 'SELECT orgs.org_name,
dpt.dept_name,
bd.dept_id_ma,
SUM(bd.projected_volume_black) proj_bk_vol,
SUM(bd.billed_projected_volume_black) pb_bk_vol,
SUM(bd.projected_volume_color) proj_col_vol,
SUM(bd.billed_projected_volume_color) pb_col_vol,' . $qA .
' FROM billing_data bd
INNER JOIN department dpt ON dpt.id = bd.dept_id_ma
INNER JOIN organization orgs ON bd.org_id_ma = orgs.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = ? ' . $qB .
' GROUP BY bd.dept_id_ma
ORDER BY dpt.dept_name;';
}
/*prepare stmt*/
$stmt = $dbLink->prepare($q);
/*Bind the criteria param*/
if($billing_type === 'Vendor'){
$stmt->bind_param('ii', $recordId, $thisVendor);
}
else{
$stmt->bind_param('i', $recordId);
}
/*Execute the stmt*/
$stmt->execute();
/*Store result*/
$stmt->store_result();
/*Check success*/
if($stmt->num_rows > 0){
$rowCount = $stmt->num_rows;
/*The number of bldgs will be the same for blk or color prints, so count the
black ones. This will be the first table and will determine if other pages need
to be added in order to keep the color prints header and table together. */
$blkCount = 0;
/*Declare html strings here so the color one can be printed after its group name*/
$mainContentB = '';
$mainContentC = '';
if($grpBy === 'Building'){
/*Bind results*/
$stmt->bind_result($orgName, $gbName, $proj_bk_vol, $pb_bk_vol, $proj_col_vol,
$pb_col_vol, $proj_bk_chg, $pb_bk_chg, $proj_col_chg, $pb_col_chg);
}
else{
/*Bind results*/
$stmt->bind_result($orgName, $gbName, $dept_id, $proj_bk_vol, $pb_bk_vol,
$proj_col_vol, $pb_col_vol, $proj_bk_chg, $pb_bk_chg, $proj_col_chg, $pb_col_chg);
}
/*Declare $main here so we can add to the string for each record*/
$mainBlack = '';
$mainColor = '';
$totBkProjVol = 0;
$totBkProjChg = 0;
$totBkPBVol = 0;
$totBkPBChg = 0;
$totColProjVol = 0;
$totColProjChg = 0;
$totColPBVol = 0;
$totColPBChg = 0;
/*Black and Color Combined Totals*/
$projectVol = 0;
$projectChg = 0;
$prebillVol = 0;
$prebillChg = 0;
while($stmt->fetch()){
$blkCount += 1;
/*Increment the totals for the grand total footer*/
$totBkProjVol = $totBkProjVol + $proj_bk_vol;
$totBkProjChg = $totBkProjChg + $proj_bk_chg;
$totBkPBVol = $totBkPBVol + $pb_bk_vol;
$totBkPBChg = $totBkPBChg + $pb_bk_chg;
$totColProjVol = $totColProjVol + $proj_col_vol;
$totColProjChg = $totColProjChg + $proj_col_chg;
$totColPBVol = $totColPBVol + $pb_col_vol;
$totColPBChg = $totColPBChg + $pb_col_chg;
$formatArray = array();
$contentArrayBk = array("numOthCols"=>"4", "col_0"=>$gbName, "col_1"=>number_format($proj_bk_vol),
"col_2"=>"$" . number_format($proj_bk_chg, 2), "col_3"=>number_format($pb_bk_vol),
"col_4"=>"$" . number_format($pb_bk_chg, 2), "alignLead"=>"left", "alignOth"=>"right",
"fArray"=>$formatArray, "multiCols"=>$widthArrayTableBk);
$contentArrayCol = array("numOthCols"=>"4", "col_0"=>$gbName, "col_1"=>number_format($proj_col_vol),
"col_2"=>"$" . number_format($proj_col_chg, 2), "col_3"=>number_format($pb_col_vol),
"col_4"=>"$" . number_format($pb_col_chg, 2), "alignLead"=>"left", "alignOth"=>"right",
"fArray"=>$formatArray, "multiCols"=>$widthArrayTableBk);
$blackContentRow = getHtmlStr('GTMULTIW2', $contentArrayBk);
$colorContentRow = getHtmlStr('GTMULTIW2', $contentArrayCol);
/*If the current record count for black copies > 23 AND the total rows
returned > 23 print the $mainBlack that is
already concatenated, then add a page, a new header (same as the first),
then reset the $mainBlack, but keep the $mainColor as is. It will be printed
after the black totals footer has been printed.*/
if(($blkCount > 23) && ($rowCount > 23)){
$mainContentB = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($mainContentB, true, true, false, false, '');
$pdf->AddPage('L');
$mainBlack = $blkTabHdr . $blackContentRow;
$blkCount = 1;
}#end if
else{
/*Send black and color arrays separately to the getHtmlStr function so it can compose the
main content for each group*/
$mainBlack .= $blackContentRow;
$mainColor .= $colorContentRow;
}#end else
}#end while
/*Assign the Black and Color Combined Totals to vars*/
$projectVol = $totBkProjVol + $totColProjVol;
$projectChg = $totBkProjChg + $totColProjChg;
$prebillVol = $totBkPBVol + $totColPBVol;
$prebillChg = $totBkPBChg + $totColPBChg;
/****************** GET DATA FOR BLACK AND COLOR END *****************/
/********************** MAIN CONTENT BLACK BEGIN *********************/
$mainContentB = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($mainContentB, true, true, false, false, '');
/********************** MAIN CONTENT BLACK END *****************/
/*Close the db connection*/
$stmt->close();
}#end if num_rows
/********************** BLACK FOOTER BEGIN*********************/
/*Print the total footer for black data*/
$totTitle = "Black Prints Totals";
$formatArray = array("col_0"=>'style="margin-top:0px; margin-bottom:0px; padding:1px;"');
$fVals = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totBkProjVol),
"col_2"=>"$" . number_format($totBkProjChg, 2), "col_3"=>number_format($totBkPBVol),
"col_4"=>"$" . number_format($totBkPBChg, 2), "alignLead"=>"right", "alignOth"=>"right",
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArray, "multiCols"=>$widthArrayTableBk);
$blkF = getHtmlStr('GTMULTIW2', $fVals);
$blackFooter = <<SetFont('helvetica', 'B', 11);
$pdf->writeHTML($blackFooter, true, true, false, false, '');
/********************** BLACK FOOTER END *********************/
if($rowCount > 12){
$pdf->AddPage('L');
}
/********************** PRINT COLOR GROUP TITLE BEGIN*********************/
$headString = "Color Prints";
$rowStyle = 'style="color:rgb(35, 114, 239); margin-top:0px; margin-bottom:0px;"';
$widthArray = array("col_0"=>800);
$tVals = array("numOthCols"=>"0", "col_0"=>$headString,
"rowStyle"=>$rowStyle, "fArray"=>$formatArrayGrpHeadCol, "multiCols"=>$widthArray);
$grpNameCol = getHtmlStr('GTMULTIW2', $tVals);
/********************** PRINT COLOR GROUP TITLE END*********************/
/********************** PRINT COLOR TABLE HEADER BEGIN*********************/
$gVals = array("numOthCols"=>"4", "col_0"=>$grpBy, "col_1"=>"Projected Volume", "col_2"=>"Projected Charges",
"col_3"=>"Pre-Billing Volume", "col_4"=>"Pre-Billing Charges",
"alignLead"=>"left", "alignOth"=>"right", "rowStyle"=>'', "fArray"=>$formatArrayHdr, "multiCols"=>$widthArrayTableBk);
$cTabHead = getHtmlStr('GTMULTIW2', $gVals);
$cTableHead = <<writeHTML($cTableHead, true, true, false, false, '');
/********************** PRINT COLOR TABLE HEADER END*********************/
/********************** MAIN CONTENT COLOR BEGIN *********************/
/*$mainColor was set above in while loop*/
$mainContentC = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($mainContentC, true, true, false, false, '');
/********************** MAIN CONTENT COLOR END *********************/
/********************** COLOR FOOTER BEGIN*********************/
$totTitle = "Color Prints Totals";
$gVals = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totColProjVol), "col_2"=>"$" . number_format($totColProjChg, 2),
"col_3"=>number_format($totColPBVol), "col_4"=>"$" . number_format($totColPBChg, 2),
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArrayTotalsF, "multiCols"=>$widthArrayTableBk);
$colFoot = getHtmlStr('GTMULTIW2', $gVals);
$colorFooter = <<SetFont('helvetica', 'B', 11);
$pdf->writeHTML($colorFooter, true, true, false, false, '');
/********************** COLOR FOOTER END*********************/
/********************** INVOICE TOTALS FOOTER BEGIN*********************/
$totTitle2 = "Total Pre-Billing Invoice";
$gVals = array("numOthCols"=>"4", "col_0"=>$totTitle2, "col_1"=>number_format($projectVol),
"col_2"=>"$" . number_format($projectChg, 2), "col_3"=>number_format($prebillVol),
"col_4"=>'$' . number_format($prebillChg, 2) . '', "alignLead"=>"right", "alignOth"=>"right",
"rowStyle"=>$rowStyleInvF, "fArray"=>$formatArrayInvF, "multiCols"=>$widthArrayTableBk);
$invFoot = getHtmlStr('GTMULTIW2', $gVals);
$invoiceFooter = <<writeHTML($invoiceFooter, true, true, false, false, '');
/********************** INVOICE TOTALS FOOTER END*********************/
/*******************PREBILL BEGIN - Star pdf ********************/
# set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE,'', PDF_HEADER_STRING);
# 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 margins
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
# set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
# set image scale factor. This is needed for all table columns to be shown.
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
# add a page
$pdf->AddPage('L');
# set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
# Title Name of Organization for the page header
$formatArrayPH = array("col_0"=>'style="font-family:Helvetica; font-size:14px; font-weight:bold; text-align:center;"');
$widthArrayPH = array("col_0"=>975);
$orgNameH = array("numOthCols"=>"0", "col_0"=>$orgName, "rowStyle"=>'', "fArray"=>$formatArrayPH, "multiCols"=>$widthArrayPH);
$orgH = getHtmlStr('GTMULTIW2', $orgNameH);
$orgHeader = <<writeHTML($orgHeader, true, true, false, false, '');
$sql = ''; #Query specific to group by building or dept.
$qB = ''; /*Query part that is required ONLY when billing_type = Vendor. Value
will be an empty string for Client, but not for Vendor. */
if($billing_type == 'Vendor'){
/*If report is for a vendor, ONLY machines owned by that vendor should be in report */
$qB = ' AND vendOrg.id = "' . $thisVendor . '"';
}
/* styling for the group name header in the prebill middle section of the report. */
$rowStyleGroup = 'style="background-color:rgb(173, 192, 217);"';
$formatArrayGroup = array("col_0"=>'style="text-align:left;"');
/***********************BEGIN TABLE HEADER FOR MID SECTION**********************/
$formatArray = array("col_0"=>'style="font-weight:bold; font-size:12px;"',
"col_1"=>'style="font-weight:normal; font-size:12px;"',
"col_2"=>'style="font-weight:bold; font-size:12px;"',
"col_3"=>'style="font-weight:normal; font-size:12px;"',
"col_4"=>'style="font-weight:bold; font-size:12px;"',
"col_5"=>'style="font-weight:bold; font-size:12px;"');
$rowStyle = '';
$widthArray = array("col_0"=>325, "col_1"=>125, "col_2"=>125, "col_3"=>125, "col_4"=>125, "col_5"=>135);
$gVals = array("numOthCols"=>"5", "col_0"=>"
Details", "col_1"=>"Full Year Projected
Black Volume
and Cost",
"col_2"=>"Pre-Billing
Black Volume
and Cost", "col_3"=>"Full Year Projected
Color Volume
and Cost",
"col_4"=>"Pre-Billing
Color Volume
and Cost", "col_5"=>"TOTAL Pre-Bill
Volume
and Cost",
"alignLead"=>"center", "alignOth"=>"center", "rowStyle"=>$rowStyle, "fArray"=>$formatArray, "multiCols"=>$widthArray);
$bldgHdr = getHtmlStr('GTMULTIW2', $gVals);
/***********************END TABLE HEADER FOR MID SECTION************************/
/************************ BEGIN SPACER ROW WITH BORDER FOR MID SECTION **********/
$formatArrayMid = array("col_0"=>'style="border-top:1px solid black; font-size:4px; font-weight:bold;"');
$widthArrayMid = array("col_0"=>950); /*for shorter header spacer line to not conflict with right aligned header org_name */
$spacerValsMid = array("numOthCols"=>"0", "col_0"=>" ", "rowStyle"=>'',
"fArray"=>$formatArrayMid, "multiCols"=>$widthArrayMid);
$spacerRowMid = getHtmlStr('GTMULTIW2', $spacerValsMid);
/************************ END SPACER ROW WITH BORDER FOR MID SECTION **********/
if($grpBy == 'Building'){
/*$qB will be concatenated to query, whether the billing_type = Vendor or Client,
but it will be an empty string for Client and extra criterion for Vendor.*/
$sql="SELECT
bldg.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.cpc_black,
bd.projected_volume_color,
bd.billed_projected_volume_color,
bd.cpc_color,
org.org_name,
bd.vendor_cpc_black,
bd.vendor_cpc_color
FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN buildings bldg ON bd.building_id_ma = bldg.id
INNER JOIN machines mac ON bd.model_id = mac.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = " . $recordId . $qB .
" AND bd.Traded NOT IN('Yes', 'Y') ORDER BY bldg.building_name, bd.room_name;";
}
else{
$sql="SELECT
bldg.building_name,
bd.room_name,
dpt.dept_name,
concat(Make,' ', model) AS MakeModel,
bd.serial_number,
bd.vendor_mach_id,
bd.projected_volume_black,
bd.billed_projected_volume_black,
bd.cpc_black,
bd.projected_volume_color,
bd.billed_projected_volume_color,
bd.cpc_color,
org.org_name,
bd.vendor_cpc_black,
bd.vendor_cpc_color
FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN buildings bldg ON bd.building_id_ma = bldg.id
INNER JOIN machines mac ON bd.model_id = mac.id
INNER JOIN department dpt ON dpt.id = bd.dept_id_ma
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = " . $recordId . $qB .
" AND bd.Traded NOT IN('Yes', 'Y') ORDER BY dpt.dept_name, bldg.building_name, bd.room_name;";
}
/* Set table variables outside the while loop, so they can be used to print the footer for the last building.
When the last building has no more rooms, there will be no new building name to compare the last one to
for determining to print the footer. */
/*This will be set to y after a building header has printed */
$footerFlag = 'n';
/*This is the current building or department name. This will only = the $groupByName after the header has printed and before the footer has printed*/
$gbName = '';
$groupByName = '';
$buildingName = '';
$room = '';
$makeModel = '';
$serialNum = '';
$vendorMa = '';
# Volume
$projBlkVol = '';
$billProjBlkVol = '';
$projColVol = '';
$billProjColVol = '';
$totalBillVol = '';
# Cost
$projFYBlkCost = '';
$billBlkCost = '';
$projFYColorCost = '';
$billColorCost = '';
$totalBillCost = '';
# cpc
$cpcBlk = '';
$cpcColor = '';
# 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;
$totPBCost = 0;
#grand totals for end of report
$gtBlkVol = 0;
$gtPBBlkVol = 0;
$gtColVol = 0;
$gtPBColVol = 0;
$gtTotPBVol = 0;
$gtBlkCost = 0;
$gtPBBlkCost = 0;
$gtColCost = 0;
$gtPBColCost = 0;
$gtTotPBCost = 0;
$recordCount = 0; /*When count reaches 6 repeat table header, then reset this var. */
#Query results.
if($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'];
if($grpBy == 'Building'){
$groupByName = $row['building_name'];
}
else{
$groupByName = $row['dept_name'];
$room = $row['building_name'] . ' - ' . $row['room_name'];
}
# 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']);
# cpc
if($billing_type == 'Vendor'){
$cpcBlk = $row['vendor_cpc_black'];
$cpcColor = $row['vendor_cpc_color'];
}
else{
$cpcBlk = $row['cpc_black'];
$cpcColor = $row['cpc_color'];
}
$projFYBlkCost = '$'.number_format($row['projected_volume_black'] * $cpcBlk, 2);
$billBlkCost = '$'.number_format($row['billed_projected_volume_black'] * $cpcBlk, 2);
$projFYColorCost = '$'.number_format($row['projected_volume_color'] * $cpcColor, 2);
$billColorCost = '$'.number_format($row['billed_projected_volume_color'] * $cpcColor, 2);
$totalBillCost = '$'.number_format(($row['billed_projected_volume_black'] * $cpcBlk)
+($row['billed_projected_volume_color'] * $cpcColor),2);
/*Assign values to the footer array BEFORE the totals are incremented. This array is a param for the function getHtmlStr. It holds
all values that will be needed in the footer. This needs to be HERE because the determining factor of which loop to run is
whether or not the $gbName matches $groupByName. This equality can only be checked when the next row is fetched. So the footer
totals MUST NOT include the current record vals until it is determined that the $gbName matches $groupByName. If the names
are different, then this footerData is sent to the function with the correct values and printed BEFORE the new building name header
and main content are printed.*/
$totTitle = "SUBTOTAL: ";
$rowStyle = 'style="background-color:rgb(198, 209, 222)";';
$widthArray = array("col_0"=>325, "col_1"=>125, "col_2"=>125, "col_3"=>125, "col_4"=>125, "col_5"=>125);
$ftrContent = array("numOthCols"=>"5",
"col_0"=>$totTitle . $gbName,
"col_1"=>number_format($TotalBlackVol) . "
$" . number_format($TotalBlackCost, 2),
"col_2"=>number_format($TotalPBBlackVol) . "
$" . number_format($TotalPBBlackCost, 2),
"col_3"=>number_format($TotalColorVol) . "
$" . number_format($TotalColorCost, 2),
"col_4"=>number_format($TotalPBColorVol) . "
$" . number_format($TotalPBColorCost, 2),
"col_5"=>number_format($TotalPBVolume) . "
$" . number_format($totPBCost, 2),
"alignLead"=>"right", "alignOth"=>"right", "rowStyle"=>$rowStyle, "fArray"=>'', "multiCols"=>$widthArray);
# Sub Totals to be incremented
# First row Total Volumes for Building Footer.
$TotalBlackVol = ($TotalBlackVol + $row['projected_volume_black']);
$TotalPBBlackVol = ($TotalPBBlackVol + $row['billed_projected_volume_black']);
$TotalColorVol = ($TotalColorVol + $row['projected_volume_color']);
$TotalPBColorVol = ($TotalPBColorVol + $row['billed_projected_volume_color']);
$TotalPBVolume = $TotalPBVolume + ($row['billed_projected_volume_black'] + $row['billed_projected_volume_color']);
# Second row Total Cost for Building Footer - calculated and incremented totals.
$TotalBlackCost = $TotalBlackCost + $row['projected_volume_black'] * $cpcBlk;
$TotalPBBlackCost = $TotalPBBlackCost + $row['billed_projected_volume_black'] * $cpcBlk;
$TotalColorCost = $TotalColorCost + $row['projected_volume_color'] * $cpcColor;
$TotalPBColorCost = $TotalPBColorCost + $row['billed_projected_volume_color'] * $cpcColor;
$totPBCost = $TotalPBBlackCost + $TotalPBColorCost;
#grand totals for end of report
$gtBlkVol = ($gtBlkVol + $row['projected_volume_black']);
$gtPBBlkVol = ($gtPBBlkVol + $row['billed_projected_volume_black']);
$gtColVol = $gtColVol + $row['projected_volume_color'];
$gtPBColVol = $gtPBColVol + $row['billed_projected_volume_color'];
$gtTotPBVol = $gtTotPBVol + ($row['billed_projected_volume_black'] + $row['billed_projected_volume_color']);
$gtBlkCost = $gtBlkCost + $row['projected_volume_black'] * $cpcBlk;
$gtPBBlkCost = $gtPBBlkCost + $row['billed_projected_volume_black'] * $cpcBlk;
$gtColCost = $gtColCost + $row['projected_volume_color'] * $cpcColor;
$gtPBColCost = $gtPBColCost + $row['billed_projected_volume_color'] * $cpcColor;
$gtTotPBCost = $gtTotPBCost + (($row['projected_volume_black'] * $cpcBlk) + ($row['projected_volume_color'] * $cpcColor));
$tabContent = array("bn"=>$buildingName, "pbv"=>$projBlkVol, "billpbv"=>$billProjBlkVol, "pcv"=>$projColVol, "billpcv"=>$billProjColVol, "totbv"=>$totalBillVol,
"room"=>$room, "mkmo"=>$makeModel, "pfybcost"=>$projFYBlkCost, "billbcost"=>$billBlkCost, "pfyccost"=>$projFYColorCost, "billccost"=>$billColorCost,
"totbcost"=>$totalBillCost, "serial"=>$serialNum, "vend"=>$vendorMa, "cpcblk"=>$cpcBlk, "cpccol"=>$cpcColor);
if($gbName != $groupByName && $footerFlag == 'n'){
/*********************BEGIN FIRST GROUP HEADER******************/
$widthArray = array("col_0"=>950);
$grpT = array("numOthCols"=>"0", "col_0"=>$groupByName,
"rowStyle"=>$rowStyleGroup, "fArray"=>$formatArrayGroup, "multiCols"=>$widthArray);
$grpName = getHtmlStr('GTMULTIW2', $grpT);
# Set the header font, then print.
$pdf->SetFont('helvetica', 'B', 12);
$buildH = <<writeHTML($buildH, true, true, false, false, '');
/*******************END FIRST GROUP HEADER****************/
/*Set the $gbName = the current $groupByName from the resultset. If they are equal, the footer will not print yet. */
$gbName = $groupByName;
/*Set the footer to y so the footer will print the first time the $gbName != $groupByName*/
$footerFlag = 'y';
# Set the font for the data.
$pdf->SetFont('helvetica', '', 10);
/*call the getHtmlStr function to construct the html for the table content*/
$mCnt = getHtmlStr('M', $tabContent);
$tblMachineData1 = <<writeHTML($tblMachineData1, true, true, false, false, '');
}#end if $gbName != $groupByName && $footerFlag == 'n'
/* If the building name equals the variable $gbName then start filling in
each machine for this building.*/
else if($gbName == $groupByName){
$recordCount += 1; /* When count reaches 6 repeat table header, then reset this var. */
/*call the getHtmlStr function to construct the html for the table content*/
$mCnt2 = getHtmlStr('M', $tabContent);
/*This will add the table header at the top of each page. Six records can fit on a pg. */
if($recordCount === 5){
$recordCount = 0;/* When count reaches 6 repeat table header, then reset this var. */
$pdf->AddPage('L');
/*********Begin Print the group header for this new page *********/
$widthArray = array("col_0"=>950);
$grp2 = array("numOthCols"=>"0", "col_0"=>"$groupByName",
"rowStyle"=>$rowStyleGroup, "fArray"=>$formatArrayGroup, "multiCols"=>$widthArray);
$grpNamex = getHtmlStr('GTMULTIW2', $grp2);
# Set the font, then print.
$pdf->SetFont('helvetica', 'B', 12);
$buildHx = <<writeHTML($buildHx, true, true, false, false, '');
/*********End Print the group header for this new page *********/
$tblMachineData2 = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($tblMachineData2, true, true, false, false, '');
}#end if $recordCount === 5
else{
$tblMachineData = <<writeHTML($tblMachineData, true, true, false, false, '');
}#end else if $recordCount === 5
}#end else if $groupByName == $gbName
else if($gbName != $groupByName && $footerFlag == 'y'){
/*call the getHtmlStr function to construct the html for the footer content*/
$ftrContent3 = getHtmlStr('GTMULTIW2', $ftrContent);
$tblFooter = <<SetFont('helvetica', 'B', 11);
/*Print the footer w/the totals BEFORE resetting the current row values = the cur val for each var*/
$pdf->writeHTML($tblFooter, true, true, false, false, '');
# Sub Totals to be incremented
# First row Total Volumes for Building Footer.
$TotalBlackVol = $row['projected_volume_black'];
$TotalPBBlackVol = $row['billed_projected_volume_black'];
$TotalColorVol = $row['projected_volume_color'];
$TotalPBColorVol = $row['billed_projected_volume_color'];
$TotalPBVolume = $row['billed_projected_volume_black'] + $row['billed_projected_volume_color'];
# Second row Total Cost for Building Footer - calculated and incremented totals.
$TotalBlackCost = $row['projected_volume_black'] * $cpcBlk;
$TotalPBBlackCost = $row['billed_projected_volume_black'] * $cpcBlk;
$TotalColorCost = $row['projected_volume_color'] * $cpcColor;
$TotalPBColorCost = $row['billed_projected_volume_color'] * $cpcColor;
$totPBCost = $TotalPBBlackCost + $TotalPBColorCost ;
# add a page and set the recordCount to 0 because this will already begin a new page.
$pdf->AddPage('L');
$recordCount = 0;
/*Add the page header for each page when a new building begins*/
# Title Name of Organization.
$orgNameH2 = array("numOthCols"=>"0", "col_0"=>$orgName, "rowStyle"=>'', "fArray"=>$formatArrayPH, "multiCols"=>$widthArrayPH);
$orgH2 = getHtmlStr('GTMULTIW2', $orgNameH2);
# Set the Title font.
$pdf->SetFont('helvetica', 'B', 12);
/*call the function to construct the html for the prebill main content header*/
#$pbMainContentH2 = getHtmlStr('GTMULTIW2', $pbMainH2);
$prebillMainH2 = <<SetFont('helvetica', 'B', 10);
/*Print the main content header for the first room*/
$pdf->writeHTML($prebillMainH2 , false, true, false, false, '');
$widthArray = array("col_0"=>950);
$grp3 = array("numOthCols"=>"0", "col_0"=>"$groupByName",
"rowStyle"=>$rowStyleGroup, "fArray"=>$formatArrayGroup, "multiCols"=>$widthArray);
$grpT3 = getHtmlStr('GTMULTIW2', $grp3);
# Set the font, then print.
$pdf->SetFont('helvetica', 'B', 12);
$buildH2 = <<writeHTML($buildH2, true, true, false, false, '');
/*Assign the new buildingName to bName*/
$gbName = $groupByName;
/*call the function to construct the html for the table content*/
$mCnt3 = getHtmlStr('M', $tabContent);
$tblMachineData2 = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($tblMachineData2, true, true, false, false, '');
}#end else if $gbName != $groupByName && $footerFlag == 'y'
}#end while
/*Assign vals to footerData now to include the vals from the last record. The vals in the current footerData array do NOT include the
vals from the last record. This is because the footer vals are assigned BEFORE the totals are incremented.*/
$totTitle = "Subtotal:";
$totPBCost = $TotalPBBlackCost + $TotalPBColorCost;
$widthArray = array("col_0"=>325, "col_1"=>125, "col_2"=>125, "col_3"=>125, "col_4"=>125, "col_5"=>125);
$formatArray = array();
$rowStyle = 'style="background-color:rgb(198, 209, 222);"';
$ftrContent = array("numOthCols"=>"5", "col_0"=>$totTitle . " " . $gbName,
"col_1"=>number_format($TotalBlackVol) . "
$" . number_format($TotalBlackCost, 2),
"col_2"=>number_format($TotalPBBlackVol) . "
$" . number_format($TotalPBBlackCost, 2),
"col_3"=>number_format($TotalColorVol) . "
$" . number_format($TotalColorCost, 2),
"col_4"=>number_format($TotalPBColorVol) . "
$" . number_format($TotalPBColorCost, 2),
"col_5"=>number_format($TotalPBVolume) . "
$" . number_format($totPBCost, 2),
"alignLead"=>"right", "alignOth"=>"right", "rowStyle"=>$rowStyle, "fArray"=>$formatArray, "multiCols"=>$widthArray);
/*call the function to construct the html for the footer content*/
$ftrContent2 = getHtmlStr('GTMULTIW2', $ftrContent);
$tblFooter2 = <<SetFont('helvetica', 'B', 10);
/*Print the footer for the last room*/
$pdf->writeHTML($tblFooter2, true, true, false, false, '');
$totTitle = "Grand Totals:";
$gtTotPBCost = $gtPBBlkCost + $gtPBColCost;
$formatArray = array(); /*cols that need formatting*/
$rowStyle = 'style="background-color:rgb(205, 220, 175);"';
$gtFooterData = array("numOthCols"=>"5", "col_0"=>$totTitle, "col_1"=>number_format($gtBlkVol) . "
$" . number_format($gtBlkCost, 2),
"col_2"=>number_format($gtPBBlkVol) . "
$" . number_format($gtPBBlkCost, 2),
"col_3"=>number_format($gtColVol) . "
$" . number_format($gtColCost, 2),
"col_4"=>number_format($gtPBColVol) . "
$" . number_format($gtPBColCost, 2),
"col_5"=>number_format($gtTotPBVol) . "
$" . number_format($gtTotPBCost, 2),
"alignLead"=>"right", "alignOth"=>"right", "rowStyle"=>$rowStyle, "fArray"=>$formatArray, "multiCols"=>$widthArray);
/*call the getHtmlStr function to construct the html for the grand total footer*/
$gt = getHtmlStr('GTMULTIW2', $gtFooterData);
# Set the font for the for the grand total footer.
$pdf->SetFont('helvetica', 'B', 12);
$gtFooter = <<writeHTML($gtFooter, true, true, false, false, '');
}#end if $result
/******************************PREBILL SUMMARY BY VENDOR***********************/
if($billing_type == 'Vendor'){
$ttl = 'Summary by Model Type';
}
else{
$ttl = 'Summary by Vendor';
}
$grpBy = 'Vendor';
/*Declared here to be used for headers and footers in last section of report */
$formatArrayHdrBC = '';
/**************************** CONSTRUCT PAGE TITLE **************************/
$widthArray = array("col_0"=>950);
$phVals2 = array("col_0"=>$topLine . "
" . $schoolYear . " / " . $billing_cycle . "
" . $ttl,
"alignLead"=>"center", "alignOth"=>"", "rowStyle"=>'', "multiCols"=>$widthArray);
$pdf->AddPage('L');
$titleStr = getHtmlStr('GTMULTIW2', $phVals2);
/********************** PRINT GROUP HEADER *********************/
$rowStyleHeader = 'style="font-size:12px; font-weight:bold;"';
$headString = "Black Prints";
$widthArray = array("col_0"=>850);
$gVals2 = array("col_0"=>$headString, "fArray"=>$formatArrayGrpHeadBk, "rowStyle"=>$rowStyleHeader, "multiCols"=>$widthArray);
$grpNameBk = getHtmlStr('GTMULTIW2', $gVals2);
$groupTitle = <<writeHTML($groupTitle , false, true, false, false, '');
$ttl = 'Vendor';
$thValsV = '';
if($billing_type == 'Vendor'){
$formatArrayHdrBC = array("col_0"=>'style="text-align:left; border-bottom:1px solid black;"',
"col_1"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_2"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_3"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_4"=>'style="text-align:right; border-bottom:1px solid black;"');
$thValsV = array("numOthCols"=>"4", "col_0"=>"Model Type", "col_1"=>"Projected
Volume",
"col_2"=>"Projected
Charges", "col_3"=>"Pre-Billing
Volume", "col_4"=>"Pre-Billing
Charges",
"fArray"=>$formatArrayHdrBC, "rowStyle"=>$rowStyleHeader, "multiCols"=>$widthArrayVend);
}
else{
$formatArrayHdrBC = array("col_0"=>'style="text-align:left; border-bottom:1px solid black;"',
"col_1"=>'style="text-align:center; border-bottom:1px solid black;"',
"col_2"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_3"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_4"=>'style="text-align:right; border-bottom:1px solid black;"',
"col_5"=>'style="text-align:right; border-bottom:1px solid black;"');
$thValsV = array("numOthCols"=>"5", "col_0"=>"$grpBy", "col_1"=>"Model
Type", "col_2"=>"Projected
Volume",
"col_3"=>"Projected
Charges", "col_4"=>"Pre-Billing
Volume",
"col_5"=>"Pre-Billing
Charges", "fArray"=>$formatArrayHdrBC, "rowStyle"=>$rowStyleHeader, "multiCols"=>$widthArrayClient);
}
/********************** BEGIN BLACK TABLE HEADER *********************/
$tabHdr = getHtmlStr('GTMULTIW2', $thValsV);
$hdrRow = <<writeHTML($hdrRow, true, true, false, false, '');
/********************** END BLACK TABLE HEADER *********************/
/********************** MAIN CONTENT BLACK BEGIN *********************/
$qB = '';
/* Fetch the correct cpc for Vendor or Client billing_type. */
if($billing_type == 'Vendor'){
$qB = ' Sum(( bd.projected_volume_black * vendor_cpc_black )) proj_bk_chg,
Sum(( bd.billed_projected_volume_black * vendor_cpc_black )) pb_bk_chg';
$qC = ' AND vendOrg.id = ?';
}
else{
$qB = ' Sum(( bd.projected_volume_black * cpc_black )) proj_bk_chg,
Sum(( bd.billed_projected_volume_black * cpc_black )) pb_bk_chg';
}
$selQB = 'SELECT org.org_name,
mt.type_name model_type,
vendOrg.org_name vendor,
Sum(bd.projected_volume_black) proj_bk_vol,
Sum(bd.billed_projected_volume_black) pb_bk_vol, ' . $qB .
' FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN machines ma ON bd.model_id = ma.id
INNER JOIN machine_types mt ON ma.model_type = mt.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = ? ' . $qC .
' GROUP BY bd.vendor_id, mt.type_name;';
$stmt = $dbLink->prepare($selQB);
/*Bind the criteria param*/
if($billing_type == 'Vendor'){
$stmt->bind_param('ii', $recordId, $thisVendor);
}
else{
$stmt->bind_param('i', $recordId);
}
/*Execute the stmt*/
$stmt->execute();
/*Store result*/
$stmt->store_result();
/*Check success*/
if($stmt->num_rows > 0){
/*Declare html strings here so the color one can be printed after its group name - MAY NOT NEED SINCE BLK AND COLOR ARE SEPARATE*/
$mainContentB = '';
$mainContentC = '';
/*Bind results*/
$stmt->bind_result($orgName, $make_mod, $vendor, $proj_bk_vol, $pb_bk_vol, $proj_bk_chg, $pb_bk_chg);
/*Declare $main here so we can add to the string for each record*/
$mainBlack = '';
$mainColor = '';
$totBkProjVol = 0;
$totBkProjChg = 0;
$totBkPBVol = 0;
$totBkPBChg = 0;
$totColProjVol = 0;
$totColProjChg = 0;
$totColPBVol = 0;
$totColPBChg = 0;
/*Black and Color Combined Totals*/
$projectVol = 0;
$projectChg = 0;
$prebillVol = 0;
$prebillChg = 0;
while($stmt->fetch()){
/*Increment the totals for the grand total footer*/
$totBkProjVol = $totBkProjVol + $proj_bk_vol;
$totBkProjChg = $totBkProjChg + $proj_bk_chg;
$totBkPBVol = $totBkPBVol + $pb_bk_vol;
$totBkPBChg = $totBkPBChg + $pb_bk_chg;
/*Send black and color arrays separately to the getHtmlStr function so it can compose the
main content for each group*/
$formatArray = array(); /*cols that need formatting*/
if($billing_type == 'Vendor'){
$formatArrayCont = array("col_0"=>'style="text-align:left;"',
"col_1"=>'style="text-align:right;"',
"col_2"=>'style="text-align:right;"',
"col_3"=>'style="text-align:right;"',
"col_4"=>'style="text-align:right;"');
$contentArrayBk = array("numOthCols"=>"5", "col_0"=>$make_mod, "col_1"=>number_format($proj_bk_vol),
"col_2"=>"$" . number_format($proj_bk_chg, 2), "col_3"=>number_format($pb_bk_vol), "col_4"=>"$" . number_format($pb_bk_chg, 2),
"recTextCol"=>$recTextCol, "fArray"=>$formatArrayCont, "multiCols"=>$widthArrayVend);
}
else{
$formatArrayCont = array("col_0"=>'style="text-align:left;"',
"col_1"=>'style="text-align:left;"',
"col_2"=>'style="text-align:right;"',
"col_3"=>'style="text-align:right;"',
"col_4"=>'style="text-align:right;"',
"col_5"=>'style="text-align:right;"');
$contentArrayBk = array("numOthCols"=>"5", "col_0"=>$vendor, "col_1"=>$make_mod, "col_2"=>number_format($proj_bk_vol),
"col_3"=>"$" . number_format($proj_bk_chg, 2), "col_4"=>number_format($pb_bk_vol), "col_5"=>"$" . number_format($pb_bk_chg, 2),
"recTextCol"=>$recTextCol, "fArray"=>$formatArrayCont, "multiCols"=>$widthArrayClient);
}
$mainBlack = $mainBlack . getHtmlStr('GTMULTIW2', $contentArrayBk);
}#end while
/*Now print the black main content*/
$mainContentB = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($mainContentB, true, true, false, false, '');
/********************** MAIN CONTENT BLACK END *********************/
/********************** BLACK FOOTER BEGIN*************************/
/*Print the total footer for black data*/
$totTitle = "Black Prints Totals";
$formatArray = array();
$gTotArrayB = '';
if($billing_type == 'Vendor'){
$gTotArrayB = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totBkProjVol),
"col_2"=>"$" . number_format($totBkProjChg, 2), "col_3"=>number_format($totBkPBVol),
"col_4"=>"$" . number_format($totBkPBChg, 2),
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArrayTotalsF, "multiCols"=>$widthArrayVend);
}
else{
$gTotArrayB = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totBkProjVol),
"col_2"=>"$" . number_format($totBkProjChg, 2), "col_3"=>number_format($totBkPBVol),
"col_4"=>"$" . number_format($totBkPBChg, 2),
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArrayTotalsF, "multiCols"=>$widthArrayClient2);
}
$totBlack = getHtmlStr('GTMULTIW2', $gTotArrayB);
$blackFooter = <<SetFont('helvetica', 'B', 11);
$pdf->writeHTML($blackFooter, true, true, false, false, '');
/********************** BLACK FOOTER END *************************/
/********************** PRINT COLOR GROUP TITLE BEGIN ******************/
$headString = "Color Prints";
$widthArray = array("col_0"=>850);
$gVals3 = array("col_0"=>$headString, "rowStyle"=>$rowStyleHeader, "multiCols"=>$widthArray, "fArray"=>$formatArrayGrpHeadCol);
/*Create the group header, then print it with the table header */
$grpName2 = getHtmlStr('GTMULTIW2', $gVals3);
/********************** PRINT COLOR GROUP TITLE END ******************/
/********************** PRINT COLOR TABLE HEADER BEGIN*********************/
$grpBy = 'Vendor';
$thValsV = '';
if($billing_type =='Vendor'){
$formatArray = array("col_0"=>'style="text-align:left; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_1"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_2"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_3"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_4"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"');
$thValsV = array("numOthCols"=>"4", "col_0"=>"Model Type", "col_1"=>"Projected
Volume",
"col_2"=>"Projected
Charges", "col_3"=>"Pre-Billing
Volume",
"col_4"=>"Pre-Billing
Charges",
"rowStyle"=>$rowStyleHeader, "fArray"=>$formatArray, "multiCols"=>$widthArrayVend);
}
else{
$formatArray = array("col_0"=>'style="text-align:left; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_1"=>'style="text-align:center; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_2"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_3"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_4"=>'style="text-align:right;font-size:12px; font-weight:bold; border-bottom:1px solid black;"',
"col_5"=>'style="text-align:right; font-size:12px; font-weight:bold; border-bottom:1px solid black;"');
$thValsV = array("numOthCols"=>"5", "col_0"=>$grpBy, "col_1"=>"Model
Type", "col_2"=>"Projected
Volume",
"col_3"=>"Projected
Charges", "col_4"=>"Pre-Billing
Volume",
"col_5"=>"Pre-Billing
Charges",
"rowStyle"=>$rowStyleHeader, "fArray"=>$formatArray, "multiCols"=>$widthArrayClient);
}
/*Create the table header, then print it after the group header */
$tabHdr2 = getHtmlStr('GTMULTIW2', $thValsV);
$hdrRow2 = <<writeHTML($hdrRow2, true, true, false, false, '');
/********************** PRINT COLOR TABLE HEADER END*********************/
/********************** MAIN CONTENT COLOR BEGIN *********************/
$qC = '';
if($billing_type == 'Vendor'){
$selQC = 'SELECT org.org_name,
mt.type_name model_type,
vendOrg.org_name vendor,
Sum(bd.projected_volume_color) proj_col_vol,
Sum(bd.billed_projected_volume_color) pb_col_vol,
Sum((bd.projected_volume_color * vendor_cpc_color)) proj_col_chg,
Sum((bd.billed_projected_volume_color * vendor_cpc_color)) pb_col_chg
FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN machines ma ON bd.model_id = ma.id
INNER JOIN machine_types mt ON ma.model_type = mt.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = ?
AND vendOrg.id = ?
AND mt.color = 1
GROUP BY mt.type_name;';
}
else{
$selQC = 'SELECT org.org_name,
mt.type_name model_type,
vendOrg.org_name vendor,
Sum(bd.projected_volume_color) proj_col_vol,
Sum(bd.billed_projected_volume_color) pb_col_vol,
Sum((bd.projected_volume_color * cpc_color)) proj_col_chg,
Sum((bd.billed_projected_volume_color * cpc_color)) pb_col_chg
FROM billing_data bd
INNER JOIN organization org ON bd.org_id_ma = org.id
INNER JOIN machines ma ON bd.model_id = ma.id
INNER JOIN machine_types mt ON ma.model_type = mt.id
INNER JOIN organization vendOrg ON vendOrg.id = bd.vendor_id
WHERE bd.billing_id = ?
AND mt.color = 1
GROUP BY bd.vendor_id, mt.type_name;';
}
/*prepare stmt*/
$eStmt = $dbLink->prepare($selQC);
/*Bind the criteria param*/
if($billing_type == 'Vendor'){
$eStmt->bind_param('ii', $recordId, $thisVendor);
}
else{
$eStmt->bind_param('i', $recordId);
}
/*Execute the stmt*/
$eStmt->execute();
/*Store result*/
$eStmt->store_result();
/*Check success*/
if($eStmt->num_rows > 0){
/*Bind results*/
$eStmt->bind_result($orgName, $make_mod, $vendor, $proj_col_vol, $pb_col_vol, $proj_col_chg, $pb_col_chg);
while($eStmt->fetch()){
$totColProjVol = $totColProjVol + $proj_col_vol;
$totColProjChg = $totColProjChg + $proj_col_chg;
$totColPBVol = $totColPBVol + $pb_col_vol;
$totColPBChg = $totColPBChg + $pb_col_chg;
/*Send black and color arrays separately to the getHtmlStr function so it can compose the
main content for each group*/
$contentArrayCol = '';
if($billing_type == 'Vendor'){
$formatArray = array();
$formatArray = array("col_0"=>'style="text-align:left;"',
"col_1"=>'style="text-align:right;"',
"col_2"=>'style="text-align:right;"',
"col_3"=>'style="text-align:right;"',
"col_4"=>'style="text-align:right;"');
$contentArrayCol = array("numOthCols"=>"4", "col_0"=>$make_mod, "col_1"=>number_format($proj_col_vol),
"col_2"=>"$" . number_format($proj_col_chg, 2), "col_3"=>number_format($pb_col_vol), "col_4"=>"$" . number_format($pb_col_chg, 2),
"fArray"=>$formatArray, "multiCols"=>$widthArrayVend);
}
else{
$formatArray = array("col_0"=>'style="text-align:left;"',
"col_1"=>'style="text-align:left;"',
"col_2"=>'style="text-align:right;"',
"col_3"=>'style="text-align:right;"',
"col_4"=>'style="text-align:right;"',
"col_5"=>'style="text-align:right;"');
$contentArrayCol = array("numOthCols"=>"5", "col_0"=>$vendor, "col_1"=>$make_mod, "col_2"=>number_format($proj_col_vol),
"col_3"=>"$" . number_format($proj_col_chg, 2), "col_4"=>number_format($pb_col_vol), "col_5"=>"$" . number_format($pb_col_chg, 2),
"fArray"=>$formatArray, "multiCols"=>$widthArrayClient);
}
$mainColor = $mainColor . getHtmlStr('GTMULTIW2', $contentArrayCol);
}#end while
/*Now print the color main content*/
$mainContentC = <<SetFont('helvetica', '', 10);
$pdf->writeHTML($mainContentC, true, true, false, false, '');
}#end if $eStmt->num_rows
/********************** MAIN CONTENT COLOR END *********************/
/*Assign the Black and Color Combined Totals to vars for the total pre-billing invoice footer*/
$projectVol = $totBkProjVol + $totColProjVol;
$projectChg = $totBkProjChg + $totColProjChg;
$prebillVol = $totBkPBVol + $totColPBVol;
$prebillChg = $totBkPBChg + $totColPBChg;
/********************** COLOR FOOTER BEGIN *********************/
$totTitle = "Color Prints Totals";
if($billing_type == 'Vendor'){
$gTotArrayC = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totColProjVol), "col_2"=>"$" . number_format($totColProjChg, 2),
"col_3"=>number_format($totColPBVol), "col_4"=>"$" . number_format($totColPBChg, 2),
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArrayTotalsF, "multiCols"=>$widthArrayVend);
}
else{
$gTotArrayC = array("numOthCols"=>"4", "col_0"=>$totTitle, "col_1"=>number_format($totColProjVol), "col_2"=>"$" . number_format($totColProjChg, 2),
"col_3"=>number_format($totColPBVol), "col_4"=>"$" . number_format($totColPBChg, 2),
"rowStyle"=>$rowStyleTotalsF, "fArray"=>$formatArrayTotalsF, "multiCols"=>$widthArrayClient2);
}
$totColor = getHtmlStr('GTMULTIW2', $gTotArrayC);
# Set the footer font, then print.
$pdf->SetFont('helvetica', 'B', 11);
$colorFooter = <<writeHTML($colorFooter, true, true, false, false, '');
/********************** COLOR FOOTER END*********************/
/********************** INVOICE TOTALS FOOTER BEGIN*********************/
$invTitle = "Total Pre-Billing Invoice";
if($billing_type == 'Vendor'){
$widthArray = $widthArrayVend;
}
else{
$widthArray = $widthArrayClient2;
}
$pbInvoiceTotals = array("numOthCols"=>"4", "col_0"=>$invTitle, "col_1"=>number_format($projectVol),
"col_2"=>"$" . number_format($projectChg, 2), "col_3"=>number_format($prebillVol),
"col_4"=>"$" . number_format($prebillChg, 2), "alignLead"=>"right", "alignOth"=>"right",
"rowStyle"=>$rowStyleInvF, "fArray"=>$formatArrayInvF, "multiCols"=>$widthArray);
$invTot = getHtmlStr('GTMULTIW2', $pbInvoiceTotals);
$invoiceFooter = <<writeHTML($invoiceFooter, true, true, false, false, '');
/********************** INVOICE TOTALS FOOTER END*********************/
/*Close the db connection*/
$stmt->close();
}#end if num_rows
mysqli_close($dbc);
# Clean any content of the output buffer.
ob_end_clean();
# Send the pdf
$pdf->Output('combinedPrebillReports.pdf', 'I');
?>