diff --git a/app/Http/Requests/Task/StoreTaskRequest.php b/app/Http/Requests/Task/StoreTaskRequest.php index f61bc4267a23..3aaedf108a29 100644 --- a/app/Http/Requests/Task/StoreTaskRequest.php +++ b/app/Http/Requests/Task/StoreTaskRequest.php @@ -55,7 +55,8 @@ class StoreTaskRequest extends Request } $rules['hash'] = 'bail|sometimes|string|nullable'; - + $rules['rate'] = 'bail|numeric'; + $rules['time_log'] = ['bail',function ($attribute, $values, $fail) { if(is_string($values)) { @@ -123,6 +124,8 @@ class StoreTaskRequest extends Request } } + $input['rate'] = isset($input['rate']) ? $input['rate'] : 0; + if(!isset($input['time_log']) || empty($input['time_log']) || $input['time_log'] == '{}') { $input['time_log'] = json_encode([]); } diff --git a/tests/Feature/Bank/BankTransactionRuleTest.php b/tests/Feature/Bank/BankTransactionRuleTest.php index 8d86dd769baf..2b77c321870f 100644 --- a/tests/Feature/Bank/BankTransactionRuleTest.php +++ b/tests/Feature/Bank/BankTransactionRuleTest.php @@ -12,13 +12,14 @@ namespace Tests\Feature\Bank; +use Tests\TestCase; +use Tests\MockAccountData; use App\Models\BankIntegration; use App\Models\BankTransaction; use App\Models\BankTransactionRule; -use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Validation\ValidationException; -use Tests\MockAccountData; -use Tests\TestCase; +use Illuminate\Routing\Middleware\ThrottleRequests; +use Illuminate\Foundation\Testing\DatabaseTransactions; class BankTransactionRuleTest extends TestCase { @@ -38,6 +39,54 @@ class BankTransactionRuleTest extends TestCase $this->withoutExceptionHandling(); } + + + + + public function testMatchCreditOnInvoiceNumber() + { + + $bi = BankIntegration::factory()->create([ + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'account_id' => $this->account->id, + ]); + + $hash = md5(time()); + + $bt = BankTransaction::factory()->create([ + 'bank_integration_id' => $bi->id, + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'description' => $hash, + 'base_type' => 'CREDIT', + 'amount' => 100 + ]); + + $br = BankTransactionRule::factory()->create([ + 'company_id' => $this->company->id, + 'user_id' => $this->user->id, + 'matches_on_all' => false, + 'auto_convert' => true, + 'applies_to' => 'CREDIT', + 'rules' => [ + [ + 'search_key' => '$invoice.number', + 'operator' => 'is', + ] + ] + ]); + + $bt = $bt->refresh(); + + $debit_rules = $bt->company->debit_rules(); + + $bt->service()->processRules(); + + $bt = $bt->fresh(); + + } + public function testMatchingWithStripos() { $bt_value = strtolower(str_replace(" ", "", 'hello soldier'));