LiFan
2024-07-16 f087a50629e95666db2e0b0ba4373834e2b9593b
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
use "maint.vd"
use "xaserver.vd"
use "xaserverarg.vd"
use "profit.vd"
use "xcell.vd"
use "vbind.vd"
use "publiccode.vd"
use "xpagecontrol.vd"
class PaymentTermEdit : public maint
{
    xdwtable dw_base;
    xdwtable    dw_p;
    xcell dw_cell;
    string sCryno;
    int OnAddrow()
    {
        dw_p = dw_base.FindDwTable("line");
        int i;
        double dDueAmount = 0;
        double dPercnet = 100;
        for (i = 1 ; i <= dw_p.GetRowCount();i++)
        {
            dDueAmount = dw_p.GetItemDouble(i,"DueAmount");
            if (dDueAmount > 0)
                break;
            dPercnet = dPercnet - dw_p.GetItemDouble(i,"DuePercent");
        }
        int irow = dw_p.InsertRow(0);
        dw_p.SetItemString(irow,"SeqNo",irow.toString());
        if (dDueAmount <= 0)
            dw_p.SetItemDouble(irow,"DuePercent",dPercnet);
        
        return 1;
    }
    int OnDeleterow()
    {
        dw_p = dw_base.FindDwTable("line");
        int row2 = dw_p.GetRow();
        if (row2 < 1) return 0;
        dw_p.DeleteRow(row2);
 
        return 1;
    }
    string OnCreateTxt()
    {
        //dw_1.AcceptText(); //²»Äܼӻᱨ´í
        int irow;
        //int icnt = dw_1.GetRowCount();
        dw_p = dw_base.FindDwTable("line");
        int icnt = dw_p.GetRowCount();
        if (icnt < 1) return "";
        string sTxt;
        //double dPercnet = 100;
        for (irow = 1;irow <= icnt ;irow ++)
        {
            string sPaymentMethod = dw_p.GetItemString(irow,"PaymentMethod"); //Ö§¸¶·½Ê½
            //string sDueDays = dw_p.GetItemDisplayString(irow,"DueDays"); 
            string sDueDays = dw_p.GetItemString(irow,"DueDays"); //ÆÚÏÞ
            string sDuePercent = dw_p.GetItemString(irow,"DuePercent"); //±ÈÀý
            string sDueAmount = dw_p.GetItemString(irow,"DueAmount"); //½ð¶î
            
            if (!sPaymentMethod || sPaymentMethod == "")
                sTxt = sTxt + "";
            if (!sDueDays || sDueDays == "")
                sTxt = sTxt + "";
            else
            {
                if (sDueDays == "-1") sDueDays = " IN ADVANCE";
                else if (sDueDays == "0") sDueDays = " AT SIGHT";
                else 
                {
                    if (sPaymentMethod == "T/T")
                        sDueDays = " WITHIN "+sDueDays + " DAYS AFTER SHIPMENT";
                    else
                        sDueDays = " AT "+sDueDays + " DAYS";
                }
                
                if (!sDuePercent || sDuePercent == "")
                {
                    if (!sDueAmount || sDueAmount == "")
                        sTxt = sTxt + "";
                    else
                    {
                        
                        sTxt = sTxt + sCryno + " " + sDueAmount + " " + sPaymentMethod + sDueDays + ";";
                    }
                }
                else
                {
                    if (sDuePercent.find(".",0) >= 0)
                    {
                        while (sDuePercent.right(1) == "0")
                        {
                            sDuePercent = sDuePercent.left(sDuePercent.length() - 1);
                        }
                        if (sDuePercent.right(1) == ".")
                            sDuePercent = sDuePercent.left(sDuePercent.length() - 1);
                    }
                
                    sTxt = sTxt + sDuePercent + "% " + sPaymentMethod+ sDueDays + ";";
                }
            }
        }
        
        sTxt = sTxt.mid(0,sTxt.length() - 1);
        if (sTxt != "")
            sTxt = sTxt + ".";
 
        return sTxt;
    }
    int OnOk()
    {
        dw_base.AcceptText();
        //ÅжÏÊÇ·ñÓбØÊäֵΪ¿Õ
        dw_p = dw_base.FindDwTable("line");
        double dPercnet = 0;
        double dAmount = 0;
        if (dw_p)
        {
            int i;
            for (i=1;i <= dw_p.GetRowCount();i++)
            {
                string seqNo = dw_p.GetItemString(i,"SeqNo");
                string sPaymentMethod = dw_p.GetItemString(i,"PaymentMethod");
                string sDueDays = dw_p.GetItemString(i,"DueDays");
                string sDuePercent = dw_p.GetItemString(i,"DuePercent");
                dPercnet = dPercnet + sDuePercent.toDouble();
                string sDueAmount = dw_p.GetItemString(i,"DueAmount");
                dAmount = dAmount + sDueAmount.toDouble();
                if (!seqNo) seqNo = "";
                if (!sPaymentMethod) sPaymentMethod = "";
                if (!sDueDays) sDueDays = "";
                if (!sDuePercent) sDuePercent = "";
                if (!sDueAmount) sDueAmount = "";
                dw_p.SetItemString(i,"SeqNo",i.toString());
                string sChargeAll = sPaymentMethod + sDueDays + sDuePercent + sDueAmount;
                if (sChargeAll != "")
                {
                    if (sPaymentMethod == "")
                    {
                        alert("Ö§¸¶·½Ê½²»ÄÜΪ¿Õ£¡");
                        return 0;
                    }
                    if (sDueDays == "")
                    {
                        alert("ÆÚÏÞ²»ÄÜΪ¿Õ£¡");
                        return 0;
                    }
 
                }
            }
        }
        
        //°Ù·Ö±ÈУÑé
        if (dw_p.GetRowCount() <= 1 && sChargeAll == "")
        {}
        else
        {
            if (dPercnet != 100)
            {
                if (dAmount <= 0)
                {
                    alert("±ÈÂʲ»µÈÓÚ100£¡");
                    return 0;
                }
            }
        }
        
        string sTxt = OnCreateTxt();
        dw_base.SetItemString(1,"PaymentTermEx",sTxt);
 
        //CloseWindow();
        return 1;
    }
    int OnItemChanged(ref TNotifyEvent evt,int p)
    {
        ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
        string colname=hdr.colname;
        string value = hdr.data;
        int row = hdr.row;
        
        if (colname == "DueDays")
        {
            xdwtable dw;
            dw = dw_base.FindDwTable("line");
            
            if (dw)
            {
                string sPaymentMethod = dw.GetItemString(row,"PaymentMethod");
                if (value == "0")
                {
                    if (sPaymentMethod == "T/T")
                    {
                        //alert("´ËÖ§¸¶·½Ê½ÆÚÏÞ²»ÄÜΪ 0 £¨AT SIGHT£©");
                        //return -1;
                    }
                }
                else if (value == "-1")
                {
                    if (sPaymentMethod != "T/T")
                    {
                        alert("´ËÖ§¸¶·½Ê½ÆÚÏÞ²»ÄÜΪ -1£¨IN ADVANCE£©");
                        return -1;
                    }
                }
            }
        
        }
        //Éú³ÉÖ§¸¶Ìõ¿îÎı¾
        if (colname == "PaymentMethod" || colname == "DueDays" || colname == "DuePercent" || colname == "DueAmount")
        {
            string sTxt = OnCreateTxt();
 
            dw_base.SetItemString(1,"Description",sTxt);
        }
        
        return 1;
    }
    int OnClick(ref TNotifyEvent evt,int p)
    {
        ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
        string value = hdr.data;
        string colname = hdr.colname;
        int row = hdr.row;
        xaserverarg arg=new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        //alert(row.toString());
        xdwtable dw;
        dw = dw_base.FindDwTable("line");
        //alert(colname);
        if (dw)
        {
            if (colname == "DuePercent")
            {
                int i;
                int icnt = dw.GetRowCount();
                if (icnt < 1)
                    return 0;
                double dDueAmount = 0;
                for (i = 1 ; i <= icnt ; i++)
                {
                    dDueAmount = dw.GetItemDouble(i,"DueAmount");
                    if (dDueAmount > 0)
                        break;
                }
                dw_cell.setNativePointer(dw_base.QueryItem("ixcell"));
                if (dDueAmount > 0)
                {
                    dw.SetColumnProp("DuePercent","cellprotect","±£»¤");//±£»¤ÖÐÎĹæ¸ñ
                }
                else
                {
                    dw.SetColumnProp("DuePercent","cellprotect","²»±£»¤");//±£»¤ÖÐÎĹæ¸ñ
                }
                    
            }
            
            if (colname == "DueAmount")
            {
                int j;
                int jcnt = dw.GetRowCount();
                if (jcnt < 1)
                    return 0;
                double dDuePercent = 0;
                for (j = 1 ; j <= jcnt ; j++)
                {
                    dDuePercent = dw.GetItemDouble(j,"DuePercent");
                    if (dDuePercent > 0)
                        break;
                }
                if (dDuePercent > 0)
                {
                    dw.SetColumnProp("DueAmount","cellprotect","±£»¤");//±£»¤ÖÐÎĹæ¸ñ
                }
                else
                {
                    dw.SetColumnProp("DueAmount","cellprotect","²»±£»¤");//±£»¤ÖÐÎĹæ¸ñ
                }
            }
            
        }
        
        return 1;
    }
        
    //±£´æÊ¼þ
    int OnSave()
    {
        if(OnOk()<1)return 0;
        dw_base = GetControl("dw_base");
        dw_base.AcceptText();
        //dw_bank.AcceptText();
        xml x = new xml;
        xaserverarg arg = new xaserverarg;        
        x.setNativePointer(xml::CreateInstance());
        dw_base.DwUpdateAllTo(x.GetXmlDoc()); 
        //dw_bank.DwUpdateAllTo(x.GetXmlDoc()); 
        //alert(x.GetXml());
        arg.setNativePointer(arg.CreateInstance());    
        arg.AddArg("content",x.GetXml());                        
        arg.AddArg("dbmap","FND_PaymentTerm.dbmap");
        //return 0;
        if (getUrl("/sale/data/PaymentTerm/entity/company/save",arg.GetString(),x) != 1)
        {
            alert("±£´æÊ§°Ü!");
            return 0;
        }                        
        else
        {    
            //alert(x.GetXml());
            if(x.GetXmlDoc().selectSingleNode("error"))
            {
                alert("±£´æ³ö´í2!");
                return 0;                
            }
            arg.AddArg("ret","Ok");
            xwin::MessageBox(GetHWND(),"±£´æ³É¹¦£¡","Ìáʾ",0);    
            //alert("±£´æ³É¹¦");
            dw_base.ResetUpdateStatus();    
            //dw_bank.ResetUpdateStatus();    
            //xwin::SendMessage(parenthwnd, 0x401, "maintsave", 0);//֪ͨlist´°¿Ú¸üÐÂÊý¾Ý
        }
        //alert("±£´æ³É¹¦");
        dw_base.Redraw();    
        //dw_bank.Redraw();    
        CloseWindow();
        return 0;
    }
            
