
    -h                     P   d dl mZ d dlmZmZ d dlmZmZ ddlT ddl	T ddl
T d dlmZ d dlmZmZ d dlmZ d d	lmZmZmZmZ d d
lmZ ddlT d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dl m!Z!m"Z" d dl#Z#d dl$Z$d Z%d Z&d Z'd Z(d Z)e! e"e%          d                         Z*e! e"e%          d                         Z+d Z,e! e"e%          d                         Z-d Z.d Z/d Z0d Z1d Z2e! e"e%          d                         Z3e!d              Z4d! Z5d" Z6e! e"e%          d#                         Z7 G d$ d%ej8                  Z9 G d& d'ej8                  Z: G d( d)ej8                  Z; G d* d+ej8                  Z< G d, d-ej8                  Z= G d. d/ej8                  Z> G d0 d1ej8                  Z? G d2 d3ej8                  Z@ G d4 d5ejA                  ZBe!d6             ZCd7 ZDe!d8             ZEe!d9             ZFe!d:             ZGe!d;             ZHd< ZId= ZJdS )>    )	DateInput)renderget_object_or_404)viewsetsgenerics   )*)transaction)MaxSum)date)HttpResponseRedirectHttpResponseHttp404JsonResponse)ObjectDoesNotExist)settings)authenticate)timezone)r   )login_requireduser_passes_testNc                     | j         S )N)is_staff)users    %/var/www/html/gestcedole/app/views.pyis_adminr      s
    =    c                 Z   	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }|dk    r)t          dt          t          j                  z             S t          dt          t          j                  z             S )N
/app/loginadminz/app/listapren_admin//app/listapren_libreria/)r   is_authenticated	TypeErrorr   usernamestrr   ANNO_LAVORO)requestuser_is_authenticatedutentes      r   init_appr*      s    > ' = = ? ? > > > ' => ! 2#L111\"F#$;c(BV>W>W$WXXX :SAU=V=V VWWW    55c                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }||j        d}t          j        j        di |
                    dd          }d}d}d| d}	|	||j        ||d	}
|                                dk    r|                    t          d
                    d         }t          |d          }||j        dd}t          j        j        di |}|                                dk    rd}nd}t!          | d|
          S t!          | d|
          S )Nr   r$   r   pr_annoscolpr_libreria	pr_classepr_codfiscale/api/prenLibreria/?format=datatables)url_ajaxannoscollibreriatotale_spesapresenti_consegnatipr_spesapr_spesa__sum   Tr/   r0   pr_consegnatoFzprenotazlist_htmx.htmlz/app/prenota )r   r"   r#   r   r$   LibreriaobjectsfilteridPrenotazioneorder_bydenominazionecount	aggregater   roundr   )r'   r6   r(   r)   libreriaRecdict	righePrenr8   r9   r5   contextrigheConsegnatis               r   listapren_libreriarO   -   s   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=K %KNCCD$+33d33<<[/ZZIL@H@@@H#{G`r~  Xk  l  lG!((Z99/J<++'{~X\]]&.5====  ""A%% $ %g7AAAg7AAAr+   c                 x   	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }| j        dk    rt                      }d}d| d}n,d}t          | j                  }|j        d         }d| d	| d}||d
||d}t          | d|          S )Nr   GETallz/api/allprenotazioni/r4   filtrasel_libreriar3   /ALL)r5   r6   r7   libreriaformmodozallprenotazlist_htmx.html)
r   r"   r#   r   r$   methodFiltraLibreriaFormPOSTdatar   )	r'   r6   r(   r)   formrX   r5   libreria_selrM   s	            r   newlistapren_adminr_   T   s    > ' = = ? ? > > > ' => ! 2#L111\"F~!!G8GGG--Y~.SSS<SSS $u^blpqqG'6@@@r+   c                     t           j                            |          }t          j                            ||          }t          |          |j        |d}t          | d|          S )Npkr.   )r6   r7   listazprenlist.html)r@   rA   getrD   rB   intrF   r   )r'   r6   
libreriaIdrJ   prensrM   s         r   prenlistrh   m   sa    !%%:%66K


%
%H+
%
V
VEx==k6OZ_``G'?G444r   c                    | j         dk    rTt          d           t          j                            |                              dd          }t                      }d}nXd}t          | j                  }|j        d         }t          j                            ||	                              dd          }|	                                d
k    rq|
                    t          d                    d         }t          |d          }|dd}t          j        j        di |}|	                                d
k    rd}	nd}	nd
}d}	||d||	||d}
t          | d|
          S )NrQ   zGET all prenr/   r1   r2   rR   rS   rT   )r0   r/   r   r:   r;   r<   Tr/   r>   FrV   )r6   	risultatir7   r8   r9   rW   rX   zallprenotazlist.htmlr?   )rY   printrD   rA   rB   rE   rZ   r[   r\   rG   rH   r   rI   r   )r'   r6   rL   r]   rX   r^   r8   rK   rN   r9   rM   s              r   listapren_adminrn   s   s   
 ~n (//H/EENN{\kll	!!--Y~. (//LV^/__hhit  wF  G  G	((Z99/J<++'>>&.5====  ""A%% $ %!"_k  EX  im  w{  |  |G'17;;;r   c                    g }d}d}d}t           j                                        }|D ]}t          j                            ||          }|                                }	|	dk    r9|                    t          d                    d         }
t          |
d          }
nd}
|	                    |j
        |	|j        |
d           ||
z  }||	z  }|dz  }||||d}t          | d	|          S )
Nr   r.   r:   r;   r<   )rC   contanome	tot_speser   )r6   totalitotprentot_genzshowtotali_all.html)r@   rA   rR   rD   rB   rG   rH   r   rI   appendrC   rF   r   )r'   r6   rs   ru   	npren_totidxlibreria_recsrigaprenLibrerianum_pren	tot_spesarM   s               r   get_totali_prenr~      s    FGI	C"&&((M  !)00XSW0XX##%%A::",,S__==oNIIq))IIITWx$BTdmnnooo9X	q"fW^__G'0':::r   c                 4   	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }d}t          j                            ||d          	                    dd          }|                    d	          }|
                                dk    r7t          |                    t          d
                    d         d          }nd}t          j                            ||          }	g }
t          dd          D ]}d}d}d}|dk    r|                    |          }t!          d| d|
                                            |
                                dk    r8|                    t          d
                    d         }t          |d          }nd}|
                    |           |
                                dk    rP|	
                                dk    r8|	                    t          d                    d         }t          |d          }||z   }||	|j        |
d}||d<   ||d<   ||d<   t'          | d|          S )Nr   r-   r   Tr=   r1   r2   r   )pr_stato__lter:   r;   r<   fa_annoscolfa_libreria   r1   z# da fatturare classe =
fa_importofa_importo__sum)r6   rl   r7   totali_classetot_fatturabiletot_fatturatotot_generaleztot_libreria_htmx.html)r   r"   r#   r   r$   r@   rA   rB   rD   rE   rG   rI   rH   r   Fatturarangerm   rv   rF   r   )r'   r6   r(   r)   rJ   r8   rN   prenfatturabilir   righeFatturar   classetotale_generaler   tot_fatturabile_classeprenfatturabili_classerM   s                    r   get_totali_libreriar      s   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=KL"*11hVarv1ww  A  A  BM  O^  _  _O#***;;Oq   9 9#j// J J? []^__ ?))hk)ZZLM!** 5 5 Q#2#9#9F#9#K#K"T6TT4J4P4P4R4RTTUUU%++--a//)?)I)I#j//)Z)Z[j)k&)./Eq)I)I& &'"34444!!!!&00\1B1BCCDUVMq11M%5O#,KLe  yF  H  HG)8G$1GO$3GN'3W===r+   c                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }| j        dk    rmt                      }t          j        	                    |d          
                    dd          }d}d}i }t          d	d
          D ]}	d||	<   d}
