Merge pull request #3911 from turbo124/v2

V2
This commit is contained in:
David Bomba 2020-07-16 15:50:31 +10:00 committed by GitHub
commit 23f12ef27c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 22 deletions

View File

@ -291,8 +291,8 @@ class CheckData extends Command
foreach(Client::cursor() as $client)
{
$invoice_balance = $client->invoices->where('is_deleted', false)->sum('balance');
$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if($ledger && number_format($invoice_balance, 4) != number_format($client->balance, 4))
@ -346,16 +346,20 @@ class CheckData extends Command
{
$wrong_balances = 0;
$wrong_paid_to_dates = 0;
//todo reversing an invoice breaks the check data at this point;
Client::cursor()->each(function ($client) use($wrong_balances){
$client->invoices->where('is_deleted', false)->each(function ($invoice) use($wrong_balances, $client){
$total_amount = $invoice->payments->sum('pivot.amount');
$total_refund = $invoice->payments->sum('pivot.refunded');
$total_credit = $invoice->credits->sum('amount');
$total_paid = $total_amount - $total_refund;
if($total_paid != ($invoice->amount - $invoice->balance)) {
if($total_paid != ($invoice->amount - $invoice->balance - $total_credit)) {
$wrong_balances++;
$this->logMessage($client->present()->name . " - " . $client->id . " - balances do not match Invoice Amount = {$invoice->amount} - Invoice Balance = {$invoice->balance} Total paid = {$total_paid}");
@ -382,13 +386,24 @@ class CheckData extends Command
$invoice_balance = $client->invoices->sum('balance');
$invoice_amounts = $client->invoices->sum('amount') - $invoice_balance;
$credit_amounts = 0;
foreach($client->invoices as $invoice)
{
$credit_amounts += $invoice->credits->sum('amount');
};
/*To handle invoice reversals, we need to "ADD BACK" the credit amounts here*/
$client_paid_to_date = $client->paid_to_date + $credit_amounts;
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();
if($ledger && (string)$invoice_amounts != rtrim($client->paid_to_date, "0"))
if($ledger && (string)$invoice_amounts != (string)$client_paid_to_date)
{
$wrong_paid_to_dates++;
$this->logMessage($client->present()->name . " - " . $client->id . " - client paid to dates do not match {$invoice_amounts} - " .rtrim($client->paid_to_date, "0"));
$this->logMessage($client->present()->name . " - " . $client->id . " - client paid to dates do not match {$invoice_amounts} - " .rtrim($client_paid_to_date, "0"));
$this->isValid = false;

View File

@ -86,7 +86,7 @@ class DemoMode extends Command
private function createSmallAccount()
{
$this->count = 100;
$this->count = 10;
$this->info('Creating Small Account and Company');

View File

@ -45,9 +45,9 @@ class InvoiceEmail extends EmailBuilder
if (iconv_strlen($subject_template) == 0) {
if ($reminder_template == 'quote') {
$subject_template = trans(
'texts.invoice_subject',
'texts.quote_subject',
[
'invoice' => $invoice->present()->invoice_number(),
'number' => $invoice->number,
'account' => $invoice->company->present()->name()
],
null,
@ -55,9 +55,9 @@ class InvoiceEmail extends EmailBuilder
);
} else {
$subject_template = trans(
'texts.reminder_subject',
'texts.invoice_subject',
[
'invoice' => $invoice->present()->invoice_number(),
'number' => $invoice->number,
'account' => $invoice->company->present()->name()
],
null,

View File

@ -198,7 +198,6 @@ class Invoice extends BaseModel
public function payments()
{
return $this->morphToMany(Payment::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps()->withTrashed();
;
}
public function company_ledger()
@ -216,6 +215,10 @@ class Invoice extends BaseModel
return $this->hasManyThrough(Backup::class, Activity::class);
}
public function credits()
{
return $this->hasMany(Credit::class);
}
// public function credits()
// {
// return $this->belongsToMany(Credit::class)->using(Paymentable::class)->withPivot(

View File

@ -42,6 +42,8 @@ class AutoBillInvoice extends AbstractService
if(!$this->invoice->isPayable())
return $this->invoice;
$this->invoice = $this->invoice->service()->markSent()->save();
if($this->invoice->balance > 0)
$gateway_token = $this->getGateway($this->invoice->balance);
else
@ -70,12 +72,12 @@ class AutoBillInvoice extends AbstractService
if($payment){
$this->invoice->service()->toggleFeesPaid()->save();
$this->invoice = $this->invoice->service()->toggleFeesPaid()->save();
}
else
{
//autobill failed
//TODO autobill failed
}

View File

@ -45,6 +45,7 @@ class HandleReversal extends AbstractService
return $this->invoice;
}
/* If the invoice has been cancelled - we need to unwind the cancellation before reversing*/
if($this->invoice->status_id == Invoice::STATUS_CANCELLED)
$this->invoice = $this->invoice->service()->reverseCancellation()->save();

View File

@ -182,9 +182,11 @@ class InvoiceService
{
$this->invoice->line_items = collect($this->invoice->line_items)
->where('type_id',3)->map(function ($item) {
->map(function ($item) {
$item->type_id=4;
if($item->type_id == 3)
$item->type_id = 4;
return $item;
})->toArray();

View File

@ -42,6 +42,10 @@ class MarkPaid extends AbstractService
$this->invoice->service()->markSent();
}
/*Don't double pay*/
if($this->invoice->statud_id == Invoice::STATUS_PAID)
return $this->invoice;
/* Create Payment */
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);

View File

@ -45,11 +45,11 @@ class TriggeredActions extends AbstractService
{
if($this->request->has('auto_bill')) {
$this->invoice->service()->autoBill()->save();
$this->invoice = $this->invoice->service()->autoBill()->save();
}
if($this->request->has('paid') && (bool)$this->request->input('paid') !== false) {
$this->invoice->service()->markPaid()->save();
$this->invoice = $this->invoice->service()->markPaid()->save();
}
if($this->request->has('send_email') && (bool)$this->request->input('send_email') !== false) {
@ -62,7 +62,8 @@ class TriggeredActions extends AbstractService
private function sendEmail()
{
$reminder_template = $this->invoice->calculateTemplate();
//$reminder_template = $this->invoice->calculateTemplate();
$reminder_template = 'payment';
$this->invoice->invitations->load('contact.client.country','invoice.client.country','invoice.company')->each(function ($invitation) use($reminder_template){

View File

@ -10,6 +10,7 @@ $factory->define(App\Models\Company::class, function (Faker $faker) {
'ip' => $faker->ipv4,
'db' => config('database.default'),
'settings' => CompanySettings::defaults(),
'is_large' => true,
'custom_fields' => (object) [
//'invoice1' => 'Custom Date|date',
// 'invoice2' => '2|switch',

View File

@ -5,7 +5,7 @@
<title>Invoice Ninja</title>
<meta name="report_errors" content="{{ $report_errors }}">
<meta name="google-signin-client_id" content="{{ config('services.google.client_id') }}">
<link rel="manifest" href="manifest.json">
<link rel="manifest" href="manifest.json?v={{sha1(time())}}">
</head>
<body style="background-color:#888888;">
@ -75,7 +75,7 @@
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/flutter_service_worker.js');
navigator.serviceWorker.register('/flutter_service_worker.js?v={{sha1(time())}}');
});
}