From 7534bc27560d215ae9d523085fe383ef05075ae0 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Thu, 4 Feb 2010 18:43:42 -0700 Subject: [PATCH] jQuery costing finished --- controllers/currencies_controller.php | 3 - views/costings/add.ctp | 38 +++++++-- webroot/css/quotenik.css | 5 +- webroot/js/add_costing.js | 107 ++++++++++++++++++++------ 4 files changed, 115 insertions(+), 38 deletions(-) diff --git a/controllers/currencies_controller.php b/controllers/currencies_controller.php index 7d4aaed9..4385b915 100755 --- a/controllers/currencies_controller.php +++ b/controllers/currencies_controller.php @@ -71,9 +71,6 @@ class CurrenciesController extends AppController { $jsonlist[$id] = array('name' => $currency['Currency']['name'], 'symbol'=>$currency['Currency']['symbol'], 'iso4217'=>$currency['Currency']['iso4217'] - - - ); } diff --git a/views/costings/add.ctp b/views/costings/add.ctp index 78697ad6..045c25fe 100755 --- a/views/costings/add.ctp +++ b/views/costings/add.ctp @@ -15,7 +15,7 @@ echo $form->input('unit_cost_price', array('label'=>'Unit Cost Price')); echo $form->input('our_discount_percent'); echo $form->input('packing', array('label'=>'Supplier packing cost')); - echo $form->input('FobCountryOfExport', array('readonly'=>'readonly', 'label'=>'FOB Country of Export')); + echo $form->input('FobCountryOfExport', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'FOB Country of Export')); ?>
@@ -24,9 +24,9 @@ echo $form->input('exchange_rate', array('label'=>'Exchange Rate ')); ?> - input('fob_sale_currency', array('readonly'=>'readonly', 'label'=>'Cost')); ?> + input('fob_sale_currency', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Cost')); ?>
- +
Customs and Duty @@ -51,21 +51,43 @@
Finance, Misc Costs input('finance_percent', array('label'=>'Finance Percent (%) ')); + echo $form->input('finance_percent', array('label'=>'Finance Percent (%)')); echo $form->input('misc_costs', array('label'=>'Misc Costs')); ?>
- + +
+ Total Landed Cost + input('total_landed_cost', array('class'=>'disabled', 'readonly'=>'readonly','label'=>'Total Landed Cost')); + ?> +
+ +
+ Selling Prices, Gross Profit + input('gross_sell_price', array('label'=>'Gross Selling Price')); + echo $form->input('gross_gp_prior_to_discount', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Gross GP prior to discount')); + echo $form->input('sale_discount_percent', array('label'=>'Discount/Commission (%) ')); + echo $form->input('net_sell_price', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Net Selling Price')); + echo $form->input('net_gp_amount', array('class'=>'disabled', 'readonly'=>'readonly', 'label'=>'Net GP Amount')); + 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')); + echo $form->input('net_sell_price_each', array('class'=>'disabled','readonly'=>'readonly', 'label'=>'Net Sell Price Each')); + + ?> +
+ input('gross_sell_price'); - echo $form->input('sale_discount_percent'); - echo $form->input('net_sell_price'); ?>
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');?> diff --git a/webroot/css/quotenik.css b/webroot/css/quotenik.css index 26d860a6..16913222 100755 --- a/webroot/css/quotenik.css +++ b/webroot/css/quotenik.css @@ -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; } diff --git a/webroot/js/add_costing.js b/webroot/js/add_costing.js index 53df925e..a317b33e 100644 --- a/webroot/js/add_costing.js +++ b/webroot/js/add_costing.js @@ -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)