public function run() { $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $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; } } $file_path = $folderpath . "/" . $latest . "/OSA Target.xlsx"; echo (string) $file_path, "\n"; Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('osa_lookups')->truncate(); DB::table('osa_lookup_targets')->truncate(); $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $filePath = $file_path; $reader->open($filePath); // Accessing the sheet name when reading foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Sheet1') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!is_null($row[0])) { if ($cnt > 0) { // dd($row); $customer_id = 0; $customer = Customer::where('customer_code', $row[0])->first(); if (!empty($customer)) { $customer_id = $customer->id; } $region_id = 0; $region = Region::where('region_code', $row[1])->first(); if (!empty($region)) { $region_id = $region->id; } $distributor_id = 0; $distributor = Distributor::where('distributor_code', $row[2])->first(); if (!empty($distributor)) { $distributor_id = $distributor->id; } $store_id = 0; $store = Store::where('store_code', $row[3])->first(); if (!empty($store)) { $store_id = $store->id; } $template_id = 0; $template = AuditTemplate::where('template_code', $row[4])->first(); if (!empty($template)) { $template_id = $template->id; } $category = FormCategory::where('category', $row[5])->first(); if (!empty($category)) { $osalookup_id = 0; $osalookup = OsaLookup::where('customer_id', $customer_id)->where('region_id', $region_id)->where('distributor_id', $distributor_id)->where('store_id', $store_id)->where('template_id', $template_id)->first(); if (empty($osalookup)) { $osalookup = new OsaLookup(); $osalookup->customer_id = $customer_id; $osalookup->region_id = $region_id; $osalookup->distributor_id = $distributor_id; $osalookup->store_id = $store_id; $osalookup->template_id = $template_id; $osalookup->save(); } $osalookup_id = $osalookup->id; OsaLookupTarget::create(array('osa_lookup_id' => $osalookup_id, 'category_id' => $category->id, 'target' => $row[8], 'total' => $row[9])); } } $cnt++; } } } else { } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
public function stores() { $accounts = Account::all(); $data = array(); foreach ($accounts as $account) { $customers = Customer::where('account_id', $account->id)->get(); $account_children = array(); foreach ($customers as $customer) { $areas = Area::where('customer_id', $customer->id)->get(); $customer_children = array(); foreach ($areas as $area) { $regions = Region::where('area_id', $area->id)->get(); $area_children = array(); foreach ($regions as $region) { $distributors = Distributor::where('region_id', $region->id)->get(); $region_children = array(); foreach ($distributors as $distributor) { $stores = Store::where('distributor_id', $distributor->id)->get(); $distributor_children = array(); foreach ($stores as $store) { $distributor_children[] = array('title' => $store->store, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id . "." . $distributor->id . "." . $store->id); } $region_children[] = array('select' => true, 'title' => $distributor->distributor, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id . "." . $distributor->id, 'children' => $distributor_children); } $area_children[] = array('select' => true, 'title' => $region->region, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id, 'children' => $region_children); } $customer_children[] = array('select' => true, 'title' => $area->area, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id, 'children' => $area_children); } $account_children[] = array('select' => true, 'title' => $customer->customer, 'isFolder' => true, 'key' => $account->id . "." . $customer->id, 'children' => $customer_children); } $data[] = array('title' => $account->account, 'isFolder' => true, 'key' => $account->id, 'children' => $account_children); } return response()->json($data); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['distributor' => 'required|max:100|unique_with:distributors, distributor_code = distributor_code', 'distributor_code' => 'required|not_in:0']); \DB::beginTransaction(); try { $distributor = new Distributor(); $distributor->distributor_code = $request->distributor_code; $distributor->distributor = $request->distributor; $distributor->save(); \DB::commit(); Session::flash('flash_message', 'Distributor successfully added!'); return redirect()->route("distributor.index"); } catch (Exception $e) { DB::rollBack(); return redirect()->back(); } }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $pharmacists = Session::get('data.pharmacy')->pharmacists; $drugs = Drug::owned()->get(); $distributors = Distributor::where('pharmacy_id', Session::get('data.pharmacy')->id)->get(); $create = true; return view('inventory.create', compact('pharmacists', 'drugs', 'create', 'distributors')); }
public function run() { DB::table('distributors')->delete(); Distributor::create(['distributor' => 'AGR', 'name' => 'Agro Distribution', 'address' => '427 Hwy 860', 'city' => 'Delhi', 'state' => 'LA', 'zip' => 71232, 'contact' => 'Katy Perry', 'email' => '--', 'phone' => '3187223490']); Distributor::create(['distributor' => "JWG", 'name' => "Jones Wines & Grains", 'address' => '17 Plantin Row', 'city' => 'Marksville', 'state' => 'LA', 'zip' => 71351, 'contact' => 'Taylor Swift', 'email' => '*****@*****.**', 'phone' => '3182908839']); Distributor::create(['distributor' => 'CPS', 'name' => 'Crop Production Services', 'address' => '5 Main Street', 'city' => 'Monroe', 'state' => 'LA', 'zip' => 71269, 'contact' => 'Barbra Streisand', 'email' => '*****@*****.**', 'phone' => '7775551212']); Distributor::create(['distributor' => 'GPA', 'name' => 'Greenpoint Agency', 'address' => '99 Green Point Drive', 'city' => 'New Orleans', 'state' => 'LA', 'zip' => 70123, 'contact' => 'Neil Diamond', 'email' => '*****@*****.**', 'phone' => '8885551212']); Distributor::create(['distributor' => 'HEL', 'name' => 'Helena', 'address' => '1 Helena Road', 'city' => 'Helana', 'state' => 'AR', 'zip' => 41000, 'contact' => 'James Brown', 'email' => '*****@*****.**', 'phone' => '9995551212']); Distributor::create(['distributor' => 'JSI', 'name' => 'Sanders Inc', 'address' => '5 Ellis Lane', 'city' => 'Rayville', 'state' => 'LA', 'zip' => 71269, 'contact' => 'Billy Joel', 'phone' => '3187283235', 'email' => '*****@*****.**']); }
public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Distributor::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $lookup = OsaLookup::with('categories')->findOrFail($id); $customers = Customer::getLists(); $regions = Region::getLists(); $distributors = Distributor::getLists(); $templates = AuditTemplate::getLists(); $categories = FormCategory::osaTagging(); $stores = Store::getLists(); return view('osalookup.edit', compact('lookup', 'sostags', 'customers', 'regions', 'distributors', 'templates', 'categories', 'stores')); }
public function run() { $start_date = ''; $end_date = ''; $folderpath = 'database/seeds/seed_files'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", $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; } } $file_path = $folderpath . "/" . $latest . "/Store Mapping.xlsx"; echo (string) $file_path, "\n"; // dd($file_path); Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); DB::table('audit_templates')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->template)) { $template = AuditTemplate::where('template', $row->template)->first(); if (count($template) == 0) { $newtemplate = new AuditTemplate(); $newtemplate->template_code = $row->channel_code; $newtemplate->template = $row->template; $newtemplate->save(); } } }); }); DB::table('grade_matrixs')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->enrollment_type)) { $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); if (count($matrix) == 0) { $newmatrix = new GradeMatrix(); $newmatrix->desc = $row->enrollment_type; $newmatrix->save(); } } }); }); DB::table('users')->truncate(); DB::table('role_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->fullname)) { $userlist = explode("/", $row->fullname); $emaillist = explode("/", $row->email); // dd($row); for ($i = 0; $i < count($userlist); $i++) { $user = User::where('username', $row->username)->first(); if (count($user) == 0) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $newuser = User::create(array('name' => strtoupper($userlist[$i]), 'email' => $email, 'username' => $row->username, 'password' => Hash::make('password'))); $newuser->roles()->attach(3); } else { // $user->name = strtoupper($row->fullname); // $user->username = $row->username; // $user->email = strtolower($row->email); // $user->update(); // if(!$user->hasRole('field')){ // $user->roles()->attach(3); // } // echo $user->hasRole('field'); } } } }); }); DB::table('accounts')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (count($account) == 0) { $newaccount = new Account(); $newaccount->account = $row->account; $newaccount->save(); } } }); }); DB::table('customers')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { // var_dump($row); $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (count($customer) == 0) { $newcustomer = new Customer(); $newcustomer->account_id = $account->id; $newcustomer->customer_code = $row->customer_code; $newcustomer->customer = $row->customer; $newcustomer->save(); } } } }); }); DB::table('areas')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $area = Area::where('customer_id', $customer->id)->where('area', $row->area)->first(); if (count($area) == 0) { $newarea = new Area(); $newarea->customer_id = $customer->id; $newarea->area = $row->area; $newarea->save(); } } } } }); }); DB::table('regions')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $region = Region::where('region_code', $row->region_code)->where('region', $row->region)->first(); if (count($region) == 0) { $newregion = new Region(); $newregion->region_code = $row->region_code; $newregion->region = $row->region; $newregion->save(); } } }); }); DB::table('distributors')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $dis = Distributor::where('distributor_code', $row->distributor_code)->where('distributor', $row->distributor)->first(); if (count($dis) == 0) { $newdis = new Distributor(); $newdis->distributor_code = $row->distributor_code; $newdis->distributor = strtoupper($row->distributor); $newdis->save(); } } }); }); DB::table('stores')->truncate(); DB::table('store_user')->truncate(); Excel::selectSheets('Sheet1')->load($file_path, function ($reader) { $records = $reader->get(); $records->each(function ($row) { if (!is_null($row->account)) { $account = Account::where('account', $row->account)->first(); if (!empty($account)) { $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first(); if (!empty($customer)) { $region = Region::where('region_code', $row->region_code)->first(); $dis = Distributor::where('distributor_code', $row->distributor_code)->first(); $store = Store::where('account_id', $account->id)->where('customer_id', $customer->id)->where('region_id', $region->id)->where('distributor_id', $dis->id)->where('store_code', $row->store_code)->where('store', $row->store_name)->first(); if (count($store) == 0) { $template = AuditTemplate::where('template', $row->template)->first(); $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first(); $newstore = new Store(); $newstore->account_id = $account->id; $newstore->customer_id = $customer->id; $newstore->region_id = $region->id; $newstore->distributor_id = $dis->id; $newstore->store_code = $row->store_code; $newstore->store = $row->store_name; $newstore->grade_matrix_id = $matrix->id; $newstore->audit_template_id = $template->id; $newstore->save(); $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $newstore->users()->attach($user->id); } } else { $emaillist = explode("/", $row->email); for ($i = 0; $i < count($emaillist); $i++) { if (empty($emaillist[$i])) { $email = strtolower($row->username . "@unilever.com"); } else { $email = strtolower($emaillist[$i]); } $user = User::where('email', $email)->first(); $store->users()->attach($user->id); } } } } } }); }); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $store = Store::findOrFail($id); $distributors = Distributor::getLists(); $audittemplates = AuditTemplate::getLists(); $passings = GradeMatrix::getLists(); $categories = FormCategory::sosTagging(); $sostags = SosTagging::all(); $storesos = StoreSosTag::where('store_id', $store->id)->get(); return view('store.edit', compact('store', 'distributors', 'audittemplates', 'passings', 'categories', 'sostags', 'storesos')); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(CreateDistributorRequest $request, $id) { $distributor_details = Distributor::findOrFail($id); $distributor_details->update($request->all()); $distributors = Distributor::where('pharmacy_id', Session::get('data.pharmacy')->id)->get(); return response()->json(['success' => true, 'message' => 'Pharmacy distributor has been added', 'redirect' => 'distributor']); }