Difference between revisions of "Accounting exports 4"

Jump to: navigation, search
(Carry forwards)
(User account balance)
(17 intermediate revisions by the same user not shown)
Line 77: Line 77:
 
<sql>SELECT  
 
<sql>SELECT  
 
     CASE
 
     CASE
         WHEN account.category=1 THEN '_tr(OTHER_ACCOUNT)'
+
         WHEN account.category=1 THEN _tr(OTHER_ACCOUNT)
         WHEN account_type.name IS NOT NULL AND (account.category=2) THEN CONCAT('_tr(MEMBER_ACCOUNT)', ' - ', account_type.name)
+
         WHEN account_type.name IS NOT NULL AND (account.category=2) THEN CONCAT(_tr(MEMBER_ACCOUNT), ' - ', account_type.name)
         WHEN account_type.name IS NOT NULL AND (account.category=3) THEN CONCAT('_tr(RESOURCE_ACCOUNT)', ' - ', account_type.name)
+
         WHEN account_type.name IS NOT NULL AND (account.category=3) THEN CONCAT(_tr(RESOURCE_ACCOUNT), ' - ', account_type.name)
         WHEN account.category=4 THEN '_tr(SUPPLIER_ACCOUNT)'
+
         WHEN account.category=4 THEN _tr(SUPPLIER_ACCOUNT)
         WHEN account.category=6 THEN '_tr(ACCOUNT_VAT_ACCOUNT)'
+
         WHEN account.category=6 THEN _tr(ACCOUNT_VAT_ACCOUNT)
         WHEN account.category=7 THEN '_tr(ACCOUNT_EXPENSE_ACCOUNT)'
+
         WHEN account.category=7 THEN _tr(ACCOUNT_EXPENSE_ACCOUNT)
         WHEN account.category=8 THEN '_tr(TREASURY_ACCOUNT)'
+
         WHEN account.category=8 THEN _tr(TREASURY_ACCOUNT)
         WHEN account.category=9 THEN '_tr(PRODUCT_ACCOUNT)'
+
         WHEN account.category=9 THEN _tr(PRODUCT_ACCOUNT)
         WHEN account.category=10 THEN '_tr(BALANCE_SHEET_ACCOUNT)'
+
         WHEN account.category=10 THEN _tr(BALANCE_SHEET_ACCOUNT)
         WHEN account.category=11 THEN '_tr(CUSTOMER_ACCOUNT)'
+
         WHEN account.category=11 THEN _tr(CUSTOMER_ACCOUNT)
 
         ELSE account.name
 
         ELSE account.name
     END AS '_tr(ACCOUNT_TYPE)',
+
     END AS _tr(ACCOUNT_TYPE),
     IFNULL(SUM( sumAccountEntry(account.id,NOW())),0) AS '_tr(ACCOUNT_BALANCE)'
+
     IFNULL(SUM( sumAccountEntry(account.id,NOW())),0) AS _tr(ACCOUNT_BALANCE)
 
FROM account
 
FROM account
 
LEFT JOIN accounting ON accounting.id=account.accounting_id  
 
LEFT JOIN accounting ON accounting.id=account.accounting_id  
Line 96: Line 96:
 
LEFT JOIN resource ON (account.owner_id = resource.id AND account.category=3)
 
LEFT JOIN resource ON (account.owner_id = resource.id AND account.category=3)
 
WHERE account.activated = 1
 
WHERE account.activated = 1
   AND accounting.id='$accountingId'
+
   AND accounting.id=$accountingId
 
   AND (
 
   AND (
 
       (person.id IS NULL AND resource.id IS NULL)
 
       (person.id IS NULL AND resource.id IS NULL)
Line 121: Line 121:
 
* Variable '''$startDate''' should be defined first and should be of '''Date and time''' value type
 
* Variable '''$startDate''' should be defined first and should be of '''Date and time''' value type
  
<sql>SELECT customer_bill_entry.bill_date AS '_tr(DATE)', CONCAT( '[LINK=index.php&#63;menuAction=download_customer_bill&menuParameter=', customer_bill_entry.flow_id, ']', customer_bill_entry.customer_bill_id, '[/LINK]' ) AS '_tr(BILL)'
+
<sql>SELECT customer_bill_entry.bill_date AS _tr(DATE), CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=download_customer_bill&menuParameter=', customer_bill_entry.flow_id, ']', customer_bill_entry.customer_bill_id, '[/LINK]' ) AS _tr(BILL)
 
FROM customer_bill_entry
 
FROM customer_bill_entry
WHERE customer_bill_entry.bill_date >= '$startDate' AND customer_bill_entry.bill_date < '$endDate'
+
WHERE customer_bill_entry.bill_date >= $startDate AND customer_bill_entry.bill_date < $endDate
 
GROUP BY customer_bill_entry.customer_bill_id
 
GROUP BY customer_bill_entry.customer_bill_id
 
ORDER BY customer_bill_entry.customer_bill_id</sql>
 
ORDER BY customer_bill_entry.customer_bill_id</sql>
Line 132: Line 132:
 
* Variable '''$year''' should be defined first and should be of '''Year''' value type.
 
* Variable '''$year''' should be defined first and should be of '''Year''' value type.
  
<sql>SELECT account.name AS '_tr(CUSTOMER)', resource_type.name AS '_tr(RESOURCE)', product.label AS '_tr(PRODUCT)', SUM(customer_bill_entry.qty) AS '_tr(QUANTITY)', SUM(customer_bill_entry.debit) AS '_tr(AMOUNT)'
+
<sql>SELECT account.name AS _tr(CUSTOMER), resource_type.name AS _tr(RESOURCE), product.label AS _tr(PRODUCT), SUM(customer_bill_entry.qty) AS _tr(QUANTITY), SUM(customer_bill_entry.debit) AS _tr(AMOUNT)
 
FROM customer_bill_entry
 
FROM customer_bill_entry
 
LEFT JOIN account_entry ON (account_entry.flow_id=customer_bill_entry.account_entry_flow_id AND account_entry.id=customer_bill_entry.account_entry_id)
 
LEFT JOIN account_entry ON (account_entry.flow_id=customer_bill_entry.account_entry_flow_id AND account_entry.id=customer_bill_entry.account_entry_id)
Line 143: Line 143:
 
LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id)
 
LEFT JOIN resource_type ON (resource_type.id=resource.resource_type_id)
 
WHERE account.category = 2
 
WHERE account.category = 2
   AND accounting.id = '$accountingId'
+
   AND accounting.id = $accountingId
   AND YEAR(account_entry.account_date) = '$year'
+
   AND YEAR(account_entry.account_date) = $year
   AND MONTH(account_entry.account_date) = '$month'
+
   AND MONTH(account_entry.account_date) = $month
 
GROUP BY account.id, resource_type.id, product.id
 
GROUP BY account.id, resource_type.id, product.id
 
ORDER BY account.name</sql>
 
ORDER BY account.name</sql>
Line 176: Line 176:
  
 
<sql>SELECT
 
<sql>SELECT
     CONCAT(last_name, ' ', first_name) AS '_tr(FULL_NAME)',
+
     CONCAT(last_name, ' ', first_name) AS _tr(FULL_NAME),
     validity_type.name AS '_tr(VALIDITY)',
+
     validity_type.name AS _tr(VALIDITY),
     grant_date AS '_tr(VALIDITY_GRANT_DATE)',
+
     grant_date AS _tr(VALIDITY_GRANT_DATE),
 
     IFNULL((
 
     IFNULL((
 
         SELECT SUM(account_entry.credit) - SUM(account_entry.debit)
 
         SELECT SUM(account_entry.credit) - SUM(account_entry.debit)
Line 204: Line 204:
 
WHERE grant_date < DATE_SUB(NOW(), INTERVAL 2 YEAR)
 
WHERE grant_date < DATE_SUB(NOW(), INTERVAL 2 YEAR)
 
   AND ( validity_type.id IN ($validityTypeId) OR '-' IN ($validityTypeId) )
 
   AND ( validity_type.id IN ($validityTypeId) OR '-' IN ($validityTypeId) )
   AND CAST(accounting.id AS CHAR) ='$accountingId'
+
   AND CAST(accounting.id AS CHAR) =$accountingId
 
   AND account.activated = 1
 
   AND account.activated = 1
 
   AND person.activated = 1
 
   AND person.activated = 1
Line 216: Line 216:
 
*Variable '''$accountingId''' should be defined first and should be of '''dbObject::Accounting''' value type.
 
*Variable '''$accountingId''' should be defined first and should be of '''dbObject::Accounting''' value type.
  
<sql>SELECT CONCAT( '[LINK=index.php&#63;menuAction=account_journal&menuParameter=', tmp_accounts.id, ']', tmp_accounts.id, '[/LINK]' ) AS '_tr(ID)', tmp_accounts.export_account AS '_tr(ACCOUNT_EXPORT)', tmp_accounts.name AS '_tr(ACCOUNT)',
+
<sql>SELECT CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=account_journal&menuParameter=', tmp_accounts.id, ']', tmp_accounts.id, '[/LINK]' ) AS _tr(ID), tmp_accounts.export_account AS _tr(ACCOUNT_EXPORT), tmp_accounts.name AS _tr(ACCOUNT),
tmp_accounts.balance AS '_tr(ACCOUNT_BALANCE)' FROM (
+
tmp_accounts.balance AS _tr(ACCOUNT_BALANCE) FROM (
 
     SELECT account.id, export_account, account.name,
 
     SELECT account.id, export_account, account.name,
     IFNULL(sumAccountEntry(account.id,'$endDate'), 0) AS balance
+
     IFNULL(sumAccountEntry(account.id,$endDate), 0) AS balance
 
     FROM account
 
     FROM account
 
     LEFT JOIN accounting ON accounting.id=account.accounting_id  
 
     LEFT JOIN accounting ON accounting.id=account.accounting_id  
 
     LEFT JOIN person ON (person.id=account.owner_id AND account.category=2)
 
     LEFT JOIN person ON (person.id=account.owner_id AND account.category=2)
 
     LEFT JOIN resource ON (resource.id=account.owner_id AND account.category=3)
 
     LEFT JOIN resource ON (resource.id=account.owner_id AND account.category=3)
     WHERE (account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$endDate') )
+
     WHERE (account.activated=1 OR (account.activated=0 AND account.deactivated_date >= $endDate) )
     AND accounting.id='$accountingId'
+
     AND accounting.id=$accountingId
 
     HAVING balance NOT IN ('0', '0.00', '0,00')
 
     HAVING balance NOT IN ('0', '0.00', '0,00')
 
     ORDER BY export_account
 
     ORDER BY export_account
Line 249: Line 249:
 
         ELSE account.name
 
         ELSE account.name
 
     END AS account_name,
 
     END AS account_name,
     IF( (@sumAccountEntry := sumAccountEntry(account.id,'$endDate')) < 0, @sumAccountEntry, 0 )  AS Debit,
+
     IF( (@sumAccountEntry := sumAccountEntry(account.id,$endDate)) < 0, @sumAccountEntry, 0 )  AS Debit,
 
     IF( @sumAccountEntry < 0, 0, @sumAccountEntry ) AS Credit
 
     IF( @sumAccountEntry < 0, 0, @sumAccountEntry ) AS Credit
 
FROM account
 
FROM account
Line 256: Line 256:
 
LEFT JOIN person ON (account.owner_id = person.id AND account.category=2)
 
LEFT JOIN person ON (account.owner_id = person.id AND account.category=2)
 
LEFT JOIN resource ON (account.owner_id = resource.id AND account.category=3)
 
LEFT JOIN resource ON (account.owner_id = resource.id AND account.category=3)
WHERE accounting.id='$accountingId'
+
WHERE accounting.id=$accountingId
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$endDate') )
+
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= $endDate) )
 
GROUP BY account.id  
 
GROUP BY account.id  
 
ORDER BY account.export_account ASC</sql>
 
ORDER BY account.export_account ASC</sql>
Line 307: Line 307:
 
LEFT JOIN accounting ON accounting.id=account.accounting_id
 
LEFT JOIN accounting ON accounting.id=account.accounting_id
 
LEFT JOIN account_entry ON (account.id=account_entry.account_id)
 
LEFT JOIN account_entry ON (account.id=account_entry.account_id)
WHERE accounting.id='$accountingId'
+
WHERE accounting.id=$accountingId
   AND account_entry.account_date >= '$startDate' AND account_entry.account_date < '$endDate'
+
   AND account_entry.account_date >= $startDate AND account_entry.account_date < $endDate
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$startDate') )
+
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= $startDate) )
 
GROUP BY account.id
 
GROUP BY account.id
 
UNION
 
UNION
Line 316: Line 316:
 
LEFT JOIN accounting ON accounting.id=account.accounting_id
 
LEFT JOIN accounting ON accounting.id=account.accounting_id
 
LEFT JOIN account_entry ON (account.id=account_entry.account_id)
 
LEFT JOIN account_entry ON (account.id=account_entry.account_id)
WHERE accounting.id='$accountingId'
+
WHERE accounting.id=$accountingId
   AND account_entry.account_date >= '$startDate' AND account_entry.account_date < '$endDate'
+
   AND account_entry.account_date >= $startDate AND account_entry.account_date < $endDate
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$startDate') )
+
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= $startDate) )
 
