PageRenderTime 137ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/SERVER/dev/admin/patronage_detail.php

https://github.com/joelbrock/is4c_nofc
PHP | 167 lines | 143 code | 19 blank | 5 comment | 17 complexity | accd27bc2cc12a45d071fcd470033229 MD5 | raw file
  1. <?
  2. require_once('../define.conf');
  3. $ryear = $_GET['ryear'];
  4. $fyear = $ryear - 1;
  5. for ($i=DATE('Y');$i>2006;$i--) {
  6. if ($i == $fyear) {
  7. $year_array .= '';
  8. } else {
  9. $year_array .= "," . $i;
  10. }
  11. }
  12. $year_array = trim($year_array, ",");
  13. $cardq = "SELECT card_no FROM " . DB_LOGNAME . ".PR_redeemed WHERE YEAR(datetime) = '$ryear'";
  14. $cardr = mysql_query($cardq) OR die(mysql_error() . "<br />" . $cardq);
  15. while ($row = mysql_fetch_array($cardr)) {
  16. $card_array .= $row[0] . ",";
  17. }
  18. if ($card_array) {
  19. $card_array = trim($card_array, ",");
  20. } else {
  21. $card_array = '0';
  22. }
  23. // echo 'Card array=' . $card_array . '<br>';
  24. if (isset($_GET['popup'])) {
  25. if ($_GET['popup'] == 'redeemed') {
  26. $query = "SELECT DATE(p.datetime) as date,
  27. p.card_no as card_no,
  28. c.LastName as lastname,
  29. c.FirstName as firstname,
  30. p.description as description,
  31. p.total as total,
  32. r.paid as paid_out,
  33. (p.total + r.paid) as diff
  34. FROM " . DB_LOGNAME . ".PR_redeemed p, custdata c, cust_pr_$ryear r
  35. WHERE p.card_no = c.CardNo AND c.CardNo = r.card_no
  36. AND ((YEAR(p.datetime) = $ryear) OR (SUBSTR(p.description, -4) = $fyear))
  37. HAVING SUBSTR(p.description, -4) NOT IN ($year_array)
  38. ORDER BY p.datetime DESC";
  39. // echo $query;
  40. $result = mysql_query($query) OR die(mysql_error() . "<br />" . $query);
  41. $num = mysql_num_rows($result);
  42. echo "<html><head><title>Patronage Redemption Report -- " . date('Y-m-d') . "</title>
  43. <script type=\"text/javascript\" src=\"../src/tablesort.js\"></script>
  44. <link rel='stylesheet' href='../src/style.css' type='text/css' />
  45. <link rel='stylesheet' href='../src/tablesort.css' type='text/css' /></head>";
  46. echo "<center><h1>FY$fyear VOUCHERS REDEEMED</h1></center>\n";
  47. echo "<table id=\"redeemed\" cellpadding=0 cellspacing=0 border=0 class=\"sortable-onload-0 rowstyle-alt colstyle-alt\">\n
  48. <caption>Search yielded (".$num.") results. Generated on " . date('n/j/y \a\t h:i A') . "</caption>\n
  49. <thead>\n
  50. <tr>\n
  51. <th class=\"sortable-numeric\">Date</th>\n
  52. <th class=\"sortable-numeric\">mem#</th>\n
  53. <th class=\"sortable-text\">Last Name</th>\n
  54. <th class=\"sortable-text\">First Name</th>\n
  55. <th class=\"sortable-currency\">Redeemed</th>\n
  56. <th class=\"sortable-currency\">Paid Out</th>\n
  57. <th class=\"sortable-currency\">diff</th>\n
  58. </tr>\n
  59. </thead>\n
  60. <tbody>\n";
  61. while ($row = mysql_fetch_assoc($result)) {
  62. echo '<tr>
  63. <td align=center>' . $row["date"] . '</td>
  64. <td align=center>' . $row["card_no"] . '</td>
  65. <td align=left>' . $row["lastname"] . '</td>
  66. <td align=left>' . $row["firstname"] . '</td>
  67. <td align=right>' . money_format('%n',$row["total"]) . '</td>
  68. <td align=right>' . money_format('%n',$row["paid_out"]) . '</td>
  69. <td align=right>';
  70. if ($row['diff'] != 0) { echo "<font color=red style=bold>";}
  71. echo money_format('%n',$row["diff"]) . '</td>
  72. </tr>';
  73. }
  74. mysql_free_result($result);
  75. }
  76. elseif ($_GET['popup'] == 'daily') {
  77. $query = "SELECT DATE(datetime) AS date, description, COUNT(*) AS ct, -SUM(total) AS total
  78. FROM " . DB_LOGNAME . ".PR_redeemed
  79. WHERE ((YEAR(datetime) = $ryear) OR (SUBSTR(description, -4) = $fyear))
  80. AND SUBSTR(description, -4) NOT IN ($year_array)
  81. GROUP BY date";
  82. // echo $query;
  83. $result = mysql_query($query) OR die(mysql_error() . "<br />" . $query);
  84. $num = mysql_num_rows($result);
  85. echo "<html><head><title>Patronage Redemption Report -- " . date('Y-m-d') . "</title>
  86. <script type=\"text/javascript\" src=\"../src/tablesort.js\"></script>
  87. <link rel='stylesheet' href='../src/style.css' type='text/css' />
  88. <link rel='stylesheet' href='../src/tablesort.css' type='text/css' /></head>";
  89. echo "<center><h1>FY$fyear DAILY PATRONAGE TOTALS</h1></center>\n";
  90. echo "<table id=\"daily\" cellpadding=0 cellspacing=0 border=0 class=\"sortable-onload-0 rowstyle-alt colstyle-alt\">\n
  91. <caption>Search yielded (".$num.") results. Generated on " . date('n/j/y \a\t h:i A') . "</caption>\n
  92. <thead>\n
  93. <tr>\n
  94. <th class=\"sortable-numeric\">date</th>\n
  95. <th class=\"sortable-text\">count</th>\n
  96. <th class=\"sortable-text\">total</th>\n
  97. </tr>\n
  98. </thead>\n
  99. <tbody>\n";
  100. while ($row = mysql_fetch_assoc($result)) {
  101. echo '<tr>
  102. <td align=center>' . $row["date"] . '</td>
  103. <td align=center>' . $row["ct"] . '</td>
  104. <td align=right>' . money_format('%n',$row["total"]) . '</td>
  105. </tr>';
  106. }
  107. mysql_free_result($result);
  108. }
  109. elseif ($_GET['popup'] == 'outstanding') {
  110. $query = "SELECT r.card_no as card_no,
  111. c.lastname as lastname,
  112. c.firstname as firstname,
  113. r.paid as paid_out
  114. FROM cust_pr_$ryear r, custdata c
  115. WHERE r.card_no = c.CardNo
  116. AND r.card_no NOT IN ($card_array)";
  117. // echo $query;
  118. $result = mysql_query($query) OR die(mysql_error() . "<br />" . $query);
  119. $num = mysql_num_rows($result);
  120. echo "<html><head><title>Patronage Redemption Report -- " . date('Y-m-d') . "</title>
  121. <script type=\"text/javascript\" src=\"../src/tablesort.js\"></script>
  122. <link rel='stylesheet' href='../src/style.css' type='text/css' />
  123. <link rel='stylesheet' href='../src/tablesort.css' type='text/css' /></head>";
  124. echo "<center><h1>FY$fyear VOUCHERS OUTSTANDING</h1></center>\n";
  125. echo "<table id=\"outstanding\" cellpadding=0 cellspacing=0 border=0 class=\"sortable-onload-0 rowstyle-alt colstyle-alt\">\n
  126. <caption>Search yielded (".$num.") results. Generated on " . date('n/j/y \a\t h:i A') . "</caption>\n
  127. <thead>\n
  128. <tr>\n
  129. <th class=\"sortable-numeric\">mem#</th>\n
  130. <th class=\"sortable-text\">Last Name</th>\n
  131. <th class=\"sortable-text\">First Name</th>\n
  132. <th class=\"sortable-currency\">Paid Out</th>\n
  133. </tr>\n
  134. </thead>\n
  135. <tbody>\n";
  136. while ($row = mysql_fetch_assoc($result)) {
  137. echo '<tr>
  138. <td align=center>' . $row["card_no"] . '</td>
  139. <td align=left>' . $row["lastname"] . '</td>
  140. <td align=left>' . $row["firstname"] . '</td>
  141. <td align=right>' . money_format('%n',$row["paid_out"]) . '</td>
  142. </tr>';
  143. }
  144. mysql_free_result($result);
  145. }
  146. }
  147. // debug_p($_REQUEST, "all the data coming in");
  148. ?>