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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Side Projects
sachag
455
43k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
260
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Deep Space Network (abreviated)
tonyrice
0
250
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
480
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
930
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
200
Prompt Engineering for Job Search
mfonobong
0
400
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