2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
2018-06-10 02:48:51 +03:00
|
|
|
namespace App\Http\Controllers\Common;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Abstracts\Http\Controller;
|
2017-09-14 22:21:00 +03:00
|
|
|
use App\Models\Banking\Account;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Banking\Transaction;
|
|
|
|
use App\Models\Common\Contact;
|
2019-12-31 15:49:09 +03:00
|
|
|
use App\Models\Purchase\Bill;
|
|
|
|
use App\Models\Sale\Invoice;
|
2018-06-10 02:48:51 +03:00
|
|
|
use App\Models\Common\Item;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Traits\Contacts;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
class Search extends Controller
|
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
use Contacts;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
2019-11-16 10:21:14 +03:00
|
|
|
public function index()
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
|
|
|
$results = array();
|
|
|
|
|
|
|
|
$keyword = request('keyword');
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$accounts = Account::enabled()->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($accounts->count()) {
|
|
|
|
foreach ($accounts as $account) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $account->id,
|
|
|
|
'name' => $account->name,
|
|
|
|
'type' => trans_choice('general.accounts', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#55588b',
|
2017-09-14 22:21:00 +03:00
|
|
|
'href' => url('banking/accounts/' . $account->id . '/edit'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$items = Item::enabled()->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($items->count()) {
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $item->id,
|
|
|
|
'name' => $item->name,
|
|
|
|
'type' => trans_choice('general.items', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#efad32',
|
2018-06-27 19:59:22 +03:00
|
|
|
'href' => url('common/items/' . $item->id . '/edit'),
|
2017-09-14 22:21:00 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$invoices = Invoice::usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($invoices->count()) {
|
|
|
|
foreach ($invoices as $invoice) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $invoice->id,
|
2019-11-16 10:21:14 +03:00
|
|
|
'name' => $invoice->invoice_number . ' - ' . $invoice->contact_name,
|
2017-09-14 22:21:00 +03:00
|
|
|
'type' => trans_choice('general.invoices', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#6da252',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('sales/invoices/' . $invoice->id),
|
2017-09-14 22:21:00 +03:00
|
|
|
];
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}/*
|
|
|
|
|
2019-11-27 12:08:36 +03:00
|
|
|
$income_transactions = Transaction::type('income')->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-27 12:08:36 +03:00
|
|
|
if ($income_transactions->count()) {
|
|
|
|
foreach ($income_transactions as $transaction) {
|
2019-11-16 10:21:14 +03:00
|
|
|
$results[] = (object)[
|
2019-11-27 12:08:36 +03:00
|
|
|
'id' => $transaction->id,
|
|
|
|
'name' => $transaction->contact_name,
|
2019-11-16 10:21:14 +03:00
|
|
|
'type' => trans_choice('general.revenues', 1),
|
|
|
|
'color' => '#00c0ef',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('sales/revenues/' . $transaction->id),
|
2019-11-16 10:21:14 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}*/
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$customers = Contact::type($this->getCustomerTypes())->enabled()->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($customers->count()) {
|
|
|
|
foreach ($customers as $customer) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $customer->id,
|
|
|
|
'name' => $customer->name,
|
|
|
|
'type' => trans_choice('general.customers', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#328aef',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('sales/customers/' . $customer->id),
|
2017-09-14 22:21:00 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$bills = Bill::usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($bills->count()) {
|
|
|
|
foreach ($bills as $bill) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $bill->id,
|
2019-11-16 10:21:14 +03:00
|
|
|
'name' => $bill->bill_number . ' - ' . $bill->contact_name,
|
2017-09-14 22:21:00 +03:00
|
|
|
'type' => trans_choice('general.bills', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#ef3232',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('purchases/bills/' . $bill->id),
|
2017-09-14 22:21:00 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
/*
|
|
|
|
$payments = Transaction::type('expense')->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
if ($revenues->count()) {
|
|
|
|
foreach ($revenues as $revenue) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $revenue->id,
|
|
|
|
'name' => $revenue->contact_name,
|
|
|
|
'type' => trans_choice('general.revenues', 1),
|
|
|
|
'color' => '#00c0ef',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('sales/revenues/' . $revenue->id),
|
2019-11-16 10:21:14 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}*/
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
$vendors = Contact::type($this->getVendorTypes())->enabled()->usingSearchString($keyword)->get();
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
if ($vendors->count()) {
|
|
|
|
foreach ($vendors as $vendor) {
|
|
|
|
$results[] = (object)[
|
|
|
|
'id' => $vendor->id,
|
|
|
|
'name' => $vendor->name,
|
|
|
|
'type' => trans_choice('general.vendors', 1),
|
2019-11-16 10:21:14 +03:00
|
|
|
'color' => '#efef32',
|
2019-12-31 15:49:09 +03:00
|
|
|
'href' => url('purchases/vendors/' . $vendor->id),
|
2017-09-14 22:21:00 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json((object) $results);
|
|
|
|
}
|
|
|
|
}
|