Ticket #50: invoice.tpl.php

File invoice.tpl.php, 10.8 kB (added by nagual69, 14 months ago)

tweaked

Line 
1<?php
2/**
3 * phpaga
4 *
5 * PDF template: show an invoice
6 *
7 * This file contains the necessary routines to manage expenses.
8 *
9 * @author Florian Lanthaler <florian@phpaga.net>
10 * @version $Id: invoice.tpl.php 888 2007-11-05 17:01:35Z florian $
11 *
12 * Copyright (c) 2003, Florian Lanthaler <florian@phpaga.net>
13 *
14 * All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
18 * met:
19 *
20 *    * Redistributions of source code must retain the above copyright
21 *      notice, this list of conditions and the following disclaimer.
22 *
23 *    * Redistributions in binary form must reproduce the above copyright
24 *      notice, this list of conditions and the following disclaimer in
25 *      the documentation and/or other materials provided with the
26 *      distribution.
27 *
28 *    * Neither the name of Florian Lanthaler nor the names of his
29 *      contributors may be used to endorse or promote products derived
30 *      from this software without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
35 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
36 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44
45$type = $data['type'];
46$info = $data['info'];
47$recipient = $data['recipient'];
48$letterhead = $data['letterhead'];
49$watermark = '';
50
51
52$this->ezSetMargins(140,
53                    70,
54                    PHPAGA_PDF_BORDER_LEFT,
55                    PHPAGA_PDF_BORDER_RIGHT);
56
57if ($letterhead)
58{
59    if (!isset($lethead) || !strlen($lethead))
60        include(PHPAGA_BASEPATH.'pdftemplates/letterhead.tpl.php');
61    $this->addObject($lethead,'all');
62}
63
64if ($type == PHPAGA_TYPE_INVOICE)
65{
66    $details = $info['bill_details'];
67    $header = array(array('label' => sprintf("%s:", utf8_decode(_('Invoice'))),
68                          'text' => $info['bill_number']),
69
70                    array('label' => sprintf("%s:",_('Date')),
71                          'text' => date(PHPAGA_DATEFORMAT_PRINT,
72                                         strtotime($info['bill_date']))));
73
74    if (isset($info['bill_date_due']) && strlen($info['bill_date_due']))
75        $header[] =  array('label' => sprintf("%s:",utf8_decode(_('Date due'))),
76                           'text' => date(PHPAGA_DATEFORMAT_PRINT,
77                                         strtotime($info['bill_date_due'])));
78
79    if (isset($info['bill_payterm']) && strlen($info['bill_payterm']))
80        $header[] =  array('label' => sprintf("%s:",utf8_decode(_('Term of payment'))),
81                           'text' => $info['bill_payterm']);
82
83    $watermark = sprintf(_("%s %s / %s"),
84                         utf8_decode(_('Invoice')), $info['bill_number'],
85                         date(PHPAGA_DATEFORMAT_PRINT,
86                              strtotime($info['bill_date'])));
87
88}
89else
90{
91    $details = $info['quot_details'];
92    $header = array(array('label' => sprintf("%s:",utf8_decode(_('Quotation'))),
93                          'text' => $info['quot_number']),
94
95                    array('label' => sprintf("%s:",utf8_decode(_('Date'))),
96                          'text' => date(PHPAGA_DATEFORMAT_PRINT,
97                                         strtotime($info['quot_date']))));
98
99    if (isset($info['quot_payterm']) && strlen($info['quot_payterm']))
100        $header[] =  array('label' => sprintf("%s:",utf8_decode(_('Term of payment'))),
101                           'text' => $info['quot_payterm']);
102
103    $watermark = sprintf(_("%s %s / %s"),
104                         utf8_decode(_('Quotation')), $info['quot_number'],
105                         date(PHPAGA_DATEFORMAT_PRINT,
106                              strtotime($info['quot_date'])));
107}
108
109$this->setColor(0.9, 0.9, 0.9, 1);
110
111$this->addText(PHPAGA_PDF_BORDER_LEFT,
112               PHPAGA_PDF_POS_Y_RECIPIENT + 20,
113               35,
114               $watermark);
115
116$this->setColor(0, 0, 0, 1);
117
118if (isset($recipient['cpn_taxnr']) && strlen($recipient['cpn_taxnr'])) {
119    $header[] = array('label' => sprintf("%s:",utf8_decode(_('VAT number'))),
120                      'text' => $recipient['cpn_taxnr']);
121}
122
123if ($recipient != null) {
124    include_once(PHPAGA_BASEPATH.'pdftemplates/recipient.tpl.php');
125}
126
127$this->ezSetY(PHPAGA_PDF_POS_Y_RECIPIENT - 25);
128
129$this->ezTable($header,
130               array('label' => '',
131                     'text' => ''),
132               '',
133               array('xPos' => PHPAGA_PDF_BORDER_LEFT + 10,
134                     'xOrientation' => 'right',
135                     'showHeadings' => 0,
136                     'shaded' => 0,
137                     'fontSize' => PHPAGA_PDF_FONT_SIZE_SMALL,
138                     'maxWidth' => PHPAGA_PDF_DOCWIDTH -
139                     (2 * PHPAGA_PDF_BORDER_LEFT),
140                     'showLines' => 0,
141                     'cols' =>
142                     array('label' =>
143                           array('justification' =>
144                                 'right'),
145                           'text' =>
146                           array('justification' =>
147                                 'left')),
148                     'protectRows' => 5));
149
150$setnum = $this->ezStartPageNumbers(PHPAGA_PDF_DOCWIDTH - PHPAGA_PDF_BORDER_LEFT,
151                                    PHPAGA_PDF_SEPARATOR_BOTTOM_HEIGHT - PHPAGA_PDF_HEADER_NEXTLINE,
152                                    PHPAGA_PDF_FONT_SIZE_SMALL,
153                                    'left',
154                                    _('Page').' {PAGENUM} / {TOTALPAGENUM}',
155                                    1);
156
157$this->ezSetDY(-PHPAGA_PDF_BILL_NEXTLINE * 2);
158
159/* line items */
160
161if (!isset($info['lineitems'])) {
162    $info['lineitems'] = array();
163
164}
165
166$this->ezTable($info['lineitems'],
167               array('lit_prodcode' => sprintf("<b>%s</b>", utf8_decode(_('Product code'))),
168                     'lit_desc' => sprintf("<b>%s</b>", utf8_decode(_('Description'))),
169                     'lit_qty' => sprintf("<b>%s</b>", utf8_decode(_('Qty./Hours'))),
170                     'lit_netprice_format' => sprintf("<b>%s</b>", utf8_decode(_('Net price')))),
171               '',
172               array('xPos' => PHPAGA_PDF_BORDER_LEFT + 5,
173                     'xOrientation' => 'right',
174                     'showHeadings' => 1,
175                     'shaded' => 0,
176                     'lineCol' => array(0.5, 0.5, 0.5),
177                     'outerLineThickness' => 0.3,
178                     'innerLineThickness' => 0.3,
179                     'fontSize' => PHPAGA_PDF_FONT_SIZE_SMALL,
180                     'width' => (PHPAGA_PDF_DOCWIDTH -
181                                 PHPAGA_PDF_BORDER_LEFT -
182                                 PHPAGA_PDF_BORDER_RIGHT),
183                     'maxWidth' => (PHPAGA_PDF_DOCWIDTH -
184                                    PHPAGA_PDF_BORDER_LEFT -
185                                    PHPAGA_PDF_BORDER_RIGHT),
186                     'showLines' => 2,
187                     'cols' => array('lit_qty' => array('justification' => 'right'),
188                                     'lit_netprice_format' => array('justification' => 'right'))));
189
190$this->ezSetDY(-PHPAGA_PDF_BILL_NEXTLINE);
191
192
193/* Expenses */
194
195if (isset($info['expenses']) && array($info['expenses']) && count($info['expenses'])) {
196
197    $expenses = array();
198
199    foreach ($info['expenses'] as $e)
200        $expenses[] = array('prj_title' => $e['prj_title'],
201                            'exp_date' => date(PHPAGA_DATEFORMAT_PRINT, strtotime($e['exp_date'])),
202                            'exp_desc' => $e['exp_desc'],
203                            'exp_sum' => phpaga_formatamount($e['exp_sum']));
204
205    $this->ezTable($expenses,
206                   array('prj_title' => sprintf("<b>%s</b>", utf8_decode(_('Project'))),
207                         'exp_date' => sprintf("<b>%s</b>", utf8_decode(_('Date'))),
208                         'exp_desc' => sprintf("<b>%s</b>", utf8_decode(_('Description'))),
209                         'exp_sum' => sprintf("<b>%s</b>", utf8_decode(_('Amount')))),
210                   utf8_decode(_('Reimbursable expenses')),
211                   array('titleFontSize' => PHPAGA_PDF_FONT_SIZE_SMALL,
212                         'xPos' => PHPAGA_PDF_BORDER_LEFT + 5,
213                         'xOrientation' => 'right',
214                         'showHeadings' => 1,
215                         'shaded' => 0,
216                         'lineCol' => array(0.5, 0.5, 0.5),
217                         'outerLineThickness' => 0.3,
218                         'innerLineThickness' => 0.3,
219                         'fontSize' => PHPAGA_PDF_FONT_SIZE_SMALL,
220                         'width' => (PHPAGA_PDF_DOCWIDTH -
221                                     PHPAGA_PDF_BORDER_LEFT -
222                                     PHPAGA_PDF_BORDER_RIGHT),
223                         'maxWidth' => (PHPAGA_PDF_DOCWIDTH -
224                                        PHPAGA_PDF_BORDER_LEFT -
225                                        PHPAGA_PDF_BORDER_RIGHT),
226                         'showLines' => 2,
227                         'cols' => array('exp_sum' => array('justification' => 'right'))));
228
229    $this->ezSetDY(-PHPAGA_PDF_BILL_NEXTLINE);
230
231}
232
233/* Details */
234
235$this->ezTable($details,
236               array('text' => '',
237                     'amount' => ''),
238               '',
239               array('xPos' => PHPAGA_PDF_BORDER_LEFT + 5,
240                     'xOrientation' => 'right',
241                     'showHeadings' => 0,
242                     'shaded' => 0,
243                     'fontSize' => PHPAGA_PDF_FONT_SIZE_SMALL,
244                     'width' => (PHPAGA_PDF_DOCWIDTH -
245                                 PHPAGA_PDF_BORDER_LEFT -
246                                 PHPAGA_PDF_BORDER_RIGHT),
247                     'maxWidth' => (PHPAGA_PDF_DOCWIDTH -
248                                    PHPAGA_PDF_BORDER_LEFT -
249                                    PHPAGA_PDF_BORDER_RIGHT),
250                     'showLines' => 2,
251                     'lineCol' => array(0.5, 0.5, 0.5),
252                     'outerLineThickness' => 0.3,
253                     'innerLineThickness' => 0.3,
254                     'cols' =>
255                     array('amount' =>
256                           array('justification' =>
257                                 'right')),
258                     'protectRows' => 10));
259
260$this->ezStopPageNumbers(1, 1, $setnum);
261
262if (($letterhead) && isset($lethead))
263{
264    $this->stopObject($lethead);
265    $this->ezSetMargins(30, 30, PHPAGA_PDF_BORDER_LEFT, PHPAGA_PDF_BORDER_RIGHT);
266
267}
268
269?>