Files
JY1.0/server/AIEmployee/App_Code/PurchaseInvoice.cs

89 lines
4.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace Jingyao.AIEmployee
{
public sealed partial class PersonalInboxHandler
{
const string InvoiceHome = "ai_采购发票", InvoiceFollow = InvoiceHome + "_入库发票跟进",
InvoiceSources = InvoiceFollow + "_来源明细", InvoiceList = InvoiceHome + "_已登记发票",
InvoiceWorkflow = "ai_采购发票办理", InvoiceReconciliations = InvoiceWorkflow + "_关联对账单",
InvoiceMetadata = InvoiceWorkflow + "_发票附件_下载", InvoiceReview = InvoiceWorkflow + "_审核",
InvoiceMatch = InvoiceWorkflow + "_自动匹配", InvoiceReconcile = InvoiceWorkflow + "_生成对账单";
static bool InvoiceWrite(string name) { return name == InvoiceReview || name == InvoiceMatch || name == InvoiceReconcile; }
static string InvoiceRoute(string name)
{
switch (name) {
case InvoiceHome: case InvoiceFollow: case InvoiceSources: case InvoiceList: return "/erp/purchase-invoices";
case InvoiceWorkflow: case InvoiceReconciliations: case InvoiceMetadata:
case InvoiceReview: case InvoiceMatch: case InvoiceReconcile: return "/erp/purchase-invoice-workflow";
default: return null;
}
}
static void BindInvoice(SqlCommand command, string name, Dictionary<string,object> inputs, Dictionary<string,object> body)
{
if (name == InvoiceHome) { Only(inputs); return; }
if (name == InvoiceFollow || name == InvoiceSources || name == InvoiceList) {
if (name == InvoiceSources) {
Only(inputs,"分组键","关键词","状态"); AddText(command,inputs,"分组键",100,null);
} else Only(inputs,"关键词","状态");
AddText(command,inputs,"关键词",150,""); AddText(command,inputs,"状态",30,"");
command.Parameters.Add("@页码",SqlDbType.Int).Value = (int)Positive(body,"pageList",100000,1);
command.Parameters.Add("@每页条数",SqlDbType.Int).Value = (int)Positive(body,"pageSize",200,20);
return;
}
command.Parameters.Add("@发票登记流水号",SqlDbType.Int).Value = (int)Positive(inputs,"发票登记流水号",Int32.MaxValue,0);
if (!InvoiceWrite(name)) {
Only(inputs,"发票登记流水号");
if (name == InvoiceMetadata) command.Parameters.Add("@包含内容",SqlDbType.Bit).Value = false;
return;
}
if (body.ContainsKey("pageList") || body.ContainsKey("pageSize")) throw BadInput();
if (name == InvoiceReview) {
Only(inputs,"发票登记流水号","动作","意见","幂等键");
AddText(command,inputs,"动作",30,null,"审核通过","审核驳回"); AddText(command,inputs,"意见",500,"");
} else Only(inputs,"发票登记流水号","幂等键");
BindIdempotency(command,inputs);
}
static List<string> ReadPermissionCodes(SqlDataReader reader, int maximum)
{
var permissions = new List<string>();
foreach (var row in NextRows(reader,maximum)) {
object code;
if (!row.TryGetValue("权限代码",out code) || !(code is string) || permissions.Contains((string)code)) throw Unavailable();
permissions.Add((string)code);
}
if (reader.NextResult()) throw Unavailable();
return permissions;
}
static object ReadInvoice(SqlCommand command,string name,SqlDataReader reader)
{
if (name == InvoiceFollow || name == InvoiceList || name == InvoiceSources) return ReadPageWithSummary(command,reader,false);
var rows = ReadRows(reader,name == InvoiceReconciliations ? Int32.MaxValue : 1);
if (name == InvoiceHome) {
if (rows.Count != 1) throw Unavailable();
return new { summary = rows[0], permissions = ReadPermissionCodes(reader,8) };
}
if (name == InvoiceWorkflow) {
var links = NextRows(reader,Int32.MaxValue);
if (rows.Count == 0 && links.Count > 0) throw Unavailable();
return new { record = rows.Count == 0 ? null : rows[0], links = links, permissions = ReadPermissionCodes(reader,8) };
}
if (name == InvoiceMetadata) {
foreach (var row in rows) {
foreach (var field in row.Values) if (field is byte[]) throw Unavailable();
row.Remove("附件内容");
}
}
if ((InvoiceWrite(name) && rows.Count != 1) || reader.NextResult()) throw Unavailable();
return new { rows = rows };
}
}
}