username@email.com
2021-07-21 fc1fe356e1cb43c7654c653e8921ee9e72150f96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using DTO;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;
using zhengcaioa.IService;
using zhengcaioa.Models;
 
namespace zhengcaioa.Controllers.Finance
{
    [CheckLogin]
    public class FiAccountTransferController : Controller
    {
        private readonly ILogger<FiAccountTransferController> _logger;
        private readonly IFiAccountService _fiAccountService;
        private readonly ILiaotianService _liaotianService;
 
        private readonly IFiAccountRecordService _iFiAccountRecordService;
        private readonly IFiSubjectService _ifiSubjectService;
 
 
        public FiAccountTransferController(ILogger<FiAccountTransferController> logger, IFiAccountService fiAccountService, ILiaotianService liaotianService, IFiAccountRecordService iFiAccountRecordService, IFiSubjectService ifiSubjectService)
        {
            _logger = logger;
            _fiAccountService = fiAccountService;
            _liaotianService = liaotianService;
            _iFiAccountRecordService = iFiAccountRecordService;
            _ifiSubjectService = ifiSubjectService;
        }
 
        public IActionResult Index()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            FiAccountRecordDTO fiAccountRecordDTO = new FiAccountRecordDTO();
            
            ViewBag.accounttype = _liaotianService.GetSYScode("fi_account", "accounttype");
            ViewBag.FiSubject = _ifiSubjectService.GetList().Where(x => x.Subjecttype == "02").ToList();
 
            ViewBag.FiSubjectIn = _ifiSubjectService.GetList().Where(x => x.Subjecttype == "01").ToList();
 
            ViewData.Model = fiAccountRecordDTO;
            return View();
        }
 
 
 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public IActionResult Save(FiAccountRecordDTO data)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            data.RecStatus = "A";
           
            data.Creater = curentuser.Id;
            data.Createtime = DateTime.Now;
           
            data.Modifier = curentuser.Id;
            data.Modifytime = DateTime.Now;
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = false;
            using (TransactionScope scope = new TransactionScope())
            {
 
                FiAccountDTO firmAccount = _fiAccountService.Get(data.AccountId);
 
 
                data.RecordTypeId = "2";//支出
                data.Department = "";
                data.PaymentUnit = "";
 
                firmAccount.AllExpenses = (firmAccount.AllExpenses ?? 0) + data.Money;
                firmAccount.Balance = (firmAccount.Balance ?? 0) - data.Money;
 
                data.AccountMoney = firmAccount.Balance;
 
                resultEntity = _iFiAccountRecordService.save(data);
                if (!resultEntity.Result)
                {
                    return new JsonResult(resultEntity);
                }
 
                resultEntity = _fiAccountService.save(firmAccount);
                if (!resultEntity.Result)
                {
                    return new JsonResult(resultEntity);
                }
 
 
 
 
 
                FiAccountDTO firmAccountIn = _fiAccountService.Get(data.InAccountId);
 
                FiAccountRecordDTO dataIn = new FiAccountRecordDTO();
 
                dataIn.Accounttype = data.InAccounttype;
                dataIn.AccountId = data.InAccountId;
                dataIn.SubjectId = data.InSubjectId;
                dataIn.Money = data.Money;
                dataIn.OperationalMatters = data.OperationalMatters;
                dataIn.RecordTypeId = "1";//收入
                dataIn.Department = "";
                dataIn.PaymentUnit = "";
                dataIn.Creater = curentuser.Id;
                dataIn.Createtime = data.Createtime;
 
                dataIn.Modifier = curentuser.Id;
                dataIn.Modifytime = data.Modifytime;
 
 
                firmAccountIn.AllIncome = (firmAccountIn.AllIncome ?? 0) + dataIn.Money;
                firmAccountIn.Balance = (firmAccountIn.Balance ?? 0) + dataIn.Money;
 
                dataIn.AccountMoney = firmAccountIn.Balance;
 
                resultEntity = _iFiAccountRecordService.save(dataIn);
                if (!resultEntity.Result)
                {
                    return new JsonResult(resultEntity);
                }
 
                resultEntity = _fiAccountService.save(firmAccountIn);
                if (!resultEntity.Result)
                {
                    return new JsonResult(resultEntity);
                }
                scope.Complete();
            }
 
 
 
            return new JsonResult(resultEntity);
        }
    }
}