Skip to content

Commit

Permalink
PaulB reportwrite mods, part 2
Browse files Browse the repository at this point in the history
Additional tweaks to the previous reportwriter changes.
  • Loading branch information
TurboPT committed Mar 9, 2018
1 parent b0f315d commit f3aeea5
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 39 deletions.
85 changes: 64 additions & 21 deletions reportwriter/WriteReport.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,43 @@ var $pageY; // y value of bottom of page less bottom margin
function Header() {
global $Prefs, $Heading, $Seq;
define(RowSpace,2); // define separation between the heading rows
$this->SetTopMargin($Prefs['margintop']);
if ($Prefs['coynameshow']) { // Show the company name
$this->SetFont($Prefs['coynamefont']);
$this->SetFontSize($Prefs['coynamefontsize']);
$Colors = explode(':',$Prefs['coynamefontcolor']);
$this->SetTextColor($Colors[0], $Colors[1], $Colors[2]);
$CellHeight = ($Prefs['coynamefontsize']+RowSpace)*0.35;
$this->Cell(0,$CellHeight,$_SESSION['CompanyRecord']['coyname'],0,1,$Prefs['coynamealign']);
}
if ($Prefs['title1show']) { // Set title 1 heading
$this->SetFont($Prefs['title1font']);
$this->SetFontSize($Prefs['title1fontsize']);
$Colors = explode(':',$Prefs['title1fontcolor']);
$this->SetTextColor($Colors[0], $Colors[1], $Colors[2]);
$CellHeight = ($Prefs['title1fontsize']+RowSpace)*0.35;
$this->Cell(0,$CellHeight,$this->SubTitle($Prefs['title1desc']),0,1,$Prefs['title1fontalign']);
}
if ($Prefs['title2show']) { // Set Title 2 heading
$this->SetFont($Prefs['title2font']);
$this->SetFontSize($Prefs['title2fontsize']);
$Colors = explode(':',$Prefs['title2fontcolor']);
$this->SetTextColor($Colors[0], $Colors[1], $Colors[2]);
$CellHeight = ($Prefs['title2fontsize']+RowSpace)*0.35;
$this->Cell(0,$CellHeight,$this->SubTitle($Prefs['title2desc']),0,1,$Prefs['title2fontalign']);
}
// Set the filter heading
$this->SetFont($Prefs['filterfont']);
$this->SetFontSize($Prefs['filterfontsize']);
$Colors = explode(':',$Prefs['filterfontcolor']);
$this->SetTextColor($Colors[0], $Colors[1], $Colors[2]);
$CellHeight = ($Prefs['filterfontsize']+RowSpace)*0.35; // convert points to mm
$CellHeight = ($Prefs['filterfontsize']+RowSpace)*0.35*2;
$this->Cell(0,$CellHeight,$Prefs['filterdesc'],'B',1,$Prefs['filterfontalign']);
$this->y0=$this->GetY(); // set y position after report headings before column titles
// Set the table header
if (substr($Prefs['datafont'], -2) <> 'BI') {
$this->SetFont($Prefs['datafont'].'BI');
}
$this->SetFontSize($Prefs['datafontsize']);
$Colors = explode(':',$Prefs['datafontcolor']);
$this->SetTextColor($Colors[0], $Colors[1], $Colors[2]);
Expand Down Expand Up @@ -95,7 +103,7 @@ var $pageY; // y value of bottom of page less bottom margin
if ($trunc) {
$value=$this->TruncData($value, $Prefs['col'.$col.'width']);
}
$this->MultiCell($CellXPos[$col]-$CellXPos[$col-1],$CellHeight,$value);
$this->MultiCell($CellXPos[$col]-$CellXPos[$col-1],$CellHeight,$value,0,$Prefs['datafontalign']);
if ($ColBreak[$key]) {
$col++;
$LastY = $this->y0;
Expand All @@ -106,31 +114,32 @@ var $pageY; // y value of bottom of page less bottom margin
$this->SetLeftMargin($CellXPos[0]);
$this->SetX($CellXPos[0]);
$this->SetY($this->y0);
$this->Cell(0,$maxY-$this->y0,' ','B');
$this->Cell(0,$maxY-$this->y0,'','B');
$this->y0=$maxY+0.35;
}

function SubTitle($Title) {
global $Prefs;
// substitutes a command string with current information
$Title=preg_replace('/%time%/', date('g:i A',time()), $Title);
$Title=preg_replace('/%date%/', date('Y-m-d',time()), $Title);
$Title=preg_replace('/%reportname%/', $Prefs['reportname'], $Title);
return $Title;
}

function Footer() {
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFontSize(8);
$this->SetTextColor(0);
//Page number
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/' . $this->getNumPages(), 0, 0, 'C');
//Position at 1.5 cm from bottom
$this->SetY(-15);
$this->SetFontSize(8);
$this->SetTextColor(0);
//Page number
$this->Cell(0,(8+RowSpace)*0.35,'Page '.$this->PageNo().' / '.$this->getNumPages(),0,0,'C');
}

function ReportTable($Data) {
global $Prefs, $Seq;

$this->SetFont($Prefs['datafont']);
$this->SetFontSize($Prefs['datafontsize']);
$FillColor = array(224, 235, 255);
$this->SetFillColor($FillColor[0],$FillColor[1],$FillColor[2]);
Expand All @@ -155,16 +164,20 @@ var $pageY; // y value of bottom of page less bottom margin
$trunc=false;
}
// Ready to draw the column data
$fill=false;
$fill=false;
$NeedTop='No';
$MaxRowHt = 0; //track the tallest row to estimate page breaks
foreach($Data as $myrow) {
foreach($Data as $myrow) {
$Action = array_shift($myrow);
$todo = explode(':',$Action); // contains a letter of the date type and title/groupname
$this->SetFontSize($Prefs['datafontsize']);
$this->SetFont($Prefs['datafont']);
switch ($todo[0]) {
case "r": // Report Total
case "g": // Group Total
// Draw a fill box
$this->SetFont($Prefs['totalsfont']);
$this->SetFontSize($Prefs['totalsfontsize']);
if ($this->y0+(2*$MaxRowHt)>$this->pageY) {
// Fill the end of the report with white space
$this->SetLeftMargin($CellXPos[0]);
Expand All @@ -179,7 +192,7 @@ var $pageY; // y value of bottom of page less bottom margin
$this->SetX($CellXPos[0]);
$this->SetY($this->y0);
$this->SetFillColor(240);
$this->Cell(0,$this->pageY-$this->y0,'',$brdr,0,'L',1);
$this->Cell(0,$CellHeight,'',$brdr,0,'L',1);
// Add total heading
$this->SetLeftMargin($CellXPos[0]);
$this->SetX($CellXPos[0]);
Expand Down Expand Up @@ -218,7 +231,7 @@ var $pageY; // y value of bottom of page less bottom margin
$this->SetX($CellXPos[0]);
$this->SetY($this->y0);
if ($fill) $this->SetFillColor($FillColor[0],$FillColor[1],$FillColor[2]); else $this->SetFillColor(255);
$this->Cell(0,$this->pageY-$this->y0,'',$brdr,0,'L',1);
$this->Cell(0,$CellHeight,'',$brdr,0,'L',1);
// fill in the data
$maxY = $this->y0; // set to current top of row
$col = 1;
Expand All @@ -229,7 +242,7 @@ var $pageY; // y value of bottom of page less bottom margin
$this->SetY($LastY);
// truncate data if necessary
if ($trunc) $value=$this->TruncData($value, $Prefs['col'.$col.'width']);
$this->MultiCell($CellXPos[$col]-$CellXPos[$col-1],$CellHeight,$value,$Prefs['datafontalign'],1);
$this->MultiCell($CellXPos[$col]-$CellXPos[$col-1],$CellHeight,$value,1,$Prefs['datafontalign']);
if ($ColBreak[$key]) {
$col++;
$LastY = $this->y0;
Expand Down Expand Up @@ -285,7 +298,7 @@ function BuildSQL($Prefs) {
}
$strField = mb_substr($strField,0,-2); // strip the last comma

$Prefs['filterdesc'] = RPT_RPTFILTER; // Initialize the filter display string
$Prefs['filterdesc'] = RPT_RPTBASIS.' | '.RPT_RPTFILTER; // Initialize the filter display string
//fetch the groupings and build first level of SORT BY string (for sub totals)
$strGroup = '';
if (is_array($Prefs['GroupListings'])) while ($FieldValues = array_shift($Prefs['GroupListings'])) {
Expand All @@ -309,7 +322,7 @@ function BuildSQL($Prefs) {
$Today = date('Y-m-d', time());
$ThisMonth = date('m');
$ThisYear = date('Y');
$Yesterday = $Today-1;
$Yesterday = date('Y-m-d', time()-86400);
$LastMonth = $ThisMonth-1;
$LastYear = $ThisYear-1;
// Find total number of days in this month:
Expand Down Expand Up @@ -409,14 +422,26 @@ function BuildSQL($Prefs) {
$d .= " AND ".$df."<='".$we."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ws).' '.RPT_TO.' '.ConvertSQLDate($we).';';
break;
case "n": // RPT_GROUP_LASTMONTH
case "n": // RPT_GROUP_LASTWTD
$ws = date('Y-m-d', mktime(0,0,0, $ThisMonth, date('j')-date('w')-7, $ThisYear));
$d = $df.">='".$ws."'";
$d .= " AND ".$df."<='".$Today."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ws).' '.RPT_TO.' '.ConvertSQLDate($Today).';';
break;
case "o": // RPT_GROUP_LASTMONTH
$ms = date('Y-m-d', mktime(0,0,0, $LastMonth, 1, $ThisYear));
$me = date('Y-m-d', mktime(0,0,0, $LastMonth, $TotalDaysLast, $ThisYear));
$d = $df.">='".$ms."'";
$d .= " AND ".$df."<='".$me."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ms).' '.RPT_TO.' '.ConvertSQLDate($me).';';
break;
case "o": // RPT_GROUP_LASTQUARTER
case "p": // RPT_GROUP_LASTMTD
$ms = date('Y-m-d', mktime(0,0,0, $LastMonth, 1, $ThisYear));
$d = $df.">='".date('Y-m-d', mktime(0,0,0, $ThisMonth, 1, $ThisYear))."'";
$d .= " AND ".$df."<='".$Today."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ms).' '.RPT_TO.' '.ConvertSQLDate($Today).';';
break;
case "q": // RPT_GROUP_LASTQUARTER
$QtrStrt = intval(($ThisMonth-1)/3)*3-2;
$QtrEnd = intval(($ThisMonth-1)/3)*3+0;
if ( $QtrEnd == 4 OR $QtrEnd == 6 OR $QtrEnd == 9 OR $QtrEnd == 11 ) { $TotalDaysLast=30; }
Expand All @@ -426,16 +451,34 @@ function BuildSQL($Prefs) {
$d .= " AND ".$df."<='".$qe."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($qs).' '.RPT_TO.' '.ConvertSQLDate($qe).';';
break;
case "p": // RPT_GROUP_LASTYEAR
case "r": // RPT_GROUP_LASTQTD
$QtrStrt = intval(($ThisMonth-1)/3)*3-2;
$qs = date('Y-m-d', mktime(0,0,0, $QtrStrt, 1, $ThisYear));
$d = $df.">='".$qs."'";
$d .= " AND ".$df."<='".$Today."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($qs).' '.RPT_TO.' '.ConvertSQLDate($Today).';';
break;
case "s": // RPT_GROUP_LASTYEAR
$ys = date('Y-m-d', mktime(0,0,0, 1, 1, $LastYear));
$ye = date('Y-m-d', mktime(0,0,0, 12, 31, $LastYear));
$d = $df.">='".$ys."'";
$d .= " AND ".$df."<='".$ye."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ys).' '.RPT_TO.' '.ConvertSQLDate($ye).';';
break;
case "t": // RPT_GROUP_LASTYTD
$ys = date('Y-m-d', mktime(0,0,0, 1, 1, $LastYear));
$d = $df.">='".$ys."'";
$d .= " AND ".$df."<='".$Today."'";
$fildesc = ' '.RPT_DATERANGE.' '.RPT_FROM.' '.ConvertSQLDate($ys).' '.RPT_TO.' '.ConvertSQLDate($Today).';';
break;
}
$strDate = $d;
if ($fildesc<>'') $Prefs['filterdesc'] .= $fildesc; // update the filter description string
// update the filter description string
if ($fildesc<>'') {
$Prefs['filterdesc'] .= $fildesc;
} else {
$Prefs['filterdesc'] .= ' '.RPT_DATERANGE.' All Transactions'.';';
}

// Fetch the Criteria
$strCrit = '';
Expand Down
31 changes: 24 additions & 7 deletions reportwriter/admin/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@
'A3:297:420' => RPT_A3,
'A4:210:297' => RPT_A4,
'A5:148:210' => RPT_A5,
'Legal:216:357' => RPT_LEGAL,
'Letter:216:282' => RPT_LETTER);
'Legal:216:356' => RPT_LEGAL,
'Letter:216:279' => RPT_LETTER);

// Fonts (defaults for FPDF)
$Fonts = array (
'helvetica' => RPT_HELVETICA,
'courier' => RPT_COURIER,
'times' => RPT_TIMES);
'courierB' => RPT_COURIERB,
'courierBI' => RPT_COURIERBI,
'courierI' => RPT_COURIERI,
'helvetica' => RPT_HELVETICA,
'helveticaB' => RPT_HELVETICAB,
'helveticaBI' => RPT_HELVETICABI,
'helveticaI' => RPT_HELVETICAI,
'times' => RPT_TIMES,
'timesB' => RPT_TIMESB,
'timesBI' => RPT_TIMESBI,
'timesI' => RPT_TIMESI);

// Available font sizes in units: points
$FontSizes = array (
Expand Down Expand Up @@ -108,9 +117,17 @@
'k' => RPT_YTD,
'l' => RPT_YESTERDAY,
'm' => RPT_LASTWEEK,
'n' => RPT_LASTMONTH,
'o' => RPT_LASTQUARTER,
'p' => RPT_LASTYEAR);
'n' => RPT_LASTWTD,
'o' => RPT_LASTMONTH,
'p' => RPT_LASTMTD,
'q' => RPT_LASTQUARTER,
'r' => RPT_LASTQTD,
's' => RPT_LASTYEAR,
't' => RPT_LASTYTD,
'u' => RPT_NEXTWEEK,
'v' => RPT_NEXTMONTH,
'w' => RPT_NEXTQUARTER,
'x' => RPT_NEXTYEAR);

/*********************************************************************************************
Form unique defaults
Expand Down
28 changes: 19 additions & 9 deletions reportwriter/admin/forms/ReportsCritSetup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_CRIT; ?></h2>
<form name="CritFieldForm" method="post" action="ReportCreator.php?action=step7">
<input type="hidden" name="FormID" value="<?php echo $_SESSION['FormID']; ?>" />
<input type="hidden" name="FormID" value="<?php echo $_SESSION['FormID']; ?>">
<input name="ReportID" type="hidden" value="<?php echo $ReportID; ?>">
<input name="Type" type="hidden" value="<?php echo $Type; ?>">
<input name="ReportName" type="hidden" value="<?php echo $reportname; ?>">
Expand All @@ -13,11 +13,11 @@ <h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_C
</table>
<table width="700" align="center" border="2" cellspacing="1" cellpadding="1">
<tr bgcolor="#CCCCCC">
<td colspan="4"><div align="center"><?php echo RPT_DATEINFO; ?></div></td>
<td colspan="5"><div align="center"><?php echo RPT_DATEINFO; ?></div></td>
</tr>
<tr>
<td width="25%"><?php echo RPT_DATELIST; ?><br /><br /><?php echo RPT_DATEINST; ?></td>
<td width="25%">
<td width="40%"><?php echo RPT_DATELIST; ?><br /><br /><?php echo RPT_DATEINST; ?></td>
<td width="15%">
<?php if (mb_strpos($DateListings['displaydesc'],'a')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange1" value="a"<?php echo $Checked; ?>><?php echo $DateChoices['a']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'b')===false) $Checked = ''; else $Checked = ' checked'; ?>
Expand All @@ -31,7 +31,7 @@ <h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_C
<?php if (mb_strpos($DateListings['displaydesc'],'f')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange6" value="f"<?php echo $Checked; ?>><?php echo $DateChoices['f']; ?><br />
</td>
<td width="25%">
<td width="15%">
<?php if (mb_strpos($DateListings['displaydesc'],'g')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange7" value="g"<?php echo $Checked; ?>><?php echo $DateChoices['g']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'h')===false) $Checked = ''; else $Checked = ' checked'; ?>
Expand All @@ -43,7 +43,7 @@ <h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_C
<?php if (mb_strpos($DateListings['displaydesc'],'k')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange11" value="k"<?php echo $Checked; ?>><?php echo $DateChoices['k']; ?><br />
</td>
<td width="25%">
<td width="15%">
<?php if (mb_strpos($DateListings['displaydesc'],'l')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange12" value="l"<?php echo $Checked; ?>><?php echo $DateChoices['l']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'m')===false) $Checked = ''; else $Checked = ' checked'; ?>
Expand All @@ -55,10 +55,20 @@ <h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_C
<?php if (mb_strpos($DateListings['displaydesc'],'p')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange16" value="p"<?php echo $Checked; ?>><?php echo $DateChoices['p']; ?><br />
</td>
<td width="15%">
<?php if (mb_strpos($DateListings['displaydesc'],'q')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange17" value="q"<?php echo $Checked; ?>><?php echo $DateChoices['q']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'r')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange18" value="r"<?php echo $Checked; ?>><?php echo $DateChoices['r']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'s')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange19" value="s"<?php echo $Checked; ?>><?php echo $DateChoices['s']; ?><br />
<?php if (mb_strpos($DateListings['displaydesc'],'t')===false) $Checked = ''; else $Checked = ' checked'; ?>
<input type="checkbox" name="DateRange20" value="t"<?php echo $Checked; ?>><?php echo $DateChoices['t']; ?><br />
</td>
</tr>
<tr>
<td><?php echo RPT_DATEDEF; ?></td>
<td colspan="3"><select name="DefDate">
<td colspan="4"><select name="DefDate">
<?php foreach($DateChoices as $key=>$value) {
if ($DateListings['params']==$key) $Selected = ' selected'; else $Selected = '';
echo '<option value="'.$key.'"'.$Selected.'>'.$value.'</option>';
Expand All @@ -67,15 +77,15 @@ <h2 align="center"><?php echo $FormParams['heading'].$reportname.' - '.RPT_BTN_C
</tr>
<tr>
<td><?php echo RPT_DATEFNAME; ?></td>
<td colspan="3">
<td colspan="4">
<select name="DateField"><OPTION Value=""><?php echo RPT_SLCTFIELD; ?>
<?php echo CreateFieldList($ReportID,$DateListings['fieldname'],''); ?></select>
</td>
</tr>
<?php if ($Type<>'frm') { ?>
<tr>
<td><?php echo RPT_TRUNC; ?></td>
<td colspan="3"><p>
<td colspan="4"><p>
<?php if ($TruncListings['params']=='1') $Checked = ' checked'; else $Checked = ''; ?>
<input type="radio" name="TruncLongDesc" value="1"<?php echo $Checked; ?>><?php echo RPT_YES; ?>
<?php if ($TruncListings['params']=='0') $Checked = ' checked'; else $Checked = ''; ?>
Expand Down
Loading

0 comments on commit f3aeea5

Please sign in to comment.