commit basic source of milestone 2

This commit is contained in:
starthomas610 2024-06-13 15:34:42 -04:00
parent 73f1fddbb4
commit c3596bca87
6 changed files with 419 additions and 20 deletions

View File

@ -9,3 +9,32 @@ function getWithoutSpaceStr(str) {
function showWarningAlert(str) {
alertify.logPosition("top right").error("<i class='ion-alert-circled'><i> " + str + "");
}
function showWarningPopup(str, callback = null, confirm_str = "Confirm") {
Swal.fire({
title: 'Warning!',
text: str,
icon: 'warning',
showCancelButton: false,
confirmButtonColor: '#d33',
confirmButtonText: 'Confirm',
}).then((result) => {
if(callback) {
callback();
}
});
}
function showSuccessPopup(str, callback = null) {
Swal.fire({
title: 'Success',
text: str,
icon: 'success',
showCancelButton: false,
confirmButtonColor: '#3085d6',
confirmButtonText: 'Confirm'
}).then((result) => {
if(callback)
callback();
});
}

View File

@ -326,6 +326,7 @@
contentType: false,
beforeSend: function() {
$('#ajax_preloader').fadeIn();
$('#f_csv').val("");
},
error: function() {
$('#ajax_preloader').fadeOut();
@ -438,19 +439,8 @@
success: function(data) {
$('#ajax_preloader').fadeOut();
console.log(data);
Swal.fire({
title: 'Success',
text: "Your operation successed!",
icon: 'success',
showCancelButton: false,
confirmButtonColor: '#3085d6',
confirmButtonText: 'Confirm'
}).then((result) => {
if (result.isConfirmed) {
history.go(-1);
} else {
history.go(-1);
}
showSuccessPopup("Your operation succeeded!", function() {
history.go(-1);
});
}
})
@ -494,7 +484,7 @@
// console.log(data);
// Swal.fire({
// title: 'Success',
// text: "Your operation successed!",
// text: "Your operation succeeded!",
// icon: 'success',
// showCancelButton: false,
// confirmButtonColor: '#3085d6',

View File

@ -2,9 +2,10 @@
require '../../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
if(isset($_FILES['f_csv'])) {
$file = $_FILES['f_csv']['tmp_name'];
$spreadsheet = IOFactory::load($file);
$spreadsheet = IOFactory::load($file, IReader::READ_DATA_ONLY);
$worksheet = $spreadsheet->getActiveSheet();
$arr_info = $worksheet->toArray();
if(count($arr_info) > 0) {

View File

@ -0,0 +1,316 @@
<?php include('../include/headscript.php'); ?>
<?php
require '../../vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
if(isset($_FILES['f_csv'])) {
$file = $_FILES['f_csv']['tmp_name'];
$template_id = $_POST['template_id'];
//get template associate data
$arr_associate_data = new WA_MySQLi_RS("rsl", $repnew, 0);
$arr_associate_data->setQuery("SELECT * FROM template_associate where template_importify_id=$template_id");
$arr_associate_data->execute();
$arr_associate = $arr_associate_data->Results;
if(count($arr_associate) > 0) { //check define columns
$spreadsheet = IOFactory::load($file, IReader::READ_DATA_ONLY);
$worksheet = $spreadsheet->getActiveSheet();
$arr_info = $worksheet->toArray();
if(count($arr_info) > 1) { //check excel rows
$arr_excel_columns = $arr_info[0];
$arr_need_columns = array();
array_push($arr_need_columns, "Sample Code (PO#)");
array_push($arr_need_columns, "Report no.");
array_push($arr_need_columns, "Part No.");
foreach($arr_associate as $item) {
array_push($arr_need_columns, $item['headerfile']);
}
//check excel data column with template associate data
$verify_flag = true;
for($i=0; $i<count($arr_need_columns); $i++) {
if(!in_array($arr_need_columns[$i], $arr_excel_columns)) {
$verify_flag = false;
break;
}
}
if($verify_flag) {
//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 = "";
for($i=1; $i<count($arr_info); $i++) {
if($arr_info[$i][$idx_sample_code_po] == $tmp_sample_code_po) {
array_push($tmp_arr_child_products, $arr_info[$i]);
} else {
if($tmp_sample_code_po != "") {
if(count($tmp_arr_child_products) > 0) {
array_push($arr_total_products, $tmp_arr_child_products);
}
}
$tmp_sample_code_po = $arr_info[$i][$idx_sample_code_po];
$tmp_arr_child_products = array();
array_push($tmp_arr_child_products, $arr_info[$i]);
}
}
if(count($tmp_arr_child_products) > 0) {
array_push($arr_total_products, $tmp_arr_child_products);
}
//define importcode (timestamp)
$importcode = time();
//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'], $i));
}
}
$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'], $i));
}
}
$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'], $i));
}
}
$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'], $i));
}
}
foreach($arr_result_project_need_idx as $q) {
$sql_result_project_query .= " and ".$q[0]."='".$q[1]."'";
}
$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 {
die("invalid_excel_data_format_error");
}
} else {
die("invalid_excel_data_format_error");
}
} else {
die("none_define_column_error");
}
} else {
die("file_empty_error");
}

