private List <tbl_MarkerDetail> MarkerDetails(int headerTransactionIserial, out TblSalesOrder SalesOrder) { using (var entities = new WorkFlowManagerDBEntities()) { var markerDetails = (from m in entities.tbl_MarkerDetail.Include("TblColor").Include("TblColor1").Include("Tbl_Wf_CuttingOrder") where m.MarkerTransactionHeader == headerTransactionIserial select m).ToList(); var sales = markerDetails.FirstOrDefault().SalesOrder; SalesOrder = entities.TblSalesOrders.FirstOrDefault(x => x.SalesOrderCode == sales && x.SalesOrderType == 2); return(markerDetails); } }
public SearchSalesOrderViewModel() { if (!DesignerProperties.IsInDesignTool) { Client = new CRUD_ManagerServiceClient(); MainRowList = new ObservableCollection <TblSalesOrder>(); SelectedMainRow = new TblSalesOrder(); Client.GetTblSalesOrderOperationCompleted += (s, sv) => { if (sv.Result != null) { foreach (var row in sv.Result) { } } }; Client.SearchSalesOrderCompleted += (s, sv) => { if (sv.Result != null) { foreach (var row in sv.Result) { //var newrow = new TblSalesOrder(); //newrow.InjectFrom(row); if (!MainRowList.Contains(row)) { //var fabric = sv.mainFabricList.FirstOrDefault(x => x.Iserial == newrow.tbl_FabricAttriputes); //if (fabric != null) //{ // newrow.FabricPerRow = fabric; //} //newrow.SeasonPerRow = new GenericTable(); //newrow.SizeGroupPerRow = new TblSizeGroup(); MainRowList.Add(row); } } } Loading = false; // FullCount = sv.fullCount; }; GetMaindata(); } }
static internal void CalcEstimatedBom(TblSalesOrder row) { using (var model = new WorkFlowManagerDBEntities()) { var bom = model.BOMs.Include("TblBOMSizes").Include("TblBOMStyleColors").Where(w => w.TblSalesOrder == row.Iserial); foreach (var bomLine in bom.ToList()) { float price = 0; var temp = model.TblTradeAgreementDetails.Where(x => x.ItemCode == bomLine.BOM_Fabric); if (temp.Any()) { price = temp.FirstOrDefault().Price; } foreach (var bomsize in bomLine.TblBOMSizes.ToList()) { foreach (var bomColor in bomLine.TblBOMStyleColors.ToList()) { var tblsalesordercolor = model.TblSalesOrderColors.Include("TblSalesOrderSizeRatios").FirstOrDefault( x => x.TblSalesOrder == row.Iserial && x.TblColor == bomColor.StyleColor); if (temp.Any(x => x.TblColor == bomColor.FabricColor)) { price = temp.FirstOrDefault().Price; } if (temp.Any(x => x.TblColor == bomColor.FabricColor && x.AccSize == bomsize.FabricSize)) { price = temp.FirstOrDefault().Price; } var bomprice = new BomCost { Bom = bomLine.Iserial, BOM_Fabric = (int)bomLine.BOM_Fabric, BOM_FabricType = bomLine.BOM_FabricType, StyleSize = bomsize.StyleSize, FabricSize = bomsize.FabricSize, MaterialUsage = bomsize.MaterialUsage, StyleColor = bomColor.StyleColor, FabricColor = bomColor.FabricColor, ProductionPerSize = tblsalesordercolor.TblSalesOrderSizeRatios.FirstOrDefault(x => x.Size == bomsize.StyleSize).ProductionPerSize, Price = price, }; model.BomCosts.AddObject(bomprice); } } } model.SaveChanges(); } }
private TblSalesOrder DeleteTblSalesOrder(TblSalesOrder row) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblSalesOrders where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row); }
public int PostRetailPo(TblSalesOrder salesOrder, int retailbrand) { using (var ccnewcontext = new ccnewEntities()) { var poheader = ccnewcontext.TblPO1Header.FirstOrDefault(x => x.supplierInvno == salesOrder.SalesOrderCode); if (poheader == null) { poheader = (new TblPO1Header { Code = "0", tblstore = retailbrand, supplierInvno = salesOrder.SalesOrderCode, tblsupplier = salesOrder.TblSupplier, votdate = DateTime.Now, Ddate = salesOrder.DeliveryDate, TblUser = 10, contactperson = "0", totblstore = 0, chequedate = "0", totvochnotax = 0, totvat = 0, totpricewvat = 0, commericaldisc = 0, grosscost = 0, additionaltax = 0, cashdisc = 0, miscdisc = 0, miscexp = 0, cashinvototal = 0, period = 0, Votype = 0, tblseason = 0, INVOICE = 0, BeforeInvoice = 0, CashNo = 0, PoStatus = 0, }); ccnewcontext.TblPO1Header.AddObject(poheader); ccnewcontext.SaveChanges(); } return(poheader.glserial); } }
public void PostRetailPoDetail(TblStyle style, TblSalesOrder salesOrder, int retailbrand, int styleIserial, TblSalesOrderSizeRatio size, int poheader, int Dserial, DateTime?deliveryDate, TblSalesOrderColor color) { using (var ccnewcontext = new ccnewEntities()) { var poheaderMaindetail = ccnewcontext.TblPO1MainDetail.FirstOrDefault( x => x.glserial == poheader && x.Dserial == Dserial); if (poheaderMaindetail == null) { poheaderMaindetail = (new TblPO1MainDetail { glserial = poheader, Dserial = Dserial, tblitem = styleIserial, Quantity = size.ProductionPerSize, ucostwot = color.LocalCost, totwot = 0, unitvat = 0, ucostwvat = 0, totvat = 0, totpricewvat = 0, AddExp = 0, ItmDis = 0, barcode = "0", QtyRec = 0, ItmCommericalDisc = 0, ItemSalesTax = 0, DeliveryDate = deliveryDate, } ); ccnewcontext.TblPO1MainDetail.AddObject(poheaderMaindetail); ccnewcontext.SaveChanges(); } var poDetail = ccnewcontext.TblPO1Detail.FirstOrDefault( x => x.glserial == poheader && x.Dserial == Dserial); if (poDetail == null) { poDetail = (new TblPO1Detail { glserial = poheader, Dserial = Dserial, Dserial1 = Dserial, tblitem = styleIserial, Quantity = size.ProductionPerSize, ucostwot = color.LocalCost, totwot = 0, unitvat = 0, ucostwvat = 0, totvat = 0, totpricewvat = 0, AddExp = 0, ItmDis = 0, barcode = "0", QtyRec = 0, ItmCommericalDisc = 0, ItemSalesTax = 0, ItmAdditionalTax = 0, ItmMiscDisc = 0, ItmMiscExp = 0, CashDiscOnVouch = 0, } ); ccnewcontext.TblPO1Detail.AddObject(poDetail); ccnewcontext.SaveChanges(); } } }
public void SendMailReportPo(string reportName, string subject, string body, int tblAuthUser, TblSalesOrder salesOrder) { string deviceInfo = null; var extension = String.Empty; var mimeType = String.Empty; var encoding = String.Empty; Warning[] warnings = null; string[] streamIDs = null; string historyId = null; // Create a Report Execution object var rsExec = new ReportExecutionService(); rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; using (var context = new WorkFlowManagerDBEntities()) { if (string.IsNullOrEmpty(ReportServer)) { ReportServer = context.tblChainSetups.SingleOrDefault(x => x.sGlobalSettingCode == "ReportServer").sSetupValue; } } rsExec.Url = ReportServer + "/ReportExecution2005.asmx"; // Load the report var execInfo = rsExec.LoadReport("/Report/" + reportName, historyId); var para = new ObservableCollection <string> { salesOrder.Iserial.ToString() }; var parameters = new ParameterValue[para.Count]; foreach (var row in para) { var index = para.IndexOf(row); parameters[0] = new ParameterValue(); parameters[index].Value = row; parameters[index].Name = execInfo.Parameters[index].Name; // paramters) { Name = , Value = row } }, "en-us"); } rsExec.SetExecutionParameters(parameters, "en-us"); // get pdf of report var results = rsExec.Render("PDF", deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); //Walla...almost no code, it's easy to manage and your done. //Take the bytes and add as an attachment to a MailMessage(SMTP): var attach = new Attachment(new MemoryStream(results), String.Format("{0}.pdf", reportName)); string emailFrom; var emailTo = new List <string>(); using (var model = new WorkFlowManagerDBEntities()) { try { var code = model.TblAuthUsers.FirstOrDefault(w => w.Iserial == tblAuthUser).Code; //emailFrom = "*****@*****.**";// emailFrom = model.Employees.FirstOrDefault(x => x.EMPLID == code).Email; var style = model.TblStyles.FirstOrDefault(x => x.Iserial == salesOrder.TblStyle); var brandsectionMail = model.TblBrandSectionMails.Where( x => x.TblBrand == style.Brand && x.TblLkpBrandSection == style.TblLkpBrandSection); foreach (var variable in brandsectionMail.Select(x => x.Emp)) { //emailTo.Add("*****@*****.**");// emailTo.Add(model.Employees.FirstOrDefault(x => x.EMPLID == variable).Email); } } catch (Exception) { emailFrom = model.Employees.FirstOrDefault(x => x.EMPLID == "0158").Email; } } //string emailTo; //using (var Model = new WorkFlowManagerDBEntities()) //{ // emailTo = "*****@*****.**"; // // emailFrom = Model.Employees.FirstOrDefault(x => x.EMPLID == EmpCode).Email; //} SendEmail(attach, emailFrom, emailTo, subject, body); }
public TblSalesOrder UpdateOrInsertTblSalesOrder(TblSalesOrder newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { var styleCode = context.TblStyles.FirstOrDefault(x => x.Iserial == newRow.TblStyle); var serial = GetMaxSalesorder(newRow.TblStyle, newRow.SalesOrderType); if (save) { //if (newRow.SalesOrderType== (int)Enums.SalesOrderType.RetailPo) //{ // var brandsectionlink = context.TblLkpBrandSectionLinks.FirstOrDefault(w => w.TblBrand == styleCode.Brand && w.TblLkpBrandSection == styleCode.TblLkpBrandSection); // if (brandsectionlink != null) // { // if (brandsectionlink.ContractRequired && newRow.TblContractHeader == null) // { // throw new InvalidOperationException("Contract Required"); // } // } //} if (newRow.TblSupplier == 0) { newRow.TblSupplier = 10000021; } if (newRow.Iserial != 0) { newRow.Iserial = 0; } //if (newRow.SalesOrderCode != null && newRow.SalesOrderCode.Length <= styleCode.Trim().Length + 4) //{ // newRow.SalesOrderCode = styleCode.Trim() + "-" + serial; //} //else //{ // if (newRow.SalesOrderCode != null && newRow.SalesOrderCode.Length <= styleCode.Trim().Length + 4) // { // newRow.SalesOrderCode = styleCode.Trim() + "-" + serial; // if (newRow.SalesOrderType == (decimal)Enums.SalesOrderType.AdvancedSampleRequest) // { // newRow.SalesOrderCode = styleCode.Trim() + "-" + "S" + "-" + serial; // } // } //} if (newRow.SalesOrderType == (decimal)Enums.SalesOrderType.AdvancedSampleRequest) { newRow.SalesOrderCode = styleCode.StyleCode.Trim() + "-" + "S" + "-" + serial; } else { if (newRow.SalesOrderCode == null) { newRow.SalesOrderCode = styleCode.StyleCode.Trim() + "-" + serial; } } newRow.CreationDate = DateTime.Now; newRow.LastUpdatedBy = null; newRow.LastUpdatedDate = null; newRow.SerialNo = serial; newRow.TblStyle1 = null; context.TblSalesOrders.AddObject(newRow); } else { var oldRow = (from e in context.TblSalesOrders where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { var updatedStrings = GenericUpdate(oldRow, newRow, context); //if (updatedStrings.Count() > 1 || (updatedStrings.Count() == 1 && updatedStrings.FirstOrDefault() != "LastUpdatedDate")) //{ // string code = newRow.SalesOrderCode; // newRow.SalesOrderCode = code + serial; // newRow.LastUpdatedDate = DateTime.Now; // newRow.LastUpdatedBy = LoggedUserInfo.WfmUserName; // GenericUpdate(oldRow, newRow, context); //} } } context.SaveChanges(); return(newRow); } }
public void PostPOWithPurchIDToAx(TblSalesOrder po, int userIserial) { using (var context = new WorkFlowManagerDBEntities()) { var headerObjToPost = context.TblSalesOrders.Include("TblStyle1").SingleOrDefault(x => x.Iserial == po.Iserial); var detailsObjToPost = context.TblSalesOrderColors.Include("TblSalesOrderSizeRatios").Include("TblSalesOrderSizeRatios").Where(x => x.TblSalesOrder == po.Iserial).ToList(); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } string dataarea = "CCM"; if (headerObjToPost.SalesOrderType == (int)Enums.SalesOrderType.RetailPo) { dataarea = "CCR"; } axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, dataarea, null, null, null); var inventDim = axapta.CreateAxaptaRecord("InventDim"); try { //Start Transaction axapta.TTSBegin(); var tableName = "PurchTable"; var _PurchID = headerObjToPost.SalesOrderCode; var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("PurchId", _PurchID); axaptaRecord.set_Field("DeliveryDate", headerObjToPost.DeliveryDate); var header = axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.TblSupplier) as AxaptaRecord; axaptaRecord.Call("initFromVendTable", header); axaptaRecord.Insert(); tableName = "PurchLine"; foreach (var item in detailsObjToPost) { foreach (var sizeRow in item.TblSalesOrderSizeRatios) { var styleId = headerObjToPost.TblStyle1.StyleCode; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); inventDim.Clear(); // InventDim.set_Field("InventLocationId", headerObjToPost.WareHouseID); inventDim.set_Field("InventColorId", item.TblColor1.Code); inventDim.set_Field("InventSizeId", sizeRow.Size); inventDim = axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventDim) as AxaptaRecord; var tempx = inventDim.get_Field("inventDimId").ToString(); axaptaRecord.set_Field("InventDimId", tempx); axaptaRecord.set_Field("ItemId", styleId); axaptaRecord.set_Field("purchId", _PurchID); axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString())); axaptaRecord.set_Field("PurchPrice", item.LocalCost + item.AdditionalCost); axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString())); axaptaRecord.set_Field("LineAmount", Convert.ToDecimal(sizeRow.ProductionPerSize.ToString())); axaptaRecord.Call("createLine", true, true, false, true, true, false); } } //No errors occured, Commit! //Axapta.TTSCommit(); } catch (Exception ex) { //There was some errors, Abort transaction and Raise error! //Axapta.TTSAbort(); throw new Exception(ex.Message); } finally { //Finally logoff the Axapta Session axapta.Logoff(); } } }
private void CreateEstimatedBom(TblSalesOrder row) { using (var model = new WorkFlowManagerDBEntities()) { var bom = model.BOMs.Include("BomCosts").Where(w => w.TblSalesOrder == row.Iserial); foreach (var bomLine in bom.ToList()) { float price = 0; // decimal exrate = 0; int?TransAgreementIserial = null; var currency = ""; var temp = model.TblTradeAgreementDetails.Where(x => x.ItemCode == bomLine.BOM_Fabric && x.ItemType == bomLine.BOM_FabricType && (x.TblTradeAgreementHeader1.Vendor == bomLine.Vendor || bomLine.Vendor == null)); if (temp.Any()) { price = temp.FirstOrDefault().Price; currency = temp.FirstOrDefault().CurrencyCode; TransAgreementIserial = temp.FirstOrDefault().Iserial; // exrate = GetExRateByCurrency(temp.FirstOrDefault().CurrencyCode, "CCM"); } var newrow = new BOMEstimated { BOM_DateAdded = bomLine.BOM_DateAdded, BOM_Fabric = bomLine.BOM_Fabric, BOM_FabricType = bomLine.BOM_FabricType, BOM_FabricRout = bomLine.BOM_FabricRout, Dyed = bomLine.Dyed, BOM_IsLocalProduction = bomLine.BOM_IsLocalProduction, TblSalesOrder = bomLine.TblSalesOrder, BOM_IsMainFabric = bomLine.BOM_IsMainFabric, BOM_Notes = bomLine.BOM_Notes, CalcMethod = bomLine.CalcMethod, IsSupplierMaterial = bomLine.IsSupplierMaterial, Bom = bomLine.Iserial }; model.BOMEstimateds.AddObject(newrow); model.SaveChanges(); var bomsizes = model.TblBOMSizes.Where(w => w.Bom == bomLine.Iserial); foreach (var bomsize in bomsizes.ToList()) { var newSize = new TblBOMSizeEstimated { Bom = newrow.Iserial, FabricSize = bomsize.FabricSize, MaterialUsage = bomsize.MaterialUsage, SizeFabricRatio = bomsize.SizeFabricRatio, StyleSize = bomsize.StyleSize, }; model.TblBOMSizeEstimateds.AddObject(newSize); } var bomColors = model.TblBOMStyleColors.Where(w => w.Bom == bomLine.Iserial); foreach (var bomColor in bomColors.ToList()) { if (temp.Any(x => x.TblColor == bomColor.FabricColor)) { price = temp.FirstOrDefault().Price; currency = temp.FirstOrDefault().CurrencyCode; TransAgreementIserial = temp.FirstOrDefault().Iserial; } var newColors = new TblBOMStyleColorEstimated { Bom = newrow.Iserial, StyleColor = bomColor.StyleColor, DyedColor = bomColor.DyedColor, FabricColor = bomColor.FabricColor, }; newColors.Price = price; newColors.CurrencyCode = currency; newColors.TblTradeAgreementDetail = TransAgreementIserial; model.TblBOMStyleColorEstimateds.AddObject(newColors); } foreach (var bomCost in bomLine.BomCosts) { var newCost = new BomCostEstimated { BOM_Fabric = bomCost.BOM_Fabric, BOM_FabricType = bomCost.BOM_FabricType, Bom = newrow.Iserial, FabricColor = bomCost.FabricColor, StyleColor = bomCost.StyleColor, StyleSize = bomCost.StyleSize, FabricSize = bomCost.FabricSize, MaterialUsage = bomCost.MaterialUsage, }; model.BomCostEstimateds.AddObject(newCost); } } model.SaveChanges(); } }
private bool PostBomToAx(TblSalesOrder row, int userIserial) { var credential = new NetworkCredential("bcproxy", "around1"); var success = false; try { if (SharedOperation.UseAx()) { var ax = new Axapta();//Ready To be Dependent from Ax; TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } ax.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); AxaptaObject import = ax.CreateAxaptaObject("NRunIntegration1"); var retval = import.Call("run", row.SalesOrderCode); if (retval.ToString() == "") { success = true; } ax.Logoff(); } using (var context = new WorkFlowManagerDBEntities()) { var temp = context.TblSalesOrders.Include("TblSalesOrderColors.TblSalesOrderSizeRatios").FirstOrDefault(x => x.SalesOrderCode == row.SalesOrderCode && x.SalesOrderType == 2); temp.Status = 1; foreach (var VARIABLE in temp.TblSalesOrderColors) { VARIABLE.ManualCalculationForProduction = true; VARIABLE.TotalForProduction = VARIABLE.Total; var Min = VARIABLE.TblSalesOrderSizeRatios.Where(x => x.ProductionPerSize > 0) .OrderBy(x => x.ProductionPerSize) .FirstOrDefault() .ProductionPerSize; foreach (var roww in VARIABLE.TblSalesOrderSizeRatios) { roww.ProductionPerSizeForProduction = roww.ProductionPerSize; if (VARIABLE.Total > 0 && roww.ProductionPerSize > 0) { if (roww.ProductionPerSize == Min) { roww.RatioForProduction = 1; } else { roww.RatioForProduction = (double)roww.ProductionPerSize / Min; } } else { roww.RatioForProduction = 0; } } } temp.IsPostedOnAxapta = true; context.SaveChanges(); } } catch (Exception ex) { success = false; throw ex; } return(success); }