public function update($id, Request $request)
 {
     $messages = [];
     //rules to apply of each field
     $rulesItem = array('name' => 'string|required', 'weight' => 'integer|required|min:0');
     $validatorItem = Validator::make($request->all(), $rulesItem);
     if ($validatorItem->fails()) {
         foreach ($validatorItem->messages()->getMessages() as $key => $value) {
             $messages[] = Lang::get('validator.global', ["name" => $key]);
         }
         $error = Constants::MSG_ERROR_CODE;
     } else {
         $name = $request->input('name');
         $weight = $request->input('weight');
         $item = Item::find($id);
         if ($item == null) {
             $messages[] = Lang::get('items.notFoundById', ['id' => $id]);
             $error = Constants::MSG_ERROR_CODE;
         } else {
             $newItem = new Item();
             $newItem->name = $name;
             $newItem->weight = $weight;
             $newItem->active = Constants::ACTIVE;
             $newItem->save();
             $item->active = Constants::ARCHIVED;
             $item->save();
             $error = Constants::MSG_OK_CODE;
             $messages[] = Lang::get('items.modified');
         }
     }
     if ($error == Constants::MSG_ERROR_CODE) {
         return redirect()->back()->with(['messages' => $messages, 'error' => $error]);
     }
     return redirect()->route('items::viewAll')->with('error', $error)->with('messages', $messages);
 }
Esempio n. 2
0
 /**
  * Creates a new Item model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Item();
     $modelPrice = new Price();
     $modelPrice->tax = 12;
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $modelPrice->load(Yii::$app->request->post()) && $modelPrice->validate()) {
         $transaction = $model->getDb()->beginTransaction();
         try {
             if (!$model->save(false)) {
                 throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->getErrors(), true)]), 500);
             }
             if (!$modelPrice->save(false)) {
                 throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelPrice->tableName())), 'msj' => print_r($modelPrice->getErrors(), true)]), 500);
             }
             $modelItemPrice = new ItemPrice();
             $modelItemPrice->item_id = $model->id;
             $modelItemPrice->price_id = $modelPrice->id;
             if (!$modelItemPrice->save(false)) {
                 throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelItemPrice->tableName())), 'msj' => print_r($modelItemPrice->getErrors(), true)]), 500);
             }
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'modelPrice' => $modelPrice]);
     }
 }
 /**
  * Creates a new Item model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Item();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $item = new Item();
     $item->nombre_item = $request->nombre;
     $item->tipo_item = $request->tipo;
     $item->estado_item = $request->estado;
     $item->concepto = $request->concepto;
     $item->save();
     return redirect('item');
 }
Esempio n. 5
0
 /**
  * Create an Item and it's derived class
  *
  * @param $inputs
  * @param User $user
  * @return Item
  */
 public function store($inputs, $user)
 {
     $item = new Item();
     $item->value = $inputs['value'];
     $item->description = $inputs['description'];
     $item->discovery_setting = $inputs['discovery_setting'];
     $item->user_id = $user->id;
     $item->save();
     return $item;
 }
Esempio n. 6
0
 /**
  * Creates a new Item model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Item();
     if ($model->load(Yii::$app->request->post())) {
         $model->stock = $model->quantity;
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Esempio n. 7
0
 public function postEdit($id)
 {
     $validator = Validator::make(Request::all(), ['name' => 'required', 'price' => 'required|numeric']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors());
     }
     $item = new Item($id);
     $item->name = Request::get('name');
     $item->description = Request::get('description');
     $item->price = Request::get('price');
     $item->save();
     return redirect('item/' . $id);
 }
Esempio n. 8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // ---------------------------------------------------------------------
     // CONFERENCE 4
     // ---------------------------------------------------------------------
     $conference = Conference::find(4);
     $item = ['name' => 'Laptop', 'quantity' => 1];
     $item = new Item($item);
     $item->conference()->associate($conference);
     $item->save();
     $item = ['name' => 'Projector', 'quantity' => 1];
     $item = new Item($item);
     $item->conference()->associate($conference);
     $item->save();
 }
Esempio n. 9
0
 /**
  * 新商品
  */
 public function save()
 {
     $item = new Item();
     $item->cat_id = Input::get('cat_id');
     $item->name = Input::get('name');
     $item->sku = Input::get('sku');
     $item->price = Input::get('price');
     $destinationPath = "";
     $fileName = date('');
     if (Request::hasFile('logo')) {
         $file = Request::file('logo');
         Request::file('photo')->move($destinationPath, $fileName);
     }
     var_dump($file);
     exit;
     $item->save();
 }
