function calculate($max) { if ($max == 1) { return 1; } return lcd($max, calculate($max - 1)); }
function set_variable($v, $e) { global $symbol_table; $symbol_table[$v] = $e; } function get_variable($v) { global $symbol_table; return doubleval($symbol_table[$v]); } function calculate($line) { global $parser; if (!strlen($line)) return; try { $parser->reset(); foreach(tokenize($line) as $t) { if (is_numeric($t)) $parser->eat('num', doubleval($t)); else if (ctype_alpha($t)) $parser->eat('var', $t); else $parser->eat("'$t'", null); } $parser->eat_eof(); } catch (parse_error $e) { echo $e->getMessage(), "\n"; } } $parser = new parse_engine(new calc()); while ($line = fgets(STDIN)) calculate(trim($line));
continue; } foreach ($lpp as $prevoz2) { //s katerimi lppji sploh ujamemo deadline if (strtotime($prevoz2[1] . ':00') >= strtotime($deadLine . ':00')) { continue; } //ali je dovolj velika razlika med alpteourjem in lppjem if (strtotime($prevoz2[0] . ':00') - strtotime($prevoz1[1] . ':00') < $varnostneMinuteNaPrestopu * 60) { continue; } $result = $prevoz1[0] . '->' . $prevoz1[1] . ' ' . $prevoz2[0] . '->' . $prevoz2[1] . "\r\n"; } } echo $result; } //{04:35, 05:05}, {05:10, 05:40}... //global $alpetour = array(); $lpp = array(); $pathAlpetour = 'alpetour.txt'; $pathLpp = 'lpp2.txt'; $voznjaLpp = 12; //lpp time to get from lpp.txt to destination $varnostneMinuteNaPrestopu = 4; // difference between alpetour arival time and lpp take off :) $deadLine = '11:09'; //when you need to be at lpp destination readData($pathAlpetour, $pathLpp, $voznjaLpp); calculate($varnostneMinuteNaPrestopu, $deadLine);
// $value = $_GET["edad"]; //}else{ // $value = $POST["edad"]; //} //$result = calculate($edad); //echo $result; ?> <html> <head> <title></title> </head> <body> <?php $value = ""; if ($_SERVER["REQUEST_METHOD"] == "GET") { $value = $_GET["edad"]; } else { $value = $_POST["edad"]; } $res = calculate($value); if ($res["status"] == true) { echo "Fue exitoso: <br>" . $res["data"] . "</br>"; } else { if ($res["status"] == false) { //fall echo "Fallo:" . $res["data"]; } } ?> </body> </html>
<article style="color:#FFFFFF;"> <p> <!-- <center><img src="logo_big.png"></center> Insert Main Logo here --> <hr/> <center><h1>Bitcoin Tracker</h1></center> <hr/> <p> <?php // Get current information $values = array(); $result = array(); $values = get_bitcoin_data("birdonwheels5"); $result = calculate($values); ?> <div class="box"> <p> Welcome! This tool lets you track bitcoin purchases and spends. </p> </div> <div class="box"> <p> <center><h3>Bitcoin Summary Statistics</h3> <table> <tr> <td>
case "GroupCancelWrit": GroupCancelWrit(); case "selectPossibleTransferWrits": selectPossibleTransferWrits(); case "selectArrearTransferWrits": selectArrearTransferWrits(); case "transferAction": transferAction(); case "ArrearTransferAction": ArrearTransferAction(); case "confirmAction": confirmAction(); case "recalculate": recalculate(); case "calculate": calculate(); case "Prior_Corrective_Writ": Prior_Corrective_Writ(); case "Next_Corrective_Writ": Next_Corrective_Writ(); } function selectPersonWrt() { $query = "DROP TABLE IF EXISTS temp_sum_item_writs2"; PdoDataAccess::runquery($query); $qry = " CREATE TEMPORARY TABLE temp_sum_item_writs2 AS\n select sum(w.value) sumValue ,w.writ_id , w.writ_ver, w.staff_id\n\t\t\t\tfrom writ_salary_items w\n\t\t\t\t\tjoin staff s on(w.staff_id=s.staff_id)\n\t\t\t\t\tjoin persons p on(p.PersonID=? AND s.PersonID=p.PersonID)\n group by writ_id , writ_ver, staff_id"; PdoDataAccess::runquery($qry, array($_GET["Q0"])); //if($_SESSION['UserID'] == 'jafarkhani') { echo PdoDataAccess::GetLatestQueryString(); die() ; } $query = " ALTER TABLE temp_sum_item_writs2 ADD INDEX(writ_id,writ_ver,staff_id) "; PdoDataAccess::runquery($query); $whr = "";
function calculate_possible_polls($users) { mysql_query("TRUNCATE TABLE candidate_poll"); foreach ($users as $reviewee) { foreach ($users as $reviewer) { $reviewer_id = (int) $reviewer['ID']; $reviewee_id = (int) $reviewee['ID']; if ($reviewer_id == $reviewee_id) { } else { if ($reviewer_id == get_team_manager($reviewee_id)) { // Enkel rijen toevegen waarbij de reviewer en reviewee verschillen of waarbij de reviewer niet te teammanager is van de reviewee. } else { mysql_query("INSERT INTO candidate_poll (Reviewer, Reviewee, Score, Ok_reviewee, Ok_reviewer, Ok_overall) VALUES ({$reviewer_id}, {$reviewee_id}, 0, 0, 0, 0)"); } } } } calculate($users); }
function display($_POST) { extract($_POST); $prev_yr_schema = substr(YR_DB, 0, 2) . (substr(YR_DB, 2) - 1); if ($prev_yr_schema < 0) { return "<li class='err'>No prior years found.</li>"; } /* "prior" should be from beginning of month (iow the end of the previous) or if it is the first period the end of period 0 (end of last year) */ global $MONPRD, $PRDMON; $month_from = $PRDMON[$MONPRD[$month_from] - 1]; switch (strtolower($key)) { case "print": case "save": case "export to spreadsheet": $print_func = true; break; default: $print_func = false; break; } // Retrieve the accounts list from Cubit db_conn("cubit"); $sql = "SELECT * FROM saved_cf_accounts"; $cfacc_rslt = db_exec($sql) or errDie("Unable to retrieve accounts list from Cubit."); $i = 0; while ($cfacc_data = pg_fetch_array($cfacc_rslt)) { // Multidimensional array, variable variable ${$cfacc_data["category"]}[] = $cfacc_data["accid"]; } $cat_list = array("nciis" => "Non Cash Item in Income Statement", "ciaal" => "Change in Assets and Liabilities", "cffuif" => "Cash Flows From / Used in Financing", "cffuii" => "Cash Flows From / Used in Investing"); $cat_total = array("ciaal" => "Net cash provided by operating activities", "cffuif" => "Net cash provided by financing activities", "cffuii" => "Net cash used in investing activities"); // Net cash and cash equivalents, beginning of period $cash_equiv_bop = array(); $cash_equiv_bop["curr_total"] = 0; $cash_equiv_bop["prev_total"] = 0; $cash_equiv_bop["var_total"] = 0; $cash_equiv_bop["percvar_total"] = 0; foreach ($cat_list as $key => $value) { if (($key == "cffuif" || $key == "cffuii") && isset(${"acc_{$key}"})) { foreach (${"acc_{$key}"} as $accid) { db_conn("core"); $sql = "SELECT * FROM trial_bal_actual WHERE accid='{$accid}' AND month='{$month_from}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve trial balance data from Cubit."); $py_data = pg_fetch_array($rslt); $sql = "SELECT * FROM trial_bal_actual WHERE accid='{$accid}' AND month='{$month_to}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve trial balance data from Cubit."); $tb_data = pg_fetch_array($rslt); /*if ($prev_yr_schema) { db_conn($prev_yr_schema); $sql = "SELECT * FROM year_balance WHERE accid='$accid'"; $rslt = db_exec($sql) or errDie("Unable to retrieve previous year data from Cubit."); $py_data = pg_fetch_array($rslt); } else { $py_data = array( "debit" => 0, "credit" => 0 ); }*/ db_conn("core"); $sql = "SELECT toptype FROM accounts WHERE accid='{$accid}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve accounts from Cubit."); $toptype = pg_fetch_result($rslt, 0); $cash_equiv_bop["curr_total"] += calculate($toptype, $tb_data["debit"], $tb_data["credit"]); $cash_equiv_bop["prev_total"] += calculate($toptype, $py_data["debit"], $py_data["credit"]); } } } $cash_equiv_bop["var_total"] = $cash_equiv_bop["curr_total"] - $cash_equiv_bop["prev_total"]; if ($cash_equiv_bop["curr_total"] && $cash_equiv_bop["prev_total"]) { $cash_equiv_bop["percvar_total"] = $cash_equiv_bop["curr_total"] / $cash_equiv_bop["prev_total"] * 100; } else { $cash_equiv_bop["percvar_total"] = 0; } // Net cash and cash equivalents, end of period $cash_equiv_eop = array(); $cash_equiv_eop["curr_total"] = 0; $cash_equiv_eop["prev_total"] = 0; $cash_equiv_eop["var_total"] = 0; $cash_equiv_eop["percvar_total"] = 0; foreach ($cat_list as $key => $value) { if (($key == "cffuif" || $key == "cffuii") && isset(${"acc_{$key}"})) { foreach (${"acc_{$key}"} as $accid) { db_conn("core"); $sql = "SELECT * FROM trial_bal_actual WHERE accid='{$accid}' AND month='{$month_from}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve trial balance data from Cubit."); $py_data = pg_fetch_array($rslt); $sql = "SELECT * FROM trial_bal_actual WHERE accid='{$accid}' AND month='{$month_to}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve trial balance data from Cubit."); $tb_data = pg_fetch_array($rslt); /*$py_month = strtolower(getMonthName($month_to)); db_conn($prev_yr_schema); $sql = "SELECT * FROM $py_month WHERE accid='$accid'"; $rslt = db_exec($sql) or errDie("Unable to retrieve previous year data from Cubit."); $py_data = pg_fetch_array($rslt);*/ db_conn("core"); $sql = "SELECT toptype FROM accounts WHERE accid='{$accid}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve accounts from Cubit."); $toptype = pg_fetch_result($rslt, 0); $cash_equiv_eop["curr_total"] += calculate($toptype, $tb_data["debit"], $tb_data["credit"]); $cash_equiv_eop["prev_total"] += calculate($toptype, $py_data["debit"], $py_data["credit"]); } } } $cash_equiv_eop["var_total"] = $cash_equiv_eop["curr_total"] - $cash_equiv_eop["prev_total"]; if ($cash_equiv_eop["curr_total"] && $cash_equiv_eop["prev_total"]) { $cash_equiv_eop["percvar_total"] = $cash_equiv_eop["curr_total"] / $cash_equiv_eop["prev_total"] * 100; } else { $cash_equiv_eop["percvar_total"] = 0; } // Output the headings and accounts $acc_out = ""; if (!pg_num_rows($cfacc_rslt)) { $acc_out .= "<tr class='bg-odd'><td colspan='5'>No accounts selected.</td></tr>"; } $i = 0; foreach ($cat_list as $key => $value) { if (isset(${$key})) { // Category heading $acc_out .= "<tr><th colspan='5' class='cashflow_cats'>{$value}</th></tr>"; foreach (${"acc_{$key}"} as $accid) { // Retrieve the account info from the trial balance db_conn("core"); $sql = "SELECT debit, credit FROM trial_bal WHERE accid='{$accid}' AND month='{$month_from}'"; $tb_rslt = db_exec($sql) or errDie("Unable to retrieve account information from Cubit."); $ptb_data = pg_fetch_array($tb_rslt); $sql = "SELECT debit, credit FROM trial_bal WHERE accid='{$accid}' AND month='{$month_to}'"; $tb_rslt = db_exec($sql) or errDie("Unable to retrieve account information from Cubit."); $tb_data = pg_fetch_array($tb_rslt); // Account information db_conn("core"); $sql = "SELECT * FROM accounts WHERE accid='{$accid}'"; $acc_rslt = db_exec($sql) or errDie("Unable to retrieve account information from Cubit."); $acc_data = pg_fetch_array($acc_rslt); // Retrieve previous year trial balance /*db_conn($prev_yr_schema); $sql = "SELECT * FROM year_balance WHERE accid='$accid'"; $ptb_rslt = db_exec($sql) or errDie("Unable to retrieve previous year account information from Cubit."); $ptb_data = pg_fetch_array($ptb_rslt); // Previous year account information db_conn("core"); $sql = "SELECT * FROM accounts WHERE accid='$accid'"; $pacc_rslt = db_exec($sql) or errDie("Unable to retrieve previous year account information from Cubit."); $pacc_data = pg_fetch_array($pacc_rslt);*/ // Make sure we've got a toptype if (empty($acc_data["toptype"])) { if ($acc_data["acctype"] == "I") { $acc_data["toptype"] = "other_income"; } if ($acc_data["acctype"] == "E") { $acc_data["toptype"] = "expenses"; } } /*if (empty($pacc_data["toptype"])) { if ($pacc_data["acctype"] == "I") $pacc_data["toptype"] = "other_income"; if ($pacc_data["acctype"] == "E") $pacc_data["toptype"] = "expenses"; }*/ // Do the calculations $current = calculate($acc_data["toptype"], $tb_data["debit"], $tb_data["credit"]); $prior = calculate($acc_data["toptype"], $ptb_data["debit"], $ptb_data["credit"]); $variance = $current - $prior; // We don't want a division by zero... if ($current && $prior) { $percvar = $current / $prior * 100; } else { $percvar = "0.00"; } // How should the current category be displayed switch ($key) { case "ciaal": if ($current <= $prior) { $decrease = "(decrease)"; $increase = "Increase"; } else { $decrease = "decrease"; $increase = "(Increase)"; } $acc_out .= "<tr class='bg-even'>\n\t\t\t\t\t\t\t<td>{$increase} {$decrease} in {$acc_data['accname']}</td>\n\t\t\t\t\t\t\t<td align='right'><b>" . sprint($current) . "</b></td>\n\t\t\t\t\t\t\t<td align='right'>" . sprint($prior) . "</td>\n\t\t\t\t\t\t\t<td align='right'>" . sprint($variance) . "</td>\n\t\t\t\t\t\t\t<td align='right'><b>" . sprint($percvar) . "</td>\n\t\t\t\t\t\t</tr>"; break; case "nciis": case "cffuif": case "cffuii": $acc_out .= "<tr class='bg-even'>\n\t\t\t\t\t\t\t<td>{$acc_data['accname']}</td>\n\t\t\t\t\t\t\t<td align='right'><b>" . sprint($current) . "</b></td>\n\t\t\t\t\t\t\t<td align='right'>" . sprint($prior) . "</td>\n\t\t\t\t\t\t\t<td align='right'>" . sprint($variance) . "</td>\n\t\t\t\t\t\t\t<td align='right'><b>" . sprint($percvar) . "</td>\n\t\t\t\t\t\t</tr>"; } // Create the total variables, unless they already exist if (!isset(${$key}["curr_total"])) { ${$key}["curr_total"] = 0.0; } if (!isset(${$key}["prev_total"])) { ${$key}["prev_total"] = 0.0; } if (!isset(${$key}["var_total"])) { ${$key}["var_total"] = 0.0; } if (!isset(${$key}["percvar_total"])) { ${$key}["percvar_total"] = 0.0; } // Assign values to the totals if (isset(${$key})) { ${$key}["curr_total"] += $current; ${$key}["prev_total"] += $prior; ${$key}["var_total"] += $variance; ${$key}["percvar_total"] += $percvar; } } if ($key == "ciaal") { $acc_out .= "<tr class='bg-odd'>\n\t\t\t\t\t<td>Total adjustments</td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["curr_total"]) . "</b></td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["prev_total"]) . "</td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["var_total"]) . "</td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["percvar_total"]) . "</b></td>\n\t\t\t\t</tr>"; } // nciis and ciaal are both in the same category, dont assign a total to both // instead just use nciis if ($key != "nciis") { if (isset($nciis) && isset($ciaal)) { $ciaal["curr_total"] += $nciis["curr_total"]; $ciaal["prev_total"] += $nciis["prev_total"]; $ciaal["var_total"] += $nciis["var_total"]; $ciaal["percvar_total"] += $nciis["percvar_total"]; } // Totals output $acc_out .= "<tr class='bg-odd'>\n\t\t\t\t\t<td>{$cat_total[$key]}</td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["curr_total"]) . "</b></td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["prev_total"]) . "</td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["var_total"]) . "</td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["percvar_total"]) . "</b></td>\n\t\t\t\t</tr>"; } else { // Totals output $acc_out .= "<tr class='bg-odd'>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["curr_total"]) . "</b></td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["prev_total"]) . "</td>\n\t\t\t\t\t<td align='right'>" . sprint(${$key}["var_total"]) . "</td>\n\t\t\t\t\t<td align='right'><b>" . sprint(${$key}["percvar_total"]) . "</b></td>\n\t\t\t\t</tr>"; } } } // Net cash and cash equivalents if (!isset($cffuif)) { $cffuif = array(); $cffuif["curr_total"] = 0.0; $cffuif["prev_total"] = 0.0; $cffuif["var_total"] = 0.0; $cffuif["percvar_total"] = 0.0; } if (!isset($cffuii)) { $cffuii = array(); $cffuii["curr_total"] = 0.0; $cffuii["prev_total"] = 0.0; $cffuii["var_total"] = 0.0; $cffuii["percvar_total"] = 0.0; } $cash_equiv = array(); $cash_equiv["curr_total"] = $cffuif["curr_total"] + $cffuii["curr_total"] + $nciis["curr_total"]; $cash_equiv["prev_total"] = $cffuif["prev_total"] + $cffuii["prev_total"] + $nciis["prev_total"]; $cash_equiv["var_total"] = $cffuif["var_total"] + $cffuii["var_total"] + $nciis["var_total"]; $cash_equiv["percvar_total"] = $cffuif["percvar_total"] + $cffuii["percvar_total"] + $nciis["percvar_total"]; if ($cash_equiv["curr_total"] < $cash_equiv["prev_total"]) { $cash_equiv["inc_dec"] = "(increase) decrease"; } else { $cash_equiv["inc_dec"] = "increase (decrease)"; } // Date range // Retrieve the current year from Cubit db_conn("core"); $sql = "SELECT yrname FROM active"; $rslt = db_exec($sql) or errDie("Unable to retrieve current year from Cubit."); $year_out = substr(pg_fetch_result($rslt, 0), 1); $month_from_out = getMonthName($month_from); $month_to_out = getMonthName($month_to); if ($month_from == $month_to) { $date_range = "{$month_from_out} {$year_out}"; } else { $date_range = "{$month_from_out} TO {$month_to_out} {$year_out}"; } $OUTPUT = ""; if (!$print_func) { $OUTPUT .= "\n\t\t<form method='post' action='" . SELF . "'>\n\t\t<input type='hidden' name='key' value='slct'>\n\t\t<input type='hidden' name='month_from' value='{$month_from}'>\n\t\t<input type='hidden' name='month_to' value='{$month_to}'>"; } $OUTPUT .= "\n\t<table border='0' cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width='100%'>\n\t\t<tr>\n\t\t\t<td><h3>Statement of Cash Flow</h3></td>\n\t\t\t<td align='right'><h3>{$date_range}</h3></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='2' class='err'>\n\t\t\tThe non-cash items have been adjusted to operating profit. The other\n\t\t\tleg must still be debited or credited to an asset/liability account.\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n\t<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n\t\t<tr>\n\t\t\t<th> </td>\n\t\t\t<th width='10%' class='thkborder'>Current</th>\n\t\t\t<th width='10%' class='thkborder'>Prior</th>\n\t\t\t<th width='10%' class='thkborder'>Variance</th>\n\t\t\t<th width='10%' class='thkborder thkborder_right'>%Var</th>\n\t\t</tr>\n\t\t{$acc_out}\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Net cash {$cash_equiv['inc_dec']} in cash and cash equivalents</td>\n\t\t\t<td align='right'><b>" . sprint($cash_equiv["curr_total"]) . "</b></td>\n\t\t\t<td align='right'>" . sprint($cash_equiv["prev_total"]) . "</td>\n\t\t\t<td align='right'>" . sprint($cash_equiv["var_total"]) . "</td>\n\t\t\t<td align='right'><b>" . sprint($cash_equiv["percvar_total"]) . "</b></td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Net cash equivalents beginning of period</td>\n\t\t\t<td align='right'><b>" . sprint($cash_equiv_bop["curr_total"]) . "</b></td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_bop["prev_total"]) . "</td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_bop["var_total"]) . "</td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_bop["percvar_total"]) . "</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Net cash equivalents end of period</td>\n\t\t\t<td align='right'><b>" . sprint($cash_equiv_eop["curr_total"]) . "</b></td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_eop["prev_total"]) . "</td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_eop["var_total"]) . "</td>\n\t\t\t<td align='right'>" . sprint($cash_equiv_eop["percvar_total"]) . "</td>\n\t\t</tr>"; if (!$print_func) { $pf = ""; foreach ($cat_list as $key => $value) { if (!isset(${"acc_{$key}"})) { continue; } foreach (${"acc_{$key}"} as $k => $v) { $pf .= "<input type='hidden' name='acc_{$key}" . "[{$k}]' value='{$v}' />"; } } $OUTPUT .= "\n\t\t{$pf}\n\t\t<tr>\n\t\t\t<td colspan='5' align='center'>\n\t\t\t\t<input type='submit' value='Accounts'>\n\t\t\t\t<input type='submit' name='key' value='Save'>\n\t\t\t\t<input type='submit' name='key' value='Print'>\n\t\t\t\t<input type='submit' name='key' value='Export to Spreadsheet'>\n\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t</form>"; } else { $OUTPUT .= "\n\t\t</table>"; } if ($print_func) { $OUTPUT = clean_html($OUTPUT); switch (strtolower($_POST["key"])) { case "print": require "../tmpl-print.php"; break; case "save": db_conn("core"); $sql = "INSERT INTO save_cashflow (output, div) VALUES ('" . base64_encode($OUTPUT) . "', '" . USER_DIV . "')"; $svincRslt = db_exec($sql) or errDie("Unable to save the balance sheet to Cubit."); return "<li>Cash Flow Statement has been successfully saved to Cubit.</li>"; break; case "export to spreadsheet": require "../xls/temp.xls.php"; Stream("cashflow", $OUTPUT); break; } } else { $OUTPUT .= "\n\t\t<p>\n\t\t<center>\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\t\t\t<tr class='datacell'><td align='center'><a target=_blank href='../core/acc-new2.php'>Add account (New Window)</a></td></tr>\n\t\t\t<tr class='datacell'><td align='center'><a href='index-reports.php'>Financials</a></td></tr>\n\t\t\t<tr class='datacell'><td align='center'><a href='index-reports-stmnt.php'>Current Year Financial Statements</a></td></tr>\n\t\t\t<tr class='datacell'><td align='center'><a href='../main.php'>Main Menu</td></tr>\n\t\t</table>\n\t\t</center>"; } return $OUTPUT; }
function AnotherCalculate($arr, $int) { return calculate($arr, $int); }
/** * profitloss method * * @return void */ public function profitloss() { $this->set('title_for_layout', __d('webzash', 'Trading and Profit & Loss Statement')); $this->set('subtitle', ''); /* POST */ if ($this->request->is('post')) { if ($this->request->data['Profitloss']['opening'] == 1) { return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'profitloss', 'options' => 1, 'opening' => 1)); } else { if (!empty($this->request->data['Profitloss']['startdate']) || !empty($this->request->data['Profitloss']['enddate'])) { return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'profitloss', 'options' => 1, 'opening' => 0, 'startdate' => $this->request->data['Profitloss']['startdate'], 'enddate' => $this->request->data['Profitloss']['enddate'])); } else { return $this->redirect(array('plugin' => 'webzash', 'controller' => 'reports', 'action' => 'profitloss')); } } } $only_opening = false; $startdate = null; $enddate = null; if (empty($this->passedArgs['options'])) { $this->set('options', false); /* Sub-title*/ $this->set('subtitle', __d('webzash', 'Closing Trading and Profit & Loss Statement as on ') . dateFromSql(Configure::read('Account.enddate'))); } else { $this->set('options', true); if (!empty($this->passedArgs['opening'])) { $only_opening = true; $this->request->data['Profitloss']['opening'] = '1'; /* Sub-title*/ $this->set('subtitle', __d('webzash', 'Opening Trading and Profit & Loss Statement as on ') . dateFromSql(Configure::read('Account.startdate'))); } else { if (!empty($this->passedArgs['startdate'])) { $startdate = dateToSQL($this->passedArgs['startdate']); $this->request->data['Profitloss']['startdate'] = $this->passedArgs['startdate']; } if (!empty($this->passedArgs['enddate'])) { $enddate = dateToSQL($this->passedArgs['enddate']); $this->request->data['Profitloss']['enddate'] = $this->passedArgs['enddate']; } /* Sub-title*/ if (!empty($this->passedArgs['startdate']) && !empty($this->passedArgs['enddate'])) { $this->set('subtitle', __d('webzash', 'Trading and Profit & Loss Statement from ' . dateFromSql(dateToSQL($this->passedArgs['startdate'])) . ' to ' . dateFromSql(dateToSQL($this->passedArgs['enddate'])))); } else { if (!empty($this->passedArgs['startdate'])) { $this->set('subtitle', __d('webzash', 'Trading and Profit & Loss Statement from ' . dateFromSql(dateToSQL($this->passedArgs['startdate'])) . ' to ' . dateFromSql(Configure::read('Account.enddate')))); } else { if (!empty($this->passedArgs['enddate'])) { $this->set('subtitle', __d('webzash', 'Trading and Profit & Loss Statement from ' . dateFromSql(Configure::read('Account.startdate')) . ' to ' . dateFromSql(dateToSQL($this->passedArgs['enddate'])))); } } } } } /**********************************************************************/ /*********************** GROSS CALCULATIONS ***************************/ /**********************************************************************/ /* Gross P/L : Expenses */ $gross_expenses = new AccountList(); $gross_expenses->Group =& $this->Group; $gross_expenses->Ledger =& $this->Ledger; $gross_expenses->only_opening = $only_opening; $gross_expenses->start_date = $startdate; $gross_expenses->end_date = $enddate; $gross_expenses->affects_gross = 1; $gross_expenses->start(4); $pandl['gross_expenses'] = $gross_expenses; $pandl['gross_expense_total'] = 0; if ($gross_expenses->cl_total_dc == 'D') { $pandl['gross_expense_total'] = $gross_expenses->cl_total; } else { $pandl['gross_expense_total'] = calculate($gross_expenses->cl_total, 0, 'n'); } /* Gross P/L : Incomes */ $gross_incomes = new AccountList(); $gross_incomes->Group =& $this->Group; $gross_incomes->Ledger =& $this->Ledger; $gross_incomes->only_opening = $only_opening; $gross_incomes->start_date = $startdate; $gross_incomes->end_date = $enddate; $gross_incomes->affects_gross = 1; $gross_incomes->start(3); $pandl['gross_incomes'] = $gross_incomes; $pandl['gross_income_total'] = 0; if ($gross_incomes->cl_total_dc == 'C') { $pandl['gross_income_total'] = $gross_incomes->cl_total; } else { $pandl['gross_income_total'] = calculate($gross_incomes->cl_total, 0, 'n'); } /* Calculating Gross P/L */ $pandl['gross_pl'] = calculate($pandl['gross_income_total'], $pandl['gross_expense_total'], '-'); /**********************************************************************/ /************************* NET CALCULATIONS ***************************/ /**********************************************************************/ /* Net P/L : Expenses */ $net_expenses = new AccountList(); $net_expenses->Group =& $this->Group; $net_expenses->Ledger =& $this->Ledger; $net_expenses->only_opening = $only_opening; $net_expenses->start_date = $startdate; $net_expenses->end_date = $enddate; $net_expenses->affects_gross = 0; $net_expenses->start(4); $pandl['net_expenses'] = $net_expenses; $pandl['net_expense_total'] = 0; if ($net_expenses->cl_total_dc == 'D') { $pandl['net_expense_total'] = $net_expenses->cl_total; } else { $pandl['net_expense_total'] = calculate($net_expenses->cl_total, 0, 'n'); } /* Net P/L : Incomes */ $net_incomes = new AccountList(); $net_incomes->Group =& $this->Group; $net_incomes->Ledger =& $this->Ledger; $net_incomes->only_opening = $only_opening; $net_incomes->start_date = $startdate; $net_incomes->end_date = $enddate; $net_incomes->affects_gross = 0; $net_incomes->start(3); $pandl['net_incomes'] = $net_incomes; $pandl['net_income_total'] = 0; if ($net_incomes->cl_total_dc == 'C') { $pandl['net_income_total'] = $net_incomes->cl_total; } else { $pandl['net_income_total'] = calculate($net_incomes->cl_total, 0, 'n'); } /* Calculating Net P/L */ $pandl['net_pl'] = calculate($pandl['net_income_total'], $pandl['net_expense_total'], '-'); $pandl['net_pl'] = calculate($pandl['net_pl'], $pandl['gross_pl'], '+'); $this->set('pandl', $pandl); /* Download report */ if (isset($this->passedArgs['downloadcsv'])) { Configure::write('Account.currency_format', 'none'); $this->layout = false; $view = new View($this, false); $response = $view->render('Reports/downloadcsv/profitloss'); $this->response->body($response); $this->response->type('text/csv'); $this->response->download('profitloss.csv'); return $this->response; } /* Download report */ if (isset($this->passedArgs['downloadxls'])) { Configure::write('Account.currency_format', 'none'); $this->layout = 'xls'; $view = new View($this, false); $response = $view->render('Reports/downloadxls/profitloss'); $this->response->body($response); $this->response->type('application/vnd.ms-excel'); $this->response->download('profitloss.xls'); return $this->response; } /* Print report */ if (isset($this->passedArgs['print'])) { $this->layout = 'print'; $view = new View($this, false); $response = $view->render('Reports/print/profitloss'); $this->response->body($response); return $this->response; } return; }
# # # # # # # # # get settings require "settings.php"; require "libs/ext.lib.php"; require "core-settings.php"; if (isset($_POST['key'])) { switch ($_POST["key"]) { case "calc": $OUTPUT = calculate(); break; default: $OUTPUT = confirm(); } } else { $OUTPUT = confirm(); } # get template require "template.php"; # confirm function confirm() { db_conn('cubit'); $Sl = "SELECT * FROM monthcloses WHERE type='Interest' ORDER BY id DESC LIMIT 1"; $Rx = db_exec($Sl) or errDie("Unable to get monthclose from db.");
</select> <input type="number" name="number2" class="form-control" value="<?php echo $_POST["number2"]; ?> "> <input type="submit" value="Apreiķināt" class="btn btn-primary" name="submit"> </form> </p> <?php $number1 = $_POST["number1"]; $number2 = $_POST["number2"]; $action = $_POST["action"]; if ($_POST["submit"]) { try { $result = calculate($number1, $number2, $action); echo '<div class="alert alert-info" role="alert">' . $number1 . ' ' . $action . ' ' . $number2 . ' = ' . $result . ' </div>'; } catch (Exception $e) { echo '<div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div>'; } } function calculate($number1, $number2, $action) { if ($number1 && $number2 && $action) { if (is_numeric($number1) && is_numeric($number2)) { switch ($action) { case '+': return $number1 + $number2; break; case '-': return $number1 - $number2;
$total = 0; for ($i = 0; $i < 5; $i++) { $make = 0.75 * 1.32 * 10 - 10; $total += $make; } return $total; } function calculate4() { $total = 0; for ($i = 0; $i < 5; $i++) { $make = 0.9 * 1.1 * 10 - 10; $total += $make; } return $total; } function calculate5() { $total = 0; for ($i = 0; $i < 5; $i++) { $make = 0.95 * 1.0421 * 10 - 10; $total += $make; } return $total; } echo "For 0.25% chance, you made " . calculate() . " doge. </br>"; echo "For 0.25% chance, you made " . calculate1() . " doge.</br>"; echo "For 0.25% chance, you made " . calculate2() . " doge.</br>"; echo "For 0.25% chance, you made " . calculate3() . " doge.</br>"; echo "For 0.25% chance, you made " . calculate4() . " doge.</br>"; echo "For 0.25% chance, you made " . calculate5() . " doge.</br>";
function printChapter($chapter_title, $page_number) { $dots = str_repeat(".", calculate($chapter_title, $page_number)); print $chapter_title . $dots . $page_number . "<br>"; }
/** * Calculate closing balance of specified ledger account for the given * date range * * @param1 int ledger id * @param2 date start date * @param3 date end date * @return array D/C, Amount */ function closingBalance($id, $start_date = null, $end_date = null) { if (empty($id)) { throw new InternalErrorException(__d('webzash', 'Ledger not specified. Failed to calculate closing balance.')); } /* Load models that are needed for calculations */ $Entry = ClassRegistry::init('Webzash.Entry'); $Entryitem = ClassRegistry::init('Webzash.Entryitem'); /* Opening balance */ $op = $this->find('first', array('conditions' => array('Ledger.id' => $id))); if (!$op) { throw new InternalErrorException(__d('webzash', 'Ledger not found. Failed to calculate closing balance.')); } $op_total = 0; $op_total_dc = $op['Ledger']['op_balance_dc']; if (is_null($start_date)) { if (empty($op['Ledger']['op_balance'])) { $op_total = 0; } else { $op_total = $op['Ledger']['op_balance']; } } $dr_total = 0; $cr_total = 0; $dr_total_dc = 0; $cr_total_dc = 0; /* Debit total */ $dr_conditions = array('Entryitem.ledger_id' => $id, 'Entryitem.dc' => 'D'); if (!is_null($start_date)) { $dr_conditions['Entry.date >='] = $start_date; } if (!is_null($end_date)) { $dr_conditions['Entry.date <='] = $end_date; } $total = $Entryitem->find('first', array('fields' => array('SUM(Entryitem.amount) as total'), 'conditions' => $dr_conditions, 'joins' => array(array('table' => 'entries', 'alias' => 'Entry', 'type' => 'LEFT', 'conditions' => array('Entry.id = Entryitem.entry_id'))))); if (empty($total[0]['total'])) { $dr_total = 0; } else { $dr_total = $total[0]['total']; } /* Credit total */ $cr_conditions = array('Entryitem.ledger_id' => $id, 'Entryitem.dc' => 'C'); if (!is_null($start_date)) { $cr_conditions['Entry.date >='] = $start_date; } if (!is_null($end_date)) { $cr_conditions['Entry.date <='] = $end_date; } $total = $Entryitem->find('first', array('fields' => array('SUM(Entryitem.amount) as total'), 'conditions' => $cr_conditions, 'joins' => array(array('table' => 'entries', 'alias' => 'Entry', 'type' => 'LEFT', 'conditions' => array('Entry.id = Entryitem.entry_id'))))); if (empty($total[0]['total'])) { $cr_total = 0; } else { $cr_total = $total[0]['total']; } /* Add opening balance */ if ($op_total_dc == 'D') { $dr_total_dc = calculate($op_total, $dr_total, '+'); $cr_total_dc = $cr_total; } else { $dr_total_dc = $dr_total; $cr_total_dc = calculate($op_total, $cr_total, '+'); } /* Calculate and update closing balance */ $cl = 0; $cl_dc = ''; if (calculate($dr_total_dc, $cr_total_dc, '>')) { $cl = calculate($dr_total_dc, $cr_total_dc, '-'); $cl_dc = 'D'; } else { if (calculate($cr_total_dc, $dr_total_dc, '==')) { $cl = 0; $cl_dc = $op_total_dc; } else { $cl = calculate($cr_total_dc, $dr_total_dc, '-'); $cl_dc = 'C'; } } return array('dc' => $cl_dc, 'amount' => $cl, 'dr_total' => $dr_total, 'cr_total' => $cr_total); }
<?php /* Faça um Programa que peça 2 números inteiros e um número real. Calcule e mostre: 1. o produto do dobro do primeiro com metade do segundo . 2. a soma do triplo do primeiro com o terceiro. 3. o terceiro elevado ao cubo. */ function calculate($a, $b, $c) { $a = (int) $a; $b = (int) $b; $first = $a * 2 * ($b * 0.5); $second = $a * 3 + $c; $third = pow($c, 3); echo "1. {$first}\n2. {$second}\n3. {$third}\n"; } calculate(13.9, 4, 94.90000000000001);
<?php require_once 'ab-testing-calculator.php'; calculate(15, 2, 15, 6);
$sha_diff = number_format($diff[0], 2, '.', ''); $scrypt_diff = number_format($diff[1], 2, '.', ''); $skein_diff = number_format($diff[2], 2, '.', ''); $groestl_diff = number_format($diff[3], 2, '.', ''); $qubit_diff = number_format($diff[4], 2, '.', ''); $results = calculate(); } if ($_POST["week"]) { $average_string = "(1 week average)"; $diff = get_avg_diffs(168); $sha_diff = number_format($diff[0], 2, '.', ''); $scrypt_diff = number_format($diff[1], 2, '.', ''); $skein_diff = number_format($diff[2], 2, '.', ''); $groestl_diff = number_format($diff[3], 2, '.', ''); $qubit_diff = number_format($diff[4], 2, '.', ''); $results = calculate(); } } function calculate() { global $sha_diff, $scrypt_diff, $skein_diff, $groestl_diff, $qubit_diff, $sha_hashrate, $scrypt_hashrate, $skein_hashrate, $groestl_hashrate, $qubit_hashrate, $sha_power, $scrypt_power, $skein_power, $groestl_power, $qubit_power, $sha_hardware, $scrypt_hardware, $skein_hardware, $groestl_hardware, $qubit_hardware, $sha_poolfee, $scrypt_poolfee, $skein_poolfee, $groestl_poolfee, $qubit_poolfee, $power_cost, $myr_price, $btc_price, $coins_per_block; $hash_multiplier = 1000000; // Gives you hashrate in hashes/sec for calculations // Put the values into percents before we do our calculations $sha_fee = $sha_poolfee / 100; $scrypt_fee = $scrypt_poolfee / 100; $skein_fee = $skein_poolfee / 100; $groestl_fee = $groestl_poolfee / 100; $qubit_fee = $qubit_poolfee / 100; $array_package = array(); // What the values are, in order:
/** * edit method * * @param string $entrytypeLabel * @param string $id * @return void */ public function edit($entrytypeLabel = null, $id = null) { /* Check for valid entry type */ if (!$entrytypeLabel) { $this->Session->setFlash(__d('webzash', 'Entry type not specified.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } $entrytype = $this->Entrytype->find('first', array('conditions' => array('Entrytype.label' => $entrytypeLabel))); if (!$entrytype) { $this->Session->setFlash(__d('webzash', 'Entry type not found.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } $this->set('entrytype', $entrytype); $this->set('title_for_layout', __d('webzash', 'Edit %s Entry', $entrytype['Entrytype']['name'])); $this->set('tag_options', $this->Tag->listAll()); /* Ledger selection */ $ledgers = new LedgerTree(); $ledgers->Group =& $this->Group; $ledgers->Ledger =& $this->Ledger; $ledgers->current_id = -1; $ledgers->restriction_bankcash = $entrytype['Entrytype']['restriction_bankcash']; $ledgers->build(0); $ledgers->toList($ledgers, -1); $ledgers_disabled = array(); foreach ($ledgers->ledgerList as $row => $data) { if ($row < 0) { $ledgers_disabled[] = $row; } } $this->set('ledger_options', $ledgers->ledgerList); $this->set('ledgers_disabled', $ledgers_disabled); /* Check for valid entry id */ if (empty($id)) { $this->Session->setFlash(__d('webzash', 'Entry not specified.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } $entry = $this->Entry->findById($id); if (!$entry) { $this->Session->setFlash(__d('webzash', 'Entry not found.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } /* Initial data */ if ($this->request->is('post') || $this->request->is('put')) { $curEntryitems = array(); foreach ($this->request->data['Entryitem'] as $row => $entryitem) { $curEntryitems[$row] = array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'dr_amount' => isset($entryitem['dr_amount']) ? $entryitem['dr_amount'] : '', 'cr_amount' => isset($entryitem['cr_amount']) ? $entryitem['cr_amount'] : ''); } $this->set('curEntryitems', $curEntryitems); } else { $curEntryitems = array(); $curEntryitemsData = $this->Entryitem->find('all', array('conditions' => array('Entryitem.entry_id' => $id))); foreach ($curEntryitemsData as $row => $data) { if ($data['Entryitem']['dc'] == 'D') { $curEntryitems[$row] = array('dc' => $data['Entryitem']['dc'], 'ledger_id' => $data['Entryitem']['ledger_id'], 'dr_amount' => $data['Entryitem']['amount'], 'cr_amount' => ''); } else { $curEntryitems[$row] = array('dc' => $data['Entryitem']['dc'], 'ledger_id' => $data['Entryitem']['ledger_id'], 'dr_amount' => '', 'cr_amount' => $data['Entryitem']['amount']); } } $curEntryitems[] = array('dc' => 'D'); $curEntryitems[] = array('dc' => 'D'); $curEntryitems[] = array('dc' => 'D'); $this->set('curEntryitems', $curEntryitems); } /* On POST */ if ($this->request->is('post') || $this->request->is('put')) { if (!empty($this->request->data)) { /* Check if acccount is locked */ if (Configure::read('Account.locked') == 1) { $this->Session->setFlash(__d('webzash', 'Sorry, no changes are possible since the account is locked.'), 'danger'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } /***************************************************************************/ /*********************************** ENTRY *********************************/ /***************************************************************************/ $entrydata = null; /* Entry id */ unset($this->request->data['Entry']['id']); $this->Entry->id = $id; $entrydata['Entry']['id'] = $id; /***** Entry number ******/ $entrydata['Entry']['number'] = $this->request->data['Entry']['number']; /****** Entrytype remains the same *****/ $entrydata['Entry']['entrytype_id'] = $entrytype['Entrytype']['id']; /****** Check tag ******/ if (empty($this->request->data['Entry']['tag_id'])) { $entrydata['Entry']['tag_id'] = null; } else { $entrydata['Entry']['tag_id'] = $this->request->data['Entry']['tag_id']; } /***** Narration *****/ $entrydata['Entry']['narration'] = $this->request->data['Entry']['narration']; /***** Date *****/ $entrydata['Entry']['date'] = dateToSql($this->request->data['Entry']['date']); /***************************************************************************/ /***************************** ENTRY ITEMS *********************************/ /***************************************************************************/ /* Check ledger restriction */ $dc_valid = false; foreach ($this->request->data['Entryitem'] as $row => $entryitem) { if ($entryitem['ledger_id'] <= 0) { continue; } $ledger = $this->Ledger->findById($entryitem['ledger_id']); if (!$ledger) { $this->Session->setFlash(__d('webzash', 'Invalid ledger selected.'), 'danger'); return; } if ($entrytype['Entrytype']['restriction_bankcash'] == 4) { if ($ledger['Ledger']['type'] != 1) { $this->Session->setFlash(__d('webzash', 'Only bank or cash ledgers are allowed for this entry type.'), 'danger'); return; } } if ($entrytype['Entrytype']['restriction_bankcash'] == 5) { if ($ledger['Ledger']['type'] == 1) { $this->Session->setFlash(__d('webzash', 'Bank or cash ledgers are not allowed for this entry type.'), 'danger'); return; } } if ($entryitem['dc'] == 'D') { if ($entrytype['Entrytype']['restriction_bankcash'] == 2) { if ($ledger['Ledger']['type'] == 1) { $dc_valid = true; } } } else { if ($entryitem['dc'] == 'C') { if ($entrytype['Entrytype']['restriction_bankcash'] == 3) { if ($ledger['Ledger']['type'] == 1) { $dc_valid = true; } } } } } if ($entrytype['Entrytype']['restriction_bankcash'] == 2) { if (!$dc_valid) { $this->Session->setFlash(__d('webzash', 'Atleast one bank or cash ledger has to be on debit side for this entry type.'), 'danger'); return; } } if ($entrytype['Entrytype']['restriction_bankcash'] == 3) { if (!$dc_valid) { $this->Session->setFlash(__d('webzash', 'Atleast one bank or cash ledger has to be on credit side for this entry type.'), 'danger'); return; } } $dr_total = 0; $cr_total = 0; /* Check equality of debit and credit total */ foreach ($this->request->data['Entryitem'] as $row => $entryitem) { if ($entryitem['ledger_id'] <= 0) { continue; } if ($entryitem['dc'] == 'D') { if ($entryitem['dr_amount'] <= 0) { $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Amount cannot be negative or zero.'), 'danger'); return; } if (countDecimal($entryitem['dr_amount']) > Configure::read('Account.decimal_places')) { $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Maximum %s decimal places allowed.', Configure::read('Account.decimal_places')), 'danger'); return; } $dr_total = calculate($dr_total, $entryitem['dr_amount'], '+'); } else { if ($entryitem['dc'] == 'C') { if ($entryitem['cr_amount'] <= 0) { $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Amount cannot be negative or zero.'), 'danger'); return; } if (countDecimal($entryitem['cr_amount']) > Configure::read('Account.decimal_places')) { $this->Session->setFlash(__d('webzash', 'Invalid amount specified. Maximum %s decimal places allowed.', Configure::read('Account.decimal_places')), 'danger'); return; } $cr_total = calculate($cr_total, $entryitem['cr_amount'], '+'); } else { $this->Session->setFlash(__d('webzash', 'Invalid Dr/Cr option selected.'), 'danger'); return; } } } if (calculate($dr_total, $cr_total, '!=')) { $this->Session->setFlash(__d('webzash', 'Debit and Credit total do not match.'), 'danger'); return; } $entrydata['Entry']['dr_total'] = $dr_total; $entrydata['Entry']['cr_total'] = $cr_total; /* Add item to entryitemdata array if everything is ok */ $entryitemdata = array(); foreach ($this->request->data['Entryitem'] as $row => $entryitem) { if ($entryitem['ledger_id'] <= 0) { continue; } if ($entryitem['dc'] == 'D') { $entryitemdata[] = array('Entryitem' => array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'amount' => $entryitem['dr_amount'])); } else { $entryitemdata[] = array('Entryitem' => array('dc' => $entryitem['dc'], 'ledger_id' => $entryitem['ledger_id'], 'amount' => $entryitem['cr_amount'])); } } /* Save entry */ $ds = $this->Entry->getDataSource(); $ds->begin(); if ($this->Entry->save($entrydata)) { /* Delete all original entryitems */ if (!$this->Entryitem->deleteAll(array('Entryitem.entry_id' => $id))) { $ds->rollback(); $this->Session->setFlash(__d('webzash', 'Previous entry items could not be deleted.'), 'danger'); return; } /* Save new entry items */ foreach ($entryitemdata as $id => $itemdata) { $itemdata['Entryitem']['entry_id'] = $this->Entry->id; $this->Entryitem->create(); if (!$this->Entryitem->save($itemdata)) { foreach ($this->Entryitem->validationErrors as $field => $msg) { $errmsg = $msg[0]; break; } $ds->rollback(); $this->Session->setFlash(__d('webzash', 'Failed to save entry ledgers. Error is : %s', $errmsg), 'danger'); return; } } $tempentry = $this->Entry->read(null, $this->Entry->id); if (!$tempentry) { $this->Session->setFlash(__d('webzash', 'Oh snap ! Failed to update entry. Please, try again.'), 'danger'); $ds->rollback(); return; } $entryNumber = h(toEntryNumber($tempentry['Entry']['number'], $entrytype['Entrytype']['id'])); $this->Log->add('Edited ' . $entrytype['Entrytype']['name'] . ' entry numbered ' . $entryNumber, 1); $ds->commit(); $this->Session->setFlash(__d('webzash', '%s entry numbered "%s" updated.', $entrytype['Entrytype']['name'], $entryNumber), 'success'); return $this->redirect(array('plugin' => 'webzash', 'controller' => 'entries', 'action' => 'index')); } else { $ds->rollback(); $this->Session->setFlash(__d('webzash', 'Failed to update entry. Please, try again.'), 'danger'); return; } } else { $this->Session->setFlash(__d('webzash', 'No data. Please, try again.'), 'danger'); return; } } else { $entry['Entry']['date'] = dateFromSql($entry['Entry']['date']); $this->request->data = $entry; return; } }
<?php // Disclaimer: Gebaut mit wenig bis keinem Wissen über PHP :-D include_once "../ressourcen/lib.php"; echo load_header("Berechnung der Abschlussnote", "Für PO 2010 Master Informatik, TU Dresden"); $module = array("bas1" => array(12, "", "Basismodul 1"), "bas2" => array(12, "", "Basismodul 2"), "bas3" => array(12, "", "Basismodul 3"), "vert" => array(15, "", "Vertiefungsmodul"), "profil" => array(12, "", "Profilmodul 2"), "praktikum" => array(12, "", "Vertieftes Master-Praktikum"), "aqua" => array(6, "", "Allgemeine Qualifikation"), "master" => array(60, "", "Master-Arbeit und Verteidigung")); calculate($_GET, $module); show_table_head(); show_modules($module); ?> <tr> <td>Profilmodul 1</td> <td><i>Keine Note.<br> Muss aber bestanden sein.</i></td> </tr> <?php echo load_footer();
$this->stack = array(); } public function push($item) { array_unshift($this->stack, $item); } public function pop() { return array_shift($this->stack); } public function top() { return current($this->stack); } public function is_empty() { return empty($this->stack); } public function show_all() { for ($i = 0; $i < count($this->stack); $i++) { echo $this->stack[$i] . ' '; } } } $current_expression = $_POST['expression']; calculate($current_expression); ?> </body> </html>
Credit limit: </td> <td> <input type="number" name="credit_limit" value="<?php echo filter_input(INPUT_POST, 'credit_limit'); ?> "/> </td> </tr> <tr> <td> New balance: </td> <td> <input type="number" name="new_balance" style="background-color: #e6e6e6" readonly value="<?php echo calculate(filter_input(INPUT_POST, 'starting_balance'), filter_input(INPUT_POST, 'total_credits'), filter_input(INPUT_POST, 'total_charges')); ?> "/> </td> </tr> <tr> <td colspan="2"> <input type="text" name="remainging_credit" size="38" style="background-color: #e6e6e6" readonly value="<?php echo balance_check(filter_input(INPUT_POST, 'credit_limit')); ?> "/> </td> </tr> <tr> <td> <button type="reset">Clear Field</button>
$tajuk = "Parameter Function"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP | <?php echo $tajuk; ?> </title> </head> <body> <?php function greeting($message) { echo $message; } greeting("Hello how are you?"); ?> <?php function calculate($number1, $number2) { $sum = $number1 * $number2; echo $sum; } calculate(122, 222); ?> </body> </html>
for ($i = 0; $i < count($arr); $i++) { if ($i == 0 || $i == 1) { continue; } $number /= $arr[$i]; } } return $number; } echo calculate('+', 5, 5, 3); echo '<br>'; echo calculate('-', 5, 5, 3); echo '<br>'; echo calculate('*', 5, 5, 3); echo '<br>'; echo calculate('/', 5, 5, 3); /* ------------------- Home 4 ---------------------- */ echo '<p>-------- Fourth exercise -------</p>'; function multiplicationTable($a, $b) { if (!is_int($a) || !is_int($b)) { echo 'ERROR. Вы ввели не корректные данные!'; return; } echo '<table border="1" style="border: 1px solid cadetblue; border-collapse: collapse">'; for ($i = 1; $i <= $a; $i++) { echo '<tr>'; for ($j = 1; $j <= $b; $j++) { echo '<td>' . $i * $j . '</td>'; } echo '</tr>';
function init() { say_Something(); echo "<br>"; calculate(); }
function toCurrency($dc, $amount) { $decimal_places = Configure::read('Account.decimal_places'); if (calculate($amount, 0, '==')) { return curreny_format(number_format(0, $decimal_places, '.', '')); } if ($dc == 'D') { if (calculate($amount, 0, '>')) { return 'Dr ' . curreny_format(number_format($amount, $decimal_places, '.', '')); } else { return 'Cr ' . curreny_format(number_format(calculate($amount, 0, 'n'), $decimal_places, '.', '')); } } else { if ($dc == 'C') { if (calculate($amount, 0, '>')) { return 'Cr ' . curreny_format(number_format($amount, $decimal_places, '.', '')); } else { return 'Dr ' . curreny_format(number_format(calculate($amount, 0, 'n'), $decimal_places, '.', '')); } } else { if ($dc == 'X') { /* Dr for positive and Cr for negative value */ if (calculate($amount, 0, '>')) { return 'Dr ' . curreny_format(number_format($amount, $decimal_places, '.', '')); } else { return 'Cr ' . curreny_format(number_format(calculate($amount, 0, 'n'), $decimal_places, '.', '')); } } else { return curreny_format(number_format($amount, $decimal_places, '.', '')); } } } return __d('webzash', 'ERROR'); }
} if ($base != $olduser[0]["base"]) { calculate($userid, $_SESSION["currentYear"], $style, $area, $username, $base); //重新计算热费 $database->insert("gr_log", ["userid" => $userid, "username" => $username, "address" => $address, "style" => "变更基本热费", "old" => $olduser[0]["base"], "new" => $base, "opid" => $_SESSION["opid"], "change_date" => date("Y-m-d")]); } $userstyle = $_POST["userStyle"]; if ($userstyle != $olduser[0]["userstyle"]) { $database->insert("gr_log", ["userid" => $userid, "username" => $username, "address" => $address, "style" => "变更用热状态", "old" => $olduser[0]["userstyle"], "new" => $userstyle, "opid" => $_SESSION["opid"], "change_date" => date("Y-m-d")]); } $manager = $_POST["manager"]; if ($manager != $olduser[0]["manager"]) { $database->insert("gr_log", ["userid" => $userid, "username" => $username, "address" => $address, "style" => "变更管理员", "old" => $olduser[0]["manager"], "new" => $manager, "opid" => $_SESSION["opid"], "change_date" => date("Y-m-d")]); } if ($area != $olduser[0]["area"]) { calculate($userid, $_SESSION["currentYear"], $style, $area, $username, $base); //重新计算热费 //记录日志 $database->insert("gr_log", ["userid" => $userid, "username" => $username, "address" => $address, "style" => "变更面积", "old" => $olduser[0]["area"], "new" => $area, "opid" => $_SESSION["opid"], "change_date" => date("Y-m-d")]); } $memo = $_POST["memo"]; if ($memo != $olduser[0]["memo"]) { $database->insert("gr_log", ["userid" => $userid, "username" => $username, "address" => $address, "style" => "变更备注", "old" => $olduser[0]["memo"], "new" => $memo, "opid" => $_SESSION["opid"], "change_date" => date("Y-m-d")]); } //update userinfo $database->update("gr_user", ["username" => $username, "addr" => $address, "contact" => $phone, "style" => $style, "userstyle" => $userstyle, "manager" => $manager, "area" => $area, "base" => $base, "memo" => $memo], ["userid" => $userid]); header("location: Controller.php?action=listAllUsers"); } if ("jianmian" === $action) { $userid = $_GET["userID"]; $year = $_GET["year"];
function analyze($expr, $side) { $e = exp_to_array($expr); $operators = array('+', '-', '*', '/'); $result = 0; for ($i = 0; $i < count($e); $i++) { if (in_array($e[$i], $operators)) { $num1 = array_pop($GLOBALS[$side]); $num2 = array_pop($GLOBALS[$side]); if (is_variable($num1) and is_variable($num2)) { $result = calculate($num1, $num2, $e[$i]); array_push($GLOBALS[$side], $result . "x"); } elseif (is_numeric($num1) and is_numeric($num2)) { $result = calculate($num1, $num2, $e[$i]); array_push($GLOBALS[$side], $result); } } else { array_push($GLOBALS[$side], $e[$i]); } } return $GLOBALS[$side]; }
global $symbol_table; return doubleval($symbol_table[$v]); } function calculate($line) { global $parser; if (!strlen($line)) { return; } try { $parser->reset(); foreach (tokenize($line) as $t) { if (is_numeric($t)) { $parser->eat('num', doubleval($t)); } else { if (ctype_alpha($t)) { $parser->eat('var', $t); } else { $parser->eat("'{$t}'", null); } } } $parser->eat_eof(); } catch (parse_error $e) { echo $e->getMessage(), "\n"; } } $parser = new parse_engine(new calc()); while ($line = fgets(STDIN)) { calculate(trim($line)); }
if ($function == "times") { echo 'selected="selected"'; } ?> >times</option> <option value="minus" <?php if ($function == "minus") { echo 'selected="selected"'; } ?> >minus</option> <option value="divide" <?php if ($function == "divide") { echo 'selected="selected"'; } ?> >divide</option> </select> <input type="text" id="number2" name="number2" value="<?php echo $number2; ?> " /> <input type="submit" id="calculate" value="Calculate"/> </form> Answer : <span id="answer"><?php echo calculate($number1, $function, $number2); ?> </span> </body> </html> <!-- php and bing powered -->