function updateItem($line_of_text) { $model = new Items(); $model->item_id = $line_of_text[0]; $model->company_id = $line_of_text[1]; $model->part_number = $line_of_text[2]; if (empty($model->part_number)) { $model->part_number = 'Not Available'; } $model->name = $line_of_text[3]; if (empty($model->name)) { $model->name = 'Not Available'; } $model->description = $line_of_text[4]; $model->barcode = $line_of_text[5]; $model->location_room = $line_of_text[6]; $model->location_row = $line_of_text[7]; $model->location_column = $line_of_text[8]; $model->location_shelf = $line_of_text[9]; $model->category_id = $line_of_text[10]; $model->current_quantity = $line_of_text[11]; if (empty($model->current_quantity)) { $model->current_quantity = '0'; } $model->available_quantity = $line_of_text[12]; if (empty($model->available_quantity)) { $model->available_quantity = '0'; } $model->recommended_lowest_quantity = $line_of_text[13]; $model->recommended_highest_quantity = $line_of_text[14]; $model->remarks = $line_of_text[15]; $model->active = $line_of_text[16]; $model->image_url = $line_of_text[17]; $model->sale_price = $line_of_text[18]; $model->factory_due_date = $line_of_text[19]; $model->suppliers_id = $line_of_text[20]; $model->fits_in_model = $line_of_text[21]; $model->created = $line_of_text[22]; $model->modified = $line_of_text[23]; $model->deleted = $line_of_text[24]; if ($model->save()) { echo '<tr style="background-color:#EAF2D3"><td>' . $model->part_number . '</td><td>Part Number Saved</td><td></td> </tr>'; } else { $errors = $model->getErrors(); echo '<tr style="background-color:#FF8566"><td>' . $model->part_number . '</td><td>Part Number Not Saved</td><td>'; echo "Item not imported"; foreach ($errors as $e) { echo "<br>" . $e[0]; } echo '</td></tr>'; //print_r($model->getErrors()).'</td></tr>'; } //end of save else }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Items(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Items'])) { $model->attributes = $_POST['Items']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->item_id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { Yii::app()->clientScript->registerPackage('items-edit'); if (!isset($_GET['id']) || NULL == ($model = Items::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'id' => (int) $_GET['id'])))) { $model = new Items(); } if (isset($_POST['Items'])) { $model->attributes = $_POST['Items']; $fn = Files::model()->uploadFile('Items[image]'); if ($fn) { $model->image = $fn['filename']; } elseif (isset($_POST['Items']['image_src'])) { $model->image = $_POST['Items']['image_src']; } $new = $model->isNewRecord; if ($model->save()) { $cats = isset($_POST['categories']) ? $_POST['categories'] : array(); if (!$new && empty($cats)) { ItemsCategory::model()->deleteAllByAttributes(array('item_id' => $model->id)); } else { if (!$new) { $dbcats = ItemsCategory::model()->findAll('item_id=:iid', array('iid' => $model->id)); $ids = array(); foreach ($dbcats as $i => $dbc) { if (false !== ($k = array_search($dbc->category_id, $cats))) { unset($cats[$k]); unset($dbc[$i]); } else { $ids[] = $dbc->category_id; } } //deleteing corresponding categories if (!empty($ids)) { $ids = implode(",", $ids); ItemsCategory::model()->deleteAll('item_id=:iid AND category_id IN (:cid)', array('iid' => $model->id, 'cid' => $ids)); } } if (!empty($cats)) { foreach ($cats as $cat) { $c = new ItemsCategory(); $c->attributes = array('category_id' => $cat, 'item_id' => $model->id); $c->save(); } } } Yii::app()->user->setFlash('ItemSaved', '1'); $this->refresh(); } } $this->render('_form', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Items(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Items'])) { $model->attributes = $_POST['Items']; if (!empty($_FILES['Items']['name']['itm_photo'])) { $image_name = $this->imageUpload($_FILES['Items']['name']['itm_photo'], $_FILES['Items']['tmp_name']['itm_photo'], 'products'); } if (!empty($image_name)) { $model->itm_photo = $image_name; } else { unset($model->itm_photo); } if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
public function postNew() { // Get input values $task = Input::get('new'); $dater = Input::get('date'); $hour = Input::get('hour'); $minute = Input::get('minutes'); $date = $dater . ' ' . $hour . ':' . $minute . ':00'; $date = strtotime($date); $date = Date("Y-m-d H:i:s", $date); // Validation $rules = array('new' => 'required|min:5|max:255'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('home')->withErrors($validator); } //Add new task $items = new Items(); $items->name = $task; $items->dueDate = $date; $items->save(); return Redirect::route('home'); }
public function createOrder() { $order_create = new Logger('OrderCreation'); $response = array(); $output = array(); try { $order = new Orders(); if (!Input::has('user_id') || !Input::has('items')) { /* * There shd be a single class which handles all this. */ $response['response_code'] = ResponseCodes::$response_code['missing_param']['code']; $response['response_message'] = ResponseCodes::$response_code['missing_param']['response_message']; echo json_encode($response); die; } // Save the order to the database $order->status = AppConstants::$avialable_status['created']; // the user id is assumed to be a part of the request. // Ideally it shouldn't be.The server shd be able to identify the user based on session id or token or any other method $order->user_id = Input::get('user_id'); $order->save(); /* * While saving items we assume that we are getting a json encoded data for the list of item. * like this [{"name":"shirt","quantity":"2"},{"name":"saree","quantity":"2"}] * with the product name and the quanity.Each item added belongs to a specific type which has a fixed price whc are intrenally mapped */ $list_of_items = json_decode(Input::get('items'), true); foreach ($list_of_items as $key => $item_data) { $item = new Items(); $item->order_id = $order->id; $item->name = $item_data['name']; $item->quantity = $item_data['quantity']; // assuming the item type is correct. $item->price = Price::$price_mapping[$item_data['name']] * $item_data['quantity']; $item->save(); } $output['order_id'] = $order->id; $response['response_code'] = ResponseCodes::$response_code['success']['code']; $response['response_message'] = ResponseCodes::$response_code['success']['response_message']; $response['output'] = $output; echo json_encode($response); } catch (Exception $e) { Log::error($e->getMessage()); $order_create->addInfo($e->getMessage()); $response['response_code'] = ResponseCodes::$response_code['internal_server_error']['code']; $response['response_message'] = ResponseCodes::$response_code['internal_server_error']['response_message']; $response['output'] = $output; echo json_encode($response); } }
public function postNewItem() { $input = Input::all(); $rules = array('cat' => 'required', 'item_precio_dol' => 'required', 'item_cod' => 'required|unique:item', 'item_nomb' => 'required|min:4', 'item_desc' => 'required|min:4'); $msg = array('required' => 'El campo :attribute es obligatorio', 'min' => 'El campo :attribute es muy corto(a)', 'unique' => 'El campo :attribute debe ser unico'); $attr = array('cat' => 'categoría', 'item_precio' => 'precio', 'item_precio_dol' => 'precio en dolares', 'item_cod' => 'artículo', 'item_nomb' => 'artículo', 'item_desc' => 'artículo'); $validation = Validator::make($input, $rules, $msg, $attr); if ($validation->fails()) { return Redirect::to('administrador/nuevo-articulo')->withErrors($validation)->withInput(); } else { $item = new Items(); $item->item_cat = $input['cat']; if (!empty($input['subcat'])) { $item->item_subcat = $input['subcat']; } $item->item_cod = $input['item_cod']; $item->item_nomb = $input['item_nomb']; $item->item_desc = $input['item_desc']; $item->item_precio = $input['item_precio_dol']; $item->save(); $id = $item->id; $misc = new Misc(); $misc->item_id = $id; $misc->save(); $misc_id = $misc->id; if (!file_exists('images/items/' . $id)) { mkdir('images/items/' . $id); } return Redirect::to('administrador/nuevo-articulo/continuar/' . $id . '/' . $misc_id); } }