From 0b1589d1738baabe8c43a706b9a6999de9f82dc4 Mon Sep 17 00:00:00 2001 From: arifal Date: Fri, 11 Jul 2025 16:31:37 +0700 Subject: [PATCH] fix share text to app and handle copy to clipboard daily report mechanic --- .../Controllers/TransactionController.php | 65 ++++- resources/views/transaction/lists.blade.php | 235 ++++++++++++++++-- 2 files changed, 263 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index b228aca..18cd41b 100755 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -117,22 +117,43 @@ class TransactionController extends Controller ->where('sa.dealer_id', Auth::user()->dealer_id) ->where('work_id', $work->id) ->whereDate('transactions.date', '=', date('Y-m-d'))->groupBy('transactions.user_sa_id')->get(); + + // Initialize data array for this work + $tm1[$work['shortname']]['data'] = []; + $daily_total = 0; + foreach($transaction_sas as $sa) { $tm1[$work['shortname']]['data'][] = $sa['sa_name'].":".$sa['qty']; + $daily_total += $sa['qty']; } - $month_share_data = Transaction::select(DB::raw('SUM(qty) as qty'), 'u.name')->join('users AS u', 'u.id', '=', 'transactions.user_sa_id')->where('transactions.dealer_id', Auth::user()->dealer->id)->whereMonth('date', date('m'))->whereYear('date', date('Y'))->where('work_id', $work->id)->groupBy('user_sa_id')->get(); - $tm1[$work['shortname']]['total_title'] = "*[PERIODE 1 - ". Carbon::now()->translatedFormat('d F Y') ."]*\n\n"; - - $sum_month_share_trx = 0; - $tm_month = []; - foreach($month_share_data as $m_trx) { - $tm_month[] = $m_trx->name.":".$m_trx->qty." Unit\n"; - $sum_month_share_trx += $m_trx->qty; + // Add daily total even if no data + if (empty($tm1[$work['shortname']]['data'])) { + $tm1[$work['shortname']]['data'][] = "Tidak ada data:0"; } + + // Remove monthly data section since this is daily report + // $month_share_data = Transaction::select(DB::raw('SUM(qty) as qty'), 'u.name') + // ->join('users AS u', 'u.id', '=', 'transactions.user_sa_id') + // ->where('transactions.dealer_id', Auth::user()->dealer->id) + // ->whereMonth('date', date('m')) + // ->whereYear('date', date('Y')) + // ->where('work_id', $work->id) + // ->groupBy('user_sa_id') + // ->get(); + + // Remove the period title since this is for daily report, not monthly + // $tm1[$work['shortname']]['total_title'] = "*[PERIODE 1 - ". Carbon::now()->translatedFormat('d F Y') ."]*\n\n"; - $tm1[$work['shortname']]['total_body'] = $tm_month; - $tm1[$work['shortname']]['total_total'] = "*TOTAL : ". $sum_month_share_trx." Unit*"; + // $sum_month_share_trx = 0; + // $tm_month = []; + // foreach($month_share_data as $m_trx) { + // $tm_month[] = $m_trx->name.":".$m_trx->qty." Unit\n"; + // $sum_month_share_trx += $m_trx->qty; + // } + + // $tm1[$work['shortname']]['total_body'] = $tm_month; + // $tm1[$work['shortname']]['total_total'] = "*TOTAL : ". $sum_month_share_trx." Unit*"; } if(isset($request->date_start)) { @@ -156,7 +177,29 @@ class TransactionController extends Controller $sas = User::where('role_id', 4)->get(); $dealers = Dealer::all(); $works = Work::all(); - return view('transaction.lists', compact('transaction_dealers', 'transaction_mechanics', 'mechanic', 'sas', 'dealers', 'works', 'date_start', 'date_end')); + + // Get KPI data for current user using KPI service + $kpiService = app(\App\Services\KpiService::class); + + // Auto-calculate current month KPI achievement including claimed transactions + $kpiService->calculateKpiAchievementWithClaims(Auth::user()); + + $kpiSummary = $kpiService->getKpiSummaryWithClaims(Auth::user()); + + // Get current month period name + $currentMonthName = now()->translatedFormat('F Y'); + + $kpiData = [ + 'target' => $kpiSummary['current_target'] ? $kpiSummary['current_target']->target_value : 0, + 'actual' => $kpiSummary['current_achievement'] ? $kpiSummary['current_achievement']->actual_value : 0, + 'percentage' => $kpiSummary['current_percentage'], + 'status' => $kpiSummary['current_achievement'] ? $kpiSummary['current_achievement']->status : 'pending', + 'status_color' => $kpiSummary['current_achievement'] ? $kpiSummary['current_achievement']->status_color : 'secondary', + 'period' => $currentMonthName, + 'has_target' => $kpiSummary['current_target'] ? true : false + ]; + + return view('transaction.lists', compact('transaction_dealers', 'transaction_mechanics', 'mechanic', 'sas', 'dealers', 'works', 'date_start', 'date_end', 'kpiData')); } public function cmp($a, $b){ diff --git a/resources/views/transaction/lists.blade.php b/resources/views/transaction/lists.blade.php index f5ffaaf..a214b19 100755 --- a/resources/views/transaction/lists.blade.php +++ b/resources/views/transaction/lists.blade.php @@ -249,22 +249,72 @@ $string = "*[Laporan Harian Mekanik ]*\n"; $string .= "*". Auth::user()->dealer->name ."*\n"; $string .= "*". $transaction_mechanics['today_date'] ."*\n\n\n"; - foreach ($transaction_mechanics['data'] as $shortname => $trx) { - $string .= $shortname."\n"; - $total_qty = 0; - foreach ($trx['data'] as $item) { - $total_qty += explode(':', $item)[1]; - $string .= $item."\n"; + + // Add KPI Achievement Information + if($kpiData['has_target']) { + $string .= "*=== KPI ACHIEVEMENT PROGRESS ===*\n"; + $string .= "*Target ". $kpiData['period'] .": ". number_format($kpiData['target']) ." Pekerjaan*\n"; + $string .= "*Pencapaian: ". number_format($kpiData['actual']) ." Pekerjaan*\n"; + $string .= "*Progress: ". $kpiData['percentage'] ."%*\n"; + + // Add status message + if($kpiData['status'] == 'exceeded') { + $string .= "*Status: ✅ Target tercapai!*\n"; + } elseif($kpiData['status'] == 'good') { + $string .= "*Status: 🔵 Performa baik*\n"; + } elseif($kpiData['status'] == 'fair') { + $string .= "*Status: 🟡 Perlu peningkatan*\n"; + } elseif($kpiData['status'] == 'poor') { + $string .= "*Status: 🔴 Perlu perbaikan*\n"; + } else { + $string .= "*Status: ⚪ Belum ada data*\n"; } - $string .= "*TOTAL".$total_qty."*\n\n"; - - $string .= $trx['total_title']; - foreach ($trx['total_body'] as $total) { - $string .= $total; - } - - $string .= $trx['total_total']."\n\n"; + $string .= "\n"; } + + $overall_total = 0; + + // Debug: Check if data exists + if (!empty($transaction_mechanics['data'])) { + foreach ($transaction_mechanics['data'] as $shortname => $trx) { + $string .= "*". $shortname ."*\n"; + $total_qty = 0; + + // Check if data array exists + if (isset($trx['data']) && is_array($trx['data'])) { + foreach ($trx['data'] as $item) { + $parts = explode(':', $item); + if (count($parts) >= 2) { + $qty = intval($parts[1]); + $total_qty += $qty; + } + $string .= $item."\n"; + } + } + + $string .= "*TOTAL: ".$total_qty." Unit*\n\n"; + $overall_total += $total_qty; + + // Remove monthly data display since this is daily report + // if (isset($trx['total_body']) && is_array($trx['total_body'])) { + // foreach ($trx['total_body'] as $total) { + // $string .= $total; + // } + // } + + // if (isset($trx['total_total'])) { + // $string .= $trx['total_total']."\n\n"; + // } + } + } else { + $string .= "*Tidak ada data transaksi hari ini*\n\n"; + } + + // Add overall summary + $string .= "*=== RINGKASAN HARIAN ===*\n"; + $string .= "*Tanggal: ". $transaction_mechanics['today_date'] ."*\n"; + $string .= "*Dealer: ". Auth::user()->dealer->name ."*\n"; + $string .= "*Total Keseluruhan: ". $overall_total ." Unit*\n"; @endphp {!! $string !!} @@ -335,23 +385,156 @@