username@email.com
23 小时以前 529d8cb61421eb65d86559d3d2636ad405b87b41
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.OA;
using System.Data;
using System.Data.SqlClient;
using CY.Infrastructure.Common;
using CY.Model;
using CY.BLL.Sys;
using CY.BLL;
using System.Transactions;
 
namespace CY.WebForm.Pages.financial
{
    //吴辉
    //采购付款选择账户
    public partial class CaigouPayEdit : BasePage
    {
 
        OA_WarehouseInfoBLL _OA_WarehouseInfoBLL = null;
        OA_CargoSpaceBLL _OA_CargoSpaceBLL = null;
        OA_OutOfStorageBLL bll_OA_OutOfStorageBLL = null;
        OA_SubjectSetBLL bll_OA_SubjectSetBLL = null;
        Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
        OA_ProcurementBLL bll_OA_ProcurementBLL = null;
        OA_FirmAccountBLL bll_OA_FirmAccountBLL = null;
        OA_SuppliersBLL bll_OA_SuppliersBLL = null;
        OA_FukuanshenqingBLL _fukuanshenqingBLL = null;
        OA_SubjectSetBLL _OA_SubjectSetBLL = null;
        Sys_DictionaryBLL _Sys_DictionaryBLL = null;
        OA_StaffBLL staffBLL = null;
        OA_BaozhengjinBLL oA_BaozhengjinBLL = null;
        decimal? AllMoney = 0;
        decimal? ReceiveMoney = 0;
        //初始化
        public CaigouPayEdit()
        {
            bll_OA_OutOfStorageBLL = new OA_OutOfStorageBLL();
            _OA_WarehouseInfoBLL = new OA_WarehouseInfoBLL();
            _OA_CargoSpaceBLL = new OA_CargoSpaceBLL();
            bll_OA_SubjectSetBLL = new OA_SubjectSetBLL();
            bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
            bll_OA_ProcurementBLL = new OA_ProcurementBLL();
            bll_OA_FirmAccountBLL = new OA_FirmAccountBLL();
            bll_OA_SuppliersBLL = new OA_SuppliersBLL();
            _fukuanshenqingBLL = new OA_FukuanshenqingBLL();
            _Sys_DictionaryBLL = new Sys_DictionaryBLL();
            staffBLL = new OA_StaffBLL();
            oA_BaozhengjinBLL = new OA_BaozhengjinBLL();
            _OA_SubjectSetBLL = new OA_SubjectSetBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialData();
            }
 
        }
 
        //加载数据
        protected void InitialData()
        {
            //科目名称
            this.selSubject.DataSource = bll_OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷");
            this.selSubject.DataBind();
            this.selSubject.Items.Insert(0, new ListItem("请选择", ""));
 
            //账户类型
            this.selAcoountTypeOut.DataSource = bll_Sys_DictionaryBLL.GetDataByType("账户类型");
            this.selAcoountTypeOut.DataBind();
 
            var id = Request["id"];
            var fukuanshenqing = _fukuanshenqingBLL.GetModelByKeyid(id.ToInt32().Value);
            if (fukuanshenqing != null)
            {
                this.Keyid.Value = id;
                this.txtYouwufapiao.Value = fukuanshenqing.YouwufapiaoName;
                string[] Keys = fukuanshenqing.DindanId.Trim(',').Split(',');
                foreach (var item in Keys)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        OA_Procurement m_OA_Procurement = bll_OA_ProcurementBLL.SelectSingleModel(item);
                        if (m_OA_Procurement != null)
                        {
                            AllMoney += m_OA_Procurement.AllMoney;
                            ReceiveMoney += (m_OA_Procurement.AllMoney - m_OA_Procurement.ReceiveMoney);
                        }
                    }
                }
                this.spanAllMoney.InnerHtml = "¥" + (AllMoney ?? 0).ToString("0.00");
                this.spanReceiveMoney.InnerHtml = "¥" + ReceiveMoney.Value.ToString("0.00");
                this.hidReceiveMoney.Value =  ReceiveMoney.Value.ToString();
                this.spanCountRe.InnerHtml = Keys.Count().ToString2() + " 单";
 
               
                this.txtReciveMoney.Value = (ReceiveMoney ?? 0).ToString("0.00");
                this.txtReciveMoney.Attributes.Add("max", (ReceiveMoney ?? 0).ToString("0.00"));
            }
               
 
            
              
            
        }
 
        //提交事件
        protected void btn_Submit_form(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(Request["selAccountNameOut"]))
                {
                    JavaScript.MessageBox("请选择账户", this);
                    return;
                }
                var werwerwerwerwe = Request["txtReciveMoney"];
                ReceiveMoney = this.txtReciveMoney.Value.ToDecimal2();
                int? SubjectId = this.selSubject.Value.ToInt32();
                var molingmoney = this.txtMolingMoney.Value.ToDecimal2();
                decimal? money = ReceiveMoney;
 
 
                int? AccountIdOut = Request["selAccountNameOut"].ToInt32();
 
                if (SubjectId == null || money == null || AccountIdOut == null)
                    JavaScript.MessageBox("操作失败", this);
                else
                {
                    DateTime nowTime = DateTime.Now;
                    OA_SubjectSet m_OA_SubjectSet = bll_OA_SubjectSetBLL.getSingleSubject(SubjectId);
                    OA_FirmAccount m_OA_FirmAccountOut = bll_OA_FirmAccountBLL.getSingleSubject(AccountIdOut);
 
                    if (m_OA_FirmAccountOut.Balance < money)
                    {
                        JavaScript.MessageBox("账户余额不足", this);
                    }
                    else
                    {
                        var id = this.Keyid.Value.ToInt32().Value;
                        var fukuanshenqing = _fukuanshenqingBLL.GetModelByKeyid(id);
 
                        if (fukuanshenqing.FukuanStatus == 2 && money>0)
                        {
                            JavaScript.MessageBox("该申请已经付款结束!", this);
                            return;
                        }
 
                        if (money > (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney))
                        {
                            JavaScript.MessageBox("操作金额大于剩余应付金额!", this);
                            return;
                        }
 
                        var Youwufapiao = Request["rdoReceiveQuannbu"];
                        if (fukuanshenqing.Youwufapiao == 2 && Youwufapiao == "1")
                        {
                            JavaScript.MessageBox("已经保存为有发票,无法修改为无发票!", this);
                            return;
                        }
 
                        if (molingmoney.HasValue)
                        {
                            if ((money + molingmoney.Value) != (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney))
                            {
                                JavaScript.MessageBox("操作金额加抹零金额必须等于剩余应付金额!", this);
                                return;
                            }
                        }
 
                        string[] Keys = fukuanshenqing.DindanId.Trim(',').Split(',');
                        var ssss = false;
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
                new TransactionOptions
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                    Timeout = TransactionManager.MaximumTimeout
                }
                ))
                        {
                            try
                            {
                                var yishoumoney = fukuanshenqing.Yishoumoney.HasValue ? fukuanshenqing.Yishoumoney.Value : 0;
                                if (money >= (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney))
                                {
                                    fukuanshenqing.FukuanStatus = 2;
                                }
                                if (molingmoney.HasValue)
                                {
                                    if ((money + molingmoney.Value) >= (fukuanshenqing.Fukuanmoney - fukuanshenqing.Yishoumoney))
                                    {
                                        fukuanshenqing.FukuanStatus = 2;
                                    }
                                }
                                fukuanshenqing.Yishoumoney = yishoumoney + money;
                                fukuanshenqing.Updater = CurrentUser.ShortName;
                                fukuanshenqing.LastUpdateTime = DateTime.Now;
                                fukuanshenqing.Youwufapiao = Youwufapiao.ToInt32();
                                ssss = _fukuanshenqingBLL.UpdateModel(fukuanshenqing);
                                if (this.txtReciveMoney.Value.ToDecimal2() > 0)
                                {
                                    List<OA_Procurement> m_OA_ProcurementList = new List<OA_Procurement>();
                                    List<OA_FirmAccountRecord> m_OA_FirmAccountRecordList = new List<OA_FirmAccountRecord>();
                                    m_OA_FirmAccountOut.Balance -= money;
                                    m_OA_FirmAccountOut.AllExpenses += money;
                                    decimal molingmoneyvalue = 0;
                                    if (molingmoney.HasValue)
                                    {
                                        molingmoneyvalue = molingmoney.Value;
                                    }
                                    foreach (var item in Keys)
                                    {
                                        OA_Procurement m_OA_Procurement = bll_OA_ProcurementBLL.SelectSingleModel(item);
                                        if (m_OA_Procurement != null)
                                        {
                                           
 
 
                                            OA_Suppliers m_OA_Suppliers = bll_OA_SuppliersBLL.getSingleSupplier(m_OA_Procurement.SuppliersId.ToString2());
                                            OA_FirmAccountRecord m_OA_FirmAccountRecordOut = new OA_FirmAccountRecord();
                                            m_OA_FirmAccountRecordOut.AccountId = m_OA_FirmAccountOut.Keyid;
                                            m_OA_FirmAccountRecordOut.RecordTypeId = 2;//支出
 
                                            m_OA_FirmAccountRecordOut.Money = m_OA_Procurement.AllMoney.Value;
                                            m_OA_Procurement.ReceiveMoney = m_OA_Procurement.AllMoney.Value ;
                                            if (molingmoneyvalue > 0)
                                            {
                                                if (m_OA_Procurement.AllMoney.Value >= molingmoneyvalue)
                                                {
                                                    m_OA_Procurement.ReceiveMoney = m_OA_Procurement.AllMoney.Value  - molingmoneyvalue;
                                                    m_OA_FirmAccountRecordOut.Money = m_OA_Procurement.AllMoney.Value  - molingmoneyvalue;
                                                    molingmoneyvalue = 0;
                                                }
                                                else
                                                {
                                                    m_OA_Procurement.ReceiveMoney = 0;
                                                    m_OA_FirmAccountRecordOut.Money = 0;
                                                    molingmoneyvalue = molingmoneyvalue - m_OA_Procurement.AllMoney.Value;
                                                }
 
                                            }
 
                                            m_OA_FirmAccountRecordOut.SubjectId = m_OA_SubjectSet.Keyid;
                                            m_OA_FirmAccountRecordOut.OperationalMatters = "采购付款";
                                            m_OA_FirmAccountRecordOut.PaymentUnit = m_OA_Suppliers.Name;
                                            m_OA_FirmAccountRecordOut.LastUpdateTime = nowTime;
                                            m_OA_FirmAccountRecordOut.Operator = CurrentUser.ShortName.ToString2();
                                            m_OA_FirmAccountRecordOut.Remark = "";
                                            m_OA_FirmAccountRecordOut.ResidualAmount = m_OA_FirmAccountOut.Balance;
                                            m_OA_FirmAccountRecordList.Add(m_OA_FirmAccountRecordOut);
                                            m_OA_ProcurementList.Add(m_OA_Procurement);
 
                                            
 
 
 
 
                                            if (m_OA_Procurement.ReceiveMoney == m_OA_Procurement.AllMoney)
                                                m_OA_Procurement.ClearingStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(1, "结账状态");
 
                                            if (fukuanshenqing.FukuanStatus == 2)
                                                m_OA_Procurement.ClearingStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(1, "结账状态");
 
                                            m_OA_Procurement.Operator = CurrentUser.ShortName;
                                            m_OA_Procurement.LastUpdateTime = DateTime.Now;
 
                                        }
                                    }
 
 
                                    if (m_OA_ProcurementList.Count > 0)
                                    {
                                        ssss = bll_OA_FirmAccountBLL.PurchasePayList(m_OA_FirmAccountRecordList, m_OA_ProcurementList, m_OA_FirmAccountOut);
                                        if (!string.IsNullOrEmpty(this.selSubject.Value))
                                        {
                                            var oA_SubjectSet = _OA_SubjectSetBLL.getSingleSubject(m_OA_FirmAccountRecordList[0].SubjectId);
                                            if (oA_SubjectSet.SubjectName.IndexOf("投标保证金") >= 0 || oA_SubjectSet.SubjectName.IndexOf("履约保证金") >= 0)
                                            {
                                                //如果选择科目是保证金,插入以条保证金数据
                                                OA_Baozhengjin oA_Baozhengjin = new OA_Baozhengjin();
                                                oA_Baozhengjin.FirmId = CurrentUser.MemberId;
                                                oA_Baozhengjin.FukuanTime = DateTime.Now;
 
                                                oA_Baozhengjin.Zhanghuleixing = this.selAcoountTypeOut.Value;
 
                                                var ss = _Sys_DictionaryBLL.GetDataByType("账户类型").FirstOrDefault(x => x.Name == oA_Baozhengjin.Zhanghuleixing);
                                                if (ss != null)
                                                {
                                                    oA_Baozhengjin.ReceiveWay = ss.Keyid;
                                                }
 
                                                oA_Baozhengjin.Account = Request["selAccountName"].ToInt32();
                                                oA_Baozhengjin.Fukuanzhanghu = m_OA_FirmAccountOut.AccountName + "-" + m_OA_FirmAccountOut.UserName;
                                                oA_Baozhengjin.Subject = m_OA_FirmAccountRecordList[0].SubjectId;
                                                oA_Baozhengjin.Fukuankemu = oA_SubjectSet.SubjectName;
                                                oA_Baozhengjin.Fukuanmoney = money;
                                                oA_Baozhengjin.Shoukuandanwei = m_OA_FirmAccountRecordList[0].PaymentUnit;
                                                oA_Baozhengjin.remark = m_OA_FirmAccountRecordList[0].OperationalMatters;
                                                oA_Baozhengjin.TuikuanTime = null;
 
                                                oA_Baozhengjin.TuikuanStatus = 1;
                                                oA_Baozhengjin.Creater = CurrentUser.ShortName;
                                                oA_Baozhengjin.CreateTime = oA_Baozhengjin.FukuanTime;
                                                oA_Baozhengjin.Updater = CurrentUser.ShortName;
                                                oA_Baozhengjin.LastUpdateTime = oA_Baozhengjin.FukuanTime;
                                                oA_Baozhengjin.MemberName = fukuanshenqing.Creater;
 
                                                var oA_Staff = staffBLL.SelectListByFirmId(CurrentUser.MemberId, false, false).Where(x => x.Name == oA_Baozhengjin.MemberName).FirstOrDefault();
                                                oA_Baozhengjin.MemberId = oA_Staff.Keyid;
 
                                                var sss = oA_BaozhengjinBLL.InsertModel(oA_Baozhengjin);
 
                                            }
                                        }
                                    }
                                }
 
                                  
 
                                if (ssss)
                                {
 
                                    scope.Complete();
                                    JavaScript.MessageBox("付款成功", this, "top.frmright.ReLoad();top.Dialog.close();");
                                }
                                else
                                    JavaScript.MessageBox("添加失败", this);
                            }
                            catch (Exception ex)
                            {
                                PAGEHandleException(ex);
                                JavaScript.MessageBox("添加失败", this);
                            }
                            finally
                            {
                                scope.Dispose();
                            }
 
                        }
 
 
                       
                      
                    }
                }
 
            }
            catch (Exception ex)
            {
                PAGEHandleException(ex);
                JavaScript.MessageBox("操作失败", this);
            }
        }
 
    }
}