Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.69 KB | None | 0 0
  1. <?php
  2. include('connect_db.php');
  3. session_start();
  4. if(isset($_POST['customer_id']))
  5. {
  6. $c_id=$_POST['customer_id'];
  7.     $cname=$_POST['customer_name'];
  8.     $age=$_POST['age'];
  9.     $sex=$_POST['sex'];
  10.     $postal=$_POST['postal_address'];
  11.     $phone=$_POST['phone'];
  12.    
  13.     $_SESSION['custId']=$c_id;
  14.     $_SESSION['custName']=$cname;
  15.     $_SESSION['age']=$age;
  16.     $_SESSION['sex']=$sex;
  17.     $_SESSION['postal_address']=$postal;
  18.     $_SESSION['phone']=$phone;
  19.                        
  20. }
  21.  
  22. if(isset($_POST['drug_name']))
  23. {
  24.     $drug=$_POST['drug_name'];
  25.     $strength=$_POST['strength'];
  26.     $dose=$_POST['dose'];
  27.     $quantity=$_POST['quantity'];
  28.     $sql=mysql_query("INSERT INTO tempPrescri(customer_id,customer_name,age,sex,postal_address,phone,drug_name,strength,dose,quantity)
  29.                         VALUES('{$_SESSION['custId']}','{$_SESSION['custName']}','{$_SESSION['age']}','{$_SESSION['sex']}','{$_SESSION['address']}','{$_SESSION['phone']}','{$drug}','{$strength}','{$dose}','{$quantity}')");
  30.                        
  31.                         $_SESSION['quantity']=$quantity;
  32.     $get_cost=mysql_query("SELECT cost FROM stock WHERE drug_name='{$drug}'");
  33.     $cost=mysql_fetch_array($get_cost);
  34.     $tot=$quantity*$cost[0];
  35.    
  36.     $file=fopen("receipts/docs/".$_SESSION['custId'].".txt", "a+");
  37.     fwrite($file, $drug.";".$strength.";".$dose.";".$quantity.";".$cost[0].";".$tot."\n");
  38.     fclose($file);
  39.     echo "<table width=\"100%\" border=1>";
  40.         echo "<tr>
  41.         <th>Drug</th>
  42.         <th>Strength </th>
  43.         <th>Dose</th>
  44.         <th>Quantity </th></tr>";
  45.         // loop through results of database query, displaying them in the table
  46.          $result = mysql_query("SELECT * FROM tempPrescri")or die(mysql_error());
  47.         while($row = mysql_fetch_array($result))
  48.         {
  49.                 // echo out the contents of each row into a table
  50.                 echo "<tr>";
  51.                
  52.                 echo '<td>' . $row['drug_name'] . '</td>';
  53.                 echo '<td>' . $row['strength'] . '</td>';
  54.                 echo '<td>' . $row['dose'] . '</td>';
  55.                 echo '<td>' . $row['quantity'] . '</td>';
  56.                 }
  57.  
  58. }
  59.  
  60. if(isset($_POST['invoice_no']))
  61. {
  62. $invoice=$_POST['invoice_no'];
  63.  
  64.     $receipt=$_POST['receipt_no'];
  65.     $amount=$_POST['amount'];
  66.     $payment=$_POST['payment_type'];
  67.     $serial=$_POST['serial_no'];
  68.    
  69.     $_SESSION['receiptNo']=$receipt;
  70.     $_SESSION['amount']=$amount;
  71.     $_SESSION['paymentType']=$payment;
  72.     $_SESSION['serialNo']=$serial;
  73. $getDetails=mysql_query("SELECT invoice,drug,cost,quantity FROM invoice_details WHERE invoice='{$invoice}'");
  74. $getQuantity=mysql_query("SELECT quantity FROM invoice_details WHERE invoice_id='{$invoice}'");
  75. $file=fopen("receipts/docs/".$_SESSION['invoiceNo'].".txt", "w");
  76.    
  77.    
  78.     echo "<table width=\"100%\" border=1>";
  79.         echo "<tr>
  80.        
  81.         <th>Drug </th>
  82.         <th>Unit cost</th>
  83.         <th>Quantity </th>
  84.         <th>Total Cost(Ksh.)</th></tr>";
  85. while($item5=mysql_fetch_array($getDetails))
  86.             {
  87.             $getDrug=mysql_query("SELECT drug_name FROM stock WHERE stock_id='{$item5['drug']}'");
  88.                        
  89.             $drug=mysql_fetch_array($getDrug);
  90.             $qtty=mysql_fetch_array($getQuantity);
  91.             $tot=$item5['cost']*$item5['quantity'];
  92.             $total[]=$tot;
  93.             fwrite($file, $drug[0].";".$item5['cost'].";".$item5['quantity'].";".$tot.";\n");  
  94.                
  95.                 echo "<tr>";
  96.                 echo '<td>' . $drug[0] . '</td>';
  97.                 echo '<td align="right">' . number_format($item5['cost'],2) . '</td>';
  98.                 echo '<td align="right">' . $item5['quantity'] . '</td>';
  99.                 echo '<td align="right">' . number_format($tot,2). '</td>';
  100.                 echo "</tr>";
  101.                        
  102.             }
  103.     $zote=array_sum($total);
  104. echo "<tr>";
  105.                 echo '<td><strong>TOTAL</strong></td>';
  106.                 echo '<td></td>';
  107.                 echo '<td></td>';
  108.                 echo '<td align="right">' . number_format($zote,2) . '</td>';
  109.                 echo "</tr>";  
  110. fwrite($file, "TOTAL;;;".$zote.";\n");
  111. fclose($file);
  112. echo "</table>";               
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement