-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.php
executable file
·114 lines (98 loc) · 3.69 KB
/
check.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
<?php
include('connect_db.php');
session_start();
if(isset($_POST['customer_id']))
{
$c_id=$_POST['customer_id'];
$cname=$_POST['customer_name'];
$age=$_POST['age'];
$sex=$_POST['sex'];
$postal=$_POST['postal_address'];
$phone=$_POST['phone'];
$_SESSION['custId']=$c_id;
$_SESSION['custName']=$cname;
$_SESSION['age']=$age;
$_SESSION['sex']=$sex;
$_SESSION['postal_address']=$postal;
$_SESSION['phone']=$phone;
}
if(isset($_POST['drug_name']))
{
$drug=$_POST['drug_name'];
$strength=$_POST['strength'];
$dose=$_POST['dose'];
$quantity=$_POST['quantity'];
$sql=mysql_query("INSERT INTO tempPrescri(customer_id,customer_name,age,sex,postal_address,phone,drug_name,strength,dose,quantity)
VALUES('{$_SESSION['custId']}','{$_SESSION['custName']}','{$_SESSION['age']}','{$_SESSION['sex']}','{$_SESSION['address']}','{$_SESSION['phone']}','{$drug}','{$strength}','{$dose}','{$quantity}')");
$_SESSION['quantity']=$quantity;
$get_cost=mysql_query("SELECT cost FROM stock WHERE drug_name='{$drug}'");
$cost=mysql_fetch_array($get_cost);
$tot=$quantity*$cost[0];
$file=fopen("receipts/docs/".$_SESSION['custId'].".txt", "a+");
fwrite($file, $drug.";".$strength.";".$dose.";".$quantity.";".$cost[0].";".$tot."\n");
fclose($file);
echo "<table width=\"100%\" border=1>";
echo "<tr>
<th>Drug</th>
<th>Strength </th>
<th>Dose</th>
<th>Quantity </th></tr>";
// loop through results of database query, displaying them in the table
$result = mysql_query("SELECT * FROM tempPrescri")or die(mysql_error());
while($row = mysql_fetch_array($result))
{
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['drug_name'] . '</td>';
echo '<td>' . $row['strength'] . '</td>';
echo '<td>' . $row['dose'] . '</td>';
echo '<td>' . $row['quantity'] . '</td>';
}
}
if(isset($_POST['invoice_no']))
{
$invoice=$_POST['invoice_no'];
$receipt=$_POST['receipt_no'];
$amount=$_POST['amount'];
$payment=$_POST['payment_type'];
$serial=$_POST['serial_no'];
$_SESSION['receiptNo']=$receipt;
$_SESSION['amount']=$amount;
$_SESSION['paymentType']=$payment;
$_SESSION['serialNo']=$serial;
$getDetails=mysql_query("SELECT invoice,drug,cost,quantity FROM invoice_details WHERE invoice='{$invoice}'");
$getQuantity=mysql_query("SELECT quantity FROM invoice_details WHERE invoice_id='{$invoice}'");
$file=fopen("receipts/docs/".$_SESSION['invoiceNo'].".txt", "w");
echo "<table width=\"100%\" border=1>";
echo "<tr>
<th>Drug </th>
<th>Unit cost</th>
<th>Quantity </th>
<th>Total Cost(Ksh.)</th></tr>";
while($item5=mysql_fetch_array($getDetails))
{
$getDrug=mysql_query("SELECT drug_name FROM stock WHERE stock_id='{$item5['drug']}'");
$drug=mysql_fetch_array($getDrug);
$qtty=mysql_fetch_array($getQuantity);
$tot=$item5['cost']*$item5['quantity'];
$total[]=$tot;
fwrite($file, $drug[0].";".$item5['cost'].";".$item5['quantity'].";".$tot.";\n");
echo "<tr>";
echo '<td>' . $drug[0] . '</td>';
echo '<td align="right">' . number_format($item5['cost'],2) . '</td>';
echo '<td align="right">' . $item5['quantity'] . '</td>';
echo '<td align="right">' . number_format($tot,2). '</td>';
echo "</tr>";
}
$zote=array_sum($total);
echo "<tr>";
echo '<td><strong>TOTAL</strong></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td align="right">' . number_format($zote,2) . '</td>';
echo "</tr>";
fwrite($file, "TOTAL;;;".$zote.";\n");
fclose($file);
echo "</table>";
}
?>