2
3
baichengfei преди 5 години
родител
ревизия
2b4e1a283c

+ 2 - 1
src/dashoo.cn/backend/api/business/invoiceinfo/invoiceinfo.go

@@ -19,7 +19,8 @@ type OilInvoiceInfo struct {
 	InvoiceOn      time.Time `xorm:"comment('开票时间') DATETIME"`
 	BankSerialNum  string    `xorm:"VARCHAR(50)"`
 	Remark         string    `xorm:"VARCHAR(255)"`
-	Url		       string    `xorm:"comment('诺诺网发票pdf') VARCHAR(255)"`
+	Url            string    `xorm:"comment('诺诺网发票pdf') VARCHAR(255)"`
+	NuNuSerialNum  string	 `xorm:"comment('诺诺网发票流水号') VARCHAR(50)"`
 	WorkflowId     string    `xorm:"VARCHAR(50)"`
 	CreateUserId   int       `xorm:"INT(11)"`
 	CreateOn       time.Time `xorm:"DATETIME"`

+ 48 - 3
src/dashoo.cn/backend/api/controllers/oilsupplier/invoiceinfo.go

@@ -2,11 +2,13 @@ package oilsupplier
 
 import (
 	"dashoo.cn/backend/api/business/invoiceinfo"
+	"dashoo.cn/backend/api/business/oilsupplier/supplier"
 	"dashoo.cn/backend/api/business/paymentinfo"
 	"dashoo.cn/backend/api/business/workflow"
 	. "dashoo.cn/backend/api/controllers"
 	"dashoo.cn/utils"
 	"fmt"
+	"strconv"
 	"time"
 )
 
@@ -58,16 +60,51 @@ func (this *OilInvoiceController) UpdateIsInvoice() string {
 	// 诺诺网发票接口
 	invoice := invoiceinfo.GetInvoiceService(utils.DBE)
 	url := "https://nnfpbox.nuonuocs.cn/shop/buyer/allow/cxfKp/cxfServerKpOrderSync.action"
+	var entity invoiceinfo.OilInvoiceInfo
+	where := "Id=" + id
+	invoice.GetEntity(&entity, where)
+
+	sup := supplier.GetOilSupplierService(utils.DBE)
+	var supplierEntity supplier.OilSupplier
+	whereS := "Id=" + strconv.Itoa(entity.SupplierId)
+	sup.GetEntity(&supplierEntity, whereS)
+
+	var paylist []paymentinfo.PaymentinfoList
+	svcp := paymentinfo.GetPaymentService(utils.DBE)
+	where = "p.Id in (" + entity.SrcIds + ")"
+	svcp.GetPaymentinfoList1(where, &paylist)
+	paramsString := ""
+	for _, pay := range paylist {
+		var amount float64
+		pay.OilPaymentInfo.Amount = "500.00"
+		amount,_ = strconv.ParseFloat(pay.OilPaymentInfo.Amount, 64)
+		tax := fmt.Sprintf("%.2f", amount * 0.06 / 1.06)
+		//tax := math.Trunc(amount * 0.06 / 1.06)
+		var a float64
+		a,_ = strconv.ParseFloat(tax, 64)
+		typeString := ""
+		if pay.OilPaymentInfo.PayType == "1" {
+			typeString = "准入交费"
+		} else if pay.OilPaymentInfo.PayType == "2" {
+			typeString = "准入交费"
+		} else if pay.OilPaymentInfo.PayType == "3" {
+			typeString = "增项交费"
+		} else if pay.OilPaymentInfo.PayType == "7" {
+			typeString = "信息变更交费"
+		}
+		paramsString += "{'goodsname':'"+pay.SupplierTypeName+" "+typeString+"','num':'','price':'','hsbz':'1','taxrate':'0.06','spec':'','unit':'','spbm':'10101150101','zsbm':'','fphxz':'0','yhzcbs':'0','zzstsgl':'','lslbs':'','kce':'','taxfreeamt':" + fmt.Sprintf("%.2f", amount-a) + ",'tax':" + tax + ",'taxamt':" + strconv.Itoa(int(amount)) + "}"
+	}
 
 	// 身份认证,在诺诺网备案后,由诺诺网提供,每个企业一个
 	identity := "2329CC5F90EDAA8208F1F3C72A0CE72A713A9D425CD50CDE"
-	params := "{'identity':'" + identity + "','order':{'buyername':'浙江爱信1诺','taxnum':'124511234993295177','phone':'0','address':'浙江省杭州市万塘路','account':'','telephone':'0','orderno':'nuonuo367889','invoicedate':'2018-10-31 19:16:51','clerk':'黄芝','saleaccount':'宇宙行442612010103507108','salephone':'0774-7893911','saleaddress':'富川瑶族自治县新永路138号','saletaxnum':'339901999999142','kptype':'1','message':'','payee':'林莉苏','checker':'林莉苏','tsfs':'-1','email':'502192347@qq.com','qdbz':'0','qdxmmc':'','dkbz':'0','deptid':'','clerkid':'','invoiceLine':'p','cpybz':'','detail':[{'goodsname':'苹果','num':'1','price':'1','hsbz':'1','taxrate':'0.13','spec':'','unit':'吨','spbm':'10101150101','zsbm':'','fphxz':'0','yhzcbs':'0','zzstsgl':'','lslbs':'','kce':''}]}}"
+	//params := "{'identity':'" + identity + "','order':{'buyername':'" + entity.SupplierName + "','taxnum':'" + entity.CommercialNo + "','phone':'18354222656','address':'" + entity.Address + "','account':'" + entity.DepositBank + entity.BankAccount + "','telephone':'" + supplierEntity.Telphone + "','orderno':'123" + entity.BankSerialNum + "','invoicedate':'" + time.Now().Format("2006-01-02 15:04:05") + "','clerk':'曲岩','saleaccount':'中国工商银行股份有限公司天津市滨海支行 0302023009104728134','salephone':'022-25922501','saleaddress':'大港油田二号院','saletaxnum':'911200007182589087','kptype':'1','message':'','payee':'曲岩','checker':'曲岩','tsfs':'1','email':'" + entity.Email + "','qdbz':'0','qdxmmc':'','dkbz':'0','deptid':'','clerkid':'','invoiceLine':'p','cpybz':'','detail':[{'goodsname':'苹果','num':'1','price':'1','hsbz':'1','taxrate':'0.13','spec':'','unit':'吨','spbm':'10101150101','zsbm':'','fphxz':'0','yhzcbs':'0','zzstsgl':'','lslbs':'','kce':''}]}}"
+	params := "{'identity':'" + identity + "','order':{'buyername':'" + entity.SupplierName + "','taxnum':'" + entity.CommercialNo + "','phone':'" + supplierEntity.Mobile + "','address':'" + entity.Address + "','account':'" + entity.DepositBank + " " + entity.BankAccount + "','telephone':'" + supplierEntity.Telphone + "','orderno':'dg123" + entity.BankSerialNum + "','invoicedate':'" + time.Now().Format("2006-01-02 15:04:05") + "','clerk':'曲岩','saleaccount':'中国工商银行股份有限公司天津市滨海支行 0302023009104728134','salephone':'022-25922501','saleaddress':'大港油田二号院','saletaxnum':'339901999999142','kptype':'1','message':'','payee':'曲岩','checker':'曲岩','tsfs':'1','email':'" + entity.Email + "','qdbz':'0','qdxmmc':'','dkbz':'0','deptid':'','clerkid':'','invoiceLine':'p','cpybz':'','detail':["+paramsString+"]}}"
 	var errinfo ErrorInfo
 	invoiceJson := invoice.Post(url, params)
 	if invoiceJson.Status != "0000"{
 		//session.Rollback()
 		errinfo.Code = -1
-		errinfo.Message = "操作失败!" + invoiceJson.Fpqqlsh
+		errinfo.Message = "操作失败!" + invoiceJson.Message
 		this.Data["json"] = &errinfo
 		this.ServeJSON()
 	} else if invoiceJson.Status == "0000" && invoiceJson.Fpqqlsh != "" {
@@ -83,12 +120,20 @@ func (this *OilInvoiceController) UpdateIsInvoice() string {
 			this.ServeJSON()
 		} else if invoiceJson1.Result == "success" && len(invoiceJson1.InvoiceList) > 0{
 			results := invoiceJson1.InvoiceList[0]
-			cols := []string{"IsInvoice", "InvoiceOn", "Url"}
+			if results.Status != "2"{
+				errinfo.Code = -1
+				errinfo.Message = "操作失败!" + results.Resultmsg
+				this.Data["json"] = &errinfo
+				this.ServeJSON()
+				return ""
+			}
+			cols := []string{"IsInvoice", "InvoiceOn", "Url", "NuNuSerialNum"}
 			svc := invoiceinfo.GetOilInvoiceInfoSession(session)
 			var info invoiceinfo.OilInvoiceInfo
 			info.IsInvoice = "1"
 			info.InvoiceOn = time.Now()
 			info.Url = results.Url
+			info.NuNuSerialNum = invoiceJson.Fpqqlsh
 			_, err = svc.UpdateEntityByIdCols(id, &info, cols)