/home/mjc1/public_html/emillennium/curl_send_soap_edit_process.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<?php header("Content-type:text/html;charset=utf-8"); ?>
<?php
    
/* 수정계산서시 넘어와야할 변수 */
    
$ChangeReason $_POST['ChangeReason'];
    
$ChangeBillAPPV $_POST['ChangeBillAPPV'];
    
$ChangeBillDate $_POST['ChangeBillDate'];
    
/* 수정계산서시 넘어와야할 변수 끝 */

    
$todaytime date("Y-m-d H:s:i"); //오늘날짜시간

    /*$ChangeReason = "01";
    $ChangeBillAPPV = "201608024100014110000006";
    $ChangeBillDate = "20160802110111";*/
    //print_r($_POST);
?>
<?php 
include("./_common.php"); ?>
<?php

$connect_tax    
= @mysql_connect($DB_HOSTtax,$DB_USERtax,$DB_PWDtax);
@
mysql_select_db$DB_NAMEtax,$connect_tax);    

//_pr($_POST); exit;

Require_once('./nusoap/lib/nusoap.php');

$m_nBillPubCodeCnt 0;
$ServiceProcess "DocumentService";
$tstamp date("Ymd_His",time());


function 
add_zero($v,$len){
    
$tmp "";
    for(
$i=$len;$i>strlen($v);$i--){
        
$tmp .= "0";
    }
    return 
$tmp.$v;
}

function 
CreateMessageID(){
    
$datetime date("YmdHis",time())."000-";
    
$rand32 "";
    for(
$i=0;$i<32;$i++){
        
$rand rand(1,15);
        if(
$rand<10){ $rand32.=$rand; }
        else {
            
$rand32.=dechex($rand);
        }
    }
    return 
$datetime.$rand32;

}

function 
make_SubmitID($biz_num=""){
    
$todaydate date("Ymd",time());
    
//if($biz_num==""){ $biz_num = "5021894746"; }
    
$rand23 "";
    for(
$i=0;$i<23;$i++){
        
$rand rand(1,15);
        if(
$rand<10){ $rand23.=$rand; }
        else {
            
$rand23.=dechex($rand);
        }
    }
    return 
$todaydate.$biz_num.$rand23;
}

function 
GetEBillPubCode($biz_num="",$sUserCode="00"){
    Global 
$m_nBillPubCodeCnt;
    Global 
$connect_tax;

    
$todaydatetime date("ymdHi",time());
    
//if($biz_num==""){ $biz_num = "5021894746"; }
    
$sUserCode $sUserCode// 사용자 코드

    
$pubcode $todaydatetime.$biz_num.$sUserCode;

    
$sql "select max(SRVC_BUSN_MGMT_NO) as num from tn_eaaa where SRVC_BUSN_MGMT_NO like '{$pubcode}%' ";
    
$res mysql_query($sql,$connect_tax);
    
$info mysql_fetch_array($res);

    if(
$info['num']!=''){
        
$pubcodeseq substr($info['num'],22,2);
        
$pubcodeseq = ($pubcodeseq*1)+1;
    } else {
        
$pubcodeseq $m_nBillPubCodeCnt+1;
    }
    
$newseq add_zero($pubcodeseq,2);

    return 
$todaydatetime.$biz_num.$sUserCode.$newseq;
}

if(
$ChangeReason!=''){
    if(
$ChangeBillAPPV==''){
        
$res_msg "error:5:변경코드는 있는데 변경원장 appv_no가 없습니다.";
        echo 
$res_msg; exit;
    }
}
$code $ChangeBillAPPV;
$code_dash substr($code,0,8)."-".substr($code,8,8)."-".substr($code,16,8);

