Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
4845ccce
Commit
4845ccce
authored
Apr 08, 2020
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dd
parent
06c05ef8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
146 additions
and
37 deletions
+146
-37
xggsve-invoice/app/base/api/impl/op/action.js
+4
-0
xggsve-invoice/app/base/db/impl/invoice/iinvoiceDao.js
+26
-0
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSve.js
+116
-37
No files found.
xggsve-invoice/app/base/api/impl/op/action.js
View file @
4845ccce
...
...
@@ -54,6 +54,10 @@ class ActionAPI extends APIBase {
case
"uploadDetail"
:
// 查询发票详细信息
opResult
=
await
this
.
iinvoiceSve
.
uploadDetailSve
(
action_body
);
break
;
case
"accumulatedAmount"
:
// 查询累计金额
opResult
=
await
this
.
iinvoiceSve
.
accumulatedAmount
(
action_body
);
break
;
// case "verificationAndCalculation": // 发票试算接口
// opResult = await rule.dispatcher(action_body);
// break;
...
...
xggsve-invoice/app/base/db/impl/invoice/iinvoiceDao.js
View file @
4845ccce
...
...
@@ -79,6 +79,32 @@ class IInvoiceDao extends Dao {
return
counts
[
0
];
}
//计算附加税累计
async
accumulatedAddValueAmountByTime
(
businessmen_credit_code
,
beginTime
,
endTime
){
let
sql
=
`select SUM(t1.additional_tax) AS additional_tax_total,SUM(t1.value_added_tax) AS value_added_tax_total from i_invoice t1
where t1.businessmen_credit_code = :businessmen_credit_code and t1.apply_time>= :beginTime and t1.apply_time <=:endTime`
;
let
res
=
await
this
.
customQuery
(
sql
,{
businessmen_credit_code
:
businessmen_credit_code
,
beginTime
:
beginTime
,
endTime
:
endTime
});
if
(
res
.
length
==
0
){
return
{
additional_tax_total
:
0
,
value_added_tax_total
:
0
};
}
return
{
additional_tax_total
:
res
[
0
].
additional_tax_total
||
0
,
value_added_tax_total
:
res
[
0
].
value_added_tax_total
||
0
};
}
/**
* 计算个税累计
* @param {*} beginTime
* @param {*} endTime
*/
async
accumulatedTaxAmountByTime
(
businessmen_credit_code
,
beginTime
,
endTime
){
let
sql
=
`select SUM(t1.personal_invoice_tax) AS personal_invoice_tax_total from i_invoice t1
where t1.businessmen_credit_code = :businessmen_credit_code and t1.apply_time>= :beginTime and t1.apply_time <= :endTime`
;
let
res
=
await
this
.
customQuery
(
sql
,{
businessmen_credit_code
:
businessmen_credit_code
,
beginTime
:
beginTime
,
endTime
:
endTime
});
if
(
!
res
||
res
.
length
==
0
)
{
return
{
personal_invoice_tax_total
:
0
};
}
return
{
personal_invoice_tax_total
:
res
[
0
].
personal_invoice_tax_total
||
0
};
}
// /**
// * 红冲列表总计
// * @param {*} params
...
...
xggsve-invoice/app/base/service/impl/invoice/iinvoiceSve.js
View file @
4845ccce
...
...
@@ -14,9 +14,9 @@ class IInvoiceService extends ServiceBase {
this
.
iinvoiceprocessDao
=
system
.
getObject
(
"db.invoice.iinvoiceprocessDao"
);
this
.
iinvoiceinforegDao
=
system
.
getObject
(
"db.invoice.iinvoiceinforegDao"
);
this
.
iinvoicedeliverDao
=
system
.
getObject
(
"db.invoice.iinvoicedeliverDao"
);
this
.
RULE_INVOICE_TYPE
=
[
"10"
,
'20'
,
'30'
];
//发票类型
this
.
RULE_BUSINESSMEN_TYPE
=
[
'10'
,
'20'
];
//销售方类型
this
.
DEFAULT_PRODUCT_ID
=
"50010000"
;
//默认产品ID
this
.
RULE_INVOICE_TYPE
=
[
"10"
,
'20'
,
'30'
];
//发票类型
this
.
RULE_BUSINESSMEN_TYPE
=
[
'10'
,
'20'
];
//销售方类型
this
.
DEFAULT_PRODUCT_ID
=
"50010000"
;
//默认产品ID
this
.
iproductDao
=
system
.
getObject
(
"db.product.iproductDao"
);
this
.
iprocessDao
=
system
.
getObject
(
"db.product.iprocessDao"
);
this
.
iproductprocessDao
=
system
.
getObject
(
"db.product.iproductprocessDao"
);
...
...
@@ -138,13 +138,19 @@ class IInvoiceService extends ServiceBase {
await
this
.
db
.
transaction
(
async
t
=>
{
_invoice
=
await
this
.
dao
.
create
(
_invoice
,
t
);
await
this
.
iinvoiceinforegDao
.
create
({
id
:
_invoice
.
id
},
t
);
await
this
.
iinvoicesummaryinfoDao
.
create
({
id
:
_invoice
.
id
},
t
);
await
this
.
iinvoiceinforegDao
.
create
({
id
:
_invoice
.
id
},
t
);
await
this
.
iinvoicesummaryinfoDao
.
create
({
id
:
_invoice
.
id
},
t
);
for
(
let
process
of
processList
)
{
process
.
invoice_id
=
_invoice
.
id
;
}
await
this
.
iinvoiceprocessDao
.
model
.
bulkCreate
(
processList
,
{
transaction
:
t
});
await
this
.
iinvoiceprocessDao
.
model
.
bulkCreate
(
processList
,
{
transaction
:
t
});
});
return
system
.
getResult
(
`success`
);
}
catch
(
error
)
{
...
...
@@ -160,32 +166,38 @@ class IInvoiceService extends ServiceBase {
let
total
=
await
this
.
dao
.
countByParams
(
params
);
if
(
total
==
0
)
{
return
system
.
getResult
({
count
:
0
,
rows
:
[]
});
return
system
.
getResult
({
count
:
0
,
rows
:
[]
});
}
let
list
=
await
this
.
dao
.
pageByParams
(
params
);
if
(
list
)
{
for
(
var
item
of
list
)
{
this
.
handleDate
(
item
,
[
'updated_at'
,
'created_at'
,
'invoice_time'
],
'YYYY-MM-DD HH:mm:ss'
);
this
.
handleDate
(
item
,
[
'updated_at'
,
'created_at'
,
'invoice_time'
],
'YYYY-MM-DD HH:mm:ss'
);
}
//格式化产品
await
this
.
setDeliver
(
list
);
//格式化业务员
await
this
.
setStatus
(
list
);
for
(
let
item
of
list
)
{
if
(
item
.
red_status
==
0
)
{
for
(
let
item
of
list
)
{
if
(
item
.
red_status
==
0
)
{
item
.
red_status_name
=
"红冲"
;
}
else
if
(
item
.
red_status
==
1
)
{
}
else
if
(
item
.
red_status
==
1
)
{
item
.
red_status_name
=
'已经红冲'
;
}
else
if
(
item
.
red_status
==
2
)
{
}
else
if
(
item
.
red_status
==
2
)
{
item
.
red_status_name
=
"红冲中"
;
}
else
{
}
else
{
item
.
red_status_name
=
""
;
}
}
await
this
.
setProduct
(
list
);
}
return
system
.
getResultSuccess
({
count
:
total
,
rows
:
list
});
return
system
.
getResultSuccess
({
count
:
total
,
rows
:
list
});
}
/**
...
...
@@ -291,7 +303,10 @@ class IInvoiceService extends ServiceBase {
if
(
!
nextObj
)
{
continue
;
}
nextStatus
.
push
({
next_status
:
nextObj
.
status
,
next_name
:
nextObj
.
name
});
nextStatus
.
push
({
next_status
:
nextObj
.
status
,
next_name
:
nextObj
.
name
});
}
let
orderProcess
=
{
...
...
@@ -317,35 +332,35 @@ class IInvoiceService extends ServiceBase {
* 根据ID查询发票详细信息
* @param {*} params
*/
async
queryInvoice
(
params
){
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 ID不能为空`
);
async
queryInvoice
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 ID不能为空`
);
}
try
{
let
_invoice
=
await
this
.
dao
.
getById
(
this
.
trim
(
params
.
id
));
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
}
this
.
handleDate
(
_invoice
,
[
'invoice_time'
,
'apply_time'
,
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
this
.
handleDate
(
_invoice
,
[
'invoice_time'
,
'apply_time'
,
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
let
_invoiceinforeg
=
await
this
.
iinvoiceinforegDao
.
getById
(
this
.
trim
(
params
.
id
))
||
{};
this
.
handleDate
(
_invoiceinforeg
,
[
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
let
_invoicedeliver
=
await
this
.
iinvoicedeliverDao
.
getById
(
_invoice
.
invoice_deliver_id
)
||
{};
let
_invoicedeliver
=
await
this
.
iinvoicedeliverDao
.
getById
(
_invoice
.
invoice_deliver_id
)
||
{};
this
.
handleDate
(
_invoicedeliver
,
[
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
let
_invoicesummaryinfo
=
await
this
.
iinvoicesummaryinfoDao
.
getById
(
this
.
trim
(
params
.
id
));
_invoicesummaryinfo
.
summary
=
JSON
.
parse
(
_invoicesummaryinfo
.
summary
);
this
.
handleDate
(
_invoicesummaryinfo
,
[
'invoice_time'
,
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
this
.
handleDate
(
_invoicesummaryinfo
,
[
'invoice_time'
,
'updated_at'
,
'created_at'
],
'YYYY-MM-DD HH:mm:ss'
);
_invoice
.
invoiceinforeg
=
_invoiceinforeg
;
_invoice
.
invoicedeliver
=
_invoicedeliver
;
_invoice
.
invoicesummaryinfo
=
_invoicesummaryinfo
;
_invoice
.
invoiceinforeg
=
_invoiceinforeg
;
_invoice
.
invoicedeliver
=
_invoicedeliver
;
_invoice
.
invoicesummaryinfo
=
_invoicesummaryinfo
;
_invoice
.
status_name
=
await
this
.
iprocessDao
.
queryInvoiceStatusName
(
_invoice
.
status
);
return
system
.
getResult
(
_invoice
);
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
@@ -353,20 +368,20 @@ class IInvoiceService extends ServiceBase {
* 更新记账
* @param {*} params
*/
async
uploadDetailSve
(
params
){
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 发票ID 不能为空`
);
async
uploadDetailSve
(
params
)
{
if
(
!
params
.
id
)
{
return
system
.
getResult
(
null
,
`参数错误 发票ID 不能为空`
);
}
try
{
let
_invoice
=
await
this
.
dao
.
model
.
findOne
({
where
:{
id
:
this
.
trim
(
params
.
id
)
where
:
{
id
:
this
.
trim
(
params
.
id
)
}
});
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
if
(
!
_invoice
)
{
return
system
.
getResult
(
null
,
`发票不存在`
);
}
_invoice
.
bookkeeping
=
1
;
_invoice
.
bookkeeping
=
1
;
_invoice
.
save
();
return
system
.
getResultSuccess
();
}
catch
(
error
)
{
...
...
@@ -375,6 +390,69 @@ class IInvoiceService extends ServiceBase {
}
}
}
module
.
exports
=
IInvoiceService
;
/**
* 计算累计金额
* @param {*} params
*/
async
accumulatedAmount
(
params
)
{
if
(
!
params
.
credit_code
)
{
return
system
.
getResult
(
null
,
`参数错误 统一社会信用代码不能为空`
);
}
if
(
!
params
.
invoiced_time
)
{
return
system
.
getResult
(
null
,
`参数错误 开票时间不能为空`
);
}
//计算增值税附加税 的时间
let
addValueTime
=
this
.
accumulatedTime
(
params
.
add_value_up_type
,
params
.
invoiced_time
);
//计算个税的时间
let
taxTime
=
this
.
accumulatedTime
(
params
.
tax_up_type
,
params
.
invoiced_time
);
try
{
let
addValueRes
=
await
this
.
dao
.
accumulatedAddValueAmountByTime
(
params
.
credit_code
,
addValueTime
.
beginTime
,
addValueTime
.
endTime
)
||
{};
let
taxValueRes
=
await
this
.
dao
.
accumulatedTaxAmountByTime
(
params
.
credit_code
,
taxTime
.
beginTime
,
taxTime
.
endTime
)
||
{};
return
system
.
getResult
({
addValueRes
,
taxValueRes
});
}
catch
(
error
)
{
console
.
log
(
error
);
return
system
.
getResult
(
null
,
`系统错误`
);
}
}
//计算时间 1:月 2:季度
accumulatedTime
(
type
,
invoiced_time
)
{
let
currentTime
=
moment
(
invoiced_time
);
let
beginTime
=
null
,
endTime
=
null
,
year
=
currentTime
.
year
(),
_month
=
currentTime
.
month
()
+
1
,
month
=
_month
<
10
?
"0"
+
_month
:
_month
,
date
=
null
;
if
(
type
==
1
)
{
date
=
"01"
;
let
maxDate
=
moment
(
`
${
year
}
-
${
month
}
`
,
"YYYY-MM"
).
daysInMonth
();
beginTime
=
`
${
year
}
-
${
month
}
-
${
date
}
00:00:00`
;
endTime
=
`
${
year
}
-
${
month
}
-
${
maxDate
}
00:00:00`
}
if
(
type
==
2
)
{
//获取当前是第几季度
let
currentQuarter
=
currentTime
.
quarter
();
//季度开始的时间
beginTime
=
moment
(
moment
(
year
+
'-01-01'
).
toDate
()).
quarter
(
currentQuarter
).
format
(
'YYYY-MM-DD HH:mm:ss'
);
let
endMonth
=
3
*
parseInt
(
currentQuarter
)
//当季度最后一个月
/* 对月数进行格式化 */
if
(
endMonth
<
10
)
endMonth
=
'0'
+
endMonth
else
endMonth
+=
''
let
endMonthDays
=
moment
(
year
+
'-'
+
endMonth
).
daysInMonth
();
// 末尾月天数
endTime
=
year
+
'-'
+
endMonth
+
'-'
+
endMonthDays
;
//完整年月日整合
}
return
{
beginTime
,
endTime
};
}
}
module
.
exports
=
IInvoiceService
;
\ No newline at end of file
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