瀏覽代碼

项目月费用

xu 7 月之前
父節點
當前提交
ed3926e76c

+ 10 - 0
server/api/v1/admin/project.go

@@ -235,6 +235,16 @@ func (pa *ProjectApi) QueryReimbursement(c *gin.Context) {
 	response.OkWithData(reimbursement, c)
 }
 
+func (pa *ProjectApi) QueryProjectSum(c *gin.Context) {
+	sum, err := projectService.QueryProjectSum()
+	if err != nil {
+		response.FailWithMessage("失败", c)
+		global.GVA_LOG.Error("QueryProjectSum ====== " + err.Error())
+		return
+	}
+	response.OkWithData(sum, c)
+}
+
 func (pa *ProjectApi) CreateProject(c *gin.Context) {
 	form, err := c.MultipartForm()
 	files := form.File["file"]

+ 4 - 0
server/dao/monthExpenses.go

@@ -0,0 +1,4 @@
+package dao
+
+type MonthExpenses struct {
+}

+ 28 - 0
server/dao/project.go

@@ -1,6 +1,7 @@
 package dao
 
 import (
+	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 	"server/global"
 )
@@ -32,6 +33,8 @@ type Project struct {
 	CollectionTotal      int64                 `json:"collectionTotal" form:"collectionTotal" gorm:"-"`
 	Reimbursement        []Reimbursement       `json:"reimbursement" form:"reimbursement" gorm:"-"`
 	ReimbursementTotal   int64                 `json:"reimbursementTotal" form:"reimbursementTotal" gorm:"-"`
+	ProjectFee           []ProjectFee          `json:"projectFee" form:"project" gorm:"-"`
+	ProjectFeeTotal      int64                 `json:"projectFeeTotal" form:"projectFeeTotal" gorm:"-"`
 }
 
 func (Project) TableName() string {
@@ -103,6 +106,31 @@ func (p Project) CreateProject() error {
 	})
 }
 
+type ProjectSum struct {
+	TotalProjectAmount    float64
+	TotalCollectionAmount float64
+	Receivables           float64
+}
+
+// QueryProjectSum 查询项目总
+func QueryProjectSum() (projectSum ProjectSum, err error) {
+	err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
+		txErr := tx.Model(&Project{}).Select("SUM(project_price) AS total_project_amount").First(&projectSum).Error
+		if txErr != nil {
+			return txErr
+		}
+		txErr = tx.Model(&Collection{}).Select("SUM(collection_price) AS total_collection_amount").First(&projectSum).Error
+		if txErr != nil {
+			return txErr
+		}
+		return txErr
+	})
+	// 使用decimal 防止精度不准
+	exponent := decimal.NewFromFloatWithExponent(projectSum.TotalProjectAmount-projectSum.TotalCollectionAmount, 2)
+	projectSum.Receivables = exponent.InexactFloat64()
+	return
+}
+
 // TODO:项目修改
 
 // UpdateProject 修改项目

+ 3 - 3
server/dao/projectMonthFee.go

@@ -19,12 +19,12 @@ func (ProjectMonthFee) TableName() string {
 }
 
 func QueryProjectMonthFee(monthTime, yearTime string) (monthFees []ProjectMonthFee, err error) {
-	db := global.GVA_DB.Model(&ProjectMonthFee{}).Select("genre, SUM(total_deposit) AS total_deposit, SUM(total_expenditure) AS total_expenditure")
+	db := global.GVA_DB.Model(&ProjectMonthFee{}).Debug().Select("genre, SUM(total_deposit) AS total_deposit, SUM(total_expenditure) AS total_expenditure")
 	if monthTime != "" {
-		db = db.Where("DATE_FORMAT(settlement_month, '%Y-%m') = ?", monthTime)
+		db = db.Where("DATE_FORMAT(CONCAT(settlement_month, '-01'), '%Y-%m') = ?", monthTime)
 	}
 	if yearTime != "" {
-		db = db.Where("DATE_FORMAT(settlement_month, '%Y') = ?", yearTime)
+		db = db.Where("DATE_FORMAT(CONCAT(settlement_month, '-01'), '%Y') = ?", yearTime)
 	}
 	err = db.Group("genre").Preload("ProjectFeeGenre").Find(&monthFees).Error
 	return monthFees, err

+ 1 - 0
server/router/admin/project.go

@@ -49,5 +49,6 @@ func (s *ProjectRouter) InitProjectRouter(Router *gin.RouterGroup) {
 		projectRouterWithoutRecord.GET("queryReimbursement", projectApi.QueryReimbursement)
 		projectRouterWithoutRecord.POST("projectFilesDownload", projectApi.ProjectFilesDownload)
 		projectRouterWithoutRecord.GET("queryProjectState", projectApi.QueryProjectState)
+		projectRouterWithoutRecord.GET("queryProjectSum", projectApi.QueryProjectSum)
 	}
 }

+ 7 - 0
server/service/admin/finance.go

@@ -86,12 +86,19 @@ func (fs *FinanceService) QueryProjectFinance(code string) (dao.Project, error)
 		return dao.Project{}, err
 	}
 
+	fee, feeTotal, err := dao.QueryProjectFeeList(8, 0, 0, 0, code, "", "", "")
+	if err != nil {
+		return dao.Project{}, err
+	}
+
 	project.Collection = collection
 	project.Reimbursement = reimbursements
 	project.WorkingHours = workingHours
 	project.ReimbursementTotal = reimbursementTotal
 	project.CollectionTotal = collectionTotal
 	project.WorkingHoursTotal = workingHoursTotal
+	project.ProjectFee = fee
+	project.ProjectFeeTotal = feeTotal
 
 	return project, err
 }

+ 4 - 0
server/service/admin/project.go

@@ -130,6 +130,10 @@ func (ps *ProjectService) QueryReimbursement(code string) ([]dao.Reimbursement,
 	return reimbursements, err
 }
 
+func (ps *ProjectService) QueryProjectSum() (dao.ProjectSum, error) {
+	return dao.QueryProjectSum()
+}
+
 func (ps *ProjectService) CreateProject(project dao.Project) error {
 	return project.CreateProject()
 }

+ 128 - 71
web/src/view/dashboard/index.vue

@@ -1,33 +1,79 @@
 <template>
   <div class="page">
     <div class="gva-card-box">
-      <div class="gva-card gva-top-card">
-        <div class="gva-top-card-left">
-          <div class="gva-top-card-left-title">早安,管理员,请开始一天的工作吧</div>
-          <div class="gva-top-card-left-dot">{{ weatherInfo }}</div>
-        </div>
-        <img
-          src="@/assets/dashboard.png"
-          class="gva-top-card-right"
-          alt
-        >
-      </div>
+      <div
+        id="main"
+        class="gva-card"
+        style="width: 100%; height: 300px;"
+        @click="handleChartClick"
+      />
     </div>
 
     <div class="gva-card-box">
       <div class="gva-card">
-        <div class="gva-card-title">数据统计</div>
+        <div class="gva-card-title">
+          <el-row :gutter="10">
+            <el-col
+              :xs="24"
+              :sm="2"
+            >
+              <span>数据统计</span>
+            </el-col>
+            <el-col
+              :xs="24"
+              :sm="4"
+            >
+              <el-date-picker
+                v-model="monthData"
+                type="month"
+                placeholder="选择月份"
+                value-format="YYYY-MM"
+                @change="choiceMonth"
+              />
+            </el-col>
+            <el-col
+              :xs="24"
+              :sm="8"
+            >
+              <el-date-picker
+                v-model="yearData"
+                type="year"
+                placeholder="选择年份"
+                value-format="YYYY"
+                @change="choiceYear"
+              />
+            </el-col>
+            <el-col
+              :xs="24"
+              :sm="6"
+            />
+          </el-row>
+        </div>
         <div class="p-4">
           <el-row :gutter="10">
             <el-col
               :xs="24"
-              :sm="13"
+              :sm="12"
             >
