cmc-sales/php/app/webroot/js/quotenik/add_costing.js

58 lines
1.6 KiB
JavaScript
Executable file

function buildup() {
//Fetch all the relevent inputs from the form
quantity = +($F('CostingQuantity'));
costprice = +($F('CostingUnitCostPrice'));
ourdiscount_percentage = +($F('CostingOurDiscountPercent'));
packing_each = +($F('CostingPacking'));
exchange_rate = +($F('CostingExchangeRate'));
shipping_cost = +($F('CostingShippingCost'));
duty = +($F('CostingDutyPercent'));
sellprice_each = +($F('sellprice_each'));
customs = +($F('CostingCustoms'));
misc_cost = +($F('CostingMiscCosts'));
finance = +($F('CostingFinancePercent'));
if(ourdiscount_percentage != 0) {
discount = ourdiscount_percentage / 100;
}
else {
discount = 0;
}
discountamount = discount * costprice;
net_foreign_price = costprice - discountamount;
total_foreign_price = net_foreign_price + packing_each;
$F('CostingFobCountryOfExport').value = total_foreign_price;
domestic_cost = total_foreign_price / exchange_rate;
$('convert_to_aud').value = domestic_cost.toFixed(2);
dutyamount = (duty / 100) * domestic_cost;
total_landed_cost = domestic_cost + dutyamount + customs + misc_cost + shipping_cost;
financeamount = (finance / 100) * domestic_cost;
financeamount = financeamount.toFixed(2);
$('financeamount').update('Finance amount: ' + financeamount);
total_landed_cost += (+financeamount);
total_landed_cost = total_landed_cost.toFixed(2);
$('total_landed_cost').value = total_landed_cost;
gross_profit_dollars = sellprice_each - total_landed_cost;
$('gross_profit_dollars').value = gross_profit_dollars;
$('gross_profit_percent').value = ((gross_profit_dollars / sellprice_each)*100).toFixed(2);
}
new Form.Observer('CostingAddForm', 0.5, buildup());