สอนทำเว็บไซต์

ตรวจสอบสินค้าไปส่งด้วยกันได้หรือไม่?

managechemicaltype.php

<?php include_once("checklogin.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Lekjew.com</title> <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"> <link rel="stylesheet" type="text/css" href="css/dataTables.bootstrap4.css"> <link rel="stylesheet" type="text/css" href="css/responsive.dataTables.css"> <link rel="stylesheet" href="assets/css/bootstrap-select.css" /> <link type="text/css" href="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/css/dataTables.checkboxes.css" rel="stylesheet" /> <?php include_once("include/style.php"); ?> </head> <body class="adminbody"> <?php include_once("include/header_login.php"); ?> <div id="main" > <?php include_once("leftmenu.php"); ?> <div class="content-page"> <div class="content"> <div class="col-md-12"> <div class="card pd-10"> <div class="col-md-12"><div class="row"> <h3>ตรวจสอบสินค้า</h3> </div></div> <div class="col-md-12"> <div class="row"> <div class="col-md-7 col-xs-12"> <div class="row"> <div class="col-md-10"> <div class="row"> <div class="col-md-4"><div class="row"> <div class="input-group mb-2 input-group-sm"> <div class="input-group-prepend"><span class="input-group-text ">สินค้า 1</span></div> <input type="text" class="form-control form-control-sm" name="ITEM_NO1" id="ITEM_NO1"> </div> </div></div> <div class="col-md-4"><div class="row"> <div class="input-group mb-2 input-group-sm"> <div class="input-group-prepend"><span class="input-group-text ">สินค้า 2</span></div> <input type="text" class="form-control form-control-sm" name="ITEM_NO2" id="ITEM_NO2"> </div> </div></div> <div class="col-md-4"><div class="row"> <div class="input-group mb-2 input-group-sm"> <div class="input-group-prepend"><span class="input-group-text">ไปส่งด้วยกัน</span></div> <select class="form-control form-control-sm" name="ITEM_STATUS" id="ITEM_STATUS"> <option value="Y">ได้</option> <option value="N">ไม่ได้</option> </select> </div> </div></div> </div> </div> <div class="col-md-2"><div class="row"> <button type="button" class='btn btn-secondary' onclick="AddChemicalType();">เพิ่ม</button> </div></div> <div class="col-md-12" id="showdoing"></div> <div class="table-responsive" id="showtbody1"> <table id="tableA" class="table table-bordered nowrap tablec" cellspacing="0" border="1" width="100%" style="table-layout:fixed;"> <thead> <tr> <th class='hide'>#</th> <th>สินค้า1</th> <th>สินค้า2</th> <th>ไปส่งด้วยกัน</th> <th>#</th> </tr> <tr> <td class='hide'>#</td> <td>สินค้า1</td> <td>สินค้า2</td> <td>ไปส่งด้วยกัน</td> <td>#</td> </tr> </thead> <tbody id="showtbody"> </tbody> </table> </div> </div> </div><!-- end col-md-7 --> <div class="col-md-5 col-xs-12"> <div class="row"> <div class="table-responsive" id="showtbody1"> <iframe id="ifm" width="100%" frameborder="0" scrolling="yes" style="height:800px;" ></iframe> </div> </div> </div><!-- end col-md-5 --> </div><!-- end row --> </div> </div> </div> </div> </div> </div> <div id="ModalDELETE" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Delete</h5> <button type="button" class="btn-close closemodaldel" data-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <input type="hidden" name="RUNNO_DELETE" id="RUNNO_DELETE" class="form-control"> <div id="showdel"></div> <div class='text-danger' id='showerr'></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary closemodaldel" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary" onclick="DeleteChemicalType();">Confirm Delete</button> </div> </div> </div> </div> </body> </html> <?php include_once("include/js.php"); ?> <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.bootstrap4.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> <!-- excel --> <script src="https://cdn.datatables.net/select/1.4.0/js/dataTables.select.min.js"></script> <script type="text/javascript" src="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/js/dataTables.checkboxes.min.js"></script> <script> RefresthTable(); CallChemicalType(); CallChemicalTypeImg(); function AddChemicalType(){ $('button').addClass('noclick'); var item1 = $('#ITEM_NO1').val(); var item2 = $('#ITEM_NO2').val(); var itemstatus = $('#ITEM_STATUS').val(); var form_data = new FormData(); form_data.append("condition", "AddChemicalType"); form_data.append("ITEM_NO1", item1); form_data.append("ITEM_NO2", item2); form_data.append("ITEM_STATUS", itemstatus); $.ajax({ url: "managechemicaltype_save.php", async: false, cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(data) { $('button').removeClass('noclick'); var err = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; for (var i = 0; i < resL; i++) { if(typeof JsonData['result'][i]['ERR'] !== "undefined" && JsonData['result'][i]['ERR'] !== null ){ err = err + JsonData['result'][i]['ERR']; } } var numerr = err.length; if(numerr>0){ $('#showdoing').html(err); }else{ CallChemicalType(); } } , error : function(data){ alert(data); $('button').removeClass('noclick'); } }); } function CallChemicalType(){ $.ajax({ url: "managechemicaltype_data.php", async: false, cache: false, contentType: false, processData: false, type: 'post', beforeSend: function() { $("#showtbody").html("<tr><td class='hide'></td><td colspan='4' class='text-center'><i class='fa fa-spinner fa-pulse fa-2x'></i></td></tr>"); }, success: function(data) { $('button').removeClass('noclick'); var tr_str = ""; var tripno = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; if(resL>0){ for (var i = 0; i < resL; i++) { tr_str = tr_str + "<tr class='row"+i+"'>"; tr_str = tr_str + "<td class='hide'>"; if(typeof JsonData['result'][i]['RUNNO'] !== "undefined" && JsonData['result'][i]['RUNNO'] !== null ){ tr_str = tr_str + JsonData['result'][i]['RUNNO']; } tr_str = tr_str + "</td>"; tr_str = tr_str + "<td>"; if(typeof JsonData['result'][i]['ITEM_NO1'] !== "undefined" && JsonData['result'][i]['ITEM_NO1'] !== null ){ tr_str = tr_str + JsonData['result'][i]['ITEM_NO1']; } tr_str = tr_str + "</td>" ; tr_str = tr_str + "<td>"; if(typeof JsonData['result'][i]['ITEM_NO2'] !== "undefined" && JsonData['result'][i]['ITEM_NO2'] !== null ){ tr_str = tr_str + JsonData['result'][i]['ITEM_NO2']; } tr_str = tr_str + "</td>" ; tr_str = tr_str + "<td>"; if(typeof JsonData['result'][i]['ITEM_STATUS'] !== "undefined" && JsonData['result'][i]['ITEM_STATUS'] !== null ){ tr_str = tr_str + JsonData['result'][i]['ITEM_STATUS']; } tr_str = tr_str + "</td>" ; tr_str = tr_str + "<td><input type='checkbox' name='' id='' class='form-control form-control-sm'></td>" ; tr_str = tr_str + "</tr>"; } } $('#tableA').DataTable().destroy(); $("#showtbody").html(tr_str); RefresthTable(); CallChemicalTypeImg(); } , error : function(data){ alert(data); $('button').removeClass('noclick'); } }); } function RefresthTable(){ $('#tableA thead tr:eq(0) th').empty(); $('#tableA thead tr:eq(0) th').each( function (i) { if(i>0 && i<=3){ var title = $(this).text(); $(this).html( '<input type="text" class="form-control form-control-sm search'+i+' section-no-print">' ); $( 'input', this ).on( 'keyup change', function () { if ( table.column(i).search() !== this.value ) { table .column(i) .search( this.value ) .draw(); } }); } } ); var table = $('#tableA').DataTable( { dom: 'Btip', paging: true, searching: true, bProcessing: true, ordering: false, lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]], iDisplayLength: -1, scrollY: "500px", scrollCollapse: true, scrollX: true, responsive: false, select: true, select: { 'style': 'multi' }, columnDefs: [{ 'targets': 4, 'checkboxes': {'selectRow': true} }], buttons:[ { extend: "selected", className: "btn btn-danger btn-sm ", text: '<i class="fa fa-trash"></i> Delete', attr: { titie: 'Delete', 'data-toggle': 'modal', 'data-target': '#ModalDELETE' }, selector: ':not(.notselect)', action: function () { var numrow = $('#tableA tbody tr').length; for(var j=0;j<numrow;j++){ $('.notselect').removeClass('selected'); } var data = []; var rows = table.rows( { selected: true } ).data().each( element => data.push( { "RUNNO" : element[0], "ITEM_NO1" : element[1], "ITEM_NO2" : element[2] }) ); var runno=""; var showrunno = ""; for(var i=0;i<data.length;i++){ if(i==0){ comma=""; }else{ comma=","; } runno=runno+comma+data[i]["RUNNO"]; showrunno=showrunno+comma+data[i]["ITEM_NO1"]+data[i]["ITEM_NO2"]+"<br>"; } $('#RUNNO_DELETE').val(runno); $('#showdel').html(showrunno); } }, { extend: 'excelHtml5', autoFilter: true, footer: true, filename: 'ExportC1', title: 'เอกสาร C1', className: "btn btn-success btn-sm", text: '<i class="fa fa-file-excel-o"></i> ประเภทสินค้า', exportOptions: { columns: ':not(.section-no-print)' } } ] }); $('#tableA thead tr:eq(0)').empty(); $('.dataTables_scrollBody #tableA tr:eq(0) ').empty(); } function DeleteChemicalType(){ var form_data = new FormData(); form_data.append("condition", "DeleteChemicalType"); form_data.append("RUNNO", $('#RUNNO_DELETE').val() ); $.ajax({ type: "POST", url: "managechemicaltype_save.php", data: form_data, dataType: 'text', processData: false, contentType: false, cache: false, success: function(data) { var j=0; var err = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; if(resL>0){ for (var i = 0; i < resL; i++) { if(typeof JsonData['result'][i]['ERR'] !== "undefined" && JsonData['result'][i]['ERR'] !== null && JsonData['result'][i]['ERR'] != ""){ err = err + JsonData['result'][i]['ERR']; } } showFailAlert(err); }else{ showSuccessAlert("ลบสำเร็จ"); $('.closemodaldel').click(); CallChemicalType(); } }, error: function(dataerr) { showFailAlert(dataerr); } }); } function showSuccessAlert(data) { $('#resultalert').html(data); $("#success-alert").fadeTo(2000, 300).slideUp(300, function(){ $("#success-alert").slideUp(300); }); } function showFailAlert(data) { $('#resultfailalert').html(data); $("#fail-alert").fadeTo(2000, 300).slideUp(300, function(){ $("#fail-alert").slideUp(300); }); } function CallChemicalTypeImg(){ var form_data = new FormData(); $.ajax({ url: "managechemicaltype_report.php", contentType: false, processData: false, data: form_data, dataType: "text", type: 'post', success: function(data) { $("#ifm").contents().find("body").html(data); } }); } </script>

managechemicaltype_save.php

<?php include('connectDBMS.php'); $result = array(); $ACTION = $_POST["condition"]; switch($ACTION){ case "AddChemicalType" : $sql = "SELECT (CASE WHEN max(RUNNO) is null THEN 1 ELSE max(RUNNO)+1 END) as RUNNO FROM ITEM_TYPE"; $rsp = sqlsrv_query($ConnDB, $sql); $row = sqlsrv_fetch_object($rsp); $RUNNO = $row->RUNNO; $ITEM_NO1 = $_POST["ITEM_NO1"]; $ITEM_NO2 = $_POST["ITEM_NO2"]; $ITEM_STATUS = $_POST["ITEM_STATUS"]; $sqladd = "INSERT INTO ITEM_TYPE (RUNNO, ITEM_NO1, ITEM_NO2, ITEM_STATUS) VALUES ($RUNNO, '$ITEM_NO1', '$ITEM_NO2', '$ITEM_STATUS'); "; $rsadd = sqlsrv_query($ConnDB, $sqladd); if(!$rsadd){ $result[] = array( "ERR" => $sqladd); } break; case "DeleteChemicalType": $sqldel = "DELETE FROM ITEM_TYPE WHERE RUNNO in (".$_POST["RUNNO"].") "; $rsdel = sqlsrv_query($ConnDB,$sqldel ); if(!$rsdel){ $result[] = array( "ERR" => $sqldel); } break; } sqlsrv_close($ConnDB); $data = array("result" => $result); echo json_encode($data, JSON_UNESCAPED_UNICODE); ?>

managechemicaltype_data.php

<?php include('connectDBMS.php'); $data = array(); $sql = "SELECT * FROM ITEM_TYPE"; $rsc = sqlsrv_query($ConnDB, $sql); while($rowp = sqlsrv_fetch_object($rsc)) { $data[] = array( "RUNNO" => $rowp->RUNNO , "ITEM_NO1" => $rowp->ITEM_NO1 , "ITEM_NO2" => $rowp->ITEM_NO2 , "ITEM_STATUS" => $rowp->ITEM_STATUS ); } sqlsrv_close($ConnDB); $json = array( "result" => $data); echo json_encode($json, JSON_UNESCAPED_UNICODE); ?>

managechemicaltype_report.php

<?php include('connectDBMS.php'); $data = array(); ?> <?php include_once("include/style.php"); ?> <table id="tableA" class="table table-bordered nowrap tablec" cellspacing="0" border="1" width="100%" style="table-layout:fixed;"> <thead> <tr> <th>ประเภทสินค้า</th> <?php $sql1 = "SELECT distinct(ITEM_NO2) as ITEM_NO2 FROM ITEM_TYPE"; $rsc1 = sqlsrv_query($ConnDB, $sql1); while($rowp1 = sqlsrv_fetch_object($rsc1)) { echo "<th> $rowp1->ITEM_NO2 </th>"; $data[] = array( "ITEM_NO2" => $rowp1->ITEM_NO2 ); } ?> </tr> </thead> <tbody> <?php $sql2 = "SELECT distinct(ITEM_NO1) as ITEM_NO1 FROM ITEM_TYPE"; $rsc2 = sqlsrv_query($ConnDB, $sql2); while($rowp2 = sqlsrv_fetch_object($rsc2)) { ?> <tr> <?php echo "<td> $rowp2->ITEM_NO1 </td>"; for ($i=0;$i<sizeof($data);$i++){ $itm_status = ""; echo "<td>"; $itm_status = AnswerData($ConnDB, $data[$i]["ITEM_NO2"], $rowp2->ITEM_NO1 ); if($itm_status=="Y"){ echo "<span class='text-success'><i class='fa fa-check-circle' aria-hidden='true'></i></span>"; }else if($itm_status=="N"){ echo "<span class='text-danger'><i class='fa fa-times-circle' aria-hidden='true'></i></span>"; }else{ echo ""; } echo "</td>"; } ?> </tr> <?php } ?> </tbody> </table> <?php function AnswerData($ConDB, $item2, $item1){ $sql = "SELECT ITEM_STATUS FROM ITEM_TYPE WHERE ITEM_NO1='$item1' and ITEM_NO2='$item2'"; $rsc = sqlsrv_query($ConDB, $sql); while($rowp = sqlsrv_fetch_object($rsc)) { $itemstatus = $rowp->ITEM_STATUS; } return $itemstatus; sqlsrv_close($ConDB); } ?>

checkchemicaltype.php

<?php include('connectDBMS.php'); echo $class = "ลิปติก, ไม้ถูพื้น, ขนม, ประทัด"; $chemicalcheck = CallChemicalTypeVal($ConnDB, $class); $count = 0; for($k=0;$k<sizeof($chemicalcheck);$k++){ // $chemicalcheck[$k]."<br>"; if($chemicalcheck[$k]=="N"){ $count++; } } if($count>0){ echo "<br>สินค้าไปด้วยกันไม่ได้"; }else{ echo "<br>สินค้าไปด้วยกันได้"; } sqlsrv_close($ConnDB); function CallChemicalTypeVal($ConDB, $cls){ $res = array(); $c = explode(", ", $cls.", "); $num = count($c) - 1; for($i=0;$i<$num;$i++){ for($j=0;$j<$num;$j++){ if($c[$i]!=$c[$j]){ $res[] = CheckChemicalType($ConDB, $c[$i], $c[$j]); } } } return $res; sqlsrv_close($ConDB); } function CheckChemicalType($ConDB, $item1, $item2){ $sql = "SELECT ITEM_STATUS FROM ITEM_TYPE WHERE ITEM_NO1='$item1' and ITEM_NO2='$item2'"; $rsc = sqlsrv_query($ConDB, $sql); while($rowp = sqlsrv_fetch_object($rsc)) { $itemstatus = $rowp->ITEM_STATUS; } return $itemstatus; sqlsrv_close($ConDB); } ?>