jQuery costing finished

This commit is contained in:
Karl Cordes 2010-02-04 18:43:42 -07:00
parent 3e50c43dce
commit 7534bc2756
4 changed files with 115 additions and 38 deletions

View file

@ -71,9 +71,6 @@ class CurrenciesController extends AppController {
$jsonlist[$id] = array('name' => $currency['Currency']['name'],
'symbol'=>$currency['Currency']['symbol'],
'iso4217'=>$currency['Currency']['iso4217']
);
}

View file

@ -15,7 +15,7 @@
echo $form->input('unit_cost_price', array('label'=>'Unit Cost Price<span class="purchaseCurrency"></span>'));
echo $form->input('our_discount_percent');
echo $form->input('packing', array('label'=>'Supplier packing cost<span class="purchaseCurrency"></span>'));
echo $form->input('FobCountryOfExport', array('readonly'=>'readonly', 'label'=>'FOB Country of Export<span class="purchaseCurrency"></span>'));
echo $form->input('FobCountryOfExport', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'FOB Country of Export<span class="purchaseCurrency"></span>'));
?>
</fieldset>
<fieldset>
@ -24,9 +24,9 @@
echo $form->input('exchange_rate', array('label'=>'Exchange Rate <span id="exchangeConversion"></span>'));
?>
<? echo $form->input('fob_sale_currency', array('readonly'=>'readonly', 'label'=>'Cost<span class="saleCurrency"></span>')); ?>
<? echo $form->input('fob_sale_currency', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Cost<span class="saleCurrency"></span>')); ?>
</fieldset>
<fieldset>
<legend>Customs and Duty</legend>
@ -51,21 +51,43 @@
<fieldset>
<legend>Finance, Misc Costs</legend>
<?
echo $form->input('finance_percent', array('label'=>'Finance Percent (%)<span id="financeAmount"></span> <span class="saleCurrency"></span>'));
echo $form->input('finance_percent', array('label'=>'Finance Percent (%)<span id="financeAmount" class="rightHandLabel"></span>'));
echo $form->input('misc_costs', array('label'=>'Misc Costs<span class="saleCurrency"></span>'));
?>
</fieldset>
<fieldset>
<legend>Total Landed Cost</legend>
<?
echo $form->input('total_landed_cost', array('class'=>'disabled', 'readonly'=>'readonly','label'=>'Total Landed Cost<span class="saleCurrency"></span>'));
?>
</fieldset>
<fieldset>
<legend>Selling Prices, Gross Profit</legend>
<?
echo $form->input('gross_sell_price', array('label'=>'Gross Selling Price<span class="saleCurrency"></span>'));
echo $form->input('gross_gp_prior_to_discount', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Gross GP prior to discount<span class="saleCurrency"></span>'));
echo $form->input('sale_discount_percent', array('label'=>'Discount/Commission (%)<span id="saleDiscountAmount" class="rightHandLabel"></span> '));
echo $form->input('net_sell_price', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Net Selling Price<span class="saleCurrency"></span>'));
echo $form->input('net_gp_amount', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Net GP Amount<span class="saleCurrency"></span>'));
echo $form->input('net_gp_percent', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Net GP Percent (%)'));
echo $form->input('gross_sell_price_each', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Gross Sell Price Each<span class="saleCurrency"></span>'));
echo $form->input('net_sell_price_each', array('class'=>'disabled','readonly'=>'readonly', 'label'=>'Net Sell Price Each<span class="saleCurrency"></span>'));
?>
</fieldset>
<?
echo $form->input('gross_sell_price');
echo $form->input('sale_discount_percent');
echo $form->input('net_sell_price');
?>
</fieldset>
<?php
echo $form->input('duty_amount', array('type'=>'hidden'));
echo $form->input('finance_amount', array('type'=>'hidden'));
echo $form->input('sale_discount_amount', array('type'=>'hidden'));
echo $form->end('Submit');?>
</div>

View file

@ -748,8 +748,7 @@ input#searchbox {
/* CSS from Easy Prototype Validation Script */
input.disabled {
border: 1px solid #F2F2F2;
background-color: #F2F2F2;
background-color: #D8D8D8;
}
input.required, textarea.required {
@ -1177,7 +1176,7 @@ label span#exchangeConversion {
position: absolute;
left: 40em;
top: 0.2em;
width: 19em; color: #088A4B; font-size: 85%; font-weight: normal; text-transform: uppercase;
width: 25em; color: #088A4B; font-size: 85%; font-weight: normal; text-transform: uppercase;
}

View file

@ -29,6 +29,9 @@ function buildup() {
var financePercent = parseFloat($("#CostingFinancePercent").val());
var miscCosts = parseFloat($("#CostingMiscCosts").val());
var grossSellPrice = parseFloat($("#CostingGrossSellPrice").val());
var saleDiscountPercent = parseFloat($("#CostingSaleDiscountPercent").val());
quantity = checkNaN(quantity);
@ -43,7 +46,8 @@ function buildup() {
financePercent = checkNaN(financePercent);
miscCosts = checkNaN(miscCosts);
grossSellPrice = checkNaN(grossSellPrice);
saleDiscountPercent = checkNaN(saleDiscountPercent);
var discountAmount = (ourDiscountPercent / 100) * quantity * unitCostPrice;
@ -56,6 +60,74 @@ function buildup() {
//Update the Exchange Conversion
$("#exchangeConversion").text("1 "+$("#CostingSaleCurrencyId :selected").text()+" = "+exchangeRate+" "+$("#CostingPurchaseCurrencyId :selected").text());
//Calculate cost in Sale Currency
var fobSaleCurrency = fobcountryofexport / exchangeRate;
fobSaleCurrency = fobSaleCurrency.toFixed(2);
$("#CostingFobSaleCurrency").val(fobSaleCurrency);
//Calulate dutyAmount, update the hidden field.
var dutyAmount = (dutyPercent/100)*fobSaleCurrency;
dutyAmount = dutyAmount.toFixed(2);
$("#CostingDutyAmount").val(dutyAmount);
//Calculate finance amount. update the the hidden field.
var financeAmount = (financePercent/100)*fobSaleCurrency;
financeAmount = financeAmount.toFixed(2);
$("#CostingFinanceAmount").val(financeAmount);
//Calculate the Total Landed Cost
var totalLandedCost = +(fobSaleCurrency) + +(customs) + +(shippingCost) + +(dutyAmount) + +(financeAmount) + +(miscCosts);
totalLandedCost = totalLandedCost.toFixed(2);
$("#CostingTotalLandedCost").val(totalLandedCost);
//Calculate the Sale Discount amount.
var saleDiscountAmount = (saleDiscountPercent/100) * grossSellPrice;
saleDiscountAmount = saleDiscountAmount.toFixed(2);
$("#CostingSaleDiscountAmount").val(saleDiscountAmount);
//Calculate the Gross GP prior to discount
var grossGP = grossSellPrice - totalLandedCost;
grossGP = grossGP.toFixed(2);
$("#CostingGrossGpPriorToDiscount").val(grossGP);
//Calculate the Net Selling Price
var netSellPrice = grossSellPrice - saleDiscountAmount;
$("#CostingNetSellPrice").val(netSellPrice);
//Calculate net GP Amount
var netGPamount = grossGP - saleDiscountAmount;
netGPamount = netGPamount.toFixed(2);
$("#CostingNetGpAmount").val(netGPamount);
//Calculate net GP %
var netGPpercent = (netGPamount / grossSellPrice) * 100;
netGPpercent = netGPpercent.toFixed(2);
$("#CostingNetGpPercent").val(netGPpercent);
//Calulate Gross/Net Sell Prices
var grossSellpriceEach = grossSellPrice / quantity;
var netSellpriceEach = netSellPrice / quantity;
$("#CostingGrossSellPriceEach").val(grossSellpriceEach);
$("#CostingNetSellPriceEach").val(netSellpriceEach);
//get a list of currencies in JSON format
//update the Sale and Purchase currency classes
@ -65,34 +137,21 @@ function buildup() {
$(".purchaseCurrency").text(data[$("#CostingPurchaseCurrencyId").val()].iso4217);
//alert(data[1].iso4217);
});
$("#dutyAmount").text("Duty Amount = "+dutyAmount+ " " +data[$("#CostingSaleCurrencyId").val()].iso4217);
$("#financeAmount").text("Finance Amount = "+financeAmount+" "+data[$("#CostingSaleCurrencyId").val()].iso4217);
$("#saleDiscountAmount").text("Discount Amount = "+saleDiscountAmount+" "+data[$("#CostingSaleCurrencyId").val()].iso4217);
});
//Update the sale Currency text
// $(".saleCurrency").text($("#CostingSaleCurrencyId :selected").text());
// $(".purchaseCurrency").text($("#CostingPurchaseCurrencyId :selected").text());
$("#exchangeConversion").text("1 "+$("#CostingSaleCurrencyId :selected").text()+" = "+exchangeRate+" "+$("#CostingPurchaseCurrencyId :selected").text());
//Calculate cost in Sale Currency
var fobSaleCurrency = fobcountryofexport / exchangeRate;
$("#CostingFobSaleCurrency").val(fobSaleCurrency.toFixed(2));
//Calulate dutyAmount, update the text and the hidden field.
var dutyAmount = (dutyPercent/100)*fobSaleCurrency;
dutyAmount = dutyAmount.toFixed(2);
$("#dutyAmount").text("Duty Amount = "+dutyAmount+ " " +$("#CostingSaleCurrencyId :selected").text());
$("#CostingDutyAmount").val(dutyAmount);
//jQuery.getJSON('', data, callback)