}
    if (!empty($cart['info']['quote_doc_id'])) {
        // Change invoice status to "paid"
        $doc_id = $cart['info']['quote_doc_id'];
        $status = 'C';
        cw_call('cw_doc_change_status', array($doc_id, $status));
        // Make relation
        $doc_data = cw_call('cw_doc_get', array($doc_id));
        foreach ($doc_ids as $relation_doc_id) {
            if ($doc_data['products']) {
                foreach ($doc_data['products'] as $v) {
                    $rel_item_id = $v['item_id'];
                    if (!is_numeric($relation_doc_id)) {
                        $relation_doc_id = cw_doc_make_relation_doc('O', $doc_id, $rel_item_id, $v['amount'], 0, 1);
                    } else {
                        cw_doc_make_relation($relation_doc_id, $rel_item_id, $v['amount']);
                    }
                    cw_doc_recalc($relation_doc_id);
                }
            }
            if ($doc_data['giftcerts'] && is_numeric($relation_doc_id)) {
                cw_doc_make_related_doc($doc_id, $relation_doc_id);
            }
        }
    }
    $secure_oid = $doc_ids;
} else {
    $doc_ids = $secure_oid;
}
cw_session_save();
if ($action == 'request_for_quote') {
function cw_doc_make_relation_doc($type, $doc_id, $item_id = 0, $amount = 0, $cause_id = 0, $is_full = false)
{
    global $tables, $config;
    $old_doc = cw_query_first("select date, doc_info_id, prefix, display_id from {$tables['docs']} where doc_id='{$doc_id}'");
    $add_info = cw_query_first("select warehouse_customer_id, cause_id from {$tables['docs_info']} where doc_info_id='{$old_doc['doc_info_id']}'");
    if ($is_full) {
        $add_info = cw_query_first("select warehouse_customer_id from {$tables['docs_info']} where doc_info_id='{$old_doc['doc_info_id']}'");
        $docs_user_info = cw_query_first("select * from {$tables['docs_user_info']} where doc_info_id='{$old_doc['doc_info_id']}'");
    }
    if ($cause_id) {
        $add_info['cause_id'] = $cause_id;
        $docs_causes = array('invoice_id' => $old_doc['display_id'], 'invoice_date' => strftime($config['Appearance']['date_format'], $old_doc['date']));
    }
    $doc_id = cw_doc_create_empty($type, array(), $old_doc['prefix'], array('docs_info' => $add_info, 'docs_causes' => $docs_causes, 'docs_user_info' => $docs_user_info));
    if ($item_id) {
        cw_doc_make_relation($doc_id, $item_id, $amount);
    }
    cw_doc_recalc($relation_doc_id);
    return $doc_id;
}