function fetch_data($date1, $date2) { global $sql, $pCodes_lookup; $data = array('tenders' => array(), 'sales' => array(), 'other' => array()); $ret = ""; $dlog = DTransactionsModel::selectDlog($date1, $date2); $dlog = "trans_archive.dlogBig"; $default_args = array($date1 . ' ' . $date2); $pageOneP = $sql->prepare("select rowName,sum(amt) from dailyDeposit\n WHERE dateStr = ? and\n rowName in ('depositAmount','buyAmount')\n group by rowName"); $pageOneR = $sql->execute($pageOneP, $default_args); while ($pageOneW = $sql->fetch_row($pageOneR)) { $data['other'][$pageOneW[0]] = $pageOneW[1]; } $data['other']['depositChecks'] = 0; $data['other']['atmNet'] = 0; $pageOneP2 = $sql->prepare("select denomination,amt FROM dailyDeposit\n WHERE dateStr = ? and\n rowName in ('depositAmount','atm')\n and denomination in ('Checks','fill','reject')"); $pageOneR2 = $sql->execute($pageOneP2, $default_args); while ($row = $sql->fetch_row($pageOneR2)) { switch (strtolower($row['denomination'])) { case 'checks': $data['other']['depositChecks'] += $row['amt']; $data['other']['depositAmount'] -= $row['amt']; break; case 'fill': $data['other']['atmNet'] += $row['amt']; break; case 'reject': $data['other']['atmNet'] -= $row['amt']; break; } } $date_args = array($date1 . ' 00:00:00', $date2 . ' 23:59:59'); $tenderP = $sql->prepare("select sum(amt),\n tender_type,tendername,\n YEAR(date),MONTH(date),DAY(date)\n FROM dailyCounts as d left join is4c_op.tenders as t\n on d.tender_type = t.tenderCode\n WHERE date between ? AND ?\n group by\n YEAR(date),MONTH(date),DAY(date),\n tender_type,tendername order by tendername"); $tenderR = $sql->execute($tenderP, $date_args); while ($tenderW = $sql->fetch_row($tenderR)) { $timestamp = getTS($tenderW, 3, 4, 5); $code = $tenderW[1]; $name = $tenderW[2]; if ($code == "SCA") { $code = "CA"; $tenderW[0] *= -1; } if ($code == "CK") { $code = "CA"; } if ($code == "CA") { $name = "Coin, Cash, and Checks"; } if ($code == "EC") { $code = "EF"; } if ($code == "CC") { $name = "Electronic Deposit (CC)"; } if ($code == "EF") { $name = "Electronic Deposit (EBT)"; $data['tenders']['AX']['name'] = 'Electronic Deposit (AMEX)'; } if (!isset($data['tenders'][$code])) { $data['tenders'][$code] = array(); } if (!isset($data['tenders'][$code][$timestamp])) { $data['tenders'][$code][$timestamp] = 0; } $data['tenders'][$code]['name'] = $name; $data['tenders'][$code][$timestamp] += $tenderW[0]; //$data['tenders']['AX'][$timestamp] = 0; } $extraTenderP = $sql->prepare("select YEAR(tdate),MONTH(tdate),DAY(tdate),\n trans_subtype,sum(total)*-1 FROM {$dlog} as d\n WHERE tdate between ? AND ?\n and trans_subtype in ('MA','RR','PP')\n group by\n YEAR(tdate),MONTH(tdate),DAY(tdate),\n trans_subtype"); $extraTenderR = $sql->execute($extraTenderP, $date_args); while ($extraTenderW = $sql->fetch_row($extraTenderR)) { $timestamp = getTS($extraTenderW, 0, 1, 2); $code = $extraTenderW[3]; if (!isset($data['tenders'][$code])) { $data['tenders'][$code] = array(); } if (!isset($data['tenders'][$code][$timestamp])) { $data['tenders'][$code][$timestamp] = 0; } $name = "RRR Coupons"; if ($code == "MA") { $name = "Mad Coupons"; } if ($code == "PP") { $name = "Pay Pal"; } $data['tenders'][$code]['name'] = $name; $data['tenders'][$code][$timestamp] += $extraTenderW[4]; } // always include these $data['other']['misc0'] = array('', array()); $data['other']['misc1'] = array('', array()); $data['other']['misc2'] = array('', array()); $data['other']['axfees'] = array('63340', array()); $salesP = $sql->prepare("select YEAR(tdate),MONTH(tdate),DAY(tdate),\n CASE WHEN department = 991 then '991' when department=992 then '992' \n else convert(t.salesCode,char) end as pcode,\n sum(total),trans_type\n FROM {$dlog} as d left join is4c_op.departments as t on\n d.department = t.dept_no \n WHERE tdate BETWEEN ? AND ?\n AND trans_subtype NOT IN ('CP','IC')\n and trans_type not in ('S','T')\n AND (register_no <> 20 or department=703)\n GROUP BY \n YEAR(tdate),MONTH(tdate),DAY(tdate),\n trans_type,\n CASE WHEN department = 991 then '991' when department=992 then '992' else convert(t.salesCode,char) end\n ORDER BY\n CASE WHEN department = 991 then '991' when department=992 then '992' else convert(t.salesCode,char) end"); $salesR = $sql->execute($salesP, $date_args); $preTS = 0; while ($salesW = $sql->fetch_row($salesR)) { $timestamp = getTS($salesW, 0, 1, 2); /* fill in zeroes for all pcodes */ if ($timestamp != $preTS) { foreach ($pCodes_lookup as $k => $v) { if (!isset($data['sales'][$k])) { $data['sales'][$k] = array(); } if (!isset($data['sales'][$k][$timestamp])) { $data['sales'][$k][$timestamp] = 0; } } $preTS = $timestamp; } if (!isset($data['other']['axfees'][1][$timestamp])) { $data['other']['axfees'][1][$timestamp] = 0; } $pcode = $salesW[3]; if ($pcode == "42231") { if (!isset($data['other']['misc1'][1][$timestamp])) { $data['other']['misc1'][1][$timestamp] = 0; } $data['other']['misc1'][1][$timestamp] += $salesW[4]; } elseif ($pcode == "42232") { if (!isset($data['other']['misc2'][1][$timestamp])) { $data['other']['misc2'][1][$timestamp] = 0; } $data['other']['misc2'][1][$timestamp] += $salesW[4]; } elseif ($pcode == "63350") { if (!isset($data['other']['misc0'][1][$timestamp])) { $data['other']['misc0'][1][$timestamp] = 0; } $data['other']['misc0'][1][$timestamp] += $salesW[4]; } elseif ($pcode != 0) { if (!isset($data['sales'][$pcode])) { $data['sales'][$pcode] = array(); } if (!isset($data['sales'][$pcode][$timestamp])) { $data['sales'][$pcode][$timestamp] = 0; } $data['sales'][$pcode][$timestamp] += $salesW[4]; } elseif ($salesW[5] == "A") { if (!isset($data['other']['tax'])) { $data['other']['tax'] = array(); } $data['other']['tax'][$timestamp] = $salesW[4]; } $data['other']['gazette'][$timestamp] = 0; $data['other']['foundmoney'][$timestamp] = 0; } $discountP = $sql->prepare("select YEAR(tdate),MONTH(tdate),DAY(tdate),\n memDesc,-sum(total)\n from {$dlog} as d left join is4c_op.memTypeID as m on d.memtype=m.memtypeID\n where upc='DISCOUNT' and tdate between ? AND ?\n group by YEAR(tdate),MONTH(tdate),DAY(tdate),\n memDesc"); $discountR = $sql->execute($discountP, $date_args); $data['other']['discount'] = array(); while ($discountW = $sql->fetch_row($discountR)) { $tstamp = getTS($discountW, 0, 1, 2); $type = $discountW[3]; if ($type == 'Non Member') { $type = 'Staff Member'; } if (!isset($data['other']['discount'][$type])) { $data['other']['discount'][$type] = array(); } if (!isset($data['other']['discount'][$type][$tstamp])) { $data['other']['discount'][$type][$tstamp] = 0; } $data['other']['discount'][$type][$tstamp] += $discountW[4]; } return $data; }
if ($today == getFD($y, $m, $i)) { echo "<td class=\"today\">" . $hao++ . "</td>"; } else { echo "<td class=\"week" . getW($y, $m, $hao) . "\">" . $hao++ . "</td>"; } } echo "</tr>"; ?> <?php for ($i = 2; $i < 7; $i++) { ?> <tr> <?php for ($j = 0; $j < 7; $j++) { if ($hao > getTS($y, $m)) { echo "<td class=\"next\">" . ($hao - getTS($y, $m)) . "</td>"; //echo '<td class="next">'.($hao-getTS($y,$m)).'</td>'; } else { if ($today == getFD($y, $m, $hao)) { echo "<td class=\"today\">" . $hao . "</td>"; } else { echo "<td class=\"week" . $j . "\">" . $hao . "</td>"; } } $hao++; } ?> </tr> <?php } ?>