{"id":6747,"date":"2019-01-28T13:53:18","date_gmt":"2019-01-28T13:53:18","guid":{"rendered":"https:\/\/itnigblog.live-website.com\/?p=6747"},"modified":"2020-07-21T11:56:11","modified_gmt":"2020-07-21T11:56:11","slug":"ski-trip-spreadsheet-scripting","status":"publish","type":"post","link":"https:\/\/itnig.net\/blog\/ski-trip-spreadsheet-scripting\/","title":{"rendered":"Ski Trip Spreadsheet Scripting"},"content":{"rendered":"<p>We have been organizing Itnig ski trips since the beginning. I remember we could fit in a car when we started, then in a pickup van, we later had to rent a couple of cars to be able to go, soon we had to share a bus with other people and now we need an entire bus for us.<\/p>\n<p><!--more--><\/p>\n<h2>Getting people to join<\/h2>\n<p>Once you have a date and a location, you can create a form with all the available options and share it via email, Slack, or whatever. We used to create it using Google Forms because it integrated with Google Spreadsheets and was easy to use, but now we use Typeform. It\u2019s beautiful and now also integrates with Spreadsheets.<\/p>\n<h2>Calculating each individual price<\/h2>\n<p>Our ski trip has a lot of variabilities. One individual might want to rent gear while another one already owns it. Some individuals might want to snowboard and others might want to rent the highest quality skis available. Some need classes and some want insurance. Some people don\u2019t even want to ski, but just spend the weekend in the snow.<br \/>\nThis results in a situation where almost everyone has a unique price and although it was easy to calculate and handle when we were 5, it gets harder when you are 50.<br \/>\nYou could perform a 200 character long nested IFS function to calculate the price for every row in the Spreadsheet, but it\u2019s easier to just code your own more readable and maintainable Google Script function.<br \/>\nFrom the \u2018Tool\u2019 menu you can access the \u2018Script Editor\u2019 and there you have a lot of freedom to write your own functions.<br \/>\nI coded the \u2018skiPrice\u2019 function to calculate the final price for every possible combination, depending on the arguments the function received. Once coded, you can call the function as if it was a normal Spreadsheet function, sending cells as parameters.<\/p>\n<figure><figcaption>The \u2018skiPrice\u2019 function calculates the final price<\/figcaption><\/figure>\n<h2>Sharing the info with the agency<\/h2>\n<p>Once you have all this information available you have to share it with the agency so they can check all prices are correct and to generate the insurance policies for the people who are paying for them. You could copy and paste or export the document but the best option is to share the live spreadsheet so they always see updated information. You could share with them the whole spreadsheet as \u201cread-only\u201d but you might have information or sheets you don\u2019t want to share with them.<br \/>\nThe best approach is to create an \u2018Agency\u2019 sheet in the same spreadsheet, with all the information you want to share with the agency. Then create a new Spreadsheet and in the first row write:<\/p>\n<pre>=IMPORTRANGE(\"https:\/\/docs.google.com\/spreadsheets\/d\/[YOUR_SPREADSHEET_ID]\/edit\";\"Agency!A1:J60\")<\/pre>\n<p>This will create a new Spreadsheet with only the sheet you want to show the agency, so you can now share it. Whenever you update the original Spreadsheet this mirror sheet will conveniently keep up to date.<\/p>\n<h2>Send custom payment emails from Spreadsheets<\/h2>\n<p>Once again this is a task that I could afford to do manually when we were fewer people but now doesn\u2019t scale. Using the power of the Google Scripts I generate the corpus of the email, containing the options each user selected.<br \/>\n<em>In the actual Spreadsheet I calculate the total price and generate the email corpus in one function call and a single iteration, but it\u2019s easie<\/em>r to explain it separately.<br \/>\nThe function \u2018mailText\u2019 generates a custom email corpus showing the user the options he chose and showing the total amount to pay. The function takes all options as parameters.<\/p>\n<p>Once the email corpus is generated, a final script runs directly from the script editor iterates through every row in the Spreadsheet and sends an email to each user containing the custom corpus.<br \/>\nAnd every user gets the email in their inbox.<\/p>\n<h2>Conclusion<\/h2>\n<p>The powerful combination of Typeform, Google Spreadsheets, and Google Scripts is great, but after organizing ski trips for years I see a clear next step. A modern ski agency app that would let companies and individuals organize their custom ski trips adjusting every detail to their budgets and keeping all the information, communication, and payment processes in one place. Considering there are more than 6M skiers only in Spain we are looking at an interesting market.<br \/>\nHow does <strong>Skitnig<\/strong> sound for a new startup name?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have been organizing Itnig ski trips since the beginning. I remember we could fit in a car when we started, then in a pickup van, we later had to rent a couple of cars to be able to go, soon we had to share a bus with other people and now we need an [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":6748,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-6747","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/posts\/6747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/comments?post=6747"}],"version-history":[{"count":14,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/posts\/6747\/revisions"}],"predecessor-version":[{"id":10195,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/posts\/6747\/revisions\/10195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itnig.net\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/media?parent=6747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/categories?post=6747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnig.net\/blog\/wp-json\/wp\/v2\/tags?post=6747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}