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
|
<?php $dir = "."; include_once($dir."/_common.php");
if($eid==''){ alert('e천년경영 로그인 후에 이용가능합니다.',"index.php"); exit; }
if($sdate==''){ $sdate = date("Y-m-",time())."01"; } if($edate==''){ $edate = date("Y-m-d",time()); }
$order_key = 'a.dealdate desc, data_created desc ';
if($smode=='comp'){ $where = " and a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' and b.taxno <> '' "; $where1 = " and aa.dealdate >= '{$sdate}' and aa.dealdate <= '{$edate}' and bb.taxno <> '' "; $where2 = " and aaa.dealdate >= '{$sdate}' and aaa.dealdate <= '{$edate}' and bbb.taxno <> '' "; } else { $where = " and a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' and b.taxno is null "; $where1 = " and aa.dealdate >= '{$sdate}' and aa.dealdate <= '{$edate}' and bb.taxno is null "; $where2 = " and aaa.dealdate >= '{$sdate}' and aaa.dealdate <= '{$edate}' and bbb.taxno is null "; }
if($stx!=''){ $where .= " and {$sti} like '%{$stx}%' "; }
if($stc!=''){ $where .= " and a.ccode = '{$stc}' "; $where1 .= " and aa.ccode = '{$stc}' "; $where2 .= " and aaa.ccode = '{$stc}' "; }
if($stpc!=''){ $where .= " and prod_cate_code2 = '{$stpc}' "; }
$sql = "select e.deal_month, a.ccode, c.comp_name, c.code1, c.comp_sn, b.tax_type,e.pname, count(b.qty) as pcnt, sum(b.sup_amt) as sum_sup_amt, sum(b.vat) as sum_vat, sum(b.tot_amt) as sum_tot_amt from sale_m a left join sale_d b on a.midx = b.midx left join customers c on a.ccode = c.code left join ((select b.tax_type as tax_type, substring(a.dealdate,1,7) as deal_month, pname from sale_m a left join sale_d b on a.midx = b.midx where 1=1 {$where} and b.tax_type = 0 order by a.dealdate desc limit 1) union (select bb.tax_type as tax_type, substring(aa.dealdate,1,7) as deal_month, pname from sale_m aa left join sale_d bb on aa.midx = bb.midx where 1=1 {$where1} and bb.tax_type = 1 order by aa.dealdate desc limit 1) union (select bbb.tax_type as tax_type, substring(aaa.dealdate,1,7) as deal_month, pname from sale_m aaa left join sale_d bbb on aaa.midx = bbb.midx where 1=1 {$where2} and bbb.tax_type = 2 order by aaa.dealdate desc limit 1) ) e on b.tax_type = e.tax_type where 1=1 {$where} group by a.ccode, c.comp_name, b.tax_type order by a.ccode, tax_type; "; $result = mysql_query($sql,$connect_e1000y);
//_pr($sql); while($cus_info=mysql_fetch_array($result)){ $list_array[] = $cus_info; } header( "Content-type: application/vnd.ms-excel" ); header( "Content-Disposition: attachment; filename=taxbill_".date("YmdHis",time()).".xls" ); header( "Content-Description: PHP4 Generated Data" ); ?> <form name='sale_list_form' method='post'> <input type='hidden' name='sel_mode' value='sum'> <input type='hidden' name='sdate' value='<?php echo $sdate?>'> <input type='hidden' name='edate' value='<?php echo $edate?>'> <div class="div-list-area"> <div class="cust-list-area"> <table class="order-sheet2" border=1> <caption class="screen_out">매출처 원장 조회<caption> <colgroup> <col style="width:90px;"><col style="width:100px;"><col style="width:140px;"> <col style="width:70px;"><col style="width:70px;"><col style="width:180px;"> <col style="width:100px;"><col style="width:90px;"><col style="width:120px;"> </colgroup>
<thead> <tr> <th scope="col">거래처코드</th><th scope="col">사업자번호</th><th scope="col">거래처명</th> <th scope="col">거래일자</th><th scope="col">과세구분</th><th scope="col">상품명/규격</th> <th scope="col">공급가액</th><th scope="col">부가세</th><th scope="col">합계액</th> </tr> </thead> <tbody> <?php $tmp_ccode = "0"; $s_amt = 0; $s_vat = 0; $s_tot = 0; $cnt = 0; for($i=0;$i<count($list_array);$i++){ $info = $list_array[$i]; //echo $tmp_ccode." = ".$info['ccode']." - {$i}<br>"; if($tmp_ccode!=$info['ccode']){ // 거래처가 바꼈을때 if($i>0){ ?> <tr> <td class="tcenter " colspan=6></td> <td class="cost cost_color_db"><?php echo number_format($s_amt);?></td> <td class="cost cost_color_db"><?php echo number_format($s_vat);?></td> <td class="cost cost_color_db"><?php echo number_format($s_tot);?></td> </tr> <?php $s_amt = 0; $s_vat = 0; $s_tot = 0; } ?> <tr> <td class="linetxt cust_sum_class" colspan=9>거래처명 : [<?php echo $info['code1'];?>]<?php echo $info['comp_name'];?></td> </tr> <?php $tmp_ccode = $info['ccode']; $cnt++; } ?> <tr> <td class="tcenter "><?php echo $info['code1'];?></td> <td class="tcenter "><?php echo $info['comp_sn']?></td> <td class="linetxt click_edit"><?php echo $info['comp_name'];?></td> <td class="tcenter"><?php echo $info['deal_month'];?></td> <td class="tcenter"><?php echo $tax_yn[$info['tax_type']];?></td> <td class="linetxt "><?php echo $info['pname']; if($info['pcnt']>1){ echo "외 ".($info['pcnt']-1)."건"; }?></td> <td class="cost "><?php echo number_format($info['sum_sup_amt']);?></td> <td class="cost "><?php echo number_format($info['sum_vat']);?></td> <td class="cost "><?php echo number_format($info['sum_tot_amt']);?></td> </tr> <?php $cnt++; $s_amt += $info['sum_sup_amt']; $s_vat += $info['sum_vat']; $s_tot += $info['sum_tot_amt']; } if(count($list_array)>0){ ?> <tr> <td class="tcenter " colspan=6></td> <td class="cost cost_color_db"><?php echo number_format($s_amt);?></td> <td class="cost cost_color_db"><?php echo number_format($s_vat);?></td> <td class="cost cost_color_db"><?php echo number_format($s_tot);?></td> </tr> <?php } ?> </tbody> </table> </div> </div> </form> ?>
|