from django.db import models
from django.template.defaultfilters import default
from _mysql import NULL
from dealerfunnel.funnel.library.common import * 


class Makesmodel(models.Model):
    year   = models.TextField(null = True)
    make   = models.TextField(null = True)
    model  = models.TextField(null = True)
    def __dir__(self):
            return [
                      'year','make','model'
                   ]                           
            
class Media_image(models.Model):
    path   = models.TextField(null = True)
    width  = models.IntegerField(null = True)
    height = models.IntegerField(null = True)
    def __dir__(self):
            return [
                      'name','width','height'
                   ]  

class User_dealer(models.Model):
    userid        = models.IntegerField(null = True)
    dealerid      = models.IntegerField(null = True)
    def __dir__(self):
            return [
                      'userid','dealerid'
                   ]
    

            
class Twillio_phone(models.Model):
    number  = models.CharField(max_length = 100,null = True)
    sid     = models.CharField(max_length = 100,null = True)
    date    = models.DateField(null = True)
    type    = models.CharField(max_length = 100, null = True)
    city    = models.CharField(max_length = 100, null = True)
    state   = models.CharField(max_length = 100, null = True)
    zip     = models.CharField(max_length = 100, null = True)
    def __dir__(self):
            return [
                      'number','sid','date','type','city','state','zip'
                   ] 

class Zipcode(models.Model):
    code    = models.CharField(max_length = 10,null = True)
    lat     = models.FloatField()
    lng     = models.FloatField()
    def __dir__(self):
            return [
                      'code','lat','lng'
                   ]
class Zipcode_distance(models.Model):
    zip1    = models.CharField(max_length = 10,null = True)
    zip2    = models.CharField(max_length = 10,null = True)
    val     = models.FloatField()
    def __dir__(self):
            return [
                      'zip1','zip2','val'
                   ]             
class Roiclient(models.Model):
    dealerid                    = models.IntegerField(null = True)
    roi_id                      = models.CharField(max_length=100,null = True)
    sl                          = models.CharField(max_length=100,null = True)
    sv                          = models.CharField(max_length=100,null = True)
    flag                        = models.IntegerField(null = True)
    lastupdate                  = models.DateTimeField(null = True)                  
class usertype_lookup(models.Model):
    user         = models.TextField(max_length=20,null = True)
class User(models.Model):
    name         = models.TextField(max_length=100,null = True)
    title        = models.TextField(max_length=100,null = True)
    email        = models.TextField(max_length=100,null = True)
    password     = models.TextField(max_length=100,null = True)
    fuserphoto   = models.ForeignKey(Media_image,related_name='userphoto',null = True)
    fusertype    = models.ForeignKey(usertype_lookup,related_name='usertype',null = True)
    keyid        = models.TextField(max_length=100,null = True)
    forgottenkey = models.TextField(max_length=100,null = True)
    timedelay    = models.IntegerField(null = True)
    address      = models.TextField(max_length=100,null = True)
    city         = models.TextField(max_length=100,null = True)
    state        = models.TextField(max_length=100,null = True)
    fzip         = models.ForeignKey(Zipcode,null = True) 
    phone        = models.TextField(max_length=100,null = True)
    cellphone    = models.TextField(max_length=100,null = True)
    islogin      = models.IntegerField(null = True,default = 0) 
    lastlogin    = models.DateTimeField(null = True)
    rdate        = models.DateTimeField(null = True)
    status       = models.IntegerField(null = True,default = 1)
    def __dir__(self):
            return [
                      'title','islogin','name','email','password','fuserphoto','fusertype','lastlogin','rdate','keyid','forgottenkey'
                      ,'cellphone','timedelay','address','city','state','fzip','phone','islogin','lastlogin','rdate','status'
                   ]
class phone(models.Model):
    number            = models.CharField(max_length = 50,null= True)
    phonetype         = models.IntegerField()
class Dealer(models.Model):
    name                        = models.CharField(max_length=100,null = True)
    address                     = models.CharField(max_length=100,null = True)
    city                        = models.CharField(max_length=50,null = True)
    state                       = models.CharField(max_length=20,null = True)
    fzip                        = models.ForeignKey(Zipcode)
    color                       = models.CharField(max_length=50,null = True)
    flogo                       = models.ForeignKey(Media_image,related_name='image1',null = True)
    fmlogo                      = models.ForeignKey(Media_image,related_name='image2',null = True)
    ftwillio                    = models.ForeignKey(Twillio_phone,related_name='twilio',null = True)
    fsmstwillio                 = models.ForeignKey(Twillio_phone,related_name='smstwilio',null = True)        
    sale_contact                = models.CharField(max_length = 100,null = True)
    sale_title                  = models.CharField(max_length = 100,null = True)
    sale_phone                  = models.CharField(max_length = 20,null = True)
    service_contact             = models.CharField(max_length = 100,null = True)
    service_title               = models.CharField(max_length = 100,null = True)
    service_phone               = models.CharField(max_length = 20,null = True)
    trade_contact               = models.CharField(max_length = 100,null = True)
    trade_title                 = models.CharField(max_length = 100,null = True)
    trade_phone                 = models.CharField(max_length = 20,null = True)
    sales_regular_hour_from     = models.CharField(max_length = 20,null = True)
    sales_sunday_hour_from      = models.CharField(max_length = 20,null = True)
    sales_saturday_hour_from    = models.CharField(max_length = 20,null = True)
    sales_regular_hour_to       = models.CharField(max_length = 20,null = True)
    sales_sunday_hour_to        = models.CharField(max_length = 20,null = True)
    sales_saturday_hour_to      = models.CharField(max_length = 20,null = True)
    service_regular_hour_from   = models.CharField(max_length = 20,null = True)
    service_sunday_hour_from    = models.CharField(max_length = 20,null = True)
    service_saturday_hour_from  = models.CharField(max_length = 20,null = True)
    service_regular_hour_to     = models.CharField(max_length = 20,null = True)
    service_sunday_hour_to      = models.CharField(max_length = 20,null = True)
    service_saturday_hour_to    = models.CharField(max_length = 20,null = True)
    triggers_budget             = models.IntegerField(null= True)
    triggers_email              = models.IntegerField(null= True)
    triggers_pieces             = models.IntegerField(null = True)
    trigger_cost_per_pieces     = models.FloatField(null = True)
    trigger_trade_cycle         = models.IntegerField(null = True)
    trigger_birthday            = models.IntegerField(null = True)
    trigger_new_purchase        = models.IntegerField(null = True)
    trigger_equity_position     = models.IntegerField(null = True)
    trigger_fst_service         = models.IntegerField(null = True)
    trigger_warranty_expiration = models.IntegerField(null = True)
    trigger_overdue_services    = models.IntegerField(null = True)
    trigger_make_conquest       = models.IntegerField(null = True)
    trigger_crossover_conquest  = models.IntegerField(null = True)
    smsforwardnumber            = models.CharField(max_length = 20,null = True)
    issms                       = models.IntegerField(null = True)
    cdate                       = models.DateField(auto_now_add=True)
    keyid                       = models.CharField(max_length=100,null = True)
    flag1                       = models.IntegerField(default=0,null= True)
    flag2                       = models.IntegerField(default=0,null= True)
    flag3                       = models.IntegerField(default=0,null= True)
    flag4                       = models.IntegerField(default=0,null= True)
    def __dir__(self):
            return [
                    'name','address','city','state','fzip','color','faddress','flogo','fmlogo','ftwillio','sale_contact','sale_title',
                    'sale_phone','service_contact','service_title','service_phone','trade_contact','trade_title',
                    'trade_phone','sales_regular_hour_from','sales_sunday_hour_from','sales_saturday_hour_from',
                    'service_regular_hour_from','service_sunday_hour_from','service_saturday_hour_from',
                    'sales_regular_hour_to','sales_sunday_hour_to','sales_saturday_hour_to',
                    'service_regular_hour_to','service_sunday_hour_to','service_saturday_hour_to',
                    'triggers_budget','triggers_pieces','trigger_cost_per_pieces','trigger_trade_cycle',
                    'trigger_birthday','trigger_new_purchase','trigger_equity_position','trigger_fst_service',
                    'trigger_warranty_expiration','trigger_overdue_services','trigger_make_conquest',
                    'trigger_crossover_conquest','cdate','keyid','triggers_email','issms','smsforwardnumber'
                    
                   ]

