Rev 33149 | Rev 33795 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(function () {//Price change handler$(document).on('change', "form#cd input.unitPrice, form#cd input.discount", function () {var $row = $(this).closest('tr'); // Get the closest <tr> parent of the changed inputvar unitPrice = parseFloat($row.find('input.unitPrice').val());if (isNaN(unitPrice)) {unitPrice = 0;}var discount = parseFloat($row.find('input.discount').val());var maxDiscount = parseFloat($row.find('input.discount').data('maxdiscount'));if (isNaN(discount)) {discount = 0;}if (isNaN(maxDiscount)) {maxDiscount = 0;}if (discount > maxDiscount) {alert("Discount can't be greater than max Discount");$row.find('input.discount').val(maxDiscount);$(this).focus();return;}if (unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)) {alert("Invalid unit/discount price");$(this).focus();return;}let lines = $("#order-items").find('tbody>tr:gt(0)').length;if (lines > 3) {calculateTotalAmount($row);} else {calculateTotalAmount();}$row.find('.mk_check_plans').trigger('click', ['manual']); // Trigger the button within the same row});$(document).on('change', "form#cd input.insuranceamount", function () {calculateTotalAmount();});$(document).on('click', ".create-order", function () {checkout("main-content");});$(document).on('click', ".mk_check_plans", function (event, source) {console.log("checkPlansssssss99999");let lines = $("#order-items").find('tbody>tr:gt(0)').length;if (lines > 3) {//No need to check plansreturn;}$('div.itemdetails').find('input').val('');let price = mop;var mop = parseFloat($(this).data("mop"));var sellingPrice = $(this).val();var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");if (!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop) {price = parseFloat(sellingPrice);} else {price = mop;}var poiId = parseFloat($(this).closest("tr").find("input.poiId").val());var discount = parseFloat($(this).closest("tr").find("input.discount").val());if (!isNaN(discount)) {price = price - discount;}let that = this;doGetAjaxRequestHandler(`${context}/checkplans?price=${price}&itemId=${itemId}&poiId=${poiId}`, function (response) {var obj = JSON.parse(response);if (obj != null) {getInsurancePlansModal(obj, that);return;} else {if (typeof source === "undefined") {alert("Product is not eligible for insurance");}}});});});class InsuranceElement extends React.Component {planChecked;constructor(props) {super(props);}render() {console.log(this.props);return <table className="table table-sm"><thead><tr><th>Plan Name</th><th>Duration</th><th>DP</th><th>Selling Price</th><th>Action</th></tr></thead><tbody>{Object.keys(this.props.plans).map((planName, i) =>this.props.plans[planName].map((plan, i) =><tr key={i}><td>{planName}</td><td>{plan.duration}</td><td>{plan.dp}</td><td>{plan.premium}</td><td><button className="btn btn-primary" data-key={plan.productId}data-amount={plan.premium} onClick={this.planChecked}>Add</button></td></tr>))}</tbody></table>;}planChecked = (e) => {debugger;let $itemDetails = $('div.itemdetails');if ($itemDetails.find('.dgram').val() === '') {bootbox.alert('Mobile RAM is required');return;}if ($itemDetails.find('.dgmemory').val() === '') {bootbox.alert('Mobile Memory is required');return;}if ($itemDetails.find('#dgmfgdate').val() === '') {bootbox.alert('Mobile Mfg Date is required');return;}let $orderItemRow = $(this.props.elePlanCheckedOn).closest('td');$orderItemRow.find('.insuranceid').val($(e.target).data('key'));$orderItemRow.find('.insuranceamount').val($(e.target).data('amount'));$orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());$orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());$orderItemRow.find('.mfgdate').val(window.mfgDate);$('#mobilePlansModal').modal('hide');calculateTotalAmount();}}let reactRoot = null;function getInsurancePlansModal(insurancePlans, elePlanCheckedOn) {const domContainer = document.querySelector('.insurancedetails');reactRoot = ReactDOM.createRoot(domContainer);reactRoot.render(<InsuranceElement plans={insurancePlans} elePlanCheckedOn={elePlanCheckedOn}/>)$('#mobilePlansModal').modal({show: true});}function calculateTotalAmount(inputEle) {if (typeof inputEle !== "undefined") {let itemId = $(inputEle).attr("itemid");let unitPrice = inputEle.value;$("#order-items").find(`input.unitPrice[itemid=${itemId}]`).each(function () {this.value = unitPrice;})}var netPayableAmount = 0;var totaInsuranceAmount = 0;$("#order-items").find('tbody>tr:gt(0)').each(function (index, el) {var rowTotal = 0;let $tr = $(el);var insuranceAmount = $tr.find('input.insuranceamount').val();if (isNaN(insuranceAmount)) {insuranceAmount = 0;} else {insuranceAmount = parseFloat(insuranceAmount);}var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));var unitPrice = parseFloat($(el).find('.unitPrice').val());if (isNaN(unitPrice)) {unitPrice = 0;}var discount = $(el).find('.discount').val();if (isNaN(discount)) {discount = 0;}rowTotal = (unitPrice - discount + insuranceAmount) * quantity;$tr.find('.totalPrice').val(rowTotal);netPayableAmount += rowTotal;totaInsuranceAmount += insuranceAmount;});if (totaInsuranceAmount > 0) {$(".mk_insurance_row").show();} else {$(".mk_insurance_row").hide();}$('#cd').find('input.netPayableAmount').val(netPayableAmount);}