<?php	
	require_once("../includes/config.php");
	$ac = new DbQuery();
    $ac->checkLogin();
    if(isset($_POST) && $_POST['action']=='save-sell-record' )
	{
	   $row = false;
	    if(isset($_POST['calculated_data'])){
	        $param = $params = array();
	        foreach($_POST['calculated_data'] as $value){
	            $param = array(	
					'table' => 'sell',
					'get'   =>'*',
					'where' => array('calculated_data'=> $value),
				);

				$select = $ac->select($param,'get_row');
				 $params['table'] = 'sell';
				 $params['field']['calculated_data'] = $value;
	            if($select)
				{
				    $params['where']['ID'] = $select['ID'];
					$row = $ac->update($params);
				}
				else
				{
					$row = $ac->insert($params);
				}
	        }
	    }
	    if($row){
			$_SESSION['success'] = $ac->getMessage('SUC_MSG');
			header('location:'.ROOT.'po-requests.php');
			die();
		}
		else{
		    $_SESSION['failed'] = $ac->getMessage('INS_ERR_MSG');
			header('location:'.ROOT.'po-requests.php');
			die();
		}
	}
	if(isset($_POST) && $_POST['action']=='delete_sell' )
	{
	    $params = array(	
		  'table' => 'sell',
		  'where' => array('calculated_data'=>$_POST['sell_id'])
		);
		$row = $ac->delete($params);
		if($row)
		{
		    echo true;
		    die;
		}
		else
		{
		    echo false;
		    die;
		}
	}
?>