Automated bill discounts

Automated bill discounts

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);
}





                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation
                                    • Topic Participants

                                    • terry



                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now