You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

97 lines
3.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BWP.B3Frameworks;
using BWP.B3Frameworks.Utils;
using BWP.B3QingDaoWanFu.Utils;
using BWP.B3Sale.BL;
using BWP.B3Sale.BO;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.JsonRpc;
using TSingSoft.WebPluginFramework;
namespace BWP.B3QingDaoWanFu.Rpc
{
[Rpc]
public static class GatheringRpc
{
[Rpc]
public static long Insert(Gathering dmo)
{
using (var context = new TransactionContext())
{
var bl = BIFactory.Create<IGatheringBL>(context);
// bl.InitNewDmo(dmo);
dmo.Domain_ID = DomainContext.Current.ID;
var dom = new DQueryDom(new JoinAlias(typeof(Customer)));
dom.Columns.Add(DQSelectColumn.Field("AccountCustomer_ID"));
dom.Columns.Add(DQSelectColumn.Field("AccountCustomer_Name"));
dom.Where.Conditions.Add(DQCondition.EQ("OuterCode", dmo.AccountCustomer_OuterCode));//
//找到该客户对应的结账客户
var info = dom.EExecuteScalar<long, string>(context.Session);
if (info == null)
throw new ApplicationException(string.Format("没有配置外部编码{0}的对应结账客户", dmo.AccountCustomer_OuterCode));
dmo.AccountCustomer_ID = info.Item1;
dmo.AccountCustomer_Name = info.Item2;
SetAccountCustomerInfo(dmo, context.Session);
var conf = new WanFuOnlineConfig();
if (conf.AccID.Value == 0)
{
throw new ApplicationException("没有配置会计单位");
}
if (conf.GatheringAccountID.Value == 0)
{
throw new ApplicationException("没有配置帐户");
}
if (conf.ReceiptTypeID.Value == 0)
{
throw new ApplicationException("没有配置收款类型");
}
dmo.AccountingUnit_ID = conf.AccID.Value;
dmo.ReceiptType_ID = conf.ReceiptTypeID.Value;
dmo.GatheringAccount_ID = conf.GatheringAccountID.Value;
// DmoUtil.RefreshDependency(dmo, "AccountingUnit_ID", "ReceiptType_ID", "GatheringAccount_ID"); 这里没有必要执行
bl.Insert(dmo);
bl.Check(dmo);
context.Commit();
}
return dmo.ID;
}
private static void SetAccountCustomerInfo(Gathering dmo, IDmoSessionWithTransaction session)
{
var dom = new DQueryDom(new JoinAlias(typeof(Customer)));
new Customer().Employee_ID = 1;
dom.Columns.Add(DQSelectColumn.Field("Department_ID"));
dom.Columns.Add(DQSelectColumn.Field("Employee_ID"));
dom.Columns.Add(DQSelectColumn.Field("Department_Name"));
dom.Columns.Add(DQSelectColumn.Field("Employee_Name"));
dom.Where.Conditions.Add(DQCondition.EQ("ID", dmo.AccountCustomer_ID));
var tuple = EExecuteScalar<long?, long?, string, string>(dom, session);
if (tuple != null)
{
dmo.Department_ID = tuple.Item1;
dmo.Employee_ID = tuple.Item2;
dmo.Department_Name = tuple.Item3;
dmo.Employee_Name = tuple.Item4;
}
else
{
throw new ApplicationException(string.Format("不存在编号为{0}的客户", dmo.AccountCustomer_OuterCode));
}
}
static Tuple<T1, T2, T3, T4> EExecuteScalar<T1, T2, T3, T4>(DQueryDom query, IDmoSessionWithTransaction session)
{
var list = query.EExecuteList<T1, T2, T3, T4>(session);
return list.Count == 0 ? null : list[0];
}
}
}