d|	|d}t          j        j	        di |                                rXt          j        j	        di |                    t          d                    d         ||	<   t          ||	         d          ||	<   |                                dk    r=|                    t          d                    d         }t          |d          }|
|z   }
||d||||d	         |d         |d         |d         |d         |
d}nd}t          | j                  }|j        d         }t$          j                            |          j        }t          j        	                    |d|          
                    dd          }d}i }t          d	d
          D ]}	d||	<   d}
|d|	|d}t          j        j	        di |                                rXt          j        j	        di |                    t          d                    d         ||	<   t          ||	         d          ||	<   |                                dk    r=|                    t          d                    d         }t          |d          }|
|z   }
|||||||d	         |d         |d         |d         |d         |
d}t+          | d|          S )Nr   rQ   Trk   r1   r2   rR   r   r   r   )r>   r1   r/   r:   r;   r<   rV            )r6   rl   r7   rW   rX   r8   tot1tot2tot3tot4tot5
totale_genrS   rT   ra   )r0   r>   r/   )r0   r>   r1   r/   zallconsegnatilist.htmlr?   )r   r"   r#   r   r$   rY   rZ   rD   rA   rB   rE   r   rG   rH   r   rI   r[   r\   r@   rd   rF   r   )r'   r6   r(   r)   r]   rL   rX   r8   r   r   r   rK   rM   r^   denom_librerias                  r   listaconsegnati_adminr      s   > ' = = ? ? > > > ' => ! 2#L111\"F~!! (//XUY/ZZccdo  rA  B  B	Aajj 	H 	HF$%M&!J$(vXVVD#*22T2288:: H(4(<(C(K(Kd(K(K(U(UVYZdVeVe(f(fgv(wf%(-mF.CQ(G(Gf%??a",,S__==oNL|Q//L!,.J'iUcgqu  HT  ^k  lm  ^n  xE  FG  xH  R_  `a  Rb  ly  z{  l|  FS  TU  FV  dn  p  p--Y~.'++|+<<J (//LX\ks/tt}}  J  L[  \  \	Aajj 	H 	HF$%M&!J".TZjrssD#*22T2288:: H(4(<(C(K(Kd(K(K(U(UVYZdVeVe(f(fgv(wf%(-mF.CQ(G(Gf%??a",,S__==oNL|Q//L!,.J'iNkoy}  P\  fs  tu  fv  @M  NO  @P  Zg  hi  Zj  tA  BC  tD  N[  \]  N^  lv  x  x'3W===r+   c                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }	 t          j        	                    |          }n# t          $ r t          d          w xY wd|_        |                                 t          dt          t          j                  z             S )Nr   r-   r   ra   Record inesistenteFr!   r   r"   r#   r   r$   r@   rA   rB   rD   rd   r   r   r>   saver%   r   r&   r'   rC   r(   r)   rJ   prens         r   reset_no_consegnator   #  s
   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=K,#''2'.. , , ,*+++, DIIKKK :SAU=V=V VWWW    55< B B7c                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }	 t          j        	                    |          }n# t          $ r t          d          w xY wd|_        |                                 t          dt          t          j                  z             S )Nr   r-   r   ra   r   Tr!   r   r   s         r   move_to_consegnator   9  s
   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=K,#''2'.. , , ,*+++, DIIKKK :C@T<U<U UVVVr   c           	         	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }i }d|d<   d|d<   d|d	<   d
|d<   d|d<   | j        dk    r+t          j
        t          j        |d}t          |          }nt          | j                  }|                                r|                    d          }|t#          |j        d                            |_        |j                            dd          dk    }|r|xj        dz  c_        |                                 t+          ddt-          j        d dd          i          S t1          |j                   t1          d           ||j        t7          t          j
                  dd}	t9          | d|	          S ) Nr   r-   r   1@r   HzG8@r<   GzA@r   皙F@r   fffffK@r   rQ   )r/   pr_data_richiestar0   initialFcommitr1   pr_facoltativooffon皙 @   
HX-TriggerzPrenotazione inserita.PrenChangedshowMessagestatusheaderserrori in form di prenotaz)r]   r7   r6   add_recprenota_modal.html)r   r"   r#   r   r$   r@   rA   rB   rY   r   r&   r   todayPrenotaFormr[   is_validr   re   r\   r:   rd   r   jsondumpsrm   errorsrF   r%   r   )
r'   r(   r)   rJ   
dict_spesarK   r]   fr   rM   s
             r   prenota_insertr   O  s   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=KJJqMJqMJqMJqMJqM~ &1"&*[  4((( 7<((==?? 	0iiui%%A"3ty'=#>#>?AJ!Y]]+;UCCtKN $

t#

FFHHH $*'+'@. . # #    $+.///(AsS[SgOhOhstuuG'/';;;r+   c           
         	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S 	 t          j                            |          }n# t          $ r t          d          w xY wi }d|d<   d|d<   d|d	<   d
|d<   d|d<   | j	        dk    rt          |          }nt          | j        |          }|                                r|                    d          }|t          |j        d                            |_        |j                            dd          dk    }|r|xj        dz  c_        |j                            dd          dk    }|                                 t#          ddt%          j        d d| dd          i          S t)          d           |||j        dd }	t-          | d!|	          S )"Nr   ra   r   r   r   r   r<   r   r   r   r   r   r   rQ   instanceFr   r1   r   r   r   r   r>   r   r   zPrenotazione # aggiornata.r   r   r   r   )r]   prenIdr6   r   r   )r   r"   r#   r   rD   rA   rd   r   r   rY   r   r[   r   r   re   r\   r:   r   r   r   rm   r/   r   )
r'   rC   r(   r   r   r]   r   r   r>   rM   s
             r   prenota_editr     s1   > ' = = ? ? > > > ' => ! 2#L111,#''2'.. , , ,*+++, JJqMJqMJqMJqMJqM~D))) 7<$777==?? 	0iiui%%A"3ty'=#>#>?AJ!Y]]+;UCCtKN $

t#

 IMM/5AATIMFFHHH $*'+'H'H'H'H. . # #    .///rt7GRSTTG'/999s    55
 A+ +Bc                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }t          t          |          }|
                                 t          dt          j         d          S )Nr   r-   r   ra   r!   rU   )r   r"   r#   r   r$   r@   rA   rB   r   rD   deleter   r&   )r'   rC   r(   r)   rJ   prenotaziones         r   prenota_delr     s    > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=K$\b999L R8;O R R RSSSr+   c                    t           j        dz   }t          j                            |          s0d}t                      d|t           j        d}t          | d|          S | j        dk    rt                      }n&t          | j	                  }|
                                r| j	        d                                         }t          |d          5 }||                                v r6d	|z   d
z   }|d|t           j        d}t          | d|          cd d d            S 	 d d d            n# 1 swxY w Y   t          |d          5 }|                    |dz              d d d            n# 1 swxY w Y   d|z   dz   }|d|t           j        d}t          | d|          S |t           j        d}t          | d|          S )Nz/alunni.csvz Lista codici fiscali non trovataT)r]   
show_toasttoast_messager6   zadd_cfminore.htmlrQ   	cf_minorerzCodice fiscale u    già presente nel filea
zCodice fiscale: z inserito in elenco)r]   r6   )r   BASE_DIRospathexistsCrispyMinoreFormr&   r   rY   r[   r   upperopenreadwrite)r'   filenamemsgrM   r]   r   myfiles          r   admin_addcodfiscaler     s   
  =0H7>>(## =0$&&  ,	
 
 g2G<<<~!!--==?? 	A[17799Ih$$ 	I--+i7:SSC $&*),$,$8	 G "'+>HH	I 	I 	I 	I 	I 	I 	I 	I-	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I h$$ /Y-.../ / / / / / / / / / / / / / / %y03HHC"!$$0	 G '#6@@@)=>>G'.888s%   A D++D/2D/E++E/2E/c           
         t          t          |          }| j        }t          j                            |j                                                  }| j        dk    rt          | j
        |          }|                                r@|                                 t          ddt          j        d d| dd	          i
          S t!          d|j        d          S t          |          }|||dd}t%          | d|          S )Nra   r-   r[   r   r   r   	Fattura #r   FattChangedr   r   Fsuccessr   r   )r]   r7   
fattura_idr   add_fattura_modal.html)r   r   r   r@   rA   rB   r$   firstrY   CreafatturaFormr[   r   r   r   r   r   r   r   r   )r'   rC   
recFatturar)   rJ   myformrM   s          r   fattura_editr     s*   "7r222J\F"))6?)CCIIKKK~ 
CCC?? 	KKMMM $*'+'C2'C'C'C. . # #       -! !   
 j111F;RSTVVG'3W===r   c           
      ,   	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S t	          t
          |          }t          j                            |          	                                rDt          j                            |          
                    d           t          d           n	 |                                 t          ddt          j        d d	| d
