Web Analytics Made Easy -
StatCounter Multiple Invoice Generation Help - CodingForum

Announcement

Collapse
No announcement yet.

Multiple Invoice Generation Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Invoice Generation Help

    Hi All,

    I have the following scenario...

    A table for Parents, a table for Children, and a table for Attendance. The Attendance table has a number of records for different children with dates and times of attendance as well as the amount for that day. Each entry is being joined to the 'Children' table via it's ID field and the Children table in turn is also joined to the Parents table via an ID field. There are also multiple entries for the same child as well as other children in the Attendance table. The Attendance table has a field called 'InvoiceGenerated' which is a status field of 0 or 1 depending on whether that entry has been through the invoice generation.

    I need to be able to do this...

    When a user clicks on a 'generate invoice' button, the system gets all the existing records in the Attendance table that have an 'InvoiceGenerated' status of 0 and then create an invoice for each parent of the child which the attendance record belongs to, storing the date and total amount. It then adds multiple lines into the InvoiceLines table that belong to that particular invoice, for all the Attendance records of each child that belongs to that parent, changing the InvoiceGenerated status of each one as it is inserted into MySQL. These lines then get printed when the use prints the invoice. It also need to take into account siblings and include these on the same invoice for that parent.

    I guess I need to use a foreach loop with a combination of other loops to achieve this but I'm stuck and not sure where to start.

    Thanks all!

  • #2
    Ps sorry for the typos - my wireless keyboard isn't that great!

    Comment


    • #3
      I may be able to assist with the printout portion of your project. Printing out a real PDF invoice using FPDF. Let me know when you get that far.

      Comment


      • #4
        You wouldn't store an invoice status in the attendance table. This results in redundant data and requires that you use transactions/rollback if anything fails.

        You would instead just use the existence of a record in the invoice table, related back to the attendance table using primary id/auto-increment column in the attendance table, to tell you if an invoice has been generated for any attendance record.

        As for the rest, you would pre-process the data when you retrieve it, making an array of arrays, storing records having the same parent id as a sub-array using the parent id as the main array key.

        $array[some_parent_id][] = array(invoice data for a child);
        $array[someother_parent_id][] = array(invoice data for a child);
        $array[someother_parent_id][] = array(invoice data for another child);

        Then just loop over this main array to get the parent id and the sub-array of invoice data, and loop over the sub-array to add the information for each child to the invoice you are producing at the time.
        Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

        Comment

        Working...
        X