commit source history importify page of milestone 2

This commit is contained in:
starthomas610 2024-06-17 10:29:09 -04:00
parent 37bc8c41c9
commit c566d10928
5 changed files with 927 additions and 225 deletions

View File

@ -0,0 +1,51 @@
<?php include('../include/headscript.php'); ?>
<?php
$his_id = $_POST['his_id'];
$his_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$his_query->setQuery("SELECT * FROM template_import_his WHERE idImportHis='$his_id'");
$his_query->execute();
$his_info = $his_query->Results;
$importcode = "";
if (count($his_info) > 0) {
$importcode = $his_info[0]['importcode'];
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`result_project`";
$deleteQuery->addFilter("importcode", "=", "s", "" . $importcode . "");
$deleteQuery->execute();
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`parts`";
$deleteQuery->addFilter("importcode", "=", "s", "" . $importcode . "");
$deleteQuery->execute();
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`reports`";
$deleteQuery->addFilter("importcode", "=", "s", "" . $importcode . "");
$deleteQuery->execute();
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`products`";
$deleteQuery->addFilter("importcode", "=", "s", "" . $importcode . "");
$deleteQuery->execute();
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`template_import_his`";
$deleteQuery->addFilter("idImportHis", "=", "i", "" . $his_id . "");
$deleteQuery->execute();
}
die("success");

View File

@ -0,0 +1,346 @@
<?php include('../include/headscript.php'); ?>
<?php include("../class/company.php");
$importify_his = new WA_MySQLi_RS("rsl", $repnew, 0);
$user_id = $_SESSION['iduserlogin'];
$importify_his->setQuery("SELECT * FROM template_import_his where user_id=$user_id");
$importify_his->execute();
$arr_his = $importify_his->Results;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<?php include('../include/seo.php'); ?>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="shortcut icon" href="../assets/images/favicon.ico">
<link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../assets/css/icons.css" rel="stylesheet" type="text/css">
<link href="../assets/css/style.css" rel="stylesheet" type="text/css">
<!-- DataTables -->
<link href="../assets/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<link href="../assets/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<script src="../assets/js/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
<style>
.table-custom tr {
height: 40px;
line-height: 40px;
}
#ajax_preloader {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: transparent;
z-index: 9999999;
}
.table-custom td,
.table-custom th {
padding: 4px 8px;
}
.table-custom .btn {
padding: 2px 15px;
line-height: 1.7;
font-size: 14px;
}
.form-row {
display: flex;
align-items: center;
/* Questo allinea verticalmente gli elementi nella riga */
gap: 10px;
/* Questo crea una piccola distanza tra gli elementi nella riga */
}
.table-custom .form-control,
.table-custom .form-select {
height: 25px;
/* Puoi modificare questo valore per adattarlo al tuo design */
padding: 2px 6px;
/* riduce la dimensione del padding */
font-size: 14px;
/* riduce la dimensione del font */
}
.table-custom .form-control-sm.analysis-input {
height: 25px;
/* Questo modifica la dimensione degli input con classe 'form-control-sm' e 'analysis-input' */
padding: 2px 6px;
font-size: 12px;
}
table.table-bordered.dataTable tbody th, table.table-bordered.dataTable thead td, table.table-bordered.dataTable tbody td, table.table-bordered.dataTable th, table.table-bordered.dataTable td {
text-align: center !important;
}
.no_padding {
padding: 0 !important;
}
</style>
</head>
<body class="fixed-left">
<!-- Loader -->
<div id="preloader">
<div id="status">
<div class="spinner"></div>
</div>
</div>
<div id="ajax_preloader">
<div id="status">
<div class="spinner"></div>
</div>
</div>
<!-- Begin page -->
<div id="wrapper">
<?php include('../include/navigationbar.php'); ?>
<!-- Start right Content here -->
<div class="content-page">
<!-- Start content -->
<div class="content">
<?php include('../include/topbar.php'); ?>
<div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<ol class="breadcrumb hide-phone p-0 m-0">
<li class="breadcrumb-item"><a href="#">Reportify</a></li>
<li class="breadcrumb-item active">Importify</li>
</ol>
</div>
<h4 class="page-title">Importify</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<h5 class="header-title pb-3 mt-0">Importify: History Import</h5>
<br><br>
<div class="table-responsive">
<table id="tbl_his" class="table table-bordered dt-responsive nowrap">
<thead>
<tr>
<th width="60px">No</th>
<th width="120px">Date/Time</th>
<th>ImportCode</th>
<th width="80px">Status</th>
<th width="80px">Action</th>
</tr>
</thead>
<tbody>
<?php
for($i=0; $i< count($arr_his); $i++) {
$item = $arr_his[$i];
?>
<tr>
<td><?=$i + 1?></td>
<td><?=date("Y-m-d H:i:s", strtotime($item['created_at']))?></td>
<td><?=$item['importcode']?></td>
<td class="no_padding">
<?php
if($item['f_status'] == 0) {
?>
<button class="btn btn-sm btn-round btn-secondary">Progressing</button>
<?php
} else if($item['f_status'] == 1) {
?>
<button class="btn btn-sm btn-round btn-success">Complete</button>
<?php
}
?>
</td>
<td class="no_padding">
<?php
if($item['f_status'] == 1) {
?>
<button onclick="onCancelHis(<?=$item['idImportHis']?>)" type="button" class="btn btn-sm btn-danger"><i class="fas fa-trash-alt"></i></button>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div><!--end table-responsive-->
</div>
</div>
</div>
</div>
<!-- end row -->
</div><!-- container -->
</div> <!-- Page content Wrapper -->
</div> <!-- content -->
<?php include('../include/footer.php'); ?>
</div>
<!-- End Right content here -->
</div>
<!-- plugin JS -->
<script src="../assets/js/popper.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/modernizr.min.js"></script>
<script src="../assets/js/detect.js"></script>
<script src="../assets/js/fastclick.js"></script>
<script src="../assets/js/jquery.slimscroll.js"></script>
<script src="../assets/js/jquery.blockUI.js"></script>
<script src="../assets/js/waves.js"></script>
<script src="../assets/js/jquery.nicescroll.js"></script>
<script src="../assets/js/jquery.scrollTo.min.js"></script>
<script src="../assets/js/common_helper.js"></script>
<script src="../assets/plugins/chart.js/chart.min.js"></script>
<script src="../assets/pages/dashboard.js"></script>
<!-- App js -->
<script src="../assets/js/app.js"></script>
<script src="../assets/plugins/alertify/js/alertify.js"></script>
<!-- Required datatable js -->
<script src="../assets/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
<!-- END wrapper -->
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
$('#ajax_preloader').fadeOut();
});
$('#tbl_his').DataTable({
"processing": true,
"serverSide": false,
"lengthChange": true,
"lengthMenu": [10, 20, 50, 100],
"pageLength": 10,
"columns": [
{"orderable": true},
{"orderable": true},
{"orderable": true},
{"orderable": true},
{"orderable": false},
],
oLanguage: {
oAria: {
sSortAscending: ": activate to sort column ascending",
sSortDescending: ": activate to sort column descending"
},
oPaginate: {sFirst: "First", sLast: "Last", sNext: "Next", sPrevious: "Previous"},
sEmptyTable: "No data available in table",
sInfo: "Showing _START_ to _END_ of _TOTAL_ entries",
sInfoEmpty: "Showing 0 to 0 of 0 entries",
sInfoFiltered: "(filtered from _MAX_ total entries)",
sInfoPostFix: "",
sDecimal: "",
sThousands: ",",
sLengthMenu: "_MENU_",
sLoadingRecords: "Loading...",
sProcessing: "Processing...",
sSearch: "Search:",
sSearchPlaceholder: "",
sUrl: "",
sZeroRecords: "No matching records found"
},
// "ajax": {
// "url": "/loadGoodsDestroyed",
// "type": "POST",
// "dataType": "json",
// "dataSrc": "data",
// "data": {start_date: start_date, end_date: end_date}
// },
// "columns": [
// {"data": "name"},
// {"data": "status"},
// {"data": "count"},
// {"data": "price"},
// {"data": "consumer"},
// {"data": "date"}
// ]
});
function onCancelHis(id) {
Swal.fire({
title: 'Cancel Confirm!',
text: "Do you want to cancel import his?",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: 'cancel_import_his.php',
type: 'POST',
data: {
his_id: id
},
beforeSend: function() {
$('#ajax_preloader').fadeIn();
},
error: function() {
$('#ajax_preloader').fadeOut();
showWarningAlert("Server Error");
},
success: function(data) {
$('#ajax_preloader').fadeOut();
if(data.indexOf("success") > -1) {
showSuccessPopup("Your operation successed!", function() {
location.reload();
});
} else {
showWarningAlert("Server Error.")
}
}
})
}
});
}
</script>
</body>
</html>