d          i          S )Nr   ra   )pr_fatturanumr   pr_statozstato passato a 0r   r   r   z eliminata.r   r   )r   r"   r#   r   r   r   rD   rA   rB   r   updaterm   r   r   r   r   )r'   rC   r(   
fatturaRecs       r   fattura_delr     s=   > ' = = ? ? > > > ' => ! 2#L111!'b111J """44;;== ##"#55<<a<HHH!"""" 	$*#:2:::& &  
   r+   c                    	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }t
          j                            |          d         }t          j	        }t          j                            ||                              d          }|                    t          d                    d         }t          j                            ||dd	
                              dd          }g }t          d	d          D ]}	d}
||d|	d	d}t          j        j        di |                                rbt          j        j        di |                    t          d                    d         }t#          |d          }|                    |           |                    d           |||||j        d}t)          | d|          S )Nr   r-   r   r   r   fa_datar   r   Tr   )r/   r0   r>   r   r1   r2   r   )r/   r0   r>   r1   r   r:   r;   r<   )rl   r6   totali_classir   r7   zfatture_libreria.htmlr?   )r   r"   r#   r   r$   r@   rA   rB   r   r&   r   rE   rH   r   rD   r   rG   rI   rv   rF   r   )r'   r6   r(   r)   rJ   fatturelistr   righeFatturabilir  r   r   rK   totfatturabile_classerM   s                 r   listafatture_libreriar  7  sK   > ' = = ? ? > > > ' => ! 2#L111\"F"))6)::1=K!H/(([h(WW``ajkkK''L(9(9::;LMM#+22xWbsw  HI2  J  J  S  S  T_  ap  q  qM!** $ $ 
&{UYhn  AB  C  C&....4466 	$$0$8$?$G$G$$G$G$Q$QRUV`RaRa$b$bcr$s!$)*?$C$C!  !67777  ####&H}mz  HS  Ha  b  bG'2G<<<r+   c                 l   	 | j                                         }n# t          $ r | j         j        }Y nw xY w|st          d          S | j         j        }| j        dk    rEt          j                            |          	                    dd          }t                      }d}nd}t          | j                  }|j        d         }t          j                            ||	          	                    d          }t          j        r7t          d
|z   dz   t!          |                                          z              |                                dk    r9|                    t'          d                    d         }t)          |d          }nd}|dt          j        |||d}	t-          | d|	          S )Nr   rQ   r   r   r  rR   rS   rT   r  zSel libreria:z count:r   r   r   r<   rV   )rl   r7   r6   totale_fatturerW   rX   zallfatturelist.html)r   r"   r#   r   r$   rY   r   rA   rB   rE   rZ   r[   r\   r   DEBUGrm   r%   rG   rH   r   rI   r&   r   )
r'   r6   r(   r)   	righeFattr]   rX   r^   r  rM   s
             r   listafatture_adminr  [  s   	B$+L$A$A$C$C!! 	B 	B 	B$+L$A!!!	B % 	6'555&>U""..8.DDMMm]fggI#%%DDDD#GL11D>2L  ..<U].^^gghqrrI~ Xol2I=IOODUDU@V@VVWWW??Q'11#l2C2CDDEVWN %na 8 8NNN )uI]q  RV  `d  e  eg4g>>>r+   c                   D    e Zd Zej                                        ZeZdS )LibrerieViewSetN)	__name__
