#include <wobject/xstring.hpp>
|
#include <xcontrol/xtreeview.hpp>
|
#include <xcontrol/xdwgrid.hpp>
|
#include <xcontrol/xcell.hpp>
|
|
|
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
|
#include "viewobject/view.base.hpp"
|
|
using xml = KXMLDOMDocument;
|
|
class __declspec(dllexport) PaymentTermEdit : public xframe
|
{
|
public:
|
xdwtable dw_1;
|
xdwtable dw_p;
|
|
xcell dw_cell;
|
vcontrol vc;
|
|
xstring sCryno;
|
|
public:
|
PaymentTermEdit(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
|
public:
|
static PaymentTermEdit* CreateInstance(void* implPtr, void* hWnd)
|
{
|
PaymentTermEdit* pWin = new PaymentTermEdit(implPtr, (HWND)hWnd);
|
return pWin;
|
}
|
|
int OnAddrow()
|
{
|
dw_p = dw_1.FindDwTable(L"Item");
|
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);
|
if (dDueAmount <= 0)
|
dw_p.SetItemDouble(irow, L"DuePercent", dPercnet);
|
|
return 1;
|
}
|
|
int OnDeleterow()
|
{
|
dw_p = dw_1.FindDwTable(L"Item");
|
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_1.FindDwTable(L"Item");
|
int icnt = dw_p.GetRowCount();
|
if (icnt < 1) return L"";
|
xstring sTxt = L"";
|
//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_1.AcceptText();
|
//判断是否有必输值为空
|
dw_p = dw_1.FindDwTable(L"Item");
|
double dPercnet = 0;
|
double dAmount = 0;
|
xstring sChargeAll = L"";
|
if (dw_p)
|
{
|
int i;
|
for (i = 1; i <= dw_p.GetRowCount(); i++)
|
{
|
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 (!sPaymentMethod) sPaymentMethod = L"";
|
if (!sDueDays) sDueDays = L"";
|
if (!sDuePercent) sDuePercent = L"";
|
if (!sDueAmount) sDueAmount = L"";
|
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.00)
|
{
|
//alert(dPercnet.toString());
|
if (dAmount <= 0.0)
|
{
|
alert(L"比率不等于100!");
|
return 0;
|
}
|
}
|
}
|
|
xstring sTxt = OnCreateTxt();
|
dw_1.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_1.FindDwTable(L"Item");
|
|
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();
|
//alert(sTxt);
|
dw_1.SetItemString(1, L"PaymentTermEx", sTxt);
|
}
|
|
return 1;
|
}
|
|
int OnClick(TEvent* evt, LPARAM p)
|
{
|
/*
|
ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR);
|
xstring value = hdr.data;
|
xstring colname = hdr.colname;
|
int row = hdr.row;
|
xaserverarg arg=new xaserverarg;
|
arg.setNativePointer(arg.CreateInstance());
|
xdwtable dw;
|
dw = dw_1.FindDwTable(L"Item");
|
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;
|
}
|
if (dDueAmount > 0)
|
{
|
xstring strold = dw_cell.GetCellProps(row,4);
|
if (strold.find(L"cellprotect=\"保护\"") > 0)
|
return 0;
|
strold = strold.replace(L"cellprotect=\"\"",L"cellprotect=\"保护\"",0);
|
dw_cell.SetCellProps(row,4,strold);
|
}
|
else
|
{
|
xstring strold1 = dw_cell.GetCellProps(row,4);
|
if (strold1.find(L"cellprotect=\"保护\"") > 0)
|
{
|
strold1 = strold1.replace(L"cellprotect=\"保护\"",L"cellprotect=\"\"",0);
|
dw_cell.SetCellProps(row,4,strold1);
|
}
|
}
|
|
}
|
|
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)
|
{
|
xstring strold2 = dw_cell.GetCellProps(row,5);
|
|
if (strold2.find(L"cellprotect=\"保护\"") > 0)
|
return 0;
|
strold2 = strold2.replace(L"cellprotect=\"\"",L"cellprotect=\"保护\"",0);
|
dw_cell.SetCellProps(row,5,strold2);
|
}
|
else
|
{
|
xstring strold3 = dw_cell.GetCellProps(row,5);
|
if (strold3.find(L"cellprotect=\"保护\"") > 0)
|
{
|
strold3 = strold3.replace(L"cellprotect=\"保护\"",L"cellprotect=\"\"",0);
|
dw_cell.SetCellProps(row,5,strold3);
|
}
|
}
|
}
|
|
}
|
*/
|
return 1;
|
}
|
|
int OnCmdDispatch(xstring comdid)
|
{
|
|
if (comdid == L"addrow") return OnAddrow();
|
else if (comdid == L"deleterow") return OnDeleterow();
|
else if (comdid == L"xmOk") return OnOk();
|
|
return 0;
|
}
|
|
int OnXCommand(TEvent* evt, LPARAM p)
|
{
|
return OnCmdDispatch(evt->xcommand.pStrID);
|
}
|
|
int OnAttachEvent()
|
{
|
AttachEvent(L"WM_XCOMMAND", (FEvent)&PaymentTermEdit::OnXCommand);
|
AttachEvent(L"dw_1", L"DWV_ITEMCHANGED", (FEvent)&PaymentTermEdit::OnItemChanged);
|
AttachEvent(L"dw_1", L"DWV_CLICKED", (FEvent)&PaymentTermEdit::OnClick);
|
|
return 1;
|
}
|
|
int OnInit()
|
{
|
xaserver Args = GetArg();
|
|
XXmlContentSvr xdoc = new XXmlContentSvr;
|
xdoc.setNativePointer(Args);
|
vc = new vcontrol;
|
vc.xdoc = xdoc;
|
|
vbind bind = new vbind;
|
bind.bind(dw_1, vc);
|
|
xml x;
|
|
x.loadXML(vc.GetContent());
|
|
//alert(x.GetXml());
|
|
dw_1.Retrieve(x);
|
|
//if (x.GetXmlDoc().documentElement.selectSingleNode(L"CurrencyCode"))
|
//{
|
// sCryno = x.GetXmlDoc().documentElement.selectSingleNode(L"CurrencyCode").text;
|
//}
|
|
return 1;
|
}
|
|
int onload()
|
{
|
dw_1 = GetControl(L"dw_1");
|
dw_1.openUrl(L"/sale/view/SaleOrder/template/payment"); //base.maint.so.tpl/payment
|
|
/*
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
if(url::get(L"/sale/view/SaleOrder/template/SaleOrder/payment1",L"",x)!=1) //SO.updata.oldserver.pr.xq
|
{
|
xstring error = x.GetXmlDoc().text;
|
trace(error);
|
return 0;
|
}
|
|
alert(L"1:"+x.GetXml());*/
|
|
dw_1.SetColHeaderHeight(0);
|
dw_1.SetRowSelectorWidth(0);
|
dw_1.SetScrollState(false);
|
|
dw_cell = new xcell;
|
dw_cell.setNativePointer(dw_1.QueryItem(L"ixcell"));
|
|
OnAttachEvent();
|
|
if (GetParam())OnInit();
|
|
return 1;
|
}
|
};
|