Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyamkung/3174618 to your computer and use it in GitHub Desktop.
Save tomoyamkung/3174618 to your computer and use it in GitHub Desktop.
Amazon マーケットプレイスで出品する商品の利益と利益率を計算するスクリプト
#! ruby
#-*- encoding: utf-8 -*-
require 'yaml'
class Calculator
def initialize(exec_file)
@yaml = YAML.load_file(get_yaml(exec_file))
end
def get_yaml(exec_file)
return exec_file.sub("rb", "yaml")
end
#計算式は次の通り
#出品価格-仕入価格-基本成約料-カテゴリ成約料-販売手数料-送料=利益
def execute(selling_price, cost_price)
sp = selling_price.to_i #出品価格
cp = cost_price.to_i #仕入価格
b = @yaml['basic'].to_i #基本成約料
c = @yaml['category'].to_i #カテゴリ成約料
f = @yaml['fee'].to_f * sp #販売手数料
t = @yaml['trans'].to_i #送料(メール便などの送料)
benefit = sp - cp - b - c - f - t
percent = sprintf("%.2f", benefit / (sp - cp) * 100)
puts("売上:#{sp - cp}円\t利益:#{benefit.to_i}円\t利益率:#{percent}%\t販売手数料:#{f.to_i}円")
end
end
if __FILE__ == $0
obj = Calculator.new(__FILE__)
obj.execute(ARGV[0], ARGV[1])
#ARGV[0]: 出品価格(お客さまが負担する送料250円も含めた金額)
#ARGV[1]: 仕入価格
end
basic: 100
category: 60
fee: 0.15
trans: 260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment