This commit is contained in:
Lasha Kapanadze 2024-10-04 22:17:48 +04:00
parent 2ea676adae
commit cf90143b77
5 changed files with 104 additions and 26 deletions

View File

@ -15,9 +15,14 @@ if(isset($_FILES['f_csv'])) {
$arr_associate = $arr_associate_data->Results;
if(count($arr_associate) > 0) { //check define columns
$spreadsheet = IOFactory::load($file, IReader::READ_DATA_ONLY);
$spreadsheet = IOFactory::load($file);
$worksheet = $spreadsheet->getActiveSheet();
$arr_info = $worksheet->toArray();
$arr_info = $worksheet->toArray();
// remove empty rows
$arr_info = array_filter($arr_info, function($row) {
return count(array_filter($row)) > 0;
});
$productsRefNumber_excelName = '';
$reportsNumberLab_excelName = '';
@ -76,7 +81,7 @@ if(isset($_FILES['f_csv'])) {
$verify_flag = false;
break;
}
}
}
if($verify_flag) {
//check result_TestName field

View File

@ -0,0 +1,21 @@
<?php include('../include/headscript.php'); ?>
<?php include("../class/company.php");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$conn = new mysqli($servername, $username, $password, $database);
$query = " SELECT `idlab`,
`name`,
`description`,
`reflab`
FROM `laboratories`";
$result = $conn->query($query);
$laboratories = [];
while ($row = $result->fetch_assoc()) {
$laboratories[] = $row;
}
echo json_encode(array(
'code' => "success",
'laboratories' => $laboratories));
}

View File

@ -37,6 +37,7 @@ function post_async($url, array $params)
if (isset($_FILES['f_csv'])) {
$file = $_FILES['f_csv']['tmp_name'];
$template_id = $_POST['template_id'];
$idLabs = $_POST['lab_id']; // get lab id
//get template associate data
$arr_associate_data = new WA_MySQLi_RS("rsl", $repnew, 0);
@ -158,7 +159,8 @@ if (isset($_FILES['f_csv'])) {
'importcode' => $importcode,
'productsRefNumber_excelName' => $productsRefNumber_excelName,
'reportsNumberLab_excelName' => $reportsNumberLab_excelName,
'partsCode_excelName' => $partsCode_excelName
'partsCode_excelName' => $partsCode_excelName,
'idLabs' => $idLabs
]);
//insert to products table

View File

@ -14,6 +14,7 @@ $importcode = $_POST['importcode'];
$productsRefNumber_excelName = $_POST['productsRefNumber_excelName'];
$reportsNumberLab_excelName = $_POST['reportsNumberLab_excelName'];
$partsCode_excelName = $_POST['partsCode_excelName'];
$idLabs = $_POST['idLabs'];
$sample_code_po_column_name = array_search("products_refnumber", $arr_associate);
@ -120,6 +121,7 @@ foreach ($arr_total_products as $product) {
$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");
$InsertQuery->bindColumn("idLabs", "i", "" . $idLabs . "", "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");
}

View File

@ -142,6 +142,8 @@
<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>
<!-- hidden input for lab id -->
<input type="hidden" id="labor_id" value="">
</ol>
</div>
<h4 class="page-title">Importify</h4>
@ -263,10 +265,10 @@
formdata.append("f_csv", $(this).prop('files')[0]);
formdata.append("template_id", tmp_id_template_importify);
// ask user to choose which lab wants to associate from get_laboratories.php
$.ajax({
url: 'check_vocabulary.php',
type: 'POST',
data: formdata,
url: 'get_laboratories.php',
type: 'POST',
processData: false,
contentType: false,
beforeSend: function() {
@ -280,32 +282,77 @@
success: function(data) {
$('#ajax_preloader').fadeOut();
if(data.indexOf("success") > -1) {
let arr_data = JSON.parse(data);
let arr_analysisvoc = arr_data['arr_analysis_data'];
console.log(arr_analysisvoc);
let arr_compundsvoc = arr_data['arr_compunds_data'];
console.log(arr_compundsvoc);
let arr_labs = JSON.parse(data);
let str_arr_option = '';
for(let i=0; i<arr_labs['laboratories'].length; i++) {
str_arr_option += '<option value="' + arr_labs['laboratories'][i]['idlab'] + '">' + arr_labs['laboratories'][i]['name'] +' - '+arr_labs['laboratories'][i]['description'] + '</option>';
}
tmp_analyvoc_idx = 0;
tmp_compundsvoc_idx = 0;
arr_total_analysisvoc = arr_analysisvoc;
arr_total_compundsvoc = arr_compundsvoc;
tmp_str_arr_compunds_kind_option = '';
tmp_str_arr_kind_option = '';
Swal.fire({
title: 'Which lab wants you to associate?',
html: `<select class="form-control" id="sel_lab">${str_arr_option}</select>`,
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Confirm',
allowOutsideClick: false,
}).then((result) => {
if(result.isConfirmed) {
let lab_id = $('#sel_lab').val();
formdata.append("lab_id", lab_id);
$("#labor_id").val(lab_id);
show_analysis_add_pop();
}else if(data.indexOf("none_define_column_error") > -1) {
$('#f_csv').val("");
showWarningPopup("The Associate Columns did not define yet!");
} else if(data.indexOf("invalid_excel_data_format_error") > -1) {
$('#f_csv').val("");
showWarningPopup("Excel data format is not valid!")
$.ajax({
url: 'check_vocabulary.php',
type: 'POST',
data: formdata,
processData: false,
contentType: false,
beforeSend: function() {
$('#ajax_preloader').fadeIn();
},
error: function() {
$('#f_csv').val("");
$('#ajax_preloader').fadeOut();
showWarningAlert("Server Error");
},
success: function(data) {
$('#ajax_preloader').fadeOut();
if(data.indexOf("success") > -1) {
let arr_data = JSON.parse(data);
let arr_analysisvoc = arr_data['arr_analysis_data'];
console.log(arr_analysisvoc);
let arr_compundsvoc = arr_data['arr_compunds_data'];
console.log(arr_compundsvoc);
tmp_analyvoc_idx = 0;
tmp_compundsvoc_idx = 0;
arr_total_analysisvoc = arr_analysisvoc;
arr_total_compundsvoc = arr_compundsvoc;
tmp_str_arr_compunds_kind_option = '';
tmp_str_arr_kind_option = '';
show_analysis_add_pop();
}else if(data.indexOf("none_define_column_error") > -1) {
$('#f_csv').val("");
showWarningPopup("The Associate Columns did not define yet!");
} else if(data.indexOf("invalid_excel_data_format_error") > -1) {
$('#f_csv').val("");
showWarningPopup("Excel data format is not valid!")
} else {
$('#f_csv').val("");
showWarningAlert("Server Error.")
}
}
})
}
});
} else {
$('#f_csv').val("");
showWarningAlert("Server Error.")
}
}
})
})
}
});
@ -522,6 +569,7 @@
if($('#f_csv').prop('files').length > 0) {
formdata.append("f_csv", $('#f_csv').prop('files')[0]);
formdata.append("template_id", tmp_id_template_importify);
formdata.append("lab_id", $('#labor_id').val());
$.ajax({
url: 'import_auto_script.php',