username@email.com
2024-12-05 991dbfbad93e1cb12d589b02100ac81a847a72f8
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.EC;
using CY.Model;
using CY.Infrastructure.Common;
using CY.BLL.Integrity;
using CY.BLL;
using System.Threading.Tasks;
using System.Transactions;
 
namespace CY.WebForm.Pages.business
{
    //吴辉
    //卖家评价
    public partial class kaipiaoConfirm : BasePage
    {
        EC_OrderBasicBLL bll_EC_OrderBasicBLL = null;
        EC_OrderBLL _eC_OrderBLL = null;
        OA_KaipiaoshenqingBLL _oA_KaipiaoshenqingBLL = null;
        OA_CorporateClientsBLL _oA_CorporateClientsBLL = null;
        OA_StaffBLL bll_OA_StaffBLL = null;
        OA_WorkPlanBll oA_WorkReminderBll = null;
 
 
        //初始化
        public kaipiaoConfirm()
        {
            bll_EC_OrderBasicBLL = new EC_OrderBasicBLL();
            _eC_OrderBLL = new EC_OrderBLL();
            _oA_CorporateClientsBLL = new OA_CorporateClientsBLL();
            _oA_KaipiaoshenqingBLL = new OA_KaipiaoshenqingBLL();
            bll_OA_StaffBLL = new OA_StaffBLL();
            oA_WorkReminderBll = new OA_WorkPlanBll();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }
 
        //绑定数据
        public void InitData()
        {
            string orderIdStr = Request["id"];
            if (!string.IsNullOrEmpty(orderIdStr))
            {
                this.selBusinessManager.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, true, false);
                this.selBusinessManager.DataTextField = "Name";
                this.selBusinessManager.DataValueField = "Keyid";
                this.selBusinessManager.DataBind();
                //this.selBusinessManager.Items.Insert(0, new ListItem("全部", ""));
                //this.selBusinessManager.Items.Insert(1, new ListItem(CurrentUser.ShortName, CurrentUser.ShortName));
 
                decimal total = 0;
                string name = "";
                this.txtOrderIds.Value = orderIdStr;
                // string[] idsArray = orderIdStr.Split(',');
                //if (idsArray != null && idsArray.Length > 0)
                //{
 
 
                var models = _eC_OrderBLL.GetOrderByIds(orderIdStr).ToList();
                if(models!=null&& models.Count > 0)
                {
                    var model = bll_EC_OrderBasicBLL.SelectModelById(models[0].Keyid.Value);
                    name = models[0].BuyerName;
                    this.selBusinessManager.Value = model.BusinessManagerId.HasValue? model.BusinessManagerId.Value.ToString():"";
                }
                total = models.Sum(x=>x.SumPrice)??0;
                txtZengjianmoney.Value = "0";
 
 
                    //foreach (var item in idsArray)
                    //{
                    //    var model = _eC_OrderBLL.GetOrderById(int.Parse(item));
                    //    if (model != null)
                    //    {
                    //        total += model.SumPrice??0;
                    //        if(string.IsNullOrEmpty(name))
                    //        {
                    //            name = model.BuyerName;
                    //        }
                    //    }
                    //}
                    //}
                kpmoney.InnerText = total.ToString("0.00");
                khname.InnerText = name;
                Dingdanshu.InnerText = orderIdStr.Split(',').Length +"个";
            }
            else
            {
                JavaScript.CloseDIVOpener(this);
            }
        }
 
        //提交事件
        protected void btn_Submit_form(object sender, EventArgs e)
        {
            AcceptAll3();                        
        }
 
