#!  /usr/bin/env python
# encoding: utf-8
# vim: ai ts=4 sts=4 et sw=4

##
##
## @author UWANTWALI ZIGAMA Didier
## d.zigama@pivotaccess.com/zigdidier@gmail.com
##


from django.db import models
from django.db.models.signals import post_save

# Create your models here.

class LoginAudit(models.Model):
    id = models.AutoField(primary_key=True)
    created_by_id = models.IntegerField()
    ip_address = models.CharField(max_length=765)
    logout_date = models.DateTimeField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'login_audit'
        
class ApwPlatformFunction(models.Model):
    id = models.IntegerField(primary_key=True)
    function_name = models.CharField(unique=True, max_length=255)
    class Meta:
        db_table = u'apw_platform_function'

class ApwPlatformStatistic(models.Model):
    id = models.IntegerField(primary_key=True)
    login_audit = models.ForeignKey(LoginAudit, on_delete=models.CASCADE)
    platform_function = models.ForeignKey(ApwPlatformFunction, on_delete=models.CASCADE)
    access_date = models.DateField()
    access_count = models.IntegerField()
    class Meta:
        db_table = u'apw_platform_statistic'        
        
class GfRegionalClassification(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=192)
    class Meta:
        db_table = u'gf_regional_classification'
        
class CountryIncomeClassification(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=48)
    class Meta:
        db_table = u'country_income_classification'
        
class Region(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    alias = models.TextField(blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'region'
        
class Band(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=192)
    class Meta:
        db_table = u'band'
        
class WhoRegion(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=192)
    class Meta:
        db_table = u'who_region'        

class Country(models.Model):
    id = models.IntegerField(primary_key=True)
    region = models.ForeignKey(Region, on_delete=models.CASCADE)
    band = models.ForeignKey(Band, null=True, blank=True, on_delete=models.CASCADE)
    who_region = models.ForeignKey(WhoRegion, null=True, blank=True, on_delete=models.CASCADE)
    income_classification = models.ForeignKey(CountryIncomeClassification, null=True, blank=True, on_delete=models.CASCADE)
    gf_regional_classification = models.ForeignKey(GfRegionalClassification, null=True, blank=True, on_delete=models.CASCADE)
    name = models.CharField(unique=True, max_length=192)
    alias = models.TextField(blank=True)
    iso_code_2 = models.CharField(max_length=6, blank=True)
    iso_code_3 = models.CharField(max_length=9, blank=True)
    global_health_facts_id = models.CharField(max_length=48, blank=True)
    who_id = models.CharField(max_length=48, blank=True)
    fc_id = models.IntegerField()
    stand_alone_hss_funding_eligibility = models.CharField(max_length=135)
    tb_hiv_coinfection_country = models.IntegerField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'country'

class CcmWebsiteTemplate(models.Model):
    id = models.IntegerField(primary_key=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    su_user = models.CharField(max_length=192)
    password = models.CharField(max_length=192)
    domain = models.CharField(max_length=192)
    tpl_path = models.CharField(max_length=765)
    virtual_server_file = models.CharField(max_length=765)
    db_name = models.CharField(max_length=192)
    created_by_id = models.IntegerField()
    prefix = models.CharField(max_length=24)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'ccm_website_template'
        
class Applicant(models.Model):
    id = models.IntegerField(primary_key=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    name = models.CharField(unique=True, max_length=192)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'applicant'

class ColumnMapping(models.Model):
    id = models.IntegerField(primary_key=True)
    relation_name = models.CharField(max_length=192)
    column_name = models.CharField(max_length=192)
    alias = models.TextField(blank=True)
    row_position = models.IntegerField()
    column_position = models.IntegerField()
    date_created = models.DateTimeField()
    last_updated = models.CharField(max_length=135)
    class Meta:
        db_table = u'column_mapping'

class DiseaseComponent(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'disease_component'

class GlobalFundRound(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    board_meeting_date = models.DateTimeField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'global_fund_round'

class DownloadAudit(models.Model):
    id = models.IntegerField(primary_key=True)
    remote_url = models.CharField(max_length=765)
    download_type = models.CharField(max_length=39)
    download_start_time = models.DateTimeField()
    file_size = models.IntegerField()
    local_file_path = models.TextField(blank=True)
    file_modification_time = models.DateTimeField(null=True, blank=True)
    download_completion_time = models.DateTimeField(null=True, blank=True)
    comment = models.TextField()
    processed_at = models.DateTimeField(null=True, blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'download_audit'

class LocalFundAgent(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'local_fund_agent'
        
class Proposal(models.Model):
    id = models.IntegerField(primary_key=True)
    applicant = models.ForeignKey(Applicant, on_delete=models.CASCADE)
    global_fund_round = models.ForeignKey(GlobalFundRound, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    gf_original_proposal_id = models.IntegerField(unique=True)
    total_lifetime_budget = models.DecimalField(max_digits=32, decimal_places=15)
    approved_grant_amount = models.DecimalField(max_digits=32, decimal_places=15)
    submission_date = models.DateTimeField(null=True, blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'proposal'

class PrincipalRecipientType(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'principal_recipient_type'

class PrincipalRecipient(models.Model):
    id = models.IntegerField(primary_key=True)
    principal_recipient_type = models.ForeignKey(PrincipalRecipientType, on_delete=models.CASCADE)
    name = models.CharField(unique=True, max_length=255)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'principal_recipient'

class PrincipalRecipientAlias(models.Model):
    id = models.IntegerField(primary_key=True)
    principal_recipient = models.ForeignKey(PrincipalRecipient, on_delete=models.CASCADE)
    principal_recipient_type = models.ForeignKey(PrincipalRecipientType, on_delete=models.CASCADE)
    name = models.CharField(unique=True, max_length=255)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'principal_recipient_alias'

class GrantStatus(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=96)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    parent_id = models.CharField(max_length=24, blank=True)
    class Meta:
        db_table = u'grant_status'

class GfGrant(models.Model):
    id = models.IntegerField(primary_key=True)
    principal_recipient = models.ForeignKey(PrincipalRecipient, null=True, blank=True, on_delete=models.CASCADE)
    row_number = models.IntegerField()
    approved_grant_status = models.CharField(max_length=15)
    grant_signing_date = models.DateTimeField(null=True, blank=True)
    gf_original_grant_id = models.IntegerField(unique=True)
    grant_number = models.CharField(max_length=192)
    grant_start_date = models.DateTimeField(null=True, blank=True)
    grant_end_date = models.DateTimeField(null=True, blank=True)
    fpm_name = models.CharField(max_length=384, blank=True)
    fpm_email = models.CharField(max_length=192, blank=True)
    grant_title = models.TextField(blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    grant_status = models.ForeignKey(GrantStatus, null=True, blank=True, on_delete=models.CASCADE)
    class Meta:
        db_table = u'gf_grant'

class GrantPhase(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'grant_phase'

class GrantAgreement(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    agreement_amount = models.DecimalField(max_digits=32, decimal_places=15)
    disbursed_amount = models.DecimalField(max_digits=32, decimal_places=15)
    committed_amount = models.DecimalField(null=True, max_digits=32, decimal_places=15, blank=True)
    approval_date = models.DateTimeField(null=True, blank=True)
    board_approval_amount = models.DecimalField(null=True, max_digits=32, decimal_places=15, blank=True)
    pr_signing_date = models.DateTimeField(null=True, blank=True)
    gf_signing_date = models.DateTimeField(null=True, blank=True)
    start_date = models.DateTimeField(null=True, blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    end_date = models.DateTimeField(null=True, blank=True)
    board_approval_date = models.DateTimeField(null=True, blank=True)
    grant_phase = models.ForeignKey(GrantPhase, null=True, blank=True, on_delete=models.CASCADE)
    current_implementation_period = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = u'grant_agreement'

class VGrantAgreement(models.Model):
    id = models.IntegerField(primary_key=True)
    grantAgreementId                          = models.CharField(max_length=36, unique=True)
    geographicAreaId                          = models.CharField(max_length=36, blank=True)
    geographicAreaName                        = models.TextField(blank=True)
    geographicAreaCode_ISO3                   = models.TextField(blank=True)
    geographicAreaCode_ISO2                   = models.TextField(blank=True)
    geographicAreaLevelName                   = models.TextField(blank=True)
    globalFundRegionalTeamId                  = models.CharField(max_length=36, blank=True)
    globalFundRegionalTeamName                = models.TextField(blank=True)
    regionName                                = models.TextField(blank=True)
    whoRegionName                             = models.TextField(blank=True)
    geographicAreaName                        = models.TextField(blank=True)
    componentId                               = models.CharField(max_length=36, blank=True)
    componentName                             = models.TextField(blank=True)
    grantAgreementNumber                      = models.TextField(blank=True)
    grantAgreementStatusTypeName              = models.TextField(blank=True)
    multiCountryId                            = models.CharField(max_length=36, blank=True)
    multiCountryName                          = models.TextField(blank=True)
    grantAgreementTitle                       = models.TextField(blank=True)
    grantAgreementSummary                     = models.TextField(blank=True)
    programStartDate                          = models.DateTimeField(null=True, blank=True)
    programEndDate                            = models.DateTimeField(null=True, blank=True)
    portfolioManager                          = models.TextField(blank=True)
    portfolioManagerEmailAddress              = models.TextField(blank=True)
    applicantId                               = models.CharField(max_length=36, blank=True)
    applicantName                             = models.TextField(blank=True)
    applicantClassificationId                 = models.CharField(max_length=36, blank=True)
    applicantClassificationName               = models.TextField(blank=True)
    applicantSubClassificationId              = models.CharField(max_length=36, blank=True)
    applicantSubClassificationName            = models.TextField(blank=True)
    principalRecipientId                      = models.CharField(max_length=36, blank=True)
    principalRecipientName                    = models.TextField(blank=True)
    principalRecipientShortName               = models.TextField(blank=True)
    principalRecipientClassificationId        = models.CharField(max_length=36, blank=True)
    principalRecipientClassificationName      = models.TextField(blank=True)
    principalRecipientSubClassificationId     = models.CharField(max_length=36, blank=True)
    principalRecipientSubClassificationName   = models.TextField(blank=True)
    leadImplementerId                         = models.CharField(max_length=36, blank=True)
    leadImplementerName                       = models.TextField(blank=True)
    leadImplementerShortName                  = models.TextField(blank=True)
    leadImplementerClassificationId           = models.CharField(max_length=36, blank=True)
    leadImplementerClassificationName         = models.TextField(blank=True)
    leadImplementerSubClassificationId        = models.CharField(max_length=36, blank=True)
    leadImplementerSubClassificationName      = models.TextField(blank=True)
    localFundAgentId                          = models.CharField(max_length=36, blank=True)
    localFundAgentName                        = models.TextField(blank=True)
    localFundAgentClassificationId            = models.CharField(max_length=36, blank=True)
    localFundAgentClassificationName          = models.TextField(blank=True)
    localFundAgentSubClassificationId         = models.CharField(max_length=36, blank=True)
    localFundAgentSubClassificationName       = models.TextField(blank=True)
    ratingMethodologyPeriod                   = models.TextField(blank=True)
    performanceRatingId                       = models.CharField(max_length=36, blank=True)
    performanceRatingCode                     = models.TextField(blank=True)
    performanceRatingDescription              = models.TextField(blank=True)
    quantitativeRatingId                      = models.CharField(max_length=36, blank=True)
    quantitativeRatingCode                    = models.TextField(blank=True)
    quantitativeRatingDescription             = models.TextField(blank=True)
    workplanTrackingMeasuresRatingId          = models.CharField(max_length=36, blank=True)
    workplanTrackingMeasuresRatingCode        = models.TextField(blank=True)
    workplanTrackingMeasuresRatingDescription = models.TextField(blank=True)
    currency                                  = models.TextField(blank=True)
    totalSignedAmount                         = models.DecimalField(max_digits=32, decimal_places=2)
    totalCommittedAmount                      = models.DecimalField(max_digits=32, decimal_places=2)
    totalDisbursedAmount                      = models.DecimalField(max_digits=32, decimal_places=2)
    isActive                                  = models.IntegerField(null=True, blank=True)

    class Meta:
        db_table = u'VGrantAgreements'


class Donor(models.Model):
    id                  = models.IntegerField(primary_key=True)
    donorId             = models.CharField(max_length=36, unique=True)
    donorName           = models.TextField(blank=True)
    geographicAreaId    = models.CharField(max_length=36, blank=True)
    dateTimeCreated     = models.DateTimeField()
    dateTimeUpdated     = models.DateTimeField()

    class Meta:
        db_table = u'Donors'

        
class GfDisbursementRating(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    disbursement_date = models.DateTimeField(null=True, blank=True)
    disbursed_amount = models.DecimalField(null=True, max_digits=32, decimal_places=15, blank=True)
    disbursement_number = models.CharField(max_length=765, blank=True)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    is_zero_disbursement = models.CharField(max_length=15, blank=True)
    implementation_period_id = models.IntegerField(null=True, blank=True)
    progress_update_id = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = u'gf_disbursement_rating'

class ProgressUpdate(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    pu_number = models.DecimalField(max_digits=6, decimal_places=1)
    pu_start_date = models.DateTimeField(null=True, blank=True)
    pu_end_date = models.DateTimeField(null=True, blank=True)
    pu_review_date = models.DateTimeField(null=True, blank=True)
    pu_summary = models.TextField(blank=True)
    rating = models.CharField(max_length=48, blank=True)
    programmatic_rating = models.CharField(max_length=48, blank=True)
    class Meta:
        db_table = u'progress_update'

class Disbursement(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    download_audit = models.ForeignKey(DownloadAudit, on_delete=models.CASCADE)
    disbursement_number = models.CharField(max_length=5)
    gf_original_disbursement_id = models.IntegerField(unique=True)
    usd_amount = models.DecimalField(max_digits=30, decimal_places=15)
    eur_amount = models.DecimalField(max_digits=30, decimal_places=15)
    rating = models.CharField(max_length=15, null=True, blank=True)
    rating_weight = models.IntegerField(null=True, blank=True)
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)
    disbursement_date = models.DateTimeField()
    row_number = models.IntegerField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'disbursement'


class VGrantAgreementDisbursement(models.Model):
    id = models.IntegerField(primary_key=True)
    grantAgreementDisbursementId		     = models.CharField(max_length=36, unique=True)
    grantAgreementId                         = models.CharField(max_length=36, blank=True)
    geographicAreaId                         = models.CharField(max_length=36, blank=True)
    geographicAreaName			             = models.TextField(blank=True)
    geographicAreaCode_ISO3                  = models.TextField(blank=True)
    geographicAreaCode_ISO2                  = models.TextField(blank=True)
    geographicAreaLevelName                  = models.TextField(blank=True)
    geographicAreaRegionName			     = models.TextField(blank=True)
    globalFundRegionalTeamId                 = models.CharField(max_length=36, blank=True)
    globalFundRegionalTeamName               = models.TextField(blank=True)
    componentId                              = models.CharField(max_length=36, blank=True)
    componentName                            = models.TextField(blank=True)
    grantAgreementNumber                     = models.TextField(blank=True)
    grantAgreementStatusTypeName             = models.TextField(blank=True)
    multiCountryId                           = models.CharField(max_length=36, blank=True)
    multiCountryName                         = models.TextField(blank=True)
    grantAgreementTitle                      = models.TextField(blank=True)
    programStartDate			             = models.DateTimeField(null=True, blank=True)
    programEndDate                           = models.DateTimeField(null=True, blank=True)
    portfolioManager                         = models.TextField(blank=True)
    portfolioManagerEmailAddress             = models.TextField(blank=True)
    applicantId                              = models.CharField(max_length=36, blank=True)
    applicantName                            = models.TextField(blank=True)
    principalRecipientId                     = models.CharField(max_length=36, blank=True)
    principalRecipientName                   = models.TextField(blank=True)
    principalRecipientShortName              = models.TextField(blank=True)
    principalRecipientClassificationId       = models.CharField(max_length=36, blank=True)
    principalRecipientClassificationName     = models.TextField(blank=True)
    principalRecipientSubClassificationId    = models.CharField(max_length=36, blank=True)
    principalRecipientSubClassificationName  = models.TextField(blank=True)
    localFundAgentId                         = models.CharField(max_length=36, blank=True)
    localFundAgentName                       = models.TextField(blank=True)
    isActive				                 = models.IntegerField(null=True, blank=True)
    implementationPeriodStatusTypeId         = models.CharField(max_length=36, blank=True)
    implementationPeriodStatusTypeName       = models.TextField(blank=True)
    grantAgreementImplementationPeriodId     = models.CharField(max_length=36, blank=True)
    grantAgreementProgressUpdateId           = models.CharField(max_length=36, blank=True)
    implementationPeriodName                 = models.TextField(blank=True)
    implementationPeriodStartDate            = models.DateTimeField(null=True, blank=True)
    implementationPeriodEndDate              = models.DateTimeField(null=True, blank=True)
    isCurrentImplementationPeriod            = models.IntegerField(null=True, blank=True)
    currency                                 = models.TextField(blank=True)
    disbursementDate                         = models.DateTimeField(null=True, blank=True)
    disbursementMonth 			             = models.IntegerField()
    disbursementYear                         = models.IntegerField()
    disbursementAmount 			             = models.DecimalField(max_digits=32, decimal_places=2)

    class Meta:
        db_table = u'VGrantAgreementDisbursements'



class Role(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    description = models.TextField(blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'role'

class EventType(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=192)
    is_public = models.IntegerField()
    template_path = models.CharField(max_length=765)
    parameter = models.CharField(max_length=765, blank=True)
    from_email = models.CharField(max_length=765)
    group_text = models.CharField(max_length=96, blank=True)
    description = models.TextField(blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'event_type'
        

class Event(models.Model):
    id = models.IntegerField(primary_key=True)
    event_type = models.ForeignKey(EventType, on_delete=models.CASCADE)
    entity_reference_id = models.IntegerField(null=True, blank=True)
    date_generated = models.DateTimeField()
    name = models.CharField(max_length=255)
    processed = models.IntegerField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'event'

class EmailSchedule(models.Model):
    id = models.IntegerField(primary_key=True)
    event = models.ForeignKey(Event, on_delete=models.CASCADE)
    to_email = models.CharField(max_length=765)
    scheduled_for_relay = models.IntegerField()
    sent_at = models.DateTimeField(null=True, blank=True)
    from_email = models.CharField(max_length=765)
    subject = models.CharField(max_length=192, blank=True)
    message_body = models.TextField(blank=True)
    delivery_date = models.DateTimeField(null=True, blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'email_schedule'

class PerformanceRating(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_rating = models.CharField(max_length=15)
    performance_category = models.CharField(max_length=192)
    progress_against_target = models.CharField(max_length=48)
    rating_weight = models.IntegerField()
    description = models.TextField(blank=True)
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'performance_rating'

class WebGfoAudit(models.Model):
    id = models.IntegerField(primary_key=True)
    latest_test = models.DateTimeField()
    issue_number = models.IntegerField()
    is_abort = models.IntegerField()
    prepared_at = models.DateTimeField(null=False)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    email_body = models.TextField(blank=True)
    class Meta:
        db_table = u'web_gfo_audit'

class ReportCriteria(models.Model):
    id = models.IntegerField(primary_key=True)
    artifact = models.CharField(max_length=192)
    name = models.CharField(max_length=192)
    created_by_id = models.IntegerField()
    is_private = models.IntegerField()
    filter_field = models.TextField()
    display_field = models.TextField()
    sort_field = models.TextField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'report_criteria'

class Module(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=48)
    display_name = models.CharField(max_length=96)
    handler = models.CharField(max_length=192)
    icon_file = models.CharField(max_length=96)
    description = models.CharField(max_length=765)
    class Meta:
        db_table = u'module'

class Repository(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=64)
    local_file_path = models.CharField(max_length=255)
    url_identifier = models.CharField(max_length=128)
    file_size = models.IntegerField()
    description = models.TextField(blank=True)
    created_by_id = models.IntegerField()
    date_created = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'repository'

class CountryMetaData(models.Model):
    id = models.IntegerField(primary_key=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    evaluation_date = models.DateTimeField()
    burden_of_disease = models.IntegerField()
    economic_classification = models.CharField(max_length=96)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    gross_domestic_product = models.DecimalField(max_digits=32, decimal_places=2)
    population = models.DecimalField(max_digits=32, decimal_places=2)
    total_exp_health_capita = models.DecimalField(max_digits=32, decimal_places=2)
    gov_exp_health_capita = models.DecimalField(max_digits=32, decimal_places=2)
    total_exp_as_percentage_gdp = models.DecimalField(max_digits=32, decimal_places=2)
    gov_exp_health_as_per_the = models.DecimalField(max_digits=32, decimal_places=2)
    private_exp_health_as_per_the = models.DecimalField(max_digits=32, decimal_places=2)
    gov_exp_health_as_per_tge = models.DecimalField(max_digits=32, decimal_places=2)
    class Meta:
        db_table = u'country_meta_data'
        
class Indicator(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.TextField()
    indicator_type = models.CharField(max_length=48, blank=True)
    class Meta:
        db_table = u'indicator'
        
class ServiceDeliveryArea(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.TextField()
    class Meta:
        db_table = u'service_delivery_area'        

class GrantIndicatorResult(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    indicator = models.ForeignKey(Indicator, on_delete=models.CASCADE)
    service_delivery_area = models.ForeignKey(ServiceDeliveryArea, null=True, blank=True, on_delete=models.CASCADE)
    period_start = models.DateField()
    period_end = models.DateField()
    target = models.CharField(max_length=2295)
    actual = models.CharField(max_length=2295)
    target_period_number = models.IntegerField()
    result_period_number = models.IntegerField()
    cumulative_type_description = models.TextField(blank=True)
    class Meta:
        db_table = u'grant_indicator_result'

class VGrantIndicatorResult(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    grant_number = models.CharField(max_length=192, blank=True)
    grant_title = models.TextField(blank=True)
    country_name = models.CharField(max_length=192, blank=True)
    country_region_name = models.CharField(max_length=192, blank=True)
    country_iso_code_3 = models.CharField(max_length=9, blank=True)
    disease_component_name = models.CharField(max_length=192, blank=True)
    principal_recipient_name = models.CharField(max_length=255, blank=True)
    indicator = models.ForeignKey(Indicator, on_delete=models.CASCADE)
    indicator_name = models.TextField()
    indicator_type = models.CharField(max_length=48, blank=True)
    service_delivery_area = models.ForeignKey(ServiceDeliveryArea, null=True, blank=True, on_delete=models.CASCADE)
    service_delivery_area_name = models.TextField()
    period_start = models.DateField()
    period_end = models.DateField()
    target = models.CharField(max_length=2295)
    actual = models.CharField(max_length=2295)
    target_period_number = models.IntegerField()
    result_period_number = models.IntegerField()
    cumulative_type_description = models.TextField(blank=True)
    class Meta:
        db_table = u'vgrant_indicator_result'

class TargetYear(models.Model):
    id = models.IntegerField(primary_key=True)
    year = models.CharField(max_length=192, blank=True)
    sort_order = models.IntegerField()
    class Meta:
        db_table = u'target_year'

class IndicatorCatalog(models.Model):
    id = models.IntegerField(primary_key=True)
    indicator = models.ForeignKey(Indicator, on_delete=models.CASCADE)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    target_year = models.ForeignKey(TargetYear, on_delete=models.CASCADE)
    reporting_quarter = models.IntegerField()
    indicator_value = models.IntegerField()
    indicator_source = models.CharField(max_length=765)
    reason_exclude_cumulative = models.TextField(blank=True)
    class Meta:
        db_table = u'indicator_catalog'
        
class Allocation(models.Model):
    id = models.IntegerField(primary_key=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    allocation_percentage = models.DecimalField(max_digits=22, decimal_places=2)
    other_existing_funds = models.DecimalField(max_digits=22, decimal_places=2)
    additional_funding = models.DecimalField(max_digits=22, decimal_places=2)
    total_funding = models.DecimalField(max_digits=22, decimal_places=2)
    allocation_status = models.CharField(max_length=135, blank=True)
    incentive_funding = models.IntegerField()
    disease_burden = models.CharField(max_length=48, blank=True)
    class Meta:
        db_table = u'allocation'

class RecipientListing(models.Model): 
    id = models.AutoField(primary_key=True, db_column='ID') # Field name made lowercase.
    unique_id = models.CharField(max_length=100, db_column='UNIQUE_ID', blank=True) # Field name made lowercase.
    round = models.IntegerField(null=True, db_column='ROUND', blank=True) # Field name made lowercase.
    disease = models.CharField(max_length=90, db_column='DISEASE', blank=True) # Field name made lowercase.
    diseasecode = models.CharField(max_length=12, db_column='DISEASECODE', blank=True) # Field name made lowercase.
    country = models.CharField(max_length=300, db_column='COUNTRY', blank=True) # Fiedate_of_issueld name made lowercase.
    countrycode = models.CharField(max_length=9, db_column='COUNTRYCODE', blank=True) # Field name made lowercase.
    recipient_type = models.CharField(max_length=6, db_column='RECIPIENT_TYPE', blank=True) # Field name made lowercase.
    organization = models.CharField(max_length=765, db_column='ORGANIZATION', blank=True) # Field name made lowercase.
    organizationcode = models.IntegerField(null=True, db_column='ORGANIZATIONCODE', blank=True) # Field name made lowercase.
    contact_person = models.CharField(max_length=765, db_column='CONTACT_PERSON', blank=True) # Field name made lowercase.
    designation = models.CharField(max_length=765, db_column='DESIGNATION', blank=True) # Field name made lowercase.
    emailaddress = models.CharField(max_length=765, db_column='EMAILADDRESS', blank=True) # Field name made lowercase.
    emailaddress2 = models.CharField(max_length=765, db_column='EMAILADDRESS2', blank=True) # Field name made lowercase.
    emailaddress3 = models.CharField(max_length=765, db_column='EMAILADDRESS3', blank=True) # Field name made lowercase.
    telephone = models.CharField(max_length=765, db_column='TELEPHONE', blank=True) # Field name made lowercase.
    telephone2 = models.CharField(max_length=765, db_column='TELEPHONE2', blank=True) # Field name made lowercase.
    telephone3 = models.CharField(max_length=765, db_column='TELEPHONE3', blank=True) # Field name made lowercase.
    contact_person2 = models.CharField(max_length=765, db_column='CONTACT_PERSON2', blank=True) # Field name made lowercase.
    contact_person3 = models.CharField(max_length=765, db_column='CONTACT_PERSON3', blank=True) # Field name made lowercase.
    designation2 = models.CharField(max_length=765, db_column='DESIGNATION2', blank=True) # Field name made lowercase.
    designation3 = models.CharField(max_length=765, db_column='DESIGNATION3', blank=True) # Field name made lowercase.
    grant_id = models.IntegerField(db_column='GRANT_ID', blank=True) # Field name made lowercase.
    parent_org_id = models.IntegerField(db_column='PARENT_ORG_ID', blank=True)
    amount = models.DecimalField(max_digits=32, decimal_places=15,db_column='AMOUNT', blank=True) # Field name made lowercase.
    additional_details=models.TextField(db_column='ADDITIONAL_DETAILS', blank=True)
    date_created = models.DateTimeField(db_column='DATE_CREATED', blank=True)
    user_id = models.IntegerField(db_column='USER_ID',blank=True)
    date_update = models.DateTimeField(db_column='DATE_UPDATED', blank=True)
    user_id_update = models.IntegerField(db_column='UPDATE_USER_ID',blank=True)
    date_of_issue = models.DateField(db_column='DATE_OF_ISSUE',blank=True) 
    class Meta:
        db_table = u'receipent_listing'

class ConsultantAreaOfSpeciality(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=255, blank=True)
    class Meta:
        db_table = u'consultant_area_of_speciality'
        
class Consultants(models.Model):
    id = models.IntegerField(primary_key=True)
    first_name = models.CharField(max_length=765, blank=True)
    last_name = models.CharField(max_length=765, blank=True)
    area_of_speciality = models.ForeignKey(ConsultantAreaOfSpeciality, null=True,
						db_column='area_of_speciality', blank=True, on_delete=models.CASCADE)
    organisation = models.CharField(max_length=765, blank=True)
    country = models.CharField(max_length=765, blank=True)
    email = models.CharField(max_length=765, blank=True)
    telephone_no = models.CharField(max_length=765, blank=True)
    mobile_no = models.CharField(max_length=135, blank=True)
    department = models.CharField(max_length=765, blank=True)
    last_consultancy = models.DateField(null=True, blank=True)
    is_active = models.IntegerField(null=True, blank=True)
    update_date = models.DateTimeField(null=True, blank=True)
    create_date = models.DateTimeField(null=True, blank=True)
    created_by = models.CharField(max_length=135, blank=True)
    class Meta:
        db_table = u'consultants'
        
class ConsultantDocuments(models.Model):
    id = models.AutoField(primary_key=True)
    document_name = models.CharField(max_length=765, blank=True)
    document_path = models.CharField(max_length=765, blank=True)
    description = models.TextField(blank=True)
    date_updated = models.DateTimeField(null=True, blank=True)
    consultants = models.ForeignKey(Consultants, on_delete=models.CASCADE) 
    url_identifier = models.CharField(max_length=128)
    file_size = models.IntegerField() 
    created_by_id = models.IntegerField()
    date_created = models.DateTimeField() 
    class Meta:
        db_table = u'consultant_documents'

class ConsultantRates(models.Model):
    id = models.AutoField(primary_key=True)
    rate_type = models.CharField(max_length=765, blank=True)
    rate_description = models.CharField(max_length=765, blank=True)
    amount = models.FloatField(null=True, blank=True)
    rate_start_date = models.DateTimeField(null=True, blank=True)
    rate_end_date = models.DateTimeField(null=True, blank=True)
    active = models.IntegerField()
    consultants = models.ForeignKey(Consultants, on_delete=models.CASCADE)
    class Meta:
        db_table = u'consultant_rates'
        
class PageLink(models.Model):
    id = models.IntegerField(primary_key=True)
    uri = models.CharField( max_length=765)
    title = models.CharField(max_length=765, blank=True)
    nid = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = u'page_link'
        
class PageStatistic(models.Model):
    id = models.IntegerField(primary_key=True)
    page_link = models.ForeignKey(PageLink, on_delete=models.CASCADE)
    visit_date = models.DateField(unique=True)
    view_count = models.IntegerField()
    nid = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = u'page_statistic'

class PublicationDownload(models.Model):
    id = models.IntegerField(primary_key=True)
    filepath = models.CharField(unique=True, max_length=255)
    filename = models.CharField(max_length=765)
    class Meta:
        db_table = u'publication_download'

class PublicationDownloadStatistic(models.Model):
    id = models.IntegerField(primary_key=True)
    publication_download = models.ForeignKey(PublicationDownload, on_delete=models.CASCADE)
    download_date = models.DateField(unique=True)
    download_count = models.IntegerField()
    class Meta:
        db_table = u'publication_download_statistic'

class Budget(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    final_amount = models.DecimalField(max_digits=32, decimal_places=15)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = u'budget'

class VBudget(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    final_amount = models.DecimalField(max_digits=32, decimal_places=15)
    grant_number = models.CharField(max_length=192, blank=True)
    grant_title = models.TextField(blank=True)
    country_name = models.CharField(max_length=192, blank=True)
    country_region_name = models.CharField(max_length=192, blank=True)
    country_iso_code_3 = models.CharField(max_length=9, blank=True)
    disease_component_name = models.CharField(max_length=192, blank=True)
    principal_recipient_name = models.CharField(max_length=255, blank=True)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = u'vbudget'      
        
class Expenditure(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    total_expenditure = models.DecimalField(max_digits=32, decimal_places=15)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = u'expenditure' 

class VExpenditure(models.Model):
    id = models.IntegerField(primary_key=True)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    total_expenditure = models.DecimalField(max_digits=32, decimal_places=15)
    grant_number = models.CharField(max_length=192, blank=True)
    grant_title = models.TextField(blank=True)
    country_name = models.CharField(max_length=192, blank=True)
    country_region_name = models.CharField(max_length=192, blank=True)
    country_iso_code_3 = models.CharField(max_length=9, blank=True)
    disease_component_name = models.CharField(max_length=192, blank=True)
    principal_recipient_name = models.CharField(max_length=255, blank=True)
    date_created = models.DateTimeField(null=True, blank=True)
    last_updated = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = u'vexpenditure'        
     
class NewsletterTracking(models.Model):
    tracking_id = models.IntegerField(primary_key=True)
    user_id = models.IntegerField(null=True, blank=True)
    newsletter = models.CharField(max_length=300, blank=True)
    views = models.IntegerField(null=True, blank=True)
    first_view = models.DateTimeField(null=True, blank=True)
    last_view = models.DateTimeField(null=True, blank=True)
    class Meta:
        db_table = u'newsletter_tracking'
"""  
      
class WebUsers(models.Model):
    uid = models.IntegerField(primary_key=True)
    name = models.CharField(unique=True, max_length=180)
    pass_field = models.CharField(max_length=384, db_column='pass') # Field renamed because it was a Python reserved word. Field name made lowercase.
    mail = models.CharField(max_length=762, blank=True)
    theme = models.CharField(max_length=765)
    signature = models.CharField(max_length=765)
    signature_format = models.CharField(max_length=765, blank=True)
    created = models.IntegerField()
    access = models.IntegerField()
    login = models.IntegerField()
    status = models.IntegerField()
    timezone = models.CharField(max_length=96, blank=True)
    language = models.CharField(max_length=36)
    init = models.CharField(max_length=762, blank=True)
    data = models.TextField(blank=True)
    picture = models.IntegerField()
    uuid = models.CharField(max_length=108)
    class Meta:
        db_table = u'web_users'

"""
    
class TrackerLogs(models.Model):
    tracker_log_id = models.IntegerField(primary_key=True)
    id = models.IntegerField(db_column='Id') # Field name made lowercase.
    log_time = models.DateTimeField(db_column='Log_Time') # Field name made lowercase.
    tracker_ip = models.CharField(max_length=135, blank=True)
    class Meta:
        db_table = u'tracker_logs'
        
class FundingDecision(models.Model):
    id = models.IntegerField(primary_key=True)
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    gf_grant = models.ForeignKey(GfGrant, on_delete=models.CASCADE)
    total_program_budget = models.DecimalField(max_digits=22, decimal_places=2)
    total_grant_agreement_amount = models.DecimalField(null=True, max_digits=22, decimal_places=2, blank=True)
    approved_date = models.DateTimeField()
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'funding_decision'
        
class IncentiveFunding(models.Model):
    id = models.IntegerField(primary_key=True)
    year_from = models.IntegerField()
    year_to = models.IntegerField()
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    disease_component = models.ForeignKey(DiseaseComponent, on_delete=models.CASCADE)
    approved_amount = models.DecimalField(max_digits=22, decimal_places=2)
    last_updated = models.DateTimeField()
    class Meta:
        db_table = u'incentive_funding'

"""
@receiver(post_save, sender=User)
def do_something_when_user_updated(sender, instance, created, **kwargs):
    if not created:
        # User object updated
        user_obj = instance
        pass 
"""
