Solved

Newsletter supplementary material

Posted on 2004-10-04
3
464 Views
Last Modified: 2011-09-20
-The Perl code explination
 -The code
0
Comment
Question by:turn123
  • 3
3 Comments
 
LVL 11

Author Comment

by:turn123
Comment Utility
Not much to explain this time.  Create a new text document in the same directory as the separate .pl file give in http://www.experts-exchange.com/Q_21188390.html#14117768 -> name it something.pl -> copy and paste the code into it.
0
 
LVL 11

Author Comment

by:turn123
Comment Utility
use strict;
use DBI;
use XML::Simple;

my $filename = "shipping_stuff.mdb";
my $dsn = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$filename";
my $dbh = DBI->connect("dbi:ODBC:$dsn", "", "")
     or die "Can't open source DB: $!\n";

my $data = XMLin("output.xml",KeyAttr => ["DataExtName"], ForceArray => [ "DataExtRet","InvoiceLineRet","InvoiceRet" ]);
my $control = 0;
while ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber} =~ /(.+)/) {
      my $sqlstatement = "INSERT into inv VALUES ('";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TimeCreated}','";
      if ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3}','";
      } elsif ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2}','";
      } else {
            $sqlstatement .= "','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr1}','";
      }
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr4}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{City}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{State}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{PostalCode}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Country}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{PONumber}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TermsRef}->{FullName}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipMethodRef}->{FullName}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{SalesRepRef}->{FullName}','";
      if ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr3} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr2}','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr3}','";
      } elsif ($data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{BillAddress}->{Addr2} =~ /.+/) {
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr2}','";
      } else {
            $sqlstatement .= "','";
            $sqlstatement .= "','";
            $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr1}','";
      }
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Addr4}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{City}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{State}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{PostalCode}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{ShipAddress}->{Country}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{EditSequence}','";
      $sqlstatement .= "$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{TxnID}')";
      open SQL, ">> sql.txt";
      print SQL $sqlstatement . "\n";
      close SQL;
      my $statementhandle = $dbh->prepare("DELETE from inv where ID = '$data->{QBXMLMsgsRs}->{InvoiceQueryRs}->{InvoiceRet}->[$control]->{RefNumber}'");
      $statementhandle->execute();
      my $statementhandle = $dbh->prepare($sqlstatement) || die "Cannot prepare statement";
      $statementhandle->execute() || die "Could not execute SQL statement, maybe invalid?";
      ++$control;
}
0
 
LVL 11

Accepted Solution

by:
turn123 earned 0 total points
Comment Utility
Question moved to Productivity Applications and closed.

turn123,
Page Editor -- Productivity Applications
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
Messaging apps are amazing tools with the power to do a lot of good, but the truth is the process of collaborating with coworkers requires relationships established through meaningful communication - the kind of communication that only happens face-…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now