Skip to content

Commit

Permalink
Merge pull request #2515 from phili67/phili67-confirmreport-v2
Browse files Browse the repository at this point in the history
ConfirmReport : update
  • Loading branch information
phili67 committed Nov 5, 2023
2 parents c11222a + cb199db commit fe3b4aa
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 111 deletions.
15 changes: 11 additions & 4 deletions src/EcclesiaCRM/Reports/ChurchInfoReportTCPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public function StripPhone($phone)

public function PrintRightJustified($x, $y, $str)
{
$str = str_replace('\n', chr(10), $str);

$iLen = mb_strlen($str);
$nMoveBy = 10 - 2 * $iLen;
$this->SetXY($x + $nMoveBy, $y);
Expand All @@ -143,26 +145,31 @@ public function PrintRightJustified($x, $y, $str)

public function PrintRightJustifiedCell($x, $y, $wid, $str)
{
$str = str_replace('\n', chr(10), $str);
$this->SetXY($x, $y);
$this->Cell($wid, SystemConfig::getValue('incrementY'), $str, 1, 0, 'R');
}

public function PrintCenteredCell($x, $y, $wid, $str)
{
$str = str_replace('\n', chr(10), $str);
$this->SetXY($x, $y);
$this->Cell($wid, SystemConfig::getValue('incrementY'), $str, 1, 0, 'C');
}

public function WriteAt($x, $y, $str)
{
$str = str_replace('\n', chr(10), $str);

$this->SetXY($x, $y);
$this->Write(SystemConfig::getValue('incrementY'), $str);
}

public function WriteAtCell($x, $y, $wid, $str)
public function WriteAtCell($x, $y, $wid, $str, $border=1, $align="L")
{
$str = str_replace('\n', chr(10), $str);
$this->SetXY($x, $y);
$this->MultiCell($wid, 4, $str, 1, "L");
$this->MultiCell($wid, 4, $str, $border, $align);
}

public function StartLetterPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2, $fam_City, $fam_State, $fam_Zip, $fam_Country, $letterhead = '')
Expand Down Expand Up @@ -197,12 +204,12 @@ public function StartLetterPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, $fam_Address1);
$curY += SystemConfig::getValue('incrementY');
}
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, $fam_City.', '.$fam_State.' '.$fam_Zip);
$curY += SystemConfig::getValue('incrementY');
if ($fam_Address2 != '') {
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, $fam_Address2);
$curY += SystemConfig::getValue('incrementY');
}
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, $fam_City.', '.$fam_State.' '.$fam_Zip);
$curY += SystemConfig::getValue('incrementY');
if ($fam_Country != '' && $fam_Country != SystemConfig::getValue('sDefaultCountry')) {
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, $fam_Country);
$curY += SystemConfig::getValue('incrementY');
Expand Down
183 changes: 118 additions & 65 deletions src/Reports/ConfirmReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*******************************************************************************
*
* filename : Reports/ConfirmReport.php
* last change : 2020-10-04 Philippe Logel
* last change : 2023-11-04 Philippe Logel
* description : Creates a PDF with all the confirmation letters asking member
* families to verify the information in the database.
Expand Down Expand Up @@ -33,6 +33,7 @@ class PDF_ConfirmReport extends ChurchInfoReportTCPDF
{
private $incrY;
public $leftX;
public $_Custom;

// Constructor
public function __construct()
Expand All @@ -46,6 +47,15 @@ public function __construct()
$this->SetAutoPageBreak(false);
}

public function AddCustomField($order, $use)
{
$this->_Custom[$order] = $use;
}

public function GetCustomField($order) {
return $this->_Custom[$order];
}

public function StartNewPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2, $fam_City, $fam_State, $fam_Zip, $fam_Country)
{
$curY = $this->StartLetterPage($fam_ID, $fam_Name, $fam_Address1, $fam_Address2, $fam_City, $fam_State, $fam_Zip, $fam_Country, 'graphic');
Expand All @@ -68,19 +78,18 @@ public function FinishPage($curY)
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, SystemConfig::getValue('sConfirm4'));

if (SystemConfig::getValue('sConfirm5') != '') {
$curY += 2 * $this->incrY;
$curY += 4 * $this->incrY;
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, SystemConfig::getValue('sConfirm5'));
$curY += 2 * $this->incrY;
$curY += 1 * $this->incrY;
}
if (SystemConfig::getValue('sConfirm6') != '') {
$curY += 2 * $this->incrY;
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, SystemConfig::getValue('sConfirm6'));
}
//If the Reports Settings Menu's SystemConfig::getValue("sConfirmSigner") is set, then display the closing statement. Hide it otherwise.
if (SystemConfig::getValue('sConfirmSigner')) {
$curY += 4 * $this->incrY;
$curY += 2 * $this->incrY;
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, SystemConfig::getValue('sConfirmSincerely').',');
$curY += 4 * $this->incrY;
$curY += 1 * $this->incrY;
$this->WriteAt(SystemConfig::getValue('leftX'), $curY, SystemConfig::getValue('sConfirmSigner'));
}
}
Expand All @@ -91,6 +100,11 @@ public function FinishPage($curY)
exit;
}

if (isset($_SESSION['POST_Datas'])) {
$_POST = $_SESSION['POST_Datas'];
unset($_SESSION['POST_Datas']);
}

// Instantiate the directory class and build the report.
$pdf = new PDF_ConfirmReport();
$filename = 'ConfirmReport'.date(SystemConfig::getValue("sDateFilenameFormat")).'.pdf';
Expand All @@ -103,12 +117,16 @@ public function FinishPage($curY)
$numCustomFields = $ormCustomFields->count();

$sCustomFieldName = [];
$sCustomFieldTypeID = [];

if ( $ormCustomFields->count() > 0) {
$iFieldNum = 0;
foreach ($ormCustomFields as $customField) {
$sCustomFieldName[$iFieldNum] = $customField->getCustomName();
$sCustomFieldTypeID[$iFieldNum] = $customField->getTypeId();
$iFieldNum+=1;

$pdf->AddCustomField( $customField->getCustomOrder(), isset($_POST["bCustom".$customField->getCustomOrder()]) );
}
}

Expand All @@ -133,7 +151,10 @@ public function FinishPage($curY)

// Loop through families

$incrY = SystemConfig::getValue('incrementY') + 0.5;
$incrYAdd = 0.0;// +0.5
$fontSize = 8;

$incrY = SystemConfig::getValue('incrementY')+$incrYAdd;

foreach ($ormFamilies as $family) {
//If this is a report for a single family, name the file accordingly.
Expand All @@ -145,50 +166,57 @@ public function FinishPage($curY)
$family->getState(), $family->getZip(), $family->getCountry());
$curY += $incrY;

$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Family Name'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getName());
$curY += $incrY;
$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Address 1'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getAddress1());
$curY += $incrY;
$pdf->SetFont('Times', 'B', 10);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Address 2'));
$pdf->SetFont('Times', '', 10);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getAddress2());
$curY += $incrY;
$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('City, State, Zip'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, ($family->getCity().', '.$family->getState().' '.$family->getZip()));
$curY += $incrY;
$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Address 2'));
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getAddress2());
$curY += $incrY;
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Home Phone'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getHomePhone());
$curY += $incrY;
$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Send Newsletter'));
$pdf->SetFont('Times', '', 10);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getSendNewsletter());
$pdf->SetFont('Times', '', $fontSize);

$pdf->WriteAtCell($dataCol, $curY, $dataWid, "");
if ($family->getSendNewsletter() == 'FALSE') {
$pdf->CheckBox('newsletterFamily'.$family->getId(), 5, false, array(), array(), 'No', $dataCol, $curY);
} else {
$pdf->CheckBox('newsletterFamily'.$family->getId(), 5, true, array(), array(), 'Yes', $dataCol, $curY);
}

$curY += $incrY;

// Missing the following information from the Family record:
// Wedding date (if present) - need to figure how to do this with sensitivity
// Family e-mail address

$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Anniversary Date'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, OutputUtils::FormatDate((!is_null($family->getWeddingdate())?$family->getWeddingdate()->format('Y-m-d'):'')));
$curY += $incrY;

$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell(SystemConfig::getValue('leftX'), $curY, $dataCol - SystemConfig::getValue('leftX'), _('Family Email'));
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($dataCol, $curY, $dataWid, $family->getEmail());
$curY += $incrY;
$curY += $incrY;
Expand Down Expand Up @@ -224,42 +252,34 @@ public function FinishPage($curY)
$XWorkPhone = 155;
$XRight = 208;

