Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['submit'])) {
  4. try {
  5. require "config.php";
  6. require "common.php";
  7. function toCurrency($number)
  8. {
  9. return '$' . number_format($number,2);
  10. }
  11.  
  12. $connection = new PDO($dsn, $username, $password, $options);
  13. $db = new PDO($dsn, $username, $password, $options);
  14. $db1 = new PDO($dsn, $username, $password, $options);
  15.  
  16. $sql = "SELECT
  17. *
  18. FROM joblist
  19. WHERE customer = :customer";
  20.  
  21. $sql_val = "SELECT customer,
  22. SUM(value) AS total_value
  23. FROM joblist
  24. AS `total_value`
  25. GROUP BY customer";
  26. $sql_bal = "SELECT customer,
  27. SUM(balance) AS total_balance
  28. FROM joblist
  29. AS `total_balance`
  30. GROUP By customer";
  31.  
  32. //var_dump($sql_bal);
  33.  
  34.  
  35. $customer = $_POST['customer'];
  36. $statement = $connection->prepare($sql);
  37. $statement->bindParam(':customer', $customer, PDO::PARAM_STR);
  38. $statement->execute();
  39. $result = $statement->fetchAll();
  40. // total SUM for value
  41. $stmt = $db->prepare($sql_val);
  42. $stmt->bindParam(':total_value', $total_value, PDO::PARAM_STR);
  43. $stmt->execute();
  44. $totalv = $stmt->fetchAll(\PDO::FETCH_GROUP|\PDO::FETCH_ASSOC);
  45.  
  46. $sumv = array_sum(array_column($totalv, 'total_value'));
  47.  
  48. var_dump($totalv);
  49.  
  50. // total SUM fro balance
  51.  
  52. $stmt1 = $db1->prepare($sql_bal);
  53. $stmt1->bindParam(':total_balance', $total_balance, PDO::PARAM_INT);
  54. $stmt1->execute();
  55. $totalb = $stmt1->fetchAll(FETCH_ASSOC);
  56. $sumb = array_sum(array_column($totalb, 'total_balance'));
  57.  
  58.  
  59. } catch(PDOException $error) {
  60. echo $sql . "<br>" . $error->getMessage();
  61. die();
  62. }
  63.  
  64. }
  65. ?>
  66.  
  67. <?php
  68. if (isset($_POST['submit'])) {
  69. if ($result && $statement->rowCount() > 0) { ?>
  70.  
  71.  
  72. <h2>Results</h2>
  73.  
  74. <table>
  75. <thead>
  76. <tr>
  77. <th>Work Order #</th>
  78. <th>Customer</th>
  79. <th>Description</th>
  80. <th>Value</th>
  81. <th>Balance</th>
  82. <th>Status</th>
  83. <th>Notes</th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87. <?php foreach ($result as $row) { ?>
  88.  
  89. <tr>
  90. <td><?php echo escape($row["work_order"]); ?></td>
  91. <td><?php echo escape($row["customer"]); ?></td>
  92. <td><?php echo escape($row["description"]); ?></td>
  93. <td><?php echo toCurrency($row["value"]); ?></td>
  94. <td><?php echo tocurrency($row["balance"]); ?></td>
  95. <td><?php echo escape($row["status"]); ?></td>
  96. <td><?php echo escape($row["notes"]); ?> </td>
  97. </tr>
  98. <?php } ?>
  99. </tbody>
  100. <P> </P>
  101. <tfoot>
  102.  
  103. <tr>
  104. <th id="value_result" align="right" colspan="3">Totals :</th>
  105. <td><class="total-column" colspan="4"><?php echo toCurrency($sumv); ?></td>
  106. <td><class="total-column" colspan="5"><?php echo toCurrency($sumb); ?></td>
  107. </tr>
  108.  
  109. </tfoot>
  110.  
  111.  
  112. </table>
  113.  
  114. <?php } else { ?>
  115. > No results found for <?php echo escape($_POST['customer']); ?>.
  116. <?php }
  117. } ?>
  118.  
  119. <?php require "templates/header.php";?>
  120.  
  121. <h2>Find Company/Customer Name</h2>
  122.  
  123. <form method="post">
  124. <label for="customer">Customer/Company Name</label>
  125. <input type="text" id="customer" name="customer">
  126. <input type="submit" name="submit" value="View Results">
  127. </form>
  128.  
  129.  
  130. <p><a href="welcome.php">Back to home</a></p>
  131.  
  132. <?php require "templates/footer.php"; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement