예제 #1
0
파일: index.php 프로젝트: phpsmith/IS4C
    foreach ($accounts as $account) {
        echo "<br /><b>Total for {$account}</b>";
        $totalR = $dbc->exec_statement($totalQ, array($account, $span[0], $span[1]));
        $data = array();
        while ($totalW = $dbc->fetch_row($totalR)) {
            if (empty($data["{$totalW['0']}"])) {
                $data["{$totalW['0']}"] = array($totalW[1], $account, $totalW[2]);
            } else {
                $data["{$totalW['0']}"][0] += $totalW[1];
                $data["{$totalW['0']}"][2] += $totalW[2];
            }
        }
        echo tablify($data, array(0, 1, 2, 3), array("pCode", "Retail", "Account", "Wholesale"), array($ALIGN_LEFT, $ALIGN_RIGHT | $TYPE_MONEY, $ALIGN_CENTER, $ALIGN_RIGHT | $TYPE_MONEY), 2, array(1, 3));
    }
    $output = ob_get_contents();
    \COREPOS\Fannie\API\data\DataCache::putFile('monthly', $output);
    ob_end_clean();
}
echo $output;
function tablify($data, $col_order, $col_headers, $formatting, $sums = -1, $sum_cols = array())
{
    $sum = 0;
    $ret = "";
    $ret .= "<table cellspacing=0 cellpadding=4 border=1><tr>";
    $i = 0;
    foreach ($col_headers as $c) {
        while ($formatting[$i] == 0) {
            $i++;
        }
        $ret .= cellify("<u>" . $c . "</u>", $formatting[$i++] & 7);
    }
예제 #2
0
 function get_startDate_endDate_view()
 {
     global $FANNIE_URL, $FANNIE_ROOT;
     $records = \COREPOS\Fannie\API\data\DataCache::getFile('daily');
     if ($records !== False) {
         $records = unserialize($records);
     }
     if (!is_array($records) || FormLib::get('no-cache') == '1') {
         $records = $this->get_data();
         \COREPOS\Fannie\API\data\DataCache::putFile('daily', serialize($records));
     }
     $ret = '';
     $debit = $credit = 0.0;
     if (FormLib::get_form_value('excel', '') === '') {
         $ret .= sprintf('<a href="OverShortMAS.php?startDate=%s&endDate=%s&excel=yes">Download</a>', $this->startDate, $this->endDate);
         $ret .= '<table class="table table-bordered small">';
         foreach ($records as $r) {
             if (preg_match('/\\(\\d+-\\d+-\\d+ \\d+-\\d+-\\d+\\)/', $r[5])) {
                 $tmp = explode(' ', $r[5]);
                 $date = trim($tmp[count($tmp) - 2], '()');
                 $trans = trim($tmp[count($tmp) - 1], '()');
                 $r[5] = sprintf('<a href="%sadmin/LookupReceipt/RenderReceiptPage.php?receipt=%s&date=%s">%s</a>', $FANNIE_URL, $trans, $date, $r[5]);
             }
             $ret .= sprintf('<tr><td>%d</td><td>%s</td><td>%s</td>
                     <td>%.2f</td><td>%.2f</td><td>%s</td></tr>', $r[0], $r[1], $r[2], $r[3], $r[4], $r[5]);
             $debit += $r[3];
             $credit += $r[4];
         }
         $ret .= sprintf('<tr><td colspan="3">Sum</td><td>%.2f</td><td>%.2f</td><td>&nbsp;</td></tr>', $debit, $credit);
         $ret .= '</table>';
     } else {
         foreach ($records as $row) {
             $line = '';
             foreach ($row as $val) {
                 $line .= strstr($val, ',') ? '"' . $val . '"' : $val;
                 $line .= ',';
             }
             $line = substr($line, 0, strlen($line) - 1) . "\r\n";
             $ret .= $line;
         }
     }
     return $ret;
 }
예제 #3
0
 public function run()
 {
     global $FANNIE_OP_DB, $FANNIE_TRANS_DB, $FANNIE_ARCHIVE_DB;
     $sql = FannieDB::get($FANNIE_OP_DB);
     $chk = $sql->query("TRUNCATE TABLE batchMergeTable");
     if ($chk === false) {
         $this->cronMsg("Could not truncate batchMergeTable", FannieLogger::WARNING);
     }
     $chk = $sql->query("INSERT INTO batchMergeTable\n                        SELECT b.startDate,b.endDate,p.upc,p.description,b.batchID\n                        FROM batches AS b LEFT JOIN batchList AS l\n                        ON b.batchID=l.batchID \n                            " . DTrans::joinProducts('l', 'p', 'INNER'));
     if ($chk === false) {
         $this->cronMsg("Could not load batch reporting data for UPCs", FannieLogger::WARNING);
     }
     $chk = $sql->query("INSERT INTO batchMergeTable \n                        SELECT b.startDate, b.endDate, p.upc, p.description, b.batchID\n                        FROM batchList AS l LEFT JOIN batches AS b\n                        ON b.batchID=l.batchID INNER JOIN upcLike AS u\n                        ON l.upc = " . $sql->concat("'LC'", $sql->convert('u.likeCode', 'CHAR'), '') . "\n                        " . DTrans::joinProducts('u', 'p', 'INNER') . "\n                        WHERE p.upc IS NOT NULL");
     if ($chk === false) {
         $this->cronMsg("Could not load batch reporting data for likecodes", FannieLogger::WARNING);
     }
     $sql = FannieDB::get($FANNIE_TRANS_DB);
     $cashierPerformanceSQL = "\n            SELECT\n            min(tdate) as proc_date,\n            max(emp_no) as emp_no,\n            max(trans_num) as Trans_Num,\n            min(tdate) as startTime,\n            max(tdate) as endTime,\n            CASE WHEN " . $sql->seconddiff('min(tdate)', 'max(tdate)') . " =0 \n                then 1 else \n                " . $sql->seconddiff('min(tdate)', 'max(tdate)') . "\n            END as transInterval,\n            sum(CASE WHEN abs(quantity) > 30 THEN 1 else abs(quantity) END) as items,\n            Count(upc) as rings,\n            SUM(case when trans_status = 'V' then 1 ELSE 0 END) AS Cancels,\n            max(card_no) as card_no\n            from dlog_90_view \n            where trans_type IN ('I','D','0','C')\n            group by year(tdate),month(tdate),day(tdate),trans_num";
     if (!$sql->isView('CashPerformDay')) {
         $chk = $sql->query("TRUNCATE TABLE CashPerformDay");
         if ($chk === false) {
             $this->cronMsg("Could not truncate CashPerformDay", FannieLogger::WARNING);
         }
         $chk = $sql->query("INSERT INTO CashPerformDay " . $cashierPerformanceSQL);
         if ($chk === false) {
             $this->cronMsg("Could not load data for CashPerformDay", FannieLogger::WARNING);
         }
     }
     if ($sql->tableExists('CashPerformDay_cache')) {
         $chk = $sql->query("TRUNCATE TABLE CashPerformDay_cache");
         if ($chk === false) {
             $this->cronMsg("Could not truncate CashPerformDay_cache", FannieLogger::WARNING);
         }
         $chk = $sql->query("INSERT INTO CashPerformDay_cache " . $cashierPerformanceSQL);
         if ($chk === false) {
             $this->cronMsg("Could not load data for CashPerformDay_cache", FannieLogger::WARNING);
         }
     }
     $sql = FannieDB::get($FANNIE_ARCHIVE_DB);
     if ($sql->table_exists("reportDataCache")) {
         $sql->query("DELETE FROM reportDataCache WHERE expires < " . $sql->now());
     }
     $daily = \COREPOS\Fannie\API\data\DataCache::fileCacheDir('daily');
     if ($daily) {
         $dh = opendir($daily);
         while (($file = readdir($dh)) !== false) {
             if (is_file($daily . '/' . $file)) {
                 unlink($daily . '/' . $file);
             }
         }
         closedir($dh);
     }
     $monthly = \COREPOS\Fannie\API\data\DataCache::fileCacheDir('monthly');
     if ($monthly && date('j') == 1) {
         $dh = opendir($monthly);
         while (($file = readdir($dh)) !== false) {
             if (is_file($monthly . '/' . $file)) {
                 unlink($monthly . '/' . $file);
             }
         }
         closedir($dh);
     }
 }
예제 #4
0
    function body_content()
    {
        ob_start();
        echo showInstallTabs('Updates');
        ?>

<h1 class="install">
    <?php 
        if (!$this->themed) {
            echo "<h1 class='install'>{$this->header}</h1>";
        }
        ?>
</h1>
<p class="ichunk">Database Updates.</p>
<?php 
        if (FormLib::get_form_value('mupdate') !== '') {
            $updateClass = FormLib::get_form_value('mupdate');
            echo '<div class="well">';
            echo 'Attempting to update model: "' . $updateClass . '"<br />';
            if (!class_exists($updateClass)) {
                echo '<div class="alert alert-danger">Error: class not found</div>';
            } elseif (!is_subclass_of($updateClass, 'BasicModel')) {
                echo '<div class="alert alert-danger">Error: not a valid model</div>';
            } else {
                $updateModel = new $updateClass(null);
                $db_name = $this->normalize_db_name($updateModel->preferredDB());
                if ($db_name === False) {
                    echo '<div class="alert alert-danger">Error: requested database unknown</div>';
                } else {
                    ob_start();
                    $changes = $updateModel->normalize($db_name, BasicModel::NORMALIZE_MODE_APPLY, true);
                    $details = ob_get_clean();
                    if ($changes === False) {
                        echo '<div class="alert alert-danger">An error occured applying the update</div>';
                    } else {
                        echo '<div class="alert alert-success">Update complete</div>';
                    }
                    printf(' <a href="" onclick="$(\'#updateDetails\').toggle();return false;"
                        >Details</a><pre class="collapse" id="updateDetails">%s</pre>', $details);
                }
            }
            echo '</div>';
        }
        $obj = new BasicModel(null);
        $models = FannieAPI::listModules('BasicModel');
        $cmd = new ReflectionClass('BasicModel');
        $cmd = $cmd->getFileName();
        echo '<ul>';
        foreach ($models as $class) {
            $model = new $class(null);
            $db_name = $this->normalize_db_name($model->preferredDB());
            if ($db_name === False) {
                continue;
            }
            ob_start();
            $changes = $model->normalize($db_name, BasicModel::NORMALIZE_MODE_CHECK);
            $details = ob_get_clean();
            if ($changes === False) {
                printf('<li>%s had errors.', $class);
            } elseif ($changes > 0) {
                printf('<li>%s has updates available.', $class);
            } elseif ($changes < 0) {
                printf('<li>%s does not match the schema but cannot be updated.', $class);
            }
            if ($changes > 0) {
                $reflector = new ReflectionClass($class);
                $model_file = $reflector->getFileName();
                printf(' <a href="" onclick="$(\'#mDetails%s\').toggle();return false;"
                    >Details</a><br /><pre class="collapse" id="mDetails%s">%s</pre><br />
                    To apply changes <a href="InstallUpdatesPage.php?mupdate=%s">Click Here</a>
                    or run the following command:<br />
                    <pre>php %s --update %s %s</pre>
                    </li>', $class, $class, $details, $class, $cmd, $db_name, $model_file);
            } else {
                if ($changes < 0 || $changes === False) {
                    printf(' <a href="" onclick="$(\'#mDetails%s\').toggle();return false;"
                    >Details</a><br /><pre class="collapse" id="mDetails%s">%s</pre></li>', $class, $class, $details);
                }
            }
        }
        echo '</ul>';
        ?>
<hr />
<p class="ichunk">CORE Updates.</p>
<em>This is new; consider it alpha-y. Commit any changes before running an update.</em><br />
<?php 
        $version_info = \COREPOS\Fannie\API\data\DataCache::check('CoreReleases');
        if ($version_info === false) {
            ini_set('user_agent', 'CORE-POS');
            $json = file_get_contents('https://api.github.com/repos/CORE-POS/IS4C/tags');
            if ($json === false && function_exists('curl_init')) {
                $ch = curl_init('https://api.github.com/repos/CORE-POS/IS4C/tags');
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURL_TIMEOUT, 10);
                curl_setopt($ch, CURLOPT_USERAGENT, 'CORE-POS');
                $json = curl_exec($ch);
                curl_close($ch);
            }
            if ($json === false) {
                echo '<div class="alert alert-danger">Error downloading release information</div>';
            } else {
                $decoded = json_decode($json, true);
                if ($decoded === null) {
                    echo '<div class="alert alert-danger">Downloaded release information is invalid</div>';
                    var_dump($json);
                } else {
                    $version_info = $json;
                    \COREPOS\Fannie\API\data\DataCache::freshen($version_info, 'day', 'CoreReleases');
                }
            }
        }
        $version_info = json_decode($version_info, true);
        $tags = array();
        foreach ($version_info as $release) {
            $tags[] = $release['name'];
        }
        usort($tags, array('InstallUpdatesPage', 'versionSort'));
        $my_version = trim(file_get_contents(dirname(__FILE__) . '/../../VERSION'));
        if ($tags[count($tags) - 1] == $my_version) {
            echo '<div class="alert alert-success">Up to date</div>';
        } elseif (!in_array($my_version, $tags)) {
            echo '<div class="alert alert-warning">Current version <strong>' . $my_version . '</strong> not recognized</div>';
        } else {
            echo '<div class="alert alert-info">
                Current version: <strong>' . $my_version . '</strong><br />
                Newest version available: <strong>' . $tags[count($tags) - 1] . '</strong>
                </div>';
            echo '<h3>To get the latest version</h3>';
            echo '<i>Make note of the big string of letters and numbers produced
                by the "git log" command. If you want to undo the update, that will be handy</i><br />';
            echo '<p><code>';
            $dir = realpath(dirname(__FILE__) . '/../../');
            echo 'cd "' . $dir . '"<br />';
            echo 'git log -n1 --pretty=oneline<br />';
            echo 'git fetch upstream<br />';
            echo 'git merge ' . $tags[count($tags) - 1] . '<br />';
            echo '</code></p>';
            echo '<h3>Troubleshooting</h3>';
            echo '<p>Error message: <i>fatal: \'upstream\' does not appear to be a repository</i><br />';
            echo 'Solution: add the repository and re-run the update commands above<br />';
            echo '<code>git remote add upstream https://github.com/CORE-POS/IS4C</code>';
            echo '</p>';
            echo '<p>Error message: <i>Automatic merge failed; fix conflicts and then commit the result.</i><br />';
            echo 'Unfortunately this means the update cannot be applied automatically. If you are a developer
                you can of course fix the conflicts. If you just need to undo the update attempt and get back
                to a working state, first try this:<br />
                <code>git reset --merge</code><br />
                If problems persist (or you have an old version of git that doesn\'t support that command) use:<br />
                <code>git reset --hard</code>
                </p>';
            echo '<p>Undoing the update<br />
                If you noted the big string of letters and numbers from "git log", you can go back to that
                exact point. Replace PREVIOUS with the big string.<br />
                <code>git reset --merge PREVIOUS</code><br />
                If not, this should get back to the version you were running before but may not be quite
                identical.<br />
                <code>git reset --merge ' . $my_version . '</code>
                </p>';
        }
        return ob_get_clean();
        // body_content
    }