        /// <summary>
        /// 批量开票申请
        /// </summary>
        public void AcceptAll3()
        {
            string ids = this.txtOrderIds.Value;
            string[] idsArray = ids.Split(',');
            if (idsArray != null && idsArray.Length > 0)
            {
                EC_OrderBasic eC_OrderBasic = bll_EC_OrderBasicBLL.SelectModelById(idsArray[0].ToInt32().Value);
                OA_CorporateClients oA_CorporateClients = _oA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, eC_OrderBasic.BuyerId);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
           new TransactionOptions
           {
               IsolationLevel = IsolationLevel.ReadCommitted,
               Timeout = TransactionManager.MaximumTimeout
           }
           )
                    )
                {
 
                    try
                    {
                        string ssss = DateTime.Now.ToString("yyyyMMdd");
                        string SellerOrderId = ssss + 1.ToString("000");
 
                        string maxSellerOrderId = _oA_KaipiaoshenqingBLL.GetModelByformid(CurrentUser.MemberId).Where(x => x.SellerOrderId.Contains(ssss)).Max(x => x.SellerOrderId);
                        if (!string.IsNullOrWhiteSpace(maxSellerOrderId))
                        {
                            string aaaaaaaaaaaa = maxSellerOrderId.Substring(maxSellerOrderId.Length - 3, 3);
                            SellerOrderId = ssss + (aaaaaaaaaaaa.ToInt32().Value + 1).ToString("000");
                        }
                        OA_Kaipiaoshenqing oA_DeliverPlan = new OA_Kaipiaoshenqing();
 
 
                        oA_DeliverPlan.Keyid = Guid.NewGuid();
                        oA_DeliverPlan.FirmId = CurrentUser.MemberId;
                        oA_DeliverPlan.BuyerId = eC_OrderBasic.BuyerId;
                        oA_DeliverPlan.Kaipiaoshenqing = 1;
                        oA_DeliverPlan.Kehuqianshou = 1;
                        oA_DeliverPlan.SellerOrderId = SellerOrderId;
                        oA_DeliverPlan.remark = this.txtContent.Value;//.Replace("\r\n", "<br>");
 
                        oA_DeliverPlan.KehuqianshouTime = null;
                        oA_DeliverPlan.KehuqianshouCreater = null;
                        oA_DeliverPlan.KaipiaoquerenTime = null;
                        oA_DeliverPlan.KaipiaoquerenCreater = null;
                        oA_DeliverPlan.BusinessManagerId = this.selBusinessManager.Value.ToInt32();
                        oA_DeliverPlan.Zengjianmoney = this.txtZengjianmoney.Value.ToDecimal2();
                        oA_DeliverPlan.kpmoney = this.kpmoney.InnerText.ToDecimal2();
                        oA_DeliverPlan.ApprovalStatus = 1;
                        oA_DeliverPlan.Dingdanshu = ids.Trim(',').Split(',').Length;
                        if (oA_DeliverPlan.Zengjianmoney < 0)
                        {
                            oA_DeliverPlan.ApprovalStatus = 0;
                            //需要添加审批信息
                            DateTime nowTime = DateTime.Now;
                            OA_WorkPlan m_OA_WorkPlan = new OA_WorkPlan();
                            m_OA_WorkPlan.ApprovalContent = "";
                            m_OA_WorkPlan.ApprovalStaffId = Guid.Empty;
                            m_OA_WorkPlan.ApprovalStaffName = "";
                            m_OA_WorkPlan.ApprovalStatus = 0;
                            m_OA_WorkPlan.ApprovalTime = nowTime;
                            m_OA_WorkPlan.EvaluationContent = "";
                            m_OA_WorkPlan.EvaluationStaff = "";
                            m_OA_WorkPlan.EvaluationStaffId = Guid.Empty;
                            m_OA_WorkPlan.EvaluationStatus = 0;
                            m_OA_WorkPlan.EvaluationTime = nowTime;
                            m_OA_WorkPlan.RewardContent = "";
                            m_OA_WorkPlan.RewardMoney = 0;
                            m_OA_WorkPlan.RewardResult = "";
                            m_OA_WorkPlan.RewardType = 0;
 
                            m_OA_WorkPlan.PlanStartTime = nowTime;
                            m_OA_WorkPlan.PlanStatus = 1;
                            m_OA_WorkPlan.SentStaffId = CurrentUser.TrueMemberId;
                            m_OA_WorkPlan.MemberId = CurrentUser.MemberId;
 
                            OA_Staff m_OA_Staff = bll_OA_StaffBLL.GetModelByMemberId(CurrentUser.TrueMemberId);
                            if (m_OA_Staff != null)
                                m_OA_WorkPlan.DepartId = m_OA_Staff.DepartmentId;
                            else
                                m_OA_WorkPlan.DepartId = 0;
 
                            m_OA_WorkPlan.PlanPeople = CurrentUser.TrueName;
                            m_OA_WorkPlan.ReciveStaffId = CurrentUser.TrueMemberId;
 
                            m_OA_WorkPlan.Operator = CurrentUser.ShortName;
                            m_OA_WorkPlan.PlanComplany = oA_DeliverPlan.Keyid.ToString();
                            m_OA_WorkPlan.PlanContent = this.khname.InnerText+" 减少金额开票申请";
                            m_OA_WorkPlan.PlanDataType = 13;
                            m_OA_WorkPlan.PlanMoney = oA_DeliverPlan.Zengjianmoney;
                            m_OA_WorkPlan.PlanRemark = oA_DeliverPlan.remark;
                            m_OA_WorkPlan.PlanRunTime = DateTime.Now;
                            m_OA_WorkPlan.PlanTitle = this.khname.InnerText + " 减少金额开票申请"; 
                            m_OA_WorkPlan.PlanType = 3;
                            m_OA_WorkPlan.LastUpdateTime = nowTime;
                            oA_WorkReminderBll.InsertModel(m_OA_WorkPlan);
                        }
                        oA_DeliverPlan.Shenqingleixing = "订单开票";
                        oA_DeliverPlan.Creater = CurrentUser.TrueMemberId;
                        oA_DeliverPlan.CreateTime = DateTime.Now;
                        oA_DeliverPlan.Updater = CurrentUser.TrueMemberId;
                        oA_DeliverPlan.LastUpdateTime = DateTime.Now;
 
                        _oA_KaipiaoshenqingBLL.InsertModel(oA_DeliverPlan);
 
                        DateTime kaipiaoshenqing = DateTime.Now;
                        //for (int i = 0; i < idsArray.Length; i++)
                        //{
                        bool result = true;
                        EC_OrderExtend model = new EC_OrderExtend();
                        //model.Keyid = idsArray[i].ToInt32();
                        model.KaipiaoshenqingCreater = CurrentUser.TrueMemberId;
                        model.KaipiaoshenqingTime = kaipiaoshenqing;
                        model.Kaipiaoshenqing = 1;
                        model.KaipiaoshenqingId = oA_DeliverPlan.Keyid;
 
                        result = _eC_OrderBLL.OldUpdateKaipiaoshenqings(model, ids);
 
                        if (!result)
                        {
                            return;
                        }
                        //}
                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        // 回滚事务
                    }
                    finally
                    {
                        // 释放资源
                        scope.Dispose();
                    }
                }
                //JavaScript.MessageBox("提交成功", this);
 
                //操作成功
                JavaScript.MessageBoxsssss("提交成功", this, true, true);
            }
        }
    }
}