Ë
    Ã?Æi
$  ã                  ó‚   — d Z ddlmZ ddl­ ddlmZmZ dd„ZdZdZ	dd„Z
dd	„Zdd
„Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zy)uE  NCF (NÃºmeros de Comprobante Fiscal, Dominican Republic receipt number).

The NCF is used to number invoices and other documents for the purpose of tax
filing. The e-CF (Comprobante Fiscal ElectrÃ³nico) is used together with a
digital certificate for the same purpose. The number is either 19, 11 or 13
(e-CF) digits long.

The 19 digit number starts with a letter (A or P) to indicate that the number
was assigned by the taxpayer or the DGII, followed a 2-digit business unit
number, a 3-digit location number, a 3-digit mechanism identifier, a 2-digit
document type and a 8-digit serial number.

The 11 digit number always starts with a B followed a 2-digit document type
and a 7-digit serial number.

The 13 digit e-CF starts with an E followed a 2-digit document type and an
8-digit serial number.

More information:

 * https://www.dgii.gov.do/
 * https://dgii.gov.do/workshopProveedoresTI-eCE/Documents/Norma05-19.pdf
 * https://dgii.gov.do/cicloContribuyente/facturacion/comprobantesFiscales/Paginas/tiposComprobantes.aspx

>>> validate('E310000000005')  # format since 2019-04-08
'E310000000005'
>>> validate('B0100000005')  # format since 2018-05-01
'B0100000005'
>>> validate('A020010210100000005')  # format before 2018-05-01
'A020010210100000005'
>>> validate('Z0100000005')
Traceback (most recent call last):
    ...
InvalidFormat: ...
é    )Úannotations)Ú*)ÚcleanÚisdigitsc                óR   — t        | d«      j                  «       j                  «       S )zˆConvert the number to the minimal representation. This strips the
    number of any valid separators and removes surrounding whitespace.ú )r   ÚstripÚupper©Únumbers    úT/var/www/html/myprovider/mon_projet_qr/lib/python3.12/site-packages/stdnum/do/ncf.pyÚcompactr   A   s#   € ô �˜Ó×#Ñ#Ó%×+Ñ+Ó-Ð-ó    )Ú01Ú02Ú03Ú04Ú11Ú12Ú13Ú14Ú15Ú16Ú17)
