6 Replies - 313 Views - Last Post: 11 April 2019 - 09:26 PM Rate Topic: -----

#1 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Help with modifying/substituting daily earnings calculation

Posted 10 April 2019 - 02:55 PM

I'd like some help, please, with substituting some code in line 88 (in Bold below). I believe that line calculates the daily video earnings. And then when this file executes, it displays that amount onto an html page:

<?php 
if (!IS_LOGGED || ($pt->config->sell_videos_system == 'off' && $pt->config->usr_v_mon == 'off') ) {
	header('Location: ' . PT_Link('404'));
	exit;
}

$currency        = '$';

if ($pt->config->payment_currency == 'EUR') {
	$currency    = '€';
}
$types = array('today','this_week','this_month','this_year');
$type = 'today';

if (!empty($_GET['type']) && in_array($_GET['type'], $types)) {
	$type = $_GET['type'];
}

if ($type == 'today') {
	$start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
	$end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");

	$array = array('00' => 0 ,'01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0);
	$ads_array = $array;
	$date_type = 'H';
	$pt->cat_type = 'today';
    $pt->chart_title = $lang->today;
    $pt->chart_text = date("l");
}
elseif ($type == 'this_week') {
	
	$time = strtotime(date('l').", ".date('M')." ".date('d').", ".date('Y'));
	if (date('l') == 'Saturday') {
		$start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
	}
	else{
		$start = strtotime('last saturday, 12:00am', $time);
	}

	if (date('l') == 'Friday') {
		$end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");
	}
	else{
		$end = strtotime('next Friday, 11:59pm', $time);
	}
	
	$array = array('Saturday' => 0 , 'Sunday' => 0 , 'Monday' => 0 , 'Tuesday' => 0 , 'Wednesday' => 0 , 'Thursday' => 0 , 'Friday' => 0);
	$ads_array = $array;
	$date_type = 'l';
	$pt->cat_type = 'this_week';
    $pt->chart_title = $lang->this_week;
    $pt->chart_text = date('y/M/d',$start)." To ".date('y/M/d',$end);
}
elseif ($type == 'this_month') {
	$start = strtotime("1 ".date('M')." ".date('Y')." 12:00am");
	$end = strtotime(cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'))." ".date('M')." ".date('Y')." 11:59pm");
	if (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 31) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0 ,'30' => 0 ,'31' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 30) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0 ,'30' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 29) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 28) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0);
	}
	$ads_array = $array;
	$pt->month_days = count($array);
	$date_type = 'd';
	$pt->cat_type = 'this_month';
    $pt->chart_title = $lang->this_month;
    $pt->chart_text = date("M");
}
elseif ($type == 'this_year') {
	$start = strtotime("1 January ".date('Y')." 12:00am");
	$end = strtotime("31 December ".date('Y')." 11:59pm");
	$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0);
	$ads_array = $array;
	$date_type = 'm';
	$pt->cat_type = 'this_year';
    $pt->chart_title = $lang->this_year;
    $pt->chart_text = date("Y");
}

$day_start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
$day_end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");
$this_day_ads_earn = $db->rawQuery("SELECT SUM(amount) AS sum FROM ".T_ADS_TRANS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end."  AND type = 'video' AND video_owner = ".$pt->user->id);

[b]$this_day_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id = ".$pt->user->id);[/b]

$day_net = 0;
foreach ($this_day_video_earn as $tr) {
	if ($tr->currency == "USD") {
		$day_net = $day_net + ($tr->amount - $tr->admin_com);
	}
	else if($tr->currency == "EUR"){
		$day_net = $day_net + ($tr->amount - $tr->admin_com);
	}
	elseif ($tr->currency == "EUR_PERCENT") {
		$day_net = $day_net + ($tr->amount - ($tr->admin_com * $tr->amount)/100);
	}
	elseif ($tr->currency == "USD_PERCENT") {
		$day_net = $day_net + ($tr->amount - ($tr->admin_com * $tr->amount)/100);
	}
}
$today_earn = $this_day_ads_earn[0]->sum + $day_net ;

$month_start = strtotime("1 ".date('M')." ".date('Y')." 12:00am");
$month_end = strtotime(cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'))." ".date('M')." ".date('Y')." 11:59pm");
$this_month_ads_earn = $db->rawQuery("SELECT SUM(amount) AS sum FROM ".T_ADS_TRANS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end."  AND type = 'video' AND video_owner = ".$pt->user->id);
$this_month_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end." AND user_id = ".$pt->user->id);
$month_net = 0;
foreach ($this_month_video_earn as $tr) {
	if ($tr->currency == "USD") {
		$month_net = $month_net + ($tr->amount - $tr->admin_com);
	}
	else if($tr->currency == "EUR"){
		$month_net = $month_net + ($tr->amount - $tr->admin_com);
	}
	elseif ($tr->currency == "EUR_PERCENT") {
		$month_net = $month_net + ($tr->amount - ($tr->admin_com * $tr->amount)/100);
	}
	elseif ($tr->currency == "USD_PERCENT") {
		$month_net = $month_net + ($tr->amount - ($tr->admin_com * $tr->amount)/100);
	}
}
$month_earn = $this_month_ads_earn[0]->sum + $month_net ;

$trans        = $db->where('user_id',$user->id)->orderBy('id','DESC')->get(T_VIDEOS_TRSNS);
$ads_trans = $db->where('time',$start,'>=')->where('time',$end,'<=')->where('video_owner',$pt->user->id)->where('type','video')->get(T_ADS_TRANS);
$total_ads = 0;
if (!empty($ads_trans)) {
	foreach ($ads_trans as $key => $ad) {
		if ($ad->time >= $start && $ad->time <= $end) {
			$day = date($date_type,$ad->time);
			if (in_array($day, array_keys($ads_array))) {
				$ads_array[$day] += $ad->amount; 
				$total_ads += $ad->amount; 
			}
		}
	}
}
$ads_list        = "";


$total_earn = 0;
if (!empty($trans)) {
	foreach ($trans as $tr) {
		$video = PT_GetVideoByID($tr->video_id, 0, 0, 2);

		$user_data   = PT_UserData($tr->paid_id);

		$currency         = "";
		$admin_currency         = "";
		$net = 0;
		if ($tr->currency == "USD") {
			$currency     = "$";
			$admin_currency     = "$".$tr->admin_com;
			$net = $tr->amount - $tr->admin_com;
		}
		else if($tr->currency == "EUR"){
			$currency     = "€";
			$admin_currency     = "€".$tr->admin_com;
			$net = $tr->amount - $tr->admin_com;
		}
		elseif ($tr->currency == "EUR_PERCENT") {
			$currency     = "€";
			$admin_currency = $tr->admin_com."%";
			$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
		}
		elseif ($tr->currency == "USD_PERCENT") {
			$currency     = "$";
			$admin_currency = $tr->admin_com."%";
			$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
		}

		if ($tr->time >= $start && $tr->time <= $end) {
			$day = date($date_type,$tr->time);
			if (in_array($day, array_keys($array))) {
				$array[$day] += $net; 
			}
		}

		$total_earn = $total_earn + (float)$net;
		if (!empty($video) && !empty($user_data)) {
			$ads_list   .= PT_LoadPage('transactions/list',array(
				'ID' => $tr->id,
				'PAID_USER' => substr($user_data->name, 0,20),
				'PAID_URL' => $user_data->url,
				'USER_NAME' => $user_data->username,
				'VIDEO_NAME' => substr($video->title, 0,20) ,
				'VIDEO_URL' => $video->url,
				'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
				'AMOUNT' => $tr->amount,
				"CURRENCY" => $currency,
				"A_CURRENCY" => $admin_currency,
				"NET" => $net,
				"TIME" => PT_Time_Elapsed_String($tr->time)
			));
		}
	}
}
$total_earn = $total_earn + $total_ads;

$pt->array = implode(', ', $array);
$pt->ads_array = implode(', ', $ads_array);
$pt->page_url_ = $pt->config->site_url.'/transactions';
$pt->title       = $lang->earnings . ' | ' . $pt->config->title;
$pt->page        = "transactions";
$pt->description = $pt->config->description;
$pt->keyword     = @$pt->config->keyword;
$pt->currency    = $currency;
$pt->content     = PT_LoadPage('transactions/content',array(
	'CURRENCY'   => $currency,
	'ADS_LIST'   => $ads_list,
	'TOTAL_EARN' => $total_earn,
	'TODAY_EARN' => $today_earn,
	'MONTH_EARN' => $month_earn
));





I have modified the web script elsewhere, where it successfully uses a separate search, purchase and play videos pages. But, I'd like to use this script file code (above) to display the daily User earnings - from my modifications. For example, that line 88 currently uses T_VIDEO_TRANS, which is a db table. My modifications stores the calculated video purchase earnings in the U_PAID_VIDEOS table, in a db column named 'earned_amount'.

I look forward to ant assistance/questions/solutions

This post has been edited by chrisjchrisj: 10 April 2019 - 02:56 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with modifying/substituting daily earnings calculation

#2 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,972
  • Joined: 15-January 14

Re: Help with modifying/substituting daily earnings calculation

Posted 10 April 2019 - 03:44 PM

Line 88 just gets data from the database, the calculations are done in the following loop where it checks each transaction and then adds the ad sum at the end.

If your table has the same structure as the other table, and the old table isn't being used for anything any more, and you want to use the same rules that the loop is using, then you can probably just change the table name.
Was This Post Helpful? 0
  • +
  • -

#3 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with modifying/substituting daily earnings calculation

Posted 10 April 2019 - 04:21 PM

Thanks again for your diagnosis.

The old table and new table don't have the same structure.

so, I tried this with no success:

$this_day_video_earn = $db->rawQuery("SELECT * FROM ".T_U_PAID_VIDEOS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id_uploaded = ".$pt->user->id);
$day_net = 0;
foreach ($this_day_video_earn as $tr) {
	if ($tr->currency == "USD") {
		$day_net = $day_net + ($tr->earned_amount);
	}



My modification already calculates the net earned amount and stores the calculated video purchase earnings in the U_PAID_VIDEOS table, in a db column named 'earned_amount'. The current script appears to calculate the net earned amount with:

day_net = $day_net + ($tr->amount - $tr->admin_com);


so, that why I changed the line to:

$day_net = $day_net + ($tr->earned_amount);



but, like I said no success, meaning that the html page doesn't open after these changes I've made. So, I'm wondering if my changes are proper code, and if so, do my changes work with the rest of the page code, or do I need to tweak it elsewhere?

Grateful for any additional guidance.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,972
  • Joined: 15-January 14

Re: Help with modifying/substituting daily earnings calculation

Posted 10 April 2019 - 04:31 PM

If the table structure is different, then does the WHERE clause in the SQL statement still make sense? And does it still have a currency column? Did you change all of the if statements inside the loop? If you're making code changes it's probably best to just post the current section of code instead of describing what you did.
Was This Post Helpful? 0
  • +
  • -

#5 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with modifying/substituting daily earnings calculation

Posted 11 April 2019 - 12:48 PM

Much thanks again for your reply.

Yes, I believe the WHERE clause still makes sense. These are the columns in the 'u_paid_videos' table:
id, id_user, id_video, video_title, time, user_id_uploaded, earned_amount, currency

I have tried many things without success (meaning the html page won't open) with my changes (in Bold) below:

Any additional guidance is greatly appreciated.

//$this_day_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id = ".$pt->user->id);

[b]$this_day_video_earn = $db->rawQuery("SELECT * FROM ".T_U_PAID_VIDEOS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id_uploaded = ".$pt->user->id);[/b]

$day_net = 0;
foreach ($this_day_video_earn as $tr) {
	if ($tr->currency == "USD") {
		//$day_net = $day_net + ($tr->amount - $tr->admin_com);
		$day_net = $day_net + ($tr->earned_amount);
	}

}
$today_earn = $this_day_ads_earn[0]->sum + $day_net ;

$month_start = strtotime("1 ".date('M')." ".date('Y')." 12:00am");
$month_end = strtotime(cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'))." ".date('M')." ".date('Y')." 11:59pm");

$this_month_ads_earn = $db->rawQuery("SELECT SUM(amount) AS sum FROM ".T_ADS_TRANS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end."  AND type = 'video' AND video_owner = ".$pt->user->id);

//$this_month_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end." AND user_id = ".$pt->user->id);

[b]$this_month_video_earn = $db->rawQuery("SELECT * FROM ".T_U_PAID_VIDEOS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end." AND user_id_uploaded = ".$pt->user->id);[/b]

$month_net = 0;
foreach ($this_month_video_earn as $tr) {
	if ($tr->currency == "USD") {
		//$month_net = $month_net + ($tr->amount - $tr->admin_com);
		$month_net = $month_net + ($tr->earned_amount);
	}

}
$month_earn = $this_month_ads_earn[0]->sum + $month_net ;

//$trans        = $db->where('user_id',$user->id)->orderBy('id','DESC')->get(T_VIDEOS_TRSNS);
[b]$trans        = $db->where('user_id_uploaded',$user->id)->orderBy('id_user')->get(T_U_PAID_VIDEOS);[/b]

$ads_trans = $db->where('time',$start,'>=')->where('time',$end,'<=')->where('video_owner',$pt->user->id)->where('type','video')->get(T_ADS_TRANS);
$total_ads = 0;
if (!empty($ads_trans)) {
	foreach ($ads_trans as $key => $ad) {
		if ($ad->time >= $start && $ad->time <= $end) {
			$day = date($date_type,$ad->time);
			if (in_array($day, array_keys($ads_array))) {
				$ads_array[$day] += $ad->amount;
				$total_ads += $ad->amount;
			}
		}
	}
}
$ads_list        = "";


$total_earn = 0;
if (!empty($trans)) {
	foreach ($trans as $tr) {
		$video = PT_GetVideoByID($tr->video_id, 0, 0, 2);

		$user_data   = PT_UserData($tr->paid_id);

		$currency         = "";
		$admin_currency         = "";
		$net = 0;
		if ($tr->currency == "USD") {
			$currency     = "$";
			$admin_currency     = "$".$tr->admin_com;
			$net = $tr->amount - $tr->admin_com;
		}
		else if($tr->currency == "EUR"){
			$currency     = "€";
			$admin_currency     = "€".$tr->admin_com;
			$net = $tr->amount - $tr->admin_com;
		}
		elseif ($tr->currency == "EUR_PERCENT") {
			$currency     = "€";
			$admin_currency = $tr->admin_com."%";
			$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
		}
		elseif ($tr->currency == "USD_PERCENT") {
			$currency     = "$";
			$admin_currency = $tr->admin_com."%";
			$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
		}

		if ($tr->time >= $start && $tr->time <= $end) {
			$day = date($date_type,$tr->time);
			if (in_array($day, array_keys($array))) {
				$array[$day] += $net;
			}
		}

		$total_earn = $total_earn + (float)$net;
		if (!empty($video) && !empty($user_data)) {
			$ads_list   .= PT_LoadPage('transactions/list',array(
				'ID' => $tr->id,
				'PAID_USER' => substr($user_data->name, 0,20),
				'PAID_URL' => $user_data->url,
				'USER_NAME' => $user_data->username,
				'VIDEO_NAME' => substr($video->title, 0,20) ,
				'VIDEO_URL' => $video->url,
				'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
				'AMOUNT' => $tr->amount,
				"CURRENCY" => $currency,
				"A_CURRENCY" => $admin_currency,
				"NET" => $net,
				"TIME" => PT_Time_Elapsed_String($tr->time)
			));
		}
	}
}
$total_earn = $total_earn + $total_ads;

$pt->array = implode(', ', $array);
$pt->ads_array = implode(', ', $ads_array);
$pt->page_url_ = $pt->config->site_url.'/transactions';
$pt->title       = $lang->earnings . ' | ' . $pt->config->title;
$pt->page        = "transactions";
$pt->description = $pt->config->description;
$pt->keyword     = @$pt->config->keyword;
$pt->currency    = $currency;
$pt->content     = PT_LoadPage('transactions/content',array(
	'CURRENCY'   => $currency,
	'ADS_LIST'   => $ads_list,
	'TOTAL_EARN' => $total_earn,
	'TODAY_EARN' => $today_earn,
	'MONTH_EARN' => $month_earn
));


Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,972
  • Joined: 15-January 14

Re: Help with modifying/substituting daily earnings calculation

Posted 11 April 2019 - 01:05 PM

Note that bold does not show as bold in a code box, it shows the code.

If you're getting a fatal error you should find out what the error is. I don't know what your database class does if an error happens, but database error messages are not automatically shown by PHP, you have to check for an error and show the message. PHP errors will either be printed to the output or to an error log depending on the settings in php.ini. I would check there to figure out what you're doing with error messages and then see what the message says. Make sure the error reporting level is also not set too low to hide certain messages. It's also possible to set those options at runtime, so if you're using a bunch of code that you didn't write then you might also need to go through it to look for changes to error reporting settings, but start with php.ini and, if necessary, set it to use an error log and then check the error log.
Was This Post Helpful? 0
  • +
  • -

#7 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with modifying/substituting daily earnings calculation

Posted 11 April 2019 - 09:26 PM

Great advice. That was very helpful. Issue resolved. Much thanks again
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1