xj qian
2024-09-24 e3664da0966a35a90193abc46f57eb1386123297
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
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
    class __declspec(dllexport) simplemaintvatnotifyWin : public xframe
    {
    public:
        xdwtable    dw_profit;
        xdwgrid        dw_item;
        xdwgrid        dw_fob;
        xstring        InvNo;
        xstring        CurInvNo;
        xnode    m_agentNode;    //Agent Condition
 
    public:
        simplemaintvatnotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static simplemaintvatnotifyWin* CreateInstance(void* implPtr, void* hWnd)
        {
            simplemaintvatnotifyWin* pWin = new simplemaintvatnotifyWin(implPtr, (HWND)hWnd);
            return pWin;
        }
        int SetAgent()
        {
            xstring xfNodeAgentArea = L"agentarea";
            xnode anode = GetAgentNode(xfNodeAgentArea);
            if (m_agentNode)
            {
                SetAgentNode(anode, m_agentNode);
            }
            else
            {
                KXMLDOMElement xframeElement = GetElement();
                KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
                if (agent)
                {
                    xstring s = agent.xml();
                    m_agentNode = SetAgentNode(anode, s);
                }
            }
            return 1;
        }
 
        xstring  GetEntityData(LPARAM  pr)
        {
            xml x ;
            dw_item.AcceptText();
            dw_item.DwUpdateAllToEx(x);
            return x.xml();
        }
 
        //½¹µã¼¤»î´¦Àíº¯Êý
        int OnSetFocus(TEvent* evt, LPARAM param)
        {
            //ÖØÖù¤¾ßÌõ
            SetAgent();
            return 1;
        }
 
        int OnPrint()
        {
            xaserverarg  arg;
            
            arg.AddArg(L"EntityName", L"VATNotify");
            arg.AddArg(L"EntityID", L"", L"");
            xstring InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"NInvoiceNo");
            if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"InvoiceNo");
            xstring SupplierID = dw_item.GetItemString(dw_item.GetRow(), L"SupplierID");
            arg.AddArg(L"EntityNo", InvoiceNo, L"");
            arg.AddArg(L"SupplierID", SupplierID);
            arg.AddArg(L"VATNotifyID", L"");
            
            openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg);
            return 1;
        }
 
        int OnPrintItem()
        {
            xaserverarg arg;
            
            arg.AddArg(L"EntityName", L"VATNotify", L"");
            arg.AddArg(L"EntityID", L"", L"");
            xstring InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"NInvoiceNo");
            if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"InvoiceNo");
            xstring SupplierID = dw_item.GetItemString(dw_item.GetRow(), L"SupplierID");
            arg.AddArg(L"EntityNo", InvoiceNo, L"");
            arg.AddArg(L"SupplierID", SupplierID);
            arg.AddArg(L"VATNotifyID", dw_item.GetGuid(dw_item.GetRow()));
            trace(InvoiceNo + L"====L" + dw_item.GetGuid(dw_item.GetRow()));
            
            openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg);
            return 1;
        }
 
        int allbill() {
            int MB_OKCANCEL = 1;
            int IDOK = 1;
            int ret =MessageBox(GetHWND(), L"È«Êý¿ªÆ±?", L"Ìáʾ", MB_OKCANCEL);
            if (ret != IDOK) return 1;
            dw_item.AcceptText();
            for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                dw_item.SetItemString(ll_row, L"NInvoiceNo", ls_dtlno);
                dw_item.SetItemString(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
                xstring sdate = publiccode::GetCurrentDate();
                dw_item.SetItemString(ll_row, L"NotifyDate", sdate);
                dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
            }
            dw_item.Redraw();
            return 1;
        }
 
        int allbillno() {
            int MB_OKCANCEL = 1;
            int IDOK = 1;
            int ret =MessageBox(GetHWND(), L"È«Êý²»¿ªÆ±?", L"Ìáʾ", MB_OKCANCEL);
            if (ret != IDOK) return 1;
            dw_item.AcceptText();
            for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L""));
                dw_item.ItemChangeTo(ll_row, L"NQuantity", dw_item.GetItemString(ll_row, L""));
                dw_item.SetItemString(ll_row, L"NQtyUnit", L"");
                dw_item.SetItemString(ll_row, L"NotifyDate", L"");
                dw_item.SetItemString(ll_row, L"NClassifyID", L"");
                dw_item.SetItemDisplayString(ll_row, L"NClassifyID", L"");
                dw_item.SetItemString(ll_row, L"NName", L"");
                dw_item.SetItemString(ll_row, L"NInvoiceNo", L"");
            }
            dw_item.Redraw();
            return 1;
        }
 
        int onebill()
        {
            int ll_row = dw_item.GetNextSelectRow(1);
            if (ll_row < 1) return 1;
 
            int MB_OKCANCEL = 1;
            int IDOK = 1;
            int ret =MessageBox(GetHWND(), L"È·ÈÏ¿ªÆ±Âð?", L"Ìáʾ", MB_OKCANCEL);
            if (ret != IDOK) return 1;
            dw_item.AcceptText();
 
            while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                dw_item.SetItemString(ll_row, L"NInvoiceNo", ls_dtlno);
                //dw_item.SetItemString(ll_row,L"NAmount",dw_item.GetItemString(ll_row,L"Amount"));
                xstring sdate = publiccode::GetCurrentDate();
                dw_item.SetItemString(ll_row, L"NotifyDate", sdate);
                dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
                ll_row = dw_item.GetNextSelectRow(ll_row + 1);
            }
 
            dw_item.Redraw();
            return 1;
        }
 
        int onebillno() {
            int ll_row = dw_item.GetNextSelectRow(1);
            if (ll_row < 1) return 1;
 
            int MB_OKCANCEL = 1;
            int IDOK = 1;
            int ret = MessageBox(GetHWND(), L"È·Èϲ»Ó迪ƱÂð?", L"Ìáʾ", MB_OKCANCEL);
            if (ret != IDOK) return 1;
            dw_item.AcceptText();
 
            while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L""));
                dw_item.ItemChangeTo(ll_row, L"NQuantity", dw_item.GetItemString(ll_row, L""));
                dw_item.SetItemString(ll_row, L"NotifyDate", L"");
                dw_item.SetItemString(ll_row, L"NClassifyID", L"");
                dw_item.SetItemDisplayString(ll_row, L"NClassifyID", L"");
                dw_item.SetItemString(ll_row, L"NQtyUnit", L"");
                dw_item.SetItemString(ll_row, L"NName", L"");
                dw_item.SetItemString(ll_row, L"NInvoiceNo", L"");
                ll_row = dw_item.GetNextSelectRow(ll_row + 1);
            }
            dw_item.Redraw();
            return 1;
        }
 
        int CalcRate()
        {
            for (int row = 1; row <= dw_fob.GetRowCount(); row++)
            {
                xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
                xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
                double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
                double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
                double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
                double rate = sumAmt / fobAmt;
                double LimitAmt = fobAmt * rate;
                dw_fob.SetItemDouble(row, L"Rate", rate);
                dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
                dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
            }
            RecalcProfitData();
            dw_fob.Redraw();
 
            return 1;
        }
 
        int onimport() {
            //OpenWindow(L"dev:xpage[import.vatnotify.vx]",0);
            return 1;
        }
 
        int OnFobItemChanged(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            xstring colname = hdr.colname;
            xstring value = hdr.data;
            int row = hdr.row;
 
            if (colname == L"Rate" || colname == L"FobAmt")
            {
                xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
                xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
                double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
                double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
                double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
                double rate = dw_fob.GetItemDouble(row, L"Rate");
                double LimitAmt = fobAmt * rate;
                dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
                dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
                dw_fob.Redraw();
                RecalcProfitData();
                return 1;
            }
 
            return 1;
        }
 
        int OnItemChanged(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            xstring colname = hdr.colname;
            xstring value = hdr.data;
            int row = hdr.row;
            xstring ClassifyID = dw_item.GetItemString(row, L"NClassifyID");
            if (ClassifyID == L"") ClassifyID = dw_item.GetItemString(row, L"ClassifyID");
            xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
            if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
            int ll_find = FobLookup(ClassifyID);
 
            //trace(L"\r\n"+ ll_find.toString()+L":"+ ClassifyID);
 
            if (colname == L"NAmount")
            {
                if (ll_find > 0)
                {
                    //xstring qtyUnit = dw_fob.GetItemString(ll_find,L"CQtyUnit");
                    xstring qtyUnit = dw_fob.GetItemString(ll_find, L"QtyUnit");
                    double limitAmt = dw_fob.GetItemDouble(ll_find, L"LimitAmt");
                    double CQuantity = dw_fob.GetItemDouble(ll_find, L"CQuantity");
                    double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
                    double amt = dw_item.GetItemDouble(row, L"NAmount");
                    //double qty = CQuantity * amt /limitAmt;
                    double qty = dw_item.GetItemDouble(row, L"Quantity");
                    if (qtyUnit.trim() != L"ǧ¿Ë")
                    {
                        int d = xstring(qty).toInt();
                        xstring s = xstring(d);
                        qty = s.toDouble();
                    }
                    else
                    {
                        dw_item.SetItemDouble(row, L"NQuantity", qty);
                        xstring sqty = dw_item.GetItemString(row, L"NQuantity");
                        qty = sqty.toDouble();
                    }
                    double restAmt = limitAmt - sumAmt;
                    dw_fob.SetItemDouble(ll_find, L"RestAmt", restAmt);
                    dw_item.ItemChangeTo(row, L"NQuantity", xstring(qty));
                    dw_fob.Redraw();
                }
                return 1;
            }
            else if (colname == L"NQuantity")
            {
                if (ll_find > 0)
                {
                    double CQuantity1 = dw_fob.GetItemDouble(ll_find, L"CQuantity");
                    double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
                    double restQuantity = CQuantity1 - sumQty;
                    dw_fob.SetItemDouble(ll_find, L"RestQty", restQuantity);
 
                    xstring qtyUnit2 = dw_fob.GetItemString(ll_find, L"QtyUnit");
                    dw_item.SetItemString(row, L"NQtyUnit", qtyUnit2);
 
                    dw_fob.Redraw();
                }
                return 1;
            }
            else if (colname == L"NInvoiceNo")
            {
                row = dw_item.GetRow();
                InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
                if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
                RetrieveFob(InvoiceNo);
                RetrieveProfit(InvoiceNo);
                return 1;
            }
            else if (colname == L"NClassifyID")
            {
                xstring NQuantity = dw_item.GetItemString(dw_item.GetRow(), L"NQuantity");
                if (NQuantity != L"") dw_item.ItemChangeTo(dw_item.GetRow(), L"NQuantity", NQuantity);
                xstring NAmount = dw_item.GetItemString(dw_item.GetRow(), L"NAmount");
                if (NAmount != L"") dw_item.ItemChangeTo(dw_item.GetRow(), L"NAmount", NAmount);
                xstring sdate = publiccode::GetCurrentDate();
                dw_item.SetItemString(dw_item.GetRow(), L"NotifyDate", sdate);
 
                //xstring qtyUnit1 = dw_fob.GetItemString(ll_find,L"CQtyUnit");
                xstring qtyUnit1 = dw_fob.GetItemString(ll_find, L"QtyUnit");
                dw_item.SetItemString(dw_item.GetRow(), L"NQtyUnit", qtyUnit1);
                dw_item.SetItemString(dw_item.GetRow(), L"VATRefundRate", dw_fob.GetItemString(ll_find, L"VATRefundRate"));
                dw_item.Redraw();
 
                return 1;
            }
            /*
                    if dwo.name='notifycname' then
            if trim(data)='' then
                this.setItem(row,'notifycustid','')
            else
                //cwd
                if pos(data,'"') > 0 then
                    ll_find = dw_3.find(L"cname='"+data+L"'",0,dw_3.rowCount())
                else
                    ll_find = dw_3.find('cname=L"'+data+'"',0,dw_3.rowCount())
                end if
                //end
        //        ll_find = dw_3.find('cname=L"'+data+'"',0,dw_3.rowCount())
                if ll_find > 0 then
                    this.setItem(row,'notifycustid',dw_3.getItemString(ll_find,'custid'))
                    this.setItem(row,'custunit',dw_3.getItemString(ll_find,'custunit'))
 
                    decimal ld_rate
                    ls_custid = dw_3.getItemString(ll_find,'custid')
                    select retax into :ld_rate from code_t_custom where code_s = :ls_custid;
                    this.setitem(row,'retax',ld_rate)
                end if
            end if
            if not isnull(this.getItemDecimal(row,'notifybuyamt')) then
                dwoex = this.object.notifybuyamt
                this.event itemchanged(row,dwoex,xstring(this.getItemDecimal(row,'notifybuyamt')))
            end if
            if not isnull(this.getItemDecimal(row,'notifycustqty')) then
                dwoex = this.object.notifycustqty
                this.event itemchanged(row,dwoex,xstring(this.getItemDecimal(row,'notifycustqty')))
            end if
            dw_1.setitem( dw_1.getrow(), 'notifydate',today())
            */
            return 1;
        }
 
        double GetSumAmountExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
        {
            xml x ;
            
            xaserverarg arg ;
            arg.AddArg(L"ClassifyID", ClassifyID);
            arg.AddArg(L"InvoiceNo", InvoiceNo);
            arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
 
            if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
            {
                xstring error = x.text();
                alert(L"err:" + error);
                return 0.0;
            }
            KXMLDOMNode n = x.selectSingleNode(L"data/Item/amt");
            if (!n) return 0.0;
            xstring str = n.text();
            return str.toDouble();
        }
 
        double GetSumQuantityExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
        {
            xml x ;
            
            xaserverarg arg ;
            arg.AddArg(L"ClassifyID", ClassifyID);
            arg.AddArg(L"InvoiceNo", InvoiceNo);
            arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
 
            if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
            {
                xstring error = x.text();
                alert(L"err:" + error);
                return 0.0;
            }
            KXMLDOMNode n = x.selectSingleNode(L"data/Item/qty");
            if (!n) return 0.0;
            xstring str = n.text();
            return str.toDouble();
        }
 
        double GetSumAmount(xstring InvoiceNo, xstring ClassifyID)
        {
            double amt = 0;
            xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
            if (InvoiceNoExcept != L"") amt = GetSumAmountExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
 
            for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
                if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                if (InvoiceNo == ls_dtlno)
                {
                    xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
                    if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
                    if (classifyID == ClassifyID)
                        amt += dw_item.GetItemDouble(ll_row, L"NAmount");
                }
            }
            return amt;
        }
 
        int RecalcProfitData()
        {
            double fobAmt = GetSumFobAmt();
            double limitAmt = GetSumLimitAmount();
            double RefundAmt = GetSumRefund();
            double goodsAmt = limitAmt - RefundAmt;
            double freight = dw_profit.GetItemDouble(1, L"Freight");
            double comm = dw_profit.GetItemDouble(1, L"Comm");
            double     netAmount = fobAmt - freight - comm;
            double exchCost = (limitAmt - RefundAmt) / fobAmt;
            dw_profit.SetItemDouble(1, L"NetAmount", netAmount);
            dw_profit.SetItemDouble(1, L"SaleAmount", fobAmt);
            dw_profit.SetItemDouble(1, L"SaleCost", goodsAmt);
            dw_profit.SetItemDouble(1, L"Drawback", RefundAmt);
            dw_profit.SetItemDouble(1, L"ExchCost", exchCost);
            dw_profit.Redraw();
            return 1;
        }
        double GetSumLimitAmount()
        {
            double amt = 0;
            for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
            {
                amt += dw_fob.GetItemDouble(ll_row, L"LimitAmt");
            }
            return amt;
        }
        double GetSumRefund()
        {
            double amt = 0;
            for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
            {
                double rate = dw_fob.GetItemDouble(ll_row, L"VATRate");
                double refundRate = dw_fob.GetItemDouble(ll_row, L"VATRefundRate");
                double d = dw_fob.GetItemDouble(ll_row, L"LimitAmt");
                double val = d / (100.0 + rate) * refundRate;
                amt += val;
            }
            return amt;
        }
        double GetSumFobAmt()
        {
            double amt = 0;
            for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
            {
                amt += dw_fob.GetItemDouble(ll_row, L"FobAmt");
            }
            return amt;
        }
 
        double GetSumQuantity(xstring InvoiceNo, xstring ClassifyID)
        {
            double qty = 0;
            xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
            if (InvoiceNoExcept != L"") qty = GetSumQuantityExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
 
            for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
            {
                xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
                if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
                if (InvoiceNo == ls_dtlno)
                {
                    xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
                    if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
                    if (classifyID == ClassifyID)
                    {
                        qty += dw_item.GetItemDouble(ll_row, L"NQuantity");
                    }
                }
            }
            return qty;
        }
 
        int FobLookup(xstring ClassifyID)
        {
            for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
            {
                if (dw_fob.GetItemString(ll_row, L"ClassifyID") == ClassifyID) return ll_row;
            }
            return -1;
        }
 
        int addother() {
            return 1;
        }
        int deleteother() {
            return 1;
        }
        //ÃüÁî·¢²¼º¯Êý
        int OnCmdDispatch(xstring comdid)
        {
            if (comdid == L"save") {
                return OnSave();
            }
            else if (comdid == L"xmParse")
                return OnParse();
            else if (comdid == L"allbill") {
                return allbill();
            }
            else if (comdid == L"allbillno") {
                return allbillno();
            }
            else if (comdid == L"onebill") {
                return onebill();
            }
            else if (comdid == L"onebillno") {
                return onebillno();
            }
            else if (comdid == L"import") {
                return onimport();
            }
            else if (comdid == L"addother") {
                return addother();
            }
            else if (comdid == L"deleteother") {
                return deleteother();
            }
            else if (comdid == L"xmPrint") {
                return OnPrint();
            }
            else if (comdid == L"xmPrintItem") {
                return OnPrintItem();
            }
            else if (comdid == L"xmCalcRate") {
                return CalcRate();
            }
            return 0;
        }
 
        int OnRowChanged(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            int row = hdr.row;
 
            xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
            if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
            if (InvoiceNo != CurInvNo)
            {
                CurInvNo = InvoiceNo;
                RetrieveFob(InvoiceNo);
                RetrieveProfit(InvoiceNo);
                RecalcProfitData();
            }
 
            return 1;
        }
 
        int OnParse()
        {
            xaserverarg arg;
            
            OpenWindow(L"dev:xpage[VATNotifyParse.vx]", arg);
            if (arg.GetArgString(L"process") == L"ok")
            {
                int row = dw_item.GetRow();
                int row1 = dw_item.InsertRow(0);
                dw_item.SetItemString(row1, L"SupplierID", dw_item.GetItemString(row, L"SupplierID"));
                dw_item.SetItemDisplayString(row1, L"SupplierID", dw_item.GetItemDisplayString(row, L"SupplierID"));
                dw_item.SetItemString(row1, L"Amount", arg.GetArgString(L"Amount"));
                dw_item.SetItemString(row1, L"Quantity", arg.GetArgString(L"Quantity"));
                dw_item.SetItemString(row1, L"CQuantity", arg.GetArgString(L"CustQuantity"));
                dw_item.SetItemString(row1, L"ClassifyID", dw_item.GetItemString(row, L"ClassifyID"));
                dw_item.SetItemDisplayString(row1, L"ClassifyID", dw_item.GetItemDisplayString(row, L"ClassifyID"));
            }
            return 1;
        }
 
        //ÃüÁî´¦Àíʼþ
        int OnXCommand(TEvent* evt, LPARAM param)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
 
        int OnSave()
        {
            xml x ;
            
            dw_item.AcceptText();
            dw_item.DwUpdateAllToEx(x);
            xaserverarg arg ;
            arg.AddArg(L"content", x.xml());
 
 
 
            //trace(x.xml);
            //return 1;
            if (xurl::get(L"/sale/data/VATNotify/base/update", arg.GetString(), x) != 1)
            {
                xstring error = x.text();
                alert(L"err:" + error);
                return 1;
            }
            xstring str = x.documentElement().getAttribute(L"text");
            if (str == L"true")
            {
                dw_item.ResetUpdateStatus();
            }
            else
            {
                alert(L"±£´æÊ§°Ü1!");
                return 1;
            }
 
            dw_fob.AcceptText();
            xml x1 ;
            
            dw_fob.DwUpdateAllToEx(x1);
            arg.AddArg(L"content", x1.xml());
            int MB_OKCANCEL = 1;
            int IDOK = 1;
 
            /*
            for(int ll_row=1;    ll_row <= dw_fob.GetRowCount(); ll_row++)
            {
                xstring RestQty = dw_fob.GetItemString(ll_row,L"RestQty");
                //xstring ClassifyID=dw_fob.GetItemString(ll_row,L"CName");
                if(RestQty !=L"0.00" ){
                    //xstring qty =RestQty;
                    int ret = win32::MessageBox(GetHWND(),L" ´æÔÚ½á´æÊýÁ¿²»Îª0µÄÎïÆ·,È·Èϱ£´æÂð?",L"Ìáʾ",MB_OKCANCEL);
                    if(ret !=IDOK) return 1;
                }
            }
            */
 
 
            //return 0;
            if (xurl::get(L"/sale/data/VATNotify/fob/update", arg.GetString(), x1) != 1)
            {
                xstring error1 = x1.text();
                alert(L"err:" + error1);
                return 1;
            }
            str = x1.documentElement().getAttribute(L"text");
            if (str == L"true")
            {
                dw_fob.ResetUpdateStatus();
                alert(L"±£´æ³É¹¦!");
            }
            else
            {
                alert(L"±£´æÊ§°Ü2!");
                return 1;
            }
            return 1;
        }
 
        int OnAttachEvent()
        {
            //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
            AttachEvent(L"WM_XCOMMAND", (FEvent)&simplemaintvatnotifyWin::OnXCommand);
            //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
            AttachEvent(L"WM_SETFOCUS", (FEvent)&simplemaintvatnotifyWin::OnSetFocus);
            AttachEvent(L"dw_item", L"DWV_ITEMCHANGED", (FEvent)&simplemaintvatnotifyWin::OnItemChanged);
            AttachEvent(L"dw_fob", L"DWV_ITEMCHANGED", (FEvent)&simplemaintvatnotifyWin::OnFobItemChanged);
            AttachEvent(L"dw_item", L"DWV_ROWFOCUSCHANGED", (FEvent)&simplemaintvatnotifyWin::OnRowChanged);
            AttachEvent(L"dw_item", L"DWV_ASKDATA", (FEvent)&simplemaintvatnotifyWin::OnAskDataItem);
            AttachCloseWindow();
            return 1;
        }
 
        int RetrieveFob(xstring InvoiceNo, bool start = false)
        {
            if (!start)
            {
                dw_fob.Filter(L"InvoiceNo", InvoiceNo);
                dw_fob.Redraw();
                if (dw_fob.GetRowCount() > 0) return 1;
            }
 
            //start = true;
            xml x ;
            
            xaserverarg arg;
            
            arg.AddArg(L"invoiceno", InvoiceNo);
            if (getUrl(L"/sale/data/VATNotify/entity/fob", arg.GetString(), x) != 1)
            {
                trace(x.text());
                return -1;
            }
            else
            {
                //trace(x.xml);
                if (start)
                {
                    dw_fob.Retrieve(x);
                    dw_fob.Redraw();
                }
                else
                {
                    xml x1 ;
                    
                    dw_fob.DwUpdateAllToEx(x1);
                    KXMLDOMElement docElement = x1.documentElement();
                    if (docElement)
                    {
                        KXMLDOMNodeList lst = x.selectNodes(L"data/Item");
                        int n = lst.length();
                        for (int i = 0; i < n; i++)
                        {
                            KXMLDOMElement e = lst.item(i);
                            docElement.appendChild(e);
                            
                        }
                    
                        dw_fob.Retrieve(x1);
                    }
                    else
                    {
                        dw_fob.Retrieve(x);
                    }
                    dw_fob.Filter(L"InvoiceNo", InvoiceNo);
                    dw_fob.Redraw();
                }
            }
            return 1;
        }
 
        int RetrieveProfit(xstring InvoiceNo)
        {
            xml x ;
            
            xaserverarg arg;
            
            arg.AddArg(L"invoiceno", InvoiceNo);
            if (getUrl(L"/sale/data/VATNotify/entity/profit", arg.GetString(), x) != 1)
            {
                trace(x.text());
                return -1;
            }
            else
            {
                dw_profit.Retrieve(x);
                dw_profit.Redraw();
            }
            return 1;
        }
 
        int  OnRetrieve()
        {
            HCURSOR  hCursor = xutil::SetCursorWait();
 
 
            xml x ;
            
            xaserverarg arg;
            
 
            if (GetWinParam())
            {
                arg = GetArg();
                
            }
            else
            {
                xutil::RestoreCursor(hCursor);
                return 1;
            }
            if (getUrl(L"/sale/data/VATNotify/entity/base", arg.GetString(), x) != 1)
            {
                trace(x.text());
                xutil::RestoreCursor(hCursor);
                return -1;
            }
            else
            {
                dw_item.Retrieve(x);
                dw_item.Redraw();
                dw_item.SetSelectionMode(1);
            }
            if (dw_item.GetRowCount() > 0)
            {
                xstring InvoiceNo = dw_item.GetItemString(1, L"NInvoiceNo");
                if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(1, L"InvoiceNo");
                CurInvNo = InvoiceNo;
                RetrieveFob(InvoiceNo);
                RetrieveProfit(InvoiceNo);
                RecalcProfitData();
            }
 
            xutil::RestoreCursor(hCursor);
            return 1;
        }
 
        //base AskData
        int OnAskDataItem(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            int row = hdr.row;
            xstring x = hdr.colname;
            if (x == L"userInvoiceNo") //ÏÂÀ­
            {
                xstring sInvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
                hdr.data = sInvoiceNo.c_str(true);
            }
 
            return 1;
        }
 
        int onload()
        {
            SetArg();
            dw_item = GetControl(L"dw_item");
            dw_item.openUrl(L"/sale/view/VATNotify/template/VATNotify/item");
            dw_item.SetColumnState(L"InvoiceNo", false);
            dw_item.SetColumnState(L"CName", false);
            //dw_item.SetColumnState(L"CreatorID",false);
            //dw_item.SetColumnState(L"CreateDate",false);
            dw_item.SetColumnState(L"VATRate", false);
            dw_item.SetColumnState(L"VATRefundRate", false);
            dw_item.SetColumnState(L"IsFinish", false);
            dw_item.SetColumnState(L"Type", false);
            dw_item.SetColumnState(L"QtyUnitName", false);
            dw_item.SetColumnState(L"QtyUnit", false);
            dw_item.SetColumnState(L"CQtyUnit", false);
 
            dw_fob = GetControl(L"dw_fob");
            dw_fob.openUrl(L"/sale/view/VATNotify/template/VATNotify/fob");
            dw_profit = GetControl(L"dw_profit");
            dw_profit.openUrl(L"/sale/view/VATNotify/template/VATNotify/profit");
            dw_profit.SetColHeaderHeight(0);
            dw_profit.SetRowSelectorWidth(0);
            dw_profit.SetHScrollState(false);
            dw_profit.SetVScrollState(false);
 
            InvNo = L"";
            CurInvNo = L"";
            xaserverarg arg;
            
 
            if (GetWinParam())
            {
                arg = GetArg();
                
                InvNo = arg.GetArgString(L"invoiceno");
                SetWindowText(GetHWND(), InvNo);
            }
            CurInvNo = InvNo;
 
            OnRetrieve();
            OnAttachEvent();
 
            return 1;
        }
 
        int onloaded()
        {
            SetAgent();
 
            return 1;
        }
    };