Class Invoice

Description

Class represents records from table invoice - a subject to bill customer

Sample usage:

  1.  $b $this->getDi()->invoiceRecord;
  2.  $b->add(Am_Di::getInstance()->productTable->load(1)1);
  3.  $b->add(Am_Di::getInstance()->productTable->load(2)2);
  4.  $b->add(Am_Di::getInstance()->productTable->load(3)3);
  5.  $b->setUser(Am_Di::getInstance()->userTable->load(1445));
  6.  $b->setCouponCode('SECOND');
  7.  $errors $b->validate();
  8.  if (!$errors)
  9.     $b->calculate();
  10.  else
  11.      echo($errors'errors');

{autogenerated}

Located in /application/default/models/Invoice.php (line 61)

Am_Record
   |
   --Am_Record_WithData
      |
      --Invoice
Class Constant Summary
Variable Summary
static mixed $statusText
_coupon $_coupon
string $_couponCode
Method Summary
Invoice add (IProduct $product, [ $qty = 1])
void addAccessPeriod (Am_Paysystem_Transaction_Abstract $transaction, [ $invoicePaymentId = null])
void addChargeback (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId)
void addItem (InvoiceItem $item)
void addPayment (Am_Paysystem_Transaction_Abstract $transaction)
Invoice_Payment addPaymentWithoutAccessPeriod (Am_Paysystem_Transaction_Abstract $transaction)
void addRefund (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId, [ $amount = null])
void addRefundInternal (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId,  $refundType, [ $refundAmount = null])
void addVoid (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId)
string calculateRebillDate ( $n)
null|string checkProductRequirements ()
InvoiceItem createItem ([IProduct $product = null])
void delete ()
void deleteItem (InvoiceItem $item)
void emailCanceled ()
void exportXmlLog ()
void extendAccessPeriod ( $newExpire, date $start, date $expire)
InvoiceItem findItem ( $type,  $id)
date getAccessExpire ()
array getAccessRecords ()
array getCalculators ()
void getCity ()
void getCountry ()
_coupon|null getCoupon ()
Am_Currency getCurrency ([ $value = null])
void getEmail ()
void getFirstName ()
InvoiceItem getItem (int $num)
array getItems ()
void getLastName ()
string getLineDescription ()
void getLogin ()
void getName ()
void getPhone ()
array getProducts ()
string getRandomizedId ([string $param = null])
void getSecureId ( $prefix)
void getShippingCity ()
void getShippingZip ()
void getState ()
void getStatus ()
void getStatusText ()
void getStreet ()
string getTerms ()
void getUniqId ( $prefix)
User|null getUser ()
void getUserId ()
void getZip ()
void hasShipping ()
void init ()
void insert ([ $reload = true])
void isCancelled ()
bool isCompleted ()
boolean isFirstPayment ()
true isFixedPrice ()
null|string isItemCompatible (InvoiceItem $item)
bool isPaid ()
void isProductCompatible (IProduct $product)
void isZero ()
void render ([ $indent = ""])
void revokeAccess (Am_Paysystem_Transaction_Abstract $transaction)
void setCancelled ([ $cancelled = true])
Invoice setCoupon (_coupon $_coupon)
void setCouponCode ( $code)
void setPaysystem (string $paysys_id)
void setUser (User $user)
void stopAccess (Am_Paysystem_Transaction_Abstract $transaction)
void update ()
void updateStatus ()
null|array validate ()
void validateCoupon ()
void _choosePaysystemIfProductPaysystem (string $paysys_id)
void _getInvoiceKey ()
void _getItemCompatibleError ( $reasonSubstring, InvoiceItem $item, InvoiceItem $existingItem)
void _getPublicId ()
void __sleep ()
void __toString ()
void __wakeup ()
Variables
static mixed $statusText = array(
self::PENDING => "Pending",
self::PAID => "Paid",
self::RECURRING_ACTIVE => "Recurring Active",
self::RECURRING_CANCELLED => "Recurring Cancelled",
self::RECURRING_FAILED => "Recurring Failed",
self::RECURRING_FINISHED => "Recurring Finished",
self::CHARGEBACK => "Chargeback Received",
)
(line 71)
_coupon $_coupon (line 93)
  • var: lazy-loading
  • access: protected
string $_couponCode (line 88)
  • access: protected
User $_user (line 90)
  • var: lazy-loading (private)
  • access: protected

