first commit
This commit is contained in:
9
app/api/v1/payroll/__init__.py
Normal file
9
app/api/v1/payroll/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.v1.payroll import scheme, pay_rate, payment_record
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
router.include_router(scheme.router, prefix='/scheme')
|
||||
router.include_router(pay_rate.router, prefix='/pay-rate')
|
||||
router.include_router(payment_record.router, prefix='/payment-record')
|
||||
BIN
app/api/v1/payroll/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/deal.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/deal.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/pay_rate.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/pay_rate.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/payment_record.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/payment_record.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/payroll.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/payroll.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/scheme.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/scheme.cpython-311.pyc
Normal file
Binary file not shown.
BIN
app/api/v1/payroll/__pycache__/summaries.cpython-311.pyc
Normal file
BIN
app/api/v1/payroll/__pycache__/summaries.cpython-311.pyc
Normal file
Binary file not shown.
57
app/api/v1/payroll/pay_rate.py
Normal file
57
app/api/v1/payroll/pay_rate.py
Normal file
@ -0,0 +1,57 @@
|
||||
from time import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app import mongo
|
||||
from app.utils.response_util import response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/get-all", tags=[""])
|
||||
async def get_all_pay_rates():
|
||||
start_time = time()
|
||||
|
||||
pay_rates = await mongo.pay_rates_collection.find(
|
||||
{}, {"_id": False}
|
||||
).sort("id", mongo.asc).to_list()
|
||||
|
||||
return response({
|
||||
"payRates": pay_rates
|
||||
}, start_time=start_time)
|
||||
|
||||
|
||||
@router.post("/create", tags=[""])
|
||||
async def create_pay_rate(params: dict):
|
||||
start_time = time()
|
||||
data = params["data"]
|
||||
data["id"] = await mongo.get_next_id(mongo.pay_rates_collection)
|
||||
|
||||
await mongo.pay_rates_collection.insert_one(data)
|
||||
return response({
|
||||
"message": "Тариф успешно создан",
|
||||
"ok": True
|
||||
}, start_time=start_time)
|
||||
|
||||
|
||||
@router.post("/update", tags=[""])
|
||||
async def update_pay_rate(params: dict):
|
||||
start_time = time()
|
||||
data = params["data"]
|
||||
|
||||
await mongo.pay_rates_collection.update_one({"id": data["id"]}, {"$set": data})
|
||||
return response({
|
||||
"message": "Тариф успешно обновлен",
|
||||
"ok": True
|
||||
}, start_time=start_time)
|
||||
|
||||
|
||||
@router.post("/delete", tags=[""])
|
||||
async def delete_pay_rate(params: dict):
|
||||
start_time = time()
|
||||
|
||||
await mongo.pay_rates_collection.delete_one({"id": params["payRateId"]})
|
||||
return response({
|
||||
"message": "Тариф успешно удален",
|
||||
"ok": True
|
||||
}, start_time=start_time)
|
||||
86
app/api/v1/payroll/payment_record.py
Normal file
86
app/api/v1/payroll/payment_record.py
Normal file
@ -0,0 +1,86 @@
|
||||
from time import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
from starlette.requests import Request
|
||||
|
||||
from app import mongo
|
||||
from app.utils.response_util import response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/get", tags=[""])
|
||||
async def get(page: int = 0, items_per_page: int = 10):
|
||||
start_time = time()
|
||||
|
||||
total = await mongo.payment_records_collection.count_documents({})
|
||||
payment_records = await mongo.payment_records_collection.find({}, {
|
||||
"_id": False
|
||||
}).limit(items_per_page).skip(items_per_page * (page - 1)).to_list(length=None)
|
||||
|
||||
for payment_record in payment_records:
|
||||
payment_record["user"] = await mongo.users_collection.find_one({"id": payment_record["userId"]}, {"_id": False})
|
||||
payment_record["createdByUser"] = await mongo.users_collection.find_one({"id": payment_record["createdByUserId"]}, {"_id": False})
|
||||
|
||||
return response({
|
||||
"paginationInfo": {
|
||||
"totalItems": total,
|
||||
"totalPages": round(total / items_per_page)
|
||||
},
|
||||
"paymentRecords": payment_records
|
||||
}, start_time=start_time)
|
||||
|
||||
|
||||
@router.post("/create", tags=[""])
|
||||
async def create(params: dict, request: Request):
|
||||
start_time = time()
|
||||
|
||||
data = params["data"]
|
||||
work_units = data.get("workUnits", 0)
|
||||
|
||||
user = await mongo.users_collection.find_one({"id": data["user"]["id"]}, {"_id": False})
|
||||
pay_rate = await mongo.pay_rates_collection.find_one(
|
||||
{"id": user.get("payRate", {}).get("id")},
|
||||
{"_id": False}
|
||||
)
|
||||
|
||||
payroll_scheme = pay_rate.get("payrollScheme", {})
|
||||
total_amount = 0.0
|
||||
|
||||
if payroll_scheme.get("key") == "hourly":
|
||||
overtime_threshold = pay_rate.get("overtimeThreshold", 0)
|
||||
base_hours = min(work_units, overtime_threshold)
|
||||
overtime_hours = max(work_units - overtime_threshold, 0)
|
||||
|
||||
base_rate = pay_rate.get("baseRate", 0)
|
||||
overtime_rate = pay_rate.get("overtimeRate", base_rate)
|
||||
|
||||
total_amount = round(base_hours * base_rate + overtime_hours * overtime_rate, 2)
|
||||
|
||||
elif payroll_scheme.get("key") == "hourly":
|
||||
base_rate = pay_rate.get("baseRate", 0)
|
||||
total_amount = base_rate * work_units
|
||||
|
||||
data["id"] = await mongo.get_next_id(mongo.payment_records_collection)
|
||||
data["userId"] = user["id"]
|
||||
data["createdByUserId"] = request.state.user["id"]
|
||||
data["createdAt"] = mongo.created_at()
|
||||
data["amount"] = total_amount
|
||||
data["payrollScheme"] = payroll_scheme
|
||||
|
||||
await mongo.payment_records_collection.insert_one(data)
|
||||
return response({
|
||||
"message": "Начисление создано",
|
||||
"ok": True
|
||||
}, start_time=start_time)
|
||||
|
||||
|
||||
@router.post("/delete", tags=[""])
|
||||
async def delete(params: dict):
|
||||
start_time = time()
|
||||
|
||||
await mongo.payment_records_collection.delete_one({"id": params["paymentRecordId"]})
|
||||
return response({
|
||||
"message": "Начисление удалено",
|
||||
"ok": True
|
||||
}, start_time=start_time)
|
||||
21
app/api/v1/payroll/payroll.py
Normal file
21
app/api/v1/payroll/payroll.py
Normal file
@ -0,0 +1,21 @@
|
||||
from time import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app import mongo
|
||||
from app.utils.response_util import response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/scheme/get-all", tags=[""])
|
||||
async def get_all_schemes():
|
||||
start_time = time()
|
||||
|
||||
schemes = await mongo.pay_rate_schemes_collection.find(
|
||||
{}, {"_id": False}
|
||||
).sort("id", mongo.asc).to_list()
|
||||
|
||||
return response({
|
||||
"payrollSchemas": schemes
|
||||
}, start_time=start_time)
|
||||
21
app/api/v1/payroll/scheme.py
Normal file
21
app/api/v1/payroll/scheme.py
Normal file
@ -0,0 +1,21 @@
|
||||
from time import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app import mongo
|
||||
from app.utils.response_util import response
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/get-all", tags=[""])
|
||||
async def get_all_schemes():
|
||||
start_time = time()
|
||||
|
||||
schemes = await mongo.pay_rate_schemes_collection.find(
|
||||
{}, {"_id": False}
|
||||
).sort("id", mongo.asc).to_list()
|
||||
|
||||
return response({
|
||||
"payrollSchemas": schemes
|
||||
}, start_time=start_time)
|
||||
Reference in New Issue
Block a user