/// <summary> ///Save,保存方法,先删除,再增加 /// </summary> public void Save(CurrentStock model, SqlTransaction tran = null, params string[] str) { string tran_flag = "1"; SqlConnection conn = new SqlConnection(Dal.DataHelper.constr); conn.Open(); if (tran == null) { tran_flag = "0"; tran = conn.BeginTransaction(); } try { Delete(model, tran, str); Add(model, tran); //如果传入事物,提交否则外层提交 if (tran_flag == "0") { tran.Commit(); conn.Close(); } } catch (Exception e) { if (tran_flag == "0") { tran.Rollback(); conn.Close(); } throw e; } }
public CurrentStock Get(int id) { logger.Info("start current stock: "); CurrentStock ass = new CurrentStock(); try { var identity = User.Identity as ClaimsIdentity; int compid = 0, userid = 0; // Access claims //foreach (Claim claim in identity.Claims) //{ // if (claim.Type == "compid") // { // compid = int.Parse(claim.Value); // } // if (claim.Type == "userid") // { // userid = int.Parse(claim.Value); // } //} logger.Info("User ID : {0} , Company Id : {1}", compid, userid); ass = context.GetCurrentStock(id); logger.Info("End current stock: "); return(ass); } catch (Exception ex) { logger.Error("Error in current stock" + ex.Message); logger.Info("End current stock: "); return(null); } }
public override global::System.Data.DataSet Clone() { CurrentStock cln = ((CurrentStock)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
//检查写入 current public void CurrentStockCheckAdd(string cinvcode, string cwhcode, string constr) { DataTable dt = U8DataHelper.GetDataTable(constr, @"select * from currentstock where cWhCode = '" + cwhcode + "' and cInvCode = '" + cinvcode + "'"); if (dt.Rows.Count < 1)//如果没有,写入 { DataTable dtitem = U8DataHelper.GetDataTable(constr, @"select * from SCM_Item where cinvcode = '" + cinvcode + "'"); CurrentStock m = new CurrentStock(); m.cWhCode = cwhcode; m.cInvCode = cinvcode; m.ItemId = int.Parse(dtitem.Rows[0]["Id"].ToString()); m.cBatch = ""; m.cVMIVenCode = ""; m.iSoType = 0; m.iSodid = ""; m.iQuantity = 0; m.iNum = 0; m.cFree1 = ""; m.cFree2 = ""; m.fOutQuantity = 0; m.fOutNum = 0; m.fInQuantity = 0; m.fInNum = 0; m.cFree3 = ""; m.cFree4 = ""; m.cFree5 = ""; m.cFree6 = ""; m.cFree7 = ""; m.cFree8 = ""; m.cFree9 = ""; m.cFree10 = ""; m.bStopFlag = false; m.fTransInQuantity = 0; m.fTransInNum = 0; m.fTransOutQuantity = 0; m.fTransOutNum = 0; m.fPlanQuantity = 0; m.fPlanNum = 0; m.fDisableQuantity = 0; m.fDisableNum = 0; m.fAvaQuantity = 0; m.fAvaNum = 0; m.BGSPSTOP = false; m.fStopQuantity = 0; m.fStopNum = 0; m.cCheckState = ""; m.iExpiratDateCalcu = 0; m.ipeqty = 0; m.ipenum = 0; new CurrentStockDal().Add2(m, constr); } }
public HttpResponseMessage addSkFree(SKFreeItem item) { logger.Info("start Return: "); try { var identity = User.Identity as ClaimsIdentity; int compid = 0, userid = 0; foreach (Claim claim in identity.Claims) { if (claim.Type == "compid") { compid = int.Parse(claim.Value); } if (claim.Type == "userid") { userid = int.Parse(claim.Value); } } ItemMaster it = context.itemMasters.Where(t => t.ItemId == item.ItemId).SingleOrDefault(); if (it != null) { item.CreationDate = indianTime; item.itemname = it.SellingUnitName; item.itemNumber = it.Number; item.SellingSku = it.SellingSku; item.Deleted = false; CurrentStock stok = context.DbCurrentStock.Where(x => x.ItemNumber == item.itemNumber && x.Warehouseid == item.WarehouseId).SingleOrDefault(); if (stok != null) { stok.CurrentInventory = stok.CurrentInventory - item.TotalQuantity; if (stok.CurrentInventory < 0) { stok.CurrentInventory = 0; } context.DbCurrentStock.Attach(stok); context.Entry(stok).State = EntityState.Modified; context.SaveChanges(); context.SKFreeItemDb.Add(item); context.SaveChanges(); } else { return(Request.CreateResponse(HttpStatusCode.OK, "item Addition Failed")); } } return(Request.CreateResponse(HttpStatusCode.OK, item)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public void Load(IEnergyDrink item) { if (CurrentStock.Count >= Capacity) { Console.WriteLine($"The vending machine is full. The {item.Name} cannot be added."); } else { CurrentStock.Add(item); } }
public void Load(IReadyMeal item) { if (CurrentStock.Count >= Capacity) { Console.WriteLine("The vending machine is full. No more products can be added."); } else { CurrentStock.Add(item); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { CurrentStock ds = new CurrentStock(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public IList <PurchaseList> Get(int wid) { try//|| a.Status == "Process" { var poList = (from a in db.DbOrderDetails where (a.Status == "Pending" || a.Status == "Process") && a.Deleted == false join i in db.itemMasters on a.ItemId equals i.ItemId select new PurchaseOrderList { OrderDetailsId = a.OrderDetailsId, Warehouseid = a.Warehouseid, WarehouseName = a.WarehouseName, OrderDate = a.OrderDate, SupplierId = i.SupplierId, PurchaseSku = i.PurchaseSku, SupplierName = i.SupplierName, OrderId = a.OrderId, ItemId = a.ItemId, SKUCode = i.Number, ItemName = i.itemname, PurchaseUnitName = i.PurchaseUnitName, Unit = i.SellingUnitName, Conversionfactor = i.PurchaseMinOrderQty, Discription = "", qty = a.qty, //CurrentInventory = c == null ? 0 : c.CurrentInventory, StoringItemName = i.StoringItemName, Price = i.PurchasePrice, NetAmmount = a.NetAmmount, TaxPercentage = a.TaxPercentage, TaxAmount = a.TaxAmmount, TotalAmountIncTax = a.TotalAmt, PurchaseMinOrderQty = i.PurchaseMinOrderQty, Status = a.Status, CreationDate = a.CreatedDate, Deleted = a.Deleted }).ToList(); List <PurchaseList> uniquelist = new List <PurchaseList>(); foreach (PurchaseOrderList item in poList) { int count = 0; //01AE101110 PurchaseList l = uniquelist.Where(x => x.PurchaseSku == item.PurchaseSku).SingleOrDefault(); if (l == null) { count += 1; l = new PurchaseList(); l.name = item.PurchaseUnitName; l.conversionfactor = item.Conversionfactor; l.Supplier = item.SupplierName; l.SupplierId = item.SupplierId; l.WareHouseId = item.Warehouseid; l.WareHouseName = item.WarehouseName; l.OrderDetailsId = item.OrderDetailsId; l.itemNumber = item.SKUCode; l.PurchaseSku = item.PurchaseSku; l.orderIDs = item.OrderDetailsId + "," + l.orderIDs; l.ItemId = item.ItemId; l.ItemName = item.ItemName; l.qty = l.qty + item.qty; l.currentinventory = item.CurrentInventory; l.Price = item.Price; uniquelist.Add(l); } else { l.orderIDs = item.OrderDetailsId + "," + l.orderIDs; l.qty = l.qty + item.qty; uniquelist.First(d => d.PurchaseSku == item.PurchaseSku).qty = l.qty; uniquelist.First(d => d.PurchaseSku == item.PurchaseSku).orderIDs = l.orderIDs; } } List <PurchaseList> cc = new List <PurchaseList>(); foreach (PurchaseList l in uniquelist) { CurrentStock cs = db.DbCurrentStock.Where(k => k.ItemNumber == l.itemNumber && k.Deleted == false && k.Warehouseid == l.WareHouseId).SingleOrDefault(); if (cs != null) { l.currentinventory = cs.CurrentInventory; if (l.qty > cs.CurrentInventory) { l.qty = l.qty - cs.CurrentInventory; List <PurchaseOrderDetailRecived> po = db.PurchaseOrderRecivedDetails.Where(x => x.ItemId == l.ItemId && x.Status != "Received").ToList(); List <PurchaseOrderDetail> po1 = db.DPurchaseOrderDeatil.Where(x => x.ItemId == l.ItemId && x.Status == "ordered").ToList(); if (po.Count != 0 && po1.Count != 0) { foreach (var p in po) { l.qty = l.qty - Convert.ToInt32((p.PurchaseQty - p.QtyRecived) * p.MOQ); } foreach (var p1 in po1) { l.qty = l.qty - Convert.ToInt32(p1.PurchaseQty * p1.MOQ); } if (l.qty > 0) { cc.Add(l); } } else if (po.Count != 0 && po1.Count == 0) { foreach (var p in po) { l.qty = l.qty - Convert.ToInt32((p.PurchaseQty - p.QtyRecived) * p.MOQ); } if (l.qty > 0) { cc.Add(l); } } else if (po.Count == 0 && po1.Count != 0) { foreach (var p in po1) { l.qty = l.qty - Convert.ToInt32(p.PurchaseQty * p.MOQ); } if (l.qty > 0) { cc.Add(l); } } else { cc.Add(l); } } } } return(cc); } catch (Exception ex) { logger.Error("Error in getting Company " + ex.Message); return(null); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); CurrentStock ds = new CurrentStock(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "ItemMasterItemDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public ActionResult SaveUpdateSaleRet(SaleRetMain SaleRet, List <SaleRetDetail> SaleRetDetail, string IsSave) { using (var transaction = new TransactionScope()) { try { RBACUser rUser = new RBACUser(Session["UserName"].ToString()); #region for Sales Return transection string trnType = "Save"; string Msg = "1"; //Firstly deleted the saved For Update if (IsSave == "1") { if (!rUser.HasPermission("SalesReturn_Update")) { return(Json("U", JsonRequestBehavior.AllowGet)); } trnType = "Update"; Msg = "2"; #region For AVP OR LOT if (Session["MaintLot"].ToString() == "True") { var sRetMain = _saleRetMainService.All().Where(s => s.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault(); var sRetDetail = _saleRetDetailService.All().Where(s => s.SaleRetId == sRetMain.SaleRetId).ToList(); foreach (var currentItem in sRetDetail) { var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode && m.LocCode == SaleRet.LocNo && m.LotNo == currentItem.LotNo); if (currentStocks != null) { currentStocks.CurrQty = currentStocks.CurrQty - currentItem.ReturnQty; currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice); _currentStockService.Update(currentStocks); } } } else { // For Costledger Code } #endregion var saleRetDel = _saleRetMainService.All().ToList().Where(y => y.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault(); _saleRetDetailService.All().ToList().Where(y => y.SaleRetId == saleRetDel.SaleRetId).ToList().ForEach(x => _saleRetDetailService.Delete(x)); _saleRetDetailService.Save(); _saleRetMainService.Delete(saleRetDel); _saleRetMainService.Save(); var rcvDel = _receiveMainService.All().ToList().Where(y => y.ChallanNo == SaleRet.ChallanNo && y.RefNo == SaleRet.SaleRetNo && y.VchrNo == SaleRet.VchrNo).FirstOrDefault(); _receiveDetailService.All().ToList().Where(y => y.RcvNo == rcvDel.RcvNo).ToList().ForEach(x => _receiveDetailService.Delete(x)); _receiveDetailService.Save(); _receiveMainService.Delete(rcvDel); _receiveMainService.Save(); } if (!rUser.HasPermission("SalesReturn_Insert")) { return(Json("X", JsonRequestBehavior.AllowGet)); } var IfExist = _saleRetMainService.All().Where(x => x.SaleRetNo == SaleRet.SaleRetNo).FirstOrDefault(); if (IfExist == null) { SaleRet.FinYear = Session["FinYear"].ToString(); SaleRet.BranchCode = Session["BranchCode"].ToString(); SaleRet.ProjCode = Session["ProjCode"].ToString(); SaleRet.EntryDateTime = DateTime.Now; _saleRetMainService.Add(SaleRet); _saleRetMainService.Save(); if (SaleRetDetail != null) { foreach (var sRetDExtItem in SaleRetDetail) { SaleRetDetail sRetDetail = new SaleRetDetail(); var srID = _saleRetMainService.All().Select(s => s.SaleRetId).LastOrDefault(); if (srID == null) { sRetDExtItem.SaleRetId = 1; } else { sRetDExtItem.SaleRetId = srID; } sRetDetail = sRetDExtItem; _saleRetDetailService.Add(sRetDetail); } } _saleRetDetailService.Save(); #region for Receive transection //var ExistRcv = _receiveMainService.All().Where(x => x.RcvNo == SaleRet.SaleRetNo).FirstOrDefault(); var rcvNo = _receiveMainService.All().Select(s => Convert.ToInt32(s.RcvNo)).LastOrDefault() + 1; //if (ExistRcv == null) //{ var todayDate = DateTime.Now; ReceiveMain recvMain = new ReceiveMain(); recvMain.RcvNo = "0" + rcvNo.ToString(); recvMain.BranchCode = Session["BranchCode"].ToString(); recvMain.RcvDate = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); recvMain.Source = SaleRet.CustCode; recvMain.ChallanNo = SaleRet.ChallanNo; recvMain.RefNo = SaleRet.SaleRetNo; recvMain.RefDate = (DateTime)SaleRet.SaleRetDate; recvMain.Remarks = SaleRet.Remarks; recvMain.AppByCode = SaleRet.ApprBy; recvMain.RcvdTime = DateTime.Now; recvMain.StoreLocCode = SaleRet.LocNo; recvMain.RecvFromSubCode = SaleRet.CustCode; recvMain.VchrNo = SaleRet.VchrNo; recvMain.FinYear = Session["FinYear"].ToString(); recvMain.GLPost = false; recvMain.RcvdDate = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); recvMain.expenseStatus = false; recvMain.CreditPur = false; double amount = 0.0; List <ReceiveDetails> receveDetailsList = new List <ReceiveDetails>(); foreach (var recvDetailsItem in SaleRetDetail) { ReceiveDetails receivDetails = new ReceiveDetails(); receivDetails.RcvNo = "0" + rcvNo.ToString(); receivDetails.ItemCode = recvDetailsItem.ItemCode; receivDetails.SubCode = SaleRet.CustCode; receivDetails.Description = recvDetailsItem.Description; receivDetails.Qty = recvDetailsItem.ReturnQty; receivDetails.Price = Convert.ToDouble(recvDetailsItem.UnitPrice); receivDetails.ExQty = recvDetailsItem.ReturnQty; receivDetails.LotNo = recvDetailsItem.LotNo; amount = amount + Convert.ToDouble((recvDetailsItem.ReturnQty * recvDetailsItem.UnitPrice)); receveDetailsList.Add(receivDetails); } recvMain.Amount = amount; #region For AVP OR LOT if (Session["MaintLot"].ToString() == "True") { foreach (var currentItem in SaleRetDetail) { var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode && m.LocCode == recvMain.StoreLocCode && m.LotNo == currentItem.LotNo); if (currentStocks != null) { currentStocks.CurrQty = currentItem.ReturnQty + currentStocks.CurrQty; currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice); _currentStockService.Update(currentStocks); } else { CurrentStock currStock = new CurrentStock(); currStock.LocCode = SaleRet.LocNo; currStock.LotNo = currentItem.LotNo; currStock.ItemCode = currentItem.ItemCode; currStock.CurrQty = currentItem.ReturnQty; currStock.UnitPrice = Convert.ToDouble(currentItem.UnitPrice); _currentStockService.Add(currStock); } var lotNO = _lotDtService.All().ToList().Where(m => m.LotNo == currentItem.LotNo).FirstOrDefault(); if (lotNO == null) { LotDT lotDt = new LotDT(); lotDt.LotNo = currentItem.LotNo; lotDt.LotDate = SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); lotDt.RefNo = SaleRet.SaleRetNo; lotDt.RefSource = "Sales Return Receive"; _lotDtService.Add(lotDt); } } } else { #region AVP foreach (var cItem in SaleRetDetail) { CostLedger cLedger = new CostLedger(); cLedger.RecQty = cItem.ReturnQty; cLedger.RecRate = Convert.ToDouble(cItem.UnitPrice); cLedger.RecTotal = System.Math.Round(cLedger.RecQty * cLedger.RecRate, 2); double CurrQty = 0, BalTotal = 0; var existCurrStoc = CostLedgerAppService.All().Where(x => x.ItemCode == cItem.ItemCode && x.LocNo == recvMain.StoreLocCode.Trim()).ToList(); if (existCurrStoc.Count != 0) { var date = existCurrStoc.Max(x => x.TrDate); var existCurrStock = CostLedgerAppService.All().OrderByDescending(s => s.RecId).Where(x => x.ItemCode == cItem.ItemCode && x.LocNo == recvMain.StoreLocCode.Trim() && x.TrDate == date).ToList(); foreach (var item in existCurrStock) { CurrQty = item.BalQty; BalTotal = item.BalTotal; } } cLedger.IssQty = 0; cLedger.IssRate = 0; cLedger.IssTotal = 0; cLedger.BalQty = CurrQty + cLedger.RecQty; if (cLedger.BalQty != 0) { cLedger.BalRate = (BalTotal + cLedger.RecTotal) / cLedger.BalQty; } else { cLedger.BalRate = 0; } cLedger.BalRate = System.Math.Round(cLedger.BalRate, 2); cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2); cLedger.LocNo = recvMain.StoreLocCode; cLedger.ItemCode = cItem.ItemCode; cLedger.TrDate = (DateTime)SaleRet.SaleRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); cLedger.UpdSrcNo = SaleRet.SaleRetNo; cLedger.UpdSrc = "SR"; CostLedgerAppService.Add(cLedger); } CostLedgerAppService.Save(); #endregion } #endregion recvMain.RcvDetails = receveDetailsList; _receiveMainService.Add(recvMain); _currentStockService.Save(); _receiveMainService.Save(); //} #endregion TransactionLogService.SaveTransactionLog(_transactionLogService, "Sales Return", trnType, rcvNo.ToString(), Session["UserName"].ToString()); //LoadDropDown.ProvitionInvRSave("IR", "I", recvInfo.RcvNo, recvInfo.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), recvMain.RcvDate.ToString("yyyy-MM-dd"), Session["UserName"].ToString()); transaction.Complete(); return(Json(new { Msg = Msg }, JsonRequestBehavior.AllowGet)); } else { transaction.Dispose(); return(Json("3", JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { transaction.Dispose(); return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet)); } } }
public List <OrderDispatchedDetails> add(List <OrderDispatchedDetails> po) { bool isDiscount = false; //bool isBaseWithoutChild = false; double finaltotal = 0; double finalTaxAmount = 0; double finalSGSTTaxAmount = 0; double finalCGSTTaxAmount = 0; double finalGrossAmount = 0; double finalTotalTaxAmount = 0; foreach (OrderDispatchedDetails pc in po) { ItemMaster items = db.itemMasters.Where(x => x.ItemId == pc.ItemId).Select(x => x).FirstOrDefault(); OrderMaster om = db.DbOrderMaster.Where(x => x.OrderId == pc.OrderId && x.Deleted == false).FirstOrDefault(); om.Status = "Ready to Dispatch"; db.DbOrderMaster.Attach(om); db.Entry(om).State = EntityState.Modified; db.SaveChanges(); if (pc != null && pc.isDeleted != true) { ItemMaster master = db.itemMasters.Where(c => c.ItemId == pc.ItemId).SingleOrDefault(); CurrentStock item = db.DbCurrentStock.Where(x => x.ItemNumber == master.Number && x.Warehouseid == pc.Warehouseid).SingleOrDefault(); if (item != null) { CurrentStockHistory Oss = new CurrentStockHistory(); if (item != null) { Oss.StockId = item.StockId; Oss.ItemNumber = item.ItemNumber; Oss.ItemName = item.ItemName; Oss.OdOrPoId = pc.OrderId; Oss.CurrentInventory = item.CurrentInventory; Oss.InventoryOut = Convert.ToInt32(pc.qty); Oss.TotalInventory = Convert.ToInt32(item.CurrentInventory - pc.qty); Oss.WarehouseName = item.WarehouseName; Oss.CreationDate = DateTime.Now; db.CurrentStockHistoryDb.Add(Oss); int id = db.SaveChanges(); } item.CurrentInventory = Convert.ToInt32(item.CurrentInventory - pc.qty); context.UpdateCurrentStock(item); } var ord = db.DbOrderDetails.Where(r => r.OrderDetailsId == pc.OrderDetailsId).SingleOrDefault(); ord.Status = "Ready to Dispatch"; ord.DiscountPercentage = pc.DiscountPercentage; db.DbOrderDetails.Attach(ord); db.Entry(ord).State = EntityState.Modified; db.SaveChanges(); // calculation var od = new OrderDispatchedDetails(); od.OrderDispatchedDetailsId = pc.OrderDispatchedDetailsId; if (pc.DiscountPercentage == 0) { isDiscount = false; } else { isDiscount = true; } od.DiscountPercentage = pc.DiscountPercentage; od.OrderDetailsId = pc.OrderDetailsId; od.OrderId = pc.OrderId; od.OrderDispatchedMasterId = pc.OrderDispatchedMasterId; od.CustomerId = pc.CustomerId; od.CustomerName = pc.CustomerName; od.City = pc.City; od.Mobile = pc.Mobile; od.OrderDate = pc.OrderDate; od.CompanyId = pc.CompanyId; od.CityId = pc.CityId; od.Warehouseid = pc.Warehouseid; od.WarehouseName = pc.WarehouseName; od.CategoryName = pc.CategoryName; od.ItemId = pc.ItemId; od.Itempic = pc.Itempic; od.itemname = pc.itemname; od.SubcategoryName = pc.SubcategoryName; od.SubsubcategoryName = pc.SubsubcategoryName; od.itemcode = pc.itemcode; od.Barcode = pc.Barcode; od.UnitPrice = pc.UnitPrice; od.Purchaseprice = pc.Purchaseprice; od.MinOrderQty = pc.MinOrderQty; od.MinOrderQtyPrice = pc.MinOrderQtyPrice; od.qty = pc.qty; od.price = pc.price; od.MinOrderQty = pc.MinOrderQty; int MOQ = items.MinOrderQty; od.MinOrderQtyPrice = MOQ * items.UnitPrice; od.price = items.price; od.MinOrderQty = items.MinOrderQty; od.MinOrderQtyPrice = MOQ * items.UnitPrice; od.qty = Convert.ToInt32(pc.qty); od.SizePerUnit = pc.SizePerUnit; int qty = 0; if (master != null) { qty = Convert.ToInt32(pc.qty); } else { qty = Convert.ToInt32(od.qty); } od.TaxPercentage = items.TotalTaxPercentage; if (od.TaxPercentage >= 0) { od.SGSTTaxPercentage = od.TaxPercentage / 2; od.CGSTTaxPercentage = od.TaxPercentage / 2; } od.HSNCode = items.HSNCode; //........CALCULATION FOR NEW SHOPKIRANA............................. od.Noqty = qty; // for total qty (no of items) // STEP 1 (UNIT PRICE * QTY) - SHOW PROPERTY od.TotalAmt = System.Math.Round(pc.UnitPrice * qty, 2); // STEP 2 (AMOUT WITHOU TEX AND WITHOUT DISCOUNT ) - SHOW PROPERTY od.AmtWithoutTaxDisc = ((100 * od.UnitPrice * qty) / (1 + od.TaxPercentage / 100)) / 100; // STEP 3 (AMOUNT WITHOUT TAX AFTER DISCOUNT) - UNSHOW PROPERTY od.AmtWithoutAfterTaxDisc = (100 * od.AmtWithoutTaxDisc) / (100 + od.DiscountPercentage); //STEP 4 (TAX AMOUNT) - UNSHOW PROPERTY od.TaxAmmount = (od.AmtWithoutAfterTaxDisc * od.TaxPercentage) / 100; if (od.TaxAmmount >= 0) { od.SGSTTaxAmmount = od.TaxAmmount / 2; od.CGSTTaxAmmount = od.TaxAmmount / 2; } //STEP 5(TOTAL TAX AMOUNT) - UNSHOW PROPERTY od.TotalAmountAfterTaxDisc = od.AmtWithoutAfterTaxDisc + od.TaxAmmount; //...............Calculate Discount............................. //od.DiscountPercentage = items.PramotionalDiscount; od.DiscountAmmount = 0; // double DiscountAmmount = od.DiscountAmmount; // double NetAmtAfterDis = (od.NetAmmount - DiscountAmmount); od.NetAmtAfterDis = 0; //double TaxAmmount = od.TaxAmmount; //................................................................... //od.UnitId = items.UnitId; //od.Unitname = items.UnitName; od.Purchaseprice = items.price; //od.VATTax = items.VATTax; od.CreatedDate = Convert.ToDateTime(pc.CreatedDate); od.UpdatedDate = Convert.ToDateTime(pc.CreatedDate); od.Deleted = false; od.Status = "Ready to Dispatch"; od.QtyChangeReason = pc.QtyChangeReason; od.itemNumber = pc.itemNumber; context.AddOrderDispatchedDetails(od); finaltotal = finaltotal + od.TotalAmt; finalTaxAmount = finalTaxAmount + od.TaxAmmount; finalSGSTTaxAmount = finalSGSTTaxAmount + od.SGSTTaxAmmount; finalCGSTTaxAmount = finalCGSTTaxAmount + od.CGSTTaxAmmount; finalGrossAmount = finalGrossAmount + od.TotalAmountAfterTaxDisc; finalTotalTaxAmount = finalTotalTaxAmount + od.TotalAmountAfterTaxDisc; } else { } } int masterid = Convert.ToInt32(po[0].OrderDispatchedMasterId); OrderDispatchedMaster ODM = db.OrderDispatchedMasters.Where(x => x.OrderDispatchedMasterId == masterid).FirstOrDefault(); finaltotal = finaltotal + ODM.deliveryCharge; finalGrossAmount = finalGrossAmount + ODM.deliveryCharge; if (ODM.WalletAmount > 0) { ODM.TotalAmount = System.Math.Round(finaltotal, 2) - ODM.WalletAmount.GetValueOrDefault(); ODM.TaxAmount = System.Math.Round(finalTaxAmount, 2); ODM.SGSTTaxAmmount = System.Math.Round(finalSGSTTaxAmount, 2); ODM.CGSTTaxAmmount = System.Math.Round(finalCGSTTaxAmount, 2); ODM.GrossAmount = System.Math.Round((Convert.ToInt32(finalGrossAmount) - ODM.WalletAmount.GetValueOrDefault()), 0); } else { ODM.TotalAmount = System.Math.Round(finaltotal, 2); ODM.TaxAmount = System.Math.Round(finalTaxAmount, 2); ODM.SGSTTaxAmmount = System.Math.Round(finalSGSTTaxAmount, 2); ODM.CGSTTaxAmmount = System.Math.Round(finalCGSTTaxAmount, 2); ODM.GrossAmount = System.Math.Round((finalGrossAmount), 0); } if (isDiscount == true) { ODM.DiscountAmount = finalTotalTaxAmount - finaltotal; } else { ODM.DiscountAmount = 0; } db.OrderDispatchedMasters.Attach(ODM); db.Entry(ODM).State = EntityState.Modified; db.SaveChanges(); try { var FreeItemList = db.SKFreeItemDb.Where(f => f.OrderId == po[0].OrderId).ToList(); foreach (var freeitem in FreeItemList) { CurrentStock itemms = db.DbCurrentStock.Where(x => x.ItemNumber == freeitem.itemNumber).SingleOrDefault(); if (itemms != null) { itemms.CurrentInventory = Convert.ToInt32(itemms.CurrentInventory + (freeitem.TotalQuantity)); context.UpdateCurrentStock(itemms); } } } catch (Exception ex) { } return(po); }
public HttpResponseMessage add(PurchaseReturn item) { logger.Info("start Return: "); try { var identity = User.Identity as ClaimsIdentity; int compid = 0, userid = 0; foreach (Claim claim in identity.Claims) { if (claim.Type == "compid") { compid = int.Parse(claim.Value); } if (claim.Type == "userid") { userid = int.Parse(claim.Value); } } if (item != null) { item.CreationDate = indianTime; item.Deleted = false; CurrentStock stok = context.DbCurrentStock.Where(x => x.ItemNumber == item.itemNumber && x.Warehouseid == item.WarehouseId).SingleOrDefault(); if (stok != null) { CurrentStockHistory Oss = new CurrentStockHistory(); if (stok != null) { Oss.StockId = stok.StockId; Oss.ItemNumber = stok.ItemNumber; Oss.ItemName = stok.ItemName; Oss.CurrentInventory = stok.CurrentInventory; Oss.OdOrPoId = item.PurchaseReturnId; Oss.PurchaseInventoryOut = Convert.ToInt32(item.TotalQuantity); Oss.TotalInventory = Convert.ToInt32(stok.CurrentInventory - item.TotalQuantity); Oss.WarehouseName = stok.WarehouseName; Oss.CreationDate = indianTime; context.CurrentStockHistoryDb.Add(Oss); int idd = context.SaveChanges(); } stok.CurrentInventory = stok.CurrentInventory - item.TotalQuantity; if (stok.CurrentInventory < 0) { stok.CurrentInventory = 0; } context.DbCurrentStock.Attach(stok); context.Entry(stok).State = EntityState.Modified; context.SaveChanges(); context.PurchaseReturnDb.Add(item); context.SaveChanges(); } else { return(Request.CreateResponse(HttpStatusCode.OK, "item Updation Failed")); } } return(Request.CreateResponse(HttpStatusCode.OK, item)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public List <ReturnOrderDispatchedDetails> add(List <ReturnOrderDispatchedDetails> po) { int Oid = po[0].OrderId; List <OrderDispatchedDetails> dispatchedobj = new List <OrderDispatchedDetails>(); dispatchedobj = db.OrderDispatchedDetailss.Where(x => x.OrderId == Oid).ToList(); List <FinalOrderDispatchedDetails> Finalobj = new List <FinalOrderDispatchedDetails>(); try { for (var i = 0; i < dispatchedobj.Count; i++) { for (var k = 0; k < po.Count; k++) { if (po[k].isDeleted != true && dispatchedobj[i].ItemId == po[k].ItemId) { dispatchedobj[i].qty = dispatchedobj[i].qty - po[k].qty; var itemIDmaster = dispatchedobj[i].ItemId; ItemMaster items = db.itemMasters.Where(x => x.ItemId == itemIDmaster).Select(x => x).FirstOrDefault(); FinalOrderDispatchedDetails newfinal = new FinalOrderDispatchedDetails(); newfinal.OrderDispatchedDetailsId = dispatchedobj[i].OrderDispatchedDetailsId; newfinal.OrderDetailsId = dispatchedobj[i].OrderDetailsId; newfinal.OrderId = dispatchedobj[i].OrderId; newfinal.OrderDispatchedMasterId = dispatchedobj[i].OrderDispatchedMasterId; newfinal.CustomerId = dispatchedobj[i].CustomerId; newfinal.CustomerName = dispatchedobj[i].CustomerName; newfinal.City = dispatchedobj[i].City; newfinal.Mobile = dispatchedobj[i].Mobile; newfinal.OrderDate = dispatchedobj[i].OrderDate; newfinal.CompanyId = dispatchedobj[i].CompanyId; newfinal.CityId = dispatchedobj[i].CityId; newfinal.Warehouseid = dispatchedobj[i].Warehouseid; newfinal.WarehouseName = dispatchedobj[i].WarehouseName; newfinal.CategoryName = dispatchedobj[i].CategoryName; newfinal.ItemId = dispatchedobj[i].ItemId; newfinal.Itempic = dispatchedobj[i].Itempic; newfinal.itemname = dispatchedobj[i].itemname; newfinal.itemcode = dispatchedobj[i].itemcode; newfinal.Barcode = dispatchedobj[i].Barcode; newfinal.UnitPrice = dispatchedobj[i].UnitPrice; newfinal.Purchaseprice = dispatchedobj[i].Purchaseprice; newfinal.MinOrderQty = dispatchedobj[i].MinOrderQty; newfinal.MinOrderQtyPrice = dispatchedobj[i].MinOrderQtyPrice; newfinal.qty = dispatchedobj[i].qty; newfinal.price = dispatchedobj[i].price; newfinal.MinOrderQty = dispatchedobj[i].MinOrderQty; int MOQ = dispatchedobj[i].MinOrderQty; newfinal.MinOrderQtyPrice = MOQ * dispatchedobj[i].UnitPrice; newfinal.qty = Convert.ToInt32(dispatchedobj[i].qty); int qty = 0; qty = Convert.ToInt32(newfinal.qty); newfinal.TaxPercentage = items.TotalTaxPercentage; //........CALCULATION FOR NEW SHOPKIRANA............................. newfinal.Noqty = qty; // for total qty (no of items) // STEP 1 (UNIT PRICE * QTY) - SHOW PROPERTY newfinal.TotalAmt = System.Math.Round(newfinal.UnitPrice * qty, 2); // STEP 2 (AMOUT WITHOU TEX AND WITHOUT DISCOUNT ) - SHOW PROPERTY newfinal.AmtWithoutTaxDisc = ((100 * newfinal.UnitPrice * qty) / (1 + newfinal.TaxPercentage / 100)) / 100; // STEP 3 (AMOUNT WITHOUT TAX AFTER DISCOUNT) - UNSHOW PROPERTY newfinal.AmtWithoutAfterTaxDisc = (100 * newfinal.AmtWithoutTaxDisc) / (100 + items.PramotionalDiscount); //STEP 4 (TAX AMOUNT) - UNSHOW PROPERTY newfinal.TaxAmmount = (newfinal.AmtWithoutAfterTaxDisc * newfinal.TaxPercentage) / 100; //STEP 5(TOTAL TAX AMOUNT) - UNSHOW PROPERTY newfinal.TotalAmountAfterTaxDisc = newfinal.AmtWithoutAfterTaxDisc + newfinal.TaxAmmount; //...............Calculate Discount............................. newfinal.DiscountPercentage = items.PramotionalDiscount; newfinal.DiscountAmmount = 0; newfinal.NetAmtAfterDis = 0; //................................................................... newfinal.Purchaseprice = items.price; //newfinal.VATTax = items.VATTax; newfinal.CreatedDate = Convert.ToDateTime(dispatchedobj[i].CreatedDate); newfinal.UpdatedDate = Convert.ToDateTime(dispatchedobj[i].CreatedDate); newfinal.Deleted = false; Finalobj.Add(newfinal); } } } foreach (FinalOrderDispatchedDetails x1 in Finalobj) { db = new AuthContext(); db.FinalOrderDispatchedDetailsDb.Add(x1); int id = db.SaveChanges(); } List <int> ItemIds = new List <int>(); foreach (ReturnOrderDispatchedDetails pc in po) { db = new AuthContext(); OrderMaster om = db.DbOrderMaster.Where(x => x.OrderId == pc.OrderId && x.Deleted == false).FirstOrDefault(); om.Status = "Order Canceled"; db.DbOrderMaster.Attach(om); db.Entry(om).State = EntityState.Modified; db.SaveChanges(); OrderDispatchedMaster odm = db.OrderDispatchedMasters.Where(x => x.OrderId == pc.OrderId && x.Deleted == false).FirstOrDefault(); odm.Status = "Order Canceled"; db.OrderDispatchedMasters.Attach(odm); db.Entry(odm).State = EntityState.Modified; db.SaveChanges(); //update stock ItemMaster master = db.itemMasters.Where(c => c.ItemId == pc.ItemId).SingleOrDefault(); CurrentStock itemm = db.DbCurrentStock.Where(x => x.ItemNumber == master.Number && x.Warehouseid == pc.Warehouseid).SingleOrDefault(); if (itemm != null && !ItemIds.Any(x => x == master.ItemId)) { CurrentStockHistory Oss = new CurrentStockHistory(); if (itemm != null) { Oss.StockId = itemm.StockId; Oss.ItemNumber = itemm.ItemNumber; Oss.ItemName = itemm.ItemName; Oss.CurrentInventory = itemm.CurrentInventory; Oss.OdOrPoId = pc.OrderId; Oss.OrderCancelInventoryIn = Convert.ToInt32(pc.qty); Oss.TotalInventory = Convert.ToInt32(itemm.CurrentInventory + pc.qty); Oss.WarehouseName = itemm.WarehouseName; Oss.CreationDate = DateTime.Now; db.CurrentStockHistoryDb.Add(Oss); int id = db.SaveChanges(); } itemm.CurrentInventory = Convert.ToInt32(itemm.CurrentInventory + (pc.qty)); context.UpdateCurrentStock(itemm); ItemIds.Add(master.ItemId); } var ord = db.DbOrderDetails.Where(r => r.OrderDetailsId == pc.OrderDetailsId).SingleOrDefault(); ord.Status = "Order Canceled"; db.DbOrderDetails.Attach(ord); db.Entry(ord).State = EntityState.Modified; db.SaveChanges(); db.AddReturnOrderDispatchedDetails(pc); } try { OrderMaster om = db.DbOrderMaster.Where(x => x.OrderId == Oid && x.Deleted == false).FirstOrDefault(); var rpoint = db.RewardPointDb.Where(c => c.CustomerId == om.CustomerId).FirstOrDefault(); if (rpoint != null) { if (om.RewardPoint > 0) { rpoint.EarningPoint -= om.RewardPoint; if (rpoint.EarningPoint < 0) { rpoint.EarningPoint = 0; } rpoint.UpdatedDate = indianTime; rpoint.TransactionDate = indianTime; db.RewardPointDb.Attach(rpoint); db.Entry(rpoint).State = EntityState.Modified; db.SaveChanges(); } } } catch (Exception ex) { } try { var FreeItemList = db.SKFreeItemDb.Where(f => f.OrderId == Oid).ToList(); foreach (var freeitem in FreeItemList) { CurrentStock itemms = db.DbCurrentStock.Where(x => x.ItemNumber == freeitem.itemNumber).SingleOrDefault(); if (itemms != null) { itemms.CurrentInventory = Convert.ToInt32(itemms.CurrentInventory + (freeitem.TotalQuantity)); context.UpdateCurrentStock(itemms); } } } catch (Exception ex) { } return(po); } catch (Exception exe) { return(null); } }
protected override void OnInitialize() { base.OnInitialize(); RxQuery(s => { return(s.Query <Catalog>() .Join(s.Query <Stock>(), catalog => catalog.Id, stock => stock.ProductId, (catalog, stock) => new { catalog, stock }) .Where(p => p.stock.Status == StockStatus.Available) .Select(c => c.catalog) .OrderBy(c => c.Name) .Distinct() .ToArray() .ToList()); }).Subscribe(Catalogs); Catalogs .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentCatalog.Value = (Catalogs.Value ?? Enumerable.Empty <Catalog>()).FirstOrDefault(); }); CurrentCatalog .Changed() .Select(_ => RxQuery(LoadAddressStock)) .Switch() .Subscribe(AddressStock, CloseCancellation.Token); AddressStock .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentAddressStock.Value = (AddressStock.Value ?? Enumerable.Empty <AddressStock>()).FirstOrDefault(); }); CurrentAddressStock .Changed() .Select(_ => RxQuery(LoadStoks)) .Switch() .Subscribe(Stocks, CloseCancellation.Token); Stocks .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentStock.Value = (Stocks.Value ?? Enumerable.Empty <Stock>()).FirstOrDefault(); }); CurrentStock .Changed() .Select(_ => RxQuery(LoadStockActions)) .Switch() .Subscribe(StockActions, CloseCancellation.Token); StockActions .Changed() .Throttle(TimeSpan.FromMilliseconds(30), Scheduler) .Subscribe(_ => { CurrentStockAction.Value = (StockActions.Value ?? Enumerable.Empty <StockAction>()).FirstOrDefault(); }); }
public void AssignOut(string strProduceSerialNo, OperLog operLog, string strWarehouse) { using (SqlConnection conn = ConnectionPool.BorrowConnection()) { //conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { string strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString(); DateTime dtSysTime = DateTime.Parse(strSysTime); string strsql1 = "SELECT * FROM tbProduceLog WHERE cnvcProduceState='6' and cnnProduceSerialNo=" + strProduceSerialNo; DataTable dtProduceLog = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql1); //rr.cndMakeDate = dtSysTime; //EntityMapping.Create(rr,trans); if (dtProduceLog.Rows.Count == 0) { throw new Exception("生产计划不在分货状态!"); } Entity.ProduceLog pl = new ProduceLog(dtProduceLog); string strsql2 = "select * from tbproducechecklog WHERE cnnAssignCount>0 and cnnproduceserialno=" + strProduceSerialNo; DataTable dtProduceCheckLog = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql2); if (dtProduceCheckLog.Rows.Count == 0) { throw new Exception("分货出库产品数量都为0"); } DataTable dtInv = SingleTableQuery.ExcuteQuery("tbInventory", trans); DataTable dtComputationUnit = SingleTableQuery.ExcuteQuery("tbComputationUnit", trans); string strsql3 = "select * from tbassignlog where cnnproduceserialno=" + strProduceSerialNo; DataTable dtAssignLog = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strsql3); if (dtAssignLog.Rows.Count == 0) { throw new Exception("未找到分货流水"); } Entity.AssignLog al = new AssignLog(dtAssignLog); Entity.RdRecord rr = new RdRecord(); rr.cnvcRdCode = "RD010"; rr.cnvcRdFlag = "0"; rr.cnvcWhCode = strWarehouse; rr.cnvcDepID = pl.cnvcProduceDeptID; //rr.cnvcOperName = operLog.cnvcop rr.cnvcComments = "分货出库"; rr.cnvcMaker = operLog.cnvcOperID; rr.cnnProorderID = pl.cnnProduceSerialNo; rr.cnvcState = "2"; rr.cndMakeDate = dtSysTime; long rrid = EntityMapping.Create(rr, trans); foreach (DataRow drProduceCheckLog in dtProduceCheckLog.Rows) { Entity.ProduceCheckLog pcl = new ProduceCheckLog(drProduceCheckLog); Entity.RdRecordDetail rrd = new RdRecordDetail(); rrd.cnvcFlag = "0"; rrd.cndExpDate = pcl.cndExpDate; //Convert.ToDateTime(this.txtProduceDate.Text).AddDays(pc.cnnDays).AddDays(Convert.ToDouble(txtDays.Text));//Convert.ToDateTime(this.txtExpDate.Text); rrd.cndMdate = pcl.cndMDate; //Convert.ToDateTime(this.txtProduceDate.Text); rrd.cnnRdID = Convert.ToDecimal(rrid); rrd.cnvcPOID = al.cnnAssignSerialNo.ToString(); DataRow[] drinvs = dtInv.Select("cnvcInvCode='" + pcl.cnvcInvCode + "'"); if (drinvs.Length == 0) { throw new Exception(pcl.cnvcInvCode + "存货档案未设置"); } Entity.Inventory inv = new AMSApp.zhenghua.Entity.Inventory(drinvs[0]); rrd.cnvcInvCode = inv.cnvcInvCode; rrd.cnvcGroupCode = inv.cnvcGroupCode; rrd.cnvcComunitCode = inv.cnvcSTComUnitCode; DataRow[] drcus = dtComputationUnit.Select("cnvcGroupCode='" + inv.cnvcGroupCode + "' and cnbMainUnit=1"); if (drcus.Length == 0) { throw new Exception(inv.cnvcGroupCode + "未设置主计量单位"); } decimal dchangerate = Convert.ToDecimal(drcus[0]["cnichangrate"].ToString()); DataRow[] drcus1 = dtComputationUnit.Select("cnvcGroupCode='" + inv.cnvcGroupCode + "' and cnvcComUnitCode='" + inv.cnvcSTComUnitCode + "'"); decimal dchangerate_st = Convert.ToDecimal(drcus1[0]["cnichangrate"].ToString()); // string strcssql = "SELECT * FROM tbCurrentStock WHERE cnvcWhCode='"+strWarehouse+"' AND cnvcInvCode='"+pcl.cnvcInvCode+"'"; // DataTable dtcs = SqlHelper.ExecuteDataTable(trans,CommandType.Text,strcssql); string strcssql = "SELECT * FROM tbCurrentStock WHERE cnvcWhCode='" + strWarehouse + "' AND cnvcInvCode='" + pcl.cnvcInvCode + "'" + " and CONVERT(char(10),isnull(cndExpDate,''),121)>=CONVERT(char(10),getdate(),121) "; string strcssql2 = "SELECT isnull(sum(cnnAvaQuantity),0) FROM tbCurrentStock WHERE cnvcWhCode='" + strWarehouse + "' AND cnvcInvCode='" + pcl.cnvcInvCode + "'" + " and CONVERT(char(10),isnull(cndExpDate,''),121)>=CONVERT(char(10),getdate(),121) "; DataTable dtcs = SqlHelper.ExecuteDataTable(trans, CommandType.Text, strcssql); decimal davaquantity = Convert.ToDecimal(SqlHelper.ExecuteScalar(trans, CommandType.Text, strcssql2).ToString()); if (dtcs.Rows.Count == 0) { throw new Exception(pcl.cnvcInvCode + "无库存"); } if (davaquantity - pcl.cnnAssignCount * dchangerate_st / dchangerate < 0) { throw new Exception(pcl.cnvcInvCode + "库存不足"); } // if(cs.cnnAvaQuantity - pcl.cnnAssignCount<0) // throw new Exception(pcl.cnvcInvCode+"库存不足"); decimal dhave = 0; foreach (DataRow drcs in dtcs.Rows) { Entity.CurrentStock cs = new CurrentStock(drcs); // if(cs.cnnAvaQuantity - pcl.cnnAssignCount<0) // throw new Exception(pcl.cnvcInvCode+"库存不足"); // cs.cnnAvaQuantity = cs.cnnAvaQuantity - pcl.cnnAssignCount; // cs.cnnQuantity = cs.cnnQuantity - pcl.cnnAssignCount; // EntityMapping.Update(cs,trans); if (cs.cnnAvaQuantity > pcl.cnnAssignCount * dchangerate_st / dchangerate - dhave) { cs.cnnAvaQuantity = cs.cnnAvaQuantity - pcl.cnnAssignCount * dchangerate_st / dchangerate; cs.cnnQuantity = cs.cnnQuantity - pcl.cnnAssignCount * dchangerate_st / dchangerate; EntityMapping.Update(cs, trans); break; } else { cs.cnnAvaQuantity = 0; cs.cnnQuantity = 0; EntityMapping.Update(cs, trans); dhave += cs.cnnAvaQuantity; } } rrd.cnnQuantity = pcl.cnnAssignCount * dchangerate_st / dchangerate; EntityMapping.Create(rrd, trans); } //string strsql = "update tbMakeDetail set cnbCollar=1 where cnnMakeSerialNo="+strMakeSerialNo; //SqlHelper.ExecuteNonQuery(trans,CommandType.Text,strsql); string strsql4 = "update tbproducelog set cnvcproducestate='7' where cnnproduceserialno=" + strProduceSerialNo; SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strsql4); operLog.cndOperDate = dtSysTime; operLog.cnvcComments = "生产流水:" + strProduceSerialNo; EntityMapping.Create(operLog, trans); trans.Commit(); } catch (SqlException sex) { trans.Rollback(); LogAdapter.WriteDatabaseException(sex); throw sex; } catch (Exception ex) { trans.Rollback(); LogAdapter.WriteFeaturesException(ex); throw ex; } finally { ConnectionPool.ReturnConnection(conn); } } }
public IList <DemandDetailsNew> Getallorderdetails(int wid) { var currentstock = db.DbCurrentStock.Where(x => x.Deleted == false).ToList(); List <DemandDetailsNew> DemandDetails = (from a in db.DbOrderDetails where (a.Status == "Pending" || a.Status == "Process") && a.Deleted == false join i in db.itemMasters on a.ItemId equals i.ItemId select new DemandDetailsNew { ItemId = a.ItemId, itemname = a.itemname, ItemCode = i.itemcode, MinOrderQty = i.PurchaseMinOrderQty, qty = a.qty, City = a.City, CityId = a.CityId, Warehouseid = a.Warehouseid, WarehouseName = a.WarehouseName, CreatedDate = a.CreatedDate, status = a.Status, itemNumber = i.Number, PurchaseSku = i.PurchaseSku, PurchaseUnitName = i.PurchaseUnitName }).ToList(); List <DemandDetailsNew> demdlist = new List <DemandDetailsNew>(); List <DemandDetailsNew> uniquelist = new List <DemandDetailsNew>(); foreach (var selectunique in DemandDetails) { int count = 0; //01AE101110 var check = uniquelist.Where(x => x.PurchaseSku == selectunique.PurchaseSku).SingleOrDefault(); if (check == null) { count += 1; uniquelist.Add(selectunique); } else { check.qty = check.qty + selectunique.qty; uniquelist.First(d => d.PurchaseSku == selectunique.PurchaseSku).qty = check.qty; } } foreach (var a in uniquelist) { CurrentStock itm = currentstock.Where(x => x.ItemNumber.Trim() == a.itemNumber.Trim()).SingleOrDefault(); if (itm != null) { if (itm.CurrentInventory < a.qty) { a.qty = a.qty - itm.CurrentInventory; List <PurchaseOrderDetailRecived> poList = db.PurchaseOrderRecivedDetails.Where(x => x.ItemId == a.ItemId && x.Status != "Received").ToList(); List <PurchaseOrderDetail> po1 = db.DPurchaseOrderDeatil.Where(x => x.ItemId == a.ItemId && x.Status == "ordered").ToList(); if (poList.Count != 0 && po1.Count != 0) { foreach (var p in poList) { a.qty = a.qty - Convert.ToInt32((p.PurchaseQty - p.QtyRecived) * p.MOQ); } foreach (var p1 in po1) { a.qty = a.qty - Convert.ToInt32(p1.TotalQuantity); } if (a.qty > 0) { demdlist.Add(a); } } else if (poList.Count != 0 && po1.Count == 0) { foreach (var p in poList) { a.qty = a.qty - Convert.ToInt32((p.PurchaseQty - p.QtyRecived) * p.MOQ); } if (a.qty > 0) { demdlist.Add(a); } } else if (poList.Count == 0 && po1.Count != 0) { foreach (var p in po1) { a.qty = a.qty - Convert.ToInt32(p.TotalQuantity); } if (a.qty > 0) { demdlist.Add(a); } } else { demdlist.Add(a); } } } } return(demdlist); }
public ActionResult SaveUpdatePurRet(PurRetMain PurRet, List <PurRetDetail> PurRetDetail, string IsSave) { using (var transaction = new TransactionScope()) { try { RBACUser rUser = new RBACUser(Session["UserName"].ToString()); #region for Purs Return transection string trnType = "Save"; string Msg = "1"; //Firstly deleted the saved For Update if (IsSave == "1") { if (!rUser.HasPermission("PurchaseReturn_Update")) { return(Json("U", JsonRequestBehavior.AllowGet)); } trnType = "Update"; Msg = "2"; #region For AVP OR LOT if (Session["MaintLot"].ToString() == "True") { var sRetMain = _PurRetMainService.All().Where(s => s.PurRetNo == PurRet.PurRetNo).FirstOrDefault(); var sRetDetail = _PurRetDetailService.All().Where(s => s.PurRetId == sRetMain.PurRetId).ToList(); foreach (var currentItem in sRetDetail) { var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode && m.LocCode == PurRet.LocNo && m.LotNo == currentItem.LotNo); if (currentStocks != null) { currentStocks.CurrQty = currentStocks.CurrQty + currentItem.ReturnQty; currentStocks.UnitPrice = Convert.ToDouble(currentItem.UnitPrice); _currentStockService.Update(currentStocks); } } } else { // For Costledger Code } #endregion var saleRetDel = _PurRetMainService.All().ToList().Where(y => y.PurRetNo == PurRet.PurRetNo).FirstOrDefault(); _PurRetDetailService.All().ToList().Where(y => y.PurRetId == saleRetDel.PurRetId).ToList().ForEach(x => _PurRetDetailService.Delete(x)); _PurRetDetailService.Save(); _PurRetMainService.Delete(saleRetDel); _PurRetMainService.Save(); var rcvDel = _issueMainService.All().ToList().Where(y => y.RefNo == PurRet.PurRetNo && y.VchrNo == PurRet.VchrNo).FirstOrDefault(); _issueDetailService.All().ToList().Where(y => y.IssueNo == PurRet.ChallanNo).ToList().ForEach(x => _issueDetailService.Delete(x)); _receiveDetailService.Save(); _issueMainService.Delete(rcvDel); _issueMainService.Save(); } if (!rUser.HasPermission("PurchaseReturn_Insert")) { return(Json("X", JsonRequestBehavior.AllowGet)); } var IfExist = _PurRetMainService.All().Where(x => x.PurRetNo == PurRet.PurRetNo).FirstOrDefault(); if (IfExist == null) { PurRet.FinYear = Session["FinYear"].ToString(); PurRet.BranchCode = Session["BranchCode"].ToString(); PurRet.ProjCode = Session["ProjCode"].ToString(); PurRet.EntryDateTime = DateTime.Now; _PurRetMainService.Add(PurRet); _PurRetMainService.Save(); if (PurRetDetail != null) { foreach (var sRetDExtItem in PurRetDetail) { PurRetDetail sRetDetail = new PurRetDetail(); var srID = _PurRetMainService.All().Select(s => s.PurRetId).LastOrDefault(); if (srID == 0) { sRetDExtItem.PurRetId = 1; } else { sRetDExtItem.PurRetId = srID; } sRetDetail = sRetDExtItem; _PurRetDetailService.Add(sRetDetail); } } _PurRetDetailService.Save(); #region For Issue var IssueNo = _issueMainService.All().Select(s => Convert.ToInt32(s.IssueNo)).LastOrDefault() + 1; if (IssueNo != 0) { var todayDate = DateTime.Now; IssueMain issueInfo = new IssueMain(); issueInfo.IssueNo = "0" + IssueNo.ToString(); //PurRet.PurRetNo; issueInfo.BranchCode = Session["BranchCode"].ToString(); issueInfo.IssueDate = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); issueInfo.FromLocCode = PurRet.LocNo; //issueInfo.StoreLocCode = PurRet.StoreLocCode; issueInfo.IssueToSubCode = PurRet.CustCode; //issueInfo.DesLocCode = PurRet.DesLocCode; //issueInfo.Accode = PurRet.Accode; issueInfo.RefNo = PurRet.PurRetNo; issueInfo.RefDate = PurRet.PurRetDate; issueInfo.Remarks = PurRet.Remarks; //issueInfo.IssueByCode = PurRet.IssueByCode; issueInfo.AppByCode = PurRet.ApprBy; issueInfo.IssTime = DateTime.Now; issueInfo.FinYear = Session["FinYear"].ToString(); issueInfo.GLPost = false; issueInfo.IssDate = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); issueInfo.cashReceiptStatus = false; issueInfo.IsReceived = false; issueInfo.VchrNo = PurRet.VchrNo; double amount = 0.0; issueInfo.EntrySrc = "PR"; issueInfo.EntrySrcNo = issueInfo.IssueNo; List <IssueDetails> issuDetailsList = new List <IssueDetails>(); #region For LOT OR AVP if (Session["MaintLot"].ToString() == "True") { #region Not AutoLot by issueDetail foreach (var currentItem in PurRetDetail) { var currentStocks = _currentStockService.All().ToList().FirstOrDefault(m => m.ItemCode == currentItem.ItemCode && m.LocCode == PurRet.LocNo && m.LotNo == currentItem.LotNo); if (currentStocks != null) { currentStocks.CurrQty = currentStocks.CurrQty - currentItem.ReturnQty; currentStocks.UnitPrice = (double)currentItem.UnitPrice; _currentStockService.Update(currentStocks); } else { CurrentStock currStock = new CurrentStock(); currStock.LocCode = PurRet.LocNo; currStock.LotNo = currentItem.LotNo; currStock.ItemCode = currentItem.ItemCode; currStock.CurrQty = 0 - currentItem.ReturnQty; currStock.UnitPrice = (double)currentItem.UnitPrice; _currentStockService.Add(currStock); } } #endregion } else { #region for Cost ledger foreach (var costLedger in PurRetDetail) { CostLedger cLedger = new CostLedger(); cLedger.IssQty = costLedger.ReturnQty; cLedger.IssRate = (double)costLedger.UnitPrice; cLedger.IssTotal = cLedger.IssQty * cLedger.IssRate; cLedger.RecQty = 0; cLedger.RecRate = 0; cLedger.RecTotal = 0; var existCurrStoc = CostLedgerAppService.All().Where(x => x.ItemCode == costLedger.ItemCode && x.LocNo == PurRet.LocNo.Trim()).ToList(); if (existCurrStoc.Count != 0) { var date = existCurrStoc.Max(x => x.TrDate); var existCurrStock = CostLedgerAppService.All().OrderByDescending(s => s.RecId).Where(x => x.ItemCode == costLedger.ItemCode && x.LocNo == PurRet.LocNo.Trim() && x.TrDate == date).FirstOrDefault(); cLedger.BalQty = existCurrStock.BalQty - cLedger.IssQty; cLedger.BalRate = System.Math.Round(existCurrStock.BalRate, 2); cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2); cLedger.LocNo = PurRet.LocNo; cLedger.ItemCode = costLedger.ItemCode; cLedger.TrDate = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); cLedger.UpdSrcNo = PurRet.PurRetNo; cLedger.UpdSrc = "PR"; CostLedgerAppService.Add(cLedger); } else if (existCurrStoc.Count == 0) { cLedger.CurrQty = 0; cLedger.UnitPrice = 0; cLedger.BalTotal = 0; cLedger.BalQty = cLedger.BalQty - cLedger.IssQty; cLedger.BalRate = cLedger.IssRate; cLedger.BalRate = System.Math.Round(cLedger.BalRate, 2); cLedger.BalTotal = System.Math.Round(cLedger.BalQty * cLedger.BalRate, 2); cLedger.LocNo = PurRet.LocNo; cLedger.ItemCode = costLedger.ItemCode; cLedger.TrDate = PurRet.PurRetDate.AddHours(todayDate.Hour).AddMinutes(todayDate.Minute).AddSeconds(todayDate.Second).AddMilliseconds(todayDate.Millisecond); cLedger.UpdSrcNo = PurRet.PurRetNo; cLedger.UpdSrc = "PR"; CostLedgerAppService.Add(cLedger); } CostLedgerAppService.Save(); } #endregion } #endregion foreach (var issuDetailsItem in PurRetDetail) { IssueDetails issueDetailsInfo = new IssueDetails(); issueDetailsInfo.IssueNo = "0" + IssueNo.ToString(); issueDetailsInfo.ItemCode = issuDetailsItem.ItemCode; issueDetailsInfo.SubCode = PurRet.CustCode; issueDetailsInfo.Description = issuDetailsItem.Description; issueDetailsInfo.Qty = issuDetailsItem.ReturnQty; issueDetailsInfo.Price = (double)issuDetailsItem.UnitPrice; //issueDetailsInfo.ExQty = issuDetailsItem.ExQty; issueDetailsInfo.LotNo = "01"; amount = amount + (issuDetailsItem.ReturnQty * (double)issuDetailsItem.UnitPrice); issuDetailsList.Add(issueDetailsInfo); } issueInfo.Amount = amount; issueInfo.IssueDetails = issuDetailsList; _issueMainService.Add(issueInfo); _issueMainService.Save(); } #endregion TransactionLogService.SaveTransactionLog(_transactionLogService, "Purchase Return", trnType, PurRet.VchrNo, Session["UserName"].ToString()); //LoadDropDown.ProvitionInvRSave("IR", "I", recvInfo.RcvNo, recvInfo.VchrNo, Session["FinYear"].ToString(), Session["ProjCode"].ToString(), Session["BranchCode"].ToString(), recvMain.RcvDate.ToString("yyyy-MM-dd"), Session["UserName"].ToString()); transaction.Complete(); return(Json(new { Msg = Msg }, JsonRequestBehavior.AllowGet)); } else { transaction.Dispose(); return(Json("3", JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { transaction.Dispose(); return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet)); } } }
/// <summary> /// 增加一条数据 /// </summary> public override void Add(dynamic obj, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CurrentStock("); strSql.Append("iNum,cFree1,cFree2,fOutQuantity,fOutNum,fInQuantity,fInNum,cFree3,cFree4,cFree5,cWhCode,cFree6,cFree7,cFree8,cFree9,cFree10,dVDate,bStopFlag,fTransInQuantity,dMdate,fTransInNum,cInvCode,fTransOutQuantity,fTransOutNum,fPlanQuantity,fPlanNum,fDisableQuantity,fDisableNum,fAvaQuantity,fAvaNum,iMassDate,BGSPSTOP,ItemId,cMassUnit,fStopQuantity,fStopNum,dLastCheckDate,cCheckState,dLastYearCheckDate,iExpiratDateCalcu,cExpirationdate,dExpirationdate,ipeqty,cBatch,ipenum,cVMIVenCode,iSoType,iSodid,iQuantity"); strSql.Append(") values ("); strSql.Append("@iNum,@cFree1,@cFree2,@fOutQuantity,@fOutNum,@fInQuantity,@fInNum,@cFree3,@cFree4,@cFree5,@cWhCode,@cFree6,@cFree7,@cFree8,@cFree9,@cFree10,@dVDate,@bStopFlag,@fTransInQuantity,@dMdate,@fTransInNum,@cInvCode,@fTransOutQuantity,@fTransOutNum,@fPlanQuantity,@fPlanNum,@fDisableQuantity,@fDisableNum,@fAvaQuantity,@fAvaNum,@iMassDate,@BGSPSTOP,@ItemId,@cMassUnit,@fStopQuantity,@fStopNum,@dLastCheckDate,@cCheckState,@dLastYearCheckDate,@iExpiratDateCalcu,@cExpirationdate,@dExpirationdate,@ipeqty,@cBatch,@ipenum,@cVMIVenCode,@iSoType,@iSodid,@iQuantity"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@iNum", SqlDbType.Decimal, 13), new SqlParameter("@cFree1", SqlDbType.NVarChar, 20), new SqlParameter("@cFree2", SqlDbType.NVarChar, 20), new SqlParameter("@fOutQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fOutNum", SqlDbType.Decimal, 13), new SqlParameter("@fInQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fInNum", SqlDbType.Decimal, 13), new SqlParameter("@cFree3", SqlDbType.NVarChar, 20), new SqlParameter("@cFree4", SqlDbType.NVarChar, 20), new SqlParameter("@cFree5", SqlDbType.NVarChar, 20), new SqlParameter("@cWhCode", SqlDbType.NVarChar, 10), new SqlParameter("@cFree6", SqlDbType.NVarChar, 20), new SqlParameter("@cFree7", SqlDbType.NVarChar, 20), new SqlParameter("@cFree8", SqlDbType.NVarChar, 20), new SqlParameter("@cFree9", SqlDbType.NVarChar, 20), new SqlParameter("@cFree10", SqlDbType.NVarChar, 20), new SqlParameter("@dVDate", SqlDbType.DateTime), new SqlParameter("@bStopFlag", SqlDbType.Bit, 1), new SqlParameter("@fTransInQuantity", SqlDbType.Decimal, 13), new SqlParameter("@dMdate", SqlDbType.DateTime), new SqlParameter("@fTransInNum", SqlDbType.Decimal, 13), new SqlParameter("@cInvCode", SqlDbType.NVarChar, 60), new SqlParameter("@fTransOutQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fTransOutNum", SqlDbType.Decimal, 13), new SqlParameter("@fPlanQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fPlanNum", SqlDbType.Decimal, 13), new SqlParameter("@fDisableQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fDisableNum", SqlDbType.Decimal, 13), new SqlParameter("@fAvaQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fAvaNum", SqlDbType.Decimal, 13), new SqlParameter("@iMassDate", SqlDbType.Int, 4), new SqlParameter("@BGSPSTOP", SqlDbType.Bit, 1), new SqlParameter("@ItemId", SqlDbType.Int, 4), new SqlParameter("@cMassUnit", SqlDbType.SmallInt, 2), new SqlParameter("@fStopQuantity", SqlDbType.Decimal, 13), new SqlParameter("@fStopNum", SqlDbType.Decimal, 13), new SqlParameter("@dLastCheckDate", SqlDbType.DateTime), new SqlParameter("@cCheckState", SqlDbType.NVarChar, 4), new SqlParameter("@dLastYearCheckDate", SqlDbType.DateTime), new SqlParameter("@iExpiratDateCalcu", SqlDbType.SmallInt, 2), new SqlParameter("@cExpirationdate", SqlDbType.VarChar, 10), new SqlParameter("@dExpirationdate", SqlDbType.DateTime), new SqlParameter("@ipeqty", SqlDbType.Decimal, 17), new SqlParameter("@cBatch", SqlDbType.NVarChar, 60), new SqlParameter("@ipenum", SqlDbType.Decimal, 17), new SqlParameter("@cVMIVenCode", SqlDbType.NVarChar, 20), new SqlParameter("@iSoType", SqlDbType.Int, 4), new SqlParameter("@iSodid", SqlDbType.NVarChar, 40), new SqlParameter("@iQuantity", SqlDbType.Decimal, 13) }; CurrentStock model = (CurrentStock)obj; parameters[0].Value = SqlNull(model.iNum); parameters[1].Value = SqlNull(model.cFree1); parameters[2].Value = SqlNull(model.cFree2); parameters[3].Value = SqlNull(model.fOutQuantity); parameters[4].Value = SqlNull(model.fOutNum); parameters[5].Value = SqlNull(model.fInQuantity); parameters[6].Value = SqlNull(model.fInNum); parameters[7].Value = SqlNull(model.cFree3); parameters[8].Value = SqlNull(model.cFree4); parameters[9].Value = SqlNull(model.cFree5); parameters[10].Value = SqlNull(model.cWhCode); parameters[11].Value = SqlNull(model.cFree6); parameters[12].Value = SqlNull(model.cFree7); parameters[13].Value = SqlNull(model.cFree8); parameters[14].Value = SqlNull(model.cFree9); parameters[15].Value = SqlNull(model.cFree10); parameters[16].Value = SqlNull(model.dVDate); parameters[17].Value = SqlNull(model.bStopFlag); parameters[18].Value = SqlNull(model.fTransInQuantity); parameters[19].Value = SqlNull(model.dMdate); parameters[20].Value = SqlNull(model.fTransInNum); parameters[21].Value = SqlNull(model.cInvCode); parameters[22].Value = SqlNull(model.fTransOutQuantity); parameters[23].Value = SqlNull(model.fTransOutNum); parameters[24].Value = SqlNull(model.fPlanQuantity); parameters[25].Value = SqlNull(model.fPlanNum); parameters[26].Value = SqlNull(model.fDisableQuantity); parameters[27].Value = SqlNull(model.fDisableNum); parameters[28].Value = SqlNull(model.fAvaQuantity); parameters[29].Value = SqlNull(model.fAvaNum); parameters[30].Value = SqlNull(model.iMassDate); parameters[31].Value = SqlNull(model.BGSPSTOP); parameters[32].Value = SqlNull(model.ItemId); parameters[33].Value = SqlNull(model.cMassUnit); parameters[34].Value = SqlNull(model.fStopQuantity); parameters[35].Value = SqlNull(model.fStopNum); parameters[36].Value = SqlNull(model.dLastCheckDate); parameters[37].Value = SqlNull(model.cCheckState); parameters[38].Value = SqlNull(model.dLastYearCheckDate); parameters[39].Value = SqlNull(model.iExpiratDateCalcu); parameters[40].Value = SqlNull(model.cExpirationdate); parameters[41].Value = SqlNull(model.dExpirationdate); parameters[42].Value = SqlNull(model.ipeqty); parameters[43].Value = SqlNull(model.cBatch); parameters[44].Value = SqlNull(model.ipenum); parameters[45].Value = SqlNull(model.cVMIVenCode); parameters[46].Value = SqlNull(model.iSoType); parameters[47].Value = SqlNull(model.iSodid); parameters[48].Value = SqlNull(model.iQuantity); if (tran == null) { DataHelper.ExcuteNonQuery(strSql.ToString(), parameters, false); } else { DataHelper.ExcuteNonQuery(strSql.ToString(), tran, parameters, false); } }
public string UploadFile() { if (HttpContext.Current.Request.Files.AllKeys.Any()) { logger.Info("start current stock Upload Exel File: "); var identity = User.Identity as ClaimsIdentity; int compid = 0, userid = 0; // Access claims foreach (Claim claim in identity.Claims) { if (claim.Type == "compid") { compid = int.Parse(claim.Value); } if (claim.Type == "userid") { userid = int.Parse(claim.Value); } } // Get the uploaded image from the Files collection System.Web.HttpPostedFile httpPostedFile = HttpContext.Current.Request.Files["file"]; if (httpPostedFile != null) { // Validate the uploaded image(optional) byte[] buffer = new byte[httpPostedFile.ContentLength]; using (BinaryReader br = new BinaryReader(httpPostedFile.InputStream)) { br.Read(buffer, 0, buffer.Length); } XSSFWorkbook hssfwb; // XSSFWorkbook workbook1; using (MemoryStream memStream = new MemoryStream()) { BinaryFormatter binForm = new BinaryFormatter(); memStream.Write(buffer, 0, buffer.Length); memStream.Seek(0, SeekOrigin.Begin); hssfwb = new XSSFWorkbook(memStream); string sSheetName = hssfwb.GetSheetName(0); ISheet sheet = hssfwb.GetSheet(sSheetName); AuthContext context = new AuthContext(); IRow rowData; ICell cellData = null; try { List <CurrentStock> currentstkcollection = new List <CurrentStock>(); for (int iRowIdx = 0; iRowIdx <= sheet.LastRowNum; iRowIdx++) // iRowIdx = 0; HeaderRow { if (iRowIdx == 0) { rowData = sheet.GetRow(iRowIdx); if (rowData != null) { string field = string.Empty; field = rowData.GetCell(0).ToString(); if (field != "ItemNumber") { JavaScriptSerializer objJSSerializer = new JavaScriptSerializer(); strJSON = objJSSerializer.Serialize("Header Name " + field + " does not exist..try again"); return(strJSON); } field = rowData.GetCell(1).ToString(); if (field != "StockId") { JavaScriptSerializer objJSSerializer = new JavaScriptSerializer(); strJSON = objJSSerializer.Serialize("Header Name " + field + " does not exist..try again"); return(strJSON); } field = rowData.GetCell(2).ToString(); if (field != "ItemName") { JavaScriptSerializer objJSSerializer = new JavaScriptSerializer(); strJSON = objJSSerializer.Serialize("Header Name " + field + " does not exist..try again"); return(strJSON); } field = rowData.GetCell(3).ToString(); if (field != "CurrentInventory") { JavaScriptSerializer objJSSerializer = new JavaScriptSerializer(); strJSON = objJSSerializer.Serialize("Header Name " + field + " does not exist..try again"); return(strJSON); } field = rowData.GetCell(4).ToString(); if (field != "WarehouseName") { JavaScriptSerializer objJSSerializer = new JavaScriptSerializer(); strJSON = objJSSerializer.Serialize("Header Name " + field + " does not exist..try again"); return(strJSON); } } } else { rowData = sheet.GetRow(iRowIdx); cellData = rowData.GetCell(0); rowData = sheet.GetRow(iRowIdx); if (rowData != null) { CurrentStock currntstk = new CurrentStock(); try { int cstid; cellData = rowData.GetCell(0); col0 = cellData == null ? "" : cellData.ToString(); currntstk.ItemNumber = col0.Trim(); logger.Info("ItemNumber :" + currntstk.ItemNumber); cellData = rowData.GetCell(1); col1 = cellData == null ? "" : cellData.ToString(); if ((col1 == null) || (col1 == "")) { cstid = 0; } else { cstid = Convert.ToInt32(col1); } currntstk.StockId = cstid; cellData = rowData.GetCell(2); col2 = cellData == null ? "" : cellData.ToString(); currntstk.ItemName = col2.Trim(); cellData = rowData.GetCell(3); col3 = cellData == null ? "" : cellData.ToString(); currntstk.CurrentInventory = Convert.ToInt32(col3); cellData = rowData.GetCell(4); col4 = cellData == null ? "" : cellData.ToString(); currntstk.WarehouseName = col4.Trim(); currentstkcollection.Add(currntstk); } catch (Exception ex) { msgitemname = ex.Message; logger.Error("Error adding customer in collection " + "\n\n" + ex.Message + "\n\n" + ex.InnerException + "\n\n" + ex.StackTrace + currntstk.ItemName); } } } } context.Addcurrentstock(currentstkcollection); string m = "save collection"; logger.Info(m); } catch (Exception ex) { logger.Error("Error loading for\n\n" + ex.Message + "\n\n" + ex.InnerException + "\n\n" + ex.StackTrace); } } var FileUrl = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName); httpPostedFile.SaveAs(FileUrl); } } if (msgitemname != null) { return(msgitemname); } msg = "Your Exel data is succesfully saved"; return(msg); }
public override string ToString() { return(CurrentStock.ToString()); }