<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script src="/js/javascript.js"></script> <body> <div id="message"></div> <div class="container_12"> <div id="nav"> <?php showMenu(); ?> <div style="float:right;margin-top:12px; margin-right:15px"><label for="quickSummary">Quick Summary By UPC:</label><input type="number" id="quickSummary" name="quickSummary"><input type="button" value="Go" onClick="window.location.assign('/upcsummary/'+$('#quickSummary').val())"></div> </div> <div id="content"> <?php $wine = new Wine($dbh); $wine->fetchWineByUPC($_GET['upc']); ?> <div id="edit" style="display:none"> <h2>Edit: <span id="editUPC"><?php echo $_GET['upc']; ?> </span></h2> <form id="form" name="form"> <input type="hidden" id="function" name="function" value="updateWine"> <input type="hidden" id="wine_id" name="wine_id" value="<?php echo $wine->getID(); ?> "> <label for="name">UPC/EAN:</label><input type="text" style="width:400px" id="upc" name="upc" value="<?php echo $wine->getUPC(); ?>
function exportCSV($arr, $dbh) { if (isset($arr['reportType']) && $arr['reportType'] == 'summaryByUPC') { $wine = new Wine($dbh); $wine->fetchWineByUPC($arr['upc']); if (isset($arr['toDate']) && $arr['toDate'] != null) { $to = $arr['toDate']; } else { $to = null; } if (isset($arr['fromDate']) && $arr['fromDate'] != null) { $from = $arr['fromDate']; } else { $from = null; } $json = $wine->getInventorySummary($from, $to); //Generate HTML and echo it out; $data = json_decode($json, true); if (!isset($data[0])) { die('No data was found matching your criteria.'); } $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/tmp/summaryByUPC.csv', 'w'); $header = 'UPC,Name,Cost,SellingPrice,Quantity,DateTime,Location'; fwrite($fp, $header); fwrite($fp, PHP_EOL); foreach ($data as $row) { fputcsv($fp, $row); } fclose($fp); header('Location: /tmp/summaryByUPC.csv'); } else { if (isset($arr['reportType']) && $arr['reportType'] == 'completeInventory') { $wine = new Wine($dbh); if (isset($arr['toDate']) && $arr['toDate'] != null) { $to = $arr['toDate']; } else { $to = null; } $args = array('date' => $to); $wines = $wine->fetchAllWines(); $data = json_decode($wines, true); $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/tmp/completeInventory.csv', 'w'); $header = 'UPC,Name,Qty,Cost/Bottle,Total Cost,Selling Price,Cost/Selling Price'; fwrite($fp, $header); fwrite($fp, PHP_EOL); foreach ($data as $row) { $curWine = new Wine($dbh); $curWine->fetchWineByUPC($row['upc']); $args = array('date' => $to); $inv = $curWine->getCurrentInventory($args); //cur is json summary of inventory $row = '' . $curWine->getUPC() . ',' . $curWine->getName() . ',' . $curWine->getCurrentInventory($args) . ',' . number_format($curWine->getCost(), 2, '.', '') . ',' . number_format($curWine->getCurrentInventory($args) * $curWine->getCost(), 2, '.', '') . ',' . number_format($curWine->getSellPrice(), 2, '.', '') . ',' . $curWine->getCost() / $curWine->getSellPrice(); fwrite($fp, $row); fwrite($fp, PHP_EOL); } fclose($fp); header('Location: /tmp/completeInventory.csv'); } else { die('Invalid Report Type'); } } }