DatedChecked Documentation

Dated Check Controller Documentation

File: /controllers/datedCheckedController.php

Purpose: Manages post-dated checks (PDCs) for both customers and suppliers, including check endorsements, payments, and cancellations

Last Updated: December 20, 2024

Total Functions: 25+

Lines of Code: ~2,130

---

๐Ÿ“‹ Overview

The Dated Checked Controller is the central hub for managing post-dated checks (PDCs) in the ERP system. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**datedchecked**Post-dated check masterdatedCheckedID, clientNum, bankName, accountNo, checkValue, checkNo, dueDate, done, addType, paperType
**clientdebtchange**Customer debt transaction logclientdebtchangeid, clientid, clientdebtchangeamount, clientdebtchangetype, clientdebtchangedate, tablename
**supplierdebtchange**Supplier debt transaction logsupplierdebtchangeid, supplierid, supplierdebtchangeamount, supplierdebtchangetype, supplierdebtchangedate, tablename
### Financial Tables

Table NamePurposeKey Columns
**save**Cash registers/safessaveid, savename, savecurrentvalue, userid
**savedaily**Cash register movementssavedailyid, saveid, savedailychangeamount, savedailychangetype, savedailymodelid, tablename
**checkdeposit**Check deposits to bankcheckdepositid, clientid, bankaccountid, checkdepositamount, checkdepositdate
**bankaccount**Bank account masteraccountid, bankid, accountbeginingbalance, treeId
**accountmovement**Bank account movementsaccountmovementid, accountid, accountmovementamount, accountmovementtype, tablename
### Reference Tables

Table NamePurposeKey Columns
**client**Customer master dataclientid, clientname, clientdebt, treeId
**supplier**Supplier master datasupplierid, suppliername, suppliercurrentDebt, treeId
**bank**Bank master databankid, bankname
**dailyentry**Accounting entriesdailyentryid, entryComment, entryDate
---

๐Ÿ”‘ Key Functions

1. selectCustomer - Choose Check Type

Location: Line 203

Purpose: Display form to select whether creating check for customer (paytype=0) or supplier (paytype=1)

Process Flow:

1. Load all banks for dropdown

2. Set today's date for default

3. If customer type: Load all clients and show client form

4. If supplier type: Load all suppliers and show supplier form

---

2. add() - Create New Post-Dated Check

Location: Line 814

Purpose: Core function to create new post-dated checks for customers or suppliers

Function Signature:

function add()

Process Flow:

1. Input Validation: Extract POST parameters (client/supplier ID, bank details, check amount, dates)

2. Check Record Creation: Insert into datedchecked table

3. Debt Management: Update client/supplier debt based on check type

4. Debt Change Logging: Insert transaction record into debt change tables

5. Accounting Entry: Create daily entry with appropriate debit/credit accounts

6. Return: Success indicator (0 for customer, 1 for supplier)

Key Variables:

---

3. payCheck / payCheckForSup - Process Check Payment

Location: Lines 304, 586

Purpose: Display payment form and process check payment to cash or bank

Process Flow:

1. Load check details by ID

2. Load customer/supplier information

3. Load available cash registers and bank accounts

4. Display payment form with options (cash=0, bank=1)

5. Process payment based on selected method

---

4. payment / paymentSupplier - Execute Payment

Location: Lines 364, 644

Purpose: Execute the actual payment processing

Payment Types:

Process Flow:

1. Validate payment type and amount

2. Update cash register or bank account balance

3. Mark check as done (done=1)

4. Generate accounting entries

5. Update account movements table

---

5. insertSaveAndSaveDaily() - Cash Register Payment

Location: Line 1163

Purpose: Process check payment to cash register

Process Flow:

1. Load current cash register balance

2. Calculate new balance (current + check amount)

3. Insert movement record in savedaily table

4. Update cash register current value

5. Generate daily entry: Debit Cash, Credit Checks Receivable

---

6. addInBankDeposit() - Bank Deposit Payment

Location: Line 1391

Purpose: Process check payment to bank account

Process Flow:

1. Insert record in checkdeposit table

2. Update bank account balance

3. Insert account movement record

4. Generate daily entry: Debit Bank, Credit Checks Receivable

5. Handle both customer and supplier scenarios

---

7. addEndorse() - Check Endorsement

Location: Line 2022

Purpose: Endorse check from one party to another

Function Signature:

function addEndorse()

Process Flow:

1. Load check and endorsement details

2. Update check status to endorsed (done=3)

3. Set endorsement date and person ID

4. Reduce supplier debt by check amount

5. Insert supplier debt change record

6. Generate daily entry for endorsement transaction

---

8. checkCancledForClient() / checkCancelSup() - Cancel Checks

Location: Lines 1717, 1941

Purpose: Cancel checks and reverse transactions

Process Flow:

1. Load check details and current debt

2. Calculate reversed debt amount

3. Update client/supplier debt (reverse original transaction)

4. Insert debt change record for cancellation

5. Reverse original daily entry using reverseEntryWithItsID()

6. Update check with cancellation reason

---

๐Ÿ”„ Workflows

