Esempio n. 1
0
 public function testWriterMonad()
 {
     $ret = runWriter(ret(1)->bind(function ($_) {
         return ret(2);
     })->bind(function ($a) {
         return tell("a")->bind(function ($_) use($a) {
             return ret($a + 5);
         });
     }));
     $this->assertEquals([7, "a"], $ret);
 }
Esempio n. 2
0
<?php

// Проверяем что нормально работает возвращаемое значение
def('ret', function () {
    return 100;
});
echo ret();
?>
---
100
function bal_sheet($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    if ($balset == 'l') {
        $baldb = $yrdb;
    } elseif ($balset == 't') {
        $baldb = "core";
    }
    # get prd name
    db_conn($yrdb);
    $sql = "SELECT * FROM info WHERE prddb ='{$prd}'";
    $prdRslt = db_exec($sql);
    $prds = pg_fetch_array($prdRslt);
    $prdname = $prds['prdname'];
    # check if can connect to prev period
    $sql = "SELECT accid FROM {$prdname} WHERE div = '" . USER_DIV . "'";
    $Rslt = @db_exec($sql) or ret("<li class=err>Unable to retrieve data from Cubit. Period <b>{$prdname}</b> was not properly close on previous year.", SELF);
    # Get Owners Equity Sub Headings
    $oesubRslt = get($baldb, "*", "bal_sheet", "type", "OESUB");
    $sheet = "<center>\n        <h3> Balance Sheet for {$prdname} on previous year {$yrname}</h3>\n        <table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='70%'>\n        <tr><th colspan=3>Owners Equity</th></tr>";
    # get accounts
    $oebal = 0;
    // OE Balance
    while ($oesub = pg_fetch_array($oesubRslt)) {
        $sheet .= "<tr class='bg-even'><td colspan=3><b>{$oesub['value']}<b></td></tr>";
        db_conn($baldb);
        $sql = "SELECT * FROM bal_sheet WHERE type ='OEACC' AND ref = {$oesub['ref']} AND div = '" . USER_DIV . "'";
        $accRslt = db_exec($sql) or errDie("Unable to retrieve balance sheet settings from the Database.", SELF);
        # get privious balances
        db_conn($yrdb);
        while ($acc = pg_fetch_array($accRslt)) {
            $query = "SELECT * FROM {$prdname} WHERE accid = '{$acc['value']}' AND div = '" . USER_DIV . "'";
            $balRslt = db_exec($query) or errDie("Unable to retrieve Account Balances from the Database.", SELF);
            $accbal = pg_fetch_array($balRslt);
            $balance = $accbal['credit'] - $accbal['debit'];
            $oebal += $balance;
            $sheet .= "<tr class='bg-odd'><td><blockquote><li>{$accbal['accname']}</td><td>" . CUR . " {$balance}</td><td><br></td></tr>";
        }
    }
    # print Net Income and OE Balance on last column
    $netincome = getNetIncome($yrdb, $prdname);
    $oebal += $netincome;
    $sheet .= "<tr class='bg-odd'><td>&nbsp<b>Net Income</b></td><td>" . CUR . " {$netincome}</td><td><br></td></tr>";
    $sheet .= "<tr class='bg-even'><td colspan=2><b>Total</b></td><td><b>" . CUR . " {$oebal}</b></td></tr>";
    # Get Assets Sub Headings
    $abal = 0;
    // Assets Balance
    $asssubRslt = get($baldb, "*", "bal_sheet", "type", "ASSSUB");
    $sheet .= "<tr><th colspan=3>Assets</th></tr>";
    # get accounts
    while ($asssub = pg_fetch_array($asssubRslt)) {
        $sheet .= "<tr class='bg-even'><td colspan=3><b>{$asssub['value']}<b></td></tr>";
        db_conn($baldb);
        $sql = "SELECT * FROM bal_sheet WHERE type ='ASSACC' AND ref = {$asssub['ref']} AND div = '" . USER_DIV . "'";
        $accRslt = db_exec($sql) or errDie("Unable to retrieve balance sheet settings from the Database.", SELF);
        # get previous account Balances
        db_conn($yrdb);
        while ($acc = pg_fetch_array($accRslt)) {
            $query = "SELECT * FROM {$prdname} WHERE accid = '{$acc['value']}' AND div = '" . USER_DIV . "'";
            $balRslt = db_exec($query) or errDie("Unable to retrieve Account Balances from the Database.", SELF);
            $accbal = pg_fetch_array($balRslt);
            $balance = $accbal['debit'] - $accbal['credit'];
            // calc Balance
            $abal += $balance;
            $sheet .= "<tr class='bg-odd'><td><blockquote><li>{$accbal['accname']}</td><td>" . CUR . " {$balance}</td><td><br></td></tr>";
        }
    }
    # print assets balance on last column
    $sheet .= "<tr class='bg-even'><td colspan=2><b>Total</b></td><td><b>" . CUR . " {$abal}</b></td></tr>\n        </table>\n\t\t<p>\n\t\t<form>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $sheet;
}
Esempio n. 4
0
    print json_encode($data, 128);
    exit;
}
# fill in all the data recieved by POST
$encode = json_encode($data, 128);
if (strlen($encode) > 20 * 1000) {
    # this is way too much data, guys
    die("Caught! This is not real data");
}
# create jobdir
if (!file_exists($web['dir'])) {
    mkdir($web['dir']);
} else {
    ret(array('msg' => 'Jobdir exists', 'jobdir' => $web['dir']));
}
file_put_contents($web['json'], $encode);
# run the creation in background
$descriptorspec = array(array('pipe', 'r'), array('file', $web['log'], 'a'), array('pipe', $web['log'], 'a'));
# this proc_open forks and immediately returns
$abs_jobdir = escapeshellarg(realpath($web['dir']));
$proc = proc_open("python ../job_interface/run-job.py --job_directory {$abs_jobdir} &", $descriptorspec, $pipes);
ret($pub);
/*
$computers = array('bishop', 'iceman', 'jubilee', 'storm', 'wolverine', 'xavier');
$rkey = array_rand($computers); # does not need to be super-duper
$computer = $computers[$rkey];
$pwd = dirname(__FILE__);
echo "Running on $computer\n";
$cmd = "ssh $computer '$pwd/libreoffice-driver/run.py $jobid'";
echo `$cmd 2>&1; echo $?`;
*/
function printacc($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # get prd name
    db_conn($yrdb);
    $sql = "SELECT * FROM info WHERE prddb ='{$prd}'";
    $prdRslt = db_exec($sql);
    $prds = pg_fetch_array($prdRslt);
    $prdname = $prds['prdname'];
    // Set up table to display in
    $OUTPUT = "\n        <center>\n        <h3>Trial Balance for {$prdname} in previous year : {$yrname}</h3>\n\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=450>\n        <tr><th>Account Number</th><th>Account Name</th><th>Debit</th><th>Credit</th></tr>";
    // Connect to database
    db_conn($yrdb);
    $sql = "SELECT * FROM {$prdname} WHERE div = '" . USER_DIV . "' ORDER BY topacc, accnum ASC";
    $accRslt = @db_exec($sql) or ret("<li class=err>Unable to retrieve data from Cubit. Period <b>{$prdname}</b> was not properly close on previous year.", SELF);
    $numrows = pg_numrows($accRslt);
    if ($numrows < 1) {
        $OUTPUT = "There are no Accounts yet in Cubit.";
        require "../template.php";
    }
    # display all Accounts
    $i = 0;
    $tldebit = 0;
    $tlcredit = 0;
    if ($zero == "no") {
        while ($acc = pg_fetch_array($accRslt)) {
            $i++;
            if (floatval($acc['debit']) == 0 && floatval($acc['credit']) == 0) {
                $i++;
                continue;
            }
            $OUTPUT .= "<tr class='" . bg_class() . "'><td>{$acc['topacc']}/{$acc['accnum']}</td><td>{$acc['accname']}</td>";
            if (floatval($acc['debit']) == 0) {
                $OUTPUT .= "<td align=center> - </td>";
            } else {
                $OUTPUT .= "<td align=center>" . CUR . " {$acc['debit']}</td>";
            }
            if (floatval($acc['credit']) == 0) {
                $OUTPUT .= "<td align=center> - </td>";
            } else {
                $OUTPUT .= "<td align=center>" . CUR . " {$acc['credit']}</td>";
            }
            $OUTPUT .= "</tr>";
            $tldebit += $acc['debit'];
            $tlcredit += $acc['credit'];
        }
    } elseif ($zero == "yes") {
        while ($acc = pg_fetch_array($accRslt)) {
            $i++;
            $OUTPUT .= "<tr class='" . bg_class() . "'><td>{$acc['topacc']}/{$acc['accnum']}</td><td>{$acc['accname']}</td>";
            if (floatval($acc['debit']) == 0) {
                $OUTPUT .= "<td align=center> - </td>";
            } else {
                $OUTPUT .= "<td align=center>" . CUR . " {$acc['debit']}</td>";
            }
            if (floatval($acc['credit']) == 0) {
                $OUTPUT .= "<td align=center> - </td>";
            } else {
                $OUTPUT .= "<td align=center>" . CUR . " {$acc['credit']}</td>";
            }
            $OUTPUT .= "</tr>";
            $tldebit += $acc['debit'];
            $tlcredit += $acc['credit'];
        }
    }
    $OUTPUT .= "<tr class='" . bg_class() . "'><td colspan=2><b>Total</b></td><td align=center><b>" . CUR . " {$tldebit}</b></td><td align=center><b>" . CUR . " {$tlcredit}</b></td></tr>\n        </table>\n\t\t<p>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t\t\t<tr><th>Quick Links</th></tr>\n                        <script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $OUTPUT;
}
function inc($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # get prd name
    db_conn($yrdb);
    $sql = "SELECT * FROM info WHERE prddb ='{$prd}'";
    $prdRslt = db_exec($sql);
    $prds = pg_fetch_array($prdRslt);
    $prdname = $prds['prdname'];
    # check if can connect to prev period
    $sql = "SELECT accid FROM {$prdname} WHERE div = '" . USER_DIV . "'";
    $Rslt = @db_exec($sql) or ret("<li class=err>Unable to retrieve data from Cubit. Period <b>{$prdname}</b> was not properly close on previous year.", SELF);
    # connect to core DB
    core_connect();
    # get the income statement settings
    $sql = "SELECT accid FROM accounts WHERE acctype = 'I' AND div = '" . USER_DIV . "'";
    $incRslt = db_exec($sql) or errDie("Unable to retrieve income statement settings from the Database", SELF);
    if (pg_numrows($incRslt) < 1) {
        return "<center>There are no accounts under income on the income statement Settings table.<br>Please Set the Income Statement";
    }
    // Connect to previous year DB
    db_conn($yrdb);
    // Set up the Table to display in
    $income = "<center><h3>Income Statement for {$prdname} in previous year : {$yrname}</h3>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=75%>\n        <tr><th width=70%>Account Name</th><th>Amount</th></tr>\n        <tr><td colspan=3><h3>Income</h3></td></tr>";
    # get account Balances
    $tlinc = 0;
    // total income credit
    $i = 0;
    while ($inc = pg_fetch_array($incRslt)) {
        # get the balances (debit nad credit) from trial Balance
        $sql = "SELECT * FROM {$prdname} WHERE accid = '{$inc['accid']}' AND div = '" . USER_DIV . "'";
        $balRslt = db_exec($sql) or errDie("Unable to retrieve Account Balance information from the Database.", SELF);
        $bal = pg_fetch_array($balRslt);
        $total = $bal['credit'] - $bal['debit'];
        if ($zero == "no") {
            if (intval($total == 0)) {
                $i++;
                continue;
            }
        }
        $tlinc += $total;
        $income .= "<tr class='" . bg_class() . "'><td>{$bal['accname']}</td><td align=center>" . CUR . " {$total}</td></tr>";
        $i++;
    }
    # write totals for income
    $income .= "<tr class='bg-odd'><td><b>Total<b></td><td align=center><b>" . CUR . " {$tlinc}</b></td></tr>";
    # connect to core DB
    core_connect();
    # get the income statement settings
    $sql = "SELECT accid FROM accounts WHERE acctype='E' AND div = '" . USER_DIV . "'";
    $expRslt = db_exec($sql) or errDie("Unable to retrieve income statement Settings from the Database", SELF);
    if (pg_numrows($expRslt) < 1) {
        return "<center>There are no accounts under Expenditures on the income statement Settings table.<br>Please Set the Income Statement";
    }
    $income .= "<tr><td colspan=3><h3>Expenditure</h3></td></tr>";
    // Connect to previous year DB
    db_conn($yrdb);
    # get account Balances for Expenditure
    $tlexp = 0;
    // total expenditures
    $i = 0;
    while ($exp = pg_fetch_array($expRslt)) {
        # get the balances (debit nad credit) from trial Balance
        $sql = "SELECT * FROM {$prdname} WHERE accid = '{$exp['accid']}' AND div = '" . USER_DIV . "'";
        $balRslt = db_exec($sql) or errDie("Unable to retrieve Account Balance information from the Database.", SELF);
        $bal = pg_fetch_array($balRslt);
        $total = $bal['debit'] - $bal['credit'];
        if ($zero == "no") {
            if (intval($total == 0)) {
                $i++;
                continue;
            }
        }
        $tlexp += $total;
        // And increment the balance for expenditure
        $income .= "<tr class='" . bg_class() . "'><td>{$bal['accname']}</td><td align=center>" . CUR . " {$total}</td></tr>";
        $i++;
    }
    $income .= "<tr class='bg-odd'><td><b>Total<b></td><td align=center><b>" . CUR . " {$tlexp}</b></td></tr>\n                    <tr><td colspan=3><br></td></tr>";
    # Calculate Profit/Loss
    $income .= "<tr class='bg-even'><td><b>Nett Profit Carried Forward<b></td><td align=center colspan=2><b>" . CUR . " " . ($tlinc - $tlexp) . "</b></td></tr>\n\t\t<tr><td><br></td></tr>\n\t\t<form></table>\n\t\t<p>\n\t\t</table>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=20%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t\t</table>";
    return $income;
}
function viewtrans($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # get prd name
    db_conn($yrdb);
    $sql = "SELECT * FROM info WHERE prddb ='{$prd}'";
    $prdRslt = db_exec($sql);
    $prds = pg_fetch_array($prdRslt);
    $prdname = $prds['prdname'];
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($yrdb, "string", 1, 5, "Invalid previous year database.");
    $v->isOk($yrname, "string", 1, 255, "Invalid previous year name.");
    # Search by date
    if ($search == "date") {
        $v->isOk($fday, "num", 1, 2, "Invalid from Date day.");
        $v->isOk($fmon, "num", 1, 2, "Invalid from Date month.");
        $v->isOk($fyear, "num", 1, 4, "Invalid from Date Year.");
        $v->isOk($today, "num", 1, 2, "Invalid to Date day.");
        $v->isOk($tomon, "num", 1, 2, "Invalid to Date month.");
        $v->isOk($toyear, "num", 1, 4, "Invalid to Date Year.");
        # mix dates
        $fromdate = $fday . "-" . $fmon . "-" . $fyear;
        $todate = $today . "-" . $tomon . "-" . $toyear;
        if (!checkdate($fmon, $fday, $fyear)) {
            $v->isOk($fromdate, "num", 1, 1, "Invalid from date.");
        }
        if (!checkdate($tomon, $today, $toyear)) {
            $v->isOk($todate, "num", 1, 1, "Invalid to date.");
        }
        # create the Search SQL
        $search = "SELECT * FROM {$prdname} WHERE date >= '{$fromdate}' AND date <= '{$todate}' AND div = '" . USER_DIV . "' ORDER BY refnum ASC";
    }
    # Search by refnum
    if ($search == "refnum") {
        $v->isOk($fromnum, "num", 1, 20, "Invalid 'from' ref  number.");
        $v->isOk($tonum, "num", 1, 20, "Invalid 'to' ref  number.");
        # create the Search SQL
        $search = "SELECT * FROM {$prdname} WHERE refnum >= {$fromnum} AND refnum <= {$tonum} AND div = '" . USER_DIV . "' ORDER BY refnum ASC";
    }
    # view all
    if ($search == "all") {
        # create the Search SQL
        $search = "SELECT * FROM {$prdname} WHERE div = '" . USER_DIV . "' ORDER BY refnum ASC";
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class=err>" . $e["msg"];
        }
        $confirm .= "<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $confirm;
    }
    # connect to audit DB
    db_conn($yrname . "_audit");
    // Set up table to display in
    $OUTPUT = "<center>\n\t\t<h3>Journal Entries for {$prdname} in previous year : {$yrname}</h3>\n\t\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='80%'>\n        <tr><th>Date</th><th>Debit</th><th>Credit</th><th>Reference No</th><th>Amount</th><th>Details</th><th>Authorised By</th></tr>";
    $tranRslt = @db_exec($search) or ret("<li class=err>Unable to retrieve data from Cubit. Period <b>{$prdname}</b> was not properly close on previous year.", SELF);
    if (pg_numrows($tranRslt) < 1) {
        return "<li> There are no Transactions in the selected Period.<br><br>\n                <table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n        \t<tr><th>Quick Links</th></tr>\n\t        <script>document.write(getQuicklinkSpecial());</script>\n                </table>";
    }
    # display all transaction
    while ($tran = pg_fetch_array($tranRslt)) {
        #get vars from tran as the are in db
        foreach ($tran as $key => $value) {
            ${$key} = $value;
        }
        # format date
        $date = explode("-", $date);
        $date = $date[2] . "-" . $date[1] . "-" . $date[0];
        // get account names
        $deb = get("core", "accname, topacc, accnum", "accounts", "accid", $debit);
        $debacc = pg_fetch_array($deb);
        $ct = get("core", "accname, topacc,accnum", "accounts", "accid", $credit);
        $ctacc = pg_fetch_array($ct);
        $OUTPUT .= "<tr class='bg-odd'><td>{$date}</td><td>{$debacc['topacc']}/{$debacc['accnum']}&nbsp;&nbsp;&nbsp;{$debacc['accname']}</td><td>{$ctacc['topacc']}/{$ctacc['accnum']}&nbsp;&nbsp;&nbsp;{$ctacc['accname']}</td><td>{$refnum}</td><td>" . CUR . " {$amount}</td><td>{$details}</td><td>{$author}</td></tr>";
    }
    $OUTPUT .= "</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=25%>\n\t<tr><td>\n\t<br>\n\t</td></tr>\n\t<tr><th>Quick Links</th></tr>\n\t\t<script>document.write(getQuicklinkSpecial());</script>\n\t</table>";
    return $OUTPUT;
}
Esempio n. 8
0
    $sqlday = "select user_max from  userinfo ;";
    $result = $db->query($sqlday);
    $row = $result->fetch_array();
    $usermaxday = $row[0];
    $sql = "select start_time ,end_time from stateinfo where book_id={$id}";
    $result = $db->query($sql);
    $row = $result->fetch_array();
    $start = strtotime($row[0]);
    $end = strtotime($row[1]);
    $day = ($end - $start) / (24 * 3600);
    if ($day > $usermaxday + 20) {
        echo 0;
        return;
    }
    $time = $end + 10 * 24 * 3600;
    $finaltime = date('Y-m-d', $time);
    $sql = "update stateinfo set  end_time='{$finaltime}' where book_id={$id} ";
    $db->query($sql);
    echo 1;
}
$action = $_POST['action'];
$id = $_POST['book_id'];
$userid = $_POST['userid'];
$db = new mysqli("localhost", "root", "qwedd80", "library");
if ($action == "borrow") {
    borrow($id, $userid, $db);
} elseif ($action == "return") {
    ret($id, $db);
} elseif ($action == "next") {
    nextday($id, $userid, $db);
}
Esempio n. 9
0
<?php

define('CID', false);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::i_am_admin()) {
    die("Access forbidden");
}
function ret($val)
{
    print $val;
    exit;
}
try {
    $patches = PatchUtil::apply_new();
} catch (ErrorException $e) {
    ret($e->getMessage());
}
ModuleManager::create_common_cache();
Base_ThemeCommon::themeup();
Base_LangCommon::update_translations();
foreach ($patches as $patch) {
    if ($patch->get_apply_status() !== Patch::STATUS_SUCCESS) {
        ret(0);
    }
}
ret(1);