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}"); }
if ($show_active == 'a') { $active = "AND completed_reseller_application=1 "; } if ($show_active == 'i') { $active = "AND completed_reseller_application=0 "; } $display_none = "1"; //if($no_display==true) $display_none = "0"; $qry_company = "select * from cs_resellerdetails where {$display_none} {$active}"; // and rd_next_pay_day<=CURDATE() $gatewayid = -1; $company_details = mysql_query($qry_company, $cnn_cs) or dieLog(mysql_error() . " ~ {$sql}"); while ($companyInfo = mysql_fetch_assoc($company_details)) { $sql = 0; if (resellerPastPayPeriod()) { $pushedBack = resellerPushBackOnePeriod(); $sql = "Update cs_resellerdetails set `rd_next_pay_day` = '{$pushedBack}' where reseller_id = '" . $companyInfo['reseller_id'] . "'"; $companyInfo['rd_next_pay_day'] = $pushedBack; } if ($sql) { mysql_query($sql) or dieLog(mysql_error() . " ~ {$sql}"); } $date_hold = 0; $ri_pay_info = calcResellerReal(); if ($show_rollover == 's' && $ri_pay_info['Status'] != 'Rollover') { continue; } if ($show_rollover == 'p' && $ri_pay_info['Status'] != 'Payable') { continue; } ?>