+ $price = $prices[$sales_type_id][$home_curr] / $rate;
+ }
+ elseif (isset($prices[$base_id][$currency]))
+ {
+ $price = $prices[$base_id][$currency] * $factor;
+ }
+ elseif (isset($prices[$base_id][$home_curr]))
+ {
+ $price = $prices[$base_id][$home_curr] * $factor / $rate;
+ }
+
+ return $price === false ? false : round($price, user_price_dec());
+}
+//----------------------------------------------------------------------------------------
+//
+// Get price for given item or kit.
+// When $std==true price is calculated as a sum of all included stock items,
+// otherwise all prices set for kits and items are accepted.
+//
+function get_kit_price($item_code, $currency, $sales_type_id, $factor=null,
+ $date=null, $std = false)
+{
+ $kit_price = 0.00;
+ if (!$std) {
+ $kit_price = get_price( $item_code, $currency, $sales_type_id,
+ $factor, $date);
+
+ if ($kit_price !== false) {
+ return $kit_price;
+ }
+ }
+ // no price for kit found, get total value of all items
+ $kit = get_item_kit($item_code);
+
+ while($item = db_fetch($kit)) {
+ if ($item['item_code'] != $item['stock_id']) {
+ // foreign/kit code
+ $kit_price += $item['quantity'] * get_kit_price( $item['stock_id'],
+ $currency, $sales_type_id, $factor, $date, $std);
+
+ } else {
+ // stock item
+ $kit_price += $item['quantity'] * get_price( $item['stock_id'],
+ $currency, $sales_type_id, $factor, $date);
+ }
+ }
+ return $kit_price;
+}
+
+//-----------------------------------------------------------------------------
+
+function set_document_parent($cart)
+{
+ $inv_no = key($cart->trans_no);
+
+ if (count($cart->src_docs) == 1) {
+
+ // if this child document has only one parent - update child link
+ $del_no = reset(array_keys($cart->src_docs));
+
+ $sql = 'UPDATE '.TB_PREF.'debtor_trans SET trans_link = ' . $del_no .
+ ' WHERE type='.$cart->trans_type.' AND trans_no='. $inv_no ;
+ db_query($sql, 'Child document link cannot be updated');
+
+ }
+ if ($cart->trans_type != 10)