class Campaign_roi_analysis(models.Model):
    car            = models.IntegerField(null = True)
    service        = models.IntegerField(null = True)
    grossprofit    = models.FloatField()
    invoiced       = models.FloatField()
    carsold        = models.FloatField()
 
class Campaign(models.Model):
    name           =    models.CharField(max_length=100,null = True)
    trigger        =    models.IntegerField(null = True)
    totalmail      =    models.IntegerField(null = True)
    totalemail     =    models.IntegerField(null = True)
    totalcost      =    models.FloatField(null = True)
    mailstyle      =    models.IntegerField(null = True)
    emailstyle     =    models.IntegerField(null = True)
    startdate      =    models.DateField()
    enddate        =    models.DateField()
    maildate       =    models.DateField()
    emaildate      =    models.DateField()
    budgetmonth    =    models.IntegerField(null = True)
    type           =    models.IntegerField(null = True)
    status         =    models.IntegerField(null = True)
    keyid          =    models.CharField(max_length=100,null = True)
    fdealer        =    models.ForeignKey(Dealer,null = True) 
    froi           =    models.ForeignKey(Campaign_roi_analysis,null = True)
    def __dir__(self):
            return [
                    'name','trigger','totalmail','totalemail','totalcost','mailstyle',
                    'startdate','enddate','maildate','emaildate','budgetmonth','fdealer',
                    'froi','keyid','type','status','emailstyle'

                   ]
 
class Historical_report(models.Model):
    year                 = models.IntegerField(null = True)
    month                = models.IntegerField(null = True)
    sales                = models.IntegerField(null = True)
    service              = models.IntegerField(null = True)
    type                 = models.IntegerField(null = True)
    revenue              = models.FloatField()
    fdealer              = models.ForeignKey(Dealer)    
                   
class State(models.Model):
    state_name           =  models.CharField(max_length=30,null = True)   
    state_abbreviation   =  models.CharField(max_length=30,null = True)
    state_status         =  models.CharField(max_length=30,null = True)

class Market_analysis(models.Model):
    fzipcode             =  models.ForeignKey(Zipcode,null = True)   
    radious              =  models.FloatField(null = True)
    customer             =  models.IntegerField(null = True)
    city                 =  models.CharField(max_length=50,null = True)
    state                =  models.CharField(max_length=10,null = True)
    bns                  =  models.IntegerField(null = True)
    snb                  =  models.IntegerField(null = True)
    bs                   =  models.IntegerField(null = True)
    makeconquest         =  models.IntegerField(null = True)
    salesmarketshare     =  models.IntegerField(null = True)
    crossoverconquest    =  models.IntegerField(null = True)
    fdealer              =  models.ForeignKey(Dealer,null = True)

class Market_analysis_temp(models.Model):
    fzipcode             =  models.ForeignKey(Zipcode,null = True)   
    radious              =  models.FloatField(null = True)
    customer             =  models.IntegerField(null = True)
    city                 =  models.CharField(max_length=50,null = True)
    state                =  models.CharField(max_length=10,null = True)
    bns                  =  models.IntegerField(null = True)
    snb                  =  models.IntegerField(null = True)
    bs                   =  models.IntegerField(null = True)
    makeconquest         =  models.IntegerField(null = True)
    salesmarketshare     =  models.IntegerField(null = True)
    crossoverconquest    =  models.IntegerField(null = True)
    fdealer              =  models.ForeignKey(Dealer,null = True)              

class Customer_analysis(models.Model):
    total_customer     = models.IntegerField(null = True)
    warrantyexpiration = models.IntegerField(null = True)
    crossoverconquest  = models.IntegerField(null = True)
    leaseexpiration    = models.IntegerField(null = True)
    birthday           = models.IntegerField(null = True)
    euityposition      = models.IntegerField(null = True)
    tradecycle         = models.IntegerField(null = True)
    makeconquest       = models.IntegerField(null = True)
    lateservice        = models.IntegerField(null = True)
    active             = models.IntegerField(null = True)
    lessactive         = models.IntegerField(null = True)
    lost               = models.IntegerField(null = True)
    active_12          = models.IntegerField(null = True)
    active_34          = models.IntegerField(null = True)
    active_5           = models.IntegerField(null = True)
    less_12            = models.IntegerField(null = True)
    less_34            = models.IntegerField(null = True)
    less_5             = models.IntegerField(null = True)
    lost_12            = models.IntegerField(null = True)
    lost_34            = models.IntegerField(null = True)
    lost_5             = models.IntegerField(null = True)
    lastvisit          = models.DateField(null = True)
    latestvisit        = models.DateField(null = True)
    bns                = models.IntegerField(null = True)
    snb                = models.IntegerField(null = True)
    bs                 = models.IntegerField(null = True)
    fdealer            = models.ForeignKey(Dealer,null = True)
    def __dir__(self):
            return [
                    'total_customer','warrantyexpiration','crossoverconquest','leaseexpiration',
                    'birthday','euityposition','tradecycle','makeconquest','lateservice','fdealer',
                    'active','lessactive','lost','active_12','active_34','active_5','less_12','less_34',
                    'less_5','lost_12','lost_34','lost_5'
                   ]          
class Cron_campaign_build(models.Model):
    campaign = models.IntegerField(null = True)
    customer = models.TextField(null = True)
    type     = models.IntegerField(null = True)
    sdate    = models.DateField(null = True)
    ndate    = models.DateField(null = True) 

class Topvehicle(models.Model):
    make              = models.CharField(max_length = 50,null= True)
    model             = models.CharField(max_length = 50,null= True)
    count             = models.IntegerField()
    fdealer           = models.ForeignKey(Dealer)

class Topzipcode(models.Model):
    zip               = models.CharField(max_length = 10,null= True)
    city              = models.CharField(max_length = 50,null= True)
    state             = models.CharField(max_length = 50,null= True)
    count             = models.IntegerField()
    sales             = models.IntegerField()
    service           = models.IntegerField()
    fdealer           = models.ForeignKey(Dealer)
    
class pinmanage(models.Model):
    start             = models.IntegerField()
    end               = models.IntegerField()
    type              = models.IntegerField()
    def __dir__(self):
            return ['start','end','type']     
class Customer_media(models.Model):
    image             = models.CharField(max_length = 500,null= True)
    link              = models.CharField(max_length = 500,null= True)
    isavailable       = models.IntegerField()
    def __dir__(self):
            return ['image','link','isavailable']    
class Customer(models.Model):
    barcode           = models.IntegerField()
    number            = models.CharField(max_length = 50,null= True)
    fname             = models.CharField(max_length = 100,null= True)
    lname             = models.CharField(max_length = 100,null= True)
    email             = models.CharField(max_length = 100,null= True)
    fmedia            = models.ForeignKey(Customer_media,related_name='media',null = True)
    homephone         = models.CharField(max_length = 100,null= True) 
    workphone         = models.CharField(max_length = 100,null= True)
    cellphone         = models.CharField(max_length = 100,null= True)
    address           = models.CharField(max_length = 100,null= True)
    city              = models.CharField(max_length = 100,null= True)
    state             = models.CharField(max_length = 100,null= True)
    fzip              = models.ForeignKey(Zipcode)
    distance          = models.FloatField()
    status            = models.IntegerField()
    lastvisit         = models.DateField(null = True)
    lastnotification  = models.DateField(null = True)
    notificationcount = models.IntegerField()
    visit             = models.IntegerField()
    sales             = models.IntegerField()
    service           = models.IntegerField()
    last_sales_date   = models.DateField(null= True)
    last_service_date = models.DateField(null= True)
    grossprofit       = models.FloatField()
    invoiced          = models.FloatField()
    carsold           = models.FloatField()
    birth_date        = models.DateField()
    iswarrantyexpiration = models.IntegerField(default=0,null= True)
    isemail           = models.IntegerField(default=0,null= True)
    isleaseexpiration = models.IntegerField(default=0,null= True)
    isbirthday        = models.IntegerField(default=0,null= True)
    isequityposition  = models.IntegerField(default=0,null= True)
    istradecycle      = models.IntegerField(default=0,null= True)
    islateservice     = models.IntegerField(default=0,null= True)
    fdealer           = models.ForeignKey(Dealer,null = True)
    fcampaign         = models.IntegerField(default=0,null= True)
    keyid             = models.CharField(max_length = 100,null= True)
    issms             = models.IntegerField(default=0,null= True)
    flag1             = models.IntegerField(default=0,null= True)
    def __dir__(self):
            return ['barcode','number','fname','lname','email','fmedia','homephone','workphone'
                    'cellphone','address','city','state','fzip','distance','status','lastvisit',
                    'lastnotification','notificationcount','visit','sales','service','last_sales_date',
                    'last_service_date','grossprofit','invoiced','carsold','birth_date','iswarrantyexpiration',
                    'isemail','isleaseexpiration','isbirthday','isequityposition','istradecycle','islateservice',
                    'fdealer','fcampaign','keyid','issms','flag1'
                     
                   ]
class Response_source(models.Model):
    source       = models.CharField(max_length = 100,null= True)
class App_status(models.Model):
    status       = models.CharField(max_length = 100,null= True)    
class Response_type(models.Model):
    type         = models.CharField(max_length = 100,null= True)
class Response_label(models.Model):
    label        = models.CharField(max_length = 100,null= True)
class Customer_buytime(models.Model):
    flag         = models.IntegerField() # This flag is used To indentify If buytime is available
    tag          = models.CharField(max_length = 100,null= True)
    def __dir__(self):
            return ['flag','tag']
class Customer_trade(models.Model):
    year         = models.CharField(max_length = 100,null= True)
    make         = models.CharField(max_length = 100,null= True)
    model        = models.CharField(max_length = 100,null= True)
    mileage      = models.CharField(max_length = 100,null= True)
    book_value   = models.CharField(max_length = 100,null= True)
    payment      = models.CharField(max_length = 100,null= True)
    payoff       = models.CharField(max_length = 100,null= True)
    apr          = models.CharField(max_length = 100,null= True)
    def __dir__(self):
            return ['year','make','model','mileage','book_value','payment','payoff','apr']
class Customer_desired_vehicle(models.Model):
    type         = models.CharField(max_length = 100,null= True)
    style        = models.CharField(max_length = 100,null= True)
    specific     = models.CharField(max_length = 100,null= True)
    downpayment  = models.CharField(max_length = 100,null= True)
    def __dir__(self):
            return ['type','style','specific','downpayment']

class Customer_financial_information(models.Model):
    dob           = models.DateField(null= True)
    ssn           = models.CharField(max_length = 100,null= True)
    employer      = models.CharField(max_length = 100,null= True)
    occupation    = models.CharField(max_length = 100,null= True)
    timeemployed  = models.CharField(max_length = 100,null= True)
    monthlyincome = models.CharField(max_length = 100,null= True)
    housingtype   = models.CharField(max_length = 100,null= True)
    housingcost   = models.CharField(max_length = 100,null= True)
    bk            = models.CharField(max_length = 100,null= True)
    repo          = models.CharField(max_length = 100,null= True)
    dlnumber      = models.CharField(max_length = 100,null= True)
    def __dir__(self):
            return ['dob','ssn','employer','occupation','timeemployed','monthlyincome','housingtype','housingcost',
                    'bk','repo','dlnumber'
                    ]
    
            
class Lead(models.Model):
    barcode                = models.IntegerField()
    fcustomer              = models.ForeignKey(Customer,null = True)
    flabel                 = models.ForeignKey(Response_label,null = True)
    fowner                 = models.ForeignKey(User,null = True)
    ftrade                 = models.ForeignKey(Customer_trade,null = True)
    fbuytime               = models.ForeignKey(Customer_buytime,null = True)
    fdesiredvehicle        = models.ForeignKey(Customer_desired_vehicle,null = True)
    ffinancialinfo         = models.ForeignKey(Customer_financial_information,null = True)
    fdealer                = models.ForeignKey(Dealer,null = True)
    leaddate               = models.DateTimeField(null = True)
    lastactivity           = models.DateTimeField(null = True)
    isnew                  = models.IntegerField()
    isactive               = models.IntegerField()
    keyid                  = models.CharField(max_length = 100,null= True)
    lastresponseid         = models.IntegerField()
    def __dir__(self):
            return ['barcode','fcustomer','flabel','fowner','ftrade','fbuytime','fdesiredvehicle','ffinancialinfo',
                    'fdealer','leaddate','isnew','keyid','isactive','lastactivity','lastresponseid'
                   ] 
class campaign_lead(models.Model):
    flead           = models.ForeignKey(Lead,null = True)
    fcampaign       = models.ForeignKey(Campaign,null = True)
    fdealer         = models.ForeignKey(Dealer,null = True)
    leaddate        = models.DateTimeField(null = True)
    dealerid        = models.IntegerField()
