Exemple #1
0
function printS($id)
{
    $ci =& get_instance();
    $s = new Section();
    $s->get_by_id($id);
    $s->e = anchor($ci->app->app_url('edit/') . $s->id, 'Edit');
    $s->d = anchor($ci->app->app_url('delete/') . $s->id, 'Delete');
    $output = "<li>";
    $output .= $s->id . '|';
    $output .= $s->name;
    $output .= add($id, 0, "add first child for {$s->name}");
    $output .= '|';
    $output .= $s->e;
    $output .= '|';
    $output .= $s->d;
    $c = new Section();
    $c->where('parent_section', $id);
    $c->order_by('sort', 'asc');
    $c->get();
    if (count($c->all) > 0) {
        $output .= "<ul>";
        foreach ($c->all as $item) {
            $output .= printS($item->id);
            $output .= "<li>" . add($id, $item->sort + 1) . "</li>";
        }
        $output .= "</ul>";
    }
    $output .= "</li>";
    return $output;
}
 /**
  * delete that section with all it's subsections
  * plus eliminate the gap between it's siblings sort
  **/
 public function delete($object = '', $related_field = '')
 {
     if (empty($object)) {
         // update all the sections sort after that section
         // that in the same parent section
         $s = new Section();
         $s->where('sort >', $this->sort);
         $s->where('parent_section', $this->parent_section);
         $s->get();
         foreach ($s as $item) {
             $item->sort--;
             $item->save();
         }
     }
     //delete this section
     parent::delete($object, $related_field);
 }
 /**
  * Update the specified resource in storage.
  * PUT /sections/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $section = Section::where('id', $id)->update(Input::all());
     if ($section) {
         $data = Section::find($id);
         return ['status' => true, 'data' => $data];
     } else {
         return ['status' => false];
     }
 }
 /**
  * add section to system (the action page)
  * 
  * @return void
  */
 public function addaction()
 {
     $sort = new Section();
     $sort->where('parent_section', $this->input->post('parent_section'))->select_max('sort')->get();
     $sort = $sort->sort + 1;
     $s = new Section();
     $s->parent_section = $this->input->post('parent_section');
     $s->name = $this->input->post('name');
     $s->sort = $sort;
     $s->view = $this->input->post('view');
     $s->save();
     redirect('section_editor');
 }
//Cursor Component
//Count Cursor
$id = $purchase->id;
$docs = DB::table('document')->where('pr_id', '=', $id)->first();
$workflow = DB::table('workflow')->get();
$taskch = TaskDetails::where('doc_id', $docs->id)->where('status', 'New')->orWhere('status', 'Active')->count();
$taskexist = TaskDetails::where('doc_id', $docs->id)->count();
//Get Cursor Value
if ($taskch == 0) {
    $taskc = TaskDetails::where('doc_id', $docs->id)->where('status', 'Done')->orderBy('id', 'DESC')->first();
} else {
    $taskc = TaskDetails::where('doc_id', $docs->id)->where('status', 'New')->orWhere('status', 'Active')->first();
}
//Queries
$workflow = Workflow::find($docs->work_id);
$section = Section::where('workflow_id', $workflow->id)->orderBy('section_order_id', 'ASC')->get();
$taskd = TaskDetails::where('doc_id', $docs->id)->orderBy('id', 'ASC')->get();
$sectioncheck = 0;
$prdays = 0;
$lastid = 0;
if ($taskexist != 0) {
    foreach ($section as $sections) {
        $sectiondays = 0;
        $task = Task::where('section_id', $sections->section_order_id)->where('wf_id', $workflow->id)->orderBy('order_id', 'ASC')->get();
        echo "<div class='panel panel-success'><div class='panel-heading'><h3 class='panel-title'>" . $sections->section_order_id . ". " . $sections->sectionName . "</h3></div>";
        echo "<div class='panel-body'>";
        echo "<table border='1' class='workflow-table'>";
        //Addon Display
        $otherc = OtherDetails::where('section_id', $sections->id)->count();
        if ($otherc != 0) {
            $otherd = OtherDetails::where('section_id', $sections->id)->get();
 public function duplicatecvpage($cv_code)
 {
     $cv_old = Cv::where('cv_code', $cv_code)->first();
     if ($cv_old->user_id != Auth::id()) {
         return 'False';
     }
     $new_cv_name = $cv_old->cv_name . ' - Copy';
     $cv = new Cv();
     do {
         $random = str_random(10);
         $count = Cv::where('cv_code', $random)->count();
     } while ($count != 0);
     $cv->cv_code = $random;
     if (Auth::check()) {
         $cv->user_id = Auth::id();
     }
     $cv->cv_name = $new_cv_name;
     $cv->user_id = $cv_old->user_id;
     $cv->full_name = $cv_old->full_name;
     $cv->phone_num = $cv_old->phone_num;
     $cv->email = $cv_old->email;
     $cv->website = $cv_old->website;
     $cv->add_line1 = $cv_old->add_line1;
     $cv->add_line2 = $cv_old->add_line2;
     $cv->dob = $cv_old->dob;
     $cv->marital_status = $cv_old->marital_status;
     $cv->profile_image = $cv_old->profile_image;
     $cv->sex = $cv_old->sex;
     $cv->state_origin = $cv_old->state_origin;
     $cv->religion = $cv_old->religion;
     $cv->religion_text = $cv_old->religion_text;
     $cv->show_profile_pic = $cv_old->show_profile_pic;
     $cv->local_government = $cv_old->local_government;
     $cv->save();
     $new_cv_id = $cv->id;
     // copying sections
     $sections = Section::where('cv_id', $cv_old->id)->get();
     foreach ($sections as $section) {
         $section_new = new Section();
         $section_new->cv_id = $new_cv_id;
         $section_new->section_name = $section->section_name;
         $section_new->type = $section->type;
         $section_new->content = $section->content;
         $section_new->default = $section->default;
         $section_new->priority = $section->priority;
         $section_new->save();
     }
     // copying educations
     $educations = Education::where('cv_id', $cv_old->id)->get();
     foreach ($educations as $education) {
         $education_new = new Education();
         $education_new->cv_id = $new_cv_id;
         $education_new->coursename = $education->coursename;
         $education_new->institutename = $education->institutename;
         $education_new->add_line1 = $education->add_line1;
         $education_new->add_line2 = $education->add_line2;
         $education_new->startdate = $education->startdate;
         $education_new->enddate = $education->enddate;
         $education_new->otherinfo = $education->otherinfo;
         $education_new->priority = $education->priority;
         $education_new->save();
     }
     // copying languages
     $languages = Language::where('cv_id', $cv_old->id)->get();
     foreach ($languages as $language) {
         $language_new = new Language();
         $language_new->cv_id = $new_cv_id;
         $language_new->language_id = $language->language_id;
         $language_new->language_name = $language->language_name;
         $language_new->ability_id = $language->ability_id;
         $language_new->level_id = $language->level_id;
         $language_new->priority = $language->priority;
         $language_new->save();
     }
     // copying nysc
     $nyscs = Nysc::where('cv_id', $cv_old->id)->get();
     foreach ($nyscs as $nysc) {
         $nysc_new = new Nysc();
         $nysc_new->cv_id = $new_cv_id;
         $nysc_new->year = $nysc->year;
         $nysc_new->batch = $nysc->batch;
         $nysc_new->ppa = $nysc->ppa;
         $nysc_new->cd = $nysc->cd;
         $nysc_new->otherinfo = $nysc->otherinfo;
         $nysc_new->priority = $nysc->priority;
         $nysc_new->save();
     }
     // copying work_exp
     $work_exps = WorkExperience::where('cv_id', $cv_old->id)->get();
     foreach ($work_exps as $work_exp) {
         $work_exp_new = new WorkExperience();
         $work_exp_new->cv_id = $new_cv_id;
         $work_exp_new->title = $work_exp->title;
         $work_exp_new->company = $work_exp->company;
         $work_exp_new->location = $work_exp->location;
         $work_exp_new->startdate = $work_exp->startdate;
         $work_exp_new->enddate = $work_exp->enddate;
         $work_exp_new->otherinfo = $work_exp->otherinfo;
         $work_exp_new->priority = $work_exp->priority;
         $work_exp_new->save();
     }
     return Redirect::back();
 }
Exemple #7
0
 function deattach_section($section = '')
 {
     //=========================
     //normalize the  sort numbers
     //=========================
     $cont = new Section();
     // we have to push all the content up to fill that hole
     // these content must me in the same section,parent,cell
     // and have sort nubmer greater than that content
     $cont->where('parent_section', $section->parent_section);
     //same section
     $cont->where('sort >', $section->sort);
     //greater sort
     $cont->get();
     //get them to process
     foreach ($cont->all as $item) {
         $item->sort--;
         $item->save();
     }
 }
 public function create_submit()
 {
     //Image Upload
     $users = DB::table('users')->get();
     $purchasecheck = DB::table('purchase_request')->count();
     if ($purchasecheck != 0) {
         $purchase = Purchase::orderby('id', 'DESC')->first();
         $docs = Document::orderby('id', 'DESC')->first();
         $pr_id = $purchase->id + 1;
         $doc_id = $docs->id + 1;
     } else {
         $pr_id = 1;
         $doc_id = 1;
     }
     foreach (Input::file('file') as $file) {
         $rules = array('file' => 'required|mimes:png,gif,jpeg,jpg|max:900000000000000000000');
         $validator = \Validator::make(array('file' => $file), $rules);
         $destine = public_path() . "/uploads";
         if ($validator->passes()) {
             $ext = $file->guessClientExtension();
             // (Based on mime type)
             $ext = $file->getClientOriginalExtension();
             // (Based on filename)
             $filename = $file->getClientOriginalName();
             $archivo = value(function () use($file) {
                 $filename = str_random(10) . '.' . $file->getClientOriginalExtension();
                 return strtolower($filename);
             });
             $archivo = value(function () use($file) {
                 $date = date('m-d-Y-h-i-s', time());
                 $filename = $date . "-" . $file->getClientOriginalName();
                 return strtolower($filename);
             });
             $attach = new Attachments();
             $attach->doc_id = $doc_id;
             $attach->data = $archivo;
             $attach->save();
             $filename = $doc_id . "_" . $attach->id;
             $file->move($destine, $archivo);
             $target_folder = $destine;
             $upload_image = $target_folder . "/" . $archivo;
             $thumbnail = $target_folder . "/resize" . $archivo;
             $actual = $target_folder . "/" . $archivo;
             // THUMBNAIL SIZE
             list($width, $height) = getimagesize($upload_image);
             $newwidth = $width;
             $newheight = $height;
             while ($newheight > 525) {
                 $newheight = $newheight * 0.8;
                 $newwidth = $newwidth * 0.8;
             }
             $source = $upload_image;
             $ext = strtolower($ext);
             $thumb = imagecreatetruecolor($newwidth, $newheight);
             if ($ext == "jpg" || $ext == "jpeg") {
                 $source = imagecreatefromjpeg($upload_image);
             } elseif ($ext == "png") {
                 $source = imagecreatefrompng($upload_image);
             } elseif ($ext == "gif") {
                 $source = imagecreatefromgif($upload_image);
             } else {
                 continue;
             }
             // RESIZE
             imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
             // MAKE NEW FILES
             if ($ext == "jpg" || $ext == "jpeg") {
                 imagejpeg($thumb, $thumbnail, 100);
             } elseif ($ext == "png") {
                 imagepng($thumb, $thumbnail, 9);
             } elseif ($ext == "gif") {
                 imagegif($thumb, $thumbnail, 100);
             } else {
                 echo "An invalid image";
             }
             unlink($actual);
             // FILE RENAMES
             rename($thumbnail, $actual);
         } else {
             $errors = $validator->errors();
             Session::put('imgerror', 'Invalid file.');
         }
     }
     //End Image Upload
     $purchase = new Purchase();
     $document = new Document();
     $purchase->projectPurpose = strip_tags(Input::get('projectPurpose'));
     $purchase->sourceOfFund = strip_tags(Input::get('sourceOfFund'));
     $purchase->amount = Input::get('amount');
     $purchase->office = Input::get('office');
     $purchase->requisitioner = Input::get('requisitioner');
     if (!Input::get('dateRequested') == '') {
         $purchase->dateRequested = Input::get('dateRequested');
     }
     $purchase->dateReceived = Input::get('dateReceived');
     $purchase->status = 'Active';
     $purchase->otherType = Input::get('otherType');
     // Get latest control number
     $cn = Input::get('controlNo');
     $checkUniqueControlNo = Purchase::where('controlNo', '=', "{$cn}")->count();
     if ($checkUniqueControlNo != 0) {
         $purchase->controlNo = '';
     } else {
         $purchase->controlNo = Input::get('controlNo');
     }
     if (Input::get('otherType') == 'Pakyaw') {
         $purchase->projectType = "None";
     } else {
         $purchase->projectType = Input::get('projectType');
     }
     // Set creator id
     $user_id = Auth::user()->id;
     $purchase->created_by = $user_id;
     $purchase_save = $purchase->save();
     if ($purchase_save && (Session::get('imgerror') == NULL || !Input::hasfile('file'))) {
         $document->pr_id = $purchase->id;
         $document->work_id = Input::get('hide_modeOfProcurement');
         $document_save = $document->save();
         if ($document_save) {
             $doc_id = $document->id;
             $workflow = Workflow::find($document->work_id);
             $section = Section::where('workflow_id', $document->work_id)->orderBy('section_order_id', 'ASC')->get();
             $firstnew = 0;
             // Set due date;
             $new_purchase = Purchase::find($purchase->id);
             $workflow_id = Input::get('hide_modeOfProcurement');
             $workflow = Workflow::find($workflow_id);
             $addToDate = $workflow->totalDays;
             date_default_timezone_set("Asia/Manila");
             $dueDate = date('Y-m-d H:i:s', strtotime("+{$addToDate} days"));
             $new_purchase->dueDate = $dueDate;
             $new_purchase->save();
             $tasks = Task::where('wf_id', $document->work_id)->orderBy('section_id', 'ASC')->orderBy('order_id', 'ASC')->get();
             foreach ($tasks as $task) {
                 $task_details = new TaskDetails();
                 $task_details->task_id = $task->id;
                 $stringamount = $new_purchase->amount;
                 $stringamount = str_replace(str_split(','), '', $stringamount);
                 $amount = (double) $stringamount;
                 if ($firstnew == 0) {
                     $task_details->status = "New";
                 } else {
                     $task_details->status = "Pending";
                 }
                 //Project Type
                 if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT" || $task->taskName == "PRE-BID CONFERENCE") {
                     $task_details->status = "Lock";
                     if ($new_purchase->projectType == "Goods/Services") {
                         if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") {
                             if ($amount > 2000000) {
                                 $task_details->status = "Pending";
                             }
                         } else {
                             if ($task->taskName == "PRE-BID CONFERENCE") {
                                 if ($amount > 1000000) {
                                     $task_details->status = "Pending";
                                 }
                             }
                         }
                     } elseif ($new_purchase->projectType == "Infrastructure") {
                         if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") {
                             if ($amount > 5000000) {
                                 $task_details->status = "Pending";
                             }
                         } else {
                             if ($task->taskName == "PRE-BID CONFERENCE") {
                                 if ($amount > 1000000) {
                                     $task_details->status = "Pending";
                                 }
                             }
                         }
                     } elseif ($new_purchase->projectType == "Consulting Services") {
                         if ($amount > 1000000) {
                             $task_details->status = "Pending";
                         }
                     }
                 }
                 //End Project Type
                 $firstnew = 1;
                 $task_details->doc_id = $document->id;
                 $task_details->save();
             }
             $users = User::all();
             foreach ($users as $user) {
                 $count = new Count();
                 $count->user_id = $user->id;
                 $count->doc_id = $doc_id;
                 $count->save();
             }
             $pr_id = Session::get('pr_id');
             DB::table('attachments')->where('doc_id', $doc_id)->update(array('saved' => 1));
             DB::table('attachments')->where('saved', '=', 0)->delete();
             Session::forget('doc_id');
             if (!Input::hasfile('file')) {
                 Session::forget('imgerror');
             }
             $connected = @fsockopen("www.google.com", 80);
             //website, port  (try 80 or 443)
             if ($connected) {
                 $sendee = DB::table('users')->where('id', $purchase->requisitioner)->first();
                 $email = $sendee->email;
                 $fname = $sendee->firstname;
                 $data = ['id' => $purchase->id];
                 Mail::send('emails.template', $data, function ($message) use($email, $fname) {
                     $message->from('*****@*****.**', 'Procurement Tracking System Tarlac');
                     $message->to($email, $fname)->subject('Tarlac Procurement Tracking System: New Purchase Request Created');
                 });
                 $notice = "Purchase request created successfully. ";
             } else {
                 $notice = "Purchase request created successfully. Email notice was not sent. ";
             }
             // Insert data to reports table
             $date_received = Input::get('dateReceived');
             $date_received = substr($date_received, 0, strrpos($date_received, ' '));
             $reports = Reports::whereDate($date_received)->first();
             if ($reports == null) {
                 $reports = new Reports();
                 $reports->date = $date_received;
                 $reports->pRequestCount = 1;
             } else {
                 $reports->pRequestCount = $reports->pRequestCount + 1;
             }
             $reports->save();
             //End Reports
             Session::put('notice', $notice);
             $office = Office::all();
             $users = User::all();
             $workflow = Workflow::all();
             return Redirect::to('purchaseRequest/view');
             Session::put('imgsuccess', 'Files uploaded.');
         } else {
             $message = "Failed to create purchase request.";
             Session::put('main_error', $message);
             // Get Other Error Messages
             $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
             $error_projectType = $purchase->validationErrors->first('projectType');
             $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
             $error_amount = $purchase->validationErrors->first('amount');
             $error_office = $purchase->validationErrors->first('office');
             $error_requisitioner = $purchase->validationErrors->first('requisitioner');
             $error_dateRequested = $purchase->validationErrors->first('dateRequested');
             $error_dateReceived = $purchase->validationErrors->first('dateReceived');
             $error_controlNo = $purchase->validationErrors->first('controlNo');
             // Inserting Error Message To a Session
             Session::put('error_projectPurpose', $error_projectPurpose);
             Session::put('error_sourceOfFund', $error_sourceOfFund);
             Session::put('error_amount', $error_amount);
             Session::put('error_office', $error_office);
             Session::put('error_requisitioner', $error_requisitioner);
             Session::put('error_dateRequested', $error_dateRequested);
             Session::put('error_dateReceived', $error_dateReceived);
             Session::put('error_projectType', $error_projectType);
             Session::put('error_controlNo', $error_controlNo);
             if ($checkUniqueControlNo != 0) {
                 Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.');
             }
             if (Input::get('hide_modeOfProcurement') == "") {
                 Session::put('m6', 'required');
             }
             Session::put('imgsuccess', 'Files uploaded.');
             return Redirect::back()->withInput();
         }
     } else {
         // Set Main Error
         $message = "Failed to create purchase request.";
         Session::put('main_error', $message);
         if (!Input::hasfile('file')) {
             Session::forget('imgerror');
         }
         // Get Other Error Messages
         $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
         $error_projectType = $purchase->validationErrors->first('projectType');
         $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
         $error_amount = $purchase->validationErrors->first('amount');
         $error_office = $purchase->validationErrors->first('office');
         $error_requisitioner = $purchase->validationErrors->first('requisitioner');
         $error_dateRequested = $purchase->validationErrors->first('dateRequested');
         $error_dateReceived = $purchase->validationErrors->first('dateReceived');
         $error_controlNo = $purchase->validationErrors->first('controlNo');
         // Inserting Error Message To a Session
         Session::put('error_projectPurpose', $error_projectPurpose);
         Session::put('error_sourceOfFund', $error_sourceOfFund);
         Session::put('error_amount', $error_amount);
         Session::put('error_office', $error_office);
         Session::put('error_requisitioner', $error_requisitioner);
         Session::put('error_dateRequested', $error_dateRequested);
         Session::put('error_dateReceived', $error_dateReceived);
         Session::put('error_projectType', $error_projectType);
         Session::put('error_controlNo', $error_controlNo);
         if ($checkUniqueControlNo != 0) {
             Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.');
         }
         if (Input::get('hide_modeOfProcurement') == "") {
             Session::put('error_modeOfProcurement', 'required');
         }
         if (Session::get('imgerror') && Input::hasfile('file')) {
             $failedpurchasecount = Purchase::where('id', $purchase->id)->count();
             if ($failedpurchasecount != 0) {
                 $failedpurchase = Purchase::find($purchase->id);
                 $failedpurchase->delete();
             }
             Session::forget('imgsuccess');
             //Image Error Return
             $task_details = TaskDetails::where('doc_id', $document->id)->delete();
             $document->delete();
             $message = "Failed to create purchase request.";
             // Set Main Error
             $message = "Failed to save purchase request.";
             Session::put('main_error', $message);
             // Get Other Error Messages
             $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
             $error_projectType = $purchase->validationErrors->first('projectType');
             $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
             $error_amount = $purchase->validationErrors->first('amount');
             $error_office = $purchase->validationErrors->first('office');
             $error_requisitioner = $purchase->validationErrors->first('requisitioner');
             $error_dateRequested = $purchase->validationErrors->first('dateRequested');
             $error_dateReceived = $purchase->validationErrors->first('dateReceived');
             $error_controlNo = $purchase->validationErrors->first('controlNo');
             // Inserting Error Message To a Session
             Session::put('error_projectPurpose', $error_projectPurpose);
             Session::put('error_sourceOfFund', $error_sourceOfFund);
             Session::put('error_amount', $error_amount);
             Session::put('error_office', $error_office);
             Session::put('error_requisitioner', $error_requisitioner);
             Session::put('error_dateRequested', $error_dateRequested);
             Session::put('error_dateReceived', $error_dateReceived);
             Session::put('error_projectType', $error_projectType);
             Session::put('error_controlNo', $error_controlNo);
             if ($checkUniqueControlNo != 0) {
                 Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.');
             }
         }
         return Redirect::back()->withInput();
     }
 }
 public function janisawesome()
 {
     function generateRandomString($length = 10)
     {
         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $randomString = '';
         for ($i = 0; $i < $length; $i++) {
             $randomString .= $characters[rand(0, strlen($characters) - 1)];
         }
         return $randomString;
     }
     function generateRandomAmount()
     {
         $length = rand(4, 8);
         $randomString = '';
         for ($i = 0; $i < $length; $i++) {
             $randomString .= rand(1, 9);
         }
         return $randomString;
     }
     $numLoop = 1;
     while ($numLoop < 301) {
         $purchase = new Purchase();
         $document = new Document();
         $purchase->projectPurpose = generateRandomString();
         $purchase->sourceOfFund = generateRandomString();
         $controlAmt = generateRandomAmount();
         $controlAmt .= ".00";
         $purchase->amount = number_format($controlAmt);
         $purchase->office = "1";
         $purchase->requisitioner = "1";
         $purchase->dateRequested = date('Y-m-d H:i:s');
         $purchase->dateReceived = date('Y-m-d H:i:s');
         $purchase->status = 'Active';
         $purchase->otherType = " ";
         // Get latest control number
         $cn = 0;
         $purchase_controlNo = Purchase::orderBy('ControlNo', 'DESC')->first();
         if (!$purchase_controlNo == NuLL) {
             $cn = $purchase_controlNo->controlNo;
         }
         $cn += 1;
         $purchase->controlNo = $cn;
         if (Input::get('otherType') == ' ') {
             $purchase->projectType = "None";
         } else {
             $purchase->projectType = "None";
         }
         // Set creator id
         $user_id = Auth::user()->id;
         $purchase->created_by = $user_id;
         $purchase_save = $purchase->save();
         if ($purchase_save) {
             if ($controlAmt < 50000) {
                 $amtControl = 1;
             } else {
                 if ($controlAmt >= 50000 && $controlAmt <= 500000) {
                     $amtControl = 2;
                 } else {
                     if ($controlAmt >= 500000) {
                         $amtControl = 3;
                     }
                 }
             }
             $document->pr_id = $purchase->id;
             $document->work_id = $amtControl;
             $document_save = $document->save();
             if ($document_save) {
                 $doc_id = $document->id;
                 $workflow = Workflow::find($document->work_id);
                 $section = Section::where('workflow_id', $document->work_id)->orderBy('section_order_id', 'ASC')->get();
                 $firstnew = 0;
                 // Set due date;
                 $new_purchase = Purchase::find($purchase->id);
                 $workflow_id = "1";
                 $workflow = Workflow::find($workflow_id);
                 $addToDate = $workflow->totalDays;
                 date_default_timezone_set("Asia/Manila");
                 $dueDate = date('Y-m-d H:i:s', strtotime("+{$addToDate} days"));
                 $new_purchase->dueDate = $dueDate;
                 $new_purchase->save();
                 $tasks = Task::where('wf_id', $document->work_id)->orderBy('section_id', 'ASC')->orderBy('order_id', 'ASC')->get();
                 foreach ($tasks as $task) {
                     $task_details = new TaskDetails();
                     $task_details->task_id = $task->id;
                     $stringamount = $new_purchase->amount;
                     $stringamount = str_replace(str_split(','), '', $stringamount);
                     $amount = (double) $stringamount;
                     if ($firstnew == 0) {
                         $task_details->status = "New";
                     } else {
                         $task_details->status = "Pending";
                     }
                     //Project Type
                     if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT" || $task->taskName == "PRE-BID CONFERENCE") {
                         $task_details->status = "Lock";
                         if ($new_purchase->projectType == "Goods/Services") {
                             if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") {
                                 if ($amount > 2000000) {
                                     $task_details->status = "Pending";
                                 }
                             } else {
                                 if ($task->taskName == "PRE-BID CONFERENCE") {
                                     if ($amount > 1000000) {
                                         $task_details->status = "Pending";
                                     }
                                 }
                             }
                         } elseif ($new_purchase->projectType == "Infrastructure") {
                             if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") {
                                 if ($amount > 5000000) {
                                     $task_details->status = "Pending";
                                 }
                             } else {
                                 if ($task->taskName == "PRE-BID CONFERENCE") {
                                     if ($amount > 1000000) {
                                         $task_details->status = "Pending";
                                     }
                                 }
                             }
                         } elseif ($new_purchase->projectType == "Consulting Services") {
                             if ($amount > 1000000) {
                                 $task_details->status = "Pending";
                             }
                         }
                     }
                     //End Project Type
                     $firstnew = 1;
                     $task_details->doc_id = $document->id;
                     $task_details->save();
                 }
                 $users = User::all();
                 foreach ($users as $user) {
                     $count = new Count();
                     $count->user_id = $user->id;
                     $count->doc_id = $doc_id;
                     $count->save();
                 }
                 $pr_id = Session::get('pr_id');
                 DB::table('attachments')->where('doc_id', $doc_id)->update(array('saved' => 1));
                 DB::table('attachments')->where('saved', '=', 0)->delete();
                 Session::forget('doc_id');
                 $connected = true;
                 // $connected = @fsockopen("www.google.com", 80);  //website, port  (try 80 or 443)
                 if (!$connected) {
                     $sendee = DB::table('users')->where('id', $purchase->requisitioner)->first();
                     $email = $sendee->email;
                     $fname = $sendee->firstname;
                     $data = ['id' => $purchase->id];
                     Mail::send('emails.template', $data, function ($message) use($email, $fname) {
                         $message->from('*****@*****.**', 'Procurement Tracking System Tarlac');
                         $message->to($email, $fname)->subject('Tarlac Procurement Tracking System: New Purchase Request Created');
                     });
                     $notice = "Purchase request created successfully. ";
                     // Insert data to reports table
                     $date_received = Input::get('dateReceived');
                     $date_received = substr($date_received, 0, strrpos($date_received, ' '));
                     $reports = Reports::whereDate($date_received)->first();
                     if ($reports == null) {
                         $reports = new Reports();
                         $reports->date = $date_received;
                         $reports->pRequestCount = 1;
                     } else {
                         $reports->pRequestCount = $reports->pRequestCount + 1;
                     }
                     $reports->save();
                     //End Reports
                 } else {
                     // Insert data to reports table
                     $date_received = Input::get('dateReceived');
                     $date_received = substr($date_received, 0, strrpos($date_received, ' '));
                     $reports = Reports::whereDate($date_received)->first();
                     if ($reports == null) {
                         $reports = new Reports();
                         $reports->date = $date_received;
                         $reports->pRequestCount = 1;
                     } else {
                         $reports->pRequestCount = $reports->pRequestCount + 1;
                     }
                     $reports->save();
                     //End Reports
                     $notice = "Purchase request created successfully. Email notice was not sent. ";
                 }
                 Session::put('notice', $notice);
                 $office = Office::all();
                 $users = User::all();
                 $workflow = Workflow::all();
                 //return Redirect::to('purchaseRequest/view');
                 return Redirect::to('janisawesome');
                 Session::put('imgsuccess', 'Files uploaded.');
             } else {
                 $message = "Failed to create purchase request.";
                 Session::put('main_error', $message);
                 // Get Other Error Messages
                 $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
                 $error_projectType = $purchase->validationErrors->first('projectType');
                 $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
                 $error_amount = $purchase->validationErrors->first('amount');
                 $error_office = $purchase->validationErrors->first('office');
                 $error_requisitioner = $purchase->validationErrors->first('requisitioner');
                 $error_dateRequested = $purchase->validationErrors->first('dateRequested');
                 $error_dateReceived = $purchase->validationErrors->first('dateReceived');
                 // Inserting Error Message To a Session
                 Session::put('error_projectPurpose', $error_projectPurpose);
                 Session::put('error_sourceOfFund', $error_sourceOfFund);
                 Session::put('error_amount', $error_amount);
                 Session::put('error_office', $error_office);
                 Session::put('error_requisitioner', $error_requisitioner);
                 Session::put('error_dateRequested', $error_dateRequested);
                 Session::put('error_dateReceived', $error_dateReceived);
                 Session::put('error_projectType', $error_projectType);
                 if (Input::get('hide_modeOfProcurement') == "") {
                     Session::put('m6', 'required');
                 }
                 Session::put('imgsuccess', 'Files uploaded.');
                 return Redirect::back()->withInput();
             }
         } else {
             // Set Main Error
             $message = "Failed to create purchase request.";
             Session::put('main_error', $message);
             // Get Other Error Messages
             $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
             $error_projectType = $purchase->validationErrors->first('projectType');
             $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
             $error_amount = $purchase->validationErrors->first('amount');
             $error_office = $purchase->validationErrors->first('office');
             $error_requisitioner = $purchase->validationErrors->first('requisitioner');
             $error_dateRequested = $purchase->validationErrors->first('dateRequested');
             $error_dateReceived = $purchase->validationErrors->first('dateReceived');
             // Inserting Error Message To a Session
             Session::put('error_projectPurpose', $error_projectPurpose);
             Session::put('error_sourceOfFund', $error_sourceOfFund);
             Session::put('error_amount', $error_amount);
             Session::put('error_office', $error_office);
             Session::put('error_requisitioner', $error_requisitioner);
             Session::put('error_dateRequested', $error_dateRequested);
             Session::put('error_dateReceived', $error_dateReceived);
             Session::put('error_projectType', $error_projectType);
             if (Input::get('hide_modeOfProcurement') == "") {
                 Session::put('error_modeOfProcurement', 'required');
             }
             if (Session::get('imgerror') && Input::hasfile('file')) {
                 $failedpurchasecount = Purchase::where('id', $purchase->id)->count();
                 if ($failedpurchasecount != 0) {
                     $failedpurchase = Purchase::find($purchase->id);
                     $failedpurchase->delete();
                 }
                 Session::forget('imgsuccess');
                 //Image Error Return
                 $task_details = TaskDetails::where('doc_id', $document->id)->delete();
                 $document->delete();
                 $message = "Failed to create purchase request.";
                 // Set Main Error
                 $message = "Failed to save purchase request.";
                 Session::put('main_error', $message);
                 // Get Other Error Messages
                 $error_projectPurpose = $purchase->validationErrors->first('projectPurpose');
                 $error_projectType = $purchase->validationErrors->first('projectType');
                 $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund');
                 $error_amount = $purchase->validationErrors->first('amount');
                 $error_office = $purchase->validationErrors->first('office');
                 $error_requisitioner = $purchase->validationErrors->first('requisitioner');
                 $error_dateRequested = $purchase->validationErrors->first('dateRequested');
                 $error_dateReceived = $purchase->validationErrors->first('dateReceived');
                 // Inserting Error Message To a Session
                 Session::put('error_projectPurpose', $error_projectPurpose);
                 Session::put('error_sourceOfFund', $error_sourceOfFund);
                 Session::put('error_amount', $error_amount);
                 Session::put('error_office', $error_office);
                 Session::put('error_requisitioner', $error_requisitioner);
                 Session::put('error_dateRequested', $error_dateRequested);
                 Session::put('error_dateReceived', $error_dateReceived);
                 Session::put('error_projectType', $error_projectType);
             }
             return Redirect::back()->withInput();
         }
         $numLoop++;
     }
 }
Exemple #10
0
 public function deleteSection($section_id, $code)
 {
     $cv = Cv::where('cv_code', $code)->first();
     $cv_id = $cv->id;
     Section::where('id', $section_id)->where('cv_id', $cv_id)->delete();
     $data["success"] = 1;
     $data["message"] = "Succefully deleted";
     return json_encode($data);
 }