/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     foreach (StoreInventories::where('fixed', 0)->get() as $inventory) {
         $inventory_items = ItemInventories::where('store_inventory_id', $inventory->id)->get();
         foreach ($inventory_items as $item) {
             $t_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $item->other_barcode)->first();
             if (empty($t_item)) {
                 TempInventories::insert(array('id' => $item->id, 'store_inventory_id' => $item->store_inventory_id, 'division' => $item->division, 'category' => $item->category, 'category_long' => $item->category_long, 'sub_category' => $item->sub_category, 'brand' => $item->brand, 'sku_code' => $item->sku_code, 'other_barcode' => $item->other_barcode, 'description' => $item->description, 'description_long' => $item->description_long, 'lpbt' => $item->lpbt, 'conversion' => $item->conversion, 'ig' => $item->ig, 'fso_multiplier' => $item->fso_multiplier, 'sapc' => $item->sapc, 'whpc' => $item->whpc, 'whcs' => $item->whcs, 'so' => $item->so, 'fso' => $item->fso, 'fso_val' => $item->fso_val));
             }
         }
         $inventory->fixed = 1;
         $inventory->update();
         ItemInventories::where('store_inventory_id', $inventory->id)->delete();
         $store = Store::where('storeid', $inventory->store_id)->first();
         $skus = DB::table('store_items')->select('store_items.id', 'store_items.store_id', 'items.description', 'items.conversion', 'store_items.ig', 'store_items.fso_multiplier', 'items.lpbt', 'categories.category_long', 'sub_categories.sub_category', 'brands.brand', 'divisions.division', 'other_barcodes.other_barcode', 'items.sku_code')->join('stores', 'stores.id', '=', 'store_items.store_id')->join('items', 'items.id', '=', 'store_items.item_id')->join('other_barcodes', 'other_barcodes.item_id', '=', 'items.id')->join('categories', 'categories.id', '=', 'items.category_id')->join('sub_categories', 'sub_categories.id', '=', 'items.sub_category_id')->join('brands', 'brands.id', '=', 'items.brand_id')->join('divisions', 'divisions.id', '=', 'items.division_id')->whereRaw('other_barcodes.area_id = stores.area_id')->where('store_items.store_id', $store->id)->orderBy('items.id', 'asc')->get();
         foreach ($skus as $sku) {
             $temp_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $sku->other_barcode)->first();
             if (empty($temp_item)) {
                 $item2 = Item::with('division')->with('category')->with('subcategory')->with('brand')->where('sku_code', $sku->sku_code)->first();
                 $fso = $sku->ig;
                 if ($sku->fso_multiplier > $sku->ig) {
                     $fso = $sku->fso_multiplier;
                 }
                 ItemInventories::insert(['store_inventory_id' => $inventory->id, 'division' => $item2->division->division, 'category' => $item2->category->category, 'category_long' => $item2->category->category_long, 'sub_category' => $item2->subcategory->sub_category, 'brand' => $item2->brand->brand, 'sku_code' => $item2->sku_code, 'other_barcode' => $sku->other_barcode, 'description' => $item2->description, 'description_long' => $item2->description_long, 'lpbt' => $item2->lpbt, 'conversion' => $sku->conversion, 'ig' => $sku->ig, 'fso_multiplier' => $sku->fso_multiplier, 'sapc' => 0, 'whpc' => 0, 'whcs' => 0, 'so' => $sku->ig, 'fso' => $fso, 'fso_val' => $item2->lpbt * $sku->ig]);
             } else {
                 ItemInventories::insert(['store_inventory_id' => $temp_item->store_inventory_id, 'division' => $temp_item->division, 'category' => $temp_item->category, 'category_long' => $temp_item->category_long, 'sub_category' => $temp_item->sub_category, 'brand' => $temp_item->brand, 'sku_code' => $temp_item->sku_code, 'other_barcode' => $temp_item->other_barcode, 'description' => $temp_item->description, 'description_long' => $temp_item->description_long, 'lpbt' => $temp_item->lpbt, 'conversion' => $temp_item->conversion, 'ig' => $temp_item->ig, 'fso_multiplier' => $temp_item->fso_multiplier, 'sapc' => $temp_item->sapc, 'whpc' => $temp_item->whpc, 'whcs' => $temp_item->whcs, 'so' => $temp_item->so, 'fso' => $temp_item->fso, 'fso_val' => $temp_item->fso_val]);
             }
         }
     }
 }
