$criteria = array('columns' => 'COUNT(*) AS overlapped', 'joins' => 'employer_fees ON employer_fees.employer = employers.id', 'match' => "employers.id = '" . $_POST['employer_id'] . "' AND \n ((salary_start = " . $_POST['salary_start'] . " OR salary_end = " . $_POST['salary_start'] . ") OR\n (salary_start = " . $_POST['salary_end'] . " OR salary_end = " . $_POST['salary_end'] . ") OR \n (salary_start < " . $_POST['salary_start'] . " AND (salary_end > " . $_POST['salary_start'] . " OR salary_end = 0)) OR\n (salary_start < " . $_POST['salary_end'] . " AND (salary_end > " . $_POST['salary_end'] . " OR salary_end = 0)))"); $result = $employer->find($criteria); if ($result[0]['overlapped'] != 0) { echo '-1'; exit; } } $data = array(); $data['guarantee_months'] = $_POST['guarantee_months']; $data['service_fee'] = $_POST['service_fee']; $data['reward_percentage'] = $_POST['reward_percentage']; $data['premier_fee'] = '0.00'; if ($_POST['id'] == '0') { $data['salary_start'] = $_POST['salary_start']; $data['salary_end'] = $_POST['salary_end']; if (!$employer->createFee($data)) { echo 'ko'; exit; } } else { $data['id'] = $_POST['id']; if (!$employer->updateFee($data)) { echo 'ko'; exit; } } echo 'ok'; exit; } if ($_POST['action'] == 'save_payment_terms') { $data = array();