def __dir__(self):
            return ['flead','fcampaign','fdealer','leaddate']    
class Customer_sms(models.Model):
    flead           = models.ForeignKey(Lead,null = True)
    fcustomer       = models.ForeignKey(Customer,null = True)
    fcampaign       = models.ForeignKey(Campaign,null = True)
    fdealer         = models.ForeignKey(Dealer,null = True)
    direction       = models.IntegerField()
    body            = models.CharField(max_length = 100,null= True)
    tophone         = models.CharField(max_length = 20,null= True)
    fromphone       = models.CharField(max_length = 20,null= True)
    media           = models.CharField(max_length = 200,null= True)
    date            = models.DateTimeField(null = True)
    def __dir__(self):
            return ['flead','fcustomer','fcampaign','fdealer','direction','body','tophone',
                    'fromphone','media','date'
                   ]
class Customer_call(models.Model):
    sid               = models.CharField(max_length = 100,null= True)
    tophone           = models.CharField(max_length = 100,null= True)
    fromphone         = models.CharField(max_length = 100,null= True)
    callstatus        = models.CharField(max_length = 100,null= True)
    callduration      = models.CharField(max_length = 100,null= True)
    recordingduration = models.CharField(max_length = 100,null= True)
    recordingurl      = models.CharField(max_length = 200,null= True)
    flead             = models.ForeignKey(Lead,null = True)
    def __dir__(self):
            return ['sid','tophone','fromphone','callstatus','callduration','recordingurl','flead']
class Customer_app(models.Model):
    date              = models.DateField(null = True)
    time              = models.TimeField(null = True)
    datetime          = models.DateTimeField(null = True)
    lastactivity      = models.DateTimeField(null = True)
    fstatus           = models.ForeignKey(App_status,null = True)
    def __dir__(self):
            return ['date','time','datetime','lastactivity','fstatus']
class Response(models.Model):
    barcode        = models.IntegerField()
    flead          = models.ForeignKey(Lead,null = True)
    fcustomer      = models.ForeignKey(Customer,null = True)
    fcampaign      = models.ForeignKey(Campaign,null = True)
    fdealer        = models.ForeignKey(Dealer,null = True)
    fresponsetype  = models.ForeignKey(Response_type,null = True)
    fsource        = models.ForeignKey(Response_source,null = True)
    fcall          = models.ForeignKey(Customer_call,null = True)
    fapp           = models.ForeignKey(Customer_app,null = True)
    responsedate   = models.DateTimeField(null = True)
    flag           = models.IntegerField(null = True)
    keyid          = models.CharField(max_length = 100,null= True)
    ctrigger       = models.IntegerField()
    def __dir__(self):
            return ['barcode','flead','fcustomer','fcampaign','fdealer','fresponsetype','fsource','fcall','fapp',
                    'responsedate','flag','keyid','ctrigger'
                    
                   ]
class Customer_campaign(models.Model):
    fcustomer    = models.ForeignKey(Customer,null = True)  
    fcampaign    = models.ForeignKey(Campaign,null = True)
    def __dir__(self):
            return ['fcustomer','fcampaign']
class Response_regular_lead_count(models.Model):
    lead           = models.IntegerField(null = True)
    phone          = models.IntegerField(null = True)
    web            = models.IntegerField(null = True)
    sms            = models.IntegerField(null = True)
    fcampaign      = models.ForeignKey(Campaign,null = True) 
    fdealer        = models.ForeignKey(Dealer,null = True)
    date           = models.DateField(null = True)
    def __dir__(self):
            return ['lead','phone','web','sms','fcampaign','fdealer','date'
                   ]              
class Campaign_lead_count(models.Model):
    lead           = models.IntegerField(null = True)
    phone          = models.IntegerField(null = True)
    web            = models.IntegerField(null = True)
    sms            = models.IntegerField(null = True)  
    fcampaign      = models.ForeignKey(Campaign,null = True)
    fdealer        = models.ForeignKey(Dealer,null = True) 
    def __dir__(self):
            return ['lead','phone','web','sms','fcampaign','fdealer']
class Campaign_label_count(models.Model):
    hot            = models.IntegerField(null = True)
    cold           = models.IntegerField(null = True)
    sold           = models.IntegerField(null = True)
    warm           = models.IntegerField(null = True)
    folloup        = models.IntegerField(null = True)
    dead           = models.IntegerField(null = True)  
    fcampaign      = models.ForeignKey(Campaign,null = True)
    fdealer        = models.ForeignKey(Dealer,null = True)
    def __dir__(self):
            return ['hot','cold','sold','warm','folloup','dead','fcampaign','fdealer']        
        
class Raw_sales(models.Model):
    acdealerid = models.CharField(max_length=30,null = True)
    dmstype = models.CharField(max_length=100,null = True) 
    dealnumber = models.CharField(max_length=20,null = True)
    customernumber = models.CharField(max_length=50,null = True)
    customername = models.CharField(max_length=100,null = True)
    customerfirstname = models.CharField(max_length=100,null = True)
    customerlastname = models.CharField(max_length=100,null = True)
    customeraddress = models.CharField(max_length=100,null = True)
    customercity = models.CharField(max_length=100,null = True)
    customerstate = models.CharField(max_length=100,null = True)
    customerzip = models.CharField(max_length=100,null = True)
    customercounty = models.CharField(max_length=100,null = True)
    customerhomephone = models.CharField(max_length=100,null = True)
    customerworkphone = models.CharField(max_length=100,null = True)
    customercellphone = models.CharField(max_length=100,null = True)
    customerpagerphone = models.CharField(max_length=100,null = True)
    customeremail = models.CharField(max_length=100,null = True)
    customerbirthdate = models.DateField(null = True)
    mailblock = models.CharField(max_length=100,null = True)
    cobuyername = models.CharField(max_length=100,null = True)
    cobuyerfirstname = models.CharField(max_length=100,null = True)
    cobuyerlastname = models.CharField(max_length=100,null = True)
    cobuyeraddress = models.CharField(max_length=100,null = True)
    cobuyercity = models.CharField(max_length=100,null = True)
    cobuyerstate = models.CharField(max_length=100,null = True)
    cobuyerzip = models.CharField(max_length=100,null = True)
    cobuyercounty = models.CharField(max_length=100,null = True)
    cobuyerhomephone = models.CharField(max_length=100,null = True)
    cobuyerworkphone = models.CharField(max_length=100,null = True)
    cobuyerbirthdate = models.DateField(null = True)
    salesman_1_number = models.CharField(max_length=100,null = True)
    salesman_1_name = models.CharField(max_length=100,null = True)
    salesman_2_number = models.CharField(max_length=100,null = True)
    salesman_2_name = models.CharField(max_length=100,null = True) 
    closingmanagername = models.CharField(max_length=100,null = True)
    closingmanagernumber = models.CharField(max_length=100,null = True)
    f_and_i_managernumber = models.CharField(max_length=100,null = True)
    f_and_i_managername = models.CharField(max_length=100,null = True)
    salesmanagernumber = models.CharField(max_length=100,null = True)
    salesmanagername = models.CharField(max_length=100,null = True)
    entrydate = models.DateField(null = True)
    dealbookdate = models.DateField(null = True)
    vehicleyear = models.IntegerField(null = True)
    vehiclemake = models.CharField(max_length=100,null = True)
    vehiclemodel = models.CharField(max_length=100,null = True)
    vehiclestocknumber = models.CharField(max_length=100,null = True)
    vehiclevin = models.CharField(max_length=100,null = True)
    vehicleexteriorcolor = models.CharField(max_length=100,null = True)
    vehicleinteriorcolor = models.CharField(max_length=100,null = True)
    vehiclemileage = models.IntegerField(null = True)
    vehicletype = models.CharField(max_length=100,null = True)
    inservicedate = models.DateField(null = True)
    holdbackamount = models.FloatField(default = 0.00,null= True)
    dealtype = models.CharField(max_length=100,null = True)
    saletype = models.CharField(max_length=100,null = True)
    bankcode = models.CharField(max_length=100,null = True)
    bankname = models.CharField(max_length=100,null = True)
    salesmancommission = models.FloatField(default = 0.00,null= True)
    grossprofitsale = models.FloatField(default = 0.00,null= True)
    financereserve = models.FloatField(default = 0.00,null= True)
    creditlifepremium = models.CharField(max_length=100,null = True)
    creditlifecommision = models.CharField(max_length=100,null = True)
    totalinsurancereserve = models.FloatField(default = 0.00,null= True)
    balloonamount = models.FloatField(default = 0.00,null= True)
    cashprice = models.FloatField(default = 0.00,null= True)
    amountfinanced = models.FloatField(default = 0.00,null= True)
    totalofpayments = models.FloatField(default = 0.00,null= True)
    msrp = models.CharField(max_length=100,null = True)
    downpayment = models.FloatField(default = 0.00,null= True)
    securitydesposit = models.FloatField(default = 0.00,null= True)
    rebate = models.FloatField(default = 0.00,null= True)
    term = models.IntegerField(null = True)
    retailpayment = models.FloatField(default = 0.00,null= True)
    paymenttype = models.CharField(max_length=10,null = True)
    retailfirstpaydate = models.DateField(null = True)
    leasefirstpaydate = models.DateField(null = True)
    daytofirstpayment = models.IntegerField(null = True)
    leaseannualmiles = models.IntegerField(null = True)
    mileagerate = models.FloatField(default = 0.00,null= True)
    aprrate = models.FloatField(default = 0.00,null= True)
    residualamount = models.FloatField(default = 0.00,null= True)
    licensefee = models.FloatField(default = 0.00,null= True)
    registrationfee = models.FloatField(default = 0.00,null= True)
    totaltax = models.FloatField(default = 0.00,null= True)
    extendedwarrantyname = models.CharField(max_length=100,null = True)
    extendedwarrantyterm = models.IntegerField(null = True)
    extendedwarrantylimitmiles = models.IntegerField(null = True)
    extendedwarrantydollar = models.FloatField(default = 0.00,null= True)
    extendedwarrantyprofit = models.FloatField(default = 0.00,null= True)
    frontgross = models.FloatField(default = 0.00,null= True)
    backgross = models.FloatField(default = 0.00,null= True)
    tradein_1_vin = models.CharField(max_length=100,null = True)
    tradein_2_vin = models.CharField(max_length=100,null = True)
    tradein_1_make = models.CharField(max_length=100,null = True)
    tradein_2_make = models.CharField(max_length=100,null = True)
    tradein_1_model = models.CharField(max_length=100,null = True)
    tradein_2_model = models.CharField(max_length=100,null = True)
    tradein_1_exteriorcolor = models.CharField(max_length=100,null = True)
    tradein_2_exteriorcolor = models.CharField(max_length=100,null = True)
    tradein_1_year = models.IntegerField(null = True)
    tradein_2_year = models.IntegerField(null = True)
    tradein_1_mileage = models.IntegerField(null = True)
    tradein_2_mileage = models.IntegerField(null = True)
    tradein_1_gross = models.FloatField(default = 0.00,null= True)
    tradein_2_gross = models.FloatField(default = 0.00,null= True)
    tradein_1_payoff = models.FloatField(default = 0.00,null= True)
    tradein_2_payoff = models.FloatField(default = 0.00,null= True)
    tradein_1_acv = models.FloatField(default = 0.00,null= True)
    tradein_2_acv = models.FloatField(default = 0.00,null= True)
    fee_1_name = models.CharField(max_length=100,null = True)
    fee_1_fee = models.CharField(max_length=100,null = True)
    fee_1_commission = models.CharField(max_length=100,null = True)
    fee_2_name = models.CharField(max_length=100,null = True)
    fee_2_fee = models.CharField(max_length=100,null = True)
    fee_2_commission = models.CharField(max_length=100,null = True)
    fee_3_name = models.CharField(max_length=100,null = True)
    fee_3_fee = models.CharField(max_length=100,null = True)
    fee_3_commission = models.CharField(max_length=100,null = True)
    fee_4_name = models.CharField(max_length=100,null = True)
    fee_4_fee = models.CharField(max_length=100,null = True)
    fee_4_commission = models.CharField(max_length=100,null = True)
    fee_5_name = models.CharField(max_length=100,null = True)
    fee_5_fee = models.CharField(max_length=100,null = True)
    fee_5_commission = models.CharField(max_length=100,null = True)
    fee_6_name = models.CharField(max_length=100,null = True)
    fee_6_fee = models.CharField(max_length=100,null = True)
    fee_6_commission = models.CharField(max_length=100,null = True)
    fee_7_name = models.CharField(max_length=100,null = True)
    fee_7_fee = models.CharField(max_length=100,null = True)
    fee_7_commission = models.CharField(max_length=100,null = True)
    fee_8_name = models.CharField(max_length=100,null = True)
    fee_8_fee = models.CharField(max_length=100,null = True)
    fee_8_commission = models.CharField(max_length=100,null = True)
    fee_9_name = models.CharField(max_length=100,null = True)
    fee_9_fee = models.CharField(max_length=100,null = True)
    fee_9_commission = models.CharField(max_length=100,null = True)
    fee_10_name = models.CharField(max_length=100,null = True)
    fee_10_fee = models.CharField(max_length=100,null = True)
    fee_10_commission = models.CharField(max_length=100,null = True)
    contractdate = models.DateField(null = True)
    insurancename = models.CharField(max_length=100,null = True)
    insuranceagentname = models.CharField(max_length=100,null = True)
    insuranceaddress = models.CharField(max_length=100,null = True)
    insurancecity = models.CharField(max_length=100,null = True)
    insurancestate = models.CharField(max_length=100,null = True)
    insurancezip = models.CharField(max_length=100,null = True)
    insurancephone = models.CharField(max_length=100,null = True)
    insurancepolicynumber = models.CharField(max_length=100,null = True)
    insuranceeffectivedate = models.DateField(null = True)
    insuranceexpirationdate = models.DateField(null = True)
    insurancecompensationdeduction = models.CharField(max_length=100,null = True)
    tradein_1_interiorcolor = models.CharField(max_length=100,null = True)
    tradein_2_interiorcolor = models.CharField(max_length=100,null = True)
    phoneblock = models.CharField(max_length=100,null = True)
    licenseplatenumber = models.CharField(max_length=100,null = True)
    cost = models.FloatField(default = 0.00,null= True)
    invoiceamount = models.FloatField(default = 0.00,null= True)
    financecharge = models.FloatField(default = 0.00,null= True)
    totalpickuppayment = models.FloatField(default = 0.00,null= True)
    totalaccessories = models.CharField(max_length=100,null = True)
    totaldriveoffamount = models.FloatField(default = 0.00,null= True)
    emailblock = models.CharField(max_length=10,null = True)
    modeldescriptionofcarsold = models.CharField(max_length=50,null = True)
    vehicleclassification = models.CharField(max_length=100,null = True)
    modelnumberofcarsold = models.CharField(max_length=100,null = True)
    gappremium = models.FloatField(default = 0.00,null= True)
    lastinstallmentdate = models.DateField(null = True)
    cashdeposit = models.FloatField(default = 0.00,null= True)
    ahpremium = models.CharField(max_length=100,null = True)
    leaserate = models.FloatField(default = 0.00,null= True)
    dealerselect = models.CharField(max_length=100,null = True)
    leasepayment = models.FloatField(default = 0.00,null= True)
    leasenetcapcost = models.FloatField(default = 0.00,null= True)
    leasetotalcapreduction = models.FloatField(default = 0.00,null= True)
    dealstatus = models.CharField(max_length=100,null = True)
    customersuffix = models.CharField(max_length=100,null = True)
    customersalutation = models.CharField(max_length=100,null = True)
    customeraddress2 = models.CharField(max_length=100,null = True)
    customermiddlename = models.CharField(max_length=100,null = True)
    globaloptout = models.CharField(max_length=100,null = True)
    leaseterm = models.CharField(max_length=100,null = True)
    extendedwarrantyflag = models.IntegerField(null = True)
    salesman_3_number = models.CharField(max_length=100,null = True)
    salesman_3_name = models.CharField(max_length=100,null = True)
    salesman_4_number = models.CharField(max_length=100,null = True)
    salesman_4_name = models.CharField(max_length=100,null = True)
    salesman_5_number = models.CharField(max_length=100,null = True)
    salesman_5_name = models.CharField(max_length=100,null = True)
    salesman_6_number = models.CharField(max_length=100,null = True)
    salesman_6_name = models.CharField(max_length=100,null = True)
    aprrate2 = models.FloatField(default = 0.00,null= True)
    aprrate3 = models.FloatField(default = 0.00,null= True)
    aprrate4 = models.FloatField(default = 0.00,null= True)
    term2 = models.FloatField(default = 0.00,null= True)
    securitydeposit2 = models.FloatField(default = 0.00,null= True)
    downpayment2 = models.FloatField(default = 0.00,null= True)
    totalofpayments2 = models.FloatField(default = 0.00,null= True)
    basepayment = models.FloatField(default = 0.00,null= True)
    journalsaleamount = models.FloatField(default = 0.00,null= True)
    individualbusinessflag = models.CharField(max_length=10,null = True)
    inventorydate = models.DateField(null = True)
    statusdate = models.DateField(null = True)
    listprice = models.FloatField(default = 0.00,null= True)
    nettradeamount = models.FloatField(default = 0.00,null= True)
    trimlevel = models.CharField(max_length=100,null = True)
    subtrimlevel = models.CharField(max_length=100,null = True)
    bodydescription = models.CharField(max_length=100,null = True)
    bodydoorcount = models.CharField(max_length=100,null = True)
    transmissiondesc = models.CharField(max_length=100,null = True)
    enginedesc = models.CharField(max_length=100,null = True)
    typecode = models.CharField(max_length=100,null = True)
    slct2 = models.CharField(max_length=100,null = True)
    dealdateoffset = models.DateField(null = True)
    accountingdate = models.DateField(null = True)
    cobuyercustnum = models.IntegerField(null = True)
    cobuyercell = models.CharField(max_length=100,null = True)
    cobuyeremail = models.CharField(max_length=100,null = True)
    cobuyersalutation = models.CharField(max_length=100,null = True)
    cobuyerphoneblock = models.CharField(max_length=100,null = True)
    cobuyermailblock = models.CharField(max_length=100,null = True)
    cobuyeremailblock = models.CharField(max_length=100,null = True)
    realbookdate = models.DateField(null = True)
    cobuyermiddlename = models.CharField(max_length=100,null = True)
    cobuyercountry = models.CharField(max_length=100,null = True)
    cobuyeraddress2 = models.CharField(max_length=100,null = True)
    cobuyeroptout = models.CharField(max_length=100,null = True)
    cobuyeroccupation = models.CharField(max_length=100,null = True)
    cobuyeremployer = models.CharField(max_length=100,null = True)
    country = models.CharField(max_length=100,null = True)
    occupation = models.CharField(max_length=100,null = True)
    employer = models.CharField(max_length=100,null = True)
    salesman2commission = models.CharField(max_length=100,null = True)
    bankaddress = models.CharField(max_length=100,null = True)
    bankcity = models.CharField(max_length=100,null = True)
    bankstate = models.CharField(max_length=100,null = True)
    bankzip = models.CharField(max_length=100,null = True)
    leaseestimatedmiles = models.IntegerField(null = True)
    aftreserve = models.FloatField(default = 0.00,null= True)
    creditlifeprem = models.FloatField(default = 0.00,null= True)
    creditliferes = models.FloatField(default = 0.00,null= True)
    ahres = models.FloatField(default = 0.00,null= True)
    language = models.CharField(max_length=100,null = True)
    buyrate = models.FloatField(default = 0.00,null= True)
    dmvamount = models.FloatField(default = 0.00,null= True)
    weight = models.CharField(max_length=100,null = True)
    statedmvtotfee = models.FloatField(default = 0.00)
    rosnumber = models.CharField(max_length=100,null = True)
    incentives = models.CharField(max_length=100,null = True)
    cass_std_line1 = models.CharField(max_length=100,null = True)
    cass_std_line2 = models.CharField(max_length=100,null = True)
    cass_std_city = models.CharField(max_length=100,null = True)
    cass_std_state = models.CharField(max_length=100,null = True)
    cass_std_zip = models.CharField(max_length=100,null = True)
    cass_std_zip4 = models.CharField(max_length=100,null = True)
    cass_std_dpbc = models.IntegerField(null = True)
    cass_std_chkdgt = models.IntegerField(null = True)
    cass_std_cart = models.CharField(max_length=100,null = True)
    cass_std_lot = models.CharField(max_length=100,null = True)
    cass_std_lotord = models.CharField(max_length=100,null = True)
    cass_std_urb = models.CharField(max_length=100,null = True)
    cass_std_fips = models.CharField(max_length=100,null = True)
    cass_std_ews = models.CharField(max_length=100,null = True)
    cass_std_lacs = models.CharField(max_length=100,null = True)
    cass_std_zipmov = models.CharField(max_length=100,null = True) 
    cass_std_z4lom = models.CharField(max_length=100,null = True)
    cass_std_ndiapt = models.CharField(max_length=100,null = True)
    cass_std_ndirr = models.CharField(max_length=100,null = True)
    cass_std_lacsrt = models.CharField(max_length=100,null = True)
    cass_std_error_cd = models.CharField(max_length=100,null = True)
    ncoa_ac_id = models.IntegerField(null= True)
    dealerid = models.CharField(max_length=100,null=True)
    filename = models.CharField(max_length=200,null = True)
    flag1 = models.IntegerField(default=0,null= True)
    flag2 = models.IntegerField(default=0,null= True)
    flag3 = models.IntegerField(default=0,null= True)
    flag4 = models.IntegerField(default=0,null= True)
    def getgross(self):
        return self.backgross + self.frontgross

