/home/mjc1/public_html/emillennium/buy_list.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
<?php
$dir 
".";
include_once(
$dir."/_common.php");
if(
$mode=='ajax'){
    
//include('./include/header.sub.php'); 
} else { // 모드 ajax일때 숨김처리
    
include('./include/header.php'); 
}

if(
$eid==''){
    
alert('e천년경영 로그인 후에 이용가능합니다.',"index.php"); exit;
}

//ck_category_init(); // 첫 사용자 카테고리 초기화

/*$sql = "select * from product_m ";
$res = mysql_query($sql,$connect_e1000y);
while($info=mysql_fetch_array($res)){
    $sql = "insert into product_u set pcode = '{$info['code']}', Mid = '{$eid}' ";    
    //_pr($sql);
    mysql_query($sql,$connect_e1000y);
}*/

if($sdate==''){ $sdate date("Y-m-",time())."01"; }
if(
$edate==''){ $edate date("Y-m-d",time()); }

if(
$show_date=='today'){ // 모드 ajax일때 날짜 처리
    
$sdate date("Y-m-d",time()); $edate date("Y-m-d",time());
}
if(
$show_date=='week'){ // 모드 ajax일때 날짜 처리
    
$sdate date("Y-m-d",time()-(60*60*24*7)); $edate date("Y-m-d",time());
}

$order_key 'a.dealdate desc, data_created desc '

$where " and a.dealdate >= '{$sdate}' and a.dealdate <= '{$edate}' ";

if(
$stx!=''){
    
$where .= " and {$sti} like '%{$stx}%' ";
}

if(
$stc!=''){
    
$where .= " and a.ccode = '{$stc}' ";
}

if(
$stpc!=''){
    
$where .= " and prod_cate_code2 = '{$stpc}' ";
}

$sql "select count(*) as cnt
                from buy_m a 
                left join (select aa.midx as dmidx, count(aa.pcode) as dcnt, sum(aa.qty) as dqty, sum(aa.tot_amt) as damt, count(aa.taxno) as dtaxno
                    from buy_d aa where 1=1
                    group by aa.midx) b
                    on a.midx = b.dmidx
                left join payment c on a.midx = c.dealidx
                left join customers d on a.ccode = d.code
            where 1=1 
$where 
"
;
$result      =    mysql_query($sql,$connect_e1000y);
$row mysql_fetch_array($result);
$total_count $row['cnt'];

$list_num 15;
if(
$_COOKIE['page_line']!=''){ $list_num $_COOKIE['page_line']; }
$total_page  ceil($total_count $list_num);  // 전체 페이지 계산
if ($page 1) { $page 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page 1) * $list_num// 시작 열을 구함

if($mode=='ajax'){ $limit ""; } else { $limit "limit $from_record$list_num"; } // 모드 ajax일때 리미트를 사용하지 않는다

$sql "select a.midx, a.ccode, d.comp_name, a.dealdate, a.dealnum, a.data_created, ifnull(b.dcnt,0) as dcnt, ifnull(b.dqty,0) as dqty, ifnull(b.damt,0) as damt, ifnull(b.dtaxno,0) as dtaxno, a.remarks, ifnull(c.amount,0) as paym, ifnull(b.damt,0)-ifnull(c.amount,0) as mibul
                from buy_m a 
                left join (select aa.midx as dmidx, count(aa.pcode) as dcnt, sum(aa.qty) as dqty, sum(aa.tot_amt) as damt, count(aa.taxno) as dtaxno
                    from buy_d aa where 1=1
                    group by aa.midx) b
                    on a.midx = b.dmidx
                left join payment c on a.midx = c.dealidx
                left join customers d on a.ccode = d.code
            where 1=1 
$where 
        order by 
$order_key $limit 
"
;
$result      =    mysql_query($sql,$connect_e1000y);

//_pr($sql);
while($cus_info=mysql_fetch_array($result)){
    
$list_array[] = $cus_info;
}

$qstr $_SERVER['QUERY_STRING'];

?>

<!--<div id="contents" style="background:#999"><img src="http://placehold.it/960x150" alt="롤링배너"></div>-->
<div id="contents" style="height:2px;border-bottom:1px solid #eee;background:#2f6ba9" class='ajax_hidden'>
    <span class="screen_out">header 하단 선</span>
</div>

<div id="wrap" class='container_wrap'>
    <div id="sub-title" class='ajax_hidden'>
        <h2>매입관리</h2>
        <div class="sub-location">
            <a href="./index.php" class="home"><span class="screen_out">홈</span></a>
            <span class="location-gt"></span>
            <a>매입관리</a>
            <span class="location-gt"></span>
            <a>매입관리 리스트</a>
        </div>
    </div>
<form name='buy_search_form' method='get'>
    <input type='hidden' name='search_form_name' id='search_form_name' value='payment_search_form'> <!-- 거래처 검색에서 리턴폼 명칭 정의-->
    <input type='hidden' name='biztype' size='' value='<?php echo $biztype;?>'>
    <div id="sub-contents-area" class='ajax_hidden'>
        <div class="sub-btn-area">
            <div class="sub-btn">
                라인수 <?php echo paging_select($list_num);?>
                <a class="lignt-blue-btn" id='btn_order_new'>새전표</a><a class="blue-btn" id='payment_process'>출금</a><!--<a class="blue-btn">주문복사</a><?php if($Orow['ordstate']==0){ ?><a class="black-btn">전체삭제</a><?php }?><a class="gray-btn" id='buy_print'>인쇄</a>--><a class="gray-btn" id='xls_down'>엑셀</a><!--<a class="black-btn" id='sel_delete'>선택삭제</a>-->
            </div>
        </div>
        <div class="sub-btn-area">
            <div class="sub-btn sub-btn-search">
                기간 : <input type='text' name='sdate' id='sdate' value='<?php echo $sdate;?>' class='width_80'> ~ <input type='text' name='edate' id='edate' value='<?php echo $edate;?>' class='width_80'>
                &nbsp;&nbsp;
                거래처검색 : 
                <input type='text' name='stc' value='<?php echo $stc;?>' class='input_readonly width_60'>
                <input type='text' name='stc_search' value='<?php echo $stc_search;?>' class='cust_search_class width_80'>&nbsp;<img src='./images/glass.png' class='customer-sel-btn glass_class'>&nbsp;
                <select name='sti'>
                    <option value='a.remarks' <?php if($sti=='a.remarks'){?>selected<?php }?>>전표비고</option>
                </select>
                <input type='text' id='stx' name='stx' size='' value='<?php echo $stx;?>' class="stx_class">&nbsp;<a href="#" class="black-btn" id='search_btn_press'>검색</a>
            </div>
        </div>
    </div>
</form>
    <div class="item_tab ajax_hidden">
        <div class="item_tab_navi">
            <a value='0'><span>매입전표 등록</span></a>
            <a value='1' class="on"><span>매입전표 관리</span></a>
            <a value='2'><span>출금전표 관리</span></a>
        </div>
    </div>

<form name='product_list_form' method='post'>
<input type='hidden' name='sel_del' value=''>
    <div class="div-list-area">
        <div class="cust-list-area">
            <table class="order-sheet2">
                <caption class="screen_out">매입처 원장 조회<caption>
                <colgroup>
                <col style="width:30px;" class='ajax_hidden'>
                <col style="width:90px;"><col style="width:80px;"><col style="width:100px;"><col style="width:200px;">
                <col style="width:60px;"><col style="width:60px;"><col style="width:100px;">
                <col style="width:100px;"><col style="width:100px;"><col style="width:60px;">
                <col style="width:160px;">
                </colgroup>

                <thead>
                    <tr>
                        <th scope="col" class='ajax_hidden'><input type='checkbox' name='ck_all' class='check_all_class'></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><th scope="col">건별미불</th><th scope="col">계산서</th>
                        <th scope="col">전표비고</th>
                    </tr>
                </thead>
                <tbody>
<?php 
    
for($i=0;$i<count($list_array);$i++){ 
        
$info $list_array[$i];
        if(
$info['cate2_code']=='0'){ $info['cate2_name'] = ""; }
?>
                    <tr>
                        <td class="tcenter ajax_hidden">
                            <input type='checkbox' name='code_idx[]' value='<?php echo $i;?>'>
                            <input type='hidden' name='codes[]' value='<?php echo $info['midx'];?>'>
                        </td>
                        <td class="tcenter "><?php echo $info['dealdate'];?></td>
                        <td class="tcenter "><?php echo substr($info['data_created'],11,8);?></td>
                        <td class="linetxt click_edit"><?php echo $info['dealnum'];?></td>
                        <td class="linetxt click_edit"><?php echo $info['comp_name'];?></td>
                        <td class="cost"><?php echo number_format($info['dcnt']);?></td>
                        <td class="cost "><?php echo number_format($info['dqty']);?></td>
                        <td class="cost "><?php echo number_format($info['damt']);?></td>
                        <td class="cost "><?php echo number_format($info['paym']);?></td>
                        <td class="cost "><?php echo number_format($info['mibul']);?></td>
                        <td class="tcenter ">
                            <?php 
                                
if($info['dtaxno']==0){ echo "<span class='red0'>미발행</span>"; } 
                                else if(
$info['dcnt']>$info['dtaxno']){ echo "<span class='blue0'>부분발행</span>"; }
                                else if(
$info['dcnt']=$info['dtaxno']){ echo "<span class='blue0'>발행</span>"; }
                            
?>
                        </td>
                        <td class="linetxt "><?php echo $info['remarks'];?></td>
                    </tr>
<?php 
    

    if(
count($list_array)==0){
?>
                    <tr>
                        <td class="tcenter" colspan=11>
                            해당되는 매입이 없습니다.
                        </td>
                    </tr>
<?php
    
}
?>
                </tbody>
            </table>
        </div>
    </div>
</form>

    <div class='pg_wrap ajax_hidden' style='padding-top:0px;'>
        <?php echo get_paging($list_num$page$total_page"?$qstr");?>
    </div>

</div><!--//wrap-->

<script>
var qstr = '<?php echo $qstr;?>';
$(function(){
<?php if($mode!='ajax'){ // 모드가 ajax 아닐때?>
    $(".item_tab_navi a").click(function(){ //네비게이션 탭 처리
        v = $(this).attr("value");
        if(v==0){
            document.location.href="./buy.php";
        } else if(v==1){
            document.location.href="./buy_list.php";
        } else if(v==2){
            document.location.href="./payment.php";
        }
    });

    $("#payment_process").click(function(){ // 출금버튼 처리
        get_payment_process();
    });

    $(".click_edit").css("cursor","pointer").click(function(){ // 전표상세보기 수정
        var code = $(this).closest("tr").find("input[name='codes[]']").val();
        document.location.href="buy.php?midx="+code;
    });

    $("#btn_order_new").click(function(){ // 새전표
        document.location.href="buy.php?<?php echo "time=".time();?>";
    });

    $(".check_all_class").click(function(){ // 전체선택 전체선택 해제
        if($(this).is(":checked")){
            $("input[name='code_idx[]']").prop("checked",true);
        } else {
            $("input[name='code_idx[]']").prop("checked",false);            
        }
    });

        $("#xls_down").click(function(){ // 엑셀다운로드
        document.buy_search_form.action='buy_list_xls_down.php';
        document.buy_search_form.target = '_blank';
        document.buy_search_form.submit();
        document.buy_search_form.action='?';
        document.buy_search_form.target = '';
    });

    $("#search_btn_press").click(function(){ // 검색버튼 누를때
        document.buy_search_form.action='?';
        document.buy_search_form.target = '';
        document.buy_search_form.submit();
    });

    /*$(".customer_change_class").change(function(){
        $("#search_btn_press").click();
    });*/
    $(".customer-sel-btn").click(function(){ // 거래처 ? 검색일경우
        customer_search('',1);
    });

    $(".cust_search_class").keypress(function(){ // 거래처명란에서 엔터로 검색일경우
        if(event.keyCode==13){
            var v_cn = $(".cust_search_class").val()
            customer_search(encodeURI(v_cn),1);
        }
    }).change(function(){
        $("input[name='stc']").val("");
    });
<?php }?>
<?php 
if($mode=='ajax'){ // 모드 ajax일때 숨김처리 ?>
    $(".ajax_hidden").hide()
<?php }?>
});

function get_payment_process(){ // 출금전표 작성
    $.get("payment.reg.inc.php?biztype=0",function(rtn){
        $("#modal_member_box").html(rtn).dialog({
            resizable: true, height:430, width:740, modal: true, title: "출금전표 [<?php if($nidx==''){?>작성<?php } else {?>수정<?php }?>]",
            buttons: {
                저장: function() {
                    payment_save();
                },
                닫기: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
}

function customer_search(v_cn,v_page){
    var sti_val = $("form[name='customer_search_form'] select[name='sti'] option:selected").val();
    if(sti_val==undefined){ sti_val = "comp_name"; }
    $.get("customer_list.inc.php?biztype=0&modetype=list&sti="+sti_val+"&stx="+v_cn+"&page="+v_page,function(rtn){
        $("#modal_member_box").html(rtn).dialog({
            resizable: true, height:780, width:1100, modal: true, title: "거래처 [검색]",
            buttons: {
                닫기: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });    
}
</script>
<?php 
if($mode!='ajax'){ // 모드 ajax일때 숨김처리
    
include('./include/footer.php'); 
}
?>
<div id="modal_member_box" title="1차모달" style="display:none;width:100%; height:100%; padding-top:3px;padding-left:3px;background-color:#FFFFFF;position:relative;"></div>
<div id="modal_member_box2" title="2차모달" style="display:none;width:100%; height:100%; padding-top:3px;padding-left:3px;background-color:#FFFFFF;position:relative;"></div>