Initial commit
This commit is contained in:
15
.editorconfig
Executable file
15
.editorconfig
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
5
.gitattributes
vendored
Executable file
5
.gitattributes
vendored
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
* text=auto
|
||||||
|
*.css linguist-vendored
|
||||||
|
*.scss linguist-vendored
|
||||||
|
*.js linguist-vendored
|
||||||
|
CHANGELOG.md export-ignore
|
||||||
15
.gitignore
vendored
Executable file
15
.gitignore
vendored
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
/node_modules
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
storage/*.key
|
||||||
|
/vendor
|
||||||
|
/storage/fonts
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
.vscode
|
||||||
|
.DS_Store
|
||||||
31
.prettierrc
Normal file
31
.prettierrc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["@prettier/plugin-php"],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.php"],
|
||||||
|
"options": {
|
||||||
|
"trailingComma": "none",
|
||||||
|
"printWidth": 110,
|
||||||
|
"proseWrap": "always",
|
||||||
|
"singleQuote": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.blade.php"],
|
||||||
|
"options": {
|
||||||
|
"parser": "blade",
|
||||||
|
"tabWidth": 1,
|
||||||
|
"useTabs": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.js"],
|
||||||
|
"options": {
|
||||||
|
"trailingComma": "none",
|
||||||
|
"printWidth": 110,
|
||||||
|
"proseWrap": "always",
|
||||||
|
"tabWidth": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
13
.styleci.yml
Executable file
13
.styleci.yml
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
php:
|
||||||
|
preset: laravel
|
||||||
|
disabled:
|
||||||
|
- unused_use
|
||||||
|
finder:
|
||||||
|
not-name:
|
||||||
|
- index.php
|
||||||
|
- server.php
|
||||||
|
js:
|
||||||
|
finder:
|
||||||
|
not-name:
|
||||||
|
- webpack.mix.js
|
||||||
|
css: true
|
||||||
39
Dockerfile
Executable file
39
Dockerfile
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#stage 0
|
||||||
|
FROM php:7.2-fpm-alpine
|
||||||
|
|
||||||
|
WORKDIR /var/www/html/trucking
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apk --update add \
|
||||||
|
curl \
|
||||||
|
openssl \
|
||||||
|
libpng-dev \
|
||||||
|
libxml2-dev \
|
||||||
|
libzip-dev \
|
||||||
|
curl-dev \
|
||||||
|
oniguruma-dev
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
RUN apk del gcc g++
|
||||||
|
RUN rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# Install PHP extensions
|
||||||
|
RUN docker-php-ext-install bcmath curl gd exif mbstring mysqli pdo pdo_mysql pcntl xml zip
|
||||||
|
|
||||||
|
# Get latest Composer
|
||||||
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
COPY ./ /var/www/html/trucking
|
||||||
|
|
||||||
|
RUN composer install \
|
||||||
|
--ignore-platform-reqs \
|
||||||
|
--no-interaction \
|
||||||
|
--no-plugins \
|
||||||
|
--no-scripts \
|
||||||
|
--prefer-dist
|
||||||
|
|
||||||
|
RUN chmod -R 777 storage/logs/ && chmod -R 777 storage/framework/
|
||||||
|
|
||||||
|
RUN cp -R vendor /vendor
|
||||||
|
|
||||||
|
# BELOM SUPPORT KIRIM EMAIL
|
||||||
41
app/Console/Kernel.php
Executable file
41
app/Console/Kernel.php
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console;
|
||||||
|
|
||||||
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
|
class Kernel extends ConsoleKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The Artisan commands provided by your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $commands = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the application's command schedule.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function schedule(Schedule $schedule)
|
||||||
|
{
|
||||||
|
// $schedule->command('inspire')->hourly();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the commands for the application.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function commands()
|
||||||
|
{
|
||||||
|
$this->load(__DIR__.'/Commands');
|
||||||
|
|
||||||
|
require base_path('routes/console.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
55
app/Exceptions/Handler.php
Executable file
55
app/Exceptions/Handler.php
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class Handler extends ExceptionHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A list of the exception types that are not reported.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontReport = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of the inputs that are never flashed for validation exceptions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontFlash = [
|
||||||
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report or log an exception.
|
||||||
|
*
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function report(Throwable $exception)
|
||||||
|
{
|
||||||
|
parent::report($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Throwable $exception
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function render($request, Throwable $exception)
|
||||||
|
{
|
||||||
|
return parent::render($request, $exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
358
app/Helper.php
Executable file
358
app/Helper.php
Executable file
@ -0,0 +1,358 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use App\Models\OrdersInvoices;
|
||||||
|
|
||||||
|
class Helper
|
||||||
|
{
|
||||||
|
|
||||||
|
const EARTH_RADIUS_M = 6371000;
|
||||||
|
const EARTH_RADIUS_KM = 6371;
|
||||||
|
const EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the great-circle distance between two points, with
|
||||||
|
* the Haversine formula.
|
||||||
|
* @param float $latitudeFrom Latitude of start point in [deg decimal]
|
||||||
|
* @param float $longitudeFrom Longitude of start point in [deg decimal]
|
||||||
|
* @param float $latitudeTo Latitude of target point in [deg decimal]
|
||||||
|
* @param float $longitudeTo Longitude of target point in [deg decimal]
|
||||||
|
* @param float $earthRadius Mean earth radius in [m]
|
||||||
|
* @return float Distance between points in [m] (same as earthRadius)
|
||||||
|
* reference: https://stackoverflow.com/questions/14750275/haversine-formula-with-php
|
||||||
|
* tolak ukur: tarik garis lurus
|
||||||
|
* miles: 3958.756 || 3959
|
||||||
|
* km: 6371
|
||||||
|
* meters: 6371000
|
||||||
|
* more accurate using km/meters than miles i think ~ rafifmulia
|
||||||
|
*/
|
||||||
|
public static function haversineGreatCircleDistance(
|
||||||
|
$latitudeFrom,
|
||||||
|
$longitudeFrom,
|
||||||
|
$latitudeTo,
|
||||||
|
$longitudeTo,
|
||||||
|
$earthRadius = self::EARTH_RADIUS_M
|
||||||
|
) {
|
||||||
|
// convert from degrees to radians
|
||||||
|
$latFrom = deg2rad($latitudeFrom);
|
||||||
|
$lonFrom = deg2rad($longitudeFrom);
|
||||||
|
$latTo = deg2rad($latitudeTo);
|
||||||
|
$lonTo = deg2rad($longitudeTo);
|
||||||
|
|
||||||
|
$latDelta = $latTo - $latFrom;
|
||||||
|
$lonDelta = $lonTo - $lonFrom;
|
||||||
|
|
||||||
|
$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
|
||||||
|
$distance = $angle * $earthRadius;
|
||||||
|
|
||||||
|
return $distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function arccosineGreatCircleDistance(
|
||||||
|
$latitudeFrom,
|
||||||
|
$longitudeFrom,
|
||||||
|
$latitudeTo,
|
||||||
|
$longitudeTo,
|
||||||
|
$earthRadius = 6371000
|
||||||
|
) {
|
||||||
|
return ($earthRadius * acos((cos(deg2rad($latitudeFrom))) * (cos(deg2rad($latitudeTo))) * (cos(deg2rad($longitudeTo) - deg2rad($longitudeFrom))) + ((sin(deg2rad($latitudeFrom))) * (sin(deg2rad($latitudeTo))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createPayload($array)
|
||||||
|
{
|
||||||
|
$string = '';
|
||||||
|
|
||||||
|
foreach ($array as $key => $val) {
|
||||||
|
if (is_array($val)) {
|
||||||
|
self::createPayload($val);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$string .= $key . '=' . $val . '&';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function req_post($url, $headers, $payload)
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_HEADER => false,
|
||||||
|
CURLOPT_HTTPHEADER => $headers,
|
||||||
|
CURLOPT_POST => 1,
|
||||||
|
CURLOPT_POSTFIELDS => $payload,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
// CURLOPT_FAILONERROR => true,
|
||||||
|
];
|
||||||
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'type' => 'error',
|
||||||
|
'message' => curl_error($ch)
|
||||||
|
];
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$result = ['type' => 'success'];
|
||||||
|
try {
|
||||||
|
$data = json_decode($resp);
|
||||||
|
|
||||||
|
if (json_last_error() == JSON_ERROR_NONE) {
|
||||||
|
$result['data'] = $data;
|
||||||
|
} else {
|
||||||
|
$result['data'] = $resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$result['data'] = $resp;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function req_get($url, $headers)
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_HTTPHEADER => $headers,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
// CURLOPT_FAILONERROR => true,
|
||||||
|
];
|
||||||
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
|
$resp = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
$result = [
|
||||||
|
'type' => 'error',
|
||||||
|
'message' => curl_error($ch)
|
||||||
|
];
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
$result = ['type' => 'success'];
|
||||||
|
try {
|
||||||
|
$data = json_decode($resp);
|
||||||
|
|
||||||
|
if (json_last_error() == JSON_ERROR_NONE) {
|
||||||
|
$result['data'] = $data;
|
||||||
|
} else {
|
||||||
|
$result['data'] = $resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$result['data'] = $resp;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listBloods()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'id' => 'A',
|
||||||
|
'name' => 'A',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'A+',
|
||||||
|
'name' => 'A+',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'B',
|
||||||
|
'name' => 'B',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'B+',
|
||||||
|
'name' => 'B+',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'O',
|
||||||
|
'name' => 'O',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'O+',
|
||||||
|
'name' => 'O+',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'AB',
|
||||||
|
'name' => 'AB',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'AB+',
|
||||||
|
'name' => 'AB+',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function countAge($date_ymd)
|
||||||
|
{
|
||||||
|
$then = date('Ymd', strtotime($date_ymd));
|
||||||
|
$diff = date('Ymd') - $then;
|
||||||
|
return (int) substr($diff, 0, -4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function terbilang($nilai)
|
||||||
|
{
|
||||||
|
function penyebut($nilai) {
|
||||||
|
$nilai = abs($nilai);
|
||||||
|
$huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
|
||||||
|
$temp = "";
|
||||||
|
if ($nilai < 12) {
|
||||||
|
$temp = " ". $huruf[$nilai];
|
||||||
|
} else if ($nilai <20) {
|
||||||
|
$temp = penyebut($nilai - 10). " belas";
|
||||||
|
} else if ($nilai < 100) {
|
||||||
|
$temp = penyebut($nilai/10)." puluh". penyebut($nilai % 10);
|
||||||
|
} else if ($nilai < 200) {
|
||||||
|
$temp = " seratus" . penyebut($nilai - 100);
|
||||||
|
} else if ($nilai < 1000) {
|
||||||
|
$temp = penyebut($nilai/100) . " ratus" . penyebut($nilai % 100);
|
||||||
|
} else if ($nilai < 2000) {
|
||||||
|
$temp = " seribu" . penyebut($nilai - 1000);
|
||||||
|
} else if ($nilai < 1000000) {
|
||||||
|
$temp = penyebut($nilai/1000) . " ribu" . penyebut($nilai % 1000);
|
||||||
|
} else if ($nilai < 1000000000) {
|
||||||
|
$temp = penyebut($nilai/1000000) . " juta" . penyebut($nilai % 1000000);
|
||||||
|
} else if ($nilai < 1000000000000) {
|
||||||
|
$temp = penyebut($nilai/1000000000) . " milyar" . penyebut(fmod($nilai,1000000000));
|
||||||
|
} else if ($nilai < 1000000000000000) {
|
||||||
|
$temp = penyebut($nilai/1000000000000) . " trilyun" . penyebut(fmod($nilai,1000000000000));
|
||||||
|
}
|
||||||
|
return $temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($nilai < 0) {
|
||||||
|
$hasil = "minus " . trim(penyebut($nilai));
|
||||||
|
} else {
|
||||||
|
$hasil = trim(penyebut($nilai));
|
||||||
|
}
|
||||||
|
return $hasil;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function lastDigitYear()
|
||||||
|
{
|
||||||
|
// 2023 => 3
|
||||||
|
return substr(date('Y'), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function weekNumOfYear()
|
||||||
|
{
|
||||||
|
// 27 jul 2022 => 30
|
||||||
|
return date('W');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dayOfWeek()
|
||||||
|
{
|
||||||
|
// monday => 01, sunday => 07
|
||||||
|
return date('N');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function gnrtOrdCode($type) {
|
||||||
|
$ord_code = '';
|
||||||
|
$ord_code .= $type;
|
||||||
|
$ord_code .= Helper::lastDigitYear() . Helper::weekNumOfYear() . Helper::dayOfWeek();
|
||||||
|
// above before running number
|
||||||
|
$likeCode = \App\Models\Orders::getOrderLikeCode($ord_code);
|
||||||
|
// below after running number
|
||||||
|
if (count($likeCode) < 1 || $likeCode === false) {
|
||||||
|
$ord_code .= '001';
|
||||||
|
} else {
|
||||||
|
if ($likeCode[0]->total < 1) {
|
||||||
|
$ord_code .= '001';
|
||||||
|
} else {
|
||||||
|
$ord_code .= str_pad($likeCode[0]->total + 1, 3, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ord_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function gnrtInvcCode($ord_code) {
|
||||||
|
$invc_code = '';
|
||||||
|
$type = substr($ord_code, 0, 1);
|
||||||
|
$invc_code .= Helper::lastDigitYear() . Helper::weekNumOfYear() . $type;
|
||||||
|
$first_invc_code = $invc_code;
|
||||||
|
// above before running number
|
||||||
|
$likeCode = \App\Models\OrdersInvoices::getLikeCode($invc_code);
|
||||||
|
// below after running number
|
||||||
|
if (count($likeCode) < 1 || $likeCode === false) {
|
||||||
|
$invc_code .= '001';
|
||||||
|
} else {
|
||||||
|
if ($likeCode[0]->total < 1) {
|
||||||
|
$invc_code .= '001';
|
||||||
|
} else {
|
||||||
|
$invc_code .= str_pad($likeCode[0]->total + 1, 3, '0', STR_PAD_LEFT);
|
||||||
|
$checkCode = OrdersInvoices::getByCode($invc_code);
|
||||||
|
if (count($checkCode) > 0) {
|
||||||
|
$invc_code = $first_invc_code;
|
||||||
|
$lastRN = OrdersInvoices::getLikeCodeLastRunningNumber($invc_code);
|
||||||
|
$newRN = (int)substr($lastRN[0]->code, -3);
|
||||||
|
$invc_code .= str_pad($newRN + 1, 3, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $invc_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function viewBillFncIsEnableBtn($prev_termin, $curr_termin)
|
||||||
|
{
|
||||||
|
if ($curr_termin->termin_ddln_type === \App\Models\OrdersTermins::DDLN_TERMIN_TYPE_ORD_FINISH) {
|
||||||
|
if ($curr_termin->drop_chk_at === 0) {
|
||||||
|
// Menunggu Pengantaran Selesai
|
||||||
|
// return 0;
|
||||||
|
if ($prev_termin->termin_is_paid === \App\Models\OrdersTermins::IS_PAID_YES) {
|
||||||
|
// Termin sebelumnya selesai dan show btn invoice
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
// Menunggu Pengantaran Selesai
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($curr_termin->termin_is_paid === \App\Models\OrdersTermins::IS_PAID_YES) {
|
||||||
|
// invoice close
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
if ($prev_termin !== 0 && $prev_termin->termin_is_paid === \App\Models\OrdersTermins::IS_PAID_NO) {
|
||||||
|
// Termin sebelumnya belum terkonfirmasi selesai
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
// Pengantaran Selesai pada and show btn invoice
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($curr_termin->termin_is_paid === \App\Models\OrdersTermins::IS_PAID_YES) {
|
||||||
|
// invoice close
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
if ($prev_termin !== 0 && $prev_termin->termin_is_paid === \App\Models\OrdersTermins::IS_PAID_NO) {
|
||||||
|
// Termin sebelumnya belum terkonfirmasi selesai
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
// show btn invoice
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function changeIpToDomain($fullurl)
|
||||||
|
{
|
||||||
|
$replace = $fullurl;
|
||||||
|
if (!strpos($fullurl, env('ORI_IP')) === false) {
|
||||||
|
$replace = str_replace(env('ORI_IP'), env('ORI_DOMAIN'), $replace);
|
||||||
|
}
|
||||||
|
return $replace;
|
||||||
|
}
|
||||||
|
}
|
||||||
289
app/Http/Controllers/AItemsController.php
Executable file
289
app/Http/Controllers/AItemsController.php
Executable file
@ -0,0 +1,289 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\AItems;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\OrdersAItems;
|
||||||
|
use App\Models\UnitTypes;
|
||||||
|
|
||||||
|
class AItemsController extends Controller
|
||||||
|
{
|
||||||
|
public function view_a_items(Request $req)
|
||||||
|
{
|
||||||
|
$unitTypes = UnitTypes::listUnitTypes(['is_active' => UnitTypes::IS_ACTIVE, 'is_publish' => UnitTypes::IS_PUBLISH]);
|
||||||
|
$data = [
|
||||||
|
'unitTypes' => $unitTypes,
|
||||||
|
'user' => $req->auth,
|
||||||
|
];
|
||||||
|
return view('menu_v2.Finance.adtItems', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_a_items(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
$filter = [];
|
||||||
|
|
||||||
|
if ($req->auth->role === Users::ROLE_ADMIN) {
|
||||||
|
$filter['crt_type'] = AItems::CRT_TYPE_ADMIN;
|
||||||
|
} else if ($req->auth->role === Users::ROLE_FINANCE) {
|
||||||
|
$filter['crt_type'] = AItems::CRT_TYPE_FINANCE;
|
||||||
|
} else {
|
||||||
|
$filter['crt_type'] = 99;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = AItems::listAItems($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list a_items');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_a_items(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a_item = AItems::showAItemsById($id);
|
||||||
|
if (count($a_item) < 1) {
|
||||||
|
$apiResp = Responses::not_found('a_item not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail a_item');
|
||||||
|
$apiResp['data'] = $a_item[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_a_items(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'type' => $req->type,
|
||||||
|
'price' => $req->price,
|
||||||
|
'status' => $req->status,
|
||||||
|
'is_adm_price' => $req->is_adm_price,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string',
|
||||||
|
'type' => 'required|integer|not_in:0',
|
||||||
|
'price' => 'required|numeric',
|
||||||
|
'status' => 'required|integer|min:0',
|
||||||
|
'is_adm_price' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqName = AItems::getByName($req->name);
|
||||||
|
if (count($uniqName) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('nama additional item sudah terdata');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->auth->role === Users::ROLE_ADMIN) {
|
||||||
|
$crt_type = AItems::CRT_TYPE_ADMIN;
|
||||||
|
} else if ($req->auth->role === Users::ROLE_FINANCE) {
|
||||||
|
$crt_type = AItems::CRT_TYPE_FINANCE;
|
||||||
|
} else {
|
||||||
|
$crt_type = 99;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insAItems = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'type' => $req->type,
|
||||||
|
'price' => $req->price,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_adm_price' => $req->is_adm_price,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'crt_type' => $crt_type,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$id = AItems::add($insAItems);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new additional item');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_updt_a_items(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
'name' => $req->name,
|
||||||
|
'type' => $req->type,
|
||||||
|
'price' => $req->price,
|
||||||
|
'status' => $req->status,
|
||||||
|
'is_adm_price' => $req->is_adm_price,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
'name' => 'required|string',
|
||||||
|
'type' => 'required|integer|not_in:0',
|
||||||
|
'price' => 'required|numeric',
|
||||||
|
'status' => 'required|integer|min:0',
|
||||||
|
'is_adm_price' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a_item = AItems::showAItemsById($id);
|
||||||
|
if (count($a_item) < 1) {
|
||||||
|
$apiResp = Responses::not_found('additional item not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqName = AItems::getByName($req->name);
|
||||||
|
if (count($uniqName) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqName as $key => $row) {
|
||||||
|
if ($row->id == $id) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request('nama additional item sudah terdata');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtAItems = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'type' => $req->type,
|
||||||
|
'price' => $req->price,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_adm_price' => $req->is_adm_price,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
AItems::updt($id, $updtAItems);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update additional item');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_a_items(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a_item = AItems::showAItemsById($id);
|
||||||
|
if (count($a_item) < 1) {
|
||||||
|
$apiResp = Responses::not_found('additional item not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
AItems::updt($id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete additional item');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
app/Http/Controllers/Api/AuthController.php
Normal file
51
app/Http/Controllers/Api/AuthController.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Validator;
|
||||||
|
use Auth;
|
||||||
|
use Hash;
|
||||||
|
use Session;
|
||||||
|
use App\Models\User;
|
||||||
|
use DB;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
public function login(Request $request)
|
||||||
|
{
|
||||||
|
// print_r($request->all());
|
||||||
|
$response = ["success" => false];
|
||||||
|
try {
|
||||||
|
$data = [
|
||||||
|
"email" => $request->email,
|
||||||
|
"password" => $request->password,
|
||||||
|
];
|
||||||
|
|
||||||
|
Auth::attempt($data);
|
||||||
|
|
||||||
|
if (Auth::check() && Auth::user()->status != 1) {
|
||||||
|
Auth::logout();
|
||||||
|
$response = [
|
||||||
|
"success" => false,
|
||||||
|
"code" => 400,
|
||||||
|
"msg" =>
|
||||||
|
"Your account is inactive, please contact the Administrator.",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"code" => 200,
|
||||||
|
"success" => true,
|
||||||
|
"data" => [
|
||||||
|
"id" => Auth::user()->id,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
$response["error"] = $th->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Executable file
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\ConfirmsPasswords;
|
||||||
|
|
||||||
|
class ConfirmPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Confirm Password Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password confirmations and
|
||||||
|
| uses a simple trait to include the behavior. You're free to explore
|
||||||
|
| this trait and override any functions that require customization.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ConfirmsPasswords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users when the intended url fails.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||||
|
|
||||||
|
class ForgotPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Password Reset Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password reset emails and
|
||||||
|
| includes a trait which assists in sending these notifications from
|
||||||
|
| your application to your users. Feel free to explore this trait.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use SendsPasswordResetEmails;
|
||||||
|
}
|
||||||
224
app/Http/Controllers/Auth/LoginController.php
Executable file
224
app/Http/Controllers/Auth/LoginController.php
Executable file
@ -0,0 +1,224 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class LoginController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Login Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller handles authenticating users for the application and
|
||||||
|
| redirecting them to your home screen. The controller uses a trait
|
||||||
|
| to conveniently provide its functionality to your applications.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use AuthenticatesUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after login.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware("guest")->except("logout");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function username()
|
||||||
|
{
|
||||||
|
return "email";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(Request $req)
|
||||||
|
{
|
||||||
|
$this->validateLogin($req);
|
||||||
|
|
||||||
|
// If the class is using the ThrottlesLogins trait, we can automatically throttle
|
||||||
|
// the login attempts for this application. We'll key this by the username and
|
||||||
|
// the IP address of the client making these requests into this application.
|
||||||
|
if (
|
||||||
|
method_exists($this, "hasTooManyLoginAttempts") &&
|
||||||
|
$this->hasTooManyLoginAttempts($req)
|
||||||
|
) {
|
||||||
|
$this->fireLockoutEvent($req);
|
||||||
|
|
||||||
|
return $this->sendLockoutResponse($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->guard()->validate($this->credentials($req))) {
|
||||||
|
$user = $this->guard()->getLastAttempted();
|
||||||
|
if ($user->dlt != null) {
|
||||||
|
$this->incrementLoginAttempts($req);
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
$this->username() => [trans("auth.failed")],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if ($user->status != Users::STATUS_ACTIVE) {
|
||||||
|
// Increment the failed login attempts and redirect back to the
|
||||||
|
// login form with an error message.
|
||||||
|
$this->incrementLoginAttempts($req);
|
||||||
|
// return redirect()
|
||||||
|
// ->back()
|
||||||
|
// ->withInput($req->only($this->username(), 'remember'))
|
||||||
|
// ->withErrors(['active' => 'You must be active to login.']);
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
$this->username() => __(
|
||||||
|
"Your account not active, please contact admin."
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->attemptLogin($req)) {
|
||||||
|
return $this->sendLoginResponse($req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the login attempt was unsuccessful we will increment the number of attempts
|
||||||
|
// to login and redirect the user back to the login form. Of course, when this
|
||||||
|
// user surpasses their maximum number of attempts they will get locked out.
|
||||||
|
$this->incrementLoginAttempts($req);
|
||||||
|
|
||||||
|
return $this->sendFailedLoginResponse($req);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateLogin(Request $req)
|
||||||
|
{
|
||||||
|
$this->validate($req, [
|
||||||
|
$this->username() => "required|string|email",
|
||||||
|
"password" => "required|string",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sendLoginResponse(Request $req)
|
||||||
|
{
|
||||||
|
$req->session()->regenerate();
|
||||||
|
|
||||||
|
$this->clearLoginAttempts($req);
|
||||||
|
|
||||||
|
if ($response = $this->authenticated($req, $this->guard()->user())) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return $req->wantsJson()
|
||||||
|
// ? new JsonResponse([], 204)
|
||||||
|
// : redirect()->intended($this->redirectPath());
|
||||||
|
// return $req->wantsJson()
|
||||||
|
// ? new JsonResponse([], 204)
|
||||||
|
// : redirect(route('view_dashboard'));
|
||||||
|
|
||||||
|
if ($req->wantsJson()) {
|
||||||
|
return new JsonResponse([], 204);
|
||||||
|
} else {
|
||||||
|
$user = Auth::user();
|
||||||
|
if ($user->role == Users::ROLE_ADMIN) {
|
||||||
|
return redirect(route("view_dashboard"));
|
||||||
|
} elseif ($user->role == Users::ROLE_VENDOR) {
|
||||||
|
return redirect(route("view_dashboard"));
|
||||||
|
} elseif ($user->role == Users::ROLE_CHECKER) {
|
||||||
|
return redirect(route("view_user_checker"));
|
||||||
|
} elseif ($user->role == Users::ROLE_CLIENT_ADMIN) {
|
||||||
|
return redirect(
|
||||||
|
route("view_user_client_transaction_add") . "?rdl=1"
|
||||||
|
);
|
||||||
|
} elseif ($user->role == Users::ROLE_SPECIAL_TRACKING) {
|
||||||
|
return redirect(route("view_dashboard"));
|
||||||
|
} elseif ($user->role == Users::ROLE_FINANCE) {
|
||||||
|
return redirect(route("view_keuangan_payment"));
|
||||||
|
} else {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
// return redirect(route('login'));
|
||||||
|
return redirect(route("login"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout(Request $req)
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
if ($user->role == Users::ROLE_ADMIN) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_admin"));
|
||||||
|
} elseif ($user->role == Users::ROLE_FINANCE) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_admin"));
|
||||||
|
} elseif ($user->role == Users::ROLE_VENDOR) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_vendor"));
|
||||||
|
} elseif ($user->role == Users::ROLE_CHECKER) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_checker"));
|
||||||
|
} elseif ($user->role == Users::ROLE_CLIENT_ADMIN) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_client"));
|
||||||
|
} elseif ($user->role == Users::ROLE_SPECIAL_TRACKING) {
|
||||||
|
$this->guard()->logout();
|
||||||
|
$req->session()->invalidate();
|
||||||
|
$req->session()->regenerateToken();
|
||||||
|
if ($response = $this->loggedOut($req)) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
return $req->wantsJson()
|
||||||
|
? new JsonResponse([], 204)
|
||||||
|
: redirect(route("login_admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
73
app/Http/Controllers/Auth/RegisterController.php
Executable file
73
app/Http/Controllers/Auth/RegisterController.php
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use App\User;
|
||||||
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class RegisterController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Register Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller handles the registration of new users as well as their
|
||||||
|
| validation and creation. By default this controller uses a trait to
|
||||||
|
| provide this functionality without requiring any additional code.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use RegistersUsers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after registration.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('guest');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a validator for an incoming registration request.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return \Illuminate\Contracts\Validation\Validator
|
||||||
|
*/
|
||||||
|
protected function validator(array $data)
|
||||||
|
{
|
||||||
|
return Validator::make($data, [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||||
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user instance after a valid registration.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return \App\User
|
||||||
|
*/
|
||||||
|
protected function create(array $data)
|
||||||
|
{
|
||||||
|
return User::create([
|
||||||
|
'name' => $data['name'],
|
||||||
|
'email' => $data['email'],
|
||||||
|
'password' => Hash::make($data['password']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
30
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||||
|
|
||||||
|
class ResetPasswordController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Password Reset Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling password reset requests
|
||||||
|
| and uses a simple trait to include this behavior. You're free to
|
||||||
|
| explore this trait and override any methods you wish to tweak.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use ResetsPasswords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after resetting their password.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
}
|
||||||
42
app/Http/Controllers/Auth/VerificationController.php
Executable file
42
app/Http/Controllers/Auth/VerificationController.php
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||||
|
|
||||||
|
class VerificationController extends Controller
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Email Verification Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller is responsible for handling email verification for any
|
||||||
|
| user that recently registered with the application. Emails may also
|
||||||
|
| be re-sent if the user didn't receive the original email message.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use VerifiesEmails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where to redirect users after verification.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $redirectTo = RouteServiceProvider::HOME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('signed')->only('verify');
|
||||||
|
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
||||||
|
}
|
||||||
|
}
|
||||||
81
app/Http/Controllers/AuthController.php
Executable file
81
app/Http/Controllers/AuthController.php
Executable file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
// public function view_login(Request $req)
|
||||||
|
// {
|
||||||
|
// return 'Do login';
|
||||||
|
// }
|
||||||
|
public function view_login_admin(Request $req)
|
||||||
|
{
|
||||||
|
return view('auth.loginAdmin');
|
||||||
|
}
|
||||||
|
public function view_login_client(Request $req)
|
||||||
|
{
|
||||||
|
return view('auth.loginClient');
|
||||||
|
}
|
||||||
|
public function view_login_vendor(Request $req)
|
||||||
|
{
|
||||||
|
return view('auth.loginVendor');
|
||||||
|
}
|
||||||
|
public function view_login_checker(Request $req)
|
||||||
|
{
|
||||||
|
return view('auth.loginChecker');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_login(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'password' => $req->password,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'password' => 'required|string',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->email) {
|
||||||
|
$input['email'] = $req->email;
|
||||||
|
$rulesInput['email'] = 'required|email';
|
||||||
|
}
|
||||||
|
if ($req->phone) {
|
||||||
|
$input['phone'] = $req->phone;
|
||||||
|
$rulesInput['phone'] = 'required|integer';
|
||||||
|
}
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$getUser = Users::getUserByEmail($req->email);
|
||||||
|
if (count($getUser) < 1) {
|
||||||
|
$getUser = Users::getUserByPhone($req->phone);
|
||||||
|
if (count($getUser) < 1) {
|
||||||
|
$apiResp = Responses::not_found('akun tidak ditemukan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('sukses login');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/Http/Controllers/ChecklistController.php
Normal file
57
app/Http/Controllers/ChecklistController.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use Auth;
|
||||||
|
use DataTables;
|
||||||
|
|
||||||
|
class ChecklistController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view("menu_v1.checklist");
|
||||||
|
}
|
||||||
|
public function table()
|
||||||
|
{
|
||||||
|
$table = DB::table("t_conf_checklists as tcc")
|
||||||
|
->leftJoin("t_clients as tc", "tc.id", "tcc.client_id")
|
||||||
|
->leftJoin("t_users as tu", "tu.id", "tcc.crt_by")
|
||||||
|
->select("tcc.*", "tu.first_name as crt_name", "tc.c_name as company_name")
|
||||||
|
->whereNull("tcc.dlt")
|
||||||
|
->where("tcc.client_id", Auth::user()->client_id);
|
||||||
|
|
||||||
|
// dd($table);
|
||||||
|
|
||||||
|
return DataTables::of($table)
|
||||||
|
->addIndexColumn()
|
||||||
|
->make();
|
||||||
|
}
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return view("menu_v1._addChecklist");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$now = time();
|
||||||
|
$_dtPost = [
|
||||||
|
"name" => $request->name,
|
||||||
|
"client_id" => Auth::user()->client_id,
|
||||||
|
"desc" => $request->desc,
|
||||||
|
"status" => $request->status,
|
||||||
|
"crt" => $now,
|
||||||
|
"updt" => $now,
|
||||||
|
"crt_by" => Auth::user()->id,
|
||||||
|
"updt_by" => Auth::user()->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$dtPost = DB::table("t_conf_checklists")->insert($_dtPost);
|
||||||
|
if ($dtPost) {
|
||||||
|
return redirect("checklist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
591
app/Http/Controllers/ClientController.php
Executable file
591
app/Http/Controllers/ClientController.php
Executable file
@ -0,0 +1,591 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class ClientController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function view_clients()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"disc_types" => Clients::select2DiscountTypes(),
|
||||||
|
];
|
||||||
|
return view("menu_v1.clients", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_clients(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$filter = [];
|
||||||
|
if ($req->cptid) {
|
||||||
|
$filter["company"] = $req->cptid;
|
||||||
|
}
|
||||||
|
$list = Clients::listClients($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
// $list[$key]->count_trx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success list clients");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
$apiResp["count"] = count($list);
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_client(Request $req, $cid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"cid" => $cid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"cid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = Clients::showClientById($cid);
|
||||||
|
if (count($client) < 1) {
|
||||||
|
$apiResp = Responses::not_found("client not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client[0]->user_id) {
|
||||||
|
$client[0]->c_credentials = Clients::CCREDENTIALS_CREATE;
|
||||||
|
} else {
|
||||||
|
$client[0]->c_credentials = Clients::CCREDENTIALS_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get detail client");
|
||||||
|
$apiResp["data"] = $client[0];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_client(Request $req)
|
||||||
|
{
|
||||||
|
//dd($req->all());
|
||||||
|
$url_clogo = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"client_logo" => $req->clogo_base64,
|
||||||
|
"client_name" => $req->cname,
|
||||||
|
"client_office_address" => $req->caddress_office,
|
||||||
|
"client_phone" => $req->cphone,
|
||||||
|
"client_email" => $req->cmail,
|
||||||
|
"pic_name" => $req->picname,
|
||||||
|
"pic_phone" => $req->picphone,
|
||||||
|
"pic_email" => $req->picmail,
|
||||||
|
// "disc_type" => $req->disc_type,
|
||||||
|
// "disc_amount" => $req->disc_amount,
|
||||||
|
"client_status" => $req->cstatus,
|
||||||
|
"is_create_login_credentials" => $req->ccredentials,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"client_logo" => "required|string",
|
||||||
|
"client_name" => "required|string|max:255",
|
||||||
|
"client_office_address" => "required|string|min:45|max:300",
|
||||||
|
"client_phone" => "required|integer|not_in:0",
|
||||||
|
"client_email" => "required|string|email",
|
||||||
|
"pic_name" => "required|string|max:255",
|
||||||
|
"pic_phone" => "required|integer|not_in:0",
|
||||||
|
"pic_email" => "required|string|email",
|
||||||
|
// "disc_type" => "required|numeric|min:0",
|
||||||
|
// "disc_amount" => "required|numeric|min:0",
|
||||||
|
"client_status" => "required|numeric",
|
||||||
|
"is_create_login_credentials" => "required|numeric",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqCPhone = Clients::getClientByPhone($req->cphone);
|
||||||
|
if (count($uniqCPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("client phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$uniqCMail = Clients::getClientByEmail($req->cmail);
|
||||||
|
if (count($uniqCMail) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("client email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqPicPhone = Clients::getPicByPhone($req->picphone);
|
||||||
|
if (count($uniqPicPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("pic phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$uniqPicMail = Clients::getPicByEmail($req->picmail);
|
||||||
|
if (count($uniqPicMail) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("pic email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqUserPhone = Users::getUserByPhone($req->cphone);
|
||||||
|
if (count($uniqUserPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("client phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$uniqUserMail = Users::getUserByEmail($req->cmail);
|
||||||
|
if (count($uniqUserMail) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("client email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->disc_type == Clients::DISC_TYPE_PERCENT && $req->disc_amount > 100) {
|
||||||
|
$apiResp = Responses::bad_request("maximum percent is 100%");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insClient = [
|
||||||
|
"c_name" => $req->cname,
|
||||||
|
"c_addr_office" => $req->caddress_office,
|
||||||
|
"c_phone" => $req->cphone,
|
||||||
|
"c_phone_code" => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
"c_mail" => $req->cmail,
|
||||||
|
"c_logo" => $url_clogo,
|
||||||
|
"pic_name" => $req->picname,
|
||||||
|
"pic_phone" => $req->picphone,
|
||||||
|
"pic_phone_code" => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
"pic_mail" => $req->picmail,
|
||||||
|
"disc_type" => 0,
|
||||||
|
"disc_amount" => 0,
|
||||||
|
"c_status" => $req->cstatus,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$clientId = Clients::addClient($insClient);
|
||||||
|
|
||||||
|
$url_clogo = "clients/$clientId/logo_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_clogo, base64_decode($req->clogo_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload client logo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$updtClient = [
|
||||||
|
"c_logo" => $url_clogo,
|
||||||
|
];
|
||||||
|
Clients::updateClient($clientId, $updtClient);
|
||||||
|
|
||||||
|
if ($req->ccredentials == Clients::CCREDENTIALS_CREATE) {
|
||||||
|
$status = Users::STATUS_ACTIVE;
|
||||||
|
if ($req->cstatus == Clients::CSTTS_INACTIVE) {
|
||||||
|
$status = Users::STATUS_NOT_ACTIVE;
|
||||||
|
}
|
||||||
|
$insAccount = [
|
||||||
|
"client_id" => $clientId,
|
||||||
|
"client_group_id" => $clientId,
|
||||||
|
"first_name" => $req->cname,
|
||||||
|
"last_name" => null,
|
||||||
|
"email" => $req->cmail,
|
||||||
|
"phone" => $req->cphone,
|
||||||
|
"phone_code" => Users::DEFAULT_PHONE_CODE,
|
||||||
|
"fulladdress" => $req->caddress_office,
|
||||||
|
"password" => Hash::make($req->cphone),
|
||||||
|
"role" => Users::ROLE_VENDOR,
|
||||||
|
"status" => $status,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Users::addUser($insAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success add new client");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_clogo);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_client(Request $req, $cid)
|
||||||
|
{
|
||||||
|
$url_clogo = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"cid" => $cid,
|
||||||
|
"client_logo" => $req->clogo_base64,
|
||||||
|
"client_name" => $req->cname,
|
||||||
|
"client_office_address" => $req->caddress_office,
|
||||||
|
"client_phone" => $req->cphone,
|
||||||
|
"client_email" => $req->cmail,
|
||||||
|
"pic_name" => $req->picname,
|
||||||
|
"pic_phone" => $req->picphone,
|
||||||
|
"pic_email" => $req->picmail,
|
||||||
|
"disc_type" => $req->disc_type,
|
||||||
|
"disc_amount" => $req->disc_amount,
|
||||||
|
"client_status" => $req->cstatus,
|
||||||
|
"is_create_login_credentials" => $req->ccredentials,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"cid" => "required|integer|not_in:0",
|
||||||
|
"client_logo" => "required|string",
|
||||||
|
"client_name" => "required|string|max:255",
|
||||||
|
"client_office_address" => "required|string|min:45|max:300",
|
||||||
|
"client_phone" => "required|integer|not_in:0",
|
||||||
|
"client_email" => "required|string|email",
|
||||||
|
"pic_name" => "required|string|max:255",
|
||||||
|
"pic_phone" => "required|integer|not_in:0",
|
||||||
|
"pic_email" => "required|string|email",
|
||||||
|
// "disc_type" => "required|numeric|min:0",
|
||||||
|
// "disc_amount" => "required|numeric|min:0",
|
||||||
|
"client_status" => "required|numeric",
|
||||||
|
"is_create_login_credentials" => "required|numeric",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = Clients::showClientById($cid);
|
||||||
|
if (count($client) < 1) {
|
||||||
|
$apiResp = Responses::not_found("client not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqCPhone = Clients::getClientByPhone($req->cphone);
|
||||||
|
if (count($uniqCPhone) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqCPhone as $key => $row) {
|
||||||
|
if ($row->id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("client phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uniqCMail = Clients::getClientByEmail($req->cmail);
|
||||||
|
if (count($uniqCMail) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqCMail as $key => $row) {
|
||||||
|
if ($row->id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("client email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqPicPhone = Clients::getPicByPhone($req->picphone);
|
||||||
|
if (count($uniqPicPhone) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqPicPhone as $key => $row) {
|
||||||
|
if ($row->id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("pic phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uniqPicMail = Clients::getPicByEmail($req->picmail);
|
||||||
|
if (count($uniqPicMail) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqPicMail as $key => $row) {
|
||||||
|
if ($row->id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("pic email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqUserPhone = Users::getUserByPhone($req->cphone);
|
||||||
|
if (count($uniqUserPhone) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqUserPhone as $key => $row) {
|
||||||
|
if ($row->client_group_id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("client phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uniqUserMail = Users::getUserByEmail($req->cmail);
|
||||||
|
if (count($uniqUserMail) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqUserMail as $key => $row) {
|
||||||
|
if ($row->client_group_id == $cid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("client email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->disc_type == Clients::DISC_TYPE_PERCENT && $req->disc_amount > 100) {
|
||||||
|
$apiResp = Responses::bad_request("maximum percent is 100%");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = Users::getUserByClientId($cid);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$url_clogo = $client[0]->c_logo;
|
||||||
|
if ($req->clogo_base64 && $req->clogo_base64 != "noupdate") {
|
||||||
|
$url_clogo = "clients/$cid/logo_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_clogo, base64_decode($req->clogo_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload client logo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($client[0]->c_logo);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updtClient = [
|
||||||
|
"c_name" => $req->cname,
|
||||||
|
"c_addr_office" => $req->caddress_office,
|
||||||
|
"c_phone" => $req->cphone,
|
||||||
|
"c_phone_code" => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
"c_mail" => $req->cmail,
|
||||||
|
"c_logo" => $url_clogo,
|
||||||
|
"pic_name" => $req->picname,
|
||||||
|
"pic_phone" => $req->picphone,
|
||||||
|
"pic_phone_code" => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
"pic_mail" => $req->picmail,
|
||||||
|
"disc_type" => $req->disc_type,
|
||||||
|
"disc_amount" => $req->disc_amount,
|
||||||
|
"c_status" => $req->cstatus,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Clients::updateClient($cid, $updtClient);
|
||||||
|
|
||||||
|
if ($req->ccredentials == Clients::CCREDENTIALS_CREATE && count($user) < 1) {
|
||||||
|
$status = Users::STATUS_ACTIVE;
|
||||||
|
if ($req->cstatus == Clients::CSTTS_INACTIVE) {
|
||||||
|
$status = Users::STATUS_NOT_ACTIVE;
|
||||||
|
}
|
||||||
|
$insAccount = [
|
||||||
|
"client_id" => $cid,
|
||||||
|
"client_group_id" => $cid,
|
||||||
|
"first_name" => $req->cname,
|
||||||
|
"last_name" => null,
|
||||||
|
"email" => $req->cmail,
|
||||||
|
"phone" => $req->cphone,
|
||||||
|
"phone_code" => Users::DEFAULT_PHONE_CODE,
|
||||||
|
"fulladdress" => $req->caddress_office,
|
||||||
|
"password" => Hash::make($req->cphone),
|
||||||
|
"role" => Users::ROLE_CLIENT_ADMIN,
|
||||||
|
"status" => $status,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Users::addUser($insAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = Users::STATUS_ACTIVE;
|
||||||
|
if ($req->cstatus == Clients::CSTTS_INACTIVE) {
|
||||||
|
$status = Users::STATUS_NOT_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the client credentials only
|
||||||
|
if (count($user) > 0) {
|
||||||
|
$updtAccount = [
|
||||||
|
"status" => $status,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Users::UpdateUser($user[0]->id, $updtAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update user group by this client
|
||||||
|
$updtGroupAccount = [
|
||||||
|
"status" => $status,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Users::updateUsersByGroupClientId($client[0]->id, $updtGroupAccount);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success update client");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_clogo);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_client(Request $req, $cid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"cid" => $cid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"cid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = Clients::showClientById($cid);
|
||||||
|
if (count($client) < 1) {
|
||||||
|
$apiResp = Responses::not_found("client not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = Users::getUserByClientId($cid);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Clients::updateClient($cid, [
|
||||||
|
"dlt" => $now,
|
||||||
|
"dlt_by" => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// delete the client credentials only
|
||||||
|
if (count($user) > 0) {
|
||||||
|
// Users::updateUser($user[0]->id, [
|
||||||
|
// 'dlt' => $now,
|
||||||
|
// 'dlt_by' => $req->auth->uid,
|
||||||
|
// ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete user group by this client
|
||||||
|
Users::updateUsersByGroupClientId($client[0]->id, [
|
||||||
|
"dlt" => $now,
|
||||||
|
"dlt_by" => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success delete client");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_universal_show_client_pt(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"cptid" => $req->cptid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"cptid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = Clients::showClientById($req->cptid);
|
||||||
|
if (count($client) < 1) {
|
||||||
|
$apiResp = Responses::not_found("client not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client[0]->user_id) {
|
||||||
|
$client[0]->c_credentials = Clients::CCREDENTIALS_CREATE;
|
||||||
|
} else {
|
||||||
|
$client[0]->c_credentials = Clients::CCREDENTIALS_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get detail client");
|
||||||
|
$apiResp["data"] = $client[0];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
387
app/Http/Controllers/ConfRateController.php
Executable file
387
app/Http/Controllers/ConfRateController.php
Executable file
@ -0,0 +1,387 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Validator;
|
||||||
|
use Hidehalo\Nanoid\Client as Nanoid;
|
||||||
|
use Hidehalo\Nanoid\GeneratorInterface as NanoidInterface;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\ConfRates;
|
||||||
|
use App\Models\Region;
|
||||||
|
use App\Models\ConfTruckTypes;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class ConfRateController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_rates(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'lanes' => ConfRates::getLanesActive(),
|
||||||
|
'provs' => Region::listProv(),
|
||||||
|
'vendors' => Users::getUsersActiveByRole(Users::ROLE_VENDOR),
|
||||||
|
'truck_types' => ConfTruckTypes::listTruckTypes(ConfTruckTypes::IS_ACTIVE),
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('menu_v1.configs.pricing', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_rates(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$list = ConfRates::listRates();
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list rates');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_rate(Request $req, $rid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'rid' => $rid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'rid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rate = ConfRates::showRateById($rid);
|
||||||
|
if (count($rate) < 1) {
|
||||||
|
$apiResp = Responses::not_found('rate not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail rate');
|
||||||
|
$apiResp['data'] = $rate[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_rate(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'origin_prov' => $req->origin_prov,
|
||||||
|
// 'origin_city' => $req->origin_city,
|
||||||
|
'via' => $req->via,
|
||||||
|
'dest_prov' => $req->dest_prov,
|
||||||
|
'dest_city' => $req->dest_city,
|
||||||
|
'dest_district' => $req->dest_district,
|
||||||
|
'vendor' => $req->vendor_id,
|
||||||
|
'vehicle_type' => $req->vhc_type_id,
|
||||||
|
'fast_time' => $req->fast_time,
|
||||||
|
'long_time' => $req->long_time,
|
||||||
|
'sell_kg' => $req->sell_kg,
|
||||||
|
'buy_kg' => $req->buy_kg,
|
||||||
|
'margin_kg' => $req->margin_kg,
|
||||||
|
'percent_kg' => $req->percent_kg,
|
||||||
|
'sell_cbm' => $req->sell_cbm,
|
||||||
|
'buy_cbm' => $req->buy_cbm,
|
||||||
|
'margin_cbm' => $req->margin_cbm,
|
||||||
|
'percent_cbm' => $req->percent_cbm,
|
||||||
|
'sell_ftl' => $req->sell_ftl,
|
||||||
|
'buy_ftl' => $req->buy_ftl,
|
||||||
|
'margin_ftl' => $req->margin_ftl,
|
||||||
|
'percent_ftl' => $req->percent_ftl,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'origin_prov' => 'required|numeric|min:0',
|
||||||
|
// 'origin_city' => 'required|numeric|min:0',
|
||||||
|
'via' => 'required|numeric|min:0',
|
||||||
|
'dest_prov' => 'required|numeric|min:0',
|
||||||
|
'dest_city' => 'required|numeric|min:0',
|
||||||
|
'dest_district' => 'nullable|numeric|min:0',
|
||||||
|
'vendor' => 'required|integer|not_in:0',
|
||||||
|
'vehicle_type' => 'required|integer|not_in:0',
|
||||||
|
'fast_time' => 'required|numeric|min:0',
|
||||||
|
'long_time' => 'required|numeric|min:0',
|
||||||
|
'sell_kg' => 'required|numeric|min:0',
|
||||||
|
'buy_kg' => 'required|numeric|min:0',
|
||||||
|
'margin_kg' => 'required|numeric|min:0',
|
||||||
|
'percent_kg' => 'required|numeric|min:0',
|
||||||
|
'sell_cbm' => 'required|numeric|min:0',
|
||||||
|
'buy_cbm' => 'required|numeric|min:0',
|
||||||
|
'margin_cbm' => 'required|numeric|min:0',
|
||||||
|
'percent_cbm' => 'required|numeric|min:0',
|
||||||
|
'sell_ftl' => 'required|numeric|min:0',
|
||||||
|
'buy_ftl' => 'required|numeric|min:0',
|
||||||
|
'margin_ftl' => 'required|numeric|min:0',
|
||||||
|
'percent_ftl' => 'required|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nanoid = new Nanoid();
|
||||||
|
$code = $nanoid->formattedId('123456789', 6);
|
||||||
|
|
||||||
|
$uniqCode = ConfRates::getRateByCode($code);
|
||||||
|
if (count($uniqCode) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('code has been used, try again');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insRate = [
|
||||||
|
'code' => $code,
|
||||||
|
'origin_prov' => $req->origin_prov,
|
||||||
|
// 'origin_city' => $req->origin_city,
|
||||||
|
'lane' => $req->via,
|
||||||
|
'dest_prov' => $req->dest_prov,
|
||||||
|
'dest_city' => $req->dest_city,
|
||||||
|
'vdr_id' => $req->vendor_id,
|
||||||
|
'vhc_type' => $req->vhc_type_id,
|
||||||
|
'fast_time' => $req->fast_time,
|
||||||
|
'long_time' => $req->long_time,
|
||||||
|
'unit_time' => ConfRates::UNIT_DAY,
|
||||||
|
'sell_kg' => $req->sell_kg,
|
||||||
|
'buy_kg' => $req->buy_kg,
|
||||||
|
'margin_kg' => $req->margin_kg,
|
||||||
|
'percent_kg' => $req->percent_kg,
|
||||||
|
'sell_cbm' => $req->sell_cbm,
|
||||||
|
'buy_cbm' => $req->buy_cbm,
|
||||||
|
'margin_cbm' => $req->margin_cbm,
|
||||||
|
'percent_cbm' => $req->percent_cbm,
|
||||||
|
'sell_ftl' => $req->sell_ftl,
|
||||||
|
'buy_ftl' => $req->buy_ftl,
|
||||||
|
'margin_ftl' => $req->margin_ftl,
|
||||||
|
'percent_ftl' => $req->percent_ftl,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->dest_district) {
|
||||||
|
$insRate['dest_district'] = $req->dest_district;
|
||||||
|
}
|
||||||
|
$rid = ConfRates::addRate($insRate);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new rate');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_rate(Request $req, $rid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'rid' => $rid,
|
||||||
|
'origin_prov' => $req->origin_prov,
|
||||||
|
// 'origin_city' => $req->origin_city,
|
||||||
|
'via' => $req->via,
|
||||||
|
'dest_prov' => $req->dest_prov,
|
||||||
|
'dest_city' => $req->dest_city,
|
||||||
|
'dest_district' => $req->dest_district,
|
||||||
|
'vendor' => $req->vendor_id,
|
||||||
|
'vehicle_type' => $req->vhc_type_id,
|
||||||
|
'fast_time' => $req->fast_time,
|
||||||
|
'long_time' => $req->long_time,
|
||||||
|
'sell_kg' => $req->sell_kg,
|
||||||
|
'buy_kg' => $req->buy_kg,
|
||||||
|
'margin_kg' => $req->margin_kg,
|
||||||
|
'percent_kg' => $req->percent_kg,
|
||||||
|
'sell_cbm' => $req->sell_cbm,
|
||||||
|
'buy_cbm' => $req->buy_cbm,
|
||||||
|
'margin_cbm' => $req->margin_cbm,
|
||||||
|
'percent_cbm' => $req->percent_cbm,
|
||||||
|
'sell_ftl' => $req->sell_ftl,
|
||||||
|
'buy_ftl' => $req->buy_ftl,
|
||||||
|
'margin_ftl' => $req->margin_ftl,
|
||||||
|
'percent_ftl' => $req->percent_ftl,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'rid' => 'required|integer|not_in:0',
|
||||||
|
'origin_prov' => 'required|numeric|min:0',
|
||||||
|
// 'origin_city' => 'required|numeric|min:0',
|
||||||
|
'via' => 'required|numeric|min:0',
|
||||||
|
'dest_prov' => 'required|numeric|min:0',
|
||||||
|
'dest_city' => 'required|numeric|min:0',
|
||||||
|
'dest_district' => 'nullable|numeric|min:0',
|
||||||
|
'vendor' => 'required|integer|not_in:0',
|
||||||
|
'vehicle_type' => 'required|integer|not_in:0',
|
||||||
|
'fast_time' => 'required|numeric|min:0',
|
||||||
|
'long_time' => 'required|numeric|min:0',
|
||||||
|
'sell_kg' => 'required|numeric|min:0',
|
||||||
|
'buy_kg' => 'required|numeric|min:0',
|
||||||
|
'margin_kg' => 'required|numeric|min:0',
|
||||||
|
'percent_kg' => 'required|numeric|min:0',
|
||||||
|
'sell_cbm' => 'required|numeric|min:0',
|
||||||
|
'buy_cbm' => 'required|numeric|min:0',
|
||||||
|
'margin_cbm' => 'required|numeric|min:0',
|
||||||
|
'percent_cbm' => 'required|numeric|min:0',
|
||||||
|
'sell_ftl' => 'required|numeric|min:0',
|
||||||
|
'buy_ftl' => 'required|numeric|min:0',
|
||||||
|
'margin_ftl' => 'required|numeric|min:0',
|
||||||
|
'percent_ftl' => 'required|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rate = ConfRates::showRateById($rid);
|
||||||
|
if (count($rate) < 1) {
|
||||||
|
$apiResp = Responses::not_found('rate not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insRate = [
|
||||||
|
'origin_prov' => $req->origin_prov,
|
||||||
|
// 'origin_city' => $req->origin_city,
|
||||||
|
'lane' => $req->via,
|
||||||
|
'dest_prov' => $req->dest_prov,
|
||||||
|
'dest_city' => $req->dest_city,
|
||||||
|
'vdr_id' => $req->vendor_id,
|
||||||
|
'vhc_type' => $req->vhc_type_id,
|
||||||
|
'fast_time' => $req->fast_time,
|
||||||
|
'long_time' => $req->long_time,
|
||||||
|
'unit_time' => ConfRates::UNIT_DAY,
|
||||||
|
'sell_kg' => $req->sell_kg,
|
||||||
|
'buy_kg' => $req->buy_kg,
|
||||||
|
'margin_kg' => $req->margin_kg,
|
||||||
|
'percent_kg' => $req->percent_kg,
|
||||||
|
'sell_cbm' => $req->sell_cbm,
|
||||||
|
'buy_cbm' => $req->buy_cbm,
|
||||||
|
'margin_cbm' => $req->margin_cbm,
|
||||||
|
'percent_cbm' => $req->percent_cbm,
|
||||||
|
'sell_ftl' => $req->sell_ftl,
|
||||||
|
'buy_ftl' => $req->buy_ftl,
|
||||||
|
'margin_ftl' => $req->margin_ftl,
|
||||||
|
'percent_ftl' => $req->percent_ftl,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->dest_district) {
|
||||||
|
$insRate['dest_district'] = $req->dest_district;
|
||||||
|
}
|
||||||
|
$rid = ConfRates::updateRate($rid, $insRate);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new rate');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_rate(Request $req, $rid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'rid' => $rid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'rid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rate = ConfRates::showRateById($rid);
|
||||||
|
if (count($rate) < 1) {
|
||||||
|
$apiResp = Responses::not_found('rate not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
ConfRates::updateRate($rid, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete rate');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
321
app/Http/Controllers/ConfTruckTypeController.php
Executable file
321
app/Http/Controllers/ConfTruckTypeController.php
Executable file
@ -0,0 +1,321 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Validator;
|
||||||
|
use Hidehalo\Nanoid\Client as Nanoid;
|
||||||
|
use Hidehalo\Nanoid\GeneratorInterface as NanoidInterface;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\ConfRates;
|
||||||
|
use App\Models\ConfTruckTypes;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
|
||||||
|
class ConfTruckTypeController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_truck_types(Request $req)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
return view('menu_v1.configs.truck_types', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_truck_types(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$list = ConfTruckTypes::listTruckTypes();
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list truck types');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_truck_type(Request $req, $ttid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'ttid' => $ttid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'ttid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$truckType = ConfTruckTypes::showTruckTypeById($ttid);
|
||||||
|
if (count($truckType) < 1) {
|
||||||
|
$apiResp = Responses::not_found('truck type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail truck type');
|
||||||
|
$apiResp['data'] = $truckType[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_truck_type(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'type_name' => $req->type_name,
|
||||||
|
'max_kg' => $req->max_kg,
|
||||||
|
'max_cbm' => $req->max_cbm,
|
||||||
|
'max_koli' => $req->max_koli,
|
||||||
|
'status' => $req->status,
|
||||||
|
'publish' => $req->publish,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'type_name' => 'required|string',
|
||||||
|
'max_kg' => 'nullable|numeric|min:0',
|
||||||
|
'max_cbm' => 'nullable|numeric|min:0',
|
||||||
|
'max_koli' => 'nullable|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
'publish' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqName = ConfTruckTypes::getTruckTypeByName($req->type_name);
|
||||||
|
if (count($uniqName) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('type name has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$type_id = ConfTruckTypes::addTypes([
|
||||||
|
'cat_id' => Vehicles::DEFAULT_CAT_ID,
|
||||||
|
'name' => $req->type_name,
|
||||||
|
'desc' => $req->type_name,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_publish' => $req->publish,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$insTruckType = [
|
||||||
|
'type_id' => $type_id,
|
||||||
|
'max_kg' => $req->max_kg ?? 0,
|
||||||
|
'max_cbm' => $req->max_cbm ?? 0,
|
||||||
|
'max_koli' => $req->max_koli ?? 0,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_publish' => $req->publish,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$ttid = ConfTruckTypes::addTruckType($insTruckType);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new truck type');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_truck_type(Request $req, $ttid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'ttid' => $ttid,
|
||||||
|
'type_name' => $req->type_name,
|
||||||
|
'max_kg' => $req->max_kg,
|
||||||
|
'max_cbm' => $req->max_cbm,
|
||||||
|
'max_koli' => $req->max_koli,
|
||||||
|
'status' => $req->status,
|
||||||
|
'publish' => $req->publish,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'ttid' => 'required|integer|not_in:0',
|
||||||
|
'type_name' => 'required|string',
|
||||||
|
'max_kg' => 'nullable|numeric|min:0',
|
||||||
|
'max_cbm' => 'nullable|numeric|min:0',
|
||||||
|
'max_koli' => 'nullable|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
'publish' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$truckType = ConfTruckTypes::showTruckTypeById($ttid);
|
||||||
|
if (count($truckType) < 1) {
|
||||||
|
$apiResp = Responses::not_found('truck type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqName = ConfTruckTypes::getTruckTypeByName($req->type_name);
|
||||||
|
if (count($uniqName) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqName as $key => $row) {
|
||||||
|
if ($row->id == $ttid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request('type name has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->status == ConfTruckTypes::IS_INACTIVE) {
|
||||||
|
$checkVhcType = ConfRates::checkVhcType($truckType[0]->type_id);
|
||||||
|
if (count($checkVhcType) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('cannot change to inactive, still connected on rates');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
ConfTruckTypes::updtTypes($truckType[0]->type_id, [
|
||||||
|
'name' => $req->type_name,
|
||||||
|
'desc' => $req->type_name,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_publish' => $req->publish,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$insTruckType = [
|
||||||
|
'type_id' => $truckType[0]->type_id,
|
||||||
|
'max_kg' => $req->max_kg ?? 0,
|
||||||
|
'max_cbm' => $req->max_cbm ?? 0,
|
||||||
|
'max_koli' => $req->max_koli ?? 0,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_publish' => $req->publish,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$ttid = ConfTruckTypes::updateTruckType($ttid, $insTruckType);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update truck type');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_truck_type(Request $req, $ttid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'ttid' => $ttid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'ttid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$truckType = ConfTruckTypes::showTruckTypeById($ttid);
|
||||||
|
if (count($truckType) < 1) {
|
||||||
|
$apiResp = Responses::not_found('truck type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkVhcType = ConfRates::checkVhcType($truckType[0]->type_id);
|
||||||
|
if (count($checkVhcType) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('cannot delete, still connected on rates');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
ConfTruckTypes::updtTypes($truckType[0]->type_id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ConfTruckTypes::updateTruckType($ttid, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete truck type');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
app/Http/Controllers/Controller.php
Executable file
13
app/Http/Controllers/Controller.php
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
|
|
||||||
|
class Controller extends BaseController
|
||||||
|
{
|
||||||
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||||
|
}
|
||||||
85
app/Http/Controllers/DanaController.php
Executable file
85
app/Http/Controllers/DanaController.php
Executable file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Dana;
|
||||||
|
|
||||||
|
class DanaController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_dana(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'dana' => Dana::getDanaById(Dana::PK_ID)[0],
|
||||||
|
];
|
||||||
|
|
||||||
|
$data['dana']->amt = number_format($data['dana']->amt, 0, ',', '.');
|
||||||
|
|
||||||
|
return view('menu_v2.Finance._dana', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_edit_dana(Request $req, $dana_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'dana_id' => $dana_id,
|
||||||
|
'saldo' => $req->amt,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'dana_id' => 'required|integer|not_in:0',
|
||||||
|
'saldo' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dana = Dana::getDanaById(Dana::PK_ID);
|
||||||
|
if (count($dana) < 1) {
|
||||||
|
$apiResp = Responses::not_found('Dana not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($input['saldo'] < Dana::MINIMUM_AMT) {
|
||||||
|
$apiResp = Responses::bad_request('Minimum saldo dana Rp'.number_format(Dana::MINIMUM_AMT, 0, ',', '.'));
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtDana = [
|
||||||
|
'amt' => $input['saldo'],
|
||||||
|
];
|
||||||
|
Dana::updateDana($input['dana_id'], $updtDana);
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success update dana');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Http/Controllers/DataTypesController.php
Executable file
91
app/Http/Controllers/DataTypesController.php
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\DataTypes;
|
||||||
|
|
||||||
|
class DataTypesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_dtypes(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'is_active' => $req->is_active,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'is_active' => 'nullable|numeric'
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['is_active'] != null && $input['is_active'] != 0) {
|
||||||
|
$filter['is_active'] = $input['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = DataTypes::listDataTypes($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list data types');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_dtypes(Request $req, $dtypes_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'dtypes_id' => $dtypes_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'dtypes_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_key = DataTypes::showDataType(['dtypes_id' => $dtypes_id]);
|
||||||
|
if (count($lgb_key) < 1) {
|
||||||
|
$apiResp = Responses::not_found('data type key not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail data type key');
|
||||||
|
$apiResp['data'] = $lgb_key[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
407
app/Http/Controllers/DevicesController.php
Executable file
407
app/Http/Controllers/DevicesController.php
Executable file
@ -0,0 +1,407 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Devices;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
|
||||||
|
class DevicesController extends Controller
|
||||||
|
{
|
||||||
|
public function view_devices(Request $req)
|
||||||
|
{
|
||||||
|
$vhcs = Vehicles::listVehicles($req->auth);
|
||||||
|
$data = [
|
||||||
|
'vhcs' => $vhcs,
|
||||||
|
];
|
||||||
|
return view('menu_v1.configs.devices', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_devices(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$list = Devices::listDevices();
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
if ($row->vhc_id == null) {
|
||||||
|
$list[$key]->is_idle = 'yes';
|
||||||
|
} else {
|
||||||
|
$list[$key]->is_idle = 'no';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list devices');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_device(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device = Devices::showDeviceById($id);
|
||||||
|
if (count($device) < 1) {
|
||||||
|
$apiResp = Responses::not_found('device not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail device');
|
||||||
|
$apiResp['data'] = $device[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_device(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'device_id' => $req->device_id,
|
||||||
|
'name' => $req->name,
|
||||||
|
'simcard' => $req->simcard,
|
||||||
|
'type' => $req->type,
|
||||||
|
'status' => $req->status,
|
||||||
|
'assigned' => $req->assigned,
|
||||||
|
'vid' => $req->vid,
|
||||||
|
'available' => $req->available,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'device_id' => 'required|numeric',
|
||||||
|
'name' => 'required|string',
|
||||||
|
'simcard' => 'required|numeric',
|
||||||
|
'type' => 'required|integer|not_in:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
'assigned' => 'required|numeric',
|
||||||
|
'vid' => 'nullable|numeric',
|
||||||
|
'available' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device_id = str_pad($req->device_id, Devices::MAX_DEVICE_ID, '0', STR_PAD_LEFT);
|
||||||
|
if (strlen($device_id) > 16) {
|
||||||
|
$apiResp = Responses::bad_request('device id maksimal 16 digit');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
if (strlen($req->simcard) > 14) {
|
||||||
|
$apiResp = Responses::bad_request('simcard maksimal 14 digit');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqDeviceId = Devices::getDeviceByDeviceId($device_id);
|
||||||
|
if (count($uniqDeviceId) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('device id has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$uniqSimcard = Devices::getDeviceBySimcard($req->simcard);
|
||||||
|
if (count($uniqSimcard) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('simcard has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insDevice = [
|
||||||
|
'device_id' => $device_id,
|
||||||
|
'name' => $req->name,
|
||||||
|
'simcard' => (int)$req->simcard,
|
||||||
|
'type' => $req->type,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_assigned' => $req->assigned,
|
||||||
|
'is_available' => $req->available,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$id = Devices::addDevice($insDevice);
|
||||||
|
|
||||||
|
if ($req->assigned == Devices::IS_ASSIGNED) {
|
||||||
|
if ($req->vid == null || $req->vid == "") {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request('kendaraan belum dipilih');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$vhc = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
if (count($vhc) > 0) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request('kendaraan sudah dipasang oleh device id ' . $vhc[0]->device_id);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$vhc = Vehicles::getVehicleById($req->vid);
|
||||||
|
if (count($vhc) > 0 && $vhc[0]->dvc_id !== 0 && $vhc[0]->device_id !== $device_id) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request('kendaraan sudah dipasang oleh device id ' . $vhc[0]->device_id);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$vid = $req->vid;
|
||||||
|
Vehicles::updateVehicle($vid, [
|
||||||
|
'dvc_id' => $id,
|
||||||
|
'device_id' => $device_id,
|
||||||
|
'simcard' => (int)$req->simcard,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$vid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new device');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_updt_device(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
'device_id' => $req->device_id,
|
||||||
|
'name' => $req->name,
|
||||||
|
'simcard' => $req->simcard,
|
||||||
|
'type' => $req->type,
|
||||||
|
'status' => $req->status,
|
||||||
|
'assigned' => $req->assigned,
|
||||||
|
'vid' => $req->vid,
|
||||||
|
'available' => $req->available,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
'device_id' => 'required|numeric',
|
||||||
|
'name' => 'required|string',
|
||||||
|
'simcard' => 'required|numeric',
|
||||||
|
'type' => 'required|integer|not_in:0',
|
||||||
|
'status' => 'required|numeric',
|
||||||
|
'assigned' => 'required|numeric',
|
||||||
|
'vid' => 'nullable|numeric',
|
||||||
|
'available' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device = Devices::showDeviceById($id);
|
||||||
|
if (count($device) < 1) {
|
||||||
|
$apiResp = Responses::not_found('device not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$device_id = str_pad($req->device_id, Devices::MAX_DEVICE_ID, '0', STR_PAD_LEFT);
|
||||||
|
if (strlen($device_id) > 16) {
|
||||||
|
$apiResp = Responses::bad_request('device id maksimal 16 digit');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
if (strlen($req->simcard) > 14) {
|
||||||
|
$apiResp = Responses::bad_request('simcard maksimal 14 digit');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqDeviceId = Devices::getDeviceByDeviceId($device_id);
|
||||||
|
if (count($uniqDeviceId) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqDeviceId as $key => $row) {
|
||||||
|
if ($row->id == $id) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request('device id has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uniqSimcard = Devices::getDeviceBySimcard($req->simcard);
|
||||||
|
if (count($uniqSimcard) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqSimcard as $key => $row) {
|
||||||
|
if ($row->id == $id) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request('simcard has been used');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->status == Devices::IS_INACTIVE) {
|
||||||
|
$isUsed = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
if (count($isUsed) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('tidak dapat mengubah menjadi nonaktif, device sedang digunakan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
if ($device[0]->vhc_id) {
|
||||||
|
Vehicles::updateVehicle($device[0]->vhc_id, [
|
||||||
|
'dvc_id' => 0,
|
||||||
|
'device_id' => str_pad(0, Devices::MAX_DEVICE_ID, '0', STR_PAD_LEFT),
|
||||||
|
'simcard' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->assigned == Devices::IS_ASSIGNED) {
|
||||||
|
if ($req->vid == null || $req->vid == "") {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request('kendaraan belum dipilih');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$vhc = Vehicles::getVehicleById($req->vid);
|
||||||
|
if (count($vhc) > 0 && $vhc[0]->dvc_id !== 0 && $vhc[0]->device_id !== $device_id) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request('kendaraan sudah dipasang dengan device id ' . $vhc[0]->device_id);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$vid = $req->vid;
|
||||||
|
Vehicles::updateVehicle($vid, [
|
||||||
|
'dvc_id' => $id,
|
||||||
|
'device_id' => $device_id,
|
||||||
|
'simcard' => (int)$req->simcard,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$vhc = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
if (count($vhc) > 0) {
|
||||||
|
$vid = $vhc[0]->id;
|
||||||
|
Vehicles::updateVehicle($vid, [
|
||||||
|
'dvc_id' => 0,
|
||||||
|
'device_id' => str_pad(0, Devices::MAX_DEVICE_ID, '0', STR_PAD_LEFT),
|
||||||
|
'simcard' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$updtDevice = [
|
||||||
|
'device_id' => $req->device_id,
|
||||||
|
'name' => $req->name,
|
||||||
|
'simcard' => (int)$req->simcard,
|
||||||
|
'type' => $req->type,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'is_assigned' => $req->assigned,
|
||||||
|
'is_available' => $req->available,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Devices::updateDevice($id, $updtDevice);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update device');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_device(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device = Devices::showDeviceById($id);
|
||||||
|
if (count($device) < 1) {
|
||||||
|
$apiResp = Responses::not_found('device not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$isUsed = Vehicles::getVehicleByDeviceId($device[0]->device_id);
|
||||||
|
if (count($isUsed) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('tidak dapat menghapus, device sedang digunakan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Devices::updateDevice($id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete device');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
678
app/Http/Controllers/DriversController.php
Executable file
678
app/Http/Controllers/DriversController.php
Executable file
@ -0,0 +1,678 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Validator;
|
||||||
|
use Auth;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Drivers;
|
||||||
|
use App\Models\DriversDetail;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\DrvPhoneDevices;
|
||||||
|
|
||||||
|
class DriversController extends Controller
|
||||||
|
{
|
||||||
|
public function api_list_drivers(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$filter = [];
|
||||||
|
if ($req->cptid) {
|
||||||
|
$filter["company"] = $req->cptid;
|
||||||
|
}
|
||||||
|
$list = Drivers::listDrivers($req->auth, $filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->mileage_km = "-";
|
||||||
|
$list[$key]->action = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success list drivers");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_driver(Request $req, $did)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"did" => $did,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"did" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = Drivers::showDriverById($did);
|
||||||
|
if (count($driver) < 1) {
|
||||||
|
$apiResp = Responses::not_found("driver not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get detail driver");
|
||||||
|
$apiResp["data"] = $driver[0];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_driver(Request $req)
|
||||||
|
{
|
||||||
|
$url_ktp = "";
|
||||||
|
$url_npwp = "";
|
||||||
|
$url_license = "";
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"ktp_photo" => $req->ktp_base64,
|
||||||
|
"nik" => $req->nik,
|
||||||
|
"fullname" => $req->fullname,
|
||||||
|
"fullname2" => $req->fullname2,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"phone2" => $req->phone2,
|
||||||
|
"email" => $req->email,
|
||||||
|
"date_of_birth" => $req->dob,
|
||||||
|
"age" => $req->age,
|
||||||
|
"blood" => $req->blood,
|
||||||
|
"home_address" => $req->fulladdress,
|
||||||
|
"npwp_photo" => $req->npwp_base64,
|
||||||
|
"npwp_number" => $req->npwp_string,
|
||||||
|
"npwp_number_hidden" => $req->npwp_number,
|
||||||
|
"license_photo" => $req->license_base64,
|
||||||
|
"license_number" => $req->license_number,
|
||||||
|
"license_exp" => $req->license_exp,
|
||||||
|
"emergency_fullname" => $req->em_fullname,
|
||||||
|
"emergency_relationship" => $req->em_relationship,
|
||||||
|
"emergency_phone" => $req->em_phone,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_kcp" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
"vendor_id" => Auth::user()->id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"ktp_photo" => "nullable|string", // required
|
||||||
|
"nik" => "nullable|integer", // required
|
||||||
|
"fullname" => "required|string|min:3|max:125",
|
||||||
|
"fullname2" => "nullable|string",
|
||||||
|
"phone" => "required|integer|not_in:0",
|
||||||
|
"phone2" => "nullable|integer|not_in:0",
|
||||||
|
"email" => "nullable|email", // required
|
||||||
|
"date_of_birth" => "nullable|date_format:Y-m-d", // required
|
||||||
|
"age" => "nullable|integer", // required
|
||||||
|
"blood" => "nullable|string|max:4", // required
|
||||||
|
"home_address" => "nullable|string|min:25", // required
|
||||||
|
"npwp_photo" => "nullable|string", // required
|
||||||
|
"npwp_number" => "nullable|string", // required
|
||||||
|
"npwp_number_hidden" => "nullable|numeric", // required
|
||||||
|
"license_photo" => "nullable|string", // required
|
||||||
|
"license_number" => "nullable|numeric", // required
|
||||||
|
"license_exp" => "nullable|date_format:Y-m-d", // required
|
||||||
|
"emergency_fullname" => "nullable|string|min:3", // required
|
||||||
|
"emergency_relationship" => "nullable|string", // required
|
||||||
|
"emergency_phone" => "nullable|integer|not_in:0", // required
|
||||||
|
"bank_id" => "required|integer|not_in:0",
|
||||||
|
"bank_code" => "required|numeric",
|
||||||
|
"bank_short" => "required|string",
|
||||||
|
"bank_name" => "required|string",
|
||||||
|
"bank_kcp" => "nullable|string",
|
||||||
|
"bank_acc_number" => "nullable|numeric", // required
|
||||||
|
"bank_acc_name" => "nullable|string|max:255", // required
|
||||||
|
"vendor_id" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if ($req->nik && strlen($req->nik) != 16) {
|
||||||
|
$apiResp = Responses::bad_input("nik must be 16 digit");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if ($req->license_number && strlen($req->license_number) < 12) {
|
||||||
|
$apiResp = Responses::bad_input("license number must be at least 12 digit");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->nik) {
|
||||||
|
$uniqNik = Drivers::getDriverByNik($req->nik);
|
||||||
|
if (count($uniqNik) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("nik has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->phone) {
|
||||||
|
$uniqPhone = Drivers::getDriverByPhone($req->phone);
|
||||||
|
if (count($uniqPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->email) {
|
||||||
|
$uniqEmail = Drivers::getDriverByEmail($req->email);
|
||||||
|
if (count($uniqEmail) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insDriver = [
|
||||||
|
"nik" => $req->nik ? $req->nik : 0,
|
||||||
|
"fullname" => $req->fullname,
|
||||||
|
"email" => $req->email,
|
||||||
|
"fullname2" => $req->fullname2,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"phone_code" => Drivers::DEFAULT_PHONE_CODE,
|
||||||
|
"phone2" => $req->phone2 ?? 0,
|
||||||
|
"phone2_code" => Drivers::DEFAULT_PHONE_CODE,
|
||||||
|
"dob" => $req->dob,
|
||||||
|
"age" => $req->age ? $req->age : 0,
|
||||||
|
"blood" => $req->blood,
|
||||||
|
"fulladdress" => $req->fulladdress,
|
||||||
|
"client_group_id" => $req->auth->client_group_id ?? null,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$insDriver["vendor_id"] = $req->auth->uid;
|
||||||
|
} else {
|
||||||
|
$insDriver["vendor_id"] = Auth::user()->id ?? 0;
|
||||||
|
}
|
||||||
|
$did = Drivers::addDriver($insDriver);
|
||||||
|
|
||||||
|
if ($req->ktp_base64) {
|
||||||
|
$url_ktp = "drivers/$did/ktp_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_ktp, base64_decode($req->ktp_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload ktp photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->npwp_base64) {
|
||||||
|
$url_npwp = "drivers/$did/npwp_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_npwp, base64_decode($req->npwp_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload npwp photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->license_base64) {
|
||||||
|
$url_license = "drivers/$did/license_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_license, base64_decode($req->license_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
Storage::disk("public")->delete($url_npwp);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload license photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$insDetail = [
|
||||||
|
"did" => $did,
|
||||||
|
"ktp_img" => $url_ktp ? $url_ktp : "",
|
||||||
|
"npwp_img" => $url_npwp ? $url_npwp : "",
|
||||||
|
"npwp_string" => $req->npwp_string,
|
||||||
|
"npwp_number" => $req->npwp_number,
|
||||||
|
"license_img" => $url_license ? $url_license : "",
|
||||||
|
"license_number" => $req->license_number,
|
||||||
|
"license_exp" => $req->license_exp,
|
||||||
|
"em_fullname" => $req->em_fullname,
|
||||||
|
"em_phone" => $req->em_phone,
|
||||||
|
"em_relationship" => $req->em_relationship,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short_name" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_branch_name" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
];
|
||||||
|
DriversDetail::addDetail($insDetail);
|
||||||
|
|
||||||
|
$insAccount = [
|
||||||
|
"client_id" => Auth::user()->client_id,
|
||||||
|
"client_group_id" => Auth::user()->client_group_id,
|
||||||
|
"first_name" => $req->fullname,
|
||||||
|
"last_name" => null,
|
||||||
|
"email" => $req->email,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"phone_code" => Users::DEFAULT_PHONE_CODE,
|
||||||
|
"fulladdress" => $req->fulladdress,
|
||||||
|
"password" => Hash::make("0" . $req->phone),
|
||||||
|
"role" => Users::ROLE_VENDOR_DRIVER,
|
||||||
|
"is_driver" => 1,
|
||||||
|
"status" => 1,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
Users::addUser($insAccount);
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success add new driver");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
Storage::disk("public")->delete($url_npwp);
|
||||||
|
Storage::disk("public")->delete($url_license);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_driver(Request $req, $did)
|
||||||
|
{
|
||||||
|
$url_ktp = "";
|
||||||
|
$url_npwp = "";
|
||||||
|
$url_license = "";
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"did" => $did,
|
||||||
|
"ktp_photo" => $req->ktp_base64,
|
||||||
|
"nik" => $req->nik,
|
||||||
|
"fullname" => $req->fullname,
|
||||||
|
"fullname2" => $req->fullname2,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"phone2" => $req->phone2,
|
||||||
|
"email" => $req->email,
|
||||||
|
"date_of_birth" => $req->dob,
|
||||||
|
"age" => $req->age,
|
||||||
|
"blood" => $req->blood,
|
||||||
|
"home_address" => $req->fulladdress,
|
||||||
|
"npwp_photo" => $req->npwp_base64,
|
||||||
|
"npwp_number" => $req->npwp_string,
|
||||||
|
"npwp_number_hidden" => $req->npwp_number,
|
||||||
|
"license_photo" => $req->license_base64,
|
||||||
|
"license_number" => $req->license_number,
|
||||||
|
"license_exp" => $req->license_exp,
|
||||||
|
"emergency_fullname" => $req->em_fullname,
|
||||||
|
"emergency_relationship" => $req->em_relationship,
|
||||||
|
"emergency_phone" => $req->em_phone,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_kcp" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
"vendor_id" => Auth::user()->id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"did" => "required|integer|not_in:0",
|
||||||
|
"ktp_photo" => "nullable|string",
|
||||||
|
"nik" => "required|integer",
|
||||||
|
"fullname" => "nullable|string|min:3|max:125", // required
|
||||||
|
"fullname2" => "nullable|string",
|
||||||
|
"phone" => "required|integer|not_in:0",
|
||||||
|
"phone2" => "nullable|integer|not_in:0",
|
||||||
|
"email" => "nullable|email", // required
|
||||||
|
"date_of_birth" => "nullable|date_format:Y-m-d", // required
|
||||||
|
"age" => "nullable|integer", // required
|
||||||
|
"blood" => "nullable|string|max:4", // required
|
||||||
|
"home_address" => "nullable|string|min:25", // required
|
||||||
|
"npwp_photo" => "nullable|string",
|
||||||
|
"npwp_number" => "nullable|string", // required
|
||||||
|
"npwp_number_hidden" => "nullable|numeric", // required
|
||||||
|
"license_photo" => "nullable|string",
|
||||||
|
"license_number" => "nullable|numeric", // required
|
||||||
|
"license_exp" => "nullable|date_format:Y-m-d", // required
|
||||||
|
"emergency_fullname" => "nullable|string|min:3", // required
|
||||||
|
"emergency_relationship" => "nullable|string", // required
|
||||||
|
"emergency_phone" => "nullable|integer|not_in:0", // required
|
||||||
|
"bank_id" => "required|integer|not_in:0", // required
|
||||||
|
"bank_code" => "required|numeric",
|
||||||
|
"bank_short" => "required|string",
|
||||||
|
"bank_name" => "required|string",
|
||||||
|
"bank_kcp" => "nullable|string",
|
||||||
|
"bank_acc_number" => "required|numeric",
|
||||||
|
"bank_acc_name" => "required|string|max:255",
|
||||||
|
"vendor_id" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if ($req->nik && strlen($req->nik) != 16) {
|
||||||
|
$apiResp = Responses::bad_input("nik must be 16 digit");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if ($req->license_number && strlen($req->license_number) < 12) {
|
||||||
|
$apiResp = Responses::bad_input("license number must be at least 12 digit");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = Drivers::showDriverById($did);
|
||||||
|
if (count($driver) < 1) {
|
||||||
|
$apiResp = Responses::not_found("driver not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->nik) {
|
||||||
|
$uniqNik = Drivers::getDriverByNik($req->nik);
|
||||||
|
if (count($uniqNik) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqNik as $key => $row) {
|
||||||
|
if ($row->id == $did) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("nik has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->phone) {
|
||||||
|
$uniqPhone = Drivers::getDriverByPhone($req->phone);
|
||||||
|
if (count($uniqPhone) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqPhone as $key => $row) {
|
||||||
|
if ($row->id == $did) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->email) {
|
||||||
|
$uniqEmail = Drivers::getDriverByEmail($req->email);
|
||||||
|
if (count($uniqEmail) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqEmail as $key => $row) {
|
||||||
|
if ($row->id == $did) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtDriver = [
|
||||||
|
"nik" => $req->nik ? $req->nik : 0,
|
||||||
|
"fullname" => $req->fullname,
|
||||||
|
"email" => $req->email,
|
||||||
|
"fullname2" => $req->fullname2,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"phone_code" => Drivers::DEFAULT_PHONE_CODE,
|
||||||
|
"phone2" => $req->phone2 ?? 0,
|
||||||
|
"phone2_code" => Drivers::DEFAULT_PHONE_CODE,
|
||||||
|
"dob" => $req->dob,
|
||||||
|
"age" => $req->age ? $req->age : 0,
|
||||||
|
"blood" => $req->blood,
|
||||||
|
"fulladdress" => $req->fulladdress,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$updtDriver["vendor_id"] = $req->auth->uid;
|
||||||
|
} else {
|
||||||
|
$updtDriver["vendor_id"] = Auth::user()->id ?? 0;
|
||||||
|
}
|
||||||
|
Drivers::updateDriver($did, $updtDriver);
|
||||||
|
|
||||||
|
if ($req->ktp_base64) {
|
||||||
|
$url_ktp = "drivers/$did/ktp_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_ktp, base64_decode($req->ktp_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload ktp photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($driver[0]->ktp_img);
|
||||||
|
}
|
||||||
|
if ($req->npwp_base64) {
|
||||||
|
$url_npwp = "drivers/$did/npwp_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_npwp, base64_decode($req->npwp_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload npwp photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($driver[0]->npwp_img);
|
||||||
|
}
|
||||||
|
if ($req->license_base64) {
|
||||||
|
$url_license = "drivers/$did/license_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_license, base64_decode($req->license_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
Storage::disk("public")->delete($url_npwp);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload license photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($driver[0]->license_img);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updtDetail = [
|
||||||
|
"npwp_string" => $req->npwp_string,
|
||||||
|
"npwp_number" => $req->npwp_number,
|
||||||
|
"license_number" => $req->license_number,
|
||||||
|
"license_exp" => $req->license_exp,
|
||||||
|
"em_fullname" => $req->em_fullname,
|
||||||
|
"em_phone" => $req->em_phone,
|
||||||
|
"em_relationship" => $req->em_relationship,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short_name" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_branch_name" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
];
|
||||||
|
if ($req->ktp_base64) {
|
||||||
|
$updtDetail["ktp_img"] = $url_ktp;
|
||||||
|
}
|
||||||
|
if ($req->npwp_base64) {
|
||||||
|
$updtDetail["npwp_img"] = $url_npwp;
|
||||||
|
}
|
||||||
|
if ($req->license_base64) {
|
||||||
|
$updtDetail["license_img"] = $url_license;
|
||||||
|
}
|
||||||
|
DriversDetail::updateDetailByDid($did, $updtDetail);
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success update driver");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_ktp);
|
||||||
|
Storage::disk("public")->delete($url_npwp);
|
||||||
|
Storage::disk("public")->delete($url_license);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_driver(Request $req, $did)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"did" => $did,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"did" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = Drivers::showDriverById($did);
|
||||||
|
if (count($driver) < 1) {
|
||||||
|
$apiResp = Responses::not_found("driver not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Drivers::updateDriver($did, [
|
||||||
|
"dlt" => $now,
|
||||||
|
"dlt_by" => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Storage::disk('public')->delete($driver[0]->ktp_img);
|
||||||
|
// Storage::disk('public')->delete($driver[0]->npwp_img);
|
||||||
|
// Storage::disk('public')->delete($driver[0]->license_img);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success delete driver");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_search_driver_name(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"name" => $req->name,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"name" => "required|string|max:125",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$drivers = Drivers::likeName($req->name);
|
||||||
|
|
||||||
|
if (count($drivers) < 1) {
|
||||||
|
$apiResp = Responses::not_found("driver not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success search driver by name");
|
||||||
|
$apiResp["data"] = $drivers;
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_reset_login_driver(Request $req, $did)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"did" => $did,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"did" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$driver = Drivers::showDriverById($did);
|
||||||
|
if (count($driver) < 1) {
|
||||||
|
$apiResp = Responses::not_found("driver not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
DrvPhoneDevices::dltByOrdDrvId($did);
|
||||||
|
|
||||||
|
$_dtUpdate = [
|
||||||
|
"phone" => $driver[0]->phone,
|
||||||
|
"password" => Hash::make("0" . $driver[0]->phone),
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => Auth::user()->id,
|
||||||
|
];
|
||||||
|
DB::table("t_users")
|
||||||
|
->where("email", $driver[0]->email)
|
||||||
|
->where("status", 1)
|
||||||
|
->whereNull("dlt")
|
||||||
|
->update($_dtUpdate);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success reset login driver");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
233
app/Http/Controllers/DummyController.php
Executable file
233
app/Http/Controllers/DummyController.php
Executable file
@ -0,0 +1,233 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Dummy;
|
||||||
|
|
||||||
|
class DummyController extends Controller
|
||||||
|
{
|
||||||
|
public function api_haversineGreatCircleDistance(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$apiResp = Responses::success();
|
||||||
|
$apiResp['data'] = [];
|
||||||
|
|
||||||
|
// round up with precisions digits = 4
|
||||||
|
|
||||||
|
// $distance == miles
|
||||||
|
// $distance = Helper::haversineGreatCircleDistance($req->start_lat, $req->start_lng, $req->end_lat, $req->end_lng, Helper::EARTH_RADIUS_MILES);
|
||||||
|
// $apiResp['data']['distance_in_km'] = round($distance*1.609, 4);
|
||||||
|
// $apiResp['data']['distance_in_miles'] = round($distance, 4);
|
||||||
|
// $apiResp['data']['distance_in_meters'] = round($distance*1609, 4);
|
||||||
|
|
||||||
|
// $distance == km
|
||||||
|
// $distance = Helper::haversineGreatCircleDistance($req->start_lat, $req->start_lng, $req->end_lat, $req->end_lng, Helper::EARTH_RADIUS_KM);
|
||||||
|
// $apiResp['data']['distance_in_km'] = round($distance, 4);
|
||||||
|
// $apiResp['data']['distance_in_miles'] = round($distance/1.609, 4);
|
||||||
|
// $apiResp['data']['distance_in_meters'] = round($distance*1000, 4);
|
||||||
|
|
||||||
|
// $distance == meters
|
||||||
|
$distance = Helper::haversineGreatCircleDistance($req->start_lat, $req->start_lng, $req->end_lat, $req->end_lng, Helper::EARTH_RADIUS_M);
|
||||||
|
$apiResp['data']['distance_in_km'] = round($distance / 1000, 4);
|
||||||
|
$apiResp['data']['distance_in_miles'] = round($distance / 1609, 4);
|
||||||
|
$apiResp['data']['distance_in_meters'] = round($distance, 4);
|
||||||
|
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_addBatchDummyTracks(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$apiResp = Responses::success();
|
||||||
|
$batch_tracks = $req->batch_tracks;
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
foreach ($batch_tracks as $key => $val) {
|
||||||
|
$batch_tracks[$key]['crt'] = $now;
|
||||||
|
$now = strtotime('+2 seconds', $now);
|
||||||
|
Dummy::addDummyTrack($batch_tracks[$key]);
|
||||||
|
}
|
||||||
|
$apiResp['data'] = $batch_tracks;
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_getTracksBySeconds(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$routes = Dummy::getByGpsId($req->gps_id);
|
||||||
|
if (!isset($routes[0])) {
|
||||||
|
$apiResp = Responses::not_found();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ngebandingin dari row yg belum berbeda ke row berikutnya
|
||||||
|
* jika data: 2,4,6,8,10
|
||||||
|
* diff_sec: 2
|
||||||
|
* results: 2,6,...
|
||||||
|
* diff_sec: 4
|
||||||
|
* results: 2,8,...
|
||||||
|
* diff_sec: 6
|
||||||
|
* results: 2,10,...
|
||||||
|
*/
|
||||||
|
// $start_now = strtotime('+'.$req->sec.' seconds', $routes[0]->crt);
|
||||||
|
// $init_per_chunk = 0;
|
||||||
|
// foreach ($routes as $key => $val) {
|
||||||
|
// if ($init_per_chunk == 1) {
|
||||||
|
// if ($val->crt >= $start_now) {
|
||||||
|
// $start_now = strtotime('+'.$req->sec.' seconds', $routes[$key-1]->crt);
|
||||||
|
// $init_per_chunk = 0;
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// $init_per_chunk = 1;
|
||||||
|
// $chunk_by_sec[] = $val;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ngebandingin dari row yg belum berbeda ke row berikutnya
|
||||||
|
* jika data: 2,4,6,8,10,12,14
|
||||||
|
* diff_sec: 2
|
||||||
|
* results: 2,4,6,8
|
||||||
|
* diff_sec: 4
|
||||||
|
* results: 2,6,10
|
||||||
|
* diff_sec: 6
|
||||||
|
* results: 2,8,14
|
||||||
|
*/
|
||||||
|
$chunk_by_sec = [];
|
||||||
|
$chunk_by_sec[] = $routes[0];
|
||||||
|
foreach ($routes as $key => $val) {
|
||||||
|
$diffSec = $val->crt - end($chunk_by_sec)->crt;
|
||||||
|
if ($diffSec >= $req->sec) {
|
||||||
|
$chunk_by_sec[] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success();
|
||||||
|
$apiResp['total'] = count($chunk_by_sec);
|
||||||
|
$apiResp['data'] = $chunk_by_sec;
|
||||||
|
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_addDummyHub(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'lat' => $req->lat,
|
||||||
|
'lng' => $req->lng,
|
||||||
|
'polygon' => $req->polygon,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string|max:45',
|
||||||
|
'lat' => 'required',
|
||||||
|
'lng' => 'required',
|
||||||
|
'polygon' => 'required|array',
|
||||||
|
'polygon.*.lat' => 'required',
|
||||||
|
'polygon.*.lng' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
DB::rollBack();
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The axis order for coordinates in WKT is Cartesian, so (X Y) or (longitude latitude).
|
||||||
|
* https://stackoverflow.com/questions/29315117/what-is-the-correct-mysql-polygon-format-for-latitude-and-longitude
|
||||||
|
* https://stackoverflow.com/questions/5756232/moving-lat-lon-text-columns-into-a-point-type-column
|
||||||
|
*/
|
||||||
|
|
||||||
|
$ins = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'lat' => $req->lat,
|
||||||
|
'lng' => $req->lng,
|
||||||
|
'lnglat' => DB::raw("ST_GeomFromText('POINT($req->lng $req->lat)')"),
|
||||||
|
'shape' => "ST_GeomFromText('MULTIPOINT(",
|
||||||
|
];
|
||||||
|
foreach ($req->polygon as $key => $val) {
|
||||||
|
$ins['shape'] .= $val['lng'] . " " . $val['lat'].", ";
|
||||||
|
}
|
||||||
|
$ins['shape'] = substr($ins['shape'], 0, -2);
|
||||||
|
$ins['shape'] .= ")')";
|
||||||
|
$ins['shape'] = DB::raw($ins['shape']);
|
||||||
|
// return (new Response($ins['shape'], 200));
|
||||||
|
Dummy::addDummyHub($ins);
|
||||||
|
|
||||||
|
$apiResp = Responses::success();
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_nearestHub(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lat' => $req->lat,
|
||||||
|
'lng' => $req->lng,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lat' => 'required',
|
||||||
|
'lng' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success();
|
||||||
|
/**
|
||||||
|
* The axis order for coordinates in WKT is Cartesian, so (X Y) or (longitude latitude).
|
||||||
|
* https://stackoverflow.com/questions/29315117/what-is-the-correct-mysql-polygon-format-for-latitude-and-longitude
|
||||||
|
* https://stackoverflow.com/questions/5756232/moving-lat-lon-text-columns-into-a-point-type-column
|
||||||
|
*/
|
||||||
|
|
||||||
|
$apiResp['data'] = Dummy::nearestHubInCircle($req->lat, $req->lng);
|
||||||
|
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3599
app/Http/Controllers/FinanceController.php
Executable file
3599
app/Http/Controllers/FinanceController.php
Executable file
File diff suppressed because it is too large
Load Diff
37
app/Http/Controllers/HomeController.php
Executable file
37
app/Http/Controllers/HomeController.php
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class HomeController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
// public function __construct()
|
||||||
|
// {
|
||||||
|
// $this->middleware('auth');
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the application dashboard.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\Support\Renderable
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
return view('home');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_redirect()
|
||||||
|
{
|
||||||
|
if (Auth::guest()) {
|
||||||
|
return redirect(route('login'));
|
||||||
|
}
|
||||||
|
return redirect(route('view_dashboard'));
|
||||||
|
}
|
||||||
|
}
|
||||||
513
app/Http/Controllers/InjectController.php
Executable file
513
app/Http/Controllers/InjectController.php
Executable file
@ -0,0 +1,513 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Validator;
|
||||||
|
use Hidehalo\Nanoid\Client as Nanoid;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Tracks;
|
||||||
|
use App\Models\Zone;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\ClientsDivs;
|
||||||
|
use App\Models\ClientsDivGroups;
|
||||||
|
use App\Models\ConfRates;
|
||||||
|
use App\Models\Region;
|
||||||
|
|
||||||
|
class InjectController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
// GPS Zones.xlsx
|
||||||
|
public function add_gps_zones_v1(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
$apiResp = Responses::bad_request('service unavailable');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'Sheet1' => $req->Sheet1,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'Sheet1' => 'required|array',
|
||||||
|
'Sheet1.*.NAME' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.COMPANY' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.DIVISION' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.GROUP' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.TYPE' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.TYPE ID' => 'required|numeric',
|
||||||
|
'Sheet1.*.COLOR' => 'required|string|min:7|max:7',
|
||||||
|
'Sheet1.*.ADDRESS' => 'required|string',
|
||||||
|
'Sheet1.*.SHIP-TO CODE' => 'nullable|string',
|
||||||
|
'Sheet1.*.SHAPE' => 'required|numeric',
|
||||||
|
'Sheet1.*.BOUNDARY' => 'required|string',
|
||||||
|
'Sheet1.*.GEONAMES' => 'nullable|string',
|
||||||
|
'Sheet1.*.COMPANIES' => 'nullable|string',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
foreach ($req->Sheet1 as $keyTop => $row) {
|
||||||
|
$now = time();
|
||||||
|
$zid = null;
|
||||||
|
$cid = Clients::DEFAULT_CID;
|
||||||
|
$c_div_id = ClientsDivs::DEFAULT_CID;
|
||||||
|
$c_div_group_id = ClientsDivGroups::DEFAULT_CID;
|
||||||
|
$uniqClient = Clients::getClientByName($row['COMPANY']);
|
||||||
|
if (count($uniqClient) > 0) {
|
||||||
|
$cid = $uniqClient[0]->id;
|
||||||
|
} else {
|
||||||
|
$insClient = [
|
||||||
|
'c_name' => $row['COMPANY'],
|
||||||
|
'c_addr_office' => $row['ADDRESS'],
|
||||||
|
'c_phone' => 81288789878,
|
||||||
|
'c_phone_code' => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
'c_mail' => 'inject@gmail.com',
|
||||||
|
'pic_name' => $row['COMPANY'],
|
||||||
|
'pic_phone' => 81288789878,
|
||||||
|
'pic_phone_code' => Clients::DEFAULT_PHONE_CODE,
|
||||||
|
'pic_mail' => 'inject@gmail.com',
|
||||||
|
'c_status' => Clients::CSTTS_ACTIVE,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => Users::DEFAULT_UID,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => Users::DEFAULT_UID,
|
||||||
|
];
|
||||||
|
$cid = Clients::addClient($insClient);
|
||||||
|
}
|
||||||
|
$uniqCDiv = ClientsDivs::getCDivByName($row['DIVISION']);
|
||||||
|
if (count($uniqCDiv) > 0) {
|
||||||
|
$c_div_id = $uniqCDiv[0]->id;
|
||||||
|
} else {
|
||||||
|
$insCDiv = [
|
||||||
|
'client_id' => $cid,
|
||||||
|
'name' => $row['DIVISION'],
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => Users::DEFAULT_UID,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => Users::DEFAULT_UID,
|
||||||
|
];
|
||||||
|
$c_div_id = ClientsDivs::addCDiv($insCDiv);
|
||||||
|
}
|
||||||
|
$uniqCDivGroup = ClientsDivGroups::getCDivGroupByName($row['GROUP']);
|
||||||
|
if (count($uniqCDivGroup) > 0) {
|
||||||
|
$c_div_group_id = $uniqCDivGroup[0]->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqZone = Zone::getZoneByName($row['NAME']);
|
||||||
|
if (count($uniqZone) > 0) {
|
||||||
|
$zid = $uniqZone[0]->id;
|
||||||
|
} else {
|
||||||
|
$boundary_latlngs = [];
|
||||||
|
$radius = 0;
|
||||||
|
$boundary_type = Zone::ZONE_BOUNDARY_POLYGON;
|
||||||
|
$workflow_type = Zone::ZONE_WORKFLOW_DEST;
|
||||||
|
|
||||||
|
if (strpos(strtolower($row['TYPE']), 'bongkar') !== false) {
|
||||||
|
$workflow_type = Zone::ZONE_WORKFLOW_DEST;
|
||||||
|
} else if (strpos(strtolower($row['TYPE']), 'muat') !== false) {
|
||||||
|
$workflow_type = Zone::ZONE_WORKFLOW_PICKUP;
|
||||||
|
} else if (strpos(strtolower($row['TYPE']), 'park') !== false) {
|
||||||
|
$workflow_type = Zone::ZONE_WORKFLOW_PARKING;
|
||||||
|
} else if (strpos(strtolower($row['TYPE']), 'bengkel') !== false) {
|
||||||
|
$workflow_type = Zone::ZONE_WORKFLOW_SERVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$boundarys = explode('|', $row['BOUNDARY']);
|
||||||
|
foreach ($boundarys as $k => $v) {
|
||||||
|
$latLng = explode(',', $v);
|
||||||
|
$boundary_latlngs[] = [
|
||||||
|
'lat' => $latLng[0],
|
||||||
|
'lng' => $latLng[1],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$row['SHAPE']; // 1=>circle,0=>polygon
|
||||||
|
if ($row['SHAPE'] == 1) {
|
||||||
|
$boundary_type = Zone::ZONE_BOUNDARY_CIRCLE;
|
||||||
|
$radius = Helper::haversineGreatCircleDistance($boundary_latlngs[0]['lat'], $boundary_latlngs[0]['lng'], $boundary_latlngs[1]['lat'], $boundary_latlngs[1]['lng']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insZone = [
|
||||||
|
'name' => $row['NAME'],
|
||||||
|
'type' => Zone::ZONE_TYPE_WAREHOUSE,
|
||||||
|
'workflow_type' => $workflow_type,
|
||||||
|
'shiptocode' => 0,
|
||||||
|
'fulladdress' => $row['ADDRESS'],
|
||||||
|
'boundary_type' => $boundary_type,
|
||||||
|
'boundary_hex_color' => strtoupper($row['COLOR']),
|
||||||
|
'boundary_latlngs' => json_encode($boundary_latlngs),
|
||||||
|
'boundary_bounds' => null,
|
||||||
|
'boundary_radius' => $radius,
|
||||||
|
'status' => Zone::STATUS_ACTIVE,
|
||||||
|
'client_group_id' => $cid,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => Users::DEFAULT_UID,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => Users::DEFAULT_UID,
|
||||||
|
];
|
||||||
|
$insZone['boundary_points'] = "ST_GeomFromText('MULTIPOINT(";
|
||||||
|
foreach ($boundary_latlngs as $key => $val) {
|
||||||
|
$insZone['boundary_points'] .= $val['lng'] . " " . $val['lat'] . ", ";
|
||||||
|
}
|
||||||
|
$insZone['boundary_points'] = substr($insZone['boundary_points'], 0, -2); // remove 2 last character
|
||||||
|
$insZone['boundary_points'] .= ")')";
|
||||||
|
$insZone['boundary_points'] = DB::raw($insZone['boundary_points']);
|
||||||
|
|
||||||
|
// dump($insZone);
|
||||||
|
// if ($keyTop == 5) {
|
||||||
|
// dd('stop');
|
||||||
|
// }
|
||||||
|
$zoneId = Zone::addZone($insZone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success inject add new zone');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// B_8074_AS_Positions_01-Feb-2022_06-Feb-2022.xlsx
|
||||||
|
/**
|
||||||
|
* 00000000AB8021AS == 0000000128021119
|
||||||
|
* 000000000B8026AS == 0000000028026119
|
||||||
|
* 000000000B8038AS == 0000000028038119
|
||||||
|
* 000000000B8074AS == 0000000028074119
|
||||||
|
* 000000000B8129AS == 0000000028129119
|
||||||
|
* 000000000B8224AS == 0000000028223119
|
||||||
|
*/
|
||||||
|
public function add_vhc_tracks_v1(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$apiResp = Responses::bad_request('service unavailable');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'Sheet1' => $req->Sheet1,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'Sheet1' => 'required|array',
|
||||||
|
'Sheet1.*.DIVISION' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.GROUP' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.TIMESTAMP' => 'required|string|max:255',
|
||||||
|
'Sheet1.*.VEHICLE' => 'required|string|max:12',
|
||||||
|
'Sheet1.*.DRIVER' => 'nullable|string',
|
||||||
|
'Sheet1.*.ZONE' => 'nullable|string',
|
||||||
|
'Sheet1.*.LOCATION' => 'required|string',
|
||||||
|
'Sheet1.*.LATITUDE' => 'required|string|max:25',
|
||||||
|
'Sheet1.*.LONGITUDE' => 'required|string|max:25',
|
||||||
|
'Sheet1.*.SPEED (kph)' => 'required|numeric',
|
||||||
|
'Sheet1.*.COURSE (°)' => 'required|numeric',
|
||||||
|
'Sheet1.*.IGINITION' => 'nullable|string|max:2',
|
||||||
|
'Sheet1.*.ENGINE STATUS' => 'required|string|max:25',
|
||||||
|
'Sheet1.*.VEHICLE MILEAGE (km)' => 'required|string',
|
||||||
|
'Sheet1.*.FUEL LEVEL (%)' => 'nullable|numeric',
|
||||||
|
'Sheet1.*.POWER TAKEOFF' => 'nullable|numeric',
|
||||||
|
];
|
||||||
|
// pre_milleage, sum_milleage
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
foreach ($req->Sheet1 as $key => $row) {
|
||||||
|
$now = time();
|
||||||
|
$track_id = null;
|
||||||
|
|
||||||
|
$crt = strtotime($row['TIMESTAMP']);
|
||||||
|
$crt_format = date('Y-m-d h:i:s', $crt);
|
||||||
|
|
||||||
|
// $nopol = explode(' ', $row['VEHICLE']);
|
||||||
|
$device_id = '0000000028223119'; // 16 digits
|
||||||
|
|
||||||
|
$ignition = null;
|
||||||
|
if ($row['IGNITION'] == 'ON') {
|
||||||
|
$ignition = 1;
|
||||||
|
} else {
|
||||||
|
$ignition = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$en_status = null;
|
||||||
|
if ($row['ENGINE STATUS'] == 'Moving') {
|
||||||
|
$en_status = 2; // moving
|
||||||
|
} else {
|
||||||
|
$en_status = 1; // idling
|
||||||
|
}
|
||||||
|
|
||||||
|
$insTracks = [
|
||||||
|
'original_hex' => '78781f12',
|
||||||
|
'protocol' => 'gt06',
|
||||||
|
'action' => 'location',
|
||||||
|
'device_id' => $device_id,
|
||||||
|
'latitude' => $row['LATITUDE'],
|
||||||
|
'longitude' => $row['LONGITUDE'],
|
||||||
|
'speed' => $row['SPEED (kph)'] ?? null,
|
||||||
|
'orientation' => $row['COURSE (°)'] ?? null,
|
||||||
|
'ignition' => $ignition, // 1 on, 2 off.
|
||||||
|
'stts_engine' => $en_status, // 1 idling, 2 moving
|
||||||
|
'stts_reverse_geo' => 1, // 1 sudah reverse
|
||||||
|
'pre_milleage' => null,
|
||||||
|
'sum_milleage' => $row['VEHICLE MILEAGE (km)'],
|
||||||
|
'crt' => $crt,
|
||||||
|
'crt_format' => $crt_format,
|
||||||
|
];
|
||||||
|
$track_id = Tracks::addTracks($insTracks);
|
||||||
|
|
||||||
|
$insTracksAddr = [
|
||||||
|
'master_id' => $track_id,
|
||||||
|
'device_id' => $device_id,
|
||||||
|
'type' => 2, // inject
|
||||||
|
'lat' => $row['LATITUDE'],
|
||||||
|
'lng' => $row['LONGITUDE'],
|
||||||
|
'zone_name' => $row['ZONE'] ?? null,
|
||||||
|
'country_id' => 1,
|
||||||
|
'country_code' => 'id',
|
||||||
|
'country_text' => 'INDONESIA',
|
||||||
|
'fulladdress' => $row['LOCATION'] ?? null,
|
||||||
|
'stts_reverse_geo' => 1, // 1 sudah reverse
|
||||||
|
'crt' => $crt,
|
||||||
|
'crt_format' => $crt_format,
|
||||||
|
];
|
||||||
|
Tracks::addTracksAddr($insTracksAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success inject add new tracks');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish Rate Bingkis.xlsx
|
||||||
|
public function add_conf_rate_v1(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$apiResp = Responses::bad_request('service unavailable');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
// $exists = Storage::disk('local')->get('PublishRateBingkis.xlsx');
|
||||||
|
// dd($exists);
|
||||||
|
|
||||||
|
// $file = fopen(__DIR__.'/../../../storage/app/PublishRateBingkis.xlsx', 'r');
|
||||||
|
// //Output lines until EOF is reached
|
||||||
|
// while(! feof($file)) {
|
||||||
|
// $line = fgets($file);
|
||||||
|
// echo $line. "<br>";
|
||||||
|
// }
|
||||||
|
// fclose($file);
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
// dd($req->input());
|
||||||
|
|
||||||
|
// DB::beginTransaction();
|
||||||
|
|
||||||
|
$lanes = ConfRates::getLanesActive();
|
||||||
|
|
||||||
|
foreach ($req['Publish Rate'] as $keyTop => $row) {
|
||||||
|
$nanoid = new Nanoid();
|
||||||
|
$code = $nanoid->formattedId('123456789', 6);
|
||||||
|
|
||||||
|
$uniqCode = ConfRates::getRateByCode($code);
|
||||||
|
if (count($uniqCode) > 0) {
|
||||||
|
$code = $nanoid->formattedId('123456789', 6);
|
||||||
|
$uniqCode = ConfRates::getRateByCode($code);
|
||||||
|
if (count($uniqCode) > 0) {
|
||||||
|
$code = $nanoid->formattedId('123456789', 6);
|
||||||
|
$uniqCode = ConfRates::getRateByCode($code);
|
||||||
|
if (count($uniqCode) > 0) {
|
||||||
|
$code = $nanoid->formattedId('123456789', 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$lead_time = explode('-', $row['Lead Time']);
|
||||||
|
$fast_time = trim($lead_time[0]);
|
||||||
|
if (count($lead_time) == 1) {
|
||||||
|
$long_time = trim($lead_time[0]);
|
||||||
|
} else {
|
||||||
|
$long_time = trim(explode('hari', $lead_time[1])[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lane_id = 0;
|
||||||
|
foreach ($lanes as $k => $v) {
|
||||||
|
if ($lane_id === 0) {
|
||||||
|
if (strpos($v->name, $row['Via']) !== false) {
|
||||||
|
$lane_id = $v->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$prid = Region::getLikeProv($row['Dest Province']);
|
||||||
|
if ($prid) {
|
||||||
|
$prid = $prid[0]->kodeProv;
|
||||||
|
} else {
|
||||||
|
$prid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$city_name = $row['Dest City'];
|
||||||
|
$district_name = $row['Dest City'];
|
||||||
|
if (strpos($row['Dest City'], '(') !== false) {
|
||||||
|
$part = explode('(', $row['Dest City']);
|
||||||
|
$pos = strpos($part[1], ')');
|
||||||
|
$part[1] = substr($part[1], 0, $pos);
|
||||||
|
|
||||||
|
$district_name = trim($part[0]);
|
||||||
|
$city_name = trim($part[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ktid = Region::getLikeCity($city_name);
|
||||||
|
if ($ktid) {
|
||||||
|
$kodeKab = 0;
|
||||||
|
foreach ($ktid as $city) {
|
||||||
|
if ($city->kodeProv == $prid) {
|
||||||
|
$kodeKab = $city->kodeKab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ktid = $kodeKab;
|
||||||
|
} else {
|
||||||
|
$ktid = 0;
|
||||||
|
}
|
||||||
|
$kcid = Region::getLikeDistrict($district_name);
|
||||||
|
if ($kcid) {
|
||||||
|
$kodeKab = $ktid;
|
||||||
|
$kodeKec = 0;
|
||||||
|
foreach ($kcid as $district) {
|
||||||
|
if ($district->kodeProv == $prid) {
|
||||||
|
if ($kodeKab === 0) {
|
||||||
|
$kodeKab = $district->kodeKab;
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
} else {
|
||||||
|
if ($kodeKab === $district->kodeKab) {
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ktid = $kodeKab;
|
||||||
|
$kcid = $kodeKec;
|
||||||
|
} else {
|
||||||
|
$kcid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ktid === 0) {
|
||||||
|
$city_name = trim($part[0]);
|
||||||
|
$district_name = trim($part[1]);
|
||||||
|
|
||||||
|
$ktid = Region::getLikeCity($city_name);
|
||||||
|
if ($ktid) {
|
||||||
|
$kodeKab = 0;
|
||||||
|
foreach ($ktid as $city) {
|
||||||
|
if ($city->kodeProv == $prid) {
|
||||||
|
$kodeKab = $city->kodeKab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ktid = $kodeKab;
|
||||||
|
} else {
|
||||||
|
$ktid = 0;
|
||||||
|
}
|
||||||
|
$kcid = Region::getLikeDistrict($district_name);
|
||||||
|
if ($kcid) {
|
||||||
|
$kodeKab = $ktid;
|
||||||
|
$kodeKec = 0;
|
||||||
|
foreach ($kcid as $district) {
|
||||||
|
if ($district->kodeProv == $prid) {
|
||||||
|
if ($kodeKab === 0) {
|
||||||
|
$kodeKab = $district->kodeKab;
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
} else {
|
||||||
|
if ($kodeKab === $district->kodeKab) {
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$kodeKec = $district->kodeKec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ktid = $kodeKab;
|
||||||
|
$kcid = $kodeKec;
|
||||||
|
} else {
|
||||||
|
$kcid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$insRate = [
|
||||||
|
'code' => $code,
|
||||||
|
'origin_prov' => 31,
|
||||||
|
// 'origin_city' => $row->origin_city,
|
||||||
|
'lane' => $lane_id,
|
||||||
|
'dest_prov' => $prid,
|
||||||
|
'dest_city' => $ktid,
|
||||||
|
'dest_district' => $kcid,
|
||||||
|
'fast_time' => $fast_time,
|
||||||
|
'long_time' => $long_time,
|
||||||
|
'unit_time' => ConfRates::UNIT_DAY,
|
||||||
|
'sell_kg' => (int)str_replace(',', '', str_replace('Rp', '', $row['Sell KG'])),
|
||||||
|
'buy_kg' => (int)str_replace(',', '', str_replace('Rp', '', $row['Buy KG'])),
|
||||||
|
'margin_kg' => (int)str_replace(',', '', str_replace('Rp', '', $row['Margin'])),
|
||||||
|
'percent_kg' => number_format(str_replace('%', '', $row['Persentase']), 2, '.', ','),
|
||||||
|
'sell_cbm' => (int)str_replace(',', '', str_replace('Rp', '', $row[' Sell CBM '])),
|
||||||
|
'buy_cbm' => (int)str_replace(',', '', str_replace('Rp', '', $row[' Buy CBM '])),
|
||||||
|
'margin_cbm' => (int)str_replace(',', '', str_replace('Rp', '', $row['Margin_1'])),
|
||||||
|
'percent_cbm' => number_format(str_replace('%', '', $row['Persentase_1']), 2, '.', ','),
|
||||||
|
'is_active' => ConfRates::IS_ACTIVE,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => 1,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
// dump($insRate);
|
||||||
|
// if ($keyTop > 5) {
|
||||||
|
// dd('stop');
|
||||||
|
// }
|
||||||
|
$rid = ConfRates::addRate($insRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success inject add new conf rate');
|
||||||
|
|
||||||
|
// DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
254
app/Http/Controllers/InsuranceController.php
Executable file
254
app/Http/Controllers/InsuranceController.php
Executable file
@ -0,0 +1,254 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\Insurances;
|
||||||
|
|
||||||
|
class InsuranceController extends Controller
|
||||||
|
{
|
||||||
|
public function view_insurances(Request $req)
|
||||||
|
{
|
||||||
|
return view('menu_v1.configs.insurances');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_insurances(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$list = Insurances::listInsurances();
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list insurances');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_insurance(Request $req, $iid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'iid' => $iid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'iid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance = Insurances::showInsuranceById($iid);
|
||||||
|
if (count($insurance) < 1) {
|
||||||
|
$apiResp = Responses::not_found('insurance not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail insurance');
|
||||||
|
$apiResp['data'] = $insurance[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_insurance(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->name,
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'price' => $req->price,
|
||||||
|
'min_price' => $req->min_price,
|
||||||
|
'max_price' => $req->max_price,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string',
|
||||||
|
'desc' => 'nullable|string',
|
||||||
|
'price' => 'required|numeric|min:0',
|
||||||
|
'min_price' => 'required|numeric|min:0',
|
||||||
|
'max_price' => 'required|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insInsurance = [
|
||||||
|
'premi_name' => $req->name,
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'premi_price' => $req->price,
|
||||||
|
'premi_min_price' => $req->min_price,
|
||||||
|
'premi_max_price' => $req->max_price,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$iid = Insurances::addInsurance($insInsurance);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new insurance');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_insurance(Request $req, $iid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'iid' => $iid,
|
||||||
|
'name' => $req->name,
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'price' => $req->price,
|
||||||
|
'min_price' => $req->min_price,
|
||||||
|
'max_price' => $req->max_price,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'iid' => 'required|integer|not_in:0',
|
||||||
|
'name' => 'required|string',
|
||||||
|
'desc' => 'nullable|string',
|
||||||
|
'price' => 'required|numeric|min:0',
|
||||||
|
'min_price' => 'required|numeric|min:0',
|
||||||
|
'max_price' => 'required|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance = Insurances::showInsuranceById($iid);
|
||||||
|
if (count($insurance) < 1) {
|
||||||
|
$apiResp = Responses::not_found('insurance not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtInsurance = [
|
||||||
|
'premi_name' => $req->name,
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'premi_price' => $req->price,
|
||||||
|
'premi_min_price' => $req->min_price,
|
||||||
|
'premi_max_price' => $req->max_price,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->dest_district) {
|
||||||
|
$updtInsurance['dest_district'] = $req->dest_district;
|
||||||
|
}
|
||||||
|
$iid = Insurances::updateInsurance($iid, $updtInsurance);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update insurance');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_insurance(Request $req, $iid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'iid' => $iid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'iid' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance = Insurances::showInsuranceById($iid);
|
||||||
|
if (count($insurance) < 1) {
|
||||||
|
$apiResp = Responses::not_found('insurance not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Insurances::updateInsurance($iid, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete insurance');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
312
app/Http/Controllers/LogbookKeysController.php
Executable file
312
app/Http/Controllers/LogbookKeysController.php
Executable file
@ -0,0 +1,312 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\LogbookTypes;
|
||||||
|
use App\Models\LogbookKeys;
|
||||||
|
use App\Models\DataTypes;
|
||||||
|
|
||||||
|
class LogbookKeysController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_lgb_keys(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'types' => LogbookTypes::listLgbTypes(['is_active' => LogbookTypes::IS_ACTIVE]),
|
||||||
|
'dtypes' => DataTypes::listDataTypes(['is_active' => DataTypes::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('menu_v1.logbook_keys', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_lgb_keys(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'cptid' => $req->cptid,
|
||||||
|
'is_active' => $req->is_active,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'cptid' => 'nullable|numeric',
|
||||||
|
'is_active' => 'nullable|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['cptid'] != null && $input['cptid'] != 0) {
|
||||||
|
$filter['cptid'] = $input['cptid'];
|
||||||
|
}
|
||||||
|
if ($input['is_active'] != null && $input['is_active'] != 0) {
|
||||||
|
$filter['is_active'] = $input['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = LogbookKeys::listLgbKeys($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list lgb_keys');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_lgb_key(Request $req, $lgb_key_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_key_id' => $lgb_key_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_key_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_key = LogbookKeys::showLgbKey(['lgb_key_id' => $lgb_key_id]);
|
||||||
|
if (count($lgb_key) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook master not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail logbook master');
|
||||||
|
$apiResp['data'] = $lgb_key[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_lgb_key(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->add_name,
|
||||||
|
'type' => $req->add_type,
|
||||||
|
'keys' => $req->add_keys,
|
||||||
|
'units' => $req->add_units,
|
||||||
|
'dtypes' => $req->add_dtypes,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'type' => 'required|numeric|min:0',
|
||||||
|
'keys' => 'required|array',
|
||||||
|
'units' => 'required|array',
|
||||||
|
'dtypes' => 'required|array',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insLgbKey = [
|
||||||
|
'name' => $input['name'],
|
||||||
|
'type' => $input['type'],
|
||||||
|
'keys' => json_encode($input['keys']),
|
||||||
|
'units' => json_encode($input['units']),
|
||||||
|
'dtypes' => json_encode($input['dtypes']),
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$lgb_key_id = LogbookKeys::addLgbKey($insLgbKey);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new logbook master');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_lgb_key(Request $req, $lgb_key_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_key_id' => $lgb_key_id,
|
||||||
|
'name' => $req->updt_name,
|
||||||
|
'type' => $req->updt_type,
|
||||||
|
'keys' => $req->updt_keys,
|
||||||
|
'units' => $req->updt_units,
|
||||||
|
'dtypes' => $req->updt_dtypes,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_key_id' => 'required|integer|not_in:0',
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'type' => 'required|numeric|min:0',
|
||||||
|
'keys' => 'required|array',
|
||||||
|
'units' => 'required|array',
|
||||||
|
'dtypes' => 'required|array',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_key = LogbookKeys::showLgbKey(['lgb_key_id' => $lgb_key_id]);
|
||||||
|
if (count($lgb_key) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook master not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtPocket = [
|
||||||
|
'name' => $input['name'],
|
||||||
|
'type' => $input['type'],
|
||||||
|
'keys' => json_encode($input['keys']),
|
||||||
|
'units' => json_encode($input['units']),
|
||||||
|
'dtypes' => json_encode($input['dtypes']),
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
LogbookKeys::updateLgbKey($input['lgb_key_id'], $updtPocket);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update logbook master');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_lgb_key(Request $req, $lgb_key_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_key_id' => $lgb_key_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_key_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_key = LogbookKeys::showLgbKey(['lgb_key_id' => $lgb_key_id]);
|
||||||
|
if (count($lgb_key) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook master not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
LogbookKeys::updateLgbKey($lgb_key_id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete logbook master');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_selection_lgb_keys(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'is_active' => $req->is_active,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'is_active' => 'nullable|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['is_active'] != null && $input['is_active'] != 0) {
|
||||||
|
$filter['is_active'] = $input['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = LogbookKeys::listLgbKeys($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list logbook master');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
278
app/Http/Controllers/LogbookTypesController.php
Executable file
278
app/Http/Controllers/LogbookTypesController.php
Executable file
@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\LogbookTypes;
|
||||||
|
|
||||||
|
class LogbookTypesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_lgb_types(Request $req)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
return view('menu_v1.logbook_types', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_lgb_types(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'cptid' => $req->cptid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'cptid' => 'nullable|numeric'
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['cptid'] != null && $input['cptid'] != 0) {
|
||||||
|
$filter['cptid'] = $input['cptid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = LogbookTypes::listLgbTypes($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list lgb_types');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_lgb_type(Request $req, $lgb_type_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_type_id' => $lgb_type_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_type_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_type = LogbookTypes::showLgbType(['lgb_type_id' => $lgb_type_id]);
|
||||||
|
if (count($lgb_type) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail logbook type');
|
||||||
|
$apiResp['data'] = $lgb_type[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_lgb_type(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->add_name,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insLgbType = [
|
||||||
|
'name' => $input['name'],
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$lgb_type_id = LogbookTypes::addLgbType($insLgbType);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new lgb_type');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_lgb_type(Request $req, $lgb_type_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_type_id' => $lgb_type_id,
|
||||||
|
'name' => $req->updt_name,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_type_id' => 'required|integer|not_in:0',
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_type = LogbookTypes::showLgbType(['lgb_type_id' => $lgb_type_id]);
|
||||||
|
if (count($lgb_type) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtPocket = [
|
||||||
|
'name' => $input['name'],
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
LogbookTypes::updateLgbType($input['lgb_type_id'], $updtPocket);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update logbook type');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_lgb_type(Request $req, $lgb_type_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'lgb_type_id' => $lgb_type_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'lgb_type_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lgb_type = LogbookTypes::showLgbType(['lgb_type_id' => $lgb_type_id]);
|
||||||
|
if (count($lgb_type) < 1) {
|
||||||
|
$apiResp = Responses::not_found('logbook type not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
LogbookTypes::updateLgbType($lgb_type_id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete logbook type');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_selection_lgb_types(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'is_active' => $req->is_active,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'is_active' => 'nullable|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['is_active'] != null && $input['is_active'] != 0) {
|
||||||
|
$filter['is_active'] = $input['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = LogbookTypes::listLgbTypes($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list logbook type');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
app/Http/Controllers/LoggerController.php
Executable file
75
app/Http/Controllers/LoggerController.php
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
|
||||||
|
class LoggerController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function logger(Request $req)
|
||||||
|
{
|
||||||
|
$now = time();
|
||||||
|
try {
|
||||||
|
$input = [
|
||||||
|
'label' => $req->label,
|
||||||
|
'level' => $req->level,
|
||||||
|
'logtype' => $req->logtype,
|
||||||
|
'keys' => $req->keys,
|
||||||
|
'act' => 'email',
|
||||||
|
'to' => ['rafifmreswara@gmail.com'],
|
||||||
|
'errors' => $req->errors,
|
||||||
|
'vers' => '1.2.1',
|
||||||
|
'source' => 'service',
|
||||||
|
'payloads' => $req->payloads,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'label' => 'required|string',
|
||||||
|
'level' => 'required|numeric',
|
||||||
|
'logtype' => 'required|string',
|
||||||
|
'keys' => 'required|array',
|
||||||
|
'act' => 'required|string',
|
||||||
|
'to' => 'nullable|array',
|
||||||
|
'errors' => 'nullable|string',
|
||||||
|
'vers' => 'required|string',
|
||||||
|
'source' => 'required|string',
|
||||||
|
'payloads' => 'nullable|string',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = Helper::createPayload([
|
||||||
|
'usnme' => 'rafif',
|
||||||
|
'paswd' => 12345678
|
||||||
|
]);
|
||||||
|
$login = Helper::req_post('https://api.simerahputih.com/logger/login', [
|
||||||
|
'Content-Type: application/x-www-form-urlencoded',
|
||||||
|
], $payload);
|
||||||
|
|
||||||
|
// $payload = Helper::createPayload($input);
|
||||||
|
// dd($payload);
|
||||||
|
$resp = Helper::req_post('https://api.simerahputih.com/logger/log', [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'x-api-key: ' . $login['data']->data->token
|
||||||
|
], json_encode($input));
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success send log');
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
dd($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
900
app/Http/Controllers/MenuController.php
Executable file
900
app/Http/Controllers/MenuController.php
Executable file
@ -0,0 +1,900 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Drivers;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
use App\Models\Devices;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\ConfRates;
|
||||||
|
use App\Models\ConfTruckTypes;
|
||||||
|
use App\Models\Zone;
|
||||||
|
use App\Models\Banks;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\OrdersVendors;
|
||||||
|
use App\Models\OrdersItems;
|
||||||
|
use App\Models\OrdersAItems;
|
||||||
|
use App\Models\UnitTypes;
|
||||||
|
use App\Models\AItems;
|
||||||
|
use App\Models\OrdersRates;
|
||||||
|
use App\Models\Finance;
|
||||||
|
use App\Models\OrdersCheckpoints;
|
||||||
|
use App\Models\OrdersInvoices;
|
||||||
|
use App\Models\OrdersDriversUploads;
|
||||||
|
|
||||||
|
class MenuController extends Controller
|
||||||
|
{
|
||||||
|
public function view_dashboard(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"client_group" => Clients::getClientById($req->auth->client_group_id),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (count($data["client_group"]) > 0) {
|
||||||
|
$data["client_group"] = $data["client_group"][0];
|
||||||
|
} else {
|
||||||
|
$data["client_group"] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view("menu_v1.dashboard", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view_drivers(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"bloods" => Helper::listBloods(),
|
||||||
|
"relationships" => Drivers::listRelationships(),
|
||||||
|
"vendors" => Users::listUsersByRole(Users::ROLE_VENDOR),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
return view("menu_v1.drivers", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view_vehicles(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
// 'cats' => Vehicles::listCats(), // default Truck
|
||||||
|
"brands" => Vehicles::listBrands(),
|
||||||
|
"types" => Vehicles::listTypes(),
|
||||||
|
"drivers" => Drivers::getDrivers($req->auth),
|
||||||
|
"vendors" => Users::listUsersByRole(Users::ROLE_VENDOR),
|
||||||
|
"devices" => Devices::listDevices([
|
||||||
|
"is_active" => Devices::IS_ACTIVE,
|
||||||
|
"type" => Devices::TYPE_BUILT_IN,
|
||||||
|
"is_idle_yes" => 1,
|
||||||
|
"is_available" => Devices::IS_AVAIL,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
// dd($data);
|
||||||
|
return view("menu_v1.vehicles", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADMIN TRX
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_transactions()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"availOrdToMerge" => Finance::availOrdToMerge(),
|
||||||
|
];
|
||||||
|
return view("menu_v1.transactions", $data);
|
||||||
|
}
|
||||||
|
public function view_transactions_view__bak(Request $req)
|
||||||
|
{
|
||||||
|
$codes = explode(",", $req->code);
|
||||||
|
$limit = count($codes);
|
||||||
|
if ($limit > 2) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
// dd($codes[0]);
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"codes" => $codes,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_checker_user" => 1,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
"couple_pck_drop" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
"limit" => $limit,
|
||||||
|
]);
|
||||||
|
// dd($orders);
|
||||||
|
if (count($orders) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// uang saku / pocket money
|
||||||
|
$checkpoints = OrdersCheckpoints::listCheckpoints([
|
||||||
|
"ord_id" => $orders[0]->ord_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$bladeViewOrders = [];
|
||||||
|
foreach ($orders as $iOrd => $order) {
|
||||||
|
// get multiple point (pick,drop)
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order->ord_id,
|
||||||
|
"limit" => $order->drop_total,
|
||||||
|
]);
|
||||||
|
// hilangkan index 0, karena yang didapatkan adalah childnya
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$orders[$iOrd]->adtPoints = $adtPoints;
|
||||||
|
|
||||||
|
// uang saku / pocket money
|
||||||
|
$orders[$iOrd]->checkpoints = $checkpoints;
|
||||||
|
|
||||||
|
// formated for blade views
|
||||||
|
$tmpBladeView = clone $order;
|
||||||
|
if ($order->ord_pck_docs_client_img) {
|
||||||
|
$tmpBladeView->ord_pck_docs_client_img = json_decode($order->ord_pck_docs_client_img);
|
||||||
|
}
|
||||||
|
if ($order->ord_acdnt_imgs) {
|
||||||
|
$tmpBladeView->ord_acdnt_imgs = json_decode($order->ord_acdnt_imgs);
|
||||||
|
}
|
||||||
|
$bladeViewOrders[] = clone $tmpBladeView;
|
||||||
|
}
|
||||||
|
$drvs_ups = OrdersDriversUploads::list([
|
||||||
|
"ord_id" => $orders[0]->ord_id,
|
||||||
|
"pck_id" => $orders[0]->ord_pck_id,
|
||||||
|
"drop_id" => $orders[0]->ord_drop_id,
|
||||||
|
"ord_pck_drop_id" => $orders[0]->ord_pck_drop_id,
|
||||||
|
]);
|
||||||
|
$data = [
|
||||||
|
"orders" => $orders,
|
||||||
|
"bladeViewOrders" => $bladeViewOrders,
|
||||||
|
"drvs_ups" => $drvs_ups,
|
||||||
|
"items" => AItems::listAItems([
|
||||||
|
"is_active" => AItems::IS_ACTIVE,
|
||||||
|
"is_adm_price" => AItems::IS_ADM_PRICE_NO,
|
||||||
|
"crt_type" => AItems::CRT_TYPE_ADMIN,
|
||||||
|
]),
|
||||||
|
"unitTypes" => UnitTypes::listUnitTypes([
|
||||||
|
"is_active" => UnitTypes::IS_ACTIVE,
|
||||||
|
"is_publish" => UnitTypes::IS_PUBLISH,
|
||||||
|
]),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
return view("menu_v1._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_transactions_view(Request $req)
|
||||||
|
{
|
||||||
|
$codes = explode(",", $req->code);
|
||||||
|
$limit = count($codes);
|
||||||
|
if ($limit > 2) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"codes" => $codes,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_checker_user" => 1,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
"limit" => $limit,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (count($orders) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$bladeViewOrders = [];
|
||||||
|
foreach ($orders as $iOrd => $order) {
|
||||||
|
// get multiple point (pick,drop)
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order->ord_id,
|
||||||
|
"limit" => $order->drop_total,
|
||||||
|
]);
|
||||||
|
// hilangkan index 0, karena yang didapatkan adalah childnya
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$orders[$iOrd]->adtPoints = $adtPoints;
|
||||||
|
// dd($adtPoints);
|
||||||
|
// formated for blade views
|
||||||
|
$tmpBladeView = clone $order;
|
||||||
|
if ($order->ord_pck_docs_client_img) {
|
||||||
|
$tmpBladeView->ord_pck_docs_client_img = json_decode($order->ord_pck_docs_client_img);
|
||||||
|
}
|
||||||
|
if ($order->ord_acdnt_imgs) {
|
||||||
|
$tmpBladeView->ord_acdnt_imgs = json_decode($order->ord_acdnt_imgs);
|
||||||
|
}
|
||||||
|
$bladeViewOrders[] = clone $tmpBladeView;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rawData = DB::table("t_orders_pck_drop as topd")
|
||||||
|
->leftJoin("t_orders_pickups as top", "top.id", "topd.pck_id")
|
||||||
|
->leftJoin("t_orders_drops as tod", "tod.id", "topd.drop_id")
|
||||||
|
->where("topd.ord_code", $codes)
|
||||||
|
->selectRaw(
|
||||||
|
"topd.id,
|
||||||
|
FROM_UNIXTIME(top.set_pck_at, '%d %M %Y') as pck_date,
|
||||||
|
FROM_UNIXTIME(top.set_pck_at, '%H:%i:%s') as pck_time,
|
||||||
|
top.pck_name,
|
||||||
|
top.pck_addr,
|
||||||
|
tod.drop_name,
|
||||||
|
tod.drop_addr"
|
||||||
|
)
|
||||||
|
->get();
|
||||||
|
foreach ($rawData as $_data) {
|
||||||
|
$ehck = DB::table("t_orders_drivers_uploads")
|
||||||
|
->select(
|
||||||
|
"id", //
|
||||||
|
"checklist_name",
|
||||||
|
"checklist_desc",
|
||||||
|
"img",
|
||||||
|
"updt"
|
||||||
|
)
|
||||||
|
->where("ord_pck_drop_id", $_data->id)
|
||||||
|
->get();
|
||||||
|
$data[] = [
|
||||||
|
"id" => $_data->id,
|
||||||
|
"pck_date" => $_data->pck_date,
|
||||||
|
"pck_time" => $_data->pck_time,
|
||||||
|
"pck_name" => $_data->pck_name,
|
||||||
|
"pck_addr" => $_data->pck_addr,
|
||||||
|
"drop_name" => $_data->drop_name,
|
||||||
|
"drop_addr" => $_data->drop_addr,
|
||||||
|
"checklist_array" => $ehck,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// dd($data[0]["checklist_array"]);
|
||||||
|
// dd($data);
|
||||||
|
$data = [
|
||||||
|
"data" => $data,
|
||||||
|
"orders" => $orders,
|
||||||
|
"bladeViewOrders" => $bladeViewOrders,
|
||||||
|
];
|
||||||
|
// dd($data);
|
||||||
|
return view("menu_v1._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_transactions_view_bak_single(Request $req)
|
||||||
|
{
|
||||||
|
$codes = explode(",", $req->code);
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $codes[0],
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_checker_user" => 1,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$cantConfirmPrice = [Orders::STTS_WAIT, Orders::STTS_CONFIRM, Orders::STTS_HAVE_GET_VHC];
|
||||||
|
$show_confirm_price = 1;
|
||||||
|
if (in_array($order[0]->status, $cantConfirmPrice)) {
|
||||||
|
$show_confirm_price = 0;
|
||||||
|
}
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order[0]->ord_id,
|
||||||
|
"limit" => $order[0]->drop_total,
|
||||||
|
]);
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"adtPoints" => $adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($adtPoints),
|
||||||
|
"items" => AItems::listAItems([
|
||||||
|
"is_active" => AItems::IS_ACTIVE,
|
||||||
|
"is_adm_price" => AItems::IS_ADM_PRICE_NO,
|
||||||
|
"crt_type" => AItems::CRT_TYPE_ADMIN,
|
||||||
|
]),
|
||||||
|
"unitTypes" => UnitTypes::listUnitTypes([
|
||||||
|
"is_active" => UnitTypes::IS_ACTIVE,
|
||||||
|
"is_publish" => UnitTypes::IS_PUBLISH,
|
||||||
|
]),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
return view("menu_v1._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_transactions_confirm(Request $req)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
"center_pck" => 1,
|
||||||
|
"get_prefer_type_truck" => 1,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
if (isset($order[0]->pck_center)) {
|
||||||
|
$split = explode(" ", $order[0]->pck_center);
|
||||||
|
$order[0]->pck_center_lat = substr($split[1], 0, -1);
|
||||||
|
$order[0]->pck_center_lng = substr($split[0], 6);
|
||||||
|
}
|
||||||
|
$rate = OrdersRates::getById($order[0]->ord_rate_id);
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"vendors" => OrdersVendors::searchVendorsByRate([
|
||||||
|
"active_rates" => $rate[0],
|
||||||
|
"prefer_truck_type" => $order[0]->prefer_truck_type,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
return view("menu_v1._confirmTransactions", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ADMIN CONFIG
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_logs_gps()
|
||||||
|
{
|
||||||
|
return view("menu_v1.configs.index_logs_gps");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CLIENT TRX
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_transactions_add(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"uclients" => Users::listUsers([
|
||||||
|
"role" => Users::ROLE_CLIENT_ADMIN,
|
||||||
|
"status" => Users::STATUS_ACTIVE,
|
||||||
|
]),
|
||||||
|
"truck_types" => ConfTruckTypes::listTruckTypesRates(
|
||||||
|
ConfTruckTypes::IS_ACTIVE,
|
||||||
|
ConfRates::LANE_EARTH
|
||||||
|
),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Clients._addTransactions", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view_user_client_transaction()
|
||||||
|
{
|
||||||
|
return view("menu_v2.Clients.transactions");
|
||||||
|
}
|
||||||
|
public function view_user_client_transaction_view(Request $req)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_user_client_transaction"));
|
||||||
|
}
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order[0]->ord_id,
|
||||||
|
"limit" => $order[0]->drop_total,
|
||||||
|
]);
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"adtPoints" => $adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($adtPoints),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Clients._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_user_client_transaction_add(Request $req)
|
||||||
|
{
|
||||||
|
$client_group_id = $req->auth->client_group_id;
|
||||||
|
|
||||||
|
// if ($req->rdl == 1) {
|
||||||
|
// // $inActive = Orders::getOrdersClientActive($req->auth->uid);
|
||||||
|
// $haveOrder = Orders::getOrdersByClient($req->auth->uid, 1);
|
||||||
|
// if (count($haveOrder) > 0) {
|
||||||
|
// return redirect(route('view_user_client_transaction'));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"pickups" => Zone::getActiveZones($client_group_id, 0, Zone::ZONE_WORKFLOW_PICKUP),
|
||||||
|
"drops" => Zone::getActiveZones($client_group_id, 0, Zone::ZONE_WORKFLOW_DEST),
|
||||||
|
"truck_types" => ConfTruckTypes::listTruckTypesRates(
|
||||||
|
ConfTruckTypes::IS_ACTIVE,
|
||||||
|
ConfRates::LANE_EARTH
|
||||||
|
),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Clients._addTransactions", $data);
|
||||||
|
}
|
||||||
|
// public function view_user_client() {
|
||||||
|
// return view('menu_v2.Clients._addTransactions');
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VENDOR TRX
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_user_vendor_transaction()
|
||||||
|
{
|
||||||
|
return view("menu_v2.Vendors.transactions");
|
||||||
|
}
|
||||||
|
public function view_user_vendor_transaction_view(Request $req)
|
||||||
|
{
|
||||||
|
$codes = explode(",", $req->code);
|
||||||
|
$limit = count($codes);
|
||||||
|
if ($limit > 2) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"codes" => $codes,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_checker_user" => 1,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
"limit" => $limit,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (count($orders) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$bladeViewOrders = [];
|
||||||
|
foreach ($orders as $iOrd => $order) {
|
||||||
|
// get multiple point (pick,drop)
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order->ord_id,
|
||||||
|
"limit" => $order->drop_total,
|
||||||
|
]);
|
||||||
|
// hilangkan index 0, karena yang didapatkan adalah childnya
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$orders[$iOrd]->adtPoints = $adtPoints;
|
||||||
|
// dd($adtPoints);
|
||||||
|
// formated for blade views
|
||||||
|
$tmpBladeView = clone $order;
|
||||||
|
if ($order->ord_pck_docs_client_img) {
|
||||||
|
$tmpBladeView->ord_pck_docs_client_img = json_decode($order->ord_pck_docs_client_img);
|
||||||
|
}
|
||||||
|
if ($order->ord_acdnt_imgs) {
|
||||||
|
$tmpBladeView->ord_acdnt_imgs = json_decode($order->ord_acdnt_imgs);
|
||||||
|
}
|
||||||
|
$bladeViewOrders[] = clone $tmpBladeView;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rawData = DB::table("t_orders_pck_drop as topd")
|
||||||
|
->leftJoin("t_orders_pickups as top", "top.id", "topd.pck_id")
|
||||||
|
->leftJoin("t_orders_drops as tod", "tod.id", "topd.drop_id")
|
||||||
|
->where("topd.ord_code", $codes)
|
||||||
|
->selectRaw(
|
||||||
|
"topd.id,
|
||||||
|
FROM_UNIXTIME(top.set_pck_at, '%d %M %Y') as pck_date,
|
||||||
|
FROM_UNIXTIME(top.set_pck_at, '%H:%i:%s') as pck_time,
|
||||||
|
top.pck_name,
|
||||||
|
top.pck_addr,
|
||||||
|
tod.drop_name,
|
||||||
|
tod.drop_addr"
|
||||||
|
)
|
||||||
|
->get();
|
||||||
|
foreach ($rawData as $_data) {
|
||||||
|
$ehck = DB::table("t_orders_drivers_uploads")
|
||||||
|
->select(
|
||||||
|
"id", //
|
||||||
|
"checklist_name",
|
||||||
|
"checklist_desc",
|
||||||
|
"img",
|
||||||
|
"updt"
|
||||||
|
)
|
||||||
|
->where("ord_pck_drop_id", $_data->id)
|
||||||
|
->get();
|
||||||
|
$data[] = [
|
||||||
|
"id" => $_data->id,
|
||||||
|
"pck_date" => $_data->pck_date,
|
||||||
|
"pck_time" => $_data->pck_time,
|
||||||
|
"pck_name" => $_data->pck_name,
|
||||||
|
"pck_addr" => $_data->pck_addr,
|
||||||
|
"drop_name" => $_data->drop_name,
|
||||||
|
"drop_addr" => $_data->drop_addr,
|
||||||
|
"checklist_array" => $ehck,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// dd($data[0]["checklist_array"]);
|
||||||
|
// dd($data);
|
||||||
|
$data = [
|
||||||
|
"data" => $data,
|
||||||
|
"orders" => $orders,
|
||||||
|
"bladeViewOrders" => $bladeViewOrders,
|
||||||
|
];
|
||||||
|
// dd($data);
|
||||||
|
return view("menu_v2.Vendors._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_user_vendor_transaction_view_bak_single(Request $req)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order[0]->ord_id,
|
||||||
|
"limit" => $order[0]->drop_total,
|
||||||
|
]);
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"adtPoints" => $adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($adtPoints),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Vendors._viewTransactions", $data);
|
||||||
|
}
|
||||||
|
public function view_user_vendor_transaction_new_order(Request $req)
|
||||||
|
{
|
||||||
|
// dd($req->code);
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
"get_exp_vendor" => 1,
|
||||||
|
"vdr_id" => $req->auth->uid,
|
||||||
|
"get_bid_info" => 1,
|
||||||
|
]);
|
||||||
|
// dd($order);
|
||||||
|
// if (count($order) < 1) {
|
||||||
|
// return redirect(route("view_user_vendor_transaction"));
|
||||||
|
// }
|
||||||
|
// if ($order[0]->vdr_status !== OrdersVendors::STTS_WAIT) {
|
||||||
|
// return redirect(route("view_user_vendor_transaction"));
|
||||||
|
// }
|
||||||
|
// if (
|
||||||
|
// $order[0]->status === Orders::STTS_WAIT ||
|
||||||
|
// $order[0]->status === Orders::STTS_CONFIRM
|
||||||
|
// ) {
|
||||||
|
// } else {
|
||||||
|
// return redirect(route("view_user_vendor_transaction"));
|
||||||
|
// }
|
||||||
|
// // date('Y-m-d H:i:s', $order[0]->vdr_exp_at);
|
||||||
|
// if ($order[0]->vdr_is_exp === OrdersVendors::LINK_WILL_EXP) {
|
||||||
|
// if ($order[0]->vdr_exp_at < time()) {
|
||||||
|
// return redirect(route("view_user_vendor_transaction"));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if ($order[0]->is_mailing_bid != OrdersVendors::IS_MAILING_BID_SEND) {
|
||||||
|
// return redirect(route("view_user_vendor_transaction"));
|
||||||
|
// }
|
||||||
|
$haveBeenAcc = OrdersVendors::getByOrdIdByStatus($order[0]->ord_id, OrdersVendors::STTS_ACC);
|
||||||
|
if (count($haveBeenAcc) > 0) {
|
||||||
|
return redirect(route("view_user_vendor_transaction"));
|
||||||
|
}
|
||||||
|
$vehicles = Vehicles::getVehiclesInIdsActiveNoInOrder($order[0]->find_vhcs);
|
||||||
|
// $drivers = Drivers::getDriversNoInOrder($req->auth, [
|
||||||
|
// 'status' => Drivers::STTS_ACTIVE
|
||||||
|
// ]);
|
||||||
|
$drivers = Drivers::getDriversNoInOrderNew($req->auth, [
|
||||||
|
"status" => Drivers::STTS_ACTIVE,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"vehicles" => $vehicles,
|
||||||
|
"drivers" => $drivers,
|
||||||
|
];
|
||||||
|
return view("menu_v2.Vendors._newOrder", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CHECKER TRX
|
||||||
|
*/
|
||||||
|
|
||||||
|
// public function view_user_checker()
|
||||||
|
// {
|
||||||
|
// return view('menu_v2.Checker.index');
|
||||||
|
// }
|
||||||
|
// public function view_user_checker_view(Request $req)
|
||||||
|
// {
|
||||||
|
// $order = Orders::showOrder([
|
||||||
|
// 'code' => $req->code,
|
||||||
|
// 'get_stts_checker' => 1,
|
||||||
|
// ]);
|
||||||
|
// if (count($order) < 1) {
|
||||||
|
// return redirect(route('view_user_checker'));
|
||||||
|
// }
|
||||||
|
// $filter = [
|
||||||
|
// 'get_not_deleted' => 1,
|
||||||
|
// ];
|
||||||
|
// $items = OrdersItems::getsByOrdId($order[0]->ord_id, $filter);
|
||||||
|
// $data = [
|
||||||
|
// 'order' => $order[0],
|
||||||
|
// 'items' => $items,
|
||||||
|
// ];
|
||||||
|
// return view('menu_v2.Checker._view', $data);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function view_user_checker()
|
||||||
|
{
|
||||||
|
return view("menu_v2.Checker.index");
|
||||||
|
}
|
||||||
|
public function view_user_checker_view(Request $req)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_prefer_type_truck" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_client_pt" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
"couple_pck_drop" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
"join_pockets" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
]);
|
||||||
|
if (count($orders) < 1) {
|
||||||
|
return redirect(route("view_user_checker"));
|
||||||
|
}
|
||||||
|
$orderOne = clone $orders[0];
|
||||||
|
if ($orders[0]->group_merge_code) {
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"group_merge_code" => $orders[0]->group_merge_code,
|
||||||
|
"get_stts_checker" => 1,
|
||||||
|
"get_prefer_type_truck" => 1,
|
||||||
|
"get_checker_data" => 1,
|
||||||
|
"get_client_pt" => 1,
|
||||||
|
"get_accidents" => 1,
|
||||||
|
"couple_pck_drop" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
"join_pockets" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
"limit" => 2,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// uang saku / pocket money
|
||||||
|
$checkpoints = OrdersCheckpoints::listCheckpoints([
|
||||||
|
"ord_id" => $orders[0]->ord_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$truck_types = ConfTruckTypes::listTruckTypes(ConfTruckTypes::IS_ACTIVE, [
|
||||||
|
"is_publish" => ConfTruckTypes::IS_PUBLISH,
|
||||||
|
]);
|
||||||
|
$bladeViewOrders = [];
|
||||||
|
foreach ($orders as $iOrd => $order) {
|
||||||
|
// get multiple point (pick,drop)
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order->ord_id,
|
||||||
|
"limit" => $order->drop_total,
|
||||||
|
]);
|
||||||
|
// hilangkan index 0, karena yang didapatkan adalah childnya
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$orders[$iOrd]->adtPoints = $adtPoints;
|
||||||
|
|
||||||
|
// uang saku / pocket money
|
||||||
|
$orders[$iOrd]->checkpoints = $checkpoints;
|
||||||
|
|
||||||
|
// formated for blade views
|
||||||
|
$tmpBladeView = clone $order;
|
||||||
|
if ($order->ord_pck_docs_client_img) {
|
||||||
|
$tmpBladeView->ord_pck_docs_client_img = json_decode($order->ord_pck_docs_client_img);
|
||||||
|
}
|
||||||
|
if ($order->ord_acdnt_imgs) {
|
||||||
|
$tmpBladeView->ord_acdnt_imgs = json_decode($order->ord_acdnt_imgs);
|
||||||
|
}
|
||||||
|
$bladeViewOrders[] = clone $tmpBladeView;
|
||||||
|
|
||||||
|
// special case for checker, karena meskipun merge tapi tampilnya tetap 1-1 per trx
|
||||||
|
if ($req->code === $order->ord_code) {
|
||||||
|
$orderOne = clone $order;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$drvs_ups = OrdersDriversUploads::list([
|
||||||
|
"ord_id" => $orders[0]->ord_id,
|
||||||
|
"pck_id" => $orders[0]->ord_pck_id,
|
||||||
|
"drop_id" => $orders[0]->ord_drop_id,
|
||||||
|
"ord_pck_drop_id" => $orders[0]->ord_pck_drop_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"orders" => $orders,
|
||||||
|
"drvs_ups" => $drvs_ups,
|
||||||
|
"order" => $orderOne,
|
||||||
|
"truck_types" => $truck_types,
|
||||||
|
"adtPoints" => $orders[0]->adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($orders[0]->adtPoints),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Checker._view", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FINANCE
|
||||||
|
*/
|
||||||
|
public function view_keuangan_payment()
|
||||||
|
{
|
||||||
|
return view("menu_v2.Finance.payment");
|
||||||
|
}
|
||||||
|
public function view_keuangan_payment_view(Request $req)
|
||||||
|
{
|
||||||
|
$codes = explode(",", $req->code);
|
||||||
|
$limit = count($codes);
|
||||||
|
if ($limit > 2) {
|
||||||
|
return redirect(route("view_transactions"));
|
||||||
|
}
|
||||||
|
$orders = Orders::showOrder([
|
||||||
|
"codes" => $codes,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_pic_zone" => 1,
|
||||||
|
// 'get_stts_checker' => 1,
|
||||||
|
// 'get_checker_data' => 1,
|
||||||
|
// 'get_checker_user' => 1,
|
||||||
|
// 'get_accidents' => 1,
|
||||||
|
"couple_pck_drop" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
"group_by" => "ord.id",
|
||||||
|
"limit" => $limit,
|
||||||
|
]);
|
||||||
|
if (count($orders) < 1) {
|
||||||
|
return redirect(route("view_keuangan_payment"));
|
||||||
|
}
|
||||||
|
$bladeViewOrders = [];
|
||||||
|
foreach ($orders as $iOrd => $order) {
|
||||||
|
// get multiple point (pick,drop)
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order->ord_id,
|
||||||
|
"limit" => $order->drop_total,
|
||||||
|
]);
|
||||||
|
// hilangkan index 0, karena yang didapatkan adalah childnya
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
$orders[$iOrd]->adtPoints = $adtPoints;
|
||||||
|
|
||||||
|
// formated for blade views
|
||||||
|
$tmpBladeView = clone $order;
|
||||||
|
// if ($order->ord_pck_docs_client_img) $tmpBladeView->ord_pck_docs_client_img = json_decode($order->ord_pck_docs_client_img);
|
||||||
|
// if ($order->ord_acdnt_imgs) $tmpBladeView->ord_acdnt_imgs = json_decode($order->ord_acdnt_imgs);
|
||||||
|
$bladeViewOrders[] = clone $tmpBladeView;
|
||||||
|
}
|
||||||
|
|
||||||
|
$drvs_ups = OrdersDriversUploads::list([
|
||||||
|
"ord_id" => $orders[0]->ord_id,
|
||||||
|
"pck_id" => $orders[0]->ord_pck_id,
|
||||||
|
"drop_id" => $orders[0]->ord_drop_id,
|
||||||
|
"ord_pck_drop_id" => $orders[0]->ord_pck_drop_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"orders" => $orders,
|
||||||
|
"bladeViewOrders" => $bladeViewOrders,
|
||||||
|
"drvs_ups" => $drvs_ups,
|
||||||
|
"items" => AItems::listAItems([
|
||||||
|
"is_active" => AItems::IS_ACTIVE,
|
||||||
|
"crt_type" => AItems::CRT_TYPE_FINANCE,
|
||||||
|
]),
|
||||||
|
"unitTypes" => UnitTypes::listUnitTypes([
|
||||||
|
"is_active" => UnitTypes::IS_ACTIVE,
|
||||||
|
"is_publish" => UnitTypes::IS_PUBLISH,
|
||||||
|
]),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
"availOrdToMerge" => Finance::availOrdToMerge([
|
||||||
|
"except_ord_id" => $orders[0]->ord_id,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Finance._viewPayment", $data);
|
||||||
|
}
|
||||||
|
public function view_keuangan_payment_view_single_bak(Request $req)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_pic_zone" => 1,
|
||||||
|
// 'get_stts_checker' => 1,
|
||||||
|
// 'get_checker_data' => 1,
|
||||||
|
// 'get_checker_user' => 1,
|
||||||
|
// 'get_accidents' => 1,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_keuangan_payment"));
|
||||||
|
}
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order[0]->ord_id,
|
||||||
|
"limit" => $order[0]->drop_total,
|
||||||
|
]);
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"adtPoints" => $adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($adtPoints),
|
||||||
|
"items" => AItems::listAItems([
|
||||||
|
"is_active" => AItems::IS_ACTIVE,
|
||||||
|
"crt_type" => AItems::CRT_TYPE_FINANCE,
|
||||||
|
]),
|
||||||
|
"unitTypes" => UnitTypes::listUnitTypes([
|
||||||
|
"is_active" => UnitTypes::IS_ACTIVE,
|
||||||
|
"is_publish" => UnitTypes::IS_PUBLISH,
|
||||||
|
]),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
"availOrdToMerge" => Finance::availOrdToMerge([
|
||||||
|
"except_ord_id" => $order[0]->ord_id,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
return view("menu_v2.Finance._viewPayment", $data);
|
||||||
|
}
|
||||||
|
public function view_keuangan_billing()
|
||||||
|
{
|
||||||
|
return view("menu_v2.Finance.billing");
|
||||||
|
}
|
||||||
|
public function view_keuangan_billing_view(Request $req)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder([
|
||||||
|
"code" => $req->code,
|
||||||
|
// 'get_prefer_type_truck' => 1,
|
||||||
|
"get_additional_vehicles_info" => 1,
|
||||||
|
"get_pic_zone" => 1,
|
||||||
|
// 'get_stts_checker' => 1,
|
||||||
|
// 'get_checker_data' => 1,
|
||||||
|
// 'get_checker_user' => 1,
|
||||||
|
// 'get_accidents' => 1,
|
||||||
|
"get_client_pt" => 1,
|
||||||
|
"couple_pck_drop" => 1,
|
||||||
|
"get_user_aprv_pck" => 1,
|
||||||
|
]);
|
||||||
|
if (count($order) < 1) {
|
||||||
|
return redirect(route("view_keuangan_billing"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$a_items = Finance::listAdtItemsBillings([
|
||||||
|
"ord_id" => $order[0]->ord_id,
|
||||||
|
"group_by" => "ord_a_item.id",
|
||||||
|
"is_bill_aprv" => OrdersAItems::IS_APRV_YES,
|
||||||
|
]);
|
||||||
|
$group_items_by_termin = [];
|
||||||
|
foreach ($a_items as $i => $row) {
|
||||||
|
if (!isset($group_items_by_termin[$row->c_group_termin_id])) {
|
||||||
|
if (
|
||||||
|
$row->a_item_type === OrdersAItems::A_TYPE_PRIMARY &&
|
||||||
|
$row->stts_merge !== OrdersAItems::STTS_MERGE_RESULT
|
||||||
|
) {
|
||||||
|
$row->previous_termin = OrdersAItems::showAItem([
|
||||||
|
"ord_id" => $row->ord_id,
|
||||||
|
"is_active" => OrdersAItems::IS_ACTIVE_YES,
|
||||||
|
"a_item_type" => OrdersAItems::A_TYPE_PRIMARY,
|
||||||
|
"prev_main_item_id" => $row->ord_a_item_id,
|
||||||
|
"c_termin_id_not_zero" => 1,
|
||||||
|
"limit" => 1,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$group_items_by_termin[$row->c_group_termin_id] = [];
|
||||||
|
$group_items_by_termin[$row->c_group_termin_id][] = $row;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$group_items_by_termin[$row->c_group_termin_id][] = $row;
|
||||||
|
}
|
||||||
|
$adtPoints = Orders::getPoints([
|
||||||
|
"id" => $order[0]->ord_id,
|
||||||
|
"limit" => $order[0]->drop_total,
|
||||||
|
]);
|
||||||
|
array_splice($adtPoints, 0, 1);
|
||||||
|
|
||||||
|
$drvs_ups = OrdersDriversUploads::list([
|
||||||
|
"ord_id" => $order[0]->ord_id,
|
||||||
|
"pck_id" => $order[0]->ord_pck_id,
|
||||||
|
"drop_id" => $order[0]->ord_drop_id,
|
||||||
|
"ord_pck_drop_id" => $order[0]->ord_pck_drop_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"order" => $order[0],
|
||||||
|
"adtPoints" => $adtPoints,
|
||||||
|
"adtPointsJson" => json_encode($adtPoints),
|
||||||
|
"drvs_ups" => $drvs_ups,
|
||||||
|
"items" => AItems::listAItems([
|
||||||
|
"is_active" => AItems::IS_ACTIVE,
|
||||||
|
"crt_type" => AItems::CRT_TYPE_FINANCE,
|
||||||
|
]),
|
||||||
|
"unitTypes" => UnitTypes::listUnitTypes([
|
||||||
|
"is_active" => UnitTypes::IS_ACTIVE,
|
||||||
|
"is_publish" => UnitTypes::IS_PUBLISH,
|
||||||
|
]),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
"group_items_by_termin" => $group_items_by_termin,
|
||||||
|
];
|
||||||
|
return view("menu_v2.Finance._viewBilling", $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
87
app/Http/Controllers/OSMController.php
Executable file
87
app/Http/Controllers/OSMController.php
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Zone;
|
||||||
|
|
||||||
|
class OSMController extends Controller
|
||||||
|
{
|
||||||
|
public function api_geo_addr(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'address' => $req->address,
|
||||||
|
'country_code' => $req->country_code,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'address' => 'required|string|min:45',
|
||||||
|
'country_code' => 'required|string|min:2',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'countrycodes' => $req->country_code,
|
||||||
|
'format' => 'geojson',
|
||||||
|
'q' => $req->address,
|
||||||
|
];
|
||||||
|
$payload = http_build_query($payload);
|
||||||
|
// $url = env('API_URL_NOMINATIM') . '/search?format=geojson&countrycodes=' . $req->country_code . '&q=' . $req->address;
|
||||||
|
$url = env('API_URL_NOMINATIM') . '/search?' . $payload;
|
||||||
|
|
||||||
|
// $respNominatim = Helper::req_get($url, [
|
||||||
|
// 'User-Agent: PostmanRuntime/7.28.4',
|
||||||
|
// 'Accept: */*',
|
||||||
|
// 'Accept-Encoding: gzip, deflate, br',
|
||||||
|
// 'Connection: keep-alive'
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
$guzReq = new GuzzleClient();
|
||||||
|
$respNominatim = $guzReq->request('GET', $url, [
|
||||||
|
'headers' => [
|
||||||
|
'Host' => $_SERVER['SERVER_ADDR'] ?? '127.0.0.1',
|
||||||
|
'User-Agent' => 'curl/7.65.3',
|
||||||
|
'Accept' => '*/*',
|
||||||
|
'Accept-Encoding' => 'gzip, deflate, br',
|
||||||
|
// 'Connection' => 'keep-alive',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($respNominatim->getStatusCode() != 200) {
|
||||||
|
$apiResp = Responses::bad_request('fail geo address');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = json_decode($respNominatim->getBody()->getContents());
|
||||||
|
$data = null;
|
||||||
|
if (count($body->features) > 0) {
|
||||||
|
$data = [
|
||||||
|
'lat' => $body->features[0]->geometry->coordinates[1],
|
||||||
|
'lng' => $body->features[0]->geometry->coordinates[0],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success geo address');
|
||||||
|
$apiResp['data'] = $data;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
498
app/Http/Controllers/PocketController.php
Executable file
498
app/Http/Controllers/PocketController.php
Executable file
@ -0,0 +1,498 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use Hidehalo\Nanoid\Client as Nanoid;
|
||||||
|
use Hidehalo\Nanoid\GeneratorInterface as NanoidInterface;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\PocketMoney;
|
||||||
|
use App\Models\Checkpoints;
|
||||||
|
use App\Models\Zone;
|
||||||
|
|
||||||
|
class PocketController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function view_pockets(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'types' => PocketMoney::getTypes(),
|
||||||
|
'flows' => PocketMoney::getFlows(),
|
||||||
|
// 'clients' => Clients::listClients(['c_status' => Clients::CSTTS_ACTIVE]),
|
||||||
|
// 'pickups' => Zone::listZones($req->auth, ['is_active' => Zone::STATUS_ACTIVE, 'type' => Zone::ZONE_TYPE_WAREHOUSE, 'workflow_type' => Zone::ZONE_WORKFLOW_PICKUP]),
|
||||||
|
// 'drops' => Zone::listZones($req->auth, ['is_active' => Zone::STATUS_ACTIVE, 'type' => Zone::ZONE_TYPE_WAREHOUSE, 'workflow_type' => Zone::ZONE_WORKFLOW_DEST]),
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('menu_v1.configs.pocket_money', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_pockets(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [
|
||||||
|
'cptid' => $req->cptid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'cptid' => 'nullable|numeric'
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
$filter = [];
|
||||||
|
if ($input['cptid'] != null && $input['cptid'] != 0) {
|
||||||
|
$filter['cptid'] = $input['cptid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = PocketMoney::listPockets($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list pockets');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_pocket(Request $req, $pocket_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'pocket_id' => $pocket_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'pocket_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pocket = PocketMoney::showPocketById($pocket_id);
|
||||||
|
if (count($pocket) < 1) {
|
||||||
|
$apiResp = Responses::not_found('pocket not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$pocket[0]->checkpoints = Checkpoints::listCheckpoints(['pocket_id' => $pocket[0]->id]);
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail pocket');
|
||||||
|
$apiResp['data'] = $pocket[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_pocket(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->add_name,
|
||||||
|
'type' => $req->add_type,
|
||||||
|
'pck' => $req->add_pck,
|
||||||
|
'drop' => $req->add_drop,
|
||||||
|
'price' => $req->add_price,
|
||||||
|
'start_checkpoint' => $req->add_start_checkpoints,
|
||||||
|
// 'end_checkpoint' => $req->add_end_checkpoints,
|
||||||
|
'price_checkpoint' => $req->add_price_checkpoints,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'type' => 'required|numeric|min:0',
|
||||||
|
'pck' => 'required|numeric|min:0',
|
||||||
|
'drop' => 'required|numeric|min:0',
|
||||||
|
'price' => 'required|numeric|min:0',
|
||||||
|
'start_checkpoint' => 'nullable|array',
|
||||||
|
'start_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
// 'end_checkpoint' => 'nullable|array',
|
||||||
|
// 'end_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
'price_checkpoint' => 'nullable|array',
|
||||||
|
'price_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nanoid = new Nanoid();
|
||||||
|
$code = $nanoid->formattedId('0123456789', 9);
|
||||||
|
// $code = $now;
|
||||||
|
$doWhile = true;
|
||||||
|
do {
|
||||||
|
if (substr($code, 0, 1) == 0) {
|
||||||
|
$code = $nanoid->formattedId('0123456789', 9);
|
||||||
|
} else {
|
||||||
|
$doWhile = false;
|
||||||
|
}
|
||||||
|
} while ($doWhile);
|
||||||
|
$uniqCode = PocketMoney::getPocketByCode($code);
|
||||||
|
if (count($uniqCode) > 0) {
|
||||||
|
$apiResp = Responses::bad_request('code has been used, try again');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// $uniqPckDrop = PocketMoney::getPocketByPckDrop($input['pck'], $input['drop']);
|
||||||
|
// if (count($uniqPckDrop) > 0) {
|
||||||
|
// $apiResp = Responses::bad_request('Pickup dan Drop sudah pernah ditambahkan');
|
||||||
|
// return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ($input['start_checkpoint']) {
|
||||||
|
if ($input['start_checkpoint'][0] != $input['pck']) {
|
||||||
|
$apiResp = Responses::bad_request('Titik lokasi pertama checkpoint haruslah sama dengan pickup');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pck = Zone::showZoneById($input['pck']);
|
||||||
|
if (count($pck) < 1) {
|
||||||
|
$apiResp = Responses::not_found('lokasi pickup tidak ditemukan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$drop = Zone::showZoneById($input['drop']);
|
||||||
|
if (count($drop) < 1) {
|
||||||
|
$apiResp = Responses::not_found('lokasi drop tidak ditemukan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pck[0]->client_group_id !== $drop[0]->client_group_id) {
|
||||||
|
$apiResp = Responses::bad_request('Lokasi pickup dan drop sudah beda perusahaan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insPocket = [
|
||||||
|
'code' => $code,
|
||||||
|
'name' => $input['name'],
|
||||||
|
'type' => $input['type'],
|
||||||
|
'flow' => PocketMoney::FLOW_HYBRID,
|
||||||
|
'pck_id' => $input['pck'],
|
||||||
|
'drop_id' => $input['drop'],
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'total' => 0,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$pocket_id = PocketMoney::addPocket($insPocket);
|
||||||
|
|
||||||
|
$total = 0;
|
||||||
|
if ($input['start_checkpoint']) {
|
||||||
|
foreach ($input['start_checkpoint'] as $i => $row) {
|
||||||
|
$insCheckpoint = [
|
||||||
|
'pocket_id' => $pocket_id,
|
||||||
|
'pck_id' => $input['start_checkpoint'][$i],
|
||||||
|
// 'drop_id' => $input['end_checkpoint'][$i],
|
||||||
|
'total' => $input['price_checkpoint'][$i],
|
||||||
|
'sort' => $i + 1,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$total += $input['price_checkpoint'][$i];
|
||||||
|
Checkpoints::addCheckpoint($insCheckpoint);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$insCheckpoint = [
|
||||||
|
'pocket_id' => $pocket_id,
|
||||||
|
'pck_id' => $input['pck'],
|
||||||
|
'drop_id' => $input['drop'],
|
||||||
|
'total' => $input['price'],
|
||||||
|
'sort' => 1,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$total += $input['price'];
|
||||||
|
Checkpoints::addCheckpoint($insCheckpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
PocketMoney::updatePocket($pocket_id, ['total' => $total]);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new pocket');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_pocket(Request $req, $pocket_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'pocket_id' => $pocket_id,
|
||||||
|
'name' => $req->updt_name,
|
||||||
|
'type' => $req->updt_type,
|
||||||
|
'pck' => $req->updt_pck,
|
||||||
|
'drop' => $req->updt_drop,
|
||||||
|
'price' => $req->updt_price,
|
||||||
|
'start_checkpoint' => $req->updt_start_checkpoints,
|
||||||
|
// 'end_checkpoint' => $req->updt_end_checkpoints,
|
||||||
|
'price_checkpoint' => $req->updt_price_checkpoints,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'pocket_id' => 'required|integer|not_in:0',
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'type' => 'required|numeric|min:0',
|
||||||
|
'pck' => 'required|numeric|min:0',
|
||||||
|
'drop' => 'required|numeric|min:0',
|
||||||
|
'price' => 'required|numeric|min:0',
|
||||||
|
'start_checkpoint' => 'nullable|array',
|
||||||
|
'start_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
// 'end_checkpoint' => 'nullable|array',
|
||||||
|
// 'end_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
'price_checkpoint' => 'nullable|array',
|
||||||
|
'price_checkpoint.*' => 'nullable|numeric|min:0',
|
||||||
|
'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pocket = PocketMoney::showPocketById($pocket_id);
|
||||||
|
if (count($pocket) < 1) {
|
||||||
|
$apiResp = Responses::not_found('pocket not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$pocket[0]->checkpoints = Checkpoints::listCheckpoints(['pocket_id' => $pocket[0]->id]);
|
||||||
|
|
||||||
|
if ($input['start_checkpoint']) {
|
||||||
|
if ($input['start_checkpoint'][0] != $input['pck']) {
|
||||||
|
$apiResp = Responses::bad_request('Titik lokasi pertama checkpoint haruslah sama dengan pickup');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pck = Zone::showZoneById($input['pck']);
|
||||||
|
if (count($pck) < 1) {
|
||||||
|
$apiResp = Responses::not_found('lokasi pickup tidak ditemukan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$drop = Zone::showZoneById($input['drop']);
|
||||||
|
if (count($drop) < 1) {
|
||||||
|
$apiResp = Responses::not_found('lokasi drop tidak ditemukan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pck[0]->client_group_id !== $drop[0]->client_group_id) {
|
||||||
|
$apiResp = Responses::bad_request('Lokasi pickup dan drop sudah beda perusahaan');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtPocket = [
|
||||||
|
// 'code' => $code,
|
||||||
|
'type' => $input['type'],
|
||||||
|
'name' => $input['name'],
|
||||||
|
// 'flow' => PocketMoney::FLOW_HYBRID,
|
||||||
|
'pck_id' => $input['pck'],
|
||||||
|
'drop_id' => $input['drop'],
|
||||||
|
'is_active' => $input['status'],
|
||||||
|
'total' => 0,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
PocketMoney::updatePocket($input['pocket_id'], $updtPocket);
|
||||||
|
|
||||||
|
$total = 0;
|
||||||
|
if ($input['start_checkpoint']) {
|
||||||
|
Checkpoints::deleteCheckpointByPocketId($input['pocket_id']);
|
||||||
|
foreach ($input['start_checkpoint'] as $i => $row) {
|
||||||
|
$insCheckpoint = [
|
||||||
|
'pocket_id' => $input['pocket_id'],
|
||||||
|
'pck_id' => $input['start_checkpoint'][$i],
|
||||||
|
// 'drop_id' => $input['end_checkpoint'][$i],
|
||||||
|
'total' => $input['price_checkpoint'][$i],
|
||||||
|
'sort' => $i + 1,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$total += $input['price_checkpoint'][$i];
|
||||||
|
Checkpoints::addCheckpoint($insCheckpoint);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Checkpoints::deleteCheckpointByPocketId($input['pocket_id']);
|
||||||
|
$updtCheckpoint = [
|
||||||
|
'pocket_id' => $input['pocket_id'],
|
||||||
|
'pck_id' => $input['pck'],
|
||||||
|
'drop_id' => $input['drop'],
|
||||||
|
'total' => $input['price'],
|
||||||
|
'sort' => 1,
|
||||||
|
'crt' => $now,
|
||||||
|
'crt_by' => $req->auth->uid,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
$total += $input['price'];
|
||||||
|
// Checkpoints::updateCheckpoint($pocket[0]->checkpoints[0]->id, $updtCheckpoint);
|
||||||
|
Checkpoints::addCheckpoint($updtCheckpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
PocketMoney::updatePocket($input['pocket_id'], ['total' => $total]);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update pocket');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_pocket(Request $req, $pocket_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'pocket_id' => $pocket_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'pocket_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pocket = PocketMoney::showPocketById($pocket_id);
|
||||||
|
if (count($pocket) < 1) {
|
||||||
|
$apiResp = Responses::not_found('pocket not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
$pocket[0]->checkpoints = Checkpoints::listCheckpoints(['pocket_id' => $pocket[0]->id]);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
PocketMoney::updatePocket($pocket_id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($pocket[0]->checkpoints as $row) {
|
||||||
|
Checkpoints::updateCheckpoint($row->id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete pocket');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_pck_drop_pocket(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'client_id' => $req->client_id,
|
||||||
|
'pck_id' => $req->pck_id,
|
||||||
|
'drop_id' => $req->drop_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'client_id' => 'required|integer|not_in:0',
|
||||||
|
'pck_id' => 'required|integer|not_in:0',
|
||||||
|
'drop_id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pockets = PocketMoney::listPockets([
|
||||||
|
'cptid' => $input['client_id'],
|
||||||
|
'pck_id' => $input['pck_id'],
|
||||||
|
'drop_id' => $input['drop_id'],
|
||||||
|
'is_active' => PocketMoney::IS_ACTIVE,
|
||||||
|
]);
|
||||||
|
if (count($pockets) < 1) {
|
||||||
|
$apiResp = Responses::not_found('pocket not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($pockets as $i => $pkt) {
|
||||||
|
$pockets[$i]->checkpoints = Checkpoints::listCheckpoints(['pocket_id' => $pkt->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get pockets');
|
||||||
|
$apiResp['data'] = $pockets;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
100
app/Http/Controllers/RegionController.php
Executable file
100
app/Http/Controllers/RegionController.php
Executable file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Zone;
|
||||||
|
use App\Models\Region;
|
||||||
|
|
||||||
|
class RegionController extends Controller
|
||||||
|
{
|
||||||
|
public function api_list_city(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'kodeProv' => $req->kodeProv,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'kodeProv' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get list district');
|
||||||
|
$apiResp['data'] = Region::listCity($req->kodeProv);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_list_district(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'kodeKab' => $req->kodeKab,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'kodeKab' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get list village');
|
||||||
|
$apiResp['data'] = Region::listDistrict($req->kodeKab);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_list_village(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'kodeKec' => $req->kodeKec,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'kodeKec' => 'required|numeric',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get list village');
|
||||||
|
$apiResp['data'] = Region::listVillage($req->kodeKec);
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
146
app/Http/Controllers/StaticInsuranceController.php
Executable file
146
app/Http/Controllers/StaticInsuranceController.php
Executable file
@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\StaticInsurances;
|
||||||
|
|
||||||
|
class StaticInsuranceController extends Controller
|
||||||
|
{
|
||||||
|
public function view_static_insurances(Request $req)
|
||||||
|
{
|
||||||
|
return view('menu_v1.configs.static_insurances');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_static_insurances(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$list = StaticInsurances::listStaticInsurances();
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list insurances');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_static_insurance(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance = StaticInsurances::getInsuranceById($id);
|
||||||
|
if (count($insurance) < 1) {
|
||||||
|
$apiResp = Responses::not_found('insurance not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail insurance');
|
||||||
|
$apiResp['data'] = $insurance[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_static_insurance(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'amt_percent' => $req->amt_percent,
|
||||||
|
// 'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
'desc' => 'required|string',
|
||||||
|
'amt_percent' => 'required|numeric|min:0',
|
||||||
|
// 'status' => 'required|numeric|min:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insurance = StaticInsurances::getInsuranceById($id);
|
||||||
|
if (count($insurance) < 1) {
|
||||||
|
$apiResp = Responses::not_found('insurance not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtInsurance = [
|
||||||
|
'desc' => $req->desc,
|
||||||
|
'amt_percent' => $req->amt_percent,
|
||||||
|
// 'is_active' => $req->status,
|
||||||
|
'updt' => $now,
|
||||||
|
'updt_by' => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->dest_district) {
|
||||||
|
$updtInsurance['dest_district'] = $req->dest_district;
|
||||||
|
}
|
||||||
|
$id = StaticInsurances::updateInsurance($id, $updtInsurance);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update insurance');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
79
app/Http/Controllers/StorageController.php
Executable file
79
app/Http/Controllers/StorageController.php
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Validator;
|
||||||
|
use Hidehalo\Nanoid\Client as Nanoid;
|
||||||
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
|
||||||
|
class StorageController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function save_photos(Request $req)
|
||||||
|
{
|
||||||
|
|
||||||
|
$url_photos_base64 = [];
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'names' => $req->names,
|
||||||
|
'photos' => $req->photos,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'names' => 'required|array',
|
||||||
|
'names.*' => 'required|string|max:255',
|
||||||
|
'photos' => 'required|array',
|
||||||
|
'photos.*' => 'required|string',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->names && count($req->names) < 1) {
|
||||||
|
$apiResp = Responses::bad_input('names is required');
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
if ($req->photos && count($req->photos) < 1) {
|
||||||
|
$apiResp = Responses::bad_input('photos is required');
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($req->photos as $i => $img) {
|
||||||
|
$clearBase64 = preg_replace('/^data:(image|application)\/(png|jpg|jpeg|pdf);base64,/', '', $img);
|
||||||
|
// $type = 'jpeg';
|
||||||
|
// if (strpos($img, 'application/pdf') !== false) $type = 'pdf';
|
||||||
|
// $url_photos_base64[$i] = "orders/" . $order[0]->ord_id . "/a_items/" . $oa_id . "/submission/" . $req->auth->uid . "/submission_proof_img_$now" . "_" . "$i.$type";
|
||||||
|
$url_photos_base64[$i] = $req->names[$i];
|
||||||
|
if (!Storage::disk('public')->put($url_photos_base64[$i], base64_decode($clearBase64))) {
|
||||||
|
$apiResp = Responses::bad_request('fail save photo');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success save photos');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if (count($url_photos_base64) > 0) {
|
||||||
|
foreach ($url_photos_base64 as $path) {
|
||||||
|
Storage::disk('public')->delete($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
249
app/Http/Controllers/TrackController.php
Executable file
249
app/Http/Controllers/TrackController.php
Executable file
@ -0,0 +1,249 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Tracks;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
use App\Models\Zone;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Orders;
|
||||||
|
|
||||||
|
class TrackController extends Controller
|
||||||
|
{
|
||||||
|
public function api_list_currect_track_vhc(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
$filter = [
|
||||||
|
"get_order_data" => 1,
|
||||||
|
];
|
||||||
|
if ($req->cptid) {
|
||||||
|
$filter["company"] = $req->cptid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->auth->is_tracking === Users::IS_TRACK_VHC_YES) {
|
||||||
|
if ($req->auth->vhcs) {
|
||||||
|
$filter["vids"] = explode(",", $req->auth->vhcs);
|
||||||
|
} else {
|
||||||
|
$filter["vid"] = 0;
|
||||||
|
}
|
||||||
|
} elseif ($req->auth->is_tracking === Users::IS_TRACK_VHC_DEFAULT) {
|
||||||
|
if ($req->auth->role === Users::ROLE_ADMIN) {
|
||||||
|
if ($req->ord_id) {
|
||||||
|
$ord = Orders::showOrder(["id" => $req->ord_id]);
|
||||||
|
if (count($ord) > 0) {
|
||||||
|
$filter["vid"] = $ord[0]->vhc_id;
|
||||||
|
} else {
|
||||||
|
$filter["vid"] = 0;
|
||||||
|
}
|
||||||
|
} elseif ($req->ord_code) {
|
||||||
|
$ord = Orders::showOrder(["code" => $req->ord_code]);
|
||||||
|
if (count($ord) > 0) {
|
||||||
|
$filter["vid"] = $ord[0]->vhc_id;
|
||||||
|
} else {
|
||||||
|
$filter["vid"] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($req->auth->role === Users::ROLE_VENDOR) {
|
||||||
|
$filter["own_by_vdr_id"] = $req->auth->uid;
|
||||||
|
} elseif ($req->auth->role === Users::ROLE_CLIENT_ADMIN) {
|
||||||
|
$ords = Orders::listOrders([
|
||||||
|
"client_id_active_orders" => $req->auth->uid,
|
||||||
|
"is_accident" => Orders::IS_ACCIDENT_NO,
|
||||||
|
]);
|
||||||
|
$filter["vids"] = [];
|
||||||
|
$filter["client_id"] = $req->auth->uid;
|
||||||
|
foreach ($ords as $k => $v) {
|
||||||
|
$filter["vids"][] = $v->vhc_id;
|
||||||
|
}
|
||||||
|
} elseif ($req->auth->role === Users::ROLE_SPECIAL_TRACKING) {
|
||||||
|
// $filter['vid'] = 0;
|
||||||
|
$filter["company"] = $req->auth->client_group_id;
|
||||||
|
} else {
|
||||||
|
$filter["vid"] = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filter["vid"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = Tracks::listCurrentTracks($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
// $list[$key]->mileage_km = '-';
|
||||||
|
$list[$key]->track_schedule = $row->track_sch_h . "/" . $row->track_sch_d; // combine track_sch_h + track_sch_d
|
||||||
|
$list[$key]->is_track_holiday_text =
|
||||||
|
$list[$key]->is_track_holiday == Vehicles::ENABLED_TRACK_HOLIDAY ? "Enabled" : "Disabled";
|
||||||
|
$list[$key]->alert_zones = "-";
|
||||||
|
$list[$key]->cameras = "-";
|
||||||
|
|
||||||
|
$insideZones = [];
|
||||||
|
$insideZoneCircle = Zone::insideZoneCircle($row->lst_lat, $row->lst_lng);
|
||||||
|
if (count($insideZoneCircle) > 0) {
|
||||||
|
array_push($insideZones, ...$insideZoneCircle);
|
||||||
|
}
|
||||||
|
$insideZoneShape = Zone::insideZoneShape($row->lst_lat, $row->lst_lng);
|
||||||
|
if (count($insideZoneShape) > 0) {
|
||||||
|
array_push($insideZones, ...$insideZoneShape);
|
||||||
|
}
|
||||||
|
if (count($insideZones) > 0) {
|
||||||
|
$list[$key]->inside_zones = $insideZones;
|
||||||
|
} else {
|
||||||
|
$list[$key]->inside_zones = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$apiResp = Responses::success("success list vehicles");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_last_move_track_vhc(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"vid" => $req->vid,
|
||||||
|
"end_at" => $req->end_at,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"vid" => "required|integer",
|
||||||
|
"end_at" => "nullable|date",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = [
|
||||||
|
"limit" => 500,
|
||||||
|
];
|
||||||
|
// default 500, jika ada filter date maka max 5K
|
||||||
|
if (
|
||||||
|
$req->start_date != null &&
|
||||||
|
$req->start_date != "" &&
|
||||||
|
($req->end_date != null && $req->end_date != "")
|
||||||
|
) {
|
||||||
|
$filter["start_date"] = $req->start_date;
|
||||||
|
$filter["end_date"] = $req->end_date;
|
||||||
|
$filter["limit"] = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = Tracks::lastMoveTracks($req->vid, $filter);
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get last movements");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_conf_list_logs_gps(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$filter = [
|
||||||
|
"limit" => 1000,
|
||||||
|
"crt_greater_than" => 1646122574,
|
||||||
|
];
|
||||||
|
|
||||||
|
$list = Tracks::listLogsGps($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success list gps tracker");
|
||||||
|
$apiResp["count"] = count($list);
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_track_order(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$ord = [];
|
||||||
|
$filter = [
|
||||||
|
"get_pic_zone" => 1,
|
||||||
|
"get_zone_data" => 1,
|
||||||
|
];
|
||||||
|
if ($req->ord_id) {
|
||||||
|
$filter["id"] = $req->ord_id;
|
||||||
|
} elseif ($req->ord_code) {
|
||||||
|
$filter["code"] = $req->ord_code;
|
||||||
|
}
|
||||||
|
$ord = Orders::showOrder($filter);
|
||||||
|
|
||||||
|
if (count($ord) < 1) {
|
||||||
|
$apiResp = Responses::not_found("order not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vid = $ord[0]->vhc_id;
|
||||||
|
|
||||||
|
$history = Tracks::lastMoveTracks($vid, [
|
||||||
|
"start_at" => $ord[0]->confirm_at,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success track order");
|
||||||
|
$apiResp["data"] = [
|
||||||
|
"order" => $ord[0],
|
||||||
|
"history" => $history,
|
||||||
|
];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5590
app/Http/Controllers/TransactionController.php
Executable file
5590
app/Http/Controllers/TransactionController.php
Executable file
File diff suppressed because it is too large
Load Diff
1850
app/Http/Controllers/TransactionSpcController.php
Executable file
1850
app/Http/Controllers/TransactionSpcController.php
Executable file
File diff suppressed because it is too large
Load Diff
2280
app/Http/Controllers/TransactionSpcController.php.bak
Executable file
2280
app/Http/Controllers/TransactionSpcController.php.bak
Executable file
File diff suppressed because it is too large
Load Diff
1845
app/Http/Controllers/TransactionSpcController_bak_many_to_many.php
Executable file
1845
app/Http/Controllers/TransactionSpcController_bak_many_to_many.php
Executable file
File diff suppressed because it is too large
Load Diff
651
app/Http/Controllers/UsersController.php
Executable file
651
app/Http/Controllers/UsersController.php
Executable file
@ -0,0 +1,651 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Clients;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
use App\Models\Banks;
|
||||||
|
use App\Models\UsersMenuPermissions;
|
||||||
|
|
||||||
|
class UsersController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function view_users(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"roles" => Users::listRoles($req->auth->role),
|
||||||
|
"pernus" => UsersMenuPermissions::listPermissionsMenus([
|
||||||
|
"is_active" => UsersMenuPermissions::IS_ACTIVE,
|
||||||
|
]),
|
||||||
|
"vehicles" => Vehicles::getVehicles(),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->auth->role == Users::ROLE_SUPERADMIN) {
|
||||||
|
$data["clients"] = Clients::select2Client();
|
||||||
|
} elseif ($req->auth->role == Users::ROLE_ADMIN) {
|
||||||
|
$data["clients"] = Clients::select2Client();
|
||||||
|
} else {
|
||||||
|
$data["clients"] = Clients::select2Client($req->auth->client_group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view("menu_v1.users", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view_profile(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
"roles" => Users::listRoles($req->auth->role),
|
||||||
|
"pernus" => UsersMenuPermissions::listPermissionsMenus([
|
||||||
|
"is_active" => UsersMenuPermissions::IS_ACTIVE,
|
||||||
|
]),
|
||||||
|
"vehicles" => Vehicles::getVehicles(),
|
||||||
|
"banks" => Banks::listBanks(["is_active" => Banks::IS_ACTIVE]),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->auth->role == Users::ROLE_SUPERADMIN) {
|
||||||
|
$data["clients"] = Clients::select2Client();
|
||||||
|
} elseif ($req->auth->role == Users::ROLE_ADMIN) {
|
||||||
|
$data["clients"] = Clients::select2Client();
|
||||||
|
} else {
|
||||||
|
$data["clients"] = Clients::select2Client($req->auth->client_group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view("menu_v1._profile", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_users(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$filter = [];
|
||||||
|
if ($req->cptid) {
|
||||||
|
$filter["company"] = $req->cptid;
|
||||||
|
}
|
||||||
|
$list = Users::listUsers($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->count_trx = 0;
|
||||||
|
$list[$key]->action = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success list users");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
$apiResp["count"] = count($list);
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_user(Request $req, $uid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"uid" => $uid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"uid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = Users::showUserById($uid);
|
||||||
|
if (count($user) < 1) {
|
||||||
|
$apiResp = Responses::not_found("user not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get detail user");
|
||||||
|
$apiResp["data"] = $user[0];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_user(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$roles = Users::arrRoles();
|
||||||
|
$statuses = Users::arrStatus();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"first_name" => $req->first_name,
|
||||||
|
"last_name" => $req->last_name,
|
||||||
|
"phone" => $req->phone,
|
||||||
|
"email" => $req->email,
|
||||||
|
"fulladdress" => $req->fulladdress,
|
||||||
|
"password" => $req->password,
|
||||||
|
"clients_id" => $req->clients,
|
||||||
|
"roles" => $req->roles,
|
||||||
|
"chk_type" => $req->chk_type,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_kcp" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
"status" => $req->status,
|
||||||
|
"is_tracking" => $req->is_tracking,
|
||||||
|
"vehicles" => $req->vehicles,
|
||||||
|
"is_vdr_bcng" => $req->is_vdr_bcng,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"first_name" => "required|string|max:125",
|
||||||
|
"last_name" => "nullable|max:125",
|
||||||
|
"phone" => "required|numeric",
|
||||||
|
"email" => "required|email",
|
||||||
|
"fulladdress" => "required|string|min:45",
|
||||||
|
"password" => "required|string|max:25",
|
||||||
|
"clients_id" => "required|integer|not_in:0",
|
||||||
|
"roles" => "required|integer|not_in:0",
|
||||||
|
"chk_type" => "nullable|integer|not_in:0",
|
||||||
|
"bank_id" => "nullable|integer|not_in:0",
|
||||||
|
"bank_code" => "nullable|numeric",
|
||||||
|
"bank_short" => "nullable|string",
|
||||||
|
"bank_name" => "nullable|string",
|
||||||
|
"bank_kcp" => "nullable|string",
|
||||||
|
"bank_acc_number" => "nullable|numeric",
|
||||||
|
"bank_acc_name" => "nullable|string|max:255",
|
||||||
|
"status" => "required|integer|not_in:0",
|
||||||
|
"is_tracking" => "nullable|numeric",
|
||||||
|
"vehicles" => "nullable|array",
|
||||||
|
"is_vdr_bcng" => "nullable|numeric",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($req->roles, $roles)) {
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_request("role not valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($req->status, $statuses)) {
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_request("status not valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->roles == Users::ROLE_VENDOR) {
|
||||||
|
if (!$req->bank_id) {
|
||||||
|
$apiResp = Responses::bad_request("bank wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if (!$req->bank_acc_number) {
|
||||||
|
$apiResp = Responses::bad_request("nomor rekening wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if (!$req->bank_acc_name) {
|
||||||
|
$apiResp = Responses::bad_request("nama pemilik rekening wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->clients) {
|
||||||
|
$clients = Clients::getClientById($req->clients);
|
||||||
|
if (count($clients) < 1) {
|
||||||
|
$apiResp = Responses::not_found("clients not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqEmail = Users::getUserByEmail($req->email);
|
||||||
|
if (count($uniqEmail) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqPhone = Users::getUserByPhone((int) $req->phone);
|
||||||
|
if (count($uniqPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqCPhone = Clients::getClientByPhone((int) $req->phone);
|
||||||
|
if (count($uniqCPhone) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vhcs = null;
|
||||||
|
if ($req->is_tracking == Users::IS_TRACK_VHC_YES) {
|
||||||
|
if (!$req->vehicles) {
|
||||||
|
$apiResp = Responses::bad_request("vehicles must be filled");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
foreach ($req->vehicles as $k => $v) {
|
||||||
|
$vhcs .= $v . ",";
|
||||||
|
}
|
||||||
|
if ($vhcs) {
|
||||||
|
if (substr($vhcs, -1) === ",") {
|
||||||
|
$vhcs = substr($vhcs, 0, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"first_name" => $req->first_name,
|
||||||
|
"last_name" => $req->last_name ?? null,
|
||||||
|
"email" => $req->email,
|
||||||
|
"phone" => (int) $req->phone,
|
||||||
|
"phone_code" => Users::DEFAULT_PHONE_CODE,
|
||||||
|
"fulladdress" => $req->fulladdress,
|
||||||
|
"password" => Hash::make($req->password),
|
||||||
|
"role" => $req->roles,
|
||||||
|
"client_id" => $req->clients,
|
||||||
|
"client_group_id" => $req->clients,
|
||||||
|
"status" => $req->status,
|
||||||
|
"is_tracking" => $req->is_tracking,
|
||||||
|
"vhcs" => $vhcs,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->roles == Users::ROLE_CHECKER) {
|
||||||
|
// $data['chk_type'] = $req->chk_type;
|
||||||
|
$data["chk_type"] = Users::CHK_TYPE_ALL;
|
||||||
|
}
|
||||||
|
if ($req->roles == Users::ROLE_VENDOR) {
|
||||||
|
$data["bank_id"] = $req->bank_id;
|
||||||
|
$data["bank_code"] = $req->bank_code;
|
||||||
|
$data["bank_name"] = $req->bank_name;
|
||||||
|
$data["bank_short_name"] = $req->bank_short;
|
||||||
|
$data["bank_branch_name"] = $req->bank_branch_name;
|
||||||
|
$data["bank_acc_number"] = $req->bank_acc_number;
|
||||||
|
$data["bank_acc_name"] = $req->bank_acc_name;
|
||||||
|
$data["is_vdr_bcng"] = $req->is_vdr_bcng;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Users::addUser($data);
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success add new user");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_user(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$roles = Users::arrRoles();
|
||||||
|
$statuses = Users::arrStatus();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"uid" => $req->uid,
|
||||||
|
"is_tracking" => $req->is_tracking,
|
||||||
|
"vehicles" => $req->vehicles,
|
||||||
|
"bank_id" => $req->bank_id,
|
||||||
|
"bank_code" => $req->bank_code,
|
||||||
|
"bank_short" => $req->bank_short,
|
||||||
|
"bank_name" => $req->bank_name,
|
||||||
|
"bank_kcp" => $req->bank_branch_name,
|
||||||
|
"bank_acc_number" => $req->bank_acc_number,
|
||||||
|
"bank_acc_name" => $req->bank_acc_name,
|
||||||
|
"is_vdr_bcng" => $req->is_vdr_bcng,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"uid" => "required|integer|not_in:0",
|
||||||
|
"is_tracking" => "nullable|numeric",
|
||||||
|
"vehicles" => "nullable|array",
|
||||||
|
"bank_id" => "nullable|integer|not_in:0",
|
||||||
|
"bank_code" => "nullable|numeric",
|
||||||
|
"bank_short" => "nullable|string",
|
||||||
|
"bank_name" => "nullable|string",
|
||||||
|
"bank_kcp" => "nullable|string",
|
||||||
|
"bank_acc_number" => "nullable|numeric",
|
||||||
|
"bank_acc_name" => "nullable|string|max:255",
|
||||||
|
"is_vdr_bcng" => "nullable|numeric",
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
"id" => $req->uid,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->first_name) {
|
||||||
|
$input["first_name"] = $req->first_name;
|
||||||
|
$rulesInput["first_name"] = "required|string|max:125";
|
||||||
|
$data["first_name"] = $req->first_name;
|
||||||
|
}
|
||||||
|
if ($req->last_name) {
|
||||||
|
$input["last_name"] = $req->last_name;
|
||||||
|
$rulesInput["last_name"] = "required|string|max:125";
|
||||||
|
$data["last_name"] = $req->last_name ?? null;
|
||||||
|
}
|
||||||
|
if ($req->email) {
|
||||||
|
$input["email"] = $req->email;
|
||||||
|
$rulesInput["email"] = "required|email";
|
||||||
|
$data["email"] = $req->email;
|
||||||
|
}
|
||||||
|
if ($req->phone) {
|
||||||
|
$input["phone"] = $req->phone;
|
||||||
|
$rulesInput["phone"] = "required|integer|not_in:0";
|
||||||
|
$data["phone"] = $req->phone;
|
||||||
|
$data["phone_code"] = Users::DEFAULT_PHONE_CODE;
|
||||||
|
}
|
||||||
|
if ($req->fulladdress) {
|
||||||
|
$input["fulladdress"] = $req->fulladdress;
|
||||||
|
$rulesInput["fulladdress"] = "required|string|min:45";
|
||||||
|
$data["fulladdress"] = $req->fulladdress;
|
||||||
|
}
|
||||||
|
if ($req->password) {
|
||||||
|
$input["password"] = $req->password;
|
||||||
|
$rulesInput["password"] = "required|string";
|
||||||
|
$data["password"] = Hash::make($req->password);
|
||||||
|
}
|
||||||
|
if ($req->clients) {
|
||||||
|
$input["clients"] = $req->clients;
|
||||||
|
$rulesInput["clients"] = "required|integer|not_in:0";
|
||||||
|
$data["client_group_id"] = $req->clients;
|
||||||
|
|
||||||
|
$clients = Clients::getClientById($req->clients);
|
||||||
|
if (count($clients) < 1) {
|
||||||
|
$apiResp = Responses::not_found("clients not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->roles) {
|
||||||
|
$input["roles"] = $req->roles;
|
||||||
|
$rulesInput["roles"] = "required|integer|not_in:0";
|
||||||
|
$data["role"] = $req->roles;
|
||||||
|
|
||||||
|
if (in_array($req->roles, $roles)) {
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_request("role not valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->roles) {
|
||||||
|
if ($req->roles == Users::ROLE_CHECKER) {
|
||||||
|
// $data['chk_type'] = $req->chk_type;
|
||||||
|
$data["chk_type"] = Users::CHK_TYPE_ALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($req->status) {
|
||||||
|
$input["status"] = $req->status;
|
||||||
|
$rulesInput["status"] = "required|integer|not_in:0";
|
||||||
|
$data["status"] = $req->status;
|
||||||
|
|
||||||
|
if (in_array($req->status, $statuses)) {
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_request("status not valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$getUser = Users::getUserById($req->uid);
|
||||||
|
if (count($getUser) < 1) {
|
||||||
|
$apiResp = Responses::not_found("user not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->roles == Users::ROLE_VENDOR) {
|
||||||
|
if (!$req->bank_id) {
|
||||||
|
$apiResp = Responses::bad_request("bank wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if (!$req->bank_branch_name) {
|
||||||
|
$apiResp = Responses::bad_request("bank kcp wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if (!$req->bank_acc_number) {
|
||||||
|
$apiResp = Responses::bad_request("nomor rekening wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
if (!$req->bank_acc_name) {
|
||||||
|
$apiResp = Responses::bad_request("nama pemilik rekening wajib diisi");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqEmail = Users::getUserByEmail($req->email);
|
||||||
|
if (count($uniqEmail) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqEmail as $key => $row) {
|
||||||
|
if ($row->id == $req->uid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("email has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uniqPhone = Users::getUserByPhone($req->phone);
|
||||||
|
if (count($uniqPhone) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqPhone as $key => $row) {
|
||||||
|
if ($row->id == $req->uid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("phone has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// $uniqCPhone = Clients::getClientByPhone($req->phone);
|
||||||
|
// if (count($uniqCPhone) > 0) {
|
||||||
|
// $notSameUser = 1;
|
||||||
|
// foreach ($uniqCPhone as $key => $row) {
|
||||||
|
// if ($row->id == $getUser[0]->client_id) {
|
||||||
|
// $notSameUser = 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if ($notSameUser) {
|
||||||
|
// $apiResp = Responses::bad_request('phone has been used');
|
||||||
|
// return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$vhcs = null;
|
||||||
|
if ($req->is_tracking == Users::IS_TRACK_VHC_YES) {
|
||||||
|
if (!$req->vehicles) {
|
||||||
|
$apiResp = Responses::bad_request("vehicles must be filled");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
foreach ($req->vehicles as $k => $v) {
|
||||||
|
$vhcs .= $v . ",";
|
||||||
|
}
|
||||||
|
if ($vhcs) {
|
||||||
|
if (substr($vhcs, -1) === ",") {
|
||||||
|
$vhcs = substr($vhcs, 0, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data["is_tracking"] = $req->is_tracking;
|
||||||
|
$data["vhcs"] = $vhcs;
|
||||||
|
|
||||||
|
if ($req->roles == Users::ROLE_VENDOR) {
|
||||||
|
$data["bank_id"] = $req->bank_id;
|
||||||
|
$data["bank_code"] = $req->bank_code;
|
||||||
|
$data["bank_name"] = $req->bank_name;
|
||||||
|
$data["bank_short_name"] = $req->bank_short;
|
||||||
|
$data["bank_branch_name"] = $req->bank_branch_name;
|
||||||
|
$data["bank_acc_number"] = $req->bank_acc_number;
|
||||||
|
$data["bank_acc_name"] = $req->bank_acc_name;
|
||||||
|
$data["is_vdr_bcng"] = $req->is_vdr_bcng;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data["updt"] = $now;
|
||||||
|
$data["updt_by"] = $req->auth->uid;
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Users::updateUser($req->uid, $data);
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success update user");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_user(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"uid" => $req->uid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"uid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
"id" => $req->uid,
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$getUser = Users::getUserById($req->uid);
|
||||||
|
if (count($getUser) < 1) {
|
||||||
|
$apiResp = Responses::not_found("user not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data["dlt"] = $now;
|
||||||
|
$data["dlt_by"] = $req->auth->uid;
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
Users::updateUser($req->uid, $data);
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success delete user");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_search_user_name(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$roles = Users::arrRoles();
|
||||||
|
$statuses = Users::arrStatus();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"name" => $req->name,
|
||||||
|
"roles" => $req->roles,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"name" => "required|string|max:125",
|
||||||
|
"roles" => "nullable|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->roles) {
|
||||||
|
if (in_array($req->roles, $roles)) {
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_request("role not valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$users = Users::likeName($req->name, $req->roles);
|
||||||
|
} else {
|
||||||
|
$users = Users::likeName($req->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($users) < 1) {
|
||||||
|
$apiResp = Responses::not_found("user not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($users as $k => $v) {
|
||||||
|
// remove from array but no reindex array
|
||||||
|
// unset($users[$k]);
|
||||||
|
// remove from array and reindex array
|
||||||
|
// array_splice($users, $k, 1);
|
||||||
|
unset($users[$k]->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success search user by name");
|
||||||
|
$apiResp["data"] = $users;
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
358
app/Http/Controllers/UsersMenuPermissionsController.php
Executable file
358
app/Http/Controllers/UsersMenuPermissionsController.php
Executable file
@ -0,0 +1,358 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Validator;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\UsersMenuPermissions;
|
||||||
|
|
||||||
|
class UsersMenuPermissionsController extends Controller
|
||||||
|
{
|
||||||
|
public function view_menu_permissions(Request $req)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $req->auth,
|
||||||
|
];
|
||||||
|
return view('menu_v1.configs.usersMenuPermissions', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function api_list_menu_permissions(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
$filter = [];
|
||||||
|
|
||||||
|
$list = UsersMenuPermissions::listPermissionsMenus($filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
$list[$key]->action = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success list menu permissions');
|
||||||
|
$apiResp['count'] = count($list);
|
||||||
|
$apiResp['data'] = $list;
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_menu_permissions(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$permis = UsersMenuPermissions::showPermissionsMenusById($id);
|
||||||
|
if (count($permis) < 1) {
|
||||||
|
$apiResp = Responses::not_found('permissions not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success get detail permissions');
|
||||||
|
$apiResp['data'] = $permis[0];
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_menu_permissions(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->name,
|
||||||
|
// menu admin
|
||||||
|
'menu_trx' => $req->menu_trx,
|
||||||
|
'menu_company' => $req->menu_company,
|
||||||
|
'menu_zone' => $req->menu_zone,
|
||||||
|
'menu_users' => $req->menu_users,
|
||||||
|
'menu_conf_rates' => $req->menu_conf_rates,
|
||||||
|
'menu_conf_insurance' => $req->menu_conf_insurance,
|
||||||
|
'menu_conf_truck_type' => $req->menu_conf_truck_type,
|
||||||
|
'menu_devices' => $req->menu_devices,
|
||||||
|
'menu_logs_devices' => $req->menu_logs_devices,
|
||||||
|
'menu_conf_adt_items' => $req->menu_conf_adt_items,
|
||||||
|
'menu_drivers' => $req->menu_drivers,
|
||||||
|
'menu_vehicles' => $req->menu_vehicles,
|
||||||
|
'menu_menu_permission' => $req->menu_menu_permission,
|
||||||
|
// menu finance
|
||||||
|
'menu_fnc_ledger_balance' => $req->menu_fnc_ledger_balance,
|
||||||
|
'menu_fnc_payment' => $req->menu_fnc_payment,
|
||||||
|
'menu_fnc_billing' => $req->menu_fnc_billing,
|
||||||
|
'menu_fnc_conf_adt_items' => $req->menu_fnc_conf_adt_items,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string',
|
||||||
|
// menu admin
|
||||||
|
'menu_trx' => 'required|numeric|max:2',
|
||||||
|
'menu_company' => 'required|numeric|max:2',
|
||||||
|
'menu_zone' => 'required|numeric|max:2',
|
||||||
|
'menu_users' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_rates' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_insurance' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_truck_type' => 'required|numeric|max:2',
|
||||||
|
'menu_devices' => 'required|numeric|max:2',
|
||||||
|
'menu_logs_devices' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_adt_items' => 'required|numeric|max:2',
|
||||||
|
'menu_drivers' => 'required|numeric|max:2',
|
||||||
|
'menu_vehicles' => 'required|numeric|max:2',
|
||||||
|
'menu_menu_permission' => 'required|numeric|max:2',
|
||||||
|
// menu finance
|
||||||
|
'menu_fnc_ledger_balance' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_payment' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_billing' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_conf_adt_items' => 'required|numeric|max:2',
|
||||||
|
'status' => 'required|integer|min:0|max:2',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$isAdmin = 0;
|
||||||
|
$isFinance = 0;
|
||||||
|
if ($req->menu_trx || $req->menu_company || $req->menu_zone || $req->menu_users || $req->menu_conf_rates || $req->menu_conf_insurance || $req->menu_conf_truck_type || $req->menu_devices || $req->menu_logs_devices || $req->menu_conf_adt_items || $req->menu_drivers || $req->menu_vehicles) {
|
||||||
|
$isAdmin = 1;
|
||||||
|
}
|
||||||
|
if ($req->menu_fnc_ledger_balance || $req->menu_fnc_payment || $req->menu_fnc_billing || $req->menu_fnc_conf_adt_items) {
|
||||||
|
$isFinance = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isAdmin && $isFinance) {
|
||||||
|
$apiResp = Responses::bad_request('Jika salah satu menu admin diizinkan, maka tidak bisa mengizinkan menu finance');
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insPer = [
|
||||||
|
'name' => $req->name,
|
||||||
|
// menu admin
|
||||||
|
'is_trx' => $req->menu_trx,
|
||||||
|
'is_company' => $req->menu_company,
|
||||||
|
'is_zone' => $req->menu_zone,
|
||||||
|
'is_users' => $req->menu_users,
|
||||||
|
'is_conf_rates' => $req->menu_conf_rates,
|
||||||
|
'is_conf_insurance' => $req->menu_conf_insurance,
|
||||||
|
'is_conf_truck_type' => $req->menu_conf_truck_type,
|
||||||
|
'is_devices' => $req->menu_devices,
|
||||||
|
'is_logs_devices' => $req->menu_logs_devices,
|
||||||
|
'is_conf_adt_items' => $req->menu_conf_adt_items,
|
||||||
|
'is_drivers' => $req->menu_drivers,
|
||||||
|
'is_vehicles' => $req->menu_vehicles,
|
||||||
|
'is_menu_permission' => $req->menu_menu_permission,
|
||||||
|
// menu finance
|
||||||
|
'is_fnc_ledger_balance' => $req->menu_fnc_ledger_balance,
|
||||||
|
'is_fnc_payment' => $req->menu_fnc_payment,
|
||||||
|
'is_fnc_billing' => $req->menu_fnc_billing,
|
||||||
|
'is_fnc_conf_adt_items' => $req->menu_fnc_conf_adt_items,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
];
|
||||||
|
$id = UsersMenuPermissions::add($insPer);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success add new permission');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_updt_menu_permissions(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'name' => $req->name,
|
||||||
|
// menu admin
|
||||||
|
'menu_trx' => $req->menu_trx,
|
||||||
|
'menu_company' => $req->menu_company,
|
||||||
|
'menu_zone' => $req->menu_zone,
|
||||||
|
'menu_users' => $req->menu_users,
|
||||||
|
'menu_conf_rates' => $req->menu_conf_rates,
|
||||||
|
'menu_conf_insurance' => $req->menu_conf_insurance,
|
||||||
|
'menu_conf_truck_type' => $req->menu_conf_truck_type,
|
||||||
|
'menu_devices' => $req->menu_devices,
|
||||||
|
'menu_logs_devices' => $req->menu_logs_devices,
|
||||||
|
'menu_conf_adt_items' => $req->menu_conf_adt_items,
|
||||||
|
'menu_drivers' => $req->menu_drivers,
|
||||||
|
'menu_vehicles' => $req->menu_vehicles,
|
||||||
|
'menu_menu_permission' => $req->menu_menu_permission,
|
||||||
|
// menu finance
|
||||||
|
'menu_fnc_ledger_balance' => $req->menu_fnc_ledger_balance,
|
||||||
|
'menu_fnc_payment' => $req->menu_fnc_payment,
|
||||||
|
'menu_fnc_billing' => $req->menu_fnc_billing,
|
||||||
|
'menu_fnc_conf_adt_items' => $req->menu_fnc_conf_adt_items,
|
||||||
|
'status' => $req->status,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'name' => 'required|string',
|
||||||
|
// menu admin
|
||||||
|
'menu_trx' => 'required|numeric|max:2',
|
||||||
|
'menu_company' => 'required|numeric|max:2',
|
||||||
|
'menu_zone' => 'required|numeric|max:2',
|
||||||
|
'menu_users' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_rates' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_insurance' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_truck_type' => 'required|numeric|max:2',
|
||||||
|
'menu_devices' => 'required|numeric|max:2',
|
||||||
|
'menu_logs_devices' => 'required|numeric|max:2',
|
||||||
|
'menu_conf_adt_items' => 'required|numeric|max:2',
|
||||||
|
'menu_drivers' => 'required|numeric|max:2',
|
||||||
|
'menu_vehicles' => 'required|numeric|max:2',
|
||||||
|
'menu_menu_permission' => 'required|numeric|max:2',
|
||||||
|
// menu finance
|
||||||
|
'menu_fnc_ledger_balance' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_payment' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_billing' => 'required|numeric|max:2',
|
||||||
|
'menu_fnc_conf_adt_items' => 'required|numeric|max:2',
|
||||||
|
'status' => 'required|integer|min:0|max:2',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$isAdmin = 0;
|
||||||
|
$isFinance = 0;
|
||||||
|
if ($req->menu_trx || $req->menu_company || $req->menu_zone || $req->menu_users || $req->menu_conf_rates || $req->menu_conf_insurance || $req->menu_conf_truck_type || $req->menu_devices || $req->menu_logs_devices || $req->menu_conf_adt_items || $req->menu_drivers || $req->menu_vehicles) {
|
||||||
|
$isAdmin = 1;
|
||||||
|
}
|
||||||
|
if ($req->menu_fnc_ledger_balance || $req->menu_fnc_payment || $req->menu_fnc_billing || $req->menu_fnc_conf_adt_items) {
|
||||||
|
$isFinance = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isAdmin && $isFinance) {
|
||||||
|
$apiResp = Responses::bad_request('Jika salah satu menu admin diizinkan, maka tidak bisa mengizinkan menu finance');
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtPer = [
|
||||||
|
'name' => $req->name,
|
||||||
|
// menu admin
|
||||||
|
'is_trx' => $req->menu_trx,
|
||||||
|
'is_company' => $req->menu_company,
|
||||||
|
'is_zone' => $req->menu_zone,
|
||||||
|
'is_users' => $req->menu_users,
|
||||||
|
'is_conf_rates' => $req->menu_conf_rates,
|
||||||
|
'is_conf_insurance' => $req->menu_conf_insurance,
|
||||||
|
'is_conf_truck_type' => $req->menu_conf_truck_type,
|
||||||
|
'is_devices' => $req->menu_devices,
|
||||||
|
'is_logs_devices' => $req->menu_logs_devices,
|
||||||
|
'is_conf_adt_items' => $req->menu_conf_adt_items,
|
||||||
|
'is_drivers' => $req->menu_drivers,
|
||||||
|
'is_vehicles' => $req->menu_vehicles,
|
||||||
|
'is_menu_permission' => $req->menu_menu_permission,
|
||||||
|
// menu finance
|
||||||
|
'is_fnc_ledger_balance' => $req->menu_fnc_ledger_balance,
|
||||||
|
'is_fnc_payment' => $req->menu_fnc_payment,
|
||||||
|
'is_fnc_billing' => $req->menu_fnc_billing,
|
||||||
|
'is_fnc_conf_adt_items' => $req->menu_fnc_conf_adt_items,
|
||||||
|
'is_active' => $req->status,
|
||||||
|
];
|
||||||
|
UsersMenuPermissions::updt($id, $updtPer);
|
||||||
|
|
||||||
|
$apiResp = Responses::created('success update permissions');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_menu_permissions(Request $req, $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
'id' => 'required|integer|not_in:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a_item = UsersMenuPermissions::showPermissionsMenusById($id);
|
||||||
|
if (count($a_item) < 1) {
|
||||||
|
$apiResp = Responses::not_found('permissions not found');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
UsersMenuPermissions::updt($id, [
|
||||||
|
'dlt' => $now,
|
||||||
|
'dlt_by' => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success('success delete permissions');
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return (new Response($apiResp, $apiResp['meta']['code']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
706
app/Http/Controllers/VehiclesController.php
Executable file
706
app/Http/Controllers/VehiclesController.php
Executable file
@ -0,0 +1,706 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Validator;
|
||||||
|
use Auth;
|
||||||
|
use App\Responses;
|
||||||
|
use App\Helper;
|
||||||
|
use App\Models\Vehicles;
|
||||||
|
use App\Models\Devices;
|
||||||
|
use App\Models\VehiclesDetail;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class VehiclesController extends Controller
|
||||||
|
{
|
||||||
|
public function api_list_vehicles(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
$input = [];
|
||||||
|
$rulesInput = [];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
// $isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
// if (!$isValidInput->passes()) {
|
||||||
|
// $apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
// return new Response($apiResp, $apiResp['meta']['code']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
$filter = [];
|
||||||
|
if ($req->cptid) {
|
||||||
|
$filter["company"] = $req->cptid;
|
||||||
|
}
|
||||||
|
$list = Vehicles::listVehicles($req->auth, $filter);
|
||||||
|
foreach ($list as $key => $row) {
|
||||||
|
$list[$key]->DT_RowIndex = $key + 1;
|
||||||
|
// $list[$key]->mileage_km = '-';
|
||||||
|
// $list[$key]->div_name = 'All Division';
|
||||||
|
// $list[$key]->group_name = 'All Group';
|
||||||
|
// $list[$key]->track_schedule = $row->track_sch_h.'/'.$row->track_sch_d; // combine track_sch_h + track_sch_d
|
||||||
|
// $list[$key]->is_track_holiday_text = ($list[$key]->is_track_holiday == Vehicles::ENABLED_TRACK_HOLIDAY) ? 'Enabled' : 'Disabled';
|
||||||
|
// $list[$key]->alert_zones = '-';
|
||||||
|
// $list[$key]->cameras = '-';
|
||||||
|
$list[$key]->action = "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success list vehicles");
|
||||||
|
$apiResp["data"] = $list;
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_show_vehicle(Request $req, $vid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"vid" => $vid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"vid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vehicle = Vehicles::showVehicleById($vid);
|
||||||
|
if (count($vehicle) < 1) {
|
||||||
|
$apiResp = Responses::not_found("vehicle not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success get detail vehicle");
|
||||||
|
$apiResp["data"] = $vehicle[0];
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_add_vehicle(Request $req)
|
||||||
|
{
|
||||||
|
$url_fvhc = "";
|
||||||
|
$url_stnk = "";
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$device_id = str_pad($req->device_id, Vehicles::MAX_DEVICE_ID, "0", STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"front_vehicle_photo" => $req->fvhc_base64,
|
||||||
|
"dvc_id" => $req->dvc_id,
|
||||||
|
"simcard" => $req->simcard,
|
||||||
|
"device_id" => $req->device_id,
|
||||||
|
"vehicle_name" => $req->vhc_name,
|
||||||
|
"brand_id" => $req->brand_id,
|
||||||
|
"type_id" => $req->type_id,
|
||||||
|
"model_id" => $req->model_id,
|
||||||
|
"speed_limit" => $req->speed_limit,
|
||||||
|
"fuel_capacity" => $req->fuel_capacity,
|
||||||
|
"fuel_drop_treshold" => $req->fuel_drop_treshold,
|
||||||
|
"max_pressure" => $req->max_pressure,
|
||||||
|
"current_driver" => $req->d_current,
|
||||||
|
"assign_driver" => $req->d_assign,
|
||||||
|
"stnk_photo" => $req->stnk_base64,
|
||||||
|
"stnk_exp" => $req->stnk_exp,
|
||||||
|
"nopol1" => $req->nopol1,
|
||||||
|
"nopol2" => $req->nopol2,
|
||||||
|
"nopol3" => $req->nopol3,
|
||||||
|
"manufacture_year" => $req->stnk_vyear,
|
||||||
|
"cylinder_capacity" => $req->cc,
|
||||||
|
"vehicle_identity_number" => $req->vin,
|
||||||
|
"engine_number" => $req->en,
|
||||||
|
"vehicle_color" => $req->color,
|
||||||
|
"fuel_type" => $req->fuel_type,
|
||||||
|
"license_plat_color" => $req->tnkb_color,
|
||||||
|
"regis_year" => $req->regis_year,
|
||||||
|
"tax_exp" => $req->tax_exp,
|
||||||
|
"kir_exp" => $req->kir_exp,
|
||||||
|
"vendor_id" => $req->vendor_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"front_vehicle_photo" => "required|string",
|
||||||
|
"dvc_id" => "nullable|integer",
|
||||||
|
"simcard" => "nullable|numeric",
|
||||||
|
"device_id" => "nullable|numeric",
|
||||||
|
"vehicle_name" => "required|string",
|
||||||
|
"brand_id" => "required|integer",
|
||||||
|
"type_id" => "required|integer",
|
||||||
|
"model_id" => "nullable|integer",
|
||||||
|
"speed_limit" => "required|numeric",
|
||||||
|
// "fuel_capacity" => "required|numeric",
|
||||||
|
// "fuel_drop_treshold" => "required|numeric",
|
||||||
|
// "max_pressure" => "required|numeric",
|
||||||
|
"current_driver" => "nullable|integer",
|
||||||
|
"assign_driver" => "nullable|integer",
|
||||||
|
"stnk_photo" => "required|string",
|
||||||
|
"stnk_exp" => "required|date_format:Y-m-d",
|
||||||
|
"nopol1" => "required|string|max:2",
|
||||||
|
"nopol2" => "required|string|max:4",
|
||||||
|
"nopol3" => "required|string|max:3",
|
||||||
|
"manufacture_year" => "required|digits:4",
|
||||||
|
"cylinder_capacity" => "required|integer",
|
||||||
|
"vehicle_identity_number" => "required|string|min:17|max:45",
|
||||||
|
"engine_number" => "required|string|min:9|max:45",
|
||||||
|
"vehicle_color" => "required|string|min:3|max:25",
|
||||||
|
"fuel_type" => "required|string|min:3|max:25",
|
||||||
|
"license_plat_color" => "required|string|min:3|max:25",
|
||||||
|
"regis_year" => "required|digits:4",
|
||||||
|
"tax_exp" => "required|date_format:Y-m-d",
|
||||||
|
"kir_exp" => "required|date_format:Y-m-d",
|
||||||
|
"vendor_id" => "nullable|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$rulesInput["simcard"] = "nullable";
|
||||||
|
}
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($req->device_id) > Vehicles::MAX_DEVICE_ID) {
|
||||||
|
$apiResp = Responses::bad_input("device_id max length is " . Vehicles::MAX_DEVICE_ID);
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($device_id !== str_pad(0, Vehicles::MAX_DEVICE_ID, "0", STR_PAD_LEFT)) {
|
||||||
|
$uniqDeviceId = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
if (count($uniqDeviceId) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("device id has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqSimcard = Vehicles::getVehicleBySimcard($req->simcard);
|
||||||
|
if (count($uniqSimcard) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("simcard has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqPlatNo = Vehicles::getVehicleByPlatNo($req->nopol1, $req->nopol2, $req->nopol3);
|
||||||
|
if (count($uniqPlatNo) > 0) {
|
||||||
|
$apiResp = Responses::bad_request("plat number has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$insVhc = [
|
||||||
|
"name" => $req->vhc_name,
|
||||||
|
"dvc_id" => $req->dvc_id ?? 0,
|
||||||
|
"device_id" => $device_id,
|
||||||
|
"simcard" => $req->simcard ?? 0,
|
||||||
|
"cat_id" => Vehicles::DEFAULT_CAT_ID,
|
||||||
|
"brand_id" => $req->brand_id,
|
||||||
|
"type_id" => $req->type_id,
|
||||||
|
"nopol1" => strtoupper($req->nopol1),
|
||||||
|
"nopol2" => strtoupper($req->nopol2),
|
||||||
|
"nopol3" => strtoupper($req->nopol3),
|
||||||
|
"c_did" => $req->d_current ?? 0,
|
||||||
|
"a_did" => $req->d_assign ?? 0,
|
||||||
|
"is_track_holiday" => Vehicles::DEFAULT_TRACK_HOLIDAY,
|
||||||
|
"track_sch_d" => Vehicles::DEFAULT_TRACK_SCH_D,
|
||||||
|
"track_sch_h" => Vehicles::DEFAULT_TRACK_SCH_H,
|
||||||
|
"client_group_id" => $req->auth->client_group_id ?? null,
|
||||||
|
"crt" => $now,
|
||||||
|
"crt_by" => $req->auth->uid,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->model_id) {
|
||||||
|
$insVhc["model_id"] = $req->model_id;
|
||||||
|
}
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$insVhc["vendor_id"] = $req->auth->uid;
|
||||||
|
$insVhc["simcard"] = 0;
|
||||||
|
} else {
|
||||||
|
$insVhc["vendor_id"] = $req->vendor_id ?? 0;
|
||||||
|
}
|
||||||
|
$vid = Vehicles::addVehicle($insVhc);
|
||||||
|
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$getUsrId = DB::table("t_users")
|
||||||
|
->where("id", Auth::user()->id)
|
||||||
|
->first();
|
||||||
|
$vhclid = DB::table("t_vehicles")->insertGetId($insVhc);
|
||||||
|
$new = $getUsrId->vhcs . "," . $vhclid;
|
||||||
|
$dtupdate = [
|
||||||
|
"vhcs" => $new,
|
||||||
|
];
|
||||||
|
DB::table("t_users")
|
||||||
|
->where("id", Auth::user()->id)
|
||||||
|
->update($dtupdate);
|
||||||
|
$dtUpdataIsTracking = [
|
||||||
|
"is_tracking" => 1,
|
||||||
|
];
|
||||||
|
DB::table("t_users")
|
||||||
|
->where("id", Auth::user()->id)
|
||||||
|
->update($dtUpdataIsTracking);
|
||||||
|
}
|
||||||
|
$url_fvhc = "vehicles/$vid/front_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_fvhc, base64_decode($req->fvhc_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload front photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$url_stnk = "vehicles/$vid/stnk_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_stnk, base64_decode($req->stnk_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_fvhc);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload front photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$insDetail = [
|
||||||
|
"vid" => $vid,
|
||||||
|
"speed_limit" => $req->speed_limit,
|
||||||
|
"fuel_capacity" => $req->fuel_capacity,
|
||||||
|
"fuel_drop_treshold" => $req->fuel_drop_treshold,
|
||||||
|
"max_pressure" => $req->max_pressure,
|
||||||
|
"fvhc_img" => $url_fvhc,
|
||||||
|
"stnk_img" => $url_stnk,
|
||||||
|
"stnk_exp" => $req->stnk_exp,
|
||||||
|
"vyear" => $req->stnk_vyear, // manufacture_year
|
||||||
|
"cc" => $req->cc, // cylinder_capacity
|
||||||
|
"vin" => strtoupper($req->vin), // vehicle_identity_number
|
||||||
|
"en" => strtoupper($req->en), // engine_number
|
||||||
|
"vcolor" => strtoupper($req->color),
|
||||||
|
"fuel_type" => strtoupper($req->fuel_type),
|
||||||
|
"tnkb_color" => strtoupper($req->tnkb_color), // license_plat_color
|
||||||
|
"regis_year" => $req->regis_year,
|
||||||
|
"tax_exp" => $req->tax_exp,
|
||||||
|
"kir_exp" => $req->kir_exp,
|
||||||
|
];
|
||||||
|
VehiclesDetail::addDetail($insDetail);
|
||||||
|
|
||||||
|
$apiResp = Responses::created("success add new vehicle");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_fvhc);
|
||||||
|
Storage::disk("public")->delete($url_stnk);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_edit_vehicle(Request $req, $vid)
|
||||||
|
{
|
||||||
|
$url_fvhc = "";
|
||||||
|
$url_stnk = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$device_id = str_pad($req->device_id, Vehicles::MAX_DEVICE_ID, "0", STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"vid" => $vid,
|
||||||
|
"front_vehicle_photo" => $req->fvhc_base64,
|
||||||
|
"dvc_id" => $req->dvc_id ?? 0,
|
||||||
|
"simcard" => $req->simcard,
|
||||||
|
"device_id" => $req->device_id,
|
||||||
|
"vehicle_name" => $req->vhc_name,
|
||||||
|
"brand_id" => $req->brand_id,
|
||||||
|
"type_id" => $req->type_id,
|
||||||
|
"model_id" => $req->model_id,
|
||||||
|
"speed_limit" => $req->speed_limit,
|
||||||
|
"fuel_capacity" => $req->fuel_capacity,
|
||||||
|
"fuel_drop_treshold" => $req->fuel_drop_treshold,
|
||||||
|
"max_pressure" => $req->max_pressure,
|
||||||
|
"current_driver" => $req->d_current,
|
||||||
|
"assign_driver" => $req->d_assign,
|
||||||
|
"stnk_photo" => $req->stnk_base64,
|
||||||
|
"stnk_exp" => $req->stnk_exp,
|
||||||
|
"nopol1" => $req->nopol1,
|
||||||
|
"nopol2" => $req->nopol2,
|
||||||
|
"nopol3" => $req->nopol3,
|
||||||
|
"manufacture_year" => $req->stnk_vyear,
|
||||||
|
"cylinder_capacity" => $req->cc,
|
||||||
|
"vehicle_identity_number" => $req->vin,
|
||||||
|
"engine_number" => $req->en,
|
||||||
|
"vehicle_color" => $req->color,
|
||||||
|
"fuel_type" => $req->fuel_type,
|
||||||
|
"license_plat_color" => $req->tnkb_color,
|
||||||
|
"regis_year" => $req->regis_year,
|
||||||
|
"tax_exp" => $req->tax_exp,
|
||||||
|
"kir_exp" => $req->kir_exp,
|
||||||
|
"vendor_id" => $req->vendor_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"vid" => "required|integer|not_in:0",
|
||||||
|
"front_vehicle_photo" => "nullable|string",
|
||||||
|
// "dvc_id" => "nullable|integer",
|
||||||
|
"simcard" => "nullable|numeric",
|
||||||
|
"device_id" => "nullable|numeric",
|
||||||
|
"vehicle_name" => "required|string",
|
||||||
|
"brand_id" => "required|integer",
|
||||||
|
"type_id" => "required|integer",
|
||||||
|
"model_id" => "nullable|integer",
|
||||||
|
"speed_limit" => "required|numeric",
|
||||||
|
// "fuel_capacity" => "required|numeric",
|
||||||
|
// "fuel_drop_treshold" => "required|numeric",
|
||||||
|
// "max_pressure" => "required|numeric",
|
||||||
|
"current_driver" => "nullable|integer",
|
||||||
|
"assign_driver" => "nullable|integer",
|
||||||
|
"stnk_photo" => "nullable|string",
|
||||||
|
"stnk_exp" => "required|date_format:Y-m-d",
|
||||||
|
"nopol1" => "required|string|max:2",
|
||||||
|
"nopol2" => "required|string|max:4",
|
||||||
|
"nopol3" => "required|string|max:3",
|
||||||
|
"manufacture_year" => "required|digits:4",
|
||||||
|
"cylinder_capacity" => "required|integer",
|
||||||
|
"vehicle_identity_number" => "required|string|min:17|max:45",
|
||||||
|
"engine_number" => "required|string|min:9|max:45",
|
||||||
|
"vehicle_color" => "required|string|min:3|max:25",
|
||||||
|
"fuel_type" => "required|string|min:3|max:25",
|
||||||
|
"license_plat_color" => "required|string|min:3|max:25",
|
||||||
|
"regis_year" => "required|digits:4",
|
||||||
|
"tax_exp" => "required|date_format:Y-m-d",
|
||||||
|
"kir_exp" => "required|date_format:Y-m-d",
|
||||||
|
"vendor_id" => "nullable|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$rulesInput["simcard"] = "nullable";
|
||||||
|
}
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($req->device_id) > Vehicles::MAX_DEVICE_ID) {
|
||||||
|
$apiResp = Responses::bad_input("device id max length is " . Vehicles::MAX_DEVICE_ID);
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vhc = Vehicles::getVehicleById($vid);
|
||||||
|
if (count($vhc) < 1) {
|
||||||
|
$apiResp = Responses::bad_request("vehicle not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
$vd = VehiclesDetail::getDetailByVid($vid);
|
||||||
|
if (count($vd) < 1) {
|
||||||
|
$apiResp = Responses::bad_request("vehicle not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ($req->dvc_id) {
|
||||||
|
// $uniqDeviceId = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
// if (count($uniqDeviceId) > 0) {
|
||||||
|
// $notSameUser = 1;
|
||||||
|
// foreach ($uniqDeviceId as $key => $row) {
|
||||||
|
// if ($row->id == $vid) {
|
||||||
|
// $notSameUser = 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if ($notSameUser) {
|
||||||
|
// $apiResp = Responses::bad_request("device id has been used");
|
||||||
|
// return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$uniqSimcard = Vehicles::getVehicleBySimcard($req->simcard);
|
||||||
|
if (count($uniqSimcard) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqSimcard as $key => $row) {
|
||||||
|
if ($row->id == $vid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("simcard has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniqPlatNo = Vehicles::getVehicleByPlatNo($req->nopol1, $req->nopol2, $req->nopol3);
|
||||||
|
if (count($uniqPlatNo) > 0) {
|
||||||
|
$notSameUser = 1;
|
||||||
|
foreach ($uniqPlatNo as $key => $row) {
|
||||||
|
if ($row->id == $vid) {
|
||||||
|
$notSameUser = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($notSameUser) {
|
||||||
|
$apiResp = Responses::bad_request("plat number has been used");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$updtVhc = [
|
||||||
|
"name" => $req->vhc_name,
|
||||||
|
"dvc_id" => $req->dvc_id,
|
||||||
|
"device_id" => $device_id,
|
||||||
|
"simcard" => (int) $req->simcard,
|
||||||
|
"cat_id" => Vehicles::DEFAULT_CAT_ID,
|
||||||
|
"brand_id" => $req->brand_id,
|
||||||
|
"type_id" => $req->type_id,
|
||||||
|
"nopol1" => strtoupper($req->nopol1),
|
||||||
|
"nopol2" => strtoupper($req->nopol2),
|
||||||
|
"nopol3" => strtoupper($req->nopol3),
|
||||||
|
"c_did" => $req->d_current ?? 0,
|
||||||
|
"a_did" => $req->d_assign ?? 0,
|
||||||
|
"is_track_holiday" => Vehicles::DEFAULT_TRACK_HOLIDAY,
|
||||||
|
"track_sch_d" => Vehicles::DEFAULT_TRACK_SCH_D,
|
||||||
|
"track_sch_h" => Vehicles::DEFAULT_TRACK_SCH_H,
|
||||||
|
"updt" => $now,
|
||||||
|
"updt_by" => $req->auth->uid,
|
||||||
|
];
|
||||||
|
if ($req->model_id) {
|
||||||
|
$updtVhc["model_id"] = $req->model_id;
|
||||||
|
}
|
||||||
|
if ($req->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$updtVhc["vendor_id"] = $req->auth->uid;
|
||||||
|
// $updtVhc["simcard"] = (int) $uniqDeviceId[0]->simcard;
|
||||||
|
} else {
|
||||||
|
$updtVhc["vendor_id"] = $req->vendor_id ?? 0;
|
||||||
|
}
|
||||||
|
Vehicles::updateVehicle($vid, $updtVhc);
|
||||||
|
|
||||||
|
if ($req->dvc_id) {
|
||||||
|
Devices::updateDevice($req->dvc_id, [
|
||||||
|
"is_assigned" => Devices::IS_ASSIGNED,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
Devices::updateDevice($vhc[0]->dvc_id, [
|
||||||
|
"is_assigned" => Devices::IS_UNASSIGNED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($req->fvhc_base64) {
|
||||||
|
$url_fvhc = "vehicles/$vid/front_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_fvhc, base64_decode($req->fvhc_base64))) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload front photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($vd[0]->fvhc_img);
|
||||||
|
}
|
||||||
|
if ($req->stnk_base64) {
|
||||||
|
$url_stnk = "vehicles/$vid/stnk_$now.jpeg";
|
||||||
|
if (!Storage::disk("public")->put($url_stnk, base64_decode($req->stnk_base64))) {
|
||||||
|
Storage::disk("public")->delete($url_fvhc);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::bad_request("fail upload front photo");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
Storage::disk("public")->delete($vd[0]->stnk_img);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updtDetail = [
|
||||||
|
"vid" => $vid,
|
||||||
|
"speed_limit" => $req->speed_limit,
|
||||||
|
"fuel_capacity" => $req->fuel_capacity,
|
||||||
|
"fuel_drop_treshold" => $req->fuel_drop_treshold,
|
||||||
|
"max_pressure" => $req->max_pressure,
|
||||||
|
"stnk_exp" => $req->stnk_exp,
|
||||||
|
"vyear" => $req->stnk_vyear, // manufacture_year
|
||||||
|
"cc" => $req->cc, // cylinder_capacity
|
||||||
|
"vin" => strtoupper($req->vin), // vehicle_identity_number
|
||||||
|
"en" => strtoupper($req->en), // engine_number
|
||||||
|
"vcolor" => strtoupper($req->color),
|
||||||
|
"fuel_type" => strtoupper($req->fuel_type),
|
||||||
|
"tnkb_color" => strtoupper($req->tnkb_color), // license_plat_color
|
||||||
|
"regis_year" => $req->regis_year,
|
||||||
|
"tax_exp" => $req->tax_exp,
|
||||||
|
"kir_exp" => $req->kir_exp,
|
||||||
|
];
|
||||||
|
if ($req->fvhc_base64) {
|
||||||
|
$updtDetail["fvhc_img"] = $url_fvhc;
|
||||||
|
}
|
||||||
|
if ($req->stnk_base64) {
|
||||||
|
$updtDetail["stnk_img"] = $url_stnk;
|
||||||
|
}
|
||||||
|
VehiclesDetail::updateDetailByVid($vid, $updtDetail);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success update vehicle");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Storage::disk("public")->delete($url_fvhc);
|
||||||
|
Storage::disk("public")->delete($url_stnk);
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_del_vehicle(Request $req, $vid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"vid" => $vid,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"vid" => "required|integer|not_in:0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vehicle = Vehicles::showVehicleById($vid);
|
||||||
|
if (count($vehicle) < 1) {
|
||||||
|
$apiResp = Responses::not_found("vehicle not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$device_id = str_pad(0, Devices::MAX_DEVICE_ID, "0", STR_PAD_LEFT);
|
||||||
|
Vehicles::updateVehicle($vid, [
|
||||||
|
"dvc_id" => 0,
|
||||||
|
"device_id" => $device_id,
|
||||||
|
"simcard" => 0,
|
||||||
|
"dlt" => $now,
|
||||||
|
"dlt_by" => $req->auth->uid,
|
||||||
|
]);
|
||||||
|
if ($vehicle[0]->dvc_id != 0) {
|
||||||
|
Devices::updateDevice($vehicle[0]->dvc_id, [
|
||||||
|
"is_assigned" => Devices::IS_UNASSIGNED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage::disk('public')->delete($vehicle[0]->fvhc_img);
|
||||||
|
// Storage::disk('public')->delete($vehicle[0]->stnk_img);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success delete vehicle");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_search_device_id(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"device_id" => $req->device_id,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"device_id" => "required|numeric",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($req->device_id) > Vehicles::MAX_DEVICE_ID) {
|
||||||
|
$apiResp = Responses::bad_input("device id max length is " . Vehicles::MAX_DEVICE_ID);
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$device_id = str_pad($req->device_id, Vehicles::MAX_DEVICE_ID, "0", STR_PAD_LEFT);
|
||||||
|
$devices = Vehicles::getVehicleByDeviceId($device_id);
|
||||||
|
|
||||||
|
if (count($devices) < 1) {
|
||||||
|
$apiResp = Responses::not_found("device id not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success search device id");
|
||||||
|
$apiResp["data"] = $devices;
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function api_search_nopol(Request $req)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$input = [
|
||||||
|
"nopol" => $req->nopol,
|
||||||
|
];
|
||||||
|
$rulesInput = [
|
||||||
|
"nopol" => "required|string",
|
||||||
|
];
|
||||||
|
|
||||||
|
// validasi input
|
||||||
|
$isValidInput = Validator::make($input, $rulesInput);
|
||||||
|
if (!$isValidInput->passes()) {
|
||||||
|
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nopol = explode(" ", strtoupper($req->nopol));
|
||||||
|
$cNopol = count($nopol);
|
||||||
|
if ($cNopol === 3) {
|
||||||
|
} elseif ($cNopol === 2) {
|
||||||
|
$nopol[2] = "";
|
||||||
|
} elseif ($cNopol === 1) {
|
||||||
|
$nopol[1] = "";
|
||||||
|
$nopol[2] = "";
|
||||||
|
} else {
|
||||||
|
$apiResp = Responses::bad_input("Nomor polisi kendaraan tidak valid");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vehicles = Vehicles::searchVehicleByPlatNo($nopol[0], $nopol[1], $nopol[2]);
|
||||||
|
|
||||||
|
if (count($vehicles) < 1) {
|
||||||
|
$apiResp = Responses::not_found("vehicles not found");
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiResp = Responses::success("success search vehicles");
|
||||||
|
$apiResp["data"] = $vehicles;
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
$apiResp = Responses::error($e->getMessage());
|
||||||
|
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1183
app/Http/Controllers/ZoneController.php
Executable file
1183
app/Http/Controllers/ZoneController.php
Executable file
File diff suppressed because it is too large
Load Diff
68
app/Http/Kernel.php
Executable file
68
app/Http/Kernel.php
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
|
||||||
|
class Kernel extends HttpKernel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The application's global HTTP middleware stack.
|
||||||
|
*
|
||||||
|
* These middleware are run during every request to your application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middleware = [
|
||||||
|
// \App\Http\Middleware\TrustHosts::class,
|
||||||
|
\App\Http\Middleware\TrustProxies::class,
|
||||||
|
\Fruitcake\Cors\HandleCors::class,
|
||||||
|
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||||
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware groups.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middlewareGroups = [
|
||||||
|
'web' => [
|
||||||
|
\App\Http\Middleware\EncryptCookies::class,
|
||||||
|
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||||
|
\Illuminate\Session\Middleware\StartSession::class,
|
||||||
|
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||||
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
|
||||||
|
'api' => [
|
||||||
|
'throttle:60,1',
|
||||||
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application's route middleware.
|
||||||
|
*
|
||||||
|
* These middleware may be assigned to groups or used individually.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $routeMiddleware = [
|
||||||
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
|
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||||
|
'auth.user' => \App\Http\Middleware\AuthUser::class,
|
||||||
|
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||||
|
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||||
|
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||||
|
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||||
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
242
app/Http/Middleware/AuthUser.php
Executable file
242
app/Http/Middleware/AuthUser.php
Executable file
@ -0,0 +1,242 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class AuthUser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$request->auth = Auth::user();
|
||||||
|
$request->auth->uid = $request->auth->id;
|
||||||
|
|
||||||
|
if ($request->auth->role == Users::ROLE_ADMIN) {
|
||||||
|
// views
|
||||||
|
if ($request->is("home/*")) {
|
||||||
|
} elseif ($request->is("home")) {
|
||||||
|
} elseif ($request->is("dashboard/*")) {
|
||||||
|
} elseif ($request->is("dashboard")) {
|
||||||
|
} elseif ($request->is("drivers/*")) {
|
||||||
|
} elseif ($request->is("drivers")) {
|
||||||
|
} elseif ($request->is("transactions/*")) {
|
||||||
|
} elseif ($request->is("transactions")) {
|
||||||
|
} elseif ($request->is("vehicles/*")) {
|
||||||
|
} elseif ($request->is("vehicles")) {
|
||||||
|
} elseif ($request->is("clients/*")) {
|
||||||
|
} elseif ($request->is("clients")) {
|
||||||
|
} elseif ($request->is("zone/*")) {
|
||||||
|
} elseif ($request->is("zone")) {
|
||||||
|
} elseif ($request->is("users/*")) {
|
||||||
|
} elseif ($request->is("users")) {
|
||||||
|
} elseif ($request->is("profile/*")) {
|
||||||
|
} elseif ($request->is("profile")) {
|
||||||
|
} elseif ($request->is("config/*")) {
|
||||||
|
} elseif ($request->is("config")) {
|
||||||
|
} elseif ($request->is("pocket/*")) {
|
||||||
|
} elseif ($request->is("pocket")) {
|
||||||
|
} elseif ($request->is("lgb_types/*")) {
|
||||||
|
} elseif ($request->is("lgb_types")) {
|
||||||
|
} elseif ($request->is("lgb_masters/*")) {
|
||||||
|
} elseif ($request->is("lgb_masters")) {
|
||||||
|
} elseif ($request->is("insurances/*")) {
|
||||||
|
} elseif ($request->is("static_insurances/*")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/conf/*")) {
|
||||||
|
} elseif ($request->is("api/conf")) {
|
||||||
|
} elseif ($request->is("api/osm/*")) {
|
||||||
|
} elseif ($request->is("api/osm")) {
|
||||||
|
} elseif ($request->is("api/region/*")) {
|
||||||
|
} elseif ($request->is("api/region")) {
|
||||||
|
} elseif ($request->is("api/zones/*")) {
|
||||||
|
} elseif ($request->is("api/zones")) {
|
||||||
|
} elseif ($request->is("api/vehicles/*")) {
|
||||||
|
} elseif ($request->is("api/vehicles")) {
|
||||||
|
} elseif ($request->is("api/drivers/*")) {
|
||||||
|
} elseif ($request->is("api/drivers")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/clients/*")) {
|
||||||
|
} elseif ($request->is("api/clients")) {
|
||||||
|
} elseif ($request->is("api/tracks/*")) {
|
||||||
|
} elseif ($request->is("api/tracks")) {
|
||||||
|
} elseif ($request->is("api/transactions/*")) {
|
||||||
|
} elseif ($request->is("api/transactions")) {
|
||||||
|
} elseif ($request->is("api/transactions_spc/*")) {
|
||||||
|
} elseif ($request->is("api/transactions_spc")) {
|
||||||
|
} elseif ($request->is("api/insurances/*")) {
|
||||||
|
} elseif ($request->is("api/insurances")) {
|
||||||
|
} elseif ($request->is("api/devices/*")) {
|
||||||
|
} elseif ($request->is("api/devices")) {
|
||||||
|
} elseif ($request->is("api/user/clients/*")) {
|
||||||
|
} elseif ($request->is("api/user/clients")) {
|
||||||
|
} elseif ($request->is("api/a_items/*")) {
|
||||||
|
} elseif ($request->is("api/a_items")) {
|
||||||
|
} elseif ($request->is("api/admin/*")) {
|
||||||
|
} elseif ($request->is("api/admin")) {
|
||||||
|
} elseif ($request->is("api/static_insurances/*")) {
|
||||||
|
} elseif ($request->is("api/static_insurances")) {
|
||||||
|
} elseif ($request->is("api/menu_permissions/*")) {
|
||||||
|
} elseif ($request->is("api/menu_permissions")) {
|
||||||
|
} elseif ($request->is("api/pocket/*")) {
|
||||||
|
} elseif ($request->is("api/pocket")) {
|
||||||
|
} elseif ($request->is("api/lgb_types/*")) {
|
||||||
|
} elseif ($request->is("api/lgb_types")) {
|
||||||
|
} elseif ($request->is("api/lgb_keys/*")) {
|
||||||
|
} elseif ($request->is("api/lgb_keys")) {
|
||||||
|
} elseif ($request->is("api/dtypes/*")) {
|
||||||
|
} elseif ($request->is("api/dtypes")) {
|
||||||
|
} elseif ($request->is("api/dana/*")) {
|
||||||
|
} elseif ($request->is("api/dana")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} elseif ($request->auth->role == Users::ROLE_VENDOR) {
|
||||||
|
// views
|
||||||
|
if ($request->is("home/*")) {
|
||||||
|
} elseif ($request->is("home")) {
|
||||||
|
} elseif ($request->is("dashboard/*")) {
|
||||||
|
} elseif ($request->is("dashboard")) {
|
||||||
|
} elseif ($request->is("checklist/*")) {
|
||||||
|
} elseif ($request->is("checklist")) {
|
||||||
|
} elseif ($request->is("zone/*")) {
|
||||||
|
} elseif ($request->is("zone")) {
|
||||||
|
} elseif ($request->is("drivers/*")) {
|
||||||
|
} elseif ($request->is("drivers")) {
|
||||||
|
} elseif ($request->is("vehicles/*")) {
|
||||||
|
} elseif ($request->is("vehicles")) {
|
||||||
|
} elseif ($request->is("profile/*")) {
|
||||||
|
} elseif ($request->is("transactions/*")) {
|
||||||
|
} elseif ($request->is("transactions")) {
|
||||||
|
} elseif ($request->is("profile")) {
|
||||||
|
} elseif ($request->is("user/vendor/*")) {
|
||||||
|
} elseif ($request->is("user/vendor")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/conf")) {
|
||||||
|
} elseif ($request->is("api/osm/*")) {
|
||||||
|
} elseif ($request->is("api/osm")) {
|
||||||
|
} elseif ($request->is("api/region/*")) {
|
||||||
|
} elseif ($request->is("api/region")) {
|
||||||
|
} elseif ($request->is("api/tracks/*")) {
|
||||||
|
} elseif ($request->is("api/tracks")) {
|
||||||
|
} elseif ($request->is("api/vehicles/*")) {
|
||||||
|
} elseif ($request->is("api/vehicles")) {
|
||||||
|
} elseif ($request->is("api/drivers/*")) {
|
||||||
|
} elseif ($request->is("api/drivers")) {
|
||||||
|
} elseif ($request->is("api/user/vendor/*")) {
|
||||||
|
} elseif ($request->is("api/user/vendor")) {
|
||||||
|
} elseif ($request->is("api/transactions_spc/*")) {
|
||||||
|
} elseif ($request->is("api/transactions_spc")) {
|
||||||
|
} elseif ($request->is("api/zones/*")) {
|
||||||
|
} elseif ($request->is("api/zones")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} elseif ($request->auth->role == Users::ROLE_CLIENT_ADMIN) {
|
||||||
|
// views
|
||||||
|
if ($request->is("home/*")) {
|
||||||
|
} elseif ($request->is("home")) {
|
||||||
|
} elseif ($request->is("dashboard/*")) {
|
||||||
|
} elseif ($request->is("dashboard")) {
|
||||||
|
} elseif ($request->is("zone/*")) {
|
||||||
|
} elseif ($request->is("zone")) {
|
||||||
|
} elseif ($request->is("profile/*")) {
|
||||||
|
} elseif ($request->is("profile")) {
|
||||||
|
} elseif ($request->is("user/clients/*")) {
|
||||||
|
} elseif ($request->is("user/clients")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/conf")) {
|
||||||
|
} elseif ($request->is("api/osm/*")) {
|
||||||
|
} elseif ($request->is("api/osm")) {
|
||||||
|
} elseif ($request->is("api/region/*")) {
|
||||||
|
} elseif ($request->is("api/region")) {
|
||||||
|
} elseif ($request->is("api/zones/*")) {
|
||||||
|
} elseif ($request->is("api/zones")) {
|
||||||
|
} elseif ($request->is("api/tracks/*")) {
|
||||||
|
} elseif ($request->is("api/tracks")) {
|
||||||
|
} elseif ($request->is("api/user/clients/*")) {
|
||||||
|
} elseif ($request->is("api/user/clients")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} elseif ($request->auth->role == Users::ROLE_CHECKER) {
|
||||||
|
// views
|
||||||
|
if ($request->is("user/checker/*")) {
|
||||||
|
} elseif ($request->is("user/checker")) {
|
||||||
|
} elseif ($request->is("profile/*")) {
|
||||||
|
} elseif ($request->is("profile")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/user/checker/*")) {
|
||||||
|
} elseif ($request->is("api/user/checker")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} elseif ($request->auth->role == Users::ROLE_FINANCE) {
|
||||||
|
// views
|
||||||
|
if ($request->is("finance/*")) {
|
||||||
|
} elseif ($request->is("profile/*")) {
|
||||||
|
} elseif ($request->is("profile")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/finance/*")) {
|
||||||
|
} elseif ($request->is("api/finance")) {
|
||||||
|
} elseif ($request->is("api/a_items/*")) {
|
||||||
|
} elseif ($request->is("api/a_items")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/dana/*")) {
|
||||||
|
} elseif ($request->is("api/dana")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} elseif ($request->auth->role == Users::ROLE_SPECIAL_TRACKING) {
|
||||||
|
// views
|
||||||
|
if ($request->is("dashboard/*")) {
|
||||||
|
} elseif ($request->is("dashboard")) {
|
||||||
|
}
|
||||||
|
// api
|
||||||
|
elseif ($request->is("api/tracks/*")) {
|
||||||
|
} elseif ($request->is("api/tracks")) {
|
||||||
|
} elseif ($request->is("api/users/*")) {
|
||||||
|
} elseif ($request->is("api/users")) {
|
||||||
|
} elseif ($request->is("api/universal/*")) {
|
||||||
|
} elseif ($request->is("api/universal")) {
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return abort(403, "Unauthorized action.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Http/Middleware/Authenticate.php
Executable file
22
app/Http/Middleware/Authenticate.php
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||||
|
|
||||||
|
class Authenticate extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the path the user should be redirected to when they are not authenticated.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
protected function redirectTo($request)
|
||||||
|
{
|
||||||
|
if (! $request->expectsJson()) {
|
||||||
|
return route('login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
app/Http/Middleware/CheckForMaintenanceMode.php
Executable file
17
app/Http/Middleware/CheckForMaintenanceMode.php
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||||
|
|
||||||
|
class CheckForMaintenanceMode extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The URIs that should be reachable while maintenance mode is enabled.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
17
app/Http/Middleware/EncryptCookies.php
Executable file
17
app/Http/Middleware/EncryptCookies.php
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||||
|
|
||||||
|
class EncryptCookies extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The names of the cookies that should not be encrypted.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
27
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file
27
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Providers\RouteServiceProvider;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class RedirectIfAuthenticated
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @param string|null $guard
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next, $guard = null)
|
||||||
|
{
|
||||||
|
if (Auth::guard($guard)->check()) {
|
||||||
|
return redirect(RouteServiceProvider::HOME);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Middleware/TrimStrings.php
Executable file
18
app/Http/Middleware/TrimStrings.php
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||||
|
|
||||||
|
class TrimStrings extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The names of the attributes that should not be trimmed.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
|
];
|
||||||
|
}
|
||||||
20
app/Http/Middleware/TrustHosts.php
Executable file
20
app/Http/Middleware/TrustHosts.php
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||||
|
|
||||||
|
class TrustHosts extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the host patterns that should be trusted.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function hosts()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->allSubdomainsOfApplicationUrl(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Http/Middleware/TrustProxies.php
Executable file
29
app/Http/Middleware/TrustProxies.php
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class TrustProxies extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The trusted proxies for this application.
|
||||||
|
*
|
||||||
|
* @var array|string|null
|
||||||
|
*/
|
||||||
|
protected $proxies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The headers that should be used to detect proxies.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $headers =
|
||||||
|
Request::HEADER_X_FORWARDED_FOR |
|
||||||
|
Request::HEADER_X_FORWARDED_HOST |
|
||||||
|
Request::HEADER_X_FORWARDED_PORT |
|
||||||
|
Request::HEADER_X_FORWARDED_PROTO |
|
||||||
|
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||||
|
|
||||||
|
}
|
||||||
17
app/Http/Middleware/VerifyCsrfToken.php
Executable file
17
app/Http/Middleware/VerifyCsrfToken.php
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||||
|
|
||||||
|
class VerifyCsrfToken extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The URIs that should be excluded from CSRF verification.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $except = [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
91
app/Models/AItems.php
Executable file
91
app/Models/AItems.php
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class AItems extends Model
|
||||||
|
{
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const IS_ADM_PRICE_NO = 0;
|
||||||
|
const IS_ADM_PRICE_YES = 1;
|
||||||
|
|
||||||
|
// 0=>system, 1=>admin, 2=>finance
|
||||||
|
const CRT_TYPE_SYSTEM = 0;
|
||||||
|
const CRT_TYPE_ADMIN = 1;
|
||||||
|
const CRT_TYPE_FINANCE = 2;
|
||||||
|
|
||||||
|
public static function listAItems($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND a_item.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['crt_type'])) {
|
||||||
|
$where .= ' AND a_item.crt_type = ?';
|
||||||
|
$params[] = $filter['crt_type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
a_item.*,ut.name as type_name
|
||||||
|
$select
|
||||||
|
FROM
|
||||||
|
t_a_items as a_item
|
||||||
|
INNER JOIN t_unit_types as ut ON a_item.type = ut.id
|
||||||
|
WHERE a_item.dlt is null
|
||||||
|
$where
|
||||||
|
ORDER BY a_item.name ASC
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showAItemsById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_a_items as a_item WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_a_items as a_item WHERE dlt is null ORDER BY a_item.name ASC;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_a_items as a_item WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByName($name, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [$name];
|
||||||
|
$where = '';
|
||||||
|
if (isset($filter['crt_type'])) {
|
||||||
|
$where .= ' AND a_item.crt_type = ?';
|
||||||
|
$params[] = $filter['crt_type'];
|
||||||
|
}
|
||||||
|
return DB::select("SELECT * FROM t_a_items as a_item WHERE dlt is null AND name = ? $where LIMIT 1;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_a_items")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_a_items")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_a_items")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
93
app/Models/Banks.php
Executable file
93
app/Models/Banks.php
Executable file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Banks extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const DFT_BANK_ID = 1; // BCA
|
||||||
|
const DFT_BANK_CODE = 014;
|
||||||
|
const DFT_BANK_NAME = "Bank Central Asia";
|
||||||
|
const DFT_BANK_SHORT_NAME = "BCA";
|
||||||
|
const DFT_BANK_ACC_NUMBER = 5270860721;
|
||||||
|
const DFT_BANK_ACC_NAME = "PT Bonceng Indonesia";
|
||||||
|
|
||||||
|
const defaultSelectedBanks = "
|
||||||
|
banks.*
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listBanks($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$join = '';
|
||||||
|
$where = '';
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Banks::defaultSelectedBanks . "
|
||||||
|
$select
|
||||||
|
FROM t_banks as banks
|
||||||
|
$join
|
||||||
|
WHERE banks.dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showBankById($bid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Banks::defaultSelectedBanks . "
|
||||||
|
FROM t_banks as banks
|
||||||
|
WHERE banks.dlt is null AND banks.id = ?
|
||||||
|
LIMIT 1;", [$bid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showBankByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Banks::defaultSelectedBanks . "
|
||||||
|
FROM t_banks as banks
|
||||||
|
WHERE banks.dlt is null AND banks.bank_code = ?
|
||||||
|
LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getBanks()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_banks WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getBankById($bid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_banks WHERE dlt is null AND id = ? LIMIT 1;", [$bid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getBankByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_banks WHERE dlt is null AND bank_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addBank($data)
|
||||||
|
{
|
||||||
|
$bid = DB::table("t_banks")->insertGetId($data);
|
||||||
|
return $bid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateBank($bid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_banks")->where("id", $bid)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteBank($bid)
|
||||||
|
{
|
||||||
|
return DB::table("t_banks")->where("id", $bid)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
app/Models/Checkpoints.php
Executable file
80
app/Models/Checkpoints.php
Executable file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Checkpoints extends Model
|
||||||
|
{
|
||||||
|
const defaultSelectedCheckpoints = "
|
||||||
|
point.*
|
||||||
|
,pck.name as pck_name,pck.fulladdress as pck_fulladdress
|
||||||
|
,drp.name as drop_name,drp.fulladdress as drop_fulladdress
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listCheckpoints($filter = [])
|
||||||
|
{
|
||||||
|
$where = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['pocket_id'])) {
|
||||||
|
$where .= ' AND point.pocket_id = ?';
|
||||||
|
$params[] = $filter['pocket_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Checkpoints::defaultSelectedCheckpoints . "
|
||||||
|
FROM t_checkpoints as point
|
||||||
|
INNER JOIN t_zones as pck ON point.pck_id = pck.id
|
||||||
|
LEFT JOIN t_zones as drp ON point.drop_id = drp.id
|
||||||
|
WHERE point.dlt is null $where;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showCheckpointById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Checkpoints::defaultSelectedCheckpoints . "
|
||||||
|
FROM t_checkpoints as point
|
||||||
|
LEFT JOIN t_zones as pck ON point.pck_id = pck.id
|
||||||
|
LEFT JOIN t_zones as drp ON point.drop_id = drp.id
|
||||||
|
WHERE point.dlt is null AND point.id = ?
|
||||||
|
LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpoints()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_checkpoints WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpointById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_checkpoints WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpointByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_checkpoints WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addCheckpoint($data)
|
||||||
|
{
|
||||||
|
$pid = DB::table("t_checkpoints")->insertGetId($data);
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateCheckpoint($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_checkpoints")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCheckpoint($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_checkpoints")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCheckpointByPocketId($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_checkpoints")->where("pocket_id", $pocket_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
172
app/Models/Clients.php
Executable file
172
app/Models/Clients.php
Executable file
@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Clients extends Model
|
||||||
|
{
|
||||||
|
const CSTTS_ACTIVE = 1;
|
||||||
|
const CSTTS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const CCREDENTIALS_CREATE = 1;
|
||||||
|
const CCREDENTIALS_NOT = 2;
|
||||||
|
|
||||||
|
const DEFAULT_PHONE_CODE = 62;
|
||||||
|
|
||||||
|
const DEFAULT_CID = 1; // swanusa account
|
||||||
|
|
||||||
|
const DISC_TYPE_NO = 0;
|
||||||
|
const DISC_TYPE_FIX = 1;
|
||||||
|
const DISC_TYPE_PERCENT = 2;
|
||||||
|
|
||||||
|
public static function listClients($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = "";
|
||||||
|
$join = "";
|
||||||
|
$where = "";
|
||||||
|
|
||||||
|
if (isset($filter["company"])) {
|
||||||
|
$where .= " AND c.id = ?";
|
||||||
|
$params[] = $filter["company"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["c_status"])) {
|
||||||
|
$where .= " AND c.c_status = ?";
|
||||||
|
$params[] = $filter["c_status"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT c.*
|
||||||
|
,c.id as client_id,u.id as user_id
|
||||||
|
,c.crt as join_date
|
||||||
|
,(SELECT COUNT(id) FROM t_orders_clients WHERE c_pt_id = c.id) as count_trx
|
||||||
|
" .
|
||||||
|
$select .
|
||||||
|
"
|
||||||
|
FROM t_clients AS c
|
||||||
|
LEFT JOIN t_users AS u ON c.id = u.client_id
|
||||||
|
" .
|
||||||
|
$join .
|
||||||
|
"
|
||||||
|
WHERE c.dlt is null
|
||||||
|
" .
|
||||||
|
$where .
|
||||||
|
"
|
||||||
|
GROUP BY c.id
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showClientById($cid)
|
||||||
|
{
|
||||||
|
$params = [$cid];
|
||||||
|
return DB::select(
|
||||||
|
"SELECT c.*
|
||||||
|
,c.id as client_id,u.id as user_id
|
||||||
|
,c.crt as join_date
|
||||||
|
FROM t_clients AS c
|
||||||
|
LEFT JOIN t_users AS u ON c.id = u.client_id
|
||||||
|
WHERE c.dlt is null
|
||||||
|
AND c.id = ?
|
||||||
|
LIMIT 1;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getClients()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getClientById($cid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND id = ? LIMIT 1;", [$cid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getClientByEmail($email)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND c_mail = ? LIMIT 2;", [$email]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getClientByPhone($phone)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND c_phone = ? LIMIT 2;", [$phone]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getClientByName($name)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND c_name = ? LIMIT 2;", [$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPicByEmail($email)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND pic_mail = ? LIMIT 2;", [$email]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPicByPhone($phone)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients WHERE dlt is null AND pic_phone = ? LIMIT 2;", [$phone]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addClient($data)
|
||||||
|
{
|
||||||
|
$cid = DB::table("t_clients")->insertGetId($data);
|
||||||
|
return $cid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateClient($cid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients")
|
||||||
|
->where("id", $cid)
|
||||||
|
->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteClient($cid)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients")
|
||||||
|
->where("id", $cid)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function select2Client($cid = null)
|
||||||
|
{
|
||||||
|
$query = "";
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if ($cid) {
|
||||||
|
$query .= "SELECT id,c_name as name FROM t_clients AS c WHERE dlt is null AND c.id = ?;";
|
||||||
|
$params[] = $cid;
|
||||||
|
} else {
|
||||||
|
$query .= "SELECT id,c_name as name FROM t_clients AS c WHERE dlt is null;";
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function arrDiscountTypes()
|
||||||
|
{
|
||||||
|
return [Clients::DISC_TYPE_NO, Clients::DISC_TYPE_FIX, Clients::DISC_TYPE_PERCENT];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function select2DiscountTypes()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"id" => Clients::DISC_TYPE_NO,
|
||||||
|
"name" => "No Discount",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => Clients::DISC_TYPE_FIX,
|
||||||
|
"name" => "Fix Amount",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => Clients::DISC_TYPE_PERCENT,
|
||||||
|
"name" => "Percent Amount",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Models/ClientsDivGroups.php
Executable file
43
app/Models/ClientsDivGroups.php
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ClientsDivGroups extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const DEFAULT_CID = 1; // swanusa account
|
||||||
|
|
||||||
|
public static function getCDivGroups()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCDivGroupById($c_div_group_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null AND id = ? LIMIT 1;", [$c_div_group_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCDivGroupByName($name)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null AND name = ? LIMIT 2;", [$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addCDivGroup($data)
|
||||||
|
{
|
||||||
|
$c_div_group_id = DB::table("t_clients_div_groups")->insertGetId($data);
|
||||||
|
return $c_div_group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateCDivGroup($c_div_group_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients_div_groups")->where("id", $c_div_group_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCDivGroup($c_div_group_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients_div_groups")->where("id", $c_div_group_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Models/ClientsDivs.php
Executable file
43
app/Models/ClientsDivs.php
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ClientsDivs extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const DEFAULT_CID = 1; // swanusa account
|
||||||
|
|
||||||
|
public static function getCDivs()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_divs WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCDivById($client_div_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_divs WHERE dlt is null AND id = ? LIMIT 1;", [$client_div_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCDivByName($name)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_clients_divs WHERE dlt is null AND name = ? LIMIT 2;", [$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addCDiv($data)
|
||||||
|
{
|
||||||
|
$client_div_id = DB::table("t_clients_divs")->insertGetId($data);
|
||||||
|
return $client_div_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateCDiv($client_div_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients_divs")->where("id", $client_div_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCDiv($client_div_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_clients_divs")->where("id", $client_div_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
149
app/Models/ConfRates.php
Executable file
149
app/Models/ConfRates.php
Executable file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ConfRates extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const UNIT_DAY = 1;
|
||||||
|
|
||||||
|
const LANE_EARTH = 1;
|
||||||
|
const LANE_SEA = 2;
|
||||||
|
|
||||||
|
const CRT_TYPE_SYSTEM = 0;
|
||||||
|
const CRT_TYPE_ADMIN = 1;
|
||||||
|
|
||||||
|
const defaultSelectedRates = "
|
||||||
|
rates.*
|
||||||
|
,(SELECT name FROM t_conf_lanes WHERE id = rates.lane LIMIT 1) as lane_name
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = rates.origin_prov LIMIT 1) as origin_prov_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = rates.origin_city LIMIT 1) as origin_city_name
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = rates.dest_prov LIMIT 1) as dest_prov_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = rates.dest_city LIMIT 1) as dest_city_name
|
||||||
|
,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = rates.dest_district LIMIT 1) as dest_district_name
|
||||||
|
,u.first_name as vdr_name,u.email as vdr_mail,vt.name as vhc_type_name
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listRates()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. ConfRates::defaultSelectedRates . "
|
||||||
|
FROM t_conf_rates as rates
|
||||||
|
LEFT JOIN t_users as u ON rates.vdr_id = u.id
|
||||||
|
LEFT JOIN t_vehicles_types as vt ON rates.vhc_type = vt.id
|
||||||
|
WHERE rates.dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showRateById($rid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. ConfRates::defaultSelectedRates . "
|
||||||
|
FROM t_conf_rates as rates
|
||||||
|
LEFT JOIN t_users as u ON rates.vdr_id = u.id
|
||||||
|
LEFT JOIN t_vehicles_types as vt ON rates.vhc_type = vt.id
|
||||||
|
WHERE rates.dlt is null AND rates.id = ?
|
||||||
|
LIMIT 1;", [$rid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRates()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRateById($rid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND id = ? LIMIT 1;", [$rid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRateByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // start packing list data
|
||||||
|
// public static function getRateByDestCity($ori_prid, $dest_ktid)
|
||||||
|
// {
|
||||||
|
// return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND is_active = " . ConfRates::IS_ACTIVE . " AND vdr_id != 0 AND vhc_type != 0 AND origin_prov = ? AND dest_city = ? GROUP BY long_time,sell_cbm,sell_kg ORDER BY fast_time ASC;", [$ori_prid, $dest_ktid]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public static function getRateByDestDistrict($ori_prid, $dest_kcid)
|
||||||
|
// {
|
||||||
|
// return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND is_active = " . ConfRates::IS_ACTIVE . " AND vdr_id != 0 AND vhc_type != 0 AND origin_prov = ? AND dest_district = ? GROUP BY long_time,sell_cbm,sell_kg ORDER BY fast_time ASC;", [$ori_prid, $dest_kcid]);
|
||||||
|
// }
|
||||||
|
// // end packing list data
|
||||||
|
|
||||||
|
// // start without packing list data
|
||||||
|
public static function getRateByDestCity($ori_prid, $dest_ktid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND is_active = " . ConfRates::IS_ACTIVE . " AND vdr_id != 0 AND vhc_type != 0 AND origin_prov = ? AND dest_city = ? GROUP BY long_time,sell_ftl ORDER BY fast_time ASC;", [$ori_prid, $dest_ktid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRateByDestDistrict($ori_prid, $dest_kcid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND is_active = " . ConfRates::IS_ACTIVE . " AND vdr_id != 0 AND vhc_type != 0 AND origin_prov = ? AND dest_district = ? GROUP BY long_time,sell_ftl ORDER BY fast_time ASC;", [$ori_prid, $dest_kcid]);
|
||||||
|
}
|
||||||
|
// // end without packing list data
|
||||||
|
|
||||||
|
public static function getUniqRate($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$join = '';
|
||||||
|
|
||||||
|
if (isset($filter['origin_prov_dest_ktid_dest_kcid_vhc_type_sell_ftl_long_time'])) {
|
||||||
|
$where .= ' AND ((origin_prov = ? AND dest_city = ?) OR (origin_prov = ? AND dest_district = ?)) AND vhc_type = ? AND sell_ftl = ? AND long_time = ?';
|
||||||
|
array_push($params, $filter['origin_prov'], $filter['dest_city'], $filter['origin_prov'], $filter['dest_district'], $filter['vhc_type'], $filter['sell_ftl'], $filter['long_time']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND rate.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
rate.*
|
||||||
|
$select
|
||||||
|
FROM t_conf_rates as rate
|
||||||
|
$join
|
||||||
|
WHERE rate.dlt is null
|
||||||
|
$where
|
||||||
|
ORDER BY fast_time ASC;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkVhcType($type_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_rates WHERE dlt is null AND vhc_type = ? LIMIT 1;", [$type_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addRate($data)
|
||||||
|
{
|
||||||
|
$rid = DB::table("t_conf_rates")->insertGetId($data);
|
||||||
|
return $rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateRate($rid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_conf_rates")->where("id", $rid)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteRate($rid)
|
||||||
|
{
|
||||||
|
return DB::table("t_conf_rates")->where("id", $rid)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* t_conf_lane
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function getLanesActive()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_conf_lanes WHERE dlt is null AND is_active = 1;");
|
||||||
|
}
|
||||||
|
}
|
||||||
104
app/Models/ConfTruckTypes.php
Executable file
104
app/Models/ConfTruckTypes.php
Executable file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ConfTruckTypes extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const IS_PUBLISH = 1;
|
||||||
|
const IS_UNPUBLISH = 2;
|
||||||
|
|
||||||
|
const defaultSelectedTruckTypes = "
|
||||||
|
tt.*
|
||||||
|
,vt.name as type_name,vt.desc as type_desc
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listTruckTypes($isActive = 0, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$whereIsActive = '';
|
||||||
|
if ($isActive != 0) {
|
||||||
|
$whereIsActive = ' AND vt.is_active = ' . ConfTruckTypes::IS_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_publish'])) {
|
||||||
|
$whereIsActive = ' AND vt.is_publish = ?';
|
||||||
|
$params[] = $filter['is_publish'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT " . ConfTruckTypes::defaultSelectedTruckTypes . " FROM t_conf_truck_types as tt LEFT JOIN t_vehicles_types as vt ON tt.type_id = vt.id WHERE tt.dlt is null " . $whereIsActive . " ;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listTruckTypesRates($isActive = 0, $lane)
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$params[] = $lane;
|
||||||
|
|
||||||
|
$whereIsActive = '';
|
||||||
|
if ($isActive != 0) {
|
||||||
|
$whereIsActive = ' AND vt.is_active = ' . ConfTruckTypes::IS_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. ConfTruckTypes::defaultSelectedTruckTypes . "
|
||||||
|
FROM t_conf_truck_types as tt
|
||||||
|
LEFT JOIN t_vehicles_types as vt ON tt.type_id = vt.id
|
||||||
|
INNER JOIN t_conf_rates as rate ON tt.type_id = rate.vhc_type
|
||||||
|
WHERE tt.dlt is null "
|
||||||
|
. $whereIsActive . "
|
||||||
|
AND rate.lane = ?
|
||||||
|
GROUP BY vhc_type
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showTruckTypeById($ttid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT " . ConfTruckTypes::defaultSelectedTruckTypes . " FROM t_conf_truck_types as tt LEFT JOIN t_vehicles_types as vt ON tt.type_id = vt.id WHERE tt.dlt is null AND tt.id = ? LIMIT 1;", [$ttid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTruckTypeByName($type_name)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT " . ConfTruckTypes::defaultSelectedTruckTypes . " FROM t_conf_truck_types as tt LEFT JOIN t_vehicles_types as vt ON tt.type_id = vt.id WHERE tt.dlt is null AND vt.name LIKE ? LIMIT 2;", ['%'.$type_name.'%']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addTruckType($data)
|
||||||
|
{
|
||||||
|
$ttid = DB::table("t_conf_truck_types")->insertGetId($data);
|
||||||
|
return $ttid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateTruckType($ttid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_conf_truck_types")->where("id", $ttid)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteTruckType($ttid)
|
||||||
|
{
|
||||||
|
return DB::table("t_conf_truck_types")->where("id", $ttid)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* t_vehicles_types
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function getTypeById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_vehicles_types WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addTypes($data)
|
||||||
|
{
|
||||||
|
return DB::table("t_vehicles_types")->insertGetId($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtTypes($tid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_vehicles_types")->where("id", $tid)->update($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Models/Dana.php
Executable file
65
app/Models/Dana.php
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Dana extends Model
|
||||||
|
{
|
||||||
|
const defaultSelectedDana = "
|
||||||
|
dana.*
|
||||||
|
";
|
||||||
|
|
||||||
|
const PK_ID = 1;
|
||||||
|
const MINIMUM_AMT = 1000000; // 9M
|
||||||
|
|
||||||
|
public static function listDana($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['id'])) {
|
||||||
|
$where .= ' AND dana.id = ?';
|
||||||
|
$params[] = $filter['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Dana::defaultSelectedDana . "
|
||||||
|
$select
|
||||||
|
FROM t_dana as dana
|
||||||
|
$join
|
||||||
|
WHERE dana.id is not null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDana()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_dana WHERE id is not null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDanaById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_dana WHERE id is not null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addDana($data)
|
||||||
|
{
|
||||||
|
$pid = DB::table("t_dana")->insertGetId($data);
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDana($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_dana")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDana($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_dana")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
107
app/Models/DataTypes.php
Executable file
107
app/Models/DataTypes.php
Executable file
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DataTypes extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
const defaultSelectedDataTypes = "
|
||||||
|
dtypes.*
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listDataTypes($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND dtypes.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. DataTypes::defaultSelectedDataTypes . "
|
||||||
|
$select
|
||||||
|
FROM t_datatypes as dtypes
|
||||||
|
$join
|
||||||
|
WHERE dtypes.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showDataType($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['data_types_id'])) {
|
||||||
|
$where .= ' AND dtypes.id = ?';
|
||||||
|
$params[] = $filter['data_types_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. DataTypes::defaultSelectedDataTypes . "
|
||||||
|
$select
|
||||||
|
FROM t_datatypes as dtypes
|
||||||
|
$join
|
||||||
|
WHERE dtypes.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataTypes()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_datatypes WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataTypeById($data_types_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_datatypes WHERE dlt is null AND id = ? LIMIT 1;", [$data_types_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataTypeByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_datatypes WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataTypeByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_datatypes WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addDataType($data)
|
||||||
|
{
|
||||||
|
$data_types_id = DB::table("t_datatypes")->insertGetId($data);
|
||||||
|
return $data_types_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDataType($data_types_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_datatypes")->where("id", $data_types_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDataType($data_types_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_datatypes")->where("id", $data_types_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
110
app/Models/Devices.php
Executable file
110
app/Models/Devices.php
Executable file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Devices extends Model
|
||||||
|
{
|
||||||
|
const MAX_DEVICE_ID = 16;
|
||||||
|
|
||||||
|
const TYPE_BUILT_IN = 1;
|
||||||
|
const TYPE_PORTABLE = 2;
|
||||||
|
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const IS_ASSIGNED = 1;
|
||||||
|
const IS_UNASSIGNED = 2;
|
||||||
|
|
||||||
|
const IS_AVAIL = 1;
|
||||||
|
const IS_UNAVAIL = 2;
|
||||||
|
|
||||||
|
const defaultSelectedDevices = "
|
||||||
|
devices.*,vhc.id as vhc_id,vhc.nopol1 as vhc_nopol1,vhc.nopol2 as vhc_nopol2,vhc.nopol3 as vhc_nopol3
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listDevices($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND devices.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_available'])) {
|
||||||
|
$where .= ' AND devices.is_available = ?';
|
||||||
|
$params[] = $filter['is_available'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['type'])) {
|
||||||
|
$where .= ' AND devices.type = ?';
|
||||||
|
$params[] = $filter['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_idle_yes'])) {
|
||||||
|
$where .= ' AND vhc.id is null';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_idle_no'])) {
|
||||||
|
$where .= ' AND vhc.id is not null';
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Devices::defaultSelectedDevices . "
|
||||||
|
FROM t_devices as devices
|
||||||
|
LEFT JOIN t_vehicles as vhc ON devices.device_id = vhc.device_id
|
||||||
|
WHERE devices.dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showDeviceById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Devices::defaultSelectedDevices . "
|
||||||
|
FROM t_devices as devices
|
||||||
|
LEFT JOIN t_vehicles as vhc ON devices.device_id = vhc.device_id
|
||||||
|
WHERE devices.dlt is null AND devices.id = ?
|
||||||
|
LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDevices()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_devices WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDeviceById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_devices WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDeviceByDeviceId($device_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_devices WHERE dlt is null AND device_id = ? LIMIT 1;", [$device_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDeviceBySimcard($simcard)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_devices WHERE dlt is null AND simcard = ? LIMIT 1;", [$simcard]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addDevice($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_devices")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDevice($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_devices")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDevice($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_devices")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
318
app/Models/Drivers.php
Executable file
318
app/Models/Drivers.php
Executable file
@ -0,0 +1,318 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Models\Orders;
|
||||||
|
|
||||||
|
class Drivers extends Model
|
||||||
|
{
|
||||||
|
const DEFAULT_PHONE_CODE = 62;
|
||||||
|
|
||||||
|
const STTS_ACTIVE = 1;
|
||||||
|
const STTS_INACTIVE = 2;
|
||||||
|
|
||||||
|
// const IN_ORD_YES = 1;
|
||||||
|
// const IN_ORD_NO = 2;
|
||||||
|
const IN_ORD_YES = 2;
|
||||||
|
const IN_ORD_NO = 1;
|
||||||
|
|
||||||
|
private const defaultSelectDriver = "d.*,dt.*,d.id,d.crt,d.crt_by,d.updt,d.updt_by,d.dlt,d.dlt_by";
|
||||||
|
|
||||||
|
public static function listDrivers($auth, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = "";
|
||||||
|
$join = "";
|
||||||
|
$where = "";
|
||||||
|
|
||||||
|
if ($auth->role == Users::ROLE_VENDOR) {
|
||||||
|
$where .= " AND d.vendor_id = " . $auth->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["company"])) {
|
||||||
|
$where .= " AND client.id = ?";
|
||||||
|
$params[] = $filter["company"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// d.nik,d.fullname,d.phone,d.phone_code,d.email,d.dob,d.age,d.gender,d.blood,d.fulladdress,d.crt,d.crt_by,d.updt,d.updt_by,
|
||||||
|
// dt.ktp_img,dt.npwp_img,dt.npwp_number,dt.npwp_string,dt.license_img,dt.license_number,dt.license_exp,dt.em_fullname,dt.em_phone,dt.em_phone_code,dt.em_relationship
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
" .
|
||||||
|
self::defaultSelectDriver .
|
||||||
|
"
|
||||||
|
,client.c_name as company_name
|
||||||
|
" .
|
||||||
|
$select .
|
||||||
|
"
|
||||||
|
FROM t_drivers as d
|
||||||
|
INNER JOIN t_drivers_detail AS dt ON d.id = dt.did
|
||||||
|
LEFT JOIN t_users AS vdr ON d.vendor_id = vdr.id
|
||||||
|
LEFT JOIN t_clients AS client ON vdr.client_group_id = client.id
|
||||||
|
" .
|
||||||
|
$join .
|
||||||
|
"
|
||||||
|
WHERE d.dlt is null
|
||||||
|
" .
|
||||||
|
$where .
|
||||||
|
"
|
||||||
|
ORDER BY d.id ASC;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDrivers($auth, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$where_vendor = "";
|
||||||
|
$join_vendor = "";
|
||||||
|
if ($auth->role != Users::ROLE_ADMIN) {
|
||||||
|
$where_vendor .= " AND d.vendor_id = " . $auth->uid;
|
||||||
|
}
|
||||||
|
if (isset($filter["status"])) {
|
||||||
|
$where_vendor .= " AND d.status = ?";
|
||||||
|
array_push($params, $filter["status"]);
|
||||||
|
}
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_drivers as d WHERE dlt is null " .
|
||||||
|
$where_vendor .
|
||||||
|
";",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showDriverById($did)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
" .
|
||||||
|
self::defaultSelectDriver .
|
||||||
|
"
|
||||||
|
FROM t_drivers AS d
|
||||||
|
INNER JOIN t_drivers_detail AS dt ON d.id = dt.did
|
||||||
|
WHERE d.dlt is null AND d.id = ? LIMIT 1;",
|
||||||
|
[$did]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriverById($did)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_drivers WHERE dlt is null AND id = ? LIMIT 1;",
|
||||||
|
[$did]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriverByEmail($email)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_drivers WHERE dlt is null AND email = ? LIMIT 2;",
|
||||||
|
[$email]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriverByPhone($phone)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_drivers WHERE dlt is null AND phone = ? LIMIT 2;",
|
||||||
|
[$phone]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriverByNik($nik)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_drivers WHERE dlt is null AND nik = ? LIMIT 2;",
|
||||||
|
[$nik]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriverByIdAllData($did)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
*,d.id as drv_id
|
||||||
|
FROM t_drivers as d
|
||||||
|
INNER JOIN t_drivers_detail as dt ON d.id = dt.did
|
||||||
|
WHERE d.dlt is null
|
||||||
|
AND d.id = ?
|
||||||
|
LIMIT 1;",
|
||||||
|
[$did]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriversNoInOrder($auth, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$where_vendor = "";
|
||||||
|
$join_vendor = "";
|
||||||
|
if ($auth->role != Users::ROLE_ADMIN) {
|
||||||
|
$where_vendor .= " AND d.vendor_id = " . $auth->uid;
|
||||||
|
}
|
||||||
|
if (isset($filter["status"])) {
|
||||||
|
$where_vendor .= " AND d.status = ?";
|
||||||
|
array_push($params, $filter["status"]);
|
||||||
|
}
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
d.*,ord.status as ord_status
|
||||||
|
FROM t_drivers as d
|
||||||
|
LEFT JOIN (SELECT MAX(ord_id) as max_ord_id,drv_id FROM t_orders_drivers GROUP BY drv_id) as ord_drv1 ON (d.id = ord_drv1.drv_id)
|
||||||
|
LEFT JOIN t_orders as ord ON (ord_drv1.max_ord_id = ord.id)
|
||||||
|
WHERE d.dlt is null
|
||||||
|
AND (ord.status is null OR ord.status IN (" .
|
||||||
|
Orders::STTS_CLIENT_PAY .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_VENDOR_PAYED .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_CLOSE .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_CANCEL .
|
||||||
|
"))
|
||||||
|
" .
|
||||||
|
$where_vendor .
|
||||||
|
"
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDriversNoInOrderNew($auth, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$where_vendor = "";
|
||||||
|
$join_vendor = "";
|
||||||
|
if ($auth->role != Users::ROLE_ADMIN) {
|
||||||
|
$where_vendor .= " AND d.vendor_id = " . $auth->uid;
|
||||||
|
}
|
||||||
|
if (isset($filter["status"])) {
|
||||||
|
$where_vendor .= " AND d.status = ?";
|
||||||
|
array_push($params, $filter["status"]);
|
||||||
|
}
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
d.*
|
||||||
|
FROM t_drivers as d
|
||||||
|
WHERE d.dlt is null
|
||||||
|
AND d.is_in_ord = " .
|
||||||
|
Drivers::IN_ORD_NO .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$where_vendor .
|
||||||
|
"
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function likeName($name)
|
||||||
|
{
|
||||||
|
$params = ["%" . $name . "%"];
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT drv.*,drv_dtl.bank_id,drv_dtl.bank_code,drv_dtl.bank_name,drv_dtl.bank_short_name,drv_dtl.bank_branch_name,drv_dtl.bank_acc_number,drv_dtl.bank_acc_name FROM t_drivers as drv INNER JOIN t_drivers_detail as drv_dtl ON drv.id = drv_dtl.did WHERE dlt is null AND fullname LIKE ?;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addDriver($data)
|
||||||
|
{
|
||||||
|
$did = DB::table("t_drivers")->insertGetId($data);
|
||||||
|
return $did;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDriver($did, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_drivers")
|
||||||
|
->where("id", $did)
|
||||||
|
->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDriver($did)
|
||||||
|
{
|
||||||
|
return DB::table("t_drivers")
|
||||||
|
->where("id", $did)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listRelationships()
|
||||||
|
{
|
||||||
|
// ENUM('wife', 'husband', 'sister', 'brother', 'father', 'mother', 'uncle', 'aunt', 'daughter', 'children', 'grandfather', 'grandmother', 'nephew', 'niece', 'family', 'sibling', 'son', 'cousin')
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
"id" => "wife",
|
||||||
|
"name" => "Wife",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "husband",
|
||||||
|
"name" => "Husband",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "sister",
|
||||||
|
"name" => "Sister",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "brother",
|
||||||
|
"name" => "Brother",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "father",
|
||||||
|
"name" => "Father",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "mother",
|
||||||
|
"name" => "Mother",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "uncle",
|
||||||
|
"name" => "Uncle",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "aunt",
|
||||||
|
"name" => "Aunt",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "cousin",
|
||||||
|
"name" => "Cousin",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "daughter",
|
||||||
|
"name" => "Daughter",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "son",
|
||||||
|
"name" => "Son",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "children",
|
||||||
|
"name" => "Children",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "grandfather",
|
||||||
|
"name" => "Grandfather",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "grandmother",
|
||||||
|
"name" => "Grandmother",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "nephew",
|
||||||
|
"name" => "Nephew",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "niece",
|
||||||
|
"name" => "Niece",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "family",
|
||||||
|
"name" => "Family",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"id" => "sibling",
|
||||||
|
"name" => "Sibling",
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/Models/DriversDetail.php
Executable file
40
app/Models/DriversDetail.php
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DriversDetail extends Model
|
||||||
|
{
|
||||||
|
public static function getDetailByDid($did)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_drivers_detail WHERE did = ? LIMIT 1;", [$did]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDetailById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_drivers_detail WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addDetail($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_drivers_detail")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDetailByDid($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_drivers_detail")->where("did", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDetail($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_drivers_detail")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDetail($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_drivers_detail")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
87
app/Models/DrvPhoneDevices.php
Executable file
87
app/Models/DrvPhoneDevices.php
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class DrvPhoneDevices extends Model
|
||||||
|
{
|
||||||
|
// t_phone_devices
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
const IS_LOGOUT = 0;
|
||||||
|
const IS_LOGIN = 1;
|
||||||
|
|
||||||
|
public static function get($filter = [])
|
||||||
|
{
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['id'])) {
|
||||||
|
$where .= ' AND phn_drv.id = ?';
|
||||||
|
$params[] = $filter['id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['device_id'])) {
|
||||||
|
$where .= ' AND phn_drv.device_id = ?';
|
||||||
|
$params[] = $filter['device_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['id'])) {
|
||||||
|
$where .= ' AND phn_drv.id = ?';
|
||||||
|
$params[] = $filter['id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['uid'])) {
|
||||||
|
$where .= ' AND phn_drv.uid = ?';
|
||||||
|
$params[] = $filter['uid'];
|
||||||
|
}
|
||||||
|
if (isset($filter['drv_id'])) {
|
||||||
|
$where .= ' AND phn_drv.did = ?';
|
||||||
|
$params[] = $filter['drv_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_login'])) {
|
||||||
|
$where .= ' AND phn_drv.is_login = ?';
|
||||||
|
$params[] = $filter['is_login'];
|
||||||
|
}
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND phn_drv.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
phn_drv.*
|
||||||
|
$select
|
||||||
|
FROM t_phone_devices as phn_drv
|
||||||
|
WHERE phn_drv.dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_phone_devices")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_phone_devices")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdDrvId($did, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_phone_devices")->where("did", $did)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_phone_devices")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdDrvId($did)
|
||||||
|
{
|
||||||
|
return DB::table("t_phone_devices")->where("did", $did)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Models/Dummy.php
Executable file
60
app/Models/Dummy.php
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Dummy extends Model
|
||||||
|
{
|
||||||
|
public static function addDummyTrack($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_dummy_tracks")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByGpsId($gps_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_dummy_tracks WHERE gps_id = ?;", [$gps_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateDummyTrack($data)
|
||||||
|
{
|
||||||
|
return DB::table("t_dummy_tracks")->where("id", $data['id'])->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteDummyTrack($data)
|
||||||
|
{
|
||||||
|
return DB::table("t_dummy_tracks")->where("id", $data['id'])->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public static function addDummyHub($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_dummy_hubs")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://stackoverflow.com/questions/574691/mysql-great-circle-distance-haversine-formula
|
||||||
|
* miles: 3958.756 || 3959
|
||||||
|
* km: 6371
|
||||||
|
* meters: 6371000
|
||||||
|
* more accurate using km/meters than miles i think ~ rafifmulia
|
||||||
|
*/
|
||||||
|
public static function nearestHubInCircle($lat, $lng)
|
||||||
|
{
|
||||||
|
$query = "SELECT id,name, ( 6371000 * acos( cos( radians( :lat1 ) ) * cos( radians( lat ) )
|
||||||
|
* cos( radians( lng ) - radians( :lng ) ) + sin( radians( :lat2 ) ) * sin(radians( lat )) ) ) AS distance
|
||||||
|
FROM t_dummy_hubs
|
||||||
|
HAVING distance <= 800
|
||||||
|
ORDER BY distance;";
|
||||||
|
$params = [
|
||||||
|
'lat1' => $lat,
|
||||||
|
'lat2' => $lat,
|
||||||
|
'lng' => $lng,
|
||||||
|
];
|
||||||
|
return DB::select($query, $params);
|
||||||
|
}
|
||||||
|
}
|
||||||
621
app/Models/Finance.php
Executable file
621
app/Models/Finance.php
Executable file
@ -0,0 +1,621 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Models\OrdersVendors;
|
||||||
|
use App\Models\Users;
|
||||||
|
use App\Models\Orders;
|
||||||
|
use App\Models\OrdersAItems;
|
||||||
|
use App\Models\OrdersInvoices;
|
||||||
|
|
||||||
|
class Finance extends Model
|
||||||
|
{
|
||||||
|
public static function listBillings($filter = [])
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_PAID_NO, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where_where .= ' AND ord.id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$where_where .= ' AND ord.crt BETWEEN ? AND ?';
|
||||||
|
$params[] = $filter['start_date'];
|
||||||
|
$params[] = $filter['end_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.id as ord_id,ord.code as ord_code,ord.status as ord_status
|
||||||
|
,(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_vdr = ? AND invc_to_client = ? AND is_bill_aprv = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_billing
|
||||||
|
,(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_vdr = ? AND invc_to_client = ? AND is_bill_paid = ? AND is_bill_aprv = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_payed
|
||||||
|
,(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_vdr = ? AND invc_to_client = ? AND is_bill_paid = ? AND is_bill_aprv = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_remaining
|
||||||
|
,ord.is_invc_paid,ord.invc_paid_at
|
||||||
|
,ord_pck.pck_name,ord_pck.set_pck_at,ord_pck.pck_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_pck.pck_kcid LIMIT 1) as pck_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_pck.pck_klid LIMIT 1) as pck_klid_name
|
||||||
|
,ord_drop.drop_name,ord_drop.drop_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_drop.drop_kcid LIMIT 1) as drop_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_drop.drop_klid LIMIT 1) as drop_klid_name
|
||||||
|
,ord_c.c_name,ord_c.c_pt_name
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||||
|
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord.is_active = " . Orders::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
" . $group_by . "
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function summaryBillings($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
// for sum
|
||||||
|
$join_sum = '';
|
||||||
|
$where_sum = '';
|
||||||
|
$params_sum_totbilling = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
$params_sum_totpayed = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
$params_sum_totremaining = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_PAID_NO, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,];
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$join_sum .= ' INNER JOIN t_orders as o ON a.ord_id = o.id';
|
||||||
|
$where_sum .= ' AND o.crt BETWEEN ? AND ?';
|
||||||
|
array_push($params_sum_totbilling, $filter['start_date'], $filter['end_date']);
|
||||||
|
array_push($params_sum_totpayed, $filter['start_date'], $filter['end_date']);
|
||||||
|
array_push($params_sum_totremaining, $filter['start_date'], $filter['end_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// php spread operator was invented on 7.2
|
||||||
|
$params_real = array_merge($params_sum_totbilling, $params_sum_totpayed, $params_sum_totremaining, $params);
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
-- (SELECT SUM(price) FROM t_orders WHERE dlt is null AND confirm_client_pay_at != 0) as total_billing
|
||||||
|
-- (SELECT SUM(price) FROM t_orders WHERE dlt is null) as total_billing -- sebelum ada fitur merge
|
||||||
|
(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_vdr = ? AND a.invc_to_client = ? AND a.is_bill_aprv = ? AND a.stts_merge IN (?,?) $where_sum) as total_billing
|
||||||
|
,(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_vdr = ? AND a.invc_to_client = ? AND a.is_bill_paid = ? AND a.is_bill_aprv = ? AND a.stts_merge IN (?,?) $where_sum) as total_payed
|
||||||
|
,(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_vdr = ? AND a.invc_to_client = ? AND a.is_bill_paid = ? AND a.is_bill_aprv = ? AND a.stts_merge IN (?,?) $where_sum) as total_remaining
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders_a_items as ord_a
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord_a.dlt is null
|
||||||
|
AND ord_a.is_active = " . OrdersAItems::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
LIMIT 1
|
||||||
|
;",
|
||||||
|
$params_real
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listPayments($filter = [])
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_NO, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where_where .= ' AND ord.id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$where_where .= ' AND ord.crt BETWEEN ? AND ?';
|
||||||
|
$params[] = $filter['start_date'];
|
||||||
|
$params[] = $filter['end_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.id as ord_id,ord.code as ord_code,ord.status as ord_status
|
||||||
|
,ord.group_code as ord_group_code
|
||||||
|
,(SELECT SUM(amt_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_client = ? AND calc_to_vdr = ? AND is_aprv = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_payment
|
||||||
|
,(SELECT SUM(amt_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_client = ? AND calc_to_vdr = ? AND is_aprv = ? AND is_paid = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_payed
|
||||||
|
,(SELECT SUM(amt_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_client = ? AND calc_to_vdr = ? AND is_aprv = ? AND is_paid = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_remaining
|
||||||
|
,ord.is_vdr_paid,ord.vdr_paid_at
|
||||||
|
,ord_pck.pck_name,ord_pck.set_pck_at,ord_pck.pck_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_pck.pck_kcid LIMIT 1) as pck_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_pck.pck_klid LIMIT 1) as pck_klid_name
|
||||||
|
,ord_drop.drop_name,ord_drop.drop_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_drop.drop_kcid LIMIT 1) as drop_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_drop.drop_klid LIMIT 1) as drop_klid_name
|
||||||
|
,ord_c.c_name,ord_c.c_pt_name
|
||||||
|
,ord_vdr.vdr_name,ord_vdr.vdr_pt_name
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||||
|
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||||
|
INNER JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord.is_active = " . Orders::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
" . $group_by . "
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// admin bank tetap terkalkulasi
|
||||||
|
// bagaimana caranya main item client tidak tecalc di pembayaran ? where column only_client is no
|
||||||
|
public static function summaryPayments($filter = [])
|
||||||
|
{
|
||||||
|
// general
|
||||||
|
$params = [];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
// for sum
|
||||||
|
$join_sum = '';
|
||||||
|
$where_sum = '';
|
||||||
|
$params_sum_totpayment = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
$params_sum_totpayed = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
$params_sum_totremaining = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_NO, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$join_sum .= ' INNER JOIN t_orders as o ON a.ord_id = o.id';
|
||||||
|
$where_sum .= ' AND o.crt BETWEEN ? AND ?';
|
||||||
|
array_push($params_sum_totpayment, $filter['start_date'], $filter['end_date']);
|
||||||
|
array_push($params_sum_totpayed, $filter['start_date'], $filter['end_date']);
|
||||||
|
array_push($params_sum_totremaining, $filter['start_date'], $filter['end_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// php spread operator was invented on 7.2
|
||||||
|
$params_real = array_merge($params_sum_totpayment, $params_sum_totpayed, $params_sum_totremaining, $params);
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
-- (SELECT SUM(buy_price) FROM t_orders WHERE dlt is null) as total_payment
|
||||||
|
(SELECT SUM(a.amt_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_client = ? AND a.calc_to_vdr = ? AND a.is_aprv = ? AND a.stts_merge IN (?,?) $where_sum) as total_payment
|
||||||
|
,(SELECT SUM(a.amt_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_client = ? AND a.calc_to_vdr = ? AND a.is_aprv = ? AND a.is_paid = ? AND a.stts_merge IN (?,?) $where_sum) as total_payed
|
||||||
|
,(SELECT SUM(a.amt_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_client = ? AND a.calc_to_vdr = ? AND a.is_aprv = ? AND a.is_paid = ? AND a.stts_merge IN (?,?) $where_sum) as total_remaining
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders_a_items as ord_a
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord_a.dlt is null
|
||||||
|
AND ord_a.is_active = " . OrdersAItems::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
LIMIT 1
|
||||||
|
;",
|
||||||
|
$params_real
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listAdtItemsPayments($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
if (isset($filter['is_access_by_admin'])) {
|
||||||
|
$where_where .= ' AND crt_type = ?';
|
||||||
|
$params[] = OrdersAItems::CRT_TYPE_ADMIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
// $where_where .= ' AND ord.id = ?';
|
||||||
|
$where_where .= ' AND ord_a_item.ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['ord_ids'])) {
|
||||||
|
$binds_ids = "";
|
||||||
|
foreach ($filter['ord_ids'] as $k => $v) {
|
||||||
|
$binds_ids .= "?,";
|
||||||
|
$params[] = $v;
|
||||||
|
}
|
||||||
|
if (substr($binds_ids, -1) === ',') {
|
||||||
|
$binds_ids = substr($binds_ids, 0, -1);
|
||||||
|
}
|
||||||
|
$where_where .= " AND ord_a_item.ord_id IN ($binds_ids)";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_aprv'])) {
|
||||||
|
$where_where .= ' AND ord_a_item.is_aprv = ?';
|
||||||
|
$params[] = $filter['is_aprv'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_crt'])) {
|
||||||
|
$select_order .= ',ucrt.first_name as ucrt_name';
|
||||||
|
$join_join .= ' LEFT JOIN t_users as ucrt ON ord_a_item.crt_by = ucrt.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_rjct'])) {
|
||||||
|
$select_order .= ',urjct.first_name as urjct_name,urjct_bill.first_name as urjct_bill_name';
|
||||||
|
$join_join .= ' LEFT JOIN t_users as urjct ON ord_a_item.rjct_by = urjct.id';
|
||||||
|
$join_join .= ' LEFT JOIN t_users as urjct_bill ON ord_a_item.rjct_bill_by = urjct_bill.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
$params[] = OrdersAItems::ONLY_CLIENT_NO;
|
||||||
|
$params[] = OrdersAItems::CALC_TO_VDR_YES;
|
||||||
|
$params[] = OrdersAItems::IS_HIDDEN_NO;
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_NO;
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_RESULT;
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id,ord_a_item.v_termin_id,ord_a_item.ord_id,ord_a_item.ord_code
|
||||||
|
,ord_a_item.desc,ord_a_item.a_item_type,ord_a_item.crt_type as a_item_crt_type
|
||||||
|
,ord_a_item.crt as a_item_crt_at
|
||||||
|
,ord_a_item.amt_base_flat,ord_a_item.unit_qty,ord_a_item.amt_tax_type,ord_a_item.amt_total_tax_flat,ord_a_item.amt_total_flat
|
||||||
|
,ord_a_item.ddln_pay_at,ord_a_item.ddln_pay_type
|
||||||
|
,ord_a_item.is_paid,ord_a_item.paid_at,ord_a_item.paid_method,ord_a_item.paid_by
|
||||||
|
,ord_a_item.is_bill_paid,ord_a_item.paid_bill_at,ord_a_item.paid_bill_method,ord_a_item.paid_bill_by
|
||||||
|
,ord_a_item.bank_name,ord_a_item.bank_short_name,ord_a_item.bank_acc_number,ord_a_item.bank_acc_name
|
||||||
|
,ord_a_item.invc_to_client
|
||||||
|
,ord_a_item.img_proof_submission
|
||||||
|
,ord_a_item.is_aprv,ord_a_item.rjct_at,ord_a_item.rjct_by,ord_a_item.rjct_bill_at,ord_a_item.rjct_bill_by
|
||||||
|
-- ,ord_a_item.is_merge_to,ord_a_item.merge_to_a_id,ord_a_item.merge_to_ord_id,ord_a_item.merge_to_ord_code,ord_a_item.merge_to_at
|
||||||
|
-- ,ord_a_item.is_merge_from,ord_a_item.merge_from_a_id,ord_a_item.merge_from_ord_id,ord_a_item.merge_from_ord_code,ord_a_item.merge_from_at
|
||||||
|
,ord_a_item.stts_merge,ord_a_item.merge_to_code,ord_a_item.group_merge_code,ord_a_item.merge_at
|
||||||
|
,ord_pck.pck_name,ord_pck.set_pck_at,ord_pck.pck_addr
|
||||||
|
-- ,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name
|
||||||
|
-- ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_pck.pck_kcid LIMIT 1) as pck_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_pck.pck_klid LIMIT 1) as pck_klid_name
|
||||||
|
,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.chk_at as drop_chk_at
|
||||||
|
-- ,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name
|
||||||
|
-- ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_drop.drop_kcid LIMIT 1) as drop_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_drop.drop_klid LIMIT 1) as drop_klid_name
|
||||||
|
,ord_c.c_name,ord_c.c_pt_name
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders_a_items as ord_a_item
|
||||||
|
INNER JOIN t_orders as ord ON ord_a_item.ord_id = ord.id
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||||
|
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord_a_item.dlt is null
|
||||||
|
AND ord.is_active = " . Orders::IS_ACTIVE_YES . "
|
||||||
|
AND ord_a_item.is_active = " . OrdersAItems::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
AND ord_a_item.only_client = ?
|
||||||
|
AND ord_a_item.calc_to_vdr = ?
|
||||||
|
AND ord_a_item.is_hidden = ?
|
||||||
|
AND ord_a_item.stts_merge IN (?,?)
|
||||||
|
" . $group_by . "
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listAdtItemsBillings($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where_where .= ' AND ord.id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_bill_aprv'])) {
|
||||||
|
$where_where .= ' AND ord_a_item.is_bill_aprv = ?';
|
||||||
|
$params[] = $filter['is_bill_aprv'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$params[] = OrdersAItems::ONLY_VDR_NO;
|
||||||
|
$params[] = OrdersAItems::INVC_TO_CLIENT_YES;
|
||||||
|
$params[] = OrdersAItems::IS_HIDDEN_NO;
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_NO;
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_RESULT;
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id,ord_a_item.v_termin_id,ord_a_item.ord_id,ord_a_item.ord_code
|
||||||
|
,ord_a_item.desc,ord_a_item.a_item_type,ord_a_item.crt_type as a_item_crt_type
|
||||||
|
,ord_a_item.unit_type,ut.name as unit_type_name,ord_a_item.unit_qty
|
||||||
|
,ord_a_item.amt_bill_base_flat,ord_a_item.unit_qty,ord_a_item.amt_bill_total_flat
|
||||||
|
,ord_a_item.is_paid,ord_a_item.paid_at,ord_a_item.paid_method,ord_a_item.paid_by
|
||||||
|
,ord_a_item.is_bill_paid,ord_a_item.paid_bill_at,ord_a_item.paid_bill_method,ord_a_item.paid_bill_by
|
||||||
|
,ord_termin.id as c_group_termin_id,ord_termin.termin_is_paid,ord_termin.termin_paid_at
|
||||||
|
,ord_termin.sequence as termin_sequence,ord_termin.termin_ddln_type
|
||||||
|
,ord_termin.termin_tax_type,ord_termin.termin_tax_ppn_percent,ord_termin.termin_tax_ppn_flat,ord_termin.termin_tax_pph_percent,ord_termin.termin_tax_pph_flat
|
||||||
|
,ord_termin.amt_bill_confirm,ord_termin.amt_bill_confirm_note
|
||||||
|
,ord_invc.id as invc_id,ord_invc.code as invc_code
|
||||||
|
,ord_invc.amt_disc_type as invc_disc_type,ord_invc.amt_disc_percent as invc_disc_percent,ord_invc.amt_disc_flat as invc_disc_flat
|
||||||
|
,ord_invc.is_gnrt_invc
|
||||||
|
,ord_a_item.is_aprv,ord_a_item.rjct_at,ord_a_item.rjct_by,ord_a_item.rjct_bill_at,ord_a_item.rjct_bill_by
|
||||||
|
,ord_a_item.stts_merge,ord_a_item.merge_to_code,ord_a_item.group_merge_code,ord_a_item.merge_at
|
||||||
|
,ord_pck.pck_name,ord_pck.set_pck_at,ord_pck.pck_addr
|
||||||
|
-- ,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name
|
||||||
|
-- ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_pck.pck_kcid LIMIT 1) as pck_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_pck.pck_klid LIMIT 1) as pck_klid_name
|
||||||
|
,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.chk_at as drop_chk_at
|
||||||
|
-- ,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name
|
||||||
|
-- ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_drop.drop_kcid LIMIT 1) as drop_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_drop.drop_klid LIMIT 1) as drop_klid_name
|
||||||
|
,ord_c.c_id,ord_c.c_name,ord_c.c_pt_id,ord_c.c_pt_name
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders_a_items as ord_a_item
|
||||||
|
INNER JOIN t_orders as ord ON ord_a_item.ord_id = ord.id
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||||
|
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||||
|
INNER JOIN t_orders_termins as ord_termin ON ord_a_item.c_termin_id = ord_termin.id
|
||||||
|
LEFT JOIN t_orders_invoices as ord_invc ON ord_termin.id = ord_invc.c_termin_id
|
||||||
|
LEFT JOIN t_unit_types as ut ON ord_a_item.unit_type = ut.id
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord_a_item.dlt is null
|
||||||
|
AND ord.is_active = " . Orders::IS_ACTIVE_YES . "
|
||||||
|
AND ord_a_item.is_active = " . OrdersAItems::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
AND only_vdr = ?
|
||||||
|
AND invc_to_client = ?
|
||||||
|
AND ord_a_item.is_hidden = ?
|
||||||
|
AND ord_a_item.stts_merge IN (?,?)
|
||||||
|
" . $group_by . "
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listLedgerBl($filter = [])
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT,
|
||||||
|
];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where_where .= ' AND ord.id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['with_items'])) {
|
||||||
|
$select_order .= "
|
||||||
|
,ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.a_item_type,ord_a_item.desc as item_desc,ord_a_item.unit_type,unit_type.name as unit_type_name,ord_a_item.unit_qty
|
||||||
|
,ord_a_item.amt_base_flat,ord_a_item.amt_result_flat,ord_a_item.amt_total_flat
|
||||||
|
,ord_a_item.amt_bill_base_flat,ord_a_item.amt_bill_result_flat,ord_a_item.amt_bill_total_flat
|
||||||
|
,ord_a_item.is_paid,ord_a_item.paid_at,ord_a_item.is_bill_paid,ord_a_item.paid_bill_at
|
||||||
|
,ord_a_item.invc_to_client,ord_a_item.calc_to_vdr,ord_a_item.is_adm_price,ord_a_item.only_client,ord_a_item.only_vdr,ord_a_item.is_hidden,ord_a_item.is_tax,ord_a_item.is_disc
|
||||||
|
,ord_a_item.is_aprv,ord_a_item.is_bill_aprv
|
||||||
|
";
|
||||||
|
$join_join .= "
|
||||||
|
INNER JOIN t_orders_a_items as ord_a_item ON ord.id = ord_a_item.ord_id
|
||||||
|
LEFT JOIN t_unit_types as unit_type ON ord_a_item.unit_type = unit_type.id
|
||||||
|
";
|
||||||
|
// perlu diperbaiki cara if di query, jika kalkulasi ke vendor maka is_aprv = , jika ke client is_bill_aprv = 1
|
||||||
|
$where_where .= ' AND ord_a_item.dlt is null AND (ord_a_item.calc_to_vdr = ' . OrdersAItems::CALC_TO_VDR_YES . ' OR ord_a_item.invc_to_client = ' . OrdersAItems::INVC_TO_CLIENT_YES . ') AND (ord_a_item.is_aprv = ' . OrdersAItems::IS_APRV_YES . ' OR ord_a_item.is_bill_aprv = ' . OrdersAItems::IS_APRV_YES . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$where_where .= ' AND ord.crt BETWEEN ? AND ?';
|
||||||
|
$params[] = $filter['start_date'];
|
||||||
|
$params[] = $filter['end_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.id as ord_id,ord.code as ord_code,ord.status as ord_status
|
||||||
|
,@total_in:=(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_vdr = ? AND invc_to_client = ? AND is_bill_aprv = ? AND is_bill_paid = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_in
|
||||||
|
,@total_out:=(SELECT SUM(amt_total_flat) FROM t_orders_a_items WHERE dlt is null AND is_active = ? AND only_client = ? AND calc_to_vdr = ? AND is_aprv = ? AND is_paid = ? AND stts_merge IN (?,?) AND ord_id = ord.id) as total_out
|
||||||
|
,(IFNULL(@total_in, 0) - IFNULL(@total_out, 0)) as total_bl
|
||||||
|
,ord_pck.pck_name,ord_pck.set_pck_at,ord_pck.pck_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_pck.pck_kcid LIMIT 1) as pck_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_pck.pck_klid LIMIT 1) as pck_klid_name
|
||||||
|
,ord_drop.drop_name,ord_drop.drop_addr
|
||||||
|
,(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name
|
||||||
|
,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name
|
||||||
|
-- ,(SELECT nmKecamatanKel FROM t_region WHERE kodeKec = ord_drop.drop_kcid LIMIT 1) as drop_kcid_name
|
||||||
|
-- ,(SELECT nmKelurahan FROM t_region WHERE kodeKel = ord_drop.drop_klid LIMIT 1) as drop_klid_name
|
||||||
|
,ord_c.c_name,ord_c.c_pt_name
|
||||||
|
,ord_vdr.vdr_name,ord_vdr.vdr_pt_name
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id
|
||||||
|
INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id
|
||||||
|
INNER JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord.is_active = " . Orders::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
" . $group_by . "
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function summaryLedgerBl($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = '';
|
||||||
|
$join_join = '';
|
||||||
|
$where_where = '';
|
||||||
|
// for sum
|
||||||
|
$join_sum = '';
|
||||||
|
$where_sum = '';
|
||||||
|
$params_sum_totin = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_VDR_NO, OrdersAItems::INVC_TO_CLIENT_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
$params_sum_totout = [OrdersAItems::IS_ACTIVE_YES, OrdersAItems::ONLY_CLIENT_NO, OrdersAItems::CALC_TO_VDR_YES, OrdersAItems::IS_APRV_YES, OrdersAItems::IS_PAID_YES, OrdersAItems::STTS_MERGE_NO, OrdersAItems::STTS_MERGE_RESULT];
|
||||||
|
|
||||||
|
if (isset($filter['start_date']) && isset($filter['end_date'])) {
|
||||||
|
$join_sum .= ' INNER JOIN t_orders as o ON a.ord_id = o.id';
|
||||||
|
$where_sum .= ' AND o.crt BETWEEN ? AND ?';
|
||||||
|
array_push($params_sum_totin, $filter['start_date'], $filter['end_date']);
|
||||||
|
array_push($params_sum_totout, $filter['start_date'], $filter['end_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// php spread operator was invented on 7.2
|
||||||
|
$params_real = array_merge($params_sum_totin, $params_sum_totout, $params);
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
@total_in:=(SELECT SUM(amt_bill_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_vdr = ? AND a.invc_to_client = ? AND a.is_bill_aprv = ? AND a.is_bill_paid = ? AND a.stts_merge IN (?,?) $where_sum) as total_in
|
||||||
|
,@total_out:=(SELECT SUM(amt_total_flat) FROM t_orders_a_items as a $join_sum WHERE a.dlt is null AND a.is_active = ? AND a.only_client = ? AND a.calc_to_vdr = ? AND a.is_aprv = ? AND a.is_paid = ? AND a.stts_merge IN (?,?) $where_sum) as total_out
|
||||||
|
,(IFNULL(@total_in, 0) - IFNULL(@total_out, 0)) as total_bl
|
||||||
|
" . $select_order . "
|
||||||
|
FROM t_orders_a_items as ord_a
|
||||||
|
" . $join_join . "
|
||||||
|
WHERE ord_a.dlt is null
|
||||||
|
AND ord_a.is_active = " . OrdersAItems::IS_ACTIVE_YES . "
|
||||||
|
" . $where_where . "
|
||||||
|
LIMIT 1
|
||||||
|
;",
|
||||||
|
$params_real
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Baru saja pembayaran dilunaskan baik dari client / vendor
|
||||||
|
* false => error
|
||||||
|
* 0 => not paid, 1 => just paid off, 2 => paid off
|
||||||
|
*/
|
||||||
|
public static function checkJustPaidOff($ord_id)
|
||||||
|
{
|
||||||
|
$order = Orders::showOrder(['id' => $ord_id]);
|
||||||
|
if (count($order) < 1 || $order === false) return false;
|
||||||
|
$out = [
|
||||||
|
'invc_paid' => 0,
|
||||||
|
'vdr_paid' => 0,
|
||||||
|
'invc_vdr_paid' => 0,
|
||||||
|
];
|
||||||
|
$currentBill = Finance::listBillings(['ord_id' => $ord_id]);
|
||||||
|
$currentPay = Finance::listPayments(['ord_id' => $ord_id]);
|
||||||
|
// paid off
|
||||||
|
if ($currentBill[0]->total_billing === $currentBill[0]->total_payed || $currentPay[0]->total_payment === $currentPay[0]->total_payed) {
|
||||||
|
if ($currentBill[0]->total_billing === $currentBill[0]->total_payed) {
|
||||||
|
// just paid off
|
||||||
|
if ($order[0]->is_invc_paid !== Orders::IS_PAID_YES) {
|
||||||
|
$out['invc_paid'] = 1;
|
||||||
|
} else {
|
||||||
|
$out['invc_paid'] = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($currentPay[0]->total_payment === $currentPay[0]->total_payed) {
|
||||||
|
// just paid off
|
||||||
|
if ($order[0]->is_vdr_paid !== Orders::IS_PAID_YES) {
|
||||||
|
$out['vdr_paid'] = 1;
|
||||||
|
} else {
|
||||||
|
$out['vdr_paid'] = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($currentBill[0]->total_billing === $currentBill[0]->total_payed && $currentPay[0]->total_payment === $currentPay[0]->total_payed) {
|
||||||
|
// just paid off
|
||||||
|
if ($out['invc_paid'] === 1 || $out['vdr_paid'] === 1) {
|
||||||
|
$out['invc_vdr_paid'] = 1;
|
||||||
|
} else {
|
||||||
|
$out['invc_vdr_paid'] = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtChangeInvc($c_termin_id)
|
||||||
|
{
|
||||||
|
$ord_invc = OrdersInvoices::getByTerminId($c_termin_id);
|
||||||
|
if ($ord_invc !== false && count($ord_invc) > 0) {
|
||||||
|
OrdersInvoices::updt($ord_invc[0]->id, [
|
||||||
|
'is_gnrt_invc' => OrdersInvoices::IS_GNRT_INVC_NO,
|
||||||
|
]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function availOrdToMerge($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$join = '';
|
||||||
|
$where = '';
|
||||||
|
$group_by = '';
|
||||||
|
|
||||||
|
$where .= ' AND ord.stts_merge IN (?,?)';
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_NO;
|
||||||
|
$params[] = OrdersAItems::STTS_MERGE_RESULT;
|
||||||
|
|
||||||
|
if (isset($filter['except_ord_id'])) {
|
||||||
|
$where .= ' AND ord.id = ?';
|
||||||
|
$params[] = $filter['except_ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.*
|
||||||
|
" . $select . "
|
||||||
|
FROM t_orders as ord
|
||||||
|
" . $join . "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
AND ord.stts_merge = " . Orders::STTS_MERGE_NO . "
|
||||||
|
" . $where . "
|
||||||
|
ORDER BY ord.id DESC
|
||||||
|
" . $group_by . "
|
||||||
|
LIMIT 100
|
||||||
|
;",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Models/Insurances.php
Executable file
65
app/Models/Insurances.php
Executable file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Insurances extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
const IS_INACTIVE = 2;
|
||||||
|
|
||||||
|
const defaultSelectedInsurances = "
|
||||||
|
insurances.*
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listInsurances()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Insurances::defaultSelectedInsurances . "
|
||||||
|
FROM t_insurances as insurances
|
||||||
|
WHERE insurances.dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showInsuranceById($iid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. Insurances::defaultSelectedInsurances . "
|
||||||
|
FROM t_insurances as insurances
|
||||||
|
WHERE insurances.dlt is null AND insurances.id = ?
|
||||||
|
LIMIT 1;", [$iid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInsurances()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_insurances WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInsuranceById($iid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_insurances WHERE dlt is null AND id = ? LIMIT 1;", [$iid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInsurancesByRangeBeneficiaryAndActive($price)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_insurances WHERE dlt is null AND is_active = " . Insurances::IS_ACTIVE . " AND ((premi_min_price >= ? AND premi_max_price <= ?) OR (premi_min_price <= ? AND premi_max_price >= ?)) ORDER BY premi_price DESC;", [$price, $price, $price, $price]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addInsurance($data)
|
||||||
|
{
|
||||||
|
$iid = DB::table("t_insurances")->insertGetId($data);
|
||||||
|
return $iid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateInsurance($iid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_insurances")->where("id", $iid)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteInsurance($iid)
|
||||||
|
{
|
||||||
|
return DB::table("t_insurances")->where("id", $iid)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Models/LogbookKeys.php
Executable file
106
app/Models/LogbookKeys.php
Executable file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class LogbookKeys extends Model
|
||||||
|
{
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
const defaultSelectedLgbKeys = "
|
||||||
|
lgb_key.*
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listLgbKeys($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND lgb_key.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. LogbookKeys::defaultSelectedLgbKeys . "
|
||||||
|
$select
|
||||||
|
FROM t_lgb_keys as lgb_key
|
||||||
|
$join
|
||||||
|
WHERE lgb_key.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showLgbKey($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['lgb_key_id'])) {
|
||||||
|
$where .= ' AND lgb_key.id = ?';
|
||||||
|
$params[] = $filter['lgb_key_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. LogbookKeys::defaultSelectedLgbKeys . "
|
||||||
|
$select
|
||||||
|
FROM t_lgb_keys as lgb_key
|
||||||
|
$join
|
||||||
|
WHERE lgb_key.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbKeys()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_keys WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbKeyById($lgb_key_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_keys WHERE dlt is null AND id = ? LIMIT 1;", [$lgb_key_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbKeyByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_keys WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbKeyByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_keys WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addLgbKey($data)
|
||||||
|
{
|
||||||
|
$lgb_key_id = DB::table("t_lgb_keys")->insertGetId($data);
|
||||||
|
return $lgb_key_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateLgbKey($lgb_key_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_lgb_keys")->where("id", $lgb_key_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteLgbKey($lgb_key_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_lgb_keys")->where("id", $lgb_key_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
107
app/Models/LogbookTypes.php
Executable file
107
app/Models/LogbookTypes.php
Executable file
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class LogbookTypes extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
const defaultSelectedLgbTypes = "
|
||||||
|
lgb_type.*
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listLgbTypes($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND lgb_type.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. LogbookTypes::defaultSelectedLgbTypes . "
|
||||||
|
$select
|
||||||
|
FROM t_lgb_types as lgb_type
|
||||||
|
$join
|
||||||
|
WHERE lgb_type.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showLgbType($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['lgb_type_id'])) {
|
||||||
|
$where .= ' AND lgb_type.id = ?';
|
||||||
|
$params[] = $filter['lgb_type_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['group_by'])) $where .= ' GROUP BY ' . $filter['group_by'];
|
||||||
|
if (isset($filter['order_by'])) $where .= ' ORDER BY ' . $filter['order_by'];
|
||||||
|
if (isset($filter['limit'])) $where .= ' LIMIT ' . $filter['limit'];
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. LogbookTypes::defaultSelectedLgbTypes . "
|
||||||
|
$select
|
||||||
|
FROM t_lgb_types as lgb_type
|
||||||
|
$join
|
||||||
|
WHERE lgb_type.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbTypes()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_types WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbTypeById($lgb_type_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_types WHERE dlt is null AND id = ? LIMIT 1;", [$lgb_type_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbTypeByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_types WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLgbTypeByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_lgb_types WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addLgbType($data)
|
||||||
|
{
|
||||||
|
$lgb_type_id = DB::table("t_lgb_types")->insertGetId($data);
|
||||||
|
return $lgb_type_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateLgbType($lgb_type_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_lgb_types")->where("id", $lgb_type_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteLgbType($lgb_type_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_lgb_types")->where("id", $lgb_type_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
635
app/Models/Orders.php
Executable file
635
app/Models/Orders.php
Executable file
@ -0,0 +1,635 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Models\OrdersVendors;
|
||||||
|
use App\Models\Users;
|
||||||
|
|
||||||
|
class Orders extends Model
|
||||||
|
{
|
||||||
|
const ONE_KG_ONE_CBM = 1328;
|
||||||
|
|
||||||
|
const TYPE_FCL = 1;
|
||||||
|
const TYPE_LCL = 2;
|
||||||
|
|
||||||
|
const STTS_WAIT = 1;
|
||||||
|
const STTS_CONFIRM = 21;
|
||||||
|
const STTS_HAVE_GET_VHC = 22;
|
||||||
|
const STTS_PCK = 2;
|
||||||
|
const STTS_GO = 3;
|
||||||
|
const STTS_ARV = 4;
|
||||||
|
const STTS_DROP = 5;
|
||||||
|
const STTS_CLIENT_PAY = 6;
|
||||||
|
const STTS_VENDOR_PAYED = 8;
|
||||||
|
const STTS_CLOSE = 10;
|
||||||
|
const STTS_CANCEL = 11;
|
||||||
|
|
||||||
|
const IS_FIX_PRICE_NO = 0;
|
||||||
|
const IS_FIX_PRICE_YES = 1;
|
||||||
|
|
||||||
|
const CANCEL_TYPE_IGNORE = 1;
|
||||||
|
const CANCEL_TYPE_CLIENT = 2;
|
||||||
|
const CANCEL_TYPE_VDR_NOT_READY = 3;
|
||||||
|
|
||||||
|
const IS_ACCIDENT_NO = 0;
|
||||||
|
const IS_ACCIDENT_YES = 1;
|
||||||
|
|
||||||
|
const CHK_STTS_WAITING = 0;
|
||||||
|
const CHK_STTS_HAS_PICKUP = 1;
|
||||||
|
const CHK_STTS_HAS_DROP = 3;
|
||||||
|
|
||||||
|
const IS_PAID_NO = 0;
|
||||||
|
const IS_PAID_YES = 1;
|
||||||
|
|
||||||
|
const IS_ACTIVE_NO = 0;
|
||||||
|
const IS_ACTIVE_YES = 1;
|
||||||
|
|
||||||
|
const CRT_TYPE_ORDER_CLIENT = 1; // normal_via_client;
|
||||||
|
const CRT_TYPE_ORDER_ADMIN = 2; // normal_via_admin;
|
||||||
|
const CRT_TYPE_ORDER_ADMIN_SPECIAL = 3; // special_via_admin;
|
||||||
|
|
||||||
|
// merge per trx
|
||||||
|
const STTS_MERGE_NO = 0;
|
||||||
|
const STTS_MERGE_TO = 1;
|
||||||
|
const STTS_MERGE_RESULT = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* column merge disini untuk merge per trx
|
||||||
|
*/
|
||||||
|
|
||||||
|
const defaultSelectedOrders = "
|
||||||
|
ord.*
|
||||||
|
,ord.id as ord_id,ord.code as ord_code
|
||||||
|
,ord_pck.pck_name,ord_pck.stts_pck,ord_pck.pck_addr
|
||||||
|
,ord_drop.drop_name,ord_drop.stts_drop,ord_drop.drop_addr
|
||||||
|
,ord_c.c_name
|
||||||
|
,ord_vdr.vdr_name
|
||||||
|
,ord_drv.drv_name
|
||||||
|
,ord_vhc.vhc_id,ord_vhc.vhc_name,ord_vhc.vhc_nopol1,ord_vhc.vhc_nopol2,ord_vhc.vhc_nopol3
|
||||||
|
,ord_rate.id as ord_rate_id
|
||||||
|
";
|
||||||
|
const defaultWhereOrders = "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
";
|
||||||
|
|
||||||
|
const defaultSelectedOrdersDetail = "
|
||||||
|
ord.*
|
||||||
|
,ord.id as ord_id,ord.code as ord_code
|
||||||
|
,ord_pck.id as ord_pck_id,ord_pck.pck_id as ord_pck_zone_id,ord_pck.pck_name,ord_pck.pck_addr,ord_pck.set_pck_at,ord_pck.pck_at,ord_pck.pck_enter_at,ord_pck.pck_leave_at
|
||||||
|
,ord_drop.id as ord_drop_id,ord_drop.drop_id as ord_drop_zone_id,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.drop_at,ord_drop.drop_enter_at,ord_drop.drop_leave_at
|
||||||
|
,ord_c.id as ord_client_id,ord_c.c_id,ord_c.c_name,ord_c.c_phone_code,ord_c.c_phone_val,ord_c.c_mail,ord_c.prefer_truck_type
|
||||||
|
,ord_vdr.id as ord_vdr_id,ord_vdr.vdr_id,ord_vdr.vdr_name,ord_vdr.vdr_phone_code,ord_vdr.vdr_phone_val,ord_vdr.vdr_mail,ord_vdr.vdr_addr,ord_vdr.status as vdr_status,ord_vdr.respond_at as vdr_respond_at,ord_vdr.crt as vdr_crt,ord_vdr.is_pkp as is_vdr_pkp
|
||||||
|
,ord_drv.drv_id,ord_drv.drv_name,ord_drv.drv_phone_code,ord_drv.drv_phone_val,ord_drv.drv_name2,ord_drv.drv_phone2_val,ord_drv.drv_mail,ord_drv.drv_addr
|
||||||
|
,ord_vhc.vhc_id,ord_vhc.vhc_name,ord_vhc.vhc_nopol1,ord_vhc.vhc_nopol2,ord_vhc.vhc_nopol3
|
||||||
|
,ord_rate.id as ord_rate_id,ord_rate.buy_ftl
|
||||||
|
";
|
||||||
|
const defaultWhereOrdersDetail = "
|
||||||
|
WHERE ord.dlt is null
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listOrders($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = "";
|
||||||
|
$join_join = "";
|
||||||
|
$where_where = "";
|
||||||
|
$group_by = "";
|
||||||
|
$order_by = "";
|
||||||
|
|
||||||
|
if (isset($filter["client_id"])) {
|
||||||
|
$where_where .= " AND ord_c.c_id = ? ";
|
||||||
|
array_push($params, $filter["client_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["client_pt_id"])) {
|
||||||
|
$where_where .= " AND ord_c.c_pt_id = ? ";
|
||||||
|
array_push($params, $filter["client_pt_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["vendor_id"])) {
|
||||||
|
$where_where .= " AND ord_vdr.vdr_id = ? ";
|
||||||
|
$where_where .= " AND ord_vdr.status = " . OrdersVendors::STTS_ACC;
|
||||||
|
array_push($params, $filter["vendor_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_stts_checker"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck.chk_id as pck_chk_id,ord_pck.chk_at as pck_chk_at,ord_pck.chk_stts as pck_chk_stts";
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_drop.chk_id as drop_chk_id,ord_drop.chk_at as drop_chk_at,ord_drop.chk_stts as drop_chk_stts";
|
||||||
|
}
|
||||||
|
if (isset($filter["chk_id"])) {
|
||||||
|
if ($filter["chk_type"] == Users::CHK_TYPE_PICKUP) {
|
||||||
|
$where_where .= " AND (ord_pck.chk_id = ? OR ord_pck.chk_id = 0) ";
|
||||||
|
array_push($params, $filter["chk_id"]);
|
||||||
|
} elseif ($filter["chk_type"] == Users::CHK_TYPE_DROP) {
|
||||||
|
$where_where .= " AND (ord_drop.chk_id = ? OR ord_drop.chk_id = 0) ";
|
||||||
|
array_push($params, $filter["chk_id"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($filter["order_open"])) {
|
||||||
|
$where_where .= " AND ord.status IN (?,?,?,?,?,?,?,?) ";
|
||||||
|
array_push(
|
||||||
|
$params,
|
||||||
|
Orders::STTS_WAIT,
|
||||||
|
Orders::STTS_WAIT,
|
||||||
|
Orders::STTS_CONFIRM,
|
||||||
|
Orders::STTS_HAVE_GET_VHC,
|
||||||
|
Orders::STTS_GO,
|
||||||
|
Orders::STTS_PCK,
|
||||||
|
Orders::STTS_ARV,
|
||||||
|
Orders::STTS_DROP,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["ready_checker"])) {
|
||||||
|
$where_where .= " AND ord.status IN (?,?,?,?,?,?,?,?) ";
|
||||||
|
array_push(
|
||||||
|
$params,
|
||||||
|
Orders::STTS_HAVE_GET_VHC,
|
||||||
|
Orders::STTS_GO,
|
||||||
|
Orders::STTS_PCK,
|
||||||
|
Orders::STTS_ARV,
|
||||||
|
Orders::STTS_DROP,
|
||||||
|
Orders::STTS_CLIENT_PAY,
|
||||||
|
Orders::STTS_VENDOR_PAYED,
|
||||||
|
Orders::STTS_CLOSE,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["client_id_active_orders"])) {
|
||||||
|
$where_where .= " AND ord_c.c_id = ? AND ord.status IN (?,?,?,?,?) ";
|
||||||
|
array_push(
|
||||||
|
$params,
|
||||||
|
$filter["client_id_active_orders"],
|
||||||
|
Orders::STTS_HAVE_GET_VHC,
|
||||||
|
Orders::STTS_GO,
|
||||||
|
Orders::STTS_PCK,
|
||||||
|
Orders::STTS_ARV,
|
||||||
|
Orders::STTS_DROP,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isset($filter["is_accident"])) {
|
||||||
|
$where_where .= " AND ord.is_accident = ? ";
|
||||||
|
array_push($params, $filter["is_accident"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["couple_pck_drop"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck_drop.id as ord_pck_drop_id,ord_pck_drop.stts as stts_delivery,ord_pck_drop.is_aprv_pck,ord_pck_drop.aprv_pck_at";
|
||||||
|
$join_join .= " INNER JOIN t_orders_pck_drop as ord_pck_drop ON ord.id = ord_pck_drop.ord_id";
|
||||||
|
$join_join .= " INNER JOIN t_orders_pickups as ord_pck ON ord_pck_drop.pck_id = ord_pck.id";
|
||||||
|
$join_join .= " INNER JOIN t_orders_drops as ord_drop ON ord_pck_drop.drop_id = ord_drop.id";
|
||||||
|
|
||||||
|
if (isset($filter["ord_pck_drop_id"])) {
|
||||||
|
$where_where .= " AND ord_pck_drop.id = ?";
|
||||||
|
array_push($params, $filter["ord_pck_drop_id"]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$join_join .= " INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id";
|
||||||
|
$join_join .= " INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["join_pockets"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pocket.pocket_id,ord_pocket.pocket_type,ord_pocket.id as ord_pocket_id,ord_pocket.pocket_name";
|
||||||
|
$join_join .= " INNER JOIN t_orders_pockets as ord_pocket ON ord.id = ord_pocket.ord_id";
|
||||||
|
}
|
||||||
|
|
||||||
|
// $group_by .= ' GROUP BY ord.group_code';
|
||||||
|
if (isset($filter["group_by"])) {
|
||||||
|
$group_by .= " GROUP BY " . $filter["group_by"];
|
||||||
|
}
|
||||||
|
if (isset($filter["order_by"])) {
|
||||||
|
$order_by .= " ORDER BY " . $filter["order_by"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
" .
|
||||||
|
Orders::defaultSelectedOrders .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$select_order .
|
||||||
|
"
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
LEFT JOIN t_orders_rates as ord_rate ON ord.id = ord_rate.ord_id
|
||||||
|
LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = " .
|
||||||
|
OrdersVendors::STTS_ACC .
|
||||||
|
" GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||||
|
LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||||
|
LEFT JOIN t_orders_drivers as ord_drv ON ord.id = ord_drv.ord_id
|
||||||
|
LEFT JOIN t_orders_vehicles as ord_vhc ON ord.id = ord_vhc.ord_id
|
||||||
|
" .
|
||||||
|
$join_join .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
Orders::defaultWhereOrders .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$where_where .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$group_by .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$order_by .
|
||||||
|
"
|
||||||
|
;",
|
||||||
|
$params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showOrder($filter)
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select_order = "";
|
||||||
|
$where_order = "";
|
||||||
|
$join_order = "";
|
||||||
|
$group_by = "";
|
||||||
|
|
||||||
|
if (isset($filter["id"])) {
|
||||||
|
$where_order .= " AND ord.id = ? ";
|
||||||
|
array_push($params, $filter["id"]);
|
||||||
|
} elseif (isset($filter["code"])) {
|
||||||
|
$where_order .= " AND ord.code = ? ";
|
||||||
|
array_push($params, $filter["code"]);
|
||||||
|
} elseif (isset($filter["codes"])) {
|
||||||
|
$binds_codes = "";
|
||||||
|
foreach ($filter["codes"] as $k => $v) {
|
||||||
|
$binds_codes .= "?,";
|
||||||
|
$params[] = $v;
|
||||||
|
}
|
||||||
|
if (substr($binds_codes, -1) === ",") {
|
||||||
|
$binds_codes = substr($binds_codes, 0, -1);
|
||||||
|
}
|
||||||
|
$where_order .= " AND ord.code IN ($binds_codes)";
|
||||||
|
} elseif (isset($filter["group_merge_code"])) {
|
||||||
|
$where_order .= " AND ord.group_merge_code IN (?)";
|
||||||
|
$params[] = $filter["group_merge_code"];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["center_pck"])) {
|
||||||
|
$select_order .= ",ST_AsText(ST_Centroid(pck_points)) as pck_center";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_prefer_type_truck"])) {
|
||||||
|
$select_order .= ",tt.name as prefer_truck_type_name";
|
||||||
|
$join_order .= " LEFT JOIN t_vehicles_types as tt ON ord_c.prefer_truck_type = tt.id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_additional_vehicles_info"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_vhc.vhc_type_id, tt2.name as vhc_type_name, ord_vhc.vhc_brand_id, tb.name as vhc_brand_name";
|
||||||
|
$join_order .= " LEFT JOIN t_vehicles_types as tt2 ON ord_vhc.vhc_type_id = tt2.id";
|
||||||
|
$join_order .= " LEFT JOIN t_vehicles_brands as tb ON ord_vhc.vhc_brand_id = tb.id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_zone_data"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_pck.pck_hex_color,ord_pck.pck_shape,ord_pck.pck_radius,ord_pck.pck_bounds,ord_pck.pck_latlngs,ST_AsText(ST_Centroid(pck_points)) as pck_center";
|
||||||
|
$select_order .=
|
||||||
|
",ord_drop.drop_hex_color,ord_drop.drop_shape,ord_drop.drop_radius,ord_drop.drop_bounds,ord_drop.drop_latlngs,ST_AsText(ST_Centroid(drop_points)) as drop_center";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_zone_zonasi"])) {
|
||||||
|
$select_order .=
|
||||||
|
",(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_pck.pck_prid LIMIT 1) as pck_prid_name ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) as pck_ktid_name";
|
||||||
|
$select_order .=
|
||||||
|
",(SELECT nmProvinsiKel FROM t_region WHERE kodeProv = ord_drop.drop_prid LIMIT 1) as drop_prid_name ,(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) as drop_ktid_name";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_pic_zone"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_pck.pic_name as pck_pic_name,ord_pck.pic_phone_code as pck_pic_phone_code,ord_pck.pic_phone_val as pck_pic_phone_val,ord_pck.pic_mail as pck_pic_mail";
|
||||||
|
$select_order .=
|
||||||
|
",ord_drop.pic_name as drop_pic_name,ord_drop.pic_phone_code as drop_pic_phone_code,ord_drop.pic_phone_val as drop_pic_phone_val,ord_drop.pic_mail as drop_pic_mail";
|
||||||
|
}
|
||||||
|
if (isset($filter["get_client_pt"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_c.c_pt_id,ord_c.c_pt_name,ord_c.c_pt_phone_code,ord_c.c_pt_phone_val,ord_c.c_pt_mail,ord_c.c_pt_addr";
|
||||||
|
$select_order .=
|
||||||
|
",ord_c.c_pt_pic_name,ord_c.c_pt_pic_phone_code,ord_c.c_pt_pic_phone_val,ord_c.c_pt_pic_mail,ord_c.c_pt_pic_addr";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_exp_vendor"])) {
|
||||||
|
$select_order .= ",ord_vdr.is_exp as vdr_is_exp,ord_vdr.exp_at as vdr_exp_at";
|
||||||
|
}
|
||||||
|
if (isset($filter["vdr_id"])) {
|
||||||
|
$select_order .= ",ord_vdr.find_vhcs";
|
||||||
|
$where_order .= " AND ord_vdr.vdr_id = ?";
|
||||||
|
array_push($params, $filter["vdr_id"]);
|
||||||
|
$join_order .= " LEFT JOIN t_orders_vendors as ord_vdr ON ord.id = ord_vdr.ord_id";
|
||||||
|
} else {
|
||||||
|
$join_order .=
|
||||||
|
"
|
||||||
|
LEFT JOIN ( SELECT MIN(respond_at) as respond_at,ord_id,vdr_id FROM t_orders_vendors WHERE status = " .
|
||||||
|
OrdersVendors::STTS_ACC .
|
||||||
|
" GROUP BY ord_id ) AS ord_vdr1 ON (ord.id = ord_vdr1.ord_id)
|
||||||
|
LEFT JOIN t_orders_vendors as ord_vdr ON ( ord_vdr.respond_at = ord_vdr1.respond_at)
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_drv_bank"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_drv.drv_bank_id,ord_drv.drv_bank_code,ord_drv.drv_bank_name,ord_drv.drv_bank_short_name,ord_drv.drv_bank_branch_name,ord_drv.drv_bank_acc_number,ord_drv.drv_bank_acc_name";
|
||||||
|
}
|
||||||
|
if (isset($filter["get_vdr_bank"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_vdr.vdr_bank_id,ord_vdr.vdr_bank_code,ord_vdr.vdr_bank_name,ord_vdr.vdr_bank_short_name,ord_vdr.vdr_bank_acc_number,ord_vdr.vdr_bank_acc_name";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_stts_checker"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck.chk_id as pck_chk_id,ord_pck.chk_at as pck_chk_at,ord_pck.chk_stts as pck_chk_stts";
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_drop.chk_id as drop_chk_id,ord_drop.chk_at as drop_chk_at,ord_drop.chk_stts as drop_chk_stts";
|
||||||
|
}
|
||||||
|
if (isset($filter["chk_id"])) {
|
||||||
|
if ($filter["chk_type"] == Users::CHK_TYPE_PICKUP) {
|
||||||
|
$where_order .= " AND (ord_pck.chk_id = ? OR ord_pck.chk_id = 0) ";
|
||||||
|
array_push($params, $filter["chk_id"]);
|
||||||
|
} elseif ($filter["chk_type"] == Users::CHK_TYPE_DROP) {
|
||||||
|
$where_order .= " AND (ord_drop.chk_id = ? OR ord_drop.chk_id = 0) ";
|
||||||
|
array_push($params, $filter["chk_id"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($filter["get_checker_user"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck.chk_name as pck_chk_name,ord_pck.chk_mail as pck_chk_mail,ord_pck.chk_phone_val as pck_chk_phone_val";
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_drop.chk_name as drop_chk_name,ord_drop.chk_mail as drop_chk_mail,ord_drop.chk_phone_val as drop_chk_phone_val";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_bid_info"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_vdr.is_mailing_bid,ord_vdr.is_mailing_bid_at,ord_vdr.is_want,ord_vdr.is_want_at";
|
||||||
|
}
|
||||||
|
|
||||||
|
// get img pickup and drop
|
||||||
|
if (isset($filter["get_checker_data"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck.chk_seal_number as ord_pck_seal_number,ord_pck.chk_seal_img as ord_pck_seal_img,ord_pck.chk_drv_armd_img as ord_pck_drv_armd_img,ord_pck.chk_nopol_img as ord_pck_nopol_img,ord_pck.chk_docs_client_img as ord_pck_docs_client_img,ord_pck.chk_seal_install_img as ord_pck_seal_install_img,ord_pck.chk_goods_img as ord_pck_goods_img";
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_drop.chk_arrived_img as ord_drop_arrived_img,ord_drop.chk_handover_img as ord_drop_handover_img,ord_drop.chk_do_ttd_img as ord_drop_do_ttd_img,ord_drop.chk_spk_img as ord_drop_spk_img";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_accidents"])) {
|
||||||
|
$select_order .=
|
||||||
|
",ord_acdnt.id as ord_acdnt_id,ord_acdnt.accident_location as ord_acdnt_location,ord_acdnt.accident_story as ord_acdnt_story,ord_acdnt.accident_imgs as ord_acdnt_imgs";
|
||||||
|
$select_order .=
|
||||||
|
",ord_acdnt.new_nopol1 as ord_acdnt_new_nopol1,ord_acdnt.new_nopol2 as ord_acdnt_new_nopol2,ord_acdnt.new_nopol3 as ord_acdnt_new_nopol3,ord_acdnt.new_vhc_type_id as ord_acdnt_new_vhc_type_id";
|
||||||
|
$select_order .= ",tt3.name as ord_acdnt_new_vhc_type_name";
|
||||||
|
$select_order .=
|
||||||
|
",ord_acdnt.new_drv_name as ord_acdnt_new_drv_name,ord_acdnt.new_drv_phone_code as ord_acdnt_new_drv_phone_code,ord_acdnt.new_drv_phone_val as ord_acdnt_new_drv_phone_val";
|
||||||
|
$select_order .= ",ord_acdnt.crt as ord_acdnt_crt_at,ord_acdnt.updt as ord_acdnt_updt_at";
|
||||||
|
$join_order .= " LEFT JOIN t_orders_accidents as ord_acdnt ON ord.id = ord_acdnt.ord_id";
|
||||||
|
$join_order .= " LEFT JOIN t_vehicles_types as tt3 ON ord_vhc.vhc_type_id = tt3.id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["select_region_pck_drop"])) {
|
||||||
|
$select_order .=
|
||||||
|
",(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) pck_ktname, (SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) drop_ktname";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["couple_pck_drop"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pck_drop.id as ord_pck_drop_id,ord_pck_drop.stts as stts_delivery,ord_pck_drop.is_aprv_pck,ord_pck_drop.aprv_pck_at";
|
||||||
|
$join_order .= " INNER JOIN t_orders_pck_drop as ord_pck_drop ON ord.id = ord_pck_drop.ord_id";
|
||||||
|
$join_order .= " INNER JOIN t_orders_pickups as ord_pck ON ord_pck_drop.pck_id = ord_pck.id";
|
||||||
|
$join_order .= " INNER JOIN t_orders_drops as ord_drop ON ord_pck_drop.drop_id = ord_drop.id";
|
||||||
|
|
||||||
|
if (isset($filter["ord_pck_drop_id"])) {
|
||||||
|
$where_order .= " AND ord_pck_drop.id = ?";
|
||||||
|
array_push($params, $filter["ord_pck_drop_id"]);
|
||||||
|
}
|
||||||
|
if (isset($filter["get_user_aprv_pck"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,(SELECT first_name FROM t_users WHERE id = ord_pck_drop.aprv_pck_by LIMIT 1) as aprv_pck_by_name";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$join_order .= " INNER JOIN t_orders_pickups as ord_pck ON ord.id = ord_pck.ord_id";
|
||||||
|
$join_order .= " INNER JOIN t_orders_drops as ord_drop ON ord.id = ord_drop.ord_id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["join_pockets"])) {
|
||||||
|
$select_order .=
|
||||||
|
" ,ord_pocket.pocket_id,ord_pocket.pocket_type,ord_pocket.id as ord_pocket_id,ord_pocket.pocket_name";
|
||||||
|
$join_order .= " INNER JOIN t_orders_pockets as ord_pocket ON ord.id = ord_pocket.ord_id";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["group_by"])) {
|
||||||
|
$group_by .= " GROUP BY " . $filter["group_by"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($filter["limit"])) {
|
||||||
|
$filter["limit"] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
" .
|
||||||
|
Orders::defaultSelectedOrdersDetail .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$select_order .
|
||||||
|
"
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
LEFT JOIN t_orders_rates as ord_rate ON ord.id = ord_rate.ord_id
|
||||||
|
LEFT JOIN t_orders_drivers as ord_drv ON ord.id = ord_drv.ord_id
|
||||||
|
LEFT JOIN t_orders_vehicles as ord_vhc ON ord.id = ord_vhc.ord_id
|
||||||
|
" .
|
||||||
|
$join_order .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
Orders::defaultWhereOrdersDetail .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$where_order .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$group_by .
|
||||||
|
"
|
||||||
|
LIMIT " .
|
||||||
|
$filter["limit"] .
|
||||||
|
";",
|
||||||
|
$params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrders()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrdersClientActive($client_id)
|
||||||
|
{
|
||||||
|
$stts =
|
||||||
|
Orders::STTS_WAIT .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_CONFIRM .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_HAVE_GET_VHC .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_PCK .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_GO .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_ARV .
|
||||||
|
"," .
|
||||||
|
Orders::STTS_DROP;
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.*,ord_c.*
|
||||||
|
,ord_c.pay_at as client_pay_at,ord_c.is_pay as client_is_pay
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
WHERE ord.dlt is null AND ord.status IN (?) AND ord_c.c_id = ?;",
|
||||||
|
[$stts, $client_id],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrdersByClient($client_id, $limit = 1000)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.*,ord_c.*
|
||||||
|
,ord_c.pay_at as client_pay_at,ord_c.is_pay as client_is_pay
|
||||||
|
FROM t_orders as ord
|
||||||
|
INNER JOIN t_orders_clients as ord_c ON ord.id = ord_c.ord_id
|
||||||
|
WHERE ord.dlt is null AND ord_c.c_id = ?
|
||||||
|
LIMIT ?;",
|
||||||
|
[$client_id, $limit],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrderById($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders WHERE dlt is null AND id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrderByCode($ordcode)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders WHERE dlt is null AND code = ? LIMIT 1;", [$ordcode]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// special case utk generate order code tanpa where dlt is null
|
||||||
|
public static function getOrderLikeCode($ordcode)
|
||||||
|
{
|
||||||
|
// return DB::select("SELECT COUNT(id) as total FROM t_orders WHERE dlt is null AND code LIKE ? LIMIT 1;", [$ordcode.'%']);
|
||||||
|
return DB::select("SELECT COUNT(id) as total FROM t_orders WHERE code LIKE ? LIMIT 1;", [
|
||||||
|
$ordcode . "%",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPoints($filter)
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = "";
|
||||||
|
$join = "";
|
||||||
|
$where = "";
|
||||||
|
$limit = "";
|
||||||
|
|
||||||
|
if (isset($filter["id"])) {
|
||||||
|
$where .= " AND ord.id = ? ";
|
||||||
|
array_push($params, $filter["id"]);
|
||||||
|
} elseif (isset($filter["code"])) {
|
||||||
|
$where .= " AND ord.code = ? ";
|
||||||
|
array_push($params, $filter["code"]);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["point_id"])) {
|
||||||
|
$where .= " AND topd.id = ? ";
|
||||||
|
array_push($params, $filter["point_id"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["center_pck"])) {
|
||||||
|
$select .= ",ST_AsText(ST_Centroid(pck_points)) as pck_center";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_zone_data"])) {
|
||||||
|
$select .=
|
||||||
|
",ord_pck.pck_hex_color,ord_pck.pck_shape,ord_pck.pck_radius,ord_pck.pck_bounds,ord_pck.pck_latlngs,ST_AsText(ST_Centroid(pck_points)) as pck_center";
|
||||||
|
$select .=
|
||||||
|
",ord_drop.drop_hex_color,ord_drop.drop_shape,ord_drop.drop_radius,ord_drop.drop_bounds,ord_drop.drop_latlngs,ST_AsText(ST_Centroid(drop_points)) as drop_center";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["get_pic_zone"])) {
|
||||||
|
$select .=
|
||||||
|
",ord_pck.pic_name as pck_pic_name,ord_pck.pic_phone_code as pck_pic_phone_code,ord_pck.pic_phone_val as pck_pic_phone_val,ord_pck.pic_mail as pck_pic_mail";
|
||||||
|
$select .=
|
||||||
|
",ord_drop.pic_name as drop_pic_name,ord_drop.pic_phone_code as drop_pic_phone_code,ord_drop.pic_phone_val as drop_pic_phone_val,ord_drop.pic_mail as drop_pic_mail";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["select_region_pck_drop"])) {
|
||||||
|
$select .=
|
||||||
|
",(SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_pck.pck_ktid LIMIT 1) pck_ktname, (SELECT nmKotamadyaKel FROM t_region WHERE kodeKab = ord_drop.drop_ktid LIMIT 1) drop_ktname";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter["limit"])) {
|
||||||
|
$limit .= " LIMIT " . $filter["limit"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- total_pck must be equal to total_drop
|
||||||
|
return DB::select(
|
||||||
|
"SELECT
|
||||||
|
ord.*
|
||||||
|
,ord.id as ord_id,ord.code as ord_code
|
||||||
|
,ord_pck.id as ord_pck_id,ord_pck.pck_id as ord_pck_zone_id,ord_pck.pck_name,ord_pck.pck_addr,ord_pck.set_pck_at,ord_pck.pck_at,ord_pck.pck_enter_at,ord_pck.pck_leave_at
|
||||||
|
,ord_drop.id as ord_drop_id,ord_drop.drop_id as ord_drop_zone_id,ord_drop.drop_name,ord_drop.drop_addr,ord_drop.drop_at,ord_drop.drop_enter_at,ord_drop.drop_leave_at
|
||||||
|
,topd.id as point_id
|
||||||
|
" .
|
||||||
|
$select .
|
||||||
|
"
|
||||||
|
FROM t_orders as ord
|
||||||
|
LEFT JOIN t_orders_pck_drop topd ON
|
||||||
|
topd.ord_id = ord.id
|
||||||
|
LEFT JOIN t_orders_pickups as ord_pck ON
|
||||||
|
topd.pck_id = ord_pck.id
|
||||||
|
LEFT JOIN t_orders_drops as ord_drop ON
|
||||||
|
topd.drop_id = ord_drop.id
|
||||||
|
" .
|
||||||
|
$join .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
Orders::defaultWhereOrdersDetail .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$where .
|
||||||
|
"
|
||||||
|
" .
|
||||||
|
$limit .
|
||||||
|
"
|
||||||
|
",
|
||||||
|
$params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addOrder($data)
|
||||||
|
{
|
||||||
|
$ordid = DB::table("t_orders")->insertGetId($data);
|
||||||
|
return $ordid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateOrder($ordid, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders")
|
||||||
|
->where("id", $ordid)
|
||||||
|
->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteOrder($ordid)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders")
|
||||||
|
->where("id", $ordid)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
397
app/Models/OrdersAItems.php
Executable file
397
app/Models/OrdersAItems.php
Executable file
@ -0,0 +1,397 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersAItems extends Model
|
||||||
|
{
|
||||||
|
// t_orders_a_items fungsinya untuk nalangin pembayaran
|
||||||
|
|
||||||
|
const FLOW_TYPE_PAYMENT = 1;
|
||||||
|
const FLOW_TYPE_BILLING = 2;
|
||||||
|
const FLOW_TYPE_HYBRID = 3;
|
||||||
|
|
||||||
|
const TYPE_CASH_OUT = 1;
|
||||||
|
const TYPE_CASH_IN = 2;
|
||||||
|
const TYPE_CASH_HYBRID = 3;
|
||||||
|
|
||||||
|
const A_TYPE_PRIMARY = 1;
|
||||||
|
const A_TYPE_SECONDARY = 2;
|
||||||
|
|
||||||
|
const AMT_TYPE_FLAT = 1;
|
||||||
|
const AMT_TYPE_PERCENT = 2;
|
||||||
|
|
||||||
|
// 1=>refer ddln_pay_at, 2=>refer to order finish(pengantaran selesai)
|
||||||
|
const DDLN_PAY_TYPE_TIME = 1;
|
||||||
|
const DDLN_PAY_TYPE_ORD_FINISH = 2;
|
||||||
|
|
||||||
|
const IS_PAID_NO = 0;
|
||||||
|
const IS_PAID_YES = 1;
|
||||||
|
|
||||||
|
const IS_HIDDEN_NO = 0;
|
||||||
|
const IS_HIDDEN_YES = 1;
|
||||||
|
|
||||||
|
// tax yang berlaku utk 1 row saja
|
||||||
|
const IS_TAX_NO = 0;
|
||||||
|
const IS_TAX_YES = 1;
|
||||||
|
|
||||||
|
const IS_DISC_NO = 0;
|
||||||
|
const IS_DISC_YES = 1;
|
||||||
|
|
||||||
|
const IS_SUBTRACT_NO = 0;
|
||||||
|
const IS_SUBTRACT_YES = 1;
|
||||||
|
|
||||||
|
// 1=>transfer
|
||||||
|
const PAID_TYPE_TF = 1;
|
||||||
|
|
||||||
|
const INVC_TO_CLIENT_YES = 1;
|
||||||
|
const INVC_TO_CLIENT_NO = 2;
|
||||||
|
|
||||||
|
const CALC_TO_VDR_YES = 1;
|
||||||
|
const CALC_TO_VDR_NO = 2;
|
||||||
|
|
||||||
|
const ONLY_CLIENT_YES = 1;
|
||||||
|
const ONLY_CLIENT_NO = 2;
|
||||||
|
|
||||||
|
const ONLY_VDR_YES = 1;
|
||||||
|
const ONLY_VDR_NO = 2;
|
||||||
|
|
||||||
|
const IS_ADM_PRICE_NO = 0;
|
||||||
|
const IS_ADM_PRICE_YES = 1;
|
||||||
|
|
||||||
|
const IS_APRV_NO = 0;
|
||||||
|
const IS_APRV_YES = 1;
|
||||||
|
|
||||||
|
const IS_ACTIVE_NO = 0;
|
||||||
|
const IS_ACTIVE_YES = 1;
|
||||||
|
|
||||||
|
// tax yang include dengan itemnya
|
||||||
|
const AMT_TAX_TYPE_WITHOUT = 0; // tanpa pajak
|
||||||
|
const AMT_TAX_TYPE_INCLUDE = 1; // termasuk pajak || pajak dibayarkan sendiri oleh (client/vendor)
|
||||||
|
const AMT_TAX_TYPE_EXCLUDE = 2; // belum termasuk pajak || pajak dibayarkan oleh bonceng
|
||||||
|
const PPN_PERCENT = 1.1;
|
||||||
|
const PPN_PERCENT_INCLUDE = 1.011;
|
||||||
|
const PPH_PERCENT = 2;
|
||||||
|
|
||||||
|
// merge satuan
|
||||||
|
const IS_MERGE_NO = 0;
|
||||||
|
const IS_MERGE_YES = 1;
|
||||||
|
|
||||||
|
// merge per trx
|
||||||
|
const STTS_MERGE_NO = 0;
|
||||||
|
const STTS_MERGE_TO = 1;
|
||||||
|
const STTS_MERGE_RESULT = 2;
|
||||||
|
|
||||||
|
// 0=>system, 1=>admin, 2=>finance
|
||||||
|
const CRT_TYPE_SYSTEM = 0;
|
||||||
|
const CRT_TYPE_ADMIN = 1;
|
||||||
|
const CRT_TYPE_FINANCE = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* termin_at itu deadline pembayaran
|
||||||
|
* column merge disini untuk merge satuan:
|
||||||
|
* is_merge_to, merge_to_a_id, merge_to_ord_id, merge_to_ord_code, merge_to_at, merge_to_by
|
||||||
|
* is_merge_from, merge_from_a_id, merge_from_ord_id, merge_from_ord_code, merge_from_at, merge_from_by
|
||||||
|
* column merge disini untuk merge per trx:
|
||||||
|
* stts_merge, merge_to_code, group_merge_code, merge_at
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function listAItems($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if (isset($filter['c_termin_id'])) {
|
||||||
|
$where .= ' AND ord_a_item.c_termin_id = ?';
|
||||||
|
$params[] = $filter['c_termin_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_hidden'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_hidden = ?';
|
||||||
|
$params[] = $filter['is_hidden'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_tax'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_tax = ?';
|
||||||
|
$params[] = $filter['is_tax'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_ppn'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_ppn = ?';
|
||||||
|
$params[] = $filter['is_ppn'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_pph'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_pph = ?';
|
||||||
|
$params[] = $filter['is_pph'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_disc'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_disc = ?';
|
||||||
|
$params[] = $filter['is_disc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.*
|
||||||
|
$select
|
||||||
|
FROM
|
||||||
|
t_orders_a_items as ord_a_item
|
||||||
|
WHERE dlt is null
|
||||||
|
$where
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_a_items;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showAItem($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$join = '';
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$group_by = '';
|
||||||
|
$limit = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_a_item_id'])) {
|
||||||
|
$where .= ' AND ord_a_item.id = ?';
|
||||||
|
$params[] = $filter['ord_a_item_id'];
|
||||||
|
} else if (isset($filter['group_merge_code'])) {
|
||||||
|
$where .= ' AND ord_a_item.group_merge_code IN (?)';
|
||||||
|
$params[] = $filter['group_merge_code'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where .= ' AND ord_a_item.ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['exclude_ord_a_item_id'])) {
|
||||||
|
$where .= ' AND ord_a_item.id != ?';
|
||||||
|
$params[] = $filter['exclude_ord_a_item_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['is_adm_price'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_adm_price = ?';
|
||||||
|
$params[] = $filter['is_adm_price'];
|
||||||
|
}
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
if (isset($filter['a_item_type'])) {
|
||||||
|
$where .= ' AND ord_a_item.a_item_type = ?';
|
||||||
|
$params[] = $filter['a_item_type'];
|
||||||
|
}
|
||||||
|
if (isset($filter['v_termin_id_not_zero'])) {
|
||||||
|
$where .= ' AND ord_a_item.v_termin_id != 0';
|
||||||
|
}
|
||||||
|
if (isset($filter['c_termin_id_not_zero'])) {
|
||||||
|
$where .= ' AND ord_a_item.c_termin_id != 0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_crt'])) {
|
||||||
|
$select .= ',ucrt.first_name as ucrt_name';
|
||||||
|
$join .= ' LEFT JOIN t_users as ucrt ON ord_a_item.crt_by = ucrt.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_rjct'])) {
|
||||||
|
$select .= ',urjct.first_name as urjct_name,urjct_bill.first_name as urjct_bill_name';
|
||||||
|
$join .= ' LEFT JOIN t_users as urjct ON ord_a_item.rjct_by = urjct.id';
|
||||||
|
$join .= ' LEFT JOIN t_users as urjct_bill ON ord_a_item.rjct_bill_by = urjct_bill.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['prev_main_item_id'])) {
|
||||||
|
$where .= ' AND ord_a_item.id < ?';
|
||||||
|
$params[] = $filter['prev_main_item_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['limit'])) {
|
||||||
|
$limit .= ' LIMIT ?';
|
||||||
|
$params[] = $filter['limit'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.*
|
||||||
|
$select
|
||||||
|
FROM
|
||||||
|
t_orders_a_items as ord_a_item
|
||||||
|
$join
|
||||||
|
WHERE ord_a_item.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$limit
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showAItemById($ord_a_item_id, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$join = '';
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if (isset($filter['is_adm_price'])) {
|
||||||
|
$where .= ' AND ord_a_item.is_adm_price = ?';
|
||||||
|
$params[] = $filter['is_adm_price'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_crt'])) {
|
||||||
|
$select .= ',ucrt.first_name as ucrt_name';
|
||||||
|
$join .= ' LEFT JOIN t_users as ucrt ON ord_a_item.crt_by = ucrt.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['get_user_rjct'])) {
|
||||||
|
$select .= ',urjct.first_name as urjct_name,urjct_bill.first_name as urjct_bill_name';
|
||||||
|
$join .= ' LEFT JOIN t_users as urjct ON ord_a_item.rjct_by = urjct.id';
|
||||||
|
$join .= ' LEFT JOIN t_users as urjct_bill ON ord_a_item.rjct_bill_by = urjct_bill.id';
|
||||||
|
}
|
||||||
|
|
||||||
|
$params[] = $ord_a_item_id;
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.*
|
||||||
|
$select
|
||||||
|
FROM
|
||||||
|
t_orders_a_items as ord_a_item
|
||||||
|
$join
|
||||||
|
WHERE ord_a_item.dlt is null
|
||||||
|
$where
|
||||||
|
AND ord_a_item.id = ?
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showAItemByIds($ids)
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if ($ids && count($ids) > 0) {
|
||||||
|
$binds_ids = "";
|
||||||
|
foreach ($ids as $k => $v) {
|
||||||
|
$binds_ids .= "?,";
|
||||||
|
$params[] = $v;
|
||||||
|
}
|
||||||
|
if (substr($binds_ids, -1) === ',') {
|
||||||
|
$binds_ids = substr($binds_ids, 0, -1);
|
||||||
|
}
|
||||||
|
$where .= " AND ord_a_item.id IN ($binds_ids)";
|
||||||
|
} else {
|
||||||
|
$where .= " AND ord_a_item.id = ?";
|
||||||
|
$params[] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.*
|
||||||
|
,ut.name as unit_type_name
|
||||||
|
$select
|
||||||
|
FROM t_orders_a_items as ord_a_item
|
||||||
|
LEFT JOIN t_unit_types as ut ON ord_a_item.unit_type = ut.id
|
||||||
|
WHERE ord_a_item.dlt is null
|
||||||
|
$where
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
// termin ids
|
||||||
|
public static function showAItemByVids($tids, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if ($tids && count($tids) > 0) {
|
||||||
|
$binds_ids = "";
|
||||||
|
foreach ($tids as $k => $v) {
|
||||||
|
$binds_ids .= "?,";
|
||||||
|
$params[] = $v;
|
||||||
|
}
|
||||||
|
if (substr($binds_ids, -1) === ',') {
|
||||||
|
$binds_ids = substr($binds_ids, 0, -1);
|
||||||
|
}
|
||||||
|
if (isset($filter['c_termin_id'])) {
|
||||||
|
$where .= " AND ord_a_item.c_termin_id IN ($binds_ids)";
|
||||||
|
} else {
|
||||||
|
$where .= " AND ord_a_item.v_termin_id IN ($binds_ids)";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isset($filter['c_termin_id'])) {
|
||||||
|
$where .= " AND ord_a_item.c_termin_id = ?";
|
||||||
|
} else {
|
||||||
|
$where .= " AND ord_a_item.v_termin_id = ?";
|
||||||
|
}
|
||||||
|
$params[] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['a_item_type'])) {
|
||||||
|
$where .= " AND ord_a_item.a_item_type = ?";
|
||||||
|
$params[] = $filter['a_item_type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_a_item.id as ord_a_item_id
|
||||||
|
,ord_a_item.*
|
||||||
|
,ut.name as unit_type_name
|
||||||
|
$select
|
||||||
|
FROM t_orders_a_items as ord_a_item
|
||||||
|
LEFT JOIN t_unit_types as ut ON ord_a_item.unit_type = ut.id
|
||||||
|
WHERE ord_a_item.dlt is null
|
||||||
|
$where
|
||||||
|
;",
|
||||||
|
$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_a_items WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_a_items WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_a_items WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_a_items")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_a_items")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_a_items")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_a_items")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_a_items")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Models/OrdersAccidents.php
Executable file
50
app/Models/OrdersAccidents.php
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersAccidents extends Model
|
||||||
|
{
|
||||||
|
public static function getAccidents()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_accidents WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAccidentById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_accidents WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAccidentByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_accidents WHERE dlt is null AND ord_id = ? LIMIT 1;", [$ord_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addAccident($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_accidents")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateAccident($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_accidents")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateAccidentByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_accidents")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteAccident($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_accidents")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteAccidentByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_accidents")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
142
app/Models/OrdersCheckpoints.php
Executable file
142
app/Models/OrdersCheckpoints.php
Executable file
@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersCheckpoints extends Model
|
||||||
|
{
|
||||||
|
const defaultSelectedCheckpoints = "
|
||||||
|
point.*
|
||||||
|
,point.id as ord_checkpoint_id
|
||||||
|
,pck.name as pck_name,pck.fulladdress as pck_fulladdress
|
||||||
|
,drp.name as drop_name,drp.fulladdress as drop_fulladdress
|
||||||
|
";
|
||||||
|
|
||||||
|
const IS_UNPAID = 0;
|
||||||
|
const IS_PAID = 1;
|
||||||
|
const IS_TF_FAIL = 2;
|
||||||
|
|
||||||
|
const TF_METHOD_MANUAL = 1;
|
||||||
|
const TF_METHOD_DANA = 2;
|
||||||
|
|
||||||
|
public static function listCheckpoints($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['id'])) {
|
||||||
|
$where .= ' AND point.id = ?';
|
||||||
|
$params[] = $filter['id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['pocket_id'])) {
|
||||||
|
$where .= ' AND point.pocket_id = ?';
|
||||||
|
$params[] = $filter['pocket_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_pocket_id'])) {
|
||||||
|
$where .= ' AND point.ord_pocket_id = ?';
|
||||||
|
$params[] = $filter['ord_pocket_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['sort'])) {
|
||||||
|
$where .= ' AND point.pocket_sort = ?';
|
||||||
|
$params[] = $filter['sort'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where .= ' AND point.ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_code'])) {
|
||||||
|
$where .= ' AND point.ord_code = ?';
|
||||||
|
$params[] = $filter['ord_code'];
|
||||||
|
}
|
||||||
|
if (isset($filter['tf_method'])) {
|
||||||
|
$where .= ' AND point.tf_method = ?';
|
||||||
|
$params[] = $filter['tf_method'];
|
||||||
|
}
|
||||||
|
if (isset($filter['where_not_tf_at'])) {
|
||||||
|
$where .= ' AND point.tf_at != ?';
|
||||||
|
$params[] = $filter['where_not_tf_at'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['order_by'])) {
|
||||||
|
$order_by = 'ORDER BY ' . $filter['order_by'];
|
||||||
|
}
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by = 'GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
if (isset($filter['limit'])) {
|
||||||
|
$limit = 'LIMIT ' . $filter['limit'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. OrdersCheckpoints::defaultSelectedCheckpoints . "
|
||||||
|
$select
|
||||||
|
FROM t_orders_checkpoints as point
|
||||||
|
INNER JOIN t_zones as pck ON point.pck_id = pck.id
|
||||||
|
LEFT JOIN t_zones as drp ON point.drop_id = drp.id
|
||||||
|
WHERE point.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showCheckpointById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. OrdersCheckpoints::defaultSelectedCheckpoints . "
|
||||||
|
FROM t_orders_checkpoints as point
|
||||||
|
LEFT JOIN t_zones as pck ON point.pck_id = pck.id
|
||||||
|
LEFT JOIN t_zones as drp ON point.drop_id = drp.id
|
||||||
|
WHERE point.dlt is null AND point.id = ?
|
||||||
|
LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpoints()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_checkpoints WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpointById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_checkpoints WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCheckpointByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_checkpoints WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addCheckpoint($data)
|
||||||
|
{
|
||||||
|
$pid = DB::table("t_orders_checkpoints")->insertGetId($data);
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateCheckpoint($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_checkpoints")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_checkpoints")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCheckpoint($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_checkpoints")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCheckpointByPocketId($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_checkpoints")->where("pocket_id", $pocket_id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteCheckpointByOrdPocketId($ord_pocket_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_checkpoints")->where("ord_pocket_id", $ord_pocket_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
62
app/Models/OrdersClients.php
Executable file
62
app/Models/OrdersClients.php
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersClients extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_NON_PKP = 0;
|
||||||
|
const IS_PKP_YES = 1;
|
||||||
|
|
||||||
|
const IS_NOT_PAY = 1;
|
||||||
|
const IS_PAYED = 2;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_clients;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_clients WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_clients WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_clients WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_clients")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_clients")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_clients")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_clients")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_clients")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Models/OrdersDrivers.php
Executable file
60
app/Models/OrdersDrivers.php
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersDrivers extends Model
|
||||||
|
{
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCodeByStatus($code, $status)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers WHERE ord_code = ? AND status = ? LIMIT 1;", [$code, $status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_drivers")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
111
app/Models/OrdersDriversUploads.php
Executable file
111
app/Models/OrdersDriversUploads.php
Executable file
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersDriversUploads extends Model
|
||||||
|
{
|
||||||
|
const STTS_UP_OTW_PICKUP = 1;
|
||||||
|
const STTS_UP_ARRIVED_PICKUP = 2;
|
||||||
|
const STTS_UP_PROCESS_PICKUP = 3;
|
||||||
|
const STTS_UP_FINISH_PICKUP = 4;
|
||||||
|
const STTS_UP_TRAVEL_DOCUMENT = 5;
|
||||||
|
const STTS_UP_OTW_DROP = 6;
|
||||||
|
const STTS_UP_ARRIVED_DROP = 7;
|
||||||
|
const STTS_UP_PROCESS_DROP = 8;
|
||||||
|
const STTS_UP_FINISH_DROP = 9;
|
||||||
|
const STTS_UP_HANDOVER_DOCUMENT = 10;
|
||||||
|
const STTS_UP_ACCIDENT = 11;
|
||||||
|
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
public static function list($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$join = '';
|
||||||
|
$limit = '';
|
||||||
|
|
||||||
|
if (isset($filter['id'])) {
|
||||||
|
$where .= ' AND drv_up.id = ?';
|
||||||
|
$params[] = $filter['id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where .= ' AND drv_up.ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_code'])) {
|
||||||
|
$where .= ' AND drv_up.ord_code = ?';
|
||||||
|
$params[] = $filter['ord_code'];
|
||||||
|
}
|
||||||
|
if (isset($filter['did'])) {
|
||||||
|
$where .= ' AND drv_up.did = ?';
|
||||||
|
$params[] = $filter['did'];
|
||||||
|
}
|
||||||
|
if (isset($filter['pck_id'])) {
|
||||||
|
$where .= ' AND drv_up.pck_id = ?';
|
||||||
|
$params[] = $filter['pck_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['drop_id'])) {
|
||||||
|
$where .= ' AND drv_up.drop_id = ?';
|
||||||
|
$params[] = $filter['drop_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_pck_drop_id'])) {
|
||||||
|
$where .= ' AND drv_up.ord_pck_drop_id = ?';
|
||||||
|
$params[] = $filter['ord_pck_drop_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT drv_up.* $select FROM t_orders_drivers_uploads as drv_up $join WHERE drv_up.dlt is null $where $limit;";
|
||||||
|
return DB::select($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers_uploads;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers_uploads WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers_uploads WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drivers_uploads WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_drivers_uploads")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers_uploads")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers_uploads")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers_uploads")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drivers_uploads")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Models/OrdersDrops.php
Executable file
63
app/Models/OrdersDrops.php
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersDrops extends Model
|
||||||
|
{
|
||||||
|
const STTS_WAIT = 1;
|
||||||
|
const STTS_DROPING = 2;
|
||||||
|
const STTS_DROPED = 3;
|
||||||
|
const STTS_FAIL = 4;
|
||||||
|
|
||||||
|
const CHK_STTS_NO = 1;
|
||||||
|
const CHK_STTS_SUBMIT = 2;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drops;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drops WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drops WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_drops WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_drops")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drops")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drops")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drops")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_drops")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/Models/OrdersInsurances.php
Executable file
59
app/Models/OrdersInsurances.php
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersInsurances extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const AMT_TYPE_FLAT = 1;
|
||||||
|
const AMT_TYPE_PERCENT = 2;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_insurances;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_insurances WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_insurances WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_insurances WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_insurances")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_insurances")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_insurances")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_insurances")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_insurances")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
109
app/Models/OrdersInvoices.php
Executable file
109
app/Models/OrdersInvoices.php
Executable file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersInvoices extends Model
|
||||||
|
{
|
||||||
|
const FLOW_TYPE_PAYMENT = 1;
|
||||||
|
const FLOW_TYPE_BILLING = 2;
|
||||||
|
const FLOW_TYPE_HYBRID = 3;
|
||||||
|
|
||||||
|
const TYPE_CASH_OUT = 1;
|
||||||
|
const TYPE_CASH_IN = 2;
|
||||||
|
const TYPE_CASH_HYBRID = 3;
|
||||||
|
|
||||||
|
const AMT_TYPE_FLAT = 1;
|
||||||
|
const AMT_TYPE_PERCENT = 2;
|
||||||
|
|
||||||
|
// 1=>refer pay_due_at, 2=>jatuh tempo 14 hari kerja
|
||||||
|
const PAY_DUE_TYPE_TIME = 1;
|
||||||
|
const PAY_DUE_TYPE_14_WORK_DAY = 2;
|
||||||
|
|
||||||
|
const IS_PAID_NO = 0;
|
||||||
|
const IS_PAID_YES = 1;
|
||||||
|
|
||||||
|
const IS_GNRT_INVC_NO = 0;
|
||||||
|
const IS_GNRT_INVC_YES = 1;
|
||||||
|
|
||||||
|
// 1=>transfer
|
||||||
|
const PAID_TYPE_TF = 1;
|
||||||
|
|
||||||
|
// 1=>admin, 2=>finance
|
||||||
|
const CRT_TYPE_SYSTEM = 0;
|
||||||
|
const CRT_TYPE_ADMIN = 1;
|
||||||
|
const CRT_TYPE_FINANCE = 2;
|
||||||
|
|
||||||
|
// 1=>client
|
||||||
|
const INVC_FOR_CLIENT = 1;
|
||||||
|
|
||||||
|
const DFT_TAX_PERCENT = 0;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null AND ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null AND ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByTerminId($terminid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_invoices WHERE dlt is null AND c_termin_id = ? LIMIT 1;", [$terminid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLikeCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT COUNT(id) as total FROM t_orders_invoices WHERE dlt is null AND code LIKE ? LIMIT 1;", [$code.'%']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLikeCodeLastRunningNumber($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT code FROM t_orders_invoices WHERE dlt is null AND code LIKE ? ORDER BY code DESC LIMIT 1;", [$code.'%']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_invoices")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_invoices")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_invoices")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_invoices")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_invoices")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
87
app/Models/OrdersItems.php
Executable file
87
app/Models/OrdersItems.php
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersItems extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const DEFAULT_WEIGHT_UNIT = 'kg';
|
||||||
|
const DEFAULT_DIMENSION_UNIT = 'm';
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getsByOrdId($ordid, $filter = [])
|
||||||
|
{
|
||||||
|
$params = [$ordid];
|
||||||
|
$where_item = '';
|
||||||
|
|
||||||
|
if (isset($filter['get_not_deleted'])) {
|
||||||
|
$where_item .= ' AND item.chk_pck_dlt = 0';
|
||||||
|
$where_item .= ' AND item.chk_drop_dlt = 0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
*
|
||||||
|
FROM t_orders_items as item
|
||||||
|
WHERE item.ord_id = ?
|
||||||
|
" . $where_item . "
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getsByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items WHERE ord_code = ?;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOrderItemByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_items WHERE item_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_items")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_items")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_items")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_items")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_items")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
103
app/Models/OrdersLogsTf.php
Executable file
103
app/Models/OrdersLogsTf.php
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersLogsTf extends Model
|
||||||
|
{
|
||||||
|
const defaultSelectedLogsTf = "
|
||||||
|
log_tf.*
|
||||||
|
";
|
||||||
|
|
||||||
|
const TYPE_TF_CHECKPOINT = 1;
|
||||||
|
|
||||||
|
const STTS_UNPAID = 0;
|
||||||
|
const STTS_PAID = 1;
|
||||||
|
const STTS_FAIL = 2;
|
||||||
|
const STTS_PENDING = 3;
|
||||||
|
|
||||||
|
const METHOD_MANUAL = 1;
|
||||||
|
const METHOD_DANA = 2;
|
||||||
|
|
||||||
|
public static function listLogsTf($filter = [])
|
||||||
|
{
|
||||||
|
$select = ''; $join = ''; $where = ''; $group_by = ''; $order_by = ''; $limit = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where .= ' AND log_tf.ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['ord_code'])) {
|
||||||
|
$where .= ' AND log_tf.ord_code = ?';
|
||||||
|
$params[] = $filter['ord_code'];
|
||||||
|
}
|
||||||
|
if (isset($filter['checkpoint_id'])) {
|
||||||
|
$where .= ' AND log_tf.checkpoint_id = ?';
|
||||||
|
$params[] = $filter['checkpoint_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['type'])) {
|
||||||
|
$where .= ' AND log_tf.type = ?';
|
||||||
|
$params[] = $filter['type'];
|
||||||
|
}
|
||||||
|
if (isset($filter['method'])) {
|
||||||
|
$where .= ' AND log_tf.method = ?';
|
||||||
|
$params[] = $filter['method'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['order_by'])) {
|
||||||
|
$order_by = 'ORDER BY ' . $filter['order_by'];
|
||||||
|
}
|
||||||
|
if (isset($filter['group_by'])) {
|
||||||
|
$group_by = 'GROUP BY ' . $filter['group_by'];
|
||||||
|
}
|
||||||
|
if (isset($filter['limit'])) {
|
||||||
|
$limit = 'LIMIT ' . $filter['limit'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. OrdersLogsTf::defaultSelectedLogsTf . "
|
||||||
|
$select
|
||||||
|
FROM t_orders_logs_tf as log_tf
|
||||||
|
$join
|
||||||
|
WHERE log_tf.dlt is null
|
||||||
|
$where
|
||||||
|
$group_by
|
||||||
|
$order_by
|
||||||
|
$limit
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLogsTf()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_logs_tf WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLogsTfById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_logs_tf WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addLogsTf($data)
|
||||||
|
{
|
||||||
|
$pid = DB::table("t_orders_logs_tf")->insertGetId($data);
|
||||||
|
return $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateLogsTf($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_logs_tf")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_logs_tf")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteLogsTf($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_logs_tf")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
70
app/Models/OrdersPckDrop.php
Executable file
70
app/Models/OrdersPckDrop.php
Executable file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersPckDrop extends Model
|
||||||
|
{
|
||||||
|
// stts_delivery
|
||||||
|
const STTS_DELIVERY_OTW_PICKUP = 1;
|
||||||
|
const STTS_DELIVERY_ARRIVED_PICKUP = 2;
|
||||||
|
const STTS_DELIVERY_PROCESS_PICKUP = 3;
|
||||||
|
const STTS_DELIVERY_FINISH_PICKUP = 4;
|
||||||
|
const STTS_DELIVERY_TRAVEL_DOC = 5;
|
||||||
|
const STTS_DELIVERY_OTW_DROP = 6;
|
||||||
|
const STTS_DELIVERY_ARRIVED_DROP = 7;
|
||||||
|
const STTS_DELIVERY_PROCESS_DROP = 8;
|
||||||
|
const STTS_DELIVERY_FINISH_DROP = 9;
|
||||||
|
const STTS_DELIVERY_HANDOVER_DOC = 10;
|
||||||
|
|
||||||
|
const IS_APRV_NO = 0;
|
||||||
|
const IS_APRV_YES = 1;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pck_drop;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pck_drop WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pck_drop WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pck_drop WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_pck_drop")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pck_drop")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pck_drop")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pck_drop")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pck_drop")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Models/OrdersPickups.php
Executable file
63
app/Models/OrdersPickups.php
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersPickups extends Model
|
||||||
|
{
|
||||||
|
const STTS_WAIT = 1;
|
||||||
|
const STTS_PICKING = 2;
|
||||||
|
const STTS_PICKED = 3;
|
||||||
|
const STTS_FAIL = 4;
|
||||||
|
|
||||||
|
const CHK_STTS_NO = 1;
|
||||||
|
const CHK_STTS_SUBMIT = 2;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pickups;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pickups WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pickups WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pickups WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_pickups")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pickups")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pickups")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pickups")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pickups")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
104
app/Models/OrdersPockets.php
Executable file
104
app/Models/OrdersPockets.php
Executable file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersPockets extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const defaultSelectedPockets = "
|
||||||
|
pm.*
|
||||||
|
,pck.name as pck_name,pck.fulladdress as pck_fulladdress
|
||||||
|
,drp.name as drop_name,drp.fulladdress as drop_fulladdress
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listPockets($filter = [])
|
||||||
|
{
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['pck_id'])) {
|
||||||
|
$where .= ' AND pm.pck_id = ?';
|
||||||
|
$params[] = $filter['pck_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['drop_id'])) {
|
||||||
|
$where .= ' AND pm.drop_id = ?';
|
||||||
|
$params[] = $filter['drop_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND pm.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
if (isset($filter['cptid'])) {
|
||||||
|
$where .= ' AND pck.client_group_id = ?';
|
||||||
|
$params[] = $filter['cptid'];
|
||||||
|
$where .= ' AND drp.client_group_id = ?';
|
||||||
|
$params[] = $filter['cptid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. OrdersPockets::defaultSelectedPockets . "
|
||||||
|
$select
|
||||||
|
FROM t_orders_pockets as pm
|
||||||
|
INNER JOIN t_zones as pck ON pm.pck_id = pck.id
|
||||||
|
INNER JOIN t_zones as drp ON pm.drop_id = drp.id
|
||||||
|
WHERE pm.dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showPocketById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. OrdersPockets::defaultSelectedPockets . "
|
||||||
|
FROM t_orders_pockets as pm
|
||||||
|
INNER JOIN t_zones as pck ON pm.pck_id = pck.id
|
||||||
|
INNER JOIN t_zones as drp ON pm.drop_id = drp.id
|
||||||
|
WHERE pm.dlt is null AND pm.id = ?
|
||||||
|
LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPockets()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pockets WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pockets WHERE dlt is null AND id = ? LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pockets WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_pockets WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addPocket($data)
|
||||||
|
{
|
||||||
|
$pocket_id = DB::table("t_orders_pockets")->insertGetId($data);
|
||||||
|
return $pocket_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updatePocket($pocket_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pockets")->where("id", $pocket_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pockets")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deletePocket($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_pockets")->where("id", $pocket_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Models/OrdersRates.php
Executable file
60
app/Models/OrdersRates.php
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersRates extends Model
|
||||||
|
{
|
||||||
|
const STTS_WAIT = 1;
|
||||||
|
const STTS_DROPING = 2;
|
||||||
|
const STTS_DROPED = 3;
|
||||||
|
const STTS_FAIL = 4;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_rates;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_rates WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_rates WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_rates WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_rates")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_rates")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_rates")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_rates")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_rates")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
149
app/Models/OrdersTermins.php
Executable file
149
app/Models/OrdersTermins.php
Executable file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersTermins extends Model
|
||||||
|
{
|
||||||
|
const FLOW_TYPE_PAYMENT = 1;
|
||||||
|
const FLOW_TYPE_BILLING = 2;
|
||||||
|
const FLOW_TYPE_HYBRID = 3;
|
||||||
|
|
||||||
|
const TYPE_CASH_OUT = 1;
|
||||||
|
const TYPE_CASH_IN = 2;
|
||||||
|
const TYPE_CASH_HYBRID = 3;
|
||||||
|
|
||||||
|
const AMT_TYPE_FLAT = 1;
|
||||||
|
const AMT_TYPE_PERCENT = 2;
|
||||||
|
|
||||||
|
// 1=>refer termin_ddln_at, 2=>refer to order finish(pengantaran selesai)
|
||||||
|
const DDLN_TERMIN_TYPE_TIME = 1;
|
||||||
|
const DDLN_TERMIN_TYPE_ORD_FINISH = 2;
|
||||||
|
|
||||||
|
const IS_PAID_NO = 0;
|
||||||
|
const IS_PAID_YES = 1;
|
||||||
|
|
||||||
|
// 1=>transfer
|
||||||
|
const PAID_TYPE_TF = 1;
|
||||||
|
|
||||||
|
// 1=>admin, 2=>finance
|
||||||
|
const CRT_TYPE_SYSTEM = 0;
|
||||||
|
const CRT_TYPE_ADMIN = 1;
|
||||||
|
const CRT_TYPE_FINANCE = 2;
|
||||||
|
|
||||||
|
const IS_ACTIVE_NO = 0;
|
||||||
|
const IS_ACTIVE_YES = 1;
|
||||||
|
|
||||||
|
// 1=>client, 2=>vendor
|
||||||
|
const TERMIN_FOR_CLIENT = 1;
|
||||||
|
const TERMIN_FOR_VENDOR = 2;
|
||||||
|
|
||||||
|
// merge per trx
|
||||||
|
const STTS_MERGE_NO = 0;
|
||||||
|
const STTS_MERGE_TO = 1;
|
||||||
|
const STTS_MERGE_RESULT = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* termin_at itu deadline pembayaran
|
||||||
|
* column merge disini untuk merge per trx
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function listWithFilter($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
|
||||||
|
if (isset($filter['ord_id'])) {
|
||||||
|
$where .= ' AND ord_id = ?';
|
||||||
|
$params[] = $filter['ord_id'];
|
||||||
|
} else if (isset($filter['ord_code'])) {
|
||||||
|
$where .= ' AND ord_code = ?';
|
||||||
|
$params[] = $filter['ord_code'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['termin_for'])) {
|
||||||
|
$where .= ' AND termin_for = ?';
|
||||||
|
$params[] = $filter['termin_for'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['crt_type'])) {
|
||||||
|
$where .= ' AND crt_type = ?';
|
||||||
|
$params[] = $filter['crt_type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['termin_is_paid'])) {
|
||||||
|
$where .= ' AND termin_is_paid = ?';
|
||||||
|
$params[] = $filter['termin_is_paid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($filter['in_stts_merge'])) {
|
||||||
|
if (is_array($filter['in_stts_merge'])) {
|
||||||
|
$where .= ' AND stts_merge IN (';
|
||||||
|
foreach ($filter['in_stts_merge'] as $in) {
|
||||||
|
$where .= '?,';
|
||||||
|
$params[] = $in;
|
||||||
|
}
|
||||||
|
if (strpos(substr($where, -1), ',') !== false) {
|
||||||
|
$where = substr($where, 0, -1) . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT
|
||||||
|
ord_termin.*
|
||||||
|
$select
|
||||||
|
FROM t_orders_termins as ord_termin
|
||||||
|
WHERE dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_termins WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_termins WHERE dlt is null AND id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_termins WHERE dlt is null AND ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_termins WHERE dlt is null AND ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_termins")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_termins")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_termins")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_termins")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_termins")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Models/OrdersVehicles.php
Executable file
60
app/Models/OrdersVehicles.php
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersVehicles extends Model
|
||||||
|
{
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vehicles;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vehicles WHERE id = ? LIMIT 1;", [$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vehicles WHERE ord_code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCodeByStatus($code, $status)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vehicles WHERE ord_code = ? AND status = ? LIMIT 1;", [$code, $status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vehicles WHERE ord_id = ? LIMIT 1;", [$ordid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_vehicles")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vehicles")->where("id", $id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vehicles")->where("ord_id", $ord_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vehicles")->where("id", $id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vehicles")->where("ord_id", $ord_id)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
193
app/Models/OrdersVendors.php
Executable file
193
app/Models/OrdersVendors.php
Executable file
@ -0,0 +1,193 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class OrdersVendors extends Model
|
||||||
|
{
|
||||||
|
const STTS_WAIT = 1;
|
||||||
|
const STTS_ACC = 2;
|
||||||
|
const STTS_REJECT = 3;
|
||||||
|
const STTS_IGNORE = 4;
|
||||||
|
const STTS_NOT_READY = 5; // want order but expired, bcs not fill data
|
||||||
|
|
||||||
|
const IS_NOT_PAY = 1;
|
||||||
|
const IS_PAYED = 2;
|
||||||
|
|
||||||
|
const LINK_WILL_EXP = 1;
|
||||||
|
const LINK_NOT_EXP = 2;
|
||||||
|
|
||||||
|
const IS_MAILING_BID_NOT = 0;
|
||||||
|
const IS_MAILING_BID_SEND = 1;
|
||||||
|
|
||||||
|
const IS_WANT_IGNORE = 0;
|
||||||
|
const IS_WANT_NO = 1;
|
||||||
|
const IS_WANT_YES = 2;
|
||||||
|
|
||||||
|
public static function get()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_orders_vendors;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getById($id)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE id = ? LIMIT 1;",
|
||||||
|
[$id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCode($code)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE ord_code = ? LIMIT 1;",
|
||||||
|
[$code]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdCodeByStatus($code, $status)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE ord_code = ? AND status = ? LIMIT 1;",
|
||||||
|
[$code, $status]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdIdByStatus($id, $status)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE ord_id = ? AND status = ? LIMIT 1;",
|
||||||
|
[$id, $status]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdId($ordid)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE ord_id = ? LIMIT 1;",
|
||||||
|
[$ordid]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByBidToken($tkn)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE bid_token = ? LIMIT 1;",
|
||||||
|
[$tkn]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByOrdIdAndVdrId($ordid, $vdrid)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors WHERE ord_id = ? AND vdr_id = ? LIMIT 1;",
|
||||||
|
[$ordid, $vdrid]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNextVendors($ordid, $not_vdr_id = 0)
|
||||||
|
{
|
||||||
|
// AND is_mailing_bid = " . OrdersVendors::IS_MAILING_BID_NOT . "
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors
|
||||||
|
WHERE ord_id = ?
|
||||||
|
AND is_want = " .
|
||||||
|
OrdersVendors::IS_WANT_IGNORE .
|
||||||
|
"
|
||||||
|
AND respond_at = 0
|
||||||
|
AND vdr_id != ?
|
||||||
|
;",
|
||||||
|
[$ordid, $not_vdr_id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getOtherVendorsWantThisOrder($ordid, $not_vdr_id = 0)
|
||||||
|
{
|
||||||
|
return DB::select(
|
||||||
|
"SELECT * FROM t_orders_vendors
|
||||||
|
WHERE ord_id = ?
|
||||||
|
AND is_mailing_bid = " .
|
||||||
|
OrdersVendors::IS_MAILING_BID_SEND .
|
||||||
|
"
|
||||||
|
AND is_want = " .
|
||||||
|
OrdersVendors::IS_WANT_YES .
|
||||||
|
"
|
||||||
|
AND status = " .
|
||||||
|
OrdersVendors::STTS_WAIT .
|
||||||
|
"
|
||||||
|
AND respond_at = 0
|
||||||
|
AND vdr_id != ?
|
||||||
|
;",
|
||||||
|
[$ordid, $not_vdr_id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function searchVendorsByRate($filter = [])
|
||||||
|
{
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
$query = "SELECT";
|
||||||
|
$query .=
|
||||||
|
" vendor.id as vdr_id,vendor.first_name,vendor.phone,vendor.phone_code,vendor.email,vendor.fulladdress";
|
||||||
|
$query .=
|
||||||
|
" ,rate.vdr_id as rate_vdr_id,rate.vhc_type as rate_vhc_type,rate.origin_prov as rate_origin_prov,rate.dest_city as rate_dest_city,rate.dest_district as rate_dest_district";
|
||||||
|
$query .=
|
||||||
|
" ,rate.fast_time as rate_fast_time,rate.long_time as rate_long_time,rate.sell_kg as rate_sell_kg,rate.sell_cbm as rate_sell_cbm,rate.sell_ftl as rate_sell_ftl";
|
||||||
|
$query .= " FROM t_conf_rates AS rate";
|
||||||
|
$query .= " INNER JOIN t_vehicles as v ON v.type_id = rate.vhc_type";
|
||||||
|
$query .= " INNER JOIN t_users as vendor ON rate.vdr_id = vendor.id";
|
||||||
|
$query .= " WHERE rate.vdr_id != 0 AND rate.dest_city != 0";
|
||||||
|
$query .=
|
||||||
|
" AND rate.origin_prov = ? AND (rate.dest_city = ? OR rate.dest_district = ?) AND rate.sell_ftl = ? AND rate.long_time = ?";
|
||||||
|
array_push(
|
||||||
|
$params,
|
||||||
|
$filter["active_rates"]->origin_prov,
|
||||||
|
$filter["active_rates"]->dest_city,
|
||||||
|
$filter["active_rates"]->dest_district,
|
||||||
|
$filter["active_rates"]->sell_ftl,
|
||||||
|
$filter["active_rates"]->long_time
|
||||||
|
);
|
||||||
|
if ($filter["prefer_truck_type"]) {
|
||||||
|
$query .= " AND v.type_id = ?";
|
||||||
|
$params[] = $filter["prefer_truck_type"];
|
||||||
|
}
|
||||||
|
$query .= " GROUP BY rate.vdr_id";
|
||||||
|
return DB::select($query, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($data)
|
||||||
|
{
|
||||||
|
$id = DB::table("t_orders_vendors")->insertGetId($data);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updt($id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vendors")
|
||||||
|
->where("id", $id)
|
||||||
|
->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updtByOrdId($ord_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vendors")
|
||||||
|
->where("ord_id", $ord_id)
|
||||||
|
->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dlt($id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vendors")
|
||||||
|
->where("id", $id)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dltByOrdId($ord_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_orders_vendors")
|
||||||
|
->where("ord_id", $ord_id)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
149
app/Models/PocketMoney.php
Executable file
149
app/Models/PocketMoney.php
Executable file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class PocketMoney extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
const IS_INACTIVE = 0;
|
||||||
|
const IS_ACTIVE = 1;
|
||||||
|
|
||||||
|
const TYPE_BUNDLE = 1;
|
||||||
|
const TYPE_BUNDLE_TEXT = 'Bundle';
|
||||||
|
const TYPE_CHECKPOINTS = 2;
|
||||||
|
const TYPE_CHECKPOINTS_TEXT = 'Checkpoints';
|
||||||
|
|
||||||
|
const FLOW_DEPARTURE = 1;
|
||||||
|
const FLOW_DEPARTURE_TEXT = 'Departure';
|
||||||
|
const FLOW_ARRIVAL = 2;
|
||||||
|
const FLOW_ARRIVAL_TEXT = 'Arrival';
|
||||||
|
const FLOW_HYBRID = 3;
|
||||||
|
const FLOW_HYBRID_TEXT = 'Hybpocket_id';
|
||||||
|
|
||||||
|
const defaultSelectedPockets = "
|
||||||
|
pm.*
|
||||||
|
,pck.name as pck_name,pck.fulladdress as pck_fulladdress
|
||||||
|
,drp.name as drop_name,drp.fulladdress as drop_fulladdress
|
||||||
|
";
|
||||||
|
|
||||||
|
public static function listPockets($filter = [])
|
||||||
|
{
|
||||||
|
$select = '';
|
||||||
|
$where = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if (isset($filter['pck_id'])) {
|
||||||
|
$where .= ' AND pm.pck_id = ?';
|
||||||
|
$params[] = $filter['pck_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['drop_id'])) {
|
||||||
|
$where .= ' AND pm.drop_id = ?';
|
||||||
|
$params[] = $filter['drop_id'];
|
||||||
|
}
|
||||||
|
if (isset($filter['is_active'])) {
|
||||||
|
$where .= ' AND pm.is_active = ?';
|
||||||
|
$params[] = $filter['is_active'];
|
||||||
|
}
|
||||||
|
if (isset($filter['cptid'])) {
|
||||||
|
$where .= ' AND pck.client_group_id = ?';
|
||||||
|
$params[] = $filter['cptid'];
|
||||||
|
$where .= ' AND drp.client_group_id = ?';
|
||||||
|
$params[] = $filter['cptid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. PocketMoney::defaultSelectedPockets . "
|
||||||
|
$select
|
||||||
|
FROM t_pocket_money as pm
|
||||||
|
INNER JOIN t_zones as pck ON pm.pck_id = pck.id
|
||||||
|
INNER JOIN t_zones as drp ON pm.drop_id = drp.id
|
||||||
|
WHERE pm.dlt is null
|
||||||
|
$where
|
||||||
|
;", $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function showPocketById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT "
|
||||||
|
. PocketMoney::defaultSelectedPockets . "
|
||||||
|
FROM t_pocket_money as pm
|
||||||
|
INNER JOIN t_zones as pck ON pm.pck_id = pck.id
|
||||||
|
INNER JOIN t_zones as drp ON pm.drop_id = drp.id
|
||||||
|
WHERE pm.dlt is null AND pm.id = ?
|
||||||
|
LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPockets()
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_pocket_money WHERE dlt is null;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketById($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_pocket_money WHERE dlt is null AND id = ? LIMIT 1;", [$pocket_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketByCode($code)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_pocket_money WHERE dlt is null AND code = ? LIMIT 1;", [$code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPocketByPckDrop($pck_id, $drop_id)
|
||||||
|
{
|
||||||
|
return DB::select("SELECT * FROM t_pocket_money WHERE dlt is null AND pck_id = ? AND drop_id = ? LIMIT 1;", [$pck_id, $drop_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function addPocket($data)
|
||||||
|
{
|
||||||
|
$pocket_id = DB::table("t_pocket_money")->insertGetId($data);
|
||||||
|
return $pocket_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updatePocket($pocket_id, $data)
|
||||||
|
{
|
||||||
|
return DB::table("t_pocket_money")->where("id", $pocket_id)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deletePocket($pocket_id)
|
||||||
|
{
|
||||||
|
return DB::table("t_pocket_money")->where("id", $pocket_id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTypes()
|
||||||
|
{
|
||||||
|
$datas = [];
|
||||||
|
for ($i=0; $i<2; $i++) {
|
||||||
|
$datas[$i] = new \stdClass();
|
||||||
|
if ($i === 0) {
|
||||||
|
$datas[$i]->id = PocketMoney::TYPE_BUNDLE;
|
||||||
|
$datas[$i]->name = PocketMoney::TYPE_BUNDLE_TEXT;
|
||||||
|
} else if ($i === 1) {
|
||||||
|
$datas[$i]->id = PocketMoney::TYPE_CHECKPOINTS;
|
||||||
|
$datas[$i]->name = PocketMoney::TYPE_CHECKPOINTS_TEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFlows()
|
||||||
|
{
|
||||||
|
$datas = [];
|
||||||
|
for ($i=0; $i<3; $i++) {
|
||||||
|
$datas[$i] = new \stdClass();
|
||||||
|
if ($i === 0) {
|
||||||
|
$datas[$i]->id = PocketMoney::FLOW_DEPARTURE;
|
||||||
|
$datas[$i]->name = PocketMoney::FLOW_DEPARTURE_TEXT;
|
||||||
|
} else if ($i === 1) {
|
||||||
|
$datas[$i]->id = PocketMoney::FLOW_ARRIVAL;
|
||||||
|
$datas[$i]->name = PocketMoney::FLOW_ARRIVAL_TEXT;
|
||||||
|
} else if ($i === 2) {
|
||||||
|
$datas[$i]->id = PocketMoney::FLOW_HYBRID;
|
||||||
|
$datas[$i]->name = PocketMoney::FLOW_HYBRID_TEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $datas;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user