Priceoffers Documentation
Price Offers Controller Documentation
File: /controllers/priceoffersController.php
Purpose: Manages price quotations, offers to customers, and promotional pricing proposals
Last Updated: December 19, 2024
Total Functions: 4
Lines of Code: 488
---
๐ Overview
The Price Offers Controller manages the creation, editing, and tracking of price quotations and offers sent to customers. It handles:
- โข Creating detailed price quotations with multiple products
- โข Managing offer conditions and terms
- โข Client-specific or general offers
- โข Product-based offers with descriptions and quantities
- โข Arabic number conversion for professional presentation
- โข Offer serial number generation and tracking
- โข Integration with product and client management
Primary Functions
- โ Create comprehensive price offers/quotations
- โ Display all offers with calculated totals
- โ Edit existing offers with full product details
- โ Update offers and associated conditions
- โ Delete offers and related data
- โ Generate unique serial numbers for offers
- โ Convert amounts to Arabic written format
- โ Handle both existing and new client offers
Related Controllers
- โข clientController.md - Customer management for offers
- โข productController.md - Product details and pricing
- โข sellbillController.md - Convert offers to sales
- โข programsettingsController.md - Currency and system settings
- โข supplierController.md - Cost analysis for pricing
- โข buyBillController.md - Product cost information
- โข unitController.md - Product units and measurements
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **offerpricebillprop** | Offer headers | id, offerpricebillid, clientid, clientname, totalprice, realtotalprice, serialno, sysdate | |
| **offerpricebill** | Offer line items | id, offerpricebillid, productid, productname, prodescrption, sellprice, pronumber, totalprice | |
| **offerpricecondition** | Offer terms and conditions | id, introduction, detail |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **product** | Product master data | offerpricebill.productid | |
| **client** | Customer data | offerpricebillprop.clientid | |
| **programsettings** | System currency settings | For amount formatting |
| Table | Key Fields | Purpose | |
|---|---|---|---|
| **offerpricebillprop** | id, clientid, clientname, totalprice, serialno | Main offer information and client details | |
| **offerpricebill** | offerpricebillid, productid, productname, sellprice, pronumber | Individual products in offer | |
| **offerpricecondition** | introduction, detail | Standard terms and conditions for offers |
๐ง Key Functions
1. add()
Purpose: Create a new price offer with multiple products and conditions
Called By: Form submission with ?do=add
Line: 283
Parameters (via $_POST):
- โข
newclientname(string) - New client name for non-existing customers - โข
oldclientname(int) - Existing client ID - โข
clienttype(int) - 0=existing client, 1=new client - โข
generalcondition(text) - General terms and conditions - โข
introductioncondition(text) - Introduction/header text for offer - โข
offerhidden_itr(int) - Number of products in offer - โข
totalsellbillprice(float) - Total offer amount - โข
offer_sellbillpricenew(float) - Real total after adjustments - โข
offerproudctid{N}(int) - Product ID for item N - โข
offerproudctname{N}(string) - Product name for item N - โข
offerproprice{N}(float) - Unit price for item N - โข
prodescrp{N}(text) - Product description for item N - โข
offerpronumber{N}(float) - Quantity for item N - โข
div_pr_offertotal{N}(float) - Line total for item N
Process Flow:
Business Logic:
1. Client Handling: Supports both existing clients (by ID) and new clients (by name)
2. Serial Generation: Creates unique offer number using getserails()
3. Product Processing: Iterates through products, handles both catalog and free-text items
4. Condition Management: Creates or updates standard terms and conditions
5. Data Validation: Skips empty product entries automatically
Code Example - Client Processing:
if ($clienttype == 0) {
// Existing client
$clientname = R::getCell('select clientname from client where clientid = ' . $oldclientname);
$Offerpricebillprop->clientid = $oldclientname;
$Offerpricebillprop->clientname = $clientname;
} else {
// New client
$Offerpricebillprop->clientid = 0;
$Offerpricebillprop->clientname = $newclientname;
}
2. show()
Purpose: Display all price offers with totals and client information
Called By: Navigation to ?do=show
Line: Embedded in main controller logic
Process Flow:
Business Logic:
1. Loads all offers using $OfferpricebillpropEx->queryAllExt()
2. Resolves client names (handles both existing and new clients)
3. Calculates grand total of all offers
4. Converts total to Arabic written format for presentation
5. Integrates YouTube help content
Arabic Number Conversion:
$ar_number = new convert_ar($total_of_all, "male");
$arabic_num = $ar_number->convert_number();
$arabic_num .= ' ' . $Programsettingdata->currancy . ' ููุท ูุงุบูุฑ';
3. edit()
Purpose: Load offer details for editing with full product and condition information
Called By: Edit action with ?do=edit&id=X
Line: Embedded in main controller logic
Parameters (via $_GET):
- โข
id(int) - Offer ID to edit
Process Flow:
Business Logic:
1. Loads offer header with total amount conversion to Arabic
2. Retrieves client information (existing client name or stores new client name)
3. Loads all products with enhanced details including barcodes
4. Gets current terms and conditions
5. Prepares comprehensive edit form
Product Details Enhancement:
foreach ($allproductdata as $data) {
$productData = $productDAO->load($data->productid);
$productName = $productData->productName;
$data->productName = $productName;
$data->parcode = $productData->parcode; // Barcode integration
}
4. update()
Purpose: Update existing offer with modified products and conditions
Called By: Form submission with ?do=update
Line: 377
Parameters (via $_POST):
- โข
editid(int) - Offer ID to update - โข
serialno(string) - Offer serial number - โข
billdate(date) - Offer date - โข
generalconditionId(int) - Condition record ID - โข All same parameters as add() function
Process Flow:
Business Logic:
1. Preserves Key Data: Keeps original serial number and date if provided
2. Clean Slate Approach: Deletes all existing products and re-creates
3. Client Flexibility: Allows changing between existing and new clients
4. Condition Updates: Updates terms and conditions by ID
5. Data Integrity: Ensures all related data stays synchronized
5. getserails()
Purpose: Generate unique serial number for new offers
Called By: add() function internally
Line: 468
Return Value: Unique 8-character serial number (YYYY + 4 random digits)
Process Flow:
Generate Random Number
โ
Format: YEAR + 4 digits
โ
Check Database for Duplicates
โ
If Duplicate: Generate New
โ
Return Unique Serial
Business Logic:
1. Creates serial format: Current year + 4 random digits (e.g., "20243847")
2. Checks existing offers to prevent duplicates
3. Regenerates if collision found
4. Ensures unique identification for each offer
Serial Generation Code:
function generateRandomString($length = 4) {
$newnum = substr(str_shuffle("0123456789"), 0, $length);
return date("Y") . '' . $newnum;
}
---
๐ Business Logic Flow
Complete Offer Creation Workflow
Offer Update Process
---
โ ๏ธ Common Issues
1. Product Line Processing Errors
Symptoms: Missing products in offers or incorrect calculations
Causes:
- โข Empty product fields not properly skipped
- โข Quantity/price type mismatches
- โข Product ID resolution failures
Solutions:
- โข Validate all numeric inputs before processing
- โข Implement proper empty field checking:
if (empty($productid) && empty($offerproudctname)) {
continue; // Skip empty lines
}
2. Client Name Resolution Issues
Symptoms: Wrong client names showing in offers
Causes:
- โข Incorrect client type handling
- โข Database query failures
- โข Missing client records
Solutions:
- โข Always validate client existence before referencing
- โข Implement fallback for missing client data
- โข Use proper error handling for database queries
3. Serial Number Collisions
Symptoms: Duplicate serial numbers causing database errors
Causes:
- โข Insufficient randomization
- โข High-volume concurrent offer creation
- โข Database constraint violations
Solutions:
- โข Implement robust collision detection
- โข Use database transactions for serial generation
- โข Consider UUID or timestamp-based serials
4. Arabic Number Conversion Failures
Symptoms: "ุนููุง ุงูุนุฏุฏ ุฎุงุฑุฌ ุงููุทุงู" error in offer display
Causes:
- โข Very large numbers outside conversion range
- โข Invalid numeric formats
- โข Library limitations
Solutions:
- โข Validate amount ranges before conversion
- โข Implement graceful fallback for large amounts
- โข Add proper error handling for conversion library
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core system operations - โข
../public/config.php- Database configuration - โข
../public/include_dao.php- Data access layer - โข
../library/num_to_ar.php- Arabic number conversion library
Required DAOs
- โข
OfferpricebillDAO.class.php- Offer line items data access - โข
Offerpricebill.class.php- Offer line item DTO - โข
OfferpricebillMySqlDAO.class.php- MySQL offer operations - โข
OfferpricebillMySqlExtDAO.class.php- Extended offer operations - โข
OfferpricebillpropDAO.class.php- Offer header data access - โข
Offerpricebillprop.class.php- Offer header DTO - โข
OfferpricebillpropMySqlDAO.class.php- MySQL offer header operations - โข
OfferpricebillpropMySqlExtDAO.class.php- Extended offer header operations - โข
OfferpriceconditionDAO.class.php- Conditions data access - โข
Offerpricecondition.class.php- Conditions DTO - โข
OfferpriceconditionMySqlDAO.class.php- MySQL conditions operations - โข
OfferpriceconditionMySqlExtDAO.class.php- Extended conditions operations - โข
ProductDAO.class.php- Product data access - โข
ClientDAO.class.php- Client data access - โข
ProgramsettingsDAO.class.php- System settings access
Template Files
- โข
priceoffersview/add.html- Offer creation form - โข
priceoffersview/show.html- Offers listing display - โข
priceoffersview/edit.html- Offer editing form - โข
header.html- Standard page header - โข
footer.html- Standard page footer - โข
succes.html- Success message template - โข
error.html- Error message template
JavaScript Dependencies
- โข jQuery for form handling and dynamic product rows
- โข Custom validation for offer forms
- โข AJAX for real-time calculations
- โข Print functionality for offer presentation
---
๐ฏ Integration Points
Product Integration
- โข Product Lookup: Real-time product search and selection
- โข Pricing: Integration with current product pricing
- โข Barcode Support: Product identification via barcodes
- โข Inventory Awareness: Check stock levels for offers
Client Integration
- โข Existing Clients: Full client database integration
- โข New Clients: Ability to create offers for prospects
- โข Client History: Track offer history per client
- โข Conversion Tracking: Monitor offer-to-sale conversion
Conversion to Sales
- โข Quote Acceptance: Convert offers to actual sales orders
- โข Pricing Lock: Maintain quoted prices during conversion
- โข Product Availability: Verify stock before conversion
- โข Terms Transfer: Carry conditions to sales orders
Financial Integration
- โข Currency Support: Multi-currency offers
- โข Tax Calculations: Apply appropriate tax rates
- โข Discount Handling: Support for quantity and promotional discounts
- โข Profit Analysis: Calculate profit margins on offers
---
๐ก Best Practices
Offer Creation
1. Always validate client information before creating offers
2. Use product catalog whenever possible for accuracy
3. Include detailed descriptions for custom items
4. Set reasonable validity periods for offers
5. Review calculations before finalizing
Data Management
1. Archive old offers regularly for performance
2. Track offer conversion rates for sales analysis
3. Maintain consistent conditions across similar offers
4. Use serial numbers for proper tracking
5. Backup offer data before major updates
Presentation
1. Format amounts professionally with Arabic text
2. Include complete terms and conditions
3. Use company branding consistently
4. Provide clear product descriptions
5. Make offers easy to understand for customers