__module____qualname__r@   rA   rR   querysetLibrerieSerializerserializer_classr?   r   r   r  r    s*        ##%%H)r   r  c                   D    e Zd Zej                                        ZeZdS )ScuoleViewSetN)	r  r  r  ScuolarA   rR   r  ScuoleSerializerr  r?   r   r   r  r    s)        ~!!##H'r   r  c                       e Zd ZeZd ZdS )AllPrenotazioniViewSetc                     | j         d         }t          j                            |                              d          S )
        This view should return a list of all the purchases for
        the user as determined by the username portion of the URL.
        r6   rj   r   kwargsrD   rA   rB   rE   selfr6   s     r   get_querysetz#AllPrenotazioniViewSet.get_queryset  s9    
 ;z*#***BBKKL_```r   Nr  r  r  PrenotazioniSerializerr  r#  r?   r   r   r  r    .        -a a a a ar   r  c                       e Zd ZeZd ZdS )PrenLibreriaViewSetc                     | j         d         }| j        j        }t          j                            |          d         }t          j                            ||                              d          S )r  r6   r-   r   r.   r   )r   r'   r   r@   rA   rB   rD   rE   r"  r6   r)   rJ   s       r   r#  z PrenLibreriaViewSet.get_queryset  sd    
 ;z*"&--v->>qA#**Q\*]]ffgz{{{r   Nr$  r?   r   r   r(  r(    s.        -
| 
| 
| 
| 
|r   r(  c                       e Zd ZeZd ZdS )AllConsegnatiViewSetc                     | j         d         }t          j                            |d                              d          S )r  r6   Trk   r   r  r!  s     r   r#  z!AllConsegnatiViewSet.get_queryset  s<    
 ;z*#**QU*VV__`stttr   Nr$  r?   r   r   r,  r,    s.        -u u u u ur   r,  c                       e Zd ZeZd ZdS )ConsegnatiLibreriaViewSetc                    | j                             dd           }| j                             dd           }| j        j        }t          j                            |j                                                  }t          j                            |d|          }||                    |          }|
                    d          S )Nr6   stator-   T)r/   r>   r0   r   r   )r   rd   r'   r   r@   rA   rB   r$   r   rD   rE   )r"  annoscol_paramstato_paramr)   rJ   r  s         r   r#  z&ConsegnatiLibreriaViewSet.get_queryset  s    T::koogt44 "&--v-GGMMOO  '..&# / 
 
 "<<H  !4555r   Nr$  r?   r   r   r/  r/    s)        -6 6 6 6 6r   r/  c                       e Zd ZeZd ZdS )FattureLibreriaViewSetc                     | j         d         }| j        j        }t          j                            |j                  d         }t          j                            ||                              d          S )r  r6   r-   r   r   r  )	r   r'   r   r@   rA   rB   r$   r   rE   r*  s       r   r#  z#FattureLibreriaViewSet.get_queryset  sd    
 ;z*"$++V_+EEaH%%HK%XXaabklllr   Nr  r  r  FattureSerializerr  r#  r?   r   r   r5  r5    s.        (m m m m mr   r5  c                       e Zd ZeZd ZdS )AllFattureViewSetc                     | j         d         }t          j                            |                              d          S )r  r6   r
  r  )r   r   rA   rB   rE   r!  s     r   r#  zAllFattureViewSet.get_queryset  s7    
 ;z*%%H%==FFyQQQr   Nr7  r?   r   r   r:  r:    s.        (R R R R Rr   r:  c                       e Zd ZeZd ZdS )PrenLibreriaListc                 x    | j         d         }| j         d         }t          j                            ||          S )r  rf   r6   )pr_libreria__idr/   )r   rD   rA   rB   )r"  rf   r6   s      r   r#  zPrenLibreriaList.get_queryset  s9    
 [.
;z*#**ZW_*```r   Nr$  r?   r   r   r=  r=    r&  r   r=  c                 j   | j         }t          j                            |j                                                  }t          t          j                  }t          j                            |d|d          }t          j                            |d|d          }|||d}t          | d|          S )Nr-   Tr   r/   r>   r0   r   r   )righe_selezionabilirighe_selezionater6   prepara_fattura.htmlr   r@   rA   rB   r$   r   r%   r   r&   rD   r   )r'   r)   rJ   r6   recselezionabilirecselezionaterM   s          r   selprenxfatturarH    s     &--v-GGMMOOh*++'/66 #a 7 
 
 &-44 #a 5 
 
 +;Q_ltuug5w???r   c                 "   | j         }t          j                            |j                                                  }t          t          j                  }t          j                            |d|d          }||d}t          | d|          S )Nr-   Tr   rA  )rC  r6   zprenxfatturare.htmlrE  )r'   r)   rJ   r6   rG  rM   s         r   aggiorna_lista_dafatturarerJ    s    &--v-GGMMOOh*++%-44 #a 5 
 
 )78LLg4g>>>r   c                    | j         }t          j                            |j                                                  }t          t          j                  }t          j                            |d|d          }t          j                            |d|d          }| j
        dk    r>| j                            d          }|r|dk    r|                    |	          }n	|}d}n|}d}||||d
}t          | d|          S )Nr-   Tr   rA  r   r[   r   rR   r   )rB  rC  r6   classe_selezionatarD  )r   r@   rA   rB   r$   r   r%   r   r&   rD   rY   r[   rd   r   )	r'   r)   rJ   r6   rG  recselezionabiliAllr   rF  rM   s	            r   selprenxfattura_xclasserN    s+    \F"))6?)CCIIKKK(&''H!)00 #a 1 1 1N
 '.55$"'! 6 5 5
 ~!!(++ 	foo299V9LL2FF.&6^hp  HN  O  OG'17;;;r   c                    t           j        }| j        }t          j                            |j                                                  }	 t          j                            ||j	        dd          
                    d           t          d          S # t          $ r+}t          dt          |           d	
          cY d }~S d }~ww xY w)Nr-   Tr   r/   r0   r>   r   r   r   z/app/selprenxfattura/z,Errore durante l'aggiornamento dello stato:   r   )r   r&   r   r@   rA   rB   r$   r   rD   rC   r   r   	Exceptionr   r%   )r'   r6   r)   rJ   es        r   azzera_lista_selezionaterU  2  s    '&--v-GGMMOO	e ''H+.hlwx'yy  A  A  KL  A  M  M  M'(?@@@ 	e 	e 	e WsSTvv W W`cddddddddd	es   A
