§
    Ób•jQ
  ã                   óP   — d dl mZ d dlmZ d dlmZ d dlmZ  G d„ d¦  «        ZdS )é    )ÚUUID)ÚOptional)ÚInvoice)ÚDecimalc                   óJ   — e Zd ZdZd„ Zd„ Zdeddfd„Zdede	e         fd	„Z
dS )
ÚInvoiceRepositoryui   
    Káº¿t ná»‘i Domain Entity Invoice xuá»‘ng báº£ng PostgreSQL.
    Sá»­ dá»¥ng schema 'invoices'.
    c                 ó   — || _         d S )N)Ú_conn)ÚselfÚconns     úFC:\Projects\DSCons\app\modules\invoices\infrastructure\repositories.pyÚ__init__zInvoiceRepository.__init__   s   € ØˆŒ
ˆ
ˆ
ó    c                 ó”   — | j                              ¦   «         5 }|                     d¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )Na²  
                CREATE SCHEMA IF NOT EXISTS invoices;
                CREATE TABLE IF NOT EXISTS invoices.invoices (
                    id UUID PRIMARY KEY,
                    invoice_no TEXT NOT NULL,
                    supplier_tax_code TEXT NOT NULL,
                    total_amount NUMERIC(18, 4) NOT NULL,
                    tax_amount NUMERIC(18, 4) NOT NULL,
                    issue_date DATE NOT NULL,
                    status TEXT NOT NULL,
                    project_id UUID,
                    created_at TIMESTAMP WITH TIME ZONE
                );
                CREATE INDEX IF NOT EXISTS idx_invoices_tax_code ON invoices.invoices(supplier_tax_code);
            )r
   ÚcursorÚexecute)r   Úcurs     r   Úensure_schemazInvoiceRepository.ensure_schema   s’   € ØŒZ×ÒÑ Ô ð 	 CØ�KŠKð ñ ô ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   š=½AÁAÚinvoiceÚreturnNc                 óp  — |                       ¦   «          | j                             ¦   «         5 }|                     dt	          |j        ¦  «        |j        |j        |j        |j	        |j
        |j        |j        rt	          |j        ¦  «        nd |j        f	¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )Na¥  
                INSERT INTO invoices.invoices 
                (id, invoice_no, supplier_tax_code, total_amount, tax_amount, issue_date, status, project_id, created_at)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
                ON CONFLICT (id) DO UPDATE SET
                    invoice_no = EXCLUDED.invoice_no,
                    supplier_tax_code = EXCLUDED.supplier_tax_code,
                    total_amount = EXCLUDED.total_amount,
                    tax_amount = EXCLUDED.tax_amount,
                    issue_date = EXCLUDED.issue_date,
                    status = EXCLUDED.status,
                    project_id = EXCLUDED.project_id;
            )r   r
   r   r   ÚstrÚidÚ
invoice_noÚsupplier_tax_codeÚtotal_amountÚ
tax_amountÚ
issue_dateÚstatusÚ
project_idÚ
created_at)r   r   r   s      r   ÚsavezInvoiceRepository.save    sú   € Ø×ÒÑÔÐØŒZ×ÒÑ Ô ð 	 CØ�KŠKð õ �G”J‘”ØÔ"ØÔ)ØÔ$ØÔ"ØÔ"Ø”Ø+2Ô+=ÐG•�GÔ&Ñ'Ô'Ð'À4ØÔ"ð
ñô ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   ®A0B+Â+B/Â2B/Ú
invoice_idc                 ó  — | j                              ¦   «         5 }|                     dt          |¦  «        f¦  «         |                     ¦   «         }|rt          di |¤Žcd d d ¦  «         S 	 d d d ¦  «         n# 1 swxY w Y   d S )Nz-SELECT * FROM invoices.invoices WHERE id = %s© )r
   r   r   r   Úfetchoner   )r   r#   r   Úrows       r   Ú	get_by_idzInvoiceRepository.get_by_id;   sÜ   € ØŒZ×ÒÑ Ô ð 	& CØ�KŠKÐGÍ#ÈjÉ/Ì/ÐI[Ñ\Ô\Ð\Ø—,’,‘.”.ˆCØð &Ý�~�~ �~�~ð		&ð 	&ð 	&ð 	&ñ 	&ô 	&ð 	&ð 	&ð&ð	&ð 	&ð 	&ñ 	&ô 	&ð 	&ð 	&ð 	&ð 	&ð 	&ð 	&øøøð 	&ð 	&ð 	&ð 	&ð
 ˆts   šAA:Á:A>ÂA>)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r   r   r(   r%   r   r   r   r      s…   € € € € € ðð ðð ð ðð ð ð$˜Gð ¨ð ð ð ð ð6 Dð ¨X°gÔ->ð ð ð ð ð ð r   r   N)	Úuuidr   Útypingr   Ú$app.modules.invoices.domain.entitiesr   Údecimalr   r   r%   r   r   ú<module>r1      s   ðØ Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø Ð Ð Ð Ð Ð ð;ð ;ð ;ð ;ð ;ñ ;ô ;ð ;ð ;ð ;r   