| Direktori : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/fertilizer/ |
| Current File : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/fertilizer/fertilizer_home.php |
<!doctype html>
<html lang="en">
<!-- head -->
<?php include 'head.php'; ?>
<body>
<div class="wrapper">
<!-- เมนูด้านซ้าย -->
<?php include 'leftside.php'; ?>
<div class="main-panel">
<!-- ส่วนหัว -->
<?php include 'header.php'; ?>
<?php include 'db/database.php';
?>
<div class="content">
<div class="container-fluid">
<div class="col-md-6">
<div class="card">
<div class="card-header card-header-icon" data-background-color="rose">
<i class="material-icons"><i class="fas fa-chalkboard-teacher"></i></i>
</div>
<div class="card-content">
<h4 class="card-title">แปรรูปปุ๋ยผสม</h4>
<form class="form-horizontal" id="form_fertilizer" method="get" >
<div class="row">
<label class="col-md-4 label-on-left">กรุณาเลือกสหกรณ์</label>
<div class="col-md-8">
<?php
$sql = mysqli_query($link,'SELECT * FROM sahakorn') or die('Error query #12');
?>
<div class="form-group label-floating is-empty">
<label class="control-label"></label>
<select name="sahakorn" id="sahakorn" class="selectpicker" data-live-search="true" title="กรุณาเลือกสหกรณ์">
<?php
while ($Result1 = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $Result1['sahakornID']; ?>">
<?php echo $Result1['name']; ?>
</option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4 label-on-left">กรุณาเลือกปีบัญชี</label>
<div class="col-md-8">
<?php
$year4=(date("Y")+543);
$year1=(date("Y")+543-1);
$year2=(date("Y")+543-2);
$year3=(date("Y")+543+1);
?>
<div class="form-group label-floating is-empty">
<label class="control-label"></label>
<select name="year" id="year" class="form-control" title="กรุณาเลือกปีบัญชี" required>
<option value="">กรุณาเลือก...</option>
<?php
echo '<option value="'.$year4.'" '.$selected.'>'.$year4.'</option>'."\n";
echo '<option value="'.$year1.'" '.$selected.'>'.$year1.'</option>'."\n";
echo '<option value="'.$year2.'" '.$selected.'>'.$year2.'</option>'."\n";
echo '<option value="'.$year3.'" '.$selected.'>'.$year3.'</option>'."\n";
?>
</select>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4 label-on-left">กรุณาเลือกสูตรปุ๋ยผสม</label>
<div class="col-md-8">
<?php
$sql2 = mysqli_query($link,'SELECT * FROM formula') or die('Error query #12');
?>
<div class="form-group label-floating is-empty">
<label class="control-label"></label>
<select name="formula" id="formula" class="form-control" title="กรุณาเลือกสูตรปุ๋ยผสม" required>
<option value="">กรุณาเลือก...</option>
<?php
while ($Result2 = mysqli_fetch_array($sql2)) {
?>
<option value="<?php echo $Result2['formulaID']; ?>">
<?php echo $Result2['name_formula']; ?>
</option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4 label-on-left">จำนวนปุ๋ยที่ผสม<font color="red"> (เป็นกระสอบ)</font></label>
<div class="col-md-8">
<div class="form-group label-floating is-empty">
<label class="control-label"></label>
<input name="fertilizer" id="fertilizer" type="number" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<label class="col-md-4"></label>
<div class="col-md-8">
<div class="form-group form-button">
<button id="submit" type="submit" class="btn btn-fill btn-rose">บันทึก</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<?php
$sahakorn = isset($_GET['sahakorn'])? $_GET['sahakorn'] : '';
$year = isset($_GET['year']) ? $_GET['year'] : '';
$formula = isset($_GET['formula']) ? $_GET['formula'] : '';
$fertilizer = isset($_GET['fertilizer']) ? $_GET['fertilizer'] : '';
$sql_report = "SELECT * FROM formula WHERE `formulaID`='$formula' ";
$result_report = mysqli_query($link, $sql_report);
$row = mysqli_fetch_assoc($result_report);
//สูตรคำนวน
$calculate = $fertilizer*50;
$calculate1 = $row['46-0-0']/50;
$calculate2 = $row['18-46-0']/50;
$calculate3 = $row['0-0-60']/50;
$result1 = $calculate*$calculate1;
$result2 = $calculate*$calculate2;
$result3 = $calculate*$calculate3;
$result_sum = $result1+$result2+$result3;
//เช็คชือซ้ำหรือไม่
$sql_formula = "SELECT sahakornID,year,formulaID FROM sahakorn_process WHERE sahakornID ='$sahakorn' and year ='$year' and formulaID = '$formula' ";
$result_formula = mysqli_query($link, $sql_formula);
$is_formula = mysqli_num_rows($result_formula);
if ($is_formula > 1) {
$sql_update1 = "UPDATE `sahakorn_process` SET `sahakornID`='$sahakorn',`year`='$year',`formulaID`='$formula' ,`sack`='$fertilizer' ,`S_mother_pui`='46-0-0' ,`sum`='$result1' WHERE (`formulaID`='$formula') and (`sahakornID`='$sahakorn') and (`year`='$year') and (`S_mother_pui`='46-0-0')";
$result_update1 = mysqli_query($link, $sql_update1);
$sql_update2 = "UPDATE `sahakorn_process` SET `sahakornID`='$sahakorn',`year`='$year',`formulaID`='$formula' ,`sack`='$fertilizer' ,`S_mother_pui`='18-46-0' ,`sum`='$result2' WHERE (`formulaID`='$formula') and (`sahakornID`='$sahakorn') and (`year`='$year') and (`S_mother_pui`='18-46-0')";
$result_update2 = mysqli_query($link, $sql_update2);
$sql_update3 = "UPDATE `sahakorn_process` SET `sahakornID`='$sahakorn',`year`='$year',`formulaID`='$formula' ,`sack`='$fertilizer' ,`S_mother_pui`='0-0-60' ,`sum`='$result3' WHERE (`formulaID`='$formula') and (`sahakornID`='$sahakorn') and (`year`='$year') and (`S_mother_pui`='0-0-60')";
$result_update3 = mysqli_query($link, $sql_update3);
}else {
$sql_insert1 = "INSERT INTO `sahakorn_process` (`sahakornID`,`year`,`formulaID`,`sack`,`S_mother_pui`,`sum`) VALUES
('$sahakorn','$year','$formula','$fertilizer','46-0-0','$result1')";
$result_insert1 = mysqli_query($link, $sql_insert1);
$sql_insert2 = "INSERT INTO `sahakorn_process` (`sahakornID`,`year`,`formulaID`,`sack`,`S_mother_pui`,`sum`) VALUES
('$sahakorn','$year','$formula','$fertilizer','18-46-0','$result2')";
$result_insert2 = mysqli_query($link, $sql_insert2);
$sql_insert3 = "INSERT INTO `sahakorn_process` (`sahakornID`,`year`,`formulaID`,`sack`,`S_mother_pui`,`sum`) VALUES
('$sahakorn','$year','$formula','$fertilizer','0-0-60','$result3')";
$result_insert3 = mysqli_query($link, $sql_insert3);
}
?>
<?php
if (empty($sahakorn)){
} else {
?>
<?php
$sql_name = "SELECT * FROM sahakorn WHERE sahakornID = $sahakorn ";
$result_name = mysqli_query($link, $sql_name);
$name_sahakorn = mysqli_fetch_assoc($result_name);
?>
<?php
//ลูบข้อมูลจากตารางมาแสดง
$sql = "SELECT DISTINCT fl.name_formula as'sut',t1.sack as'sk', t2.sum as'46-0-0',t3.sum as'18-46-0',t4.sum as'0-0-60'
FROM sahakorn AS sk
INNER JOIN sahakorn_process AS t1 ON t1.sahakornID=sk.sahakornID
INNER JOIN sahakorn_process AS t2 ON t2.S_mother_pui='46-0-0' AND t2.sahakornID=sk.sahakornID AND t1.sack=t2.sack AND t1.formulaID=t2.formulaID AND t1.`year`=t2.`year`
INNER JOIN sahakorn_process AS t3 ON t3.S_mother_pui='18-46-0' AND t3.sahakornID=sk.sahakornID AND t2.sack=t3.sack AND t2.formulaID=t3.formulaID AND t2.`year`=t3.`year`
INNER JOIN sahakorn_process AS t4 ON t4.S_mother_pui='0-0-60' AND t4.sahakornID=sk.sahakornID AND t3.sack=t4.sack AND t3.formulaID=t4.formulaID AND t3.`year`=t4.`year`
INNER JOIN formula AS fl ON fl.formulaID=t1.formulaID WHERE t1.sahakornID=$sahakorn and t1.year = $year";
$result = mysqli_query($link, $sql);
?>
<div class="col-lg-11 col-md-12">
<div class="card">
<div class="card-header card-header-tabs" data-background-color="rose">
<h4 class="card-title">แปรรูปปุ๋ยผสม <?php echo $name_sahakorn['name']; ?> ปี <?php echo $year; ?></h4>
</div>
<div class="card-content table-responsive" >
<table id="datatables" class="table table-hover">
<thead class="text-success">
<th class="text-center">สูตรปุ๋ยที่ผสม</th>
<th class="text-right">จำนวนที่ผสม(เป็นกระสอบ)</th>
<th class="text-right">แม่ปุ๋ย46-0-0</th>
<th class="text-right">แม่ปุ๋ย18-46-0</th>
<th class="text-right">แม่ปุ๋ย0-0-60</th>
<th class="text-right">รวมทั้งสิ้น(กิโลกรัม)</th>
</thead>
<?php
$total_sack = 0.00;
$total_46 = 0.00;
$total_18 = 0.00;
$total_0 = 0.00;
$total_sum = 0.00;
while ($row_loop = mysqli_fetch_array($result)) {
$total = 0.00;
$total = $total + $row_loop['46-0-0'] + $row_loop['18-46-0'] + $row_loop['0-0-60'];
$total_sack = $total_sack + $row_loop['sk'];
$total_46 = $total_46 + $row_loop['46-0-0'];
$total_18 = $total_18 + $row_loop['18-46-0'];
$total_0 = $total_0 + $row_loop['0-0-60'];
$total_sum = $total_sum + $total;
?>
<tr>
<td class="text-center"><?php echo $row_loop['sut']; ?></td>
<td class="text-right"><?php echo number_format($row_loop['sk'],2); ?></td>
<td class="text-right"><?php echo number_format($row_loop['46-0-0'],2); ?></td>
<td class="text-right"><?php echo number_format($row_loop['18-46-0'],2); ?></td>
<td class="text-right"><?php echo number_format($row_loop['0-0-60'],2); ?></td>
<td class="text-right"><?php echo number_format($total,2); ?></td>
</tr>
<tbody>
<?php } ?>
<tr>
<td class="text-center">ผลรวม</td>
<td class="text-right"> <?php echo number_format($total_sack,2); ?> </td>
<td class="text-right"> <?php echo number_format($total_46,2); ?> </td>
<td class="text-right"> <?php echo number_format($total_18,2); ?> </td>
<td class="text-right"> <?php echo number_format($total_0,2); ?> </td>
<td class="text-right"> <?php echo number_format($total_sum,2); ?> </td>
</tr>
</tbody>
<?php
$sql_report1 = "SELECT * FROM sahakorn_process AS t1 LEFT JOIN sahakorn AS t2 ON (t1.sahakornID = t2.sahakornID) LEFT JOIN formula AS t3 ON (t1.formulaID = t3.formulaID) WHERE t1.sahakornID = $sahakorn AND t1.year = $year ";
$result_report1 = mysqli_query($link, $sql_report1);
$sum_sack = 0.00;
$sack46 = 0.00;
$sack18 = 0.00;
$sack0 = 0.00;
$sum1 = 0.00;
$sum2 = 0.00;
$sum3 = 0.00;
$sum_sum = 0.00;
while ($row_report1 = mysqli_fetch_array($result_report1)) { ?>
<?php
$sum_sack = $sum_sack+$row_report1['sack'];
// $sum46 = $row_report1['S_mother_pui'];
if ($row_report1['S_mother_pui'] == '46-0-0') {
$sum1 = $sum1 + $row_report1['sum'];
$sack46 = $sack46 + $row_report1['sack'];
}elseif ($row_report1['S_mother_pui'] == '18-46-0') {
$sum2 = $sum2 + $row_report1['sum'];
$sack18 = $sack18 + $row_report1['sack'];
}elseif ($row_report1['S_mother_pui'] == '0-0-60') {
$sum3 = $sum3 + $row_report1['sum'];
$sack0 = $sack0 + $row_report1['sack'];
}
$sum_sum = $sum_sum+$row_report1['sum'];
?>
<?php } ?>
</table>
<?php
if (empty($sum_sack)) {
} else {
//เช็คชือซ้ำหรือไม่
$sql_mother_pui = "SELECT sahakornID,year FROM mother_pui WHERE sahakornID ='$sahakorn' and year ='$year'";
$result_mother_pui = mysqli_query($link, $sql_mother_pui);
$is_mother_pui = mysqli_num_rows($result_mother_pui);
if ($is_mother_pui > 1) {
$sql_update_mother_pui1 = "UPDATE `mother_pui` SET`sahakornID`='$sahakorn',`year`='$year',`m_sack`='$sack46',`name_pui`='46-0-0',`m_sum`='$sum1' WHERE (`sahakornID`='$sahakorn') and (`year`='$year') and (`name_pui`='46-0-0')";
$result_update_mother_pui1 = mysqli_query($link, $sql_update_mother_pui1);
$sql_update_mother_pui2 = "UPDATE `mother_pui` SET`sahakornID`='$sahakorn',`year`='$year',`m_sack`='$sack18',`name_pui`='18-46-0',`m_sum`='$sum2' WHERE (`sahakornID`='$sahakorn') and (`year`='$year') and (`name_pui`='18-46-0')";
$result_update_mother_pui2 = mysqli_query($link, $sql_update_mother_pui2);
$sql_update_mother_pui3 = "UPDATE `mother_pui` SET`sahakornID`='$sahakorn',`year`='$year',`m_sack`='$sack0',`name_pui`='0-0-60',`m_sum`='$sum3' WHERE (`sahakornID`='$sahakorn') and (`year`='$year') and (`name_pui`='0-0-60')";
$result_update_mother_pui3 = mysqli_query($link, $sql_update_mother_pui3);
} else {
$sql_insert_mother_pui1 = "INSERT INTO `mother_pui` (`sahakornID`,`year`,`m_sack`,`name_pui`,`m_sum`) VALUES
('$sahakorn','$year','$sack46','46-0-0','$sum1')";
$result_insert_mother_pui1 = mysqli_query($link, $sql_insert_mother_pui1);
$sql_insert_mother_pui2 = "INSERT INTO `mother_pui` (`sahakornID`,`year`,`m_sack`,`name_pui`,`m_sum`) VALUES
('$sahakorn','$year','$sack18','18-46-0','$sum2')";
$result_insert_mother_pui2 = mysqli_query($link, $sql_insert_mother_pui2);
$sql_insert_mother_pui3 = "INSERT INTO `mother_pui` (`sahakornID`,`year`,`m_sack`,`name_pui`,`m_sum`) VALUES
('$sahakorn','$year','$sack0','0-0-60','$sum3')";
$result_insert_mother_pui3 = mysqli_query($link, $sql_insert_mother_pui3);
}
}
?>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<!-- footer1 -->
<?php include 'footer1.php'; ?>
</div>
</div>
<!-- footer2 -->
<?php include 'footer2.php'; ?>
<!-- Mirrored from demos.creative-tim.com/material-dashboard-pro/examples/dashboard.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 20 Mar 2017 21:32:16 GMT -->
</html>