private void ReceivepackingSlip(int Iserial, int userIserial) { var axapta = new Axapta(); var transactionGuid = Guid.NewGuid().ToString(); var credential = new NetworkCredential("bcproxy", "around1"); var header = new TblPurchaseReceiveHeader(); using (var model = new WorkFlowManagerDBEntities()) { header = model.TblPurchaseReceiveHeaders.Include("TblPurchaseOrderHeaderRequest1") .Include("TblPurchaseReceiveDetails.TblPurchaseOrderDetailRequest1") .FirstOrDefault(w => w.Iserial == Iserial); TblAuthUser userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); var warehouse = model.TblWarehouses.FirstOrDefault(w => w.Iserial == header.TblWarehouse); if (userToLogin != null) { axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); } const string tableName = "AutoPICKING"; var axaptaRecord = axapta.CreateAxaptaRecord(tableName); foreach (var variable in header.TblPurchaseReceiveDetails) { var color = model.TblColors.FirstOrDefault(e => e.Iserial == variable.TblPurchaseOrderDetailRequest1.FabricColor).Code; var purchdim = model.PurchlineInventDimWithoutRecs.Where(w => w.ITEMID == variable.TblPurchaseOrderDetailRequest1.ItemId && w.CONFIGID == color && w.PURCHID == header.TblPurchaseOrderHeaderRequest1.AxPurchase); if (variable.TblPurchaseOrderDetailRequest1.BatchNo != null) { purchdim = purchdim.Where(x => x.INVENTBATCHID == variable.TblPurchaseOrderDetailRequest1.BatchNo); } if (variable.TblPurchaseOrderDetailRequest1.Size != null) { purchdim = purchdim.Where(x => x.INVENTSIZEID == variable.TblPurchaseOrderDetailRequest1.Size); } axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("DATAAREAID", "Ccm"); axaptaRecord.set_Field("TransactionGuid", transactionGuid); axaptaRecord.set_Field("FABRICLOCATION", warehouse.Code); axaptaRecord.set_Field("QTY", Convert.ToDecimal(variable.Qty)); axaptaRecord.set_Field("WORKFLOWJOURID", header.Iserial); axaptaRecord.set_Field("LineNum", purchdim.OrderByDescending(w => w.LINENUM).FirstOrDefault().LINENUM); axaptaRecord.Insert(); } } CreatePackingSlip(header.DocCode + "_" + header.RefNo, header.TblPurchaseOrderHeaderRequest1.AxPurchase, transactionGuid, userIserial); }
private int DeleteTblPurchaseReceiveHeader(TblPurchaseReceiveHeader row) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblPurchaseReceiveHeaders where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row.Iserial); }
private TblPurchaseReceiveHeader UpdateOrInsertTblPurchaseReceiveHeader(TblPurchaseReceiveHeader newRow, int index, out int outindex, string createdBy, int userIserial) { outindex = index; var totallist = new List <TblPurchaseReceiveDetail>(); using (var context = new WorkFlowManagerDBEntities()) { var newrowRet = new TblPurchaseReceiveHeader(); var oldRow = (from e in context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails") where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { newRow.CreatedBy = oldRow.CreatedBy; newRow.CreationDate = oldRow.CreationDate; newRow.LastUpdatedBy = createdBy; newRow.LastUpdatedDate = DateTime.Now; SharedOperation.GenericUpdate(oldRow, newRow, context); var OlDheader = context.TblPurchaseOrderHeaderRequests.FirstOrDefault(w => w.Iserial == oldRow.TblPurchaseOrderHeaderRequest); if (OlDheader.AxPurchase == null) { foreach (var VARIABLE in oldRow.TblPurchaseReceiveDetails) { totallist.Add(VARIABLE); } } } else { var warehouse = context.TblWarehouses.FirstOrDefault(w => w.Iserial == newRow.TblWarehouse); foreach (var VARIABLE in newRow.TblPurchaseReceiveDetails) { totallist.Add(VARIABLE); } newRow.TblPurchaseReceiveDetails.Clear(); if (totallist.Any(w => w.Qty > 0)) { foreach (var variable in totallist.Where(x => x.Qty > 0)) { newRow.TblPurchaseReceiveDetails.Add(variable); } var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == warehouse.Receive); newRow.DocCode = SharedOperation.HandelSequence(seqRow); newRow.CreatedBy = createdBy; newRow.CreationDate = DateTime.Now; newRow.TblInventType = 1; context.TblPurchaseReceiveHeaders.AddObject(newRow); } if (totallist.Any(w => w.Qty < 0)) { newrowRet = new TblPurchaseReceiveHeader { DocDate = newRow.DocDate, RefNo = newRow.RefNo, Notes = newRow.Notes, TblWarehouse = newRow.TblWarehouse, Vendor = newRow.Vendor, TblPurchaseOrderHeaderRequest = newRow.TblPurchaseOrderHeaderRequest, Iserial = 0, }; newrowRet.TblPurchaseReceiveDetails.Clear(); foreach (var variable in totallist.Where(x => x.Qty < 0)) { newrowRet.TblPurchaseReceiveDetails.Add(variable); } var seqRow = context.TblSequenceProductions.FirstOrDefault(x => x.Iserial == warehouse.RetReceive); newrowRet.DocCode = SharedOperation.HandelSequence(seqRow); newrowRet.CreatedBy = createdBy; newrowRet.CreationDate = DateTime.Now; newrowRet.TblInventType = 2; context.TblPurchaseReceiveHeaders.AddObject(newrowRet); } } context.SaveChanges(); //if (true) //{ //} //var ListOfRec = (from e in context.TblPurchaseReceiveDetails // where e.TblPurchaseReceiveHeader == newRow.Iserial // select e).ToList(); //newRow.TblPurchaseReceiveDetails = new System.Data.Objects.DataClasses.EntityCollection<TblPurchaseReceiveDetail>(); //foreach (var item in ListOfRec) //{ // newRow.TblPurchaseReceiveDetails.Add(item); //} //foreach (var VARIABLE in newRow.TblPurchaseReceiveDetails) //{ // totallist.Add(VARIABLE); //} if (totallist.Any(w => w.Qty > 0)) { PoPlanPurchase(newRow.Iserial, userIserial); ReceivepackingSlip(newRow.Iserial, userIserial); } if (totallist.Any(w => w.Qty < 0)) { PoPlanPurchase(newrowRet.Iserial, userIserial); //var header = context.TblPurchaseReceiveHeaders.Include("TblPurchaseOrderHeaderRequest1").Include("TblPurchaseReceiveDetails.TblPurchaseOrderDetailRequest1").FirstOrDefault(w => w.Iserial == newrowRet.Iserial); ReceivepackingSlip(newrowRet.Iserial, userIserial); } if (totallist.Any(w => w.Qty > 0)) { var purchaserec = context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails").FirstOrDefault(w => w.Iserial == newRow.Iserial); foreach (var item in purchaserec.TblPurchaseReceiveDetails.ToList()) { var purchaseOrderDetailRequest = context.TblPurchaseOrderDetailRequests.FirstOrDefault(w => w.Iserial == item.TblPurchaseOrderDetailRequest); purchaseOrderDetailRequest.BatchNo = ""; purchaseOrderDetailRequest.ReceiveNow = 0; } } if (totallist.Any(w => w.Qty < 0)) { var purchaserec = context.TblPurchaseReceiveHeaders.Include("TblPurchaseReceiveDetails").FirstOrDefault(w => w.Iserial == newrowRet.Iserial); foreach (var item in purchaserec.TblPurchaseReceiveDetails.ToList()) { var purchaseOrderDetailRequest = context.TblPurchaseOrderDetailRequests.FirstOrDefault(w => w.Iserial == item.TblPurchaseOrderDetailRequest); purchaseOrderDetailRequest.BatchNo = ""; purchaseOrderDetailRequest.ReceiveNow = 0; } } return(newRow); } }