|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Helper\DatabaseHelper;
|
|
|
|
use App\Helper\DatabaseHelper;
|
|
|
|
use App\Helper\JSONResponse;
|
|
|
|
use App\Helper\JSONResponse;
|
|
|
|
use App\Helper\STS\Indokargo;
|
|
|
|
use App\Helper\STS\Indokargo;
|
|
|
|
@ -70,11 +71,17 @@ class Tv extends Model {
|
|
|
|
...DatabaseHelper::getOrderBysValidations(),
|
|
|
|
...DatabaseHelper::getOrderBysValidations(),
|
|
|
|
'search' => DatabaseHelper::getSearchValidation(),
|
|
|
|
'search' => DatabaseHelper::getSearchValidation(),
|
|
|
|
'apkVersionCode' => 'nullable|integer',
|
|
|
|
'apkVersionCode' => 'nullable|integer',
|
|
|
|
|
|
|
|
'tz' => 'required|timezone',
|
|
|
|
'isActive' => 'nullable|boolean',
|
|
|
|
'isActive' => 'nullable|boolean',
|
|
|
|
|
|
|
|
'installedAt' => 'nullable|array',
|
|
|
|
|
|
|
|
'installedAt.from' => 'nullable|date',
|
|
|
|
|
|
|
|
'installedAt.to' => 'nullable|date',
|
|
|
|
'lastConnectedAt' => 'nullable|array',
|
|
|
|
'lastConnectedAt' => 'nullable|array',
|
|
|
|
'lastConnectedAt.from' => 'nullable|date',
|
|
|
|
'lastConnectedAt.from' => 'nullable|date',
|
|
|
|
'lastConnectedAt.to' => 'nullable|date'
|
|
|
|
'lastConnectedAt.to' => 'nullable|date',
|
|
|
|
|
|
|
|
'lastConnectedDay' => 'nullable|int'
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
Common::setTimezone($request->tz);
|
|
|
|
|
|
|
|
|
|
|
|
return Tv::when($request->isActive != null, function($q) use($request) {
|
|
|
|
return Tv::when($request->isActive != null, function($q) use($request) {
|
|
|
|
$q->where('is_active', $request->isActive);
|
|
|
|
$q->where('is_active', $request->isActive);
|
|
|
|
@ -82,6 +89,12 @@ class Tv extends Model {
|
|
|
|
->when($request->apkVersionCode, function($q, $apkVersionCode) {
|
|
|
|
->when($request->apkVersionCode, function($q, $apkVersionCode) {
|
|
|
|
$q->where('apk_version_code', $apkVersionCode);
|
|
|
|
$q->where('apk_version_code', $apkVersionCode);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
->when($request->installedAt['from'] ?? '', function($q, $from) {
|
|
|
|
|
|
|
|
$q->where(DB::raw('DATE(installed_at)'), '>=', $from);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
->when($request->installedAt['to'] ?? '', function($q, $to) {
|
|
|
|
|
|
|
|
$q->where(DB::raw('DATE(installed_at)'), '<=', $to);
|
|
|
|
|
|
|
|
})
|
|
|
|
->when($request->lastConnectedAt['from'] ?? '', function($q, $from) {
|
|
|
|
->when($request->lastConnectedAt['from'] ?? '', function($q, $from) {
|
|
|
|
$q->where(DB::raw('DATE(last_connected_at)'), '>=', $from);
|
|
|
|
$q->where(DB::raw('DATE(last_connected_at)'), '>=', $from);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -178,12 +191,7 @@ class Tv extends Model {
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------
|
|
|
|
// -- RELATED TO EXCEL
|
|
|
|
// -- RELATED TO EXCEL
|
|
|
|
public static function getExcelDetail(Request $request) {
|
|
|
|
public static function getExcelDetail(Request $request) {
|
|
|
|
$cols = ['code', 'apk_version_code', 'apk_version_name', 'installed_at', 'last_connected_at',
|
|
|
|
return JSONResponse::Success(['rows' => TV::validateAndGetEloquentFromRequest($request)->get()]);
|
|
|
|
'company_name', 'address', 'street_address', 'notes',
|
|
|
|
|
|
|
|
'col1', 'col2', 'col3', 'col4', 'col5',
|
|
|
|
|
|
|
|
'col6', 'col7', 'col8', 'col9', 'col10',
|
|
|
|
|
|
|
|
'is_active'];
|
|
|
|
|
|
|
|
return JSONResponse::Success(['rows' => TV::validateAndGetEloquentFromRequest($request)->select(...$cols)->get()]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---- RELATED TO EXPORT IMPORT
|
|
|
|
// ---- RELATED TO EXPORT IMPORT
|
|
|
|
@ -202,8 +210,8 @@ class Tv extends Model {
|
|
|
|
return JSONResponse::Success(['rows' => $rows]);
|
|
|
|
return JSONResponse::Success(['rows' => $rows]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static function getExportData(Request $request) {
|
|
|
|
public static function getExportData(Request $request) {
|
|
|
|
$rows = TV::validateAndGetEloquentFromRequest($request)->select(...self::EXCEL_TEMPLATE_COLS)->get();
|
|
|
|
$rows = TV::validateAndGetEloquentFromRequest($request)->get();
|
|
|
|
return JSONResponse::Success(['rows' => $rows]);
|
|
|
|
return JSONResponse::Success(['rows' => $rows, 'cols' => self::EXCEL_TEMPLATE_COLS]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ------ RELATED TO IMPORT
|
|
|
|
// ------ RELATED TO IMPORT
|
|
|
|
private static function _checkExcelFormat($tvRows) {
|
|
|
|
private static function _checkExcelFormat($tvRows) {
|
|
|
|
|