diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index e4eaf0cda946..32ab3529254d 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -361,6 +361,10 @@ class DemoMode extends Command $invoice = $invoice->service()->markPaid()->save(); + $invoice->payments->each(function ($payment){ + $payment->date = now()->addDays(rand(0,90)); + $payment->save(); + }); } //@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging. event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars())); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 397336a1855d..6b3922a254a2 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -50,11 +50,20 @@ class AutoBillInvoice extends AbstractService if(!$gateway_token) return $this->invoice; - $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->balance); + if($this->invoice->partial){ + $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->partial); + $amount = $this->invoice->partial + $fee; + } + else{ + $fee = $gateway_token->gateway->calcGatewayFee($this->invoice->balance); + $amount = $this->invoice->balance + $fee; + } if($fee > 0) $this->purgeStaleGatewayFees()->addFeeToInvoice($fee); + + $response = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice); //if response was successful, toggle the fee type_id to paid