function calcOverallError() { global $numPatterns; global $patNum; global $errThisPat; global $RMSerror; $RMSerror = 0.0; for ($i = 0; $i < $numPatterns; $i++) { $patNum = $i; calcNet(); $RMSerror = $RMSerror + $errThisPat * $errThisPat; } $RMSerror = $RMSerror / $numPatterns; $RMSerror = sqrt($RMSerror); }
if ($datejump < 24 * 60 * 60) { $datejump = 24 * 60 * 60 * 7; } if ($startdate > $thisdate) { $balance = 0; } for ($i = 0; $i <= $numOfMonths; $i++) { $rollOverApplied = $rollOverAppliedNext; if ($balance >= $companyInfo['rd_rollover']) { $balance = 0; } else { $rollOverAppliedNext = $balance; } $thismonth = $i % 12 + 1; $thisyear = floor($i / 12); $Net = calcNet($thismonth, $thisyear, $companyInfo); $NetApplied = $Net; $balance += $Net; $finalbalance = $balance; } $startdate = $i; $startdate = $i; $carryoverbalance = $balance; $balance = $finalbalance; $rollover = "No Balance"; if ($balance < $companyInfo['rd_rollover']) { if ($balance != 0) { $rollover = "Rollover"; } $wireFeeApplied = 0; } else {
function projSetCalc() { set_time_limit(30); global $projSettlement; global $projSettlementPeriods; global $monthlyChargebackPerc; global $companyInfo; global $thisdate; global $cnn_cs; global $pSKey; global $pSAllCompanys; $userid_val = intval($companyInfo['userId']); $dateadded_time = strtotime($companyInfo['date_added']); $dateadded = getdate($dateadded_time); $dateadded_time += ($companyInfo['cd_paystartday'] + $companyInfo['cd_paydelay'] - $dateadded['wday'] - 1) * 60 * 60 * 24; if ($companyInfo['cd_payperiod'] < 1) { $companyInfo['cd_payperiod'] = 7; } $datejump = 24 * 60 * 60 * $companyInfo['cd_payperiod']; $fdaysback = $companyInfo['cd_payperiod'] + $companyInfo['cd_paydelay']; $tdaysback = $companyInfo['cd_paydelay']; $chargeEachMonth = $dateadded_time + 24 * 60 * 60 * 30; $startdate = $dateadded_time; // Start Info $weekbasedate = 932832000; $balance = -$companyInfo['cd_appfee']; if ($datejump < 24 * 60 * 60) { $datejump = 24 * 60 * 60 * 7; } if ($startdate > $thisdate) { $balance = 0; } $monthlyChargebackPerc = ""; $matching = 1; if (date_compare(time() + $fdaysback * 24 * 60 * 60, $thisdate, "LE")) { $thisdate = time() + $fdaysback * 24 * 60 * 60; } for ($i = $startdate; date_compare($i, $thisdate, "LE"); $i += $datejump) { // For each Pay Period $Net = ""; $payment_made = false; $curMonthStamp = intval(date("ym", $fdate)); if (!isset($monthlyChargebackPerc[$curMonthStamp])) { $ch_year = intval(date("Y", $fdate)); $ch_month = intval(date("m", $fdate)) + 1; if ($ch_month > 12) { $ch_month = 1; $ch_year++; } $qry_details = "SELECT COUNT(`amount`) as cnt, SUM(`r_chargeback`) as sum FROM `cs_transactiondetails` as t WHERE (`userId` = '{$userid_val}') AND `td_is_chargeback` = '1' AND `cancellationDate` between '" . date("Y-m", $fdate) . "-01 00:00:00' and '{$ch_year}-{$ch_month}-01 00:00:01'"; $rst_details = mysql_query($qry_details, $cnn_cs) or dieLog(mysql_errno() . ": " . mysql_error() . "<BR>Cannot execute query"); $monthlyChargebacks = mysql_fetch_assoc($rst_details); $qry_details = "SELECT COUNT(`amount`) as cnt FROM `cs_transactiondetails` as t WHERE (`userId` = '{$userid_val}') AND `transactionDate` between '" . date("Y-m", $fdate) . "-01 00:00:00' and '{$ch_year}-{$ch_month}-01 00:00:01'"; $rst_details = mysql_query($qry_details, $cnn_cs) or dieLog(mysql_errno() . ": " . mysql_error() . "<BR>Cannot execute query"); $monthlyTotal = mysql_fetch_assoc($rst_details); if ($monthlyTotal['cnt'] <= 0) { $monthlyChargebackPerc[$curMonthStamp]['ch_perc'] = 0; } else { $monthlyChargebackPerc[$curMonthStamp]['ch_perc'] = $monthlyChargebacks['cnt'] / $monthlyTotal['cnt']; } $monthlyChargebackPerc[$curMonthStamp]['ch_pentalty'] = $monthlyChargebacks['sum']; } $fdate = $i - 60 * 60 * 24 * $fdaysback; $tdate = $i - 60 * 60 * 24 * ($tdaysback + 1); $weekid = floor(($i - $weekbasedate) / (7 * 24 * 60 * 60)); $projPayPeriod = ""; $projPayPeriod['br'] = "<br>"; $projPayPeriod['timestamp'] = $i; $projPayPeriod['date'] = date("l, F j, Y", $i); $projPayPeriod['rollover'] = $rollOverAppliedNext; $projPayPeriod['monthlyfee'] = 0; $projPayPeriod['wirefee'] = 0; $projPayPeriod['startdate'] = date("l, F j, Y, ", $fdate); $projPayPeriod['enddate'] = date("l, F j, Y, ", $tdate); $projPayPeriod['balance'] = 0; $projPayPeriod['invoice'] = ""; $projPayPeriod['pay?'] = 0; $projPayPeriod['rollover?'] = 0; $projPayPeriod['ih_inv_ID'] = -1; $projPayPeriod['Net'] = 0; $projPayPeriod['weekid'] = $weekid; $projPayPeriod['matching'] = $matching; $matching++; if ($matching > 4) { $matching = 1; } $rollOverAppliedNext = 0; // Roll over for next round $payment_made = false; $inv_details = ""; $sql = "select * from `cs_invoice_history` where `ih_weekid` = '{$weekid}' AND `userId`='" . $userid_val . "'"; $inv_details = mysql_query($sql, $cnn_cs) or dieLog(" Cannot execute query. {$sql} Error:" . mysql_error()); if ($invoiceInfo = mysql_fetch_assoc($inv_details)) { $payment_made = true; $balance = 0; $rollOverAppliedNext = 0; $projPayPeriod['balance'] = $invoiceInfo['ih_balance']; $projPayPeriod['monthlyfee'] = $invoiceInfo['ih_monthlyfee']; $projPayPeriod['wirefee'] = $invoiceInfo['ih_wirefee']; $projPayPeriod['rollover'] = $invoiceInfo['ih_rollover']; $projPayPeriod['Net'] = $invoiceInfo['ih_net']; $projPayPeriod['timestamp'] = $invoiceInfo['ih_date']; $projPayPeriod['pay?'] = 0; $projPayPeriod['ih_inv_ID'] = $invoiceInfo['ih_inv_ID']; $projPayPeriod['invoice'] = "Payed on " . date("m-d-y", strtotime($invoiceInfo['ih_date_payed'])); if ($projPayPeriod['monthlyfee'] > 0) { $chargeEachMonth = $i + 24 * 60 * 60 * 30; } } if (!$payment_made) { if (date_compare($i, $chargeEachMonth, "GE")) { // If a month has passed, charge monthly fee if ($chargeEachMonth < time()) { $balance -= $companyInfo['cs_monthly_charge']; $projPayPeriod['monthlyfee'] = $companyInfo['cs_monthly_charge']; $chargeEachMonth = $i + 24 * 60 * 60 * 30; } else { $chargeEachMonth = 1.0E+19; } } $Net = calcNet($fdate, $tdate); $projPayPeriod['Net'] = $Net; $balance += $Net; $projPayPeriod['balance'] = $balance; $rollOverAppliedNext = 0; if ($balance >= $companyInfo['cd_rollover'] && $balance > 0) { $projPayPeriod['balance'] = $balance - $companyInfo['cd_wirefee']; $projPayPeriod['wirefee'] = $companyInfo['cd_wirefee']; $balance = 0; $projPayPeriod['invoice'] = "Not Payed"; $projPayPeriod['pay?'] = 1; } else { if ($balance != 0) { $projPayPeriod['invoice'] = "Rollover"; $projPayPeriod['rollover?'] = 1; } else { $projPayPeriod['invoice'] = "No Balance"; } $rollOverAppliedNext = $balance; } } $keyval = intval(date("ymd", $projPayPeriod['timestamp'])); if ($pSKey == 'weekid') { $keyval = $projPayPeriod['weekid']; } if ($pSAllCompanys) { $projPayPeriod['invoice'] = ""; } $projSettlement[$keyval] = $projPayPeriod; $projSettlementPeriods[intval(date("ymd", $fdate))]['txt'] = "Starts ->"; $projSettlementPeriods[intval(date("ymd", $tdate))]['txt'] .= "<- Ends"; $projSettlementPeriods[intval(date("ymd", $fdate))]['matching'] = $matching; } $projSettlementPeriods[intval(date("ymd", $fdate + $datejump))]['txt'] = "Starts ->"; $projSettlementPeriods[intval(date("ymd", $tdate + $datejump))]['txt'] .= "<- Ends"; $projSettlementPeriods[intval(date("ymd", $fdate + $datejump))]['matching'] = $matching; $matching++; if ($matching > 4) { $matching = 1; } $projSettlementPeriods[intval(date("ymd", $fdate + $datejump * 2))]['txt'] = "Starts ->"; $projSettlementPeriods[intval(date("ymd", $tdate + $datejump * 2))]['txt'] .= "<- Ends"; $projSettlementPeriods[intval(date("ymd", $fdate + $datejump * 2))]['matching'] = $matching; $matching++; if ($matching > 4) { $matching = 1; } $projSettlementPeriods[intval(date("ymd", $fdate + $datejump * 3))]['txt'] = "Starts ->"; $projSettlementPeriods[intval(date("ymd", $tdate + $datejump * 3))]['txt'] .= "<- Ends"; $projSettlementPeriods[intval(date("ymd", $fdate + $datejump * 3))]['matching'] = $matching; if ($pSAllCompanys) { $projSettlementPeriods = ""; } return $projSettlement; }