@extends('layouts.app') @section('content')

📝 Marketing Strategy Input

@php $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; $periodType = request('period_type', 'monthly'); @endphp @if($periodType === 'yearly') Full Year {{ $year }} @else {{ $months[$month - 1] }} {{ $year }} @endif

View Dashboard
@if(session('success'))
{{ session('success') }}
@endif
@if($periodType === 'monthly')
@endif
@if($periodType === 'yearly')

📊 Year {{ $year }} Summary

All Sales
Total Marketing Spend
RM {{ number_format($existingData->total_marketing_spend ?? 0, 2) }}
Total Revenue Generated
RM {{ number_format($actualRevenue, 2) }}
All Sales (HQ + Stokis + Agent)
Average ROI
{{ number_format($existingData->roi_percentage ?? 0, 2) }}%
@php $totalSpend = $existingData->total_marketing_spend ?? 0; $allRatio = $totalSpend > 0 ? $actualRevenue / $totalSpend : 0; @endphp
Ratio: {{ number_format($allRatio, 2) }}x
Based on All Sales
Aggregated from {{ $existingData->months_count ?? 0 }} months of data

Channel Breakdown (Full Year - All Sales)

Brand Ambassadors
RM {{ number_format($existingData->brand_ambassador_spend ?? 0, 2) }}
Ads
RM {{ number_format($existingData->ads_spend ?? 0, 2) }}
Social Media
RM {{ number_format($existingData->social_media_spend ?? 0, 2) }}
Events
RM {{ number_format($existingData->events_spend ?? 0, 2) }}
Other
RM {{ number_format($existingData->other_spend ?? 0, 2) }}
Total Profit (All Sales)
RM {{ number_format(($actualRevenue - ($existingData->total_marketing_spend ?? 0)), 2) }}
Revenue: RM {{ number_format($actualRevenue, 2) }}
@else
Revenue for this Month
All Sales
RM {{ number_format($actualRevenue, 2) }}
Total Sales (HQ: RM {{ number_format($hqRevenue, 2) }} + Stokis: RM {{ number_format($stokisSales, 2) }} + Agent: RM {{ number_format($agentSales, 2) }})
@csrf

Marketing Spend Breakdown

Total Marketing Spend
RM 0.00
@php $channels = ['Facebook', 'Instagram', 'TikTok', 'Google Ads', 'YouTube', 'Twitter', 'LinkedIn', 'Others']; $existingChannels = $existingData ? explode(', ', $existingData->channels_used) : []; @endphp @foreach($channels as $channel) @endforeach
@if($existingData) @endif
@endif @if($periodType === 'yearly' && ($existingData->months_count ?? 0) > 0)

Strategic Analysis for {{ $year }}

Get AI-powered strategic recommendations based on the full year's performance

@endif @if($existingData && ($existingData->ai_analysis || $existingData->ai_recommendations))
AI

AI-Powered Insights

Strategic analysis and actionable recommendations

@if($existingData->ai_analysis)

Performance Analysis

@php // Parse analysis into bullet points $analysisLines = explode("\n", $existingData->ai_analysis); $bulletPoints = []; foreach($analysisLines as $line) { $line = trim($line); if(preg_match('/^\d+\.\s+\*\*(.+?)\*\*:\s*(.+)$/', $line, $matches)) { // Format: 1. **Title**: Description $bulletPoints[] = ['title' => $matches[1], 'text' => $matches[2]]; } elseif(preg_match('/^[-•]\s*(.+)$/', $line, $matches)) { // Format: - Text or • Text $bulletPoints[] = ['title' => null, 'text' => $matches[1]]; } elseif(!empty($line) && !in_array($line, ['Analysis:', 'ANALYSIS:', '###'])) { $bulletPoints[] = ['title' => null, 'text' => $line]; } } @endphp @foreach($bulletPoints as $index => $point)
{{ $index + 1 }}
@if($point['title'])
{{ $point['title'] }}

{{ $point['text'] }}

@else

{{ $point['text'] }}

@endif
@endforeach
@endif @if($existingData->ai_recommendations)

Action Plan

{{ substr_count($existingData->ai_recommendations, "\n") + 1 }} Recommendations
@php // Parse recommendations into action items $recommendationLines = explode("\n", $existingData->ai_recommendations); $recommendations = []; foreach($recommendationLines as $line) { $line = trim($line); if(preg_match('/^\d+\.\s+\*\*(.+?)\*\*:\s*(.+)$/', $line, $matches)) { // Format: 1. **Title**: Description $recommendations[] = ['title' => $matches[1], 'text' => $matches[2]]; } elseif(preg_match('/^\d+\.\s+(.+)$/', $line, $matches)) { // Format: 1. Text $recommendations[] = ['title' => null, 'text' => $matches[1]]; } elseif(preg_match('/^[-•]\s*(.+)$/', $line, $matches)) { // Format: - Text or • Text $recommendations[] = ['title' => null, 'text' => $matches[1]]; } elseif(!empty($line) && !in_array($line, ['Recommendations:', 'RECOMMENDATIONS:', '###'])) { $recommendations[] = ['title' => null, 'text' => $line]; } } @endphp @foreach($recommendations as $index => $rec)
@if($rec['title'])
{{ $index + 1 }}. {{ $rec['title'] }}

{{ $rec['text'] }}

@else

{{ $index + 1 }}. {{ $rec['text'] }}

@endif
@endforeach
@endif
@endif
@endsection