/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/templates/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     DB::table('channel_items')->truncate();
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'MKL Mapping') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         // dd($row);
                         if (!ctype_digit(trim($row[4])) || !ctype_digit(trim($row[5])) || !ctype_digit(trim($row[6]))) {
                             InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'MKL Mapping', 'remarks' => 'Invalid mapping']);
                         } else {
                             $channel = '';
                             if (trim($row[0]) != '') {
                                 $channel = Channel::where('channel_code', trim($row[0]))->first();
                             }
                             $item = Item::where('sku_code', trim($row[3]))->first();
                             if (!empty($item)) {
                                 $item_type = ItemType::where('type', "MKL")->first();
                                 $osa_tagging = 0;
                                 if (isset($row[7])) {
                                     $osa_tagging = trim($row[7]);
                                 }
                                 $npi_tagging = 0;
                                 if (isset($row[8])) {
                                     $npi_tagging = trim($row[8]);
                                 }
                                 ChannelItem::firstOrCreate(['channel_id' => $channel->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]);
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
 }
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/seed_files/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     echo 'Seeding ' . $filePath . PHP_EOL;
     // DB::table('other_barcodes')->truncate();
     Item::where('active', 1)->update(['cleared' => 0]);
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Other Codes') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if (!is_null($row[0]) && trim($row[0]) != '') {
                     if ($cnt > 0) {
                         $item = Item::where('sku_code', trim($row[0]))->first();
                         if (!empty($item)) {
                             if ($item->cleared == 0) {
                                 OtherBarcode::where('item_id', $item->id)->delete();
                                 $item->cleared = 1;
                                 $item->save();
                             }
                             $area = Area::where('area', strtoupper($row[1]))->first();
                             if (!empty($item) && !empty($area)) {
                                 OtherBarcode::firstOrCreate(['item_id' => $item->id, 'area_id' => $area->id, 'other_barcode' => trim($row[2])]);
                             }
                         } else {
                             // dd($row);
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/seed_files/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     // DB::table('store_items');
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Assortment Mapping') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         if (!ctype_digit(trim($row[4]))) {
                             InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'Assortment Mapping', 'remarks' => 'Invalid mapping']);
                         } else {
                             $channel = '';
                             $customer = '';
                             $store = '';
                             if (trim($row[0]) != '') {
                                 $channel = Channel::where('channel_code', trim($row[0]))->get();
                             }
                             if (trim($row[1]) != '') {
                                 $customer = Customer::where('customer_code', trim($row[1]))->get();
                             }
                             if (trim($row[2]) != '') {
                                 $store = Store::where('store_code', trim($row[2]))->first();
                             }
                             // dd($store);
                             $stores = Store::where(function ($query) use($channel) {
                                 if (!empty($channel)) {
                                     $channel_id = [];
                                     foreach ($channel as $value) {
                                         $channel_id[] = $value->id;
                                     }
                                     $query->whereIn('channel_id', $channel_id);
                                 }
                             })->where(function ($query) use($customer) {
                                 if (!empty($customer)) {
                                     $customer_id = [];
                                     foreach ($customer as $value) {
                                         $customer_id[] = $value->id;
                                     }
                                     $query->whereIn('customer_id', $customer_id);
                                 }
                             })->where(function ($query) use($store) {
                                 if (!empty($store)) {
                                     $query->where('store', $store->id);
                                 }
                             })->get();
                             // dd($stores);
                             $item = Item::where('sku_code', trim($row[3]))->first();
                             if (!empty($item)) {
                                 $item_type = ItemType::where('type', "ASSORTMENT")->first();
                                 foreach ($stores as $store) {
                                     $w_mkl = StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->get();
                                     $cw_mkl = ChannelItem::where('channel_id', $store->channel_id)->where('item_id', $item->id)->get();
                                     if (count($w_mkl) == 0) {
                                         StoreItem::firstOrCreate(['store_id' => $store->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => 0, 'npi_tagged' => 0]);
                                     }
                                     if (count($cw_mkl) == 0) {
                                         ChannelItem::firstOrCreate(['channel_id' => $store->channel_id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => 0, 'npi_tagged' => 0]);
                                     }
                                 }
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     $hash = UpdateHash::find(1);
     if (empty($hash)) {
         UpdateHash::create(['hash' => \Hash::make(date('Y-m-d H:i:s'))]);
     } else {
         $hash->hash = md5(date('Y-m-d H:i:s'));
         $hash->update();
     }
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Ejemplo n.º 4
0
 public function viewAll()
 {
     $error = \Session::get('error');
     $messages = \Session::get('messages');
     $items = Item::where('active', Constants::ACTIVE)->get();
     return view('items.viewAll', ['items' => $items, 'error' => $error, 'messages' => $messages]);
 }
Ejemplo n.º 5
0
 /**
  *
  * @return mixed
  */
 public function siblings()
 {
     if (!$this->parent) {
         return Item::forCurrentUser()->whereNull('parent_id')->where('id', '!=', $this->id)->get();
     }
     return Item::where('parent_id', $this->parent_id)->where('id', '!=', $this->id)->get();
 }
Ejemplo n.º 6
0
 public function get_item_by_category(Request $request)
 {
     if ($request->ajax()) {
         $category_id = $request->input('category_id');
         $iteminfo = Item::where('itemssubgroupid', $category_id)->get();
         return response()->json($iteminfo);
     }
 }
Ejemplo n.º 7
0
Archivo: Item.php Proyecto: sabihk/soft
 /**
  * Count duplicate fields
  * If check is done while updating data then check except this id
  *
  * @param string $field_name
  * @param array $fields
  * @return int
  */
 public function duplicateField($field_name, $fields)
 {
     $field_count = Item::where($field_name, $fields['name']);
     if (!empty($fields['item_id'])) {
         $field_count = $field_count->where('id', '!=', $fields['item_id']);
     }
     $field_count = $field_count->count();
     return $field_count;
 }
Ejemplo n.º 8
0
 public function delete(Request $request, $banqueId, $itemId)
 {
     // verify request inputs
     if (is_null($itemId)) {
         return response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST);
     } else {
         $item = Item::where('id_Item', '=', $itemId)->delete();
         return is_null($item) ? response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST) : $item;
     }
 }
Ejemplo n.º 9
0
 public function add($itemId)
 {
     //   Cart::add(455, 'Sample Item', 100.99, 2, array());
     /* 取得商品信息 */
     $item = Item::where('id', '=', $itemId)->first();
     //   var_dump($item);exit;
     /* 初始化要插入购物车的基本件数据 */
     $parent = array('user_id' => Auth::id(), 'goods_id' => $itemId, 'sku' => $item['sku'], 'item_name' => addslashes($item['name']), 'price' => $item['price']);
     Cart::add($itemId, addslashes($item['name']), $item['price'], '1', array());
     return redirect()->route('cart.index');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     set_time_limit(0);
     ini_set('memory_limit', -1);
     $updated_igs = UpdatedIg::all();
     foreach ($updated_igs as $row) {
         $store = Store::where('store_code', $row->store_code)->first();
         if (!empty($store)) {
             $item = Item::where('sku_code', $row->sku_code)->first();
             if (!empty($item)) {
                 StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->update(['ig' => $row->ig, 'ig_updated' => 1]);
             }
         }
     }
 }
Ejemplo n.º 11
0
 public function getDocumentItems(Request $request)
 {
     $id = $request->get('document_id');
     $document = \App\Models\Document::find($id);
     $items = \App\Models\Item::where('document_id', '=', $id);
     if (Auth::user()->username == '1-0275071849') {
         $datatables = Datatables::of($items)->addColumn('action', function ($item) {
             return '<a href="/item/' . $item->id . '" class="actions icons"><i class="fa fa-eye"></i></a>';
         });
     } else {
         $datatables = Datatables::of($items)->addColumn('action', function ($item) {
             return '<a href="/item/' . $item->id . '" class="actions icons"><i class="fa fa-eye"></i></a><a href="/item/' . $item->id . '/edit" class="actions icons"><i class="fa fa-pencil-square-o"></i></a><a href="/item/destroy/' . $item->id . '" class="actions icons"><i class="fa fa-trash"></i></a>';
         });
     }
     return $datatables->make(true);
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('updated_igs', function (Blueprint $table) {
         $table->string('area')->after('id');
         $table->string('region_code')->after('area');
         $table->string('region')->after('region_code');
         $table->string('distributor_code')->after('region');
         $table->string('distributor')->after('distributor_code');
         $table->string('agency_code')->after('distributor');
         $table->string('agency')->after('agency_code');
         $table->string('storeid')->after('agency');
         $table->string('channel_code')->after('store_name');
         $table->string('channel')->after('channel_code');
         $table->string('other_code')->after('channel');
     });
     set_time_limit(0);
     ini_set('memory_limit', -1);
     $updated_igs = UpdatedIg::all();
     foreach ($updated_igs as $updated_ig) {
         $store = Store::where('store_code', $updated_ig->store_code)->first();
         $item = Item::where('sku_code', $updated_ig->sku_code)->first();
         if (!empty($store) && !empty($item)) {
             $other_code = OtherBarcode::where('item_id', $item->id)->where('area_id', $store->area->id)->first();
             $updated_ig->area = $store->area->area;
             $updated_ig->region_code = $store->region->region_code;
             $updated_ig->region = $store->region->region;
             $updated_ig->distributor_code = $store->distributor->distributor_code;
             $updated_ig->distributor = $store->distributor->distributor;
             $updated_ig->agency_code = $store->agency->agency_code;
             $updated_ig->agency = $store->agency->agency_name;
             $updated_ig->storeid = $store->storeid;
             $updated_ig->channel_code = $store->channel->channel_code;
             $updated_ig->channel = $store->channel->channel_desc;
             if (!empty($other_code)) {
                 $updated_ig->other_code = $other_code->other_barcode;
             }
             $updated_ig->update();
         }
     }
 }
 public function run()
 {
     $divisions = ['HPC CATEGORY', 'FOODS CATEGORY'];
     $inventories = ItemInventories::whereNotIn('division', $divisions)->get();
     foreach ($inventories as $inventory) {
         $item = Item::where('sku_code', $inventory->sku_code)->first();
         $inventory->division = $item->division->division;
         $inventory->category = $item->category->category;
         $inventory->category_long = $item->category->category_long;
         $inventory->sub_category = $item->subcategory->sub_category;
         $inventory->brand = $item->brand->brand;
         $inventory->update();
     }
     $asinventories = AssortmentItemInventories::whereNotIn('division', $divisions)->get();
     foreach ($asinventories as $inventory) {
         $item = Item::where('sku_code', $inventory->sku_code)->first();
         $inventory->division = $item->division->division;
         $inventory->category = $item->category->category;
         $inventory->category_long = $item->category->category_long;
         $inventory->sub_category = $item->subcategory->sub_category;
         $inventory->brand = $item->brand->brand;
         $inventory->update();
     }
 }
Ejemplo n.º 14
0
 public function getItems($banqueId)
 {
     return Item::where('id_Banque', '=', $banqueId)->get();
 }
Ejemplo n.º 15
0
 public function search(Request $request)
 {
     $items = Item::where('nombre_item', 'like', '%' . $request->nombre . '%')->get();
     return \View::make('list_item', compact('items'));
 }
Ejemplo n.º 16
0
 public static function total($month, $year)
 {
     return Item::where(DB::raw('MONTH(created_at)'), '=', $month)->where(DB::raw('YEAR(created_at)'), '=', $year)->sum('amount');
 }
Ejemplo n.º 17
0
 /**
  * @return \Illuminate\Routing\Route|null|string
  */
 public function ingnoreId()
 {
     $id = $this->route('item');
     $name = $this->input('name');
     return Item::where(compact('id', 'name'))->exists() ? $id : '';
 }
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/seed_files/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     // DB::table('divisions')->truncate();
     // DB::table('categories')->truncate();
     // DB::table('sub_categories')->truncate();
     // DB::table('brands')->truncate();
     // DB::table('items')->truncate();
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Items') {
             $cnt = 0;
             Item::where('active', 1)->update(['active' => 0, 'cleared' => 0]);
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         $division = Division::firstOrCreate(['division' => strtoupper($row[9])]);
                         $category = Category::firstOrCreate(['category' => strtoupper($row[1]), 'category_long' => strtoupper($row[0])]);
                         $sub_category = SubCategory::firstOrCreate(['category_id' => $category->id, 'sub_category' => strtoupper($row[7])]);
                         $brand = Brand::firstOrCreate(['brand' => strtoupper($row[8])]);
                         $itemExist = Item::where('sku_code', strtoupper($row[2]))->first();
                         if (empty($itemExist)) {
                             $item = Item::firstOrCreate(['sku_code' => trim($row[2]), 'barcode' => $row[3], 'description' => strtoupper($row[4]), 'description_long' => strtoupper($row[5]), 'conversion' => trim($row[6]), 'lpbt' => trim($row[10]), 'division_id' => $division->id, 'category_id' => $category->id, 'sub_category_id' => $sub_category->id, 'brand_id' => $brand->id, 'active' => 1]);
                         } else {
                             $itemExist->sku_code = trim($row[2]);
                             $itemExist->barcode = $row[3];
                             $itemExist->description = strtoupper($row[4]);
                             $itemExist->description_long = strtoupper($row[5]);
                             $itemExist->conversion = trim($row[6]);
                             $itemExist->lpbt = trim($row[10]);
                             $itemExist->division_id = $division->id;
                             $itemExist->category_id = $category->id;
                             $itemExist->sub_category_id = $sub_category->id;
                             $itemExist->brand_id = $brand->id;
                             $itemExist->active = 1;
                             $itemExist->save();
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Ejemplo n.º 19
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $lists = Item::where('type', '=', 'Service')->paginate(10);
     return view('service.index', compact('lists'));
 }
