Adding stuff to invoice based on alphabet letter of Sell-to

yuppicideyuppicide Member Posts: 410
edited 2011-08-23 in Navision Attain
Navision 3.10.

Awhile ago you guys helped me add special text to print on an invoice based on what the payment terms are.

Example:
IF "Payment Terms Code" = 'CC' THEN BEGIN
  RemitText1 := 'YOUR ORDER HAS ALREADY BEEN PAID FOR.';
  RemitText3 := '';
  RemitText4 := '';
  RemitText5 := '';
  RemitText6 := '';
  RemitText7 := '';
  RemitText8 := '';
  RemitText9 := '';
 END;

Etc.. the above dictates that the customer has already paid by CC. There's a bunch of them for all our different Payment Terms. Those RemitText get filled in with more information for other Payment Terms.. for example if there was an address a payment should be mailed to, it will show that on the invoice.

Now I'm wondering if there's a way to further add something to this.

We have problems where some customers are factored (meaning an outside company gives them credit and handles payments for us). In my instructions that print on the invoice it only has information on who to make checks to and where to mail. If the customer has a payment problem (such as they're going to be late, or want to see if they accept credit card, etc), they should be calling them and not us.

I want to add RemitText10 and how can I get Navision to do this:

If Sell-to Customer name starts with the letters A through C then RemitText10 will print one phone number.

If Sell-to Customer name starts with the letters D through H then RemitText10 will print one phone number.

etc.

There's different reps at the company they should contact.

Comments

  • SavatageSavatage Member Posts: 7,142
    Variable Repmarker Type Text

    RepMarker := COPYSTR("Sell-to Customer name",1,1);//Gets the first character
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7890';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7891';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7892';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7893';

    Does anyone start with a number? you'll have to handle that too.
  • yuppicideyuppicide Member Posts: 410
    Thanks! I think I notice a potential problem

    It's

    A - C
    D - H
    I - M
    N - SK
    SL - Z

    .. your code only checks the first character.
  • SavatageSavatage Member Posts: 7,142
    If Sell-to Customer name starts with the letters A through C then RemitText10 will print one phone number.

    If Sell-to Customer name starts with the letters D through H then RemitText10 will print one phone number.
    oh i based on your first post . only showed 1 character

    is there another field on the customer card that distinguishes the rep differences instead of the characters in the name? perhaps salesperson code? or a custom field? location code?
  • geronimogeronimo Member Posts: 90
    Savatage wrote:
    Variable Repmarker Type Text

    RepMarker := COPYSTR("Sell-to Customer name",1,1);//Gets the first character
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7890';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7891';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7892';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7893';

    Does anyone start with a number? you'll have to handle that too.

    You could check for the second char in the same way (its not really performant but as it is one record each time it shouldnt be that much of a problem)

    RepMarker := COPYSTR("Sell-to Customer name",1,1);//Gets the first character
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7890';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7891';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7892';
    IF RepMarker IN THEN REMITTEXT10 := '123-456-7893';
    if RepMarker = 'S' then begin
    Repmarker := COPYSTR("Sell-to Customer name",2,1); //gets second char
    if repmarker in then REMITTEXT10 := '123-456-7890';
    if repmarker in then remittext10 := '213-456-7890';
    end;
  • yuppicideyuppicide Member Posts: 410
    I haven't tried this yet, but I want to do it soon. I'm looking at your code and had a question:
    if repmarker in ['L',....'Z'] then remittext10 := '212-575-5794';
    

    In that code above, I'm assuming it means any letter L through Z. In the line of code above it, why is B there? Shouldn't:
    if repmarker in ['A','B',...,'K'] then REMITTEXT10 := '212-575-8023';
    

    Shouldn't that not need the B? Any letter A through K.
  • geronimogeronimo Member Posts: 90
    its indeed any letter, i typed 'A','B' and then got bored so just added the K at the end.

    Oh and you could leave the 'S' out of the line above. (IKF RepMarker IN THEN REMITTEXT10 := '123-456-7893';)

    It doesnt really do any harm as it gets filled in later on but just in case there is a combination with S that isn't expected in the code.
  • yuppicideyuppicide Member Posts: 410
    Understood.. I was actually going to attempt what you did exactly.. figuring it was a shortcut.. so I see I need to actually add every letter.
  • SavatageSavatage Member Posts: 7,142
    Savatage wrote:
    is there another field on the customer card that distinguishes the rep differences instead of the characters in the name? perhaps salesperson code? or a custom field? location code?
  • Torben_R.Torben_R. Member Posts: 99
    geronimo wrote:
    its indeed any letter, i typed 'A','B' and then got bored so just added the K at the end.

    Oh and you could leave the 'S' out of the line above. (IKF RepMarker IN THEN REMITTEXT10 := '123-456-7893';)

    It doesnt really do any harm as it gets filled in later on but just in case there is a combination with S that isn't expected in the code.

    Just a small trick
    IF RepMarker IN ['R'..'Z']
    

    Normal filters does work as long as you remember the '' to indicate that it's a text.
  • yuppicideyuppicide Member Posts: 410
    I can't go by Salesperson Code.. Reason being is because salespersons handle territory, such as Southeast, Midwest, etc. The people who handle the credit go by company name alphabet letter.

    I could create a custom field maybe if you think that's a better way of going about things, but that will add one more step to whoever enters the customer card and if they do that step wrong then it'll print wrong.
    Savatage wrote:
    Savatage wrote:
    is there another field on the customer card that distinguishes the rep differences instead of the characters in the name? perhaps salesperson code? or a custom field? location code?
  • yuppicideyuppicide Member Posts: 410
    Wondering where I shall add this new code and thought of two more questions.

    1 -

    I am in the C/AL CODE. In there I can see code I previously entered. There is RemitText1 through RemitText9 that can print currently. For some of the Payment Terms Code I do not use 7-9.. do I need to specify them?

    Here's an example of one I've entered:
    IF "Payment Terms Code" = 'N30' THEN BEGIN
      RemitText1 := 'PLEASE REMIT PAYMENT TO:';
      RemitText3 := 'OUR COMPANY';
      RemitText4 := '## XXXX DRIVE';
      RemitText5 := 'SUITE XXX';
      RemitText6 := 'CITY, NJ #####';
      RemitText7 := '';
      RemitText8 := '';
      RemitText9 := '';
     END;
    

    As you can see 7-9 are blank. Do I even need those three lines? Other times it's used, not in this case.

    2 -

    Where am I to enter this new code? For example I have the following code:
    IF "Payment Terms Code" = 'NET+30F' THEN BEGIN
      RemitText1 := 'MAKE AND MAIL CHECKS PAYABLE TO:';
      RemitText3 := 'SOME CORPORATION';
      RemitText4 := 'P.O. BOX ####';
      RemitText5 := 'MIDTOWN STATION';
      RemitText6 := 'NEW YORK, NY 10018';
      RemitText7 := 'THIS ACCOUNT AND ALL THE MERCHANDISE CONSTITUTING THE SAME HAVE BEEN ASSIGNED AND ARE';
      RemitText8 := 'OWNED BY, AND PAYABLE EXCLUSIVELY TO SOME CORPORATION. IF INCORRECT, IN';
      RemitText9 := 'ANY PARTICULAR, COMMUNICATE DIRECTLY TO SOME CORPORATION.';
     END;
    IF "Payment Terms Code" = 'NET10EOMF' THEN BEGIN
      RemitText1 := 'MAKE AND MAIL CHECKS PAYABLE TO:';
      RemitText3 := 'SOME CORPORATION';
      RemitText4 := 'P.O. BOX ####';
      RemitText5 := 'MIDTOWN STATION';
      RemitText6 := 'NEW YORK, NY 10018';
      RemitText7 := 'THIS ACCOUNT AND ALL THE MERCHANDISE CONSTITUTING THE SAME HAVE BEEN ASSIGNED AND ARE';
      RemitText8 := 'OWNED BY, AND PAYABLE EXCLUSIVELY TO SOME CORPORATION. IF INCORRECT, IN';
      RemitText9 := 'ANY PARTICULAR, COMMUNICATE DIRECTLY TO SOME CORPORATION.';
     END;
    

    .. there's more of them following that one for other Payment Terms Code. We're going to add RemitText10 to say 'For assistance call ###-###-####'.

    The other two questions - there's 12 of those.. is there a way to add all of them into one? like
    IF "Payment Terms Code" = 'NET+30F' OR 'NET10EOMF' THEN BEGIN
    

    I know you probably cannot have more than one OR, but maybe there's another way to do it. Then I can at least shorten my C/AL CODE.

    Also, where I am going to add in the code for RemitText10.. will I need to add that every time after RemitText9?
  • DenSterDenSter Member Posts: 8,307
    Yes you should definitely always set all of those variables.

    Instead of using multiple IF statements, you should be using a CASE statement.
    CASE "Payment Terms Code" OF
      'N30':
        BEGIN
          RemitText1 := 'PLEASE REMIT PAYMENT TO:';
          RemitText3 := 'OUR COMPANY';
          RemitText4 := '## XXXX DRIVE';
          RemitText5 := 'SUITE XXX';
          RemitText6 := 'CITY, NJ #####';
          RemitText7 := '';
          RemitText8 := '';
          RemitText9 := '';
        END;
      'NET+30F','NET10EOMF':
        BEGIN
          // insert code for those two in here
        END;
    END;
    
    The difference is that with IF statements, it has to evaluate the same value in every IF statement. With a CASE statement it only needs to evaluate the value once, so it is more efficient.

    If you're dead set on using multiple IF statements, go like this:
    IF ("Payment Terms Code" = 'NET+30F') OR ("Payment Terms Code" = 'NET10EOMF') THEN BEGIN
    

    You can have as many OR statements as you want.

    Yes you will have to add the Remit10 value to all of them, unless the value is the same for all of them.
  • Torben_R.Torben_R. Member Posts: 99
    DenSter wrote:
    IF ("Payment Terms Code" = 'NET+30F') OR ("Payment Terms Code" = 'NET10EOMF') THEN BEGIN

    or use
    IF "Payment Terms Code" IN ['NET+30F','NET10EOMF','third code','forth code','etc.'] THEN
    

    sometimes it's easier to do it the other way around
    IF NOT ("Payment Terms Code" IN ['NET+30F','NET10EOMF']) THEN
    
  • yuppicideyuppicide Member Posts: 410
    Just wanted to say it worked perfectly.
  • yuppicideyuppicide Member Posts: 410
    edited 2011-08-23
    EDIT: Wrong post.
  • yuppicideyuppicide Member Posts: 410
    EDIT: Wrong post.
Sign In or Register to comment.