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
import django.db.models.deletion
......@@ -14,26 +14,27 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name="Employee",
fields=[
("employee_id", models.CharField(max_length=10)),
(
"employee_id",
models.CharField(max_length=10, primary_key=True, serialize=False),
"employee_name",
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",
models.CharField(blank=True, max_length=255, null=True),
"employee_email",
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",
models.CharField(blank=True, max_length=10, null=True),
models.CharField(blank=True, default="", max_length=10, null=True),
),
(
"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):
"position_id",
models.CharField(max_length=10, primary_key=True, serialize=False),
),
("history_no", models.CharField(max_length=10)),
("position_name", models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name="Productivity",
name="SummaryReport",
fields=[
("report_no", models.AutoField(primary_key=True, serialize=False)),
("sr_no", models.AutoField(primary_key=True, serialize=False)),
("prod_score", models.FloatField()),
("totalworkhrs", models.DurationField()),
("prod_date", models.DateField(null=True)),
("workinghours", models.DurationField()),
("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)),
("status", models.CharField(max_length=255)),
("totalduration", models.DurationField()),
(
"employee_name",
models.ForeignKey(
default="",
on_delete=django.db.models.deletion.CASCADE,
to="IPSapp.employee",
),
),
],
),
migrations.CreateModel(
name="SummaryReport",
name="Productivity",
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()),
("report_no", models.AutoField(primary_key=True, serialize=False)),
("remarks", models.TextField(blank=True, max_length=2000)),
("process", models.CharField(max_length=255)),
("duration", models.CharField(max_length=5)),
("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(
......@@ -98,10 +120,6 @@ class Migration(migrations.Migration):
"history_no",
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_enddate", models.DateField(null=True)),
(
......
from django.db import models
#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):
employee_id = models.CharField(max_length=10, primary_key=True)
employee_fname = models.CharField(max_length=255)
employee_mname = models.CharField(max_length=255, blank=True, 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 = 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'
employee_id = models.CharField(max_length=10)
employee_name = models.CharField(max_length=255, primary_key=True)
employee_sex = models.CharField(max_length=1, blank=True, null=True, default='')
employee_bday = models.DateField(blank=True, null=True, default='')
employee_email = models.CharField(max_length=255, blank=True, null=True, default='')
employee_num = models.CharField(max_length=10, blank=True, null=True, default='')
employee_emergnum = models.CharField(max_length=10, blank=True, null=True, default='')
def __str__(self):
return str(self.employee_name)
class Productivity(models.Model):
report_no = models.AutoField(primary_key=True)
#employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
prod_date = models.DateField(null=True)
workinghours = models.DurationField()
employee_name = models.ForeignKey('Employee', on_delete=models.CASCADE, default='', unique=True)
sr_no = models.ForeignKey('SummaryReport', on_delete=models.CASCADE, default='')
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)
duration = models.CharField(max_length=5)
status = models.CharField(max_length=255)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='productivity_fk'
# )
# ]
#class JobOrder(models.Model):
#joborder_no = models.CharField(max_length=10, primary_key=True)
#report_no = models.ForeignKey('Productivity', on_delete=models.CASCADE)
#process = models.CharField(max_length=255)
#status = models.CharField(max_length=255)
def getReportno(self):
return self.report_no
def getRemarks(self):
return self.remarks
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):
position_id = models.CharField(max_length=10, primary_key=True)
history_no = models.CharField(max_length=10)
position_name = models.CharField(max_length=255)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['history_no'],
# ['history.history_no'],
# name='position_fk'
# )
# ]
class History(models.Model):
history_no = models.CharField(max_length=10, primary_key=True)
employee = models.ForeignKey('Employee', 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_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):
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()
date = models.DateField()
totalworkhrs = models.DurationField()
prod_date = models.DateField(null=True)
totalduration = models.DurationField()
def getSrno(self):
return self.sr_no
def getEmployeename(self):
return self.employee_name
def getProdScore(self):
return self.prod_score
def getDate(self):
return self.date
def getTotalWorkHrs(self):
return self.totalworkhrs
def getProdDate(self):
return self.prod_date
def getTotalDuration(self):
return self.totalduration
def __str__(self):
return "pk: " + str(self.pk) + ": " + str(self.sr_no) + ", " + self.employee_name + ", " + str(self.prod_score) + ", " + str(self.date)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='dashboard_fk1'
# ),
# models.ForeignKeyConstraint(
# ['report_no'],
# ['productivity.report_no'],
# name='dashboard_fk2'
# )
# ]
return "PK/SR No.: " + str(self.sr_no) + ", " + str(self.prod_date) + ", " + str(self.totalduration) + ", " + str(self.prod_score) + ", " + str(self.totalworkhrs)
class IPSUser(models.Model):
username = models.CharField(max_length=300, unique=True)
......
......@@ -43,7 +43,7 @@
<tr>
<td>{{ row.sr_no}}</td>
<td>{{ row.employee_name}}</td>
<td>{{ row.date}}</td>
<td>{{ row.prod_date}}</td>
<td>{{ row.prod_score }}</td>
<td>{{ row.totalworkhrs }}</td>
<!-- add more cells for additional fields -->
......
......@@ -18,15 +18,13 @@
<div class="top-cont">
<h1 clas="choose-file">Choose file</h1>
<div class="secondline">
<textarea readonly></textarea>
<!-- <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 %}
<label for="file-upload" class="cf-button">
Choose File
</label>
<input id="file-upload" type="file" name="csv_file" style="
display: none;"/>
<label for="file">Choose a file to upload:</label>
<input type="file" name="file" id="file">
<input type="submit" value="Upload">
</form>
<!-- <label for="csv_file">Upload a CSV file:</label> -->
<!-- <input type="file" class="cf-button" name="csv_file" accept=".csv"> -->
<!-- <input type="submit" value="Upload"> -->
......
......@@ -2,7 +2,7 @@ from django.shortcuts import render, redirect
import io
import csv
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.utils.dateparse import parse_date, parse_duration
# from dateutil.parser import parse as parse_date
......@@ -81,19 +81,19 @@ def loginpage(request):
def upload_csv(request):
if request.method == 'POST':
csv_file = request.FILES['csv_file']
csv_file = request.FILES['file']
if not csv_file.name.endswith('.csv'):
messages.error(request, 'This is not a CSV file')
else:
# read the data from the uploaded file
csv_data = csv.reader(
(line.decode('utf-8') for line in csv_file),
(line.decode('latin-1') for line in csv_file),
delimiter=',',
quotechar='"'
)
#Loop through data rows
for i, row in enumerate(csv_data):
# Check if this row is the start of a new report
# Check if this row is the start of a new report
if row[0] == 'PRODUCTIVITY REPORT':
# Reset variables for the new report
sr_no = row[1]
......@@ -101,52 +101,84 @@ def upload_csv(request):
prod_score = None
date = 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
elif i == 4 and employee_name is None:
elif i == startrow + 5 and employee_name is None:
employee_name = row[0]
# 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()
return redirect('home')
return render(request, 'EmployeeProdDB/upload_csv.html')
def upload_csv(request):
if request.method == 'POST':
csv_file = request.FILES['csv_file']
if not csv_file.name.endswith('.csv'):
messages.error(request, 'This is not a CSV file')
else:
# Read the data from the uploaded file
csv_data = csv.DictReader(csv_file.read().decode('utf-8').splitlines())
# Loop through data rows
for row in csv_data:
# 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)
elif row[2] != '' and row[2] != None and row[2] != 'Status':
jobno = row[0]
status = row[2]
process = row[5]
duration = row[12]
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()
getSr =SummaryReport.objects.get(sr_no=summary_pr.sr_no)
productivities = []
for j in prodrecords:
saveprod = Productivity(
sr_no=getSr,
employee_id=getEmp,
status=j[0],
process=j[1],
totalduration=j[2],
remarks=j[3]
)
productivities.append(saveprod)
saveprodbulk = Productivity.objects.bulk_create(productivities)
# 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
)
return render(request, 'EmployeeProdDB/upload_csv.html', {'message': 'Data imported successfully!'})
# 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):
data = SummaryReport.objects.all()
# Get the start and end dates from the request GET parameters
......
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