// resellerLedger.php: The admin page functions for viewing the company transactions as a summary. include 'includes/sessioncheck.php'; $headerInclude = "reports"; $periodhead = "Ledgers"; $display_stat_wait = true; include 'includes/header.php'; require_once '../includes/function.php'; require_once '../includes/projSetCalc.php'; include '../includes/function1.php'; $str_adminapproval = ""; $sessionlogin = isset($HTTP_SESSION_VARS["sessionReseller"]) ? $HTTP_SESSION_VARS["sessionReseller"] : ""; $qry_company = "select * from cs_resellerdetails where reseller_id ='{$sessionlogin}'"; $gatewayid = -1; $rst_details = mysql_query($qry_company, $cnn_cs) or dieLog("Cannot execute query"); $companyInfo = mysql_fetch_assoc($rst_details); $proj_ri_pay_info = calcResellerReal(); $str_month_from = isset($_GET["cbo_from_month"]) ? trim($_GET["cbo_from_month"]) : ""; $str_year_from = isset($_GET["cbo_from_year"]) ? trim($_GET["cbo_from_year"]) : ""; if ($str_month_from == "") { $str_day_from = date("j"); $str_month_from = date("m"); $str_year_from = date("Y"); } if ($gatewayid == -1) { ?> <script language="JavaScript"> function func_submitfuture(futureyear,futuremonth,futureday){ obj_form = document.FrmMerchant; obj_form.method="post"; obj_form.action="viewfuturedetails.php?futyear="+futureyear+"&futmonth="+futuremonth+"&futday="+futureday; obj_form.submit();
$companyInfo = mysql_fetch_assoc($rst_details); $paydate = strtotime($companyInfo['rd_next_pay_day']); if ($_REQUEST['custom_pay_day']) { $paydate = strtotime($_REQUEST['custom_pay_day']); } if ($_POST['Submit'] == 'Pay Company') { $date_hold = 0; $ri_notes = $_POST['ri_notes']; $paid = payReseller($paydate); if ($paid != -1) { $msg = "Reseller Paid Successfully"; } else { $msg = "Error paying Reseller!"; } } $ri_pay_info = calcResellerReal($paydate); ?> <style type="text/css"> <!-- .style1 {font-size: 10px} .style4 {font-size: 12px; font-weight: bold; } .style5 { color: #FFFFFF; } .style7 { font-size: 12px; color: #CC3300; font-weight: bold; } --> </style>
function payReseller($thisdate = 0) { global $cnn_cs; global $companyInfo; global $ri_notes; $nextPayDayTime = strtotime(resellerPushBackOnePeriod()); if (!$thisdate) { $thisdate = $nextPayDayTime; } $date_hold = date("Y-m-d g:i:s", $thisdate - $fdate); $date_delay = date("Y-m-d g:i:s", $thisdate - 60); $nextPayDay = date('Y-m-', $nextPayDayTime) . $companyInfo['rd_paydelay']; $ri_pay_info = calcResellerReal(strtotime($nextPayDay)); $ri_pay_info['Status'] = "Paid"; if (!$ri_pay_info['pay']) { return -1; } // Create an Invoice $invoiceName = $companyInfo['reseller_companyname'] . " - " . date("l, F j, Y") . " - \$" . formatMoney($ri_pay_info['Balance']); $invoice_sql = "INSERT INTO `cs_reseller_invoice` \r\n\t(`ri_title`, `ri_reseller_id` , `ri_date` , `ri_balance` , `ri_deduction` , `ri_pay_info` , `ri_company_info`, `ri_notes` )\r\nVALUES (\r\n'{$invoiceName}', '" . $companyInfo['reseller_id'] . "', NOW( ) , '" . $ri_pay_info['Balance'] . "', '" . $ri_pay_info['TotalDeductions'] . "', '" . addslashes(serialize($ri_pay_info)) . "', '" . addslashes(serialize($companyInfo)) . "', '{$ri_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_reseller_paid = 0\r\nand t.`transactionId` = td.`transactionId` and td.transactionDate < '{$date_hold}'\r\nleft join cs_transactiondetails as tdc ON tdc.td_reseller_deducted = 0\r\nand t.`transactionId` = tdc.`transactionId` and tdc.cancellationDate < '{$date_delay}'\r\nset td.td_reseller_paid = {$invoice_id}, tdc.td_reseller_deducted={$invoice_id}\r\n WHERE cd.reseller_id='" . $companyInfo['reseller_id'] . "'"; $result = mysql_query($transaction_sql, $cnn_cs) or dieLog(mysql_error() . " ~ {$transaction_sql}"); // Update Company $company_sql = "UPDATE `cs_resellerdetails` as rd SET \r\n`rd_next_pay_day` = '{$nextPayDay}'\r\n WHERE rd.reseller_id='" . $companyInfo['reseller_id'] . "'"; $result = mysql_query($company_sql, $cnn_cs) or dieLog(mysql_error() . " ~ {$company_sql}"); }