|
@@ -9,16 +9,19 @@ import (
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// simpleMakeInvoice 简单开票
|
|
|
+// simpleMakeInvoice 简单开票(包含一个订单开多张票)
|
|
|
func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
var (
|
|
|
res gdb.Result
|
|
|
)
|
|
|
- //查询需要开票的数据(新开发票【a.invoice_status=0 AND a.invoice_changed=0】,红冲后新开【a.invoice_status=2 AND a.invoice_changed=1】)
|
|
|
- res, err = g.DB().Query(ctx, "SELECT a.*,b.pay_way,b.order_money,b.pay_money FROM invoice a INNER JOIN dataexport_order b ON a.order_code=b.order_code WHERE ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1 )) AND a.invoice_variety='普通发票(电子发票)' AND a.invoice_order_code is NULL AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
+ //查询需要开票的数据
|
|
|
+ //(新开发票【a.invoice_status=0 AND a.invoice_changed=0】,红冲后新开【a.invoice_status=2 AND a.invoice_changed=1】)
|
|
|
+ //线上申请发票【invoice_order_code is null 】, 管理后台一个订单拆分多个发票【invoice_order_code not like '%,%'】
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,b.pay_way,b.order_money,b.pay_money FROM invoice a INNER JOIN dataexport_order b ON a.order_code=b.order_code WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1 )) AND (a.invoice_order_code is NULL OR a.invoice_code not like '%,%') AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
if err != nil {
|
|
|
err = gerror.Wrap(err, "simpleMakeInvoice-查询待开票异常")
|
|
|
return
|
|
@@ -32,9 +35,11 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
return
|
|
|
}
|
|
|
var (
|
|
|
- iType = gconv.String(m["invoice_type"])
|
|
|
- remark = gconv.String(m["remark"])
|
|
|
- prices float64
|
|
|
+ iType = gconv.String(m["invoice_type"])
|
|
|
+ remark = gconv.String(m["remark"])
|
|
|
+ invoiceVariety = gconv.String(m["invoice_variety"])
|
|
|
+ invoiceContent = gconv.String(m["invoice_content"])
|
|
|
+ prices float64
|
|
|
)
|
|
|
|
|
|
//公对公转账 账单金额可以修改 开发票应取实付金额 pay_money
|
|
@@ -47,16 +52,22 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
|
|
|
c := MakeInvoiceData{
|
|
|
Type: "2",
|
|
|
- Id: fmt.Sprintf("id:%d", gconv.Int64(m["id"])), //因为orderCode不唯一,此处用订单发票数据库id
|
|
|
+ Id: fmt.Sprintf("id:%d", gconv.Int64(m["id"])), //因为orderCode不唯一,此处禁止使用orderCode
|
|
|
Notes: remark,
|
|
|
Fhr: g.Cfg().MustGet(ctx, "company.hfr", "贺鹏飞").String(),
|
|
|
InvoiceArr: []MakeInvoiceItems{{
|
|
|
- Xmmc: g.Cfg().MustGet(ctx, "company.taxCode").String(), //开票项
|
|
|
- WhStatus: 1, //开票项是否维护
|
|
|
- Je: strconv.FormatFloat(prices, 'f', -1, 64), //金额
|
|
|
- Sl: "1", //数量
|
|
|
+ Xmmc: consts.GetTaxCodeByName(invoiceContent), //开票项
|
|
|
+ WhStatus: 1, //开票项是否维护
|
|
|
+ Je: strconv.FormatFloat(prices, 'f', -1, 64), //金额
|
|
|
+ Sl: "1", //数量
|
|
|
}},
|
|
|
}
|
|
|
+
|
|
|
+ // 1 增值税专用发票;2 普通发票
|
|
|
+ if strings.Contains(invoiceVariety, "专用") {
|
|
|
+ c.Type = "1"
|
|
|
+ }
|
|
|
+
|
|
|
if iType == "单位" {
|
|
|
c.Gmfmc = gconv.String(m["company_name"])
|
|
|
c.Gmfnsrsbh = gconv.String(m["taxpayer_identnum"])
|
|
@@ -80,12 +91,13 @@ func (im *InvoiceManager) simpleMakeInvoice(ctx context.Context) (total, okNum i
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// selfMakeInvoice 自助开票
|
|
|
+// selfMakeInvoice 联合开票(多个订单开一张发票)
|
|
|
func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int, end bool, err error) {
|
|
|
var (
|
|
|
res gdb.Result
|
|
|
)
|
|
|
- res, err = g.DB().Query(ctx, "SELECT a.invoice_money,a.only_Identifying,a.invoice_type,a.company_name,a.taxpayer_identnum,a.remark FROM invoice a WHERE a.invoice_status=0 AND a.invoice_changed=0 AND a.invoice_variety='电子普通发票' AND a.invoice_order_code is not NULL AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
|
|
|
+ //(新开发票【a.invoice_status=0 AND a.invoice_changed=0】,红冲后新开【a.invoice_status=2 AND a.invoice_changed=1】)
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT a.invoice_type,a.remark,a.invoice_variety,a.taxpayer_identnum,a.company_name,a.invoice_content,a.invoice_money FROM invoice a WHERE a.invoice_variety like '%电子%' AND ((a.invoice_status=0 AND a.invoice_changed=0) or (a.invoice_status=2 AND a.invoice_changed=1)) AND a.invoice_code like '%,%' AND a.create_time > ? GROUP BY invoice_order_code", consts.InvoiceStartTime.Unix())
|
|
|
if err != nil {
|
|
|
err = gerror.Wrap(err, "selfMakeInvoice-查询待开票异常")
|
|
|
return
|
|
@@ -99,23 +111,30 @@ func (im *InvoiceManager) selfMakeInvoice(ctx context.Context) (total, okNum int
|
|
|
return
|
|
|
}
|
|
|
var (
|
|
|
- orderCode = gconv.String(m["only_Identifying"])
|
|
|
- iType = gconv.String(m["invoice_type"])
|
|
|
- prices = gconv.Float64(m["invoice_money"]) / float64(100)
|
|
|
- remark = gconv.String(m["remark"])
|
|
|
+ onlyIdentifying = gconv.String(m["only_Identifying"])
|
|
|
+ iType = gconv.String(m["invoice_type"])
|
|
|
+ prices = gconv.Float64(m["invoice_money"]) / float64(100)
|
|
|
+ remark = gconv.String(m["remark"])
|
|
|
+ invoiceVariety = gconv.String(m["invoice_variety"])
|
|
|
+ invoiceContent = gconv.String(m["invoice_content"])
|
|
|
)
|
|
|
c := MakeInvoiceData{
|
|
|
Type: "2",
|
|
|
- Id: fmt.Sprintf("only_Identifying:%s", orderCode),
|
|
|
+ Id: fmt.Sprintf("only_Identifying:%s", onlyIdentifying),
|
|
|
Notes: remark,
|
|
|
Fhr: g.Cfg().MustGet(ctx, "company.hfr", "贺鹏飞").String(),
|
|
|
InvoiceArr: []MakeInvoiceItems{{
|
|
|
- Xmmc: g.Cfg().MustGet(ctx, "company.taxCode").String(), //开票项
|
|
|
- WhStatus: 1, //开票项是否维护
|
|
|
- Je: strconv.FormatFloat(prices, 'f', -1, 64), //金额
|
|
|
- Sl: "1", //数量
|
|
|
+ Xmmc: consts.GetTaxCodeByName(invoiceContent), //开票项
|
|
|
+ WhStatus: 1, //开票项是否维护
|
|
|
+ Je: strconv.FormatFloat(prices, 'f', -1, 64), //金额
|
|
|
+ Sl: "1", //数量
|
|
|
}},
|
|
|
}
|
|
|
+ // 1 增值税专用发票;2 普通发票
|
|
|
+ if strings.Contains(invoiceVariety, "专用") {
|
|
|
+ c.Type = "1"
|
|
|
+ }
|
|
|
+
|
|
|
if iType == "单位" {
|
|
|
c.Gmfmc = gconv.String(m["company_name"])
|
|
|
c.Gmfnsrsbh = gconv.String(m["taxpayer_identnum"])
|
|
@@ -145,7 +164,7 @@ func (im *InvoiceManager) makeRedInvoice(ctx context.Context) (total, okNum int,
|
|
|
res gdb.Result
|
|
|
)
|
|
|
//冲红任务
|
|
|
- res, err = g.DB().Query(ctx, "SELECT invoice_number,billing_time FROM invoice a WHERE a.invoice_status=0 AND a.invoice_changed=1 AND a.invoice_variety='普通发票(电子发票)' AND a.invoice_order_code is NULL AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
+ res, err = g.DB().Query(ctx, "SELECT invoice_number,billing_time FROM invoice a WHERE a.invoice_variety like '%电子%' AND a.invoice_status=0 AND a.invoice_changed=1 AND a.invoice_order_code is NULL AND a.create_time > ? ", consts.InvoiceStartTime.Unix())
|
|
|
if err != nil {
|
|
|
err = gerror.Wrap(err, "selfMakeChangeInvoice-查询待冲红订单异常")
|
|
|
return
|