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 . "/Store SOS.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('store_sos_tags')->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 (!empty($row[0])) {
                     // dd($row);
                     if ($cnt > 0) {
                         // dd($row);
                         $store = Store::where('store_code', $row[0])->first();
                         // dd($store);
                         $category = FormCategory::where('category', strtoupper($row[2]))->first();
                         // dd($category);
                         $sos = SosTagging::where('sos_tag', strtoupper($row[3]))->first();
                         // dd($sos);
                         StoreSosTag::insert(array('store_id' => $store->id, 'form_category_id' => $category->id, 'sos_tag_id' => $sos->id));
                         // echo (string)$row[0], "\n";
                     }
                     $cnt++;
                 }
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 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 . "/Secondary Display.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('secondary_displays')->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() == 'Sheet2') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if (!is_null($row[0])) {
                     if ($cnt > 0) {
                         $category = FormCategory::firstOrCreate(['category' => strtoupper($row[0])]);
                         $category->secondary_display = 1;
                         $category->update();
                         if (!empty($category)) {
                             SecondaryDisplay::create(array('category_id' => $category->id, 'brand' => $row[1]));
                         }
                     }
                     $cnt++;
                 }
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 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();
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $store = Store::findOrFail($id);
     $stores = Store::getLists();
     $categories = FormCategory::with(array('secondarybrand' => function ($query) {
         $query->orderBy('brand');
     }))->where('secondary_display', 1)->orderBy('category')->get();
     $list = SecondaryDisplayLookup::getLists($id);
     // dd($list);
     return view('secondarylookup.edit', compact('stores', 'categories', 'store', 'list'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $category = FormCategory::findOrFail($id);
     $this->validate($request, ['category' => 'required|max:100|unique_with:form_categories,' . $id]);
     \DB::beginTransaction();
     try {
         $category->category = $request->category;
         $category->secondary_display = $request->secondary_display ? 1 : 0;
         $category->osa_tagging = $request->osa_tagging ? 1 : 0;
         $category->sos_tagging = $request->sos_tagging ? 1 : 0;
         $category->custom = $request->custom ? 1 : 0;
         $category->perfect_store = $request->perfect_store ? 1 : 0;
         $category->update();
         \DB::commit();
         Session::flash('flash_message', 'Form Catagory successfully updated!');
         return redirect()->route("formcategory.edit", [$id]);
     } catch (Exception $e) {
         DB::rollBack();
         return redirect()->back();
     }
 }
 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 . "/Category Tagging.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->category)) {
                 $form_category = FormCategory::where('category', $row->category)->first();
                 // dd($form_category);
                 if (!empty($form_category)) {
                     $form_category->sos_tagging = $row->sos;
                     $form_category->osa_tagging = $row->osa;
                     $form_category->secondary_display = $row->secondary_display;
                     $form_category->update();
                 }
             }
         });
     });
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Ejemplo n.º 7
0
 /**
  * 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 storeform(Request $request, $id)
 {
     // dd($request->all());
     $this->validate($request, ['category' => 'required', 'group' => 'required', 'prompt' => 'required', 'formtype' => 'required']);
     \DB::beginTransaction();
     try {
         $template = AuditTemplate::find($id);
         $form_type = FormType::find($request->formtype);
         $prompt = $request->prompt;
         foreach ($request->category as $cat_id) {
             $category = FormCategory::find($cat_id);
             $cat_order = 1;
             $a_cat_id = 0;
             $clast_cnt = AuditTemplateCategory::getLastOrder($template->id);
             if (empty($clast_cnt)) {
                 $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                 $a_cat_id = $a_cat->id;
             } else {
                 $cat = AuditTemplateCategory::categoryExist($template->id, $category->id);
                 if (empty($cat)) {
                     $cat_order = $clast_cnt->category_order + 1;
                     $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                     $a_cat_id = $a_cat->id;
                 } else {
                     $a_cat_id = $cat->id;
                 }
             }
             foreach ($request->group as $grp_id) {
                 $group = FormGroup::find($grp_id);
                 $grp_order = 1;
                 $a_grp_id = 0;
                 $glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id);
                 if (empty($glast_cnt)) {
                     $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                     $a_grp_id = $a_grp->id;
                 } else {
                     $grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id);
                     if (empty($grp)) {
                         $grp_order = $glast_cnt->group_order + 1;
                         $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                         $a_grp_id = $a_grp->id;
                     } else {
                         $a_grp_id = $grp->id;
                     }
                 }
                 $form = Form::create(array('audit_template_id' => $template->id, 'form_type_id' => $form_type->id, 'prompt' => strtoupper($prompt), 'required' => $request->required == '1' ? 1 : 0, 'expected_answer' => $request->expected_answer == '1' ? 1 : 0, 'exempt' => $request->exempt == '1' ? 1 : 0));
                 if ($request->formtype == 9) {
                     $multiData = array();
                     foreach ($request->multiselect as $option) {
                         $multiData[] = array('form_id' => $form->id, 'multi_select_id' => $option);
                     }
                     if (count($multiData) > 0) {
                         FormMultiSelect::insert($multiData);
                     }
                 }
                 if ($request->formtype == 10) {
                     $singleData = array();
                     foreach ($request->singleselect as $option) {
                         $singleData[] = array('form_id' => $form->id, 'single_select_id' => $option);
                     }
                     if (count($singleData) > 0) {
                         FormSingleSelect::insert($singleData);
                     }
                 }
                 if ($request->formtype == 11) {
                     if ($request->has('formula')) {
                         $text = $request->formula;
                         preg_match_all('/:(.*?):/', $text, $matches);
                         $index = array();
                         foreach ($matches[1] as $value) {
                             $split_up = explode('_', $value);
                             $last_item = $split_up[count($split_up) - 1];
                             $index[] = $last_item;
                         }
                         $formula1 = $text;
                         foreach ($matches[1] as $key => $a) {
                             $formula1 = str_replace(':' . $a . ':', $index[$key], $formula1);
                         }
                         $formformula = new FormFormula();
                         $formformula->form_id = $form->id;
                         $formformula->formula = $formula1;
                         $formformula->formula_desc = $request->formula;
                         $formformula->save();
                     }
                 }
                 if ($request->formtype == 12) {
                     if ($request->has('condition')) {
                     }
                 }
                 $order = 1;
                 $a_frm_id = 0;
                 $last_cnt = AuditTemplateForm::getLastOrder($a_grp_id);
                 if (!empty($last_cnt)) {
                     $order = $last_cnt->order + 1;
                 }
                 AuditTemplateForm::insert(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id));
             }
         }
         \DB::commit();
         Session::flash('flash_message', 'Template successfully added!');
         return redirect()->route("audittemplate.form", $id);
     } catch (Exception $e) {
         DB::rollBack();
         Session::flash('flash_message', 'An error occured in adding form!');
         return redirect()->back();
     }
 }
 /**
  * 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'));
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $categories = FormCategory::secondaryDisplay()->lists('category', 'id');
     return view('secondarydisplay.create', compact('categories'));
 }
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('form_categories')->truncate();
     DB::table('form_groups')->truncate();
     DB::table('forms')->truncate();
     DB::table('single_selects')->truncate();
     DB::table('form_single_selects')->truncate();
     DB::table('multi_selects')->truncate();
     DB::table('form_multi_selects')->truncate();
     DB::table('form_formulas')->truncate();
     DB::table('form_conditions')->truncate();
     DB::table('audit_template_forms')->truncate();
     DB::table('audit_template_groups')->truncate();
     DB::table('audit_template_categories')->truncate();
     // \DB::beginTransaction();
     // try {
     $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;
         }
     }
     // $this->filename = $folderpath.$latest.'/mtprimarysales.csv';
     $files = File::allFiles($folderpath . "/" . $latest . "/templates");
     foreach ($files as $file) {
         echo (string) $file, "\n";
         $reader = ReaderFactory::create(Type::XLSX);
         // for XLSX files
         $reader->open($file);
         //   // Accessing the sheet name when reading
         foreach ($reader->getSheetIterator() as $sheet) {
             if ($sheet->getName() == 'Sheet1') {
                 $cnt = 0;
                 foreach ($sheet->getRowIterator() as $row) {
                     if ($cnt > 0) {
                         if ($row[1] != '') {
                             $start_date = $row[4];
                             $end_date = $row[5];
                             $template = AuditTemplate::firstOrCreate(['template' => $row[1]]);
                             $template->start_date = $start_date;
                             $template->end_date = $end_date;
                             $template->update();
                             $category = FormCategory::firstOrCreate(['category' => $row[3]]);
                             // dd($category);
                             $group = FormGroup::firstOrCreate(['group_desc' => $row[6]]);
                             $type = $row[11];
                             if (strtoupper($type) == 'DOUBLE') {
                                 $form_type = FormType::where('form_type', "NUMERIC")->first();
                             } else {
                                 $form_type = FormType::where('form_type', strtoupper($type))->first();
                             }
                             $image = "";
                             if (!empty($row[15])) {
                                 $image = $row[15];
                             }
                             if ($form_type->id == 11) {
                                 $index1 = array();
                                 $index2 = array();
                                 preg_match_all('/{(.*?)}/', $row[12], $matches);
                                 foreach ($matches[1] as $key => $a) {
                                     $data = DB::table('temp_forms')->where('code', $a)->first();
                                     if (!empty($data)) {
                                         $other_form = FormRepository::insertForm($template, $a, $data->type, $data->required, $data->prompt, $data->choices, $data->expected_answer, $image, null, null, null);
                                         $index1[$a] = $other_form->id;
                                         $index2[$a] = $other_form->prompt . '_' . $other_form->id;
                                     } else {
                                         $other_form = DB::table('forms')->where('code', $a)->first();
                                         // echo $a;
                                         if (empty($other_form)) {
                                             // dd($a);
                                         }
                                         // $other_form = FormRepository::insertForm($template,$a,$data->form_type_id,$data->required,$data->prompt,null,$data->expected_answer,null,$image);
                                         $index1[$a] = '!' . $other_form->id;
                                         $index2[$a] = $other_form->prompt . '_' . $other_form->id;
                                     }
                                 }
                                 $formula1 = $row[12];
                                 $formula2 = $row[12];
                                 foreach ($matches[1] as $key => $a) {
                                     $formula1 = str_replace('{' . $a . '}', $index1[$a], $formula1);
                                     $formula2 = str_replace('{' . $a . '}', ' :' . $index2[$a] . ': ', $formula2);
                                 }
                                 $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $formula1, null, $image, $formula2, null, null);
                             } elseif ($form_type->id == 12) {
                                 $options = explode("~", $row[12]);
                                 preg_match_all('/(.*?){(.*?)}/', $row[12], $matches);
                                 $data_con = array();
                                 $options = explode("~", $row[12]);
                                 foreach ($options as $option) {
                                     $with_value = preg_match('/{(.*?)}/', $option, $match);
                                     $x1 = array();
                                     $x2 = array();
                                     $_opt1 = "";
                                     $_opt2 = "";
                                     if ($with_value) {
                                         $codes = explode('^', $match[1]);
                                         if (count($codes) > 0) {
                                             foreach ($codes as $code) {
                                                 if ($code != '') {
                                                     $other_data = DB::table('temp_forms')->where('code', $code)->first();
                                                     if (empty($other_data)) {
                                                         $other_data = DB::table('forms')->where('code', $code)->first();
                                                     }
                                                     $other_form = FormRepository::insertForm($template, $code, $other_data->type, $other_data->required, $other_data->prompt, $other_data->choices, $other_data->expected_answer, null, null, null, null);
                                                     $x1[] = $other_form->id;
                                                     $x2[] = $other_form->prompt . '_' . $other_form->id;
                                                 }
                                             }
                                         }
                                         if (count($x1) > 0) {
                                             $_opt1 = implode("^", $x1);
                                         }
                                         if (count($x2) > 0) {
                                             $_opt2 = implode("^", $x2);
                                         }
                                     }
                                     $data_con[] = ['option' => strtoupper(strtok($option, '{')), 'condition' => $_opt1, 'condition_desc' => $_opt2];
                                 }
                                 // dd($data_con);
                                 $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $row[12], $row[14], $image, array(), $data_con, $row[16]);
                             } else {
                                 $form = FormRepository::insertForm($template, $row[7], $row[11], $row[10], $row[9], $row[12], $row[14], $image, null, null, $row[16]);
                             }
                             $cat_order = 1;
                             $a_cat_id = 0;
                             $clast_cnt = AuditTemplateCategory::getLastOrder($template->id);
                             if (empty($clast_cnt)) {
                                 $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                                 $a_cat_id = $a_cat->id;
                             } else {
                                 $cat = AuditTemplateCategory::categoryExist($template->id, $category->id);
                                 if (empty($cat)) {
                                     $cat_order = $clast_cnt->category_order + 1;
                                     $a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
                                     $a_cat_id = $a_cat->id;
                                 } else {
                                     $a_cat_id = $cat->id;
                                 }
                             }
                             $grp_order = 1;
                             $a_grp_id = 0;
                             $glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id);
                             if (empty($glast_cnt)) {
                                 $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                                 $a_grp_id = $a_grp->id;
                             } else {
                                 $grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id);
                                 if (empty($grp)) {
                                     $grp_order = $glast_cnt->group_order + 1;
                                     $a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
                                     $a_grp_id = $a_grp->id;
                                 } else {
                                     $a_grp_id = $grp->id;
                                 }
                             }
                             $order = 1;
                             $a_frm_id = 0;
                             $last_cnt = AuditTemplateForm::getLastOrder($a_grp_id);
                             if (!empty($last_cnt)) {
                                 $order = $last_cnt->order + 1;
                             }
                             AuditTemplateForm::create(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id));
                         }
                     }
                     $cnt++;
                 }
             }
             // }elseif($sheet->getName() == 'Others') {
             // 	// $cnt = 0;
             // 	// foreach ($sheet->getRowIterator() as $row) {
             // 	// 	if($cnt > 0){
             // 	// 		if(!is_null($row[2])){
             // 	// 			$prompt = addslashes($row[1]);
             // 	// 			DB::statement('INSERT INTO temp_forms (code, prompt, required, type, choices) VALUES ("'.$row[0].'","'.$prompt.'","'.$row[2].'","'.$row[3].'","'.$row[4].'");');
             // 	// 		}
             // 	// 	}
             // 	// 	$cnt++;
             // 	// }
             // }else{
             // }
         }
         $reader->close();
     }
     $users = User::all();
     foreach ($users as $user) {
         $mapping = UserMapping::where('user_name', $user->name)->where('start_date', $start_date)->where('end_date', $end_date)->first();
         if (!empty($mapping)) {
             $mapping->mapped_stores = $user->stores->count();
             $mapping->update();
         } else {
             UserMapping::create(['user_name' => $user->name, 'start_date' => $start_date, 'end_date' => $end_date, 'mapped_stores' => $user->stores->count()]);
         }
     }
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }