1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Fixes for payment validations

This commit is contained in:
David Bomba 2024-04-15 07:57:24 +10:00
parent 013454f25b
commit 9e12e32e29
9 changed files with 37 additions and 60 deletions

View File

@ -207,7 +207,6 @@ class InvoiceController extends Controller
//format data
$invoices->map(function ($invoice) {
// $invoice->service()->removeUnpaidGatewayFees();
$invoice->balance = $invoice->balance > 0 ? Number::formatValue($invoice->balance, $invoice->client->currency()) : 0;
$invoice->partial = $invoice->partial > 0 ? Number::formatValue($invoice->partial, $invoice->client->currency()) : 0;

View File

@ -27,12 +27,18 @@ class StoreBankTransactionRuleRequest extends Request
*/
public function authorize(): bool
{
return auth()->user()->can('create', BankTransactionRule::class) && auth()->user()->account->hasFeature(Account::FEATURE_API);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', BankTransactionRule::class) && $user->account->hasFeature(Account::FEATURE_API);
;
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
/* Ensure we have a client name, and that all emails are unique*/
$rules = [
'name' => 'bail|required|string',
@ -45,18 +51,9 @@ class StoreBankTransactionRuleRequest extends Request
'applies_to' => 'bail|sometimes|string',
];
if (isset($this->category_id)) {
$rules['category_id'] = 'bail|sometimes|exists:expense_categories,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
}
if (isset($this->vendor_id)) {
$rules['vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
}
if (isset($this->client_id)) {
$rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
}
$rules['category_id'] = 'bail|sometimes|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.$user->company()->id.',is_deleted,0';
return $rules;
}

View File

@ -45,9 +45,9 @@ class UpdatePaymentRequest extends Request
'client_id' => ['sometimes', 'bail', Rule::in([$this->payment->client_id])],
'number' => ['sometimes', 'bail', Rule::unique('payments')->where('company_id', $user->company()->id)->ignore($this->payment->id)],
'invoices' => ['sometimes', 'bail', 'nullable', 'array', new PaymentAppliedValidAmount($this->all())],
'invoices.*.invoice_id' => ['sometimes','distinct',Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
'invoices.*.invoice_id' => ['sometimes','distinct',Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->payment->client_id)],
'invoices.*.amount' => ['sometimes','numeric','min:0'],
'credits.*.credit_id' => ['sometimes','bail','distinct',Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
'credits.*.credit_id' => ['sometimes','bail','distinct',Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->payment->client_id)],
'credits.*.amount' => ['required', 'bail'],
];

View File

@ -61,7 +61,8 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
->where('id', '<', $company_ledger->id)
->where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id)
->where('balance', '!=', 0)
->whereNotNull('balance')
// ->where('balance', '!=', 0)
->orderBy('id', 'DESC')
->first();

View File

@ -23,31 +23,6 @@ class Submit extends Component
public function mount()
{
// $request = new \Illuminate\Http\Request([
// 'sidebar' => 'hidden',
// 'hash' => $this->context['hash'],
// 'action' => 'payment',
// 'invoices' => [
// $this->context['form']['invoice_hashed_id'],
// ],
// 'payable_invoices' => [
// [
// 'amount' => $this->context['form']['payable_amount'],
// 'invoice_id' => $this->context['form']['invoice_hashed_id'],
// ],
// ],
// 'company_gateway_id' => $this->context['form']['company_gateway_id'],
// 'payment_method_id' => $this->context['form']['payment_method_id'],
// 'contact_first_name' => $this->context['contact']['first_name'],
// 'contact_last_name' => $this->context['contact']['last_name'],
// 'contact_email' => $this->context['contact']['email'],
// ]);
// return redirect((new InstantPayment($request))->run());
// dd($this->context);
nlog($this->context);
$this->dispatch(
'purchase.submit',
invoice_hashed_id: $this->context['form']['invoice_hashed_id'],

View File

@ -101,6 +101,12 @@ class Number
if($comma === false) //no comma must be a decimal number already
return (float) $value;
if(!$decimal && substr($value, -3, 1) != ","){
$value = $value.".00";
}
$decimal = strpos($value, '.');
if($decimal < $comma){ //decimal before a comma = euro
$value = str_replace(['.',','], ['','.'], $value);
return (float) $value;
@ -228,9 +234,6 @@ class Number
$code = $currency->code;
$swapSymbol = $currency->swap_currency_symbol;
// App\Models\Client::country() returns instance of BelongsTo.
// App\Models\Company::country() returns record for the country, that's why we check for the instance.
if ($entity instanceof Company) {
$country = $entity->country();
} else {

View File

@ -26,9 +26,7 @@ trait SubscriptionHooker
'X-Requested-With' => 'XMLHttpRequest',
];
$post_purchase_rest_method = &$subscription->webhook_configuration['post_purchase_rest_method'];
if (!isset($subscription->webhook_configuration['post_purchase_url']) && !$post_purchase_rest_method) {
if (!isset($subscription->webhook_configuration['post_purchase_url']) && !isset($subscription->webhook_configuration['post_purchase_rest_method'])) {
return [];
}

View File

@ -12,16 +12,17 @@
namespace Tests\Feature\Bank;
use App\Factory\BankIntegrationFactory;
use App\Factory\BankTransactionFactory;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Models\BankTransaction;
use Tests\TestCase;
use App\Models\Expense;
use App\Models\Invoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
use App\Factory\InvoiceFactory;
use App\Models\BankTransaction;
use App\Factory\InvoiceItemFactory;
use App\Factory\BankIntegrationFactory;
use App\Factory\BankTransactionFactory;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class BankTransactionTest extends TestCase
{

View File

@ -28,15 +28,17 @@ class NumberTest extends TestCase
"22000.76" =>"22 000,76",
"22000.76" =>"22.000,76",
"22000.76" =>"22,000.76",
"22000" =>"22 000",
"22000" =>"22,000",
"2201" => "2,201",
"22001" =>"22 001",
"22002" =>"22,002",
"37123" => "37,123",
"22" =>"22.000",
"22000" =>"22.000,",
"22000.76" =>"22000.76",
"22000.76" =>"22000,76",
"1022000.76" =>"1.022.000,76",
"1022000.76" =>"1,022,000.76",
// "1000000" =>"1,000,000",
"1000000" =>"1,000,000",
// "1000000" =>"1.000.000",
"1022000.76" =>"1022000.76",
"1022000.76" =>"1022000,76",
@ -48,7 +50,7 @@ class NumberTest extends TestCase
"1" =>"1.00",
"1" =>"1,00",
"423545" =>"423545 €",
// "423545" =>"423,545 €",
"423545" =>"423,545 €",
// "423545" =>"423.545 €",
"1" =>"1,00 €",
"1.02" =>"€ 1.02",
@ -58,7 +60,8 @@ class NumberTest extends TestCase
"1000.02" =>"1.000,02 EURO",
"9.975" => "9.975",
"9975" => "9.975,",
"9975" => "9.975,00"
"9975" => "9.975,00",
// "0.571" => "0,571",
];