Employee Attendance Done!!
TODO: Only need to reload Attendance and Employee Attendance on Save
This commit is contained in:
parent
bd05e6bb17
commit
cda157f05c
brewman
overlord/src/app/employee-attendance
@ -26,14 +26,14 @@ def get_db() -> Session:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=schemas.Attendance)
|
||||||
def attendance_blank(
|
def attendance_blank(
|
||||||
request: Request, user: UserToken = Security(get_user, scopes=["attendance"])
|
request: Request, user: UserToken = Security(get_user, scopes=["attendance"])
|
||||||
):
|
):
|
||||||
return {"date": get_date(request.session), "body": []}
|
return {"date": get_date(request.session), "body": []}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{date_}")
|
@router.get("/{date_}", response_model=schemas.Attendance)
|
||||||
def attendance_date(
|
def attendance_date(
|
||||||
date_: str,
|
date_: str,
|
||||||
request: Request,
|
request: Request,
|
||||||
@ -90,10 +90,10 @@ def attendance_date_report(date_: date, db: Session):
|
|||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{date_}")
|
@router.post("/{date_}", response_model=schemas.Attendance)
|
||||||
def save(
|
def save(
|
||||||
date_: str,
|
date_: str,
|
||||||
data: schemas.AttendanceIn,
|
data: schemas.Attendance,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["attendance"]),
|
user: UserToken = Security(get_user, scopes=["attendance"]),
|
||||||
):
|
):
|
||||||
|
@ -151,7 +151,7 @@ async def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@router.get("/query",) # "Authenticated"
|
@router.get("/query")
|
||||||
async def show_term(
|
async def show_term(
|
||||||
q: str,
|
q: str,
|
||||||
c: int = None,
|
c: int = None,
|
||||||
@ -159,7 +159,7 @@ async def show_term(
|
|||||||
current_user: UserToken = Depends(get_user),
|
current_user: UserToken = Depends(get_user),
|
||||||
):
|
):
|
||||||
list_ = []
|
list_ = []
|
||||||
for index, item in enumerate(AccountBase.list(10, q, dbsession=db)):
|
for index, item in enumerate(AccountBase.query(q=q, type_=10, db=db)):
|
||||||
list_.append(
|
list_.append(
|
||||||
{
|
{
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
|
@ -28,7 +28,7 @@ def get_db() -> Session:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=schemas.EmployeeAttendance)
|
||||||
def show_blank(
|
def show_blank(
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["attendance"]),
|
user: UserToken = Security(get_user, scopes=["attendance"]),
|
||||||
@ -41,9 +41,9 @@ def show_blank(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{id_}")
|
@router.get("/{id_}", response_model=schemas.EmployeeAttendance)
|
||||||
def employee_attendance_report(
|
def employee_attendance_report(
|
||||||
id_: int,
|
id_: uuid.UUID,
|
||||||
request: Request,
|
request: Request,
|
||||||
s: str = None,
|
s: str = None,
|
||||||
f: str = None,
|
f: str = None,
|
||||||
@ -90,23 +90,23 @@ def employee_attendance(employee: Employee, start_date: date, finish_date: date,
|
|||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
att = 0 if att is None else att.attendance_type
|
att = 0 if att is None else att.attendance_type
|
||||||
prints, hours, worked = get_prints(employee.id, item, db)
|
prints, hours_worked, full_day = get_prints(employee.id, item, db)
|
||||||
list_.append(
|
list_.append(
|
||||||
{
|
schemas.EmployeeAttendanceItem(
|
||||||
"date": item.strftime("%d-%b-%Y"),
|
date=item.strftime("%d-%b-%Y"),
|
||||||
"attendanceType": {"id": att},
|
attendanceType={"id": att},
|
||||||
"prints": prints,
|
prints=prints,
|
||||||
"hours": hours,
|
hoursWorked=hours_worked,
|
||||||
"worked": worked,
|
fullDay=full_day
|
||||||
}
|
)
|
||||||
)
|
)
|
||||||
return list_
|
return list_
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{id_}")
|
@router.post("/{id_}", response_model=schemas.EmployeeAttendance)
|
||||||
def save_employee_attendance(
|
def save_employee_attendance(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
data: schemas.EmployeeAttendanceIn,
|
data: schemas.EmployeeAttendance,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["attendance"]),
|
user: UserToken = Security(get_user, scopes=["attendance"]),
|
||||||
):
|
):
|
||||||
@ -115,14 +115,14 @@ def save_employee_attendance(
|
|||||||
employee: Employee = db.query(Employee).filter(Employee.id == id_).first()
|
employee: Employee = db.query(Employee).filter(Employee.id == id_).first()
|
||||||
for item in data.body:
|
for item in data.body:
|
||||||
if start_date is None:
|
if start_date is None:
|
||||||
start_date = item.date
|
start_date = item.date_
|
||||||
finish_date = item.date
|
finish_date = item.date_
|
||||||
|
|
||||||
attendance_type = item.attendance_type.id_
|
attendance_type = item.attendance_type.id_
|
||||||
if attendance_type != 0:
|
if attendance_type != 0:
|
||||||
attendance = Attendance(
|
attendance = Attendance(
|
||||||
employee_id=employee.id,
|
employee_id=employee.id,
|
||||||
date=item.date,
|
date=item.date_,
|
||||||
attendance_type=attendance_type,
|
attendance_type=attendance_type,
|
||||||
user_id=user.id_,
|
user_id=user.id_,
|
||||||
)
|
)
|
||||||
|
@ -21,6 +21,8 @@ class LedgerItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -42,10 +44,14 @@ class Ledger(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -73,6 +79,8 @@ class BalanceSheet(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -110,10 +118,14 @@ class CashFlow(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -139,6 +151,8 @@ class ClosingStock(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -156,6 +170,8 @@ class DaybookItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -176,10 +192,14 @@ class Daybook(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -207,10 +227,14 @@ class NetTransactions(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -231,6 +255,8 @@ class ProductLedgerItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -252,10 +278,14 @@ class ProductLedger(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -285,10 +315,14 @@ class ProfitLoss(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
@ -305,6 +339,8 @@ class PurchaseEntriesItem(BaseModel):
|
|||||||
|
|
||||||
@validator("date_", pre=True)
|
@validator("date_", pre=True)
|
||||||
def parse_date(cls, value):
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -324,10 +360,14 @@ class PurchaseEntries(BaseModel):
|
|||||||
|
|
||||||
@validator("start_date", pre=True)
|
@validator("start_date", pre=True)
|
||||||
def parse_start_date(cls, value):
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
@validator("finish_date", pre=True)
|
@validator("finish_date", pre=True)
|
||||||
def parse_finish_date(cls, value):
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from typing import List, Optional
|
|||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
|
from brewman.schemas.master import AccountLink
|
||||||
|
|
||||||
|
|
||||||
class Voucher(BaseModel):
|
class Voucher(BaseModel):
|
||||||
@ -95,18 +96,65 @@ class AttendanceItem(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
|
|
||||||
class AttendanceIn(BaseModel):
|
|
||||||
|
class Attendance(BaseModel):
|
||||||
|
date_: Optional[date]
|
||||||
body: List[AttendanceItem]
|
body: List[AttendanceItem]
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
|
|
||||||
class EmployeeAttendanceItem(BaseModel):
|
class EmployeeAttendanceItem(BaseModel):
|
||||||
date: date
|
date_: date
|
||||||
attendance_type: AttendanceType
|
attendance_type: AttendanceType
|
||||||
|
prints: str
|
||||||
|
hours_worked: str
|
||||||
|
full_day: Optional[bool]
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
|
|
||||||
class EmployeeAttendanceIn(BaseModel):
|
class EmployeeAttendance(BaseModel):
|
||||||
|
start_date: Optional[date]
|
||||||
|
finish_date: Optional[date]
|
||||||
|
employee: Optional[AccountLink]
|
||||||
body: List[EmployeeAttendanceItem]
|
body: List[EmployeeAttendanceItem]
|
||||||
|
|
||||||
|
@validator("start_date", pre=True)
|
||||||
|
def parse_start_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
@validator("finish_date", pre=True)
|
||||||
|
def parse_finish_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
|
|
||||||
class Fingerprint(BaseModel):
|
class Fingerprint(BaseModel):
|
||||||
id: uuid.UUID
|
id: uuid.UUID
|
||||||
|
@ -58,9 +58,9 @@
|
|||||||
{{row.prints}}
|
{{row.prints}}
|
||||||
<mat-icon *ngIf="!form.controls.attendances.controls[i].pristine">new_releases</mat-icon>
|
<mat-icon *ngIf="!form.controls.attendances.controls[i].pristine">new_releases</mat-icon>
|
||||||
<mat-chip-list class="no-bg">
|
<mat-chip-list class="no-bg">
|
||||||
<mat-chip *ngIf="row.hours.length" class="no-bg" [selected]="row.worked !== 'Error'"
|
<mat-chip *ngIf="row.hoursWorked.length" class="no-bg" [selected]="true"
|
||||||
[color]="row.worked === true ? 'primary' : 'warn'">
|
[color]="row.fullDay === true ? 'primary' : 'warn'">
|
||||||
{{row.hours}}
|
{{row.hoursWorked}}
|
||||||
</mat-chip>
|
</mat-chip>
|
||||||
</mat-chip-list>
|
</mat-chip-list>
|
||||||
</mat-cell>
|
</mat-cell>
|
||||||
|
@ -16,8 +16,8 @@ export class EmployeeAttendanceItem {
|
|||||||
date: string;
|
date: string;
|
||||||
attendanceType: AttendanceType;
|
attendanceType: AttendanceType;
|
||||||
prints: string;
|
prints: string;
|
||||||
hours: string;
|
hoursWorked: string;
|
||||||
worked: string;
|
fullDay?: boolean;
|
||||||
|
|
||||||
public constructor(init?: Partial<EmployeeAttendanceItem>) {
|
public constructor(init?: Partial<EmployeeAttendanceItem>) {
|
||||||
Object.assign(this, init);
|
Object.assign(this, init);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user