fourcal/src/main/resources/static/assets/js/project_budget_income.js

285 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 一个收入详情的字段
*/
//INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
INCOME_DETAIL2 = {
"num": [false, "序号", "string"],
"type": [false, "类别", "string"],
"name": [false, "产品大类", "string"],
"taxRate": [false, "税率", "number"],
"totalTaxInclude": [false, "含税总金额", "number"],
"totalTaxExclude": [false, "不含税金额", "number"],
"totalTax": [false, "税金", "number"]
};
INCOME_DETAIL = {
"num": [false, "序号", "string"],
"type": [false, "类别", "string"],
"name": [false, "产品大类", "string"],
"taxRate": [false, "税率", "number"],
"totalTaxInclude": [false, "含税总金额", "number"],
"totalTaxExclude": [false, "不含税金额", "number"],
"totalTax": [false, "税金", "number"]
};
/*$(function () {
$("#income-detail").click(function () {
$('#my-prompt-income-detail').modal({
relatedTarget: this,
closeOnConfirm:false,
onConfirm: function(e) {
//不能使用e.data因为无法获取动态添加的
var data = collectData("am-modal-prompt-input-income");
//data = prepareAjaxData(data, INCOME_DETAIL_ARR, $("#id").val(),false);
data = prepareAjaxDataVerify(data, INCOME_DETAIL, $("#id").val());
if(data.details){
postAjax(base+"/project/budgetEditSaveIncomeDetail", data, updateIncomeData);
}
},
onCancel: function(e) {
}
});
});
$("#incomeAddBtn").click(function () {
appendTrIncome();
});
});*/
$(function () {
$("#income-detail").click(function () {
$('#my-prompt-income-detail').modal({
relatedTarget: this,
closeOnConfirm: false,
onConfirm: function (e) {
//不能使用e.data因为无法获取动态添加的
var data = collectData("am-modal-prompt-input-income");
//data = prepareAjaxData(data, INCOME_DETAIL_ARR, $("#id").val(),false);
data = prepareAjaxDataVerify(data, INCOME_DETAIL2, $("#id").val());
if (data.details) {
postAjax(base + "/project/budgetEditSaveIncomeDetail", data, updateIncomeData);
}
},
onCancel: function (e) {
}
});
});
});
//保存收入明细表
$(function () {
$("#incomeTableSave").click(function () {
var data = collectData("am-modal-prompt-input-income");
data = prepareAjaxDataVerify(data, INCOME_DETAIL2, $("#id").val());
if (data.details) {
postAjax(base + "/project/budgetEditSaveIncomeDetail", data, updateIncomeData);
}
});
$("#incomeAddBtn").click(function () {
appendTrIncome();
$("#incomeAddBtn").blur();
});
bindTypeSelectChangeIncome()
});
/**
* 更新页面收入的数据【累加】
*/
function updateIncomeData(data, returnData) {
var incomeDetails = data.details;
var deviceTaxInclude = 0;
var deviceTaxExclude = 0;
var deviceTax = 0;
var engineerTaxInclude = 0;
var engineerTaxExclude = 0;
var engineerTax = 0;
var serviceTaxInclude = 0;
var serviceTaxExclude = 0;
var serviceTax = 0;
var incomeTaxRates = "";
var set = new Set();
incomeDetails.forEach(function (t, number, ts) {
console.log("income income " + t["type"] + ", " + t["taxRate"] + ", " + t["totalTaxInclude"] + ", " + t["totalTaxExclude"]);
if (t["type"] == "1") {
//设备类
deviceTaxInclude += f2(t["totalTaxInclude"]);
deviceTaxExclude += f2(t["totalTaxExclude"]);
deviceTax += f2(t["totalTax"]);
} else if (t["type"] == "2") {
//工程类
engineerTaxInclude += f2(t["totalTaxInclude"]);
engineerTaxExclude += f2(t["totalTaxExclude"]);
engineerTax += f2(t["totalTax"]);
} else if (t["type"] == "3") {
//服务类
serviceTaxInclude += f2(t["totalTaxInclude"]);
serviceTaxExclude += f2(t["totalTaxExclude"]);
serviceTax += f2(t["totalTax"]);
}
if (!set.has(t["taxRate"])) {
incomeTaxRates += f2Fixed(t["taxRate"]) + "%,";
set.add(t["taxRate"]);
}
});
console.log("incomeTaxRates: " + incomeTaxRates);
$("input[name='incomeDeviceTaxInclude']").val(f2Fixed(deviceTaxInclude));
$("input[name='incomeDeviceTaxExclude']").val(f2Fixed(deviceTaxExclude));
$("input[name='incomeDeviceTax']").val(f2Fixed(deviceTax));
$("input[name='incomeEngineerTaxInclude']").val(f2Fixed(engineerTaxInclude));
$("input[name='incomeEngineerTaxExclude']").val(f2Fixed(engineerTaxExclude));
$("input[name='incomeEngineerTax']").val(f2Fixed(engineerTax));
$("input[name='incomeServiceTaxInclude']").val(f2Fixed(serviceTaxInclude));
$("input[name='incomeServiceTaxExclude']").val(f2Fixed(serviceTaxExclude));
$("input[name='incomeServiceTax']").val(f2Fixed(serviceTax));
$("input[name='incomeTotalTaxInclude']").val(f2Fixed(deviceTaxInclude + engineerTaxInclude + serviceTaxInclude));
$("input[name='incomeTotalTaxExclude']").val(f2Fixed(deviceTaxExclude + engineerTaxExclude + serviceTaxExclude));
$("input[name='incomeTotalTax']").val(f2Fixed(deviceTax + engineerTax + serviceTax));
$("input[name='costCompanyManageTaxExclude']").val(f2Fixed(0.028 * (deviceTaxExclude + engineerTaxExclude + serviceTaxExclude)));
// $(".input-total-title-sale-income-budget-plan").val($("input[name='incomeTotalTaxInclude']").val());
// $(".input-total-title-total-income-budget-plan").val(f2Fixed(f2($("input[name='incomeTotalTaxInclude']").val())
// + f2($(".input-total-title-earnest-money-income-budget-plan").val())));
updateProjectContributionProfitRate();
if (incomeTaxRates.length > 0) {
$(".incomeTaxRates").text(incomeTaxRates.substr(0, incomeTaxRates.length - 1));
}
layuiAlert("保存成功");
$('#my-prompt-income-detail').modal('close');
}
/**
* 收入明细增加一行
*/
function appendTrIncome(dataRow) {
var template = '<tr class="incomeaddtr">\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-budget-num" readonly></td>\n' +
' <td width="100px">\n' +
' <select style="float: left;" class="am-modal-prompt-input am-modal-prompt-input-income am-modal-prompt-input-income-type">\n' +
' <option value="1">设备类</option>\n' +
' <option value="2">工程类</option>\n' +
' <option value="3">服务类</option>\n' +
' </select>\n' +
' </td>' +
'<td>' +
'<select style="float: left;" class="am-modal-prompt-input am-modal-prompt-input-income am-modal-prompt-input-income-category input-changeable-tax-rate-income-select">' +
'<option value="华智产品">华智产品 </option> <option value="华三产品">华三产品 </option><option value="汇智产品"> 汇智产品</option><option value="自定义">自定义</option>' +
'<input type="hidden" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate-income-name">' +
'</select>' +
'</td>' +
' <td><input type="text" min="0.00" max="99.99" step="0.01" maxlength="5" class="number am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate input-changeable-tax-rate-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-include input-changeable-total-tax-include-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-exclude input-changeable-total-tax-exclude-income" readonly></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax input-changeable-total-tax-income" readonly></td>\n' +
' <td><button type="button" style="margin-top: 10px" class="am-btn am-btn-danger am-btn-xs am-round am-modal-line-delete"><span class="am-icon-minus"></span></button></td>\n' +
' </tr>';
$("#incomeTotal").before(template);
//重新绑定删除事件和input修改事件
bindDeleteBtnIncome();
bindNum();
bindChangeableInput();
bindIncomeTotal();
bindTypeSelectChangeIncome()
//绑定数字输入框保留两位小数
bindNumberInput();
if ($('#incomeTable').find('tbody') && $('#incomeTable').find('tbody')[0]) {
$('#incomeTable').find('tbody')[0].scrollTop = $('#incomeTable').find('tbody')[0].scrollHeight
}
if(dataRow.type){
initRowData(dataRow)
}
}
/**
* 绑定每一行的删除事件删除当前的一行tr修改总计值
*/
function bindDeleteBtnIncome() {
$(".am-modal-line-delete").click(function () {
//删除自己对应的tr
$(this).parent().parent().remove();
bindNum();
updateAmount("input-changeable-amount-income", "input-changeable-total-amount-income");
updateTotal("input-changeable-total-tax-include-income", "input-changeable-total-total-tax-include-income");
updateTotal("input-changeable-total-tax-exclude-income", "input-changeable-total-total-tax-exclude-income");
updateTotal("input-changeable-total-tax-income", "input-changeable-total-total-tax-income");
});
}
/**
* 绑定每个可改变的输入框,修改后改变对应输入框的值
*/
function bindIncomeTotal() {
//数量改变
$(".input-changeable-amount-income").change(function () {
updateAmount("input-changeable-amount-income", "input-changeable-total-amount-income");
updateTotal("input-changeable-total-tax-include-income", "input-changeable-total-total-tax-include-income");
updateTotal("input-changeable-total-tax-exclude-income", "input-changeable-total-total-tax-exclude-income");
updateTotal("input-changeable-total-tax-income", "input-changeable-total-total-tax-income");
});
//单价改变
$(".input-changeable-price-income").change(function () {
updateTotal("input-changeable-total-tax-include-income", "input-changeable-total-total-tax-include-income");
updateTotal("input-changeable-total-tax-exclude-income", "input-changeable-total-total-tax-exclude-income");
updateTotal("input-changeable-total-tax-income", "input-changeable-total-total-tax-income");
});
//税率改变
$(".input-changeable-tax-rate-income").change(function () {
updateTotal("input-changeable-total-tax-exclude-income", "input-changeable-total-total-tax-exclude-income");
updateTotal("input-changeable-total-tax-income", "input-changeable-total-total-tax-income");
});
$(".input-changeable-total-tax-include-income").change(function () {
updateTotal("input-changeable-total-tax-include-income", "input-changeable-total-total-tax-include-income");
updateTotal("input-changeable-total-tax-exclude-income", "input-changeable-total-total-tax-exclude-income");
updateTotal("input-changeable-total-tax-income", "input-changeable-total-total-tax-income");
});
}
function bindTypeSelectChangeIncome() {
//大类变化联动类别
$(".input-changeable-tax-rate-income-select").on('change', function () {
var nameSelect = $(this).parent().parent().find(".input-changeable-tax-rate-income-select");
var nameInput = $(this).parent().parent().find(".input-changeable-tax-rate-income-name");
var type = $(this).val();
if (type == '自定义') {
nameSelect.attr("style", "display:none");
nameInput.attr("type", "text");
} else {
nameSelect.attr("style", "display:block");
nameInput.attr("type", "hidden");
}
});
$(".am-modal-prompt-input-income-type").on('change', function () {
var nameSelect = $(this).parent().parent().find(".input-changeable-tax-rate-income-select");
var nameInput = $(this).parent().parent().find(".input-changeable-tax-rate-income-name");
nameSelect.attr("style", "display:block");
nameInput.attr("type", "hidden");
})
}
function initRowData(data){
$('#incomeTable tbody .incomeaddtr:last').find('.am-modal-prompt-input-income-type').val(data.type)
if(data.name!='华智产品'&&data.name!='华三产品'&&data.name!='汇智产品' ){
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-tax-rate-income-select').val('自定义')
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-tax-rate-income-select')
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-tax-rate-income-name').val(data.name)
$('#incomeTable tbody .incomeaddtr').last().find('.input-changeable-tax-rate-income-select').trigger('change')
}else{
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-tax-rate-income-select').val(data.name)
}
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-tax-rate-income').val(data.taxRate)
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-total-tax-include-income').val(data.totalTaxInclude)
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-total-tax-exclude-income').val(data.totalTaxExclude)
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-total-tax-income').val(data.totalTax)
$('#incomeTable tbody .incomeaddtr:last').find('.input-changeable-total-tax-include-income').trigger('change')
}