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

The variable $client->payment_balance is not showing the correct amount. #9421

Closed
CarrnellTech opened this issue Apr 2, 2024 · 7 comments
Closed

Comments

@CarrnellTech
Copy link

CarrnellTech commented Apr 2, 2024

Setup

v5.8.39-W156
Docker

Interface

  • Flutter: []
  • React: []
  • Both: [X]

Checklist

  • Can you replicate the issue on our v5 demo site https://demo.invoiceninja.com or https://react.invoicing.co/demo?
    • No
  • Have you searched existing issues?
    • Yes, no results.
  • Have you reported this to Slack/forum before posting?
    • No
  • Have you inspected the logs in storage/logs/laravel.log for any errors?
    • No, I don't believe this would output an error.

Describe the bug

I have placed the custom code of $client->payment_balance in v5-develop/resources/views/portal/ninja2020/dashboard/index.blade.php and everything works perfectly.

Except on one of my clients it shows an incorrect balance. It is supposed to read as $23.24 but is instead showing $63.68. I suspect it is not subtracting one of the $40.44 invoices. The April 1st invoice did automatically use some of the available unapplied payment via recurring invoice creation, perhaps there is a bug there?

(Additional side note, I had a client that had $0.01 in unapplied payment, but, it did not use it automatically. so something weird is happening there. Let me know if I need to make this a different bug report.)

The client has 4 payments for their entire history as follows:

  • $100 (Partially Unapplied) (Applied $76.76)
    • Inv $36.32
    • Inv $40.44 (Apr 1)
  • $40 (Completed)
    • Inv $35.88
    • Inv $4.12
  • $45 (Completed)
    • Inv $40.44
    • Inv $4.56
  • $45 (Deleted) (Applied $44.89)

Steps To Reproduce

Not sure how to reproduce. I have put {{ App\Utils\Number::formatMoney($client->payment_balance, $client) }} somewhere in the dashboard page to get the variable's output as expected.

May need to trigger the automatic use of unapplied payments.

Expected Behavior

Return the payment balance of the client that has not been used yet.

Screenshots

image
image

@turbo124
Copy link
Member

turbo124 commented Apr 2, 2024

the payment_balance column is delayed in its value. ie. if you perform a payment action, it may take 5 minutes for the payment_balance to update. could this explain it?

@CarrnellTech
Copy link
Author

CarrnellTech commented Apr 2, 2024

I believe the payment was applied yesterday. So that exceeds 5 minutes. If it is delayed, perhaps I jumped the gun a bit and it will fix itself tonight?

Also, when you said column that made me wonder if this can also be seen in the client list. And yes it is also seen there! A much easier way to see the value output without editing the code.
image

Additional picture of the payment applied to automatically created invoice.
image

@turbo124
Copy link
Member

turbo124 commented Apr 3, 2024

Do you have the cron scheduler running? There is a scheduled task which updates this field every 5 minutes.

@CarrnellTech
Copy link
Author

CarrnellTech commented Apr 4, 2024

I am running the application in a docker container. I have not changed anything other than some small html/php snippets.


Here is the crontab on my docker container:
/var/www/app> cat /etc/crontabs/root 
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
*/15    *       *       *       *       run-parts /etc/periodic/15min
0       *       *       *       *       run-parts /etc/periodic/hourly
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly

Here is a capture of my recent logs
  2024-04-04 20:20:00 Running [queue-size-job] ..................... 17ms DONE
  2024-04-04 20:20:00 Running [Callback] ............................ 7ms DONE
  2024-04-04 20:20:02 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:20:02 App\Jobs\Ninja\QueueSize ................... 3.20ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
[REDACTED] -  04/Apr/2024:20:23:14 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:23:15 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:23:15 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:23:15 +0000 "GET /index.php" 200
   INFO  No scheduled commands are ready to run.  
  2024-04-04 20:25:00 Running [queue-size-job] ..................... 16ms DONE
  2024-04-04 20:25:00 Running [Callback] ............................ 7ms DONE
  2024-04-04 20:25:02 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:25:02 App\Jobs\Ninja\QueueSize ................... 3.48ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
[REDACTED] -  04/Apr/2024:20:28:39 +0000 "POST /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:40 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:40 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:40 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:44 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:44 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:46 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:46 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
[REDACTED] -  04/Apr/2024:20:28:47 +0000 "GET /index.php" 200
   INFO  No scheduled commands are ready to run.  
  2024-04-04 20:30:00 Running [queue-size-job] ..................... 21ms DONE
  2024-04-04 20:30:00 Running [stale-invoice-job] ................... 3ms DONE
  2024-04-04 20:30:00 Running [Callback] ............................ 8ms DONE
  2024-04-04 20:30:02 App\Jobs\Subscription\CleanStaleInvoiceOrder ... RUNNING
  2024-04-04 20:30:02 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:30:02 App\Jobs\Ninja\QueueSize ................... 6.73ms DONE
  2024-04-04 20:30:02 App\Jobs\Subscription\CleanStaleInvoiceOrder  18.24ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
  2024-04-04 20:35:00 Running [queue-size-job] ..................... 17ms DONE
  2024-04-04 20:35:00 Running [Callback] ............................ 6ms DONE
  2024-04-04 20:35:03 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:35:03 App\Jobs\Ninja\QueueSize ................... 4.28ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
  2024-04-04 20:40:00 Running [queue-size-job] ..................... 33ms DONE
  2024-04-04 20:40:00 Running [update-calculated-fields-job] ....... 12ms DONE
  2024-04-04 20:40:00 Running [Callback] ............................ 7ms DONE
  2024-04-04 20:40:03 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:40:03 App\Jobs\Ninja\QueueSize ................... 5.32ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
  2024-04-04 20:45:00 Running [queue-size-job] ..................... 14ms DONE
  2024-04-04 20:45:00 Running [Callback] ............................ 6ms DONE
  2024-04-04 20:45:03 App\Jobs\Ninja\QueueSize ....................... RUNNING
  2024-04-04 20:45:03 App\Jobs\Ninja\QueueSize ................... 5.94ms DONE
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  
   INFO  No scheduled commands are ready to run.  

Just for some added contexts, I pull the latest docker image, override the original entry point script add extra commands to change the html/php snippets, then immediately call the original entrypoint script while leaving the original calling parameters in place. (I have been wanting to get into building docker images without that entrypoint override, but have not had the time to fully do that properly yet.) This is purely to make cosmetic changes for our specific use case.

@CarrnellTech
Copy link
Author

I thought to also get the daemon controller Supervisord and currently running processes if that helps.


Supervisord.conf on my docker container during production:
[supervisord]
nodaemon=true
pidfile=/tmp/supervisord.pid
logfile=/dev/null ; nodaemon will cause logs to go to stdout
logfile_maxbytes=0
loglevel=info

[program:php-fpm]
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php-fpm

[program:scheduler]
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php artisan schedule:work

[program:queue-worker]
process_name=%(program_name)s_%(process_num)02d
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
numprocs=2
command=php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600

[eventlistener:shutdown]
command=shutdown.sh
events=PROCESS_STATE_STOPPED, PROCESS_STATE_EXITED, PROCESS_STATE_FATAL
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

Top on my docker container during production:
Mem: 7855196K used, 280692K free, 97776K shrd, 248052K buff, 1261424K cached
CPU:  57% usr   3% sys   0% nic  39% idle   0% io   0% irq   0% sirq
Load average: 0.21 0.20 0.21 4/888 202
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   69    65 invoicen S     181m   2%   1   0% php-fpm: pool www
   70    65 invoicen S     179m   2%   0   0% php-fpm: pool www
   65    13 invoicen S     178m   2%   0   0% php-fpm: master process (/usr/local/etc/php-fpm.conf)
   66    13 invoicen S     103m   1%   1   0% php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600
   67    13 invoicen S     103m   1%   0   0% php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600
   68    13 invoicen S     101m   1%   0   0% php artisan schedule:work
   13     1 invoicen S    28232   0%   0   0% {supervisord} /usr/bin/python3 /usr/bin/supervisord
  148     0 root     S     1700   0%   2   0% sh
    1     0 invoicen S     1632   0%   0   0% sh /usr/local/bin/prepend_entrypoint.sh supervisord
   64    13 invoicen S     1628   0%   0   0% {shutdown.sh} /bin/sh /usr/local/bin/shutdown.sh
  202   148 root     R     1624   0%   0   0% top

@CarrnellTech
Copy link
Author

I have updated the docker container to v5.8.47-W156 and it has not changed the issue.
image

@CarrnellTech
Copy link
Author

I have opted to purge the client and spend a couple days recreate them due to this not going away on its own. I now no longer have access to the data for test purposes. I suppose I will also close the ticket as it is no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants