global $app_strings;
global $app_list_strings;
global $current_language;
global $current_user;
global $sugar_version, $sugar_config;
$focus = new EstimateCalc();
if (!empty($_REQUEST['record'])) {
    $focus->retrieve($_REQUEST['record']);
}
$precalc = null;
if (isset($_REQUEST['precalc']) && !empty($_REQUEST['precalc'])) {
    $precalc = $_REQUEST['precalc'];
}
if (!empty($_REQUEST['estimate_id']) && isset($_REQUEST['estimate_id']) && !is_null($_REQUEST['estimate_id'])) {
    $estimate_id = $_REQUEST['estimate_id'];
    $components_estimate = $focus->componentsEstimate($estimate_id);
} elseif (isset($focus->estimate_id) && !is_null($focus->estimate_id)) {
    $estimate_id = $focus->estimate_id;
    $components_estimate = $focus->componentsEstimate($estimate_id);
} else {
    exit;
}
if (!empty($_REQUEST['estimate_name']) && isset($_REQUEST['estimate_name']) && !is_null($_REQUEST['estimate_name'])) {
    $estimate_name = $_REQUEST['estimate_name'];
}
echo "\n<p>\n";
echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME'] . ": " . $focus->name, true);
echo "\n</p>\n";
global $theme;
$theme_path = "themes/" . $theme . "/";
$image_path = $theme_path . "images/";
        $componentEstimate->press_rate_a_machine = $pressestimate['press_rate'][0]['machine'];
        $componentEstimate->press_rate_b_inks = $pressestimate['press_rate'][1]['colors'];
        $componentEstimate->press_rate_b_machine = $pressestimate['press_rate'][1]['machine'];
        $componentEstimate->assigned_user_id = $current_user->id;
        $componentEstimate->press_paperwaste_rate_id = $paperestimate['press_paperwaste_rate']['id'];
        $componentEstimate->press_paperwaste_rate_name = $paperestimate['press_paperwaste_rate']['name'];
        $componentEstimate->press_paperwaste_rate_machine = $paperestimate['press_paperwaste_rate']['machine'];
        $componentEstimate->save($GLOBALS['check_notify']);
    }
    ///////////
    $estimateCalc = new EstimateCalc();
    $estimatecalc_id = $focus->get_calc_record($focus->id);
    if (!is_null($estimatecalc_id) && !empty($estimatecalc_id)) {
        $estimateCalc->retrieve($estimatecalc_id);
    }
    $components_estimate = $estimateCalc->componentsEstimate($focus->id);
    $estimateCalc->name = $mod_strings['LBL_EST_NAME_PREFIX'] . "-" . $focus->name;
    $estimateCalc->estimate_name = $focus->name;
    $estimateCalc->estimate_id = $focus->id;
    $estimateCalc->total_paper = $components_estimate['total_paper'];
    $estimateCalc->total_prepress = $components_estimate['total_prepress'];
    $estimateCalc->total_press = $components_estimate['total_press'];
    $estimateCalc->total_operations = $components_estimate['total_operations'];
    $estimateCalc->total_estimate = $components_estimate['total'];
    $estimateCalc->assigned_user_id = $current_user->id;
    $estimateCalc->status = 'uptodate';
    $estimateCalc->save($GLOBALS['check_notify']);
    $focus->sub_status = 'estimated';
    $focus->save($GLOBALS['check_notify']);
    header("Location: index.php?action=DetailView&module=EstimateCalc&record={$estimateCalc->id}");
}