From 5697e7985b3c88067f9ecfaf21bf9afb666a775f Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 1 Aug 2012 22:34:59 +1000 Subject: [PATCH] Fixes for export --- modules/export/classes/export/quicken.php | 30 ++++++++++++++++++--- modules/invoice/classes/model/invoice.php | 13 +++++++++ modules/invoice/views/invoice/user/view.php | 4 +++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/modules/export/classes/export/quicken.php b/modules/export/classes/export/quicken.php index 4b438f55..fc0b7813 100644 --- a/modules/export/classes/export/quicken.php +++ b/modules/export/classes/export/quicken.php @@ -93,9 +93,8 @@ class Export_Quicken extends Export { ->find(); if ($eo->loaded()) { - $map_data = unserialize($eo->map_data); - $qto->ACCNT = $map_data['account']; - $qto->INVITEM = $map_data['item']; + $qto->ACCNT = $eo->map_data['account']; + $qto->INVITEM = $eo->map_data['item']; } else { throw new Kohana_Exception('Missing product map data for :product (:id)', @@ -112,7 +111,7 @@ class Export_Quicken extends Export { $qto->ACCNT = 'Other Income'; $qto->INVITEM = 'Unknown'; $qto->MEMO = sprintf('%s (%s)', - $iio->product->product_translate->find()->name,$daterange); + $iio->product->product_translate->find()->name,$daterange); } $qto->CLEAR = 'N'; @@ -135,6 +134,29 @@ class Export_Quicken extends Export { $qio->addInvoiceItem($qto); } + // Add credits as a other item + $qto = new Quicken_InvoiceItem; + $qto->ACCNT = 'Other Income'; + $qto->INVITEM = 'Product:Unknown'; + $qto->CLEAR = 'N'; + $qto->QNTY = 1; + $qto->MEMO = 'Credit Item'; + + if ($pio->invoice->tax()) { + $qto->TAXABLE = 'Y'; + # @todo, get this from OSB + $qto->TAXCODE = 'GST'; + $qto->TAXRATE = sprintf('%3.2f%%','0.10'); + $tax = round($pio->invoice->credit_amt/11,2); + $qto->TAXAMOUNT = sprintf('%3.2f',$tax); + } else { + $qto->TAXAMOUNT = 0; + } + + $qto->PRICE = sprintf('%3.2f',round(($pio->invoice->credit_amt-$tax)*-1,2)); + $qto->AMOUNT = sprintf('%3.2f',round(($pio->invoice->credit_amt-$tax),2)); + $qio->addInvoiceItem($qto); + $qo->addInvoice($qio); } } diff --git a/modules/invoice/classes/model/invoice.php b/modules/invoice/classes/model/invoice.php index 61662ae4..0d35fa6f 100644 --- a/modules/invoice/classes/model/invoice.php +++ b/modules/invoice/classes/model/invoice.php @@ -117,6 +117,19 @@ class Model_Invoice extends ORMOSB { return $format ? Currency::display($result) : Currency::round($result); } + public function credits() { + return array($this); + } + + public function credits_total($format=FALSE) { + $result = 0; + + foreach ($this->credits() as $po) + $result += $po->credit_amt; + + return $format ? Currency::display($result) : Currency::round($result); + } + public function discount($format=FALSE) { $result = 0; diff --git a/modules/invoice/views/invoice/user/view.php b/modules/invoice/views/invoice/user/view.php index 82f46c69..1692f0b0 100644 --- a/modules/invoice/views/invoice/user/view.php +++ b/modules/invoice/views/invoice/user/view.php @@ -39,6 +39,10 @@ Payments Received to Date payments_total(TRUE); ?> + + Credits Applied to Date + credits_total(TRUE); ?> + Total Charges Due This Invoice due(TRUE); ?>