Need help with a couple of custom scripts

Hey guys I need to add some custom scripting and am very new to javascript so hoping someone could help me with it. First of all I need to take the Sales Invoice Date and calculate the last day of the following month and populate the payment_due_date with that value. So far I have my logic as:

var calcduedate = myDateVar.getMonth()
myDateVar.setMonth(calcduedate + 1)

Just need some assistance on the replace command and to have it occur onsave so:

frappe.ui.form.on('Sales Invoice', 'save', function(calcduedate){

Secondly I want to trigger to send an email when a Sales Order meets the following criteria:

  1. workflow_state = “Complete” and
  2. ship_by = “Pickup”

But not sure where to start with this one. Any assistance would be appreciated, thanks.

You can send the email via Email Alert


frappe.ui.form.on('Sales Invoice', 'validate', function(frm) { 
  frm.doc.datevar = ...;

Thanks @rmehta I totally forgot about built in email alerts! We go live tomorrow so the nerves are affecting my memory :smile:

Thanks so much for the suggestion on payment date too.

I haven’t forgotten about writing an implementation story either just a bit busy prior to tomorrow excitement!