PierreL Posted January 24, 2009 Share Posted January 24, 2009 Hi Guys I'm pretty new to PHP and need desperate help to modify a function. This function calculates commision for an auction. function vbccalc_commission($vbc_finalprice, $vbcomm_increments){ settype($vbc_finalprice, "float"); // Build the Commissions Structure $vbcomm_inc = explode("\n", $vbcomm_increments); $vbccomm_index = '0'; foreach($vbcomm_inc AS $vbcomm_inc_bit){ $vbccomm_bit = explode("|", $vbcomm_inc_bit); $vbccomm_index++; $vbccomm_level[$vbccomm_index] = $vbccomm_index; settype($vbccomm_bit[0], "float"); $vbccomm_price[$vbccomm_index] = $vbccomm_bit[0]; settype($vbccomm_bit[1], "float"); $vbccomm_fee[$vbccomm_index] = $vbccomm_bit[1]; $max = $vbccomm_index; } $count = $max; $vbcomm_sum = '0'; while ($count > 0) { if($vbc_finalprice >= $vbccomm_price[$count]){ $vbcomm_step = $vbc_finalprice - $vbccomm_price[$count]; $vbcomm_bit = $vbcomm_step * $vbccomm_fee[$count]; $vbcomm_sum = $vbcomm_sum + $vbcomm_bit; $vbc_finalprice = $vbc_finalprice - $vbcomm_step; } $count--; } $vbc_commission = $vbcomm_sum; return $vbc_commission; } The $vbcomm_increments is not needed anymore. The new commision structure can be hard coded. $vbcomm_increments allowed you to modify the script but the modifier can not do what i want the script to do. Below is an example of what i want this script to do - Listing fee for all items is R 15.00 - Goods listed from R 0.01 - R 500.00, only the listing fee has to be paid. - From R 500.01 - R 10 000.00, listing fee + 5% - From R 10 000.01 and above, listing fee + 3% Examples - You sell a fly box with flies for R 200.00, the fee is the listing fee of R 15.00 - You sell a rod for R 600.00, the fee is the listing fee (R 15.00) + 5% of R 600.00 (R 30.00) = R 45.00 - You sell a Sage for R 1200.00, the fee is the listing fee (R 15.00) + 5% of R 1200.00 (R60.00) = R 75.00 - You sell your vehicle for R 50 000.00, the fee is the listing fee (R15.00) + 3% of R 50 000.00 (R 1500.00) = R 1515.00 The guy that wrote this mod for an auction scripts is not supporting this anymore and is un available which leaves me in a bad spot not being able to launch. I would be really gratefull if someone can help me out. Thanks in advance All the best Pierre Quote Link to comment https://forums.phpfreaks.com/topic/142285-commision-script/ Share on other sites More sharing options...
DeanWhitehouse Posted January 24, 2009 Share Posted January 24, 2009 And you want us to modify it for you? Try and modify it yourself and when you hit an error or problem then ask us to help you fix it, we are not here to do work for free but to help. Quote Link to comment https://forums.phpfreaks.com/topic/142285-commision-script/#findComment-745445 Share on other sites More sharing options...
PierreL Posted January 25, 2009 Author Share Posted January 25, 2009 Hi Blade No i dont expect you guys to do it, just needed advise, this is what i tried. $vbc_finalprice = 200.00; if($vbc_finalprice <= 500.00) { $vbcomm_sum = 15.00; }else if ($vbc_finalprice >= 500.01 && $vbc_finalprice <= 10000.00){ $vbcomm_sum = $vbc_finalprice * (1 - 0.05) + 15.00; }else($vbc_finalprice >= 10000.01){ $vbcomm_sum = $vbc_finalprice * (1 - 0.03) + 15.00; } $vbc_commission = $vbcomm_sum; return $vbc_commission; print "$vbc_commission"; PHP does not seem to like this, but you get what i am trying to do here else if ($vbc_finalprice >= 500.01 && $vbc_finalprice <= 10000.00) Cheers Quote Link to comment https://forums.phpfreaks.com/topic/142285-commision-script/#findComment-745767 Share on other sites More sharing options...
PierreL Posted January 25, 2009 Author Share Posted January 25, 2009 Ok i think i;ve cracked it if(($vbc_finalprice >= 0.01) and ($vbc_finalprice <= 500.00)) { $vbcomm_sum = 15.00; }else if (($vbc_finalprice >= 500.01) and ($vbc_finalprice <= 10000.00)){ $vbcomm_sum = $vbc_finalprice * 0.05 + 15.00; }else if($vbc_finalprice >= 10000.01){ $vbcomm_sum = $vbc_finalprice * 0.03 + 15.00; }else{ $vbcomm_sum = 0; } $vbc_commission = $vbcomm_sum; return $vbc_commission; Quote Link to comment https://forums.phpfreaks.com/topic/142285-commision-script/#findComment-745770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.