LiFan
2024-07-23 9ab768f94cecdcec13c22e7d70e9fd8a18afef53
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
ÿþ#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include <wobject/xdouble.hpp>
#include <xcontrol/xlayersheet.hpp>
#include <xcontrol/xdatetimepick.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
    class __declspec(dllexport) APNew :  public xframe
    {
    public:
        xdwgrid    dw_1;
        xdwgrid    dw_3;
        bool        bstart;
        xlayersheet m_layer;
        xnode    m_agentNode;    //Agent Condition
        xstring searchStr;    
    public:
        APNew(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static APNew* CreateInstance(void* implPtr, void* hWnd)
        {
            APNew* pWin = new APNew(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;
        }
        
                
        int OnSave(bool continueAdd)
        {
                
            /*int     IDYES = 6;
            int     MB_YESNO = 4;
            if(win32::MessageBox(GetHWND(),L"/f&Tnx¤‹leQ/eØNfÆ~ÿ",L"Ðc:y", MB_YESNO) != IDYES) return 1;*/
                
            dw_3.AcceptText();
            xstring error;
            xstring str;
            xml x ;
            xaserverarg arg ;
            
            arg.setNativePointer(xaserverarg::CreateInstance());
            dw_3.DwUpdateAllToEx(x);
            arg.AddArg(L"content",x.xml());
            if(xurl::get(L"/sale/data/AP/update", arg.GetString(),x)!=1)
            {
                error = x.text();
                alert(L"err:"+error);
                return 1;
            }
            str = x.documentElement().getAttribute(L"text");
            if(str != L"true")
            {
                alert(L"leQ1Y%!");
                return 1;
            }
                
            dw_3.ResetUpdateStatus();    
        
                
            if(!continueAdd)
            {
                alert(L"leQbŸR!");
                CloseWindow();
            }
            else 
            {
                m_layer.SelectSheet(0);
            }
            
            return 1;
        }
            
        
        //&q¹pÀo;mYtýQpe
        int OnSetFocus(TEvent* evt, LPARAM param)
        {
            //͑nå]wQag
            SetAgent();
            return 1;
        }
        
        //}TäNÑS^ýQpe
        int OnCmdDispatch(xstring comdid)
        {
            int index;
            if (comdid==L"xmPrev")
            {
                index = m_layer.GetSheetIndex();
                index --;
                m_layer.SelectSheet(index);
            }
            else if (comdid==L"xmNext") 
            {
                index = m_layer.GetSheetIndex();
                index ++;
                if(index==1)
                {
                    xcontrol(GetControl(L"sle_filter")).SetText(L"");
                    xstring str=L"";
                    if(str != searchStr)
                    {
                        searchStr = str;
                        //dw_1.Filter(L"*",searchStr);
                        dw_1.Filter(L"VATSupplierID",searchStr);
                    }
                }
                m_layer.SelectSheet(index);
                return 1;
            }
            else if(comdid==L"xmOk")
            {
                return OnSave(false);
            }
            else if(comdid==L"xmCancel")
            {
                CloseWindow();
                return 1;
            }
            return 0;
        }
        
        int OnDoubleClicked(TEvent* evt, LPARAM p)
        {
            dw_1.AcceptText();
                
            HCURSOR hCursor = xutil::SetCursorWait();
            int col = dw_1.GetColumn();
            dw_1.ItemChangeTo(dw_1.GetRow(),L"PayAmount",dw_1.GetItemString(dw_1.GetRow(),L"Balance"));
            dw_1.Redraw();
            xutil::RestoreCursor(hCursor);
            return 1;        
        }
        
        int OnItemAskStyle(TEvent* evt, LPARAM p)
        {
            int DMS_CSSSTYLE = 0x8;
            DWASKSTYLENMHDR& hdr = *(DWASKSTYLENMHDR*)evt->notify.pnmh;
            int row = hdr.row;
            int col = hdr.col;
            xstring colname = hdr.colname;
 
            int rows = dw_1.GetRowCount();
            if(row < 1 || row > rows)
            {
                return 1;
            }
            
            if(colname==L"NInvoiceNo")
            {
                xstring NInvoiceNo = dw_1.GetItemString(row,L"NInvoiceNo");
                xstring InvoiceNo = dw_1.GetItemString(row,L"InvoiceNo");
                if(NInvoiceNo != InvoiceNo)
                {                    
                    hdr.mask =  DMS_CSSSTYLE;
                    hdr.pCssStyle = (LPTSTR)L"color:#ff0000";
                }
            }
            
            return 1;
        }    
        
        int OnTabSelectedSheet(TEvent* evt, LPARAM p)
        {
            int index = m_layer.GetSheetIndex();
            if (index == 1)
            {
                dw_1.AcceptText();
            
            
                dw_3.Reset();
            
                xml x ;
                
                x.loadXML(L"<data/>");
                    
                xml x1 ;
                
                int i=0;
                for (i=1;i <=dw_1.GetRowCount(); i++)
                {
                    xstring Amount = dw_1.GetItemString(i,L"PayAmount");
                    xstring PrePayAmount = dw_1.GetItemString(i,L"PrePayAmount");
                    xstring SupplierID = dw_1.GetItemString(i,L"VATSupplierID");
                    if (Amount != L"" && Amount.toInt() != 0)
                    {
                        int row = dw_3.InsertRow(0); 
                        xstring sdate = publiccode::GetCurrentDate();
                        dw_3.SetItemString(row,L"APDate",sdate);
                    
                        dw_3.SetItemString(row,L"CreateDate",sdate);
                        dw_3.SetItemString(row,L"PayedDate",sdate);
                        xstring suserid = publiccode::GetUser().id;
                        xstring susername = publiccode::GetUser().name;
                        dw_3.SetItemString(row,L"CreatorID",suserid);
                        dw_3.SetItemDisplayString(row,L"CreatorID",susername);
                        dw_3.SetItemString(row,L"InvoiceNo",dw_1.GetItemString(i,L"NInvoiceNo"));
                    
                        dw_3.SetItemString(row,L"Amount",dw_1.GetItemString(i,L"PayAmount"));
                        
                        dw_3.SetItemString(row,L"SupplierID",dw_1.GetItemString(i,L"SupplierID"));
                        dw_3.SetItemDisplayString(row,L"SupplierID",dw_1.GetItemDisplayString(i,L"SupplierID"));
                        dw_3.SetItemString(row,L"APSupplierID",dw_1.GetItemString(i,L"VATSupplierID"));
                        dw_3.SetItemDisplayString(row,L"APSupplierID",dw_1.GetItemDisplayString(i,L"VATSupplierID"));
                        
                        dw_3.SetItemDisplayString(row,L"SalespersonID",dw_1.GetItemDisplayString(i,L"SalespersonID"));
                        dw_3.SetItemString(row,L"SalespersonID",dw_1.GetItemString(i,L"SalespersonID"));
                        dw_3.SetItemString(row,L"OrgName",dw_1.GetItemString(i,L"OrgName"));
                        xstring APID = publiccode::GetGuid();
                        dw_3.SetItemString(row,L"APID",APID);
                    }
                    
                }
                
            }
                    
                    
            return 1;
        }
        
        //}TäNYt‹NöN
        int OnXCommand(TEvent* evt, int param)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
        
        int OnAttachEvent()
        {
            //Ñ~š[å]wQag¹pûQ‹NöN
            AttachEvent(L"WM_XCOMMAND", (FEvent)&APNew::OnXCommand);
            //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag
            AttachEvent(L"WM_SETFOCUS", (FEvent)&APNew::OnSetFocus);
            AttachEvent(L"dw_1",L"DWV_DOUBLECLICKED", (FEvent)&APNew::OnDoubleClicked);//LˆÌSûQ
            AttachEvent(L"dw_1",L"DWV_ASKSTYLE", (FEvent)&APNew::OnItemAskStyle);
            //AttachEvent(L"dw_1",L"DWV_ITEMCHANGED",OnItemChanged);
            AttachEvent(L"tab_1", L"LYSN_SELECTEDSHEET", (FEvent)&APNew::OnTabSelectedSheet);
            AttachEvent(L"dw_3",L"DWV_ITEMCHANGED", (FEvent)&APNew::OnDoubleClickedOne);
            return 1;
        }
        
        int OnDoubleClickedOne(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            xstring colname=hdr.colname;
            xstring value = hdr.data;
            
            double Amount= dw_3.GetItemDouble(hdr.row,L"Amount");
            double PayedAmount = dw_3.GetItemDouble(hdr.row,L"PayedAmount");
            
            if (colname == L"PrePayAmount" || colname == L"Amount") 
            {
                double Amount1 = dw_3.GetItemDouble(hdr.row,L"Amount");
                double PrePayAmount = dw_3.GetItemDouble(hdr.row,L"PrePayAmount");
                dw_3.SetItemDouble(hdr.row,L"PayedAmount", xdouble(Amount - PrePayAmount).round(2));
            }
            return 1;
        }
        /*int OnItemChanged(TEvent* evt, LPARAM p)
        {
            ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
            xstring colname=hdr.colname;
            xstring value = hdr.data;
            int row = hdr.row;            
        
            if(colname==L"PayAmount")
            {
                double amt = dw_1.GetItemDouble(row,L"PayAmount");
                xstring InvoiceNo = dw_1.GetItemString(row,L"NInvoiceNo");
                xstring id = dw_1.GetItemString(row,L"VATInvoiceID");
                double  preAmt = CalcMatchPrePay(InvoiceNo,amt,id);
                dw_1.SetItemDouble(row,L"PrePayAmount",preAmt);
            
                preAmt = dw_1.GetItemDouble(row,L"PrePayAmount");
                dw_1.SetItemDouble(row,L"APAmount",amt - preAmt);
                dw_1.Redraw();
            }
            if(colname==L"APAmount")
            {
                double PrePayAmount = dw_1.GetItemDouble(row,L"PrePayAmount");
                double APAmount = dw_1.GetItemDouble(row,L"APAmount");
                dw_1.SetItemDouble(row,L"PayAmount",PrePayAmount + APAmount);
                dw_1.Redraw();
            }
            return 1;
        }*/
        /*
        int  OnRetrieve()
        {
            xml x ;
            
            xaserverarg arg ;
            arg.setNativePointer(arg.CreateInstance());    
            arg.AddArg(L"xxx",L"xxx");
            if (getUrl(L"",arg.GetString(),x)!=1)
            {
                trace(x.text());
                return -1;
            }else    
            {
                //dw_list.Retrieve(x);
                //dw_list.Redraw();
            }
            return 1;
        }
        */
        
        int onload()
        {
            SetArg();
            m_layer = GetControl(L"tab_1");
            dw_1 = GetControl(L"dw_1");
            dw_1.openUrl(L"/sale/view/AP/template/ImportList1");
            dw_1.SetAskStyle(true);
            dw_1.SetColumnState(L"PrePayAmount",false);
            dw_1.SetColumnState(L"APAmount",false);
            
            dw_3 = GetControl(L"dw_3");
            dw_3.openUrl(L"/sale/view/AP/template/ImportList3");
            
            
            xml x;
            x ;
            
            
            xaserverarg arg = GetArg();
            if(arg)
            {
                xstring InvoiceNo = arg.GetArgString(L"InvoiceNo");
                x = ViewObject::RetrieveData(L"/sale/data/AP/list1",L"ShipDays",L"1=1",L"QueryTxt",InvoiceNo);
                if(x)dw_1.Retrieve(x);
            }
        
            OnAttachEvent();
            searchStr = L"";
            bstart = true;
            
            return 1;    
        }
        
        int onloaded()
        {
            SetAgent();            
            
            return 1;
        }        
    };