/**
  * Display a specific resource
  * In this case, PurchaseOrderDetails and Article for this PurchaseOrderDetail $id
  */
 public function show($id)
 {
     if (Entrust::can('receive') == false) {
         return redirect()->route('home');
     }
     Log::debug(__METHOD__ . '(' . __LINE__ . '):  id: ' . $id);
     // using an implementation of the ReceiveArticle Repository Interface
     $purchaseOrderDetail = $this->purchaseOrderDetailRepository->find($id);
     // using an implementation of the ReceiveArticle Repository Interface
     $article = $this->articleRepository->find($purchaseOrderDetail->SKU);
     //dd($article);
     Session::put('podID', $purchaseOrderDetail->objectID);
     Session::put('articleID', $article->objectID);
     // calling into business logic
     ReceiveArticle::selectArticle($purchaseOrderDetail, $article);
     /*
      * if user has already selected a location, and now is associating a purchaseOrderDetail line
      * then we should associate the purchaseOrderDetail line with the location
      */
     if (Session::has('locationID')) {
         ReceiveArticle::setPurchaseOrderDetailLocation($purchaseOrderDetail->objectID, Session::get('locationID'));
     }
     // calling into business logic, calculate the UPCs grid
     $upcs = ReceiveArticle::receivedUPCsGrid($purchaseOrderDetail->objectID, $article->objectID);
     // retrieve ReceiptHistory, & current UserConversation
     $filter = ['POD' => $purchaseOrderDetail->objectID, 'Article' => $article->objectID, 'User_Name' => Auth::user()->name];
     $receiptHistories = $this->receiptHistoryRepository->filterOn($filter, 3)->reverse();
     $userConversations = $this->padReverse($this->userConversationRepository->filterOn($filter, 15));
     return view('pages.receiveArticle.show', compact('purchaseOrderDetail', 'article', 'upcs', 'receiptHistories', 'userConversations'));
 }
 /**
  * Merge a list Purchase Order Details and their Articles
  */
 public function mergePODetailWithArticle($filter)
 {
     $results = [];
     // get the PurchaseOrder
     $purchaseOrder = $this->purchaseOrderRepository->filterOn($filter, 1);
     $filter['Order_Number'] = $purchaseOrder->objectID;
     // get the PurchaseOrderDetails
     $purchaseOrderDetails = $this->purchaseOrderDetailRepository->filterOn($filter, 0);
     //dd($purchaseOrderDetails);
     if (isset($purchaseOrderDetails) && count($purchaseOrderDetails)) {
         // foreach purchaseOrderDetail record, merge with Article
         for ($i = 0; $i < count($purchaseOrderDetails); $i++) {
             $article = $this->articleRepository->find($purchaseOrderDetails[$i]->SKU);
             if (isset($article)) {
                 // build results
                 $result = ['purchaseOrderDetailID' => $purchaseOrderDetails[$i]->objectID, 'Expected_Qty' => $purchaseOrderDetails[$i]->Expected_Qty, 'articleID' => $article->objectID, 'Client_SKU' => $article->Client_SKU, 'Description' => $article->Description, 'UOM' => $article->UOM, 'Case_Pack' => $article->Case_Pack, 'Colour' => $article->Colour, 'Zone' => $article->Zone, 'rework' => isset($article->rework) ? $article->rework : ''];
                 // need a compound key here, for when multiple PODs point to the same Article
                 $key = $results[$article->Client_SKU . ', ' . $purchaseOrderDetails[$i]->objectID] = $result;
             }
         }
     }
     ksort($results);
     //dd(__METHOD__."(".__LINE__.")",compact('filter','purchaseOrder','purchaseOrderDetails','results'));
     $perPage = 10;
     if (Request::has('page')) {
         $bypass = $perPage * (Request::get('page') - 1) * -1;
     } else {
         $bypass = 0;
     }
     $thisPage = [];
     foreach ($results as $key => $value) {
         $bypass++;
         if ($bypass > 0) {
             $thisPage[] = $value;
         }
         if (count($thisPage) == $perPage) {
             break;
         }
     }
     $currentURL = Request::url();
     //dd(__METHOD__."(".__LINE__.")",compact('thisPage','results','bypass', 'currentURL'));
     return new LengthAwarePaginator($thisPage, count($results), $perPage, Request::get('page'), ['path' => Request::url()]);
 }
 /**
  * display the specific resource
  */
 public function show($id)
 {
     // using an implementation of the PurchaseOrderDetail Repository Interface
     $purchaseOrderDetail = $this->purchaseOrderDetailRepository->find($id);
     return view('pages.purchaseOrderDetail.show', compact('purchaseOrderDetail'));
 }