date) ? date('Y-m-d', strtotime($request->date)) : date('Y-m-d'); $date_in_minus_4_months = date('Y-m-d', strtotime($date_in . ' -4 months')); $for = isset($request->for) ? $request->for : 'a'; $username = m3_user() !== '' ? Str::upper(trim(m3_user())) : ''; // Get Logged User CO & WH & PL $iCM428M = DB::connection(config('m3.connection', 'pgsql'))->table('icm428m') ->select('R428US', 'R428CO', 'R428WH', 'R428PL') ->where('R428US', '=', $username) ->first(); $co = isset($iCM428M->R428CO) ? $iCM428M->R428CO : ''; $whseno = isset($iCM428M->R428WH) ? $iCM428M->R428WH : ''; $plantno = isset($iCM428M->R428PL) ? $iCM428M->R428PL : ''; $all = "tempfile4 as ( select a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype, sum(dollarvalue) as dollarvalue, sum(weight) as weight, max(source) as source from tempfile3 where not (a4shipvia1='OCEAN' or interco='interco') and source<>'A2' group by a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype ) select * from tempfile4 order by source"; $ltl = "tempfile4 as ( select a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype, sum(dollarvalue) as dollarvalue, sum(weight) as weight, max(source) as source from tempfile3 where not (a4shipvia1='OCEAN' or interco='interco') and source<>'A2' and a4shiptype='LTL' group by a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype ) select * from tempfile4 order by source"; $parcel = "tempfile4 as ( select a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype, sum(dollarvalue) as dollarvalue, sum(weight) as weight, max(source) as source from tempfile3 where not (a4shipvia1='OCEAN' or interco='interco') and source<>'A2' and a4shiptype='SmallPack' group by a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype ) select * from tempfile4 order by source"; $io = "tempfile4 as ( select a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype, sum(dollarvalue) as dollarvalue, sum(weight) as weight, max(source) as source from tempfile3 where (a4shipvia1='OCEAN' or interco='interco') and source<>'A2' group by a5macpkr, a4shshnm, a4shipvia1, interco, a4shiptype ) select * from tempfile4 order by source"; switch ($for) { case 'a': $stmt2 = $all; break; case 'l': $stmt2 = $ltl; break; case 'p': $stmt2 = $parcel; break; case 'i': $stmt2 = $io; break; default: $stmt2 = $all; break; } include $_SERVER['DOCUMENT_ROOT'] . '/../../KPI2_update711M_SQL_main.inc.php'; $perfDetails = DB::connection(config('m3.connection', 'pgsql'))->select($sqlstmt1 . $stmt2); return view('m3::liberty-theme.pages.whsePerfDetails', compact('perfDetails', 'date_in', 'for')); } }