Formatting Script For Automated Email in Google Spreadsheets - google-sheets

I am a restaurant owner trying to automate the creation of a message to my employees using google spreadsheets.
I have this:
=E2&CHAR(10)&CHAR(10)&"Here are your tip numbers:"&CHAR(10)&CHAR(10)&"Cash Tips: "&I2&" Credit Card Tips: "&J2&" Form 4070's are due in the office by 4pm Wednesday and they are required by law from every tipped employee. Thank you. -- Management Team"
Here are the cell values:
E2 = "Ron"
I2 = "19"
J2 = "25"
Currently, it looks like this:
Ron
Here are your tip numbers:
Cash Tips 19 Credit Card Tips: 25 Form 4070's are due in the office by 4pm Wednesday and they are required by law from every tipped employee. Thank you. -- Management Team
But I would like it to be formatted like this:
Ron,
Here are your tip numbers:
Cash Tips: $19
Credit Card Tips: $25
Form 4070's are due in the office by 4pm Wednesday and they are required by law from every tipped employee.
Thank you.
-- Management Team
Can anyone help an old guy out who has zero experience doing this?
So, I am looking for:
A comma after "Ron"
"Cash Tips:" in BOLD letters
"Credit Card Tips:" in BOLD letters
A "$" sign before the number in the I2 and J2 fields
Lines skipped as noted above.

Partial formatting, for the bold, is unavailable at this time.
This takes care of the rest though:
=E2&","&CHAR(10)&CHAR(10)&"Here are your tip numbers:"&CHAR(10)&CHAR(10)&"Cash Tips: "&"$"&I2&CHAR(10)&CHAR(10)&"Credit Card Tips: "&"$"&J2&CHAR(10)&CHAR(10)&"Form 4070's are due in the office by 4pm Wednesday and they are required by law from every tipped employee."&CHAR(10)&CHAR(10)&"Thank you."&CHAR(10)&CHAR(10)&"-- Management Team"
Update to accommodate the rounding of currency values to 2 decimal places:
=E2&","&CHAR(10)&CHAR(10)&"Here are your tip numbers:"&CHAR(10)&CHAR(10)&"Cash Tips: "&"$"&ROUND(I2, 2)&CHAR(10)&CHAR(10)&"Credit Card Tips: "&"$"&ROUND(J2, 2)&CHAR(10)&CHAR(10)&"Form 4070's are due in the office by 4pm Wednesday and they are required by law from every tipped employee."&CHAR(10)&CHAR(10)&"Thank you."&CHAR(10)&CHAR(10)&"-- Management Team"

Related

Can i create a sum using a key? Absence tracker

I’ve been tasked with creating an absence tracker that will monitor holidays and sickness - I have created the basic layout and a key which determines holiday = H half day morning =Hd1 absence = A etc ...
So the premise is obviously if employee 1 is on holiday you would enter H in the relevant date cell, off sock you would enter A.
What I’m struggling with is the correct formula to add them up each month so absence will be separate and not so much of an issue, but say they have Monday on holiday, and Tuesday as a morning on holiday and then they’re off on compassionate leave on Friday at the end of the month there would be 3 days authorised leave, I’m confused how I put that in a formula.
Try something like this, using countif formula:
=countif(D$6:D$34,$C2)
My solution is available here:
https://docs.google.com/spreadsheets/d/1_oCCsuvseJUqrjWgjDKesON9CSFLZTXxQvYAG8T5Cwk/copy

Commission calculation based on sliding month (googlesheets)

I have to pay a commission to Agents (affiliates) based on the following conditions:
the commission starts on a monthly basis following a USER (linked to the Agent) first deposit/purchase on a website
agents have a decreasing commission, ex: 1 month following first deposit of their USER = 30% of sales, 2d month period following 1st deposit of USER: 25% of sales, etc
Commission are paid on a month basis calculation (ex: from 01/07/2020 till 31/07/2020)
If a USER makes a first purchase on June 22d and if sales commission for 1st period is 30%, then agent is eligible to a 30% commission on sales from june 22d till July 22d, then 25% for sales from 23rd july till 23rd august, etc
I have designed a googlesheets (see below) that serves the purpose (using 12 columns to get the correct commission% for a specific user on a specific day!), but I am trying to find a more straight forward formula to get the applicable com. % based on the commission sliding table and the first deposit date of a specific user.
Can anyone help?
The google sheets showing my calc is here:
https://docs.google.com/spreadsheets/d/1I1gzZ670hJH8HwCGizzbvlQkg0dgAvgOSQTfOUL0VgU/edit?usp=sharing
This might help you. (Updated to correct the row number of where the formula should go.)
If you insert a new column in your sheet, to the right of Column W, the Current Commision Month, and paste the following formula in the cell where the Current Commision Month header text should appear (Row 9 in your sample) of that column, it replicates the results in your Current Commision Month.
But it does not require columns I through V. You can test that by deleting columns I through V - you can use Undo and Redo to go back and forth, if necessary. Depending on how you use your "End" column - the logic wasn't clear to me - the info for that can also be gained in this one column.
={"Current
Commision
Month";"";ArrayFormula(
if(
($H11:H<>"") * ($A11:A>=date(year(H11:H),month(H11:H),day(H11:H))),
ifs( $A11:A< date(year(H11:H),month(H11:H)+1,day(H11:H)),1,
$A11:A< date(year(H11:H),month(H11:H)+2,day(H11:H)),2,
$A11:A< date(year(H11:H),month(H11:H)+3,day(H11:H)),3,
$A11:A< date(year(H11:H),month(H11:H)+4,day(H11:H)),4,
$A11:A< date(year(H11:H),month(H11:H)+5,day(H11:H)),5,
$A11:A< date(year(H11:H),month(H11:H)+6,day(H11:H)),6,
$A11:A>=date(year(H11:H),month(H11:H)+7,day(H11:H)),9999),
""))}
The first IF test is to check that the FirstDeposit date is not blank, and that the sale date is greater than or equal to the FirstDeposit date.
The IFS tests go through and check whether the sale date is less than one of the months, and stops at the first value (commission month) that is greater than the sale date. If never, it places a vlaue of 9999.
Note that the "9999" values are just to indicate the sale date is greater than the "End" date, and can be changed to blanks or whatever you want.
[![enter image description here][1]][1]
I've added a sample tab with the final result. Let me know if this helps. There may be several other enhancements possible for your sheet, in particular the use of ARRAYFORMULAS to fill values down many of your columns.
I haven't spent time on the actual commision calculations, in the final columns, but if you feel that still needs improvements, I can try to simplify there as well.
[1]: https://i.stack.imgur.com/TfFZ5.png

String.removingPercentEncoding returns nil on particularly large strings

I am building an application that shows events that are near to the user. Some of these events are scraped from the web, and some are posted to my backend from users of the app. The ones that have been posted to the backend by users are returned with a description string property that is URL percent encoded (this has to do with storing emojis in my SQL database, and is a whole other story).
When the events are pulled from my API, some events will have percent encoding while others will not. Typically, when using String.removingPercentEncoding on a string that isn't encoded, nothing in the string changes.
Example:
let example = "This is an example text"
let decodedExample = example.removingPercentEncoding!
print(decodedExample)
The above code returns This is an example text.
Now, with particularly long event description strings that do not have percent encoding, we use the same method and expect that it would just return the same string. What I am finding however, is that calling .removingPercentEncoding on one of these very long strings is actually returning nil. The string in the following example has 3,123 characters.
Example:
print("Encoded event description: ", event.description!)
print("Decoded event description: ", self.event.description.removingPercentEncoding ?? "Decoding failed")
The above code returns:
Encoded event description: The Experience:\nThe Pavel Barber Hockey School is coming to St. Louis May 17th - 19th, 2019! Join head instructor Pavel Barber, a world renown stickhandling and shootout specialist, and friends for an experience that will challenge these young athletes to get better and encourage mental and physical skill development in a fun and creative environment. \nThe Features:\n\n\n4 Hours On-Ice Skill Development: 1 Hour Friday, 2 Hours Saturday, 1 Hour Sunday\n\n\n4 Hours Off-Ice Skill Development w/ Our Floorball+ HKY Training Program: 1 Hour Friday, 2 Hours Saturday, 1 Hour Sunday\n\n\n1 Personal Growth Group Session Saturday and Sunday\n\n\nScrimmage Game on Sunday\n\n\nPavel Barber Jersey and Socks Included\n\n\nLunch Included Saturday and Sunday\n\n\n \nThe Schedule:Friday, May 17th, 2019 - Day 1 - 5:30 pm - 8 pmSaturday, May 18th, 2019 - Day 2 - 7:30 am - 2 pmSunday, May 19th, 2019 - Day 3 - 7:30 am - 12:30 pm*Times and location subject to change. \n \nOther School Info:\n\n\nSpace is limited and will be filled on a first come, first serve basis\n\n\nAge groups include 7-10 year olds, 11-12 year olds, 13-15 year olds\n\n\nSkill Level Requirements - Kids should be proficient in the basics of hockey before attending the school\n\n\nRefund Policy: Refunds will only be allowed 30 days prior to the start of the school. All refunds are subject to a 20% cancellation fee.\n\n\nThis is not an overnight camp. All kids will need to be picked up and dropped off daily.\n\n\nPlease send your child with the following items each day of the school: workout clothes (such as shorts, t-shirt and gym shoes) for the off-ice sessions and sunscreen as there will be some outdoor activity. Water will be available for the players for all on-ice and off-ice training sessions.\n\n\nPavel Barber and Floorball Merch will be available at the school as well, but we recommend adding to your order now to ensure sizing and product availability\n\n\n \nAbout Pavel Barber:Pavel Barber has quickly emerged as one of the most sought after stick handling and skill development insturctors in the world. He is an internet hockey legend for his incredible hands, creative shootout moves and dangles and his skill development work. His YouTube channel has over 23 MILLION views on it and growing. Barber specializes in stick handling, shoout moves and creative skill development for both hockey and floorball. In fact, he is obsessed with it. He has studied talent generation across all fields and enjoys passing on that knowledge and training hockey players of all ages and skill levels.\nIn 2016, Barber was selected to the Team Canada National Floorball team that competed in Riga at the World Floorball Championships. \nBarber is a GoPro sponsored athlete and has played Indoor Hockey and Field Hockey for Team Canada between 2010 and 2015.\nOriginally from Toronto, Barber currently resides in Vancouver (or anywhere he can have a stick and puck/ball in his hands).\n\nPrice: $350 – $450\n\nFor more info, click here: https://www.eventbrite.com/e/pavel-barber-hockey-school-st-louis-registration-46948450078?aff=ebdssbdestsearch
Decoded event description: Decoding failed
Any idea why String.removingPercentEncoding works on typically lengthed strings, but returns nil on very large strings (3,000+ characters)?
I have tried some millions times with random String of length far more than 3,000, and cannot reproduce the same issue.
Your event.description! has a non-escaped percent symbol, which is the reason removingPercentEncoding fails.
...to a 20% cancellation...
The length of the string is irrelevant.
Generally, removingPercentEncoding fails when the original String contains non-escaped percent symbols.
You can check it easily:
let str = "20%"
print(str.removingPercentEncoding ?? "*fail*") //->*fail*
If the original string may contain percent symbols, always applying removingPercentEncoding would not be a good strategy.

Google Sheets Formula For Wage Calculation

We are trying to work out a formula for paying our sales team. Basically they get paid a basic wage of £350 regardless of making any sales as a "safety net" or 40% of sales done up to £2000 (whichever is greater). So for example, £1000 sales = £400 commission, £500 sales = £350 commissions.
Essentially the £350 is there incase sales fall below £875 they are guaranteed to still get the £350.
It gets a little tricky for me when sales go over £2000 anything OVER £2000 they get 50% on. So for example £3000 sales they would get £800 on the first £2000 and £500 on the £1000 over the £2000. So total wages for that week would be £1,300. Some examples below:
Sales: £500 Pay = £350
Sales: £900 Pay = £360
Sales: £1500 Pay = £600
Sales: £2500 Pay = £1,050
Sales: £4000 Pay = £1,800
Is there a formula I can use if i have the sales total of the sales agent, to calculate there wage automatically.
Any help would be greatly appreciated.
This is a fairly short way of doing it
=MAX(350,0.4*A1+0.1*text(A1-2000,"0;\0"))
Otherwise perhaps more simply
=if(A1<875,350,if(A1<2000,A1*0.4,800+(A1-2000)*0.5))
Which can be simplified to
=IF(A1<875,350,IF(A1<2000,A1*0.4,0.5*A1-200))

issue with yql (yahoo api's) using oauth

i am using oauth_util.rb ( https://gist.github.com/383159 ) and my YQL query is
"select * from search.termextract where context=\"#{text}\""
This works where text is a short string, but fails for the longer ones with the following error:
RuntimeError (Please provide valid credentials. OAuth oauth_problem="signature_invalid", realm="yahooapis.com" for text [ Virdhawal Khade Wins Historic Medal | Sports News Bangalore November 16, 2010 -19-year-old Indian swimmer and GoSports Foundation awardee, Virdhawal Khade, has made history at the Guangzhou Games by clinching the Bronze Medal in the Men's 50m Butterfly event. ... Starting the Finals in fifth place, Veer's performance was nothing short of astonishing, as he finished with his season best time of 24.31 seconds. He finished 0.65 seconds shy of first placed 27-year-old Zhou Jiawei, the top ranked Chinese Swimmer who is also ... ]):
Thanx in advance.
got it... needed to use URI.encode to encode the URI instead of CGI::escape

Resources