/** * 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; namespace CY.WebForm.Pages.financial { /// /// 订单收款 /// public partial class OrderMoneyReceive : BasePage { private EC_OrderBasicBLL _eC_OrderBasicBLL = null; private EC_OrderBasic _orderBasic = null;//当前订单 private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null; /// /// 初始化构造 /// public OrderMoneyReceive() { 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) { int? orderId = MyConvert.ConvertToInt32(Request["id"]); string receiveWay = Request["rdoReceiveWay"]; _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.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/OrderMoneyReceive.aspx?id=" + orderId + "'"); //Response.Redirect("/Pages/financial/OrderMoneyReceive.aspx?id=" + orderId); return; } } if (!orderId.HasValue || 0 >= orderId.Value || string.IsNullOrEmpty(receiveWay)) { JavaScript.MessageBox("传入参数错误!", this); return; } if (null == _orderBasic) { JavaScript.MessageBox("订单不存在或已删除!", this); return; } bool isWin = "0".Equals(receiveWay) ? UsePrepare() : ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName); 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() { int? orderId = MyConvert.ConvertToInt32(Request["id"]); if (!orderId.HasValue || 0 >= orderId.Value) { return; } try { _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.Value); OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId,_orderBasic.BuyerId); if (m_OA_CorporateClients != null) { this.nowCustomMoney.InnerHtml = "¥" + (m_OA_CorporateClients.Prepayments ?? 0).ToString("0.00"); this.nowCredit.InnerHtml = "¥" + (m_OA_CorporateClients.Credit ?? 0).ToString("0.00"); } else { this.nowCustomMoney.InnerHtml = "¥0" ; this.nowCredit.InnerHtml = "¥0"; } rptOrderInfo.DataSource = new List() { _orderBasic }; rptOrderInfo.DataBind(); } catch (Exception ex) { PAGEHandleException(ex); JavaScript.MessageBox("订单不存在!", this); } } /// /// 收款到账户 /// /// /// /// private bool ToAccount(int orderId, string buyerName) { OA_FirmAccountRecord oA_FirmAccountRecord = new Model.OA_FirmAccountRecord(); oA_FirmAccountRecord.Money = MyConvert.ConvertToDecimal(txtReceiveMoney.Value); 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() { decimal? money = MyConvert.ConvertToDecimal(txtReceiveMoney.Value); 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); } } }