B 
C! CCCc                 t   t           j        }| j        }t          j                            |j                                                  }| j        dk    rP| j	        
                    d          }|dk    r	 t          j                            ||j        dd|          }|                                dk    r|                    d	           n8# t          $ r+}t!          d
t#          |           d          cY d }~S d }~ww xY wt%          ddi          S t&           	 t          j                            ||j        dd                              d	           n8# t          $ r+}t!          d
t#          |           d          cY d }~S d }~ww xY wt%          ddi          S t%          ddid          S )Nr-   r[   r   rR   Tr   )r/   r0   r>   r   r1   r   r   z,Errore durante l'aggiornamento della lista: rQ  rR  messagez0Aggiornamento della lista eseguito con successo.rP  errorzRichiesta non valida.  )r   r&   r   r@   rA   rB   r$   r   rY   r[   rd   rD   rC   rG   r   rS  r   r%   r   rm   )r'   r6   r)   rJ   rL  recsrT  s          r   set_filtrati_selezionatir[  A  s    #H\F"))6?)CCIIKKK~$\--h77 &&i#+22xU`Ucsw  CD  Pb2  c  c::<<>>KKK+++ i i i#$[SVWXSYSY$[$[dghhhhhhhhhi  ,^ _```Ei$++knlp{|+}}  E  E  OP  E  Q  Q  Q  Q i i i#$[SVWXSYSY$[$[dghhhhhhhhhi  ,^ _``` W&=>sKKKKs=   8AC 
D D :D D!<E 
F( FFFc                    | j         }t          j                            |j                                                  }t          t          j                  }t          j
                                                    }||j        ddd}t          j        j        di |}|                    t          d                    d         }|rt!          |d          nd}| j        d	k    rt%          | j                  }|                                rt+          j                    5  |                    d
          }	|	                                 |                    d|	j                   d d d            n# 1 swxY w Y   t5          ddd          S t7          d           t7          |j                   t5          d
