-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwf-invc.php
717 lines (620 loc) · 20.8 KB
/
wf-invc.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
<?php
/*
PURPOSE: classes for managing Invoices in WorkFerret
HISTORY:
2013-11-08 split off from WorkFerret.main
*/
define('KS_CLASS_PROJECTS','clsWFProjects');
class clsWFInvoices extends clsTable_key_single {
use ftLinkableTable;
// ++ SETUP ++ //
public function __construct($iDB) {
parent::__construct($iDB);
$this->Name('invoice');
$this->KeyName('ID');
$this->ClassSng('clsWFInvoice');
$this->ActionKey('invc');
}
// -- SETUP -- //
// ++ DATA TABLES ACCESS ++ //
protected function ProjectTable($id=NULL) {
return $this->Engine()->Make(KS_CLASS_PROJECTS,$id);
}
// -- DATA TABLES ACCESS -- //
// ++ ACTIONS ++ //
/*-----
ACTION: Creates a new, empty invoice
INPUT:
iProj: ID of project to which this invoice will belong
iArSess: array of sessions to be included on the invoice (as a list of IDs)
Sessions may not be sorted correctly in this array, so Create should sort them
before generating invoice lines.
*/
public function Create($idProj,$sNotes) {
// get invoice sequencing information and generate the invoice number:
if (empty($idProj)) {
throw new exception('Internal Error: Trying to create invoice for unspecified project.');
}
$nSeq = $this->NextInvoiceSeq($idProj);
$idNext = $this->NextID();
$rcProj = $this->ProjectTable($idProj);
$strPfx = $rcProj->Value('InvcPfx');
$strInvcNum = sprintf('%1$05u-%2$s-%3$04u',$idNext,$strPfx,$nSeq);
// create the new invoice record
$db = $this->Engine();
$arIns = array(
'ID_Proj' => $idProj,
'InvcSeq' => $nSeq,
'InvcNum' => $db->SanitizeAndQuote($strInvcNum),
'WhenCreated' => 'NOW()',
'Notes' => $db->SanitizeAndQuote($sNotes)
);
$this->Insert($arIns);
$id = $db->NewID();
return $id;
}
// -- ACTIONS -- //
// ++ CALCULATIONS ++ //
/*-----
RETURNS: The next available sequence number for the given project
PUBLIC so Project page can show it
NOTES:
* Sorting by "InvcSeq+0" instead of just "InvcSeq" because otherwise InvcSeq is treated as a string.
* Perhaps the InvcSeq field should be changed to INTEGER. It was VARCHAR because I thought I might
use some alpha characters at some point, like "12A". It's not clear if this is even sortable in SQL.
If the ability to insert between integers is needed, then maybe it should be a FLOAT and we could
do things like "12.1" rather than "12A"
*/
public function NextInvoiceSeq($idProj) {
$rs = $this->GetData('ID_Proj='.$idProj,NULL,'(InvcSeq+0) DESC');
if ($rs->HasRows()) {
$rs->NextRow();
$nSeq = $rs->Value('InvcSeq');
return $nSeq+1;
} else {
return 1;
}
}
// -- CALCULATIONS -- //
// ++ RECORDSET ACCESS ++ //
/*-----
RETURNS: Dataset of all unsent invoices. Only unsent invoices can be modified; sent invoices should be voided and replaced
with a new invoice.
*/
public function GetUnsent($idProj=NULL) {
$sqlFilt = '(WhenSent IS NULL) AND (WhenVoid IS NULL)';
if (!is_null($idProj)) {
$sqlFilt .= ' AND (ID_Proj='.$idProj.')';
}
return $this->GetData($sqlFilt);
}
// -- RECORDSET ACCESS -- //
// ++ WEB UI COMPONENTS ++ //
public function DropDown(array $iArArgs=NULL) {
if (isset($iArArgs['where'])) {
$sqlFilt = $iArArgs['where'];
} else {
$sqlFilt = NULL;
}
$objRows = $this->GetData($sqlFilt,NULL,'InvcNum');
return $objRows->DropDown($iArArgs);
}
// -- WEB UI COMPONENTS -- //
public function AdminPage() {
$rs = $this->GetData();
return $rs->AdminList();
}
}
class clsWFInvoice extends cDataRecord_MW {
private $objProj;
private $idCache; // ID of invoice for which we have cached data
private $arLineStats; // cached invoice data
// ++ SETUP ++ //
protected function InitVars() {
parent::InitVars();
$this->arLineStats = NULL;
$this->idCache = NULL;
}
// -- SETUP -- //
// ++ BOILERPLATE AUXILIARY ++ //
// STUB until we have time to create MW-compatible event logging
public function CreateEvent(array $arArgs) {
return NULL;
}
public function SelfLink_name() {
return $this->SelfLink($this->InvoiceNumber());
}
// -- BOILERPLATE AUXILIARY -- //
// ++ DATA FIELD ACCESS ++ //
protected function InvoiceNumber() {
return $this->Value('InvcNum');
}
public function IsVoid() {
$dtVoid = $this->Value('WhenVoid');
return (!is_null($dtVoid));
}
// PURPOSE: callback for drop-down lists
public function Text_forList() {
return $this->InvoiceNumber();
}
// -- DATA FIELD ACCESS -- //
// ++ DATA FIELD CALCULATIONS ++ //
/*----
TODO: This should either be faster (just retrieve the highest-Seq line) or
it could be useful by renumbering the Seq field every time. Probably being
faster would be better.
*/
protected function NextILineSeq() {
$nSeqMax = 0;
$rs = $this->InvoiceLineRecords(FALSE);
if ($rs->HasRows()) {
while ($rs->NextRow()) {
$nSeqCur = $rs->Value('Seq');
if ($nSeqCur > $nSeqMax) {
$nSeqMax = $nSeqCur;
}
}
}
return $nSeqMax + 1;
}
// -- DATA FIELD CALCULATIONS -- //
// ++ DATA TABLES ACCESS ++ //
protected function ProjectTable($id=NULL) {
return $this->Engine()->Make(KS_CLASS_PROJECTS);
}
protected function SessionTable($id=NULL) {
return $this->Engine()->Make('wfcSessions');
}
protected function InvoiceLineTable() {
return $this->Engine()->Make('clsWFInvcLines');
}
// -- DATA TABLES ACCESS -- //
// ++ DATA RECORDS ACCESS ++ //
public function InvoiceRecord() {
return $this->InvoiceTable($this->InvoiceID);
}
/*----
RETURNS: recordset of lines for this invoice
HISTORY:
2011-06-18 written
*/
protected function Lines($iSortByDate) {
throw new exception('Lines() is deprecated; call InvoiceLineRecords().');
}
public function InvoiceLineRecords($bDateSort) {
$tInvc = $this->InvoiceLineTable();
if ($bDateSort) {
$sqlSort = 'LineDate';
} else {
$sqlSort = 'Seq,LineDate';
}
return $tInvc->GetData('ID_Invc='.$this->KeyValue(),NULL,$sqlSort);
}
public function ProjectRecord() {
$doLoad = FALSE;
$idProj = $this->Value('ID_Proj');
if (empty($this->objProj)) {
$doLoad = TRUE;
} elseif ($this->objProj->KeyValue() != $idProj) {
$doLoad = TRUE;
}
if ($doLoad) {
$this->objProj = $this->objDB->Projects()->GetItem($idProj);
}
return $this->objProj;
}
public function SessionRecords() {
$tSess = $this->SessionTable();
$rs = $tSess->GetData('ID_Invc='.$this->KeyValue());
return $rs;
}
protected function ProjectRecords() {
return $this->ProjectTable()->Records_forDropDown();
}
// -- DATA RECORDS ACCESS -- //
// ++ FORM BUILDING ++ //
/*----
HISTORY:
2010-11-06 adapted from VbzStockBin for VbzAdminTitle
2011-01-26 adapted from VbzAdminTitle
2011-12-03 adapted for WorkFerret
2011-12-28 adapting for clsWFInvoice
*/
private $frmPage;
private function PageForm() {
if (empty($this->frmPage)) {
$oForm = new fcForm_DB($this);
$oField = new fcFormField_Num($oForm,'ID_Proj');
$oCtrl = new fcFormControl_HTML_DropDown($oField,array());
$oCtrl->Records($this->ProjectRecords());
$oField = new fcFormField_Text($oForm,'InvcSeq');
$oCtrl = new fcFormControl_HTML($oField,array('size'=>3));
$oField = new fcFormField_Text($oForm,'InvcNum');
$oCtrl = new fcFormControl_HTML($oField,array('size'=>20));
$oField = new fcFormField_Num($oForm,'TotalAmt');
$oCtrl = new fcFormControl_HTML($oField,array('size'=>5));
$oField = new fcFormField_Time($oForm,'WhenCreated');
$oCtrl = new fcFormControl_HTML_Timestamp($oField,array('size'=>10));
$oCtrl->Editable(FALSE); // make control read-only
$oField = new fcFormField_Time($oForm,'WhenEdited');
$oCtrl = new fcFormControl_HTML_Timestamp($oField,array('size'=>10));
$oCtrl->Editable(FALSE); // make control read-only
$oField = new fcFormField_Time($oForm,'WhenSent');
$oCtrl = new fcFormControl_HTML_Timestamp($oField,array('size'=>10));
//$oField->Format('n/j G:i');
$oField = new fcFormField_Time($oForm,'WhenPaid');
$oCtrl = new fcFormControl_HTML_Timestamp($oField,array('size'=>10));
$oField = new fcFormField_Time($oForm,'WhenVoid');
$oCtrl = new fcFormControl_HTML_Timestamp($oField,array('size'=>15));
$oField = new fcFormField_Text($oForm,'Notes');
$oCtrl = new fcFormControl_HTML_TextArea($oField,array('rows'=>3,'cols'=>50));
$this->frmPage = $oForm;
}
return $this->frmPage;
}
private $tpPage;
protected function PageTemplate() {
if (empty($this->tpPage)) {
$sTplt = <<<__END__
<table>
<tr><td align=right><b>ID</b>:</td><td>[#ID#]</td></tr>
<tr><td align=right><b>Project</b>:</td><td>[#ID_Proj#]</td></tr>
<tr><td align=right><b>Sequence</b>:</td><td>[#InvcSeq#]</td></tr>
<tr><td align=right><b>Number</b>:</td><td>[#InvcNum#]</td></tr>
<tr><td align=right><b>Total</b>:</td><td>[#TotalAmt#]</td></tr>
<tr><td align=right><b>Created</b>:</td><td>[#WhenCreated#]</td></tr>
<tr><td align=right><b>Edited</b>:</td><td>[#WhenEdited#]</td></tr>
<tr><td align=right><b>Sent</b>:</td><td>[#WhenSent#]</td></tr>
<tr><td align=right><b>Paid</b>:</td><td>[#WhenPaid#]</td></tr>
<tr><td align=right><b>Voided</b>:</td><td>[#WhenVoid#] [#!DoVoid#]</td></tr>
<tr><td align=right><b>Notes</b>:</td><td>[#Notes#]</td></tr>
</table>
__END__;
$this->tpPage = new fcTemplate_array('[#','#]',$sTplt);
}
return $this->tpPage;
}
// -- FORM BUILDING -- //
// ++ WEB UI ++ //
public function ListLines($bDoRenum) {
$rs = $this->InvoiceLineRecords($bDoRenum);
return $rs->AdminList($bDoRenum);
}
public function AdminPage() {
global $wgRequest,$wgOut;
global $vgPage,$vgOut;
$doSave = $wgRequest->getBool('btnSave');
$strAction = $vgPage->Arg('do');
$doVoid = ($strAction == 'void');
$doRenum = ($strAction == 'ren');
$doEdit = ($strAction == 'edit');
$doForm = $doEdit;
$vgPage->UseHTML();
if ($doVoid) {
$arUpd = array(
'WhenVoid' => 'NOW()',
);
$this->Update($arUpd);
$this->SelfRedirect();
}
if ($doSave) {
$this->AdminSave();
}
$id = $this->KeyValue();
$strName = 'Invoice '.$this->Value('InvcNum');
$objPage = new clsWikiFormatter($vgPage);
$objSection = new clsWikiSection_std_page($objPage,$strName,2);
//$objSection->PageKeys(array('page','id','show.invoiced')); // add "show.invoiced" to the list of page-identifiers
$objLink = $objSection->AddLink_local(new clsWikiSectionLink_option(array(),'edit','do','edit','view'));
/*
If we ever want to have more "do" options, then use this code instead:
$objLink = $objSection->AddLink(new clsWikiSection_section('do'));
$objLink = $objSection->AddLink_local(new clsWikiSectionLink_option(array(),'view','do'));
$objLink = $objSection->AddLink_local(new clsWikiSectionLink_option(array(),'edit','do'));
*/
$out = $objSection->Render();
// calculate form customizations
if (!$this->IsVoid() && !$doEdit) {
$sPopup = 'immediately VOID this invoice';
$arLink['do'] = 'void';
$htVoidNow = ' ['.$this->SelfLink('void now',$sPopup,$arLink).']';
} else {
$htVoidNow = NULL;
}
// ++ RENDER THE FORM
if ($doForm) {
$out .= '<form method=post>';
}
$frmEdit = $this->PageForm();
if ($this->IsNew()) {
$frmEdit->ClearValues();
} else {
$frmEdit->LoadRecord();
}
// -- RENDER THE FORM
$oTplt = $this->PageTemplate();
$arCtrls = $frmEdit->RenderControls($doEdit);
// custom vars
$arCtrls['ID'] = $this->SelfLink();
$arCtrls['!DoVoid'] = $htVoidNow;
$oTplt->VariableValues($arCtrls);
$out .= $oTplt->Render();
// FORM FOOTER
if ($doForm) {
$out .= '<input type=submit name=btnSave value="Save">';
$out .= '</form>';
}
$wgOut->AddHTML($out); $out = '';
// invoice lines
$wgOut->AddHTML($this->ListLines($doRenum));
}
/*-----
ACTION: Save the user's edits to the shipment
HISTORY:
2011-02-17 Retired old custom code; now using objForm helper object
2011-12-03 Adapted from VbzCart to WorkFerret.clsWFInvcLine.
2011-12-27 Copying from clsWFInvcLine to clsWFInvoice, replacing hand-built AdminSave().
*/
private function AdminSave() {
global $vgOut;
$oForm = $this->PageForm();
$oForm->ClearValues();
$out = $oForm->Save();
//$out = $this->PageForm()->Save();
$vgOut->AddText($out);
}
public function AdminList() {
global $vgPage;
if ($this->hasRows()) {
$vgPage->UseHTML();
$doShowVoid = $vgPage->Arg('vvi');
$objPage = new clsWikiFormatter($vgPage);
$objSection = new clsWikiSection_std_page($objPage,'Invoices',3);
$objLink = $objSection->AddLink_local(new clsWikiSectionLink_option(array(),'vvi',NULL,'voided'));
$objLink->Popup('view voided invoices');
$out = $objSection->Render();
$out .= <<<__END__
<table>
<tr>
<th>ID</th>
<th>Prj</th>
<th>Number</th>
<th>Total</th>
<th>Created</th>
<th>Edited</th>
<th>Sent</th>
<th>Paid</th>
<th>Voided</th>
<th>Notes</th>
</tr>
__END__;
$isOdd = TRUE;
while ($this->NextRow()) {
$doShow = TRUE;
$isVoid = $this->IsVoid();
if ($isVoid) {
$doShow = $doShowVoid;
}
if ($doShow) {
$wtStyle = $isOdd?'background:#ffffff;':'background:#eeeeee;';
$isOdd = !$isOdd;
$wtStyle .= ($isVoid?' text-decoration:line-through;':'');
$ftID = $this->SelfLink();
$objProj = $this->ProjectRecord();
$ftProj = $objProj->SelfLink($objProj->Value('InvcPfx'),$objProj->Value('Name'));
$ftNum = $this->Value('InvcNum');
$ftTot = $this->Value('TotalAmt');
$ftWhenCrea = $this->Value('WhenCreated');
$ftWhenEdit = $this->Value('WhenEdited');
$ftWhenSent = $this->Value('WhenSent');
$ftWhenPaid = $this->Value('WhenPaid');
$ftWhenVoid = $this->Value('WhenVoid');
$ftNotes = $this->Value('Notes');
$out .= <<<__END__
<tr style="$wtStyle">
<td>$ftID</td>
<td>$ftProj</td>
<td>$ftNum</td>
<td align=right>$ftTot</td>
<td>$ftWhenCrea</td>
<td>$ftWhenEdit</td>
<td>$ftWhenSent</td>
<td>$ftWhenPaid</td>
<td>$ftWhenVoid</td>
<td>$ftNotes</td>
</tr>
__END__;
}
}
$out .= "\n</table>";
return $out;
} else {
return 'No invoices found.';
}
}
/*-----
RETURNS: HTML for drop-down list of invoices in current data set
Includes "NONE" as a choice. (should this be an option in $arArgs?)
*/
public function DropDown(array $arArgs=NULL) {
$strName = fcArray::Nz($arArgs,'ctrl.name',$this->Table()->Name());
$strNone = fcArray::Nz($arArgs,'none','none found');
$sqlNone = fcArray::Nz($arArgs,'none.sql','NULL'); // SQL to use for 'none'
$intDeflt = fcArray::Nz($arArgs,'default',0);
if ($this->hasRows()) {
$out = "\n".'<select name="'.$strName.'">';
// "NONE"
if ($intDeflt == 0) {
$htSelect = " selected";
} else {
$htSelect = '';
}
$out .= "\n".' <option'.$htSelect.' value="'.$sqlNone.'">NONE</option>';
// actual invoices
while ($this->NextRow()) {
$id = $this->KeyValue();
if ($id == $intDeflt) {
$htSelect = " selected";
} else {
$htSelect = '';
}
$out .= "\n".' <option'.$htSelect.' value="'.$id.'">'.$this->Value('InvcNum')."</option>";
}
$out .= "\n</select>\n";
return $out;
} else {
return $strNone;
}
}
// -- WEB UI -- //
// ++ CALCULATIONS ++ //
/*----
ACTION: Calculates a few stats about the invoice's lines
* renumbers those lines, preserving their existing order
* updates each line's balance
HISTORY:
2011-06-19 written
2011-12-04 fixed update -- was calling table update instead of row update
*/
private function MakeLineStats() {
$id = $this->Value('ID');
if ($this->idCache != $id) {
$rsLines = $this->Lines(TRUE); // TRUE = sort by date (not sure if that's best -- prevents Seq override)
$intSeq = 0;
$dlrBal = 0;
while ($rsLines->NextRow()) {
$intSeq++;
$dlrLine = $rsLines->Value('CostLine');
$dlrBal += $dlrLine;
$dlrBalOld = $rsLines->Value('CostBal');
$arUpd = NULL;
if ($rsLines->Value('Seq') != $intSeq) {
$arUpd['Seq'] = $intSeq;
}
if ($dlrBalOld != $dlrBal) {
$arUpd['CostBal'] = $dlrBal;
}
if (is_array($arUpd)) {
$rsLines->Update($arUpd);
}
}
$this->arLineStats['count'] = $intSeq;
$this->arLineStats['bal'] = $dlrBal;
$this->idCache = $id;
}
}
/*----
RETURNS: number of lines in this invoice
ACTIONS: runs MakeLineStats(), which corrects balances and sequence
HISTORY:
2011-06-18 written
*/
public function LineCount() {
$this->MakeLineStats();
return $this->arLineStats['count'];
}
/*----
RETURNS: balance of all lines currently assigned to this invoice
ACTIONS: runs MakeLineStats(), which corrects balances and sequence
HISTORY:
2011-06-18 written
*/
public function LineBalance() {
$this->MakeLineStats();
return $this->arLineStats['bal'];
}
// -- CALCULATIONS -- //
// ++ ACTIONS ++ //
protected function AddNewLine(clsWFInvcLine $rcLine) {
// insert the given data
}
/*----
INPUT:
$arSess: array of session data, unsorted
HISTORY:
2015-05-05 rewriting from scratch
*/
public function AddLines(array $arSess) {
// collect sessions in an array so we can sort them
$tSess = $this->SessionTable();
foreach ($arSess as $idSess => $val) {
$rcSess = $tSess->GetItem($idSess);
$arSessRecs[$rcSess->SortKey()] = $rcSess->Values();
}
// do the sort
ksort($arSessRecs);
// go through them in order, doing additional calculations, and add them to the invoice
$nSeq = $this->NextILineSeq();
$dlrBal = 0;
$idInvc = $this->KeyValue();
$rcSess = $this->SessionTable()->SpawnItem();
$rcILine = $this->InvoiceLineTable()->SpawnItem();
foreach ($arSessRecs as $sSort => $arSess) {
$rcSess->Values($arSess);
$dlrLine = $rcSess->Cost_calc();
$dlrBal += $dlrLine;
$arSess['CostLine'] = $dlrLine;
$arSess['CostBal'] = $dlrBal;
$arSess['TimeTotal'] = $rcSess->TimeFinal_hours();
$rcSess->Values($arSess); // update object from modified fields
$rcILine->CopySession($rcSess);
$rcILine->InvoiceID($idInvc);
$rcILine->Seq($nSeq);
$rcILine->Create(); // write the ILine data to a new record
$rcSess->Assign_toInvoice($rcILine); // assign the Session record to that ILine
$nSeq++;
}
// update the invoice
$arUpd = array(
'TotalAmt' => $dlrBal,
'ID_Debit' => 'NULL' // not using this anymore
);
$this->Update($arUpd);
}
/*-----
INPUT:
$iArSess: array of session data, unsorted
VERSION: consolidates by date+rate
This implementation is probably buggy, however.
HISTORY:
2011-06-15 significant rewrite to fix transcription bug
2014-03-26 moved most of this process into the Invoice Line class, to fix the bug for real.
*/
public function AddLines_OLD(array $iArSess) {
// copy the sessions into an array for sorting:
$idxLine = 0;
$intBillAmt = 0;
$arSess = NULL;
foreach ($iArSess as $idSess=>$val) {
$rcSess = $this->Engine()->Sessions()->GetItem($idSess);
$strSort = $rcSess->SortKey().'.'.$idSess; // date plus sorting index plus Session ID
$arSess[$strSort] = $rcSess->Values();
$intBillAmt += (int)($rcSess->Value('CostLine') * 100);
}
$dlrAddedAmt = $intBillAmt/100;
$dlrInvcAmtOld = $this->LineBalance();
$dlrInvcAmtNew = $dlrInvcAmtOld + $dlrAddedAmt; // add new lines to existing invc total
// update the invoice
$arUpd = array(
'TotalAmt' => $dlrInvcAmtNew,
'ID_Debit' => 'NULL' // not using this anymore
);
$this->Update($arUpd);
if (!is_null($arSess)) {
// sort lines by sort key (defined by session object SortKey(): date + seq)
ksort($arSess);
// go through sessions and add invoice lines as appropriate
// - setup for iteration:
// get the number of lines already in the invoice -- numbering starts there
// when these change, an invoice line is triggered:
$idRateLast = NULL;
$strDateLast = NULL;
// invoice line setup
$rcILine = $this->InvoiceLineTable()->SpawnItem();
$rcILine->InvoiceID($this->KeyValue());
$rcILine->InvoiceStart();
$rcILine->AddSessions($arSess);
}
}
// -- ACTIONS -- //
}