1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Payment Terms (#3737)

* Fixes for converting a quote to invoice

* Fixes for deleting an invoice

* Payment Terms CRUD

* Payment Terms

* Push PaymentTerms back into the DB

* Payment Terms

* Payment Terms

* Create api docs for payment terms
This commit is contained in:
David Bomba 2020-05-23 13:28:24 +10:00 committed by GitHub
parent 586424d2c0
commit 970c9bb87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 870 additions and 39 deletions

View File

@ -0,0 +1,26 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Factory;
use App\Models\PaymentTerm;
class PaymentTermFactory
{
public static function create(int $company_id, int $user_id) :PaymentTerm
{
$payment_term = new PaymentTerm;
$payment_term->user_id = $user_id;
$payment_term->company_id = $company_id;
return $payment_term;
}
}

View File

@ -670,6 +670,9 @@ class InvoiceController extends BaseController
}
break;
case 'delete':
//need to make sure the invoice is cancelled first!!
$invoice->service()->handleCancellation()->save();
$this->invoice_repo->delete($invoice);
if (!$bulk) {

View File

@ -0,0 +1,12 @@
<?php
/**
* @OA\Schema(
* schema="PaymentTerm",
* type="object",
* @OA\Property(property="num_days", type="integer", example="1", description="The payment term length in days"),
* @OA\Property(property="name", type="string", example="NET 1", description="The payment term length in string format"),
* @OA\Property(property="created_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* @OA\Property(property="updated_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* @OA\Property(property="archived_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* )
*/

View File

@ -0,0 +1,391 @@
<?php
namespace App\Http\Controllers;
use App\Factory\PaymentTermFactory;
use App\Http\Requests\PaymentTerm\CreatePaymentTermRequest;
use App\Http\Requests\PaymentTerm\DestroyPaymentTermRequest;
use App\Http\Requests\PaymentTerm\ShowPaymentTermRequest;
use App\Http\Requests\PaymentTerm\StorePaymentTermRequest;
use App\Http\Requests\PaymentTerm\UpdatePaymentTermRequest;
use App\Models\PaymentTerm;
use App\Transformers\PaymentTermTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
class PaymentTermController extends BaseController
{
use MakesHash;
protected $entity_type = PaymentTerm::class;
protected $entity_transformer = PaymentTermTransformer::class;
public function __construct()
{
parent::__construct();
}
/**
* @OA\Get(
* path="/api/v1/payment_terms",
* operationId="getPaymentTerms",
* tags={"payment_terms"},
* summary="Gets a list of payment terms",
* description="Lists payment terms",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\Response(
* response=200,
* description="A list of payment terms",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function index()
{
$payment_terms = PaymentTerm::whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
return $this->listResponse($payment_terms);
}
/**
* Show the form for creating a new resource.
*
* @param \App\Http\Requests\Payment\CreatePaymentTermRequest $request The request
*
* @return \Illuminate\Http\Response
*
*
*
* @OA\Get(
* path="/api/v1/payment_terms/create",
* operationId="getPaymentTermsCreate",
* tags={"payment_terms"},
* summary="Gets a new blank PaymentTerm object",
* description="Returns a blank object with default values",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A blank PaymentTerm object",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function create(CreatePaymentTermRequest $request)
{
$payment_term = PaymentTermFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($payment_term);
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\Payment\StorePaymentRequest $request The request
*
* @return \Illuminate\Http\Response
*
*
*
* @OA\Post(
* path="/api/v1/payment_terms",
* operationId="storePaymentTerm",
* tags={"payment_terms"},
* summary="Adds a Payment",
* description="Adds a Payment Term to the system",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\RequestBody(
* description="The payment_terms request",
* required=true,
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=200,
* description="Returns the saved Payment object",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function store(StorePaymentTermRequest $request)
{
$payment_term = PaymentTermFactory::create(auth()->user()->company()->id, auth()->user()->id);
$payment_term->fill($request->all());
$payment_term->save();
return $this->itemResponse($payment_term->fresh());
}
/**
* @OA\Get(
* path="/api/v1/payment_terms/{id}",
* operationId="showPaymentTerm",
* tags={"payment_terms"},
* summary="Shows a Payment Term",
* description="Displays an Payment Term by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Term Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment Term object",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function show(ShowPaymentTermRequest $request, PaymentTerm $payment_term)
{
return $this->itemResponse($payment_term);
}
/**
* @OA\Get(
* path="/api/v1/payment_terms/{id}/edit",
* operationId="editPaymentTerms",
* tags={"payment_terms"},
* summary="Shows an Payment Term for editting",
* description="Displays an Payment Term by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Term Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function edit(EditPaymentRequest $request, Payment $payment)
{
return $this->itemResponse($payment);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\PaymentTerm\UpdatePaymentTermRequest $request The request
* @param \App\Models\PaymentTerm $payment_term The payment term
*
* @return \Illuminate\Http\Response
*
*
* @OA\Put(
* path="/api/v1/payment_terms/{id}",
* operationId="updatePaymentTerm",
* tags={"payment_terms"},
* summary="Updates a Payment Term",
* description="Handles the updating of an Payment Termby id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Term Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment Term object",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/PaymentTerm"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function update(UpdatePaymentTermRequest $request, PaymentTerm $payment_term)
{
$payment_term->fill($request->all());
$payment_term->save();
return $this->itemResponse($payment_term->fresh());
}
/**
* Remove the specified resource from storage.
*
* @param \App\Http\Requests\PaymentTerm\DestroyPaymentTermRequest $request
* @param \App\Models\PaymentTerm $payment_term
*
* @return \Illuminate\Http\Response
*
*
* @OA\Delete(
* path="/api/v1/payment_terms/{id}",
* operationId="deletePaymentTerm",
* tags={"payment_termss"},
* summary="Deletes a Payment Term",
* description="Handles the deletion of an PaymentTerm by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Term Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns a HTTP status",
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*
*/
public function destroy(DestroyPaymentTermRequest $request, PaymentTerm $payment_term)
{
$payment_term->delete();
return response()->json([], 200);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\Payment;
class ActionPaymentTermRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\PaymentTerm;
class CreatePaymentTermRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\PaymentTerm;
class DestroyPaymentTermRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\PaymentTerm;
class EditPaymentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->isAdmin();
}
public function rules()
{
$rules = [];
return $rules;
}
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
$this->replace($input);
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\PaymentTerm;
class ShowPaymentTermRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Models\PaymentTerm;
use App\Utils\Traits\MakesHash;
class StorePaymentTermRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
public function rules()
{
$rules = [
];
return $rules;
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\PaymentTerm;
use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class UpdatePaymentTermRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
public function rules()
{
return [
'num_days' => 'required',
];
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
}

View File

@ -30,6 +30,8 @@ class PaymentTerm extends BaseModel
*/
protected $dates = ['deleted_at'];
protected $fillable = ['num_days'];
public function getNumDays()
{
return $this->num_days == -1 ? 0 : $this->num_days;
@ -39,7 +41,7 @@ class PaymentTerm extends BaseModel
{
$default_terms = collect(config('ninja.payment_terms'));
$terms = self::scope()->get();
$terms = self::whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null)->get();
$terms->map(function ($term) {
return $term['num_days'];

View File

@ -0,0 +1,32 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
use App\Models\PaymentTerm;
use App\Utils\Traits\MakesHash;
class PaymentTermTransformer extends EntityTransformer
{
use MakesHash;
public function transform(PaymentTerm $payment_term)
{
return [
'id' => (string) $this->encodePrimaryKey($payment_term->id),
'num_days' => (int) $payment_term->num_days,
'name' => (string) ctrans('texts.payment_terms_net') . ' ' . $payment_term->getNumDays(),
'created_at' => (int)$payment_term->created_at,
'updated_at' => (int)$payment_term->updated_at,
'archived_at' => (int)$payment_term->deleted_at,
];
}
}

View File

@ -97,41 +97,6 @@ return [
'slack' => env('SLACK_WEBHOOK_URL', ''),
'mail' => env('HOSTED_EMAIL', ''),
],
'payment_terms' => [
[
'num_days' => 0,
'name' => '',
],
[
'num_days' => 7,
'name' => '',
],
[
'num_days' => 10,
'name' => '',
],
[
'num_days' => 14,
'name' => '',
],
[
'num_days' => 15,
'name' => '',
],
[
'num_days' => 30,
'name' => '',
],
[
'num_days' => 60,
'name' => '',
],
[
'num_days' => 90,
'name' => '',
]
],
'themes' => [
'global' => 'ninja2020',
'portal' => 'ninja2020',

View File

@ -1026,8 +1026,8 @@ class CreateUsersTable extends Migration
$table->increments('id');
$table->integer('num_days');
$table->string('name')->nullable();
$table->unsignedInteger('company_id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('company_id')->nullable();
$table->unsignedInteger('user_id')->nullable();
$table->timestamps(6);
$table->softDeletes('deleted_at', 6);

View File

@ -28,6 +28,7 @@ class DatabaseSeeder extends Seeder
$this->call('LanguageSeeder');
$this->call('CountriesSeeder');
$this->call('IndustrySeeder');
$this->call('PaymentTermsSeeder');
$this->call('PaymentTypesSeeder');
$this->call('GatewayTypesSeeder');
$this->call('DateFormatsSeeder');

View File

@ -0,0 +1,28 @@
<?php
use App\Models\PaymentTerm;
use Illuminate\Database\Seeder;
class PaymentTermsSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
$paymentTerms = [
['num_days' => -1, 'name' => 'Net 0'],
['num_days' => 7, 'name' => ''],
['num_days' => 10, 'name' => ''],
['num_days' => 14, 'name' => ''],
['num_days' => 15, 'name' => ''],
['num_days' => 30, 'name' => ''],
['num_days' => 60, 'name' => ''],
['num_days' => 90, 'name' => ''],
];
foreach ($paymentTerms as $paymentTerm) {
PaymentTerm::create($paymentTerm);
}
}
}

View File

@ -71,6 +71,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::resource('client_statement', 'ClientStatementController@statement');// name = (client_statement. index / create / show / update / destroy / edit
Route::resource('payment_terms', 'PaymentTermController');// name = (payments. index / create / show / update / destroy / edit
Route::resource('payments', 'PaymentController');// name = (payments. index / create / show / update / destroy / edit
Route::post('payments/refund', 'PaymentController@refund')->name('payments.refund');

View File

@ -0,0 +1,113 @@
<?php
namespace Tests\Feature;
use App\DataMapper\DefaultSettings;
use App\Factory\PaymentTermFactory;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\PaymentTerm;
use App\Models\User;
use App\Utils\Traits\MakesHash;
use Faker\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Http\Controllers\PaymentTermController
*/
class PaymentTermsApiTest 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 testPaymentTermsGet()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->get('/api/v1/payment_terms');
$response->assertStatus(200);
}
public function testPostPaymentTerm()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->post('/api/v1/payment_terms', ['num_days' => 50 ]);
$response->assertStatus(200);
$data = $response->json();
$this->hashed_id = $data['data']['id'];
}
public function testPutPaymentTerms()
{
$payment_term = PaymentTermFactory::create($this->company->id, $this->user->id);
$payment_term->num_days = 500;
$payment_term->save();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->put('/api/v1/payment_terms/' . $this->encodePrimaryKey($payment_term->id), ['num_days' => 5000 ]);
$response->assertStatus(200);
}
public function testDeletePaymentTerm()
{
$payment_term = PaymentTermFactory::create($this->company->id, $this->user->id);
$payment_term->num_days = 500;
$payment_term->save();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token
])->delete('/api/v1/payment_terms/' . $this->encodePrimaryKey($payment_term->id));
$response->assertStatus(200);
$payment_term = PaymentTerm::find($payment_term->id);
$this->assertNull($payment_term);
}
}

View File

@ -27,7 +27,7 @@ class CollectionMergingTest extends TestCase
public function testBlankCollectionReturned()
{
$this->assertEquals($this->terms->count(), 0);
$this->assertEquals($this->terms->count(), 8);
}
public function testMergingCollection()