mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
ACH autobill bug fixes
This commit is contained in:
parent
acbc0e887f
commit
1c119fe35a
@ -71,14 +71,12 @@ class SendRecurringInvoices extends Command
|
||||
}
|
||||
|
||||
$delayedAutoBillInvoices = Invoice::with('account.timezone', 'recurring_invoice', 'invoice_items', 'client', 'user')
|
||||
->leftJoin('invoices as recurring_invoice', 'invoices.recurring_invoice_id', '=', 'recurring_invoice.id')
|
||||
->whereRaw('invoices.is_deleted IS FALSE AND invoices.deleted_at IS NULL AND invoices.is_recurring IS FALSE
|
||||
AND invoices.balance > 0 AND invoices.due_date = ?
|
||||
AND (recurring_invoice.auto_bill = ? OR (recurring_invoice.auto_bill != ? AND recurring_invoice.client_enable_auto_bill IS TRUE))',
|
||||
array($today->format('Y-m-d'), AUTO_BILL_ALWAYS, AUTO_BILL_OFF))
|
||||
->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS FALSE
|
||||
AND balance > 0 AND due_date = ? AND recurring_invoice_id IS NOT NULL',
|
||||
array($today->format('Y-m-d')))
|
||||
->orderBy('invoices.id', 'asc')
|
||||
->get();
|
||||
$this->info(count($delayedAutoBillInvoices).' due recurring auto bill invoice instance(s) found');
|
||||
$this->info(count($delayedAutoBillInvoices).' due recurring invoice instance(s) found');
|
||||
|
||||
foreach ($delayedAutoBillInvoices as $invoice) {
|
||||
$autoBill = $invoice->getAutoBillEnabled();
|
||||
@ -91,6 +89,7 @@ class SendRecurringInvoices extends Command
|
||||
$this->info('Processing Invoice '.$invoice->id.' - Should bill '.($billNow ? 'YES' : 'NO'));
|
||||
|
||||
if ($billNow) {
|
||||
// autoBillInvoice will check for changes to ACH invoices, so we're not checking here
|
||||
$this->paymentService->autoBillInvoice($invoice);
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ class PaymentMethod extends EntityModel
|
||||
}
|
||||
|
||||
public function requiresDelayedAutoBill(){
|
||||
return $this->payment_type_id == PAYMENT_TYPE_DIRECT_DEBIT;
|
||||
return $this->payment_type_id == PAYMENT_TYPE_ACH;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,6 +816,7 @@ class InvoiceRepository extends BaseRepository
|
||||
$recurInvoice->save();
|
||||
|
||||
if ($recurInvoice->getAutoBillEnabled() && !$recurInvoice->account->auto_bill_on_due_date) {
|
||||
// autoBillInvoice will check for ACH, so we're not checking here
|
||||
if ($this->paymentService->autoBillInvoice($invoice)) {
|
||||
// update the invoice reference to match its actual state
|
||||
// this is to ensure a 'payment received' email is sent
|
||||
|
@ -16,6 +16,7 @@ use App\Models\Account;
|
||||
use App\Models\Country;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Activity;
|
||||
use App\Models\AccountGateway;
|
||||
use App\Http\Controllers\PaymentController;
|
||||
use App\Models\AccountGatewayToken;
|
||||
@ -872,16 +873,21 @@ class PaymentService extends BaseService
|
||||
}
|
||||
|
||||
if ($defaultPaymentMethod->requiresDelayedAutoBill()) {
|
||||
$invoiceDate = DateTime::createFromFormat('Y-m-d', $invoice_date);
|
||||
$invoiceDate = \DateTime::createFromFormat('Y-m-d', $invoice->invoice_date);
|
||||
$minDueDate = clone $invoiceDate;
|
||||
$minDueDate->modify('+10 days');
|
||||
|
||||
if (DateTime::create() < $minDueDate) {
|
||||
if (date_create() < $minDueDate) {
|
||||
// Can't auto bill now
|
||||
return false;
|
||||
}
|
||||
|
||||
$firstUpdate = \App\Models\Activities::where('invoice_id', '=', $invoice->id)
|
||||
if ($invoice->partial > 0) {
|
||||
// The amount would be different than the amount in the email
|
||||
return false;
|
||||
}
|
||||
|
||||
$firstUpdate = Activity::where('invoice_id', '=', $invoice->id)
|
||||
->where('activity_type_id', '=', ACTIVITY_TYPE_UPDATE_INVOICE)
|
||||
->first();
|
||||
|
||||
@ -894,10 +900,7 @@ class PaymentService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
$invoicePayments = \App\Models\Activities::where('invoice_id', '=', $invoice->id)
|
||||
->where('activity_type_id', '=', ACTIVITY_TYPE_CREATE_PAYMENT);
|
||||
|
||||
if ($invoicePayments->count()) {
|
||||
if ($invoice->payments->count()) {
|
||||
// ACH requirements are strict; don't auto bill this
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user