Ú31Ú32Ú33Ú34Ú41Ú43Ú44Ú45Ú46Ú47c                óÈ  — t        | «      } t        | «      dk(  r7| d   dk7  st        | dd «      s
t        «       ‚| dd t        vr
t        «       ‚| S t        | «      dk(  r7| d   dk7  st        | dd «      s
t        «       ‚| dd t        vr
t        «       ‚| S t        | «      d	k(  r6| d   d
vst        | dd «      s
t        «       ‚| dd t        vr
t        «       ‚| S t        «       ‚)ú,Check if the number provided is a valid NCF.é   r   ÚEé   Né   é   ÚBé   ÚAPé	   )r   Úlenr   ÚInvalidFormatÚ_ecf_document_typesÚInvalidComponentÚ_ncf_document_typesÚInvalidLengthr   s    r   Úvalidater6   d   sý   € ä�V‹_€FÜ
ˆ6ƒ{�bÒØ�!‰9˜Ò¤8¨F°1°2¨JÔ#7Ü“/Ð!Ø�!�Aˆ;Ô1Ñ1Ü"Ó$Ð$ð €Mô 
ˆV‹˜Ò	Ø�!‰9˜Ò¤8¨F°1°2¨JÔ#7Ü“/Ð!Ø�!�Aˆ;Ô1Ñ1Ü"Ó$Ð$ð €Mô 
ˆV‹˜Ò	Ø�!‰9˜DÑ ¬°¸¸°Ô(<Ü“/Ð!Ø�!�Bˆ<Ô2Ñ2Ü"Ó$Ð$ð €Mô ‹oÐr   c                óJ   — 	 t        t        | «      «      S # t        $ r Y yw xY w)r&   F)Úboolr6   ÚValidationErrorr   s    r   Úis_validr:   {   s)   € ðÜ”H˜VÓ$Ó%Ð%øÜò Ùðús   ‚ –	"¡"c                óÂ   ‡— i dd“dd“dd“dd“d	d
“dd“dd
“dd
“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd d d!dd"œ¥Št        ˆfd#„| j                  «       D «       «      S )$z0Translate SOAP result entries into dictionaries.ÚNOMBREÚnameÚCOMPROBANTEÚproofÚ	ES_VALIDOr:   ÚMENSAJE_VALIDACIONÚvalidation_messageÚRNCÚrncÚNCFÚncfu   RNC / CÃ©dulau   RNC/CÃ©dulau   Nombre / RazÃ³n Socialu   Nombre/RazÃ³n SocialÚEstadoÚstatuszTipo de comprobanteÚtypeu   VÃ¡lido hastaÚvalid_untilu   CÃ³digo de SeguridadÚsecurity_codez
Rnc EmisorÚissuing_rnczRnc CompradorÚ	buyer_rnczMonto TotalÚtotalÚtotal_itbisÚissuing_dateÚsignature_date)zTotal de ITBISzFecha Emisi&oacutenu   Fecha EmisiÃ³nzFecha de Firmaze-NCFc              3  óL   •K  — | ]  \  }}‰j                  ||«      |f–— Œ y ­w)N)Úget)Ú.0ÚkeyÚvalueÚtranslations      €r   ú	<genexpr>z"_convert_result.<locals>.<genexpr>�   s-   øè ø€ ò *áˆC�ð 
�‰˜˜cÓ	" EÔ*ñ*ùs   ƒ!$)ÚdictÚitems)ÚresultrW   s    @r   Ú_convert_resultr\   ƒ   s  ø€ ðØ�&ðà�wðð 	�Zðð 	Ð2ð	ð
 	ˆuðð 	ˆuðð 	˜ðð 	�uðð 	! &ðð 	 ðð 	�(ðð 	˜vðð 	˜ðð 	 ðð 	�mðð  	˜ð!ð" 	�wð#ð$ (Ø-Ø(Ø*Øò-€Kô0 ó *à Ÿ,™,›.ô*ó *ð *r   Nc           
     óT  — ddl }ddl}ddlm}  || «      } t        |«      }|r ||«      }d}	|j	                  «       }
||
_        |
j                  j                  ddi«       |j                  j                  |
j                  |	|¬«      j                  «      }|j                  d«      j                  d	«      }|j                  d
«      j                  d	«      }||d|| dœ}|d   dk(  r
||d<   ||d<   |j                  j                  |
j                  |	||¬«      j                  «      }|d   dk(  rdnd}|j                  |«      }|�×|d   dk(  rdnd}d|j                  |«      j                  «       i}|j                  t!        |j#                  d«      D �cg c])  }|j                  sŒ|j                  j                  «       ‘Œ+ c}|j#                  d«      D �cg c])  }|j                  sŒ|j                  j                  «       ‘Œ+ c}«      «       t%        |«      S yc c}w c c}w )u�  Validate the RNC, NCF combination on using the DGII online web service.

    This uses the validation service run by the the DirecciÃ³n General de
    Impuestos Internos, the Dominican Republic tax department to check
    whether the combination of RNC and NCF is valid. The timeout is in
    seconds.

    The `timeout` argument specifies the network timeout in seconds.

    The `verify` argument is either a boolean that determines whether the
    server's certificate is validate or a string which must be a path the CA
    certificate bundle to use for verification.

    Returns a dict with the following structure for a NCF::

        {
            'name': 'The registered name',
            'status': 'VIGENTE',
            'type': 'FACTURAS DE CREDITO FISCAL',
            'rnc': '123456789',
            'ncf': 'A020010210100000005',
            'validation_message': 'El NCF digitado es vÃ¡lido.',
        }

    For an ECNF::

        {
            'status': 'Aceptado',
            'issuing_rnc': '1234567890123',
            'buyer_rnc': '123456789',
            'ncf': 'E300000000000',
            'security_code': '1+2kP3',
            'issuing_date': '2020-03-25',
            'signature_date': '2020-03-22',
            'total': '2203.50',
            'total_itbis': '305.10',
            'validation_message': 'Aceptado',
        }

    Will return None if the number is invalid or unknown.r   N)r   zMhttps://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/ncf.aspxz
