Commit 3977069a authored by dexsap's avatar dexsap

updated

parent cb539dd4
# Generated by Django 4.2 on 2023-04-04 18:18 # Generated by Django 4.2 on 2023-05-16 12:52
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -14,26 +14,27 @@ class Migration(migrations.Migration): ...@@ -14,26 +14,27 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name="Employee", name="Employee",
fields=[ fields=[
("employee_id", models.CharField(max_length=10)),
( (
"employee_id", "employee_name",
models.CharField(max_length=10, primary_key=True, serialize=False), models.CharField(max_length=255, primary_key=True, serialize=False),
),
(
"employee_sex",
models.CharField(blank=True, default="", max_length=1, null=True),
), ),
("employee_fname", models.CharField(max_length=255)), ("employee_bday", models.DateField(blank=True, default="", null=True)),
( (
"employee_mname", "employee_email",
models.CharField(blank=True, max_length=255, null=True), models.CharField(blank=True, default="", max_length=255, null=True),
), ),
("employee_lname", models.CharField(max_length=255)),
("employee_sex", models.CharField(max_length=1)),
("employee_bday", models.DateField()),
("employee_email", models.CharField(max_length=255)),
( (
"employee_num", "employee_num",
models.CharField(blank=True, max_length=10, null=True), models.CharField(blank=True, default="", max_length=10, null=True),
), ),
( (
"employee_emergnum", "employee_emergnum",
models.CharField(blank=True, max_length=10, null=True), models.CharField(blank=True, default="", max_length=10, null=True),
), ),
], ],
), ),
...@@ -64,31 +65,52 @@ class Migration(migrations.Migration): ...@@ -64,31 +65,52 @@ class Migration(migrations.Migration):
"position_id", "position_id",
models.CharField(max_length=10, primary_key=True, serialize=False), models.CharField(max_length=10, primary_key=True, serialize=False),
), ),
("history_no", models.CharField(max_length=10)),
("position_name", models.CharField(max_length=255)), ("position_name", models.CharField(max_length=255)),
], ],
), ),
migrations.CreateModel(
name="SummaryReport",
fields=[
("sr_no", models.AutoField(primary_key=True, serialize=False)),
("prod_score", models.FloatField()),
("totalworkhrs", models.DurationField()),
("prod_date", models.DateField(null=True)),
("totalduration", models.DurationField()),
(
"employee_name",
models.ForeignKey(
default="",
on_delete=django.db.models.deletion.CASCADE,
to="IPSapp.employee",
),
),
],
),
migrations.CreateModel( migrations.CreateModel(
name="Productivity", name="Productivity",
fields=[ fields=[
("report_no", models.AutoField(primary_key=True, serialize=False)), ("report_no", models.AutoField(primary_key=True, serialize=False)),
("prod_date", models.DateField(null=True)),
("workinghours", models.DurationField()),
("remarks", models.TextField(blank=True, max_length=2000)), ("remarks", models.TextField(blank=True, max_length=2000)),
("prod_score", models.FloatField(null=True)),
("joborder_no", models.CharField(max_length=10)),
("process", models.CharField(max_length=255)), ("process", models.CharField(max_length=255)),
("duration", models.CharField(max_length=5)),
("status", models.CharField(max_length=255)), ("status", models.CharField(max_length=255)),
], (
"employee_name",
models.ForeignKey(
default="",
on_delete=django.db.models.deletion.CASCADE,
to="IPSapp.employee",
unique=True,
),
),
(
"sr_no",
models.ForeignKey(
default="",
on_delete=django.db.models.deletion.CASCADE,
to="IPSapp.summaryreport",
),
), ),
migrations.CreateModel(
name="SummaryReport",
fields=[
("sr_no", models.AutoField(primary_key=True, serialize=False)),
("employee_name", models.CharField(default="No Name", max_length=255)),
("prod_score", models.FloatField()),
("date", models.DateField()),
("totalworkhrs", models.DurationField()),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
...@@ -98,10 +120,6 @@ class Migration(migrations.Migration): ...@@ -98,10 +120,6 @@ class Migration(migrations.Migration):
"history_no", "history_no",
models.CharField(max_length=10, primary_key=True, serialize=False), models.CharField(max_length=10, primary_key=True, serialize=False),
), ),
("employee_fname", models.CharField(max_length=255)),
("employee_mname", models.CharField(blank=True, max_length=255)),
("employee_lname", models.CharField(max_length=255)),
("position_name", models.CharField(max_length=255)),
("position_startdate", models.DateField()), ("position_startdate", models.DateField()),
("position_enddate", models.DateField(null=True)), ("position_enddate", models.DateField(null=True)),
( (
......
from django.db import models from django.db import models
#from .employee import Employee #from .employee import Employee
class Upload(models.Model):
file = models.FileField(upload_to='Uploaded CSV/')
class Meta:
app_label = 'your_app_name'
class Employee(models.Model): class Employee(models.Model):
employee_id = models.CharField(max_length=10, primary_key=True) employee_id = models.CharField(max_length=10)
employee_fname = models.CharField(max_length=255) employee_name = models.CharField(max_length=255, primary_key=True)
employee_mname = models.CharField(max_length=255, blank=True, null=True) employee_sex = models.CharField(max_length=1, blank=True, null=True, default='')
employee_lname = models.CharField(max_length=255) employee_bday = models.DateField(blank=True, null=True, default='')
employee_sex = models.CharField(max_length=1) employee_email = models.CharField(max_length=255, blank=True, null=True, default='')
employee_bday = models.DateField() employee_num = models.CharField(max_length=10, blank=True, null=True, default='')
employee_email = models.CharField(max_length=255) employee_emergnum = models.CharField(max_length=10, blank=True, null=True, default='')
employee_num = models.CharField(max_length=10, blank=True, null=True)
employee_emergnum = models.CharField(max_length=10, blank=True, null=True)
# class Meta:
# db_table = 'employee'
def __str__(self):
return str(self.employee_name)
class Productivity(models.Model): class Productivity(models.Model):
report_no = models.AutoField(primary_key=True) report_no = models.AutoField(primary_key=True)
#employee = models.ForeignKey('Employee', on_delete=models.CASCADE) employee_name = models.ForeignKey('Employee', on_delete=models.CASCADE, default='', unique=True)
prod_date = models.DateField(null=True) sr_no = models.ForeignKey('SummaryReport', on_delete=models.CASCADE, default='')
workinghours = models.DurationField()
remarks = models.TextField(max_length=2000, blank=True) remarks = models.TextField(max_length=2000, blank=True)
prod_score = models.FloatField(null=True)
joborder_no = models.CharField(max_length=10)
process = models.CharField(max_length=255) process = models.CharField(max_length=255)
duration = models.CharField(max_length=5)
status = models.CharField(max_length=255) status = models.CharField(max_length=255)
# class Meta: def getReportno(self):
# constraints = [ return self.report_no
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='productivity_fk'
# )
# ]
#class JobOrder(models.Model): def getRemarks(self):
#joborder_no = models.CharField(max_length=10, primary_key=True) return self.remarks
#report_no = models.ForeignKey('Productivity', on_delete=models.CASCADE)
#process = models.CharField(max_length=255)
#status = models.CharField(max_length=255)
def getProcess(self):
return self.process
def getDuration(self):
return self.duration
def getStatus(self):
return self.status
def __str__(self):
return "PK No.: " + str(self.report_no) + ", " + str(self.status) + ", " + str(self.process) + ", " + str(self.duration) + ", " + str(self.remarks)
class Position(models.Model): class Position(models.Model):
position_id = models.CharField(max_length=10, primary_key=True) position_id = models.CharField(max_length=10, primary_key=True)
history_no = models.CharField(max_length=10)
position_name = models.CharField(max_length=255) position_name = models.CharField(max_length=255)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['history_no'],
# ['history.history_no'],
# name='position_fk'
# )
# ]
class History(models.Model): class History(models.Model):
history_no = models.CharField(max_length=10, primary_key=True) history_no = models.CharField(max_length=10, primary_key=True)
employee = models.ForeignKey('Employee', on_delete=models.CASCADE) employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
position = models.ForeignKey('Position', on_delete=models.CASCADE) position = models.ForeignKey('Position', on_delete=models.CASCADE)
employee_fname = models.CharField(max_length=255)
employee_mname = models.CharField(max_length=255, blank=True)
employee_lname = models.CharField(max_length=255)
position_name = models.CharField(max_length=255)
position_startdate = models.DateField() position_startdate = models.DateField()
position_enddate = models.DateField(null=True) position_enddate = models.DateField(null=True)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='history_fk1'
# ),
# models.ForeignKeyConstraint(
# ['position_id'],
# ['position.position_id'],
# name='history_fk2'
# )
# ]
# class SummaryPR(models.Model):
# productivity_score = models.IntegerField()
# date = models.DateField()
# totalworkhrs = models.DurationField()
class SummaryReport(models.Model): class SummaryReport(models.Model):
sr_no = models.AutoField(primary_key=True) sr_no = models.AutoField(primary_key=True)
employee_name = models.CharField(max_length=255, default="No Name") employee_name = models.ForeignKey('Employee', on_delete=models.CASCADE, default='')
prod_score = models.FloatField() prod_score = models.FloatField()
date = models.DateField()
totalworkhrs = models.DurationField() totalworkhrs = models.DurationField()
prod_date = models.DateField(null=True)
totalduration = models.DurationField()
def getSrno(self): def getSrno(self):
return self.sr_no return self.sr_no
def getEmployeename(self):
return self.employee_name
def getProdScore(self): def getProdScore(self):
return self.prod_score return self.prod_score
def getDate(self): def getTotalWorkHrs(self):
return self.date return self.totalworkhrs
def getProdDate(self):
return self.prod_date
def getTotalDuration(self):
return self.totalduration
def __str__(self): def __str__(self):
return "pk: " + str(self.pk) + ": " + str(self.sr_no) + ", " + self.employee_name + ", " + str(self.prod_score) + ", " + str(self.date) return "PK/SR No.: " + str(self.sr_no) + ", " + str(self.prod_date) + ", " + str(self.totalduration) + ", " + str(self.prod_score) + ", " + str(self.totalworkhrs)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='dashboard_fk1'
# ),
# models.ForeignKeyConstraint(
# ['report_no'],
# ['productivity.report_no'],
# name='dashboard_fk2'
# )
# ]
class IPSUser(models.Model): class IPSUser(models.Model):
username = models.CharField(max_length=300, unique=True) username = models.CharField(max_length=300, unique=True)
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<tr> <tr>
<td>{{ row.sr_no}}</td> <td>{{ row.sr_no}}</td>
<td>{{ row.employee_name}}</td> <td>{{ row.employee_name}}</td>
<td>{{ row.date}}</td> <td>{{ row.prod_date}}</td>
<td>{{ row.prod_score }}</td> <td>{{ row.prod_score }}</td>
<td>{{ row.totalworkhrs }}</td> <td>{{ row.totalworkhrs }}</td>
<!-- add more cells for additional fields --> <!-- add more cells for additional fields -->
......
...@@ -18,15 +18,13 @@ ...@@ -18,15 +18,13 @@
<div class="top-cont"> <div class="top-cont">
<h1 clas="choose-file">Choose file</h1> <h1 clas="choose-file">Choose file</h1>
<div class="secondline"> <div class="secondline">
<textarea readonly></textarea>
<!-- <button type="file" name="csv_file" accept=".csv">Choose File</button> --> <!-- <button type="file" name="csv_file" accept=".csv">Choose File</button> -->
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data" action="{% url 'upload_csv' %}">
{% csrf_token %} {% csrf_token %}
<label for="file-upload" class="cf-button"> <label for="file">Choose a file to upload:</label>
Choose File <input type="file" name="file" id="file">
</label> <input type="submit" value="Upload">
<input id="file-upload" type="file" name="csv_file" style=" </form>
display: none;"/>
<!-- <label for="csv_file">Upload a CSV file:</label> --> <!-- <label for="csv_file">Upload a CSV file:</label> -->
<!-- <input type="file" class="cf-button" name="csv_file" accept=".csv"> --> <!-- <input type="file" class="cf-button" name="csv_file" accept=".csv"> -->
<!-- <input type="submit" value="Upload"> --> <!-- <input type="submit" value="Upload"> -->
......
...@@ -2,7 +2,7 @@ from django.shortcuts import render, redirect ...@@ -2,7 +2,7 @@ from django.shortcuts import render, redirect
import io import io
import csv import csv
from datetime import datetime, timedelta from datetime import datetime, timedelta
from .models import Productivity, IPSUser, SummaryReport from .models import Productivity, IPSUser, SummaryReport, Employee
from django.contrib import messages from django.contrib import messages
from django.utils.dateparse import parse_date, parse_duration from django.utils.dateparse import parse_date, parse_duration
# from dateutil.parser import parse as parse_date # from dateutil.parser import parse as parse_date
...@@ -81,13 +81,13 @@ def loginpage(request): ...@@ -81,13 +81,13 @@ def loginpage(request):
def upload_csv(request): def upload_csv(request):
if request.method == 'POST': if request.method == 'POST':
csv_file = request.FILES['csv_file'] csv_file = request.FILES['file']
if not csv_file.name.endswith('.csv'): if not csv_file.name.endswith('.csv'):
messages.error(request, 'This is not a CSV file') messages.error(request, 'This is not a CSV file')
else: else:
# read the data from the uploaded file # read the data from the uploaded file
csv_data = csv.reader( csv_data = csv.reader(
(line.decode('utf-8') for line in csv_file), (line.decode('latin-1') for line in csv_file),
delimiter=',', delimiter=',',
quotechar='"' quotechar='"'
) )
...@@ -101,51 +101,83 @@ def upload_csv(request): ...@@ -101,51 +101,83 @@ def upload_csv(request):
prod_score = None prod_score = None
date = None date = None
totalworkhrs = None totalworkhrs = None
totalduration = None
jobno = None
status = None
process = None
duration = None
remarks = None
startrow = i
prodrecords = []
elif i == startrow + 2 and employee_name is None:
date = row[0].replace("For the period of '",'')
date = date[:-12].replace(' ','')
date_obj = datetime.strptime(date, '%m/%d/%Y')
# Check if this is the fifth row after the start of the report # Check if this is the fifth row after the start of the report
elif i == 4 and employee_name is None: elif i == startrow + 5 and employee_name is None:
employee_name = row[0] employee_name = row[0]
# Check if this row contains a date and "Total Duration:" and "Productivity %" elif row[2] != '' and row[2] != None and row[2] != 'Status':
if len(row) > 2 and "/" in row[0] and "Total Duration:" in row and "Productivity %" in row: jobno = row[0]
date = datetime.strptime(row[0], '%m/%d/%Y').date() status = row[2]
totalworkhrs = timedelta(hours=float(row[row.index("Total Duration:") + 2])) process = row[5]
prod_score = int(row[row.index("Productivity %") + 2]) duration = row[12]
summary_pr = SummaryReport.objects.create(sr_no=sr_no, employee_name=employee_name, prod_score=prod_score, date=date, totalworkhrs=totalworkhrs) remarks = row[14]
# process
prodrecords.append([status,process,duration,remarks])
messages.error(request, prodrecords)
jobno = None
status = None
process = None
remarks = None
elif row[12] == 'Productivity %':
prod_score = row[14].replace('%','')
if row[10]:
totalduration = float(row[10])
hours = int(totalduration)
minutes = int((totalduration - hours) * 60)
totaldurationtd = timedelta(hours=hours, minutes=minutes)
elif row[8] == 'Hrs Worked:':
if row[10]:
totalworkhrs = float(row[10])
hours = int(totalworkhrs)
minutes = int((totalworkhrs - hours) * 60)
totalworkhrstd = timedelta(hours=hours, minutes=minutes)
getEmp = Employee.objects.get(employee_name=employee_name)
summary_pr = SummaryReport.objects.create(employee_name=getEmp, prod_score=prod_score, totalworkhrs=totalworkhrstd, prod_date=date_obj,totalduration=totaldurationtd)
summary_pr.save() summary_pr.save()
return redirect('home')
return render(request, 'EmployeeProdDB/upload_csv.html')
def upload_csv(request): getSr =SummaryReport.objects.get(sr_no=summary_pr.sr_no)
if request.method == 'POST':
csv_file = request.FILES['csv_file'] productivities = []
if not csv_file.name.endswith('.csv'): for j in prodrecords:
messages.error(request, 'This is not a CSV file') saveprod = Productivity(
else: sr_no=getSr,
# Read the data from the uploaded file employee_id=getEmp,
csv_data = csv.DictReader(csv_file.read().decode('utf-8').splitlines()) status=j[0],
process=j[1],
# Loop through data rows totalduration=j[2],
for row in csv_data: remarks=j[3]
# Convert duration string to a Duration object
working_hours = row['Work Hours']
if working_hours:
hours, minutes, seconds= map(int, working_hours.split(':'))
working_hours = timedelta(hours=hours, minutes=minutes, seconds=seconds)
# Create a new SummaryReport object
summary_report = SummaryReport.objects.create(
employee_name=row['Employee Name'],
prod_score=row['Productivity Score'],
date=row['Date'],
totalworkhrs=working_hours
) )
productivities.append(saveprod)
return render(request, 'EmployeeProdDB/upload_csv.html', {'message': 'Data imported successfully!'}) saveprodbulk = Productivity.objects.bulk_create(productivities)
return render(request, 'EmployeeProdDB/upload_csv.html')
# messages.error(request, employee_name + ' ' + date + ' ' + totalworkhrs + ' ' + prod_score)
# # Check if this row contains a date and "Total Duration:" and "Productivity %"
# if len(row) > 2 and "/" in row[0] and "Total Duration:" in row and "Productivity %" in row:
# date = datetime.strptime(row[0], '%m/%d/%Y').date()
# totalworkhrs = timedelta(hours=float(row[row.index("Total Duration:") + 2]))
# prod_score = int(row[row.index("Productivity %") + 2])
# summary_pr = SummaryReport.objects.create(sr_no=sr_no, employee_name=employee_name, prod_score=prod_score, date=date, totalworkhrs=totalworkhrs)
# summary_pr.save()
# messages.error(request, row)
return redirect('home')
return render(request, 'EmployeeProdDB/upload_csv.html')
def chart_template(request): def chart_template(request):
data = SummaryReport.objects.all() data = SummaryReport.objects.all()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment