Invoice invoice = new Invoice(session);
// initialize a blank invoice that we can populate
await invoice.Load(-1);
// create a new invoice datarow
DataRow invoiceRow = invoice.InvoiceTable.NewRow();
// set the desired column values for the new invoice datarow
// grab the next available invoice number
invoiceRow[Invoice.Field_Invoice_InvoiceNumber] = await invoice.GetNextInvoiceNumber(Invoice.Literal_InvoiceType_Sale, 0);
invoiceRow[Invoice.Field_Invoice_InvoiceType_LinkCode] = Invoice.Literal_InvoiceType_Sale;
invoiceRow[Invoice.Field_Invoice_IssueDate] = DateTime.Today;
invoiceRow[Invoice.Field_Invoice_Client_LinkNo] = 4;
invoiceRow[Invoice.Field_Invoice_Branch_LinkNo] = 0;
invoiceRow[Invoice.Field_Invoice_RecordLocator] = "ABCDEF";
// add the new invoice datarow to the invoice table
invoice.InvoiceTable.Rows.Add(invoiceRow);
// create a new booking datarow; booking is a child table of invoice
DataRow bookingRow = invoice.BookingTable.NewRow();
// set the desired column values for the new booking datarow
bookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier;
bookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 2;
bookingRow[Invoice.Field_Booking_ConfirmNo] = "ABC123";
// associate the booking datarow with the invoice datarow
bookingRow[Invoice.Field_Booking_Invoice_LinkNo] = invoiceRow[Invoice.Field_Invoice_InvoiceNo];
// add the new booking datarow to the booking table
invoice.BookingTable.Rows.Add(bookingRow);
// create a new booking datarow; booking is a child table of invoice
bookingRow = invoice.BookingTable.NewRow();
// set the desired column values for the new booking datarow
bookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier;
bookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 3;
bookingRow[Invoice.Field_Booking_ConfirmNo] = "DEF456";
// associate the booking datarow with the invoice datarow
bookingRow[Invoice.Field_Booking_Invoice_LinkNo] = invoiceRow[Invoice.Field_Invoice_InvoiceNo];
// add the new booking datarow to the booking table
invoice.BookingTable.Rows.Add(bookingRow);
// create a new segment datarow; segment is a child table of booking
DataRow segmentRow = invoice.SegmentTable.NewRow();
// set the desired column values for the new segment datarow
segmentRow[Invoice.Field_Segment_IndexNo] = 1;
// associate the segment datarow with the booking datarow
segmentRow[Invoice.Field_Segment_Booking_LinkNo] = bookingRow[Invoice.Field_Booking_BookingNo];
// add the new segment datarow to the segment table
invoice.SegmentTable.Rows.Add(segmentRow);
// save the invoice
await invoice.Save();