Esempio n. 10
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Item();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (Yii::$app->request->post('ajax') !== null) {
             return \app\helpers\Response::send(200, $model);
         }
         //$model->pic->saveAs('/to/localFile');
         return $this->redirect(array('admin', 'id' => $model->id));
     }
     if (Yii::$app->request->post('ajax') !== null) {
         return \app\helpers\Response::send(501, $model->errors);
     }
     $model->sku = $model->maxId() + 1;
     $model->parent_item_id = 0;
     return $this->render('create', array('model' => $model));
 }
Esempio n. 11
0
 /**
  * Create an Item for a Conference.
  *
  * @param  ItemRequest  $request
  * @param  int  $cid
  * @return Response
  */
 public function store(ItemRequest $request, $cid)
 {
     try {
         $user = $this->isConferenceManager($request, $cid);
         if (!$user) {
             return response()->error(403, 'You are not a manager of this conference!');
         }
         $conference = Conference::find($cid);
         if (!$conference) {
             return response()->error(404, 'Conference Not Found');
         }
         $item = new Item($request->all());
         $item->conference()->associate($conference);
         $item->save();
         return response()->success();
     } catch (Exception $e) {
         return response()->error();
     }
 }
Esempio n. 12
0
 public function register(Request $request)
 {
     $u = new Item();
     $u->itemssubgroupid = $request->input('itemssubgroupid');
     $u->code = $request->input('code');
     $u->name = $request->input('name');
     $u->quantity = $request->input('quantity');
     $u->mesid = $request->input('mesid');
     $u->price = $request->input('price');
     if ($request->input('sstatus') == NULL) {
         $u->sstatus = 0;
     } else {
         $u->sstatus = $request->input('sstatus');
     }
     $u->userid = $request->input('userid');
     $u->save();
     //echo 'successfully Inserted.';
     return redirect('itemmaster');
 }
Esempio n. 13
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ItemRequest $request)
 {
     //store
     $item = new Item();
     $item->name = Input::get('name');
     $item->unit = Input::get('unit');
     $item->remarks = Input::get('remarks');
     $item->min_level = Input::get('min_level');
     $item->max_level = Input::get('max_level');
     $item->storage_req = Input::get('storage_req');
     $item->user_id = Auth::user()->id;
     try {
         $item->save();
         $url = session('SOURCE_URL');
         return redirect()->to($url)->with('message', trans('messages.record-successfully-saved'))->with('activeitem', $item->id);
     } catch (QueryException $e) {
         \Log::error($e);
     }
 }
 public function postUpload()
 {
     $files = $this->flyLocal()->listContents();
     foreach ($files as $file) {
         if (preg_match('/.csv$/', $file['basename'])) {
             $contents = $this->flyLocal()->readAndDelete($file['basename']);
             $csv = Reader::createFromString($contents);
             $rows = $csv->setOffset(1)->fetchAll();
             foreach ($rows as $row) {
                 $item = new Item();
                 $item->date = strtotime($row[0]);
                 $item->category = $row[1];
                 $item->title = $row[2];
                 $item->location = $row[3];
                 $item->condition = $row[4];
                 $item->amount = $row[5];
                 $item->tax_name = $row[6];
                 $item->tax_amount = $row[7];
                 $item->save();
             }
         }
     }
     return redirect('admin');
 }
Esempio n. 15
0
 public function addItem($bookID)
 {
     if ($this->petugas == null) {
         header("Location: " . base . "/Auth");
         exit;
     }
     $item = new Item();
     $item->BookID = $bookID;
     $item->save();
     header("Location: " . base . "/Book/items/{$bookID}");
 }
Esempio n. 16
0
 /**
  *
  * @return Item
  */
 public function createItem($parent = NULL)
 {
     $categoryIds = Category::lists('id')->all();
     $item = new Item(['title' => $this->faker->sentence, 'category_id' => $this->faker->randomElement($categoryIds), 'priority' => $this->faker->numberBetween(1, 5)]);
     //        if ($item->priority === 1) {
     //            $urgent = $this->faker->boolean(5);
     //            if ($urgent) {
     //                $item->urgency = 1;
     //            }
     //        }
     $item->user()->associate(User::first());
     if ($this->faker->boolean(50)) {
         $item->body = 'item body';
     }
     if (!is_null($parent)) {
         $item->parent()->associate($parent);
     }
     $item->save();
     return $item;
 }
