Search code examples
androidif-statementandroid-intentbundlecalculation

show total based on quantity and display total,item name,Rate etc


This is the code for check the quantity value is empty else do the calculation

 ordernew.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    if (addordernew.getText().toString().equals("")) {
                        addordernew.requestFocus();
                        addordernew.setError("Quantity is not Entered");
    
                    } else {
    
                        if(getstock.getText().toString().equals("Stove Top Stuffing"))
                        {
                            ShowItem.setText("Stove Top Stuffing");
                            
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Campell's Soup"))
                        {
                            ShowItem.setText("Campell's Soup");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Tide"))
                        {
                            ShowItem.setText("Tide");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Pampers"))
                        {
                            ShowItem.setText("Pampers");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Pepsi Products"))
                        {
                            ShowItem.setText("Pepsi Products");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Tang"))
                        {
                            ShowItem.setText("Tang");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Top Ramen"))
                        {
                            ShowItem.setText("Top Ramen");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Knorr"))
                        {
                            ShowItem.setText("Knorr");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Palmolive"))
                        {
                            ShowItem.setText("Palmolive");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Scotch-Brite"))
                        {
                            ShowItem.setText("Scotch-Brite");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Bounty Paper Towls"))
                        {
                            ShowItem.setText("Bounty Paper Towls");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
    
    
                        if(getstock.getText().toString().equals("Oreo Cookies"))
                        {
                            ShowItem.setText("Oreo Cookies");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
    
                        if(getstock.getText().toString().equals("Quaker Oats"))
                        {
                            ShowItem.setText("Quaker Oats");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
                        if(getstock.getText().toString().equals("Lays Potato Chips"))
                        {
                            ShowItem.setText("Lays Potato Chips");
                            Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
                        }
    
    
                        //  ShowItem.setText("Stove Top Stuffing");
                        //Showqty.setText(addordernew.getText().toString());
                       // ShowRate.setText(rategiven.getText().toString());
                        Toast.makeText(getApplicationContext(), "Order Taken", Toast.LENGTH_SHORT).show();
                    }
                }
            });

this is the code for the tax rate and percentage calculation

  getstock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(AddOrder.this, ListItem.class);
              Intent intent = getIntent();
               Bundle bd = intent.getExtras();
                if (bd != null) {
                    String getname = (String) bd.get("position");
                    getstock.setText(getname);
                    System.out.println(getname);


                   if(getstock.getText().toString().equals("Stove Top Stuffing")) {
                       taxgiven.setText("12");
                        stockgiven.setText("250");
                        rategiven.setText("598.214");
                        MRPRate.setText("999");


                       //Showqty.setText(addorder.getText().toString());
                       // ShowRate.setText(TaxInclrate.getText().toString());

                        //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)Math.round(rateamount* taxamount) / 100);
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);

                                          }
                   else if(getstock.getText().toString().equals("Campell's Soup"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("100");
                       rategiven.setText("150");
                       MRPRate.setText("456");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Tide"))
                   {
                       taxgiven.setText("5");
                       String a=taxgiven.getText().toString();
                       stockgiven.setText("50");
                       rategiven.setText("200");
                       MRPRate.setText("1000");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Pampers"))
                   {
                         taxgiven.setText("5");
                       stockgiven.setText("25");
                       rategiven.setText("100");
                       MRPRate.setText("1234");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Pepsi Products"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("5");
                       rategiven.setText("140");
                       MRPRate.setText("500");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Tang"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("23");
                       rategiven.setText("340");
                       MRPRate.setText("450");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Top Ramen"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("34");
                       rategiven.setText("1230");
                       MRPRate.setText("345");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Knorr"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("40");
                       MRPRate.setText("876");



                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Palmolive"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("145");
                       MRPRate.setText("980");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Scotch-Brite"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("10");
                       MRPRate.setText("890");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Bounty Paper Towls"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("150");
                       MRPRate.setText("1120");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Oreo Cookies"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("100");
                       MRPRate.setText("789");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Quaker Oats"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("400");
                       MRPRate.setText("1245");

                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)Math.round(rateamount* taxamount) / 100);
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }
                   else if(getstock.getText().toString().equals("Lays Potato Chips"))
                   {
                       taxgiven.setText("5");
                       stockgiven.setText("250");
                       rategiven.setText("15");
                       MRPRate.setText("900");

                       //percentage calculation
                       double taxamount = Double.parseDouble(taxgiven.getText().toString());
                       double rateamount = Double.parseDouble(rategiven.getText().toString());
                       Double result = ((double)rateamount* taxamount) / 100;
                       Double finalamount=(result + rateamount);
                       TaxInclrate.setText(""+finalamount);
                   }

                }
                startActivity(i);
            }
        });

and based on quantity i want to show the total tax rate and percentage calculation everything is work smoothly until i get this problem what can i do to get the total based on Quantity


Solution

  • getstock.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(AddOrder.this, ListItem.class);
                  Intent intent = getIntent();
                   Bundle bd = intent.getExtras();
                    if (bd != null) {
                        String getname = (String) bd.get("position");
                        getstock.setText(getname);
                        System.out.println(getname);
    
    
                       if(getstock.getText().toString().equals("Stove Top Stuffing")) {
                           taxgiven.setText("12");
                            stockgiven.setText("250");
                            rategiven.setText("598.214");
                            MRPRate.setText("999");
    
    
                           //Showqty.setText(addorder.getText().toString());
                           // ShowRate.setText(TaxInclrate.getText().toString());
    
                            //percentage calculation
                           double taxamount = Double.parseDouble(taxgiven.getText().toString());
                           double rateamount = Double.parseDouble(rategiven.getText().toString());
                           Double result = ((double)Math.round(rateamount* taxamount) / 100);
                           Double finalamount=(result + rateamount);
                           TaxInclrate.setText(""+finalamount);
    
                                              }
                       else if(getstock.getText().toString().equals("Campell's Soup"))
                       {
                           taxgiven.setText("5");
                           stockgiven.setText("100");
                           rategiven.setText("150");
                           MRPRate.setText("456");
    
                           //percentage calculation
                           double taxamount = Double.parseDouble(taxgiven.getText().toString());
                           double rateamount = Double.parseDouble(rategiven.getText().toString());
                           Double result = ((double)rateamount* taxamount) / 100;
                           Double finalamount=(result + rateamount);
                           TaxInclrate.setText(""+finalamount);
                       }
                       else if(getstock.getText().toString().equals("Tide"))
                       {
                           taxgiven.setText("5");
                           String a=taxgiven.getText().toString();
                           stockgiven.setText("50");
                           rategiven.setText("200");
                           MRPRate.setText("1000");
    
                           //percentage calculation
                           double taxamount = Double.parseDouble(taxgiven.getText().toString());
                           double rateamount = Double.parseDouble(rategiven.getText().toString());
                           Double result = ((double)rateamount* taxamount) / 100;
                           Double finalamount=(result + rateamount);
                           TaxInclrate.setText(""+finalamount);
                       }
                     
                    }
                    startActivity(i);
                }
            });
    

    this is for order class

    ordernew.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    if (addordernew.getText().toString().equals("")) {
                        addordernew.requestFocus();
                        addordernew.setError("Quantity is not Entered");
    
                    } else {
    
                        if(getstock.getText().toString().equals("Stove Top Stuffing"))
                        {
    
                             ShowItem.setText("Stove Top Stuffing");
    
                             Showqty.setText(addordernew.getText().toString());
                            ShowRate.setText(rategiven.getText().toString());
    
                            //Calculate total tax and grandtotal
                            int totalPrice=0;
                            int Totaltax=0;
                            int Grandtotal=0;
                            double taxamount = Double.parseDouble(taxgiven.getText().toString());
                            double rateamount = Double.parseDouble(rategiven.getText().toString());
                            Double result = ((double)Math.round(rateamount* taxamount) / 100);
                            Double finalamount=(result + rateamount);
                            TaxInclrate.setText(""+finalamount);
    
                          totalPrice+= (Double.parseDouble(Showqty.getText().toString()) * Double.parseDouble(rategiven.getText().toString()));
                            Totaltax+= (Double.parseDouble(Showqty.getText().toString()) * ((double)Math.round(rateamount* taxamount) / 100));
                            Grandtotal=totalPrice+Totaltax;
                          totalamtnew.setText(""+totalPrice);
                          taxnewratenew.setText(""+Totaltax);
                            discountnew.setText("0.00");
                           roundoffratenew.setText("0.00");
                         grandtotalnew.setText(""+Grandtotal);
    
    
    
    
    
                          // Totaltax += (Double.parseDouble(Showqty.getText().toString()))* Double.parseDouble(taxgiven.getText().toString());
    
                            //ShowRate.setText(""+totalPrice);
    
                         //calculate total tax grandtotal
    
    
                         // Double result = ((double)rateamount* taxamount) / 100;
    //                        taxnewratenew.setText(""+Totaltax);
    //                        discountnew.setText("0.00");
    //                        roundoffratenew.setText("0.00");
    //                        grandtotalnew.setText(""+totalPrice);
                        }
    
                        if(getstock.getText().toString().equals("Campell's Soup"))
                         {
                            ShowItem.setText("Campell's Soup");
                             ShowRate.setText(rategiven.getText().toString());
                            Showqty.setText(addordernew.getText().toString());
                            //ShowRate.setText(rategiven.getText().toString());
    
    
                             //Calculate total tax and grandtotal
                             int totalPrice=0;
                             int Totaltax=0;
                             int Grandtotal=0;
                             double taxamount = Double.parseDouble(taxgiven.getText().toString());
                             double rateamount = Double.parseDouble(rategiven.getText().toString());
                             Double result = ((double)Math.round(rateamount* taxamount) / 100);
                             Double finalamount=(result + rateamount);
                             TaxInclrate.setText(""+finalamount);
    
                             totalPrice+= (Double.parseDouble(Showqty.getText().toString()) * Double.parseDouble(rategiven.getText().toString()));
                             Totaltax+= (Double.parseDouble(Showqty.getText().toString()) * ((double)Math.round(rateamount* taxamount) / 100));
                             Grandtotal=totalPrice+Totaltax;
                             totalamtnew.setText(""+totalPrice);
                             taxnewratenew.setText(""+Totaltax);
                             discountnew.setText("0.00");
                             roundoffratenew.setText("0.00");
                             grandtotalnew.setText(""+Grandtotal);
    
    
    
    
                         }