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
|
<? include_once("./_common.php"); include("./header.php"); include("./commonST.php");
$all_sql = "";
if(( $id == "" ) && ( $sid == "" )) { echo "<script>alert('천년스마트발주 로그인 후에 이용가능합니다.');location.href = './index.php';</script>"; } // 접속권한 체크 include("./checkLicenses.php");
$sql = "SELECT * FROM customer WHERE code = '{$cuscode}'"; $result = mysql_query($sql); $cuso = mysql_fetch_array($result);
// Notice Error 방지 isset($_POST['txtdate']) ? $txtdate = $_POST['txtdate'] : $txtdate = ""; isset($_POST['txtdate2']) ? $txtdate2 = $_POST['txtdate2'] : $txtdate2 = ""; isset($_POST['duration']) ? $duration = $_POST['duration'] : $duration = "-7"; // 기간 검색하지 않고 '오늘'로 두고 바로 조회 버튼클릭 했을 경우 예외처리 if($duration == 0){ $txtdate = date("Y-m-d", time()); $txtdate2 = date("Y-m-d", time()); }
if (!isset($Tsum)) $Tsum = ""; if (!isset($Tprice)) $Tprice = ""; if (!isset($Tamount)) $Tamount = ""; if (!isset($Ttax)) $Ttax = ""; if (!isset($Tdc)) $Tdc = ""; if (!isset($Ttotal)) $Ttotal = ""; if (!isset($T2amount)) $T2amount = "";
if(!isset($category_code)) $category_code = ""; if(!isset($txtdate)) $txtdate = ""; if(!isset($txtdate2)) $txtdate2 = ""; if(!isset($pg)) $pg = "";
if(!isset($row)) $row = ""; if(!isset($row['part'])) $row['part'] = ""; if(!isset($dPrice)) $dPrice = ""; if(!isset($totalprice)) $totalprice = ""; if(!isset($sumdc)) $sumdc = ""; if(!isset($i)) $i = ""; if(!isset($saleprice)) $saleprice = "";
if(!isset($dTotalMoney)) $dTotalMoney = 0;
$charSet_sql = "set names utf8"; mysql_query($charSet_sql);
// 옵션 값 $optionqry = "SELECT optname, optvalue FROM options"; $optresult = mysql_query($optionqry); $optqtydec = 0; $optdangadec = 0; $optpricedec = 0; while( $optrow = mysql_fetch_array($optresult)){ if($optrow['optname'] == "ON라인신규고객등록") $optnew = $optrow['optvalue']; if($optrow['optname'] == "ON주문시금액숨김") $optmhide = $optrow['optvalue']; if($optrow['optname'] == "주문한도숨김") $optlimit = $optrow['optvalue']; if($optrow['optname'] == "선수금주문방식") $optsmoney = $optrow['optvalue']; if($optrow['optname'] == "ON주문시박스관리") $optbox = $optrow['optvalue']; if($optrow['optname'] == "ON지정상품분류") $optcate = $optrow['optvalue']; if($optrow['optname'] == "ON지정상품") $optpro = $optrow['optvalue']; if($optrow['optname'] == "ON특별단가적용") $optspe = $optrow['optvalue']; if($optrow['optname'] == "다중단가계산기준") $optdac = $optrow['optvalue']; //0 매입단가 1매출단가 2기준단가 if($optrow['optname'] == "온주원장입금비고") $optbigo = $optrow['optvalue']; //0 사용안함 1사용함 if($optrow['optname'] == "수량소수점수") $optqtydec = $optrow['optvalue']; if($optrow['optname'] == "단가소수점수") $optdangadec = $optrow['optvalue']; if($optrow['optname'] == "금액소수점수") $optpricedec = $optrow['optvalue']; } //part : # 거래분야(0:매입,1:매출,2: 매입,매출) if($row['part'] == "0"){ echo "<script>alert('발주처만 이용 가능합니다.');location.href = './index.php';</script>"; }
$cm_nCount = 50; $cm_item_nCount = 30;
if($sid == "mjtest"){ if ($txtdate == ""){ $txtdate = ($txtdate == "") ? date("2010-11-01") : $txtdate; } if ($txtdate2 == ""){ $txtdate2 = ($txtdate2 == "") ? date("2010-11-30") : $txtdate2; } }else{ if ($txtdate == ""){ $txtdate = ($txtdate == "") ? date("Y-m-d", strtotime("-7 Day")) : $txtdate; //$txtdate = ($txtdate == "") ? date("Y-m-d", strtotime("-3 Month")) : $txtdate; } if ($txtdate2 == ""){ $txtdate2 = ($txtdate2 == "") ? date("Y-m-d", time()) : $txtdate2; } } ?> <script> // 일차를 파라메터로 받는다 function setDay(t){ var now = new Date; if ((now.getMonth()+1) < 10){ month = "0"+(now.getMonth()+1); }else{ month = (now.getMonth()+1); } if (now.getDate() < 10){ date = "0"+now.getDate(); }else{ date = now.getDate(); } var today = now.getFullYear() + "-" + month + "-" + date; // 현재날짜 document.searchFrm.txtdate2.value = today; document.searchFrm.txtdate.value = getThatday(today,t); // 현재날짜와 일차를 파라미터로 보내서 결과리턴한다. }
//날짜, 일차를 파라메터로 받는다. function getThatday(today, t){ var pdate=new Array(); var pday=today.split("-"); // 날짜를 구분자로 나누어 배열로 변환한다. var ptoday=new Date(pday[0],pday[1]-1,pday[2]); // 데이트객체 생성한다. var ptimestamp=ptoday.valueOf()+1000*60*60*24*t; // t일후의 타임스탬프를 얻는다. 음수라면 이전날짜를 얻는다. var thatday=new Date(ptimestamp); // t일후의 날짜객체 생성한다. pdate[pdate.length]=thatday.getFullYear(); // 년 if (thatday.getMonth()+1 < 10){ pdate[pdate.length]="0"+(thatday.getMonth()+1); // 월 }else{ pdate[pdate.length]=thatday.getMonth()+1; // 월 } if (thatday.getDate() < 10){ pdate[pdate.length]="0"+thatday.getDate(); // 일 }else{ pdate[pdate.length]=thatday.getDate(); // 일 }
return pdate.join("-"); // 배열을 / 구분자로 합쳐 스트링으로 변환후 반환 }
// 검색 function Search(){ searchFrm.submit(); } </script>
<form name='searchFrm' id="searchFrm" method="post">
<div class="snb"> <p class="txt">거래원장 <span class="f11 blue">거래내역을 확인하실 수 있습니다.</span> <?if($_SESSION['sa_uid']=='hschina'){?> <span class="f11 blue" style='position:absolute;right:20px;top:90px;'> 발주처 : <?=$cuso['compname']?></span> <?}?> </p> </div>
<div class="buy_section"> <div class="search"> <h2>거래원장 조회</h2>
<div class="buy"> <select title="선택" id="duration" name="duration" onchange="setDay(this.value);"> <option value="0" <? if($duration == '0'){ echo "selected"; } ?>>오늘</option> <option value="-3" <? if($duration == '-3'){ echo "selected"; } ?>>최근 3일</option> <option value="-5" <? if($duration == '-5'){ echo "selected"; } ?>>최근 5일</option> <option value="-7" <? if($duration == '-7'){ echo "selected"; } ?>>최근 7일</option> <option value="-30" <? if($duration == '-30'){ echo "selected"; } ?>>최근 1개월</option> <option value="-90" <? if($duration == '-90'){ echo "selected"; } ?>>최근 3개월</option> <option value="-180" <? if($duration == '-180'){ echo "selected"; } ?>>최근 6개월</option> <option value="-365" <? if($duration == '-365'){ echo "selected"; } ?>>최근 1년</option> </select> </div>
<dl class="buy"> <dt class="screen_out"><label>시작일</label></dt> <dd> <!--input type="text" id="" placeholder="시작일(YYYY-MM-DD)" class="it" onblur="" onclick=""--> <input type="text" name="txtdate" id="txtdate" placeholder="시작일(YYYY-MM-DD)" class="it" onblur="" onclick="" value="<?=$txtdate?>"> </dd>
<dt class="screen_out"><label>종료일</label></dt> <dd> <!--input type="text" id="" placeholder="종료일(YYYY-MM-DD)" class="it" onblur="" onclick=""--> <input type="text" name="txtdate2" id="txtdate2" placeholder="종료일(YYYY-MM-DD)" class="it" onblur="" onclick="" value="<?=$txtdate2?>"> </dd> </dl>
<span class="ls ls_v2"><input type="button" title="조회" value="조 회" class="btn_sl" onclick="Search();"></span> </div><!-- class="search" --> <input type=hidden name='mode' value='search'> </form>
<? $old_sql = " SELECT 4, 'prev_sale' AS code, '' AS dealdate, '' AS pname, '' AS pnorm, 0 AS price, 0 AS qnt, 0 AS amount, 0 AS tax, SUM(s.dc) AS dc, SUM(s.total) AS total, 0 AS mamount, 0 as bigo FROM sale AS s WHERE s.dealdate < '{$txtdate}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' UNION ALL SELECT 5, 'prev_rece' AS CODE, '' AS dealdate, '' AS pname, '' AS pnorm, 0 AS price, 0 AS qnt, 0 AS amount, 0 AS tax, SUM(s.dc) AS dc, 0 AS total, SUM(s.amount+s.usepoint) AS mamount, s.bigo FROM receive AS s WHERE s.dealdate < '{$txtdate}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' ";
$all_sql .= $old_sql." "; $total_sql = " SELECT 0, s.code, s.dealdate, s.pname, s.pnorm, s.price, s.qnt, s.amount, s.tax, s.dc, s.total, 0 AS mamount, 0 as bigo FROM sale AS s WHERE s.dealdate BETWEEN '{$txtdate}' AND '{$txtdate2}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' UNION ALL SELECT 2, 'sumday' AS code, s.dealdate, '' AS pname, '' AS pnorm, sum(s.price), sum(s.qnt), sum(s.amount), sum(s.tax), sum(s.dc), sum(s.total), '0' AS mamount , 0 as bigo FROM sale AS s WHERE s.dealdate BETWEEN '{$txtdate}' AND '{$txtdate2}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' group by dealdate UNION ALL SELECT 1, s.code, s.dealdate, '' AS pname, '' AS pnorm, '' AS price, '' AS qnt, '' AS amount, '' AS tax, s.dc, '' AS total, (s.amount+s.usepoint) AS mamount, s.bigo FROM receive AS s WHERE s.dealdate BETWEEN '{$txtdate}' AND '{$txtdate2}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' ORDER BY dealdate, 1, code "; $all_sql .= $total_sql." "; //이월금액 $oldresult = mysql_query($old_sql) or die (mysql_error()); if(mysql_num_rows($oldresult) > 0 ){ while ($oldRow = mysql_fetch_array($oldresult)){ if($oldRow['code']=="prev_sale"){ $oldtotal = $oldRow['total']; } if($oldRow['code']=="prev_rece"){ $oldmamount = $oldRow['mamount']; $oldmamountdc = $oldRow['dc']; } } $basesql = "SELECT cust_base_sale FROM customer WHERE code = '{$cuscode}'"; $baseresult = mysql_query($basesql); $baserow = mysql_fetch_array($baseresult); $oldsum = $oldtotal - $oldmamount - $oldmamountdc + $baserow['cust_base_sale']; if($optmhide != "1"){ ?> <div class="books"> <div class="books_carry">전기이월 : <span class="fright"><?=number_format($oldsum,$optpricedec)?></span> </div> </div> <? } //내역 $result = mysql_query($total_sql) or die (mysql_error()); $nTotalCount = mysql_num_rows($result); $nPage = ceil($nTotalCount / $cm_nCount); if ($pg == "") $pg = 1; $nFrom = ($pg - 1) * $cm_nCount; $sql = $total_sql . " "; $result = mysql_query($sql) or die (mysql_error()); $bg = "#ffffff"; if( mysql_num_rows($result) > 0 ){ //전기 이월금액 미리 더하기 $dTotalMoney = $oldsum; while ($Row = mysql_fetch_array($result)){ $proResult = $Row['pname']; //입금 문자 처리 & 배경색 if(!$Row['mamount'] == ""){ $proResult = "[입금]"; }else if($Row['code'] == "sumday"){ $proResult = "[일계]"; } //잔액 소계 if( $Row['code'] == "sumday"){ }else{ //잔액 = 전기이월 + 합계액 - 입금액 $dTotalMoney = $dTotalMoney + $Row['total'] - $Row['mamount'] ; if (! $Row[0] == "0"){ $dTotalMoney = $dTotalMoney - $Row['dc']; } $i++; } //입금액 $dPrice = $dPrice + $Row['mamount']; //세일금액 변수 if($Row[0] == "1"){ $saleday = $Row['dealdate']; $saleprice = $saleprice + $Row['dc']; $i++; } if($Row[0] == "2"){ $sumsaleday = $Row['dealdate']; $sumsaleprice = $Row['dc']; } if($Row['code'] == "sumday"){ $totalday = $Row['dealdate']; $totalprice = $totalprice+$Row['dc']; $i++; } //일자별 입금액 소계 작업중 // if ($Row[dealdate] == $Row[dealdate]){ // } else if($Row[mamount]) { if($Row[0] == "2"){ $dcdate = $Row['dealdate']; } if($Row[0] == "1" and $dcdate = $Row['dealdate']){ $sumdc = $sumdc + $Row['dc']; $sumdate = $Row['dealdate']; $i++; } ?> <div class="books"> <dl> <dt class="books_day">일자 : <span><?=$Row['dealdate']?></span></dt>
<dd> <!-- 상품 : 회색부분1 시작 --> <?if($Row['code'] != "sumday" && $proResult != "[입금]"){ // 일계가 아닐때 처리?> <div class="optbox"> <ul class="optlist"> <?if($optmhide == "1"){?> <li> 상품명 : <span class="black"><?=$proResult?></span> </li> <li> 수량 : <span><?if(!$Row['qnt'] =="0"){ echo number_format($Row['qnt'],$optqtydec);}?></span> / 규격 : <span><?=$Row['pnorm']?></span> </li> <li> 입금액 : <span class="red"> <? if ($Row['code'] == "sumday"){ echo number_format($dPrice,$optpricedec); $dPrice = "0"; } if(!$Row['mamount'] =="0"){ echo number_format($Row['mamount'],$optpricedec); } ?> </span> / </li> <?}else{?> <li> 상품명 : <span class="black"><?=$proResult?></span> </li> <li> 단가 : <span class="blue"><? if(($Row['code'] == "sumday") or (! $Row['mamount'] == "")){ } else {echo number_format($Row['price'],$optdangadec);}?></span> / 수량 : <span><?if(!$Row['qnt'] =="0"){ echo number_format($Row['qnt'],$optqtydec);}?></span> / 규격 : <span><?=$Row['pnorm'];?> </span> </li> <li> 공급가액 : <span class="blue"><? if(!$Row['amount'] =="0"){ echo number_format($Row['amount'],$optpricedec);}?></span> / 부가세 : (+)<span class="black"><? if(!$Row['tax'] =="0"){ echo number_format($Row['tax'],$optpricedec);}?></span> / 할인 : (-)<span class="black"> <? if ( $Row[0] == "0" or $Row[0] == "1"){ echo number_format($Row['dc'],$optpricedec); }else if($Row[0] == "2"){ if ( $Row['dealdate'] == $dcdate and $Row[0] == "2"){ $totaldc = $sumdc +$Row['dc']; echo number_format($totaldc,$optpricedec); $sumdc = 0 ; } } ?></span> </li> <li> 합계액 : <span class="blue"><? if(!$Row['qnt'] =="0"){ echo number_format($Row['total'],$optpricedec);}?></span> / 입금액 : <span class="red"> <? if ($Row['code'] == "sumday"){ echo number_format($dPrice,$optpricedec); $dPrice = "0"; } if(!$Row['mamount'] =="0"){ echo number_format($Row['mamount'],$optpricedec); } ?> </span> / 잔액 : <span class="black"><?=number_format($dTotalMoney,$optpricedec)?></span> </li>
<!-- 주문개발 --> <!-- <li> 입금비고 : <span class="black">거래원장에서 cs에서 처리한 입금 비고표기란입니다.</span> </li> -->
<?}?> </ul> </div><!-- 상품 : 회색부분1 끝 --> <? }else if(! $Row['mamount'] == ""){ //입금일때 처리 ?> <!-- 입금 : 흰부분 --> <div class="income"> <div class="books_carry">입금액 : <? if ($Row['code'] == "sumday"){ echo number_format($dPrice,$optpricedec); $dPrice = "0"; } if(!$Row['mamount'] =="0"){ echo number_format($Row['mamount'],$optpricedec); } ?> <span class="fright">잔액 : <?=number_format($dTotalMoney,$optpricedec)?></span> </div> <?if($optbigo == 1){?> <div class="books_carry">비고 : <?=$Row['bigo']?></div> <?}?> </div><!-- 입금 : 흰부분 --> <? }else if($Row['code'] == "sumday"){ // 일계일때 처리 ?> <!-- 일계 : 파란부분 --> <div class="optsum"> <ul> <h2 class="sum_title">[ 일 계 ]</h2> <li> 수량 : <span><?if(!$Row['qnt'] =="0"){ echo number_format($Row['qnt'],$optqtydec);}?></span> <?if($optmhide != "1"){?>/ 공급가액 : <span class="blue"><? if(!$Row['amount'] =="0"){ echo number_format($Row['amount'],$optpricedec);}?></span> / 부가세 : (+)<span class="black"><? if(!$Row['tax'] =="0"){ echo number_format($Row['tax'],$optpricedec);}?></span> <?}?> </li> <?if($optmhide != "1"){?> <li> 할인 : (-)<span class="black"> <? if ( $Row[0] == "0" or $Row[0] == "1"){ echo number_format($Row['dc'],$optpricedec); }else if($Row[0] == "2"){ if ( $Row['dealdate'] == $dcdate and $Row[0] == "2"){ $totaldc = $sumdc +$Row['dc']; echo number_format($totaldc,$optpricedec); $sumdc = 0 ; } } ?> </span> / 합계액 : <span class="blue"><? if(!$Row['qnt'] =="0"){ echo number_format($Row['total'],$optpricedec);}?></span> </li> <?}?> <li> 입금액 : <span class="red"><? if ($Row['code'] == "sumday"){ echo number_format($dPrice,$optpricedec); $dPrice = "0"; } if(!$Row['mamount'] =="0"){ echo number_format($Row['mamount'],$optpricedec); } ?> </span> <?if($optmhide != "1"){?>/ 잔액 : <span class="black"><?=number_format($dTotalMoney,$optpricedec)?></span> <?}?> </li> </ul> </div><!-- 일계 : 파란부분 끝--> <?}?>
</dd> </dl> </div><!-- <div class="books"> --> <? } } } ?> <? $sum_sql = " SELECT 0, sum(price), sum(qnt), sum(amount), sum(tax), sum(dc), sum(total), '' AS mamount FROM sale AS s WHERE s.dealdate BETWEEN '{$txtdate}' AND '{$txtdate2}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' UNION ALL SELECT 1, '' AS price, '' AS qnt, '' AS amount, '' AS tax, sum(dc), '' AS total, sum(amount+usepoint) AS mamount FROM receive AS s WHERE s.dealdate BETWEEN '{$txtdate}' AND '{$txtdate2}' AND ocode = '{$sacode}' AND ccode = '{$cuscode}' ";
$all_sql .= $sum_sql." ";
$sumsql = $sum_sql . " "; $resultsum = mysql_query($sumsql) or die (mysql_error());
if( mysql_num_rows($resultsum) > 0 ){ while ($Rowsum = mysql_fetch_array($resultsum)){ $Tsum = $Tsum + $Rowsum['sum(qnt)']; $Tprice = $Tprice + $Rowsum['sum(price)']; $Tamount = $Tamount + $Rowsum['sum(amount)']; $Ttax = $Ttax + $Rowsum['sum(tax)']; $Tdc = $Tdc + $Rowsum['sum(dc)']; $Ttotal = $Ttotal + $Rowsum['sum(total)']; $T2amount = $T2amount + $Rowsum['mamount'];
$i++; } } ?> <!-- 수량 단가 공급가액 부가세 할인 합계액 입금액 잔액--> <? if($optmhide == "1"){ ?> <div class="books"> <ul class="books_carry"> <h2 class="sum_title">[ 검색기간 합계 ]</h2> <li> 수량 : <span><?=number_format($Tsum,$optqtydec)?></span> </li> <li> 잔액 : <span class="black"><?=number_format($dTotalMoney,$optpricedec)?></span> </li> </ul> </div> <?}else{?> <div class="books"> <ul class="books_carry"> <h2 class="sum_title">[ 검색기간 합계 ]</h2> <li> 수량 : <span><?=number_format($Tsum,$optqtydec)?></span> / 공급가액 : <span class="blue"><?=number_format($Tamount,$optpricedec)?></span> / 부가세 : (+)<span class="black"><?=number_format($Ttax,$optpricedec)?></span> </li> <li> 할인 : (-)<span class="black"><?=number_format($Tdc,$optpricedec)?></span> / 합계액 : <span class="blue"><?=number_format($Ttotal,$optpricedec)?></span> </li> <li> 입금액 : <span class="red"><?=number_format($T2amount,$optpricedec)?></span> / 잔액 : <span class="black"><?=number_format($dTotalMoney,$optpricedec)?></span> </li> </ul> </div> <?}?> <textarea style='display:none;'><?php echo $all_sql;?></textarea> <? include("./footer.php"); ?>
|