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
79bd88b3
Commit
79bd88b3
authored
Feb 21, 2023
by
陶然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决借票冲销撤销接口bug
parent
06a7a83b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
175 additions
and
170 deletions
+175
-170
PaymentExtension.cs
Src/Extensions/PaymentExtension.cs
+172
-169
RestfulInvoice.Debit.cs
Src/Transforms/RestfulInvoice.Debit.cs
+3
-1
No files found.
Src/Extensions/PaymentExtension.cs
View file @
79bd88b3
...
@@ -310,6 +310,153 @@ namespace Kivii.Finances
...
@@ -310,6 +310,153 @@ namespace Kivii.Finances
/// <summary>
/// <summary>
/// complate!
/// complate!
/// 重新计算Payment的 AmountInvoice
/// 只针对Bank等根级Payment
/// </summary>
/// <param name="payment"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
static
Payment
RecalculateAmountInvoice
(
this
Payment
payment
,
IDbConnection
conn
=
null
)
{
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
Type
!=
PaymentType
.
Bank
&&
payment
.
Type
!=
PaymentType
.
Split
).
ThrowIfTrue
(
"不支持的类型"
);
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
var
amountInvoiced
=
conn
.
Scalar
<
Payment
,
decimal
>(
o
=>
Sql
.
Sum
(
o
.
AmountInvoice
),
p
=>
Sql
.
In
(
p
.
Type
,
PaymentType
.
Assign
,
PaymentType
.
Split
)
&&
p
.
ParentKvid
==
payment
.
Kvid
&&
p
.
OffsetKvid
==
Guid
.
Empty
);
Payment
parentPayment
=
null
;
if
(
payment
.
ParentKvid
!=
Guid
.
Empty
)
parentPayment
=
conn
.
SingleById
<
Payment
>(
payment
.
ParentKvid
);
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
try
{
payment
.
AmountInvoice
=
amountInvoiced
;
payment
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
conn
.
UpdateOnly
(
payment
);
if
(
parentPayment
!=
null
)
parentPayment
.
RecalculateAmountSplit
(
conn
);
trans
?.
Commit
();
return
payment
;
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
}
/// <summary>
/// 重新计算Assign类型的AmountInvoice或AmountUsed
/// 如果是上级到账进行开票,收款登记或充值的话,存在子集Assign则需要向下更新对应的AmountInvoice和AmountUsed
/// </summary>
/// <param name="payment"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
static
List
<
Payment
>
RecalculateAssignAmount
(
this
Payment
payment
,
IDbConnection
conn
=
null
)
{
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
Type
!=
PaymentType
.
Split
).
ThrowIfTrue
(
"不支持的类型"
);
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
//查看已经拆分的项目分得的已经开票金额
var
existSplits
=
conn
.
Select
<
Payment
>(
o
=>
o
.
ParentKvid
==
payment
.
Kvid
&&
o
.
OffsetKvid
==
Guid
.
Empty
&&
o
.
Type
==
PaymentType
.
Assign
);
if
(
existSplits
.
IsNullOrEmpty
())
return
null
;
if
(
payment
.
AmountInvoice
<=
0
)
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountInvoice
==
0
)
continue
;
item
.
AmountInvoice
=
0
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
}
}
else
//如果要拆分的到账已经开过票 就要计算拆分项的开票金额
{
if
(
payment
.
AmountInvoice
<
payment
.
Amount
)
//到账的部分进行了开票 就需要计算拆分项的开票金额
{
var
amountInvoice
=
payment
.
AmountInvoice
;
foreach
(
var
item
in
existSplits
)
{
var
currentAmount
=
amountInvoice
>
item
.
Amount
?
item
.
Amount
:
amountInvoice
;
item
.
AmountInvoice
=
currentAmount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
amountInvoice
-=
currentAmount
;
}
}
else
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountInvoice
==
item
.
Amount
)
continue
;
item
.
AmountInvoice
=
item
.
Amount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
}
}
}
if
(
payment
.
AmountUsed
<=
0
)
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountUsed
==
0
)
continue
;
item
.
AmountUsed
=
0
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
}
}
else
//如果要拆分的到账已经开过票 就要计算拆分项的开票金额
{
if
(
payment
.
AmountUsed
<
payment
.
Amount
)
//到账的部分进行了开票 就需要计算拆分项的开票金额
{
var
amountUsed
=
payment
.
AmountUsed
;
foreach
(
var
item
in
existSplits
)
{
var
currentAmount
=
amountUsed
>
item
.
Amount
?
item
.
Amount
:
amountUsed
;
item
.
AmountUsed
=
currentAmount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
amountUsed
-=
currentAmount
;
}
}
else
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountUsed
==
item
.
Amount
)
continue
;
item
.
AmountUsed
=
item
.
Amount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
}
}
}
var
rtns
=
new
List
<
Payment
>();
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
try
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
OnlyProperties
.
IsNullOrEmpty
())
continue
;
conn
.
UpdateOnly
(
item
);
rtns
.
Add
(
item
);
}
trans
?.
Commit
();
return
rtns
;
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
}
/// <summary>
/// complate!
/// 到账冲账,此方法不做业务判断,传过来的Payment均可Offset,除已经冲账过的
/// 到账冲账,此方法不做业务判断,传过来的Payment均可Offset,除已经冲账过的
/// </summary>
/// </summary>
/// <param name="payment"></param>
/// <param name="payment"></param>
...
@@ -399,35 +546,38 @@ namespace Kivii.Finances
...
@@ -399,35 +546,38 @@ namespace Kivii.Finances
else
amountUsed
=
amountAssign
;
else
amountUsed
=
amountAssign
;
}
}
#
region
新增拆分项目
#
region
新增拆分项目
var
split
Payment
=
new
Payment
();
var
assign
Payment
=
new
Payment
();
split
Payment
.
PopulateWith
(
payment
);
//先从父级中拷贝所有参数
assign
Payment
.
PopulateWith
(
payment
);
//先从父级中拷贝所有参数
//赋值
//赋值
split
Payment
.
Kvid
=
Guid
.
NewGuid
();
assign
Payment
.
Kvid
=
Guid
.
NewGuid
();
split
Payment
.
ParentKvid
=
payment
.
Kvid
;
assign
Payment
.
ParentKvid
=
payment
.
Kvid
;
split
Payment
.
RootKvid
=
payment
.
RootKvid
;
assign
Payment
.
RootKvid
=
payment
.
RootKvid
;
split
Payment
.
OffsetKvid
=
Guid
.
Empty
;
assign
Payment
.
OffsetKvid
=
Guid
.
Empty
;
split
Payment
.
OwnerKvid
=
ownerKvid
==
null
?
Guid
.
Empty
:
ownerKvid
.
Value
;
assign
Payment
.
OwnerKvid
=
ownerKvid
==
null
?
Guid
.
Empty
:
ownerKvid
.
Value
;
split
Payment
.
OwnerName
=
ownerName
;
assign
Payment
.
OwnerName
=
ownerName
;
//业务设置
//业务设置
split
Payment
.
BizId
=
string
.
Empty
;
assign
Payment
.
BizId
=
string
.
Empty
;
split
Payment
.
BizKvid
=
Guid
.
Empty
;
assign
Payment
.
BizKvid
=
Guid
.
Empty
;
split
Payment
.
BizType
=
string
.
Empty
;
assign
Payment
.
BizType
=
string
.
Empty
;
split
Payment
.
SerialNumber
=
payment
.
GetSubSerialNumber
();
assign
Payment
.
SerialNumber
=
payment
.
GetSubSerialNumber
();
split
Payment
.
Type
=
PaymentType
.
Assign
;
assign
Payment
.
Type
=
PaymentType
.
Assign
;
//金额设置
//金额设置
split
Payment
.
Amount
=
amountAssign
;
assign
Payment
.
Amount
=
amountAssign
;
split
Payment
.
AmountSplited
=
0
;
assign
Payment
.
AmountSplited
=
0
;
split
Payment
.
AmountUsed
=
amountUsed
;
assign
Payment
.
AmountUsed
=
amountUsed
;
split
Payment
.
AmountInvoice
=
amountInvoice
;
// payment.AmountInvoice > amountSplit ? amountSplit : payment.AmountInvoice;
assign
Payment
.
AmountInvoice
=
amountInvoice
;
// payment.AmountInvoice > amountSplit ? amountSplit : payment.AmountInvoice;
//splitPayment.Summary = string.Empty;
//splitPayment.Summary = string.Empty;
if
(!
remark
.
IsNullOrEmpty
())
splitPayment
.
Remark
+=
$"[划转备注:
{
remark
}
]"
;
if
(!
remark
.
IsNullOrEmpty
())
assignPayment
.
Remark
+=
$"[划转备注:
{
remark
}
]"
;
splitPayment
.
OperateTime
=
payment
.
OperateTime
;
assignPayment
.
OperateTime
=
payment
.
OperateTime
;
splitPayment
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
assignPayment
.
OperatorName
=
KiviiContext
.
CurrentMember
.
FullName
;
splitPayment
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
assignPayment
.
OperatorKvid
=
KiviiContext
.
CurrentMember
.
Kvid
;
if
(
assignPayment
.
Metadata
.
IsNullOrEmpty
())
assignPayment
.
Metadata
=
new
Dictionary
<
string
,
string
>();
assignPayment
.
Metadata
[
"AssignOwnerName"
]
=
payment
.
OwnerName
;
assignPayment
.
Metadata
[
"AssignOwnerKvid"
]
=
payment
.
OwnerKvid
.
ToString
();
//splitPayment.Status = 1;
//splitPayment.Status = 1;
#
endregion
#
endregion
return
split
Payment
;
return
assign
Payment
;
}
}
/// <summary>
/// <summary>
...
@@ -571,152 +721,5 @@ namespace Kivii.Finances
...
@@ -571,152 +721,5 @@ namespace Kivii.Finances
return
splitPayment
;
return
splitPayment
;
}
}
/// <summary>
/// complate!
/// 重新计算Payment的 AmountInvoice
/// 只针对Bank等根级Payment
/// </summary>
/// <param name="payment"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
static
Payment
RecalculateAmountInvoice
(
this
Payment
payment
,
IDbConnection
conn
=
null
)
{
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
Type
!=
PaymentType
.
Bank
&&
payment
.
Type
!=
PaymentType
.
Split
).
ThrowIfTrue
(
"不支持的类型"
);
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
var
amountInvoiced
=
conn
.
Scalar
<
Payment
,
decimal
>(
o
=>
Sql
.
Sum
(
o
.
AmountInvoice
),
p
=>
Sql
.
In
(
p
.
Type
,
PaymentType
.
Assign
,
PaymentType
.
Split
)
&&
p
.
ParentKvid
==
payment
.
Kvid
&&
p
.
OffsetKvid
==
Guid
.
Empty
);
Payment
parentPayment
=
null
;
if
(
payment
.
ParentKvid
!=
Guid
.
Empty
)
parentPayment
=
conn
.
SingleById
<
Payment
>(
payment
.
ParentKvid
);
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
try
{
payment
.
AmountInvoice
=
amountInvoiced
;
payment
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
conn
.
UpdateOnly
(
payment
);
if
(
parentPayment
!=
null
)
parentPayment
.
RecalculateAmountSplit
(
conn
);
trans
?.
Commit
();
return
payment
;
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
}
/// <summary>
/// 重新计算Assign类型的AmountInvoice或AmountUsed
/// 如果是上级到账进行开票,收款登记或充值的话,存在子集Assign则需要向下更新对应的AmountInvoice和AmountUsed
/// </summary>
/// <param name="payment"></param>
/// <param name="conn"></param>
/// <returns></returns>
public
static
List
<
Payment
>
RecalculateAssignAmount
(
this
Payment
payment
,
IDbConnection
conn
=
null
)
{
payment
.
ThrowIfNull
(
"要更新的付款记录不能为空!"
);
(
payment
.
OffsetKvid
!=
Guid
.
Empty
).
ThrowIfTrue
(
"此到账已作废 无法重新计算开票金额"
);
(
payment
.
Type
!=
PaymentType
.
Split
).
ThrowIfTrue
(
"不支持的类型"
);
bool
useTransaction
=
conn
==
null
;
//是否启用事务,如果外部未传入conn,启用内部事务
if
(
conn
==
null
)
conn
=
KiviiContext
.
GetOpenedDbConnection
<
Payment
>();
//查看已经拆分的项目分得的已经开票金额
var
existSplits
=
conn
.
Select
<
Payment
>(
o
=>
o
.
RootKvid
==
payment
.
RootKvid
&&
o
.
OffsetKvid
==
Guid
.
Empty
&&
o
.
Type
==
PaymentType
.
Assign
);
if
(
existSplits
.
IsNullOrEmpty
())
return
null
;
if
(
payment
.
AmountInvoice
<=
0
)
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountInvoice
==
0
)
continue
;
item
.
AmountInvoice
=
0
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
}
}
else
//如果要拆分的到账已经开过票 就要计算拆分项的开票金额
{
if
(
payment
.
AmountInvoice
<
payment
.
Amount
)
//到账的部分进行了开票 就需要计算拆分项的开票金额
{
var
amountInvoice
=
payment
.
AmountInvoice
;
foreach
(
var
item
in
existSplits
)
{
var
currentAmount
=
amountInvoice
>
item
.
Amount
?
item
.
Amount
:
amountInvoice
;
item
.
AmountInvoice
=
currentAmount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
amountInvoice
-=
currentAmount
;
}
}
else
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountInvoice
==
item
.
Amount
)
continue
;
item
.
AmountInvoice
=
item
.
Amount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountInvoice
);
}
}
}
if
(
payment
.
AmountUsed
<=
0
)
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountUsed
==
0
)
continue
;
item
.
AmountUsed
=
0
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
}
}
else
//如果要拆分的到账已经开过票 就要计算拆分项的开票金额
{
if
(
payment
.
AmountUsed
<
payment
.
Amount
)
//到账的部分进行了开票 就需要计算拆分项的开票金额
{
var
amountUsed
=
payment
.
AmountUsed
;
foreach
(
var
item
in
existSplits
)
{
var
currentAmount
=
amountUsed
>
item
.
Amount
?
item
.
Amount
:
amountUsed
;
item
.
AmountUsed
=
currentAmount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
amountUsed
-=
currentAmount
;
}
}
else
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
AmountUsed
==
item
.
Amount
)
continue
;
item
.
AmountUsed
=
item
.
Amount
;
item
.
AddOnlyProperties
(
o
=>
o
.
AmountUsed
);
}
}
}
var
rtns
=
new
List
<
Payment
>();
IDbTransaction
trans
=
null
;
//事务,如果外部来了Connection,不生成事务
if
(
useTransaction
)
trans
=
conn
.
OpenTransaction
();
try
{
foreach
(
var
item
in
existSplits
)
{
if
(
item
.
OnlyProperties
.
IsNullOrEmpty
())
continue
;
conn
.
UpdateOnly
(
item
);
rtns
.
Add
(
item
);
}
trans
?.
Commit
();
return
rtns
;
}
catch
(
Exception
ex
)
{
trans
?.
Rollback
();
throw
ex
;
}
}
}
}
}
}
Src/Transforms/RestfulInvoice.Debit.cs
View file @
79bd88b3
...
@@ -208,7 +208,9 @@ namespace Kivii.Finances.Transforms
...
@@ -208,7 +208,9 @@ namespace Kivii.Finances.Transforms
{
{
foreach
(
var
item
in
splitPayments
)
foreach
(
var
item
in
splitPayments
)
{
{
if
(
item
.
OnlyProperties
.
Count
>
0
)
conn
.
UpdateOnly
(
item
);
if
(
item
.
OnlyProperties
.
Count
<=
0
)
continue
;
conn
.
UpdateOnly
(
item
);
item
.
RecalculateAssignAmount
(
conn
);
}
}
}
}
rtns
.
Results
.
AddRange
(
invoices
);
rtns
.
Results
.
AddRange
(
invoices
);
...
...
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