View File

@ -20,12 +20,24 @@
<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">
<script src="../assets/js/jquery.min.js"></script>
<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;
@ -74,6 +86,12 @@
</div>
</div>
<div id="ajax_preloader">
<div id="status">
<div class="spinner"></div>
</div>
</div>
<!-- Begin page -->
<div id="wrapper">
@ -154,7 +172,7 @@
<td>
<a href="runimport.php?idimporttemplates=<?php echo ($templateimportify->getColumnVal("idimporttemplates")); ?>">
<a onclick="onRunImport(<?php echo ($templateimportify->getColumnVal("idimporttemplates")); ?>)">
<button type="button" class="btn btn-danger waves-effect waves-light" data-toggle="tooltip" title="Run Import">
<i class="fas fa-play font-size-16 align-middle"></i>
</button>
@ -185,6 +203,7 @@
?></tbody>
</table>
</div><!--end table-responsive-->
<input id="f_csv" type="file" name="f_csv" style="display: none" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/csv">
<script>
document.addEventListener('DOMContentLoaded', function() {
const deleteButtons = document.querySelectorAll('.canc-btn');
@ -211,8 +230,50 @@
});
});
});
</script>
let tmp_id_template_importify = 0;
function onRunImport(id_template_importify) {
tmp_id_template_importify = id_template_importify;
$('#f_csv').trigger("click");
}
$('#f_csv').change(function(){
let formdata = new FormData();
if($(this).prop('files').length > 0) {
formdata.append("f_csv", $(this).prop('files')[0]);
formdata.append("template_id", tmp_id_template_importify);
$.ajax({
url: 'import_auto_script.php',
type: 'POST',
data: formdata,
processData: false,
contentType: false,
beforeSend: function() {
$('#ajax_preloader').fadeIn();
$('#f_csv').val("");
},
error: function() {
$('#ajax_preloader').fadeOut();
showWarningAlert("Server Error");
},
success: function(data) {
$('#ajax_preloader').fadeOut();
if(data.indexOf("success") > -1) {
showSuccessPopup("Your operation succeeded!");
}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) {
showWarningPopup("Excel data format is not valid!")
} else {
showWarningAlert("Server Error.")
}
console.log(data);
}
})
}
});
</script>
</div>
</div>
</div>
@ -236,11 +297,11 @@
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
$('#ajax_preloader').fadeOut();
});
</script>
<!-- plugin JS -->
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/popper.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/modernizr.min.js"></script>
@ -251,14 +312,16 @@
<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>
</body>
</html>
</html>

View File

@ -7,7 +7,7 @@ $arr_selected_csv = json_decode($_POST['arr_selected_csv']);
$arr_selected_tbl_title = json_decode($_POST['arr_selected_tbl_title']);
$arr_selected_tbl_name = json_decode($_POST['arr_selected_tbl_name']);
$arr_db_headerfile = json_decode($_POST['arr_db_headerfile']);
ini_set('memory_limit', '128M');
$deleteQuery = new WA_MySQLi_Query($repnew);
$deleteQuery->Action = "delete";
$deleteQuery->Table = "`template_associate`";