    int OnCmdDispatch(string comdid)
    {
        //alert(comdid);
        if(comdid=="xmOk") OnSave();
        else if(comdid=="addrow") OnAddrow();
        else if(comdid=="deleterow") OnDeleterow();
        //else if(comdid=="AddRow") OnAddRow();
        //else if(comdid=="InsertRow") OnInsertRow();
        //else if(comdid=="DeleteRow")OnDeleteRow();
        return 1;
    }
 
    //°´Å¥Ê¼þ
    int OnXCommand(ref TXCommandEvent evt,int p)
    {
        return OnCmdDispatch(evt.pStrID);
    }
 
    int OnAttachEvent()
    {
        //°´Å¥Ê¼þ
        AttachEvent("WM_XCOMMAND",OnXCommand);
        //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
        //AttachEvent("WM_SETFOCUS",OnSetFocus);
        AttachEvent("dw_base","DWV_ITEMCHANGED",OnItemChanged);
        AttachEvent("dw_base","DWV_CLICKED",OnClick);
    }
    int OnRetrieve()
    {
        if(GetParam())
        {
            int p = GetParam();
            xaserverarg args = new xaserverarg;
            args.setNativePointer(p);
            string id = args.GetArgString("EntityID");
            //alert(id);
            if(id=="new")
            {
                
                //OnAddNew();
            }
            else
            {
                xml x = new xml;
                x.setNativePointer(xml::CreateInstance());
                if(getUrl("/sale/data/PaymentTerm/entity/base12", args.GetString(), x) != 1)
                {
                    alert("´íÎó");
                    return -1;
                }
                //alert(x.GetXml());
                dw_base.Retrieve(x);
                //dw_bank.Retrieve(x);
                dw_base.Redraw();
                //dw_bank.Redraw();
            }
        }
        return 1;
    }
 
    int onload()
    {
        //maint::onload();
        //maint::onloaded();
        dw_base = GetControl("dw_base");
        dw_cell = new xcell;
        dw_cell.setNativePointer(dw_base.QueryItem("ixcell"));
        dw_base.openUrl("/sale/view/Payment/template/Payment/maint");
        //alert("1233");
        OnRetrieve();
        OnAttachEvent();
        //dw_base = GetControl("dw_base");
        
    }
    
    int onloaded()
    {    
        //maint::onloaded();
        //alert("response");
        //dw_base = GetControl("dw_base");
        //dw_cell = new xcell;
        //dw_cell.setNativePointer(dw_base.QueryItem("ixcell"));
        return -1; 
    }
    
};