๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Return Buy Bill Controller Documentation

File: /controllers/returnBuyBillController.php

Purpose: Manages purchase return operations, refunds to suppliers, and inventory adjustments for returned goods

Last Updated: December 19, 2024

Total Functions: 30

Lines of Code: 1,464

---

๐Ÿ“‹ Overview

The Return Buy Bill Controller handles all operations related to returning purchased goods back to suppliers. It manages:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**returnbuybill**Main return billsreturnbuybillid, returnbuybillserial, returnbuybilldate, returnbuybilltotalbill, returnbuybillsupplierid, returnbuybillstoreid
**returnbuybilldetail**Return bill line itemsreturnbuybilldetailid, returnbuybillid, returnbuybilldetailproductid, returnbuybilldetailquantity, returnbuybilldetailprice
**returnbuybillcurr**Multi-currency returnsreturnbuybillcurrid, returnbuybillid, returnbuybillcurrencyid, returnbuybillexchangerate
### Inventory Tables (Updated)

Table NamePurposeRelationship
**storedetail**Stock quantities by storeIncreased on returns
**sizecolorstoredetail**Stock by size/color variantsFor variant products
**storereport**Stock movement historyAudit trail for returns
**buypriceshistorybook**Purchase price historyCost tracking
**productserial**Serial number trackingFor serialized items
### Financial Tables

Table NamePurposeRelationship
**supplier**Supplier master datareturnbuybill.returnbuybillsupplierid
**supplierdebtchange**Supplier debt changesDebt reduction tracking
**save**Cash registers/safesreturnbuybill.returnbuybillsaveid
**savedaily**Daily cash movementsFinancial reconciliation
**dailyentry**Accounting journal entriesAuto-generated from returns
### Reference Tables

Table NamePurposeRelationship
**product**Product master dataForeign key in details
**productunit**Units of measurementreturnbuybilldetail.productunitid
**store**Warehouses/storesreturnbuybill.returnbuybillstoreid
**billname**Bill templates/typesreturnbuybill.billnameid
**billsettings**Bill configurationPer bill type settings
**currency**Currency definitionsFor multi-currency
---

๐Ÿ”ง Key Functions

1. editprint()

Purpose: Main entry point for creating/editing return buy bills

Called By: Form submission with ?do=editprint

Line: 319

Parameters (via $_POST):

Database Operations:

Business Logic Flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
User submits
return form
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Validate data
& permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Save return
bill header
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Process each
returned item
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Update supplier
debt (decrease)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Increase store
inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create daily
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2. showBillDetails($returnbuybillId)

Purpose: Display detailed view of a specific return bill

Parameters: $returnbuybillId - Return bill ID

Line: 572

Returns: Formatted HTML view with:

3. delete()

Purpose: Delete a return buy bill and reverse all its effects

Called By: Form with ?do=delete

Line: 711

Database Operations:

4. getStoreDetails($storeId, $productId, $unittype, $sizeColorStoreDetailId, $sizeId, $colorId)

Purpose: Retrieve current stock levels for a product in a store

Line: 1135

Parameters:

Returns: Current quantity and store detail record

5. increaseProductQuantity($storedetailId, $productquantityBefore, $productChangeAmount, $sizeColorStoreDetailId, $sizeId, $colorId)

Purpose: Increase inventory when products are returned

Line: 1161

Database Operations:

6. updateSupplierDebt($supplierId, $supplierDebtAfter, $totaldeptafterInMainCurr)

Purpose: Reduce supplier debt when goods are returned

Line: 1330

Parameters:

7. insertSupplierDebtChange($supplierId, $supplierDebtChangeBefore, $supplierDebtChangeBeforeInMainCurr, $supplierDebtChangeAmountInMainCurr, $supplierDebtChangeAmount, $supplierDebtChangeType, $processname, $supplierDebtChangeModelId, $supplierDebtChangeAfter, $supplierDebtChangeAfterInMainCurr, $tablename, $comment)

Purpose: Record supplier debt change for audit trail

Line: 1346

---

๐Ÿ”„ Business Logic Flow

Return Purchase Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Original
Purchase Bill
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Select Products
to Return
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create Return
Bill Header
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Add Return
Line Items
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Calculate
Return Amount
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Update Supplier
Debt (Reduce)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Increase Store
Inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Update Cash
Register
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Create Daily
Entry Record
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
Generate
Return Receipt
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Files Involved:

---

โš ๏ธ Common Issues

Issue 1: Object Initialization

Problem: Fatal error: Attempt to assign property on null

Cause: PHP 8.2 requires explicit object initialization

Fix: Initialize objects before property assignment

Files: Various functions throughout controller

Issue 2: Type Conversion

Problem: TypeError: Unsupported operand types: string + string

Cause: PHP 8.2 strict type checking for arithmetic

Fix: Cast strings to numeric types before calculations

Issue 3: Array Validation

Problem: TypeError: count(): Argument must be Countable

Cause: count() called on non-array values

Fix: Use !empty() or validate array type first

---

๐Ÿ”— Dependencies

Includes

include("../public/impOpreation.php");
include_once("../public/config.php");
include_once("dailyentryfun.php");
include("../public/include_dao.php");

Required DAOs

Related Views

JavaScript Files

---

๐ŸŽฏ URL Routes & Actions

Action (`?do=`)MethodDescriptionView Template
showGETDisplay return bills listreturnbuybill_show.html
editprintPOSTCreate/edit return billreturnbuybill_add.html
detailsGETShow return bill detailsreturnbuybill_details.html
deletePOSTDelete return bill-
sucessGETSuccess confirmationsuccess.html
errorGETError displayerror.html
---

๐Ÿ” Permissions & Security

Required Permissions

Security Checks

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

---

๐Ÿ“ Notes

Important Considerations

Future Improvements

---

๐Ÿ“š Related Documentation

โ†‘