Пример #1
0
 public function addOffer(request $request)
 {
     $rules = array('title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required');
     $Validator = $this->customValidator($request->all(), $rules, array());
     if ($Validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'messages' => $Validator->errors()->all()], 400);
     }
     $is_parent = false;
     $offerArr = $request->only('title', 'fineprint');
     $offerArr['startDate'] = date('Y-m-d H:i:s', strtotime($request->input('startDate')));
     $offerArr['endDate'] = date('Y-m-d H:i:s', strtotime($request->input('endDate')));
     if ($request->has('store_token')) {
         if ($request->input('store_token') == 'all' && Auth::user()->Stores->is_parent) {
             $store_id = Auth::user()->Stores->id;
             $is_parent = true;
         } else {
             if ($request->input('store_token') == 'all') {
                 return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403);
             } else {
                 $storeId = Crypt::decrypt($request->input('store_token'));
                 if (!$this->checkUserHasStorePermission($storeId)) {
                     return response()->json(['response_code' => 'ERR_UNA', 'messages' => 'User Not Authorized'], 403);
                 }
                 $store_id = $storeId;
             }
         }
     } else {
         $store_id = Auth::user()->Stores->id;
     }
     $offerArr['store_id'] = $store_id;
     $offer = Offers::create($offerArr);
     if ($is_parent) {
         //creating offer for all sub merchants if user selects and if he is super merchant
         $offer->is_parent = true;
         $offer->save();
         $matchThese = ['is_child' => true, 'parent_id' => $store_id];
         $stores = MerchantStore::where($matchThese)->get();
         $offerInp = $request->only('title', 'fineprint', 'startDate', 'endDate');
         $offerInp['is_child'] = true;
         $offerInp['parent_id'] = $offer->id;
         foreach ($stores as $store) {
             $offerInp['store_id'] = $store->id;
             Offers::create($offerInp);
         }
     }
     return response()->json(['response_code' => 'RES_SOC', 'messages' => 'Store Offer Created', 'data' => $offer], 201);
 }
Пример #2
0
 public function unpaid_report($semester_id, request $request)
 {
     $statistics = Student::select('name', 'username', 'email', 'mobile', 'gender', 'national_id')->where('state', 'active')->where('free_percent', 0)->whereNotIn('id', function ($query) {
         $query->select('student_id')->from('financial_invoices')->where('semester_id', 9)->where('type', 'credit');
     })->whereIn('id', function ($query) {
         $query->select('student_id')->from('student_subjects')->where('semester_id', 9)->where('state', 'study')->distinct();
     });
     if ($request->has('name')) {
         $statistics->where('name', 'LIKE', "%" . $request->input('name') . '%');
     }
     if ($request->has('code')) {
         $statistics->where('username', $request->input('code'));
     }
     $statistics = $statistics->orderBy('name', 'ASC')->get();
     /*
     		$statistics = DB::select("
     			SELECT name , username , email, mobile , gender , national_id
     			from students
     			where
     			state = 'active'
     			AND
     			free_percent = 0
     			AND
     			id not IN
     			( SELECT student_id from financial_invoices where semester_id = 9 and type = 'credit')
     			AND
     			id IN
     			( SELECT DISTINCT student_id from student_subjects where semester_id = 9 and state = 'study')
     			");
     */
     return view('financials::reports.unpaid', compact('statistics'));
 }
Пример #3
0
 public function postStore(request $request)
 {
     $rules = array('store_name' => 'required|min:2|max:60', 'description' => 'required|min:10', 'tags' => 'required', 'cost_two' => 'required', 'landline' => 'required');
     $Validator = $this->customValidator($request->all(), $rules, array());
     if ($Validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'messages' => $Validator->errors()->all()], 400);
     }
     $storeInput = $request->only('store_name', 'description', 'cost_two', 'landline');
     if ($request->has('veg')) {
         $storeInput['veg'] = $request->input('veg');
     }
     $storeInput['user_id'] = Auth::id();
     $tags = $request->only('tags');
     $tagStore = explode(',', $tags['tags']);
     $store = MerchantStore::create($storeInput);
     if ($request->hasFile('logo')) {
         $image = $request->file('logo');
         $imageName = strtotime(Carbon::now()) . md5($store->id) . '.' . $image->getClientOriginalExtension();
         $path = public_path('assets/img/stores/' . $imageName);
         Image::make($image->getRealPath())->resize(280, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save($path);
         $store->logoUrl = $imageName;
     }
     $store->status = true;
     //commet it when required
     $store->save();
     $store->tags()->attach($tagStore);
     return response()->json(['response_code' => 'RES_SC', 'messages' => 'Store Created', 'data' => $store], 201);
 }
