diff --git a/postgresTest/PROJECT1/__pycache__/admin.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/admin.cpython-311.pyc index 14dfa7fb904bf848b317bf1591425844c3c37848..b40a2231d68a17d04a77a490c38b19db2b02ce1a 100644 Binary files a/postgresTest/PROJECT1/__pycache__/admin.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/admin.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc index b5efbc4ef1e22dde3621d756906e6e31f1609a3c..e43f987ffec4721365fff7387a20d7e579fcc1de 100644 Binary files a/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/forms.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc index fa97e0d747deea46f6c7b8388e4fe07f7b66464a..2adcd25c545d82e61e2acce51c02a32f5d154f82 100644 Binary files a/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/models.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/urls.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/urls.cpython-311.pyc index 62c1c1a07c825047c92d5203802b81550b4df820..471557d6700e6a4fc0031ca064a24fdf4f136254 100644 Binary files a/postgresTest/PROJECT1/__pycache__/urls.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/urls.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc b/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc index de5f47f2e00f37b8c7bf17f4c2c456c0e12a2f3c..c994f8664d23059ce276573f94aac5f6c7c4e9c5 100644 Binary files a/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc and b/postgresTest/PROJECT1/__pycache__/views.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/admin.py b/postgresTest/PROJECT1/admin.py index 68d4c816997c26e251e654f3a20fb4781902e9d3..be853d07fa2c58b3d45d38b3831596edb7960946 100644 --- a/postgresTest/PROJECT1/admin.py +++ b/postgresTest/PROJECT1/admin.py @@ -1,14 +1,8 @@ from django.contrib import admin -from .models import Job, CustomUser, JobRating, CartItem,Forecast, Sale, Account, LeaveForm -from django.contrib.auth.models import User +from .models import Job, CustomUser, Contact # Register your models here. admin.site.register(Job) admin.site.register(CustomUser) -admin.site.register(JobRating) -admin.site.register(CartItem) -admin.site.register(Forecast) -admin.site.register(Sale) -admin.site.register(Account) -admin.site.register(LeaveForm) -superusers = CustomUser.objects.filter(is_superuser=True) +admin.site.register(Contact) + diff --git a/postgresTest/PROJECT1/forms.py b/postgresTest/PROJECT1/forms.py index ab7f43df630820ebc6b71415c273fe58af7a948a..132bf80df73eee7d7a1d2836744b9b1848f6e881 100644 --- a/postgresTest/PROJECT1/forms.py +++ b/postgresTest/PROJECT1/forms.py @@ -1,17 +1,11 @@ from django import forms from django.contrib.auth.forms import UserCreationForm from django.contrib.auth import get_user_model -from .models import Contact, Forecast, Sale, Account, CustomUser, Meeting +from .models import Contact, CustomUser import datetime -class ScheduleMeetingForm(forms.ModelForm): - class Meta: - model = Meeting - fields = ['employee_type', 'date', 'start_time', 'end_time'] - widgets = { - 'date': forms.HiddenInput(), - } + class RoleAssignmentForm(forms.ModelForm): class Meta: @@ -27,62 +21,12 @@ class RoleAssignmentForm(forms.ModelForm): } -class ForecastForm(forms.ModelForm): - MONTH_CHOICES = [ - ('Jan', 'January'), ('Feb', 'February'), ('Mar', 'March'), ('Apr', 'April'), - ('May', 'May'), ('Jun', 'June'), ('Jul', 'July'), ('Aug', 'August'), - ('Sep', 'September'), ('Oct', 'October'), ('Nov', 'November'), ('Dec', 'December') - ] - - month = forms.ChoiceField(choices=MONTH_CHOICES) - year = forms.IntegerField(min_value=datetime.datetime.now().year, initial=datetime.datetime.now().year) - - class Meta: - model = Forecast - fields = ['month', 'year', 'value'] - - def clean_year(self): - year = self.cleaned_data.get('year') - if year <= 2023: - raise forms.ValidationError("Year must be higher than 2023.") - return year - -class SaleForm(forms.ModelForm): - QUARTER_CHOICES = [ - ('Q1', 'First Quarter'), - ('Q2', 'Second Quarter'), - ('Q3', 'Third Quarter'), - ('Q4', 'Fourth Quarter'), - ] - - quarter = forms.ChoiceField(choices=QUARTER_CHOICES) - year = forms.IntegerField(min_value=2015, max_value=datetime.datetime.now().year) - value = forms.DecimalField(widget=forms.NumberInput(attrs={'step': '0.01'})) - - class Meta: - model = Sale - fields = ['quarter', 'year', 'value'] - - def clean_year(self): - year = self.cleaned_data.get('year') - current_year = datetime.datetime.now().year - if year < 2015 or year > current_year: - raise forms.ValidationError(f"Year must be between 2015 and {current_year}.") - return year - -class AccountForm(forms.ModelForm): - class Meta: - model = Account - fields = ['category', 'value'] class CustomUserCreationForm(UserCreationForm): class Meta(UserCreationForm.Meta): model = get_user_model() fields = UserCreationForm.Meta.fields -class AddToCartForm(forms.Form): - quantity = forms.IntegerField(min_value=1, initial=0) - class ContactForm(forms.ModelForm): class Meta: model = Contact @@ -93,3 +37,19 @@ class ContactForm(forms.ModelForm): 'email': forms.EmailInput(attrs={'placeholder': 'Email', 'required': True, 'class': 'form-control'}), 'message': forms.Textarea(attrs={'placeholder': 'Message', 'required': True, 'class': 'form-control message-box'}), } + +from django import forms +from .models import Employee + +class OnboardingForm(forms.ModelForm): + class Meta: + model = Employee + fields = ['first_name', 'last_name', 'email', 'department', 'start_date', 'job_title'] + widgets = { + 'first_name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'First Name'}), + 'last_name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Last Name'}), + 'email': forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'Email Address'}), + 'department': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Department'}), + 'start_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}), + 'job_title': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Job Title'}), + } diff --git a/postgresTest/PROJECT1/migrations/0021_employee_delete_account_remove_cartitem_job_and_more.py b/postgresTest/PROJECT1/migrations/0021_employee_delete_account_remove_cartitem_job_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..655001b91ab14607dce0db5de7028939966ecebc --- /dev/null +++ b/postgresTest/PROJECT1/migrations/0021_employee_delete_account_remove_cartitem_job_and_more.py @@ -0,0 +1,116 @@ +# Generated by Django 5.0.6 on 2024-09-30 14:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('PROJECT1', '0020_rename_meeting_date_meeting_date_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='Employee', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=100)), + ('last_name', models.CharField(max_length=100)), + ('email', models.EmailField(max_length=254, unique=True)), + ('department', models.CharField(max_length=100)), + ('start_date', models.DateField()), + ('job_title', models.CharField(max_length=100)), + ], + ), + migrations.DeleteModel( + name='Account', + ), + migrations.RemoveField( + model_name='cartitem', + name='job', + ), + migrations.RemoveField( + model_name='cartitem', + name='user', + ), + migrations.DeleteModel( + name='Forecast', + ), + migrations.RemoveField( + model_name='jobrating', + name='job', + ), + migrations.RemoveField( + model_name='jobrating', + name='user', + ), + migrations.RemoveField( + model_name='submittedleaveform', + name='leave_form', + ), + migrations.RemoveField( + model_name='meeting', + name='user', + ), + migrations.RemoveField( + model_name='order', + name='user', + ), + migrations.RemoveField( + model_name='orderitem', + name='order', + ), + migrations.RemoveField( + model_name='orderitem', + name='job', + ), + migrations.RemoveField( + model_name='orderitem', + name='user', + ), + migrations.RemoveField( + model_name='punch', + name='user', + ), + migrations.DeleteModel( + name='Sale', + ), + migrations.RemoveField( + model_name='submittedleaveform', + name='employee', + ), + migrations.AlterField( + model_name='job', + name='img', + field=models.ImageField(blank=True, null=True, upload_to='pics'), + ), + migrations.AlterField( + model_name='job', + name='price', + field=models.IntegerField(blank=True, null=True), + ), + migrations.DeleteModel( + name='CartItem', + ), + migrations.DeleteModel( + name='JobRating', + ), + migrations.DeleteModel( + name='LeaveForm', + ), + migrations.DeleteModel( + name='Meeting', + ), + migrations.DeleteModel( + name='Order', + ), + migrations.DeleteModel( + name='OrderItem', + ), + migrations.DeleteModel( + name='Punch', + ), + migrations.DeleteModel( + name='SubmittedLeaveForm', + ), + ] diff --git a/postgresTest/PROJECT1/migrations/__pycache__/0021_employee_delete_account_remove_cartitem_job_and_more.cpython-311.pyc b/postgresTest/PROJECT1/migrations/__pycache__/0021_employee_delete_account_remove_cartitem_job_and_more.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..98bfdbe1eebf18295a70a402bb9b53f3bef7d5cf Binary files /dev/null and b/postgresTest/PROJECT1/migrations/__pycache__/0021_employee_delete_account_remove_cartitem_job_and_more.cpython-311.pyc differ diff --git a/postgresTest/PROJECT1/models.py b/postgresTest/PROJECT1/models.py index cf8787b380457ced760f6e5ad07c63b64e81020f..e47e624ad8bc21478ea77ab9f5efe947dde80803 100644 --- a/postgresTest/PROJECT1/models.py +++ b/postgresTest/PROJECT1/models.py @@ -1,37 +1,19 @@ from django.conf import settings from django.db import models -from django.contrib.auth.models import AbstractUser, Group, Permission, User +from django.contrib.auth.models import AbstractUser -# Store Meeting Information -class Meeting(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - date = models.DateField() - start_time = models.TimeField(null=True, blank=True, default=None) - end_time = models.TimeField() - employee_type = models.CharField(max_length=50) - def __str__(self): - return f"{self.employee_type} meeting on {self.date} from {self.start_time or '--:--:--'} to {self.end_time}" - - -# Define the LeaveForm model once -class LeaveForm(models.Model): - name = models.CharField(max_length=100) - form_url = models.URLField() - - def __str__(self): - return self.name - -# The SubmittedLeaveForm model -class SubmittedLeaveForm(models.Model): - employee = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - leave_form = models.ForeignKey(LeaveForm, on_delete=models.CASCADE) - date_submitted = models.DateTimeField(auto_now_add=True) - form_url = models.URLField() # The specific Google Form URL the employee used +class Employee(models.Model): + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + email = models.EmailField(unique=True) + department = models.CharField(max_length=100) + start_date = models.DateField() + job_title = models.CharField(max_length=100) def __str__(self): - return f"{self.employee.username} - {self.leave_form.name}" - + return f"{self.first_name} {self.last_name} - {self.department}" + # The CustomUser model class CustomUser(AbstractUser): ROLE_CHOICES = ( @@ -42,80 +24,16 @@ class CustomUser(AbstractUser): ) role = models.CharField(max_length=20, choices=ROLE_CHOICES, default='EMPLOYEE') -# The Punch model -class Punch(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - date = models.DateField() - punch_in = models.DateTimeField(null=True, blank=True) - punch_out = models.DateTimeField(null=True, blank=True) - total_time = models.DurationField(null=True, blank=True) # Add this field to store total working time - - def __str__(self): - return f"{self.user} - {self.date}" - -# The Forecast model -class Forecast(models.Model): - month = models.CharField(max_length=3) - year = models.IntegerField() - value = models.FloatField() - - def __str__(self): - return f"{self.month} {self.year} - {self.value}" - -# The Sale model -class Sale(models.Model): - quarter = models.CharField(max_length=2) - year = models.IntegerField() - value = models.FloatField() - - def __str__(self): - return f"{self.quarter} {self.year} - {self.value}" - -# The Account model -class Account(models.Model): - category = models.CharField(max_length=20) - value = models.FloatField() - - def __str__(self): - return f"{self.category} - {self.value}" - # The Job model class Job(models.Model): name = models.CharField(max_length=100) - img = models.ImageField(upload_to='pics') + img = models.ImageField(upload_to='pics', blank=True, null=True) # Optional if needed desc = models.TextField() - price = models.IntegerField() + price = models.IntegerField(blank=True, null=True) # Optional if needed form_url = models.URLField(blank=True, null=True) - @property - def average_rating(self): - ratings = JobRating.objects.filter(job=self) - return ratings.aggregate(Avg('rating'))['rating__avg'] or 0 - -# The CartItem model -class CartItem(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) - job = models.ForeignKey(Job, on_delete=models.CASCADE) - quantity = models.IntegerField(default=1) - - def get_subtotal(self): - return self.quantity * self.job.price - -# The Order model -class Order(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) - purchased_at = models.DateTimeField(auto_now_add=True) - total_price = models.DecimalField(max_digits=10, decimal_places=2) - -# The OrderItem model -class OrderItem(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) - order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name='order_items') - job = models.ForeignKey(Job, on_delete=models.CASCADE) - quantity = models.IntegerField() - - def get_price(self): - return self.quantity * self.job.price + def __str__(self): + return self.name # The Contact model class Contact(models.Model): @@ -127,13 +45,3 @@ class Contact(models.Model): def __str__(self): return self.name - -# The JobRating model -class JobRating(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) - job = models.ForeignKey(Job, on_delete=models.CASCADE) - rating = models.IntegerField() - review = models.TextField(blank=True, null=True) - - def __str__(self): - return f"{self.user.username}'s rating of {self.job.name}: {self.rating}" diff --git a/postgresTest/PROJECT1/templates/add_account.html b/postgresTest/PROJECT1/templates/add_account.html deleted file mode 100644 index 32e22324134803bb3b0a87e6dba0370e54eeb509..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/add_account.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -<div class="container mt-4"> - <h2>Add Account</h2> - <form method="post"> - {% csrf_token %} - {{ form.as_p }} - <button type="submit" class="btn btn-primary">Add Account</button> - </form> -</div> -{% endblock %} diff --git a/postgresTest/PROJECT1/templates/add_forecast.html b/postgresTest/PROJECT1/templates/add_forecast.html deleted file mode 100644 index 14e246d462da22e34df1c46d7f0a1c18371e8e51..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/add_forecast.html +++ /dev/null @@ -1,12 +0,0 @@ -<!-- add_forecast.html --> -{% extends 'base.html' %} -{% block content %} -<div class="container"> - <h2>Add Forecast</h2> - <form method="post"> - {% csrf_token %} - {{ form.as_p }} - <button type="submit" class="btn btn-primary">Add</button> - </form> -</div> -{% endblock %} \ No newline at end of file diff --git a/postgresTest/PROJECT1/templates/add_sale.html b/postgresTest/PROJECT1/templates/add_sale.html deleted file mode 100644 index 0338c23d682ec95284b1feda921cf1fffdb1a41d..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/add_sale.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'base.html' %} -{% block content %} -<div class="container"> - <h2>Add Sale</h2> - <form method="post"> - {% csrf_token %} - {{ form.as_p }} - <button type="submit" class="btn btn-primary">Add Sale</button> - </form> -</div> -{% endblock %} diff --git a/postgresTest/PROJECT1/templates/all_leave_forms.html b/postgresTest/PROJECT1/templates/all_leave_forms.html deleted file mode 100644 index e03fd61f89175b83ea14f38cd7207cf199d0b55d..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/all_leave_forms.html +++ /dev/null @@ -1,27 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -<div class="container mt-5"> - <h2 class="text-center">All Leave Forms</h2> - <table class="table table-bordered"> - <thead> - <tr> - <th>Employee</th> - <th>Leave Type</th> - <th>Date Submitted</th> - <th>Form URL</th> - </tr> - </thead> - <tbody> - {% for form in leave_forms %} - <tr> - <td>{{ form.employee.username }}</td> - <td>{{ form.leave_type }}</td> - <td>{{ form.date_submitted }}</td> - <td><a href="{{ form.form_url }}" target="_blank">View Form</a></td> - </tr> - {% endfor %} - </tbody> - </table> -</div> -{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/calendar.html b/postgresTest/PROJECT1/templates/calendar.html deleted file mode 100644 index 0751fe5432ba1790cbcef063c71406ff319942a5..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/calendar.html +++ /dev/null @@ -1,180 +0,0 @@ -{% extends 'base.html' %} -{% load custom_filters %} -{% block title %}Calendar{% endblock title %} -{% block content %} -<div class="container mt-5"> - <h2 class="text-center">{{ month_name }} {{ year }} Calendar</h2> - <div class="text-center mb-3"> - <a href="{% url 'calendar_view' previous_year previous_month %}" class="btn btn-info">« Previous</a> - <span class="mx-3">{{ month_name }} {{ year }}</span> - <a href="{% url 'calendar_view' next_year next_month %}" class="btn btn-info">Next »</a> - </div> - <div class="row"> - <div class="col-md-12"> - <table class="table table-bordered"> - <thead> - <tr> - {% for day in "MTWTFSS" %} - <th>{{ day }}</th> - {% endfor %} - </tr> - </thead> - <tbody> - {% for week in calendar_data %} - <tr> - {% for day in week %} - {% if day == 0 %} - <td></td> - {% else %} - <td> - <button type="button" class="btn btn-link" data-toggle="modal" data-target="#scheduleModal" data-day="{{ day }}"> - {{ day }} - </button> - {% if punch_data|get_item:day %} - <ul> - {% for punch in punch_data|get_item:day %} - <li>Punch In: {{ punch.punch_in|date:"H:i:s" }}</li> - {% if punch.punch_out %} - <li>Punch Out: {{ punch.punch_out|date:"H:i:s" }}</li> - <li>Total Time: {{ punch.total_time }}</li> - {% else %} - <li><strong>Not Punched Out</strong></li> - {% endif %} - {% endfor %} - </ul> - {% endif %} - </td> - {% endif %} - {% endfor %} - </tr> - {% endfor %} - </tbody> - </table> - </div> - </div> - <div class="text-center mt-5"> - <form id="punch-form" method="post" action="{% url 'punch' %}"> - {% csrf_token %} - <button type="submit" class="btn {{ punch_button_class }}" id="punch-button">{{ punch_button_text }}</button> - </form> - <div id="timer" class="mt-3"></div> - </div> -</div> - -<!-- Modal for Scheduling Meetings --> -<div class="modal fade" id="scheduleModal" tabindex="-1" aria-labelledby="scheduleModalLabel" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="scheduleModalLabel">Schedule a Meeting for Day <span id="modal-day"></span></h5> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"> - <span aria-hidden="true">×</span> - </button> - </div> - <div class="modal-body"> - <form method="post" action="{% url 'schedule_meeting' %}"> - {% csrf_token %} - <input type="hidden" id="selectedDay" name="selectedDay" value=""> - <div class="form-group"> - <label for="employeeType">Select Employee Type:</label> - <select class="form-control" id="employeeType" name="employeeType"> - <option value="HR Staff">HR Staff</option> - <option value="Administrator">Administrator</option> - <option value="Employee Manager">Employee Manager</option> - <option value="Employee">Employee</option> - </select> - </div> - <div class="form-group"> - <label for="startTime">Start Time:</label> - <select class="form-control" id="startTime" name="startTime"> - {% for time in time_options %} - <option value="{{ time }}">{{ time }}</option> - {% endfor %} - </select> - </div> - <div class="form-group"> - <label for="endTime">End Time:</label> - <select class="form-control" id="endTime" name="endTime"> - {% for time in time_options %} - <option value="{{ time }}">{{ time }}</option> - {% endfor %} - </select> - </div> - <button type="submit" class="btn btn-primary">Schedule Meeting</button> - </form> - </div> - </div> - </div> -</div> - -<script> - document.addEventListener("DOMContentLoaded", function() { - const punchForm = document.getElementById("punch-form"); - const punchButton = document.getElementById("punch-button"); - const timerElement = document.getElementById("timer"); - let timerInterval; - - punchForm.addEventListener("submit", function(event) { - event.preventDefault(); - fetch(punchForm.action, { - method: "POST", - headers: { - "X-CSRFToken": punchForm.querySelector("[name=csrfmiddlewaretoken]").value, - "Content-Type": "application/json" - }, - body: JSON.stringify({}) - }) - .then(response => response.json()) - .then(data => { - if (data.status === "punched_in") { - punchButton.classList.remove("btn-success"); - punchButton.classList.add("btn-danger"); - punchButton.innerText = "Punch Out"; - startTimer(new Date(data.punch_in)); - } else if (data.status === "punched_out") { - punchButton.classList.remove("btn-danger"); - punchButton.classList.add("btn-success"); - punchButton.innerText = "Punch In"; - clearInterval(timerInterval); - timerElement.innerText = "Total Time: " + data.total_time; - } - }) - .catch(error => console.error("Error:", error)); - }); - - {% if current_punch and not current_punch.punch_out %} - let punchInTime = new Date('{{ current_punch.punch_in|date:"Y-m-d H:i:s" }}'); - startTimer(punchInTime); - {% endif %} - - function startTimer(startTime) { - timerInterval = setInterval(function() { - let now = new Date(); - let elapsed = now - startTime; - - let hours = Math.floor(elapsed / 3600000); - let minutes = Math.floor((elapsed % 3600000) / 60000); - let seconds = Math.floor((elapsed % 60000) / 1000); - - timerElement.innerText = `Time Elapsed: ${hours}h ${minutes}m ${seconds}s`; - - if (punchButton.innerText === "Punch In") { - clearInterval(timerInterval); - } - }, 1000); - } - - $('#scheduleModal').on('show.bs.modal', function (event) { - var button = event.relatedTarget; - var day = button.getAttribute('data-day'); - var modalTitle = document.getElementById('scheduleModalLabel'); - var modalDay = document.getElementById('modal-day'); - var modalInputDay = document.getElementById('selectedDay'); - - modalTitle.textContent = 'Schedule a Meeting for Day ' + day; - modalDay.textContent = day; - modalInputDay.value = day; - }); - }); -</script> -{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/cartpage.html b/postgresTest/PROJECT1/templates/cartpage.html deleted file mode 100644 index 8ef1806d31c3dc17346cbf134796ae8ea41c6bd5..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/cartpage.html +++ /dev/null @@ -1,41 +0,0 @@ -{% extends 'base.html' %} -{% load static %} -<!--Cart Page Title--> -{% block title %} -Your Cart -{% endblock title %} -<!--Cart Page Form--> -{% block content %} -<body> - <h1 class="h1">Your Cart</h1> - {% if cart_items %} - {% for item in cart_items %} - <div class="cart-item"> - <img src="{{ item.product.img.url }}" alt="{{ item.product.name }}"> - <div class="cart-item-info"> - <h3>{{ item.product.name }}</h3> - <p>Price per item: ${{ item.product.price }}</p> - <label for="quantity-{{ item.id }}"><b>Quantity:</b></label> - <form method="post" action="{% url 'update_cart' item.id %}" class="update-cart-form"> - {% csrf_token %} - <input type="number" id="quantity-{{ item.id }}" name="quantity-{{ item.id }}" min="1" value="{{ item.quantity }}"> - <button type="submit">Update</button> - </form> - <p>Total Price: $<span id="price-{{ item.id }}">{{ item.get_subtotal }}</span></p> - <form method="post" action="{% url 'remove_from_cart' item.id %}"> - {% csrf_token %} - <button type="submit">Remove</button> - </form> - </div> - </div> - {% endfor %} - <div class="finalize-order-container"> - <form action="{% url 'order' %}" method="get"> - <button type="submit" class="finalize-order-btn">Finalize Order</button> - </form> - </div> - {% else %} - <p>Your cart is empty.</p> - {% endif %} -</body> -{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/employee.html b/postgresTest/PROJECT1/templates/employee.html deleted file mode 100644 index bc25b4c3c493050412047787c4d317318494ab5d..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/employee.html +++ /dev/null @@ -1,49 +0,0 @@ -{% extends 'base.html' %} -{% load custom_filters %} - -{% block title %}Employee List{% endblock %} - -{% block content %} -<div class="container"> - <h2>Employee List</h2> - - <!-- Section for grouping employees by role --> - <div class="row"> - {% for role, employees in employees|group_by_role %} - <div class="col-md-6"> - <h3>{{ role|title }}</h3> - <ul> - {% for employee in employees %} - <li>{{ employee.get_full_name }} - {{ employee.email }}</li> - {% endfor %} - </ul> - </div> - {% endfor %} - </div> - - <!-- Section for displaying all employees in a table --> - <table class="table table-striped mt-4"> - <thead> - <tr> - <th>Name</th> - <th>Email</th> - <th>Role</th> - <th>Actions</th> - </tr> - </thead> - <tbody> - {% for employee in employees %} - <tr> - <td>{{ employee.get_full_name }}</td> - <td>{{ employee.email }}</td> - <td>{{ employee.role }}</td> - <td> - <!-- Actions like edit role could go here --> - <a href="{% url 'edit_role' employee.id %}" class="btn btn-primary">Edit Role</a> - </td> - </tr> - {% endfor %} - </tbody> - </table> -</div> -{% endblock %} diff --git a/postgresTest/PROJECT1/templates/inventory.html b/postgresTest/PROJECT1/templates/inventory.html deleted file mode 100644 index a6c3cadff21235eb7aaf1cd6bd72a48774a786c1..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/inventory.html +++ /dev/null @@ -1,228 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -<div class="container mt-4"> - <h2>Inventory Dashboard</h2> - <div class="row mb-4"> - <!-- Links to Add Data --> - <div class="col-md-4"> - <a href="{% url 'add_forecast' %}" class="btn btn-primary btn-block">Add Forecast</a> - </div> - <div class="col-md-4"> - <a href="{% url 'add_sale' %}" class="btn btn-primary btn-block">Add Sale</a> - </div> - <div class="col-md-4"> - <a href="{% url 'add_account' %}" class="btn btn-primary btn-block">Add Account</a> - </div> - </div> - <div class="row"> - <!-- Forecast Year Selector --> - <div class="col-md-6"> - <div class="form-group mt-4"> - <label for="forecast_year">Select Forecast Year</label> - <select class="form-control" id="forecast_year" name="forecast_year" onchange="updateForecastGraph()"> - {% for y in forecast_year_range %} - <option value="{{ y }}" {% if y == forecast_year %}selected{% endif %}>{{ y }}</option> - {% endfor %} - </select> - </div> - <!-- Forecast Graph --> - <div class="card mb-4"> - <div class="card-header"> - Forecast for {{ forecast_year }} - </div> - <div class="card-body"> - <canvas id="forecastChart"></canvas> - </div> - </div> - </div> - <!-- Sales Year Selector --> - <div class="col-md-6"> - <div class="form-group mt-4"> - <label for="sales_year">Select Sales Year</label> - <select class="form-control" id="sales_year" name="sales_year" onchange="updateSalesGraph()"> - {% for y in sales_year_range %} - <option value="{{ y }}" {% if y == sales_year %}selected{% endif %}>{{ y }}</option> - {% endfor %} - </select> - </div> - <!-- Sales Graph --> - <div class="card mb-4"> - <div class="card-header"> - Sales for {{ sales_year }} - </div> - <div class="card-body"> - <canvas id="salesChart"></canvas> - </div> - </div> - </div> - <!-- Account Graphs --> - <div class="col-md-6"> - <div class="card mb-4"> - <div class="card-header"> - Account Graphs - </div> - <div class="card-body"> - <canvas id="accountChart1"></canvas> - </div> - </div> - <div class="card mb-4"> - <div class="card-header"> - Account Graphs - </div> - <div class="card-body"> - <canvas id="accountChart2"></canvas> - </div> - </div> - </div> - <!-- Barcode Generator --> - <div class="col-md-6"> - <div class="card mb-4"> - <div class="card-header"> - Barcode Generator - </div> - <div class="card-body"> - <input type="text" id="barcodeValue" class="form-control" placeholder="Enter value for barcode"> - <button id="generateBarcode" class="btn btn-primary mt-2">Generate Barcode</button> - <svg id="barcode"></svg> - </div> - </div> - </div> - </div> -</div> - -<!-- Chart.js --> -<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> -<!-- JsBarcode --> -<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js"></script> -<script> - document.addEventListener("DOMContentLoaded", function() { - // Prepare data - var forecastLabels = {{ forecast_labels|safe }}; - var forecastData = {{ forecast_data|safe }}; - var salesLabels = {{ sales_labels|safe }}; - var salesData = {{ sales_data|safe }}; - var accountLabels = {{ account_labels|safe }}; - var accountData = {{ account_data|safe }}; - - // Log data for debugging - console.log('Forecast Labels:', forecastLabels); - console.log('Forecast Data:', forecastData); - console.log('Sales Labels:', salesLabels); - console.log('Sales Data:', salesData); - console.log('Account Labels:', accountLabels); - console.log('Account Data:', accountData); - - // Forecast Chart - var forecastCtx = document.getElementById('forecastChart').getContext('2d'); - var forecastChart = new Chart(forecastCtx, { - type: 'line', - data: { - labels: forecastLabels, - datasets: [{ - label: 'Forecast', - data: forecastData, - backgroundColor: 'rgba(54, 162, 235, 0.2)', - borderColor: 'rgba(54, 162, 235, 1)', - borderWidth: 1 - }] - }, - options: { - scales: { - y: { - beginAtZero: true - } - } - } - }); - - // Sales Chart - var salesCtx = document.getElementById('salesChart').getContext('2d'); - var salesChart = new Chart(salesCtx, { - type: 'bar', - data: { - labels: salesLabels, - datasets: [{ - label: 'Sales', - data: salesData, - backgroundColor: 'rgba(75, 192, 192, 0.2)', - borderColor: 'rgba(75, 192, 192, 1)', - borderWidth: 1 - }] - }, - options: { - scales: { - y: { - beginAtZero: true - } - } - } - }); - - // Account Graph 1 - var accountCtx1 = document.getElementById('accountChart1').getContext('2d'); - var accountChart1 = new Chart(accountCtx1, { - type: 'pie', - data: { - labels: accountLabels.slice(0, 2), // Assume first two categories are for account 1 - datasets: [{ - label: 'Accounts', - data: accountData.slice(0, 2), - backgroundColor: ['rgba(255, 99, 132, 0.2)', 'rgba(255, 206, 86, 0.2)'], - borderColor: ['rgba(255, 99, 132, 1)', 'rgba(255, 206, 86, 1)'], - borderWidth: 1 - }] - }, - options: { - responsive: true - } - }); - - // Account Graph 2 - var accountCtx2 = document.getElementById('accountChart2').getContext('2d'); - var accountChart2 = new Chart(accountCtx2, { - type: 'doughnut', - data: { - labels: accountLabels.slice(2), // Assume remaining categories are for account 2 - datasets: [{ - label: 'Accounts', - data: accountData.slice(2), - backgroundColor: ['rgba(153, 102, 255, 0.2)', 'rgba(255, 159, 64, 0.2)'], - borderColor: ['rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)'], - borderWidth: 1 - }] - }, - options: { - responsive: true - } - }); - - // Barcode Generator - document.getElementById('generateBarcode').addEventListener('click', function() { - var value = document.getElementById('barcodeValue').value; - JsBarcode("#barcode", value, { - format: "CODE39", - lineColor: "#000", - width: 2, - height: 100, - displayValue: true - }); - }); - - // Functions to update the graphs - window.updateForecastGraph = function() { - var selectedYear = document.getElementById('forecast_year').value; - var url = new URL(window.location.href); - url.searchParams.set('forecast_year', selectedYear); - window.location.href = url.href; - }; - - window.updateSalesGraph = function() { - var selectedYear = document.getElementById('sales_year').value; - var url = new URL(window.location.href); - url.searchParams.set('sales_year', selectedYear); - window.location.href = url.href; - }; - }); -</script> -{% endblock %} diff --git a/postgresTest/PROJECT1/templates/job.html b/postgresTest/PROJECT1/templates/job.html deleted file mode 100644 index ff9c04c13641c6a0aaaf3a4565f540dfbd991235..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/job.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends 'base.html' %} -{% load static %} -{% block content %} -<div class="container mt-5"> - <h2 class="text-center">Available Jobs</h2> - <div class="row"> - {% for job in jobs %} - <div class="col-md-4"> - <div class="card mb-4"> - <img src="{{ job.img.url }}" class="card-img-top" alt="{{ job.name }}"> - <div class="card-body"> - <h5 class="card-title">{{ job.name }}</h5> - <p class="card-text">{{ job.desc }}</p> - <p class="card-text"><strong>Price:</strong> {{ job.price }}</p> - <a href="{% url 'job_detail' job.id %}" class="btn btn-primary">View Details</a> - {% if job.form_url %} - <a href="{{ job.form_url }}" target="_blank" class="btn btn-secondary mt-2">Apply via Google Form</a> - {% endif %} - </div> - </div> - </div> - {% endfor %} - </div> -</div> -{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/leave.html b/postgresTest/PROJECT1/templates/leave.html deleted file mode 100644 index d4a158278dedbce3ab1e0bd6f4224c65a57fa9a2..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/leave.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -<div class="container mt-5"> - <h2 class="text-center">Leave Application</h2> - <form method="POST" action="{% url 'submit_leave' %}" target="_blank"> - {% csrf_token %} - <div class="form-group"> - <label for="leaveType">Select Leave Type</label> - <select class="form-control" id="leaveType" name="leave_type"> - {% for form in leave_forms %} - <option value="{{ form.id }}">{{ form.name }}</option> - <a href="{{ form.form_url }}" target="_blank">{{ form.name }}</a> - {% endfor %} - </select> - </div> - <button type="submit" class="btn btn-primary">Submit</button> - </form> -</div> -{% endblock content %} - diff --git a/postgresTest/PROJECT1/templates/meeting_list.html b/postgresTest/PROJECT1/templates/meeting_list.html deleted file mode 100644 index e41581cfe967651ba1a84d23f9414a04429c4629..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/meeting_list.html +++ /dev/null @@ -1,57 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Your Scheduled Meetings</title> - <link rel="stylesheet" href="{% static 'css/bootstrap.css' %}"> - <style> - .meeting-table { - margin-top: 20px; - width: 100%; - border-collapse: collapse; - } - - .meeting-table th, .meeting-table td { - padding: 12px; - border: 1px solid #ddd; - text-align: left; - } - - .meeting-table th { - background-color: #f2f2f2; - } - </style> -</head> -<body> - <div class="container"> - <h2 class="mt-4">Your Scheduled Meetings</h2> - <table class="meeting-table table table-striped"> - <thead> - <tr> - <th>Date</th> - <th>Start Time</th> - <th>End Time</th> - <th>Employee Type</th> - </tr> - </thead> - <tbody> - {% if meetings %} - {% for meeting in meetings %} - <tr> - <td>{{ meeting.date }}</td> - <td>{{ meeting.start_time }}</td> - <td>{{ meeting.end_time }}</td> - <td>{{ meeting.employee_type }}</td> - </tr> - {% endfor %} - {% else %} - <tr> - <td colspan="4">No meetings scheduled.</td> - </tr> - {% endif %} - </tbody> - </table> - </div> -</body> -</html> diff --git a/postgresTest/PROJECT1/templates/onboard_employee.html b/postgresTest/PROJECT1/templates/onboard_employee.html new file mode 100644 index 0000000000000000000000000000000000000000..1921e8c798b5b6f9d5de31a7d7c0340ce33a708c --- /dev/null +++ b/postgresTest/PROJECT1/templates/onboard_employee.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% load custom_filters %} +{% load static %} + +{% block title %} +Onboard New Employee +{% endblock title %} + +{% block content %} +<h1>Onboard New Employee</h1> + +<form method="POST"> + {% csrf_token %} + {{ form.as_p }} <!-- This renders all form fields as paragraphs --> + <button type="submit" class="btn btn-primary">Submit</button> +</form> +<!-- End of Onboard New Employee Section --> +{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/order.html b/postgresTest/PROJECT1/templates/order.html deleted file mode 100644 index 016b287685d805263f5c18c3183348d626605bfd..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/order.html +++ /dev/null @@ -1,34 +0,0 @@ -{% extends 'base.html' %} -{% load static %} -<!-- Order Page Title --> -{% block title %} -Order Payment -{% endblock title %} - -{% block content %} -<!-- Finalize Order Form --> -<body> - <div class="order-form"> - <h1>Order Details</h1> - <form action="{% url 'finalize_order' %}" method="post"> - {% csrf_token %} - <div> - <label for="address">Address:</label> - <input type="text" id="address" name="address" required> - </div> - {% for item_id in item_ids %} - <input type="hidden" name="item_ids" value="{{ item_id }}"> - {% endfor %} - - <h2>Payment Information</h2> - <p>Total Cost: {{ total_price }}</p> - <div> - <label for="billing_details">Billing Details:</label> - <input type="text" id="billing_details" name="billing_details"> - </div> - - <button type="submit" class="btn1">Submit Order</button> - </form> -</div> -</body> -{% endblock content %} \ No newline at end of file diff --git a/postgresTest/PROJECT1/templates/order_success.html b/postgresTest/PROJECT1/templates/order_success.html deleted file mode 100644 index ef2fe5e1c645da4cf4511f93ca1ec579b4161d41..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/order_success.html +++ /dev/null @@ -1,33 +0,0 @@ -{% extends 'base.html' %} -{% load static %} -<!-- Order Success Display --> -{% block content %} -<body> - <div class="order-summary"> - <h1>Success</h1> - <p>Order has been placed successfully!</p> - - <h2>Order Summary</h2> - <p>Order ID: {{ order.id }}</p> - <p>Order Date: {{ order.purchased_at }}</p> - <p>Total Price: ${{ order.total_price }}</p> - - <table> - <tr> - <th>Product</th> - <th>Quantity</th> - <th>Price</th> - </tr> - {% for item in order_items %} - <tr> - <td>{{ item.product.name }}</td> - <td>{{ item.quantity }}</td> - <td>${{ item.product.price }}</td> - - </tr> - {% endfor %} - </table> - <a href="{% url 'home' %}" class="btn2">Go back to home</a> - </div> -</body> -{% endblock %} diff --git a/postgresTest/PROJECT1/templates/product_detail.html b/postgresTest/PROJECT1/templates/product_detail.html deleted file mode 100644 index e6e5baeaa73360a386a63122902c41da446be851..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/product_detail.html +++ /dev/null @@ -1,121 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block title %} -{{ product.name }} -{% endblock title %} -<!-- Product Detail styling section --> -{% block content %} -<style> - body { - font-family: 'Arial', sans-serif; - line-height: 1.6; - margin: 0; - padding: 20px; - background: #f4f4f4; - } - - .container { - max-width: 1100px; - margin: auto; - overflow: hidden; - padding: 0 20px; - } - - h1 { - color: #333; - text-align: center; - margin-bottom: 1em; - } - - .product-image { - text-align: center; - margin-bottom: 2em; - } - - .product-image img { - max-width: 50%; - height: auto; - border: 1px solid #ddd; - border-radius: 5px; - box-shadow: 2px 2px 10px rgba(0,0,0,0.1); - } - - .product-info { - background: #fff; - padding: 20px; - margin-bottom: 20px; - border-radius: 5px; - box-shadow: 2px 2px 10px rgba(0,0,0,0.1); - } - - .product-info p { - color: #555; - font-size: 1.1em; - } - - .product-info p.price { - font-weight: bold; - font-size: 1.4em; - color: #333; - } - - .btn2 { - display: block; - width: 100%; - padding: 10px; - background-color: #5cb85c; - color: white; - border: none; - border-radius: 5px; - cursor: pointer; - font-size: 1.2em; - text-align: center; - text-decoration: none; - } - - .btn2:hover { - background-color: #4cae4c; - } - - form { - text-align: center; - margin-top: 20px; - } - - label { - display: block; - margin-bottom: 5px; - font-weight: bold; - } - - input[type="number"] { - padding: 10px; - margin-bottom: 10px; - border-radius: 5px; - border: 1px solid #ddd; - width: 100px; - text-align: center; - } -</style> -<!-- Product Display --> -<div class="container"> - <h1>{{ product.name }}</h1> - <div class="product-image"> - <img src="{{ product.img.url }}" alt="{{ product.name }}"> - </div> - <div class="product-info"> - <p>{{ product.desc }}</p> - <p class="price">Price: ${{ product.price }}</p> - </div> - - <!-- Add to Cart Form --> - <form method="post" action="{% url 'add_to_cart' product.id %}"> - {% csrf_token %} - <label for="quantity">Quantity:</label> - <input type="number" id="quantity" name="quantity" min="1" value="1"> - <button type="submit" class="btn2">Add To Cart</button> - </form> -</div> - -{% endblock content %} diff --git a/postgresTest/PROJECT1/templates/socialaccountlogin.html b/postgresTest/PROJECT1/templates/socialaccountlogin.html deleted file mode 100644 index 1bd1e67235cdf20e5806a84aa69ab93f3a5dc46b..0000000000000000000000000000000000000000 --- a/postgresTest/PROJECT1/templates/socialaccountlogin.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block title %}Edit Profile{% endblock title %} - -{% block content %} -<div class="container mt-5"> - <div class="row justify-content-center"> - <div class="col-md-8"> - <div class="card"> - <h5 class="card-header text-center">Edit Profile</h5> - <div class="card-body"> - <form method="post"> - {% csrf_token %} - {{ form.as_p }} - <button type="submit" class="btn btn-primary">Save changes</button> - </form> - </div> - </div> - </div> - </div> -</div> -{% endblock content %} diff --git a/postgresTest/PROJECT1/urls.py b/postgresTest/PROJECT1/urls.py index 06bbdf2f25b66dc474ef5f5442f6068f69d1f194..2227e392b7e7e027edbc19eedd9c0798636c8da1 100644 --- a/postgresTest/PROJECT1/urls.py +++ b/postgresTest/PROJECT1/urls.py @@ -2,43 +2,22 @@ from django.urls import path, include from . import views from django.conf import settings from django.conf.urls.static import static -from .views import delete_account,CustomLoginView, profile_view, profile_edit_view, edit_role, all_leave_forms +from .views import delete_account, CustomLoginView, profile_view, profile_edit_view, edit_role from django.contrib.auth import views as auth_views - - urlpatterns = [ path('', views.home, name='home'), - path('job/', views.jobs, name='job'), - path('testimonial/', views.testimonial, name='testimonial'), path('custom_login/', views.custom_login, name='custom_login'), path('register/', views.register, name='register'), - path('contact/', views.contact, name='contact'), path('delete_account/', delete_account, name='delete_account'), path('login/', CustomLoginView.as_view(), name='login'), path('logout/', views.logout_view, name='logout'), - path('dashboard/', views.dashboard, name='dashboard'), - path('error/', views.error_page, name='error'), - path('calendar/<int:year>/<int:month>/', views.calendar_view, name='calendar_view'), - path('calendar/', views.redirect_to_current_month, name='redirect_to_current_month'), - path('punch/', views.punch, name='punch'), - path('inventory/', views.inventory_view, name='inventory'), - path('add_forecast/', views.add_forecast, name='add_forecast'), - path('add_sale/', views.add_sale, name='add_sale'), - path('add_account/', views.add_account, name='add_account'), path('accounts/profile/', profile_view, name='profile'), path('accounts/profile/edit/', profile_edit_view, name='profile_edit'), path('accounts/', include('allauth.urls')), path('employees/', views.employee_list, name='employee_list'), - path('employees/', views.employee_list, name='employee'), path('edit-role/<int:user_id>/', edit_role, name='edit_role'), - path('job/<int:id>/', views.job_detail, name='job_detail'), - path('leave/', views.leave, name='leave'), - path('submit_leave/', views.submit_leave, name='submit_leave'), - path('all_leave_forms/', all_leave_forms, name='all_leave_forms'), - path('schedule_meeting/', views.schedule_meeting, name='schedule_meeting'), - path('meetings/', views.meeting_list, name='meeting_list') + path('onboard/', views.onboard_employee, name='onboard_employee'), + path('onboarding-success/', views.onboarding_success, name='onboarding_success'), + path('dashboard/', views.dashboard, name='dashboard') ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - - - diff --git a/postgresTest/PROJECT1/views.py b/postgresTest/PROJECT1/views.py index 5c983924b4132a32ebd56d8fbb83ab306b216f1a..0cbc0ebfa5d8eb69c17356204e1afbdd1a4bc299 100644 --- a/postgresTest/PROJECT1/views.py +++ b/postgresTest/PROJECT1/views.py @@ -1,84 +1,34 @@ - from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout -from django.contrib.auth.decorators import login_required, user_passes_test +from django.contrib.auth.decorators import login_required from django.contrib import messages -from .models import Job, JobRating, Contact, Forecast, Sale, Account, Punch, CustomUser, LeaveForm, SubmittedLeaveForm, Meeting -from .forms import CustomUserCreationForm, ContactForm, ForecastForm, SaleForm, AccountForm, RoleAssignmentForm, ScheduleMeetingForm -from django.db.models import Avg -from datetime import datetime -from django.http import JsonResponse -from django.utils import timezone +from .models import Job, CustomUser +from .forms import CustomUserCreationForm, ContactForm, RoleAssignmentForm, OnboardingForm from django.contrib.auth.views import LoginView from django.contrib.auth.forms import UserChangeForm -import calendar - -from django.utils import timezone -from datetime import datetime @login_required -def meeting_list(request): - meetings = Meeting.objects.filter(user=request.user) - return render(request, 'meeting_list.html', {'meetings': meetings}) - -@login_required -def schedule_meeting(request): - if request.method == 'POST': - selected_day = request.POST.get('selectedDay') - employee_type = request.POST.get('employeeType') - start_time = request.POST.get('startTime') - end_time = request.POST.get('endTime') - - # Get the year and month from the session - year = request.session.get('calendar_year') - month = request.session.get('calendar_month') - - # Construct the full date string using the year, month, and day - meeting_date_str = f"{year}-{month:02d}-{int(selected_day):02d}" - meeting_date = datetime.strptime(meeting_date_str, "%Y-%m-%d").date() - - # Convert start_time and end_time to time objects - start_time_obj = datetime.strptime(start_time, "%H:%M").time() - end_time_obj = datetime.strptime(end_time, "%H:%M").time() - - # Create and save the meeting - Meeting.objects.create( - user=request.user, - date=meeting_date, - start_time=start_time_obj, - end_time=end_time_obj, - employee_type=employee_type - ) - - # Redirect back to the calendar view - return redirect('calendar_view', year=year, month=month) - +def dashboard(request): + return render(request, 'dashboard.html') -# Fetch all leave forms - consolidated function @login_required -def all_leave_forms(request): - if request.user.is_staff: - leave_forms = SubmittedLeaveForm.objects.all() # Fetch all submitted leave forms +def onboard_employee(request): + if request.method == 'POST': # This handles the form submission + form = OnboardingForm(request.POST) + if form.is_valid(): + form.save() # This saves the form data to the database (Employee model) + messages.success(request, 'Employee has been successfully onboarded.') + return redirect('onboarding_success') else: - leave_forms = SubmittedLeaveForm.objects.filter(employee=request.user) # Fetch only the leave forms submitted by the logged-in employee + form = OnboardingForm() # This displays an empty form for a GET request + return render(request, 'onboard_employee.html', {'form': form}) - return render(request, 'all_leave_forms.html', {'leave_forms': leave_forms}) @login_required -def leave(request): - leave_forms = LeaveForm.objects.all() - return render(request, 'leave.html', {'leave_forms': leave_forms}) +def onboarding_success(request): + return render(request, 'onboarding_success.html') -@login_required -def submit_leave(request): - leave_type_id = request.POST.get('leave_type') - leave_form = LeaveForm.objects.get(id=leave_type_id) - return redirect(leave_form.form_url) - -def job_detail(request, id): - job = get_object_or_404(Job, id=id) - return render(request, 'job_detail.html', {'job': job}) @login_required def edit_role(request, user_id): @@ -92,18 +42,22 @@ def edit_role(request, user_id): form = RoleAssignmentForm(instance=user) return render(request, 'edit_role.html', {'form': form, 'user': user}) + class CustomLoginView(LoginView): template_name = 'login.html' + @login_required def employee_list(request): employees = CustomUser.objects.all().order_by('role') return render(request, 'employee.html', {'employees': employees}) + @login_required def profile_view(request): return render(request, 'profile.html') + @login_required def profile_edit_view(request): if request.method == 'POST': @@ -115,194 +69,10 @@ def profile_edit_view(request): form = UserChangeForm(instance=request.user) return render(request, 'profile_edit.html', {'form': form}) -def inventory_view(request): - forecast_year = request.GET.get('forecast_year', datetime.now().year) - sales_year = request.GET.get('sales_year', datetime.now().year) - - forecasts = Forecast.objects.filter(year=forecast_year) - sales = Sale.objects.filter(year=sales_year) - accounts = Account.objects.all() - - forecast_year_range = range(2023, 2032) # Year range for forecasts - sales_year_range = range(2015, 2026) # Year range for sales - - forecast_labels = [f.month for f in forecasts] - forecast_data = [f.value for f in forecasts] - sales_labels = [s.quarter for s in sales] - sales_data = [s.value for s in sales] - account_labels = [a.category for a in accounts] - account_data = [a.value for a in accounts] - - return render(request, 'inventory.html', { - 'forecasts': forecasts, - 'sales': sales, - 'accounts': accounts, - 'forecast_year': int(forecast_year), - 'sales_year': int(sales_year), - 'forecast_year_range': forecast_year_range, - 'sales_year_range': sales_year_range, - 'forecast_labels': forecast_labels, - 'forecast_data': forecast_data, - 'sales_labels': sales_labels, - 'sales_data': sales_data, - 'account_labels': account_labels, - 'account_data': account_data, - }) - -def add_sale(request): - if request.method == 'POST': - form = SaleForm(request.POST) - if form.is_valid(): - form.save() - return redirect('inventory') - else: - form = SaleForm() - return render(request, 'add_sale.html', {'form': form}) - -def add_forecast(request): - if request.method == 'POST': - form = ForecastForm(request.POST) - if form.is_valid(): - form.save() - return redirect('inventory') - else: - form = ForecastForm() - return render(request, 'add_forecast.html', {'form': form}) - -def add_account(request): - if request.method == 'POST': - form = AccountForm(request.POST) - if form.is_valid(): - form.save() - return redirect('inventory') - else: - form = AccountForm() - return render(request, 'add_account.html', {'form': form}) - -@login_required -def redirect_to_current_month(request): - now = timezone.now() - return redirect('calendar_view', year=now.year, month=now.month) - -@login_required -def calendar_view(request, year, month): - user = request.user - - - # Convert month to int and ensure it's within the 1-12 range - month = int(month) - if month < 1: - month = 1 - elif month > 12: - month = 12 - - # Calculate previous and next month and year - previous_month = month - 1 if month > 1 else 12 - previous_year = year if month > 1 else year - 1 - next_month = month + 1 if month < 12 else 1 - next_year = year if month < 12 else year + 1 - - # Generate calendar data for the month - cal = calendar.Calendar() - month_days = cal.monthdayscalendar(year, month) - - # Fetch punch data (assuming it's filtered by date) - punch_data = {} - for day in range(1, calendar.monthrange(year, month)[1] + 1): - date = timezone.datetime(year, month, day).date() - punches = Punch.objects.filter(user=user, date=date) - punch_data[day] = punches - - # Determine the current punch status - today = timezone.now().date() - current_punch = Punch.objects.filter(user=user, date=today, punch_out__isnull=True).order_by('-punch_in').first() - punch_button_text = 'Punch In' if not current_punch else 'Punch Out' - punch_button_class = 'btn-success' if not current_punch else 'btn-danger' - - # Get month name - month_name = calendar.month_name[month] - - # Store the current year and month in the session for use in scheduling - request.session['calendar_year'] = year - request.session['calendar_month'] = month - - # Initialize the form before any conditionals - form = ScheduleMeetingForm() - - # Handle meeting scheduling form submission - if request.method == 'POST': - form = ScheduleMeetingForm(request.POST) - if form.is_valid(): - selected_day = request.POST.get('selectedDay') - # Construct the full date string - meeting_date_str = f"{year}-{month:02d}-{int(selected_day):02d}" - meeting_date = timezone.datetime.strptime(meeting_date_str, "%Y-%m-%d").date() - meeting = form.save(commit=False) - meeting.user = user - meeting.date = meeting_date - meeting.save() - return redirect('calendar_view', year=year, month=month) - - # Time options for the dropdown - time_options = [f"{hour:02}:00" for hour in range(8, 19)] + [f"{hour:02}:30" for hour in range(8, 19)] - - # Render the template with the context data - context = { - 'year': year, - 'month': month, - 'month_name': month_name, - 'calendar_data': month_days, - 'punch_data': punch_data, - 'current_punch': current_punch, - 'punch_button_text': punch_button_text, - 'punch_button_class': punch_button_class, - 'previous_year': previous_year, - 'previous_month': previous_month, - 'next_year': next_year, - 'next_month': next_month, - 'form': form, - 'time_options': time_options, # Pass the time options to the template - } - - return render(request, 'calendar.html', context) - -@login_required -def punch(request): - if request.method == "POST": - user = request.user - today = timezone.now().date() - - current_punch = Punch.objects.filter(user=user, date=today, punch_out__isnull=True).order_by('-punch_in').first() - - if current_punch: - current_punch.punch_out = timezone.now() - total_time = current_punch.punch_out - current_punch.punch_in - current_punch.total_time = total_time - current_punch.save() - return JsonResponse({ - "status": "punched_out", - "punch_out": current_punch.punch_out.strftime("%Y-%m-%d %H:%M:%S"), - "total_time": str(total_time) - }) - else: - new_punch = Punch.objects.create(user=user, date=today, punch_in=timezone.now()) - return JsonResponse({ - "status": "punched_in", - "punch_in": new_punch.punch_in.strftime("%Y-%m-%d %H:%M:%S") - }) - - return JsonResponse({"error": "Invalid request"}, status=400) def error_page(request): return render(request, 'error.html') -@login_required -def dashboard(request): - kpi_data = { - 'retention_rate': {'Q1': 95, 'Q2': 93, 'Q3': 90, 'Q4': 92}, - 'time_to_fill': {'Q1': 30, 'Q2': 28, 'Q3': 35, 'Q4': 32}, - } - return render(request, 'dashboard.html', {'kpi_data': kpi_data}) def register(request): if request.method == 'POST': @@ -316,11 +86,13 @@ def register(request): form = CustomUserCreationForm() return render(request, 'register.html', {'form': form}) + def logout_view(request): auth_logout(request) messages.success(request, 'You have successfully logged out.') return redirect('home') + @login_required def delete_account(request): if request.method == 'POST': @@ -329,25 +101,26 @@ def delete_account(request): messages.success(request, 'Your account has been successfully deleted.') return redirect('login') + def home(request): jobs = Job.objects.all() form = ContactForm() context = { 'jobs': jobs, - 'form': form, + 'form': form, } return render(request, 'index.html', context) -def contact(request): - return render(request, 'contact.html') def jobs(request): jobs = Job.objects.all() return render(request, 'job.html', {'jobs': jobs}) + def testimonial(request): return render(request, 'testimonial.html') + def custom_login(request): if request.method == 'POST': username = request.POST['username']