Skip to content

Person attributes - #3161

Open
DamianoSilverhand wants to merge 5 commits into
opensourcepos:masterfrom
DamianoSilverhand:person_attributes
Open

DamianoSilverhand wants to merge 5 commits into
opensourcepos:masterfrom
DamianoSilverhand:person_attributes

Conversation

@DamianoSilverhand

Copy link
Copy Markdown

This PR adds person attributes on Customers, Suppliers and Employees. Also includes person attributes in customer import using csv.

@DamianoSilverhand DamianoSilverhand mentioned this pull request Apr 16, 2021
@stale

stale Bot commented May 22, 2021

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the wontfix label May 22, 2021
@jekkos jekkos self-assigned this May 25, 2021
@stale stale Bot removed the wontfix label May 25, 2021
@jekkos jekkos added this to the 3.4.0 milestone May 28, 2021
@jekkos

jekkos commented May 28, 2021

Copy link
Copy Markdown
Member

We'll rebase / review again after next changes for item import of @objecttothis are integrated.

Comment thread application/controllers/Customers.php Resolved

@objecttothis objecttothis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do a full review. Just the one change that I noted.

$failCodes[] = $i;
$failed_row = $i+1;
$failCodes[] = $failed_row;
log_message("ERROR","CSV Item import failed on line ". $failed_row .". This customer was not imported.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs to change. I think it probably needs to read something like log_message("ERROR","CSV Customer import failed on line ". $failed_row .". This customer was not imported.");

@objecttothis objecttothis Jul 14, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you aren't using string interpolation you need to use ' not ". " calls the parser unnecessarily when there are no variables to parse. That said, this line would be better written with string interpolation:
log_message("ERROR","CSV Customer import failed on line $failed_row. This customer was not imported.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamianoSilverhand still motivated to drive this one home?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos if you can get the Person Attributes to show in the table view he might get interested in it again. LOL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have cloned and rebased the branch and pushed it to the organisation's repo now.. let's see what changes are in there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odiea maybe you were referring to #2819 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, we need to fix that first so this change can be implemented correctly

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos @odiea I am still motivated, just that table view issue.

@odiea odiea Jul 26, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jekkos I downloaded this version but Now I am unable to update an employee. The Dev server does the same. Unable to update Employee. I can create a new Employee. The Demo server also does not allow the Employee to be updated and I am getting no errors with errors set to 1 . I narrowed it down to the following commit. Check username before employee creation (#3239)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for testing, I'll have look later, I probably missed something there. It might have been better to implement the check as a jQuery validation instead.

@objecttothis objecttothis modified the milestones: 3.4.0, 3.5.0 Dec 10, 2022
@jekkos
jekkos force-pushed the master branch 4 times, most recently from fddedb8 to 6d106d6 Compare November 14, 2024 23:13
@jekkos
jekkos force-pushed the master branch 7 times, most recently from 32cd824 to cce2c1c Compare December 26, 2024 22:21
@objecttothis

Copy link
Copy Markdown
Member

@DamianoSilverhand now that CI4 has been merged into the master can you rebase your changes so we can proceed?

@objecttothis

Copy link
Copy Markdown
Member

@jekkos this PR seems to have gone stale. It is a change I will eventually get to, but other changes are taking priority at the moment. Do you have any thoughts for what we should do with this PR? I never heard back from @DamianoSilverhand.

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

PR #3161 Rework Plan - Person Attributes (Unified Architecture)

This is a plan to modernize and properly implement person attributes using the unified attribute system.

Current Status

I'm working on a reimplementation based on the latest CI4 master branch with the following approach:

Architectural Approach

Using Unified Attribute System (instead of separate person_attribute tables):

  • Add person_id column to existing attribute_links table
  • Add visibility flags: SHOW_IN_CUSTOMERS = 8, SHOW_IN_EMPLOYEES = 16, SHOW_IN_SUPPLIERS = 32
  • Reuse existing attribute_definitions, attribute_values, and attribute_links tables
  • Shared logic in base Persons controller for Customers, Employees, Suppliers

Implementation Progress

✅ Completed:

  • Database migration for person_id in attribute_links
  • Attribute model updated with person support
  • Persons controller with shared attribute handling
  • attributes/person.php view created

🔄 In Progress:

  • Customer/Employee/Supplier controller integration

📋 Remaining:

  • Update person form views
  • Attribute definition form visibility flags
  • Table display helpers
  • Language strings

Benefits of Unified Approach

  1. Consistency - Same attribute system for items, sales, receivings, and persons
  2. Less code duplication - Reuse existing attribute infrastructure
  3. Easier maintenance - Single source of truth for attribute logic
  4. CI4 native - Built on current codebase, not CI3

Worktree

Working in: opensourcepos-person-attributes branch feature/person-attributes

I'll update this PR as progress continues. Feedback welcome on the architectural approach.

@objecttothis

Copy link
Copy Markdown
Member

PR #3161 Rework Plan - Person Attributes (Unified Architecture)

This is a plan to modernize and properly implement person attributes using the unified attribute system.

Current Status

I'm working on a reimplementation based on the latest CI4 master branch with the following approach:

Architectural Approach

Using Unified Attribute System (instead of separate person_attribute tables):

* Add `person_id` column to existing `attribute_links` table

* Add visibility flags: `SHOW_IN_CUSTOMERS = 8`, `SHOW_IN_EMPLOYEES = 16`, `SHOW_IN_SUPPLIERS = 32`

* Reuse existing `attribute_definitions`, `attribute_values`, and `attribute_links` tables

* Shared logic in base `Persons` controller for Customers, Employees, Suppliers

Implementation Progress

✅ Completed:

* Database migration for `person_id` in `attribute_links`

* Attribute model updated with person support

* Persons controller with shared attribute handling

* attributes/person.php view created

🔄 In Progress:

* Customer/Employee/Supplier controller integration

📋 Remaining:

* Update person form views

* Attribute definition form visibility flags

* Table display helpers

* Language strings

Benefits of Unified Approach

1. **Consistency** - Same attribute system for items, sales, receivings, and persons

2. **Less code duplication** - Reuse existing attribute infrastructure

3. **Easier maintenance** - Single source of truth for attribute logic

4. **CI4 native** - Built on current codebase, not CI3

Worktree

Working in: opensourcepos-person-attributes branch feature/person-attributes

I'll update this PR as progress continues. Feedback welcome on the architectural approach.

Excellent choice to re-use the existing architecture to add person attributes. We need to consider indices on the attribute_links table and rework them so they are optimized for the queries we are doing. Right now there are potentially too many indices, which will slow down write operations.

With attribute_definitions we likely need to maintain two different views in the UI. One for Person Attributes and the other for Item attributes. In the attribute_definitions table we should add a person_attribute column to store the boolean value so that the business logic in each model can properly return only item attributes or only person attributes.

@objecttothis

Copy link
Copy Markdown
Member

Excellent choice to re-use the existing architecture to add person attributes. We need to consider indices on the attribute_links table and rework them so they are optimized for the queries we are doing. Right now there are potentially too many indices, which will slow down write operations.

With attribute_definitions we likely need to maintain two different views in the UI. One for Person Attributes and the other for Item attributes. In the attribute_definitions table we should add a person_attribute column to store the boolean value so that the business logic in each model can properly return only item attributes or only person attributes.

We also need to make sure person attributes are not allowed to be added to items and vis a versa. If we are keeping one Model and Controller for Attributes rather than breaking it into two, that's fine but we need to think through the best way to structure CRUD methods then so that we are not writing a lot of redundant code. Potentially one way to do this would be to add a parameter to indicate the attribute type. This could be a bool isPersonAttribute = false or we could make it an int to represent an attribute type, but I would not pass a string since that increases the risk of typos causing bugs.

Something to consider regarding visibility is that it should not just affect the manage.php view in terms of which columns show up in the table. visibility should also prevent that type of attribute from being added to that type of person. Currently in item attributes I believe visibility just affects whether it appears in the table. We need a way of restricting person attributes from being added to specific types of people. For example a DROPDOWN attribute called "Role" may be good to show up for Employees but we don't want it appearing in Customer views. Visibility is how we should do that restricting, but I don't think we should change the current behavior for item attributes.

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

Progress Update

The person attributes implementation is progressing well. Here's the current status:

✅ Completed

  • Database migration for person_id column in attribute_links
  • Attribute model: Added person constants (SHOW_IN_CUSTOMERS=16, SHOW_IN_EMPLOYEES=32, SHOW_IN_SUPPLIERS=64) and person attribute methods
  • Persons controller: Added shared getPersonAttributes() and savePersonAttributes() methods
  • Customer/Employee/Supplier controllers: Added getAttributes() method and integrated attribute saving in postSave()
  • Created app/Views/attributes/person.php view
  • Updated app/Language/en/Attributes.php with person visibility labels
  • Updated Attributes controller to include person flags

🔄 Remaining

  • Add person attributes container to person forms (form_basic_info.php or person-specific forms)
  • Update attributes/form.php to properly show visibility checkboxes
  • Table display helpers for person attributes

Constants (bit flags)

SHOW_IN_ITEMS = 1
SHOW_IN_SALES = 2
SHOW_IN_RECEIVINGS = 4
SHOW_IN_SEARCH = 8
SHOW_IN_CUSTOMERS = 16
SHOW_IN_EMPLOYEES = 32
SHOW_IN_SUPPLIERS = 64

Working in worktree: opensourcepos-person-attributes on branch feature/person-attributes

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

Implementation Complete ✓

The person attributes implementation is now complete. Here's the summary:

Files Changed

New Files:

  • app/Database/Migrations/20260402000000_AddPersonToAttributeLinks.php - Migration for person_id column
  • app/Views/attributes/person.php - View for rendering person attributes

Modified Files:

  • app/Models/Attribute.php - Added person attribute methods and constants
  • app/Controllers/Persons.php - Added shared attribute handling methods
  • app/Controllers/Customers.php - PSR-12 naming + attribute save integration
  • app/Controllers/Employees.php - PSR-12 naming + attribute save integration
  • app/Controllers/Suppliers.php - PSR-12 naming + attribute save integration
  • app/Controllers/Attributes.php - Added person flags to visibility
  • app/Language/en/Attributes.php - Added person visibility labels
  • app/Views/customers/form.php - Added person attributes container
  • app/Views/employees/form.php - Added person attributes container
  • app/Views/suppliers/form.php - Added person attributes container

Constants (Bit Flags)

SHOW_IN_ITEMS = 1
SHOW_IN_SALES = 2
SHOW_IN_RECEIVINGS = 4
SHOW_IN_SEARCH = 8
SHOW_IN_CUSTOMERS = 16
SHOW_IN_EMPLOYEES = 32
SHOW_IN_SUPPLIERS = 64

Architecture

  • Unified attribute system: person_id added to existing attribute_links table
  • Shared logic in Persons controller: getPersonAttributes() and savePersonAttributes()
  • Per-person-type visibility flags: Attributes can be shown for customers, employees, or suppliers independently

Next Steps

  1. Run database migration to add person_id column
  2. Test the attribute forms for each person type (customer, employee, supplier)
  3. Verify attribute visibility settings work correctly

Worktree: opensourcepos-person-attributes on branch feature/person-attributes

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

Rebase Complete ✓

The branch has been rebased on top of the latest master (commit 165c335).

Conflict Resolved

  • app/Models/Attribute.php - Combined the new upstream updateAttributeValue() method with the person attribute methods

Files Changed

modified:   app/Controllers/Attributes.php
modified:   app/Controllers/Customers.php
modified:   app/Controllers/Employees.php
modified:   app/Controllers/Persons.php
modified:   app/Controllers/Suppliers.php
new file:   app/Database/Migrations/20260402000000_AddPersonToAttributeLinks.php
modified:   app/Language/en/Attributes.php
modified:   app/Models/Attribute.php
new file:   app/Views/attributes/person.php
modified:   app/Views/customers/form.php
modified:   app/Views/employees/form.php
modified:   app/Views/suppliers/form.php

The branch is now ready for testing. The person attributes feature has been properly integrated with the latest changes from master.

$this->load->view("customers/form", $data);
}

/*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPdocs that don't add information of value should be removed completely.

Adds Person_attributes to customer controller
*/

public function person_attributes($customer_id = -1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new code should have PSR compliant function and variable names.

Adds Person_attributes to customer controller
*/

public function person_attributes($customer_id = -1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 should be replaced with a constant. I think we use NEW_ENTRY for this



foreach($data['definition_values'] as $definition_id => $definition_value)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new code must be PSR compliant. All of this new code needs to be refactored with curly braces in the correct places.

Adds Person_attributes to customer controller
*/

public function person_attributes($customer_id = -1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function name does not describe what the function does. It should be renamed to correctly describe what the function does. If this is the corollary to getAttributes() in the Items controller then it should be renamed to getPersonAttributes()

foreach($data['definition_values'] as $definition_id => $definition_value)
{
$person_attribute_value = $this->Person_attribute->get_person_attribute_value($customer_id, $definition_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete one extra line here



$data['definition_names'] = $this->Person_attribute->get_definition_names();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the extra empty lines in this function. Generally variable definitions would have no blank lines between them and code blocks would have one blank line before/after.

$this->load->view('person_attributes/person', $data);
}

/*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is all old CI3 code, so all the conflicts need to be resolved in this branch before I review more.

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

Addressing Review Feedback

Thank you @objecttothis for the detailed architectural feedback. Let me address each point:

1. Database Indices on attribute_links

Good point. The current migration modifies the generated_unique_column but we should review all indices. I will analyze the query patterns and propose optimized indices.

2. Separate Views for Person vs Item Attributes

Agreed. I will add:

  • A person_attribute boolean column to attribute_definitions
  • Separate navigation/menu entries for Person Attributes and Item Attributes
  • Filter in Attributes::getSearch() to return only the appropriate type

3. person_attribute Column in attribute_definitions

This is cleaner than using visibility flags alone. I will add a migration to add this column.

Then business logic can filter:

  • Item attributes: WHERE person_attribute = 0
  • Person attributes: WHERE person_attribute = 1

4. Prevent Cross-Type Assignment

With the person_attribute column, we can enforce:

  • When saving item attributes, query only person_attribute = 0 definitions
  • When saving person attributes, query only person_attribute = 1 definitions
  • Add validation in model to reject mismatches

5. Attribute Type Parameter

I will use a bool parameter in the model methods to indicate attribute type.

6. Visibility for Person Type Restriction

The current visibility flags (SHOW_IN_CUSTOMERS, SHOW_IN_EMPLOYEES, SHOW_IN_SUPPLIERS) already handle this - an attribute with only SHOW_IN_EMPLOYEES will not appear in customer/supplier forms.

Proposed Next Steps

  1. Add person_attribute column migration
  2. Update Attribute model with type-filtering methods
  3. Split the Attributes manage view into Item Attributes and Person Attributes
  4. Review and optimize attribute_links indices
  5. Add validation to prevent cross-type assignment

Would you like me to proceed with these changes?

@jekkos

jekkos commented Apr 15, 2026

Copy link
Copy Markdown
Member

Addressing Review Feedback - Changes Applied

Based on @objecttothis feedback, I have made the following updates:

1. Added person_attribute Column

New migration: app/Database/Migrations/20260403000000_AddPersonAttributeFlag.php

  • Adds person_attribute TINYINT(1) DEFAULT 0 to ospos_attribute_definitions
  • Existing attributes default to 0 (item attributes)

2. Updated Attribute Model

  • Added person_attribute to $allowedFields
  • Added new method getDefinitionsByType(bool $isPersonAttribute, int $definitionFlags = 0)
  • This separates item attributes from person attributes in queries

3. Updated Persons Controller

  • Changed getPersonAttributes() to use getDefinitionsByType(true, $definitionFlags)
  • Now filters only person attributes (person_attribute = 1)

Files Added/Modified

new file:   app/Database/Migrations/20260403000000_AddPersonAttributeFlag.php
modified:   app/Models/Attribute.php
modified:   app/Controllers/Persons.php

Still TODO

Based on the review:

  1. Separate Attribute Views - Create distinct UI for Person Attributes vs Item Attributes
  2. Optimize Indices - Review and optimize attribute_links indices
  3. Validation - Add validation to prevent assigning person attributes to items and vice versa
  4. Attributes Controller - Update to handle the new person_attribute column in CRUD operations

Constants Summary

SHOW_IN_ITEMS = 1
SHOW_IN_SALES = 2
SHOW_IN_RECEIVINGS = 4
SHOW_IN_SEARCH = 8
SHOW_IN_CUSTOMERS = 16
SHOW_IN_EMPLOYEES = 32
SHOW_IN_SUPPLIERS = 64

Should I proceed with the remaining items (separate views, indices optimization, validation)?

@objecttothis

Copy link
Copy Markdown
Member

Addressing Review Feedback - Changes Applied

Based on @objecttothis feedback, I have made the following updates:

1. Added person_attribute Column

New migration: app/Database/Migrations/20260403000000_AddPersonAttributeFlag.php

* Adds `person_attribute` TINYINT(1) DEFAULT 0 to `ospos_attribute_definitions`

* Existing attributes default to 0 (item attributes)

2. Updated Attribute Model

* Added `person_attribute` to `$allowedFields`

* Added new method `getDefinitionsByType(bool $isPersonAttribute, int $definitionFlags = 0)`

* This separates item attributes from person attributes in queries

3. Updated Persons Controller

* Changed `getPersonAttributes()` to use `getDefinitionsByType(true, $definitionFlags)`

* Now filters only person attributes (person_attribute = 1)

Files Added/Modified

new file:   app/Database/Migrations/20260403000000_AddPersonAttributeFlag.php
modified:   app/Models/Attribute.php
modified:   app/Controllers/Persons.php

Still TODO

Based on the review:

1. **Separate Attribute Views** - Create distinct UI for Person Attributes vs Item Attributes

2. **Optimize Indices** - Review and optimize attribute_links indices

3. **Validation** - Add validation to prevent assigning person attributes to items and vice versa

4. **Attributes Controller** - Update to handle the new `person_attribute` column in CRUD operations

Constants Summary

SHOW_IN_ITEMS = 1
SHOW_IN_SALES = 2
SHOW_IN_RECEIVINGS = 4
SHOW_IN_SEARCH = 8
SHOW_IN_CUSTOMERS = 16
SHOW_IN_EMPLOYEES = 32
SHOW_IN_SUPPLIERS = 64

Should I proceed with the remaining items (separate views, indices optimization, validation)?

You need to resolve the branch conflicts before proceeding further.

@objecttothis

Copy link
Copy Markdown
Member

Constants Summary

SHOW_IN_ITEMS = 1
SHOW_IN_SALES = 2
SHOW_IN_RECEIVINGS = 4
SHOW_IN_SEARCH = 8
SHOW_IN_CUSTOMERS = 16
SHOW_IN_EMPLOYEES = 32
SHOW_IN_SUPPLIERS = 64

Using a tinyint as a bitmask will handle up to 8 flags and it only requires one column per row, but that's about it for the advantages. It's difficult to maintain the code and is not easily human readable. I recommend that we create a parent PR here to first migrate our current infrastructure for flags to a mapping table.

     CREATE TABLE `attribute_visibility` (
         `attribute_definition_id` INT NOT NULL,
         `scope` ENUM('item', 'sale', 'receiving', 'customer', 'employee', 'supplier', 'person_search', 'item_search') NOT NULL,
         PRIMARY KEY (`attribute_definition_id`, `scope`),
         FOREIGN KEY (`attribute_definition_id`) REFERENCES `attribute_definitions`(`definition_id`)
     );

A clean model for this can be created in code which will not only unclutter the attribute model, but will create better SRP adherence. A migration would need to be made to migrate existing flags, but that wouldn't take too much work to do.

jekkos pushed a commit that referenced this pull request Apr 20, 2026
- Add person_id column to attribute_links table for person attributes
- Add person_attribute column to attribute_definitions to distinguish item vs person attributes
- Add visibility flags: SHOW_IN_CUSTOMERS, SHOW_IN_EMPLOYEES, SHOW_IN_SUPPLIERS
- Add person attribute methods to Attribute model (getAttributesByPerson, savePersonAttributeLink, etc.)
- Refactor Persons controller with shared attribute handling (getPersonAttributes, savePersonAttributes)
- Update Customers, Employees, Suppliers controllers with PSR-12 naming and attribute integration
- Create attributes/person.php view for rendering person attributes
- Add person attributes container to customer/employee/supplier forms

Relates to #3161
@jekkos

jekkos commented Apr 20, 2026

Copy link
Copy Markdown
Member

This PR has been superseded by PR #4521 which contains a complete rework of the person attributes feature based on the latest master branch with the unified attribute system approach.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants