1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Remove strings and replace with translations

This commit is contained in:
= 2021-01-24 22:48:09 +11:00
parent 36d7ee5d6a
commit 04d1a43dfe
19 changed files with 75 additions and 101 deletions

View File

@ -33,6 +33,6 @@ class ValidCompanyQuantity implements Rule
*/ */
public function message() public function message()
{ {
return 'Limit of 10 companies per account.'; return ctrans('texts.company_limit_reached');
} }
} }

View File

@ -48,6 +48,6 @@ class CreditsSumRule implements Rule
*/ */
public function message() public function message()
{ {
return "Total credits applied cannot be MORE than total of invoices"; return ctrans('texts.credits_applied_validation');
} }
} }

View File

@ -41,7 +41,7 @@ class UniqueCreditNumberRule implements Rule
*/ */
public function message() public function message()
{ {
return 'Credit number already taken'; return ctrans('texts.credit_number_taken');
} }
/** /**

View File

@ -44,7 +44,8 @@ class ValidCreditsRules implements Rule
private function checkCreditsAreHomogenous() private function checkCreditsAreHomogenous()
{ {
if (! array_key_exists('client_id', $this->input)) { 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; return false;
} }
@ -57,44 +58,32 @@ class ValidCreditsRules implements Rule
$cred = Credit::find($this->decodePrimaryKey($credit['credit_id'])); $cred = Credit::find($this->decodePrimaryKey($credit['credit_id']));
if (! $cred) { if (! $cred) {
$this->error_msg = 'Credit not found '; $this->error_msg = ctrans('texts.credit_not_found');
return false; return false;
} }
if ($cred->client_id != $this->input['client_id']) { 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; return false;
} }
} }
if (! (array_unique($unique_array) == $unique_array)) { if (! (array_unique($unique_array) == $unique_array)) {
$this->error_msg = 'Duplicate credits submitted.'; $this->error_msg = ctrans('texts.duplicate_credits_submitted');
return false; return false;
} }
if (count($this->input['credits']) >= 1 && count($this->input['invoices']) == 0) { 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; return false;
} }
if (count($this->input['credits']) >= 1) { 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; return true;

View File

@ -41,7 +41,7 @@ class UniqueExpenseNumberRule implements Rule
*/ */
public function message() 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']) ->where('number', $this->input['number'])
->withTrashed(); ->withTrashed();
// if(isset($this->input['client_id']))
// $expense->where('client_id', $this->input['client_id']);
return $expense->exists(); 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;
} }
} }

View File

@ -41,7 +41,7 @@ class UniqueInvoiceNumberRule implements Rule
*/ */
public function message() public function message()
{ {
return 'Invoice number already taken'; return ctrans('texts.invoice_number_taken');
} }
/** /**

View File

@ -44,7 +44,8 @@ class ValidInvoicesRules implements Rule
private function checkInvoicesAreHomogenous() private function checkInvoicesAreHomogenous()
{ {
if (! array_key_exists('client_id', $this->input)) { 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; return false;
} }
@ -60,14 +61,14 @@ class ValidInvoicesRules implements Rule
if (! $inv) { if (! $inv) {
$this->error_msg = 'Invoice not found '; $this->error_msg = ctrans('texts.invoice_not_found');
return false; return false;
} }
if ($inv->client_id != $this->input['client_id']) { 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; return false;
} }
@ -83,14 +84,14 @@ class ValidInvoicesRules implements Rule
} }
else if($invoice['amount'] > $inv->balance) { 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; return false;
} }
} }
if (! (array_unique($unique_array) == $unique_array)) { if (! (array_unique($unique_array) == $unique_array)) {
$this->error_msg = 'Duplicate invoices submitted.'; $this->error_msg = ctrans('texts.duplicate_invoices_submitted');
return false; return false;
} }

View File

@ -41,7 +41,7 @@ class ValidRefundableRequest implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
if (! array_key_exists('id', $this->input)) { if (! array_key_exists('id', $this->input)) {
$this->error_msg = 'Payment `id` required.'; $this->error_msg = ctrans('texts.payment_id_required');
return false; return false;
} }
@ -49,7 +49,7 @@ class ValidRefundableRequest implements Rule
$payment = Payment::whereId($this->input['id'])->first(); $payment = Payment::whereId($this->input['id'])->first();
if (! $payment) { if (! $payment) {
$this->error_msg = 'Unable to retrieve specified payment'; $this->error_msg = ctrans('texts.unable_to_retrieve_payment');
return false; return false;
} }
@ -57,31 +57,17 @@ class ValidRefundableRequest implements Rule
$request_invoices = request()->has('invoices') ? $this->input['invoices'] : []; $request_invoices = request()->has('invoices') ? $this->input['invoices'] : [];
$request_credits = request()->has('credits') ? $this->input['credits'] : []; $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()) { if ($payment->invoices()->exists()) {
foreach ($payment->invoices as $paymentable_invoice) { foreach ($payment->invoices as $paymentable_invoice) {
$this->checkInvoice($paymentable_invoice, $request_invoices); $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) { foreach ($request_invoices as $request_invoice) {
$this->checkInvoiceIsPaymentable($request_invoice, $payment); $this->checkInvoiceIsPaymentable($request_invoice, $payment);
} }
// foreach($request_credits as $request_credit)
// $this->checkCreditIsPaymentable($request_credit, $payment);
if (strlen($this->error_msg) > 0) { if (strlen($this->error_msg) > 0) {
return false; return false;
} }
@ -97,12 +83,12 @@ class ValidRefundableRequest implements Rule
$paymentable_invoice = $payment->invoices->where('id', $invoice->id)->first(); $paymentable_invoice = $payment->invoices->where('id', $invoice->id)->first();
if (! $paymentable_invoice) { 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; return false;
} }
} else { } 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; return false;
} }
@ -116,12 +102,12 @@ class ValidRefundableRequest implements Rule
$paymentable_credit = $payment->credits->where('id', $credit->id)->first(); $paymentable_credit = $payment->credits->where('id', $credit->id)->first();
if (! $paymentable_invoice) { 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; return false;
} }
} else { } 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; return false;
} }
@ -140,7 +126,7 @@ class ValidRefundableRequest implements Rule
if ($request_invoice['amount'] > $refundable_amount) { if ($request_invoice['amount'] > $refundable_amount) {
$invoice = $paymentable; $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; return false;
} }
@ -148,7 +134,7 @@ class ValidRefundableRequest implements Rule
} }
if (! $record_found) { 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; return false;
} }
@ -167,7 +153,7 @@ class ValidRefundableRequest implements Rule
if ($request_credit['amount'] > $refundable_amount) { if ($request_credit['amount'] > $refundable_amount) {
$credit = $paymentable; $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; return false;
} }
@ -175,7 +161,7 @@ class ValidRefundableRequest implements Rule
} }
if (! $record_found) { 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; return false;
} }

View File

@ -33,7 +33,7 @@ class PaymentAmountsBalanceRule implements Rule
*/ */
public function message() public function message()
{ {
return 'Amounts do not balance correctly.'; return ctrans('texts.amounts_do_not_balance');
} }
private function calculateAmounts() :bool private function calculateAmounts() :bool
@ -69,10 +69,8 @@ class PaymentAmountsBalanceRule implements Rule
} }
} else { } else {
return true; 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; return $payment_amounts >= $invoice_amounts;
} }

