portal icon indicating copy to clipboard operation
portal copied to clipboard

AMC Projects Automatic Invoices

Open GauravGusain98 opened this issue 2 years ago • 26 comments

Feature Requested By @mohitsharma-22

Related Issue https://github.com/ColoredCow/portal/issues/2754

Is your feature request related to a problem? Please describe. In the portal, there are a few categories of projects like hourly billing, fixed budget, and AMC. Among these AMC projects are the projects where we are only responsible for the system maintenance and no new features or enhancement is covered in this.

The contract period for these AMC projects is of 1 year or more based on contract terms and the invoice for AMC projects usually goes quarterly i.e every 3 months.

Now we want to create a functionality that will be used to send invoices for AMC projects based on their billing frequency mentioned in the projects financial details page image

Additional context Once this is created, we will be able to send AMC invoices automatically from the portal, which will save a lot of time for the finance team.

Point of contact for guidance @GauravGusain98

GauravGusain98 avatar Jan 24 '23 04:01 GauravGusain98

Action items

Pre-requisites

  • [x] Run Seeders related to project module. This will create new client and project with hours added for team members Reference link
  • [x] Find the newly created project
  • [x] Open the client details corresponding to that project
  • [x] Add details related to client like country, service rate
  • [x] Set billing frequency to monthly
  • [x] Edit project
    • [x] Set billing level to Project level
    • [x] Billing type to monthly billing
  • [x] Now run this query in database
       INSERT INTO `settings` (`module`, `setting_key`, `setting_value`, `created_at`, `updated_at`) VALUES
    ('invoice', 'send_invoice_subject', '|*project_name*| Invoice |*term*| |*year*|', '2022-06-29 11:50:09', '2022-06-29 11:50:09'),
    ('invoice', 'send_invoice_body', '<div><span style=\"color: #202124; font-family: Roboto, sans-serif; white-space: pre-wrap;\">Hi </span>|*billing_person_name*|<span style=\"color: #202124; font-family: Roboto, sans-serif; white-space: pre-wrap;\">, </span><br /><span style=\"color: #202124; font-family: Roboto, sans-serif; white-space: pre-wrap;\"><br />I hope you are doing great. <br /><br />Sending you the invoice [|*invoice_number*|] for the projects for the period of |*term*| |*year*| and the total amount of this invoice is </span><strong>|*invoice_amount*|</strong><span style=\"color: #202124; font-family: Roboto, sans-serif; white-space: pre-wrap;\"> <br /><br />Please find an attached copy of the invoice. <br /><br />Thanks and Regards, <br />Test User</span></div>', '2022-06-29 11:50:09', '2022-06-29 11:50:09'),
    ('invoice', 'invoice_reminder_subject', '|*project_name*| Invoice - |*term*| |*year*|', '2022-07-05 14:22:44', '2022-07-06 19:52:18'),
    ('invoice', 'invoice_reminder_body', '<span style=\"font-size: 12pt; font-family: arial, helvetica, sans-serif;\"><span style=\"color: #202124; white-space: pre-wrap;\">Hi </span>|*billing_person_name*|<span style=\"color: #202124; white-space: pre-wrap;\">, </span></span><br /><span style=\"color: #202124; font-family: arial, helvetica, sans-serif; white-space: pre-wrap; font-size: 12pt;\"><br /><span style=\"color: #202124;\"><span style=\"white-space: pre-wrap;\">I hope you are doing great. </span></span><br /><br /><span style=\"color: #202124;\"><span style=\"white-space: pre-wrap;\"><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 12pt; white-space: pre-wrap;\">I’m sure you’ve already noticed, but I just thought to check with you on the last invoice. Not sure if you could get a chance to process it. <br /><br /></span></span><span style=\"color: #202124; font-family: arial, helvetica, sans-serif; font-size: 16px; white-space: pre-wrap;\">We simply wanted to drop in with a gentle check on it. Do let us know in case there’s anything we could help with or if you’d like to share. </span><br /><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 16px; white-space: pre-wrap;\"><br />The total amount of this invoice</span></span><span style=\"color: #202124; font-family: arial, helvetica, sans-serif; font-size: 16px; white-space: pre-wrap;\"> [|*invoice_number*|]</span><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 16px; white-space: pre-wrap;\"> is </span></span><span style=\"color: #202124; font-family: arial, helvetica, sans-serif; font-size: 16px; white-space: pre-wrap;\">|*invoice_amount*|</span><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 16px; white-space: pre-wrap;\">. Please find an attached copy of the invoice for your reference.</span></span><br /><br /><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 12pt; white-space: pre-wrap;\">Thanks and Regards, </span></span><br /><span style=\"color: #202124; font-family: arial, helvetica, sans-serif;\"><span style=\"font-size: 12pt; white-space: pre-wrap;\">Test User</span></span></span></span><br /></span>', '2022-07-05 14:22:44', '2022-07-29 11:14:59'),
    ('invoice', 'received_invoice_payment_subject', 'Payment Received:|*project_name*| Invoice - |*term*| |*year*|', '2022-07-05 14:26:10', '2022-07-14 23:32:54'),
    ('invoice', 'received_invoice_payment_body', '<span style=\"font-size: 12pt; font-family: arial, helvetica, sans-serif;\"><span style=\"color: #202124; white-space: pre-wrap;\">Hi </span>|*billing_person_name*|<span style=\"color: #202124; white-space: pre-wrap;\">, </span></span><br /><span style=\"font-family: arial, helvetica, sans-serif;\"><br /><span style=\"color: #202124;\"><span style=\"font-size: 16px; white-space: pre-wrap;\">I confirm we received the payment of |*currency*||*amount*| for the invoice [|*invoice_number*|]. <br /><br />Thank you very much. <br /><br />Thanks &amp; Regards, <br />Test User</span></span><br /></span>', '2022-07-05 14:26:10', '2022-08-03 01:48:52');
    

