Ejemplo n.º 1
0
        public CrmLeadDetailWizard(CRMLeadDB modelObj, string page)
        {
            InitializeComponent();
            // CRMLeadDB obj = new CRMLeadDB();

            //if(modelObj.serverupdate_string!=null)
            //{
            //    synclayout.IsVisible = true;
            //}

            dbobj = modelObj;
            //   CustomerNameValue.Text = modelObj.name;
            CrmNameValue.Text = modelObj.customer;
            //ExpectedRevenueValue.Text = modelObj.expected_revenue + "$";
            //ProbabilityValue.Text = modelObj.probability + "%";
            EmailValue.Text = modelObj.email;
            PhoneValue.Text = modelObj.phone;
            TeamValue.Text  = modelObj.team_name;
            //NextActivityValue.Text = modelObj.next_activity;
            //NextActivityDateValue.Text = modelObj.next_activity;
            //  ActivityDescritionValue.Text = modelObj.title_action;
            //  expectedClosingValue.Text = "";
            //StreetValue.Text = modelObj.street;
            //Street2Value.Text = modelObj.street2;
            //CityValue.Text = modelObj.city;
            //CountryValue.Text = modelObj.country;
            //ContactNameValue.Text = modelObj.contact_name;
            //ContactMobileValue.Text = modelObj.mobile;
            priorityCnt = Convert.ToInt32(modelObj.priority);

            //if(modelObj.yellowimg_string=="")
            //{
            //    synclayout.IsVisible = false;
            //}
            crm_lead_id = dbobj.id;

            if (page == "Lead")
            {
                //  btnStack.IsVisible = false;
                Convertbtn.IsVisible = true;
            }

            if (priorityCnt == 3)
            {
                RatingLayout3.IsVisible = true;
            }
            else if (priorityCnt == 2)
            {
                RatingLayout2.IsVisible = true;
            }
            else if (priorityCnt == 1)
            {
                RatingLayout1.IsVisible = true;
            }
            else
            {
            }
        }
Ejemplo n.º 2
0
        private async void createClickedAsync(object sender, EventArgs ea)
        {
            if (leadTitle.Text == "")
            {
                leadtitle_alert.IsVisible = true;
            }

            //else if (Convert.ToInt32(prob_entry.Text) > 100)
            //{
            //    leadtitle_alert.IsVisible = false;
            //    prob_alert.IsVisible = true;
            //}

            else
            {
                //var cusid = App.cusdict.FirstOrDefault(x => x.Value == customer_Picker.SelectedItem.ToString()).Key;
                //vals["partner_id"] = cusid;

                var currentpage = new LoadingAlert();

                await PopupNavigation.PushAsync(currentpage);

                try
                {
                    List <CRMLead> crmLeadData = Controller.InstanceCreation().crmLeadData();
                }


                catch (Exception ea1)
                {
                    if (ea1.Message.Contains("(Network is unreachable)") || ea1.Message.Contains("NameResolutionFailure"))
                    {
                        App.NetAvailable = false;
                    }

                    else if (ea1.Message.Contains("(503) Service Unavailable"))
                    {
                        App.responseState = false;
                    }
                }


                int stateid   = 0;
                int countryid = 0;

                vals["contact_name"] = contName.Text;

                vals["name"] = leadTitle.Text;

                vals["email_from"] = eMail.Text;
                vals["phone"]      = phone.Text;
                vals["function"]   = jobPos.Text;
                //vals["street"] = street.Text;
                //vals["street2"] = street2.Text;
                //vals["zip"] = zip.Text;

                var salespersonid = App.salespersons.FirstOrDefault(x => x.Value == salesperson_Picker.SelectedItem.ToString()).Key;
                vals["user_id"] = salespersonid;

                var salesteamid = App.salesteam.FirstOrDefault(x => x.Value == salesteam_Picker.SelectedItem.ToString()).Key;
                vals["team_id"] = salesteamid;

                //var customerid = App.cusdict.FirstOrDefault(x => x.Value == customer_Picker.SelectedItem.ToString()).Key;
                //vals["partner_id"] = customerid;

                //vals["partner_name"] = customer_Picker.SelectedItem.ToString();

                // var nextactivityid =
                //     (
                //         from i in App.nextActivityList
                //         where i.name == nextact_Picker.SelectedItem.ToString()
                //             select new
                //             {
                //                 i.id,
                //             }
                //).ToList();

                //foreach (var comgroup in nextactivityid)
                //{
                //    next_activity_id = comgroup.id;
                //}

                // vals["next_activity_id"] = next_activity_id;

                //String date_deadline_string = String.Format("{0:MM-dd-yyyy HH:mm:ss}", expected_closing_Picker.Date);

                //vals["date_deadline"] = date_deadline_string;

                //  vals["planned_revenue"] = exrev_entry.Text;

                // vals["probability"] = prob_entry.Text;

                //if (state_picker.SelectedItem == null)
                //{
                //    vals["state_id"] = false;
                //}
                //else
                //{
                //     stateid = App.statedict.FirstOrDefault(x => x.Value == state_picker.SelectedItem.ToString()).Key;
                //    vals["state_id"] = stateid;
                //}

                //if (country_picker.SelectedItem == null)
                //{
                //    vals["country_id"] = false;
                //}
                //else
                //{
                //     countryid = App.countrydict.FirstOrDefault(x => x.Value == country_picker.SelectedItem.ToString()).Key;
                //    vals["country_id"] = countryid;
                //}


                vals["description"] = comments.Text;

                vals["type"] = "lead";

                vals["priority"] = count;


                //bool updated = Controller.InstanceCreation().UpdateCRMOpporData("sale.crm", "create_crm_quotations", vals);

                if (App.NetAvailable == true)
                {
                    string updated = Controller.InstanceCreation().UpdateLeadCreationData("crm.lead", "create", vals);

                    if (updated == "Odoo Error")
                    {
                        // App.Current.MainPage = new MasterPage(new CrmTabbedPage());
                        // Navigation.PushPopupAsync(new MasterPage(  );
                        await  DisplayAlert("Alert", "Please try again", "Ok");
                    }
                    else
                    {
                        var currentpage1 = new LoadingAlert();
                        await PopupNavigation.PushAsync(currentpage1);

                        //  await DisplayAlert("Alert", "Created Successfull", "Ok");

                        //    List<CRMLead> crmLeadData = Controller.InstanceCreation().crmLeadData();

                        App.Current.MainPage = new MasterPage(new CrmTabbedPage("tab1"));

                        Loadingalertcall();

                        salesteam_Picker.Unfocus();
                    }
                }

                else if (App.NetAvailable == false)
                {
                    int stateidoffline   = 0;
                    int countryidoffline = 0;

                    var salespersonidoffline = salespersdict.FirstOrDefault(x => x.Value == salesperson_Picker.SelectedItem.ToString()).Key;
                    vals["user_id"] = salespersonidoffline;

                    var salesteamidoffline = salesteamdict.FirstOrDefault(x => x.Value == salesteam_Picker.SelectedItem.ToString()).Key;
                    vals["team_id"] = salesteamidoffline;


                    //var customeridoffline = customerdict.FirstOrDefault(x => x.Value == customer_Picker.SelectedItem.ToString()).Key;
                    //vals["partner_id"] = customeridoffline;

                    //var nextactidoffline = nextact_List.FirstOrDefault(x => x.name == nextact_Picker.SelectedItem.ToString());
                    //vals["next_activity_id"] = nextactidoffline;

                    // var nextactidoffline =
                    //(
                    //         from i in nextact_List
                    //    where i.name == nextact_Picker.SelectedItem.ToString()
                    //    select new
                    //    {
                    //        i.id,
                    //    }
                    //).ToList();

                    //foreach (var comgroup in nextactivityid)
                    //{
                    //    next_activity_id = comgroup.id;
                    //}

                    //String ex_closing_string = String.Format("{0:MM-dd-yyyy HH:mm:ss}", expected_closing_Picker.Date);


                    //if (state_picker.SelectedItem == null)
                    //{
                    //  //  vals["state_id"] = false;
                    //    stateidoffline = 0;
                    //}
                    //else
                    //{
                    //    stateidoffline = statedict.FirstOrDefault(x => x.Value == state_picker.SelectedItem.ToString()).Key;
                    //    vals["state_id"] = stateidoffline;
                    //}

                    //if (country_picker.SelectedItem == null)
                    //{
                    //    // vals["country_id"] = false;

                    //    countryidoffline = 0;
                    //}
                    //else
                    //{
                    //    countryidoffline = countrydict.FirstOrDefault(x => x.Value == country_picker.SelectedItem.ToString()).Key;
                    //    vals["country_id"] = countryidoffline;
                    //}


                    var sample = new CRMLeadDB
                    {
                        //  id = item.id,
                        customer = leadTitle.Text,
                        // next_activity = item.next_activity,

                        name = leadTitle.Text,

                        //   probability = item.probability,
                        //  phone = item.phone,
                        //  title_action = item.title_action,
                        //  expected_revenue = item.expected_revenue,

                        //   team_name = salesteam_Picker.SelectedItem.ToString(),
                        priority = Int32.Parse(count),
                        //  state = state_picker.SelectedItem.ToString(),
                        //street = street.Text,
                        //street2 = street2.Text,
                        //city = city.Text,
                        //   country = country_picker.SelectedItem.ToString(),
                        contact_name = contName.Text,
                        mobile       = phone.Text,
                        email        = eMail.Text,

                        function    = jobPos.Text,
                        user_id     = salespersonid,
                        team_id     = salesteamid,
                        state_id    = stateid,
                        country_id  = countryid,
                        description = comments.Text,
                        type        = "lead",
                        nextact_id  = next_activity_id,
                        //  expected_closing = ex_closing_string,
                        //  zip= zip.Text,
                        // pipe_date = item.pipe_date,
                        //   pipe_date1 = item.pipe_date1,
                        //  conDate = item.conDate,
                        // conDate1 = item.conDate1,
                        //  DateOrder = item.DateOrder,
                        FullState        = "  New  ",
                        yellowimg_string = "yellowcircle.png",
                        state_colour     = "#3498db",
                        //  server_color = "#fafb80",
                        serverupdate_string = "Local"

                                              //order_line = item.order_line[0].ToString()
                    };
                    App._connection.Insert(sample);


                    App._connection.CreateTable <CRMLeadDB>();
                    try
                    {
                        var details = (from y in App._connection.Table <CRMLeadDB>() select y).ToList();
                        App.crmListDb = details;
                    }
                    catch (Exception ex)
                    {
                        int i = 0;
                    }

                    //   await DisplayAlert("Alert", "Created Successfull", "Ok");
                    // await Navigation.PopAllPopupAsync();
                    App.Current.MainPage = new MasterPage(new CrmTabbedPage("tab1"));

                    Loadingalertcall();
                }
            }
        }
Ejemplo n.º 3
0
        private void crmLeadListView_ItemTapped(object sender, ItemTappedEventArgs ea)
        {
            //if (App.NetAvailable == true && App.crmList.Count != App.crmListDb.Count && App.crmListDb.Count != 0)
            //{
            //    CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
            //    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
            //}

            //else if (App.NetAvailable == true && App.crmList.Count == App.crmListDb.Count)
            //{
            //    CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
            //    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
            //}

            //else if(App.NetAvailable == true && App.crmList.Count > App.crmListDb.Count)
            //{
            //    CRMLead masterItemObj = (CRMLead)ea.Item;
            //    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
            //}

            //else if(App.NetAvailable == false)
            //{
            //    CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
            //    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
            //}


            //  List<CRMLead> crmLeadData = Controller.InstanceCreation().crmLeadData();



            //CRMLead masterItemObj = (CRMLead)ea.Item;
            //Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));

            if (App.NetAvailable == true)
            {
                crmLeadListView.ItemsSource = App.crmList;

                var result1 = from y in App.crmListDb
                              where y.yellowimg_string == "yellowcircle.png"
                              select y;

                if (result1.Count() == 0)
                {
                    try
                    {
                        CRMLead masterItemObj = (CRMLead)ea.Item;
                        Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                    }

                    catch
                    {
                        CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
                        Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                    }
                }

                else
                {
                    try
                    {
                        CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
                        Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                    }
                    catch {
                        CRMLead masterItemObj = (CRMLead)ea.Item;
                        Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                    }
                }
            }


            else if (App.NetAvailable == false)
            {
                try
                {
                    CRMLeadDB masterItemObj = (CRMLeadDB)ea.Item;
                    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                }

                catch
                {
                    CRMLead masterItemObj = (CRMLead)ea.Item;
                    Navigation.PushPopupAsync(new CrmLeadDetailWizard(masterItemObj, "Lead"));
                }
            }
        }
Ejemplo n.º 4
0
        async void phoneClicked(object sender, EventArgs e1)
        {
            var args = (TappedEventArgs)e1;


            try
            {
                CRMLead myobj = args.Parameter as CRMLead;

                var phoneDialer = CrossMessaging.Current.PhoneDialer;
                if (phoneDialer.CanMakePhoneCall && myobj.phone != "")
                {
                    start_record = true;


                    await DisplayAlert("Alert", "Your call will be recorded", "Ok");

                    DependencyService.Get <IPhoneCall>().makecall(myobj.phone);

                    //  await   recorder.StopRecordingOnSilence = false;


                    await Task.Delay(5000);

                    //  Thread.Sleep(10000);
                    DependencyService.Get <IAudioRecorder>().StartRecording();


                    //  var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                    var res = await DisplayAlert("Alert", "Save the record?", "Ok", "Cancel");

                    if (res)
                    {
                        //  await recorder.StopRecording();

                        //stopWatch.Stop();

                        //await recorder.StopRecording();
                        //// Get the elapsed time as a TimeSpan value.
                        //TimeSpan ts = stopWatch.Elapsed;


                        //try
                        //{
                        //    var filePath = recorder.GetAudioFilePath();

                        //    if (filePath != null)
                        //    {
                        //       // PlayButton.IsEnabled = false;
                        //       // RecordButton.IsEnabled = false;

                        //        player.Play(filePath);
                        //    }
                        //}
                        //catch (Exception ex)
                        //{
                        //    //blow up the app!
                        //    throw ex;
                        //}

                        DependencyService.Get <IAudioRecorder>().StopRecording();

                        var currentpage = new LoadingAlert();
                        await PopupNavigation.PushAsync(currentpage);


                        Dictionary <string, dynamic> vals = new Dictionary <string, dynamic>();

                        //string UploadData = DependencyService.Get<IAudioRecorder>().RecordAudio();

                        string UploadData = DependencyService.Get <IAudioRecorder>().OutputString();

                        vals["res_model"]   = "crm.lead";
                        vals["res_id"]      = myobj.id;
                        vals["name"]        = "test.3gp";
                        vals["datas"]       = UploadData;
                        vals["datas_fname"] = "test.3gp";

                        var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                        DependencyService.Get <IAudioRecorder>().PlayRecording();

                        //  var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                        await DisplayAlert("Alert", "Record updated successfully", "Ok");

                        await PopupNavigation.PopAsync();
                    }
                    else
                    {
                        // await DisplayAlert("Alert", "Try Again", "Ok");
                        //  await PopupNavigation.PopAsync();
                    }
                }
                else
                {
                    start_record = false;
                    await Navigation.PushPopupAsync(new PhoneWizard());
                }
            }
            catch
            {
                CRMLeadDB myobj       = args.Parameter as CRMLeadDB;
                var       phoneDialer = CrossMessaging.Current.PhoneDialer;
                if (phoneDialer.CanMakePhoneCall && myobj.phone != "")
                {
                    phoneDialer.MakePhoneCall(myobj.phone);
                }
                else
                {
                    await Navigation.PushPopupAsync(new PhoneWizard());
                }
            }
        }
