public function AdjustPOItem($data = array()) { if ($data && is_array($data)) { foreach ($data['quantity_list'] as $key => $val) { //debug(strripos($key, 'cabinet')); if (strripos($key, 'cabinet')) { $id = explode('|', $key); //debug($id); App::uses("Cabinet", "Inventory.Model"); $list_Item = new Cabinet(); $query = "SELECT i.id as id, i.number as number, i.item_title as title, i.price as price, ci.item_quantity as quantity FROM cabinets_items as ci INNER JOIN items as i ON i.id=ci.item_id WHERE ci.cabinet_id={$id['0']}"; $list_data = $list_Item->query($query); //debug($list_data); foreach ($list_data as $row) { $tmp_key = $row['i']['id'] . '|item'; if (array_key_exists($tmp_key, $data['quantity_list'])) { $data['quantity_list'][$tmp_key] = $data['quantity_list'][$tmp_key] + $row['ci']['quantity'] * $val; } else { $data['quantity_list'] = array_merge($data['quantity_list'], array($tmp_key => $row['ci']['quantity'] * $val)); $data['name_list'] = array_merge($data['name_list'], array($tmp_key => $row['ci']['number'])); $data['price_list'] = array_merge($data['price_list'], array($tmp_key => $row['ci']['price'])); $data['title_list'] = array_merge($data['title_list'], array($tmp_key => $row['ci']['title'])); } unset($data['quantity_list'][$key]); unset($data['name_list'][$key]); unset($data['price_list'][$key]); unset($data['title_list'][$key]); } } } } return $data; }