2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
14 // Price in words. $doc_type is set to document type and can be used to suppress
15 // price in words printing for selected document types.
16 // Used instead of built in simple english price_in_words() function.
18 // Returns: amount in words as string.
20 // function price_in_words($amount, $doc_type)
25 // Exchange rate currency $curr as on date $date.
26 // Keep in mind FA has internally implemented 3 exrate providers
27 // If any of them supports your currency, you can simply use function below
28 // with apprioprate provider set, otherwise implement your own.
29 // Returns: $curr value in home currency units as a real number.
31 // function retrieve_ex_rate($curr, $date)
33 // $provider = 'ECB'; // 'ECB', 'YAHOO' or 'GOOGLE'
34 // return get_extern_rate($curr, $provider, $date);
37 // Generic function called at the end of Tax Report (report 709)
38 // Can be used e.g. for special database updates on every report printing
39 // or to print special tax report footer
42 // function tax_report_done()
45 // Following database transaction hooks akcepts array of parameters:
46 // 'cart' => transaction data
47 // 'trans_type' => transaction type
49 // function db_prewrite(&$cart, $trans_type)
52 // function db_postwrite(&$cart, $trans_type)
55 // function db_prevoid($trans_type, $trans_no)
61 Calls hook $method defined in extension $ext (if any)
63 function hook_invoke($ext, &$data, $opts=null) {
67 if (isset($Hooks[$ext]) && method_exists($Hooks[$ext], $method)) {
68 $Hooks[$ext]->$method($data, $opts);
73 Calls hook $methods defined in all extensions (if any)
75 function hook_invoke_all($method, &$data, $opts=null) {
80 foreach($Hooks as $ext => $hook)
81 if (method_exists($hook, $method)) {
82 $result = $Hooks[$ext]->$method($data, $opts);
83 if (isset($result) && is_array($result)) {
84 $return = array_merge_recursive($return, $result);
85 } else if (isset($result)) {
92 Returns first non-null result returned from hook.
94 function hook_invoke_first($method, &$data, $opts=null) {
99 foreach($Hooks as $ext => $hook) {
100 if (method_exists($hook, $method)) {
101 $result = $Hooks[$ext]->$method($data, $opts);
108 //------------------------------------------------------------------------------------------
109 // Database transaction hooks.
110 // $type - type of transaction (simplifies cart processing)
111 // $cart - transaction cart
112 // $args is optional array of parameters
114 // For FA 2.3 prewrite, postwrite and prevoid hooks are implemented for following transaction types:
116 // ST_BANKPAYMENT, ST_BANKDEPOSIT, ST_BANKTRANSFER,
117 // ST_SALESORDER, ST_SALESQUOTE, ST_SALESINVOICE, ST_CUSTCREDIT, ST_CUSTPAYMENT, ST_CUSTDELIVERY,
118 // ST_LOCTRANSFER, ST_INVADJUST,
119 // ST_PURCHORDER, ST_SUPPINVOICE, ST_SUPPCREDIT, ST_SUPPAYMENT, ST_SUPPRECEIVE,
120 // ST_WORKORDER, ST_MANUISSUE, ST_MANURECEIVE,
123 Invoked after transaction has been read from database to cart.
126 //function hook_db_postread(&$cart, $type)
128 // hook_invoke_all('db_postread', $cart, $type);
132 Invoked before transaction is written to database.
134 function hook_db_prewrite(&$cart, $type)
136 hook_invoke_all('db_prewrite', $cart, $type);
140 Invoked after transaction has been written to database.
142 function hook_db_postwrite(&$cart, $type)
144 hook_invoke_all('db_postwrite', $cart, $type);
147 Invoked before transaction is voided
149 function hook_db_prevoid($type, $type_no)
151 hook_invoke_all('db_prevoid', $type, $type_no);
154 //-------------------------------------------------------------------------------------------
158 // Alternative exchange rates feeds.
160 function hook_retrieve_exrate($currency, $date)
162 return hook_invoke_first('retrieve_exrate', $currency, $date);
165 // Generic function called at the end of Tax Report (report 709)
167 function hook_tax_report_done()
169 hook_invoke_all('tax_report_done', $dummy);
172 // Amount in words displayed on various documents (especially sales invoice)
174 function hook_price_in_words($amount, $document)
176 return hook_invoke_first('price_in_words', $amount, $document);