<?xml version="1.0" encoding="ISO-8859-1"?>
<INDICATOR title="Intégrité tables" 
	name="iCTI_compta_integrite_tables" 
	type="CTIsql" 
	softCode="iCTI_compta"
	eisOnly="false"
	indicatorKey="" 
	linkView="COMPTA000043">
	<reportTitle><![CDATA[Intégrité tables compta [CONTEXT] [STATUT]]]></reportTitle>
	<reportDescription></reportDescription>
	<SQL database="iCTI">
		<select><![CDATA[		
						SELECT
							now() AS date,
								count_p_historique_ecritures - count_v_historique_ecritures +
								count_p_historique_ecritures_total - count_v_historique_ecritures_total +
								count_p_comptes - count_v_comptes
							AS ecart_total,
							count_p_historique_ecritures,
							count_v_historique_ecritures,
							count_p_historique_ecritures - count_v_historique_ecritures AS ecart_historique_ecritures,
							count_p_historique_ecritures_total,
							count_v_historique_ecritures_total,
							count_p_historique_ecritures_total - count_v_historique_ecritures_total AS ecart_historique_ecritures_total,
							count_p_comptes,
							count_v_comptes,
							count_p_comptes - count_v_comptes AS ecart_comptes
						FROM
							(
							SELECT 
							(SELECT count(*) FROM compta.p_historique_ecritures) AS count_p_historique_ecritures,
							(SELECT count(*) FROM compta.v_historique_ecritures_1) AS count_v_historique_ecritures,
							(SELECT count(*) FROM compta.p_historique_ecritures_total) AS count_p_historique_ecritures_total,
							(SELECT count(*) FROM compta.v_historique_ecritures_total_1) AS count_v_historique_ecritures_total,
							(SELECT count(*) AS count FROM compta.t_comptes	WHERE oid IN (SELECT compte_id FROM compta.p_historique_ecritures_total) OR oid IN (SELECT compte_extra_id FROM compta.p_historique_ecritures_total)) AS count_p_comptes,
							(SELECT count(*) AS count FROM compta.t_comptes_c WHERE oid IN (SELECT compte_id FROM compta.p_historique_ecritures_total) OR oid IN (SELECT compte_extra_id FROM compta.p_historique_ecritures_total)) AS count_v_comptes
							) subview
		]]></select>
	</SQL>
	<ALERT rule_compareField="ecart_historique_ecritures" rule_compareOperator=">" rule_compareValue="0" result="ERROR" resultText="ERREUR d'intégrité sur table p_historique_ecritures" />
	<ALERT rule_compareField="ecart_historique_ecritures_total" rule_compareOperator=">" rule_compareValue="0" result="ERROR" resultText="ERREUR d'intégrité sur table p_historique_ecritures_total" />
	<ALERT rule_compareField="ecart_comptes" rule_compareOperator=">" rule_compareValue="0" result="ERROR" resultText="ERREUR d'intégrité sur table t_comptes" />
	<ALERT rule_compareField="ecart_total" rule_compareOperator="=" rule_compareValue="0" result="OK" resultText="Intégrité CORRECTE" />

</INDICATOR>
