ContractSaleIncomeController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. package cn.com.lzt.contractsaleincome.controller;
  2. import cn.com.lzt.contractsale.entity.ContractSaleEntity;
  3. import cn.com.lzt.contractsaleincome.entity.ContractSaleIncomeEntity;
  4. import cn.com.lzt.contractsaleincome.service.ContractSaleIncomeServiceI;
  5. import cn.com.lzt.contractsaleinvoice.entity.ContractSaleInvoiceEntity;
  6. import cn.com.lzt.tools.DecimalUtils;
  7. import com.xcgl.utils.XcglDateUtils;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.apache.log4j.Logger;
  10. import org.jeecgframework.core.beanvalidator.BeanValidators;
  11. import org.jeecgframework.core.common.controller.BaseController;
  12. import org.jeecgframework.core.common.exception.BusinessException;
  13. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  14. import org.jeecgframework.core.common.model.json.AjaxJson;
  15. import org.jeecgframework.core.common.model.json.DataGrid;
  16. import org.jeecgframework.core.constant.Globals;
  17. import org.jeecgframework.core.util.*;
  18. import org.jeecgframework.poi.excel.ExcelImportUtil;
  19. import org.jeecgframework.poi.excel.entity.ExportParams;
  20. import org.jeecgframework.poi.excel.entity.ImportParams;
  21. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  22. import org.jeecgframework.tag.core.easyui.TagUtil;
  23. import org.jeecgframework.web.system.pojo.base.TSUser;
  24. import org.jeecgframework.web.system.service.SystemService;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.http.HttpHeaders;
  27. import org.springframework.http.HttpStatus;
  28. import org.springframework.http.MediaType;
  29. import org.springframework.http.ResponseEntity;
  30. import org.springframework.stereotype.Controller;
  31. import org.springframework.ui.ModelMap;
  32. import org.springframework.web.bind.annotation.*;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import org.springframework.web.multipart.MultipartHttpServletRequest;
  35. import org.springframework.web.servlet.ModelAndView;
  36. import org.springframework.web.util.UriComponentsBuilder;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpServletResponse;
  39. import javax.validation.ConstraintViolation;
  40. import javax.validation.Validator;
  41. import java.io.IOException;
  42. import java.net.URI;
  43. import java.text.DecimalFormat;
  44. import java.text.ParseException;
  45. import java.util.*;
  46. /**
  47. * @Title: Controller
  48. * @Description: 销售合同收款
  49. * @author onlineGenerator
  50. * @date 2019-06-24 14:14:52
  51. * @version V1.0
  52. *
  53. */
  54. @Controller
  55. @RequestMapping("/contractSaleIncomeController")
  56. public class ContractSaleIncomeController extends BaseController {
  57. /**
  58. * Logger for this class
  59. */
  60. private static final Logger logger = Logger.getLogger(ContractSaleIncomeController.class);
  61. @Autowired
  62. private ContractSaleIncomeServiceI contractSaleIncomeService;
  63. @Autowired
  64. private SystemService systemService;
  65. @Autowired
  66. private Validator validator;
  67. /**
  68. * 销售合同收款列表 页面跳转
  69. *
  70. * @return
  71. */
  72. @RequestMapping(params = "list")
  73. public ModelAndView list(HttpServletRequest request) {
  74. request.setAttribute("invoiceid", request.getParameter("invoiceid"));
  75. return new ModelAndView("cn/com/lzt/contractsaleincome/contractSaleIncomeList");
  76. }
  77. @RequestMapping(params = "listByContractid")
  78. public ModelAndView listByContractid(String contractid,HttpServletRequest request) {
  79. if(StringUtils.isEmpty(contractid))
  80. contractid = "1";
  81. request.setAttribute("contractid", contractid);
  82. return new ModelAndView("cn/com/lzt/contractsaleincome/contractSaleIncomeListReadonly");
  83. }
  84. /**
  85. * easyui AJAX请求数据
  86. *
  87. * @param request
  88. * @param response
  89. * @param dataGrid
  90. * @param user
  91. */
  92. @RequestMapping(params = "datagrid")
  93. public void datagrid(ContractSaleIncomeEntity contractSaleIncome,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  94. CriteriaQuery cq = new CriteriaQuery(ContractSaleIncomeEntity.class, dataGrid);
  95. //查询条件组装器
  96. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSaleIncome, request.getParameterMap());
  97. try{
  98. //自定义追加查询条件
  99. }catch (Exception e) {
  100. throw new BusinessException(e.getMessage());
  101. }
  102. cq.add();
  103. this.contractSaleIncomeService.getDataGridReturn(cq, true);
  104. if (StringUtils.isNotEmpty(contractSaleIncome.getSourcebillid())) {
  105. List<ContractSaleIncomeEntity> resualtlist = dataGrid.getResults();
  106. Double sum = 0.0;
  107. if (resualtlist.size() != 0) {
  108. for (ContractSaleIncomeEntity aa : resualtlist) {
  109. sum = sum + Double.valueOf(aa.getIncomeamount());
  110. }
  111. }
  112. // 格式化为小数点2位数
  113. DecimalFormat df = new DecimalFormat("#.00");
  114. String total_salary = df.format(sum);
  115. dataGrid.setFooter("incomeamount:累计收款:,periodBegin:"+total_salary);
  116. }
  117. TagUtil.datagrid(response, dataGrid);
  118. }
  119. /**
  120. * 删除销售合同收款
  121. *
  122. * @return
  123. */
  124. @RequestMapping(params = "doDel")
  125. @ResponseBody
  126. public AjaxJson doDel(ContractSaleIncomeEntity contractSaleIncome, HttpServletRequest request) {
  127. String message = null;
  128. AjaxJson j = new AjaxJson();
  129. String lastincomedate = null;
  130. if(StringUtils.isNotEmpty(contractSaleIncome.getId()))
  131. contractSaleIncome = systemService.getEntity(ContractSaleIncomeEntity.class, contractSaleIncome.getId());
  132. else {
  133. List<ContractSaleIncomeEntity> entitys = systemService.findHql(
  134. "From ContractSaleIncomeEntity where invoiceid =? order by incomedate desc", contractSaleIncome.getInvoiceid());
  135. if(entitys.size() > 0) {
  136. contractSaleIncome = entitys.get(0);
  137. if(entitys.size() > 1) {
  138. lastincomedate = DateUtils.datetimeFormat.format(entitys.get(1).getIncomedate());
  139. }
  140. }else {
  141. j.setSuccess(false);
  142. j.setMsg("此合同发票无收款的信息,取消收款失败");
  143. return j;
  144. }
  145. }
  146. message = "成功取消销售合同收款";
  147. try{
  148. contractSaleIncomeService.delete(contractSaleIncome);
  149. updateContractSaleTotalIncome(contractSaleIncome.getSourcebillid(), 0-contractSaleIncome.getIncomeamount(),
  150. lastincomedate,contractSaleIncome.getInvoiceid(), Globals.CONTRACT_STATUS_INVOICE);
  151. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  152. }catch(Exception e){
  153. e.printStackTrace();
  154. message = "取消销售合同收款失败";
  155. throw new BusinessException(e.getMessage());
  156. }
  157. j.setMsg(message);
  158. return j;
  159. }
  160. /**
  161. * 批量删除销售合同收款
  162. *
  163. * @return
  164. */
  165. @RequestMapping(params = "doBatchDel")
  166. @ResponseBody
  167. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  168. String message = null;
  169. AjaxJson j = new AjaxJson();
  170. message = "销售合同收款删除成功";
  171. try{
  172. for(String id:ids.split(",")){
  173. ContractSaleIncomeEntity contractSaleIncome = systemService.getEntity(ContractSaleIncomeEntity.class,
  174. id
  175. );
  176. contractSaleIncomeService.delete(contractSaleIncome);
  177. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  178. }
  179. }catch(Exception e){
  180. e.printStackTrace();
  181. message = "销售合同收款删除失败";
  182. throw new BusinessException(e.getMessage());
  183. }
  184. j.setMsg(message);
  185. return j;
  186. }
  187. /**
  188. * 添加销售合同收款
  189. *
  190. * @param ids
  191. * @return
  192. */
  193. @RequestMapping(params = "doAdd")
  194. @ResponseBody
  195. public AjaxJson doAdd(ContractSaleIncomeEntity contractSaleIncome, HttpServletRequest request) {
  196. String message = null;
  197. AjaxJson j = new AjaxJson();
  198. message = "销售合同收款添加成功";
  199. try{
  200. setFinancialData(contractSaleIncome);
  201. ContractSaleInvoiceEntity invoice = systemService.get(ContractSaleInvoiceEntity.class, contractSaleIncome.getInvoiceid());
  202. String msg = checkData(contractSaleIncome,invoice);
  203. if(msg != null) {
  204. j.setSuccess(false);
  205. j.setMsg(msg);
  206. return j;
  207. }
  208. contractSaleIncomeService.save(contractSaleIncome);
  209. //回写合同收款合计
  210. updateContractSaleTotalIncome(contractSaleIncome.getSourcebillid(), contractSaleIncome.getIncomeamount(),
  211. DateUtils.datetimeFormat.format(contractSaleIncome.getIncomedate()),
  212. contractSaleIncome.getInvoiceid(),
  213. contractSaleIncome.getIncomeamount()==invoice.getInvoiceamount()-invoice.getIncomeamount()?Globals.CONTRACT_STATUS_INCOME:Globals.CONTRACT_STATUS_INVOICE);
  214. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  215. }catch(Exception e){
  216. e.printStackTrace();
  217. message = "销售合同收款添加失败";
  218. throw new BusinessException(e.getMessage());
  219. }
  220. j.setMsg(message);
  221. return j;
  222. }
  223. /**
  224. * 更新销售合同收款
  225. *
  226. * @param ids
  227. * @return
  228. */
  229. @RequestMapping(params = "doUpdate")
  230. @ResponseBody
  231. public AjaxJson doUpdate(ContractSaleIncomeEntity contractSaleIncome, HttpServletRequest request) {
  232. String message = null;
  233. AjaxJson j = new AjaxJson();
  234. message = "销售合同收款更新成功";
  235. ContractSaleIncomeEntity t = contractSaleIncomeService.get(ContractSaleIncomeEntity.class, contractSaleIncome.getId());
  236. try {
  237. setFinancialData(contractSaleIncome);
  238. MyBeanUtils.copyBeanNotNull2Bean(contractSaleIncome, t);
  239. contractSaleIncomeService.saveOrUpdate(t);
  240. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. message = "销售合同收款更新失败";
  244. throw new BusinessException(e.getMessage());
  245. }
  246. j.setMsg(message);
  247. return j;
  248. }
  249. /**
  250. * 销售合同收款新增页面跳转
  251. *
  252. * @return
  253. */
  254. @RequestMapping(params = "goAdd")
  255. public ModelAndView goAdd(ContractSaleIncomeEntity contractSaleIncome, HttpServletRequest req) {
  256. //设置默认值,来源单据信息、默认收款金额、操作员等
  257. String invoiceid = req.getParameter("invoiceid");
  258. TSUser user = ResourceUtil.getSessionUser();
  259. ContractSaleInvoiceEntity invoice = systemService.get(ContractSaleInvoiceEntity.class, invoiceid);
  260. ContractSaleEntity contract = systemService.get(ContractSaleEntity.class, invoice.getContractid());
  261. contractSaleIncome.setOperatorid(user.getId());
  262. contractSaleIncome.setOperatorname(user.getRealName());
  263. contractSaleIncome.setSourcetype("contractsale");
  264. contractSaleIncome.setSourcebillcode(contract.getCode());
  265. contractSaleIncome.setSourcebillid(invoice.getContractid());
  266. contractSaleIncome.setInvoiceid(invoiceid);
  267. contractSaleIncome.setTotalamount(contract.getTotalamount());
  268. contractSaleIncome.setTotalincome(contract.getTotalincome());
  269. contractSaleIncome.setIncomeamount(invoice.getInvoiceamount()-invoice.getIncomeamount());
  270. //如果多次收款,则默认设置物业费起始时间为上次收款的截止时间的下一天
  271. if(invoice.getIncomeamount()>0) {
  272. List<ContractSaleIncomeEntity> entitys = systemService.findHql("From ContractSaleIncomeEntity where invoiceid =? order by incomedate desc", contractSaleIncome.getInvoiceid());
  273. if(entitys.size() > 0) {
  274. ContractSaleIncomeEntity lastIncome = entitys.get(0);
  275. contractSaleIncome.setPeriodBegin(XcglDateUtils.addDateDay(lastIncome.getPeriodEnd(), 1, DateUtils.datetimeFormat).substring(0,10)) ;
  276. }
  277. }else {
  278. contractSaleIncome.setPeriodBegin(invoice.getPeriodBegin());
  279. }
  280. contractSaleIncome.setPeriodEnd(invoice.getPeriodEnd());
  281. if (StringUtil.isNotEmpty(contractSaleIncome.getId())) {
  282. contractSaleIncome = contractSaleIncomeService.getEntity(ContractSaleIncomeEntity.class, contractSaleIncome.getId());
  283. }
  284. req.setAttribute("contractSaleIncomePage", contractSaleIncome);
  285. return new ModelAndView("cn/com/lzt/contractsaleincome/contractSaleIncome-add");
  286. }
  287. /**
  288. * 销售合同收款编辑页面跳转
  289. *
  290. * @return
  291. */
  292. @RequestMapping(params = "goUpdate")
  293. public ModelAndView goUpdate(ContractSaleIncomeEntity contractSaleIncome, HttpServletRequest req) {
  294. if (StringUtil.isNotEmpty(contractSaleIncome.getId())) {
  295. contractSaleIncome = contractSaleIncomeService.getEntity(ContractSaleIncomeEntity.class, contractSaleIncome.getId());
  296. req.setAttribute("contractSaleIncomePage", contractSaleIncome);
  297. }
  298. return new ModelAndView("cn/com/lzt/contractsaleincome/contractSaleIncome-update");
  299. }
  300. /**
  301. * 导入功能跳转
  302. *
  303. * @return
  304. */
  305. @RequestMapping(params = "upload")
  306. public ModelAndView upload(HttpServletRequest req) {
  307. req.setAttribute("controller_name","contractSaleIncomeController");
  308. return new ModelAndView("common/upload/pub_excel_upload");
  309. }
  310. /**
  311. * 导出excel
  312. *
  313. * @param request
  314. * @param response
  315. */
  316. @RequestMapping(params = "exportXls")
  317. public String exportXls(ContractSaleIncomeEntity contractSaleIncome,HttpServletRequest request,HttpServletResponse response
  318. , DataGrid dataGrid,ModelMap modelMap) {
  319. CriteriaQuery cq = new CriteriaQuery(ContractSaleIncomeEntity.class, dataGrid);
  320. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractSaleIncome, request.getParameterMap());
  321. List<ContractSaleIncomeEntity> contractSaleIncomes = this.contractSaleIncomeService.getListByCriteriaQuery(cq,false);
  322. modelMap.put(NormalExcelConstants.FILE_NAME,"销售合同收款");
  323. modelMap.put(NormalExcelConstants.CLASS,ContractSaleIncomeEntity.class);
  324. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("销售合同收款列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  325. "导出信息"));
  326. modelMap.put(NormalExcelConstants.DATA_LIST,contractSaleIncomes);
  327. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  328. }
  329. /**
  330. * 导出excel 使模板
  331. *
  332. * @param request
  333. * @param response
  334. */
  335. @RequestMapping(params = "exportXlsByT")
  336. public String exportXlsByT(ContractSaleIncomeEntity contractSaleIncome,HttpServletRequest request,HttpServletResponse response
  337. , DataGrid dataGrid,ModelMap modelMap) {
  338. modelMap.put(NormalExcelConstants.FILE_NAME,"销售合同收款");
  339. modelMap.put(NormalExcelConstants.CLASS,ContractSaleIncomeEntity.class);
  340. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("销售合同收款列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  341. "导出信息"));
  342. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  343. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  344. }
  345. @SuppressWarnings("unchecked")
  346. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  347. @ResponseBody
  348. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  349. AjaxJson j = new AjaxJson();
  350. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  351. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  352. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  353. MultipartFile file = entity.getValue();// 获取上传文件对象
  354. ImportParams params = new ImportParams();
  355. params.setTitleRows(2);
  356. params.setHeadRows(1);
  357. params.setNeedSave(true);
  358. try {
  359. List<ContractSaleIncomeEntity> listContractSaleIncomeEntitys = ExcelImportUtil.importExcel(file.getInputStream(),ContractSaleIncomeEntity.class,params);
  360. for (ContractSaleIncomeEntity contractSaleIncome : listContractSaleIncomeEntitys) {
  361. contractSaleIncomeService.save(contractSaleIncome);
  362. }
  363. j.setMsg("文件导入成功!");
  364. } catch (Exception e) {
  365. j.setMsg("文件导入失败!");
  366. logger.error(ExceptionUtil.getExceptionMessage(e));
  367. }finally{
  368. try {
  369. file.getInputStream().close();
  370. } catch (IOException e) {
  371. e.printStackTrace();
  372. }
  373. }
  374. }
  375. return j;
  376. }
  377. @RequestMapping(method = RequestMethod.GET)
  378. @ResponseBody
  379. public List<ContractSaleIncomeEntity> list() {
  380. List<ContractSaleIncomeEntity> listContractSaleIncomes=contractSaleIncomeService.getList(ContractSaleIncomeEntity.class);
  381. return listContractSaleIncomes;
  382. }
  383. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  384. @ResponseBody
  385. public ResponseEntity<?> get(@PathVariable("id") String id) {
  386. ContractSaleIncomeEntity task = contractSaleIncomeService.get(ContractSaleIncomeEntity.class, id);
  387. if (task == null) {
  388. return new ResponseEntity(HttpStatus.NOT_FOUND);
  389. }
  390. return new ResponseEntity(task, HttpStatus.OK);
  391. }
  392. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  393. @ResponseBody
  394. public ResponseEntity<?> create(@RequestBody ContractSaleIncomeEntity contractSaleIncome, UriComponentsBuilder uriBuilder) {
  395. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  396. Set<ConstraintViolation<ContractSaleIncomeEntity>> failures = validator.validate(contractSaleIncome);
  397. if (!failures.isEmpty()) {
  398. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  399. }
  400. //保存
  401. try{
  402. contractSaleIncomeService.save(contractSaleIncome);
  403. } catch (Exception e) {
  404. e.printStackTrace();
  405. return new ResponseEntity(HttpStatus.NO_CONTENT);
  406. }
  407. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  408. String id = contractSaleIncome.getId();
  409. URI uri = uriBuilder.path("/rest/contractSaleIncomeController/" + id).build().toUri();
  410. HttpHeaders headers = new HttpHeaders();
  411. headers.setLocation(uri);
  412. return new ResponseEntity(headers, HttpStatus.CREATED);
  413. }
  414. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  415. public ResponseEntity<?> update(@RequestBody ContractSaleIncomeEntity contractSaleIncome) {
  416. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  417. Set<ConstraintViolation<ContractSaleIncomeEntity>> failures = validator.validate(contractSaleIncome);
  418. if (!failures.isEmpty()) {
  419. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  420. }
  421. //保存
  422. try{
  423. contractSaleIncomeService.saveOrUpdate(contractSaleIncome);
  424. } catch (Exception e) {
  425. e.printStackTrace();
  426. return new ResponseEntity(HttpStatus.NO_CONTENT);
  427. }
  428. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  429. return new ResponseEntity(HttpStatus.NO_CONTENT);
  430. }
  431. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  432. @ResponseStatus(HttpStatus.NO_CONTENT)
  433. public void delete(@PathVariable("id") String id) {
  434. ContractSaleIncomeEntity income = systemService.get(ContractSaleIncomeEntity.class, id);
  435. contractSaleIncomeService.deleteEntityById(ContractSaleIncomeEntity.class, id);
  436. updateContractSaleTotalIncome(income.getSourcebillid(), income.getIncomeamount(),
  437. DateUtils.datetimeFormat.format(income.getIncomedate()),income.getInvoiceid(), Globals.CONTRACT_STATUS_INVOICE);
  438. }
  439. private void updateContractSaleTotalIncome(String cid,Double incomeamount,String incomedate,String invoiceid,String newStatus) {
  440. //回写合同
  441. String updateSql = "update t_b_contract_sale c set c.totalincome = c.totalincome+? where c.id =? ";
  442. systemService.executeSql(updateSql,incomeamount, cid);
  443. //回写发票
  444. updateSql = "update t_b_contract_sale_invoice c set c.incomeamount = c.incomeamount+? ,c.incomedate=? ,c.busstatus=? where c.id =? ";
  445. systemService.executeSql(updateSql,incomeamount,incomedate,newStatus,invoiceid);
  446. }
  447. /**
  448. * 设置收上年、收下年、收本年金额
  449. * @throws ParseException
  450. * */
  451. private ContractSaleIncomeEntity setFinancialData(ContractSaleIncomeEntity income) throws ParseException {
  452. if(income.getPeriodBegin().substring(0,4).equals(income.getPeriodEnd().substring(0,4))) {
  453. //不跨年
  454. income.setC2cincome(income.getIncomeamount());
  455. income.setC2lincome(DecimalUtils.ZERO);
  456. income.setC2nincome(DecimalUtils.ZERO);
  457. }else {
  458. //跨年时,需要计算开上一年或开下一年金额
  459. Date begin = DateUtils.datetimeFormat.parse(income.getPeriodBegin()+" 00:00:00");
  460. Date end = DateUtils.datetimeFormat.parse(income.getPeriodEnd()+" 00:00:00");
  461. //属于上一年的天数
  462. int firstHalf = XcglDateUtils.differentDays2YearEnd(begin)+1;
  463. //属于下一年的天数
  464. int secondHalf = XcglDateUtils.differentDays2YearStart(end)+1;
  465. double firstAmount = DecimalUtils.formatToDouble((income.getIncomeamount()*firstHalf)/(firstHalf+secondHalf));
  466. double secondAmount = DecimalUtils.formatToDouble(income.getIncomeamount()-firstAmount);
  467. //如果收款日期属于上半个阶段
  468. if(income.getPeriodBegin().substring(0,4).equals(
  469. DateUtils.date_sdf.format(income.getIncomedate()).substring(0,4))) {
  470. income.setC2cincome(firstAmount);//收本年
  471. income.setC2nincome(secondAmount);//收下年
  472. income.setC2lincome(DecimalUtils.ZERO);//收上年
  473. }else {
  474. //收款日期属于下半个阶段
  475. income.setC2cincome(secondAmount);//收本年
  476. income.setC2nincome(DecimalUtils.ZERO);//收下年
  477. income.setC2lincome(firstAmount);//收上年
  478. }
  479. }
  480. return income;
  481. }
  482. String checkData(ContractSaleIncomeEntity income,ContractSaleInvoiceEntity invoice) {
  483. String msg = null;
  484. if( income.getPeriodBegin().compareTo(invoice.getPeriodBegin()) < 0)
  485. msg = "收款信息中【物业费起始日期】不能小于发票【物业费起始日期】";
  486. if(income.getPeriodEnd().compareTo(invoice.getPeriodEnd()) > 0)
  487. msg = "收款信息中【物业费截止日期】不能大于发票【物业费截止日期】";
  488. return msg;
  489. }
  490. }