Skip to content

Instantly share code, notes, and snippets.

@gmann1982
Created February 24, 2014 20:24
Show Gist options
  • Save gmann1982/9196264 to your computer and use it in GitHub Desktop.
Save gmann1982/9196264 to your computer and use it in GitHub Desktop.
<?php
/**
*
*/
ini_set("memory_limit", "256M");
class Reports
{
public $conn_count = 0;
public $un_conn_count = 0;
// GAMMA
public $gammaConns = 0;
public $gammaConnsUnConn = 0;
public $gammaOG = 0.03;
// EE
public $eeConns = 0;
public $eeConnsUnConn = 0;
public $eeOG = 0.03;
public function masterDashboard($dealerId = false, $from = false, $to = false)
{
$data = array();
$data['connected'] = $this->getConnected(false, $from, $to);
$data['unConnected'] = $this->getUnConnected();
//echo $this->conn_count;
return $data;
}
public function getConnected($dealer_id = false, $from = false, $to = false, $bdm_id = false)
{
try {
global $database;
$sql = "SELECT tbl_quotes.id, tbl_quotes.searchConn, tbl_quotes.quoteCategory, tbl_quotes.UGComm, tbl_quotes.searchTerm, tbl_quotes.buyOut, tbl_quotes.margin,
tbl_quotedetails.basicParentCommission, tbl_quotedetails.basicChildCommission, tbl_quotedetails.networkId, tbl_quotedetails.currency, tbl_quotedetails.addMargin,
tbl_quotedetails.volumeCommission, tbl_quotedetails.networkBonus, tbl_quotedetails.convergedBonus, tbl_quotedetails.rrpMonthlyTotal, tbl_quotedetails.rrpMonthly, tbl_quotedetails.ourMonthly, tbl_quotedetails.kitFund,
tbl_quotes.VodafoneMARGIN, tbl_quotes.TMobileMARGIN, tbl_quotes.O2MARGIN, tbl_quotes.ThreeMARGIN, tbl_quotes.MBBMARGIN, tbl_quotes.UpgradeMARGIN, tbl_quotes.OrangeMARGIN, tbl_quotes.EEMargin,
tbl_quotehardware.reasonId
FROM tbl_quotes
LEFT JOIN tbl_quotedetails
ON tbl_quotes.id = tbl_quotedetails.quote_Id
LEFT JOIN tbl_quotehardware
ON tbl_quotes.id = tbl_quotehardware.quote_Id
WHERE tbl_quotes.kitPosted = 1 AND tbl_quotes.connDate >= '$from' AND tbl_quotes.connDate <= '$to' AND tbl_quotehardware.reasonId != 11
GROUP BY tbl_quotes.id
ORDER BY tbl_quotes.id";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_OBJ)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
}
if (empty($data)) {
return "sorry no data to retrieve";
} else {
foreach ($data as $dat)
{
$this->conn_count += $dat['searchConn'];
}
$report['basicTotal'] = $this->calculateBasicCommission($data);
$report['basicAverage'] = $this->calculateAverage($report['basicTotal'], $this->conn_count);
$report['volumeTotal'] = $this->calculateVolumeCommission($data);
$report['volumeAverage'] = $this->calculateAverage($report['volumeTotal'], $this->conn_count);
$report['networkBonusTotal'] = $this->calculateNetworkBonus($data);
$report['networkBonusAverage'] = $this->calculateAverage($report['networkBonusTotal'], $this->conn_count);
$report['convergedBonusTotal'] = $this->calculateConvergedBonus($data);
$report['convergedBonusAverage'] = $this->calculateAverage($report['convergedBonusTotal'], $this->conn_count);
$report['kitCostTotal'] = $this->calculateKitCost($data);
$report['kitCostAverage'] = $this->calculateAverage($report['kitCostTotal'], $this->conn_count);
$report['rebateTotal'] = $this->calculateRebate($data);
$report['rebateAverage'] = $this->calculateAverage($report['rebateTotal'], $this->conn_count);
$report['buyoutTotal'] = $this->calculateBuyout($data);
$report['buyoutAverage'] = $this->calculateAverage($report['buyoutTotal'], $this->conn_count);
$report['dealerMarginTotal'] = $this->calculateDealerMargin($data);
$report['dealerMarginAverage'] = $this->calculateAverage($report['dealerMarginTotal'], $this->conn_count);
$report['LRpromoDiscount'] = $this->calculateLineRentalPromoDiscount($data);
$report['LRpromoDiscountAverage'] = $this->calculateAverage($report['LRpromoDiscount'], $this->conn_count);
$report['additionalDealerFunding'] = $this->calculateAdditionalDealerFunding($data);
$report['additionalDealerFundingAverage'] = $this->calculateAverage($report['additionalDealerFunding'], $this->conn_count);
$report['boltOnCommission'] = $this->calculateBoltOnCommission($data);
$report['boltOnCommissionAverage'] = $this->calculateAverage($report['boltOnCommission'], $this->conn_count);
$report['hardware_fund'] = $this->calculateHardwareFund($data);
$report['hardware_fund_average'] = $this->calculateAverage($report['hardware_fund'], $this->conn_count);
$report['gammaOG'] = $this->calculateGammaOngoingConn($data);
$report['gammaOGAverage'] = $this->calculateAverage($report['gammaOG'], $this->gammaConns);
$report['gammaLR'] = $this->calculateGammaLineRental($data);
$report['gammaLRAverage'] = $this->calculateAverage($report['gammaLR'], $this->gammaConns);
$report['gammaBoltOnLR'] = $this->calculateGammaBoltOnLR($data);
$report['gammaBoltOnLRAverage'] = $this->calculateAverage($report['gammaBoltOnLR'], $this->gammaConns);
$report['ourMarginTotal'] = $this->calculateOurMargin($data) - $report['LRpromoDiscount'] - $report['additionalDealerFunding'];
$report['ourMarginAverage'] = $this->calculateAverage($report['ourMarginTotal'], $this->conn_count);
$report['ourMarginGrandTotal'] = $report['ourMarginTotal'] + $report['gammaOG'];
$report['ourMarginGrandTotalAverage'] = $this->calculateAverage($report['ourMarginGrandTotal'], $this->conn_count);
$report['count'] = $this->conn_count;
$report['gammaCount'] = $this->gammaConns;
return $report;
}
} catch(Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function getUnConnected($dealer_id = false)
{
try {
global $database;
$sql = "SELECT tbl_quotes.id, tbl_quotes.searchConn, tbl_quotes.quoteCategory, tbl_quotes.UGComm, tbl_quotes.searchTerm, tbl_quotes.buyOut, tbl_quotes.margin,
tbl_quotedetails.basicParentCommission, tbl_quotedetails.basicChildCommission, tbl_quotedetails.networkId, tbl_quotedetails.currency, tbl_quotedetails.addMargin,
tbl_quotedetails.volumeCommission, tbl_quotedetails.networkBonus, tbl_quotedetails.convergedBonus, tbl_quotedetails.rrpMonthlyTotal, tbl_quotedetails.ourMonthly, tbl_quotedetails.rrpMonthly, tbl_quotedetails.kitFund,
tbl_quotes.VodafoneMARGIN, tbl_quotes.TMobileMARGIN, tbl_quotes.O2MARGIN, tbl_quotes.ThreeMARGIN, tbl_quotes.MBBMARGIN, tbl_quotes.UpgradeMARGIN, tbl_quotes.OrangeMARGIN, tbl_quotes.EEMargin,
tbl_quotehardware.reasonId
FROM tbl_quotes
LEFT JOIN tbl_quotedetails
ON tbl_quotes.id = tbl_quotedetails.quote_Id
LEFT JOIN tbl_quotehardware
ON tbl_quotes.id = tbl_quotehardware.quote_Id
WHERE tbl_quotes.kitPosted = 0 AND tbl_quotes.termsAccepted = 1 AND tbl_quotehardware.reasonId != 11
GROUP BY tbl_quotes.id
ORDER BY tbl_quotes.id ASC";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_OBJ)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
}
if (empty($data)) {
return "sorry no data to retrieve";
} else {
foreach ($data as $dat)
{
$this->un_conn_count += $dat['searchConn'];
}
//echo $this->un_conn_count;
$report['basicTotal'] = $this->calculateBasicCommission($data);
$report['basicAverage'] = $this->calculateAverage($report['basicTotal'], $this->un_conn_count);
$report['volumeTotal'] = $this->calculateVolumeCommission($data);
$report['volumeAverage'] = $this->calculateAverage($report['volumeTotal'], $this->un_conn_count);
$report['networkBonusTotal'] = $this->calculateNetworkBonus($data);
$report['networkBonusAverage'] = $this->calculateAverage($report['networkBonusTotal'], $this->un_conn_count);
$report['convergedBonusTotal'] = $this->calculateConvergedBonus($data);
$report['convergedBonusAverage'] = $this->calculateAverage($report['convergedBonusTotal'], $this->un_conn_count);
$report['kitCostTotal'] = $this->calculateKitCost($data);
$report['kitCostAverage'] = $this->calculateAverage($report['kitCostTotal'], $this->un_conn_count);
$report['rebateTotal'] = $this->calculateRebate($data);
$report['rebateAverage'] = $this->calculateAverage($report['rebateTotal'], $this->un_conn_count);
$report['buyoutTotal'] = $this->calculateBuyout($data);
$report['buyoutAverage'] = $this->calculateAverage($report['buyoutTotal'], $this->un_conn_count);
$report['dealerMarginTotal'] = $this->calculateDealerMargin($data);
$report['dealerMarginAverage'] = $this->calculateAverage($report['dealerMarginTotal'], $this->un_conn_count);
$report['LRpromoDiscount'] = $this->calculateLineRentalPromoDiscount($data);
$report['LRpromoDiscountAverage'] = $this->calculateAverage($report['LRpromoDiscount'], $this->un_conn_count);
$report['additionalDealerFunding'] = $this->calculateAdditionalDealerFunding($data);
$report['additionalDealerFundingAverage'] = $this->calculateAverage($report['additionalDealerFunding'], $this->un_conn_count);
$report['boltOnCommission'] = $this->calculateBoltOnCommission($data);
$report['boltOnCommissionAverage'] = $this->calculateAverage($report['boltOnCommission'], $this->un_conn_count);
$report['hardware_fund'] = $this->calculateHardwareFund($data);
$report['hardware_fund_average'] = $this->calculateAverage($report['hardware_fund'], $this->un_conn_count);
// GAMMA
$report['gammaOG'] = $this->calculateGammaOngoingUnConn($data);
$report['gammaOGAverage'] = $this->calculateAverage($report['gammaOG'], $this->gammaConnsUnConn);
$report['gammaLR'] = $this->calculateGammaLineRental($data);
$report['gammaLRAverage'] = $this->calculateAverage($report['gammaLR'], $this->gammaConnsUnConn);
$report['gammaBoltOnLR'] = $this->calculateGammaBoltOnLR($data);
$report['gammaBoltOnLRAverage'] = $this->calculateAverage($report['gammaBoltOnLR'], $this->gammaConnsUnConn);
// EE
// $report['eeOG'] = $this->calculateeeOngoingUnConn($data);
// $report['eeOGAverage'] = $this->calculateAverage($report['eeOG'], $this->eeConnsUnConn);
// $report['eeLR'] = $this->calculateeeLineRental($data);
// $report['eeLRAverage'] = $this->calculateAverage($report['eeLR'], $this->eeConnsUnConn);
// $report['eeBoltOnLR'] = $this->calculateeeBoltOnLR($data);
// $report['eeBoltOnLRAverage'] = $this->calculateAverage($report['eeBoltOnLR'], $this->eeConnsUnConn);
$report['ourMarginTotal'] = $this->calculateOurMargin($data) - $report['LRpromoDiscount'] - $report['additionalDealerFunding'];
$report['ourMarginAverage'] = $this->calculateAverage($report['ourMarginTotal'], $this->un_conn_count);
$report['ourMarginGrandTotal'] = $report['ourMarginTotal'] + $report['gammaOG'];
$report['ourMarginGrandTotalAverage'] = $this->calculateAverage($report['ourMarginGrandTotal'], $this->un_conn_count);
$report['count'] = $this->un_conn_count;
$report['gammaCount'] = $this->gammaConnsUnConn;
return $report;
}
} catch(Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionUnConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateBasicCommission($data = array())
{
try {
$overallCommission = 0;
foreach ($data as $key)
{
if ($key['quoteCategory'] == 'U')
{
$overallCommission += $key['UGComm'];
}
else
{
$childConns = $key['searchConn'] - 1;
$parentCommission = $key['basicParentCommission'];
$childCommission = $key['basicChildCommission'] * $childConns;
$totalCommission = $parentCommission + $childCommission;
// echo "<pre>";
// echo $key['id'].'<br />';
// echo $parentCommission.'<br />';
// echo $childConns.': '.$childCommission.'<br />';
// echo $totalCommission.'<br />';
// echo "</pre>";
//echo $key['id'].': '.$totalCommission.'<br />';
$overallCommission += $totalCommission;
}
}
return $overallCommission;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateAverage($total, $count)
{
$average = $total / $count;
return $average;
}
public function calculateVolumeCommission($data = array())
{
try {
$totalVolumeCommission = 0;
foreach ($data as $key)
{
$volumeCommission = 0;
if ( $key['quoteCategory'] == 'U' || $key['quoteCategory'] == 'BB' )
{
$volumeCommission == 0;
//echo "U";
}
else
{
$volumeCommission = $key['searchConn'] * $key['volumeCommission'];
}
//echo "<pre>$volumeCommission</pre>";
$totalVolumeCommission += $volumeCommission;
}
return $totalVolumeCommission;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateNetworkBonus($data = array())
{
try {
$totalNetworkBonus = 0;
foreach ($data as $key)
{
$networkBonus = $key['searchConn'] * $key['networkBonus'];
$totalNetworkBonus += $networkBonus;
}
return $totalNetworkBonus;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateConvergedBonus($data = array())
{
try {
$totalConvergedBonus = 0;
foreach ($data as $key)
{
$convergedBonus = $key['searchConn'] * $key['convergedBonus'];
$totalConvergedBonus += $convergedBonus;
}
return $totalConvergedBonus;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function fetchBasicCommissionConnected\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function getHardware($id)
{
try {
global $database;
$sql = "SELECT price FROM tbl_quotehardware WHERE quote_Id = '$id'";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_OBJ)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
//$this->num_rows++;
}
if (empty($data)) {
return array();
} else {
return $data;
}
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function getHardware\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function getBoltOnBez($id)
{
try {
global $database;
$sql = "SELECT qty, commission, price FROM tbl_quotedetailsbez WHERE quote_Id = '$id'";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_ASSOC)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
//$this->num_rows++;
}
if (empty($data)) {
return array();
} else {
return $data;
}
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function getBoltOnBez\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function getBoltOnBiz($id)
{
try {
global $database;
$sql = "SELECT qty, commission, price FROM tbl_quotedetailsbiz WHERE quote_Id = '$id'";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_ASSOC)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
//$this->num_rows++;
}
if (empty($data)) {
return array();
} else {
return $data;
}
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function tbl_quotedetailsbiz\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function getBoltOnData($id)
{
try {
global $database;
$sql = "SELECT qty, commission, price FROM tbl_quotedetailsdata WHERE quote_Id = '$id'";
$q = $database->query($sql);
while ($result = $q->fetch(PDO::FETCH_ASSOC)) {
$array = array();
foreach ($result as $key => $val) {
$array[$key] = $val;
}
$data[] = $array;
//$this->num_rows++;
}
if (empty($data)) {
return array();
} else {
return $data;
}
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function tbl_quotedetailsdata\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateKitCost($data = array())
{
$totalKitCost = 0;
try {
foreach ($data as $key)
{
$hardware = $this->getHardware($key['id']);
//print_r($hardware);
foreach ($hardware as $kit)
{
$totalKitCost += $kit['price'] * $key['searchTerm'];
//echo $totalKitCost . '<br />';
}
}
return $totalKitCost;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateKitCost\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateRebate($data = array())
{
$totalRebate = 0;
try {
foreach ($data as $key) {
$rebate = 0;
if ($key['ourMonthly'] <= $key['rrpMonthlyTotal'])
{
$rebate = ($key['rrpMonthlyTotal'] - $key['ourMonthly']) * $key['searchTerm'];
$totalRebate += $rebate;
//echo $totalRebate;
}
}
return $totalRebate;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateRebate\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateBuyout($data = array())
{
$totalBuyout = 0;
try {
foreach ($data as $key)
{
$totalBuyout += $key['buyOut'];
}
return $totalBuyout;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateBuyout\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateHardwareFund($data = array())
{
$total = 0;
try {
foreach ($data as $key)
{
$total += ceil(($key['kitFund'] * $key['searchConn']));
}
return $total;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateHardwareFund\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateDealerMargin($data = array())
{
$totalDealerMargin = 0;
try {
foreach ($data as $key)
{
$totalDealerMargin += $key['margin'];
}
return $totalDealerMargin;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateDealerMargin\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateOurMargin($data = array())
{
$ourMarginTotal = 0;
$networkMargin = array(
'1' => 'OrangeMARGIN',
'2' => 'TMobileMARGIN',
'3' => 'VodafoneMARGIN',
'4' => 'O2MARGIN',
'5' => 'ThreeMARGIN',
'6' => 'EEMargin'
);
try {
foreach ($data as $key)
{
//echo $key['quoteCategory'];
switch ($key['quoteCategory'])
{
case 'U':
$ourMarginTotal += $key['UpgradeMARGIN'] * $key['searchConn'];
break;
case 'BB':
$ourMarginTotal += $key['MBBMARGIN'] * $key['searchConn'];
break;
default:
$ourMarginTotal += ($key[$networkMargin[$key['networkId']]] * $key['searchConn']);
//echo $key['id'].': '. $key[$networkMargin[$key['networkId']]].'<br />';
break;
}
// echo "<pre>".$key['id'].": $ourMarginTotal</pre>";
}
// echo "<pre>".$ourMarginTotal."</pre>";
return $ourMarginTotal;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateOurMargin\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateLineRentalPromoDiscount($data = array())
{
$LRpromoTotal = 0;
foreach ($data as $key)
{
$LRpromo = trim($key['currency']) * ($key['searchConn'] - 1);
$LRpromoTotal += $LRpromo;
}
return $LRpromoTotal;
}
public function calculateAdditionalDealerFunding($data = array())
{
$AddFundingTotal = 0;
foreach ($data as $key)
{
if ($key['addMargin'])
{
$addFund = trim($key['addMargin']) * $key['searchConn'];
$AddFundingTotal += $addFund;
}
}
return $AddFundingTotal;
}
public function calculateBoltOnCommission($data = array())
{
$totalBoltonComm = 0;
foreach ($data as $key) {
//echo $key['id'].'<br>';
// fetch each of the boltons
$bez = $this->getBoltOnBez($key['id']);
$biz = $this->getBoltOnBiz($key['id']);
$data = $this->getBoltOnData($key['id']);
// calculate the total commission for each
if( !empty( $bez ) )
{
foreach($bez as $be)
{
if( $be['commission'] < 0 )
{
$totalBoltonComm -= $this->calculateIndividualBoltOnCommission($be['qty'], $be['commission']);
}
else
{
$totalBoltonComm += $this->calculateIndividualBoltOnCommission($be['qty'], $be['commission']);
}
}
}
if ( !empty( $biz ) )
{
foreach($biz as $bi)
{
//$totalBoltonComm += $this->calculateIndividualBoltOnCommission($bi['qty'], $bi['commission']);
if( $bi['commission'] < 0 )
{
$totalBoltonComm -= $this->calculateIndividualBoltOnCommission($bi['qty'], $bi['commission']);
}
else
{
$totalBoltonComm += $this->calculateIndividualBoltOnCommission($bi['qty'], $bi['commission']);
}
}
}
if( !empty( $data ) )
{
foreach($data as $da)
{
//$totalBoltonComm += $this->calculateIndividualBoltOnCommission($da['qty'], $da['commission']);
if( $da['commission'] < 0 )
{
$totalBoltonComm -= $this->calculateIndividualBoltOnCommission($da['qty'], $da['commission']);
}
else
{
$totalBoltonComm += $this->calculateIndividualBoltOnCommission($da['qty'], $da['commission']);
}
}
}
}
return $totalBoltonComm;
}
public function calculateIndividualBoltOnCommission($qty, $commission)
{
try {
$total = 0;
$total = $qty * $commission;
// echo $qty.': '.$commission.'<br>';
// echo $total.'<br />';
return $total;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateIndividualBoltOnCommission\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateIndividualBoltOnPrice($qty, $price)
{
try {
$total = 0;
$total = $qty * $price;
return $total;
} catch (Exception $e) {
$this->error = "Could not fetch basic commissions using function calculateIndividualBoltOnCommission\n";
$this->error .= "The following exception was given: ".$e;
echo $this->error;
}
}
public function calculateGammaOngoingConn($data = array())
{
// filter throught each of the array and calculate the ones that are gamma
$totalGammaOG = 0;
foreach ($data as $key) {
if( $key['networkId'] == 3)
{
//echo 'LR: '.$key['rrpMonthlyTotal'].' term: '.$key['searchTerm'].'<br />';
$totalGammaOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConns += $key['searchConn'];
}
}
return $totalGammaOG;
}
public function calculateGammaOngoingUnConn($data = array())
{
$totalGammaOG = 0;
foreach ($data as $key) {
if( $key['networkId'] == 3)
{
$totalGammaOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
}
}
return $totalGammaOG;
}
public function calculateOngoingUnConn($data = array())
{
$totalOG = 0;
foreach ($data as $key) {
switch ($key['networkId']) {
case '1':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
case '2':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
case '3':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
case '4':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
case '5':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
case '6':
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
break;
}
if( $key['networkId'] == 3)
{
$totalOG += ($key['rrpMonthlyTotal'] * $key['searchTerm']) * $this->gammaOG;
$this->gammaConnsUnConn += $key['searchConn'];
}
}
return $totalOG;
}
public function calculateGammaLineRental($data = array())
{
// filter throught each of the array and calculate the ones that are gamma
$totalGammaLR = 0;
foreach ($data as $key) {
if( $key['networkId'] == 3)
{
//echo 'LR: '.$key['rrpMonthlyTotal'].' term: '.$key['searchTerm'].'<br />';
$totalGammaLR += $key['rrpMonthly'];
}
}
return $totalGammaLR;
}
public function calculateGammaBoltOnLR($data = array())
{
$totalGammaBoltOnLR = 0;
foreach ($data as $key) {
//echo $key['id'].'<br>';
// fetch each of the boltons\
if ($key['networkId'] == 3)
{
$bez = $this->getBoltOnBez($key['id']);
$biz = $this->getBoltOnBiz($key['id']);
$data = $this->getBoltOnData($key['id']);
// calculate the total price for each
if( !empty( $bez ) )
{
foreach($bez as $be)
{
$totalGammaBoltOnLR += $this->calculateIndividualBoltOnPrice($be['qty'], $be['price']);
}
}
if ( !empty( $biz ) )
{
foreach($biz as $bi)
{
$totalGammaBoltOnLR += $this->calculateIndividualBoltOnPrice($bi['qty'], $bi['price']);
}
}
if( !empty( $data ) )
{
foreach($data as $da)
{
$totalGammaBoltOnLR += $this->calculateIndividualBoltOnPrice($da['qty'], $da['price']);
}
}
}
}
return $totalGammaBoltOnLR;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment