@php /** @var \Illuminate\Support\Fluent|mixed $cheque */ $mode = $mode ?? 'paper'; // 'paper' | 'card' $pvDetectBankKey = function (string $label): string { $l = strtolower($label); if (str_contains($l, 'seylan')) return 'Seylan'; if (str_contains($l, 'hatton') || str_contains($l, 'hnb')) return 'HNB'; if (str_contains($l, 'commercial')) return 'Commercial'; if (str_contains($l, 'dfcc')) return 'DFCC'; if (str_contains($l, 'sampath')) return 'Sampath'; if (str_contains($l, 'union')) return 'Union'; if (str_contains($l, 'ndb')) return 'NDB'; if (str_contains($l, 'national savings') || str_contains($l, 'nsb')) return 'NSB'; if (str_contains($l, 'people') || str_contains($l, 'peoples')) return "People's"; if (str_contains($l, 'bank of ceylon') || str_contains($l, 'boc')) return 'BOC'; return ''; }; $pvAmountToWords = function (float $n) { $ones = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']; $tens = ['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']; $chunkToWords = function (int $num) use (&$chunkToWords, $ones, $tens): string { $out = ''; if ($num >= 100) { $out .= $ones[intdiv($num, 100)].' hundred'; $num = $num % 100; if ($num > 0) $out .= ' '; } if ($num >= 20) { $out .= $tens[intdiv($num, 10)]; $num = $num % 10; if ($num > 0) $out .= '-'.$ones[$num]; return $out; } if ($num > 0 || $out === '') { $out .= $ones[$num]; } return $out; }; $intToWords = function (int $num) use (&$intToWords, $chunkToWords): string { if ($num === 0) return 'zero'; $n = abs($num); $parts = []; $scales = [ ['v' => 1_000_000_000, 'label' => 'billion'], ['v' => 1_000_000, 'label' => 'million'], ['v' => 1_000, 'label' => 'thousand'], ]; foreach ($scales as $s) { if ($n >= $s['v']) { $q = intdiv($n, $s['v']); $n = $n % $s['v']; $parts[] = $chunkToWords($q).' '.$s['label']; } } if ($n > 0) $parts[] = $chunkToWords($n); return trim(implode(' ', $parts)); }; $amt = max(0, $n); $rupees = (int) floor($amt); $cents = (int) round(($amt - $rupees) * 100); $title = ucwords($intToWords($rupees)); $centsPart = ''; if ($cents > 0) { $centsPart = ' and '.ucwords($intToWords($cents)).' Cents'; } return trim($title.$centsPart.' Only'); }; $pvSplitTwoLines = function (string $text, int $limit = 72): array { $t = trim($text); if ($t === '') return ['', '']; if (mb_strlen($t) <= $limit) return [$t, '']; $cut = mb_strrpos(mb_substr($t, 0, $limit + 1), ' '); if ($cut === false || $cut < 10) $cut = $limit; $a = trim(mb_substr($t, 0, $cut)); $b = trim(mb_substr($t, $cut)); return [$a, $b]; }; $pvExtractAccountNameOnly = function (string $raw): string { $t = trim(preg_replace('/\s*\([^)]*\)\s*$/', '', $raw) ?? ''); if ($t === '') return ''; $t = preg_replace('/\b(bank|seylan|hatton|hnb|commercial|dfcc|sampath|union|ndb|national\s+savings|nsb|people\'s|peoples|people|bank\s+of\s+ceylon|boc)\b/i', ' ', $t) ?? ''; $t = trim(preg_replace('/\s+/', ' ', $t) ?? ''); return $t; }; $direction = (string) ($cheque->direction ?? 'issue'); $party = ''; if ($direction === 'issue') { $party = $cheque->supplier?->supplier_name ?: ($cheque->personAccount?->name ?: ($cheque->payee ?? '')); } else { $party = $cheque->customer?->name ?: ($cheque->personAccount?->name ?: ($cheque->payee ?? '')); } $bankAccountLabel = (string) (($cheque->account->name ?? '') ?: ($cheque->bank_name ?? '')); $ourBankKey = $pvDetectBankKey($bankAccountLabel); $ourBankLogo = $ourBankKey !== '' ? ($pvBankLogosAll[$ourBankKey] ?? null) : null; $recvBankName = trim((string) ($cheque->received_bank_name ?? '')); $recvLogo = $recvBankName !== '' ? ($pvBankLogosAll[$recvBankName] ?? null) : null; $recvInitials = 'OT'; if ($recvBankName !== '') { $base = preg_replace('/[^A-Za-z]/', ' ', $recvBankName) ?? ''; $parts = array_values(array_filter(preg_split('/\s+/', trim($base)) ?: [])); $recvInitials = strtoupper(substr($parts[0] ?? 'O', 0, 1).substr($parts[1] ?? '', 0, 1)); $recvInitials = $recvInitials !== '' ? $recvInitials : 'OT'; } $amt = (float) ($cheque->amount ?? 0); $amtFig = $amt > 0 ? number_format($amt, 2) : ''; $words = $amt > 0 ? $pvAmountToWords($amt) : ''; [$w1, $w2] = $pvSplitTwoLines($words, 72); $clearDate = (string) ($cheque->clear_date ?? ''); $digits = ''; if ($clearDate !== '' && str_contains($clearDate, '-')) { [$yy, $mm, $dd] = array_pad(explode('-', $clearDate), 3, ''); $digits = str_pad($dd, 2, ' ', STR_PAD_LEFT).str_pad($mm, 2, ' ', STR_PAD_LEFT).str_pad($yy, 4, ' ', STR_PAD_LEFT); } $boxes = str_split(substr($digits, 0, 8)); $chequeNo = (string) ($cheque->cheque_no ?? ''); $chequeType = (string) ($cheque->cheque_type ?? 'crossed'); $cat = trim((string) ($cheque->category?->name ?? '')); $sub = trim((string) ($cheque->subcategory?->name ?? '')); $pvLocationLogoUrl = ''; if (!empty($currentLocation) && !empty($currentLocation->logo)) { $pvLocationLogoUrl = asset('storage/' . $currentLocation->logo); } $releaseDate = (string) ($cheque->clear_date ?? ''); $defaultClearAt = $releaseDate !== '' ? $releaseDate : now()->toDateString(); $noteBg = $direction === 'receive' ? 'bg-green-50' : 'bg-red-50'; $noteBorder = $direction === 'receive' ? 'border-green-200' : 'border-red-200'; $noteBadgeBg = $direction === 'receive' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'; $noteBadgeText = $direction === 'receive' ? 'RECEIVE' : 'ISSUE'; @endphp @if($mode === 'card')