using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Web;
|
using System.Web.UI;
|
using System.Web.UI.WebControls;
|
using CY.BLL.OA;
|
using System.Data;
|
using System.Data.SqlClient;
|
using CY.Infrastructure.Common;
|
using CY.Model;
|
using CY.BLL.Sys;
|
|
namespace CY.WebForm.Pages.financial
|
{
|
//吴辉
|
//采购付款选择账户
|
public partial class PurchasePayEdit : BasePage
|
{
|
|
OA_WarehouseInfoBLL _OA_WarehouseInfoBLL = null;
|
OA_CargoSpaceBLL _OA_CargoSpaceBLL = null;
|
OA_OutOfStorageBLL bll_OA_OutOfStorageBLL = null;
|
OA_SubjectSetBLL bll_OA_SubjectSetBLL = null;
|
Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
|
OA_ProcurementBLL bll_OA_ProcurementBLL = null;
|
OA_FirmAccountBLL bll_OA_FirmAccountBLL = null;
|
OA_SuppliersBLL bll_OA_SuppliersBLL = null;
|
decimal? AllMoney = 0;
|
decimal? ReceiveMoney = 0;
|
//初始化
|
public PurchasePayEdit()
|
{
|
bll_OA_OutOfStorageBLL = new OA_OutOfStorageBLL();
|
_OA_WarehouseInfoBLL = new OA_WarehouseInfoBLL();
|
_OA_CargoSpaceBLL = new OA_CargoSpaceBLL();
|
bll_OA_SubjectSetBLL = new OA_SubjectSetBLL();
|
bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
|
bll_OA_ProcurementBLL = new OA_ProcurementBLL();
|
bll_OA_FirmAccountBLL = new OA_FirmAccountBLL();
|
bll_OA_SuppliersBLL = new OA_SuppliersBLL();
|
}
|
|
//页面加载
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
if (!IsPostBack)
|
{
|
InitialData();
|
}
|
|
}
|
|
//加载数据
|
protected void InitialData()
|
{
|
//科目名称
|
this.selSubject.DataSource = bll_OA_SubjectSetBLL.getAllSubject(CurrentUser.MemberId, "贷");
|
this.selSubject.DataBind();
|
this.selSubject.Items.Insert(0, new ListItem("请选择", ""));
|
|
//账户类型
|
this.selAcoountTypeOut.DataSource = bll_Sys_DictionaryBLL.GetDataByType("账户类型");
|
this.selAcoountTypeOut.DataBind();
|
|
string[] Keys = Request["Keyid"].ToString2().Trim('|').Split('|');
|
foreach (var item in Keys)
|
{
|
if (!string.IsNullOrEmpty(item))
|
{
|
OA_Procurement m_OA_Procurement = bll_OA_ProcurementBLL.SelectSingleModel(item);
|
if (m_OA_Procurement != null)
|
{
|
AllMoney += m_OA_Procurement.AllMoney;
|
ReceiveMoney += (m_OA_Procurement.AllMoney - m_OA_Procurement.ReceiveMoney);
|
}
|
}
|
}
|
|
if (Request["amount"].ToString2() == "one")
|
{
|
this.spanAllMoney.InnerHtml = "¥" + (AllMoney ?? 0).ToString("0.00");
|
this.spanReceiveMoney.InnerHtml = "¥" + (ReceiveMoney ?? 0).ToString("0.00");
|
this.spanCountRe.InnerHtml = "1 单";
|
|
this.txtReciveMoney.Enabled = true;
|
this.txtReciveMoney.Text = (ReceiveMoney ?? 0).ToString("0.00");
|
this.txtReciveMoney.Attributes.Add("max", (ReceiveMoney ?? 0).ToString("0.00"));
|
|
}
|
else
|
{
|
this.spanAllMoney.InnerHtml = "¥" + (AllMoney ?? 0).ToString("0.00");
|
this.spanReceiveMoney.InnerHtml = "¥" + ReceiveMoney.Value.ToString("0.00");
|
this.spanCountRe.InnerHtml = Keys.Count().ToString2() + " 单";
|
|
this.txtReciveMoney.Enabled = false;
|
this.txtReciveMoney.Text = (ReceiveMoney ?? 0).ToString("0.00");
|
this.txtReciveMoney.Attributes.Add("max", (ReceiveMoney ?? 0).ToString("0.00"));
|
}
|
}
|
|
//提交事件
|
protected void btn_Submit_form(object sender, EventArgs e)
|
{
|
try
|
{
|
|
string[] Keys = Request["Keyid"].ToString2().Trim('|').Split('|');
|
foreach (var item in Keys)
|
{
|
if (!string.IsNullOrEmpty(item))
|
{
|
OA_Procurement m_OA_Procurement = bll_OA_ProcurementBLL.SelectSingleModel(item);
|
if (m_OA_Procurement != null)
|
{
|
AllMoney += (m_OA_Procurement.AllMoney - m_OA_Procurement.ReceiveMoney);
|
ReceiveMoney += (m_OA_Procurement.AllMoney - m_OA_Procurement.ReceiveMoney);
|
}
|
}
|
}
|
|
int? SubjectId = this.selSubject.Value.ToInt32();
|
|
decimal? money = ReceiveMoney;
|
if (Request["amount"].ToString2() == "one")
|
{
|
money = this.txtReciveMoney.Text.ToDecimal2();
|
}
|
|
int? AccountIdOut = Request["selAccountNameOut"].ToInt32();
|
|
if (SubjectId == null || money == null || AccountIdOut == null)
|
JavaScript.MessageBox("操作失败", this);
|
else
|
{
|
DateTime nowTime = DateTime.Now;
|
OA_SubjectSet m_OA_SubjectSet = bll_OA_SubjectSetBLL.getSingleSubject(SubjectId);
|
OA_FirmAccount m_OA_FirmAccountOut = bll_OA_FirmAccountBLL.getSingleSubject(AccountIdOut);
|
|
if (m_OA_FirmAccountOut.Balance < money)
|
{
|
JavaScript.MessageBox("账户余额不足", this);
|
}
|
else
|
{
|
List<OA_Procurement> m_OA_ProcurementList = new List<OA_Procurement>();
|
List<OA_FirmAccountRecord> m_OA_FirmAccountRecordList = new List<OA_FirmAccountRecord>();
|
m_OA_FirmAccountOut.Balance -= money;
|
m_OA_FirmAccountOut.AllExpenses += money;
|
foreach (var item in Keys)
|
{
|
OA_Procurement m_OA_Procurement = bll_OA_ProcurementBLL.SelectSingleModel(item);
|
if (m_OA_Procurement != null)
|
{
|
if (Request["amount"].ToString2() == "one")
|
m_OA_Procurement.ReceiveMoney += money;
|
else
|
m_OA_Procurement.ReceiveMoney = m_OA_Procurement.AllMoney;
|
|
if (m_OA_Procurement.ReceiveMoney == m_OA_Procurement.AllMoney)
|
m_OA_Procurement.ClearingStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(1, "结账状态");
|
|
m_OA_Procurement.Operator = CurrentUser.ShortName;
|
m_OA_Procurement.LastUpdateTime = DateTime.Now;
|
|
|
OA_Suppliers m_OA_Suppliers = bll_OA_SuppliersBLL.getSingleSupplier(m_OA_Procurement.SuppliersId.ToString2());
|
OA_FirmAccountRecord m_OA_FirmAccountRecordOut = new OA_FirmAccountRecord();
|
m_OA_FirmAccountRecordOut.AccountId = m_OA_FirmAccountOut.Keyid;
|
m_OA_FirmAccountRecordOut.RecordTypeId = 2;//支出
|
|
if (Request["amount"].ToString2() == "one")
|
m_OA_FirmAccountRecordOut.Money = money;
|
else
|
m_OA_FirmAccountRecordOut.Money = (m_OA_Procurement.AllMoney - m_OA_Procurement.ReceiveMoney);
|
|
m_OA_FirmAccountRecordOut.SubjectId = m_OA_SubjectSet.Keyid;
|
m_OA_FirmAccountRecordOut.OperationalMatters = "采购付款";
|
m_OA_FirmAccountRecordOut.PaymentUnit = m_OA_Suppliers.Name;
|
m_OA_FirmAccountRecordOut.LastUpdateTime = nowTime;
|
m_OA_FirmAccountRecordOut.Operator = CurrentUser.ShortName.ToString2();
|
m_OA_FirmAccountRecordOut.Remark = "";
|
m_OA_FirmAccountRecordOut.ResidualAmount = m_OA_FirmAccountOut.Balance;
|
m_OA_FirmAccountRecordList.Add(m_OA_FirmAccountRecordOut);
|
m_OA_ProcurementList.Add(m_OA_Procurement);
|
}
|
}
|
if (m_OA_ProcurementList.Count > 0)
|
{
|
//bll_OA_FirmAccountBLL.PurchasePayList(m_OA_FirmAccountRecordList, m_OA_ProcurementList, m_OA_FirmAccountOut)
|
if (bll_OA_FirmAccountBLL.PurchasePayList(m_OA_FirmAccountRecordList, m_OA_ProcurementList, m_OA_FirmAccountOut))
|
JavaScript.RefreshDIVOpener(this);
|
else
|
JavaScript.MessageBox("付款失败", this);
|
}
|
else
|
JavaScript.MessageBox("付款失败", this);
|
}
|
}
|
|
}
|
catch (Exception ex)
|
{
|
PAGEHandleException(ex);
|
JavaScript.MessageBox("操作失败", this);
|
}
|
}
|
|
}
|
}
|