forked from victorkagimu/KwaMoja
/
KCMCLabTests.php
705 lines (658 loc) · 26.6 KB
/
KCMCLabTests.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
<?php
include ('includes/session.php');
$Title = _('Billing For Laboratory Tests');
include ('includes/header.php');
include ('includes/SQL_CommonFunctions.php');
include ('includes/GetSalesTransGLCodes.php');
include ('includes/CustomerSearch.php');
if (!isset($_POST['BankAccount']) or isset($_POST['Cancel'])) {
unset($_POST['SubmitCash']);
unset($_POST['Patient']);
unset($_SESSION['Items']);
$_SESSION['Items']['Lines'] = 0;
$_SESSION['Items']['Value'] = 0;
}
if (isset($_POST['BankAccount'])) {
$SQL = "SELECT currencies.decimalplaces
FROM bankaccounts
INNER JOIN currencies
ON currencies.currabrev=bankaccounts.currcode
WHERE bankaccounts.accountcode='" . $_POST['BankAccount'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$DecimalPlaces = $MyRow['decimalplaces'];
} else {
$SQL = "SELECT decimalplaces
FROM currencies
WHERE currabrev='" . $_SESSION['CompanyRecord']['currencydefault'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$DecimalPlaces = $MyRow['decimalplaces'];
}
if (!isset($_POST['Search']) and !isset($_POST['Next']) and !isset($_POST['Previous']) and !isset($_POST['Go1']) and !isset($_POST['Go2']) and isset($_POST['JustSelectedACustomer']) and empty($_POST['Patient'])) {
/*Need to figure out the number of the form variable that the user clicked on */
for ($i = 0;$i < count($_POST);$i++) { //loop through the returned customers
if (isset($_POST['SubmitCustomerSelection' . $i])) {
break;
}
}
if ($i == count($_POST)) {
prnMsg(_('Unable to identify the selected customer'), 'error');
} else {
$Patient[0] = $_POST['SelectedCustomer' . $i];
$Patient[1] = $_POST['SelectedBranch' . $i];
unset($_POST['Search']);
}
}
if (isset($_GET['Delete'])) {
$_SESSION['Items']['Value']-= $_SESSION['Items'][$_GET['Delete']]['Quantity'] * $_SESSION['Items'][$_GET['Delete']]['Price'];
unset($_SESSION['Items'][$_GET['Delete']]);
$_POST['Patient'] = $_GET['Patient'] . ' ' . $_GET['Branch'];
$Patient[0] = $_GET['Patient'];
$Patient[1] = $_GET['Branch'];
}
if (isset($_POST['ChangeItem'])) {
$Patient[0] = $_POST['PatientNo'];
$Patient[1] = $_POST['BranchNo'];
}
if (isset($_POST['ChangeItem']) and $_POST['StockID'] != '') {
$Patient[0] = $_POST['PatientNo'];
$Patient[1] = $_POST['BranchNo'];
$SQL = "SELECT price
FROM prices
WHERE stockid='" . $_POST['StockID'] . "'
AND typeabbrev='" . $_POST['PriceList'] . "'
AND '" . FormatDateForSQL($_POST['AdmissionDate']) . "' between startdate and enddate";
$PriceResult = DB_query($SQL);
if (DB_num_rows($PriceResult) == 0) {
$Price = 0;
} else {
$MyRow = DB_fetch_array($PriceResult);
$Price = $MyRow['price'];
}
$_SESSION['Items'][$_SESSION['Items']['Lines']]['StockID'] = $_POST['StockID'];
$_SESSION['Items'][$_SESSION['Items']['Lines']]['Quantity'] = $_POST['Quantity'];
$_SESSION['Items'][$_SESSION['Items']['Lines']]['Price'] = $Price;
$_SESSION['Items']['Value']+= $Price * $_POST['Quantity'];
$_SESSION['Items']['Lines']++;
} else if (isset($_POST['ChangeItem']) and $_POST['StockID'] == '' and isset($_POST['AddDoctorFee'])) {
$_SESSION['Items']['Value']+= filter_number_format($_POST['DoctorsFee']);
} else if (isset($_POST['ChangeItem']) and $_POST['StockID'] == '' and !isset($_POST['AddDoctorFee'])) {
$_SESSION['Items']['Value']-= filter_number_format($_POST['DoctorsFee']);
}
if (isset($_POST['SubmitCash']) or isset($_POST['SubmitInsurance'])) {
$InputError = 0;
if ((!isset($_POST['BankAccount']) or $_POST['BankAccount'] == '') and !isset($_POST['SubmitInsurance'])) {
$InputError = 1;
$msg[] = _('You must select a cash collection point');
}
if ($_SESSION['Items']['Lines'] == 0) {
$InputError = 1;
$msg[] = _('You must select at least one test');
}
if ($InputError == 1) {
foreach ($msg as $message) {
prnMsg($message, 'info');
$_POST['ChangeItem'] = 'Yes';
$Patient[0] = $_POST['PatientNo'];
$Patient[1] = $_POST['BranchNo'];
}
} else {
DB_Txn_Begin();
/*First off create the sales order
* entries in the database
*/
$OrderNo = GetNextTransNo(30);
$HeaderSQL = "INSERT INTO salesorders ( orderno,
debtorno,
branchcode,
comments,
orddate,
shipvia,
deliverto,
fromstkloc,
deliverydate,
confirmeddate,
deliverblind)
VALUES (
'" . $OrderNo . "',
'" . $_POST['PatientNo'] . "',
'" . $_POST['BranchNo'] . "',
'" . DB_escape_string($_POST['Comments']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'1',
'" . $_SESSION['UserStockLocation'] . "',
'" . $_SESSION['UserStockLocation'] . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
0
)";
$ErrMsg = _('The order cannot be added because');
$InsertQryResult = DB_query($HeaderSQL, $ErrMsg);
for ($i = 0;$i < $_SESSION['Items']['Lines'];$i++) {
if (isset($_SESSION['Items'][$i]['StockID'])) {
$LineItemSQL = "INSERT INTO salesorderdetails (orderlineno,
orderno,
stkcode,
unitprice,
quantity,
discountpercent,
narrative,
itemdue,
actualdispatchdate,
qtyinvoiced,
completed)
VALUES (
'" . $i . "',
'" . $OrderNo . "',
'" . $_SESSION['Items'][$i]['StockID'] . "',
'" . $_SESSION['Items'][$i]['Price'] . "',
'" . $_SESSION['Items'][$i]['Quantity'] . "',
'0',
'" . _('Sales order for laboratory test transaction') . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'1',
1
)";
$DbgMsg = _('Trouble inserting a line of a sales order. The SQL that failed was');
$Ins_LineItemResult = DB_query($LineItemSQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE care_encounter_prescription SET bill_number='" . $OrderNo . "'
WHERE nr='" . $_SESSION['Items'][$i]['Care2x'] . "'";
$DbgMsg = _('Trouble inserting a line of a sales order. The SQL that failed was');
$UpdateCare2xResult = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
}
if (isset($_POST['Doctor'])) {
$SuppInvoiceNumber = GetNextTransNo(20);
$DoctorsInvoiceSQL = "INSERT INTO supptrans (transno,
type,
supplierno,
suppreference,
trandate,
duedate,
inputdate,
settled,
rate,
ovamount,
ovgst,
diffonexch,
alloc,
transtext,
hold,
id)
VALUES (
'" . $SuppInvoiceNumber . "',
'20',
'" . $_POST['Doctor'] . "',
'',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'0',
'1',
'" . $_POST['DoctorsFee'] . "',
'0',
'0',
'0',
'" . $_POST['Doctor'] . ' ' . _('fee') . ' ' . _('for patient') . ' ' . $_POST['PatientNo'] . "',
'0',
''
)";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The doctors transaction record could not be inserted because');
$DbgMsg = _('The following SQL to insert the doctors transaction record was used');
$Result = DB_query($DoctorsInvoiceSQL, $ErrMsg, $DbgMsg, true);
}
$InvoiceNo = GetNextTransNo(10);
$PeriodNo = GetPeriod($_POST['AdmissionDate']);
if (isset($_POST['SubmitInsurance'])) {
$_POST['Received'] = 0;
} else {
$_POST['InsuranceRef'] = '';
}
$SQL = "INSERT INTO debtortrans (
transno,
type,
debtorno,
branchcode,
trandate,
inputdate,
prd,
order_,
ovamount,
ovgst,
rate,
invtext,
reference,
shipvia,
alloc )
VALUES (
'" . $InvoiceNo . "',
10,
'" . $_POST['PatientNo'] . "',
'" . $_POST['BranchNo'] . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $OrderNo . "',
'" . $_SESSION['Items']['Value'] . "',
'0',
'1',
'" . _('Invoice for Laboratory test of Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . $_POST['InsuranceRef'] . "',
'1',
'" . $_POST['Received'] . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The debtor transaction record could not be inserted because');
$DbgMsg = _('The following SQL to insert the debtor transaction record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
for ($i = 0;$i < $_SESSION['Items']['Lines'];$i++) {
if (isset($_SESSION['Items'][$i]['StockID'])) {
$SQL = "SELECT mbflag
FROM stockmaster
WHERE stockid='" . $_SESSION['Items'][$i]['StockID'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
if (isset($_SESSION['Items'][$i]['StockID'])) {
$SQL = "INSERT INTO stockmoves (
stockid,
type,
transno,
loccode,
trandate,
debtorno,
branchcode,
prd,
reference,
qty,
price,
show_on_inv_crds,
newqoh
) VALUES (
'" . $_SESSION['Items'][$i]['StockID'] . "',
10,
'" . $InvoiceNo . "',
'" . $_SESSION['UserStockLocation'] . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $_POST['PatientNo'] . "',
'" . $_POST['BranchNo'] . "',
'" . $PeriodNo . "',
'" . _('Invoice for Laboratory test of Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . -$_SESSION['Items'][$i]['Quantity'] . "',
'" . $_SESSION['Items'][$i]['Price'] . "',
1,
0
)";
$BaseStockID = $_SESSION['Items'][$i]['StockID'];
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Stock movement records for') . ' ' . $_POST['StockID'] . ' ' . _('could not be inserted because');
$DbgMsg = _('The following SQL to insert the stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
}
}
$SQL = "SELECT salestype
FROM debtorsmaster
WHERE debtorno='" . $_POST['PatientNo'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$SalesGLAccounts = GetSalesGLAccount('AN', $BaseStockID, $MyRow['salestype']);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
tag,
narrative,
amount)
VALUES ( 10,
'" . $InvoiceNo . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $SalesGLAccounts['salesglcode'] . "',
'" . $_SESSION['DefaultTag'] . "',
'" . _('Invoice for Laboratory test of Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . -$_SESSION['Items']['Value'] . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The cost of sales GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
tag,
narrative,
amount )
VALUES ( 10,
'" . $InvoiceNo . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['debtorsact'] . "',
'" . $_SESSION['DefaultTag'] . "',
'" . _('Invoice for Laboratory test of Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . $_SESSION['Items']['Value'] . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock side of the cost of sales GL posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
if (isset($_POST['SubmitCash'])) {
$ReceiptNumber = GetNextTransNo(12);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
tag,
narrative,
amount)
VALUES (12,
'" . $ReceiptNumber . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $_POST['BankAccount'] . "',
'" . $_SESSION['DefaultTag'] . "',
'" . _('Payment of Laboratory test for Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . ($_SESSION['Items']['Value']) . "')";
$DbgMsg = _('The SQL that failed to insert the GL transaction for the bank account debit was');
$ErrMsg = _('Cannot insert a GL transaction for the bank account debit');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/* Now Credit Debtors account with receipt */
$SQL = "INSERT INTO gltrans ( type,
typeno,
trandate,
periodno,
account,
tag,
narrative,
amount)
VALUES (12,
'" . $ReceiptNumber . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $_SESSION['CompanyRecord']['debtorsact'] . "',
'" . $_SESSION['DefaultTag'] . "',
'" . _('Payment of Laboratory test for Patient number') . ' ' . $_POST['PatientNo'] . "',
'" . -($_SESSION['Items']['Value']) . "'
)";
$DbgMsg = _('The SQL that failed to insert the GL transaction for the debtors account credit was');
$ErrMsg = _('Cannot insert a GL transaction for the debtors account credit');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO banktrans (type,
transno,
bankact,
ref,
exrate,
functionalexrate,
transdate,
banktranstype,
amount,
currcode,
userid)
VALUES (12,
'" . $ReceiptNumber . "',
'" . $_POST['BankAccount'] . "',
'" . _('Laboratory test for Patient') . ' ' . $_POST['PatientNo'] . "',
'1',
'1',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'2',
'" . ($_SESSION['Items']['Value']) . "',
'" . $_SESSION['CompanyRecord']['currencydefault'] . "',
'" . $_SESSION['UserID'] . "'
)";
$DbgMsg = _('The SQL that failed to insert the bank account transaction was');
$ErrMsg = _('Cannot insert a bank transaction');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "INSERT INTO debtortrans (transno,
type,
debtorno,
trandate,
inputdate,
prd,
reference,
rate,
ovamount,
alloc,
invtext)
VALUES ('" . $ReceiptNumber . "',
12,
'" . $_POST['PatientNo'] . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . FormatDateForSQL($_POST['AdmissionDate']) . "',
'" . $PeriodNo . "',
'" . $InvoiceNo . "',
'1',
'" . -$_SESSION['Items']['Value'] . "',
'" . -$_POST['Received'] . "',
'" . _('Payment of Laboratory test for Patient number') . ' ' . $_POST['PatientNo'] . "'
)";
prnMsg(_('The transaction has been successfully posted'), 'success');
echo '<br /><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?New=True">' . _('Enter another receipt') . '</a>';
$DbgMsg = _('The SQL that failed to insert the customer receipt transaction was');
$ErrMsg = _('Cannot insert a receipt transaction against the customer because');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
DB_Txn_Commit();
unset($_SESSION['Items']);
echo '<meta http-equiv="Refresh" content="0; url=' . $RootPath . '/PDFPatientReceipt.php?FromTransNo=' . $InvoiceNo . '&InvOrCredit=Invoice&PrintPDF=True">';
include ('includes/footer.php');
$_SESSION['DefaultCashPoint'] = $_POST['BankAccount'];
exit;
} elseif (isset($_POST['SubmitInsurance'])) {
prnMsg(_('The transaction has been successfully posted'), 'success');
echo '<br /><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?New=True">' . _('Enter another receipt') . '</a>';
DB_Txn_Commit();
include ('includes/footer.php');
exit;
}
}
}
if (!isset($Patient)) {
ShowCustomerSearchFields($RootPath, $_SESSION['Theme']);
}
if (isset($_POST['Search']) or isset($_POST['Go1']) or isset($_POST['Go2']) or isset($_POST['Next']) or isset($_POST['Previous'])) {
$PatientResult = CustomerSearchSQL();
if (DB_num_rows($PatientResult) == 0) {
prnMsg(_('No patient records contain the selected text') . ' - ' . _('please alter your search criteria and try again'), 'info');
echo '<br />';
}
} //end of if search
if (isset($PatientResult)) {
ShowReturnedCustomers($PatientResult);
}
if (isset($Patient)) {
$SQL = "SELECT name,
clientsince,
salestype,
phoneno
FROM debtorsmaster
LEFT JOIN custbranch
ON debtorsmaster.debtorno=custbranch.debtorno
WHERE debtorsmaster.debtorno='" . $Patient[0] . "'";
$Result = DB_query($SQL);
$mydebtorrow = DB_fetch_array($Result);
$Care2xSQL = "SELECT care_encounter_prescription.article_item_number,
care_encounter_prescription.nr,
partcode,
total_dosage,
prescribe_date
FROM care_encounter_prescription
LEFT JOIN care_tz_drugsandservices
ON care_encounter_prescription.article_item_number=care_tz_drugsandservices.item_id
LEFT JOIN stockmaster
ON care_tz_drugsandservices.partcode=stockmaster.stockid
LEFT JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
LEFT JOIN care_encounter
ON care_encounter.encounter_nr=care_encounter_prescription.encounter_nr
AND stockcategory.stocktype='T'
WHERE care_encounter.pid='" . $Patient[0] . "'
AND care_encounter_prescription.bill_number=''";
$Care2xResult = DB_query($Care2xSQL);
$i = 0;
while ($MyCare2xRow = DB_fetch_array($Care2xResult)) {
$PriceSQL = "SELECT price
FROM prices
WHERE stockid='" . $MyCare2xRow['partcode'] . "'
AND typeabbrev='" . $mydebtorrow['salestype'] . "'
AND '" . $MyCare2xRow['prescribe_date'] . "' between startdate and enddate";
$PriceResult = DB_query($PriceSQL);
if (DB_num_rows($PriceResult) == 0) {
$Price = 0;
} else {
$MyRow = DB_fetch_array($PriceResult);
$Price = $MyRow['price'];
}
$_SESSION['Items'][$i]['StockID'] = $MyCare2xRow['partcode'];
$_SESSION['Items'][$i]['Quantity'] = $MyCare2xRow['total_dosage'];
$_SESSION['Items'][$i]['Price'] = $Price;
$_SESSION['Items'][$i]['Care2x'] = $MyCare2xRow['nr'];
$_SESSION['Items']['Value']+= $Price * $MyCare2xRow['total_dosage'];
$_SESSION['Items']['Lines']++;
$i++;
}
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/TestTubes.png" title="' . _('Search') . '" alt="" />' . $Title . '</p>';
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method=post>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<input type="hidden" name="PriceList" value="' . $mydebtorrow['salestype'] . '" />';
echo '<input type="hidden" name="PatientNo" value="' . $Patient[0] . '" />';
echo '<input type="hidden" name="BranchNo" value="' . $Patient[1] . '" />';
echo '<table class="selection">';
echo '<tr>
<th colspan="3"><font size="3" color="navy">' . $mydebtorrow['name'] . '</font><font size="2" color="navy"> - ' . $mydebtorrow['phoneno'] . '</font></th>
<th style="text-align: right"><a href="KCMCEditPatientDetails.php?PatientNumber=' . $Patient[0] . '&BranchCode=' . $Patient[1] . '" target="_blank">
<img width="15px" src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/user.png" alt="Patient Details" /></a>
</th>
</tr>';
echo '<tr><td>' . _('Date of Admission') . ':</td>
<td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="AdmissionDate" maxlength="10" size="11" value="' . date($_SESSION['DefaultDateFormat']) . '" /></td></tr>';
echo '<tr><td>' . _('Type of Laboratory test') . ':</td>';
$SQL = "SELECT stockid,
description
FROM stockmaster
LEFT JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE stockcategory.stocktype='T'";
$Result = DB_query($SQL);
if (isset($_POST['StockID'])) {
$StockID = $_POST['StockID'];
} else {
$StockID = '';
}
for ($i = 0;$i < $_SESSION['Items']['Lines'];$i++) {
if (isset($_SESSION['Items'][$i])) {
while ($MyRow = DB_fetch_array($Result)) {
if ($MyRow['stockid'] == $_SESSION['Items'][$i]['StockID']) {
echo '<td>' . $MyRow['description'] . '</td>';
}
}
echo '<td> ' . _('Quantity') . ' - ';
echo ' ' . $_SESSION['Items'][$i]['Quantity'];
echo ' @ ' . number_format($_SESSION['Items'][$i]['Price'], 0) . ' ' . $_SESSION['CompanyRecord']['currencydefault'] . '</td>';
if ($_SESSION['CanAmendBill'] == 1) {
echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?Delete=' . $i . '&Patient=' . $Patient[0] . '&Branch=' . $Patient[1] . '">' . _('Delete') . '</a></td></tr>';
} else {
echo '<td>' . _('Delete') . '</td></tr>';
}
DB_data_seek($Result, 0);
echo '<tr><td>';
}
}
echo '<td><select name="StockID"">';
echo '<option value=""></option>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<option value="' . $MyRow['stockid'] . '">' . $MyRow['stockid'] . ' - ' . $MyRow['description'] . '</option>';
}
echo '</select>';
DB_data_seek($Result, 0);
echo '</td><td> ' . _('Quantity') . ' - ';
echo '<select name="Quantity" onChange="ReloadForm(ChangeItem)">';
echo '<option value=""></option>';
for ($j = 0;$j < 100;$j++) {
echo '<option value="' . $j . '">' . $j . '</option>';
}
echo '</select></td></tr>';
echo '<input type="submit" name="ChangeItem" style="display:none" value=" " />';
echo '<tr><td>' . _('Payment Fee') . '</td>';
echo '<td>' . number_format($_SESSION['Items']['Value'], 0) . ' ' . $_SESSION['CompanyRecord']['currencydefault'] . '</td></tr>';
echo '<input type="hidden" name="Price" value="' . $_SESSION['Items']['Value'] . '" />';
$SQL = "SELECT supplierid,
suppname
FROM suppliers
LEFT JOIN suppliertype
ON suppliertype.typeid=suppliers.supptype
WHERE suppliertype.typename='Doctors'";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<tr><td>' . _('Doctors Name') . ':</td>';
echo '<td><select name="Doctor">';
echo '<option value="">' . _('Select a doctor from list') . '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if (isset($_POST['Doctor']) and $_POST['Doctor'] == $MyRow['supplierid']) {
echo '<option selected="selected" value="' . $MyRow['supplierid'] . '">' . $MyRow['supplierid'] . ' - ' . $MyRow['suppname'] . '</option>';
} else {
echo '<option value="' . $MyRow['supplierid'] . '">' . $MyRow['supplierid'] . ' - ' . $MyRow['suppname'] . '</option>';
}
}
echo '</select></td></tr>';
echo '<tr><td>';
if (isset($_POST['DoctorsFee']) and $_POST['DoctorsFee'] != '') {
echo _('Doctors Fee') . ':</td><td><input type="text" class="number" size="10" name="DoctorsFee" value="' . locale_number_format(filter_number_format($_POST['DoctorsFee']), $DecimalPlaces) . '" />';
} else {
echo _('Doctors Fee') . ':</td><td><input type="text" class="number" size="10" name="DoctorsFee" value="" />';
}
if (isset($_POST['AddDoctorFee'])) {
echo '<input type="checkbox" checked="checked" name="AddDoctorFee" value="Add Doctors fee to balance" onChange="ReloadForm(ChangeItem)" />' . _('Add Doctors fee to balance') . '</td></tr>';
} else {
echo '<input type="checkbox" name="AddDoctorFee" value="Add Doctors fee to balance" onChange="ReloadForm(ChangeItem)" />' . _('Add Doctors fee to balance') . '</td></tr>';
}
}
if ($Patient[1] == 'CASH') {
if (!isset($Received)) {
$Received = $_SESSION['Items']['Value'];
}
echo '<tr><td>' . _('Amount Received') . '</td>';
echo '<td><input type="text" class="number" size="10" name="Received" value="' . number_format($Received, 0, '.', '') . '" /></td></tr>';
$SQL = "SELECT bankaccountname,
bankaccounts.accountcode,
bankaccounts.currcode
FROM bankaccounts
INNER JOIN bankaccountusers
ON bankaccounts.accountcode=bankaccountusers.accountcode
WHERE pettycash=1
AND bankaccountusers.userid='" . $_SESSION['UserID'] . "'";
$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$AccountsResults = DB_query($SQL, $ErrMsg, $DbgMsg);
echo '<tr><td>' . _('Received into') . ':</td><td><select name="BankAccount">';
if (DB_num_rows($AccountsResults) == 0) {
echo '</select></td></tr></table><p>';
prnMsg(_('Bank Accounts have not yet been defined. You must first') . ' <a href="' . $RootPath . '/BankAccounts.php">' . _('define the bank accounts') . '</a> ' . _('and general ledger accounts to be affected'), 'warn');
include ('includes/footer.php');
exit;
} else {
echo '<option value=""></option>';
while ($MyRow = DB_fetch_array($AccountsResults)) {
/*list the bank account names */
if (isset($_SESSION['DefaultCashPoint']) and $_SESSION['DefaultCashPoint'] == $MyRow['accountcode']) {
echo '<option selected value="' . $MyRow['accountcode'] . '">' . $MyRow['bankaccountname'] . ' - ' . $MyRow['currcode'] . '</option>';
} else {
echo '<option value="' . $MyRow['accountcode'] . '">' . $MyRow['bankaccountname'] . ' - ' . $MyRow['currcode'] . '</option>';
}
}
echo '</select></td></tr>';
}
echo '<tr><td>' . _('Comments') . '</td>';
echo '<td><input type="text" size="50" name="Comments" value="" /></td></tr>';
echo '</table>';
echo '<input type="submit" name="SubmitCash" value="' . _('Make Payment') . '" />';
} else {
echo '<tr><td>' . _('Insurance Reference') . '</td>';
echo '<td><input type="text" size="10" name="InsuranceRef" value="" /></td></tr>';
echo '<tr><td>' . _('Comments') . '</td>';
echo '<td><input type="text" size="50" name="Comments" value="" /></td></tr>';
echo '</table>';
echo '<input type="submit" name="SubmitInsurance" value="' . _('Process Invoice') . '" />';
}
echo '<input type="submit" name="Cancel" value="' . _('Cancel Transaction') . '" />';
echo '</form>';
}
include ('includes/footer.php');
?>