Answers.Body: <p>The Line Item table is oriented towards the current state of an order's line item. The Financial Item table is oriented towards keeping track of the history of the financial aspects of line items. The Financial Transaction table is the base table for financial transactions created by CiviCRM every time there is any add, update, cancel, refund, pay grant or other action that has a financial impact. </p>
  
  <p>At a high level, each time there is a change in a line item that produces a financial effect, like a change in the quantity, or the price, or the financial type associated with the line item, a reversal entry of the previous financial impact of the line item is made in the financial item table, and a new entry is inserted representing the current financial impact. </p>
  
  <p>Another difference is that line items are more like business entities while financial items are aspects of financial accounting entries. To hide the complexity of double entry bookkeeping, CiviCRM uses Financial Types to create a bundle of Financial Accounts that will be used through the life cycle of a transaction for things like its Accounts Receivable account, its Revenue account, and potentially other accounts like the Accounts Payable or Contra Revenue account for refunds owing. These financial accounts are the ones that appear in the Chart of Accounts for an organization. Line items have financial types associated with them, while the specific detailed nature of financial items means they have financial accounts associated with them.</p>
  
  <p>The civicrm_financial_trxn and civicrm_financial_item tables hold the main accounting or bookkeeping information in CiviCRM while civicrm_entity_financial_trxn is a related table that connects records in civicrm_financial_trxn to related records in various other tables. There are many types of financial transactions, and they all are stored in these tables, and are exportable via Financial Batch exports to Accounting Packages like QuickBooks, Sage, and Microsoft Dynamics.</p>
  
  <p>Bookkeeping entries have two sides to them: a debit account and a credit account, as well as an amount and a date. Some bookkeeping entries are split, where a single amount on one side is split amongst several amounts and accounts on the other side. For example, a payment for an event registration and a donation would have the total going into the bank on one side, and revenue being recognized for two accounts on the other side.</p>
  
  <p>In the case of contributions which handle the finances for donations, memberships and event registration as well as other sale items, each line item will create a civicrm_financial_item, each payment will create a civicrm_financial_trxn, and civicrm_entity_financial_item records will connect them. In the case of line items with sales tax, which in general goes to a different account in an organization's chart of accounts, there will be an additional entry in the civicrm_financial_item table representing the tax on a line item.</p>
  
  <p>An important principle of accounting is that books should be auditable. One part of that is to retain records about all of the changes that have been made on items. So if a purchase is made with pay later selected, and two partial payments are made, the number of things purchased is changed, a refund is made, etc., then all of these are tracked in the financial tables in CiviCRM. Entries in civicrm_financial_item and civicrm_financial_trxn tables are intended to never be edited or deleted.</p>
  
  <p>We highly discourage developers trying to write directly to the civicrm_financial_trxn, civicrm_financial_item and civicrm_entity_financial_trxn tables which store financial information in CiviCRM since version 4.3. We'd encourage use of the order api and/or payment api, and will enhance and/or fix issues with those APIs.</p>
  
  <p>Documentation that is reasonably accurate on entries for these interlinked tables for various types of accounting transactions can be found at <a href="https://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Data+Flow#CiviAccounts4.3DataFlow-OnlineorofflinecontributionwithFEE" rel="noreferrer">https://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Data+Flow#CiviAccounts4.3DataFlow-OnlineorofflinecontributionwithFEE</a>. </p>
  
  <p>The Caldera Forms CiviCRM plugin for WordPress was recently trying to integrate its support for various line item operations with Civi core, so their code may provide useful guidance. The Line Item Edit extension might also be a useful developer resource, though I seem to recall that it needs a bit of refactoring.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-23T18:15:06.457Z
