public void GetEstimation(string sfProjectID, int estRevID, int jobID, int employeeNumber) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Name, Cost__c, Remarks__c, Version__c, Temp_Estimation_Hour__c, Target_Date__c, Due_Time__c, Issue_Date_Time__c, " + " (SELECT Status, LastActor.Name, CompletedDate FROM ProcessInstances order by CompletedDate desc limit 1)," + " (SELECT Id, Name, Item_Order__c, Category__c, Sign_Type__c, Feature_1__c, Feature_2__c, Graphic__c, Item_Name__c, Previous_Estimation_Available__c, Sale_Requirement__c, Estimator_Description__c, Position__c, Requirement__c, Quantity__c, Item_Cost__c, Height_Feet__c, Height_Feet1_s__c, Height_Feet2_s__c, Height_Feet3_s__c, Height_Inches__c, Height_Inches1__c, Height_Inches2__c, Height_Inches3__c, Width_Feet_s__c, Width_Inches__c, Thickness_Feet_s__c, Thickness_Feet1_s__c, Thickness_Feet2_s__c, Thickness_Feet3_s__c, Thickness_Inches__c, Thickness_Inches1__c, Thickness_Inches2__c, Thickness_Inches3__c, PC_s__c, PC1_s__c, PC2_s__c, PC3_s__c, Item_Option__c FROM Items__r)," + " (SELECT Id, Service_Name__r.Name, Service_Detail__c, Service_Cost__c, Note__c, Service_Name__r.MIS_Service_Number__c FROM Service_Costs__r) " + " FROM Estimation__c " + " WHERE Project_Name__c = '" + sfProjectID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } if (result == null || (result != null && result.size == 0)) { return; } //cast query results IEnumerable <enterprise.Estimation__c> estimationList = result.records.Cast <enterprise.Estimation__c>(); //show results foreach (var el in estimationList) { /* item */ GetAllItems(el.Id, estRevID, el.Items__r); /* services */ ServiceMethods sm = new ServiceMethods(salesForceProjectID); sm.GetAllServices(el.Id, estRevID, el.Service_Costs__r); UpdateEstimation(estRevID, el.Cost__c, el.Remarks__c, el.Version__c); GetEstimationApprovalData(el.Id, jobID, estRevID, el.ProcessInstances, el.Version__c, employeeNumber, el.Temp_Estimation_Hour__c, el.Target_Date__c, el.Due_Time__c, el.Issue_Date_Time__c); } LogMethods.Log.Debug("GetEstimation:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetEstimation:Error:" + e.Message); } }
public void GetAllInspectorInstructions(int woId, string sfWorkOrderID) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Category__c, Final_Instruction__c, Instruction__c " + " FROM Inspector_Instruction__c where Work_Order_Name__c = '" + sfWorkOrderID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) return; //cast query results IEnumerable<enterprise.Inspector_Instruction__c> inspectorList = result.records.Cast<enterprise.Inspector_Instruction__c>(); List<string> items = new List<string>(); foreach (var wl in inspectorList) { items.Add(wl.Id); /* check if the work order exists */ int workShopID = CommonMethods.GetMISID(TableName.WO_Instruction_DataTable_SC_I, wl.Id, sfWorkOrderID, salesForceProjectID); if (workShopID == 0) { InsertInspectorInstruction(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_SC_I, wl.Id, newId.ToString(), sfWorkOrderID, salesForceProjectID); } } else { UpdateInspectorInstruction(workShopID, wl.Category__c, wl.Instruction__c, wl.Final_Instruction__c); } } DeleteAllDeletedInspectorInstructions(items.ToArray(), sfWorkOrderID); LogMethods.Log.Debug("GetAllInspectorInstructions:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllInspectorInstructions:Error:" + e.Message); } }
public void GetAllCheckLists(int woId, string sfWorkOrderID) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Check_List_Item__c, Content__c " + " FROM Site_Check_Check_List__c where Work_Order_Name__c = '" + sfWorkOrderID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) return; //cast query results IEnumerable<enterprise.Site_Check_Check_List__c> checkList = result.records.Cast<enterprise.Site_Check_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_SC_C, wl.Id, sfWorkOrderID, salesForceProjectID); if (checkListID == 0) { InsertCheckList(woId, wl.Check_List_Item__c, wl.Content__c); int newId = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_WORKORDER_CHECKLIST_DATATABLE); if (newId > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.WO_WORKORDER_CHECKLIST_DATATABLE_SC_C, wl.Id, newId.ToString(), sfWorkOrderID, salesForceProjectID); } } else { UpdateCheckListInstruction(checkListID, wl.Check_List_Item__c, wl.Content__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 GetAllWorkOrders(string sfProjectID, int jobID, int estRevID, int userEmployeeID) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Name, Work_Order_Number__c, (select Id, Title, TextPreview from AttachedContentNotes), RecordType.Name, Work_Order_Type__c, Payment_Method__c, Version__c, Rush__c, Rush_Reason__c, Remarks__c, Project_Name__r.Account_Executive__r.CommunityNickname, " + " Issue_Date__c, Issue_Date_Time__c, Due_Date__c, Clone_Type__c, Previous_Work_Order_Number__r.Name, Site_Check_Purpose__c, Site_Check_Purpose_As_Other__c, Amount__c, Previous_Work_Order_Number__r.Clone_Type__c, Previous_Work_Order_Number__r.Version__c, Previous_Work_Order_Number__r.Work_Order_Number__c, Revise_WO_Count__c, " + " (SELECT Status, LastActor.Name, CompletedDate FROM ProcessInstances order by CompletedDate desc limit 1)," + " (SELECT Id, Item_Name__c, Item_Order__c, Sign_Type__c, Requirement__c, Item_Description__c, Item_Cost__c, Quantity__c FROM Items__r)," + " (SELECT Id, Category__c, Final_Instruction__c, Instruction__c FROM WorkShop_Instructions__r)," + " (SELECT Id, Category__c, Final_Instruction__c, Instruction__c FROM Installer_Instructions__r)," + " (SELECT Id, Check_List_Item__c, Content__c, Content_For_Check_List_Item_As_Others__c FROM Production_Check_List__r)," + " (SELECT Id, Category__c, Final_Instruction__c, Instruction__c FROM Servicer_Instructions__r)," + " (SELECT Id, Check_List_Item__c, Content__c, Content_For_Check_List_Item_As_Others__c FROM Service_Check_Lists__r)" + " FROM Work_Order__c " + " WHERE Project_Name__c = '" + sfProjectID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } //cast query results IEnumerable <enterprise.Work_Order__c> workOrderList = result.records.Cast <enterprise.Work_Order__c>(); foreach (var ql in workOrderList) { /* check if the work order exists */ int workOrderID = CommonMethods.GetMISID(TableName.Sales_JobMasterList_WO, ql.Id, salesForceProjectID); if (workOrderID == 0) { // not exist WorkorderGenerateFromEstimation gw = new WorkorderGenerateFromEstimation(jobID, estRevID); gw.CreateNew(); workOrderID = gw.WoID; if (workOrderID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_JobMasterList_WO, ql.Id, workOrderID.ToString(), salesForceProjectID); } } if (workOrderID != 0) { UpdateWorkOrder(workOrderID, ql.Work_Order_Number__c, ql.RecordType.Name, ql.Payment_Method__c, ql.Version__c, ql.Rush__c, ql.Rush_Reason__c, ql.Remarks__c, ql.Issue_Date__c, ql.Due_Date__c, ql.Clone_Type__c, ql.Previous_Work_Order_Number__r, ql.Site_Check_Purpose__c, ql.Site_Check_Purpose_As_Other__c, ql.Id, ql.Amount__c, ql.Revise_WO_Count__c, ql.Project_Name__r.Account_Executive__r); // generate work order items HandleWorkOrderItem(workOrderID, estRevID, ql.Id, ql.Items__r, ql.RecordType.Name); switch (ql.RecordType.Name) { case "Production": ProductionWOMethods pm = new ProductionWOMethods(salesForceProjectID); pm.GetAllWorkShopInstructions(workOrderID, ql.Id, ql.WorkShop_Instructions__r); pm.GetAllInstallerInstructions(workOrderID, ql.Id, ql.Installer_Instructions__r); pm.GetAllCheckLists(workOrderID, ql.Id, ql.Production_Check_List__r); pm.GetAllNotes(workOrderID, ql.AttachedContentNotes, ql.Id); break; case "Service": ServiceWOMethods sm = new ServiceWOMethods(salesForceProjectID); sm.GetAllWorkShopInstructions(workOrderID, ql.Id, ql.WorkShop_Instructions__r); sm.GetAllServicerInstructions(workOrderID, ql.Id, ql.Servicer_Instructions__r); sm.GetAllCheckLists(workOrderID, ql.Id, ql.Service_Check_Lists__r); sm.GetAllNotes(workOrderID, ql.AttachedContentNotes, ql.Id); break; case "Site Check": SiteCheckWOMethods scm = new SiteCheckWOMethods(salesForceProjectID); scm.GetAllInspectorInstructions(workOrderID, ql.Id); scm.GetAllCheckLists(workOrderID, ql.Id); scm.GetAllNotes(workOrderID, ql.AttachedContentNotes, ql.Id); break; default: break; } /* check if the work order is approved */ HandleApprovalStatus(ql.Id, jobID, estRevID, workOrderID, userEmployeeID, ql.Remarks__c, ql.Due_Date__c, ql.Rush__c, ql.RecordType.Name, ql.ProcessInstances, ql.Version__c, ql.Issue_Date_Time__c); } } LogMethods.Log.Debug("GetAllWorkOrders:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllWorkOrders:Error:" + e.Message); } }
private void UpdateWorkOrderItem(int estRevID, string salesforceItemID, long workOrderItemID, string itemName, string requirement, string description, double?itemCost, double?quality, double?itemOrder, string PC, string signType) { try { var workOrderItem = _db.WO_Item.Where(x => x.woItemID == workOrderItemID).FirstOrDefault(); if (workOrderItem != null) { workOrderItem.estItemNameText = itemName; int requirementID = 10; var jobType = _db.FW_JOB_TYPE.Where(x => x.JOB_TYPE.Trim() == requirement.Trim()).FirstOrDefault(); if (jobType != null) { requirementID = jobType.TYPE_ID; } else { LogMethods.Log.Warn("UpdateWorkOrderItem:Warn:" + "Requirement of " + requirement + " doesn't exist on FW_JOB_TYPE table."); } workOrderItem.Requirement = requirementID; workOrderItem.woDescription = description; if (quality != null) { workOrderItem.qty = Convert.ToInt16(quality); } if (PC != null) { workOrderItem.qtyPC = Convert.ToInt16(PC); } else { workOrderItem.qtyPC = 0; } if (itemCost != null) { workOrderItem.qiAmount = (double)itemCost; } long estItemID = CommonMethods.GetEstimationItemID(estRevID, itemName); if (estItemID != 0) { workOrderItem.estItemID = estItemID; } if (itemOrder != null) { workOrderItem.woPrintOrder = Convert.ToInt16(itemOrder); } Product optionDetails = _db.Products.Where(x => x.ProductName.Trim() == signType & x.Active).FirstOrDefault(); if (optionDetails != null) { workOrderItem.NameDetailsID = optionDetails.ProductID; } _db.Entry(workOrderItem).State = EntityState.Modified; _db.SaveChanges(); //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Purpose__c, Type__c, Hyperlink__c " + " FROM Drawing_Attachment__c " + " WHERE Item_Number__c = '" + salesforceItemID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } //cast query results IEnumerable <enterprise.Drawing_Attachment__c> drawingAttachmentList = result.records.Cast <enterprise.Drawing_Attachment__c>(); List <string> items = new List <string>(); foreach (var ql in drawingAttachmentList) { items.Add(ql.Id); /* check if the work order exists */ int drawingAttachmentID = CommonMethods.GetMISID(TableName.WO_Item_Drawing, ql.Id, salesforceItemID, salesForceProjectID); int purpose = 1; switch (ql.Purpose__c) { case "Concept Design": purpose = 4; break; case "Permit Drawing": purpose = 2; break; case "Work-Order Drawing": purpose = 3; break; } /* remove special character */ string hyperlink = ql.Hyperlink__c.TrimStart(); while (hyperlink[0] != 'P' && hyperlink[0] != 'K' && hyperlink[0] != 'Q' && hyperlink[0] != 'H') { hyperlink = hyperlink.Substring(1); } string fileName = ""; try { fileName = Path.GetFileNameWithoutExtension(hyperlink); } catch (Exception e) { fileName = ""; } if (drawingAttachmentID == 0) { InsertItemLink(workOrderItemID, hyperlink, purpose, ql.Type__c, fileName); int temp = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_Item_Drawing); CommonMethods.InsertToMISSalesForceMapping(TableName.WO_Item_Drawing, ql.Id, temp.ToString(), salesforceItemID, salesForceProjectID); } else { UpdateItemLink(drawingAttachmentID, hyperlink, purpose, ql.Type__c, fileName); } } DeleteAllDeletedDrawingAttachments(items.ToArray(), salesforceItemID); LogMethods.Log.Debug("UpdateWorkOrderItem:Debug:" + "Done"); } } } catch (Exception e) { LogMethods.Log.Error("UpdateWorkOrderItem:Error:" + e.Message); } }
public void GetAllProjects() { try { LogMethods.Log.Info("GetAllProjects:Info:" + "Start processing all projects"); //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Project_Number__c, Name, CloseDate, Type, OwnerId, Owner.CommunityNickname, Bidding_Type__c, Bidding_Source__c, Product_Line__c, Middle_Updated_Flag__c, " + " Bidding_Due_Date__c, Bidding_Remark__c, Sync__c, Account_Executive__r.CommunityNickname, Project_Coordinator__r.CommunityNickname, " + " (SELECT Id, Name, Billing_Company_City__c, Billing_Contact_Name__r.Account.Id, Billing_Company_Name__r.Name, Billing_Company_Name__r.Id, Billing_Company_Postal_Code__c, Billing_Company_Province__c, Billing_Company_Street__c, Billing_Contact_Name__r.FirstName, Billing_Contact_Name__r.LastName, Billing_Contact_Name__r.Id, Billing_Contact_Phone__c, Billing_Company_Country__c, Quoting_Company_City__c, Quoting_Company_Name__r.Name, Quoting_Company_Name__r.Id, Quoting_Contact_Name__r.Account.Id, Quoting_Company_Postal_Code__c, Quoting_Company_Province__c, Quoting_Company_Street__c, Quoting_Contact_Name__r.FirstName, Quoting_Contact_Name__r.LastName, Quoting_Contact_Name__r.Id, Quoting_Contact_Phone__c, Quoting_Company_Country__c,Installing_Company_City__c, Installing_Company_Name__r.Name, Installing_Company_Name__r.Id, Installing_Contact_Name__r.Account.Id, Installing_Company_Postal_Code__c, Installing_Company_Province__c, Installing_Company_Street__c, Installing_Contact_Name__r.FirstName, Installing_Contact_Name__r.LastName, Installing_Contact_Name__r.Id, Installing_Contact_Phone__c, Installing_Company_Country__c, Billing_Account_Intersection__c, Billing_Account_Corner__c, Installing_Account_Intersection__c,Installing_Account_Corner__c,Quoting_Account_Intersection__c,Quoting_Account_Corner__c,Billing_Company_Name__r.Legal_Name__c FROM Bill_Quote_Ships__r), " + " (SELECT Id, Number_of_Signs__c, Project_Value_Estimated__c, Remarks__c, Issue_Date__c, Due_Date__c, LandLord__r.Name, LandLord_Contact__r.Name, LandLord_Phone_Number__c, LandLord__r.BillingStreet, LandLord__r.BillingCity, LandLord__r.BillingState, LandLord__r.BillingPostalCode FROM Sign_Permits__r)," + " (SELECT Id, Occupation_Start_Time__c, Occupation_End_Time__c, Issue_Date__c, Type_Of_Truck__c, Truck_Weight__c, Foreman_Name__r.Name, Foreman_Phone__c, Remarks__c FROM Hoisting_Permits__r)," + " (SELECT Id, Stick_Position_Radius__c, Dept_Of_Holes__c, Issue_Date__c, Due_Date__c, Remarks__c FROM StakeOut_Permits__r)," + " (SELECT Id, Name, First_Site_Contact__c, Second_Site_Contact__c, Budget__c, Provided_By__c, Remarks__c, Due_Date__c, Rush__c, Requirement__c, Requirement_As_Other__c, Estimated_Shipping_Cost__c, Shipping_Items_Total_Value__c, Work_Order_Number__c FROM SubContracts__r) " + " FROM Opportunity " + " WHERE Sync__c = true and Middle_Updated_Flag__c = 1 "; //+ " WHERE name= '2131 Yonge Street - Exterior and Interior Signage Program'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } //cast query results IEnumerable <enterprise.Opportunity> opportunityList = result.records.Cast <enterprise.Opportunity>(); /* * enterprise.Opportunity[] opp = new enterprise.Opportunity[result.size]; * int i = 0; * foreach (var opportunity in opportunityList) * { * enterprise.Opportunity temp = new enterprise.Opportunity(); * temp.Id = opportunity.Id; * temp.Middle_Updated_Flag__c = 0; * temp.Middle_Updated_Flag__cSpecified = true; * opp[i] = temp; * i++; * } * enterprise.LimitInfo[] l1; * enterprise.SaveResult[] s1; * queryClient.update(header, null, null, null, null, null, null, null, null, null, null, null, null, opp, out l1, out s1); * */ int size = result.size; int j = 1; int k = 0; while (j <= size) { int limitArray = (size > 150) ? 150 : size; size -= limitArray; enterprise.Opportunity[] opp = new enterprise.Opportunity[limitArray]; int i = 0; for (int m = k; m < k + limitArray; m++) { enterprise.Opportunity temp = new enterprise.Opportunity(); temp.Id = opportunityList.ElementAt(m).Id; temp.Middle_Updated_Flag__c = 0; temp.Middle_Updated_Flag__cSpecified = true; opp[i] = temp; i++; } k += limitArray; enterprise.LimitInfo[] l1; enterprise.SaveResult[] s1; queryClient.update(header, null, null, null, null, null, null, null, null, null, null, null, null, opp, out l1, out s1); } //show results foreach (var opportunity in opportunityList) { /* get project owner */ //string un = CommonMethods.GetUserName(opportunity.OwnerId); string un = (opportunity.Owner.CommunityNickname == null ? "" : opportunity.Owner.CommunityNickname); FsEmployee fsEmployee = new FsEmployee(un); if (fsEmployee.EmployeeNumber > 0) { LogMethods.Log.Info("GetAllProjects:Info:" + "Processing project name:" + opportunity.Name); int sales_JobMasterListID = CommonMethods.GetMISID(TableName.Sales_JobMasterList, opportunity.Id, opportunity.Id); if (sales_JobMasterListID == 0) { int jobID = CreateNewProject(fsEmployee.EmployeeNumber); /* insert data to MISSalesForceMapping */ if (jobID > 0) { UpdateProject(jobID, opportunity.CloseDate, fsEmployee.EmployeeNumber, opportunity.Name, opportunity.Type, opportunity.Account_Executive__r, opportunity.Product_Line__c, opportunity.Project_Coordinator__r); /* update jobnumber */ UpdateJobNumber(jobID, opportunity.Project_Number__c); CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_JobMasterList, opportunity.Id, jobID.ToString(), opportunity.Id); } else { LogMethods.Log.Error("GetAllProjects:Error:" + "Cannot create a new project!"); continue; } sales_JobMasterListID = jobID; } else { UpdateProject(sales_JobMasterListID, opportunity.CloseDate, fsEmployee.EmployeeNumber, opportunity.Name, opportunity.Type, opportunity.Account_Executive__r, opportunity.Product_Line__c, opportunity.Project_Coordinator__r); } /* for bidding project */ if (opportunity.Type == SalesType.Bid) { /* check if the bidding record exists */ int biddingID = GetBiddingID(sales_JobMasterListID); if (biddingID > 0) { //exist UpdateBiddingProject(biddingID, sales_JobMasterListID, opportunity.Bidding_Type__c, opportunity.Bidding_Source__c, opportunity.Bidding_Due_Date__c, opportunity.Bidding_Remark__c); } else { InsertBiddingProject(fsEmployee.EmployeeNumber); UpdateBiddingProject(SqlCommon.GetNewlyInsertedRecordID("Sales_JobMaster_BiddingJob"), Convert.ToInt32(sales_JobMasterListID), opportunity.Bidding_Type__c, opportunity.Bidding_Source__c, opportunity.Bidding_Due_Date__c, opportunity.Bidding_Remark__c); } } /* Bill-Quote-Ship */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing account and contact"); CustomerMethods cm = new CustomerMethods(opportunity.Id); cm.GetAllAccounts(opportunity.Id, sales_JobMasterListID, fsEmployee.EmployeeNumber, opportunity.Bill_Quote_Ships__r); /* Estimation */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing estimation"); EstimationMethods em = new EstimationMethods(opportunity.Id); int estRevID = CommonMethods.GetEstRevID(sales_JobMasterListID); em.GetEstimation(opportunity.Id, estRevID, sales_JobMasterListID, fsEmployee.EmployeeNumber); /*Drawing */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing drawing"); DrawingMethods dm = new DrawingMethods(opportunity.Id); dm.GetAllDrawings(opportunity.Id, estRevID, sales_JobMasterListID, fsEmployee.EmployeeNumber); /* Quote */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing quote"); QuoteMethods qm = new QuoteMethods(opportunity.Id); qm.GetAllQuotes(opportunity.Id, sales_JobMasterListID, estRevID, fsEmployee.EmployeeNumber); /* Sign/Hoisting/Stakeout permit */ PermitMethods pm = new PermitMethods(opportunity.Id); LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing sign permit"); pm.GetAllSignPermits(opportunity.Id, sales_JobMasterListID, fsEmployee.EmployeeNumber, opportunity.Sign_Permits__r); LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing hoisting permit"); pm.GetAllHoistingPermits(opportunity.Id, sales_JobMasterListID, fsEmployee.EmployeeNumber, opportunity.Hoisting_Permits__r); LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing stakeout permit"); pm.GetAllStakeOutPermits(opportunity.Id, sales_JobMasterListID, fsEmployee.EmployeeNumber, opportunity.StakeOut_Permits__r); /* WorkOrder */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing work order"); WorkOrderMethods wo = new WorkOrderMethods(opportunity.Id); wo.GetAllWorkOrders(opportunity.Id, sales_JobMasterListID, estRevID, fsEmployee.EmployeeNumber); /* Sub-Contract */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing SubContract"); SubContractMethods sc = new SubContractMethods(opportunity.Id); sc.GetAllSubContracts(opportunity.Id, sales_JobMasterListID, fsEmployee.EmployeeNumber, opportunity.SubContracts__r); /* Invoice */ LogMethods.Log.Debug("GetAllProjects:Debug:" + "Processing invoice"); InvoiceMethods im = new InvoiceMethods(opportunity.Id); im.GetAllInvoices(opportunity.Id, sales_JobMasterListID, estRevID, fsEmployee.EmployeeNumber); LogMethods.Log.Info("GetAllProjects:Info:" + "Done: " + opportunity.Name + "<Project Num:" + opportunity.Project_Number__c + ">"); } else { LogMethods.Log.Error("GetAllProjects:Error:" + "User Name: " + un + " does not exist in database"); } } LogMethods.Log.Info("GetAllProjects:Info:" + "All projects are done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllProjects:Error:" + e.Message); } }
public void GetAllDrawings(string sfProjectID, int estRevID, int jobID, int employeeNumber) { try { using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Name, Version__c, Drawing_Requisition_Type__c, Drawing_Purpose__c, Is_Electronic_File_From_Client_Available__c, " + " Is_GC_Or_Designer_Drawing_Available__c, Is_Landord_Or_Mall_Criteria_Available__c, Is_Latest_Version_Q_D_Quotation_Avail__c, " + " Is_Site_Check_Photo_Available__c, Is_Site_Check_Report_Available__c, LastModifiedDate, Drawing_Hour__c, Number_Of_Drawings__c, Target_Date__c, Due_Time__c, Issue_Date_Time__c, " + " (SELECT Id, Item_Name__c, Item_Description__c, Quantity__c FROM Items__r)," + " (SELECT Status, LastActor.Name, CompletedDate FROM ProcessInstances order by CompletedDate desc limit 1)" + " FROM Drawing__c " + " WHERE Project_Name__c = '" + sfProjectID + "'" + " order by LastModifiedDate desc"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } IEnumerable <enterprise.Drawing__c> drawingList = result.records.Cast <enterprise.Drawing__c>(); /* in MIS, only one drawing */ int requisitionId = 0; bool flag = false; foreach (var dl in drawingList) { if (!flag) { /* one unique row will be inserted if it is not existent */ var vm = new DrawingRequisitionFormVm(jobID, estRevID); vm.Initialization(); /* update data */ requisitionId = UpdateDrawing(estRevID, dl.Version__c, dl.Drawing_Requisition_Type__c, dl.Drawing_Purpose__c, dl.Is_Electronic_File_From_Client_Available__c, dl.Is_GC_Or_Designer_Drawing_Available__c, dl.Is_Landord_Or_Mall_Criteria_Available__c, dl.Is_Latest_Version_Q_D_Quotation_Avail__c, dl.Is_Site_Check_Photo_Available__c, dl.Is_Site_Check_Report_Available__c); if (requisitionId != 0) { /* Salesforce can create multi-drawing request but the MIS only supports one at a time so * I will only show the latest one on the MIS system*/ // update SalesForceParentID in MISSalesForceMapping UpdateMISSalesForceMapping(TableName.Sales_Dispatching_DrawingRequisition_EstimationItem, dl.Id); // add items to drawing GetAllDrawingItems(sfProjectID, requisitionId, estRevID, dl.Id, dl.Items__r); GetDrawingApprovalData(jobID, dl.ProcessInstances, dl.Version__c, employeeNumber, dl.Drawing_Hour__c, dl.Target_Date__c, requisitionId, dl.Drawing_Requisition_Type__c, dl.Id, dl.Number_Of_Drawings__c, dl.Due_Time__c, dl.Issue_Date_Time__c); } flag = true; } else { GetDrawingApprovalData(jobID, dl.ProcessInstances, dl.Version__c, employeeNumber, dl.Drawing_Hour__c, dl.Target_Date__c, requisitionId, dl.Drawing_Requisition_Type__c, dl.Id, dl.Number_Of_Drawings__c, dl.Due_Time__c, dl.Issue_Date_Time__c); } } } } catch (Exception e) { LogMethods.Log.Error("GetAllDrawing:Error:" + e.Message); } }
public void GetAllInvoices(string sfProjectID, int jobID, int estRevID, int userEmployeeID) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Name, Status__c, Invoice_Type__c, Issue_Date__c, Shipping_Method__c, Contract_Number__c, Contract_Date__c, Project_Name__r.Account_Executive__r.CommunityNickname, Project_Name__r.Project_Coordinator__r.CommunityNickname, " + " Terms__c, SubTotal__c, Discount__c, HST__c, Deposit__c, Quotation_Number__r.Tax_Option__c, Work_Order_Number__c, Project_Name__r.Currency__c, Invoice_Number__c, Quotation_Number__r.PO_No__c, Suffix__c, Version__c, " + " (SELECT Id, Item_Name__c, Item_Order__c, Requirement__c, Item_Description__c, Item_Cost__c, Quantity__c FROM Items__r), " + " (SELECT Id, Service_Name__r.Name, Service_Detail__c, Service_Cost__c,Note__c, Service_Name__r.MIS_Service_Number__c FROM Service_Costs__r) ," + " Subtotal_After_Discount__c " + " FROM Invoice__c " + " WHERE Project_Name__c = '" + sfProjectID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } //cast query results IEnumerable <enterprise.Invoice__c> invoiceList = result.records.Cast <enterprise.Invoice__c>(); foreach (var ql in invoiceList) { string invoiceName = ql.Invoice_Number__c; /* check if the work order exists */ int invoiceID = CommonMethods.GetMISID(TableName.Sales_JobMasterList_Invoice, ql.Id, salesForceProjectID); if (invoiceID == 0) { // not exist ProjectCompany cp = new ProjectCompany(jobID); if (cp.isThereABilltoCompany) { InvoiceTitleGenerateFromProject inv = new InvoiceTitleGenerateFromProject(jobID); inv.Generate(); invoiceID = inv.MyID; if (invoiceID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_JobMasterList_Invoice, ql.Id, invoiceID.ToString(), salesForceProjectID); } } else { LogMethods.Log.Debug("GetAllInvoices:Debug:" + "It doesn't have a bill to company"); } } if (invoiceID != 0) { UpdateInvoice(invoiceID, invoiceName, ql.Issue_Date__c, userEmployeeID, ql.Terms__c, ql.Contract_Number__c, ql.Shipping_Method__c, ql.Contract_Date__c, ql.Quotation_Number__r.Tax_Option__c, ql.HST__c, ql.Deposit__c, ql.Discount__c, ql.Invoice_Type__c, ql.Work_Order_Number__c, ql.Project_Name__r.Currency__c, ql.Project_Name__r.Account_Executive__r, ql.Project_Name__r.Project_Coordinator__r, ql.Quotation_Number__r, ql.Suffix__c, ql.Version__c, ql.Status__c, ql.Subtotal_After_Discount__c); /* handle item */ HandleInvoiceItem(invoiceID, estRevID, ql.Id, ql.Items__r); /* handle service */ HandleInvoiceService(invoiceID, ql.Id, ql.Service_Costs__r); } } LogMethods.Log.Debug("GetAllInvoices:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllInvoices:Error:" + e.Message); } }
public void GetAllQuotes(string sfProjectID, int jobID, int estRevID, int userEmployeeID) { try { //create service client to call API endpoint using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr)) { //create SQL query statement string query = "SELECT Id, Name, Status__c, Sub_Total__c, SubTotal_Discount__c, " + " Contract_Number__c, Contract_Amount__c, Contract_Issue_Date__c, Contract_Due_Date__c, Deposit__c, Terms__c, Version__c, Project_Name__r.Project_Coordinator__r.CommunityNickname, " + " Tax_Option__c, Tax_Rate__c, Project_Name__r.Currency__c, " + " (SELECT Id, Title__c, Content__c FROM Notes__r), " + " (SELECT Id, Item_Name__c, Item_Order__c, Requirement__c, Item_Description__c, Item_Cost__c, Quantity__c, Item_Option__c FROM Items__r), " + " (SELECT Id, Service_Name__r.Name, Service_Detail__c, Service_Cost__c,Note__c, Service_Name__r.MIS_Service_Number__c FROM Service_Costs__r) " + " FROM Quotation__c " + " WHERE Project_Name__c = '" + sfProjectID + "'"; enterprise.QueryResult result; queryClient.query( header, //sessionheader null, //queryoptions null, //mruheader null, //packageversion query, out result); /* if no any record, return */ if (result.size == 0) { return; } //cast query results IEnumerable <enterprise.Quotation__c> quoteList = result.records.Cast <enterprise.Quotation__c>(); foreach (var ql in quoteList) { /* check if the quote exists */ int quoteID = CommonMethods.GetMISID(TableName.Sales_JobMasterList_quoteRev, ql.Id, salesForceProjectID); if (quoteID == 0) { // not exist // generate quote title var qt = new QuoteTitleGenerate(jobID, estRevID); qt.GenerateTitle(); int quoteRevID = qt.GetNewID(); if (quoteRevID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Sales_JobMasterList_quoteRev, ql.Id, quoteRevID.ToString(), salesForceProjectID); } quoteID = quoteRevID; } if (quoteID != 0) { UpdateQuote(quoteID, ql.Sub_Total__c, ql.SubTotal_Discount__c, ql.Version__c, ql.Tax_Option__c, ql.Tax_Rate__c, ql.Terms__c, ql.Project_Name__r.Currency__c, ql.Project_Name__r.Project_Coordinator__r); // handle quote items HandleQuoteItem(jobID, estRevID, quoteID, ql.Id, ql.Items__r); // handle services HandleQuoteService(jobID, estRevID, quoteID, ql.Id, ql.Service_Costs__r); // handle notes HandleNotes(jobID, estRevID, quoteID, ql.Notes__r, ql.Id); if (ql.Status__c == "Accepted") { // update contract information UpdateWINContract(quoteID, ql.Contract_Number__c, ql.Contract_Issue_Date__c, ql.Contract_Due_Date__c, ql.Contract_Amount__c, ql.Deposit__c, ql.Terms__c); } else if (ql.Status__c == "Denied") { UpdateLOSSNContract(quoteID); } } } LogMethods.Log.Debug("GetAllQuote:Debug:" + "Done"); } } catch (Exception e) { LogMethods.Log.Error("GetAllQuote:Error:" + e.Message); } }