1
|
|
|
<?php |
2
|
|
|
class Intraface_modules_debtor_Controller_Collection extends k_Component |
3
|
|
|
{ |
4
|
|
|
protected $error; |
5
|
|
|
protected $debtor; |
6
|
|
|
protected $template; |
7
|
|
|
protected $gateway; |
8
|
|
|
protected $doctrine; |
9
|
|
|
|
10
|
|
|
function __construct(k_TemplateFactory $template, Doctrine_Connection_Common $doctrine) |
11
|
|
|
{ |
12
|
|
|
$this->template = $template; |
13
|
|
|
$this->doctrine = $doctrine; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function map($name) |
17
|
|
|
{ |
18
|
|
|
if (is_numeric($name)) { |
19
|
|
|
return 'Intraface_modules_debtor_Controller_Show'; |
20
|
|
|
} elseif ($name == 'create') { |
21
|
|
|
return 'Intraface_modules_debtor_Controller_Create'; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function renderHtml() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$debtor_module = $this->getKernel()->module('debtor'); |
|
|
|
|
28
|
|
|
$contact_module = $this->getKernel()->useModule('contact'); |
|
|
|
|
29
|
|
|
$product_module = $this->getKernel()->useModule('product'); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->getGateway()->setType($this->getType()); |
32
|
|
|
|
33
|
|
|
if (intval($this->query("contact_id")) != 0) { |
34
|
|
|
$this->getGateway()->getDBQuery()->setFilter("contact_id", $this->query("contact_id")); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if (intval($this->query("product_id")) != 0) { |
38
|
|
|
$this->getGateway()->getDBQuery()->setFilter("product_id", $this->query("product_id")); |
39
|
|
|
if (isset($_GET['product_variation_id'])) { |
40
|
|
|
$this->getGateway()->getDBQuery()->setFilter("product_variation_id", $_GET["product_variation_id"]); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// søgning |
45
|
|
|
if (isset($_GET["text"]) && $_GET["text"] != "") { |
46
|
|
|
$this->getGateway()->getDBQuery()->setFilter("text", $_GET["text"]); |
47
|
|
|
} |
48
|
|
|
if (isset($_GET["date_field"]) && $_GET["date_field"] != "") { |
49
|
|
|
$this->getGateway()->getDBQuery()->setFilter("date_field", $_GET["date_field"]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (isset($_GET["from_date"]) && $_GET["from_date"] != "") { |
53
|
|
|
$this->getGateway()->getDBQuery()->setFilter("from_date", $_GET["from_date"]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (isset($_GET["to_date"]) && $_GET["to_date"] != "") { |
57
|
|
|
$this->getGateway()->getDBQuery()->setFilter("to_date", $_GET["to_date"]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if ($this->getGateway()->getDBQuery()->checkFilter("contact_id")) { |
61
|
|
|
$this->getGateway()->getDBQuery()->setFilter("status", "-1"); |
62
|
|
View Code Duplication |
} elseif (isset($_GET["status"]) && $_GET['status'] != '') { |
63
|
|
|
$this->getGateway()->getDBQuery()->setFilter("status", $_GET["status"]); |
64
|
|
|
} else { |
65
|
|
|
$this->getGateway()->getDBQuery()->setFilter("status", "-2"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (!empty($_GET['not_stated']) and $_GET['not_stated'] == 'true') { |
|
|
|
|
69
|
|
|
$this->getGateway()->getDBQuery()->setFilter("not_stated", true); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (isset($_GET['sorting']) && $_GET['sorting'] != 0) { |
73
|
|
|
$this->getGateway()->getDBQuery()->setFilter("sorting", $_GET['sorting']); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->getGateway()->getDBQuery()->usePaging("paging", $this->getKernel()->setting->get('user', 'rows_pr_page')); |
77
|
|
|
$this->getGateway()->getDBQuery()->storeResult("use_stored", $this->getType(), "toplevel"); |
78
|
|
|
//$debtor->getDBQuery()->setExtraUri('&type='.$debtor->get("type")); |
|
|
|
|
79
|
|
|
$this->getGateway()->getDBQuery()->setUri($this->url(null, array('use_stored' => 'true'))); |
80
|
|
|
|
81
|
|
|
$data = array( |
82
|
|
|
'posts' => $this->getGateway()->findAll(), |
83
|
|
|
'debtor' => $this->getGateway()); |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
// @todo kan følgende ikke lige så godt hente fra $this->query() |
87
|
|
|
if (intval($this->getGateway()->getDBQuery()->getFilter('product_id')) != 0) { |
88
|
|
|
$data['product'] = new Product($this->getKernel(), $this->getGateway()->getDBQuery()->getFilter('product_id')); |
89
|
|
View Code Duplication |
if (intval($this->getGateway()->getDBQuery()->getFilter('product_variation_id')) != 0) { |
90
|
|
|
$data['variation'] = $data['product']->getVariation($this->getGateway()->getDBQuery()->getFilter('product_variation_id')); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
View Code Duplication |
if (intval($this->getGateway()->getDBQuery()->getFilter('contact_id')) != 0) { |
94
|
|
|
$data['contact'] = new Contact($this->getKernel(), $this->getGateway()->getDBQuery()->getFilter('contact_id')); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$smarty = $this->template->create(dirname(__FILE__) . '/templates/collection'); |
98
|
|
|
return $smarty->render($this, $data); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
function postForm() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$debtor = $this->getDebtor(); |
|
|
|
|
104
|
|
|
$contact = new Contact($this->getKernel(), $_POST["contact_id"]); |
105
|
|
|
|
106
|
|
|
if (isset($_POST["contact_person_id"]) && $_POST["contact_person_id"] == "-1") { |
107
|
|
|
$contact_person = new ContactPerson($contact); |
108
|
|
|
$person["name"] = $_POST['contact_person_name']; |
|
|
|
|
109
|
|
|
$person["email"] = $_POST['contact_person_email']; |
110
|
|
|
$contact_person->save($person); |
111
|
|
|
$contact_person->load(); |
112
|
|
|
$_POST["contact_person_id"] = $contact_person->get("id"); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if ($this->getKernel()->intranet->hasModuleAccess('currency') && !empty($_POST['currency_id'])) { |
116
|
|
|
$currency_module = $this->getKernel()->useModule('currency', false); // false = ignore user access |
|
|
|
|
117
|
|
|
$gateway = new Intraface_modules_currency_Currency_Gateway($this->doctrine); |
118
|
|
|
$currency = $gateway->findById($_POST['currency_id']); |
119
|
|
|
if ($currency == false) { |
120
|
|
|
throw new Exception('Invalid currency'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$_POST['currency'] = $currency; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if ($debtor->update($_POST)) { |
127
|
|
|
return new k_SeeOther($this->url('../list/' . $debtor->get('id'))); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->render(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
function renderXls() |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
if ($this->query('simple')) { |
136
|
|
|
Intraface_Doctrine_Intranet::singleton($this->getKernel()->intranet->getId()); |
137
|
|
|
|
138
|
|
|
$debtor = Debtor::factory($this->getKernel(), intval($_GET["id"]), $this->getType()); |
139
|
|
|
$dbquery = $debtor->getDbQuery(); |
140
|
|
|
$type = $this->getType(); |
141
|
|
|
unset($debtor); |
142
|
|
|
|
143
|
|
|
$dbquery->storeResult("use_stored", $type, "toplevel"); |
144
|
|
|
$dbquery->loadStored(); |
145
|
|
|
|
146
|
|
|
$gateway = new Intraface_modules_debtor_DebtorDoctrineGateway($this->doctrine, $this->getKernel()->user); |
147
|
|
|
// echo number_format(memory_get_usage())." After gateway initializd<br />"; die; |
|
|
|
|
148
|
|
|
$posts = $gateway->findByDbQuerySearch($dbquery); |
149
|
|
|
|
150
|
|
|
/* |
|
|
|
|
151
|
|
|
echo '<pre>'; |
152
|
|
|
var_dump($posts->getFirst()->toArray()); die(); |
153
|
|
|
print_r($posts->toArray(true)); |
154
|
|
|
echo '</pre>'; |
155
|
|
|
echo number_format(memory_get_usage())." After gateway initializd<br />"; die; |
156
|
|
|
*/ |
157
|
|
|
|
158
|
|
|
// spreadsheet |
159
|
|
|
$workbook = new Spreadsheet_Excel_Writer(); |
160
|
|
|
$workbook->setVersion(8); |
161
|
|
|
|
162
|
|
|
$workbook->send('debtor.xls'); |
163
|
|
|
|
164
|
|
|
$format_bold = $workbook->addFormat(); |
165
|
|
|
$format_bold->setBold(); |
166
|
|
|
$format_bold->setSize(8); |
167
|
|
|
|
168
|
|
|
$format_italic = $workbook->addFormat(); |
169
|
|
|
$format_italic->setItalic(); |
170
|
|
|
$format_italic->setSize(8); |
171
|
|
|
|
172
|
|
|
$format = $workbook->addFormat(); |
173
|
|
|
$format->setSize(8); |
174
|
|
|
|
175
|
|
|
// Creating a worksheet |
176
|
|
|
$worksheet = $workbook->addWorksheet(ucfirst($this->t($this->getType()))); |
177
|
|
|
$worksheet->setInputEncoding('UTF-8'); |
178
|
|
|
|
179
|
|
|
$i = 1; |
180
|
|
|
$worksheet->write($i, 0, $this->getKernel()->intranet->get('name'), $format_bold); |
181
|
|
|
$i++; |
182
|
|
|
|
183
|
|
|
$status_types = array( |
184
|
|
|
-3 => 'Afskrevet', |
185
|
|
|
-2 => 'Åbne', |
186
|
|
|
-1 => 'Alle', |
187
|
|
|
0 => 'Oprettet', |
188
|
|
|
1 => 'Sendt', |
189
|
|
|
2 => 'Afsluttet', |
190
|
|
|
3 => 'Annulleret'); |
191
|
|
|
|
192
|
|
|
$worksheet->write($i, 0, 'Status', $format_italic); |
193
|
|
|
$worksheet->write($i, 1, $status_types[$dbquery->getFilter('status')], $format_italic); |
194
|
|
|
$i++; |
195
|
|
|
|
196
|
|
|
$worksheet->write($i, 0, 'Søgetekst', $format_italic); |
197
|
|
|
$worksheet->write($i, 1, $dbquery->getFilter('text'), $format_italic); |
198
|
|
|
$i++; |
199
|
|
|
|
200
|
|
|
if ($dbquery->checkFilter('product_id')) { |
201
|
|
|
$product = new Product($this->getKernel(), $dbquery->getFilter('product_id')); |
202
|
|
|
|
203
|
|
|
$worksheet->write($i, 0, 'Produkt', $format_italic); |
204
|
|
|
$worksheet->write($i, 1, $product->get('name'), $format_italic); |
205
|
|
|
$i++; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
if ($dbquery->checkFilter('contact_id')) { |
209
|
|
|
$contact = new Contact($this->getKernel(), $dbquery->getFilter('contact_id')); |
210
|
|
|
|
211
|
|
|
$worksheet->write($i, 0, 'Kontakt', $format_italic); |
212
|
|
|
$worksheet->write($i, 1, $contact->address->get('name'), $format_italic); |
213
|
|
|
$i++; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$worksheet->write($i, 0, "Antal i søgningen", $format_italic); |
217
|
|
|
$worksheet->write($i, 1, count($posts), $format_italic); |
218
|
|
|
$i++; |
219
|
|
|
|
220
|
|
|
$i++; |
221
|
|
|
$worksheet->write($i, 0, 'Nummer', $format_bold); |
222
|
|
|
$worksheet->write($i, 1, 'Kontakt nummer', $format_bold); |
223
|
|
|
$worksheet->write($i, 2, 'Kontakt navn', $format_bold); |
224
|
|
|
$worksheet->write($i, 3, 'Beskrivelse', $format_bold); |
225
|
|
|
$worksheet->write($i, 4, 'Beløb', $format_bold); |
226
|
|
|
$worksheet->write($i, 5, 'Oprettet', $format_bold); |
227
|
|
|
$worksheet->write($i, 6, 'Sendt', $format_bold); |
228
|
|
|
//$worksheet->write($i, 7, __("due_date"), $format_bold); |
|
|
|
|
229
|
|
|
$c = 8; |
230
|
|
|
if ($type == 'invoice') { |
231
|
|
|
$worksheet->write($i, $c, 'Forfaldsbeløb', $format_bold); |
232
|
|
|
$c++; |
233
|
|
|
} |
234
|
|
|
$worksheet->write($i, $c, 'Kontaktnøgleord', $format_bold); |
235
|
|
|
$c++; |
236
|
|
|
|
237
|
|
View Code Duplication |
if (!empty($product) && is_object($product) && get_class($product) == 'product') { |
238
|
|
|
$worksheet->write($i, $c, 'Antal valgte produkt', $format_bold); |
239
|
|
|
$c++; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$i++; |
243
|
|
|
|
244
|
|
|
$due_total = 0; |
245
|
|
|
$sent_total = 0; |
246
|
|
|
$total = 0; |
247
|
|
|
|
248
|
|
|
foreach ($posts as $debtor) { |
249
|
|
|
if (strtotime($debtor->getDueDate()->getAsIso()) < time() && ($debtor->getStatus() == "created" or $debtor->getStatus() == "sent")) { |
|
|
|
|
250
|
|
|
$due_total += $debtor->getTotal()->getAsIso(2); |
251
|
|
|
} |
252
|
|
|
if ($debtor->getStatus() == "sent") { |
253
|
|
|
$sent_total += $debtor->getTotal()->getAsIso(2); |
254
|
|
|
} |
255
|
|
|
$total += $debtor->getTotal()->getAsIso(2); |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @todo this could be done with Doctrine, but this seems only to have minimal memory usage |
259
|
|
|
*/ |
260
|
|
|
$contact = new Contact($this->getKernel(), $debtor->contact_id); |
261
|
|
|
$worksheet->write($i, 0, $debtor->getNumber()); |
262
|
|
|
$worksheet->write($i, 1, $contact->get('number')); // $posts[$j]['contact']['number'] |
|
|
|
|
263
|
|
|
$worksheet->write($i, 2, $contact->get('name')); |
264
|
|
|
$worksheet->write($i, 3, $debtor->getDescription()); |
265
|
|
|
$worksheet->writeNumber($i, 4, $debtor->getTotal()->getAsIso()); |
266
|
|
|
$worksheet->write($i, 5, $debtor->getDebtorDate()->getAsLocal('da_DK')); |
267
|
|
|
|
268
|
|
|
if ($debtor->getStatus() != "created") { |
269
|
|
|
$worksheet->write($i, 6, $debtor->getDateSent()->getAsLocal('da_DK')); |
270
|
|
|
} else { |
271
|
|
|
$worksheet->write($i, 6, "Nej"); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
if ($debtor->getStatus() == "executed" || $debtor->getStatus() == "canceled") { |
275
|
|
|
$worksheet->write($i, 7, $this->t($debtor->getStatus())); |
276
|
|
|
} else { |
277
|
|
|
$worksheet->write($i, 7, $debtor->getDueDate()->getAsLocal('da_DK')); |
278
|
|
|
} |
279
|
|
|
$c = 8; |
280
|
|
|
if ($type == 'invoice') { |
281
|
|
|
$worksheet->write($i, $c, '-'); // $posts[$j]['arrears'] |
|
|
|
|
282
|
|
|
$c++; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/* |
|
|
|
|
286
|
|
|
// not implemented |
287
|
|
|
$keywords = array(); |
288
|
|
|
$contact = new Contact($this->getKernel(), $posts[$j]['contact']['id']); |
289
|
|
|
$appender = $contact->getKeywordAppender(); |
290
|
|
|
$keyword_ids = $appender->getConnectedKeywords(); |
291
|
|
|
if (count($keyword_ids) > 0) { |
292
|
|
|
foreach ($keyword_ids AS $keyword_id) { |
293
|
|
|
$keyword = new Keyword($contact, $keyword_id); |
294
|
|
|
$keywords[] = $keyword->getKeyword(); |
295
|
|
|
} |
296
|
|
|
$worksheet->write($i, $c, implode(', ', $keywords)); |
297
|
|
|
$c++; |
298
|
|
|
}*/ |
299
|
|
|
|
300
|
|
|
/* |
|
|
|
|
301
|
|
|
// not implemented |
302
|
|
|
if (!empty($product) && is_object($product) && get_class($product) == 'product') { |
303
|
|
|
$quantity_product = 0; |
304
|
|
|
if (count($posts[$j]['items']) > 0) { |
305
|
|
|
foreach ($posts[$j]['items'] AS $item) { |
306
|
|
|
if ($item['product_id'] == $product->get('id')) { |
307
|
|
|
$quantity_product += $item['quantity']; |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
$worksheet->write($i, $c, $quantity_product); |
312
|
|
|
$c++; |
313
|
|
|
}*/ |
314
|
|
|
|
315
|
|
|
$i++; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
$i++; |
320
|
|
|
$i++; |
321
|
|
|
|
322
|
|
|
$worksheet->write($i, 0, 'Forfaldne', $format_italic); |
323
|
|
|
$worksheet->write($i, 1, number_format($due_total, 2, ",", "."), $format_italic); |
324
|
|
|
$i++; |
325
|
|
|
|
326
|
|
|
$worksheet->write($i, 0, 'Udestående (sendt):', $format_italic); |
327
|
|
|
$worksheet->write($i, 1, number_format($sent_total, 2, ",", "."), $format_italic); |
328
|
|
|
$i++; |
329
|
|
|
|
330
|
|
|
$worksheet->write($i, 0, 'Total:', $format_italic); |
331
|
|
|
$worksheet->write($i, 1, number_format($total, 2, ",", "."), $format_italic); |
332
|
|
|
$i++; |
333
|
|
|
|
334
|
|
|
// $worksheet->write($i, 0, number_format(memory_get_usage())); |
|
|
|
|
335
|
|
|
|
336
|
|
|
$worksheet->hideGridLines(); |
337
|
|
|
|
338
|
|
|
return $workbook->close(); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
$debtor_module = $this->getKernel()->module('debtor'); |
|
|
|
|
342
|
|
|
|
343
|
|
|
$this->getGateway()->getDBQuery()->storeResult("use_stored", $this->getType(), "toplevel"); |
344
|
|
|
|
345
|
|
|
$posts = $this->getGateway()->findAll(); |
346
|
|
|
|
347
|
|
|
// spreadsheet |
348
|
|
|
$workbook = new Spreadsheet_Excel_Writer(); |
349
|
|
|
|
350
|
|
|
$workbook->send('debtor.xls'); |
351
|
|
|
|
352
|
|
|
$format_bold = $workbook->addFormat(); |
353
|
|
|
$format_bold->setBold(); |
354
|
|
|
$format_bold->setSize(8); |
355
|
|
|
|
356
|
|
|
$format_italic = $workbook->addFormat(); |
357
|
|
|
$format_italic->setItalic(); |
358
|
|
|
$format_italic->setSize(8); |
359
|
|
|
|
360
|
|
|
$format = $workbook->addFormat(); |
361
|
|
|
$format->setSize(8); |
362
|
|
|
|
363
|
|
|
// Creating a worksheet |
364
|
|
|
$worksheet = $workbook->addWorksheet(ucfirst($this->t($this->getType()))); |
365
|
|
|
|
366
|
|
|
$i = 1; |
367
|
|
|
$worksheet->write($i, 0, $this->getKernel()->intranet->get('name'), $format_bold); |
368
|
|
|
$i++; |
369
|
|
|
|
370
|
|
|
$status_types = array( |
371
|
|
|
-3 => 'Afskrevet', |
372
|
|
|
-2 => 'Åbne', |
373
|
|
|
-1 => 'Alle', |
374
|
|
|
0 => 'Oprettet', |
375
|
|
|
1 => 'Sendt', |
376
|
|
|
2 => 'Afsluttet', |
377
|
|
|
3 => 'Annulleret'); |
378
|
|
|
|
379
|
|
|
$worksheet->write($i, 0, 'Status', $format_italic); |
380
|
|
|
$worksheet->write($i, 1, $status_types[$this->getGateway()->getDBQuery()->getFilter('status')], $format_italic); |
381
|
|
|
$i++; |
382
|
|
|
|
383
|
|
|
$worksheet->write($i, 0, 'Søgetekst', $format_italic); |
384
|
|
|
$worksheet->write($i, 1, $this->getGateway()->getDBQuery()->getFilter('text'), $format_italic); |
385
|
|
|
$i++; |
386
|
|
|
|
387
|
|
View Code Duplication |
if ($this->getGateway()->getDbQuery()->checkFilter('product_id')) { |
388
|
|
|
$product = new Product($this->getKernel(), $this->getGateway()->getDbQuery()->getFilter('product_id')); |
389
|
|
|
|
390
|
|
|
$worksheet->write($i, 0, 'Produkt', $format_italic); |
391
|
|
|
$worksheet->write($i, 1, $product->get('name'), $format_italic); |
392
|
|
|
$i++; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
View Code Duplication |
if ($this->getGateway()->getDbQuery()->checkFilter('contact_id')) { |
396
|
|
|
$contact = new Contact($this->getKernel(), $this->getGateway()->getDbQuery()->getFilter('contact_id')); |
397
|
|
|
|
398
|
|
|
$worksheet->write($i, 0, 'Kontakt', $format_italic); |
399
|
|
|
$worksheet->write($i, 1, $contact->address->get('name'), $format_italic); |
400
|
|
|
$i++; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
$worksheet->write($i, 0, "Antal i søgningen", $format_italic); |
404
|
|
|
$worksheet->write($i, 1, count($posts), $format_italic); |
405
|
|
|
$i++; |
406
|
|
|
|
407
|
|
|
$i++; |
408
|
|
|
$worksheet->write($i, 0, 'Nummer', $format_bold); |
409
|
|
|
$worksheet->write($i, 1, 'Kontakt nummer', $format_bold); |
410
|
|
|
$worksheet->write($i, 2, 'Kontakt navn', $format_bold); |
411
|
|
|
$worksheet->write($i, 3, 'Beskrivelse', $format_bold); |
412
|
|
|
$worksheet->write($i, 4, 'Beløb', $format_bold); |
413
|
|
|
$worksheet->write($i, 5, 'Oprettet', $format_bold); |
414
|
|
|
$worksheet->write($i, 6, 'Sendt', $format_bold); |
415
|
|
|
//$worksheet->write($i, 7, __("due_date"), $format_bold); |
|
|
|
|
416
|
|
|
$c = 8; |
417
|
|
|
if ($this->getGateway()->getType() == 'invoice') { |
418
|
|
|
$worksheet->write($i, $c, 'Forfaldsbeløb', $format_bold); |
419
|
|
|
$c++; |
420
|
|
|
} |
421
|
|
|
$worksheet->write($i, $c, 'Kontaktnøgleord', $format_bold); |
422
|
|
|
$c++; |
423
|
|
|
|
424
|
|
View Code Duplication |
if (!empty($product) && is_object($product) && get_class($product) == 'product') { |
425
|
|
|
$worksheet->write($i, $c, 'Antal valgte produkt', $format_bold); |
426
|
|
|
$c++; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
// HACK unsetting debtor which is actually ok to avoid memory problems // |
430
|
|
|
$type = $this->getType(); |
431
|
|
|
unset($debtor); |
432
|
|
|
// HACK end // |
433
|
|
|
|
434
|
|
|
$i++; |
435
|
|
|
|
436
|
|
|
$due_total = 0; |
437
|
|
|
$sent_total = 0; |
438
|
|
|
$total = 0; |
439
|
|
|
|
440
|
|
|
foreach ($posts as $post) { |
441
|
|
|
if ($post["due_date"] < date("Y-m-d") && ($post["status"] == "created" or $post["status"] == "sent")) { |
|
|
|
|
442
|
|
|
$due_total += $post["total"]; |
443
|
|
|
} |
444
|
|
|
if ($post["status"] == "sent") { |
445
|
|
|
$sent_total += $post["total"]; |
446
|
|
|
} |
447
|
|
|
$total += $post["total"]; |
448
|
|
|
|
449
|
|
|
$worksheet->write($i, 0, $post["number"]); |
450
|
|
|
$worksheet->write($i, 1, $post['contact']['number']); |
451
|
|
|
$worksheet->write($i, 2, $post["name"]); |
452
|
|
|
$worksheet->write($i, 3, $post["description"]); |
453
|
|
|
$worksheet->writeNumber($i, 4, $post["total"]); |
454
|
|
|
$worksheet->write($i, 5, $post["dk_this_date"]); |
455
|
|
|
|
456
|
|
|
if ($posts[$j]["status"] != "created") { |
|
|
|
|
457
|
|
|
$worksheet->write($i, 6, $post["dk_date_sent"]); |
458
|
|
|
} else { |
459
|
|
|
$worksheet->write($i, 6, "Nej"); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
if ($posts[$j]["status"] == "executed" || $post["status"] == "canceled") { |
463
|
|
|
$worksheet->write($i, 7, $this->t($post["status"], 'debtor')); |
|
|
|
|
464
|
|
|
} else { |
465
|
|
|
$worksheet->write($i, 7, $post["dk_due_date"]); |
466
|
|
|
} |
467
|
|
|
$c = 8; |
468
|
|
|
if ($type == 'invoice') { |
469
|
|
|
$worksheet->write($i, $c, $post['arrears']); |
470
|
|
|
$c++; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/* |
|
|
|
|
474
|
|
|
$keywords = array(); |
475
|
|
|
$contact = new Contact($this->getKernel(), $post['contact']['id']); |
476
|
|
|
$appender = $contact->getKeywordAppender(); |
477
|
|
|
$keyword_ids = $appender->getConnectedKeywords(); |
478
|
|
|
if (count($keyword_ids) > 0) { |
479
|
|
|
foreach ($keyword_ids AS $keyword_id) { |
480
|
|
|
$keyword = new Keyword($contact, $keyword_id); |
481
|
|
|
$keywords[] = $keyword->getKeyword(); |
482
|
|
|
} |
483
|
|
|
$worksheet->write($i, $c, implode(', ', $keywords)); |
484
|
|
|
$c++; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
if (!empty($product) && is_object($product) && get_class($product) == 'product') { |
488
|
|
|
$quantity_product = 0; |
489
|
|
|
if (count($post['items']) > 0) { |
490
|
|
|
foreach ($post['items'] AS $item) { |
491
|
|
|
if ($item['product_id'] == $product->get('id')) { |
492
|
|
|
$quantity_product += $item['quantity']; |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
$worksheet->write($i, $c, $quantity_product); |
497
|
|
|
$c++; |
498
|
|
|
} |
499
|
|
|
*/ |
500
|
|
|
|
501
|
|
|
$i++; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
$i++; |
505
|
|
|
$i++; |
506
|
|
|
|
507
|
|
|
$worksheet->write($i, 0, 'Forfaldne', $format_italic); |
508
|
|
|
$worksheet->write($i, 1, number_format($due_total, 2, ",", "."), $format_italic); |
509
|
|
|
$i++; |
510
|
|
|
|
511
|
|
|
$worksheet->write($i, 0, 'Udestående (sendt):', $format_italic); |
512
|
|
|
$worksheet->write($i, 1, number_format($sent_total, 2, ",", "."), $format_italic); |
513
|
|
|
$i++; |
514
|
|
|
|
515
|
|
|
$worksheet->write($i, 0, 'Total:', $format_italic); |
516
|
|
|
$worksheet->write($i, 1, number_format($total, 2, ",", "."), $format_italic); |
517
|
|
|
$i++; |
518
|
|
|
|
519
|
|
|
$worksheet->hideGridLines(); |
520
|
|
|
|
521
|
|
|
return $workbook->close(); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
function renderHtmlCreate() |
525
|
|
|
{ |
526
|
|
|
return new k_SeeOther($this->url('create')); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
function getReturnUrl($contact_id) |
530
|
|
|
{ |
531
|
|
|
return $this->url(null, array('create', 'contact_id' => $contact_id)); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
function getValues() |
535
|
|
|
{ |
536
|
|
|
return array( |
537
|
|
|
'number' => '' |
538
|
|
|
); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
function getAction() |
542
|
|
|
{ |
543
|
|
|
return 'Create'; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
function getType() |
547
|
|
|
{ |
548
|
|
|
return $this->context->getType(); |
|
|
|
|
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
function getContact() |
552
|
|
|
{ |
553
|
|
|
$module = $this->getKernel()->module('contact'); |
|
|
|
|
554
|
|
|
return new Contact($this->getKernel(), $this->query('contact_id')); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
function getGateway() |
558
|
|
|
{ |
559
|
|
|
Intraface_Doctrine_Intranet::singleton($this->getKernel()->intranet->getId()); |
560
|
|
|
|
561
|
|
|
if (!empty($this->gateway)) { |
562
|
|
|
return $this->gateway; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
$this->gateway = new Intraface_modules_debtor_DebtorGateway($this->getKernel()); |
566
|
|
|
return $this->gateway; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/* |
|
|
|
|
570
|
|
|
function getDebtor() |
571
|
|
|
{ |
572
|
|
|
if (is_object($this->debtor)) { |
573
|
|
|
return $this->debtor; |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
return ($this->debtor = Debtor::factory($this->getKernel(), $this->query('id'), $this->getType())); |
577
|
|
|
} |
578
|
|
|
*/ |
579
|
|
|
|
580
|
|
|
function getPosts() |
581
|
|
|
{ |
582
|
|
|
return $this->getGateway()->findAll(); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
function getKernel() |
586
|
|
|
{ |
587
|
|
|
return $this->context->getKernel(); |
|
|
|
|
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
function getError() |
591
|
|
|
{ |
592
|
|
|
if (is_object($this->error)) { |
593
|
|
|
return $this->error; |
594
|
|
|
} |
595
|
|
|
return ($this->error = new Intraface_Error()); |
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: