Giter Club home page Giter Club logo

fishfry-google-square's Introduction

StMM Fish Fry - Google Sheets & Square

To be added here: CI status

Prerequisites

  • git - code repository
  • nodejs - used for build system
  • clasp - used to develop Google Apps locally

Square Maintenance

Add SQUARE_ACCESS_TOKEN

In order to sync with Square, you'll need the SQUARE_ACCESS_TOKEN for the respective storefront.

TODO:

Setup webhooks on Square

TODO:

Google Apps Maintenance

Main Google Documents

Setup webhooks on Google Apps

TODO:

How to edit Google Sheet scripts locally

If you want to make a copy, this should work (without being connected to square).

  1. Clone the Git repository:
    git clone https://github.com/kofc7186/fishfry-google-square.git
    cd fishfry-google-square
    npm install @google/clasp -g
  2. Make a copy of Master Fish Fry Sheet
  3. In the new copy that was just created:
    • select "File/Project Properties"
      • Under info tab, there is a field "script ID"
      • Copy the "script ID" to your clipboard
  4. Edit the .clasp.json in the root directory of the repo with the value you copied in the previous step
  5. Install the NodeJS package from the git repo:
    npm install
  6. Authenticate and authorize clasp to manipulate the project with the google account that has access to the new copy:
    clasp login
    This launches a browser and asks you to login via oauth.
  7. Enable Apps Script API by visiting Apps Script API and toggle Google Apps Script API to ON.
  8. Modify files locally, then push/pull the changes between your desktop and Google Apps
    • clasp push will push the code on your local machine to the Google App
    • clasp pull will pull the code from Google App to your local machine

API Documentation

The hosted JSDoc files can be found here.

To generate updated documentation:

TODO:

Google Apps JavaScript Classes

These are classes used to interact with the Google infrastructure.

  • Logger
    • used to write out text to the debugging logs
  • PropertiesService
    • Allows scripts to store simple data in key-value pairs scoped to one script, one user of a script, or one document in which an add-on is used.
    • Used to retrieve the SQUARE_ACCESS_TOKEN attribute to communicate with Square
  • HtmlService
    • Service for returning HTML and other text content from a script.
    • Used to render HTML forms for user input
    • Used to render response to websocket from Square
  • UrlFetchApp
    • Fetch resources and communicate with other hosts over the Internet.
    • Used to make RESTful calls to Square
  • SpreadsheetApp
    • This class allows users to open Google Sheets files and to create new ones.
    • Used to manipulate the main Google Sheet
  • DocumentApp
    • The document service creates and opens Documents that can be edited.
    • Used to retrieve the Print template, create new document based on data from Sheet
  • LockService
    • Prevents concurrent access to sections of code.
    • Used to retrive atomic human interpretable order number (i.e. auto-increment)
  • Utilities
    • This service provides utilities for string encoding/decoding, date formatting, JSON manipulation, and other miscellaneous tasks.
    • Used for date/time formatting

Source Code

└── src
    ├── FormatOrder.js - used to take input from Square API and format it to insert into Google Sheets
    ├── Worksheet.js - manipulation to the Worksheet Transactions
    ├── doPost.js - webhook callback for Square
    ├── html - form templates
    ├── menuItems.js - objects for items customers may order, and what ingredients are contained within each order
    ├── orm.js - helper functions to manipulate the Google Sheet and Workbooks within
    ├── printLabels.js - generate label from an order, as well as send the label to the printer spool
    ├── simulateSquare.js - testing helper to simulate data from Square
    ├── squareAPI.js - simulate responses from Square's RESTful APIs (used in test only) 
    └── triggers.js - JavaScript trigger functions (i.e. entry point for Google Sheets)

fishfry-google-square's People

Contributors

bobcallaway avatar szelenka-cisco avatar szelenka avatar marschneatcisco avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

osgirl

fishfry-google-square's Issues

Add lastname filter on "Cashier Station"

  1. text form to search spreadsheet (pivot table)
  2. update filter on spreadsheet (pivot table)
  3. when advancing state, clear filter on spreadsheet
  4. have button to reset filter in event of no advancing state

sometimes SquareAPI transactionMetadata responses are incomplete

Sometimes, we have observed that initial calls to the v2 square transaction API does not return the customer ID in the nested tender object. That results in not being able to fetch the customer's name and the name in the spreadsheet row ends up as empty (this isn't ideal...)

