Last active
January 1, 2017 05:56
-
-
Save chrisza4/92bdfd203748ebb271bc26d3b5d73403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Invoice { | |
| private bool isForXDepartment; | |
| private bool isForYDepartment; | |
| private bool isCalculateVat; | |
| private bool isCalculateSpecialTax; | |
| private double departmentYBudgetRatio; | |
| private List<InvoiceItem> items; | |
| public class InvoiceItem { | |
| public int quantity; | |
| public string description; | |
| public double pricePerUnit; | |
| } | |
| public Invoice(bool isForXDepartment, bool isForYDepartment, bool isCalculateVat, bool isCalculateSpecialTax, double departmentYBudgetRatio) { | |
| this.isForXDepartment = isForXDepartment; | |
| this.isForYDepartment = isForYDepartment; | |
| this.isCalculateVat = isForXDepartment; | |
| this.isCalculateSpecialTax = isCalculateSpecialTax; | |
| this.departmentYBudgetRatio = departmentYBudgetRatio; | |
| } | |
| public double calculateSumPrice () { | |
| var price = 0; | |
| if (this.isForXDepartment) { | |
| price = this.calculateSumPriceForDepartmentX(); | |
| } | |
| else if (this.isForYDepartment) { | |
| price = this.calculateSumPriceForDepartmentY(); | |
| } | |
| else { | |
| price = this.calculateSumPriceForNormalCase(); | |
| } | |
| if (this.isCalculateVat) { | |
| price = this.plusVat(price) | |
| } | |
| else if (this.isCalculateSpecialTax) { | |
| if (this.isForXDepartment) { | |
| price = this.plusVat(price) * 1.03 | |
| } | |
| else { | |
| price = this.plusVat(price) * 1.05 | |
| } | |
| } | |
| return price; | |
| } | |
| private double calculateSumPriceForDepartmentX () { | |
| // สำหรับแผนกนี้ เราซื้อขายโปรเจ๊กต์ เลยใช้ Quote ราคารวม ไม่ต้องสนใจราคาต่อหน่วย | |
| // ราคาต่อหน่วย (pricePerUnit) เลยเป็นราคาที่ใช้ได้เลย ไม่ต้องคูณ Quantity | |
| return items.sum(d => d.pricePerUnit) | |
| } | |
| private double calculateSumPriceForDepartmentY () { | |
| // สำหรับแผนกนี้ การซื้อขายเราจะจ่ายมัดจำไปแล้ว 20% ดังนั้นราคารวมจะเหลือแค่ 80% | |
| return this.calculateSumPriceForNormalCase() * 0.8 | |
| } | |
| private double calculateSumPriceForNormalCase () { | |
| return items.sum(d => d.quantity * d.pricePerUnit) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment