Merge pull request #1182 from openclassify/dia

#2480 Sales Reports
This commit is contained in:
spektra2147 2021-10-04 09:58:29 +03:00 committed by GitHub
commit 3ae16acf24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 169 additions and 49 deletions

View File

@ -1,6 +1,16 @@
$(document).ready( function () {
$('#stockReport').DataTable({
ajax: '/admin/api/classified/report/stock',
ajax: {
url: '/admin/api/classified/report/stock',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
order: [[ 1, "asc" ]],
columns: [
{
@ -26,7 +36,17 @@ $(document).ready( function () {
});
$('#unexplainedReport').DataTable({
ajax: '/admin/api/classified/report/unexplained',
ajax: {
url: '/admin/api/classified/report/unexplained',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'name',
@ -42,7 +62,17 @@ $(document).ready( function () {
});
$('#noImageReport').DataTable({
ajax: '/admin/api/classified/report/no-image',
ajax: {
url: '/admin/api/classified/report/no-image',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'name',
@ -58,7 +88,17 @@ $(document).ready( function () {
});
$('#metaPageReport').DataTable({
ajax: '/admin/api/classified/report/page',
ajax: {
url: '/admin/api/classified/report/page',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
columns: [
{
data: 'name',

View File

@ -542,7 +542,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
return $query
->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))
->where('status', '=', 'approved')
->where('slug', '!=', '')
->orderBy('publish_at', 'desc');
->where('slug', '!=', '');
}
}

View File

@ -603,16 +603,28 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
public function getStockReport()
{
return $this->newQuery()
$classifieds = $this->newQuery()
->current()
->select('stock', 'name', 'advs_advs.id', 'slug')
->where('is_get_adv', true)
->where('stock', '<=', 10)
->leftJoin('advs_advs_translations as classified_trans', function ($join) {
$join->on('advs_advs.id', '=', 'classified_trans.entry_id');
$join->whereIn('locale', [config('app.locale'), setting_value('streams::default_locale'), 'en']);
})
->get();
});
if ($search = request('search.value')) {
$classifieds = $classifieds->where('name', 'LIKE', "%$search%");
}
if ($orderDir = request('order.0.dir')) {
$classifieds = $classifieds->orderBy(request('order.0.column') == 1 ? 'stock' : 'name', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $classifieds->paginate($limit, ['*'], 'page', $page);
}
public function getAllClassifiedsCount()
@ -630,25 +642,38 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
public function getUnexplainedClassifiedsReport()
{
return $this->newQuery()
$classifieds = $this->newQuery()
->current()
->select('name', 'advs_advs.id', 'slug')
->select('classified_trans.name', 'advs_advs.id', 'slug')
->where(function ($query) {
$query->where('advs_desc', '=', '')
->orWhereNull('advs_desc');
$query->where('classified_trans.advs_desc', '=', '')
->orWhereNull('classified_trans.advs_desc');
})
->leftJoin('advs_advs_translations as classified_trans', function ($join) {
$join->on('advs_advs.id', '=', 'classified_trans.entry_id');
$join->whereIn('locale', [config('app.locale'), setting_value('streams::default_locale'), 'en']);
})
->get();
});
if ($search = request('search.value')) {
$classifieds = $classifieds->where('classified_trans.name', 'LIKE', "%$search%");
}
if ($orderDir = request('order.0.dir')) {
$classifieds = $classifieds->orderBy('name', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $classifieds->paginate($limit, ['*'], 'page', $page);
}
public function getNoImageClassifiedsReport()
{
return $this->newQuery()
$classifieds = $this->newQuery()
->current()
->select('name', 'advs_advs.id', 'slug')
->select('classified_trans.name', 'advs_advs.id', 'slug')
->where(function ($query) {
$query->where('cover_photo', '=', '')
->orWhereNull('cover_photo');
@ -656,7 +681,20 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
->leftJoin('advs_advs_translations as classified_trans', function ($join) {
$join->on('advs_advs.id', '=', 'classified_trans.entry_id');
$join->whereIn('locale', [config('app.locale'), setting_value('streams::default_locale'), 'en']);
})
->get();
});
if ($search = request('search.value')) {
$classifieds = $classifieds->where('classified_trans.name', 'LIKE', "%$search%");
}
if ($orderDir = request('order.0.dir')) {
$classifieds = $classifieds->orderBy('name', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $classifieds->paginate($limit, ['*'], 'page', $page);
}
}

View File

@ -16,9 +16,7 @@ class ReportController extends AdminController
public function stock()
{
return [
'data' => $this->advRepository->getStockReport()
];
return $this->advRepository->getStockReport();
}
public function status()
@ -42,16 +40,12 @@ class ReportController extends AdminController
public function unexplained()
{
return [
'data' => $this->advRepository->getUnexplainedClassifiedsReport()
];
return $this->advRepository->getUnexplainedClassifiedsReport();
}
public function noImage()
{
return [
'data' => $this->advRepository->getNoImageClassifiedsReport()
];
return $this->advRepository->getNoImageClassifiedsReport();
}
public function page(PageRepositoryInterface $pageRepository)
@ -65,11 +59,20 @@ class ReportController extends AdminController
->leftJoin('pages_pages_translations as pages_trans', function ($join) {
$join->on('pages_pages.id', '=', 'pages_trans.entry_id');
$join->whereIn('locale', [config('app.locale'), setting_value('streams::default_locale'), 'en']);
})
->get();
});
return [
'data' => $pages
];
if ($search = request('search.value')) {
$pages = $pages->where('title', 'LIKE', "%$search%");
}
if ($orderDir = request('order.0.dir')) {
$pages = $pages->orderBy('title', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $pages->paginate($limit, ['*'], 'page', $page);
}
}

View File

@ -1,7 +1,16 @@
$(document).ready( function () {
$('#newMemberReport').DataTable({
ajax: '/admin/api/profile/report/latest',
order: [[ 1, "desc" ]],
ajax: {
url: '/admin/api/profile/report/latest',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
columns: [
{ data: 'member', defaultContent: usersReportTrans.undefined_member },
{ data: 'date' },
@ -9,8 +18,17 @@ $(document).ready( function () {
});
$('#loginMemberReport').DataTable({
ajax: '/admin/api/profile/report/login',
order: [[ 1, "desc" ]],
ajax: {
url: '/admin/api/profile/report/login',
dataSrc( json ) {
json.recordsTotal = json.total;
json.recordsFiltered = json.total;
return json.data;
}
},
processing: true,
serverSide: true,
columns: [
{ data: 'member', defaultContent: usersReportTrans.undefined_member },
{ data: 'date' },

View File

@ -17,13 +17,24 @@ class ReportController extends AdminController
public function latest()
{
$members = $this->userRepository->newQuery()
->selectRaw("DATE_FORMAT(created_at, '%d.%m.%Y %H:%i') as date, CONCAT_WS('', first_name, ' ', last_name) AS member")
->where('created_at', '>=', Carbon::today()->subWeek())
->get();
->selectRaw("DATE_FORMAT(created_at, '%d.%m.%Y %H:%i') as date, CONCAT_WS('', first_name, ' ', last_name) AS member, id AS user_id")
->where('created_at', '>=', Carbon::today()->subWeek());
return [
'data' => $members
];
if ($search = request('search.value')) {
$members = $members->whereRaw("
(SELECT CONCAT_WS('', first_name, ' ', last_name) AS member) LIKE '%$search%'
");
}
if ($orderDir = request('order.0.dir')) {
$members = $members->orderBy('member', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $members->paginate($limit, ['*'], 'page', $page);
}
public function login()
@ -31,11 +42,22 @@ class ReportController extends AdminController
$members = $this->userRepository->newQuery()
->selectRaw("DATE_FORMAT(last_login_at, '%d.%m.%Y %H:%i') as date, CONCAT_WS('', first_name, ' ', last_name) AS member")
->whereNotNull('last_login_at')
->where('last_login_at', '>=', Carbon::today()->subWeek())
->get();
->where('last_login_at', '>=', Carbon::today()->subWeek());
return [
'data' => $members
];
if ($search = request('search.value')) {
$members = $members->whereRaw("
(SELECT CONCAT_WS('', first_name, ' ', last_name) AS member) LIKE '%$search%'
");
}
if ($orderDir = request('order.0.dir')) {
$members = $members->orderBy('member', $orderDir);
}
$start = request('start');
$limit = request('length') ?: 10;
$page = $start ? $start / $limit + 1 : 1;
return $members->paginate($limit, ['*'], 'page', $page);
}
}