mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for linking expenses
This commit is contained in:
parent
9ee545160c
commit
006a4e4738
@ -39,7 +39,7 @@ class MatchBankTransactionRequest extends Request
|
||||
$rules['transactions.*.vendor_id'] = 'bail|nullable|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
$rules['transactions.*.id'] = 'bail|required|exists:bank_transactions,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
$rules['transactions.*.payment_id'] = 'bail|sometimes|nullable|exists:payments,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
$rules['transactions.*.expense_id'] = 'bail|sometimes|nullable|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
// $rules['transactions.*.expense_id'] = 'bail|sometimes|nullable|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@ -72,14 +72,14 @@ class MatchBankTransactionRequest extends Request
|
||||
}
|
||||
|
||||
if (array_key_exists('expense_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['expense_id']) >= 1) {
|
||||
$inputs['transactions'][$key]['expense_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['expense_id']);
|
||||
// $inputs['transactions'][$key]['expense_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['expense_id']);
|
||||
|
||||
$e = Expense::withTrashed()->where('company_id', auth()->user()->company()->id)->where('id', $inputs['transactions'][$key]['expense_id'])->first();
|
||||
// $e = Expense::withTrashed()->where('company_id', auth()->user()->company()->id)->where('id', $inputs['transactions'][$key]['expense_id'])->first();
|
||||
|
||||
/*Ensure we don't relink an existing expense*/
|
||||
if (!$e || is_numeric($e->transaction_id)) {
|
||||
unset($inputs['transactions'][$key]['expense_id']);
|
||||
}
|
||||
// if (!$e || is_numeric($e->transaction_id)) {
|
||||
// unset($inputs['transactions'][$key]['expense_id']);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,19 +156,27 @@ class MatchBankTransactions implements ShouldQueue
|
||||
return $this;
|
||||
}
|
||||
|
||||
$expense = Expense::withTrashed()->find($input['expense_id']);
|
||||
$_expenses = explode(",", $input['expense_id']);
|
||||
|
||||
if ($expense && !$expense->transaction_id) {
|
||||
$expense->transaction_id = $this->bt->id;
|
||||
$expense->save();
|
||||
foreach($_expenses as $_expense) {
|
||||
|
||||
$expense = Expense::withTrashed()
|
||||
->where('id', $this->decodePrimaryKey($_expense))
|
||||
->where('company_id', $this->bt->company_id)
|
||||
->first();
|
||||
|
||||
$this->bt->expense_id = $this->coalesceExpenses($expense->hashed_id);
|
||||
$this->bt->status_id = BankTransaction::STATUS_CONVERTED;
|
||||
$this->bt->vendor_id = $expense->vendor_id;
|
||||
$this->bt->ninja_category_id = $expense->category_id;
|
||||
$this->bt->save();
|
||||
if ($expense && !$expense->transaction_id) {
|
||||
$expense->transaction_id = $this->bt->id;
|
||||
$expense->save();
|
||||
|
||||
$this->bts->push($this->bt->id);
|
||||
$this->bt->expense_id = $this->coalesceExpenses($expense->hashed_id);
|
||||
$this->bt->status_id = BankTransaction::STATUS_CONVERTED;
|
||||
$this->bt->vendor_id = $expense->vendor_id;
|
||||
$this->bt->ninja_category_id = $expense->category_id;
|
||||
$this->bt->save();
|
||||
|
||||
$this->bts->push($this->bt->id);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user