Skip to main content

Inventory Turns Report

static void InventoryTurns(Args _args) { itemId itemId; inventTrans inventTrans; inventSum inventSum; qty thisQty, qtyOnHand, totalDailyQtyOnHand, avgDailyQtyOnHand, usageQty; Amount thisValue, valueOnHand, totalDailyValueOnHand, avgDailyValueOnHand, usageValue; Real turnsByQty, turnsByValue; date lastDate, fromDate, toDate; ; //set the itemID and date range itemId = '00001'; fromDate = mkDate(1,1,2010); toDate = mkDate(31,12,2010); //****average daily on-hand lastDate = systemDateGet(); //initialize with today. //inventSum contains today's values for qty and value while select inventSum where inventSum.ItemId == itemId && inventSum.Closed == NoYes::No { qtyOnHand += inventSum.PhysicalInvent; valueOnHand += (inventSum.PhysicalValue + inventSum.PostedValue); } //starting with today, we work backward to the from date and manually calculate what the on-hand qty/value was each day while (lastDate >= fromDate) { if (lastDate <= toDate) //if we're within the date range, then sum the on-hand qty/value for determination of the average { //add one days worth of the current OnHand figures totalDailyQtyOnHand += qtyOnHand; totalDailyValueOnHand += valueOnHand; //update average calc avgDailyQtyOnHand = totalDailyQtyOnHand/((toDate + 1) - lastDate); avgDailyValueOnHand = totalDailyValueOnHand/((toDate + 1) - lastDate); } lastDate --; thisQty = 0; thisValue = 0; while select Qty, CostAmountPosted, CostAmountPhysical from inventTrans where inventTrans.ItemId == itemId && inventTrans.DatePhysical == lastDate { thisQty += inventTrans.Qty; //use the posted (financial) value if available if (inventTrans.CostAmountPosted != 0) { thisValue += inventTrans.CostAmountPosted; } else { thisValue += inventTrans.CostAmountPhysical; } } //calc the new onHand values qtyOnHand += -1 * thisQty; valueOnHand += -1 * thisValue; } //****annual usage while select inventTrans order by DatePhysical desc where inventTrans.ItemId == itemId && inventTrans.datePhysical >= fromDate //this should work in place of limits on statusIssue < 3 and statusReceipt < 3 && inventTrans.datePhysical <= toDate && (inventTrans.TransType == InventTransType::Sales || inventTrans.TransType == InventTransType::ProdLine || inventTrans.TransType == InventTransType::Project || inventTrans.TransType == InventTransType::InventTransaction) { usageQty += -1*inventTrans.Qty; usageValue += -1*inventTrans.CostAmountPhysical; } //****calc turns = usageQty divided by average on-hand qty if (avgDailyQtyOnHand == 0) //divide by zero protection { turnsByQty = 0; } else { turnsByQty = usageQty / avgDailyQtyOnHand; } if (avgDailyValueOnHand == 0) { turnsByValue = 0; } else { turnsByValue = usageValue / avgDailyValueOnHand; } info(strfmt("Item Id: %1, Turns by Qty: %2, Turns by Value: %3",itemId,turnsByQty,turnsByValue)); }

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }