1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Fixes for expense repository

This commit is contained in:
David Bomba 2024-07-10 13:58:27 +10:00
parent 398e72a968
commit 116d0f4b15
4 changed files with 42 additions and 3 deletions

View File

@ -56,7 +56,7 @@ class UpdateExpenseRequest extends Request
$rules['invoice_id'] = 'bail|sometimes|nullable|exists:invoices,id,company_id,'.$user->company()->id;
$rules['documents'] = 'bail|sometimes|array';
$rules['amount'] = ['sometimes', 'bail', 'nullable', 'numeric', 'max:99999999999999'];
return $this->globalRules($rules);
}

View File

@ -46,7 +46,7 @@ class ExpenseRepository extends BaseRepository
/** @var \App\Models\User $user */
$user = auth()->user();
$payment_date = &$data['payment_date'];
$payment_date = isset($data['payment_date']) ? $data['payment_date'] : false;
if($payment_date && $payment_date == $expense->payment_date) {
//do nothing

View File

@ -47,6 +47,46 @@ class ExpenseApiTest extends TestCase
Model::reguard();
}
public function testVendorPayment()
{
$data = [
'amount' => 100,
'payment_date' => now()->format('Y-m-d'),
'vendor_id' => $this->vendor->hashed_id,
'date' => '2021-10-01',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/expenses', $data);
$arr = $response->json();
$response->assertStatus(200);
$this->assertEquals($this->vendor->hashed_id, $arr['data']['vendor_id']);
$this->assertEquals(now()->format('Y-m-d'), $arr['data']['payment_date']);
$data = [
'amount' => 100,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson('/api/v1/expenses/'.$arr['data']['id'], $data);
$arr = $response->json();
$response->assertStatus(200);
$this->assertEquals(now()->format('Y-m-d'), $arr['data']['payment_date']);
}
public function testExpensePutWithVendorStatus()
{

View File

@ -47,7 +47,6 @@ class VendorApiTest extends TestCase
Model::reguard();
}
public function testVendorContactCreation()
{
$data = [