-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CAS AP Invoice - Invoices and Batches #3254
Comments
AnalisysQuestions
Scheduler
Batches UI
CSV Report
Tables Schemascas_invoice_batches
cas_invoices
cas_invoice_details
cas_distribution_accounts
CAS API Invoice Payload Details{
"invoiceType": "Standard", // Fixed for now and not configurable, will be hard-coded while generating the CAS API payload.
"supplierNumber": "3125635", // Retrieved from the cas_supplier_id associated during the batch creation.
"supplierSiteNumber": "001", // Retrieved from the cas_supplier_id associated during the batch creation.
"invoiceDate": "17-APR-2024", // Batch creation date (best assumption for now) or approval date.
"invoiceNumber": "988855", // For now, "supplier number concatenated with record id" or similar.
"invoiceAmount": 300.00, // Always 0(zero). Since SIMS will be generating the debt and credit records, the SUM should be always 0. This is not expected to be calculated at this moment to execute any sort of validation.
"payGroup": "GEN GLP", // // Fixed for now and not configurable, will be hard-coded while generating the CAS API payload.
"dateInvoiceReceived": "02-MAR-2024", // Disbursement receipt file date.
"dateGoodsReceived": "01-MAR-2024", // Do not provide it.
"remittanceCode": "01", // Fixed for now and not configurable, will be hard-coded while generating the CAS API payload.
"specialHandling": "N", // Fixed for now and not configurable, will be hard-coded while generating the CAS API payload.
"nameLine1": "", // Do not provide it. The docs mentioned it as conditional but not on which field.
"nameLine2": "", // Do not provide it. The docs mentioned it as conditional but not on which field.
"addressLine1": "", // Do not provide it. The assumption is that all fields address-related fields can be optional if "address line 1" is not provided.
"addressLine2": "", // Do not provide it.
"addressLine3": "", // Do not provide it.
"city": "", // Do not provide it.
"country": "", // Do not provide it.
"province": "", // Do not provide it.
"postalCode": "", // Do not provide it.
"qualifiedReceiver": "", // Do not provide it.
"terms": "Immediate", // Fixed for now and not configurable, will be hard-coded while generating the CAS API payload.
"payAloneFlag": "Y", // Do not provide it.
"paymentAdviceComments": "Test", // Do not provide it.
"remittanceMessage1": "", // Send an empty string for now.
"remittanceMessage2": "", // Send an empty string for now.
"remittanceMessage3": "", // Do not provide.
"glDate": "17-APR-2024", // Batch creation date for now.
"invoiceBatchName": "CASAPWEB1", // "SIMSBATCH"(constant) + "sequence number from sequence control".
"currencyCode": "CAD", // Fixed and not configurable, will be hard-coded while generating the CAS API payload.
"invoiceLineDetails": [
{
"invoiceLineNumber": 1, // Mandatory, incremental number inside the invoiceLineDetails list.
"invoiceLineType": "Item", // Fixed as per the docs.
"lineCode": "DR", // Fixed as per the docs (DR or CR).
"invoiceLineAmount": 150.00, // Award(grant) value.
"defaultDistributionAccount": "105.15006.10120.5505.1500000.000000.0000", // Will be specific for an award(grant) plus the operation type (credit/debit).
"description": "Test Line Description", // Do not provide it.
"taxClassificationCode": "", // Do not provide it.
"distributionSupplier": "", // Do not provide it.
"info1": "", // Do not provide it.
"info2": "", // Do not provide it.
"info3": "" // Do not provide it.
},
{
"invoiceLineNumber": 2, // Mandatory, incremental number inside the invoiceLineDetails list.
"invoiceLineType": "Item", // Fixed as per the docs.
"lineCode": "CR", // Fixed as per the docs (DR or CR).
"invoiceLineAmount": 150.00, // Award(grant) value.
"defaultDistributionAccount": "105.15006.10120.7701.1500000.000000.0000", // Will be specific for an award(grant) plus the operation type (credit/debit).
"description": "Test Line 2", // Do not provide it.
"taxClassificationCode": "", // Do not provide it.
"distributionSupplier": "", // Do not provide it.
"info1": "", // Do not provide it.
"info2": "", // Do not provide it.
"info3": "" // Do not provide it.
}
]
} |
@CarlyCotton are the distribution accounts different for the different offering intensities or grants like |
@CarlyCotton are you aware if there is a cut date till when we should be checking if receipts have invoices generated? |
@andrewsignori-aot Invoices not generated - I think this can be accomplished by a report that users can run. Disbursements without an Invoice or something. |
@CarlyCotton persisting the decisions from the last call, they are:
|
@CarlyCotton the AC states "an invoice PER disbursement date" but can we consider "one invoice per document number", which means "one invoice per disbursement receipt", right?
|
@CarlyCotton the "batch date" mentioned in some business AC does not seem part of the CAS invoice payload, right? |
@andrewsignori-aot New: |
@CarlyCotton adding the draft from our latest chat to not lose it. Once your notes are in they will take precedence.
|
@CarlyCotton, question originated from a PR comment. Since the supplier being active is part of the criteria to create the invoice I would say that we should persist it when the batch is created and in the event it changes and CAS API call fails, it will generate a |
@CarlyCotton do you see any need to store the student SIN currently associated with the student for history purposes? |
Yes, I think we continue to use the cas supplier at the time of batch creation. Worst case we get a fail on the single invoice.
Nope, the supplier is the more important piece of information for the invoice. If the SIN doesn't match the supplier we end up in the same position with manual intervention being required. |
…ity Models (#4289) New tables to allow the CAS invoices to be created for disbursement receipts. ## ER with new tables  ### Sample `sims.cas_distribution_accounts`  _Note:_ The values will be populated manually per environment. ### Rollback      
@CarlyCotton I am planning to have the scheduler create the batches running at 8 PM PST from Monday to Friday considering that:
|
@CarlyCotton I was not able to find an answer for this one. Did we have a decision about a possible date to stop to look for a pending receipt? For instance, "only check disbursement receipts with disbursed dates in the last month". |
@CarlyCotton is there a plan to add some error handling to the batch generation? |
At this point I don't have a limit on how far back to search for receipt disbursements. This may change in the future as this new daily batch process stabilizes. Didn't have a plan for error handling on the batch generation. Is this going to be run through a job on the dashboard? Logs and a sysdig alert like the other processes would work. |
- Created the new scheduler default setup including DB migrations. - Added information in the wiki with the agreed time with the business. - Created only the first E2E to allow some testing. Adding further E2E is planned but it will also demand adding more factories hence this was a point to stop for now. - Created DB seeding for the new CAS distribution accounts to allow easy execution assertions on expected distribution accounts. It may be shared with API when API tests are created. - _Note:_ DB seeding was never enabled for queue-consumers and few files were modified to allow it following the same already in place for the API. - Minor refactors were executed in the DB seeding to allow the system user to be retrieved and the default logger to be used instead of `console`. - The `sequence-control` service was changed to allow outside control of the sequence increment. ## Pending Receipts Query - Query to retrieve the pending receipts was kept as "query builder" to enforce the inner joins (even if some of them would work as left joins enforced by the where condition). - Query to retrieve the pending receipts currently does not have a stop date to look for pending disbursements and is just retrieving anything that is pending. ## Saving Operations The method to save the invoices is using a single transaction and chunk inserts. The 150-chunk size was determined by local tests using 50 to 500-chunk sizes. The tests were realized with 1000 invoice records and each one had 4 invoice details where it took around 1 second to complete the DB persistence operation. In terms of SQL parameters, Postgres can accept a maximum of [65K parameters](https://www.postgresql.org/docs/current/limits.html) in a single command. The save operation in chunks was not logging any additional select and was grouping the insert operations as below for invoices and similar for invoice details. ```sql INSERT INTO "sims"."cas_invoices"("created_at", "updated_at", "invoice_number", "invoice_status", "invoice_status_updated_on", "errors", "creator", "modifier", "cas_invoice_batch_id", "disbursement_receipt_id", "cas_supplier_id") VALUES (DEFAULT, DEFAULT, $1, $2, $3, DEFAULT, $4, DEFAULT, $5, $6, $7), (DEFAULT, DEFAULT, $8, $9, $10, DEFAULT, $11, DEFAULT, $12, $13, $14), (DEFAULT, DEFAULT, $15, $16, $17, DEFAULT, $18, DEFAULT, $19, $20, $21), (DEFAULT, DEFAULT, $22, $23, $24, DEFAULT, $25, DEFAULT, $26, $27, $28), (DEFAULT, DEFAULT, $29, $30, $31, DEFAULT, $32, DEFAULT, $33, $34, $35), (DEFAULT, DEFAULT, $36, $37, $38, DEFAULT, $39, DEFAULT, $40, $41, $42) (...) ``` ## Migration revert 
New proposed UI to allow invoice batches download. The content is completely subject to be changed and the goal is to have a starting point to make some progress towards the final solution. - Used a data table with server-side pagination. - Enabled sort operation only for the batch date for now. - Enable some filters on statuses. - Added temporary download button (functionality to be added during this sprint in an upcoming PR). - Added temporary modals to the UI to later add the functionality for batch approval/rejection (it may or may not be an effort in the current sprint). - Final Ministry roles to be created in an upcoming PR. - E2E tests to be added in an upcoming PR.  _Note: the above UI was changed during PR to remove the "Only" prefix that can be noticed in the below images._  
- Enabled the download of a CSV file that represents a batch and its invoice details. - Each row represents awards added to one invoice and its distribution accounts. - Created a new role, `aest-cas-invoicing`, and added it globally to the CAS invoice controller and UI links. ### Report Download Benchmark Data for an outputted report with 1122 invoice details. - File size output: 287Kb. - Report generation total: 456.248ms - Data retrieval: 394.036ms (SQL query and typeorm objects creation). - Report generation: 53.758ms (Typeorm objects to 2D objects for CSV generation). - Report CSV generation: 5.309ms (2D objects to CSV format). ## Sample report for one invoice with two awards (color manually added)  ## Minor refactor Method `streamFile` moved to a utils file to be shared between reports, CAS invoice reports, and others in the future.
Created new E2E tests for the new endpoints and extended scheduler E2E tests previously added (only one). ## API Endpoints (CASInvoiceBatchAESTController) - getCASInvoiceBatchReport - Should generate an invoice batch report with part-time and full-time invoices when the batch exists. - Should throw a HttpStatus Not Found (404) when the requested invoice batch does not exist. - Should throw a HttpStatus Forbidden (403) error when an unauthorized Ministry user tries to get the invoice batch report. - getInvoiceBatches - Should be able to get invoice batches for the first page in a paginated result with a limit of two per page in descending order when there are three invoice batches available. - Should be able to get only pending invoice batches when the filter for status is applied. - Should throw a HttpStatus Bad Request (400) error when the filter for status is invalid. - Should throw a HttpStatus Bad Request (400) error when the sortField is invalid. - Should throw a HttpStatus Forbidden (403) error when an unauthorized Ministry user tries to get the invoice batches. ## Scheduler - Should create a new CAS invoice and avoid making a second invoice when a receipt already has an invoice associated with it. - Should interrupt the process when an invoice is trying to be generated but there are no distribution accounts available to create the invoice details ([addressing previous PR comment](#4297 (comment))). - Should finalize the process nicely when there is no pending receipt to process ([addressing previous PR comment](#4297 (comment))).
Demo on DEVUsing existing applications on DEV with a receipt already in place. Last name: JACK UPDATED Last name: Boni Signori_1 Notes
Tables Resetdelete from sims.cas_invoice_batches
delete from sims.cas_invoices
delete from sims.cas_invoice_details Fake Distribution Accounts to be inserted in non-prodINSERT into
sims.cas_distribution_accounts (award_value_code,"offering_intensity",operation_code,distribution_account,is_active,created_at,updated_at,creator,modifier)
VALUES
('BGPD','Full Time','CR','BGPD.CR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('BGPD','Full Time','DR','BGPD.DR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('SBSD','Full Time','CR','SBSD.CR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('SBSD','Full Time','DR','SBSD.DR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('BCAG','Part Time','CR','BCAG.CR.PART-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('BCAG','Part Time','DR','BCAG.DR.PART-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('SBSD','Part Time','CR','SBSD.CR.PART-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('SBSD','Part Time','DR','SBSD.DR.PART-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-01-29 09:07:18.025',634,NULL),
('BCAG','Full Time','CR','BCAG.CR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-02-05 18:14:21.193',634,NULL),
('BCAG','Full Time','DR','BCAG.DR.FULL-TIME.0000000000000000000000',true,'2025-01-29 09:07:18.025','2025-02-05 18:14:21.193',634,NULL); System user from each environment must be changed. select * from sims.users where last_name = 'system-user' |
User Story:
As a member of the SABC Finance team (Ministry User), I need to be able to review and approve a detailed inventory of the previous day’s PT and FT provincial grant disbursements so that SIMS can notify CAS about these disbursements and maintain up to date records of a student’s taxable income. This summary will need to have a sub total of each award and a total for the batch.
Each Invoice should relate to a single disbursement for an individual student. It will need to have two line items per award under the invoice.
Every Invoice will be included in a daily batch of invoices.
Once approved, the entire batch is sent to CAS. We need to record the outcome for each invoice, success or error
Acceptance Criteria:
Access/Roles
Invoices
Batches
Business Context:
Files for CAS: DEVS>CAS
For PT and FT student aid funding, this will only require $0 invoices to ensure T4As are generated based on provincial grants.
This may need to be revised in the future with inclusion of any invoicing for actual funds disbursed or for peripheral programs.
Although there are no set volume limitations, the service is designed for single processing in real time throughout the business day, typically up to 10,000 requests per day (distributed throughout the day) and up to 2,000 invoices (if sent one after the other)
AP Web Service Client Onboarding v02r02.pdf
AP Invoice Web Service Field Requirements -General.xlsx
Technical
Batches UI
Reports
at the bottom left of the Ministry Portal.BCSG
greater than 0 (zero).BCSG
, select allvalue_types
BC Grant
(but BCSG) records from thedisbursement_values
and consider only itseffective_amount
to be added to the invoices (only select records where the BC Grant is greater than zero).BC Grant
create an invoice details with all active distribution accounts from the new tablecas_distribution_accounts
associated with the grantvalue_code
. Expected to have two (CR/DR) active distribution accounts for each grant code.CSV Report
Order by Award Code, Supplier Number, and Document number.
Tables Schemas
cas_invoice_batches
id
: serial;batch_name
: varchar(50);batch_date:
timestamp.approval_status
:Pending
,Approved
,Rejected
;approval_status_updated_on
: timestamp;approval_status_updated_by
: related touser_id
.cas_invoices
id
: serial;cas_invoice_batch_id
: related tocas_invoice_batches
;disbursement_id
: related to disbursements;cas_supplier_id
: related to the active supplier ID at the time of the batch creation;invoice_number
: varchar(40), generated during the time of the batch creation;invoice_status
:Pending
,Sent
,Manual intervention
cas_invoice_details
id
: serial;cas_invoice_id
: related tocas_invoices
;cas_distribution_account_id
: related tocas_distribution_accounts
.value_amount
: numeric(8, 2)cas_distribution_accounts
ìd
: serial;award_value_code
: varchar(10);operation_code
: CR or DRis_active
: booleanaward_value_code
,operation_code
, andis_active
as true.The text was updated successfully, but these errors were encountered: