diff --git a/app/Http/ValidationRules/Company/ValidCompanyQuantity.php b/app/Http/ValidationRules/Company/ValidCompanyQuantity.php index aa164571e65a..5ab98ec6d5ae 100644 --- a/app/Http/ValidationRules/Company/ValidCompanyQuantity.php +++ b/app/Http/ValidationRules/Company/ValidCompanyQuantity.php @@ -33,6 +33,6 @@ class ValidCompanyQuantity implements Rule */ public function message() { - return 'Limit of 10 companies per account.'; + return ctrans('texts.company_limit_reached'); } } diff --git a/app/Http/ValidationRules/Credit/CreditsSumRule.php b/app/Http/ValidationRules/Credit/CreditsSumRule.php index 1d30630075cf..a659befe114c 100644 --- a/app/Http/ValidationRules/Credit/CreditsSumRule.php +++ b/app/Http/ValidationRules/Credit/CreditsSumRule.php @@ -48,6 +48,6 @@ class CreditsSumRule implements Rule */ public function message() { - return "Total credits applied cannot be MORE than total of invoices"; + return ctrans('texts.credits_applied_validation'); } } diff --git a/app/Http/ValidationRules/Credit/UniqueCreditNumberRule.php b/app/Http/ValidationRules/Credit/UniqueCreditNumberRule.php index 1f0dac92266d..d1a15ee1c19b 100644 --- a/app/Http/ValidationRules/Credit/UniqueCreditNumberRule.php +++ b/app/Http/ValidationRules/Credit/UniqueCreditNumberRule.php @@ -41,7 +41,7 @@ class UniqueCreditNumberRule implements Rule */ public function message() { - return 'Credit number already taken'; + return ctrans('texts.credit_number_taken'); } /** diff --git a/app/Http/ValidationRules/Credit/ValidCreditsRules.php b/app/Http/ValidationRules/Credit/ValidCreditsRules.php index 356e2e864a5b..689465f82403 100644 --- a/app/Http/ValidationRules/Credit/ValidCreditsRules.php +++ b/app/Http/ValidationRules/Credit/ValidCreditsRules.php @@ -44,7 +44,8 @@ class ValidCreditsRules implements Rule private function checkCreditsAreHomogenous() { if (! array_key_exists('client_id', $this->input)) { - $this->error_msg = 'Client id is required'; + + $this->error_msg = ctrans('texts.client_id_required'); return false; } @@ -57,44 +58,32 @@ class ValidCreditsRules implements Rule $cred = Credit::find($this->decodePrimaryKey($credit['credit_id'])); if (! $cred) { - $this->error_msg = 'Credit not found '; + $this->error_msg = ctrans('texts.credit_not_found'); return false; } if ($cred->client_id != $this->input['client_id']) { - $this->error_msg = 'Selected invoices are not from a single client'; + $this->error_msg = ctrans('texts.invoices_dont_match_client'); return false; } } if (! (array_unique($unique_array) == $unique_array)) { - $this->error_msg = 'Duplicate credits submitted.'; + $this->error_msg = ctrans('texts.duplicate_credits_submitted'); return false; } if (count($this->input['credits']) >= 1 && count($this->input['invoices']) == 0) { - $this->error_msg = 'You must have an invoice set when using a credit in a payment'; + $this->error_msg = ctrans('texts.credit_with_no_invoice'); return false; } if (count($this->input['credits']) >= 1) { - // $total_payments = $this->input['amount'] + array_sum(array_column($this->input['credits'], 'amount')); - -// nlog(print_r($this->input,1)); -// nlog("total payments = {$total_payments}"); -// nlog("total credits available = " . array_sum(array_column($this->input['credits'], 'amount'))); -// nlog("total invoices payable = " . array_sum(array_column($this->input['invoices'], 'amount'))); - - // if($total_payments > array_sum(array_column($this->input['invoices'], 'amount'))){ - - // $this->error_msg = "Sum of total payments and credits is greater than the total of invoices"; - // return false; - // } } return true; diff --git a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php index 40966b5f7b3f..68d3889a0d7f 100644 --- a/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php +++ b/app/Http/ValidationRules/Expense/UniqueExpenseNumberRule.php @@ -41,7 +41,7 @@ class UniqueExpenseNumberRule implements Rule */ public function message() { - return 'Expense number already taken'; + return ctrans('texts.expense_number_taken'); } /** @@ -57,20 +57,7 @@ class UniqueExpenseNumberRule implements Rule ->where('number', $this->input['number']) ->withTrashed(); - // if(isset($this->input['client_id'])) - // $expense->where('client_id', $this->input['client_id']); - return $expense->exists(); - // $expense = Expense::where('client_id', $this->input['client_id']) - // ->where('number', $this->input['number']) - // ->withTrashed() - // ->exists(); - - // if ($expense) { - // return false; - // } - - // return true; } } diff --git a/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php b/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php index a97d596b5a31..3efa342b8d9e 100644 --- a/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php +++ b/app/Http/ValidationRules/Invoice/UniqueInvoiceNumberRule.php @@ -41,7 +41,7 @@ class UniqueInvoiceNumberRule implements Rule */ public function message() { - return 'Invoice number already taken'; + return ctrans('texts.invoice_number_taken'); } /** diff --git a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php index 957f4f2cb248..b1b489c9e977 100644 --- a/app/Http/ValidationRules/Payment/ValidInvoicesRules.php +++ b/app/Http/ValidationRules/Payment/ValidInvoicesRules.php @@ -44,7 +44,8 @@ class ValidInvoicesRules implements Rule private function checkInvoicesAreHomogenous() { if (! array_key_exists('client_id', $this->input)) { - $this->error_msg = 'Client id is required'; + + $this->error_msg = ctrans('texts.client_id_required'); return false; } @@ -60,14 +61,14 @@ class ValidInvoicesRules implements Rule if (! $inv) { - $this->error_msg = 'Invoice not found '; + $this->error_msg = ctrans('texts.invoice_not_found'); return false; } if ($inv->client_id != $this->input['client_id']) { - $this->error_msg = 'Selected invoices are not from a single client'; + $this->error_msg = ctrans('texts.invoices_dont_match_client'); return false; } @@ -83,14 +84,14 @@ class ValidInvoicesRules implements Rule } else if($invoice['amount'] > $inv->balance) { - $this->error_msg = 'Amount cannot be greater than invoice balance'; + $this->error_msg = ctrans('texts.amount_greater_than_balance'); return false; } } if (! (array_unique($unique_array) == $unique_array)) { - $this->error_msg = 'Duplicate invoices submitted.'; + $this->error_msg = ctrans('texts.duplicate_invoices_submitted'); return false; } diff --git a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php index e5367a21c43f..55234c899a1f 100644 --- a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php +++ b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php @@ -41,7 +41,7 @@ class ValidRefundableRequest implements Rule public function passes($attribute, $value) { if (! array_key_exists('id', $this->input)) { - $this->error_msg = 'Payment `id` required.'; + $this->error_msg = ctrans('texts.payment_id_required'); return false; } @@ -49,7 +49,7 @@ class ValidRefundableRequest implements Rule $payment = Payment::whereId($this->input['id'])->first(); if (! $payment) { - $this->error_msg = 'Unable to retrieve specified payment'; + $this->error_msg = ctrans('texts.unable_to_retrieve_payment'); return false; } @@ -57,31 +57,17 @@ class ValidRefundableRequest implements Rule $request_invoices = request()->has('invoices') ? $this->input['invoices'] : []; $request_credits = request()->has('credits') ? $this->input['credits'] : []; - // foreach($request_invoices as $key => $value) - // $request_invoices[$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']); - - // foreach($request_credits as $key => $value) - // $request_credits[$key]['credit_id'] = $this->decodePrimaryKey($value['credit_id']); - if ($payment->invoices()->exists()) { foreach ($payment->invoices as $paymentable_invoice) { $this->checkInvoice($paymentable_invoice, $request_invoices); } } - // if($payment->credits()->exists()) - // { - // foreach($payment->credits as $paymentable_credit) - // $this->checkCredit($paymentable_credit, $request_credits); - // } foreach ($request_invoices as $request_invoice) { $this->checkInvoiceIsPaymentable($request_invoice, $payment); } - // foreach($request_credits as $request_credit) - // $this->checkCreditIsPaymentable($request_credit, $payment); - if (strlen($this->error_msg) > 0) { return false; } @@ -97,12 +83,12 @@ class ValidRefundableRequest implements Rule $paymentable_invoice = $payment->invoices->where('id', $invoice->id)->first(); if (! $paymentable_invoice) { - $this->error_msg = 'Invoice id '.$invoice->hashed_id.' is not related to this payment'; + $this->error_msg = ctrans('texts.invoice_not_related_to_payment', ['invoice' => $invoice->hashed_id]); return false; } } else { - $this->error_msg = 'Invoice id '.$invoice->hashed_id.' is not related to this payment'; + $this->error_msg = ctrans('texts.invoice_not_related_to_payment', ['invoice' => $invoice->hashed_id]); return false; } @@ -116,12 +102,12 @@ class ValidRefundableRequest implements Rule $paymentable_credit = $payment->credits->where('id', $credit->id)->first(); if (! $paymentable_invoice) { - $this->error_msg = 'Credit id '.$credit->hashed_id.' is not related to this payment'; + $this->error_msg = ctrans('texts.credit_not_related_to_payment', ['credit' => $credit->hashed_id]); return false; } } else { - $this->error_msg = 'Credit id '.$credit->hashed_id.' is not related to this payment'; + $this->error_msg = ctrans('texts.credit_not_related_to_payment', ['credit' => $credit->hashed_id]); return false; } @@ -140,7 +126,7 @@ class ValidRefundableRequest implements Rule if ($request_invoice['amount'] > $refundable_amount) { $invoice = $paymentable; - $this->error_msg = 'Attempting to refund more than allowed for invoice id '.$invoice->hashed_id.', maximum refundable amount is '.$refundable_amount; + $this->error_msg = ctrans('texts.max_refundable_invoice', ['invoice' => $invoice->hashed_id, 'amount' => $refundable_amount]); return false; } @@ -148,7 +134,7 @@ class ValidRefundableRequest implements Rule } if (! $record_found) { - $this->error_msg = 'Attempting to refund a payment with invoices attached, please specify valid invoice/s to be refunded.'; + $this->error_msg = ctrans('texts.refund_without_invoices'); return false; } @@ -167,7 +153,7 @@ class ValidRefundableRequest implements Rule if ($request_credit['amount'] > $refundable_amount) { $credit = $paymentable; - $this->error_msg = 'Attempting to refund more than allowed for credit '.$credit->number.', maximum refundable amount is '.$refundable_amount; + $this->error_msg = ctrans('texts.max_refundable_credit',['credit' => $credit->hashed_id, 'amount' => $refundable_amount]); return false; } @@ -175,7 +161,7 @@ class ValidRefundableRequest implements Rule } if (! $record_found) { - $this->error_msg = 'Attempting to refund a payment with credits attached, please specify valid credit/s to be refunded.'; + $this->error_msg = ctrans('texts.refund_without_credits'); return false; } diff --git a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php index 2f7efe259275..aa932e83cd4c 100644 --- a/app/Http/ValidationRules/PaymentAmountsBalanceRule.php +++ b/app/Http/ValidationRules/PaymentAmountsBalanceRule.php @@ -33,7 +33,7 @@ class PaymentAmountsBalanceRule implements Rule */ public function message() { - return 'Amounts do not balance correctly.'; + return ctrans('texts.amounts_do_not_balance'); } private function calculateAmounts() :bool @@ -69,10 +69,8 @@ class PaymentAmountsBalanceRule implements Rule } } else { return true; - } // if no invoices are present, then this is an unapplied payment, let this pass validation! - - // nlog("payment amounts = {$payment_amounts}"); - // nlog("invoice amounts = {$invoice_amounts}"); + } + return $payment_amounts >= $invoice_amounts; } diff --git a/app/Http/ValidationRules/PaymentAppliedValidAmount.php b/app/Http/ValidationRules/PaymentAppliedValidAmount.php index f3da06764d6c..33e1e138ccdf 100644 --- a/app/Http/ValidationRules/PaymentAppliedValidAmount.php +++ b/app/Http/ValidationRules/PaymentAppliedValidAmount.php @@ -37,7 +37,7 @@ class PaymentAppliedValidAmount implements Rule */ public function message() { - return 'Insufficient applied amount remaining to cover payment.'; + return ctrans('texts.insufficient_applied_amount_remaining'); } private function calculateAmounts() :bool diff --git a/app/Http/ValidationRules/Project/ValidProjectForClient.php b/app/Http/ValidationRules/Project/ValidProjectForClient.php index cceade8f75d5..3cb7db419297 100644 --- a/app/Http/ValidationRules/Project/ValidProjectForClient.php +++ b/app/Http/ValidationRules/Project/ValidProjectForClient.php @@ -53,6 +53,6 @@ class ValidProjectForClient implements Rule */ public function message() { - return "Project client does not match entity client"; + return ctrans('texts.project_client_do_not_match'); } } diff --git a/app/Http/ValidationRules/Quote/UniqueQuoteNumberRule.php b/app/Http/ValidationRules/Quote/UniqueQuoteNumberRule.php index 28440a4a5ba9..e061d1539c5d 100644 --- a/app/Http/ValidationRules/Quote/UniqueQuoteNumberRule.php +++ b/app/Http/ValidationRules/Quote/UniqueQuoteNumberRule.php @@ -41,7 +41,7 @@ class UniqueQuoteNumberRule implements Rule */ public function message() { - return 'Quote number already taken'; + return ctrans('texts.quote_number_taken'); } /** diff --git a/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php b/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php index a1ceb7f7eb46..330eca952628 100644 --- a/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php +++ b/app/Http/ValidationRules/Recurring/UniqueRecurringInvoiceNumberRule.php @@ -41,7 +41,7 @@ class UniqueRecurringInvoiceNumberRule implements Rule */ public function message() { - return "Recurring Invoice number {$this->input['number']} already taken"; + return ctrans('texts.recurring_invoice_number_taken', ['number' => $this->input['number']]); } /** diff --git a/app/Http/ValidationRules/User/RelatedUserRule.php b/app/Http/ValidationRules/User/RelatedUserRule.php index 5061d7eccb53..a46032c91be8 100644 --- a/app/Http/ValidationRules/User/RelatedUserRule.php +++ b/app/Http/ValidationRules/User/RelatedUserRule.php @@ -40,7 +40,7 @@ class RelatedUserRule implements Rule */ public function message() { - return 'User not associated with this account'; + return ctrans('texts.user_not_associated_with_account'); } /** diff --git a/app/Http/ValidationRules/ValidCreditsPresentRule.php b/app/Http/ValidationRules/ValidCreditsPresentRule.php index 604d0652bf20..ebbeaf16a4b2 100644 --- a/app/Http/ValidationRules/ValidCreditsPresentRule.php +++ b/app/Http/ValidationRules/ValidCreditsPresentRule.php @@ -37,26 +37,13 @@ class ValidCreditsPresentRule implements Rule */ public function message() { - return 'Insufficient balance on credit.'; + return ctrans('texts.insufficient_credit_balance'); } private function validCreditsPresent() :bool { //todo need to ensure the clients credits are here not random ones! - // if (request()->input('credits') && is_array(request()->input('credits'))) { - // foreach (request()->input('credits') as $credit) { - // $cred = Credit::find($this->decodePrimaryKey($credit['credit_id'])); - - // if (! $cred || $cred->balance == 0) { - // return false; - // } - // } - // } - - // return true; - - if (request()->input('credits') && is_array(request()->input('credits'))) { $credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id'))) ->where('balance', '>', 0) diff --git a/app/Http/ValidationRules/ValidPayableInvoicesRule.php b/app/Http/ValidationRules/ValidPayableInvoicesRule.php index 67d098428cb2..98cbc47fa282 100644 --- a/app/Http/ValidationRules/ValidPayableInvoicesRule.php +++ b/app/Http/ValidationRules/ValidPayableInvoicesRule.php @@ -40,7 +40,7 @@ class ValidPayableInvoicesRule implements Rule foreach ($invoices as $invoice) { if (! $invoice->isPayable()) { - $this->error_msg = 'One or more of these invoices have been paid'; + $this->error_msg = ctrans('texts.one_or_more_invoices_paid'); return false; } diff --git a/app/Http/ValidationRules/ValidRefundableInvoices.php b/app/Http/ValidationRules/ValidRefundableInvoices.php index 72fc3002ba91..e500b57466a6 100644 --- a/app/Http/ValidationRules/ValidRefundableInvoices.php +++ b/app/Http/ValidationRules/ValidRefundableInvoices.php @@ -40,7 +40,7 @@ class ValidRefundableInvoices implements Rule public function passes($attribute, $value) { if (! array_key_exists('id', $this->input)) { - $this->error_msg = 'Payment `id` required.'; + $this->error_msg = ctrans('texts.payment_id_required'); return false; } @@ -48,17 +48,11 @@ class ValidRefundableInvoices implements Rule $payment = Payment::whereId($this->input['id'])->first(); if (! $payment) { - $this->error_msg = "Payment couldn't be retrieved cannot be refunded "; + $this->error_msg = ctrans('texts.unable_to_retrieve_payment'); return false; } - /*We are not sending the Refunded amount in the 'amount field, this is the Payment->amount, need to skip this check. */ - // if (request()->has('amount') && (request()->input('amount') > ($payment->amount - $payment->refunded))) { - // $this->error_msg = "Attempting to refund more than payment amount, enter a value equal to or lower than the payment amount of ". $payment->amount; - // return false; - // } - /*If no invoices has been sent, then we apply the payment to the client account*/ $invoices = []; @@ -70,7 +64,7 @@ class ValidRefundableInvoices implements Rule foreach ($invoices as $invoice) { if (! $invoice->isRefundable()) { - $this->error_msg = 'Invoice id '.$invoice->hashed_id.' cannot be refunded'; + $this->error_msg = ctrans('texts.invoice_cannot_be_refunded', ['invoice' => $invoice->hashed_id]); return false; } @@ -82,7 +76,7 @@ class ValidRefundableInvoices implements Rule $pivot_record = $payment->paymentables->where('paymentable_id', $invoice->id)->first(); if ($val['amount'] > ($pivot_record->amount - $pivot_record->refunded)) { - $this->error_msg = 'Attempting to refund '.$val['amount'].' only '.($pivot_record->amount - $pivot_record->refunded).' available for refund'; + $this->error_msg = ctrans('texts.attempted_refund_failed', ['amount' => $val['amount'], 'refundable_amount' => ($pivot_record->amount - $pivot_record->refunded)]); return false; } diff --git a/app/Http/ValidationRules/ValidUserForCompany.php b/app/Http/ValidationRules/ValidUserForCompany.php index a045d8c83e06..d09b5760aa40 100644 --- a/app/Http/ValidationRules/ValidUserForCompany.php +++ b/app/Http/ValidationRules/ValidUserForCompany.php @@ -34,7 +34,6 @@ class ValidUserForCompany implements Rule */ public function message() { - return 'This user is unable to be attached to this company. Perhaps they have already registered a user on another account?'; - //return ctrans('texts.email_already_register'); + return ctrans('texts.user_not_associated_with_this_account'); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3ef41ab64de3..133ad13de41a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3374,4 +3374,37 @@ return [ 'required_client_info_save_label' => 'We will save this, so you don\'t have to enter it next time.', 'notification_credit_bounced' => 'We were unable to deliver Credit :invoice to :contact. \n :error', 'notification_credit_bounced_subject' => 'Unable to deliver Credit :invoice', + + 'company_limit_reached' => 'Limit of 10 companies per account.', + 'credits_applied_validation' => 'Total credits applied cannot be MORE than total of invoices', + 'credit_number_taken' => 'Credit number already taken', + 'credit_not_found' => 'Credit not found', + 'invoices_dont_match_client' => 'Selected invoices are not from a single client', + 'duplicate_credits_submitted' => 'Duplicate credits submitted.', + 'duplicate_invoices_submitted' => 'Duplicate invoices submitted.', + 'credit_with_no_invoice' => 'You must have an invoice set when using a credit in a payment', + 'client_id_required' => 'Client id is required', + 'expense_number_taken' => 'Expense number already taken', + 'invoice_number_taken' => 'Invoice number already taken', + 'invoice_not_found' => 'Invoice not found', + 'amount_greater_than_balance' => 'Amount cannot be greater than invoice balance', + 'payment_id_required' => 'Payment `id` required.', + 'unable_to_retrieve_payment' => 'Unable to retrieve specified payment', + 'invoice_not_related_to_payment' => 'Invoice id :invoice is not related to this payment', + 'credit_not_related_to_payment' => 'Credit id :credit is not related to this payment', + 'max_refundable_invoice' => 'Attempting to refund more than allowed for invoice id :invoice, maximum refundable amount is :amount', + 'refund_without_invoices' => 'Attempting to refund a payment with invoices attached, please specify valid invoice/s to be refunded.', + 'refund_without_credits' => 'Attempting to refund a payment with credits attached, please specify valid credits/s to be refunded.', + 'max_refundable_credit' => 'Attempting to refund more than allowed for credit :credit, maximum refundable amount is :amount', + 'project_client_do_not_match' => "Project client does not match entity client", + 'quote_number_taken' => 'Quote number already taken', + 'recurring_invoice_number_taken' => 'Recurring Invoice number :number already taken', + 'user_not_associated_with_account' => 'User not associated with this account', + 'amounts_do_not_balance' => 'Amounts do not balance correctly.', + 'insufficient_applied_amount_remaining' => 'Insufficient applied amount remaining to cover payment.', + 'insufficient_credit_balance' => 'Insufficient balance on credit.', + 'one_or_more_invoices_paid' => 'One or more of these invoices have been paid', + 'invoice_cannot_be_refunded' => 'Invoice id :number cannot be refunded', + 'attempted_refund_failed' => 'Attempting to refund :amount only :refundable_amount available for refund', + 'user_not_associated_with_this_account' => 'This user is unable to be attached to this company. Perhaps they have already registered a user on another account?', ];