Skip to content

Commit

Permalink
Merge pull request #7528 from ehuelsmann/cleanup/buttons-workflow-fol…
Browse files Browse the repository at this point in the history
…lowup

Buttons via workflow (followup for reversals)
  • Loading branch information
ehuelsmann committed Jul 23, 2023
2 parents 0b1fd62 + a9ee06b commit fe63a10
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 15 deletions.
23 changes: 14 additions & 9 deletions lib/LedgerSMB/Workflow/Condition/PeriodClosed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ sub evaluate {
my ($self, $wf) = @_;
my $dbh = $wf->_factory->
get_persister_for_workflow_type( $wf->type )->handle;
my ($opened) = $dbh->selectrow_array(
q|SELECT (?::date + ?::interval) > MAX(end_date)
OR MAX(end_date) IS NULL
FROM account_checkpoint|,
{},
$wf->context->param( $self->workflow_parameter ),
$self->offset
);
die $dbh->errstr if $dbh->err;

my $date = $wf->context->param( $self->workflow_parameter );
my $opened;
if ($date) {
($opened) = $dbh->selectrow_array(
q|SELECT (?::date + ?::interval) > MAX(end_date)
OR MAX(end_date) IS NULL
FROM account_checkpoint|,
{},
$date,
$self->offset
);
die $dbh->errstr if $dbh->err;
}

condition_error 'Period open' if $opened;
return 1;
Expand Down
21 changes: 20 additions & 1 deletion old/bin/aa.pl
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,28 @@ sub post_reversing {
local $form->{description};
local $form->{reference};
local $form->{approved};
local $form->{workflow_id};

&create_links; # create_links overwrites 'reversing'
};

my $wf = $form->{_wire}->get('workflows')
->create_workflow( 'AR/AP',
Workflow::Context->new(
'transdate' => $form->{transdate},
'batch-id' => $form->{batch_id},
'table_name' => 'gl',
'reversing' => $form->{reversing},
'is_transaction' => 1
) );
$form->{workflow_id} = $wf->id;
$wf->execute_action( $form->{__action} );

AA->post_transaction( \%myconfig, \%$form );
$form->call_procedure( funcname=>'draft_approve',
args => [ $form->{id} ]);
$form->{approved} = 1;

my $query = q{UPDATE transactions SET reversing = ? WHERE id = ?};
$form->{dbh}->do(
$query,
Expand Down Expand Up @@ -464,7 +481,8 @@ sub form_header {
Workflow::Context->new(
'batch-id' => $form->{batch_id},
'table_name' => lc($form->{ARAP}),
is_transaction => 1
is_transaction => 1,
reversing => $form->{reversing},
) );
$form->{workflow_id} = $wf->id;
}
Expand Down Expand Up @@ -1068,6 +1086,7 @@ sub form_footer {
my $wf = $form->{_wire}->get('workflows')
->fetch_workflow( 'AR/AP', $form->{workflow_id} );
$transdate = $form->datetonum( \%myconfig, $form->{transdate} );
$wf->context->param( transdate => $transdate );

# type=submit $locale->text('Update')
# type=submit $locale->text('Print')
Expand Down
26 changes: 23 additions & 3 deletions old/bin/gl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ sub approve {

sub new {
for my $row (0 .. $form->{rowcount}){
for my $fld(qw(accno projectnumber acc debit credit source memo)){
for my $fld (
qw(accno projectnumber acc debit credit source memo )
) {
delete $form->{"${fld}_${row}"};
}
}
for my $fld (qw(description reference rowcount id workflow_id transdate notes)) {
for my $fld (
qw(description reference rowcount id workflow_id
transdate notes reversing reversing_reference )
) {
delete $form->{$fld};
}
add();
Expand Down Expand Up @@ -232,13 +237,27 @@ sub post_reversing {
local $form->{reference};
local $form->{reversing_reference} = $form->{reference};
local $form->{approved};
local $form->{workflow_id};

&create_links; # create_links overwrites 'reversing'
};
my $wf = $form->{_wire}->get('workflows')
->create_workflow( 'GL',
Workflow::Context->new(
'transdate' => $form->{transdate},
'batch-id' => $form->{batch_id},
'table_name' => 'gl',
'reversing' => $form->{reversing}
) );
$form->{workflow_id} = $wf->id;
$wf->execute_action( $form->{__action} );

# Why do I not need _reverse_amounts here???
# _reverse_amounts();
GL->post_transaction( \%myconfig, \%$form, $locale);
$form->call_procedure( funcname=>'draft_approve',
args => [ $form->{id} ]);
$form->{approved} = 1;

my $query = q{UPDATE transactions SET reversing = ? WHERE id = ?};
$form->{dbh}->do(
Expand Down Expand Up @@ -324,7 +343,8 @@ sub display_form
->create_workflow( 'GL',
Workflow::Context->new(
'batch-id' => $form->{batch_id},
'table_name' => 'gl'
'table_name' => 'gl',
'reversing' => $form->{reversing}
) );
$form->{workflow_id} = $wf->id;
}
Expand Down
3 changes: 3 additions & 0 deletions workflows/ar-ap.conditions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<condition name="is-batch-member"
test="$context->{'batch-id'}"
class="Workflow::Condition::Evaluate" />
<condition name="reversing"
test="$context->{'reversing'}"
class="Workflow::Condition::Evaluate" />
</conditions>
19 changes: 18 additions & 1 deletion workflows/ar-ap.workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
<type>AR/AP</type>
<persister>JournalEntry</persister>
<description>Manage the life cycle of an AR/AP document</description>

<state name="INITIAL">
<action name="update" resulting_state="NOCHANGE" />
<action name="post" resulting_state="SAVED" />
<action name="post" resulting_state="SAVED">
<condition name="!reversing" />
<condition name="!period-closed" />
<condition name="complete" />
</action>
<action name="post_and_approve" resulting_state="POSTED">
<condition name="!reversing" />
<condition name="!is-batch-member" />
<condition name="!separate-duties" />
<condition name="!period-closed" />
<condition name="complete" />
</action>
<action name="batch-approve" resulting_state="POSTED">
<condition name="!reversing" />
<condition name="is-batch-member" />
<condition name="!period-closed" />
<condition name="complete" />
</action>
<action name="post_reversing" resulting_state="POSTED">
<condition name="reversing" />
<condition name="!period-closed" />
<condition name="acl-draft-post" />
</action>
</state>

<state name="SAVED">
<!-- action name="save_temp" resulting_state="NOCHANGE">
<condition name="!is_invoice" />
Expand Down Expand Up @@ -60,6 +73,7 @@
<condition name="is_invoice" />
</action>
</state>

<state name="POSTED">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="copy_to_new" resulting_state="NOCHANGE" />
Expand All @@ -85,14 +99,17 @@
<condition name="is_invoice" />
</action>
</state>

<state name="ONHOLD">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="release" resulting_state="POSTED" />
</state>

<state name="VOIDED">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="copy_to_new" resulting_state="NOCHANGE" />
</state>

<state name="REVERSED">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="copy_to_new" resulting_state="NOCHANGE" />
Expand Down
3 changes: 3 additions & 0 deletions workflows/gl.conditions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<condition name="is-batch-member"
test="$context->{'batch-id'}"
class="Workflow::Condition::Evaluate" />
<condition name="reversing"
test="$context->{'reversing'}"
class="Workflow::Condition::Evaluate" />
</conditions>
17 changes: 16 additions & 1 deletion workflows/gl.workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@
<type>GL</type>
<persister>JournalEntry</persister>
<description>Manage the life cycle of a GL document (excluding year-end, inventory adjustment and fixed assets transactions)</description>

<state name="INITIAL">
<action name="update" resulting_state="NOCHANGE" />
<action name="post" resulting_state="SAVED" />
<action name="post" resulting_state="SAVED">
<condition name="!reversing" />
<condition name="!period-closed" />
<condition name="complete" />
</action>
<action name="post_and_approve" resulting_state="POSTED">
<condition name="!reversing" />
<condition name="!separate-duties" />
<condition name="!period-closed" />
<condition name="complete" />
</action>
<action name="post_reversing" resulting_state="POSTED">
<condition name="reversing" />
<condition name="!period-closed" />
<condition name="acl-draft-post" />
</action>
</state>

<state name="SAVED">
<!-- action name="save_temp" resulting_state="NOCHANGE">
<condition name="!is_invoice" />
Expand All @@ -36,16 +48,19 @@
<condition name="is-batch-member" />
</action>
</state>

<state name="POSTED">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="copy_to_new" resulting_state="NOCHANGE" />
<action name="reverse" resulting_state="REVERSED" />
<action name="schedule" resulting_state="NOCHANGE" />
<action name="print" resulting_state="NOCHANGE" />
</state>

<state name="REVERSED">
<action name="save_info" resulting_state="NOCHANGE" />
<action name="copy_to_new" resulting_state="NOCHANGE" />
</state>

<state name="DELETED" />
</workflow>

0 comments on commit fe63a10

Please sign in to comment.