Ejemplo n.º 5
0
        public List <CRMLead> crmLeadData()
        {
            String[] colourcodes = new String[] { "#3498db", "#e67e22", "#c0392b", "#2ecc71", "#d35400", "#27ae60", " #e74c3c", "#2980b9" };
            try
            {
                //JObject res = odooConnector.odooCrmLeadDataCall("sale.crm", "get_your_pipelines_all_orders");

                App.filterdict["range"] = "False";
                App.filterdict["days"]  = "False";
                App.filterdict["month"] = "True";

                //   odooConnector = OdooRPC.InstanceCreation(Settings.UserUrlName);
                JObject res = odooConnector.odooFilterDataCall("sale.crm", "get_your_pipelines_all_orders");

                //List<OrderLine> test = new List<OrderLine>();

                App.statedict   = res["state_list"].ToObject <Dictionary <int, string> >();
                App.countrydict = res["country_list"].ToObject <Dictionary <int, string> >();

                App.partner_name  = res["user_name"].ToString();
                App.partner_image = res["user_image_medium"].ToString();
                App.partner_id    = res["partner_id"].ToObject <int>();
                App.partner_email = res["user_email"].ToString();

                App.taxList     = res["taxes"].ToObject <List <taxes> >();
                App.paytermList = res["payment_terms"].ToObject <List <paytermList> >();

                App.commisiongroupList = res["commission_group"].ToObject <List <commisiongroupList> >();

                App.salesteam    = res["sales_team"].ToObject <Dictionary <int, string> >();
                App.salespersons = res["sales_persons"].ToObject <Dictionary <int, string> >();

                App.productList = res["Products"].ToObject <List <ProductsList> >();

                App.user_location_string = res["location"].ToString();

                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <UserModelDB>();


                if (App.UserListDb.Count == 0)
                {
                    var json_state = Newtonsoft.Json.JsonConvert.SerializeObject(res["state_list"]);

                    var json_country = Newtonsoft.Json.JsonConvert.SerializeObject(res["country_list"]);

                    var json_tags         = Newtonsoft.Json.JsonConvert.SerializeObject(res["crm_lead_tags"]);
                    var json_salesteam    = Newtonsoft.Json.JsonConvert.SerializeObject(res["sales_team"]);
                    var json_salespersons = Newtonsoft.Json.JsonConvert.SerializeObject(res["sales_persons"]);

                    var json_customers_list = Newtonsoft.Json.JsonConvert.SerializeObject(res["Customers"]);
                    var json_next_activity  = Newtonsoft.Json.JsonConvert.SerializeObject(res["next_activity"]);
                    var json_stages         = Newtonsoft.Json.JsonConvert.SerializeObject(res["stages"]);

                    var json_payment_terms = Newtonsoft.Json.JsonConvert.SerializeObject(res["payment_terms"]);

                    var json_commission_groups = Newtonsoft.Json.JsonConvert.SerializeObject(res["commission_group"]);

                    var jso_tags_list = Newtonsoft.Json.JsonConvert.SerializeObject(res["taxes"]);

                    var jso_products_list = Newtonsoft.Json.JsonConvert.SerializeObject(res["Products"]);


                    var sample = new UserModelDB
                    {
                        userid            = App.userid,
                        partnerid         = App.partner_id,
                        user_image_medium = App.partner_image,
                        user_email        = App.partner_email,
                        user_name         = App.partner_name,
                        state_list        = json_state,
                        country_list      = json_country,
                        tagsPicker        = json_tags,
                        sales_team        = json_salesteam,
                        sales_persons     = json_salespersons,
                        customers_list    = json_customers_list,
                        next_activity     = json_next_activity,
                        stages            = json_stages,
                        payment_terms     = json_payment_terms,
                        commission_group  = json_commission_groups,
                        tax_list          = jso_tags_list,
                        products          = jso_products_list
                    };
                    App._connection.Insert(sample);

                    try
                    {
                        var details = (from y in App._connection.Table <UserModelDB>() select y).ToList();

                        App.UserListDb = details;

                        List <ProductsList>      productslistdb = new List <ProductsList>();
                        Dictionary <int, string> cusdictdb      = new Dictionary <int, string>();
                        foreach (var item in App.UserListDb)
                        {
                            productslistdb = JsonConvert.DeserializeObject <List <ProductsList> >(item.products);

                            cusdictdb = JsonConvert.DeserializeObject <Dictionary <int, string> >(item.customers_list);

                            App.ProductListDb = productslistdb;
                            App.cusdictDb     = cusdictdb;
                            App.userid_db     = item.userid;
                        }
                    }


                    catch
                    {
                        int te = 0;
                    }

                    //List<ProductsList> productslistdb = new List<ProductsList>();
                    //foreach (var item in App.UserListDb)
                    //{
                    //    productslistdb = JsonConvert.DeserializeObject<List<ProductsList>>(item.products);

                    //    App.productList = productslistdb;
                    //}
                }



                App.nextActivityList = res["next_activity"].ToObject <List <next_activity> >();

                App.crmList = res["crm_leads"].ToObject <List <CRMLead> >();

                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <CRMLeadDB>();

                var crmlead_details = App._connection.Query <CRMLeadDB>("SELECT * from CRMLeadDB where yellowimg_string = ?", "yellowcircle.png");

                if (crmlead_details.Count() == 0)
                {
                    App._connection.Query <SalesQuotationDB>("DELETE from CRMLeadDB");

                    foreach (var item in App.crmList)
                    {
                        var sample = new CRMLeadDB
                        {
                            id               = item.id,
                            customer         = item.customer,
                            next_activity    = item.next_activity,
                            name             = item.name,
                            probability      = item.probability,
                            phone            = item.phone,
                            title_action     = item.title_action,
                            expected_revenue = item.expected_revenue,

                            team_name    = item.team_name,
                            priority     = item.priority,
                            state        = item.state,
                            street       = item.street,
                            street2      = item.street2,
                            city         = item.city,
                            country      = item.country,
                            contact_name = item.contact_name,
                            mobile       = item.mobile,
                            email        = item.email,
                            pipe_date    = item.pipe_date,
                            pipe_date1   = item.pipe_date1,
                            conDate      = item.conDate,
                            conDate1     = item.conDate1,
                            DateOrder    = item.DateOrder,
                            FullState    = item.FullState,

                            state_colour = item.state_colour,

                            //order_line = item.order_line[0].ToString()
                        };
                        App._connection.Insert(sample);


                        //App._samp.Add(sample);
                    }

                    try
                    {
                        var details = (from y in App._connection.Table <CRMLeadDB>() select y).ToList();

                        App.crmListDb = details;
                    }

                    catch
                    {
                        int te = 0;
                    }
                }

                App.crmOpprList = res["crm_quotations"].ToObject <List <CRMOpportunities> >();

                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <CRMOpportunitiesDB>();

                var crmoppo_details = App._connection.Query <CRMOpportunitiesDB>("SELECT * from CRMOpportunitiesDB where yellowimg_string = ?", "yellowcircle.png");

                if (crmoppo_details.Count == 0)
                {
                    App._connection.Query <SalesQuotationDB>("DELETE from CRMOpportunitiesDB");
                    foreach (var item in App.crmOpprList)
                    {
                        var sample = new CRMOpportunitiesDB
                        {
                            customer         = item.customer,
                            next_activity    = item.next_activity,
                            name             = item.name,
                            probability      = item.probability,
                            phone            = item.phone,
                            title_action     = item.title_action,
                            expected_revenue = item.expected_revenue,
                            team_name        = item.team_name,
                            priority         = item.priority,
                            state            = item.state,
                            street           = item.street,
                            street2          = item.street2,
                            city             = item.city,
                            country          = item.country,
                            contact_name     = item.contact_name,
                            mobile           = item.mobile,
                            email            = item.email,
                            FullState        = item.FullState,
                            state_colour     = item.state_colour,
                            pipe_date        = item.pipe_date,
                            //pipe_datetime = item.pipe_datetime,
                            //pipe_datetime1 = item.pipe_datetime1,
                            pipe_datetime  = item.pipe_datetime.ToString(),
                            pipe_datetime1 = item.pipe_datetime1.ToString(),
                            DateOrder      = item.DateOrder,
                            newpipe_date   = item.newpipe_date,
                        };
                        App._connection.Insert(sample);
                    }

                    try
                    {
                        var details = (from y in App._connection.Table <CRMOpportunitiesDB>() select y).ToList();

                        App.CRMOpportunitiesListDb = details;
                    }
                    catch
                    {
                        int te = 0;
                    }
                }

                App.salesQuotList = res["sale_quotations"].ToObject <List <SalesQuotation> >();

                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <SalesQuotationDB>();

                var sq_details = App._connection.Query <SalesQuotationDB>("SELECT * from SalesQuotationDB where yellowimg_string = ?", "yellowcircle.png");


                if (sq_details.Count() == 0)
                {
                    App._connection.Query <SalesQuotationDB>("DELETE from SalesQuotationDB");

                    foreach (var item in App.salesQuotList)
                    {
                        var json_orderline = Newtonsoft.Json.JsonConvert.SerializeObject(item.order_line);
                        var sample         = new SalesQuotationDB
                        {
                            customer = item.customer,
                            //    next_activity = item.next_activity,
                            name = item.name,
                            //  probability = item.probability,
                            // phone = item.phone,
                            //  title_action = item.title_action,
                            //  expected_revenue = item.expected_revenue,
                            payment_term = item.payment_term,
                            // team_name = item.team_name,
                            priority = item.priority,
                            state    = item.state,
                            street   = item.street,
                            street2  = item.street2,
                            city     = item.city,
                            country  = item.country,
                            // contact_name = item.contact_name,
                            //  mobile = item.mobile,
                            //  email = item.email,
                            // state_colour = item.state_colour,
                            sales_person       = item.sales_person,
                            sales_team         = item.sales_team,
                            customer_reference = item.customer_reference,
                            fiscal_position    = item.fiscal_position,
                            FullState          = item.FullState,
                            state_colour       = item.state_colour,
                            DateOrder          = item.DateOrder,
                            order_line         = json_orderline
                        };
                        App._connection.Insert(sample);
                        //App._samp.Add(sample);
                    }

                    try
                    {
                        var details = (from y in App._connection.Table <SalesQuotationDB>() select y).ToList();
                        App.SalesQuotationListDb = details;
                    }

                    catch
                    {
                        int te = 0;
                    }
                }


                App.promotionsList = res["promotions"].ToObject <List <ActivePromotions> >();

                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <ActivePromotionsDB>();

                //var promotion_details = App._connection.Query<ActivePromotionsDB>("SELECT * from ActivePromotionsDB");

                if (App.promotionsList.Count() != 0)
                {
                    App._connection.Query <ActivePromotionsDB>("DELETE from ActivePromotionsDB");

                    foreach (var item in App.promotionsList)
                    {
                        var dblist1     = Newtonsoft.Json.JsonConvert.SerializeObject(item.list1);
                        var dblist2     = Newtonsoft.Json.JsonConvert.SerializeObject(item.list2);
                        var dbtype_list = Newtonsoft.Json.JsonConvert.SerializeObject(item.type_list);

                        var sample = new ActivePromotionsDB
                        {
                            product      = item.product,
                            name         = item.name,
                            start_date   = item.Fstart_date,
                            end_date     = item.Fend_date,
                            type         = item.type,
                            type_list    = dbtype_list,
                            list1        = dblist1,
                            list2        = dblist2,
                            Fstart_date  = item.Fstart_date,
                            Fend_date    = item.Fend_date,
                            EndDateColor = item.EndDateColor,
                        };
                        App._connection.Insert(sample);
                        //App._samp.Add(sample);
                    }

                    try
                    {
                        var details = (from y in App._connection.Table <ActivePromotionsDB>() select y).ToList();
                        App.promotionsListDB = details;
                    }

                    catch
                    {
                        int te = 0;
                    }
                }


                App.salesOrderList = res["sale_orders"].ToObject <List <SalesOrder> >();


                App._connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                App._connection.CreateTable <SalesOrderDB>();

                if (App.SalesOrderListDb.Count == 0)
                {
                    foreach (var item in App.salesOrderList)
                    {
                        var json_orderline = Newtonsoft.Json.JsonConvert.SerializeObject(item.order_line);

                        var sample = new SalesOrderDB
                        {
                            customer           = item.customer,
                            next_activity      = item.next_activity,
                            name               = item.name,
                            probability        = item.probability,
                            phone              = item.phone,
                            title_action       = item.title_action,
                            expected_revenue   = item.expected_revenue,
                            payment_term       = item.payment_term,
                            team_name          = item.team_name,
                            priority           = item.priority,
                            state              = item.state,
                            street             = item.street,
                            street2            = item.street2,
                            city               = item.city,
                            country            = item.country,
                            contact_name       = item.contact_name,
                            mobile             = item.mobile,
                            email              = item.email,
                            state_colour       = item.state_colour,
                            sales_person       = item.sales_person,
                            sales_team         = item.sales_team,
                            customer_reference = item.customer_reference,
                            fiscal_position    = item.fiscal_position,
                            FullState          = item.FullState,

                            //  ColorCode = item.ColorCode,

                            DateOrder = item.DateOrder,

                            order_line = json_orderline,
                        };
                        App._connection.Insert(sample);
                        //App._samp.Add(sample);
                    }

                    try
                    {
                        var details = (from y in App._connection.Table <SalesOrderDB>() select y).ToList();
                        App.SalesOrderListDb = details;
                    }
                    catch
                    {
                        int te = 0;
                    }
                }


                App.stageList = res["stages"].ToObject <List <stages> >();

                String colorCodeData = "";

                int cnt = 0;
                foreach (stages stateObj in res["stages"].ToObject <List <stages> >())
                {
                    try
                    {
                        colorCodeData = colorCodeData + "," + stateObj.name + "^" + colourcodes[cnt];
                    }
                    catch
                    {
                        cnt = 0;
                        continue;
                    }
                    cnt++;
                }

                Settings.StageColourCode = colorCodeData;
                App.cusdict = res["Customers"].ToObject <Dictionary <int, string> >();

                App.reasondict = res["lost_reason"].ToObject <Dictionary <int, string> >();

                App.crmleadtags = res["crm_lead_tags"].ToObject <Dictionary <int, string> >();

                App.user_gps_enabled = res["user_gps_enabled"].ToObject <Boolean>();
                App.user_gps_time    = res["user_gps_time"].ToObject <int>();

                App.locationsList = res["Location"].ToObject <List <LocationsList> >();

                return(App.crmList);
            }
            catch (Exception ea)
            {
                System.Diagnostics.Debug.WriteLine("::::: CRM Warning Message ::::  " + ea.Message);

                if (ea.Message.Contains("(Network is unreachable)") || ea.Message.Contains("NameResolutionFailure"))
                {
                    App.NetAvailable = false;
                }

                else if (ea.Message.Contains("(503) Service Unavailable"))
                {
                    App.responseState = false;
                }
                return(App.crmList);
            }
        }
Ejemplo n.º 6
0
        async void phoneClicked(object sender, EventArgs e1)
        {
            var args = (TappedEventArgs)e1;

            //try
            //{
            //    CRMLead myobj = args.Parameter as CRMLead;

            //    var phoneDialer = CrossMessaging.Current.PhoneDialer;
            //    if (phoneDialer.CanMakePhoneCall && myobj.phone != "")
            //    {
            //        start_record = true;

            //        //   DependencyService.Get<IPhoneCall>().makecall("12345");

            //        // phoneDialer.MakePhoneCall(myobj.phone);

            //        await DisplayAlert("Alert", "Your call will be recorded", "Ok");

            //        DependencyService.Get<IPhoneCall>().makecall(myobj.phone);

            //      //  await   recorder.StopRecordingOnSilence = false;


            //        await RecordAudio();


            //        stopWatch.Start();


            //      //  var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

            //        var res =   await DisplayAlert("Alert", "Save the record?","Ok","Cancel");

            //        if (res)
            //        {

            //          //  await recorder.StopRecording();

            //           stopWatch.Stop();

            //            await recorder.StopRecording();
            //            // Get the elapsed time as a TimeSpan value.
            //            TimeSpan ts = stopWatch.Elapsed;

            //            // Format and display the TimeSpan value.
            //            //string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            //                //ts.Hours, ts.Minutes, ts.Seconds,
            //                //ts.Milliseconds / 10);


            //            var currentpage = new LoadingAlert();
            //            await PopupNavigation.PushAsync(currentpage);

            //            //  TimeSpan duration = new TimeSpan(0, 1, 0, 0);
            //            //  recorder.
            //            recorder.TotalAudioTimeout = ts;

            //         //   var filePath = recorder.GetAudioFilePath();


            //            Dictionary<string, dynamic> vals = new Dictionary<string, dynamic>();

            //            var stream = recorder.GetAudioFileStream();



            //            String UploadData = "";

            //            using (MemoryStream ms = new MemoryStream())
            //            {
            //                stream.CopyTo(ms);
            //                 ms.ToArray();


            //               // String UploadData = Convert.ToBase64String(ms.ToArray());
            //                 UploadData = Convert.ToBase64String(ms.ToArray());

            //                vals["res_model"] = "crm.lead";
            //                vals["res_id"] = myobj.id;
            //                vals["name"] = "test.wav";
            //                vals["datas"] = UploadData;
            //                vals["datas_fname"] = "test.wav";
            //            }


            //            var bytes = Encoding.Unicode.GetBytes(UploadData);
            //            using (var msi = new MemoryStream(bytes))
            //            using (var mso = new MemoryStream())
            //            {
            //                using (var gs = new GZipStream(mso, CompressionMode.Compress))
            //                {
            //                    msi.CopyTo(gs);
            //                }
            //                String fin_str = Convert.ToBase64String(mso.ToArray());
            //            }



            //           var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

            //            Dictionary<string, dynamic> valslog = new Dictionary<string, dynamic>();

            //            valslog["name"] = myobj.phone;
            //            valslog["partner_id"] = App.partner_id;
            //            valslog["user_id"] = App.userid;
            //            valslog["date"] = DateTime.Now.ToString("yyyy-MM-dd hh:mm");
            //            valslog["opportunity_id"] = myobj.id;
            //            valslog["partner_phone"] = "";


            //           // var res2 = Controller.InstanceCreation().UpdateLeadCreationData("crm.phonecal", "create", valslog);

            //            await DisplayAlert("Alert", "Record updated successfully", "Ok");

            //            await PopupNavigation.PopAsync();



            //        }
            //        else
            //        {
            //            // await DisplayAlert("Alert", "Try Again", "Ok");
            //          //  await PopupNavigation.PopAsync();
            //        }

            //    }
            //    else
            //    {
            //        start_record = false;
            //        await Navigation.PushPopupAsync(new PhoneWizard());
            //    }


            //}


            try
            {
                CRMLead myobj = args.Parameter as CRMLead;

                var phoneDialer = CrossMessaging.Current.PhoneDialer;
                if (phoneDialer.CanMakePhoneCall && myobj.phone != "")
                {
                    await DisplayAlert("Alert", "Your call will be recorded", "Ok");

                    DependencyService.Get <IPhoneCall>().makecall(myobj.phone);


                    await Task.Delay(5000);

                    //  Thread.Sleep(10000);
                    DependencyService.Get <IAudioRecorder>().StartRecording();

                    stopWatch.Start();

                    //  var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                    var res = await DisplayAlert("Alert", "Save the record?", "Ok", "Cancel");

                    if (res)
                    {
                        stopWatch.Stop();

                        // await recorder.StopRecording();
                        // Get the elapsed time as a TimeSpan value.
                        TimeSpan ts = stopWatch.Elapsed;

                        // Format and display the TimeSpan value.
                        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
                                                           ts.Hours, ts.Minutes, ts.Seconds);


                        DependencyService.Get <IAudioRecorder>().StopRecording();

                        var currentpage = new LoadingAlert();
                        await PopupNavigation.PushAsync(currentpage);


                        Dictionary <string, dynamic> vals = new Dictionary <string, dynamic>();

                        //string UploadData = DependencyService.Get<IAudioRecorder>().RecordAudio();

                        string UploadData = DependencyService.Get <IAudioRecorder>().OutputString();

                        vals["res_model"] = "crm.lead";
                        vals["res_id"]    = myobj.id;
                        // vals["name"] = "test.3gp";
                        vals["name"] = myobj.name + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm");

                        vals["datas"]       = UploadData;
                        vals["datas_fname"] = "test.3gp";

                        var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                        Dictionary <string, dynamic> valslog = new Dictionary <string, dynamic>();

                        valslog["partner_phone"]  = myobj.phone;
                        valslog["partner_id"]     = App.partner_id;
                        valslog["user_id"]        = App.userid;
                        valslog["date"]           = DateTime.Now.ToString("yyyy-MM-dd hh:mm");
                        valslog["opportunity_id"] = myobj.id;
                        valslog["name"]           = "Call Discuss";
                        valslog["state"]          = "done";
                        valslog["duration"]       = ts.Minutes + "." + ts.Seconds;

                        var res2 = Controller.InstanceCreation().UpdateLeadCreationData("crm.phonecall", "create", valslog);

                        //   DependencyService.Get<IAudioRecorder>().PlayRecording();

                        //  var res1 = Controller.InstanceCreation().UpdateLeadCreationData("ir.attachment", "create", vals);

                        await DisplayAlert("Alert", "Record updated successfully", "Ok");

                        await PopupNavigation.PopAsync();
                    }
                    else
                    {
                        await PopupNavigation.PopAsync();

                        // await DisplayAlert("Alert", "Try Again", "Ok");
                        //  await PopupNavigation.PopAsync();
                    }
                }
                else
                {
                    start_record = false;
                    await Navigation.PushPopupAsync(new PhoneWizard());
                }
            }

            catch
            {
                CRMLeadDB myobj       = args.Parameter as CRMLeadDB;
                var       phoneDialer = CrossMessaging.Current.PhoneDialer;
                if (phoneDialer.CanMakePhoneCall && myobj.phone != "")
                {
                    phoneDialer.MakePhoneCall(myobj.phone);
                }
                else
                {
                    await Navigation.PushPopupAsync(new PhoneWizard());
                }
            }
        }