style: Pint 포맷팅 적용

This commit is contained in:
김보곤
2026-02-25 11:45:01 +09:00
parent 68b1622a4e
commit 9a7c548246
199 changed files with 1420 additions and 1083 deletions

View File

@@ -21,9 +21,13 @@ class EtaxController extends Controller
* 바로빌 SOAP 설정
*/
private ?string $certKey = null;
private ?string $corpNum = null;
private bool $isTestMode = false;
private ?string $soapUrl = null;
private ?\SoapClient $soapClient = null;
public function __construct()
@@ -35,7 +39,7 @@ public function __construct()
$this->certKey = $activeConfig->cert_key;
$this->corpNum = $activeConfig->corp_num;
$this->isTestMode = $activeConfig->environment === 'test';
$this->soapUrl = $activeConfig->base_url . '/TI.asmx?WSDL';
$this->soapUrl = $activeConfig->base_url.'/TI.asmx?WSDL';
} else {
// 설정이 없으면 기본값 사용
$this->isTestMode = config('services.barobill.test_mode', true);
@@ -57,14 +61,14 @@ public function __construct()
*/
private function initSoapClient(): void
{
if (!empty($this->certKey) || $this->isTestMode) {
if (! empty($this->certKey) || $this->isTestMode) {
try {
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
'allow_self_signed' => true,
],
]);
$this->soapClient = new \SoapClient($this->soapUrl, [
@@ -73,10 +77,10 @@ private function initSoapClient(): void
'exceptions' => true,
'connection_timeout' => 30,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
'cache_wsdl' => WSDL_CACHE_NONE,
]);
} catch (\Throwable $e) {
Log::error('바로빌 SOAP 클라이언트 생성 실패: ' . $e->getMessage());
Log::error('바로빌 SOAP 클라이언트 생성 실패: '.$e->getMessage());
}
}
}
@@ -135,14 +139,14 @@ private function applyMemberServerMode(BarobillMember $member): void
$baseUrl = $config->base_url ?: ($memberTestMode
? 'https://testws.baroservice.com'
: 'https://ws.baroservice.com');
$this->soapUrl = $baseUrl . '/TI.asmx?WSDL';
$this->soapUrl = $baseUrl.'/TI.asmx?WSDL';
// SOAP 클라이언트 재초기화
$this->initSoapClient();
Log::info('[Etax] 서버 모드 적용', [
'targetEnv' => $targetEnv,
'certKey' => substr($this->certKey ?? '', 0, 10) . '...',
'certKey' => substr($this->certKey ?? '', 0, 10).'...',
'corpNum' => $this->corpNum,
'soapUrl' => $this->soapUrl,
]);
@@ -173,7 +177,7 @@ public function getInvoices(): JsonResponse
$allInvoices = $data['invoices'] ?? [];
// 본사(테넌트 1)가 아니면 해당 테넌트의 세금계산서만 필터링
if (!$isHeadquarters && $tenantId) {
if (! $isHeadquarters && $tenantId) {
$invoices = array_values(array_filter($allInvoices, function ($invoice) use ($tenantId) {
return ($invoice['tenant_id'] ?? null) == $tenantId;
}));
@@ -204,12 +208,12 @@ public function issue(Request $request): JsonResponse
$input = $request->all();
$useRealAPI = $this->soapClient !== null && ($this->isTestMode || !empty($this->certKey));
$useRealAPI = $this->soapClient !== null && ($this->isTestMode || ! empty($this->certKey));
$debugInfo = [
'hasSoapClient' => $this->soapClient !== null,
'hasCertKey' => !empty($this->certKey),
'hasCorpNum' => !empty($this->corpNum),
'hasCertKey' => ! empty($this->certKey),
'hasCorpNum' => ! empty($this->corpNum),
'isTestMode' => $this->isTestMode,
'willUseRealAPI' => $useRealAPI,
];
@@ -218,7 +222,7 @@ public function issue(Request $request): JsonResponse
$apiResult = $this->issueTaxInvoice($input);
if ($apiResult['success']) {
$mgtKey = $input['issueKey'] ?? 'MGT' . date('YmdHis') . rand(1000, 9999);
$mgtKey = $input['issueKey'] ?? 'MGT'.date('YmdHis').rand(1000, 9999);
$newInvoice = $this->createInvoiceRecord($input, $mgtKey, $apiResult['data'] ?? null);
$this->saveInvoice($newInvoice);
@@ -245,7 +249,7 @@ public function issue(Request $request): JsonResponse
}
} else {
// 시뮬레이션 모드
$issueKey = 'BARO-' . date('Y') . '-' . str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT);
$issueKey = 'BARO-'.date('Y').'-'.str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT);
$newInvoice = $this->createInvoiceRecord($input, $issueKey, null);
$this->saveInvoice($newInvoice);
@@ -293,16 +297,16 @@ public function sendToNts(Request $request): JsonResponse
}
}
if (!$invoice) {
if (! $invoice) {
return response()->json([
'success' => false,
'error' => '세금계산서를 찾을 수 없습니다.',
], 404);
}
$useRealAPI = $this->soapClient !== null && !empty($this->certKey);
$useRealAPI = $this->soapClient !== null && ! empty($this->certKey);
if ($useRealAPI && !empty($invoice['mgtKey'])) {
if ($useRealAPI && ! empty($invoice['mgtKey'])) {
$result = $this->callBarobillSOAP('SendToNTS', [
'CorpNum' => $this->corpNum,
'MgtKey' => $invoice['mgtKey'],
@@ -310,7 +314,7 @@ public function sendToNts(Request $request): JsonResponse
if ($result['success']) {
$data['invoices'][$invoiceIndex]['status'] = 'sent';
$data['invoices'][$invoiceIndex]['ntsReceiptNo'] = 'NTS-' . date('YmdHis');
$data['invoices'][$invoiceIndex]['ntsReceiptNo'] = 'NTS-'.date('YmdHis');
$data['invoices'][$invoiceIndex]['sentAt'] = date('Y-m-d');
file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
@@ -327,7 +331,7 @@ public function sendToNts(Request $request): JsonResponse
} else {
// 시뮬레이션
$data['invoices'][$invoiceIndex]['status'] = 'sent';
$data['invoices'][$invoiceIndex]['ntsReceiptNo'] = 'NTS-SIM-' . date('YmdHis');
$data['invoices'][$invoiceIndex]['ntsReceiptNo'] = 'NTS-SIM-'.date('YmdHis');
$data['invoices'][$invoiceIndex]['sentAt'] = date('Y-m-d');
file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
@@ -345,12 +349,12 @@ public function sendToNts(Request $request): JsonResponse
public function getSupplier(): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return response()->json(['success' => false, 'error' => '테넌트가 선택되지 않았습니다.'], 400);
}
$member = BarobillMember::where('tenant_id', $tenantId)->first();
if (!$member) {
if (! $member) {
return response()->json(['success' => false, 'error' => '바로빌 회원사 정보가 없습니다.'], 404);
}
@@ -376,12 +380,12 @@ public function getSupplier(): JsonResponse
public function updateSupplier(Request $request): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (!$tenantId) {
if (! $tenantId) {
return response()->json(['success' => false, 'error' => '테넌트가 선택되지 않았습니다.'], 400);
}
$member = BarobillMember::where('tenant_id', $tenantId)->first();
if (!$member) {
if (! $member) {
return response()->json(['success' => false, 'error' => '바로빌 회원사 정보가 없습니다.'], 404);
}
@@ -424,7 +428,7 @@ public function delete(Request $request): JsonResponse
$dataFile = storage_path('app/barobill/invoices_data.json');
if (!file_exists($dataFile)) {
if (! file_exists($dataFile)) {
return response()->json([
'success' => false,
'error' => '데이터 파일이 없습니다.',
@@ -434,7 +438,7 @@ public function delete(Request $request): JsonResponse
$data = json_decode(file_get_contents($dataFile), true) ?? ['invoices' => []];
$originalCount = count($data['invoices']);
$data['invoices'] = array_values(array_filter($data['invoices'], fn($inv) => $inv['id'] !== $invoiceId));
$data['invoices'] = array_values(array_filter($data['invoices'], fn ($inv) => $inv['id'] !== $invoiceId));
if (count($data['invoices']) === $originalCount) {
return response()->json([
@@ -456,20 +460,20 @@ public function delete(Request $request): JsonResponse
*/
private function callBarobillSOAP(string $method, array $params = []): array
{
if (!$this->soapClient) {
if (! $this->soapClient) {
return [
'success' => false,
'error' => '바로빌 SOAP 클라이언트가 초기화되지 않았습니다.',
];
}
if (!isset($params['CERTKEY'])) {
if (! isset($params['CERTKEY'])) {
$params['CERTKEY'] = $this->certKey;
}
try {
$result = $this->soapClient->$method($params);
$resultProperty = $method . 'Result';
$resultProperty = $method.'Result';
if (isset($result->$resultProperty)) {
$resultData = $result->$resultProperty;
@@ -477,7 +481,7 @@ private function callBarobillSOAP(string $method, array $params = []): array
if (is_numeric($resultData) && $resultData < 0) {
return [
'success' => false,
'error' => '바로빌 API 오류 코드: ' . $resultData,
'error' => '바로빌 API 오류 코드: '.$resultData,
'error_code' => $resultData,
];
}
@@ -495,12 +499,12 @@ private function callBarobillSOAP(string $method, array $params = []): array
} catch (\SoapFault $e) {
return [
'success' => false,
'error' => 'SOAP 오류: ' . $e->getMessage(),
'error' => 'SOAP 오류: '.$e->getMessage(),
];
} catch (\Throwable $e) {
return [
'success' => false,
'error' => 'API 호출 오류: ' . $e->getMessage(),
'error' => 'API 호출 오류: '.$e->getMessage(),
];
}
}
@@ -510,7 +514,7 @@ private function callBarobillSOAP(string $method, array $params = []): array
*/
private function issueTaxInvoice(array $invoiceData): array
{
$mgtKey = $invoiceData['issueKey'] ?? 'MGT' . date('YmdHis') . rand(1000, 9999);
$mgtKey = $invoiceData['issueKey'] ?? 'MGT'.date('YmdHis').rand(1000, 9999);
$supplyAmt = 0;
$vat = 0;
@@ -583,7 +587,7 @@ private function issueTaxInvoice(array $invoiceData): array
$month = str_pad($item['month'] ?? '', 2, '0', STR_PAD_LEFT);
$day = str_pad($item['day'] ?? '', 2, '0', STR_PAD_LEFT);
$purchaseExpiry = ($month && $day && $month !== '00' && $day !== '00')
? $year . $month . $day
? $year.$month.$day
: '';
$taxInvoice['TaxInvoiceTradeLineItems']['TaxInvoiceTradeLineItem'][] = [
@@ -613,7 +617,7 @@ private function issueTaxInvoice(array $invoiceData): array
private function createInvoiceRecord(array $input, string $issueKey, $apiData): array
{
return [
'id' => 'inv_' . time() . '_' . rand(1000, 9999),
'id' => 'inv_'.time().'_'.rand(1000, 9999),
'tenant_id' => session('selected_tenant_id'), // 테넌트별 필터링용
'issueKey' => $issueKey,
'mgtKey' => $issueKey,
@@ -638,7 +642,7 @@ private function createInvoiceRecord(array $input, string $issueKey, $apiData):
'memo' => $input['memo'] ?? '',
'createdAt' => date('Y-m-d\TH:i:s'),
'sentAt' => date('Y-m-d'),
'barobillInvoiceId' => is_numeric($apiData) ? (string)$apiData : '',
'barobillInvoiceId' => is_numeric($apiData) ? (string) $apiData : '',
];
}
@@ -648,11 +652,11 @@ private function createInvoiceRecord(array $input, string $issueKey, $apiData):
private function saveInvoice(array $invoice): bool
{
$dataDir = storage_path('app/barobill');
if (!is_dir($dataDir)) {
if (! is_dir($dataDir)) {
mkdir($dataDir, 0755, true);
}
$dataFile = $dataDir . '/invoices_data.json';
$dataFile = $dataDir.'/invoices_data.json';
$existingData = ['invoices' => []];
if (file_exists($dataFile)) {