Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
        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);
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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);
            }
        }
Example #9
0
        /// <summary>
        /// Call SFDC endpoint and retrieve authentication token and API URL for SOAP callers
        /// </summary>
        ///
        public static bool AuthenticateSfdcEnterpriseUser(string user, string pass, string token)
        {
            //print message to console
            LogMethods.Log.Debug("Authenticating against the Enterprise API ...");
            Console.WriteLine("Authenticating against the Enterprise API ...");
            try
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                //use default binding and address from app.config
                using (enterprise.SoapClient loginClient = new enterprise.SoapClient("Soap"))
                {
                    //set account password and account token variables
                    string sfdcPassword = pass;
                    string sfdcToken    = token;

                    //set to Force.com user account that has API access enabled
                    string sfdcUserName = user;

                    //create login password value
                    string loginPassword = sfdcPassword + sfdcToken;

                    //call Login operation from Enterprise WSDL
                    enterprise.LoginResult result =
                        loginClient.login(
                            null, //LoginScopeHeader
                            sfdcUserName,
                            loginPassword);

                    //get response values
                    sessionId = result.sessionId;
                    serverUrl = result.serverUrl;

                    //print response values
                    Console.WriteLine(string.Format("The session ID is {0} and server URL is {1}", sessionId, serverUrl));
                    Console.WriteLine("");
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("AuthenticateSfdcEnterpriseUser:Error = " + e.Message);
                return(false);
            }

            return(true);
        }
Example #10
0
        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);
            }
        }
Example #11
0
        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 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);
            }
        }
        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);
            }
        }
Example #14
0
        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);
            }
        }
        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);
            }
        }
Example #16
0
        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);
            }
        }
Example #17
0
        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);
            }
        }
Example #18
0
        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);
            }
        }
Example #19
0
        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 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);
            }
        }
Example #21
0
        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);
            }
        }
Example #22
0
        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);
            }
        }
        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);
            }
        }
Example #24
0
        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);
            }
        }