Add check for invoice JS amounts

This commit is contained in:
Hillel Coren 2017-07-03 13:15:06 +03:00
parent 25bd16ccb1
commit 561407f3cc
2 changed files with 51 additions and 9 deletions

View File

@ -3,6 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use Carbon; use Carbon;
use App\Libraries\CurlUtils;
use DB; use DB;
use Exception; use Exception;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -75,6 +76,7 @@ class CheckData extends Command
$this->checkDraftSentInvoices(); $this->checkDraftSentInvoices();
} }
$this->checkInvoices();
$this->checkBalances(); $this->checkBalances();
$this->checkContacts(); $this->checkContacts();
$this->checkUserAccounts(); $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() private function checkOAuth()
{ {
// check for duplicate oauth ids // check for duplicate oauth ids

View File

@ -200,15 +200,22 @@
$(function() { $(function() {
@if (Input::has('phantomjs')) @if (Input::has('phantomjs'))
doc = getPDFString(); @if (Input::has('phantomjs_balances'))
doc.getDataUrl(function(pdfString) { document.write(calculateAmounts(invoice).total_amount);
document.write(pdfString); document.close();
document.close(); if (window.hasOwnProperty('pjsc_meta')) {
window['pjsc_meta'].remainingTasks--;
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 @else
refreshPDF(); refreshPDF();
@endif @endif