Although discounts are available on bills, it can be a bit of a chore filling this in on every bill.
For those that use this feature a lot, a custom function to automate it is attached below ....
⦁ A custom field is required in contacts for the discount amount, as a percentage.
⦁ Enter the name you choose for this custom field here in the code below.
⦁ You also need to get or set up a discount account if chart of accounts & get the id for it.
⦁ Enter this id here in the code below.
⦁ Enter your organization id here in the code below.
⦁ Create a new custom function for bills & paste the code below, after changing the placeholders below.
⦁ Create a new workflow for the bills module, event based | Created & copy | Immediate actions: Custom functions - name as you named your custom function above.
⦁ You then need to edit the vendor & enter the discount amount, as a percentage into the vendor custom field you created for any vendors you want this to work with.
orgId = "your organization id here";
nett = bill.get("sub_total");
id = bill.get("vendor_id");
billId = bill.get("bill_id");
vendorX = zoho.books.getRecordsByID("contacts",orgId,id);
vendor = vendorX.get("contact");
cf = vendor.get("custom_fields");
percent = "none";
for each line in cf
{
if(line.containsValue("your custom field name here"))
{
percent = line.get("value");
}
}
if(percent != "none" && percent != null)
{
nett = toDecimal(nett);
discP = toDecimal(percent);
disc = 100 - discP;
discount = nett
* discP / 100;
discountAmount = discount.round(2);
new_values = Map();
new_values.put("discount_account_id","your discount account id here");
new_values.put("discount_amount",discountAmount);
new_values.put("discount",discountAmount);
response = zoho.books.updateRecord("bills",orgId,billId,new_values);
}