From 5f7f65f00d4d1c280f8b09b73ef7dcfa2af0fd54 Mon Sep 17 00:00:00 2001
From: dsmzx <dsmzx@123.com>
Date: 星期三, 26 六月 2024 09:14:21 +0800
Subject: [PATCH] 出库/入库 打印
---
models/warehouse.go | 37 ++++---
controllers/operation.go | 208 ++++++++++++++++++++++++++++++++---------
models/file_template_attachment.go | 14 --
3 files changed, 183 insertions(+), 76 deletions(-)
diff --git a/controllers/operation.go b/controllers/operation.go
index cc7030d..2cc1671 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -9,6 +9,7 @@
"github.com/shopspring/decimal"
"github.com/xuri/excelize/v2"
"gorm.io/gorm"
+ "io/ioutil"
"sort"
"strconv"
"strings"
@@ -742,33 +743,32 @@
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
}
- fileTemplateAttachments, err := models.NewFileTemplateAttachmentSearch().SetWarehouseId(oT.WarehouseId).Find()
+ warehouse, err := models.NewWarehouseSearch().SetID(oT.WarehouseId).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
}
- for _, fileTemplateAttachment := range fileTemplateAttachments {
- if fileTemplateAttachment.Category == constvar.FileTemplateCategory_JialianInput1 {
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianInput1, operation)
- fileUrl, err = JialianOperation(fileTemplateAttachment.Category, operation)
- // 鍑哄簱
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianOutput1, operation)
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, err.Error())
- return
- }
- break
- } else if fileTemplateAttachment.Category == constvar.FileWarehouseCategory_JialianInput2 {
- fileUrl, err = JialianOperation(fileTemplateAttachment.Category, operation)
- // 鍑哄簱
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianOutput1, operation)
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, err.Error())
- return
- }
- break
- }
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
}
+
+ if warehouse.FileTemplateCategoryIn == constvar.FileTemplateCategory_JialianInput1 {
+ fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ } else if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
+ fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ }
+
} else if companyName == "geruimi" {
fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Selfmade, operation)
if err != nil {
@@ -783,34 +783,31 @@
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
}
- fileTemplateAttachments, err := models.NewFileTemplateAttachmentSearch().SetWarehouseId(oT.WarehouseId).Find()
+ warehouse, err := models.NewWarehouseSearch().SetID(oT.WarehouseId).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
}
- for _, fileTemplateAttachment := range fileTemplateAttachments {
- if fileTemplateAttachment.Category == constvar.FileTemplateCategory_JialianOutput1 {
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianInput1, operation)
- fileUrl, err = JialianOperation(fileTemplateAttachment.Category, operation)
- // 鍑哄簱
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianOutput1, operation)
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, err.Error())
- return
- }
- break
- } else if fileTemplateAttachment.Category == constvar.FileWarehouseCategory_JialianOutput2 {
- fileUrl, err = JialianOperation(fileTemplateAttachment.Category, operation)
- // 鍑哄簱
- //fileUrl, err = JialianOperation(constvar.FileTemplateCategory_JialianOutput1, operation)
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, err.Error())
- return
- }
- break
- }
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
}
+ if warehouse.FileTemplateCategoryOut == constvar.FileTemplateCategory_JialianOutput1 {
+ fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ } else if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
+ fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation)
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+
+ }
} else if companyName == "geruimi" {
fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Output, operation)
if err != nil {
@@ -829,7 +826,7 @@
util.ResponseFormat(c, code.Success, m)
}
-func JialianOperation(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
+func JialianOperation1(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
// 鑾峰彇妯℃澘璁板綍
template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
if err != nil {
@@ -854,9 +851,9 @@
defer f.Close()
sheet := "Sheet1"
- if category == constvar.FileTemplateCategory_JialianInput1 {
+ if category == constvar.FileWarehouseCategory_JialianInput2 {
sheet = "鍏ュ簱鍗�"
- } else if category == constvar.FileTemplateCategory_JialianOutput1 {
+ } else if category == constvar.FileWarehouseCategory_JialianOutput2 {
sheet = "鍑哄簱鍗�"
}
@@ -903,7 +900,7 @@
break
}
f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Name) // 浜у搧鍚嶇О
- f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Unit) //瑙勬牸
+ f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Specs) //瑙勬牸
f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["棰滆壊"], v.ProductId)]) //棰滆壊
f.SetCellValue(sheet, "E"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["闈㈡枡"], v.ProductId)]) //闈㈡枡
f.SetCellValue(sheet, "F"+strconv.Itoa(rowIndex), v.TotalGrossWeight.String()) //閲嶉噺
@@ -972,6 +969,7 @@
}
fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
+ ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
if err != nil {
//ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
logx.Errorf("file upload err: %v", err)
@@ -980,6 +978,120 @@
return fileUrl, nil
}
+func JialianOperation2(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
+ // 鑾峰彇妯℃澘璁板綍
+ template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
+ if err != nil {
+ return "", errors.New("鑾峰彇妯$増璁板綍澶辫触:" + err.Error())
+ }
+ fmt.Println(template)
+ // 鏍规嵁妯℃澘璺緞鑾峰彇妯℃澘娑堟伅
+ readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
+ if err != nil {
+ return "", errors.New("鑾峰彇妯$増澶辫触:" + err.Error())
+ }
+
+ // 璇诲彇妯℃澘鍐呭
+ f, err := excelize.OpenReader(readerCloser)
+ if err != nil {
+ return "", errors.New("璇诲彇excel妯$増澶辫触锛�" + err.Error())
+ }
+ readerCloser.Close()
+
+ defer f.Close()
+
+ sheet := "Sheet1"
+ f.SetCellValue(sheet, "A2", "鍗曚綅(閮ㄩ棬):"+operation.CompanyName) // 鍗曚綅閮ㄩ棬
+ f.SetCellValue(sheet, "H2", operation.OperationDate) // 鏃堕棿
+ f.SetCellValue(sheet, "O2", operation.Number) // 缂栧彿
+
+ totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
+ totalPrice := decimal.NewFromInt(0) // 鎬讳环
+ rowIndex := 5
+ for i, v := range operation.Details {
+ //璁剧疆琛ㄥ崟鏈�澶�9鏉℃暟鎹�
+ if i > 9 {
+ break
+ }
+ f.SetCellValue(sheet, "A"+strconv.Itoa(rowIndex), v.Product.Name) // 浜у搧鍚嶇О
+ f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Specs) //瑙勬牸
+ f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.TotalGrossWeight.String()) //閲嶉噺
+ f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), v.Amount.String()) //鏁伴噺
+ f.SetCellValue(sheet, "E"+strconv.Itoa(rowIndex), v.AuxiliaryAmount.String()) //杈呭姪鏁伴噺
+ f.SetCellValue(sheet, "F"+strconv.Itoa(rowIndex), v.AuxiliaryUnit) //杈呭姪鍗曚綅
+ f.SetCellValue(sheet, "G"+strconv.Itoa(rowIndex), v.Product.SalePrice.String()) // 鍗曚环
+
+ // 閲戦
+ if !v.Product.SalePrice.IsZero() {
+ ap := v.Amount.Mul(v.Product.SalePrice)
+ totalPrice = totalPrice.Add(ap)
+ price := ap.String()
+ split := strings.Split(price, ".")
+ if len(split) == 2 {
+ for n, a := range split[1] {
+ f.SetCellValue(sheet, string('O'+n)+strconv.Itoa(rowIndex), string(a))
+ }
+ }
+ s := split[0]
+ n := 0
+ for j := len(s) - 1; j >= 0; j-- {
+ if n == 6 {
+ f.SetCellValue(sheet, string('N'-n)+strconv.Itoa(rowIndex), s[:j])
+ break
+ }
+ f.SetCellValue(sheet, string('N'-n)+strconv.Itoa(rowIndex), string(s[j]))
+ n++
+ }
+ }
+ rowIndex++
+ totalAmount = totalAmount.Add(v.Amount)
+ }
+
+ //鍚堣
+ if !totalPrice.IsZero() {
+ price := totalPrice.String()
+ split := strings.Split(price, ".")
+ if len(split) == 2 {
+ for n, a := range split[1] {
+ f.SetCellValue(sheet, string('N'+n)+"14", string(a))
+ }
+ } else {
+ f.SetCellValue(sheet, "O14", "0")
+ f.SetCellValue(sheet, "P14", "0")
+ }
+ s := split[0]
+ n := 0
+ for j := len(s) - 1; j >= 0; j-- {
+ if n == 6 {
+ f.SetCellValue(sheet, string('N'-n)+"14", s[:j])
+ break
+ }
+ f.SetCellValue(sheet, string('N'-n)+"14", string(s[j]))
+ n++
+ }
+ }
+
+ f.SetCellValue(sheet, "Q5", operation.Remark) // 澶囨敞
+
+ // 绗�14琛�
+ f.SetCellValue(sheet, "B15", operation.Manager) // 涓荤
+ f.SetCellValue(sheet, "D15", operation.Accountant) // 浼氳
+ f.SetCellValue(sheet, "H15", operation.Custodian) //淇濈鍛�
+ f.SetCellValue(sheet, "Q15", operation.Custodian) //缁忔墜
+ buf, err := f.WriteToBuffer()
+ if err != nil {
+ return "", err
+ }
+
+ fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
+ ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
+ if err != nil {
+ logx.Errorf("file upload err: %v", err)
+ return "", err
+ }
+ return fileUrl, nil
+}
+
func ExportInputSelfmade(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
if err != nil {
diff --git a/models/file_template_attachment.go b/models/file_template_attachment.go
index 1b1a89f..a55c0db 100644
--- a/models/file_template_attachment.go
+++ b/models/file_template_attachment.go
@@ -10,10 +10,9 @@
type (
FileTemplateAttachment struct {
WmsModel
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Category constvar.FileTemplateCategory `json:"category" gorm:"type:int(11);comment:妯$増绉嶇被"`
- WarehouseId int `json:"warehouseId" gorm:"type:int(11);comment:浠撳簱id"`
- Name string `json:"name" gorm:"type:varchar(63);comment:妯$増鍚嶇О"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Category constvar.FileTemplateCategory `json:"category" gorm:"type:int(11);comment:妯$増绉嶇被"`
+ Name string `json:"name" gorm:"type:varchar(63);comment:妯$増鍚嶇О"`
//AttachmentId uint `json:"attachmentId" gorm:"comment:闄勪欢琛ㄥ閿�"`
//Attachment Attachment `json:"attachment" gorm:"foreignKey:AttachmentId;references:Id"`
TableInfo string `json:"tableInfo" gorm:"type:varchar(31);comment:琛ㄥ悕"`
@@ -52,10 +51,6 @@
slf.Order = order
return slf
}
-func (slf *FileTemplateAttachmentSearch) SetWarehouseId(warehouseId int) *FileTemplateAttachmentSearch {
- slf.WarehouseId = warehouseId
- return slf
-}
func (slf *FileTemplateAttachmentSearch) SetID(id int) *FileTemplateAttachmentSearch {
slf.Id = id
@@ -82,9 +77,6 @@
if slf.Id != 0 {
db = db.Where("id = ?", slf.Id)
- }
- if slf.WarehouseId != 0 {
- db = db.Where("warehouse_id = ?", slf.Id)
}
if slf.Order != "" {
db = db.Order(slf.Order)
diff --git a/models/warehouse.go b/models/warehouse.go
index df467d2..d6756af 100644
--- a/models/warehouse.go
+++ b/models/warehouse.go
@@ -4,6 +4,7 @@
"fmt"
"gorm.io/gorm"
"strings"
+ "wms/constvar"
"wms/pkg/mysqlx"
)
@@ -11,23 +12,25 @@
// Warehouse 浠撳簱
Warehouse struct {
WmsModel
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:浠撳簱鍚嶇О"` //浠撳簱鍚嶇О
- Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:鏄惁婵�娲�"` //鏄惁鍚敤锛屼紶true灏辫
- Code string `json:"code" gorm:"index;type:varchar(255);not null;comment:浠撳簱缂栫爜"` //浠撳簱缂栫爜
- PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:鍚堜綔浼欎即id"` //鍚堜綔浼欎即id
- BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:鏄惁璐拱琛ョ粰"` //鏄惁璐拱琛ョ粰锛屽凡璐拱浜у搧鑳藉鍙戦�佸埌姝や粨搴�
- ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:琛ョ粰鏉ユ簮浠撳簱ID"` //琛ョ粰鏉ユ簮浠撳簱ID
- ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱ID
- ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱
- CompanyId int `json:"companyId" gorm:"type:int;not null;comment:鍏徃id"`
- Company Company `json:"company" gorm:"foreignKey:CompanyId"`
- Address string `json:"address" gorm:"type:varchar(512);comment:鍦板潃"` //鍦板潃
- InboundTransportation int `json:"inboundTransportation" gorm:"type:int;comment:鍏ュ悜杩愯緭"` //鍏ュ悜杩愯緭
- OutboundTransportation int `json:"outboundTransportation" gorm:"type:int;comment:鍑哄簱杩愯緭"` //鍑哄簱杩愯緭
- LocationId int `json:"locationId" gorm:"type:int;comment:浣嶇疆id"` //榛樿浣嶇疆id
- WarehouseLocation string `json:"warehouseLocation" gorm:"-"` //搴撳瓨浣嶇疆
- Contacts string `json:"contacts" gorm:"type:varchar(255);comment:鑱旂郴浜�"` //鑱旂郴浜�
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:浠撳簱鍚嶇О"` //浠撳簱鍚嶇О
+ Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:鏄惁婵�娲�"` //鏄惁鍚敤锛屼紶true灏辫
+ Code string `json:"code" gorm:"index;type:varchar(255);not null;comment:浠撳簱缂栫爜"` //浠撳簱缂栫爜
+ PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:鍚堜綔浼欎即id"` //鍚堜綔浼欎即id
+ BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:鏄惁璐拱琛ョ粰"` //鏄惁璐拱琛ョ粰锛屽凡璐拱浜у搧鑳藉鍙戦�佸埌姝や粨搴�
+ ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:琛ョ粰鏉ユ簮浠撳簱ID"` //琛ョ粰鏉ユ簮浠撳簱ID
+ ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱ID
+ ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱
+ CompanyId int `json:"companyId" gorm:"type:int;not null;comment:鍏徃id"`
+ Company Company `json:"company" gorm:"foreignKey:CompanyId"`
+ Address string `json:"address" gorm:"type:varchar(512);comment:鍦板潃"` //鍦板潃
+ InboundTransportation int `json:"inboundTransportation" gorm:"type:int;comment:鍏ュ悜杩愯緭"` //鍏ュ悜杩愯緭
+ OutboundTransportation int `json:"outboundTransportation" gorm:"type:int;comment:鍑哄簱杩愯緭"` //鍑哄簱杩愯緭
+ LocationId int `json:"locationId" gorm:"type:int;comment:浣嶇疆id"` //榛樿浣嶇疆id
+ WarehouseLocation string `json:"warehouseLocation" gorm:"-"` //搴撳瓨浣嶇疆
+ Contacts string `json:"contacts" gorm:"type:varchar(255);comment:鑱旂郴浜�"` //鑱旂郴浜�
+ FileTemplateCategoryIn constvar.FileTemplateCategory `json:"fileTemplateCategoryIn" gorm:"type:int(11);comment:鍏ュ簱妯$増绉嶇被"`
+ FileTemplateCategoryOut constvar.FileTemplateCategory `json:"fileTemplateCategoryOut" gorm:"type:int(11);comment:鍑哄簱妯$増绉嶇被"`
}
WarehouseSearch struct {
--
Gitblit v1.8.0