Merge pull request #2408 from sevannerse/connect-split-transaction
Connect split transaction
This commit is contained in:
@ -35,7 +35,7 @@ class Transactions extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$transactions = Transaction::with('account', 'category', 'contact')->isNotRecurring()->collect(['paid_at'=> 'desc']);
|
||||
$transactions = Transaction::with('account', 'category', 'contact')->isNotRecurring()->isNotSplit()->collect(['paid_at'=> 'desc']);
|
||||
|
||||
$totals = [
|
||||
'income' => 0,
|
||||
@ -325,6 +325,45 @@ class Transactions extends Controller
|
||||
return $pdf->download($file_name);
|
||||
}
|
||||
|
||||
public function dial(Transaction $transaction)
|
||||
{
|
||||
$documents = collect([]);
|
||||
|
||||
if ($transaction->type == Transaction::INCOME_TYPE && $transaction->contact->exists) {
|
||||
$builder = $transaction->contact
|
||||
->invoices();
|
||||
}
|
||||
|
||||
if ($transaction->type == Transaction::INCOME_TYPE && ! $transaction->contact->exists) {
|
||||
$builder = Document::invoice();
|
||||
}
|
||||
|
||||
if ($transaction->type == Transaction::EXPENSE_TYPE && $transaction->contact->exists) {
|
||||
$builder = $transaction->contact
|
||||
->bills();
|
||||
}
|
||||
|
||||
if ($transaction->type == Transaction::EXPENSE_TYPE && ! $transaction->contact->exists) {
|
||||
$builder = Document::bill();
|
||||
}
|
||||
|
||||
if (isset($builder)) {
|
||||
$documents = $builder->notPaid()
|
||||
->where('currency_code', $transaction->currency_code)
|
||||
->with(['media', 'totals', 'transactions'])
|
||||
->get()
|
||||
->toJson();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'transaction' => $transaction->load(['account', 'category'])->toJson(),
|
||||
'currency' => $transaction->currency->toJson(),
|
||||
'documents' => $documents,
|
||||
];
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function connect(Transaction $transaction, TransactionConnect $request)
|
||||
{
|
||||
$total_items = count($request->data['items']);
|
||||
|
@ -190,6 +190,16 @@ class Transaction extends Model
|
||||
return $query->where($this->qualifyColumn('type'), 'not like', '%-recurring');
|
||||
}
|
||||
|
||||
public function scopeIsSplit(Builder $query): Builder
|
||||
{
|
||||
return $query->where($this->qualifyColumn('type'), 'like', '%-split');
|
||||
}
|
||||
|
||||
public function scopeIsNotSplit(Builder $query): Builder
|
||||
{
|
||||
return $query->where($this->qualifyColumn('type'), 'not like', '%-split');
|
||||
}
|
||||
|
||||
public function scopeIsTransfer(Builder $query): Builder
|
||||
{
|
||||
return $query->where('category_id', '=', Category::transfer());
|
||||
@ -470,22 +480,10 @@ class Transaction extends Model
|
||||
'permission' => 'create-banking-transactions',
|
||||
'attributes' => [
|
||||
'id' => 'index-transactions-more-actions-connect-' . $this->id,
|
||||
'@click' => 'onConnect(\'' . route('transactions.dial', $this->id) . '\')',
|
||||
],
|
||||
];
|
||||
|
||||
$transaction = $this->load('account')->toJson();
|
||||
$currency = $this->currency->toJson();
|
||||
|
||||
if ($this->contact->exists) {
|
||||
$document = $this->contact->invoices()->notPaid()->where('currency_code', $this->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson();
|
||||
|
||||
$connect['attributes']['@click'] = 'onConnect()';
|
||||
} else {
|
||||
$document = \App\Models\Document\Document::invoice()->notPaid()->where('currency_code', $this->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson();
|
||||
|
||||
$connect['attributes']['@click'] = 'onConnect()';
|
||||
}
|
||||
|
||||
$actions[] = $connect;
|
||||
|
||||
$actions[] = [
|
||||
|
Reference in New Issue
Block a user