ORDER BY 2, 3</sql>
 
ORDER BY 2, 3</sql>
  
Line 334: Line 334:
 
<sql>SELECT psp_transaction.transaction_date, account.name, psp_transaction.amount, psp_transaction.state FROM psp_transaction
 
<sql>SELECT psp_transaction.transaction_date, account.name, psp_transaction.amount, psp_transaction.state FROM psp_transaction
 
LEFT JOIN account ON account.id=psp_transaction.credit_account_id
 
LEFT JOIN account ON account.id=psp_transaction.credit_account_id
WHERE psp_transaction.transaction_date >= "$startDate" AND psp_transaction.transaction_date<="$endDate"
+
WHERE psp_transaction.transaction_date >= $startDate AND psp_transaction.transaction_date<=$endDate
 
ORDER BY psp_transaction.transaction_date DESC</sql>
 
ORDER BY psp_transaction.transaction_date DESC</sql>
  
Line 374: Line 374:
 
*Variable '''$paymentType''' should be defined first and should be of '''dbObject::PaymentType''' value type.
 
*Variable '''$paymentType''' should be defined first and should be of '''dbObject::PaymentType''' value type.
  
<sql>SELECT payment_type.name AS '_tr(ENCASHMENT_TYPE)',
+
<sql>SELECT payment_type.name AS _tr(ENCASHMENT_TYPE),
       IF(account.category = 2, CONCAT( person.last_name, ' ', person.first_name), account.name) AS '_tr(NAME)',  
+
       IF(account.category = 2, CONCAT( person.last_name, ' ', person.first_name), account.name) AS _tr(NAME),  
       DATE(account_entry.account_date) AS '_tr(DATE)',  
+
       DATE(account_entry.account_date) AS _tr(DATE),  
       account_entry.payment_description AS '_tr(DESCRIPTION)', account_entry.credit AS '_tr(AMOUNT)'
+
       account_entry.payment_description AS _tr(DESCRIPTION), account_entry.credit AS _tr(AMOUNT)
 
FROM account_entry
 
FROM account_entry
 
LEFT JOIN payment_type ON payment_type.id = account_entry.payment_type
 
LEFT JOIN payment_type ON payment_type.id = account_entry.payment_type
Line 384: Line 384:
 
WHERE
 
WHERE
 
     CASE
 
     CASE
         WHEN ('$paymentType'='') THEN account_entry.payment_type IS NOT NULL
+
         WHEN ($paymentType='') THEN account_entry.payment_type IS NOT NULL
         ELSE account_entry.payment_type='$paymentType'
+
         ELSE account_entry.payment_type=$paymentType
 
     END
 
     END
  AND credit > 0 AND account_entry.account_date >= '$startDate' AND account_entry.account_date  <= '$endDate'
+
  AND credit > 0 AND account_entry.account_date >= $startDate AND account_entry.account_date  <= $endDate
 
ORDER BY 1, 3, 2</sql>
 
ORDER BY 1, 3, 2</sql>
  
Line 597: Line 597:
  
 
<sql>SELECT
 
<sql>SELECT
     CONCAT( '[LINK=index.php&#63;menuAction=account_journal&menuParameter=', account.id, ']', account.id, '[/LINK]' ) AS '_tr(ID)',
+
     CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=account_journal&menuParameter=', account.id, ']', account.id, '[/LINK]' ) AS _tr(ID),
     CONCAT( personWithProfile.last_name, ' ', personWithProfile.first_name) AS '_tr(LAST_NAME)',
+
     CONCAT( personWithProfile.last_name, ' ', personWithProfile.first_name) AS _tr(LAST_NAME),
     personWithProfile.person_profile AS '_tr(PROFILE)',
+
     personWithProfile.person_profile AS _tr(PROFILE),
     account_type.name AS '_tr(ACCOUNT_TYPE)',
+
     account_type.name AS _tr(ACCOUNT_TYPE),
     IFNULL(sumAccountEntry(account.id,'$endDate'),0) AS '_tr(BALANCE)'
+
     IFNULL(sumAccountEntry(account.id,$endDate),0) AS _tr(BALANCE)
 
FROM account
 
FROM account
 
LEFT JOIN accounting ON accounting.id=account.accounting_id  
 
LEFT JOIN accounting ON accounting.id=account.accounting_id  
Line 613: Line 613:
 
) AS personWithProfile ON personWithProfile.id=account.owner_id  
 
) AS personWithProfile ON personWithProfile.id=account.owner_id  
 
WHERE account.category=2
 
WHERE account.category=2
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$endDate') )
+
   AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= $endDate) )
   AND CAST(accounting.id AS CHAR) = '$accountingId'
+
   AND CAST(accounting.id AS CHAR) = $accountingId
 
   AND personWithProfile.id IS NOT NULL
 
   AND personWithProfile.id IS NOT NULL
 
ORDER BY personWithProfile.last_name, personWithProfile.first_name</sql>
 
ORDER BY personWithProfile.last_name, personWithProfile.first_name</sql>
  
=Validated entries for an account between two dates=
+
=Validated only or all entries for an account between two dates=
  
 
*Variable '''$startDate''' should be defined first and should be of '''Date and time''' value type.
 
*Variable '''$startDate''' should be defined first and should be of '''Date and time''' value type.
Line 624: Line 624:
 
*Variable '''$accountId''' should be defined first and should be of '''dbObject::Account''' value type.
 
*Variable '''$accountId''' should be defined first and should be of '''dbObject::Account''' value type.
  
<sql>SELECT '' AS 'Date', '' AS 'Numero flux', '' AS 'Comptes affectés', CONCAT( 'Solde au ', $startDate ) AS 'Commentaires',
+
<sql>SELECT '' AS _tr(DATE), '' AS _tr(FLOW_NUMBER), '' AS _tr(AFFECTED_ACCOUNTS), CONCAT( _tr(TEXT_BALANCE), $startDate ) AS _tr(COMMENTS),
       IF( (@startBalance := sumValidatedAccountEntry($accountId, $startDate)) < 0, @startBalance, '' ) AS 'Débit',
+
       IF( (@startBalance := sumValidatedAccountEntry($accountId, $startDate)) < 0, @startBalance, '' ) AS _tr(DEBIT),
       IF( @startBalance >= 0, @startBalance, '' ) AS 'Crédit'
+
       IF( @startBalance >= 0, @startBalance, '' ) AS _tr(CREDIT)
 
UNION
 
UNION
 
SELECT account_entry.account_date, account_entry.flow_id,  
 
