<!-- images section -->


<div id="img-section" class="no-print">

    <?php 
$docs = Document::where('pr_id', $purchase->id)->first();
$attachmentc = DB::table('attachments')->where('doc_id', $docs->id)->count();
if ($attachmentc != 0) {
    echo "<h3>" . "Attachments" . "</h3>";
}
$luser = Auth::user()->id;
$count = Count::where('doc_id', '=', $docs->id)->where('user_id', '=', $luser)->delete();
$attachments = DB::table('attachments')->where('doc_id', $docs->id)->get();
$srclink = "uploads\\";
?>

    @foreach ($attachments as $attachment)
    <div class="image-container">
        <a href="{{asset('uploads/'.$attachment->data)}}" data-lightbox="{{$attachment->data}}" title="{{$attachment->data}}">
            <img class="img-thumbnail" src="{{asset('uploads/'.$attachment->data)}}" style="width: 100px; height: 100px;" />
        </a>

    </div>
    @endforeach

</div>
                    <th width="10%">Action</th>
                @endif
                @endif
            </tr>
        </thead>
        <tbody>
            @foreach($requests as $request)
                <tr id="content"
                    <?php 
$useroffice = Auth::user()->office_id;
$doc = new Document();
$doc = DB::table('document')->where('pr_id', $request->id)->first();
$doc_id = $doc->id;
$userx = Auth::User()->id;
$counter = 0;
$counter = Count::where('user_id', $userx)->where('doc_id', $doc_id)->count();
if ($counter != 0) {
    echo "class ='success'";
}
?>
                >
                    <td><?php 
echo str_pad($request->controlNo, 5, '0', STR_PAD_LEFT);
?>
</td>
                    <td>
                        <a data-toggle="tooltip" data-placement="top" class="purpose" href="{{ URL::to('purchaseRequest/vieweach/'. $request->id) }}" title="View Project Details">
                            {{ $request->projectPurpose; }}
                        </a>
                    </td>
                    <?php 
 public function done()
 {
     $taskdetails_id = Input::get('taskdetails_id');
     $taskd = TaskDetails::find($taskdetails_id);
     $taskd->status = "Done";
     $docs = Document::find($taskd->doc_id);
     $id = $docs->pr_id;
     $delcount = Count::where('doc_id', $docs->id)->delete();
     $users = User::get();
     foreach ($users as $user) {
         $count = new Count();
         $count->user_id = $user->id;
         $count->doc_id = $docs->id;
         $count->save();
     }
     $birth = new DateTime($taskd->dateReceived);
     $today = new DateTime();
     $diff = $birth->diff($today);
     $aDays = $diff->format('%d');
     $taskd->daysOfAction = $aDays;
     $taskd->dateFinished = $today;
     $taskd->save();
     date_default_timezone_set("Asia/Manila");
     $upDate = date('Y-m-d H:i:s');
     DB::table('purchase_request')->where('id', $id)->update(array('updated_at' => $upDate));
     $tasknext = TaskDetails::find($taskdetails_id + 1);
     if ($tasknext->doc_id == $taskd->doc_id) {
         $counter = 1;
         $tasknext = TaskDetails::find($taskdetails_id + $counter);
         while ($tasknext->status == "Lock") {
             $counter = $counter + 1;
             $tasknext = TaskDetails::find($taskdetails_id + $counter);
         }
         $tasknext->status = "New";
         $tasknext->save();
     } else {
         $purchase = Purchase::find($docs->pr_id);
         $purchase->status = "Closed";
         $purchase->save();
     }
     $request_id = Input::get('pr_id');
     return Redirect::to("purchaseRequest/vieweach/{$request_id}");
 }
 public function philgeps()
 {
     Session::put('goToChecklist', 'true');
     //Initializations
     $referenceno = strip_tags(Input::get('referenceno'));
     $datepublished = Input::get('datepublished');
     $enddate = Input::get('enddate');
     $by = " " . strip_tags(Input::get('by'));
     $by = preg_replace('/\\s+/', ' ', $by);
     if ($by == " ") {
         $by = "None";
     }
     $taskdetails_id = Input::get('taskdetails_id');
     $check = 0;
     $taskd = TaskDetails::find($taskdetails_id);
     $docs = Document::find($taskd->doc_id);
     if ($taskd->status == "Done") {
         Session::put('errorchecklist', 'Saved failed. Task was already completed by another user.');
         return Redirect::back();
     }
     //Validation Process
     if (ctype_alnum(str_replace(array(' ', '-', '.', ',', 'ñ', 'Ñ'), '', $by))) {
         $check = $check + 1;
     }
     if (ctype_alnum(str_replace(array(' ', '-', '.'), '', $referenceno))) {
         $check = $check + 1;
     }
     if ($check == 2) {
         $id = $docs->pr_id;
         $delcount = Count::where('doc_id', $docs->id)->delete();
         $userx = User::get();
         foreach ($userx as $userv) {
             $count = new Count();
             $count->user_id = $userv->id;
             $count->doc_id = $docs->id;
             $count->save();
         }
         Session::put('successchecklist', 'Task completed.');
         $taskd = TaskDetails::find($taskdetails_id);
         $taskd->status = "Done";
         $taskd->custom1 = $referenceno;
         $taskd->custom2 = $datepublished;
         $taskd->custom3 = $enddate;
         $taskd->assignee = $by;
         $taskd->save();
         $tasknext = TaskDetails::find($taskdetails_id + 1);
         $tasknextc = TaskDetails::where('id', $taskdetails_id + 1)->where('doc_id', $docs->pr_id)->count();
         date_default_timezone_set("Asia/Manila");
         $upDate = date('Y-m-d H:i:s');
         DB::table('purchase_request')->where('id', $id)->update(array('updated_at' => $upDate));
         DB::table('taskdetails')->where('id', $taskdetails_id)->update(array('dateFinished' => $upDate));
         if ($tasknextc != 0) {
             //Project Type Filter
             $counter = 1;
             $tasknext = TaskDetails::find($taskdetails_id + $counter);
             while ($tasknext->status == "Lock" || $tasknext->status == "Done") {
                 $counter = $counter + 1;
                 $tasknext = TaskDetails::find($taskdetails_id + $counter);
             }
             $tasknext->status = "New";
             $tasknext->save();
             //End Project Type Filter
         } else {
             $purchase = Purchase::find($docs->pr_id);
             $purchase->status = "Closed";
             $purchase->save();
             $request_id = Input::get('pr_id');
             return Redirect::to("purchaseRequest/vieweach/{$request_id}");
         }
     } else {
         Session::put('errorchecklist', 'Invalid input.');
         return Redirect::back()->withInput();
     }
     return Redirect::back();
 }