Skip to content

Feat/import office visit#1387

Merged
belwalshubham merged 1 commit intomainfrom
feat/import-office-visit
Aug 9, 2025
Merged

Feat/import office visit#1387
belwalshubham merged 1 commit intomainfrom
feat/import-office-visit

Conversation

@belwalshubham
Copy link
Copy Markdown
Collaborator

@belwalshubham belwalshubham commented Aug 9, 2025

Summary by CodeRabbit

  • New Features

    • Added new CLI tools for importing and processing collection camps, dropping centers, activities, vehicle dispatches, material contributions, and office visits from CSV files, with improved validation, matching, and error reporting.
    • Updated navigation menu restrictions for the 'project_ho_and_accounts' role to hide specific menus and submenus.
  • Bug Fixes

    • Updated the Goonj logo in generated receipts to use the correct production URL.
    • Improved element selection in the contribution form for hiding profile fields.
  • Refactor

    • Enhanced CLI import scripts for better data handling, modularity, and maintainability.
    • Improved contact and entity lookup logic across multiple scripts.
  • Chores

    • Disabled several automated email notification and receipt generation features by commenting out related code.
    • Disabled dynamic city dropdown injection in both admin and main site scripts.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 9, 2025

Caution

Review failed

Failed to post review comments.

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d118b7 and e222868.

⛔ Files ignored due to path filters (15)
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - Copy of conatct test 1 (1).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - Final Institution Import sheet.csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - conatct test (10).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - conatct test (3).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - final Individual Import sheet.csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (11).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (12).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (4).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (6).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (7).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - goonj activities contact (8).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - test (16).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - testing institution (4).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - testing institution (5).csv is excluded by !**/*.csv
  • wp-content/civi-extensions/goonjcustom/cli/Final data cleanups - testing institution (6).csv is excluded by !**/*.csv
📒 Files selected for processing (19)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (2 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionCollectionCampService.php (2 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionDroppingCenterService.php (2 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionMaterialContributionService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionReceiptGenerationService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/MaterialContributionService.php (2 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/NavigationPermissionService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/assign-initiator-dropping-center.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/assign-material-contribution-to-dropping-center-contacts.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/import-individual-collection-camp.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/import-individual-goonj-activities.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/import-institution-collection-camp.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/import-institution-goonj-activities.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/import-office-visit.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/cli/impotr-individual-dropping-center.php (1 hunks)
  • wp-content/themes/goonj-crm/admin-script.js (1 hunks)
  • wp-content/themes/goonj-crm/goonj-contribution.js (1 hunks)
  • wp-content/themes/goonj-crm/main.js (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2024-10-11T09:53:14.458Z
Learnt from: belwalshubham
PR: ColoredCow/goonj#284
File: wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php:520-520
Timestamp: 2024-10-11T09:53:14.458Z
Learning: In `wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php`, it's acceptable that the `reGenerateCollectionCampQr` method calls `generateQrCode` with only the `$collectionCampId` parameter, as QR codes are generated when the Dropping Center is authorized. We'll implement changes if any issues arise in the future.

Applied to files:

  • wp-content/civi-extensions/goonjcustom/Civi/CollectionBaseService.php
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionCollectionCampService.php
  • wp-content/civi-extensions/goonjcustom/Civi/NavigationPermissionService.php
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionReceiptGenerationService.php
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionMaterialContributionService.php
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionDroppingCenterService.php
  • wp-content/civi-extensions/goonjcustom/Civi/MaterialContributionService.php
  • wp-content/civi-extensions/goonjcustom/cli/impotr-individual-dropping-center.php
  • wp-content/civi-extensions/goonjcustom/cli/import-institution-collection-camp.php
  • wp-content/civi-extensions/goonjcustom/cli/import-individual-goonj-activities.php
  • wp-content/civi-extensions/goonjcustom/cli/assign-initiator-dropping-center.php
  • wp-content/civi-extensions/goonjcustom/cli/import-individual-collection-camp.php
  • wp-content/civi-extensions/goonjcustom/cli/import-institution-goonj-activities.php
  • wp-content/civi-extensions/goonjcustom/cli/assign-material-contribution-to-dropping-center-contacts.php
📚 Learning: 2024-10-13T01:00:56.008Z
Learnt from: belwalshubham
PR: ColoredCow/goonj#338
File: wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php:69-70
Timestamp: 2024-10-13T01:00:56.008Z
Learning: In `DroppingCenterService.php` (PHP, CiviCRM framework), when the `is_active` property remains constant (`1`) for all tabs in the `droppingCenterTabset` method, it's preferred to hardcode `is_active` in the loop instead of including it in the `$tabConfigs` array to reduce redundancy.

Applied to files:

  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionDroppingCenterService.php
📚 Learning: 2024-10-08T09:25:18.536Z
Learnt from: belwalshubham
PR: ColoredCow/goonj#284
File: wp-content/plugins/goonj-blocks/src/render.php:45-47
Timestamp: 2024-10-08T09:25:18.536Z
Learning: In the `wp-content/plugins/goonj-blocks/src/render.php` file, the team considers error handling for `DateTime` object creation unnecessary when using `$action_target['Dropping_Centre.Start_Time']` and `$action_target['Dropping_Centre.End_Time']`.

Applied to files:

  • wp-content/themes/goonj-crm/main.js
🪛 PHPMD (2.15.0)
wp-content/civi-extensions/goonjcustom/cli/impotr-individual-dropping-center.php

181-181: Avoid unused local variables such as '$results'. (Unused Code Rules)

(UnusedLocalVariable)

wp-content/civi-extensions/goonjcustom/cli/import-individual-goonj-activities.php

143-143: Avoid unused local variables such as '$results'. (Unused Code Rules)

(UnusedLocalVariable)

wp-content/civi-extensions/goonjcustom/cli/assign-initiator-dropping-center.php

144-144: Avoid unused local variables such as '$bags'. (Unused Code Rules)

(UnusedLocalVariable)

wp-content/civi-extensions/goonjcustom/cli/import-institution-goonj-activities.php

254-254: Avoid unused local variables such as '$createdRaw'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (6)
wp-content/civi-extensions/goonjcustom/Civi/InstitutionMaterialContributionService.php (1)

28-114: Do not remove these methods—they’re still referenced

The grep shows that the static methods in InstitutionMaterialContributionService are called elsewhere in the extension. Deleting them will break those call-sites:

  • wp-content/civi-extensions/goonjcustom/Civi/Traits/QrCodeable.php:193
    Calls InstitutionMaterialContributionService::generateContributionReceiptHtml(...)
  • wp-content/civi-extensions/goonjcustom/Civi/InstitutionReceiptGenerationService.php:269
    Calls prepareEmailParams(...)

If you intend to delete these “dead” methods, first update or remove their usages in the above files.

Likely an incorrect or invalid review comment.

wp-content/civi-extensions/goonjcustom/cli/import-office-visit.php (2)

225-231: Undefined index $COL['contact_id'] currently causes a notice and null resolution

Fix is to add the alias mapping as above. Without it, resolve_contact_id_from_csv() never gets used.

After adding the mapping, this lookup chain is sound.


274-282: Target contact likely should be the Office, not the same person; verify custom field assignment mode

  • For Office visits, common pattern is:
    • source_contact_id = the visitor (person)
    • target_contact_id = the office (organization)
  • Also, You_are_Visiting_as looks like an Option List; set by label to avoid numeric IDs.

Confirm your data model. If consistent with above, apply:

-        ->addValue('source_contact_id', $contactId)
-        ->addValue('target_contact_id', $contactId)
-        ->addValue(CF_OFFICE_FIELD, $officeId)
-        ->addValue(CF_VISITING_AS, 'Individual')
+        ->addValue('source_contact_id', $contactId)
+        ->addValue('target_contact_id', $officeId)  // office as target
+        ->addValue(CF_OFFICE_FIELD, $officeId)      // custom field holds office too
+        ->addValue(CF_VISITING_AS . ':label', 'Individual') // set by label
wp-content/civi-extensions/goonjcustom/cli/impotr-individual-dropping-center.php (1)

134-148: Fix stray quote, adjust state mapping, and normalize the opening‐date format

Please address the following in impotr-individual-dropping-center.php (lines 134–148):

• Remove the extra " at the start of the Dropping_Centre.District_City key so it maps correctly.
• Change the suffix on the state field to match what the API expects when you pass an ID—use 'Dropping_Centre.State' (or, if you’d rather pass the name, use ':label' and supply the state name).
• Convert the incoming DD/MM/YY(YY) string into YYYY-MM-DD before inserting, e.g.:

(
  $raw = $data['When do you wish to open center (Date) (DD/MM/YY)'] ?? ''
) && ($d = \DateTime::createFromFormat('d/m/Y', $raw) ?: \DateTime::createFromFormat('d/m/y', $raw))
  ? $d->format('Y-m-d')
  : ''

Suggested diff:

-      '"Dropping_Centre.District_City' => $data['City'] ?? '',
-      'Dropping_Centre.State:name'     => get_state_id($data['State'] ?? ''),
-      'Dropping_Centre.When_do_you_wish_to_open_center_Date_' 
-                                       => $data['When do you wish to open center (Date) (DD/MM/YY)'] ?? '',
+      'Dropping_Centre.District_City' => $data['City'] ?? '',
+      'Dropping_Centre.State'         => get_state_id($data['State'] ?? ''),  // or ':label' with name
+      'Dropping_Centre.When_do_you_wish_to_open_center_Date_' 
+                                       => (
+      ($raw = $data['When do you wish to open center (Date) (DD/MM/YY)'] ?? '')
+      && ($d = \DateTime::createFromFormat('d/m/Y', $raw)
+        ?: \DateTime::createFromFormat('d/m/y', $raw))
+      ) ? $d->format('Y-m-d') : '',

Before merging, please verify:

  • Is When_do_you_wish_to_open_center_Date_ defined as a DATE or DATETIME in CiviCRM (i.e. do we need YYYY-MM-DD vs YYYY-MM-DD HH:MM:SS)?
  • Does the custom “State” field accept the option‐value ID or the label?
wp-content/civi-extensions/goonjcustom/cli/import-institution-goonj-activities.php (1)

350-357: Target contact for activity: confirm business rule

Target is set to organization. Verify whether target should be the initiator (person), organization, or both (multiple targets). Adjust if needed.

wp-content/civi-extensions/goonjcustom/cli/assign-material-contribution-to-dropping-center-contacts.php (1)

92-127: Contact lookup logic LGTM (consistent with other scripts)

Preferred matching by first+email then first+mobile, with logging. Reusable and readable.

Walkthrough

This pull request introduces and refactors several CLI scripts for importing and processing various CRM-related data from CSV files, disables multiple email notification and receipt generation services by commenting out their code, adjusts role-based access control and navigation menu visibility for the 'project_ho_and_accounts' role, and disables dynamic city dropdown injection in the UI by commenting out related JavaScript. Minor selector improvements and a logo URL update are also included.

Changes

Cohort / File(s) Change Summary
Access Control & Navigation Role Updates
.../Civi/CollectionBaseService.php, .../Civi/NavigationPermissionService.php
Added 'project_ho_and_accounts' to restricted roles for ACL and to navigation menu hiding rules.
Disable Email Notification & Receipt Services
.../Civi/DroppingCenterService.php, .../Civi/InstitutionCollectionCampService.php, .../Civi/InstitutionDroppingCenterService.php, .../Civi/InstitutionMaterialContributionService.php, .../Civi/MaterialContributionService.php
Commented out event subscriptions and implementations for email notification and receipt generation services, disabling their functionality.
Logo URL Update
.../Civi/InstitutionReceiptGenerationService.php
Updated Goonj logo image URL in receipt HTML generation.
Disable City Dropdown Injection
.../admin-script.js, .../main.js
Commented out all code related to dynamic city dropdown injection in forms, disabling the feature.
Minor JS Selector Fix
.../goonj-contribution.js
Removed duplicate variable declaration and improved selector specificity for hiding a profile div.
New & Refactored CLI Import Scripts
.../cli/assign-initiator-dropping-center.php, .../cli/assign-material-contribution-to-dropping-center-contacts.php, .../cli/import-individual-collection-camp.php, .../cli/import-individual-goonj-activities.php, .../cli/import-institution-collection-camp.php, .../cli/import-institution-goonj-activities.php, .../cli/import-office-visit.php, .../cli/impotr-individual-dropping-center.php
Added or extensively refactored CLI PHP scripts for importing and processing CRM data from CSVs, with improved validation, error handling, and entity creation logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI Script
    participant CSV File
    participant CiviCRM API

    User->>CLI Script: Run import script (with CSV path)
    CLI Script->>CSV File: Read and parse rows
    loop For each valid row
        CLI Script->>CiviCRM API: Lookup/resolve related entities (contacts, offices, etc.)
        CLI Script->>CiviCRM API: Create/update entity (e.g., Collection Camp, Activity)
        CiviCRM API-->>CLI Script: Return success/failure
        CLI Script->>User: Log result (created/skipped/error)
    end
    CLI Script->>User: Print summary
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90 minutes

Possibly related PRs

Suggested labels

status : ready for review

Suggested reviewers

  • tarunnjoshi

Poem

🚚 Scripts awaken, data flows anew,
Roles are adjusted, permissions in view.
Emails go silent, receipts take a rest,
Dropdowns are dormant, city fields unpressed.
With code refactored, importers in line—
Reviewers, your wisdom will help this code shine!

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/import-office-visit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@belwalshubham belwalshubham changed the base branch from dev to main August 9, 2025 07:59
@belwalshubham belwalshubham self-assigned this Aug 9, 2025
@belwalshubham belwalshubham merged commit cd014bc into main Aug 9, 2025
1 check was pending
@belwalshubham belwalshubham deleted the feat/import-office-visit branch August 9, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant