Сумма запроса POSTGRES - PullRequest
0 голосов
/ 04 апреля 2020

Я пытаюсь получить СУММУ КОЛИЧЕСТВА AMOUNTEUR. Ожидаю сумму -62,63 и 34,43. Мне нужно добавить множество комментариев, чтобы поблагодарить меня за вашу помощь. Я пытаюсь экспортировать журнал счетов-фактур для экспорта в совместимый формат winbooks. Если у вас есть какой-то опыт

SELECT 
            CASE 
                WHEN account_account.code LIKE '40%%'
                    THEN 1
                WHEN account_account.code LIKE '44%%'
                    THEN 2
                ELSE 3
            END as DOCTYPE,
            CASE
                WHEN (account_account.code LIKE '40%%' or account_account.code LIKE '451%%' or account_account.code LIKE '70%%') and account_move.name like 'FAC%%'
                    THEN 'VENTES'
                WHEN (account_account.code LIKE '40%%' or account_account.code LIKE '451%%' or account_account.code LIKE '70%%') and account_move.name like 'NC%%'
                    THEN 'NCVEN'
            END as DBKCODE,
            '' as DBKTYPE,
            CASE 
                WHEN (account_move.name LIKE 'FAC%%')
                    THEN REPLACE(SUBSTR(account_move.name, 5, 11), '/' ,'') 
                WHEN (account_move.name LIKE 'NC%%')
                    THEN REPLACE(SUBSTR(account_move.name, 4, 11), '/' ,'')
            END as DOCNUMBER,   
            '' as DOCORDER,
            '' as OPCODE,
            CASE 
                WHEN account_account.code LIKE '40%%'
                    THEN '400000'
                WHEN account_account.code LIKE '44%%'
                    THEN '440000'
                ELSE account_account.code    
            END as ACCOUNTGL,
                        CASE
                WHEN account_move_line.partner_id IS null 
                    THEN '400751'
                ELSE res_partner.ref
            END as ACCOUNTRP,
            '' as BOOKYEAR,
            '' as PERIOD,
            '' as DATE,
            To_CHAR(account_move.date, 'YYYYMMDD') as DATEDOC,
            '' as DUEDATE,
            CASE
            WHEN account_account.code LIKE '40%%'
                    THEN SUBSTRING(account_move_line.name , 1, 40)
            WHEN account_account.code LIKE '44%%'
                    THEN SUBSTRING(account_move_line.name , 1, 40)
            WHEN account_account.code LIKE '701%%'
                    THEN ''
            ELSE SUBSTRING(account_move_line.name , 1, 40)
            END as COMMENT,
            CASE 
            WHEN account_account.code = '701000'
                    THEN '' 
            END as COMMENTEXT,
            '' as AMOUNT,
            CASE
            WHEN account_account.code = '701000'
                THEN SUM(round(balance, 2))
            ELSE (round(balance, 2))
            END as AMOUNTEUR,
            CASE 
                WHEN account_account.code LIKE '40%%' or account_account.code LIKE '44%%'
                    THEN round(account_move.amount / 1.21, 2)
                WHEN account_account.code LIKE '451%%' or account_account.code LIKE '411%%'
                    THEN round(account_move.amount / 1.21, 2)
            END as VATBASE,
            CASE
                WHEN account_account.code LIKE '451%%'
                    THEN round(account_tax.amount)
                WHEN account_account.code LIKE '411%%'
                    THEN round(account_tax.amount)
            END as VATCODE,
            '' as CURRAMOUNT,
            '' as CURRCODE,
            '' as CUREURBASE,
            '' as VATTAX,
            '' as VATIMPUT,
            '' as CURRATE,
            '' as REMINDLEV,
            account_full_reconcile.name as MATCHNO
        FROM public.account_move_line
        JOIN account_move ON (account_move.id = account_move_line.move_id)
        JOIN account_account ON (account_account.id = account_move_line.account_id)
        LEFT JOIN account_full_reconcile ON (account_full_reconcile.id = account_move_line.full_reconcile_id)
        LEFT JOIN account_tax ON (account_tax.id = account_move_line.tax_line_id)
        LEFT JOIN res_partner ON (res_partner.id = account_move_line.partner_id)
        WHERE (account_move.name LIKE 'FAC%%' or account_move.name LIKE 'NC%%' )
        AND (account_move.date BETWEEN '2020-03-01' AND '2020-03-31') GROUP BY account_move_line.invoice_id,account_move_line.balance,account_account.code,account_move.name,account_move_line.partner_id,res_partner.ref,account_move.date,account_move_line.name,account_move.amount,account_tax.amount,account_full_reconcile.name order by account_move_line.invoice_id;

захват результатов

Мне нужно добавить много комментариев, дайте мне знать спасибо за вашу помощь. затем я пытаюсь экспортировать журнал счетов-фактур для экспорта в совместимый формат winbooks. Если у вас есть какой-то опыт

...