#include <wobject/xstring.hpp>
|
#include <xcontrol/xtreeview.hpp>
|
#include <xcontrol/xdwgrid.hpp>
|
#include <wobject/xdouble.hpp>
|
|
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
|
#include "viewobject/view.base.hpp"
|
|
using xml = KXMLDOMDocument;
|
class __declspec(dllexport) MaintVATInvoice : public xframe
|
{
|
public:
|
xdwgrid dw_list;
|
xdwtable dw_base;
|
xstring VATInvoiceID;
|
xnode m_agentNode; //Agent Condition
|
public:
|
MaintVATInvoice(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
|
public:
|
static MaintVATInvoice* CreateInstance(void* implPtr, void* hWnd)
|
{
|
MaintVATInvoice* pWin = new MaintVATInvoice(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()
|
{
|
dw_list.AcceptText();
|
xstring error;
|
xstring str;
|
xml x ;
|
xaserverarg arg ;
|
|
|
|
|
dw_list.DwUpdateAllToEx(x);
|
xml x0 ;
|
|
x0.loadXML(L"<data/>");
|
|
KXMLDOMNodeList t = x.selectNodes(L"data/Item[@update.modify]");
|
KXMLDOMElement e1= x0.documentElement();
|
int len = t.length();
|
for(int i=0;i<len;i++)
|
{
|
e1.appendChild(t.item(i));
|
}
|
arg.AddArg(L"content",x0.xml());
|
|
if(xurl::get(L"/sale/data/VATNotify/base/update", arg.GetString(),x0)!=1)
|
{
|
error = x0.text();
|
alert(L"err:"+error);
|
return 1;
|
}
|
str = x0.documentElement().getAttribute(L"text");
|
if(str != L"true")
|
{
|
alert(L"±£´æÊ§°Ü!");
|
return 1;
|
}
|
|
dw_base.AcceptText();
|
xml x1 ;
|
|
dw_base.DwUpdateAllTo(x1);
|
|
arg.AddArg(L"content",x1.xml());
|
if(xurl::get(L"/sale/data/VATNotify/vatinvoice/update", arg.GetString(),x1)!=1)
|
{
|
error = x1.text();
|
alert(L"err:"+error);
|
return 1;
|
}
|
str = x1.documentElement().getAttribute(L"text");
|
if(str != L"true")
|
{
|
alert(L"±£´æÊ§°Ü!");
|
return 1;
|
}
|
|
dw_list.ResetUpdateStatus();
|
dw_base.ResetUpdateStatus();
|
|
alert(L"±£´æ³É¹¦!");
|
CloseWindow();
|
return 1;
|
}
|
|
int RecalcVatAmt(int row)
|
{
|
double VatRate = dw_list.GetItemDouble(row,L"VATRate");
|
if((int)(VatRate*100) < 1) VatRate = 17.0;
|
double VATRefundRate = dw_list.GetItemDouble(row,L"VATRefundRate");
|
double billAmt = dw_list.GetItemDouble(row,L"VATBillAmount");
|
double VatAmt = billAmt /(100.0+VatRate)*VatRate;
|
double VATRefundAmt = billAmt /(100.0+VatRate)*VATRefundRate;
|
dw_list.SetItemDouble(row,L"VATAmount",VatAmt);
|
dw_list.SetItemDouble(row,L"RefundAmount",VATRefundAmt);
|
dw_list.SetItemDouble(row,L"NetAmount",billAmt - VatAmt);
|
|
return 1;
|
}
|
|
//ºÏ¼Æ
|
int SUMRecalcVatAmt()
|
{
|
double VATBillAmountEx=0;
|
double DeduceAmountEx=0;
|
double GoodsAmountEx=0;
|
double OverAmountEx=0;
|
double RefundAmountEx=0;
|
double VATAmountEx=0;
|
for(int i = 1;i <=dw_list.GetRowCount(); ++i)
|
{
|
double VATBillAmount=dw_list.GetItemDouble(i,L"VATBillAmount");
|
VATBillAmountEx+=VATBillAmount;
|
double DeduceAmount=dw_list.GetItemDouble(i,L"DeduceAmount");
|
DeduceAmountEx+=DeduceAmount;
|
double NetAmount=dw_list.GetItemDouble(i,L"NetAmount");
|
GoodsAmountEx+=NetAmount;
|
double OverAmount=dw_list.GetItemDouble(i,L"OverAmount");
|
OverAmountEx+=OverAmount;
|
double RefundAmount=dw_list.GetItemDouble(i,L"RefundAmount");
|
RefundAmountEx+=RefundAmount;
|
double VATAmount=dw_list.GetItemDouble(i,L"VATAmount");
|
VATAmountEx+=VATAmount;
|
|
}
|
dw_base.SetItemDouble(1,L"VATBillAmount",VATBillAmountEx);
|
dw_base.SetItemDouble(1,L"DeduceAmount",DeduceAmountEx);
|
dw_base.SetItemDouble(1,L"GoodsAmount",GoodsAmountEx);
|
dw_base.SetItemDouble(1,L"OverAmount",OverAmountEx);
|
dw_base.SetItemDouble(1,L"RefundAmount",RefundAmountEx);
|
dw_base.SetItemDouble(1,L"VATAmount",VATAmountEx);
|
|
dw_base.Redraw();
|
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(value==L"") return 1;
|
if(colname==L"VATAmount")
|
{
|
double VATAmount=dw_list.GetItemDouble(row,L"VATAmount");
|
double billAmtt= dw_list.GetItemDouble(row,L"VATBillAmount");
|
|
double v4= billAmtt - VATAmount;
|
int v5=(int)VATAmount;
|
if(v5>=0){
|
dw_list.SetItemDouble(row,L"NetAmount",v4);
|
dw_list.Redraw();
|
|
dw_base.SetItemDouble(1,L"GoodsAmount",v4);
|
dw_base.SetItemDouble(1,L"VATAmount",VATAmount);
|
dw_base.Redraw();
|
|
}
|
SUMRecalcVatAmt();
|
}
|
else if(colname==L"RefundAmount")
|
{
|
double RefundAmountt=dw_list.GetItemDouble(row,L"RefundAmount");
|
//dw_base.SetItemDouble(1,L"RefundAmount",RefundAmountt);
|
//dw_base.Redraw();
|
SUMRecalcVatAmt();
|
}
|
else if(colname==L"VATBillAmount")
|
{
|
RecalcVatAmt(row);
|
|
if(value==L"" || value==L"0.00")
|
{
|
dw_list.SetItemString(row,L"OverAmount",L"");
|
dw_list.SetItemString(row,L"DeduceAmount",L"");
|
}else
|
{
|
double NAmount = dw_list.GetItemDouble(row,L"NAmount");
|
double billAmt = dw_list.GetItemDouble(row,L"VATBillAmount");//¿ªÆ±½ð¶î
|
double VATAmount1=dw_list.GetItemDouble(row,L"VATAmount"); //Ôöֵ˰¶î
|
double oAmt1 = dw_list.GetItemDouble(row,L"OverAmount");//¶à¿ª½ð¶î
|
double RefundAmount = dw_list.GetItemDouble(row,L"RefundAmount");
|
double dAmt1 = dw_list.GetItemDouble(row,L"DeduceAmount");//¿Û¿î½ð¶î
|
double Amt = NAmount - billAmt ;
|
int v1 = (int)Amt;
|
int v2 = (billAmt - NAmount);
|
if(v2 < 0) v2 = - v2;
|
if(v1 <0 || v2<49 )
|
{
|
dw_list.SetItemDouble(row,L"OverAmount",billAmt - NAmount);
|
dw_list.SetItemDouble(row,L"DeduceAmount",0.0);
|
/*dw_base.SetItemDouble(1,L"GoodsAmount",billAmt - VATAmount1);
|
dw_base.SetItemDouble(1,L"VATAmount",VATAmount1);
|
dw_base.SetItemDouble(1,L"VATBillAmount",billAmt);
|
dw_base.SetItemDouble(1,L"DeduceAmount",0.0);
|
dw_base.SetItemDouble(1,L"OverAmount",billAmt - NAmount);
|
dw_base.SetItemDouble(1,L"RefundAmount",RefundAmount);*/
|
}
|
else
|
{
|
dw_list.SetItemDouble(row,L"OverAmount",0.0);
|
dw_list.SetItemDouble(row,L"DeduceAmount", NAmount - billAmt);
|
/*dw_base.SetItemDouble(1,L"GoodsAmount",billAmt - VATAmount1);
|
dw_base.SetItemDouble(1,L"VATAmount",VATAmount1);
|
dw_base.SetItemDouble(1,L"VATBillAmount",billAmt);
|
dw_base.SetItemDouble(1,L"DeduceAmount",NAmount - billAmt);
|
dw_base.SetItemDouble(1,L"OverAmount",0.0);
|
dw_base.SetItemDouble(1,L"RefundAmount",RefundAmount);*/
|
}
|
|
}
|
SUMRecalcVatAmt();
|
dw_list.Redraw();
|
}
|
else if(colname==L"DeduceAmount" || colname==L"OverAmount")
|
{
|
double dAmt = dw_list.GetItemDouble(row,L"DeduceAmount");
|
double oAmt = dw_list.GetItemDouble(row,L"OverAmount");
|
double nAmt = dw_list.GetItemDouble(row,L"NAmount");
|
double VatRate = dw_list.GetItemDouble(row,L"VATRate");
|
if((int)(VatRate*100) < 1) VatRate = 17.0;
|
double VatAmt = (nAmt + oAmt - dAmt)/(100.0+VatRate)*VatRate; //Ôöֵ˰¶î
|
dw_list.SetItemDouble(row,L"VATBillAmount",nAmt + oAmt - dAmt);
|
/*if(oAmt>0){
|
dw_base.SetItemDouble(1,L"GoodsAmount",nAmt + oAmt - dAmt - VatAmt);
|
dw_base.SetItemDouble(1,L"VATAmount",VatAmt);
|
dw_base.SetItemDouble(1,L"VATBillAmount",nAmt + oAmt - dAmt);
|
dw_base.SetItemDouble(1,L"OverAmount",oAmt);
|
}*/
|
RecalcVatAmt(row);
|
SUMRecalcVatAmt();
|
dw_list.Redraw();
|
}
|
|
return 1;
|
}
|
|
|
|
//½¹µã¼¤»î´¦Àíº¯Êý
|
int OnSetFocus(TEvent* evt, LPARAM param)
|
{
|
//ÖØÖù¤¾ßÌõ
|
SetAgent();
|
return 1;
|
}
|
|
//ÃüÁî·¢²¼º¯Êý
|
int OnCmdDispatch(xstring comdid)
|
{
|
if(comdid==L"xmClose")
|
{
|
CloseWindow();
|
return 1;
|
}else if(comdid==L"xmSave")
|
{
|
return OnSave();
|
}
|
return 0;
|
}
|
|
|
|
//ÃüÁî´¦Àíʼþ
|
int OnXCommand(TEvent* evt, LPARAM param)
|
{
|
return OnCmdDispatch(evt->xcommand.pStrID);
|
}
|
|
int OnItemChangedTwo(TEvent* evt, LPARAM p)
|
{
|
DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
|
xstring colname=hdr.colname;
|
xstring value = hdr.data;
|
|
if (colname == L"RefundAmount")
|
{
|
double RefundAmount2 = dw_base.GetItemDouble(hdr.row,L"RefundAmount");
|
dw_base.SetItemDouble(hdr.row,L"TaxfundAmount", xdouble((RefundAmount2)).round(2));
|
}
|
|
double RefundAmount= dw_base.GetItemDouble(hdr.row,L"RefundAmount");
|
double TaxfundAmount1 = dw_base.GetItemDouble(hdr.row,L"TaxfundAmount");
|
if(TaxfundAmount1 ==0.00)
|
{
|
dw_base.SetItemDouble(hdr.row,L"TaxfundAmount", xdouble((RefundAmount)).round(2));
|
}
|
if (colname == L"TaxfundAmount" || colname == L"AlreadyRefundAmount" || colname == L"RefundAmount")
|
{
|
double TaxfundAmount = dw_base.GetItemDouble(hdr.row,L"TaxfundAmount");
|
double AlreadyRefundAmount = dw_base.GetItemDouble(hdr.row,L"AlreadyRefundAmount");
|
dw_base.SetItemDouble(hdr.row,L"NotRefundAmount", xdouble((TaxfundAmount - AlreadyRefundAmount)).round(2));
|
}
|
return 1;
|
}
|
|
int OnAttachEvent()
|
{
|
//°ó¶¨¹¤¾ßÌõµã»÷ʼþ
|
AttachEvent(L"WM_XCOMMAND", (FEvent)&MaintVATInvoice::OnXCommand);
|
//»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
|
AttachEvent(L"WM_SETFOCUS", (FEvent)&MaintVATInvoice::OnSetFocus);
|
AttachEvent(L"dw_list",L"DWV_ITEMCHANGED", (FEvent)&MaintVATInvoice::OnItemChanged);
|
AttachEvent(L"dw_base",L"DWV_ITEMCHANGED", (FEvent)&MaintVATInvoice::OnItemChangedTwo);
|
return 1;
|
}
|
|
|
int OnRetrieve()
|
{
|
xml x ;
|
|
xaserverarg arg = GetArg();
|
|
arg.AddArg(L"VATInvoiceID",VATInvoiceID);
|
if (getUrl(L"/sale/data/VATNotify/vatinvoice/base",arg.GetString(),x)!=1)
|
{
|
trace(x.text());
|
return -1;
|
}else
|
{
|
dw_base.Retrieve(x);
|
dw_base.Redraw();
|
}
|
|
if (getUrl(L"/sale/data/VATNotify/vatinvoice/item",arg.GetString(),x)!=1)
|
{
|
trace(x.text());
|
return -1;
|
}else
|
{
|
dw_list.Retrieve(x);
|
dw_list.Redraw();
|
}
|
|
return 1;
|
}
|
|
|
int onload()
|
{
|
SetArg();
|
dw_list = GetControl(L"dw_list");
|
dw_list.openUrl(L"/sale/view/VATNotify/template/VATInvoice/item");
|
|
dw_base = GetControl(L"dw_base");
|
dw_base.openUrl(L"/sale/view/VATNotify/template/VATInvoice/base");
|
|
|
|
VATInvoiceID = L"";
|
|
|
if (GetWinParam())
|
{
|
xaserverarg arg = GetArg();
|
VATInvoiceID = arg.GetArgString(L"VATInvoiceID");
|
|
}
|
|
|
OnAttachEvent();
|
|
if(VATInvoiceID !=L"") OnRetrieve();
|
|
return 1;
|
}
|
|
int onloaded()
|
{
|
SetAgent();
|
|
return 1;
|
}
|
};
|