Options

Average cost

LeshabelaLeshabela Member Posts: 35
hi all,

i want to calculate the average cost and post it, but after i've done my calculations in item journal line, i posted the line, and in the value entry invoiced quantity is zero and i want it to take the value of quantity in the item journal line.how can i get the field to show items.

ItemJnlLine.SETRANGE("Journal Batch Name");
IF ItemJnlLine.FIND('-') THEN BEGIN
Items.GET(ItemJnlLine."Item No.");
ItemJnlLine.VALIDATE(ItemJnlLine.Quantity);
ItemCostMgt.CalculateAverageCost(Items,AverageCostLCY,AverageCostACY);
IF AverageCostLCY = 0 THEN BEGIN
PurchInvLine.SETCURRENTKEY(PurchInvLine."Document No.",PurchInvLine."Line No.");
PurchInvLine.SETRANGE(PurchInvLine."No.",Items."No.");
IF PurchInvLine.FIND('+') THEN BEGIN
ItemJnlLine.INIT;
ItemJnlLine."Journal Template Name" := "Journal Template Name";
ItemJnlLine."Journal Batch Name" := "Journal Batch Name";
ItemJnlLine."Line No." := "Line No.";
ItemJnlLine."Item No." := "Item No.";
ItemJnlLine."Posting Date" := "Posting Date";
ItemJnlLine."Entry Type" := "Entry Type";
ItemJnlLine."Document No." := "Document No.";
ItemJnlLine.Description := Description;
ItemJnlLine.Quantity := Quantity;
ItemJnlLine."Unit Cost" := PurchInvLine."Unit Cost (LCY)";
ItemJnlLine."Quantity (Base)" := Quantity;
ItemJnlLine."Unit of Measure Code" := PurchInvLine."Unit of Measure Code";
ItemJnlLine.MODIFY;

MESSAGE(Text001 + '%1',CostAvgAmt);
END;
END;
END;

thanks
Learning Never End.

Comments

  • Options
    ArhontisArhontis Member Posts: 667
    First of all, you shouldn't use the init function prior to modify, this places 0 to the quantity field and also modifies all the fields.

    Secondly, since you only need to get and modify the cost of the item then you should only modify that specific field, unit of measure and not the whole ItemJnlLine record.

    If the AverageCostLCY <>0 you don't do anything...

    You should place an else begin/end statement with:
    ELSE BEGIN
      ItemJnlLine."Unit Cost" := AverageCostLCY;
      ItemJnlLine.MODIFY;
    END;
    
    after the:
    MESSAGE(Text001 + '%1',CostAvgAmt); 
    END;
    END;
    
  • Options
    Tim81Tim81 Member Posts: 68
    Arhontis wrote:
    MESSAGE(Text001 + '%1',CostAvgAmt); 
    END;
    END;
    
    [offtopic]
    Why don't you assign the '%1' directly to the Text-Const?
    [/offtopic]
  • Options
    ArhontisArhontis Member Posts: 667
    :D

    He he... you are correct Tim, if I am to improve all of the code I have ever replied to, I wouldn't have time to code my own projects...
Sign In or Register to comment.