<?php







 include('db_con.php');







  







  include('function.php');







  







  if (isset($_SESSION['user_id'])) {







    $user_type = $_SESSION['user_type'];







    $user_id = $_SESSION['user_id'];







    $user_name = $_SESSION['user_name'];







    $branch_id = $_SESSION['branch_id'];







    $branch_name = $_SESSION['branch_name'];







    $store_id = $_SESSION['store_id'];







    $store_name = $_SESSION['store_name'];







}else{







  header('Location: login');







  die();







}







  $do_id = $_GET["id"];















  















if(isset($_POST["update"]))







  {       















      $statement = $connect->prepare("







                DELETE FROM do_detail WHERE do_id = :do_id and item_status = 'Not Approved'







            ");







            $statement->execute(







                array(







                    ':do_id'       =>      $do_id







                )







            );















      for($count=0; $count<$_POST["total_item"]; $count++)







      {















        $statement = $connect->prepare("







          INSERT INTO do_detail







          (do_id,item_no,store_id,ctn,qty,item_status)







          VALUES(:do_id, :item_no, :store_id, :ctn, :qty, :item_status)







        ");















        $statement->execute(







          array(







            ':do_id'               =>  $do_id,







            ':item_no'              =>  trim($_POST["item_no"][$count]),







            ':store_id'              =>  $store_id,







            ':ctn'              =>  trim($_POST["ctn"][$count]),







            ':qty'          =>  trim($_POST["qty"][$count]),            







            ':item_status'           =>  trim($_POST["item_status"][$count])







          )







        );































        







        //$result = $statement->fetchAll();







      }















       































      























      header("location: dashboard.php");







    }







































    ?>















<!DOCTYPE html>







<html>







<head>







  <?php include('include/head.php'); ?>







  <link rel="stylesheet" href="css/datepicker.css">







  <link rel="stylesheet" href="css/jquery.datetimepicker.css">







  <link rel="stylesheet" href="css/jquery.datetimepicker.min.css">







  <link rel="stylesheet" href="css/jquery.jquery-ui.min.css">







  







  







</head>







<body>







  <?php include('include/header.php'); ?>







  <?php include('include/sidebar.php'); ?>







<div class="main-container">















  <!-- Content Wrapper. Contains page content -->







  <div class="content-wrapper">







    <!-- Content Header (Page header) -->







    <div class="content-header">







      <div class="container-fluid">







        <div class="row mb-2">







          <div class="col-sm-6">







            <h1 class="m-0 text-dark"></h1>







          </div><!-- /.col -->







          <div class="col-sm-6">







            <ol class="breadcrumb float-sm-right">







              <li class="breadcrumb-item"><a href="#">Inventory</a></li>







              <li class="breadcrumb-item"><a href="#">Delivery Orders</a></li>







              <li class="breadcrumb-item active">ALL </li>







            </ol>







          </div><!-- /.col -->







        </div><!-- /.row -->







      </div><!-- /.container-fluid -->







    </div>







    <!-- /.content-header -->















    <!-- Main content -->







    <section class="content">







      <div class="container-fluid">







      <?php







      if(isset($_GET["detail"]))







      {















     







        $statement = $connect->prepare("







          SELECT m.s_id,c.name cust_name,m.dated,s.store_name,m.description FROM do 







            m, store s, sale l,customers c WHERE s.store_id = m.store_id and m.do_id = :do_id and m.s_id=l.s_id and l.cust_id=c.cust_id 







            LIMIT 1







        ");







        $statement->execute(







          array(







            ':do_id'       =>  $do_id







            )







          );







        $result = $statement->fetchAll();







        foreach($result as $row)







        {







        ?>







         <script src="vendors/scripts/script.js"></script>







        <script>







        $(document).ready(function(){















          $('.do_id').text("<?php echo $do_id; ?>");







          $('.s_id').text("<?php echo $row["s_id"]; ?>"); 







           $('.store_name').text("<?php echo $row["store_name"]; ?>"); 







            $('.description').text("<?php echo $row["description"]; ?>"); 



            $('.cust_name').text("<?php echo $row["cust_name"]; ?>"); 







        







       







         







                







         















        });







        </script>















       







        <form method="post" id="sale_form" AutoComplete="off" />















        <div class="table-responsive">







          <table class="table table-bordered">







            <tr>







              <td colspan="2" align="center"><h2 style="margin-top:10.5px">Delivery Order</h2></td>







            </tr>







            <br />







            <br />







            <tr>







                <td colspan="2">







                  <table id="tbl_main" class="table table-bordered" />







                  <tr><td>Do ID</td><td>Sale ID</td><td>Customer</td><td>From Store</td><td>Description</td></tr>







                  







                  <tr><td><span class="do_id"></span></td><td><span class="s_id"></span></td><td><span class="cust_name"></td><td><span class="store_name"></span></td><td><span class="description"></span></td></tr>















                  </table>







                  <br />







                  <table width="100%" id="invoice-item-table" class="table table-bordered">







                     <tr>







                      <th width="5%">Sr#.</th>







                      







                      <th width="50%">Item Name</th>







                      <th width="10%">Ctn</th>







                      <th width="10%">Qty</th>







                      <th width="35%">Status</th>







                  







                    </tr>







                   







                    







                    <?php







                    $statement = $connect->prepare("







                      SELECT sum(d.qty) from do_detail d







                      WHERE d.do_id = :do_id and d.store_id = :store_id 







                      and d.item_status = 'Not Approved'







                    ");







                    $statement->execute(







                      array(







                        ':do_id'       =>  $do_id,







                         ':store_id'       =>  $store_id







                      )







                    );







                    $tot_qty = $statement->fetchcolumn();







                    $statement = $connect->prepare("







                      SELECT d.item_no,CONCAT(i.item_name,' ',t.type_name, ' ' ,b.brand_name, ' ', l.color_name) as item_name,d.ctn,d.qty,d.item_status from do_detail d, items i ,item_brand b,item_type t,item_color l 







                      WHERE i.item_id=d.item_no and i.brand_id=b.brand_id and i.color_id=l.color_id and t.type_id=i.type_id and d.do_id = :do_id and d.store_id = :store_id







                      and d.item_status = 'Not Approved'







                    ");







                    $statement->execute(







                      array(







                        ':do_id'       =>  $do_id,







                         ':store_id'       =>  $store_id







                      )







                    );







                    $item_result = $statement->fetchAll();







                    $m = 0;







                    foreach($item_result as $sub_row)







                    {







                      $m = $m + 1;







                    ?>







                    <tr>







                      <td><span id="sr_no"><?php echo $m; ?></span></td>







                      <td><select name="item_no[]" id="item_no<?php echo $m; ?>" data-srno="1" class="form-control input-sm item_no" readonly />







                      <option value="<?php echo $sub_row["item_no"]; ?>"><?php echo $sub_row["item_name"]; ?></option>







                        















                        </select></td>







                        <td><input type="text" name="ctn[]" id="ctn<?php echo $m; ?>" class="form-control input-sm number_only ctn" value="<?php echo $sub_row["ctn"]; ?>" readonly/></td>







                        







                      <td><input type="text" name="qty[]" id="qty<?php echo $m; ?>" class="form-control input-sm number_only qty" value="<?php echo $sub_row["qty"]; ?>" readonly/></td>







                      







                    







                      







                      <td><select name="item_status[]" id="item_status<?php echo $m; ?>" data-sr_no="1" class="form-control item_status">







                      <option value="<?php echo $sub_row["item_status"]; ?>"><?php echo $sub_row["item_status"]; ?></option>







                        <option value="Approved">Approved</option>







                        <option value="Not Approved">Not Approved</option>







                      </select></td>







                      







                    







                     







                    </tr>







                    <?php







                    }







                    ?>







                   







                  </table>







                   







                 







                </td>







              </tr>







              <tr>







                <td width="55%" align="right"><b>Total Qty</td>







                <td width="45%" align="left"><b><span id="total_amount"><?php echo $tot_qty;?></span></b></td>







               







              </tr>







               







                </tr>







                







                







            







              







              <tr>







                <td colspan="2"></td>







              </tr>







              <tr>







                <td colspan="2" align="center">







                  <input type="hidden" name="total_item" id="total_item" value="<?php echo $m; ?>" />







                  <input type="submit" name="update" id="update" class="btn btn-info" value="Update" />







                </td>







              </tr>







          </table>







        </div>







      </form>















        </div>







             























        







        







      </div><!-- /.container-fluid -->







    </section>







    <!-- /.content -->







 







  <!-- /.content-wrapper -->







 







    </div>







    </div>















 







  







  <script src="js/jquery-ui.js"></script>







  <script src="js/jquery-ui.min.js"></script>































  







  







  























</body>







</html>















      <script>







      $(document).ready(function(){















        







        







      































        















        //$("#item_type"+count).change(function(){







        //var itemtype = $(".item_type option:selected").val();







       







      







        















        $('#save').click(function(){







          















          $('#invoice_form').submit();















        });















      });







      </script>















       <?php







     }







   }







?>