Example #2
0
/**
 * Correct sequence of files attached to an item
 */
function correctFileSequence($item_id)
{
    $item = Item::with('files')->find($item_id);
    if ($item) {
        // get all files attached to this item
        $files = $item->files()->get();
        $seq = 1;
        // update the sequence nomber on each file
        foreach ($files as $file) {
            // get the actual file DB object and update it
            $file->pivot->update(['seq_no' => $seq]);
            $seq += 1;
        }
        $item->save();
    }
}
Example #3
0
 /**
  * Rebuild the search index
  * @return bool
  * @throws \Exception
  */
 public function reindex()
 {
     // Clear the search index
     if ($this->getIndex()->exists()) {
         $this->getIndex()->delete();
         $this->getIndex()->create();
     }
     // Get all items and reindex them
     Item::with('itemable')->chunk(100, function ($items) {
         $documents = [];
         foreach ($items as $item) {
             /* @var $itemable Searchable */
             $itemable = $item->itemable;
             $documents[] = new Document($itemable->getSearchableId(), $itemable->getSearchableBody());
         }
         $this->getTypedIndex()->addDocuments($documents);
     });
     return true;
 }
Example #4
0
 /**
  * PERMANENTLY DELETE all trashed items of a plan
  *
  */
 public function deleteAllTrashed($plan_id)
 {
     $plan = Plan::find($plan_id);
     // check if user is leader of the corresponding plan or author/admin
     if (!$plan->leader_id == Auth::user()->id || !Auth::user()->isAuthor()) {
         flash('Sorry, only plan leader or Author can delete items');
         return redirect()->back();
     }
     // this item should be restored
     $items = Item::with('files')->onlyTrashed()->where('plan_id', $plan_id);
     if (!$items) {
         return false;
     }
     $items->forceDelete();
     flash('All trashed items deleted');
     return \Redirect::back();
 }