Ejemplo n.º 20
0
/**
 * Go to next or previous item in the list of items of a plan
 *      or swap between chords and sheetmusic
 */
function nextItem($plan_id, $item_id, $direction)
{
    // get the full plan
    $plan = Plan::find($plan_id);
    // items list sort order depending on direction
    $orderBy = "asc";
    if ($direction == 'previous') {
        $orderBy = 'desc';
    }
    if (Auth::user()->ownsPlan($plan_id)) {
        // get all the items for this plan
        $items = $plan->items()->orderBy('seq_no', $orderBy)->get();
    } else {
        // get all items but not "FLEO" items (for leaders eyes only)
        $items = $plan->items()->where('forLeadersEyesOnly', false)->orderBy('seq_no', $orderBy)->get();
    }
    // perhaps the item_id is a seq no
    $Ar_seq_no = explode('-', $item_id);
    // if item_id actually is a seq_no, then the format is: <text>-<text>-<seq_no>
    if (count($Ar_seq_no) == 3) {
        // third element is the actual seq no
        // but we need to increase it by 1
        $cur_seq_no = $Ar_seq_no[2] + 1;
        // now find item with the new seq no
        $curItem = Item::where([['plan_id', '=', $plan_id], ['seq_no', '=', $cur_seq_no]])->first();
        // return the item id of that item (if we found it!)
        if ($curItem) {
            return $curItem->id;
        } else {
            return 0;
            // not found!
        }
    } else {
        $curItem = Item::find($item_id);
    }
    // get seq_no of desired next or previous item
    $new_seq_no = 0;
    // to prevent unnassigned exception
    if ($direction == 'next') {
        if ($curItem->seq_no == count($items)) {
            $new_seq_no = 1.0;
        } else {
            $new_seq_no = $curItem->seq_no + 1;
        }
    } elseif ($direction == 'previous') {
        if ($curItem->seq_no == 1.0) {
            $new_seq_no = count($items);
        } else {
            $new_seq_no = $curItem->seq_no - 1;
        }
    } elseif ($direction == 'swap') {
        $new_seq_no = $curItem->seq_no;
    }
    // find the new item id
    foreach ($items as $item) {
        if ($direction == 'next' && $item->seq_no >= $new_seq_no) {
            return $item->id;
        } elseif ($direction == 'previous' && $item->seq_no <= $new_seq_no) {
            return $item->id;
        } elseif ($item->seq_no == $new_seq_no) {
            return $item->id;
        }
    }
    return $item->id;
}
Ejemplo n.º 21
0
 public function postupdateig(Request $request)
 {
     if ($request->hasFile('file')) {
         $file_path = $request->file('file')->move(storage_path() . '/uploads/temp/', $request->file('file')->getClientOriginalName());
         \DB::beginTransaction();
         try {
             set_time_limit(0);
             $reader = ReaderFactory::create(Type::XLSX);
             // for XLSX files
             $reader->open($file_path);
             foreach ($reader->getSheetIterator() as $sheet) {
                 if ($sheet->getName() == 'Sheet1') {
                     $cnt = 0;
                     foreach ($sheet->getRowIterator() as $row) {
                         if ($cnt > 0) {
                             if (!empty($row[5])) {
                                 // dd($row);
                                 $updated_ig = UpdatedIg::where('store_code', $row[8])->where('sku_code', $row[13])->first();
                                 if (!empty($updated_ig)) {
                                     $updated_ig->ig = $row[23];
                                     $updated_ig->update();
                                 } else {
                                     // dd($row);
                                     UpdatedIg::firstOrCreate(['area' => $row[0], 'region_code' => $row[1], 'region' => $row[2], 'distributor_code' => $row[3], 'distributor' => $row[4], 'agency_code' => $row[5], 'agency' => $row[6], 'storeid' => $row[7], 'store_code' => $row[8], 'store_name' => $row[9], 'channel_code' => $row[10], 'channel' => $row[11], 'other_code' => $row[12], 'sku_code' => $row[13], 'description' => $row[14], 'division' => $row[15], 'category' => $row[16], 'sub_category' => $row[17], 'brand' => $row[18], 'conversion' => $row[19], 'min_stock' => $row[20], 'fso_multiplier' => $row[21], 'lpbt' => $row[22], 'ig' => $row[23]]);
                                 }
                                 $store = Store::where('store_code', $row[8])->first();
                                 if (!empty($store)) {
                                     $item = Item::where('sku_code', $row[13])->first();
                                     if (!empty($item)) {
                                         StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->update(['ig' => $row[23]]);
                                     }
                                 }
                             }
                         }
                         $cnt++;
                     }
                 }
             }
             $hash = UpdateHash::find(1);
             if (empty($hash)) {
                 UpdateHash::create(['hash' => \Hash::make(date('Y-m-d H:i:s'))]);
             } else {
                 $hash->hash = md5(date('Y-m-d H:i:s'));
                 $hash->update();
             }
             \DB::commit();
             $reader->close();
         } catch (\Exception $e) {
             \DB::rollback();
             dd($e);
         }
         if (\File::exists($file_path)) {
             \File::delete($file_path);
         }
         Session::flash('flash_message', 'Updated IG successfully updated.');
         Session::flash('flash_class', 'alert-success');
     } else {
         Session::flash('flash_message', 'Error updating item IG.');
         Session::flash('flash_class', 'alert-danger');
     }
     return redirect()->route("item.updatedig");
 }
