private void GetAllItems(string sfEstimation, int estRevID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Item__c> itemList = result.records.Cast <enterprise.Item__c>(); //show results List <string> items = new List <string>(); foreach (var il in itemList) { items.Add(il.Id); long estItemID = CommonMethods.GetMISID(TableName.EST_Item, il.Id, sfEstimation, salesForceProjectID); if (estItemID == 0) { int productID = 0; Product optionDetails = _db.Products.Where(x => x.ProductName.Trim() == il.Sign_Type__c & x.Active).FirstOrDefault(); if (optionDetails != null) { productID = optionDetails.ProductID; } var est = new MyEstItemCreate(estRevID, productID, il.Item_Name__c); if (est != null && est.EstItemID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.EST_Item, il.Id, est.EstItemID.ToString(), sfEstimation, salesForceProjectID); } estItemID = est.EstItemID; } UpdateEstItem(estItemID, il.Item_Name__c, il.Item_Order__c, il.Sign_Type__c, il.Previous_Estimation_Available__c, il.Sale_Requirement__c, il.Estimator_Description__c, il.Position__c, il.Requirement__c, il.Quantity__c, il.Item_Cost__c, il.Item_Option__c); UpdateEstItemSize(estItemID, il.Height_Feet__c, il.Height_Feet1_s__c, il.Height_Feet2_s__c, il.Height_Feet3_s__c, il.Height_Inches__c, il.Height_Inches1__c, il.Height_Inches2__c, il.Height_Inches3__c, il.Width_Feet_s__c, il.Width_Inches__c, il.Thickness_Feet_s__c, il.Thickness_Feet1_s__c, il.Thickness_Feet2_s__c, il.Thickness_Feet3_s__c, il.Thickness_Inches__c, il.Thickness_Inches1__c, il.Thickness_Inches2__c, il.Thickness_Inches3__c, il.PC_s__c, il.PC1_s__c, il.PC2_s__c, il.PC3_s__c); } /* delete old items */ DeleteAllDeletedEstimationItems(items.ToArray(), sfEstimation); LogMethods.Log.Debug("GetAllItems:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllItems:Error:" + e.Message); } }
private void HandleInvoiceService(int invoiceID, string sfInvoiceID, enterprise.QueryResult result) { try { using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } IEnumerable <enterprise.Service_Cost__c> serviceList = result.records.Cast <enterprise.Service_Cost__c>(); var svc = new FsService(invoiceID, "Invoice"); List <string> services = new List <string>(); foreach (var sl in serviceList) { services.Add(sl.Id); long estServiceID = CommonMethods.GetMISID(TableName.Fw_Quote_Service, sl.Id, sfInvoiceID, salesForceProjectID); if (estServiceID == 0) { int printOrder = svc.GetQsMaxPrintOrder() + 1; svc.InsertRecord(Convert.ToInt32(sl.Service_Name__r.MIS_Service_Number__c), sl.Service_Cost__c1 == null ? "0" : sl.Service_Cost__c1.ToString(), 1, sl.Service_Detail__c == null ? "" : sl.Service_Detail__c, sl.Service_Name__r.Name, sl.Service_Cost__c1 == null ? "0" : sl.Service_Cost__c1.ToString(), printOrder ); int qs_id = SqlCommon.GetNewlyInsertedRecordID(TableName.Fw_Quote_Service); if (qs_id > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Fw_Quote_Service, sl.Id, qs_id.ToString(), sfInvoiceID, salesForceProjectID); } } else { UpdateInvoiceService(estServiceID, sl.Service_Cost__c1, sl.Service_Detail__c, sl.Service_Name__r.Name, Convert.ToInt16(sl.Service_Name__r.MIS_Service_Number__c), sl.Note__c); } } DeleteAllDeletedInvoiceServices(services.ToArray(), sfInvoiceID); LogMethods.Log.Debug("HandleInvoiceService:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("HandleInvoiceService:Error:" + e.Message); } }
public void GetAllCheckLists(int woId, string sfWorkOrderID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Production_Check_List__c> checkList = result.records.Cast <enterprise.Production_Check_List__c>(); List <string> items = new List <string>(); foreach (var wl in checkList) { items.Add(wl.Id); int checkListID = CommonMethods.GetMISID(TableName.WO_WORKORDER_CHECKLIST_DATATABLE_PC, wl.Id, sfWorkOrderID, salesForceProjectID); if (checkListID == 0) { InsertCheckList(woId, wl.Check_List_Item__c, wl.Content__c, wl.Content_For_Check_List_Item_As_Others__c); int newId = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_WORKORDER_CHECKLIST_DATATABLE); if (newId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.WO_WORKORDER_CHECKLIST_DATATABLE_PC, wl.Id, newId.ToString(), sfWorkOrderID, salesForceProjectID); } } else { UpdateCheckListInstruction(checkListID, wl.Check_List_Item__c, wl.Content__c, wl.Content_For_Check_List_Item_As_Others__c); } } /* use the same function with Work Shop Instruction */ DeleteAllDeletedCheckLists(items.ToArray(), sfWorkOrderID); LogMethods.Log.Debug("GetAllCheckLists:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllCheckLists:Error:" + e.Message); } }
public void GetAllWorkShopInstructions(int woId, string sfWorkOrderID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.WorkShop_Instruction__c> workShopList = result.records.Cast <enterprise.WorkShop_Instruction__c>(); List <string> items = new List <string>(); foreach (var wl in workShopList) { items.Add(wl.Id); /* check if the work order exists */ int workShopID = CommonMethods.GetMISID(TableName.WO_Instruction_DataTable_PW, wl.Id, sfWorkOrderID, salesForceProjectID); if (workShopID == 0) { InsertWorkShopInstruction(woId, wl.Category__c, wl.Instruction__c, wl.Final_Instruction__c); int newId = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_Instruction_DataTable); if (newId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.WO_Instruction_DataTable_PW, wl.Id, newId.ToString(), sfWorkOrderID, salesForceProjectID); } } else { UpdateWorkShopInstruction(workShopID, wl.Category__c, wl.Instruction__c, wl.Final_Instruction__c); } } DeleteAllDeletedWorkShopInstructions(items.ToArray(), sfWorkOrderID); LogMethods.Log.Debug("GetAllWorkShopInstruction:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllWorkShopInstruction:Error:" + e.Message); } }
private void HandleNotes(int jobID, int estRevID, int quoteRevID, enterprise.QueryResult result, string sfQuoteID) { try { if (result != null) { IEnumerable <enterprise.Note__c> quoteList = result.records.Cast <enterprise.Note__c>(); List <string> notes = new List <string>(); foreach (var q in quoteList) { notes.Add(q.Id); int noteID = CommonMethods.GetMISID(TableName.Fw_Quote_Note, q.Id, sfQuoteID, salesForceProjectID); if (noteID == 0) { QuoteNoteCreateNew qnc = new QuoteNoteCreateNew(quoteRevID); qnc.Insert(); int newNoteId = SqlCommon.GetNewlyInsertedRecordID(TableName.Fw_Quote_Note); if (newNoteId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Fw_Quote_Note, q.Id, newNoteId.ToString(), sfQuoteID, salesForceProjectID); } noteID = newNoteId; } if (noteID != 0) { UpdateNote(q.Title__c, q.Content__c, noteID); } } DeleteAllDeletedQuoteNotes(notes.ToArray(), sfQuoteID); LogMethods.Log.Debug("HandleNotes:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("HandleNotes:Error:" + e.Message); } }
public void GetAllNotes(int woId, enterprise.QueryResult result, string sfWorkOrderID) { try { if (result != null) { IEnumerable<enterprise.AttachedContentNote> noteList = result.records.Cast<enterprise.AttachedContentNote>(); List<string> notes = new List<string>(); foreach (var q in noteList) { notes.Add(q.Id); int noteID = CommonMethods.GetMISID(TableName.WO_ShippingItem_SC, q.Id, sfWorkOrderID, salesForceProjectID); if (noteID == 0) { InsertNote(woId, q.Title, q.TextPreview); int newNoteId = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_ShippingItem); if (newNoteId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.WO_ShippingItem_SC, q.Id, newNoteId.ToString(), sfWorkOrderID, salesForceProjectID); } } else { UpdateNote(noteID, q.Title, q.TextPreview); } } DeleteAllDeletedNotes(notes.ToArray(), sfWorkOrderID); LogMethods.Log.Debug("GetAllNotes:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllNotes:Error:" + "Done"); } }
public void GetAllSignPermits(string sfProjectID, int jobID, int userEmployeeID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Sign_Permit__c> signPermitList = result.records.Cast <enterprise.Sign_Permit__c>(); foreach (var sp in signPermitList) { /* check if the sign permit exists */ int sign_permitID = CommonMethods.GetMISID(TableName.PermitForSignPermit, sp.Id, salesForceProjectID); if (sign_permitID == 0) { CreatePermit cpa = new CreatePermit(userEmployeeID, jobID, 10, 0); cpa.Create(); int id = cpa.NewlyInsertedID; if (id > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.PermitForSignPermit, sp.Id, id.ToString(), salesForceProjectID); } sign_permitID = id; } if (sign_permitID != 0) { HandleLandlord(sp.Id, sp.LandLord__r.BillingStreet, sp.LandLord__r.BillingCity, sp.LandLord__r.BillingState, sp.LandLord__r.BillingPostalCode, sp.LandLord_Contact__r.Name, sp.LandLord_Phone_Number__c, sp.LandLord__r.Name); UpdateSignPermit(sp.Id, sign_permitID, sp.Number_of_Signs__c, sp.Project_Value_Estimated__c, sp.Issue_Date__c, sp.Due_Date__c, sp.Remarks__c); } } LogMethods.Log.Debug("GetAllSignPermits:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllSignPermits:Error:" + e.Message); } }
public void GetAllStakeOutPermits(string sfProjectID, int jobID, int userEmployeeID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.StakeOut_Permit__c> stakeoutPermitList = result.records.Cast <enterprise.StakeOut_Permit__c>(); foreach (var sp in stakeoutPermitList) { int stakeout_permitID = CommonMethods.GetMISID(TableName.PermitForStakeout, sp.Id, salesForceProjectID); if (stakeout_permitID == 0) { CreatePermit cpa = new CreatePermit(userEmployeeID, jobID, 20, 0); cpa.Create(); int id = cpa.NewlyInsertedID; if (id > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.PermitForStakeout, sp.Id, id.ToString(), salesForceProjectID); } stakeout_permitID = id; } if (stakeout_permitID != 0) { UpdateStakeOutPermit(stakeout_permitID, sp.Stick_Position_Radius__c, sp.Dept_Of_Holes__c, sp.Issue_Date__c, sp.Due_Date__c, sp.Remarks__c); } } LogMethods.Log.Debug("GetAllStakeOutPermits:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllStakeOutPermits:Error:" + e.Message); } }
public void GetAllHoistingPermits(string sfProjectID, int jobID, int userEmployeeID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Hoisting_Permit__c> hoistingPermitList = result.records.Cast <enterprise.Hoisting_Permit__c>(); foreach (var sp in hoistingPermitList) { int hoisting_permitID = CommonMethods.GetMISID(TableName.PermitForHoisting, sp.Id, salesForceProjectID); if (hoisting_permitID == 0) { CreatePermit cpa = new CreatePermit(userEmployeeID, jobID, 30, 0); cpa.Create(); int id = cpa.NewlyInsertedID; if (id > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.PermitForHoisting, sp.Id, id.ToString(), salesForceProjectID); } hoisting_permitID = id; } if (hoisting_permitID != 0) { UpdateHoistingPermit(hoisting_permitID, sp.Issue_Date__c, sp.Occupation_Start_Time__c, sp.Occupation_End_Time__c, sp.Type_Of_Truck__c, sp.Truck_Weight__c, sp.Foreman_Name__r.Name, sp.Foreman_Phone__c, sp.Remarks__c); } } LogMethods.Log.Debug("GetAllHoistingPermits:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllHoistingPermits:Error:" + e.Message); } }
public void GetAllAccounts(string sfProjectID, int misJobID, int employeeNumber, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Bill_Quote_Install__c> billQuoteShipList = result.records.Cast <enterprise.Bill_Quote_Install__c>(); //show results foreach (var bqs in billQuoteShipList) { bool hasOne = false; if (bqs.Billing_Company_Name__r != null && bqs.Billing_Contact_Name__r != null) { HandleAccount(bqs.Billing_Company_Name__r.Name, bqs.Billing_Company_Street__c, bqs.Billing_Company_Province__c, bqs.Billing_Company_Postal_Code__c, bqs.Billing_Company_City__c, bqs.Billing_Company_Country__c, bqs.Billing_Contact_Name__r.FirstName, bqs.Billing_Contact_Name__r.LastName, bqs.Billing_Contact_Phone__c, bqs.Billing_Contact_Name__r.Id, bqs.Billing_Account_Intersection__c, bqs.Billing_Account_Corner__c, misJobID, employeeNumber, bqs.Billing_Company_Name__r.Id, 1, bqs.Billing_Company_Name__r.Legal_Name__c); hasOne = true; } if (bqs.Quoting_Company_Name__r != null && bqs.Quoting_Contact_Name__r != null) { HandleAccount(bqs.Quoting_Company_Name__r.Name, bqs.Quoting_Company_Street__c, bqs.Quoting_Company_Province__c, bqs.Quoting_Company_Postal_Code__c, bqs.Quoting_Company_City__c, bqs.Quoting_Company_Country__c, bqs.Quoting_Contact_Name__r.FirstName, bqs.Quoting_Contact_Name__r.LastName, bqs.Quoting_Contact_Phone__c, bqs.Quoting_Contact_Name__r.Id, bqs.Quoting_Account_Intersection__c, bqs.Quoting_Account_Corner__c, misJobID, employeeNumber, bqs.Quoting_Company_Name__r.Id, 2, bqs.Billing_Company_Name__r.Legal_Name__c); hasOne = true; } if (bqs.Installing_Company_Name__r != null && bqs.Installing_Contact_Name__r != null) { HandleAccount(bqs.Installing_Company_Name__r.Name, bqs.Installing_Company_Street__c, bqs.Installing_Company_Province__c, bqs.Installing_Company_Postal_Code__c, bqs.Installing_Company_City__c, bqs.Installing_Company_Country__c, bqs.Installing_Contact_Name__r.FirstName, bqs.Installing_Contact_Name__r.LastName, bqs.Installing_Contact_Phone__c, bqs.Installing_Contact_Name__r.Id, bqs.Installing_Account_Intersection__c, bqs.Installing_Account_Corner__c, misJobID, employeeNumber, bqs.Installing_Company_Name__r.Id, 3, bqs.Billing_Company_Name__r.Legal_Name__c); hasOne = true; } /* delete default row if there exists at least one bill/quote/install */ if (hasOne) { var records = _db.Sales_JobMasterList_Customer.Where(x => x.jobID == misJobID && x.cID == 0 && x.contactName == 0 && x.isBillTo == false && x.isQuoteTo == false && x.isInstallOrShipTo == false).ToList(); if (records.Any()) { foreach (var r in records) { //delete it _db.Sales_JobMasterList_Customer.Remove(r); } _db.SaveChanges(); } } } LogMethods.Log.Debug("GetAllAccounts:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllAccounts:Error:" + e.Message); } }
private void GetAllDrawingItems(string sfProjectID, int drawingRequisitionID, int estRevID, string sfDrawingID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Item__c> itemList = result.records.Cast <enterprise.Item__c>(); //show results var results = new List <MyLongKeyValueBool>(); List <string> items = new List <string>(); foreach (var il in itemList) { items.Add(il.Id); int itemIDTemp = CommonMethods.GetMISID(TableName.Sales_Dispatching_DrawingRequisition_EstimationItem, il.Id, sfDrawingID, salesForceProjectID); if (itemIDTemp == 0) { /* get item ID from EST_ITEM table */ int itemID = CommonMethods.GetEstimationItemID(estRevID, il.Item_Name__c); if (itemID != 0) { var r = new MyLongKeyValueBool(); r.Key = itemID; r.IsChecked = true; r.Value1 = il.Id; results.Add(r); } } else { UpdateDrawingItem(itemIDTemp, il.Quantity__c, il.Item_Description__c); } } if (results.Any()) { var vm = new DrawingRequisitionItemVm(); vm.RequisitionID = drawingRequisitionID; vm.AvailableEstItems = results; vm.CreateRequisitionItems(); foreach (var ret in results) { if (Convert.ToInt16(ret.Value2) > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_Dispatching_DrawingRequisition_EstimationItem, ret.Value1, ret.Value2, sfDrawingID, salesForceProjectID); } } } // delete old data DeleteAllDeletedDrawingItems(items.ToArray(), sfDrawingID); LogMethods.Log.Debug("GetAllDrawingItems:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllDrawingItems:Error:" + e.Message); } }
private void HandleQuoteItem(int jobID, int estRevID, int quoteRevID, string sfQuoteID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Item__c> itemList = result.records.Cast <enterprise.Item__c>(); List <string> items = new List <string>(); //show results foreach (var il in itemList) { items.Add(il.Id); int itemIDTemp = CommonMethods.GetMISID(TableName.Quote_Item, il.Id, sfQuoteID, salesForceProjectID); if (itemIDTemp == 0) { var qt = new QuoteTitleGenerate(jobID, estRevID); qt.MyID = quoteRevID; int itemID = CommonMethods.GetEstimationItemID(estRevID, il.Item_Name__c); if (itemID != 0) { int quoteItemID = qt.GenerateNewItems(itemID); if (quoteItemID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Quote_Item, il.Id, quoteItemID.ToString(), sfQuoteID, salesForceProjectID); itemIDTemp = quoteItemID; } } else { QuoteItemBlank qib = new QuoteItemBlank(quoteRevID); qib.CreateNew(); int quoteItemID = qib.NewID; if (quoteItemID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Quote_Item, il.Id, quoteItemID.ToString(), sfQuoteID, salesForceProjectID); itemIDTemp = quoteItemID; } } } if (itemIDTemp != 0) { UpdateQuoteItem(itemIDTemp, il.Item_Name__c, il.Requirement__c, il.Item_Description__c, il.Item_Cost__c, il.Quantity__c, il.Item_Order__c, il.Item_Option__c); } } DeleteAllDeletedQuoteItems(items.ToArray(), sfQuoteID); LogMethods.Log.Debug("HandleQuoteItem:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("HandleQuoteItem:Error:" + e.Message); } }
private void GetEstimationApprovalData(string sfEstimaitonID, int jobId, int estRevID, enterprise.QueryResult result, double?version, int employeeNumber, double?estHour, DateTime?dueDate, DateTime?dueTime, DateTime?issueDateTime) { try { if (version == null || result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>(); foreach (var el in processInstanceList) { if (el.Status == "Pending") { var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version).FirstOrDefault(); if (sales_Dispatching == null) { SubmitEstimationRequestVm vm = new SubmitEstimationRequestVm(); vm.JobID = jobId; vm.EstRevID = estRevID; vm.SubmitBy = employeeNumber; vm.EstimatorID = 8; //mr Fan if (dueDate != null) { if (dueTime != null) { TimeZone localZone = TimeZone.CurrentTimeZone; DateTime currentUTC = localZone.ToUniversalTime(dueTime.Value); DateTime localTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, currentUTC.Hour, currentUTC.Minute, 00); if (localZone.IsDaylightSavingTime(localTime)) { localTime = localTime.AddHours(-1); } vm.FormatedRequiredTime = localTime.ToString("MMM dd, yyyy hh:mm tt"); } else { vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); } } else { DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2); DateTime dt2 = DateTime.Now.AddMinutes(2); vm.FormatedRequiredTime = new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); } if (issueDateTime != null) { vm.Create(issueDateTime.Value.ToLocalTime()); } else { vm.Create(); } vm.OnEstimationSubmittedWithoutChangingEstVer(); } } else if (el.Status == "Approved") { var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version).FirstOrDefault(); if (sales_Dispatching != null) { if (estHour != null) { sales_Dispatching.WorkedHour = estHour; } sales_Dispatching.Status = 249; if (el.CompletedDate != null) { sales_Dispatching.FinishedDate = el.CompletedDate.Value.ToLocalTime(); } _db.Entry(sales_Dispatching).State = EntityState.Modified; _db.SaveChanges(); } } else if (el.Status == "Removed") { var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 201 && x.Importance == version + 1).FirstOrDefault(); if (sales_Dispatching != null) { /* delete a row in Sales_Dispatching */ _db.Sales_Dispatching.Remove(sales_Dispatching); _db.SaveChanges(); } } } } catch (Exception e) { LogMethods.Log.Error("GetEstimationApprovalData:Error:" + e.Message); } }
private void HandleInvoiceItem(int invoiceID, int estRevID, string sfInvoiceID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Item__c> itemList = result.records.Cast <enterprise.Item__c>(); List <string> items = new List <string>(); //show results foreach (var il in itemList) { items.Add(il.Id); int itemIDTemp = CommonMethods.GetMISID(TableName.Invoice_Item, il.Id, sfInvoiceID, salesForceProjectID); if (itemIDTemp == 0) { InvoiceItemBlank inv = new InvoiceItemBlank(invoiceID); inv.CreateNew(); int newId = SqlCommon.GetNewlyInsertedRecordID(TableName.Invoice_Item); if (newId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Invoice_Item, il.Id, newId.ToString(), sfInvoiceID, salesForceProjectID); } itemIDTemp = newId; } if (itemIDTemp != 0) { UpdateInvoiceItem(estRevID, il.Id, itemIDTemp, il.Item_Name__c, il.Requirement__c, il.Item_Description__c, il.Item_Cost__c, il.Quantity__c, il.Item_Order__c); } } /* delete work order items which has been removed out of work order */ DeleteAllDeletedInvoiceItems(items.ToArray(), sfInvoiceID); LogMethods.Log.Debug("HandleInvoiceItem:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("HandleInvoiceItem:Error:" + e.Message); } }
public void GetAllSubContracts(string sfProjectID, int jobID, int userEmployeeID, enterprise.QueryResult result) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.SubContract__c> subContractList = result.records.Cast <enterprise.SubContract__c>(); List <string> items = new List <string>(); foreach (var sp in subContractList) { items.Add(sp.Id); /* check if the sign permit exists */ int subContractID = CommonMethods.GetMISID(TableName.SubContract, sp.Id, salesForceProjectID); if (subContractID == 0) { SubContractDomain.Model.SubContract sc = new SubContractDomain.Model.SubContract(); sc.JobID = jobID; sc.RequestDate = DateTime.Now; sc.RequestBy = userEmployeeID; sc.StatusID = 0; sc.ContactPerson1 = 0; sc.ContactPerson2 = 0; sc.Budget = 0; sc.Remark = ""; sc.TargetDate = DateTime.Today; sc.RequirementID = 0; sc.Requirement = ""; SubContractCreate scCreate = new SubContractCreate(userEmployeeID); scCreate.Create(sc); subContractID = scCreate.NewlyInsertedID; if (subContractID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.SubContract, sp.Id, subContractID.ToString(), salesForceProjectID); } } if (subContractID != 0) { UpdateSubContract(subContractID, salesForceProjectID, sp.First_Site_Contact__c, sp.Second_Site_Contact__c, sp.Budget__c, sp.Provided_By__c, sp.Remarks__c, sp.Due_Date__c, sp.Rush__c, sp.Requirement__c, sp.Requirement_As_Other__c, sp.Estimated_Shipping_Cost__c, sp.Shipping_Items_Total_Value__c, sp.Work_Order_Number__c); } } DeleteAllDeletedSubContracts(items.ToArray()); LogMethods.Log.Debug("GetAllSubContracts:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllSubContracts:Error:" + e.Message); } }
private void HandleApprovalStatus(string sfWorkOrderID, int jobId, int estRevID, int woId, int userEmployeeID, string remarks, DateTime?dueDate, string rush, string woType, enterprise.QueryResult result, double?version, DateTime?issueDateTime) { try { if (version == null) { return; } short ver = Convert.ToInt16(version); var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == 720 && x.WoID == woId && x.Importance == ver).FirstOrDefault(); if (sales_Dispatching == null) { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>(); //show results foreach (var el in processInstanceList) { if (el.Status == "Pending") { int taskCategory = 720; //-- [Work order Approval] is defined in Sales_Dispatching_Task_Category int submitBy = userEmployeeID; string taskFromWhere = "wip"; // coresponding to stage of 2 TaskSubmitFactory foTaskSubmit = new TaskSubmitFactory(taskCategory, submitBy, taskFromWhere); TaskSubmit dp = foTaskSubmit.ObjTaskSubmit; dp.ParameterDispatchingTask.Responsible = 8; // Mr. Fan is approved it dp.ParameterDispatchingTask.JobId = jobId; dp.ParameterDispatchingTask.EstRevId = estRevID; dp.ParameterDispatchingTask.WoId = woId; dp.ParameterDispatchingTask.Subject = "Workorder approval"; //DispatchingTaskEN.NDispatchingTaskPurpose.WorkorderApproval if (!string.IsNullOrEmpty(remarks)) { dp.ParameterDispatchingTask.Description = remarks.Trim(); } if (dueDate != null) { dp.ParameterDispatchingTask.RequiredTime = (DateTime)dueDate; } else { dp.ParameterDispatchingTask.RequiredTime = DateTime.Now.AddDays(1); } if (issueDateTime != null) { dp.ParameterDispatchingTask.SubmitTime = issueDateTime.Value.ToLocalTime(); } else { dp.ParameterDispatchingTask.SubmitTime = DateTime.Now; } switch (rush) { case "Yes": dp.ParameterDispatchingTask.Rush = true; break; default: dp.ParameterDispatchingTask.Rush = false; break; } switch (woType) { case "Production": dp.ParameterDispatchingTask.WorkorderType = 10; break; case "Service": dp.ParameterDispatchingTask.WorkorderType = 20; break; case "Site Check": dp.ParameterDispatchingTask.WorkorderType = 30; break; default: break; } dp.EnableDuplicateSubmit = true; dp.Insert(ver); } } LogMethods.Log.Debug("HandleApprovalStatus:Debug:" + "Done"); } } else { // this work order has been submitted using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>(); //show results foreach (var el in processInstanceList) { if (el.Status == "Removed") { var workOrder = _db.Sales_JobMasterList_WO.Where(x => x.woID == sales_Dispatching.WoID).FirstOrDefault(); if (workOrder != null) { workOrder.woStatus = (short)NJobStatus.woNew; } _db.Entry(workOrder).State = EntityState.Modified; _db.SaveChanges(); /* delete a row in Sales_Dispatching */ _db.Sales_Dispatching.Remove(sales_Dispatching); _db.SaveChanges(); } } } } } catch (Exception e) { LogMethods.Log.Error("HandleApprovalStatus:Error:" + e.Message); } }
private void HandleWorkOrderItem(int workOrderID, int estRevID, string sfWorkOrderID, enterprise.QueryResult result, string woType) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Item__c> itemList = result.records.Cast <enterprise.Item__c>(); List <string> items = new List <string>(); //show results foreach (var il in itemList) { items.Add(il.Id); int itemIDTemp = CommonMethods.GetMISID(TableName.WO_Item, il.Id, sfWorkOrderID, salesForceProjectID); if (itemIDTemp == 0) { WokrorderItemGenerateFromBlank woItem = new WokrorderItemGenerateFromBlank(workOrderID); // no error if (woItem.ValidationID == 0) { woItem.InsertItem(); int newWOItemID = woItem.NewWorkItemID; if (newWOItemID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.WO_Item, il.Id, newWOItemID.ToString(), sfWorkOrderID, salesForceProjectID); } itemIDTemp = newWOItemID; } } if (itemIDTemp != 0) { UpdateWorkOrderItem(estRevID, il.Id, itemIDTemp, il.Item_Name__c, il.Requirement__c, il.Item_Description__c, il.Item_Cost__c, il.Quantity__c, il.Item_Order__c, il.PC_s__c, il.Sign_Type__c); //Update Leadtime Table UpdateLeadtimetable(itemIDTemp, woType); } } /* delete work order items which has been removed out of work order */ DeleteAllDeletedWorkOrderItems(items.ToArray(), sfWorkOrderID); LogMethods.Log.Debug("HandleWorkOrderItem:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("HandleWorkOrderItem:Error:" + e.Message); } }
private void GetDrawingApprovalData(int jobId, enterprise.QueryResult result, double?version, int employeeNumber, double?drawHour, DateTime?dueDate, int requisitionId, string drawingType, string sfDrawingID, double?NumofDrawings, DateTime?dueTime, DateTime?issueDateTime) { try { if (version == null || result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.ProcessInstance> processInstanceList = result.records.Cast <enterprise.ProcessInstance>(); foreach (var el in processInstanceList) { int taskType = 501; short taskStatus = 549; if (drawingType.Trim() == "Structure") { taskType = 551; taskStatus = 599; } if (el.Status == "Pending") { int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID); if (drawingID == 0) { //not exist var vm = new SubmitDrawingRequestVm(requisitionId, employeeNumber); if (dueDate != null) { if (dueTime != null) { TimeZone localZone = TimeZone.CurrentTimeZone; DateTime currentUTC = localZone.ToUniversalTime(dueTime.Value); DateTime localTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, currentUTC.Hour, currentUTC.Minute, 00); if (localZone.IsDaylightSavingTime(localTime)) { localTime = localTime.AddHours(-1); } vm.FormatedRequiredTime = localTime.ToString("MMM dd, yyyy hh:mm tt"); } else { vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); } } else { DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2); DateTime dt2 = DateTime.Now.AddMinutes(2); vm.FormatedRequiredTime = new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); } long taskID; if (issueDateTime == null) { taskID = vm.Create(); } else { taskID = vm.Create(issueDateTime.Value.ToLocalTime()); } if (taskID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_Dispatching, sfDrawingID, taskID.ToString(), salesForceProjectID); } } /* * var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.JobID == jobId && x.TaskType == taskType && x.Importance == version).FirstOrDefault(); * if (sales_Dispatching == null) * { * var vm = new SubmitDrawingRequestVm(requisitionId, employeeNumber); * if (dueDate != null) * { * vm.FormatedRequiredTime = new DateTime(dueDate.Value.Year, dueDate.Value.Month, dueDate.Value.Day, dueDate.Value.Hour, dueDate.Value.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); * } * else * { * DateTime dt1 = MyDateTime.GetDateOfAddedBusinessDays(DateTime.Today, 2); * DateTime dt2 = DateTime.Now.AddMinutes(2); * vm.FormatedRequiredTime = * new DateTime(dt1.Year, dt1.Month, dt1.Day, dt2.Hour, dt2.Minute, 00).ToString("MMM dd, yyyy hh:mm tt"); * } * vm.Create(); * } * */ } else if (el.Status == "Approved") { int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID); if (drawingID > 0) { var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.TaskID == drawingID).FirstOrDefault(); if (sales_Dispatching != null) { if (drawHour != null) { sales_Dispatching.WorkedHour = drawHour; } if (NumofDrawings != null) { sales_Dispatching.NumberOfDrawing = Convert.ToInt32(NumofDrawings); } sales_Dispatching.Status = taskStatus; if (el.CompletedDate != null) { sales_Dispatching.FinishedDate = el.CompletedDate.Value.ToLocalTime(); } _db.Entry(sales_Dispatching).State = EntityState.Modified; _db.SaveChanges(); } } } else if (el.Status == "Removed") { int drawingID = CommonMethods.GetMISID(TableName.Sales_Dispatching, sfDrawingID, salesForceProjectID); if (drawingID > 0) { var sales_Dispatching = _db.Sales_Dispatching.Where(x => x.TaskID == drawingID).FirstOrDefault(); if (sales_Dispatching != null) { /* delete a row in Sales_Dispatching */ _db.Sales_Dispatching.Remove(sales_Dispatching); _db.SaveChanges(); } } } } } catch (Exception e) { LogMethods.Log.Error("GetDrawingApprovalData:Error:" + e.Message); } }