Example #5
0
 /**
  * Get Discovered Tags
  *
  * @param TagRepositoryInterface $tagRepo
  * @param null $user
  * @return mixed
  */
 public function discovered(TagRepositoryInterface $tagRepo, $user = null)
 {
     // Get recent tags
     $tags = $tagRepo->recent(10)->lists('name');
     // Get items for recent tags
     $query = Item::with('itemable')->whereHas('tags', function ($query) use($tags) {
         $query->whereIn('name', $tags);
     })->where('itemable_type', 'App\\Models\\Link')->orderBy('created_at', 'desc');
     // If we have a user, exclude their tags
     if ($user) {
         $query->where('user_id', '<>', $user->id);
     }
     return $query->simplePaginate();
 }
 public function uploadassortment(Request $request)
 {
     $destinationPath = storage_path() . '/uploads/assortment/';
     $fileName = $request->file('data')->getClientOriginalName();
     $request->file('data')->move($destinationPath, $fileName);
     $filePath = storage_path() . '/uploads/assortment/' . $fileName;
     $filename_data = explode("-", $fileName);
     if (count($filename_data) == 6 && $filename_data[5] == '5.csv') {
         $storeid = $filename_data[0];
         $userid = $filename_data[1];
         $year = explode(".", $filename_data[4]);
         $transdate = date('Y-m-d', strtotime($year[0] . '-' . $filename_data[2] . '-' . $filename_data[3]));
         $imgname = explode(".", $fileName);
         $signature = 'IM_' . $imgname[0] . '.jpg';
         $store = Store::with('area')->with('enrollment')->with('distributor')->with('client')->with('channel')->with('customer')->with('region')->with('agency')->find($storeid);
         // dd($store->store_code);
         $user = User::find($userid);
         DB::beginTransaction();
         try {
             // dd($store);
             $store_inventory = AssortmentInventories::where('store_pri_id', $store->id)->where('transaction_date', $transdate)->first();
             if (!empty($store_inventory)) {
                 AssortmentItemInventories::where('store_inventory_id', $store_inventory->id)->delete();
                 $store_inventory->delete();
             }
             $store_inventory = AssortmentInventories::create(['area' => $store->area->area, 'enrollment_type' => $store->enrollment->enrollment, 'distributor_code' => $store->distributor->distributor_code, 'distributor' => $store->distributor->distributor, 'store_id' => $store->storeid, 'store_pri_id' => $store->id, 'store_code' => $store->store_code, 'store_code_psup' => $store->store_code_psup, 'store_name' => $store->store_name, 'client_code' => $store->client->client_code, 'client_name' => $store->client->client_name, 'channel_code' => $store->channel->channel_code, 'channel_name' => $store->channel->channel_desc, 'customer_code' => $store->customer->customer_code, 'customer_name' => $store->customer->customer_name, 'region_short_name' => $store->region->region_short, 'region_name' => $store->region->region, 'region_code' => $store->region->region_code, 'agency_code' => $store->agency->agency_code, 'agency' => $store->agency->agency_name, 'username' => $user->name, 'signature' => $signature, 'transaction_date' => $transdate]);
             $reader = ReaderFactory::create(Type::CSV);
             // for XLSX files
             $reader->setFieldDelimiter(';');
             $reader->open($filePath);
             $areas = ['MDC', 'ROSE PHARMACY', '360 PHARMACY', '360 DRUG', 'ST. JOSEPH DRUG', 'SOUTH STAR DRUG'];
             foreach ($reader->getSheetIterator() as $sheet) {
                 foreach ($sheet->getRowIterator() as $row) {
                     $item = Item::with('division')->with('category')->with('subcategory')->with('brand')->where('sku_code', trim($row[0]))->first();
                     if (!empty($item)) {
                         $store_item = StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->first();
                         $osa = 0;
                         $oos = 0;
                         $min_stock = 2;
                         if (in_array($store->area->area, $areas)) {
                             $min_stock = 3;
                         }
                         if (!isset($row[11])) {
                             if (!empty($store_item)) {
                                 $min_stock = $store_item->min_stock;
                             }
                         } else {
                             $min_stock = $row[11];
                         }
                         if ($row[1] > $min_stock) {
                             $osa = 1;
                         } else {
                             $oos = 1;
                         }
                         AssortmentItemInventories::insert(['store_inventory_id' => $store_inventory->id, 'division' => $item->division->division, 'category' => $item->category->category, 'category_long' => $item->category->category_long, 'sub_category' => $item->subcategory->sub_category, 'brand' => $item->brand->brand, 'sku_code' => $item->sku_code, 'other_barcode' => $row[7], 'description' => $item->description, 'description_long' => $item->description_long, 'lpbt' => $item->lpbt, 'conversion' => $row[10], 'ig' => $row[9], 'min_stock' => $min_stock, 'fso_multiplier' => $row[8], 'sapc' => $row[1], 'whpc' => $row[2], 'whcs' => $row[3], 'so' => $row[4], 'fso' => $row[5], 'fso_val' => $row[6], 'osa' => $osa, 'oos' => $oos]);
                     }
                 }
             }
             $reader->close();
             DB::commit();
             return response()->json(array('msg' => 'file uploaded', 'status' => 0));
         } catch (Exception $e) {
             DB::rollback();
             return response()->json(array('msg' => 'file uploaded error', 'status' => 1));
         }
     } else {
         return response()->json(array('msg' => 'Cannot upload file, invalid version', 'status' => 1));
     }
 }
Example #7
0
 /**
  * Change seq_no of a file 
  */
 public function move($item_id, $file_id, $direction)
 {
     $item = Item::with('files')->find($item_id);
     if ($item) {
         foreach ($item->files as $file) {
             if ($file->id == $file_id) {
                 $k = $file->pivot->seq_no;
                 if ($direction == 'up') {
                     $file->pivot->update(['seq_no' => $k - 1.1]);
                 }
                 if ($direction == 'down') {
                     $file->pivot->update(['seq_no' => $k + 1.1]);
                 }
             }
         }
         $item->save();
         // make sure all files atteched to this item have the correct seq no now
         correctFileSequence($item_id);
         return \Redirect::route('cspot.items.edit', [$item->plan_id, $item->id]);
     } else {
         flash('Error! Item with ID "' . $item_id . '" not found');
     }
     return \Redirect::back();
 }