Guest User

Untitled

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