$bi_ID = $bi_pay_info_month[$curDayStamp]['bi_ID']; $showProfit = $bi_pay_info_month[$curDayStamp]['TotalProfit']; if ($bi_pay_info_month[$curDayStamp]['ProfitMode']) { $showProfit = $bi_pay_info_month[$curDayStamp]['ProfitMode'][$bankInfo['bk_payment_type']]; } $showProfit *= $bk_commission / 100; $content = "<a href='viewBankInvoice.php?bi_ID={$bi_ID}' class='" . $bi_pay_info_month[$curDayStamp]['Status'] . "'>Daily Profit: " . formatMoney($showProfit) . "</a><BR>"; if ($bankInfo['bk_payout_support']) { $content .= "<input name='' type='button' title='" . $bi_pay_info_month[$curDayStamp]['bi_download_count'] . "' value='Payout File (" . $bi_pay_info_month[$curDayStamp]['bi_download_count'] . ")' class='infoSubSection' onClick=\"document.location.href='PayoutGenerate.php?bi_ID={$bi_ID}';this.title++;this.value='Payout File ('+this.title+')';\">"; } $class = 'bk4'; //etelPrint(++$wut2); } else { if ($lastInvoiceDate <= $curDayStamp && $_REQUEST['calc_payout']) { $date_hold = 0; $bi_pay_info_item = calcBankReal($curDayStamp, &$calcInfo); $showEst = true; if ($bi_pay_info_item['pay']) { $estProfit = $bi_pay_info_item['TotalProfit']; $rollOverProfit = 0; $calcInfo['last_date_hold'] = $bi_pay_info_item['date_hold']; $calcInfo['last_date_delay'] = $bi_pay_info_item['date_delay']; if (date("m", $curMonth) == date("m", $curDayStamp)) { $invoiceEstBalance += $bi_pay_info_item['TotalProfit']; } } else { $estProfit = $bi_pay_info_item['TotalProfit']; if ($rollOverProfit == $estProfit) { $showEst = false; } if ($estProfit) {
$bank_details = mysql_query($qry_company, $cnn_cs) or dieLog("Cannot execute query"); $bi_pay_info_item = NULL; $bi_pay_info = NULL; $i = 0; $invoice_options = ""; while ($bankInfo = mysql_fetch_assoc($bank_details)) { $calcInfo = null; $calcInfo['forceCalc'] = true; $calcInfo['last_date_hold'] = date("Y-m-d 00:00:00", $str_from_stamp); $calcInfo['last_date_delay'] = date("Y-m-d 00:00:00", $str_from_stamp); $calcInfo['date_hold'] = date("Y-m-d 00:00:00", $str_to_stamp); $calcInfo['date_delay'] = date("Y-m-d 00:00:00", $str_to_stamp); //$calcInfo['forceProfitView'] = true; $bankInfo['bk_payment_type'] = 'profit'; $calcInfo['estimateMode'] = true; $bi_pay_info_item[$i] = calcBankReal(0, $calcInfo); $bi_pay_info['TotalProfit'] += $bi_pay_info_item[$i]['TotalProfit']; $bi_pay_info['Profit'] += $bi_pay_info_item[$i]['Profit']; $bi_pay_info['Deductions'] += $bi_pay_info_item[$i]['Deductions'] + $bi_pay_info_item[$i]['WireFee']; $bi_pay_info_item[$i]['TotalApproves'] = $bankInfo['TotalApproves']; $bi_pay_info_item[$i]['TotalApprovesNum'] = $bankInfo['TotalApprovesNum']; $bi_pay_info_item[$i]['TotalTransNum'] = $bankInfo['TotalTransNum']; $bi_pay_info['TotalApproves'] += $bankInfo['TotalApproves']; $bi_pay_info['TotalApprovesNum'] += $bankInfo['TotalApprovesNum']; $bi_pay_info['TotalTransNum'] += $bankInfo['TotalTransNum']; $i++; } //$profitMsg .= "<BR>Total Daily Profit: $".formatMoney($bi_pay_info['TotalProfit'])."\n"; // Company Stats $sql = "SELECT \n\t\n\tCOUNT(distinct cd.`userId`) as TotalCompanys,\n\tSUM(date_added {$str_date_range}) as NewCompanys,\n\tGROUP_CONCAT(distinct if(date_added {$str_date_range},userId,NULL) SEPARATOR '|') as NewCompanyList,\n\t\n\tSUM(cd.`cd_completion`=1 AND cd.`transaction_type`='Adult') as AdltApps,\n\t\n\tSUM(`cd_completion`=3) as ReqRates,\n\t\n\tSUM(`cd_completion`=9) as ReqLive,\n\t\n\tSUM(`cd_completion`=3 and gateway_id in (5,6)) as IBillReqRates,\n\n\tSUM(`cd_completion`=9 and gateway_id in (5,6)) as IBillReqLive,\n\n\t\n\tSUM(`activeuser`=1 AND `cd_completion`=10) as Live,\n\t\n\tSUM(`cd_reseller_rates_request`=1 AND `cd_completion`<4) as ResReqRates,\n\t\n\tSUM(`cd_reseller_rates_request`!='0' AND `cd_reseller_rates_request`!='1' AND `cd_completion`<4) as RatesMarkedUp,\n\t\n\tCURDATE() as Date\n\t\n\tFROM `cs_companydetails` as cd \n\tWHERE cd.cd_ignore=0 {$bank_sql_limit} "; //etelPrint($sql);
function updateBankInvoice($time = 0) { global $cnn_cs; global $bankInfo; global $date_hold; global $date_delay; global $includeInvoiceFees; if (!$time) { $time = time(); } $sql = "SELECT * FROM `cs_bank_invoice` WHERE `bi_bank_id` = '" . $bankInfo['bank_id'] . "' AND `bi_date` = curdate()"; $result = mysql_query($sql, $cnn_cs); if (mysql_num_rows($result) >= 1) { $cs_bank_invoice = mysql_fetch_assoc($result); $bi_pay_info = @unserialize($cs_bank_invoice['bi_pay_info']); $bi_pay_info['bi_ID'] = $cs_bank_invoice['bi_ID']; return $bi_pay_info; } $calcInfo['includeInvoiceFees'] = true; $bi_pay_info = calcBankReal($time, $calcInfo); $date_hold = $bi_pay_info['date_hold']; $date_delay = $bi_pay_info['date_delay']; $calcInfo['includeInvoiceFees'] = false; if (!$bi_pay_info['pay']) { return $bi_pay_info; } $bi_pay_info['Status'] = "Paid"; $bi_transactions = $bi_pay_info['TransactionList']; $bi_deductions = $bi_pay_info['DeductionsList']; $bi_mib_ID_list = $bi_pay_info['MInvoiceList']; unset($bi_pay_info['TransactionList']); unset($bi_pay_info['DeductionsList']); unset($bi_pay_info['MInvoiceList']); // Create an Invoice $invoiceName = date("l, F j, Y") . " - " . $bankInfo['bank_name'] . " - \$" . formatMoney($bi_pay_info['TotalProfit']); $invoice_sql = "INSERT INTO `cs_bank_invoice` \r\n\t(`bi_mib_ID_list`, `bi_transactions`,`bi_deductions`,`bi_title`, `bi_bank_id` , `bi_date` , `bi_balance` , `bi_deduction` , `bi_pay_info` , `bi_bank_info`, `bi_notes` )\r\nVALUES (\r\n'{$bi_mib_ID_list}', '{$bi_transactions}','{$bi_deductions}','{$invoiceName}', '" . $bankInfo['bank_id'] . "', '" . date('y-m-d g:i:s', $time) . "' , '" . $bi_pay_info['TotalProfit'] . "', '" . $bi_pay_info['Deductions'] . "', '" . addslashes(serialize($bi_pay_info)) . "', '" . addslashes(serialize($bankInfo)) . "', '{$bi_notes}'\r\n);\r\n"; $result = mysql_query($invoice_sql, $cnn_cs) or dieLog(mysql_error() . " ~ {$invoice_sql}"); $invoice_id = mysql_insert_id($cnn_cs); // Update Transactions $transaction_sql = "UPDATE cs_transactiondetails as t \r\nleft join cs_companydetails as cd on cd.userId = t.userId\r\nleft join cs_transactiondetails as td on td.td_bank_paid = 0\r\nand t.`transactionId` = td.`transactionId` and td.transactionDate < '{$date_hold}'\r\nleft join cs_transactiondetails as tdc ON tdc.td_bank_deducted = 0\r\nand t.`transactionId` = tdc.`transactionId` and tdc.cancellationDate < '{$date_delay}'\r\nset td.td_bank_paid = {$invoice_id}, tdc.td_bank_deducted={$invoice_id}\r\nWHERE t.bank_id='" . $bankInfo['bank_id'] . "'"; // AND cd.`cd_pay_status`='payable' $result = mysql_query($transaction_sql, $cnn_cs) or dieLog(mysql_error() . " ~ {$transaction_sql}"); $sql = "update `cs_merchant_invoice_banksub` as mib \r\n\tset mib_paid={$invoice_id}\r\n\tWHERE mib_paid=0 AND `mib_bank_id` = '" . $bankInfo['bank_id'] . "'"; $result = mysql_query($sql, $cnn_cs) or dieLog(mysql_error() . " ~ {$sql}"); // Update Misc Fees if ($bi_pay_info['mf_ID_list']) { $sql = "update `cs_misc_fees` set mf_paid={$invoice_id} where mf_ID in ('" . $bi_pay_info['mf_ID_list'] . "')"; $result = mysql_query($sql, $cnn_cs) or dieLog(mysql_error($cnn_cs) . " ~ {$sql}"); } $bi_pay_info['bi_ID'] = $invoice_id; return $bi_pay_info; }