
PK 
var count = 1;
$(document).ready(function() {
/* $("#plotrange").on("change",function() {
var start_plotrange= $("#start_plotrange").val();
var end_plotrange= $("#end_plotrange").val();
});*/
$("#addButton").click(function() {
var selectblock = $('#block');
if (selectblock.val() === '') {
alert("Please select any block and then proceed.");
$('#block').focus();
return false;
}
//$('#ppsize'+ count).empty('');
var plotsize= $("#plotsize").val();
/* var start_plotrange= $("#start_plotrange").val();
var end_plotrange= $("#end_plotrange").val();*/
var array = plotsize.split(',');
//console.log(array);
if (count >50) {
alert("Only 50 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div'));
//.attr("id", 'TextBoxDiv' + count);
newTextBoxDiv.attr({
id : "TextBoxDiv"+count,
"class" : "plot-add-bx"
});
$('<option value="">Select Block</option>').appendTo('#qty'+ count);
var poption="";
for (var i = 0; i < array.length; i++) {
poption+='<option value="'+array[i]+'">'+array[i]+'</option>';
}
var facingoption="";
facingoption+= '<option value="">Select Facing</option>'
+
'<option value="north">north</option>'
+
'<option value="south">south</option>'
+
'<option value="east">east</option>'
+
'<option value="west">west</option>';
var blockname="";
blockname+= '<option value="">Select Block</option>'
+
'<option value="A">A</option>'
+
'<option value="B">B</option>'
+
'<option value="C">C</option>'
+
'<option value="D">D</option>';
//console.log(poption);
newTextBoxDiv.after().html(
'<div>'+count+'</div>\n\
' +
'<div class="plot-input"><input type="text" size="2" name="plotno[]" id="plotno' + count + '" value="" class="form-control plot-size" placeholder="Plot No" required></div>\n\
' +
'<div class="plot-input"><input type="text" name="qty[]" id="qty'+count+'" value="" class="form-control plot-size" placeholder="Plot Size" required></div>\n\
' +
'<div class="plot-input" style="display:none;"><input type="hidden" name="tprice[]" id="tprice' + count + '" value="" class="form-control plot-size" READONLY></div>\n\
' +
'<div class="plot-input"><input type="number" name="plccf[]" id="plccf' + count + '" value="0" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input"><input type="number" name="plcpf[]" id="plcpf' + count + '" value="0" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input"><input type="number" name="plcrf[]" id="plcrf' + count + '" value="0" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input"><input type="number" name="discount[]" id="discount' + count + '" value="0" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input"><input type="number" name="total[]" id="total' + count + '" value="0" class="form-control plot-size"READONLY></div>\n\
' +
'<div class="plot-input" style="display:none;"><input type="number" name="price[]" id="price' + count + '" value="" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input" style="display:none;"><input type="hidden" name="discountedamt[]" id="discountedamt' + count + '" value="" class="form-control plot-size"></div>\n\
' +
'<div class="plot-input" style="display:none;"><input type="number" name="cam[]" id="cam' + count + '" value="" class="form-control plot-size""></div>\n\
'+
'<div class="plot-input"><select name="blockname[]" id="blockname' +count+'" value="" class="form-control plot-size" placeholder="Select Block" required>'+blockname+'</select></div>\n\
' +
'<div class="plot-input"><select name="facing[]" id="facing' +count+'" value="" class="form-control plot-size" placeholder="Select Facing" required>'+facingoption+'</select></div>\n\
' +
'<div class="plot-input"><input type="text" name="north[]" id="north' + count + '" value="" class="form-control plot-size" placeholder="North"></div>\n\
' +
'<div class="plot-input"><input type="text" name="south[]" id="south' + count + '" value="" class="form-control plot-size" placeholder="South"></div>\n\
' +
'<div class="plot-input"><input type="text" name="east[]" id="east' + count + '" value="" class="form-control plot-size" placeholder="East" ></div>\n\
' +
'<div class="plot-input"><input type="text" name="west[]" id="west' + count + '" value="" class="form-control plot-size" placeholder="West"></div>'
);
newTextBoxDiv.appendTo("#TextBoxesGroup");
$("input[name^='plotno']").change( function() {
// check input ($(this).val()) for validity here
var valueOfChangedInput = $(this).val();
var timeRepeated = 0;
$("input[name^='plotno']").each(function () {
//Inside each() check the 'valueOfChangedInput' with all other existing input
if ($(this).val() == valueOfChangedInput ) {
timeRepeated++; //this will be executed at least 1 time because of the input, which is changed just now
}
});
if(timeRepeated > 1) {
alert("Duplicate value found !");
$(this).css('border-color','#F00');
$(this).val('');
}
});
$('#plotno' + count).on("change", function() {
if($(this).val()<=0){
alert("Please Enter Valid Plot No");
$(this).css('border-color','#F00');
$(this).val('');
}else{
$(this).css('border-color','');
//calculate($(this));
}
});
$('#qty' + count).on("change", function() {
//var prsize = $(this).val();
var start_plotrange= $("#start_plotrange").val();
var end_plotrange= $("#end_plotrange").val();
if((parseFloat($(this).val()) < parseFloat(start_plotrange))|| (parseFloat($(this).val()) > parseFloat(end_plotrange))){
alert("Please Enter Valid Plot Size");
$(this).css('border-color','#F00');
$(this).val('');
//$(this).focus();
}else{
$(this).css('border-color','');
//calculate($(this));
calculateSalePrice($(this),$(this).val(),'plot_size');
}
});
$('#plccf' + count).on("change", function() {
//calculate($(this));
calculateSalePrice($(this),$(this).val(),'plc_corner_facing');
});
$('#plcpf' + count).on("change", function() {
//calculate($(this));
calculateSalePrice($(this),$(this).val(),'plc_park_facing');
});
$('#plcrf' + count).on("change", function() {
//calculate($(this));
calculateSalePrice($(this),$(this).val(),'plc_road_facing');
});
$('#discount' + count).on("change", function() {
//alert($(this).val()+"::"+$(this).attr('id'));
calculateSalePrice($(this),$(this).val(),'discountt');
//console.log('discount: '+$(this).val());
});
$('#price' + count).on("change",function(){
calculate($(this));
});
$('#edcm' + count).on("change", function(e) {
calculate($(this));
});
$('#tax_per' + count).on("change", function() {
//calculate($(this));
});
count++;
}); //closing the addButton function
//To caluculate Total amount based on edc and tax percentage
function calculateSalePrice(el,val,id){
var count = el.attr("id").indexOf("qty") != -1 ? el.attr("id").substring(3) : el.attr("id").substring(5); //alert(count);
if(id=='discountt'){
count = count.replace("unt", "");
}
var plot_size = isNaN(parseFloat($('#qty' + count).val())) ? 0 : parseFloat($('#qty' + count).val());//alert(plot_size);
var plc_corner_facing = isNaN(parseFloat($('#plccf' + count).val())) ? 0 : parseFloat($('#plccf' + count).val());
var plc_park_facing = isNaN(parseFloat($('#plcpf' + count).val())) ? 0 : parseFloat($('#plcpf' + count).val());
var plc_road_facing = isNaN(parseFloat($('#plcrf' + count).val())) ? 0 : parseFloat($('#plcrf' + count).val());
var discount = isNaN(parseFloat($('#discount' + count).val())) ? 0 : parseFloat($('#discount' + count).val());
switch(id){
case 'plot_size':
plot_size = val;
break;
case 'plc_corner_facing':
plc_corner_facing = val;
break;
case 'plc_park_facing':
plc_park_facing = val;
break;
case 'plc_road_facing':
plc_road_facing = val;
break;
case 'discountt':
discount = val; //alert('discount: '+discount);
break;
default:
break;
}
var cpfm = $("#cpmfrate").data("cpmfrate"); //alert('cpfm'+cpfm);
var base_price = Math.ceil(plot_size*cpfm); //alert('base_price'+base_price);
$("#tprice" + count).val(base_price);
var plc = Math.ceil(((base_price*plc_corner_facing)/100)) +
Math.ceil(((base_price*plc_park_facing)/100)) +
Math.ceil(((base_price*plc_road_facing)/100)); //alert(plc)
var discounted_plc = Math.ceil(plc - (plc*discount)/100);
var sale_price = Math.ceil(base_price + discounted_plc);
$("#total" + count).val(sale_price);
$("#discountedamt" + count).val(discounted_plc);
/* console.log('base_price: '+base_price);
console.log('plc: '+plc);
console.log('discounted_plc: '+discounted_plc);
console.log('sale_price: '+sale_price);
console.log('---------------------')*/
}
//To remove the added textboxes
$("#removeButton").click(function() {
if (count == 0) {
alert("No more textbox to remove");
return false;
}
count--;
$("#TextBoxDiv" + count).remove();
});
});


PK 99