# Copyright (c) 2000-2002 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: ECPayment.pm,v 2.6 2008/06/18 16:35:02 moeller Exp $ package Bivio::Biz::Model::ECPayment; use strict; use Bivio::Base 'Model.RealmBase'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.6 $ =~ /\d+/g); my($_ECPOS) = __PACKAGE__->use('Type.ECPointOfSale'); my($_ECPS) = __PACKAGE__->use('Type.ECPaymentStatus'); sub create { my($self, $values) = @_; $values->{description} = $values->{service}->get_short_desc unless defined($values->{description}); $values->{status} ||= $_ECPS->CAPTURED; $values->{point_of_sale} ||= $_ECPOS->INTERNET; return shift->SUPER::create(@_); } sub get_amount_sum { # Returns the sum of all payments in this realm. Returns 0 if no payments # for this realm. my($self) = @_; return (Bivio::SQL::Connection->execute_one_row( 'SELECT SUM(amount) FROM ec_payment_t WHERE realm_id = ?', [$self->get_request->get('auth_id')]) || [0])->[0]; } sub internal_initialize { # none of the related fields are linked here # need to always preserve ECPayments, so deleting them # via cascade_delete() should always fail return { version => 1, table_name => 'ec_payment_t', columns => { ec_payment_id => ['PrimaryId', 'PRIMARY_KEY'], # Which realm is using the service realm_id => ['PrimaryId', 'NOT_NULL'], # Which realm paid for the service user_id => ['PrimaryId', 'NOT_NULL'], creation_date_time => ['DateTime', 'NOT_NULL'], amount => ['Amount', 'NOT_NULL'], method => ['ECPaymentMethod', 'NOT_ZERO_ENUM'], status => ['ECPaymentStatus', 'NOT_NULL'], description => ['Line', 'NOT_NULL'], remark => ['Text', 'NONE'], salesperson_id => ['PrimaryId', 'NONE'], service => ['ECService', 'NOT_NULL'], point_of_sale => ['ECPointOfSale', 'NOT_NULL'], }, auth_id => 'realm_id', }; } sub unsafe_get_model { # Overridden to support getting the related ECSubscription, # ECCheckPayment or ECCreditCardPayment. my($self, $name) = @_; if ($name eq 'ECSubscription' || $name eq 'ECCheckPayment' || $name eq 'ECCreditCardPayment') { my($model) = $self->new_other($name); $model->unauth_load({ ec_payment_id => $self->get('ec_payment_id'), }); return $model; } return shift->SUPER::unsafe_get_model(@_); } 1;