TypeClient Documentation
Type Client Controller Documentation
File: /controllers/typeClientController.php
Purpose: Manages client types/categories, classifications, and related business information
Last Updated: December 20, 2024
Total Functions: 8
Lines of Code: 313
---
๐ Overview
The Type Client Controller manages client type/category classification in the ERP system. It handles:
- โข Creating and editing client types (customer categories)
- โข Managing client type classifications and conditions
- โข Tracking client type-specific information (tax registration, contact details)
- โข Supporting obgyn-specific type classifications
- โข Soft delete functionality (temporary delete/restore)
- โข Integration with YouTube help links
- โข WebAPI integration for external systems
Primary Functions
- โ Create new client types
- โ Edit existing client types
- โ Delete client types (permanent)
- โ Temporary delete (soft delete)
- โ Restore deleted client types
- โ View all client types
- โ Business information management
- โ Tax registration tracking
Related Controllers
- โข clientController.php - Client master data management
- โข sellbillController.php - Sales operations using client types
- โข buyBillController.php - Purchase operations
- โข supplierController.php - Supplier management
- โข branchesController.php - Branch management
- โข userController.php - User management
- โข programsettingsController.php - System settings
- โข currencyController.php - Currency management
- โข taxController.php - Tax management
- โข accountstree.php - Chart of accounts
- โข dailyentry.php - Accounting entries
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **typeclient** | Client type master data | typeId, typeName, typeDate, conditions, comments, webApiId, nameCompanyClaimsOfficer, mobile, email, taxRegistration, address, obgyTypeId |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **client** | Client master data | client.clienttypeid โ typeclient.typeId | |
| **sellbill** | Sales bills | sellbill.sellbilltypeclientid โ typeclient.typeId | |
| **programsettings** | System configuration | Global settings lookup | |
| **youtubelink** | Help video links | General help system |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **user** | System users | Created/modified by tracking | |
| **webapi** | External API integration | typeclient.webApiId โ webapi.id |
๐ง Key Functions
1. add() - Create New Client Type
Location: Line 198
Purpose: Creates a new client type/category with all business details
Function Signature:
function add()
Parameters (via $_POST):
- โข
typename- Client type name - โข
comments- Additional comments/notes - โข
webApiId- External API integration ID - โข
nameCompanyClaimsOfficer- Claims officer name - โข
mobile- Contact mobile number - โข
email- Contact email address - โข
taxRegistration- Tax registration number - โข
address- Business address - โข
obgyTypeId- Obstetrics/Gynecology type classification
Process Flow:
Code Example:
$type->typeName = $_POST['typename'];
$type->conditions = 0; // Active by default
$type->typeDate = date("Y-m-d");
$type->comments = $_POST['comments'];
$type->webApiId = (int) $_POST['webApiId'];
$type->nameCompanyClaimsOfficer = $_POST['nameCompanyClaimsOfficer'];
// ... other fields
$id = $TypeClientDAO->insert($type);
---
2. show() - Display All Client Types
Location: Line 223
Purpose: Retrieves all client types for display
Function Signature:
function show()
Return Value: Array of all client type records
Process Flow:
---
3. edit() - Load Client Type for Editing
Location: Line 231
Purpose: Load specific client type data for editing form
Function Signature:
function edit()
Parameters:
- โข
$_GET['id']- Client type ID to edit
Return Value: Client type object data
Process Flow:
---
4. update() - Update Client Type
Location: Line 240
Purpose: Update existing client type with new information
Function Signature:
function update()
Parameters (via $_POST):
- โข
typename- Updated client type name - โข
typeid- ID of type being updated - โข
conditions- Active/inactive status - โข
comments- Updated comments - โข All business fields (mobile, email, etc.)
Process Flow:
---
5. delete() - Permanent Delete
Location: Line 267
Purpose: Permanently delete a client type from database
Function Signature:
function delete()
Parameters:
- โข
$_GET['id']- ID of client type to delete
Process Flow:
โ ๏ธ Warning: This is a hard delete. Check for dependencies before deletion.
---
6. tempdelete() - Soft Delete
Location: Line 274
Purpose: Temporarily hide client type (soft delete)
Function Signature:
function tempdelete($clientid)
Parameters:
- โข
$clientid- Client type ID (optional, gets from $_GET if not provided)
Return Value: Status message ("success" or error message)
Process Flow:
---
7. returndelete() - Restore Deleted
Location: Line 294
Purpose: Restore temporarily deleted client type
Function Signature:
function returndelete($clientid)
Parameters:
- โข
$clientid- Client type ID (optional, gets from $_GET if not provided)
Return Value: Status message ("success" or error message)
Process Flow:
---
๐ Business Logic Flow
Complete CRUD Workflow
Error Handling Pattern
---
โ ๏ธ Common Issues
1. PHP 8.2 Compatibility
- โข Issue: Object property assignment on uninitialized objects
- โข Solution: Controllers use proper object initialization patterns
- โข Status: โ Compatible
2. Foreign Key Constraints
- โข Issue: Cannot delete client type if referenced by clients or sales
- โข Solution: Implement dependency checking before deletion
- โข Recommendation: Use soft delete (
tempdelete()) instead
3. Data Validation
- โข Issue: No server-side validation for required fields
- โข Solution: Add validation in add() and update() functions
- โข Current Status: Relies on client-side validation only
4. Concurrency
- โข Issue: No optimistic locking for concurrent updates
- โข Impact: Last-update-wins scenario
- โข Recommendation: Add version tracking or row-level locking
---
๐ Dependencies
Required Files
- โข
/public/impOpreation.php- Core operations and MAC address handling - โข
/public/config.php- Database and system configuration - โข
/public/include_dao.php- All DAO class inclusions - โข
/library/uploadImages.php- Image handling utilities - โข
/public/authentication.php- User authentication and session management
DAO Classes
- โข
TypeClientDAO.class.php- Data access interface - โข
TypeClient.class.php- Data transfer object - โข
TypeClientMySqlDAO.class.php- MySQL implementation - โข
TypeClientMySqlExtDAO.class.php- Extended MySQL operations (soft delete)
Template Dependencies
- โข
typesview/add.html- Add form template - โข
typesview/show.html- List view template - โข
typesview/edit.html- Edit form template - โข
typesview/editprint.html- Print-friendly edit view - โข
header.html,footer.html- Layout templates - โข
succes.html,error.html- Status page templates
External Integrations
- โข YouTube Link system for help videos
- โข WebAPI integration for external system synchronization
- โข Smarty templating engine for view rendering
---
๐ฏ Usage Examples
Creating a New Client Type
// POST data for new retail client type
$_POST = [
'typename' => 'Retail Customer',
'comments' => 'Regular retail customers with standard pricing',
'webApiId' => 1,
'nameCompanyClaimsOfficer' => 'John Doe',
'mobile' => '+1234567890',
'email' => 'john@company.com',
'taxRegistration' => 'TAX123456',
'address' => '123 Business St, City',
'obgyTypeId' => 0
];
// Controller call: ?do=add
// Result: New client type created, redirect to success
Querying Client Types in Other Controllers
// Used in sellbillController.php
$allTypeClient = R::getAll('select typeId,typeName from typeclient where conditions=0');
// Used in claims system
$typeclients = R::getAll('SELECT * FROM typeclient WHERE typeId in (0,1,2,3)');
---
๐ Business Rules
1. Default Status: New client types are created with conditions = 0 (active)
2. Date Tracking: typeDate is automatically set to current date on create/update
3. Soft Delete: Prefer temporary delete over permanent deletion for data integrity
4. WebAPI Integration: Support for external system integration via webApiId
5. Specialized Types: Support for obstetrics/gynecology specific classifications
6. Business Information: Comprehensive contact and tax information tracking
---
Performance Notes:
- โข Simple CRUD operations with minimal complexity
- โข No complex joins or heavy calculations
- โข Uses standard DAO pattern for database operations
- โข Session-based authentication on each operation
Security Notes:
- โข Requires authentication for all operations
- โข Uses parameterized queries via DAO layer
- โข Input sanitization handled by DAO implementations
- โข Session validation on each controller action