Managely – Create Customer Bill Tos

When importing data from Alarm Biller to Managely, you will need to use the script below to insert default bill records.

 

if not exists (select * from aCustomerBillTo) 

 

begin 

 

insert into aCustomerBillTo 

 

(CustomerId, IsBusiness, FirstName, LastName, Address1, Address2, Phone1, Phone1Ext, 

 

CellPhone, Email, City, [State], ZipCode, Plus4, ModifyUserId, Inactive, CreatedUserId, ModifyDate, CreatedDate) 

 

select CustomerId, IsBusiness, FirstName, LastName, Address1, Address2, Phone1, Phone1Ext, 

 

CellPhone, Email, City, [State], Zipcode, Plus4, ModifyUserId, Inactive, CreatedUserId, GETDATE(), GETDATE() 

 

from aCustomer 

 

where PrimaryBillToId is null 

 

 

 

 

update aCustomer set PrimaryBillToId=bt.Id 

 

from aCustomer ac 

 

inner join aCustomerBillTo bt on ac.CustomerId=bt.CustomerId 

 

where ac.PrimaryBillToId is null 

 

end 

 

 

 

 

 

PRINT 'Begin Converting aCustomer BillTo Defaults' 

 

 

 

 

PRINT ' Primary' 

 

 

 

 

INSERT INTO aCustomerBillToDefault 

 

(BillToId, CustomerId, Type, ModifyUserId, Inactive, CreatedDate, ModifyDate, CreatedUserId) 

 

SELECT PrimaryBillToId, CustomerId, 1, ModifyUserId, 0, GETUTCDATE(), GETUTCDATE(), ModifyUserId 

 

FROM aCustomer 

 

WHERE PrimaryBillToId IS NOT NULL 

 

 

 

 

PRINT ' Invoice' 

 

 

 

 

INSERT INTO aCustomerBillToDefault 

 

(BillToId, CustomerId, Type, ModifyUserId, Inactive, CreatedDate, ModifyDate, CreatedUserId) 

 

SELECT InvoiceDefaultBillToId, CustomerId, 2, ModifyUserId, 0, GETUTCDATE(), GETUTCDATE(), ModifyUserId 

 

FROM aCustomer 

 

WHERE InvoiceDefaultBillToId IS NOT NULL 

 

 

 

 

PRINT ' RMR' 

 

 

 

 

INSERT INTO aCustomerBillToDefault 

 

(BillToId, CustomerId, Type, ModifyUserId, Inactive, CreatedDate, ModifyDate, CreatedUserId) 

 

SELECT RMRDefaultBillToId, CustomerId, 3, ModifyUserId, 0, GETUTCDATE(), GETUTCDATE(), ModifyUserId 

 

FROM aCustomer 

 

WHERE RMRDefaultBillToId IS NOT NULL 

 

 

 

 

PRINT ' Cleanup' 

 

 

 

 

UPDATE c 

 

SET PrimaryBillToId = NULL, 

 

InvoiceDefaultBillToId = NULL, 

 

RMRDefaultBillToId = NULL 

 

FROM aCustomer c 

 

WHERE PrimaryBillToId IS NOT NULL 

 

OR InvoiceDefaultBillToId IS NOT NULL 

 

OR RMRDefaultBillToId IS NOT NULL 

 

 

 

 

PRINT 'End Converting aCustomer BillTo Defaults' 

 

 

 

 

 

 

Was this article helpful?
Thank you for your feedback!
User Icon

Thank you! Your comment has been submitted for approval.