class Raw_service(models.Model):
    acdealerid = models.CharField(max_length=30,null = True)     
    dmstype = models.CharField(max_length=100,null = True) 
    ronumber = models.CharField(max_length=100,null = True)
    opendate = models.DateField(null = True)
    customernumber = models.CharField(max_length=50,null = True)
    customername = models.CharField(max_length=100,null = True)
    customerfirstname = models.CharField(max_length=100,null = True)
    customerlastname = models.CharField(max_length=100,null = True)
    customeraddress = models.CharField(max_length=100,null = True)
    customercity = models.CharField(max_length=100,null = True)
    customerstate = models.CharField(max_length=100,null = True)
    customerzip = models.CharField(max_length=10,null = True)
    customerhomephone = models.CharField(max_length=20,null = True)
    customerworkphone = models.CharField(max_length=20,null = True)
    customercellphone = models.CharField(max_length=20,null = True)
    customeremail = models.CharField(max_length=100,null = True)
    customerbirthdate = models.CharField(max_length=100,null = True)
    vehiclemileage = models.CharField(max_length=100,null = True)
    vehicleyear = models.CharField(max_length=100,null = True)
    vehiclemake = models.CharField(max_length=100,null = True)
    vehiclemodel = models.CharField(max_length=100,null = True)
    vehiclevin = models.CharField(max_length=100,null = True)
    serviceadvisornumber = models.CharField(max_length=100,null = True)
    serviceadvisorname = models.CharField(max_length=100,null = True)
    technicianname = models.CharField(max_length=100,null = True)
    techniciannumber = models.CharField(max_length=100,null = True)
    deliverydate = models.DateField(null = True)
    operationcode = models.CharField(max_length=100,null = True)
    operationdescription = models.CharField(max_length=100,null = True)
    roamount = models.FloatField(null = True,default = 0)
    warrantyname = models.CharField(max_length=100,null = True)
    warrantyexpirationdate = models.DateField(null = True)
    warrantyexpirationmiles = models.CharField(max_length=100,null = True)
    salesmannumber = models.CharField(max_length=100,null = True)
    salesmanname = models.CharField(max_length=100,null = True)
    closeddate = models.DateField(null = True)
    labortypes = models.CharField(max_length=100,null = True)
    warrantylaboramount = models.FloatField(null = True,default = 0)
    warrantypartjobsale = models.FloatField(null = True,default = 0)
    warrantymiscamount = models.FloatField(null = True,default = 0)
    warrantyrepairordertotal = models.FloatField(null = True,default = 0)
    internallaborsale = models.FloatField(null = True,default = 0)
    internalpartssale = models.FloatField(null = True,default = 0)
    internalmiscamount = models.FloatField(null = True,default = 0)
    internalrepairordertotal = models.FloatField(null = True,default = 0)
    customerpaylaboramount = models.FloatField(null = True,default = 0)
    customerpaypartssale = models.FloatField(null = True,default = 0)
    customerpaymiscsale = models.FloatField(null = True,default = 0)
    customerpayrepairordertotal = models.FloatField(null = True,default = 0)
    laborcostdollar = models.FloatField(null = True,default = 0)
    partscostdollar = models.FloatField(null = True,default = 0)
    misccostdollar = models.FloatField(null = True,default = 0)
    miscdollar = models.FloatField(null = True,default = 0)
    labordollar = models.FloatField(null = True,default = 0)
    partsdollar = models.FloatField(null = True,default = 0)
    vehiclecolor = models.CharField(max_length=100,null = True)
    customerpaypartscost = models.FloatField(null = True,default = 0)
    customerpaylaborcost = models.FloatField(null = True,default = 0)
    customerpaygogcost = models.FloatField(null = True,default = 0)
    customerpaysubletcost = models.FloatField(null = True,default = 0)
    customerpaymisccost = models.FloatField(null = True,default = 0)
    warrantypartscost = models.FloatField(null = True,default = 0)
    warrantylaborcost = models.FloatField(null = True,default = 0)
    warrantygogcost = models.FloatField(null = True,default = 0)
    warrantysubletcost = models.FloatField(null = True,default = 0)
    warrantymisccost = models.FloatField(null = True,default = 0)
    internalpartscost = models.FloatField(null = True,default = 0)
    internallaborcost = models.FloatField(null = True,default = 0)
    internalgogcost = models.FloatField(null = True,default = 0)
    internalsubletcost = models.FloatField(null = True,default = 0)
    internalmisccost = models.FloatField(null = True,default = 0)
    totaltax = models.FloatField(null = True,default = 0)
    totallaborhours = models.FloatField(null = True,default = 0)
    totalbillhours = models.FloatField(null = True,default = 0)
    servicecomment = models.TextField(null = True)
    laborcomplaint = models.TextField(null = True)
    laborbillingrate = models.FloatField(null = True)
    labortechnicianrate = models.CharField(max_length=100,null = True)
    appointmentflag = models.CharField(max_length=10,null = True)
    mailblock = models.CharField(max_length=100,null = True)
    emailblock = models.CharField(max_length=100,null = True)
    phoneblock = models.CharField(max_length=100,null = True)
    roinvoicedate = models.DateField(null = True)
    rocustomerpaypostdate = models.DateField(null = True)
    rostatus = models.CharField(max_length=100,null = True)
    mechanicnumber = models.CharField(max_length=100,null = True)
    romileage = models.CharField(max_length=100,null = True)
    deliverymileage = models.CharField(max_length=100,null = True)
    stocknumber = models.CharField(max_length=100,null = True)
    recommendedservice = models.CharField(max_length=100,null = True)
    recommendations = models.CharField(max_length=100,null = True)
    customersuffix = models.CharField(max_length=100,null = True)
    customersalutation = models.CharField(max_length=100,null = True)
    customeraddress2 = models.CharField(max_length=100,null = True)
    customermiddlename = models.CharField(max_length=100,null = True)
    globaloptout = models.CharField(max_length=100,null = True)
    promisedate = models.DateField(null = True)
    promisetime = models.CharField(max_length=100,null = True)
    rologon = models.CharField(max_length=100,null = True)
    labortypes2 = models.CharField(max_length=100,null = True)
    languagepreference = models.CharField(max_length=100,null = True)
    misccode = models.CharField(max_length=100,null = True)
    misccodeamount = models.FloatField(null = True)
    partnumber = models.CharField(max_length=100,null = True)
    partdescription = models.CharField(max_length=100,null = True)
    partquantity = models.CharField(max_length=100,null = True)
    misccodedescription = models.CharField(max_length=100,null = True)
    makeprefix = models.CharField(max_length=100,null = True)
    department = models.CharField(max_length=100,null = True)
    rototalcost = models.FloatField(null= True)
    pipedcomplaint = models.CharField(max_length=100,null = True)
    pipedcomment = models.TextField(null = True)
    mileageout = models.CharField(max_length=100,null = True)
    individualbusinessflag = models.CharField(max_length=100,null = True)
    custgogsale = models.FloatField(null = True)
    laborhours = models.CharField(max_length=100,null = True)
    billinghours = models.CharField(max_length=100,null = True)
    tagno = models.CharField(max_length=100,null = True)
    stocktype = models.CharField(max_length=100,null = True)
    roopentime = models.CharField(max_length=100,null = True)
    custsubsale = models.FloatField(null = True,default = 0)
    warrgogsale = models.FloatField(null = True,default = 0)
    warrsubsale = models.FloatField(null = True,default = 0)
    intlgogsale = models.FloatField(null = True,default = 0)
    intlsubsale = models.FloatField(null = True,default = 0)
    totalgogcost = models.FloatField(null = True,default = 0)
    totalgogsale = models.FloatField(null = True,default = 0)
    totalsubcost = models.FloatField(null = True,default = 0)
    totalsubsale = models.FloatField(null = True,default = 0)
    model = models.CharField(max_length=100,null = True)
    transmission = models.CharField(max_length=100,null = True)
    engineconfig = models.CharField(max_length=100,null = True)
    trimlevel = models.CharField(max_length=100,null = True)
    paymentmethod = models.CharField(max_length=100,null = True)
    pickupdate = models.DateField(null = True)
    custgender = models.CharField(max_length=100,null = True)
    jobstatus = models.CharField(max_length=100,null = True)
    cass_std_line1 = models.CharField(max_length=100,null = True)
    cass_std_line2 = models.CharField(max_length=100,null = True)
    cass_std_city = models.CharField(max_length=100,null = True)
    cass_std_state = models.CharField(max_length=100,null = True)
    cass_std_zip = models.CharField(max_length=100,null = True)
    cass_std_zip4 = models.CharField(max_length=100,null = True)
    cass_std_dpbc = models.CharField(max_length=100,null = True)
    cass_std_chkdgt = models.CharField(max_length=100,null = True)
    cass_std_cart = models.CharField(max_length=100,null = True)
    cass_std_lot = models.CharField(max_length=100,null = True)
    cass_std_lotord = models.CharField(max_length=100,null = True)
    cass_std_urb = models.CharField(max_length=100,null = True)
    cass_std_fips = models.CharField(max_length=100,null = True)
    cass_std_ews = models.CharField(max_length=100,null = True)
    cass_std_lacs = models.CharField(max_length=100,null = True)
    cass_std_zipmov = models.CharField(max_length=100,null = True)
    cass_std_z4lom = models.CharField(max_length=100,null = True)
    cass_std_ndiapt = models.CharField(max_length=100,null = True)
    cass_std_ndirr = models.CharField(max_length=100,null = True)
    cass_std_lacsrt = models.CharField(max_length=100,null = True)
    cass_std_error_cd = models.CharField(max_length=100,null = True)
    ncoa_ac_id = models.CharField(max_length=100,null = True)
    dealerid = models.CharField(max_length=100,null=True)
    filename = models.CharField(max_length=200,null = True)
    flag1 = models.IntegerField(default=0,null= True)
    flag2 = models.IntegerField(default=0,null= True)
    flag3 = models.IntegerField(default=0,null= True)
    flag4 = models.IntegerField(default=0,null= True)
    def getwarranty(self):
        lst = []
        lst.append(self.warrantysubletcost)
        lst.append(self.warrantyrepairordertotal)
        lst.append(self.warrantypartscost)
        lst.append(self.warrantymisccost)
        lst.append(self.warrantylaborcost)
        lst.append(self.warrantygogcost)
        return float(commonfunction().addmodalfiled(lst))
         
    def getcustomerpay(self):
        lst = []
        lst.append(self.customerpaygogcost)
        lst.append(self.customerpaylaborcost)
        lst.append(self.customerpaymisccost)
        lst.append(self.customerpaypartscost)
        return float(commonfunction().addmodalfiled(lst)) 
        
class Customer_roi(models.Model):
    type                    = models.IntegerField()    
    entrydate               = models.DateField()
    warrantyexpiration      = models.DateField()
    leaseexpiration         = models.DateField()
    grossprofit             = models.FloatField()
    invoiced                = models.FloatField()
    carsold                 = models.FloatField()
    sales_delay             = models.IntegerField()
    service_delay           = models.IntegerField()
    delay                   = models.IntegerField()
    year                    = models.IntegerField(null = True)
    make                    = models.CharField(max_length=100,null = True)
    model                   = models.CharField(max_length=100,null = True)
    mileage                 = models.IntegerField(null = True)
    tyear                   = models.IntegerField(null = True)
    tmake                   = models.CharField(max_length=100,null = True)
    tmodel                  = models.CharField(max_length=100,null = True)
    tmileage                = models.IntegerField(null = True)
    istradein               = models.IntegerField(null = True)
    fsales                  = models.ForeignKey(Raw_sales,null = True)
    fservice                = models.ForeignKey(Raw_service,null = True)
    fcustomer               = models.ForeignKey(Customer,null = True)
    fdealer                 = models.ForeignKey(Dealer,null = True) 
    iswarrantyexpiration    = models.IntegerField(null = True)
    isleaseexpiration       = models.IntegerField(null = True)
class Campaign_roi_match(models.Model):
    type                    = models.IntegerField()    
    entrydate               = models.DateField()
    warrantyexpiration      = models.DateField()
    leaseexpiration         = models.DateField()
    grossprofit             = models.FloatField()
    invoiced                = models.FloatField()
    carsold                 = models.FloatField()
    sales_delay             = models.IntegerField()
    service_delay           = models.IntegerField()
    delay                   = models.IntegerField()
    year                    = models.IntegerField(null = True)
    make                    = models.CharField(max_length=100,null = True)
    model                   = models.CharField(max_length=100,null = True)
    mileage                 = models.IntegerField(null = True)
    tyear                   = models.IntegerField(null = True)
    tmake                   = models.CharField(max_length=100,null = True)
    tmodel                  = models.CharField(max_length=100,null = True)
    tmileage                = models.IntegerField(null = True)
    istradein               = models.IntegerField(null = True)
    fsales                  = models.ForeignKey(Raw_sales,null = True)
    fservice                = models.ForeignKey(Raw_service,null = True)
    fcustomer               = models.ForeignKey(Customer,null = True)
    fdealer                 = models.ForeignKey(Dealer,null = True)
    fcampaign               = models.ForeignKey(Campaign,null = True)
class City(models.Model):
    city                    = models.CharField(max_length=100,null = True)          
               