Basics Concept - 1 pointer

  • [x] Read about Models in Laravel. Share your understanding of why we use them in the task comment in your own language
  • [x] Read about Views in Laravel. Share your understanding of why we use them in the task comment in your own language
  • [x] Read about Routes in Laravel. Share your understanding of why we use them in the task comment in your own language
  • [x] Read about Controller in Laravel. Share your understanding of why we use them in the task comment in your own language
  • [x] Read about Services files in Laravel. Share your understanding of why we use them in the task comment in your own language
  • [x] Read how we can print a value in Laravel using dd()
  • [x] Try printing hello world using the dd function
  • [x] In the invoice page try printing any invoice details using the dd() function

Automatic Invoice workflow understanding - 1 pointer

  • [x] Check how an automatic invoice i.e ready-to-send invoice can be generated. Share the findings with @GauravGusain98 on the portal channel
  • [x] In the backend, find the function from which the data related to the client base and project-based invoices are coming. Share the detail in the comment
  • [x] From that data, filter out the AMC projects so that we don't receive the invoice data for those projects in frontend. You can test it by editing the project for which we have the ready-to-send invoices and setting it as AMC. Now the project invoice should not come in the ready-to-send invoice

List AMC projects invoice - 3 pointer

  • [x] Similar to the 2 groups (i.e Client Level and Project Level) in the ready-to-send invoices, now add another section with the name AMC projects as shown below image
  • [x] In the backend get the data related to the AMC invoice and print it on screen using dd(). It should print the AMC project-related invoice
  • [x] Pass the data to frontend and show it under the AMC project invoice

Data calculation for an invoice - 3 pointer

  • [x] Understand how the invoice details like amount, efforts, etc are getting calculated. Share your understanding with @GauravGusain98 in the comment.
  • [x] In the project Model, create a function that will calculate the next billing date of the invoice. Check if any such function already exists or not. If exist we need to update that function.
  • [x] The next billing date should be calculated using billing frequency and billing date. Currently, the billing date is taken from client_billing_details as the invoice for a client goes on the same date. The billing frequency can vary from project to project, so we use it to store the billing frequency at both project and client levels i.e in project_billing_details and client_billing_details tables. So if both are present then the priority should be given to project_billing_details data. now use this information to add functionality such that the next billing date can be calculated correctly. Note: In case of the quarterly invoice the next billing date should be calculated based on sent_on_date of previous invoice. i.e after 3 months of previous invoice month_
  • [x] For most AMC the rates are fixed, so the amount is also mentioned in the project_billing_details table.
  • [x] Show the data correctly on ready to send invoice page

GauravGusain98 avatar Jan 24 '23 13:01 GauravGusain98

step 1:- I have run php artisan module:seed image

rajatsajwan avatar Jan 27 '23 11:01 rajatsajwan

I have run php artisan module:seed

Also, find out how you can run seeder for a specific module instead of running it for every module. It will be helpful moving forward

GauravGusain98 avatar Jan 27 '23 11:01 GauravGusain98

Also did you understand the requirement? Any doubt on it for now?

GauravGusain98 avatar Jan 27 '23 11:01 GauravGusain98

what i understand : 1-create a functionality to send mail to client about invoice. 2- based on billing frequency. what is dont understand: 1-where it have to create?

rajatsajwan avatar Jan 27 '23 12:01 rajatsajwan

question : Also, find out how you can run seeder for a specific module instead of running it for every module. It will be helpful moving forward answer: php artisan module:seed module_name

rajatsajwan avatar Jan 27 '23 12:01 rajatsajwan

step 2- Find the newly created project i find project-76 image

rajatsajwan avatar Jan 27 '23 12:01 rajatsajwan

step 2- Find the newly created project i find project-76

The project should have booked hours

GauravGusain98 avatar Jan 27 '23 13:01 GauravGusain98

Step 2 >find newly project image

Step 3> open the client details (kade ltd) image

Step 4> add detail like country,service rate.

image Step 5> Set billing frequency to monthly image

Step 6> edit project 1-Set billing level to Project level 2-project type to monthly billing

image

rajatsajwan avatar Jan 27 '23 16:01 rajatsajwan

Step 7> I have inserted the query in DB

image

rajatsajwan avatar Jan 27 '23 17:01 rajatsajwan

Step8> modal is used to interact with database table.it define the relationships between different tables. Allows us to manipulate data.

Step9> View is used for displaying data to the user it is defined for structure & layout of user interface such as html , JS & css . Mostly views are store in resources/view folder.

Step10> Routes are used to defined URLs that a web application should response to. It map view page to the controller routes are of different type GET,POST,DELETE it also accept parameter & send it to controller.

rajatsajwan avatar Jan 28 '23 07:01 rajatsajwan

Step11> In controller there are classes used to handle http request & return response. Controller is responsible for user input , Calculations , interacting with database & return appropriate view of data. Most common task such as retrieving data from the database, validate user data & returning view. This file is typically store in http \ controller folder.

Step12> A service is file that that contain a specific piece of code\functionality Main purpose of making service is that to separate complex & repeated code from controller & made controller more readable, maintainable, easy to test as well as easier to reuse the service. It is also called service layer. It is stored in app \ service & can be used by multiple controllers.

rajatsajwan avatar Jan 28 '23 08:01 rajatsajwan

Step13> there are 2 way to print value 1> dd(dump & die) 2>dump In dd() it dump the value & stop further program executions. In dump() it dump the value which is in between the bracket() as shown in figure but further executions of code is not stoped.

Screenshot_20221229_113920

Example of display of dump value ->

image

Step 14> example of hello by using dd Screenshot_20230128_141412

rajatsajwan avatar Jan 28 '23 08:01 rajatsajwan

Step15>Step14> In invoice i print @dd($quarter); Screenshot_20230128_155125

output: Screenshot_20230128_155136

rajatsajwan avatar Jan 28 '23 10:01 rajatsajwan

Step16>

Automatic invoice can be generated by clicking Ready to send hyperlink. Then it go to route & trigger the index function in invoiceController Which return the view(invoice::index) & also trigger the invoiceService file Screenshot_20230130_151722

The invoice service file collect data of $client invoice data & project invoice data Screenshot_20230130_151733

& Return -Invoice -Clients -CurrencyService -TotalRecivableAmount -Filters -InvoiceStatus -clientsReadyToSendInvoicesData -projectsReadyToSendInvoicesData -sendInvoiceEmailSubject.[from setting.php file->setting table in DB] -sendInvoiceEmailBody. [from setting.php file->setting table in DB] -invoiceReminderEmailSubject. [from setting.php file->setting table in DB] -invoiceReminderEmailBody. [from setting.php file->setting table in DB]

rajatsajwan avatar Jan 30 '23 09:01 rajatsajwan

Step17> Data is coming from InvoiceService.php file The Function from which the data related to client base & project-base invoice are coming. Are 1-clientReadyToSendInvoicesData 2-projectsReadyToSendInvoicesData & these function are taking data from: 1- Client data is coming from client.php file from function ScopeInvoiceReadyToSend. 2- Project data is coming from project.php file from function ScopeInvoiceReadyToSend.

rajatsajwan avatar Jan 31 '23 07:01 rajatsajwan

Step18> I have filter out the non amc project from the projectsReadyToSendInvoicesData. By adding the quarry where(‘is_amc’, ’!=’, 1) now the Query look like this.

Screenshot_20230131_130427

rajatsajwan avatar Jan 31 '23 16:01 rajatsajwan

Step19> I have create similar group like Client level billing projects & Project level billing Project. image

rajatsajwan avatar Feb 02 '23 04:02 rajatsajwan

Step20 & Step21> image

rajatsajwan avatar Feb 02 '23 04:02 rajatsajwan

Step22> Amount details are coming from the functions which are in Module\Project\Entities\Project.php

getTotalLedgerAmount
getResorcesBillableAmount getTotalPayableAmountForTerm EffortSheet are coming from attribute of project.

rajatsajwan avatar Feb 02 '23 16:02 rajatsajwan

i was stuck in

image

In client_billing_details their Is billing_frequency In project_billing_detail there is no column of billing_frequency

image

rajatsajwan avatar Feb 02 '23 16:02 rajatsajwan

I think in project_billing_details there is no billing frequency. Its the service rate that we are storing. You need to store the details in service_rate column. The billing frequency will be decided from client_details only.

Suppose, if a project has service rate of 1000$/month but its billing_frequency is quarterly, then the invoice will go each quarter and the amount will be calculated as (service_rate * 3)

GauravGusain98 avatar Feb 03 '23 05:02 GauravGusain98

I have made a function which calculate total amount = service_rate * frequency image

result

image

rajatsajwan avatar Feb 03 '23 06:02 rajatsajwan

I have made a function which calculate total amount = service_rate * frequency image

result

image

The naming convention of functions and variables are not correct format

GauravGusain98 avatar Feb 06 '23 04:02 GauravGusain98

image

sir I use camalCase

rajatsajwan avatar Feb 06 '23 05:02 rajatsajwan

@deepakbarmola Can we please this one on priority. Let me know if there are any questions.

mohitsharma-22 avatar Dec 05 '23 08:12 mohitsharma-22