<!DOCTYPE html>
<html lang="ja">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<meta charset="UTF-8">
<title>受注参照</title>
<style>
body{
font-family: Meiryo, sans-serif;
font-size: 12px;
}
#view_tb{
border-collapse: collapse;
font-size: 12px;
}
#view_tb td, #view_tb th{
border: 1px dotted #ccc;
white-space: nowrap;
padding: 1px;
}
#view_tb tr:hover{
background-color: #eef;
}
#frm{
margin-bottom: 10px;
background-color: #eef;
}
#bk{
display: none;
}
#sav_tb td{
text-align: right;
}
.yen{
text-align: right;
}
.lnk{
cursor: pointer;
color: blue;
}
</style>
</head>
<body>
<a href="?view=受注一覧&offset=0" id="bk">戻る</a>
<div id="header">
<?php
require_once('config.php');
require_once('functions.php');
// 登録 //
if( $_GET['save'] == "登録"){
$n = date("Y-m-d");
echo <<< HTML
<form method="POST">
<table id="sav_tb">
<tr><td>区分:</td><td><input type="text" value="新規" disabled></td></tr>
<tr><td>型式:</td><td><input type="text"></td></tr>
<tr><td>工番(数値):</td><td><input type="text" value=0></td></tr>
<tr><td>数量(数値):</td><td><input type="text" value=0></td></tr>
<tr><td>納期:</td><td><input type="text" value="$n"></td></tr>
<tr><td>得意先:</td><td><input type="text"></td></tr>
<tr><td>単価(数値):</td><td><input type="text" value="0"></td></tr>
<tr><td>金額(数値):</td><td><input type="text" value="0" disabled></td></tr>
<tr><td>本社備考1:</td><td><input type="text"></td></tr>
<tr><td>本社備考2:</td><td><input type="text"></td></tr>
<tr><td>納期確定:</td><td><input type="text"></td></tr>
<tr><td>更新日:</td><td><input type="text" value="$n" disabled></td></tr>
<tr><td>作成日:</td><td><input type="text" value="$n" disabled></td></tr>
<tr>
<td></td>
<td><span class="lnk" id="sv">[登録]</span> <span class="lnk" id="abt">[中止]</span></td>
</tr>
</table>
</div><!-- header -->
</form>
<script>
$(function(){
// 登録 //
$(document).on('click', '#sv', function(){
var kubun = $("#sav_tb tr:nth-child(1) input").val();
var katashiki = $("#sav_tb tr:nth-child(2) input").val();
var kouban = parseInt($("#sav_tb tr:nth-child(3) input").val());
var suryo = parseInt($("#sav_tb tr:nth-child(4) input").val());
var nouki = $("#sav_tb tr:nth-child(5) input").val();
var tokuisaki = $("#sav_tb tr:nth-child(6) input").val();
var tanka = parseInt($("#sav_tb tr:nth-child(7) input").val());
var kingaku = parseInt($("#sav_tb tr:nth-child(8) input").val());
var honsyabikou1 = $("#sav_tb tr:nth-child(9) input").val();
var honsyabikou2 = $("#sav_tb tr:nth-child(10) input").val();
var noukikakutei = $("#sav_tb tr:nth-child(11) input").val();
var koushinbi = $("#sav_tb tr:nth-child(12) input").val();
var sakuseibi = $("#sav_tb tr:nth-child(13) input").val();
// nouki //
if (nouki != ""){
nouki = nouki.replace(/\//g,"-");
var d = new Date(nouki);
var mth = d.getMonth() + 1;
if( 1 <= mth && 12 >= mth && 10 > mth ){
mth = '0' + mth;
}else if( 1 <= mth && 12 >= mth ){
mth = mth;
}else{
alert("納期を確認してください(YYYY-MM-DD)");
return;
}
var day = d.getDate();
if( 1 <= day && 31 >= day && 10 > day ){
day = '0' + day;
}else if( 1 <= day && 31 >= day ){
day = day;
}else{
alert("納期を確認してください(YYYY-MM-DD)");
return;
}
nouki = d.getFullYear() + "-" + mth + "-" + day;
$("#sav_tb tr:nth-child(5) input").val(nouki);
}
// suryo tanka //
if((!isNaN(suryo)) && (!isNaN(tanka))){
kingaku = suryo * tanka;
$("#sav_tb tr:nth-child(8) input").val(kingaku);
}else{
alert("数量と単価を確認してください");
return;
}
// kouban //
if(isNaN(kouban)){
alert("工番を確認してください");
return;
}
if(confirm('登録しますか?')){
$.post('_save.php',{
kubun: kubun,
katashiki: katashiki,
kouban: kouban,
suryo: suryo,
nouki: nouki,
tokuisaki: tokuisaki,
tanka: tanka,
kingaku: kingaku,
honsyabikou1: honsyabikou1,
honsyabikou2: honsyabikou2,
noukikakutei: noukikakutei,
koushinbi: koushinbi,
sakuseibi: sakuseibi
},function(){
location.href="?view=受注一覧&offset=0";
});
}
});
// 中止 //
$(document).on('click', '#abt', function(){
location.href="?view=受注一覧&offset=0";
});
});
</script>
</body>
</html>
HTML;
exit;
}
// 受注一覧 在庫一覧 //
if( $_GET['view'] == "在庫一覧" ){
echo $_GET['view'];
$sql = "select * from order_tb where (入庫 is not null) and (出庫 is null)";
$cntsql = "select count(*) from order_tb where (入庫 is not null) and (出庫 is null)";
if (array_key_exists('型',$_GET)){
$sql = $sql . " and (型式 like '%" . $_GET['型'] . "%')";
$cntsql = $cntsql . " and (型式 like '%" . $_GET['型'] . "%')";
}
if (array_key_exists('工',$_GET)){
$sql = $sql . " and (工番 like '%" . $_GET['工'] . "%')";
$cntsql = $cntsql . " and (工番 like '%" . $_GET['工'] . "%')";
}
if (array_key_exists('納',$_GET) && $_GET['納'] != ""){
$sql = $sql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')";
$cntsql = $cntsql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')";
}
if (array_key_exists('得',$_GET)){
$sql = $sql . " and (得意先 like '%" . $_GET['得'] . "%')";
$cntsql = $cntsql . " and (得意先 like '%" . $_GET['得'] . "%')";
}
if (array_key_exists('本',$_GET)){
$sql = $sql . " and ((本社備考1 like '%" . $_GET['本'] . "%')";
$sql = $sql . " or (本社備考2 like '%" . $_GET['本'] . "%'))";
$cntsql = $cntsql . " and ((本社備考1 like '%" . $_GET['本'] . "%')";
$cntsql = $cntsql . " or (本社備考2 like '%" . $_GET['本'] . "%'))";
}
if (array_key_exists('更',$_GET) && $_GET['更'] != ""){
$sql = $sql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')";
$cntsql = $cntsql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')";
}
if (array_key_exists('作',$_GET) && $_GET['作'] != ""){
$sql = $sql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')";
$cntsql = $cntsql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')";
}
$sql = $sql . " limit " . $_GET['offset'] . ",100;";
$cntsql = $cntsql . ";";
}elseif( $_GET['view'] == "受注一覧" ){
echo $_GET['view'];
$sql = "select * from order_tb where (id is not null)";
$cntsql = "select count(*) from order_tb where (id is not null)";
if (array_key_exists('型',$_GET)){
$sql = $sql . " and (型式 like '%" . $_GET['型'] . "%')";
$cntsql = $cntsql . " and (型式 like '%" . $_GET['型'] . "%')";
}
if (array_key_exists('工',$_GET)){
$sql = $sql . " and (工番 like '%" . $_GET['工'] . "%')";
$cntsql = $cntsql . " and (工番 like '%" . $_GET['工'] . "%')";
}
if (array_key_exists('納',$_GET) && $_GET['納'] != ""){
$sql = $sql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')";
$cntsql = $cntsql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')";
}
if (array_key_exists('得',$_GET)){
$sql = $sql . " and (得意先 like '%" . $_GET['得'] . "%')";
$cntsql = $cntsql . " and (得意先 like '%" . $_GET['得'] . "%')";
}
if (array_key_exists('本',$_GET)){
$sql = $sql . " and ((本社備考1 like '%" . $_GET['本'] . "%')";
$sql = $sql . " or (本社備考2 like '%" . $_GET['本'] . "%'))";
$cntsql = $cntsql . " and ((本社備考1 like '%" . $_GET['本'] . "%')";
$cntsql = $cntsql . " or (本社備考2 like '%" . $_GET['本'] . "%'))";
}
if (array_key_exists('更',$_GET) && $_GET['更'] != ""){
$sql = $sql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')";
$cntsql = $cntsql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')";
}
if (array_key_exists('作',$_GET) && $_GET['作'] != ""){
$sql = $sql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')";
$cntsql = $cntsql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')";
}
$sql = $sql . " limit " . $_GET['offset'] . ",100;";
$cntsql = $cntsql . ";";
}else{
echo <<< HTML
<a href="?view=受注一覧&offset=0">受注一覧(入出庫管理)</a>
</div><!--header-->
</body>
</html>
HTML;
exit;
}
$db = con();
$rows = array();
$s = $db->query($cntsql);
if (array_key_exists('型',$_GET)){ echo "(検索結果)"; }
$cnt = $s->fetchColumn();
echo " " .$cnt . "件取得しました";
foreach($db->query($sql) as $row){
array_push($rows, $row);
}
?>
<form method="GET" id="frm">
<input type="submit" value="受注一覧" name="view">
<input type="submit" value="在庫一覧" name="view">
<input type="hidden" value="0" name="offset">
<?php if($_GET['offset'] > 0 && array_key_exists('型', $_GET)): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] - 100; ?>
&型=<?php echo $_GET['型']; ?>
&工=<?php echo $_GET['工']; ?>
&納=<?php echo $_GET['納']; ?>
&得=<?php echo $_GET['得']; ?>
&本=<?php echo $_GET['本']; ?>
&更=<?php echo $_GET['更']; ?>
&作=<?php echo $_GET['作']; ?>
">前へ</a>
<?php elseif($_GET['offset'] > 0): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] - 100; ?>">前へ</a>
<?php else: ?>
前へ
<?php endif; ?>
<?php if($_GET['offset'] + 100 < $cnt && array_key_exists('型', $_GET)): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] + 100; ?>
&型=<?php echo $_GET['型']; ?>
&工=<?php echo $_GET['工']; ?>
&納=<?php echo $_GET['納']; ?>
&得=<?php echo $_GET['得']; ?>
&本=<?php echo $_GET['本']; ?>
&更=<?php echo $_GET['更']; ?>
&作=<?php echo $_GET['作']; ?>
">次へ</a>
<?php elseif($_GET['offset'] + 100 < $cnt): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] + 100; ?>">次へ</a>
<?php else: ?>
次へ
<?php endif; ?>
<?php if($_GET['offset'] < (($cnt-1) - (($cnt-1) % 100)) && array_key_exists('型', $_GET)): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo ($cnt-1) - (($cnt-1) % 100); ?>
&型=<?php echo $_GET['型']; ?>
&工=<?php echo $_GET['工']; ?>
&納=<?php echo $_GET['納']; ?>
&得=<?php echo $_GET['得']; ?>
&本=<?php echo $_GET['本']; ?>
&更=<?php echo $_GET['更']; ?>
&作=<?php echo $_GET['作']; ?>
">最後へ</a>
<?php elseif($_GET['offset'] < (($cnt-1) - (($cnt-1) % 100))): ?>
<a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo ($cnt-1) - (($cnt-1) % 100); ?>">最後へ</a>
<?php else: ?>
最後へ
<?php endif; ?>
(<?php echo $_GET['offset'] + 1; ?>から<?php echo $_GET['offset'] + 100; ?>まで)
</form>
<form method="GET" id="frm">
<input type="submit" value="登録" name="save">
<input type="button" id="csv" value="書出">
</form>
<form method="GET" id="frm">
型:<input type="text" value="<?php echo $_GET['型']; ?>" size="8" name="型">
工:<input type="text" value="<?php echo $_GET['工']; ?>" size="8" name="工">
納:<input type="text" value="<?php echo $_GET['納']; ?>" size="8" name="納" id="n">
得:<input type="text" value="<?php echo $_GET['得']; ?>" size="8" name="得">
本:<input type="text" value="<?php echo $_GET['本']; ?>" size="8" name="本">
更:<input type="text" value="<?php echo $_GET['更']; ?>" size="8" name="更">
作:<input type="text" value="<?php echo $_GET['作']; ?>" size="8" name="作">
<input type="hidden" value="<?php echo $_GET['view']; ?>" name="view">
<input type="hidden" value="0" name="offset">
<input type="submit" value="取得">:
</form>
</div><!-- header -->
<div id="view">
<table id="view_tb">
<tr>
<th>区分</th>
<th>型式</th>
<th>工番</th>
<th>数量</th>
<th>納期</th>
<th>得意先</th>
<th>単価</th>
<th>金額</th>
<th>本社備考1</th>
<th>本社備考2</th>
<th>納期確定</th>
<th>更新日</th>
<th>作成日</th>
<th>入庫</th>
<th>出庫</th>
<th>入庫</th>
<th>出庫</th>
<th>入消</th>
<th>出消</th>
<th></th>
<th>分割</th>
<th>回数</th>
<th>削除</th>
</tr>
<?php for($i = 0, $total = 0; $i < count($rows); $i++ ): ?>
<tr id="r_<?php echo $rows[$i][0]; ?>" data-id="<?php echo $rows[$i][0]; ?>">
<td><?php echo $rows[$i][2]; ?></td>
<td><?php echo $rows[$i][4]; ?></td>
<td><?php echo $rows[$i][5]; ?></td>
<td><?php echo $rows[$i][9]; ?></td>
<td><?php echo $rows[$i][10]; ?></td>
<td><?php echo $rows[$i][15]; ?></td>
<td class="lnk yen" id="plice"><?php echo $rows[$i][16]; ?></td>
<td class="yen"><?php echo $rows[$i][17]; ?></td>
<td><?php echo $rows[$i][18]; ?></td>
<td><?php echo $rows[$i][19]; ?></td>
<td><?php echo $rows[$i][20]; ?></td>
<td><?php echo $rows[$i][22]; ?></td>
<td><?php echo $rows[$i][23]; ?></td>
<td><?php echo $rows[$i][24]; ?></td>
<td><?php echo $rows[$i][25]; ?></td>
<td class="lnk" id="rcv">[入庫]</td>
<td class="lnk" id="shp">[出庫]</td>
<td class="lnk" id="d_rcv">[入消]</td>
<td class="lnk" id="d_shp">[出消]</td>
<td><input id="inp" type="text" size="1"></td>
<td class="lnk" id="sp">[分割]</td>
<td><?php echo $rows[$i][26]; ?></td>
<td class="lnk" id="del">[削除]</td>
</tr>
<?php $total = $total + $rows[$i][17]; ?>
<?php endfor; ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="yen"><?php echo number_format($total); ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div><!--view-->
<script>
$(function(){
// 削除 //
$(document).on('click', '#del', function(){
if(confirm('削除しますか?')){
var id = $(this).parent().data('id');
$.post('_delete.php',{id: id},function(){
$('#r_' + id).fadeOut(300);
location.reload();
});
}
});
// 入庫 //
$(document).on('click', '#rcv', function(){
if(confirm('入庫しますか?')){
var id = $(this).parent().data('id');
$.post('_rcv.php',{id: id},function(rs){
$('#r_' + id + " > td:nth-child(14)").text(rs);
});
}
});
// 出庫 //
$(document).on('click', '#shp', function(){
if(confirm('出庫しますか?')){
var id = $(this).parent().data('id');
$.post('_shp.php',{id: id},function(rs){
$('#r_' + id + " > td:nth-child(15)").text(rs);
});
}
});
// 入消 //
$(document).on('click', '#d_rcv', function(){
if(confirm('入庫を取消しますか?')){
var id = $(this).parent().data('id');
$.post('_d_rcv.php',{id: id},function(){
$('#r_' + id + " > td:nth-child(14)").text("");
});
}
});
// 出消 //
$(document).on('click', '#d_shp', function(){
if(confirm('出庫を取消しますか?')){
var id = $(this).parent().data('id');
$.post('_d_shp.php',{id: id},function(){
$('#r_' + id + " > td:nth-child(15)").text("");
});
}
});
// 分割 //
$(document).on('click', '#sp', function(){
var id = $(this).parent().data('id');
var num = parseInt($('#r_' + id + " > td:nth-child(4)").text());
var plice = parseInt($('#r_' + id + " > td:nth-child(7)").text());
var p_num = parseInt($('#r_' + id + ' input').val());
if(!isNaN(p_num) && num > p_num && p_num > 0){
if(confirm('受注数 ' + num + ' から ' + p_num + ' を別の行に複製します')){
num = num - p_num;
$.post('_pull_num.php',{id: id, num: num, p_num: p_num, plice: plice},function(){
$('#r_' + id).fadeOut(300,function(){
location.reload();
});
});
}
}
});
// 単価 //
$(document).on('click', '#plice',function(){
var id = $(this).parent().data('id');
var num = parseInt($('#r_' + id + " > td:nth-child(4)").text());
var plice = parseInt(prompt("単価を入力してください"));
if(!isNaN(plice) && !isNaN(plice * num)){
$.post('_plice.php',{id: id, num: num, plice: plice},function(){
$('#r_' + id + " > td:nth-child(7)").text(plice);
$('#r_' + id + " > td:nth-child(8)").text(plice * num);
location.reload();
});
}
});
// 書出 //
var flg = true;
$(document).on('click', '#csv',function(){
if(flg){
flg = false;
$("#view_tb th:nth-child(n+16):nth-child(-n+21), td:nth-child(n+16):nth-child(-n+21)").remove();
$("#view_tb th:nth-last-child(1), td:nth-last-child(1)").remove();
$("#header").css("display","none");
$("#bk").css("display","inline");
}
});
});
</script>
</body>
</html>