Shippercompanies Documentation
Shipper Companies Controller Documentation
File: /controllers/shippercompaniesController.php
Purpose: Manages shipping companies and their representatives for logistics and delivery operations
Last Updated: December 20, 2024
Total Functions: 8
Lines of Code: 508
---
๐ Overview
The Shipper Companies Controller manages shipping/logistics companies and their representative contacts in the ERP system. It handles:
- โข Creating and editing shipping companies
- โข Managing company representatives (multiple per company)
- โข Dynamic representative management (add/remove via interface)
- โข Soft delete functionality (temporary delete/restore)
- โข Bulk operations on multiple companies
- โข Integration with shipping policies and bills
- โข Validation for policy dependencies before deletion
Primary Functions
- โ Create new shipping companies with multiple representatives
- โ Edit existing companies and their representatives
- โ Delete companies (with policy validation)
- โ Temporary delete (soft delete)
- โ Restore deleted companies
- โ View all companies with representatives
- โ Bulk operations (delete/restore multiple companies)
- โ Representative contact management
Related Controllers
- โข sellbillController.php - Sales with shipping integration
- โข buyBillController.php - Purchase operations
- โข clientController.php - Client management
- โข supplierController.php - Supplier management
- โข storeController.php - Warehouse management
- โข productController.php - Product management
- โข currencyController.php - Currency management
- โข taxController.php - Tax management
- โข userController.php - User management
- โข branchesController.php - Branch management
- โข programsettingsController.php - System settings
- โข shippingFilesController.php - Shipping document management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **shippercompanies** | Shipping company master data | companyId, companyName, otherInfo, tempdele | |
| **representativecompany** | Company representatives | representativecompanyId, representativeName, representativePhone, companyId, otherInfo |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **policy** | Shipping policies | policy.companyId โ shippercompanies.companyId | |
| **youtubelink** | Help video links | General help system integration |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **user** | System users | Created/modified by tracking | |
| **programsettings** | System configuration | Global settings lookup |
๐ง Key Functions
1. add() - Create New Shipping Company
Location: Line 257
Purpose: Creates a new shipping company with multiple representatives
Function Signature:
function add()
Parameters (via $_POST):
- โข
companyName- Shipping company name - โข
otherInfo- Additional company information - โข
hidden_itr- Number of representatives being added - โข
representativeName{n}- Representative names (dynamic, n=1 to hidden_itr) - โข
representativePhone{n}- Representative phone numbers - โข
otherInfo{n}- Additional representative information
Process Flow:
Code Example:
// Create company first
$myShippercompanies->companyName = $_POST['companyName'];
$myShippercompanies->tempdele = 0; // Active by default
$companyId = $myShippercompaniesRecord->insert($myShippercompanies, $otherInfo);
// Add representatives
for ($h = 1; $h <= $itr; $h++) {
$representativeName = $_POST['representativeName' . $h];
$representativePhone = $_POST['representativePhone' . $h];
if (isset($representativeName) && $representativeName != "" &&
isset($representativePhone) && $representativePhone != "") {
$myRepresentativecompany->companyId = $companyId;
$myRepresentativecompany->representativeName = $representativeName;
$myRepresentativecompany->representativePhone = $representativePhone;
$myRepresentativecompanyRecord->insert($myRepresentativecompany, $otherInfo);
}
}
---
2. show() - Display All Shipping Companies
Location: Line 295
Purpose: Retrieves all shipping companies for display
Function Signature:
function show()
Return Value: Array of all shipping company records
Process Flow:
---
3. deletetemp() - Soft Delete Company
Location: Line 305
Purpose: Temporarily hide shipping company (soft delete)
Function Signature:
function deletetemp($companyId)
Parameters:
- โข
$companyId- Company ID to soft delete
Return Value: Status message ("success" or error message)
Process Flow:
Code Example:
$myShippercompanies->companyId = $companyId;
$myShippercompanies->tempdele = 1; // Mark as deleted
$myShippercompaniesEx->updateTempdele($myShippercompanies);
---
4. returndelete() - Restore Deleted Company
Location: Line 331
Purpose: Restore temporarily deleted shipping company
Function Signature:
function returndelete($companyId)
Parameters:
- โข
$companyId- Company ID to restore
Return Value: Status message ("success" or error message)
Process Flow:
---
5. delete() - Permanent Delete with Validation
Location: Line 357
Purpose: Permanently delete shipping company after policy validation
Function Signature:
function delete($companyId)
Parameters:
- โข
$companyId- Company ID to delete
Return Value: Array [policyValid, statusMessage]
- โข
policyValid: 0 = can delete, 1 = has policies (cannot delete) - โข
statusMessage: Success or error message
Process Flow:
Code Example:
// Check for dependent policies
$policyData = $myPolicyRecord->queryByCompanyId($companyId);
if (count($policyData) > 0) {
$policyValid = 1;
$note = "ูุง ูู
ูู ุญุฐู ูุฐู ุงูุดุฑูุฉ ููุฌูุฏ ุจูููุตุฉ ุดุญู ู
ุฑุชูุทุฉ ุจูุง";
} else {
// Safe to delete
$myRepresentativecompanyRecord->deleteByCompanyId($companyId);
$myShippercompaniesRecord->delete($companyId);
$policyValid = 0;
$note = "success";
}
return array($policyValid, $note);
---
6. edit() - Load Company for Editing
Location: Line 396
Purpose: Load shipping company and representative data for editing
Function Signature:
function edit($companyId)
Parameters:
- โข
$companyId- Company ID to edit
Return Value: Array [loadData, representativecompanyData, representativecompanyNum]
- โข
loadData: Company master data object - โข
representativecompanyData: Array of representative records - โข
representativecompanyNum: Count of representatives
Process Flow:
---
7. update() - Update Company and Representatives
Location: Line 414
Purpose: Update company information and rebuild representative list
Function Signature:
function update()
Parameters (via $_POST):
- โข
companyName- Updated company name - โข
companyId- Company ID being updated - โข
tempdele- Company active status - โข
otherInfo- Additional company information - โข
hidden_itr- Number of representatives - โข Representative arrays (same as add function)
Process Flow:
โ ๏ธ Important: This function completely replaces all representatives rather than updating individual records.
---
8. executeOperation() - Bulk Operations
Location: Line 458
Purpose: Perform bulk operations on multiple selected companies
Function Signature:
function executeOperation()
Parameters (via $_POST):
- โข
operation- Operation type (1=temp delete, 2=restore, 3=permanent delete) - โข
choosedItem- Array of company IDs to process
Return Value: Sets Smarty variables for result display
Process Flow:
Code Example:
$operationType = $_POST['operation'];
$choosedItemArr = $_POST['choosedItem'];
foreach ($choosedItemArr as $companyId) {
$shippercompaniesData = $myShippercompaniesRecord->load($companyId);
$companyName = $shippercompaniesData->companyName;
if ($operationType == '1') {
// Temp delete
$note = deletetemp($companyId);
} elseif ($operationType == "2") {
// Restore
$note = returndelete($companyId);
} elseif ($operationType == "3") {
// Permanent delete
$note = delete($companyId);
}
// Collect output for display
$outputString .= $companyName . ": " . $result . "<br/>";
}
---
๐ Business Logic Flow
Complete Company Management Workflow
Representative Management Logic
---
โ ๏ธ Common Issues
1. Policy Dependency Validation
- โข Issue: Cannot delete companies with active shipping policies
- โข Solution: System checks
policy.companyIdbefore allowing deletion - โข User Experience: Clear error message with policy reference
- โข Status: โ Implemented
2. Representative Management
- โข Issue: Update replaces all representatives instead of individual updates
- โข Impact: May cause concurrency issues with multiple users
- โข Current Behavior: Delete all โ Re-insert all
- โข Recommendation: Implement individual representative update tracking
3. Bulk Operation Performance
- โข Issue: Bulk operations process one by one (not transactional)
- โข Impact: Partial failures possible
- โข Current Status: Individual try-catch per item
- โข Recommendation: Wrap in database transaction
4. Input Validation
- โข Issue: Limited server-side validation
- โข Current: Basic empty string checks for representatives
- โข Missing: Company name uniqueness, phone number format validation
- โข Recommendation: Add comprehensive validation layer
---
๐ Dependencies
Required Files
- โข
/public/impOpreation.php- Core operations and system utilities - โข
/public/config.php- Database and system configuration - โข
/public/include_dao.php- All DAO class inclusions - โข
/public/authentication.php- User authentication and session management
DAO Classes
- โข
ShippercompaniesDAO.class.php- Data access interface for companies - โข
Shippercompanie.class.php- Company data transfer object - โข
ShippercompaniesMySqlDAO.class.php- MySQL implementation for companies - โข
ShippercompaniesMySqlExtDAO.class.php- Extended MySQL operations (soft delete) - โข
RepresentativecompanyDAO.class.php- Representative data access interface - โข
Representativecompany.class.php- Representative data transfer object - โข
RepresentativecompanyMySqlDAO.class.php- MySQL implementation for representatives - โข
PolicyDAO.class.php- Policy dependency validation - โข
YoutubeLinkDAO.class.php- Help system integration
Template Dependencies
- โข
shippercompaniesview/add.html- Add form template - โข
shippercompaniesview/show.html- List view template with bulk operations - โข
shippercompaniesview/edit.html- Edit form template - โข
header.html,footer.html- Layout templates - โข
succes.html,error.html- Status page templates - โข
notes2.html- Special notes display for policy conflicts
JavaScript Dependencies
- โข Custom validation scripts (
customValidation = 1) - โข Shipper-specific UI enhancements (
customShipper = 1) - โข Bank and check-related UI features (
customBank = 1,customCheck = 1)
---
๐ฏ Usage Examples
Creating a Shipping Company with Representatives
// POST data for new shipping company
$_POST = [
'companyName' => 'Express Logistics LLC',
'otherInfo' => 'Nationwide shipping coverage',
'hidden_itr' => 3, // 3 representatives
'representativeName1' => 'John Smith',
'representativePhone1' => '+1234567890',
'otherInfo1' => 'Sales Manager',
'representativeName2' => 'Jane Doe',
'representativePhone2' => '+1234567891',
'otherInfo2' => 'Operations Manager',
'representativeName3' => 'Bob Wilson',
'representativePhone3' => '+1234567892',
'otherInfo3' => 'Customer Service'
];
// Controller call: ?do=add
// Result: Company + 3 representatives created
Bulk Operations
// POST data for bulk operations
$_POST = [
'operation' => '1', // Temp delete
'choosedItem' => ['1', '3', '5'] // Company IDs
];
// Controller call: ?do=executeOperation
// Result: Companies 1, 3, 5 temporarily deleted
Policy Validation Before Deletion
// Attempt permanent deletion
// GET: ?do=delete&companyId=123
// If policies exist:
// Result: Error page with message
// "ูุง ูู
ูู ุญุฐู ูุฐู ุงูุดุฑูุฉ ููุฌูุฏ ุจูููุตุฉ ุดุญู ู
ุฑุชูุทุฉ ุจูุง"
// If no policies:
// Result: Company and all representatives deleted
---
๐ Business Rules
1. Company Creation: Must have company name, representatives are optional
2. Representative Validation: Both name and phone required for each representative
3. Soft Delete Priority: Prefer temporary delete over permanent deletion
4. Policy Protection: Cannot permanently delete companies with active policies
5. Bulk Operations: Support mass temporary delete, restore, and permanent delete
6. Representative Management: Complete replacement on update (not individual updates)
7. Status Tracking: tempdele field manages soft delete status (0=active, 1=deleted)
---
Performance Notes:
- โข Dynamic representative management via looping (scalable for reasonable numbers)
- โข Policy validation adds database query overhead on deletion
- โข Bulk operations are not transactional (individual processing)
- โข Standard DAO pattern for database operations
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
- โข Foreign key validation prevents orphaned policy records