View File

@ -4,6 +4,31 @@ require '../../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
function post_async($url, array $params)
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
if(isset($_FILES['f_csv'])) {
$file = $_FILES['f_csv']['tmp_name'];
$template_id = $_POST['template_id'];
@ -42,6 +67,7 @@ if(isset($_FILES['f_csv'])) {
//separate by Sample Code (PO#) - product
$idx_sample_code_po = array_search("Sample Code (PO#)", $arr_excel_columns);
$arr_total_products = array();
$tmp_arr_child_products = array();
$tmp_sample_code_po = "";
@ -67,235 +93,258 @@ if(isset($_FILES['f_csv'])) {
//define importcode (timestamp)
$importcode = time();
//insert import his
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`template_import_his`";
$InsertQuery->bindColumn("created_at", "s", date("Y-m-d H:i:s"), "WA_DEFAULT");
$InsertQuery->bindColumn("user_id", "i", "" . $_SESSION['iduserlogin'], "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "s", "" .$importcode, "WA_DEFAULT");
$InsertQuery->bindColumn("f_status", "i", "0", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
// post_async("localhost:80/0_claudio/reportify_new/public/userarea/importify/importify_bg_script.php", [
// 'importcode' => $importcode
// ]);
post_async($_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']."/../importify_bg_script.php", [
'arr_project' => json_encode($arr_total_products),
'arr_excel_columns' => json_encode($arr_excel_columns),
'arr_associate' => json_encode($arr_associate),
'importcode' => $importcode
]);
//insert to products table
foreach($arr_total_products as $product) {
//check exist product item
$sample_code_po = $product[0][$idx_sample_code_po];
$product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
$product_query->execute();
$product_info = $product_query->Results;
$idproducts = "";
if(count($product_info) > 0) {
$idproducts = $product_info[0]['idproducts'];
} else { // have to insert new
$arr_product_need_idx = array();
for($i=0; $i<count($arr_associate); $i++) {
if($arr_associate[$i]['table_name'] == "products") {
array_push($arr_product_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`products`";
$InsertQuery->bindColumn("products_refnumber", "s", $product[0][$idx_sample_code_po], "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode. "", "WA_DEFAULT");
for($i=0; $i<count($arr_product_need_idx); $i++) {
$InsertQuery->bindColumn($arr_product_need_idx[$i][0], "s", $product[0][$arr_product_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
$product_query->execute();
$product_info = $product_query->Results;
if(count($product_info) > 0) {
$idproducts = $product_info[0]['idproducts'];
}
}
if($idproducts == "") {
die("server_error");
}
//----------- report table ------------------
//separate reports table data
$idx_report_no_po = array_search("Report no.", $arr_excel_columns);
$arr_total_reports = array();
$tmp_arr_child_reports = array();
$tmp_report_no = "";
for($i=0; $i<count($product); $i++) {
if($product[$i][$idx_report_no_po] == $tmp_report_no) {
array_push($tmp_arr_child_reports, $product[$i]);
} else {
if($tmp_report_no != "") {
if(count($tmp_arr_child_reports) > 0) {
array_push($arr_total_reports, $tmp_arr_child_reports);
}
}
$tmp_report_no = $product[$i][$idx_report_no_po];
$tmp_arr_child_reports = array();
array_push($tmp_arr_child_reports, $product[$i]);
}
}
if(count($tmp_arr_child_reports) > 0) {
array_push($arr_total_reports, $tmp_arr_child_reports);
}
//insert to reports table
foreach($arr_total_reports as $report) {
//check exist reports item
$report_no = $report[0][$idx_report_no_po];
$report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
$report_query->execute();
$report_info = $report_query->Results;
$idreports = "";
if (count($report_info) > 0) {
$idreports = $report_info[0]['idreports'];
} else { // have to insert new
$arr_report_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]['table_name'] == "reports") {
array_push($arr_report_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`reports`";
$InsertQuery->bindColumn("reportsNumberLab", "s", $report[0][$idx_report_no_po]."", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts."", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_report_need_idx); $i++) {
$InsertQuery->bindColumn($arr_report_need_idx[$i][0], "s", $report[0][$arr_report_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
$report_query->execute();
$report_info = $report_query->Results;
if (count($report_info) > 0) {
$idreports = $report_info[0]['idreports'];
}
}
if ($idreports == "") {
die("server_error");
}
//----------- parts table ------------------
//separate parts table data
$idx_part_no_po = array_search("Part No.", $arr_excel_columns);
$arr_total_parts = array();
$tmp_arr_child_parts = array();
$tmp_part_no = "";
for($i=0; $i<count($report); $i++) {
if($report[$i][$idx_part_no_po] == $tmp_part_no) {
array_push($tmp_arr_child_parts, $report[$i]);
} else {
if($tmp_part_no != "") {
if(count($tmp_arr_child_parts) > 0) {
array_push($arr_total_parts, $tmp_arr_child_parts);
}
}
$tmp_part_no = $report[$i][$idx_part_no_po];
$tmp_arr_child_parts = array();
array_push($tmp_arr_child_parts, $report[$i]);
}
}
if(count($tmp_arr_child_parts) > 0) {
array_push($arr_total_parts, $tmp_arr_child_parts);
}
//insert to parts table
foreach($arr_total_parts as $part) {
//check exist parts item
$part_no = $part[0][$idx_part_no_po];
$part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
$part_query->execute();
$part_info = $part_query->Results;
$idparts = "";
if (count($part_info) > 0) {
$idparts = $part_info[0]['idParts'];
} else { // have to insert new
$arr_part_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]['table_name'] == "parts") {
array_push($arr_part_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`parts`";
$InsertQuery->bindColumn("partsCode", "s", $part[0][$idx_part_no_po] . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_part_need_idx); $i++) {
$InsertQuery->bindColumn($arr_part_need_idx[$i][0], "s", $part[0][$arr_part_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
$part_query->execute();
$part_info = $part_query->Results;
if (count($part_info) > 0) {
$idparts = $part_info[0]['idParts'];
}
}
if ($idparts == "") {
die("server_error");
}
//----------- result_project table ------------------
foreach($part as $result_project) {
//check exist result_project item
// $result_project_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $sql_result_project_query = "SELECT * FROM result_project WHERE idPart='$idparts' and idreports='$idreports' and idproducts='$idproducts'";
// foreach($arr_total_products as $product) {
// //check exist product item
// $sample_code_po = $product[0][$idx_sample_code_po];
// $product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
// $product_query->execute();
//
$arr_result_project_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]['table_name'] == "result_project") {
array_push($arr_result_project_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
}
}
// $product_info = $product_query->Results;
// $idproducts = "";
//
// foreach($arr_result_project_need_idx as $q) {
// $sql_result_project_query .= " and ".$q[0]."='".$q[0]."'";
// if(count($product_info) > 0) {
// $idproducts = $product_info[0]['idproducts'];
// } else { // have to insert new
// $arr_product_need_idx = array();
// for($i=0; $i<count($arr_associate); $i++) {
// if($arr_associate[$i]['table_name'] == "products") {
// array_push($arr_product_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
// }
// }
//
// $InsertQuery = new WA_MySQLi_Query($repnew);
// $InsertQuery->Action = "insert";
// $InsertQuery->Table = "`products`";
// $InsertQuery->bindColumn("products_refnumber", "s", $product[0][$idx_sample_code_po], "WA_DEFAULT");
// $InsertQuery->bindColumn("importcode", "i", "" . $importcode. "", "WA_DEFAULT");
// for($i=0; $i<count($arr_product_need_idx); $i++) {
// $InsertQuery->bindColumn($arr_product_need_idx[$i][0], "s", $product[0][$arr_product_need_idx[$i][1]], "WA_DEFAULT");
// }
// $InsertQuery->saveInSession("");
// $InsertQuery->execute();
//
// $product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
// $product_query->execute();
//
// $product_info = $product_query->Results;
// if(count($product_info) > 0) {
// $idproducts = $product_info[0]['idproducts'];
// }
// }
// if($idproducts == "") {
// die("server_error");
// }
//
//
// //----------- report table ------------------
// //separate reports table data
// $idx_report_no_po = array_search("Report no.", $arr_excel_columns);
//
// $arr_total_reports = array();
// $tmp_arr_child_reports = array();
// $tmp_report_no = "";
// for($i=0; $i<count($product); $i++) {
// if($product[$i][$idx_report_no_po] == $tmp_report_no) {
// array_push($tmp_arr_child_reports, $product[$i]);
// } else {
// if($tmp_report_no != "") {
// if(count($tmp_arr_child_reports) > 0) {
// array_push($arr_total_reports, $tmp_arr_child_reports);
// }
// }
// $tmp_report_no = $product[$i][$idx_report_no_po];
// $tmp_arr_child_reports = array();
// array_push($tmp_arr_child_reports, $product[$i]);
// }
// }
// if(count($tmp_arr_child_reports) > 0) {
// array_push($arr_total_reports, $tmp_arr_child_reports);
// }
//
// //insert to reports table
// foreach($arr_total_reports as $report) {
// //check exist reports item
// $report_no = $report[0][$idx_report_no_po];
// $report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
// $report_query->execute();
//
// $report_info = $report_query->Results;
// $idreports = "";
//
// if (count($report_info) > 0) {
// $idreports = $report_info[0]['idreports'];
// } else { // have to insert new
// $arr_report_need_idx = array();
// for ($i = 0; $i < count($arr_associate); $i++) {
// if ($arr_associate[$i]['table_name'] == "reports") {
// array_push($arr_report_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
// }
// }
//
// $InsertQuery = new WA_MySQLi_Query($repnew);
// $InsertQuery->Action = "insert";
// $InsertQuery->Table = "`reports`";
// $InsertQuery->bindColumn("reportsNumberLab", "s", $report[0][$idx_report_no_po]."", "WA_DEFAULT");
// $InsertQuery->bindColumn("idproducts", "i", "" . $idproducts."", "WA_DEFAULT");
// $InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
// for ($i = 0; $i < count($arr_report_need_idx); $i++) {
// $InsertQuery->bindColumn($arr_report_need_idx[$i][0], "s", $report[0][$arr_report_need_idx[$i][1]], "WA_DEFAULT");
// }
// $InsertQuery->saveInSession("");
// $InsertQuery->execute();
//
// $report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
// $report_query->execute();
//
// $report_info = $report_query->Results;
// if (count($report_info) > 0) {
// $idreports = $report_info[0]['idreports'];
// }
// }
// if ($idreports == "") {
// die("server_error");
// }
//
// //----------- parts table ------------------
// //separate parts table data
// $idx_part_no_po = array_search("Part No.", $arr_excel_columns);
//
// $arr_total_parts = array();
// $tmp_arr_child_parts = array();
// $tmp_part_no = "";
// for($i=0; $i<count($report); $i++) {
// if($report[$i][$idx_part_no_po] == $tmp_part_no) {
// array_push($tmp_arr_child_parts, $report[$i]);
// } else {
// if($tmp_part_no != "") {
// if(count($tmp_arr_child_parts) > 0) {
// array_push($arr_total_parts, $tmp_arr_child_parts);
// }
// }
// $tmp_part_no = $report[$i][$idx_part_no_po];
// $tmp_arr_child_parts = array();
// array_push($tmp_arr_child_parts, $report[$i]);
// }
// }
// if(count($tmp_arr_child_parts) > 0) {
// array_push($arr_total_parts, $tmp_arr_child_parts);
// }
//
// //insert to parts table
// foreach($arr_total_parts as $part) {
// //check exist parts item
// $part_no = $part[0][$idx_part_no_po];
// $part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
// $part_query->execute();
//
// $part_info = $part_query->Results;
// $idparts = "";
//
// if (count($part_info) > 0) {
// $idparts = $part_info[0]['idParts'];
// } else { // have to insert new
// $arr_part_need_idx = array();
// for ($i = 0; $i < count($arr_associate); $i++) {
// if ($arr_associate[$i]['table_name'] == "parts") {
// array_push($arr_part_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
// }
// }
//
// $result_project_query->setQuery($sql_result_project_query);
// $result_project_query->execute();
//
// $result_project_info = $result_project_query->Results;
//
// if (count($result_project_info) == 0) {
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`result_project`";
$InsertQuery->bindColumn("idPart", "s", $idparts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_result_project_need_idx); $i++) {
$InsertQuery->bindColumn($arr_result_project_need_idx[$i][0], "s", $result_project[$arr_result_project_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
// $InsertQuery = new WA_MySQLi_Query($repnew);
// $InsertQuery->Action = "insert";
// $InsertQuery->Table = "`parts`";
// $InsertQuery->bindColumn("partsCode", "s", $part[0][$idx_part_no_po] . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
// for ($i = 0; $i < count($arr_part_need_idx); $i++) {
// $InsertQuery->bindColumn($arr_part_need_idx[$i][0], "s", $part[0][$arr_part_need_idx[$i][1]], "WA_DEFAULT");
// }
}
}
}
}
// $InsertQuery->saveInSession("");
// $InsertQuery->execute();
//
// $part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
// $part_query->execute();
//
// $part_info = $part_query->Results;
// if (count($part_info) > 0) {
// $idparts = $part_info[0]['idParts'];
// }
// }
// if ($idparts == "") {
// die("server_error");
// }
//
// //----------- result_project table ------------------
// foreach($part as $result_project) {
// //check exist result_project item
//// $result_project_query = new WA_MySQLi_RS("getquery", $repnew, 0);
//// $sql_result_project_query = "SELECT * FROM result_project WHERE idPart='$idparts' and idreports='$idreports' and idproducts='$idproducts'";
////
// $arr_result_project_need_idx = array();
// for ($i = 0; $i < count($arr_associate); $i++) {
// if ($arr_associate[$i]['table_name'] == "result_project") {
// array_push($arr_result_project_need_idx, array($arr_associate[$i]['column_name'], array_search($arr_associate[$i]['headerfile'], $arr_excel_columns)));
// }
// }
////
//// foreach($arr_result_project_need_idx as $q) {
//// $sql_result_project_query .= " and ".$q[0]."='".$q[0]."'";
//// }
////
//// $result_project_query->setQuery($sql_result_project_query);
//// $result_project_query->execute();
////
//// $result_project_info = $result_project_query->Results;
////
//// if (count($result_project_info) == 0) {
// $InsertQuery = new WA_MySQLi_Query($repnew);
// $InsertQuery->Action = "insert";
// $InsertQuery->Table = "`result_project`";
// $InsertQuery->bindColumn("idPart", "s", $idparts . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
// $InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
// for ($i = 0; $i < count($arr_result_project_need_idx); $i++) {
// $InsertQuery->bindColumn($arr_result_project_need_idx[$i][0], "s", $result_project[$arr_result_project_need_idx[$i][1]], "WA_DEFAULT");
// }
// $InsertQuery->saveInSession("");
// $InsertQuery->execute();
//// }
// }
// }
// }
// }
die('success');
} else {

View File

@ -0,0 +1,256 @@
<?php
define('BASE_PATH', realpath(__DIR__ . '/../../..'));
require_once(BASE_PATH . '\public\Connections\repnew.php');
?>
<?php require_once(BASE_PATH . '/public/webassist/mysqli/rsobj.php'); ?>
<?php require_once(BASE_PATH . '/public/webassist/mysqli/queryobj.php'); ?>
<?php require_once(BASE_PATH . "/public/webassist/form_validations/wavt_scripts_php.php"); ?>
<?php
$arr_total_products = json_decode($_POST['arr_project']);
$arr_excel_columns = json_decode($_POST['arr_excel_columns']);
$arr_associate = json_decode($_POST['arr_associate']);
$importcode = $_POST['importcode'];
$idx_sample_code_po = array_search("Sample Code (PO#)", $arr_excel_columns);
//insert to products table
$idx = 0;
foreach($arr_total_products as $product) {
//check exist product item
$sample_code_po = $product[0][$idx_sample_code_po];
$product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
$product_query->execute();
$product_info = $product_query->Results;
$idproducts = "";
if(count($product_info) > 0) {
$idproducts = $product_info[0]['idproducts'];
} else { // have to insert new
$arr_product_need_idx = array();
for($i=0; $i<count($arr_associate); $i++) {
if($arr_associate[$i]->table_name == "products") {
array_push($arr_product_need_idx, array($arr_associate[$i]->column_name, array_search($arr_associate[$i]->headerfile, $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`products`";
$InsertQuery->bindColumn("products_refnumber", "s", $product[0][$idx_sample_code_po], "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode. "", "WA_DEFAULT");
for($i=0; $i<count($arr_product_need_idx); $i++) {
$InsertQuery->bindColumn($arr_product_need_idx[$i][0], "s", $product[0][$arr_product_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$product_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$product_query->setQuery("SELECT * FROM products WHERE products_refnumber='$sample_code_po'");
$product_query->execute();
$product_info = $product_query->Results;
if(count($product_info) > 0) {
$idproducts = $product_info[0]['idproducts'];
}
}
$idx++;
if($idproducts == "") {
die("server_error");
}
//----------- report table ------------------
//separate reports table data
$idx_report_no_po = array_search("Report no.", $arr_excel_columns);
$arr_total_reports = array();
$tmp_arr_child_reports = array();
$tmp_report_no = "";
for($i=0; $i<count($product); $i++) {
if($product[$i][$idx_report_no_po] == $tmp_report_no) {
array_push($tmp_arr_child_reports, $product[$i]);
} else {
if($tmp_report_no != "") {
if(count($tmp_arr_child_reports) > 0) {
array_push($arr_total_reports, $tmp_arr_child_reports);
}
}
$tmp_report_no = $product[$i][$idx_report_no_po];
$tmp_arr_child_reports = array();
array_push($tmp_arr_child_reports, $product[$i]);
}
}
if(count($tmp_arr_child_reports) > 0) {
array_push($arr_total_reports, $tmp_arr_child_reports);
}
//insert to reports table
foreach($arr_total_reports as $report) {
//check exist reports item
$report_no = $report[0][$idx_report_no_po];
$report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
$report_query->execute();
$report_info = $report_query->Results;
$idreports = "";
if (count($report_info) > 0) {
$idreports = $report_info[0]['idreports'];
} else { // have to insert new
$arr_report_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]->table_name == "reports") {
array_push($arr_report_need_idx, array($arr_associate[$i]->column_name, array_search($arr_associate[$i]->headerfile, $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`reports`";
$InsertQuery->bindColumn("reportsNumberLab", "s", $report[0][$idx_report_no_po]."", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts."", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_report_need_idx); $i++) {
$InsertQuery->bindColumn($arr_report_need_idx[$i][0], "s", $report[0][$arr_report_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$report_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$report_query->setQuery("SELECT * FROM reports WHERE reportsNumberLab='$report_no' and idproducts='$idproducts'");
$report_query->execute();
$report_info = $report_query->Results;
if (count($report_info) > 0) {
$idreports = $report_info[0]['idreports'];
}
}
if ($idreports == "") {
die("server_error");
}
//----------- parts table ------------------
//separate parts table data
$idx_part_no_po = array_search("Part No.", $arr_excel_columns);
$arr_total_parts = array();
$tmp_arr_child_parts = array();
$tmp_part_no = "";
for($i=0; $i<count($report); $i++) {
if($report[$i][$idx_part_no_po] == $tmp_part_no) {
array_push($tmp_arr_child_parts, $report[$i]);
} else {
if($tmp_part_no != "") {
if(count($tmp_arr_child_parts) > 0) {
array_push($arr_total_parts, $tmp_arr_child_parts);
}
}
$tmp_part_no = $report[$i][$idx_part_no_po];
$tmp_arr_child_parts = array();
array_push($tmp_arr_child_parts, $report[$i]);
}
}
if(count($tmp_arr_child_parts) > 0) {
array_push($arr_total_parts, $tmp_arr_child_parts);
}
//insert to parts table
foreach($arr_total_parts as $part) {
//check exist parts item
$part_no = $part[0][$idx_part_no_po];
$part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
$part_query->execute();
$part_info = $part_query->Results;
$idparts = "";
if (count($part_info) > 0) {
$idparts = $part_info[0]['idParts'];
} else { // have to insert new
$arr_part_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]->table_name == "parts") {
array_push($arr_part_need_idx, array($arr_associate[$i]->column_name, array_search($arr_associate[$i]->headerfile, $arr_excel_columns)));
}
}
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`parts`";
$InsertQuery->bindColumn("partsCode", "s", $part[0][$idx_part_no_po] . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_part_need_idx); $i++) {
$InsertQuery->bindColumn($arr_part_need_idx[$i][0], "s", $part[0][$arr_part_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$part_query = new WA_MySQLi_RS("getquery", $repnew, 0);
$part_query->setQuery("SELECT * FROM parts WHERE partsCode='$part_no' and idreports='$idreports' and idproducts='$idproducts'");
$part_query->execute();
$part_info = $part_query->Results;
if (count($part_info) > 0) {
$idparts = $part_info[0]['idParts'];
}
}
if ($idparts == "") {
die("server_error");
}
//----------- result_project table ------------------
foreach($part as $result_project) {
//check exist result_project item
// $result_project_query = new WA_MySQLi_RS("getquery", $repnew, 0);
// $sql_result_project_query = "SELECT * FROM result_project WHERE idPart='$idparts' and idreports='$idreports' and idproducts='$idproducts'";
//
$arr_result_project_need_idx = array();
for ($i = 0; $i < count($arr_associate); $i++) {
if ($arr_associate[$i]->table_name == "result_project") {
array_push($arr_result_project_need_idx, array($arr_associate[$i]->column_name, array_search($arr_associate[$i]->headerfile, $arr_excel_columns)));
}
}
//
// foreach($arr_result_project_need_idx as $q) {
// $sql_result_project_query .= " and ".$q[0]."='".$q[0]."'";
// }
//
// $result_project_query->setQuery($sql_result_project_query);
// $result_project_query->execute();
//
// $result_project_info = $result_project_query->Results;
//
// if (count($result_project_info) == 0) {
$InsertQuery = new WA_MySQLi_Query($repnew);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "`result_project`";
$InsertQuery->bindColumn("idPart", "s", $idparts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idproducts", "i", "" . $idproducts . "", "WA_DEFAULT");
$InsertQuery->bindColumn("idreports", "i", "" . $idreports . "", "WA_DEFAULT");
$InsertQuery->bindColumn("importcode", "i", "" . $importcode . "", "WA_DEFAULT");
for ($i = 0; $i < count($arr_result_project_need_idx); $i++) {
$InsertQuery->bindColumn($arr_result_project_need_idx[$i][0], "s", $result_project[$arr_result_project_need_idx[$i][1]], "WA_DEFAULT");
}
$InsertQuery->saveInSession("");
$InsertQuery->execute();
// }
}
}
}
}
$UpdateQuery = new WA_MySQLi_Query($repnew);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "`template_import_his`";
$UpdateQuery->bindColumn("f_status", "i", "1", "WA_DEFAULT");
$UpdateQuery->addFilter("importcode", "=", "s", "".$importcode . "");
$UpdateQuery->execute();

View File

@ -131,7 +131,7 @@
<h5 class="header-title pb-3 mt-0">Importify: <?php echo $dashboard; ?></h5>
<a class="btn btn-primary" href="insert-importifytemplate.php" role="button">Insert new template</a>
<a class="btn btn-success" href="rsl-category.php" role="button">Import File</a>
<a href="archiveimport.php"><button type="button" class="btn btn-info w-md waves-effect waves-light">Hystory Import</button></a>
<a href="history_importify.php"><button type="button" class="btn btn-info w-md waves-effect waves-light">Hystory Import</button></a>
<a href="importifydashboard.php"><button type="button" class="btn btn-pink w-md waves-effect waves-light">Importify Dasboard</button></a>
<a href="dashboard.php"><button type="button" class="btn btn-danger w-md waves-effect waves-light">Reportify Dasboard</button></a>
@ -260,7 +260,7 @@
success: function(data) {
$('#ajax_preloader').fadeOut();
if(data.indexOf("success") > -1) {
showSuccessPopup("Your operation succeeded!");
showSuccessPopup("Your operation requested!");
}else if(data.indexOf("none_define_column_error") > -1) {
showWarningPopup("The Associate Columns did not define yet!");
} else if(data.indexOf("invalid_excel_data_format_error") > -1) {