SELECT account_entry.account_date, account_entry.flow_id,  
Line 657: Line 657:
 
     WHERE account_entry.account_id=$accountId
 
     WHERE account_entry.account_id=$accountId
 
       AND account_entry.account_date>=$startDate AND account_entry.account_date<$endDate
 
       AND account_entry.account_date>=$startDate AND account_entry.account_date<$endDate
       AND account_entry.validated=1
+
       AND (account_entry.validated=1 OR $validatedOnly=0)
 
       AND account.id <> affected_account.id
 
       AND account.id <> affected_account.id
 
     GROUP BY account_entry.id
 
     GROUP BY account_entry.id
Line 671: Line 671:
 
GROUP BY account_entry.id
 
GROUP BY account_entry.id
 
UNION
 
UNION
SELECT '_', '', '', CONCAT( 'Solde au ', $endDate ),
+
SELECT '_', '', '', CONCAT( _tr(TEXT_BALANCE), $endDate ),
 
       IF( (@endBalance := sumValidatedAccountEntry($accountId, $endDate)) < 0, @endBalance, '' ),
 
       IF( (@endBalance := sumValidatedAccountEntry($accountId, $endDate)) < 0, @endBalance, '' ),
 
       IF( @endBalance >= 0, @endBalance, '' )
 
       IF( @endBalance >= 0, @endBalance, '' )
 
ORDER BY 1, 2</sql>
 
ORDER BY 1, 2</sql>

Revision as of 17:10, 18 January 2022

Introduction

This page lists SQL requests for OpenFlyers release 4 export about Accounting.

Balances of resource accounts

  • Variable $accountingId should be defined first and should be of dbObject::Accounting value type.
  • Variable $endDate should be defined first and should be of value type Date and time value type.
[OF_DYNAMIC_SQL]
SELECT IFNULL(CONCAT(
    'SELECT resource.name \'_tr(NAME)\',',
    GROUP_CONCAT(
        CONCAT(
            ' (SELECT sumAccountEntry(account.id, '$endDate') AS balance
               FROM account
               LEFT JOIN account_type ON (account.account_type=account_type.id)
               WHERE account_type.activated=1
                 AND account.category=3
                 AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$endDate') )
                 AND account.owner_id=resource.id
                 AND account.account_type=',
            account_type.id,
            ') AS \'',
            REPLACE(account_type.name, '\'', '\\\''),
            '\''
        )
    ),
    ', (SELECT SUM(sumAccountEntry(account.id, '$endDate')) AS balance
       FROM account
       LEFT JOIN account_type ON (account.account_type=account_type.id)
       WHERE account_type.activated=1
         AND account.category=3
         AND ( account.activated=1 OR (account.activated=0 AND account.deactivated_date >= '$endDate') )
         AND account.owner_id=resource.id
       GROUP BY account.owner_id
    ) AS \'_tr(TOTAL)\'
    FROM resource WHERE resource.physical=1 AND resource.activated=1 GROUP BY resource.id'
), 'SELECT \'\'')
FROM account_type
LEFT JOIN accounting ON accounting.id=account_type.accounting_id
WHERE account_type.category=3
  AND account_type.activated=1
  AND accounting.id=$accountingId

Carry forwards

  • Variable $accountingId should be defined first and should be of dbObject::Accounting value type.
