-//------------------------------------------------------------------------------
-// Retreive parent document number(s) for given transaction
-//
-function get_parent_trans($trans_type, $trans_no) {
-
- $sql = 'SELECT trans_link FROM
- '.TB_PREF.'debtor_trans WHERE
- (trans_no='.db_escape($trans_no).' AND type='.db_escape($trans_type).' AND trans_link!=0)';
-
- $result = db_query($sql, 'Parent document numbers cannot be retrieved');
-
- if (db_num_rows($result)) {
- $link = db_fetch($result);
- return array($link['trans_link']);
- }
- if ($trans_type!=ST_SALESINVOICE) return 0; // this is credit note with no parent invoice
- // invoice: find batch invoice parent trans.
- $sql = 'SELECT trans_no FROM
- '.TB_PREF.'debtor_trans WHERE
- (trans_link='.db_escape($trans_no).' AND type='. get_parent_type($trans_type) .')';
-
- $result = db_query($sql, 'Delivery links cannot be retrieved');
-
- $delivery = array();
- if(db_num_rows($result)>0) {
- while($link = db_fetch($result)) {
- $delivery[] = $link['trans_no'];
- }
- }
- return count($delivery) ? $delivery : 0;
-}
-