ReturnBuyBill Documentation
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:
- โข Creating and editing purchase return bills (return buy bills)
- โข Adjusting supplier debts for returned goods
- โข Restoring inventory levels after returns
- โข Managing cash register adjustments for refunds
- โข Serial number tracking for returned items
- โข Daily accounting entries for returns
- โข Currency conversion for multi-currency returns
Primary Functions
- โ Create new purchase return bills
- โ Edit existing return bills
- โ Delete return bills
- โ View return bill details
- โ Print return bills
- โ Adjust supplier debts
- โ Update inventory quantities
- โ Track serial numbers
- โ Generate accounting entries
- โ Handle multi-currency returns
Related Controllers
- โข buyBillController.php - Original purchase operations
- โข supplierController.php - Supplier management
- โข productController.php - Product management
- โข storeController.php - Warehouse/store management
- โข returnSellBillController.php - Sales returns
- โข storedetailController.php - Inventory management
- โข dailyentryController.php - Accounting entries
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **returnbuybill** | Main return bills | returnbuybillid, returnbuybillserial, returnbuybilldate, returnbuybilltotalbill, returnbuybillsupplierid, returnbuybillstoreid | |
| **returnbuybilldetail** | Return bill line items | returnbuybilldetailid, returnbuybillid, returnbuybilldetailproductid, returnbuybilldetailquantity, returnbuybilldetailprice | |
| **returnbuybillcurr** | Multi-currency returns | returnbuybillcurrid, returnbuybillid, returnbuybillcurrencyid, returnbuybillexchangerate |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **storedetail** | Stock quantities by store | Increased on returns | |
| **sizecolorstoredetail** | Stock by size/color variants | For variant products | |
| **storereport** | Stock movement history | Audit trail for returns | |
| **buypriceshistorybook** | Purchase price history | Cost tracking | |
| **productserial** | Serial number tracking | For serialized items |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **supplier** | Supplier master data | returnbuybill.returnbuybillsupplierid | |
| **supplierdebtchange** | Supplier debt changes | Debt reduction tracking | |
| **save** | Cash registers/safes | returnbuybill.returnbuybillsaveid | |
| **savedaily** | Daily cash movements | Financial reconciliation | |
| **dailyentry** | Accounting journal entries | Auto-generated from returns |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **product** | Product master data | Foreign key in details | |
| **productunit** | Units of measurement | returnbuybilldetail.productunitid | |
| **store** | Warehouses/stores | returnbuybill.returnbuybillstoreid | |
| **billname** | Bill templates/types | returnbuybill.billnameid | |
| **billsettings** | Bill configuration | Per bill type settings | |
| **currency** | Currency definitions | For 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):
- โข
returnbuybillId- ID of existing bill (empty for new) - โข
returnbuybillserial- Serial number - โข
returnbuybillsupplierid- Supplier ID - โข
returnbuybillstoreid- Store ID - โข
returnbuybillsaveid- Cash register ID - โข
returnbuybilldate- Return date - โข
returnbuybilltotalbill- Total amount
Database Operations:
- โข INSERT/UPDATE
returnbuybill - โข INSERT/UPDATE
returnbuybilldetail - โข UPDATE
supplier(debt reduction) - โข UPDATE
storedetail(inventory increase) - โข INSERT
storereport(audit trail) - โข INSERT
savedaily(cash movement)
Business Logic Flow:
2. showBillDetails($returnbuybillId)
Purpose: Display detailed view of a specific return bill
Parameters: $returnbuybillId - Return bill ID
Line: 572
Returns: Formatted HTML view with:
- โข Return bill header information
- โข Line items with products and quantities
- โข Supplier information
- โข Total amounts and currency
3. delete()
Purpose: Delete a return buy bill and reverse all its effects
Called By: Form with ?do=delete
Line: 711
Database Operations:
- โข Reverse supplier debt changes
- โข Reverse inventory adjustments
- โข Reverse cash register changes
- โข DELETE from
returnbuybilldetail - โข DELETE from
returnbuybill - โข INSERT audit records
4. getStoreDetails($storeId, $productId, $unittype, $sizeColorStoreDetailId, $sizeId, $colorId)
Purpose: Retrieve current stock levels for a product in a store
Line: 1135
Parameters:
- โข
$storeId- Store identifier - โข
$productId- Product identifier - โข
$unittype- Unit type (1=main, 2=secondary) - โข
$sizeColorStoreDetailId- Size/color variant ID - โข
$sizeId,$colorId- Variant identifiers
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:
- โข UPDATE
storedetailSET quantity = quantity + amount - โข UPDATE
sizecolorstoredetailif variants exist - โข INSERT
storereportfor audit trail
6. updateSupplierDebt($supplierId, $supplierDebtAfter, $totaldeptafterInMainCurr)
Purpose: Reduce supplier debt when goods are returned
Line: 1330
Parameters:
- โข
$supplierId- Supplier identifier - โข
$supplierDebtAfter- New debt amount - โข
$totaldeptafterInMainCurr- Debt in main currency
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
Files Involved:
- โข View:
/views/default/returnbuybill/returnbuybill_add.html - โข Model:
/models/dto/Returnbuybill.class.php - โข DAO:
/models/mysql/ReturnbuybillMySqlDAO.class.php
---
โ ๏ธ 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
- โข
ReturnbuybillDAO- Return bill operations - โข
ReturnbuybilldetailDAO- Return line items - โข
SupplierDAO- Supplier management - โข
StoredetailDAO- Inventory operations - โข
StorereportDAO- Audit trail - โข
SaveDAO- Cash register operations - โข
ProductDAO- Product information
Related Views
- โข
/views/default/returnbuybill/returnbuybill_add.html- Return form - โข
/views/default/returnbuybill/returnbuybill_show.html- Return list - โข
/views/default/returnbuybill/returnbuybill_details.html- Return details
JavaScript Files
- โข
/views/default/assets/js/returnbuybill.js- Return bill functionality
---
๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template | |
|---|---|---|---|---|
| show | GET | Display return bills list | returnbuybill_show.html | |
| editprint | POST | Create/edit return bill | returnbuybill_add.html | |
| details | GET | Show return bill details | returnbuybill_details.html | |
| delete | POST | Delete return bill | - | |
| sucess | GET | Success confirmation | success.html | |
| error | GET | Error display | error.html |
๐ Permissions & Security
Required Permissions
- โข Return bill creation/editing rights
- โข Supplier management access
- โข Inventory adjustment permissions
Security Checks
include_once("../public/authentication.php");
include_once("initiateStaticSessionCommingWithCurl.php");
---
๐ Notes
Important Considerations
- โข Return bills must reference original purchase bills
- โข Inventory adjustments are immediate and permanent
- โข Supplier debt changes must be properly tracked
- โข Multi-currency calculations require exchange rates
- โข Serial numbers must be properly handled for returns
Future Improvements
- โป๏ธ Add batch return processing
- โป๏ธ Implement return approval workflow
- โป๏ธ Add return reason codes
- โป๏ธ Integrate with quality control system
- โป๏ธ Add return analytics dashboard
---