chore: adjust for filter TV

v2.0.0
ricky rx 1 year ago
parent 3ff470bc55
commit 2ed57016bc

@ -2,6 +2,8 @@
namespace App\Helper;
use Illuminate\Support\Facades\DB;
class Common {
public static function convertRequestConfig(?array $requestConfig): array {
$config = [];
@ -26,4 +28,9 @@ class Common {
public static function trueOrFalse(mixed $value): bool {
return ($value === "true" || $value === "1" || $value === 1 || $value === true) ? true : false;
}
public static function setTimezone($timezone) {
date_default_timezone_set($timezone);
DB::statement("SET TIME ZONE '$timezone'");
}
}

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

Loading…
Cancel
Save