+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
+ This program 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 License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+//------------------------------------------------------------------------------
+// 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=' .$trans_no. ' AND type='.$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='.$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;
+}
+
+//----------------------------------------------------------------------------------------
+// Mark changes in debtor_trans_details
+//
+function update_customer_trans_version($type, $versions) {
+
+ $sql= 'UPDATE '.TB_PREF. 'debtor_trans SET version=version+1
+ WHERE type='.$type. ' AND (';
+
+ foreach ($versions as $trans_no=>$version)
+ $where[] = '(trans_no='.$trans_no.
+ ' AND version='.$version.')';
+
+ $sql .= implode(' OR ', $where) .')';
+
+ return db_query($sql, 'Concurrent editing conflict');
+}