/**
|
* 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 InvoicingShouruqueren : BasePage
|
{
|
private EC_OrderBasicBLL _eC_OrderBasicBLL = null;
|
|
private OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
|
OA_KaipiaoshenqingBLL oA_KaipiaoshenqingBLL = null;
|
OA_KaipiaoJineQuerenBLL oA_KaipiaoJineQuerenBLL = null;
|
|
/// <summary>
|
/// 初始化构造
|
/// </summary>
|
public InvoicingShouruqueren()
|
{
|
bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
|
oA_KaipiaoshenqingBLL = new OA_KaipiaoshenqingBLL();
|
_eC_OrderBasicBLL = new EC_OrderBasicBLL();
|
oA_KaipiaoJineQuerenBLL = new OA_KaipiaoJineQuerenBLL();
|
}
|
/// <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"];
|
|
|
var ids = this.ids.Value;
|
|
bool isWin = false;
|
|
|
var idssss = ids.Trim(',').Split(',');
|
|
var idsssssint = new List<int>();
|
foreach(var iddd in idssss)
|
{
|
idsssssint.Add(int.Parse(iddd));
|
}
|
var a_Kaipiaoshenqing = oA_KaipiaoshenqingBLL.GetModelByKeyid(id.ToGuid2());
|
var oA_KaipiaoJineQuerens = oA_KaipiaoJineQuerenBLL.GetModelBybuyerid(a_Kaipiaoshenqing.BuyerId).Where(x => x.Querenstatus == 0 && idsssssint.Contains(x.Keyid));
|
|
var ReceiveMoney = this.txtReceiveMoney.Value.ToDecimal2();
|
var WeiHexiaomoney = oA_KaipiaoJineQuerens.Sum(x=>x.WeiHexiaomoney);
|
|
if (WeiHexiaomoney< ReceiveMoney)
|
{
|
JavaScript.MessageBox("本次收款金额大于未确认收入!", this);
|
return;
|
}
|
|
|
|
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;
|
|
|
|
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);
|
using (var scope = new TransactionScope(TransactionScopeOption.Required,
|
new TransactionOptions
|
{
|
IsolationLevel = IsolationLevel.ReadCommitted,
|
Timeout = TransactionManager.MaximumTimeout
|
}
|
))
|
{
|
|
try
|
{
|
|
|
if (string.IsNullOrEmpty(id) )
|
{
|
JavaScript.MessageBox("传入参数错误!", this);
|
return;
|
}
|
if (null == _orderBasicmodes)
|
{
|
JavaScript.MessageBox("订单不存在或已删除!", this);
|
return;
|
}
|
//更新确认收入
|
decimal weiReceiveMoney = ReceiveMoney.Value;
|
foreach (var a_KaipiaoJineQueren in oA_KaipiaoJineQuerens)
|
{
|
if(a_KaipiaoJineQueren.WeiHexiaomoney <= weiReceiveMoney)
|
{
|
|
var a_KaipiaoJineQuerendetail = new OA_KaipiaoJineQuerendetail();
|
a_KaipiaoJineQuerendetail.KaipiaoJineQuerenId = a_KaipiaoJineQueren.Keyid;
|
a_KaipiaoJineQuerendetail.KaipiaoshenqingId = id.ToGuid2();
|
a_KaipiaoJineQuerendetail.Hexiaomoney = a_KaipiaoJineQueren.WeiHexiaomoney;
|
a_KaipiaoJineQuerendetail.Creater = CurrentUser.ShortName;
|
a_KaipiaoJineQuerendetail.CreateTime = DateTime.Now;
|
a_KaipiaoJineQuerendetail.Updater = CurrentUser.ShortName;
|
a_KaipiaoJineQuerendetail.LastUpdateTime = a_KaipiaoJineQuerendetail.CreateTime;
|
isWin = oA_KaipiaoJineQuerenBLL.InserModeldetail(a_KaipiaoJineQuerendetail);
|
|
weiReceiveMoney = ReceiveMoney.Value - a_KaipiaoJineQueren.WeiHexiaomoney.Value;
|
a_KaipiaoJineQueren.Hexiaomoney = a_KaipiaoJineQueren.Fukuanmoney;
|
a_KaipiaoJineQueren.Querenstatus = 1;
|
isWin = oA_KaipiaoJineQuerenBLL.UpdateModel(a_KaipiaoJineQueren);
|
}
|
else
|
{
|
var a_KaipiaoJineQuerendetail = new OA_KaipiaoJineQuerendetail();
|
a_KaipiaoJineQuerendetail.KaipiaoJineQuerenId = a_KaipiaoJineQueren.Keyid;
|
a_KaipiaoJineQuerendetail.KaipiaoshenqingId = id.ToGuid2();
|
a_KaipiaoJineQuerendetail.Hexiaomoney = weiReceiveMoney;
|
a_KaipiaoJineQuerendetail.Creater = CurrentUser.ShortName;
|
a_KaipiaoJineQuerendetail.CreateTime = DateTime.Now;
|
a_KaipiaoJineQuerendetail.Updater = CurrentUser.ShortName;
|
a_KaipiaoJineQuerendetail.LastUpdateTime = a_KaipiaoJineQuerendetail.CreateTime;
|
isWin = oA_KaipiaoJineQuerenBLL.InserModeldetail(a_KaipiaoJineQuerendetail);
|
|
|
a_KaipiaoJineQueren.Hexiaomoney = a_KaipiaoJineQueren.Hexiaomoney.Value + weiReceiveMoney;
|
|
isWin = oA_KaipiaoJineQuerenBLL.UpdateModel(a_KaipiaoJineQueren);
|
|
weiReceiveMoney = 0;
|
}
|
|
|
|
if (weiReceiveMoney <= 0)
|
{
|
break;
|
}
|
}
|
|
|
|
weiReceiveMoney = ReceiveMoney.Value;
|
foreach (var _orderBasic in _orderBasicmodes)
|
{
|
if (_orderBasic.UnPayedMoney <= 0)
|
{
|
continue;
|
}
|
decimal UnPayedMoney = _orderBasic.UnPayedMoney;
|
if (_orderBasic.UnPayedMoney > weiReceiveMoney)
|
{
|
UnPayedMoney = weiReceiveMoney;
|
weiReceiveMoney = 0;
|
}
|
else
|
{
|
weiReceiveMoney = weiReceiveMoney - _orderBasic.UnPayedMoney;
|
}
|
|
|
|
isWin = ToAccount(_orderBasic.Keyid.Value, _orderBasic.BuyerName, UnPayedMoney);
|
if (!isWin)
|
{
|
JavaScript.MessageBox(_orderBasic.SellerOrderId + "收款失败!", this);
|
return;
|
//break;
|
}
|
if (weiReceiveMoney<=0)
|
{
|
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();
|
|
|
|
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;
|
|
|
|
Infrastructure.Query.Pagination pagination = new Infrastructure.Query.Pagination()
|
{
|
PageSize = 1000,
|
PageIndex = 1
|
};
|
var _orderBasicmodes = _eC_OrderBasicBLL.SelectModelPage_Seller(pagination, SearchParam);
|
|
|
|
|
decimal shoukuanmoney = 0;
|
decimal sumMoney = 0;
|
if (id == null || id.Length==0)
|
{
|
return;
|
}
|
|
try
|
{
|
|
foreach (var _orderBasicmode in _orderBasicmodes)
|
{
|
|
|
sumMoney += (_orderBasicmode.SumPrice.HasValue? _orderBasicmode.SumPrice.Value:0);
|
shoukuanmoney += _orderBasicmode.UnPayedMoney;
|
|
}
|
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";
|
var oA_KaipiaoJineQuerens = oA_KaipiaoJineQuerenBLL.GetModelBybuyerid(a_Kaipiaoshenqing.BuyerId).Where(x => x.Querenstatus == 0);
|
rptData.DataSource = oA_KaipiaoJineQuerens;
|
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.ReceiveMoneyToQueren(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);
|
}
|
}
|
|
}
|
}
|