/**
|
* 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 InvoicingShoukuan : BasePage
|
{
|
private EC_OrderBasicBLL _eC_OrderBasicBLL = null;
|
|
private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
|
OA_KaipiaoshenqingBLL oA_KaipiaoshenqingBLL = null;
|
|
/// <summary>
|
/// 初始化构造
|
/// </summary>
|
public InvoicingShoukuan()
|
{
|
bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
|
oA_KaipiaoshenqingBLL = new OA_KaipiaoshenqingBLL();
|
_eC_OrderBasicBLL = new EC_OrderBasicBLL();
|
}
|
/// <summary>
|
/// 界面加载事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
|
//btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick);
|
if (!IsPostBack)
|
{
|
LoadOrder();
|
}
|
|
if (IsPostBack || IsCallback)
|
return;
|
InitPage();
|
|
}
|
|
/// <summary>
|
/// 提交按钮点击事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void btn_Submit_form(object sender, EventArgs e)
|
{
|
if (string.IsNullOrEmpty(this.txtReceiveMoney.Value) )
|
{
|
JavaScript.MessageBox("请填写收款金额!", this);
|
return;
|
}
|
|
if (this.txtReceiveMoney.Value.ToDecimal2() <= 0 )
|
{
|
JavaScript.MessageBox("请填写收款金额!", this);
|
return;
|
}
|
|
if (this.txtReceiveMoney.Value.ToDecimal2()> this.hidReceiveMoney.Value.ToDecimal2())
|
{
|
JavaScript.MessageBox("本次收款金额大于订单未付款!", this);
|
return;
|
}
|
|
|
|
var id = Request["id"];
|
//string[] orderIds = Request["ids"].Split(',');
|
string receiveWay = Request["rdoReceiveWay"];
|
|
var ids = this.ids.Value;
|
|
bool isWin = false;
|
Dictionary<int, object> searchParam = new Dictionary<int, object>();
|
|
SetParamValue(searchParam, 1, CurrentUser.MemberId);
|
SetParamValue(searchParam, 2, "");
|
SetParamValue(searchParam, 3, "");
|
SetParamValue(searchParam, 4, "");
|
SetParamValue(searchParam, 5, "");
|
SetParamValue(searchParam, 6, "");
|
SetParamValue(searchParam, 7, "");
|
SetParamValue(searchParam, 8, "");
|
SetParamValue(searchParam, 9, "");
|
SetParamValue(searchParam, 10, "");
|
SetParamValue(searchParam, 11, "");
|
SetParamValue(searchParam, 12, "");
|
SetParamValue(searchParam, 13, "");
|
SetParamValue(searchParam, 14, "");
|
SetParamValue(searchParam, 15, "");
|
SetParamValue(searchParam, 16, "");
|
SetParamValue(searchParam, 18, 0);
|
SetParamValue(searchParam, 19, CurrentUser.TrueMemberId);
|
SetParamValue(searchParam, 20, CurrentUser.StaffId);
|
SetParamValue(searchParam, 21, CurrentUser.TrueName);
|
SetParamValue(searchParam, 22, "");
|
SetParamValue(searchParam, 23, "");
|
SetParamValue(searchParam, 24, "");
|
SetParamValue(searchParam, 25, "");
|
SetParamValue(searchParam, 26, id.ToGuid2());
|
SearchParam = searchParam;
|
|
|
/// UCPager1.AspNetPager.CurrentPageIndex = 1;//重置页数
|
//再次查询
|
// AspNetPager_PageChanged(UCPager1.AspNetPager, new EventArgs());
|
Infrastructure.Query.Pagination pagination = new Infrastructure.Query.Pagination()
|
{
|
PageSize = 1000,// UCPager1.AspNetPager.PageSize,
|
PageIndex = 1// UCPager1.AspNetPager.CurrentPageIndex
|
};
|
var _orderBasicmodes = _eC_OrderBasicBLL.SelectModelPage_Seller(pagination, SearchParam);//.Where(x=>x.Quchudingdan == 2);
|
|
var eC_OrderBasicsmeixuan = new List<EC_OrderBasic>();
|
decimal xuanzhongjine = 0;
|
if (Request["rdoReceiveQuannbu"] == "1")
|
{
|
var idxuan = ids.Trim(',').Split(',');
|
int?[] intArray = new int?[idxuan.Length];
|
for (int i = 0; i < idxuan.Length; i++)
|
{
|
intArray[i] = int.Parse(idxuan[i]);
|
}
|
var intArrayList = intArray.ToList();
|
|
//未选中的订单
|
eC_OrderBasicsmeixuan = _orderBasicmodes.Where(x => !intArrayList.Contains(x.Keyid)).ToList();
|
//选中的订单
|
_orderBasicmodes = _orderBasicmodes.Where(x => intArrayList.Contains(x.Keyid)).ToList();
|
|
|
xuanzhongjine = _orderBasicmodes.Sum(x=>x.UnPayedMoney);
|
|
if (this.txtReceiveMoney.Value.ToDecimal2() < xuanzhongjine)
|
{
|
JavaScript.MessageBox("本次收款金额小于选中订单未付款!", this);
|
return;
|
}
|
}
|
|
|
|
using (var scope = new TransactionScope(TransactionScopeOption.Required,
|
new TransactionOptions
|
{
|
IsolationLevel = IsolationLevel.ReadCommitted,
|
Timeout = TransactionManager.MaximumTimeout
|
}
|
))
|
{
|
|
try
|
{
|
|
//var _orderBasicmodes = _eC_OrderBasicBLL.GetOrderByIds(ids);
|
if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(receiveWay))
|
{
|
JavaScript.MessageBox("传入参数错误!", this);
|
return;
|
}
|
if (null == _orderBasicmodes)
|
{
|
JavaScript.MessageBox("订单不存在或已删除!", this);
|
return;
|
}
|
|
|
|
int i = 0;
|
foreach (var _orderBasic in _orderBasicmodes)
|
{
|
if (_orderBasic.UnPayedMoney <= 0)
|
{
|
continue;
|
}
|
|
//EC_OrderBasic _orderBasic = _eC_OrderBasicBLL.SelectModelById(orderId.ToInt32().Value);
|
|
if (receiveWay == "0" && i == 0)
|
{
|
OA_CorporateClients m_OA_CorporateClients = bll_OA_CorporateClientsBLL.SelectModelByFirmIdandMemberId(CurrentUser.MemberId, _orderBasic.BuyerId);
|
if (m_OA_CorporateClients != null)
|
{
|
if (this.txtReceiveMoney.Value.ToDecimal2() > (m_OA_CorporateClients.Prepayments + m_OA_CorporateClients.Credit))
|
{
|
JavaScript.MessageBox("预付款不足!", this, "window.location='/Pages/financial/InvoicingShoukuan.aspx?id=" + Request["id"] + "'");
|
//Response.Redirect("/Pages/financial/OrderMoneyReceive.aspx?id=" + orderId);
|
return;
|
}
|
}
|
else
|
{
|
JavaScript.MessageBox("预付款不足!", this, "window.location='/Pages/financial/InvoicingShoukuan.aspx?id=" + Request["id"] + "'");
|
}
|
|
|
}
|
i = i + 1;
|
|
isWin = "0".Equals(receiveWay) ? UsePrepare(_orderBasic) : ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName, _orderBasic.UnPayedMoney);
|
if (!isWin)
|
{
|
JavaScript.MessageBox(_orderBasic.SellerOrderId + "收款失败!", this);
|
return;
|
//break;
|
}
|
|
}
|
if(Request["rdoReceiveQuannbu"] == "1" && this.txtReceiveMoney.Value.ToDecimal2() > xuanzhongjine)
|
{
|
var shengyujine = this.txtReceiveMoney.Value.ToDecimal2() - xuanzhongjine;
|
foreach (var _orderBasic in eC_OrderBasicsmeixuan)
|
{
|
if (_orderBasic.UnPayedMoney <= 0)
|
{
|
continue;
|
}
|
if (shengyujine <= 0)
|
{
|
break;
|
}
|
|
if(shengyujine<= _orderBasic.UnPayedMoney)
|
{
|
isWin = "0".Equals(receiveWay) ? UsePrepare(_orderBasic, shengyujine.Value) : ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName, shengyujine.Value);
|
shengyujine = 0;
|
}
|
else
|
{
|
isWin = "0".Equals(receiveWay) ? UsePrepare(_orderBasic) : ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName, _orderBasic.UnPayedMoney);
|
shengyujine = shengyujine-_orderBasic.UnPayedMoney;
|
}
|
|
|
if (!isWin)
|
{
|
JavaScript.MessageBox(_orderBasic.SellerOrderId + "收款失败!", this);
|
return;
|
//break;
|
}
|
|
}
|
}
|
|
|
|
|
scope.Complete();
|
}
|
catch (Exception ex)
|
{
|
// 回滚事务
|
}
|
finally
|
{
|
// 释放资源
|
scope.Dispose();
|
}
|
}
|
|
|
if (isWin)
|
{
|
JavaScript.MessageBox("操作成功", this);
|
|
JavaScript.RefreshDIVOpener(this);
|
}
|
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
|
// ;
|
|
|
}
|
|
/// <summary>
|
/// 加载页面数据
|
/// </summary>
|
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("请选择", ""));
|
this.selSubjects.Value = "1";
|
|
int i = -1;
|
//账户类型
|
List<Sys_Dictionary> accountsType = _Sys_DictionaryBLL.GetDataByType("账户类型") as List<Sys_Dictionary>;
|
Request.RequestContext.RouteData.DataTokens.Add("accountsTypes", null == accountsType || accountsType.Count == 0 ? "[]" : JsonHelper.GetJsonStringByObject(accountsType));
|
|
List<OA_FirmAccount> firmAccounts = oA_FirmAccountBLL.getAllSubject(CurrentUser.MemberId, "") as List<OA_FirmAccount>;
|
|
const string ACCOUNTSJSONKEY = "accounts";
|
if (null == firmAccounts)
|
{
|
Request.RequestContext.RouteData.DataTokens.Add(ACCOUNTSJSONKEY, "[]");
|
return;
|
}
|
|
IEnumerable<IGrouping<string, OA_FirmAccount>> groupings = firmAccounts.GroupBy(fa => fa.AccountType);
|
StringBuilder builder = new StringBuilder();
|
|
foreach (IGrouping<string, OA_FirmAccount> 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);
|
}
|
}
|
|
/// <summary>
|
/// 加载订单
|
/// </summary>
|
private void LoadOrder()
|
{
|
var id = Request["id"];
|
|
var a_Kaipiaoshenqing = oA_KaipiaoshenqingBLL.GetModelByKeyid(id.ToGuid2());
|
if (a_Kaipiaoshenqing != null)
|
{
|
var corporateClients = bll_OA_CorporateClientsBLL.GetModel(a_Kaipiaoshenqing.BuyerId);
|
if (corporateClients!=null)
|
{
|
this.txtBuyerName.Value = corporateClients.CompanyName;
|
}
|
this.txtFapiaohao.Value = a_Kaipiaoshenqing.Fapiaohao;
|
}
|
|
|
|
Dictionary<int, object> searchParam = new Dictionary<int, object>();
|
|
SetParamValue(searchParam, 1, CurrentUser.MemberId);
|
SetParamValue(searchParam, 2, "");
|
SetParamValue(searchParam, 3, "");
|
SetParamValue(searchParam, 4, "");
|
SetParamValue(searchParam, 5, "");
|
SetParamValue(searchParam, 6, "");
|
SetParamValue(searchParam, 7, "");
|
SetParamValue(searchParam, 8, "");
|
SetParamValue(searchParam, 9, "");
|
SetParamValue(searchParam, 10, "");
|
SetParamValue(searchParam, 11, "");
|
SetParamValue(searchParam, 12, "");
|
SetParamValue(searchParam, 13, "");
|
SetParamValue(searchParam, 14, "");
|
SetParamValue(searchParam, 15, "");
|
SetParamValue(searchParam, 16, "");
|
SetParamValue(searchParam, 18, 0);
|
SetParamValue(searchParam, 19, CurrentUser.TrueMemberId);
|
SetParamValue(searchParam, 20, CurrentUser.StaffId);
|
SetParamValue(searchParam, 21, CurrentUser.TrueName);
|
SetParamValue(searchParam, 22, "");
|
SetParamValue(searchParam, 23, "");
|
SetParamValue(searchParam, 24, "");
|
SetParamValue(searchParam, 25, "");
|
SetParamValue(searchParam, 26, id.ToGuid2());
|
SearchParam = searchParam;
|
|
|
/// UCPager1.AspNetPager.CurrentPageIndex = 1;//重置页数
|
//再次查询
|
// AspNetPager_PageChanged(UCPager1.AspNetPager, new EventArgs());
|
Infrastructure.Query.Pagination pagination = new Infrastructure.Query.Pagination()
|
{
|
PageSize = 1000,// UCPager1.AspNetPager.PageSize,
|
PageIndex = 1// UCPager1.AspNetPager.CurrentPageIndex
|
};
|
var _orderBasicmodes = _eC_OrderBasicBLL.SelectModelPage_Seller(pagination, SearchParam);//.Where(x=>x.Quchudingdan == 2);
|
|
|
|
//string[] orderIds = Request["id"];
|
// this.ids.Value = Request["id"];
|
//List<EC_OrderBasic> eC_OrderBasics = new List<EC_OrderBasic>();
|
decimal shoukuanmoney = 0;
|
decimal sumMoney = 0;
|
if (id == null || id.Length==0)
|
{
|
return;
|
}
|
|
try
|
{
|
//var _orderBasicmodes = _eC_OrderBasicBLL.GetOrderByIds(this.ids.Value);
|
foreach (var _orderBasicmode in _orderBasicmodes)
|
{
|
// 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";
|
//}
|
|
|
sumMoney += (_orderBasicmode.SumPrice.HasValue? _orderBasicmode.SumPrice.Value:0);
|
shoukuanmoney += _orderBasicmode.UnPayedMoney;
|
// eC_OrderBasics.Add(_orderBasicmode);
|
}
|
this.txtReceiveMoney.Value = String.Format("{0:F}", shoukuanmoney);
|
this.txtSumMoney.Value = String.Format("{0:F}", sumMoney);
|
this.hidReceiveMoney.Value = String.Format("{0:F}", shoukuanmoney);
|
this.NoMoney.InnerText = "0";
|
rptData.DataSource = _orderBasicmodes;
|
rptData.DataBind();
|
}
|
catch (Exception ex)
|
{
|
PAGEHandleException(ex);
|
JavaScript.MessageBox("订单不存在!", this);
|
}
|
|
|
}
|
|
/// <summary>
|
/// 收款到账户
|
/// </summary>
|
/// <param name="orderId"></param>
|
/// <param name="buyerName"></param>
|
/// <returns></returns>
|
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);
|
}
|
|
/// <summary>
|
/// 使用预付款(付款、收款)
|
/// </summary>
|
/// <returns></returns>
|
private bool UsePrepare(EC_OrderBasic _orderBasic, decimal UnPayedMoney = 0)
|
{
|
decimal? money = _orderBasic.UnPayedMoney;
|
if(UnPayedMoney > 0)
|
{
|
money = 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);
|
}
|
|
|
/// <summary>
|
/// 查询参数
|
/// </summary>
|
private Dictionary<int, object> SearchParam
|
{
|
get
|
{
|
return ViewState["SearchParam"] as Dictionary<int, object>;
|
}
|
set
|
{
|
ViewState["SearchParam"] = value;
|
}
|
}
|
|
/// <summary>
|
/// 设置查询参数方法
|
/// </summary>
|
/// <param name="target">设置目标</param>
|
/// <param name="key">键</param>
|
/// <param name="value">值</param>
|
private static void SetParamValue(Dictionary<int, object> target, int key, object value)
|
{
|
if (string.IsNullOrEmpty(string.Format("{0}", value)))
|
return;
|
else
|
{
|
}
|
|
if (target.ContainsKey(key))
|
{
|
target[key] = value;
|
}
|
else
|
{
|
target.Add(key, value);
|
}
|
}
|
|
}
|
}
|