在下面的代碼中,我想將值打印到兩個部分。獲取唯一的值並使用javascript計算總金額
第一部分是工作良好我有顯示大桶,總價,材料的描述中,代碼等
在第二部分我想顯示獨特的大桶,並從第一部分其量。
第一部: - 工作
Code MaterialDesc Vat Total Price
11 XXX 10% 500
12 yyy 10 % 800
13 zzz 5% 100
第二標段: - 不工作
VAT Amount:
10% 1300
5% 100
<asp:LinkButton ID="lnkPrint" OnClick="lnkPrint_Click" OnClientClick = "return PrintPanel();" runat="server" CommandName="Print"
Text="Print" />
function PrintPanel() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
var today = dd + '/' + mm + '/' + yyyy;
// var map = new Object();
var txtPrint = "";
//txtPrint = '<table><h2 align=\"center\">Food Store</h2><h3 align=center>109,Eswaran Koil street,Puducherry-607001 </h3 ><h4 align=center>Tin No:34310000244, Ph:0413-2227546-49</h4><h5 align=center><U>Cridit Bill</U></h5>';
txtPrint = '<table><h3 align=center>Food Store.</h3 ><h4 align=center>' + currentLocationAddress + '</h4><h5 align=center><U>Cridit Bill</U></h5>';
txtPrint += '<table width=\"100%\"><tr><td width=\"25%\"><b>Customer Name :</b></td><td width=\"25%\">' + currentCustomer + '</td>';
txtPrint += '<td width=\"25%\"><b>Invoice No :</b></td><td width=\"25%\">' + document.getElementById("<%=txtInvoiceNO.ClientID%>").value + '</td></tr></table>';
txtPrint += '<table width=\"100%\"><tr><td width=\"25%\"><b>Address:</b></td><td width=\"25%\">' + currentCustomerAddress + '</td>';
txtPrint += '<td width=\"25%\"><b>Date :</b></td><td width=\"25%\">' + today + '</td></tr></table>';
txtPrint += '<table width=\"36%\"><tr><td width=\"\"20%><b>Phone No:</b></td><td width=\"20%\">' + ContactNo + '</td>';
//txtPrint += '// <td width=\"25%\"><b>TIN :</b></td><td width=\"25%\"></td>'
txtPrint += '</tr></table>';
txtPrint += '</table><BR>';
txtPrint += '<hr width=\"100%\" align=left><table width=\"100%\" cellpadding=2 cellspacing=0><tr>';
txtPrint += '<th width=150px align=center><b> Code</b></th>';
txtPrint += '<th width=50px align=center><b>Barcode</b></th>';
txtPrint += '<th width=\"80%\" align=left><b>Material Description</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>Unit Price</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>VAT(%)</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>Quantity</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>Price</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>VAT Amount</b></th>';
txtPrint += '<th width=\"10%\" align=center><b>Total Price</b></th></tr>';
txtPrint += '<table><table><hr width=\"100%\" align=left>';
$.each(invoiceData, function (i, item) {
var ProductName = GetProductName(item.ProductID);
var UnitPrice = item.UnitPrice;
var ProductCode = item.ProductCode;
var VAT = item.VAT;
var Quantity = item.Quantity; // item.QuantityRequested;
var PriceWithVAT = item.UnitPrice;
var VATAmount = CalcVATAmount(UnitPrice, VAT);
var TotalPrice = item.Total;
var Barcode = GenerateBarcodeImg(ProductCode);
txtPrint += '<table width=\"100%\"><tr><td width=\"10%\" align=left>' + ProductCode + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + imgContent + '</td>';
txtPrint += '<td width=\"40%\" align=center>' + ProductName + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + UnitPrice + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + VAT + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + Quantity + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + PriceWithVAT + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + VATAmount + '</td>';
txtPrint += '<td width=\"10%\" align=center>' + TotalPrice + '</td></tr></table>';
});
txtPrint += '</table></table><hr width=\"100%\" align=left></table>';
txtPrint += '<table width=\"100%\"><tr>';
txtPrint += '<td width=\"85%\" align=right ><b>Invoice Total Value :</b></td><td width=\"15%\" align=center>' + document.getElementById("<%=hidTotalCost.ClientID%>").value + '</td><tr></table>';
var UniqVAT = $.unique(VAT);
txtPrint += '</table><BR>';
txtPrint += '<hr width=\"50%\" align=left><table width=\"50%\" cellpadding=2 cellspacing=0><tr>';
txtPrint += '<th width=10px align=center><b> VAT%</b></th>';
txtPrint += '<th width=10px align=center><b>Amount</b></th>';
txtPrint += '<th width=\"10%\" align=left><b>VAT AMOUNT</b></th>';
txtPrint += '<table><table><hr width=\"50%\" align=left>';
txtPrint += '<table width=\"100%\"><tr><td width=\"10%\" align=left>' + UniqVAT + '</td>';
txtPrint += 'Thanking you,<BR> SVGFPPL.<BR><BR>';
txtPrint += "(Authorised Signatory)";
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<body >');
printWindow.document.write(txtPrint);
printWindow.document.write('</body>');
printWindow.document.close();
setTimeout(function() {
printWindow.print();
}, 500);
return false;
}
我認爲你應該過濾一個你想顯示在數據級別的源而不是在JavaScript中。無論是數據庫還是json數據。這很容易 – FRizal 2015-04-06 11:59:15