View File

@ -37,7 +37,7 @@ class PaymentAppliedValidAmount implements Rule
*/ */
public function message() public function message()
{ {
return 'Insufficient applied amount remaining to cover payment.'; return ctrans('texts.insufficient_applied_amount_remaining');
} }
private function calculateAmounts() :bool private function calculateAmounts() :bool

View File

@ -53,6 +53,6 @@ class ValidProjectForClient implements Rule
*/ */
public function message() public function message()
{ {
return "Project client does not match entity client"; return ctrans('texts.project_client_do_not_match');
} }
} }

View File

@ -41,7 +41,7 @@ class UniqueQuoteNumberRule implements Rule
*/ */
public function message() public function message()
{ {
return 'Quote number already taken'; return ctrans('texts.quote_number_taken');
} }
/** /**

View File

@ -41,7 +41,7 @@ class UniqueRecurringInvoiceNumberRule implements Rule
*/ */
public function message() public function message()
{ {
return "Recurring Invoice number {$this->input['number']} already taken"; return ctrans('texts.recurring_invoice_number_taken', ['number' => $this->input['number']]);
} }
/** /**

View File

@ -40,7 +40,7 @@ class RelatedUserRule implements Rule
*/ */
public function message() public function message()
{ {
return 'User not associated with this account'; return ctrans('texts.user_not_associated_with_account');
} }
/** /**

View File

@ -37,26 +37,13 @@ class ValidCreditsPresentRule implements Rule
*/ */
public function message() public function message()
{ {
return 'Insufficient balance on credit.'; return ctrans('texts.insufficient_credit_balance');
} }
private function validCreditsPresent() :bool private function validCreditsPresent() :bool
{ {
//todo need to ensure the clients credits are here not random ones! //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'))) { if (request()->input('credits') && is_array(request()->input('credits'))) {
$credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id'))) $credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id')))
->where('balance', '>', 0) ->where('balance', '>', 0)

View File

@ -40,7 +40,7 @@ class ValidPayableInvoicesRule implements Rule
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if (! $invoice->isPayable()) { 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; return false;
} }

View File

@ -40,7 +40,7 @@ class ValidRefundableInvoices implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
if (! array_key_exists('id', $this->input)) { if (! array_key_exists('id', $this->input)) {
$this->error_msg = 'Payment `id` required.'; $this->error_msg = ctrans('texts.payment_id_required');
return false; return false;
} }
@ -48,17 +48,11 @@ class ValidRefundableInvoices implements Rule
$payment = Payment::whereId($this->input['id'])->first(); $payment = Payment::whereId($this->input['id'])->first();
if (! $payment) { if (! $payment) {
$this->error_msg = "Payment couldn't be retrieved cannot be refunded "; $this->error_msg = ctrans('texts.unable_to_retrieve_payment');
return false; 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*/ /*If no invoices has been sent, then we apply the payment to the client account*/
$invoices = []; $invoices = [];
@ -70,7 +64,7 @@ class ValidRefundableInvoices implements Rule
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if (! $invoice->isRefundable()) { 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; return false;
} }
@ -82,7 +76,7 @@ class ValidRefundableInvoices implements Rule
$pivot_record = $payment->paymentables->where('paymentable_id', $invoice->id)->first(); $pivot_record = $payment->paymentables->where('paymentable_id', $invoice->id)->first();
if ($val['amount'] > ($pivot_record->amount - $pivot_record->refunded)) { 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; return false;
} }

View File

@ -34,7 +34,6 @@ class ValidUserForCompany implements Rule
*/ */
public function message() 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.user_not_associated_with_this_account');
//return ctrans('texts.email_already_register');
} }
} }

View File

@ -3374,4 +3374,37 @@ return [
'required_client_info_save_label' => 'We will save this, so you don\'t have to enter it next time.', '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' => 'We were unable to deliver Credit :invoice to :contact. \n :error',
'notification_credit_bounced_subject' => 'Unable to deliver Credit :invoice', '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?',
]; ];