Answers.Text: I have a similar problem at Amnesty International and I do not write directly to the files but use the API. Nonetheless I get the same error, which seems to concentrate on a call to the FinancialItem getsingle API that is not within a try/catch block in the function . The issue started with an upgrade to CiviCRM 5.5.1. I am diving into it next week and if required will add an issue on Gitlab.
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T08:21:24.033Z
Answers.Text: Thanks for the link to the documentation. But my question about what is a financial item and what is a line item has not been answered. Could you explain to me what a financial item is? I have an assumption about what a line item is.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T08:24:33.817Z
Answers.Text: Joe, I did use the line item and contribution api. But now financial items are created. If I want to create a financial item? Does this create also a transaction?
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T20:18:05.933Z
Answers.Text: Hi @JaapJansma-CiviCooP, I've expanded my answer to hopefully better answer your question.
Answers.UserDisplayName: Joe Murray
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-29T10:34:25.877Z
Answers.Text: Thanks @JoeMurray.  Am I correct that the line item API has a bug as it does not produces the underlying financial item(s)?
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-30T15:48:44.393Z
Answers.Text: Hi @JaapJansma-CiviCooP. It may. Could you post details to an issue in lab.c.o, assign it to me, and we'll investigate.
Answers.UserDisplayName: Joe Murray
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-05T10:39:43.993Z
Answers.Text: Hey @JoeMurray I have opened an issue see: https://lab.civicrm.org/dev/financial/issues/42. Thanks!
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-23T18:12:09.487Z
Answers.LastActivityDate: 2019-02-05T15:33:45.307Z
Answers.LastEditDate: 2019-02-05T15:33:45.307Z
Answers.UserDisplayName: Joe Murray
Answers.Body: <p>Let me try to explain: Line item, Financial item</p>
  
  <p>First of all both line item and financial item are created based on contribution</p>
  
  <p>Line item are created only once and financial items are created based on the contribution status </p>
  
  <hr>
  
  <p><strong>Line item</strong> </p>
  
  <p>Line item are used for invoice purpose which holds contribution break down (amount and tax amount) </p>
  
  <p>They are static line which gets changed only when a contribution total changes </p>
  
  <hr>
  
  <p><strong>Financial Item:</strong></p>
  
  <p>Financial items are created for each contribution status - Purely used for accounting purpose (also for finding the outstanding contribution amount to pay)</p>
  
  <p>when you create a contribution as pending you end up with financial item as pending </p>
  
  <p>Then when the contribution is completed you will see one more record for completed </p>
  
  <p>same for cancelled and refund</p>
  
  <hr>
  
  <p>Other linked tables </p>
  
  <p>civicrm_entity_financial_trxn<br/>
  civicrm_financial_trxn  </p>
  
  <p>I guess this helps - I tried my best !!!</p>
  
  <p>Thanks </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T08:26:30.473Z
Answers.Text: I have discovered that when a line items contains VAT there is a financial item for the amount without VAT and the amount with VAT.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T12:06:23.693Z
Answers.Text: I have created an extension to create financial items for line items: https://lab.civicrm.org/partners/civicoop/correctlineitems
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-23T18:50:35.223Z
Answers.LastActivityDate: 2019-01-23T18:50:35.223Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.Body: <p>If I may add another question:  Why are we going through this whole rigmarole in the first place with &quot;financial type&quot; &quot;financial item&quot; and line item&quot;s?!</p>
  <p>In Quickbooks, things are simple:  Every record has two objects, which they represent in rows on a spreadsheet (starting at different columns though): (1) transaction (2) line items.  Every transaction must have at least one line item and, but can have more.  The transaction is represented by one row in a spreadsheet, the first line item is a second row in a spreadsheet the the second line item is a third etc.  The sum total of the &quot;items&quot; (line items) becomes the &quot;amount&quot; on the transaction record.  The transaction record itself does not have any items. This way, a single transaction can have a single or multiple &quot;items&quot; and &quot;classes&quot;, be recorded as one transaction (and gives you the benefit of tracking quantity &amp; inventory when that's relevant).</p>
  <p>In Civi, each transaction is only one line and that one line must have a &quot;financial type&quot; associated with it (&quot;financial type&quot; seems to match QB &quot;items&quot;-because they are both associated with accounts, but not actually accounts).</p>
  <p>If you don't use the line item extension, you can't record split transactions, quantities, or inventory.</p>
  <p>If you do use the line item extension, you have &quot;line items&quot; and &quot;financial items&quot; &amp; &quot;financial types&quot; which are all essentially the same thing but overcomplicate things for no good reason (they are all a way of recording what was &quot;sold&quot;).  All the line item fields are stuck in some weird place that you can only access with a special report.  Because the transaction itself requires a &quot;financial type&quot;, the &quot;financial types&quot;of the &quot;line items&quot; are overridden, rendered useless (the whole reason are putting different &quot;financial types&quot; on each line item is because this one transaction can't be characterized by one &quot;financial type&quot;).</p>
  <p>You can't export the line items as CSV, IIF or sync with Quickbooks and it doesn't reflect the reality of business.  The QBO integration had to map civi &quot;accounts&quot; to QBO &quot;items/products/services&quot; which doesn't make any sense (shouldn't accounts map to accounts, not &quot;items&quot;?)  The reason they had to do this, is because every QB sales receipt or invoice must have an &quot;item&quot;, and there's no good item to map to.</p>
  <p>Is there any reason civi can't mirror the same setup as QB with (1) &quot;items&quot; (2) &quot;class&quot; (3)&quot;accounts&quot; and require every transaction to use line items, even if they only have one?  This doesn't hurt other accounting softwares which don't record like this because they can pull only the &quot;transaction line&quot; while QBO can sync seamlessly with all the relevant lines.</p>
  <p>For the record, I would argue that &quot;events&quot; should also use line items to represent the &quot;ticket/item&quot; that was sold as a &quot;contribution&quot;.</p>
  <p>Does anyone have ideas on this?  I do, and I'm willing to put money towards it, but it needs more support from the community first.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T21:03:46.630Z
Answers.Text: StackExchange expects an Answer to be ... an Answer. Not a way of asking a new Question. Since you have now created a separate Question perhaps you can either remove this answer, or integrate it with your own Question
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-17T15:26:35.440Z
Answers.LastActivityDate: 2020-06-17T15:26:35.440Z
Answers.UserDisplayName: Yona
Answers.Body: <p>The solution to my question is to use the Order API. The order API does create a contribution, line items and the underlyning financial items etc...</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-14T11:12:21.653Z
Answers.LastActivityDate: 2019-02-14T11:12:21.653Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Body: <p>I have created an extension to generate invoices (contributions) based on time spend on activities on a case. </p>
  
  <p>For each activity a line item was created and added to the contribution. 
  Also the financial type had 21% percent of VAT configured. </p>
  
  <p>In CiviCRM version 4.6 this extension works smoothly. However after upgrading to CiviCRM version 5.9.1 I cannnot edit contributions any more. It fails with the error <code>Expected one FinancialItem but found 0</code>.</p>
  
  <p>After debugging I found out that the line items created with my extension does not have a related financial item (I did not even know they existed and/or where required). </p>
  
  <p>So now I have changed my extension to create <strong>two</strong> financial items when <strong>one</strong> line item is added:</p>
  
  <ol>
  <li>One financial item for the amount <strong>without VAT</strong></li>
  <li>And, one financial item for the <strong>VAT amount</strong></li>
  </ol>
  
  <p>Contributions created after this change could be edited. Hurray! </p>
  
  <p><strong>The questions</strong></p>
  
  <p>Now comes my questions:</p>
  
  <ol>
  <li>What are financial items?</li>
  <li>How do they differ from line items?</li>
  <li>Where do I find documentation about line items and financial items?</li>
  <li>What are financial transactions (trxn)? (See answer of Joe)?</li>
  </ol>
  
  <p><strong>Solution</strong></p>
  
  <p>To create all the underlying financial items etc.. One must use the Order API. The order API does create a contribution and line items.</p>
  
Tags: <civicontribute><contributions><financial-accounts><line-items>
Title: What is a line item? And what is a financial item and how are those two linked together?
ThreadText: # What is a line item? And what is a financial item and how are those two linked together?
  
  (Asked by: username_0 on 2019-01-23)
  
  I have created an extension to generate invoices (contributions) based on time spend on activities on a case.
  
  For each activity a line item was created and added to the contribution.
  Also the financial type had 21% percent of VAT configured.
  
  In CiviCRM version 4.6 this extension works smoothly. However after upgrading to CiviCRM version 5.9.1 I cannnot edit contributions any more. It fails with the error `Expected one FinancialItem but found 0`.
  
  After debugging I found out that the line items created with my extension does not have a related financial item (I did not even know they existed and/or where required).
  
  So now I have changed my extension to create **two** financial items when **one** line item is added:
  
  1. One financial item for the amount **without VAT**
  2. And, one financial item for the **VAT amount**
  
  Contributions created after this change could be edited. Hurray!
  
  **The questions**
  
  Now comes my questions:
  
  1. What are financial items?
  2. How do they differ from line items?
  3. Where do I find documentation about line items and financial items?
  4. What are financial transactions (trxn)? (See answer of Joe)?
  
  **Solution**
  
  To create all the underlying financial items etc.. One must use the Order API. The order API does create a contribution and line items.
  
  **Tags:** civicontribute, contributions, financial-accounts, line-items
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_0 on 2019-02-14. Score: 3 | Accepted answer
  
  The solution to my question is to use the Order API. The order API does create a contribution, line items and the underlyning financial items etc...
  
  
  ---
  
  ### Answer by username_1 on 2019-01-23. Score: 9
  
  The Line Item table is oriented towards the current state of an order's line item. The Financial Item table is oriented towards keeping track of the history of the financial aspects of line items. The Financial Transaction table is the base table for financial transactions created by CiviCRM every time there is any add, update, cancel, refund, pay grant or other action that has a financial impact.
  
  At a high level, each time there is a change in a line item that produces a financial effect, like a change in the quantity, or the price, or the financial type associated with the line item, a reversal entry of the previous financial impact of the line item is made in the financial item table, and a new entry is inserted representing the current financial impact.
  
  Another difference is that line items are more like business entities while financial items are aspects of financial accounting entries. To hide the complexity of double entry bookkeeping, CiviCRM uses Financial Types to create a bundle of Financial Accounts that will be used through the life cycle of a transaction for things like its Accounts Receivable account, its Revenue account, and potentially other accounts like the Accounts Payable or Contra Revenue account for refunds owing. These financial accounts are the ones that appear in the Chart of Accounts for an organization. Line items have financial types associated with them, while the specific detailed nature of financial items means they have financial accounts associated with them.
  
  The civicrm\_financial\_trxn and civicrm\_financial\_item tables hold the main accounting or bookkeeping information in CiviCRM while civicrm\_entity\_financial\_trxn is a related table that connects records in civicrm\_financial\_trxn to related records in various other tables. There are many types of financial transactions, and they all are stored in these tables, and are exportable via Financial Batch exports to Accounting Packages like QuickBooks, Sage, and Microsoft Dynamics.
  
  Bookkeeping entries have two sides to them: a debit account and a credit account, as well as an amount and a date. Some bookkeeping entries are split, where a single amount on one side is split amongst several amounts and accounts on the other side. For example, a payment for an event registration and a donation would have the total going into the bank on one side, and revenue being recognized for two accounts on the other side.
  
  In the case of contributions which handle the finances for donations, memberships and event registration as well as other sale items, each line item will create a civicrm\_financial\_item, each payment will create a civicrm\_financial\_trxn, and civicrm\_entity\_financial\_item records will connect them. In the case of line items with sales tax, which in general goes to a different account in an organization's chart of accounts, there will be an additional entry in the civicrm\_financial\_item table representing the tax on a line item.
  
  An important principle of accounting is that books should be auditable. One part of that is to retain records about all of the changes that have been made on items. So if a purchase is made with pay later selected, and two partial payments are made, the number of things purchased is changed, a refund is made, etc., then all of these are tracked in the financial tables in CiviCRM. Entries in civicrm\_financial\_item and civicrm\_financial\_trxn tables are intended to never be edited or deleted.
  
  We highly discourage developers trying to write directly to the civicrm\_financial\_trxn, civicrm\_financial\_item and civicrm\_entity\_financial\_trxn tables which store financial information in CiviCRM since version 4.3. We'd encourage use of the order api and/or payment api, and will enhance and/or fix issues with those APIs.
  
  Documentation that is reasonably accurate on entries for these interlinked tables for various types of accounting transactions can be found at <https://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Data+Flow#CiviAccounts4.3DataFlow-OnlineorofflinecontributionwithFEE>.
  
  The Caldera Forms CiviCRM plugin for WordPress was recently trying to integrate its support for various line item operations with Civi core, so their code may provide useful guidance. The Line Item Edit extension might also be a useful developer resource, though I seem to recall that it needs a bit of refactoring.
  
  > **Comments:**
  > **username_2**: I have a similar problem at Amnesty International and I do not write directly to the files but use the API. Nonetheless I get the same error, which seems to concentrate on a call to the FinancialItem getsingle API that is not within a try/catch block in the function . The issue started with an upgrade to CiviCRM 5.5.1. I am diving into it next week and if required will add an issue on Gitlab.  
  > **username_0**: Thanks for the link to the documentation. But my question about what is a financial item and what is a line item has not been answered. Could you explain to me what a financial item is? I have an assumption about what a line item is.  
  > **username_0**: Joe, I did use the line item and contribution api. But now financial items are created. If I want to create a financial item? Does this create also a transaction?  
  > **username_1**: Hi @JaapJansma-username_0, I've expanded my answer to hopefully better answer your question.  
  > **username_0**: Thanks @username_1.  Am I correct that the line item API has a bug as it does not produces the underlying financial item(s)?  
  > **username_1**: Hi @JaapJansma-username_0. It may. Could you post details to an issue in lab.c.o, assign it to me, and we'll investigate.  
  > **username_0**: Hey @username_1 I have opened an issue see: https://lab.civicrm.org/dev/financial/issues/42. Thanks!  
  
  ---
  
  ### Answer by username_3 on 2019-01-23. Score: 2
  
  Let me try to explain: Line item, Financial item
  
  First of all both line item and financial item are created based on contribution
  
  Line item are created only once and financial items are created based on the contribution status
  
  ---
  
  **Line item**
  
  Line item are used for invoice purpose which holds contribution break down (amount and tax amount)
  
  They are static line which gets changed only when a contribution total changes
  
  ---
  
  **Financial Item:**
  
  Financial items are created for each contribution status - Purely used for accounting purpose (also for finding the outstanding contribution amount to pay)
  
  when you create a contribution as pending you end up with financial item as pending
  
  Then when the contribution is completed you will see one more record for completed
  
  same for cancelled and refund
  
  ---
  
  Other linked tables
  
  civicrm\_entity\_financial\_trxn  
  civicrm\_financial\_trxn
  
  I guess this helps - I tried my best !!!
  
  Thanks
  
  > **Comments:**
  > **username_0**: I have discovered that when a line items contains VAT there is a financial item for the amount without VAT and the amount with VAT.  
  > **username_0**: I have created an extension to create financial items for line items: https://lab.civicrm.org/partners/username_0/correctlineitems  
  
  ---
  
  ### Answer by username_4 on 2020-06-17. Score: 0
  
  If I may add another question: Why are we going through this whole rigmarole in the first place with "financial type" "financial item" and line item"s?!
  
  In Quickbooks, things are simple: Every record has two objects, which they represent in rows on a spreadsheet (starting at different columns though): (1) transaction (2) line items. Every transaction must have at least one line item and, but can have more. The transaction is represented by one row in a spreadsheet, the first line item is a second row in a spreadsheet the the second line item is a third etc. The sum total of the "items" (line items) becomes the "amount" on the transaction record. The transaction record itself does not have any items. This way, a single transaction can have a single or multiple "items" and "classes", be recorded as one transaction (and gives you the benefit of tracking quantity & inventory when that's relevant).
  
  In Civi, each transaction is only one line and that one line must have a "financial type" associated with it ("financial type" seems to match QB "items"-because they are both associated with accounts, but not actually accounts).
  
  If you don't use the line item extension, you can't record split transactions, quantities, or inventory.
  
  If you do use the line item extension, you have "line items" and "financial items" & "financial types" which are all essentially the same thing but overcomplicate things for no good reason (they are all a way of recording what was "sold"). All the line item fields are stuck in some weird place that you can only access with a special report. Because the transaction itself requires a "financial type", the "financial types"of the "line items" are overridden, rendered useless (the whole reason are putting different "financial types" on each line item is because this one transaction can't be characterized by one "financial type").
  
  You can't export the line items as CSV, IIF or sync with Quickbooks and it doesn't reflect the reality of business. The QBO integration had to map civi "accounts" to QBO "items/products/services" which doesn't make any sense (shouldn't accounts map to accounts, not "items"?) The reason they had to do this, is because every QB sales receipt or invoice must have an "item", and there's no good item to map to.
  
  Is there any reason civi can't mirror the same setup as QB with (1) "items" (2) "class" (3)"accounts" and require every transaction to use line items, even if they only have one? This doesn't hurt other accounting softwares which don't record like this because they can pull only the "transaction line" while QBO can sync seamlessly with all the relevant lines.
  
  For the record, I would argue that "events" should also use line items to represent the "ticket/item" that was sold as a "contribution".
  
  Does anyone have ideas on this? I do, and I'm willing to put money towards it, but it needs more support from the community first.
  
  > **Comments:**
  > **username_5**: StackExchange expects an Answer to be ... an Answer. Not a way of asking a new Question. Since you have now created a separate Question perhaps you can either remove this answer, or integrate it with your own Question  
  
  ---
  
  