def post(self):
        self.response.out.write("added <br />")
        user = users.get_current_user()
        
        #See if the user choose to upload a payslip or other
        if self.request.POST['type'] == "payslip":

            self.response.out.write("payslip <br />")
            
            payslip = Models.Payslip(parent=Models.payslip_key(user.user_id()))
             
            #Set the model attributes 
            payslip.ownerId = user.user_id()
            payslip.beginning = datetime.datetime.strptime(self.request.POST['beginning'],'%Y-%m-%d').date()
            payslip.ending = datetime.datetime.strptime(self.request.POST['ending'],'%Y-%m-%d').date()
            payslip.income = float(self.request.POST['income'])
            payslip.tax = float(self.request.POST['tax'])
            payslip.net = float(self.request.POST['income']) - float(self.request.POST['tax'])
            payslip.company = self.request.POST['company']
            
            #Output the given form to the confirmation page
            self.response.out.write(payslip.ownerId + "<br/>" )
            self.response.out.write(str(payslip.upload_date) + "<br/>")
            self.response.out.write(str(payslip.beginning) + "<br/>")
            self.response.out.write(str(payslip.ending) + "<br/>")
            self.response.out.write(str(payslip.income) + "<br/>")
            self.response.out.write(str(payslip.tax) + "<br/>")
            self.response.out.write(str(payslip.net) + "<br/>")
            self.response.out.write(str(payslip.company) + "<br/>")
            
            #add the model to the data store
            payslip.put()                         
             
        else:
            self.response.out.write("other <br />")
            
            file = Models.File(parent=Models.file_key(user.user_id()))
            
            #Set the model attributes 
            file.ownerId = user.user_id()
            file.title = self.request.POST['title']
            file.description = self.request.POST['description']
            
            #Output the given form to the confirmation page
            self.response.out.write( file.ownerId + "<br/>" )
            self.response.out.write(file.title + "<br/>")
            self.response.out.write(file.description + "<br/>")
            
            #add the model to the data store
            file.put()
Beispiel #2
0
    def get(self):
        if users.get_current_user():
            # GQL query to get the payslips from the datastore
            payslips = db.GqlQuery(
                "SELECT * " "FROM Payslip " "WHERE ANCESTOR IS :1 ",
                Models.payslip_key(users.get_current_user().user_id()),
            )

            list1 = [0, 0, 0, 0]
            list2 = [0, 0, 0, 0]

            # Set the list to the first 4 payslips income and tax for the graph
            index = 0
            for payslip in payslips:
                if index >= 4:
                    break
                list1[index] = payslip.income
                list2[index] = payslip.tax
                index += 1

            # set specific stylesheets and scripts needed per page
            # set the values for the graph
            specific_urls = (
                """
                <link type="text/css" rel="stylesheet" href="/stylesheets/"""
                + self.__class__.__name__
                + """.css" />
                <script type="text/javascript" src="https://www.google.com/jsapi"></script>
                <script type="text/javascript">
                  google.load("visualization", "1", {packages:["corechart"]});
                  google.setOnLoadCallback(drawChart);
                  function drawChart() {
                    var data = google.visualization.arrayToDataTable([
                      ['Payslip', 'Income', 'Tax'],
                      ['1',  """
                + str(list1[0])
                + """,      """
                + str(list2[0])
                + """],
                      ['2',  """
                + str(list1[1])
                + """,      """
                + str(list2[1])
                + """],
                      ['3',  """
                + str(list1[2])
                + """,      """
                + str(list2[2])
                + """],
                      ['4',  """
                + str(list1[3])
                + """,      """
                + str(list2[3])
                + """]
                    ]);
            
                    var options = {
                      title: 'Income Breakdown',
    
                    };
            
                    var chart = new google.visualization.AreaChart(document.getElementById('chart-div'));
                    chart.draw(data, options);
                  }
                </script>
            """
            )

            # Set the nested template values to the generate payslip function
            payslip_template_values = {"payslips": generate_payslip_html(self, payslips)}

            template = jinja_environment.get_template("Page_Content/payslips.html")
            payslip_template = template.render(payslip_template_values)

            myFile = open("Page_Content/payslips.html", "r")

            # Create a log out url for the user
            url = users.create_logout_url(self.request.uri)
            # set the nav list
            nav = (
                """
            <nav>
                <ul>
                    <li><a href="/dashboard">Dashboard</a></li>
                    <li><a href="/design">Design</a></li>
                    <li><a href="/about">About</a></li>
                    <li><a href="%s">Logout</a></li>
                </ul>
            </nav>
            """
                % url
            )

            template_values = {"specific_urls": specific_urls, "nav": nav, "content": payslip_template}

            template = jinja_environment.get_template("index.html")
            self.response.out.write(template.render(template_values))
        else:
            self.redirect("/")
