zoukankan      html  css  js  c++  java
  • 单价变更时采购单中单价为0的自动校正

    --@FPrice为未税单价

    CREATE TRIGGER poorderPriceUpdate ON t_SupplyEntry

    FOR  UPDATE

    AS

    BEGIN

      DECLARE @FSupID INT,

        @FItemID INT,

        @FUsed INT,

        @FPrice DECIMAL(28,10),

        @FDiscount DECIMAL(28,10),

        @FDisableDate DATETIME,

        @FQuoteTime DATETIME

      SELECT  @FUsed = FUsed,@FSupID = FSupID,@FItemID = FItemID,@FPrice = FPrice,

              @FDiscount = FDiscount,@FDisableDate = FDisableDate,

              @FQuoteTime = FQuoteTime

      FROM    Inserted

      IF  UPDATE(FUsed)  AND @FUsed = 1 AND @FQuoteTime <= GETDATE() AND @FDisableDate > GETDATE()

      BEGIN

        --select a1.fqty,a1.fcommitQty,a1.FStockQty,  --订货数量,到货数量,入库数量

        --a1.fcess,  --税率

        --a1.fprice,a1.fauxprice,a1.famount,--未税单价,辅助单价,未税金额

        --a1.fauxtaxprice,a1.fallamount,a1.ftaxamount, --含税单价, 价税合计,税额

        --a1.fauxpricediscount,a1.fpricediscount,a1.ftaxprice,  --实际含税单价, 含税单价,含税单价

        --a1.FEntrySelfP0247,a1.FAmtDiscount  --含税单价,折扣额

        --from poorderentry a1

        --left join poorder b1 on a1.finterid=b1.finterid

        --where b1.fbillno='0911M0533'

        UPDATE  a1

        SET     a1.FPrice = @FPrice,a1.FAuxPrice = @FPrice,

                a1.FAmount = @FPrice * a1.FQty,

                a1.FAuxTaxPrice = @FPrice * ( 1 + a1.FCess / 100 ),

                a1.FAllamount = @FPrice * ( 1 + a1.FCess / 100 ) * a1.FQty,

                a1.FTaxAmount = @FPrice * a1.FCess / 100 * a1.FQty,

                a1.FAuxPriceDiscount = @FPrice * ( 1 + a1.FCess / 100 ) * ( 1 - @FDiscount / 100 ),

                a1.FPriceDiscount = @FPrice * ( 1 + a1.FCess / 100 ) * ( 1 - @FDiscount / 100 ),

                a1.FTaxPrice = @FPrice * ( 1 + a1.FCess / 100 ),

                a1.FAmtDiscount = @FPrice * a1.FQty * @FDiscount / 100

        FROM    POOrderEntry a1,

                POOrder b1

        WHERE   a1.FPrice = 0 AND b1.FSupplyID = @FSupID AND a1.FItemID = @FItemID AND b1.FInterID = a1.FInterID

      END

    END

     

    @FPrice 为含税单价

    --------------------------------------------------

    CREATE TRIGGER poorderPriceUpdate ON t_SupplyEntry

    FOR  UPDATE

    AS

    BEGIN

      DECLARE @FSupID INT,

        @FItemID INT,

        @FUsed INT,

        @FPrice DECIMAL(28,10),

        @FDiscount DECIMAL(28,10),

        @FDisableDate DATETIME,

        @FQuoteTime DATETIME

      SELECT  @FUsed = FUsed,@FSupID = FSupID,@FItemID = FItemID,@FPrice = FPrice,

              @FDiscount = FDiscount,@FDisableDate = FDisableDate,

              @FQuoteTime = FQuoteTime

      FROM    Inserted

      IF  UPDATE(FUsed)  AND @FUsed = 1 AND @FQuoteTime <= GETDATE() AND @FDisableDate > GETDATE()

        BEGIN

        --@FPrice 为含税单价

        --select a1.fqty,a1.fcommitQty,a1.FStockQty,  --订货数量,到货数量,入库数量

        --a1.fcess,  --税率

        --a1.fprice,a1.fauxprice,a1.famount,--未税单价,辅助单价,未税金额

        --a1.fauxtaxprice,a1.fallamount,a1.ftaxamount, --含税单价, 价税合计,税额

        --a1.fauxpricediscount,a1.fpricediscount,a1.ftaxprice,  --实际含税单价, 含税单价,含税单价

        --a1.FEntrySelfP0247,a1.FAmtDiscount  --含税单价,折扣额

        --from poorderentry a1

        --left join poorder b1 on a1.finterid=b1.finterid

        --where b1.fbillno='0911M0533'

        UPDATE  a1

        SET     a1.FPrice = @FPrice / ( 1 + a1.FCess / 100 ),

                a1.FAuxPrice = @FPrice / ( 1 + a1.FCess / 100 ),

                a1.FAmount = @FPrice / ( 1 + a1.FCess / 100 ) * a1.FQty,

                a1.FAuxTaxPrice = @FPrice,a1.FAllamount = @FPrice * a1.FQty,

                a1.FTaxAmount = @FPrice / ( 1 + a1.FCess / 100 ) * a1.FCess / 100 * a1.FQty,

                a1.FAuxPriceDiscount = @FPrice * ( 1 - @FDiscount / 100 ),

                a1.FPriceDiscount = @FPrice * ( 1 - @FDiscount / 100 ),

                a1.FTaxPrice = @FPrice,

                a1.FAmtDiscount = @FPrice / ( 1 + a1.FCess / 100 ) * a1.FQty * @FDiscount / 100

        FROM    POOrderEntry a1,

                POOrder b1

        WHERE   a1.FPrice = 0 AND b1.FSupplyID = @FSupID AND a1.FItemID = @FItemID

                AND b1.FInterID = a1.FInterID

      END

    END

     

  • 相关阅读:
    java不定参数列表---乔老师没讲,但是传智有讲
    java数据库连接模板代码通用收集
    java数据库连接模板代码通用收集
    BZOJ2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛
    BZOJ1598: [Usaco2008 Mar]牛跑步
    BZOJ1710: [Usaco2007 Open]Cheappal 廉价回文
    manacher模板
    BZOJ1584: [Usaco2009 Mar]Cleaning Up 打扫卫生
    BZOJ1753: [Usaco2005 qua]Who's in the Middle
    BZOJ1828: [Usaco2010 Mar]balloc 农场分配
  • 原文地址:https://www.cnblogs.com/jshchg/p/2149734.html
Copyright © 2011-2022 走看看