/home/mjc1/public_html/emillennium/buy.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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
<?php
$dir 
".";
include_once(
$dir."/_common.php");
include(
'./include/header.php'); 

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

$taxno_exists "N";

$amts 0$vats 0$tot_amts 0$qtys 0;

if(
$midx!=''){
    
$sql "select a.*, b.*, b.data_created as d_reg_date, c.code1, c.telno, c.hpno, c.faxno, c.comp_name, c.ceo_name, c.vattype, d.unit, a.remarks as mremarks, e.nidx, e.amount, c.cur_arrear, c.cur_recvbl
                from buy_m a left join buy_d b on a.midx = b.midx left join customers c on a.ccode = c.code 
                    left join product_m d on b.pcode = d.code
                    left join payment e on a.midx = e.dealidx
                where 1=1 and a.midx = '
{$midx}' ";
    
//_pr($sql);
    
$res mysql_query($sql,$connect_e1000y);
    while(
$minfo mysql_fetch_array($res)){
        
$dealdate $minfo['dealdate'];
        
$remarks $minfo['mremarks'];
        
$telno $minfo['telno'];
        
$hpno $minfo['hpno'];
        
$faxno $minfo['faxno'];
        
$ccode $minfo['ccode'];
        
$ccode1 $minfo['code1'];
        
$comp_name $minfo['comp_name'];
        
$ceo_name $minfo['ceo_name'];
        
$vattype $minfo['vattype'];
        
$amount $minfo['amount'];
        
$cur_arrear $minfo['cur_arrear'];
        
$cur_recvbl $minfo['cur_recvbl'];

        if(
$minfo['taxno']){
            
$taxno_exists "Y";
        }

        
$amts += $minfo['sup_amt'];
        
$vats += $minfo['vat'];
        
$tot_amts += $minfo['tot_amt'];
        
$qtys += $minfo['qty'];                
        
$nidx $minfo['nidx'];

        
$buy_array[] = $minfo;
    }
    if(
$dealdate==''){
        echo 
"<script>document.location.href='?';</script>";
        exit;
    }
} else {
    
/*$sql = "select max(midx)+1 as maxcode from buy_m where 1=1";
    $res = mysql_query($sql,$connect_e1000y);
    $minfo = mysql_fetch_array($res);
    $midx = $minfo['maxcode'];*/
    
$dealdate date("Y-m-d",time());
}

?>
<style>
    .cust_modal2 { border:0px solid #e1e1e1; width:700px; padding:10px; font-size:13px }
</style>

<div id="contents" style="height:2px;border-bottom:1px solid #eee;background:#2f6ba9">
    <span class="screen_out">header 하단 선</span>
</div>

<div id="wrap" class='container_wrap'>
    <div id="sub-title">
        <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='customer_search_form' method='get'>
    <input type='hidden' name='biztype' size='' value='<?php echo $biztype;?>'>
    <div id="sub-contents-area">
        <div class="sub-btn-area">
            <div class="sub-btn">
                <!--<select name='order_key' class='order_key_class'>
                    <option value='comp_name' <?php if($order_key=='comp_name'){?>selected<?php }?>>상호명순</option>
                    <option value='code1' <?php if($order_key=='code1'){?>selected<?php }?>>코드순</option>
                </select>
                라인수 <?php echo paging_select($list_num);?>-->
                <a class="lignt-blue-btn" id='btn_order_new'>새전표</a><a class="black-btn" id='all_delete'>전체삭제</a><a class="blue-btn" id='payment_process'>출금</a><!--<a class="blue-btn">주문복사</a><a class="black-btn">전체삭제</a><a class="gray-btn" id='buy_print'>인쇄</a>--><?php if($_SERVER['REMOTE_ADDR']=='58.151.27.172'){?><a class="gray-btn" id='tax_process'>계산서</a><?php }?><a class="gray-btn" id='xls_down'>엑셀</a>
            </div>
        </div>
        <!--<div class="sub-btn-area">
            <div class="sub-btn sub-btn-search">
                <select name='sti'>
                    <option value='a.comp_name' <?php if($sti=='a.comp_name'){?>selected<?php }?>>상호명</option>
                    <option value='a.code1' <?php if($sti=='a.code1'){?>selected<?php }?>>코드</option>
                    <option value='a.comp_sn' <?php if($sti=='a.comp_sn'){?>selected<?php }?>>사업자번호</option>
                    <option value='a.ceo_name' <?php if($sti=='a.ceo_name'){?>selected<?php }?>>대표자</option>
                    <option value='a.telno' <?php if($sti=='a.telno'){?>selected<?php }?>>전화번호</option>
                    <option value='a.hpno' <?php if($sti=='a.hpno'){?>selected<?php }?>>핸드폰</option>
                    <option value='a.email' <?php if($sti=='a.email'){?>selected<?php }?>>이메일</option>
                    <option value='a.memo' <?php if($sti=='a.memo'){?>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>-->
        <br>
    </div>
</form>
    <div class="item_tab">
        <div class="item_tab_navi">
            <a value='0' class="on"><span>매입전표 등록</span></a>
            <a value='1'><span>매입전표 관리</span></a>
            <a value='2'><span>출금전표 관리</span></a>
        </div>
    </div><!--//item_tab-->
<form name='buy_form' id="buy_form" method='post'>
    <input type='hidden' name='sel_del' value=''>
    <input type='hidden' name='all_del' value=''>
    <input type='hidden' name='sel_del_list' value=''>

    <h4 style='font-size:14px; font-weight:bold;margin-top:10px;'>기본정보</h4>
    <div class="sub-write-area" style='display:block;width:1200px;'>

        <div class="order-sheet-area" style='width:1200px;'>
            <table class="order-sheet">
                <caption class="screen_out">주문내역</caption>
                <colgroup>
                    <col style="width:130px;"><col style="width:260px;">
                    <col style="width:130px;"><col style="width:260px;">
                    <col style="width:130px;"><col style="width:260px;">
                </colgroup>

                <tbody>
                <tr>
                    <th>전표번호</th>
                    <td class='linetxt'><input type='text' name='midx' value='<?php echo $midx;?>' class='input_readonly width_80'></td>
                    <th>계산서</th>
                    <td class='linetxt'>미발행</td>
                    <th>거래일자</th>
                    <td class='linetxt'><input type='text' name='dealdate' id='dealdate' value='<?php echo $dealdate;?>' class='input_readonly width_80'> </td>
                </tr>
                <tr>
                    <th>거래처</th>
                    <td class='linetxt'>
                        <input type='hidden' name='ccode' value='<?php echo $ccode;?>'>
                        <input type='text' name='ccode1' value='<?php echo $ccode1;?>' class='input_readonly width_60'>
                        <input type='text' name='comp_name' value='<?php echo $comp_name;?>' class='width_120 customer-sel-btn2' >
                        &nbsp;<img src='./images/glass.png' class='customer-sel-btn glass_class'>
                    </td>
                    <th>전표비고</th>
                    <td colspan=3 class='linetxt'><input type='text' name='remarks' value='<?php echo $remarks;?>' class='width_500' id="remarks"></td>
                </tr>
                <tr>
                    <th>전화번호</th>
                    <td class='linetxt'><input type='text' name='telno' value='<?php echo $telno;?>' class='input_readonly width_120'></td>
                    <th>휴대전화</th>
                    <td class='linetxt'><input type='text' name='hpno' value='<?php echo $hpno;?>' class='input_readonly width_120'></td>
                    <th>팩스번호</th>
                    <td class='linetxt'><input type='text' name='faxno' value='<?php echo $faxno;?>' class='input_readonly width_120'></td>
                <tr>
                    <th>새액구분</th>
                    <td class='linetxt'>
                        <select name='tax_type' id='tax_type'>
                            <option value='0' <?php if($vattype==0){?>selected<?php }?>>없음</option>
                            <option value='1' <?php if($vattype==1){?>selected<?php }?>>포함</option>
                            <option value='2' <?php if($vattype==2){?>selected<?php }?>>별도</option>
                        </select>
                    </td>
                    <th>대표자</th>
                    <td class='linetxt'><input type='text' name='ceo_name' value='<?php echo $ceo_name;?>' class='input_readonly width_120'></td>
                    <th>수금액</th>
                    <td class='addcolor td_sugum_class'><?php echo number_format($amount);?></td>
                </tr>
                <tr>
                    <th>공급가</th>
                    <td class='addcolor td_amt_class'><?php echo number_format($amts);?></td>
                    <th>부가세</th>
                    <td class='addcolor td_vat_class'><?php echo number_format($vats);?></td>
                    <th>합계금액</th>
                    <td class='addcolor td_sumamt_class'><?php echo number_format($tot_amts);?></td>
                </tr>
                <tr>
                    <th>총수량</th>
                    <td class='addcolor td_qty_class'><?php echo number_format($qtys);?></td>
                    <th>전미불</th>
                    <td class='addcolor td_oldmi_class'>0</td>
                    <th>미불금</th>
                    <td class='addcolor td_nowmi_class'><?php echo number_format($cur_arrear);?></td>
                </tr>
            </table>
        </div>
    </div>


    <input type='hidden' name='sel_del' value=''>
    <div class="div-list-area">
<?php if($taxno_exists=='N'){ // 계산서번호가 있으면 삭제 안됨?>
        <a class='sel_delete'>[선택삭제]</a> <a class='add_line_class'>[행삽입]</a>
<?php }?>
        <div class="cust-list-area" style='margin-top:5px;'>
            <table class="order-sheet2">
                <caption class="screen_out">매입전표등록<caption>
                <colgroup>
                <col style="width:30px;">
                <col style="width:160px;"><col style="width:130px;"><col style="width:60px;">
                <col style="width:80px;"><col style="width:80px;"><col style="width:95px;">
                <col style="width:75px;"><col style="width:95px;"><col style="width:60px;">
                <col style="width:100px;"><col style="width:110px;"><col style="width:70px;">
                </colgroup>

                <thead>
                    <tr>
                        <th scope="col"><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><th scope="col">처리시간</th>
                    </tr>
                </thead>
                <tbody>
<?php 
if($midx!=''){
    for(
$i=0;$i<count($buy_array);$i++){ 
        
$info $buy_array[$i];
?>
                    <tr>
                        <td class="tcenter ">
                            <input type='checkbox' name='seq_idx[]' value='<?php echo $i;?>'>
                            <input type='hidden' name='seqs[]' value='<?php echo $info['seq'];?>'>
                            <input type='hidden' name='pcode[]' value='<?php echo $info['pcode'];?>'>
                        </td>
                        <td class="linetxt "><input type='text' name='pname[]' class='width_pname' value='<?php echo $info['pname'];?>'></td>
                        <td class="linetxt "><input type='text' name='pnorm[]' class='width_pnorm' value='<?php echo $info['pnorm'];?>'></td>
                        <td class="tcenter "><input type='text' name='punit[]' class='width_punit input_readonly' value='<?php echo $info['unit'];?>'></td>
                        <td class="tcenter"><input type='text' name='pqty[]' class='width_pqty number_class' value='<?php echo number_format($info['qty']);?>'></td>
                        <td class="tcenter "><input type='text' name='pprice[]' class='width_pprice number_class' value='<?php echo number_format($info['price']);?>'></td>
                        <td class="tcenter "><input type='text' name='psump_amt[]' class='width_psump_amt number_class' value='<?php echo number_format($info['sup_amt']);?>'></td>
                        <td class="tcenter "><input type='text' name='pvat[]' class='width_pvat number_class' value='<?php echo number_format($info['vat']);?>'></td>
                        <td class="tcenter "><input type='text' name='ptot_amt[]' class='width_ptot_amt input_readonly' value='<?php echo number_format($info['tot_amt']);?>'></td>
                        <td class="tcenter ">
                            <input type='hidden' name='tax_type[]' value='<?php echo $info['tax_type'];?>'>
                            <span class='tax_type_class' style='font-size:11.66px;'><?php echo $tax_yn[$info['tax_type']]."품";?></span>
                        </td>
                        <td class="linetxt "><input type='text' name='premarks[]' class='width_premarks' value='<?php echo $info['remarks'];?>'></td>
                        <td class="linetxt "><input type='text' name='ptaxno[]' class='width_ptaxno input_readonly' value='<?php echo $info['taxno'];?>'></td>
                        <td class="tcenter "><input type='text' name='pdate[]' class='width_pdate input_readonly' value='<?php echo substr($info['d_reg_date'],2,17);?>'></td>
                    </tr>
<?php 
    

}
?>
                </tbody>
            </table>
        </div>
    </div>
<input type='hidden' name='pname_idx' id='pname_idx' value=''>
<input type='hidden' name='line_modify_seq' id='line_modify_seq' value=''>
</form>
    <table class='ori_line_div'>
        <tbody>
            <tr>
                <td class="tcenter ">
                    <input type='checkbox' name='seq_idx[]' value=''>
                    <input type='hidden' name='seqs[]' value=''>
                    <input type='hidden' name='pcode[]' value=''>
                </td>
                <td class="linetxt "><input type='text' name='pname[]' class='width_pname'></td>
                <td class="linetxt "><input type='text' name='pnorm[]' class='width_pnorm'></td>
                <td class="tcenter "><input type='text' name='punit[]' class='width_punit input_readonly'></td>
                <td class="tcenter"><input type='text' name='pqty[]' class='width_pqty number_class'></td>
                <td class="tcenter "><input type='text' name='pprice[]' class='width_pprice number_class'></td>
                <td class="tcenter "><input type='text' name='psump_amt[]' class='width_psump_amt number_class'></td>
                <td class="tcenter "><input type='text' name='pvat[]' class='width_pvat number_class'></td>
                <td class="tcenter "><input type='text' name='ptot_amt[]' class='width_ptot_amt input_readonly'></td>
                <td class="tcenter ">
                    <input type='hidden' name='tax_type[]' value=''>
                    <span class='tax_type_class' style='font-size:11.66px;'>과세품</span>
                </td>
                <td class="linetxt "><input type='text' name='premarks[]' class='width_premarks'></td>
                <td class="linetxt "><input type='text' name='ptaxno[]' class='width_ptaxno input_readonly'></td>
                <td class="tcenter "><input type='text' name='pdate[]' class='width_pdate input_readonly'></td>
            </tr>
        </tbody>
    </table>
</div>
<script>
$(function(){

    $(".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";
        }
    });

    $(".customer-sel-btn").click(function(){ // 거래처 ? 검색일경우
        customer_search('',1);
    });
    $(".customer-sel-btn2").keypress(function(){ // 거래처명란에서 엔터로 검색일경우
        if(event.keyCode==13){
            var v_cn = $(".customer-sel-btn2").val()
            customer_search(encodeURI(v_cn),1);
        }
    });

    /*$(document).on("click","form[name='customer_search_form'] #search_btn_press",function(){ // 거래처 검색 dialog안에서 검색버튼누를때
        var v_cn = $("form[name='customer_search_form'] #stx").val()
        customer_search(encodeURI(v_cn),1);
    });

    $(document).on("keyup","form[name='customer_search_form'] #stx",function(){ // 거래처 검색 dialog안에서 검색란 엔터칠때
        if(event.keyCode==13){
            var v_cn = $("form[name='customer_search_form'] #stx").val()
            customer_search(encodeURI(v_cn),1);
        }
    });*/

    $(document).on("click","form[name='product_search_form'] #search_btn_press",function(){ // 상품 검색 dialog안에서 검색버튼누를때
        var v_cn = $("form[name='product_search_form'] #stx").val()
        product_search(encodeURI(v_cn),1);
    });

    $(document).on("keyup","form[name='product_search_form'] #stx",function(){ // 상품 검색 dialog안에서 검색란 엔터칠때
        if(event.keyCode==13){
            var v_cn = $("form[name='product_search_form'] #stx").val()
            product_search(encodeURI(v_cn),1);
        }
    });

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

    $("#all_delete").click(function(){ // 전체 삭제
        if(!change_flag()){ return; } // 변경가능 확인

        if($("input[name='midx']").val()!=''){ // 수정모드일때만 전체삭제 동작하게
            if(confirm('전체 내역을 정말로 삭제하시겠습니까?\n삭제시 모든내역이 한번에 삭제됩니다.')){
                get_all_delete($("input[name='midx']").val());
            }
        }
    });

    $(".sel_delete").css("cursor","pointer").click(function(){ // 선택삭제
        if(!change_flag()){ return; } // 변경가능 확인

        var ck_cnt = 0; var ck_seq_idx_list = "";
        $(".order-sheet2 input[name='seq_idx[]']").each(function(){
            if($(this).is(":checked")==true){    ck_cnt++;    }
        });
        if(ck_cnt==0){ alert('삭제하실 상품을 선택하시기 바랍니다.'); return; }
        if(confirm('정말로 삭제하시겠습니까?')){
            $(".order-sheet2 input[name='seq_idx[]']").each(function(){
                if($(this).is(":checked")==true){
                    var tr_obj = $(this).closest("tr");
                    ck_seq_idx_list = ck_seq_idx_list + $(tr_obj).find("input[name='seqs[]']").val()+",";
                    $(tr_obj).remove();
                }
            });
            get_seq_idx_init();
            get_sel_delete(ck_seq_idx_list,'Y'); // 이미 등록되었을경우 DB지우고 계산
        }
    });

    $(".add_line_class").click(function(){ // 행삽입시
        if($("input[name='ccode']").val()!=''){    add_line();    } else {    alert('거래처를 선택하시기 바랍니다.')        }
    });

    $(document).on("keypress",".width_pname",function(){ //상품 검색
        if(event.keyCode==13){
            var $tr_obj = $(this).closest("tr");
            var v_pname = $(this).val();
            $("#pname_idx").val($tr_obj.index());
            product_search(encodeURI(v_pname),1);
        }
    });

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

    $(document).on("change","#remarks, #dealdate",function(){
        get_all_save();
    });
    
    $(document).on("change",".width_pnorm, .width_pqty, .width_pprice, .width_psump_amt, .width_pvat, .width_premarks",function(){ // 규격, 숫자, 단가, 공급가액,부가세변경시 업데이트 : 라인수정
        if(!change_flag()){ return; } // 변경가능 확인

        var $tr_obj = $(this).closest("tr");
        $("#line_modify_seq").val($tr_obj.find("input[name='seqs[]']").val());
        if($(this).hasClass("width_pqty") || $(this).hasClass("width_pprice")){ // 수량,단가 변경시 부가세 재계산
            line_prod_vat($tr_obj);
        }
        if($(this).hasClass("width_pqty") || $(this).hasClass("width_pprice") || $(this).hasClass("width_psump_amt") || $(this).hasClass("width_pvat")){ // 합계금액 재계산
            line_prod_cal($tr_obj);
        }
        get_all_save();
        $("#line_modify_seq").val('');
    });

    $(document).on("keypress",".width_pnorm, .width_pqty, .width_pprice, .width_psump_amt, .width_pvat, .width_premarks",function(){ // 규격, 숫자, 단가, 공급가액,부가세변경시 업데이트 : 라인수정 체인지외에 엔터쳤을때도 저장 처리
        if(!change_flag()){ return; } // 변경가능 확인

        if(event.keyCode==13){
            var $tr_obj = $(this).closest("tr");
            $("#line_modify_seq").val($tr_obj.find("input[name='seqs[]']").val());
            if($(this).hasClass("width_pqty") || $(this).hasClass("width_pprice")){ // 수량,단가 변경시 부가세 재계산
                line_prod_vat($tr_obj);
            }
            if($(this).hasClass("width_pqty") || $(this).hasClass("width_pprice") || $(this).hasClass("width_psump_amt") || $(this).hasClass("width_pvat")){ // 합계금액 재계산
                line_prod_cal($tr_obj);
            }
            get_all_save();
            $("#line_modify_seq").val('');
        }
    });

    $("#tax_type").change(function(){  //새액구분 변경시
        if(!change_flag()){ return; } // 변경가능 확인

        $("#buy_form input[name='seq_idx[]']").each(function(){
            if($(this).is(":checked")){
                $tr_obj = $(this).closest("tr");
                //$("#line_modify_seq").val($tr_obj.find("input[name='seqs[]']").val());
                line_prod_vat($tr_obj);
                //get_all_save();
                //$("#line_modify_seq").val('');
            }
        });
        if($(this).val()==0){ // 없음일때 부가세 수정 불가처리
            $(".width_pvat").addClass("input_readonly").attr("readonly",true);
        } else {
            $(".width_pvat").removeClass("input_readonly").attr("readonly",false);
        }
        get_all_save();
    });

    $("#tax_process").click(function(){ // 계산서 버튼 클릭
        var midx = $("input[name='midx']").val();
        if(midx!=''){
            taxinvoice_process(midx);
        }
    });

    $("#payment_process").click(function(){ // 출금버튼 처리
        //if(!change_flag()){ return; } // 변경가능 확인

        var midx = $("input[name='midx']").val();
        if(midx!=''){
            get_payment_process(midx);
        } else {
            get_payment_process('');
        }
    });

    $("#xls_down").click(function(){ // 엑셀다운
        var midx = $("input[name='midx']").val();
        if(midx!=''){
            window.open("sale_buy_xls.php?mode=buy&midx="+midx,"xls_down","width=100, height=100");
        } else {
            alert('엑셀로 보낼 데이터가 없습니다. \n자료조회후 엑셀로 보내세요.');
        }
    });

    var cus_tax_type = $("#tax_type option:selected").val();
    if(cus_tax_type==0){ // 새액구분에서 부가세 없음일경우 부가세 수정 불가
        $(".width_pvat").addClass("input_readonly");
    }

    $(document).on("mouseenter",".width_pdate",function(){
        $pos = $(this).position(); 
        $left = parseInt($pos.left)+30;
        $val = $(this).val();
        $("#alt_div").show().html($val).css("left",$left+"px").css("top",$pos.top+"px");
    });

    $(document).on("mouseleave",".width_pdate",function(){
        $("#alt_div").hide();
    });

    $(".input_readonly").attr("readonly",true);    
<?php if($midx!='' && $taxno_exists == "N"){ ?>
    add_line();
<?php ?>
});

function customer_search(v_cn,v_page){ // 거래처 검색
    
    if($("input[name='midx']").val()!=''){ // 기존의 전표가 저장되어 있을때 거래처 변경안되고 새전표 작성할지 유도 질문
        if(confirm('새로운 전표를 작성하시겠습니까?')){
            document.location.href='?<?php echo "time=".time();?>';
        } else {
            return;
        }
    }

    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&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" );
                }
            }
        });
    });
}

