
    6Mjq              
       H   d Z ddlZddlZddlZej                  j                  ej                  j                  e            Zej                  j                  ed      Z
e
fdZd Zd Zedk(  r4 e       Z edd	d
ddddde      Z e ej$                  edd             yy)u?  
Moteur de prix du calculateur Support-Héros (volume-first, orienté résultat).

Aucune constante en dur: tout vient de pricing_config.json (éditable).
Principe: prix = heures standard estimées x taux cible, majoré selon la
complexité (type client, secteur), arrondi à la cinquantaine supérieure,
plancher au forfait minimum. Le sur-mesure (bloc Métier & Adaptation) n'est
jamais auto-chiffré: il porte un flag RDV. Toute estimation se termine sur un RDV.

Usage:
    from pricing_engine import load_config, estimate
    cfg = load_config()
    res = estimate({
        "nb_factures_vente": 30, "nb_depenses": 20,
        "nb_collaborateurs": 5, "nb_lignes_bancaires": 2,
        "type_client": 1, "secteur": 1,
        "services": ["ventes", "achats", "rh", "precompta"],
        "metier_adaptation": False,
    }, cfg)
    Nzpricing_config.jsonc                 r    t        | d      5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nzutf-8)encoding)openjsonload)pathfs     ,/root/workspace/Calculette/pricing_engine.pyload_configr      s.    	dW	% yy|  s   -6c                     |r)|dkD  r$t        t        j                  | |z        |z        S t        t        j                  |             S )Nr   )intmathceil)valuesteps     r
   _ceil_tor   #   s<    q499UT\*T122tyy      c                 Z   |d   }|d   }| j                  d      }g }d}|j                         D ]  \  }}t        | j                  |d   d      xs d      }	|||v n|	dkD  }
|
r|	dk  r;t        |j                  dd      xs d      }|d	   d
z  |	d|z
  z  z  }||z  }|	r|d
z  |	z  nd}|j                  ||d   |d   |	|d	   t	        |d      t	        |d      t	        ||z  d      d        g }d}|j                  di       j                  dg       D ci c]  }|d   |
 }}| j                  dg       xs g D ]  }|j                  |      }|s|d   dk(  rLt        |j                  dd      xs d      }||z  }|j                  ||d   d|t	        ||z  d      d       kd}|j                  ||d   ddd        ||z  }|d   j                  t        | j                  dd            d      }|d   j                  t        | j                  dd            d      }d}|j                  d i       }|j                  d!      r^t        | j                  d"d      xs d      }|j                  d#g       D ]*  }||j                  d$d      k\  s|j                  d%d      }, |d|z   |z   z  |z  }|dkD  rt        ||j                  d&d            nd}|dkD  rt        ||j                  d'd            nd}t        | j                  d(            }|d)   }|t	        |d      |rt	        ||z  d      ndt	        |d      |||||||d   d|r|d*   ndd+d|j                  d,i       j                  d!      r%|j                  d,i       j                  d-d      d.d/S dd.d/S c c}w )0a  Compute a monthly forfait estimate from prospect inputs.

    inputs keys (all optional, default 0 / off):
      nb_factures_vente, nb_depenses, nb_collaborateurs, nb_lignes_bancaires
      type_client (1..5), secteur (1..9)
      services: list of active standard block keys (default: all with driver>0)
      metier_adaptation: bool (adds the RDV-scoped block)
    Returns a dict with the price, the per-block breakdown, and flags.
    taux_cible_eur_hblocs_standardsservicesg        driverr   Ndegressivite_elasticiteminutes_par_uniteg      N@   label   )blocr   r   quantiter   minutes_effectives_par_uniteheures
montant_htFoptions_missions	catalogueidoptionstyper!   heures_mois)r%   r   r'   r!   r"   Trdv)r%   r   r'   r"   majoration_type_clienttype_clientmajoration_secteursecteurg      ?modulateur_caactifcapaliersca_minfacteurforfait_minimum_eurarrondi_superieur_ametier_adaptationbloc_metier_adaptationaction)selectionner   
auto_pricer8   
onboardingmontant_euru1   Estimation indicative. À valider/ajuster en RDV.)forfait_mensuel_htheures_standard_estimeestaux_implicitesous_total_htr*   r,   
facteur_cadetail_blocsr#   r7   necessite_rdvonboarding_htnote)	getitemsfloatappendroundstrmaxr   bool) inputscfgrateblocksselected	breakdowntotal_hourskeyb
driver_valactiveehourseff_minoptions_outopts_rdvor$   oidhsubtotalmaj_typemaj_sect	ca_factormodr0   p	price_rawprice_flooredpricemetiermbs                                    r
   estimaterl   )   sE    !"D"#F zz*%HIK,,. Q6::ak15:;
&.&:#/aq !%%115:;&'$.:!a%3HIu/9%$,+qwZk"!"#6!7,1'1,=E1oa0	
 		. KH%(WW-?%D%H%HVX%YZ4!ZIZzz)R(.B 5MM#V9 aeeM1-23A1KcAgJ+,E!d(A<N P Q HcAgJ.2 4 55 T!H +,00VZZq5Q1RTWXH'(,,SIq1I-JCPH I
''/2
&C
www6::dA&+!,B' 	2AQUU8Q''EE)S1		2 AL834y@I JSUVC	377+@!#DE\]MJWZ[J[H]CGG,A1$EFabE &**012F	%	&B $$)+q$9;F% 3Q7Dx+"*&!'![&,bl$	#
 LOGGT`bdLeLiLijqLrr266}aHC% " yzC% Q [s   N(__main__         r         T)nb_factures_ventenb_depensesnb_collaborateursnb_lignes_bancairesr+   r-   r6   F)ensure_asciiindent)__doc__r   r   osr   dirnameabspath__file__HEREjoinCONFIG_PATHr   r   rl   __name__rO   demoprintdumps r   r
   <module>r      s   (   		wwrwwx01ggll4!67 ! 
!eP z
-CqQT 	D
 
*$**Ta
89 r   