$pdf->SetFont('Times', 'B', 10);
$pdf->WriteAtCell($XName, $curY, $XGender - $XName, _('Member Name'));
$pdf->WriteAtCell($XGender, $curY, $XRole - $XGender, _('M/F'));
$pdf->WriteAtCell($XRole, $curY, $XEmail - $XRole, _('Adult/Child'));
$pdf->WriteAtCell($XEmail, $curY, $XBirthday - $XEmail, _('Email'));
$pdf->WriteAtCell($XBirthday, $curY, $XHideAge - $XBirthday, _('Birthday'));
$pdf->WriteAtCell($XHideAge, $curY, $XCellPhone - $XHideAge, substr(_('Hide Age'),0,5));
$pdf->WriteAtCell($XCellPhone, $curY, $XClassification - $XCellPhone, substr(_('Cell phone'),0,13).".");
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, _('Member/Friend'));
$pdf->SetFont('Times', '', 10);
$curY += $incrY;

$numFamilyMembers = 0;
//while ($aMember = mysqli_fetch_array($rsFamilyMembers)) {
foreach ($ormFamilyMembers as $fMember) {
$numFamilyMembers++; // add one to the people count

// Make sure the person data will display with adequate room for the trailer and group information
if (($curY + $numCustomFields * $incrY) > 260) {
$curY = $pdf->StartLetterPage($family->getId(), $family->getName(), $family->getAddress1(), $family->getAddress2(), $family->getCity(), $family->getState(), $family->getZip(), $family->getCountry());
$pdf->SetFont('Times', 'B', 10);
$pdf->WriteAtCell($XName, $curY, $XGender - $XName, _('Member Name'));
$pdf->WriteAtCell($XGender, $curY, $XRole - $XGender, _('M/F'));
$pdf->WriteAtCell($XRole, $curY, $XEmail - $XRole, _('Adult/Child'));
$pdf->WriteAtCell($XEmail, $curY, $XBirthday - $XEmail, _('Email'));
$pdf->WriteAtCell($XBirthday, $curY, $XHideAge - $XBirthday, _('Birthday'));
$pdf->WriteAtCell($XHideAge, $curY, $XCellPhone - $XHideAge, substr(_('Hide Age'),0,5));
$pdf->WriteAtCell($XCellPhone, $curY, $XClassification - $XCellPhone, substr(_('Cell phone'),0,15).".");
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, _('Member/Friend'));
$pdf->SetFont('Times', '', 10);
$curY += $incrY;
$curY = $pdf->StartLetterPage($family->getId(), $family->getName(), $family->getAddress1(), $family->getAddress2(), $family->getCity(), $family->getState(), $family->getZip(), $family->getCountry());
}

$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell($XName, $curY, $XGender - $XName, _('Member Name'));
$pdf->WriteAtCell($XGender, $curY, $XRole - $XGender, _('M/F'));
$pdf->WriteAtCell($XRole, $curY, $XEmail - $XRole, _('Adult/Child'));
$pdf->WriteAtCell($XEmail, $curY, $XBirthday - $XEmail, _('Email'));
$pdf->WriteAtCell($XBirthday, $curY, $XHideAge - $XBirthday, _('Birthday'));
$pdf->SetFont('Times', 'B', 5);
$pdf->WriteAtCell($XHideAge, $curY, $XCellPhone - $XHideAge, _('Hide Age'), "LTR");
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell($XCellPhone, $curY, $XClassification - $XCellPhone, substr(_('Cell phone'),0,10).".");
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, _('Work Phone'));
$pdf->SetFont('Times', '', $fontSize);
$curY += $incrY;

$iPersonID = $fMember->getId();
$pdf->SetFont('Times', 'B', 10);
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell($XName, $curY, $XGender - $XName, $fMember->getFirstName().' '.$fMember->getMiddleName().' '.$fMember->getLastName());
$pdf->SetFont('Times', '', 10);
$pdf->SetFont('Times', '', $fontSize);
$genderStr = ($fMember->getGender() == 1 ? 'M' : 'F');
$pdf->WriteAtCell($XGender, $curY, $XRole - $XGender, $genderStr);
$pdf->WriteAtCell($XRole, $curY, $XEmail - $XRole, $fMember->getFamRole());
Expand All @@ -282,11 +302,29 @@ public function FinishPage($curY)
$pdf->WriteAtCell($XBirthday, $curY, $XHideAge - $XBirthday, $birthdayStr);
$pdf->WriteAtCell($XHideAge, $curY, $XCellPhone - $XHideAge, $hideAgeStr);
$pdf->WriteAtCell($XCellPhone, $curY, $XClassification - $XCellPhone, $fMember->getCellPhone());
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, $fMember->getClassName());
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, $fMember->getWorkPhone());

$curY += $incrY;
$curY += $incrY;
// Missing the following information for the personal record: ??? Is this the place to put this data ???
// Work Phone
$pdf->WriteAtCell($XWorkPhone, $curY, $XRight - $XWorkPhone, _('Work Phone').':'.$fMember->getWorkPhone());
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell($XGender, $curY, $XEmail - $XGender, _('Send Newsletter'));
$pdf->WriteAtCell($XEmail, $curY, $XBirthday - $XEmail, "");
if ($fMember->getSendNewsletter() == 'FALSE') {
$pdf->CheckBox('newsletterPerson'.$fMember->getId(), 5, false, array(), array(), 'No', $XEmail, $curY);
} else {
$pdf->CheckBox('newsletterPerson'.$fMember->getId(), 5, true, array(), array(), 'Yes', $XEmail, $curY);
}


$pdf->WriteAtCell($XCellPhone, $curY, $XClassification - $XCellPhone, _('Classification'));
$pdf->SetFont('Times', '', $fontSize);
$pdf->WriteAtCell($XClassification, $curY, $XRight - $XClassification, $fMember->getClassName());




$curY += $incrY;
$curY += $incrY;

Expand Down Expand Up @@ -315,20 +353,35 @@ public function FinishPage($curY)
// Leaving 12 mm for a bottom margin yields 183 mm.
$numWide = 0; // starting value for columns
foreach ($ormCustomFields as $custField) {

if ($pdf->GetCustomField($custField->getCustomOrder()) == 0) continue;

if ($sCustomFieldName[$custField->getCustomOrder() - 1]) {
$currentFieldData = trim($aCustomData[$custField->getCustomField()]);

$currentFieldData = OutputUtils::displayCustomField($custField->getTypeId(), trim($aCustomData[$custField->getCustomField()]), $custField->getCustomSpecial(), false);

$OutStr = $sCustomFieldName[$custField->getCustomOrder() - 1].' : '.$currentFieldData.' ';
$pdf->WriteAtCell($xInc, $curY, $xSize, $sCustomFieldName[$custField->getCustomOrder() - 1]);
if ($currentFieldData == '') {
$pdf->SetFont('Times', 'B', 10);
$pdf->WriteAtCell($xInc + $xSize, $curY, $xSize, '');
$pdf->SetFont('Times', '', 10);
} else {
$pdf->WriteAtCell($xInc + $xSize, $curY, $xSize, $currentFieldData);
}
if ($sCustomFieldTypeID[$custField->getCustomOrder() - 1] == 1) {
$pdf->WriteAtCell($xInc, $curY, $xSize, $sCustomFieldName[$custField->getCustomOrder() - 1]);
$pdf->WriteAtCell($xInc + $xSize, $curY, $xSize, "");
if (is_null($currentFieldData) or $currentFieldData == '' or $currentFieldData == 'FALSE') {
$pdf->CheckBox('props'.$custField->getId(), 5, false, array(), array(), 'No', $xInc + $xSize, $curY);
} else {
$pdf->CheckBox('props'.$custField->getId(), 5, true, array(), array(), 'Yes', $xInc + $xSize, $curY);
}
} else {
$OutStr = $sCustomFieldName[$custField->getCustomOrder() - 1].' : '.$currentFieldData.' ';
$pdf->WriteAtCell($xInc, $curY, $xSize, $sCustomFieldName[$custField->getCustomOrder() - 1]);

if ($currentFieldData == '') {
$pdf->SetFont('Times', 'B', $fontSize);
$pdf->WriteAtCell($xInc + $xSize, $curY, $xSize, '');
$pdf->SetFont('Times', '', $fontSize);
} else {
$pdf->WriteAtCell($xInc + $xSize, $curY, $xSize, $currentFieldData);
}
}

$numWide += 1; // increment the number of columns done
$xInc += (2 * $xSize); // Increment the X position by about 1/2 page width
if (($numWide % 2) == 0) { // 2 columns
Expand Down Expand Up @@ -396,4 +449,4 @@ public function FinishPage($curY)
$pdf->Output($filename, 'D');
} else {
$pdf->Output();
}
}
Loading

0 comments on commit fe3b4aa

Please sign in to comment.