public double GetSOHAmount(int itemId, int storeId, int month, int year) { //ask by normal u get soh on normal month IssueDoc iss = new IssueDoc(); ReceiveDoc rec = new ReceiveDoc(); Disposal dis = new Disposal(); YearEnd yEnd = new YearEnd(); //int month = (mon > 2) ? mon - 2 : ((mon == 1) ? 11 : 12); //int year = (mon > 2) ? yr : yr - 1; double cons = 0; cons = (yEnd.GetBBalanceAmount(year, storeId, itemId, month) + rec.GetReceivedAmount(itemId, storeId, year) + dis.GetAdjustedAmount(itemId, storeId, year) - iss.GetIssuedAmount(itemId, storeId, year) - dis.GetLossesAmount(itemId, storeId, year)); this.FlushData(); // this.LoadFromRawSql(String.Format("SELECT SUM(QuantityLeft) AS Quantity FROM ReceiveDoc WHERE (ItemID = {0}) AND (StoreID = {1} AND ((Month(Date) <= {2} AND Year(Date) = {3}) OR (Month(Date) > 10 AND Year(Date) = {4})))", itemId, storeId, month, year, year - 1)); // cons = (this.DataTable.Rows[0]["Quantity"].ToString() != "") ? Convert.ToInt64(this.DataTable.Rows[0]["Quantity"]) : 0; return cons; }
public DataTable BalanceAllItems(int storeId, int year, int month, string selectedType) { IssueDoc iss = new IssueDoc(); ReceiveDoc rec = new ReceiveDoc(); Disposal dis = new Disposal(); YearEnd yEnd = new YearEnd(); Items itm = new Items(); DataTable dtResult = new DataTable(); string[] col = { "FullItemName", "BBalance", "BBAmount", "ReceivedQty", "ReceivedAmount", "IssuedQty", "IssuedAmount", "LossesQty", "LossesAmount", "AdjustedQty", "AdjustedAmount", "SOH", "SOHAmount", "Received", "ID", "CategoryId", "SubCategoryID" }; int i = 0; foreach (string s in col) { if (i > 0) { dtResult.Columns.Add(s, typeof(double)); } else { dtResult.Columns.Add(s); } i++; } DataTable dtItem = ((selectedType == "Drug") ? itm.GetAllItems(1) : itm.GetAllSupply()); foreach (DataRow dr in dtItem.Rows) { string itemName = dr["FullItemName"].ToString();// +" - " + dr["DosageForm"].ToString() + " - " + dr["Strength"].ToString(); int itemId = Convert.ToInt32(dr["ID"]); Int64 bb = yEnd.GetBBalance(year, storeId, itemId, month); double bbAmount = yEnd.GetBBalanceAmount(year, storeId, itemId, month); Int64 recQuant = rec.GetReceivedQuantityTillMonth(itemId, storeId, month, year); double recPrice = rec.GetReceivedAmountTillMonth(itemId, storeId, month, year); Int64 issuedQuant = iss.GetIssuedQuantityTillMonth(itemId, storeId, month, year); double issPrice = iss.GetIssuedAmountTillMonth(itemId, storeId, month, year); Int64 lossQuant = dis.GetLossesQuantityTillMonth(itemId, storeId, month, year); double lossAmount = dis.GetLossesAmountTillMonth(itemId, storeId, month, year); Int64 adjQuant = dis.GetAdjustedQuantityTillMonth(itemId, storeId, month, year); double adjAmount = dis.GetAdjustedAmountTillMonth(itemId, storeId, month, year); Int64 SOH = bb + recQuant + adjQuant - issuedQuant - lossQuant; double SOHAmount = (bbAmount + recPrice + adjAmount - issPrice) - lossAmount; if (SOHAmount < 0) { ; } int Isrec = ((bb == 0 && recQuant == 0) ? 0 : 1); object[] obj = { itemName, bb, bbAmount, recQuant, recPrice, issuedQuant, issPrice, lossQuant, lossAmount, adjQuant, adjAmount, SOH, SOHAmount, Isrec, itemId, Convert.ToInt32(dr["CategoryId"]), Convert.ToInt32(dr["SubCategoryID"]) }; dtResult.Rows.Add(obj); } return dtResult; }