File size: 56,364 Bytes
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ff154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ff154
 
 
 
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fbe144
4a85540
9fbe144
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ff154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ff154
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fbe144
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
26ff154
 
4a85540
 
 
 
 
 
 
 
cb43e8f
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
 
 
26ff154
4a85540
 
26ff154
 
 
 
 
 
 
 
 
 
 
4a85540
 
 
26ff154
 
 
 
4a85540
cb43e8f
 
 
 
 
 
26ff154
 
 
 
4a85540
 
26ff154
 
 
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
26ff154
 
 
 
 
4a85540
 
 
 
26ff154
4a85540
 
 
 
26ff154
4a85540
 
 
 
 
 
 
3035369
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
26ff154
4a85540
 
 
 
26ff154
4a85540
 
26ff154
 
 
4a85540
26ff154
4a85540
 
26ff154
4a85540
26ff154
4a85540
 
26ff154
4a85540
 
 
 
 
 
 
 
 
 
 
26ff154
 
 
 
 
 
4a85540
 
26ff154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3035369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26ff154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb43e8f
 
26ff154
 
cb43e8f
26ff154
 
 
4a85540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
<!DOCTYPE html>
<html dir="rtl" lang="fa">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>سیستم مدیریت تسهیلات بانکی</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/persian-datepicker/dist/css/persian-datepicker.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/persian-date.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/persian-datepicker/dist/js/persian-datepicker.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/persian-number.min.js"></script>
    <style>
        @font-face {
            font-family: 'IRANSans';
            src: url('https://cdn.fontcdn.ir/Font/Persian/IRANSans/IRANSansWeb.eot');
            src: url('https://cdn.fontcdn.ir/Font/Persian/IRANSans/IRANSansWeb.eot?#iefix') format('embedded-opentype'),
                 url('https://cdn.fontcdn.ir/Font/Persian/IRANSans/IRANSansWeb.woff2') format('woff2'),
                 url('https://cdn.fontcdn.ir/Font/Persian/IRANSans/IRANSansWeb.woff') format('woff'),
                 url('https://cdn.fontcdn.ir/Font/Persian/IRANSans/IRANSansWeb.ttf') format('truetype');
            font-weight: normal;
            font-style: normal;
        }
        body {
            font-family: 'IRANSans', sans-serif;
        }
        .table-container {
            overflow-x: auto;
        }
        .active-tab {
            background-color: #3b82f6;
            color: white;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto px-4 py-8">
        <h1 class="text-3xl font-bold text-center mb-8 text-blue-700">سیستم مدیریت تسهیلات بانکی</h1>
        
        <!-- Navigation Tabs -->
        <div class="flex mb-6 border-b">
            <button id="loanTabBtn" class="px-6 py-2 rounded-t-lg active-tab" onclick="showTab('loanTab')">تعریف تسهیلات</button>
            <button id="paymentTabBtn" class="px-6 py-2 rounded-t-lg bg-gray-200" onclick="showTab('paymentTab')">ثبت پرداخت</button>
            <button id="reportTabBtn" class="px-6 py-2 rounded-t-lg bg-gray-200" onclick="showTab('reportTab')">گزارش مغایرت</button>
        </div>
        
        <!-- Loan Definition Tab -->
        <div id="loanTab" class="bg-white p-6 rounded-lg shadow-md">
            <h2 class="text-xl font-semibold mb-4 text-blue-600">فرم تعریف تسهیلات بانکی</h2>
            
            <form id="loanForm" class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label for="loanNumber" class="block mb-2 font-medium">شماره تسهیلات</label>
                    <input type="text" id="loanNumber" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                </div>
                
                <div>
                    <label for="bankName" class="block mb-2 font-medium">نام بانک</label>
                    <div class="flex">
                        <select id="bankName" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                            <option value="">انتخاب کنید</option>
                            <option value="بانک ملی">بانک ملی</option>
                            <option value="بانک صادرات">بانک صادرات</option>
                            <option value="بانک ملت">بانک ملت</option>
                            <option value="بانک تجارت">بانک تجارت</option>
                            <option value="بانک رفاه">بانک رفاه</option>
                            <option value="بانک سپه">بانک سپه</option>
                            <option value="بانک کشاورزی">بانک کشاورزی</option>
                            <option value="بانک پارسیان">بانک پارسیان</option>
                        </select>
                        <button type="button" onclick="showAddBankModal()" class="mr-2 px-3 bg-blue-100 text-blue-600 rounded hover:bg-blue-200">
                            +
                        </button>
                    </div>
                </div>

                <!-- Add Bank Modal -->
                <div id="addBankModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
                    <div class="bg-white p-6 rounded-lg shadow-lg w-96">
                        <h3 class="text-xl font-semibold mb-4">افزودن بانک جدید</h3>
                        <input type="text" id="newBankName" class="w-full p-2 border rounded mb-4" placeholder="نام بانک">
                        <div class="flex justify-end">
                            <button onclick="hideAddBankModal()" class="px-4 py-2 bg-gray-200 rounded mr-2">انصراف</button>
                            <button onclick="addNewBank()" class="px-4 py-2 bg-blue-600 text-white rounded">ذخیره</button>
                        </div>
                    </div>
                </div>
                
                <div>
                    <label for="loanType" class="block mb-2 font-medium">نوع تسهیلات</label>
                    <select id="loanType" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                        <option value="">انتخاب کنید</option>
                        <option value="مسکن">مسکن</option>
                        <option value="خودرو">خودرو</option>
                        <option value="ماده‌ی ۹۱">ماده‌ی ۹۱</option>
                        <option value="قرض‌الحسنه">قرض‌الحسنه</option>
                        <option value="تجاری">تجاری</option>
                    </select>
                </div>
                
                <div>
                    <label for="loanAmount" class="block mb-2 font-medium">مبلغ تسهیلات (ریال)</label>
                    <input type="text" id="loanAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number" required>
                </div>
                
                <div>
                    <label for="installmentCount" class="block mb-2 font-medium">تعداد اقساط</label>
                    <input type="number" id="installmentCount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                </div>
                
                <div>
                    <label for="loanDate" class="block mb-2 font-medium">تاریخ اخذ تسهیلات</label>
                    <input type="text" id="loanDate" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 datepicker" required>
                </div>

                <div>
                    <label for="installmentAmount" class="block mb-2 font-medium">مبلغ هر قسط (ریال)</label>
                    <input type="text" id="installmentAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number" required>
                </div>
                
                <div>
                    <label for="interestRate" class="block mb-2 font-medium">درصد سود (%)</label>
                    <input type="number" step="0.01" id="interestRate" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                </div>
                
                <div>
                    <label for="penaltyRate" class="block mb-2 font-medium">درصد جریمه (%)</label>
                    <input type="number" step="0.01" id="penaltyRate" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                </div>
                
                <div class="md:col-span-2 flex flex-wrap gap-2">
                    <button type="submit" class="w-full md:w-auto bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 transition">ذخیره تسهیلات</button>
                    <button type="button" onclick="generateInstallments()" class="w-full md:w-auto bg-green-600 text-white px-6 py-2 rounded hover:bg-green-700 transition">تولید اقساط</button>
                    <button type="button" onclick="clearLoanForm()" class="w-full md:w-auto bg-gray-600 text-white px-6 py-2 rounded hover:bg-gray-700 transition">افزودن جدید</button>
                </div>
            </form>
            
            <div id="installmentsSection" class="mt-8 hidden">
                <h3 class="text-lg font-semibold mb-4 text-blue-600">جدول اقساط</h3>
                <div class="table-container">
                    <table id="installmentsTable" class="min-w-full bg-white border">
                        <thead>
                            <tr class="bg-gray-200">
                                <th class="py-2 px-4 border">ردیف</th>
                                <th class="py-2 px-4 border">تاریخ سررسید</th>
                                <th class="py-2 px-4 border">مبلغ قسط</th>
                                <th class="py-2 px-4 border">سود</th>
                                <th class="py-2 px-4 border">جریمه</th>
                                <th class="py-2 px-4 border">اصل تسهیلات</th>
                            </tr>
                        </thead>
                        <tbody id="installmentsBody">
                            <!-- Installments will be added here -->
                        </tbody>
                    </table>
                </div>
                <div class="mt-4">
                    <button id="saveInstallmentsBtn" class="bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 transition hidden">ذخیره اقساط</button>
                </div>
            </div>

            <!-- Loans List Table -->
            <div class="mt-8">
                <h3 class="text-lg font-semibold mb-4 text-blue-600">لیست تسهیلات تعریف شده</h3>
                <div class="table-container">
                    <table id="loansTable" class="min-w-full bg-white border">
                        <thead>
                            <tr class="bg-gray-200">
                                <th class="py-2 px-4 border">ردیف</th>
                                <th class="py-2 px-4 border">شماره تسهیلات</th>
                                <th class="py-2 px-4 border">بانک</th>
                                <th class="py-2 px-4 border">نوع تسهیلات</th>
                                <th class="py-2 px-4 border">مبلغ</th>
                                <th class="py-2 px-4 border">اقدامات</th>
                            </tr>
                        </thead>
                        <tbody id="loansBody">
                            <!-- Loans will be added here -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
        <!-- Payment Registration Tab -->
        <div id="paymentTab" class="hidden bg-white p-6 rounded-lg shadow-md">
            <h2 class="text-xl font-semibold mb-4 text-blue-600">فرم ثبت پرداخت</h2>
            
            <form id="paymentForm" class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label for="paymentLoanNumber" class="block mb-2 font-medium">شماره تسهیلات</label>
                    <select id="paymentLoanNumber" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" required>
                        <option value="">انتخاب کنید</option>
                        <!-- Loans will be populated here -->
                    </select>
                </div>
                
                <div>
                    <label for="paymentBankName" class="block mb-2 font-medium">نام بانک</label>
                    <input type="text" id="paymentBankName" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500" readonly>
                </div>
                
                <div>
                    <label for="paymentDate" class="block mb-2 font-medium">تاریخ پرداخت</label>
                    <input type="text" id="paymentDate" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 datepicker" required>
                </div>
                
                <div>
                    <label for="paymentAmount" class="block mb-2 font-medium">مبلغ پرداخت (ریال)</label>
                    <input type="text" id="paymentAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number" required>
                </div>
                
                <div class="md:col-span-2">
                    <h3 class="text-lg font-semibold mb-2 text-blue-600">توزیع مبلغ پرداختی</h3>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div>
                            <label for="principalAmount" class="block mb-2 font-medium">اصل تسهیلات (ریال)</label>
                            <input type="text" id="principalAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number" required>
                        </div>
                        <div>
                            <label for="interestAmount" class="block mb-2 font-medium">سود تسهیلات (ریال)</label>
                            <input type="text" id="interestAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number" required>
                        </div>
                        <div>
                            <label for="penaltyAmount" class="block mb-2 font-medium">جریمه (ریال)</label>
                            <input type="text" id="penaltyAmount" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500 persian-number">
                        </div>
                    </div>
                </div>
                
                <div class="md:col-span-2">
                    <button type="submit" class="w-full md:w-auto bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 transition">ثبت پرداخت</button>
                </div>
            </form>
            
            <div class="mt-8">
                <h3 class="text-lg font-semibold mb-4 text-blue-600">پرداخت‌های ثبت شده</h3>
                <div class="table-container">
                    <table id="paymentsTable" class="min-w-full bg-white border">
                        <thead>
                            <tr class="bg-gray-200">
                                <th class="py-2 px-4 border">ردیف</th>
                                <th class="py-2 px-4 border">شماره تسهیلات</th>
                                <th class="py-2 px-4 border">بانک</th>
                                <th class="py-2 px-4 border">تاریخ پرداخت</th>
                                <th class="py-2 px-4 border">مبلغ پرداخت</th>
                                <th class="py-2 px-4 border">اصل</th>
                                <th class="py-2 px-4 border">سود</th>
                                <th class="py-2 px-4 border">جریمه</th>
                                <th class="py-2 px-4 border">اقدامات</th>
                            </tr>
                        </thead>
                        <tbody id="paymentsBody">
                            <!-- Payments will be added here -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
        <!-- Discrepancy Report Tab -->
        <div id="reportTab" class="hidden bg-white p-6 rounded-lg shadow-md">
            <h2 class="text-xl font-semibold mb-4 text-blue-600">گزارش مغایرت بانکی</h2>
            
            <form id="reportForm" class="mb-6">
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                    <div>
                        <label for="reportLoanNumber" class="block mb-2 font-medium">شماره تسهیلات</label>
                        <select id="reportLoanNumber" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500">
                            <option value="">همه تسهیلات</option>
                            <!-- Loans will be populated here -->
                        </select>
                    </div>
                    
                    <div>
                        <label for="reportBankName" class="block mb-2 font-medium">بانک</label>
                        <select id="reportBankName" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500">
                            <option value="">همه بانک‌ها</option>
                            <option value="بانک ملی">بانک ملی</option>
                            <option value="بانک صادرات">بانک صادرات</option>
                            <option value="بانک ملت">بانک ملت</option>
                            <option value="بانک تجارت">بانک تجارت</option>
                            <option value="بانک رفاه">بانک رفاه</option>
                            <option value="بانک سپه">بانک سپه</option>
                            <option value="بانک کشاورزی">بانک کشاورزی</option>
                            <option value="بانک پارسیان">بانک پارسیان</option>
                        </select>
                    </div>
                    
                    <div>
                        <label for="reportMethod" class="block mb-2 font-medium">روش محاسباتی</label>
                        <select id="reportMethod" class="w-full p-2 border rounded focus:ring-2 focus:ring-blue-500">
                            <option value="equal">تقسیم مساوی (اصل/سود/جریمه)</option>
                            <option value="interestFirst">پرداخت سود و جریمه قبل از اصل</option>
                        </select>
                    </div>
                </div>
                
                <div class="mt-4">
                    <button type="button" onclick="generateReport()" class="w-full md:w-auto bg-blue-600 text-white px-6 py-2 rounded hover:bg-blue-700 transition">تهیه گزارش</button>
                </div>
            </form>
            
            <div id="reportResult" class="hidden">
                <h3 class="text-lg font-semibold mb-4 text-blue-600">نتایج گزارش مغایرت</h3>
                <div class="mb-4 p-4 bg-blue-50 rounded">
                    <p id="summaryText"></p>
                </div>
                
                <div class="table-container">
                    <table id="discrepancyTable" class="min-w-full bg-white border">
                        <thead>
                            <tr class="bg-gray-200">
                                <th class="py-2 px-4 border">ردیف</th>
                                <th class="py-2 px-4 border">شماره تسهیلات</th>
                                <th class="py-2 px-4 border">بانک</th>
                                <th class="py-2 px-4 border">تاریخ پرداخت</th>
                                <th class="py-2 px-4 border">مبلغ ثبت شده</th>
                                <th class="py-2 px-4 border">مبلغ محاسبه شده</th>
                                <th class="py-2 px-4 border">اختلاف</th>
                                <th class="py-2 px-4 border">نوع اختلاف</th>
                            </tr>
                        </thead>
                        <tbody id="discrepancyBody">
                            <!-- Report results will be added here -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Persian date picker initialization
        $(document).ready(function() {
            $(".datepicker").pDatepicker({
                observer: true,
                format: 'YYYY/MM/DD',
                initialValue: false
            });
            
            // Format Persian numbers
            $('.persian-number').on('input', function() {
                this.value = persianJs(this.value).englishNumber().toString();
            });
        });

        // Data storage
        let loans = [];
        let payments = [];
        
        
        // Switch between tabs
        function showTab(tabId) {
            document.getElementById('loanTab').classList.add('hidden');
            document.getElementById('paymentTab').classList.add('hidden');
            document.getElementById('reportTab').classList.add('hidden');
            
            document.getElementById('loanTabBtn').classList.remove('active-tab');
            document.getElementById('paymentTabBtn').classList.remove('active-tab');
            document.getElementById('reportTabBtn').classList.remove('active-tab');
            
            document.getElementById(tabId).classList.remove('hidden');
            document.getElementById(tabId + 'Btn').classList.add('active-tab');
            
            if (tabId === 'paymentTab') {
                populateLoanNumbers('paymentLoanNumber');
                document.getElementById('paymentBankName').value = '';
            } else if (tabId === 'reportTab') {
                populateLoanNumbers('reportLoanNumber');
            }
        }
        
        // Populate loan numbers in dropdowns
        function populateLoanNumbers(elementId) {
            const selectElement = document.getElementById(elementId);
            
            // Save the current selected value
            const currentValue = selectElement.value;
            
            // Clear existing options except the first one
            while (selectElement.options.length > 1) {
                selectElement.remove(1);
            }
            
            // Add loan numbers from the loans array
            loans.forEach(loan => {
                const option = document.createElement('option');
                option.value = loan.loanNumber;
                option.textContent = loan.loanNumber;
                selectElement.appendChild(option);
            });
            
            // Restore the previous selection if it still exists
            if (currentValue && Array.from(selectElement.options).some(o => o.value === currentValue)) {
                selectElement.value = currentValue;
            }
        }
        
        // Clear loan form
        function clearLoanForm() {
            document.getElementById('loanForm').reset();
            document.getElementById('installmentsSection').classList.add('hidden');
            document.getElementById('saveInstallmentsBtn').classList.add('hidden');
            document.getElementById('installmentsBody').innerHTML = '';
        }

        // Handle loan form submission
        document.getElementById('loanForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const loan = {
                loanNumber: document.getElementById('loanNumber').value,
                bankName: document.getElementById('bankName').value,
                loanType: document.getElementById('loanType').value,
                loanDate: document.getElementById('loanDate').value,
                loanAmount: parseFloat(document.getElementById('loanAmount').value.replace(/,/g, '')) || 0,
                installmentCount: parseInt(document.getElementById('installmentCount').value),
                installmentAmount: parseFloat(document.getElementById('installmentAmount').value.replace(/,/g, '')),
                interestRate: parseFloat(document.getElementById('interestRate').value),
                penaltyRate: parseFloat(document.getElementById('penaltyRate').value),
                installments: [],
                createdAt: new Date().toISOString()
            };
            
            // Validate required fields
            if (!loan.loanNumber || !loan.bankName || !loan.loanType || !loan.loanDate || 
                isNaN(loan.loanAmount) || isNaN(loan.installmentCount) || isNaN(loan.installmentAmount) || 
                isNaN(loan.interestRate) || isNaN(loan.penaltyRate)) {
                alert('لطفاً همه فیلدهای فرم را به درستی پر کنید.');
                return;
            }
            
            // Check if this loan number already exists
            const existingIndex = loans.findIndex(l => l.loanNumber === loan.loanNumber);
            if (existingIndex !== -1) {
                loans[existingIndex] = loan; // Update existing loan
                alert('تسهیلات با این شماره قبلاً ثبت شده و اطلاعات آن به‌روزرسانی شد.');
            } else {
                loans.push(loan); // Add new loan
                alert('تسهیلات جدید با موفقیت ثبت شد.');
            }
            
            refreshLoansTable();
        });
        
        // Format loan amount input
        function formatLoanAmount(input) {
            let value = input.value.replace(/,/g, '');
            if (!value) return;
            
            value = parseInt(value);
            if (isNaN(value)) value = 0;
            
            input.value = value.toLocaleString('en-US');
        }
        
        // Generate installments
        function generateInstallments() {
            const loanNumber = document.getElementById('loanNumber').value;
            const loanAmountInput = document.getElementById('loanAmount');
            const installmentCountInput = document.getElementById('installmentCount');
            const installmentAmountInput = document.getElementById('installmentAmount');
            const interestRateInput = document.getElementById('interestRate');
            
            // Basic validation
            if (!loanNumber) {
                alert('لطفاً ابتدا تسهیلات را ذخیره کنید');
                return;
            }
            
            // Validate required fields have values
            if (!loanNumber || !loanAmountInput.value || !installmentCountInput.value || 
                !installmentAmountInput.value || !interestRateInput.value) {
                alert('لطفاً همه فیلدهای تسهیلات را تکمیل کنید.');
                return;
            }

            // Convert to numeric values
            const loanAmount = parseFloat(loanAmountInput.value.replace(/,/g, '')) || 0;
            const installmentCount = parseInt(installmentCountInput.value) || 0;
            const installmentAmount = parseFloat(installmentAmountInput.value.replace(/,/g, '')) || 0;
            const interestRate = parseFloat(interestRateInput.value) || 0;

            // Additional validation
            if (loanAmount <= 0 || installmentCount <= 0 || installmentAmount <= 0 || interestRate <= 0) {
                alert('مقادیر باید بزرگتر از صفر باشند.');
                return;
            }
            
            const tbody = document.getElementById('installmentsBody');
            tbody.innerHTML = '';
            
            const fixedPrincipal = loanAmount / installmentCount;
            
            // Convert Persian numbers to English for calculations
            function toEnglishNumber(number) {
                return parseFloat(persianJs(number).englishNumber().toString().replace(/,/g, ''));
            }
            
            for (let i = 0; i < installmentCount; i++) {
                const tr = document.createElement('tr');
                tr.className = 'hover:bg-gray-50';
                
                // Row number
                const td1 = document.createElement('td');
                td1.className = 'py-2 px-4 border text-center';
                td1.textContent = i + 1;
                
                // Due date (Persian date picker)
                const td2 = document.createElement('td');
                td2.className = 'py-2 px-4 border';
                const dateInput = document.createElement('input');
                dateInput.type = 'text';
                dateInput.className = 'w-full p-2 border rounded datepicker';
                dateInput.placeholder = 'انتخاب تاریخ';
                dateInput.required = true;
                
                // Try to preserve existing date if available
                const loanNumber = document.getElementById('loanNumber').value;
                const loan = loans.find(l => l.loanNumber === loanNumber);
                if (loan && loan.installments && loan.installments[i]) {
                    dateInput.value = loan.installments[i].dueDate;
                }
                
                td2.appendChild(dateInput);
                $(dateInput).pDatepicker({
                    observer: true,
                    format: 'YYYY/MM/DD',
                    initialValue: false
                });
                
                // Installment amount (fixed)
                const td3 = document.createElement('td');
                td3.className = 'py-2 px-4 border text-left';
                td3.textContent = installmentAmount.toLocaleString('fa-IR');
                
                // Interest amount
                const td4 = document.createElement('td');
                td4.className = 'py-2 px-4 border text-left';
                const remainingAmount = loanAmount - (fixedPrincipal * i);
                const interest = Math.round((remainingAmount * interestRate / 100) / 12);
                td4.textContent = interest.toLocaleString('fa-IR');
                
                // Penalty amount
                const td5 = document.createElement('td');
                td5.className = 'py-2 px-4 border text-left';
                td5.textContent = '۰';
                
                // Principal amount
                const td6 = document.createElement('td');
                td6.className = 'py-2 px-4 border text-left';
                td6.textContent = (installmentAmount - interest).toLocaleString('fa-IR');
                
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                
                tbody.appendChild(tr);
            }
            
            // Show save button if we have installments
            if (installmentCount > 0) {
                document.getElementById('saveInstallmentsBtn').classList.remove('hidden');
            } else {
                document.getElementById('saveInstallmentsBtn').classList.add('hidden');
            }
        }
        
        // Bank management functions
        function showAddBankModal() {
            document.getElementById('addBankModal').classList.remove('hidden');
        }

        function hideAddBankModal() {
            document.getElementById('addBankModal').classList.add('hidden');
            document.getElementById('newBankName').value = '';
        }

        function addNewBank() {
            const bankName = document.getElementById('newBankName').value.trim();
            if (!bankName) {
                alert('لطفاً نام بانک را وارد کنید.');
                return;
            }

            const select = document.getElementById('bankName');
            const option = document.createElement('option');
            option.value = bankName;
            option.textContent = bankName;
            select.appendChild(option);
            select.value = bankName;

            hideAddBankModal();
        }

        // Load loans into the table
        function refreshLoansTable() {
            const tbody = document.getElementById('loansBody');
            tbody.innerHTML = '';
            
            loans.forEach((loan, index) => {
                const tr = document.createElement('tr');
                tr.className = 'hover:bg-gray-50';
                
                const td1 = document.createElement('td');
                td1.className = 'py-2 px-4 border text-center';
                td1.textContent = index + 1;
                
                const td2 = document.createElement('td');
                td2.className = 'py-2 px-4 border text-center';
                td2.textContent = loan.loanNumber;
                
                const td3 = document.createElement('td');
                td3.className = 'py-2 px-4 border';
                td3.textContent = loan.bankName;
                
                const td4 = document.createElement('td');
                td4.className = 'py-2 px-4 border';
                td4.textContent = loan.loanType;
                
                const td5 = document.createElement('td');
                td5.className = 'py-2 px-4 border text-left';
                td5.textContent = loan.loanAmount.toLocaleString('fa-IR');
                
                const td6 = document.createElement('td');
                td6.className = 'py-2 px-4 border text-center';
                
                const editBtn = document.createElement('button');
                editBtn.className = 'text-blue-600 hover:text-blue-800 ml-2';
                editBtn.innerHTML = 'ویرایش';
                editBtn.addEventListener('click', () => editLoan(index));
                
                const deleteBtn = document.createElement('button');
                deleteBtn.className = 'text-red-600 hover:text-red-800';
                deleteBtn.innerHTML = 'حذف';
                deleteBtn.addEventListener('click', () => deleteLoan(index));
                
                td6.appendChild(editBtn);
                td6.appendChild(deleteBtn);
                
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                
                tbody.appendChild(tr);
            });
        }

        // Edit a loan
        function editLoan(index) {
            const loan = loans[index];
            
            document.getElementById('loanNumber').value = loan.loanNumber;
            document.getElementById('bankName').value = loan.bankName;
            document.getElementById('loanType').value = loan.loanType;
            document.getElementById('loanAmount').value = loan.loanAmount.toLocaleString('en-US');
            document.getElementById('installmentCount').value = loan.installmentCount;
            document.getElementById('installmentAmount').value = loan.installmentAmount.toLocaleString('en-US');
            document.getElementById('loanDate').value = loan.loanDate;
            document.getElementById('interestRate').value = loan.interestRate;
            document.getElementById('penaltyRate').value = loan.penaltyRate;
            
            // Show installments section if it has installments
            if (loan.installments && loan.installments.length > 0) {
                document.getElementById('installmentsSection').classList.remove('hidden');
                document.getElementById('saveInstallmentsBtn').classList.remove('hidden');
                
                const tbody = document.getElementById('installmentsBody');
                tbody.innerHTML = '';
                
                loan.installments.forEach((inst, idx) => {
                    const tr = document.createElement('tr');
                    tr.className = 'hover:bg-gray-50';
                    
                    // Row number
                    const td1 = document.createElement('td');
                    td1.className = 'py-2 px-4 border text-center';
                    td1.textContent = idx + 1;
                    
                    // Due date
                    const td2 = document.createElement('td');
                    td2.className = 'py-2 px-4 border';
                    const dateInput = document.createElement('input');
                    dateInput.type = 'text';
                    dateInput.className = 'w-full p-2 border rounded datepicker';
                    dateInput.value = inst.dueDate;
                    dateInput.required = true;
                    td2.appendChild(dateInput);
                    $(dateInput).pDatepicker({
                        observer: true,
                        format: 'YYYY/MM/DD',
                        initialValue: false
                    });
                    
                    // Installment amount
                    const td3 = document.createElement('td');
                    td3.className = 'py-2 px-4 border text-left';
                    td3.textContent = inst.amount.toLocaleString('fa-IR');
                    
                    // Interest amount
                    const td4 = document.createElement('td');
                    td4.className = 'py-2 px-4 border text-left';
                    td4.textContent = inst.interest.toLocaleString('fa-IR');
                    
                    // Penalty amount
                    const td5 = document.createElement('td');
                    td5.className = 'py-2 px-4 border text-left';
                    td5.textContent = inst.penalty.toLocaleString('fa-IR');
                    
                    // Principal amount
                    const td6 = document.createElement('td');
                    td6.className = 'py-2 px-4 border text-left';
                    td6.textContent = inst.principal.toLocaleString('fa-IR');
                    
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    tr.appendChild(td5);
                    tr.appendChild(td6);
                    
                    tbody.appendChild(tr);
                });
            }
            
            // Scroll to form
            document.getElementById('loanTab').scrollIntoView({behavior: 'smooth'});
        }

        // Delete a loan
        function deleteLoan(index) {
            if (confirm('آیا از حذف این تسهیلات مطمئن هستید؟')) {
                loans.splice(index, 1);
                refreshLoansTable();
                
                // Also refresh payment and report dropdowns if open
                if (!document.getElementById('paymentTab').classList.contains('hidden')) {
                    populateLoanNumbers('paymentLoanNumber');
                }
                if (!document.getElementById('reportTab').classList.contains('hidden')) {
                    populateLoanNumbers('reportLoanNumber');
                }
                
                alert('تسهیلات با موفقیت حذف شد.');
            }
        }

        // Save installments
        document.getElementById('saveInstallmentsBtn').addEventListener('click', function() {
            const loanNumber = document.getElementById('loanNumber').value;
            const loanIndex = loans.findIndex(l => l.loanNumber === loanNumber);
            
            if (loanIndex === -1) {
                alert('تسهیلات یافت نشد.');
                return;
            }
            
            const rows = document.getElementById('installmentsBody').rows;
            const installments = [];
            
            for (let i = 0; i < rows.length; i++) {
                const cells = rows[i].cells;
                
                const installment = {
                    number: i + 1,
                    dueDate: cells[1].querySelector('input').value,
                    amount: parseFloat(document.getElementById('installmentAmount').value.replace(/,/g, '')),
                    interest: parseFloat(persianJs(cells[3].textContent).englishNumber().toString().replace(/,/g, '')),
                    penalty: parseFloat(persianJs(cells[4].textContent).englishNumber().toString().replace(/,/g, '')),
                    principal: parseFloat(persianJs(cells[5].textContent).englishNumber().toString().replace(/,/g, ''))
                };
                
                installments.push(installment);
            }
            
            loans[loanIndex].installments = installments;
            alert('اقساط با موفقیت ذخیره شدند.');
        });
        
        // Update bank name when loan number is selected in payment form
        document.getElementById('paymentLoanNumber').addEventListener('change', function() {
            const loanNumber = this.value;
            if (!loanNumber) {
                document.getElementById('paymentBankName').value = '';
                return;
            }
            
            const loan = loans.find(l => l.loanNumber === loanNumber);
            if (loan) {
                document.getElementById('paymentBankName').value = loan.bankName;
            }
        });
        
        // Handle payment form submission
        document.getElementById('paymentForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const payment = {
                loanNumber: document.getElementById('paymentLoanNumber').value,
                bankName: document.getElementById('paymentBankName').value,
                paymentDate: document.getElementById('paymentDate').value,
                paymentAmount: parseFloat(document.getElementById('paymentAmount').value.replace(/,/g, '')),
                principalAmount: parseFloat(document.getElementById('principalAmount').value.replace(/,/g, '')),
                interestAmount: parseFloat(document.getElementById('interestAmount').value.replace(/,/g, '')),
                penaltyAmount: parseFloat((document.getElementById('penaltyAmount').value || '').replace(/,/g, '')) || 0,
                createdAt: new Date().toISOString()
            };
            
        // Make generateInstallments button work
        document.querySelector('button[onclick="generateInstallments()"]').addEventListener('click', function(e) {
            e.preventDefault();
            generateInstallments();
            document.getElementById('installmentsSection').classList.remove('hidden');
        });

        // Validate payment
            const calculatedTotal = payment.principalAmount + payment.interestAmount + payment.penaltyAmount;
            if (Math.abs(calculatedTotal - payment.paymentAmount) > 1) {
                alert(`جمع مبالغ جزء (${calculatedTotal.toLocaleString('fa-IR')}) با مبلغ کل پرداختی (${payment.paymentAmount.toLocaleString('fa-IR')}) مغایرت دارد.`);
                return;
            }
            
            payments.push(payment);
            addPaymentToTable(payment);
            
            // Clear the form (except for loan number)
            document.getElementById('paymentDate').value = '';
            document.getElementById('paymentAmount').value = '';
            document.getElementById('principalAmount').value = '';
            document.getElementById('interestAmount').value = '';
            document.getElementById('penaltyAmount').value = '';
            
            alert('پرداخت با موفقیت ثبت شد.');
        });
        
        // Add payment to payments table
        function addPaymentToTable(payment) {
            const tbody = document.getElementById('paymentsBody');
            const tr = document.createElement('tr');
            tr.className = 'hover:bg-gray-50';
            tr.dataset.paymentId = payments.length - 1;
            
            const td1 = document.createElement('td');
            td1.className = 'py-2 px-4 border text-center';
            td1.textContent = payments.length;
            
            const td2 = document.createElement('td');
            td2.className = 'py-2 px-4 border text-center';
            td2.textContent = payment.loanNumber;
            
            const td3 = document.createElement('td');
            td3.className = 'py-2 px-4 border';
            td3.textContent = payment.bankName;
            
            const td4 = document.createElement('td');
            td4.className = 'py-2 px-4 border text-center';
            td4.textContent = payment.paymentDate;
            
            const td5 = document.createElement('td');
            td5.className = 'py-2 px-4 border text-left';
            td5.textContent = payment.paymentAmount.toLocaleString('fa-IR');
            
            const td6 = document.createElement('td');
            td6.className = 'py-2 px-4 border text-left';
            td6.textContent = payment.principalAmount.toLocaleString('fa-IR');
            
            const td7 = document.createElement('td');
            td7.className = 'py-2 px-4 border text-left';
            td7.textContent = payment.interestAmount.toLocaleString('fa-IR');
            
            const td8 = document.createElement('td');
            td8.className = 'py-2 px-4 border text-left';
            td8.textContent = payment.penaltyAmount.toLocaleString('fa-IR');
            
            const td9 = document.createElement('td');
            td9.className = 'py-2 px-4 border text-center';
            const deleteBtn = document.createElement('button');
            deleteBtn.className = 'text-red-600 hover:text-red-800';
            deleteBtn.innerHTML = 'حذف';
            deleteBtn.addEventListener('click', function() {
                deletePayment(this.closest('tr').dataset.paymentId);
            });
            td9.appendChild(deleteBtn);
            
            tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);
            tr.appendChild(td5);
            tr.appendChild(td6);
            tr.appendChild(td7);
            tr.appendChild(td8);
            tr.appendChild(td9);
            
            tbody.appendChild(tr);
        }
        
        // Delete a payment
        function deletePayment(paymentId) {
            if (confirm('آیا از حذف این پرداخت مطمئن هستید؟')) {
                payments.splice(paymentId, 1);
                refreshPaymentsTable();
                
                // Reindex payments
                payments = payments.map((payment, index) => {
                    return {...payment, id: index};
                });
            }
        }
        
        // Refresh payments table
        function refreshPaymentsTable() {
            const tbody = document.getElementById('paymentsBody');
            tbody.innerHTML = '';
            
            payments.forEach((payment, index) => {
                payment.id = index; // Update payment ID
                addPaymentToTable(payment);
            });
        }
        
        // Generate discrepancy report
        function generateReport() {
            const loanNumberFilter = document.getElementById('reportLoanNumber').value;
            const bankNameFilter = document.getElementById('reportBankName').value;
            const method = document.getElementById('reportMethod').value;
            
            // Filter payments
            let filteredPayments = [...payments];
            
            if (loanNumberFilter) {
                filteredPayments = filteredPayments.filter(p => p.loanNumber === loanNumberFilter);
            }
            
            if (bankNameFilter) {
                filteredPayments = filteredPayments.filter(p => p.bankName === bankNameFilter);
            }
            
            if (filteredPayments.length === 0) {
                alert('با فیلترهای انتخاب شده پرداختی یافت نشد.');
                return;
            }
            
            // Process each payment based on the selected method
            const discrepancies = [];
            
            filteredPayments.forEach(payment => {
                const loan = loans.find(l => l.loanNumber === payment.loanNumber);
                if (!loan) return;
                
                if (method === 'equal') {
                    // Equal distribution method
                    const calculatedPrincipal = Math.round(payment.paymentAmount / 3);
                    const calculatedInterest = Math.round(payment.paymentAmount / 3);
                    const calculatedPenalty = Math.round(payment.paymentAmount / 3);
                    
                    // Calculate differences
                    const principalDiff = payment.principalAmount - calculatedPrincipal;
                    const interestDiff = payment.interestAmount - calculatedInterest;
                    const penaltyDiff = payment.penaltyAmount - calculatedPenalty;
                    
                    if (principalDiff !== 0 || interestDiff !== 0 || penaltyDiff !== 0) {
                        discrepancies.push({
                            loanNumber: payment.loanNumber,
                            bankName: payment.bankName,
                            paymentDate: payment.paymentDate,
                            recordedAmount: `${payment.principalAmount.toLocaleString('fa-IR')} + ${payment.interestAmount.toLocaleString('fa-IR')} + ${payment.penaltyAmount.toLocaleString('fa-IR')}`,
                            calculatedAmount: `${calculatedPrincipal.toLocaleString('fa-IR')} + ${calculatedInterest.toLocaleString('fa-IR')} + ${calculatedPenalty.toLocaleString('fa-IR')}`,
                            difference: (principalDiff + interestDiff + penaltyDiff).toLocaleString('fa-IR'),
                            type: 'تقسیم مساوی'
                        });
                    }
                } else if (method === 'interestFirst') {
                    // Interest and penalty first method
                    
                    // 1. Apply to penalty
                    const remainingAfterPenalty = Math.max(0, payment.paymentAmount - payment.penaltyAmount);
                    
                    // 2. Apply to interest
                    const remainingAfterInterest = Math.max(0, remainingAfterPenalty - payment.interestAmount);
                    
                    // 3. Remainder goes to principal
                    const calculatedPrincipal = remainingAfterInterest;
                    const calculatedInterest = payment.interestAmount;
                    const calculatedPenalty = payment.penaltyAmount;
                    
                    // Calculate differences
                    const principalDiff = payment.principalAmount - calculatedPrincipal;
                    const interestDiff = 0; // No difference in interest as we use the exact amount
                    const penaltyDiff = 0; // No difference in penalty as we use the exact amount
                    
                    if (principalDiff !== 0 || interestDiff !== 0 || penaltyDiff !== 0) {
                        discrepancies.push({
                            loanNumber: payment.loanNumber,
                            bankName: payment.bankName,
                            paymentDate: payment.paymentDate,
                            recordedAmount: `${payment.principalAmount.toLocaleString('fa-IR')} + ${payment.interestAmount.toLocaleString('fa-IR')} + ${payment.penaltyAmount.toLocaleString('fa-IR')}`,
                            calculatedAmount: `${calculatedPrincipal.toLocaleString('fa-IR')} + ${calculatedInterest.toLocaleString('fa-IR')} + ${calculatedPenalty.toLocaleString('fa-IR')}`,
                            difference: (principalDiff + interestDiff + penaltyDiff).toLocaleString('fa-IR'),
                            type: 'سود و جریمه قبل از اصل'
                        });
                    }
                }
            });
            
            // Display results
            if (discrepancies.length === 0) {
                document.getElementById('summaryText').textContent = `هیچ مغایرتی با روش "${method === 'equal' ? 'تقسیم مساوی' : 'سود و جریمه قبل از اصل'}" یافت نشد.`;
                document.getElementById('discrepancyBody').innerHTML = '';
            } else {
                document.getElementById('summaryText').textContent = `${discrepancies.length} مغایرت با روش "${method === 'equal' ? 'تقسیم مساوی' : 'سود و جریمه قبل از اصل'}" یافت شد.`;
                
                const tbody = document.getElementById('discrepancyBody');
                tbody.innerHTML = '';
                
                discrepancies.forEach((item, index) => {
                    const tr = document.createElement('tr');
                    tr.className = 'hover:bg-gray-50';
                    
                    const td1 = document.createElement('td');
                    td1.className = 'py-2 px-4 border text-center';
                    td1.textContent = index + 1;
                    
                    const td2 = document.createElement('td');
                    td2.className = 'py-2 px-4 border text-center';
                    td2.textContent = item.loanNumber;
                    
                    const td3 = document.createElement('td');
                    td3.className = 'py-2 px-4 border';
                    td3.textContent = item.bankName;
                    
                    const td4 = document.createElement('td');
                    td4.className = 'py-2 px-4 border text-center';
                    td4.textContent = item.paymentDate;
                    
                    const td5 = document.createElement('td');
                    td5.className = 'py-2 px-4 border text-left';
                    td5.textContent = item.recordedAmount;
                    
                    const td6 = document.createElement('td');
                    td6.className = 'py-2 px-4 border text-left';
                    td6.textContent = item.calculatedAmount;
                    
                    const td7 = document.createElement('td');
                    td7.className = 'py-2 px-4 border text-left';
                    td7.textContent = item.difference;
                    
                    const td8 = document.createElement('td');
                    td8.className = 'py-2 px-4 border';
                    td8.textContent = item.type;
                    
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    tr.appendChild(td5);
                    tr.appendChild(td6);
                    tr.appendChild(td7);
                    tr.appendChild(td8);
                    
                    tbody.appendChild(tr);
                });
            }
            
            document.getElementById('reportResult').classList.remove('hidden');
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Amiali6262/https-huggingface-co-amiali62623" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>