function product_search(v_cn,v_page){ // 상품 검색
    if(!change_flag()){ return; } // 변경가능 확인

    var sti_val = $("form[name='product_search_form'] select[name='sti'] option:selected").val();
    if(sti_val==undefined){ sti_val = "a.name"; }
    $.get("product_list.inc.php?biztype=0&sti="+sti_val+"&stx="+v_cn+"&page="+v_page,function(rtn){
        $("#modal_member_box").html(rtn).dialog({
            resizable: true, height:820, width:1150, modal: true, title: "상품 [검색]",
            buttons: {
                닫기: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
}

function add_line(){ // 라인추가
    var new_line_html = $(".ori_line_div tbody").html();
    $("form[name='buy_form'] .order-sheet2 tbody").append(new_line_html);

    line_seq_idx_last();
}

function line_seq_idx_last(){
    var last_seq_idx = 0;
    $(".order-sheet2 input[name='seq_idx[]']").each(function(idx){
        if(idx==0){ 
            if($(this).val()==''){ $(this).val(idx); } 
        } else {
            if($(this).val()==''){ $(this).val(parseInt(last_seq_idx)+1); } 
        }
        last_seq_idx = $(this).val();
    });
}

function get_all_save(){ // 현재값 저장 처리
    if(!change_flag()){ return; } // 변경가능 확인

    $("#buy_form input[name='sel_del']").val("save");
    var form_data = $("#buy_form").serialize();

    $.ajax({type:"post", url:"ajax.buy_reg_process.php", data:form_data, async:false, dataType : "xml", 
        success:function(xml){    
            var v_mode = $(xml).find("mode").text();
            var v_mode_ok = $(xml).find("mode_ok").text();
            var v_msg = $(xml).find("msg").text();
            var v_sum_qty = $(xml).find("sum_qty").text();
            var v_sum_tot_amt = $(xml).find("sum_tot_amt").text();
            var v_sum_sump_amt = $(xml).find("sum_sump_amt").text();
            var v_sum_vat = $(xml).find("sum_vat").text();
            var v_mibul = $(xml).find("mibul").text();
            var v_midx = $(xml).find("midx").text();
            var v_pdate = $(xml).find("pdate").text();

            var v_add_key_list = $(xml).find("add_key_list").text();
            var v_add_seq_list = $(xml).find("add_seq_list").text();
            if(v_mode_ok!='Y' && v_msg!=''){
                alert(v_msg);
            } else {
                if(v_pdate!=''){
                    $("form[name='buy_form'] input[name='pdate[]']").eq($("#pname_idx").val()).val(v_pdate);
                }
                $(".td_qty_class").html(v_sum_qty);
                $(".td_sumamt_class").html(v_sum_tot_amt);
                $(".td_amt_class").html(v_sum_sump_amt);
                $(".td_vat_class").html(v_sum_vat);
                $(".td_nowmi_class").html(v_mibul);
                if(v_midx!=''){ $("input[name='midx']").val(v_midx); }
                if(v_mode=='update' || v_mode=='new'){ // 업데이트 일경우 추가된 상품의 seq번호를 업데이트 해준다.
                    vv1 = v_add_key_list.split(",");
                    vv2 = v_add_seq_list.split(",");
                    for(i=0;i<vv1.length;i++){
                        $("#buy_form input[name='seqs[]']").eq(vv1[i]).val(vv2[i]);
                    }
                }
            }
        },
        error:function(rtn,status,error){    alert(error);        }
    });
}

function get_all_delete(midx){
    if(!change_flag()){ return; } // 변경가능 확인

    $("#buy_form input[name='all_del']").val("Y");
    var form_data = $("#buy_form").serialize();

    $.ajax({type:"post", url:"ajax.buy_reg_process.php", data:form_data, async:false, dataType : "xml", 
        success:function(xml){    
            var v_mode = $(xml).find("mode").text();
            var v_mode_ok = $(xml).find("mode_ok").text();
            var v_msg = $(xml).find("msg").text();
            var v_sum_qty = $(xml).find("sum_qty").text();
            var v_sum_tot_amt = $(xml).find("sum_tot_amt").text();
            var v_sum_sump_amt = $(xml).find("sum_sump_amt").text();
            var v_sum_vat = $(xml).find("sum_vat").text();
            var v_mibul = $(xml).find("mibul").text();
            if(v_mode_ok!='Y' && v_msg!=''){
                alert(v_msg);
            } else {
                alert('전표가 모두 삭제되었습니다.');
                document.location.href='?<?php echo $qstr."&time=".time();?>';
            }
        },
        error:function(rtn,status,error){    alert(error);        }
    });
}

function get_sel_delete(sel_del_list,del_mode){ // 선택레코드 바로 삭제
    if(!change_flag()){ return; } // 변경가능 확인

    $("#buy_form input[name='sel_del']").val(del_mode);
    $("#buy_form input[name='sel_del_list']").val(sel_del_list);
    var form_data = $("#buy_form").serialize();

    $.ajax({type:"post", url:"ajax.buy_reg_process.php", data:form_data, async:false, dataType : "xml", 
        success:function(xml){    
            var v_mode = $(xml).find("mode").text();
            var v_mode_ok = $(xml).find("mode_ok").text();
            var v_msg = $(xml).find("msg").text();
            var v_sum_qty = $(xml).find("sum_qty").text();
            var v_sum_tot_amt = $(xml).find("sum_tot_amt").text();
            var v_sum_sump_amt = $(xml).find("sum_sump_amt").text();
            var v_sum_vat = $(xml).find("sum_vat").text();
            var v_mibul = $(xml).find("mibul").text();
            if(v_mode_ok!='Y' && v_msg!=''){
                alert(v_msg);
            } else {
                $(".td_qty_class").html(v_sum_qty);
                $(".td_sumamt_class").html(v_sum_tot_amt);
                $(".td_amt_class").html(v_sum_sump_amt);
                $(".td_vat_class").html(v_sum_vat);
                $(".td_nowmi_class").html(v_mibul);
                //document.location.reload();
            }
        },
        error:function(rtn,status,error){    alert(error);        }
    });
}

function line_prod_vat($tr_obj){ // 한라인 VAT 재계산
    var cus_tax_type = $("#tax_type option:selected").val();
    var v_tax_type = $tr_obj.find("input[name='tax_type[]']").val();
    
    var qty = number_ch($tr_obj.find("input[name='pqty[]']").val());
    var price = number_ch($tr_obj.find("input[name='pprice[]']").val());
    price = price*qty;
    if(cus_tax_type==0 || v_tax_type==0 || v_tax_type==2){
        $tr_obj.find("input[name='psump_amt[]']").val(formatCurrency(price));
        $tr_obj.find("input[name='pvat[]']").val(0);    
    } else if(cus_tax_type==1){
        v=Math.round(price/11);
        v1 = price-v;
        $tr_obj.find("input[name='psump_amt[]']").val(formatCurrency(v1));
        $tr_obj.find("input[name='pvat[]']").val(formatCurrency(v));    
    } else if(cus_tax_type==2){
        v = Math.round(price*0.1);
        $tr_obj.find("input[name='psump_amt[]']").val(formatCurrency(price));
        $tr_obj.find("input[name='pvat[]']").val(formatCurrency(v));    
    }
    line_prod_cal($tr_obj);
}

function line_prod_cal($tr_obj){ // 한라인 합계금액 재계산
    var amt = $tr_obj.find("input[name='psump_amt[]']").val();
    var vat = $tr_obj.find("input[name='pvat[]']").val();
    var sum_amt = (number_ch(amt)+number_ch(vat));
    $tr_obj.find("input[name='ptot_amt[]']").val(formatCurrency(sum_amt));
}

function get_seq_idx_init(){
    $(".order-sheet2 input[name='seq_idx[]']").each(function(idx){
        $(this).val(idx);
    });
}

function change_flag(){ //
    <?php if($taxno_exists=='Y'){?>return false;<?php ?> // 계산서번호가 있으면 변경불가

    return true;
}

function get_payment_process(midx){ // 출금전표 작성/관리
    $.get("payment.reg.inc.php?biztype=0&midx="+midx,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 taxinvoice_process(midx){ // 계산서 창 처리
    if('<?php echo $taxno_exists;?>'!='N'){
        alert('해당 전표는 계산서가 이미 발행되었습니다.'); 
        document.location.href='taxbill_buy_nts.php';
        return;
    }
    if(midx!=''){
        $.get("ajax.buy_tax_form.php?midx="+midx,function(rtn){
            $("#tax_form_div").html(rtn);
            $.post("taxbill.buy.reg.inc.php?",$("form[name='tax_reg_form']").serialize(), function(rtn){
                $("#modal_member_box").html(rtn).dialog({
                    resizable: true, height:335, width:740, modal: true, title: "매입 세금계산서 처리",
                    buttons: {
                        닫기: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
            });
        });
    }
}

function noEvent() {
    if (event.keyCode == 116) {
        event.keyCode= 2;
        alert('전표등록시엔 F5(Refresh)가 되지않습니다..');
        return false;
    }
    else if(event.ctrlKey && (event.keyCode==78 || event.keyCode == 82))
    {
        alert('전표등록시엔 F5(Refresh)가 되지않습니다..');
        return false;
    }
}
document.onkeydown = noEvent;
</script>
<form name='tax_reg_form' method='post' action=''>
<div id='tax_form_div' style='display:none;'>
    
</div>
</form>
<?php include('./include/footer.php'); ?>
<div id="modal_member_box" title="거래처수정" 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="거래처수정" style="display:none;width:100%; height:100%; padding-top:3px;padding-left:3px;background-color:#FFFFFF;position:relative;"></div>
<div id="modal_member_box3" title="거래처수정" style="display:none;width:100%; height:100%; padding-top:3px;padding-left:3px;background-color:#FFFFFF;position:relative;"></div>
<div id='alt_div' style='display:none; position:absolute; border:1px solid #999;background:#FFFFE0; width:120px; height:22px;'>