Calculate social security contributions

Hello

This question is only out of curiosity.
I have a sum of money to be paid to a customer for a certain period.
Of this amount, I have to subtract the social security contributions. The percentage may change during the period of one month.
CREATE TABLE annuity(
 customer_id NUMBER
,amount NUMBER
,due_date DATE
,method_of_payment INTEGER
);
-- method_of_payment means the payment interval, e.g. 3 is quaterly
CREATE TABLE ssc(
 date_from DATE
,date_to DATE
,percentage NUMBER
);

INSERT INTO annuity (customer_id ,amount ,due_date ,method_of_payment)
    VALUES(1,1000,DATE '2012-01-01',3);
INSERT INTO annuity (customer_id ,amount ,due_date ,method_of_payment)
    VALUES(2,2000,DATE '2012-01-01',1);
INSERT INTO annuity (customer_id ,amount ,due_date ,method_of_payment)
    VALUES(3,3000,DATE '2012-01-01',6);

INSERT INTO ssc (date_from ,date_to ,percentage)
    VALUES (DATE '2011-12-01',DATE '2012-01-31',10);
INSERT INTO ssc (date_from ,date_to ,percentage)
    VALUES (DATE '2012-02-01',DATE '2012-05-31',20);
INSERT INTO ssc (date_from ,date_to ,percentage)
    VALUES (DATE '2012-06-01',NULL,30);

SELECT * FROM annuity;
SELECT * FROM ssc;

CUSTOMER_ID AMOUNT DUE_DATE   METHOD_OF_PAYMENT
----------- ------ ---------- -----------------
1           1000   01.01.2012 3
2           2000   01.01.2012 1
3           3000   01.01.2012 6

DATE_FROM  DATE_TO    PERCENTAGE
---------- ---------- ----------
01.12.2011 31.01.2012 10
01.02.2012 31.05.2012 20
01.06.2012            30
So far, I do the following:
I generate each month interval end_date and payment
I can not use CONNECT BY LEVEL < = method_of_payment, because I want to calculate for more then a single customer.
The method with CAST (MULTISET... part of my box, which is filled with snippets of the Web ;-)

Eventually I reach the ssc of table for each month and summarize again.
WITH annuity_each_month AS (
    SELECT  customer_id
           ,due_date
           ,amount / method_of_payment amount_per_month
           ,ADD_MONTHS(
                 due_date
                ,(ROW_NUMBER() OVER (PARTITION BY customer_id,due_date ORDER BY NULL)-1)
                ) AS generated_date
    FROM    annuity
           ,TABLE(
                CAST(
                    MULTISET(SELECT NULL FROM dual CONNECT BY ROWNUM <= method_of_payment)
                    AS sys.dbms_debug_vc2coll
                    )
                ) t
     )
SELECT  ROUND(SUM(aem.amount_per_month * ssc.percentage / 100),2) ssc_payment
       ,aem.customer_id
       ,aem.due_date
FROM    annuity_each_month aem
        JOIN ssc
          ON (   ssc.date_from <= aem.generated_date
             AND (  ssc.date_to > aem.generated_date
                 OR ssc.date_to IS NULL
                 )
             )
GROUP BY aem.customer_id
        ,aem.due_date;

SSC_PAYMENT CUSTOMER_ID DUE_DATE                  
----------- ----------- ----------
200         2           01.01.2012                
600         3           01.01.2012                
166.67      1           01.01.2012  
Does anyone know the other simple, elegant and efficient for calculating social security contributions?

Concerning
Marcus

Hello

Here's one way:

SELECT       a.customer_id
,       SUM ( a.amount
           * ssc.percentage
           * .01
           * MONTHS_BETWEEN ( LEAST    ( ADD_MONTHS ( a.due_date, a.method_of_payment)
                                         , NVL (ssc.date_to, DATE '9998-12-31') + 1
                           )
                            , GREATEST ( a.due_date
                                   , ssc.date_from
                           )
                      )
           / a.method_of_payment
           )          AS ssc_payment
FROM       annuity  a
JOIN       ssc          ON   a.due_date          <= NVL (ssc.date_to, DATE '9999-12-31')
                 and  ADD_MONTHS ( a.due_date
                              , a.method_of_payment
                         ) - 1     > ssc.date_from
GROUP BY  a.customer_id
ORDER BY  a.customer_id
;

Basically, this approach:
(a) between each line of annuity with each row overlapping of ssc
(b) estimated the number of months for this combination
(c) number of (b) is used in the calculation of the ssc_payment for this period
(d) all periods for the same customer totals.

This requires that everything works in units of 1 month; for example, a.due_date and ssc.date_from are still the first few months, and ssc.date_to is always at the end of a few months (or NULL). This approach can be adapted to work with everyday, or even fractions of a day.

Published by: Frank Kulash, may 2, 2012 08:20

Marwim wrote:
... I can not use CONNECT BY LEVEL<= method_of_payment,="" because="" i="" want="" to="" calculate="" it="" for="" more="" then="" one="">

You can use CONNECT BY if you want. When you use 'LEVEL '.<= x"="" as="" the="" only="" connect="" by="" condition,="" you="" usually="" want="" to="" use="" a="" table="" with="" only="" 1="" row.="" you="" could="" then="" join="" the="" results="" to="" the="" annuity="" table,="" with="" "lvl=""><= method_of_payment"="" as="" the="" join="">

Tags: Database

Similar Questions

  • Why Firefox remember social security numbers?

    I don't think it's normal, so I'm not sure if it's the fault of Firefox or failure of the Web site. I was just something on Paypal.com and when it came time to fill out my social security number, he had 'suggestions' pop-up in the fields with my SSN it call back before. Things like SS # and credit card, numbers not remember like that because it's a security important question for if someone else uses my computer.

    I don't want to disable fields remember entirely because this feature is useful for me. Names, addresses, phone numbers, emails, are going well to be auto-rempli, but not something extremely sensitive as SS #.

    Again, sorry if it's lack of Paypal. I will contact them instead if it is.

    Thank you for any information you can provide.

    Firefox has a built-in algorithm to check for credit card numbers (Luhn), but not for other privacy sensitive numbers.

  • AppStore will be asked for credit card and social security number

    Woman received email asking for verification of the purchase. We did not make a new purchase. Connected to answer and were invited to CR. card number AND social security number. I stepped back at that time. Apple do that?

    This is a phishing attempt. Do not respond. Shall not disclose any personal or financial information. You can use the address below to send the suspicious message to Apple. [email protected]

    The link below has information to identify fraudulent emails.

    http://support.Apple.com/kb/HT4933

  • Need help with date + put social security in shape in PDF format...

    HI -.

    I m working on a form that must be filled from the internet...

    The design I made I have InDesign - and the formfields I did I have Acrobat Pro.
    and finally I m setting everything in LiveCycle...

    I met two problems...

    I need the date field to correct himself--if the choice of the user to use the wrong format...

    for example -.

    We want to have AAAA-MM-JJ
    and if the user writes JJ MM AA-
    It must be accepted and corrected...

    Also - in Sweden in any case always write us the number of social security in this way
    YYMMDD-NNNN (N = number between 0 and 9)

    How can I get the requgnize field and 'demand' this format...

    I´ll hope my Swinglish can be understandable?

    Idespiran

    Perhaps the LC can detect the AcroForm fields and convert them into fields of LC, but you may lose some things like formatting, validation, calculation, etc.

    Is that the two are not compatible. I find easier to handle, Acrobat forms personally, but you might disagree.

    If you decide to use the LC forms, then you should post your question in the forum Live Cycle Designer.

  • QS social security number field.

    Working more generally on the end of the design/layout of Adobe products, mainly with Photoshop and InDesign... But my boss decided I have to redo all our old forms of their redesign in Adobe LiveCycle 7.1.  I have a field where the end user will be required to enter a social security number.  Our users are... not tech savvy, to say the least, and because the old forms already have dashes that go between the numbers (999-99-9999) until the user clicks in the field, they stay like that on new forms that I've created.

    In the 'Value' tab, in the 'Object' palette, I am able to enter a value by default, but when I preview the form and the attempt to enter data, the default text (spaces and dashes) don't go away.  Is there a way to make this work without scripting?  I don't know anything about scripts, so I don't know the first place to start trying to write a.  If the script is the only way, someone at - it a script, you can post for me, or a URL I can go to, to read on HOW to do it?

    Any help is greatly appreciated.  Thanks in advance!

    ~ Nicholaii

    not enough-, but it works.  Text overlays dashes during automatic formatting

    added the reset

  • I have a problem with the security of the computer.

    Original title: pirate problems

    I found the name in my story on December 5th, a says that they have our association in my computer until 2017? Please, I have the name... Help me, im afraid the name appeared as aprilsuedyer...

    Hello sarahannainttheone2012 and welcome to the Microsoft form.

    first from now this second unplug your Internet cela page must remain open but as long as the closed connections. Turn off your router

    I know that hackers doing this now because iv looked this topics. HES sale information over the Internet, the damage is done. do not mater if its buffer overflow attack or a more frequent attack

    all of your personal information has changed.  That is to say whatever it is that youv'e put on the computer. chances are that it is a key logger send password. Bank accounts. social security numbers. pins and other data typed to the intruder.

    then contact your ISP (internet service provider), they will guide you from there

    format and reinstall windows 7

    Now if your wondering why its because there is a hacker. you are probably involved in a bigger bait and the trap set in place where you clicked on the wrong thing and you where to hit

    When you set up your computer. look into getting a router. use a port closed and put in place the password to be long with letters and random numbers

    good luck and the means feel fre to post back when you get it sorted

  • % Of contribution to turnover

    Hello

    I'm new to OBIEE and I find it difficult to calculate the contribution % to the total turnover.

    Currently, I have a request to implement this output sales split in the store with a filter that shows only the sales of special items.

    I tried to add a similar request and inlcude all elements such as then I could calculate the percentage contribution to store specific items sales.

    I don't know what to do next.

    Any help would be greatly appreciated.

    Thank you

    Hello

    I'm surprised that the formula does not work.
    Your formula should look like this:

    FILTER ("Table of facts". "" Measure "to HELP ('Table of Dimension'. "Dimension attribute" IN (' value 1', 'Value 2'))) / 'Table of facts'. " "" Measure "* 100

    You must change the data format of course to get the percent sign.

    Kind regards
    Stijn

  • How do you prevent Siri to send text messages?

    My children told me just show a problem with my iPhone 6 and Siri:

    My phone is locked, my child picks up the phone, press the home button and said "Send by David SMS", Siri let him write a voice message: "what is your social security number?   Siri sends, my other child shows me it seems I just send the message from my iPhone.

    David sends what looks like his social security number (it is not, we test all this), and the message appears on my locked iPhone.

    So if I left my phone sitting around, everyone could use Siri to do things like this for the information of anyone in my Contacts, even though I have a 6-digit code and fingerprints id put in place.

    What settings I need to change on my iPhone 6 to ensure that ever happening?

    Where they have found out about this: http://www.liveleak.com/view?i=c73_1475783202

    Post edited by: Phlac - add source my children found.

    Disable Siri "access on the lock screen.

    Settings > Siri

  • iPhone more than 7. Trying to order.

    Okay, so I really need help. If someone's out there want to give me the best answer, I'm for it. I tried to buy the iPhone 7 more, BUT he asks me a phone number and all that. I put it and I also put in my social security number because that's what he was asking. It is said he struggled to connect with AT & T. The carrier I have is outspoken, but through the AT & T towers. So I'm lost. I don't know what to do anymore. I am therefore able to buy this phone.

    It looks that you choose AT & T and she's trying to check your account for the upgrade eligibility. Are you trying to finance by a carrier or buy outright?

  • Nervous about upgrading to El Capitan

    Hello

    I am currently using OS X 10.8.5 on a Mid 2012 Mac Book Pro.  I have a 500 GB HD and 432 GB available.  My processor is an Intel Core i5 2.5 GHz and I have DDR3 4 GB 1600 MHz memory.

    My question is my browser (Safari 6.2.8) is updated as much as possible with the Mountain Lion and my credit card company wants an updated set browser to access their site, and I don't know there will be others to follow soon as well as social security, Healthcare.gov, etc.  Also I was see the rotation occasionally surfing autour beach ball.  I can't use Google chrome, either as the OS is too old for that as well.  If unfortunately an upgrade is probably in order.  I've never backed up my computer, I know my pain, but to tell you the truth, it seems really complicated and unreliable.  I copied my spreadsheets, music and photos on the big flash drives. I'm NOT super trendy clientele and mostly use my computer to surf the web, pay your bills online and photos and music.

    I have read several threads here about backing up your computer and even of level 1 users they all seem like they know their way around a hard drive, but most seems to be Greek.  Archive or back up or cloning?  really! I read glowing reports for EC balanced with an equal percent of horror stories.  There are still enemies with each new version, but he always puts fear in me.   So here's my concerns and I hope that someone will be willing to help me with questions.  I apologize beforehand for the length, just trying to give as much information as possible.  I hope this is the right forum for this.

    1. once I figured out hard drive external not really "drives" I checked a few Mac ready those off to use with TM, WD and Seagate are most available.  I really useless a backup by the hour of my computer because I do not change that much every day and it seems that you have to leave this plugged in 24/7, which seems to be a pain for a laptop, making it not so portable. In addition, I read to turn off the computer to remove the external hard drive safely.  really? Just do a manual backup to once per week or per month?

    2 would it not be better for me to use a cloning software, so that I can just do a (bootable?) copy of my current operating system and files instead of the hour by hour back ups with time machine?  I don't know if I'm wise enough to understand all this.  I've been to the site Web of Super Duper and they seem useful, but that's another $ 30 on top of $60 for a 1 TB hard drive.

    3. I've read that you should have 2 copies of your back upward.  This means that the right of the external hard drive 2?

    4. do you need Internet to do back ups?  I use my iPhone as a hotspot, but go to my children if I need more long-term WiFi although their isn't super fast like his outing in the glue.

    5. I don't have a ton of applications other than those that the computer came with, but those I have I really want to lose.  Microsoft Office for Mac 2011, Family Tree Maker for Mac v. 2 being the main.  Also my printer is old so I might have to replace it. I checked their compatibility from a link on this forum.  It seems that two of them will not work.  I don't know how to check if my printer model will work with CBS. Simple workaround?  I hate to lose everything if I update.  For some applications you is impossible to pass up to that you upgrade your operating system, but does that mean that I will lose all the old files?

    6. can you have 1 computer but have 2 OS?  El Capitan when I need to do web stuff and mountain lion to use my other applications?  Probably not easy. Or do I have to take out a loan and buy another computer and keep my old for my obsolete applications?

    7. If I have to do this (upgrade) to EC what should be my game plan be?  Everything to make the transition smoother?  In simple terms for a dummy?

    Anyway, if someone wants to help, I admire!

    If you don't want to upgrade your version of OS X, the version of OS X Lion mountain Safari from Apple is more a web browser secure OS X Lion of the mountains of 10.8 and you should stop using this version of Safari.

    OS X 10.8 Mountain Lion receives more updates of security and, in my view, little time goes more to receive new updates of iTunes, either.

    Same problem with Google Chrome and Mozilla Firefox, which ended support for OS X 10.6 - 10, 8.

    Mozilla Firefox has just ended its support of web browser and its last full version, this emitted (ver. 48.0.0), last August for OS X 10.6 - 10, 8 can still be used for some time more.

    https://www.Mozilla.org/en-us/Firefox/desktop/

    OR

    Mozilla continues support of security (of newest web browser feature support) for the web browser Firefox through their program of Firefox ESR, (that you CAN download, install and use) that will continue only security support for Firefox until next April 2017 for OS X 10.6 - 10, 8.

    You can use these versions of the ESR. Ignore the notes support educational/business.

    https://www.Mozilla.org/en-us/Firefox/organizations/FAQ/

    OR

    See SeaMonkey.

    http://www.SeaMonkey-project.org/

    Good luck!

  • Contextual before accessing the e-mail dialog box

    On August 10, 2015 when I opened Firefox to access my email account, a popup dialog appeared offering online ID protection. He seemed to make an offering of Mozilla, I went and signed up for it. However, when I got to the point where they have asked for my social security number, I left. Unfortunately, in the process before this stage, I must have authorized a trial of this offer and had given their number in my debit card, assuming I would be responsible only for $1.00. 15, I got a warning from my Bank saying that my card has be used for a purchase outside the United States. The amount was priced at $29.95 per ThinkCredit. The same day I called to 800-424-0262 and asked what the charge was for and was told it was for a trial for Credit Reporting in 7 days. I said that I was not interested and told me that they would cancel the order (cancellation #79845570). I informed my Bank and they said they would monitor the account to ensure that the charge had been reversed. Yesterday I received my bank statement and noticed the my account had been charge $1.00 two times on the 10th. Once for periodic charges for the ThinkCredit and once for a recurring fee for Idsafelock (800-316-0249)
    I know it's a bit long explanation before my question of: was initiated by Mozilla or Firefox above pop-up dialog box?

    Thanking you in advance for your cooperation and consideration for answering my question, I remain,

    Robert P. Worst
    [email protected]

    No, he wasn't - Mozilla has nothing to do with "scams" like that. Best thing to do is to contact your Bank and dispute the charges.

  • Is available for download from McAfee a part of download of Mozilla Firefox?

    Quite quickly after downloading Mozill, a McAfee icon appeared on my home page and in my hard drive program files. I tried to uninstall that I saw nothing about this when I downloaded the program. A window appeared asking me my social security and a box number asking that I am hosting a new program to install. Is this normal or should I worry?

    Have you downloaded Firefox from www.mozilla.org? If you downloaded it from anywhere else, it is possible that you have been infected by malicious software.

  • Old phone, calls double

    I have recently updated from an Iphone 4S for a 6 s IPhone, keeping my existing Vodafone contract - I gave the 4 old my daughter who has a separate contract from the mobile to another mobile provider (TalkTalk) - the problem is that sometimes (IE not all the time) came from a call to me on the 6s also rings on the 4 - any advice on how to avoid this would be very welcome

    It is normal that she also get iMessages and see your journal to call and you will not be able to facetime between two devices

    This is because you use the same appleID, it can be regarded as a social security number in the apple world they all have two ring because they are both you

    Give him his own appleID and use family sharing, so you need not buy apps with its new appleID

  • I think that I have on my MBP 2010 mid thunderous

    Hi all.

    I think I have thunder-stirke on my MBP 2010 Middle even with a new disk it gets damaged soon as I installed it.

    I also have a heat excessive upper right (lower case), a vibrant hum in waves in the upper right (all lowercase) and the sounds of rattling lower trackpad.

    I moved the only external drive and everything works fine.

    Any suggestions on how to get rid of it?

    p. s.

    A new MBP is out of the question that I'm on a retirement budget social security now.

    Take a look at this thread, I think that it covers many thunderous better than me.

    Re: thunderous-2 after having been infected still infected?

    To find out what the problem may be, please download and run EtreCheck, created by one of the wizards own here in CSA. It is a diagnostic tool that is very useful for us to find problems. It will also give us additional specifications on your Mac. After his execution after the logfile here. It will never contain any personal information.

  • A third party read or access my messages without knowing?

    A third party can access my messages, watsapp or my email without my knowledge or permission of their device, a computer or Mac?

    iMessages is encrypted, so unless someone has your Apple ID and password, you shouldn't have a problem. If your email is safe depends on a number of factors, including the strength your passkey is, is how reliable your email provider and if the Government has issued a summons to appear as a guide. In the United States, there are classes of queries from Government for requiring information do not warn the user, the mail provider. I wouldn't consider sending secure enough to send credit card information or social security number. Examine the encryption options if you need for secure e-mail.

    I don't know enough about WhatsApp to comment on how secure it is.

    What should really be important, who's going to be interested in your information. If it's just a jealous ex, secure passwords of accounts and to keep all your devices protected by Word is probably enough. If you have attracted the attention of a Government, which is another case.

Maybe you are looking for

  • Portege Z930 - network WLan problems

    Z930 Windows 7 is 3 years old.I'm having problems connecting to the home network and I do not understand the clues to work towards a solution. Other laptops can connect to the wired network and wireless, but cant Z930, or down and will not show the h

  • Could not load dll target ("C:\program files\backweb\backweb client\6.1.0.153\program\backweb.dll error code126)

    Original title: error code 126 Could not load dll target ("C:\program files\backweb\backweb client\6.1.0.153\program\backweb.dll error code126) How can I fix it?

  • Inconsistency of the sample BluetoothDemo

    could someone tell me what are the requirements needed to work with thebluetooth demo? Start working with this example using the SDK 6 and 6 on my blackberry OS, allconfigurations of the eclipse had to version 6. Where try to test with another OS6 wa

  • Adding filters of mutiple to dynamic objects with different selections

    This is my workflow and issue:1 convert a layer of object / smart cab.2 make the selection of the image (for example, clouds) and then apply another filter - "Topaz" clarity - in the same smart layer.I would now like to make a different choice (for e

  • Adobe CS3 Activation question

    I used Photoshop CS3 since 2007 without problem, and yesterday I received a message "your computer Setup seems to have changed...". "and says I need to activate it. If I press OK, and then click Next, I see the message "Activate later" or try to call