1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
This commit is contained in:
David Bomba 2021-08-24 11:23:53 +10:00
parent 37bd5dbd6a
commit 174248e03d
10 changed files with 479 additions and 1 deletions

View File

@ -0,0 +1,47 @@
<?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://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\RecurringExpense;
use App\Models\Company;
use App\Models\RecurringExpense;
use Illuminate\Queue\SerializesModels;
/**
* Class RecurringExpenseWasArchived.
*/
class RecurringExpenseWasArchived
{
use SerializesModels;
/**
* @var RecurringExpense
*/
public $recurring_expense;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param RecurringExpense $recurring_expense
* @param Company $company
* @param array $event_vars
*/
public function __construct(RecurringExpense $recurring_expense, Company $company, array $event_vars)
{
$this->recurring_expense = $recurring_expense;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,47 @@
<?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://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\RecurringExpense;
use App\Models\Company;
use App\Models\RecurringExpense;
use Illuminate\Queue\SerializesModels;
/**
* Class RecurringExpenseWasCreated.
*/
class RecurringExpenseWasCreated
{
use SerializesModels;
/**
* @var RecurringExpense
*/
public $recurring_expense;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param RecurringExpense $recurring_expense
* @param Company $company
* @param array $event_vars
*/
public function __construct(RecurringExpense $recurring_expense, Company $company, array $event_vars)
{
$this->recurring_expense = $recurring_expense;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,47 @@
<?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://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\RecurringExpense;
use App\Models\Company;
use App\Models\RecurringExpense;
use Illuminate\Queue\SerializesModels;
/**
* Class RecurringExpenseWasDeleted.
*/
class RecurringExpenseWasDeleted
{
use SerializesModels;
/**
* @var RecurringExpense
*/
public $recurring_expense;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param RecurringExpense $recurring_expense
* @param Company $company
* @param array $event_vars
*/
public function __construct(RecurringExpense $recurring_expense, Company $company, array $event_vars)
{
$this->recurring_expense = $recurring_expense;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,49 @@
<?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://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\RecurringExpense;
use App\Models\Company;
use App\Models\RecurringExpense;
use Illuminate\Queue\SerializesModels;
/**
* Class RecurringExpenseWasRestored.
*/
class RecurringExpenseWasRestored
{
use SerializesModels;
/**
* @var RecurringExpense
*/
public $recurring_expense;
public $company;
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*
* @param RecurringExpense $recurring_expense
* @param Company $company
* @param array $event_vars
*/
public function __construct(RecurringExpense $recurring_expense, $fromDeleted, Company $company, array $event_vars)
{
$this->recurring_expense = $recurring_expense;
$this->fromDeleted = $fromDeleted;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,47 @@
<?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://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\RecurringExpense;
use App\Models\Company;
use App\Models\RecurringExpense;
use Illuminate\Queue\SerializesModels;
/**
* Class RecurringExpenseWasUpdated.
*/
class RecurringExpenseWasUpdated
{
use SerializesModels;
/**
* @var RecurringExpense
*/
public $recurring_expense;
public $company;
public $event_vars;
/**
* Create a new event instance.
*
* @param RecurringExpense $recurring_expense
* @param Company $company
* @param array $event_vars
*/
public function __construct(RecurringExpense $recurring_expense, Company $company, array $event_vars)
{
$this->recurring_expense = $recurring_expense;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -0,0 +1,47 @@
<?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\RecurringExpense;
use Illuminate\Database\Eloquent\Factories\Factory;
class RecurringExpenseFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = RecurringExpense::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'amount' => $this->faker->numberBetween(1, 10),
'custom_value1' => $this->faker->text(10),
'custom_value2' => $this->faker->text(10),
'custom_value3' => $this->faker->text(10),
'custom_value4' => $this->faker->text(10),
'exchange_rate' => $this->faker->randomFloat(2, 0, 1),
'date' => $this->faker->date(),
'is_deleted' => false,
'public_notes' => $this->faker->text(50),
'private_notes' => $this->faker->text(50),
'transaction_reference' => $this->faker->text(5),
'invoice_id' => null,
];
}
}

View File

@ -26,9 +26,11 @@ class RecurringExpensesSchema extends Migration
$table->unsignedInteger('invoice_id')->nullable();
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('bank_id')->nullable();
$table->unsignedInteger('project_id')->nullable();
$table->unsignedInteger('payment_type_id')->nullable();
$table->unsignedInteger('recurring_expense_id')->nullable();
$table->boolean('is_deleted')->default(false);
$table->boolean('uses_inclusive_taxes')->default(true);
$table->string('tax_name1')->nullable();
$table->string('tax_name2')->nullable();
$table->string('tax_name3')->nullable();
@ -44,6 +46,9 @@ class RecurringExpensesSchema extends Migration
$table->unsignedInteger('category_id')->nullable();
$table->boolean('calculate_tax_by_amount')->default(false);
$table->decimal('tax_amount1', 20, 6);
$table->decimal('tax_amount2', 20, 6);
$table->decimal('tax_amount3', 20, 6);
$table->decimal('tax_rate1', 20, 6);
$table->decimal('tax_rate2', 20, 6);
$table->decimal('tax_rate3', 20, 6);
@ -53,7 +58,7 @@ class RecurringExpensesSchema extends Migration
$table->unsignedInteger('assigned_user_id')->nullable();
$table->string('number')->nullable();
$table->unsignedInteger('invoice_currency_id')->nullable();
$table->unsignedInteger('expense_currency_id')->nullable();
$table->unsignedInteger('currency_id')->nullable();
$table->text('private_notes')->nullable();
$table->text('public_notes')->nullable();
$table->text('transaction_reference')->nullable();

View File

@ -129,6 +129,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('quotes/bulk', 'QuoteController@bulk')->name('quotes.bulk');
Route::put('quotes/{quote}/upload', 'QuoteController@upload');
Route::resource('recurring_expenses', 'RecurringExpenseController');
Route::resource('recurring_invoices', 'RecurringInvoiceController'); // name = (recurring_invoices. index / create / show / update / destroy / edit
Route::post('recurring_invoices/bulk', 'RecurringInvoiceController@bulk')->name('recurring_invoices.bulk');
Route::put('recurring_invoices/{recurring_invoice}/upload', 'RecurringInvoiceController@upload');

View File

@ -0,0 +1,175 @@
<?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\Feature;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
use Tests\TestCase;
use Illuminate\Validation\ValidationException;
/**
* @test
* @covers App\Http\Controllers\RecurringExpenseController
*/
class RecurringExpenseApiTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
use MockAccountData;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
Session::start();
$this->faker = \Faker\Factory::create();
Model::reguard();
}
public function testRecurringExpenseGet()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/recurring_expenses/');
$response->assertStatus(200);
}
public function testRecurringExpenseGetSingleExpense()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/recurring_expenses/'.$this->recurring_expense->hashed_id);
$response->assertStatus(200);
}
public function testRecurringExpensePost()
{
$data = [
'amount' => 10,
'client_id' => $this->client->hashed_id,
'number' => '123321',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/recurring_expenses', $data);
$response->assertStatus(200);
}
// $arr = $response->json();
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->put('/api/v1/recurring_expenses/'.$arr['data']['id'], $data)->assertStatus(200);
// try{
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->post('/api/v1/recurring_expenses', $data);
// }
// catch(ValidationException $e){
// $response->assertStatus(302);
// }
// }
// public function testRecurringExpensePut()
// {
// $data = [
// 'name' => $this->faker->firstName,
// 'public_notes' => 'Coolio',
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->put('/api/v1/recurring_expenses/'.$this->encodePrimaryKey($this->project->id), $data);
// $response->assertStatus(200);
// }
// public function testRecurringExpenseNotArchived()
// {
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->get('/api/v1/recurring_expenses/'.$this->encodePrimaryKey($this->project->id));
// $arr = $response->json();
// $this->assertEquals(0, $arr['data']['archived_at']);
// }
// public function testRecurringExpenseArchived()
// {
// $data = [
// 'ids' => [$this->encodePrimaryKey($this->project->id)],
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->post('/api/v1/recurring_expenses/bulk?action=archive', $data);
// $arr = $response->json();
// $this->assertNotNull($arr['data'][0]['archived_at']);
// }
// public function testRecurringExpenseRestored()
// {
// $data = [
// 'ids' => [$this->encodePrimaryKey($this->project->id)],
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->post('/api/v1/recurring_expenses/bulk?action=restore', $data);
// $arr = $response->json();
// $this->assertEquals(0, $arr['data'][0]['archived_at']);
// }
// public function testRecurringExpenseDeleted()
// {
// $data = [
// 'ids' => [$this->encodePrimaryKey($this->project->id)],
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->post('/api/v1/recurring_expenses/bulk?action=delete', $data);
// $arr = $response->json();
// $this->assertTrue($arr['data'][0]['is_deleted']);
// }
}

View File

@ -36,6 +36,7 @@ use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use App\Models\RecurringExpense;
use App\Models\RecurringInvoice;
use App\Models\Task;
use App\Models\TaskStatus;
@ -83,6 +84,11 @@ trait MockAccountData
*/
public $token;
/**
* @var
*/
public $recurring_expense;
/**
* @var
*/
@ -285,6 +291,13 @@ trait MockAccountData
'company_id' => $this->company->id,
]);
$this->recurring_expense = RecurringExpense::factory()->create([
'user_id' => $user_id,
'company_id' => $this->company->id,
]);
$this->task = Task::factory()->create([
'user_id' => $user_id,
'company_id' => $this->company->id,