1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02: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()
{
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()
{
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()
{
return 'Credit number already taken';
return ctrans('texts.credit_number_taken');
}
/**

View File

@ -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;

View File

@ -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;
}
}

View File

@ -41,7 +41,7 @@ class UniqueInvoiceNumberRule implements Rule
*/
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()
{
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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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');
}
}

View File

@ -41,7 +41,7 @@ class UniqueQuoteNumberRule implements Rule
*/
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()
{
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()
{
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()
{
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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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');
}
}

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.',
'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?',
];