from django.db import models

class Account(models.Model):
    number = models.CharField(max_length=10, null=True)
    bank = models.CharField(max_length=30, null=True)
    name = models.CharField(max_length=55, null=True)
    created = models.DateTimeField(auto_now_add=True, null=True)
    updated = models.DateTimeField(auto_now=True, null=True)

    def __str__(self):
        try:
            return str(self.number) + " - " + str(self.bank)
        except:
            return str(self.id)

    class Meta:
        ordering = ('-created',)

class Category(models.Model):
    amount = models.DecimalField(null=True, max_digits=10, decimal_places=2, verbose_name="Amount to be Paid")
    category = models.CharField(max_length=55, null=True)
    classe = models.ForeignKey('management.Class', on_delete=models.SET_NULL, null=True, verbose_name="Class")
    created = models.DateTimeField(auto_now_add=True, null=True)
    updated = models.DateTimeField(auto_now=True, null=True)

    def __str__(self):
        try:
            return str(self.category) + " - " + str(self.classe)
        except:
            return str(self.id)

    class Meta:
        ordering = ('category',)

class Notification(models.Model):
    PAYMENT_CHOICES = [
        ('Bank Transfer', 'Bank Transfer'),
		('Cash Deposit (Bank)', 'Cash Deposit (Bank)'),
        ('POS Transaction', 'POS Transaction'),
        ('Cheque', 'Cheque'),
        ('Other Offline Method', 'Other Offline Method'),
    ]
    REVIEW_CHOICES = [
        ('Pending', 'Pending'),
		('Approved', 'Approved'),
    ]
    term = models.ForeignKey('management.Term', on_delete = models.SET_NULL, null=True)
    student = models.ForeignKey('account.Person', on_delete = models.SET_NULL, null=True, verbose_name="Student Paid for", related_name="student")
    recorder = models.ForeignKey('account.Person', on_delete = models.SET_NULL, null=True, related_name="recorder")
    category = models.ForeignKey('payment.Category', on_delete = models.SET_NULL, null=True, verbose_name="Payment Category")
    amount_paid = models.DecimalField(null=True, max_digits=10, decimal_places=2, verbose_name="Amount Paid")
    balance = models.DecimalField(null=True, max_digits=10, decimal_places=2)
    method = models.CharField(max_length=20, default="Bank Transfer", choices=PAYMENT_CHOICES, null=True)
    account = models.ForeignKey('payment.Account', on_delete = models.SET_NULL, null=True, blank=True, verbose_name="School Bank Account Paid to")
    date = models.DateField(null=True, verbose_name="Payment Date")
    review = models.CharField(max_length=8, default="Pending", choices=REVIEW_CHOICES, null=True)
    completed = models.BooleanField(max_length=5, default = False)
    receipt_id = models.CharField(max_length=16, null=True)
    # last_transaction = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2)
    # amount_credited = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2, verbose_name="Credit")
    # current_balance = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2)
    # amount_credited = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2, verbose_name="Credit")
    # referral = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2)
    # first = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2)
    # point = models.DecimalField(blank=True, null=True, max_digits=15, decimal_places=2)
    created = models.DateTimeField(auto_now_add=True, null=True)
    updated = models.DateTimeField(auto_now=True)

    def __str__(self):
        try:
            return str(self.student.username) + " - " + str(self.student.first_name) + " " + str(self.student.last_name)
        except:
            return str(self.id)
    class Meta:
        ordering = ('-created',)
