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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**offerpricebillprop**Offer headersid, offerpricebillid, clientid, clientname, totalprice, realtotalprice, serialno, sysdate
**offerpricebill**Offer line itemsid, offerpricebillid, productid, productname, prodescrption, sellprice, pronumber, totalprice
**offerpricecondition**Offer terms and conditionsid, introduction, detail
### Product and Client Integration

Table NamePurposeRelationship
**product**Product master dataofferpricebill.productid
**client**Customer dataofferpricebillprop.clientid
**programsettings**System currency settingsFor amount formatting
### Data Structure Details

TableKey FieldsPurpose
**offerpricebillprop**id, clientid, clientname, totalprice, serialnoMain offer information and client details
**offerpricebill**offerpricebillid, productid, productname, sellprice, pronumberIndividual products in offer
**offerpricecondition**introduction, detailStandard 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):

Process Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Handle Client Info
- Existing Client
- Or New Client
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Process Products
- Validate data
- Insert each item
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Handle Conditions
- Create if first
- Update if exists
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Process Each Offer
- Get client name
- Calculate totals
- Format amounts
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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):

Process Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Get Client Details
- Handle existing
- Handle new client
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Load All Products
- Get product names
- Get descriptions
- Get barcodes
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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):

Process Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Clear Old Products
- Prepare for new
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Insert New Products
- Process each item
- Validate data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Gather Offer Information
- Client details
- Product requirements
- Special conditions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create Offer Header
- Generate unique serial
- Set client information
- Calculate totals
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Process Product Lines
- Add each product
- Set quantities & prices
- Include descriptions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Set Terms & Conditions
- Standard terms
- Custom conditions
- Payment terms
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Format for Presentation
- Convert totals to Arabic
- Apply company branding
- Generate PDF/print format
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Offer Update Process

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Load Existing Data
- Offer details
- Product lines
- Conditions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Apply Changes
- Update header
- Modify products
- Update terms
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Clear Old Products
- Remove all items
- Prepare for new
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Insert New Items
- Add each product
- Recalculate
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

โš ๏ธ Common Issues

1. Product Line Processing Errors

Symptoms: Missing products in offers or incorrect calculations

Causes:

Solutions:

if (empty($productid) && empty($offerproudctname)) {
    continue; // Skip empty lines
}

2. Client Name Resolution Issues

Symptoms: Wrong client names showing in offers

Causes:

Solutions:

3. Serial Number Collisions

Symptoms: Duplicate serial numbers causing database errors

Causes:

Solutions:

4. Arabic Number Conversion Failures

Symptoms: "ุนููˆุง ุงู„ุนุฏุฏ ุฎุงุฑุฌ ุงู„ู†ุทุงู‚" error in offer display

Causes:

Solutions:

---

๐Ÿ”— Dependencies

Required Files

Required DAOs

Template Files

JavaScript Dependencies

---

๐ŸŽฏ Integration Points

Product Integration

Client Integration

Conversion to Sales

Financial Integration

---

๐Ÿ’ก 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