Пример #4
0
 public function addOffer(request $request)
 {
     $rules = array('title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required');
     $validator = $this->customValidator($request->all(), $rules, array());
     if ($validator->fails()) {
         return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]);
     }
     $is_parent = false;
     $fineprintArr = explode("\n", $request->input('fineprint'));
     $fineprint = '';
     foreach ($fineprintArr as $value) {
         if ($value != '' || !empty($value)) {
             $fineprint .= '<li>' . $value . '</li>';
         }
     }
     if ($request->has('store_token')) {
         if ($request->input('store_token') == 'all' && Auth::user()->Stores->is_parent) {
             $store_id = Auth::user()->Stores->id;
             $is_parent = true;
         } else {
             if ($request->input('store_token') == 'all') {
                 return response()->json(['status' => 'fail', 'message' => 'Not Authorized']);
             } else {
                 $storeId = Crypt::decrypt($request->input('store_token'));
                 if (!$this->checkUserHasStorePermission($storeId)) {
                     return response()->json(['status' => 'fail', 'message' => 'Not Authorized']);
                 }
                 $store_id = $storeId;
             }
         }
     } else {
         $store_id = Auth::user()->Stores->id;
     }
     $offerInput = $request->only('title', 'startDate', 'endDate');
     $offerInput['store_id'] = $store_id;
     $offerInput['fineprint'] = $fineprint;
     $offer = Offers::create($offerInput);
     if ($is_parent) {
         $offer->is_parent = true;
         $offer->save();
         //creating offer for all sub merchants if user selects and if he is super merchant
         $matchThese = ['is_child' => true, 'parent_id' => $store_id];
         $stores = MerchantStore::where($matchThese)->get();
         $offerInp = $request->only('title', 'fineprint', 'startDate', 'endDate');
         $offerInp['is_child'] = true;
         $offerInp['parent_id'] = $offer->id;
         foreach ($stores as $store) {
             $offerInp['store_id'] = $store->id;
             Offers::create($offerInp);
         }
     }
     return response()->json(['status' => 'success']);
 }
Пример #5
0
 /**
  * Validate the form from the specification provided. The definition data
  * is an associative array having the field name as the key and the
  * definition as the value. The following syntax is used:
  *
  * validate {email|ip|int|bool[ean]|float}  - validate form
  *
  * between MIN and MAX  - valid if field between min and max
  *
  * above VALUE  - valid if field above value
  *
  * below VALUE  - valid if field below value
  *
  * netmask {IP/MASK}[;{IP/MASK}..]  - valid if ip in one of the masks
  *
  * match REGEX  - valid if regex match
  *
  * as OTHERFIELD  - valid if value is same as other field
  *
  * minlength LEN  - valid if longer than len
  *
  * maxlength LEN  - valid if shorter than len
  *
  * @param string $data The field definition data
  * @return bool True if the form is valid
  */
 public function validateForm($data)
 {
     $toks = 'validate:1 between:1 and:1 above:1 below:1 netmask:1 ' . 'match:1 as:1 minlength:1 maxlength:1 required:0 default:1';
     $this->fields = $data;
     $this->valid = true;
     // Go over each of the expected form fields
     foreach ((array) $data as $field => $attr) {
         if (request::has($field)) {
             $this->raw[$field] = (string) request::get($field);
         } else {
             $this->raw[$field] = null;
         }
         $valid = true;
         $data = $this->raw[$field];
         $t = new Tokenizer($toks, $attr);
         $ta = $t->getTokens();
         foreach ($t as $tok => $arg) {
             switch ($tok) {
                 case 'validate':
                     switch ($arg) {
                         case 'email':
                             $valid = filter_var($data, FILTER_VALIDATE_EMAIL);
                             break;
                         case 'ip':
                             $valid = filter_var($data, FILTER_VALIDATE_IP);
                             break;
                         case 'int':
                             $valid = filter_var($data, FILTER_VALIDATE_INT);
                             break;
                         case 'bool':
                         case 'boolean':
                             $valid = filter_var($data, FILTER_VALIDATE_BOOL);
                             break;
                         case 'float':
                             $valid = filter_var($data, FILTER_VALIDATE_FLOAT);
                             break;
                         case 'file':
                             // is a file?
                             break;
                         default:
                             throw new BaseException('Invalid validation type: ' . $arg);
                     }
                     break;
                 case 'between':
                     // check if between $arg and ['and']
                     $min = $arg;
                     if (!isset($ta['and'])) {
                         throw new BaseException('Form field definition using "between" without "and"');
                     }
                     $max = $ta['and'];
                     if ($data < $min || $data > $max) {
                         $valid = false;
                     }
                     break;
                 case 'minlength':
                     if (strlen($data) < $arg) {
                         $valid = false;
                     }
                     break;
                 case 'maxlength':
                     if (strlen($data) > $arg) {
                         $valid = false;
                     }
                     break;
                 case 'above':
                     if ($data < $arg) {
                         $valid = false;
                     }
                     break;
                 case 'below':
                     if ($data > $arg) {
                         $valid = false;
                     }
                     break;
                 case 'netmask':
                     $s = explode(';', $arg);
                     // Match subnet x.x.x.x/xxx
                     $valid = false;
                     foreach ($s as $net) {
                         list($net, $mask) = explode('/', $net);
                         if ((ip2long($data) & ~((1 << 32 - $mask) - 1)) == (ip2long($net) & ~((1 << 32 - $mask) - 1))) {
                             $valid = true;
                             break;
                         }
                         /*
                         $netpart = explode('/',$net);
                         $ip = sprintf("%032b",ip2long($data)); 
                         $subnet = sprintf("%032b",ip2long($netpart[0])); 
                         if (substr_compare($ip,$subnet,0,$netpart[1]) === 0) {
                             $valid = true;
                             break;
                         }
                         */
                     }
                     break;
                 case 'match':
                     $ret = preg_match($arg, $data);
                     if (!$ret) {
                         $valid = false;
                     }
                     break;
                 case 'as':
                     if ($data != $this->raw[$arg]) {
                         $valid = false;
                     }
                     break;
                 case 'required':
                     if ($data == null) {
                         $valid = false;
                     }
                     break;
                 case 'default':
                     if ($data == null) {
                         $data = $arg;
                     }
                     break;
                 default:
                     throw new BaseException("Invalid token.");
             }
         }
         // if (!$valid) { Console::warn('Form field %s failed validation', $field); }
         $this->fieldvalid[$field] = $valid;
         $this->parsed[$field] = $data;
         if (!$valid) {
             $this->formvalid = false;
         }
     }
     return $this->formvalid;
 }
