MT#5879 Changes related to invoice email template.

mr3.3.1
Irina Peshinskaya 11 years ago
parent 576f5e0dea
commit 6d6484a645

@ -226,6 +226,11 @@ sub POST :Allow {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'passreset_email_template_id', doesn't exist for reseller assigned to customer contact");
return;
}
if($customer->invoice_email_template_id &&
$customer->invoice_email_template->reseller_id != $customer->contact->reseller_id) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'invoice_email_template_id', doesn't exist for reseller assigned to customer contact");
return;
}
try {
$customer->billing_mappings->create({

@ -172,7 +172,13 @@ sub DELETE :Allow {
{
my $item = $self->item_by_id($c, $id);
last unless $self->resource_exists($c, emailtemplate => $item);
#foreach(qw/subscriber_email_template_id passreset_email_template_id invoice_email_template_id/){
# $c->model('DB')->resultset('contracts')->search({
# $_ => $item->id,
# })->update({
# $_ => undef,
# });
#}
$c->model('DB')->resultset('contracts')->search({
subscriber_email_template_id => $item->id,
})->update({
@ -183,6 +189,11 @@ sub DELETE :Allow {
})->update({
passreset_email_template_id => undef,
});
$c->model('DB')->resultset('contracts')->search({
invoice_email_template_id => $item->id,
})->update({
invoice_email_template_id => undef,
});
$item->delete;

@ -124,7 +124,11 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) {
c => $c,
form => $form,
fields => {'contact.create' => $c->uri_for('/contact/create'),
'billing_profile.create' => $c->uri_for('/billing/create')},
'billing_profile.create' => $c->uri_for('/billing/create'),
'subscriber_email_template.create' => $c->uri_for('/emailtemplate/create'),
'passreset_email_template.create' => $c->uri_for('/emailtemplate/create'),
'invoice_email_template.create' => $c->uri_for('/emailtemplate/create'),
},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
@ -355,6 +359,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$params->{billing_profile}{id} = $billing_mapping->billing_profile_id;
$params->{subscriber_email_template}{id} = delete $params->{subscriber_email_template_id};
$params->{passreset_email_template}{id} = delete $params->{passreset_email_template_id};
$params->{invoice_email_template}{id} = delete $params->{invoice_email_template_id};
$params = $params->merge($c->session->{created_objects});
if($c->config->{features}->{cloudpbx}) {
$form = NGCP::Panel::Form::Contract::ProductSelect->new(ctx => $c);
@ -370,7 +375,11 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
c => $c,
form => $form,
fields => {'contact.create' => $c->uri_for('/contact/create'),
'billing_profile.create' => $c->uri_for('/billing/create')},
'billing_profile.create' => $c->uri_for('/billing/create'),
'subscriber_email_template.create' => $c->uri_for('/emailtemplate/create'),
'passreset_email_template.create' => $c->uri_for('/emailtemplate/create'),
'invoice_email_template.create' => $c->uri_for('/emailtemplate/create'),
},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {

@ -156,6 +156,13 @@ sub tmpl_delete :Chained('tmpl_base') :PathPart('delete') {
my ($self, $c) = @_;
try {
#foreach(qw/subscriber_email_template_id passreset_email_template_id invoice_email_template_id/){
# $c->model('DB')->resultset('contracts')->search({
# $_ => $c->stash->{tmpl}->id,
# })->update({
# $_ => undef,
# });
#}
$c->model('DB')->resultset('contracts')->search({
subscriber_email_template_id => $c->stash->{tmpl}->id,
})->update({
@ -166,6 +173,11 @@ sub tmpl_delete :Chained('tmpl_base') :PathPart('delete') {
})->update({
passreset_email_template_id => undef,
});
$c->model('DB')->resultset('contracts')->search({
invoice_email_template_id => $c->stash->{tmpl}->id,
})->update({
invoice_email_template_id => undef,
});
$c->stash->{tmpl}->delete;
$c->flash(messages => [{type => 'success', text => $c->loc('Email template successfully deleted') }]);
} catch ($e) {

@ -22,7 +22,7 @@ has_field 'max_subscribers' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template vat_rate add_vat/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template invoice_email_template vat_rate add_vat/],
);
1;

@ -22,7 +22,7 @@ has_field 'max_subscribers' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template vat_rate add_vat/],
render_list => [qw/contact billing_profile product max_subscribers status external_id subscriber_email_template passreset_email_template invoice_email_template vat_rate add_vat/],
);
1;

@ -77,6 +77,7 @@ sub hal_from_customer {
Data::HAL::Link->new(relation => 'ngcp:contractbalances', href => sprintf("/api/contractbalances/%d", $contract_balance->id)),
$customer->subscriber_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:subscriberemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->subscriber_email_template_id))) : (),
$customer->passreset_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:passresetemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->passreset_email_template_id))) : (),
$customer->invoice_email_template_id ? (Data::HAL::Link->new(relation => 'ngcp:invoiceemailtemplates', href => sprintf("/api/emailtemplates/%d", $customer->invoice_email_template_id))) : (),
Data::HAL::Link->new(relation => 'ngcp:calls', href => sprintf("/api/calls/?customer_id=%d", $customer->id)),
],
relation => 'ngcp:'.$self->resource_name,
@ -187,6 +188,17 @@ sub update_customer {
return;
}
}
my $oldinvtmpl = $old_resource->{invoice_email_template_id} // 0;
if($resource->{invoice_email_template_id} &&
$oldinvtmpl != $resource->{invoice_email_template_id}) {
my $tmpl = $c->model('DB')->resultset('email_templates')
->search({ reseller_id => $custcontact->reseller_id })
->find($resource->{invoice_email_template_id});
unless($tmpl) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'invoice_email_template_id', doesn't exist for reseller assigned to customer contact");
return;
}
}
my $old_ext_id = $customer->external_id // '';

Loading…
Cancel
Save