Workflow 1: Customer Check Creation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Customer Owes Money
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Select Check Type
- Choose "Customer" (paytype=0)
- Load customer list and bank list
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Fill Check Details
- Customer ID, Bank Name, Account Number
- Check Number, Amount, Due Date
- Paper Type (1=payable, 0=receivable)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Create Check Record
- Insert into datedchecked table
- Update customer debt (+/- based on paper type)
- Log debt change in clientdebtchange
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Generate Accounting Entry
- IF Payable: Debit Checks Payable, Credit Customer
- IF Receivable: Debit Customer, Credit Checks Recv
- Link daily entry ID to check record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow 2: Check Payment Processing

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Check Due Date Arrives
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Select Check for Payment
- Choose check from pending list
- Load check details and party information
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Choose Payment Method
โ†’ Cash Payment (paytype=0)
โ”‚ โ”‚ โ””โ”€ Select cash register โ”‚
โ”‚ โ””โ”€โ†’ Bank Payment (paytype=1) โ”‚
โ”‚ โ””โ”€ Select bank account โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Process Payment
โ†’ Cash: Update register balance + movement record
โ”‚ โ””โ”€โ†’ Bank: Create deposit + update account balance โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Complete Transaction
- Mark check as done (done=1)
- Generate accounting entry
- Update account movements table
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default viewStart page - select check type
`do=selectCustomer`Customer/supplier selectionShow form to choose customer or supplier
`do=add``add()`Create new post-dated check
`do=showClient`Client check listingShow all customer checks
`do=showSupllier`Supplier check listingShow all supplier checks
`do=payCheck`Payment formDisplay check payment form
`do=payment`Payment processingProcess customer check payment
`do=payCheckForSup`Supplier payment formDisplay supplier check payment form
`do=paymentSupplier`Supplier payment processingProcess supplier check payment
`do=details`Check details viewShow detailed check information
`do=endorse`Endorsement formShow check endorsement form
`do=addEndorse``addEndorse()`Process check endorsement
`do=checkCancledForClient`Cancellation formShow client check cancellation form
`do=checkCancledForSupplier`Supplier cancellation formShow supplier check cancellation form
---

๐Ÿ”’ Security & Permissions

Authentication Requirements

include_once("../public/authentication.php");

User Activity Tracking

Transaction Safety

$mytransactions = new Transaction();
try {
    // Operations here
    $mytransactions->commit();
} catch (Exception $ex) {
    $mytransactions->rollback();
}

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Indexes Required:

- datedchecked(clientNum, dueDate, done)

- clientdebtchange(clientid, clientdebtchangedate)

- supplierdebtchange(supplierid, supplierdebtchangedate)

2. Query Patterns:

- Frequent queries by customer/supplier ID

- Date range filtering on due dates

- Status filtering (done=0 for pending checks)

3. Memory Considerations:

- Check listing may return large datasets

- Consider pagination for high-volume users

---

๐Ÿ› Common Issues & Troubleshooting

1. Check Payment Fails

Issue: Payment process returns error or doesn't update balances

Cause: Insufficient balance in target account or transaction rollback

Debug Steps:

-- Check current account balance
SELECT * FROM save WHERE saveid = [ID];
SELECT * FROM bankaccount WHERE accountid = [ID];

-- Check for failed transactions
SELECT * FROM datedchecked WHERE done = 0 AND dueDate < NOW();

2. Missing Daily Entries

Issue: Check transactions don't appear in accounting reports

Cause: Daily entry generation failed or was not linked

Fix:

-- Find checks without daily entries
SELECT * FROM datedchecked WHERE dailyentryid = 0 OR dailyentryid IS NULL;

3. Debt Calculation Errors

Issue: Customer/supplier debt doesn't match check amounts

Cause: Incorrect debt type calculation or missing debt change records

Debug:

-- Verify debt change records
SELECT SUM(CASE WHEN clientdebtchangetype = 0 THEN clientdebtchangeamount 
               ELSE -clientdebtchangeamount END) as calculated_debt
FROM clientdebtchange 
WHERE clientid = [ID] AND tablename = 'datedCheckedController.php';

4. Endorsement Issues

Issue: Check endorsement doesn't transfer properly

Cause: Missing supplier debt update or incorrect accounting entry

Verification:

-- Check endorsement status
SELECT * FROM datedchecked WHERE done = 3 AND endorsePersonId IS NOT NULL;

---

๐Ÿงช Testing Scenarios

Test Case 1: Customer Check Creation

1. Create customer receivable check
2. Verify customer debt increases by check amount
3. Confirm daily entry created (Dr: Customer, Cr: Checks Receivable)
4. Check debt change record in clientdebtchange table

Test Case 2: Check Payment to Cash

1. Create check and process payment to cash register
2. Verify cash register balance increases
3. Check movement record in savedaily table
4. Confirm check marked as done (done=1)

Test Case 3: Check Endorsement

1. Create customer check
2. Endorse to supplier
3. Verify supplier debt decreases
4. Check endorsement fields updated
5. Confirm daily entry for endorsement transaction

Test Case 4: Check Cancellation

1. Create check
2. Cancel with reason
3. Verify debt reversal
4. Check original daily entry is reversed
5. Confirm cancellation reason recorded

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur