Credit issue needs help

My issue is that we canu2019t manage our credit exposure under this scenario.  Assume a customer has a $1.5mm Credit line.  If we u2018credit approveu2019 $1mm order, and all but $100k is confirmed and ships; then we u2018credit approveu2019 an additional $600k order (which our credit screen would show bringing us up to our credit limit); but then the product arrives for the original $100k out of stock u2013 and then we end up with a $1.6mm balance on a $1.5mm credit line.
What are the available alternatives in standard SAP?

While it's captured by the above - a specific example of what you can give is actual output or error messages from the updates in which you have "encountered issues".
The mouse/touchpad problems do not likely produce any (obvious) error messages, so it's not unreasonable for those to be a bit more cryptic - but the update attempts definitely produce output ... share it.
The mouse/touchpad problems may leave some useful information in dmesg logs - particularly right after you connect the mouse.
Are you using synaptics?

Similar Messages

  • Spry Menu Bar issue, NEED HELP...???

    Here is the coding for a menu bar that i created with CS3, for some reason i am having an issue when i open the web page in IE, on firefox and safari it looks fine, the menu drops down to sub menu's fine, but for some reason when i open it in IE, the submenu's show on the very top of the page rather than right below the menu itself, please check my coding and see if there is an issue???
    i ran compatability and there are no issues shown.
    @charset "UTF-8";
    /* SpryMenuBarHorizontal.css - Revision: Spry Preview Release 1.4 */
    /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */
    LAYOUT INFORMATION: describes box model, positioning, z-order
    /* The outermost container of the Menu Bar, an auto width box with no margin or padding */
    ul.MenuBarHorizontal
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        cursor: default;
        width: auto;
    /* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */
    ul.MenuBarActive
        z-index: 1000;
    /* Menu item containers, position children relative to this container and are a fixed width */
    ul.MenuBarHorizontal li
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        position: relative;
        text-align: left;
        cursor: pointer;
        width: 10.4em;
        float: left;
        background-image: url(tab2.png);
    /* Submenus should appear below their parent (top: 0) with a higher z-index, but they are initially off the left side of the screen (-1000em) */
    ul.MenuBarHorizontal ul
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        z-index: 1020;
        cursor: default;
        width: 8.2em;
        position: absolute;
        left: -1000em;
        text-decoration: underline;
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to auto so it comes onto the screen below its parent menu item */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible
        left: auto;
        background-image: url(../tab1.png);
    /* Menu item containers are same fixed width as parent */
    ul.MenuBarHorizontal ul li
        width: 8.2em;
    /* Submenus should appear slightly overlapping to the right (95%) and up (-5%) */
    ul.MenuBarHorizontal ul ul
        position: absolute;
        margin: -5% 0 0 95%;
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible ul.MenuBarSubmenuVisible
        left: auto;
        top: 0;
    DESIGN INFORMATION: describes color scheme, borders, fonts
    /* Submenu containers have borders on all sides */
    ul.MenuBarHorizontal ul
    /* Menu items are a light gray block with padding and no text decoration */
    ul.MenuBarHorizontal a
        display: block;
        cursor: default;
        padding: 0.5em 0.75em;
        color: #FFFFFF;
        text-decoration: none;
        border-left-color: #0063bd;
        border-right-color: #0063bd;
        border-right-width: 3px;
        border-left-width: thin;
        font-family: Calibri;
        font-weight: bold;
        font-size: 19px;
    /* Menu items that have mouse over or focus have a blue background and white text */
    ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus
        color: #000000;
    /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */
    ul.MenuBarHorizontal a.MenuBarItemHover, ul.MenuBarHorizontal a.MenuBarItemSubmenuHover, ul.MenuBarHorizontal a.MenuBarSubmenuVisible
        color: #000000;
    SUBMENU INDICATION: styles if there is a submenu under a given menu item
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenu
        background-image: url(SpryMenuBarDown.gif);
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenu
        background-image: url(SpryMenuBarRight.gif);
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenuHover
        background-image: url(SpryMenuBarDownHover.gif);
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenuHover
        background-image: url(SpryMenuBarRightHover.gif);
        background-repeat: no-repeat;
        background-position: 95% 50%;
    BROWSER HACKS: the hacks below should not be changed unless you are an expert
    /* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */
    ul.MenuBarHorizontal iframe
        position: absolute;
        z-index: 1010;
    /* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */
    @media screen, projection
        ul.MenuBarHorizontal li.MenuBarItemIE
        display: inline-block;
        f\loat: left;
        position: relative;

    Hey gramps, thanks for the info, i have updated my spry framework to 1.6.1 but the problem is still the same, i recreated my menu with the new 1.6 and it still doing the same thing, the submenu's are like vertically reversed... ugh need help.
    here the new code
    @charset "UTF-8";
    /* SpryMenuBarHorizontal.css - version 0.6 - Spry Pre-Release 1.6.1 */
    /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */
    LAYOUT INFORMATION: describes box model, positioning, z-order
    /* The outermost container of the Menu Bar, an auto width box with no margin or padding */
    ul.MenuBarHorizontal
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        cursor: default;
        width: auto;
    /* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */
    ul.MenuBarActive
        z-index: 1000;
    /* Menu item containers, position children relative to this container and are a fixed width */
    ul.MenuBarHorizontal li
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        position: relative;
        text-align: left;
        cursor: pointer;
        width: 10.4em;
        float: left;
    /* Submenus should appear below their parent (top: 0) with a higher z-index, but they are initially off the left side of the screen (-1000em) */
    ul.MenuBarHorizontal ul
        margin: 0;
        padding: 0;
        list-style-type: none;
        font-size: 100%;
        z-index: 1020;
        cursor: default;
        width: 8.2em;
        position: absolute;
        left: -1000em;
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to auto so it comes onto the screen below its parent menu item */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible
        left: auto;
        background-image: url(../tab1.png);
        line-height: 18px;
    /* Menu item containers are same fixed width as parent */
    ul.MenuBarHorizontal ul li
        width: 8.2em;
    /* Submenus should appear slightly overlapping to the right (95%) and up (-5%) */
    ul.MenuBarHorizontal ul ul
        position: absolute;
        margin: -5% 0 0 95%;
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible ul.MenuBarSubmenuVisible
        left: auto;
        top: 0;
    DESIGN INFORMATION: describes color scheme, borders, fonts
    /* Submenu containers have borders on all sides */
    ul.MenuBarHorizontal ul
        border: 1px solid #CCC;
    /* Menu items are a light gray block with padding and no text decoration */
    ul.MenuBarHorizontal a
        display: block;
        cursor: pointer;
        padding: 0.5em 0.75em;
        color: #FFFFFF;
        text-decoration: none;
        font-size: 19px;
        font-family: Calibri;
        font-weight: bolder;
    /* Menu items that have mouse over or focus have a blue background and white text */
    ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus
        color: #000000;
    /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */
    ul.MenuBarHorizontal a.MenuBarItemHover, ul.MenuBarHorizontal a.MenuBarItemSubmenuHover, ul.MenuBarHorizontal a.MenuBarSubmenuVisible
        color: #000000;
    SUBMENU INDICATION: styles if there is a submenu under a given menu item
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenu
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenu
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenuHover
        background-repeat: no-repeat;
        background-position: 95% 50%;
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a "hover" background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenuHover
        background-repeat: no-repeat;
        background-position: 95% 50%;
    BROWSER HACKS: the hacks below should not be changed unless you are an expert
    /* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */
    ul.MenuBarHorizontal iframe
        position: absolute;
        z-index: 1010;
    /* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */
    @media screen, projection
        ul.MenuBarHorizontal li.MenuBarItemIE
        display: inline;
        f\loat: left;

  • Concurrent crystal license timeout Issue, need help.

    Hi,
    My company is using crystal enterprise 10 with 18 concurrent user license.
    However, we often hit out of crystal license issues.
    Does time to wait for exporting crystal reports to excel/pdf takes up licenses?
    Does time to wait for crystal report to be printed or viewed on the web browser takes up licenses?
    We all know that user sessions take up user licenses. 1 user login take up 1 license.
    Does crystal pruning job takes up user licenses too?
    Need help urgently, much appreciated.

    Hi Daren,
    Support on Cystal Enterprise 10 has expired. Make sure that your users are actually logging off and not just closing their browser.
    One user can take up multiple licenses by not logging off or opening multiple browsers to view multiple reports. Scheduled jobs that are running do not take up license, but a user veiwing a historical instance does take up a license.
    In your metrics tab in the Cyrsatl Management Console -> Servers-> cms you should be able to see the active number of sessions- system connections are backend connections between the servers and these do not take up any licenses.
    Best Regards,
    Jadie

  • T400 LCD dim issue - Need help!!

    I'm having a LCD dim issue with a T400. Have changed the LCD panel, LCD cable and systemboard but still having same issue. If i removed the lcd card, then the display is working fine. I've tested the lcd card in another working unit and it's working as well (means the lcd card is working). I use a working lcd card and plug into this T400 but LCD still dim. 
    I've try to switch the problematic lcd cable and lcd panel to a working systemboard and it kills the systemboard. Have try to switch a few things but still unable to find the root cause. Urgently need help on this. Any advice will be appreciated.
    Model : 6475-RM5

    hey bhoh
    i suggest uninstalling your current graphic card driver, let windows install its own generic drivers and see if that makes any difference
    WW Social Media
    Important Note: If you need help, post your question in the forum, and include your system type, model number and OS. Do not post your serial number.
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"!
    Follow @LenovoForums on Twitter!
    Have you checked out the Community Knowledgebase yet?!
    How to send a private message? --> Check out this article.

  • Stuttering flv playback issue- need help asap

    We need help asap. Have a project is due to deliver today (5/14).
    We have a video to go on a dvd-rom, live action with Motion Graphics behind.
    When output is done thru Projector the Motion Graphics stutter as they scroll.
    Here is more technical info:
    Stuttering flv playback issue:
    Prores 422 timeline 29.97fps 1280x720 output from fcp using current settings.
    Mov file is approx 7gb, plays relatively smooth on a mac pro with no raid.
    Frame by frame analysis shows all frames are present with no jumps tears or skips.
    Tried several output paths, programs and settings to create a smooth flv file to no avail.
    We adjusted data rates from 2k, 3.5k, 4k and 8k, no luck
    We adjusted keyframe rates from low to all frames, no luck.
    We tried cs3 flash encoder, cs5 media encoder, squeeze ect, same results.
    Playback in the flash projector seems to choke slightly no matter what we do.
    Have also posted in the Director Forum.
    Any help much appreciated!

    Here are a few ideas off the top of my head:
    Try playing the file using a different xtra, sometimes different ones will work better.  If you have Director 11.5, there is a native flv playback xtra.
    You can build a player easily in Flash using the flvPlayback component, then bring that into Director as a swf.
    Once you have the video in Director, try making the member Direct To Stage (DTS).  If it is already DTS, try making it not DTS.
    Make sure the video is not transparent, and nothing in Director overlaps the video... in fact, when the video is playing, nothing should be moving at all, and try to keep the amount of code that is running to a minimum.
    Try lowering your video's data rate further or try using a different codec.
    Using VBR (Variable Bit Rate) compression often makes the video appear to play smoother.
    Try compressing the flv with different software.  FFMpeg, for example, is free and does a very good job, often better than the Flash Video Encoder that comes with Flash/Creative Suite.

  • RSI Issue: Need help on IBM/Lenovo external keyboards w Trackpoint? Pic

    Need help on IBM/Lenovo external keyboards w Trackpoint? Pic
    I started my journey with Thinkpads on a T42, then T43.. then T61, X61T, R61 & T410 (bought for 2 cousins & they love it), W510 (dads new laptop). I may be a much recent convert but I swear by them now. 
    MAJOR ISSUE: Recently started feeling RSI (Repetitive Stress) & Carpal Tunnel symptoms (already doing stretches.. adjusted the desk.. & finding new adjustable LCD stand) since I am not using the Thinkpad directly... but using it docked with an External keyboard. Lot of Mousing as well. I'd like to go back to Thinkpad FEEL... or atleast have keyboard with a pointing device so my hands dont have to keep moving back n forth. 
    So, it would be great it some of my fellow T4x/T6x/X6x 'ers would guide me a bit on this... share their first hand experience, or what they've seen on these keyboards and feel free to point me to reliable sources of information. 
    Currently this would greatly be use with T61 - Adv Mini Dock - 30" XHD3000 LCD as shown in my signature below. 
    Anyone who has used or know something about one of these Thinkpad related keyboard (ideally both of these to give a comparative response). 
    Which of the following have you used? 
    How was the experience? 
    (Maybe point me to thread with peoples experiences)
    If you've used several, which one do you prefer / recommend? Why? 
    At the moment I have a "slim" BTC 6200C desktop keyboard. It has laptop like scissor keyswitches, so I like it the slim notebook like profile. 
    The way I have positioned my 30" LCD I'd like to be able to keep the keyboard on my lap at times while on my chair and maybe on the desk at times. 
    ThinkPad Full-Size UltraNav USB Keyboard 
    The keyboard and trackpad of the IBM Lenovo Thinkplus USB Keyboard with Ultranav:
    ThinkPad Travel UltraNav USB Keyboard 
    The travel version of the above:
    Newer: 
    ThinkPad USB Keyboard with TrackPoint
    A 2009 replacement for the previous one but not the full keyboard nor wireless: 
    Thinkpads:
    T61 8892-02U: 14.1"SXGA+/2.2C2D/4G/XP|Adv Mini Dock|30" Gateway XHD3000 WQXGA via Dual-link DVI
    X61T 7767-96U: 12.1"SXGA+/1.6C2D/3G/Vista|Ultrabase
    W510 4319-2PU: 15.6"FHD/i7-720QM/4G/Win7Pro64 (for dad)
    T43 1875-DLU: 14.1"XGA/1.7PM-740/1G/XP
    Dell:
    Inspiron 9300: 17"WUXGA/NVidiaGeForce6800/2.2PM/2G/XP (old)

    I had the same issue - had to go to voice command for a few weeks (sucked) wore wrist gards to keep things netural.
    Everything went away when I changed to a USB keyboard with the Ultra nav (I use the track point and disable the pad).
    I've been working like that for 6+ years now... no issues.
    (as a side note, sleeping with wrist guards on helped heal me the fastest.  I had neoprine, with a metal plate in them - from a local drug store)

  • LCD monitor display issue, need help

    I have a strange problem with my LCD display, it goes like this:
    When I first boot up the mac and the wallpaper appears on the display the image looks perfect, all the tones are right etc, but as the startup progresses, programs loading etc, the display changes suddenly, becomes too bright in the highs, too dark in the lows, and over-saturated in between. Its looks horrible.
    I have just discovered that I can correct the issue by going into system prefs, display, selecting the options tab (next to Display and Color) and turning overscan on, then back off, voila, all fixed.
    Looks great.
    Thing is I have to do this every time now that I start the computer, and Im wondering if anyone knows what causes this issue and if theres anything I can do as a more robust solution.
    The kicker is I have the same problem with a viewsonic LCD on my secondary machine (Powermac G5, Osx 10.4), right at the beginning of startup it looks great then suddenly all goes wrong, too dark/light over-saturated. Its as if the image has been blended with itself in multiply mode a la photoshop.
    And on my second machine there is no option for overscan so I cant use my quick fix.
    Is overscan a feature of the OS or the monitor?
    The worst part is I need these displays to work correctly because Im a graphic designer, I need my colors to look right so I can do my job, and while I could go buy a $1000 monitor its not possible atm, and Id kinda like to know why this problem occurs. So if I do buy a different I can be assured the problem wont rear its ugly head again. But I dont think the problme is the monitor. I think its something to do with the communication between the display and the computer.
    The monitor can display correctly, and does for a brief moment, then it all goes very wrong. Ive spoken to NEC and they werent much help but Ill be trying them again today too.
    But again, I thinks its the computer, not the monitors as I can reproduce the issue swapping out monitors.
    I hope Ive described it adequately,
    Thanks in advance for any help forthcoming, this is very frustrating and is causing me endless headaches.

    Mattdp,
    I am currently having the same problem with my 20" cinema display. Did you ever find a long term solution? Apple states that the PowerMac G5 is legacy with no support available, and suggested a reset the PRAM. I did so to no avail. I too have 10.4.11 and thus no "overscan" to turn off. This is my wife's primary computer for her photography business, and the color issue needs to be resolved as quickly as I can find the answer.
    Is there a possible solution through the terminal?
    Rick

  • HT201272 Need help guys i purchased a gems using my credit card but i didnt get the gems in that game but i was charge on my credit card, need help :(

    I tried to purchased gems in the game castle master i used my credit card but when i tried to purchase for the first time no gems was added on my account i tried it again it went thru but when i saw my invoice for my purchase i got charged twice but i only got the gems once, NEED HELP PLEASE

    Hi..
    If this is an In-App purchase, turn off the subscription until the matter is resolved >  iTunes Store: Purchasing and managing auto-renewing subscriptions
    iTunes Store: About In-App Purchases

  • Odd mail issues, need help

    A couple of things I need help with.
    1) Mail constantly goes offline and pops up a dialog box asking for my password. I enter my password in the box and hit okay and it doesn't take. I can hit cancel and put mail back online but that's a pain. What is causing that and how do I fix it?
    2) People send me mail and then about 30 min later I get the same email again. This problem doesn't happen with every email, just some.
    I have no mail rules on. and I run virus software and it's fine.
    Can someone please help me on this. Thanks!
    1.25 GHz PPC G4 / 20"   Mac OS X (10.3.9)   768 MB DDR SDRAM, iSight camera, Wacom Tablet

    Open /Applications/Utilities/Keychain Access, choose Keychain First Aid from the application menu, and proceed to repair the keychain. If that doesn’t work, you may try removing the password entry from the keychain and letting Mail create it again.
    Also, in Mail open Help > Mail Help and read the article titled “Mail keeps asking for my keychain password”, in case it applies to you. There is a related article titled “My password is not saved” that you may also want to read, but beware that the last suggestion provided there (deleting the mail account) is wrong and could cause irretrievable data loss if this was a POP account.
    Note that Mail doesn’t always correctly report what the problem really is. If Mail can connect to the server but cannot log into your mail account for some reason, it’ll ask for your password, regardless of whether that’s really the problem or not. Don’t keep entering the password every time, because that’s not the problem (click Cancel instead, and take the account back online afterwards).
    What’s the time interval chosen in Mail > Preferences > General > Check for New Mail? If it’s set to Every minute, try changing it to Every 5 minutes.
    Go to Apple Menu > System Preferences > Network, choose Network Port Configurations from the Show popup menu, and make sure that the configuration used to connect to Internet appears at the top of the list.
    Also, try using a different method to connect to Internet, if possible, or connecting the computer to Internet as directly as possible, i.e. bypassing any routers that might be present, using an ethernet cable instead of wireless, etc., and see whether that makes a difference.
    BTW, if you’re using Mac OS X 10.3, as your profile indicates, it would have been more appropriate to discuss this in the Mail & Address Book - Mac OS X 10.3 & earlier forum. If the discussion applies to both Mail 1.x and Mail 2.x, it doesn’t really matter, but it’s difficult to know that in advance.

  • HP NC2400 Drive cable issue : need help

    Can someone please send a picture of what an installed zif harddrive drive for an NC2400 looks like ? Does it go topside up or down ? How does the cable look when installed ? Need help. Does anyone have a spare harddrive cable ?
    Any help would be much appreciated!!
    Bill C.

    This manual shows the drive with the metal side Up
    http://h10032.www1.hp.com/ctg/Manual/c00741440.pdf
    Service manual here, it does not show the cable as a separate part of part number
    Click Me
    You will need to contact HP parts
    http://partsurfer.hp.com/ContactUs.aspx

  • Performance Issue ---Need help

    Hello Friends,
    Could you guys please help me in improving the performance. This query takes 2 minutes to run and I was wondering if you guys can just take a look and suggest something. I would really appreciate your help on this
    ALTER PROCEDURE [dbo].test
    @loginid int,
    @branchid int,
    @asofdate datetime,
    @ageperiod int,
    @showdetails bit,
    @programstatus INT,
    @propertytype INT,
    @sortby nvarchar(100)
    AS
    BEGIN
    SET FMTONLY OFF -- will allow temp tables on procedures for fyi reporting
    SET NOCOUNT ON
    SELECT
    mecdate = CONVERT( DATETIME, CONVERT(NVARCHAR(4),monthendyear) + '-' + CONVERT(NVARCHAR(2),monthendmonth) + '-1 00:00:00.000' ),
    branchid
    INTO
    #mecs
    FROM
    tmonthendcompleted
    WHERE
    companyid = 1 -- we should put it as parameter but we only have one company
    AND
    @branchid = -999
    OR branchid = @branchid
    --Create temp table
    CREATE TABLE #tmpAR
    branchid int not null default (0),
    accountid int not null default (0),
    siteid int not null default (0),
    programid int not null default (0),
    routeid int not null default(0),
    invoiceid int not null default (0),
    paymentid int not null default(0),
    transactiondate datetime not null,
    eventname nvarchar(50) not null,
    agingbucketnumber int not null default (0),
    invoicetotal money not null default (0),
    paymenttotal money not null default (0),
    prepay money not null default (0),
    prepayid int not null default(0)
    --Get pending invoices
    INSERT INTO
    #tmpAR (branchid, accountid, siteid, programid, routeid, invoiceid, transactiondate, eventname, agingbucketnumber, invoicetotal)
    SELECT
    invitem.servicecenterid, inv.accountid, est.siteid, invitem.programid,
    ISNULL((select top 1 routeid from tprogramvalue WHERE programid = invitem.programid AND effectivedate <= @asofdate and routeid > 0 order by effectivedate desc, utctimestamp desc), 0),
    inv.invoiceid, inv.invoicedate, max(invitem.itemdescription),
    -- go to first day of invoice month, get max MEC date and datediff to get bucket # (according to asofdate)
    ISNULL((DATEDIFF(MONTH, DATEADD(month, DATEDIFF(month, 0, inv.invoicedate), 0), (SELECT MAX(mecdate) FROM #mecs WHERE branchid = invitem.servicecenterid AND mecdate <= @asofdate)) ),0),
    SUM(invitem.subtotalregular + invitem.fedtaxregular + invitem.statetaxregular + invitem.localtaxregular)
    FROM
    tinvoiceitem invitem
    INNER JOIN tinvoice inv ON invitem.invoiceid = inv.invoiceid
    INNER JOIN tprogram prog ON invitem.programid = prog.programid
    INNER JOIN tprogramsetup ON prog.programtypeid = tprogramsetup.programtypeid
    INNER JOIN testimate est ON prog.estimateid = est.estimateid
    INNER JOIN vreportlogin on invitem.servicecenterid = vreportlogin.branchid
    INNER JOIN ttempkeyid tmpkey on tprogramsetup.reportcategory=tmpkey.keyid and tmpkey.typeid=64 and tmpkey.loginid = @loginid
    WHERE
    vreportlogin.loginid = @loginid
    AND (@branchid=-999 or vreportlogin.branchid = @branchid)
    AND inv.invoicedate < @asofdate
    GROUP BY
    invitem.servicecenterid, inv.accountid, est.siteid, invitem.programid, inv.routeid,
    inv.invoiceid, inv.invoicedate
    HAVING
    (ROUND(SUM(ISNULL([subtotalregular],0) + ISNULL([fedtaxregular],0) + ISNULL([statetaxregular],0) + ISNULL([localtaxregular],0)),2)
    ROUND(ISNULL((select sum(tpaymentitem.amount)
    from tpaymentitem
    inner join tpayment on tpayment.paymentid = tpaymentitem.headerid
    where invoiceid=inv.invoiceid
    and tpayment.datereceived < @asofdate),0)
    ,2)
    ) > 0
    --Get payments to pending invoices
    INSERT INTO
    #tmpAR (branchid, accountid, siteid, programid, routeid, invoiceid, paymentid, transactiondate, eventname, agingbucketnumber, paymenttotal)
    SELECT
    payitem.servicecenterid, pay.accountid, est.siteid, payitem.programid,
    ISNULL((select top 1 routeid from tprogramvalue WHERE programid =payitem.programid AND effectivedate <= @asofdate and routeid > 0 order by effectivedate desc, utctimestamp desc), 0),
    payitem.invoiceid, pay.paymentid, pay.datereceived,
    (select max(tinvoiceitem.itemdescription) from tinvoiceitem where invoiceid = payitem.invoiceid),
    -- go to first day of invoice month, get max MEC date and datediff to get bucket # (according to asofdate)
    ISNULL((DATEDIFF(MONTH, DATEADD(month, DATEDIFF(month, 0, inv.invoicedate), 0), (SELECT MAX(mecdate) FROM #mecs WHERE branchid = payitem.servicecenterid AND mecdate <= @asofdate)) ),0),
    SUM(payitem.amount)
    FROM
    tpaymentitem payitem
    INNER JOIN tpayment pay ON payitem.headerid = pay.paymentid
    INNER JOIN tprogram prog ON payitem.programid = prog.programid
    INNER JOIN tprogramsetup ON prog.programtypeid = tprogramsetup.programtypeid
    INNER JOIN testimate est ON prog.estimateid = est.estimateid
    INNER JOIN tinvoice inv ON payitem.invoiceid = inv.invoiceid
    INNER JOIN vreportlogin on payitem.servicecenterid = vreportlogin.branchid
    INNER JOIN ttempkeyid tmpkey on tprogramsetup.reportcategory=tmpkey.keyid and tmpkey.typeid=64 and tmpkey.loginid = @loginid
    WHERE
    vreportlogin.loginid = @loginid
    AND (@branchid=-999 or vreportlogin.branchid = @branchid)
    AND payitem.invoiceid in (select invoiceid from #tmpAR)
    AND pay.datereceived < @asofdate
    GROUP BY
    payitem.servicecenterid, pay.accountid, est.siteid, payitem.programid, inv.routeid,
    payitem.invoiceid, inv.invoicedate, pay.paymentid, pay.datereceived
    --Get payments to cop
    INSERT INTO
    #tmpAR (branchid, accountid, siteid, programid, routeid, prepayid, transactiondate, eventname, prepay)
    SELECT
    payitem.servicecenterid, pay.accountid, est.siteid, payitem.programid,
    ISNULL((select top 1 routeid from tprogramvalue WHERE programid =payitem.programid AND effectivedate <= @asofdate and routeid > 0 order by effectivedate desc, utctimestamp desc), 0) as routeid,
    pay.paymentid, pay.datereceived, max(progname.programname), SUM(payitem.amount)
    FROM
    tpaymentitem payitem
    INNER JOIN tpayment pay ON payitem.headerid = pay.paymentid
    INNER JOIN tprogram prog ON payitem.programid = prog.programid
    INNER JOIN tprogramsetup ON prog.programtypeid = tprogramsetup.programtypeid
    INNER JOIN tprogramsetupname000 progname ON progname.programtypeid = prog.programtypeid
    INNER JOIN testimate est ON prog.estimateid = est.estimateid
    INNER JOIN vreportlogin on payitem.servicecenterid = vreportlogin.branchid
    INNER JOIN ttempkeyid tmpkey on tprogramsetup.reportcategory=tmpkey.keyid and tmpkey.typeid=64 and tmpkey.loginid = @loginid
    WHERE
    vreportlogin.loginid = @loginid
    AND (@branchid=-999 or vreportlogin.branchid = @branchid)
    AND pay.datereceived < @asofdate
    AND payitem.invoiceid = 0
    GROUP BY
    pay.paymentid, payitem.servicecenterid, pay.accountid, est.siteid, payitem.programid, pay.datereceived
    CREATE TABLE #tmpAR2
    branchid int not null default (0),
    accountid int not null default (0),
    siteid int not null default(0),
    programid int not null default(0),
    routeid int not null default(0),
    invoiceid int not null default(0),
    paymentid int not null default(0),
    prepayid int not null default(0),
    transactiondate datetime,
    transactiondescription nvarchar(200),
    eventname nvarchar(50),
    InBucket01 money default (0),
    InBucket2 money default (0),
    InBucket3 money default (0),
    InBucket4 money default (0),
    InBucket5 money default (0),
    prepay money default (0),
    ProgramInBucket01 money not null default(0),
    ProgramInBucket2 money not null default(0),
    ProgramInBucket3 money not null default(0),
    ProgramInBucket4 money not null default(0),
    ProgramInBucket5 money not null default(0),
    ProgramDebit money not null default(0),
    ProgramCredit money not null default(0),
    ProgramBalance money not null default(0),
    RouteInBucket01 money not null default(0),
    RouteInBucket2 money not null default(0),
    RouteInBucket3 money not null default(0),
    RouteInBucket4 money not null default(0),
    RouteInBucket5 money not null default(0),
    RouteDebit money not null default(0),
    RouteCredit money not null default(0),
    RouteBalance money not null default(0),
    BranchInBucket01 money not null default(0),
    BranchInBucket2 money not null default(0),
    BranchInBucket3 money not null default(0),
    BranchInBucket4 money not null default(0),
    BranchInBucket5 money not null default(0),
    BranchDebit money not null default(0),
    BranchCredit money not null default(0),
    BranchBalance money not null default(0)
    update #tmpAR
    set agingbucketnumber = 4
    where agingbucketnumber > 4
    --Bucket 0 INVOICES
    INSERT INTO #tmpAR2 (branchid, accountid, invoiceid, transactiondate, transactiondescription, eventname, InBucket01, siteid, programid, routeid)
    SELECT branchid, accountid, invoiceid, transactiondate, dbo.fngetTransactionDescription(invoiceid,1) as description, eventname, invoicetotal, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 0
    AND invoicetotal > 0
    --Bucket 0 PAYMENTS
    INSERT INTO #tmpAR2 (branchid, accountid, paymentid, transactiondate, transactiondescription, eventname, InBucket01, siteid, programid, routeid)
    SELECT branchid, accountid, paymentid, transactiondate, dbo.fngetTransactionDescription(paymentid,2) as description, eventname, paymenttotal*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 0
    AND paymenttotal <> 0
    --Bucket 1 INVOICE
    INSERT INTO #tmpAR2 (branchid, accountid, invoiceid, transactiondate, transactiondescription, eventname, InBucket2, siteid, programid, routeid)
    SELECT branchid, accountid, invoiceid, transactiondate, dbo.fngetTransactionDescription(invoiceid,1) as description, eventname, invoicetotal, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 1
    AND invoicetotal > 0
    --Bucket 1 PAYMENT
    INSERT INTO #tmpAR2 (branchid, accountid, paymentid, transactiondate, transactiondescription, eventname, InBucket2, siteid, programid, routeid)
    SELECT branchid, accountid, paymentid, transactiondate, dbo.fngetTransactionDescription(paymentid,2) as description, eventname, paymenttotal*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 1
    AND paymenttotal <> 0
    --Bucket 2 INVOICES
    INSERT INTO #tmpAR2 (branchid, accountid, invoiceid, transactiondate, transactiondescription, eventname, InBucket3, siteid, programid, routeid)
    SELECT branchid, accountid, invoiceid, transactiondate, dbo.fngetTransactionDescription(invoiceid,1) as description, eventname, invoicetotal, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 2
    AND invoicetotal > 0
    --Bucket 2 PAYMENT
    INSERT INTO #tmpAR2 (branchid, accountid, paymentid, transactiondate, transactiondescription, eventname, InBucket3, siteid, programid, routeid)
    SELECT branchid, accountid, paymentid, transactiondate, dbo.fngetTransactionDescription(paymentid,2) as description, eventname, paymenttotal*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 2
    AND paymenttotal <> 0
    --Bucket 3 (91-120 days) INVOICES
    INSERT INTO #tmpAR2 (branchid, accountid, invoiceid, transactiondate, transactiondescription, eventname, InBucket4, siteid, programid, routeid)
    SELECT branchid, accountid, invoiceid, transactiondate, dbo.fngetTransactionDescription(invoiceid,1) as description, eventname, invoicetotal, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 3
    AND invoicetotal > 0
    --Bucket 3 (91-120 days) PAYMENTS
    INSERT INTO #tmpAR2 (branchid, accountid, paymentid, transactiondate, transactiondescription, eventname, InBucket4, siteid, programid, routeid)
    SELECT branchid, accountid, paymentid, transactiondate, dbo.fngetTransactionDescription(paymentid,2) as description, eventname, paymenttotal*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 3
    AND paymenttotal <> 0
    --Bucket 4 (over 120 days) INVOICES
    INSERT INTO #tmpAR2 (branchid, accountid, invoiceid, transactiondate, transactiondescription, eventname, InBucket5, siteid, programid, routeid)
    SELECT branchid, accountid, invoiceid, transactiondate, dbo.fngetTransactionDescription(invoiceid,1) as description, eventname, invoicetotal, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 4
    AND invoicetotal > 0
    --Bucket 4 (over 120 days) PAYMENTS
    INSERT INTO #tmpAR2 (branchid, accountid, paymentid, transactiondate, transactiondescription, eventname, InBucket5, siteid, programid, routeid)
    SELECT branchid, accountid, paymentid, transactiondate, dbo.fngetTransactionDescription(paymentid,2) as description, eventname, paymenttotal*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE agingbucketnumber = 4
    AND paymenttotal <> 0
    --Prepay
    INSERT INTO #tmpAR2 (branchid, accountid, prepayid, transactiondate, transactiondescription, eventname, prepay, siteid, programid, routeid)
    SELECT branchid, accountid, prepayid, transactiondate, dbo.fngetTransactionDescription(prepayid,2) as description, eventname, prepay*-1, siteid, programid, routeid
    FROM #tmpAR
    WHERE prepay <> 0
    DECLARE @InBucket01Total money
    DECLARE @InBucket2Total money
    DECLARE @InBucket3Total money
    DECLARE @InBucket4Total money
    DECLARE @InBucket5Total money
    DECLARE @DebitBalance money
    DECLARE @CreditBalance money
    DECLARE @Balance money
    --PROGRAM TOTALS
    SELECT
    INTO
    #tmpProgramTotals
    FROM
    #tmpAR2
    DECLARE @programid int
    DECLARE @routeid int
    WHILE (select COUNT(*) from #tmpProgramTotals) > 0
    BEGIN
    select top 1 @programid = programid, @routeid = routeid from #tmpProgramTotals
    --Get Program Totals
    select
    @InBucket01Total = SUM(InBucket01),
    @InBucket2Total = SUM(InBucket2),
    @InBucket3Total = SUM(InBucket3),
    @InBucket4Total = SUM(InBucket4),
    @InBucket5Total = SUM(InBucket5),
    @DebitBalance = SUM(InBucket01) + SUM(InBucket2) + SUM(InBucket3) + SUM(InBucket4) + SUM(InBucket5),
    @CreditBalance = SUM(prepay),
    @Balance = ((SUM(InBucket01) + SUM(InBucket2) + SUM(InBucket3) + SUM(InBucket4) + SUM(InBucket5)) + SUM(prepay))
    from #tmpProgramTotals where programid = @programid and routeid = @routeid
    UPDATE
    #tmpAR2
    SET
    ProgramInBucket01 = @InBucket01Total,
    ProgramInBucket2 = @InBucket2Total,
    ProgramInBucket3 = @InBucket3Total,
    ProgramInBucket4 = @InBucket4Total,
    ProgramInBucket5 = @InBucket5Total,
    ProgramDebit = @DebitBalance,
    ProgramCredit = @CreditBalance,
    ProgramBalance = @Balance
    WHERE
    programid = @programid
    AND routeid = @routeid
    delete #tmpProgramTotals where programid = @programid and routeid = @routeid
    END
    DROP TABLE #tmpProgramTotals
    CREATE TABLE #tmpIncludedprepay (paymentid int)
    SELECT
    INTO
    #tmpProgramCredits
    FROM
    #tmpAR2
    WHILE (select COUNT(*) from #tmpProgramCredits) > 0
    BEGIN
    select top 1 @programid = programid, @routeid = routeid from #tmpProgramCredits
    declare @programcreditbalance money
    select @programcreditbalance = ProgramCredit from #tmpAR2 where programid = @programid and routeid = @routeid
    while @programcreditbalance < 0
    BEGIN
    declare @creditamount money
    declare @paymentid int
    select top 1 @creditamount = prepay, @paymentid = prepayid
    from #tmpAR2
    where programid = @programid and routeid = @routeid
    and prepayid <> 0 and prepayid not in (select paymentid from #tmpIncludedprepay)
    and prepay < 0
    order by transactiondate desc
    insert into #tmpIncludedprepay values (@paymentid)
    if @programcreditbalance - @creditamount > 0
    BEGIN
    UPDATE
    #tmpAR2
    SET
    prepay = @programcreditbalance
    WHERE
    prepayid = @paymentid
    END
    set @programcreditbalance = @programcreditbalance - @creditamount
    END
    delete #tmpProgramCredits where programid = @programid and routeid = @routeid
    END
    DROP TABLE #tmpProgramCredits
    DELETE FROM #tmpAR2
    WHERE prepayid <> 0 AND prepayid not in (select paymentid from #tmpIncludedprepay)
    DROP TABLE #tmpIncludedprepay
    SELECT
    acct.accountid,
    acct.accountnum,
    br.branchid,
    br.branchname,
    r.routeid,
    r.routename,
    CASE scontact.businessname WHEN '' THEN scontact.lastname + '. ' + scontact.firstname ELSE scontact.businessname END as Name,
    sphone.phonenumber,
    CASE WHEN prog.canceldate is not null THEN 'Cancelled'
    ELSE CASE WHEN prog.pendingcanceldate is not null THEN 'Pending Cancel'
    ELSE CASE WHEN prog.warrantyexpirationdate <= @asofdate THEN 'Expired'
    ELSE 'Active' END
    END
    END as programstatus,
    CASE WHEN prog.canceldate is not null THEN 3
    ELSE CASE WHEN prog.pendingcanceldate is not null THEN 4
    ELSE CASE WHEN prog.warrantyexpirationdate <= @asofdate THEN 2
    ELSE 1 END
    END
    END as programstatus_indicator,
    prog.programid,
    convert(varchar, transactiondate, 101) as transactiondate,
    transactiondescription,
    eventname,
    (CASE WHEN prepay <> 0 then prepay else InBucket01 END) as InBucket01,
    InBucket2,
    InBucket3,
    InBucket4,
    InBucket5,
    ProgramDebit,
    ProgramCredit,
    ProgramBalance,
    ProgramInBucket01,
    ProgramInBucket2,
    ProgramInBucket3,
    ProgramInBucket4,
    ProgramInBucket5,
    RouteInBucket01,
    RouteInBucket2,
    RouteInBucket3,
    RouteInBucket4,
    RouteInBucket5,
    RouteDebit,
    RouteCredit,
    RouteBalance,
    BranchInBucket01,
    BranchInBucket2,
    BranchInBucket3,
    BranchInBucket4,
    BranchInBucket5,
    BranchDebit,
    BranchCredit,
    BranchBalance,
    Detail = 1,
    Age = CASE @ageperiod
    WHEN 0 THEN 'Debits'
    WHEN 1 THEN 'Credits'
    WHEN 2 THEN '31-60 Days and older'
    WHEN 3 THEN '61-90 Days and older'
    WHEN 4 THEN '91-120 Days and older'
    WHEN 5 THEN '120 Days and older'
    WHEN -999 THEN 'All Balance'
    END,
    PropertyType = CASE sit.propertytype
    WHEN 1 THEN 'Residential'
    WHEN 2 THEN 'Commercial'
    WHEN 5 THEN 'National'
    ELSE ''
    END
    INTO
    #results
    FROM
    #tmpAR2
    INNER JOIN taccount acct ON acct.accountid = #tmpAR2.accountid
    INNER JOIN tbranch br ON br.branchid = #tmpAR2.branchid
    INNER JOIN troute r ON r.routeid = #tmpAR2.routeid
    INNER JOIN tprogram prog ON prog.programid = #tmpAR2.programid
    INNER JOIN testimate est ON est.estimateid = prog.estimateid
    INNER JOIN tsite sit ON sit.siteid = est.siteid
    INNER JOIN tcontact scontact on acct.primarycontactid = scontact.contactid
    INNER JOIN taddress saddr on acct.billingaddressid = saddr.addressid
    LEFT JOIN tcontactphonenumber sphone ON scontact.primaryphoneid = sphone.phoneid
    WHERE
    --Debit Balance
    (@ageperiod <> 0 OR ProgramBalance > 0)
    --Credit Balance
    AND (@ageperiod <> 1 OR ProgramBalance < 0)
    --31-60 Days and older
    AND (@ageperiod <> 2 OR (ProgramInBucket2 > 0 or ProgramInBucket3 > 0 or ProgramInBucket4 > 0 or ProgramInBucket5 > 0))
    --61-90 Days and older
    AND (@ageperiod <> 3 OR (ProgramInBucket3 > 0 or ProgramInBucket4 > 0 or ProgramInBucket5 > 0))
    --90 Days and older
    AND (@ageperiod <> 4 OR (ProgramInBucket4 > 0 or ProgramInBucket5 > 0))
    --120 Days and older
    AND (@ageperiod <> 5 OR ProgramInBucket5 > 0)
    -- property type
    AND (@propertytype = -999 OR sit.propertytype = @propertytype)
    --Need to add a line with null values for the timeline if details are not showing
    IF @showdetails = 0
    BEGIN
    INSERT INTO
    #results
    SELECT DISTINCT
    --TFS-8903 .. JL ... 2/12/2014
    accountid,
    accountnum, branchid, branchname, routeid, routename, Name,
    phonenumber, programstatus,programstatus_indicator,programid, null, null, null,
    null, null, null, null, null,
    ProgramDebit,ProgramCredit, ProgramBalance,
    ProgramInBucket01, ProgramInBucket2, ProgramInBucket3, ProgramInBucket4, ProgramInBucket5,
    RouteInBucket01, RouteInBucket2, RouteInBucket3, RouteInBucket4, RouteInBucket5,
    RouteDebit, RouteCredit, RouteBalance,
    BranchInBucket01, BranchInBucket2, BranchInBucket3, BranchInBucket4, BranchInBucket5,
    BranchDebit, BranchCredit, BranchBalance,
    0, Age, PropertyType
    FROM
    #results
    DELETE FROM #results
    WHERE Detail = 1
    END
    IF @programstatus <> -999 AND @programstatus <> 1 -- ACTIVE
    BEGIN
    DELETE r
    FROM
    #results r
    INNER JOIN tprogram p
    ON r.programid = p.programid
    WHERE
    r.programstatus_indicator = 1
    END
    IF @programstatus <> -999 AND @programstatus <> 2 -- Expired
    BEGIN
    DELETE r
    FROM
    #results r
    INNER JOIN tprogram p
    ON r.programid = p.programid
    WHERE
    r.programstatus_indicator = 2
    END
    IF @programstatus <> -999 AND @programstatus <> 3 -- CANCELLED
    BEGIN
    DELETE r
    FROM
    #results r
    INNER JOIN tprogram p
    ON r.programid = p.programid
    WHERE
    r.programstatus_indicator = 3
    END
    IF @programstatus <> -999 AND @programstatus <> 4 -- PENDING CANCEL
    BEGIN
    DELETE r
    FROM
    #results r
    INNER JOIN tprogram p
    ON r.programid = p.programid
    WHERE
    r.programstatus_indicator = 4
    END
    SELECT
    branchid,
    routeid
    INTO
    #branchesRoutes
    FROM
    tbranchroute
    IF @branchid <> -999
    BEGIN
    DELETE FROM #branchesRoutes
    WHERE branchid <> @branchid
    END
    SELECT
    accountid = ISNULL(res.accountid,0),
    accountnum = ISNULL(res.accountnum, ''),
    branchid = b.branchid,
    branchname = b.branchname,
    routeid = r.routeid,
    routename = r.routename,
    Name = ISNULL(Name,''),
    phonenumber,
    programstatus,
    programid = ISNULL(programid,0),
    transactiondate = transactiondate,
    transactiondescription,
    eventname,
    detail0to30 = InBucket01,
    detail31to60 = InBucket2,
    detail61to90 = InBucket3,
    detailOver90 = InBucket4,
    detailOver120 = InBucket5,
    ProgramDebit = ISNULL(ProgramDebit,0),
    ProgramCredit = ISNULL(ProgramCredit,0),
    ProgramBalance = ISNULL(ProgramBalance,0),
    Program0to30 = ISNULL(ProgramInBucket01,0),
    Program31to60 = ISNULL(ProgramInBucket2,0),
    Program61to90 = ISNULL(ProgramInBucket3,0),
    ProgramOver90 = ISNULL(ProgramInBucket4,0),
    ProgramOver120 = ISNULL(ProgramInBucket5,0),
    Route0to30 = ISNULL(RouteInBucket01,0),
    Route31to60 = ISNULL(RouteInBucket2,0),
    Route61to90 = ISNULL(RouteInBucket3,0),
    RouteOver90 = ISNULL(RouteInBucket4,0),
    RouteOver120 = ISNULL(RouteInBucket5,0),
    RouteDebit = ISNULL(RouteDebit,0),
    RouteCredit = ISNULL(RouteCredit,0),
    RouteBalance = ISNULL(RouteBalance,0),
    Branch0to30 = ISNULL(BranchInBucket01,0),
    Branch31to60 = ISNULL(BranchInBucket2,0),
    Branch61to90 = ISNULL(BranchInBucket3,0),
    BranchOver90 = ISNULL(BranchInBucket4,0),
    BranchOver120 = ISNULL(BranchInBucket5,0),
    BranchDebit = ISNULL(BranchDebit,0),
    BranchCredit = ISNULL(BranchCredit,0),
    BranchBalance = ISNULL(BranchBalance,0),
    ISNULL((select top 1 tfinancestatussetup.financestatus
    from tevent inner join tfinancestatussetup on tevent.financestatusid = tfinancestatussetup.financestatusid
    inner join tprogram on tevent.programid = tprogram.programid
    inner join #results r2 on r2.programid = tprogram.programid
    inner join testimate on testimate.estimateid = tprogram.estimateid
    where testimate.accountid = res.accountid
    order by tevent.submitteddate desc), '') as racstatus,
    Detail = ISNULL(Detail,0),
    Age,
    Case
    when (acc.allowautobill = 1) or
    (select count(accp.programid) from taccountebaprogram accp
    where accp.accountid = acc.accountid ) > 0 then 'Auto Pay'
    else ''
    END as StatusNote,
    CASE @sortby
    WHEN 'name' THEN 1
    ELSE 0
    END as Sort,
    PropertyType,
    hasservices = CASE WHEN res.accountid IS NULL THEN 0 ELSE 1 END
    INTO
    #results2
    FROM
    #results res
    inner join taccount acc on acc.accountid=res.accountid
    inner join #branchesRoutes br on br.routeid = res.routeid AND br.branchid = res.branchid
    inner join troute r ON r.routeid = br.routeid
    inner join tbranch b on b.branchid = br.branchid
    --Set Route Totals
    SELECT
    routeid,
    SUM(ProgramInBucket01) as RouteInBucket01,
    SUM(ProgramInBucket2) as RouteInBucket2,
    SUM(ProgramInBucket3) as RouteInBucket3,
    SUM(ProgramInBucket4) as RouteInBucket4,
    SUM(ProgramInBucket5) as RouteInBucket5, --xx
    SUM(ProgramDebit) as RouteDebit,
    SUM(ProgramCredit) as RouteCredit,
    SUM(ProgramBalance) as RouteBalance
    INTO
    #routetotals
    FROM
    (select distinct
    routeid, programid, ProgramInBucket01, ProgramInBucket2, ProgramInBucket3, ProgramInBucket4, ProgramInBucket5, ProgramDebit, ProgramCredit, ProgramBalance
    from
    #results
    ) t
    GROUP BY
    routeid
    UPDATE
    #results2
    SET
    Route0to30 = t.RouteInBucket01,
    Route31to60 = t.RouteInBucket2,
    Route61to90 = t.RouteInBucket3,
    RouteOver90 = t.RouteInBucket4,
    RouteOver120 = t.RouteInBucket5,
    RouteDebit = t.RouteDebit,
    RouteCredit = t.RouteCredit,
    RouteBalance = t.RouteBalance
    FROM
    #results2
    INNER JOIN #routetotals t on t.routeid = #results2.routeid
    --Set Branch Totals
    SELECT
    branchid,
    SUM(Route0to30) as BranchInBucket01,
    SUM(Route31to60) as BranchInBucket2,
    SUM(Route61to90) as BranchInBucket3,
    SUM(RouteOver90) as BranchInBucket4,
    SUM(RouteOver120) as BranchInBucket5,
    SUM(RouteDebit) as BranchDebit,
    SUM(RouteCredit) as BranchCredit,
    SUM(RouteBalance) as BranchBalance
    INTO
    #branchtotals
    FROM
    (select distinct
    branchid, routeid, Route0to30, Route31to60, Route61to90, RouteOver90, RouteOver120, RouteDebit, RouteCredit, RouteBalance
    from
    #results2
    ) t
    GROUP BY
    branchid
    UPDATE
    #results2
    SET
    Branch0to30 = t.BranchInBucket01,
    Branch31to60 = t.BranchInBucket2,
    Branch61to90 = t.BranchInBucket3,
    BranchOver90 = t.BranchInBucket4,
    BranchOver120 = t.BranchInBucket5,
    BranchDebit = t.BranchDebit,
    BranchCredit = t.BranchCredit,
    BranchBalance = t.BranchBalance
    FROM
    #results2
    INNER JOIN #branchtotals t on t.branchid = #results2.branchid
    SELECT * FROM #results2 -- order by routeid, branchid
    drop table #branchesRoutes
    drop table #tmpAR
    drop table #branchtotals
    drop table #routetotals
    drop table #tmpAR2
    drop table #results
    drop table #results2
    drop table #mecs
    END

    Use this tool on my web site:
    http://www.sommarskog.se/sqlutil/sqltrace.html
    The stored procedure sp_sqltrace sets up a trace filtered for you own spid, and accepts a command batch, which in your case is a call to your stored procedure. It will aggregrate the data per statement. This procedure helps you identify what is taking time.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • I am having problems rebooting my mid 2009 macbook pro (grey screen other issues), need help!

    I am having problems rebooting, I have experienced the same problem as others with the grey screen but my case is a little different, It started with my mid 2009 macbook pro acting a little slower than normal, the screen would freeze, mouse wouldnt move and i'd be forced to "force reboot" this went on for a couple of days until i was tinkering with the wifi connection and it froze again. I had to reboot and this time i noticed that it took a long time to get to the login screen. i put in my password and it went into infinite load (i also tried the guest account and other accounts with same result). i tried rebooting again and the same thing would happen. after several reboots, the screen just stayed grey, sometimes with the apple logo and gear sometimes without it. Since its a 2009, (and for the most part, still works like a champ) i decided test the ram, i took one stick of ram out at a time to see if i could notice anything wrong with them. when i stuck just one in, the mac was still having the same problem rebooting. i pulled that ram and and stuck in the other and i noticed that this time the apple logo never appeard and a big crossed out circle appeared. figuring that the ram must be the problem, i ordered new ram and installed it. i noticed that when i rebooted for the first time with the new ram it was rather quick and took me straight to the login screen and i was able to log in with no problem. at this point i thought the problem was solved, but i noticed the macbook still acting funny. at first, none of my files appeared on my desktop or in the finder window. after about 20 minutes, everything magically popped up. i also noticed long pauses/freezes with the colored pin wheel spinnig. i closed the laptop and opened it again and the screen just stayed black. i tried rebooting again, and again i got the grey screen with no signs of being able to log in... i waited about 20 minutes and tried to reboot again and again i was able to log in, however the macbook is still acting slow and will freeze with no signs of unfreezing without a reboot.
    my macbook is 5 years old and has plenty of miles on it, so i understand if the thing needs to be replaced alltogether but does anyone know what could be the issue? could the bad ram have corrupted the hard drive in anyway? would re-installing the OS fix it?? and if so, how would i do that if i downloaded mavericks from the app store? are there any other solutions to this problem?
    all my files and what not are backed up on an external HD so theres nothing on it that i'd miss desperately if i had to whipe the hard drive but id really like to get her working again without any whiping of the HD. if anyone can help me out, it'd be greatly appreciated

    It is very difficult to offer troubleshooting suggestions when the "os version" you are using is unknown as each os has their own troubleshooting solutions. 
    How large is your hard drive and how much hard drive space do you have left? 

  • Animated .GIF Issue Need Help

    I made an animated gif with a transparent background, saved it for the web with the best quality settings I know of, and the image gets this weird white outline around it. Here's what it looks like on grey background so you can actually see the issue I'm having: http://imgur.com/ujKBJDu
    at first I thought it was an anti alias issue with my crappy laptop, but then when I exported it on a high end gaming pc it looked exactly the same. Anyway I need to export this and not end up with this issue so any help is appreciated.

    When it comes to gif, there is no anti-aliasing. As the transparency has only one shade of grey. The white line is residual from a white background.

  • EP6 sp12 Performance Issue, Need help to improve performance

    We have a Portal development environment with EP6.0 sp12.
    What we are experiencing is performance issue, It's not extremely slow, but slow compared to normal ( compared to our prod box). For example, after putting the username and password and clicking the <Log on> Button it's taking more than 10 secs for the first home page to appear. Also currently we have hooked the Portal with 3 xAPPS system and one BW system. The time taken for a BW query to appear ( with selection screen) is also more than 10 secs. However access to one other xAPPS is comparatively faster.
    Do we have a simple to use guide( Not a very elaborate one) with step by step guidance to immediately improve the performance of the Portal.
    Simple guide, easy to implement,  with immediate effect is what we are looking for in the short term
    Thanks
    Arunabha

    Hi Eric,
      I have searched but didn't find the Portal Tuning and Optimization Guide as you have suggested, Can you help to find this.
    Subrato,
      This is good and I would obviously read through this, The issue here is this is only for Network.
      But do you know any other guide, which as very basic ( may be 10 steps) and show step by step the process, it would be very helpful. I already have some information from the thread Portal Performance - page loads slow, client cache reset/cleared too often
    But really looking for answer ( steps to do it quickly and effectively) instead of list of various guides.
    It would be very helpful if you or anybody( who has actually done some performance tuning) can send  a basic list of steps that I can do immediately, instead of reading through these large guides.
    I know I am looking for a shortcut, but this is the need of the hour.
    Thanks
    Arun

  • Compatability Issue: Need Help Disabling Additional Functions - URGENT!

    I am experiencing a problem with running Pro Tools 8.0.4 LE on my HP Pavilion dv7, which is encountered as a DAE error -6006 when loading Pro Tools. Research indicates that this error relates somehow to the firewire connection, and I am able to use Pro Tools on this system with a different interface (one that only has two microphone inputs) that allows me to connect via USB.
    Also, when I do run Pro Tools via USB it seems that I can't use the Quick Punch feature without a minimum 10 second (usually a lot longer) delayed response after pressing the playback or record button!
    I have been emailing Pro Tools support back and forth daily for 10 days now, and in the most recent email, they have said:
    "This might be an incompatibility issue. HP Pavilion dv7 laptop is not tested by our US headquarter testing team 
    and not officially supported.
    As you have found by yourself, each PC manufacture pre- installs their own features (as TV tuner) and the program into 
    Windows OS , the motherboard and BIOS. They work differently to Pro Tools and sometimes conflict. That is why we cannot support those PCs we have not tested.
    Please turn off all the additional function by HP from BIOS. Please ask HP support how to do."
    Therefore, I am requesting assistance with disabling all unnecessary services and processes on my HP laptop. I am assuming that the TV tuner is not a necessary service, but I have no idea about most of the others, and obviously I don't want to disable something that is necessary.
    If you could help me ASAP I would really appreciate it, as I need to get on with recording urgently! Thank you.
    This question was solved.
    View Solution.

    UPDATE:
    I have also been advised by Pro Tools support that if I add a supported FireWire card with Texas Instrument FireWire chip onto my computer, it may solve the problem. When I asked them how to go about doing this, they responded:
    "If your PC has Express Card slot, 
    http://avid.custkb.com/avid/app/selfservice/search.jsp?DocId=352647
    SIIG FireWire 2-Port ExpressCard
    is tested and supported FireWire card.
    Please ask HP about the spec of your computer."

Maybe you are looking for

  • Order of songs on Ipod different than in Itunes

    I have my itunes to sort my songs by "Date Added" so the most recent songs show up at the top of the playlists. However, when I synced it to my new nano 5th gen, the songs are alphabetically listed on the ipod. How can I fix this? I haven't had this

  • After Effects & Premiere CS5 HELP!

    I purchased Adobe CS5 Master Collection through my work. IT was already opened when I got it. When I installed it every program was there to install except After Effects and Premiere. This was on my macbook pro duel cor 2.16 running snow leopard. Whe

  • When I try to update LR I get an error message Application not found

    When I try to update LR I get an error message "Application not found". When I try Help in LR it can't be found. What is wrong?

  • Height adjustment for Intel I-Macs

    As a consulting ergonomist I am baffled by Apple decision to mount the new I-mac on a base that allows little height adjustment. I queried one of my All-apple-all-the-time clients about obtaining VESA mounts for these machines and heard back through

  • Pidgin audio call error

    when I use audio call in pidgin ,there are two differernt repsonse 1,one error is: error adding stream 2,there is only "Calling" in the audio calling window. my arch is 64 bit pidgin is Pidgin 2.7.3 (libpurple 2.7.3) thanks for your help !