| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | |
| | | return err |
| | | } |
| | | if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First(); err != nil { |
| | | location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First() |
| | | if err != nil { |
| | | return err |
| | | } else { |
| | | params.FromLocationID = location.Id |
| | | } |
| | | if params.ToLocationID == 0 { |
| | | return errors.New("请选择目标位置") |
| | | for k, v := range params.Details { |
| | | params.Details[k].FromLocationID = location.Id |
| | | if v.ToLocationID == 0 { |
| | | params.Details[k].ToLocationID = params.LocationID |
| | | } |
| | | } |
| | | |
| | | } |
| | | if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First(); err != nil { |
| | | location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First() |
| | | if err != nil { |
| | | return err |
| | | } else { |
| | | params.ToLocationID = location.Id |
| | | } |
| | | if params.FromLocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | for k, v := range params.Details { |
| | | params.Details[k].ToLocationID = location.Id |
| | | if v.FromLocationID == 0 { |
| | | return errors.New("请选择出库位置") |
| | | } |
| | | } |
| | | |
| | | } |
| | | if operationType.BaseOperationType == constvar.BaseOperationTypeInternal { |
| | | if params.ToLocationID == 0 { |
| | | return errors.New("请选择目标位置") |
| | | for _, v := range params.Details { |
| | | if v.ToLocationID == 0 { |
| | | return errors.New("请选择目标位置") |
| | | } |
| | | if v.FromLocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | } |
| | | } |
| | | if params.FromLocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | } |
| | | |
| | | } |
| | | return nil |
| | | } |
| | |
| | | |
| | | if params.OperationDate == "" { |
| | | return errors.New("请选择安排日期") |
| | | } |
| | | |
| | | if params.LocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | } |
| | | |
| | | if len(params.Details) <= 0 { |
| | |
| | | util.ResponseFormat(c, code.RequestError, "该出入库信息无法完成") |
| | | return |
| | | } |
| | | err = models.WithTransaction(func(tx *gorm.DB) error { |
| | | |
| | | listDetails, err := models.NewOperationDetailsSearch().SetOperationId(operation.Id).SetPreload(true).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | var mapLocAmount map[string]*models.LocationProductAmount |
| | | locAmountList, err := models.NewLocationProductAmountSearch().Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | return |
| | | } |
| | | if len(locAmountList) > 0 { |
| | | mapLocAmount = make(map[string]*models.LocationProductAmount) |
| | | for _, v := range locAmountList { |
| | | mapLocAmount[strconv.Itoa(v.LocationId)+v.ProductId] = v |
| | | } |
| | | } |
| | | |
| | | err = models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish, AuditDate: time.Now().Format("2006-01-02 15:04:05")}); err != nil { |
| | | return err |
| | | } |
| | |
| | | return err |
| | | } |
| | | |
| | | var listProdtId []string |
| | | var listProdt []*models.Material |
| | | mapProdt := make(map[string]decimal.Decimal) |
| | | listDetails, err := models.NewOperationDetailsSearch().SetOperationId(operation.Id).FindAll() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, v := range listDetails { |
| | | listProdtId = append(listProdtId, v.ProductId) |
| | | mapProdt[v.ProductId] = v.Amount |
| | | } |
| | | |
| | | if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | if operation.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | var operationInputs []*models.Operation |
| | | for k, v := range listProdt { |
| | | value, ok := mapProdt[v.ID] |
| | | if !ok { |
| | | return errors.New("产品种类异常") |
| | | locationRoleList, err := models.NewLocationProductSearch().Find() |
| | | if err != nil { |
| | | return errors.New("获取上架规则信息失败") |
| | | } |
| | | var mapLocationRoleProduct, mapLocationRoleCategory map[string]*models.LocationProduct |
| | | if len(locationRoleList) > 0 { |
| | | mapLocationRoleProduct = make(map[string]*models.LocationProduct) |
| | | mapLocationRoleCategory = make(map[string]*models.LocationProduct) |
| | | for _, v := range locationRoleList { |
| | | if v.RuleType == constvar.RuleType_Product { |
| | | mapLocationRoleProduct[strconv.Itoa(v.AreaId)+v.ProductId] = v |
| | | } |
| | | if v.RuleType == constvar.RuleType_ProductCategory { |
| | | mapLocationRoleCategory[strconv.Itoa(v.AreaId)+strconv.Itoa(v.ProductCategoryID)] = v |
| | | } |
| | | } |
| | | } |
| | | |
| | | listProdt[k].Amount = listProdt[k].Amount.Add(value) |
| | | if err := tx.Save(listProdt[k]).Error; err != nil { |
| | | var details []*models.OperationDetails |
| | | for k, v := range listDetails { |
| | | listDetails[k].Product.Amount = listDetails[k].Product.Amount.Add(v.Amount) |
| | | if err := tx.Save(&listDetails[k].Product).Error; err != nil { |
| | | return err |
| | | } |
| | | |
| | | locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | |
| | | if err == nil { |
| | | operationTransfer := &models.Operation{ |
| | | Number: operation.Number, |
| | | SourceNumber: operation.SourceNumber, |
| | | OperationTypeId: 0, |
| | | OperationTypeName: operation.OperationTypeName, |
| | | Status: constvar.OperationStatus_Finish, |
| | | FromLocationID: locationRule.AreaId, |
| | | ToLocationID: locationRule.LocationId, |
| | | OperationDate: operation.OperationDate, |
| | | ContacterID: operation.ContacterID, |
| | | ContacterName: operation.ContacterName, |
| | | CompanyID: operation.CompanyID, |
| | | CompanyName: operation.CompanyName, |
| | | Comment: operation.Comment, |
| | | BaseOperationType: constvar.BaseOperationTypeInternal, |
| | | Details: []*models.OperationDetails{ |
| | | { |
| | | ProductId: v.ID, |
| | | Amount: value, |
| | | }, |
| | | }, |
| | | if roleProduct, ok := mapLocationRoleProduct[strconv.Itoa(operation.LocationID)+v.ProductId]; ok { |
| | | detail := &models.OperationDetails{ |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | FromLocationID: roleProduct.AreaId, |
| | | ToLocationID: roleProduct.LocationId, |
| | | } |
| | | operationInputs = append(operationInputs, operationTransfer) |
| | | details = append(details, detail) |
| | | |
| | | //if err := tx.Create(&operationTransfer).Error; err != nil { |
| | | // return err |
| | | //} |
| | | |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(locationRule.LocationId). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | locAmount.LocationId = locationRule.LocationId |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | locAmount.ProductCategoryID = v.CategoryId |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | if err == nil { |
| | | operationTransfer := &models.Operation{ |
| | | Number: operation.Number, |
| | | SourceNumber: operation.SourceNumber, |
| | | OperationTypeId: 0, |
| | | OperationTypeName: operation.OperationTypeName, |
| | | Status: constvar.OperationStatus_Finish, |
| | | FromLocationID: locationRule.AreaId, |
| | | ToLocationID: locationRule.LocationId, |
| | | OperationDate: operation.OperationDate, |
| | | ContacterID: operation.ContacterID, |
| | | ContacterName: operation.ContacterName, |
| | | CompanyID: operation.CompanyID, |
| | | CompanyName: operation.CompanyName, |
| | | Comment: operation.Comment, |
| | | BaseOperationType: constvar.BaseOperationTypeInternal, |
| | | Details: []*models.OperationDetails{ |
| | | { |
| | | ProductId: v.ID, |
| | | Amount: value, |
| | | }, |
| | | }, |
| | | } |
| | | operationInputs = append(operationInputs, operationTransfer) |
| | | |
| | | //if err := tx.Create(&operationTransfer).Error; err != nil { |
| | | // return err |
| | | //} |
| | | |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(locationRule.LocationId). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | locAmount.LocationId = locationRule.LocationId |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | locAmount.ProductCategoryID = v.CategoryId |
| | | if locAmount, aok := mapLocAmount[strconv.Itoa(roleProduct.LocationId)+v.ProductId]; aok { |
| | | locAmount.Amount = locAmount.Amount.Add(v.Amount) |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(operation.ToLocationID). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{ |
| | | LocationId: roleProduct.LocationId, |
| | | ProductCategoryID: v.Product.CategoryId, |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | CreateDate: time.Now().Format("2006-01-02 15:04:05"), |
| | | }); err != nil { |
| | | return err |
| | | } |
| | | locAmount.LocationId = operation.ToLocationID |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | locAmount.ProductCategoryID = v.CategoryId |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | if roleCategory, cok := mapLocationRoleCategory[strconv.Itoa(operation.LocationID)+strconv.Itoa(v.Product.CategoryId)]; cok { |
| | | detail := &models.OperationDetails{ |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | FromLocationID: roleCategory.AreaId, |
| | | ToLocationID: roleCategory.LocationId, |
| | | } |
| | | details = append(details, detail) |
| | | |
| | | if locAmount, aok := mapLocAmount[strconv.Itoa(roleCategory.LocationId)+v.ProductId]; aok { |
| | | locAmount.Amount = locAmount.Amount.Add(v.Amount) |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{ |
| | | LocationId: roleCategory.LocationId, |
| | | ProductCategoryID: v.Product.CategoryId, |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | CreateDate: time.Now().Format("2006-01-02 15:04:05"), |
| | | }); err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } else { |
| | | if locAmount, aok := mapLocAmount[strconv.Itoa(operation.LocationID)+v.ProductId]; aok { |
| | | locAmount.Amount = locAmount.Amount.Add(v.Amount) |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{ |
| | | LocationId: operation.LocationID, |
| | | ProductCategoryID: v.Product.CategoryId, |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | CreateDate: time.Now().Format("2006-01-02 15:04:05"), |
| | | }); err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if len(operationInputs) > 0 { |
| | | if err := tx.Create(&operationInputs).Error; err != nil { |
| | | if len(details) > 0 { |
| | | if err := tx.Create(&models.Operation{ |
| | | Number: operation.Number, |
| | | SourceNumber: operation.SourceNumber, |
| | | OperationTypeId: 0, |
| | | OperationTypeName: operation.OperationTypeName, |
| | | Status: constvar.OperationStatus_Finish, |
| | | OperationDate: operation.OperationDate, |
| | | ContacterID: operation.ContacterID, |
| | | ContacterName: operation.ContacterName, |
| | | CompanyID: operation.CompanyID, |
| | | CompanyName: operation.CompanyName, |
| | | Comment: operation.Comment, |
| | | BaseOperationType: constvar.BaseOperationTypeInternal, |
| | | Details: details, |
| | | }).Error; err != nil { |
| | | return err |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | for k, v := range listProdt { |
| | | value, ok := mapProdt[v.ID] |
| | | if !ok { |
| | | return errors.New("产品种类异常") |
| | | } |
| | | for k, v := range listDetails { |
| | | //todo 演示测试数据 |
| | | data, err := os.ReadFile("conf/input.json") |
| | | if err != nil { |
| | |
| | | return errors.New("格式转换失败") |
| | | } |
| | | if opa.OpaCheck(c, m, "operation") { |
| | | if v.Amount.LessThan(value) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Name, v.Amount.String(), value.String())) |
| | | if v.Product.Amount.LessThan(v.Amount) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Product.Name, v.Product.Amount.String(), v.Amount.String())) |
| | | } |
| | | } |
| | | listProdt[k].Amount = listProdt[k].Amount.Sub(value) |
| | | if err := tx.Save(listProdt[k]).Error; err != nil { |
| | | //todo ================end=============================== |
| | | if v.Product.Amount.LessThan(v.Amount) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Product.Name, v.Product.Amount.String(), v.Amount.String())) |
| | | } |
| | | listDetails[k].Product.Amount = listDetails[k].Product.Amount.Sub(v.Amount) |
| | | if err := tx.Save(&listDetails[k].Product).Error; err != nil { |
| | | return err |
| | | } |
| | | locAmount, res := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(operation.FromLocationID). |
| | | FirstRes() |
| | | if res.Error != nil { |
| | | if res.Error == gorm.ErrRecordNotFound { |
| | | return errors.New("当前仓库没有该产品,请先入库") |
| | | |
| | | if locAmount, aok := mapLocAmount[strconv.Itoa(v.FromLocationID)+v.ProductId]; aok { |
| | | if locAmount.Amount.LessThan(v.Amount) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Product.Name, locAmount.Amount.String(), v.Amount.String())) |
| | | } |
| | | return res.Error |
| | | } |
| | | if locAmount.Amount.LessThan(value) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Name, v.Amount.String(), value.String())) |
| | | } |
| | | locAmount.Amount = locAmount.Amount.Sub(value) |
| | | if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil { |
| | | return err |
| | | locAmount.Amount = locAmount.Amount.Sub(v.Amount) |
| | | if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil { |
| | | return err |
| | | } |
| | | } else { |
| | | return errors.New("当前仓库没有该产品,请先入库") |
| | | } |
| | | } |
| | | if operation.Source != "" { |
| | |
| | | } |
| | | |
| | | if operation.BaseOperationType == constvar.BaseOperationTypeInternal { |
| | | var operationInputs []*models.Operation |
| | | for _, v := range listProdt { |
| | | value, ok := mapProdt[v.ID] |
| | | if !ok { |
| | | return errors.New("产品种类异常") |
| | | } |
| | | //listProdt[k].Amount = listProdt[k].Amount.Add(value) |
| | | //if err := tx.Save(listProdt[k]).Error; err != nil { |
| | | // return err |
| | | //} |
| | | fromLocAmount, res := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(operation.FromLocationID). |
| | | FirstRes() |
| | | if res.Error != nil { |
| | | return err |
| | | } |
| | | if fromLocAmount.Amount.LessThan(value) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,调拨:%v,数量不够,无法完成调拨操作", v.Name, v.Amount.String(), value.String())) |
| | | } |
| | | fromLocAmount.Amount = fromLocAmount.Amount.Sub(value) |
| | | if err := models.NewLocationProductAmountSearch().SetID(fromLocAmount.Id).Update(fromLocAmount); err != nil { |
| | | return err |
| | | } |
| | | |
| | | locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | |
| | | if err == nil { |
| | | operationTransfer := &models.Operation{ |
| | | Number: operation.Number, |
| | | SourceNumber: operation.SourceNumber, |
| | | OperationTypeId: 0, |
| | | OperationTypeName: operation.OperationTypeName, |
| | | Status: constvar.OperationStatus_Finish, |
| | | FromLocationID: locationRule.AreaId, |
| | | ToLocationID: locationRule.LocationId, |
| | | OperationDate: operation.OperationDate, |
| | | ContacterID: operation.ContacterID, |
| | | ContacterName: operation.ContacterName, |
| | | CompanyID: operation.CompanyID, |
| | | CompanyName: operation.CompanyName, |
| | | Comment: operation.Comment, |
| | | BaseOperationType: constvar.BaseOperationTypeInternal, |
| | | Details: []*models.OperationDetails{ |
| | | { |
| | | ProductId: v.ID, |
| | | Amount: value, |
| | | }, |
| | | }, |
| | | for _, v := range listDetails { |
| | | if fromLocAmount, aok := mapLocAmount[strconv.Itoa(v.FromLocationID)+v.ProductId]; aok { |
| | | if fromLocAmount.Amount.LessThan(v.Amount) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Product.Name, fromLocAmount.Amount.String(), v.Amount.String())) |
| | | } |
| | | operationInputs = append(operationInputs, operationTransfer) |
| | | |
| | | //if err := tx.Create(&operationTransfer).Error; err != nil { |
| | | // return err |
| | | //} |
| | | |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(locationRule.LocationId). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | fromLocAmount.Amount = fromLocAmount.Amount.Sub(v.Amount) |
| | | if err := models.NewLocationProductAmountSearch().SetID(fromLocAmount.Id).Update(fromLocAmount); err != nil { |
| | | return err |
| | | } |
| | | locAmount.LocationId = locationRule.LocationId |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | locAmount.ProductCategoryID = v.CategoryId |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return errors.New("当前仓库没有该产品,请先入库") |
| | | } |
| | | |
| | | if toLocAmount, aok := mapLocAmount[strconv.Itoa(v.ToLocationID)+v.ProductId]; aok { |
| | | toLocAmount.Amount = toLocAmount.Amount.Add(v.Amount) |
| | | if err := models.NewLocationProductAmountSearch().SetID(toLocAmount.Id).Update(toLocAmount); err != nil { |
| | | return err |
| | | } |
| | | if err == nil { |
| | | operationTransfer := &models.Operation{ |
| | | Number: operation.Number, |
| | | SourceNumber: operation.SourceNumber, |
| | | OperationTypeId: 0, |
| | | OperationTypeName: operation.OperationTypeName, |
| | | Status: constvar.OperationStatus_Finish, |
| | | FromLocationID: locationRule.AreaId, |
| | | ToLocationID: locationRule.LocationId, |
| | | OperationDate: operation.OperationDate, |
| | | ContacterID: operation.ContacterID, |
| | | ContacterName: operation.ContacterName, |
| | | CompanyID: operation.CompanyID, |
| | | CompanyName: operation.CompanyName, |
| | | Comment: operation.Comment, |
| | | BaseOperationType: constvar.BaseOperationTypeInternal, |
| | | Details: []*models.OperationDetails{ |
| | | { |
| | | ProductId: v.ID, |
| | | Amount: value, |
| | | }, |
| | | }, |
| | | } |
| | | operationInputs = append(operationInputs, operationTransfer) |
| | | |
| | | //if err := tx.Create(&operationTransfer).Error; err != nil { |
| | | // return err |
| | | //} |
| | | |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(locationRule.LocationId). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | locAmount.LocationId = locationRule.LocationId |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | locAmount.ProductCategoryID = v.CategoryId |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | locAmount, err := models.NewLocationProductAmountSearch(). |
| | | SetProductId(v.ID). |
| | | SetLocationId(operation.ToLocationID). |
| | | First() |
| | | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| | | return err |
| | | } |
| | | locAmount.LocationId = operation.ToLocationID |
| | | locAmount.ProductId = v.ID |
| | | locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05") |
| | | locAmount.Amount = locAmount.Amount.Add(value) |
| | | if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil { |
| | | return res.Error |
| | | } |
| | | } else { |
| | | if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{ |
| | | LocationId: v.ToLocationID, |
| | | ProductCategoryID: v.Product.CategoryId, |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount, |
| | | CreateDate: time.Now().Format("2006-01-02 15:04:05"), |
| | | }); err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } |
| | | if len(operationInputs) > 0 { |
| | | if err := tx.Create(&operationInputs).Error; err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } |
| | |
| | | Amount: v.Amount, |
| | | Unit: v.Product.Unit, |
| | | Weight: operation.Weight, |
| | | FromLocationId: operation.FromLocationID, |
| | | FromLocation: operation.FromLocation.Name, |
| | | ToLocationId: operation.ToLocationID, |
| | | ToLocation: operation.ToLocation.Name, |
| | | FromLocationId: v.FromLocationID, |
| | | FromLocation: v.FromLocation.Name, |
| | | ToLocationId: v.ToLocationID, |
| | | ToLocation: v.ToLocation.Name, |
| | | } |
| | | histories = append(histories, history) |
| | | } |
| | |
| | | } |
| | | |
| | | func ExportInputSelfmade(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) { |
| | | template, err := models.NewFileTemplateAttachmentSearch().SetPreload(true).SetCategory(category).First() |
| | | template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First() |
| | | if err != nil { |
| | | return "", errors.New("获取模版记录失败:" + err.Error()) |
| | | } |
| | | readerCloser, err := http.HttpGetWithReadCloser(template.Attachment.FileUrl) |
| | | readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl) |
| | | if err != nil { |
| | | return "", errors.New("获取模版失败:" + err.Error()) |
| | | } |
| | |
| | | f.SetCellValue("Sheet1", "C"+strconv.Itoa(rowIndex), v.Product.Specs) |
| | | f.SetCellValue("Sheet1", "D"+strconv.Itoa(rowIndex), v.Product.Unit) |
| | | f.SetCellValue("Sheet1", "E"+strconv.Itoa(rowIndex), v.Amount.String()) |
| | | f.SetCellValue("Sheet1", "H"+strconv.Itoa(rowIndex), operation.ToLocation.Name) |
| | | f.SetCellValue("Sheet1", "H"+strconv.Itoa(rowIndex), v.ToLocation.Name) |
| | | f.SetCellValue("Sheet1", "I"+strconv.Itoa(rowIndex), operation.Comment) |
| | | rowIndex++ |
| | | totalAmount = totalAmount.Add(v.Amount) |
| | |
| | | } |
| | | |
| | | func ExportOutputOperation(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) { |
| | | repositoryLevels := strings.Split(operation.FromLocation.JointName, "/") |
| | | template, err := models.NewFileTemplateAttachmentSearch().SetPreload(true).SetCategory(category).First() |
| | | repositoryLevels := strings.Split(operation.Location.JointName, "/") |
| | | template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First() |
| | | if err != nil { |
| | | return "", errors.New("获取模版记录失败:" + err.Error()) |
| | | } |
| | | readerCloser, err := http.HttpGetWithReadCloser(template.Attachment.FileUrl) |
| | | readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl) |
| | | if err != nil { |
| | | return "", errors.New("获取模版失败:" + err.Error()) |
| | | } |
| | |
| | | return |
| | | } |
| | | |
| | | db := mysqlx.GetDB().Table("wms_operation").Select("wms_operation.id as operation_id,wms_operation.number,wms_operation.base_operation_type,material.id AS product_id,material.`name` AS product_name,wms_operation_details.amount,material.unit,wms_operation.from_location_id,from_location.`name` AS from_location,wms_operation.to_location_id,to_location.`name` AS to_location,wms_operation.operation_date as date,wms_operation.`status`").InnerJoins("inner join wms_operation_details ON wms_operation_details.operation_id = wms_operation.id").InnerJoins("INNER JOIN material ON material.id = wms_operation_details.product_id").InnerJoins("INNER JOIN wms_location AS from_location ON from_location.id = wms_operation.from_location_id").InnerJoins("INNER JOIN wms_location AS to_location ON to_location.id = wms_operation.to_location_id") |
| | | db := mysqlx.GetDB().Table("wms_operation"). |
| | | Select("wms_operation.id as operation_id,wms_operation.number,wms_operation.base_operation_type,material.id AS product_id,material.`name` AS product_name,wms_operation_details.amount,material.unit,wms_operation_details.from_location_id,from_location.`name` AS from_location,wms_operation_details.to_location_id,to_location.`name` AS to_location,wms_operation.operation_date as date,wms_operation.`status`"). |
| | | InnerJoins("inner join wms_operation_details ON wms_operation_details.operation_id = wms_operation.id"). |
| | | InnerJoins("INNER JOIN material ON material.id = wms_operation_details.product_id"). |
| | | InnerJoins("INNER JOIN wms_location AS from_location ON from_location.id = wms_operation_details.from_location_id"). |
| | | InnerJoins("INNER JOIN wms_location AS to_location ON to_location.id = wms_operation_details.to_location_id") |
| | | if params.Condition != "" { |
| | | db = db.Where("wms_operation.number like ? or wms_operation.source_number like ? or from_location.`name` like ? or to_location.`name` like ?", "%"+params.Condition+"%", "%"+params.Condition+"%", "%"+params.Condition+"%", "%"+params.Condition+"%") |
| | | db = db.Where("wms_operation.number like ? or wms_operation.source_number like ? or from_location.`name` like ? or to_location.`name` like ? or material.`name` like ? ", "%"+params.Condition+"%", "%"+params.Condition+"%", "%"+params.Condition+"%", "%"+params.Condition+"%", "%"+params.Condition+"%") |
| | | } |
| | | var ( |
| | | records = make([]*response.InventoryHistory, 0) |
| | |
| | | return |
| | | } |
| | | |
| | | if err := db.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize).Find(&records).Error; err != nil { |
| | | if err := db.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize).Order("wms_operation.created_at desc").Find(&records).Error; err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | | return |
| | | } |