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
740
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
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.7k
4 Signs Your Business is Dying
shpigford
187
23k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Faster Mobile Websites
deanohume
310
32k
Darren the Foodie - Storyboard
khoart
PRO
4
4.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
430
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
520
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
520
Mobile First: as difficult as doing things right
swwweet
225
10k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
So, you think you're a good person
axbom
PRO
2
2.2k
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