Parcourir la source

营业额、成本支出、毛利润 同比 代码编写

amigotrip il y a 9 mois
Parent
commit
38e4b6411c

+ 60 - 25
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -3268,6 +3268,7 @@ Where dfp.IsDel = 0 And dfp.IsPay = 1
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> StatisticsYOY(YOYDto _dto)
         {
+            //同比增长率 = (本期 - 同期) / 同期 * 100%;
             if (_dto.Year < 1) return Ok(JsonView(false,"操作失败"));
 
 
@@ -3423,37 +3424,37 @@ SELECT
   (
     SELECT
       CAST(
-        SUM(
-          ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
-        ) AS DECIMAL(12, 2)
+        SUM((gec.PriceSum * gec.Coefficient * ccp.DayRate)) AS DECIMAL(12, 2)
       )
     FROM
-      Grp_HotelReservations hr
-      INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
+      OA2023DB.dbo.Fin_GroupExtraCost gec
+      INNER JOIN Grp_CreditCardPayment ccp ON gec.Id = ccp.CId
     WHERE
-      hr.IsDel = 0
-      AND ccp.IsDel = 0
-      AND ccp.CTable = 76
+      ccp.IsDel = 0
+      AND ccp.CTable = 1015
       AND ccp.IsAuditGM = 1
-      AND ccp.PayMoney <> 0
-      AND ccp.IsPay = 0
-      AND di.Id = hr.DiId
-  ) AS HotelAmount,
+      AND ccp.IsPay = 1
+      AND di.Id = gec.DiId
+  ) AS ExcessAmount,
   (
     SELECT
       CAST(
-        SUM((gec.PriceSum * gec.Coefficient * ccp.DayRate)) AS DECIMAL(12, 2)
+        SUM(
+          ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
+        ) AS DECIMAL(12, 2)
       )
     FROM
-      OA2023DB.dbo.Fin_GroupExtraCost gec
-      INNER JOIN Grp_CreditCardPayment ccp ON gec.Id = ccp.CId
+      Fin_PaymentRefundAndOtherMoney prom
+      INNER JOIN Grp_CreditCardPayment ccp ON prom.DiId = ccp.DIId
+      AND prom.Id = ccp.CId
     WHERE
-      ccp.IsDel = 0
-      AND ccp.CTable = 1015
+      prom.IsDel = 0
+      AND prom.PayType = 1
+      AND ccp.CTable = 285
       AND ccp.IsAuditGM = 1
       AND ccp.IsPay = 1
-      AND di.Id = gec.DiId
-  ) AS ExcessAmount
+      AND di.Id = prom.DiId
+  ) AS SKTHAmount
 FROM
   Grp_DelegationInfo di
 WHERE
@@ -3462,29 +3463,63 @@ WHERE
   AND di.VisitDate BETWEEN '{0}' AND '{1}'
 ORDER BY
   di.VisitDate
-",beginDt,endDt);
+", beginDt,endDt);
 
             var data = await _sqlSugar.SqlQueryable<StatisticsYOYView>(sql).ToListAsync();
 
             var thisYearData = data.Where(x => x.Year == _dto.Year).ToList();
             var lastYearData = data.Where(x => x.Year == (_dto.Year - 1)).ToList();
 
-            List<YOYReturnView> SalesYOYData = new List<YOYReturnView>();
+            List<YOYReturnView> salesYOYData = new List<YOYReturnView>();
+            List<YOYReturnView> costYOYData = new List<YOYReturnView>();
+            List<YOYReturnView> grossProfitYOYData = new List<YOYReturnView>();
             int monthIndex = 1;
             while (monthIndex < 13)
             {
-
-
-
+                var thisMonthData = thisYearData.Where(x => x.Month == monthIndex).ToList();
+                var lastMonthData = lastYearData.Where(x => x.Month == monthIndex).ToList();
+                var thisGroupIds = thisMonthData.Select(x => x.Id).ToList();
+                var lastGroupIds = lastMonthData.Select(x => x.Id).ToList();
+
+                decimal thisSalesAmount = thisMonthData.Sum(x => x.SaleAmount),
+                        lastSalesAmount = lastYearData.Sum(x => x.SaleAmount),
+                        thisCostAmount = thisMonthData.Sum(x => x.CostAmount),
+                        lastCostAmount = lastYearData.Sum(x => x.CostAmount),
+                        thisgrossProfitAmount = thisMonthData.Sum(x => x.GrossProfitAmount),
+                        lastgrossProfitAmount = lastYearData.Sum(x => x.GrossProfitAmount);
+
+                salesYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisSalesAmount, lastSalesAmount, thisGroupIds, lastGroupIds));
+                costYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisCostAmount, lastCostAmount, thisGroupIds, lastGroupIds));
+                grossProfitYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisgrossProfitAmount, lastgrossProfitAmount, thisGroupIds, lastGroupIds));
 
                 monthIndex++;
             }
+            salesYOYData = salesYOYData.OrderBy(x => x.Month).ToList();
+            costYOYData = costYOYData.OrderBy(x => x.Month).ToList();
+            grossProfitYOYData = grossProfitYOYData.OrderBy(x => x.Month).ToList();
 
 
+            return Ok(JsonView(true,"操作成功!", new { salesYOYData = salesYOYData, costYOYData = costYOYData, grossProfitYOYData = grossProfitYOYData }));
+        }
 
-            return Ok(JsonView(true,"操作成功!", new { data = data, SalesData = new { },CostData = new { } }));
+        /// <summary>
+        /// 同比计算
+        /// </summary>
+        /// <param name="currentAmount">本期金额</param>
+        /// <param name="contemporaneousAmount">同期金额</param>
+        /// <returns>同期增长/下降率</returns>
+        private static decimal CalculateYOY(decimal currentAmount, decimal contemporaneousAmount)
+        {
+            decimal rate = 0.00M;
+            if (contemporaneousAmount != 0)
+            {
+                rate = (currentAmount - contemporaneousAmount) / contemporaneousAmount;
+            }
+
+            return rate;
         }
 
+
         #endregion
     }
 }

+ 9 - 3
OASystem/OASystem.Domain/ViewModels/Financial/Fin_DailyFeePaymentView.cs

@@ -658,6 +658,11 @@ namespace OASystem.Domain.ViewModels.Financial
         /// </summary>
         public decimal ExcessAmount { get; set; }
 
+        /// <summary>
+        /// 收款退还金额
+        /// </summary>
+        public decimal SKTHAmount { get; set; }
+
         /// <summary>
         /// 成本金额
         /// </summary>
@@ -669,16 +674,17 @@ namespace OASystem.Domain.ViewModels.Financial
             }
         }
 
+        /// <summary>
+        /// 毛利润
+        /// </summary>
         public decimal GrossProfitAmount
         {
             get
             {
-                return SaleAmount - CostAmount;
+                return SaleAmount - SKTHAmount - CostAmount;
             }
         }
 
-        public List<int> ThisIds { get; set; }
-        public List<int> LastIds { get; set; }
     }
     public class YOYReturnView
     {