The below script will generate invoices for PayHub (Payment Hub; Pay Hub) for demos, etc.
--------------------------------------------------
-- Invoices Generator for PayHub Demos -----------
--------------------------------------------------
-- Usage:
-- Step1. Declare the starting value for CustomKeys
-- Step2. Declare the BillingContactID to set the invoices to
-- Step3. Declare the ShippingContactID to set the invoices to
-- Step4. Declare the UserID to set the invoices to
-- Step5. Declare the AccountID to set the invoices to
-- Step6. Tell Ron to say thank you
---------------------------------------------------
DECLARE @i INT = 0;
DECLARE @baseKey INT = # -- !!! Step1: Set the starting value for the CustomKeys in the format of INV-XXXX
DECLARE @currentDateTime DATETIME = GETDATE(); -- Using the current date and time
WHILE @i < 100
BEGIN
SET @baseKey = @baseKey + 1;
INSERT INTO Invoicing.SalesInvoice (
CustomKey, CreatedDate, Active, SubtotalItems, SubtotalShipping,
SubtotalTaxes, SubtotalFees, SubtotalHandling, SubtotalDiscounts,
Total, ShippingSameAsBilling, StatusID, StateID, TypeID,
BillingContactID, ShippingContactID, UserID, AccountID, BalanceDue
)
VALUES (
'INV-' + CAST(@baseKey AS NVARCHAR(10)), -- Incrementing CustomKey
@currentDateTime,
1,
ROUND((RAND() * (1500 - 700) + 700), 2), -- Random subtotal items between 700 and 1500
ROUND((RAND() * (200 - 50) + 50), 2), -- Random subtotal shipping between 50 and 200
0.00, 0.00, 0.00,
ROUND((RAND() * (100 - 50) + 50), 2), -- Random subtotal discounts between 50 and 100
ROUND((RAND() * (2000 - 900) + 900), 2), -- Random total between 900 and 2000
1, 1, 1, 1,
#, -- !!! Step2: Set a BillingContactID to associate invoices to
#, -- !!! Step3: Set a ShippingContactID to associate invoices to
#, -- !!! Step4: Set a UserID to associate invoices to
#, -- !!! Step5: Set an AccountID to associate invoices to
ROUND((RAND() * (2000 - 900) + 900), 2) -- Random balance due, same range as total
);
SET @i = @i + 1;
END