Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
GASで在庫管理をサクッと実装した話
Search
tekihei2317
October 08, 2021
730
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GASで在庫管理をサクッと実装した話
tekihei2317
October 08, 2021
More Decks by tekihei2317
See All by tekihei2317
Metabaseで個人ダッシュボードを作成する
tekihei2317
0
360
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Building Adaptive Systems
keathley
44
3.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Everyday Curiosity
cassininazir
0
350
Deep Space Network (abreviated)
tonyrice
0
370
Git: the NoSQL Database
bkeepers
PRO
433
67k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
780
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
270
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Odyssey Design
rkendrick25
PRO
2
870
Transcript
GAS で在庫管理をサクッと実装した話 by @tekihei2317
目次 1. ある日のこと 2. Google App Script (GAS )とはなにか 3.
先入先出法について 4. 作ったプログラム 5. clasp でローカルでGAS を書く 6. まとめ by @tekihei2317
ある日のこと 上長「在庫管理したいんだけど、スプレッドシートでこれ出来る?」 上長「先入先出法っていうのがあって... 」 ぼく「なるほど... 」 ~~ 30 分後 ~~
ぼく「スプレッドシートだと難しいと思います!」 ぼく「プログラムを書きたくなるやつですね」 by @tekihei2317
ある日のこと(続き) ~~ その日の夜 ~~ ぼく「あ!そういえばGAS があったわ!作っちゃお!!」 ~~ 翌日の朝 ~~ ぼく「なんかできた!!」
by @tekihei2317
できたもの by @tekihei2317
先入先出法とは 先に仕入れた商品から先に販売したと仮定して、棚卸資産(在庫の価 値)を計算する方法。 例) りんごを300 円×30 個、500 円×20 個、400 円×40
個の順に仕入れる 棚卸資産は、 20 個販売したとき 300×10+500×20+400×40 = 29000 円 40 個販売したとき 500×10+400×40 = 21000 円 by @tekihei2317
Google App Script ( GAS )とは Google のサービスと連携したアプリケーションを作るためのプラッ トフォーム Gmail
、Google Drive 、Google Calender 、etc... JavaScript で書ける! 処理系がChrome と同じV8 エンジン by @tekihei2317
作ったプログラム(入力) 在庫の個数と価値のペアをシートから読み込む const makeStocks = (lastRowIndex) => { const stocks
= []; for(let i = OFFSET_ROW; i <= lastRowIndex; i++){ const count = sheet.getRange(i, OFFSET_COL).getValue(); if (count > 0) { const price = sheet.getRange(i, OFFSET_COL + 1).getValue(); stocks.push({ count, price }); } } return stocks; }; by @tekihei2317
作ったプログラム(計算) 在庫と引き出した個数の累計から、引き出した在庫の価値を求める > const stocks = [ ... { price:
300, count: 3 }, ... { price: 500, count: 2 }, ... { price: 400, count: 3 }, ... ]; > const consumedCounts = [0, 0, 0, 2, 4, 5, 8]; > let calcConsumedPriceSum; > import("./src/lib/calcConsumedPriceSum.js").then((module) => calcConsumedPriceSum = module.default); > calcConsumedPriceSum(stocks, consumedCounts); [ 0, 0, 0, 600, 1400, 1900, 3100 ] by @tekihei2317
作ったプログラム(出力) 計算した値をセルに出力する const setPriceSum = (priceSumList) => { priceSumList.forEach((priceSum, index)
=> { sheet.getRange(OFFSET_ROW + 1 + index, CONSUMED_COUNT_COL + 1).setValue(priceSum); }); } by @tekihei2317
作ったプログラム(トリガーの設定) セルを変更したときに計算を実行する const onEdit = () => { const lastRowIndex
= calcLastRowIndex(); const stocks = makeStocks(lastRowIndex); const priceSumList = calcResult(stocks, lastRowIndex); setPriceSum(priceSumList); clearPriceSum(priceSumList.length); }; by @tekihei2317
clasp でローカルで GAS を書く clasp を使うと、スクリプトをローカルで書いてpush/pull できる clasp push が少し時間がかかる
今回のリポジトリ https://github.com/tekihei2317/gas-inventory-management by @tekihei2317
まとめ GAS はJS で書けるので便利! by @tekihei2317
参考サイト GAS (Google Apps Script )入門|エクセルの神髄 GAS のGoogle 謹製CLI ツール
clasp - Qiita by @tekihei2317