xj qian
2024-07-09 69b7db403da8d663f388c61c37567f357fbd9236
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
þÿuse "xcontrol.vframe.vbusiness.vd"
use "xbase.vframe.vbusiness.vd"
use "supplier.view.vd"
 
unit trade
[
    class ExportCreditMaint : public frame
    {
        xdwtable    dw_base;
        xnode    m_agentNode;    //Agent Condition
        int hObject = 0;
        xdwgrid     dw_item;
 
        int SetAgent()
        {
            string xfNodeAgentArea = "agentarea";
            xnode anode = GetAgentNode(xfNodeAgentArea);
            if (m_agentNode)
            {
                SetAgentNodeContent(anode, m_agentNode);
            }
            else
            {
                msxml::IXMLDOMElement xframeElement = GetElement();
                msxml::IXMLDOMElement agent = xframeElement.selectSingleNode("agent/" + xfNodeAgentArea + "[1]/*");
                if (agent)
                {
                    string s = agent.xml;
                    m_agentNode = SetAgentNodeContent(anode, s);
                }
            }
            return 1;
        }
 
        string GetGuid()
        {
            return publiccode::GetGuid();
        }
 
        int OnSaveEx()
        {
            dw_base.AcceptText();
            string CustomerID = dw_base.GetItemString(1, "CustomerID", 0);
            if (CustomerID == "")
            {
                alert("Npe¹T yðN:zzÿ");
                return -1;
            }
            string PaymentMethod = dw_base.GetItemString(1, "PaymentMethod", 0);
            if (PaymentMethod == "")
            {
                alert("e/NØe¹_N:zzÿ");
                return -1;
            }
            string EffectiveDate = dw_base.GetItemString(1, "EffectiveDate", 0);
            if (EffectiveDate == "")
            {
                alert("ueHeågN:zzÿ");
                return -1;
            }
            string CreditTerm = dw_base.GetItemString(1, "CreditTerm", 0);
            if (CreditTerm == "")
            {
                alert("Oáu(g–PN:zzÿ");
                return -1;
            }
            string CreditLimit = dw_base.GetItemString(1, "CreditLimit", 0);
            if (CreditLimit == "")
            {
                alert("Oáu(˜^¦N:zzÿ");
                return -1;
            }
            string RegistrationNumber = dw_base.GetItemString(1, "RegistrationNumber", 0);
            if (RegistrationNumber == "")
            {
                alert("Npe¹lèQŒS÷N:zzÿ");
                return -1;
            }
            string FreeDate = dw_base.GetItemString(1, "FreeDate", 0);
            if (FreeDate == "")
            {
                alert("•òngN:zzÿ");
                return -1;
            }
 
            string BuyerCode = dw_base.GetItemString(1, "BuyerCode", 0);
            if (BuyerCode == "")
            {
                alert("Npe¹NãxN:zz,‹÷W([¢b7N-XkQ™Npe¹Nãxÿ");
                return -1;
            }
            else
            {
                xml check_x = ViewObject::RetrieveData("/sale/data/Expense3/ExportCreditBuyerCode", "BuyerCode", BuyerCode);
                if (check_x)
                {
                    string cut = check_x.GetXmlDoc().documentElement.getAttribute("count");
                    int cutEx = cut.toInt();
                    string ExportCreditID = dw_base.GetItemString(1, "ExportCreditID", 0);
                    if (cutEx > 0)
                    {
                        if (cutEx == 1 && ExportCreditID != "")
                        {
                            return OnSave();
                        }
                        alert("Npe¹Nãx]ò[XW(ÿ ‹÷‘Íe°    béNpe¹T yðÿ");
                        return -1;
                    }
                }
            }
 
            string BIType = dw_base.GetItemString(1, "BIType", 0);
            if (BIType != "Y")
            {
                alert("g*N
O [¡bySUcnÿ");
                return -1;
            }
 
            OnSave();
            return 1;
        }
 
        int OnSave()
        {
            xml x = new xml;
            x.setNativePointer(xml::CreateInstance());
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());
            dw_base.AcceptText();
            dw_base.DwUpdateAllTo(x.GetXmlDoc());
            string error = "";
            arg.AddArg("content", x.GetXml());
            if (url::get("/sale/data/Expense3/update/ExportCredit", arg.GetString(), x) != 1)
            {
                error = x.GetXmlDoc().text;
                //alert(error);
            }
            else
            {
                string str = x.GetXmlDoc().documentElement.getAttribute("text");
                if (str == "true")
                {
                    dw_base.ResetUpdateStatus();
                    //alert("OÝ[XbRŸ!");
                }
                else
                {
                    alert("OÝ[XY1%!");
                }
                //alert(str);
            }
            if (dw_item.GetRowCount() > 0)
            {
                OnSaveS();
            }
            else
            {
                alert("OÝ[XbRŸ!");
                OmSearch();
            }
            return 1;
        }
 
        int OnSaveS()
        {
            xml x1 = new xml;
            x1.setNativePointer(xml::CreateInstance());
            dw_item.AcceptText();
            dw_item.DwUpdateAllToEx(x1.GetXmlDoc());
            xaserverarg arg1 = new xaserverarg;
            arg1.setNativePointer(xaserverarg::CreateInstance());
            arg1.AddArg("content", x1.GetXml());
            trace(x1.GetXml());
            if (url::get("/sale/data/Expense3/update/ExportCreditItem", arg1.GetString(), x1) != 1)
            {
                string error = x1.GetXmlDoc().text;
                alert("err:" + error);
                return 1;
            }
            string str = x1.GetXmlDoc().documentElement.getAttribute("text");
            if (str == "true")
            {
                dw_item.ResetUpdateStatus();
                alert("OÝ[XbRŸ!");
                OmSearch();
            }
            else
            {
                alert("OÝ[XY1%!");
            }
            return 1;
        }
 
        //q&p¹oÀm;YtQýep
        int OnSetFocus(ref TEvent evt, int param)
        {
            //‘Ín]åQwga
            SetAgent();
            return 1;
        }
 
        //T}NäSÑ^Qýep
        int OnCmdDispatch(string comdid)
        {
            string NO = publiccode::GetUser().no;
            string Jobname = publiccode::GetUser().jobname;
            if (NO == "admin") Jobname = "";
            if (Jobname == "NR¡TX")
            {
                if (comdid == "XmSearch")
                {
                    OmSearch();
                    return 1;
                }
                return 1;
            }
 
            if (comdid == "XmSave")
            {
                OnSaveEx();
                return 1;
            }
            if (comdid == "XmSearch")
            {
                OmSearch();
                return 1;
            }
            if (comdid == "AddItem")
            {
                AddItem();
                return 1;
            }
            if (comdid == "DelItem")
            {
                dw_item.DeleteRow(0);
                return 1;
            }
            return 0;
        }
 
        int OnPremiumAmount()
        {
            double PremiumRate = dw_base.GetItemDouble(1, "PremiumRate");
            double InsuredAmount = 0.00;
 
 
            for (int i = 1; i <= dw_item.GetRowCount(); i++)
            {
                InsuredAmount = dw_item.GetItemDouble(i, "InsuredAmount");
                trace(InsuredAmount.toString());
                trace((InsuredAmount * PremiumRate / 100).toString());
                dw_item.SetItemDouble(i, "PremiumAmount", (InsuredAmount * PremiumRate / 100).round(2));
            }
            dw_item.Redraw();
            return 1;
        }
 
        int AddItem()
        {
            string  CustomerID = dw_base.GetItemString(1, "CustomerID");
            if (CustomerID != "")
            {
                xaserverarg arg = new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());
                arg.AddArg("HWND", GetHWND().toString());
                arg.AddArg("CustomerID", CustomerID);
                OpenWindow("dev:xpage[ExportCredit.SwitchTo.vx]", cast(arg as int));
 
                if (arg.GetArgString("items") != "")
                {
                    string str = arg.GetArgString("items");
                    ONImportXml(str);
                }
            }
            return 1;
        }
 
        int ONImportXml(string str)
        {
            if (str != "")
            {
                xml x = new xml;
                x.setNativePointer(xml::CreateInstance());
                x.LoadXml(str);
                msxml::IXMLDOMNodeList items = x.GetXmlDoc().selectNodes("data/Item");
                int len = items.length;
                int row = 0;
 
                string ID = dw_base.GetGuid(1);
 
                for (int i = 0; i < len; i++)
                {
                    if (i == 0 && dw_item.GetRowCount() > 0 && dw_item.GetItemString(dw_item.GetRowCount(), "InvoiceNo") == "")
                    {
                        row = dw_item.GetRowCount();
                    }
                    else
                    {
                        row = dw_item.InsertRow(0);
                    }
 
                    msxml::IXMLDOMNode e = items.item(i);
 
                    dw_item.SetItemString(row, "ExportCreditID", ID);
                    if (e.selectSingleNode("InvoiceNo"))dw_item.SetItemString(row, "InvoiceNo", e.selectSingleNode("InvoiceNo").text);
                    if (e.selectSingleNode("SalespersonName"))dw_item.SetItemDisplayString(row, "SalespersonID", e.selectSingleNode("SalespersonName").text);
                    if (e.selectSingleNode("SalespersonID"))dw_item.SetItemString(row, "SalespersonID", e.selectSingleNode("SalespersonID").text);
                    if (e.selectSingleNode("CurrencyCode"))dw_item.SetItemString(row, "CurrencyCode", e.selectSingleNode("CurrencyCode").text);
                    if (e.selectSingleNode("Amount")) dw_item.SetItemString(row, "Amount", e.selectSingleNode("Amount").text);
                    if (e.selectSingleNode("ETD")) dw_item.SetItemString(row, "ETD", e.selectSingleNode("ETD").text);
                }
            }
            return 1;
        }
 
        //[¡bySUcn
        int DocCount(string guid)
        {
            dw_base.AcceptText();
            xdwtable dw = dw_base.FindDwTable("ExportCredit", 0);
            string count = "0";
            string entityid = dw_base.GetItemString(1, "ExportCreditID", 0);
            if (entityid.length() <= 0)
            {
                entityid = guid;
                dw_base.SetGuid(1, entityid);
            }
            xml x1 = ViewObject::RetrieveData("/sale/data/TDocument3/attachment/GetDocCountEx_s", "entityid", entityid);
            msxml::IXMLDOMNodeList items = x1.GetXmlDoc().selectNodes("data/Item");
            msxml::IXMLDOMNode t = items.item(0);
            if (t.selectSingleNode("count"))count = t.selectSingleNode("count").text;
            if (count == "0")
            {
                dw_base.SetItemString(1, "BIType", "N");
            }
            else
            {
                dw_base.SetItemString(1, "BIType", "Y");
            }
        }
 
        int OnItemClick(ref TNotifyEvent evt, int p)
        {
            ref DWNMHDR  hdr = evt.pnmh;
            string value = hdr.data;
            //alert(value);
            //xdwtable dw = dw_base.FindDwTable("item2",0);
            //xdwtable dw1 = dw_base.FindDwTable("item3",0);                            
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());
 
            if (value == "[¡bySUN
O *")
            {
                string guid = dw_base.GetGuid(1);
                if (guid.length() <= 0)
                {
                    guid = publiccode::GetGuid();
                    dw_base.SetGuid(1, guid);
                }
                arg.AddArg("entityid", guid);
                int p3 = cast(arg as int);
                OpenWindow("dev:xpage[maint.Document.ExportCredit.v3.vx]", p3);
                DocCount(guid);
            }
 
            return 1;
        }
 
        int OnBaseItemChanged(ref TNotifyEvent evt, int p)
        {
            ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
            string colname = hdr.colname;
            string value = hdr.data;
 
            string dwname = "dw_base";
            if (value != "")
            {
                msxml::IXMLDOMNodeList nlist = GetElement().selectNodes("//*[@name='" + dwname + "']/trans[@for='" + colname + "']");
                ViewObject::TransData(nlist, dw_base, hdr.row, colname, value);
            }
            if (colname == "PremiumRate")
            {
                //OnPremiumAmount();
            }
            dw_item.Redraw();
            return 1;
        }
        //T}NäYtN‹Nö
        int OnXCommand(ref TXCommandEvent evt, int param)
        {
            return OnCmdDispatch(evt.pStrID);
        }
 
        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;
            string dwname = "dw_item";
            if (colname == "Type")
            {
                if (value == "N")
                {
                    dw_item.SetItemString(row, "CreatorID", "");
                    dw_item.SetItemDisplayString(row, "CreatorID", "");
                    dw_item.SetItemString(row, "CreateDate", "");
                    dw_item.SetItemString(row, "Note", "");
                }
                else
                {
                    string Createdate = publiccode::GetCurrentDate();
                    string userid = publiccode::GetUser().id;
                    string username = publiccode::GetUser().name;
                    dw_item.SetItemString(row, "CreatorID", userid);
                    dw_item.SetItemDisplayString(row, "CreatorID", username);
                    dw_item.SetItemString(row, "CreateDate", Createdate);
                    dw_item.SetGuid(row, publiccode::GetGuid());
                }
            }
 
            if (colname == "InsuredAmount")
            {
                double InsuredAmount = dw_item.GetItemDouble(row, "InsuredAmount");
                double PremiumRate = dw_base.GetItemDouble(1, "PremiumRate");
                dw_item.SetItemDouble(row, "PremiumAmount", (InsuredAmount * PremiumRate / 100).round(2));
 
                //OnPremiumAmount();
            }
            dw_item.Redraw();
            return 1;
        }
 
        int OnDoubleClicked(ref TNotifyEvent evt, int p)
        {
            ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
            string colnames = hdr.colname;
            string values = hdr.data;
            int rows = hdr.row;
            string dwname = "dw_item";
 
            string Amount = dw_item.GetItemString(rows, "Amount");
            dw_item.SetItemString(rows, "InsuredAmount", Amount);
 
            double PremiumRate = dw_base.GetItemDouble(1, "PremiumRate");
            double InsuredAmount = Amount.toDouble();
 
            dw_item.SetItemDouble(rows, "PremiumAmount", (InsuredAmount * PremiumRate / 100).round(2));
            dw_item.Redraw();
            return 1;
        }
        int OnAttachEvent()
        {
            //~Ñ[š]åQwgap¹QûN‹Nö
            AttachEvent("WM_XCOMMAND", OnXCommand);
            //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
            AttachEvent("WM_SETFOCUS", OnSetFocus);
            AttachEvent("dw_base", "DWV_CLICKED", OnItemClick);
            AttachEvent("dw_base", "DWV_ITEMCHANGED", OnBaseItemChanged);
            AttachEvent("dw_item", "DWV_DOUBLECLICKED", OnDoubleClicked);//ˆLSÌQû
            AttachEvent("dw_item", "DWV_ITEMCHANGED", OnItemChanged);
        }
 
 
        int  OnRetrieve(string ExportCreditID)
        {
            xml x = new xml;
            x.setNativePointer(xml::CreateInstance());
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());
            arg.AddArg("ExportCreditID", ExportCreditID);
            if (getUrl("/sale/data/Expense3/ExportCreditByID", arg.GetString(), x) != 1)
            {
                trace(x.GetXmlDoc().text);
                return -1;
            }
            else
            {
                dw_base.Retrieve(x);
                dw_base.Redraw();
            }
 
 
            if (url::get("/sale/data/Expense3/GetExportCreditItemEx", arg.GetString(), x) != 1)
            {
                trace(x.GetXmlDoc().text);
                return -1;
            }
            dw_item.Retrieve(x);
            dw_item.Redraw();
            return 1;
        }
 
        int OnNewInital()
        {
            string sdate = publiccode::GetCurrentDate();
            string m_userid = publiccode::GetUser().id;
            string m_username = publiccode::GetUser().name;
            string guid = publiccode::GetGuid();
 
 
            dw_base.SetItemString(1, "PaymentMethod", "O/A");
 
            dw_base.SetItemString(1, "QuotaState", "g    eH");
            dw_base.SetItemString(1, "Whether", "f/");
            dw_base.SetItemString(1, "RejectionRatio", "90");
            dw_base.SetItemString(1, "BusinessRisk", "90");
            dw_base.SetGuid(1, guid);
 
        }
 
        int OmSearch()
        {
            if (GetParam())
            {
                xaserverarg arg = GetParam();
                if (arg.GetArgString("ExportCreditID") != "")
                {
                    OnRetrieve(arg.GetArgString("ExportCreditID"));
 
                }
 
            }
            else
            {
                string ExportCreditID = dw_base.GetGuid(1);
                OnRetrieve(ExportCreditID);
            }
            return 1;
        }
 
        int onload()
        {
            dw_base = GetControl("dw_base");
            dw_base.openUrl("/sale/view/expense3/ExportCredit");
 
            dw_base.SetColHeaderHeight(0);
            dw_base.SetRowSelectorWidth(0);
            dw_base.SetHScrollState(false);
            dw_base.SetVScrollState(false);
 
            dw_item = GetControl("dw_item");
            dw_item.openUrl("/sale/view/expense3/ExportCreditItem");
 
            dw_item.SetColumnState("ExportCreditItemID", false);
            dw_item.SetColumnState("ExportCreditID", false);
 
            OnAttachEvent();
 
 
            if (GetParam())
            {
                xaserverarg arg = GetParam();
                if (arg.GetArgString("ExportCreditID") != "")
                {
                    OnRetrieve(arg.GetArgString("ExportCreditID"));
                }
 
            }
            else
            {
                OnNewInital();
            }
            return 1;
        }
 
        int onloaded()
        {
            SetAgent();
            return 1;
        }
 
    };
]