mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5825 from turbo124/v5-develop
Force stripe amount to int
This commit is contained in:
commit
ee9b3a484f
@ -65,7 +65,7 @@ class CheckData extends Command
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'ninja:check-data {--database=} {--fix=}';
|
protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -34,6 +34,7 @@ use App\Models\Project;
|
|||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
|
use App\Models\TaxRate;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
use App\Models\VendorContact;
|
use App\Models\VendorContact;
|
||||||
@ -154,6 +155,29 @@ class CreateSingleAccount extends Command
|
|||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
TaxRate::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'name' => 'GST',
|
||||||
|
'rate' => 10
|
||||||
|
]);
|
||||||
|
|
||||||
|
TaxRate::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'name' => 'VAT',
|
||||||
|
'rate' => 17.5
|
||||||
|
]);
|
||||||
|
|
||||||
|
TaxRate::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'name' => 'CA Sales Tax',
|
||||||
|
'rate' => 5
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
$this->info('Creating '.$this->count.' clients');
|
$this->info('Creating '.$this->count.' clients');
|
||||||
|
|
||||||
for ($x = 0; $x < $this->count; $x++) {
|
for ($x = 0; $x < $this->count; $x++) {
|
||||||
|
@ -449,7 +449,7 @@ class LoginController extends BaseController
|
|||||||
|
|
||||||
MultiDB::setDefaultDatabase();
|
MultiDB::setDefaultDatabase();
|
||||||
|
|
||||||
$account = CreateAccount::dispatchNow($new_account);
|
$account = CreateAccount::dispatchNow($new_account, request()->getClientIp());
|
||||||
|
|
||||||
Auth::login($account->default_company->owner(), true);
|
Auth::login($account->default_company->owner(), true);
|
||||||
|
|
||||||
|
108
app/Jobs/Cron/AutoBillCron.php
Normal file
108
app/Jobs/Cron/AutoBillCron.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Jobs\Cron;
|
||||||
|
|
||||||
|
use App\Jobs\RecurringInvoice\SendRecurring;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\RecurringInvoice;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
class AutoBillCron
|
||||||
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
|
||||||
|
public $tries = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle() : void
|
||||||
|
{
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
/* Get all invoices where the send date is less than NOW + 30 minutes() */
|
||||||
|
nlog("Performing Autobilling ".Carbon::now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
|
|
||||||
|
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now())
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('auto_bill_enabled', true)
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->with('company')
|
||||||
|
->cursor();
|
||||||
|
|
||||||
|
$auto_bill_partial_invoices->each(function ($invoice){
|
||||||
|
$this->runAutoBiller($invoice);
|
||||||
|
});
|
||||||
|
|
||||||
|
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now())
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('auto_bill_enabled', true)
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->with('company')
|
||||||
|
->cursor();
|
||||||
|
|
||||||
|
$auto_bill_invoices->each(function ($invoice){
|
||||||
|
$this->runAutoBiller($invoice);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//multiDB environment, need to
|
||||||
|
foreach (MultiDB::$dbs as $db) {
|
||||||
|
MultiDB::setDB($db);
|
||||||
|
|
||||||
|
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now())
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('auto_bill_enabled', true)
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->with('company')
|
||||||
|
->cursor();
|
||||||
|
|
||||||
|
$auto_bill_partial_invoices->each(function ($invoice){
|
||||||
|
$this->runAutoBiller($invoice);
|
||||||
|
});
|
||||||
|
|
||||||
|
$auto_bill_invoices = Invoice::whereDate('due_date', '<=', now())
|
||||||
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
|
->where('auto_bill_enabled', true)
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->with('company')
|
||||||
|
->cursor();
|
||||||
|
|
||||||
|
$auto_bill_invoices->each(function ($invoice){
|
||||||
|
$this->runAutoBiller($invoice);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function runAutoBiller(Invoice $invoice)
|
||||||
|
{
|
||||||
|
$invoice->service()->autoBill()->save();
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,6 @@ trait Utilities
|
|||||||
|
|
||||||
public function convertToStripeAmount($amount, $precision)
|
public function convertToStripeAmount($amount, $precision)
|
||||||
{
|
{
|
||||||
return $amount * pow(10, $precision);
|
return (int)($amount * pow(10, $precision));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$is_partial = false;
|
||||||
|
|
||||||
/* Is the invoice payable? */
|
/* Is the invoice payable? */
|
||||||
if (! $this->invoice->isPayable())
|
if (! $this->invoice->isPayable())
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
@ -57,6 +59,8 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
/* Determine $amount */
|
/* Determine $amount */
|
||||||
if ($this->invoice->partial > 0) {
|
if ($this->invoice->partial > 0) {
|
||||||
|
$is_partial = true;
|
||||||
|
$invoice_total = $this->invoice->amount;
|
||||||
$amount = $this->invoice->partial;
|
$amount = $this->invoice->partial;
|
||||||
} elseif ($this->invoice->balance > 0) {
|
} elseif ($this->invoice->balance > 0) {
|
||||||
$amount = $this->invoice->balance;
|
$amount = $this->invoice->balance;
|
||||||
@ -77,7 +81,10 @@ class AutoBillInvoice extends AbstractService
|
|||||||
//$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes);
|
//$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes);
|
||||||
$this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save();
|
$this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save();
|
||||||
|
|
||||||
$fee = $this->invoice->amount - $amount;
|
if($is_partial)
|
||||||
|
$fee = $this->invoice->amount - $invoice_total;
|
||||||
|
else
|
||||||
|
$fee = $this->invoice->amount - $amount;
|
||||||
|
|
||||||
/* Build payment hash */
|
/* Build payment hash */
|
||||||
$payment_hash = PaymentHash::create([
|
$payment_hash = PaymentHash::create([
|
||||||
@ -340,68 +347,4 @@ class AutoBillInvoice extends AbstractService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes any existing unpaid gateway fees
|
|
||||||
* due to previous payment failure.
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
// private function purgeStaleGatewayFees()
|
|
||||||
// {
|
|
||||||
// $starting_amount = $this->invoice->amount;
|
|
||||||
|
|
||||||
// $line_items = $this->invoice->line_items;
|
|
||||||
|
|
||||||
// $new_items = [];
|
|
||||||
|
|
||||||
// foreach($line_items as $item)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// if($item->type_id != 3)
|
|
||||||
// $new_items[] = $item;
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $this->invoice->line_items = $new_items;
|
|
||||||
// $this->invoice->save();
|
|
||||||
|
|
||||||
// $this->invoice = $this->invoice->calc()->getInvoice();
|
|
||||||
|
|
||||||
// if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){
|
|
||||||
// $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
|
|
||||||
// $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return $this;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Checks whether a given gateway token is able
|
|
||||||
// * to process the payment after passing through the
|
|
||||||
// * fees and limits check.
|
|
||||||
// *
|
|
||||||
// * @param CompanyGateway $cg The CompanyGateway instance
|
|
||||||
// * @param float $amount The amount to be paid
|
|
||||||
// * @return bool
|
|
||||||
// */
|
|
||||||
// public function validGatewayLimits($cg, $amount) : bool
|
|
||||||
// {
|
|
||||||
// if (isset($cg->fees_and_limits)) {
|
|
||||||
// $fees_and_limits = $cg->fees_and_limits->{'1'};
|
|
||||||
// } else {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
|
||||||
// info("amount {$amount} less than ".$fees_and_limits->min_limit);
|
|
||||||
// $passes = false;
|
|
||||||
// } elseif ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->max_limit) {
|
|
||||||
// info("amount {$amount} greater than ".$fees_and_limits->max_limit);
|
|
||||||
// $passes = false;
|
|
||||||
// } else {
|
|
||||||
// $passes = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return $passes;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
38
database/factories/TaxRateFactory.php
Normal file
38
database/factories/TaxRateFactory.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\TaxRate;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class TaxRateFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = TaxRate::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->word(3),
|
||||||
|
'rate' => rand(1,20)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user