<?php //
/**********************************************************************
***********************************************************************/

function save_est_boq_group_to_sys_project($est_boq_group, $project_id)
{

    if(isset($est_boq_group['id']) && $est_boq_group['id'] > 0 ){
        update_project_boq_item_groups($est_boq_group['id'], $est_boq_group['code'], 
                                       $est_boq_group['description'], $est_boq_group['display_order'], $est_boq_group['parent_id'] );
        $boq_group_id = $est_boq_group['id'];
    }
    else{
        $boq_group_id = add_project_boq_item_groups($project_id, $est_boq_group['code'], 
                                    $est_boq_group['description'], $est_boq_group['display_order'], $est_boq_group['parent_id']);
    }
    return array("success"=>true, "trans_no"=>$boq_group_id, "message"=>"");  
}
    
    
function save_est_boq_item_to_sys_boq_item($est_boq_item, $project_id)
{
    
    if(isset($est_boq_item['id']) && $est_boq_item['id'] > 0 ){
        update_project_boq_item($est_boq_item['id'], $est_boq_item['display_order'], $est_boq_item['type_id'], $est_boq_item['code'], $est_boq_item['description'], 
                            $est_boq_item['billing_type'], $est_boq_item['unit'], $est_boq_item['rate'], $est_boq_item['max_quantity'], 
                            $est_boq_item['long_description'], $est_boq_item['print_long_description'], $est_boq_item['tax_group_id'], $est_boq_item['group_id']);
        return $est_boq_item['id'];
    }
    else{
        return add_project_boq_item($project_id, $est_boq_item['type_id'], $est_boq_item['display_order'], $est_boq_item['code'], $est_boq_item['description'], 
                             $est_boq_item['billing_type'], $est_boq_item['unit'], $est_boq_item['rate'],  $est_boq_item['max_quantity'], 
                             $est_boq_item['long_description'], $est_boq_item['print_long_description'], $est_boq_item['tax_group_id'],  $est_boq_item['group_id']);
    }
}

function save_est_boq_item_component_to_sys_boq_item_component($boq_item_component)
{
    
    if(isset($boq_item_component['id']) && $boq_item_component['id'] > 0 ){

//        update_project_boq_item_component($boq_item_component['id'], $boq_item_component['boq_item_id'], $boq_item_component['detail_type_code'],
//                                          $boq_item_component['primary_type'], $boq_item_component['cost'], $boq_item_component['row_state']);
        return $boq_item_component['id'];
    }
    else{
//        return add_project_boq_item_component($boq_item_component['boq_item_id'], $boq_item_component['detail_type_code'], $boq_item_component['primary_type'], 
//                                       $boq_item_component['cost'], $boq_item_component['row_state']);
        return create_boq_item_component_record($boq_item_component['boq_item_id'], $boq_item_component['detail_type_code'], $boq_item_component['primary_type']);


    }
    
}

//function save_est_boq_item_component_detail_to_sys_boq_item_component_detail($boq_item_component_detail, $type)
//{
//    switch ($type) {
//        case 'COST':
//            if(isset($boq_item_component_detail['id']) && $boq_item_component_detail['id'] > 0 ){
//
//                save_boq_item_cost($boq_item_component_detail['id'], $boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//            else{
//                add_boq_item_cost($boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//
//            break;
//            
//        case 'MATERIAL':
//            if(isset($boq_item_component_detail['id']) && $boq_item_component_detail['id'] > 0 ){
//
//                save_boq_item_cost($boq_item_component_detail['id'], $boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//            else{
//                add_boq_item_cost($boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//
//            break;
//            
//        case 'ASSET':
//            if(isset($boq_item_component_detail['id']) && $boq_item_component_detail['id'] > 0 ){
//
//                save_boq_item_cost($boq_item_component_detail['id'], $boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//            else{
//                add_boq_item_cost($boq_item_component_detail['boq_item_id'], $boq_item_component_detail['detail_type_code'], 
//                                   $boq_item_component_detail['description'], $boq_item_component_detail['cost'], $boq_item_component_detail['comment']);
//            }
//
//            break;
//
//        default:
//            break;
//    }
//    
//    
//}









?>
































































































