we perhaps need to poll that API with some sort of sleep/backoff as we may be seeing replication effects of whatever persistence store Square is using.

display cash amount of transaction in transaction log

to help cashiers view what the order number is, they can currently correlate the last name and total meal count to find the order number. If we added the total transaction amounts ($), that would potentially be helpful.

incorporate pagination into loggedUrlFetch

While most of our Square API calls fetch single objects (or data sorted so that we only care about the first element in the response), as a failsafe we have added support to poll the Square API to find transactions for which we did not process a webhook. Since we are likely to have > 100 orders in one evening, there is a risk that we would not fetch all orders in a single API call.

Therefore, we need to support the pagination API for when we are polling the Square v1 Payment endpoint.

https://docs.connect.squareup.com/api/connect/v1#pagination

request to print "fried fish" and "fried shrimp" in lieu of "hand breaded" on labels

Danny Lynch asked me @ Mass this morning if we could stop using the "HB" or "Hand breaded" wording on the labels placed on each Styrofoam container. These terms apparently confuse people working on the delivery lines and using the "fried" moniker would be a better approach.

I think we should leave the menu as "Hand Breaded" but print "Fried".

set onEdit trigger to regenerate label file if any relevant spreadsheets edits are made

in the "worst" case, one of the "admins" will want to make manual edits in the spreadsheet to override errors, etc.

Some of those edits (customer name, meal notes) may need to be reflected in the label document.... we need to add an onEdit trigger to scan the range of cells under edit, and if any cells in relevant columns are touched, we need to regenerate the label doc.

Multi-meal label printing

On some labels (take 3-meal order #2503), the first meal label was fine, but the second showed the order ID line for both the second meal as well as for the 3rd meal (e.g. order "2 of 3" and "3 of 3").
The actual generated google docs file for this order looks good; however, there seems to be a problem handling the page break from the google doc when sending to cloud print.

You will note in the google doc for the order that the first label, after the “Fried Combo” text, has two blank lines; while the second label (after "Grilled Cheese” has only one. In the doc, if I just press enter on the line after Grilled Cheese, the label prints fine (even though the doc looks no different), so I think the simple workaround would be to always do the appendParagraph for line5 (the comment), even if it’s just some blank text. Kludgey, but it should get things printing as expected.

E.g. in FormatLabel.gs, just go with:

  var comments = "  ";
  if (notes[mealCount - 1].length > 0) {
    comments = notes[mealCount - 1]

  var line5 = body
      .appendParagraph(comments)

manual width on HTML panels is too small

It'd be nice to be able to allow the user to scale these, or have it rendered at 25-50% of the display screen it's being rendered on. It seems the setWidth only accepts integers though, so we'd need to find a way to discover the browsers width at runtime.

Short term fix may be to simply increase the px int passed into this function. It would also be nice to have an object variable to define the width in one location, then have each page read the value from there, rather than having to edit it manually in multiple function calls.

.setWidth(300);

Schema Proposal

Likely a 'future state' where this could evolve to, after Lent 2018.

It'd be nice to have a consistent repository for some of the values used throughout the code. Is there a decent ORM like SQLAlchemy for JavaScript in the browser or GAS?

Or would it make sense to have different "worksheets" in the Google Sheet for these types of tables, which we could reference in the code?

EnumOrderStates:

pkid key value

possible values

  • Order Submitted
  • Payment Processed
  • Physically Present
  • Expedite
  • Labeled
  • Ready
  • Closed

EnumIngredients:

pkid key value

possible values

  • Fish
  • Shrimp
  • Clam Chowder
  • Potatoes
  • Mac & Cheese
  • Coleslaw
  • Grilled Cheese

EnumServingTypes

pkid key value

possible values

  • Meal
  • Side
  • Soup

MenuItem

pkid display fk_serving_type list_price

possible values

  • Baked Fish
  • Fried Fish
  • etc.

MenuItemIngredients

pkid fk_menu_item fk_ingredient quantity

Customers

pkid last_name square_id

Order

pkid fk_customer special_note receipt_url created_at

OrderItems

This would be used to determine the number of labels to print, which is currently a count of the number of "meals". Although if someone just orders a side, it should be on it's own label?

pkid fk_order

OrderItemsInventory

pkid fk_order_items fk_menu_item quantity

OrderState

Having the data in this format would allow us to do some interesting analytics on the state changes for each order, and let us use the data to help optimize execution in future years.

fk_order fk_order_state timestamp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.