Function Description
|
Depending on the values of the Type_Switch and Invoice_Count parameters, create a temporary directory named after the current process_id in which to store the following generated invoices or statements. Only one of the following six steps will be used for each invocation of this script:
-
If Type_Switch = ‘NewInvoice’ and Invoice_Count = ‘all’, first ensure that the Sys_Last_Annual_Cycle is no more than 16 months after the current date[1]. If this test is successful, then get a list of all records in the User table where User_IsActive = ‘Active’ and User_Expiry_Date is less than the Sys_Last_Annual_Cycle. For each of these User records, create a new Invoice record, inserting the User_Number as the foreign key, the current date as the Invoice_Date, the Invoiced_Medium as the value of the Medium_Switch field, and the Invocie_EnteredBy as the value of REMOTE_USER.
-
If the User IsMember field = 0, create a new invoice for this user. This Invoice should have a single Invoice_Item with Item_Amount = Sys_Reg_User_Price and Item_Description = “Renewal of Free Internet Account”.[2]
-
If the User_Is_Member field= 1, denoting that the user is a member, then determine if the User is an Individual or Instutional member by querying the Member table for this user and create a new Invoice record with an Invoice_Item with Item_Description of either “Institutional Membership Renewal” or “Individual Membership Renewal” and an Item_Amount of either “Sys_Ind_Mem_Price” or “Sys_Inst_Mem_Price” respectively.
-
If the User_Is_Member field = 1 and the user has a corresponding record in the Services table, for each service listed in the Service Table, multiply any non-zero value by the respective Price in the System_Defaults table and create a new Invoice_Item record with this product in the Item_Amount field and the Service Description in the Item_Description field, and update the Invoice_Number and User_Number.
-
Once the Membership and all Services have been invoices for a user, obtain the sum of all Invoice_Item entries for this Invoice_Number and put this value in the Invoice_Amount field
-
Increment the sys_Last_Annual_Cycle by 1 year to be December 31 of the end of the current billing cycle.
-
If Type_Switch = ‘NewInvoice’ and Invoice_Count = ‘1’, get the User_UserName value from the CGI script and query the User table to get the corresponding User_Number for this UserName. For this User_Number, create a new Invoice record, inserting the User_Number as the foreign key, the current date as the Invoice_Date, the Invoiced_Medium as the value of the Medium_Switch field, and the Invocie_EnteredBy as the value of REMOTE_USER.
-
If the User IsMember field = 0, create a new invoice for this user. This Invoice should have a single Invoice_Item with Item_Amount = Sys_Reg_User_Price and Item_Description = “Renewal of Free Internet Account”.
-
If the User_Is_Member field= 1, denoting that the user is a member, then determine if the User is an Individual or Instutional member by querying the Member table for this user and create a new Invoice record with an Invoice_Item with Item_Description of either “Institutional Membership Renewal” or “Individual Membership Renewal” and an Item_Amount of either “Sys_Ind_Mem_Price” or “Sys_Inst_Mem_Price” respectively.
-
For each service listed in the Service Table, multiply any non-zero value by the respective Price in the System_Defaults table and create a new Invoice_Item record with this product in the Item_Amount field and the Service Description in the Item_Description field, and update the Invoice_Number and User_Number. Once all Services have been invoices for the user, obtain the sum of all Invoice_Item entries for this Invoice_Number and put this value in the Invoice_Amount field.
-
Once the Membership and all Services have been invoices for the user, obtain the sum of all Invoice_Item entries for this Invoice_Number and put this value in the Invoice_Amount field.
-
If Type_Switch = ‘ExistingInvoice’ and Invoice_Count = ‘all’, get a list of all invoices from the Invoice_Table where there is no corresponding Receipt table entry and where ‘User_IsActive = ‘Active’.
-
If Type_Switch = ‘ExistingInvoice’ and Invoice_Count = ‘1’, get the User_UserName value from the CGI script and query the User table to get the corresponding User_Number for this UserName. Get a list of all invoices from the Invoice_Table where there is no corresponding Receipt table entry and where the Invoice table User_Number is the current User_Number.
-
If Type_Switch = ‘Statement’ and Invoice_Count = ‘all’, get a list of all Invoices and Receipts for each User where User_IsActive = ‘Active’. Format each statement using the stmt.tmpl template file such that all invoice and receipt entries are combined and then sorted in an oldest-date-first list.
-
If Type_Switch = ‘Statement’ and Invoice_Count = ‘1’, get a list of all Invoices and Receipts for the User_Number corresponding to the User_UserName value. Format the statement using the stmt.tmpl template file such that all invoice and receipt entries are combined and then sorted in a oldest-date-first list.
Regardless of which of the above six steps was selected, get the value of the Medium_Switch parameter:
-
If the Medium_Switch = ‘E-mail’ format each file in the temporary directory created above as an e-mail message and send the statement or invoice via e-mail to <User_UserName>@gpfn.ca. Delete each temporary file after it is sent.
-
If the Medium_Switch = ‘Screen’, format each file in the temporary directory created above as an HTML table, formatting it according to the invoice.tmpl or statement.tmpl file and then zipping it and then inserting a link in the returned page so the volunteer can download the file using a HTTP transport. Delete each temporary file after it is incorporated into the new HTML page.
Delete the temporary directory created above.
|