from django.db import models
from cadastro.models import Empresa
from datetime import datetime

meses = [(1,"01"),(2,"02"),(3,"03"),(4,"04"),(5,"05"),(6,"06"),(7,"07"),(8,"08"),(9,"09"),(10,"11"),(12,"12"),]
anos = [(1,"2018"),(2,"2019"),(3,"2020"),(4,"2021"),(5,"2022"),]

class Fiscal(models.Model):
    empresa = models.ForeignKey(Empresa, on_delete=models.CASCADE)
    mes = models.IntegerField('Mês', choices=meses)
    ano = models.IntegerField('Ano', choices=anos)
    planilha = models.FileField(upload_to='uploads/%Y/%m', max_length=200)
    data_envio = models.DateTimeField(auto_now_add=True, editable=False,)

class Nota(models.Model):
    empresa = models.ForeignKey(Empresa, on_delete=models.CASCADE)
    numero_nota = models.PositiveIntegerField('Número_nota')
    dt_Escritur = models.DateField('Dt. Escrituração')
    serie = models.CharField('Série', max_length=3)
    cfop = models.CharField('CFOP', max_length=4)
    cnpj = models.CharField('CNPJ/CPF', max_length=14)
    uf = models.CharField('UF', max_length=2)
    especie = models.CharField('Espécie', max_length=5)
    desd = models.CharField('desd.', max_length=1)
    codigo_Produto = models.CharField('Cod. Produto', max_length=20)
    numero_Item = models.CharField('Num. Item', max_length=3)
    ncm = models.CharField('NCM', max_length=8)
    cst = models.CharField('CST', max_length=3)
    quantidade = models.DecimalField('Quantidade', max_digits=14, decimal_places=4)
    preco_un = models.DecimalField('Preco_un', max_digits=14, decimal_places=6)
    desconto = models.DecimalField('Vl. Desconto', max_digits=14, decimal_places=2)
    valor_liquido = models.DecimalField('Vl. Liquido', max_digits=14, decimal_places=2)
    despesas = models.DecimalField('Vl. Despesas', max_digits=14, decimal_places=2)
    codigo_ctb = models.CharField('Cod. CTB', max_length=5)
    frete = models.DecimalField('Vl. Frete', max_digits=14, decimal_places=2)
    seguro = models.DecimalField('Vl. Seguro', max_digits=14, decimal_places=2)
    numero_di = models.CharField('Num DI', max_length=10)
    data_di = models.DateField('Data_DI')
    di_simplificadora = models.CharField('DI Simplificadora', max_length=3)
    mov_fisica = models.CharField('Mov. Física', max_length=3)
    cst_pis = models.CharField('CST_PIS', max_length=2)
    cst_cofins = models.CharField('CST_COFINS', max_length=2)
    natureza_receita = models.CharField('Nat. Receita', max_length=3)
    cod_contr_social = models.CharField('Cod. Contr Social', max_length=1)
    ind_tipo_cred_soc = models.CharField('Ind. Tipo Cred.', max_length=1)
    codigo_bc_credito = models.CharField('Cod. BC Crédito', max_length=1)
    nat_frete = models.CharField('Nat. Frete', max_length=2)
    valor_receita = models.DecimalField('Vl. Receita', max_digits=14, decimal_places=2)
    valor_pis = models.DecimalField('Vl. Pis', max_digits=14, decimal_places=2)
    valor_cofins = models.DecimalField('Vl. Cofins', max_digits=14, decimal_places=2)
    valor_bc_pis_cofins = models.DecimalField('Vl. BC Pis_Cofins', max_digits=14, decimal_places=2)
    aliquota_pis = models.DecimalField('Alíquota Pis', max_digits=5, decimal_places=2)
    aliquota_cofins = models.DecimalField('Alíquota Cofins', max_digits=5, decimal_places=2)
    valor_bc_qtde = models.DecimalField(max_digits=14, decimal_places=2)
    aliq_pis_vlr = models.DecimalField(max_digits=5, decimal_places=2)
    aliq_cofins_vlr = models.DecimalField(max_digits=5, decimal_places=2)
    pis_pago = models.DecimalField(max_digits=14, decimal_places=2)
    cofins_pago = models.DecimalField(max_digits=14, decimal_places=2)
    drawback = models.CharField(max_length=3)
    bc_difal = models.DecimalField(max_digits=14, decimal_places=2)
    aliquota_fcp = models.DecimalField(max_digits=5, decimal_places=2)
    aliquota_interna_uf_destino = models.DecimalField(max_digits=5, decimal_places=2)
    aliquota_interestadual = models.DecimalField(max_digits=5, decimal_places=2)
    partilha_uf_destino_perc = models.DecimalField(max_digits=5, decimal_places=2)
    icms_fcp_uf_destino= models.DecimalField(max_digits=14, decimal_places=2)
    icms_uf_destino = models.DecimalField(max_digits=14, decimal_places=2)
    icms_uf_origem = models.DecimalField(max_digits=14, decimal_places=2)
    bc_icms = models.DecimalField(max_digits=14, decimal_places=2)
    aliquota_icms = models.DecimalField(max_digits=5, decimal_places=2)
    valor_icms = models.DecimalField(max_digits=14, decimal_places=2)
    isentas_icms = models.DecimalField(max_digits=14, decimal_places=2)
    outras_icms = models.DecimalField(max_digits=14, decimal_places=2)
    icms_desonerado = models.DecimalField(max_digits=14, decimal_places=2)
    bc_subst_tribut = models.DecimalField(max_digits=14, decimal_places=2)
    aliq_sub_trib = models.DecimalField(max_digits=5, decimal_places=2)
    icms_subst_tribut = models.DecimalField(max_digits=14, decimal_places=2)
    cest = models.CharField(max_length=8)
    cst_ipi = models.CharField(max_length=2)
    bc_ipi = models.DecimalField(max_digits=14, decimal_places=2)
    aliquota_ipi = models.DecimalField(max_digits=5, decimal_places=2)
    valor_ipi = models.DecimalField(max_digits=14, decimal_places=2)
    isentas_ipi = models.DecimalField(max_digits=14, decimal_places=2)
    outras_ipi = models.DecimalField(max_digits=14, decimal_places=2)
    ipi_nao_creditado = models.DecimalField(max_digits=14, decimal_places=2)
    ipi_creditado_50 = models.DecimalField(max_digits=14, decimal_places=2)

    def __str__(self):
        return str(self.empresa) + ' - ' + str(self.numero_nota)