Inherited Variables

Inherited from Am_Record_WithData

Am_Record_WithData::$_dataStorage

Inherited from Am_Record

Am_Record::$_db
Am_Record::$_disableInsertPkCheck
Am_Record::$_isFrozen
Am_Record::$_table
Methods
add (line 190)

Add a product or calculated charge as a line to invoice

  • return: provides fluent interface
  • throws: Am_Exception_InvalidRequest if items is incompatible
Invoice add (IProduct $product, [ $qty = 1])
addAccessPeriod (line 853)

If given $transaction was not handled yet (@see Am_Paysystem_Transaction_Abstract::getUniqId) we will handle it, and add access records to amember_invoice_access table,

  • access: public
void addAccessPeriod (Am_Paysystem_Transaction_Abstract $transaction, [ $invoicePaymentId = null])
addChargeback (line 1043)

Add chargback for payment with given receiptId and disable ALL access records

  • access: public
void addChargeback (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId)
addItem (line 140)
void addItem (InvoiceItem $item)
addPayment (line 958)
  • access: public
void addPayment (Am_Paysystem_Transaction_Abstract $transaction)
addPaymentWithoutAccessPeriod (line 966)
  • access: public
Invoice_Payment addPaymentWithoutAccessPeriod (Am_Paysystem_Transaction_Abstract $transaction)
addRefund (line 1037)

Add refund for payment with receiptId === $origReceiptId and related access records

  • access: public
void addRefund (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId, [ $amount = null])
addRefundInternal (line 1048)
  • access: protected
void addRefundInternal (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId,  $refundType, [ $refundAmount = null])
addVoid (line 1031)
  • access: public
void addVoid (Am_Paysystem_Transaction_Abstract $transaction,  $origReceiptId)
calculate (line 239)

Refresh totals according to currently selected

items, _coupon, user and so ons Should be called on a fresh invoice only, because it may break reporting later if called on a paid invoice

  • return: provides fluent interface
Invoice calculate ()
calculateRebillDate (line 679)

Calculate planned rebill date for $n rebill

  • return: date
string calculateRebillDate ( $n)
  • $n
checkProductRequirements (line 322)

Check product requirements and return null if OK, or error message

  • access: protected
null|string checkProductRequirements ()
createItem (line 107)

Create new empty InvoiceItem, assign invoice_id

and return

InvoiceItem createItem ([IProduct $product = null])
delete (line 832)

Dangerous! Deletes all related payments from 'payments' table

void delete ()

Redefinition of:
Am_Record_WithData::delete()
deleteItem (line 133)

Delete an item

void deleteItem (InvoiceItem $item)
emailCanceled (line 1082)
void emailCanceled ()
exportXmlLog (line 1306)
  • access: public
void exportXmlLog ()
extendAccessPeriod (line 936)

Add small manual access period for example during cc_rebill failure

  • access: public
void extendAccessPeriod ( $newExpire, date $start, date $expire)
  • date $start
  • date $expire
  • $newExpire
findItem (line 122)

Find an item in $this->getItems() by type and ids

InvoiceItem findItem ( $type,  $id)
  • $type
  • $id
getAccessExpire (line 1231)
  • return: max expiration date of current invoice's access records
  • access: public
date getAccessExpire ()
getAccessRecords (line 1225)
  • return: of related Access objects
  • access: public
array getAccessRecords ()
getCalculators (line 210)
  • return: of instantiated Am_Invoice_Calc_* objects
array getCalculators ()
getCity (line 589)
  • access: public
void getCity ()
getCountry (line 599)
  • access: public
void getCountry ()
getCoupon (line 437)

Return _coupon record (by coupon_id) or a new empty _coupon object

caches result in $this->_coupon

_coupon|null getCoupon ()
getCurrency (line 487)
Am_Currency getCurrency ([ $value = null])
  • $value
getEmail (line 578)
  • access: public
void getEmail ()
getExpectedPaymentsCount (line 1150)

How many payments must be done here for complete cycle

  • access: public
void getExpectedPaymentsCount ()
getFirstName (line 568)
  • access: public
void getFirstName ()
getItem (line 151)
InvoiceItem getItem (int $num)
  • int $num: - number of item in invoice
getItems (line 164)
  • return: InvoiceItem records
array getItems ()
getLastName (line 573)
  • access: public
void getLastName ()
getLineDescription (line 650)

Return one-line description of products in the basket

to be passed to payment system

string getLineDescription ()
getLogin (line 553)
  • access: public
void getLogin ()
getName (line 563)
  • access: public
void getName ()
getPaymentRecords (line 1237)
  • access: public
void getPaymentRecords ()
getPaymentsCount (line 1247)
  • access: public
void getPaymentsCount ()
getPhone (line 609)
  • access: public
void getPhone ()
getProducts (line 175)

return array of all items Products (it will be loaded if item_type == 'product'

  • return: Product
array getProducts ()
getRandomizedId (line 668)

Return invoice id with not-numeric random string added

this avoids "duplicate invoice" error in paysystems like Paypal, and can be easily stipped by running it is proved that in same session it will return the same id for same invoice

  • return: . 'randomstring';
  • example: example not found
string getRandomizedId ([string $param = null])
  • string $param: if set to date it will be not be unique within current date
getRefundRecords (line 1242)
  • access: public
void getRefundRecords ()
getSecureId (line 725)

Return string in form 1123-LKj3lrkjg3

  • link: InvoiceTable->findBySecureId
void getSecureId ( $prefix)
  • $prefix
getShippingCity (line 620)
  • access: public
void getShippingCity ()
getShippingCountry (line 630)
  • access: public
void getShippingCountry ()
getShippingPhone (line 640)
  • access: public
void getShippingPhone ()
getShippingState (line 625)
  • access: public
void getShippingState ()
getShippingStreet (line 615)
  • access: public
void getShippingStreet ()
getShippingZip (line 635)
  • access: public
void getShippingZip ()
getState (line 594)
  • access: public
void getState ()
getStatus (line 1158)
  • access: public
void getStatus ()
getStatusText (line 1180)
  • access: public
void getStatusText ()
getStatusTextColor (line 1163)
  • access: public
void getStatusTextColor ()
getStreet (line 584)
  • access: public
void getStreet ()
getTerms (line 1290)
  • return: caclulated billing terms
  • access: public
string getTerms ()
getUniqId (line 716)

Return unique id for invoice. With the same prefix, returned value

is always the same for the same invoice

void getUniqId ( $prefix)
  • $prefix
getUser (line 415)

Return user record (by user_id) or null

caches result in $this->_user

User|null getUser ()
getUserId (line 558)
  • access: public
void getUserId ()
getZip (line 604)
  • access: public
void getZip ()
hasShipping (line 730)
void hasShipping ()
init (line 95)
  • access: public
void init ()

Redefinition of:
Am_Record::init()
Function to be overriden in child classes
insert (line 800)
void insert ([ $reload = true])
  • $reload

Redefinition of:
Am_Record_WithData::insert()
isCancelled (line 1264)
  • access: public
void isCancelled ()
isCompleted (line 1282)
  • return: true if this invoice is "completed" as it said in aMember<=3
  • access: public
bool isCompleted ()
isFirstPayment (line 500)

Return flag necessary for _coupon discount calculation

  • todo: actual calcultations in Invoice::isFirstPayment
  • access: public
boolean isFirstPayment ()
isFixedPrice (line 747)
  • return: if this invoice is acceptable for "fixed price" plugins It means - one product, no taxes, no discounts, no shipping
  • access: public
true isFixedPrice ()
isItemCompatible (line 521)

This checks new item for compatibility with already added products

in the invoice items. If settings of recurring billing is incompatible,

  • product is not compared to itself
  • if product has rebill_times = 0, it is compatible
  • if product has rebill_times = 1, firstPeriod must be compatible (equal to) with all other such products in basket
  • if product has rebill_times > 1, secondPeriod must be compatible (equal to) with all other such products in basket

  • return: translated error message
  • access: public
null|string isItemCompatible (InvoiceItem $item)
isPaid (line 1274)
  • return: true if there was real payments for this invoice
  • access: public
bool isPaid ()
isProductCompatible (line 547)
void isProductCompatible (IProduct $product)
isZero (line 738)
  • access: public
void isZero ()
render (line 763)
void render ([ $indent = ""])
  • $indent
revokeAccess (line 1208)
  • access: public
void revokeAccess (Am_Paysystem_Transaction_Abstract $transaction)
setCancelled (line 1252)
  • access: public
void setCancelled ([ $cancelled = true])
  • $cancelled
setCoupon (line 450)

Set _coupon and check if that is acceptable

  • return: provides fluent interface
Invoice setCoupon (_coupon $_coupon)
  • $_coupon
setCouponCode (line 461)

Set _coupon code

You also need to call validateCoupon() to get it loaded and checked

void setCouponCode ( $code)
  • $code
setPaysystem (line 388)

Validates and sets passed paysysy_id

  • see: $this->paysys_id
  • access: public
void setPaysystem (string $paysys_id)
  • string $paysys_id
setUser (line 426)
void setUser (User $user)
stopAccess (line 1185)
  • access: public
void stopAccess (Am_Paysystem_Transaction_Abstract $transaction)
update (line 791)
void update ()

Redefinition of:
Am_Record_WithData::update()
updateRebillDate (line 1002)
  • access: protected
void updateRebillDate ()
updateStatus (line 1102)
  • access: public
void updateStatus ()
validate (line 303)

Validate invoice to make sure it is fully ready for payment processing

check for

  • no items
  • items are compatible by its terms
  • user_id set and valid
  • paysys_id set and valid
  • @todo currency set and valid
  • trial1Total, total - calculated
  • coupon_id is !set || valid
  • !isPaid

  • return: null if OK, array of translated errors if not
null|array validate ()
validateCoupon (line 471)

Validate currently set coupon code, return error message or null of OK

void validateCoupon ()
_autoChoosePaysystemIfProductPaysystem (line 357)
  • access: protected
void _autoChoosePaysystemIfProductPaysystem ()
_choosePaysystemIfProductPaysystem (line 339)

Make choice of paysystem if $this->getDi()->config->get('product_paysystem') enabled

If paysys_id is null, we will try to choose an acceptable paysystem automatically

  • access: protected
void _choosePaysystemIfProductPaysystem (string $paysys_id)
  • string $paysys_id: paysys_id (optional)
_getInvoiceKey (line 698)
  • access: protected
void _getInvoiceKey ()
_getItemCompatibleError (line 505)
  • access: protected
void _getItemCompatibleError ( $reasonSubstring, InvoiceItem $item, InvoiceItem $existingItem)
_getPublicId (line 705)
  • access: protected
void _getPublicId ()
__sleep (line 1296)
  • access: public
void __sleep ()

Redefinition of:
Am_Record::__sleep()
__toString (line 754)
void __toString ()

Redefinition of:
Am_Record::__toString()
__wakeup (line 1301)
  • access: public
void __wakeup ()

Redefinition of:
Am_Record::__wakeup()

Inherited Methods

Inherited From Am_Record_WithData

Am_Record_WithData::data()
Am_Record_WithData::delete()
Am_Record_WithData::fromRow()
Am_Record_WithData::insert()
Am_Record_WithData::setForInsert()
Am_Record_WithData::setForUpdate()
Am_Record_WithData::toArray()
Am_Record_WithData::toRow()
Am_Record_WithData::update()
Am_Record_WithData::_prepareForSet()

Inherited From Am_Record

Am_Record::__construct()
Am_Record::delete()
Am_Record::deleteFromRelatedTable()
Am_Record::disableInsertPkCheck()
Am_Record::exportXml()
Am_Record::fromRow()
Am_Record::get()
Am_Record::getAdapter()
Am_Record::getDi()
Am_Record::getTable()
Am_Record::init()
Am_Record::insert()
Am_Record::isLoaded()
Am_Record::pk()
Am_Record::refresh()
Am_Record::replace()
Am_Record::save()
Am_Record::serializeIds()
Am_Record::set()
Am_Record::setForInsert()
Am_Record::setForUpdate()
Am_Record::toArray()
Am_Record::toggleFrozen()
Am_Record::toRow()
Am_Record::unserializeIds()
Am_Record::update()
Am_Record::updateQuick()
Am_Record::updateSelectedFields()
Am_Record::_isValidField()
Am_Record::_setTable()
Am_Record::__sleep()
Am_Record::__toString()
Am_Record::__wakeup()
Class Constants
CHARGEBACK = 7 (line 69)
PAID = 1 (line 64)
PENDING = 0 (line 63)
RECURRING_ACTIVE = 2 (line 65)
RECURRING_CANCELLED = 3 (line 66)
RECURRING_FAILED = 4 (line 67)
RECURRING_FINISHED = 5 (line 68)

Documentation generated on Wed, 11 Apr 2012 09:05:14 -0400 by phpDocumentor 1.4.4