from django.db import models class DepartmentFinancials(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") year = models.IntegerField(verbose_name="年份") annual_revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年度营业收入(万元)") annual_revenue_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="年度营业收入完成率") annual_new_revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年度新增收入(万元)") annual_new_revenue_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="年度新增收入完成率") annual_existing_revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年度存量收入(万元)") annual_existing_revenue_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="年度存量收入完成率") annual_operating_costs = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年度营业成本(万元)") annual_operating_costs_utilization_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="年度营业成本占用率") annual_expenses = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年度费用开销(万元)") annual_expenses_utilization_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="年度费用开销占用率") operating_profit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="营业利润(万元)") class Meta: verbose_name = "业务部门年度总体经营指标" verbose_name_plural = "业务部门年度总体经营指标" def __str__(self): return f"{self.primary_department} {self.year} 业务部门年度总体经营指标" def save(self, *args, **kwargs): # 添加业务逻辑或计算字段 super().save(*args, **kwargs) class DepartmentFinancialMonthly(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") year_month = models.CharField(max_length=7, verbose_name="年月") current_month_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="当月收入(万元)") monthly_income_target = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="月收入目标(万元)") monthly_target_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="月目标完成率") current_month_new_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="当月新增收入(万元)") monthly_new_income_target = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="月新增收入目标(万元)") monthly_new_income_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="月新增收入完成率") current_month_existing_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="当月存量收入(万元)") monthly_existing_income_target = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="月存量收入目标(万元)") monthly_existing_income_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="月存量收入完成率") annual_accumulated_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年累计收入(万元)") accumulated_target_completion_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="累计目标完成率") class Meta: verbose_name = "业务部门收入情况" verbose_name_plural = "业务部门收入情况" def __str__(self): return f"{self.year_month} - {self.primary_department}" def save(self, *args, **kwargs): # 在此可以添加特定的业务逻辑,例如验证收入目标完成率的计算等 super().save(*args, **kwargs) class DepartmentCosts(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") year_month = models.CharField(max_length=7, verbose_name="年月") current_month_cost = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="当月成本(万元)") monthly_cost_limit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="月成本限额(万元)") monthly_cost_utilization_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="月成本占用率") annual_accumulated_cost = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年累计成本(万元)") accumulated_cost_utilization_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="累计成本占用率") class Meta: verbose_name = "业务部门成本情况" verbose_name_plural = "业务部门成本情况" def __str__(self): return f"{self.year_month} - {self.primary_department} - 业务部门收入情况" def save(self, *args, **kwargs): # 在此可以添加特定的业务逻辑,例如自动计算成本占用率等 if not self.current_month_cost or not self.monthly_cost_limit: self.monthly_cost_utilization_rate = None else: self.monthly_cost_utilization_rate = (self.current_month_cost / self.monthly_cost_limit) * 100 if not self.annual_accumulated_cost or not self.monthly_cost_limit * 12: # 假设年成本限额是月限额的12倍 self.accumulated_cost_utilization_rate = None else: self.accumulated_cost_utilization_rate = (self.annual_accumulated_cost / ( self.monthly_cost_limit * 12)) * 100 super().save(*args, **kwargs) class DepartmentProfit(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") year_month = models.CharField(max_length=7, verbose_name="年月") operating_profit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="营业利润(万元)") annual_operating_profit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="年累计营业利润(万元)") class Meta: verbose_name = "业务部门利润情况" verbose_name_plural = "业务部门利润情况" def __str__(self): return f"{self.primary_department} {self.year_month} 业务部门利润情况" def save(self, *args, **kwargs): # 在此可以添加特定的业务逻辑,例如自动更新年累计营业利润等 super().save(*args, **kwargs) class Project(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") project_name = models.CharField(max_length=255, verbose_name="项目名称") project_type = models.CharField(max_length=255, verbose_name="项目类型") project_manager = models.CharField(max_length=255, verbose_name="负责人") project_status = models.CharField(max_length=255, verbose_name="项目状态") project_progress = models.CharField(max_length=255, verbose_name="项目进度") project_nature = models.CharField(max_length=255, verbose_name="项目性质") contract_date = models.DateField(verbose_name="签约时间", null=True, blank=True) target_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="标的金额(元)") contract_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="合同费率") revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="收入(元)") cost_rate = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="成本费率") cost = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="成本(元)") net_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="净收入(元)") transaction_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="成交金额(元)") total_tax_inclusive_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="价税合计金额(元)") payment_received = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="回款金额(元)") class Meta: verbose_name = "业务部门项目进度" verbose_name_plural = "业务部门项目进度" def __str__(self): return f"{self.project_name} - {self.project_status}" def save(self, *args, **kwargs): # 在此可以添加特定的业务逻辑,例如自动计算净收入等 super().save(*args, **kwargs) class DepartmentProjectSettlement(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") project_name = models.CharField(max_length=255, verbose_name="项目名称") revenue = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="营业收入(元)") operating_costs = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="营业成本(元)") taxes_and_surcharges = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="税金及附加(元)") operating_profit = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="营业利润(元)") company_retention = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="公司留存(元)") project_commission = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="项目提成(元)") project_provision_fund = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="项目公积金(元)") class Meta: verbose_name = "业务部门项目结算" verbose_name_plural = "业务部门项目结算" def __str__(self): return f"{self.primary_department} - {self.project_name}" def save(self, *args, **kwargs): # 在此可以添加特定的业务逻辑,例如自动计算营业利润等 if self.revenue and self.operating_costs and self.taxes_and_surcharges: self.operating_profit = self.revenue - self.operating_costs - self.taxes_and_surcharges super().save(*args, **kwargs) class ProjectPayment(models.Model): primary_department = models.CharField(max_length=255, verbose_name="一级部门") project_name = models.CharField(max_length=255, verbose_name="项目名称") project_type = models.CharField(max_length=255, verbose_name="项目类型") project_manager = models.CharField(max_length=255, verbose_name="负责人") total_tax_inclusive_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="价税合计金额(元)") payment_received = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="回款金额(元)") outstanding_payment_amount = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="待回款金额(元)") receivable_net_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="应收净收入(元)") actual_net_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="实收净收入(元)") outstanding_net_income = models.DecimalField(max_digits=15, decimal_places=2, verbose_name="待收净收入") class Meta: verbose_name = "项目回款情况" verbose_name_plural = "项目回款情况" def __str__(self): return f"{self.project_name} ({self.project_type}) - 负责人: {self.project_manager}" def save(self, *args, **kwargs): # 自动计算待回款金额和待收净收入 self.outstanding_payment_amount = self.total_tax_inclusive_amount - self.payment_received self.outstanding_net_income = self.receivable_net_income - self.actual_net_income super().save(*args, **kwargs) class RevenueStructure(models.Model): primary_department = models.CharField(max_length=255) year_month = models.CharField(max_length=7) project_type = models.CharField(max_length=255) total_tax_inclusive_amount = models.DecimalField(max_digits=15, decimal_places=2) percentage = models.DecimalField(max_digits=5, decimal_places=2) cumulative_tax_inclusive_amount = models.DecimalField(max_digits=15, decimal_places=2) cumulative_percentage = models.DecimalField(max_digits=5, decimal_places=2) class Meta: verbose_name = '业务部门收入结构' verbose_name_plural = verbose_name def __str__(self): return f"{self.primary_department} - {self.year_month}" class ProfitStructure(models.Model): primary_department = models.CharField(max_length=255) year_month = models.CharField(max_length=7) project_type = models.CharField(max_length=255) net_receivable_income = models.DecimalField(max_digits=15, decimal_places=2) percentage = models.DecimalField(max_digits=5, decimal_places=2) cumulative_net_receivable_income = models.DecimalField(max_digits=15, decimal_places=2) cumulative_percentage = models.DecimalField(max_digits=5, decimal_places=2) class Meta: verbose_name = '业务部门利润结构' verbose_name_plural = verbose_name def __str__(self): return f"{self.primary_department} - {self.year_month}" class ProjectManagerIncome(models.Model): primary_department = models.CharField(max_length=255) name = models.CharField(max_length=255) year_month = models.CharField(max_length=7) current_month_income = models.DecimalField(max_digits=15, decimal_places=2) monthly_income_target = models.DecimalField(max_digits=15, decimal_places=2) monthly_target_completion_rate = models.DecimalField(max_digits=5, decimal_places=2) annual_accumulated_income = models.DecimalField(max_digits=15, decimal_places=2) annual_target_completion_rate = models.DecimalField(max_digits=5, decimal_places=2) current_month_commission = models.DecimalField(max_digits=15, decimal_places=2) current_month_accrued_commission = models.DecimalField(max_digits=15, decimal_places=2) annual_accumulated_commission = models.DecimalField(max_digits=15, decimal_places=2) annual_accumulated_accrued_commission = models.DecimalField(max_digits=15, decimal_places=2) class Meta: verbose_name = '业务部门项目经理收入完成及提成情况' verbose_name_plural = verbose_name def __str__(self): return f"{self.primary_department} - {self.name} - {self.year_month}" class AttendanceRecord(models.Model): primary_department = models.CharField(max_length=255) year_month = models.CharField(max_length=7) late = models.IntegerField() early_departure = models.IntegerField() absenteeism = models.IntegerField() annual_leave = models.IntegerField() personal_leave = models.IntegerField() sick_leave = models.IntegerField() other_leave = models.IntegerField() total_days = models.IntegerField() class Meta: verbose_name = '业务部门出勤情况' verbose_name_plural = verbose_name def __str__(self): return f"{self.primary_department} - {self.year_month}"