-              <echarts-line />
+              <el-table :data="projectMonthFee">
+                <el-table-column
+                  prop="projectFeeGenre.name"
+                  label="费用类型"
+                  width="200"
+                />
+                <el-table-column
+                  prop="totalExpenditure"
+                  label="支出金额"
+                />
+                <el-table-column
+                  prop="totalDeposit"
+                  label="支入金额"
+                />
+              </el-table>
             </el-col>
             <el-col
               :xs="24"
-              :sm="11"
+              :sm="12"
             >
               <dashboard-table />
             </el-col>
@@ -39,70 +85,81 @@
 </template>
 
 <script setup>
-import EchartsLine from '@/view/dashboard/dashboardCharts/echartsLine.vue'
 import DashboardTable from '@/view/dashboard/dashboardTable/dashboardTable.vue'
-import { ref } from 'vue'
-import { useRouter } from 'vue-router'
-import { useWeatherInfo } from '@/view/dashboard/weather.js'
-import SelectImage from '@/components/selectImage/selectImage.vue'
+import { ref, onMounted } from 'vue'
+import { queryProjectSum } from '@/api/project'
+import * as echarts from 'echarts'
+import { queryProjectMonthFee } from '@/api/cost'
 
-defineOptions({
-  name: 'Dashboard'
-})
+const initChart = () => {
+  const chartDom = document.getElementById('main')
+  const myChart = echarts.init(chartDom)
+  myChart.setOption({
+    title: {
+      text: '项目总表'
+    },
+    xAxis: {
+      type: 'value'
+    },
+    yAxis: {
+      type: 'category',
+      data: ['项目总营业额', '项目已收款', '项目应收款']
+    },
+    tooltip: {
+      trigger: 'axis',
+      axisPointer: {
+        type: 'shadow'
+      }
+    },
+    series: [
+      {
+        data: xData.value,
+        type: 'bar'
+      }
+    ]
+  })
+}
 
-const weatherInfo = useWeatherInfo()
+// 筛选数据
+const monthData = ref('')
+const yearData = ref('')
 
-const toolCards = ref([
-  {
-    label: '用户管理',
-    icon: 'monitor',
-    name: 'user',
-    color: '#ff9c6e',
-    bg: 'rgba(255, 156, 110,.3)'
-  },
-  {
-    label: '角色管理',
-    icon: 'setting',
-    name: 'authority',
-    color: '#69c0ff',
-    bg: 'rgba(105, 192, 255,.3)'
-  },
-  {
-    label: '菜单管理',
-    icon: 'menu',
-    name: 'menu',
-    color: '#b37feb',
-    bg: 'rgba(179, 127, 235,.3)'
-  },
-  {
-    label: '代码生成器',
-    icon: 'cpu',
-    name: 'autoCode',
-    color: '#ffd666',
-    bg: 'rgba(255, 214, 102,.3)'
-  },
-  {
-    label: '表单生成器',
-    icon: 'document-checked',
-    name: 'formCreate',
-    color: '#ff85c0',
-    bg: 'rgba(255, 133, 192,.3)'
-  },
-  {
-    label: '关于我们',
-    icon: 'user',
-    name: 'about',
-    color: '#5cdbd3',
-    bg: 'rgba(92, 219, 211,.3)'
-  }
-])
+const projectSum = ref()
+const projectMonthFee = ref()
 
-const router = useRouter()
+const xData = ref([])
+const queryData = async() => {
+  await queryProjectSum().then(res => {
+    projectSum.value = res.data
+    for (const key in projectSum.value) {
+      xData.value.push(projectSum.value[key])
+    }
+  })
+  await queryProjectMonthFee(monthData.value, yearData.value).then(res => {
+    console.log(res.data)
+    projectMonthFee.value = res.data
+  })
+  initChart()
+}
 
-const toTarget = (name) => {
-  router.push({ name })
+const handleChartClick = () => {
+  console.log('详情')
 }
 
+// 项目费用
+const choiceYear = () => {
+  monthData.value = ''
+  queryData()
+}
+const choiceMonth = () => {
+  yearData.value = ''
+  queryData()
+}
+onMounted(() => {
+  queryData()
+  initChart()
+})
+
 </script>
 
 <style lang="scss" scoped>