sub create_sl_invoice_mech { my $self = shift; my ($customer, $event_id) = @_; my ($inv_id,$inv_pdf_path,$inv_html_path); $inv_pdf_path = '/path/to/pdf/file'; $inv_html_path = '/path/to/html/file'; print STDERR "Now creating new invoice for $customer->{'name'}.\n"; my $base_url = $self->{'Cfg'}->{'default'}->{'base_url'}; my $user = $self->{'Cfg'}->{'sl_event_registration'}->{'user'}; my $pw = $self->{'Cfg'}->{'sl_event_registration'}->{'pw'}; # 'is.pl?path=bin/mozilla&action=add&level=AR--Sales%20Invoice&login=test-user&js=1&type=invoice'; my $arg = 'path=bin/mozilla'; $arg .= '&login=' .$user; $arg .= '&password=' . $pw; $arg .= '&action=Login'; $arg .= '&action=add'; $arg .= '&level=AR--Sales%20Invoice'; $arg .= '&login=' .$user; $arg .= '&js=1'; $arg .= '&type=invoice'; my $url = $base_url . 'is.pl?' . $arg; print STDERR "\$url is: $url \n"; my $agent = $self->{'mech'}; $agent->get($url); if($agent->success()){ $agent->field('customer', $customer->{'customer_id'}); print STDERR "customer_id is: $customer->{'customer_id'}\n"; $agent->field('employee', $self->{'Cfg'}->{'default'}->{'employee'}); print STDERR "Employee is: $self->{'Cfg'}->{'default'}->{'employee'}\n"; # 'Finding Your Center Event Registration--10064'); $agent->field('partnumber_1', $event_id ); print STDERR "As partnumber_1 we will use $event_id\n"; $agent->click_button( name => 'action', value => 'Update' ); if($agent->success()){ print "\$agent reports that invoice was successfully updated\n"; } $agent->click_button( name => 'action', value => 'Post' ); if($agent->success()){ print '\$agent reports that invoice was successfully posted',"\n"; } # sleep 15; # $agent->click_button( name => 'action', value => 'Post' ); # $agent->click_button( name => 'action', value => 'Post' ); # sleep 15; # $agent->click_button( name => 'action', value => 'Post' ); # $agent->click_button( name => 'action', value => 'Post' ); # sleep 15; # $agent->click_button( name => 'action', value => 'Post' ); } else { croak "Unable to get invoice creation form.\n"; } # print STDERR $agent->content(); open('INVOICE','>','/home/hesco/sb/fyc_registration/invoice.html'); print INVOICE $agent->content(); close(INVOICE); print STDERR "We're about to search_sl_invoice_mech for $customer->{'customer_id'} at this point . . . \n"; my @invoice_ids = $self->search_sl_invoice_mech($customer->{'customer_id'}); print STDERR "We have search_sl_invoice_mech and found |@invoice_ids| . . . \n"; # print Dumper($customer); # print STDERR "We're about to retrieve_sl_invoice_mech at this point . . . "; my $inv = $self->retrieve_sl_invoice_mech($customer,$invoice_ids[0]); # print STDERR 'We have retrieve_sl_invoice_mech at this point . . . '; $inv_id = $inv->{'id'} || $invoice_ids[0] || 0; my $amount = $inv->{'amount'} || 0; my $msg = sprintf ("Have now grabbed id: %u for \$%.2f as the new invoice.\n", $inv_id, $amount); print STDERR $msg; my %invoice = ( id => $inv_id, amount => $amount, pdf_path => "$inv_pdf_path", html_path => "$inv_html_path", ); $self->{'Cfg'}->{'invoices'}->{'latest_invoice'} = \%invoice; return \%invoice; }