File size: 2,212 Bytes
64d42fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Calculate Profit from CSV</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.min.css">
    <style>
        body {
            padding: 2rem;
        }
        .container {
            max-width: 600px;
            margin: auto;
        }
        .output {
            margin-top: 2rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Calculate Profit from CSV</h1>
        <form id="upload-form">
            <label for="file">Choose CSV file:</label>
            <input type="file" id="file" name="file" accept=".csv" required>
            <button type="submit" class="button-primary">Upload</button>
        </form>
        <div class="output" id="output"></div>
    </div>

    <script>
        document.getElementById('upload-form').addEventListener('submit', function(event) {
            event.preventDefault();
            var formData = new FormData();
            var fileField = document.querySelector("input[type='file']");
            formData.append('file', fileField.files[0]);

            fetch('/calculate_profit_csv', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                const outputDiv = document.getElementById('output');
                outputDiv.innerHTML = `
                    <h2>Profit Calculation Result</h2>
                    <p><strong>Initial Deposit Amount:</strong> ${data.jumlah_awal_deposit}</p>
                    <p><strong>Total Withdrawals:</strong> ${data.total_withdraw}</p>
                    <p><strong>Profit:</strong> ${data.profit}</p>
                    <p><strong>Profit Percentage:</strong> ${data.profit_percentage.toFixed(2)}%</p>
                `;
            })
            .catch(error => {
                const outputDiv = document.getElementById('output');
                outputDiv.innerHTML = `<p class="error">Error: ${error}</p>`;
            });
        });
    </script>
</body>
</html>