diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 2ebf7f50e3e2..b446a8d805b2 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -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; diff --git a/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php b/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php index aff60123fb66..c6ad4e159315 100644 --- a/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php +++ b/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php @@ -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; } diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index 0cc1beba7563..3c309af4c6f4 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -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'], ]; diff --git a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php index 7016f421a8a5..7a8724ce15c8 100644 --- a/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php +++ b/app/Jobs/Ledger/ClientLedgerBalanceUpdate.php @@ -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(); diff --git a/app/Livewire/BillingPortal/Submit.php b/app/Livewire/BillingPortal/Submit.php index a1324f96a3c1..d56340fa8d44 100644 --- a/app/Livewire/BillingPortal/Submit.php +++ b/app/Livewire/BillingPortal/Submit.php @@ -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'], diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 96def2edd94f..cc2a37033bae 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -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 { diff --git a/app/Utils/Traits/SubscriptionHooker.php b/app/Utils/Traits/SubscriptionHooker.php index f8dc0a1b97e8..bf33da13a494 100644 --- a/app/Utils/Traits/SubscriptionHooker.php +++ b/app/Utils/Traits/SubscriptionHooker.php @@ -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 []; } diff --git a/tests/Feature/Bank/BankTransactionTest.php b/tests/Feature/Bank/BankTransactionTest.php index 93176928f4df..60312d8c9f59 100644 --- a/tests/Feature/Bank/BankTransactionTest.php +++ b/tests/Feature/Bank/BankTransactionTest.php @@ -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 { diff --git a/tests/Unit/NumberTest.php b/tests/Unit/NumberTest.php index 191a034517e0..1f8e4ba04122 100644 --- a/tests/Unit/NumberTest.php +++ b/tests/Unit/NumberTest.php @@ -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", ];