From 6f9bdff1150fd4e080fd07a1783ea0fece72a325 Mon Sep 17 00:00:00 2001 From: eko54r Date: Thu, 14 May 2026 12:25:21 +0700 Subject: [PATCH] update --- ...hrough__Fixing_PostgreSQL_Compatibility.md | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/walkthroughs/2026-05-14_b817429e_Walkthrough__Fixing_PostgreSQL_Compatibility.md b/walkthroughs/2026-05-14_b817429e_Walkthrough__Fixing_PostgreSQL_Compatibility.md index 5793c45f..6a1a069d 100644 --- a/walkthroughs/2026-05-14_b817429e_Walkthrough__Fixing_PostgreSQL_Compatibility.md +++ b/walkthroughs/2026-05-14_b817429e_Walkthrough__Fixing_PostgreSQL_Compatibility.md @@ -1,24 +1,37 @@ -# Walkthrough - Fixing PostgreSQL Compatibility +# Fix: BadMethodCallException & PostgreSQL Compatibility Audit -I have resolved the SQL errors occurring in the Loss Profit History module when running on PostgreSQL. +I have resolved the `BadMethodCallException` reported in the `AcnooSaleController` and performed a final "automated" audit to fix remaining PostgreSQL compatibility issues. ## Changes Made -### Business Module Controllers -- **[AcnooLossProfitHistoryController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/Business/App/Http/Controllers/AcnooLossProfitHistoryController.php)**: - - Quoted `saleDate`, `lossProfit`, `incomeDate`, `expenseDate`, and `date` columns in all `DB::raw` expressions. - - Changed double quotes (`"`) to single quotes (`'`) for string literals (`'positive'`, `'negative'`) in `CASE` statements. -- **[AcnooLossProfitHistoryReportController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/Business/App/Http/Controllers/AcnooLossProfitHistoryReportController.php)**: - - Applied identical fixes for PostgreSQL compatibility. -- **[AcnooProductLossProfitReportController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/Business/App/Http/Controllers/AcnooProductLossProfitReportController.php)**: - - Quoted `lossProfit` in `CASE` statements. +### 1. Fixed Missing `dueForBranch` Method +- **File**: [Party.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/app/Models/Party.php) +- **Fix**: Implemented the `dueForBranch($branchId = null)` method in the `Party` model. +- **Logic**: + - For **Suppliers**: Sums `dueAmount` from the `purchases` table for the specified branch. + - For **Customers**: Sums `dueAmount` from the `sales` table for the specified branch. + - This resolves the crash on the Sale and Purchase creation screens. -### Export Classes -- **[ExportLossProfitHistory.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/Business/App/Exports/ExportLossProfitHistory.php)**: - - Fixed column quoting and string literals for Excel/CSV exports. -- **[ExportProductLossProfit.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/Business/App/Exports/ExportProductLossProfit.php)**: - - Fixed column quoting in `CASE` statements for product loss/profit exports. +### 2. Automated PostgreSQL Audit & Fixes +I ran an audit script to find remaining MySQL-specific syntax or unquoted mixed-case identifiers. -## Verification Results -- The code changes directly address the `SQLSTATE[42703]` (Undefined column) error by ensuring PostgreSQL recognizes the mixed-case column names. -- String literal fixes prevent PostgreSQL from interpreting `'positive'` and `'negative'` as column names. +- **[AcnooBranchController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/Modules/MultiBranchAddon/App/Http/Controllers/AcnooBranchController.php)**: Quoted `"lossProfit"` in `incomeExpense` reports. +- **[Admin/DashboardController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/app/Http/Controllers/Admin/DashboardController.php)**: + - Updated `TO_CHAR` format to `FMMonth` to avoid padded spaces. + - Fixed `groupBy` to use the full expression instead of an alias for better PostgreSQL compatibility. +- **[StatisticsController.php](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/app/Http/Controllers/Api/StatisticsController.php)**: + - Updated `groupBy` logic to use the `TO_CHAR` expression directly, preventing "must appear in the GROUP BY clause" errors. + +## Verification + +### Automated Audit +- The audit script was used to identify these locations. +- You can find the script here: [audit_postgres.py](file:///media/itc43/Data/OTHER_PROJECT/kulakpos/kulakpos_15Maret2026_to%20GTEA/public_html/scratch/audit_postgres.py). + +### Manual Verification Required +1. **Sale Creation**: Open the "Create Sale" screen to verify that customer due amounts are now displayed correctly without error. +2. **Purchase Creation**: Open the "Create Purchase" screen to verify supplier due amounts. +3. **Reports**: Check the Branch Income/Expense report and Admin Dashboard to ensure charts are rendering correctly. + +> [!NOTE] +> I have committed these changes locally. Please run `git push` from your terminal to upload the fixes to your repository.