public static bool NeedsBackorder(int orderID) { var query = HCMIS.Repository.Queries.Order.SelectNeedsBackorder(orderID); var order = new Order(); order.LoadFromRawSql(query); return order.RowCount > 0; }
/// <summary> /// Computes the stock calculations for an order detail. /// </summary> /// <param name="currentMonth">The current month.</param> /// <param name="currentYear">The current year.</param> /// <param name="userID">The user ID.</param> /// <param name="orderDetail">The order detail.</param> /// <returns></returns> public DataRow ComputeStockCalculationsForAnOrderDetail(int currentMonth, int currentYear, int userID, OrderDetail orderDetail) { if (!IsOrderDetailTableReady(orderDetail)) { PrepareOrderDetailTable(orderDetail); } int? preferredManufacturer; int? preferredPhysicalStoreID; decimal usableStock; decimal approved; decimal availableQuantity; Balance bal = new Balance(); ItemManufacturer imf = new ItemManufacturer(); int? unitid = null; PriceSettings priceSettings = BLL.Settings.HandleDeliveryNotes ? PriceSettings.BOTH : PriceSettings.PRICED_ONLY; BLL.Order parentOrder = new Order(); parentOrder.LoadByPrimaryKey(orderDetail.OrderID); unitid = orderDetail.UnitID; preferredManufacturer = orderDetail.IsColumnNull("PreferredManufacturerID") ? null : new int?(orderDetail.PreferredManufacturerID); preferredPhysicalStoreID = orderDetail.IsColumnNull("PreferredPhysicalStoreID") ? null : new int?(orderDetail.PreferredPhysicalStoreID); if (orderDetail.IsColumnNull("StoreID")) { orderDetail.StoreID = BLL.Activity.GetActivityUsingFEFO(this.FromStore, orderDetail.ItemID, orderDetail.UnitID); orderDetail.Save(); } Activity storeObject = new Activity(); availableQuantity = storeObject.LoadOptionsForOrderDetail(userID, orderDetail.ID, priceSettings, bal, false, out usableStock, out approved); orderDetail.SetColumn("AvailableStores", storeObject.DefaultView); if (storeObject.RowCount == 1) { orderDetail.StoreID = storeObject.ID; // Avoid error if the column IsDeliveryNote doesn't exsit at all. orderDetail.DeliveryNote = storeObject.DefaultView.Table.Columns.IndexOf("IsDeliveryNote") >= 0 && !storeObject.IsColumnNull("IsDeliveryNote") && Convert.ToBoolean(storeObject.GetColumn("IsDeliveryNote")); availableQuantity = Convert.ToDecimal(storeObject.GetColumn("AvailableSKU")); } else if (storeObject.RowCount > 1) { //TOCLEAN: Lord have mercy. // // check if the default activity is selected // if it has been selected, then do a good job and select it. storeObject.Rewind(); while ( !storeObject.EOF && ( ( storeObject.ID == orderDetail.StoreID && !orderDetail.IsColumnNull("DeliveryNote") && orderDetail.DeliveryNote && !Convert.ToBoolean(storeObject.GetColumn("IsDeliveryNote")) ) || storeObject.ID != orderDetail.StoreID ) ) { storeObject.MoveNext(); } // the selected store is found, don't worry. if (!storeObject.EOF) { availableQuantity = Convert.ToDecimal(storeObject.GetColumn("AvailableSKU")); } else { // the selected store is not found, please do select the first store. storeObject.Rewind(); orderDetail.StoreID = storeObject.ID; orderDetail.DeliveryNote = (storeObject.DefaultView.Table.Columns.IndexOf("IsDeliveryNote") >= 0 && !storeObject.IsColumnNull("IsDeliveryNote") && Convert.ToBoolean(storeObject.GetColumn("IsDeliveryNote"))); availableQuantity = Convert.ToDecimal(storeObject.GetColumn("AvailableSKU")); } } orderDetail.SetColumn("HasStores", (storeObject.RowCount > 1) ? "*" : ""); // Precaution ... to hide -ve available quantity. if (availableQuantity < 0) { availableQuantity = 0; } orderDetail.StockedOut = availableQuantity <= 0; orderDetail.Save(); int qinBu = 1; if (unitid.HasValue) { ItemUnit itemUnit = new ItemUnit(); itemUnit.LoadByPrimaryKey(unitid.Value); qinBu = itemUnit.QtyPerUnit; //Checking if the columns from the vwGetAllItems have been filled in. var fullItemName = orderDetail.GetColumn("FullItemName").ToString(); if (string.IsNullOrEmpty(fullItemName)) { BLL.Order temp = new Order(); temp.LoadFromRawSql(HCMIS.Repository.Queries.Order.SelectItemDetail(orderDetail.ItemID)); orderDetail.SetColumn("Unit", itemUnit.Text); orderDetail.SetColumn("FullItemName", temp.GetColumn("FullItemName")); orderDetail.SetColumn("StockCode", temp.GetColumn("StockCode")); orderDetail.SetColumn("CategoryType", temp.GetColumn("CategoryType")); } } orderDetail.SetColumn("AvailableQuantity", availableQuantity); orderDetail.SetColumn("PricedQuantity", usableStock); if (orderDetail.IsColumnNull("ApprovedQuantity")) { if ((orderDetail.Quantity / ((long)qinBu)) < availableQuantity) { orderDetail.ApprovedQuantity = orderDetail.Quantity; } else { orderDetail.ApprovedQuantity = availableQuantity * qinBu; } } if (BLL.Settings.AllowPreferredManufacturers) { Manufacturer manuf = new Manufacturer(); manuf.LoadForItem(orderDetail.ItemID, orderDetail.StoreID, orderDetail.UnitID, true); manuf.AddNew(); manuf.ID = -1; manuf.Name = "Remove Preference"; orderDetail.SetColumn("AvailableManufacturer", manuf.DefaultView); orderDetail.SetColumn("HasManufacturers", (manuf.RowCount > 2) ? "*" : ""); if (manuf.RowCount == 2) { manuf.Rewind(); orderDetail.PreferredManufacturerID = manuf.ID; } } if (BLL.Settings.AllowPreferredPhysicalStore) { PhysicalStore phyStore = new PhysicalStore(); phyStore.LoadForItem(userID, orderDetail.ItemID, orderDetail.StoreID, orderDetail.UnitID); phyStore.AddNew(); phyStore.Name = "Remove Preference"; phyStore.ID = -1; orderDetail.SetColumn("AvailablePhysicalStore", phyStore.DefaultView); orderDetail.SetColumn("HasPhysicalStoreChoice", (phyStore.RowCount > 2) ? "*" : ""); if (phyStore.RowCount == 2) { phyStore.Rewind(); orderDetail.PreferredPhysicalStoreID = phyStore.ID; } } if (BLL.Settings.AllowPreferredExpiry) { ReceiveDoc rd = new ReceiveDoc(); rd.LoadExpiryDatesForItem(orderDetail.ItemID, orderDetail.StoreID, orderDetail.UnitID, true, preferredManufacturer, preferredPhysicalStoreID); rd.AddNew(); rd.SetColumn("ExpiryDateString", "Remove Preference"); orderDetail.SetColumn("AvailableExpiry", rd.DefaultView); orderDetail.SetColumn("HasExpiryChoice", (rd.RowCount > 2) ? "*" : ""); if (!orderDetail.IsColumnNull("PreferredExpiryDate")) { DateTime expDate = orderDetail.PreferredExpiryDate; string expDateStr = string.Format("{0}-{1:00}-{2:00}", expDate.Year, expDate.Month, expDate.Day, ""); orderDetail.SetColumn("ExpiryDateString", expDateStr); } } // do some reseting if the approved quanitty is greater than if (orderDetail.ApprovedQuantity / qinBu > availableQuantity) { orderDetail.ApprovedQuantity = availableQuantity * qinBu; } orderDetail.SetColumn("UsableStock", usableStock); orderDetail.SetColumn("PApprovedStock", approved); orderDetail.SetColumn("SKUBU", qinBu); orderDetail.SetColumn("AvailableSKU", availableQuantity); string TextID = ((orderDetail.IsColumnNull("DeliveryNote") || !orderDetail.DeliveryNote) ? "N" : "D") + orderDetail.StoreID.ToString(); orderDetail.SetColumn("TextID", TextID); orderDetail.SetColumn("ApprovedSKU", orderDetail.ApprovedQuantity / Convert.ToDecimal(qinBu)); orderDetail.SetColumn("RequestedSKU", orderDetail.Quantity / Convert.ToDecimal(qinBu)); if (availableQuantity == 0) { orderDetail.SetColumnNull("TextID"); orderDetail.SetColumnNull("StoreID"); } Item itm = new Item(); string warning = (itm.GetItemAllowStatus(orderDetail.ItemID, this.RequestedBy) == 0) ? "Warning" : ""; orderDetail.SetColumn("Warning", warning); //if (!orderDetail.IsColumnNull("StoreID")) //{ // var balance = new Balance(); //balance.LoadQuantityNotReceive(orderDetail.ItemID, orderDetail.UnitID, parentOrder.FromStore); //var totalrequested =balance.GetTotalApprovedQuantityByItem(parentOrder.ID, orderDetail.ItemID, orderDetail.UnitID,parentOrder.FromStore); orderDetail.SetColumn("GIT", 0); orderDetail.SetColumn("CRequested",0); orderDetail.SetColumn("CApproved",0); //orderDetail.SetColumn("DOS", balance.DOS); //orderDetail.SetColumn("TotalIssued", balance.TotalIssued); //orderDetail.SetColumn("FiscalYearDays", balance.FiscalYearDays); //decimal amc = 0; //decimal mos = 0; //var totalissued = balance.TotalIssued; //var totaldatediff = balance.FiscalYearDays - balance.DOS; //if (totalissued != 0) //{ // amc = Convert.ToDecimal(totalissued / totaldatediff) * 30; //} //else if (amc == 0) //{ // mos = Convert.ToDecimal(balance.FiscalYearDays / 30.0); //} //else if (amc != 0 && availableQuantity != 0) //{ // mos = Convert.ToDecimal(availableQuantity / amc); //} //else if (availableQuantity == 0 && amc != 0) //{ // mos = 0; //} //else //{ // amc = 0; // mos = 0; //} orderDetail.SetColumn("TotalRequested", 0); orderDetail.SetColumn("AMC", 0); orderDetail.SetColumn("MOS", 0); //} return orderDetail.DefaultView.ToTable().Rows[0]; }
/// <summary> /// Gets the weekly wish list summary. /// </summary> /// <returns></returns> public static object GetWeeklyWishListSummary() { var query = HCMIS.Repository.Queries.Order.SelectGetWeeklyWishListSummary(); Order ord = new Order(); ord.LoadFromRawSql(query); return ord.DefaultView; }
/// <summary> /// Returns a table with Date and Wishlist amount entered on that date. /// </summary> /// <param name="days">For the past how many days (Enter -1 for all)</param> /// <returns></returns> public static object GetWishListSummary(int days) { string query; if (days == -1) query = HCMIS.Repository.Queries.Order.SelectGetWishListSummary(); else query = HCMIS.Repository.Queries.Order.SelectGetWishListSummary(days); Order ord = new Order(); ord.LoadFromRawSql(query); return ord.DefaultView; }
/// <summary> /// Gets the approved quantity. /// </summary> /// <param name="setting">The setting.</param> /// <param name="storeId">The store id.</param> /// <param name="itemID">The item ID.</param> /// <param name="unitid">The unitid.</param> /// <param name="preferedExpiry">The prefered expiry.</param> /// <param name="preferredManufacturer">The preferred manufacturer.</param> /// <param name="preferredPhysicalStoreID">The preferred physical store ID.</param> /// <returns></returns> internal static int GetApprovedQuantity(PriceSettings setting, int storeId, int itemID, int? unitid, DateTime? preferedExpiry, int? preferredManufacturer, int? preferredPhysicalStoreID) { var query = HCMIS.Repository.Queries.Order.SelectGetApprovedQuantity(storeId, itemID, unitid, preferedExpiry, preferredManufacturer, preferredPhysicalStoreID, setting == PriceSettings.DELIVERY_NOTE_ONLY); Order ord = new Order(); ord.LoadFromRawSql(query); if (ord.RowCount > 0 && !ord.IsColumnNull("Approved")) { return Convert.ToInt32(ord.GetColumn("Approved")); } return 0; }
/// <summary> /// Returns the list of requisitions with the status specified. /// </summary> /// <param name="status">The status.</param> /// <param name="userID">The user ID.</param> /// <returns></returns> public static DataTable GetRequisitions(string statuscode, int userID) { string orderStatuses = statuscode == "DRFT" ? "'DRFT'" : " 'DRFT','ORFI','APRD','PIKL','PLCN' "; var query = HCMIS.Repository.Queries.Order.SelectGetRequisitions(userID, orderStatuses); Order ord = new Order(); ord.LoadFromRawSql(query); while (!ord.EOF) { EthiopianDate.EthiopianDate eth; ord.SetColumn("DateRequested", EthiopianDate.EthiopianDate.GregorianToEthiopian(Convert.ToDateTime(ord.GetColumn("EurDate")))); ord.MoveNext(); } return ord.DataTable; }
/// <summary> /// Gets the requisition details. /// </summary> /// <param name="orderID">The order ID.</param> /// <returns></returns> public static DataTable GetRequisitionDetails(int orderID) { var query = HCMIS.Repository.Queries.Order.SelectGetRequisitionDetailsQuery(orderID); Order ord = new Order(); ord.LoadFromRawSql(query); return ord.DataTable; }
/// <summary> /// Gets the order status list. /// </summary> /// <returns></returns> public static DataTable GetOrderStatusList(int modeID) { var query = HCMIS.Repository.Queries.Order.SelectGetOrderStatusList(modeID); Order order = new Order(); order.LoadFromRawSql(query); return order.DataTable; }
/// <summary> /// Returns the Date, Order for a specific order status ID /// </summary> /// <param name="orderStatusID">The order status ID.</param> /// <param name="days">For the past how many days (Enter -1 for all)</param> /// <returns></returns> public static object GetOrdersForReport(int orderStatusID, int days) { string query; if (days == -1) query = HCMIS.Repository.Queries.Order.SelectGetOrdersForReport(orderStatusID); else query = HCMIS.Repository.Queries.Order.SelectGetOrdersForReport(orderStatusID, days); Order ord = new Order(); ord.LoadFromRawSql(query); return ord.DefaultView; }
/// <summary> /// Gets Next order reference number, /// this is used instead of implementation on the database because the reference number logic was changed /// after the inital design which allowed users to type in the reference number. /// </summary> /// <returns></returns> public static string GetNextOrderReference() { Order order = new Order(); var query = HCMIS.Repository.Queries.Order.SelectGetNextOrderReference(FiscalYear.Current.ID); order.LoadFromRawSql(query); if (order.RowCount == 0 || order.RefNo == "") { return "1"; } int last = Convert.ToInt32(order.RefNo); return (last + 1).ToString(); ; }
public static DataTable GetMissingSTVs(int userID) { var query = HCMIS.Repository.Queries.Order.SelectGetMissingSTVs(); Order order = new Order(); order.LoadFromRawSql(query); return order.DataTable; }