+//--------------------------------------------------------------------------------------------------
+function get_parent_type($type)
+{
+ $parent_types = array( 11=>10, 10=>13, 13=>30 );
+ return isset($parent_types[$type]) ? $parent_types[$type] : 0;
+}
+
+//--------------------------------------------------------------------------------------------------
+function update_parent_line($doc_type, $line_id, $qty_dispatched)
+{
+ $doc_type = get_parent_type($doc_type);
+
+ //echo "update line: $line_id, $doc_type, $qty_dispatch";
+ if ($doc_type==0)
+ return false;
+ else {
+ if ($doc_type==30)
+ $sql = "UPDATE ".TB_PREF."sales_order_details
+ SET qty_sent = qty_sent + $qty_dispatched
+ WHERE id=$line_id";
+ else
+ $sql = "UPDATE ".TB_PREF."debtor_trans_details
+ SET qty_done = qty_done + $qty_dispatched
+ WHERE id=$line_id";
+ }
+ db_query($sql, "The parent document detail record could not be updated");
+ return true;
+}
+
+//--------------------------------------------------------------------------------------------------
+// find inventory location for given transaction
+//
+function get_location(&$cart)
+{
+ $sql = "SELECT ".TB_PREF."locations.* FROM ".TB_PREF."stock_moves,"
+ .TB_PREF."locations".
+ " WHERE type=".$cart->trans_type.
+ " AND trans_no=".key($cart->trans_no).
+ " AND qty!=0 ".
+ " AND ".TB_PREF."locations.loc_code=".TB_PREF."stock_moves.loc_code";
+ $result = db_query($sql, 'Retreiving inventory location');
+
+
+ if (db_num_rows($result)) {
+ return db_fetch($result);
+ }
+ return null;
+}
+//--------------------------------------------------------------------------------------------------
+// Generic read debtor transaction into cart
+//
+// $trans_no - array of trans nums; special case trans_no==0 - new doc
+//
+function read_sales_trans($doc_type, $trans_no, &$cart)
+{
+ if (!is_array($trans_no) && $trans_no)
+ $trans_no = array($trans_no);
+
+ $cart->trans_type = $doc_type;
+ if (!$trans_no) { // new document
+ $cart->trans_no = $trans_no;
+ } else {
+ // read header data from first document
+ $myrow = get_customer_trans($trans_no[0],$doc_type);
+ if (count($trans_no)>1)
+ $cart->trans_no = get_customer_trans_version($doc_type, $trans_no);
+ else
+ $cart->trans_no = array($trans_no[0]=>$myrow["version"]);
+
+ $cart->set_sales_type($myrow["tpe"], $myrow["sales_type"], $myrow["tax_included"],0);
+
+ $cart->set_customer($myrow["debtor_no"], $myrow["DebtorName"],
+ $myrow["curr_code"], $myrow["discount"]);
+
+ $cart->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
+ $myrow["tax_group_name"], $myrow["phone"], $myrow["email"]);
+
+ $cart->reference = $myrow["reference"];
+ $cart->order_no = $myrow["order_"];
+ $cart->trans_link = $myrow["trans_link"];
+ $cart->due_date = sql2date($myrow["due_date"]);
+ $cart->document_date = sql2date($myrow["tran_date"]);