Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Biz.Finances.V2.0
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶然
Kivii.Biz.Finances.V2.0
Commits
71e4d546
Commit
71e4d546
authored
Nov 20, 2021
by
陶然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
055b9906
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
292 additions
and
41 deletions
+292
-41
InvoiceApply.cs
Src/Entities/InvoiceApply.cs
+2
-14
SettlementDetail.cs
Src/Entities/SettlementDetail.cs
+1
-2
PaymentExtension.cs
Src/Extensions/PaymentExtension.cs
+23
-5
Kivii.Biz.Finances.V2.0.csproj
Src/Kivii.Biz.Finances.V2.0.csproj
+3
-0
RestfulInvoice.Offset.Deficit.cs
Src/Transforms/RestfulInvoice.Offset.Deficit.cs
+54
-0
RestfulInvoiceApply.Apply.cs
Src/Transforms/RestfulInvoiceApply.Apply.cs
+3
-4
RestfulInvoiceApply.cs
Src/Transforms/RestfulInvoiceApply.cs
+57
-0
RestfulInvoiceTitle.cs
Src/Transforms/RestfulInvoiceTitle.cs
+56
-0
RestfulPayment.Accept.cs
Src/Transforms/RestfulPayment.Accept.cs
+11
-11
RestfulPayment.Offset.cs
Src/Transforms/RestfulPayment.Offset.cs
+2
-1
RestfulPayment.Split.cs
Src/Transforms/RestfulPayment.Split.cs
+2
-2
RestfulPayment.cs
Src/Transforms/RestfulPayment.cs
+1
-1
RestfulSettlement.cs
Src/Transforms/RestfulSettlement.cs
+77
-1
No files found.
Src/Entities/InvoiceApply.cs
View file @
71e4d546
...
@@ -83,7 +83,7 @@ namespace Kivii.Finances.Entities
...
@@ -83,7 +83,7 @@ namespace Kivii.Finances.Entities
[
ApiMember
(
Description
=
"付方税号,收票方税号"
)]
[
ApiMember
(
Description
=
"付方税号,收票方税号"
)]
[
IgnoreUpdate
]
[
IgnoreUpdate
]
[
StringLength
(
100
)]
[
StringLength
(
100
)
,
Required
]
public
string
PayerTaxNumber
{
get
;
set
;
}
public
string
PayerTaxNumber
{
get
;
set
;
}
[
ApiMember
(
Description
=
"公司地址"
)]
[
ApiMember
(
Description
=
"公司地址"
)]
...
@@ -237,19 +237,7 @@ namespace Kivii.Finances.Entities
...
@@ -237,19 +237,7 @@ namespace Kivii.Finances.Entities
/// <summary>
/// <summary>
/// 关联,与收款一一对应用
/// 关联,与收款一一对应用
/// </summary>
/// </summary>
Related
,
Related
/// <summary>
/// 现金,财务用
/// </summary>
Cash
,
/// <summary>
/// Pos机,财务用
/// </summary>
Pos
,
AliPay
,
WeChat
}
}
public
enum
InvoiceApplyStatus
public
enum
InvoiceApplyStatus
...
...
Src/Entities/SettlementDetail.cs
View file @
71e4d546
...
@@ -23,8 +23,7 @@ namespace Kivii.Finances.Entities
...
@@ -23,8 +23,7 @@ namespace Kivii.Finances.Entities
public
Guid
OffsetKvid
{
get
;
set
;
}
public
Guid
OffsetKvid
{
get
;
set
;
}
[
ApiMember
(
Description
=
"业务Kvid,根据结算精细度,Settlement中的BizKvid可能会和SettlementDetail中的BizKvid一致,"
+
[
ApiMember
(
Description
=
"业务Kvid,根据结算精细度,Settlement中的BizKvid可能会和SettlementDetail中的BizKvid一致,查询时需要同时查询两表数据"
)]
"查询时需要同时查询两表数据"
)]
[
InternalSetter
]
[
InternalSetter
]
[
DefaultEmptyGuid
]
[
DefaultEmptyGuid
]
public
Guid
BizKvid
{
get
;
set
;
}
public
Guid
BizKvid
{
get
;
set
;
}
...
...
Src/Extensions/PaymentExtension.cs
View file @
71e4d546
...
@@ -84,10 +84,11 @@ namespace Kivii.Finances
...
@@ -84,10 +84,11 @@ namespace Kivii.Finances
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
RootKvid
!=
payment
.
Kvid
).
ThrowIfTrue
(
"不支持的类型"
);
(
payment
.
RootKvid
!=
payment
.
Kvid
).
ThrowIfTrue
(
"不支持的类型"
);
(
payment
.
Type
!=
PaymentType
.
Bank
).
ThrowIfTrue
(
"不支持的类型"
);
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
var
amountInvoiced
=
conn
.
Scalar
<
Payment
,
decimal
>(
o
=>
Sql
.
Sum
(
o
.
AmountInvoice
),
p
=>
p
.
ParentKvid
==
payment
.
Kvid
&&
p
.
OffsetKvid
==
Guid
.
Empty
);
var
amountInvoiced
=
conn
.
Scalar
<
Payment
,
decimal
>(
o
=>
Sql
.
Sum
(
o
.
AmountInvoice
),
p
=>
p
.
Type
==
PaymentType
.
Split
&&
p
.
ParentKvid
==
payment
.
Kvid
&&
p
.
OffsetKvid
==
Guid
.
Empty
);
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
try
try
...
@@ -120,8 +121,9 @@ namespace Kivii.Finances
...
@@ -120,8 +121,9 @@ namespace Kivii.Finances
(
payment
.
Amount
<=
0
).
ThrowIfTrue
(
"付款记录发生金额不能少于0!"
);
(
payment
.
Amount
<=
0
).
ThrowIfTrue
(
"付款记录发生金额不能少于0!"
);
(
payment
.
AmountInvoice
==
0
).
ThrowIfFalse
(
"付款记录开票金额不为0!"
);
(
payment
.
AmountInvoice
==
0
).
ThrowIfFalse
(
"付款记录开票金额不为0!"
);
(
payment
.
AmountUsed
==
0
).
ThrowIfFalse
(
"付款记录使用金额不为0!"
);
(
payment
.
AmountUsed
==
0
).
ThrowIfFalse
(
"付款记录使用金额不为0!"
);
(
payment
.
AmountSplited
==
0
).
ThrowIfFalse
(
"付款记录拆分不为0!"
);
(
payment
.
Type
!=
PaymentType
.
Cash
&&
payment
.
Type
!=
PaymentType
.
Pos
&&
payment
.
Type
!=
PaymentType
.
Bank
).
ThrowIfTrue
(
"仅支持接受现金刷卡或者银行流水记录"
);
(
payment
.
Type
!=
PaymentType
.
Cash
&&
payment
.
Type
!=
PaymentType
.
Pos
&&
payment
.
Type
!=
PaymentType
.
Bank
).
ThrowIfTrue
(
"仅支持接受现金刷卡或者银行流水记录"
);
if
(
payment
.
Type
==
PaymentType
.
Bank
)
(
payment
.
AmountSplited
!=
0
).
ThrowIfTrue
(
"付款记录拆分不为0!"
);
else
(
payment
.
AmountSplited
!=
payment
.
Amount
).
ThrowIfTrue
(
"现金刷卡拆分金额错误!"
);
if
(
payment
.
ParentKvid
!=
Guid
.
Empty
)
payment
.
ParentKvid
=
Guid
.
Empty
;
if
(
payment
.
ParentKvid
!=
Guid
.
Empty
)
payment
.
ParentKvid
=
Guid
.
Empty
;
if
(
payment
.
OffsetKvid
!=
Guid
.
Empty
)
payment
.
OffsetKvid
=
Guid
.
Empty
;
if
(
payment
.
OffsetKvid
!=
Guid
.
Empty
)
payment
.
OffsetKvid
=
Guid
.
Empty
;
if
(
payment
.
Kvid
==
Guid
.
Empty
)
payment
.
Kvid
=
Guid
.
NewGuid
();
if
(
payment
.
Kvid
==
Guid
.
Empty
)
payment
.
Kvid
=
Guid
.
NewGuid
();
...
@@ -193,7 +195,7 @@ namespace Kivii.Finances
...
@@ -193,7 +195,7 @@ namespace Kivii.Finances
/// <param name="ownerKvid"></param>
/// <param name="ownerKvid"></param>
/// <param name="ownerName"></param>
/// <param name="ownerName"></param>
/// <returns></returns>
/// <returns></returns>
public
static
Payment
BizSplit
(
this
Payment
payment
,
decimal
amountSplit
,
Guid
?
ownerKvid
=
null
,
string
ownerName
=
null
)
public
static
Payment
BizSplit
(
this
Payment
payment
,
decimal
amountSplit
,
Guid
?
ownerKvid
=
null
,
string
ownerName
=
null
,
IDbConnection
conn
=
null
)
{
{
payment
.
ThrowIfNull
(
$"传入payment参数为空"
);
payment
.
ThrowIfNull
(
$"传入payment参数为空"
);
if
(
payment
.
Type
!=
PaymentType
.
Bank
)
throw
new
Exception
(
"非银行到账不可以认领!"
);
if
(
payment
.
Type
!=
PaymentType
.
Bank
)
throw
new
Exception
(
"非银行到账不可以认领!"
);
...
@@ -201,7 +203,23 @@ namespace Kivii.Finances
...
@@ -201,7 +203,23 @@ namespace Kivii.Finances
(
amountSplit
<=
0
).
ThrowIfTrue
(
"拆分认领金额不能为零或负值。"
);
(
amountSplit
<=
0
).
ThrowIfTrue
(
"拆分认领金额不能为零或负值。"
);
if
(
payment
.
AmountSplited
==
payment
.
Amount
)
throw
new
Exception
(
"无剩余收款可认领!"
);
if
(
payment
.
AmountSplited
==
payment
.
Amount
)
throw
new
Exception
(
"无剩余收款可认领!"
);
if
(
payment
.
AmountSplited
+
amountSplit
>
payment
.
Amount
)
throw
new
Exception
(
"认领金额超出范围!"
);
if
(
payment
.
AmountSplited
+
amountSplit
>
payment
.
Amount
)
throw
new
Exception
(
"认领金额超出范围!"
);
decimal
amountInvoice
=
0
;
if
(
payment
.
AmountInvoice
>
0
)
//如果要拆分的到账已经开过票 就要计算拆分项的开票金额
{
if
(
payment
.
AmountInvoice
<
payment
.
Amount
)
//到账的部分进行了开票 就需要计算拆分项的开票金额
{
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
//查看已经拆分的项目分得的已经开票金额
var
existSplits
=
conn
.
Select
<
Payment
>(
o
=>
o
.
RootKvid
==
payment
.
RootKvid
&&
o
.
Type
==
PaymentType
.
Split
&&
o
.
OffsetKvid
==
Guid
.
Empty
);
if
(!
existSplits
.
IsNullOrEmpty
())
{
//剩余的开票金额
var
remainAmountInvoice
=
payment
.
AmountInvoice
-
existSplits
.
Sum
(
o
=>
o
.
AmountInvoice
);
if
(
remainAmountInvoice
>
0
)
amountInvoice
=
remainAmountInvoice
>
amountSplit
?
amountSplit
:
remainAmountInvoice
;
}
}
else
amountInvoice
=
amountSplit
;
//否则直接记录拆分项完全开票
}
#
region
新增拆分项目
#
region
新增拆分项目
var
splitPayment
=
new
Payment
();
var
splitPayment
=
new
Payment
();
splitPayment
.
PopulateWith
(
payment
);
//先从父级中拷贝所有参数
splitPayment
.
PopulateWith
(
payment
);
//先从父级中拷贝所有参数
...
@@ -222,7 +240,7 @@ namespace Kivii.Finances
...
@@ -222,7 +240,7 @@ namespace Kivii.Finances
splitPayment
.
Amount
=
amountSplit
;
splitPayment
.
Amount
=
amountSplit
;
splitPayment
.
AmountSplited
=
0
;
splitPayment
.
AmountSplited
=
0
;
splitPayment
.
AmountUsed
=
0
;
splitPayment
.
AmountUsed
=
0
;
splitPayment
.
AmountInvoice
=
payment
.
AmountInvoice
>
amountSplit
?
amountSplit
:
payment
.
AmountInvoice
;
splitPayment
.
AmountInvoice
=
amountInvoice
;
//
payment.AmountInvoice > amountSplit ? amountSplit : payment.AmountInvoice;
splitPayment
.
Summary
=
string
.
Empty
;
splitPayment
.
Summary
=
string
.
Empty
;
splitPayment
.
Remark
=
string
.
Empty
;
splitPayment
.
Remark
=
string
.
Empty
;
splitPayment
.
OperateTime
=
payment
.
OperateTime
;
splitPayment
.
OperateTime
=
payment
.
OperateTime
;
...
...
Src/Kivii.Biz.Finances.V2.0.csproj
View file @
71e4d546
...
@@ -79,7 +79,10 @@
...
@@ -79,7 +79,10 @@
<Compile
Include=
"Transforms\RestfulAccountDetail.cs"
/>
<Compile
Include=
"Transforms\RestfulAccountDetail.cs"
/>
<Compile
Include=
"Transforms\RestfulBill.cs"
/>
<Compile
Include=
"Transforms\RestfulBill.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoice.Debit.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoice.Debit.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoice.Offset.Deficit.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoiceApply.Apply.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoiceApply.Apply.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoiceApply.cs"
/>
<Compile
Include=
"Transforms\RestfulInvoiceTitle.cs"
/>
<Compile
Include=
"Transforms\RestfulPay.cs"
/>
<Compile
Include=
"Transforms\RestfulPay.cs"
/>
<Compile
Include=
"Transforms\RestfulPayment.Accept.cs"
/>
<Compile
Include=
"Transforms\RestfulPayment.Accept.cs"
/>
<Compile
Include=
"Transforms\RestfulPayment.Account.cs"
/>
<Compile
Include=
"Transforms\RestfulPayment.Account.cs"
/>
...
...
Src/Transforms/RestfulInvoice.Offset.Deficit.cs
0 → 100644
View file @
71e4d546
using
Kivii.Finances.Entities
;
using
Kivii.Linq
;
using
Kivii.Web
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Kivii.Finances.Transforms
{
[
Api
(
Description
=
"发票作废"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceOffset
:
RestfulExecution
<
Invoice
>
{
public
Guid
Kvid
{
get
;
set
;
}
public
string
Remark
{
get
;
set
;
}
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
Kvid
.
ThrowIfEmpty
(
"请传入要冲销的发票Kvid!"
);
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Invoice
>();
var
invoice
=
conn
.
SingleById
<
Invoice
>(
Kvid
);
invoice
.
ThrowIfNull
(
"未找到对应发票!"
);
invoice
.
BizKvid
.
ThrowIfNotEmpty
(
"发票已关联业务! 请先解除关联!"
);
invoice
.
OffsetKvid
.
ThrowIfNotEmpty
(
"发票已作废!"
);
var
apply
=
conn
.
SingleById
<
InvoiceApply
>(
invoice
.
ApplyKvid
);
return
base
.
OnExecution
(
req
,
res
);
}
}
[
Api
(
Description
=
"作废撤回"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceOffsetCancel
:
RestfulExecution
<
Invoice
>
{
}
[
Api
(
Description
=
"发票红冲"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceDeficit
:
RestfulExecution
<
Invoice
>
{
}
[
Api
(
Description
=
"红冲撤回"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceDeficitCancel
:
RestfulExecution
<
Invoice
>
{
}
}
Src/Transforms/RestfulInvoiceApply.Apply.cs
View file @
71e4d546
...
@@ -189,8 +189,7 @@ namespace Kivii.Finances.Transforms
...
@@ -189,8 +189,7 @@ namespace Kivii.Finances.Transforms
{
{
#
region
apply
驳回
#
region
apply
驳回
//进入开票状态后不可驳回
//进入开票状态后不可驳回
if
(
apply
.
Status
>=
(
int
)
InvoiceApplyStatus
.
FinancialExecute
)
continue
;
(
apply
.
Status
>=
(
int
)
InvoiceApplyStatus
.
FinancialExecute
).
ThrowIfTrue
(
"撤销失败,当前申请已进入开票列队或已完成开票!"
);
//if (apply.Status < (int)ApplyStatus.ProcessAdoption) continue;
apply
.
Status
=
(
int
)
InvoiceApplyStatus
.
ApplyReject
;
apply
.
Status
=
(
int
)
InvoiceApplyStatus
.
ApplyReject
;
apply
.
AddOnlyProperties
(
o
=>
o
.
Status
);
apply
.
AddOnlyProperties
(
o
=>
o
.
Status
);
apply
.
AmountUsed
=
0
;
apply
.
AmountUsed
=
0
;
...
@@ -351,7 +350,7 @@ namespace Kivii.Finances.Transforms
...
@@ -351,7 +350,7 @@ namespace Kivii.Finances.Transforms
if
(
Details
.
IsNullOrEmpty
())
Details
=
new
List
<
InvoiceApplyDetail
>();
if
(
Details
.
IsNullOrEmpty
())
Details
=
new
List
<
InvoiceApplyDetail
>();
if
(
Detail
!=
null
)
Details
.
Add
(
Detail
);
if
(
Detail
!=
null
)
Details
.
Add
(
Detail
);
if
(
Kvids
==
null
||
Kvids
.
Count
<=
0
)
throw
new
Exception
(
"请先选择申请条目!"
);
if
(
Kvids
==
null
||
Kvids
.
Count
<=
0
)
throw
new
Exception
(
"请先选择申请条目!"
);
if
(
Item
.
OperateType
!=
InvoiceApplyType
.
Payment
&&
Item
.
OperateType
!=
InvoiceApplyType
.
Pos
&&
Item
.
OperateType
!=
InvoiceApplyType
.
Cash
&&
Item
.
OperateType
!=
InvoiceApplyType
.
AliPay
&&
Item
.
OperateType
!=
InvoiceApplyType
.
WeChat
)
throw
new
Exception
(
"合并开票只针对收款刷卡现金申请!"
);
if
(
Item
.
OperateType
!=
InvoiceApplyType
.
Payment
)
throw
new
Exception
(
"合并开票只针对收款刷卡现金申请!"
);
if
(
Details
.
Exists
(
o
=>
o
.
GoodsFullName
.
IsNullOrEmpty
()))
throw
new
Exception
(
"明细名称存在空值!"
);
if
(
Details
.
Exists
(
o
=>
o
.
GoodsFullName
.
IsNullOrEmpty
()))
throw
new
Exception
(
"明细名称存在空值!"
);
if
(
Details
.
Exists
(
o
=>
o
.
TaxRate
<
0
)
||
Details
.
Exists
(
o
=>
o
.
TaxRate
>
1
))
throw
new
Exception
(
"存在明细税率设置范围不在0-1之间!"
);
if
(
Details
.
Exists
(
o
=>
o
.
TaxRate
<
0
)
||
Details
.
Exists
(
o
=>
o
.
TaxRate
>
1
))
throw
new
Exception
(
"存在明细税率设置范围不在0-1之间!"
);
...
@@ -370,7 +369,7 @@ namespace Kivii.Finances.Transforms
...
@@ -370,7 +369,7 @@ namespace Kivii.Finances.Transforms
if
(
applys
.
Count
<
2
)
throw
new
Exception
(
"请选择两条以上的申请进行合并!"
);
if
(
applys
.
Count
<
2
)
throw
new
Exception
(
"请选择两条以上的申请进行合并!"
);
//if (applys.Exists(o => o.Type != "VATS")) throw new Exception("普票暂时无法合并开票");
//if (applys.Exists(o => o.Type != "VATS")) throw new Exception("普票暂时无法合并开票");
if
(
applys
.
Exists
(
o
=>
o
.
PayerName
!=
Item
.
PayerName
))
throw
new
Exception
(
"合并申请抬头不一致!"
);
if
(
applys
.
Exists
(
o
=>
o
.
PayerName
!=
Item
.
PayerName
))
throw
new
Exception
(
"合并申请抬头不一致!"
);
if
(!
applys
.
Exists
(
o
=>
Sql
.
In
(
o
.
OperateType
,
InvoiceApplyType
.
Payment
,
InvoiceApplyType
.
Pos
,
InvoiceApplyType
.
Cash
,
InvoiceApplyType
.
AliPay
,
InvoiceApplyType
.
WeChat
)
))
throw
new
Exception
(
"合并开票只针对收款刷卡现金申请!"
);
if
(!
applys
.
Exists
(
o
=>
o
.
OperateType
!=
InvoiceApplyType
.
Payment
))
throw
new
Exception
(
"合并开票只针对收款刷卡现金申请!"
);
if
(
applys
.
Exists
(
o
=>
o
.
OperateType
==
InvoiceApplyType
.
Payment
))
Item
.
OperateType
=
InvoiceApplyType
.
Payment
;
if
(
applys
.
Exists
(
o
=>
o
.
OperateType
==
InvoiceApplyType
.
Payment
))
Item
.
OperateType
=
InvoiceApplyType
.
Payment
;
var
groups
=
applys
.
GroupBy
(
o
=>
new
{
o
.
PayerName
,
o
.
PayerTaxNumber
});
var
groups
=
applys
.
GroupBy
(
o
=>
new
{
o
.
PayerName
,
o
.
PayerTaxNumber
});
if
(
groups
.
Count
()
!=
1
)
throw
new
Exception
(
"合并申请抬头不一致!"
);
if
(
groups
.
Count
()
!=
1
)
throw
new
Exception
(
"合并申请抬头不一致!"
);
...
...
Src/Transforms/RestfulInvoiceApply.cs
0 → 100644
View file @
71e4d546
using
Kivii.Finances.Entities
;
using
Kivii.Linq
;
using
Kivii.Web
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Kivii.Finances.Transforms
{
[
Api
(
Description
=
"开票申请查询"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceApplyQueryEx
:
RestfulExecution
<
InvoiceApply
>
{
#
region
QueryArgs
public
virtual
int
?
Skip
{
get
;
set
;
}
public
virtual
int
?
Take
{
get
;
set
;
}
public
virtual
string
OrderBy
{
get
;
set
;
}
public
string
OrderByDesc
{
get
;
set
;
}
public
virtual
string
Include
{
get
;
set
;
}
public
virtual
string
Fields
{
get
;
set
;
}
public
string
QueryKeys
{
get
;
set
;
}
public
string
QueryValues
{
get
;
set
;
}
#
endregion
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
InvoiceApply
>();
var
dynamicParams
=
Request
.
GetRequestParams
();
var
autoQuery
=
Request
.
TryResolve
<
IAutoQueryDb
>();
autoQuery
.
IncludeTotal
=
true
;
var
request
=
new
RestfulQuery
<
InvoiceApply
>();
request
=
request
.
PopulateWith
(
this
);
var
sqlExpress
=
autoQuery
.
CreateQuery
(
Request
,
conn
,
request
,
dynamicParams
);
sqlExpress
.
Where
(
o
=>
o
.
OffsetKvid
==
Guid
.
Empty
&&
o
.
OperateType
!=
InvoiceApplyType
.
Related
);
var
rtns
=
autoQuery
.
Execute
(
Request
,
conn
,
request
,
sqlExpress
);
return
rtns
;
}
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceApplyQuery
:
RestfulQuery
<
InvoiceApply
>
{
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceApplyRead
:
RestfulRead
<
InvoiceApply
>
{
}
}
Src/Transforms/RestfulInvoiceTitle.cs
0 → 100644
View file @
71e4d546
using
Kivii.Finances.Entities
;
using
Kivii.Web
;
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Kivii.Finances.Transforms
{
#
region
CRUDQ
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceTitleCreate
:
RestfulCreate
<
InvoiceTitle
>
{
public
override
bool
OnPreRestfulCreate
(
IRequest
req
,
IResponse
res
,
IDbConnection
dbConnection
,
IRestfulCreateResponse
<
InvoiceTitle
>
rtns
)
{
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
"("
,
"("
);
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
")"
,
")"
);
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
" "
,
""
);
return
base
.
OnPreRestfulCreate
(
req
,
res
,
dbConnection
,
rtns
);
}
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceTitleUpdate
:
RestfulUpdate
<
InvoiceTitle
>
{
public
override
bool
OnPreRestfulUpdate
(
IRequest
req
,
IResponse
res
,
IDbConnection
dbConnection
,
IRestfulUpdateResponse
<
InvoiceTitle
>
rtns
)
{
if
(!
Item
.
CompanyName
.
IsNullOrEmpty
())
{
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
"("
,
"("
);
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
")"
,
")"
);
Item
.
CompanyName
=
Item
.
CompanyName
.
Replace
(
" "
,
""
);
Item
.
AddOnlyProperties
(
o
=>
o
.
CompanyName
);
}
return
base
.
OnPreRestfulUpdate
(
req
,
res
,
dbConnection
,
rtns
);
}
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceTitleRead
:
RestfulRead
<
InvoiceTitle
>
{
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceTitleQuery
:
RestfulQuery
<
InvoiceTitle
>
{
}
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
InvoiceTitleDelete
:
RestfulDelete
<
InvoiceTitle
>
{
}
#
endregion
}
Src/Transforms/RestfulPayment.Accept.cs
View file @
71e4d546
...
@@ -64,9 +64,9 @@ namespace Kivii.Finances.Transforms
...
@@ -64,9 +64,9 @@ namespace Kivii.Finances.Transforms
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
PayerAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayerAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayerAccountName
=
accountBalance
.
Name
;
item
.
PayerAccountName
=
item
.
PayerAccountName
.
IsNullOrEmpty
()
?
accountBalance
.
Name
:
item
.
PayerAccount
Name
;
item
.
PayerAccountOwnerName
=
accountBalance
.
OwnerName
;
item
.
PayerAccountOwnerName
=
item
.
PayerAccountOwnerName
.
IsNullOrEmpty
()
?
accountBalance
.
OwnerName
:
item
.
PayerAccount
OwnerName
;
item
.
PayerAccountSerialNumber
=
accountBalance
.
SerialNumber
;
item
.
PayerAccountSerialNumber
=
item
.
PayerAccountSerialNumber
.
IsNullOrEmpty
()
?
accountBalance
.
SerialNumber
:
item
.
PayerAccount
SerialNumber
;
item
.
PayeeAccountKvid
=
bankAccount
.
Kvid
;
item
.
PayeeAccountKvid
=
bankAccount
.
Kvid
;
item
.
PayeeAccountName
=
bankAccount
.
Name
;
item
.
PayeeAccountName
=
bankAccount
.
Name
;
...
@@ -115,7 +115,7 @@ namespace Kivii.Finances.Transforms
...
@@ -115,7 +115,7 @@ namespace Kivii.Finances.Transforms
if
(
item
.
Amount
<=
0
)
continue
;
if
(
item
.
Amount
<=
0
)
continue
;
var
itemKvid
=
Guid
.
NewGuid
();
var
itemKvid
=
Guid
.
NewGuid
();
item
.
AmountInvoice
=
0
;
item
.
AmountInvoice
=
0
;
item
.
AmountSplited
=
0
;
item
.
AmountSplited
=
item
.
Amount
;
item
.
AmountUsed
=
0
;
item
.
AmountUsed
=
0
;
item
.
OwnerKvid
=
ownerKvid
;
item
.
OwnerKvid
=
ownerKvid
;
...
@@ -129,9 +129,9 @@ namespace Kivii.Finances.Transforms
...
@@ -129,9 +129,9 @@ namespace Kivii.Finances.Transforms
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
PayerAccountKvid
=
cashAccount
.
Kvid
;
item
.
PayerAccountKvid
=
cashAccount
.
Kvid
;
item
.
PayerAccountName
=
cashAccount
.
Name
;
item
.
PayerAccountName
=
item
.
PayerAccountName
.
IsNullOrEmpty
()
?
cashAccount
.
Name
:
item
.
PayerAccount
Name
;
item
.
PayerAccountOwnerName
=
cashAccount
.
OwnerName
;
item
.
PayerAccountOwnerName
=
item
.
PayerAccountOwnerName
.
IsNullOrEmpty
()
?
cashAccount
.
OwnerName
:
item
.
PayerAccount
OwnerName
;
item
.
PayerAccountSerialNumber
=
cashAccount
.
SerialNumber
;
item
.
PayerAccountSerialNumber
=
item
.
PayerAccountSerialNumber
.
IsNullOrEmpty
()
?
cashAccount
.
SerialNumber
:
item
.
PayerAccount
SerialNumber
;
item
.
PayeeAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayeeAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayeeAccountName
=
accountBalance
.
Name
;
item
.
PayeeAccountName
=
accountBalance
.
Name
;
...
@@ -155,7 +155,7 @@ namespace Kivii.Finances.Transforms
...
@@ -155,7 +155,7 @@ namespace Kivii.Finances.Transforms
if
(
item
.
Amount
<=
0
)
continue
;
if
(
item
.
Amount
<=
0
)
continue
;
var
itemKvid
=
Guid
.
NewGuid
();
var
itemKvid
=
Guid
.
NewGuid
();
item
.
AmountInvoice
=
0
;
item
.
AmountInvoice
=
0
;
item
.
AmountSplited
=
0
;
item
.
AmountSplited
=
item
.
Amount
;
item
.
AmountUsed
=
0
;
item
.
AmountUsed
=
0
;
item
.
OwnerKvid
=
ownerKvid
;
item
.
OwnerKvid
=
ownerKvid
;
...
@@ -169,9 +169,9 @@ namespace Kivii.Finances.Transforms
...
@@ -169,9 +169,9 @@ namespace Kivii.Finances.Transforms
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
ParentKvid
=
Guid
.
Empty
;
item
.
PayerAccountKvid
=
posAccount
.
Kvid
;
item
.
PayerAccountKvid
=
posAccount
.
Kvid
;
item
.
PayerAccountName
=
posAccount
.
Name
;
item
.
PayerAccountName
=
item
.
PayerAccountName
.
IsNullOrEmpty
()
?
posAccount
.
Name
:
item
.
PayerAccount
Name
;
item
.
PayerAccountOwnerName
=
posAccount
.
OwnerName
;
item
.
PayerAccountOwnerName
=
item
.
PayerAccountOwnerName
.
IsNullOrEmpty
()
?
posAccount
.
OwnerName
:
item
.
PayerAccount
OwnerName
;
item
.
PayerAccountSerialNumber
=
posAccount
.
SerialNumber
;
item
.
PayerAccountSerialNumber
=
item
.
PayerAccountSerialNumber
.
IsNullOrEmpty
()
?
posAccount
.
SerialNumber
:
item
.
PayerAccount
SerialNumber
;
item
.
PayeeAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayeeAccountKvid
=
accountBalance
.
Kvid
;
item
.
PayeeAccountName
=
accountBalance
.
Name
;
item
.
PayeeAccountName
=
accountBalance
.
Name
;
...
...
Src/Transforms/RestfulPayment.Offset.cs
View file @
71e4d546
...
@@ -30,7 +30,8 @@ namespace Kivii.Finances.Transforms
...
@@ -30,7 +30,8 @@ namespace Kivii.Finances.Transforms
if
(
payments
.
Exists
(
o
=>
o
.
Type
!=
PaymentType
.
Bank
&&
o
.
Type
!=
PaymentType
.
Cash
&&
o
.
Type
!=
PaymentType
.
Pos
&&
o
.
Type
!=
PaymentType
.
AliPay
&&
o
.
Type
!=
PaymentType
.
WeChat
))
throw
new
Exception
(
"非可冲销收款类型!"
);
if
(
payments
.
Exists
(
o
=>
o
.
Type
!=
PaymentType
.
Bank
&&
o
.
Type
!=
PaymentType
.
Cash
&&
o
.
Type
!=
PaymentType
.
Pos
&&
o
.
Type
!=
PaymentType
.
AliPay
&&
o
.
Type
!=
PaymentType
.
WeChat
))
throw
new
Exception
(
"非可冲销收款类型!"
);
if
(
payments
.
Exists
(
o
=>
o
.
BizKvid
!=
Guid
.
Empty
))
throw
new
Exception
(
"收付款已关联业务!请先解除关联!"
);
if
(
payments
.
Exists
(
o
=>
o
.
BizKvid
!=
Guid
.
Empty
))
throw
new
Exception
(
"收付款已关联业务!请先解除关联!"
);
if
(
payments
.
Exists
(
o
=>
o
.
OffsetKvid
!=
Guid
.
Empty
))
throw
new
Exception
(
"收付款已冲账"
);
if
(
payments
.
Exists
(
o
=>
o
.
OffsetKvid
!=
Guid
.
Empty
))
throw
new
Exception
(
"收付款已冲账"
);
(
payments
.
Exists
(
o
=>
o
.
AmountInvoice
>
0
||
o
.
AmountSplited
>
0
||
o
.
AmountUsed
>
0
)).
ThrowIfTrue
(
$"不可冲账,存在到账已开票:
{
payments
.
Sum
(
o
=>
o
.
AmountInvoice
)}
元,已认领:
{
payments
.
Sum
(
o
=>
o
.
AmountSplited
)}
元,已使用:
{
payments
.
Sum
(
o
=>
o
.
AmountUsed
)}
元"
);
if
(
payments
.
Exists
(
o
=>
o
.
Type
!=
PaymentType
.
Cash
&&
o
.
Type
!=
PaymentType
.
Pos
))
(
payments
.
Exists
(
o
=>
o
.
AmountInvoice
>
0
||
o
.
AmountSplited
>
0
||
o
.
AmountUsed
>
0
)).
ThrowIfTrue
(
$"不可冲账,存在到账已开票:
{
payments
.
Sum
(
o
=>
o
.
AmountInvoice
)}
元,已认领:
{
payments
.
Sum
(
o
=>
o
.
AmountSplited
)}
元,已使用:
{
payments
.
Sum
(
o
=>
o
.
AmountUsed
)}
元"
);
else
(
payments
.
Exists
(
o
=>
o
.
AmountInvoice
>
0
||
o
.
AmountUsed
>
0
)).
ThrowIfTrue
(
$"不可冲账,存在到账已开票:
{
payments
.
Sum
(
o
=>
o
.
AmountInvoice
)}
元,已使用:
{
payments
.
Sum
(
o
=>
o
.
AmountUsed
)}
元"
);
//查询当前项的拆分子项List
//查询当前项的拆分子项List
if
(
conn
.
Exists
<
Payment
>(
o
=>
Sql
.
In
(
o
.
ParentKvid
,
payments
.
ConvertAll
(
p
=>
p
.
Kvid
))
&&
o
.
OffsetKvid
==
Guid
.
Empty
))
throw
new
Exception
(
"不可冲账,此到账存在未冲账子项!"
);
if
(
conn
.
Exists
<
Payment
>(
o
=>
Sql
.
In
(
o
.
ParentKvid
,
payments
.
ConvertAll
(
p
=>
p
.
Kvid
))
&&
o
.
OffsetKvid
==
Guid
.
Empty
))
throw
new
Exception
(
"不可冲账,此到账存在未冲账子项!"
);
if
(
conn
.
Exists
<
InvoiceApply
>(
o
=>
Sql
.
In
(
o
.
BizKvid
,
payments
.
ConvertAll
(
p
=>
p
.
Kvid
))
&&
o
.
OffsetKvid
==
Guid
.
Empty
))
throw
new
Exception
(
"申请开票中,不可冲账!"
);
if
(
conn
.
Exists
<
InvoiceApply
>(
o
=>
Sql
.
In
(
o
.
BizKvid
,
payments
.
ConvertAll
(
p
=>
p
.
Kvid
))
&&
o
.
OffsetKvid
==
Guid
.
Empty
))
throw
new
Exception
(
"申请开票中,不可冲账!"
);
...
...
Src/Transforms/RestfulPayment.Split.cs
View file @
71e4d546
...
@@ -74,7 +74,7 @@ namespace Kivii.Finances.Transforms
...
@@ -74,7 +74,7 @@ namespace Kivii.Finances.Transforms
if
(
payment
.
AmountSplited
+
Amount
>
payment
.
Amount
)
throw
new
Exception
(
"认领金额超出范围!"
);
if
(
payment
.
AmountSplited
+
Amount
>
payment
.
Amount
)
throw
new
Exception
(
"认领金额超出范围!"
);
bank
=
payment
;
bank
=
payment
;
split
=
bank
.
BizSplit
(
Amount
,
ownerKvid
,
ownerName
);
split
=
bank
.
BizSplit
(
Amount
,
ownerKvid
,
ownerName
,
conn
);
#
region
记录日志
#
region
记录日志
log
=
new
EntityLog
<
Payment
>();
log
=
new
EntityLog
<
Payment
>();
...
@@ -201,7 +201,7 @@ namespace Kivii.Finances.Transforms
...
@@ -201,7 +201,7 @@ namespace Kivii.Finances.Transforms
{
{
var
amount
=
payment
.
Amount
-
payment
.
AmountSplited
;
var
amount
=
payment
.
Amount
-
payment
.
AmountSplited
;
if
(
amount
<=
0
)
continue
;
if
(
amount
<=
0
)
continue
;
var
splitPayment
=
payment
.
BizSplit
(
amount
,
ownerKvid
,
ownerName
);
var
splitPayment
=
payment
.
BizSplit
(
amount
,
ownerKvid
,
ownerName
,
conn
);
splits
.
Add
(
splitPayment
);
splits
.
Add
(
splitPayment
);
banks
.
Add
(
payment
);
banks
.
Add
(
payment
);
...
...
Src/Transforms/RestfulPayment.cs
View file @
71e4d546
...
@@ -15,7 +15,7 @@ namespace Kivii.Finances.Transforms
...
@@ -15,7 +15,7 @@ namespace Kivii.Finances.Transforms
}
}
[
Api
(
Description
=
"到账查询"
)]
[
Api
(
Description
=
"到账查询
Ex
"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
PaymentQueryEx
:
RestfulExecution
<
Payment
>
public
class
PaymentQueryEx
:
RestfulExecution
<
Payment
>
{
{
...
...
Src/Transforms/RestfulSettlement.cs
View file @
71e4d546
...
@@ -131,11 +131,30 @@ namespace Kivii.Finances.Transforms
...
@@ -131,11 +131,30 @@ namespace Kivii.Finances.Transforms
{
{
public
Guid
Kvid
{
get
;
set
;
}
public
Guid
Kvid
{
get
;
set
;
}
public
bool
IncludeDetail
{
get
;
set
;
}
public
override
object
OnExecutionGeneric
<
G
>(
IRequest
req
,
IResponse
res
)
public
override
object
OnExecutionGeneric
<
G
>(
IRequest
req
,
IResponse
res
)
{
{
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
EntitySettlement
<
G
>>();
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
EntitySettlement
<
G
>>();
var
rtns
=
new
RestfulReadResponse
<
EntitySettlement
<
G
>>();
var
rtns
=
new
RestfulReadResponse
<
EntitySettlement
<
G
>>();
rtns
.
Result
=
conn
.
SingleById
<
EntitySettlement
<
G
>>(
Kvid
);
rtns
.
Result
=
new
EntitySettlement
<
G
>();
if
(
typeof
(
G
)
!=
typeof
(
Settlement
))
rtns
.
Result
=
conn
.
SingleById
<
EntitySettlement
<
G
>>(
Kvid
);
else
{
var
settlement
=
conn
.
SingleById
<
Settlement
>(
Kvid
);
if
(
settlement
!=
null
)
rtns
.
Result
.
PopulateWith
(
settlement
);
}
if
(
IncludeDetail
)
{
var
details
=
conn
.
Select
<
EntitySettlementDetail
<
G
>>(
o
=>
o
.
SettlementKvid
==
Kvid
&&
o
.
OffsetKvid
==
Guid
.
Empty
);
rtns
.
Result
.
Details
=
new
List
<
SettlementDetail
>();
foreach
(
var
item
in
details
)
{
var
detail
=
new
SettlementDetail
();
detail
.
PopulateWith
(
item
);
rtns
.
Result
.
Details
.
Add
(
detail
);
}
}
return
rtns
;
return
rtns
;
}
}
}
}
...
@@ -144,6 +163,63 @@ namespace Kivii.Finances.Transforms
...
@@ -144,6 +163,63 @@ namespace Kivii.Finances.Transforms
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
SettlementQuery
:
RestfulQuery
<
Settlement
>
public
class
SettlementQuery
:
RestfulQuery
<
Settlement
>
{
{
}
[
Api
(
Description
=
"结算查询Ex"
)]
[
RequiresAnyRole
(
SystemRoles
.
Everyone
)]
public
class
SettlementQueryEx
:
RestfulExecution
<
Settlement
>
{
#
region
QueryArgs
public
virtual
int
?
Skip
{
get
;
set
;
}
public
virtual
int
?
Take
{
get
;
set
;
}
public
virtual
string
OrderBy
{
get
;
set
;
}
public
string
OrderByDesc
{
get
;
set
;
}
public
virtual
string
Include
{
get
;
set
;
}
public
virtual
string
Fields
{
get
;
set
;
}
public
string
QueryKeys
{
get
;
set
;
}
public
string
QueryValues
{
get
;
set
;
}
#
endregion
public
bool
?
IsPayed
{
get
;
set
;
}
//是否已经收款
public
bool
?
IsBilled
{
get
;
set
;
}
//是否已经制作过账单
public
override
object
OnExecution
(
IRequest
req
,
IResponse
res
)
{
var
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Settlement
>();
var
dynamicParams
=
Request
.
GetRequestParams
();
var
autoQuery
=
Request
.
TryResolve
<
IAutoQueryDb
>();
autoQuery
.
IncludeTotal
=
true
;
var
request
=
new
RestfulQuery
<
Settlement
>();
request
=
request
.
PopulateWith
(
this
);
var
sqlExpress
=
autoQuery
.
CreateQuery
(
Request
,
conn
,
request
,
dynamicParams
);
if
(
IsPayed
!=
null
)
{
if
(
IsPayed
.
Value
)
sqlExpress
.
And
(
o
=>
o
.
PayKvid
!=
Guid
.
Empty
);
else
sqlExpress
.
And
(
o
=>
o
.
PayKvid
==
Guid
.
Empty
);
}
if
(
IsBilled
!=
null
)
{
var
queryBillDetails
=
conn
.
From
<
BillDetail
>();
queryBillDetails
.
Where
(
o
=>
o
.
OffsetKvid
==
Guid
.
Empty
);
queryBillDetails
.
Select
(
o
=>
o
.
BizKvid
);
if
(
IsBilled
.
Value
)
sqlExpress
.
And
(
o
=>
Sql
.
In
(
o
.
Kvid
,
queryBillDetails
));
else
sqlExpress
.
And
(
o
=>
!
Sql
.
In
(
o
.
Kvid
,
queryBillDetails
));
}
var
rtns
=
autoQuery
.
Execute
(
Request
,
conn
,
request
,
sqlExpress
);
return
rtns
;
}
}
}
[
Api
(
Description
=
"结算删除"
)]
[
Api
(
Description
=
"结算删除"
)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment