zhangqian
2024-07-29 985e3b7a74962d1aae5cba3451f3bff35daf5794
service/inventory_report_forms.go
@@ -87,7 +87,9 @@
      data.Cost = material.Cost
      data.Unit = material.Unit
      data.Value = material.Amount.Mul(material.Cost)
      data.ProductType = material.CategoryName
      data.ProductCategory = material.CategoryName
      data.ProductType = material.Type
      data.ProductSpecs = material.Specs
      for _, amount := range productAmounts {
         if material.ID == amount.ProductId {
            data.Amount = data.Amount.Add(amount.Amount)
@@ -129,29 +131,37 @@
   locationIds []int,
   err error) {
   productAmounts = make([]*models.LocationProductAmount, 0)
   if params.WarehouseCode != "" {
      locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
      if err != nil {
         return nil, nil, nil, nil, err
      }
   locationSearch := models.NewLocationSearch()
   //if params.WarehouseCode != "" {
   //   locationSearch.SetJointName(params.WarehouseCode)
   //}
   if params.WarehouseId > 0 {
      locationSearch.SetWarehouseId(params.WarehouseId)
   }
      for _, location := range locations {
         locationIds = append(locationIds, location.Id)
      }
      productAmounts, err = models.NewLocationProductAmountSearch().SetLocationIds(locationIds).SetQuery("amount > 0").Find()
      if err != nil {
         return nil, nil, nil, nil, err
      }
      for _, amount := range productAmounts {
         productIds = append(productIds, amount.ProductId)
      }
   locations, err := locationSearch.FindNotTotal()
   if err != nil {
      return nil, nil, nil, nil, err
   }
   for _, location := range locations {
      locationIds = append(locationIds, location.Id)
   }
   productAmounts, err = models.NewLocationProductAmountSearch().
      SetLocationIds(locationIds).SetQuery("amount > 0").
      Find()
   if err != nil {
      return nil, nil, nil, nil, err
   }
   for _, amount := range productAmounts {
      productIds = append(productIds, amount.ProductId)
   }
   //查询产品
   search = models.NewMaterialSearch()
   search.Orm = search.Orm.Model(&models.Material{}).
      Select(`material.id, material.name, material.cost, material.amount, material.unit, material.more_unit, material.more_unit_value, wms_product_category.name as category_name `).
      Joins("left join wms_product_category on material.category_id = wms_product_category.id")
   search.Orm = search.Orm.Model(&models.Material{}). // material
                        Select(`material.id, material.name, material.cost, material.amount, material.unit, material.more_unit, material.more_unit_value, wms_product_category.name as category_name `).
                        Joins("left join wms_product_category on material.category_id = wms_product_category.id")
   if len(params.CategoryIds) > 0 {
      search.Orm.Where("material.category_id in (?)", params.CategoryIds)
   }