public JsonResult GetWorkTypes(string userName, string password, string domain, string companies, string utcTime, string signatureValue) { ValidateSignature.Check(userName, password, utcTime, signatureValue); using (Axapta ax = AxaptaInstanceContainer.GetInstance(userName, new SecurityHelper().Decrypt(password, true), domain, "")) { List <WorkType> list = new List <WorkType>(); if (companies != null && companies.Length > 0) { using (AxaptaRecord workflowWorkItemTableRecord = ax.CreateAxaptaRecord("WorkflowWorkItemTable")) { using (AxaptaRecord workflowTrackingStatusTableRecord = ax.CreateAxaptaRecord("WorkflowTrackingStatusTable")) { string query = "select RecId from %1 " + "where %1.UserId == curUserId() && %1.Status == WorkflowWorkItemStatus::Pending " + "join DocumentType, ContextTableId, count(RecId) from %2 group by DocumentType, ContextTableId " + "where %1.CorrelationId == %2.CorrelationId " + "&& %2.TrackingStatus == WorkflowTrackingStatus::Pending"; ax.ExecuteStmt(query, workflowWorkItemTableRecord, workflowTrackingStatusTableRecord); string axRecCount = ax.ToString(); while (workflowWorkItemTableRecord.Found == true) { string empty = string.Empty; if (workflowTrackingStatusTableRecord.Found == true) { empty = workflowTrackingStatusTableRecord.get_Field("ContextTableId").ToString(); } if (DataAreaIncluding.Check(empty, companies)) { object contextTableId = workflowTrackingStatusTableRecord.get_Field("ContextTableId"); object documentType = workflowTrackingStatusTableRecord.get_Field("DocumentType"); object recId = workflowTrackingStatusTableRecord.get_Field("RecId"); object tblName = ax.CallStaticClassMethod("Global", "tableId2Name", recId); list.Add(new WorkType() { WorkTypeName = documentType.ToString(), WorkTypeCount = Convert.ToInt32(recId) }); workflowWorkItemTableRecord.Next(); } } } } } return(Json(list, JsonRequestBehavior.AllowGet)); } }
private void PostReportAsAFinish(int transId, int journalType, int routeCardHeaderIserial, int postPostOrNo) { using (var context = new WorkFlowManagerDBEntities()) { var routeCardHeaderRow = context .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial); var chainSetupList = context.tblChainSetups.Where(x => x.sGridHeaderEName == "Route Card").ToList(); var routeCardDetailList = context.RouteCardDetails.Where(x => x.RoutGroupID == routeCardHeaderRow.RoutGroupID && x.Trans_TransactionHeader == transId && x.Direction == routeCardHeaderRow.Direction).ToList(); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); const string tableName = "AutoRoute"; AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim"); int i = 0; try { if (routeCardDetailList.Count > 0) { foreach (var item in routeCardDetailList) { string warehouse = null; if (item.Degree == "1st") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse1st").sSetupValue; } else if (item.Degree == "2nd") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse2st").sSetupValue; } else if (item.Degree == "3rd") { warehouse = chainSetupList.SingleOrDefault(x => x.sGlobalSettingCode == "DefaultFPWarehouse3rd").sSetupValue; } var site = context.GetLocations.Where(x => x.INVENTLOCATIONID == warehouse).Select(x => x.INVENTSITEID).FirstOrDefault(); #region MyRegion axapta.ExecuteStmt("select * from %1 " + "JOIN %2" + " where %1.InventDimId == %2.InventDimId" + " && %2.ConfigID =='" + item.Color + "'" + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent); var inventDim = salesRecord.get_Field("InventDimID").ToString(); #endregion MyRegion var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("TransId", routeCardHeaderRow.Iserial); if (item.Style != null) { axaptaRecord.set_Field("ItemID", item.Style); } if (item.SalesOrder != null) { axaptaRecord.set_Field("SalesId", item.SalesOrder); } if (item.Color != null) { axaptaRecord.set_Field("Colour", item.Color); } // AxaptaRecord.set_Field("Machine", _WorkStationID); if (item.SizeQuantity != null) { axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.SizeQuantity)); } // AxaptaRecord.set_Field("Operation", _OperationID); if (routeCardHeaderRow.DocDate != null) { axaptaRecord.set_Field("DocDate", routeCardHeaderRow.DocDate); } if (warehouse != null) { axaptaRecord.set_Field("WhareHouse", warehouse); } if (warehouse != null) { axaptaRecord.set_Field("Location", warehouse); } if (site != null) { axaptaRecord.set_Field("Site", site); } axaptaRecord.set_Field("InventDimID", inventDim); axaptaRecord.set_Field("JournalType", journalType); axaptaRecord.set_Field("BatchId", "N/a"); if (item.Size != null) { axaptaRecord.set_Field("SreialId", item.Size); } if (i < 3) { i++; } axaptaRecord.Insert(); } var import = axapta.CreateAxaptaObject("CreateProductionJournals"); var retval = import.Call("CreateReportJournal", routeCardHeaderRow.Iserial, journalType, true, postPostOrNo); if (retval.ToString() == "0") { throw new Exception("Error While Posting To AX"); } else { routeCardHeaderRow.AxReportAsAFinishedJournalId = retval.ToString(); } ClearAxTable(tableName, axapta); context.SaveChanges(); } } 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(); } } }
public void PostRoutCardToAx(int routeCardHeaderIserial, int postPostOrNo) // posted=1 { using (var context = new WorkFlowManagerDBEntities()) { //int _TransID, string _WorkStationID, string _OperationID, int JournalType var routeHeaderRow = context .RouteCardHeaders.SingleOrDefault(x => x.Iserial == routeCardHeaderIserial); var operation = context.WF_RouteGroup.Where(x => x.iSerial == routeHeaderRow.RoutGroupID).Select(x => x.Code).SingleOrDefault(); var workStation = context.WF_Route.Where(x => x.iSerial == routeHeaderRow.RoutID).Select(x => x.Code).SingleOrDefault(); var detailsObjToPost = context .RealRoutCards .Where(x => x.TransID == routeHeaderRow.TransID && x.Operation == operation && x.WorkStation == workStation).ToList(); var axapta = new Axapta(); var credential = new NetworkCredential("bcproxy", "around1"); axapta.LogonAs("osama.gamal", "ccasual.loc", credential, "ccm", null, null, null); AxaptaRecord salesRecord = axapta.CreateAxaptaRecord("SalesLine"), invent = axapta.CreateAxaptaRecord("InventDim"); const string tableName = "AutoRoute"; //List<string> _TempinventDimIDList = new List<string>(); //_TempinventDimIDList.Add("00008851_086"); //_TempinventDimIDList.Add("00012748_086"); //_TempinventDimIDList.Add("00008851_086"); bool posted = false; try { if (detailsObjToPost.Count > 0) { foreach (var item in detailsObjToPost) { axapta.ExecuteStmt("select * from %1 " + "JOIN %2" + " where %1.InventDimId == %2.InventDimId" + " && %2.ConfigID =='" + item.Color + "'" + " && %1.SalesId == '" + item.SalesOrder + "'", salesRecord, invent); var inventDim = salesRecord.get_Field("InventDimID").ToString(); var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("TransId", routeCardHeaderIserial); if (item.StyleHeader != null) { axaptaRecord.set_Field("ItemID", item.StyleHeader); } if (item.SalesOrder != null) { axaptaRecord.set_Field("SalesId", item.SalesOrder); } if (item.Color != null) { axaptaRecord.set_Field("Colour", item.Color); } if (item.WorkStation != null) { axaptaRecord.set_Field("Machine", item.WorkStation); } if (item.Qty != null) { axaptaRecord.set_Field("Qty", Convert.ToDecimal(item.Qty.ToString())); } if (item.Operation != null) { axaptaRecord.set_Field("Operation", item.Operation); } if (item.DocDate != null) { axaptaRecord.set_Field("DocDate", item.DocDate); } axaptaRecord.set_Field("WhareHouse", ""); axaptaRecord.set_Field("Site", ""); if (inventDim != null) { axaptaRecord.set_Field("InventDimID", inventDim); } axaptaRecord.set_Field("JournalType", 5); if ((routeHeaderRow.RouteType == 5)) { axaptaRecord.set_Field("BatchId", "1"); axaptaRecord.set_Field("JournalType", 5); } axaptaRecord.Insert(); } var import = axapta.CreateAxaptaObject("CreateProductionJournals"); var retval = import.Call("CreateRouteJournal", routeCardHeaderIserial, workStation, operation, 5, postPostOrNo); if (retval.ToString() == "0") { throw new Exception("Error While Posting To AX"); } else { routeHeaderRow.AxRouteCardJournalId = retval.ToString(); if (postPostOrNo == 1) { posted = true; } routeHeaderRow.IsPosted = posted; } ClearAxTable(tableName, axapta); context.SaveChanges(); } } 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(); } if (routeHeaderRow.RouteType == 3) // Report AS a Finish { PostReportAsAFinish(routeHeaderRow.TransID, 3, routeCardHeaderIserial, postPostOrNo); } if (routeHeaderRow.Direction == 0) { PurchaseRouteServicesToAx(routeHeaderRow, postPostOrNo); } PickingList(routeCardHeaderIserial, postPostOrNo); } }