mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Recurring expenses cron job
This commit is contained in:
parent
4bd3f382cb
commit
577eedb457
@ -21,6 +21,7 @@ class RecurringExpenseFactory
|
|||||||
$recurring_expense->user_id = $user_id;
|
$recurring_expense->user_id = $user_id;
|
||||||
$recurring_expense->company_id = $company_id;
|
$recurring_expense->company_id = $company_id;
|
||||||
$recurring_expense->is_deleted = false;
|
$recurring_expense->is_deleted = false;
|
||||||
|
$recurring_expense->invoice_documents = false;
|
||||||
$recurring_expense->should_be_invoiced = false;
|
$recurring_expense->should_be_invoiced = false;
|
||||||
$recurring_expense->tax_name1 = '';
|
$recurring_expense->tax_name1 = '';
|
||||||
$recurring_expense->tax_rate1 = 0;
|
$recurring_expense->tax_rate1 = 0;
|
||||||
@ -28,6 +29,9 @@ class RecurringExpenseFactory
|
|||||||
$recurring_expense->tax_rate2 = 0;
|
$recurring_expense->tax_rate2 = 0;
|
||||||
$recurring_expense->tax_name3 = '';
|
$recurring_expense->tax_name3 = '';
|
||||||
$recurring_expense->tax_rate3 = 0;
|
$recurring_expense->tax_rate3 = 0;
|
||||||
|
$recurring_expense->tax_amount1 = 0;
|
||||||
|
$recurring_expense->tax_amount2 = 0;
|
||||||
|
$recurring_expense->tax_amount3 = 0;
|
||||||
$recurring_expense->date = null;
|
$recurring_expense->date = null;
|
||||||
$recurring_expense->payment_date = null;
|
$recurring_expense->payment_date = null;
|
||||||
$recurring_expense->amount = 0;
|
$recurring_expense->amount = 0;
|
||||||
@ -39,6 +43,8 @@ class RecurringExpenseFactory
|
|||||||
$recurring_expense->custom_value2 = '';
|
$recurring_expense->custom_value2 = '';
|
||||||
$recurring_expense->custom_value3 = '';
|
$recurring_expense->custom_value3 = '';
|
||||||
$recurring_expense->custom_value4 = '';
|
$recurring_expense->custom_value4 = '';
|
||||||
|
$recurring_expense->uses_inclusive_taxes = true;
|
||||||
|
$recurring_expense->calculate_tax_by_amount = true;
|
||||||
|
|
||||||
return $recurring_expense;
|
return $recurring_expense;
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,18 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Cron;
|
namespace App\Jobs\Cron;
|
||||||
|
|
||||||
|
use App\Factory\RecurringExpenseToExpenseFactory;
|
||||||
use App\Jobs\RecurringInvoice\SendRecurring;
|
use App\Jobs\RecurringInvoice\SendRecurring;
|
||||||
use App\Libraries\MultiDB;
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\RecurringExpense;
|
use App\Models\RecurringExpense;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class RecurringExpensesCron
|
class RecurringExpensesCron
|
||||||
{
|
{
|
||||||
use Dispatchable;
|
use Dispatchable;
|
||||||
|
use GeneratesCounter;
|
||||||
|
|
||||||
public $tries = 1;
|
public $tries = 1;
|
||||||
|
|
||||||
@ -82,7 +85,11 @@ class RecurringExpensesCron
|
|||||||
|
|
||||||
private function generateExpense(RecurringExpense $recurring_expense)
|
private function generateExpense(RecurringExpense $recurring_expense)
|
||||||
{
|
{
|
||||||
|
$expense = RecurringExpenseToExpenseFactory::create($recurring_expense);
|
||||||
|
$expense->save();
|
||||||
|
|
||||||
|
$expense->number = $this->getNextExpenseNumber($expense);
|
||||||
|
$expense->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class RecurringExpensesSchema extends Migration
|
|||||||
$table->date('date')->nullable();
|
$table->date('date')->nullable();
|
||||||
$table->date('payment_date')->nullable();
|
$table->date('payment_date')->nullable();
|
||||||
$table->boolean('should_be_invoiced')->default(false);
|
$table->boolean('should_be_invoiced')->default(false);
|
||||||
$table->boolean('invoice_documents')->default();
|
$table->boolean('invoice_documents')->default(false);
|
||||||
$table->string('transaction_id')->nullable();
|
$table->string('transaction_id')->nullable();
|
||||||
$table->string('custom_value1')->nullable();
|
$table->string('custom_value1')->nullable();
|
||||||
$table->string('custom_value2')->nullable();
|
$table->string('custom_value2')->nullable();
|
||||||
@ -46,14 +46,14 @@ class RecurringExpensesSchema extends Migration
|
|||||||
|
|
||||||
$table->unsignedInteger('category_id')->nullable();
|
$table->unsignedInteger('category_id')->nullable();
|
||||||
$table->boolean('calculate_tax_by_amount')->default(false);
|
$table->boolean('calculate_tax_by_amount')->default(false);
|
||||||
$table->decimal('tax_amount1', 20, 6);
|
$table->decimal('tax_amount1', 20, 6)->nullable();
|
||||||
$table->decimal('tax_amount2', 20, 6);
|
$table->decimal('tax_amount2', 20, 6)->nullable();
|
||||||
$table->decimal('tax_amount3', 20, 6);
|
$table->decimal('tax_amount3', 20, 6)->nullable();
|
||||||
$table->decimal('tax_rate1', 20, 6);
|
$table->decimal('tax_rate1', 20, 6)->nullable();
|
||||||
$table->decimal('tax_rate2', 20, 6);
|
$table->decimal('tax_rate2', 20, 6)->nullable();
|
||||||
$table->decimal('tax_rate3', 20, 6);
|
$table->decimal('tax_rate3', 20, 6)->nullable();
|
||||||
$table->decimal('amount', 20, 6);
|
$table->decimal('amount', 20, 6)->nullable();
|
||||||
$table->decimal('foreign_amount', 20, 6);
|
$table->decimal('foreign_amount', 20, 6)->nullable();
|
||||||
$table->decimal('exchange_rate', 20, 6)->default(1);
|
$table->decimal('exchange_rate', 20, 6)->default(1);
|
||||||
$table->unsignedInteger('assigned_user_id')->nullable();
|
$table->unsignedInteger('assigned_user_id')->nullable();
|
||||||
$table->string('number')->nullable();
|
$table->string('number')->nullable();
|
||||||
|
69
tests/Unit/RecurringExpenseCloneTest.php
Normal file
69
tests/Unit/RecurringExpenseCloneTest.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?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 Tests\Unit;
|
||||||
|
|
||||||
|
use App\Factory\RecurringExpenseFactory;
|
||||||
|
use App\Factory\RecurringExpenseToExpenseFactory;
|
||||||
|
use App\Models\Account;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\RecurringExpense;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Utils\Ninja;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class RecurringExpenseCloneTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public $faker;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBadBase64String()
|
||||||
|
{
|
||||||
|
$account = Account::factory()->create();
|
||||||
|
$user = User::factory()->create(['account_id' => $account->id, 'email' => $this->faker->unique()->safeEmail]);
|
||||||
|
$company = Company::factory()->create(['account_id' => $account->id]);
|
||||||
|
|
||||||
|
$client = Client::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$recurring_expense = RecurringExpenseFactory::create($company->id, $user->id);
|
||||||
|
$recurring_expense->date = now();
|
||||||
|
$recurring_expense->amount = 10;
|
||||||
|
$recurring_expense->foreign_amount = 20;
|
||||||
|
$recurring_expense->exchange_rate = 0.5;
|
||||||
|
$recurring_expense->private_notes = "private";
|
||||||
|
$recurring_expense->public_notes = "public";
|
||||||
|
$recurring_expense->custom_value4 = "custom4";
|
||||||
|
$recurring_expense->should_be_invoiced = true;
|
||||||
|
|
||||||
|
$recurring_expense->save();
|
||||||
|
|
||||||
|
$expense = RecurringExpenseToExpenseFactory::create($recurring_expense);
|
||||||
|
$expense->save();
|
||||||
|
|
||||||
|
$this->assertNotNull($expense);
|
||||||
|
$this->assertEquals(20, $expense->foreign_amount);
|
||||||
|
$this->assertEquals(10, $expense->amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user