Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GASで在庫管理をサクッと実装した話
Search
tekihei2317
October 08, 2021
720
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
340
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Scaling GitHub
holman
464
140k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
530
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
270
Speed Design
sergeychernyshev
33
1.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Agile that works and the tools we love
rasmusluckow
331
22k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
Product Roadmaps are Hard
iamctodd
55
12k
Unsuck your backbone
ammeep
672
58k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
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