mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add check for invoice JS amounts
This commit is contained in:
parent
25bd16ccb1
commit
561407f3cc
@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon;
|
||||
use App\Libraries\CurlUtils;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
@ -75,6 +76,7 @@ class CheckData extends Command
|
||||
$this->checkDraftSentInvoices();
|
||||
}
|
||||
|
||||
$this->checkInvoices();
|
||||
$this->checkBalances();
|
||||
$this->checkContacts();
|
||||
$this->checkUserAccounts();
|
||||
@ -131,6 +133,39 @@ class CheckData extends Command
|
||||
}
|
||||
}
|
||||
|
||||
private function checkInvoices()
|
||||
{
|
||||
if (! env('PHANTOMJS_BIN_PATH')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$date = new Carbon();
|
||||
$date = $date->subDays(1)->format('Y-m-d');
|
||||
|
||||
$invoices = Invoice::withTrashed()
|
||||
->with('invitations')
|
||||
->where('created_at', '>', $date)
|
||||
->orderBy('id')
|
||||
->get(['id', 'balance']);
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$link = $invoice->getInvitationLink();
|
||||
$this->logMessage('Checking invoice: ' . $invoice->id . ' - ' . $invoice->balance);
|
||||
$result = CurlUtils::phantom('GET', $link . '?phantomjs=true&phantomjs_balances=true&phantomjs_secret=' . env('PHANTOMJS_SECRET'));
|
||||
$result = floatval(strip_tags($result));
|
||||
$this->logMessage('Result: ' . $result);
|
||||
|
||||
if ($result != $invoice->balance) {
|
||||
$this->logMessage("Amounts do not match - PHP: {$invoice->balance}, JS: {$result}");
|
||||
$this->isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isValid) {
|
||||
$this->logMessage('0 invoices with mismatched PHP/JS balances');
|
||||
}
|
||||
}
|
||||
|
||||
private function checkOAuth()
|
||||
{
|
||||
// check for duplicate oauth ids
|
||||
|
@ -200,15 +200,22 @@
|
||||
|
||||
$(function() {
|
||||
@if (Input::has('phantomjs'))
|
||||
@if (Input::has('phantomjs_balances'))
|
||||
document.write(calculateAmounts(invoice).total_amount);
|
||||
document.close();
|
||||
if (window.hasOwnProperty('pjsc_meta')) {
|
||||
window['pjsc_meta'].remainingTasks--;
|
||||
}
|
||||
@else
|
||||
doc = getPDFString();
|
||||
doc.getDataUrl(function(pdfString) {
|
||||
document.write(pdfString);
|
||||
document.close();
|
||||
|
||||
if (window.hasOwnProperty('pjsc_meta')) {
|
||||
window['pjsc_meta'].remainingTasks--;
|
||||
}
|
||||
});
|
||||
@endif
|
||||
@else
|
||||
refreshPDF();
|
||||
@endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user