Last active
January 1, 2017 06:38
-
-
Save chrisza4/c8d879485372c09cb591ccc3b58f2eab 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 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; // ตัดทิ้งได้ เป็น False แน่นอน | |
| this.isCalculateSpecialTax = isCalculateSpecialTax; | |
| } | |
| public double calculateSumPrice () { | |
| var price = 0.0; | |
| if (this.isForXDepartment) { // ตัดทิ้งได้ | |
| price = this.calculateSumPriceForDepartmentX(); | |
| } | |
| else if (this.isForYDepartment) { // ไม่ต้องเช็ค IF แล้ว เพราะเป็น True แน่ๆ | |
| price = this.calculateSumPriceForDepartmentY(); | |
| } | |
| else { // ตัดทิ้งได้ ไม่ลงมาที่นี่แน่นอน | |
| price = this.calculateSumPriceForNormalCase(); | |
| } | |
| if (this.isCalculateVat) { // ตัดทิ้งตรงนี้ได้เพราะ isCalculateVat เป็น False แน่ๆ | |
| price = this.plusVat(price); | |
| } | |
| else if (this.isCalculateSpecialTax) { | |
| // ตัดทิ้งได้ เพราะเป็น False แน่ๆ สำหรับเคส Department Y | |
| if (this.isForXDepartment) { | |
| price = this.plusVat(price) * 1.03; | |
| } | |
| else { | |
| price = this.plusVat(price) * 1.05; | |
| } | |
| } | |
| return price; | |
| } | |
| // ตัดทิ้งได้ ไม่ใช้ Method นี้แน่ๆ | |
| private double calculateSumPriceForDepartmentX () { | |
| // สำหรับแผนกนี้ เราซื้อขายโปรเจ๊กต์ เลยใช้ Quote ราคารวม ไม่ต้องสนใจราคาต่อหน่วย | |
| // ราคาต่อหน่วย (pricePerUnit) เลยเป็นราคาที่ใช้ได้เลย ไม่ต้องคูณ Quantity | |
| return items.sum(d => d.pricePerUnit); | |
| } | |
| private double calculateSumPriceForDepartmentY () { | |
| // สำหรับแผนกนี้ การซื้อขายเราจะจ่ายมัดจำไปแล้ว 20% ดังนั้นราคารวมจะเหลือแค่ 80% | |
| return this.calculateSumPriceForNormalCase() * 0.8; | |
| } | |
| // ตัดทิ้งได้แน่นอน แต่ต้องเอาโค้ดไปรวมไว้ใน CalculateSumPriceForDepartmentY | |
| private double calculateSumPriceForNormalCase () { | |
| return items.sum(d => d.quantity * d.pricePerUnit); | |
| } | |
| private double plusVat (double price) { | |
| return price * 1.07; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment