This is a discussion on Compatability oscommerce contribs for OSCMax within the osCmax v2 Customization/Mods forums, part of the osCmax v2.0 Forums category; Originally Posted by met00 For example, here is the edit product for our admin - you can see that it ...
Ummm, Margin Report is NOT from me so I have no idea what fields they call from the database (we modified the code to meet our needs as margin report didn't).
Below is the code where we add costs and compute margin...
Hope that helps.Code:<? // MOD: added MSRP ?> <tr bgcolor="#ebebff"> <td class="main"><?php echo TEXT_PRODUCTS_PRICE_MSRP; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_msrp', $pInfo->products_msrp); ?></td> </tr> <tr bgcolor="#ebebff"> <td class="main"><?php echo TEXT_PRODUCTS_PRICE_NET; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_price', $pInfo->products_price, 'onKeyUp="updateGross()"'); ?></td> </tr> <tr bgcolor="#ebebff"> <td class="main"><?php echo TEXT_PRODUCTS_PRICE_GROSS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_price_gross', $pInfo->products_price, 'OnKeyUp="updateNet()"'); ?></td> </tr> <? $margin = $pInfo->products_price - $pInfo->products_cost; if ($pInfo->products_price != 0) $marginp = (1 - ( $pInfo->products_cost / $pInfo->products_price )) * 100; if ($margin < .01 ) $margin = "<font color=red>".$margin."</font>"; ?> <tr bgcolor="#ebebff"> <td class="main"><?php echo TEXT_PRODUCTS_PRICE_COST; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_cost', $pInfo->products_cost); ?> <i>Margin: <?echo $margin; ?> (<?echo sprintf('%01.2f',$marginp); ?>%)</i></td> </tr>![]()
so endith the lesson
<think>sometimes I just sit's and thinks</think>
"Here you are with a hand full of holes, a thumb up your ass, and a big grin to pass the time of day with." - TWB
It will, I will be able to work it out from that, thanks!![]()
That did the trick, I hardly had to change anything since my variables are the same.
I thought that the shown margin would update real time like the prices do (you change the net price, and the gross price will change to show your price + taxes), guess I hoped for too muchI will try to make it work that way
and let you know.
Thx!
So here is my solution, now the info gets updated real-time as you change any of the values, gross value, net value, or product cost:
Here I created updateMargin, and added a call to the function on updateGross and updateNet, so if the net or gross values change, the margins will do so too.
And here is the HTML part used before the PRICE_NET and PRICE_GROSS parts:PHP Code:function updateGross() {
var taxRate = getTaxRate();
var grossValue = document.forms["new_product"].products_price.value;
if (taxRate > 0) {
grossValue = grossValue * ((taxRate / 100) + 1);
}
document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
updateMargin();
}
function updateNet() {
var taxRate = getTaxRate();
var netValue = document.forms["new_product"].products_price_gross.value;
if (taxRate > 0) {
netValue = netValue / ((taxRate / 100) + 1);
}
document.forms["new_product"].products_price.value = doRound(netValue, 4);
updateMargin();
}
function updateMargin() {
var netValue = document.forms["new_product"].products_price.value;
var costValue = document.forms["new_product"].products_cost.value;
document.getElementById('margin').innerHTML=doRound(netValue - costValue,2);
document.getElementById('margin_pct').innerHTML=doRound( (costValue*100)/netValue , 2);
}
Also, a little bit down there is this piece of code:PHP Code:<tr bgcolor="#ebebff">
<td class="main"><?php echo TEXT_PRODUCTS_PRICE_COST; ?></td>
<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_cost', $pInfo->products_cost, 'onKeyUp="updateMargin()"'); ?> <i>Margen: <label id="margin"></label> (<label id="margin_pct"></label>%)</i></td>
</tr>
I added the updateMargin() there, so the margins will be shown on page load.PHP Code:<script language="javascript"><!--
updateGross();
updateMargin();
//--></script>
Bookmarks