Kgshop commited on
Commit
e75543c
·
verified ·
1 Parent(s): bd28a2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +124 -148
app.py CHANGED
@@ -63,21 +63,13 @@ def download_db_from_hf(specific_file=None, retries=3, delay=5):
63
  try:
64
  if file_name == DATA_FILE:
65
  with open(file_name, 'w', encoding='utf-8') as f:
66
- json.dump({
67
- 'products': [],
68
- 'categories': [],
69
- 'orders': {},
70
- 'employees': [],
71
- 'workdays': {},
72
- 'fines': [],
73
- 'settings': {
74
- 'cafe_name': 'HongKong',
75
- 'wa_shift1': '+77470623684',
76
- 'wa_shift2': '+77470623684',
77
- 'active_shift': 1,
78
- 'logo_version': '1'
79
- }
80
- }, f)
81
  except Exception:
82
  pass
83
  success = False
@@ -188,9 +180,9 @@ def load_data():
188
 
189
  for emp in data['employees']:
190
  if 'pin' not in emp: emp['pin'] = '0000'
191
- if 'daily_rate' not in emp or emp['daily_rate'] == 0: emp['daily_rate'] = 230000
192
- if 'target_amount' not in emp or emp['target_amount'] == 0: emp['target_amount'] = 1500000
193
- if 'bonus_percentage' not in emp or emp['bonus_percentage'] == 0: emp['bonus_percentage'] = 10
194
 
195
  if not os.path.exists(DATA_FILE):
196
  try:
@@ -953,7 +945,7 @@ ORDER_TEMPLATE = '''
953
  <div class="totals-area">
954
  <div class="totals-row">
955
  <span>Итого:</span>
956
- <span>{{ order.total_price }}</span>
957
  </div>
958
  {% set discount = order.discount|default(0)|float %}
959
  {% if discount > 0 %}
@@ -1179,7 +1171,7 @@ SALARY_TEMPLATE = '''
1179
  <head>
1180
  <meta charset="UTF-8">
1181
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
1182
- <title>Отчет по ЗП</title>
1183
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
1184
  <style>
1185
  :root { --primary: #D4AF37; --bg: #000000; --surface: #111111; --border: #333333; --danger: #ff4757; --success: #2ed573; --info: #D4AF37; --warning: #ffa502; --text: #ffffff; --text-muted: #888888; }
@@ -1192,7 +1184,7 @@ SALARY_TEMPLATE = '''
1192
  .btn { padding: 12px 20px; border: none; border-radius: 10px; font-weight: 700; cursor: pointer; color: #000; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; font-size: 0.95rem; transition: opacity 0.2s; }
1193
  .btn:active { opacity: 0.8; }
1194
  .btn-success { background: var(--success); }
1195
- .btn-danger { background: var(--danger); color: #fff; }
1196
  .btn-dark { background: #1a1a1a; color: var(--primary); border: 1px solid var(--border); }
1197
 
1198
  .report-section { background: var(--surface); padding: 20px; border-radius: 16px; border: 1px solid var(--border); margin-bottom: 20px; }
@@ -1200,7 +1192,7 @@ SALARY_TEMPLATE = '''
1200
  .form-row { display: flex; gap: 10px; flex-wrap: wrap; }
1201
  .form-row > * { flex: 1; min-width: 150px; }
1202
  input[type="date"], input[type="number"], input[type="text"], select { width: 100%; padding: 12px 15px; border: 1px solid var(--border); border-radius: 10px; font-size: 0.95rem; outline: none; transition: border-color 0.2s; background: #1a1a1a; color: var(--text); }
1203
- input:focus, select:focus { border-color: var(--primary); background: #222; }
1204
  label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
1205
 
1206
  .rep-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
@@ -1221,6 +1213,64 @@ SALARY_TEMPLATE = '''
1221
  </div>
1222
 
1223
  <div class="report-section">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1224
  <div class="form-row" style="margin-bottom: 20px; align-items: flex-end;">
1225
  <div>
1226
  <label>Дата начала</label>
@@ -1236,44 +1286,6 @@ SALARY_TEMPLATE = '''
1236
  <table class="rep-table" id="tableSalary"></table>
1237
  </div>
1238
  </div>
1239
-
1240
- <div class="report-section">
1241
- <h2 style="color: var(--primary); margin-top: 0; margin-bottom: 15px;"><i class="fas fa-exclamation-triangle"></i> Добавить штраф</h2>
1242
- <form method="POST" action="/admin/salary" style="display:flex; flex-direction:column; gap:12px;">
1243
- <input type="hidden" name="action" value="add_fine">
1244
- <div class="form-row">
1245
- <div>
1246
- <label>Сотрудник</label>
1247
- <select name="employee_id" required>
1248
- <option value="">Выберите сотрудника</option>
1249
- {% for emp in employees %}
1250
- <option value="{{ emp.id }}">{{ emp.name }}</option>
1251
- {% endfor %}
1252
- </select>
1253
- </div>
1254
- <div>
1255
- <label>Сумма штрафа (сум)</label>
1256
- <input type="number" name="amount" placeholder="Например, 50000" required>
1257
- </div>
1258
- <div>
1259
- <label>Дата</label>
1260
- <input type="date" name="date" id="fineDate" required>
1261
- </div>
1262
- </div>
1263
- <div>
1264
- <label>Причина штрафа</label>
1265
- <input type="text" name="reason" placeholder="Причина..." required autocomplete="off">
1266
- </div>
1267
- <button type="submit" class="btn btn-danger" style="align-self: flex-start;"><i class="fas fa-plus"></i> Наложить штраф</button>
1268
- </form>
1269
- </div>
1270
-
1271
- <div class="report-section">
1272
- <h2 style="color: var(--primary); margin-top: 0; margin-bottom: 15px;"><i class="fas fa-list"></i> Список штрафов за период</h2>
1273
- <div style="overflow-x:auto;">
1274
- <table class="rep-table" id="tableFines"></table>
1275
- </div>
1276
- </div>
1277
  </div>
1278
 
1279
  <script>
@@ -1293,7 +1305,8 @@ SALARY_TEMPLATE = '''
1293
  const firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
1294
  document.getElementById('salStart').value = getLocalDateStr(firstDay);
1295
  document.getElementById('salEnd').value = todayStr;
1296
- document.getElementById('fineDate').value = todayStr;
 
1297
  generateSalaryReport();
1298
  }
1299
 
@@ -1302,7 +1315,7 @@ SALARY_TEMPLATE = '''
1302
  const end = document.getElementById('salEnd').value;
1303
  if (!start || !end) return;
1304
 
1305
- let html = '<tr><th>Сотрудник</th><th>Отработано дней</th><th>Фикс. ЗП</th><th>Бонусы (>1.5M)</th><th>Штрафы</th><th>Итого ЗП</th></tr>';
1306
 
1307
  let empSales = {};
1308
  allOrders.forEach(o => {
@@ -1313,19 +1326,12 @@ SALARY_TEMPLATE = '''
1313
  empSales[o.employee_id][oDate] += o.total_price;
1314
  }
1315
  });
1316
-
1317
- let empFines = {};
1318
- fines.forEach(f => {
1319
- if (f.date >= start && f.date <= end) {
1320
- if (!empFines[f.employee_id]) empFines[f.employee_id] = 0;
1321
- empFines[f.employee_id] += parseFloat(f.amount || 0);
1322
- }
1323
- });
1324
 
1325
  employees.forEach(emp => {
1326
  let daysWorked = 0;
1327
  let fixedSal = 0;
1328
  let bonusSal = 0;
 
1329
 
1330
  let currDate = new Date(start);
1331
  const endDate = new Date(end);
@@ -1333,72 +1339,45 @@ SALARY_TEMPLATE = '''
1333
  while(currDate <= endDate) {
1334
  const dateStr = getLocalDateStr(currDate);
1335
 
1336
- const worked = workdays[dateStr] && workdays[dateStr].includes(emp.id);
1337
  const dailySales = (empSales[emp.id] && empSales[emp.id][dateStr]) ? empSales[emp.id][dateStr] : 0;
1338
 
1339
- if (worked) {
1340
  daysWorked++;
1341
- fixedSal += parseFloat(emp.daily_rate || 230000);
1342
- }
1343
-
1344
- const target = parseFloat(emp.target_amount || 1500000);
1345
- const pct = parseFloat(emp.bonus_percentage || 10);
1346
-
1347
- if (pct > 0 && dailySales > target) {
1348
- bonusSal += (dailySales - target) * (pct / 100);
1349
  }
1350
-
1351
  currDate.setDate(currDate.getDate() + 1);
1352
  }
1353
-
1354
- const totalFines = empFines[emp.id] || 0;
 
 
 
 
 
1355
  const total = fixedSal + bonusSal - totalFines;
1356
-
1357
- if (daysWorked > 0 || total !== 0 || bonusSal > 0 || totalFines > 0) {
1358
  html += `<tr>
1359
  <td>${emp.name}</td>
1360
  <td>${daysWorked}</td>
1361
- <td>${fixedSal.toFixed(0)} ${currencyCode}</td>
1362
- <td>${bonusSal.toFixed(0)} ${currencyCode}</td>
1363
- <td style="color:var(--danger);">${totalFines.toFixed(0)} ${currencyCode}</td>
1364
- <td style="font-weight:bold; color:var(--success);">${total.toFixed(0)} ${currencyCode}</td>
1365
  </tr>`;
1366
  }
1367
  });
1368
 
1369
- document.getElementById('tableSalary').innerHTML = html;
1370
- renderFinesTable(start, end);
1371
- }
1372
-
1373
- function renderFinesTable(start, end) {
1374
- let html = '<tr><th>Дата</th><th>Сотрудник</th><th>Причина</th><th>Сумма</th><th>Действие</th></tr>';
1375
- let count = 0;
1376
-
1377
- fines.forEach(f => {
1378
- if (f.date >= start && f.date <= end) {
1379
- count++;
1380
- const emp = employees.find(e => e.id === f.employee_id);
1381
- const empName = emp ? emp.name : 'Удален';
1382
- html += `<tr>
1383
- <td>${f.date}</td>
1384
- <td>${empName}</td>
1385
- <td>${f.reason}</td>
1386
- <td style="color:var(--danger); font-weight:bold;">-${f.amount} ${currencyCode}</td>
1387
- <td>
1388
- <form method="POST" action="/admin/salary" style="margin:0;" onsubmit="return confirm('Удалить штраф?');">
1389
- <input type="hidden" name="action" value="delete_fine">
1390
- <input type="hidden" name="fine_id" value="${f.id}">
1391
- <button type="submit" class="btn btn-danger" style="padding:4px 8px; font-size:0.8rem;"><i class="fas fa-trash"></i></button>
1392
- </form>
1393
- </td>
1394
- </tr>`;
1395
- }
1396
- });
1397
-
1398
- if (count === 0) {
1399
- html += '<tr><td colspan="5">Штрафов за выбранный период нет</td></tr>';
1400
  }
1401
- document.getElementById('tableFines').innerHTML = html;
1402
  }
1403
 
1404
  window.onload = () => {
@@ -1550,7 +1529,7 @@ ADMIN_TEMPLATE = '''
1550
  <div style="flex:1; min-width:150px;"><label>Имя</label><input type="text" name="employee_name" required autocomplete="off"></div>
1551
  <div style="flex:1; min-width:100px;"><label>PIN (4 цифры)</label><input type="text" name="pin" pattern="\\d{4}" required autocomplete="off"></div>
1552
  <div style="flex:1; min-width:100px;"><label>Ставка за день</label><input type="number" name="daily_rate" value="230000" required></div>
1553
- <div style="flex:1; min-width:100px;"><label>Цель (план)</label><input type="number" name="target_amount" value="1500000" required></div>
1554
  <div style="flex:1; min-width:100px;"><label>Бонус (%)</label><input type="number" name="bonus_percentage" value="10" step="0.1" required></div>
1555
  <button type="submit" class="btn btn-dark" style="width:100%; margin-top:10px;"><i class="fas fa-plus"></i> Добавить</button>
1556
  </form>
@@ -1566,7 +1545,7 @@ ADMIN_TEMPLATE = '''
1566
  <div style="flex:1; min-width:150px;"><label>Имя</label><input type="text" name="name" value="{{ emp.name }}" required></div>
1567
  <div style="flex:1; min-width:100px;"><label>PIN</label><input type="text" name="pin" value="{{ emp.pin }}" pattern="\\d{4}" required></div>
1568
  <div style="flex:1; min-width:100px;"><label>Ставка</label><input type="number" name="daily_rate" value="{{ emp.daily_rate }}" required></div>
1569
- <div style="flex:1; min-width:100px;"><label>Цель (план)</label><input type="number" name="target_amount" value="{{ emp.target_amount }}" required></div>
1570
  <div style="flex:1; min-width:100px;"><label>Бонус %</label><input type="number" name="bonus_percentage" value="{{ emp.bonus_percentage }}" step="0.1" required></div>
1571
  <button type="submit" class="btn btn-primary" title="Сохранить"><i class="fas fa-save"></i></button>
1572
  </form>
@@ -1992,41 +1971,38 @@ def admin_salary():
1992
  action = request.form.get('action')
1993
  if action == 'add_fine':
1994
  emp_id = request.form.get('employee_id')
1995
- try: amount = float(request.form.get('amount', 0))
1996
- except: amount = 0
1997
- reason = request.form.get('reason', '').strip()
1998
- date_str = request.form.get('date', get_current_date())
1999
-
2000
- if emp_id and amount > 0:
2001
- fines = data.get('fines', [])
2002
- fines.append({
2003
- 'id': uuid4().hex,
2004
- 'employee_id': emp_id,
2005
- 'amount': amount,
2006
- 'reason': reason,
2007
- 'date': date_str
2008
- })
2009
- data['fines'] = fines
2010
- save_data(data)
2011
-
2012
  elif action == 'delete_fine':
2013
  fine_id = request.form.get('fine_id')
2014
  data['fines'] = [f for f in data.get('fines', []) if f.get('id') != fine_id]
2015
  save_data(data)
2016
-
2017
- return redirect(url_for('admin_salary'))
2018
 
2019
  orders = data.get('orders', {})
2020
  employees = data.get('employees', [])
2021
  workdays = data.get('workdays', {})
2022
  fines = data.get('fines', [])
2023
 
 
 
2024
  return render_template_string(
2025
  SALARY_TEMPLATE,
2026
  orders_json=json.dumps(list(orders.values())),
2027
  employees_json=json.dumps(employees),
2028
  workdays_json=json.dumps(workdays),
2029
  fines_json=json.dumps(fines),
 
2030
  employees=employees,
2031
  currency_code=CURRENCY_CODE
2032
  )
@@ -2056,11 +2032,11 @@ def admin():
2056
  elif action == 'add_employee':
2057
  emp_name = request.form.get('employee_name', '').strip()
2058
  pin = request.form.get('pin', '0000').strip()
2059
- try: daily_rate = float(request.form.get('daily_rate', 230000))
2060
  except: daily_rate = 230000
2061
- try: target_amount = float(request.form.get('target_amount', 1500000))
2062
  except: target_amount = 1500000
2063
- try: bonus_percentage = float(request.form.get('bonus_percentage', 10))
2064
  except: bonus_percentage = 10
2065
 
2066
  if emp_name:
@@ -2081,11 +2057,11 @@ def admin():
2081
  if e.get('id') == emp_id:
2082
  e['name'] = request.form.get('name', '').strip()
2083
  e['pin'] = request.form.get('pin', '0000').strip()
2084
- try: e['daily_rate'] = float(request.form.get('daily_rate', 230000))
2085
  except: e['daily_rate'] = 230000
2086
- try: e['target_amount'] = float(request.form.get('target_amount', 1500000))
2087
  except: e['target_amount'] = 1500000
2088
- try: e['bonus_percentage'] = float(request.form.get('bonus_percentage', 10))
2089
  except: e['bonus_percentage'] = 10
2090
  break
2091
  data['employees'] = employees
 
63
  try:
64
  if file_name == DATA_FILE:
65
  with open(file_name, 'w', encoding='utf-8') as f:
66
+ json.dump({'products': [], 'categories': [], 'orders': {}, 'employees': [], 'workdays': {}, 'fines': [], 'settings': {
67
+ 'cafe_name': 'HongKong',
68
+ 'wa_shift1': '+77470623684',
69
+ 'wa_shift2': '+77470623684',
70
+ 'active_shift': 1,
71
+ 'logo_version': '1'
72
+ }}, f)
 
 
 
 
 
 
 
 
73
  except Exception:
74
  pass
75
  success = False
 
180
 
181
  for emp in data['employees']:
182
  if 'pin' not in emp: emp['pin'] = '0000'
183
+ if 'daily_rate' not in emp: emp['daily_rate'] = 230000
184
+ if 'target_amount' not in emp: emp['target_amount'] = 1500000
185
+ if 'bonus_percentage' not in emp: emp['bonus_percentage'] = 10
186
 
187
  if not os.path.exists(DATA_FILE):
188
  try:
 
945
  <div class="totals-area">
946
  <div class="totals-row">
947
  <span>Итого:</span>
948
+ <span>{{ raw_total }}</span>
949
  </div>
950
  {% set discount = order.discount|default(0)|float %}
951
  {% if discount > 0 %}
 
1171
  <head>
1172
  <meta charset="UTF-8">
1173
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
1174
+ <title>Отчет по ЗП и Штрафам</title>
1175
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
1176
  <style>
1177
  :root { --primary: #D4AF37; --bg: #000000; --surface: #111111; --border: #333333; --danger: #ff4757; --success: #2ed573; --info: #D4AF37; --warning: #ffa502; --text: #ffffff; --text-muted: #888888; }
 
1184
  .btn { padding: 12px 20px; border: none; border-radius: 10px; font-weight: 700; cursor: pointer; color: #000; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; font-size: 0.95rem; transition: opacity 0.2s; }
1185
  .btn:active { opacity: 0.8; }
1186
  .btn-success { background: var(--success); }
1187
+ .btn-danger { background: var(--danger); }
1188
  .btn-dark { background: #1a1a1a; color: var(--primary); border: 1px solid var(--border); }
1189
 
1190
  .report-section { background: var(--surface); padding: 20px; border-radius: 16px; border: 1px solid var(--border); margin-bottom: 20px; }
 
1192
  .form-row { display: flex; gap: 10px; flex-wrap: wrap; }
1193
  .form-row > * { flex: 1; min-width: 150px; }
1194
  input[type="date"], input[type="number"], input[type="text"], select { width: 100%; padding: 12px 15px; border: 1px solid var(--border); border-radius: 10px; font-size: 0.95rem; outline: none; transition: border-color 0.2s; background: #1a1a1a; color: var(--text); }
1195
+ input[type="date"]:focus, input[type="number"]:focus, input[type="text"]:focus, select:focus { border-color: var(--primary); background: #222; }
1196
  label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
1197
 
1198
  .rep-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
 
1213
  </div>
1214
 
1215
  <div class="report-section">
1216
+ <h2 style="margin-top:0; color:var(--primary); font-size:1.2rem; margin-bottom: 15px;">Управление штрафами</h2>
1217
+ <form method="POST" style="display:flex; gap:10px; flex-wrap:wrap; align-items:flex-end;">
1218
+ <input type="hidden" name="action" value="add_fine">
1219
+ <div style="flex:1; min-width:150px;">
1220
+ <label>Сотрудник</label>
1221
+ <select name="employee_id" required>
1222
+ {% for emp in employees %}
1223
+ <option value="{{ emp.id }}">{{ emp.name }}</option>
1224
+ {% endfor %}
1225
+ </select>
1226
+ </div>
1227
+ <div style="flex:1; min-width:120px;">
1228
+ <label>Дата</label>
1229
+ <input type="date" name="date" required id="fineDate">
1230
+ </div>
1231
+ <div style="flex:1; min-width:120px;">
1232
+ <label>Сумма</label>
1233
+ <input type="number" name="amount" required step="1" min="0">
1234
+ </div>
1235
+ <div style="flex:2; min-width:150px;">
1236
+ <label>Причина</label>
1237
+ <input type="text" name="reason" required autocomplete="off">
1238
+ </div>
1239
+ <button type="submit" class="btn btn-danger" style="height:44px; color:#fff;"><i class="fas fa-plus"></i> Добавить штраф</button>
1240
+ </form>
1241
+
1242
+ <h3 style="margin-top:25px; margin-bottom:10px; font-size:1.1rem; color:var(--primary);">История штрафов</h3>
1243
+ <div style="overflow-x:auto;">
1244
+ <table class="rep-table">
1245
+ <tr><th>Сотрудник</th><th>Дата</th><th>Причина</th><th>Сумма</th><th>Действия</th></tr>
1246
+ {% for fine in fines %}
1247
+ <tr>
1248
+ <td>
1249
+ {% for emp in employees %}
1250
+ {% if emp.id == fine.employee_id %}{{ emp.name }}{% endif %}
1251
+ {% endfor %}
1252
+ </td>
1253
+ <td>{{ fine.date }}</td>
1254
+ <td>{{ fine.reason }}</td>
1255
+ <td style="color:var(--danger); font-weight:bold;">-{{ fine.amount }} {{ currency_code }}</td>
1256
+ <td>
1257
+ <form method="POST" style="margin:0;" onsubmit="return confirm('Удалить штраф?');">
1258
+ <input type="hidden" name="action" value="delete_fine">
1259
+ <input type="hidden" name="fine_id" value="{{ fine.id }}">
1260
+ <button type="submit" class="btn btn-dark" style="padding:5px 10px; border-color:var(--danger); color:var(--danger);"><i class="fas fa-trash"></i></button>
1261
+ </form>
1262
+ </td>
1263
+ </tr>
1264
+ {% endfor %}
1265
+ {% if not fines %}
1266
+ <tr><td colspan="5" style="text-align:center; padding:15px; color:var(--text-muted);">Нет штрафов</td></tr>
1267
+ {% endif %}
1268
+ </table>
1269
+ </div>
1270
+ </div>
1271
+
1272
+ <div class="report-section">
1273
+ <h2 style="margin-top:0; color:var(--primary); font-size:1.2rem; margin-bottom: 15px;">Генерация Зарплаты</h2>
1274
  <div class="form-row" style="margin-bottom: 20px; align-items: flex-end;">
1275
  <div>
1276
  <label>Дата начала</label>
 
1286
  <table class="rep-table" id="tableSalary"></table>
1287
  </div>
1288
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1289
  </div>
1290
 
1291
  <script>
 
1305
  const firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
1306
  document.getElementById('salStart').value = getLocalDateStr(firstDay);
1307
  document.getElementById('salEnd').value = todayStr;
1308
+ const fineDateInput = document.getElementById('fineDate');
1309
+ if(fineDateInput) { fineDateInput.value = todayStr; }
1310
  generateSalaryReport();
1311
  }
1312
 
 
1315
  const end = document.getElementById('salEnd').value;
1316
  if (!start || !end) return;
1317
 
1318
+ let html = '<tr><th>Сотрудник</th><th>Дней отработано</th><th>Фикс. ЗП</th><th>Бонусы с продаж</th><th>Штрафы</th><th>Итого ЗП</th></tr>';
1319
 
1320
  let empSales = {};
1321
  allOrders.forEach(o => {
 
1326
  empSales[o.employee_id][oDate] += o.total_price;
1327
  }
1328
  });
 
 
 
 
 
 
 
 
1329
 
1330
  employees.forEach(emp => {
1331
  let daysWorked = 0;
1332
  let fixedSal = 0;
1333
  let bonusSal = 0;
1334
+ let totalFines = 0;
1335
 
1336
  let currDate = new Date(start);
1337
  const endDate = new Date(end);
 
1339
  while(currDate <= endDate) {
1340
  const dateStr = getLocalDateStr(currDate);
1341
 
 
1342
  const dailySales = (empSales[emp.id] && empSales[emp.id][dateStr]) ? empSales[emp.id][dateStr] : 0;
1343
 
1344
+ if (dailySales > 0) {
1345
  daysWorked++;
1346
+ fixedSal += parseFloat(emp.daily_rate || 0);
1347
+
1348
+ const target = parseFloat(emp.target_amount || 0);
1349
+ const pct = parseFloat(emp.bonus_percentage || 0);
1350
+
1351
+ if (pct > 0 && dailySales > target) {
1352
+ bonusSal += (dailySales - target) * (pct / 100);
1353
+ }
1354
  }
 
1355
  currDate.setDate(currDate.getDate() + 1);
1356
  }
1357
+
1358
+ fines.forEach(f => {
1359
+ if (f.employee_id === emp.id && f.date >= start && f.date <= end) {
1360
+ totalFines += parseFloat(f.amount);
1361
+ }
1362
+ });
1363
+
1364
  const total = fixedSal + bonusSal - totalFines;
1365
+ if (daysWorked > 0 || total > 0 || totalFines > 0) {
 
1366
  html += `<tr>
1367
  <td>${emp.name}</td>
1368
  <td>${daysWorked}</td>
1369
+ <td>${fixedSal.toFixed(2)} ${currencyCode}</td>
1370
+ <td>${bonusSal.toFixed(2)} ${currencyCode}</td>
1371
+ <td style="color:var(--danger);">-${totalFines.toFixed(2)} ${currencyCode}</td>
1372
+ <td style="font-weight:bold; color:var(--success);">${total.toFixed(2)} ${currencyCode}</td>
1373
  </tr>`;
1374
  }
1375
  });
1376
 
1377
+ if (html === '<tr><th>Сотрудник</th><th>Дней отработано</th><th>Фикс. ЗП</th><th>Бонусы с продаж</th><th>Штрафы</th><th>Итого ЗП</th></tr>') {
1378
+ html += '<tr><td colspan="6">За выбранный период данных нет</td></tr>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1379
  }
1380
+ document.getElementById('tableSalary').innerHTML = html;
1381
  }
1382
 
1383
  window.onload = () => {
 
1529
  <div style="flex:1; min-width:150px;"><label>Имя</label><input type="text" name="employee_name" required autocomplete="off"></div>
1530
  <div style="flex:1; min-width:100px;"><label>PIN (4 цифры)</label><input type="text" name="pin" pattern="\\d{4}" required autocomplete="off"></div>
1531
  <div style="flex:1; min-width:100px;"><label>Ставка за день</label><input type="number" name="daily_rate" value="230000" required></div>
1532
+ <div style="flex:1; min-width:100px;"><label>Цель (n сумма)</label><input type="number" name="target_amount" value="1500000" required></div>
1533
  <div style="flex:1; min-width:100px;"><label>Бонус (%)</label><input type="number" name="bonus_percentage" value="10" step="0.1" required></div>
1534
  <button type="submit" class="btn btn-dark" style="width:100%; margin-top:10px;"><i class="fas fa-plus"></i> Добавить</button>
1535
  </form>
 
1545
  <div style="flex:1; min-width:150px;"><label>Имя</label><input type="text" name="name" value="{{ emp.name }}" required></div>
1546
  <div style="flex:1; min-width:100px;"><label>PIN</label><input type="text" name="pin" value="{{ emp.pin }}" pattern="\\d{4}" required></div>
1547
  <div style="flex:1; min-width:100px;"><label>Ставка</label><input type="number" name="daily_rate" value="{{ emp.daily_rate }}" required></div>
1548
+ <div style="flex:1; min-width:100px;"><label>Цель (n)</label><input type="number" name="target_amount" value="{{ emp.target_amount }}" required></div>
1549
  <div style="flex:1; min-width:100px;"><label>Бонус %</label><input type="number" name="bonus_percentage" value="{{ emp.bonus_percentage }}" step="0.1" required></div>
1550
  <button type="submit" class="btn btn-primary" title="Сохранить"><i class="fas fa-save"></i></button>
1551
  </form>
 
1971
  action = request.form.get('action')
1972
  if action == 'add_fine':
1973
  emp_id = request.form.get('employee_id')
1974
+ date_fine = request.form.get('date')
1975
+ amount = float(request.form.get('amount', 0))
1976
+ reason = request.form.get('reason', '')
1977
+ data.setdefault('fines', []).append({
1978
+ 'id': uuid4().hex,
1979
+ 'employee_id': emp_id,
1980
+ 'date': date_fine,
1981
+ 'amount': amount,
1982
+ 'reason': reason
1983
+ })
1984
+ save_data(data)
1985
+ return redirect(url_for('admin_salary'))
 
 
 
 
 
1986
  elif action == 'delete_fine':
1987
  fine_id = request.form.get('fine_id')
1988
  data['fines'] = [f for f in data.get('fines', []) if f.get('id') != fine_id]
1989
  save_data(data)
1990
+ return redirect(url_for('admin_salary'))
 
1991
 
1992
  orders = data.get('orders', {})
1993
  employees = data.get('employees', [])
1994
  workdays = data.get('workdays', {})
1995
  fines = data.get('fines', [])
1996
 
1997
+ fines = sorted(fines, key=lambda x: x.get('date', ''), reverse=True)
1998
+
1999
  return render_template_string(
2000
  SALARY_TEMPLATE,
2001
  orders_json=json.dumps(list(orders.values())),
2002
  employees_json=json.dumps(employees),
2003
  workdays_json=json.dumps(workdays),
2004
  fines_json=json.dumps(fines),
2005
+ fines=fines,
2006
  employees=employees,
2007
  currency_code=CURRENCY_CODE
2008
  )
 
2032
  elif action == 'add_employee':
2033
  emp_name = request.form.get('employee_name', '').strip()
2034
  pin = request.form.get('pin', '0000').strip()
2035
+ try: daily_rate = float(request.form.get('daily_rate', 0))
2036
  except: daily_rate = 230000
2037
+ try: target_amount = float(request.form.get('target_amount', 0))
2038
  except: target_amount = 1500000
2039
+ try: bonus_percentage = float(request.form.get('bonus_percentage', 0))
2040
  except: bonus_percentage = 10
2041
 
2042
  if emp_name:
 
2057
  if e.get('id') == emp_id:
2058
  e['name'] = request.form.get('name', '').strip()
2059
  e['pin'] = request.form.get('pin', '0000').strip()
2060
+ try: e['daily_rate'] = float(request.form.get('daily_rate', 0))
2061
  except: e['daily_rate'] = 230000
2062
+ try: e['target_amount'] = float(request.form.get('target_amount', 0))
2063
  except: e['target_amount'] = 1500000
2064
+ try: e['bonus_percentage'] = float(request.form.get('bonus_percentage', 0))
2065
  except: e['bonus_percentage'] = 10
2066
  break
2067
  data['employees'] = employees