# -*- coding: utf-8 -*-
import datetime
import calendar
from django.db import models
from coin.offers.models import Offer 

class Invoice(models.Model):

    INVOICES_STATUS_CHOICES = (
        ('open', 'A payer'),
        ('closed', 'Reglée'),
        ('trouble', 'Litige')
    )

    status = models.CharField(max_length=50, choices=INVOICES_STATUS_CHOICES,
                              default='open')
    amount = models.DecimalField(max_digits=5, decimal_places=2)
    date = models.DateField(default=datetime.date.today, null=True)
    period_from = models.DateField(
        default=datetime.date(datetime.date.today().year,
                datetime.date.today().month, 1),
        null=True)
    period_to = models.DateField(
        default=datetime.date(datetime.date.today().year,
                datetime.date.today().month + 1, 1) - datetime.timedelta (days = 1),
        null=True)
    date_due = models.DateField(
        default=datetime.date(datetime.date.today().year,
                    datetime.date.today().month + 1, 1) - datetime.timedelta (days = 1),
        null=True)
    offer = models.ForeignKey(Offer)


class InvoiceDetail(models.Model):

    label = models.CharField(max_length=100)
    amount = models.DecimalField(max_digits=5, decimal_places=2)
    quantity = models.IntegerField(null=True)
    tax = models.IntegerField(null=True)
    invoice = models.ForeignKey(Invoice)

    def __unicode__(self):
        return self.label


class Payment(models.Model):
    payment_means = models.CharField(max_length=100, null=True)
    amount = models.DecimalField(max_digits=7, decimal_places=2, null=True)
    date = models.DateField(default=datetime.date.today)
    invoce = models.ForeignKey(Invoice)
