Ejemplo n.º 1
0
$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();
?>
"><br>
			<label for="name">Type:</label><select class="select" id="type" name="type">
			<option value="Chardonnay" <?php 
echo strtoupper($wine->getType()) == 'CHARDONNAY' ? 'selected' : '';
?>
>Chardonnay</option>
			<option value="Fume/Sauvignon Blanc" <?php 
echo strtoupper($wine->getType()) == 'FUME/SAUVIGNON BLANC' ? 'selected' : '';
?>
>Fume/Sauvignon Blanc</option>
			<option value="Pinot Grigio" <?php 
echo strtoupper($wine->getType()) == 'PINOT GRIGIO' ? 'selected' : '';
?>
>Pinot Grigio</option>
Ejemplo n.º 2
0
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');
        }
    }
}