@@ -1262,6 +1262,69 @@ private static function getDocumentiPrecedenti($id_record, $tipo_record)
12621262 }
12631263 }
12641264
1265+ // Per gli interventi, controlla se ci sono documenti precedenti tramite id_contratto, id_ordine o id_preventivo
1266+ if ($ tipo_record == 'intervento ' ) {
1267+ // Recupera i campi dell'intervento
1268+ $ query_intervento = 'SELECT id_contratto, id_ordine, id_preventivo FROM in_interventi WHERE id = ' .prepare ($ id_record );
1269+ $ intervento = $ dbo ->fetchOne ($ query_intervento );
1270+
1271+ if ($ intervento ) {
1272+ // Se c'è un contratto collegato
1273+ if (!empty ($ intervento ['id_contratto ' ])) {
1274+ $ doc_info = self ::getInfoDocumento ($ intervento ['id_contratto ' ], 'Modules \\Contratti \\Contratto ' );
1275+ if ($ doc_info ) {
1276+ // Verifica che non sia già stato aggiunto
1277+ $ già_presente = false ;
1278+ foreach ($ documenti_precedenti as $ doc ) {
1279+ if ($ doc ['id ' ] == $ doc_info ['id ' ] && $ doc ['tipo_documento ' ] == $ doc_info ['tipo_documento ' ]) {
1280+ $ già_presente = true ;
1281+ break ;
1282+ }
1283+ }
1284+ if (!$ già_presente ) {
1285+ $ documenti_precedenti [] = $ doc_info ;
1286+ }
1287+ }
1288+ }
1289+
1290+ // Se c'è un ordine collegato
1291+ if (!empty ($ intervento ['id_ordine ' ])) {
1292+ $ doc_info = self ::getInfoDocumento ($ intervento ['id_ordine ' ], 'Modules \\Ordini \\Ordine ' );
1293+ if ($ doc_info ) {
1294+ // Verifica che non sia già stato aggiunto
1295+ $ già_presente = false ;
1296+ foreach ($ documenti_precedenti as $ doc ) {
1297+ if ($ doc ['id ' ] == $ doc_info ['id ' ] && $ doc ['tipo_documento ' ] == $ doc_info ['tipo_documento ' ]) {
1298+ $ già_presente = true ;
1299+ break ;
1300+ }
1301+ }
1302+ if (!$ già_presente ) {
1303+ $ documenti_precedenti [] = $ doc_info ;
1304+ }
1305+ }
1306+ }
1307+
1308+ // Se c'è un preventivo collegato
1309+ if (!empty ($ intervento ['id_preventivo ' ])) {
1310+ $ doc_info = self ::getInfoDocumento ($ intervento ['id_preventivo ' ], 'Modules \\Preventivi \\Preventivo ' );
1311+ if ($ doc_info ) {
1312+ // Verifica che non sia già stato aggiunto
1313+ $ già_presente = false ;
1314+ foreach ($ documenti_precedenti as $ doc ) {
1315+ if ($ doc ['id ' ] == $ doc_info ['id ' ] && $ doc ['tipo_documento ' ] == $ doc_info ['tipo_documento ' ]) {
1316+ $ già_presente = true ;
1317+ break ;
1318+ }
1319+ }
1320+ if (!$ già_presente ) {
1321+ $ documenti_precedenti [] = $ doc_info ;
1322+ }
1323+ }
1324+ }
1325+ }
1326+ }
1327+
12651328 return $ documenti_precedenti ;
12661329 }
12671330
@@ -1315,6 +1378,42 @@ private static function getDocumentiSuccessivi($id_record, $tipo_record)
13151378 }
13161379 }
13171380
1381+ // controlla in in_interventi se ci sono interventi con id_contratto = $id_record
1382+ if ($ tipo_record == 'contratto ' ) {
1383+ $ query = 'SELECT DISTINCT id FROM in_interventi WHERE id_contratto = ' .prepare ($ id_record );
1384+ $ risultati = $ dbo ->fetchArray ($ query );
1385+ foreach ($ risultati as $ risultato ) {
1386+ $ doc_info = self ::getInfoDocumento ($ risultato ['id ' ], 'Modules \\Interventi \\Intervento ' );
1387+ if ($ doc_info ) {
1388+ $ documenti_successivi [] = $ doc_info ;
1389+ }
1390+ }
1391+ }
1392+
1393+ // controlla in in_interventi se ci sono interventi con id_ordine = $id_record
1394+ if ($ tipo_record == 'ordine ' ) {
1395+ $ query = 'SELECT DISTINCT id FROM in_interventi WHERE id_ordine = ' .prepare ($ id_record );
1396+ $ risultati = $ dbo ->fetchArray ($ query );
1397+ foreach ($ risultati as $ risultato ) {
1398+ $ doc_info = self ::getInfoDocumento ($ risultato ['id ' ], 'Modules \\Interventi \\Intervento ' );
1399+ if ($ doc_info ) {
1400+ $ documenti_successivi [] = $ doc_info ;
1401+ }
1402+ }
1403+ }
1404+
1405+ // controlla in in_interventi se ci sono interventi con id_preventivo = $id_record
1406+ if ($ tipo_record == 'preventivo ' ) {
1407+ $ query = 'SELECT DISTINCT id FROM in_interventi WHERE id_preventivo = ' .prepare ($ id_record );
1408+ $ risultati = $ dbo ->fetchArray ($ query );
1409+ foreach ($ risultati as $ risultato ) {
1410+ $ doc_info = self ::getInfoDocumento ($ risultato ['id ' ], 'Modules \\Interventi \\Intervento ' );
1411+ if ($ doc_info ) {
1412+ $ documenti_successivi [] = $ doc_info ;
1413+ }
1414+ }
1415+ }
1416+
13181417 return $ documenti_successivi ;
13191418 }
13201419
0 commit comments