示例#1
0
 /**
  * Update configuration key and value into database (automatically insert if key does not exist)
  *
  * @param string $key Key
  * @param mixed $values $values is an array if the configuration is multilingual, a single string else.
  * @param boolean $html Specify if html is authorized in value
  *
  * @return boolean Update result
  */
 public static function updateValue($key, $values, $html = false)
 {
     // if (!Validate::isConfigName($key))
     // 	die(Tools::displayError());
     $current_value = Configuration::get($key);
     /* Update classic values */
     /* If the current value exists but the _CONF_IDS[$key] does not, it mean the value has been set but not save, we need to add */
     if ($current_value !== false) {
         $values = pSQL($values, $html);
         /* Do not update the database if the current value is the same one than the new one */
         if ($values == $current_value) {
             $result = true;
         } else {
             $model = Configuration::where('name', '=', $key)->firstOrFail();
             $model->value = $values;
             // $result = $db->AutoExecute(_DB_PREFIX_.'configuration',
             // 	array('value' => $values, 'date_upd' => date('Y-m-d H:i:s')),
             // 	'UPDATE', '`id_configuration` = '.(int)self::$_CONF_IDS[$key], true, true);
             // if ($result)
             if ($result = $model->save()) {
                 self::$_CONF[$key] = stripslashes($values);
             }
         }
     } else {
         $result = self::_addConfiguration($key, $values);
         if ($result) {
             self::$_CONF[$key] = stripslashes($values);
             // Configuration::set($key, $values, $id_shop_group, $id_shop);
         }
     }
     return (bool) $result;
 }
示例#2
0
 public static function percent($percent = 0, $decimalPlaces = null)
 {
     if ($decimalPlaces == null) {
         $decimalPlaces = Configuration::get('DEF_PERCENT_DECIMALS');
     }
     $number = number_format($percent, $decimalPlaces, '.', '');
     return $number;
 }
示例#3
0
 public static function date_short(\Carbon\Carbon $date, $format = '')
 {
     // http://laravel.io/forum/03-11-2014-date-format
     // https://laracasts.com/forum/?p=764-saving-carbon-dates-from-user-input/0
     if ($format == '') {
         $format = \App\Configuration::get('DATE_FORMAT_SHORT');
     }
     // Should take value after User / Environment settings
     // echo ($format); die();
     // $date = \Carbon\Carbon::createFromFormat($format, $date);
     // http://laravel.io/forum/03-12-2014-class-carbon-not-found?page=1
     // echo $date.' - '.Configuration::get('DATE_FORMAT_SHORT').' - '.$date->format($format); die();
     return $date->format($format);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     /*
     |--------------------------------------------------------------------------
     | Application Configuration
     |--------------------------------------------------------------------------
     |
     | Load Configuration Keys.
     |
     */
     Configuration::loadConfiguration();
     if (Auth::check()) {
         $user = User::with('language')->find(Auth::id());
         // $email = Auth::user()->email;
         $language = $user->language;
     } else {
         $user = NULL;
         $language = Language::find(intval(Request::cookie('user_language')));
         if (!$language) {
             $language = Language::findOrFail(intval(Configuration::get('DEF_LANGUAGE')));
         }
     }
     $company = Company::with('currency')->findOrFail(intval(Configuration::get('DEF_COMPANY')));
     Context::getContext()->user = $user;
     Context::getContext()->language = $language;
     Context::getContext()->company = $company;
     Context::getContext()->currency = $company->currency;
     Context::getContext()->controller = $request->segment(1);
     if ($request->segment(3) == 'attributes') {
         Context::getContext()->controller = $request->segment(3);
     }
     Context::getContext()->action = NULL;
     //$action;
     /* * /
     		// echo_r($request->route()->getAction());
     		// http://laravel.io/forum/10-15-2014-laravel-5-passing-parameters-to-middleware-handlers
     		// http://www.codeheaps.com/php-programming/laravel-5-middleware-stack-decoded/
     		// http://blog.elliothesp.co.uk/coding/passing-parameters-middleware-laravel-5/
     		// https://gist.github.com/dwightwatson/6200599
     		// http://stackoverflow.com/questions/26840278/laravel-5-how-to-get-route-action-name
     		    $action = $request->route()->getAction();
     		    $routeArray = Str::parseCallback($action['controller'], null);
     
     		    if (last($routeArray) != null) {
     		        // Remove 'controller' from the controller name.
     		        $controller = str_replace('Controller', '', class_basename(head($routeArray)));
     
     		        // Take out the method from the action.
     		        $action = str_replace(['get', 'post', 'patch', 'put', 'delete'], '', last($routeArray));
     
     		        // return Str::slug($controller . '-' . $action);
     		    } else {
     		        // return 'closure';
     		        $controller = 'closure';
     		        $action = '';
     		    }
     		// gist ENDS
     
     		Context::getContext()->controller = $controller;
     		Context::getContext()->action     = $action; 
     		echo Str::slug($controller . '-' . $action);
     / * */
     // Changing Timezone At Runtime. But this change does not seem to be taken by Carbon... Why?
     Config::set('app.timezone', Configuration::get('TIMEZONE'));
     // Changing The Default Language At Runtime
     App::setLocale(Context::getContext()->language->iso_code);
     return $next($request);
 }
示例#5
0
Route::group(['middleware' => 'auth'], function () {
    // Route::get( 'contact', 'ContactMessagesController@create');
    Route::post('contact', 'ContactMessagesController@store');
    // See: https://gist.github.com/drawmyattention/8cb599ee5dc0af5f4246
    Route::group(array('middleware' => 'authAdmin'), function () {
        Route::resource('companies', 'CompaniesController');
        Route::resource('configurations', 'ConfigurationsController');
        Route::resource('configurationkeys', 'ConfigurationKeysController');
        Route::resource('languages', 'LanguagesController');
        //		Route::resource('sequences', 'SequencesController');
        Route::resource('users', 'UsersController');
        //		Route::resource('templates', 'TemplatesController');
        Route::resource('currencies', 'CurrenciesController');
        Route::resource('taxes', 'TaxesController');
        Route::resource('categories', 'CategoriesController');
        Route::resource('products', 'ProductsController');
        Route::post('products/{id}/combine', array('as' => 'products.combine', 'uses' => 'ProductsController@combine'));
        Route::get('products/ajax/name_lookup', array('uses' => 'ProductsController@ajaxProductSearch', 'as' => 'products.ajax.nameLookup'));
        Route::post('products/ajax/options_lookup', array('uses' => 'ProductsController@ajaxProductOptionsSearch', 'as' => 'products.ajax.optionsLookup'));
        Route::resource('optiongroups', 'OptionGroupsController');
        Route::resource('optiongroups.options', 'OptionsController');
        Route::resource('combinations', 'CombinationsController');
        Route::resource('warehouses', 'WarehousesController');
        Route::resource('stockmovements', 'StockMovementsController');
    });
});
/* ********************************************************** */
Route::get('test', function () {
    echo \Carbon\Carbon::now();
    echo Config::get('app.timezone') . \App\Configuration::get('TIMEZONE');
});
 /**
  * Show the form for editing the specified resource.
  * GET /companies/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $company = $this->company = Company::with('Address')->with('Currency')->findOrFail(intval(Configuration::get('DEF_COMPANY')));
     return View::make('companies.edit', compact('company'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     die(Input::get('tab_index'));
     $input = Input::all();
     // STEP 1 : validate data (pendding)
     $validator = Validator::make($input, Customer::$rules);
     if (!$validator->passes()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // STEP 2 : build objects
     // Customer Stuff
     $customerData = array();
     $customerData['name_fiscal'] = $input['name_fiscal'];
     //		$customerData['name_commercial'] = $input['name_commercial'];
     //      $customerData['firstname']       = $input['firstname'];
     //      $customerData['lastname']        = $input['lastname'];
     //      $customerData['email']           = $input['email'];
     $customerData['website'] = Input::get('website', '');
     $customerData['identification'] = Input::get('identification', '');
     //      $customerData['phone']           = $input['phone'];
     //      $customerData['phone_mobile']    = $input['phone_mobile'];
     //      $customerData['fax']             = $input['fax'];
     $customerData['outstanding_amount_allowed'] = Input::get('outstanding_amount_allowed', Configuration::get('DEF_OUTSTANDING_AMOUNT'));
     $customerData['outstanding_amount'] = 0;
     $customerData['unresolved_amount'] = 0;
     $customerData['notes'] = Input::get('notes', '');
     $customerData['accept_einvoice'] = Input::get('accept_einvoice', 0);
     $customerData['accept_einvoice'] = intval($customerData['accept_einvoice']) > 0 ? 1 : 0;
     $customerData['blocked'] = 0;
     $customerData['active'] = Input::get('activce', 1);
     $customerData['active'] = intval($customerData['active']) > 0 ? 1 : 0;
     // Customer Relations!
     $customerData['salesrep_id'] = 0;
     $customerData['currency_id'] = 0;
     $customerData['customer_group_id'] = 0;
     $customerData['payment_method_id'] = 0;
     $customerData['sequence_id'] = 0;
     $customerData['carrier_id'] = 0;
     $customerData['price_list_id'] = 0;
     $customerData['direct_debit_account_id'] = 0;
     $customerData['invoicing_address_id'] = 0;
     $customerData['shipping_address_id'] = 0;
     // Addresses Stuff
     $addressInvData = array();
     $addressInvData['alias'] = 'Dirección Principal';
     $addressInvData['model_name'] = 'Customer';
     $addressInvData['name_commercial'] = Input::get('name_commercial', '');
     $addressInvData['address1'] = Input::get('address1', '');
     $addressInvData['address2'] = Input::get('address2', '');
     $addressInvData['postcode'] = Input::get('postcode', '');
     $addressInvData['city'] = Input::get('city', '');
     $addressInvData['state'] = Input::get('state', '');
     $addressInvData['country'] = Input::get('country', Configuration::get('DEF_COUNTRY_NAME'));
     $addressInvData['firstname'] = Input::get('firstname', '');
     $addressInvData['lastname'] = Input::get('lastname', '');
     $addressInvData['email'] = Input::get('email', '');
     $addressInvData['phone'] = Input::get('phone', '');
     $addressInvData['phone_mobile'] = Input::get('phone_mobile', '');
     $addressInvData['fax'] = Input::get('fax', '');
     $addressInvData['notes'] = '';
     $addressInvData['active'] = 1;
     $addressInvData['latitude'] = 0;
     $addressInvData['longitude'] = 0;
     // Address Relations!
     $addressInvData['owner_id'] = 0;
     $addressInvData['state_id'] = 0;
     $addressInvData['country_id'] = 0;
     $addressShipData = array();
     //		$addressShipData[''] = $input['ship_address_'];
     $customer = Customer::create($customerData);
     $addressInv = Address::create($addressInvData);
     $addressInv->Customer()->associate($customer);
     $customer->addresses()->save($addressInv);
     $customer->invoicing_address_id = $addressInv->id;
     $customer->shipping_address_id = $addressInv->id;
     $customer->save();
     // $customer->touch();
     // See: http://stackoverflow.com/questions/16740973/one-to-many-relationship-inserts-2-records-into-table
     // Kind of different...
     /*
                 return Redirect::route('customers.create')
     		->withInput()
     		->with('message_error', 'Esta txuta!');
     */
     // return Redirect::to('customers/' . $customer->id . '/edit')
     return Redirect::to('customers')->with('success', 'El Cliente se ha creado correctamente.');
     // return Redirect::route('customers.create')
     //        ->with('message_error', 'Esta txuta!');
     /*
             $v = Validator::make($input, Customer::$rules);
     
             if ($v->passes())
             {
                 $this->customer->create($input);
     
                 return Redirect::route('admin.customers.index')
     				->with('message_info', 'El registro se ha creado correctamente: '. $input['name'].' - '.$input['percent'].'%');
             }
     
             return Redirect::route('admin.customers.create')
                 ->withInput()
                 ->withErrors($v)
                 ->with('message_error', 'There were validation errors');
     */
 }