From 86eb6c07cf3d0f75782377454194fad1e5f160d2 Mon Sep 17 00:00:00 2001 From: xj qian <qianxj15@sina.com> Date: 星期三, 26 六月 2024 08:51:19 +0800 Subject: [PATCH] add ptr --- jrj/project/business/GDN3.list.cpp | 718 ++++++++ jrj/xframe/wobject/xaserverarg.hpp | 71 jrj/ext-jrj/ext-jrj.vcxproj | 6 jrj/project/business/GDN3.maint.cpp | 4228 +++++++++++++++++++++++++++++++++++++++++++++++++ jrj/xframe/kobject/kxml.hpp | 16 jrj/ext-jrj/ext-jrj.vcxproj.filters | 6 6 files changed, 4,979 insertions(+), 66 deletions(-) diff --git a/jrj/ext-jrj/ext-jrj.vcxproj b/jrj/ext-jrj/ext-jrj.vcxproj index 301e3e0..503e38a 100644 --- a/jrj/ext-jrj/ext-jrj.vcxproj +++ b/jrj/ext-jrj/ext-jrj.vcxproj @@ -224,6 +224,12 @@ <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> </ClCompile> <ClCompile Include="..\project\business\EnquiryEx3.list.cpp" /> + <ClCompile Include="..\project\business\GDN3.list.cpp"> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> + </ClCompile> + <ClCompile Include="..\project\business\GDN3.maint.cpp"> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> + </ClCompile> <ClCompile Include="..\project\business\Product.list.cpp"> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> </ClCompile> diff --git a/jrj/ext-jrj/ext-jrj.vcxproj.filters b/jrj/ext-jrj/ext-jrj.vcxproj.filters index a789be6..aeb0c76 100644 --- a/jrj/ext-jrj/ext-jrj.vcxproj.filters +++ b/jrj/ext-jrj/ext-jrj.vcxproj.filters @@ -311,5 +311,11 @@ <ClCompile Include="..\project\business\EnquiryEx3.list.cpp"> <Filter>project\business</Filter> </ClCompile> + <ClCompile Include="..\project\business\GDN3.list.cpp"> + <Filter>project\business</Filter> + </ClCompile> + <ClCompile Include="..\project\business\GDN3.maint.cpp"> + <Filter>project\business</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file diff --git a/jrj/project/business/GDN3.list.cpp b/jrj/project/business/GDN3.list.cpp new file mode 100644 index 0000000..6ed85f3 --- /dev/null +++ b/jrj/project/business/GDN3.list.cpp @@ -0,0 +1,718 @@ +#include <wobject/xstring.hpp> +#include <xcontrol/xtreeview.hpp> +#include <xcontrol/xdwgrid.hpp> + +#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" +#include "viewobject/view.base.hpp" + +class __declspec(dllexport) GDN3list : public listwin +{ +public: + GDN3list(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {} +public: + static GDN3list* CreateInstance(void* implPtr, void* hWnd) + { + GDN3list* pWin = new GDN3list(implPtr, (HWND)hWnd); + return pWin; + } + +public: + xstring m_sType; //树选中的类型 + xstring m_sTypeTxt; //树选中的数据 + xstring urlTree; + xstring myDataUrl; + xstring searchStr; + xstring rows; + bool readed; + + int changeddlb; + xcombobox ddlb_1; + xcombobox cbx_datashow; + + xtreeview tv_folder; + xdwgrid dw_goods; + xdwgrid dw_source; + xdwtable dw_profit; + xdwgrid dw_custom; + + //process tree +//查找当前树项的顶级目录 + int LookupTopFolder(HTREEVIEW hItem) + { + int hRoot = tv_folder.GetRootItem(); + while (tv_folder.GetParentItem(hItem)) hItem = tv_folder.GetParentItem(hItem); + return hItem; + } + + + + //焦点激活处理函数 + int OnSetFocus(TEvent* evt, int param) + { + //重置工具条 + int row = dw_list.GetRow(); + if (row < 1) return 1; + KXMLDOMElement ele = dw_list.GetRowElement(row); + xstring id = GetEntityIDName(1); + trace(L"\rn---" + id); + xstring entity = ele.selectSingleNode(id).text(); + //trace(entity); + SetAgent(L"list", entity); + + return 1; + } + + int ExpandCatChildFolder(HTREEVIEW hItem, KXMLDOMElement ele, int image) + { + KXMLDOMNodeList nlist = ele.SelectNodes(L"item"); + int len = nlist.length; + if (len > 0) tv_folder.SetItemChild(hItem, 1); + for (int i = 0; i < len; i++) + { + KXMLDOMElement e = nlist.item(i); + xstring name = e.getAttribute(L"name"); + int h = tv_folder.InsertChildItem(hItem, name, trust(e as int), image); + ExpandCatChildFolder(h, e, 35); + } + return 1; + } + + int ExpandFolderItem(HTREEVIEW hItem, xstring no) + { + //xml x = ViewObject::RetrieveData(urlTree,L"no",no); + xml x = xml::Make(); + xaserverarg arg = xaserverarg::Make(); + arg.AddArg(L"no", no); + xaserver::ExecXQuery(GetServerUrl(), L"[customerfolder.gdn.sql.xq]", arg.GetString(), x); + + if (!x) return 0; + + KXMLDOMNodeList nlist = x.GetXmlDoc().SelectNodes(L"/data/item"); + int len = nlist.length; + for (int i = 0; i < len; i++) + { + KXMLDOMElement e = nlist.item(i); + xstring name = e.getAttribute(L"name"); + int h = tv_folder.InsertChildItem(hItem, name, trust(e as int), 35); + ExpandCatChildFolder(h, e, 35); + } + x.Free(); + return 1; + } + + //树展开 + int OnTreeExpanding(ref TNotifyEvent evt, int p) + { + ref NMTREEVIEW nmtv = evt.pnmh; + HTREEVIEW hItem = nmtv.itemNew.hItem; + int hTopItem = LookupTopFolder(hItem); + xstring name = tv_folder.GetItemLabel(hTopItem); + int child = tv_folder.GetChildItem(hItem); + + KXMLDOMElement e = tv_folder.GetItemData(hItem); + if (!child)ExpandFolderItem(hItem, e.getAttribute(L"no")); + + return 1; + } + + int ExpandChildFolder(HTREEVIEW hItem, KXMLDOMElement pElement) + { + KXMLDOMNodeList nlist = pElement.SelectNodes(L"Item"); + int len = nlist.length; + for (int i = 0; i < len; i++) + { + KXMLDOMElement e = nlist.item(i); + xstring name = e.getAttribute(L"name"); + xstring sImage = e.getAttribute(L"image"); + int image = 15; + //if(sImage) image = sImage.toInt(); + int h = tv_folder.InsertChildItem(tv_folder.GetId(), hItem, name, trust(e as int), image); + tv_folder.SetItemChild(h, 1); + ExpandChildFolder(h, e); + } + return 1; + } + + int InitialFolder() + { + KXMLDOMElement xframeElement = GetElement(); + KXMLDOMElement e = xframeElement.selectSingleNode(L"//xtree[@name='tv_folder']/initial"); + if (e)ExpandChildFolder(0, e); + return 1; + } + + int OnTreeSelChanged(ref TNotifyEvent evt, int p) + { + if (changeddlb) return 1; + return OnPreRetrieve(); + + return 1; + } + + int ViewUpdate(int pr, xstring updateItem, xaserverarg arg) + { + if (updateItem == L"del") + { + int DelRow = this.dw_list.GetRow(); + this.dw_list.DeleteRow(DelRow); + + } + else if (updateItem == L"setstate") + { + int row = this.dw_list.GetRow(); + if (row < 1) return 1; + KXMLDOMElement ele = this.dw_list.GetRowElement(row); + xstring id = GetEntityIDName(1); + xstring entity = ele.selectSingleNode(id).text(); + SetAgent(L"list", entity); + if (arg.GetArgString(L"state") != L"") + //this.dw_list.SetItemString(row, L"ApprovalStatus", arg.GetArgString(L"state")); + dw_list.SetItemString(row, L"ApplyStatus", arg.GetArgString(L"state")); + if (arg.GetArgString(L"billstatus") != L"") + { + xstring billstatus = arg.GetArgString(L"billstatus"); + xstring statusName = GetBillStatusName(billstatus); + dw_list.SetItemString(row, L"ApprovalStatus", billstatus); + dw_list.SetItemDisplayString(row, L"ApprovalStatus", statusName); + } + + this.dw_list.Redraw(); + } + + return 1; + } + + bool IsEmptyQueryStr(xstring queryStr) + { + if (queryStr == L"") return true; + if (queryStr == L"<items join='and'/>") return true; + if (queryStr == L"<items join=\"and\"/>") return true; + return false; + } + + //检索 + int OnPreRetrieveEx() + { + + if (readed) return 1; + HTREEVIEW hItem = tv_folder.GetSelectedItem(); + if (hItem <= 0) + { + hItem = tv_folder.GetRootItem(); + if (hItem <= 0) return 1; + } + int hCursor = xutil::SetCursorWait(); + KXMLDOMElement e1 = cast(tv_folder.GetItemData(hItem) as KXMLDOMElement); + xstring no = e1.getAttribute(L"no"); + //xml x = 0; + //x = ViewObject::RetrieveData(myDataUrl,L"no",no,L"QueryTxt", m_QueryTxt,L"rows",rows); + xstring DeptName = publiccode::GetUser().deptname; + xaserverarg arg = xaserverarg::Make(); + arg.AddArg(L"no", no); + arg.AddArg(L"QueryTxt", m_QueryTxt); + arg.AddArg(L"rows", rows); + trace(no + L"***" + m_QueryTxt + L"***" + rows); + /*if(DeptName==L"跟单部"){ + dw_list.DwRetrieve(GetServerUrl(),L"[list.creator.gdn.sql.xq]",arg.GetString()); + }else{ + dw_list.DwRetrieve(GetServerUrl(),L"[list.folder.gdn.sql.xq]",arg.GetString()); + }*/ + dw_list.DwRetrieve(GetServerUrl(), L"[list.folder.gdn.sql.xq]", arg.GetString()); + arg.Free(); + dw_list.SetReadOnly(true); + dw_list.SetRowSort(L"ETD", false); + + if (dw_list.GetRowCount() >= 1) RetrieveDetail(1); + + xutil::RestoreCursor(hCursor); + + return 1; + } + + int OnPreRetrieve() + { + HTREEVIEW hItem = tv_folder.GetSelectedItem(); + if (hItem <= 0) return 1; + + int hCursor = xutil::SetCursorWait(); + KXMLDOMElement e1 = cast(tv_folder.GetItemData(hItem) as KXMLDOMElement); + xstring no = e1.getAttribute(L"no"); + xml x = 0; + trace(L"\r\n" + no + L"\r\n" + m_QueryTxt); + x = ViewObject::RetrieveData(myDataUrl, L"no", no, L"QueryTxt", m_QueryTxt, L"rows", rows); + if (x) + { + dw_list.Retrieve(x); + dw_list.Redraw(); + } + else + { + dw_list.ResetEx(); + dw_list.Redraw(); + } + dw_list.SetReadOnly(true); + dw_list.SetRowSort(L"ETD", false); + + if (dw_list.GetRowCount() >= 1) RetrieveDetail(1); + + xutil::RestoreCursor(hCursor); + + return 1; + } + + int RetrieveDetail(int row) + { + xstring EntityID = dw_list.GetGuid(row); + xstring InvoiceNo = dw_list.GetItemString(row, L"InvoiceNo"); + dw_goods.DwRetrieve(GetServerUrl(), L"[gdnline.gdn.sql.xq]", L"EntityID", EntityID); + dw_goods.SetReadOnly(true); + + //dw_source.DwRetrieve(GetServerUrl(),L"[source.gdn.sql.xq]",L"EntityID", EntityID ); + + + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/source/maintex1", L"GDNID", EntityID); + if (x) + dw_source.Retrieve(x); + else + dw_source.Reset(); + dw_source.Redraw(); + dw_source.SetReadOnly(true); + + xml x1 = ViewObject::RetrieveData(L"/sale/data/Custom3/maint/custom/data", L"invno", InvoiceNo); + if (x1) + dw_custom.Retrieve(x1); + else + dw_custom.Reset(); + dw_custom.Redraw(); + dw_custom.SetReadOnly(true); + + dw_profit.DwRetrieve(GetServerUrl(), L"[profit.dgn.sql.xq]", L"EntityID", EntityID); + dw_profit.SetReadOnly(true); + + return 1; + } + + int OnRowChanged(ref TNotifyEvent evt, int p) + { + + //fixed one event only one process + listwin::OnRowChanged(evt, p); + + ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); + int row = hdr.row; + int hCursor = xutil::SetCursorWait(); + RetrieveDetail(row); + xutil::RestoreCursor(hCursor); + + return 1; + } + + /* +int PreOnCmdDispatch(xstring comdid) +{ + //返回0——不在执行以下代码;返回其他——执行以下代码。 + if(comdid==L"action:bill.merge") + { + OpenWindow(L"dev:xpage[Merge.GDN.vx]"); + return 0; + } + else if(comdid==L"action:bill.check.ask") + { + int row = dw_list.GetRow(); + xstring ApprovalStatus = dw_list.GetItemString(row,L"ApprovalStatus"); + if(ApprovalStatus == L"9"){ + alert(L"合并票不允许提交审批!"); + return 0; + } + xstring InvoiceNo = dw_list.GetItemString(row,L"InvoiceNo"); + xml x = ViewObject::RetrieveData(L"/sale/data/Gdn/checksource",L"invno",InvoiceNo); + if(!x) return 1; + + if(x.GetXmlDoc().selectSingleNode(L"error")) + { + alert(x.GetXmlDoc().selectSingleNode(L"error").text); + return 0; + } + + } + else if(comdid==L"action:bill.new") + { + xstring s = publiccode::GetUser().id; + + xml supplier_x = ViewObject::RetrieveData(L"/sale/data/SupplierV3/entity/FindBySaleType",L"id", s); + if(supplier_x) + { + if(supplier_x.GetXmlDoc().text != L"业务员") + { + alert(L"当前角色不是业务员不能新增单子,请重新选择角色"); + return 0; + } + } + } + return 1; +} +*/ + + int OnSearch() + { + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + arg.AddArg(L"text", searchStr); + OpenWindow(L"dev:xpage[search.dialog.vx]", cast(arg as int)); + xstring str = arg.GetArgString(L"text"); + if (str != searchStr) + { + searchStr = str; + dw_list.Filter(L"*", searchStr); + return 1; + } + return 1; + } + + int PreOnCmdDispatch(xstring comdid) + { + if (comdid == L"action:bill.refresh") + { + changeddlb = 1; + int RItem = tv_folder.GetRootItem(); + while (tv_folder.GetChildItem(RItem)) + tv_folder.DeleteItem(tv_folder.GetChildItem(RItem)); + ExpandFolderItem(RItem, L"Category:Customer"); + tv_folder.ExpandItem(RItem); + tv_folder.ItemFocus(RItem); + changeddlb = 0; + return OnPreRetrieve(); + } + else if (comdid == L"action:bill.merge") + { + OpenWindow(L"dev:xpage[Merge.GDN.vx]"); + return 0; + } + else if (comdid == L"xmSaveAs") + return dw_list.SaveAs(L""); + else if (comdid == L"xmSearch") + return OnSearch(); + else if (comdid.find(L"bill.print") > 0) + { + xstring EntityIDS = dw_list.GetGuid(dw_list.GetRow()); + xml xs = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudge", L"GDNID", EntityIDS); + xstring Results1 = xs.GetXmlDoc().text(); + if (Results1 != L"") + { + alert(Results1); + return 0; + } + + OnPrintOne(); + OnPrint(); + return 1; + } + else if (comdid == L"action:bill.new") + { + if (publiccode::GetUser().name != L"admin") + { + xstring s = publiccode::GetUser().id; + xml supplier_x = ViewObject::RetrieveData(L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s); + if (supplier_x) + { + if (supplier_x.GetXmlDoc().text != L"跟单") + { + alert(L"当前角色不是跟单员不能新增单子,请重新选择角色"); + return 0; + } + } + } + } + else if (comdid == L"action:bill.GDNDelay") + { + xstring EntityIDEx = dw_list.GetGuid(dw_list.GetRow()); + xaserverarg argEx = new xaserverarg; + argEx.setNativePointer(argEx.CreateInstance()); + trace(EntityIDEx); + argEx.AddArg(L"GDNID", EntityIDEx); + OpenWindow(L"dev:xpage[GDNDelay.vx]", cast(argEx as int)); + return 1; + } + else if (comdid == L"action:bill.check.ask") + { + int row = dw_list.GetRow(); + xstring ApprovalStatus = dw_list.GetItemString(row, L"ApprovalStatus"); + if (ApprovalStatus == L"9") { + alert(L"合并票不允许提交审批!"); + return 0; + } + + xstring EntityID = dw_list.GetGuid(dw_list.GetRow()); + xml xx = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudge", L"GDNID", EntityID); + xstring Results = xx.GetXmlDoc().text(); + if (Results != L"") + { + alert(Results); + return 0; + } + + xml xx2 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeEx", L"GDNID", EntityID); + xstring Results2 = xx2.GetXmlDoc().text(); + if (Results2 != L"") + { + alert(Results2); + return 0; + } + + xml xx3 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeExS", L"GDNID", EntityID); + xstring Results3 = xx3.GetXmlDoc().text(); + if (Results3 != L"") + { + alert(Results3); + return 0; + } + + xml xx4 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeAmount", L"GDNID", EntityID); + xstring Results4 = xx4.GetXmlDoc().text(); + if (Results4 != L"") + { + alert(Results4); + return 0; + } + + /*xml xx5= ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNCost",L"GDNID",EntityID); + xstring Results5=xx5.GetXmlDoc().text(); + if(Results5 !=L"") + { + alert(Results5); + return 0; + }*/ + + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + trace(EntityID); + arg.AddArg(L"GDNID", EntityID); + OpenWindow(L"dev:xpage[GDNDelay.vx]", cast(arg as int)); + + } + else if (comdid == L"action:bill.SourceRemark") return OnSourceRemark(); + + return 1; + } + + int OnSourceRemark() + { + xstring name = L"出运明细单"; + xml x = ViewObject::RetrieveData(L"/sale/data/TradeFinance3/GetSetUpRemarks", L"Type", name); + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + KXMLDOMNode t = items.item(0); + xstring Content = L""; + if (t.selectSingleNode(L"Content")) + { + Content = t.selectSingleNode(L"Content").text(); + } + xaserverarg arg1 = new xaserverarg; + arg1.setNativePointer(arg1.CreateInstance()); + arg1.AddArg(L"value", Content); + OpenWindow(L"dev:xpage[memo.edit.new.vx]", arg1.getNativePointer()); + + return 1; + } + + int OnPrint() + { + int row = dw_list.GetRow(); + xstring GDNID = dw_list.GetGuid(row); + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/CheckCDLine", L"GDNID", GDNID); + xstring r = x.GetXmlDoc().text(); + int r1 = r.toInt(); + if (x) + { + if (r1 > 0) + { + alert(L"报关数量和报关金额与出运数量和金额不一致\r\n部分报关数量和金额需要核对!"); + } + } + //alert(GDNID); + return 1; + } + + int OnPrintOne() + { + int row = dw_list.GetRow(); + xstring GDNID = dw_list.GetGuid(row); + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/CheckGW", L"GDNID", GDNID); + xstring r = x.GetXmlDoc().text(); + int r1 = r.toInt(); + if (x) + { + if (r1 > 0) + { + alert(L"毛重总量或净总重量不一致,需要核对!"); + } + } + //alert(GDNID); + return 1; + } + + + //xcombobox下拉 + int OnSelectDdlb(ref TNotifyEvent evt, int p) + { + changeddlb = 1; + int wid = ddlb_1.GetId(); + int CB_GETCURSEL = 0x0147; + int nIndex = win32::SendMessage(wid, CB_GETCURSEL, 0, 0); + KXMLDOMElement e = ddlb_1.GetElement(); + KXMLDOMElement e2 = e.selectSingleNode(L"item[" + (nIndex + 1).toString() + L"]"); + xstring no = e2.selectSingleNode(L"@element").text(); + + HTREEVIEW hItem = tv_folder.GetRootItem(); + while (tv_folder.GetChildItem(hItem)) + tv_folder.DeleteItem(tv_folder.GetChildItem(hItem)); + + ExpandFolderItem(hItem, no); + + changeddlb = 0; + return 1; + } + + int OnSelectDataShowDdlb(ref TNotifyEvent evt, int p) + { + int wid = cbx_datashow.GetId(); + int CB_GETCURSEL = 0x0147; + int nIndex = win32::SendMessage(wid, CB_GETCURSEL, 0, 0); + KXMLDOMElement e = cbx_datashow.GetElement(); + KXMLDOMElement e2 = e.selectSingleNode(L"item[" + (nIndex + 1).toString() + L"]"); + rows = e2.selectSingleNode(L"@rows").text(); + OnPreRetrieve(); + + return 1; + } + + + int AttachEvent() + { + AttachEvent(L"tv_folder", L"TVN_SELCHANGED", OnTreeSelChanged); //树选择 + //AttachEvent(L"tv_folder", L"TVN_ITEMEXPANDING",OnTreeExpanding); //树展开 + AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", OnRowChanged); + AttachEvent(L"cbx_1", L"CBN_SELCHANGE", OnSelectDdlb); + AttachEvent(L"cbx_datashow", L"CBN_SELCHANGE", OnSelectDataShowDdlb); + return 1; + } + + virtual xstring GetTemplateUrl() + { + return "/sale/view/GDN/template/GDN/ListEx"; + } + int onload() + { + listwin::onload(); + dw_list.SetColumnState(L"CurrencyNo", false); + + ddlb_1 = GetControl(L"cbx_1"); + cbx_datashow = GetControl(L"cbx_datashow"); + dw_goods = GetControl(L"dw_goods"); + //dw_goods.openUrl(L"/sale/view/GDN/template/GDNItem1"); + dw_goods.SetDataObject(GetServerUrl(), L"dev:sheet[GDN.v3.EX.tpl/GDNItem]"); + dw_goods.SetColumnState(L"ItemID", false); + dw_goods.SetColumnState(L"LineType", false); + dw_goods.SetColumnState(L"LineNo", false); + dw_goods.SetColumnState(L"Assortment", false); + dw_goods.SetColumnState(L"SOLineNo", false); + dw_goods.SetColumnState(L"SKUNo", false); + dw_goods.SetColumnState(L"POCreatorID", false); + dw_goods.SetColumnState(L"BuyAmount", false); + dw_goods.SetColumnState(L"CostRate", false); + dw_goods.SetColumnState(L"CommissionRate", false); + dw_goods.SetColumnState(L"DiscountRate", false); + dw_goods.SetColumnState(L"Remark", false); + dw_goods.SetColumnState(L"DiscountRate", false); + dw_goods.SetColumnState(L"SOLineID", false); + dw_goods.SetColumnState(L"PONo", false); + + dw_source = GetControl(L"dw_source"); + //dw_source.openUrl(L"/sale/view/GDN/template/item/sourcing"); + dw_source.SetDataObject(GetServerUrl(), L"dev:sheet[GDN.v3.EX.tpl/SourcingItem]"); + + dw_source.SetColumnState(L"POID", false); + dw_source.SetColumnState(L"InvoiceNo", false); + dw_source.SetColumnState(L"ETD", false); + dw_source.SetColumnState(L"SOLineID", false); + dw_source.SetColumnState(L"ItemID", false); + dw_source.SetColumnState(L"POItemID", false); + dw_source.SetColumnState(L"GDNLineID", false); + dw_source.SetColumnState(L"Amount", false); + + dw_profit = GetControl(L"dw_profit"); + //dw_profit.openUrl(L"/sale/view/GDN/template/Profit"); + dw_profit.SetDataObject(GetServerUrl(), L"dev:sheet[GDN.v3.EX.tpl/Profit]"); + dw_profit.SetColHeaderHeight(0); + dw_profit.SetRowSelectorWidth(0); + dw_profit.SetHScrollState(false); + + + dw_custom = GetControl(L"dw_custom"); + dw_custom.openUrl(L"/sale/view/Custom3/template/maint"); + dw_custom.SetColumnState(L"ClassifyID", false); + dw_custom.SetColumnState(L"AmountEx", false); + //dw_custom.SetReadOnlyColumn(L"CustName",true); + dw_custom.SetColumnState(L"LineNo", false); + + rows = L"500"; + myDataUrl = L"/sale/data/GDN3/folder/list"; + urlTree = L"/sale/data/GDN3/folder"; + tv_folder = GetControl(L"tv_folder"); + //tv_folder.SetLineAtRoot(true); + InitialFolder(); + return 1; + } + + int onloaded() + { + + HTREEVIEW hItem = tv_folder.GetRootItem(); + ExpandFolderItem(hItem, L"Category:Customer"); + tv_folder.ExpandItem(hItem); + tv_folder.ItemFocus(hItem); + + listwin::onloaded(); + searchStr = L""; + readed = true; + + + + //attach my control event + AttachEvent(); + + readed = false; + + return 1; + } + + int ProcessUsedArg(xaserverarg arg) + { + xstring action = arg.GetArgString(L"Action"); + //trace(L"\r\n*******************action:"+action+L"\r\n"); + if (action == L"bill.open") { + int row = dw_list.GetRow(); + xstring ApprovalStatus = dw_list.GetItemString(row, L"ApprovalStatus"); + if (ApprovalStatus == L"9") + { + arg.AddArg(L"ReadOnly", L"true"); + arg.AddArg(L"ReadOnlyEx", L"true"); + } + } + else { + arg.AddArg(L"ReadOnly", L"false"); + } + + HTREEVIEW hItem = tv_folder.GetCaretItem(); + if (hItem <= 0) return 1; + KXMLDOMElement e = tv_folder.GetItemData(hItem); + xstring no = e.getAttribute(L"no"); + if (no.find(L"Customer:") >= 0) + { + arg.AddArg(L"CustomerID", e.getAttribute(L"id")); + xstring name = e.getAttribute(L"name"); + if (name.find(L"(L") >= 0) name = name.left(name.find(L"(L")); + arg.AddArg(L"CustomerName", name); + } + return 1; + } +}; \ No newline at end of file diff --git a/jrj/project/business/GDN3.maint.cpp b/jrj/project/business/GDN3.maint.cpp new file mode 100644 index 0000000..c8af0b1 --- /dev/null +++ b/jrj/project/business/GDN3.maint.cpp @@ -0,0 +1,4228 @@ +#include <wobject/xstring.hpp> +#include <wobject/xdouble.hpp> +#include <xcontrol/xtreeview.hpp> +#include <xcontrol/xdwgrid.hpp> +#include <xcontrol/ximageview.hpp> + +#include "vbusiness/vframe/maint.vframe.vbusiness.hpp" +#include "viewobject/view.base.hpp" +#include "viewobject/saleorder.view.hpp" +#include "viewobject/quote.view.hpp" + +class __declspec(dllexport) GDN3MaintWin : public maint +{ +public: + GDN3MaintWin(void* implPtr, HWND hWnd) :maint(implPtr, hWnd) {} +public: + static GDN3MaintWin* CreateInstance(void* implPtr, void* hWnd) + { + GDN3MaintWin* pWin = new GDN3MaintWin(implPtr, (HWND)hWnd); + return pWin; + } +public: + xdwtable dw_base; + xdwgrid dw_item; + xdwgrid dw_custom; + xdwtable dw_profit; + xdwgrid dw_source; + xdwgrid dw_cdelement; + xdwgrid dw_invoiceItem; + xdwgrid dw_customex; + xdwgrid dw_billnote; + xdwgrid dw_doclist; + xdwgrid dw_fcl; + + xstring InvoiceNo; + xstring InvoiceID; + bool readonly; + bool haveUpdate; + xnode m_agentNode; //Agent Condition + xstring tabname; + bool datareading; + bool readonlyEx; + xstring searchStr; + //xstring ApprovalStatus; + //xdwgrid dw_element; + + int SetAgent(xstring scene, xstring EntityName, xstring EntityID) + { + xstring xfNodeAgentArea = L"agentarea"; + xnode anode = GetAgentNode(xfNodeAgentArea); + KXMLDOMElement xframeElement = GetElement(); + KXMLDOMNode agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*"); + + xml x; + + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + arg.AddArg(L"scene", scene, L"xs:xstring"); + arg.AddArg(L"EntityID", EntityID, L"xs:xstring"); + arg.AddArg(L"EntityName", EntityName, L"xs:xstring"); + url::get(L"/workflow/query/datarole/" + EntityName, arg.GetString(), x); + + xstring sNodes; + sNodes = L"datarole/actions/action[contains(@scene,'" + scene + L"')]"; + KXMLDOMNodeList nlist = x.GetXmlDoc().SelectNodes(sNodes); + int index; + int nlen = nlist.length; + KXMLDOMElement ele; + + xstring tools = L"<vbox class=''>"; + if (scene == L"list") tools += L"<xspace height='12'/>"; + + haveUpdate = false; + for (index = 0; index < nlen; index++) + { + ele = nlist.item(index); + xstring name = ele.selectSingleNode(L"@id").text;//.getAttribute(L"id"); + xstring label = ele.selectSingleNode(L"@caption").text;//ele.getAttribute(L"caption"); + xstring image; + xstring src = L""; + if (ele.selectSingleNode(L"@image")) + image = ele.selectSingleNode(L"@image").text; + else + image = L"0 22"; + + if (ele.selectSingleNode(L"@src")) + src = ele.selectSingleNode(L"@src").text; + + xstring tool; + if (name.find(L"bill.update") >= 0) haveUpdate = true; + if (src != L"") + tool = L"<xtoolbutton src='" + src + L"' caption='" + label + L"' name='action:" + name + L"' height='23' style='background-color:none #ceecce none #ffffff'/>"; + else + tool = L"<xtoolbutton image='" + image + L"' caption='" + label + L"' name='action:" + name + L"' height='23' style='background-color:none #ceecce none #ffffff'/>"; + tools += tool; + } + if (agent) + { + nlist = agent.SelectNodes(L".//xtoolbutton"); + nlen = nlist.length; + for (index = 0; index < nlen; index++) + { + ele = nlist.item(index); + xstring tmp = ele.xml; + tools += tmp; + } + } + tools += L"</vbox>"; + SetAgentNodeContent(anode, tools); + + return 1; + } + + int OnMakeGdnLineEx() + { + int cnt = dw_invoiceItem.GetRowCount(); + for (int k = 1; k <= cnt; k++) dw_invoiceItem.DeleteRow(1); + + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + dw_invoiceItem.InsertRow(0); + dw_invoiceItem.SetItemString(row, L"ClassifyID", dw_item.GetItemString(row, L"ClassifyID")); + dw_invoiceItem.SetItemDisplayString(row, L"ClassifyID", dw_item.GetItemDisplayString(row, L"ClassifyID")); + + dw_invoiceItem.SetItemString(row, L"Quantity", dw_item.GetItemString(row, L"Quantity")); + dw_invoiceItem.SetItemString(row, L"Packages", dw_item.GetItemString(row, L"Packages")); + dw_invoiceItem.SetItemString(row, L"Amount", dw_item.GetItemString(row, L"Amount")); + dw_invoiceItem.SetItemString(row, L"UnitPrice", dw_item.GetItemString(row, L"UnitPrice")); + + dw_invoiceItem.SetItemString(row, L"ContainerNo", dw_item.GetItemString(row, L"ContainerNo")); + dw_invoiceItem.SetItemString(row, L"GoodsNo", dw_item.GetItemString(row, L"GoodsNo")); + dw_invoiceItem.SetItemString(row, L"CustomerItemNo", dw_item.GetItemString(row, L"CustomerItemNo")); + dw_invoiceItem.SetItemString(row, L"PONo", dw_item.GetItemString(row, L"PONo")); + dw_invoiceItem.SetItemString(row, L"EName", dw_item.GetItemString(row, L"EName")); + dw_invoiceItem.SetItemString(row, L"Mark", dw_item.GetItemString(row, L"Mark")); + dw_invoiceItem.SetItemString(row, L"GroupNo", dw_item.GetItemString(row, L"GroupNo")); + + dw_invoiceItem.SetItemString(row, L"UnitPrice", dw_item.GetItemString(row, L"UnitPrice")); + dw_invoiceItem.SetItemString(row, L"CurrencyCode", dw_base.GetItemString(1, L"CurrencyCode")); + dw_invoiceItem.SetItemString(row, L"PackingRate", dw_item.GetItemString(row, L"PackingRate")); + dw_invoiceItem.SetItemString(row, L"VolumeDesc", dw_item.GetItemString(row, L"VolumeDesc")); + dw_invoiceItem.SetItemString(row, L"VolumePerPkg", dw_item.GetItemString(row, L"VolumePerPkg")); + dw_invoiceItem.SetItemString(row, L"Volume", dw_item.GetItemString(row, L"Volume")); + dw_invoiceItem.SetItemString(row, L"NWPerPkg", dw_item.GetItemString(row, L"NWPerPkg")); + dw_invoiceItem.SetItemString(row, L"NW", dw_item.GetItemString(row, L"NW")); + dw_invoiceItem.SetItemString(row, L"GWPerPkg", dw_item.GetItemString(row, L"GWPerPkg")); + dw_invoiceItem.SetItemString(row, L"GW", dw_item.GetItemString(row, L"GW")); + dw_invoiceItem.SetItemString(row, L"PackageL", dw_item.GetItemString(row, L"PackageL")); + dw_invoiceItem.SetItemString(row, L"PackageW", dw_item.GetItemString(row, L"PackageW")); + dw_invoiceItem.SetItemString(row, L"PackageH", dw_item.GetItemString(row, L"PackageH")); + + xstring voldesc = dw_item.GetItemString(row, L"PackageL") + L"*" + + dw_item.GetItemString(row, L"PackageW") + L"*" + + dw_item.GetItemString(row, L"PackageH"); + dw_invoiceItem.SetItemString(row, L"VolumeDesc", voldesc); + + dw_invoiceItem.SetItemString(row, L"InnerQty", dw_item.GetItemString(row, L"InnerQty")); + dw_invoiceItem.SetItemString(row, L"CommissionRate", dw_item.GetItemString(row, L"CommissionRate")); + dw_invoiceItem.SetItemString(row, L"DiscountRate", dw_item.GetItemString(row, L"DiscountRate")); + + dw_invoiceItem.SetItemString(row, L"ItemID", dw_item.GetItemString(row, L"ItemID")); + dw_invoiceItem.SetItemString(row, L"LineType", dw_item.GetItemString(row, L"LineType")); + dw_invoiceItem.SetItemString(row, L"LineNo", dw_item.GetItemString(row, L"LineNo")); + dw_invoiceItem.SetItemString(row, L"Assortment", dw_item.GetItemString(row, L"Assortment")); + dw_invoiceItem.SetItemString(row, L"GDNID", dw_item.GetItemString(row, L"GDNID")); + dw_invoiceItem.SetItemString(row, L"SOLineID", dw_item.GetItemString(row, L"SOLineID")); + + dw_invoiceItem.SetItemString(row, L"UOMCode", dw_item.GetItemString(row, L"UOMCode")); + dw_invoiceItem.SetItemDisplayString(row, L"UOMCode", dw_item.GetItemDisplayString(row, L"UOMCode")); + + dw_invoiceItem.SetItemString(row, L"KOPCode", dw_item.GetItemString(row, L"KOPCode")); + dw_invoiceItem.SetItemDisplayString(row, L"KOPCode", dw_item.GetItemDisplayString(row, L"KOPCode")); + + KXMLDOMElement e = dw_item.GetRowElement(row); + dw_invoiceItem.SetItemString(row, L"GDNLineID", e.getAttribute(L"guid")); + } + + return 1; + } + + xstring GetEntityData(int pr) + { + dw_base.AcceptText(); + dw_source.AcceptText(); + dw_item.AcceptText(); + dw_custom.AcceptText(); + + xml xbase = new xml; + xbase.setNativePointer(xml::CreateInstance()); + dw_base.DwUpdateAllTo(xbase.GetXmlDoc()); + + KXMLDOMElement ebase = xbase.GetXmlDoc().documentElement; + + xml xitem = new xml; + xitem.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xitemdoc = xitem.GetXmlDoc(); + dw_item.DwUpdateAllToEx(xitemdoc); + if (xitem.GetXml() != L"") + { + KXMLDOMElement eitem = xitemdoc.documentElement; + if (eitem) ebase.appendChild(eitem); + } + + xml xsource = new xml; + xsource.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xsourcedoc = xsource.GetXmlDoc(); + dw_source.DwUpdateAllToEx(xsourcedoc); + + + if (xsource.GetXml() != L"") + { + KXMLDOMElement eitem1 = xitemdoc.documentElement; + if (eitem1) ebase.appendChild(eitem1); + } + + xml xcustom = new xml; + xcustom.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xcustomdoc = xcustom.GetXmlDoc(); + dw_source.DwUpdateAllToEx(xcustomdoc); + if (xcustom.GetXml() != L"") + { + KXMLDOMElement eitem2 = xitemdoc.documentElement; + if (eitem2) ebase.appendChild(eitem1); + } + + return ebase.xml; + } + + + int SetAgentEx() + { + SetAgent(L"maint", L"GDN3", InvoiceID); + if (readonlyEx && tabname == L"cdelement") + SwitchLayer(L"agent_" + tabname, L"agentareaframe"); + else if (haveUpdate && !readonly) + SwitchLayer(L"agent_" + tabname, L"agentareaframe"); + + return 1; + } + + //焦点激活处理函数 + int OnSetFocus(TEvent* evt, int param) + { + //重置工具条 + SetAgentEx(); + return 1; + } + + xstring GetEntityID(int /*param*/ pr) + { + return InvoiceID; + } + + xstring GetEntityName(int /*param*/ pr) + { + return "GDN3"; + } + + xstring GetGuid() + { + return publiccode::GetGuid(); + } + + int SetCustomerHabit(xstring CustomerID) + { + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/habit/customer", L"CustomerID", CustomerID); + if (x) + { + KXMLDOMNodeList nodes = x.GetXmlDoc().selectNodes(L"GDN/*"); + int len = nodes.length; + for (int i = 0; i < len; i++) + { + KXMLDOMElement e = nodes.item(i); + dw_base.SetItemString(1, e.tagName, e.text); + if (e.selectSingleNode(L"@_displaystring")) + dw_base.SetItemDisplayString(1, e.tagName, e.selectSingleNode(L"@_displaystring").text); + } + } + return 1; + } + + int PoTotal(int row) + { + double Quantity_s = 0.0; + double Amount_s = 0.0; + double Vol_s = 0.0; + double Price = 0.0; + if (row < 1 or row > dw_item.GetRowCount()) return 1; + + KXMLDOMElement e = dw_item.GetRowElement(row); + xstring GDNLineID = e.getAttribute(L"guid"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + double SAmount = dw_item.GetItemDouble(row, L"Amount"); + for (int k = 1; k <= dw_source.GetRowCount(); ++k) + { + xstring POGDNLineID = dw_source.GetItemString(k, L"GDNLineID"); + if (GDNLineID == POGDNLineID) { + + double Amount = dw_source.GetItemDouble(k, L"BuyAmount"); + Amount_s += Amount; + } + } + dw_item.SetItemDouble(row, L"BuyAmount", Amount_s); + Price = Amount_s / Quantity; + Vol_s = Amount_s / SAmount; + dw_item.SetItemDouble(row, L"BuyUnitPrice", Price); + dw_item.SetItemDouble(row, L"CostRate", Vol_s); + + return 1; + } + + int PoTotal() + { + double Quantity_s = 0.0; + double Amount_s = 0.0; + double Vol_s = 0.0; + double Price = 0.0; + double PackUnitPrice_s = 0.0; + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + for (int k = 1; k <= dw_source.GetRowCount(); ++k) { + //double UnitPrice = dw_source.GetItemDouble(row,L"UnitPrice"); + KXMLDOMElement e = dw_item.GetRowElement(row); + xstring GDNLineID = e.getAttribute(L"guid"); + double Amount = dw_source.GetItemDouble(k, L"BuyAmount"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + double SAmount = dw_item.GetItemDouble(row, L"Amount"); + double PackUnitPrice = dw_item.GetItemDouble(row, L"PackUnitPrice"); + //xstring = dw_item.GetItemString(row,L"GDNLineID"); + xstring POGDNLineID = dw_source.GetItemString(k, L"GDNLineID"); + if (GDNLineID == POGDNLineID) { + Amount_s += Amount; + dw_item.SetItemDouble(row, L"BuyAmount", Amount_s); + Price = Amount_s / Quantity; + Vol_s = Amount_s / SAmount; + dw_item.SetItemDouble(row, L"BuyUnitPrice", Price); + dw_item.SetItemDouble(row, L"CostRate", Vol_s); + } + } + Amount_s = 0.0; + } + return 1; + } + + int calcTotal() + { + double Quantity_s = 0.0; + int Packages_s = 0.0; + double GW_s = 0.0; + double NW_s = 0.0; + double Amount_s = 0.0; + double Vol_s = 0.0; + double Price = 0.0; + double Cost_s = 0.0; + double ResearchCommissionRate_s = 0.0; + double MiddlemanAmountRate_s = 0.0; + + for (int row = 1; row <= dw_item.GetRowCount(); row++) + { + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + int Packages = dw_item.GetItemDouble(row, L"Packages").toInt(); + double GW = dw_item.GetItemDouble(row, L"GW"); + double NW = dw_item.GetItemDouble(row, L"NW"); + double Vol = dw_item.GetItemDouble(row, L"Volume"); + double ResearchCommissionRate = dw_item.GetItemDouble(row, L"ResearchCommissionRate"); + double MiddlemanAmountRate = dw_item.GetItemDouble(row, L"MiddlemanAmountRate"); + + double UnitPrice = dw_item.GetItemDouble(row, L"UnitPrice"); + double Amount = dw_item.GetItemDouble(row, L"Amount"); + double Cost = dw_item.GetItemDouble(row, L"Cost"); + Quantity_s += Quantity; + Packages_s += Packages; + GW_s += GW; + NW_s += NW; + Amount_s += Amount; + Vol_s += Vol.round(2); + Cost_s += Cost; + ResearchCommissionRate_s += ResearchCommissionRate; + MiddlemanAmountRate_s += MiddlemanAmountRate; + } + dw_base.SetItemDouble(1, L"Quantity", Quantity_s); + dw_base.SetItemDouble(1, L"GW", GW_s); + dw_base.SetItemDouble(1, L"NW", NW_s); + dw_base.SetItemString(1, L"Packages", Packages_s.toString()); + dw_base.SetItemDouble(1, L"Volume", Vol_s.round(2)); + dw_base.ItemChangeTo(1, L"Amount", Amount_s.toString()); + + dw_base.SetItemDouble(1, L"PrivateCommissionAmount", ResearchCommissionRate_s + MiddlemanAmountRate_s); + + //dw_base.SetItemDouble(1,L"Cost",Cost_s); + //dw_base.SetItemDouble(1,L"DraftAmount",Amount_s); + return 1; + } + + + //overroad + bool NeedNotifyUpdate() + { + if (readonly && !readonlyEx) return false; + if (!haveUpdate) return false; + return true; + } + + //overroad + int DoUpdate(bool showSuccess) + { + if (readonly && !readonlyEx) + { + alert(L"当前状态不能保存!"); + return 1; + } + + dw_base.AcceptText(); + dw_source.AcceptText(); + dw_profit.AcceptText(); + dw_invoiceItem.AcceptText(); + dw_fcl.AcceptText(); + dw_cdelement.AcceptText(); + xstring InvoiceNo1 = dw_base.GetItemString(1, L"InvoiceNo"); + if (InvoiceNo1 == L"") + { + alert(L"请输入外运编号"); + return 0; + } + else if (InvoiceID == L"") { + xml check_x = ViewObject::RetrieveData(L"/sale/data/GDN/source/FindByInvoiceNo", L"InvoiceNo", InvoiceNo1); + if (check_x) + { + xstring cnt = check_x.GetXmlDoc().documentElement.getAttribute(L"count"); + if (cnt != L"0") { + alert(L"外运编号已存在,请重新填写!"); + return 0; + } + } + } + + if (dw_base.GetItemString(1, L"CompanyID") == L"") + { + alert(L"请输入经营单位"); + return 0; + } + + if (dw_base.GetItemString(1, L"ETD") == L"") + { + alert(L"请输入预配船期"); + return 0; + } + + if (dw_base.GetItemString(1, L"OperationTips") == L"") + { + alert(L"请输入操作提示"); + return 0; + } + + /*if(dw_base.GetItemString(1,L"PriceTerm")==L"") + { + alert(L"请输入价格条款"); + return 0; + } + if(dw_base.GetItemString(1,L"PaymentTerm")==L"") + { + alert(L"请输入汇款方式"); + return 0; + } + if(dw_base.GetItemString(1,L"Country") == L"") + { + alert(L"请选择贸易国别"); + return 0; + } + if(dw_base.GetItemString(1,L"TradeType") == L"") + { + alert(L"请选择贸易方式"); + return 0; + } + if(dw_base.GetItemString(1,L"POL") == L"") + { + alert(L"请选择出口口岸"); + return 0; + } + if(dw_base.GetItemString(1,L"POD") == L"") + { + alert(L"请选择目的港"); + return 0; + } + if(dw_base.GetItemString(1,L"TransportMode") == L"") + { + alert(L"请选择运输方式"); + return 0; + }*/ + /* + if(dw_base.GetItemString(1,L"Mark") == L"") + { + alert(L"请输入唛头(无唛头,请填“N/M”)L"); + return 0; + }*/ + + /* + if(dw_base.GetItemString(1,L"FinalCountry") == L"") + { + alert(L"请选择运抵国"); + return 0; + }*/ + + //if(dw_base.GetItemString(1,L"GoodsSource") == L"") + //{ + // alert(L"请选择货物产地(货物产地:开票工厂金额最大的工厂所属地)L"); + // return 0; + // } + + //calcTotal(); + + xstring str = L""; + dw_base.AcceptText(); + xml xbase = new xml; + xbase.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xbasedoc = xbase.GetXmlDoc(); + dw_base.DwUpdateAllTo(xbasedoc); + + xaserverarg arg = GDNView::MakeArg(); + //if(dw_billnote.DeletedCount()+dw_billnote.ModifiedCount() > 0) + //{ + xml xbillnote = new xml; + xbillnote.setNativePointer(xml::CreateInstance()); + dw_billnote.DwUpdateAllToEx(xbillnote.GetXmlDoc()); + + KXMLDOMElement docinfo = xbillnote.GetXmlDoc().selectSingleNode(L"GDN/DocInfo"); + docinfo.SetAttribute(L"update.modify", L"1"); + xbase.GetXmlDoc().documentElement.appendChild(docinfo); + xbase.GetXmlDoc().documentElement.SetAttribute(L"update.modify", L"1"); + //} + arg.AddArg(L"content", xbase.GetXml()); + if (url::get(L"/sale/data/Gdn3/update/base", arg.GetString(), xbase) != 1) + { + xstring error = xbase.GetXmlDoc().text; + alert(L"err:" + error); + alert(L"基本信息保存失败!"); + return -1; + } + str = xbase.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"基本信息保存失败!"); + return -1; + } + dw_base.ResetUpdateStatus(); + + dw_profit.AcceptText(); + xml xprofit = new xml; + xprofit.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xprofitdoc = xprofit.GetXmlDoc(); + dw_profit.DwUpdateAllTo(xprofitdoc); + xaserverarg arg3 = GDNView::MakeArg(); + arg3.AddArg(L"content", xprofit.GetXml()); + if (url::get(L"/sale/data/Gdn/update/profit", arg3.GetString(), xprofit) != 1) + { + xstring error4 = xprofit.GetXmlDoc().text; + } + else + { + str = xprofit.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"盈亏信息保存失败!"); + return -1; + } + dw_profit.ResetUpdateStatus(); + } + + dw_item.AcceptText(); + + int k; + for (k = 1; k <= dw_item.GetRowCount(); k++) + { + if (dw_item.GetItemString(k, L"SeqNo") == L"") + { + dw_item.SetItemString(k, L"SeqNo", k.toString()); + } + } + + xml xitem = new xml; + xitem.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xitemdoc = xitem.GetXmlDoc(); + dw_item.DwUpdateAllToEx(xitemdoc); + //dw_base.DwUpdateAllTo(xitemdoc); + xaserverarg arg1 = GDNView::MakeArg(); + arg1.AddArg(L"content", xitem.GetXml()); + + if (url::get(L"/sale/data/Gdn/update/item", arg1.GetString(), xitem) != 1) + { + xstring error1 = xitem.GetXmlDoc().text; + } + else + { + str = xitem.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"商品信息保存失败!"); + return -1; + } + //alert(error1); + dw_item.ResetUpdateStatus(); + } + dw_source.AcceptText(); + xml x; + x.setNativePointer(x.CreateInstance()); + dw_source.DwUpdateAllToEx(x.GetXmlDoc()); + xaserverarg arg2 = GDNView::MakeArg(); + arg2.AddArg(L"content", x.GetXml()); + + if (url::get(L"/sale/data/Gdn/update/sourceex", arg2.GetString(), x) != 1) + { + xstring error3 = x.GetXmlDoc().text; + } + else + { + str = x.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"货源信息保存失败!"); + return -1; + } + dw_source.ResetUpdateStatus(); + } + + dw_custom.AcceptText(); + for (k = 1; k <= dw_custom.GetRowCount(); k++) + { + if (dw_custom.GetItemString(k, L"LineNo") == L"") + { + dw_custom.SetItemString(k, L"LineNo", k.toString()); + } + } + xml xcustom = new xml; + xcustom.setNativePointer(xcustom.CreateInstance()); + dw_custom.DwUpdateAllToEx(xcustom.GetXmlDoc()); + if (xcustom.GetXml() != L"") + { + xcustom = CustomView::UpdateCustomItem(dw_base.GetItemString(1, L"InvoiceNo"), xcustom.GetXml()); + if (!xcustom) + { + xstring error5 = xcustom.GetXmlDoc().text; + } + else + { + str = xcustom.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"报关信息保存失败!"); + return -1; + } + dw_custom.ResetUpdateStatus(); + } + } + if (dw_invoiceItem.GetRowCount() > 0) + { + dw_invoiceItem.AcceptText(); + xml x1 = new xml; + x1.setNativePointer(x1.CreateInstance()); + dw_invoiceItem.DwUpdateAllToEx(x1.GetXmlDoc()); + xaserverarg arg4 = GDNView::MakeArg(); + arg4.AddArg(L"content", x1.GetXml()); + if (url::get(L"/sale/data/Gdn/update/itemex", arg4.GetString(), x1) != 1) + if (!x1) + { + alert(L"议付信息保存失败!"); + return -1; + } + str = x1.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"议付信息保存失败!"); + return -1; + } + dw_invoiceItem.ResetUpdateStatus(); + } + dw_fcl.AcceptText(); + xml xfcl = new xml; + xfcl.setNativePointer(xfcl.CreateInstance()); + dw_fcl.DwUpdateAllToEx(xfcl.GetXmlDoc()); + xaserverarg arg8 = GDNView::MakeArg(); + arg8.AddArg(L"content", xfcl.GetXml()); + + if (url::get(L"/sale/data/Gdn/update/container", arg8.GetString(), xfcl) != 1) + { + xstring error8 = xfcl.GetXmlDoc().text; + } + else + { + str = xfcl.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"分箱信息保存失败!"); + return -1; + } + dw_fcl.ResetUpdateStatus(); + } + dw_cdelement.AcceptText(); + xml xcdelement = new xml; + xcdelement.setNativePointer(xcdelement.CreateInstance()); + dw_cdelement.DwUpdateAllToEx(xcdelement.GetXmlDoc()); + if (xcdelement.GetXml() != L"") + { + xcdelement = CustomView::UpdateCustomElement(dw_base.GetItemString(1, L"InvoiceNo"), xcdelement.GetXml()); + if (!xcdelement) + { + xstring error6 = xcdelement.GetXmlDoc().text; + alert(L"err:" + error6); + alert(L"申报要素信息保存失败!"); + //return -1; + } + else + { + str = xcdelement.GetXmlDoc().documentElement.getAttribute(L"text"); + if (str == L"false") + { + alert(L"申报要素信息保存失败!"); + return -1; + } + dw_cdelement.ResetUpdateStatus(); + } + } + + + + if (showSuccess) + alert(L"保存成功!"); + if (InvoiceID == L"") + { + InvoiceID = dw_base.GetGuid(1); + InvoiceNo = dw_base.GetItemString(1, L"InvoiceNo"); + } + return 1; + } + + + + bool validClassfyID() + { + if (dw_custom.GetRow() < 1) return true; + int i = 0; + xstring classfyid; + for (i = 1; i <= dw_item.GetRowCount(); i++) + { + classfyid = dw_item.GetItemString(i, L"ClassifyID"); + if (dw_custom.LookUpRow(L"ClassifyID", classfyid) == 0) + { + alert(L"出货商品第" + i.toString() + L"行海关代码[" + + dw_item.GetItemDisplayString(i, L"ClassifyID") + L"]与报关商品不一致"); + return false; + } + + } + + for (i = 1; i <= dw_custom.GetRowCount(); i++) + { + classfyid = dw_custom.GetItemString(i, L"ClassifyID"); + if (dw_item.LookUpRow(L"ClassifyID", classfyid) == 0) + { + alert(L"报关商品第" + i.toString() + L"行海关代码[" + + dw_item.GetItemDisplayString(i, L"ClassifyID") + L"]与出货商品不一致"); + return false; + } + + xml xx3 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNClassifyID", L"InvoiceNo", classfyid); + trace(classfyid); + xstring Results3 = xx3.GetXmlDoc().text; + if (Results3 != L"") + { + alert(Results3); + return false; + } + + /* + if(dw_custom.GetItemString(i,L"ItemGoodsSource")==L"") + { + alert(L"报关商品第"+i.toString()+L"行货源地为空,无法保存"); + return false; + } + */ + if (dw_custom.GetItemString(i, L"UOMCode") == L"") + { + alert(L"开票单位为空!"); + return false; + } + + } + + /* + xstring No = dw_base.GetItemString(1,L"InvoiceNo"); + if(No != L"") + { + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/GDNClassifyID",L"InvoiceNo", No); + if(x.GetXmlDoc().selectSingleNode(L"data/item/ClassifyID")) + if(x.GetXmlDoc().selectSingleNode(L"data/item/CDquantity")) + xstring ClassifyIDOne=L""; + xstring CDquantityOne=L""; + ClassifyIDOne = x.GetXmlDoc().selectSingleNode(L"data/item/ClassifyID").text; + CDquantityOne= x.GetXmlDoc().selectSingleNode(L"data/item/CDquantity").text; + double CDquantityTwo=CDquantityOne.toInt(); + } + double ttl=0.0; + for(i=1;i<=dw_item.GetRowCount();i++) + { + classfyid = dw_item.GetItemString(i,L"ClassifyID"); + if(classfyid == ClassifyIDOne) + { + if(dw_item.GetItemString(i,L"CDQuantity")==L""||dw_item.GetItemString(i,L"CDQuantity")==L"0.00") + { + alert(L"出运产品第"+i.toString()+L":报关数量为空!"); + return false; + } + if(dw_item.GetItemString(i,L"CDAmount")==L""||dw_item.GetItemString(i,L"CDAmount")==L"0.00") + { + alert(L"出运产品第"+i.toString()+L":报关总价为空!"); + return false; + } + double CDQuantity = dw_item.GetItemDouble(i,L"CDQuantity"); + ttl += CDQuantity; + } + } + if(ttl != CDquantityTwo) + { + alert(L"报关数量不一致!"); + return false; + }*/ + return true; + } + + bool CheckGW() + { + int i = 0; + double GWS = 0.0; + double NWS = 0.0; + for (int k = 1; k <= dw_item.GetRowCount(); k++) + { + double GW = dw_custom.GetItemDouble(k, L"GW"); + double NW = dw_custom.GetItemDouble(k, L"NW"); + GWS += (GW).round(2); + NWS += (NW).round(2); + } + + double GW1 = dw_base.GetItemDouble(1, L"GW"); + double NW1 = dw_base.GetItemDouble(1, L"NW"); + if ((NWS).round(2) != (NW1).round(2) || (GWS).round(2) != (GW1).round(2)) + { + alert(L"毛重总量或净总重量不一致,需要核对!"); + return 0; + } + return true; +} + + + bool LegalQtyCDLine() + { + xstring ApprovalStatus = dw_base.GetItemString(1, L"ApprovalStatus"); + trace(L"#######" + ApprovalStatus + L"#######"); + double NW = 0.0; + double NWS = 0.0; + if (ApprovalStatus != L"9") + { + int i = 0; + for (int k = 1; k <= dw_custom.GetRowCount(); k++) + { + xstring LegalUOMCode = dw_custom.GetItemString(k, L"LegalUOMCode"); + if (LegalUOMCode == L"千克") + { + xstring ClassifyID = dw_custom.GetItemString(k, L"ClassifyID"); + xstring ClassifyName = dw_custom.GetItemString(k, L"CustName"); + xstring GroupNo = dw_custom.GetItemString(k, L"GroupNo"); + if (GroupNo != L"") ClassifyName += ClassifyName + L"(L" + GroupNo + L")L"; + + double LegalQty = dw_custom.GetItemDouble(k, L"LegalQty"); + + for (i = 1; i <= dw_item.GetRowCount(); i++) + { + if (ClassifyID != dw_item.GetItemString(i, L"ClassifyID")) continue; + if (GroupNo != dw_item.GetItemString(i, L"GroupNo")) continue; + + + NW = dw_item.GetItemDouble(i, L"NW"); + + NWS += NW; + + } + trace(L"*****" + NWS.toString() + L"*****" + LegalQty.toString() + L"*****"); + NWS = NWS - LegalQty; + + if (NWS < 0.0) NWS = 0.0 - NWS; + if (NWS >= 1.0) + { + alert(L"[" + ClassifyName + L"]对应的报关数量不一致!"); + return 0; + } + } + } + } + return true; + } + + + bool CheckCDLine() + { + xstring ApprovalStatus = dw_base.GetItemString(1, L"ApprovalStatus"); + trace(L"#######" + ApprovalStatus + L"#######"); + //alert(ApprovalStatus); + if (ApprovalStatus != L"9") + { + int i = 0; + for (int k = 1; k <= dw_custom.GetRowCount(); k++) + { + xstring ClassifyID = dw_custom.GetItemString(k, L"ClassifyID"); + xstring ClassifyName = dw_custom.GetItemString(k, L"CustName"); + xstring GroupNo = dw_custom.GetItemString(k, L"GroupNo"); + if (GroupNo != L"") ClassifyName += ClassifyName + L"(L" + GroupNo + L")L"; + double VQuantity = dw_custom.GetItemDouble(k, L"Quantity"); + double VAmount = dw_custom.GetItemDouble(k, L"Amount"); + double qty = 0.0; + double amt = 0.0; + double qttl = 0.0; + double attl = 0.0; + for (i = 1; i <= dw_item.GetRowCount(); i++) + { + if (ClassifyID != dw_item.GetItemString(i, L"ClassifyID")) continue; + if (GroupNo != dw_item.GetItemString(i, L"GroupNo")) continue; + + if (dw_item.GetItemDouble(i, L"CDQuantity") == 0.0) + qty = dw_item.GetItemDouble(i, L"Quantity"); + else + qty = dw_item.GetItemDouble(i, L"CDQuantity"); + if (dw_item.GetItemDouble(i, L"CDAmount") == 0.0) + amt = dw_item.GetItemDouble(i, L"Amount"); + else + amt = dw_item.GetItemDouble(i, L"CDAmount"); + qttl += qty; + attl += amt; + } + + qttl = qttl - VQuantity; + attl = attl - VAmount; + + //alert(L"Quantity: "+VQuantity.toString()+L"Amount: "+VAmount.toString()+L" QTTL:"+qttl.toString()+L" ATTL:"+ attl.toString()); + + if (qttl < 0.0) qttl = 0.0 - qttl; + if (attl < 0.0) attl = 0.0 - attl; + if (qttl >= 1.0 || attl >= 1.0) + { + alert(L"[" + ClassifyName + L"]对应商品请填写开票数量和报关金额\r\n不填写表示开票数量和报关金额与出运数量和金额一致!"); + return 0; + } + } + } + return true; + } + + bool validProfit() + { + double amt = dw_profit.GetItemString(1, L"ProfitAmountEx"); + if (amt < 0.0) + { + if (dw_profit.GetItemString(1, L"Note") == L"") + { + alert(L"利润为负,请在盈亏备注中写明原因!"); + return false; + } + } + return true; + } + + int OnSave() + { + if (!validClassfyID()) return 1; + if (!validProfit()) return 1; + if (!CheckCDLine()) return 1; + if (!LegalQtyCDLine()) return 1; + + + DoUpdate(true); + + return 1; + } + + int ClearSourcingItem(int nRow) + { + if (nRow < 1 or nRow > dw_item.GetRowCount()) return 1; + xstring GDNLineID = dw_item.GetGuid(nRow); + for (int i = dw_source.GetRowCount(); i >= 1; i--) + { + if (dw_source.GetItemString(i, L"GDNLineID") == GDNLineID) + dw_source.DeleteRow(i); + } + return 1; + } + + int RefreshSourcingItem(int nRow, bool clear = true) + { + + if (nRow < 1 or nRow > dw_item.GetRowCount()) return 1; + xstring GDNLineID = dw_item.GetGuid(nRow); + if (clear) ClearSourcingItem(nRow); + double ExchangeCostEx = dw_profit.GetItemDouble(1, L"ExchangeCostEx"); + xml x = xml::Make(); + x.LoadXml(L"<data/>"); + KXMLDOMElement e = dw_item.GetRowElement(nRow); + KXMLDOMNode n = e.cloneNode(-1); + x.GetXmlDoc().documentElement.appendChild(n); + n.Release(); + xstring val = x.GetXml(); + trace(L"=======L" + val + L"=======L"); + x.Free(); + + xml source = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/gdn/sourcing/refreshitemex", L"content", val); + if (source) + { + KXMLDOMNodeList items = source.GetXmlDoc().selectNodes(L"data/Item"); + //trace(L"=======L"+source.GetXml()+L"=======L"); + int len = items.length; + int row = 0; + for (int i = 0; i < len; i++) + { + row = dw_source.InsertRow(0); + KXMLDOMNode t = items.item(i); + //dw_source.SetItemDouble(row,L"Swapthecost",ExchangeCostEx); + if (t.selectSingleNode(L"PONo"))dw_source.SetItemString(row, L"PONo", t.selectSingleNode(L"PONo").text); + if (t.selectSingleNode(L"POItemID"))dw_source.SetItemString(row, L"POItemID", t.selectSingleNode(L"POItemID").text); + if (t.selectSingleNode(L"SOLineID"))dw_source.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GDNLineID"))dw_source.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"GDNID"))dw_source.SetItemString(row, L"GDNID", t.selectSingleNode(L"GDNID").text); + + if (t.selectSingleNode(L"GoodsNo"))dw_source.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"GDNQuantity"))dw_source.SetItemString(row, L"GDNQuantity", t.selectSingleNode(L"GDNQuantity").text); + if (t.selectSingleNode(L"BuyQuantity"))dw_source.SetItemString(row, L"BuyQuantity", t.selectSingleNode(L"BuyQuantity").text); + if (t.selectSingleNode(L"CName"))dw_source.SetItemString(row, L"CName", t.selectSingleNode(L"CName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_source.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"BOMPart"))dw_source.SetItemString(row, L"BOMPart", t.selectSingleNode(L"BOMPart").text); + if (t.selectSingleNode(L"ItemID"))dw_source.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"BuyUnitPrice"))dw_source.SetItemString(row, L"BuyUnitPrice", t.selectSingleNode(L"BuyUnitPrice").text); + if (t.selectSingleNode(L"BuyAmount"))dw_source.SetItemString(row, L"BuyAmount", t.selectSingleNode(L"BuyAmount").text); + if (t.selectSingleNode(L"SupplierID"))dw_source.SetItemString(row, L"SupplierID", t.selectSingleNode(L"SupplierID").text); + if (t.selectSingleNode(L"SupplierID/@_displaystring"))dw_source.SetItemDisplayString(row, L"SupplierID", t.selectSingleNode(L"SupplierID/@_displaystring").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + //trace(L"\r\nHasVATInvoice:"+dw_source.GetItemDisplayString(row,L"HasVATInvoice")); + if (dw_source.GetItemString(row, L"HasVATInvoice") == L"Y") + { + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + if (t.selectSingleNode(L"VATRefundRate"))dw_source.SetItemString(row, L"VATRefundRate", t.selectSingleNode(L"VATRefundRate").text); + } + + if (t.selectSingleNode(L"Amount"))dw_source.SetItemString(row, L"Amount", t.selectSingleNode(L"Amount").text); + if (t.selectSingleNode(L"POCreatorID"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID").text); + if (t.selectSingleNode(L"POCreatorID/@_displaystring"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID/@_displaystring").text); + if (t.selectSingleNode(L"Swapthecost"))dw_source.SetItemString(row, L"Swapthecost", t.selectSingleNode(L"Swapthecost").text); + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + if (t.selectSingleNode(L"PurcharName"))dw_source.SetItemString(row, L"PurcharID", t.selectSingleNode(L"PurcharName").text); + if (t.selectSingleNode(L"PurcharID"))dw_source.SetItemString(row, L"PurcharID", t.selectSingleNode(L"PurcharID").text); + + if (t.selectSingleNode(L"PackUnitPrice"))dw_source.SetItemString(row, L"PackUnitPrice", t.selectSingleNode(L"PackUnitPrice").text); + + } + + PoTotal(nRow); + if (clear) + { + evalPurcharCost(); + evalTotalCost(); + evalProfitAmountEx(); + dw_profit.Redraw(); + } + } + + return 1; + } + + int RefreshSourcingItem1(int nRow, bool clear = true) + { + if (nRow < 1 or nRow > dw_item.GetRowCount()) return 1; + xstring GDNLineID = dw_item.GetGuid(nRow); + if (clear) ClearSourcingItem(nRow); + double ExchangeCostEx = dw_profit.GetItemDouble(1, L"ExchangeCostEx"); + xml x = xml::Make(); + x.LoadXml(L"<data/>"); + KXMLDOMElement e = dw_item.GetRowElement(nRow); + KXMLDOMNode n = e.cloneNode(-1); + x.GetXmlDoc().documentElement.appendChild(n); + n.Release(); + xstring val = x.GetXml(); + trace(L"123=======L" + val + L"=======123"); + x.Free(); + + xml source = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/gdn/sourcing/refreshitemexOne", L"content", val); + if (source) + { + KXMLDOMNodeList items = source.GetXmlDoc().selectNodes(L"data/Item"); + int len = items.length; + int row = 0; + for (int i = 0; i < len; i++) + { + row = dw_source.InsertRow(0); + KXMLDOMNode t = items.item(i); + //dw_source.SetItemDouble(row,L"Swapthecost",ExchangeCostEx); + if (t.selectSingleNode(L"PONo"))dw_source.SetItemString(row, L"PONo", t.selectSingleNode(L"PONo").text); + if (t.selectSingleNode(L"POItemID"))dw_source.SetItemString(row, L"POItemID", t.selectSingleNode(L"POItemID").text); + if (t.selectSingleNode(L"SOLineID"))dw_source.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GDNLineID"))dw_source.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"GDNID"))dw_source.SetItemString(row, L"GDNID", t.selectSingleNode(L"GDNID").text); + + if (t.selectSingleNode(L"GoodsNo"))dw_source.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"GDNQuantity"))dw_source.SetItemString(row, L"GDNQuantity", t.selectSingleNode(L"GDNQuantity").text); + if (t.selectSingleNode(L"BuyQuantity"))dw_source.SetItemString(row, L"BuyQuantity", t.selectSingleNode(L"BuyQuantity").text); + if (t.selectSingleNode(L"CName"))dw_source.SetItemString(row, L"CName", t.selectSingleNode(L"CName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_source.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"BOMPart"))dw_source.SetItemString(row, L"BOMPart", t.selectSingleNode(L"BOMPart").text); + if (t.selectSingleNode(L"ItemID"))dw_source.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"BuyUnitPrice"))dw_source.SetItemString(row, L"BuyUnitPrice", t.selectSingleNode(L"BuyUnitPrice").text); + if (t.selectSingleNode(L"BuyAmount"))dw_source.SetItemString(row, L"BuyAmount", t.selectSingleNode(L"BuyAmount").text); + if (t.selectSingleNode(L"SupplierID"))dw_source.SetItemString(row, L"SupplierID", t.selectSingleNode(L"SupplierID").text); + if (t.selectSingleNode(L"SupplierID/@_displaystring"))dw_source.SetItemDisplayString(row, L"SupplierID", t.selectSingleNode(L"SupplierID/@_displaystring").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemDisplayString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + // if(t.selectSingleNode(L"HSCode"))dw_source.SetItemString(row,L"HSCode",t.selectSingleNode(L"HSCode").text); + + if (dw_source.GetItemString(row, L"HasVATInvoice") == L"Y") + { + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + if (t.selectSingleNode(L"VATRefundRate"))dw_source.SetItemString(row, L"VATRefundRate", t.selectSingleNode(L"VATRefundRate").text); + } + + if (t.selectSingleNode(L"Amount"))dw_source.SetItemString(row, L"Amount", t.selectSingleNode(L"Amount").text); + if (t.selectSingleNode(L"POCreatorID"))dw_source.SetItemString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID").text); + if (t.selectSingleNode(L"POCreatorID/@_displaystring"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID/@_displaystring").text); + if (t.selectSingleNode(L"Swapthecost"))dw_source.SetItemString(row, L"Swapthecost", t.selectSingleNode(L"Swapthecost").text); + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + if (t.selectSingleNode(L"PurcharName"))dw_source.SetItemDisplayString(row, L"PurcharID", t.selectSingleNode(L"PurcharName").text); + if (t.selectSingleNode(L"PurcharID"))dw_source.SetItemString(row, L"PurcharID", t.selectSingleNode(L"PurcharID").text); + + if (t.selectSingleNode(L"PackUnitPrice"))dw_source.SetItemString(row, L"PackUnitPrice", t.selectSingleNode(L"PackUnitPrice").text); + } + + PoTotal(nRow); + if (clear) + { + evalPurcharCost(); + evalTotalCost(); + evalProfitAmountEx(); + dw_profit.Redraw(); + } + } + + return 1; + } + + int RefreshSourcingAllEx() + { + + while (dw_source.GetRowCount() > 0) dw_source.DeleteRow(1); + + dw_item.AcceptText(); + xml xitem = new xml; + xitem.setNativePointer(xml::CreateInstance()); + KXMLDOMDocument xitemdoc = xitem.GetXmlDoc(); + dw_item.DwUpdateAllToEx(xitemdoc); + trace(L"****" + xitem.GetXml() + L"****"); + + xml x = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/gdn/sourcing/refreshitemexOne", L"content", xitem.GetXml()); + trace(x.GetXml()); + if (x) + { + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + int len = items.length; + int row = 0; + for (int i = 0; i < len; i++) + { + row = dw_source.InsertRow(0); + KXMLDOMNode t = items.item(i); + + if (t.selectSingleNode(L"PONo"))dw_source.SetItemString(row, L"PONo", t.selectSingleNode(L"PONo").text); + if (t.selectSingleNode(L"POItemID"))dw_source.SetItemString(row, L"POItemID", t.selectSingleNode(L"POItemID").text); + if (t.selectSingleNode(L"SOLineID"))dw_source.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GDNLineID"))dw_source.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"GDNID"))dw_source.SetItemString(row, L"GDNID", t.selectSingleNode(L"GDNID").text); + + if (t.selectSingleNode(L"GoodsNo"))dw_source.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"GDNQuantity"))dw_source.SetItemString(row, L"GDNQuantity", t.selectSingleNode(L"GDNQuantity").text); + if (t.selectSingleNode(L"BuyQuantity"))dw_source.SetItemString(row, L"BuyQuantity", t.selectSingleNode(L"BuyQuantity").text); + if (t.selectSingleNode(L"CName"))dw_source.SetItemString(row, L"CName", t.selectSingleNode(L"CName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_source.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"BOMPart"))dw_source.SetItemString(row, L"BOMPart", t.selectSingleNode(L"BOMPart").text); + if (t.selectSingleNode(L"ItemID"))dw_source.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"BuyUnitPrice"))dw_source.SetItemString(row, L"BuyUnitPrice", t.selectSingleNode(L"BuyUnitPrice").text); + + if (t.selectSingleNode(L"BuyAmount"))dw_source.SetItemString(row, L"BuyAmount", t.selectSingleNode(L"BuyAmount").text); + + if (t.selectSingleNode(L"SupplierID"))dw_source.SetItemString(row, L"SupplierID", t.selectSingleNode(L"SupplierID").text); + if (t.selectSingleNode(L"SupplierID/@_displaystring"))dw_source.SetItemDisplayString(row, L"SupplierID", t.selectSingleNode(L"SupplierID/@_displaystring").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemDisplayString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + if (t.selectSingleNode(L"Amount"))dw_source.SetItemDisplayString(row, L"Amount", t.selectSingleNode(L"Amount").text); + if (t.selectSingleNode(L"POCreatorID"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID").text); + if (t.selectSingleNode(L"POCreatorID/@_displaystring"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID/@_displaystring").text); + if (t.selectSingleNode(L"Swapthecost"))dw_source.SetItemDisplayString(row, L"Swapthecost", t.selectSingleNode(L"Swapthecost").text); + if (t.selectSingleNode(L"PurcharName"))dw_source.SetItemDisplayString(row, L"PurcharID", t.selectSingleNode(L"PurcharName").text); + if (t.selectSingleNode(L"PurcharID"))dw_source.SetItemString(row, L"PurcharID", t.selectSingleNode(L"PurcharID").text); + if (t.selectSingleNode(L"PackUnitPrice"))dw_source.SetItemString(row, L"PackUnitPrice", t.selectSingleNode(L"PackUnitPrice").text); + // if(t.selectSingleNode(L"HSCode"))dw_source.SetItemString(row,L"HSCode",t.selectSingleNode(L"HSCode").text); + if (dw_source.GetItemDisplayString(row, L"HasVATInvoice") == L"Y") + { + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + if (t.selectSingleNode(L"VATRefundRate"))dw_source.SetItemString(row, L"VATRefundRate", t.selectSingleNode(L"VATRefundRate").text); + } + } + evalPurcharCost(); + evalTotalCost(); + + dw_profit.Redraw(); + + PoTotal(); + + x.Free(); + evalProfitAmountEx(); + } + + return 1; + } + + int RefreshSourcingAll() + { + while (dw_source.GetRowCount() > 0) dw_source.DeleteRow(dw_source.GetRowCount()); + + xstring No = dw_base.GetItemString(1, L"InvoiceNo"); + for (int k = 1; k <= dw_item.GetRowCount(); k++) + { + KXMLDOMElement e = dw_item.GetRowElement(k); + xstring gdnLineID = e.getAttribute(L"guid"); + xml x = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/gdn/sourcing/refreshitem", L"InvoiceNo", No, L"GDNLineID", gdnLineID); + if (x) + { + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + int len = items.length; + int row = 0; + for (int i = 0; i < len; i++) + { + row = dw_source.InsertRow(0); + KXMLDOMNode t = items.item(i); + + if (t.selectSingleNode(L"PONo"))dw_source.SetItemString(row, L"PONo", t.selectSingleNode(L"PONo").text); + if (t.selectSingleNode(L"POItemID"))dw_source.SetItemString(row, L"POItemID", t.selectSingleNode(L"POItemID").text); + if (t.selectSingleNode(L"SOLineID"))dw_source.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GDNLineID"))dw_source.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"GDNID"))dw_source.SetItemString(row, L"GDNID", t.selectSingleNode(L"GDNID").text); + + if (t.selectSingleNode(L"GoodsNo"))dw_source.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"GDNQuantity"))dw_source.SetItemString(row, L"GDNQuantity", t.selectSingleNode(L"GDNQuantity").text); + if (t.selectSingleNode(L"BuyQuantity"))dw_source.SetItemString(row, L"BuyQuantity", t.selectSingleNode(L"BuyQuantity").text); + if (t.selectSingleNode(L"CName"))dw_source.SetItemString(row, L"CName", t.selectSingleNode(L"CName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_source.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"BOMPart"))dw_source.SetItemString(row, L"BOMPart", t.selectSingleNode(L"BOMPart").text); + if (t.selectSingleNode(L"ItemID"))dw_source.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"BuyUnitPrice"))dw_source.SetItemString(row, L"BuyUnitPrice", t.selectSingleNode(L"BuyUnitPrice").text); + if (t.selectSingleNode(L"BuyAmount"))dw_source.SetItemString(row, L"BuyAmount", t.selectSingleNode(L"BuyAmount").text); + if (t.selectSingleNode(L"SupplierID"))dw_source.SetItemString(row, L"SupplierID", t.selectSingleNode(L"SupplierID").text); + if (t.selectSingleNode(L"SupplierID/@_displaystring"))dw_source.SetItemDisplayString(row, L"SupplierID", t.selectSingleNode(L"SupplierID/@_displaystring").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemDisplayString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + if (dw_source.GetItemDisplayString(row, L"HasVATInvoice") == L"Y") + { + if (t.selectSingleNode(L"VATRefundRate"))dw_source.SetItemString(row, L"VATRefundRate", t.selectSingleNode(L"VATRefundRate").text); + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + } + if (t.selectSingleNode(L"Amount"))dw_source.SetItemDisplayString(row, L"Amount", t.selectSingleNode(L"Amount").text); + if (t.selectSingleNode(L"POCreatorID"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID").text); + if (t.selectSingleNode(L"POCreatorID/@_displaystring"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID/@_displaystring").text); + if (t.selectSingleNode(L"Swapthecost"))dw_source.SetItemDisplayString(row, L"Swapthecost", t.selectSingleNode(L"Swapthecost").text); + } + } + evalTotalCost(); + evalProfitAmountEx(); + dw_profit.Redraw(); + } + + return 1; + } + + //event + int OnDWClick(ref TNotifyEvent evt, int p) + { + ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); + xstring value = hdr.data; + xstring colname = hdr.colname; + + return 1; + } + + int OnProfitItemChanged(ref TNotifyEvent evt, int p) + { + int HCursor = xutil::SetCursorWait(); + ref DWNMHDR hdr = cast(evt.pnmh as ref DWNMHDR); + int row = hdr.row; + xstring col = hdr.colname; + xstring data = hdr.data; + + if (col == L"DrawbackIntrest" || + col == L"DrawbackIntrest" || + col == L"CustomFee" || + col == L"InspectionFee" || + col == L"PaperCardCopyFee" || + col == L"TransportationFee" || + col == L"StorageFee" || + col == L"PortIncidentalFee" || + col == L"BankFee" || + col == L"RiskPrepareFee" || + col == L"AllocatedFee" || + col == L"ManagementFee" || + col == L"RiskFundAmount" || + col == L"FundsIntrestFee" || + col == L"AgentAmount" || + col == L"AgentTax" || + col == L"OtherFee") + { + evalTotalCost(); + evalProfitAmountEx(); + dw_profit.Redraw(); + } + + xutil::RestoreCursor(HCursor); + + return 1; + } + + int OnCustomItemChanged(ref TNotifyEvent evt, int p) + { + int HCursor = xutil::SetCursorWait(); + ref DWNMHDR hdr = cast(evt.pnmh as ref DWNMHDR); + int row = hdr.row; + xstring col = hdr.colname; + xstring data = hdr.data; + if (col == L"AdjustParam") + { + double rate = 1.0; + if (data != L"") rate = data.toDouble(); + double amt = dw_custom.GetItemDouble(row, L"AmountEx"); + dw_custom.SetItemDouble(row, L"Amount", amt * rate); + double quantity = dw_custom.GetItemDouble(row, L"Quantity"); + double price = amt * rate / quantity; + dw_custom.SetItemDouble(row, L"UnitPrice", price); + dw_custom.Redraw(); + } + if (col == L"UnitPrice" || col == L"Quantity") + { + double UnitPrice = dw_custom.GetItemDouble(row, L"UnitPrice"); + double Quantity = dw_custom.GetItemDouble(row, L"Quantity"); + double Amount = UnitPrice * Quantity; + dw_custom.SetItemDouble(row, L"Amount", Amount); + dw_custom.Redraw(); + } + return 1; + } + + int CalcDraftAmount() + { + + double amt = dw_base.GetItemDouble(1, L"Amount");//4646 + double camt = dw_base.GetItemDouble(1, L"CommissionAmount");//46 + amt = amt - camt; + double damt = dw_base.GetItemDouble(1, L"DiscountAmount");//46 + amt = amt - damt; + double exterm = dw_base.GetItemDouble(1, L"Cost");//46 + xstring moreless = dw_base.GetItemString(1, L"CostMoreLess");//-1 + if (dw_base.GetItemString(1, L"Cost") != L"") + { + if (moreless == L"-1") + amt = amt - exterm; + else + amt = amt + exterm; + } + dw_base.SetItemDouble(1, L"DraftAmount", amt); + return 1; + } + + int OnBaseItemChanged(ref TNotifyEvent evt, int p) + { + + int HCursor = xutil::SetCursorWait(); + ref DWNMHDR hdr = cast(evt.pnmh as ref DWNMHDR); + int row = hdr.row; + xstring col = hdr.colname; + xstring data = hdr.data; + + if (col == L"CustomerID") + { + SetCustomerHabit(data); + return 1; + } + if (col == L"InvoiceNo") + { + dw_profit.SetItemString(1, L"InvoiceNo", data); + dw_base.Redraw(); + } + else if (col == L"Amount") + { + double amt = dw_base.GetItemDouble(1, L"Amount"); + if (dw_base.GetItemString(1, L"CommissionRate") != L"") + { + double commrate1 = dw_base.GetItemDouble(1, L"CommissionRate"); + dw_base.SetItemDouble(1, L"CommissionAmount", amt * commrate1 / 100.0); + } + if (dw_base.GetItemString(1, L"PrivateCommissionRate") != L"") + { + double fcommrate1 = dw_base.GetItemDouble(1, L"PrivateCommissionRate"); + dw_base.SetItemDouble(1, L"PrivateCommissionAmount", amt * fcommrate1 / 100.0); + } + if (dw_base.GetItemString(1, L"DiscountRate") != L"") + { + double drate1 = dw_base.GetItemDouble(1, L"DiscountRate"); + dw_base.SetItemDouble(1, L"DiscountAmount", amt * drate1 / 100.0); + } + CalcDraftAmount(); + CalcProfit(); + + dw_base.Redraw(); + } + + if (col == L"Cost" || col == L"CostMoreLess") + { + CalcDraftAmount(); + CalcProfit(); + dw_base.Redraw(); + } + + if (col == L"CommissionAmount" || col == L"PrivateCommissionAmount" || col == L"DiscountAmount") + { + CalcDraftAmount(); + CalcProfit(); + + dw_base.Redraw(); + } + if (col == L"GoodsSource") + { + + xstring s = dw_base.GetItemString(1, L"GoodsSource"); + xml supplier_x = ViewObject::RetrieveData(L"/sale/data/expense3/view/FindByOriginName", L"OriginName", s); + if (supplier_x) + { + KXMLDOMNode o = supplier_x.GetXmlDoc().selectSingleNode(L"Item"); + xstring GoodsSource = o.selectSingleNode(L"OriginName").text; + xstring OriginID = o.selectSingleNode(L"OriginID").text; + xstring sname = OriginID + L" " + s; + xstring name = o.selectSingleNode(L"name").text; + if (sname == name) { + dw_base.SetItemDisplayString(1, L"GoodsSource", name); + dw_base.SetItemString(1, L"GoodsSource", name); + } + } + else if (!supplier_x) { + dw_base.SetItemDisplayString(1, L"GoodsSource", L""); + dw_base.SetItemString(1, L"GoodsSource", L""); + + } + dw_base.Redraw(); + } + if (col == L"CommissionRate") + { + if (data == L"") + { + dw_base.SetItemString(1, L"CommissionAmount", L""); + } + else + { + double commrate = data.toDouble(); + dw_base.SetItemDouble(1, L"CommissionAmount", + dw_base.GetItemDouble(1, L"Amount") * commrate / 100.0); + } + CalcDraftAmount(); + CalcProfit(); + dw_base.Redraw(); + } + if (col == L"DiscountRate") + { + if (data == L"") + { + dw_base.SetItemString(1, L"DiscountAmount", L""); + } + else + { + double DiscountRate = data.toDouble(); + dw_base.SetItemDouble(1, L"DiscountAmount", + dw_base.GetItemDouble(1, L"Amount") * DiscountRate / 100.0); + } + CalcDraftAmount(); + CalcProfit(); + dw_base.Redraw(); + } + else if (col == L"PrivateCommissionRate") + { + if (data == L"") + { + dw_base.SetItemString(1, L"PrivateCommissionAmount", L""); + } + else + { + double fcommrate = data.toDouble(); + dw_base.SetItemDouble(1, L"PrivateCommissionAmount", + dw_base.GetItemDouble(1, L"Amount") * fcommrate / 100.0); + } + CalcProfit(); + dw_base.Redraw(); + } + else if (col == L"PaymentTerm") + { + if (data.find(L"L/C") >= 0) + { + dw_base.SetColumnProp(L"LCNo", L"cellprotect", L"0"); + dw_base.SetColumnProp(L"LCSignDate", L"cellprotect", L"0"); + dw_base.SetColumnProp(L"LCSigner", L"cellprotect", L"0"); + dw_base.SetColumnProp(L"LCReceiveDate", L"cellprotect", L"0"); + dw_base.SetColumnProp(L"LCBank", L"cellprotect", L"0"); + dw_base.Redraw(); + } + else + { + dw_base.SetColumnProp(L"LCNo", L"cellprotect", L"1"); + dw_base.SetColumnProp(L"LCSignDate", L"cellprotect", L"1"); + dw_base.SetColumnProp(L"LCSigner", L"cellprotect", L"1"); + dw_base.SetColumnProp(L"LCReceiveDate", L"cellprotect", L"1"); + dw_base.SetColumnProp(L"LCBank", L"cellprotect", L"1"); + dw_base.Redraw(); + } + } + else if (col == L"ETD") + { + xstring ETD = dw_base.GetItemString(1, L"ETD"); + xstring exchangeRate = L""; + if (ETD != L"") + { + trace(ETD); + xml x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/paramEx", L"ETD", ETD); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchangeRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + if (exchangeRate != L"") + { + dw_profit.SetItemString(1, L"ExchangeRate", exchangeRate); + } + else + { + xml xp = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"cryrate"); + if (xp.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchangeRate = xp.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + dw_profit.SetItemString(1, L"ExchangeRate", exchangeRate); + + } + evalManagementFee(); + evalRiskFundAmount(); + } + + dw_profit.Redraw(); + } + return 1; + } + + double CalcVolumePkg(int row) + { + xstring ll = dw_item.GetItemString(row, L"PackageL"); + xstring lw = dw_item.GetItemString(row, L"PackageW"); + xstring lh = dw_item.GetItemString(row, L"PackageH"); + double pl = dw_item.GetItemDouble(row, L"PackageL"); + double pw = dw_item.GetItemDouble(row, L"PackageW"); + double ph = dw_item.GetItemDouble(row, L"PackageH"); + if (ll != L"" || lh != L"" || lw != L"") + { + if (lh == L"") ph = 1.0; + if (lw == L"") pw = 1.0; + if (ll == L"") pl = 1.0; + return pl * ph * pw / 1000000.0; + } + else + return 0.0; + } + + int OnSetRetax(int row) + { + if (row < 1) return 1; + + xstring ClassifyID = dw_item.GetItemString(row, L"ClassifyID"); + xstring refundRate = L"*"; + trace(L"\r\n--------" + ClassifyID + L"-----------"); + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyinfo", L"ClassifyID", ClassifyID); + if (x) + { + KXMLDOMNode o = x.GetXmlDoc().selectSingleNode(L"data/Item"); + if (o) + { + refundRate = o.selectSingleNode(L"VATRefundRate").text; + } + } + if (refundRate != L"*") + { + xstring GDNLineID = dw_item.GetGuid(row); + for (int i = dw_source.GetRowCount(); i >= 1; i--) + { + if (dw_source.GetItemString(i, L"GDNLineID") == GDNLineID) + { + if (dw_source.GetItemString(i, L"HasVATInvoice") == L"Y") + { + dw_source.SetItemString(i, L"VATRefundRate", refundRate); + dw_source.ItemChangeTo(i, L"VATRefundRate", refundRate); + } + } + } + } + return 1; + } + + int SetCDUnitPrice(int row, xstring col, xstring data) + { + if (data == L"") + { + dw_item.SetItemDisplayString(row, col, L""); + dw_item.SetItemString(row, L"CDUnitPrice", L""); + dw_item.SetItemDisplayString(row, L"CDUnitPrice", L""); + } + else + { + double d3 = dw_item.GetItemDouble(row, L"CDAmount"); + double d4 = dw_item.GetItemDouble(row, L"CDQuantity"); + double d6 = 0.0; + if (d4 == 0.0) dw_item.GetItemDouble(row, L"Quantity"); + if (d4 != 0.0) + { + double d5 = d3 / d4; + d5 = d5.round(4); + if (d3 <= 0.0 && d4 <= 0.0) + { + //trace(L"--------1111-----------"); + dw_item.SetItemDouble(row, L"CDUnitPrice", d6); + } + else + { + dw_item.SetItemDouble(row, L"CDUnitPrice", d5); + } + dw_item.Redraw(); + } + } + return 1; + } + + int OnItemChanged(ref TNotifyEvent evt, int p) + { + //if(datareading) return 0; + int HCursor = xutil::SetCursorWait(); + ref DWNMHDR hdr = cast(evt.pnmh as ref DWNMHDR); + int row = hdr.row; + xstring col = hdr.colname; + xstring data = hdr.data; + + if (col == L"ClassifyID") + { + OnSetRetax(row); + CalcProfit(); + return 1; + } + if (col == L"Quantity" || col == L"PackingRate") + { + //件数 + double dqty = dw_item.GetItemDouble(row, L"Quantity"); + xstring spackingrate = dw_item.GetItemString(row, L"PackingRate"); + int ipack = caclPacking(dqty, spackingrate); + dw_item.ItemChangeTo(row, L"Packages", ipack.toString()); + if (col == L"Quantity") + { + if (!datareading) + { + calcTotal(); + RefreshSourcingItem1(row); + CalcProfit(); + //RefreshSourcingAllEx(); + } + } + dw_item.Redraw(); + } + if (col == L"Packages") + { + double packages = dw_item.GetItemDouble(row, L"Packages"); + double nwpkg = dw_item.GetItemDouble(row, L"NWPerPkg"); + double gwpkg = dw_item.GetItemDouble(row, L"GWPerPkg"); + double UnitCommPrice = dw_item.GetItemDouble(row, L"UnitCommPrice"); + double Quantity2 = dw_item.GetItemDouble(row, L"Quantity"); + double MiddlemanAmount = dw_item.GetItemDouble(row, L"MiddlemanAmount"); + + double nw = nwpkg * packages; + double gw = gwpkg * packages; + double rw = UnitCommPrice * Quantity2; + double MiddlemanAmountRate = MiddlemanAmount * Quantity2; + + double pv2 = CalcVolumePkg(row); + dw_item.SetItemDouble(row, L"VolumePerPkg", pv2); + double ctns2 = dw_item.GetItemDouble(row, L"Packages"); + double svol2 = pv2 * ctns2; + dw_item.SetItemDouble(row, L"Volume", svol2.round(2)); + + dw_item.SetItemDouble(row, L"NW", nw); + dw_item.SetItemDouble(row, L"GW", gw); + dw_item.SetItemDouble(row, L"ResearchCommissionRate", rw); + dw_item.SetItemDouble(row, L"MiddlemanAmountRate", MiddlemanAmountRate); + dw_item.Redraw(); + calcTotal(); + + } + if (col == L"NWPerPkg" || col == L"MiddlemanAmount" || col == L"GWPerPkg" || col == L"MiddlemanAmountRate" || col == L"ResearchCommissionRate" || col == L"Quantity" || col == L"UnitCommPrice") + { + double packages1 = dw_item.GetItemDouble(row, L"Packages"); + double UnitCommPrice1 = dw_item.GetItemDouble(row, L"UnitCommPrice"); + double nwpkg1 = dw_item.GetItemDouble(row, L"NWPerPkg"); + double gwpkg1 = dw_item.GetItemDouble(row, L"GWPerPkg"); + double Quantity1 = dw_item.GetItemDouble(row, L"Quantity"); + double MiddlemanAmount1 = dw_item.GetItemDouble(row, L"MiddlemanAmount"); + + double nw1 = nwpkg1 * packages1; + double gw1 = gwpkg1 * packages1; + double rw1 = UnitCommPrice1 * Quantity1; + double MiddlemanAmountRate1 = MiddlemanAmount1 * Quantity1; + + dw_item.SetItemDouble(row, L"NW", nw1); + dw_item.SetItemDouble(row, L"GW", gw1); + dw_item.SetItemDouble(row, L"ResearchCommissionRate", rw1); + dw_item.SetItemDouble(row, L"MiddlemanAmountRate", MiddlemanAmountRate1); + + double NWS = 0.0; + double GWS = 0.0; + double RWS = 0.0; + double MAS = 0.0; + for (int i = 1; i <= dw_item.GetRowCount(); ++i) + { + double NW = dw_item.GetItemDouble(i, L"NW"); + NWS += NW; + double GW = dw_item.GetItemDouble(i, L"GW"); + GWS += GW; + double RW = dw_item.GetItemDouble(i, L"ResearchCommissionRate"); + RWS += RW; + double MA = dw_item.GetItemDouble(i, L"MiddlemanAmountRate"); + MAS += MA; + } + dw_base.SetItemDouble(1, L"NW", NWS); + dw_base.SetItemDouble(1, L"GW", GWS); + dw_base.SetItemDouble(1, L"ResearchCommissionRate", RWS); + + dw_item.Redraw(); + } + if (col == L"PackageL" || col == L"PackageW" || col == L"PackageH") + { + double pv = CalcVolumePkg(row); + dw_item.SetItemDouble(row, L"VolumePerPkg", pv); + double ctns = dw_item.GetItemDouble(row, L"Packages"); + double svol = pv * ctns; + //trace(svol.toString() +L"******"+svol.round(2)); + + dw_item.SetItemDouble(row, L"Volume", svol.round(2)); + double Volumes = 0.0; + for (int roww = 1; roww <= dw_item.GetRowCount(); ++roww) + { + double Volume = dw_item.GetItemDouble(roww, L"Volume"); + Volumes += Volume.round(2); + } + dw_base.SetItemDouble(1, L"Volume", Volumes.round(2)); + dw_item.Redraw(); + } + if (col == L"VolumePerPkg") + { + double pv1 = CalcVolumePkg(row); + double ctns1 = dw_item.GetItemDouble(row, L"Packages"); + double svol1 = pv1 * ctns1; + dw_item.SetItemDouble(row, L"Volume", svol1); + dw_item.Redraw(); + } + if (col == L"Quantity" || col == L"UnitPrice") + { + if (!datareading) + { + double d1 = dw_item.GetItemDouble(row, L"Quantity"); + double d2 = dw_item.GetItemDouble(row, L"UnitPrice"); + double d = d1 * d2; + d = d.round(2); + dw_item.SetItemDouble(row, L"Amount", d); + + calcTotal(); + CalcProfit(); + } + } + if (col == L"CDAmount" || col == L"CDQuantity") + { + SetCDUnitPrice(row, col, data); + } + + xutil::RestoreCursor(HCursor); + + return 1; + } + + + int GDNSourcePoTotal() + { + double Amount_s = 0.0; + double Vol_s = 0.0; + double Vol_A = 2.0; + for (int row = 1; row <= dw_source.GetRowCount(); ++row) + { + for (int k = 1; k <= dw_item.GetRowCount(); ++k) { + //double UnitPrice = dw_source.GetItemDouble(row,L"UnitPrice"); + KXMLDOMElement e = dw_item.GetRowElement(k); + xstring GDNLineID = e.getAttribute(L"guid"); + double GDNSourceAmount = dw_source.GetItemDouble(row, L"BuyAmount"); + double GDNItemAmount = dw_item.GetItemDouble(k, L"Amount"); + xstring POGDNLineID = dw_source.GetItemString(row, L"GDNLineID"); + if (GDNLineID == POGDNLineID) { + Amount_s += GDNSourceAmount; + } + + } + Vol_s = Amount_s / GDNItemAmount; + dw_source.SetItemDouble(row, L"Swapthecost", Vol_s); + } + return 1; + } + + int OnItemChangedEx(ref TNotifyEvent evt, int p) + { + ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); + xstring colname = hdr.colname; + xstring value = hdr.data; + + if (colname == L"VATRefundRate") + { + //double price1 = dw_source.GetItemDouble(hdr.row,L"BuyUnitPrice"); + //double quantity1 = dw_source.GetItemDouble(hdr.row,L"BuyQuantity"); + double amount1 = dw_source.GetItemDouble(hdr.row, L"BuyAmount"); + double VATRefundRate = dw_source.GetItemDouble(hdr.row, L"VATRefundRate"); + //dw_source.SetItemDouble(hdr.row,L"RefundAmount", price1 * quantity1 / 1.13 * VATRefundRate/100); + dw_source.SetItemDouble(hdr.row, L"RefundAmount", amount1 / 1.13 * VATRefundRate / 100); + evalDrawbackEx(); + evalTotalCost(); + evalProfitAmountEx(); + } + + if (colname == L"BuyUnitPrice" || colname == L"BuyQuantity" || colname == L"PackUnitPrice") //读取最近订单信息 + { + double price = dw_source.GetItemDouble(hdr.row, L"BuyUnitPrice"); + double quantity = dw_source.GetItemDouble(hdr.row, L"BuyQuantity"); + double Amount = dw_source.GetItemDouble(hdr.row, L"Amount"); + double PackUnitPrice = dw_source.GetItemDouble(hdr.row, L"PackUnitPrice"); + dw_source.SetItemDouble(hdr.row, L"BuyAmount", price * quantity + PackUnitPrice); + } + if (colname == L"BuyUnitPrice" || colname == L"BuyQuantity" || colname == L"PackUnitPrice" || colname == L"BuyAmount") + { + if (dw_source.GetItemString(hdr.row, L"VATRefundRate") != L"") + { + double amount2 = dw_source.GetItemDouble(hdr.row, L"BuyAmount"); + double VATRefundRate2 = dw_source.GetItemDouble(hdr.row, L"VATRefundRate"); + dw_source.SetItemDouble(hdr.row, L"RefundAmount", amount2 / 1.13 * VATRefundRate2 / 100); + } + CalcProfit(); + } + return 1; + } + + + int OnAskDataBase(ref TNotifyEvent evt, int p) + { + ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); + + xstring x = hdr.colname; + if (x == L"userSalespersonID") + { + xstring sSalespersonID = dw_base.GetItemString(1, L"SalespersonID"); + hdr.data = sSalespersonID; + } + return 1; + } + + int OnBillNoteDoubleClicked(ref TNotifyEvent evt, int p) + { + ref DWNMHDR hdr = evt.pnmh; + xstring colname = hdr.colname; + int row = hdr.row; + if (colname == L"Content") + { + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + xstring str = dw_billnote.GetItemString(row, colname); + arg.AddArg(L"value", str); + openUrl(L"/sale/view/view.dlg/xpage/memo/edit/new", arg.getNativePointer()); + xstring comdid = arg.GetArgString(L"comdid"); + if (comdid == L"xmOK") + { + xstring value = arg.GetArgString(L"value"); + dw_billnote.SetItemString(row, colname, value); + dw_billnote.Redraw(); + } + } + return 1; + } + + int OnPrint() + { + CheckCDLine(); + CheckGW(); + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + arg.AddArg(L"EntityName", L"GDN3", L""); + arg.AddArg(L"EntityID", InvoiceID, L""); + arg.AddArg(L"EntityNo", dw_base.GetItemString(1, L"InvoiceNo"), L""); + int p = arg.ptr_native_; + openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", p); + return 1; + } + + int OnMakeSumPack() + { + double Quantity_s = 0.0; + int Packages_s = 0.0; + double GW_s = 0.0; + double NW_s = 0.0; + double Amount_s = 0.0; + double Vol_s = 0.0; + + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + int Packages = dw_item.GetItemDouble(row, L"Packages").toInt(); + double GW = dw_item.GetItemDouble(row, L"GW"); + double NW = dw_item.GetItemDouble(row, L"NW"); + double Amount = dw_item.GetItemDouble(row, L"Amount"); + double Vol = dw_item.GetItemDouble(row, L"Volume"); + + Quantity_s += Quantity; + Packages_s += Packages; + GW_s += GW; + NW_s += NW; + Amount_s += Amount; + Vol_s += Vol; + } + + return 1; + } + + int OnMakeContainer() + { + int cnt = dw_fcl.GetRowCount(); + for (int k = 1; k <= cnt; k++) + { + dw_fcl.SetItemDouble(k, L"Quantity", 0.0); + dw_fcl.SetItemDouble(k, L"GW", 0.0); + dw_fcl.SetItemDouble(k, L"NW", 0.0); + dw_fcl.SetItemString(k, L"Packages", L"0"); + dw_fcl.SetItemDouble(k, L"Volume", 0.0); + dw_fcl.SetItemString(k, L"UseFlag", L"0"); + dw_fcl.SetItemDouble(k, L"Amount", 0.0); + } + + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + xstring ContainerNo = dw_item.GetItemString(row, L"ContainerNo"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + int Packages = dw_item.GetItemInt(row, L"Packages"); + double GW = dw_item.GetItemDouble(row, L"GW"); + double NW = dw_item.GetItemDouble(row, L"NW"); + double Amount = dw_item.GetItemDouble(row, L"Amount"); + double Vol = dw_item.GetItemDouble(row, L"Volume"); + + int i = 1; + for (i = 1; i <= dw_fcl.GetRowCount(); i++) + { + if (dw_fcl.GetItemString(i, L"ContainerNo") == ContainerNo)break; + } + if (i > dw_fcl.GetRowCount()) + { + dw_fcl.InsertRow(0); + i = dw_fcl.GetRowCount(); + + dw_fcl.SetItemString(i, L"ContainerNo", ContainerNo); + dw_fcl.SetItemString(i, L"GDNID", dw_base.GetGuid(1)); + } + + dw_fcl.SetItemString(i, L"UseFlag", L"1"); + + double val; + val = dw_fcl.GetItemDouble(i, L"Amount"); + val += Amount; + dw_fcl.SetItemDouble(i, L"Amount", val); + + val = dw_fcl.GetItemDouble(i, L"Quantity"); + val += Quantity; + dw_fcl.SetItemDouble(i, L"Quantity", val); + + val = dw_fcl.GetItemDouble(i, L"GW"); + val += GW; + dw_fcl.SetItemDouble(i, L"GW", val); + + val = dw_fcl.GetItemDouble(i, L"NW"); + val += NW; + dw_fcl.SetItemDouble(i, L"NW", val); + + int nval = dw_fcl.GetItemDouble(i, L"Packages"); + nval += Packages; + dw_fcl.SetItemInt(i, L"Packages", nval); + + val = dw_fcl.GetItemDouble(i, L"Volume"); + val += Vol; + dw_fcl.SetItemDouble(i, L"Volume", val); + + } + dw_fcl.Redraw(); + + for (int m = cnt; m >= 1; m--) + { + if (dw_fcl.GetItemString(m, L"UseFlag") == L"0") + dw_fcl.DeleteRow(m); + } + + return 1; + } + + int OnMakeCustom() + { + int HCursor = xutil::SetCursorWait(); + dw_custom.AcceptText(); + int cnt = dw_custom.GetRowCount(); + bool cdelement = false; + for (int k = 1; k <= cnt; k++) + { + dw_custom.SetItemString(k, L"Quantity", L""); + dw_custom.SetItemString(k, L"Packages", L""); + dw_custom.SetItemString(k, L"GW", L""); + dw_custom.SetItemString(k, L"NW", L""); + dw_custom.SetItemString(k, L"Amount", L""); + dw_custom.SetItemString(k, L"AmountEx", L""); + dw_custom.SetItemString(k, L"VATRate", L""); + dw_custom.SetItemString(k, L"VATRefundRate", L""); + dw_custom.SetItemString(k, L"Volume", L""); + dw_custom.SetItemString(k, L"UnitPrice", L""); + dw_custom.SetItemString(k, L"UOMCode", L""); + dw_custom.SetItemString(k, L"KOPCode", L""); + dw_custom.SetItemString(k, L"UseFlag", L"0"); + dw_custom.SetItemString(k, L"AmountEx", L""); + dw_custom.SetItemString(k, L"CurrencyCode", L""); + dw_custom.SetItemString(k, L"LineNo", L""); + } + + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + xstring ClassifyID = dw_item.GetItemString(row, L"ClassifyID"); + xstring name = dw_item.GetItemDisplayString(row, L"ClassifyID"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + xstring GroupNo = dw_item.GetItemString(row, L"GroupNo"); + int Packages = dw_item.GetItemInt(row, L"Packages"); + double GW = dw_item.GetItemDouble(row, L"GW"); + double NW = dw_item.GetItemDouble(row, L"NW"); + double Amount = dw_item.GetItemDouble(row, L"Amount"); + xstring VATRate = dw_item.GetItemString(row, L"VATRate"); + xstring VATRefundRate = dw_item.GetItemString(row, L"VATRefundRate"); + double Vol = dw_item.GetItemDouble(row, L"Volume"); + xstring UnitPrice = dw_item.GetItemString(row, L"UnitPrice"); + xstring UOMCode = dw_item.GetItemString(row, L"UOMCode"); + xstring KOPCode = dw_item.GetItemString(row, L"KOPCode"); + + int i = 1; + bool bAdd = false; + for (i = 1; i <= dw_custom.GetRowCount(); i++) + { + if (dw_custom.GetItemString(i, L"ClassifyID") == ClassifyID && dw_custom.GetItemString(i, L"GroupNo") == GroupNo) + break; + } + if (i > dw_custom.GetRowCount()) + { + dw_custom.InsertRow(0); + i = dw_custom.GetRowCount(); + dw_custom.SetItemString(i, L"ClassifyID", ClassifyID); + bAdd = true; + } + dw_custom.SetItemString(i, L"UseFlag", L"1"); + dw_custom.SetItemString(i, L"CustName", name); + dw_custom.SetItemString(i, L"GroupNo", GroupNo); + + double val = 0; + double samt = 0; + val = dw_custom.GetItemDouble(i, L"Amount"); + val += Amount; + samt = val; + dw_custom.SetItemDouble(i, L"Amount", val); + dw_custom.SetItemDouble(i, L"AmountEx", val); + dw_custom.SetItemString(i, L"VATRates", VATRate); + dw_custom.SetItemString(i, L"VATRefundRate", VATRefundRate); + dw_custom.SetItemString(i, L"UOMCode", UOMCode); + dw_custom.SetItemString(i, L"KOPCode", KOPCode); + dw_custom.SetItemDisplayString(i, L"UOMCode", dw_item.GetItemDisplayString(row, L"UOMCode")); + dw_custom.SetItemDisplayString(i, L"KOPCode", dw_item.GetItemDisplayString(row, L"KOPCode")); + dw_custom.SetItemString(i, L"CurrencyCode", CurrencyCode); + + + + val = dw_custom.GetItemDouble(i, L"Quantity"); + val += Quantity.round(3); + double sqty = 0; + sqty = val; + dw_custom.SetItemDouble(i, L"Quantity", val); + + val = dw_custom.GetItemDouble(i, L"GW"); + val += GW.round(3); + dw_custom.SetItemDouble(i, L"GW", val); + + val = dw_custom.GetItemDouble(i, L"NW"); + val += NW.round(3); + dw_custom.SetItemDouble(i, L"NW", val); + + int nval = dw_custom.GetItemDouble(i, L"Packages"); + nval += Packages; + dw_custom.SetItemInt(i, L"Packages", nval); + + val = dw_custom.GetItemDouble(i, L"Volume"); + val += Vol; + dw_custom.SetItemDouble(i, L"Volume", val); + + double price = samt / sqty; + dw_custom.SetItemDouble(i, L"UnitPrice", price); + + + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyinfo", L"ClassifyID", ClassifyID); + + if (x) + { + KXMLDOMNode o = x.GetXmlDoc().selectSingleNode(L"data/Item"); + if (o) + { + if (o.selectSingleNode(L"VATRates")) + { + xstring str1 = o.selectSingleNode(L"VATRates").text; + if (str1.find(L",L") >= 0) str1 = str1.left(str1.find(L",L")); + dw_custom.SetItemString(i, L"VATRates", str1); + } + if (o.selectSingleNode(L"CustEName")) + { + dw_custom.SetItemString(i, L"CustEName", o.selectSingleNode(L"CustEName").text); + } + if (o.selectSingleNode(L"SupervisionRuler")) + { + dw_custom.SetItemString(i, L"SupervisionRuler", o.selectSingleNode(L"SupervisionRuler").text); + } + if (o.selectSingleNode(L"VATRefundRate")) + { + dw_custom.SetItemString(i, L"VATRefundRate", o.selectSingleNode(L"VATRefundRate").text); + } + if (o.selectSingleNode(L"HSCode")) + { + xstring hscode = o.selectSingleNode(L"HSCode").text; + if (dw_custom.GetItemString(i, L"CustName").find(L"[") >= 0) + { + xstring str = dw_custom.GetItemString(i, L"CustName"); + + str = str.left(str.find(L"[")); + dw_custom.SetItemString(i, L"CustName", str); + } + dw_custom.SetItemString(i, L"HSCode", hscode); + } + if (o.selectSingleNode(L"UOM")) + { + dw_custom.SetItemString(i, L"LegalUOMCode", o.selectSingleNode(L"UOM").text); + dw_customex.SetItemString(i, L"LegalUOMCode", o.selectSingleNode(L"UOM").text); + xstring uom = o.selectSingleNode(L"UOM").text; + if (uom == L"千克") + { + dw_custom.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"NW")); + } + else + { + dw_custom.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"Quantity")); + } + } + } + } + /* + xml x= ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyinfo",L"ClassifyID",ClassifyID); + if(x) + { + KXMLDOMNode o = x.GetXmlDoc().selectSingleNode(L"data/Item"); + if(o) + { + if(o.selectSingleNode(L"VATRates")) + { + xstring str1 = o.selectSingleNode(L"VATRates").text; + if(str1.find(L",L")) str1 = str1.left(str1.find(L",L")); + dw_custom.SetItemString(i,L"VATRates",str1); + } + if(o.selectSingleNode(L"CustEName")) + { + dw_custom.SetItemString(i,L"CustEName",o.selectSingleNode(L"CustEName").text); + }dw_base.SetItemString(1,L"Amount") + if(o.selectSingleNode(L"VATRefundRate")) + { + dw_custom.SetItemString(i,L"VATRefundRate",o.selectSingleNode(L"VATRefundRate").text); + } + if(o.selectSingleNode(L"SupervisionRuler")) + { + dw_custom.SetItemString(i,L"SupervisionRuler",o.selectSingleNode(L"SupervisionRuler").text); + } + if(o.selectSingleNode(L"HSCode")) + { + xstring hscode = o.selectSingleNode(L"HSCode").text; + if(dw_custom.GetItemString(i,L"CustName").find(L"["+hscode)>=0) + { + xstring str = dw_custom.GetItemString(i,L"CustName"); + str = str.left(str.find(L"[" + hscode)); + dw_custom.SetItemString(i,L"CustName",str); + } + dw_custom.SetItemString(i,L"HSCode",hscode); + } + if(o.selectSingleNode(L"UOM")) + { + dw_custom.SetItemString(i,L"LegalUOMCode",o.selectSingleNode(L"UOM").text); + dw_customex.SetItemString(i,L"LegalUOMCode",o.selectSingleNode(L"UOM").text); + xstring uom = o.selectSingleNode(L"UOM").text; + if(uom==L"千克") + { + dw_custom.SetItemString(i,L"LegalQty",dw_custom.GetItemString(i,L"NW")); + } + else + { + dw_custom.SetItemString(i,L"LegalQty",dw_custom.GetItemString(i,L"Quantity")); + } + } + } + }*/ + if (bAdd) + { + AddCDElement(i); + cdelement = true; + } + } + for (int m = cnt; m >= 1; m--) + { + if (dw_custom.GetItemString(m, L"UseFlag") == L"0") + { + if (dw_custom.GetItemString(i, L"ClassifyID") != L"") + DeleteCDElement(dw_custom.GetItemString(i, L"ClassifyID")); + dw_custom.DeleteRow(m); + } + } + xutil::RestoreCursor(HCursor); + dw_custom.Redraw(); + if (cdelement)alert(L"请更新报关要素!"); + + return 1; + } + + int AddCDElement(int cdrow) + { + xstring ClassifyID = dw_custom.GetItemString(cdrow, L"ClassifyID"); + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyelement", L"ClassifyID", ClassifyID); + if (x) + { + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"/GDN/CDElement"); + int lens = items.length; + for (int k = 0; k < lens; k++) + { + int row = dw_cdelement.InsertRow(0); + KXMLDOMElement e = items.item(k); + + KXMLDOMElement e1 = dw_custom.GetRowElement(cdrow); + xstring CDLineID = e1.getAttribute(L"guid"); + if (CDLineID == L"") + { + e1.SetAttribute(L"guid", ViewObject::GetGuid()); + CDLineID = e1.getAttribute(L"guid"); + } + dw_cdelement.SetItemString(row, L"CDLineID", CDLineID); + dw_cdelement.SetItemString(row, L"GDNID", dw_base.GetGuid(1)); + if (e.selectSingleNode(L"HSCode")) dw_cdelement.SetItemString(row, L"HSCode", e.selectSingleNode(L"HSCode").text); + if (e.selectSingleNode(L"SeqNo")) dw_cdelement.SetItemString(row, L"SeqNo", e.selectSingleNode(L"SeqNo").text); + if (e.selectSingleNode(L"EleName")) dw_cdelement.SetItemString(row, L"EleName", e.selectSingleNode(L"EleName").text); + if (e.selectSingleNode(L"EleContent")) dw_cdelement.SetItemString(row, L"EleContent", e.selectSingleNode(L"EleContent").text); + if (e.selectSingleNode(L"CustomName")) dw_cdelement.SetItemString(row, L"CustomName", e.selectSingleNode(L"CustomName").text); + if (e.selectSingleNode(L"ClassifyID")) dw_cdelement.SetItemString(row, L"ClassifyID", e.selectSingleNode(L"ClassifyID").text); + /*if(e.selectSingleNode(L"EleName")) + { + if(e.selectSingleNode(L"EleName").text==L"品牌类型") + { + if(dw_base.GetItemString(1,L"POL")==L"NINGBO") + { + dw_cdelement.SetItemString(row,L"EleContent",L"境内自主品牌"); + }else + { + dw_cdelement.SetItemString(row,L"EleContent",L"无品牌"); + } + } + else if(e.selectSingleNode(L"EleName").text==L"出口享惠情况") + {i + xstring country = dw_base.GetItemString(1,L"FinalCountry"); + if(country==L"") + { + dw_cdelement.SetItemString(row,L"EleContent",L"不享受"); + } + else if(L"601,127,322,129,415,337,133,107,119,122,103,434,106,331,134,136,105,132,609,111,112,141,412,143".find(country)>=0) + { + dw_cdelement.SetItemString(row,L"EleContent",L"享受"); + }else + { + dw_cdelement.SetItemString(row,L"EleContent",L"不享受"); + } + } + }*/ + } + } + return 1; + } + + int DeleteCDElement(xstring ClassifyID) + { + for (int m = dw_cdelement.GetRowCount(); m >= 1; m--) + { + if (dw_cdelement.GetItemString(m, L"ClassifyID") == ClassifyID)dw_cdelement.DeleteRow(m); + } + return 1; + } + + //生成 + int OnMakeCustom1() + { + if (dw_cdelement.GetRowCount() > 0) + { + if (win32::MessageBox(GetHWND(), L"更新报关信息会使报关要素无效,是否继续?", L"提示", 1) == 2) + return 1; + } + int cnt = dw_custom.GetRowCount(); + for (int k = 1; k <= cnt; k++) dw_custom.DeleteRow(1); + + cnt = dw_customex.GetRowCount(); + for (int m = 1; m <= cnt; m++) dw_customex.DeleteRow(1); + + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + + for (int row = 1; row <= dw_item.GetRowCount(); ++row) + { + xstring ClassifyID = dw_item.GetItemString(row, L"ClassifyID"); + xstring GroupNo = dw_item.GetItemString(row, L"GroupNo"); + xstring name = dw_item.GetItemDisplayString(row, L"ClassifyID"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + int Packages = dw_item.GetItemInt(row, L"Packages"); + double GW = dw_item.GetItemDouble(row, L"GW"); + double NW = dw_item.GetItemDouble(row, L"NW"); + double Amount = dw_item.GetItemDouble(row, L"Amount"); + xstring VATRate = dw_item.GetItemString(row, L"VATRate"); + xstring VATRefundRate = dw_item.GetItemString(row, L"VATRefundRate"); + double Vol = dw_item.GetItemDouble(row, L"Volume"); + xstring UnitPrice = dw_item.GetItemString(row, L"UnitPrice"); + xstring UOMCode = dw_item.GetItemString(row, L"UOMCode"); + xstring KOPCode = dw_item.GetItemString(row, L"KOPCode"); + + + int i = 1; + for (i = 1; i <= dw_custom.GetRowCount(); i++) + { + if (dw_custom.GetItemString(i, L"ClassifyID") == ClassifyID && dw_custom.GetItemString(i, L"GroupNo") == GroupNo) + break; + } + if (i > dw_custom.GetRowCount()) + { + dw_custom.InsertRow(0); + dw_customex.InsertRow(0); + i = dw_custom.GetRowCount(); + } + + dw_custom.SetItemString(i, L"ClassifyID", ClassifyID); + dw_customex.SetItemString(i, L"ClassifyID", ClassifyID); + dw_custom.SetItemString(i, L"CustName", name); + dw_customex.SetItemString(i, L"CustName", name); + dw_custom.SetItemString(i, L"GroupNo", GroupNo); + + double val = 0; + double samt = 0; + val = dw_custom.GetItemDouble(i, L"Amount"); + val += Amount; + samt = val; + dw_custom.SetItemDouble(i, L"Amount", val); + dw_custom.SetItemDouble(i, L"AmountEx", val); + dw_custom.SetItemString(i, L"VATRate", VATRate); + dw_custom.SetItemString(i, L"VATRefundRate", VATRefundRate); + dw_custom.SetItemString(i, L"UOMCode", UOMCode); + dw_custom.SetItemString(i, L"KOPCode", KOPCode); + dw_custom.SetItemDisplayString(i, L"UOMCode", + dw_item.GetItemDisplayString(row, L"UOMCode")); + dw_custom.SetItemDisplayString(i, L"KOPCode", + dw_item.GetItemDisplayString(row, L"KOPCode")); + dw_custom.SetItemString(i, L"CurrencyCode", CurrencyCode); + + dw_customex.SetItemDouble(i, L"Amount", val); + dw_customex.SetItemDouble(i, L"AmountEx", val); + dw_customex.SetItemString(i, L"VATRate", VATRate); + dw_customex.SetItemString(i, L"VATRefundRate", VATRefundRate); + dw_customex.SetItemString(i, L"UOMCode", UOMCode); + dw_customex.SetItemString(i, L"KOPCode", KOPCode); + dw_customex.SetItemDisplayString(i, L"UOMCode", + dw_item.GetItemDisplayString(row, L"UOMCode")); + dw_customex.SetItemDisplayString(i, L"KOPCode", + dw_item.GetItemDisplayString(row, L"KOPCode")); + dw_customex.SetItemString(i, L"CurrencyCode", CurrencyCode); + + val = dw_custom.GetItemDouble(i, L"Quantity"); + val += Quantity; + double sqty = 0; + sqty = val; + dw_custom.SetItemDouble(i, L"Quantity", val); + dw_customex.SetItemDouble(i, L"Quantity", val); + + val = dw_custom.GetItemDouble(i, L"GW"); + val += GW; + dw_custom.SetItemDouble(i, L"GW", val); + dw_customex.SetItemDouble(i, L"GW", val); + + val = dw_custom.GetItemDouble(i, L"NW"); + val += NW; + dw_custom.SetItemDouble(i, L"NW", val); + dw_customex.SetItemDouble(i, L"NW", val); + + int nval = dw_custom.GetItemDouble(i, L"Packages"); + nval += Packages; + dw_custom.SetItemInt(i, L"Packages", nval); + dw_customex.SetItemInt(i, L"Packages", nval); + + val = dw_custom.GetItemDouble(i, L"Volume"); + val += Vol; + dw_custom.SetItemDouble(i, L"Volume", val); + dw_customex.SetItemDouble(i, L"Volume", val); + + double price = samt / sqty; + dw_custom.SetItemDouble(i, L"UnitPrice", price); + dw_customex.SetItemDouble(i, L"UnitPrice", price); + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyinfoex", L"ClassifyID", ClassifyID); + if (x) + { + KXMLDOMNode o = x.GetXmlDoc().selectSingleNode(L"data/Item"); + if (o) + { + if (o.selectSingleNode(L"VATRates")) + { + xstring str1 = o.selectSingleNode(L"VATRates").text; + if (str1.find(L",L")) str1 = str1.left(str1.find(L",L")); + dw_custom.SetItemString(i, L"VATRates", str1); + dw_customex.SetItemString(i, L"VATRates", str1); + } + if (o.selectSingleNode(L"CustEName")) + { + dw_custom.SetItemString(i, L"CustEName", o.selectSingleNode(L"CustEName").text); + dw_customex.SetItemString(i, L"CustEName", o.selectSingleNode(L"CustEName").text); + } + if (o.selectSingleNode(L"SupervisionRuler")) + { + dw_custom.SetItemString(i, L"SupervisionRuler", o.selectSingleNode(L"SupervisionRuler").text); + } + if (o.selectSingleNode(L"VATRefundRate")) + { + dw_custom.SetItemString(i, L"VATRefundRate", o.selectSingleNode(L"VATRefundRate").text); + dw_customex.SetItemString(i, L"VATRefundRate", o.selectSingleNode(L"VATRefundRate").text); + } + if (o.selectSingleNode(L"HSCode")) + { + xstring hscode = o.selectSingleNode(L"HSCode").text; + if (dw_custom.GetItemString(i, L"CustName").find(L"[" + hscode) >= 0) + { + xstring str = dw_custom.GetItemString(i, L"CustName"); + + str = str.left(str.find(L"[" + hscode)); + dw_custom.SetItemString(i, L"CustName", str); + dw_customex.SetItemString(i, L"CustName", str); + } + dw_custom.SetItemString(i, L"HSCode", hscode); + dw_customex.SetItemString(i, L"HSCode", hscode); + } + if (o.selectSingleNode(L"UOM")) + { + dw_custom.SetItemString(i, L"LegalUOMCode", o.selectSingleNode(L"UOM").text); + dw_customex.SetItemString(i, L"LegalUOMCode", o.selectSingleNode(L"UOM").text); + xstring uom = o.selectSingleNode(L"UOM").text; + if (uom == L"千克") + { + dw_custom.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"NW")); + dw_customex.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"NW")); + } + else + { + dw_custom.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"Quantity")); + dw_customex.SetItemString(i, L"LegalQty", dw_custom.GetItemString(i, L"Quantity")); + } + } + } + } + } + + alert(L"报关数据已刷新,请更新报关要素!"); + + + + return 1; + } + + int OnAddSourcingItem() + { + xaserverarg arg = GDNView::MakeArg(); + arg.AddArg(L"InvoiceNo", dw_base.GetItemString(1, L"InvoiceNo")); + int p = arg; + OpenWindow(L"dev:xpage[select.item.po.vx]", p); + xstring str = arg.GetArgString(L"items"); + if (str != L"") + { + xml x; + + x.LoadXml(str); + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + int len = items.length; + int row = 0; + for (int i = 0; i < len; i++) + { + if (i == 0 && dw_source.GetRowCount() > 0 && dw_source.GetItemString(dw_source.GetRowCount(), L"GoodsNo") == L"") + { + row = dw_source.GetRowCount(); + } + else + { + row = dw_source.InsertRow(0); + } + KXMLDOMNode t = items.item(i); + + if (t.selectSingleNode(L"PONo"))dw_source.SetItemString(row, L"PONo", t.selectSingleNode(L"PONo").text); + if (t.selectSingleNode(L"POItemID"))dw_source.SetItemString(row, L"POItemID", t.selectSingleNode(L"POItemID").text); + if (t.selectSingleNode(L"SOLineID"))dw_source.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GDNLineID"))dw_source.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"GDNID"))dw_source.SetItemString(row, L"GDNID", t.selectSingleNode(L"GDNID").text); + + if (t.selectSingleNode(L"GoodsNo"))dw_source.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"GDNQuantity"))dw_source.SetItemString(row, L"GDNQuantity", t.selectSingleNode(L"GDNQuantity").text); + if (t.selectSingleNode(L"BuyQuantity"))dw_source.SetItemString(row, L"BuyQuantity", t.selectSingleNode(L"BuyQuantity").text); + if (t.selectSingleNode(L"CName"))dw_source.SetItemString(row, L"CName", t.selectSingleNode(L"CName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_source.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"BOMPart"))dw_source.SetItemString(row, L"BOMPart", t.selectSingleNode(L"BOMPart").text); + if (t.selectSingleNode(L"ItemID"))dw_source.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"BuyUnitPrice"))dw_source.SetItemString(row, L"BuyUnitPrice", t.selectSingleNode(L"BuyUnitPrice").text); + if (t.selectSingleNode(L"BuyAmount"))dw_source.SetItemString(row, L"BuyAmount", t.selectSingleNode(L"BuyAmount").text); + if (t.selectSingleNode(L"SupplierID"))dw_source.SetItemString(row, L"SupplierID", t.selectSingleNode(L"POSupplierID").text); + if (t.selectSingleNode(L"SupplierID/@_displaystring"))dw_source.SetItemDisplayString(row, L"SupplierID", t.selectSingleNode(L"SupplierID/@_displaystring").text); + if (t.selectSingleNode(L"HasVATInvoice"))dw_source.SetItemDisplayString(row, L"HasVATInvoice", t.selectSingleNode(L"HasVATInvoice").text); + if (t.selectSingleNode(L"VATRefundRate"))dw_source.SetItemDisplayString(row, L"VATRefundRate", t.selectSingleNode(L"VATRefundRate").text); + if (t.selectSingleNode(L"Amount"))dw_source.SetItemDisplayString(row, L"Amount", t.selectSingleNode(L"Amount").text); + if (t.selectSingleNode(L"POCreatorID"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID").text); + if (t.selectSingleNode(L"POCreatorID/@_displaystring"))dw_source.SetItemDisplayString(row, L"POCreatorID", t.selectSingleNode(L"POCreatorID/@_displaystring").text); + if (t.selectSingleNode(L"Swapthecost"))dw_source.SetItemDisplayString(row, L"Swapthecost", t.selectSingleNode(L"Swapthecost").text); + if (t.selectSingleNode(L"RefundAmount"))dw_source.SetItemDisplayString(row, L"RefundAmount", t.selectSingleNode(L"RefundAmount").text); + //if(t.selectSingleNode(L"HSCode"))dw_source.SetItemDisplayString(row,L"HSCode",t.selectSingleNode(L"HSCode").text); + } + CalcProfit(); + } + return 1; + } + + int OnDeleteSourceingItem() + { + dw_source.DeleteRow(0); + evalPurcharCost(); + evalTotalCost(); + CalcProfit(); + return 1; + } + + int OnAddGDNItems(xstring str) + { + + if (str != L"") + { + trace(str); + xml x; + + x.LoadXml(str); + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + int len = items.length; + int row = 0; + xstring SONos = dw_base.GetItemString(1, L"SONos"); + xstring OrderNos = dw_base.GetItemString(1, L"OrderNos"); + xstring OperationTipss = dw_base.GetItemString(1, L"OperationTips"); + xstring FrontMarkss = dw_base.GetItemString(1, L"Mark"); + + datareading = true; + double costs = 0.0; + double PrivateCommissionAmount = 0.0; + double PrivateCommissionAmountEx = 0.0; + for (int i = 0; i < len; i++) + { + if (i == 0 && dw_item.GetRowCount() > 0 && dw_item.GetItemString(dw_item.GetRowCount(), L"GoodsNo") == L"") + { + row = dw_item.GetRowCount(); + } + else + { + row = dw_item.InsertRow(0); + } + KXMLDOMNode t = items.item(i); + dw_item.SetItemString(row, L"SeqNo", (row * 10).toString()); + dw_item.SetItemString(row, L"GDNID", dw_base.GetGuid(1)); + double cost = t.selectSingleNode(L"Cost").text.toDouble(); + + if (t.selectSingleNode(L"SONo")) + { + xstring SONo = t.selectSingleNode(L"SONo").text; + if (SONos == L"") + { + SONos = SONo; + costs = cost; + } + else if (SONos.find(SONo) < 0) + { + SONos += L",L" + SONo; + costs += cost; + } + } + + if (t.selectSingleNode(L"CustomerPONo")) + { + xstring CustomerPONo = t.selectSingleNode(L"CustomerPONo").text; + if (OrderNos == L"") + OrderNos = CustomerPONo; + else if (OrderNos.find(CustomerPONo) < 0) OrderNos += L",L" + CustomerPONo; + } + + if (t.selectSingleNode(L"OperationTips")) + { + xstring OperationTips = t.selectSingleNode(L"OperationTips").text; + if (OperationTipss == L"") + OperationTipss = OperationTips; + else if (OperationTipss.find(OperationTips) < 0) OperationTipss += L"\r\n" + OperationTips; + } + + if (t.selectSingleNode(L"FrontMarks")) + { + xstring FrontMarks = t.selectSingleNode(L"FrontMarks").text; + if (FrontMarkss == L"") + FrontMarkss = FrontMarks; + else if (FrontMarkss.find(FrontMarks) < 0) FrontMarkss += L"\r\n" + FrontMarks; + } + + //int cost = t.selectSingleNode(L"Cost").text.toDouble(); + //dw_base.SetItemString(1,L"Cost",t.selectSingleNode(L"Cost").text); + if (t.selectSingleNode(L"SalespersonID/@_displaystring"))dw_base.SetItemDisplayString(1, L"SalespersonID", t.selectSingleNode(L"SalespersonID/@_displaystring").text); + if (t.selectSingleNode(L"SalespersonID"))dw_base.SetItemString(1, L"SalespersonID", t.selectSingleNode(L"SalespersonID").text); + if (t.selectSingleNode(L"CustomerID"))dw_base.SetItemString(1, L"CustomerID", t.selectSingleNode(L"CustomerID").text); + if (t.selectSingleNode(L"CustomerID/@_displaystring"))dw_base.SetItemDisplayString(1, L"CustomerID", t.selectSingleNode(L"CustomerID/@_displaystring").text); + + //trace(L"*****************"); + if (t.selectSingleNode(L"LCNo"))dw_base.SetItemString(1, L"LCNo", t.selectSingleNode(L"LCNo").text); + if (t.selectSingleNode(L"LCSignDate"))dw_base.SetItemString(1, L"LCSignDate", t.selectSingleNode(L"LCSignDate").text); + if (t.selectSingleNode(L"LCReceiveDate"))dw_base.SetItemString(1, L"LCReceiveDate", t.selectSingleNode(L"LCReceiveDate").text); + if (t.selectSingleNode(L"DraftPayer"))dw_base.SetItemString(1, L"DraftPayer", t.selectSingleNode(L"DraftPayer").text); + if (t.selectSingleNode(L"NegotiatingBank"))dw_base.SetItemString(1, L"NegotiatingBank", t.selectSingleNode(L"NegotiatingBank").text); + if (t.selectSingleNode(L"DraftTerm"))dw_base.SetItemString(1, L"DraftTerm", t.selectSingleNode(L"DraftTerm").text); + if (t.selectSingleNode(L"CustomerDesc"))dw_base.SetItemString(1, L"CustomerDesc", t.selectSingleNode(L"CustomerDesc").text); + if (t.selectSingleNode(L"LCSigner"))dw_base.SetItemString(1, L"LCSigner", t.selectSingleNode(L"LCSigner").text); + if (t.selectSingleNode(L"Consignee"))dw_base.SetItemString(1, L"Consignee", t.selectSingleNode(L"Consignee").text); + if (t.selectSingleNode(L"NotifyParty"))dw_base.SetItemString(1, L"NotifyParty", t.selectSingleNode(L"NotifyParty").text); + if (t.selectSingleNode(L"Country"))dw_base.SetItemString(1, L"Country", t.selectSingleNode(L"Country").text); + if (t.selectSingleNode(L"CountryName"))dw_base.SetItemDisplayString(1, L"Country", t.selectSingleNode(L"CountryName").text); + if (t.selectSingleNode(L"TradeType"))dw_base.SetItemString(1, L"TradeType", t.selectSingleNode(L"TradeType").text); + if (t.selectSingleNode(L"TradeTypeName"))dw_base.SetItemDisplayString(1, L"TradeType", t.selectSingleNode(L"TradeTypeName").text); + if (t.selectSingleNode(L"TransportMode"))dw_base.SetItemString(1, L"TransportMode", t.selectSingleNode(L"TransportMode").text); + if (t.selectSingleNode(L"TransportModeName"))dw_base.SetItemDisplayString(1, L"TransportMode", t.selectSingleNode(L"TransportModeName").text); + if (t.selectSingleNode(L"POL"))dw_base.SetItemString(1, L"POL", t.selectSingleNode(L"POL").text); + if (t.selectSingleNode(L"PriceTerm"))dw_base.SetItemString(1, L"PriceTerm", t.selectSingleNode(L"PriceTerm").text); + if (t.selectSingleNode(L"PaymentTerm"))dw_base.SetItemString(1, L"PaymentTerm", t.selectSingleNode(L"PaymentTerm").text); + if (t.selectSingleNode(L"PaymentTermMore"))dw_base.SetItemString(1, L"PaymentTermMore", t.selectSingleNode(L"PaymentTermMore").text); + + + if (t.selectSingleNode(L"SOLineID"))dw_item.SetItemString(row, L"SOLineID", t.selectSingleNode(L"SOLineID").text); + if (t.selectSingleNode(L"GoodsNo"))dw_item.SetItemString(row, L"GoodsNo", t.selectSingleNode(L"GoodsNo").text); + if (t.selectSingleNode(L"EName"))dw_item.SetItemString(row, L"EName", t.selectSingleNode(L"EName").text); + if (t.selectSingleNode(L"CustomerItemNo"))dw_item.SetItemString(row, L"CustomerItemNo", t.selectSingleNode(L"CustomerItemNo").text); + if (t.selectSingleNode(L"ItemID"))dw_item.SetItemString(row, L"ItemID", t.selectSingleNode(L"ItemID").text); + if (t.selectSingleNode(L"UnitPrice"))dw_item.SetItemString(row, L"UnitPrice", t.selectSingleNode(L"UnitPrice").text); + if (t.selectSingleNode(L"GDNLineID"))dw_item.SetItemString(row, L"GDNLineID", t.selectSingleNode(L"GDNLineID").text); + + if (t.selectSingleNode(L"SONo"))dw_item.SetItemString(row, L"SONo", t.selectSingleNode(L"SONo").text); + + if (t.selectSingleNode(L"SOLineNo"))dw_item.SetItemString(row, L"SOLineNo", t.selectSingleNode(L"SOLineNo").text); + if (t.selectSingleNode(L"CustomerPONo"))dw_item.SetItemString(row, L"PONo", t.selectSingleNode(L"CustomerPONo").text); + if (t.selectSingleNode(L"GroupNo"))dw_item.SetItemString(row, L"PONo", t.selectSingleNode(L"GroupNo").text); + + if (t.selectSingleNode(L"SKUNo"))dw_item.SetItemString(row, L"SKUNo", t.selectSingleNode(L"SKUNo").text); + if (t.selectSingleNode(L"Packing"))dw_item.SetItemString(row, L"Packing", t.selectSingleNode(L"Packing").text); + if (t.selectSingleNode(L"InnerQty"))dw_item.SetItemString(row, L"InnerQty", t.selectSingleNode(L"InnerQty").text); + if (t.selectSingleNode(L"PackingRate"))dw_item.SetItemString(row, L"PackingRate", t.selectSingleNode(L"PackingRate").text); + if (t.selectSingleNode(L"Brand"))dw_item.SetItemString(row, L"Brand", t.selectSingleNode(L"Brand").text); + if (t.selectSingleNode(L"UOMCode"))dw_item.SetItemString(row, L"UOMCode", t.selectSingleNode(L"UOMCode").text); + if (t.selectSingleNode(L"UOMCode/@_displaystring"))dw_item.SetItemDisplayString(row, L"UOMCode", t.selectSingleNode(L"UOMCode/@_displaystring").text); + + if (t.selectSingleNode(L"KOPCode"))dw_item.SetItemString(row, L"KOPCode", t.selectSingleNode(L"KOPCode").text); + if (t.selectSingleNode(L"KOPCode/@_displaystring"))dw_item.SetItemDisplayString(row, L"KOPCode", t.selectSingleNode(L"KOPCode/@_displaystring").text); + if (t.selectSingleNode(L"PackageL"))dw_item.SetItemString(row, L"PackageL", t.selectSingleNode(L"PackageL").text); + if (t.selectSingleNode(L"PackageW"))dw_item.SetItemString(row, L"PackageW", t.selectSingleNode(L"PackageW").text); + if (t.selectSingleNode(L"PackageH"))dw_item.SetItemString(row, L"PackageH", t.selectSingleNode(L"PackageH").text); + if (t.selectSingleNode(L"GWPerPkg"))dw_item.SetItemString(row, L"GWPerPkg", t.selectSingleNode(L"GWPerPkg").text); + if (t.selectSingleNode(L"NWPerPkg"))dw_item.SetItemString(row, L"NWPerPkg", t.selectSingleNode(L"NWPerPkg").text); + if (t.selectSingleNode(L"ClassifyID"))dw_item.SetItemString(row, L"ClassifyID", t.selectSingleNode(L"ClassifyID").text); + if (t.selectSingleNode(L"ClassifyID/@_displaystring"))dw_item.SetItemDisplayString(row, L"ClassifyID", t.selectSingleNode(L"ClassifyID/@_displaystring").text); + if (t.selectSingleNode(L"Remarks"))dw_item.SetItemString(row, L"Remarks", t.selectSingleNode(L"Remarks").text); + + if (t.selectSingleNode(L"UnitCommPrice"))dw_item.SetItemString(row, L"UnitCommPrice", t.selectSingleNode(L"UnitCommPrice").text); + if (t.selectSingleNode(L"MiddlemanAmount"))dw_item.SetItemString(row, L"MiddlemanAmount", t.selectSingleNode(L"MiddlemanAmount").text); + if (t.selectSingleNode(L"ShipQuantity")) + dw_item.ItemChangeTo(row, L"Quantity", t.selectSingleNode(L"ShipQuantity").text); + else + if (t.selectSingleNode(L"Quantity"))dw_item.ItemChangeTo(row, L"Quantity", t.selectSingleNode(L"Quantity").text); + + double d1 = dw_item.GetItemDouble(row, L"Quantity"); + double d2 = dw_item.GetItemDouble(row, L"UnitPrice"); + double d = d1 * d2; + d = d.round(2); + dw_item.SetItemDouble(row, L"Amount", d); + + double UnitCommPrice = dw_item.GetItemDouble(row, L"UnitCommPrice"); + double MiddlemanAmount = dw_item.GetItemDouble(row, L"MiddlemanAmount"); + double Quantity = dw_item.GetItemDouble(row, L"Quantity"); + double ResearchCommission = UnitCommPrice * Quantity; + double MiddlemanAmountRate = MiddlemanAmount * Quantity; + PrivateCommissionAmount += ResearchCommission; + PrivateCommissionAmountEx += MiddlemanAmountRate; + //if(t.selectSingleNode(L"Amount"))dw_item.SetItemString(row,L"Amount",t.selectSingleNode(L"Amount").text); + + + RefreshSourcingItem(row, false); + + } + + dw_base.SetItemString(1, L"SONos", SONos); + dw_base.SetItemString(1, L"OrderNos", OrderNos); + dw_base.SetItemString(1, L"OperationTips", OperationTipss); + dw_base.SetItemString(1, L"Mark", FrontMarkss); + + double CostEx = dw_base.GetItemDouble(1, L"Cost"); + if (CostEx == 0 || CostEx == L"") + { + if (costs >= 0) { + dw_base.SetItemString(1, L"CostMoreLess", L"1"); + dw_base.SetItemDisplayString(1, L"CostMoreLess", L"PLUS"); + dw_base.SetItemDouble(1, L"Cost", costs); + } + else { + dw_base.SetItemString(1, L"CostMoreLess", L"-1"); + dw_base.SetItemDisplayString(1, L"CostMoreLess", L"LESS"); + dw_base.SetItemDouble(1, L"Cost", costs * -1); + } + } + dw_base.SetItemDouble(1, L"PrivateCommissionAmount", PrivateCommissionAmount + PrivateCommissionAmountEx); + datareading = false; + calcTotal(); + evalTotalCost(); + //RefreshSourcingAllEx(); + CalcProfit(); + } + return 1; + } + + int OnAddGDNItem() + { + //trace(L"12313"); + xaserverarg arg = GDNView::MakeArg(); + arg.AddArg(L"CustomerID", dw_base.GetItemString(1, L"CustomerID")); + arg.AddArg(L"InvoiceNo", dw_base.GetItemString(1, L"InvoiceNo")); + arg.AddArg(L"SONo", dw_base.GetItemString(1, L"")); + int p = arg; + if (dw_base.GetItemString(1, L"CustomerID") == L"") + { + OpenWindow(L"dev:xpage[SelectItem.New.GDN.vx]", cast(arg as int)); + if (dw_base.GetItemString(1, L"CustomerID") == L"") + { + dw_base.SetItemDisplayString(1, L"CustomerID", arg.GetArgString(L"PartyName")); + dw_base.ItemChangeTo(1, L"CustomerID", arg.GetArgString(L"PartyID")); + dw_profit.ItemChangeTo(1, L"CustomerID", arg.GetArgString(L"PartyID")); + dw_profit.SetItemDisplayString(1, L"CustomerID", arg.GetArgString(L"PartyName")); + } + } + else + { + OpenWindow(L"dev:xpage[select.gdnitem.so.vx]", p); + } + + xstring str = arg.GetArgString(L"items"); + trace(L"*****"); + return OnAddGDNItems(str); + } + + int OnCDElementMatch() + { + for (int i = 1; i <= dw_custom.GetRowCount(); i++) + { + xstring ClassifyID = dw_custom.GetItemString(i, L"ClassifyID"); + KXMLDOMElement e1 = dw_custom.GetRowElement(i); + xstring CDLineID = e1.getAttribute(L"guid"); + if (CDLineID == L"") + { + e1.SetAttribute(L"guid", ViewObject::GetGuid()); + CDLineID = e1.getAttribute(L"guid"); + } + + for (int row = 1; row <= dw_cdelement.GetRowCount(); row++) + { + if (ClassifyID == dw_cdelement.GetItemString(row, L"ClassifyID")) + { + dw_cdelement.SetItemString(row, L"CDLineID", CDLineID); + dw_cdelement.SetItemString(row, L"GDNID", dw_base.GetGuid(1)); + dw_cdelement.SetItemString(row, L"HSCode", dw_custom.GetItemString(i, L"HSCode")); + dw_cdelement.Redraw(); + } + } + } + return 1; + } + + int OnCDElement() + { + + while (dw_cdelement.GetRowCount() > 0) { + dw_cdelement.DeleteRow(dw_cdelement.GetRowCount()); + } + + for (int i = 1; i <= dw_custom.GetRowCount(); i++) + { + xstring ClassifyID = dw_custom.GetItemString(i, L"ClassifyID"); + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyelement", L"ClassifyID", ClassifyID); + if (x) + { + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"/GDN/CDElement"); + int lens = items.length; + for (int k = 0; k < lens; k++) + { + int row = dw_cdelement.InsertRow(0); + KXMLDOMElement e = items.item(k); + + KXMLDOMElement e1 = dw_custom.GetRowElement(i); + xstring CDLineID = e1.getAttribute(L"guid"); + if (CDLineID == L"") + { + e1.SetAttribute(L"guid", ViewObject::GetGuid()); + CDLineID = e1.getAttribute(L"guid"); + } + dw_cdelement.SetItemString(row, L"CDLineID", CDLineID); + dw_cdelement.SetItemString(row, L"GDNID", dw_base.GetGuid(1)); + if (e.selectSingleNode(L"HSCode")) dw_cdelement.SetItemString(row, L"HSCode", e.selectSingleNode(L"HSCode").text); + if (e.selectSingleNode(L"SeqNo")) dw_cdelement.SetItemString(row, L"SeqNo", e.selectSingleNode(L"SeqNo").text); + if (e.selectSingleNode(L"EleName")) dw_cdelement.SetItemString(row, L"EleName", e.selectSingleNode(L"EleName").text); + if (e.selectSingleNode(L"EleContent")) dw_cdelement.SetItemString(row, L"EleContent", e.selectSingleNode(L"EleContent").text); + /*if(e.selectSingleNode(L"EleName")) + { + if(e.selectSingleNode(L"EleName").text==L"品牌类型") + { + if(dw_base.GetItemString(1,L"POL")==L"NINGBO") + { + dw_cdelement.SetItemString(row,L"EleContent",L"境内自主品牌"); + }else + { + dw_cdelement.SetItemString(row,L"EleContent",L"无品牌"); + } + } + else if(e.selectSingleNode(L"EleName").text==L"出口享惠情况") + { + xstring country = dw_base.GetItemString(1,L"FinalCountry"); + if(country==L"") + { + dw_cdelement.SetItemString(row,L"EleContent",L"不享受"); + } + else if(L"601,127,322,129,415,337,133,107,119,122,103,434,106,331,134,136,105,132,609,111,112,141,412,143".find(country)>=0) + { + dw_cdelement.SetItemString(row,L"EleContent",L"享受"); + }else + { + dw_cdelement.SetItemString(row,L"EleContent",L"不享受"); + } + } + }*/ + if (e.selectSingleNode(L"CustomName")) dw_cdelement.SetItemString(row, L"CustomName", e.selectSingleNode(L"CustomName").text); + if (e.selectSingleNode(L"ClassifyID")) dw_cdelement.SetItemString(row, L"ClassifyID", e.selectSingleNode(L"ClassifyID").text); + } + } + } + + return 1; + } + + int OnDeleteGDNItem() + { + if (dw_item.GetRow() < 1) return 1; + ClearSourcingItem(dw_item.GetRow()); + dw_item.DeleteRow(0); + calcTotal(); + evalTotalCost(); + CalcProfit(); + + xstring PONo_s = L""; + xstring SONo_s = L""; + for (int k = 1; k <= dw_item.GetRowCount(); k++) + { + xstring SONo = dw_item.GetItemString(k, L"SONo"); + if (SONo_s == L"") + { + SONo_s = SONo; + } + else if (SONo_s.find(SONo) < 0) + { + SONo_s += L",L" + SONo; + } + xstring PONo = dw_item.GetItemString(k, L"PONo"); + if (PONo_s == L"") + { + PONo_s = PONo; + } + else if (PONo_s.find(PONo) < 0) + { + PONo_s += L",L" + PONo; + } + } + dw_base.SetItemString(1, L"OrderNos", PONo_s); + dw_base.SetItemString(1, L"SONos", SONo_s); + return 1; + } + + //命令发布函数 + int OnCmdDispatch(xstring comdid) + { + if (comdid.find(L"bill.update") > 0) + { + return OnSave(); + } + if (comdid == L"xmCDElementMatch") + { + return OnCDElementMatch(); + } + if (comdid == L"xmSaveAs") + { + int i = dw_item.SaveAs(L""); + if (i == 1) + alert(L"导出成功"); + return 1; + } + if (comdid == L"xmSearch") + { + xaserverarg arg1 = new xaserverarg; + arg1.setNativePointer(arg1.CreateInstance()); + arg1.AddArg(L"text", searchStr); + + if (tabname == L"sourcing") + { + OpenWindow(L"dev:xpage[search.dialog.vx]", cast(arg1 as int)); + xstring str = arg1.GetArgString(L"text"); + searchStr = str; + dw_source.Filter(L"*", searchStr); + return 1; + } + else if (tabname == L"goods") + { + OpenWindow(L"dev:xpage[search.dialog.vx]", cast(arg1 as int)); + str = arg1.GetArgString(L"text"); + searchStr = str; + dw_item.Filter(L"*", searchStr); + return 1; + } + return 1; + } + if (comdid == L"action:bill.SourceRemark") return OnSourceRemark(); + if (comdid == L"action:bill.GDNDelay") + { + xstring EntityIDEx = dw_base.GetGuid(1); + xaserverarg argEx = new xaserverarg; + argEx.setNativePointer(argEx.CreateInstance()); + trace(EntityIDEx); + argEx.AddArg(L"GDNID", EntityIDEx); + OpenWindow(L"dev:xpage[GDNDelay.vx]", cast(argEx as int)); + return 1; + } + if (comdid == L"action:bill.Volume") + { + calcTotal(); + return 1; + } + if (comdid.find(L"bill.print") > 0) + { + xstring EntityID1 = dw_base.GetGuid(1); + xml x1 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudge", L"GDNID", EntityID1); + xstring Results1 = x1.GetXmlDoc().text; + if (Results1 != L"") + { + alert(Results1); + return 0; + } + + OnPrintOne(); + OnPrint(); + return 1; + } + if (comdid == L"action:bill.check.ask") + { + xstring ApprovalStatus = dw_base.GetItemString(1, L"ApprovalStatus"); + if (ApprovalStatus == L"9") + { + alert(L"合并票不允许提交审批!"); + return 0; + } + if (dw_cdelement.GetRowCount() < 1) + { + alert(L"请生成报关要素!"); + return 0; + } + if (dw_source.GetRowCount() < 1) + { + alert(L"采购货源未生成!"); + return 0; + } + + xstring EntityID = dw_base.GetGuid(1); + xml xx = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudge", L"GDNID", EntityID); + xstring Results = xx.GetXmlDoc().text; + if (Results != L"") + { + alert(Results); + return 0; + } + + xml xx1 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeEx", L"GDNID", EntityID); + xstring Results2 = xx1.GetXmlDoc().text; + if (Results2 != L"") + { + alert(Results2); + return 0; + } + + xml xx3 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeExS", L"GDNID", EntityID); + xstring Results3 = xx3.GetXmlDoc().text; + if (Results3 != L"") + { + alert(Results3); + return 0; + } + + xml xx4 = ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNJudgeAmount", L"GDNID", EntityID); + xstring Results4 = xx4.GetXmlDoc().text; + if (Results4 != L"") + { + alert(Results4); + return 0; + } + + /* xml xx5= ViewObject::RetrieveData(L"/sale/data/GDN/GetGDNCost",L"GDNID",EntityID); + xstring Results5=xx5.GetXmlDoc().text; + if(Results5 !=L"") + { + alert(Results5); + return 0; + }*/ + + xaserverarg arg7 = new xaserverarg; + arg7.setNativePointer(arg7.CreateInstance()); + trace(EntityID); + arg7.AddArg(L"GDNID", EntityID); + OpenWindow(L"dev:xpage[GDNDelay.vx]", cast(arg7 as int)); + + } + if (comdid.find(L"action:", 0) >= 0) + { + int ret = ProcessFlowAction(comdid, 1); + } + if (comdid == L"xmRefreshSourcingAll") + { + if (dw_base.GetItemString(1, L"InvoiceNo") == L"") + { + alert(L"请先保存,在刷新货源!"); + return 1; + } + return RefreshSourcingAllEx(); + } + if (comdid == L"xmMakeGdnLineEx") + { + return OnMakeGdnLineEx(); + } + if (comdid == L"xmRefreshSourcingItem") + { + if (dw_base.GetItemString(1, L"InvoiceNo") == L"") + { + alert(L"请先保存,在刷新货源!"); + return 1; + } + return RefreshSourcingItem1(dw_item.GetRow()); + } + + if (comdid == L"xmMakeContainer") + { + return OnMakeContainer(); + } + else if (comdid == L"xmCDElement") + { + return OnCDElement(); + } + else if (comdid == L"tab_goods") + { + tabname = L"goods"; + SetAgentEx(); + return 1; + } + else if (comdid == L"tab_sourcing") + { + tabname = L"sourcing"; + SetAgentEx(); + return 1; + } + else if (comdid == L"tab_profit") + { + tabname = L"profit"; + SetAgentEx(); + return 1; + } + else if (comdid == L"tab_cdelement") + { + tabname = L"cdelement"; + SetAgentEx(); + return 1; + } + else if (comdid == L"tab_base") + { + tabname = L"base"; + SetAgentEx(); + return 1; + } + else if (comdid == L"makeCustom") + { + OnMakeSumPack(); + return OnMakeCustom(); + } + else if (comdid == L"xmDeleteRow") + { + dw_item.DeleteRow(0); + return 1; + } + else if (comdid == L"xmAddItem") + { + //dw_item.InsertRow(0); + PoTotal();//新增时没有作用 + return OnAddGDNItem(); + } + else if (comdid == L"xmDeleteItem") + { + //dw_item.DeleteRow(0); + return OnDeleteGDNItem(); + } + else if (comdid == L"xmAddSourcingItem") + { + return OnAddSourcingItem(); + } + if (comdid == L"xmDeleteSourcingItem") + { + return OnDeleteSourceingItem(); + } + else if (comdid == L"xmSave") + { + OnSave(); + return 1; + } + else if (comdid == L"xmPrint") + { + OnPrint(); + return 1; + } + else if (comdid == L"xmClose") + { + //CloseWindow(); + return 1; + } + else if (comdid == L"xmCalcProfit") + { + CalcProfit(); + return 1; + } + else if (comdid == L"xmGDNSourcePaperCard") + { + if (dw_base.GetItemString(1, L"InvoiceNo") != L"") + { + xaserverarg arg2 = new xaserverarg; + arg2.setNativePointer(arg2.CreateInstance()); + arg2.AddArg(L"InvoiceNo", dw_base.GetItemString(1, L"InvoiceNo")); + arg2.AddArg(L"HWND", GetHWND().toString()); + OpenWindow(L"dev:xpage[GDNSourcePaperCard.vx]", cast(arg2 as int)); + } + else + { + alert(L"请先保存出运信息,在修改纸卡开票!"); + } + return 1; + } + else if (comdid == L"xmRefreshSource") + { + xstring invno = dw_base.GetItemString(1, L"InvoiceNo"); + OnRefreshSource(invno); + return 1; + } + else if (comdid == L"xmMaintBuyPrice") + { + xaserverarg arg = GDNView::MakeArg(); + int row = dw_source.GetRow(); + if (row < 1) return 1; + arg.AddArg(L"SupplierID", dw_source.GetItemString(row, L"SupplierID")); + arg.AddArg(L"SupplierName", dw_source.GetItemDisplayString(row, L"SupplierID")); + arg.AddArg(L"Price", dw_source.GetItemString(row, L"BuyUnitPrice")); + OpenWindow(L"dev:xpage[GDNSourcePriceMaint.vx]", cast(arg as int)); + if (arg.GetArgString(L"result") == L"ok") + { + if (arg.GetArgString(L"SupplierID") != L"") + { + dw_source.SetItemString(row, L"SupplierID", arg.GetArgString(L"SupplierID")); + dw_source.SetItemDisplayString(row, L"SupplierID", arg.GetArgString(L"SupplierName")); + } + if (arg.GetArgString(L"Price") != L"" && arg.GetArgString(L"Price") != L"0.00") + dw_source.ItemChangeTo(row, L"BuyUnitPrice", arg.GetArgString(L"Price")); + dw_source.Redraw(); + } + } + return 0; + } + + int OnSourceRemark() + { + xstring name = L"出运明细单"; + xml x = ViewObject::RetrieveData(L"/sale/data/TradeFinance3/GetSetUpRemarks", L"Type", name); + KXMLDOMNodeList items = x.GetXmlDoc().selectNodes(L"data/Item"); + KXMLDOMNode t = items.item(0); + xstring Content = L""; + if (t.selectSingleNode(L"Content")) + { + Content = t.selectSingleNode(L"Content").text; + } + xaserverarg arg1 = new xaserverarg; + arg1.setNativePointer(arg1.CreateInstance()); + arg1.AddArg(L"value", Content); + OpenWindow(L"dev:xpage[memo.edit.new.vx]", arg1.getNativePointer()); + + return 1; + } + + int OnPrintOne() + { + xstring GDNID = dw_base.GetGuid(1); + xml x = ViewObject::RetrieveData(L"/sale/data/GDN/CheckGW", L"GDNID", GDNID); + xstring r = x.GetXmlDoc().text; + int r1 = r.toInt(); + if (x) + { + if (r1 > 0) + { + alert(L"毛重总量或净总重量不一致,需要核对!"); + } + } + + + xml xs = ViewObject::RetrieveData(L"/sale/data/GDN/CheckCDLine", L"GDNID", GDNID); + xstring rs = xs.GetXmlDoc().text; + int rs1 = rs.toInt(); + if (xs) + { + if (rs1 > 0) + { + alert(L"报关数量和报关金额与出运数量和金额不一致\r\n部分报关数量和金额需要核对!"); + } + } + + //alert(GDNID); + return 1; + } + //命令处理事件 + int OnXCommand(ref TXCommandEvent evt, int param) + { + return OnCmdDispatch(evt.pStrID); + } + + //风险计提 + int evalRisk() + { + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + double amt = dw_profit.GetItemDouble(1, L"Amount"); + xstring exchRate = L""; + xstring exchRate2 = L""; + + xml x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"prepareFeeRate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + double rate = exchRate.toDouble(); + + xml x1 = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"cryrate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchRate2 = x1.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + double cryrate = exchRate2.toDouble(); + + if (CurrencyCode == L"RMB" || CurrencyCode == L"CNY") + { + if (exchRate != L"") + { + amt = amt / cryrate; + + } + } + + dw_profit.SetItemDouble(1, L"RiskPrepareFee", amt * rate); + return 1; + } + + //采购成本 + + + int evalPurcharCost() + { + double cost = dw_source.GetItemSumDouble(L"BuyAmount"); + dw_profit.SetItemDouble(1, L"Cost", cost); + return 1; + } + + //退税 + int evalDrawback() + { + //calc Drawback + double retax = 0; + double tax = 0; + double cost = 0; + double Drawback = 0; + for (int k = 1; k <= dw_item.GetRowCount(); k++) + { + KXMLDOMElement e = dw_item.GetRowElement(k); + xstring gdnLineID = e.getAttribute(L"guid"); + xstring ClassifyID = dw_item.GetItemString(k, L"ClassifyID"); + retax = 16; + tax = 16; + + if (ClassifyID != L"") + { + //trace(L"\r\n" + ClassifyID); + xml x = ViewObject::RetrieveData(L"/sale/data/Custom3/custom/classifyinfo", L"ClassifyID", ClassifyID); + if (x) + { + // trace(L"\r\n" + x.GetXml()); + KXMLDOMNode o = x.GetXmlDoc().selectSingleNode(L"data/Item"); + if (o) + { + KXMLDOMNode n = o.selectSingleNode(L"VATRates"); + if (n) + { + tax = n.text.toDouble(); + n.Release(); + } + n = o.selectSingleNode(L"VATRefundRate"); + if (n) + { + retax = n.text.toDouble(); + n.Release(); + } + o.Release(); + } + x.GetXmlDoc().Release(); + } + } + + cost = 0; + for (int m = 1; m <= dw_source.GetRowCount(); m++) + { + if (dw_source.GetItemString(m, L"GDNLineID") == gdnLineID) + cost += dw_source.GetItemDouble(m, L"BuyAmount"); + } + Drawback += cost / (100.0 + tax) * retax; + } + dw_profit.SetItemDouble(1, L"Drawback", Drawback); + return 1; + } + + int evalDrawbackEx() + { + double Drawback = 0.0; + for (int m = 1; m <= dw_source.GetRowCount(); m++) + { + double RefundAmount = dw_source.GetItemDouble(m, L"RefundAmount"); + Drawback += RefundAmount; + } + dw_profit.SetItemDouble(1, L"Drawback", Drawback); + return 1; + } + + int evalManagementFee() + { + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + xstring expRate = L""; + xstring exchRate = L""; + + xml x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"cryrate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + + x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"mgtFeeRate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + expRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + //double sale = dw_profit.GetItemDouble(1,L"ExchangeAmountEx"); + + xstring ETDEx = dw_base.GetItemString(1, L"ETD"); + if (ETDEx >= L"2023-01-01") + { + expRate = L"0.2"; + } + + double sale = dw_profit.GetItemDouble(1, L"Amount"); + double ManagementFee = 0; + if (CurrencyCode == L"RMB" || CurrencyCode == L"CNY") + { + if (exchRate != L"") + { + double r1 = exchRate.toDouble();//汇率 + + double r2 = expRate.toDouble(); //公司管理 + + ManagementFee = (sale / r1) * r2; + } + } + else + { + double rate = expRate.toDouble(); + ManagementFee = sale * rate; + } + trace(ManagementFee.toString()); + dw_profit.SetItemDouble(1, L"ManagementFee", ManagementFee); + return 1; + } + + //风险基金 + int evalRiskFundAmount() + { + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + xstring expRate = L""; + xstring exchRate = L""; + + xml x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"cryrate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + + x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"RiskFundAmount"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + expRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + //double sale = dw_profit.GetItemDouble(1,L"ExchangeAmountEx"); + + xstring ETDEx = dw_base.GetItemString(1, L"ETD"); + if (ETDEx < "2023-01-01") + { + //alert(L"1"); + expRate = L"0.0"; + } + + double sale = dw_profit.GetItemDouble(1, L"Amount"); + double RiskFundAmount = 0; + if (CurrencyCode == L"RMB" || CurrencyCode == L"CNY") + { + if (exchRate != L"") + { + double r1 = exchRate.toDouble();//汇率 + + double r2 = expRate.toDouble(); + + RiskFundAmount = (sale / r1) * r2; + } + } + else + { + double rate = expRate.toDouble(); + RiskFundAmount = sale * rate; + } + //alert(L"+++L"+ETDEx+L"+++L"+rate.toString()+L"+++L"+sale.toString()+L"+++L"+RiskFundAmount.toString()+L"+++L"); + dw_profit.SetItemDouble(1, L"RiskFundAmount", RiskFundAmount); + return 1; + } + + //总成本 + int evalTotalCost() + { + double ttl = 0; + ttl = dw_profit.GetItemDouble(1, L"Cost"); + + ttl -= dw_profit.GetItemDouble(1, L"Drawback"); + ttl += dw_profit.GetItemDouble(1, L"DrawbackIntrest"); + ttl += dw_profit.GetItemDouble(1, L"CustomFee"); + ttl += dw_profit.GetItemDouble(1, L"InspectionFee"); + ttl += dw_profit.GetItemDouble(1, L"PaperCardCopyFee"); + ttl += dw_profit.GetItemDouble(1, L"TransportationFee"); + ttl += dw_profit.GetItemDouble(1, L"StorageFee"); + ttl += dw_profit.GetItemDouble(1, L"PortIncidentalFee"); + ttl += dw_profit.GetItemDouble(1, L"RiskPrepareFee"); + ttl += dw_profit.GetItemDouble(1, L"AllocatedFee"); + ttl += dw_profit.GetItemDouble(1, L"ManagementFee"); + ttl += dw_profit.GetItemDouble(1, L"RiskFundAmount"); + ttl += dw_profit.GetItemDouble(1, L"FundsIntrestFee"); + ttl -= dw_profit.GetItemDouble(1, L"AgentAmount"); + ttl += dw_profit.GetItemDouble(1, L"AgentTax"); + ttl += dw_profit.GetItemDouble(1, L"OtherFee"); + + dw_profit.SetItemDouble(1, L"TotalCostEx", ttl); + + return 1; + } + + //销售 + int evalSale() + { + dw_profit.SetItemString(1, L"Quantity", dw_base.GetItemString(1, L"Quantity")); + dw_profit.SetItemString(1, L"Amount", dw_base.GetItemString(1, L"Amount")); + dw_profit.SetItemString(1, L"Freight", dw_base.GetItemString(1, L"Freight")); + dw_profit.SetItemString(1, L"InsuranceAmount", dw_base.GetItemString(1, L"InsuranceAmount")); + //dw_profit.SetItemString(1,L"CommissionAmount",dw_base.GetItemString(1,L"CommissionAmount")); + + double comm1 = dw_base.GetItemDouble(1, L"CommissionAmount"); + double comm2 = dw_base.GetItemDouble(1, L"PrivateCommissionAmount"); + double comm3 = dw_base.GetItemDouble(1, L"DiscountAmount"); + double comm = comm1 + comm2 + comm3; + dw_profit.SetItemDouble(1, L"CommissionAmount", comm); + + xstring cost = dw_base.GetItemString(1, L"Cost"); + if (cost != L"") + { + xstring lessa = dw_base.GetItemString(1, L"CostMoreLess"); + double costAmt = cost.toDouble(); + if (lessa == L"-1") costAmt = 0.0 - costAmt; + dw_profit.SetItemDouble(1, L"SaleExternCost", costAmt); + } + else + dw_profit.SetItemDouble(1, L"SaleExternCost", 0.0); + + + double ttl = 0; + ttl = dw_base.GetItemDouble(1, L"Amount"); + ttl -= dw_base.GetItemDouble(1, L"Freight"); + ttl -= dw_base.GetItemDouble(1, L"InsuranceAmount"); + ttl -= dw_base.GetItemDouble(1, L"CommissionAmount"); + ttl -= dw_base.GetItemDouble(1, L"PrivateCommissionAmount"); + ttl -= dw_base.GetItemDouble(1, L"DiscountAmount"); + ttl += dw_profit.GetItemDouble(1, L"SaleExternCost"); + + + xstring CurrencyCode = dw_base.GetItemString(1, L"CurrencyCode"); + xstring exchangeRate = L""; + exchangeRate = dw_profit.GetItemString(1, L"ExchangeRate"); + if (exchangeRate == L"") { + xml x = ViewObject::RetrieveData(L"/sale/data/GDN3/profit/param", L"item", L"cryrate"); + if (x.GetXmlDoc().selectSingleNode(L"root/item/@value")) + exchangeRate = x.GetXmlDoc().selectSingleNode(L"root/item/@value").text; + dw_profit.SetItemString(1, L"ExchangeRate", exchangeRate); + } + if (exchangeRate != L"" || CurrencyCode == L"USD") { + //dw_profit.SetItemString(1,L"ExchangeRate",exchangeRate); + dw_profit.SetItemDouble(1, L"ExchangeAmountEx", ttl); + } + + if (CurrencyCode == L"RMB" || CurrencyCode == L"CNY") + { + //exchangeRate=L"6.6"; + dw_profit.SetItemDouble(1, L"ExchangeAmountEx", ttl / exchangeRate.toDouble()); + } + + return 1; + } + + int evalProfitAmount() + { + + double sale = dw_profit.GetItemDouble(1, L"ExchangeAmountEx"); + double exchRate = dw_profit.GetItemDouble(1, L"ExchangeRate"); + double ttl = dw_profit.GetItemDouble(1, L"TotalCostEx"); + double drawback = dw_profit.GetItemDouble(1, L"Drawback"); + if (exchRate != 0) + { + dw_profit.SetItemDouble(1, L"ProfitAmountEx", sale * exchRate - ttl); + dw_base.SetItemDouble(1, L"ProfitAmountEx", sale * exchRate - ttl); + } + else + { + dw_profit.SetItemString(1, L"ProfitAmountEx", L""); + dw_base.SetItemString(1, L"ProfitAmountEx", L""); + } + if (sale != 0.0) + { + double amt1 = ttl; + amt1 = amt1 / sale; + dw_profit.SetItemDouble(1, L"ExchangeCostEx", amt1); + } + else + dw_profit.SetItemString(1, L"ExchangeCostEx", L""); + + return 1; + } + + int evalProfitAmountEx() + { + double amount = dw_profit.GetItemDouble(1, L"Amount"); + double cost = dw_profit.GetItemDouble(1, L"Cost"); + + double sale = dw_profit.GetItemDouble(1, L"ExchangeAmountEx"); + double exchRate = dw_profit.GetItemDouble(1, L"ExchangeRate"); + double ttl = dw_profit.GetItemDouble(1, L"TotalCostEx"); + double drawback = dw_profit.GetItemDouble(1, L"Drawback"); + if (exchRate != 0) + { + dw_profit.SetItemDouble(1, L"ProfitAmountEx", sale * exchRate - ttl); + dw_base.SetItemDouble(1, L"ProfitAmountEx", sale * exchRate - ttl); + } + else + { + dw_profit.SetItemString(1, L"ProfitAmountEx", L""); + dw_base.SetItemString(1, L"ProfitAmountEx", L""); + } + if (amount != 0.0) + { + double amt1 = cost; + amt1 = amt1 / amount; + + dw_profit.SetItemDouble(1, L"ExchangeCostEx", amt1); + for (int m = 1; m <= dw_source.GetRowCount(); m++) + { + //dw_source.SetItemDouble(m,L"Swapthecost",amt1); + } + } + else + dw_profit.SetItemString(1, L"ExchangeCostEx", L""); + dw_source.Redraw(); + return 1; + } + + int CalcProfit() + { + evalSale(); + evalManagementFee(); + evalRiskFundAmount(); + evalRisk(); + evalPurcharCost(); + evalDrawbackEx(); + evalTotalCost(); + evalProfitAmountEx(); + } + + int OnItemAskStyle(ref TNotifyEvent evt, int p) + { + int DMS_CSSSTYLE = 0x8; + ref DWASKSTYLENMHDR hdr = trust(evt.pnmh as ref DWASKSTYLENMHDR); + int row = hdr.row; + int col = hdr.col; + xstring colname = hdr.colname; + + int rows = dw_item.GetRowCount(); + if (row < 1 || row > rows) + { + return 1; + } + + if (colname == L"Packages") + { + int PackingRate = dw_item.GetItemString(row, L"PackingRate").toInt(); + int Quantity = dw_item.GetItemString(row, L"Quantity").toInt(); + if (PackingRate != 0) + { + if ((Quantity / PackingRate) * PackingRate != Quantity) + { + hdr.mask = DMS_CSSSTYLE; + hdr.cssstyle = L"color:#ff0000"; + } + } + } + return 1; + } + + int OnAttachEvent() + { + //绑定工具条点击事件 + AttachEvent(L"WM_XCOMMAND", OnXCommand); + //获取焦点事件,用于重置工具条 + AttachEvent(L"WM_SETFOCUS", OnSetFocus); + + AttachEvent(L"dw_item", L"DWV_ITEMCHANGED", OnItemChanged); + AttachEvent(L"dw_source", L"DWV_ITEMCHANGED", OnItemChangedEx); + AttachEvent(L"dw_base", L"DWV_ASKDATA", OnAskDataBase); + + AttachEvent(L"dw_base", L"DWV_ITEMCHANGED", OnBaseItemChanged); + + AttachEvent(L"dw_profit", L"DWV_ITEMCHANGED", OnProfitItemChanged); + AttachEvent(L"dw_custom", L"DWV_ITEMCHANGED", OnCustomItemChanged); + AttachEvent(L"dw_billnote", L"DWV_DOUBLECLICKED", OnBillNoteDoubleClicked);//行双击 + AttachEvent(L"dw_item", L"DWV_ASKSTYLE", OnItemAskStyle); + + AttachCloseWindow(); + + } + + int RetrieveUseBuffer(xstring invno) + { + + xml x; + x = new xml; + + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + arg.AddArg(L"EntityID", GetEntityID(1)); + arg.AddArg(L"invno", invno); + + //int t0 = win32::GetTickCount(); + //if(url::get(L"/sale/data/Gdn/data/buffer", arg.GetString(),x)!=1) + if (url::get(L"/sale/data/Gdn/data", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + + //trace(x.GetXml()); + //trace(L"\r\n出运数据读取:"+(win32::GetTickCount() - t0).toString()); + + KXMLDOMElement ele; + KXMLDOMNode node; + KXMLDOMDocument xdoc = x.GetXmlDoc(); + node = xdoc.selectSingleNode(L"data/Item[@subject='Base' or @subject='base']/*"); + + dw_base.DwRetrieve(GetServerUrl(), L"[gdnbase.gdn.sql.xq]", L"EntityID", InvoiceID); + + if (node) + { + ele = node; + //node.release(); + //dw_base.Retrieve(ele); + //ele.release(); + + dw_billnote.Retrieve(ele); + if (dw_billnote.GetRowCount() < 1) + { + xml x0; + x0 = new xml; + x0.setNativePointer(xml::CreateInstance()); + xstring billnote = L"<GDN><DocInfo><data><Item Name='报关发票' Field='Remark'></Item>" + + "<Item Name='报关箱单' Field='Remark'></Item>" + + "<Item Name='议付发票' Field='Remark'></Item>" + + "<Item Name='议付箱单' Field='Remark'></Item>" + + "<Item Name='装船通知' Field='Remark'></Item>" + + "<Item Name='加拿大海关发票' Field='Remark'></Item>" + + "<Item Name='FORMA' Field='Remark'></Item></data></DocInfo></GDN>"; + x0.LoadXml(billnote); + dw_billnote.Retrieve(x0); + } + } + /*node = xdoc.selectSingleNode(L"data/Item[@subject='GDNProfit' or @subject='profit']/*"); + if(node) + { + ele = node; + //node.release(); + dw_profit.Retrieve(ele); + // ele.release(); + }*/ + dw_profit.DwRetrieve(GetServerUrl(), L"[profit.dgn.sql.xq]", L"EntityID", InvoiceID); + dw_item.DwRetrieve(GetServerUrl(), L"[gdnline.gdn.sql.xq]", L"EntityID", InvoiceID); + dw_item.SetSelectionMode(1); + if (dw_item.GetRowCount() < 1) + { + xml x2 = xml::Make(); + x2.LoadXml(L"<GDN/>"); + dw_item.Retrieve(x2); + x2.Free(); + } + + /* + node = xdoc.selectSingleNode(L"data/Item[@subject='GDNLine' or @subject='gdnline']/*"); + if(node) + { + ele = node; + //node.release(); + dw_item.Retrieve(ele); + ele.release(); + }*/ + + node = xdoc.selectSingleNode(L"data/Item[@subject='GDNLineEx' or @subject='gdnlineex']/*"); + if (node) + { + ele = node; + //node.release(); + dw_invoiceItem.Retrieve(ele); + ele.release(); + } + //alert(L"123"+InvoiceID); + //dw_source.DwRetrieve(GetServerUrl(),L"[source.gdn.sql.xq]", L"EntityID", InvoiceID); + //dw_source.SetSelectionMode(1); + + node = xdoc.selectSingleNode(L"data/Item[@subject='GDNSource' or @subject='source']/*"); + if (node) + { + ele = node; + //node.release(); + dw_source.Retrieve(ele); + ele.release(); + } + dw_custom.DwRetrieve(GetServerUrl(), L"[cdline.gdn.sql.xq]", L"EntityID", InvoiceID); + dw_custom.SetSelectionMode(1); + /* + node = xdoc.selectSingleNode(L"data/Item[@subject='CDLine' or @subject='cdline']/*"); + if(node) + { + ele = node; + //node.release(); + dw_custom.Retrieve(ele); + ele.release(); + } + */ + node = xdoc.selectSingleNode(L"data/Item[@subject='CDElement' or @subject='cdelement']/*"); + if (node) + { + ele = node; + //node.release(); + dw_cdelement.Retrieve(ele); + dw_cdelement.SetSelectionMode(1); + ele.release(); + } + + node = xdoc.selectSingleNode(L"data/Item[@subject='Container' or @subject='container']/*"); + if (node) + { + ele = node; + //node.release(); + dw_fcl.Retrieve(ele); + ele.release(); + } + + return 1; + } + + int OnRefreshSource(xstring invno) + { + xml x; + x = new xml; + + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + + arg.AddArg(L"invno", invno); + if (url::get(L"/sale/data/Gdn/source/maintex", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + + dw_source.Retrieve(x); + dw_source.SetSelectionMode(1); + return 1; + } + int Retrieve(xstring invno) + { + + //return RetrieveUseBuffer(invno); + + xml x; + x = new xml; + + xaserverarg arg = new xaserverarg; + arg.setNativePointer(arg.CreateInstance()); + + arg.AddArg(L"invno", invno); + if (url::get(L"/sale/data/Gdn/source/maintex", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + + dw_source.Retrieve(x); + dw_source.SetSelectionMode(1); + if (url::get(L"/sale/data/Gdn/source/base", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + + dw_base.Retrieve(x); + + dw_billnote.Retrieve(x); + if (dw_billnote.GetRowCount() < 1) + { + xstring billnote = L"<GDN><DocInfo><data><Item Name='报关发票' Field='Remark'></Item>" + + "<Item Name='报关箱单' Field='Remark'></Item>" + + "<Item Name='议付发票' Field='Remark'></Item>" + + "<Item Name='议付箱单' Field='Remark'></Item>" + + "<Item Name='装船通知' Field='Remark'></Item>" + + "<Item Name='加拿大海关发票' Field='Remark'></Item>" + + "<Item Name='FORMA' Field='Remark'></Item></data></DocInfo></GDN>"; + x.LoadXml(billnote); + dw_billnote.Retrieve(x); + } + if (url::get(L"/sale/data/Gdn/source/gdnline", arg.GetString(), x) != 1) + { + alert(x.GetXml); + return -1; + } + dw_item.Retrieve(x); + dw_item.SetSelectionMode(1); + + if (url::get(L"/sale/data/Gdn/source/gdnlineex", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + dw_invoiceItem.Retrieve(x); + + + if (url::get(L"/sale/data/Gdn/source/profit", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + dw_profit.Retrieve(x); + + if (url::get(L"/sale/data/Custom3/maint/custom/data", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + dw_custom.Retrieve(x); + dw_customex.Retrieve(x); + dw_custom.SetSelectionMode(1); + + if (url::get(L"/sale/data/Gdn/source/cdelement", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + dw_cdelement.Retrieve(x); + dw_cdelement.SetSelectionMode(1); + //dw_cdelement.Retrieve(x); + + if (url::get(L"/sale/data/Gdn/source/container", arg.GetString(), x) != 1) + { + alert(x.GetXmlDoc().text); + return -1; + } + dw_fcl.Retrieve(x); + dw_fcl.SetSelectionMode(1); + return 1; + } + + //件数 + int caclPacking(double dQty, xstring sPRate) + { + if (sPRate == L"" || sPRate == L"0" || sPRate == L" ") + return 0; + double dPackages; + int iFlag; + iFlag = sPRate.find(L"/", 1); + if (iFlag >= 0) + { + xstring sBegin = sPRate.mid(0, iFlag); + xstring sEnd = sPRate.mid(iFlag + 1, sPRate.length() - iFlag + 2); + if (!sBegin || sBegin == L"" || sBegin == L"0" || !sEnd || sEnd == L"" || sEnd == L"0") + return 0; + dPackages = dQty * sEnd.toDouble() / sBegin.toDouble(); + } + else + { + dPackages = dQty / sPRate.toDouble(); + } + + if ((dPackages * 1000).toInt() > dPackages.toInt() * 1000) + dPackages = dPackages + 1; + + return dPackages.toInt(); + } + + xstring GetInvoiceID(xstring InvoiceNo) + { + xml x = xml::Make(); + xaserverarg arg = xaserverarg::Make(); + arg.AddArg(L"InvoiceNo", InvoiceNo); + xaserver::ExecXQuery(GetServerUrl(), L"[gdnid.gdn.xq]", arg.GetString(), x); + xstring InvoiceID1 = L""; + if (x.GetXmlDoc()) + { + InvoiceID1 = x.GetXmlDoc().text; + } + arg.Free(); + x.Free(); + return InvoiceID1; + } + + int OnNewInital() + { + xstring sdate = publiccode::GetCurrentDate(); + dw_base.SetItemString(1, L"InvoiceDate", sdate); + xstring suserid = publiccode::GetUser().id; + xstring susername = publiccode::GetUser().name; + //dw_base.SetItemString(1,L"SalespersonID",suserid); + //dw_base.SetItemDisplayString(1,L"SalespersonID",susername); + dw_base.SetItemString(1, L"CompanyID", L"E9E3C542-062C-4957-B8F4-9B92C3E351FC"); + dw_base.SetItemDisplayString(1, L"CompanyID", L"宁波家尔佳进出口有限公司"); + dw_base.SetItemString(1, L"CreatorID", suserid); + dw_base.SetItemDisplayString(1, L"CreatorID", susername); + dw_base.SetItemString(1, L"CreateDate", sdate); + dw_base.SetItemString(1, L"TradeMode", L"Z"); + dw_base.SetItemDisplayString(1, L"TradeMode", L"自营"); + + dw_base.SetItemString(1, L"CurrencyCode", L"USD"); + dw_profit.SetItemString(1, L"CurrencyCode", L"USD"); + dw_profit.SetItemString(1, L"InvoiceDate", sdate); + //dw_base.SetItemString(1,L"SalespersonID",suserid); + //dw_base.SetItemDisplayString(1,L"SalespersonID",susername); + //dw_profit.SetItemString(1,L"SalespersonID",suserid); + //dw_profit.SetItemDisplayString(1,L"SalespersonID",susername); + xstring id = publiccode::GetGuid(); + dw_base.SetGuid(1, id); + dw_profit.SetGuid(1, id); + + xml x = ViewObject::MakeXml(); + xstring billnote = L"<GDN><DocInfo><data><Item Name='报关发票' Field='Remark'></Item>" + + "<Item Name='报关箱单' Field='Remark'></Item>" + + "<Item Name='议付发票' Field='Remark'></Item>" + + "<Item Name='议付箱单' Field='Remark'></Item>" + + "<Item Name='装船通知' Field='Remark'></Item>" + + "<Item Name='加拿大海关发票' Field='Remark'></Item>" + + "<Item Name='FORMA' Field='Remark'></Item></data></DocInfo></GDN>"; + x.LoadXml(billnote); + dw_billnote.Retrieve(x); + } + + int onload() + { + + xstring userid = publiccode::GetUser().id; + //trace(userid); + haveUpdate = true; + InvoiceID = L""; + tabname = L"base"; + + OnAttachEvent(); + + dw_base = GetControl(L"dw_base"); + dw_base.openUrl(L"/sale/view/GDN/template/Base"); + dw_base.SetColHeaderHeight(0); + dw_base.SetRowSelectorWidth(0); + dw_base.SetHScrollState(false); + + //dw_base.SetVScrollState(false); + //dw_base.SetColumnState(L"GoodsSource",false); + + dw_item = GetControl(L"dw_item"); + //dw_item.openUrl(L"/sale/view/GDN/template/GDNItem1"); + dw_item.SetDataObject(GetServerUrl(), L"dev:sheet[GDN.v3.Ex.tpl/GDNItem]"); + + xstring userno = publiccode::GetUser().no; + + //alert(userno); + //trace(userno); + //trace(userid); + //if(userno==L"exp-442"){ + //dw_item.SetReadOnlyColumn(L"Packages",false); + //} + dw_item.SetAskStyle(true); + dw_item.SetColumnState(L"GroupNo", true); + dw_item.SetColumnState(L"ItemID", false); + dw_item.SetColumnState(L"LineType", false); + dw_item.SetColumnState(L"LineNo", false); + dw_item.SetColumnState(L"Assortment", false); + dw_item.SetColumnState(L"GDNID", false); + dw_item.SetColumnState(L"SOLineID", false); + dw_item.SetColumnState(L"GDNLineID", false); + dw_item.SetColumnState(L"SOLineNo", false); + dw_item.SetColumnState(L"SKUNo", false); + dw_item.SetColumnState(L"BuyUnitPrice", false); + dw_item.SetColumnState(L"POCreatorID", false); + dw_item.SetColumnState(L"BuyAmount", false); + dw_item.SetColumnState(L"CostRate", false); + dw_item.SetColumnState(L"CommissionRate", false); + dw_item.SetColumnState(L"DiscountRate", false); + dw_item.SetColumnState(L"Remark", false); + //dw_item.SetColumnState(L"UOMCode",false); + + + + dw_source = GetControl(L"dw_source"); + dw_source.openUrl(L"/sale/view/GDN/template/item/sourcing"); + dw_source.SetColumnState(L"POID", false); + dw_source.SetColumnState(L"SOLineID", false); + dw_source.SetColumnState(L"ItemID", false); + dw_source.SetColumnState(L"POItemID", false); + dw_source.SetColumnState(L"GDNLineID", false); + dw_source.SetColumnState(L"ETD", false); + dw_source.SetColumnState(L"InvoiceNo", false); + dw_source.SetColumnState(L"GDNID", false); + dw_source.SetColumnState(L"Amount", false); + dw_source.SetColumnState(L"GDNSourceAmout", false); + dw_source.SetColumnState(L"GDNLineAmout", false); + + //dw_source.SetColumnState(L"Amount",false); + + + dw_custom = GetControl(L"dw_custom"); + dw_custom.openUrl(L"/sale/view/Custom3/template/maint"); + dw_custom.SetColumnState(L"ClassifyID", false); + dw_custom.SetColumnState(L"AmountEx", false); + //dw_custom.SetReadOnlyColumn(L"CustName",true); + dw_custom.SetColumnState(L"LineNo", false); + + + dw_customex = GetControl(L"dw_customex"); + dw_customex.openUrl(L"/sale/view/GDN/template/item3"); + + dw_invoiceItem = GetControl(L"dw_invoiceex"); + dw_invoiceItem.openUrl(L"/sale/view/GDN/template/item1"); + + dw_fcl = GetControl(L"dw_fcl"); + dw_fcl.openUrl(L"/sale/view/GDN/template/item2"); + dw_fcl.SetColumnState(L"GDNID", false); + dw_fcl.SetColumnState(L"UseFlag", false); + //dw_fcl.InsertRow(0); + + dw_billnote = GetControl(L"dw_billnote"); + dw_billnote.openUrl(L"/sale/view/GDN/template/billnote"); + + dw_profit = GetControl(L"dw_profit"); + dw_profit.openUrl(L"/sale/view/GDN/template/Profit"); + dw_profit.SetColHeaderHeight(0); + dw_profit.SetRowSelectorWidth(0); + dw_profit.SetHScrollState(false); + + dw_cdelement = GetControl(L"dw_cdelement"); + dw_cdelement.openUrl(L"/sale/view/Custom3/template/element"); + dw_cdelement.SetColumnState(L"CDLineID", false); + dw_cdelement.SetColumnState(L"ClassifyID", false); + dw_cdelement.SetColumnState(L"GDNID", false); + + dw_doclist = GetControl(L"dw_doclist"); + dw_doclist.openUrl(L"/sale/view/GDN/template/doclist"); + + InvoiceNo = L""; + if (GetParam()) + { + xaserverarg arg_param = new xaserverarg; + arg_param.setNativePointer(GetParam()); + + InvoiceNo = arg_param.GetArgString(L"InvoiceNo"); + if (InvoiceNo == L"") InvoiceNo = arg_param.GetArgString(L"EntityNo"); + if (InvoiceNo == L"") + { + xstring EntityID = arg_param.GetArgString(L"EntityID"); + if (EntityID != L"") InvoiceNo = GDNView::GetInvoiceNoByID(EntityID); + } + InvoiceID = arg_param.GetArgString(L"EntityID"); + if (InvoiceID == L"" && InvoiceNo != L"") + { + InvoiceID = GetInvoiceID(InvoiceNo); + } + + readonly = false; + readonlyEx = false; + if (arg_param.GetArgString(L"ReadOnly") == L"true") readonly = true; + if (arg_param.GetArgString(L"ReadOnlyEx") == L"true") readonlyEx = true; + } + + dw_base.SetEditUpperMode(true); + dw_item.SetEditUpperMode(true); + dw_custom.SetEditUpperMode(true); + dw_profit.SetEditUpperMode(true); + dw_source.SetEditUpperMode(true); + dw_cdelement.SetEditUpperMode(true); + dw_invoiceItem.SetEditUpperMode(true); + dw_customex.SetEditUpperMode(true); + dw_billnote.SetEditUpperMode(true); + dw_doclist.SetEditUpperMode(true); + dw_fcl.SetEditUpperMode(true); + + datareading = false; + return 1; + } + + int onloaded() + { + if (InvoiceNo != L"") + { + Retrieve(InvoiceNo); + //CalcProfit();//重新计算盈亏 + } + else + { + OnNewInital(); + if (GetParam()) + { + xaserverarg arg = new xaserverarg; + arg.setNativePointer(GetParam()); + + if (arg.GetArgString(L"CustomerID") != L"") + { + dw_base.ItemChangeTo(1, L"CustomerID", arg.GetArgString(L"CustomerID")); + dw_base.SetItemDisplayString(1, L"CustomerID", arg.GetArgString(L"CustomerName")); + xstring dwname = L"dw_base"; + xstring colname = L"CustomerID"; + xstring value = arg.GetArgString(L"CustomerID"); + KXMLDOMNodeList nlist = GetElement().selectNodes(L"//*[@name='" + dwname + L"']/trans[@for='" + colname + L"']"); + ViewObject::TransData(nlist, dw_base, 1, colname, value); + trace(L"+++++L"); + } + } + OnAddGDNItem(); + } + if (readonly) + { + dw_base.SetReadOnly(true); + dw_item.SetReadOnly(true); + if (!readonlyEx) + { + dw_custom.SetReadOnly(true); + dw_cdelement.SetReadOnly(true); + } + dw_profit.SetReadOnly(true); + dw_source.SetReadOnly(true); + dw_invoiceItem.SetReadOnly(true); + dw_customex.SetReadOnly(true); + dw_billnote.SetReadOnly(true); + dw_doclist.SetReadOnly(true); + dw_fcl.SetReadOnly(true); + } + dw_base.SetColumnProp(L"VerificationSheet", L"cellprotect", L"1"); + + SetAgentEx(); + return 1; + } +}; \ No newline at end of file diff --git a/jrj/xframe/kobject/kxml.hpp b/jrj/xframe/kobject/kxml.hpp index f152062..966d8ad 100644 --- a/jrj/xframe/kobject/kxml.hpp +++ b/jrj/xframe/kobject/kxml.hpp @@ -255,6 +255,22 @@ }; }} +class KXMLDOMElementPtr +{ +private: + KXMLDOMElement* m_pElement; +public: + KXMLDOMElementPtr(LPARAM ele) :m_pElement((KXMLDOMElement* )ele) {} + KXMLDOMElementPtr(KXMLDOMElement* pEle) :m_pElement((KXMLDOMElement*)pEle) {} + KXMLDOMElementPtr(KXMLDOMElement ele) :m_pElement(new KXMLDOMElement(ele)) {} +public: + KXMLDOMElement* value() { return m_pElement; } +public: + operator KXMLDOMElement* () { return m_pElement; } + operator KXMLDOMElement& () { return *m_pElement; } + KXMLDOMElement* operator -> () { return m_pElement; } +}; + using KXMLDOMDocument=Hxsoft::XFrame::KXMLDOMDocument; using KXMLDOMNode=Hxsoft::XFrame::KXMLDOMNode; using KXMLDOMElement=Hxsoft::XFrame::KXMLDOMElement; diff --git a/jrj/xframe/wobject/xaserverarg.hpp b/jrj/xframe/wobject/xaserverarg.hpp index 9445853..0909ca6 100644 --- a/jrj/xframe/wobject/xaserverarg.hpp +++ b/jrj/xframe/wobject/xaserverarg.hpp @@ -120,74 +120,13 @@ xaserverarg* arg; public: xaserverargPtr() :arg(new xaserverarg) {} + xaserverargPtr(LPARAM* val) :arg((xaserverarg*)val) {} + xaserverargPtr(xaserverarg* val) :arg(val) {} + xaserverargPtr(xaserverarg val) :arg(new xaserverarg(val)){} +public: + xaserverarg* value() { return arg; } public: operator xaserverarg& () { return *arg; } operator xaserverarg* () { return arg; } xaserverarg* operator ->() { return arg; } -public: - int AddArg(string argname, string val, string typ = NULL) //alias "?AddArg@IXAServerArg@XFrame@Hxsoft@@QAEHPB_W00@Z"; - { - return arg->AddArg(argname, val, typ); - } - - int ClearArgs() //alias "?ClearArgs@IXAServerArg@XFrame@Hxsoft@@QAEHXZ" from "xframe.dll"; - { - return arg->ClearArgs(); - } - - int RemoveArg(string argname) //alias "?RemoveArg@IXAServerArg@XFrame@Hxsoft@@QAEHPB_W@Z"; - { - return arg->RemoveArg(argname); - } - /*int SetArg(string argname,double val,string typ=NULL) //alias "?SetArg@IXAServerArg@XFrame@Hxsoft@@QAEHPB_WNO@Z"; - { - return arg->SetArg(argname,val,typ); - } - int SetArg(string argname,int val,string typ=NULL) //alias "?SetArg@IXAServerArg@XFrame@Hxsoft@@QAEHPB_WHO@Z"; - { - return arg->SetArg(argname,val,typ); - }*/ - int SetArg(string argname, string val, string typ = NULL) //alias "?SetArg@IXAServerArg@XFrame@Hxsoft@@QAEHPB_W00@Z"; - { - return arg->SetArg(argname, val, typ); - } - string GetString() //alias "?GetString@IXAServerArg@XFrame@Hxsoft@@QAEPB_WXZ" from "xframe.dll"; - { - return arg->GetString(); - } - static void* CreateInstance() //alias "?CreateInstance@IXAServerArg@XFrame@Hxsoft@@SAPAV123@XZ"; - { - return Hxsoft::XFrame::IXAServerArg::CreateInstance(); - } - static int ReleaseInstance(void* p) //alias "?ReleaseInstance@IXAServerArg@XFrame@Hxsoft@@SAHPAV123@@Z"; - { - Hxsoft::XFrame::IXAServerArg::ReleaseInstance((Hxsoft::XFrame::IXAServerArg*)p); - return 1; - } - bool GetArgBool(string argname) //alias "?GetArgBool@IXAServerArg@XFrame@Hxsoft@@QAE_NPA_W@Z"; - { - return arg->GetArgBool((LPTSTR)argname); - } - double GetArgDouble(string argname) //alias "?GetArgDouble@IXAServerArg@XFrame@Hxsoft@@QAENPA_W@Z"; - { - return arg->GetArgDouble((LPTSTR)argname); - } - int GetArgInt(string argname) //alias "?GetArgInt@IXAServerArg@XFrame@Hxsoft@@QAEHPA_W@Z"; - { - return arg->GetArgInt((LPTSTR)argname); - } - string GetArgString(string argname) //alias "?GetArgString@IXAServerArg@XFrame@Hxsoft@@QAEPA_WPA_W@Z"; - { - return arg->GetArgString((LPTSTR)argname); - } - - int SetParam(LPCTSTR pArgName, LPARAM pValue) - { - return arg->SetParam(pArgName, pValue); - } - - LPARAM GetParam(LPCTSTR pArgName) - { - return arg->GetParam(pArgName); - } }; \ No newline at end of file -- Gitblit v1.9.3