þÿ#include <wobject/xstring.hpp> #include <xcontrol/xtreeview.hpp> #include <xcontrol/xdwgrid.hpp> #include <wobject/xdouble.hpp> #include <xcontrol/xlayersheet.hpp> #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" #include "viewobject/view.base.hpp" using xml = KXMLDOMDocument; class __declspec(dllexport) SalaryslipEdit : public xframe { public: xdwtable dw_base; xnode m_agentNode; //Agent Condition HWND hObject; bool updated; public: SalaryslipEdit(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} public: static SalaryslipEdit* CreateInstance(void* implPtr, void* hWnd) { SalaryslipEdit* pWin = new SalaryslipEdit(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; } //q&p¹oÀm;YtQýep int OnSetFocus(TEvent* evt, LPARAM param) { //‘Ín]åQwga SetAgent(); return 1; } int OnSave() { xstring SalaryslipNo = dw_base.GetItemString(1, L"SalaryslipNo"); xml x ; if (SalaryslipNo == L"") { x = ViewObject::RetrieveData(L"/sale/data/expense3/view/MakeSalaryslipNo"); SalaryslipNo = x.text(); dw_base.SetItemString(1, L"SalaryslipNo", SalaryslipNo); x.Reset(); } dw_base.AcceptText(); dw_base.DwUpdateAllTo(x); xaserverarg arg; arg.AddArg(L"content", x.xml()); if (xurl::get(L"/sale/data/expense3/update/salaryslip", arg.GetString(), x) != 1) { xstring error = x.text(); alert(L"err:" + error); return 1; } xstring str = x.documentElement().getAttribute(L"text"); if (str == L"true") { dw_base.ResetUpdateStatus(); dw_base.Redraw(); updated = true; alert(L"OÝ[XbRŸ!"); } else { alert(L"OÝ[XY1%!"); } return 1; } //T}NäSÑ^Qýep int OnCmdDispatch(xstring comdid) { if (comdid == L"xmClose") { if (updated) SendMessage(hObject, 0x401, (LPARAM)L"xmRefresh", 0); CloseWindow(); return 1; } else if (comdid == L"xmSave") { OnSave(); } return 0; } int ComputeTotal() { double SalaryAmount = dw_base.GetItemDouble(1, L"SalaryAmount"); double lastSalay = dw_base.GetItemDouble(1, L"lastSalay"); double ttSalary = dw_base.GetItemDouble(1, L"ttSalary"); double lastTotalSalary = dw_base.GetItemDouble(1, L"lastTotalSalary"); double OffsettingAmount = dw_base.GetItemDouble(1, L"OffsettingAmount"); double lastOffsettingAmount = dw_base.GetItemDouble(1, L"lastOffsettingAmount"); double totalOffsetting = OffsettingAmount + lastOffsettingAmount; dw_base.SetItemDouble(1, L"totalOffsetting", totalOffsetting); double tax = ttSalary - totalOffsetting; double totalTax = 0; if (tax > 0.0) { if (tax <= 36000.00) { totalTax = tax * 0.03; } else if (tax > 36000.00 && tax <= 144000.00) { totalTax = tax * 0.10 - 2520.00; } else if (tax > 144000.00 && tax <= 300000.00) { totalTax = tax * 0.20 - 19620.00; } else if (tax > 300000.00 && tax <= 420000.00) { totalTax = tax * 0.25 - 31920.00; } else if (tax > 420000.00 && tax <= 660000.00) { totalTax = tax * 0.30 - 52920.00; } else if (tax > 660000.00 && tax <= 960000.00) { totalTax = tax * 0.35 - 85920.00; } else if (tax > 960000.00) { totalTax = tax * 0.45 - 181920.00; } dw_base.SetItemDouble(1, L"totalTax", totalTax); } return 1; } int ComputeTax() { ComputeTotal(); double totalTax = dw_base.GetItemDouble(1, L"totalTax"); double lastTotalTax = dw_base.GetItemDouble(1, L"lastTotalTax"); double SalaryAmount = dw_base.GetItemDouble(1, L"SalaryAmount"); double PersonalIncomeTax = totalTax - lastTotalTax; if (PersonalIncomeTax < 0.00) { PersonalIncomeTax = 0.00; } dw_base.SetItemDouble(1, L"PersonalIncomeTax", PersonalIncomeTax); PersonalIncomeTax = dw_base.GetItemDouble(1, L"PersonalIncomeTax"); double DeductFeeAount = dw_base.GetItemDouble(1, L"DeductFeeAount"); double ActualAmount = SalaryAmount - PersonalIncomeTax - DeductFeeAount; dw_base.SetItemDouble(1, L"ActualAmount", ActualAmount); dw_base.Redraw(); return 1; } int ComputeIncomeTax() { double DeductFeeAount = dw_base.GetItemDouble(1, L"DeductFeeAount"); double SalaryAmount = dw_base.GetItemDouble(1, L"SalaryAmount"); double SpecialDeductFee = dw_base.GetItemDouble(1, L"SpecialDeductFee"); double OffsettingAmount = DeductFeeAount + SpecialDeductFee + 5000; double IncomeTax = SalaryAmount - OffsettingAmount; dw_base.SetItemDouble(1, L"OffsettingAmount", OffsettingAmount); dw_base.SetItemDouble(1, L"IncomeTax", IncomeTax); return 1; } int ComputeDeductFeeAount() { double EndowmentInsurance = dw_base.GetItemDouble(1, L"EndowmentInsurance"); double MedicalInsurance = dw_base.GetItemDouble(1, L"MedicalInsurance"); double UnemploymentInsurance = dw_base.GetItemDouble(1, L"UnemploymentInsurance"); double HousingProvidentFund = dw_base.GetItemDouble(1, L"HousingProvidentFund"); double LeaveDeductFee = dw_base.GetItemDouble(1, L"LeaveDeductFee"); double OtherDeductFee = dw_base.GetItemDouble(1, L"OtherDeductFee"); //double SpecialDeductFee = dw_base.GetItemDouble(1,L"SpecialDeductFee"); double DeductFeeAount = EndowmentInsurance + MedicalInsurance + UnemploymentInsurance + HousingProvidentFund + LeaveDeductFee + OtherDeductFee; dw_base.SetItemDouble(1, L"DeductFeeAount", DeductFeeAount); 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; xml x ; if (colname == L"PersonID") { if (value == L"") return 0; xml xp = ViewObject::RetrieveData(L"/sale/data/expense3/GetPersonID", L"PersonID", value); KXMLDOMNodeList itemp = xp.selectNodes(L"data/Item"); KXMLDOMNode tp = itemp.item(0); if (tp.selectSingleNode(L"SpecialDeductFeeAmout")) { /*double SpecialDeductFeeAmoutEx = 0.00; xstring SpecialDeductFeeAmout = ; SpecialDeductFeeAmoutEx =SpecialDeductFeeAmout.toDouble();*/ dw_base.SetItemString(1, L"SpecialDeductFee", tp.selectSingleNode(L"SpecialDeductFeeAmout").text()); } if (tp.selectSingleNode(L"DeptName")) { dw_base.SetItemString(1, L"DeptName", tp.selectSingleNode(L"DeptName").text()); dw_base.SetItemDisplayString(1, L"DeptName", tp.selectSingleNode(L"DeptName").text()); } if (tp.selectSingleNode(L"GroupName")) { dw_base.SetItemString(1, L"GroupName", tp.selectSingleNode(L"GroupName").text()); dw_base.SetItemDisplayString(1, L"GroupName", tp.selectSingleNode(L"GroupName").text()); } } if (colname == L"PersonID" || colname == L"SalaryslipDate") { xstring PersonID = dw_base.GetItemString(1, L"PersonID"); xstring SalarysDate = dw_base.GetItemString(1, L"SalaryslipDate"); xstring sdate = publiccode::GetCurrentDate(); if (PersonID == L"") { return 0; } if (SalarysDate == L"") { SalarysDate = sdate; } x = ViewObject::RetrieveData(L"/sale/data/expense3/view/GetLastData", L"PersonID", PersonID, L"SalarysDate", SalarysDate); KXMLDOMNodeList items = x.selectNodes(L"data/amount"); KXMLDOMNode t = items.item(0); double lastSpecialDeductFee = 0.00; double lastOffsettingAmount = 0.00; double lastTotalTax = 0.00; if (t.selectSingleNode(L"lastSpecialDeductFee")) { xstring SpecialDeductFeeTxt = t.selectSingleNode(L"lastSpecialDeductFee").text(); lastSpecialDeductFee = SpecialDeductFeeTxt.toDouble(); dw_base.SetItemDouble(1, L"SpecialDeductFee", lastSpecialDeductFee); ComputeDeductFeeAount(); } if (t.selectSingleNode(L"lastOffsettingAmount")) { xstring lastOffsettingAmountTxT = t.selectSingleNode(L"lastOffsettingAmount").text(); lastOffsettingAmount = lastOffsettingAmountTxT.toDouble(); dw_base.SetItemDouble(1, L"lastOffsettingAmount", lastOffsettingAmount); } if (t.selectSingleNode(L"lastTotalTax")) { xstring lastTotalTaxTxt = t.selectSingleNode(L"lastTotalTax").text(); lastTotalTax = lastTotalTaxTxt.toDouble(); dw_base.SetItemDouble(1, L"lastTotalTax", lastTotalTax); } initial(); ComputeTax(); }if (colname == L"BasicSalary" || colname == L"MealAllowance" || colname == L"MoneyAward") { double BasicSalary = dw_base.GetItemDouble(1, L"BasicSalary"); double MealAllowance = dw_base.GetItemDouble(1, L"MealAllowance"); double MoneyAward = dw_base.GetItemDouble(1, L"MoneyAward"); double SalaryAmount = BasicSalary + MealAllowance + MoneyAward; dw_base.SetItemDouble(1, L"SalaryAmount", SalaryAmount); double lastSalay = dw_base.GetItemDouble(1, L"lastSalay"); dw_base.SetItemDouble(1, L"ttSalary", lastSalay + SalaryAmount); ComputeIncomeTax(); ComputeTax(); } if (colname == L"EndowmentInsurance" || colname == L"MedicalInsurance" || colname == L"UnemploymentInsurance" || colname == L"HousingProvidentFund" || colname == L"LeaveDeductFee" || colname == L"OtherDeductFee" || colname == L"SpecialDeductFee") { ComputeDeductFeeAount(); ComputeIncomeTax(); ComputeTax(); } if (colname == L"SalaryAmount" || colname == L"DeductFeeAount" || colname == L"OffsettingAmount") { ComputeIncomeTax(); ComputeTax(); } if (colname == L"ttSalary") { ComputeTax(); } if (colname == L"PersonalIncomeTax") { double SalaryAmount1 = dw_base.GetItemDouble(1, L"SalaryAmount"); double PersonalIncomeTax = value.toDouble(); double DeductFeeAount = dw_base.GetItemDouble(1, L"DeductFeeAount"); double ActualAmount = SalaryAmount1 - PersonalIncomeTax - DeductFeeAount; dw_base.SetItemDouble(1, L"ActualAmount", ActualAmount); } dw_base.Redraw(); return 1; } //T}NäYtN‹Nö int OnXCommand(TEvent* evt, LPARAM param) { return OnCmdDispatch(evt->xcommand.pStrID); } int OnDWClick(TEvent* evt, LPARAM p) { DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; xstring value = hdr.data; xstring colname = hdr.colname; if (value == L"}/‹¡e6Qe") { HCURSOR hCursor = xutil::SetCursorWait(); xaserverarg arg; xstring PersonID = dw_base.GetItemString(1, L"PersonID"); if (PersonID == L"") { alert(L"‹÷ béTX]å"); return 0; } arg.AddArg(L"PersonID", PersonID); xstring SalaryslipDate = dw_base.GetItemString(1, L"SalaryslipDate"); arg.AddArg(L"SalaryslipDate", SalaryslipDate); OpenWindow(L"dev:xpage[SelectSalaryslip.vx]", arg); xutil::RestoreCursor(hCursor); xstring amount = arg.GetArgString(L"amount"); if (amount != L"") { dw_base.SetItemDouble(1, L"lastSalay", amount.toDouble()); dw_base.SetItemDouble(1, L"ttSalary", amount.toDouble() + dw_base.GetItemDouble(1, L"SalaryAmount")); dw_base.Redraw(); ComputeTax(); } return 1; } } int OnAttachEvent() { //~Ñ[š]åQwgap¹QûN‹Nö AttachEvent(L"WM_XCOMMAND", (FEvent)&SalaryslipEdit::OnXCommand); //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga AttachEvent(L"WM_SETFOCUS", (FEvent)&SalaryslipEdit::OnSetFocus); AttachEvent(L"dw_base", L"DWV_ITEMCHANGED", (FEvent)&SalaryslipEdit::OnItemChanged); AttachEvent(L"dw_base", L"DWV_CLICKED", (FEvent)&SalaryslipEdit::OnDWClick); return 1; } int OnRetrieve(xstring SalaryslipID) { xml x ; xaserverarg arg; arg.AddArg(L"SalaryslipID", SalaryslipID); if (getUrl(L"/sale/data/expense3/view/getSalaryslipByID", arg.GetString(), x) != 1) { trace(x.text()); return -1; } else { dw_base.Retrieve(x); dw_base.Redraw(); } return 1; } int initial() { //dw_base.SetItemDouble(1, L"ActualAmount", 1427.40); dw_base.SetItemDouble(1, L"ActualAmount", 1859.74); dw_base.SetItemDouble(1, L"BasicSalary", 2490.00); dw_base.SetItemDouble(1, L"MealAllowance", 0.00); dw_base.SetItemDouble(1, L"EndowmentInsurance", 384.96);//Q{€ dw_base.SetItemDouble(1, L"MedicalInsurance", 96.24);//S;OÝ dw_base.SetItemDouble(1, L"UnemploymentInsurance", 24.06);//Y1N dw_base.SetItemDouble(1, L"HousingProvidentFund", 125.00); dw_base.SetItemDouble(1, L"DeductFeeAount", 630.26); //dw_base.SetItemDouble(1,"SpecialDeductFee",2000.00); dw_base.SetItemDouble(1, L"lastSalay", 0.0); dw_base.SetItemDouble(1, L"SalaryAmount", 2490.00);//^”SÑT‹¡ ComputeIncomeTax(); return 1; } int onload() { SetArg(); dw_base = GetControl(L"dw_base"); dw_base.openUrl(L"/sale/view/expense3/Salaryslip/Base"); dw_base.SetColHeaderHeight(0); dw_base.SetRowSelectorWidth(0); dw_base.SetHScrollState(false); dw_base.SetVScrollState(false); xstring suserid = publiccode::GetUser().id; xstring susername = publiccode::GetUser().name; xstring sdate = publiccode::GetCurrentDate(); xstring SalaryslipID = L""; hObject = 0; if (GetWinParam()) { xaserverarg arg=GetArg(); SalaryslipID = arg.GetArgString(L"SalaryslipID"); hObject = (HWND)arg.GetParam(L"HWND"); } if (SalaryslipID != L"") { OnRetrieve(SalaryslipID); dw_base.Redraw(); } else { dw_base.SetItemString(1, L"SalaryslipDate", sdate); dw_base.SetItemString(1, L"CreateDate", sdate); dw_base.SetItemString(1, L"CreatorID", suserid); initial(); } OnAttachEvent(); updated = false; return 1; } int onloaded() { SetAgent(); return 1; } };