Пример #1
0
if (!isset($sugarbean->product_id) || is_null($sugarbean->product_id) || empty($sugarbean->product_id)) {
    $product = new Products();
    $product->account_id = $_REQUEST['account_id'];
    $product->account_name = $_REQUEST['account_name'];
    $product->contact_id = $_REQUEST['contact_id'];
    $product->contact_name = $_REQUEST['contact_name'];
    $product->name = $_REQUEST['product_name'];
    $product->number = 'PRD' . $product->generate_number('number', $product->table_name);
    //TO DO GENERATE NUMBER
    $product->save($GLOBALS['check_notify']);
    $sugarbean->product_id = $product->id;
} else {
    $product = new Products();
    $product->retrieve($sugarbean->product_id);
}
$sugarbean->save($GLOBALS['check_notify']);
$product->clientorder_id = $sugarbean->id;
$product->save($GLOBALS['check_notify']);
$sugarbean->save($GLOBALS['check_notify']);
if (isset($_REQUEST['add_component']) && $_REQUEST['add_component'] != "") {
    $_REQUEST['return_url'] = 'index.php?module=EstimateComponents&action=EditView&return_module=' . $_REQUEST['parent_bean'] . '&add_component=true&return_id=' . $sugarbean->id . '&return_action=EditView&parent_id=' . $sugarbean->id . '&parent_name=' . $sugarbean->name . '&parent_bean=' . $_REQUEST['parent_bean'];
}
//$sugarbean->status_update('',$sugarbean->id);
$return_id = $sugarbean->id;
$productstatus = new ProductStatus();
if (isset($_REQUEST['status_action']) && !empty($_REQUEST['status_action'])) {
    $productstatus->update_product_status($_REQUEST['status_action'], $sugarbean, $old_status);
} else {
    $productstatus->update_product_status($_REQUEST['status'], $sugarbean, $old_status);
}
handleRedirect($return_id, 'ClientOrders');
    //To Do: add operations
    //Transport
    //Pack
    $Estimates->save($GLOBALS['check_notify']);
    $Components = new EstimateComponents();
    $components_array = $Components->get_full_list("id", "parent_id='" . $ClientRequest->id . "'");
    for ($i = 0; $i < count($components_array); $i++) {
        $EstimateComponents = new EstimateComponents();
        $fields = $components_array[$i]->column_fields;
        foreach ($fields as $field) {
            $EstimateComponents->{$field} = $components_array[$i]->{$field};
        }
        $EstimateComponents->id = null;
        $EstimateComponents->date_entered = null;
        $EstimateComponents->date_modified = null;
        $EstimateComponents->created_by = null;
        $EstimateComponents->modified_user_id = null;
        $EstimateComponents->assigned_user_id = null;
        $EstimateComponents->assigned_user_name = null;
        $EstimateComponents->parent_bean = 'Estimates';
        $EstimateComponents->parent_id = $Estimates->id;
        $EstimateComponents->parent_name = $Estimates->name;
        $EstimateComponents->number = $EstimateComponents->generate_number('number', 'estimates_components', $Estimates->id, $Estimates->table_name);
        $EstimateComponents->save($GLOBALS['check_notify']);
    }
}
$productstatus = new ProductStatus();
if (isset($_REQUEST['status_action']) && !empty($_REQUEST['status_action'])) {
    $productstatus->update_product_status($_REQUEST['status_action'], $Estimates);
}
handleRedirect($Estimates->id, 'Estimates');
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'modules/Quotes/Quote.php';
     require_once 'modules/QuoteLines/QuoteLine.php';
     require_once 'log4php/LoggerManager.php';
     require_once 'include/formbase.php';
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $focus = new Quote();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (!ACLController::checkAccess($focus->module_dir, 'edit', $focus->isOwner($current_user->id))) {
         ACLController::displayNoAccess(true);
     }
     ///// Retrive old status ///////
     $old_bean = new Products();
     $old_bean->retrieve($focus->product_id);
     $old_status = $old_bean->status;
     //////////////////////////////
     /*	if(empty($_REQUEST['status']) || $_REQUEST['status'] == 'off'){
     		$focus->status = 0;	
     	}else{
     		$focus->status= 1;
     	}
     	
     	echo "post length:".count($_POST); 
         echo "product_count:".$count."<br>";
     	echo "cost_price num:".count($_POST["cost_price"])."<br";*/
     $return_id = $focus->save();
     /*$quoteLine1 = new QuoteLine();
     	$quoteLine1->mark_deletedByQuoteid($return_id);
     	$count = count($_POST);
     	$keys = array_keys($_POST);
     	$sum = 0;
     	for($i = 0;$i< $count; $i++) {
     		//echo $keys[$i]."<br>";
     		if(substr_count($keys[$i],"productid_") > 0) {
     			$index = substr($keys[$i],strpos($keys[$i],"_")+1);
     			$product_id = $_POST["productid_".$index];
     			
     			if(!isset($product_id) || empty($product_id))
     				continue;
     			
     			$product_name = $_POST["productname_".$index];
     			$product_num = $_POST["productnum_".$index];
                 $pages = $_POST["pages_".$index];
      			$quantity = $_POST["quantity_".$index];
                 $estp = $_POST["estp_".$index];
                 $price = $_POST["price_".$index];     
                 
     			$quoteLine = new QuoteLine();
                 $quoteLine->price = $price;
                 $quoteLine->estp = $estp;
                 $quoteLine->productid = $product_id;
                 $quoteLine->productname = $product_name;
                 $quoteLine->productnum = $product_num;
                 $quoteLine->pages = $pages;
     			$quoteLine->quantity = $quantity;
     			$quoteLine->quoteid = $return_id;
     			$quoteLine->save();
     		}
     	}
     	$count = $_POST["product_count"];*/
     /*	$component = new ProductComponents;
     	$component->retrieve($sugarbean->component_id);
     	$component->status_update('quoted', $component->id);*/
     //	$GLOBLES['log']->debug("Saved record with id of ".$return_id);
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
     $productstatus = new ProductStatus();
     if (isset($_REQUEST['status_action']) && !empty($_REQUEST['status_action'])) {
         $productstatus->update_product_status($_REQUEST['status_action'], $focus, $old_status);
     } else {
         $productstatus->update_product_status($_REQUEST['status'], $focus, $old_status);
     }
 }
    //To Do: add operations
    //Transport
    //Pack
    $ClientOrders->save($GLOBALS['check_notify']);
    $Components = new ClientorderComponents();
    $components_array = $Components->get_full_list("id", "parent_id='" . $ClientRequest->id . "'");
    for ($i = 0; $i < count($components_array); $i++) {
        $ClientorderComponents = new ClientorderComponents();
        $fields = $components_array[$i]->column_fields;
        foreach ($fields as $field) {
            $ClientorderComponents->{$field} = $components_array[$i]->{$field};
        }
        $ClientorderComponents->id = null;
        $ClientorderComponents->date_entered = null;
        $ClientorderComponents->date_modified = null;
        $ClientorderComponents->created_by = null;
        $ClientorderComponents->modified_user_id = null;
        $ClientorderComponents->assigned_user_id = null;
        $ClientorderComponents->assigned_user_name = null;
        $ClientorderComponents->parent_bean = 'ClientOrders';
        $ClientorderComponents->parent_id = $ClientOrders->id;
        $ClientorderComponents->parent_name = $ClientOrders->name;
        $ClientorderComponents->number = $ClientorderComponents->generate_number('number', 'clientorders_components', $ClientOrders->id, $ClientOrders->table_name);
        $ClientorderComponents->save($GLOBALS['check_notify']);
    }
}
$productstatus = new ProductStatus();
if (isset($_REQUEST['status_action']) && !empty($_REQUEST['status_action'])) {
    $productstatus->update_product_status($_REQUEST['status_action'], $ClientOrders);
}
handleRedirect($ClientOrders->id, 'ClientOrders');