Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-923

Add option to cache copy of invoice when generated

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 5.1.0-b1
    • Component/s: None
    • Labels:
      None

      Description

      Currently invoice copies (PDFs, for example) are generated on the fly. This allows any changes made to the invoice to be reflected when the invoice is next viewed. However, some localities require that the invoice not change at all after being generated.

      To handle these instances, there should be a company setting to save a cached copy of the invoice to disk (Disabled by default). Once saved, all future requests to generate invoices will instead return the cached copy (if the company setting is enabled) if it exists. If a cached copy does not exist, it should be generated and cached to disk. Any future changes to the invoice would not affect the cached copy.

      In the rare event that a cached copy must be updated, there should be a "Recache" checkbox on the edit invoice page that allows the cached copy to be overwritten when saved. This option should only appear if the save cached copies company setting is enabled.

      We may need to also prevent an invoice from being updated once it's cached. Perhaps this would be a second setting? "Do not allow invoices to be modified after they are created.", but we would probably need a way to allow certain people to override this.

      As a sanity check, perhaps we should raise an error if an invoice is attempted to be edited without checking the "recache" option.

      This task should not apply to draft and proforma invoice types.

      UPDATE 12/11/20

      It has been suggested that we store the data only, rather than archiving a physical copy of the PDF which would be larger. We could store the invoices to disk in JSON format only – all of the data, and still generate the invoice PDF's on the fly, but rather than populating the invoice with data from the database, we populate from the invoice's JSON file if it exists. However, some indicate that it's not acceptable for the invoice template/design to change, others expect it to change. So there could be an option to store JSON only, or JSON + PDF.

        Issue Links

          Activity

          Hide
          admin Paul Phillips added a comment -

          Maybe this should be turned on automatically with proforma invoices, see CORE-497

          Show
          admin Paul Phillips added a comment - Maybe this should be turned on automatically with proforma invoices, see CORE-497
          Hide
          cody Cody Phillips (Inactive) added a comment -

          Considering each PDF is generally around 650KB, I would vote no for enabling automatically.

          Show
          cody Cody Phillips (Inactive) added a comment - Considering each PDF is generally around 650KB, I would vote no for enabling automatically.
          Hide
          admin Paul Phillips added a comment -

          Locations that necessitate proforma invoices usually require that invoices not be changed once generated. If we create these on the fly, addresses and names at minimum may change. If caching these is an issue due to size, perhaps caching all of the data to a json file or similar is preferable, and generating the PDF on the fly from the static data.

          Show
          admin Paul Phillips added a comment - Locations that necessitate proforma invoices usually require that invoices not be changed once generated. If we create these on the fly, addresses and names at minimum may change. If caching these is an issue due to size, perhaps caching all of the data to a json file or similar is preferable, and generating the PDF on the fly from the static data.
          Hide
          cody Cody Phillips (Inactive) added a comment -

          Caching to json file wouldn't work as the data structure the invoice data would be stored in may change at some point, necessitating that all previously cached records be updated to conform to the new expected format in order to be rendered into PDF format.

          There only two options, as far I as can tell:

          1. Cache the PDF document itself (makes the most sense, since this is the only way to prevent the document from being altered. Admin may change the PDF template used, etc., etc.)
          2. Cache all invoice data in the database. This would require storing a snapshot of all invoice related information across all joins. Super complex, as almost everything in the database is related to invoice data (client, contacts, transactions, services, company settings). This method also can't guarantee that a user using a custom invoice template will maintain state correctly (as their custom template might make other joins not anticipated).

          So really, that only leaves option #1.

          Show
          cody Cody Phillips (Inactive) added a comment - Caching to json file wouldn't work as the data structure the invoice data would be stored in may change at some point, necessitating that all previously cached records be updated to conform to the new expected format in order to be rendered into PDF format. There only two options, as far I as can tell: Cache the PDF document itself (makes the most sense, since this is the only way to prevent the document from being altered. Admin may change the PDF template used, etc., etc.) Cache all invoice data in the database. This would require storing a snapshot of all invoice related information across all joins. Super complex, as almost everything in the database is related to invoice data (client, contacts, transactions, services, company settings). This method also can't guarantee that a user using a custom invoice template will maintain state correctly (as their custom template might make other joins not anticipated). So really, that only leaves option #1.
          Hide
          admin Paul Phillips added a comment -

          There might be another option. Contact details are the things that would primarily change. Preventing an invoice from being updated otherwise wouldn't be difficult to do. We store all contact information changes. If we are able to fetch the contact details from the state they were in at the time the invoice was generated, we'll have the correct details.

          Show
          admin Paul Phillips added a comment - There might be another option. Contact details are the things that would primarily change. Preventing an invoice from being updated otherwise wouldn't be difficult to do. We store all contact information changes. If we are able to fetch the contact details from the state they were in at the time the invoice was generated, we'll have the correct details.
          Hide
          cody Cody Phillips (Inactive) added a comment - - edited

          I think it's much more than contact details and invoice line items.

          This also includes:

          • Client number
          • Client settings such as:
            • Tax ID
          • Company settings such as:
            • Terms
            • Company Address
            • Tax ID
            • Background image
            • Logo
            • Display logo/background image option

          And of course lets not forget custom invoice templates which we should also support, which again may perform additional joins on data.

          Show
          cody Cody Phillips (Inactive) added a comment - - edited I think it's much more than contact details and invoice line items. This also includes: Client number Client settings such as: Tax ID Company settings such as: Terms Company Address Tax ID Background image Logo Display logo/background image option And of course lets not forget custom invoice templates which we should also support, which again may perform additional joins on data.
          Hide
          cody Cody Phillips (Inactive) added a comment -

          Maybe we can add the following options as well:

          • Option to delete archived copy after X months
          • Store archived copies on Amazon AWS (tied into backup settings – will need to abstract and denote as "Cloud storage", and allow cloud storage provider extensions)
          Show
          cody Cody Phillips (Inactive) added a comment - Maybe we can add the following options as well: Option to delete archived copy after X months Store archived copies on Amazon AWS (tied into backup settings – will need to abstract and denote as "Cloud storage", and allow cloud storage provider extensions)

            People

            • Assignee:
              abdy Abdy Franco
              Reporter:
              admin Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                8/Jun/21

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 days, 41 minutes
                4d 41m

                  Agile