if(
$code!=''){ 
    
$queryTax 
            
                    
" SELECT s.ETAXBIL_APPV_NO, s.BUSN_KND_CD, decode(s.BUSNID,'12345678') AS BUSNID, s.SUB_BD_NO, s.MAIN_TX_OFFCR_NM, s.MAIN_TX_OFFCR_TELNO, s.MAIN_TX_OFFCR_EMAIL_ADDR, s.BUSNSECT_NM, s.DETAIL_NM, decode(s.CHIEF_NM,'12345678') AS CHIEF_NM, decode(s.TRADE_NM,'12345678') AS TRADE_NM, s.ADDR, 
                    d.ETAXBIL_APPV_NO, decode(d.SUP_AMT_SM,'12345678') AS SUP_AMT_SM, decode(d.TX_SM,'12345678') AS TX_SM, decode(d.TOT_AMT,'12345678') AS TOT_AMT, d.ETAXBIL_NOTE, d.RCPT_RQEST_TP_CD, d.WRITE_DT, d.EMAIL_CHECK, d.SND_STATUS_CD, d.ETAXBIL_CL_CD,d.ETAXBIL_KND_CD, d.ETAXBIL_RVS_CS_CD, d.SRVC_BUSN_MGMT_NO,
                    d.ISU_DATE,
                    f.ETAXBIL_APPV_NO, f.THNG_SEQNO, f.THNG_PURCHS_DT,  f.THNG_NM, f.THNG_STNDRD_NM, REPLACE(FORMAT(f.THNG_QTY,2),'.00','') AS THNG_QTY, REPLACE(FORMAT(f.THNG_UNTPC,2),'.00','') AS THNG_UNTPC, decode(f.THNG_SUP_AMT,'12345678') AS THNG_SUP_AMT, decode(f.THNG_TX,'12345678') AS THNG_TX, f.THNG_NOTE, d.ORG_ETAXBIL_APPV_NO
                    FROM
                    (tn_eaaa AS d LEFT JOIN tn_eaab AS s ON (s.ETAXBIL_APPV_NO = d.ETAXBIL_APPV_NO) LEFT JOIN 
                    tn_eaac AS f ON d.ETAXBIL_APPV_NO = f.ETAXBIL_APPV_NO)
                    WHERE s.ETAXBIL_APPV_NO = '
$code'";
    
//echo $queryTax;    exit;
    
$res mysql_query($queryTax,$connect_tax);
    
$rowcnt 0;
    
$ov_cnt 0$ov_qty 0$ov_amt 0$ov_vat 0;
    while(
$rowTax=mysql_fetch_array($res)){
        if(
$rowTax[BUSN_KND_CD] == "01"){
            if(
$rowcnt>4){
                
$ov_cnt++;
                
$ov_qty += $rowTax['THNG_QTY'];
                
$ov_amt += $rowTax['THNG_SUP_AMT'];
                
$ov_vat += $rowTax['THNG_TX'];
                
$rowcnt++;
                continue;
            }
            
$rowcnt++;
        }
        
$rowTax array_utf8($rowTax);
        
$idx $rowTax[ETAXBIL_APPV_NO];
        
$srvcode $rowTax[SRVC_BUSN_MGMT_NO];
        
$isudate $rowTax[ISU_DATE];
        
$emailCheck        $rowTax[EMAIL_CHECK];

        
$taxtype        $rowTax[ETAXBIL_CL_CD];    //일반 면세 구분
        
$taxtype2        $rowTax[ETAXBIL_KND_CD];    //일반:01 영세:02 구분
        
$tax_type $taxtype.$taxtype2;

        
$SndCheck        $rowTax[SND_STATUS_CD];

        
$Volume         $rowTax[ETAXBIL_APPV_NO];    //승인번호
        
$SerialNum      ;    //일련번호

        
if($ChangeReason=='04' || $ChangeReason=='06' || $ChangeReason=='03' || $ChangeReason=='01'){ // 04:계약의 해제, 06:이중발행 정정, 03:환입 01:기재사항 착오는 첫번째 부(-)계산서 보여주기용
            
$offerPrice $rowTax[SUP_AMT_SM]*-1;    //공급가액
            
$billprice $rowTax[TX_SM]*-1;    //세액
            
$rowTax[THNG_QTY] = $rowTax[THNG_QTY]*-1;
            
$rowTax[THNG_SUP_AMT] = $rowTax[THNG_SUP_AMT]*-1;
            
$rowTax[THNG_TX] = $rowTax[THNG_TX]*-1;
            
$totalPrice     number_format($rowTax[TOT_AMT]*-1);    //합계금액
            
            
if($ChangeReason=='04'){
                
$etxbil_note "당초 작성일자 ($WRITE_DT) 당초 승인번호($code_dash) 수정사유:계약의 해제";
            } else if(
$ChangeReason=='06'){
                
$etxbil_note "당초 승인번호($code_dash) 수정사유:이중발행 정정";
            } else if(
$ChangeReason=='03'){
                
$etxbil_note "당초 작성일자 ($WRITE_DT) 당초 승인번호($code_dash) 수정사유:환입";
            } else if(
$ChangeReason=='01'){
                
$etxbil_note "당초 승인번호($code_dash) 수정사유:기재사항 착오 정정용 부(-)계산서";
            }
        } else {
            
$offerPrice $rowTax[SUP_AMT_SM];    //공급가액
            
$billprice $rowTax[TX_SM];    //세액
            
$totalPrice     number_format($rowTax[TOT_AMT]);    //합계금액

            
if($ChangeReason=='02'){
                
$etxbil_note "당초 승인번호($code_dash) 수정사유:공급가액 변동";
            }
        }

        
$rowTax[THNG_UNTPC] = number_change($rowTax[THNG_UNTPC]);

        if(
$rowTax[BUSN_KND_CD] == "01"){
            
$rowTaxArray[] = $rowTax;
            
$sCompanyNum1    $rowTax[BUSNID];            //사업자번호
            
$sCompanyNum     substr($sCompanyNum1 03) ."-"substr($sCompanyNum1 32) ."-"substr($sCompanyNum1 55);
            
$sCompanySubNum $rowTax[SUB_BD_NO];        //종사업장번호
            
            //도장 
            
$sCompanyNumimg1 $rowTax[BUSNID]; 
            
//공급자 사업자번호 변환
            
$sCompanyNumimg2=substr($sCompanyNumimg1 03) ."-"substr($sCompanyNumimg1 32) ."-"substr($sCompanyNumimg1 55);
            
$sCompanyNumimg=$sCompanyNumimg2.".gif";    //도장이미지


            //담당자 정보
            
$sOFFCR            $rowTax[MAIN_TX_OFFCR_NM];
            
$sOFFPN            $rowTax[MAIN_TX_OFFCR_TELNO];
            
$sOFFEM            $rowTax[MAIN_TX_OFFCR_EMAIL_ADDR];

            
$sCompanyNname  $rowTax[TRADE_NM];    //상호
            
$sChiefName     $rowTax[CHIEF_NM];        //성명
            
$sCompanyAddr   $rowTax[ADDR];    //주소
            
$sUptae         $rowTax[BUSNSECT_NM];            //업태
            
$sJongmok       $rowTax[DETAIL_NM];        //종목
        
} else if($rowTax[BUSN_KND_CD] == "02"){
            
//담당자 정보
            
$rOFFCR            $rowTax[MAIN_TX_OFFCR_NM];
            
$rOFFPN            $rowTax[MAIN_TX_OFFCR_TELNO];
            
$rOFFEM            $rowTax[MAIN_TX_OFFCR_EMAIL_ADDR];


            
$rCompanyNum1    $rowTax[BUSNID];            //사업자번호
            
$rCompanyNum     substr($rCompanyNum1 03) ."-"substr($rCompanyNum1 32) ."-"substr($rCompanyNum1 55);
            
$rCompanySubNum $rowTax[SUB_BD_NO];        //종사업장번호
            
$rCompanyNname  $rowTax[TRADE_NM];    //상호
            
$rChiefName     $rowTax[CHIEF_NM];        //성명
            
$rCompanyAddr   $rowTax[ADDR];    //주소
            
$rUptae         $rowTax[BUSNSECT_NM];            //업태
            
$rJongmok       $rowTax[DETAIL_NM];        //종목
        
}

        
$blankNum       11 strlen($rowTax[SUP_AMT_SM]);                //공란수
        
$sumNum       strlen($rowTax[SUP_AMT_SM]);            //공급가액자리수
        
$billnum      strlen($rowTax[TX_SM]);                //세액자리수
        
$bigo            $rowTax[ETAXBIL_NOTE];    //총 비고

        
$year           substr($rowTax[WRITE_DT],0,4);    //년
        
$month          substr($rowTax[WRITE_DT],4,2);    //월
        
$day            substr($rowTax[WRITE_DT],6,2);    //일
        
$WRITE_DT $rowTax[WRITE_DT];

        
$cash           number_format($rowTax[cash]);            //현금
        
$checkPrice     number_format($rowTax[checkPrice]);    //수표
        
$bill           number_format($rowTax[bill]);            //어음
        
$onCredit       number_format($rowTax[onCredit]);        //외상미수금

        
if ($rowTax[RCPT_RQEST_TP_CD] == "01") {
            
$irecved "영수";
        } else if (
$rowTax[RCPT_RQEST_TP_CD] == "02"){
            
$irecved "청구";
        }
        
$RCPT_RQEST_TP_CD $rowTax[RCPT_RQEST_TP_CD];

        
$ORG_ETAXBIL_APPV_NO $rowTax['ORG_ETAXBIL_APPV_NO'];
    }

    
//_pr($rowTaxArray);

    
if($rowcnt>5){
        
$rowTaxArray[4]['THNG_NM'] = $rowTaxArray[4]['THNG_NM']."외 {$ov_cnt}건";
        
$rowTaxArray[4]['THNG_STNDRD_NM'] = "";
        
$rowTaxArray[4]['THNG_UNTPC'] = 0;
        if(
$ChangeReason=='04' || $ChangeReason=='06' || $ChangeReason=='03' || $ChangeReason=='01'){ // 04:계약의 해제, 06:이중발행 정정, 03:환입 01:기재사항 착오는 첫번째 부(-)계산서 보여주기용
            
$rowTaxArray[4]['THNG_QTY'] = $rowTaxArray[4]['THNG_QTY']-$ov_qty;
            
$rowTaxArray[4]['THNG_SUP_AMT'] = $rowTaxArray[4]['THNG_SUP_AMT']-$ov_amt;
            
$rowTaxArray[4]['THNG_TX'] = $rowTaxArray[4]['THNG_TX']-$ov_vat;
        }
    }
// end if($code)

if($idx!=''){
    if(
$tax_type=='0101'){ $tax_type1='02'$tax_type2='01'; } // 일반과세
    
if($tax_type=='0102'){ $tax_type1='02'$tax_type2='02'; } // 영세
    
if($tax_type=='0301'){ $tax_type1='04'$tax_type2='01'; } // 면세

/* 변수 정리 구간 */
    
$SubmitID  make_SubmitID($sCompanyNum1);
    
$iCount 1;
    
$PubCode GetEBillPubCode($sCompanyNum1);
    
$IssueDateTime1 date("YmdHis",time()); ; // 발행일자
    
if($rSMScheck=='on'){
        
$m_sAppcode "160704000200T"// 뭔지모르겠음 SMSSend보내기 "T", "F"
    
} else {
        
$m_sAppcode "160704000200F"// 뭔지모르겠음 SMSSend보내기 "T", "F"
    
}
    
$IssueStatus "S"//발행초기값: I-무시, S-발행
    
$debud_mode "Y"// 삭제 재발행모드를 위해서 I 모드로 기본으로 가기로 함
    
if($debud_mode=="Y"){ // 개발자 모드에서는 국세청에 전송하지 않습니다.
        
$SendStatus "I"//국세청 전송 초기값: I-무시, S-전송
    
} else {
        
$SendStatus "S";
    }
    
$SendEmail "N"//이메일 전송 초기값: Y-무시, N-전송 (코드값과 의미가 반대임을 주의)
    
$DescriptionText $etxbil_note// 수정사유 비고

    
$DescriptionText_xml "";
    if(
$DescriptionText!=''){
        
$DescriptionText_xml "<DescriptionText>{$DescriptionText}</DescriptionText>";
    }
    if(
$ChangeReason!=''){
        
$AmendmentStatusCode_xml "<AmendmentStatusCode>{$ChangeReason}</AmendmentStatusCode>";
        
$OriginalIssueID_xml "<OriginalIssueID>{$ChangeBillAPPV}</OriginalIssueID>";
    }
    if(
$ChangeReason=='04' || $ChangeReason=='06' || $ChangeReason=='03'){ // 04:계약의 해제, 06:이중발행 정정, 03:환입
        
$IssueDateTime2 $WRITE_DT// 작성일자
    
} else {
        
$IssueDateTime2 $WRITE_DT// 작성일자
    
}
    
$TaxType $tax_type1.$tax_type2//01,02 과세 03,04 면세 그리고 4자리 되어야함 0101 db select 시엔 tn_eaaa테이블의 ETAXBIL_CL_CD필드와 ETAXBIL_KND_CD의 합임..2자리식 4자리
    
$DemandTag $RCPT_RQEST_TP_CD// 01 영수, 02 청구 구분

    
$sCompanyNum $sCompanyNum1//"5021894746";
    
$sCompanyName $sCompanyNname//"MJSOFT";
    
$sChiefName $sChiefName//"박성원";
    
$sPerson $sOFFCR    //"박성원";
    
$sEmail $sOFFEM//"ryunen@chol.com";
    
$sPhone $sOFFPN//"010";
    
$sCompanyAddr $sCompanyAddr//"서울 송파구 오금동 46-9";
    
$sUptae $sUptae//"도소매";
    
$sJongmok $sJongmok//"일반의약품";

    
$rCompanyNum $rCompanyNum1//"5021894746";
    
$rCompanyName $rCompanyNname//"미진유통";
    
$rChiefName $rChiefName//"이미진";
    
$rPerson $rOFFCR//"박성원";
    
$rEmail $rOFFEM//"ryunen@chol.com";
    
$rPhone $rOFFPN//"010-9357-0525";
    
$rCompanyAddr $rCompanyAddr//"서울 강동구 천호3동 223-3334445";
    
$rUptae $rUptae//"도소매2";
    
$rJongmok $rJongmok//"일반의약품2";

    
$BusinessTypeCode "01"// 01(사업자등록번호),02(주민등록번호), 03(외국인)

    
$totalprice $offerPrice;
    
//면세(일반 계산서)와 수정 계산서의 경우에는 세액합계를 표기하지 않음
    
if($TaxType=='0101' || $TaxType=='0201'){
        
$totaltax $billprice;
    } else {
        
$totaltax 0;
    }
    
$sumprice number_change($totalPrice);

    
$item_xml "";
    for(
$i=0;$i<count($rowTaxArray);$i++){
        
$rowTax $rowTaxArray[$i];
        
$seqnum $i+1;
        
$item_xml .= "<TaxInvoiceTradeLineItem>
                            <SequenceNumeric>
{$seqnum}</SequenceNumeric>
                            <InvoiceAmount>
{$rowTax[THNG_SUP_AMT]}</InvoiceAmount>
                            <ChargeableUnitQuantity>
{$rowTax[THNG_QTY]}</ChargeableUnitQuantity>
                            <NameText>
{$rowTax[THNG_NM]}</NameText>
                            <InformationText>
{$rowTax[THNG_STNDRD_NM]}</InformationText>
                            <PurchaseExpiryDateTime>
{$rowTax[THNG_PURCHS_DT]}</PurchaseExpiryDateTime>
                            <DescriptionText>
{$rowTax[THNG_NOTE]}</DescriptionText>
                            <TotalTax>
                                <CalculatedAmount>
{$rowTax[THNG_TX]}</CalculatedAmount>
                            </TotalTax>
                            <UnitPrice>
                                <UnitAmount>
{$rowTax[THNG_UNTPC]}</UnitAmount>
                            </UnitPrice>
                        </TaxInvoiceTradeLineItem>"
;
    }
/* 변수 정리 구간 끝 */

/* XML 입력 구간 */

                        //$body_string = <<<XML
                        
$body_string "
                            <SubmitID>
{$SubmitID}</SubmitID>
                            <TotalCount>
{$iCount}</TotalCount>
                            <Document>
                                <TaxInvoice>
                                    <ExchangedDocument>
                                        <ID>
{$PubCode}</ID>
                                        <IssueDateTime>
{$IssueDateTime1}</IssueDateTime>
                                        <ReferencedDocument>
                                            <ID>
{$m_sAppcode}</ID>
                                        </ReferencedDocument>
                                        <IssueStatus>
{$IssueStatus}</IssueStatus>
                                        <SendStatus>
{$SendStatus}</SendStatus>
                                        <SendEmail>
{$SendEmail}</SendEmail>
                                    </ExchangedDocument>
                                    <TaxInvoiceDocument>
                                        <IssueID/>
                                        <TypeCode>
{$TaxType}</TypeCode>
                                        
{$DescriptionText_xml}
                                        <IssueDateTime>
{$IssueDateTime2}</IssueDateTime>
                                        
{$AmendmentStatusCode_xml}
                                        
{$OriginalIssueID_xml}
                                        <PurposeCode>
{$DemandTag}</PurposeCode>
                                    </TaxInvoiceDocument>
                                    <TaxInvoiceTradeSettlement>
                                        <InvoicerParty>
                                            <ID>
{$sCompanyNum}</ID>
                                            <TypeCode>
{$sUptae}</TypeCode>
                                            <NameText>
{$sCompanyName}</NameText>
                                            <ClassificationCode>
{$sJongmok}</ClassificationCode>
                                            <SpecifiedOrganization>
                                                <TaxRegistrationID/>
                                            </SpecifiedOrganization>
                                            <SpecifiedPerson>
                                                <NameText>
{$sChiefName}</NameText>
                                            </SpecifiedPerson>
                                            <DefinedContact>
                                                <PersonNameText>
{$sPerson}</PersonNameText>
                                                <TelephoneCommunication>
{$sPhone}</TelephoneCommunication>
                                                <URICommunication>
{$sEmail}</URICommunication>
                                            </DefinedContact>
                                            <SpecifiedAddress>
                                                <LineOneText>
{$sCompanyAddr}</LineOneText>
                                            </SpecifiedAddress>
                                        </InvoicerParty>
                                        <InvoiceeParty>
                                            <ID>
{$rCompanyNum}</ID>
                                            <TypeCode>
{$rUptae}</TypeCode>
                                            <NameText>
{$rCompanyName}</NameText>
                                            <ClassificationCode>
{$rJongmok}</ClassificationCode>
                                            <SpecifiedOrganization>
                                                <TaxRegistrationID/>
                                                <BusinessTypeCode>
{$BusinessTypeCode}</BusinessTypeCode>
                                            </SpecifiedOrganization>
                                            <SpecifiedPerson>
                                                <NameText>
{$rChiefName}</NameText>
                                            </SpecifiedPerson>
                                            <PrimaryDefinedContact>
                                                <PersonNameText>
{$rPerson}</PersonNameText>
                                                <TelephoneCommunication>
{$rPhone}</TelephoneCommunication>
                                                <URICommunication>
{$rEmail}</URICommunication>
                                            </PrimaryDefinedContact>
                                            <SpecifiedAddress>
                                                <LineOneText>
{$rCompanyAddr}</LineOneText>
                                            </SpecifiedAddress>
                                        </InvoiceeParty>
                                        <SpecifiedMonetarySummation>
                                            <ChargeTotalAmount>
{$totalprice}</ChargeTotalAmount>
                                            <TaxTotalAmount>
{$totaltax}</TaxTotalAmount>
                                            <GrandTotalAmount>
{$sumprice}</GrandTotalAmount>
                                        </SpecifiedMonetarySummation>
                                    </TaxInvoiceTradeSettlement>
                                    
{$item_xml}
                                </TaxInvoice>
                            </Document>
                            "
;
    
//                    XML;

    /* XML 입력 구간 끝 */

    
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
    
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
    
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
    
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
    
$useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
    
$client = new nusoap_client("http://{$DB_HOSTtax}:7000/axis2/services/{$ServiceProcess}"false,
                            
$proxyhost$proxyport$proxyusername$proxypassword);
    
$err $client->getError();
    if (
$err) {
        echo 
'<h2>Constructor error</h2><pre>' $err '</pre>';
        echo 
'<h2>Debug</h2><pre>' htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
        exit();
    }
    
$client->setUseCurl($useCURL);

    
$MessageID CreateMessageID(); // "20160727171205000-d60512a264a907ecae38ebe53cd7df1e";
    
$TimeStamp date("Y-m-d",time())."T".date("H:i:s")."000Z";
    
$headers "
        <wsa:MessageID>
{$MessageID}</wsa:MessageID>
        <wsa:To>http://
{$DB_HOSTtax}:7000/axis2/services/{$ServiceProcess}</wsa:To>
        <wsa:Action>http://soap.openet.com</wsa:Action>
        <MessageHeader>
        <Version>3.0</Version>
        <From>
            <PartyID>1208646911</PartyID>
            <PartyName>미진소프트</PartyName>
        </From>
        <To>
            <PartyID>1234567890</PartyID>
            <PartyName>TestBed</PartyName>
        </To>
        <ReplyTo>http://220.90.215.20:7000/axis2/services/TaxService</ReplyTo>
        <OperationType>01</OperationType>
        <MessageType>01</MessageType>
        <TimeStamp>
{$TimeStamp}</TimeStamp>
        </MessageHeader>
    "


    
//echo "<textarea>";    echo $headers;    echo "</textarea>";
    
$xml_cont $headers.$body_string;
    
    
// 생성한 xml 로그
    
$xml_file_name $eid."_{$code}_make_{$tstamp}.xml";
    
xml_file_log($code.":".$xml_cont,$xml_file_name);

    
//exit;

    
$client->setHeaders($headers); 
    
$client->soap_defencoding "utf-8";
    
$client->decode_utf8 false;

    
$params $body_string// object 배열로 던지거나 xml스트링으로 던져도 됨

    
$result $client->call('RequestMessage'$params'''');
    if (
$client->fault) {
        
//echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>'; print_r($result); echo '</pre>';
    
} else {
        
$err $client->getError();
        if (
$err) {
            
//echo '<h2>Error</h2><pre>' . $err . '</pre>';
        
} else {
            
//echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
            
if($result['ReturnCode']=='01'){
                
$v explode("|",$result['ResponseMsg']);
                
$resmsg trim($v[0]);
                
$mgmt_no substr($resmsg,0,24);
                
$appv_no substr($resmsg,24,24);
                
/*$sql = "update taxlist set etax = '{$appv_no}' where code = '{$tax_code}' ";
                $res = mysql_query($sql,$connect_ezbill);*/

                
$res_msg "ok:$code:$appv_no";

                
// 포인트 차감
                
$usepoint "150";
                
$usetype "1";
                
$pointbigo iconv("UTF-8","EUCKR",$rCompanyName);

                
$pisql "INSERT INTO cash_use ( cust_id, rgst_dtm, usepoint, use_type, use_fkey, bigo )
                          VALUE ( '
$eid', '$todaytime', '$usepoint', '$usetype', '$mgmt_no', '$pointbigo' )";
                
mysql_query($pisql,$connect_cash);

                
$sCompany iconv("UTF-8","EUCKR",$sCompanyName);
                
// 웹 이지텍스용 로그
                
$sql "insert into easytax_web_log set
                            user_id = '
{$eid}', use_point = '{$usepoint}', appv_no = '{$appv_no}', 
                            mgmt_no = '
{$mgmt_no}', sCompany = '{$sCompany}', rCompany = '{$pointbigo}',  sCompnum = '{$sCompanyNum}', rCompnum = '{$rCompanyNum}', 
                            rgst_dtm = '
{$todaytime}',    server = '{$DB_HOSTtax}'
                "
;
                
//echo $sql;
                
mysql_query($sql,$connect_web);

                
$sql "insert into tn_eaaa_mjdata set
                            ETAXBIL_APPV_NO = '
{$appv_no}', PC_IP = '{$_SERVER['REMOTE_ADDR']}', PC_MAC = '', 
                            PC_NAME = '
{$eid}', APP_CODE = '80', APP_VER = '1.0'
                "
;
                
$res mysql_query($sql,$connect_tax);

            } else {
                
$ResponseMsg iconv_euckr($result['ResponseMsg']);
                
$res_msg "error:9:$ResponseMsg";    
            }
        }
    }
    
    
// soap에 request된 xml 로그
    
$xml_file_name $eid."_{$code}_make_req_{$tstamp}.xml";
    
xml_file_log($client->request,$xml_file_name);

    
// soap에서 response된 xml 로그
    
$xml_file_name $eid."_{$code}_make_res_{$tstamp}.xml";
    
xml_file_log($client->response,$xml_file_name);

} else {
    
$res_msg "error:1:해당 DB가 존재하지 않습니다.";
}

@
mysql_close($connect_tax);

echo 
$res_msg; exit;
?>