Mini Shell

Direktori : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/fertilizer/
Upload File :
Current File : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/new/fertilizer/fertilizer_sum.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_home" method="get" action="fertilizer_sum.php">
                                       <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 ($Result = mysqli_fetch_array($sql)) {
                                                   ?>
                                                   <option value="<?php echo $Result['sahakornID']; ?>">
                                                   <?php echo $Result['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
                                           $Query = 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 ($Result = mysqli_fetch_array($Query)) {
                                                   ?>
                                                   <option value="<?php echo $Result['formulaID']; ?>">
                                                   <?php echo $Result['name_formula']; ?>
                                                   </option>
                                                     <?php
                                                      }
                                                       ?>     
                                                   </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <label class="col-md-4 label-on-left">ปุ๋ยผสมคงเหลือยกมาต้นปี</label>
                                            <div class="col-md-8">
                                                <div class="form-group label-floating is-empty">
                                                    <label class="cont rol-label"></label>
                                                    <input name="fertilizer1" id="fertilizer1" type="number" class="form-control" required>
                                                </div>
                                            </div>
                                        </div>   
                                         <div class="row">
                                            <label class="col-md-4 label-on-left">ขายปุ๋ยผสม</label>
                                            <div class="col-md-8">
                                                <div class="form-group label-floating is-empty">
                                                    <label class="control-label"></label>
                                                    <input name="fertilizer2" id="fertilizer2" type="number" class="form-control" required>
                                                </div>
                                            </div>
                                        </div> 
                                        <div class="row">
                                            <label class="col-md-4 label-on-left">เบิกใช้</label>
                                            <div class="col-md-8">
                                                <div class="form-group label-floating is-empty">
                                                    <label class="control-label"></label>
                                                    <input name="fertilizer22" id="fertilizer22" type="number" class="form-control" required>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <label class="col-md-4 label-on-left">ปริมาณนับได้(กระสอบ)</label>
                                            <div class="col-md-8">
                                                <div class="form-group label-floating is-empty">
                                                    <label class="control-label"></label>
                                                    <input name="fertilizer3" id="fertilizer3" type="number" class="form-control" required>
                                                </div>
                                            </div>
                                        </div> 
                                        <div class="row">
                                            <label class="col-md-3"></label>
                                            <div class="col-md-9">
                                                <div class="form-group form-button">
                                                    <button 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'] : '';
                    $fertilizer1 = isset($_GET['fertilizer1']) ? $_GET['fertilizer1'] : '';
                    $fertilizer2 = isset($_GET['fertilizer2']) ? $_GET['fertilizer2'] : '';
                    $fertilizer3 = isset($_GET['fertilizer3']) ? $_GET['fertilizer3'] : '';
                    $fertilizer22 = isset($_GET['fertilizer22']) ? $_GET['fertilizer22'] : '';
                    
                     if (empty($year)){
                             
                   //ถ้าว่าง
                                 
                    } else {
                    
                   //ลูปดึงข้อมูลมาคำนวน
                    $sql_report1 = "SELECT * FROM sahakorn_process WHERE sahakornID = $sahakorn AND year = $year AND formulaID = $formula ";
                    $result_report1 = mysqli_query($link, $sql_report1);

                      $sum_sum = 0.00;
                       while ($row_report1 = mysqli_fetch_array($result_report1))  { 
                              $sum_sum = $sum_sum + $row_report1['sum'];
                              
                       }
                       $sum_sum1 = $fertilizer1 + $sum_sum;
                       
                   //สูตรคำนวน
                    $sum = $sum_sum1 - $fertilizer2 - $fertilizer22;
                    $sum1 = $sum/50;
                    $sum2 = $fertilizer3 - $sum1;
                        //เช็คข้อมูลซ้ำเพื่อบันทึกหรืออัพเดท
                        $sql_calculate = "SELECT sahakornID,year,formulaID FROM calculate_remaining WHERE sahakornID ='$sahakorn' and year ='$year' and formulaID = '$formula' ";
                        $result_calculate = mysqli_query($link, $sql_calculate);
                        $is_calculate = mysqli_num_rows($result_calculate);
                        if ($is_calculate == 1) {
                           $sql_update_remaining = "UPDATE `calculate_remaining` SET`sahakornID`='$sahakorn',`year`='$year',`formulaID`='$formula',`remaining_pui`='$fertilizer1',`from_production`='$sum_sum',`sell_pui`='$fertilizer2',`use`='$fertilizer22',`pui_year_balance`='$sum',`sack_R`='$sum1',`countable_R`='$fertilizer3',`tooshort_R`='$sum2' WHERE (`sahakornID`='$sahakorn') and (`year`='$year') and (`formulaID`='$formula')";
                           $result_update_remaining = mysqli_query($link, $sql_update_remaining);  
                        }else {
                           $sql_insert_remaining = "INSERT INTO `calculate_remaining`(`sahakornID`,`year`,`formulaID`,`remaining_pui`,`from_production`,`sell_pui`,`use`,`pui_year_balance`,`sack_R`,`countable_R`,`tooshort_R`) VALUES 
                           ('$sahakorn','$year','$formula','$fertilizer1','$sum_sum','$fertilizer2','$fertilizer22','$sum','$sum1','$fertilizer3','$sum2')";
                           $result_insert_remaining = mysqli_query($link, $sql_insert_remaining);
                        }
                    
                        //ดึงข้อมูลจากตารางมาแสดง
                        $sql_report2 = "SELECT * FROM calculate_remaining 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_report2 = mysqli_query($link, $sql_report2); 
                        //ดึงข้อมูลแสดงสวนหัว
                         $sql_name = "SELECT * FROM sahakorn WHERE sahakornID = $sahakorn ";
                         $result_name = mysqli_query($link, $sql_name);
                         $name_sahakorn = mysqli_fetch_assoc($result_name);
                        
                    ?>
                        
                           <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-center">ปุ๋ยผสมคงเหลือยกมาต้นปี</th>
                                            <th  class="text-center">รับจาการผลิต</th>
                                            <th  class="text-center">รวม</th> 
                                            <th  class="text-center">ขายปุ๋ยผสม</th>
                                            <th  class="text-center">เบิกใช้</th>
                                            <th  class="text-center">ปุ๋ยผสมคงเหลือสิ้นปี</th>
                                            <th  class="text-center">คิดเป็นกระสอบ</th>
                                            <th  class="text-center">ปริมาณนับได้</th>
                                            <th  class="text-center">ขาด/เกิน</th>
                                        </thead>
                                    <?php 
                                              $sum_sum11 = 0.00;
                                               while ($row_report2 = mysqli_fetch_array($result_report2))  {   
                                                   
                                                   $sum_sum11 = $row_report2['remaining_pui']+$row_report2['from_production'];
                                                   
                                                   ?>
                                        <tbody>
                                            <tr>
                                                <td class="text-center"><?php echo $row_report2['name_formula']; ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['remaining_pui'],2); ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['from_production'],2);  ?></td>
                                                <td class="text-center"><?php echo number_format($sum_sum11,2); ?></td> 
                                                <td class="text-center"><?php echo number_format($row_report2['sell_pui'],2); ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['use'],2); ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['pui_year_balance'],2); ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['sack_R'],2); ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['countable_R'],2);  ?></td>
                                                <td class="text-center"><?php echo number_format($row_report2['tooshort_R'],2);  ?></td>
                                            </tr>
                                     <?php  } ?>      
                                        </tbody>
                                    </table>
                                </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>

Zerion Mini Shell 1.0