Branches Documentation
Branches Controller Documentation
File: /controllers/branchesController.php
Purpose: Manages company branches/locations, branch settings, and branch-related operations
Last Updated: December 19, 2024
Total Functions: 6
Lines of Code: 262
---
๐ Overview
The Branches Controller manages the company's physical branches and locations in the ERP system. It handles:
- โข Creating and managing company branches/locations
- โข Branch contact information and settings
- โข Branch logo/image management
- โข Branch status management (active/inactive)
- โข Multi-language branch names (Arabic/English)
- โข Branch taxation numbers and addresses
Primary Functions
- โ Add new company branches
- โ View all branches in listing format
- โ Edit existing branch information
- โ Update branch details
- โ Delete branches from system
- โ Toggle branch active/inactive status
- โ Branch logo upload and management
- โ Print branch details
Related Controllers
- โข programsettingsController.md - Company settings
- โข userController.md - User management per branch
- โข storeController.md - Warehouses per branch
- โข sellbillController.md - Sales operations per branch
- โข buyBillController.md - Purchase operations per branch
- โข clientController.md - Customer management per branch
- โข supplierController.md - Supplier management per branch
- โข employeeController.md - Employee management per branch
- โข saveController.md - Cash registers per branch
- โข dailyentry.md - Accounting entries per branch
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **branch** | Branch master data | branchId, branchName, nameEn, phone, mobile, email, branchAddress, addressEn, branchTaxNo, logo, status, createdAt, updatedAt |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **youtubelink** | Associated video content | Referenced for branch marketing | |
| **user** | Branch employees | Users assigned to specific branches | |
| **store** | Branch warehouses | Each store belongs to a branch | |
| **buybill** | Purchase operations | buybill.branchid references branch | |
| **sellbill** | Sales operations | sellbill.branchid references branch |
| Directory | Purpose | File Types |
|---|---|---|
| **../views/default/images/branch_image** | Branch logos | JPG, PNG, GIF (250x250 px) |
๐ง Key Functions
1. add()
Purpose: Create a new company branch with all details
Called By: Form submission with ?do=add
Line: 145
Parameters (via $_POST):
- โข
branchname(string) - Branch name in Arabic - โข
nameEn(string) - Branch name in English - โข
phone(string) - Branch telephone number - โข
mobile(string) - Branch mobile number - โข
email(string) - Branch email address - โข
branchNo(string) - Branch identification number - โข
branchAddress(string) - Branch address in Arabic - โข
addressEn(string) - Branch address in English - โข
message(text) - Branch description/notes - โข
branchTaxNo(string) - Branch tax identification number - โข
status(int) - Branch status (1=active, 0=inactive) - โข
logo(file) - Branch logo image file
Process Flow:
Form Data Collection
โ
Image Upload Processing (250x250px)
โ
Branch Object Creation
โ
Database Insert
โ
Redirect to Success
Business Logic:
1. Collects all branch information from form
2. Sets automatic dates (branchDate, createdAt, updatedAt)
3. Processes logo upload using uploadImages() with 250x250 resize
4. Creates Branch DTO object with all data
5. Inserts into database via BranchDAO
2. show()
Purpose: Display all branches in system listing
Called By: Navigation to ?do=show
Line: 183
Return Value: Array of all branch objects
Process Flow:
Database Query (queryAll)
โ
Return Branch Array
โ
Template Assignment
โ
Display Branch List
Business Logic:
1. Queries all branches from database
2. Returns complete branch data array
3. Used by template to display branch listing
3. edit()
Purpose: Load branch data for editing form
Called By: Edit link with ?do=edit&id=X
Line: 192
Parameters (via $_GET):
- โข
id(int) - Branch ID to edit
Return Value: Branch object with all data
Process Flow:
Get Branch ID from URL
โ
Load Branch from Database
โ
Return Branch Object
โ
Populate Edit Form
4. update()
Purpose: Update existing branch information
Called By: Form submission with ?do=update
Line: 202
Parameters (via $_POST):
- โข
branchid(int) - Branch ID to update - โข All same parameters as add() function
Process Flow:
Load Existing Branch
โ
Collect Form Data
โ
Process Image Update
โ
Update Branch Object
โ
Database Update
โ
Redirect to Success
Business Logic:
1. Loads existing branch to preserve original creation date
2. Updates all modifiable fields
3. Handles logo image update or keeps existing
4. Uses updateImages() for image management
5. Updates updatedAt timestamp automatically
5. delete()
Purpose: Remove branch from system
Called By: Delete action with ?do=delete&id=X
Line: 243
Parameters (via $_GET):
- โข
id(int) - Branch ID to delete
Process Flow:
Get Branch ID
โ
Database Delete
โ
Redirect to Success
Business Logic:
1. Hard deletes branch record from database
2. Note: Should check for dependencies before deletion
6. toggleStatus()
Purpose: Toggle branch active/inactive status
Called By: Status toggle with ?do=toggleStatus&id=X
Line: 251
Parameters (via $_GET):
- โข
id(int) - Branch ID to toggle
Process Flow:
Load Branch Record
โ
Toggle Status (0โ1)
โ
Update Database
โ
Redirect to Success
Business Logic:
1. Loads current branch record
2. Toggles status: 1โ0 or 0โ1
3. Updates record in database
4. Enables/disables branch for operations
---
๐ Business Logic Flow
Branch Creation Workflow
Branch Status Management
---
โ ๏ธ Common Issues
1. Image Upload Failures
Symptoms: Logo not displaying after upload
Causes:
- โข Directory permissions on ../views/default/images/branch_image
- โข File size too large
- โข Invalid image format
Solutions:
- โข Ensure directory is writable (755 permissions)
- โข Check file size limits in PHP config
- โข Validate image format before upload
2. Branch Deletion Dependencies
Symptoms: Foreign key constraint errors
Causes: Branch has related records in other tables
Solutions:
- โข Check for users assigned to branch
- โข Check for stores under branch
- โข Check for bills/transactions for branch
- โข Implement soft delete instead of hard delete
3. Status Toggle Not Working
Symptoms: Branch status doesn't change
Causes:
- โข Missing permissions
- โข Database connection issues
- โข Caching issues
Solutions:
- โข Verify user has branch management permissions
- โข Check database connectivity
- โข Clear application cache
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations and session management - โข
../public/config.php- Database and system configuration - โข
../public/include_dao.php- Data Access Object includes - โข
../library/uploadImages.php- Image upload and processing utilities
Required DAOs
- โข
BranchDAO.class.php- Branch data access interface - โข
Branch.class.php- Branch data transfer object - โข
BranchMySqlDAO.class.php- MySQL implementation for branch operations - โข
BranchMySqlExtDAO.class.php- Extended branch operations - โข
YoutubeLinkDAO.class.php- YouTube link management - โข
YoutubeLink.class.php- YouTube link DTO - โข
YoutubeLinkMySqlDAO.class.php- YouTube link MySQL operations - โข
YoutubeLinkMySqlExtDAO.class.php- Extended YouTube operations
Template Files
- โข
branchesview/add.html- Branch creation form - โข
branchesview/show.html- Branch listing display - โข
branchesview/edit.html- Branch editing form - โข
branchesview/editprint.html- Printable branch details - โข
header.html- Standard page header - โข
footer.html- Standard page footer - โข
succes.html- Success message template - โข
error.html- Error message template
Image Upload Configuration
- โข Target Directory:
../views/default/images/branch_image - โข Image Dimensions: 250x250 pixels (automatically resized)
- โข Supported Formats: JPG, PNG, GIF
- โข Upload Class: Uses custom upload class from uploadImages.php
---
๐ฏ Integration Points
Multi-Branch Operations
Many other controllers reference branch data:
- โข Sales operations filter by branch
- โข Purchase operations assign to branch
- โข User management assigns users to branches
- โข Warehouse/store management per branch
- โข Financial reporting per branch
Security Considerations
- โข Authentication required for all operations
- โข File upload validation needed
- โข Input sanitization for all form fields
- โข Permission checks for branch management
Performance Notes
- โข Branch data frequently cached due to frequent lookups
- โข Logo images should be optimized for web display
- โข Status checks impact user interface availability