Esempio n. 17
0
 public function addItemByExcel($row, $banqueId, $titreIdGItem)
 {
     $item = new Item();
     $item->valeur = $row["valeur"];
     $item->label = $row["label_item"];
     $item->id_Competence = $row["id_competence_item"];
     $item->id_TitreGItem = $titreIdGItem;
     $item->id_Banque = $banqueId;
     $item->save();
 }
Esempio n. 18
0
 /**
  * POST /api/itemRequests
  * @param StoreItemRequest $request
  * @return Response
  */
 public function store(StoreItemRequest $request)
 {
     $currentUser = Auth::user();
     if ($currentUser && $this->itemsRepository->itemAlreadyExists($request)) {
         //Checking $currentUser is true because if it's feedback sent from one of my apps,
         //the itemAlreadyExists method will throw an exception because the user isn't logged in
         return response(['error' => "You already have this item here.", 'status' => Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST);
     } else {
         $item = new Item($request->only(['title', 'body', 'priority', 'urgency', 'favourite', 'alarm', 'not_before', 'recurring_unit', 'recurring_frequency']));
         if ($request->get('recurring_unit') === 'none') {
             $item->recurring_unit = null;
         }
         //This is because the alarm was getting set to 0000-00-00 00:00:00 when no alarm was specified
         if ($request->has('alarm') && !$request->get('alarm')) {
             $item->alarm = null;
         }
         $parent = false;
         if ($request->get('parent_id')) {
             $parent = Item::find($request->get('parent_id'));
             $item->parent()->associate($parent);
         }
         if ($currentUser) {
             $item->user()->associate(Auth::user());
         } else {
             //User is not logged in. It could be a feedback request from one of my apps. Add the item to my items (user_id 1).
             $item->user()->associate(1);
         }
         $item->category()->associate(Category::find($request->get('category_id')));
         $item->index = $item->calculateIndex($request->get('index'), $parent);
         $item->save();
         $item = $this->transform($this->createItem($item, new ItemTransformer()))['data'];
         return response($item, Response::HTTP_CREATED);
     }
 }
Esempio n. 19
0
 /**
  * 新商品
  */
 public function save()
 {
     Plupload::receive('file', function ($file) {
         $file->move(storage_path() . '/tmp/', $file->getClientOriginalName());
         $this->path = storage_path() . '/tmp/' . $file->getClientOriginalName();
         //Session::put('path', storage_path() . '/tmp/'.$file->getClientOriginalName());
     });
     $item = new Item();
     $item->cat_id = Input::get('cat_id');
     $item->name = Input::get('name');
     $item->sku = Input::get('sku');
     $item->logo = $this->path;
     $item->price = Input::get('price');
     $rs = $item->save();
     if ($rs) {
         /* 商品编号 */
         $itemId = $item->id;
         $this->getAttr($itemId);
         //添加属性操作
         /*
         $sql = "INSERT INTO " .$ecs->table('goods_attr'). " (attr_id, goods_id, attr_value, attr_price)".
             "VALUES ('$attr_id', '$goods_id', '$attr_value', '$info[attr_price]')";
         */
     }
     return redirect()->route('admin.item.index');
 }
Esempio n. 20
0
 public function readBkmv()
 {
     //sort
     $this->sortBkmvFile();
     //skip for testing
     //
     //new company
     //get perm from ini
     //if (substr($line,395,1)=='2')
     //    $encoding="ibm862";
     //else
     $encoding = "windows-1255";
     //$encoding="ibm862";
     Yii::info('start Openimport');
     //$bkmv = $yiiBasepath."/files/".$configPath."/openformt/bkmvdata.txt-sorted";
     $bkmv = $this->bkmvFile . "-sorted";
     $suc = array();
     $suc['B110'] = 0;
     $suc['A100'] = 0;
     $suc['B100'] = 0;
     $suc['C100'] = 0;
     $suc['M100'] = 0;
     $suc['D110'] = 0;
     $suc['D120'] = 0;
     $suc['Z900'] = 0;
     $analze = array();
     $analze['B110'] = 0;
     $analze['A100'] = 0;
     $analze['B100'] = 0;
     $analze['C100'] = 0;
     $analze['M100'] = 0;
     $analze['D110'] = 0;
     $analze['D120'] = 0;
     $analze['Z900'] = 0;
     $accType = 200;
     //DELETE FROM `qwe_docCheques` WHERE 1;DELETE FROM `qwe_docDetails` WHERE 1;DELETE FROM `qwe_accounts` WHERE 1;DELETE FROM `qwe_items` WHERE 1;DELETE FROM `qwe_docs` WHERE 1;
     if ($fp = fopen($bkmv, 'r')) {
         while ($line = fgets($fp)) {
             @($line = iconv($encoding, "UTF-8//IGNORE", $line));
             //$line=utf8_encode($line);
             $type = substr($line, 0, 4);
             //$obj=$this->readline($line,$type);
             $obj = true;
             if (!$obj) {
                 //$suc[$type]--;
             } else {
                 //foreach ($obj as &$value)
                 //	if ($encoding=="ibm862")
                 //		$value = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $value)));
                 if ($type == 'B110') {
                     //Acc Haeder
                     /* Account Import */
                     $acc = new Accounts();
                     $acc->readLine($line, $type);
                     if (isset($this->accTypeIndex[$acc->type])) {
                         $this->accDesc[$acc->type] = $this->accDesc[$acc->type] . "," . $acc->name;
                     } else {
                         $this->accDesc[$acc->type] = $acc->name;
                         $this->accTypeIndex[$acc->type] = $accType;
                         $accType++;
                     }
                     $acc->type = $this->accTypeIndex[$acc->type];
                     if ($acc->currency_id == '') {
                         $acc->currency_id = 'ILS';
                     }
                     $acc->system_acc = 0;
                     if (!$acc->save()) {
                         var_dump($acc->errors);
                     }
                     //get new acc index save old
                     unset($acc);
                     //*/
                 }
                 if ($type == 'M100') {
                     //Item In Stock
                     $item = new Item();
                     $item->category_id = 0;
                     $item->parent_item_id = 0;
                     $item->isProduct = 0;
                     $item->profit = 0;
                     $item->stockType = 0;
                     $item->readLine($line, $type);
                     if ($item->currency_id == '') {
                         $item->currency_id = 'ILS';
                     }
                     if ($item->sku == '') {
                         $item->sku = $item->id;
                     }
                     if ($item->itemVatCat_id == '') {
                         $item->itemVatCat_id = '1';
                     }
                     if ($item->unit_id == '') {
                         $item->unit_id = '1';
                     }
                     if (!$item->save()) {
                         var_dump($item->errors);
                     }
                     unset($item);
                     //*/
                 }
                 if ($type == 'C100') {
                     //Doc Haeder
                     //return "done!";
                     //Yii::$app->end();
                     //find type
                     //global $DocOpenType;
                     $doc = new Docs();
                     $doc->readLine($line, $type);
                     $doc->action = true;
                     $doc->status = true;
                     //needtoChange
                     //Yii::log($doc,'info','app');
                     if ($doc->currency_id == '') {
                         $doc->currency_id = 'ILS';
                     }
                     if (!$doc->save()) {
                         var_dump($doc->errors);
                     }
                     unset($doc);
                     /*
                                               if ((isset($DocOpenType[$obj['doctype']])) && (isset($accIndex[$obj['account']]))){
                                               $obj['doctype']=$DocOpenType[$obj['doctype']];
                                               $doc=new document($obj['doctype']);
                                               $stype=$obj['doctype'];
                                               foreach($obj as $key=>$value){
                                               $doc->$key=$value;//print "$key <br />";
                                               }
                                               $doc->account=$accIndex[$doc->account];
                                               //search for old acc index
                                               if (isset($doc->rcptdetials)) unset($doc->rcptdetials);
                                               if (isset($doc->docdetials)) unset($doc->docdetials);
                     
                                               if($check){
                                               if((strtotime($doc->issue_date)>$begindmy)&&(strtotime($doc->issue_date)<$enddmy))
                                               $docIndex[$stype.$obj["docnum"]]=$doc->newDocument();
                                               //print "we are chking!";
                                               }else{
                                               $docIndex[$stype.$obj["docnum"]]=$doc->newDocument();
                                               }
                                               //get new doc index save old
                                               unset($doc);
                                               } */
                 }
                 if ($type == 'D110') {
                     //Doc Detial
                     $docdetial = new Docdetails();
                     $docdetial->readLine($line, $type);
                     if ($docdetial->unit_id == '') {
                         $docdetial->unit_id = 1;
                     }
                     if ($docdetial->currency_id == '') {
                         $docdetial->currency_id = 'ILS';
                     }
                     //Yii::log($docdetial,'info','app');
                     if (!$docdetial->save()) {
                         var_dump($docdetial->errors);
                     }
                     unset($docdetial);
                     /*
                                               global $DocOpenType;
                                               $stype=$DocOpenType[$obj['doctype']];
                                               if (isset($docIndex[$stype.$obj["num"]])){
                                               $docdetial=new documentDetail;
                                               $docdetial->price=$obj['price'];
                                               unset($obj['doctype']);
                                               unset($obj['price']);
                     
                                               foreach($obj as $key=>$value){
                                               $docdetial->{$key}=$value;//print "$key <br />";
                     
                                               }
                     
                                               $docdetial->num=$docIndex[$stype.$obj["num"]];
                                               $docdetial->newDetial();
                     
                                               //search for old doc index
                                               //die;
                                               //update to new index
                                               unset($docdetial);
                                               }// */
                 }
                 if ($type == 'D120') {
                     //Kaballa Detial
                     $rcptdetial = new Doccheques();
                     $rcptdetial->readLine($line, $type);
                     //Yii::log($rcptdetial, 'info', 'app');
                     if ($rcptdetial->currency_id == '') {
                         $rcptdetial->currency_id = 'ILS';
                     }
                     if (!$rcptdetial->save()) {
                         var_dump($rcptdetial->errors);
                     }
                     unset($rcptdetial);
                     /*
                                               global $DocOpenType;
                                               $stype=$DocOpenType[$obj['doctype']];
                                               if (isset($docIndex[$stype.$obj["refnum"]])){
                                               $rcptdetial=new receiptDetail();
                                               //$stype=$DocOpenType[$obj['doctype']];
                                               $rcptdetial->sum=(float)$obj['sum'];
                                               unset($obj['sum']);
                                               unset($obj['doctype']);
                                               foreach($obj as $key=>$value){
                                               $rcptdetial->$key=$value;
                                               }
                                               $rcptdetial->refnum=$docIndex[$stype.$obj["refnum"]];
                                               $rcptdetial->newDetial();
                                               //search for old doc index
                                               //update to new index
                                               unset($rcptdetial);
                                               } */
                 }
                 if ($type == 'B100') {
                     //Move Recored
                     $transaction = new Transactions();
                     $transaction->readLine($line, $type);
                     if ($transaction->type == '') {
                         $transaction->type = 1;
                     }
                     if ($transaction->currency_id == '') {
                         $transaction->currency_id = 'ILS';
                     }
                     if (!$transaction->save()) {
                         var_dump($transaction->errors);
                     }
                     //Yii::log($transaction,'info','app');
                     unset($transaction);
                     /*
                                               //print $obj['value'].":".$obj['type'];
                                               global $openTransType;
                     
                                               if (isset($accIndex[$obj['account']])){
                                               $bsum= $obj['sum'];
                                               if($obj['value']==1)
                                               $bsum= -1 * $obj['sum'];
                                               //print $bsum."<br />\n";
                                               $usum=$bsum*-1;
                     
                                               $uaccount=$obj['account1'];
                                               $stype=$openTransType[$obj['type']];
                                               unset($obj['sum']);
                                               unset($obj['value']);
                                               unset($obj['account1']);
                                               //adam:! need to reset type of action!
                     
                                               $transaction=new transaction;
                     
                                               foreach($obj as $key=>$value){
                                               $transaction->$key=$value;//print "$key <br />";
                                               }
                                               $transaction->type=$stype;
                                               $transaction->sum=$bsum;
                                               $transaction->account=$accIndex[$obj['account']];
                     
                                               if($check){
                                               if((strtotime($transaction->date)>$begindmy)&&(strtotime($transaction->date)<$enddmy)){
                                               // "gone";
                                               $transaction->newTransactions();
                                               }
                                               //print "gone2";
                                               }else{
                                               //print "gone1";
                                               $transaction->newTransactions();
                                               }
                                               unset($transaction);
                                               }// */
                 }
                 unset($obj);
                 $suc[$type]++;
             }
             $analze[$type]++;
             //if ($analze[$type]>100)	break;
         }
         Yii::info("End OpenImport");
         //print_r($docIndex);
         //end loop
         //print_r($accIndex);
     } else {
         echo Yii::t('app', "error cant open file!");
     }
 }