from django.db import models
from apps.system.models import CommonBModel,CommonAModel,Dict
from simple_history.models import HistoricalRecords
from django.contrib.postgres.fields import ArrayField
from apps.project.models import CertApp
from apps.crm.models import Enterprise
import uuid
# Create your models here.
class Bill(CommonBModel):
     """
     收费单表
     """
     feecode = models.CharField('收费单号',unique=True, max_length=300)
     number = models.ForeignKey(CertApp, related_name='bill_number', on_delete=models.DO_NOTHING)
     feecharacter = models.ForeignKey(Dict, verbose_name='费用性质', related_name='bill_feecharacter', on_delete=models.DO_NOTHING)
     totalfee = models.FloatField('总金额',null=True, blank=True, default=0) 
     deductions = models.FloatField('扣减额',null=True, blank=True, default=0)
     exchangetype = models.CharField('外汇类型', max_length=300)
     exchangerate = models.FloatField('外币汇率',null=True, blank=True, default=0)
     paidrmb = models.FloatField('实收人名币',null=True, blank=True, default=0)
     paidwb = models.FloatField('实收外币',null=True, blank=True, default=0)
     remark = models.CharField('备注', max_length=300)
     class Meta:
        verbose_name = '收费信息'
        verbose_name_plural = verbose_name
     def __str__(self):
        return self.feecode

class Chargeitem(CommonBModel):
     """
        收费项目
     """
     bills = models.ForeignKey(Bill, related_name='chargeitem_bill',to_field='feecode',null=True, blank=True, on_delete=models.DO_NOTHING)
     itemkind = models.CharField('收费项目',null=True, blank=True, max_length=300)
     unitcount = models.FloatField('单元数量',null=True, blank=True, default=0) 
     perfee = models.FloatField('单价',null=True, blank=True, default=0)
     pertotal = models.FloatField('小计',null=True, blank=True, default=0)
     remark = models.CharField('备注',null=True, blank=True, max_length=300)
     class Meta:
        verbose_name = '收费项目'
        verbose_name_plural = verbose_name
     def __str__(self):
        return self.itemkind