50, "col_1"=>155, "col_2"=>80, "col_3"=>90, "col_4"=>10, "col_5"=>90, "col_6"=>10, "col_7"=>75, "col_8"=>75, "col_9"=>10, "col_10"=>90); $rowStyleComb = 'style="font-size:11px; font-weight:bold; color:rgb(255, 255, 255);"'; $formatArrayAvg = array("col_0"=>'', "col_1"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_2"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_3"=>'style="background-color:rgb(31, 78, 121);"'); $widthArrayAvg = array("col_0"=>50, "col_1"=>250, "col_2"=>75, "col_3"=>360); $rowStyleT = 'style="background-color:rgb(216, 216, 216); color:rgb(0, 102, 34); font-size:14px; font-weight:bold;"'; /********************* END SHARED FORMAT AND WIDTH ARRAYS FOR THE SUMMARY BY BLDG SECTION ******************/ /*********************BEGIN EMPTY SPACER ROW WITH RIGHT BORDERS*************/ $formatArraySB = array("col_0"=>'style="border-right:1px solid black; font-size:4px;"', "col_1"=>'style="border-right:2px solid black; font-size:4px;"', "col_2"=>'style="border-right:1px solid black; font-size:4px;"'); $rowStyleSpc = ''; $widthArray2 = array("col_0"=>385, "col_1"=>100, "col_2"=>160); $spacerVals = array("numOthCols"=>"2", "col_0"=>"", "rowStyle"=>$rowStyleSpc, "fArray"=>$formatArraySB, "multiCols"=>$widthArray2); $borderRights = getHtmlStr('GTMULTIW2', $spacerVals); /*Different width cols for Client report last page */ $widthArray2C = array("col_0"=>430, "col_1"=>95, "col_2"=>160); $spacerValsC = array("numOthCols"=>"2", "col_0"=>"", "rowStyle"=>$rowStyleSpc, "fArray"=>$formatArraySB, "multiCols"=>$widthArray2C); $borderRightsClient = getHtmlStr('GTMULTIW2', $spacerValsC); /*********************END EMPTY SPACER ROW WITH RIGHT BORDERS*************/ /**********************BEGIN EMPTY SPACER ROWS WITH NO BORDERS************/ $formatArraySpc = array("col_0"=>'style="font-size:8px;"'); $widthArraySpc = array("col_0"=>850); $spacerVals2 = array("numOthCols"=>"0", "col_0"=>" ", "rowStyle"=>$rowStyleSpc, "fArray"=>$formatArraySpc, "multiCols"=>$widthArraySpc); $spacerRow2 = getHtmlStr('GTMULTIW2', $spacerVals2); $formatArraySpcH = array("col_0"=>'style="font-size:4px; border-top:3px solid black;"'); $widthArraySpcH = array("col_0"=>940); $spacerValsH = array("numOthCols"=>"0", "col_0"=>" ", "rowStyle"=>$rowStyleT, "fArray"=>$formatArraySpcH, "multiCols"=>$widthArraySpcH); $spacerRowHeight = getHtmlStr('GTMULTIW2', $spacerValsH); /*For height of blue spacer rows between TOTALS and AVERAGE rows */ $rowStyleTotSpacer = 'style="font-size:8px;"'; /*Total balance due with green background */ $rowStyleTotHeight = 'style="background-color:rgb(205, 220, 175); color:rgb(0, 102, 34); font-size:14px; font-weight:bold;"'; $spacerVals3 = array("numOthCols"=>"0", "col_0"=>" ", "rowStyle"=>$rowStyleTotHeight, "fArray"=>$formatArraySpcH, "multiCols"=>$widthArraySpcH); $spacerTotRowHeight = getHtmlStr('GTMULTIW2', $spacerVals3); /**********************END EMPTY SPACER ROWS WITH NO BORDERS*************/ $rowStyle9 = 'style="font-size:9px;"'; /**************************** BEGIN GET DATA FOR PAGE TITLE **************************/ /* Query for the org_name, school year and billing type. The last 2 go in the page title and the footer */ $schoolYearFmt = ''; $orgName = ''; $thisVendorName = ''; $thisContact = ''; $footerSuffix = ''; $sqlN = "SELECT org.org_name, looksy.school_year, vendOrg.org_name vendor_org, tbc.`First Name` contactName FROM billing_data_archive bda INNER JOIN organization org ON org.id = bda.org_id_ma INNER JOIN lkp_school_year looksy ON looksy.yr_id = bda.school_year INNER JOIN organization vendOrg ON vendOrg.id = bda.vendor_id LEFT JOIN tblContacts tbc ON tbc.org_id_contact = bda.org_id_ma AND tbc.decision_maker = 'Yes' WHERE bda.org_id_ma = ? AND bda.school_year = ? " . $addVendCrit . " GROUP BY org.org_name;"; /*********************/ /*Prepare stmt*/ $stmtN = $dbLink->prepare($sqlN); /*Bind the criteria param*/ if($rpt_type === 'Vendor'){ $stmtN->bind_param('idi', $recordId, $schoolYear, $thisVendor); } else{ $stmtN->bind_param('id', $recordId, $schoolYear); } /*Execute the stmt*/ $stmtN->execute(); /*Store result*/ $stmtN->store_result(); /*Check success*/ if($stmtN->num_rows > 0){ /*Bind results*/ $stmtN->bind_result($orgName, $schoolYearFmt, $thisVendorName, $thisContact); while($stmtN->fetch()){ if($rpt_type === 'Vendor'){ $footerSuffix = ' ' . $thisVendorName . ' '; } else{ $footerSuffix = ' ' . $orgName . ' '; } }#end while }#end if num_rows else{ /*For orgs that are upgraded early in the school year so there is no billing yet associated with the org, use current_devices instead of billing_data_archive*/ $sqlN = "SELECT org.org_name, (select school_year from lkp_school_year where yr_id = ?) schoolYearFmt, vendOrg.org_name vendor_org, tbc.`First Name` contactName FROM current_devices bda INNER JOIN organization org ON org.id = bda.org_id_ma INNER JOIN organization vendOrg ON vendOrg.id = bda.vendor_id LEFT JOIN tblContacts tbc ON tbc.org_id_contact = bda.org_id_ma AND tbc.decision_maker = 'Yes' WHERE bda.org_id_ma = ? " . $addVendCrit . " GROUP BY org.org_name;"; /*Prepare stmt*/ $stmtN = $dbLink->prepare($sqlN); /*Bind the criteria param*/ if($rpt_type === 'Vendor'){ $stmtN->bind_param('iii', $schoolYear, $recordId, $thisVendor); } else{ $stmtN->bind_param('ii', $schoolYear, $recordId); } /*Execute the stmt*/ $stmtN->execute(); /*Store result*/ $stmtN->store_result(); if($stmtN->num_rows > 0){ /*Bind results*/ $stmtN->bind_result($orgName, $schoolYearFmt, $thisVendorName, $thisContact); while($stmtN->fetch()){ if($rpt_type === 'Vendor'){ $footerSuffix = ' ' . $thisVendorName . ' '; } else{ $footerSuffix = ' ' . $orgName . ' '; } }#end while }#end if num_rows }//end else $billingCycle = 'Reconciliation'; /* Concat the string for the left side of the page footer */ $footerInformation = $schoolYearFmt . ' / ' . $billingCycle . ' / ' . $footerSuffix; /* SJH Commented out on 6/5/2020. I don't think it was working. This number is used on the layoutFunctions footer function to determine which page the numbering should start printing on. The annual report has a cover page and a cover letter that should have NO footer. The yearly_reconciliation has a cover letter that should have NO footer. $footerBeginPrintPg = 2; */ /**************************** END GET DATA FOR PAGE TITLE **************************/ /****************************BEGIN COVER LETTER ****************************/ $pdf->SetPrintFooter(true); 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/logo_spc.png', 4, 2, 43, 24, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false); /*Place Skip's signature by coordinates. */ /*vertical was change from 235 to 175 on 6/4/2020, which moved signature up on page.*/ $pdf->Image('images/skip.png', 48, 175, 50, 30, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false); /*getCoverPg in layoutFunctions.php will return the entire cover letter, but Skip's signature will need to be repositioned with the line above to align it with his closing.*/ $coverLetter = getCoverPg($thisContact); $coverLetterPage = <<writeHTML($coverLetterPage, false, true, false, false, ''); }#end if $addCoverLetter = 'Y' /******************************END COVER LETTER ****************************/ $pdf->setImageScale(1.00); $pdf->SetPrintHeader(true); $pdf->startPage('L'); /* ADD LOGO HEADER */ $pdf->Image('images/mst_Header.png', 0, 0, 300, 15, 'PNG', '', '', true, 150, '', false, false, 0, true, false, false); /******************* BEGIN CREATE PAGE TITLE ******************/ $formatArrayTitle = array("col_0"=>'style="font-size:12px; font-weight:bold; text-align:center;"'); $titleVals = array("numOthCols"=>0, "col_0"=>$orgName . '
' . $schoolYearFmt . ' / ' . $billingCycle . '
' . $ttl . '', "rowStyle"=>$rowStyleSpc, "fArray"=>$formatArrayTitle, "multiCols"=>$widthArraySpc); $titleStr = getHtmlStr('GTMULTIW2', $titleVals); /******************* END CREATE PAGE TITLE ******************/ /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameBk = createGroupHeader('Black Prints', 50, 685, ' color:rgb(0, 0, 0);', null); /********************** BEGIN CREATE BLACK TABLE HEADER *********************/ $rowStyleH = 'style="font-size:10px; font-weight:bold; color:rgb(0, 0, 0);"'; $widthArrayHeader = array("col_0"=>50, "col_1"=>180, "col_2"=>70, "col_3"=>15, "col_4"=>70, "col_5"=>15, "col_6"=>75, "col_7"=>10, "col_8"=>15, "col_9"=>75, "col_10"=>2, "col_11"=>65, "col_12"=>3, "col_13"=>15, "col_14"=>75, "col_15"=>10); $formatArrayHeader = array("col_0"=>'', "col_1"=>'style="border-bottom:1px solid black; text-align:left;"', "col_2"=>'style="border-bottom:1px solid black; text-align:center;"', "col_3"=>'style="border-bottom:1px solid black;"', "col_4"=>'style="border-bottom:1px solid black; border-right:1px solid black; text-align:center;"', "col_5"=>'style="border-bottom:1px solid black;"', "col_6"=>'style="border-bottom:1px solid black; text-align:center;"', "col_7"=>'style="border-bottom:1px solid black; border-right:2px solid black;"', "col_8"=>'style="border-bottom:1px solid black; text-align:center;"', "col_9"=>'style="border-bottom:1px solid black; text-align:center;"', "col_10"=>'style="border-bottom:1px solid black;"', "col_11"=>'style="border-bottom:1px solid black; text-align:center;"', "col_12"=>'style="border-bottom:1px solid black; border-right:1px solid black;"', "col_13"=>'style="border-bottom:1px solid black;"', "col_14"=>'style="border-bottom:1px solid black; text-align:center;"'); $thVals = array("numOthCols"=>14, "col_0"=>"", "col_1"=>" 
" . $grpBy, "col_2"=>"Full Year
Volume", "col_3"=>"", "col_4"=>"Pre-Paid
Volume", "col_5"=>"", "col_6"=>"Reconciled
Volume", "col_7"=>"", "col_8"=>"", "col_9"=>"Full Year
Costs", "col_10"=>"", "col_11"=>"Pre-Paid
Costs", "col_12"=>"", "col_13"=>"", "col_14"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeader, "multiCols"=>$widthArrayHeader, "cellPad"=>1); $tabHdr = getHtmlStr('GTMULTIW2', $thVals); /********************** END CREATE BLACK TABLE HEADER *********************/ /********************** MAIN CONTENT BLACK BEGIN SUM BY BLDG*********************/ /* These are here so all 3 report sections can use them. This will add cpc columns to the select string depending on whether the report is for a Client or Vendor*/ $cpcBlkStr = ''; $cpcColorStr = ''; $cpcBlkStrCd = ''; $cpcColorStrCd = ''; $addVendCriterion = ''; $sumAddCrit = ''; #This will have a different value based on the report type of Client or Vendor. $addCrit = ''; $sumAddCriterion = ''; /*This is because the alias on the summary page is different. The joins are different. Keep this. */ $curCol = ""; $sumWhereVend = ''; $grpCl = ""; $curJoin = ""; $vendJoin = ""; #This will be an additional join when the rpt_type is Vendor $detGroupBy = ''; /*This will be an additional group by col for use only in the client reports. There can be more than 1 vendor with the same type of copier, and without adding vendor to the group by the volumes for all of a specific type are lumped together into the last vendor in the resultset.*/ $addl_group = ""; $addl_groupCd = ""; /*If the report is Vendor type, then the vendor cpc values will be used for calculating costs. */ if($rpt_type === 'Vendor'){ $cpcBlkStr = "vendor_cpc_black"; $cpcColorStr = "vendor_cpc_color"; $cpcBlkStrCd = "`Black_Vendor_cpc`"; /*column in current_devices, Machine_Archive*/ $cpcColorStrCd = "`Color_Vendor_cpc`"; /*column in current_devices, Machine_Archive*/ /* If the report is for a Vendor, limit the resultset to only machines owned by that vendor. */ /* Add a join to the org table to get the vendor data */ $vendJoin = ' INNER JOIN organization vendOrg ON vendOrg.id = bda.vendor_id '; /* Machines are listed once for Client and once for Vendor in the bda table, so add this criterion to not dupe the records */ $addCrit = ' AND bda.billing_type = "Vendor" AND bda.vendor_id = ? '; $addVendCriterion = ' AND cd.vendor_id = ? '; /*This is because the alias on the summary page is different. The joins are different. The vendor join has a bind variable appended. Keep this. */ $sumAddCrit = ' AND bida.billing_type = "Vendor" AND vendOrg.id = ? '; $sumAddCriterion = ' AND bida.billing_type = "Vendor" '; $sumWhereVend = ' WHERE bda.vendor_id = ? '; $sumWhereVendCda = ' AND cda.vendor_id = ? '; $detGroupBy = ' bda.vendor_cpc_black, bda.vendor_cpc_color '; } /*If the report is Client type, then the client cpc values will be used for calculating costs. */ else{ $cpcBlkStr = "cpc_black"; $cpcColorStr = "cpc_color"; $cpcBlkStrCd = "`CostCopy`"; /*column in current_devices, Machine_Archive*/ $cpcColorStrCd = "`Mstrcpc`"; /*column in current_devices, Machine_Archive*/ /*Machines are listed once for Client and once for Vendor in the bda table, so add this criterion to not dupe the records */ $addCrit = ' AND bda.billing_type = "Client"'; /*This is because the alias on the summary page is different. The joins are different. The vendor join has a bind variable appended. Keep this. */ $sumAddCriterion = ' AND bida.billing_type = "Client" '; $sumAddCrit = ' AND bida.billing_type = "Client" '; $sumWhereVend = ''; $addl_group = ' , bda.vendor_id '; /*$addl_group = ' , bda.vendor_id_ma ';*/ $addl_groupCd = ' cda.vendor_id, '; $detGroupBy = ' bda.cpc_black, bda.cpc_color '; } $q = ''; /*This will be the query based on whether the $grpBy is Building or Department AND if it is for a client or vendor*/ /* prepare stmt */ if($grpBy === 'Building'){ /* Group by Building for Client type OR Vendor type report. */ $curCol = "building_name, ";#select this column also $grpCl = "building_name "; #group by this column //$grpCl = "id "; #group by this column $curJoin = " INNER JOIN buildings bldg_dept ON bldg_dept.id = cd.building_id_ma AND bldg_dept.org_id = cd.org_id_ma "; $curJoinCd = " INNER JOIN buildings bldg_dept ON bldg_dept.id = ma.building_id_ma AND bldg_dept.org_id = ma.org_id_ma "; } else{ /* Group by Department for Client type OR Vendor type report. */ $curCol = "dept_name, "; #Used for a different query. Keep both $grpCl = "dept_name "; #group by this column $curJoin = " INNER JOIN department bldg_dept ON bldg_dept.id = cd.dept_id_ma AND bldg_dept.org_id = ma.org_id_ma "; $curJoinCd = " INNER JOIN department bldg_dept ON bldg_dept.id = ma.dept_id_ma AND bldg_dept.org_id = ma.org_id_ma "; } /* Sum by Building or Department for Client type OR Vendor type report. When bda.billing_cycle != 10 it will get all bills for the year except the reconciliation. This criteria is needed because there can be > 1 prebill for the year and we need to include all prebilled charges in this report.*/ $q = 'SELECT allRows.' . $curCol . ' SUM(fy_bk_vols) fy_bk_vol, SUM(prepaid_bk_vols) prepaid_bk_vol, SUM(fy_black_costs) fy_bk_costs, SUM(prepaid_bk_costs) prepaid_bk_costs, SUM(fy_col_vols) fy_col_vol, SUM(prepaid_col_vols) prepaid_col_vol, SUM(fy_color_costs) fy_col_costs, SUM(prepaid_color_costs) prepaid_col_costs FROM (SELECT cda.'. $curCol . ' SUM(cda.fy_bk_vol) fy_bk_vols, 0 prepaid_bk_vols, SUM(cda.fy_bk_vol * cd.' . $cpcBlkStrCd . ') fy_black_costs, 0 prepaid_bk_costs, SUM(cda.fy_col_vol) fy_col_vols, 0 prepaid_col_vols, SUM(cda.fy_col_vol * cd.' . $cpcColorStrCd . ') fy_color_costs, 0 prepaid_color_costs FROM ' . $deviceTable . ' cd INNER JOIN (SELECT bldg_dept.' . $curCol . ' SUM(ma.`End` - ma.`Begin`) fy_bk_vol, SUM(ma.`MstrEnd` - ma.`MstrBegin`) fy_col_vol, ma.`SerialNumber`, ma.`EDate` end_date FROM ' . $deviceTable . ' ma INNER JOIN machines mach ON mach.id = ma.model_id ' . $curJoinCd . ' GROUP BY ma.`SerialNumber`, ma.`EDate`) cda ON cda.`SerialNumber` = cd.`SerialNumber` WHERE cd.`SerialNumber` IN(SELECT `SerialNumber` FROM current_devices cdv WHERE org_id_ma = ?) AND cd.SerialNumber NOT IN(SELECT bida.serial_number FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCrit . ' GROUP BY bida.serial_number) ' . $addVendCriterion . ' GROUP BY cda.' . $grpCl . ' UNION ALL SELECT cda.'. $curCol . ' SUM(cda.fy_bk_vol) fy_bk_vols, SUM(bda.prepaid_blk_vol) prepaid_bk_vols, SUM(cda.fy_bk_vol * bda.' . $cpcBlkStr . ') fy_black_costs, SUM(bda.prepaid_blk_costs) prepaid_bk_costs, SUM(cda.fy_col_vol) fy_col_vols, SUM(bda.prepaid_col_vol) prepaid_col_vols, SUM(cda.fy_col_vol * bda.' . $cpcColorStr . ') fy_color_costs, SUM(bda.prepaid_col_costs) prepaid_color_costs FROM (SELECT MAX(bida.billing_cycle), bida.serial_number, bida.vendor_id, bida.vendor_id_ma, vendOrg.org_name, bida.cpc_color, bida.cpc_black, bida.vendor_cpc_black, bida.vendor_cpc_color, bida.billing_type, bida.billing_cycle, bida.school_year, bida.org_id_ma, Sum(bida.billed_projected_volume_color) prepaid_col_vol, Sum(bida.billed_projected_volume_color * bida.' . $cpcColorStr . ') prepaid_col_costs, Sum(bida.billed_projected_volume_black) prepaid_blk_vol, Sum(bida.billed_projected_volume_black * bida.' . $cpcBlkStr . ') prepaid_blk_costs FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCrit . ' GROUP BY bida.serial_number) bda INNER JOIN (SELECT bldg_dept.' . $curCol . ' SUM(cd.`End` - cd.`Begin`) fy_bk_vol, SUM(cd.`MstrEnd` - cd.`MstrBegin`) fy_col_vol, cd.`SerialNumber`, cd.`EDate` end_date FROM ' . $deviceTable . ' cd INNER JOIN machines mach ON mach.id = cd.model_id ' . $curJoin . ' GROUP BY cd.`SerialNumber`, cd.`EDate`) cda ON cda.`SerialNumber` = bda.serial_number ' . $vendJoin . ' GROUP BY cda.' . $grpCl . ') allRows GROUP BY allRows.' . $grpCl . ';'; $stmt = $dbLink->prepare($q); /*Bind the criteria param*/ if($rpt_type == 'Vendor'){ $stmt->bind_param('iiiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $stmt->bind_param('iiiii', $recordId, $recordId, $schoolYear, $recordId, $schoolYear); } /*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*/ $mainContentB = ''; $mainContentC = ''; /*Bind results*/ $stmt->bind_result($gbName, $fy_bk_vol, $prepaid_bk_vol, $fy_bk_costs, $prepaid_bk_costs, $fy_col_vol, $prepaid_col_vol, $fy_col_costs, $prepaid_col_costs); /*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()){ /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$prepaid_bk_vol, "actbkvol"=>$fy_bk_vol, "ppbkcosts"=>$prepaid_bk_costs, "actbkcosts"=>$fy_bk_costs, "ppcolvol"=>$prepaid_col_vol, "actcolvol"=>$fy_col_vol, "ppcolcosts"=>$prepaid_col_costs, "actcolcosts"=>$fy_col_costs); /* Get the calculated vol and cost values along with the color for the text */ $aVals = getAllReconciledVals($arrayArgs); /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayBk = getSummaryFormatArray($aVals["textBkVol"], $aVals["textBkCst"]); /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTxtCol is appended to the format for col 1 in both the volumes row and the costs row. $colTxtCol is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTxtCol = getTextColor($fy_bk_vol); $colTxtCol = getTextColor($fy_col_vol); $contentArrayBk = array("numOthCols"=>10, "col_0"=>"", "col_1"=>$gbName, "col_2"=>'' . number_format($fy_bk_vol) . '', "col_3"=>number_format($prepaid_bk_vol), "col_4"=>"", "col_5"=>formatDec($aVals["recVolB"]), "col_6"=>"", "col_7"=>'$' . number_format($fy_bk_costs, 2) . '', "col_8"=>"$" . number_format($prepaid_bk_costs, 2), "col_9"=>"", "col_10"=>formatCurrency($aVals["recCostB"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayH, "cellPad"=>1); /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayCol = getSummaryFormatArray($aVals["textColVol"], $aVals["textColCst"]); $contentArrayCol = array("numOthCols"=>10, "col_0"=>"", "col_1"=>$gbName, "col_2"=>'' . number_format($fy_col_vol) . '', "col_3"=>number_format($prepaid_col_vol), "col_4"=>"", "col_5"=>formatDec($aVals["recVolC"]), "col_6"=>"", "col_7"=>'$' . number_format($fy_col_costs, 2) . '', "col_8"=>"$" . number_format($prepaid_col_costs, 2), "col_9"=>"", "col_10"=>formatCurrency($aVals["recCostC"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayCol, "multiCols"=>$widthArrayH, "cellPad"=>1); /*Increment the totals for the group total footer*/ $totBkProjVol = $totBkProjVol + $fy_bk_vol; $totBkProjChg = $totBkProjChg + $fy_bk_costs; $totBkPBVol = $totBkPBVol + $prepaid_bk_vol; $totBkPBChg = $totBkPBChg + $prepaid_bk_costs; $totColProjVol = $totColProjVol + $fy_col_vol; $totColProjChg = $totColProjChg + $fy_col_costs; $totColPBVol = $totColPBVol + $prepaid_col_vol; $totColPBChg = $totColPBChg + $prepaid_col_costs; /*Send black and color arrays separately to the getHtmlStr function so it can compose the main content for each group*/ $mainBlack = $mainBlack . getHtmlStr('GTMULTIW2', $contentArrayBk); $mainColor = $mainColor . getHtmlStr('GTMULTIW2', $contentArrayCol); }#end while /*Assign the Black and Color Combined Totals to vars. These vals will go on the TOTALS footer, which displays the combined totals for black and color*/ $projectVol = $totBkProjVol + $totColProjVol; $projectChg = $totBkProjChg + $totColProjChg; $prebillVol = $totBkPBVol + $totColPBVol; $prebillChg = $totBkPBChg + $totColPBChg; }#end if num_rows /********************** SUM BY BLDG MAIN CONTENT BLACK END *****************/ else{ $msgConstruct = getRptNoDataMessage("There was no data for a yearly reconciliation report matching your criteria.", "P"); $pdf->writeHTML($msgConstruct, true, true, false, false, ''); } /*Close the db connection*/ $stmt->close(); /*********************** BLACK GROUP TOTALS FOOTER BEGIN***********************/ /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$totBkPBVol, "actbkvol"=>$totBkProjVol, "ppbkcosts"=>$totBkPBChg, "actbkcosts"=>$totBkProjChg, "ppcolvol"=>$totColPBVol, "actcolvol"=>$totColProjVol, "ppcolcosts"=>$totColPBChg, "actcolcosts"=>$totColProjChg); $totVals = getAllReconciledVals($arrayArgs); $rowStyleF = 'style="font-size:10px; font-weight:bold;"'; /*Call getSummaryFormatArray to get the format using the colors for vol and cost. Pass the variable with the desired background-color. */ $backgroundColor = 'background-color:rgb(222, 235, 247);'; $formatArrayBk = getSummaryFormatArray($totVals["textBkVol"], $totVals["textBkCst"], $backgroundColor); /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTxtColSub is appended to the format for col 1 in both the volumes row and the costs row. $colTxtColSub is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTxtColSub = getTextColor($totBkProjVol); $colTxtColSub = getTextColor($totColProjVol); $bfVals = array("numOthCols"=>10, "col_0"=>'', "col_1"=>"Black Prints Totals", "col_2"=>'' . number_format($totBkProjVol) . '', "col_3"=>number_format($totBkPBVol), "col_4"=>"", "col_5"=>formatDec($totVals["recVolB"]), "col_6"=>"", "col_7"=>'$' . number_format($totBkProjChg, 2) . '', "col_8"=>"$" . number_format($totBkPBChg, 2), "col_9"=>"", "col_10"=>formatCurrency($totVals["recCostB"]), "rowStyle"=>$rowStyleF, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayH, "cellPad"=>1); $totBlack = getHtmlStr('GTMULTIW2', $bfVals); /********************** BLACK GROUP TOTALS FOOTER END *********************/ /* CREATE COLOR GROUP TITLE */ /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameCol = createGroupHeader('Color Prints', 50, 685, ' color:rgb(35, 114, 239);', null); /********************** BEGIN SUMMARY BY BLDG COLOR ***********************/ $thVals = array("numOthCols"=>14, "col_0"=>"", "col_1"=>" 
" . $grpBy, "col_2"=>"Full Year
Volume", "col_3"=>"", "col_4"=>"Pre-Paid
Volume", "col_5"=>"", "col_6"=>"Reconciled
Volume", "col_7"=>"", "col_8"=>"", "col_9"=>"Full Year
Costs", "col_10"=>"", "col_11"=>"Pre-Paid
Costs", "col_12"=>"", "col_13"=>"", "col_14"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeader, "multiCols"=>$widthArrayHeader, "cellPad"=>1); $tabHdrCol = getHtmlStr('GTMULTIW2', $thVals); /*Call getSummaryFormatArray to get the format using the colors for vol and cost. Pass the variable with the desired background-color. */ $backgroundColor = 'background-color:rgb(222, 235, 247);'; $formatArrayCol = getSummaryFormatArray($totVals["textColVol"], $totVals["textColCst"], $backgroundColor); $cfVals = array("numOthCols"=>10, "col_0"=>"", "col_1"=>"Color Prints Totals", "col_2"=>'' . number_format($totColProjVol) . '', "col_3"=>number_format($totColPBVol), "col_4"=>"", "col_5"=>formatDec($totVals["recVolC"]), "col_6"=>"", "col_7"=>'$' . number_format($totColProjChg, 2) . '', "col_8"=>"$" . number_format($totColPBChg, 2), "col_9"=>"", "col_10"=>formatCurrency($totVals["recCostC"]), "rowStyle"=>$rowStyleF, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArrayCol, "multiCols"=>$widthArrayH, "cellPad"=>1); $totColor = getHtmlStr('GTMULTIW2', $cfVals); /********************** END SUMMARY BY BLDG COLOR*********************/ /********************** SUMMARY BY BUILDING TOTALS FOOTER BEGIN*****************/ $combinedGrpTotRecVol = $totVals["recVolB"] + $totVals["recVolC"]; $combinedGrpTotRecCost = $totVals["recCostB"] + $totVals["recCostC"]; $avg_cost_per_print = $projectChg / $projectVol; $formatArrayTot = array("col_0"=>'', "col_1"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_2"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_3"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_4"=>'style="border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_5"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_6"=>'style="border-right:2px solid white; background-color:rgb(31, 78, 121);"', "col_7"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_8"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_9"=>'style="border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_10"=>'style="text-align:right; background-color:rgb(31, 78, 121);"'); $grpTotVals = array("numOthCols"=>10, "col_0"=>"", "col_1"=>"TOTALS:", "col_2"=>number_format($projectVol), "col_3"=>number_format($prebillVol), "col_4"=>"", "col_5"=>formatDec($combinedGrpTotRecVol), "col_6"=>"", "col_7"=>"$" . number_format($projectChg, 2), "col_8"=>"$" . number_format($prebillChg, 2), "col_9"=>"", "col_10"=>formatCurrency($combinedGrpTotRecCost), "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayTot, "multiCols"=>$widthArrayH, "cellPad"=>1); $invTot = getHtmlStr('GTMULTIW2', $grpTotVals); /* Spacer row between totals and average rows */ $totSpacerVals = array("numOthCols"=>"3", "col_0"=>"", "col_1"=>"", "col_2"=>"", "col_3"=>"", "rowStyle"=>$rowStyleTotSpacer, "fArray"=>$formatArrayAvg, "multiCols"=>$widthArrayAvg); $spacerRowCol = getHtmlStr('GTMULTIW2', $totSpacerVals); $avgCost = array("numOthCols"=>3, "col_0"=>"", "col_1"=>"Average Cost Per Print For Black & Color:", "col_2"=>"$" . number_format($avg_cost_per_print, 5), "col_3"=>"", "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayAvg, "multiCols"=>$widthArrayAvg, "cellPad"=>2); $aCost = getHtmlStr('GTMULTIW2', $avgCost); /*Begin covid-19 additional note SJH Added 6/30/2020 - due to covid-19 */ $creditBalText = "* If there is a credit balance, it will be applied to next year's pre-billing, which should be forthcoming in July."; $formatArrayCredBal = array("col_0"=>'style="color:red; font-size:12px; font-weight:normal; text-align:center;"'); $widthArrayCredBal = array("col_0"=>735); $creditBalVals = array("numOthCols"=>0, "col_0"=>$creditBalText, "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayCredBal, "multiCols"=>$widthArrayCredBal); $creditBal = getHtmlStr('GTMULTIW2', $creditBalVals); /*End covid-19 additional note*/ /* Print the entire page */ $avgCostFooter = <<writeHTML($avgCostFooter, true, false, true, false, ''); /********************* SUMMARY BY BUILDING TOTALS FOOTER END ********************/ /********************** BEGIN FULL YEAR RECONCILIATION HERE *********************/ # 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 the Title font. $pdf->SetFont('helvetica', 'B', 14); # Title Name of Organization. $pdf->Write(0, $orgName . ' - By Machine', '', 0, 'C', true, 0, false, false, 0); # set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } /************ BEGIN ARRAYS AND VARIABLES USED IN RECONCILIATION DETAILS SECTION **************/ /*FOOTER TITLE ROW*/ $formatArrayT = array("col_0"=>'style="text-align:left;"'); $widthArrayT = array("col_0"=>940); /*FOOTER CONTENT*/ $formatArrayHdr = array("col_0"=>'style="border-bottom:1px solid #595959; text-align:left;"', "col_1"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_2"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_3"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_4"=>'style="border-bottom:1px solid #595959; border-right:2px solid #595959;"', "col_5"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_6"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_7"=>'style="border-bottom:1px solid #595959; text-align:right;"', "col_8"=>'style="border-bottom:1px solid #595959; border-right:2px solid #595959;"', "col_9"=>'style="border-bottom:1px solid #595959; text-align:right;"'); $widthArrayS = array("col_0"=>60, "col_1"=>130, "col_2"=>130, "col_3"=>130, "col_4"=>5, "col_5"=>105, "col_6"=>130, "col_7"=>120, "col_8"=>5, "col_9"=>125); $rowStyleN = 'style="background-color:rgb(216, 216, 216); font-size:12px; font-weight:normal;"'; $rowStyleB = 'style="background-color:rgb(216, 216, 216); color:rgb(70, 70, 70); font-size:12px; font-weight:bold;"'; $rowStyleGTB = 'style="background-color:rgb(205, 220, 175); color:rgb(70, 70, 70); font-size:12px; font-weight:bold;"'; $rowStyleGTN = 'style="background-color:rgb(205, 220, 175); color:rgb(0, 0, 0); font-size:12px; font-weight:normal;"'; $rowStyleTGT = 'style="background-color:rgb(205, 220, 175); color:rgb(0, 102, 34); font-size:14px; font-weight:bold;"'; $subTotHdr = array("numOthCols"=>9, "col_0"=>"", "col_1"=>"Actual Black", "col_2"=>"Pre-Paid Black", "col_3"=>"Reconciled Black", "col_4"=>"", "col_5"=>"Actual Color", "col_6"=>"Pre-Paid Color", "col_7"=>"Reconciled Color", "col_8"=>"", "col_9"=>"Reconciled Total", "rowStyle"=>$rowStyleB, "fArray"=>$formatArrayHdr, "multiCols"=>$widthArrayS); $grandTotHdr = array("numOthCols"=>9, "col_0"=>"", "col_1"=>"Actual Black", "col_2"=>"Pre-Paid Black", "col_3"=>"Reconciled Black", "col_4"=>"", "col_5"=>"Actual Color", "col_6"=>"Pre-Paid Color", "col_7"=>"Reconciled Color", "col_8"=>"", "col_9"=>"Reconciled Total", "rowStyle"=>$rowStyleGTB, "fArray"=>$formatArrayHdr, "multiCols"=>$widthArrayS); $titleRowVals2 = array("numOthCols"=>0, "col_0"=>"TOTALS", "rowStyle"=>$rowStyleTGT, "fArray"=>$formatArrayT, "multiCols"=>$widthArrayT); #for specs section $formatArraySpecs = array("col_0"=>'style="border-top:1px solid black; border-left:1px solid black; font-weight:bold; text-align:left;"', "col_1"=>'style="border-top:1px solid black; font-weight:normal; text-align:center;"', "col_2"=>'style="border-top:1px solid black; border-right:1px solid black;"'); $rowStyleSpecs = 'style="background-color:rgb(214, 223, 236); font-size:12px;"'; $widthArraySpecs = array("col_0"=>235, "col_1"=>470, "col_2"=>235); $formatArraySerNum = array("col_0"=>'style="border-bottom:1px solid black; border-left:1px solid black; font-weight:bold; text-align:left;"', "col_1"=>'style="border-bottom:1px solid black; font-weight:normal; text-align:center;"', "col_2"=>'style="border-bottom:1px solid black; border-right:1px solid black;"'); $formatArraySpacerSpecs = array("col_0"=>'style="border-left:1px solid black;"', "col_1"=>"", "col_2"=>'style="border-right:1px solid black;"'); $spacerSpecsVals = array("numOthCols"=>2, "col_0"=>"", "col_1"=>"", "col_2"=>"", "rowStyle"=>$rowStyleSpecs, "fArray"=>$formatArraySpacerSpecs, "multiCols"=>$widthArraySpecs); $spacerSpecs = getHtmlStr('GTMULTIW2', $spacerSpecsVals); $formatArrayMtr = array("col_0"=>'', "col_1"=>'style="text-align:right; font-weight:normal;"', "col_2"=>'style="text-align:right; font-weight:normal;"', "col_3"=>'style="text-align:right; font-weight:normal;"', "col_4"=>'style="text-align:right; border-right:2px solid #595959;"', "col_5"=>'style="text-align:right; font-weight:normal;"', "col_6"=>'style="text-align:right; font-weight:normal;"', "col_7"=>'style="text-align:right; font-weight:normal;"', "col_8"=>'style="text-align:right; font-weight:normal;"', "col_9"=>'style="text-align:right; font-weight:normal;"'); $rowStyleMtr = ''; $widthArrayMtr = array("col_0"=>20, "col_1"=>140, "col_2"=>140, "col_3"=>140, "col_4"=>15, "col_5"=>150, "col_6"=>150, "col_7"=>150, "col_8"=>20); $formatArrayDetails = array("col_0"=>'style="border-bottom:2px solid #595959;"', "col_1"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_2"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_3"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_4"=>'style="text-align:right; font-weight:bold; border-right:2px solid #595959; border-bottom:2px solid #595959;"', "col_5"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_6"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_7"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"', "col_8"=>'style="text-align:right; font-weight:bold; border-right:2px solid #595959; border-bottom:2px solid #595959;"', "col_9"=>'style="text-align:right; font-weight:bold; border-bottom:2px solid #595959;"'); $rowStyleDetails = 'style="color:rgb(89, 89, 89); font-size:12px;"'; $widthArrayDetails = array("col_0"=>60, "col_1"=>130, "col_2"=>130, "col_3"=>130, "col_4"=>5, "col_5"=>105, "col_6"=>130, "col_7"=>120, "col_8"=>5, "col_9"=>125); $detailsHeaderVals = array("numOthCols"=>9,"col_0"=>"", "col_1"=>"Actual Black", "col_2"=>"Pre-Paid Black", "col_3"=>"Reconciled Black", "col_4"=>"", "col_5"=>"Actual Color", "col_6"=>"Pre-Paid Color", "col_7"=>"Reconciled Color", "col_8"=>"", "col_9"=>"Reconciled Total", "rowStyle"=>$rowStyleDetails, "fArray"=>$formatArrayDetails, "multiCols"=>$widthArrayDetails); $detailsHeader = getHtmlStr('GTMULTIW2', $detailsHeaderVals); /************ END ARRAYS AND VARIABLES USED IN RECONCILIATION DETAILS SECTION **************/ $detailRecCount = 1; /*This will be the query based on whether the $grpBy is Building or Department AND if it is for a client or vendor*/ $qA = 'SELECT * FROM (SELECT bldg_dept.' . $curCol . ' cd.room_name, concat(mach.make," ", mach.model) MakeModel, cd.SerialNumber serial_number, `VendorMachID` vendor_mach_id, (cd.`End` - cd.`Begin`) fy_bk_vol, 0 bpv_blk, cd.CostCopy cpc_black, 0 pb_blk_cost, cd.`MstrEnd` - cd.`MstrBegin` fy_col_vol, 0 bpv_col, cd.Mstrcpc cpc_color, 0 pb_col_cost, cd.Black_Vendor_cpc vendor_cpc_black, cd.Color_Vendor_cpc vendor_cpc_color, cd.`Begin` begin_meter_black, cd.`End` end_meter_black, cd.`MstrBegin` begin_meter_color, cd.`MstrEnd` end_meter_color, UPPER(cd.`Traded`) traded, UPPER(cd.`Moved`) moved, UPPER(cd.`Meter Reset`) meter_reset, DATE_FORMAT(cd.`EDate`, "%m/%d/%Y") end_dt, cd.`Storage` in_storage FROM ' . $deviceTable . ' cd INNER JOIN machines mach ON mach.id = cd.model_id ' . $curJoin . ' WHERE cd.SerialNumber IN(SELECT SerialNumber FROM current_devices WHERE org_id_ma = ?) AND cd.SerialNumber NOT IN(SELECT bida.serial_number FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCrit . ' GROUP BY bida.serial_number) AND cd.org_id_ma = ? ' . $addVendCriterion . ' UNION ALL SELECT cda.' . $curCol . ' bda.room_name, concat(cda.Make," ", cda.model) AS MakeModel, cda.SerialNumber, bda.vendor_mach_id, cda.fy_bk_vol, SUM(bda.billed_projected_volume_black) bpv_blk, bda.cpc_black, SUM(bda.billed_projected_volume_black * ' . $cpcBlkStr . ') pb_blk_cost, cda.fy_col_vol, SUM(bda.billed_projected_volume_color) bpv_col, bda.cpc_color, SUM(bda.billed_projected_volume_color * ' . $cpcColorStr . ') pb_col_cost, bda.vendor_cpc_black, bda.vendor_cpc_color, cda.`Begin` begin_meter_black, cda.`End` end_meter_black, cda.`MstrBegin` begin_meter_color, cda.`MstrEnd` end_meter_color, cda.traded, cda.moved, cda.meter_reset, DATE_FORMAT(cda.end_dt, "%m/%d/%Y") end_dt, cda.in_storage FROM billing_data_archive bda ' . $vendJoin . ' INNER JOIN (SELECT bldg_dept.' . $curCol . ' mach.make, mach.model, cd.org_id_ma, cd.`Begin`, cd.`End`, cd.`MstrBegin`, cd.`MstrEnd`, SUM(cd.`End` - cd.`Begin`) fy_bk_vol, SUM(cd.`MstrEnd` - cd.`MstrBegin`) fy_col_vol, cd.SerialNumber, UPPER(cd.Traded) traded, UPPER(cd.Moved) moved, UPPER(`Meter Reset`) meter_reset, cd.`EDate` end_dt, cd.`Storage` in_storage FROM ' . $deviceTable . ' cd INNER JOIN machines mach ON mach.id = cd.model_id ' . $curJoin . ' GROUP BY cd.SerialNumber, cd.`EDate`) cda ON cda.SerialNumber = bda.serial_number AND cda.org_id_ma = bda.org_id_ma WHERE bda.org_id_ma = ? AND bda.billing_cycle != 10 AND bda.school_year = ? ' . $addCrit . ' GROUP BY cda.SerialNumber) allRows ORDER BY allRows.' . $curCol . ' allRows.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 is the current building or department name. This will only = the $building or department name after the header has printed and before the footer has printed*/ $gbName = ''; $groupByName = ''; $curSerNum = ''; $newCpc = 'N'; /*This will be set to y after a building or department header has printed */ $footerFlag = 'n'; $totalBillVol = ''; # Cost $actualBlkCost = ''; $prepaidBlkCost = ''; $actualColorCost = ''; $prepaidColorCost = ''; $totalBillCost = ''; # cpc $cpcBlk = ''; $cpcColor = ''; # Total Black and Color Volumes $totBlackVol = 0; $totPreBlackVol = 0; $totColVol = 0; $totPreColVol = 0; $TotalPBVolume = 0; # Total Black and Color Cost $TotalBlackCost = 0; $TotalPBBlackCost = 0; $TotalColorCost = 0; $TotalPBColorCost = 0; $TPBCost = 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; if($sql = $dbLink->prepare($qA)) { // assuming $mysqli is the connection /*Bind the criteria param based on whether this is a Vendor report or Client report. */ if($rpt_type == 'Vendor'){ $sql->bind_param('iiiiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $recordId, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $sql->bind_param('iiiiii', $recordId, $recordId, $schoolYear, $recordId, $recordId, $schoolYear); } $sql->execute(); // any additional code you need would go here. } else { //$error = $dbLink->errno . ' ' . $dbLink->error; $error = "There is an error in this report. Please contact IT support."; echo $error; // 1054 Unknown column 'foo' in 'field list' } /*Set the font for the table header*/ $pdf->SetFont('helvetica', '', 10); /*Store result*/ $sql->store_result(); /*Check success*/ if($sql->num_rows > 0){ /*Bind results*/ if($grpBy == 'Building'){ $sql->bind_result($buildingName, $room, $makeModel, $serialNum, $vendorMa, $actualBlkVol, $prepaidBlkVol, $cpcBlk_c, $pb_blk_cost, $actualColVol, $prepaidColVol, $cpcColor_c, $pb_col_cost, $vendor_cpc_black, $vendor_cpc_color, $begin_meter_bk, $end_meter_bk, $begin_meter_col, $end_meter_col, $traded, $moved, $meter_reset, $end_dt, $storage); } else{ $sql->bind_result($dept_name, $room, $makeModel, $serialNum, $vendorMa, $actualBlkVol, $prepaidBlkVol, $cpcBlk_c, $pb_blk_cost, $actualColVol, $prepaidColVol, $cpcColor_c, $pb_col_cost, $vendor_cpc_black, $vendor_cpc_color, $begin_meter_bk, $end_meter_bk, $begin_meter_col, $end_meter_col, $traded, $moved, $meter_reset, $end_dt, $storage); } while($sql->fetch()){ /*If the current serial number is the same as the previous one, then $newCpc = Y. The reason for this is that we do not want the totals printing a second time in the recon report. This will make it so that the first time the serial number is printed, the totals will be assigned to that record. The 2nd listing will only show the meter reads and the new cpc, but no totals for vol or cost. */ if($curSerNum === $serialNum){ $actualBlkVol = 0; $actualColVol = 0; $newCpc = 'Y'; } else{ $curSerNum = $serialNum; } $trade_move_reset = ''; $detailRecCount += 1; if($grpBy == 'Building'){ $groupByName = $buildingName; } else{ $groupByName = $dept_name; } if($rpt_type == 'Vendor'){ $cpcBlk = $vendor_cpc_black; $cpcColor = $vendor_cpc_color; } else{ $cpcBlk = $cpcBlk_c; $cpcColor = $cpcColor_c; } if($traded === 'Y' || $moved === 'Y' || $meter_reset === 'Y' || $storage === 'Y' || $newCpc === 'Y'){ /* This will be a concatenated string for display under the building name in the details section only if the machine has Y in the current_devices table in columns Traded, Moved, Reset, or Storage. This value will change for each record. */ $trade_move_reset = ''; if($traded === 'Y'){ $trade_move_reset .= "Machine Traded "; } if($moved === 'Y'){ $trade_move_reset .= "Machine Moved "; } if($meter_reset === 'Y'){ $trade_move_reset .= "Meter Reset "; } /*Add the end_dt to the string and close the span*/ $trade_move_reset .= $end_dt . ""; /* if storage = Y or it is a new cpc, no end_dt is needed, so do not concat just assign the value*/ if($storage === 'Y'){ $trade_move_reset = 'Storage'; } if($newCpc === 'Y'){ $trade_move_reset = 'CPC correction - actual vol is only in 1st record.'; $newCpc = 'N'; } }//end while $totalBillVol = $prepaidBlkVol + $prepaidColVol; #Costs $actualBlkCost = $actualBlkVol * $cpcBlk; $prepaidBlkCost = $pb_blk_cost; #$prepaidBlkVol * $cpcBlk; $actualColorCost = $actualColVol * $cpcColor; $prepaidColorCost = $pb_col_cost; #$prepaidColVol * $cpcColor; $totalBillCost = ($prepaidBlkVol * $cpcBlk) +($prepaidColVol * $cpcColor); /*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.*/ /*This is the array of sub total data.*/ $val = array("bn"=>$gbName, "actBkVol"=>$totBlackVol, "ppBkVol"=>$totPreBlackVol, "actColVol"=>$totColVol, "ppColVol"=>$totPreColVol, "actBkCost"=>$TotalBlackCost, "ppBkCost"=>$TotalPBBlackCost, "actColCost"=>$TotalColorCost, "ppColCost"=>$TotalPBColorCost); # Sub Totals to be incremented # First row Total Volumes for Building Footer. $totBlackVol = ($totBlackVol + $actualBlkVol); $totPreBlackVol = ($totPreBlackVol + $prepaidBlkVol); $totColVol= ($totColVol + $actualColVol); $totPreColVol = ($totPreColVol + $prepaidColVol); $TotalPBVolume = $TotalPBVolume + ($prepaidBlkVol + $prepaidColVol); # Second row Total Cost for Building Footer - calculated and incremented totals. $TotalBlackCost = $TotalBlackCost + $actualBlkVol * $cpcBlk; $TotalPBBlackCost = $TotalPBBlackCost + $prepaidBlkVol * $cpcBlk; $TotalColorCost = $TotalColorCost + $actualColVol * $cpcColor; $TotalPBColorCost = $TotalPBColorCost + $prepaidColVol * $cpcColor; #grand totals for end of report $gtBlkVol = ($gtBlkVol + $actualBlkVol); $gtPBBlkVol = ($gtPBBlkVol + $prepaidBlkVol); $gtColVol = $gtColVol + $actualColVol; $gtPBColVol = $gtPBColVol + $prepaidColVol; $gtTotPBVol = $gtTotPBVol + ($prepaidBlkVol + $prepaidColVol); $gtBlkCost = $gtBlkCost + $actualBlkVol * $cpcBlk; $gtPBBlkCost = $gtPBBlkCost + $prepaidBlkVol * $cpcBlk; $gtColCost = $gtColCost + $actualColVol * $cpcColor; $gtPBColCost = $gtPBColCost + $prepaidColVol * $cpcColor; $gtTotPBCost = $gtTotPBCost + (($actualBlkVol * $cpcBlk) + ($actualColVol * $cpcColor)); $machData = array("bn"=>$groupByName, "room"=>$room, "mkmo"=>$makeModel, "serial"=>$serialNum, "actBkVol"=>$actualBlkVol, "ppBkVol"=>$prepaidBlkVol, "actColVol"=>$actualColVol, "ppColVol"=>$prepaidColVol, "actBkCost"=>$actualBlkCost, "ppBkCost"=>$prepaidBlkCost, "actColCost"=>$actualColorCost, "ppColCost"=>$prepaidColorCost, "serial"=>$serialNum, "vend"=>$vendorMa, "cpcblk"=>$cpcBlk, "cpccol"=>$cpcColor, "start_read_bk"=>$begin_meter_bk, "end_read_bk"=>$end_meter_bk, "start_read_col"=>$begin_meter_col, "end_read_col"=>$end_meter_col); /*********BEGIN CONSTRUCT THE SPECS SECTION HERE FOR ALL CONDITIONALS***************/ /*Create all 3 parts of the spec section*/ $nameSpecs = array("numOthCols"=>2, "col_0"=>" " . $machData["bn"], "col_1"=>"Location: " . $machData["room"] . '  -   Make Model:' . $machData["mkmo"], "col_2"=>"", "rowStyle"=>$rowStyleSpecs, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArraySpecs, "multiCols"=>$widthArraySpecs); $serNumSpecs = array("numOthCols"=>2, "col_0"=>$trade_move_reset, "col_1"=>"Serial Number: " . $machData["serial"] . '  Vendor ID:' . $machData["vend"], "col_2"=>"", "rowStyle"=>$rowStyleSpecs, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArraySerNum, "multiCols"=>$widthArraySpecs); $meterReads = array("numOthCols"=>8, "col_0"=>"", "col_1"=>"Start Read: " . number_format($machData["start_read_bk"]), "col_2"=>"End Read: " . number_format($machData["end_read_bk"]), "col_3"=>"Black CPC: $" . number_format($machData["cpcblk"], 5), "col_4"=>"", "col_5"=>"Start Read: " . number_format($machData["start_read_col"]), "col_6"=>"End Read: " . number_format($machData["end_read_col"]), "col_7"=>"Color CPC: $" . number_format($machData["cpccol"], 5), "col_8"=>"", "rowStyle"=>$rowStyleMtr, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArrayMtr, "multiCols"=>$widthArrayMtr); /*call the getHtmlStr function to construct all 3 sections of the specs content*/ $nameSpecsRow = getHtmlStr('GTMULTIW2', $nameSpecs); $serNumSpecsRow = getHtmlStr('GTMULTIW2', $serNumSpecs); $meterRow = getHtmlStr('GTMULTIW2', $meterReads); /************END CONSTRUCT THE SPECS SECTION HERE FOR ALL CONDITIONALS*******/ /*****************BEGIN RECONCILED TOTAL VOLUME AND COSTS********************/ /* Calculate the reconciled totals for volume and cost */ $recTotVol = ($machData["actBkVol"] - $machData["ppBkVol"]) + ($machData["actColVol"] - $machData["ppColVol"]); $recTotCost = ($machData["actBkCost"] - $machData["ppBkCost"]) + ($machData["actColCost"] - $machData["ppColCost"]); $totVolTextC = getTextColor($recTotVol); $totCostTextC = getTextColor($recTotCost); /*****************END RECONCILED TOTAL VOLUME AND COSTS********************/ $arrayArgs = array("ppbkvol"=>$machData["ppBkVol"], "actbkvol"=>$machData["actBkVol"], "ppbkcosts"=>$machData["ppBkCost"], "actbkcosts"=>$machData["actBkCost"], "ppcolvol"=>$machData["ppColVol"], "actcolvol"=>$machData["actColVol"], "ppcolcosts"=>$machData["ppColCost"], "actcolcosts"=>$machData["actColCost"]); $rcVals = getAllReconciledVals($arrayArgs); $rowStyleDetailsContent = 'style="color:rgb(0, 0, 0); font-size:12px;"'; /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTextCol is appended to the format for col 1 in both the volumes row and the costs row. $colTextCol is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTextCol = getTextColor($machData["actBkVol"]); $colTextCol = getTextColor($machData["actColVol"]); /*format for volumes data*/ $formatArrayDetailsContent = array( "col_0"=>'style="text-align:left; font-weight:bold; color:#595959; border-bottom:.5px solid #595959;"', "col_1"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $bkTextCol . '"', "col_2"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;"', "col_3"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $rcVals["textBkVol"] . '"', "col_4"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959; border-right:2px solid #595959;"', "col_5"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $colTextCol . '"', "col_6"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;"', "col_7"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $rcVals["textColVol"] . '"', "col_8"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959; border-right:2px solid #595959;"', "col_9"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $totVolTextC . '"'); /*format for cost data*/ $formatArrayDetailsContentC = array( "col_0"=>'style="text-align:left; font-weight:bold; color:#595959; border-bottom:.5px solid #595959;"', "col_1"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $bkTextCol . '"', "col_2"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;"', "col_3"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $rcVals["textBkCst"] . '"', "col_4"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959; border-right:2px solid #595959;"', "col_5"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $colTextCol . '"', "col_6"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;"', "col_7"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $rcVals["textColCst"] . '"', "col_8"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959; border-right:2px solid #595959;"', "col_9"=>'style="text-align:right; font-weight:normal; border-bottom:.5px solid #595959;' . $totCostTextC . '"'); $detContentVols = array("numOthCols"=>9,"col_0"=>"Volumes:", "col_1"=>number_format($machData["actBkVol"]), "col_2"=>number_format($machData["ppBkVol"]), "col_3"=>formatDec($rcVals["recVolB"]), "col_4"=>"", "col_5"=>number_format($machData["actColVol"]), "col_6"=>number_format($machData["ppColVol"]), "col_7"=>formatDec($rcVals["recVolC"]), "col_8"=>"", "col_9"=>formatDec($recTotVol), "rowStyle"=>$rowStyleDetailsContent, "fArray"=>$formatArrayDetailsContent, "multiCols"=>$widthArrayDetails, "cellPad"=>2); $detContentCosts = array("numOthCols"=>9,"col_0"=>"Costs:", "col_1"=>"$" . number_format($machData["actBkCost"], 2), "col_2"=>"$" . number_format($machData["ppBkCost"], 2), "col_3"=>formatCurrency($rcVals["recCostB"]), "col_4"=>"", "col_5"=>"$" . number_format($machData["actColCost"], 2), "col_6"=>"$" . number_format($machData["ppColCost"], 2), "col_7"=>formatCurrency($rcVals["recCostC"]), "col_8"=>"", "col_9"=>formatCurrency($recTotCost), "rowStyle"=>$rowStyleDetailsContent, "fArray"=>$formatArrayDetailsContentC, "multiCols"=>$widthArrayDetails, "cellPad"=>2); $titleRowVals = array("numOthCols"=>0, "col_0"=>"SUBTOTALS for  " . $gbName, "rowStyle"=>$rowStyleT, "alignLead"=>"left", "alignOth"=>"", "fArray"=>$formatArrayT, "multiCols"=>$widthArrayT); $detailsContentVol = getHtmlStr('GTMULTIW2', $detContentVols); $detailsContentCost = getHtmlStr('GTMULTIW2', $detContentCosts); /* Begin constructing the report layout by $grouByName and whether or not the footerFlag is y or n. A flag of n means that this is the very first record, so print the building specs header then print the content, but NO footer yet. */ if( $gbName != $groupByName && $footerFlag === 'n'){ $tblDetails = <<writeHTML($tblDetails, false, true, false, false, ''); /*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); }#end if $groupByName != $gbName /* If the building name equals the variable $gbName then continue printing the specs header and machine data for this building. No footer */ else if($gbName == $groupByName){ $tblDetails = << 5){ /* 5 records including footers have been printed, so add a page and reset the count to 1. */ $pdf->AddPage('L'); $detailRecCount = 1; } $pdf->writeHTML($tblDetails, false, true, false, false, ''); }#end else if $groupByName == $gbName /*This is a record for a new group and it is not the first group, so add a footer for the previous group BEFORE adding the content for the new group. */ else if($gbName != $groupByName && $footerFlag == 'y'){ /*call the getHtmlStr function to construct the html for the subtotal title row. This will be printed along with the rest of the footer.*/ $rowTitle = getHtmlStr('GTMULTIW2', $titleRowVals); $recTotVol = ''; $recTotCost = ''; $totVolTextCol;#text color for volume values in subtotals footers $totCostTextCol;#text color for cost values in subtotals footers /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$val["ppBkVol"], "actbkvol"=>$val["actBkVol"], "ppbkcosts"=>$val["ppBkCost"], "actbkcosts"=>$val["actBkCost"], "ppcolvol"=>$val["ppColVol"], "actcolvol"=>$val["actColVol"], "ppcolcosts"=>$val["ppColCost"], "actcolcosts"=>$val["actColCost"]); $rcVals = getAllReconciledVals($arrayArgs); /*****************BEGIN RECONCILED TOTAL VOLUME AND COSTS********************/ /* Calculate the reconciled totals for volume and cost */ $recTotVol = ($val["actBkVol"] - $val["ppBkVol"]) + ($val["actColVol"] - $val["ppColVol"]); $recTotCost = ($val["actBkCost"] - $val["ppBkCost"]) + ($val["actColCost"] - $val["ppColCost"]); $totVolTextC = getTextColor($recTotVol); $totCostTextC = getTextColor($recTotCost); /*****************END RECONCILED TOTAL VOLUME AND COSTS********************/ $formatArraySVol = getReconFormatArray($rcVals["textBkVol"], $rcVals["textColVol"], $totVolTextC); $formatArraySCost = getReconFormatArray($rcVals["textBkCst"], $rcVals["textColCst"], $totCostTextC); /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTextCol is appended to the format for col 1 in both the volumes row and the costs row. $colTextCol is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTextColSub = getTextColor($val["actBkVol"]); $colTextColSub = getTextColor($val["actColVol"]); $sTotVolFtr = array("numOthCols"=>9, "col_0"=>"Volumes:", "col_1"=>'' . number_format($val["actBkVol"]) . '', "col_2"=>number_format($val["ppBkVol"]), "col_3"=>formatDec($rcVals["recVolB"]), "col_4"=>"", "col_5"=>'' . number_format($val["actColVol"]) . '', "col_6"=>number_format($val["ppColVol"]), "col_7"=>formatDec($rcVals["recVolC"]), "col_8"=>"", "col_9"=>formatDec($recTotVol), "rowStyle"=>$rowStyleN, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArraySVol, "multiCols"=>$widthArrayS, "cellPad"=>1); $sTotCostFtr = array("numOthCols"=>9, "col_0"=>"Costs:", "col_1"=>'$' . number_format($val["actBkCost"], 2) . '', "col_2"=>"$" . number_format($val["ppBkCost"], 2), "col_3"=>formatCurrency($rcVals["recCostB"]), "col_4"=>"", "col_5"=>'$' . number_format($val["actColCost"], 2) . '', "col_6"=>"$" . number_format($val["ppColCost"], 2), "col_7"=>formatCurrency($rcVals["recCostC"]), "col_8"=>"", "col_9"=>formatCurrency($recTotCost), "rowStyle"=>$rowStyleN, "alignLead"=>"", "alignOth"=>"", "fArray"=>$formatArraySCost, "multiCols"=>$widthArrayS, "cellPad"=>1); /*call the getHtmlStr function to construct all sections of the footer content*/ $hdrRow = getHtmlStr('GTMULTIW2', $subTotHdr); $volRow = getHtmlStr('GTMULTIW2', $sTotVolFtr); $costRow = getHtmlStr('GTMULTIW2', $sTotCostFtr); $subTotFooter = << 5){ /* The count has passed 5 so add a page then reset the count to 2 for footer record and the record that will print after the footer. */ $pdf->AddPage('L'); $detailRecCount = 2; } else if($detailRecCount = 5){ /* Increment the count to account for the footer record, but don't add a page yet. */ $detailRecCount += 1; } /*Print the footer w/the totals BEFORE resetting the current row values = the cur val for each var*/ $pdf->writeHTML($subTotFooter, true, true, false, false, ''); # Sub Totals to be incremented # First row Total Volumes for Building Footer. $totBlackVol = $actualBlkVol; $totPreBlackVol = $prepaidBlkVol; $totColVol = $actualColVol; $totPreColVol = $prepaidColVol; $TotalPBVolume = $prepaidBlkVol + $prepaidColVol; # Second row Total Cost for Building Footer - calculated and incremented totals. $TotalBlackCost = $actualBlkVol * $cpcBlk; $TotalPBBlackCost = $prepaidBlkVol * $cpcBlk; $TotalColorCost = $actualColVol * $cpcColor; $TotalPBColorCost = $prepaidColVol * $cpcColor; /* Now that the footer has printed, add a page and reset the count to 1 for the current record waiting to print. */ $pdf->AddPage('L'); $detailRecCount = 1; /*Print all 3 parts of the spec section along with spacer rows*/ $tblSpecs = <<writeHTML($tblSpecs, false, true, false, false, ''); /*Assign the new $groupByName to $gbName*/ $gbName = $groupByName; $tblDetails = <<writeHTML($tblDetails, false, true, false, false, ''); }#end else if $gbName != $groupByName && $footerFlag == 'y' }#end while $val = array("bn"=>$buildingName, "actBkVol"=>$totBlackVol, "ppBkVol"=>$totPreBlackVol, "actColVol"=>$totColVol, "ppColVol"=>$totPreColVol, "actBkCost"=>$TotalBlackCost, "ppBkCost"=>$TotalPBBlackCost, "actColCost"=>$TotalColorCost, "ppColCost"=>$TotalPBColorCost); /*Assign values to the grandTotData array*/ $grandTotData = array("actBkVol"=>$gtBlkVol, "ppBkVol"=>$gtPBBlkVol, "actColVol"=>$gtColVol, "ppColVol"=>$gtPBColVol, "tvol"=>$gtTotPBVol, "actBkCost"=>$gtBlkCost, "ppBkCost"=>$gtPBBlkCost, "actColCost"=>$gtColCost, "ppColCost"=>$gtPBColCost, "gtpbcost"=>$gtTotPBCost); /*Subtotal footer for the last room*/ $recTotVol = ''; $recTotCost = ''; $totVolTextCol;#text color for volume values in subtotals footers $totCostTextCol;#text color for cost values in subtotals footers /*SJH Added on 5/29/2020 for Pam. If the actual subtotal black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTextColSt is appended to the format for col 1 in both the volumes row and the costs row. $colTextColSt is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTextColSt = getTextColor($val["actBkVol"]); $colTextColSt = getTextColor($val["actColVol"]); /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$val["ppBkVol"], "actbkvol"=>$val["actBkVol"], "ppbkcosts"=>$val["ppBkCost"], "actbkcosts"=>$val["actBkCost"], "ppcolvol"=>$val["ppColVol"], "actcolvol"=>$val["actColVol"], "ppcolcosts"=>$val["ppColCost"], "actcolcosts"=>$val["actColCost"]); $rcVals = getAllReconciledVals($arrayArgs); /*****************BEGIN RECONCILED TOTAL VOLUME AND COSTS********************/ /* Calculate the reconciled totals for volume and cost */ $recTotVol = ($val["actBkVol"] - $val["ppBkVol"]) + ($val["actColVol"] - $val["ppColVol"]); $recTotCost = ($val["actBkCost"] - $val["ppBkCost"]) + ($val["actColCost"] - $val["ppColCost"]); $totVolTextC = getTextColor($recTotVol); $totCostTextC = getTextColor($recTotCost); /*****************END RECONCILED TOTAL VOLUME AND COSTS********************/ /************Subtotal footer rows*****************/ $formatArraySVol = getReconFormatArray($rcVals["textBkVol"], $rcVals["textColVol"], $totVolTextC); $formatArraySCost = getReconFormatArray($rcVals["textBkCst"], $rcVals["textColCst"], $totCostTextC); $sTotVolFtr = array("numOthCols"=>9, "col_0"=>"Volumes:", "col_1"=>'' . number_format($val["actBkVol"]) . '', "col_2"=>number_format($val["ppBkVol"]), "col_3"=>formatDec($rcVals["recVolB"]), "col_4"=>"", "col_5"=>'' . number_format($val["actColVol"]) . '', "col_6"=>number_format($val["ppColVol"]), "col_7"=>formatDec($rcVals["recVolC"]), "col_8"=>"", "col_9"=>formatDec($recTotVol), "rowStyle"=>$rowStyleN, "fArray"=>$formatArraySVol, "multiCols"=>$widthArrayS, "cellPad"=>1); $sTotCostFtr = array("numOthCols"=>9, "col_0"=>"Costs:", "col_1"=>'$' . number_format($val["actBkCost"], 2) . '', "col_2"=>"$" . number_format($val["ppBkCost"], 2), "col_3"=>formatCurrency($rcVals["recCostB"]), "col_4"=>"", "col_5"=>'$' . number_format($val["actColCost"], 2) . '', "col_6"=>"$" . number_format($val["ppColCost"], 2), "col_7"=>formatCurrency($rcVals["recCostC"]), "col_8"=>"", "col_9"=>formatCurrency($recTotCost), "rowStyle"=>$rowStyleN, "fArray"=>$formatArraySCost, "multiCols"=>$widthArrayS, "cellPad"=>1); /*call the getHtmlStr function to construct the html for the subtotal title row.*/ $rowTitle2 = getHtmlStr('GTMULTIW2', $titleRowVals); /*call the getHtmlStr function to construct all sections of the footer content*/ $hdrRow = getHtmlStr('GTMULTIW2', $subTotHdr); $volRow = getHtmlStr('GTMULTIW2', $sTotVolFtr); $costRow = getHtmlStr('GTMULTIW2', $sTotCostFtr); $subTotFooter = <<writeHTML($subTotFooter, true, true, false, false, ''); $recTotVol = ''; $recTotCost = ''; $totVolTextCol;#text color for volume values in subtotals footers $totCostTextCol;#text color for cost values in subtotals footers /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$grandTotData["ppBkVol"], "actbkvol"=>$grandTotData["actBkVol"], "ppbkcosts"=>$grandTotData["ppBkCost"], "actbkcosts"=>$grandTotData["actBkCost"], "ppcolvol"=>$grandTotData["ppColVol"], "actcolvol"=>$grandTotData["actColVol"], "ppcolcosts"=>$grandTotData["ppColCost"], "actcolcosts"=>$grandTotData["actColCost"]); $gtVals = getAllReconciledVals($arrayArgs); /*****************BEGIN RECONCILED TOTAL VOLUME AND COSTS********************/ /* Calculate the reconciled totals for volume and cost */ $recTotVol = ($grandTotData["actBkVol"] - $grandTotData["ppBkVol"]) + ($grandTotData["actColVol"] - $grandTotData["ppColVol"]); $recTotCost = ($grandTotData["actBkCost"] - $grandTotData["ppBkCost"]) + ($grandTotData["actColCost"] - $grandTotData["ppColCost"]); $totVolTextC = getTextColor($recTotVol); $totCostTextC = getTextColor($recTotCost); /*****************END RECONCILED TOTAL VOLUME AND COSTS********************/ /***************Grand total footer rows******************/ $formatArraygtVol = getReconFormatArray($gtVals["textBkVol"], $gtVals["textColVol"], $totVolTextC); $formatArraygtCost = getReconFormatArray($gtVals["textBkCst"], $gtVals["textColCst"], $totCostTextC); /*SJH Added on 5/29/2020 for Pam. If the actual grand total black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTextColGt is appended to the format for col 1 in both the volumes row and the costs row. $colTextColGt is appended to the format for col 5 in both the volumes row and the costs row. */ $bkTextColGt = getTextColor($grandTotData["actBkVol"]); $colTextColGt = getTextColor($grandTotData["actColVol"]); $gTotVolFtr = array("numOthCols"=>9, "col_0"=>"Volumes:", "col_1"=>'' . number_format($grandTotData["actBkVol"]) . '', "col_2"=>number_format($grandTotData["ppBkVol"]), "col_3"=>formatDec($gtVals["recVolB"]), "col_4"=>"", "col_5"=>'' . number_format($grandTotData["actColVol"]) . '', "col_6"=>number_format($grandTotData["ppColVol"]), "col_7"=>formatDec($gtVals["recVolC"]), "col_8"=>"", "col_9"=>formatDec($recTotVol), "rowStyle"=>$rowStyleGTN, "fArray"=>$formatArraygtVol, "multiCols"=>$widthArrayS, "cellPad"=>1); $gTotCostFtr = array("numOthCols"=>9, "col_0"=>"Costs:", "col_1"=>'$' . number_format($grandTotData["actBkCost"], 2) . '', "col_2"=>"$" . number_format($grandTotData["ppBkCost"], 2), "col_3"=>formatCurrency($gtVals["recCostB"]), "col_4"=>"", "col_5"=>'$' . number_format($grandTotData["actColCost"], 2) . '', "col_6"=>"$" . number_format($grandTotData["ppColCost"], 2), "col_7"=>formatCurrency($gtVals["recCostC"]), "col_8"=>"", "col_9"=>formatCurrency($recTotCost), "rowStyle"=>$rowStyleGTN, "fArray"=>$formatArraygtCost, "multiCols"=>$widthArrayS, "cellPad"=>1); /*call the getHtmlStr function to construct the html for the TOTAL BALANCE DUE title row.*/ $rowTitle2 = getHtmlStr('GTMULTIW2', $titleRowVals2); /*call the getHtmlStr function to construct all sections of the footer content*/ $hdrRow = getHtmlStr('GTMULTIW2', $grandTotHdr); $volRow = getHtmlStr('GTMULTIW2', $gTotVolFtr); $costRow = getHtmlStr('GTMULTIW2', $gTotCostFtr); $totBalDueFooter = << 5){ /* 5 records including footers have been printed, so add a page. There is no need to reset the count because this is the last print */ $pdf->AddPage('L'); } /*Print the footer w/the grand totals.*/ $pdf->writeHTML($totBalDueFooter, false, true, false, false, ''); }#end if $result else{ $msgConstruct = getRptNoDataMessage("There was no data for a yearly reconciliation report matching your criteria.", "P"); $pdf->writeHTML($msgConstruct, true, true, false, false, ''); } /*Close the db connection*/ $sql->close(); /******************************END FULL YEAR RECONCILIATION HERE************************/ /***************************** SUMMARY BY VENDOR OR TYPE ***********************/ $formatArrayHeaderClient = array(); $widthArrayHeaderClient = array(); $widthArrayHClient = array(); /******************* CONSTRUCT PAGE TITLE ********************/ # set image scale factor. This is needed for all table columns to be shown. $pdf->setImageScale(1.00); $pdf->AddPage('L'); $leadColTitle = ''; $highCol = 'yellow'; /*If this report is for a vendor, the first column heading will be Model Type, otherwise it will be Vendor. */ if($rpt_type === 'Vendor'){ $leadColTitle = 'Model Type'; $ttl = 'Summary by Type'; /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameBk = createGroupHeader('Black Prints', 50, 685, ' color:rgb(0, 0, 0);', null); /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameCol = createGroupHeader('Color Prints', 50, 685, ' color:rgb(35, 114, 239);', null); } else{ $leadColTitle = 'Vendor'; $ttl = 'Summary by Vendor'; /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameBk = createGroupHeader('Black Prints', 15, 685, ' color:rgb(0, 0, 0);', null); /*Call function createGroupHeader($title, $margin, $width, $textCol, $bgCol) to create group header*/ $grpNameCol = createGroupHeader('Color Prints', 15, 685, ' color:rgb(35, 114, 239);', null); } $widthArrayTest = array("col_0"=>775); $titleVals = array("numOthCols"=>0, "col_0"=>$orgName . '
' . $schoolYearFmt . ' / ' . $billingCycle . '
' . $ttl . '', "rowStyle"=>$rowStyleSpc, "fArray"=>$formatArrayTitle, "multiCols"=>$widthArrayTest); $titleStr = getHtmlStr('GTMULTIW2', $titleVals); /********************** PRINT PAGE TITLE AND GROUP HEADER *********************/ $groupTitle = <<writeHTML($groupTitle, false, true, false, false, ''); /*This report will be grouped by vendor for Client type reports AND by machine type for Vendor type reports, so the column headings will be either "Vendor" or "Machine Type". For client type reports the first col will be the Vendor and the second will be the Model Type. For vendor type reports, the first col will be Machine Type and the value will be the $make_mod. */ /********************** PRINT BLACK TABLE HEADER *********************/ $groupClause = '';#used for black and color sections $sectVals = ''; $formatArrayHeaderV = array("col_0"=>'', "col_1"=>'style="border-bottom:1px solid black; text-align:left;"', "col_2"=>'style="border-bottom:1px solid black; text-align:left;"', "col_3"=>'style="border-bottom:1px solid black; text-align:center;"', "col_4"=>'style="border-bottom:1px solid black;"', "col_5"=>'style="border-bottom:1px solid black; border-right:1px solid black; text-align:center;"', "col_6"=>'style="border-bottom:1px solid black;"', "col_7"=>'style="border-bottom:1px solid black; text-align:center;"', "col_8"=>'style="border-bottom:1px solid black; border-right:2px solid black;"', "col_9"=>'style="border-bottom:1px solid black; text-align:center;"', "col_10"=>'style="border-bottom:1px solid black; text-align:center;"', "col_11"=>'style="border-bottom:1px solid black;"', "col_12"=>'style="border-bottom:1px solid black; text-align:center;"', "col_13"=>'style="border-bottom:1px solid black; border-right:1px solid black;"', "col_14"=>'style="border-bottom:1px solid black;"', "col_15"=>'style="border-bottom:1px solid black; text-align:center;"'); $widthArrayHeaderV = array("col_0"=>50, "col_1"=>165, "col_2"=>35, "col_3"=>50, "col_4"=>15, "col_5"=>70, "col_6"=>15, "col_7"=>75, "col_8"=>10, "col_9"=>15, "col_10"=>75, "col_11"=>2, "col_12"=>65, "col_13"=>3, "col_14"=>15, "col_15"=>75); if($rpt_type === 'Client'){ /* Clients need data grouped by vendor. Show machine data for all vendors. Vendors need data grouped by machine type only.*/ $groupClause = " bda.vendor_id, "; /*The header has extra spacing columns to line up the centered headers with the right-aligned content */ $widthArrayHeaderClient = array("col_0"=>10, "col_1"=>135, "col_2"=>92, "col_3"=>57, "col_4"=>70, "col_5"=>6, "col_6"=>60, "col_7"=>20, "col_8"=>65, "col_9"=>10, "col_10"=>10, "col_11"=>65, "col_12"=>15, "col_13"=>60, "col_14"=>10, "col_15"=>10, "col_16"=>65); $widthArrayHClient = array("col_0"=>10, "col_1"=>170, "col_2"=>90, "col_3"=>50, "col_4"=>80, "col_5"=>70, "col_6"=>5, "col_7"=>90, "col_8"=>5, "col_9"=>75, "col_10"=>75, "col_11"=>10, "col_12"=>15); $formatArrayHeaderClient = array("col_0"=>'', "col_1"=>'style="border-bottom:1px solid black; text-align:left;"', "col_2"=>'style="border-bottom:1px solid black; text-align:left;"', "col_3"=>'style="border-bottom:1px solid black; text-align:center;"', "col_4"=>'style="border-bottom:1px solid black; text-align:center;"', "col_5"=>'style="border-bottom:1px solid black;"', "col_6"=>'style="border-bottom:1px solid black; border-right:1px solid black; text-align:center;"', "col_7"=>'style="border-bottom:1px solid black;"', "col_8"=>'style="border-bottom:1px solid black; text-align:center;"', "col_9"=>'style="border-bottom:1px solid black; border-right:2px solid black;"', "col_10"=>'style="border-bottom:1px solid black; text-align:center;"', "col_11"=>'style="border-bottom:1px solid black; text-align:center;"', "col_12"=>'style="border-bottom:1px solid black;"', "col_13"=>'style="border-bottom:1px solid black; text-align:center;"', "col_14"=>'style="border-bottom:1px solid black; border-right:1px solid black;"', "col_15"=>'style="border-bottom:1px solid black;"', "col_16"=>'style="border-bottom:1px solid black; text-align:center;"'); $sectVals = array("numOthCols"=>16, "col_0"=>"", "col_1"=>" 
" . $leadColTitle, "col_2"=>" 
Model Type", "col_3"=>" 
CPC", "col_4"=>"Full Year
Volume", "col_5"=>"", "col_6"=>"Pre-Paid
Volume", "col_7"=>"", "col_8"=>"Reconciled
Volume", "col_9"=>"", "col_10"=>"", "col_11"=>"Full Year
Costs","col_12"=>"", "col_13"=>"Pre-Paid
Costs", "col_14"=>"", "col_15"=>"", "col_16"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeaderClient, "multiCols"=>$widthArrayHeaderClient, "cellPad"=>1); $borderRights = $borderRightsClient; }#end if($rpt_type === 'Client') else{ $sectVals = array("numOthCols"=>15, "col_0"=>"", "col_1"=>" 
" . $leadColTitle, "col_2"=>" 
CPC", "col_3"=>"Full Year
Volume", "col_4"=>"", "col_5"=>"Pre-Paid
Volume", "col_6"=>"", "col_7"=>"Reconciled
Volume", "col_8"=>"", "col_9"=>"", "col_10"=>"Full Year
Costs","col_11"=>"", "col_12"=>"Pre-Paid
Costs", "col_13"=>"", "col_14"=>"", "col_15"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeaderV, "multiCols"=>$widthArrayHeaderV, "cellPad"=>1); } $sectHdr = getHtmlStr('GTMULTIW2', $sectVals); $sect3Hdr = <<writeHTML($sect3Hdr, false, true, false, false, ''); /********************** MAIN CONTENT BLACK BEGIN *********************/ $qStr = ''; /*This will be the query based on whether the $rpt_type is Vendor or Client. */ /*Keep track of the row count. If rows exceed 20, add a new page before printing content.*/ $myRowCount = 0; $qStr = 'SELECT allRows.model_type, allRows.org_name, SUM(allRows.fy_blk_vol), SUM(allRows.fy_bk_costs), SUM(allRows.prepaid_bk_vol), SUM(allRows.prepaid_bk_costs), allRows.vendor_id, allRows.cpc_black FROM (SELECT mtp.type_name model_type, vendOrg.org_name, SUM(cda.`End` - cda.`Begin`) fy_blk_vol, SUM((cda.`End` - cda.`Begin`) * cda.' . $cpcBlkStrCd . ' ) fy_bk_costs, 0 prepaid_bk_vol, 0 prepaid_bk_costs, cda.vendor_id, cda.' . $cpcBlkStrCd . ' cpc_black FROM ' . $deviceTable . ' cda INNER JOIN machines mach ON mach.id = cda.model_id INNER JOIN machine_types mtp ON mtp.id = mach.model_type INNER JOIN organization vendOrg ON vendOrg.id = cda.vendor_id WHERE cda.SerialNumber IN(SELECT SerialNumber FROM current_devices WHERE org_id_ma = ?) AND cda.SerialNumber NOT IN(SELECT bida.serial_number FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ?' . $sumAddCriterion . ' GROUP BY bida.serial_number) ' . $sumWhereVendCda . ' GROUP BY mtp.type_name, ' . $addl_groupCd . ' cda.' . $cpcBlkStrCd . ' UNION ALL SELECT cda.type_name model_type, bda.org_name, SUM(cda.fy_blk_vol) fy_blk_vol, SUM(cda.fy_blk_vol * bda.cpc_black) fy_bk_costs, SUM(bda.prepaid_bk_vol) prepaid_bk_vol, SUM(bda.prepaid_bk_costs) prepaid_bk_costs, bda.vendor_id, bda.cpc_black FROM (SELECT MAX(bida.billing_cycle), bida.serial_number, bida.vendor_id, bida.vendor_id_ma, vendOrg.org_name, bida.' . $cpcBlkStr . ' cpc_black, bida.billing_type, bida.billing_cycle, bida.school_year, bida.org_id_ma, Sum(bida.billed_projected_volume_black) prepaid_bk_vol, Sum(bida.billed_projected_volume_black * bida.' . $cpcBlkStr . ') prepaid_bk_costs FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCriterion . ' GROUP BY bida.serial_number) bda INNER JOIN (SELECT mtp.type_name, cd.building_id_ma, cd.org_id_ma, SUM(cd.`End` - cd.`Begin`) fy_blk_vol, cd.SerialNumber, cd.CostCopy cur_cpc FROM ' . $deviceTable . ' cd INNER JOIN machines mach ON mach.id = cd.model_id INNER JOIN machine_types mtp ON mtp.id = mach.model_type GROUP BY cd.SerialNumber) cda ON cda.SerialNumber = bda.serial_number AND cda.org_id_ma = bda.org_id_ma ' . $sumWhereVend . ' GROUP BY cda.type_name ' . $addl_group . ', cda.cur_cpc) allRows GROUP BY allRows.model_type, allRows.vendor_id, allRows.cpc_black;'; /*prepare stmt*/ $stmt = $dbLink->prepare($qStr); if($stmt = $dbLink->prepare($qStr)) { // assuming $mysqli is the connection if($rpt_type == 'Vendor'){ $stmt->bind_param('iiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $stmt->bind_param('iiiii', $recordId, $recordId, $schoolYear, $recordId, $schoolYear); } $stmt->execute(); } else { #$error = "There is an issue with the request. Please contact tech support."; $error = $dbLink->errno . ' ' . $dbLink->error; echo $error; } /*Bind the criteria param*/ /*if($rpt_type === 'Vendor'){ $stmt->bind_param('iiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $stmt->bind_param('iiiii', $recordId, $recordId, $schoolYear, $recordId, $schoolYear); }*/ /*Execute the stmt*/ #$stmt->execute(); /*Store result*/ $stmt->store_result(); /*Check success*/ if($stmt->num_rows > 0){ /*Bind results*/ /*$stmt->bind_result($make_mod, $vendor, $fy_bk_vol, $fy_col_vol, $fy_bk_costs, $fy_col_costs, $prepaid_bk_vol, $prepaid_bk_costs, $prepaid_col_vol, $prepaid_col_costs, $vend_id_ma, $cur_cpc, $cpc_color);*/ $stmt->bind_result($make_mod, $vendor, $fy_bk_vol, $fy_bk_costs, $prepaid_bk_vol, $prepaid_bk_costs, $vend_id_ma, $cur_cpc); /*Reset $mainBlack and $mainColor here so we can start fresh and 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; $sVendValsBk = array(); $contentArrayBk = ''; $formatArrayBk = ''; while($stmt->fetch()){ $myRowCount += 1; /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$prepaid_bk_vol, "actbkvol"=>$fy_bk_vol, "ppbkcosts"=>$prepaid_bk_costs, "actbkcosts"=>$fy_bk_costs, "ppcolvol"=>0, "actcolvol"=>0, "ppcolcosts"=>0, "actcolcosts"=>0); $sVendValsBk = getAllReconciledVals($arrayArgs); /*Increment the totals for the group total footer*/ $totBkProjVol = $totBkProjVol + $fy_bk_vol; $totBkProjChg = $totBkProjChg + $fy_bk_costs; $totBkPBVol = $totBkPBVol + $prepaid_bk_vol; $totBkPBChg = $totBkPBChg + $prepaid_bk_costs; /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $blackTxtCol is appended to the format for cols and 7 (vol and cost). */ $blackTxtCol = getTextColor($fy_bk_vol); $widthArrayHVendCont = array("col_0"=>50, "col_1"=>145, "col_2"=>50, "col_3"=>60, "col_4"=>70, "col_5"=>10, "col_6"=>90, "col_7"=>10, "col_8"=>75, "col_9"=>75, "col_10"=>10, "col_11"=>90); if($rpt_type == 'Vendor'){ /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayBk = getSummaryFormatArrayVend($sVendValsBk["textBkVol"], $sVendValsBk["textBkCst"]); $contentArrayBk = array("numOthCols"=>"11", "col_0"=>"", "col_1"=>$make_mod, "col_2"=>number_format($cur_cpc, 5), "col_3"=>'' . number_format($fy_bk_vol) . '', "col_4"=>number_format($prepaid_bk_vol), "col_5"=>"", "col_6"=>formatDec($sVendValsBk["recVolB"]), "col_7"=>"", "col_8"=>'$' . number_format($fy_bk_costs, 2) . '', "col_9"=>"$" . number_format($prepaid_bk_costs, 2), "col_10"=>"", "col_11"=>formatCurrency($sVendValsBk["recCostB"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayHVendCont, "cellPad"=>1); } else{ $widthArrayHClient = array("col_0"=>10, "col_1"=>135, "col_2"=>95, "col_3"=>45, "col_4"=>70, "col_5"=>70, "col_6"=>5, "col_7"=>80, "col_8"=>15, "col_9"=>75, "col_10"=>75, "col_11"=>10, "col_12"=>70); /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayBk = getSummaryFormatArrayClient($sVendValsBk["textBkVol"], $sVendValsBk["textBkCst"]); $contentArrayBk = array("numOthCols"=>"12", "col_0"=>"", "col_1"=>$vendor, "col_2"=>$make_mod, "col_3"=>"$" . number_format($cur_cpc, 5), "col_4"=>'' . number_format($fy_bk_vol) . '', "col_5"=>number_format($prepaid_bk_vol), "col_6"=>"", "col_7"=>formatDec($sVendValsBk["recVolB"]), "col_8"=>"", "col_9"=>'$' . number_format($fy_bk_costs, 2) . '', "col_10"=>"$" . number_format($prepaid_bk_costs, 2), "col_11"=>"", "col_12"=>formatCurrency($sVendValsBk["recCostB"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayHClient, "cellPad"=>1); } /*Send black and color arrays separately to the getHtmlStr function so it can compose the main content for each group*/ if($myRowCount > 21){ $blackRows = <<writeHTML($blackRows, false, true, false, false, ''); /*Begin a new page, then reset the rowCount to 1 for the current record that will begin the new concat*/ $pdf->setImageScale(1.00); $pdf->AddPage('L'); $myRowCount = 1; /*Start over with creating the remaining black content.*/ $mainBlack = getHtmlStr('GTMULTIW2', $contentArrayBk); } else{ $mainBlack = $mainBlack . getHtmlStr('GTMULTIW2', $contentArrayBk); } }#end while /*Close the db connection*/ $stmt->close(); /********************** SUMMARY BY VENDOR BLACK FOOTER BEGIN*********************/ /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>$totBkPBVol, "actbkvol"=>$totBkProjVol, "ppbkcosts"=>$totBkPBChg, "actbkcosts"=>$totBkProjChg, "ppcolvol"=>0, "actcolvol"=>0, "ppcolcosts"=>0, "actcolcosts"=>0); $sTotVendValsBk = getAllReconciledVals($arrayArgs); $backgroundColor = 'background-color:rgb(222, 235, 247);'; /*SJH Added on 5/29/2020 for Pam. If the actual black volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $bkTxtCol is appended to the format for both the volumes row and the costs row. */ $bkTxtColT = getTextColor($totBkProjVol); if($rpt_type == 'Vendor'){ /*Call getSummaryFormatArray to get the format using the colors for vol and cost. Pass the variable with the desired background-color. */ $formatArrayBk = getSummaryFormatArrayVend($sTotVendValsBk["textBkVol"], $sTotVendValsBk["textBkCst"], $backgroundColor); $bfVals = array("numOthCols"=>11, "col_0"=>"", "col_1"=>"Black Prints Totals", "col_2"=>"", "col_3"=>'' . number_format($totBkProjVol) . '', "col_4"=>number_format($totBkPBVol), "col_5"=>"", "col_6"=>formatDec($sTotVendValsBk["recVolB"]), "col_7"=>"", "col_8"=>'$' . number_format($totBkProjChg, 2) . '', "col_9"=>"$" . number_format($totBkPBChg, 2), "col_10"=>"", "col_11"=>formatCurrency($sTotVendValsBk["recCostB"]), "rowStyle"=>$rowStyleF, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayHVendCont, "cellPad"=>1); } else{ /*Call getSummaryFormatArray to get the format using the colors for vol and cost. Pass the variable with the desired background-color. */ $formatArrayBk = getSummaryFormatArrayClient($sTotVendValsBk["textBkVol"], $sTotVendValsBk["textBkCst"], $backgroundColor); $bfVals = array("numOthCols"=>12, "col_0"=>"", "col_1"=>"Black Prints Totals", "col_2"=>"", "col_3"=>"", "col_4"=>'' . number_format($totBkProjVol) . '', "col_5"=>number_format($totBkPBVol), "col_6"=>"", "col_7"=>formatDec($sTotVendValsBk["recVolB"]), "col_8"=>"", "col_9"=>'$' . number_format($totBkProjChg, 2) . '', "col_10"=>"$" . number_format($totBkPBChg, 2), "col_11"=>"", "col_12"=>formatCurrency($sTotVendValsBk["recCostB"]), "rowStyle"=>$rowStyleF, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayHClient, "cellPad"=>1); } $totBlack = getHtmlStr('GTMULTIW2', $bfVals); $blackFooter = <<writeHTML($blackFooter, false, true, false, false, ''); /********************** SUMMARY BY VENDOR BLACK FOOTER END ******************/ /********************** PRINT COLOR GROUP TITLE *********************/ $groupTitle2 = <<writeHTML($groupTitle2, false, true, false, false, ''); /********************** PRINT COLOR TABLE HEADER BEGIN *********************/ $thValsV2 = ''; if($rpt_type === 'Client'){ $thValsV2 = array("numOthCols"=>16, "col_0"=>"", "col_1"=>" 
" . $leadColTitle, "col_2"=>" 
Model Type", "col_3"=>" 
CPC", "col_4"=>"Full Year
Volume", "col_5"=>"", "col_6"=>"Pre-Paid
Volume", "col_7"=>"", "col_8"=>"Reconciled
Volume", "col_9"=>"", "col_10"=>"", "col_11"=>"Full Year
Costs","col_12"=>"", "col_13"=>"Pre-Paid
Costs", "col_14"=>"", "col_15"=>"", "col_16"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeaderClient, "multiCols"=>$widthArrayHeaderClient, "cellPad"=>1); $borderRights = $borderRightsClient; } else{ $thValsV2 = array("numOthCols"=>15, "col_0"=>"", "col_1"=>" 
" . $leadColTitle, "col_2"=>" 
CPC", "col_3"=>"Full Year
Volume", "col_4"=>"", "col_5"=>"Pre-Paid
Volume", "col_6"=>"", "col_7"=>"Reconciled
Volume", "col_8"=>"", "col_9"=>"", "col_10"=>"Full Year
Costs","col_11"=>"", "col_12"=>"Pre-Paid
Costs", "col_13"=>"", "col_14"=>"", "col_15"=>"Reconciled
Costs", "rowStyle"=>$rowStyleH, "fArray"=>$formatArrayHeaderV, "multiCols"=>$widthArrayHeaderV, "cellPad"=>1); } $tabHdr2 = getHtmlStr('GTMULTIW2', $thValsV2); $hdrRow2 = <<writeHTML($hdrRow2, false, true, false, false, ''); /********************** PRINT COLOR TABLE HEADER END*********************/ /********************** SUMMARY BY VENDOR MAIN CONTENT COLOR BEGIN *********************/ $qStr = ''; /*This will be the query based on whether the $rpt_type is Vendor or Client. */ $qStr = 'SELECT allRows.model_type, allRows.org_name, SUM(allRows.fy_col_vol) fy_col_vol, SUM(allRows.fy_col_costs) fy_col_costs, SUM(allRows.prepaid_col_vol) prepaid_col_vol, SUM(allRows.prepaid_col_costs) prepaid_col_costs, allRows.vendor_id, allRows.cpc_color FROM (SELECT mtp.type_name model_type, vendOrg.org_name, SUM(cda.`MstrEnd` - cda.`MstrBegin`) fy_col_vol, SUM((cda.`MstrEnd` - cda.`MstrBegin`) * cda.' . $cpcColorStrCd . ') fy_col_costs, 0 prepaid_col_vol, 0 prepaid_col_costs, cda.vendor_id, cda.' . $cpcColorStrCd . ' cpc_color FROM ' . $deviceTable . ' cda INNER JOIN machines mach ON mach.id = cda.model_id INNER JOIN machine_types mtp ON mtp.id = mach.model_type INNER JOIN organization vendOrg ON vendOrg.id = cda.vendor_id WHERE cda.SerialNumber IN(SELECT SerialNumber FROM current_devices WHERE org_id_ma = ?) AND cda.SerialNumber NOT IN(SELECT bida.serial_number FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCriterion . ' GROUP BY bida.serial_number) ' . $sumWhereVendCda . ' GROUP BY mtp.type_name, cda.vendor_id, cda.' . $cpcColorStrCd . ' UNION ALL SELECT cda.type_name model_type, bda.org_name, SUM(cda.fy_col_vol) fy_col_vol, SUM(cda.fy_col_vol * bda.cpc_color) fy_col_costs, SUM(bda.prepaid_col_vol) prepaid_col_vol, SUM(bda.prepaid_col_costs) prepaid_col_costs, bda.vendor_id, bda.cpc_color FROM (SELECT MAX(bida.billing_cycle), bida.serial_number, bida.vendor_id, bida.vendor_id_ma, vendOrg.org_name, bida.' . $cpcColorStr . ' cpc_color, bida.billing_type, bida.billing_cycle, bida.school_year, bida.org_id_ma, Sum(bida.billed_projected_volume_color) prepaid_col_vol, Sum(bida.billed_projected_volume_color * bida.' . $cpcColorStr . ' ) prepaid_col_costs FROM billing_data_archive bida LEFT JOIN organization vendOrg ON vendOrg.id = bida.vendor_id WHERE bida.org_id_ma = ? AND bida.billing_cycle != 10 AND bida.school_year = ? ' . $sumAddCriterion . ' GROUP BY bida.serial_number) bda INNER JOIN (SELECT mtp.type_name, cd.org_id_ma, cd.building_id_ma, SUM(cd.`MstrEnd` - cd.`MstrBegin`) fy_col_vol, cd.SerialNumber, cd.Mstrcpc cur_cpc FROM ' . $deviceTable . ' cd INNER JOIN machines mach ON mach.id = cd.model_id INNER JOIN machine_types mtp ON mtp.id = mach.model_type WHERE mtp.color = 1 GROUP BY cd.SerialNumber) cda ON cda.SerialNumber = bda.serial_number AND cda.org_id_ma = bda.org_id_ma ' . $sumWhereVend . ' GROUP BY cda.type_name ' . $addl_group . ', cda.cur_cpc) allRows GROUP BY allRows.model_type, allRows.vendor_id, allRows.cpc_color;'; /*prepare stmt*/ $eStmt = $dbLink->prepare($qStr); if($eStmt = $dbLink->prepare($qStr)) { // assuming $mysqli is the connection if($rpt_type === 'Vendor'){ $eStmt->bind_param('iiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $eStmt->bind_param('iiiii', $recordId, $recordId, $schoolYear, $recordId, $schoolYear); } $eStmt->execute(); } else { #$error = "There is an issue with the request. Please contact tech support."; $error = $dbLink->errno . ' ' . $dbLink->error; echo $error; } /*Bind the criteria param*/ /*if($rpt_type === 'Vendor'){ $eStmt->bind_param('iiiiiii', $recordId, $recordId, $schoolYear, $thisVendor, $recordId, $schoolYear, $thisVendor); } else{ $eStmt->bind_param('iiiii', $recordId, $recordId, $schoolYear, $recordId, $schoolYear); }*/ /*Execute the stmt*/ #$eStmt->execute(); /*Store result*/ $eStmt->store_result(); /*Check success*/ if($eStmt->num_rows > 0){ /*Bind results*/ $eStmt->bind_result($make_mod, $vendor, $proj_col_vol, $proj_col_chg, $pb_col_vol, $pb_col_chg, $vend_id_ma, $cur_cpc); while($eStmt->fetch()){ $myRowCount += 1; /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>0, "actbkvol"=>0, "ppbkcosts"=>0, "actbkcosts"=>0, "ppcolvol"=>$pb_col_vol, "actcolvol"=>$proj_col_vol, "ppcolcosts"=>$pb_col_chg, "actcolcosts"=>$proj_col_chg); $sVendValsCol = getAllReconciledVals($arrayArgs); /*SJH Added on 5/29/2020 for Pam. If the actual color volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $blackTxtCol is appended to the format for cols and 7 (vol and cost). $colTxtCol is appended to the format for col 5 and (vol and cost). */ $colorTxtCol = getTextColor($proj_col_vol); if($rpt_type == 'Client'){ /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayCol = getSummaryFormatArrayClient($sVendValsCol["textColVol"], $sVendValsCol["textColCst"]); $contentArrayCol = array("numOthCols"=>"12", "col_0"=>"", "col_1"=>$vendor, "col_2"=>$make_mod, "col_3"=>"$" . number_format($cur_cpc, 5), "col_4"=>'' . number_format($proj_col_vol) . '', "col_5"=>number_format($pb_col_vol), "col_6"=>"", "col_7"=>formatDec($sVendValsCol["recVolC"]), "col_8"=>"", "col_9"=>'$' . number_format($proj_col_chg, 2) . '', "col_10"=>"$" . number_format($pb_col_chg, 2), "col_11"=>"", "col_12"=>formatCurrency($sVendValsCol["recCostC"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayCol, "multiCols"=>$widthArrayHClient, "cellPad"=>1); } else{ /*Call getSummaryFormatArray to get the format using the colors for vol and cost*/ $formatArrayCol = getSummaryFormatArrayVend($sVendValsCol["textColVol"], $sVendValsCol["textColCst"]); $contentArrayCol = array("numOthCols"=>"11", "col_0"=>"", "col_1"=>$make_mod, "col_2"=>number_format($cur_cpc, 5), "col_3"=>'' . number_format($proj_col_vol) . '', "col_4"=>number_format($pb_col_vol), "col_5"=>"", "col_6"=>formatDec($sVendValsCol["recVolC"]), "col_7"=>"", "col_8"=>'$' . number_format($proj_col_chg, 2) . '', "col_9"=>"$" . number_format($pb_col_chg, 2), "col_10"=>"", "col_11"=>formatCurrency($sVendValsCol["recCostC"]), "rowStyle"=>$rowStyle9, "fArray"=>$formatArrayCol, "multiCols"=>$widthArrayHVendCont, "cellPad"=>1); } $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*/ if($myRowCount > 21){ $colorRows = <<writeHTML($colorRows, false, true, false, false, ''); /*Begin a new page, then reset the rowCount to 1 for the current record that will begin the new concat*/ $pdf->setImageScale(1.00); $pdf->AddPage('L'); $myRowCount = 1; /*Start over with creating the remaining black content.*/ $mainColor = getHtmlStr('GTMULTIW2', $contentArrayCol); } else{ $mainColor = $mainColor . getHtmlStr('GTMULTIW2', $contentArrayCol); } }#end while }#end if $eStmt->num_rows /*Close the db connection*/ $eStmt->close(); /********************** SUMMARY BY VENDOR MAIN CONTENT COLOR END *********************/ /*Assign the Black and Color Combined Totals to vars for the combined total footer*/ $totProjectVol = $totBkProjVol + $totColProjVol; $totProjectChg = $totBkProjChg + $totColProjChg; $totPrebillVol = $totBkPBVol + $totColPBVol; $totPrebillChg = $totBkPBChg + $totColPBChg; /*Create an array of the vol and cost values to send to the getAllReconciledVals function */ $arrayArgs = array("ppbkvol"=>0, "actbkvol"=>0, "ppbkcosts"=>0, "actbkcosts"=>0, "ppcolvol"=>$totColPBVol, "actcolvol"=>$totColProjVol, "ppcolcosts"=>$totColPBChg, "actcolcosts"=>$totColProjChg); $sTotVendValsCol = getAllReconciledVals($arrayArgs); /*Call getSummaryFormatArray to get the format using the colors for vol and cost. Pass the variable with the desired background-color. */ $backgroundColor = 'background-color:rgb(222, 235, 247);'; /*SJH Added on 5/29/2020 for Pam. If the actual color volume < 0 then both the volume and cost will be in red, otherwise it will default to black. $colTxtColT is appended to the format for col 5 in both the volumes row and the costs row. */ $colTxtColT = getTextColor($totColProjVol); if($rpt_type == 'Client'){ $formatArrayCol = getSummaryFormatArrayClient($sTotVendValsCol["textColVol"], $sTotVendValsCol["textColCst"], $backgroundColor); $cfVals = array("numOthCols"=>12, "col_0"=>"", "col_1"=>"Color Prints Totals", "col_2"=>"", "col_3"=>"", "col_4"=>'' . number_format($totColProjVol) . '', "col_5"=>number_format($totColPBVol), "col_6"=>"", "col_7"=>formatDec($sTotVendValsCol["recVolC"]), "col_8"=>"", "col_9"=>'$' . number_format($totColProjChg, 2) . '', "col_10"=>"$" . number_format($totColPBChg, 2), "col_11"=>"", "col_12"=>formatCurrency($totVals["recCostC"]), "rowStyle"=>$rowStyleF, "fArray"=>$formatArrayBk, "multiCols"=>$widthArrayHClient, "cellPad"=>1); } else{ $formatArrayCol = getSummaryFormatArrayVend($sTotVendValsCol["textColVol"], $sTotVendValsCol["textColCst"], $backgroundColor); $cfVals = array("numOthCols"=>11, "col_0"=>"", "col_1"=>"Color Prints Totals", "col_2"=>"", "col_3"=>'' . number_format($totColProjVol) . '', "col_4"=>number_format($totColPBVol), "col_5"=>"", "col_6"=>formatDec($sTotVendValsCol["recVolC"]), "col_7"=>"", "col_8"=>'$' . number_format($totColProjChg, 2) . '', "col_9"=>"$" . number_format($totColPBChg, 2), "col_10"=>"", "col_11"=>formatCurrency($totVals["recCostC"], 2), "rowStyle"=>$rowStyleF, "fArray"=>$formatArrayCol, "multiCols"=>$widthArrayHVendCont, "cellPad"=>1); } $totColor = getHtmlStr('GTMULTIW2', $cfVals); $colorFooter = <<writeHTML($colorFooter, true, true, false, false, ''); /************************** COLOR FOOTER END****************************/ /******************** COMBINED BLACK AND COLOR TOTALS FOOTER BEGIN*****************/ $combinedGrpTotRecVol = ($totBkProjVol - $totBkPBVol) + ($totColProjVol - $totColPBVol); $combinedGrpTotRecCost = ($totBkProjChg - $totBkPBChg) + ($totColProjChg - $totColPBChg); $formatArrayComb = ''; $widthArrayAvg = ''; if($rpt_type === 'Client'){ $formatArrayComb = array("col_0"=>'', "col_1"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_2"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_3"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_4"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_5"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_6"=>'style="text-align:right; border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_7"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_8"=>'style="text-align:right; border-right:2px solid white; background-color:rgb(31, 78, 121);"', "col_9"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_10"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_11"=>'style="text-align:right; border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_12"=>'style="text-align:right; background-color:rgb(31, 78, 121);"'); $grpTotVals = array("numOthCols"=>12, "col_0"=>"", "col_1"=>"TOTALS:", "col_2"=>"", "col_3"=>"", "col_4"=>number_format($totProjectVol), "col_5"=>number_format($totPrebillVol), "col_6"=>"", "col_7"=>formatDec($combinedGrpTotRecVol), "col_8"=>"", "col_9"=>"$" . number_format($totProjectChg, 2), "col_10"=>"$" . number_format($totPrebillChg, 2), "col_11"=>"", "col_12"=>formatCurrency($combinedGrpTotRecCost, 2), "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayComb, "multiCols"=>$widthArrayHClient, "cellPad"=>1); $widthArrayAvg = array("col_0"=>10, "col_1"=>280, "col_2"=>60, "col_3"=>405); } else{ $formatArrayComb = array("col_0"=>'', "col_1"=>'style="text-align:left; background-color:rgb(31, 78, 121);"', "col_2"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_3"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_4"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_5"=>'style="border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_6"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_7"=>'style="border-right:2px solid white; background-color:rgb(31, 78, 121);"', "col_8"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_9"=>'style="text-align:right; background-color:rgb(31, 78, 121);"', "col_10"=>'style="border-right:1px solid white; background-color:rgb(31, 78, 121);"', "col_11"=>'style="text-align:right; background-color:rgb(31, 78, 121);"'); $grpTotVals = array("numOthCols"=>11, "col_0"=>"", "col_1"=>"TOTALS:", "col_2"=>"", "col_3"=>number_format($totProjectVol), "col_4"=>number_format($totPrebillVol), "col_5"=>"", "col_6"=>formatDec($combinedGrpTotRecVol), "col_7"=>"", "col_8"=>"$" . number_format($totProjectChg, 2), "col_9"=>"$" . number_format($totPrebillChg, 2), "col_10"=>"", "col_11"=>formatCurrency($combinedGrpTotRecCost, 2), "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayComb, "multiCols"=>$widthArrayHVendCont, "cellPad"=>1); $widthArrayAvg = array("col_0"=>50, "col_1"=>250, "col_2"=>75, "col_3"=>360); } $combTot = getHtmlStr('GTMULTIW2', $grpTotVals); /********************** COMBINED BLACK AND COLOR TOTALS FOOTER END *********************/ /* Spacer row between totals and average rows */ $totSpacerVals2 = array("numOthCols"=>"3", "col_0"=>"", "col_1"=>"", "col_2"=>"", "col_3"=>"", "rowStyle"=>$rowStyleTotSpacer, "fArray"=>$formatArrayAvg, "multiCols"=>$widthArrayAvg); $spacerRowCol2 = getHtmlStr('GTMULTIW2', $totSpacerVals2); $avg_cost_per_print = $totProjectChg / $totProjectVol; $avgCost = array("numOthCols"=>3, "col_0"=>"", "col_1"=>"Average Cost Per Print For Black & Color:", "col_2"=>"$" . number_format($avg_cost_per_print, 5), "col_3"=>"", "rowStyle"=>$rowStyleComb, "fArray"=>$formatArrayAvg, "multiCols"=>$widthArrayAvg, "cellPad"=>1); $aCost = getHtmlStr('GTMULTIW2', $avgCost); $avgCostFooter = <<writeHTML($avgCostFooter, true, false, true, false, ''); /*Close the db connection*/ $stmt->close(); }#end if num_rows else{ $msgConstruct = getRptNoDataMessage("There was no data for a yearly reconciliation report matching your criteria.", "P"); $pdf->writeHTML($msgConstruct, true, true, false, false, ''); } mysqli_close($dbc); # Clean any content of the output buffer. ob_end_clean(); # Send the pdf $pdf->Output('yearlyReconciliation.pdf', 'I'); ?>