MT#5879 Apply newly created id to worm to continue work with cretated template.

ipeshinskaya/InvoiceTemplate5
Irina Peshinskaya 11 years ago committed by Victor Seva
parent e5932aa005
commit 2d334de084

@ -897,7 +897,7 @@ sub invoice_template_list :Chained('base') :PathPart('') :Args(0) {
$c->log->debug('invoice_template_list');
$c->stash( template => 'customer/invoice_template_list.tt' );
$c->forward( 'invoice_template_list_data' );
$c->detach($c->view('SVG'));#just no wrapper - aybe there is some other way?
$c->detach($c->view('SVG'));#just no wrapper - maybe there is some other way?
}
sub invoice :Chained('invoice_template_list_data') :PathPart('') :Args(0) {
@ -960,6 +960,17 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
#here we also may be better should contact model, not DB directly. Will return to this separation later
#at the end - we can figure out rather basic controller behaviour
($out->{tt_id},undef,$out->{tt_data}) = $backend->getCustomerInvoiceTemplate( %$in, result => \$tt_string_customer );
$out->{json} = {
tt_data => {
tt_id => $out->{tt_data}->get_column('id'),
},
};
foreach(qw/name is_active/){
$out->{json}->{tt_data}->{$_} = $out->{tt_data}->get_column($_);
}
}
#we need to get default to 1) sanitize (if in->tt_string) or 2)if not in->tt_string and no customer->tt_string
@ -991,11 +1002,18 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
}
#/sanitize - to sub, later
$backend->storeCustomerInvoiceTemplate(
my($tt_stored) = $backend->storeCustomerInvoiceTemplate(
%$in,
tt_string_sanitized => \$tt_string_sanitized,
);
$out->{json} = {
tt_data => {
tt_id => $tt_stored->{tt_id},
},
};
$out->{tt_string} = $tt_string_sanitized;
}elsif(!$tt_string_customer || $tt_string_force_default){
$out->{tt_string} = $tt_string_default;
@ -1057,13 +1075,8 @@ sub invoice_template :Chained('invoice_data') :PathPart('template') :Args {
},
};
#can be empty if we just load default
if($out->{tt_data}){
$aaData->{form} = {
tt_id => $out->{tt_data}->get_column('id'),
};
foreach(qw/name is_active/){
$aaData->{form}->{$_} = $out->{tt_data}->get_column($_);
}
if($out->{json} && $out->{json}->{tt_data}){
$aaData->{form} = $out->{json}->{tt_data};
}else{
#if we didn't have tt_data - then we have empty form fields with applied defaults
$aaData->{form} = $in;

@ -7,11 +7,10 @@ use Data::Dumper;
sub getDefaultConditions{
my $self = shift;
my ($params) = @_;
irka::loglong(Dumper($params));
#irka::loglong(Dumper($params));
my ($contract_id,$tt_sourcestate,$tt_type,$tt_id) = @$params{qw/contract_id tt_sourcestate tt_type tt_id/};
my $conditions = {};
irka::loglong("getDefaultConditions: tt_id=$tt_id;\n");
#my $tt_record = $self->resultset('invoice_template')->search({
if($tt_id){
$conditions = { id => $tt_id };
}else{
@ -29,7 +28,7 @@ sub getCustomerInvoiceTemplate{
my ($contract_id,$tt_sourcestate,$tt_type,$tt_id) = @params{qw/contract_id tt_sourcestate tt_type tt_id/};
irka::loglong("getCustomerInvoiceTemplate: tt_id=$tt_id;\n");
irka::loglong(Dumper(\%params));
#irka::loglong(Dumper(\%params));
my $result = '';
my $conditions = $self->getDefaultConditions(\%params);
@ -73,25 +72,40 @@ sub storeCustomerInvoiceTemplate{
# })->update_all({
# is_active => 0,
# });
#I think that SQl + DBI are much more flexible and compact
my $tt_record_created;
my $tt_record_updated;
if( !$tt_id ){
$self->schema->resultset('invoice_template')->create({
$tt_record_created = $self->schema->resultset('invoice_template')->create({
reseller_id => $contract_id,
type => $tt_type,
is_active => 1,
is_active => $is_active,
name => $name,
'base64_'.$tt_sourcestate => $$tt_string,
});
if($tt_record_created){
$tt_id = $tt_record_created->id();
}
}else{
my $conditions = $self->getDefaultConditions(\%params);
my $tt_record = $self->schema->resultset('invoice_template')->search($conditions);
$tt_record->update({
$tt_record_updated = $self->schema->resultset('invoice_template')->search($conditions);
$tt_record_updated->update({
is_active => $is_active,
name => $name,
'base64_'.$tt_sourcestate => $$tt_string,
});
}
if($is_active && $tt_id){
$self->schema->resultset('invoice_template')->search({
reseller_id => $contract_id,
type => $tt_type,
id => {'!=' => $tt_id },
})->update_all({
is_active => 0,
});
}
});
return { tt_id => $tt_id };
}
sub getCustomerInvoiceTemplateList{
my $self = shift;

@ -159,10 +159,21 @@ function savePreviewedAndShowParsed( data ){
function saveTemplate( data ) {
var svgString = getSvgString();
data.tt_sourcestate='saved';
data.tt_output_type = 'json';
var q = uriForAction( data, 'invoice_template_saved' );
//alert('saveTemplate: q='+q+';');
$.post( q, { template: svgString })
.done( function( httpResponse ) {
url: q,
datatype: "json",
$.ajax(
type: "POST",
url: q,
dataType: 'json',
data: { template: svgString },
).done( function( jsonResponse ) {
if(jsonResponse.aaData && jsonResponse.aaData.form){
$('form[name=invoice_template]').loadJSON(jsonResponse.aaData.form);
}
refreshTemplateList( data.contract_id );
});
}

@ -24,7 +24,7 @@
</style>
</defs>
<style>
<style type="text/css">
<![CDATA[
.address, .company{
font-weight: bold;

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Loading…
Cancel
Save