public sp_SAP_WarehouseStockAvailability_Result WarehouseBatches(string itemcode)
 {
     using (var ctx = new DevEntities())
     {
         return(ctx.sp_SAP_WarehouseStockAvailability(itemcode).FirstOrDefault());
     }
 }
Ejemplo n.º 2
0
        public static void ClearAllDrafts(SAP sap)
        {
            using (var ctx = new DevEntities())
            {
                var deliveries = ctx.ReserveInvoices_OpenedDrafts.Select(x => x.DocEntry).ToArray();

                for (int i = 0; i < deliveries.Length; i++)
                {
                    Delivery d = new Delivery();
                    d.LoadDraft(sap, deliveries[i]);

                    int result = d.ClearDraft();

                    if (result == 0)
                    {
                        Console.WriteLine(deliveries[i] + " cleared.");
                    }
                    else
                    {
                        Console.WriteLine("Error clearing " + deliveries[i] + ". " + sap.oCompany.GetLastErrorDescription());
                    }

                    d = null;
                }
            }
        }
        public double AllocateNonBatchStock(string itemcode, string shopwhscode, double iqty)
        {
            decimal d_iqty = Convert.ToDecimal(iqty);

            using (var ctx = new DevEntities())
            {
                var stock = ctx.sp_SAP_ShopStockAvailability(itemcode, shopwhscode).FirstOrDefault();

                if (stock != null)
                {
                    decimal av_qty = stock.AVAILQTY.Value - Convert.ToDecimal(StockCumalation.Where(x => x.ItemCode == itemcode).Sum(x => x.InvQuantity));

                    if (av_qty >= d_iqty)
                    {
                        var q = Convert.ToDouble(d_iqty);

                        StockCumalation.Add(new StockCumalationItem
                        {
                            ItemCode    = itemcode,
                            InvQuantity = q
                        });

                        return(q);
                    }
                }

                return(0);
            }
        }
Ejemplo n.º 4
0
 public void GetInvoices(int top)
 {
     using (var ctx = new DevEntities())
     {
         Invoices = ctx.sp_ReserveInvoices_InvoiceLines2(top).ToArray();
     }
 }
Ejemplo n.º 5
0
        public static int CountOpenedDrafts()
        {
            using (var ctx = new DevEntities())
            {
                var deliveries = ctx.ReserveInvoices_OpenedDrafts.Select(x => x.DocEntry).ToArray();

                return(deliveries.Length);
            }
        }
Ejemplo n.º 6
0
        // Warehousing
        public static int?GetBPLIdFromWhscode(string shopwhscode)
        {
            using (var ctx = new DevEntities())
            {
                var whscodeObj = ctx.sp_SAP_GetBPLIdFromWhscode(shopwhscode).FirstOrDefault();

                return(whscodeObj?.BPLid);
            }
        }
Ejemplo n.º 7
0
        public static sp_SAP_WarehouseStockAvailability_Result WarehouseStockCheck(string itemcode, decimal invquantity)
        {
            using (var ctx = new DevEntities())
            {
                var fromwhs = ctx.sp_SAP_WarehouseStockAvailability(itemcode)
                              .Where(x => x.AVAILQTY.Value >= invquantity)
                              .OrderBy(x => x.PRIORITY)
                              .FirstOrDefault();

                return(fromwhs);
            }
        }
            public IEnumerable <BinAllocationItem> AllocateBins_KS(List <BinAllocationItem> acc_bins)
            {
                using (var ctx = new DevEntities())
                {
                    var av_bins = ctx.sp_SAP_BinAvailability_KS(AbsEntry, WhsCode).ToArray();

                    // Batch enough for requested qty

                    var    alc_bins   = new List <BinAllocationItem>();
                    double remain_qty = InvQuantity;

                    foreach (var b in av_bins)
                    {
                        var bin_qty = Convert.ToDouble(b.OnHandQty.Value);

                        var bin_cum_qty = bin_qty - acc_bins.Where(x => x.BinAbsEntry == b.AbsEntry && x.BatchAbsEntry == b.SnBMDAbs).Sum(x => x.InvQuantity);

                        if (remain_qty > 0 && bin_cum_qty > 0)
                        {
                            if (remain_qty >= bin_cum_qty)
                            {
                                // Remaining more than batch qty

                                var alc_item = new BinAllocationItem();
                                alc_item.BatchAbsEntry = b.SnBMDAbs;
                                alc_item.BinAbsEntry   = b.AbsEntry;
                                alc_item.BinCode       = b.BinCode;
                                alc_item.InvQuantity   = bin_cum_qty;

                                remain_qty = remain_qty - bin_cum_qty; // update tracking

                                alc_bins.Add(alc_item);
                            }
                            else
                            {
                                // Remaining more than abtch qty batch_qty > remain_qty

                                var alc_item = new BinAllocationItem();
                                alc_item.BatchAbsEntry = b.SnBMDAbs;
                                alc_item.BinAbsEntry   = b.AbsEntry;
                                alc_item.BinCode       = b.BinCode;
                                alc_item.InvQuantity   = remain_qty;

                                remain_qty = 0;

                                alc_bins.Add(alc_item);
                            }
                        }
                    }

                    return(alc_bins);
                }
            }
Ejemplo n.º 9
0
        public void SortUnallocatedItems(SAP sap)
        {
            if (ZeroBatchLineNums.Count > 0)
            {
                var ZeroBatchLineNumsArray = ZeroBatchLineNums.ToArray();
                var line = oDraft.Lines;
                using (var ctx = new DevEntities())
                {
                    for (int i = 0; i < ZeroBatchLineNumsArray.Length; i++)
                    {
                        line.SetCurrentLine(ZeroBatchLineNumsArray[i]);

                        double requiredQty = line.InventoryQuantity - line.BatchNumbers.TotalBatchQuantity();
                        //decimal dInventoryQuantity = Convert.ToDecimal(line.InventoryQuantity);
                        decimal dReqInventoryQuantity = Convert.ToDecimal(requiredQty);

                        var fromwhs = StockInfo.WarehouseStockCheck(line.ItemCode, dReqInventoryQuantity);

                        if (fromwhs != null)
                        {
                            //  Get from warehouses.


                            var invuom = new Item(sap, line.ItemCode).oItem.InventoryUoMEntry;
                            WarehouseTransferItems.Add(new StockTransferItem
                            {
                                LineNum  = line.LineNum,
                                ItemCode = line.ItemCode,
                                //InvQuantity = line.InventoryQuantity,
                                InvQuantity   = Convert.ToDouble(dReqInventoryQuantity),
                                FromWarehouse = fromwhs.WhsCode,
                                ToWarehouse   = line.WarehouseCode,
                                InvUomEntry   = invuom
                            });
                        }
                        else
                        {
                            // Check KIMSON
                            string owner = StockInfo.IsItemLongdanKimson(sap, line.ItemCode);


                            switch (owner)
                            {
                            case "LONGDAN":

                                // Direct goods in
                                var grItem = new GoodsReceiptItem();
                                grItem.ItemCode = line.ItemCode;
                                //grItem.InvQuantity = line.InventoryQuantity;
                                grItem.InvQuantity = Convert.ToDouble(dReqInventoryQuantity);
                                grItem.ShopWhscode = line.WarehouseCode;

                                grItem.Quantity = line.Quantity;
                                grItem.UomCode  = line.UoMCode;
                                grItem.UomEntry = line.UoMEntry;

                                GoodsReceiptItems.Add(grItem);

                                break;


                            case "KIMSON":

                                var k_item = new KimsonDeliveryItem();
                                k_item.ItemCode = line.ItemCode;
                                k_item.Quantity = line.Quantity;
                                k_item.UoMEntry = line.UoMEntry;

                                KimsonDeliveryItems.Add(k_item);

                                break;
                            }

                            // Not KIMSON then GOODS IN
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public IEnumerable <BatchAllocationItem> AllocateBatches_KS(string itemcode, string whscode, double iqty)
        {
            decimal diqty = Convert.ToDecimal(iqty);

            using (var ctx = new DevEntities())
            {
                var av_batches = ctx.sp_SAP_BatchAvailability_KS(itemcode, whscode).ToArray();

                var av_totalqty = Convert.ToDouble(av_batches.Sum(x => x.get_avail_res_qty_col_alias - x.get_avail_res_commit_qty_col_alias));

                if (av_totalqty >= iqty)
                {
                    // Batch enough for requested qty

                    var    alc_batches = new List <BatchAllocationItem>();
                    double remain_qty  = iqty;

                    foreach (var b in av_batches)
                    {
                        var bat_qty = Convert.ToDouble((b.get_avail_res_qty_col_alias - b.get_avail_res_commit_qty_col_alias));

                        var bat_cum_qty = bat_qty - BatchCumulation.Where(x => x.AbsEntry == b.absentry).Sum(x => x.InvQuantity);

                        if (remain_qty > 0 && bat_cum_qty > 0)
                        {
                            if (remain_qty >= bat_cum_qty)
                            {
                                // Remaining more than batch qty

                                var alc_item = new BatchAllocationItem();
                                alc_item.ItemCode    = b.itemcode;
                                alc_item.AbsEntry    = b.absentry;
                                alc_item.BatchNumber = b.distnumber;
                                alc_item.InvQuantity = bat_cum_qty;
                                alc_item.WhsCode     = whscode;

                                remain_qty = remain_qty - bat_cum_qty; // update tracking

                                alc_batches.Add(alc_item);
                            }
                            else
                            {
                                // Remaining more than abtch qty batch_qty > remain_qty

                                var alc_item = new BatchAllocationItem();
                                alc_item.ItemCode    = b.itemcode;
                                alc_item.AbsEntry    = b.absentry;
                                alc_item.BatchNumber = b.distnumber;
                                alc_item.InvQuantity = remain_qty;
                                alc_item.WhsCode     = whscode;

                                remain_qty = 0;

                                alc_batches.Add(alc_item);
                            }
                        }
                    }

                    // Store batch history
                    BatchCumulation.AddRange(alc_batches);

                    return(alc_batches);
                }
                else
                {
                    // Not enough batch qty
                    // Check other warehouses
                    return(null);
                }
            }
        }