Monday, July 13, 2015

Calculate Tax by the Tax Slab

I tried in the Internet to see the Tier based tax calculation , Though it looks simple i didnt get any correct solution.
Then I started wrote that logic and thought of publishing it here.


Lets assume , The give amount is Rs. 640 and we need to calculate Tax for that.

Tax Slabs are given below


Tier Range Percentage
1-30010
301-60020
601-100030
1001 and above40


The Tax Calculation for the given Amount Rs. 640 should be like this

           for the first 300 Rs                                            Tax    :                  30
           Second Tier   up to 600 Rs                               Tax    :                   60
          Last /  Third Tier    up to 40 Rs                          Tax   :                   12


Total Tax Amount :  102

The method to do this operation given below



private static void calculate( double salary) {

    TierRange[] tierRanges = new TierRange[] {

            new TierRange(1, 300, 1.25), new TierRange(301, 600, 1.75), new TierRange(601, 1000, 2.25),
            new TierRange(1001, 999999, 2.75),

    };
    double  given = salary;

    double amount = 0.0;

    if (given == 0) {
        amount = 0;
    } else {

        for (TierRange tierRange : tierRanges) {

            int calcValue = 0;
            if (given >= tierRange.low && given <= tierRange.high) {
                calcValue = (given - tierRange.low) + 1;
                amount += (calcValue * tierRange.value);
                System.out.println(given+"  "+calcValue+"  "+amount+" "+(calcValue * tierRange.value));
                break;
            } else {
                calcValue = (tierRange.high - tierRange.low) + 1;
                amount += (calcValue * tierRange.value);
                System.out.println(given+"  "+calcValue+"  "+amount+" "+(calcValue * tierRange.value));
            }

        }
    }


TierRange is a class which contains 3 fields low , high and percentage .



The same can be done using a Stored Procedure also

       

Assume Tier Ranges comes from a Table called

BILL_ADMIN.TIER_TEMPLATE

The query to fetch the Tier Range given below

SELECT TIER_START , TIER_END , RATE_PU FROM BILL_ADMIN.TIER_TEMPLATE;


TIER_START   --- Low Range
 TIER_END      ----  High Range
 RATE_PU       --- Rate Percentage


create or replace PROCEDURE BILLINGCALCPROC
IS

T_GIVEN NUMBER;
T_TIER_START NUMBER ;
T_TIER_END NUMBER;
T_RATE_PU NUMBER;
T_CALCVAL NUMBER;
T_BILL_ID VARCHAR2(30);
T_AMOUNT NUMBER;

CURSOR BILL_CALC
IS
SELECT TOTAL_UNIT, BILL_ID FROM BILL_ADMIN.MONTHLY_INVOICE ;
CURSOR TIER_RANGE
IS
SELECT TIER_START , TIER_END , RATE_PU FROM BILL_ADMIN.TIER_TEMPLATE;


BEGIN

OPEN BILL_CALC;
LOOP
FETCH BILL_CALC INTO T_GIVEN ,T_BILL_ID;
EXIT
WHEN BILL_CALC%NOTFOUND;
T_AMOUNT := 0;
IF (T_GIVEN=0) THEN
UPDATE BILL_ADMIN.MONTHLY_INVOICE SET AMOUNT = 0 WHERE BILL_ID = T_BILL_ID;
ELSE
OPEN TIER_RANGE;
LOOP
FETCH TIER_RANGE INTO T_TIER_START ,T_TIER_END, T_RATE_PU;
EXIT
WHEN TIER_RANGE%NOTFOUND;
T_CALCVAL := 0;
IF(T_GIVEN >= T_TIER_START AND T_GIVEN <= T_TIER_END) THEN
T_CALCVAL := (T_GIVEN - T_TIER_START ) +1;
T_AMOUNT := T_AMOUNT + (T_CALCVALT_RATE_PU);
UPDATE BILL_ADMIN.MONTHLY_INVOICE
SET AMOUNT = T_AMOUNT
WHERE BILL_ID = T_BILL_ID;
GOTO LOOP_END;
ELSE
T_CALCVAL := (T_TIER_END - T_TIER_START ) +1;
T_AMOUNT := T_AMOUNT + (T_CALCVALT_RATE_PU);
END IF;
END LOOP;
<>
CLOSE TIER_RANGE;
END IF;
END LOOP;
CLOSE BILL_CALC;
COMMIT;
END;


This is for the Refernce .



Thursday, March 26, 2015

Make in India - My Version



I am living in a House  with nice backyard.  It has good ambiance, no noise pollution or air pollution.
It has very good water sources too .


One day , I  invited a businessman to my home and offered him to use my backyard for rent.
He agreed. He came with 1000 Rs investment money to my home. He offered Rs. 150 as rent to use my backyard and one more Rs. 150 for me to work as Employee for him.  I too happily agreed for that.


Businessman purchased raw materials for Rs.700 , started manufacturing work in my backyard. He has completed the manufacturing work and the final product is ready now.


He sold the final product to me and my neighbor , each costs Rs. 600.  He finally left with money Rs 1200. He got 20%  profit. I got employment and rent from him . I felt my lifestyle got improved .


Do you think this is a happy ending story  ?


Oh sorry ,please wait,  i missed to tell few things in this story.
The manufacturing work created few other things too


  • It created air pollution and noise pollution
  • It took plenty of water resources also
  • it left out huge of amount Chemical waste in my backyard which will not go away for years.
  • Last but not the least , the manufactured product is a Gun or Bomb. ( I hope everybody knows Make in India is not for consumer products , it is to manufacture weapons in India ).


Now , please decide what kind of story it is and do we really need “Make In India”.




                      










Thursday, February 26, 2015

Network Drive Mapping for Windows Services

This Article will explain about the steps need to be followed to use the Network Shared folders in the
Windows Services .

When we see the " Directory Path Invalid  " error during the Service start up, most of solutions
comes in Google search will tell us to use the UNC (Universal Naming Convention) Path for instead of Shared Folder mapping.

But sometimes the UNC path is not a perfect solution, especially in my  case where it has $ symbol in that path.  The Shared folder is from one windows server and it has a $ symbol in the path .

The UNC path with the $ symbol is not  accepted by the Apache  HTTP server while publishing the directory using the Alias name.

So what we did to resolve this issue.

the solution is we should have  a Drive letter for the mapped Shared Folder and it should be with the user
NT AUTHORITY / SYSTEM ..

Here is the one time setup to resolve this issue.


1. Download the Sysinternals Suite to the system from Microsoft website.
2.  Unzip the suite and keep it in some folder. (Ex C:\tmp)
3. Open the Command prompt using Run as Administrator .
4. type whoami in the command prompt it will show ur user id .
5. Go to Sysinternals suite folder and execute the following command
                      psexec -i -s comd.exe
        It will open a new command prompt.
       if check user id using the command whoami  .. It will display NT AUTHORITY \SYSTEM.
6. In the new command prompt execute the mapping command

        Syntax
                            net use DRIVELETTER: UNCPath /persistent:yes /savecre

       Ex  :
                            net use L: \\server1\folder1  /persistent /savecre

7. Now a New Drive will be available in the My Computer with the Title "Disconnected Network Drive"
    Don't worry about the title it is connected and you can access the files.
    Except  the user System for all others it will display as Disconnected Network Drive .
8. Now go to Apache HTTP Server Config file (httpd.conf)  which is available in the installed folder
   under conf directory .
 
     The Directory directive used to publish the files to the browser can use the newly created Drive path.



In case if you want to have the drive connected every time you logged in , you can add the step
6 command in a batch file.

Open the Control Panel --> Administrative Tools --> Scheduled Tasks - Schedule a Task and should run as "SYSTEM" .

That's all !!!
 Now start the HTTP Server and it will serve you those files.