forked from timschofield/webERP-Medical
/
SupplierAllocations.php
700 lines (528 loc) · 24.6 KB
/
SupplierAllocations.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
<?php
/* $Id$*/
/*
This page can be called with...
1. A SuppTrans TransNo and Type
The page will then show potential allocations for the transaction called with,
this page can be called from the supplier enquiry to show the make up and to modify
existing allocations
2. A SupplierID
The page will show all outstanding payments or credits yet to be allocated for the supplier selected
3. No parameters
The page will show all outstanding supplier credit notes and payments yet to be
allocated
*/
include('includes/DefineSuppAllocsClass.php');
include('includes/session.inc');
$title = _('Supplier Payment') . '/' . _('Credit Note Allocations');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('Supplier Allocations') . '" alt="" />' . ' ' . _('Supplier Allocations') . '</p>';
if (isset($_POST['UpdateDatabase']) OR isset($_POST['RefreshAllocTotal'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
if (!isset($_SESSION['Alloc'])){
prnMsg( _('Allocations can not be processed again') . '. ' . _('If you hit refresh on this page after having just processed an allocation') . ', ' . _('try to use the navigation links provided rather than the back button, to avoid this message in future'),'warn');
include('includes/footer.inc');
exit;
}
/*1st off run through and update the array with the amounts allocated
This works because the form has an input field called the value of
AllocnItm->ID for each record of the array - and PHP sets the value of
the form variable on a post*/
$TotalAllocated = 0;
$TotalDiffOnExch = 0;
for ($AllocCounter=0; $AllocCounter < $_POST['TotalNumberOfAllocs']; $AllocCounter++){
$_POST['Amt' . $AllocCounter] = filter_currency_input($_POST['Amt' . $AllocCounter]);
$_POST['YetToAlloc' . $AllocCounter] = filter_currency_input($_POST['YetToAlloc' . $AllocCounter]);
if (!is_numeric($_POST['Amt' . $AllocCounter])){
$_POST['Amt' . $AllocCounter] = 0;
}
if ($_POST['Amt' . $AllocCounter] < 0){
prnMsg(_('The entry for the amount to allocate was negative') . '. ' . _('A positive allocation amount is expected'),'error');
$_POST['Amt' . $AllocCounter] = 0;
}
if (isset($_POST['All' . $AllocCounter]) and $_POST['All' . $AllocCounter] == True){
$_POST['Amt' . $AllocCounter] = $_POST['YetToAlloc' . $AllocCounter];
}
/*Now check to see that the AllocAmt is no greater than the
amount left to be allocated against the transaction under review */
if ($_POST['Amt' . $AllocCounter] > $_POST['YetToAlloc' . $AllocCounter]){
$_POST['Amt' . $AllocCounter] = $_POST['YetToAlloc' . $AllocCounter];
}
$_SESSION['Alloc']->Allocs[$_POST['AllocID' . $AllocCounter]]->AllocAmt = $_POST['Amt' . $AllocCounter];
/*recalcuate the new difference on exchange
(a +positive amount is a gain -ve a loss)*/
$_SESSION['Alloc']->Allocs[$_POST['AllocID' . $AllocCounter]]->DiffOnExch = ($_POST['Amt' . $AllocCounter] / $_SESSION['Alloc']->TransExRate) - ($_POST['Amt' . $AllocCounter] / $_SESSION['Alloc']->Allocs[$_POST['AllocID' . $AllocCounter]]->ExRate);
$TotalDiffOnExch = $TotalDiffOnExch + $_SESSION['Alloc']->Allocs[$_POST['AllocID' . $AllocCounter]]->DiffOnExch;
$TotalAllocated = $TotalAllocated + $_POST['Amt' . $AllocCounter];
} /*end of the loop to set the new allocation amounts,
recalc diff on exchange and add up total allocations */
if ($TotalAllocated + $_SESSION['Alloc']->TransAmt > 0.005){
echo '<br />';
prnMsg(_('These allocations cannot be processed because the amount allocated is more than the amount of the') .
' ' . $_SESSION['Alloc']->TransTypeName . ' ' . _('being allocated') . '<br />' . _('Total allocated') . ' = ' . $TotalAllocated . ' ' . _('and the total amount of the Credit/payment was') . ' ' . -$_SESSION['Alloc']->TransAmt,'error');
echo '<br />';
$InputError = 1;
}
}
if (isset($_POST['UpdateDatabase'])){
if ($InputError == 0){ /* ie all the traps were passed */
/* actions to take having checked that the input is sensible
1st set up a transaction on this thread*/
$SQL = 'BEGIN';
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('The transaction BEGIN failed with error');
$DbgMsg = _('The SQL that was used but failed was');
$Result=DB_query($SQL, $db, $ErrMsg, $DbgMsg);
foreach ($_SESSION['Alloc']->Allocs as $AllocnItem) {
if ($AllocnItem->OrigAlloc >0 AND ($AllocnItem->OrigAlloc != $AllocnItem->AllocAmt)){
/*Orignial allocation was not 0 and it has now changed
need to delete the old allocation record */
$SQL = "DELETE FROM suppallocs WHERE id = '" . $AllocnItem->PrevAllocRecordID . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The existing allocation for') . ' ' . $AllocnItem->TransType .' ' . $AllocnItem->TypeNo . ' ' . _('could not be deleted because');
$DbgMsg = _('The following SQL to delete the allocation record was used');
$Result=DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
}
if ($AllocnItem->OrigAlloc != $AllocnItem->AllocAmt){
/*Only when there has been a change to the allocated amount
do we need to insert a new allocation record and update
the transaction with the new alloc amount and diff on exch */
if ($AllocnItem->AllocAmt > 0){
$SQL = "INSERT INTO suppallocs (datealloc, amt, transid_allocfrom, transid_allocto) VALUES ('" . FormatDateForSQL(date($_SESSION['DefaultDateFormat'])) . "',
'" . $AllocnItem->AllocAmt . "',
'" . $_SESSION['Alloc']->AllocTrans . "',
'" . $AllocnItem->ID . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The supplier allocation record for') . ' ' . $AllocnItem->TransType . ' ' . $AllocnItem->TypeNo . ' ' ._('could not be inserted because');
$DbgMsg = _('The following SQL to insert the allocation record was used');
$Result=DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
}
$NewAllocTotal = $AllocnItem->PrevAlloc + $AllocnItem->AllocAmt;
if (abs($NewAllocTotal-$AllocnItem->TransAmount) < 0.01){
$Settled = 1;
} else {
$Settled = 0;
}
$SQL = "UPDATE supptrans SET diffonexch='" . $AllocnItem->DiffOnExch . "',
alloc = '" . $NewAllocTotal . "',
settled = '" . $Settled . "'
WHERE id = '" . $AllocnItem->ID . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The debtor transaction record could not be modified for the allocation against it because');
$DbgMsg = _('The following SQL to update the debtor transaction record was used');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
} /*end if the new allocation is different to what it was before */
} /*end of the loop through the array of allocations made */
/*Now update the payment or credit note with the amount allocated
and the new diff on exchange */
if (abs($TotalAllocated + $_SESSION['Alloc']->TransAmt) < 0.01){
$Settled = 1;
} else {
$Settled = 0;
}
$SQL = "UPDATE supptrans SET alloc = '" . -$TotalAllocated . "',
diffonexch = '" . -$TotalDiffOnExch . "',
settled='" . $Settled . "'
WHERE id = '" . $_SESSION['AllocTrans'] . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' .
_('The supplier payment or credit note transaction could not be modified for the new allocation and exchange difference because');
$DbgMsg = _('The following SQL to update the payment or credit note was used');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
/*Almost there ... if there is a change in the total diff on exchange
and if the GLLink to debtors is active - need to post diff on exchange to GL */
$MovtInDiffOnExch = $_SESSION['Alloc']->PrevDiffOnExch + $TotalDiffOnExch;
if ($MovtInDiffOnExch !=0 ){
if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1){
$PeriodNo = GetPeriod($_SESSION['Alloc']->TransDate, $db);
$_SESSION['Alloc']->TransDate = FormatDateForSQL($_SESSION['Alloc']->TransDate);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
defaulttag,
narrative,
amount)
VALUES ('" . $_SESSION['Alloc']->TransType . "',
'" . $_SESSION['Alloc']->TransNo . "',
'" . $_SESSION['Alloc']->TransDate . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['purchasesexchangediffact'] . "',
'" . $_SESSION['DefaultTag'] . "',
'". _('Exch diff') . "',
'" . $MovtInDiffOnExch . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' .
_('The GL entry for the difference on exchange arising out of this allocation could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
defaulttag,
narrative,
amount)
VALUES ('" . $_SESSION['Alloc']->TransType . "',
'" . $_SESSION['Alloc']->TransNo . "',
'" . $_SESSION['Alloc']->TransDate . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['creditorsact'] . "',
'" . $_SESSION['DefaultTag'] . "',
'" . _('Exch Diff') . "',
'" . -$MovtInDiffOnExch . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ' : ' .
_('The GL entry for the difference on exchange arising out of this allocation could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, True);
}
}
/* OK Commit the transaction */
$SQL = 'COMMIT';
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' .
_('The updates and insertions arising from this allocation could not be committed to the database');
$DbgMsg = _('The COMMIT SQL failed');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg);
/*finally delete the session variables holding all the previous data */
unset($_SESSION['AllocTrans']);
unset($_SESSION['Alloc']);
unset($_POST['AllocTrans']);
} /* end of processing required if there were no input errors trapped */
}
/*The main logic determines whether the page is called with a Supplier code
a specific transaction or with no parameters ie else
If with a supplier code show just that suppliers payments and credits for allocating
If with a specific payment or credit show the invoices and credits available
for allocating to */
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if (isset($_POST['SupplierID'])){
$_GET['SupplierID'] = $_POST['SupplierID'];
echo '<input type="hidden" name="SupplierID" value="' . $_POST['SupplierID'] . '" />';
}
If (isset($_GET['AllocTrans'])){
/*page called with a specific transaction ID for allocating
SupplierID may also be set but this is the logic to follow
the SupplierID logic is only for showing the payments and credits to allocate*/
/*The logic is:
- read in the transaction into a session class variable
- read in the invoices available for allocating to into a session array of allocs object
- Display the supplier name the transaction being allocated amount and trans no
- Display the invoices for allocating to with a form entry for each one
for the allocated amount to be entered */
$_SESSION['Alloc'] = new Allocation;
/*The session varibale AllocTrans is set from the passed variable AllocTrans
on the first pass */
$_SESSION['AllocTrans'] = $_GET['AllocTrans'];
$_POST['AllocTrans'] = $_GET['AllocTrans'];
$SQL= "SELECT systypes.typename,
supptrans.type,
supptrans.transno,
supptrans.trandate,
supptrans.supplierno,
suppliers.suppname,
suppliers.currcode,
rate,
(supptrans.ovamount+supptrans.ovgst) AS total,
supptrans.diffonexch,
supptrans.alloc
FROM supptrans,
systypes,
suppliers
WHERE supptrans.type = systypes.typeid
AND supptrans.supplierno = suppliers.supplierid
AND supptrans.id='" . $_SESSION['AllocTrans'] . "'";
$Result = DB_query($SQL, $db);
if (DB_num_rows($Result) != 1){
echo _('There was a problem retrieving the information relating the transaction selected') . '. ' . _('Allocations are unable to proceed');
if ($debug == 1){
echo '<br />' . _('The SQL that was used to retrieve the transaction information was') . ' :<br />' . $SQL;
}
exit;
}
$myrow = DB_fetch_array($Result);
$_SESSION['Alloc']->AllocTrans = $_SESSION['AllocTrans'];
$_SESSION['Alloc']->SupplierID = $myrow['supplierno'];
$_SESSION['Alloc']->SuppName = $myrow['suppname'];;
$_SESSION['Alloc']->CurrCode = $myrow['currcode'];;
$_SESSION['Alloc']->TransType = $myrow['type'];
$_SESSION['Alloc']->TransTypeName = $myrow['typename'];
$_SESSION['Alloc']->TransNo = $myrow['transno'];
$_SESSION['Alloc']->TransExRate = $myrow['rate'];
$_SESSION['Alloc']->TransAmt = $myrow['total'];
$_SESSION['Alloc']->PrevDiffOnExch = $myrow['diffonexch'];
$_SESSION['Alloc']->TransDate = ConvertSQLDate($myrow['trandate']);
/* Now populate the array of possible (and previous actual) allocations for this supplier */
/*First get the transactions that have outstanding balances ie Total-Alloc >0 */
$SQL= "SELECT supptrans.id,
typename,
transno,
trandate,
suppreference,
rate,
ovamount+ovgst AS total,
diffonexch,
alloc
FROM supptrans,
systypes
WHERE supptrans.type = systypes.typeid
AND supptrans.settled=0
AND abs(ovamount+ovgst-alloc)>0.009
AND supplierno='" . $_SESSION['Alloc']->SupplierID . "'";
$ErrMsg = _('There was a problem retrieving the transactions available to allocate to');
$DbgMsg = _('The SQL that was used to retrieve the transaction information was');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg);
while ($myrow=DB_fetch_array($Result)){
$_SESSION['Alloc']->add_to_AllocsAllocn ($myrow['id'],
$myrow['typename'],
$myrow['transno'],
ConvertSQLDate($myrow['trandate']),
$myrow['suppreference'],
0,
$myrow['total'],
$myrow['rate'],
$myrow['diffonexch'],
$myrow['diffonexch'],
$myrow['alloc'],
'NA');
}
/* Now get trans that might have previously been allocated to by this trans
NB existing entries where still some of the trans outstanding entered from
above logic will be overwritten with the prev alloc detail below */
$SQL = "SELECT supptrans.id,
typename,
transno,
trandate,
suppreference,
rate,
ovamount+ovgst AS total,
diffonexch,
supptrans.alloc-suppallocs.amt AS prevallocs,
amt,
suppallocs.id AS allocid
FROM supptrans,
systypes,
suppallocs
WHERE supptrans.type = systypes.typeid
AND supptrans.id=suppallocs.transid_allocto
AND suppallocs.transid_allocfrom='" . $_SESSION['AllocTrans'] .
"' AND supplierno='" . $_SESSION['Alloc']->SupplierID . "'";
$ErrMsg = _('There was a problem retrieving the previously allocated transactions for modification');
$DbgMsg = _('The SQL that was used to retrieve the previously allocated transaction information was');
$Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg);
while ($myrow = DB_fetch_array($Result)){
$DiffOnExchThisOne = ($myrow['amt']/$myrow['rate']) - ($myrow['amt']/$_SESSION['Alloc']->TransExRate);
$_SESSION['Alloc']->add_to_AllocsAllocn ($myrow['id'], $myrow['typename'], $myrow['transno'],
ConvertSQLDate($myrow['trandate']), $myrow['suppreference'], $myrow['amt'],
$myrow['total'],
$myrow['rate'],
$DiffOnExchThisOne,
($myrow['diffonexch'] - $DiffOnExchThisOne),
$myrow['prevallocs'],
$myrow['allocid']);
}
}
if (isset($_POST['AllocTrans'])){
echo '<input type="hidden" name="AllocTrans" value="' . $_POST['AllocTrans'] . '" />';
/*Show the transaction being allocated and the potential trans it could be allocated to
and those where there is already an existing allocation */
echo '<div class="centre"><font color="blue">' . _('Allocation of supplier') . ' ' .
$_SESSION['Alloc']->TransTypeName . ' ' . _('number') . ' ' .
$_SESSION['Alloc']->TransNo . ' ' . _('from') . ' ' .
$_SESSION['Alloc']->SupplierID . ' - <b>' .
$_SESSION['Alloc']->SuppName . '</b>, ' . _('dated') . ' ' .
$_SESSION['Alloc']->TransDate;
if ($_SESSION['Alloc']->TransExRate != 1){
echo '<br />' . _('Amount in supplier currency'). ' <b>' .
locale_money_format(-$_SESSION['Alloc']->TransAmt,$_SESSION['Alloc']->CurrCode) . '</b><i> (' .
_('converted into local currency at an exchange rate of') . ' ' .
$_SESSION['Alloc']->TransExRate . ')</i></font><br />';
} else {
echo '<br />' . _('Transaction total') . ': <b>' . locale_money_format(-$_SESSION['Alloc']->TransAmt, $_SESSION['Alloc']->CurrCode) . '</b></div>';
}
/*Now display the potential and existing allocations put into the array above */
echo '<table cellpadding="2" class="selection">';
$TableHeader = '<tr><th>' . _('Type') . '</th>
<th>' . _('Trans') . '<br />' . _('Number') . '</th>
<th>' . _('Trans') .'<br />' . _('Date') . '</th>
<th>' . _('Supp') . '<br />' . _('Ref') . '</th>
<th>' . _('Total') . '<br />' . _('Amount') . '</th>
<th>' . _('Yet to') . '<br />' . _('Allocate') . '</th>
<th>' . _('This') . '<br />' . _('Allocation') . '</th></tr>';
$k = 0;
$Counter = 0;
$RowCounter = 0;
$TotalAllocated = 0;
foreach ($_SESSION['Alloc']->Allocs as $AllocnItem) {
/*Alternate the background colour for each potential allocation line */
if ($k == 1){
echo '<tr class="EvenTableRows">';
$k = 0;
} else {
echo '<tr class="OddTableRows">';
$k = 1;
}
$RowCounter++;
if ($RowCounter == 15){
/*Set up another row of headings to ensure always a heading on the screen of potential allocns*/
echo $TableHeader;
$RowCounter = 1;
}
$YetToAlloc = ($AllocnItem->TransAmount - $AllocnItem->PrevAlloc);
echo '<td>'.$AllocnItem->TransType.'</td>
<td>'.$AllocnItem->TypeNo.'</td>
<td>'.$AllocnItem->TransDate.'</td>
<td>'.$AllocnItem->SuppRef.'</td>
<td class="number">' . locale_money_format($AllocnItem->TransAmount,$_SESSION['Alloc']->CurrCode) . '</td>
<td class="number">' . locale_money_format($YetToAlloc,$_SESSION['Alloc']->CurrCode) . '
<input type="hidden" name="YetToAlloc' . $Counter . '" value="' . locale_money_format($YetToAlloc,$_SESSION['Alloc']->CurrCode) . '" /></td>';
if (ABS($AllocnItem->AllocAmt-$YetToAlloc) < 0.01){
echo '<td class="number"><input type="checkbox" name="All' . $Counter . '" value="' . True . '" />';
} else {
echo '<td class="number"><input type="checkbox" name="All' . $Counter . '" />';
}
echo '<input type="text" class="number" name="Amt' . $Counter .'" maxlength="12" size="13" value="' . locale_money_format($AllocnItem->AllocAmt,$_SESSION['Alloc']->CurrCode) . '" />
<input type="hidden" name="AllocID' . $Counter . '" value="' . $AllocnItem->ID . '" /></td></tr>';
$TotalAllocated = $TotalAllocated + $AllocnItem->AllocAmt;
$Counter++;
}
echo '<tr><td colspan="5" class="number"><b><u>' . _('Total Allocated') . ':</u></b></td>
<td class="number"><b><u>' . locale_money_format($TotalAllocated,$_SESSION['Alloc']->CurrCode) . '</u></b></td></tr>';
echo '<tr><td colspan="5" class="number"><b>' . _('Left to allocate') . '</b></td><td class="number"><b>' .
locale_money_format(-$_SESSION['Alloc']->TransAmt - $TotalAllocated,$_SESSION['Alloc']->CurrCode) . '</b></td></tr></table>';
echo '<div class="centre"><input type="hidden" name="TotalNumberOfAllocs" value="' . $Counter . '" />';
echo '<br /><button type="submit" name="RefreshAllocTotal">' . _('Recalculate Total To Allocate') . '</button>';
echo '<button type="submit" name="UpdateDatabase">' . _('Process Allocations') . '</button></div>';
} elseif(isset($_GET['SupplierID'])){
/*page called with a supplier code so show the transactions to allocate
specific to the supplier selected */
echo '<input type="hidden" name=SupplierID value="' . $_GET['SupplierID'] . '" />';
/*Clear any previous allocation records */
unset($_SESSION['Alloc']);
$sql = "SELECT id,
transno,
typename,
type,
suppliers.supplierid,
suppname,
trandate,
suppreference,
rate,
ovamount+ovgst AS total,
alloc
FROM supptrans,
suppliers,
systypes
WHERE supptrans.type=systypes.typeid
AND supptrans.supplierno=suppliers.supplierid
AND suppliers.supplierid='" . $_GET['SupplierID'] ."'
AND (type=21 or type=22) AND settled=0 ORDER BY id";
$result = DB_query($sql, $db);
if (DB_num_rows($result) == 0){
prnMsg(_('There are no outstanding payments or credits yet to be allocated for this supplier'),'info');
include('includes/footer.inc');
exit;
}
echo '<table class="selection">';
$TableHeader = '<tr><th>' . _('Trans Type') .
'</th><th>' . _('Supplier') .
'</th><th>' . _('Number') .
'</th><th>' . _('Date') .
'</th><th>' . _('Total') .
'</th><th>' . _('To Alloc') . '</th></tr>'. "\n";
echo $TableHeader;
/* set up table of TransType - Supplier - Trans No - Date - Total - Left to alloc */
$RowCounter = 0;
$k = 0; //row colour counter
while ($myrow = DB_fetch_array($result)) {
if ($k == 1){
echo '<tr class="EvenTableRows">';
$k = 0;
} else {
echo '<tr class="OddTableRows">';
$k = 1;
}
printf('<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td class="number">%0.2f</td>
<td class="number">%0.2f</td>
<td><a href="%sAllocTrans=%s">' . _('Allocate') .'</td>
</tr>',
$myrow['typename'],
$myrow['suppname'],
$myrow['transno'],
ConvertSQLDate($myrow['trandate']),
locale_money_format($myrow['total'],$myrow['currcode']),
locale_money_format($myrow['total']-$myrow['alloc'],$myrow['currcode']),
htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') .'?',
$myrow['id']);
}
} else { /* show all outstanding payments and credits to be allocated */
/*Clear any previous allocation records */
unset($_SESSION['Alloc']->Allocs);
unset($_SESSION['Alloc']);
$sql = "SELECT id,
transno,
typename,
type,
suppliers.supplierid,
suppname,
trandate,
suppreference,
rate,
ovamount+ovgst AS total,
alloc,
currcode
FROM supptrans,
suppliers,
systypes
WHERE supptrans.type=systypes.typeid
AND supptrans.supplierno=suppliers.supplierid
AND (type=21 or type=22)
AND settled=0 ORDER BY id";
$result = DB_query($sql, $db);
echo '<table class="selection">';
$TableHeader = '<tr><th>' . _('Trans Type') . '</th>
<th>' . _('Supplier') . '</th>
<th>' . _('Number') . '</th>
<th>' . _('Date') . '</th>
<th>' . _('Total') . '</th>
<th>' . _('To Alloc') . '</th>
<th>' . _('More Info') . '</th></tr>';
echo $TableHeader;
/* set up table of Tran Type - Supplier - Trans No - Date - Total - Left to alloc */
$k = 0; //row colour counter
$RowCounter = 0;
while ($myrow = DB_fetch_array($result)) {
if ($k == 1){
echo '<tr class="EvenTableRows">';
$k = 0;
} else {
echo '<tr class="OddTableRows">';
$k = 1;
}
printf('<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td class="number">%s</td>
<td class="number">%s</td>
<td><a href="%sAllocTrans=%s">' . _('Allocate') . '</td>
</tr>',
$myrow['typename'],
$myrow['suppname'],
$myrow['transno'],
ConvertSQLDate($myrow['trandate']),
locale_money_format($myrow['total'],$myrow['currcode']),
locale_money_format($myrow['total']-$myrow['alloc'],$myrow['currcode']),
htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') .'?',
$myrow['id']);
} //END WHILE LIST LOOP
echo '</table>';
if (DB_num_rows($result) == 0) {
prnMsg(_('There are no allocations to be done'),'info');
}
} /* end of else if not a SupplierID or transaction called with the URL */
echo '</form>';
include('includes/footer.inc');
?>