* Easyshop is a web shop system */ include_once './core/incomming_goods.class.php'; include_once './core/vendor.class.php'; class admin_incomming_goods_editor { private $base_object; private $layout_object; private $incomming_goods_object; function __construct($base_object, $layout_object) { $this->base_object = $base_object; $this->layout_object = $layout_object; $this->incomming_goods_object = new Incomming_goods($base_object); } // end __construct function run() { if (isset($_GET['action'])) { $action = $_GET['action']; } elseif (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = false; } if (isset($_GET['id'])) { $id = $_GET['id']; } elseif (isset($_POST['id'])) { $id = $_POST['id']; } else { $id = false; } if ($action == "get_tab") { $this->get_tab($id); } elseif ($action == "view_stat") { $this->view_stat($id); } elseif ($action == "update") { if (!$id) { $id = $this->incomming_goods_object->create_new(); } $this->update($id); } elseif ($action == "add_item") { $this->add_item($id); } elseif ($action == "upload_bill") { $this->upload_bill($id); } elseif ($action == "delete_bill_file") { $this->delete_bill_file($id); } elseif ($action == "delete_item") { $this->delete_item($id); } else { return $this->setup_list($id); } } // end run private function setup_list($id) { $today = ''; if ($id) { $data = $this->incomming_goods_object->get_by_id($id); if ($data) { $this->layout_object->assign('form_data', $data); $today = substr($data->date,8,2).'.'.substr($data->date,5,2).'.'.substr($data->date,0,4); } else { $this->layout_object->assign('error_message', "Dieser Wareneingang existiert nicht."); } } else { // get today date $today = date("d.m.Y", time()); } $this->layout_object->assign('today', $today); return $this->layout_object->fetch('admin_incomming_goods_editor.tpl'); } // end default_action private function view_stat($id) { if ($id) { $data = $this->incomming_goods_object->get_by_id($id); $data->item_list = array_reverse($data->item_list); if ($data) { $this->layout_object->assign('form_data', $data); $today = substr($data->date,8,2).'.'.substr($data->date,5,2).'.'.substr($data->date,0,4); } else { $this->layout_object->assign('error_message', "Es ist ein Fehler aufgetreten."); } } elseif(!$id && $_POST['date']) { $date = substr($_POST['date'],6,4).'-'.substr($_POST['date'],3,2).'-'.substr($_POST['date'],0,2); $id = $this->incomming_goods_object->get_id_by_date($date); if(!$id) { $id = $this->incomming_goods_object->create_new($date); } // get data $data = $this->incomming_goods_object->get_by_id($id); if ($data) { $this->layout_object->assign('form_data', $data); $today = substr($data->date,8,2).'.'.substr($data->date,5,2).'.'.substr($data->date,0,4); } else { $this->layout_object->assign('error_message', "Es ist ein Fehler aufgetreten."); } } //$data = $this->incomming_goods_object->get_by_id($id); // get vendors $vendor_object = new Vendor($this->base_object); $data->vendors = $vendor_object->get_all(); if ($data) { $this->layout_object->assign('form_data', $data); } else { $this->layout_object->assign('error_message', "Es ist ein Fehler aufgetreten."); } echo $this->layout_object->fetch('admin_incomming_goods_view.tpl'); exit(); } // only used in ajax, so i terminate with exit private function update($id) { $data = array(); $item_amount = $_POST['item_amount']; $item_price_sum = str_replace(',','.',$_POST['item_price_sum']); $item_id = $_POST['item_id']; $data['items'] = array(); for ($i=0;$i < count($item_id);$i++) { $data['items'][] = array( 'item_id' => $item_id[$i], 'amount' => $item_amount[$i], 'price_sum' => $item_price_sum[$i] ); } if (isset($_POST['number'])) { $data['number'] = $_POST['number']; $data['vendor_id'] = $_POST['vendor_id']; $data['date'] = substr($_POST['date'],6,4).'-'.substr($_POST['date'],3,2).'-'.substr($_POST['date'],0,2); $data['skonto'] = $_POST['skonto']; $data['eg_nr'] = $_POST['eg_nr']; $data['cost_sum'] = str_replace(',','.',$_POST['cost_sum']); $data['import'] = $_POST['import']; $data['currency'] = $_POST['currency']; $data['conversion_price'] = str_replace(',','.',$_POST['conversion_price']); if ($data['id'] == '') { unset($data['id']); } $this->incomming_goods_object->set_id($id); $result = $this->incomming_goods_object->update($data); if ($result) { $return = array('status' => 'success', 'id' => $id); } else { $return = array('status' => 'error', 'message' => 'save failed'); } } else { $return = array('status' => 'error', 'message' => 'no forms data'); } echo json_encode($return); exit(); } // end save private function delete_bill_file($id) { if ($id) { if ($this->incomming_goods_object->delete_bill_file($id)) { $return = array('status' => 'success'); } else { $return = array('status' => 'error'); } } else { $return = array('status' => 'error'); } echo json_encode($return); exit(); } private function upload_bill($id) { if ($id) { $temp_file = $_FILES['Filedata']['tmp_name']; if ($temp_file != '') { $result = $this->incomming_goods_object->save_bill($id, $temp_file); if ($result) { $return = array('status' => 'success'); } else { $return = array('status' => 'error', 'message' => "ERROR: can't save", 'data', $result); } } else { $return = array('status' => 'error', 'message' => 'ERROR: no file'); } } else { $return = array('status' => 'error', 'message' => 'ERROR: no id'); } echo json_encode($return); exit(); } // end upload // only used in ajax, so i terminate with exit private function add_item($id) { $data = array(); $this->incomming_goods_object->set_id($id); $data['item_id'] = $_POST['item_id']; $data['amount'] = $_POST['amount']; $data['price_sum'] = str_replace(',','.',$_POST['price_sum']); $data['inventory_object_id'] = $id; $result = $this->incomming_goods_object->add_item($data); if ($result) { $return = array('status' => 'success'); } else { $return = array('status' => 'error', 'message' => 'save failed'); } echo json_encode($return); exit(); } // end save // only used in ajax, so i terminate with exit private function delete_item($id) { $this->incomming_goods_object->set_id($id); $result = $this->incomming_goods_object->delete_item($_POST['item_id']); if ($result) { $return = array('status' => 'success'); } else { $return = array('status' => 'error', 'message' => 'save failed'); } echo json_encode($return); exit(); } // end save } // end