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