Advertisement
Guest User

Untitled

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