收入明细完全ok了

master
xxssyyyyssxx 2021-11-03 15:03:03 +08:00
parent e194697964
commit 2459429a75
3 changed files with 131 additions and 102 deletions

View File

@ -20,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import top.jfunc.common.utils.CollectionUtil;
import javax.servlet.http.HttpServletResponse;
@ -177,22 +174,21 @@ public class ProjectController extends BaseController{
*
*/
@RequestMapping("/budgetEditSaveIncomeDetail")
@ResponseBody
public ResponseMsg budgetEditSaveIncomeDetail(@RequestBody String body) {
JSONObject jsonObject = JSON.parseObject(body);
JSONArray incomeDetails = jsonObject.getJSONArray("incomeDetails");
if(CollectionUtil.isNotEmpty(incomeDetails)){
List<ProjectBudgetIncomeDetail> incomeDetailList = new ArrayList<>(incomeDetails.size());
for (int i = 0; i < incomeDetails.size(); i++) {
ProjectBudgetIncomeDetail incomeDetail = incomeDetails.getObject(i, ProjectBudgetIncomeDetail.class);
incomeDetailList.add(incomeDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetIncomeDetail(project);
projectBudgetService.saveBudgetIncomeDetail(project, incomeDetailList);
List<ProjectBudgetIncomeDetail> incomeDetailList = new ArrayList<>(incomeDetails.size());
for (int i = 0; i < incomeDetails.size(); i++) {
ProjectBudgetIncomeDetail incomeDetail = incomeDetails.getObject(i, ProjectBudgetIncomeDetail.class);
incomeDetailList.add(incomeDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetIncomeDetail(project);
projectBudgetService.saveBudgetIncomeDetail(project, incomeDetailList);
return ResponseMsg.buildSuccessMsg("成功");
}
/**
@ -202,19 +198,17 @@ public class ProjectController extends BaseController{
public ResponseMsg budgetEditSaveCostDetail(@RequestBody String body) {
JSONObject jsonObject = JSON.parseObject(body);
JSONArray costDetails = jsonObject.getJSONArray("costDetails");
if(CollectionUtil.isNotEmpty(costDetails)){
List<ProjectBudgetCostDetail> costDetailList = new ArrayList<>(costDetails.size());
for (int i = 0; i < costDetails.size(); i++) {
ProjectBudgetCostDetail costDetail = costDetails.getObject(i, ProjectBudgetCostDetail.class);
costDetailList.add(costDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetCostDetail(project);
projectBudgetService.saveBudgetCostDetail(project, costDetailList);
List<ProjectBudgetCostDetail> costDetailList = new ArrayList<>(costDetails.size());
for (int i = 0; i < costDetails.size(); i++) {
ProjectBudgetCostDetail costDetail = costDetails.getObject(i, ProjectBudgetCostDetail.class);
costDetailList.add(costDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetCostDetail(project);
projectBudgetService.saveBudgetCostDetail(project, costDetailList);
return ResponseMsg.buildSuccessMsg("成功");
}
/**
@ -224,19 +218,17 @@ public class ProjectController extends BaseController{
public ResponseMsg budgetEditSaveCostProjectManageDetail(@RequestBody String body) {
JSONObject jsonObject = JSON.parseObject(body);
JSONArray costDetails = jsonObject.getJSONArray("costProjectManageDetails");
if(CollectionUtil.isNotEmpty(costDetails)){
List<ProjectBudgetCostProjectManageDetail> costDetailList = new ArrayList<>(costDetails.size());
for (int i = 0; i < costDetails.size(); i++) {
ProjectBudgetCostProjectManageDetail costDetail = costDetails.getObject(i, ProjectBudgetCostProjectManageDetail.class);
costDetailList.add(costDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetCostProjectManageDetail(project);
projectBudgetService.saveBudgetCostProjectManageDetail(project, costDetailList);
List<ProjectBudgetCostProjectManageDetail> costDetailList = new ArrayList<>(costDetails.size());
for (int i = 0; i < costDetails.size(); i++) {
ProjectBudgetCostProjectManageDetail costDetail = costDetails.getObject(i, ProjectBudgetCostProjectManageDetail.class);
costDetailList.add(costDetail);
}
Project project = projectService.getProject(jsonObject.getInteger("projectId"));
projectBudgetService.clearBudgetCostProjectManageDetail(project);
projectBudgetService.saveBudgetCostProjectManageDetail(project, costDetailList);
return ResponseMsg.buildSuccessMsg("成功");
}
@InitBinder

View File

@ -25,6 +25,10 @@ function arrayToMatrix(list, elementsPerSubArray) {
function arr2Object(arr, mapArr) {
var obj = {};
for (var i = 0; i < mapArr.length; i++) {
if(!arr[i]){
//如果有空的就返回空
return null;
}
obj[mapArr[i]]=arr[i];
}
return obj;
@ -33,8 +37,89 @@ function arr2Object(arr, mapArr) {
/**
* 一个收入详情的字段
*/
INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate"];
INCOME_DETAIL_PROP_LENGTH=8;
INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
/**
* 保存收入明细数据
*/
function saveIncomeDetail(url, data, projectId) {
if(Array.isArray(data) && data.length != 0){
var incomeDetails = convertIncomeDetail(data);
var da = {
"incomeDetails":incomeDetails,
"projectId":projectId
};
console.log(da);
$.ajax({
url: url,
data: JSON.stringify(da),
type: "post",
dataType: "json",
contentType:"application/json",
async: false,
success: function (d) {
console.log(d);
updateIncomeData(incomeDetails);
}
});
}
}
/**
* 更新页面收入的数据累加
*/
function updateIncomeData(incomeDetails) {
var deviceTaxInclude = 0;
var deviceTaxExclude = 0;
var engineerTaxInclude = 0;
var engineerTaxExclude = 0;
var serviceTaxInclude = 0;
var serviceTaxExclude = 0;
incomeDetails.forEach(function (t, number, ts) {
if(t["type"] == "1"){
//设备类
deviceTaxInclude += parseFloat(t["totalTaxInclude"]);
deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "2"){
//工程类
engineerTaxInclude += parseFloat(t["totalTaxInclude"]);
engineerTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "3"){
//服务类
serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}
});
$("input[name='incomeDeviceTaxInclude']").val(deviceTaxInclude);
$("input[name='incomeDeviceTaxExclude']").val(deviceTaxExclude);
$("input[name='incomeEngineerTaxInclude']").val(engineerTaxInclude);
$("input[name='incomeEngineerTaxExclude']").val(engineerTaxExclude);
$("input[name='incomeServiceTaxInclude']").val(serviceTaxInclude);
$("input[name='incomeServiceTaxExclude']").val(serviceTaxExclude);
$("input[name='incomeTotalTaxInclude']").val(deviceTaxInclude+engineerTaxInclude+serviceTaxInclude);
$("input[name='incomeTotalTaxExclude']").val(deviceTaxExclude+engineerTaxExclude+serviceTaxExclude);
}
/**
* 将页面收集到的数据转换为ajax请求的数据一维数组转换为对象数组
* @param data
* @returns {Array}
*/
function convertIncomeDetail(data) {
var arr = arrayToMatrix(data,INCOME_DETAIL_ARR.length);
var incomeDetails = [];
for (var i=0;i<arr.length;i++){
var obj = arr2Object(arr[i], INCOME_DETAIL_ARR);
if(obj){
incomeDetails.push(obj);
}
}
return incomeDetails;
}
/**
* 收集收入明细的数据因为动态添加的行modal无法识别所以自己来收集
@ -48,37 +133,6 @@ function collectIncomeData(className) {
return a;
}
/**
* 保存收入明细数据
*/
function saveIncome(url, data, projectId) {
if(Array.isArray(data) && data.length != 0){
console.log(data);
var arr = arrayToMatrix(data,INCOME_DETAIL_PROP_LENGTH);
var incomeDetails = [];
for (var i=0;i<arr.length;i++){
incomeDetails.push(arr2Object(arr[i], INCOME_DETAIL_ARR));
}
var da = {
"incomeDetails":incomeDetails,
"projectId":projectId
};
$.ajax({
url: url,
data: JSON.stringify(da),
type: "post",
dataType: "json",
contentType:"application/json",
async: false,
success: function (d) {
console.log(d);
//TODO 进行计算
}
});
}
}
/**
* 绑定每一行的删除事件删除当前的一行tr
*/

View File

@ -204,26 +204,26 @@
<tr>
<td>收入</td>
<td>设备类</td>
<td><input name="incomeDeviceTaxInclude" value="${budgetBean.incomeDeviceTaxInclude!1}" required readonly></td>
<td><input name="incomeDeviceTaxExclude" value="${budgetBean.incomeDeviceTaxExclude!2}" required readonly></td>
<td><input name="incomeDeviceTaxInclude" value="${budgetBean.incomeDeviceTaxInclude!0}" required readonly></td>
<td><input name="incomeDeviceTaxExclude" value="${budgetBean.incomeDeviceTaxExclude!0}" required readonly></td>
</tr>
<tr>
<td>收入</td>
<td>工程类</td>
<td><input name="incomeEngineerTaxInclude" value="${budgetBean.incomeEngineerTaxInclude!3}" required readonly></td>
<td><input name="incomeEngineerTaxExclude" value="${budgetBean.incomeEngineerTaxExclude!4}" required readonly></td>
<td><input name="incomeEngineerTaxInclude" value="${budgetBean.incomeEngineerTaxInclude!0}" required readonly></td>
<td><input name="incomeEngineerTaxExclude" value="${budgetBean.incomeEngineerTaxExclude!0}" required readonly></td>
</tr>
<tr>
<td>收入</td>
<td>服务类</td>
<td><input name="incomeServiceTaxInclude" value="${budgetBean.incomeServiceTaxInclude!5}" required readonly></td>
<td><input name="incomeServiceTaxExclude" value="${budgetBean.incomeServiceTaxExclude!6}" required readonly></td>
<td><input name="incomeServiceTaxInclude" value="${budgetBean.incomeServiceTaxInclude!0}" required readonly></td>
<td><input name="incomeServiceTaxExclude" value="${budgetBean.incomeServiceTaxExclude!0}" required readonly></td>
</tr>
<tr>
<td>合计</td>
<td></td>
<td><input name="incomeTotalTaxInclude" value="${budgetBean.incomeTotalTaxInclude!7}" readonly required></td>
<td><input name="incomeTotalTaxExclude" value="${budgetBean.incomeTotalTaxExclude!8}" readonly required></td>
<td><input name="incomeTotalTaxInclude" value="${budgetBean.incomeTotalTaxInclude!0}" readonly required></td>
<td><input name="incomeTotalTaxExclude" value="${budgetBean.incomeTotalTaxExclude!0}" readonly required></td>
</tr>
</tbody>
</table>
@ -441,31 +441,14 @@
<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate" value="${incomeDetail.taxRate!}"></td>
<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-include" value="${incomeDetail.totalTaxInclude!}" readonly></td>
<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-exclude" value="${incomeDetail.totalTaxExclude!}" readonly></td>
<td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete">删除</button></td>
<td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>
</tr>
</#list>
</#if>
<#--<tr>
<td>
<select data-am-selected class="am-modal-prompt-input">
<option value="1">设备类</option>
<option value="2">工程类</option>
<option value="3">服务类</option>
</select>
</td>
<td><input type="text" class="am-modal-prompt-input"></td>
<td><input type="text" class="am-modal-prompt-input"></td>
<td><input type="text" class="am-modal-prompt-input"></td>
<td><input type="text" class="am-modal-prompt-input"></td>
<td><input type="text" class="am-modal-prompt-input"></td>
<td><input type="text" class="am-modal-prompt-input" readonly></td>
<td><input type="text" class="am-modal-prompt-input" readonly></td>
</tr>-->
</tbody>
</table>
<button type="button" id="incomeAddBtn" class="am-btn am-btn-primary am-btn-xs">添加一行</button>
<button type="button" id="incomeAddBtn" class="am-btn am-btn-primary am-btn-xs"><span class="am-icon-plus"></span></button>
</div>
<div class="am-modal-footer">
<span class="am-modal-btn" data-am-modal-cancel>取消</span>
@ -505,7 +488,7 @@
onConfirm: function(e) {
//不能使用e.data因为无法获取动态添加的
var data = collectIncomeData("am-modal-prompt-input-income");
saveIncome("${base}/project/budgetEditSaveIncomeDetail", data, $("#id").val());
saveIncomeDetail("${base}/project/budgetEditSaveIncomeDetail", data, $("#id").val());
},
onCancel: function(e) {
}
@ -527,7 +510,7 @@
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-include" readonly></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-exclude" readonly></td>\n' +
' <td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete">删除</button></td>\n' +
' <td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>\n' +
' </tr>';
$("#incomeTable").append(template);
bindDeleteBtn();