during clone pars ask to clone analysis related
This commit is contained in:
@@ -10,6 +10,7 @@ $data = json_decode(file_get_contents('php://input'), true);
|
|||||||
|
|
||||||
$sourceIddatadb = isset($data['source_iddatadb']) ? (int)$data['source_iddatadb'] : 0;
|
$sourceIddatadb = isset($data['source_iddatadb']) ? (int)$data['source_iddatadb'] : 0;
|
||||||
$targetList = $data['target_iddatadb_list'] ?? [];
|
$targetList = $data['target_iddatadb_list'] ?? [];
|
||||||
|
$cloneAnalyses = !empty($data['clone_analyses']);
|
||||||
|
|
||||||
$targetIds = array_values(array_unique(array_filter(array_map('intval', (array)$targetList), function ($v) use ($sourceIddatadb) {
|
$targetIds = array_values(array_unique(array_filter(array_map('intval', (array)$targetList), function ($v) use ($sourceIddatadb) {
|
||||||
return $v > 0 && $v !== $sourceIddatadb;
|
return $v > 0 && $v !== $sourceIddatadb;
|
||||||
@@ -62,6 +63,23 @@ try {
|
|||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
");
|
");
|
||||||
|
|
||||||
|
$stmtLoadAnalyses = $pdo->prepare("
|
||||||
|
SELECT idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
||||||
|
analysis_level, is_web_selectable, is_accredited
|
||||||
|
FROM identification_parts_analyses
|
||||||
|
WHERE part_id = ?
|
||||||
|
ORDER BY id ASC
|
||||||
|
");
|
||||||
|
|
||||||
|
$stmtInsertAnalysis = $pdo->prepare("
|
||||||
|
INSERT INTO identification_parts_analyses
|
||||||
|
(part_id, iddatadb, idmatrice, analysis_recordkey, analysis_name, analysis_method,
|
||||||
|
analysis_level, is_web_selectable, is_accredited, created_at, updated_at)
|
||||||
|
VALUES
|
||||||
|
(:part_id, :iddatadb, :idmatrice, :analysis_recordkey, :analysis_name, :analysis_method,
|
||||||
|
:analysis_level, :is_web_selectable, :is_accredited, NOW(), NOW())
|
||||||
|
");
|
||||||
|
|
||||||
$stmtInsertCF = $pdo->prepare("
|
$stmtInsertCF = $pdo->prepare("
|
||||||
INSERT INTO identification_parts_customfields
|
INSERT INTO identification_parts_customfields
|
||||||
(part_id, field_id, value_id, value_text, created_at, updated_at)
|
(part_id, field_id, value_id, value_text, created_at, updated_at)
|
||||||
@@ -71,6 +89,7 @@ try {
|
|||||||
|
|
||||||
$details = [];
|
$details = [];
|
||||||
$totalClonedParts = 0;
|
$totalClonedParts = 0;
|
||||||
|
$totalClonedAnalyses = 0;
|
||||||
|
|
||||||
// 3. Clone source parts to each target record
|
// 3. Clone source parts to each target record
|
||||||
foreach ($targetIds as $targetIddatadb) {
|
foreach ($targetIds as $targetIddatadb) {
|
||||||
@@ -102,6 +121,27 @@ try {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clone linked analyses, if requested
|
||||||
|
if ($cloneAnalyses) {
|
||||||
|
$stmtLoadAnalyses->execute([(int)$part['id']]);
|
||||||
|
$analyses = $stmtLoadAnalyses->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
foreach ($analyses as $an) {
|
||||||
|
$stmtInsertAnalysis->execute([
|
||||||
|
':part_id' => $newPartId,
|
||||||
|
':iddatadb' => $targetIddatadb,
|
||||||
|
':idmatrice' => ($an['idmatrice'] !== null && $an['idmatrice'] !== '') ? (int)$an['idmatrice'] : null,
|
||||||
|
':analysis_recordkey' => $an['analysis_recordkey'],
|
||||||
|
':analysis_name' => $an['analysis_name'] ?? null,
|
||||||
|
':analysis_method' => $an['analysis_method'] ?? null,
|
||||||
|
':analysis_level' => ($an['analysis_level'] !== null && $an['analysis_level'] !== '') ? (int)$an['analysis_level'] : null,
|
||||||
|
':is_web_selectable' => (int)($an['is_web_selectable'] ?? 0),
|
||||||
|
':is_accredited' => (int)($an['is_accredited'] ?? 0),
|
||||||
|
]);
|
||||||
|
$totalClonedAnalyses++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$clonedCountForTarget++;
|
$clonedCountForTarget++;
|
||||||
$totalClonedParts++;
|
$totalClonedParts++;
|
||||||
}
|
}
|
||||||
@@ -119,6 +159,7 @@ try {
|
|||||||
'source_iddatadb' => $sourceIddatadb,
|
'source_iddatadb' => $sourceIddatadb,
|
||||||
'cloned_targets' => count($targetIds),
|
'cloned_targets' => count($targetIds),
|
||||||
'total_cloned_parts' => $totalClonedParts,
|
'total_cloned_parts' => $totalClonedParts,
|
||||||
|
'total_cloned_analyses' => $totalClonedAnalyses,
|
||||||
'details' => $details
|
'details' => $details
|
||||||
]);
|
]);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
|||||||
@@ -188,6 +188,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale di conferma per la clonazione delle parti -->
|
||||||
|
<div class="modal fade" id="cloneConfirmModal" tabindex="-1" aria-labelledby="cloneConfirmModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-sm">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="cloneConfirmModalLabel">Conferma Clonazione</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p class="clone-confirm-message mb-3"></p>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="cloneAnalysesCheckbox">
|
||||||
|
<label class="form-check-label" for="cloneAnalysesCheckbox">
|
||||||
|
Duplica anche le analisi collegate
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Annulla</button>
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" id="cloneConfirmBtn">Conferma</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Finestra modale "Aggiungi preventivo" -->
|
<!-- Finestra modale "Aggiungi preventivo" -->
|
||||||
<div class="modal fade" id="addQuotationModal" tabindex="-1" aria-labelledby="addQuotationModalLabel" aria-hidden="true">
|
<div class="modal fade" id="addQuotationModal" tabindex="-1" aria-labelledby="addQuotationModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-md">
|
<div class="modal-dialog modal-md">
|
||||||
@@ -755,5 +780,13 @@
|
|||||||
padding: 0.1rem 0.25rem !important;
|
padding: 0.1rem 0.25rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#cloneConfirmModal {
|
||||||
|
z-index: 1070 !important
|
||||||
|
}
|
||||||
|
|
||||||
|
#cloneConfirmModal .modal-backdrop {
|
||||||
|
z-index: 1065 !important
|
||||||
|
}
|
||||||
|
|
||||||
/* rosso */
|
/* rosso */
|
||||||
</style>
|
</style>
|
||||||
@@ -2376,15 +2376,42 @@ $(document).ready(function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
// Store context and open confirmation modal (replaces native confirm())
|
||||||
!confirm(
|
$("#cloneConfirmModal").data("source-iddatadb", sourceIddatadb);
|
||||||
|
$("#cloneConfirmModal").data("target-ids", targetIds);
|
||||||
|
$("#cloneConfirmModal")
|
||||||
|
.find(".clone-confirm-message")
|
||||||
|
.text(
|
||||||
`Confermi il clone delle parti del record ${sourceIddatadb} negli altri ${targetIds.length} record visibili?`,
|
`Confermi il clone delle parti del record ${sourceIddatadb} negli altri ${targetIds.length} record visibili?`,
|
||||||
)
|
);
|
||||||
) {
|
$("#cloneAnalysesCheckbox").prop("checked", false);
|
||||||
|
|
||||||
|
const modalInstance = new bootstrap.Modal(
|
||||||
|
document.getElementById("cloneConfirmModal"),
|
||||||
|
{ backdrop: "static", keyboard: false },
|
||||||
|
);
|
||||||
|
modalInstance.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("click", "#cloneConfirmBtn", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const sourceIddatadb = $("#cloneConfirmModal").data("source-iddatadb");
|
||||||
|
const targetIds = $("#cloneConfirmModal").data("target-ids") || [];
|
||||||
|
const cloneAnalyses = $("#cloneAnalysesCheckbox").is(":checked");
|
||||||
|
|
||||||
|
if (!sourceIddatadb || !targetIds.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $btn = $(this);
|
const modalInstance = bootstrap.Modal.getInstance(
|
||||||
|
document.getElementById("cloneConfirmModal"),
|
||||||
|
);
|
||||||
|
if (modalInstance) {
|
||||||
|
modalInstance.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
const $btn = $("#clonePartsBtn");
|
||||||
const originalHtml = $btn.html();
|
const originalHtml = $btn.html();
|
||||||
$btn.prop("disabled", true).html(
|
$btn.prop("disabled", true).html(
|
||||||
'<i class="fas fa-spinner fa-spin"></i> Clonazione...',
|
'<i class="fas fa-spinner fa-spin"></i> Clonazione...',
|
||||||
@@ -2398,15 +2425,20 @@ $(document).ready(function () {
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
source_iddatadb: sourceIddatadb,
|
source_iddatadb: sourceIddatadb,
|
||||||
target_iddatadb_list: targetIds,
|
target_iddatadb_list: targetIds,
|
||||||
|
clone_analyses: cloneAnalyses,
|
||||||
}),
|
}),
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
$btn.prop("disabled", false).html(originalHtml);
|
$btn.prop("disabled", false).html(originalHtml);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
const analysesInfo = cloneAnalyses
|
||||||
|
? `, total cloned analyses: ${response.total_cloned_analyses || 0}`
|
||||||
|
: "";
|
||||||
|
|
||||||
const successMsg = $(
|
const successMsg = $(
|
||||||
`<div class="alert alert-success temp-alert" role="alert">
|
`<div class="alert alert-success temp-alert" role="alert">
|
||||||
Clone completed. Source parts copied to ${response.cloned_targets || 0} record(s), total cloned parts: ${response.total_cloned_parts || 0}.
|
Clone completed. Source parts copied to ${response.cloned_targets || 0} record(s), total cloned parts: ${response.total_cloned_parts || 0}${analysesInfo}.
|
||||||
</div>`,
|
</div>`,
|
||||||
);
|
);
|
||||||
$("#partsModal .modal-body").prepend(successMsg);
|
$("#partsModal .modal-body").prepend(successMsg);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user