Alpha Video Training
Page 1 of 3 123 LastLast
Results 1 to 30 of 82

Thread: Complex conditional lookup

  1. #1
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Complex conditional lookup

    Hello -

    I hope someone can help me with a problem in creating a lookup for a client. This is a small lawn care company that I'm working with.

    I need to add a line items to an invoice. OK no problem right???

    The problem I'm having is kind of mulit-faceted.

    They have both 'hard items' like sprinkler parts, mower parts, etc. and they have services that, depending on what the service is, is charged differently.

    The parts I have no problem with - real similar to AlphaSports setup. Where I'm running in to problems is looking up for the services.

    I have several spreadsheets they use (of course no rhyme or reason in the pricing - I'm trying to get them to change still) that I converted to tables. Most of the services are charged out based on square footage of the property they are treating (Fertilizer, insect controll, weed controll, etc. Some are also charged hourly.

    The customer table contains a field for lawn area (in sq ft) and account type. Depending on the service I need to find the area measurement in the appropriate range in the servicelookup table and put that cost in the line item based on commercial or residential.

    The other problem I'm having is how to put both 'parts' and 'services' on the same invoice. In other words how to choose where I'm looking for the item number to charge out.

    I've attached a small test db that I've been playing with. May be some one can see something I'm missing.

    Thanks for your help!

    Scott

  2. #2
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Complex conditional lookup

    Hi Scott,

    I have not looked at your app but the first thing that comes to mind is a second child table for the items that are charged by the sq ft. You will need to decide if the labour charge fields could be included in one of these tables or have another child table.

    The lookup would be filtered based on commercial or residential. This would be a filed value in the customer table.

    The the child tables would be used as sub reports on Invoices etc.
    Last edited by Keith Hubert; 04-24-2009 at 05:57 PM.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  3. #3
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Keith -

    Thanks for the quick reply.

    I do have a separate table for the lookup of the service. Also a table for the products. The problem I'm having is I can look up the products just fine and they fill in the lineitems table just fine - I just can't get the switch over to the service table to work.


    Also the services has a range of lawn area. so... (not real figures I'm not in front of it right now.)

    AREA Residential Commercial
    0 - 1999 sq ft $33.95 $31.95
    2000 - 2499 sq ft $38.95 $36.95
    2500 - 2999 sq ft $43.95 $41.95
    and so on.

    Say the customer I'm entering in the invoice for has a lawn with 2105 sq ft (a field in the customer table) and is residential (also a field in the customer). I would need to find it in the table in the 2000-2499 range for area and determine that the price to fill in would be $38.95

    It is the switching between the two lookups and the determining where the customers area falls in the service ranges that have me baffled.

    Thanks.

    Scott

  4. #4
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Complex conditional lookup

    Hi Scott,

    It is getting late here so I'll just answer the question about the second lookup.

    Assuming there is more than 1 item, then you would have a second browse on the form.

    With regard to the area costings, that would be a calculated field using a Case Select function. See the help file.

    I'll have another look at this interesting project in the morning.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  5. #5
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    Scott, I'm having a look but have a question... in your Product table the Product_Id is defaulting to a format of Pnnn. I understand that it's autoincrement, but where are you setting the "P"?

  6. #6
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    David -

    The "P" was set in the first record. P0001 Alpha continues the numbering convention automatically in the auto increment rules. Kind of silly but it is a left over from old A4 DOS days for me. Helps me to know what numbers and ids are what when I'm looking at the tables.

  7. #7
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Keith -

    I thought about the second browse a bit. I suppose I could put a second browse to the same lineitems (invoice_items) if I had to. I just think that would be bit confusing adding invoice items to the invoice for my client. Not to mention the screen real estate it would take up.

    I thought a bit about placing a button on the form to 'add' a new item to the invoice. Then using a dialog box to set a variable as to which lookup to perform. There is 4 different price sheets they use that all have different rates. I'm still trying to normalize the data to get it down to a tight db. They are just reluctant to change because of the "it's the way we've always done it" and if it "ain't broke why fix it?" mentality.

    Scott

  8. #8
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    Scott... not sure if this is what you want...

    Is the idea to build a list of Products/Services for the client in the Invoice form?

    If so, in the Product table include services as well. For those Services based on Sq. Ft. enter a cost of 0.00

    Now, when you pick a Product, the browse will be filled in, as it is now.
    But, when you pick a Service, and it's 0.00 then the servicelookup table will be accessed, the sq. ft. found in area and the Cost will be placed in the price field. I'm not very good with complex expressions yet - I tend to go right after the source using code. The code for this is in the field rules for the set under Product_Id.

    I also added a condition to the Product_Id lookup where it sets price so that the cost of 0.00 is not written to the price field.

    Also, I took off the .T. on the Skip field for Product_Id - not sure why now - maybe it was so I could enter services as S001.

    This also lets you put Parts and Services on the same invoice.

    Attached is an updated database.

  9. #9
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    Scott, when you get into the Event code for Product_Id in the table, add the following lines after the Table_Open

    query.sort = "area"
    indx = tbl.query_create()

    This will make sure the Area is sorted so that the test for Area will be correct.

  10. #10
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Complex conditional lookup

    Hi David,

    That Lookup is rather neet, but how would you filter the lookup of Product->Price based on the value of Accttype?
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  11. #11
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    You could add a filter to the code. The ServiceLookup table doesn't have AcctType right now, but it makes sense to add it if the costs are different for services based on area. It's not great that you have to loop through the ServiceLookup table, but the # of records are finite and few so...

  12. #12
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Complex conditional lookup

    Hi David,

    I think you missed my filter question, I was asking about doing a filter to the Product table if the customer is either Domestic or Retail.

    Ideally Conditional Lookup tables can be used, so that different price fields can be displayed.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  13. #13
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Hi David and Keith -

    I just got in this morning and will look this over. Thanks in advance for all you are helping me with this.

    It always amazes me the willingness of the Alpha community to help each other out.

    More soon - Scott

  14. #14
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    I see what you mean Keith. I've played with it but can't see a way using Lookups to set either the Commerical or RetailPrice based on AcctType AND be able to set Service price. I'd use code at this point.

  15. #15
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    David -

    I guess I need you to step me through what you did.

    When I go into to the Invoice form to create a new invoice it now behaves differently than what I think it should.

    Instead of starting at the top with choosing a customer it starts out entering a new invoice item for the current invoice.

    On entering a product I still only get the commercial pricing. Not the retail.

    I don't see any fill in if I enter a service 'part'.

    I'll keep working with this to try and see what you did.

    Thanks!

  16. #16
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Complex conditional lookup

    Hi David,

    Now you see what I mean about two tables and two browses. Leads to easier control.

    Scott, you are worried about screen real estate, what about having the extra browse on a tabbed object.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  17. #17
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Hi Keith and David -

    I have still yet to decipher Davids example. I can't see the forest for the trees I think.

    I did manage to get something working partially - some what.
    I just started over and tried it from a different route. Something one of you said got me to thinking, "what if I set the pricelevel and type first before looking up the item_no?"

    This works fine if the lookup tables are the same structure. I still can't wrap my head around the area thing and would like to "bring in" the level and the type from the customer table. Maybe as a variable??

    Any way at least some progress. Let me know if you have any ideas.

    Thanks again to you both for all your help!

  18. #18
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,625

    Default Re: Complex conditional lookup

    Quote Originally Posted by Scott Axton View Post
    The other problem I'm having is how to put both 'parts' and 'services' on the same invoice. In other words how to choose where I'm looking for the item number to charge out.
    Maybe a set like this:
    Code:
    Invoice [1:1] Customer
            [1:M] Parts
            [1:M] Services  (or maybe this would be [1:1] ?)
    To get your proper service codes I would use a little xbasic - fetch thru the (or maybe a find the nearest) service area and compare against the customer area, and retrieve the price.

  19. #19
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,535

    Default Re: Complex conditional lookup

    To get to the Area calc, have a look at the Set, under Product_Id - in the Event tab (I think it's the event tab - not at my desk). There's Xbasic code in there that opens the ServiceLookup table and finds the correct Area - based on the Customer Area - and returns the correct price.

  20. #20
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,625

    Default Re: Complex conditional lookup

    Quote Originally Posted by Davidk View Post
    To get to the Area calc, have a look at the Set, under Product_Id - in the Event tab (I think it's the event tab - not at my desk). There's Xbasic code in there that opens the ServiceLookup table and finds the correct Area - based on the Customer Area - and returns the correct price.
    Ok, sorry David. Didn't look at your download. Sounds like you solved it. Very good then.

  21. #21
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    David -

    I still can't get it to work in your example. I see what and were you did this but it just isn't firing for me in the form.

    I think you're on the right track I'll just keep working it.

    The second example I uploaded (lookup2.zip) works great with parts from two different tables. I will try just a lookup to find just the service marry the two if I can get it working.

    Scott

  22. #22
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Peter -

    The structure is basically like you have it.


    Invoice [1:1] Customer
    [1:M] Parts OR Services



    I wish I could just use a formula like rate * sq ft = cost but it just isn't that simple.

    The client has a base rate they charge. As the area grows in size the cost per sq ft drops. Unfortunately not uniformly enough to put in to a mathematical formula. Thus the need for lookup.

    The way I am looking at it is in the servicelookup table the area is the 'key' to find the cost. In the invoice items table the quantity would always be 1 for services or one application - although I suppose theoretically you could have more that one application.

    If you have a chance look at the second upload I did (lookup2.zip) That works fine.

    Thanks,
    Scott

  23. #23
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: Complex conditional lookup

    Nothing complex about what you want to do, but if you were to add both products and services in the same invoice, in which field do you want service to go?
    The invoice item table does not have a field to accept that. Sure you could have one field for either a product or a service, but I am not sure which one you want to dedicate for that purpose.

    Incidentally, there is one mega major capital sin in your set structure. Will get to that later..

  24. #24
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    George -

    If I read this right - m thinking was that both would be added to the lineitems table.
    I can see what you're saying about having the same fields in both.

    OK I give - What major sin(s)?
    The examples I have posted don't necessarily reflect how I would end up in structure Just what I've done trying to get things to work.

    -Scott

  25. #25
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: Complex conditional lookup

    Scott:
    My understanding, you want to have one invoice that includes charges for both products used and services rendered. That's the way it should be. It would be rather ridiculous to send the customer 2 invoices, one for products and another for services not to mention double postage.

    To include both products and services in the same table, the one that has invoice items, I am not sure where (in which field) to add the service. The table has fields for ID's and some other numeric stuff, but there is no field to accept the type of service provided. Would be rather silly to put that under say produc_ID. What I am saying, perhaps you should add one more field, let's call it description, which will have a description of the product or the service. If that's OK, then we could get to how to get the values you the 2 different tables.
    Last edited by G Gabriel; 04-25-2009 at 07:27 PM.

  26. #26
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,625

    Default Re: Complex conditional lookup

    Quote Originally Posted by G Gabriel View Post
    To include both products and services in the same table, the one that has invoice items, I am not sure where (in which field) to add the service.
    Or, you could have the two child tables - products & services and use 2 subreports in the detail section of a report based upon the set.

  27. #27
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default Re: Complex conditional lookup

    Quote Originally Posted by Peter.Greulich View Post
    Or, you could have the two child tables - products & services and use 2 subreports in the detail section of a report based upon the set.
    Yes.. but I think the question is asked in the context of a form with an embedded browse. At least, that's what's in the zip file.

  28. #28
    Member
    Real Name
    Scott Axton
    Join Date
    Dec 2001
    Location
    Colorado Springs CO
    Posts
    94

    Default Re: Complex conditional lookup

    Quote Originally Posted by G Gabriel View Post
    Scott:
    My understanding, you want to have one invoice that includes charges for both products used and services rendered. That's the way it should be. It would be rather ridiculous to send the customer 2 invoices, one for products and another for services not to mention double postage.
    My thoughts exactly! I just want to list each out 1, 2, 3, 4
    Code:
    L1 - Service   Lawn Fertilization       $33.50          1           $33.50
    L2 - Product   Sprinkler Head           $4.95           2           $9.90
    L3 - Product   Widget                   $89.00          4         $356.00




    Quote Originally Posted by G Gabriel View Post
    To include both products and services in the same table, the one that has invoice items, I amnot sure where (in which field) to add the service. The table has fields for ID's and some other numeric stuff, but there is no field to accept the type of service provided. Would be rather silly to put tha under say produc_ID. What I am saying, perhaps you sould add one more field, let's call it description, which will have a description of the product or the service. If that's OK, then we could get to how to get the values you the 2 different tables.
    That is kind of where I was headed in the second version I posted above (lookup2.zip) I created a type in the line item - the choices were Product or Service. I don't have a customer table to lookup from in that example because I stripped out the items and lookup tables just trying to get that part to work. My intention is that cost is cost whether product or service. If a service qty = 1. If a product Qty = 1 to whatever.




  29. #29
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,625

    Default Re: Complex conditional lookup

    Quote Originally Posted by G Gabriel View Post
    Yes.. but I think the question is asked in the context of a form with an embedded browse. At least, that's what's in the zip file.
    I guess so. Except the 2nd zip file by Scott doesn't have any forms.

  30. #30
    Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,625

    Default Re: Complex conditional lookup

    Quote Originally Posted by Scott Axton View Post
    My thoughts exactly! I just want to list each out 1, 2, 3, 4
    Code:
    L1 - Service   Lawn Fertilization       $33.50          1           $33.50
    L2 - Product   Sprinkler Head           $4.95           2           $9.90
    L3 - Product   Widget                   $89.00          4         $356.00
    In that case, I would fill that table w. xbasic, using a button called "New Item" or whatever. The button could pop up a choice, "product" or "service" and an xdialog could pop up for either one. There's a million ways to do this, really.

Similar Threads

  1. Complex Conditional Statements
    By Ronald Dodge in forum Alpha Five Version 5
    Replies: 19
    Last Post: 05-23-2004, 09:09 AM
  2. Conditional Lookup
    By pinzgauer in forum Alpha Five Version 5
    Replies: 3
    Last Post: 12-21-2003, 02:56 PM
  3. complex lookup table
    By Pat in forum Alpha Five Version 5
    Replies: 4
    Last Post: 11-18-2003, 07:03 AM
  4. Need help creating complex lookup expression
    By joannristau in forum Alpha Five Version 5
    Replies: 12
    Last Post: 05-02-2003, 02:17 AM
  5. complex lookup
    By bob muzik in forum Alpha Five Version 4
    Replies: 14
    Last Post: 12-17-2000, 06:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •