Commit b88ebf22 by 陶然

增加发票作废对接OA功能

parent e3bd28e8
......@@ -13,6 +13,89 @@ namespace Kivii.Finances.Seeyon.Extensions
{
internal static class ApplyExtension
{
public static string GetTemplateCodeSuffix(this string payeeName)
{
var rtns = string.Empty;
if (payeeName.Contains("南京市产品质量监督检验院")) rtns = "ZJY";
if (payeeName.Contains("深圳市宁深检验检测技术有限公司")) rtns = "NS";
if (payeeName.Contains("江苏苏测智能装备检测有限公司")) rtns = "ZB";
if (payeeName.Contains("江苏苏测检测认证有限公司")) rtns = "SC";
return rtns;
}
public static string ConvertToChinese(this decimal Num)
{
string[] DX_SZ = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };//大写数字
string[] DX_DW = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万" };
string[] DX_XSDS = { "角", "分" };//大些小数单位
if (Num == 0) return DX_SZ[0];
Boolean IsXS_bool = false;//是否小数
string NumStr;//整个数字字符串
string NumStr_Zs;//整数部分
string NumSr_Xs = "";//小数部分
string NumStr_R = "";//返回的字符串
NumStr = Num.ToString();
NumStr_Zs = NumStr;
if (NumStr_Zs.Contains("."))
{
NumStr = Math.Round(Num, 2).ToString();
NumStr_Zs = NumStr.Substring(0, NumStr.IndexOf("."));
NumSr_Xs = NumStr.Substring((NumStr.IndexOf(".") + 1), (NumStr.Length - NumStr.IndexOf(".") - 1));
IsXS_bool = true;
}
int k = 0;
Boolean IsZeor = false;//整数中间连续0的情况
for (int i = 0; i < NumStr_Zs.Length; i++) //整数
{
int j = int.Parse(NumStr_Zs.Substring(i, 1));
if (j != 0)
{
NumStr_R += DX_SZ[j] + DX_DW[NumStr_Zs.Length - i - 1];
IsZeor = false; //没有连续0
}
else if (j == 0)
{
k++;
if (!IsZeor && !(NumStr_Zs.Length == i + 1)) //等于0不是最后一位,连续0取一次
{
//有问题
if (NumStr_Zs.Length - i - 1 >= 4 && NumStr_Zs.Length - i - 1 <= 6)
NumStr_R += DX_DW[4] + "零";
else
if (NumStr_Zs.Length - i - 1 > 7)
NumStr_R += DX_DW[8] + "零";
else
NumStr_R += "零";
IsZeor = true;
}
if (NumStr_Zs.Length == i + 1)// 等于0且是最后一位 变成 XX元整
NumStr_R += DX_DW[NumStr_Zs.Length - i - 1];
}
}
if (NumStr_Zs.Length > 2 && k == NumStr_Zs.Length - 1)
NumStr_R = NumStr_R.Remove(NumStr_R.IndexOf('零'), 1); //比如1000,10000元整的情况下 去0
if (!IsXS_bool) return NumStr_R + "整"; //如果没有小数就返回
else
{
for (int i = 0; i < NumSr_Xs.Length; i++)
{
int j = int.Parse(NumSr_Xs.Substring(i, 1));
NumStr_R += DX_SZ[j] + DX_XSDS[NumSr_Xs.Length - i - 1];
}
}
return NumStr_R;
}
public static ResponseToken RequestRestToken(this JsonServiceClient client, string loginName)
{
if (client == null) throw new ArgumentNullException("client");
......@@ -49,21 +132,23 @@ namespace Kivii.Finances.Seeyon.Extensions
}
}
#region 账单申请发票
public static ResponseForm<ResponseData> RequestBillForm0710(this JsonServiceClient client, FormMain_OrdinaryInvoice0710 form, ResponseToken token)
{
if (client == null) throw new ArgumentNullException("client");
if (form == null) throw new ArgumentNullException("form");
//var token = client.RequestRestToken(session.FullName);
var request = new RequestForm<RequestForm_InvoiceApply>();
var request = new RequestForm<RequestForm_Apply>();
request.appName = Configs.appName;//"collaboration";
request.data = new RequestData<RequestForm_InvoiceApply>();
request.data = new RequestData<RequestForm_Apply>();
request.data.templateCode = Configs.templateCodeOrdinaryInvoice;//"JYHTSQ";
var templateCodeSuffix = form.收款单位名称.GetTemplateCodeSuffix();
if (!templateCodeSuffix.IsNullOrEmpty()) request.data.templateCode = $"{Configs.templateCodeOrdinaryInvoice}_{templateCodeSuffix}";
request.data.draft = "0";
//request.data.senderLoginName = token.bindingUser.loginName;
request.data.subject = $"到账发票申请({token.bindingUser.name} {DateTime.Now:yyyy-MM-dd HH:mm})";
request.data.data = new RequestForm_InvoiceApply();
request.data.data = new RequestForm_Apply();
request.data.data.formmain_0710 = new FormMain_OrdinaryInvoice0710();
request.data.data.formmain_0710 = form;
Console.WriteLine("-------------------------------------------------------------------------");
......@@ -78,16 +163,16 @@ namespace Kivii.Finances.Seeyon.Extensions
if (client == null) throw new ArgumentNullException("client");
if (form == null) throw new ArgumentNullException("form");
//var token = client.RequestRestToken(session.FullName);
var request = new RequestForm<RequestForm_InvoiceApply>();
var request = new RequestForm<RequestForm_Apply>();
request.appName = Configs.appName;//"collaboration";
request.data = new RequestData<RequestForm_InvoiceApply>();
request.data = new RequestData<RequestForm_Apply>();
request.data.templateCode = Configs.templateCodeAdvanceInvoice;//"JYHTSQ";
var templateCodeSuffix = form.收款单位.GetTemplateCodeSuffix();
if (!templateCodeSuffix.IsNullOrEmpty()) request.data.templateCode = $"{Configs.templateCodeAdvanceInvoice}_{templateCodeSuffix}";
request.data.draft = "0";
//request.data.senderLoginName = token.bindingUser.loginName;
request.data.subject = $"预借发票申请({token.bindingUser.name} {DateTime.Now:yyyy-MM-dd HH:mm})";
request.data.data = new RequestForm_InvoiceApply();
request.data.data = new RequestForm_Apply();
request.data.data.formmain_0318 = new FormMain_AdvanceInvoice0318();
request.data.data.formmain_0318 = form;
Console.WriteLine("-------------------------------------------------------------------------");
......@@ -97,7 +182,6 @@ namespace Kivii.Finances.Seeyon.Extensions
return rtns;
}
public static FormMain_OrdinaryInvoice0710 PayedConvertToForm(this List<InvoiceApply> applys, ResponseOrgMember orgMember)
{
//var orgMember = client.RequestOrgMember(session.FullName);
......@@ -108,7 +192,7 @@ namespace Kivii.Finances.Seeyon.Extensions
var amount = applys.Sum(o => o.Amount);
var rtns = new FormMain_OrdinaryInvoice0710();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(BillApply).FullName;
rtns.业务类型 = typeof(Entities.BillApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = apply.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
......@@ -140,7 +224,7 @@ namespace Kivii.Finances.Seeyon.Extensions
bizKvids.Add(apply.Kvid.ToString());
var rtns = new FormMain_OrdinaryInvoice0710();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(BillApply).FullName;
rtns.业务类型 = typeof(Entities.BillApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = apply.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
......@@ -174,7 +258,7 @@ namespace Kivii.Finances.Seeyon.Extensions
var amount = applys.Sum(o => o.Amount);
var rtns = new FormMain_AdvanceInvoice0318();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(BillApply).FullName;
rtns.业务类型 = typeof(Entities.BillApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = apply.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
......@@ -206,7 +290,7 @@ namespace Kivii.Finances.Seeyon.Extensions
bizKvids.Add(apply.Kvid.ToString());
var rtns = new FormMain_AdvanceInvoice0318();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(BillApply).FullName;
rtns.业务类型 = typeof(Entities.BillApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = apply.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
......@@ -229,88 +313,103 @@ namespace Kivii.Finances.Seeyon.Extensions
rtns.收款单位 = apply.PayeeName;
return rtns;
}
#endregion
public static string GetTemplateCodeSuffix(this string payeeName)
#region 发票作废
public static ResponseForm<ResponseData> RequestOffsetForm0712(this JsonServiceClient client, FormMain_InvoiceVoid0712 form, ResponseToken token)
{
var rtns = string.Empty;
if (payeeName.Contains("南京市产品质量监督检验院")) rtns = "ZJY";
if (payeeName.Contains("深圳市宁深检验检测技术有限公司")) rtns = "NS";
if (payeeName.Contains("江苏苏测智能装备检测有限公司")) rtns = "ZB";
if (payeeName.Contains("江苏苏测检测认证有限公司")) rtns = "SC";
if (client == null) throw new ArgumentNullException("client");
if (form == null) throw new ArgumentNullException("form");
//var token = client.RequestRestToken(session.FullName);
var request = new RequestForm<RequestForm_Apply>();
request.appName = Configs.appName;//"collaboration";
request.data = new RequestData<RequestForm_Apply>();
request.data.templateCode = Configs.templateCodeInvoiceVoid;//"JYHTSQ";
var templateCodeSuffix = form.收款单位名称.GetTemplateCodeSuffix();
if (!templateCodeSuffix.IsNullOrEmpty()) request.data.templateCode = $"{Configs.templateCodeInvoiceVoid}_{templateCodeSuffix}";
request.data.draft = "0";
//request.data.senderLoginName = token.bindingUser.loginName;
request.data.subject = $"发票当月作废申请({token.bindingUser.name} {DateTime.Now:yyyy-MM-dd HH:mm})";
request.data.data = new RequestForm_Apply();
request.data.data.formmain_0712 = new FormMain_InvoiceVoid0712();
request.data.data.formmain_0712 = form;
Console.WriteLine("-------------------------------------------------------------------------");
Console.WriteLine(JsonSerializer.SerializeToString(request));
Console.WriteLine("-------------------------------------------------------------------------");
var rtns = client.Post<ResponseForm<ResponseData>>($"{Configs.RouteRequestForm}?token={token.id}", request);
return rtns;
}
public static string ConvertToChinese(this decimal Num)
public static FormMain_InvoiceVoid0712 OffsetConvertToForm(this Invoice invoice, ResponseOrgMember orgMember)
{
string[] DX_SZ = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" };//大写数字
string[] DX_DW = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万" };
string[] DX_XSDS = { "角", "分" };//大些小数单位
if (Num == 0) return DX_SZ[0];
Boolean IsXS_bool = false;//是否小数
string NumStr;//整个数字字符串
string NumStr_Zs;//整数部分
string NumSr_Xs = "";//小数部分
string NumStr_R = "";//返回的字符串
NumStr = Num.ToString();
NumStr_Zs = NumStr;
if (NumStr_Zs.Contains("."))
{
NumStr = Math.Round(Num, 2).ToString();
NumStr_Zs = NumStr.Substring(0, NumStr.IndexOf("."));
NumSr_Xs = NumStr.Substring((NumStr.IndexOf(".") + 1), (NumStr.Length - NumStr.IndexOf(".") - 1));
IsXS_bool = true;
}
int k = 0;
Boolean IsZeor = false;//整数中间连续0的情况
for (int i = 0; i < NumStr_Zs.Length; i++) //整数
{
int j = int.Parse(NumStr_Zs.Substring(i, 1));
if (j != 0)
{
NumStr_R += DX_SZ[j] + DX_DW[NumStr_Zs.Length - i - 1];
IsZeor = false; //没有连续0
}
else if (j == 0)
{
k++;
if (!IsZeor && !(NumStr_Zs.Length == i + 1)) //等于0不是最后一位,连续0取一次
{
//有问题
if (NumStr_Zs.Length - i - 1 >= 4 && NumStr_Zs.Length - i - 1 <= 6)
NumStr_R += DX_DW[4] + "零";
else
if (NumStr_Zs.Length - i - 1 > 7)
NumStr_R += DX_DW[8] + "零";
else
NumStr_R += "零";
IsZeor = true;
//var orgMember = client.RequestOrgMember(session.FullName);
if (orgMember == null) throw new Exception("未找到OA登录人员信息!");
var bizKvids = new List<string>();
bizKvids.Add(invoice.Kvid.ToString());
var rtns = new FormMain_InvoiceVoid0712();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(InvoiceOffsetApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = invoice.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
rtns.申请部门 = orgMember.orgDepartmentId;//KiviiContext.CurrentMember.DepartmentName;
rtns.申请人 = orgMember.id;//apply.OperatorName;
rtns.原发票号 = invoice.SerialNumber;
rtns.原发票类型 = invoice.Type == "增值税专用发票" ? "-4189929216282050282" : (invoice.Type == "增值税普通发票" ? "4529935671729733794" : "4728848026009816823");
rtns.原发票开票单位 = invoice.PayerName;
rtns.收款单位名称 = invoice.PayerName;
rtns.原开票金额 = invoice.Amount.ToString();
return rtns;
}
if (NumStr_Zs.Length == i + 1)// 等于0且是最后一位 变成 XX元整
NumStr_R += DX_DW[NumStr_Zs.Length - i - 1];
}
public static ResponseForm<ResponseData> RequestFlushForm0338(this JsonServiceClient client, FormMain_InvoiceRedFlush0338 form, ResponseToken token)
{
if (client == null) throw new ArgumentNullException("client");
if (form == null) throw new ArgumentNullException("form");
//var token = client.RequestRestToken(session.FullName);
var request = new RequestForm<RequestForm_Apply>();
request.appName = Configs.appName;//"collaboration";
request.data = new RequestData<RequestForm_Apply>();
request.data.templateCode = Configs.templateCodeInvoiceRedOffset;//"JYHTSQ";
var templateCodeSuffix = form.收款单位名称.GetTemplateCodeSuffix();
if (!templateCodeSuffix.IsNullOrEmpty()) request.data.templateCode = $"{Configs.templateCodeInvoiceRedOffset}_{templateCodeSuffix}";
request.data.draft = "0";
//request.data.senderLoginName = token.bindingUser.loginName;
request.data.subject = $"跨月发票红冲申请({token.bindingUser.name} {DateTime.Now:yyyy-MM-dd HH:mm})";
request.data.data = new RequestForm_Apply();
request.data.data.formmain_0338 = new FormMain_InvoiceRedFlush0338();
request.data.data.formmain_0338 = form;
Console.WriteLine("-------------------------------------------------------------------------");
Console.WriteLine(JsonSerializer.SerializeToString(request));
Console.WriteLine("-------------------------------------------------------------------------");
var rtns = client.Post<ResponseForm<ResponseData>>($"{Configs.RouteRequestForm}?token={token.id}", request);
return rtns;
}
if (NumStr_Zs.Length > 2 && k == NumStr_Zs.Length - 1)
NumStr_R = NumStr_R.Remove(NumStr_R.IndexOf('零'), 1); //比如1000,10000元整的情况下 去0
if (!IsXS_bool) return NumStr_R + "整"; //如果没有小数就返回
else
{
for (int i = 0; i < NumSr_Xs.Length; i++)
public static FormMain_InvoiceRedFlush0338 FlushConvertToForm(this Invoice invoice, ResponseOrgMember orgMember)
{
int j = int.Parse(NumSr_Xs.Substring(i, 1));
NumStr_R += DX_SZ[j] + DX_XSDS[NumSr_Xs.Length - i - 1];
}
//var orgMember = client.RequestOrgMember(session.FullName);
if (orgMember == null) throw new Exception("未找到OA登录人员信息!");
var bizKvids = new List<string>();
bizKvids.Add(invoice.Kvid.ToString());
var rtns = new FormMain_InvoiceRedFlush0338();
//var settlementType = "code|MonthlySettlement";//默认月结
rtns.业务类型 = typeof(InvoiceOffsetApply).FullName;
rtns.业务编号 = bizKvids;
rtns.单据编号 = invoice.SerialNumber;
rtns.申请日期 = DateTime.Now.ToString("yyyy-MM-dd");
rtns.申请部门 = orgMember.orgDepartmentId;//KiviiContext.CurrentMember.DepartmentName;
rtns.申请人 = orgMember.id;//apply.OperatorName;
rtns.是否为预借发票 = invoice.Category == "Debit" ? "-9179045864512534208" : "-7622688603542042575";
rtns.原发票号 = invoice.SerialNumber;
rtns.原发票类型 = invoice.Type == "增值税专用发票" ? "-4189929216282050282" : (invoice.Type == "增值税普通发票" ? "4529935671729733794" : "4728848026009816823");
rtns.原发票开票单位 = invoice.PayerName;
rtns.收款单位名称 = invoice.PayerName;
rtns.原开票金额 = invoice.Amount.ToString();
return rtns;
}
return NumStr_R;
}
#endregion
}
}
......@@ -11,6 +11,7 @@ namespace Kivii.Finances.Seeyon
internal static string BaseUrl = "http://61.132.52.110:82";//"http://zyoa.jst-gov.com";
public const string TableNameApply = "FINA_Applies";
public const string TableNameInvoice = "FINA_Invoices";
/// <summary>
/// 提交表单接口
......
......@@ -275,14 +275,234 @@ namespace Kivii.Finances.Seeyon.Entities
}
}
public class RequestForm_InvoiceApply
public class OffsetApply { }
[Api(Description = "发票作废申请")]
[Alias(Configs.TableNameInvoice)]
public class InvoiceOffsetApply : Invoice, IEntityIsSeeyonApply
{
[Ignore]
public List<Guid> Kvids { get; set; }
[Ignore]
public string Reason { get; set; }
public object OnGetApplyResult(Guid Kvid, object Result, string Message)
{
//有专用接受接口,此接口暂不实现
var rtns = new RestfulExecutionResponse<Invoice>();
rtns.Results = new List<Invoice>();
return rtns;
}
public object OnGetApplyResult(List<Guid> Kvids, object Result, string Message)
{
//有专用接受接口,此接口暂不实现
var rtns = new RestfulExecutionResponse<Invoice>();
rtns.Results = new List<Invoice>();
return rtns;
}
public object OnSubmitApplyForm<T>(Guid Kvid)
{
Kvid.ThrowIfEmpty("请传入要申请作废的信息!");
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
Invoice invoice = conn.SingleById<Invoice>(Kvid);
invoice.ThrowIfNull("未找到此业务信息!");
if (invoice.BizKvid != Guid.Empty) throw new Exception("当前发票已在申请中!");
if (invoice.OffsetKvid != Guid.Empty) throw new Exception("当前发票已作废!");
var session = KiviiContext.Request.GetSession();
var client = new JsonServiceClient(Configs.BaseUrl);
var token = client.RequestRestToken(session.FullName);
var orgMember = client.RequestOrgMember(session.FullName, token);
var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>();
var applyForm = invoice.OffsetConvertToForm(orgMember);
var resp = client.RequestOffsetForm0712(applyForm, token);
if (resp.code != "0") throw new Exception($"OA接口调用失败,原因:{resp.message}");
invoice.BizId = resp.data.subject;
invoice.AddOnlyProperties(o => o.BizId);
invoice.BizType = typeof(InvoiceOffsetApply).FullName;
invoice.AddOnlyProperties(o => o.BizType);
conn.UpdateOnly(invoice);
var log = new EntityLog<Invoice>();
log.OwnerKvid = invoice.Kvid;
log.Title = "当月发票申请作废";
log.Type = "OA申请";
log.Summary = $"提交了当月发票申请作废申请,审批将在OA执行";
conn.Insert(log);
rtns.Results.Add(invoice);
return rtns;
}
public object OnSubmitApplyForm<T>(T form)
{
form.ThrowIfNull("请传入发票信息!");
var formOffset = form as InvoiceOffsetApply;
formOffset.ThrowIfNull("传入的发票信息不能为空!");
var kvids = formOffset.Kvids;
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
var invoices = conn.SelectByIds<Invoice>(kvids);
invoices.ThrowIfNullOrEmpty("未找到发票信息!");
if (invoices.Exists(o=>o.BizKvid != Guid.Empty)) throw new Exception("当前发票已在申请中!");
if (invoices.Exists(o => o.OffsetKvid != Guid.Empty)) throw new Exception("当前发票已作废!");
var session = KiviiContext.Request.GetSession();
var client = new JsonServiceClient(Configs.BaseUrl);
var token = client.RequestRestToken(session.FullName);
var orgMember = client.RequestOrgMember(session.FullName, token);
var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>();
foreach (var invoice in invoices)
{
var applyForm = invoice.OffsetConvertToForm(orgMember);
applyForm.原因 = formOffset.Reason;
var resp = client.RequestOffsetForm0712(applyForm, token);
if (resp.code != "0") throw new Exception($"OA接口调用失败,原因:{resp.message}");
invoice.BizId = resp.data.subject;
invoice.AddOnlyProperties(o => o.BizId);
invoice.BizType = typeof(InvoiceOffsetApply).FullName;
invoice.AddOnlyProperties(o => o.BizType);
conn.UpdateOnly(invoice);
var log = new EntityLog<Invoice>();
log.OwnerKvid = invoice.Kvid;
log.Title = "当月发票申请作废";
log.Type = "OA申请";
log.Summary = $"提交了当月发票申请作废申请,审批将在OA执行";
conn.Insert(log);
rtns.Results.Add(invoice);
}
return rtns;
}
}
[Api(Description = "发票红冲申请")]
[Alias(Configs.TableNameInvoice)]
public class InvoiceRedFlushApply : Invoice, IEntityIsSeeyonApply
{
[Ignore]
public List<Guid> Kvids { get; set; }
[Ignore]
public string Reason { get; set; }
public object OnGetApplyResult(Guid Kvid, object Result, string Message)
{
//有专用接受接口,此接口暂不实现
var rtns = new RestfulExecutionResponse<Invoice>();
rtns.Results = new List<Invoice>();
return rtns;
}
public object OnGetApplyResult(List<Guid> Kvids, object Result, string Message)
{
//有专用接受接口,此接口暂不实现
var rtns = new RestfulExecutionResponse<Invoice>();
rtns.Results = new List<Invoice>();
return rtns;
}
public object OnSubmitApplyForm<T>(Guid Kvid)
{
Kvid.ThrowIfEmpty("请传入要申请作废的信息!");
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
Invoice invoice = conn.SingleById<Invoice>(Kvid);
invoice.ThrowIfNull("未找到此业务信息!");
if (invoice.BizKvid != Guid.Empty) throw new Exception("当前发票已在申请中!");
if (invoice.OffsetKvid != Guid.Empty) throw new Exception("当前发票已作废!");
var session = KiviiContext.Request.GetSession();
var client = new JsonServiceClient(Configs.BaseUrl);
var token = client.RequestRestToken(session.FullName);
var orgMember = client.RequestOrgMember(session.FullName, token);
var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>();
var applyForm = invoice.FlushConvertToForm(orgMember);
var resp = client.RequestFlushForm0338(applyForm, token);
if (resp.code != "0") throw new Exception($"OA接口调用失败,原因:{resp.message}");
invoice.BizId = resp.data.subject;
invoice.AddOnlyProperties(o => o.BizId);
invoice.BizType = typeof(InvoiceOffsetApply).FullName;
invoice.AddOnlyProperties(o => o.BizType);
conn.UpdateOnly(invoice);
var log = new EntityLog<Invoice>();
log.OwnerKvid = invoice.Kvid;
log.Title = "跨月发票红冲申请";
log.Type = "OA申请";
log.Summary = $"提交了跨月发票红冲申请申请,审批将在OA执行";
conn.Insert(log);
rtns.Results.Add(invoice);
return rtns;
}
public object OnSubmitApplyForm<T>(T form)
{
form.ThrowIfNull("请传入发票信息!");
var formOffset = form as InvoiceOffsetApply;
formOffset.ThrowIfNull("传入的发票信息不能为空!");
var kvids = formOffset.Kvids;
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
var invoices = conn.SelectByIds<Invoice>(kvids);
invoices.ThrowIfNullOrEmpty("未找到发票信息!");
if (invoices.Exists(o => o.BizKvid != Guid.Empty)) throw new Exception("当前发票已在申请中!");
if (invoices.Exists(o => o.OffsetKvid != Guid.Empty)) throw new Exception("当前发票已作废!");
var session = KiviiContext.Request.GetSession();
var client = new JsonServiceClient(Configs.BaseUrl);
var token = client.RequestRestToken(session.FullName);
var orgMember = client.RequestOrgMember(session.FullName, token);
var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>();
foreach (var invoice in invoices)
{
var applyForm = invoice.FlushConvertToForm(orgMember);
applyForm.原因 = formOffset.Reason;
var resp = client.RequestFlushForm0338(applyForm, token);
if (resp.code != "0") throw new Exception($"OA接口调用失败,原因:{resp.message}");
invoice.BizId = resp.data.subject;
invoice.AddOnlyProperties(o => o.BizId);
invoice.BizType = typeof(InvoiceOffsetApply).FullName;
invoice.AddOnlyProperties(o => o.BizType);
conn.UpdateOnly(invoice);
var log = new EntityLog<Invoice>();
log.OwnerKvid = invoice.Kvid;
log.Title = "跨月发票红冲申请";
log.Type = "OA申请";
log.Summary = $"提交了跨月发票红冲申请申请,审批将在OA执行";
conn.Insert(log);
rtns.Results.Add(invoice);
}
return rtns;
}
}
#region OA表单
public class RequestForm_Apply
{
public FormMain_OrdinaryInvoice0710 formmain_0710 { get; set; }
public FormMain_AdvanceInvoice0318 formmain_0318 { get; set; }
public FormMain_InvoiceVoid0712 formmain_0712 { get; set; }
public FormMain_InvoiceRedFlush0338 formmain_0338 { get; set; }
}
#region OA表单
/// <summary>
/// 发起流程表单接口【到账发票申请】
/// </summary>
......@@ -465,12 +685,15 @@ namespace Kivii.Finances.Seeyon.Entities
public string 原因 { get; set; }
public string 原开票金额 { get; set; }
public string 收款单位名称 { get; set; }
}
/// <summary>
/// 发起流程表单接口【跨月发票红冲申请】
/// </summary>
public class FormMain_InvoiceRedOffset0338
public class FormMain_InvoiceRedFlush0338
{
/// <summary>
/// 唯一编号,BizKvid
......@@ -521,6 +744,8 @@ namespace Kivii.Finances.Seeyon.Entities
public string 原开票金额 { get; set; }
public string 冲红发票号码 { get; set; }
public string 收款单位名称 { get; set; }
}
#endregion
}
......@@ -52,11 +52,15 @@
<ItemGroup>
<Compile Include="ApplyExtension.cs" />
<Compile Include="Configs.cs" />
<Compile Include="Entities\BillApply.cs" />
<Compile Include="Entities\Apply.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RestfulBillApply.cs" />
<Compile Include="RestfulApply.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Kivii.Biz.Finances.V2.0\Src\Kivii.Biz.Finances.V2.0.csproj">
<Project>{8d9479e9-5c4f-4d96-8bc1-c771be0d91b1}</Project>
<Name>Kivii.Biz.Finances.V2.0</Name>
</ProjectReference>
<ProjectReference Include="..\..\Kivii.Seeyon.Addons\Src\Kivii.Seeyon.Addons.V4.5.csproj">
<Project>{4304bea2-2f6c-41e6-976b-3b2bc63d3fe3}</Project>
<Name>Kivii.Seeyon.Addons.V4.5</Name>
......
......@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2023.12180")]
[assembly: AssemblyFileVersion("5.4.2023.12180")]
[assembly: AssemblyVersion("5.4.2024.1150")]
[assembly: AssemblyFileVersion("5.4.2024.1150")]
......@@ -277,4 +277,207 @@ namespace Kivii.Finances.Seeyon
return rtns;
}
}
[Api(Description = "OA作废发票回写调用")]
public class OffsetApplyResult : RestfulExecution<OffsetApply>
{
public Guid Kvid { get; set; }//InvoiceApplyKvid
public List<Guid> Kvids { get; set; }//InvoiceApplyKvids
public string Result { get; set; }// 审批通过/审批不通过
public List<Invoice> Invoices { get; set; }// 发票信息,最少要有发票号码和开票时间
public string Message { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
if (Kvid == Guid.Empty && Kvids.IsNullOrEmpty()) throw new Exception("业务编号不能为空!");
if (Kvids.IsNullOrEmpty()) Kvids = new List<Guid>();
if (Kvid != Guid.Empty) Kvids.Add(Kvid);
if (Result.IsNullOrEmpty()) throw new Exception("请传入审批结果:【审批通过/审批不通过】!");
var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
var invoices = conn.SelectByIds<Invoice>(Kvids);
if (invoices.IsNullOrEmpty()) throw new Exception("未找到指定的申请信息!");
if (invoices.Exists(o => o.OffsetKvid != Guid.Empty || o.RootKvid != o.Kvid)) throw new Exception("存在不正确的发票类型");
var kvids = invoices.ConvertAll(o => o.Kvid);
var applyKvids = invoices.ConvertAll(o => o.ApplyKvid);
var rtns = new RestfulExecutionResponse<Invoice>();
rtns.Results = new List<Invoice>();
if (Result == "审批通过")
{
var relationInvoices = conn.Select<Invoice>(o => Sql.In(o.ParentKvid, kvids) && o.OffsetKvid == Guid.Empty && o.Type == "Relation");
var existApplies = conn.Select<InvoiceApply>(o => o.OperateType == InvoiceApplyType.Related && Sql.In(o.RootKvid, applyKvids));
List<Payment> existPayments = null;
List<Payment> splitPayments = null;
List<Invoice> offsets = new List<Invoice>();
List<EntityLog<Invoice>> logs = new List<EntityLog<Invoice>>();
if (!relationInvoices.IsNullOrEmpty())
{
existPayments = conn.Select<Payment>(o => Sql.In(o.Kvid, relationInvoices.ConvertAll(p => p.BizKvid)));//Type:Bank,Pos,Cash,WeChat...
if (!existPayments.IsNullOrEmpty())
{
splitPayments = conn.Select<Payment>(o => o.OffsetKvid == Guid.Empty && o.Type == PaymentType.Split && Sql.In(o.ParentKvid, existPayments.ConvertAll(p => p.Kvid)));
foreach (var item in existPayments)
{
var relations = relationInvoices.Where(o => o.BizKvid == item.Kvid).ToList();
if (!relations.IsNullOrEmpty())
{
item.AmountInvoice -= relations.Sum(o => o.Amount);
if (item.AmountInvoice < 0) item.AmountInvoice = 0;
item.AddOnlyProperties(o => o.AmountInvoice);
if (item.AmountInvoice <= 0)
{
item.InvoiceTime = null;
item.AddOnlyProperties(o => o.InvoiceTime);
}
}
if (!splitPayments.IsNullOrEmpty())//要是所选Payment存在拆分项,满足条件就要更新AmountInvoice
{
decimal amountInvoice = 0;
amountInvoice = item.AmountInvoice;
foreach (var split in splitPayments)
{
if (amountInvoice <= 0) split.AmountInvoice = 0;
else split.AmountInvoice = split.Amount >= amountInvoice ? amountInvoice : split.Amount;
split.AddOnlyProperties(o => o.AmountInvoice);
if (split.AmountInvoice <= 0)
{
split.InvoiceTime = null;
split.AddOnlyProperties(o => o.InvoiceTime);
}
amountInvoice -= split.AmountInvoice;
}
}
}
}
foreach (var item in relationInvoices)
{
var offset = item.Offset($"发票作废:{Message}");
offsets.Add(offset);
}
}
foreach (var item in invoices)
{
var log = new EntityLog<Invoice>();
log.OwnerKvid = item.Kvid;
log.Title = item.BizId;
log.Type = "OA申请";
log.Summary = "OA审批不通过,驳回了发票作废审批";
log.Remark = Message;
log.CreatorName = "OA审批";
logs.Add(log);
if (item.Metadata.IsNullOrEmpty()) item.Metadata = new Dictionary<string, string>();
item.Metadata["SeeyonResult"] = Result;
item.Metadata["SeeyonMessage"] = Message;
item.AddOnlyProperties(o => o.Metadata);
Invoice redInvoice = null;
if (!Invoices.IsNullOrEmpty()) redInvoice = Invoices[0];
var offset = item.Offset($"发票作废:{Message}", redInvoice);
offsets.Add(offset);
}
var trans = conn.OpenTransaction();
try
{
foreach (var log in logs)
{
conn.Insert(log);
}
foreach (var item in invoices)
{
conn.UpdateOnly(item);
rtns.Results.Add(item);
}
//删除关联Payment的发票数据
if (!relationInvoices.IsNullOrEmpty())
{
foreach (var item in relationInvoices)
{
conn.UpdateOnly(item);
}
}
foreach (var item in offsets)
{
conn.Insert(item);
}
//更新已关联的payment的AmountInvoice
if (!existPayments.IsNullOrEmpty())
{
foreach (var item in existPayments)
{
if (item.OnlyProperties.Count > 0) conn.UpdateOnly(item);
}
}
//更新已关联的payment的父级或子级AmountInvoice
if (!splitPayments.IsNullOrEmpty())
{
foreach (var item in splitPayments)
{
if (item.OnlyProperties.Count > 0) conn.UpdateOnly(item);
}
}
if (!existApplies.IsNullOrEmpty())
{
//删除申请关联的数据
var updateInvoiceApplys = conn.From<InvoiceApply>();
updateInvoiceApplys = updateInvoiceApplys.Update(o => new { o.Status, o.Summary });
updateInvoiceApplys = updateInvoiceApplys.Where(o => Sql.In(o.Kvid, existApplies.ConvertAll(p => p.Kvid)));
conn.UpdateOnly<InvoiceApply>(new InvoiceApply { Status = -1, Summary = $"发票作废:{Message}" }, updateInvoiceApplys);
}
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
else
{
var trans = conn.OpenTransaction();
try
{
foreach (var invoice in invoices)
{
var log = new EntityLog<Invoice>();
log.OwnerKvid = invoice.Kvid;
log.Title = invoice.BizId;
log.Type = "OA申请";
log.Summary = "OA审批不通过,驳回了发票作废审批";
log.Remark = Message;
log.CreatorName = "OA审批";
conn.Insert(log);
if (invoice.Metadata.IsNullOrEmpty()) invoice.Metadata = new Dictionary<string, string>();
invoice.Metadata["SeeyonResult"] = Result;
invoice.Metadata["SeeyonMessage"] = Message;
invoice.AddOnlyProperties(o => o.Metadata);
invoice.BizId = string.Empty;
invoice.AddOnlyProperties(o => o.BizId);
invoice.BizType = string.Empty;
invoice.AddOnlyProperties(o => o.BizType);
conn.UpdateOnly(invoice);
rtns.Results.Add(invoice);
}
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return rtns;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment