MT#11917 Write journal for customer create/update.

Work in progress.
changes/94/1194/1
Rene Krenn 11 years ago
parent 2914f7c77e
commit eed41633bd

@ -243,6 +243,13 @@ sub POST :Allow {
}
try {
$customer = $schema->resultset('contracts')->create($resource);
$schema->resultset('journals')->create({
type => "create",
resource => "customers",
resource_id => $customer->id,
timestamp => $now->hires_epoch,
content => undef,
});
} catch($e) {
$c->log->error("failed to create customer contract: $e"); # TODO: user, message, trace, ...
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create customer.");

@ -518,5 +518,10 @@ sub is_false {
return;
}
sub to_json {
my ($self, $data) = @_;
return JSON::to_json($data, { canonical => 1, pretty => 1, utf8 => 1 });
}
1;
# vim: set tabstop=4 expandtab:

@ -116,6 +116,15 @@ sub customer_by_id {
sub update_customer {
my ($self, $c, $customer, $old_resource, $resource, $form) = @_;
my $old_hal = $self->hal_from_customer($c, $customer, $form);
$c->model('DB')->resultset('journals')->create({
type => "update",
resource => "customers",
resource_id => $customer->id,
timestamp => NGCP::Panel::Utils::DateTime::current_local->hires_epoch,
content => $self->to_json($old_hal->resource),
});
my $billing_mapping = $customer->billing_mappings->find($customer->get_column('bmid'));
$old_resource->{billing_profile_id} = $billing_mapping->billing_profile_id;
$old_resource->{prepaid} = $billing_mapping->billing_profile->prepaid;

Loading…
Cancel
Save