{"id":2703,"date":"2026-07-26T10:10:13","date_gmt":"2026-07-26T02:10:13","guid":{"rendered":"https:\/\/www.jh1999.cn\/?p=2703"},"modified":"2026-07-26T10:18:20","modified_gmt":"2026-07-26T02:18:20","slug":"ax%e8%b0%83%e7%94%a8%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e5%82%a8%e5%ad%98%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/www.jh1999.cn\/?p=2703","title":{"rendered":"AX\u8c03\u7528\u6570\u636e\u5e93\u50a8\u5b58\u8fc7\u7a0b"},"content":{"rendered":"<div class=\"gb-container gb-container-6ab208ea\">\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u5728AX\u5f00\u53d1\u7684\u4e2d\uff0c\u5982\u679c\u8fc2\u5230\u8981\u4ece\u4e24\u5343\u4e07\u7ea7\u7684\u6570\u636e\u8868\u4e2d\u63d0\u53d6\u8bb0\u5f55\u5e76\u52a0\u4ee5\u8fd0\u884c\u751f\u6210\u62a5\u8868\uff0c\u5e38\u89c4\u7684 while select \u4ee3\u7801\u6267\u884c\u6548\u7387\u6781\u4f4e\uff0c\u7528\u6237\u901a\u5e38\u90fd\u7b49\u4e0d\u5230\u7ed3\u679c\u5c31\u5931\u53bb\u4fe1\u5fc3\u4e86\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u8c03\u7528\u6570\u636e\u5e93\u7684\u50a8\u5b58\u8fc7\u7a0b\u6765\u5b9e\u73b0\uff0c\u50a8\u5b58\u8fc7\u7a0b\u5168\u7a0b\u5728\u6570\u636e\u5e93\u91cc\u8fd0\u884c\uff0c\u53ea\u63d0\u53d6\u7b26\u5408\u6761\u4ef6\u7684\u8bb0\u5f55\u7ed9AX\uff0c\u5927\u5927\u51cf\u8f7b\u7f51\u7edc\u548cAOS\u7684\u8d1f\u62c5\uff0c\u6548\u7387\u63d0\u5347\u4e0d\u6b62100\u4f4d\u3002<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">\u4e0b\u9762\u662f\u751f\u6210\u7269\u6599\u5e93\u5b58\u5468\u8f6c\u7387\u7684\u4ee3\u7801\u5b9e\u4f8b\uff0c\u76ee\u7684\uff1a\u6839\u64da\u7528\u6236\u9078\u5b9a\u7684\u5009\u5eab\uff0c\u958b\u59cb\u65e5\u671f\uff0c\u622a\u6b62\u65e5\u671f\uff0c\u751f\u6210\u5eab\u5b58\u7269\u6599\u5468\u8f49\u7387\u5831\u8868\uff0c\u5831\u8868\u95dc\u9375\u6b04\u4f4d\uff1a\u7269\u6599\u7de8\u865f\uff0c\u7269\u6599\u540d\u7a31\uff0c\u55ae\u4f4d\uff0c\u6210\u672c\u55ae\u50f9\uff0c\u76e4\u9ede\u57fa\u6578\uff0c\u671f\u521d\u5eab\u5b58\u6578\u91cf\uff0c\u671f\u521d\u5eab\u5b58\u8ca8\u503c\uff0c\u671f\u9593\u51fa\u5eab\u6578\u91cf\uff0c\u671f\u9593\u51fa\u5eab\u8ca8\u503c\uff0c\u671f\u672b\u5eab\u5b58\u6578\u91cf\uff0c\u671f\u672b\u5eab\u5b58\u8ca8\u503c\uff0c\u5468\u8f49\u7387\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b04\u4f4d\u8aaa\u660e\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u76e4\u9ede\u57fa\u6578\uff1a\u8ddd\u96e2\u8d77\u59cb\u65e5\u671f\u4e4b\u524d\u6700\u8fd1\u7684\u76e4\u9ede\u65e5\u671f\u53ca\u76e4\u9ede\u6578\u91cf\uff0c\u4f5c\u70ba\u76e4\u9ede\u57fa\u6578\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u671f\u521d\u5eab\u5b58\u6578\u91cf\uff1a\u76e4\u9ede\u57fa\u6578 \u52a0\u6e1b \u5f9e\u76e4\u9ede\u65e5\u5230\u8d77\u59cb\u65e5\u7684\u51fa\u5165\u5009\u6578\u91cf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u671f\u9593\u51fa\u5eab\u6578\u91cf\uff1a\u8d77\u59cb\u65e5\u671f\u5230\u622a\u6b62\u65e5\u671f\u4e4b\u9593\u7684\u51fa\u5009\u6578\u91cf\u7d2f\u8a08<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u671f\u672b\u5eab\u5b58\u6578\u91cf\uff1a\u671f\u521d\u5eab\u5b58\u6578\u91cf \u52a0\u6e1b \u5f9e\u8d77\u59cb\u65e5\u671f\u5230\u622a\u6b62\u65e5\u671f\u7684\u51fa\u5165\u5009\u6578\u91cf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5eab\u5b58\u8ca8\u503c = \u6210\u672c\u55ae\u50f9 * \u6578\u91cf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5468\u8f49\u7387% = \u671f\u9593\u51fa\u5eab\u8ca8\u503c*100 \/ (\u671f\u521d\u5eab\u5b58\u8ca8\u503c+\u671f\u672b\u5eab\u5b58\u8ca8\u503c)\/2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u4e2a\u9879\u76ee\u5206\u4e24\u90e8\u4efd\uff1a\u4e00\u3001\u6570\u636e\u5e93\u4e2d\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1b\u4e8c\u3001AX\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USE PROD\nGO\n\nIF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'&#91;dbo].&#91;SPL_CalcInventoryTurnover]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)\n    DROP PROCEDURE &#91;dbo].&#91;SPL_CalcInventoryTurnover]\nGO\n\nCREATE PROCEDURE &#91;dbo].&#91;SPL_CalcInventoryTurnover]\n    @CountingDate CHAR(8),\n    @DateFrom CHAR(8),\n    @DateTo CHAR(8),\n    @InventDimId VARCHAR(20),\n    @DataAreaId CHAR(3)\nAS\nBEGIN\n    SET NOCOUNT ON;\n\n    DECLARE @CountDate DATETIME, @FromDate DATETIME, @ToDate DATETIME;\n    SET @CountDate = CONVERT(DATETIME, @CountingDate, 112);\n    SET @FromDate  = CONVERT(DATETIME, @DateFrom, 112);\n    SET @ToDate    = CONVERT(DATETIME, @DateTo, 112);\n\n    -- \u4e3b\u7d50\u679c\u8868\n    CREATE TABLE #Turnover (\n        ItemId VARCHAR(20) PRIMARY KEY,\n        CountingQty DECIMAL(28,12) DEFAULT 0,\n        OpeningQty DECIMAL(28,12) DEFAULT 0,\n        ClosingQty DECIMAL(28,12) DEFAULT 0,\n        IssueQty DECIMAL(28,12) DEFAULT 0\n    );\n\n    -- \u9810\u5b9a\u4ea4\u6613\u805a\u5408\u8868\n    CREATE TABLE #TransSum (\n        ItemId VARCHAR(20) PRIMARY KEY,\n        OpeningChange DECIMAL(28,12) DEFAULT 0,\n        ClosingChange DECIMAL(28,12) DEFAULT 0,\n        IssueQty DECIMAL(28,12) DEFAULT 0\n    );\n\n    -- 1. \u76e4\u9ede\u57fa\u6e96\u5eab\u5b58\n    INSERT INTO #Turnover (ItemId, CountingQty)\n    SELECT ItemId, SUM(Counted)\n    FROM InventJournalTrans WITH (NOLOCK)\n    WHERE Voucher > ''\n      AND Counted > 0\n      AND InventDimId = @InventDimId\n      AND JournalType = 4\n      AND TransDate = @CountDate\n      AND DataAreaId = @DataAreaId\n    GROUP BY ItemId;\n\n    -- 2. \u88dc\u5145\u65b0\u7269\u6599\n    INSERT INTO #Turnover (ItemId, CountingQty)\n        SELECT ItemId, 0\n        FROM InventTrans WITH (NOLOCK)\n        WHERE InventDimId = @InventDimId\n          AND DatePhysical > @CountDate\n          AND DatePhysical &lt;= @ToDate\n          AND DataAreaId = @DataAreaId\n          AND TransType &lt;= 10\n          AND NOT EXISTS (\n              SELECT 1 FROM #Turnover t WHERE t.ItemId = InventTrans.ItemId)\n        GROUP BY ItemId;  \n\n    -- 3. \u9810\u805a\u5408\u4ea4\u6613\u6578\u64da\n    INSERT INTO #TransSum (ItemId, OpeningChange, ClosingChange, IssueQty)\n    SELECT \n        ItemId,\n        SUM(CASE WHEN DatePhysical > @CountDate AND DatePhysical &lt;= @FromDate THEN Qty ELSE 0 END),\n        SUM(CASE WHEN DatePhysical > @FromDate AND DatePhysical &lt;= @ToDate THEN Qty ELSE 0 END),\n        SUM(CASE WHEN DatePhysical >= @FromDate AND DatePhysical &lt;= @ToDate AND Qty &lt; 0 THEN -Qty ELSE 0 END)\n    FROM InventTrans WITH (NOLOCK)\n    WHERE InventDimId = @InventDimId\n      AND DataAreaId = @DataAreaId\n      AND TransType &lt;= 10\n      AND DatePhysical > @CountDate\n      AND DatePhysical &lt;= @ToDate\n    GROUP BY ItemId;\n\n    -- 4. \u5408\u4f75\u5230\u4e3b\u8868\n    UPDATE t\n    SET \n        OpeningQty = t.CountingQty + ISNULL(s.OpeningChange, 0),\n        ClosingQty = t.CountingQty + ISNULL(s.OpeningChange, 0) + ISNULL(s.ClosingChange, 0),\n        IssueQty = ISNULL(s.IssueQty, 0)\n    FROM #Turnover t\n    LEFT JOIN #TransSum s ON t.ItemId = s.ItemId;\n\n    -- 5. \u56de\u50b3\u7d50\u679c\n    SELECT ItemId, CountingQty, OpeningQty, ClosingQty, IssueQty\n    FROM #Turnover\n    ORDER BY ItemId;\n\n    DROP TABLE #TransSum;\n    DROP TABLE #Turnover;\nEND\nGO\n\nGRANT EXECUTE ON &#91;dbo].&#91;SPL_CalcInventoryTurnover] TO axView\nGO<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">AX\u4e2d\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u5e76\u5728FORM\u7684GRID\u4e2d\u5c55\u793a\u7ed3\u679c\u7684\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/sandal \u5168\u90e8\u7269\u6599\u6307\u5b9a\u671f\u95f4\u7684\u5eab\u5b58\u5468\u8f49\u7387\n\/\/COM\u6539\u6210command-\u89e3\u51b3\u9632\u57f7\u884c\u8d85\u6642\u95ee\u9898\nvoid SPL_EnquireNoItem()\n{\n    InventTable         _inventTable;\n    InventTableModule   _inventTableModule;\n    str     _strCountDate, _strFromDate, _strToDate;\n    COM     adoConnection;\n    COM     adoCommand; \/\/New Component\n    COM     adoRecordset;\n    COM     adoFields;\n    COM     adoField;\n    COMVariant  _tempVar;\n    str     sqlCmd;\n    str     _itemId, _tempStr;\n    real    _countingQty, _openingQty, _closingQty, _issueQty, _avgAmt;\n    int     _recordCount;\n    str     _connStr = \"Provider=SQLOLEDB.1;Data Source=192.168.0.186;Initial Catalog=PROD;User ID=axView;Password=11111111111;\";\n    ;\n    _strCountDate   = date2str(g_ckDate,321,2,0,2,0,4); \/\/\u8f49\u5b57\u7b26YYYYMMDD\n    _strFromDate    = date2str(g_FromDate,321,2,0,2,0,4);\n    _strToDate      = date2str(g_ToDate,321,2,0,2,0,4);\n\n    \/\/\u81e8\u6642\u9a57\u8b49\u53c3\u6578\u4ee3\u78bc\n    \/\/info(strFmt(\"\u76e4\u9ede\u65e5: %1, \u671f\u521d: %2, \u671f\u672b: %3\", _strCountDate, _strFromDate, _strToDate));\n    \/\/info(strFmt(\"\u5009\u5eab:'%1', \u516c\u53f8: %2\", g_fullDimId, curext()));\n\n    \/\/\u5efa\u7acb\u93c8\u63a5\n    adoConnection = new COM(\"ADODB.Connection\");\n    adoConnection.Open(_connStr);\n    \/\/\u5efa\u7acbCommand\u5c0d\u8c61\u4e26\u8a2d\u7f6e\u8d85\u6642\u6642\u9593\n    adoCommand = new COM(\"ADODB.Command\");\n    adoCommand.ActiveConnection(adoConnection);\n    adoCommand.CommandTimeout(600);  \/\/ \u8d85\u664210\u5206\u9418\n    adoCommand.CommandType(1);       \/\/ adCmdText = 1\n    \/\/\u53d6\u904e\u7a0b\u547d\u4ee4\n    sqlCmd = strFmt(\n        \"EXEC &#91;dbo].&#91;SPL_CalcInventoryTurnover] '%1', '%2', '%3', '%4', '%5'\",\n        _strCountDate, _strFromDate, _strToDate, g_fullDimId, curext() );\n    adoCommand.CommandText(sqlCmd);\n    adoRecordset = adoCommand.Execute();  \/\/ \u901a\u904e Command \u57f7\u884c\n    \/\/adoRecordset = adoConnection.Execute(sqlCmd); \/\/\u8d85\u6642\u5931\u6557\n\n    if (!adoRecordset || (adoRecordset.BOF() &amp;&amp; adoRecordset.EOF()))\n    {\n        info('\u6c92\u6709\u53d6\u5230\u6578\u64da');\n        if (adoRecordset)\n            adoRecordset.Close();\n        adoConnection.Close();\n        return;\n    }\n\n     \/\/\u904d\u6b77\u5beb\u5165\u81e8\u6642\u8868\n    _recordCount = 0;\n    adoRecordset.MoveFirst();\n    while (!adoRecordset.EOF())\n    {\n        _countingQty= 0;\n        _openingQty = 0;\n        _closingQty = 0;\n        _issueQty   = 0;\n        adoFields   = adoRecordset.Fields();\n        adoField    = adoFields.Item(0);\n        _tempVar    = adoField.Value();\n        _itemId     = (_tempVar.variantType() == 0) ? \"\" : _tempVar.bstr();\n        adoField    = adoFields.Item(1);\n        _tempVar    = adoField.Value();\n        _countingQty= (_tempVar.variantType() == 0) ? 0 : _tempVar.decimal();\n        adoField = adoFields.Item(2);\n        _tempVar    = adoField.Value();\n        _openingQty = (_tempVar.variantType() == 0) ? 0 : _tempVar.decimal();\n        adoField = adoFields.Item(3);\n        _tempVar    = adoField.Value();\n        _closingQty = (_tempVar.variantType() == 0) ? 0 : _tempVar.decimal();\n        adoField = adoFields.Item(4);\n        _tempVar    = adoField.Value();\n        _issueQty   = (_tempVar.variantType() == 0) ? 0 : _tempVar.decimal();\n        \/\/_issueQty = str2num(_tempStr);    \/\/\u7121\u6548\u7684\u7a7a\u503c\n        \/\/_itemId     = adoRecordset.Fields(\"ItemId\").Value();\/\/Error\n        \/\/\u8abf\u8a66\u4fe1\u606f\n        \/\/info(strFmt(\"\u7b2c %1 \u689d\u8a18\u9304\", _recordCount + 1));\n        \/\/info(strFmt(\"ItemId: '%1'\", _itemId));\n\n        _inventTable = InventTable::find(_itemId);\n        _inventTableModule = InventTableModule::find(_itemId, ModuleInventPurchSales::Invent);\n\n        SPL_tmpEnqTable.clear();\n        SPL_tmpEnqTable.ItemID    = _itemId;\n        SPL_tmpEnqTable.ItemName  = _inventTable.ItemName;\n        SPL_tmpEnqTable.BomUnitID = _inventTable.BOMUnitId;\n        SPL_tmpEnqTable.Price     = _inventTableModule.Price;\n\n        \/\/ \u6620\u5c04\u5b58\u5132\u904e\u7a0b\u7d50\u679c \u2192 Grid \u6b04\u4f4d\n        SPL_tmpEnqTable.Qty3 = _countingQty;   \/\/ \u76e4\u9ede\u6578\u91cf\n        SPL_tmpEnqTable.Qty4 = _openingQty;    \/\/ \u671f\u521d\u6578\u91cf\n        SPL_tmpEnqTable.Qty5 = _issueQty;      \/\/ \u51fa\u5eab\u6578\u91cf\n        SPL_tmpEnqTable.Qty6 = _closingQty;    \/\/ \u671f\u672b\u6578\u91cf\n        SPL_tmpEnqTable.Amt1 = decRound(_openingQty * SPL_tmpEnqTable.Price, 2);\n        SPL_tmpEnqTable.Amt2 = decRound(_issueQty * SPL_tmpEnqTable.Price, 2);\n        SPL_tmpEnqTable.Amt3 = decRound(_closingQty * SPL_tmpEnqTable.Price, 2);\n        _avgAmt = (SPL_tmpEnqTable.Amt1 + SPL_tmpEnqTable.Amt3)\/2;\n        if (_avgAmt != 0)\n            SPL_tmpEnqTable.Qty1 = decRound(SPL_tmpEnqTable.Amt2*100 \/ _avgAmt,0);\n        else\n            SPL_tmpEnqTable.Qty1 = 0;\n        SPL_tmpEnqTable.insert();\n        _recordCount++;\n\n        adoRecordset.MoveNext();\n    }\n\n    \/\/\u6e05\u7406\u8cc7\u6e90\n    adoRecordset.Close();\n    adoConnection.Close();\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/www.jh1999.cn\/wp-content\/uploads\/2026\/07\/ChenXuYuan2.png\" alt=\"\" class=\"wp-image-2721\" srcset=\"http:\/\/www.jh1999.cn\/wp-content\/uploads\/2026\/07\/ChenXuYuan2.png 800w, http:\/\/www.jh1999.cn\/wp-content\/uploads\/2026\/07\/ChenXuYuan2-300x225.png 300w, http:\/\/www.jh1999.cn\/wp-content\/uploads\/2026\/07\/ChenXuYuan2-768x576.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\u5728AX\u5f00\u53d1\u7684\u4e2d\uff0c\u5982\u679c\u8fc2\u5230\u8981\u4ece\u4e24\u5343\u4e07\u7ea7\u7684\u6570\u636e\u8868\u4e2d\u63d0\u53d6\u8bb0\u5f55\u5e76\u52a0\u4ee5\u8fd0\u884c\u751f\u6210\u62a5\u8868\uff0c\u5e38\u89c4\u7684 while select \u4ee3 &#8230; <a title=\"AX\u8c03\u7528\u6570\u636e\u5e93\u50a8\u5b58\u8fc7\u7a0b\" class=\"read-more\" href=\"http:\/\/www.jh1999.cn\/?p=2703\" aria-label=\"Read more about AX\u8c03\u7528\u6570\u636e\u5e93\u50a8\u5b58\u8fc7\u7a0b\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2703","post","type-post","status-publish","format-standard","hentry","category-kfbj"],"_links":{"self":[{"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/posts\/2703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2703"}],"version-history":[{"count":16,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/posts\/2703\/revisions"}],"predecessor-version":[{"id":2726,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=\/wp\/v2\/posts\/2703\/revisions\/2726"}],"wp:attachment":[{"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jh1999.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}