lightswitch html - 总量未计算
lightswitch html - total amount not calculating
我正在尝试在 lightswitch html 中构建一个简单的 p.o.s 条目。我的问题是总金额计算不正确。我对这一切 javascript 和 lightswitch 都是新手所以请原谅我的天真。
我在我的 "updateTotal function" 中插入了一个断点 我显然遇到的问题是,一旦我单击 addsales 详细信息(当还没有数据时),它就会调用 updateTotal 函数。需要做的是它应该在我选择产品后调用 updateTotal。
我做错了什么?
下面是我写的代码。有谁能够帮助我?
myapp.AddEditSalesHeader.created = 函数(屏幕){
// Write code here.
//Set the default values of the following fields.
screen.SalesHeader.InvoiceNo = "(Auto Invoice #)";
var vTime = new Date();
screen.SalesHeader.InvoiceTime = vTime;
screen.SalesHeader.ModePmt = "CASH";
screen.SalesHeader.Shipment = "PICK-UP";
screen.SalesHeader.PerDiscount = 0;
screen.SalesHeader.TotalDiscount = 0;
screen.SalesHeader.NetAmount = 0;
screen.SalesHeader.AmountReturn = 0;
screen.SalesHeader.CashReceived = 0;
screen.SalesHeader.ChangeDue = 0;
screen.findContentItem("InvoiceNo").isReadOnly = true;
screen.findContentItem("InvoiceDate").isReadOnly = true;
screen.findContentItem("TotalAmount").isReadOnly = true;
screen.findContentItem("NetAmount").isReadOnly = true;
};
myapp.AddEditSalesHeader.PerDiscount_postRender = function (element, contentItem) {
//Compute TotalAmount & NetAmount when PerDiscount value is entered
contentItem.dataBind("value",
function (PerDiscount) {
var vADisc = contentItem.screen.SalesHeader.TotalAmount * (PerDiscount / 100);
contentItem.screen.SalesHeader.TotalDiscount = vADisc;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - vADisc;
});
};
myapp.AddEditSalesHeader.TotalAmount_postRender = function (element, contentItem) {
function updateTotal() {
var InvDetail = contentItem.screen.SalesDetails.data;
var AmtDetail = 0;
InvDetail.forEach(function (sales) {
if (isNaN(sales.Amount)) {
AmtDetail = 0;
}
else {
//Update the TotalAmount
AmtDetail = AmtDetail + sales.Amount;
}
})
//Display the TotalAmount
contentItem.screen.SalesHeader.TotalAmount = AmtDetail;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount
- contentItem.screen.SalesHeader.TotalDiscount;
}
//Set up a databind on screen.SaleDetails.count
contentItem.dataBind("screen.SalesDetails.count", function () {
updateTotal();}
);
}
myapp.AddEditSalesHeader.TotalDiscount_postRender = function (element, contentItem) {
// Write code here.
//Compute PerDiscount & NetAmount when the TotalDiscount value is entered
contentItem.dataBind("value",
function (TotalDiscount) {
if (TotalDiscount > 0) {
contentItem.screen.SalesHeader.PerDiscount = (TotalDiscount / contentItem.screen.SalesHeader.TotalAmount) * 100;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - TotalDiscount;
}
else {
contentItem.screen.SalesHeader.PerDiscount = 0;
}
});
};
myapp.AddEditSalesHeader.InvTime_postRender = function (element, contentItem) {
// Write code here.
this.setInterval(
function () {
var currentTime = new Date();
$(element).text(currentTime.toLocaleTimeString());
},
1000
);
};
//function CallGetTotAmt(operation) {
// $.ajax({
// type: 'post',
// data: {},
// url: '../Web/GetTotAmount.ashx',
// success: operation.code(function AjaxSuccess(AjaxResult) {
// operation.complete(AjaxResult);
// })
// });
//}
myapp.AddEditSalesHeader.Details_postRender = function (element, contentItem) {
// Write code here.
//Hide the save command button
$("[data-ls-tap='tap:{data.shell.saveCommand.command}']").hide();
//Hide the discard command button
$("[data-ls-tap='tap:{data.shell.discardCommand.command}']").hide();
};
myapp.AddEditSalesHeader.Cancel_execute = function (screen) {
// Write code here.
msls.showMessageBox("Close transaction? Closing will cause any unsaved changes to be discarded.", {
title: "System Advisory",
buttons: msls.MessageBoxButtons.yesNo
})
.then(function (result) {
if (result === msls.MessageBoxResult.yes) {
myapp.cancelChanges();
}
});
};
myapp.AddEditSalesHeader.Save_execute = function (screen) {
// Write code here.
//Get the total data in SalesHeader
myapp.activeDataWorkspace.ApplicationData.SalesHeaders.includeTotalCount().execute().then(function (result) {
var varInvNo = AutoInvNo(result);
//Set InvoiceNo before saving
screen.SalesHeader.InvoiceNo = varInvNo;
var InvDetail = screen.SalesDetails.data;
var varStock = 0;
InvDetail.forEach(function (entity) {
//Update ProductFile StockOnHand that have products in SalesDetail
varStock = entity.ProductFile.StockOnHand - entity.Quantity;
entity.ProductFile.StockOnHand = varStock;
entity.ProductFile.TranCode = "O";
entity.InvoiceNo = varInvNo;
})
myapp.commitChanges().then(null, function fail(e) {
msls.showMessageBox(e.message, { title: e.title }).then(function () {
screen.SalesHeader.InvoiceNo = "(Auto Invoice #)";
throw e;
});
});
});
};
//Utility
function AutoInvNo(InvNo) {
var InvNumber = 1;
var Entities = InvNo.results;
//Count the total data in SalesHeader
Entities.forEach(function (entity) {
InvNumber = InvNumber + 1;
});
//Return InvNumber value
return InvNumber;
};
myapp.AddEditSalesHeader.Print_execute = function (screen) {
// Write code here.
var LoadingDiv = $("<div></div>");
var Loading = $("<h1> Loading Report...</h1>");
Loading.appendTo(LoadingDiv);
LoadingDiv.appendTo($(element));
// Get Report
var HTMLContent = $("<div></div>").html(
"<object width='650px' height='650px' data='../Reports/BranchSalesReport.rdlc'/>"
);
// Make report appear on top of the Loading message
HTMLContent.css({
"margin-top": "-50px"
});
HTMLContent.appendTo($(element));
}
这会解决你的问题:我所做的就是将时间间隔添加到底部的代码中,这样它就知道要多次检查总数... post 渲染函数只被调用一次通常这样里面的函数实际上并没有被调用。
function updateTotal() {
var InvDetail = contentItem.screen.SalesDetails.data;
var AmtDetail = 0;
InvDetail.forEach(function (sales) {
if (isNaN(sales.Amount)) {
AmtDetail = 0;
}
else {
//Update the TotalAmount
AmtDetail = AmtDetail + sales.Amount;
}
})
//Display the TotalAmount
contentItem.screen.SalesHeader.TotalAmount = AmtDetail;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount
- contentItem.screen.SalesHeader.TotalDiscount;
}
this.setInterval(
function () {
//Set up a databind on screen.SaleDetails.count
contentItem.dataBind("screen.SalesDetails.count", updateTotal);
},1000);
下面的代码解决了 Amt Discount 和 Net Amount 中的 NaN:
myapp.AddEditSalesHeader.TotalDiscount_postRender = function (element, contentItem) {
// Write code here.
//Compute PerDiscount & NetAmount when the TotalDiscount value is entered
contentItem.dataBind("value",
function () {
if (contentItem.value > 0) {
contentItem.screen.SalesHeader.PerDiscount = (contentItem.value / contentItem.screen.SalesHeader.TotalAmount) * 100;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - contentItem.value;
}
else {
contentItem.value = 0;
}
});
};
我正在尝试在 lightswitch html 中构建一个简单的 p.o.s 条目。我的问题是总金额计算不正确。我对这一切 javascript 和 lightswitch 都是新手所以请原谅我的天真。
我在我的 "updateTotal function" 中插入了一个断点 我显然遇到的问题是,一旦我单击 addsales 详细信息(当还没有数据时),它就会调用 updateTotal 函数。需要做的是它应该在我选择产品后调用 updateTotal。
我做错了什么?
下面是我写的代码。有谁能够帮助我? myapp.AddEditSalesHeader.created = 函数(屏幕){
// Write code here.
//Set the default values of the following fields.
screen.SalesHeader.InvoiceNo = "(Auto Invoice #)";
var vTime = new Date();
screen.SalesHeader.InvoiceTime = vTime;
screen.SalesHeader.ModePmt = "CASH";
screen.SalesHeader.Shipment = "PICK-UP";
screen.SalesHeader.PerDiscount = 0;
screen.SalesHeader.TotalDiscount = 0;
screen.SalesHeader.NetAmount = 0;
screen.SalesHeader.AmountReturn = 0;
screen.SalesHeader.CashReceived = 0;
screen.SalesHeader.ChangeDue = 0;
screen.findContentItem("InvoiceNo").isReadOnly = true;
screen.findContentItem("InvoiceDate").isReadOnly = true;
screen.findContentItem("TotalAmount").isReadOnly = true;
screen.findContentItem("NetAmount").isReadOnly = true;
};
myapp.AddEditSalesHeader.PerDiscount_postRender = function (element, contentItem) {
//Compute TotalAmount & NetAmount when PerDiscount value is entered
contentItem.dataBind("value",
function (PerDiscount) {
var vADisc = contentItem.screen.SalesHeader.TotalAmount * (PerDiscount / 100);
contentItem.screen.SalesHeader.TotalDiscount = vADisc;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - vADisc;
});
};
myapp.AddEditSalesHeader.TotalAmount_postRender = function (element, contentItem) {
function updateTotal() {
var InvDetail = contentItem.screen.SalesDetails.data;
var AmtDetail = 0;
InvDetail.forEach(function (sales) {
if (isNaN(sales.Amount)) {
AmtDetail = 0;
}
else {
//Update the TotalAmount
AmtDetail = AmtDetail + sales.Amount;
}
})
//Display the TotalAmount
contentItem.screen.SalesHeader.TotalAmount = AmtDetail;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount
- contentItem.screen.SalesHeader.TotalDiscount;
}
//Set up a databind on screen.SaleDetails.count
contentItem.dataBind("screen.SalesDetails.count", function () {
updateTotal();}
);
}
myapp.AddEditSalesHeader.TotalDiscount_postRender = function (element, contentItem) {
// Write code here.
//Compute PerDiscount & NetAmount when the TotalDiscount value is entered
contentItem.dataBind("value",
function (TotalDiscount) {
if (TotalDiscount > 0) {
contentItem.screen.SalesHeader.PerDiscount = (TotalDiscount / contentItem.screen.SalesHeader.TotalAmount) * 100;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - TotalDiscount;
}
else {
contentItem.screen.SalesHeader.PerDiscount = 0;
}
});
};
myapp.AddEditSalesHeader.InvTime_postRender = function (element, contentItem) {
// Write code here.
this.setInterval(
function () {
var currentTime = new Date();
$(element).text(currentTime.toLocaleTimeString());
},
1000
);
};
//function CallGetTotAmt(operation) {
// $.ajax({
// type: 'post',
// data: {},
// url: '../Web/GetTotAmount.ashx',
// success: operation.code(function AjaxSuccess(AjaxResult) {
// operation.complete(AjaxResult);
// })
// });
//}
myapp.AddEditSalesHeader.Details_postRender = function (element, contentItem) {
// Write code here.
//Hide the save command button
$("[data-ls-tap='tap:{data.shell.saveCommand.command}']").hide();
//Hide the discard command button
$("[data-ls-tap='tap:{data.shell.discardCommand.command}']").hide();
};
myapp.AddEditSalesHeader.Cancel_execute = function (screen) {
// Write code here.
msls.showMessageBox("Close transaction? Closing will cause any unsaved changes to be discarded.", {
title: "System Advisory",
buttons: msls.MessageBoxButtons.yesNo
})
.then(function (result) {
if (result === msls.MessageBoxResult.yes) {
myapp.cancelChanges();
}
});
};
myapp.AddEditSalesHeader.Save_execute = function (screen) {
// Write code here.
//Get the total data in SalesHeader
myapp.activeDataWorkspace.ApplicationData.SalesHeaders.includeTotalCount().execute().then(function (result) {
var varInvNo = AutoInvNo(result);
//Set InvoiceNo before saving
screen.SalesHeader.InvoiceNo = varInvNo;
var InvDetail = screen.SalesDetails.data;
var varStock = 0;
InvDetail.forEach(function (entity) {
//Update ProductFile StockOnHand that have products in SalesDetail
varStock = entity.ProductFile.StockOnHand - entity.Quantity;
entity.ProductFile.StockOnHand = varStock;
entity.ProductFile.TranCode = "O";
entity.InvoiceNo = varInvNo;
})
myapp.commitChanges().then(null, function fail(e) {
msls.showMessageBox(e.message, { title: e.title }).then(function () {
screen.SalesHeader.InvoiceNo = "(Auto Invoice #)";
throw e;
});
});
});
};
//Utility
function AutoInvNo(InvNo) {
var InvNumber = 1;
var Entities = InvNo.results;
//Count the total data in SalesHeader
Entities.forEach(function (entity) {
InvNumber = InvNumber + 1;
});
//Return InvNumber value
return InvNumber;
};
myapp.AddEditSalesHeader.Print_execute = function (screen) {
// Write code here.
var LoadingDiv = $("<div></div>");
var Loading = $("<h1> Loading Report...</h1>");
Loading.appendTo(LoadingDiv);
LoadingDiv.appendTo($(element));
// Get Report
var HTMLContent = $("<div></div>").html(
"<object width='650px' height='650px' data='../Reports/BranchSalesReport.rdlc'/>"
);
// Make report appear on top of the Loading message
HTMLContent.css({
"margin-top": "-50px"
});
HTMLContent.appendTo($(element));
}
这会解决你的问题:我所做的就是将时间间隔添加到底部的代码中,这样它就知道要多次检查总数... post 渲染函数只被调用一次通常这样里面的函数实际上并没有被调用。
function updateTotal() {
var InvDetail = contentItem.screen.SalesDetails.data;
var AmtDetail = 0;
InvDetail.forEach(function (sales) {
if (isNaN(sales.Amount)) {
AmtDetail = 0;
}
else {
//Update the TotalAmount
AmtDetail = AmtDetail + sales.Amount;
}
})
//Display the TotalAmount
contentItem.screen.SalesHeader.TotalAmount = AmtDetail;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount
- contentItem.screen.SalesHeader.TotalDiscount;
}
this.setInterval(
function () {
//Set up a databind on screen.SaleDetails.count
contentItem.dataBind("screen.SalesDetails.count", updateTotal);
},1000);
下面的代码解决了 Amt Discount 和 Net Amount 中的 NaN:
myapp.AddEditSalesHeader.TotalDiscount_postRender = function (element, contentItem) {
// Write code here.
//Compute PerDiscount & NetAmount when the TotalDiscount value is entered
contentItem.dataBind("value",
function () {
if (contentItem.value > 0) {
contentItem.screen.SalesHeader.PerDiscount = (contentItem.value / contentItem.screen.SalesHeader.TotalAmount) * 100;
contentItem.screen.SalesHeader.NetAmount = contentItem.screen.SalesHeader.TotalAmount - contentItem.value;
}
else {
contentItem.value = 0;
}
});
};