Change Order of Billing Lines
I have looked through the knowledge base and prior posts, but does anyone know a way to change the order of the billing lines in an invoice?
We create our invoices by importing time in our projects, but when 30-50 billing lines import, they are sometimes imported in an order that doesn't make perfect sense. I'd love to be able to reorder the billing lines in the invoice without having to delete everything, but I can't find an easy way to do it.
-
Actually, I'd like to be able to manually change the order for particular billing lines. We have it sorted by date, but with multiple entries on one date, it sometimes makes more sense to have one line before the other.
For example, we might have:
9/11/18 - Did some work according to the requests made in the call.
9/11/18 - Spoke to Client.
I'd like to be able to manually move up the second one to be before the first one, because they clearly had the phone call first.
-
Hi Vivian,
One way to do this is to add a number field to the billing line and add that as a column in your upload file so that number 1 is the first billing line, number 2 is the second and so on. You will want to go into the PDF formats tab and select the format that you are using the enter this new custom number field into the sort field so that the system will sort on it.
Thank you,
Ryan
-
Using Ryan's suggestion above, this is the code I'm now using to populate my new custom Sort Order field:
//constructor to get the billing, billing line, and shift records
public BillingLinesSyncWithShiftsController(ApexPages.StandardController controller) {
bill = (AcctSeed__Billing__c) controller.getRecord();
billId = bill.Id;
category = bill.Category__c;
customerId = bill.AcctSeed__Customer__c;
clientId = customerId.left(15);
cycleStartDate = bill.AcctSeed__Billing_Cycle_Start_Date__c;
cycleEndDate = bill.AcctSeed__Billing_Cycle_End_Date__c;
billableShifts = [SELECT Id, Billing_Line__c, sirenum__Shift_Date__c, sirenum__Contact__c, sirenum__Employee_Name__c,
Actual_Length__c, Bill_Rate__c, Comments_formatted__c FROM sirenum__Shift__c
WHERE sirenum__Client_ID__c =: clientId AND sirenum__Allow_charge__c = true AND
sirenum__Shift_Date__c >=: cycleStartDate AND sirenum__Shift_Date__c <=: cycleEndDate AND
(sirenum__Rota__r.Name =: category OR sirenum__Team__r.sirenum__Rota__r.Name =: category)
ORDER BY sirenum__Shift_Date__c, Bill_Rate__c DESC, sirenum__Employee_Name__c];
billingLines = [SELECT Id FROM AcctSeed__Billing_Line__c WHERE AcctSeed__Billing__c =: billId];
billingLinesToDelete = [SELECT Id FROM AcctSeed__Billing_Line__c
WHERE AcctSeed__Billing__c =: billId AND (Allow_Charge__c = false OR Shift__r.sirenum__Client_ID__c !=: clientId)];
}
//method called from the Visualforce page action
public PageReference syncWithShifts() {
for (sirenum__Shift__c billableShift : billableShifts) {
if (billableShift.Billing_Line__c == null) {
AcctSeed__Billing_Line__c billingLineToInsert = new AcctSeed__Billing_Line__c (
AcctSeed__Billing__c = billId,
Shift__c = billableShift.Id,
AcctSeed__Date__c = billableShift.sirenum__Shift_Date__c,
Health_Professional__c = billableShift.sirenum__Contact__c,
AcctSeed__Hours_Units__c = billableShift.Actual_Length__c,
AcctSeed__Rate__c = billableShift.Bill_Rate__c,
AcctSeed__Comment__c = billableShift.Comments_formatted__c,
Sort_Order__c = i++
);
billingLinesToUpsert.add(billingLineToInsert);
} else if (billableShift.Billing_Line__c != null) {
AcctSeed__Billing_Line__c billingLineToUpdate= new AcctSeed__Billing_Line__c (
Id = billableShift.Billing_Line__c,
AcctSeed__Billing__c = billId,
Shift__c = billableShift.Id,
AcctSeed__Date__c = billableShift.sirenum__Shift_Date__c,
Health_Professional__c = billableShift.sirenum__Contact__c,
AcctSeed__Hours_Units__c = billableShift.Actual_Length__c,
AcctSeed__Rate__c = billableShift.Bill_Rate__c,
AcctSeed__Comment__c = billableShift.Comments_formatted__c,
Sort_Order__c = i++
);
billingLinesToUpsert.add(billingLineToUpdate);
}
}
if (!billingLinesToUpsert.isEmpty()) {
upsert billingLinesToUpsert;
}
if (!billingLinesToDelete.isEmpty()) {
delete billingLinesToDelete;
}
//return to the billing record
PageReference pageRef = new PageReference('/'+billId);
aura.redirect(pageRef);
return pageRef;
}
Please sign in to leave a comment.
Comments
4 comments