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

    Copy Last Years Sales

    Here's one for the thinking caps. My customer wants to copy certain fields of all of last years sales records for each customer. Currently, I have it set up so the user can click an icon to create a new record and then copy certain fields. The works great but with 5,400 records it's still much to time consuming doing them one at a time. I would be helpful to have a batch operation to accomplish the task. Simply duplicating the table will not work because several fields in each record would have to be cleared of data.

    What is needed:

    1. Enter a new record for each record of the previous year.
    2. Copy 6 fields of that record to the new record.
    3. Submit the record.

    All records from all years are kept in the same table. the Service Year field contains the year for the record. At some point, some of the records will be archived, keeping the last 2 or 3 years records in the active database. Thus for 2015, the operation needs to search for the previous year, 2014. The do steps 1-3. This needs to be done for each record where the year field = 2014. However, there must be a dialog which asks for the previous year so the operation knows to search for 2104. I have the Service Year field set up to enter the current date but show only the year.

    How might this be created so all the user has to do is to click the Copy Last Years Sales button, enter the last year (year only) and the click a button to begin the operation. Since the Service Year field is a date field, it might not be able to search for only the year.

    Thanks for your ideas.
    TYVM :) kenn

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

    #2
    Re: Copy Last Years Sales

    Sounds straightforward enough, but that's the kind of thing you have to code in xbasic. I don't know how else you would do that. Take a look at operations. There might be a way there.
    Peter
    AlphaBase Solutions, LLC

    [email protected]
    https://www.alphabasesolutions.com


    Comment


      #3
      Re: Copy Last Years Sales

      You are correct. I looked at the operations and it maybe can be done one operation at a time and then combine them, However, I suspect the better way is to code it. At least if something goes amiss, I think it would be easier to trouble shoot.
      TYVM :) kenn

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

      Comment


        #4
        Re: Copy Last Years Sales

        Code:
        'debug(1)
        dim tbl_a as p
        dim tbl_b as p
        tbl_a = table.open("your_table_name")
        tbl_b = table.open("your_table_name")
        tbl_a.fetch_first()
        
        while .not. tbl_a.fetch_eof()
        	if year(tbl_a.startdate) = 2014
        		tbl_b.enter_begin(.t.)
        		tbl_b.field_name = tbl_a.field_name
        		tbl_b.field_name  = tbl_a.field_name 
        		tbl_b.field_name  = tbl_a.field_name 
        		tbl_b.enter_end(.t.)
        	end if
        		tbl_a.fetch_next()
        	
        end while
        
        tbl_b.close()
        tbl_a.close()
        so here is my sample code
        substitute your file name and field names,
        file name will be the same for both tbl_a and tbl_b, field name will be same in both tabl_a and tabl_b obviously.
        I am using startdate as my date field you will need to substitute to yours,
        and see if this works.
        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


          #5
          Re: Copy Last Years Sales

          Slight correction:

          Code:
          tbl_a = table.open("[COLOR="#FF0000"][pathalias.adb_path]\[/COLOR]your_table_name")
          tbl_b = table.open("[COLOR="#FF0000"][pathalias.adb_path]\[/COLOR]your_table_name")
          Peter
          AlphaBase Solutions, LLC

          [email protected]
          https://www.alphabasesolutions.com


          Comment


            #6
            Re: Copy Last Years Sales

            this is for wcd, as far as I know ken uses wcd. one day he will migrate to web side totally.
            Last edited by GGandhi; 03-16-2015, 09:46 AM.
            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


              #7
              Re: Copy Last Years Sales

              Didn't realize it was WCD.
              Peter
              AlphaBase Solutions, LLC

              [email protected]
              https://www.alphabasesolutions.com


              Comment


                #8
                Re: Copy Last Years Sales

                Here's an interesting quirk. I have a client who uses (v12 in this case) in a dbf web-browser app in an internal network situation with about a dozen or better users. They run the web app server. The client has numerous calculated field rules in several tables using dbsum(), lookupc(), etc. These functions all address tables directly. In theory you are supposed to use [pathalias.adb_path]\ to prefix the table. As a matter of fact, according to one of the Alpha programmers I spoke to about this, said it MUST be included. That's always been my experience as well. But my client never knew he was "supposed" to prefix the path alias and it works nonetheless. When it doesn't work is when I applied xbasic to change a record. Then all the calc field rule expressions using those functions fail - and we had to tag on the alias to those expression in that particular table to make it work. In the mean time, the other tables using similar expressions w/o the alias continue to work just fine. So it seems that something has changes somewhere along the line and even some of the Alpha programmers are not aware of that change.
                Peter
                AlphaBase Solutions, LLC

                [email protected]
                https://www.alphabasesolutions.com


                Comment


                  #9
                  Re: Copy Last Years Sales

                  Hello Gandhi and Peter, (Hi, Tom)

                  It's sorta WCD and sorta web. Not total either one. How can that be? I use a DT form to launch the app. The onInit event of the form calls the Main TUI where the menu is to go to the grids. Of course, the reports must be DT because the web reports only work with SQL and my tables are dbf. Thus, the app is 99% web. The user never sees the DT form.

                  Question: The code is for 2 tables which means either the same table name for both or 2 separate tables. If the latter, then I will need to post the data back to the initial table. Whih way is this?

                  Thanks,
                  TYVM :) kenn

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

                  Comment


                    #10
                    Re: Copy Last Years Sales

                    Ken,

                    You can use dbf reports on the web. And they can even be based upon sets.

                    In Gandhi's code, you are updating tbl_b from tbl_a.
                    Peter
                    AlphaBase Solutions, LLC

                    [email protected]
                    https://www.alphabasesolutions.com


                    Comment


                      #11
                      Re: Copy Last Years Sales

                      both tables are the same tbl_a and tbl_b are the same
                      so are the fields.
                      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


                        #12
                        Re: Copy Last Years Sales

                        Gandhi,

                        OK, I'll try it that way. I duplicated table a and removed the data and not needed fields from table b. The ran the code and it worked great.

                        Peter,

                        Yes, DT, dbf reports can be used on the web. Reports based on dbf tables cannot be created with the web tools. One must use the DT for that. Maybe I missed something but the few times I'v tried, it only allows me to choose sql tables.
                        TYVM :) kenn

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

                        Comment


                          #13
                          Re: Copy Last Years Sales

                          Yes, that's what I use too. Just the regular controlpanel report writer. Only very recently have I moved my sql reports to the web controlpanel and use the report writer there. But by the same token your dbf tables are still there in the desktop CP. To me, that doesn't make much difference. Writing reports from the web CP is identical to using the regular CP. But I get it that the web CP doesn't allow you to create dbf reports there. I think Alpha is just consolidating web tools all in one place.
                          Peter
                          AlphaBase Solutions, LLC

                          [email protected]
                          https://www.alphabasesolutions.com


                          Comment


                            #14
                            Re: Copy Last Years Sales

                            Agreed. I switched the table name so both are the same. It took about 3.5 minutes to run the code and it worked perfectly. Now I need to add an askvar to prompt for the year. I should be able to copy that code from another part. I did not add your code nut will if you think it will prevent possible problems later on.
                            TYVM :) kenn

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

                            Comment


                              #15
                              Re: Copy Last Years Sales

                              according to the first post you are checking the table and select the previous year and create new records in the same table, if that is so then in the code you are creating two instances of the table checking one and inserting in another.
                              here is a function that will do the same for every last year by a click of a button to call this function.

                              FUNCTION copyLastYearData AS V ( )

                              dim curYr as n
                              curYr = year(date())
                              dim tbl_a as p
                              dim tbl_b as p
                              tbl_a = table.open("ken")
                              tbl_b = table.open("ken")
                              tbl_a.fetch_first()

                              while .not. tbl_a.fetch_eof()
                              if year(tbl_a.startdate) = curYr-1
                              tbl_b.enter_begin(.t.)
                              tbl_b.name = tbl_a.name
                              tbl_b.schedule = tbl_a.schedule
                              tbl_b.type = tbl_a.type
                              tbl_b.enter_end(.t.)
                              end if
                              tbl_a.fetch_next()

                              end while
                              tbl_b.close()
                              tbl_a.close()
                              msgbox("Result", "all the relevant last year data copied to new records")
                              END FUNCTION
                              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

                              Working...
                              X