Ejemplo n.º 22
0
 private function resolveItemsBySloppyName($skins)
 {
     $name_count = 0;
     foreach ($skins as &$skin) {
         if (isset($skin['items'])) {
             continue;
         }
         $items = Item::where('name_en', 'LIKE', $skin['name'] . '% Skin')->lists('id');
         if (count($items) == 0) {
             continue;
         }
         $skin['items'] = $items;
         $name_count++;
     }
     $this->info('Resolved ' . $name_count . ' skins by sloppy name lookup...');
     return $skins;
 }
Ejemplo n.º 23
0
 /**
  * Get items matching the skin id
  *
  * @return array
  */
 public function bySkin()
 {
     // Request data
     $skin_id = $this->getInput('skin_id');
     // Grab the item ids that match the skin
     $ids = Item::where('skin', $skin_id)->lists('id');
     return $this->apiResponse($ids);
 }
Ejemplo n.º 24
0
 public function importFile(Request $request)
 {
     $messages = [];
     $error = Constants::MSG_OK_CODE;
     $num_successful_import = 0;
     //==============
     //Check
     //==============
     $inputName = 'csv_file';
     if (!$request->hasFile($inputName)) {
         $error = Constants::MSG_ERROR_CODE;
         $messages[] = Lang::get('orders.noFile');
         return redirect()->route('orders::viewAll')->with('error', $error)->with('messages', $messages);
     }
     if (!$request->file($inputName)->isValid()) {
         $error = Constants::MSG_ERROR_CODE;
         $messages[] = Lang::get('orders.invalidFile');
         return redirect()->route('orders::viewAll')->with('error', $error)->with('messages', $messages);
     }
     //==============
     //Treatment
     //==============
     $file = $request->file($inputName);
     if (($handle = fopen($file, "r")) !== false) {
         $i = 0;
         setlocale(LC_ALL, 'fr_FR.UTF-8');
         while (($data = fgetcsv($handle, null, ";", "\"")) !== false) {
             $i++;
             if ($i == 1) {
                 continue;
             }
             //skip the first line
             $date = $data[0];
             $orderNumber = trim(substr($data[1], 7));
             $customerName = $data[2];
             $adress = $data[3];
             //order already exist
             if (Order::find($orderNumber)) {
                 $messages[] = Lang::get('orders.alreadyExists', ['id' => $orderNumber]);
                 $error = Constants::MSG_WARNING_CODE;
                 continue;
             }
             $order = new Order();
             $order->date = Carbon::parse($date);
             $order->id = intval($orderNumber);
             $order->name = $customerName;
             $order->address = $adress;
             $order->user_id = Constants::DEFAULT_USER_ID;
             $order->status = Constants::ORDER_WAITING;
             //======================
             //Treatment Order lines
             //======================
             $detail = str_getcsv($data[4], ";");
             $orderRows = [];
             $orderHasProducts = false;
             foreach ($detail as $key => $value) {
                 $item = trim(substr($value, 0, strpos($value, "(")));
                 if (strlen($item) <= 0) {
                     $messages[] = Lang::get('orders.hasNoProducts', ['id' => $orderNumber]);
                     $error = Constants::MSG_WARNING_CODE;
                     continue;
                 }
                 $quantity = rtrim(substr($value, strpos($value, "(") + 1), ")");
                 $ref = Item::where("name", "=", $item)->first();
                 if ($ref != null) {
                     $row = new OrderRow();
                     $row->item_id = $ref->id;
                     $row->order_id = $order->id;
                     $row->quantity = $quantity;
                     $orderRows[] = $row;
                     if ($ref->active == Constants::ARCHIVED) {
                         $messages[] = Lang::get('orders.productArchived', ['produit' => $ref->name, 'id' => $orderNumber]);
                         $error = Constants::MSG_WARNING_CODE;
                     }
                     $orderHasProducts = true;
                 } else {
                     $messages[] = Lang::get('orders.productNotFound', ['produit' => $item, 'id' => $orderNumber]);
                     $error = Constants::MSG_WARNING_CODE;
                 }
             }
             if (!$orderHasProducts) {
                 $messages[] = Lang::get('orders.hasNoProducts', ['id' => $orderNumber]);
                 $error = Constants::MSG_WARNING_CODE;
                 continue;
             }
             if ($order->save()) {
                 foreach ($orderRows as $key => $value) {
                     $value->save();
                 }
                 $num_successful_import++;
             } else {
                 $error = Constants::MSG_ERROR_CODE;
                 $messages[] = Lang::get('orders.saveError');
             }
         }
         fclose($handle);
     } else {
         $error = Constants::MSG_ERROR_CODE;
         $messages[] = Lang::get('orders.fileError');
     }
     $messages[] = Lang::get('orders.lineImported', ['number' => $num_successful_import]);
     return redirect()->route('orders::viewAll')->with('error', $error)->with('messages', $messages);
 }
Ejemplo n.º 25
0
 public function selectTen()
 {
     return Item::where('type', '=', 'Product')->paginate(10);
 }
Ejemplo n.º 26
0
 /**
  * For moving item to new parent. Make room for the new item.
  * @param $new_parent
  * @param $new_index
  */
 public function moveIn($new_parent, $new_index)
 {
     if ($new_parent) {
         Item::where('parent_id', $new_parent->id)->where('index', '>=', $new_index)->increment('index');
     } else {
         //Moving home
         Item::forCurrentUser()->whereNull('parent_id')->where('index', '>=', $new_index)->increment('index');
     }
 }