It's actually a deeper question as to data normalization--

Some stuff seems redundant, as it can be calculated, but that assumes that the data never gets modified once it's been created, and that there are no special exceptions.

For someone who just wants something quick to sell something online, and doesn't care about historical trends and such, calculating on the fly is probably just fine ... But you have to understand that you can never look back up an old invoice in the system.

The auto-calculating situation you've described also doesn't allow for item bulk discounts (especially for the complex ones, where it's not just a total percentage off, but the first 1-20 items are full price, but there's a reduction on the 21-100 items, and a further discount on 101+)

Even the order total may not just be a straight sum -- maybe there's a discount if you order more than $100 (or whatever currency you're dealing in).

I'm all for the calculating it at the time the order, and writing out all of the values, rather than attempting to re-calculate the invoice on what may be different info (price changes, even item description changes, etc.). It's not efficient in terms of size, but it is efficient for speed, and I find it to be more useful in the long term.

As for 'correct' -- no one way is more 'correct' than the other other. You have to decide what your requirements and constraints are for the project, and make the decisions based on that. One way is easier to code, and takes much less space to store; the other way will take you longer to write, but gives extra functionality that may (or may not) be useful in the situations your program is going to be used.


In reply to Re: To auto-calc or not auto-calc by jhourcle
in thread To auto-calc or not auto-calc by jk2addict

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.