[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] database -> XML



Wow. It's amazing to me how tight this code is. I'm getting the job done
with almost zero overhead!

Thanks Perl and CPAN!!  (and especially XML::Twig and Class::Date in
this snippet)

j


(Yes, I know a couple globals float magically into the sub. Yes I know
that's bad.)



------------------------------------------------------
=head2 add_lostbiz

Add the lostbiz section to the XML document.

=cut

sub add_lostbiz {
   my ($root) = @_;
   my $lostbiz = XML::Twig::Elt->new('lostbiz');
   $lostbiz->paste(last_child => $root) or die;

   # res_transact.room_cat is actually storing adult_qty. See our data
dictionary.
   my $strsql = <<EOT;
SELECT
   last_mod_when, wrap_up_reason, tran_source, arrival_date,
depart_date, room_cat_code,
   rate_cat, room_cat adult_qty, rate_tohigh_amt
FROM res_transact
WHERE prop = '$prop'
and transaction_type != "R"
and wrap_up_reason >= 199
and wrap_up_reason < 599
EOT
   my $sth = $dbh->prepare($strsql);
   $sth->execute;
   my @row;
   while (@row = $sth->fetchrow) {
      for (@row) { s/\s+$// }
      my ($time, $type, $src, $doa, $depart_date, $rt, $seg, $gcnt,
$exprrev) = @row;
      $time =~ s/[- :]//g;
      $doa         = Control::DateTime->new($doa);
      $depart_date = Control::DateTime->new($depart_date);
      my $los = ($depart_date - $doa)->day;
      $rt = $xref->roomcat_xref(
         prop        => $prop,
         crs_roomcat => $rt,
      );
      $seg = $xref->ratecat_xref(
         crs_ratecat => $seg,
      );
      my $elt = XML::Twig::Elt->new( loss => {
         time    => $time,
         type    => $xref->wrap_up_reason($type),
         src     => $src,
         doa     => $doa->format("%Y%m%d"),
         los     => $los,
         rt      => $rt,
         seg     => $seg,
         cas     => "N",
         gcnt    => $gcnt,
         exprrev => sprintf("%0.2f", $exprrev * $los),
      });
      $elt->paste(last_child => $lostbiz) or die;
   }
   $sth->finish;
}
------------------------------------------------------
<revolutiondata asof="20070420151810" hotel="TUSNTL" seq="1" ver="1.50">
  <lostbiz>
    <loss cas="N" doa="20070520" exprrev="158.00" gcnt="2" los="2"
rt="DELUXE" seg="11" src="OMNIREZ-PH" time="20070420092525" type="RR"/>
    <loss cas="N" doa="20070523" exprrev="338.00" gcnt="2" los="2"
rt="DELUXE" seg="07" src="TUSNTL-PH" time="20070420111725" type="RR"/>
    <loss cas="N" doa="20070607" exprrev="345.00" gcnt="1" los="3"
rt="DELUXE" seg="09" src="OMNIREZ-PH" time="20070420132059" type="RR"/>
    <loss cas="N" doa="20070503" exprrev="480.00" gcnt="2" los="3"
rt="DELUXE" seg="09" src="OMNIREZ-PH" time="20070420132407" type="RR"/>
    <loss cas="N" doa="20070503" exprrev="480.00" gcnt="2" los="3"
rt="DELUXE" seg="09" src="OMNIREZ-PH" time="20070420133025" type="RR"/>
  </lostbiz>
</revolutiondata>
------------------------------------------------------