ShippingFiles Documentation
Shipping Files Controller Documentation
File: /controllers/shippingFilesController.php
Purpose: Manages shipping documentation, file uploads, and delivery tracking for import contracts
Last Updated: December 19, 2024
Total Functions: 3 main actions + 12 file type handlers
Lines of Code: 161
---
๐ Overview
The Shipping Files Controller manages the complete documentation workflow for shipping and import operations. It handles:
- โข Tracking shipping documents by chassis number
- โข Managing multiple file types for each shipment
- โข File upload and storage for shipping documents
- โข User tracking for document uploads
- โข Integration with import contracts and inventory
- โข Real-time file status updates via AJAX
- โข Document versioning and user audit trails
Primary Functions
- โ Initialize shipping file records by chassis number
- โ Upload and manage 12 different document types
- โ Track which user uploaded each document and when
- โ Display file management interface with real-time updates
- โ Handle both file uploads and note updates
- โ Print-ready document views
- โ Integration with import contract system
Document Types Managed
- โข buybillfile - Purchase order documents
- โข performafile - Performa invoice documents
- โข cocfile - Certificate of Conformity
- โข finalbillfile - Final invoice documents
- โข warehousefile - Warehouse receipts
- โข shippolicyfile - Shipping policy documents
- โข eurofile - European compliance documents
- โข customevalfile - Customs evaluation documents
- โข model4file - Model 4 certification documents
- โข endrosementfile - Endorsement documents
- โข batchreleasefile - Batch release certificates
- โข trafficnotifyfile - Traffic notification documents
- โข saleagreementfile - Sale agreement documents
- โข taxinvoicefile - Tax invoice documents
- โข other - Other miscellaneous documents
Related Controllers
- โข buyBillController.md - Purchase order integration
- โข supplierController.md - Supplier documentation
- โข storeController.md - Warehouse receipt management
- โข productController.md - Product import documentation
- โข userController.md - User audit trails
- โข employeeController.md - Employee document handling
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **shippingfile** | Main shipping documents | id, chasis, buybillfile, cocfile, finalbillfile, warehousefile, etc. | |
| **shippingfile (user columns)** | User tracking | buybilluserid, cocuserid, finalbilluserid, warehouseuserid, etc. | |
| **shippingfile (date columns)** | Date tracking | buybilldate, cocdate, finalbilldate, warehousedate, etc. |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **importcontract** | Import chassis data | Source of chassis numbers | |
| **user** | User information | User who uploaded files |
| Directory | Purpose | File Types |
|---|---|---|
| **../upload/shippingFiles** | Document storage | PDF, DOC, JPG, PNG, etc. |
Each document type has 3 associated columns:
- โข {type}file - File name/path
- โข {type}userid - User who uploaded
- โข {type}date - Upload timestamp
Example for Buy Bill documents:
- โข
buybillfile- stores filename - โข
buybilluserid- stores uploader user ID - โข
buybilldate- stores upload datetime
---
๐ง Key Functions
1. Main Interface (empty $do)
Purpose: Display chassis selection and main shipping files interface
Called By: Direct navigation to controller
Line: 8
Process Flow:
Load Chassis Numbers
โ
Filter Active Contracts (del < 2)
โ
Display Chassis Selection
โ
Await User Selection
Business Logic:
1. Queries distinct chassis numbers from importcontract table
2. Filters only active contracts (not deleted: del < 2)
3. Displays chassis selection dropdown
4. Provides interface for file management
Database Query:
SELECT DISTINCT chasisno FROM importcontract
WHERE chasisno != '' AND del < 2
2. getFiles
Purpose: Load or create shipping file record for specific chassis
Called By: AJAX request with chassis selection
Line: 18
Parameters (via $_POST):
- โข
chasis(string) - Chassis number to manage
Process Flow:
Business Logic:
1. Auto-Creation: Creates shipping file record if doesn't exist
2. User Resolution: Loads employee names for all document types
3. Complete Data: Provides full file status for interface
4. Real-time Updates: Supports dynamic file management
Username Resolution Example:
$files['buybillusername'] = R::getCell(
"SELECT employeename FROM user WHERE userid = ?",
[$files['buybilluserid']]
);
3. updateFilesData
Purpose: Handle file uploads and note updates with comprehensive type mapping
Called By: AJAX file upload or note update
Line: 68
Parameters (via $_POST):
- โข
fileid(int) - Shipping file record ID - โข
col(string) - Column to update (file type) - โข
type(string) - 'note' or 'file' - โข
value(string) - Note content (for notes only) - โข
uploadedFile(file) - File to upload (for files only)
Process Flow:
Business Logic:
1. Type Detection: Handles both file uploads and note updates
2. Column Mapping: Maps file types to database columns and user tracking fields
3. User Audit: Tracks who uploaded what and when
4. Error Handling: Provides proper response codes for AJAX
5. File Management: Uses custom upload library for file processing
Column Mapping Logic:
switch ($col) {
case 'buybillfile':
$userCol = 'buybilluserid';
$dateCol = 'buybilldate';
break;
case 'cocfile':
$userCol = 'cocuserid';
$dateCol = 'cocdate';
break;
// ... continues for all 12+ document types
}
Database Update with Audit Trail:
R::exec("UPDATE shippingfile SET $col = '$fileName',
$userCol = " . $_SESSION['userid'] . ",
$dateCol = '$date' WHERE id = $fileid");
---
๐ Business Logic Flow
Complete Shipping Documentation Workflow
File Upload Process
---
โ ๏ธ Common Issues
1. File Upload Failures
Symptoms: Files not uploading, error responses
Causes:
- โข Directory permission issues on ../upload/shippingFiles
- โข File size exceeding PHP limits
- โข Invalid file types
- โข Insufficient disk space
Solutions:
- โข Ensure upload directory has 755 permissions
- โข Check
upload_max_filesizeandpost_max_sizein php.ini - โข Validate file types before upload
- โข Monitor disk space usage
2. Chassis Number Not Found
Symptoms: No chassis numbers appear in dropdown
Causes:
- โข No active import contracts
- โข Data in importcontract table marked as deleted
- โข Database connection issues
Solutions:
- โข Verify import contracts exist with
del < 2 - โข Check importcontract table data integrity
- โข Ensure database connectivity
3. User Name Resolution Failures
Symptoms: Blank user names in file upload tracking
Causes:
- โข Missing user records
- โข Invalid user IDs in session
- โข Deleted user accounts
Solutions:
- โข Validate user existence before file operations
- โข Implement fallback for missing user data
- โข Handle deleted user accounts gracefully
4. AJAX Response Errors
Symptoms: File upload interface not updating
Causes:
- โข Invalid JSON responses
- โข PHP errors during upload
- โข Network connectivity issues
Solutions:
- โข Add proper error handling in AJAX calls
- โข Validate server responses
- โข Implement retry mechanisms for failed uploads
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core system operations - โข
../library/uploadImages.php- File upload utilities
Database Dependencies
- โข RedBeanPHP: Used for all database operations (R::getAll, R::exec, etc.)
- โข Session Management: User tracking via $_SESSION['userid']
File System Dependencies
- โข Upload Directory:
../upload/shippingFiles/must be writable - โข File Processing: Custom upload class for file handling
Frontend Dependencies
- โข AJAX Support: For real-time file uploads and updates
- โข JavaScript: File upload interface and progress tracking
- โข Smarty Templates: For displaying file management interface
Template Files
- โข
shippingFilesView/add.html- Main chassis selection interface - โข
shippingFilesView/files.html- File management interface - โข
shippingFilesView/editprint.html- Print-ready document view - โข
header.html- Standard page header - โข
footer.html- Standard page footer
---
๐ฏ Integration Points
Import Contract Integration
- โข Chassis Tracking: Direct link to import contract chassis numbers
- โข Status Updates: Shipping file status affects contract completion
- โข Document Requirements: Different contracts may require different documents
User Management Integration
- โข Audit Trails: Complete tracking of who uploaded what when
- โข Permissions: Role-based access to different document types
- โข Employee Names: Real-time resolution of user information
File Management Integration
- โข Storage: Centralized file storage with organized structure
- โข Versioning: Support for document updates and replacements
- โข Access Control: Secure file access based on user permissions
Workflow Integration
- โข Process Tracking: Document completion affects overall import workflow
- โข Notifications: Alert systems for missing or expired documents
- โข Reporting: Status reports on shipping documentation progress
---
๐ก Best Practices
File Management
1. Organize files systematically by chassis number and document type
2. Implement file versioning for updated documents
3. Regular backup of critical shipping documents
4. Monitor storage space usage
5. Validate file integrity after uploads
Security Considerations
1. Validate file types to prevent malicious uploads
2. Scan uploaded files for viruses if possible
3. Implement access controls based on user roles
4. Log all file access for security auditing
5. Regular security reviews of upload directory
Performance Optimization
1. Compress large files before storage when possible
2. Use efficient file formats (PDF over images when applicable)
3. Implement lazy loading for file listings
4. Cache user information to reduce database queries
5. Monitor upload times and optimize as needed
Data Management
1. Maintain complete audit trails for all document changes
2. Regular cleanup of obsolete or duplicate files
3. Document retention policies based on legal requirements
4. Backup strategies for critical shipping documents
5. Disaster recovery plans for document loss scenarios
---
๐ง Technical Implementation Details
File Upload Process
// File upload with custom library
$handle = new upload($_FILES['uploadedFile']);
$fileName = uploadfile($handle, '../upload/shippingFiles');
// Database update with audit trail
R::exec("UPDATE shippingfile SET $col = '$fileName',
$userCol = " . $_SESSION['userid'] . ",
$dateCol = '$date' WHERE id = $fileid");
AJAX Response Format
{
"success": true,
"data": [
"file_url",
"upload_date",
"uploader_name"
]
}
Database Schema Pattern
For each document type, the system maintains:
- โข File column: Stores actual filename
- โข User column: Tracks who uploaded
- โข Date column: Timestamps the upload
This provides complete audit trail for all shipping documents.