User-AgentzMozilla/5.0 (python-stdnum))Útimeoutz#.//input[@name="__EVENTVALIDATION"]rV   z.//input[@name="__VIEWSTATE"]ÚBuscar)Ú__EVENTVALIDATIONÚ__VIEWSTATEzctl00$cphMain$btnConsultarzctl00$cphMain$txtNCFzctl00$cphMain$txtRNCr(   zctl00$cphMain$txtRncCompradorzctl00$cphMain$txtCodigoSeg)Údatar^   z".//div[@id="cphMain_PResultadoFE"]z .//div[@id="cphMain_pResultado"]z.//*[@id="cphMain_lblEstadoFe"]z".//*[@id="cphMain_lblInformacion"]rB   z.//thz
.//td/span)Ú	lxml.htmlÚrequestsÚstdnum.do.rncr   ÚSessionÚverifyÚheadersÚupdateÚhtmlÚ
fromstringrS   ÚtextÚfindÚpostÚfindtextr	   ÚzipÚfindallr\   )rD   rF   rM   rK   r^   rg   Úlxmlrd   Úrnc_compactÚurlÚsessionÚdocumentÚ
validationÚ	viewstaterb   Úresult_pathr[   Úlbl_pathÚxs                      r   Ú
check_dgiir|   ¢   s  € ó` ÛÝ4Ù
�cÓ
€CÜ
�#‹,€CÙÙ 	Ó*ˆ	Ø
Y€CØ×ÑÓ €GØ€G„NØ‡O�O×ÑØÐ3ðô ð �y‰y×#Ñ#Ø�‰�C ˆÓ)×.Ñ.ó0€Hà—‘ÐDÓE×IÑIÈ'ÓR€JØ—‘Ð=Ó>×BÑBÀ7ÓK€Ià'Ø Ø&.Ø #Ø #ñ€Dð ˆ1�v�‚}Ø09ˆÐ,Ñ-Ø-:ˆÐ)Ñ*à�y‰y×#Ñ#Ø�‰�S˜t¨WˆÓ5×:Ñ:ó<€Hà:=¸a¹&ÀCº-Ñ6ÐMo€KØ�]‰]˜;Ó'€FØÐØ8;¸A¹À#ºÑ4ÐKoˆà  (×"3Ñ"3°HÓ"=×"CÑ"CÓ"Eð
ˆð 	�‰”CØ%+§^¡^°GÓ%<ÖG ÀÇÃˆQ�V‰V�\‰\�^ÒGØ%+§^¡^°LÓ%AÖL ÀQÇVÃVˆQ�V‰V�\‰\�^ÒLóNô 	Oô ˜tÓ$Ð$Øùò HùÚLs   ÆH Æ*H ÇH%Ç-H%)r   ÚstrÚreturnr}   )r   r}   r~   r8   )r[   údict[str, str]r~   r   )NNé   T)rD   r}   rF   r}   rM   ú
str | NonerK   r�   r^   Úfloatrg   z
bool | strr~   zdict[str, str] | None)Ú__doc__Ú
__future__r   Ústdnum.exceptionsÚstdnum.utilr   r   r   r4   r2   r6   r:   r\   r|   © r   r   ú<module>rˆ      s˜   ðñ."õH #ä ß 'ó.ðÐ ðÐ óó.ó*ðD !Ø $ØØðZØ	ðZà	ðZð ðZð ð	Zð
 ðZð ðZð ôZr   