NetTalk Central

Author Topic: How should I import sales history into database?  (Read 5270 times)

Alan Telford

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
How should I import sales history into database?
« on: July 08, 2007, 08:05:23 PM »
I have a nettalk website.
I want the users to be able to import sales history from a CSV file.
The user will want to import 1 or more months at a time for their allowed branches.
Each user can view many different branches/sites

I'm thinking of using the following approach:
  • generate a sample CSV file; "Branch","Date","Sales" with one row per date per branch.
  • this ensures the "Branch" name is accurate and the "Date" is in the right format.
  • allow the user to download this to their local machine, edit, and fill in the "Sales" column.
  • allow user to select the CSV file and upload to the web site.
  • process the CSV file and import into the database.

In NetTalk:
- Create a NetWebForm with wizard style;
- Tab1 = instructions for what's going to happen
- Tab2 = allow user to enter startdate and finishdate, then push a "Generate" button to create the sample CSV file and send to the user
- Tab3 = a "File Upload" button to select the CSV file, and an "Import" button. When the "Import" button is pushed this uploads the file, reads the file and checks it for validity, and goes to tab 4.
- Tab4 = gives summary information about CSV file (eg date range) and button to "Update Database" which asks user to confirm the import into the live database

Does this sound like a suitable approach?
Should I use a NetWebForm for this?

Any suggestions welcome!!!
Regards,
Alan Telford

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: How should I import sales history into database?
« Reply #1 on: July 08, 2007, 10:55:19 PM »
Hi Alan,

The idea is spot on, but unfortunately there are one or two minor complications.

The most glaring complication is that the file will only "upload" on a "submit". I'm keen to make an asynchronous upload, (ie click a button, file uploads, but form remains) but I haven't done that yet.

So the "upload" button has to be a "submit" button, which kinda makes the code on your side a bit more icky. You could (in theory) come back to the same form, but the form knows where it is, so jumps ahead to tab 4, or you could build it as 2 separate forms (which might be easier to code).

Cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: How should I import sales history into database?
« Reply #2 on: August 27, 2007, 07:37:34 AM »
Alan,

This is very much what I'd to be able to , too.
I have it down to get the file, run some validation on the data, and then let the user know of any errors.
My problem so far has been how to manage the file location. I'd like to get it into a subdirectory of uploads. Got some help from Bruce in the Clarion Forums. He suggested I look here.

Have you come up with a solution? What other problems did you come up against?

Thanks,
chris
Real programmers use copy con newapp.exe

Alan Telford

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Re: How should I import sales history into database?
« Reply #3 on: August 27, 2007, 01:38:38 PM »
Chris,

In the end I have a netwebform with a "File Upload" string and an "Import Now" button of type submit.
The "File Upload" allows them to pick a file off their local pc.
When they press the "Import Now" button it does a submit on the form, which actually does the upload (in the nettalk classes) and then redirects me to the URL I specified on the ImportNow button

I have implemented this new URL as another netwebform.
At the start I check p_web.getvalue('import_filename').
If this is non-blank, then the user entered a filename before pressing the import now button.
I don't have any choice of the filename or where it gets put. But what I do is immediately open the file, import into a memory table, delete the original file, and continue.

i.e. rather than trying to control where it gets uploaded, I instead take immediate action and convert the file into a format I want to use (which in this case was a memory table).
I then have a browse on the memory table so they can check their results, before pushing another button to actually SAVE it to the database.

Hope this helps,
Alan