Sales/Invoice.cs
author Markus Bröker<broeker.markus@googlemail.com>
Wed, 29 Mar 2017 12:48:46 +0200
changeset 2 0907765a8b2e
parent 1 80c685d55d63
permissions -rwxr-xr-x
Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     1
/**
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     2
 * Invoice.cs
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
     3
 * 
2
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     4
 * The MIT License (MIT)
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     5
 *
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     6
 * @copyright Copyright(C) 2017 4Customers UG
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     7
 * @author    Markus Bröker<broeker.markus@googlemail.com>
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     8
 *
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
     9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    10
 * of this software and associated documentation files (the "Software"), to deal
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    11
 * in the Software without restriction, including without limitation the rights
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    13
 * copies of the Software, and to permit persons to whom the Software is
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    14
 * furnished to do so, subject to the following conditions:
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    15
 *
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    16
 * The above copyright notice and this permission notice shall be included in all
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    17
 * copies or substantial portions of the Software.
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    18
 *
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0907765a8b2e Visual Studio / Xamarin Studio Lizenzbedingungen beachten
Markus Bröker<broeker.markus@googlemail.com>
parents: 1
diff changeset
    25
 * SOFTWARE.
0
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    26
 */
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    27
using System;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    28
using System.Collections.Generic;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    29
using System.Linq;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    30
using System.Text;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    31
using System.Threading.Tasks;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    32
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    33
using static Sales.Payment;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    34
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    35
namespace Sales
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    36
{
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    37
    delegate double InvoiceDelegate();
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    38
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    39
    class Invoice
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    40
    {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    41
        private double value = 0;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    42
        private PaymentType till;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    43
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    44
        public Invoice(double value, PaymentType till)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    45
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    46
            this.value = value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    47
            this.till = till;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    48
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    49
            InvoiceDelegate invoiceDelegateReference = this.Rabatt;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    50
            invoiceDelegateReference += this.AddTax;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    51
            invoiceDelegateReference += this.Skonto;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    52
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    53
            invoiceDelegateReference();
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    54
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    55
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    56
        public double getFinalResult()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    57
        {            
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    58
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    59
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    60
1
80c685d55d63 Sinnvolles Beispiel für Function-Pointer in C#
Markus Bröker<broeker.markus@googlemail.com>
parents: 0
diff changeset
    61
        // Rabatt auf den Netto Preis
0
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    62
        private double Rabatt()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    63
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    64
            if (value > 1000.0)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    65
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    66
                value *= 0.75;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    67
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    68
            else if (value > 500.0)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    69
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    70
                value *= 0.85;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    71
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    72
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    73
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    74
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    75
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    76
        // Steuern auf den rabattierten Nettopreis
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    77
        private double AddTax()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    78
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    79
            value *= 1.19;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    80
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    81
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    82
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    83
        // Skonto immer zum Schluss
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    84
        private double Skonto()
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    85
        {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    86
            switch (till)
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    87
            {
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    88
                case PaymentType.NOW:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    89
                    value *= 0.97;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    90
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    91
                case PaymentType.WEEK:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    92
                    value *= 0.98;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    93
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    94
                case PaymentType.MONTH:
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    95
                    value *= 0.99;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    96
                    break;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    97
            }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    98
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
    99
            return value;
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
   100
        }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
   101
    }
cfa10fbf52b3 Initialer Commit
Markus Bröker<mbroeker@4customers.de>
parents:
diff changeset
   102
}