Anurag K
Anurag K

Reputation: 189

How To Generate Earning Price Based on Left and Right Point Value in mlm software

I am working in MLM and now I want a code for generating earning value(price) based on user LEFT and RIGHt Point Value. I want To generate weekly earning based on his left and right PV. Every Sunday Run This File on the server and it generates earning one by one all user.

if I have left and the right point value of the user. three conditions are applied in generate earning price.

  1. if Left PV and Right Pv is greater then 100 PV so generate 1000/Rs earning value (3 times applied) every time user earn 1000 if left PV and right PV both increase 100 PV.

  2. Now after this earning generated in 300 Left PV and Right PV each time user increase 300 PV in each side then earning generated 3000Rs(3 times applied).

  3. finally bothe above condition is applied then every time user Left and Right Point Value increase 300 (suppose left = some vale +300 and right = some value +300) than earning amount 2800Rs generated.

I have used this code but this code result does not match what I am expecting.

       if ($LPV >= 100 && $RPV >= 100 && $LPV <= 1200  && $RPV <= 1200) {

        $L_Reminderval = floor($LPV/ 100) . "</br>";
        $R_Reminderval  =  floor($RPV/ 100)."</br>";
        echo $MinVal = (min($L_Reminderval,$R_Reminderval));        
        $earn_val = '1000';
        for ($x = 1; $x <= $MinVal; $x++) {
            if ($x <=3){
                $L_Remaining_Pv = $LPV - $x*100;
                $R_Remaining_Pv = $RPV - $x*100;
                $L_pv_earn_generate = $LPV - $L_Remaining_Pv;
                $R_pv_earn_generate = $RPV - $R_Remaining_Pv;
                $user_obj = new LIB_Earns();
                $data = $user_obj->InserEarnRecord($UserID, $LPV, $RPV, $L_Remaining_Pv, $R_Remaining_Pv, $L_pv_earn_generate, $R_pv_earn_generate, $earn_val);
                $earn_val += '1000';
            }
            elseif ($x <=12 ){                      
                $L_Remaining_Pv = $LPV - $x*100;
                $R_Remaining_Pv = $RPV - $x*100;
                $L_pv_earn_generate = $LPV - $L_Remaining_Pv;
                $R_pv_earn_generate = $RPV - $R_Remaining_Pv;
                $user_obj = new LIB_Earns();
                $data = $user_obj->InserEarnRecord($UserID, $LPV, $RPV, $L_Remaining_Pv, $R_Remaining_Pv, $L_pv_earn_generate, $R_pv_earn_generate, $earn_val);
                $earn_val += '1000';                        
            }
        }
    }

please provide code and logic with insert query. Table Structure what I am useing Now I expected to get Total Left and Right Pv, remaining Left PV and Right PV and earn generate Left Pv and Right Pv. and earning amount.

Upvotes: 0

Views: 134

Answers (1)

Anurag K
Anurag K

Reputation: 189

After a long struggle, I found a solution to this question

public function GenerateEarningCalculate($UserID,$L,$R){

    //$PD=900;
    //$PI=5;            
    $L = !empty($PD) ? $L-$PD : $L;
    $R = !empty($PD) ? $R-$PD : $R;
    $S = ($L < $R) ? $L : $R;
    $P=0;
    $ER = array();
    $TL=0;
    $i = !empty($PI) ? $PI : 0;
    for (; $S > 0; $i++) {
        $T = intval($i / 3);
        $C=0;
        if($T==0){
            if ($S >= 100){
                $P+=1000;
                $C=100;
            }else {
                break;
            }
            array_push($ER, 100);
        }else if($T==1){
            if ($S >= 300){
                $P+=3000;
                $C=300;
            }else {
                break;
            }
            array_push($ER, 300);
        }else{
            if ($S >= 300){
                $P+=2500;
                $C=300;
            }else {
                break;
            }
            array_push($ER, 300);
        }
        $S-=$C;
        $TL+=$C;
        $TLR=$R-$TL;
        $TLL=$L-$TL;
    }

    $user_obj = new LIB_Earning();
    $data = $user_obj->InserEarnRecord($UserID, $L, $R, $TLL, $TLR, $TL, $TL, $P ,$i);

    //echo $P; //Save it
    //var_dump($ER);
    //echo $i; // Save it
    //var_dump($L);
    //var_dump($R);
}

Next function to insert record in the table

public function InserEarnRecord($UserID,$l_pv,$r_pv, $L_Remaining_Pv, 
          $R_Remaining_Pv, $L_pv_earn_generate, $R_pv_earn_generate, $earn_val, $i) {

       //Insert query place here
    }

Upvotes: 1

Related Questions