Пример #6
0
 /**
  * @todo Document
  * @param array $meta
  * @return type 
  */
 public function validate(array $meta)
 {
     $formdata = $meta['formdata'];
     foreach ($this->_items as $ci) {
         if (is_a($ci, WizardLayoutControl)) {
             $ci->validate($meta);
         } else {
             $key = $ci->getKey();
             $formdata[$key]['changed'] = true;
             // Do the validation here
             if (arr::hasKey($formdata, $key) && request::has($key) && $formdata[$key]['value'] == (string) request::get($key)) {
                 // Not changed, so query previous state of validation
                 $formdata[$key]['changed'] = false;
                 if ($formdata[$key]['valid'] != true) {
                     // Do validation
                 }
             } else {
                 // Insert into array
                 $formdata[$key] = array('value' => (string) request::get($key), 'valid' => $formdata[$key]['valid']);
             }
         }
     }
     return $formdata;
 }
 public function postIndex(request $request)
 {
     $this->data['title'] = "Travel applications";
     //if immigration...
     if (Auth::user()->department_id == 6) {
         $this->data['title'] = "Approved travel applications";
         $matchThese = [];
         $travelApplications = travelApplication::where($matchThese)->orderBy('updated_at', 'desc')->get();
         $this->data['travelApplications'] = $travelApplications;
         return view('dashboard', $this->data);
     } else {
         $matchThese = [];
         if ($request->has('province')) {
             $matchThese["province"] = $request->province;
         } else {
             if (Auth::user()->province) {
                 $matchThese["province"] = Auth::user()->province;
             }
         }
         if ($request->has('region')) {
             $matchThese["region"] = $request->region;
         } else {
             if (Auth::user()->region) {
                 $matchThese["region"] = Auth::user()->region;
             }
         }
         if ($request->has('municipality')) {
             $matchThese["municipality"] = $request->municipality;
         } else {
             if (Auth::user()->municipality) {
                 $matchThese["municipality"] = Auth::user()->municipality;
             }
         }
         if ($request->has('travelstatus')) {
             $matchThese["applicationstatus_id"] = $request->travelstatus;
         }
         if ($_POST['dateFrom'] != "" && $_POST['dateTo'] != "") {
             $dateFrom = new DateTime($_POST['dateFrom']);
             $dateTo = new DateTime($_POST['dateTo']);
             $dateFromString = $dateFrom->format('Y-m-d');
             $dateToString = $dateTo->format('Y-m-d') . " 23:59:00";
             $travelApplications = travelApplication::where($matchThese)->where('created_at', '<=', $dateToString)->where('created_at', '>=', $dateFromString)->orderBy('updated_at')->orderBy('updated_at', 'desc')->get();
         } else {
             $travelApplications = travelApplication::where($matchThese)->orderBy('updated_at', 'desc')->get();
         }
         $this->data['travelApplications'] = $travelApplications;
         return view('dashboard', $this->data);
     }
 }