SELECT
    IF (account.category = 2, CONCAT(person.last_name,'  
',IFNULL(person.first_name, ''),' (',account_type.name,')'),
    IF (account.category = 3,CONCAT(resource.name,'  
(',account_type.name,')'),account.name)) AS Nom,
    export_account AS Code_comptable,
    debit AS 'Debit',
    credit AS 'Credit'
FROM account
LEFT JOIN accounting ON accounting.id=account.accounting_id 
LEFT JOIN balance ON balance.account_id=account.id
LEFT JOIN person ON person.id=account.owner_id AND account.category = 2
LEFT JOIN resource ON resource.id=account.owner_id AND account.category = 3
LEFT JOIN account_type ON account_type.id=account.account_type
WHERE account.activated = 1
  AND balance.balance_date_id = (SELECT balance_date.id FROM balance_date ORDER BY balance_date.id DESC LIMIT 1)
  AND accounting.id=$accountingId
  AND (
      (person.id IS NULL AND resource.id IS NULL)
      OR
      (person.activated=1 AND account.category=2)
      OR
      (resource.activated=1 AND account.category=3)
  )
ORDER BY Nom ASC

Category account balance

  • Variable $accountingId should be defined first and should be of dbObject::Accounting value type.
SELECT 
    CASE
        WHEN account.category=1 THEN _tr(OTHER_ACCOUNT)
        WHEN account_type.name IS NOT NULL AND (account.category=2) THEN CONCAT(_tr(MEMBER_ACCOUNT), ' - ', account_type.name)
        WHEN account_type.name IS NOT NULL AND (account.category=3) THEN CONCAT(_tr(RESOURCE_ACCOUNT), ' - ', account_type.name)
        WHEN account.category=4 THEN _tr(SUPPLIER_ACCOUNT)
        WHEN account.category=6 THEN _tr(ACCOUNT_VAT_ACCOUNT)
        WHEN account.category=7 THEN _tr(ACCOUNT_EXPENSE_ACCOUNT)
        WHEN account.category=8 THEN _tr(TREASURY_ACCOUNT)
        WHEN account.category=9 THEN _tr(PRODUCT_ACCOUNT)
        WHEN account.category=10 THEN _tr(BALANCE_SHEET_ACCOUNT)
        WHEN account.category=11 THEN _tr(CUSTOMER_ACCOUNT)
        ELSE account.name
    END AS _tr(ACCOUNT_TYPE),
    IFNULL(SUM( sumAccountEntry(account.id,NOW())),0) AS _tr(ACCOUNT_BALANCE)
FROM account
LEFT JOIN accounting ON accounting.id=account.accounting_id 
LEFT JOIN account_type ON (account.account_type = account_type.id AND account.category IN(2,3))
LEFT JOIN person ON (account.owner_id = person.id AND account.category=2)
LEFT JOIN resource ON (account.owner_id = resource.id AND account.category=3)
WHERE account.activated = 1
  AND accounting.id=$accountingId
  AND (
      (person.id IS NULL AND resource.id IS NULL)
      OR
      (person.activated=1 AND account.category=2)
      OR
      (resource.activated=1 AND account.category=3)
  )
GROUP BY account.category

Cheque deposit slip

SELECT date_format(ae.registration_date, "%d/%m/%Y") as "date", a.name, formatDecimal(ae.credit) as montant, ae.payment_description as libelle, 
(SELECT a2.name FROM account_entry ae2 JOIN account a2 ON a2.id = ae2.account_id WHERE ae2.flow_id = ae.flow_id AND ae2.debit > 0 LIMIT 0,1) as compte_banque, ae.comments as commentaire
FROM account_entry ae
JOIN account a
  ON ae.account_id = a.id
WHERE a.account_type = 1
  AND ae.validated = 1
  AND ae.credit > 0
ORDER BY ae.registration_date DESC

Customer bill between date

  • Variable $endDate should be defined first and should be of Date and time value type
  • Variable $startDate should be defined first and should be of Date and time value type
SELECT customer_bill_entry.bill_date AS _tr(DATE), CONCAT( '[LINK=index.php[QUESTION_MARK]menuAction=download_customer_bill&menuParameter=', customer_bill_entry.flow_id, ']', customer_bill_entry.customer_bill_id, '[/LINK]' ) AS _tr(BILL)
FROM customer_bill_entry
WHERE customer_bill_entry.bill_date >= $startDate AND customer_bill_entry.bill_date < $endDate
GROUP BY customer_bill_entry.customer_bill_id
ORDER BY customer_bill_entry.customer_bill_id

Customer bill per month and per accounting

  • Variable $accountingId should be defined first and should be of dbOject::Accounting value type.
  • Variable $month should be defined first and should be of Month value type.
  • Variable $year should be defined first and should be of Year value type.
SELECT account.name AS _tr(CUSTOMER), resource_type.name AS _tr(RESOURCE), product.label AS _tr(PRODUCT), <