Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Prospect Updates #3748

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

[Feat]: Prospect Updates #3748

wants to merge 3 commits into from

Conversation

Ayush8923
Copy link
Member

@Ayush8923 Ayush8923 commented Nov 24, 2024

Targets: #3745

Changes

  • Fixed the issue with the amount formatting, ensuring proper handling for small numbers without breaking the current format.

Summary by CodeRabbit

  • New Features

    • Updated budget formatting to align with Indian currency standards across various views.
    • Enhanced organization name display logic to prioritize project names.
  • Bug Fixes

    • Corrected method references for budget formatting in the prospects table and details view.

Copy link

coderabbitai bot commented Nov 24, 2024

Walkthrough

The changes in this pull request involve modifications to the Prospect class and its associated views to update the currency formatting method from formattedAmount to formattedIndianAmount. The method's internal logic has been adjusted to accommodate Indian currency formatting standards, particularly by introducing a conditional check based on the length of the amount string. Corresponding updates have been made in the Blade template files to ensure that the budget amounts are displayed using the new formatting method.

Changes

File Path Change Summary
Modules/Prospect/Entities/Prospect.php Renamed method formattedAmount to formattedIndianAmount and updated internal logic.
Modules/Prospect/Resources/views/index.blade.php Updated budget display to use formattedIndianAmount.
Modules/Prospect/Resources/views/subviews/prospect-details.blade.php Changed budget formatting method from formattedAmount to formattedIndianAmount.

Possibly related PRs

  • [Feat]:- Prospect Insights Section #3739: The changes in this PR involve updating the method used to format budget amounts from formattedAmount to formattedIndianAmount, which directly relates to the changes made in the main PR regarding the renaming and logic modification of the formattedAmount method in the Prospect class.
  • [Hotfix]:- Remove the Mandatory Field #3740: This PR includes modifications to the index.blade.php file, which also updates the logic for displaying the budget, ensuring that the new formattedIndianAmount method is utilized, thus connecting it to the changes in the main PR.
  • [Fix]:- Remove the Mandatory Field  #3742: This PR modifies the ProspectRequest to allow certain fields to be nullable, which indirectly relates to the overall handling of prospect data, including budget fields that are formatted using the updated method in the main PR.

Suggested labels

status : ready for review

Suggested reviewers

  • GauravGusain98
  • pankaj-ag

Poem

In the land of prospects, bright and grand,
Amounts now formatted by a careful hand.
From formattedAmount to formattedIndianAmount,
The budget shines true, no need to recount!
With commas and rupees, all neatly in line,
Our code now dances, oh how divine! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ad85c41 and 2eea75a.

📒 Files selected for processing (1)
  • Modules/Prospect/Resources/views/index.blade.php (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Modules/Prospect/Resources/views/index.blade.php

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

@Ayush8923 Ayush8923 self-assigned this Nov 24, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
Modules/Prospect/Entities/Prospect.php (1)

Line range hint 41-52: Consider extracting the formatting logic into a service class.

The current implementation mixes currency formatting logic with the model class, which violates the Single Responsibility Principle. Consider:

  1. Moving this to a dedicated CurrencyFormatter service
  2. Making the format configurable (Indian, International, etc.)
  3. Adding unit tests for various edge cases

Would you like me to help create a separate service class for currency formatting?

Modules/Prospect/Resources/views/index.blade.php (1)

71-73: Consider improving the currency display implementation.

The current implementation separates the currency symbol and the formatted amount into different spans, which could lead to layout issues (unwanted spaces or line breaks). Consider combining them into a single formatted string.

-                                    {{ isset($prospect->currency) && isset($currencySymbols[$prospect->currency]) ? $currencySymbols[$prospect->currency] : '' }}
-                                    {{ $prospect->budget ? $prospect->formattedIndianAmount($prospect->budget) : '-' }}
+                                    @if($prospect->budget)
+                                        {{ ($prospect->currency && isset($currencySymbols[$prospect->currency]) ? $currencySymbols[$prospect->currency] : '') . $prospect->formattedIndianAmount($prospect->budget) }}
+                                    @else
+                                        -
+                                    @endif
Modules/Prospect/Resources/views/subviews/prospect-details.blade.php (1)

59-62: Consider extracting currency formatting logic

The currency display logic is split across multiple lines, mixing currency symbol lookup with amount formatting. Consider extracting this into a dedicated helper method for better maintainability.

- {{ isset($prospect->currency) && isset($currencySymbols[$prospect->currency]) ? $currencySymbols[$prospect->currency] : '' }}
- {{ $prospect->budget ? $prospect->formattedIndianAmount($prospect->budget) : 'N/A' }}
+ {{ $prospect->getFormattedBudgetWithCurrency() ?? 'N/A' }}

This would encapsulate both the currency symbol and amount formatting in a single method, making the template cleaner and the logic more reusable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bbb4f07 and 62d50d9.

📒 Files selected for processing (3)
  • Modules/Prospect/Entities/Prospect.php (1 hunks)
  • Modules/Prospect/Resources/views/index.blade.php (1 hunks)
  • Modules/Prospect/Resources/views/subviews/prospect-details.blade.php (1 hunks)
🔇 Additional comments (2)
Modules/Prospect/Entities/Prospect.php (1)

41-42: Verify the impact of method renaming across the codebase.

The method has been renamed from formattedAmount to formattedIndianAmount, which better reflects its specific purpose. However, we should ensure all calling code has been updated.

✅ Verification successful

All method references have been properly updated

The codebase scan shows that:

  • The old method name formattedAmount only appears within the implementation of formattedIndianAmount as a variable name
  • The new method name formattedIndianAmount is correctly used in two view files:
    • Modules/Prospect/Resources/views/index.blade.php
    • Modules/Prospect/Resources/views/subviews/prospect-details.blade.php
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining calls to the old method name
rg "formattedAmount" --type php

# Search for calls to the new method name to verify updates
rg "formattedIndianAmount" --type php

Length of output: 715

Modules/Prospect/Resources/views/index.blade.php (1)

72-72: Verify consistent usage of the new formatting method across all views.

The change from formattedAmount to formattedIndianAmount needs to be consistently applied across all views to maintain uniform formatting.

✅ Verification successful

The change to formattedIndianAmount appears to be consistently applied

The verification shows that:

  • No instances of the old formattedAmount method were found in the relevant modules
  • The new formattedIndianAmount method is consistently used in both places where prospect budget is displayed:
    • Modules/Prospect/Resources/views/index.blade.php
    • Modules/Prospect/Resources/views/subviews/prospect-details.blade.php
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of the old formatting method
rg "formattedAmount" --type blade

# Search for the new formatting method to ensure consistent adoption
rg "formattedIndianAmount" --type blade

Length of output: 133


Script:

#!/bin/bash
# Search for any remaining instances of the old formatting method in blade files
rg "formattedAmount" "*.blade.php"

# Search for the new formatting method to ensure consistent adoption
rg "formattedIndianAmount" "*.blade.php"

# Find all blade files in the repository to ensure we're not missing any
fd ".blade.php$"

Length of output: 23287


Script:

#!/bin/bash
# Search for any remaining instances of the old formatting method in the specific directories
rg "formattedAmount" Modules/Prospect/Resources/views/
rg "formattedAmount" Modules/Invoice/Resources/views/
rg "formattedAmount" Modules/Client/Resources/views/

# Search for the new formatting method to ensure consistent adoption
rg "formattedIndianAmount" Modules/Prospect/Resources/views/
rg "formattedIndianAmount" Modules/Invoice/Resources/views/
rg "formattedIndianAmount" Modules/Client/Resources/views/

Length of output: 689

Comment on lines +43 to +47
$amount = (string) $amount;

if (strlen($amount) <= 3) {
return $amount;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding input validation and documentation.

The new length check logic needs input validation and documentation:

  1. The type cast to string assumes the input is numeric
  2. The purpose of the length check (≤3) should be documented
  3. Consider handling negative numbers and decimals
     public function formattedIndianAmount($amount)
     {
+        // Return early if amount is null or empty
+        if ($amount === null || $amount === '') {
+            return '0';
+        }
+
+        // Handle negative numbers
+        $isNegative = $amount < 0;
+        $amount = abs($amount);
+
         $amount = (string) $amount;
 
         if (strlen($amount) <= 3) {
-            return $amount;
+            return $isNegative ? "-{$amount}" : $amount;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$amount = (string) $amount;
if (strlen($amount) <= 3) {
return $amount;
}
// Return early if amount is null or empty
if ($amount === null || $amount === '') {
return '0';
}
// Handle negative numbers
$isNegative = $amount < 0;
$amount = abs($amount);
$amount = (string) $amount;
if (strlen($amount) <= 3) {
return $isNegative ? "-{$amount}" : $amount;
}

@@ -69,7 +69,7 @@
<td class="w-30p">
<span>
{{ isset($prospect->currency) && isset($currencySymbols[$prospect->currency]) ? $currencySymbols[$prospect->currency] : '' }}
{{ $prospect->budget ? $prospect->formattedAmount($prospect->budget) : '-' }}
{{ $prospect->budget ? $prospect->formattedIndianAmount($prospect->budget) : '-' }}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add fallback formatting for error handling.

The code directly calls formattedIndianAmount without any error handling. Consider adding a try-catch block or helper method to handle potential formatting errors gracefully.

-                                    {{ $prospect->budget ? $prospect->formattedIndianAmount($prospect->budget) : '-' }}
+                                    {{ $prospect->budget ? ($prospect->tryFormatAmount($prospect->budget) ?? '-') : '-' }}

Consider adding this helper method to the Prospect model:

public function tryFormatAmount($amount) {
    try {
        return $this->formattedIndianAmount($amount);
    } catch (\Exception $e) {
        \Log::error('Amount formatting failed: ' . $e->getMessage());
        return null;
    }
}

@@ -58,7 +58,7 @@ class="ml-2">{{ config('prospect.customer-types')[$prospect->customer_type] ?? '
<label for="budget" class="font-weight-bold">Budget:</label>
<span class="ml-2">
{{ isset($prospect->currency) && isset($currencySymbols[$prospect->currency]) ? $currencySymbols[$prospect->currency] : '' }}
{{ $prospect->budget ? $prospect->formattedAmount($prospect->budget) : 'N/A' }}
{{ $prospect->budget ? $prospect->formattedIndianAmount($prospect->budget) : 'N/A' }}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Method exists but needs attention to potential issues

The formattedIndianAmount method exists in the Prospect model, but there are a few concerns:

  • The method is being used in the view but appears to be missing proper documentation
  • The implementation shows it's a public method that could be reused across the application, suggesting it might be better placed in a dedicated formatting trait or helper class
  • The method name implies Indian-specific formatting, but the implementation is tightly coupled to the Prospect model
🔗 Analysis chain

Verify the existence of formattedIndianAmount method

The change from formattedAmount to formattedIndianAmount looks good, but let's verify that this method exists in the Prospect model.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of formattedIndianAmount method in Prospect model
# and check for consistent usage across the codebase

# Check if the method exists in the Prospect model
ast-grep --pattern 'function formattedIndianAmount' Modules/Prospect/Entities/Prospect.php

# Check for any remaining uses of the old method
rg "formattedAmount" --type php

Length of output: 332


Script:

#!/bin/bash
# Let's check the actual implementation in the Prospect model
rg -A 10 "function.*Amount" Modules/Prospect/Entities/Prospect.php

Length of output: 382

Copy link

cypress bot commented Nov 24, 2024

Employee portal    Run #8923

Run Properties:  status check passed Passed #8923  •  git commit e83da383c0 ℹ️: Merge 2eea75a429faadee7446a7d2b95f7082d7f0c0f5 into bbb4f07f46e8c5038e8ba37ca087...
Project Employee portal
Branch Review refs/pull/3748/merge
Run status status check passed Passed #8923
Run duration 00m 26s
Commit git commit e83da383c0 ℹ️: Merge 2eea75a429faadee7446a7d2b95f7082d7f0c0f5 into bbb4f07f46e8c5038e8ba37ca087...
Committer Ayush
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Nov 24, 2024

Coverage report for commit: 2eea75a
File: coverage.xml

Cover ┌─────────────────────────┐ Freq.
   0% │ ███████████████████████ │ 80.7%
  10% │ █░░░░░░░░░░░░░░░░░░░░░░ │  1.8%
  20% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  30% │ █░░░░░░░░░░░░░░░░░░░░░░ │  0.9%
  40% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  50% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  60% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  70% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  80% │ █░░░░░░░░░░░░░░░░░░░░░░ │  0.9%
  90% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
 100% │ █████░░░░░░░░░░░░░░░░░░ │ 15.8%
      └─────────────────────────┘
 *Legend:* █ = Current Distribution 
Summary - Lines: 3.16% | Methods: 5.43%
FilesLinesMethodsBranches
app/Casts
   Decrypted.php--100.00%
app/Console/Commands
   CheckCommand.php--100.00%
   FakeProdDataCommand.php2.22%12.50%100.00%
   Setup.php--100.00%
app/Console
   Kernel.php9.52%50.00%100.00%
app/Exceptions
   Handler.php75.00%-100.00%
app/Helpers
   ContentHelper.php--100.00%
   DateHelper.php--100.00%
   DecimalToWordsHelper.php--100.00%
   FileHelper.php--100.00%
app/Http/Controllers/Auth
   ForgotPasswordController.php--100.00%
   LoginController.php--100.00%
   RegisterController.php--100.00%
   ResetPasswordController.php--100.00%
app/Http/Controllers
   ClientController.php--100.00%
   CommentController.php--100.00%
   Controller.php100.00%100.00%100.00%
   HomeController.php26.47%50.00%100.00%
   ProjectController.php--100.00%
   ProjectStageController.php--100.00%
   UserBookController.php--100.00%
   UserController.php--100.00%
app/Http/Controllers/Finance
   InvoiceController.php--100.00%
   PaymentController.php--100.00%
   ReportsController.php--100.00%
app/Http/Controllers/HR/Applications
   VolunteerApplicationController.php--100.00%
app/Http/Controllers/HR/Volunteers
   CampaignsController.php--100.00%
   ReportsController.php--100.00%
   VolunteerOpportunityController.php--100.00%
app/Http/Controllers/KnowledgeCafe
   KnowledgeCafeController.php--100.00%
   WeeklyDoseController.php--100.00%
app/Http/Controllers/KnowledgeCafe/Library
   BookCategoryController.php--100.00%
   BookCommentController.php--100.00%
   BookController.php--100.00%
app/Http/Controllers/Settings
   BankDetailController.php--100.00%
   ConfigurationController.php--100.00%
   HRController.php--100.00%
   NDAAgreementController.php--100.00%
   PermissionController.php--100.00%
   SettingController.php--100.00%
app/Http
   Kernel.php100.00%100.00%100.00%
app/Http/Middleware
   EncryptCookies.php100.00%100.00%100.00%
   RedirectIfAuthenticated.php--100.00%
   TrimStrings.php100.00%100.00%100.00%
   TrustProxies.php100.00%100.00%100.00%
   VerifyCsrfToken.php100.00%100.00%100.00%
app/Http/Requests
   ClientRequest.php--100.00%
   ProjectRequest.php--100.00%
   ProjectStageRequest.php--100.00%
app/Http/Requests/Finance
   InvoiceRequest.php--100.00%
   PaymentRequest.php--100.00%
app/Http/Requests/KnowledgeCafe/Library
   BookCategoryRequest.php--100.00%
   BookRequest.php--100.00%
app/Http/Requests/KnowledgeCafe
   WeeklyDoseRequest.php--100.00%
app/Http/Requests/Setting
   SettingRequest.php--100.00%
   UpdateRolePermissionsRequest.php--100.00%
   UpdateUserRolesRequest.php--100.00%
app/Http/View/Composers
   CodeTrekApplicantsComposer.php100.00%100.00%100.00%
app/Imports
   ApplicationImport.php--100.00%
app/Listeners
   RemoveUserFromWebsite.php--100.00%
app/Mail
   DailyEffortSummary.php--100.00%
   ErrorReport.php--100.00%
   sendEmail.php--100.00%
app/Models
   BankDetails.php100.00%100.00%100.00%
   Category.php--100.00%
   Client.php--100.00%
   Comment.php--100.00%
   Country.php100.00%100.00%100.00%
   Project.php--100.00%
   ProjectStage.php--100.00%
   ProjectStageBilling.php--100.00%
   Resource.php--100.00%
   Setting.php--100.00%
   SkillSet.php100.00%100.00%100.00%
   Tag.php--100.00%
app/Models/Finance
   Invoice.php--100.00%
   Payment.php--100.00%
app/Models/Finance/PaymentModes
   Cash.php--100.00%
   Cheque.php--100.00%
   WireTransfer.php--100.00%
app/Models/KnowledgeCafe/Library
   Book.php13.79%13.64%100.00%
   BookAMonth.php--100.00%
   BookCategory.php--100.00%
app/Models/KnowledgeCafe
   WeeklyDose.php100.00%100.00%100.00%
app/Notifications
   ReviewNDA.php--100.00%
app/Observers
   UserObserver.php100.00%100.00%100.00%
app/Policies
   ClientPolicy.php--100.00%
   ProjectPolicy.php--100.00%
   SettingPolicy.php--100.00%
   UserPolicy.php--100.00%
app/Policies/Finance
   InvoicePolicy.php--100.00%
   ReportPolicy.php--100.00%
app/Policies/Infrastructure
   BillingsPolicy.php--100.00%
app/Policies/KnowledgeCafe/Library
   BookCategoryPolicy.php--100.00%
   BookPolicy.php--100.00%
app/Policies/KnowledgeCafe
   WeeklyDosePolicy.php--100.00%
app/Providers
   AppServiceProvider.php100.00%100.00%100.00%
   ApplicantsComposerServiceProvider.php100.00%100.00%100.00%
   AuthServiceProvider.php100.00%100.00%100.00%
   BroadcastServiceProvider.php--100.00%
   DatabaseServiceProvider.php100.00%100.00%100.00%
   EventServiceProvider.php100.00%100.00%100.00%
   RouteServiceProvider.php100.00%100.00%100.00%
app/Rules
   TeamMemberDesignationRule.php--100.00%
   TeamMemberRule.php--100.00%
app/Services
   BookServices.php--100.00%
   CalendarEventService.php--100.00%
   EmployeeService.php--100.00%
   GSuiteUserService.php--100.00%
   SettingService.php--100.00%
   WebsiteUserService.php--100.00%
app/Traits
   Encryptable.php--100.00%
   Filters.php--100.00%
   HasTags.php--100.00%

🤖 comment via lucassabreu/comment-coverage-clover

@Ayush8923 Ayush8923 added the status : ready for review Items that are ready for code review label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status : ready for review Items that are ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant