implemented product deletion function


			
			
				1.2@1701
			
			
		
Daniel Tiefnig 17 years ago
parent a59448ebf5
commit 1ede1b0397

@ -53,14 +53,32 @@ sub edit_product : Local {
my $product = $c->request->params->{product};
if($product) {
if(ref $c->session->{restore_product_input} eq 'HASH') {
$c->stash->{product}{data} = $c->session->{restore_product_input};
delete $c->session->{restore_product_input};
$c->stash->{product}{handle} = $product ? $product : $c->request->params->{handle};
$c->stash->{product}{data}{price} =
sprintf "%.2f", $c->stash->{product}{data}{price} /= 100;
} elsif($product) {
return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_product',
{ handle => $product },
\$c->stash->{product}
);
$c->stash->{handle} = $product;
$c->stash->{product}{data}{price} =
sprintf "%.2f", $c->stash->{product}{data}{price} /= 100;
}
$c->stash->{handle} = $product if $product;
my $bilprofs;
return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_billing_profiles',
undef,
\$bilprofs
);
$c->stash->{bilprofs} = $$bilprofs{result} if eval { @{$$bilprofs{result}} };
unshift @{$c->stash->{bilprofs}}, { handle => undef, data => { name => '' } };
return 1;
}
@ -76,58 +94,277 @@ sub do_edit_product : Local {
my %messages;
my %settings;
# existing product handle, if any
my $product = $c->request->params->{product};
# new product handle, if any
my $handle = $c->request->params->{handle};
$settings{class} = $c->request->params->{class};
$settings{name} = $c->request->params->{name};
$settings{on_sale} = $c->request->params->{on_sale} ? 1 : 0;
$settings{price} = $c->request->params->{price} || undef;
$settings{weight} = $c->request->params->{weight} || undef;
$settings{price} = $c->request->params->{price};
if(length $settings{price}) {
if($settings{price} =~ /^[+]?\d+(?:[.,]\d\d?)?$/) {
$settings{price} =~ s/,/./;
$settings{price} *= 100;
} else {
$messages{price} = 'Client.Syntax.CashValue';
}
} else {
$settings{price} = 0;
}
$settings{weight} = $c->request->params->{weight};
if(length $settings{weight}) {
$messages{weight} = 'Client.Syntax.TimeValue'
unless $settings{weight} =~ /^[+]?\d+$/;
$settings{weight} =~ s/^\+//;
} else {
$settings{weight} = 0;
}
$settings{billing_profile} = $c->request->params->{billing_profile} || undef;
unless(keys %messages) {
if($product) {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'update_product',
{ handle => $product,
data => \%settings,
},
undef))
{
$messages{prodmsg} = 'Web.Product.Updated';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#product");
return;
}
$c->session->{restore_product_input} = \%settings;
$c->response->redirect("/billing/edit_product?product=$product");
return;
} else {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'create_product',
{ handle => $handle,
data => \%settings,
},
undef))
{
$messages{prodmsg} = 'Web.Product.Created';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#product");
return;
}
$c->session->{restore_product_input} = \%settings;
$c->response->redirect("/billing/edit_product?handle=$handle");
return;
}
}
$c->session->{messages} = \%messages;
$c->session->{restore_product_input} = \%settings;
if($product) {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'update_product',
{ handle => $product,
data => \%settings,
},
$c->response->redirect("/billing/edit_product?product=$product");
} else {
$c->response->redirect("/billing/edit_product?handle=$handle");
}
return;
}
=head2 do_delete_product
Delete a product from the database.
=cut
sub do_delete_product : Local {
my ( $self, $c ) = @_;
my $product = $c->request->params->{product};
if($product) {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'delete_product',
{ handle => $product },
undef))
{
$messages{prodmsg} = 'Server.Voip.SavedSettings';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#products");
$c->session->{messages} = { prodmsg => 'Web.Product.Deleted' };
$c->response->redirect("/billing#product");
return;
}
$c->session->{restore_product_input} = \%settings;
$c->response->redirect("/billing/edit_product?product=$product");
return;
}
$c->response->redirect("/billing");
return;
}
=head2 edit_bilprof
Display settings for a billing profile or allow to enter a new one.
=cut
sub edit_bilprof : Local {
my ( $self, $c ) = @_;
$c->stash->{template} = 'tt/bilprof_edit.tt';
my $bilprof = $c->request->params->{bilprof};
if(ref $c->session->{restore_bilprof_input} eq 'HASH') {
$c->stash->{bilprof}{data} = $c->session->{restore_bilprof_input};
delete $c->session->{restore_bilprof_input};
$c->stash->{bilprof}{handle} = $bilprof ? $bilprof : $c->request->params->{handle};
$c->stash->{bilprof}{data}{interval_charge} =
sprintf "%.2f", $c->stash->{bilprof}{data}{interval_charge} /= 100;
$c->stash->{bilprof}{data}{interval_free_cash} =
sprintf "%.2f", $c->stash->{bilprof}{data}{interval_free_cash} /= 100;
} elsif($bilprof) {
return unless $c->model('Provisioning')->call_prov( $c, 'billing', 'get_billing_profile',
{ handle => $bilprof },
\$c->stash->{bilprof}
);
$c->stash->{bilprof}{data}{interval_charge} =
sprintf "%.2f", $c->stash->{bilprof}{data}{interval_charge} /= 100;
$c->stash->{bilprof}{data}{interval_free_cash} =
sprintf "%.2f", $c->stash->{bilprof}{data}{interval_free_cash} /= 100;
}
$c->stash->{handle} = $bilprof if $bilprof;
return 1;
}
=head2 do_edit_bilprof
Change settings for a billing profile in the database or create a new
one.
=cut
sub do_edit_bilprof : Local {
my ( $self, $c ) = @_;
my %messages;
my %settings;
# existing profile handle, if any
my $bilprof = $c->request->params->{bilprof};
# new profile handle, if any
my $handle = $c->request->params->{handle};
$settings{name} = $c->request->params->{name};
$settings{prepaid} = $c->request->params->{prepaid} ? 1 : 0;
$settings{interval_unit} = $c->request->params->{interval_unit} || 'month';
$settings{interval_count} = $c->request->params->{interval_count} || 1;
$settings{interval_charge} = $c->request->params->{interval_charge};
if(length $settings{interval_charge}) {
if($settings{interval_charge} =~ /^[+]?\d+(?:[.,]\d\d?)?$/) {
$settings{interval_charge} =~ s/,/./;
$settings{interval_charge} *= 100;
} else {
$messages{charge} = 'Client.Syntax.CashValue';
}
} else {
$settings{interval_charge} = 0;
}
$settings{interval_free_time} = $c->request->params->{interval_free_time};
if(length $settings{interval_free_time}) {
$messages{free_time} = 'Client.Syntax.TimeValue'
unless $settings{interval_free_time} =~ /^[+]?\d+$/;
$settings{interval_free_time} =~ s/^\+//;
} else {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'create_product',
{ handle => $handle,
data => \%settings,
},
$settings{interval_free_time} = 0;
}
$settings{interval_free_cash} = $c->request->params->{interval_free_cash};
if(length $settings{interval_free_cash}) {
if($settings{interval_free_cash} =~ /^[+]?\d+(?:[.,]\d\d?)?$/) {
$settings{interval_free_cash} =~ s/,/./;
$settings{interval_free_cash} *= 100;
} else {
$messages{free_cash} = 'Client.Syntax.CashValue';
}
} else {
$settings{interval_free_cash} = 0;
}
unless(keys %messages) {
if($bilprof) {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'update_billing_profile',
{ handle => $bilprof,
data => \%settings,
},
undef))
{
$messages{profmsg} = 'Web.Bilprof.Updated';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#bilprof");
return;
}
$c->session->{restore_bilprof_input} = \%settings;
$c->response->redirect("/billing/edit_bilprof?bilprof=$bilprof");
return;
} else {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'create_billing_profile',
{ handle => $handle,
data => \%settings,
},
undef))
{
$messages{profmsg} = 'Web.Bilprof.Created';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#bilprof");
return;
}
$c->session->{restore_bilprof_input} = \%settings;
$c->response->redirect("/billing/edit_bilprof?handle=$handle");
return;
}
}
$c->session->{messages} = \%messages;
$c->session->{restore_bilprof_input} = \%settings;
if($bilprof) {
$c->response->redirect("/billing/edit_bilprof?bilprof=$bilprof");
} else {
$c->response->redirect("/billing/edit_bilprof?handle=$handle");
}
return;
}
=head2 do_delete_bilprof
Delete a billing profile from the database.
=cut
sub do_delete_bilprof : Local {
my ( $self, $c ) = @_;
my $bilprof = $c->request->params->{bilprof};
if($bilprof) {
if($c->model('Provisioning')->call_prov( $c, 'billing', 'delete_billing_profile',
{ handle => $bilprof },
undef))
{
$messages{prodmsg} = 'Server.Voip.SavedSettings';
$c->session->{messages} = \%messages;
$c->response->redirect("/billing#products");
$c->session->{messages} = { profmsg => 'Web.Bilprof.Deleted' };
$c->response->redirect("/billing#bilprof");
return;
}
$c->session->{restore_product_input} = \%settings;
$c->response->redirect("/billing/edit_product");
return;
}
$c->response->redirect("/billing");
return;
}
=head1 BUGS AND LIMITATIONS
=over
=item missing product delete function
=item missing billing profile functions
=item functions are missing some syntax checks
=back

@ -1,4 +1,4 @@
<h3>Products</h3>
<h3 id="product">Products</h3>
[% UNLESS Catalyst.session.admin.read_only %]
<div class="actions">
@ -7,6 +7,7 @@
[% END %]
<div class="p1">
[% IF messages.prodmsg %]<div class="goodmsg">[% messages.prodmsg %]</div>[% END %]
<table>
[% IF products %]
<tr class="table_header">
@ -45,7 +46,7 @@
</table>
</div>
<h3>Billing Profiles</h3>
<h3 id="bilprof">Billing Profiles</h3>
[% UNLESS Catalyst.session.admin.read_only %]
<div class="actions">
@ -54,8 +55,7 @@
[% END %]
<div class="p1">
[% IF messages.cdommsg %]<div class="goodmsg">[% messages.cdommsg %]</div>[% END %]
[% IF messages.cdomerr %]<div class="errormsg">[% messages.cdomerr %]</div>[% END %]
[% IF messages.profmsg %]<div class="goodmsg">[% messages.profmsg %]</div>[% END %]
<table>
[% IF bilprofs %]
@ -68,7 +68,10 @@
[% id = 0 %]
[% FOREACH bilprof = bilprofs %]
<tr>
<td>[% bilprof.data.prepaid %]</td>
<td class="tdcenter">
<input type="checkbox" class="checkbox" name="prepaid" disabled="disabled"
[% IF bilprof.data.prepaid %]checked="checked"[% END %] />
</td>
<td>[% bilprof.data.name %]</td>
<td>
[% UNLESS Catalyst.session.admin.read_only %]

@ -0,0 +1,69 @@
[% IF handle %]
<h3>Edit Billing Profile</h3>
[% ELSE %]
<h3>Create New Billing Profile</h3>
[% END %]
<div class="actions">
<a href="/billing#bilprof" class="aaction">cancel</a>
</div>
<div class="p1">
<form action="do_edit_bilprof" method="post">
<input type="hidden" name="bilprof" value="[% handle %]" />
<table>
<tr>
<td class="tdkey">handle:</td>
[% IF handle %]
<td>[% bilprof.handle %]</td>
[% ELSE %]
<td><input type="text" name="handle" value="[% bilprof.handle %]" /></td>
[% END %]
</tr>
[% IF messages.handle %]<tr><td /><td><div class="errormsg">[% messages.handle %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">name:</td>
<td><input type="text" name="name" value="[% bilprof.data.name %]" /></td>
</tr>
[% IF messages.name %]<tr><td /><td><div class="errormsg">[% messages.name %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">prepaid:</td>
<td><input type="checkbox" class="checkbox" name="prepaid" [% IF bilprof.data.prepaid %]checked="checked"[% END %] /></td>
</tr>
<!--
<tr>
<td class="tdkey">interval unit:</td>
<td>
<select size="1" name="interval_unit">
<option [% IF bilprof.data.interval_unit == "month" %]selected="selected"[% END %]>month</option>
<option [% IF bilprof.data.interval_unit == "week" %]selected="selected"[% END %]>week</option>
</select>
</td>
</tr>
[% IF messages.unit %]<tr><td /><td><div class="errormsg">[% messages.unit %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">interval count:</td>
<td><input type="text" name="interval_count" value="[% bilprof.data.interval_count %]" /></td>
</tr>
[% IF messages.count %]<tr><td /><td><div class="errormsg">[% messages.count %]</div></td></tr>[% END %]
-->
<tr>
<td class="tdkey">interval charge:</td>
<td><input type="text" name="interval_charge" value="[% bilprof.data.interval_charge %]" /></td>
</tr>
[% IF messages.charge %]<tr><td /><td><div class="errormsg">[% messages.charge %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">interval free time:</td>
<td><input type="text" name="interval_free_time" value="[% bilprof.data.interval_free_time %]" /></td>
</tr>
[% IF messages.free_time %]<tr><td /><td><div class="errormsg">[% messages.free_time %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">interval free cash:</td>
<td><input type="text" name="interval_free_cash" value="[% bilprof.data.interval_free_cash %]" /></td>
</tr>
[% IF messages.free_cash %]<tr><td /><td><div class="errormsg">[% messages.free_cash %]</div></td></tr>[% END %]
</table>
<input type="submit" class="but" value="Save &#187;" />
</form>
</div>

@ -21,6 +21,7 @@
<td><input type="text" name="handle" value="[% product.handle %]" /></td>
[% END %]
</tr>
[% IF messages.handle %]<tr><td /><td><div class="errormsg">[% messages.handle %]</div></td></tr>[% END %]
<!--
<tr>
<td class="tdkey">class:</td>
@ -32,26 +33,38 @@
</select>
</td>
</tr>
[% IF messages.class %]<tr><td /><td><div class="errormsg">[% messages.class %]</div></td></tr>[% END %]
-->
<tr>
<td class="tdkey">name:</td>
<td><input type="text" name="name" value="[% product.data.name %]" /></td>
</tr>
[% IF messages.name %]<tr><td /><td><div class="errormsg">[% messages.name %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">on sale:</td>
<td><input type="checkbox" class="checkbox" name="on_sale" [% IF product.data.on_sale %]checked="checked"[% END %] /></td>
</tr>
[% IF messages.on_sale %]<tr><td /><td><div class="errormsg">[% messages.on_sale %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">price:</td>
<td><input type="text" name="price" value="[% product.data.price %]" /></td>
</tr>
[% IF messages.price %]<tr><td /><td><div class="errormsg">[% messages.price %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">weight:</td>
<td><input type="text" name="weight" value="[% product.data.weight %]" /></td>
</tr>
[% IF messages.weight %]<tr><td /><td><div class="errormsg">[% messages.weight %]</div></td></tr>[% END %]
<tr>
<td class="tdkey">billing_profile:</td>
<td><input type="text" name="billing_profile" value="[% product.data.billing_profile %]" /></td>
<td>
<select size="1" name="billing_profile">
[% FOREACH bilprof = bilprofs %]
<option [% IF bilprof.handle == product.data.billing_profile %]selected="selected"[% END %]
value="[% bilprof.handle %]">[% bilprof.data.name %]</option>
[% END %]
</select>
</td>
</tr>
</table>
<input type="submit" class="but" value="Save &#187;" />

Loading…
Cancel
Save