Last active
January 1, 2017 06:16
-
-
Save chrisza4/8e23db06136ba46ae4e50ea7232037b0 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 InvoiceDepartmentX { | |
| private bool isForXDepartment; // ไม่จำเป็น เพราะเป็น X เสมอ | |
| private bool isForYDepartment; // ไม่จำเป็น เพราะเป็น X เสมอ | |
| 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 InvoiceDepartmentX(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.0; | |
| if (this.isForXDepartment) { // ไม่จำเป็นต้องใช้ IF แล้ว เพราะเป็น X เสมอ | |
| price = this.calculateSumPriceForDepartmentX(); | |
| } | |
| else if (this.isForYDepartment) { // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| price = this.calculateSumPriceForDepartmentY(); // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| } // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| else { // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| price = this.calculateSumPriceForNormalCase(); // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| } // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 27 เสมอ | |
| if (this.isCalculateVat) { | |
| price = this.plusVat(price); | |
| } | |
| else if (this.isCalculateSpecialTax) { | |
| if (this.isForXDepartment) { | |
| price = this.plusVat(price) * 1.03; | |
| } // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 41 เสมอ | |
| else { // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 41 เสมอ | |
| price = this.plusVat(price) * 1.05; // ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 41 เสมอ | |
| }// ไม่จำเป็นต้องใช้อันนี้ เพราะมันจะเข้าบรรทัดที่ 41 เสมอ | |
| } | |
| return price; | |
| } | |
| private double calculateSumPriceForDepartmentX () { | |
| // สำหรับแผนกนี้ เราซื้อขายโปรเจ๊กต์ เลยใช้ Quote ราคารวม ไม่ต้องสนใจราคาต่อหน่วย | |
| // ราคาต่อหน่วย (pricePerUnit) เลยเป็นราคาที่ใช้ได้เลย ไม่ต้องคูณ Quantity | |
| return items.sum(d => d.pricePerUnit); | |
| } | |
| // ********* Method ข้างล่างนี้ไม่จำเป็นอีกแล้ว ************* | |
| private double calculateSumPriceForDepartmentY () { | |
| // สำหรับแผนกนี้ การซื้อขายเราจะจ่ายมัดจำไปแล้ว 20% ดังนั้นราคารวมจะเหลือแค่ 80% | |
| return this.calculateSumPriceForNormalCase() * 0.8; | |
| } | |
| 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