This project is a Cash Collection application with a RESTful backend and mobile and web frontends. It manages tasks for Cash Collectors who collect cash from customers and deliver it to Managers. The project includes features to ensure that Cash Collectors do not abuse the system.
-
Database Models:
User
: Custom user model extendingAbstractUser
with roles for Cash Collectors and Managers.Customer
: Model to store customer details.Task
: Model to store tasks related to cash collection, including customer, amount due, collection status, and timestamps.
-
Admin Interface:
- Manage users, customers, and tasks.
- View status of tasks and Cash Collectors' freeze status.
-
RESTful API:
- Endpoints to manage tasks, including creation, collection, delivery, and status checks.
- JWT authentication for secure access.
- API to generate CSV reports for tasks.
-
CSV Output:
- Generate CSV reports for tasks with filters for completed, assigned, and delivered tasks.
-
Clone the repository:
git clone https://github.com/amremaish/CashCollector cd cash-collector
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py migrate
-
Create a superuser:
python manage.py createsuperuser
-
Run the development server:
python manage.py runserver
You can view it from here.
Description: Authenticate a user and obtain a token.
Method: POST
Endpoint: /api/users/login
curl -X POST http://localhost:8000/api/users/login \
-H "Content-Type: application/json" \
-d '{
"username": "cash_collector",
"password": "123456"
}'
Description: Retrieve the current authenticated user’s details.
Method: GET
Endpoint: /api/users/me
curl -X GET http://localhost:8000/api/users/me \
-H "Authorization: Bearer <TOKEN>"
Description: Retrieve Cash Collector status whether frozen or not
Method: GET
Endpoint: /api/users/status
curl -X GET 'http://localhost:8000/api/users/status' \
-H "Authorization: Bearer <TOKEN>"
Description: Add a new cash collector user.
Method: PUT
Endpoint: /api/users/add/cash-collector
curl -X PUT http://localhost:8000/api/users/add/cash-collector \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"username": "cash_collector",
"email": "[email protected]",
"first_name": "Amr",
"last_name": "Emaish",
"password": "123456"
}'
Description: Sign up a new manager user.
Method: PUT
Endpoint: /api/users/manager/signup
curl -X PUT http://localhost:8000/api/users/manager/signup \
-H "Content-Type: application/json" \
-d '{
"username": "manager",
"email": "[email protected]",
"first_name": "Amr",
"last_name": "Emaish",
"password": "123456"
}'
Description: Add a new customer.
Method: PUT
Endpoint: /api/users/add/customer
curl -X PUT http://localhost:8000/api/users/add/customer \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"name": "test customer",
"address": "Cairo / Egypt"
}'
Description: Retrieve a list of customers with pagination.
Method: GET
Endpoint: /api/users/customers?page=2&page_size=5
curl -X GET http://localhost:8000/api/users/customers?page=2&page_size=5 \
-H "Authorization: Bearer <TOKEN>"
Description: Add a new task for a customer.
Method: PUT
Endpoint: /api/tasks/create
curl -X PUT http://localhost:8000/api/tasks/create \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"customer": 4
}'
Description: Retrieve a list of tasks with pagination.
Method: GET
Endpoint: /api/tasks?page=1&page_size=5
curl -X GET http://localhost:8000/api/tasks?page=1&page_size=5 \
-H "Authorization: Bearer <TOKEN>"
Description: Retrieve the next task.
Method: GET
Endpoint: /api/tasks/next_task
curl -X GET http://localhost:8000/api/tasks/next_task \
-H "Authorization: Bearer <TOKEN>"
Description: Collect payment for a task.
Method: POST
Endpoint: /api/tasks/19/collect
curl -X POST http://localhost:8000/api/tasks/19/collect \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"amount_due": 3000
}'
Description: Mark a task as delivered.
Method: POST
Endpoint: /api/tasks/16/deliver
curl -X POST http://localhost:8000/api/tasks/16/deliver \
-H "Authorization: Bearer <TOKEN>"
Description: Generate a CSV file for tasks.
Method: GET
Endpoint: /api/tasks/generate_csv?assigned=1&delivered=1
curl -X GET http://localhost:8000/api/tasks/generate_csv?assigned=1&delivered=1 \
-H "Authorization: Bearer <TOKEN>"