Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Copy Last Years Sales

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #46
    Re: Function - How many reasons....

    Originally posted by aal_fareed View Post
    please try this i am sure it will work for you
    just make sure that estabdate contains date value

    dim curYr as C
    curYr = year(convert_type(estabdate,"D"))
    Hi Ahmed,

    This does not work. It throws the error message that the variable, "estabdate" is not found.

    Thanks,
    TYVM :) kenn

    Knowing what you can achieve will not become reality until you imagine and explore.

    Comment


      #47
      Re: Function - How many reasons....

      Hi Robin,

      I copied the script in it's entirety. First time through, it said there was a missing End While command. I added it. 2nd time through, it didn't like the line: on error goto ERRTRAP. I commented it out. The 3rd time through, The system cannot find the file specified: TLC_3copy.DBF. (I left off the full path) Grrrrrrr.
      TYVM :) kenn

      Knowing what you can achieve will not become reality until you imagine and explore.

      Comment


        #48
        Re: Function - How many reasons....

        Code:
        'Date Created: 16-Mar-2015 02:20:06 PM
        'Last Updated: 21-Mar-2015 06:16:20 PM
        'Created By  : kenn
        'Updated By  : Govindan
        
        debug(1)
        
        
        dim tbl_a as p
        dim tbl_b as p
        
        tbl_a = table.open("tlc_3apps")
        tbl_b = table.open("tlc_3apps")
        dim curYr as n
        curYr = year(date())
        tbl_a.fetch_first()
        
        while .not. tbl_a.fetch_eof()
        	if year(tbl_a.estabdate) = curYr-1
        		tbl_b.enter_begin(.t.)
        		tbl_b.Customerid = tbl_a.Customerid
        		tbl_b.Svcsiteid  = tbl_a.Svcsiteid
        		tbl_b.Service  = tbl_a.Service
        		tbl_b.Svc_Descrip = tbl_a.Svc_Descrip
        		tbl_b.Svc_Zip  = tbl_a.Svc_Zip
        		tbl_b.Sale  = tbl_a.Sale
        		tbl_b.Exempt = tbl_a.Exempt
        		tbl_b.Comborate  = tbl_a.Comborate
        		tbl_b.Discount  = tbl_a.Discount
        		tbl_b.Disc_Note = tbl_a.Disc_Note
        		tbl_b.enter_end(.t.)
        	end if
        		tbl_a.fetch_next()
        	
        end while
        
        tbl_b.close()
        tbl_a.close()
        here is the updated code for you using your tables and it works here.
        see if it does for you.
        you had many mistakes. code was running around everywhere but not doing anything.

        edit: see this screencast.
        http://screencast.com/t/lqS9DKuWi9K
        Last edited by GGandhi; 03-21-2015, 06:34 PM.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #49
          Re: Function - How many reasons....

          Ken,
          Did you duplicate the table as I did? The script as I posted would not have worked otherwise. Which is no doubt what the errors were about. I don't see the point in copying the records to the same table - is there one?
          Robin

          Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

          Comment


            #50
            Re: Function - How many reasons....

            Hi Ken,

            I won't try to guess what you're doing, but the problem here is really just a matter of timing.
            You are trying to use the value for tbl_a.estabdate before you open the table.
            If you move the curYr = year(tbl_a.estabdate) statement to a position after you open the table, you will find that error is no longer a problem.

            I see other issues like GGhandi did, but I believe you will pose those questions later.
            I have attached a couple images to help illustrate.

            tbl_a_isnotopenyet.PNG
            tbl_a_isnowopen.PNG
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #51
              Re: Function - How many reasons....

              Hi Robin,

              The customer purchases from year to year are, with few exceptions, the same. Thus, copying certain data from the previous year to the current year, saves a huge amount of data entry.
              TYVM :) kenn

              Knowing what you can achieve will not become reality until you imagine and explore.

              Comment


                #52
                Re: Copy Last Years Sales

                Hi Ken,

                I cheat a lot. It looks like you want an operation to Copy last years sales into a 2nd table.
                The code shown below can be pasted into a script, that can be attached to button on a DT form.

                Not sure if I'm late to the party, but I think this answers the initial question.


                Code:
                'In case the destination table name is stored as a relative file name, or uses an alias
                'in the drive/path specification, use the filename_decode() function to convert the
                'filename to an absolute filename.
                copy_db_name = filename_decode("\users\ken\desktop\tlc 3-19-15\last_year_sales.dbf")
                
                a_tbl = table.open("tlc_3apps")
                ON ERROR GOTO ERROR21032015224246376
                
                
                DIM a5_operation_order as C
                a5_operation_order = "recno()"
                query.order = a5_operation_order
                DIM a5_operation_filter as C
                a5_operation_filter = "year(Estabdate)=year(date())-1"
                query.filter = a5_operation_filter
                query.options = "I"
                query.description = "Temporary Query"
                i_indx = a_tbl.query_create()
                
                copy.set = ""
                copy.db = copy_db_name
                copy.dd = .F.
                copy.delete_o_dd = .F.
                copy.records = .T.
                copy.fields = 10
                copy.field1 = "Customerid"
                copy.field2 = "Svcsiteid"
                copy.field3 = "Service"
                copy.field4 = "Svc_Descrip"
                copy.field5 = "Svc_Zip"
                copy.field6 = "Sale"
                copy.field7 = "Exempt"
                copy.field8 = "Comborate"
                copy.field9 = "Discount"
                copy.field10 = "Disc_Note"
                
                a_tbl.copy()
                
                
                GOTO CONTINUE21032015224246376
                ERROR21032015224246376:
                ON ERROR GOTO 0
                ui_msg_box("Error","Error running Copy Operation"+crlf()+error_text_get())
                END
                CONTINUE21032015224246376:
                a_tbl.close()
                'Add the table just created by the Copy operation to the Database..
                file_add_to_db(copy_db_name)
                Gregg
                https://paiza.io is a great site to test and share sql code

                Comment


                  #53
                  Re: Function - How many reasons....

                  did the code in post #16 work for you at all?
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                    #54
                    Re: Function - How many reasons....

                    Originally posted by GGandhi View Post
                    did the code in post #16 work for you at all?
                    Yes, it works with just the table that I sent to you. However, it doesn't work with the app. I'm trying to isolate the problem but as you know, that can be a tedious task. I will you you informed.
                    TYVM :) kenn

                    Knowing what you can achieve will not become reality until you imagine and explore.

                    Comment


                      #55
                      Re: Copy Last Years Sales

                      Hi Greg,

                      I need to copy last years sales to the same table. My customer's customers are repeat customers which order the same services every year. the ability to batch copy all services/sales from the last year to the current year saves a huge amount of data entry time. That said, your code will have it's place because we will only want to keep only so many years in the current table with the other years to be archived. Just how may years to keep current hasn't been determined. So no, you're not late to the party. Thanks for your input.
                      TYVM :) kenn

                      Knowing what you can achieve will not become reality until you imagine and explore.

                      Comment


                        #56
                        Re: Copy Last Years Sales

                        Ken,

                        It's easy enough to import last year's sales back into the primary table.

                        The code below does it, although I don't have it checking for duplicate records.


                        Gregg
                        Code:
                        'In case the destination table name is stored as a relative file name, or uses an alias
                        'in the drive/path specification, use the filename_decode() function to convert the
                        'filename to an absolute filename.
                        copy_db_name = filename_decode("\users\ken\desktop\tlc 3-19-15\last_year_sales.dbf")
                        
                        a_tbl = table.open("tlc_3apps")
                        ON ERROR GOTO ERROR21032015224246376
                        
                        
                        DIM a5_operation_order as C
                        a5_operation_order = "recno()"
                        query.order = a5_operation_order
                        DIM a5_operation_filter as C
                        a5_operation_filter = "year(Estabdate)=year(date())-1"
                        query.filter = a5_operation_filter
                        query.options = "I"
                        query.description = "Temporary Query"
                        i_indx = a_tbl.query_create()
                        
                        copy.set = ""
                        copy.db = copy_db_name
                        copy.dd = .F.
                        copy.delete_o_dd = .F.
                        copy.records = .T.
                        copy.fields = 10
                        copy.field1 = "Customerid"
                        copy.field2 = "Svcsiteid"
                        copy.field3 = "Service"
                        copy.field4 = "Svc_Descrip"
                        copy.field5 = "Svc_Zip"
                        copy.field6 = "Sale"
                        copy.field7 = "Exempt"
                        copy.field8 = "Comborate"
                        copy.field9 = "Discount"
                        copy.field10 = "Disc_Note"
                        
                        a_tbl.copy()
                        
                        
                        GOTO CONTINUE21032015224246376
                        ERROR21032015224246376:
                        ON ERROR GOTO 0
                        ui_msg_box("Error","Error running Copy Operation"+crlf()+error_text_get())
                        END
                        CONTINUE21032015224246376:
                        a_tbl.close()
                        'Add the table just created by the Copy operation to the Database..
                        file_add_to_db(copy_db_name)
                        
                        
                        ' Now import least year's sales back into the main table
                        
                        DIM Append as P
                        
                        a_tbl = table.open("tlc_3apps")
                        append.t_db = "last_year_sales"
                        ON ERROR GOTO ERROR2203201511448739
                        
                        
                        append.m_key = ""
                        append.t_key = ""
                        append.m_filter = ""
                        append.t_filter = ""
                        append.type = "All"
                        append.m_count = 10
                        append.m_field1 = "CUSTOMERID"
                        append.m_exp1 = "@LAST_YEAR_SALES->CUSTOMERID"
                        append.m_field2 = "SVCSITEID"
                        append.m_exp2 = "@LAST_YEAR_SALES->SVCSITEID"
                        append.m_field3 = "SERVICE"
                        append.m_exp3 = "@LAST_YEAR_SALES->SERVICE"
                        append.m_field4 = "SVC_DESCRIP"
                        append.m_exp4 = "@LAST_YEAR_SALES->SVC_DESCRIP"
                        append.m_field5 = "SVC_ZIP"
                        append.m_exp5 = "@LAST_YEAR_SALES->SVC_ZIP"
                        append.m_field6 = "SALE"
                        append.m_exp6 = "@LAST_YEAR_SALES->SALE"
                        append.m_field7 = "EXEMPT"
                        append.m_exp7 = "@LAST_YEAR_SALES->EXEMPT"
                        append.m_field8 = "COMBORATE"
                        append.m_exp8 = "@LAST_YEAR_SALES->COMBORATE"
                        append.m_field9 = "DISCOUNT"
                        append.m_exp9 = "@LAST_YEAR_SALES->DISCOUNT"
                        append.m_field10 = "DISC_NOTE"
                        append.m_exp10 = "@LAST_YEAR_SALES->DISC_NOTE"
                        append.t_count = 0
                        
                        a_tbl.append()
                        
                        
                        GOTO CONTINUE2203201511448739
                        ERROR2203201511448739:
                        ON ERROR GOTO 0
                        ui_msg_box("Error","Error running Append Operation"+crlf()+error_text_get())
                        END
                        CONTINUE2203201511448739:
                        a_tbl.close()
                        'If the Operation is run from within a Form or Browse, then refresh the window
                        if is_object(topparent.this) then
                        	if topparent.Class() = "form" .or. topparent.class() = "browse" then
                        		topparent.Refresh_layout()
                        	end if
                        end if
                        Gregg
                        https://paiza.io is a great site to test and share sql code

                        Comment


                          #57
                          Re: Copy Last Years Sales

                          Kenn

                          Looks like 2 threads on the same subject.

                          http://www.alphasoftware.com/alphafo...w-many-reasons

                          Yes No Maybe?

                          If Yes, I'll merge them. It's getting confusing to follow..
                          Al Buchholz
                          Bookwood Systems, LTD
                          Weekly QReportBuilder Webinars Thursday 1 pm CST

                          Occam's Razor - KISS
                          Normalize till it hurts - De-normalize till it works.
                          Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                          When we triage a problem it is much easier to read sample systems than to read a mind.
                          "Make it as simple as possible, but not simpler."
                          Albert Einstein

                          http://www.iadn.com/images/media/iadn_member.png

                          Comment


                            #58
                            Re: Copy Last Years Sales

                            Hello Al,

                            I started this one for the copy. As I went along, I started the other one to try to resolve the error message. You may merge them, That's OK with me.
                            TYVM :) kenn

                            Knowing what you can achieve will not become reality until you imagine and explore.

                            Comment


                              #59
                              Re: Function - How many reasons....

                              N/t
                              Last edited by MoGrace; 03-22-2015, 01:48 PM.
                              Robin

                              Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                              Comment


                                #60
                                Re: Function - How many reasons....

                                A huge thank you to all who made suggestions and provided guidance for accomplishing this task. I am very, very much appreciative of each person's contribution. This is a recap of the task at hand and the conclusion of the effort.

                                My need: My customer has 5,000 customers. Their customers remain pretty steady year after year and order the same service/s year after year, anywhere from 1 to as many as 10 services.Thus, entering all the sales data for several thousand records consumes a lot of time, a lot of time!! This code looks at a date field which is displayed as the year only, subtracts 1 year and then copies all the sales for that year to the same table so the customer. Not every field in the record is copied but only the fields where the data remains the same. So, with a 1 button push, all of the pertinent data for each sale of for each customer are copied, thereby avoiding several hundred hours of repetitive data entry each year. In reality, it saves the expense of an additional staff person.

                                This is the code. You will need to use your table names and field names. You can use as many fields as you want/need. Hopefull, this may be of held to others.

                                'debug(1)


                                dim tbl_a as p
                                dim tbl_b as p

                                tbl_a = table.open("yourtablename")
                                tbl_b = table.open("yourtablename")

                                dim curYr as n
                                curYr = year(date())

                                tbl_a.fetch_first()

                                while .not. tbl_a.fetch_eof()

                                if year(tbl_a.yourdatefield) = curYr-1
                                tbl_b.enter_begin(.t.)
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.Yourfieldname = tbl_a.Yourfieldname
                                tbl_b.enter_end(.t.)
                                end if
                                tbl_a.fetch_next()

                                end while

                                tbl_b.close()
                                tbl_a.close()

                                msgbox("Result", "All the relevant data of last years sales was copied as new record.")
                                Last edited by forskare; 03-23-2015, 04:34 PM.
                                TYVM :) kenn

                                Knowing what you can achieve will not become reality until you imagine and explore.

                                Comment

                                Working...
                                X