This repository was archived by the owner on Jul 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatement.class
More file actions
107 lines (94 loc) · 3.83 KB
/
statement.class
File metadata and controls
107 lines (94 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace CG;
use CG as r;
use CG\Util as u;
/**
* @file
* Common Good pdf class
* Extends the TCPDF class -- especially for custom headers and footer.
*/
require_once DRUPAL_ROOT . '/vendor/tcpdf/config/tcpdf_config.php'; // lang/eng.php';
require_once DRUPAL_ROOT . '/vendor/tcpdf/tcpdf.php';
class Statement extends \TCPDF {
public $regionName; // name of region
public $regionInfo; // addr, phone, email of region
public $qid; // Common Good account in header
public $period; // statement period
/**
* Create a pdf object for the given Common Good account.
* @param acct $a: the Common Good account object
* @param int $period: period date (for account statements) (defaults to current period)
*/
public function __construct($a = NULL, $period) {
// parent::__construct('P', 'in', 'LETTER');
parent::__construct('P', 'mm', 'LETTER');
u\setDft($a, r\acct());
$ctty = r\acct($a->community);
list ($this->regionName, $phone) = array($ctty->fullName, u\fmtPhone($ctty->phone));
$this->regionInfo = "$ctty->postalAddr<br>$phone • $ctty->email";
$this->qid = $a->mainQid;
$this->period = $period;
}
/**
* Output a cell
* Overrides parent just for testing.
*/
public function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M') {
global $formOut; if (u\test()) $formOut['text'] .= "$txt \n";
parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height, $calign, $valign);
}
public function Header() {
$m = 5; // basic margin
$this->Image(__DIR__ . '/images/' . PROJECT_LOGO, $m + 2, $m, 14, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetFont('helvetica', '', 9);
$this->writeHTMLCell(50, 0, $m + 20, $m + 2, '<b style="color:#004d00; font-stretch:expanded;">' . PROJECT . '™</b><br>' . t('the payment card<br>for community power'));
$this->writeHTMLCell(80, 0, $m + 65, $m + 2, "<b>$this->regionName</b><br>$this->regionInfo", 0, 0, FALSE, TRUE, 'C');
list ($page, $pages) = array($this->getAliasNumPage(), $this->getAliasNbPages());
$this->writeHTMLCell(50, 0, $m + 168, $m + 2, "<b>Account: $this->qid</b><br>$this->period<br>Page $page of $pages");
$this->Line($m, $m + 17, $m + 200, $m + 17);
}
public function Footer() {
$h = $this->getPageHeight();
$this->Line(5, $h - 13, 5 + 200, $h - 13);
$this->SetFont('helvetica', '', 9);
$this->SetY(-13);
$this->Cell(0, 10, t('To manage your account, sign in at %CG_DOMAIN'), 0, '', 'C');
}
/**
* Output a solid-background section header bar.
* @param string $subtitle: section header text
*/
function barHead($subtitle) {
$size = $this->getFontSizePt();
$this->SetTextColor(255,255,255);
$this->setFontSize(1.2 * $size);
$this->SetFillColor(0,0,128);
$this->Cell(0, 0, $subtitle, '', 1, 'C', TRUE);
$this->setFontSize(.5 * $size);
$this->newLine();
$this->setFontSize($size);
$this->SetTextColor();
}
/**
* Output column headers.
*/
function colHeads($fields) {
$size = $this->getFontSizePt();
$this->SetTextColor(0,0,128);
foreach ($fields as $one) {
list ($head, $fieldName, $width, $align) = explode('/', $one);
$this->Cell($width, 0, $head, '', 0, $align);
}
$this->newLine();
$this->SetTextColor();
}
function newLine() {$this->Cell(0, 0, '', '', 1);}
/**
* Close and output PDF document
* @param string $dest: I=inline (to browser) D=download F=to file,...
*/
public function finish($filename = '', $dest = 'I') { // must be same args and defaults as in TCPDF
// if (isDEV) parent::Output(TEST_PDF_FLNM, 'F'); // for testing
if (u\test()) $this->Close(); else parent::Output($filename, $dest);
}
}