Search.php
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace App\Http\Controllers\Common;
use App\Http\Controllers\Controller;
use App\Models\Banking\Account;
use App\Models\Expense\Bill;
use App\Models\Expense\Payment;
use App\Models\Expense\Vendor;
use App\Models\Income\Invoice;
use App\Models\Income\Revenue;
use App\Models\Income\Customer;
use App\Models\Common\Item;
class Search extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$items = Item::enabled()->with('category')->get()->sortBy('name');
return view('items.items.index', compact('items'));
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function search()
{
$results = array();
$keyword = request('keyword');
$accounts = Account::enabled()->search($keyword)->get();
if ($accounts->count()) {
foreach ($accounts as $account) {
$results[] = (object)[
'id' => $account->id,
'name' => $account->name,
'type' => trans_choice('general.accounts', 1),
'color' => '#337ab7',
'href' => url('banking/accounts/' . $account->id . '/edit'),
];
}
}
$items = Item::enabled()->search($keyword)->get();
if ($items->count()) {
foreach ($items as $item) {
$results[] = (object)[
'id' => $item->id,
'name' => $item->name,
'type' => trans_choice('general.items', 1),
'color' => '#f5bd65',
'href' => url('common/items/' . $item->id . '/edit'),
];
}
}
$invoices = Invoice::search($keyword)->get();
if ($invoices->count()) {
foreach ($invoices as $invoice) {
$results[] = (object)[
'id' => $invoice->id,
'name' => $invoice->invoice_number . ' - ' . $invoice->customer_name,
'type' => trans_choice('general.invoices', 1),
'color' => '#00c0ef',
'href' => url('incomes/invoices/' . $invoice->id),
];
}
}
//$revenues = Revenue::search($keyword)->get();
$customers = Customer::enabled()->search($keyword)->get();
if ($customers->count()) {
foreach ($customers as $customer) {
$results[] = (object)[
'id' => $customer->id,
'name' => $customer->name,
'type' => trans_choice('general.customers', 1),
'color' => '#03d876',
'href' => url('incomes/customers/' . $customer->id),
];
}
}
$bills = Bill::search($keyword)->get();
if ($bills->count()) {
foreach ($bills as $bill) {
$results[] = (object)[
'id' => $bill->id,
'name' => $bill->bill_number . ' - ' . $bill->vendor_name,
'type' => trans_choice('general.bills', 1),
'color' => '#dd4b39',
'href' => url('expenses/bills/' . $bill->id),
];
}
}
//$payments = Payment::search($keyword)->get();
$vendors = Vendor::enabled()->search($keyword)->get();
if ($vendors->count()) {
foreach ($vendors as $vendor) {
$results[] = (object)[
'id' => $vendor->id,
'name' => $vendor->name,
'type' => trans_choice('general.vendors', 1),
'color' => '#ff8373',
'href' => url('expenses/vendors/' . $vendor->id),
];
}
}
return response()->json((object) $results);
}
}