public static int CreateKimsonDelivery(SAP sapks, KimsonDeliveryItem[] ks_items) { var oCompany = sapks.oCompany; Documents delivery = (Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); delivery.DocObjectCodeEx = "15"; // 15 = Delivery delivery.CardCode = LongdanCardCode; delivery.DocDate = DateTime.Today; for (int i = 0; i < ks_items.Count(); i++) { if (i > 0) delivery.Lines.Add(); // Items delivery.Lines.ItemCode = ks_items[i].ItemCode; delivery.Lines.Quantity = ks_items[i].Quantity; delivery.Lines.WarehouseCode = WarehouseCode; delivery.Lines.UoMEntry = ks_items[i].UoMEntry; } int result = delivery.Add(); if (result == 0) NewDeliveryDocEntry = oCompany.GetNewObjectKey(); return result; }
private void btnConnect_Click(object sender, EventArgs e) { // Console Console.WriteLine("Connect companies..."); // Array of specified companies string[] companies = SAP.Companies; // Initiate form property array Companies = new SAP[companies.Length]; int c = 0; for (int i = 0; i < companies.Length; i++) { Companies[i] = new SAP(companies[i]); // Console if (Companies[i].oCompany.Connected) { Console.WriteLine($"{Companies[i].oCompany.CompanyDB} connected."); c++; } } // Console Console.WriteLine($"Connected to {c} companies." + Environment.NewLine); }
public static int CreateDraft(SAP sap, StockTransferItem[] items) { var st = (SAPbobsCOM.StockTransfer)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransferDraft); st.DocObjectCode = BoObjectTypes.oStockTransfer; //st.DocObjectCodeEx = "67"; // 67 = Stock transfer st.DocDate = DateTime.Today; st.FromWarehouse = items[0].FromWarehouse; st.ToWarehouse = items[0].ToWarehouse; //st.BPL_IDAssignedToInvoice = 1; string text = null; for (int i = 0; i < items.Count(); i++) { if (i > 0) { st.Lines.Add(); } // Items st.Lines.ItemCode = items[i].ItemCode; st.Lines.Quantity = items[i].InvQuantity; st.Lines.UoMEntry = items[i].InvUomEntry; st.Lines.WarehouseCode = items[i].ToWarehouse; st.Lines.FromWarehouseCode = items[i].FromWarehouse; text += $"{items[i].ItemCode}, {items[i].InvQuantity} ({items[i].InvUomEntry}), {items[i].ToWarehouse}, {items[i].FromWarehouse}" + Environment.NewLine; } int result = st.Add(); return(result); }
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 static int GetSysBinAbsByWhscode(SAP sap, string whscode) { var recordSet = (Recordset)sap.oCompany.GetBusinessObject(BoObjectTypes.BoRecordset); recordSet.DoQuery($"SELECT AbsEntry FROM [LONGDAN-Newton].DBO.OBIN WHERE SYSBIN = 'Y' AND WhsCode = '{whscode}'"); return(Convert.ToInt32(recordSet.Fields.Item(0).Value)); }
// // Methods // public Warehouse(SAP sap, string whscode) { oWarehouse = (Warehouses)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oWarehouses); oWarehouse.GetByKey(whscode); InitialStockAccount = oWarehouse.StockAccount; InitialCostOfGoodsSoldAccount = oWarehouse.CostOfGoodsSold; InitialAllocationAccount = oWarehouse.TransfersAcc; }
public string CreateDraftKimson(SAP sapks) { string results = null; string LongdanCardCode = "LDCustomer"; string WarehouseCode = "F"; if (KimsonDeliveryItems.Count > 0) { // Create draft in SAP Documents deliveryDraftKS = (Documents)sapks.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); deliveryDraftKS.DocObjectCodeEx = "15"; // 15 = Delivery deliveryDraftKS.CardCode = LongdanCardCode; deliveryDraftKS.DocDate = oDraft.DocDate; var items = KimsonDeliveryItems.ToArray(); for (int i = 0; i < items.Count(); i++) { if (i > 0) { deliveryDraftKS.Lines.Add(); } // Items deliveryDraftKS.Lines.ItemCode = items[i].ItemCode; deliveryDraftKS.Lines.Quantity = items[i].Quantity; deliveryDraftKS.Lines.WarehouseCode = WarehouseCode; deliveryDraftKS.Lines.UoMEntry = items[i].UoMEntry; deliveryDraftKS.Lines.VolumeUnit = 4; // Accounting deliveryDraftKS.Lines.COGSAccountCode = "500007"; } int result = deliveryDraftKS.Add(); if (result != 0) { results = results + sapks.oCompany.GetLastErrorDescription() + Environment.NewLine; } else { results = results + "OK - " + sapks.oCompany.GetNewObjectKey() + Environment.NewLine; } } else { results = "No items for Kimson import."; } return(results); }
public void SortNonBatchItems(SAP sap) { if (NonBatchLineNums.Count > 0) { var NonBatchLineNumsArray = NonBatchLineNums.ToArray(); var line = oDraft.Lines; var allocatorNonbatch = new NonBatchAllocation(); for (int i = 0; i < NonBatchLineNumsArray.Length; i++) { line.SetCurrentLine(NonBatchLineNumsArray[i]); // Any stock in the shop? double qty = allocatorNonbatch.AllocateNonBatchStock(line.ItemCode, line.WarehouseCode, line.InventoryQuantity); if (qty == 0) { decimal dInventoryQuantity = Convert.ToDecimal(line.InventoryQuantity); var fromwhs = StockInfo.WarehouseStockCheck(line.ItemCode, dInventoryQuantity); 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, FromWarehouse = fromwhs.WhsCode, ToWarehouse = line.WarehouseCode, InvUomEntry = invuom }); } else { // Goods in GoodsReceiptItem gitem = new GoodsReceiptItem(); gitem.ItemCode = line.ItemCode; gitem.InvQuantity = line.InventoryQuantity; gitem.Quantity = line.Quantity; gitem.UomCode = line.UoMCode; gitem.UomEntry = line.UoMEntry; gitem.ShopWhscode = line.WarehouseCode; GoodsReceiptItems.Add(gitem); } } } } }
public static int CreateGoodsReceipt(SAP sap, GoodsReceiptItem[] items, int?bplid) { // Cost price list number int priceListNum = 2; var gr = (Documents)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry); if (bplid != null) { gr.BPL_IDAssignedToInvoice = bplid.Value; } for (int i = 0; i < items.Length; i++) { var item = new Item(sap, items[i].ItemCode); if (i > 0) { gr.Lines.Add(); } gr.Lines.ItemCode = items[i].ItemCode; gr.Lines.Quantity = items[i].InvQuantity; gr.Lines.WarehouseCode = items[i].ShopWhscode; // Cost price item.oItem.PriceList.SetCurrentLine(priceListNum); gr.Lines.UnitPrice = item.oItem.PriceList.Price; gr.Lines.Currency = item.oItem.PriceList.Currency; if (item.oItem.ManageBatchNumbers == BoYesNoEnum.tYES) { // Batches gr.Lines.BatchNumbers.BatchNumber = DateTime.Today.ToString("yyMMdd") + "GoodsReptKS" + DateTime.Now.Second.ToString("00"); gr.Lines.BatchNumbers.Quantity = items[i].InvQuantity; } } return(gr.Add()); }
public static string IsItemLongdanKimson(SAP sap, string itemcode) { var item = (Items)sap.oCompany.GetBusinessObject(BoObjectTypes.oItems); var result = item.GetByKey(itemcode); if (result == true) { if (item.Properties[1] == BoYesNoEnum.tYES && item.Properties[2] == BoYesNoEnum.tNO) { return("KIMSON"); } if (item.Properties[1] == BoYesNoEnum.tNO && item.Properties[2] == BoYesNoEnum.tYES) { return("LONGDAN"); } } return(null); }
public bool LoadDraft(SAP sap, int docentry) { this.sap = sap; oDraft = (SAPbobsCOM.StockTransfer)sap.oCompany.GetBusinessObject(BoObjectTypes.oStockTransferDraft); return(oDraft.GetByKey(docentry)); }
public static int CreateGRPO(SAP sap, GoodsReceiptItem[] items, string cardcode, DateTime docdate, int?bplid) { // Cost price list number int priceListNum = 2; var grpo = (Documents)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes); // Headers grpo.CardCode = cardcode; grpo.DocDate = docdate; if (bplid.HasValue) { grpo.BPL_IDAssignedToInvoice = bplid.Value; } // Console Console.WriteLine($"{grpo.CardCode} {grpo.DocDate.ToString("dd/MM/yyyy")} BPLId: {grpo.BPL_IDAssignedToInvoice}"); List <string> frozenItems = new List <string>(); List <string> unpurchasableItems = new List <string>(); string shopAccounting = null; for (int i = 0; i < items.Length; i++) { if (i == 0) { shopAccounting = items[i].ShopWhscode; } var item = new Item(sap, items[i].ItemCode); // Inactive item? if (item.oItem.Frozen == BoYesNoEnum.tYES) { item.oItem.Frozen = BoYesNoEnum.tNO; if (item.oItem.Update() == 0) { frozenItems.Add(items[i].ItemCode); } } // Unpurchasable items? if (item.oItem.PurchaseItem == BoYesNoEnum.tNO) { item.oItem.PurchaseItem = BoYesNoEnum.tYES; if (item.oItem.Update() == 0) { unpurchasableItems.Add(items[i].ItemCode); } } if (i > 0) { grpo.Lines.Add(); } grpo.Lines.ItemCode = items[i].ItemCode; grpo.Lines.InventoryQuantity = items[i].InvQuantity; grpo.Lines.UoMEntry = item.oItem.InventoryUoMEntry; //grpo.Lines.WarehouseCode = items[i].ShopWhscode; // Cost price item.oItem.PriceList.SetCurrentLine(priceListNum); grpo.Lines.UnitPrice = item.oItem.PriceList.Price; grpo.Lines.Currency = item.oItem.PriceList.Currency; grpo.Lines.VolumeUnit = 4; if (item.oItem.ManageBatchNumbers == BoYesNoEnum.tYES) { // Batches grpo.Lines.BatchNumbers.BatchNumber = DateTime.Today.ToString("yyMMdd") + "GRPO" + DateTime.Now.Second.ToString("00"); grpo.Lines.BatchNumbers.Quantity = items[i].InvQuantity; } // Console Console.WriteLine($"{grpo.Lines.ItemCode} x{grpo.Lines.InventoryQuantity.ToString()} [{grpo.Lines.BatchNumbers.BatchNumber} x{grpo.Lines.BatchNumbers.Quantity}]"); } // Accounting Warehouse shopwhs = new Warehouse(sap, shopAccounting); //Warehouse whsF = new Warehouse(sap, "F"); //Warehouse whsLT = new Warehouse(sap, "LT"); shopwhs.SetAllocationAccount("208041"); //whsF.SetAllocationAccount("208041"); //whsLT.SetAllocationAccount("208041"); int result = grpo.Add(); shopwhs.RevertInitialAccounts(); //whsF.RevertInitialAccounts(); //whsLT.RevertInitialAccounts(); // Refreeze items foreach (string itemcode in frozenItems) { var item = new Item(sap, itemcode); item.oItem.Frozen = BoYesNoEnum.tNO; item.oItem.Update(); Console.WriteLine($"{itemcode} has reverted back to frozen."); } // Re-unpurchase items foreach (string itemcode in unpurchasableItems) { var item = new Item(sap, itemcode); item.oItem.PurchaseItem = BoYesNoEnum.tNO; item.oItem.Update(); Console.WriteLine($"{itemcode} has reverted back to unpurchasable."); } return(result); }
public bool LoadKSDeliveryNote(SAP sapks, int docentry) { oDeliveryNotes = (Documents)sapks.oCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes); return(oDeliveryNotes.GetByKey(docentry)); }
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 } } } } }
public bool LoadDraft(SAP sap, int docentry) { this.sap = sap; oDraft = (Documents)sap.oCompany.GetBusinessObject(BoObjectTypes.oDrafts); return(oDraft.GetByKey(docentry)); }
public static string CreateDraft(SAP sap, Invoice invoice, PriceModeDocumentEnum pricemode) { // Which price mode var lines = invoice.GetInvoicesByPriceMode(pricemode); string results = null; if (lines.Length > 0) { // Group by shop var shopitems = from i in lines group i by new { i.BaseCard, i.WhsCode } into g select new { Shop = g.Key.BaseCard, Whscode = g.Key.WhsCode, Items = g, DocDate = g.First().DocDate }; // Memory var shopItemsList = shopitems.ToArray(); // Create draft in SAP foreach (var shop in shopItemsList) { Documents delivery = (Documents)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts); Documents invoices = (Documents)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices); delivery.DocObjectCodeEx = "15"; // 15 = Delivery delivery.CardCode = shop.Shop; delivery.DocDate = shop.DocDate.Value; //delivery.BPL_IDAssignedToInvoice = 1; // Price mode delivery.PriceMode = pricemode; var items = shop.Items.ToArray(); //Console.WriteLine($"Creating draft for {shop.Shop}, items: {items.Count()}"); for (int i = 0; i < items.Count(); i++) { if (i > 0) { delivery.Lines.Add(); } // Items delivery.Lines.ItemCode = items[i].ItemCode; //delivery.Lines.Quantity = Convert.ToDouble(items[i].Quantity); delivery.Lines.Quantity = Convert.ToDouble(items[i].OpenQty.Value); delivery.Lines.WarehouseCode = shop.Whscode; delivery.Lines.UoMEntry = items[i].UomEntry.Value; // References delivery.Lines.BaseEntry = items[i].DocEntry; delivery.Lines.BaseLine = items[i].LineNum; delivery.Lines.BaseType = 13; // 13 = Invoices // Pricing if (pricemode == PriceModeDocumentEnum.pmdGross) { delivery.Lines.GrossPrice = Convert.ToDouble(items[i].GrossPrice.Value); } if (pricemode == PriceModeDocumentEnum.pmdNet) { delivery.Lines.UnitPrice = Convert.ToDouble(items[i].NetPrice.Value); } } int result = delivery.Add(); if (result != 0) { results = results + sap.oCompany.GetLastErrorDescription() + Environment.NewLine; } else { int newDocEntry = int.Parse(sap.oCompany.GetNewObjectKey()); DeliveryDraftsTaskList.Add(newDocEntry); results = results + "OK - " + sap.oCompany.GetNewObjectKey() + Environment.NewLine; } } } else { results = "No invoices for " + pricemode + "."; } return(results); }
public Item(SAP sap, string itemcode) { oItem = (Items)sap.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems); oItem.GetByKey(itemcode); }
public static int AllocateBatchesBins(this Documents doc, SAP sap) { var allocator = new BatchBinAllocation(); List <string> frozenItems = new List <string>(); var lines = doc.Lines; for (int i = 0; i < lines.Count; i++) { lines.SetCurrentLine(i); // Item info var item = new Item(sap, lines.ItemCode); // Unfreeze items if (item.oItem.Frozen == BoYesNoEnum.tYES) { item.oItem.Frozen = BoYesNoEnum.tNO; if (item.oItem.Update() == 0) { frozenItems.Add(lines.ItemCode); } } // Inventory item if (item.oItem.InventoryItem == BoYesNoEnum.tYES) { // Managed by batches if (item.oItem.ManageBatchNumbers == BoYesNoEnum.tYES) { BatchBinAllocation.BatchAllocationItem[] batchesAvailable; switch (sap.oCompany.CompanyDB) { default: // Longdan batchesAvailable = allocator.AllocateBatches(lines.ItemCode, lines.WarehouseCode, lines.InventoryQuantity)?.ToArray(); break; case "KIMSON-Newton": batchesAvailable = allocator.AllocateBatches_KS(lines.ItemCode, lines.WarehouseCode, lines.InventoryQuantity)?.ToArray(); break; } // If there are batches available if (batchesAvailable != null && batchesAvailable.Count() > 0) { for (int j = 0; j < batchesAvailable.Count(); j++) { if (j > 0) { lines.BatchNumbers.Add(); } lines.BatchNumbers.BatchNumber = batchesAvailable[j].BatchNumber; lines.BatchNumbers.Quantity = batchesAvailable[j].InvQuantity; lines.BatchNumbers.BaseLineNumber = lines.LineNum; // Bins BatchBinAllocation.BinAllocationItem[] binsAvailable; switch (sap.oCompany.CompanyDB) { default: // Longdan binsAvailable = batchesAvailable[j].AllocateBins(allocator.BinCumulation2).ToArray(); break; case "KIMSON-Newton": binsAvailable = batchesAvailable[j].AllocateBins_KS(allocator.BinCumulation2).ToArray(); break; } for (int k = 0; k < binsAvailable.Count(); k++) { if (k > 0) { lines.BinAllocations.Add(); } lines.BinAllocations.BaseLineNumber = lines.LineNum; lines.BinAllocations.BinAbsEntry = binsAvailable[k].BinAbsEntry; lines.BinAllocations.Quantity = binsAvailable[k].InvQuantity; lines.BinAllocations.SerialAndBatchNumbersBaseLine = j; // Tracking allocator.BinCumulation2.Add(new BatchBinAllocation.BinAllocationItem { BatchAbsEntry = binsAvailable[k].BatchAbsEntry, BinAbsEntry = binsAvailable[k].BinAbsEntry, BinCode = binsAvailable[k].BinCode, InvQuantity = binsAvailable[k].InvQuantity }); } } } } } } int result = doc.Update(); // Unfreeze items foreach (string itemcode in frozenItems) { var item = new Item(sap, itemcode); item.oItem.Frozen = BoYesNoEnum.tNO; item.oItem.Update(); Console.WriteLine($"{itemcode} has reverted back to frozen."); } return(result); }