$smarty->assign('confirmation', 'Y');
    }
} elseif ($action == "cancel") {
    $smarty->assign('message', 'cancel');
    unset($aom_orders[$doc_id]);
    cw_header_location("index.php?target={$target}&doc_id={$doc_id}&mode=edit");
}
if (cw_session_is_registered("message")) {
    $message =& cw_session_register("message");
    $smarty->assign('message', $message);
    cw_session_unregister("message");
}
$customer_membership_id = $aom_orders[$doc_id]['userinfo']['membership_id'];
if ($action == 'update_customer' && !$aom_orders[$doc_id]['saved'] && in_array(AREA_TYPE, array('P', 'A', 'G', 'B'))) {
    if ($customer_info['customer_id'] != $aom_orders[$doc_id]['userinfo']['customer_id']) {
        cw_aom_update_customer($aom_orders[$doc_id], $customer_info['customer_id']);
    } else {
        if ($customer_info['main_address']['address_id']) {
            $customer_info['main_address'] = cw_user_get_address($customer_info['customer_id'], $customer_info['main_address']['address_id']);
        }
        if ($customer_info['current_address']['address_id']) {
            $customer_info['current_address'] = cw_user_get_address($customer_info['customer_id'], $customer_info['current_address']['address_id']);
        }
        $aom_orders[$doc_id]['userinfo'] = cw_doc_prepare_user_information($customer_info, $aom_orders[$doc_id]['userinfo']);
    }
    cw_header_location("index.php?target={$target}&doc_id={$doc_id}&mode=edit&js_tab=customer");
}
if ($action == 'update_customer' && $aom_orders[$doc_id]['type'] == 'O' && in_array(AREA_TYPE, array('C'))) {
    if ($customer_info['main_address']['address_id']) {
        $customer_info['main_address'] = cw_user_get_address($customer_info['customer_id'], $customer_info['main_address']['address_id']);
    }
    }
    if (!$aom_orders[$doc_id]['pos']['paid_by_cc']) {
        if ($aom_orders[$doc_id]['pos']['payment']) {
            $aom_orders[$doc_id]['pos']['change'] = $aom_orders[$doc_id]['pos']['payment'] - $aom_orders[$doc_id]['info']['total'];
        }
    } else {
        $aom_orders[$doc_id]['pos']['payment'] = $aom_orders[$doc_id]['pos']['change'] = 0;
    }
}
if ($action == 'update_warehouse' && $warehouse_info && AREA_TYPE == 'A') {
    if ($aom_orders[$doc_id]['type'] == 'D') {
        $aom_orders[$doc_id]['info']['company_id'] = $warehouse_info['company_id'];
        cw_aom_update_warehouse($aom_orders[$doc_id], $warehouse_info['customer_id']);
        cw_aom_update_customer($aom_orders[$doc_id], $warehouse_info['dest_customer_id']);
        if ($aom_orders[$doc_id]['info']['warehouse_customer_id'] == $aom_orders[$doc_id]['userinfo']['customer_id']) {
            cw_aom_update_customer($aom_orders[$doc_id], 0);
            $top_message = array('content' => cw_get_langvar_by_name('lbl_dest_source_equals'), 'type' => 'E');
        }
    } else {
        $aom_orders[$doc_id]['info']['company_id'] = $warehouse_info['company_id'];
        cw_aom_update_warehouse($aom_orders[$doc_id], $warehouse_info['customer_id']);
    }
}
if ($action && $aom_orders[$doc_id]['saved']) {
    $error_message = cw_get_langvar_by_name('txt_aom_already_printed');
}
if ($action == 'save_doc' && !$aom_orders[$doc_id]['saved']) {
    if ($aom_orders[$doc_id] && $aom_orders[$doc_id]['info']['total'] >= 0 && count($aom_orders[$doc_id]['products'])) {
        if ($aom_orders[$doc_id]['type'] == 'G' && $config['pos']['is_use_printer'] != 'Y' && AREA_TYPE == 'G') {
            $aom_orders[$doc_id]['type'] = 'I';
        }