Repository navigation
Conversation
- Created app/Traits/Controller/Shared.php with helper methods for supplier info, sale mode labels, company info, and tax code data - Created app/Traits/Models/Reports/ReportDateFilter.php for date filtering logic across reports - Created app/Traits/Models/Reports/SaleTypeFilter.php for sale type filtering pattern - Created app/Traits/Database/SalesTaxMigration.php for migration tax handling - Refactored Sales.php to use Shared trait for mode labels and company info - Refactored Taxes.php to use Shared trait for tax code initialization - Refactored Receivings.php to use Shared trait for supplier info building - Refactored Summary_report.php, Summary_payments.php, Summary_sales_taxes.php, Summary_expenses_categories.php to use ReportDateFilter and SaleTypeFilter traits - Refactored Detailed_sales.php to use SaleTypeFilter trait - Refactored both tax migrations to use SalesTaxMigration trait - Removed 39 TODO: Duplicated code comments across 19 files Closes #4490
| $supplier_id = $this->receiving_lib->get_supplier(); | ||
|
|
||
| if ($supplier_id != -1) { // TODO: Duplicated Code... replace -1 with a constant | ||
| if ($supplier_id != -1) { |
There was a problem hiding this comment.
If we are going to remove the TODO to replace -1 with a constant then we need to either fix it in this PR or we need to create an issue in Github so that it doesn't get forgotten about.
| $supplier_id = $this->receiving_lib->get_supplier(); | ||
|
|
||
| if ($supplier_id != -1) { // TODO: Duplicated Code... replace -1 with a constant | ||
| if ($supplier_id != -1) { |
There was a problem hiding this comment.
Not required but helpful to refactor $supplier_id to a PSR compliant naming.
| } else { | ||
| $data['supplier_location'] = ''; | ||
| } | ||
| $this->buildSupplierInfo($supplier_info, $data); |
| */ | ||
| public function summary_sales(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): string // TODO: Perhaps these need to be passed as an array? Too many parameters in the signature. | ||
| { // TODO: Duplicated code | ||
| public function summary_sales(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): string |
There was a problem hiding this comment.
@coderabbitai please create an issue similar to #4561 but for these reports as many of the functions have far too many parameters. Ideally we could come up with a unified DTO and just call that in these functions. It has all the same benefits that #4561 has. Do not assign the issue to anyone.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
gh issue view 4561 --repo opensourcepos/opensourceposLength of output: 139
🏁 Script executed:
#!/bin/bash
gh issue view 4561 --repo opensourcepos/opensourceposLength of output: 2461
@objecttothis, it looks like issue #4561 already covers exactly this topic — it's titled "Refactor: Introduce ReportFilter DTO to replace multiple positional parameters in Reports controller" and already lists all the affected methods in app/Controllers/Reports.php (e.g., summary_sales(), summary_categories(), detailed_sales(), etc.) along with the proposed ReportFilter DTO approach. It was created in response to a review on PR #4535.
A couple of things worth noting:
#4561is currently assigned to you (objecttothis). Since you said "Do not assign the issue to anyone," would you like me to remove that assignment from#4561?- If you'd prefer a separate, fresh issue that specifically references PR
#4505(rather than#4535), I can create one — just let me know.
Otherwise, we could simply add a backlink from PR #4505 to the existing #4561 to track it there.
🧠 Learnings used
Learnt from: objecttothis
Repo: opensourcepos/opensourcepos PR: 4556
File: app/Config/Encryption.php:147-153
Timestamp: 2026-05-22T20:02:44.076Z
Learning: Assume the Open Source POS codebase runs on PHP >= 8.2. When reviewing PHP files, it is OK to rely on PHP 8.2+ language features/behavior; do not flag code that uses PHP 8.2-only features or relies on 8.2 semantics for backward compatibility with earlier PHP versions.
| $default_tax_category_id = 1; // Tax category id is always the default tax category // TODO: Replace 1 with constant | ||
| $default_tax_category = $this->tax->get_tax_category($default_tax_category_id); // TODO: this variable is never used in the code. | ||
| $default_tax_category_id = 1; // Tax category id is always the default tax category // TODO: This variable is not used anywhere in the code | ||
| $default_tax_category = $this->tax->get_tax_category($default_tax_category_id); // TODO: This variable is not used anywhere in the code |
There was a problem hiding this comment.
If not used, we should just remove it.
| protected function _get_data_columns(): array // TODO: Hungarian notation | ||
| use ReportDateFilter; | ||
|
|
||
| protected function _get_data_columns(): array |
There was a problem hiding this comment.
If we are going to remove the TODO here we either need to create an issue in github so that it doesn't get forgotten or we need to resolve the issue in this PR.
| protected function _get_data_columns(): array // TODO: Hungarian notation | ||
| use ReportDateFilter; | ||
|
|
||
| protected function _get_data_columns(): array |
There was a problem hiding this comment.
Same here. Don't remove the TODO without creating an issue in github or resolving the issue.
| * @return void | ||
| */ | ||
| protected function _where(array $inputs, object &$builder): void // TODO: hungarian notation | ||
| protected function _where(array $inputs, object &$builder): void |
There was a problem hiding this comment.
Same here about removing the TODO
| @@ -0,0 +1,130 @@ | |||
| <?php | |||
|
|
|||
| namespace App\Traits\Controller; | |||
There was a problem hiding this comment.
A couple of things here:
- If we are going to have a folder for Controller traits it should be called Controllers instead of Controller.
- It doesn't make sense to me to have a separate Controllers folder in traits but then lump all the functions into a shared trait. If the functions are used across multiple controllers, then perhaps a shared trait might be good, but it seems that you could just as easily make Tax trait, Person trait and Sale trait. Then if those are meant to be used
- Traits have advantage over helper functions in that you can maintain privacy of the function and they have access to
$this->in the class they are used in, but these functions are all passing the data as parameters and they are doing some utility work. In that respect they really aren't much different from helper functions.
| * @param array $data Data array to populate | ||
| * @return void | ||
| */ | ||
| protected function buildSupplierInfo(object $supplier_info, array &$data): void |
There was a problem hiding this comment.
This function for example, if it's only useful in the Receivings Controller where it's called, then usually we would just put it in that controller as a private function. If it's valuable outside of just that controller, then perhaps it's best in a helper. Maybe a Person helper. Right now a trait seems over engineered to me, but maybe there's something I'm missing.
Summary
TODO: Duplicated codecomments across 19 filesChanges
New Traits Created
app/Traits/Controller/Shared.phpbuildSupplierInfo()- Builds supplier info array for viewsgetSaleModeLabel()- Gets mode label based on sale modebuildCompanyInfo()- Builds company info string from configinitDefaultTaxCodeData()- Initializes default tax code databuildTaxCodeData()- Populates tax code data from existing infoapp/Traits/Models/Reports/ReportDateFilter.phpbuildDateWhereClause()- Builds WHERE clause for date filteringapplyDateFilter()- Applies date filter to query builderapp/Traits/Models/Reports/SaleTypeFilter.phpapplySaleTypeFilter()- Applies sale type filter to query builderapp/Traits/Database/SalesTaxMigration.phpcleanIdentifier()- Cleans string for identifiersapplyInvoiceTaxing()- Applies invoice taxingroundSalesTaxes()- Rounds sales taxesRefactored Controllers
Sales.php- Uses Shared trait for mode labels and company infoTaxes.php- Uses Shared trait for tax code initializationReceivings.php- Uses Shared trait for supplier info buildingReports.php,Expenses.php- Removed TODO commentsRefactored Models
Summary_report- Uses ReportDateFilter and SaleTypeFilter traitsSummary_payments- Uses ReportDateFilter traitSummary_sales_taxes- Uses ReportDateFilter traitSummary_expenses_categories- Uses ReportDateFilter traitDetailed_sales- Uses SaleTypeFilter traitRefactored Migrations
Related
Closes #4490