Beispiel #3
0
    def post(self):
        self.response.out.write("added <br />")
        user = users.get_current_user()
        
        #See if the user choose to upload a payslip or other
        if self.request.POST['type'] == "payslip":

            self.response.out.write("payslip <br />")
            
            payslip = Models.Payslip(parent=Models.payslip_key(user.user_id()))
             
            #Set the model attributes 
            payslip.ownerId = user.user_id()
            payslip.beginning = datetime.datetime.strptime(self.request.POST['beginning'],'%Y-%m-%d').date()
            payslip.ending = datetime.datetime.strptime(self.request.POST['ending'],'%Y-%m-%d').date()
            payslip.income = float(self.request.POST['income'])
            payslip.tax = float(self.request.POST['tax'])
            payslip.net = float(self.request.POST['income']) - float(self.request.POST['tax'])
            payslip.company = self.request.POST['company']
            
            # Create the file
            file_name = files.blobstore.create(mime_type='application/octet-stream')
           
            
            # Open the file and write to it
            with files.open(file_name, 'a') as f:
                f.write("data")
            
            # Finalize the file. Do this before attempting to read it.
            files.finalize(file_name)
            
            # Get the file's blob key
            payslip.file_key = files.blobstore.get_blob_key(file_name)
            
            #Output the given form to the confirmation page
            self.response.out.write(payslip.ownerId + "<br/>" )
            self.response.out.write(str(payslip.upload_date) + "<br/>")
            self.response.out.write(str(payslip.beginning) + "<br/>")
            self.response.out.write(str(payslip.ending) + "<br/>")
            self.response.out.write(str(payslip.income) + "<br/>")
            self.response.out.write(str(payslip.tax) + "<br/>")
            self.response.out.write(str(payslip.net) + "<br/>")
            self.response.out.write(str(payslip.company) + "<br/>")
            
            #add the model to the data store
            payslip.put()             
            self.redirect('/payslips')
           
             
        else:
            self.response.out.write("other <br />")
            
            file = Models.File(parent=Models.file_key(user.user_id()))
            
            #Set the model attributes 
            file.ownerId = user.user_id()
            file.title = self.request.POST['title']
            file.description = self.request.POST['description']


            form_data = cgi.FieldStorage()
            
            if form_data.getvalue('file'):
                subject = form_data.getvalue('file')
                # Create the file
                file_name = files.blobstore.create(mime_type='application/octet-stream')
                
                # Open the file and write to it
                with files.open(file_name, 'a') as f:
                    f.write(subject)
                
                # Finalize the file. Do this before attempting to read it.
                files.finalize(file_name)
                
                # Get the file's blob key
                file.file_key = files.blobstore.get_blob_key(file_name)
               
            else:
               subject = "Not set"
               
            
            #Output the given form to the confirmation page
            self.response.out.write( file.ownerId + "<br/>" )
            self.response.out.write(file.title + "<br/>")
            self.response.out.write(file.description + "<br/>")
            
            #add the model to the data store
            file.put()
            self.redirect('/files')
    def get(self):
        
        user = users.get_current_user() 
        
        if user:
            
            pasyer_users = db.GqlQuery("SELECT * "
                "FROM Site_User "
                "WHERE userid = :1 ",
                user.user_id())
            
            current_user = False
            for pasyer_user in pasyer_users:
                current_user = pasyer_user

            if not current_user:
                self.redirect("/settings")
            else:
            
                payslips = db.GqlQuery("SELECT * "
                    "FROM Payslip "
                    "WHERE ANCESTOR IS :1 ",
                    Models.payslip_key(user.user_id()))
        
                income = 0
                tax = 0
                payslip_count = 0            
                for payslip in payslips:
                    income+= payslip.income
                    tax += payslip.tax
                    payslip_count += 1
                    
                files = db.GqlQuery("SELECT * "
                    "FROM File "
                    "WHERE ANCESTOR IS :1 ",
                    Models.file_key(user.user_id()))
                file_count = 0    
                for file in files:
                    file_count += 1
                    
    
                #set stylesheets needed per page 
                specific_urls = """
                    <link type="text/css" rel="stylesheet" href="/stylesheets/""" + self.__class__.__name__ + """.css" />
                """
                
                dashboard_template_values = {
                    'name': current_user.name,
                    'email': current_user.email,
                    'account_type': current_user.account_type,
                    'payslip_quantity': payslip_count,
                    'file_quantity': file_count,
                    'income': income,
                    'tax': tax,
                    'net': income - tax
                }
                
                template = jinja_environment.get_template('Page_Content/dashboard.html')
                dashboard_template = template.render(dashboard_template_values)
                
                url = users.create_logout_url(self.request.uri)
                nav = """
                <nav>
                    <ul>
                        <li><a href="/dashboard">Dashboard</a></li>
                        <li><a href="#">Design</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="%s">Logout</a></li>
                    </ul>
                </nav>
                """ % url
               
                    
                template_values = {
                    'specific_urls':specific_urls,
                    'nav': nav,
                    'content': dashboard_template
                }
               
                template = jinja_environment.get_template('index.html')
                self.response.out.write(template.render(template_values))
        else:
            self.redirect('/')
import webapp2
import jinja2
import os
import Models

from google.appengine.ext import db
from google.appengine.api import users


payslips = db.GqlQuery("SELECT * "
                "FROM Payslip "
                "WHERE ANCESTOR IS :1 ",
                Models.payslip_key(users.get_current_user().user_id()))
    
income = 0
tax = 0
payslip_count = 0            
for payslip in payslips:
    income+= payslip.income
    tax += payslip.tax
    payslip_count += 1
    
employee = Models.Employee()
 
employee.userid = user.user_id()
employee.income = income
employee.tax = tax
employee.net = income - tax
employee.account_type = "employee"

employee.put()