Esempio n. 1
0
 /**
  * Function to create a customer
  *
  * Input names to create customer
  *
  * lang_id_301 [langId]
  * group_id_301 [groupId]
  * date_301 [date]
  * company_301 [company]
  * tin_301 [tin]
  * gender_id_301 [gender]
  * treatment_id_301 [treatment]
  * state_id_301 [stateId]
  * name_301 [name]
  * surname_301 [surname]
  * avatar_301 [avatar]
  * birth_date_301 [birthDate]
  * email_301 [email]
  * phone_301 [phone]
  * mobile_301 [mobile]
  * user_301 [user]
  * password_301 [password]
  * active_301 [active]
  * country_id_301 [country]
  * territorial_area_1_id_301 [territorialArea1]
  * territorial_area_2_id_301 [territorialArea2]
  * cp_301 [cp]
  * locality_301 [locality]
  * address_301 [address]
  * latitude_301 [latitude]
  * longitude_301 [longitude]
  *
  * @param   \Illuminate\Http\Request        $request
  * @return  \Syscover\Crm\Models\Customer   $customer
  * @throws  \Exception
  */
 public static function createCustomer(Request $request)
 {
     if (!$request->has('email')) {
         throw new \Exception('You have to define an email field to record a user');
     }
     $customer = Customer::create(['lang_id_301' => $request->has('langId') ? $request->input('langId') : null, 'group_id_301' => $request->input('groupId'), 'date_301' => $request->has('date') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $request->input('date'))->getTimestamp() : date('U'), 'company_301' => $request->has('company') ? $request->input('company') : null, 'tin_301' => $request->has('tin') ? $request->input('tin') : null, 'gender_id_301' => $request->has('gender') ? $request->input('gender') : null, 'treatment_id_301' => $request->has('treatment') ? $request->input('treatment') : null, 'state_id_301' => $request->has('stateId') ? $request->input('stateId') : null, 'name_301' => $request->has('name') ? ucwords(strtolower($request->input('name'))) : null, 'surname_301' => $request->has('surname') ? ucwords(strtolower($request->input('surname'))) : null, 'avatar_301' => $request->has('avatar') ? $request->input('avatar') : null, 'birth_date_301' => $request->has('birthDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $request->input('birthDate'))->getTimestamp() : null, 'email_301' => strtolower($request->input('email')), 'phone_301' => $request->has('phone') ? $request->input('phone') : null, 'mobile_301' => $request->has('mobile') ? $request->input('mobile') : null, 'user_301' => $request->has('user') ? $request->input('user') : strtolower($request->input('email')), 'password_301' => $request->has('password') ? Hash::make($request->input('password')) : Hash::make(Miscellaneous::randomStr(8)), 'active_301' => $request->has('active'), 'confirmed_301' => false, 'country_id_301' => $request->has('country') ? $request->input('country') : null, 'territorial_area_1_id_301' => $request->has('territorialArea1') ? $request->input('territorialArea1') : null, 'territorial_area_2_id_301' => $request->has('territorialArea2') ? $request->input('territorialArea2') : null, 'territorial_area_3_id_301' => $request->has('territorialArea3') ? $request->input('territorialArea3') : null, 'cp_301' => $request->has('cp') ? $request->input('cp') : null, 'locality_301' => $request->has('locality') ? ucfirst($request->input('locality')) : null, 'address_301' => $request->has('address') ? $request->input('address') : null, 'latitude_301' => $request->has('latitude') ? $request->input('latitude') : null, 'longitude_301' => $request->has('longitude') ? $request->input('longitude') : null]);
     return $customer;
 }
Esempio n. 2
0
 public function editCustomRecord($parameters)
 {
     $response = FacturaDirecta::getClient($parameters['object']->customer_id_090);
     $collection = collect();
     // check that response does not contain httpStatus 404
     if (!isset($response['httpStatus'])) {
         // set id like integer, to compare in select
         $response['id'] = (int) $response['id'];
         $parameters['customers'] = $collection->push(Miscellaneous::arrayToObject($response));
     }
     return $parameters;
 }
Esempio n. 3
0
 public function updateCustomRecord($parameters)
 {
     if ($this->request->hasFile('image')) {
         $filename = Miscellaneous::uploadFiles('image', public_path() . '/packages/syscover/pulsar/storage/langs');
     } else {
         $filename = $this->request->input('image');
     }
     if ($this->request->input('base')) {
         Lang::resetBaseLang();
     }
     Lang::where('id_001', $parameters['id'])->update(['id_001' => $this->request->input('id'), 'name_001' => $this->request->input('name'), 'image_001' => $filename, 'sorting_001' => $this->request->input('sorting'), 'base_001' => $this->request->input('base', 0), 'active_001' => $this->request->input('active', 0)]);
     if ($this->request->input('base')) {
         session(['baseLang' => Lang::getBaseLang()]);
     }
 }
Esempio n. 4
0
 public function uploadFilesWysiwyg()
 {
     $parameters = $this->request->route()->parameters();
     $uri = 'packages/syscover/cms/storage/wysiwyg';
     $path = public_path() . '/' . $uri;
     $types = $this->getTypes($parameters['type']);
     $file = $this->request->file('file');
     $extension = $file->getClientOriginalExtension();
     $mime = $file->getClientMimeType();
     if (in_array($mime, $types['mime']) && in_array($extension, $types['extension'])) {
         $name = Miscellaneous::uploadFiles('file', $path);
         $response = ['success' => true, 'link' => asset($uri . '/' . $name)];
         return response()->json($response);
     }
 }
Esempio n. 5
0
 public function jsonData()
 {
     // get parameters from url route
     $parameters = $this->request->route()->parameters();
     $actionsAcl = Action::get();
     $acl = AclLibrary::getProfileAcl($parameters['profile']);
     $parameters = Miscellaneous::dataTablePaginate($this->request, $parameters);
     $parameters = Miscellaneous::dataTableSorting($this->request, $parameters, $this->indexColumns);
     $parameters = Miscellaneous::dataTableFiltering($this->request, $parameters);
     // set columns in parameters array
     $parameters['indexColumns'] = $this->indexColumns;
     $parametersCount = $parameters;
     $parametersCount['count'] = true;
     // get data to table
     $objects = call_user_func($this->model . '::getIndexRecords', $this->request, $parameters);
     $iFilteredTotal = call_user_func($this->model . '::getIndexRecords', $this->request, $parametersCount);
     $iTotal = call_user_func($this->model . '::countRecords', $this->request, $parameters);
     // get properties of model class
     $class = new \ReflectionClass($this->model);
     $response = ["sEcho" => intval($this->request->input('sEcho')), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => []];
     // instance model to get primary key
     $instance = new $this->model();
     $aObjects = $objects->toArray();
     $i = 0;
     foreach ($aObjects as $aObject) {
         $row = [];
         foreach ($this->indexColumns as $indexColumn) {
             $row[] = $aObject[$indexColumn];
         }
         $actions = '<div><select id="re' . $aObject[$instance->getKeyName()] . '" data-resource="' . $aObject[$instance->getKeyName()] . '" data-nresource="' . $aObject['name_007'] . '" multiple style="width: 100%;">';
         foreach ($actionsAcl as $actionAcl) {
             $selected = $acl->allows($aObject['id_007'], $actionAcl->id_008, $parameters['profile']) ? ' selected' : null;
             $actions .= '<option value="' . $actionAcl->id_008 . '"' . $selected . '>' . $actionAcl->name_008 . '</option>';
         }
         $actions .= '</select></div>';
         $row[] = $actions;
         $response['aaData'][] = $row;
         $i++;
     }
     return response()->json($response);
 }
Esempio n. 6
0
 public function updateCustomRecord($parameters)
 {
     $request = ['customer_id_078' => $this->request->input('customer'), 'shop_id_078' => $this->request->input('shopId'), 'company_id_078' => $this->request->input('company'), 'family_id_078' => $this->request->input('family'), 'brand_id_078' => $this->request->input('brand'), 'product_id_078' => $this->request->input('product'), 'address_id_078' => $this->request->has('aliasId') ? $this->request->input('aliasId') : null, 'company_name_078' => $this->request->has('companyName') ? $this->request->input('companyName') : null, 'name_078' => $this->request->has('name') ? $this->request->input('name') : null, 'surname_078' => $this->request->has('surname') ? $this->request->input('surname') : null, 'country_id_078' => $this->request->input('country'), 'territorial_area_1_id_078' => $this->request->has('territorialArea1') ? $this->request->input('territorialArea1') : null, 'territorial_area_2_id_078' => $this->request->has('territorialArea2') ? $this->request->input('territorialArea2') : null, 'territorial_area_3_id_078' => $this->request->has('territorialArea3') ? $this->request->input('territorialArea3') : null, 'cp_078' => $this->request->has('cp') ? $this->request->input('cp') : null, 'locality_078' => $this->request->has('locality') ? $this->request->input('locality') : null, 'address_078' => $this->request->has('address') ? $this->request->input('address') : null, 'phone_078' => $this->request->has('phone') ? $this->request->input('phone') : null, 'email_078' => $this->request->has('email') ? $this->request->input('email') : null, 'observations_078' => $this->request->has('observations') ? $this->request->input('observations') : null, 'view_width_078' => $this->request->input('viewWidth'), 'view_height_078' => $this->request->input('viewHeight'), 'total_width_078' => $this->request->has('totalWidth') ? $this->request->input('totalWidth') : null, 'total_height_078' => $this->request->has('totalHeight') ? $this->request->input('totalHeight') : null, 'units_078' => $this->request->input('units'), 'expiration_078' => $this->request->has('expiration') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('expiration'))->getTimestamp() : null, 'expiration_text_078' => $this->request->has('expiration') ? $this->request->input('expiration') : null, 'comments_078' => $this->request->has('comments') ? $this->request->input('comments') : null];
     if ($this->request->hasFile('attachment')) {
         $request['attachment_078'] = Miscellaneous::uploadFiles('attachment', public_path() . '/packages/syscover/octopus/storage/attachment/request');
     }
     OctopusRequest::where('id_078', $parameters['id'])->update($request);
     $this->sendRequestEmail($parameters['id'], 'update');
 }
Esempio n. 7
0
 /**
  * Function to search pattern inside message
  * @param $message
  * @param $patterns
  * @return array
  */
 public static function checkEmailPattern($message, $patterns)
 {
     $response = [];
     $patternFound = false;
     $objPattern = null;
     $subject = $message->getSubject();
     $body = $message->getMessageBody();
     foreach ($patterns as $pattern) {
         $subjectFound = false;
         $messageFound = false;
         if (empty($pattern->subject_049) == false && strpos($subject, $pattern->subject_049) !== false) {
             $subjectFound = true;
         }
         if (empty($pattern->message_049) === false && strpos($body, $pattern->message_049) !== false) {
             $messageFound = true;
         }
         if ($pattern->operator_049 == 'and' && $subjectFound && $messageFound) {
             $patternFound = true;
             $objPattern = $pattern;
             break;
         } elseif (($pattern->operator_049 == 'or' || $pattern->operator_049 == null) && ($subjectFound || $messageFound)) {
             $patternFound = true;
             $objPattern = $pattern;
             break;
         }
     }
     if ($patternFound) {
         $response['success'] = true;
         $response['pattern'] = $objPattern;
         $emails = Miscellaneous::extractEmail($body);
         $response['contacts'] = Contact::builder()->whereIn('email_041', $emails)->where('unsubscribe_email_041', false)->get();
     } else {
         $response['success'] = false;
         $response['pattern'] = false;
         $emails = Miscellaneous::extractEmail($body);
         $response['contacts'] = Contact::builder()->whereIn('email_041', $emails)->where('unsubscribe_email_041', false)->get();
     }
     return $response;
 }
Esempio n. 8
0
 public function editCustomRecord($parameters)
 {
     $parameters['campaigns'] = Campaign::builder()->where('active_221', true)->get();
     $parameters['products'] = Product::builder()->where('lang_id_112', base_lang()->id_001)->get();
     $parameters['places'] = Place::builder()->get();
     $productPrefixes = ProductPrefix::all();
     $parameters['products']->map(function ($item, $key) use($productPrefixes) {
         // set prefix products
         $productPrefix = $productPrefixes->where('product_id_222', $item->id_111)->first();
         if ($productPrefix == null) {
             return $item->prefix_222 = null;
         }
         return $item->prefix_222 = $productPrefixes->where('product_id_222', $item->id_111)->first()->prefix_222;
     });
     $response = FacturaDirecta::getInvoice($parameters['object']->invoice_id_226);
     $collection = collect();
     // check that response does not contain httpStatus 404
     if (!isset($response['httpStatus'])) {
         // set id like integer, to compare in select
         $response['id'] = (int) $response['id'];
         $parameters['invoices'] = $collection->push(Miscellaneous::arrayToObject($response));
     }
     // objects from place
     if (isset($parameters['object']->place_id_226)) {
         $result = collect(config('booking.models'))->where('id', $parameters['object']->place_id_226);
         if (count($result) === 0) {
             return response()->json(['status' => 'error', 'code' => 404, 'message' => 'Records not found']);
         }
         // model constructor
         $model = App::make($result->first()->model);
         // use sofa to get lang from lang table of object query
         $parameters['objects'] = $model->builder()->where('lang_id', base_lang()->id_001)->get();
         $parameters['objectName'] = trans_choice($result->first()->name, 1);
     }
     return $parameters;
 }
Esempio n. 9
0
 /**
  * Function to get data record to list objects
  *
  * @access	public
  * @param   \Illuminate\Http\Request    $request
  * @param   array                       $parameters
  * @return	array|\Illuminate\Database\Eloquent\Model[]
  */
 public static function getIndexRecords($request, $parameters)
 {
     $instance = new static();
     if (method_exists($instance, 'addToGetIndexRecords')) {
         $query = $instance->addToGetIndexRecords($request, $parameters);
     } else {
         if (method_exists($instance, 'scopeBuilder')) {
             $query = $instance->builder();
         } else {
             $query = $instance->query();
         }
     }
     $query = Miscellaneous::getQueryWhere($request, $query, $parameters);
     if (isset($parameters['count']) && $parameters['count']) {
         // if we need count results
         if (method_exists($instance, 'customCountIndexRecords')) {
             return $instance->customCountIndexRecords($query, $parameters);
         } else {
             return $query->count();
         }
     } else {
         // if we need limit and order results
         if (isset($parameters['length'])) {
             $query->take($parameters['length']);
         }
         if (isset($parameters['start'])) {
             $query->skip($parameters['start']);
         }
         if (isset($parameters['order']) && is_array($parameters['order'])) {
             $query->orderBy($parameters['order']['column'], isset($parameters['order']['dir']) ? $parameters['order']['dir'] : 'asc');
         }
         if (method_exists($instance, 'getCustomReturnIndexRecords')) {
             // if we need a custom get()
             return $instance->getCustomReturnIndexRecords($query, $parameters);
         } else {
             // if has diplayColumns variable
             if (isset($parameters['displayColumns']) && is_array($parameters['displayColumns']) && count($parameters['displayColumns']) > 0) {
                 return $query->get($parameters['displayColumns']);
             } else {
                 return $query->get();
             }
         }
     }
 }
Esempio n. 10
0
 protected function getSubtotalOverTotal()
 {
     $subtotal = null;
     if ($this->request->has('price')) {
         if ($this->request->has('productClassTax')) {
             // get tax rurles from product
             $taxRules = TaxRule::builder()->where('country_id_103', config('market.taxCountry'))->where('customer_class_tax_id_106', config('market.taxCustomerClass'))->where('product_class_tax_id_107', $this->request->input('productClassTax'))->orderBy('priority_104', 'asc')->get();
             if ((int) config('market.taxProductPrices') == TaxRuleLibrary::PRICE_WITH_TAX) {
                 $taxes = TaxRuleLibrary::taxCalculateOverTotal((double) $this->request->input('price'), $taxRules);
                 $taxAmount = $taxes->sum('taxAmount');
             }
             $subtotal = (double) $this->request->input('price') - $taxAmount;
         } else {
             $subtotal = $this->request->input('price');
         }
     } else {
         // if has not price, get precisionSubtotal input
         // covert possible strign with comma and dots to float val
         $subtotal = Miscellaneous::tofloat($this->request->input('precisionSubtotal'));
     }
     return $subtotal;
 }
Esempio n. 11
0
 public function apiGetCouponCode()
 {
     $couponCode = Miscellaneous::generateRandomString((int) $this->request->input('length'), 'uppercase-number');
     while (CartPriceRule::where('coupon_code_120', $couponCode)->count() > 0) {
         $couponCode = Miscellaneous::generateRandomString((int) $this->request->input('length'), 'uppercase-number');
     }
     return response()->json(['status' => 'success', 'couponCode' => $couponCode]);
 }
Esempio n. 12
0
 /**
  * @access	public
  * @return	\Illuminate\Support\Facades\View
  */
 public function editRecord()
 {
     // get parameters from url route
     $parameters = $this->request->route()->parameters();
     $parameters['urlParameters'] = $parameters;
     // set path variable to save in cookie, search param datatable component,
     // after creating urlParameters to don't send value, to URL create
     $parameters['path'] = $this->request->path();
     $parameters['resource'] = $this->resource;
     $parameters['action'] = 'update';
     $parameters['package'] = $this->package;
     $parameters['folder'] = $this->folder;
     $parameters['routeSuffix'] = $this->routeSuffix;
     $parameters['icon'] = $this->icon;
     $parameters['objectTrans'] = isset($this->objectTrans) && $this->objectTrans != null ? Miscellaneous::getObjectTransValue($parameters, $this->objectTrans) : null;
     // check if object has multiple language
     if (isset($parameters['lang'])) {
         if (isset($this->model) && method_exists($this->model, 'getTranslationRecord')) {
             $parameters['object'] = call_user_func($this->model . '::getTranslationRecord', $parameters);
         } elseif (isset($this->model)) {
             throw new InvalidArgumentException('The methods getTranslationRecord on ' . $this->model . ' is not definite');
         }
         if (method_exists($parameters['object'], 'getLang')) {
             $parameters['lang'] = $parameters['object']->getLang;
         }
         // check that we have lang object
         if ($parameters['lang'] === null) {
             throw new InvalidArgumentException('The language object is not instantiated, method getLang on model ' . $this->model . ' is not defined');
         }
     } else {
         // check if is implements getRecord function in model, for objects with joins
         if (isset($this->model) && method_exists($this->model, 'getRecord')) {
             $parameters['object'] = call_user_func($this->model . '::getRecord', $parameters);
         } elseif (isset($this->model)) {
             // call builder, by default is instance on Syscover\Pulsar\Core\Model or in model object
             $parameters['object'] = call_user_func($this->model . '::builder')->find($parameters['id']);
         }
     }
     $parameters = $this->editCustomRecord($parameters);
     // check if parameters is a RedirectResponse object, to send request to other url
     if (is_object($parameters) && get_class($parameters) == \Illuminate\Http\RedirectResponse::class) {
         return $parameters;
     }
     // set viewParamentes on parameters for throw to view
     $parameters['viewParameters'] = $this->viewParameters;
     // check if exist edit view, default all request go to common view
     if (view()->exists($this->package . '::' . $this->folder . '.edit', $parameters)) {
         return view($this->package . '::' . $this->folder . '.edit', $parameters);
     } else {
         return view($this->package . '::' . $this->folder . '.form', $parameters);
     }
 }
Esempio n. 13
0
 /**
  * @param   integer   $frequency
  * @param   $parameters
  * @return  array
  */
 public static function getFrequencyData($frequency, $parameters = [])
 {
     $response['lastRun'] = date('U');
     $response['nextRun'] = null;
     // set time stamp according frequency
     switch ($frequency) {
         case 1:
             // one time, set dates values from fields
             $response['from'] = isset($parameters['from']) ? $parameters['from'] : null;
             $response['until'] = isset($parameters['until']) ? $parameters['until'] : null;
             break;
         case 2:
             // daily, get values of last day
             $response['from'] = strtotime('last day 00:00:00');
             $response['until'] = strtotime('last day 23:59:59');
             $response['nextRun'] = strtotime('tomorrow');
             break;
         case 3:
             // weekly, get values of last week
             $response['from'] = strtotime('monday last week 00:00:00');
             $response['until'] = strtotime('sunday last week 23:59:59');
             $response['nextRun'] = strtotime('monday next week 00:00:00');
             break;
         case 4:
             // monthly, get values of last month
             $response['from'] = strtotime('first day of last month 00:00:00');
             $response['until'] = strtotime('last day of last month 23:59:59');
             $response['nextRun'] = strtotime('first day of next month 00:00:00');
             break;
         case 5:
             // quarterly, get values of last quarter
             $quarter = Miscellaneous::getQuarter('last');
             $response['from'] = $quarter['starDate'];
             $response['until'] = $quarter['endDate'];
             $quarter = Miscellaneous::getQuarter('current');
             $response['nextRun'] = $quarter['endDate'];
             break;
         default:
             $response['from'] = null;
             $response['until'] = null;
     }
     return $response;
 }
Esempio n. 14
0
 public function editCustomRecord($parameters)
 {
     // get resourse to know if set user, depend of view, todos or user todos
     $actions = $this->request->route()->getAction();
     $parameters['resource'] = $actions['resource'];
     if ($parameters['object']->type_id_093 == 2) {
         $response = FacturaDirecta::getClient($parameters['object']->customer_id_093);
         $collection = collect();
         // check that response does not contain httpStatus 404
         if (!isset($response['httpStatus'])) {
             // set id like integer, to compare in select
             $response['id'] = (int) $response['id'];
             $parameters['customers'] = $collection->push(Miscellaneous::arrayToObject($response));
         }
     }
     // types
     $parameters['types'] = array_map(function ($object) {
         $object->name = trans_choice($object->name, 1);
         return $object;
     }, config('projects.types'));
     // projects
     $parameters['projects'] = Project::builder()->where('end_date_090', '>', date('U'))->orWhereNull('end_date_090')->get();
     // todo: cambiar por listado de programadores
     $users = User::builder()->get();
     $parameters['users'] = $users->map(function ($user, $key) {
         $user->name = $user->name_010 . ' ' . $user->surname_010;
         return $user;
     });
     return $parameters;
 }