zenityx's picture
Update app.py
4e8182e verified
import streamlit as st
st.title("โปรแกรมคำนวณราคาสินค้า (VAT 7% และหัก ณ ที่จ่าย 3% จากเงินต้น)")
st.markdown(
"""
โปรแกรมนี้ช่วยคำนวณราคาสินค้าโดยใช้สูตร:
- **VAT 7%:** คำนวณจาก Base Price
- **หัก ณ ที่จ่าย 3%:** คำนวณจาก Base Price
- **ยอดสุทธิที่ได้รับ:** Base Price + VAT - Withholding Tax
ซึ่งสามารถเขียนเป็นสมการได้ว่า:
**Net Amount = Base Price × 1.04**
คุณสามารถเลือกกรอกข้อมูลที่คุณทราบได้จาก 3 ตัวเลือก แล้วระบบจะคำนวณตัวเลขที่เหลือให้โดยอัตโนมัติ
"""
)
# ให้ผู้ใช้เลือกประเภทของจำนวนเงินที่ต้องการกรอก
calc_option = st.radio(
"เลือกประเภทของจำนวนเงินที่คุณต้องการกรอก:",
("ราคาก่อน VAT (Base Price)", "ราคาสินค้ารวม VAT (Invoice Price)", "ยอดสุทธิที่ได้รับ (Net Amount)")
)
# รับค่าจำนวนเงินจากผู้ใช้
amount = st.number_input("กรอกจำนวนเงิน:", min_value=0.0, format="%.2f")
if amount:
if calc_option == "ราคาก่อน VAT (Base Price)":
base_price = amount
vat = base_price * 0.07
withholding_tax = base_price * 0.03
invoice_price = base_price + vat
net_amount = base_price + vat - withholding_tax
elif calc_option == "ราคาสินค้ารวม VAT (Invoice Price)":
# จาก Invoice Price เราได้ว่า: Invoice Price = Base Price + VAT = Base Price * 1.07
base_price = amount / 1.07
vat = base_price * 0.07
withholding_tax = base_price * 0.03
net_amount = base_price + vat - withholding_tax
invoice_price = amount
elif calc_option == "ยอดสุทธิที่ได้รับ (Net Amount)":
# จาก Net Amount = Base Price × 1.04 => Base Price = Net Amount / 1.04
base_price = amount / 1.04
vat = base_price * 0.07
withholding_tax = base_price * 0.03
invoice_price = base_price + vat
net_amount = amount
st.subheader("ผลลัพธ์:")
st.write(f"**ราคาก่อน VAT (Base Price):** {base_price:,.2f} บาท")
st.write(f"**VAT (7%):** {vat:,.2f} บาท")
st.write(f"**ยอดสินค้ารวม VAT (Invoice Price):** {invoice_price:,.2f} บาท")
st.write(f"**หัก ณ ที่จ่าย (3% จาก Base Price):** {withholding_tax:,.2f} บาท")
st.write(f"**ยอดสุทธิที่ได้รับ (Net Amount):** {net_amount:,.2f} บาท")