Programsettings Documentation
Program Settings Controller Documentation
File: /controllers/programsettingsController.php
Purpose: Manages system-wide configuration, company settings, and global behavior
Last Updated: December 19, 2024
Total Functions: 5
Lines of Code: ~903
---
๐ Overview
The Program Settings Controller is the central component for managing system-wide configuration and global settings in the ERP system. It handles:
- โข Company information and branding
- โข System behavior and feature toggles
- โข Multi-currency and localization settings
- โข Restaurant and POS configurations
- โข E-invoice and tax settings
- โข Product and inventory defaults
- โข UI customization and display options
- โข Image and document management
- โข Database structure modifications
- โข Integration settings for external systems
Primary Functions
- โ Update comprehensive system settings
- โ Company profile management
- โ Feature toggle configuration
- โ Currency and localization setup
- โ Tax and e-invoice configuration
- โ Restaurant/cafe specific settings
- โ Product behavior defaults
- โ UI customization options
- โ File upload management
- โ Database structure adjustments
Related Controllers
- โข userController.php - User management
- โข usergroupController.php - User group management
- โข billsettingsController.php - Bill templates
- โข sellbillController.php - Sales operations
- โข buyBillController.php - Purchase operations
- โข productController.php - Product management
- โข storeController.php - Store management
- โข clientController.php - Customer management
- โข supplierController.php - Supplier management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **programsettings** | System configuration | programsettingsid, companyname, address, phone, email, logo, timezone | |
| **ebillsetting** | E-invoice configuration | id, eunitInTax, eTaxNum, eTaxNumBranch, eGovernorate, eCity | |
| **transfersell** | Transfer settings | Special business transfer settings |
| Category | Purpose | Key Fields | |
|---|---|---|---|
| **Company Info** | Business identity | companyname, address, phone, email, website, logo | |
| **Financial** | Money settings | currency, roundnumbers, vatValue, valueadded | |
| **Product Settings** | Item behavior | parcode, limitamount, measuringunit, updateproductprice | |
| **UI Settings** | Display options | searchlimit, colortype, noOfDecimalPlaces | |
| **Restaurant** | POS features | isRestaurent, isCafe, restaurantStoreId, takeAwayClient | |
| **Printing** | Output options | printingpapersize, saveprinting, deptprinting | |
| **E-Invoice** | Tax compliance | ebill, saudielectronicinvoice, vatvalueqr | |
| **Integration** | External systems | qrerp, webApiId, tamweenBakery |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **store** | Warehouses | programsettings.restaurantStoreId | |
| **usergroup** | User roles | Used for pharmacy group settings | |
| **productcat** | Product categories | Used for medical categories | |
| **expensestype** | Expense types | Used for dollar expense types |
๐ง Key Functions
1. Default Display - Load Configuration Form
Location: Line 117
Purpose: Load and display the comprehensive system settings form
Process Flow:
2. update() - Update System Configuration
Location: Line 171
Purpose: Comprehensive update of all system settings with validation and processing
Function Signature:
function update()
Key Parameters (via $_POST - over 200 settings):
Company Information:
- โข
companyname- Business name - โข
address- Business address - โข
phone,faxnumber,email,website- Contact info - โข
taxcard,commercialregistration,licenseNo- Legal info
System Behavior:
- โข
roundnumbers- Number rounding - โข
searchlimit- Search result limits - โข
timezone- System timezone - โข
noOfDecimalPlaces- Decimal precision - โข
enablequantityfractions- Fractional quantities
Product Settings:
- โข
parcode- Barcode settings - โข
parcodeDigits- Barcode length - โข
limitamount- Stock alert levels - โข
updateproductprice- Price update behavior
Financial Configuration:
- โข
currancy- System currency - โข
vatValue- VAT percentage - โข
valueadded- VAT application - โข
clientDefaultDebtLimit- Credit limits
Restaurant/POS Settings:
- โข
isRestaurent,isCafe- Operation mode - โข
restaurantStoreId- Default store - โข
takeAwayClient- Takeaway customer - โข
hall,delivery,takeAway- Service types
E-Invoice Configuration:
- โข
ebill- E-invoice enabled - โข
saudielectronicinvoice- Saudi ZATCA - โข
eTaxNum- Tax registration number
3. affectTableStructureWithDecimalPlaces() - Database Schema Updates
Location: Line 847
Purpose: Modify database table structure based on decimal place settings
Parameters:
- โข
noOfDecimalPlacesBillTotal- Bill total precision - โข
noOfDecimalPlaces- General decimal precision
Process:
Tables Modified:
- โข
sellbill- Sales totals, payments - โข
sellbilldetail- Line item amounts
4. CURL_IT() - External API Communication
Location: Line 863
Purpose: Send company data to external QR ERP system
5. addPreDigitsToNum() - Barcode Formatting
Location: Line 888
Purpose: Format numbers with leading zeros for barcode generation
---
๐ Business Logic Flow
Settings Update Workflow
Restaurant Service Configuration
---
โ ๏ธ Common Issues
Image Upload Processing
Issue: Multiple image uploads with different resize requirements
// โ
IMPLEMENTED: Lines 428-444 - Different upload handlers
updateImages() // For logos (250x250)
updateImagesWithoutresiz() // For headers (original size)
Database Schema Changes
Issue: Decimal precision changes require table structure modifications
// โ
SOLUTION: Lines 844-861 - Dynamic ALTER TABLE queries
affectTableStructureWithDecimalPlaces($noOfDecimalPlacesBillTotal, $noOfDecimalPlaces);
Barcode Generation
Issue: Barcode digit changes require regenerating all product codes
// โ
IMPLEMENTED: Lines 788-810 - Barcode regeneration
if ($oldParcodeDigits != $parcodeDigits) {
$availableParcodeEX->truncate();
$availableParcodeEX->callGenerateParcodesSP($parcodeDigits);
}
Performance Considerations
- โข Cache Invalidation: Header cache cleared on sync structure changes
- โข External API: QR ERP updates only when connected to internet
- โข Database Changes: Schema modifications can be time-consuming
---
๐ Dependencies
Required DAOs
- โข
ProgramsettingsMySqlDAO- Main settings operations - โข
ProgramsettingsMySqlExtDAO- Extended settings queries - โข
EbillsettingMySqlDAO- E-invoice settings - โข
StoreMySqlDAO- Store configuration - โข
UsergroupMySqlDAO- User group settings - โข
ClientMySqlExtDAO- Client debt limit updates - โข
AvailableparcodeMySqlExtDAO- Barcode management
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/config.php- Configuration - โข
../library/uploadImages.php- Image processing - โข
../public/include_dao.php- DAO includes
External Dependencies
- โข Image processing libraries for logos/headers
- โข Internet connectivity for QR ERP integration
- โข Database ALTER privileges for structure changes
- โข File system access for image storage
---
๐ Performance Notes
- โข Single comprehensive update function handles 200+ settings
- โข Image uploads processed asynchronously
- โข Database structure changes executed in batch
- โข External API calls wrapped in connectivity checks
- โข Cache management for performance optimization
- โข Array processing for multi-select configurations
The Program Settings Controller serves as the nerve center of the ERP system, controlling global behavior and ensuring consistent operation across all modules.