/** * OrderMoneyReceive.aspx.cs * * 功 能: 订单收款 * 类 名: OrderMoneyReceive * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── * V0.01 2013-5-28 13:44 吴崎均 初版 * */ 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.Infrastructure.Common; using CY.Model; using CY.BLL.OA; using CY.BLL.Sys; using System.Text; using CY.BLL; using System.Transactions; namespace CY.WebForm.Pages.financial { public partial class OrderMoneyBatchReceive : BasePage { private EC_OrderBasicBLL _eC_OrderBasicBLL = null; private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null; /// /// 初始化构造 /// public OrderMoneyBatchReceive() { bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL(); } /// /// 界面加载事件 /// /// /// protected void Page_Load(object sender, EventArgs e) { _eC_OrderBasicBLL = new EC_OrderBasicBLL(); btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick); LoadOrder(); if (IsPostBack || IsCallback) return; InitPage(); } /// /// 提交按钮点击事件 /// /// /// void btnSubmit_ServerClick(object sender, EventArgs e) { string[] orderIds = Request["ids"].Split(','); string receiveWay = Request["rdoReceiveWay"]; bool isWin = false; using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TransactionManager.MaximumTimeout } )) { foreach (string orderId in orderIds) { EC_OrderBasic _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.ToInt32().Value); OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, _orderBasic.BuyerId); if (receiveWay == "0" && m_OA_CorporateClients != null) { if (this.txtReceiveMoney.Value.ToInt32() > (m_OA_CorporateClients.Prepayments + m_OA_CorporateClients.Credit)) { JavaScript.MessageBox("预付款不足!", this, "window.location='/Pages/financial/OrderMoneyBatchReceive.aspx?id=" + Request["ids"] + "'"); //Response.Redirect("/Pages/financial/OrderMoneyReceive.aspx?id=" + orderId); return; } } if (string.IsNullOrEmpty(orderId) || string.IsNullOrEmpty(receiveWay)) { JavaScript.MessageBox("传入参数错误!", this); return; } if (null == _orderBasic) { JavaScript.MessageBox("订单不存在或已删除!", this); return; } isWin = "0".Equals(receiveWay) ? UsePrepare(_orderBasic) : ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName, _orderBasic.UnPayedMoney); if (!isWin) { break; } } scope.Complete(); } if (isWin) { JavaScript.MessageBox("操作成功", this, true, true); } else { JavaScript.MessageBox("操作失败", this); } //JavaScript.MessageBox(isWin ? "收款成功!" : "收款失败!", this, "top.frmright.ReLoad();top.Dialog.close();"); Request.RequestContext.RouteData.DataTokens.Add("IsWin", isWin ? "1" : ""); if (!isWin) InitPage(); else ; } /// /// 加载页面数据 /// private void InitPage() { try { Sys_DictionaryBLL _Sys_DictionaryBLL = new Sys_DictionaryBLL(); OA_SubjectSetBLL _OA_SubjectSetBLL = new OA_SubjectSetBLL(); OA_FirmAccountBLL oA_FirmAccountBLL = new OA_FirmAccountBLL(); //科目名称 this.selSubjects.DataSource = _OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "借"); this.selSubjects.DataBind(); this.selSubjects.Items.Insert(0, new ListItem("请选择", "")); int i = -1; //账户类型 List accountsType = _Sys_DictionaryBLL.GetDataByType("账户类型") as List; Request.RequestContext.RouteData.DataTokens.Add("accountsTypes", null == accountsType || accountsType.Count == 0 ? "[]" : JsonHelper.GetJsonStringByObject(accountsType)); List firmAccounts = oA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, "") as List; const string ACCOUNTSJSONKEY = "accounts"; if (null == firmAccounts) { Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, "[]"); return; } IEnumerable> groupings = firmAccounts.GroupBy(fa => fa.AccountType); StringBuilder builder = new StringBuilder(); foreach (IGrouping groupitem in groupings) { OA_FirmAccount[] items = groupitem.ToArray(); builder.AppendFormat("{0}\"{2}\":{3}{1}", ",", "", groupitem.Key, JsonHelper.GetJsonStringByObject(items)); } builder.Append("}]"); builder.Replace(",", "[{", 0, 1); Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, null == firmAccounts ? "[]" : builder.ToString()); } catch (Exception ex) { PAGEHandleException(ex); } } /// /// 加载订单 /// private void LoadOrder() { string[] orderIds = Request["id"].Split(','); this.ids.Value = Request["id"]; List eC_OrderBasics = new List(); decimal shoukuanmoney = 0; if (orderIds==null || orderIds.Length==0) { return; } try { foreach (string orderId in orderIds) { EC_OrderBasic _orderBasicmode = _eC_OrderBasicBLL.SelectModelById(orderId.ToInt32().Value); OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, _orderBasicmode.BuyerId); if (m_OA_CorporateClients != null) { _orderBasicmode.nowCustomMoney = "¥" + (m_OA_CorporateClients.Prepayments ?? 0).ToString("0.00"); _orderBasicmode.nowCredit = "¥" + (m_OA_CorporateClients.Credit ?? 0).ToString("0.00"); } else { _orderBasicmode.nowCustomMoney = "¥0"; _orderBasicmode.nowCredit = "¥0"; } shoukuanmoney += _orderBasicmode.UnPayedMoney; eC_OrderBasics.Add(_orderBasicmode); } this.txtReceiveMoney.Value = String.Format("{0:F}", shoukuanmoney); //rptOrderInfo.DataSource = eC_OrderBasics; //rptOrderInfo.DataBind(); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("订单不存在!", this); } } /// /// 收款到账户 /// /// /// /// private bool ToAccount(int orderId, string buyerName,decimal UnPayedMoney) { OA_FirmAccountRecord oA_FirmAccountRecord = new Model.OA_FirmAccountRecord(); oA_FirmAccountRecord.Money = UnPayedMoney; oA_FirmAccountRecord.LastUpdateTime = MyConvert.ConvertToDateTime(txtReceiveDate.Value); if (!oA_FirmAccountRecord.Money.HasValue || 0 > oA_FirmAccountRecord.Money.Value) { return false; } if (!oA_FirmAccountRecord.LastUpdateTime.HasValue) { return false; } oA_FirmAccountRecord.Operator = CurrentUser.ShortName; oA_FirmAccountRecord.Remark = txtRemark.Value; oA_FirmAccountRecord.PaymentUnit = buyerName; oA_FirmAccountRecord.SubjectId = MyConvert.ConvertToInt32(selSubjects.Value); oA_FirmAccountRecord.AccountId = MyConvert.ConvertToInt32("0".Equals(Request["rdoReceiveWay"]) ? "0" : Request["selAccounts"]); if (!oA_FirmAccountRecord.AccountId.HasValue || 0 == oA_FirmAccountRecord.AccountId.Value) return false; return _eC_OrderBasicBLL.ReceiveMoneyToAccount(orderId, oA_FirmAccountRecord); } /// /// 使用预付款(付款、收款) /// /// private bool UsePrepare(EC_OrderBasic _orderBasic) { decimal? money = _orderBasic.UnPayedMoney; int operatTypeId = 3; string subject = "订单付款"; switch (Request["outsourceType"]) { case "1": operatTypeId = 2; subject = "外协付款"; break; default: break; } return _eC_OrderBasicBLL.ReceiveMoney(_orderBasic.SellerId, _orderBasic.BuyerId, _orderBasic.Keyid.Value, money.Value, operatTypeId, subject, CurrentUser.ShortName); } } }