- 注册时间
- 2014-2-21
- 最后登录
- 2014-7-25
- 阅读权限
- 10
- 积分
- 49
- 精华
- 0
- 帖子
- 13
|
- <script type="text/javascript">
- mini.parse();
- var grid = mini.get("datagrid1");
- function addGridRow() {
- var newRow = {Name: "", Qty: "", TaxPrice: "", Price: "", DiscountRate: "", RealTaxPrice: "", RealPrice: "", Amount: "", Deduction: "", TaxRate: 17, Tax: "", TaxAmount: "", Amount: "", Description: "", gCode: "" };
- grid.addRow(newRow);
- }
- $(document).ready(function () {
- for (var i = 0; i < 5; i++) {
- addGridRow();
- }
- });
- function onCellBeginEdit(e) {
- var row = grid.getSelected();
- //不含税单价
- if (e.field === "Price") {
- $.ajax({
- url: "?",
- success: function (data) {
- var taxPrice = row["TaxPrice"];
- var taxRate = row["TaxRate"];
- if (taxPrice === "")
- taxPrice = 0;
- if (taxRate === "")
- taxRate = 0;
- var price = taxPrice / (1 + taxRate / 100);
- e.editor.setValue(price.toFixed(4));
- }
- })
- //row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- //grid.getCellEditor(grid.getColumn("Price"), row).setValue(row.Price);
- if (row["DiscountRate"] === "")
- row["DiscountRate"] = 0;
- row.RealTaxPrice = (row["TaxPrice"] * (1 - row["DiscountRate"] / 100)).toFixed(4);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
- row.Deduction = (row["TaxPrice"] * row["Qty"] * (row["DiscountRate"] / 100)).toFixed(2);
- row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.Tax = (row["TaxAmount"] - row["Amount"]).toFixed(2);
- }
- //实际含税单价
- if (e.field === "RealTaxPrice") {
- $.ajax({
- url: "?",
- success: function (data) {
- row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- var taxPrice = row["TaxPrice"];
- var discountRate = row["DiscountRate"];
- if (taxPrice === "")
- taxPrice = 0;
- if (discountRate === "")
- discountRate = 0;
- var price = taxPrice * (1 - discountRate / 100);
- e.editor.setValue(price.toFixed(4));
- row.RealTaxPrice = price.toFixed(4);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
- row.Deduction = (row["TaxPrice"] * row["Qty"] * (row["DiscountRate"] / 100)).toFixed(2);
- row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.Tax = (row["TaxAmount"] - row["Amount"]).toFixed(2);
- }
- })
- }
- //折扣额
- if (e.field === "Deduction") {
- $.ajax({
- async: false,
- url: "?",
- success: function (data) {
- var taxPrice = row["TaxPrice"];
- var dRate = row["DiscountRate"];
- var qty = row["Qty"];
- if (taxPrice === "")
- taxPrice = 0;
- if (dRate === "")
- dRate = 0;
- if (qty === "")
- qty = 0;
- var price = taxPrice * qty * (dRate / 100);
- e.editor.setValue("");
- e.editor.setValue(price.toFixed(2));
- row.Deduction = price.toFixed(2);
- }
- })
- }
- //税额
- if (e.field === "Tax") {
- //Price
- row.Price = (row["TaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- if (row["DiscountRate"] === "")
- row["DiscountRate"] = 0;
- row.RealTaxPrice = (row["TaxPrice"] * (1 - row["DiscountRate"] / 100)).toFixed(4);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.RealPrice = (row["RealTaxPrice"] / (1 + row["TaxRate"] / 100)).toFixed(4);
- row.Amount = (row["RealPrice"] * row["Qty"]).toFixed(2);
- row.Deduction = ((row["TaxPrice"] - row["RealTaxPrice"]) * row["Qty"]).toFixed(2);
- if (row["TaxRate"] === "")
- row["TaxRate"] = 0;
- row.TaxAmount = (row["Qty"] * row["RealTaxPrice"]).toFixed(2);
- $.ajax({
- url: "?",
- success: function (data) {
- var amount = row["Amount"];
- var taxAmount = row["TaxAmount"];
- if (amount === "")
- amount = 0;
- if (taxAmount === "")
- taxAmount = 0;
- var price = taxAmount - amount;
- e.editor.setValue(price.toFixed(2));
- }
- })
- }
- //价税合计
- if (e.field === "TaxAmount") {
- $.ajax({
- url: "?",
- success: function (data) {
- var qty = row["Qty"];
- var rtp = row["RealTaxPrice"];
- if (qty === "")
- qty = 0;
- if (rtp === "")
- rtp = 0;
- var taxAmount = (rtp * qty).toFixed(2);
- e.editor.setValue(taxAmount);
- }
- })
- }
- }
- function onCellEndEdit(e) {
- var row = grid.getSelected();
- if (e.field === "TaxRate") {
- if (e.value !== 17) {
- }
- }
- }
- function EnterAdd(e) {
- if (e.source.ownerRowID == grid.getData().length - 1) {
- addGridRow();
- }
- }
- </script>
复制代码 |
|