|j        d          S t%          ||||d          }||d}
t;          | d|
          S )Nr-   Tr   rP  r:   r;   r<   g        r[   Fr   )r   r   zFattura creata.)r   rW  errorir   )r   r   r   r  r   )r]   r7   r   r?   )r   r@   rA   rB   r$   r   r%   r   r&   r   nowr   rC   rD   rH   r   rI   rY   r   r[   r   r
   atomicr   r   rb   r   rm   r   r   )r'   r)   rJ   r6   oggirK   righexFatturaimporto_fatturar   fatturarM   s              r   prepara_fatturard  h  sO    \F"))6?)CCIIKKK8'((H<>>  D#KNUYghiiD (/77$77M#--c*oo>>OO3BKeOQ///O~ ..?? 	#%% K K ++U+33$$awz$JJJK K K K K K K K K K K K K K K  ,! !   
 (OOO&-     -! !   
 %"	& &   F ;77G'3W===s   !AE44E8;E8c                 h    t           j                            d          }t          | dd|i          S )Nr<   )r1  zmyapp/right_table.htmlrC  )ItemrA   rB   r   )r'   rC  s     r   update_dafatturare_tablerg    s5    ++!+44'36IK\5]^^^r   c                 |   | j         dk    r| j                            d          }| j                            d          }	 t          j                            |          }n# t
          $ r t          d          w xY w||_        |                                 t          ddi          S t          dd	id
          S )Nr[   	record_idnuovo_statora   r   rW  zStato aggiornato con successorX  zRichiesta non validarY  rR  )
rY   r[   rd   rD   rA   r   r   r   r   r   )r'   ri  rj  myprens       r   aggiorna_stato_prenrl    s    ~L$$[11	l&&}55	0!)---;;FF! 	0 	0 	0.///	0 &Y(GHIIIW&<=cJJJJs    A" "A<)Kdjango.formsr   django.shortcutsr   r   rest_frameworkr   r   modelscodfis_formserializers	django.dbr
   django.db.modelsr   r   datetimer   django.httpr   r   r   r   django.core.exceptionsr   formsdjango.confr   django.contrib.authr   django.utilsr   django.contrib.auth.decoratorsr   r   r   r   r   r*   rO   r_   rh   rn   r~   r   r   r   r   r   r   r   r   r   r   r  r  ModelViewSetr  r  r  r(  r,  r/  r5  r:  ListAPIViewr=  rH  rJ  rN  rU  r[  rd  rg  rl  r?   r   r   <module>r     s   " " " " " " 5 5 5 5 5 5 5 5 , , , , , , , ,             ! ! ! ! ! ! % % % % % % % %       Q Q Q Q Q Q Q Q Q Q Q Q 5 5 5 5 5 5                 , , , , , , - - - - - - - - ! ! ! ! ! ! $ $ $ $ $ $ K K K K K K K K  				  X X X$$4 $4 $4NA A A25 5 5 (< <  << (; ;  ;09> 9> 9>v (7> 7>  7>rX X X,W W W,2< 2< 2<h4: 4: 4:lT T T  (.9 .9  .9` > > >8  >"= "= "=H ( ?  ?   ?D* * * * *h+ * * *( ( ( ( (H) ( ( (
a 
a 
a 
a 
aX2 
a 
a 
a| | | | |(/ | | |	u 	u 	u 	u 	u80 	u 	u 	u6 6 6 6 6 5 6 6 62m m m m mX2 m m m	R 	R 	R 	R 	R- 	R 	R 	R
a 
a 
a 
a 
ax+ 
a 
a 
a @ @ @,? ? ? < < <@ e e e $L $L $LL ,> ,> ,>\_ _ _K K K K Kr   