+
    Uj¯  ã                   óŠ   € R t ^ RIHtHtHt ^ RIHtHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHtHt ^ RIHtHt R tR	 tR
# )zÅ
Services de lecture pour le tableau de bord.

Cette couche regroupe uniquement des calculs et agregations d'affichage
afin de ne pas toucher au flux critique facture -> fiscalisation -> paiement.
)ÚdatetimeÚtimeÚ	timedelta)ÚDecimalÚInvalidOperationÚROUND_HALF_UP)ÚSum)Útimezone)Ú#compute_product_specific_tax_amount)ÚClientÚCommandeÚConfigurationÚLigneCommande)ÚCommandeSerializerÚConfigurationSerializerc                 ó@  € / p \         P                  ! 4       p\         P                  ! \        P                  ! V\
        P                  4      4      pV\        ^R7      ,           p\        P                  P                  RVVR7      pVP                  4       V R&   VP                  \        R4      4      R,          ;'       g    ^ V R&   \        P                  P                  \        R4      4      R,          ;'       g    ^ V R&   \        P                  P                  4       V R	&   R
V R&   R
V R&   \        P                  P!                  4       pV'       d‚    \#        \%        VP&                  ;'       g    ^ 4      4      pV^ 8”  dR   W`R&   \#        \%        V R,          ;'       g    ^ 4      4      V,          P)                  \#        R4      \*        R7      V R&   \        P                  P                  RR7      pVP                  4       V R&   VP                  RR7      P                  4       V R&   VP5                  RR7      P                  4       V R&   \        P                  P                  \        R4      4      R,          ;'       g    ^ V R&   \#        \%        V R,          ;'       g    ^ 4      4      \#        \%        V R,          ;'       g    ^ 4      4      ,
          P)                  \#        R4      \*        R7      V R&   VP                  \        R4      4      R,          ;'       g    ^ pV R,          ^ 8”  dW   \#        \%        V4      4      \#        \%        V R,          4      4      ,          P)                  \#        R4      \*        R7      V R&   M\#        R4      V R&   VP                  \        R4      4      R,          ;'       g    ^ V R&   VP                  ^ R7      P                  4       V R&   R
V R &   R
V R!&   V R,          '       d©   \#        \%        V R,          ;'       g    ^ 4      4      V R,          ,          P)                  \#        R4      \*        R7      V R &   \#        \%        V R,          ;'       g    ^ 4      4      V R,          ,          P)                  \#        R4      \*        R7      V R!&   \#        R4      p	\6        P                  P9                  R"4      P                  RR#R$7       F5  p
V	\;        V
P<                  V
P>                  V
P@                  4      ,          p	K7  	  V	P)                  \#        R4      \*        R7      V R%&   \        P                  PC                  4       PE                  R&4      R',          V R(&   V #   \,        \.        \0        \2        3 d
    R
T R&    ELÇi ; i))z;Construit le contexte complet utilise par le dashboard web.)ÚdaysÚFV)Útype_factureÚdate_commande__gteÚdate_commande__ltÚventes_aujourdhui_countÚmontant_totalÚmontant_total__sumÚchiffre_affaires_aujourdhuiÚ	ca_globalÚclients_countNÚca_global_usdÚdashboard_taux_changez0.01)Úrounding)r   Úfactures_emises_countÚPAYEE)Ústatut_paiementÚfactures_emises_payees_countÚ factures_emises_en_attente_countÚtva_montantÚtva_montant__sumÚca_global_tvaÚca_global_htÚticket_moyenz0.00Úremise_globaleÚremise_globale__sumÚreductions_total)Úremise_globale__gtÚreductions_countÚticket_moyen_usdÚreductions_total_usdÚproduitT)Úcommande__type_factureÚproduit__est_taxe_specifiqueÚtaxes_specifiques_totalú-date_commande:Né
   NÚdernieres_commandes)#r	   Ú	localdateÚ
make_awarer   Úcombiner   Úminr   r   ÚobjectsÚfilterÚcountÚ	aggregater   r   r   Úfirstr   ÚstrÚtaux_changeÚquantizer   r   Ú	TypeErrorÚ
ValueErrorÚZeroDivisionErrorÚexcluder   Úselect_relatedr
   r1   Ú
sous_totalÚquantiteÚallÚorder_by)ÚcontextÚtodayÚ	day_startÚday_endÚventes_aujourdhui_qsÚconfigrB   Úfactures_emises_qsÚmontant_factures_emisesr4   Úlignes              Ú4D:\ProjetDjango\FacControl_1.4\dashboard\services.pyÚbuild_dashboard_contextrW      s  € à€Gä×ÒÓ €EÜ×#Ò#¤H×$4Ò$4°U¼D¿H¹HÓ$EÓF€IØœ)¨Ô+Õ+€GÜ#×+Ñ+×2Ñ2ØØ$Ø!ð 3ó Ðð *>×)CÑ)CÓ)E€GÐ%Ñ&à×&Ñ&¤s¨?Ó';Ó<Ð=QÕR×WÐWÐVWð Ð)Ñ*ô 	×Ñ×"Ñ"¤3 Ó#7Ó8Ð9MÕN×SÐSÐRSð ˆKÑô  &Ÿ~™~×3Ñ3Ó5€GˆOÑà#€GˆOÑØ'+€GÐ#Ñ$Ü×"Ñ"×(Ñ(Ó*€Fßð	,Ü!¤# f×&8Ñ&8×&=Ð&=¸AÓ">Ó?ˆKØ˜QŒØ3>Ð/Ñ0äœC ¨Õ 4× 9Ð 9¸Ó:Ó;¸kÕIß‘(œ7 6›?´]�(ÓCð ˜Ñ(ô "×)Ñ)×0Ñ0¸dÐ0ÓCÐØ'9×'?Ñ'?Ó'A€GÐ#Ñ$Ø.@×.GÑ.GØð /Hó /ç�eƒgð Ð*Ñ+ð 3E×2LÑ2LØð 3Mó 3ç�eƒgð Ð.Ñ/ô
 	×Ñ×"Ñ"¤3 }Ó#5Ó6Ð7IÕJ×OÐOÈað ˆOÑô 	”�G˜KÕ(×-Ð-¨AÓ.Ó/Ü
”#�g˜oÕ.×3Ð3°!Ó4Ó
5õ	6ç�hŒw�v‹¬€hÓ7ð ˆNÑð 	×$Ñ$¤S¨Ó%9Ó:Ð;OÕP×UÐUÐTUð ð Ð&Õ'¨!Ô+ä”CÐ/Ó0Ó1Ü”c˜'Ð"9Õ:Ó;Ó<õ=ç
‰(”7˜6“?¬]ˆ(Ó
;ð 	�Òô
 #*¨&£/ˆ�Ñð 	×$Ñ$¤SÐ)9Ó%:Ó;Ð<QÕR×WÐWÐVWð ÐÑð #5×";Ñ";ÈqÐ";Ó"Q×"WÑ"WÓ"Y€GÐÑà"&€GÐÑØ&*€GÐ"Ñ#ØÐ&×'Ô'ä”C˜ Õ/×4Ð4°1Ó5Ó6ØÐ-Õ.õ/ç
‰(”7˜6“?¬]ˆ(Ó
;ð 	Ð"Ñ#ô
 ”C˜Ð 2Õ3×8Ð8°qÓ9Ó:ØÐ-Õ.õ/ç
‰(”7˜6“?¬]ˆ(Ó
;ð 	Ð&Ñ'ô
 & f›oÐÜ×&Ñ&×5Ñ5°iÓ@×GÑGØ#Ø%)ð Hö ˆð 	 Ô#FØ�M‰MØ×ÑØ�N‰Nó$
õ 	
Òñ	ð *A×)IÑ)IÜ�‹Üð *Jó *€GÐ%Ñ&ô
 &.×%5Ñ%5×%9Ñ%9Ó%;×%DÑ%DÐEUÓ%VÐWZÕ%[€GÐ!Ñ"Ø€NøôA !¤)¬ZÔ9JÐKô 	,Ø'+ˆG�OÔ$ð	,ús   ÅU9 Å2A#U9 Õ9 VÖVc                ó  € V P                   p\        P                  P                  4       pV'       d   \	        V4      P
                  M/ p\        P                  P                  VR7      P                  R4      R,          p\        VRR7      P
                  p\        P                  ! 4       P                  4       p\        P                  P                  WR7      pVP                  \        R4      4      R,          ;'       g    ^ pV'       d&   \        V4      \        VP                   4      ,          M^ p	\        P                  P                  WR	7      P                  \        R4      4      R,          ;'       g    ^ p
V'       d&   \        V
4      \        VP                   4      ,          M^ pR
V P"                  ;'       g    V P$                  RV'       d   VP&                  MRRV P)                  4       /pRVRVRRVRV	RV
RV/RV/# )z9Construit la charge utile de l'endpoint API du dashboard.)Úpoint_de_venter5   :Né   NT)Úmany)rY   Údate_commande__dater   r   )Úvendeurr\   ÚusernameÚpdv_nomzPDV InconnuÚrolerR   Ú	user_infoÚstatsÚ	today_usdÚ	today_cdfÚuser_today_usdÚuser_today_cdfÚrecent_transactions)rY   r   r<   r@   r   Údatar   r=   rL   r   r	   ÚnowÚdater?   r   ÚfloatrB   Ú
first_namer^   ÚnomÚget_role_display)ÚuserÚpdvrR   Úconfig_dataÚrecent_salesÚrecent_sales_datarN   Útodays_salesÚtotal_sales_usdÚtotal_sales_cdfÚ
user_salesÚuser_sales_cdfra   s   &            rV   Úbuild_dashboard_api_payloadry   w   sÂ  € à
×
Ñ
€CÜ×"Ñ"×(Ñ(Ó*€Fß:@Ô)¨&Ó1×6Ò6Àb€Kä×#Ñ#×*Ñ*¸#Ð*Ó>×GÑGÐHXÓYÐZ\Õ]€LÜ*¨<¸dÔC×HÑHÐä�LŠL‹N×ÑÓ!€EÜ×#Ñ#×*Ñ*¸#Ð*ÓY€LØ"×,Ñ,¬S°Ó-AÓBÐCWÕX×]Ð]Ð\]€OßLR”e˜OÓ,¬u°V×5GÑ5GÓ/HÖHÐXY€Oô 	×Ñ×Ñ¨ÐÓH×RÑRÜ�Ó ó	
à
õ	 ÷ 	ð 	ð ð	 ÷ GM”U˜:Ó&¬¨v×/AÑ/AÓ)BÖBÐRS€Nð 	�D—O‘O×4Ð4 t§}¡}ØŸc�3—7’7 }Ø�×%Ñ%Ó'ð€Ið 	�+Ø�YØØ˜Ø˜Ø˜jØ˜nð	
ð 	Ð0ð
ð 
ó    N)Ú__doc__r   r   r   Údecimalr   r   r   Údjango.db.modelsr   Údjango.utilsr	   Úfacturation.fiscal_rulesr
   Úfacturation.modelsr   r   r   r   Úfacturation.serializersr   r   rW   ry   © rz   rV   Ú<module>rƒ      s6   ðñ÷ /Ñ .ß <Ñ <å  Ý !å Hß MÓ Mß OòaôH&rz   