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
|
<?php $dir = "."; include_once($dir."/_common.php");
$mode_ok = "Y";
if($eid==''){ $mode = "x"; $mode_ok = "N"; $msg = "e천년경영 로그인 후에 이용가능합니다."; }
@extract($_POST);
$todaytime = date("Y-m-d H:s:i"); //오늘날짜시간 $midx_list = stripslashes($midx_list);
$all_sql = ""; $tax_midx_list = ""; $ccode_list = "";
if($smode=='comp'){ // 내부발행된 데이터를 국세청 발행할때 $sql = "select count(*) as cnt from (select a.ccode, b.tax_type from sale_m a left join sale_d b on a.midx = b.midx where {$midx_list} ) c where 1=1 group by ccode, tax_type"; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; while($info = mysql_fetch_array($res)){ // 항목이 99개 넘는지 체크 if($info['cnt']>99){ $mode_ok = "N"; $msg = "거래처, 세금 구분별 항목이 99개를 넘을수 없습니다."; } }
if($mode_ok=='Y'){ $sql = "select distinct a.ccode, a.midx from sale_tax_m a left join sale_tax_d b on a.midx = b.midx where {$midx_list} "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; while($info = mysql_fetch_array($res)){ $tax_midx_list .= "{$info['midx']},"; // 국세청 전송위해서 처리한 리스트 midx를 저장한다. $ccode_list .= "{$info['ccode']},"; // 국세청 전송위한 거래처코드 저장 } } } if($sendmode=='direct' || $sendmode=='nts'){ // 내부발행 및 국세청발행시 DB는 동일 처리 $mode = "direct"; if($sel_mode=='detail'){ // 상세일때 내부저장
$sql = "select count(*) as cnt from (select a.ccode, b.tax_type from sale_m a left join sale_d b on a.midx = b.midx where {$midx_list} ) c where 1=1 group by ccode, tax_type"; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; while($info = mysql_fetch_array($res)){ // 항목이 99개 넘는지 체크 if($info['cnt']>99){ $mode_ok = "N"; $msg = "거래처, 세금 구분별 항목이 99개를 넘을수 없습니다."; } }
if($mode_ok=='Y'){ $sql = "select a.ccode, b.tax_type from sale_d b left join sale_m a on a.midx = b.midx where {$midx_list} group by a.ccode, b.tax_type order by a.ccode, b.tax_type"; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; while($info = mysql_fetch_array($res)){ // 거래처별 세금구분별로 페이지 처리용 $ct_array[] = $info; } foreach($ct_array as $key=>$row){ $ccode = $row['ccode']; $tax_type = $row['tax_type']; $taxsn = last_sale_tax_code(); $ocode = get_ocode($ccode); if($c_date_type=='1'){ $writedate = $c_date; } else { $writedate = date("Y-m-d",time()); }
$sql = "insert into sale_tax_m set ocode = '{$ocode}', taxsn = '{$taxsn}', bookno1 = 1, bookno2 = '{$taxsn}', immd_yn = 0, tax_type = '{$tax_type}', ccode = '{$ccode}', writedate = '{$writedate}', issue_dttime = '".date("Y-m-d H:i:s",time())."', blank = 0, remarks = '', recved_yn = '{$recved_yn}', card_yn = 0, etax_appv_no = '', etax_srvc_no = '', cng_reason = '', data_created = '".date("Y-m-d H:i:s",time())."', data_updated = '".date("Y-m-d H:i:s",time())."' "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금계산서 마스터 저장 $midx = mysql_insert_id($connect_e1000y); $tax_midx_list .= "$midx,"; // 국세청 전송위해서 처리한 리스트 midx를 저장한다. $ccode_list .= "$ccode,"; // 국세청 전송위한 거래처코드 저장
$sql = "select * from (select b.midx, b.seq, b.pcode, b.pname, b.pnorm, c.unit, b.qty, b.price, b.sup_amt, b.vat, b.tot_amt, b.tax_type, a.ccode, a.dealdate, b.remarks from sale_d b left join sale_m a on a.midx = b.midx left join product_m c on b.pcode = c.code where {$midx_list} ) aa where ccode = '{$ccode}' and tax_type = '{$tax_type}' order by ccode, tax_type, midx, seq "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; $info_array = null; while($info = mysql_fetch_array($res)){ // 거래처별,세금구분별로 데이터 가져오기 $info_array[] = $info; }
$seq = 1; foreach($info_array as $key=>$info){ if($d_date_type=='1'){ $dealdate = $d_date; } else { $dealdate = $info['dealdate']; } $sql = "insert into sale_tax_d set midx = '{$midx}', seq = '{$seq}', dealdate = '{$dealdate}', pname = '{$info['pname']}', pnorm = '{$info['pnorm']}', unit = '{$info['unit']}', qty = '{$info['qty']}', price = '{$info['price']}', sup_amt = '{$info['sup_amt']}', vat = '{$info['vat']}', remarks = '{$info['remarks']}', data_created = '".date("Y-m-d H:i:s",time())."', data_updated = '".date("Y-m-d H:i:s",time())."' "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금게산서 서브 저장
$sql = "update sale_d set taxno = '{$midx}' where midx = '{$info['midx']}' and seq = '{$info['seq']}' "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; $seq++; } } } } else if($sel_mode=='sum'){ // 집계일때 내부저장 $ccode_tax = explode(",",$code_list);
foreach($ccode_tax as $key=>$val){ $v = explode("^",$val); $ccode = $v[1]; $tax_type = $v[2];
$taxsn = last_sale_tax_code(); $ocode = get_ocode($ccode); if($c_date_type=='1'){ $writedate = $c_date; } else { $writedate = date("Y-m-d",time()); }
$sql = "insert into sale_tax_m set ocode = '{$ocode}', taxsn = '{$taxsn}', bookno1 = 1, bookno2 = '{$taxsn}', immd_yn = 0, tax_type = '{$tax_type}', ccode = '{$ccode}', writedate = '{$writedate}', issue_dttime = '".date("Y-m-d H:i:s",time())."', blank = 0, remarks = '', recved_yn = '{$recved_yn}', card_yn = 0, etax_appv_no = '', etax_srvc_no = '', cng_reason = '', data_created = '".date("Y-m-d H:i:s",time())."', data_updated = '".date("Y-m-d H:i:s",time())."' "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금계산서 마스터 저장 $midx = mysql_insert_id($connect_e1000y); $tax_midx_list .= "$midx,"; // 국세청 전송위해서 처리한 리스트 midx를 저장한다. $ccode_list .= "$ccode,"; // 국세청 전송위한 거래처코드 저장
$sql = "select a.ccode, b.tax_type, sum(b.sup_amt) as sup_amt, sum(b.vat) as vat, sum(b.tot_amt) as tot_amt, e.pname, count(b.qty) as pcnt from sale_m a left join sale_d b on a.midx = b.midx , (select b.tax_type as tax_type, pname from sale_m a left join sale_d b on a.midx = b.midx where 1=1 and a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' and a.ccode = '{$ccode}' and b.tax_type = '{$tax_type}' and b.taxno is null order by a.dealdate desc limit 1) e where a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' and a.ccode = '{$ccode}' and b.tax_type = '{$tax_type}' and b.taxno is null group by a.ccode, b.tax_type "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금게산서 서브를 집계로 가져와서 저장한다. $info = mysql_fetch_array($res);
$seq = 1; if($d_date_type=='1'){ $dealdate = $d_date; } else { $dealdate = date("Y-m-d",time()); } if($info['pcnt']>1){ $pname = $info['pname']."외 ".($info['pcnt']-1)."건"; } else { $pname = $info['pname']; } $sql = "insert into sale_tax_d set midx = '{$midx}', seq = '{$seq}', dealdate = '{$dealdate}', pname = '{$pname}', pnorm = '', unit = '', qty = '0', price = '0', sup_amt = '{$info['sup_amt']}', vat = '{$info['vat']}', remarks = '{$info['remarks']}', data_created = '".date("Y-m-d H:i:s",time())."', data_updated = '".date("Y-m-d H:i:s",time())."' "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금게산서 서브 저장
$sql = "select a.midx, b.seq from sale_m a left join sale_d b on a.midx = b.midx where a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' and a.ccode = '{$ccode}' and b.tax_type = '{$tax_type}' and b.taxno is null"; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; while($info = mysql_fetch_array($res)){ $sql = "update sale_d set taxno = '{$midx}' where midx = '{$info['midx']}' and seq = '{$info['seq']}' "; mysql_query($sql,$connect_e1000y); $all_sql .= $sql; }
} }
} else if($sendmode=='cancel'){ // 발행 취소
$mode = "cancel";
foreach($code_idx as $key=>$val){ $code_list .= "{$codes[$val]},"; $v = explode("^",$codes[$val]); if($v[0]=='g'){ $midx = trim($v[2]); $seq = trim($v[3]); if($midx!='' && $seq!=''){ $midx_list .= "{$midx},"; } } } $code_list = substr($code_list,0,strlen($code_list)-1); $midx_list = substr($midx_list,0,strlen($midx_list)-1);
$sql = "delete from sale_tax_m where midx in ({$midx_list})"; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금계산서 삭제(서브는 알아서 같이 지워짐)
$sql = "select midx, seq, taxno from sale_d where taxno in ({$midx_list}) "; $res = mysql_query($sql,$connect_e1000y); $all_sql .= $sql; // 세금계산서 연동 매출 키 삭제 while($info = mysql_fetch_array($res)){ $sql = "update sale_d set taxno = null where midx = '{$info['midx']}' and seq = '{$info['seq']}' "; mysql_query($sql,$connect_e1000y); $all_sql .= $sql; }
}
function tax_soap_process($tax_code,$rSMScheck){ Global $eid;
$loginUrl = "http://".$_SERVER['SERVER_NAME']."/emillennium/curl_send_soap_process.php"; $login_data = "tax_code={$tax_code}&eid2={$eid}&rSMScheck={$rSMScheck}"; $result = curl_call($loginUrl,$login_data); //$result = iconv_euckr($result);
return $result;
}
//_pr($_POST); $sendmode = "debug"; //_pr($tax_midx_list); $sendmode = "debug";
if($sendmode=='nts'){ // 국세청처리 $office_info = get_office_info(); // 공급처정보 가져옴
$tax_midx_list = substr($tax_midx_list,0,strlen($tax_midx_list)-1); $ccode_list = substr($ccode_list,0,strlen($ccode_list)-1); //echo $tax_midx_list; $midx_array = explode(",",$tax_midx_list); $ccode_array = explode(",",$ccode_list); $cnt=0; foreach($midx_array as $key=>$val){ $res = tax_soap_process($val,$sms_send);
$ccode = $ccode_array[$cnt]; $cust_info = get_customers_info($ccode); //공급받는자 정보 가져옴 $v = explode(":",$res); $v_tax_code = $v[1]; $v_appv_no = $v[2]; $v_mgmt_no = $v[3]; if($v[0]=='ok'){ if($sms_send=='on'){ // sms보낼때 포인트와 sms처리 처리 $usepoint = "170"; $usetype = "1"; $pointbigo = $office_info['comp_name']." / SMS:".$cust_info['tax_charge_hpno'];
/* 번호처리 */ if($sPhone == ""){ $sndphone = "010-000-0000"; } else { $sndphone = str_replace("-","",$office_info['tax_charge_hpno']); //보내는번호 -제거 } $rcvphone = str_replace("-","",$cust_info['tax_charge_hpno']); //받는번호 -제거
/* 메시지 처리 */
$sndmsg = substr($office_info['comp_name'],0,20)."로부터 세금계산서발급 수신메일:".$cust_info['tax_charge_email']; $subsndmsg = substr($sndmsg,0,80);
$sms_userid = $tax_sms_id; $sms_pswd = $tax_sms_pw;
$sms_msg = $subsndmsg; $sms_fromtel = $sndphone; //$sms_fromtel = "15668680"; // 신버젼도 발신번호 문제로 날라가지 않을때 사용됨 $sms_totel = $rcvphone; $cttime = date("YmdHis",time()); $usign = sha1($cttime.sha1($sms_pswd)); $loginUrl = "http://psms.mjsoft.co/api/sms_send.php"; $login_data = "&uid=$sms_userid&ctime=$cttime&usign=$usign&senddate=&phone=$sms_totel&callback=$sms_fromtel&msg=$sms_msg&appcode=106";
$result = curl_call($loginUrl,$login_data); $json_data = json_decode($result); if($json_data->msg!='OK'){ // sms 실패시 포인트 변동 $usepoint = "150"; $usetype = "1"; $pointbigo = $office_info['comp_name']." / SMS:실패"; }
sms_send_log($eid."_".$val,$loginUrl.$login_data,$result); // 로그 남김 } else { // sms아닐때의 포인트 처리 $usepoint = "150"; $usetype = "1"; $pointbigo = $office_info['comp_name']; }
$pointbigo = iconv("utf-8","euckr",$pointbigo); $pisql = "INSERT INTO cash_use ( cust_id, rgst_dtm, usepoint, use_type, use_fkey, bigo ) VALUE ( '$eid', '$todaytime', '$usepoint', '$usetype', '$v_mgmt_no', '$pointbigo' )"; mysql_query($pisql,$connect_cash); } else { $mode_ok = "N"; $msg.="{$v[1]} 계산서오류 : {$v[2]} : {$res} "; } $cnt++; } }
echo "<?php xml version='1.0' encoding='utf-8'?><output>"; echo "<mode>".$mode."</mode>"; echo "<mode_ok>".$mode_ok."</mode_ok>"; echo "<rtn_url>".$rtn_url."</rtn_url>"; echo "<msg>".$msg."</msg>"; echo "<tax_midx_list>".$tax_midx_list."</tax_midx_list>"; echo "<ccode_array>".$ccode_array."</ccode_array>"; echo "</output>";
?>
|