Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed seedlot transaction issues (description, editing amount/weight, update current count) and improved dialogs #4691

Merged
merged 8 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions lib/CXGN/Stock/Seedlot/Transaction.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ has 'description' => ( isa => 'Maybe[Str]',
is => 'rw',
);

sub BUILD {
my $self = shift;
has 'seedlot_id' => (
isa => 'Int',
is => 'rw',
);


sub BUILD {
my $self = shift;
my $seedlot_id = $self->seedlot_id();
if ($self->transaction_id()) {
my $row = $self->schema()->resultset("Stock::StockRelationship")->find( { stock_relationship_id => $self->transaction_id() }, { join => ['subject', 'object'], '+select' => ['subject.uniquename', 'subject.type_id', 'object.uniquename', 'object.type_id'], '+as' => ['subject_uniquename', 'subject_type_id', 'object_uniquename', 'object_type_id'] } );

Expand All @@ -69,19 +75,24 @@ sub BUILD {
$self->timestamp($data->{timestamp});
$self->operator($data->{operator});
$self->description($data->{description});
if ($row->subject_id == $seedlot_id){
$self->factor(1);
} elsif ($row->object_id == $seedlot_id){
$self->factor(-1);
}
}
}

# class method
sub get_transactions_by_seedlot_id {
sub get_transactions_by_seedlot_id {
my $class = shift;
my $schema = shift;
my $seedlot_id = shift;

print STDERR "Get transactions by seedlot...$seedlot_id\n";
my $type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "seed transaction", "stock_relationship")->cvterm_id();
my $rs = $schema->resultset("Stock::StockRelationship")->search(
{ '-or' =>
{ '-or' =>
[
subject_id => $seedlot_id,
object_id => $seedlot_id
Expand Down Expand Up @@ -133,7 +144,7 @@ sub get_transactions_by_seedlot_id {
return \@transactions;
}

sub get_transactions {
sub get_transactions {
my $class = shift;
my $schema = shift;
my $seedlot_id = shift;
Expand Down Expand Up @@ -163,14 +174,14 @@ sub get_transactions {
}
}
}

if (@ids){
$filter{"-or"} = [
subject_id => { -in => \@ids },
object_id => { -in => \@ids },
];
}

my $type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "seed transaction", "stock_relationship")->cvterm_id();
$filter{'me.type_id'} = { '-in' => $type_id };

Expand Down Expand Up @@ -215,8 +226,8 @@ sub get_transactions {
return \@transactions, $total_count;
}

sub store {
my $self = shift;
sub store {
my $self = shift;
my $transaction_type_id = SGN::Model::Cvterm->get_cvterm_row($self->schema(), "seed transaction", "stock_relationship")->cvterm_id();

my $amount = defined($self->amount()) ? $self->amount() : 'NA';
Expand Down Expand Up @@ -245,7 +256,7 @@ sub store {
}, {order_by => { -desc => 'rank'} });

my $new_rank = 0;
if ($row_rs->first) {
if ($row_rs->first) {
$new_rank = $row_rs->first->rank()+1;
}
#print STDERR Dumper $new_rank;
Expand All @@ -261,7 +272,7 @@ sub store {
return $row->stock_relationship_id();
}

else {
else {
my $row = $self->schema()->resultset("Stock::StockRelationship")->find({ stock_relationship_id => $self->transaction_id });
$row->update({
value => $json_value
Expand Down Expand Up @@ -291,11 +302,8 @@ sub update_transaction_object_id {
}

sub delete {


}

1;



42 changes: 37 additions & 5 deletions lib/SGN/Controller/AJAX/Seedlot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,9 @@ sub seedlot_transaction_base :Chained('seedlot_base') PathPart('transaction') Ca
my $self = shift;
my $c = shift;
my $schema = $c->dbic_schema("Bio::Chado::Schema");
my $seedlot_id = $c->stash->{seedlot}->seedlot_id();
my $transaction_id = shift;
my $t_obj = CXGN::Stock::Seedlot::Transaction->new(schema=>$schema, transaction_id=>$transaction_id);
my $t_obj = CXGN::Stock::Seedlot::Transaction->new(schema=>$schema, transaction_id=>$transaction_id, seedlot_id=>$seedlot_id);
$c->stash->{transaction_id} = $transaction_id;
$c->stash->{transaction_object} = $t_obj;
}
Expand All @@ -890,20 +891,31 @@ sub seedlot_transaction_details :Chained('seedlot_transaction_base') PathPart(''
my $self = shift;
my $c = shift;
my $t = $c->stash->{transaction_object};
my $factor = $t->factor;
my $transaction_type;
if ($factor == 1) {
$transaction_type = 'added to this seedlot';
} elsif ($factor == -1) {
$transaction_type = 'removed from this seedlot';
}

$c->stash->{rest} = {
success => 1,
transaction_id => $t->transaction_id,
description=>$t->description,
amount=>$t->amount,
weight_gram=>$t->weight_gram,
operator=>$t->operator,
timestamp=>$t->timestamp
timestamp=>$t->timestamp,
factor=>$t->factor,
transaction_type=>$transaction_type
};
}

sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit') Args(0) {
my $self = shift;
my $c = shift;
my $schema = $c->dbic_schema("Bio::Chado::Schema");

if (!$c->user()){
$c->stash->{rest} = { error => "You must be logged in to edit seedlot transactions" };
Expand All @@ -915,6 +927,13 @@ sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit
}

my $t = $c->stash->{transaction_object};
my $from_stock = $t->from_stock();
my $from_stock_id = $from_stock->[0];
my $from_stock_type = $from_stock->[2];
my $to_stock = $t->to_stock();
my $to_stock_id = $to_stock->[0];
my $to_stock_type = $to_stock->[2];

my $edit_operator = $c->req->param('operator');
my $edit_amount = $c->req->param('amount');
my $edit_weight = $c->req->param('weight_gram');
Expand All @@ -926,8 +945,21 @@ sub edit_seedlot_transaction :Chained('seedlot_transaction_base') PathPart('edit
$t->description($edit_desc);
$t->timestamp($edit_timestamp);
my $transaction_id = $t->store();
$c->stash->{seedlot}->set_current_count_property();
$c->stash->{seedlot}->set_current_weight_property();

my $seedlot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seedlot', 'stock_type')->cvterm_id();

if ($from_stock_type == $seedlot_cvterm_id) {
my $from_stock_update = CXGN::Stock::Seedlot->new(schema => $schema, seedlot_id => $from_stock_id);
$from_stock_update->set_current_count_property();
$from_stock_update->set_current_weight_property();
}

if ($to_stock_type == $seedlot_cvterm_id) {
my $to_stock_update = CXGN::Stock::Seedlot->new(schema => $schema, seedlot_id => $to_stock_id);
$to_stock_update->set_current_count_property();
$to_stock_update->set_current_weight_property();
}

if ($transaction_id){
my $dbh = $c->dbc->dbh();
my $bs = CXGN::BreederSearch->new( { dbh=>$dbh, dbname=>$c->config->{dbname}, } );
Expand Down Expand Up @@ -1129,7 +1161,7 @@ sub add_seedlot_transaction :Chained('seedlot_base') :PathPart('transaction/add'
my $amount = $c->req->param("amount");
my $weight = $c->req->param("weight");
my $timestamp = $c->req->param("timestamp");
my $description = $c->req->param("description");
my $description = $c->req->param("transaction_description");
my $factor = $c->req->param("factor");
my $transaction = CXGN::Stock::Seedlot::Transaction->new(schema => $c->stash->{schema});
$transaction->factor($factor);
Expand Down
40 changes: 35 additions & 5 deletions mason/breeders_toolbox/seedlot_details.mas
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ $maintenance_enabled => undef
</div>

<div class="form-group">
<label class="col-sm-3 control-label">Transaction Amount (number seeds): </label>
<label class="col-sm-3 control-label">Transaction Amount (number of seeds): </label>
<div class="col-sm-9" >
<input class="form-control" id="seedlot_transaction_amount" placeholder="Amount OR Weight Required">
</div>
Expand All @@ -265,7 +265,8 @@ $maintenance_enabled => undef
</div>
</div>
<div class="modal-footer">
<button id="create_new_seedlot_transaction_button" type="button" class="btn btn-primary" >OK</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="create_new_seedlot_transaction_button" type="button" class="btn btn-primary" >Submit</button>
</div>
</div>
</div>
Expand All @@ -285,6 +286,7 @@ $maintenance_enabled => undef
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="edit_seedlot_transaction_button" type="button" class="btn btn-primary" >Save</button>
</div>
</div>
Expand Down Expand Up @@ -390,12 +392,35 @@ $maintenance_enabled => undef
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="edit_seedlot_details_button" type="button" class="btn btn-primary" >Save</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="transaction_saved_dialog_message" name="transaction_saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="transactionSavedDialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="transactionSavedDialog">Success</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<p>
<span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
The transaction was saved successfully.
</p>
</div>
</div>
<div class="modal-footer">
<button id="dismiss_transaction_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
</div>
</div>
</div>
</div>

<script>
jQuery(document).ready(function () {

Expand Down Expand Up @@ -583,8 +608,8 @@ $maintenance_enabled => undef
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.success == 1) {
alert("The seedlot transaction has been created.");
jQuery('#add_seedlot_transaction_dialog').modal('hide');
jQuery('#transaction_saved_dialog_message').modal('show');
seedlot_transactions_table.ajax.reload();
}
if (response.error) {
Expand Down Expand Up @@ -654,7 +679,8 @@ $maintenance_enabled => undef
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.success == 1) {
alert('Transaction updated!');
jQuery('#edit_seedlot_transaction_dialog').modal('hide');
jQuery('#transaction_saved_dialog_message').modal('show');
seedlot_transactions_table.ajax.reload();
}
if (response.error) {
Expand Down Expand Up @@ -732,6 +758,10 @@ $maintenance_enabled => undef
}
});

jQuery('#dismiss_transaction_saved_dialog').click(function(){
location.reload();
});

});

function editSeedlotTransaction(transaction_id){
Expand All @@ -743,7 +773,7 @@ function editSeedlotTransaction(transaction_id){
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.success == 1) {
html = '<form class="form-horizontal"><div class="form-group"><label class="col-sm-3 control-label">Transaction ID: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_id" value="'+response.transaction_id+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Operator: </label><div class="col-sm-9" ><input type="text" id="edit_seedlot_transaction_operator" class="form-control" value="'+response.operator+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Amount (Number seeds): </label><div class="col-sm-9" ><input type="number" class="form-control" id="edit_seedlot_transaction_amount" value="'+response.amount+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Weight (g): </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_weight" value="'+response.weight_gram+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Timestamp: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_timestamp" value="'+response.timestamp+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Transaction Description: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_description" value="'+response.description+'" /></div></div></form>';
html = '<form class="form-horizontal"><div class="form-group"><label class="col-sm-3 control-label">Transaction ID: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_id" value="'+response.transaction_id+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Operator: </label><div class="col-sm-9" ><input type="text" id="edit_seedlot_transaction_operator" class="form-control" value="'+response.operator+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Transaction Type: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_type" value="'+response.transaction_type+'" disabled/></div></div><div class="form-group"><label class="col-sm-3 control-label">Amount (Number of seeds): </label><div class="col-sm-9" ><input type="number" class="form-control" id="edit_seedlot_transaction_amount" value="'+response.amount+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Weight (g): </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_weight" value="'+response.weight_gram+'" /></div></div><div class="form-group"><label class="col-sm-3 control-label">Timestamp: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_timestamp" value="'+response.timestamp+'" disabled /></div></div><div class="form-group"><label class="col-sm-3 control-label">Transaction Description: </label><div class="col-sm-9" ><input type="text" class="form-control" id="edit_seedlot_transaction_description" value="'+response.description+'" /></div></div></form>';
jQuery('#edit_seedlot_transaction_div').html(html);
jQuery('#edit_seedlot_transaction_dialog').modal('show');
}
Expand Down
34 changes: 29 additions & 5 deletions t/unit_fixture/CXGN/Stock/Seedlot/Transaction.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $source_seedlot->organization_name('bti');
$source_seedlot->population_name('test seedlot pop');
$source_seedlot->breeding_program_id($seedlot_breeding_program_id);
my $return = $source_seedlot->store();
print STDERR Dumper $return;
#print STDERR Dumper $return;
my $source_seedlot_id = $return->{seedlot_id};

print STDERR "Creating transaction 1...\n";
Expand Down Expand Up @@ -113,7 +113,7 @@ $trans2->timestamp(localtime);
$trans2->description('Moving 7 seed from seedlot 2 to seedlot 1');
$trans2->operator('janedoe');

$trans2->store();
my $trans_id_2 =$trans2->store();

print STDERR "Creating transaction 3...\n";
my $trans3 = CXGN::Stock::Seedlot::Transaction->new(
Expand All @@ -126,7 +126,7 @@ $trans3->description('Moving 3 seed from seedlot 1 to seedlot 2');
$trans3->operator('janedoe');
$trans3->amount(3);

$trans3->store();
my $trans_id_3 = $trans3->store();

#checking seedlots after transaction
my $source_seedlot_after_trans3 = CXGN::Stock::Seedlot->new(
Expand All @@ -148,7 +148,7 @@ foreach my $t (@{$source_seedlot_after_trans3->transactions()}) {
ok($t->transaction_id, "check transcation ids");
push @transactions, [ $t->from_stock()->[1], $t->to_stock()->[1], $t->factor()*$t->amount(), $t->operator, $t->description ];
}
print STDERR Dumper \@transactions;
#print STDERR Dumper \@transactions;
is_deeply(\@transactions, [
[
'test seedlot',
Expand Down Expand Up @@ -192,7 +192,7 @@ foreach my $t (@{$dest_seedlot_after_trans3->transactions()}) {
ok($t->transaction_id, "check transcation ids");
push @transactions2, [ $t->from_stock()->[1], $t->to_stock()->[1], $t->factor()*$t->amount(), $t->operator, $t->description ];
}
print STDERR Dumper \@transactions2;
#print STDERR Dumper \@transactions2;
is_deeply(\@transactions2, [
[
'test seedlot',
Expand All @@ -217,4 +217,28 @@ is_deeply(\@transactions2, [
]
], 'check transactions of dest_seedlot');

#test editing transaction 3 from test seedlot page
my $edit_trans3 = CXGN::Stock::Seedlot::Transaction->new(
schema => $f->bcs_schema(),
transaction_id => $trans_id_3,
seedlot_id => $dest_seedlot_id
);
$edit_trans3->to_stock([$source_seedlot_id, $source_seedlot->uniquename, $seedlot_type_id]);
$edit_trans3->from_stock([$dest_seedlot_id, $dest_seedlot->uniquename, $seedlot_type_id]);
$edit_trans3->timestamp(localtime);
$edit_trans3->description('Moving 5 seed from seedlot 1 to seedlot 2');
$edit_trans3->operator('janedoe');
$edit_trans3->amount(5);

my $edit_trans_id = $edit_trans3->store();
is($edit_trans_id, $trans_id_3);

my $test_seedlot_after_editing = CXGN::Stock::Seedlot->new(
schema => $schema,
seedlot_id => $dest_seedlot_id
);

is($test_seedlot_after_editing->current_count, 7);


done_testing();
Loading