예제 #1
0
 /**
  * The constructor
  * @param string $dir The directory where the application is located 
  * @throws \InvalidArgumentException
  */
 function __construct($dir)
 {
     if (!is_string($dir)) {
         throw new \InvalidArgumentException('');
     }
     parent::__construct($dir);
 }
    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store(Request $request)
    {
        $this->validate($request, StockMovement::$rules);
        // Has Combination?
        if ($request->has('group')) {
            $groups = $request->input('group');
            $q = '';
            foreach ($groups as $option) {
                $q .= ' (co.option_id = ' . $option . ') or';
            }
            $q = substr($q, 0, -2);
            $q = 'SELECT combination_id, COUNT(combination_id) tot FROM `combinations` as c
					left join combination_option as co
					on co.combination_id = c.id
					WHERE c.product_id = ' . $request->input('product_id') . '
					AND ( ' . $q . ' )
					GROUP BY combination_id ORDER BY tot DESC
					LIMIT 1';
            $result = DB::select(DB::raw($q));
            // echo $q.'<br>';echo_r($result); die();
            $combination_id = $result[0]->combination_id;
        } else {
            $combination_id = 0;
        }
        $extradata = ['date' => \Carbon\Carbon::createFromFormat(\App\Context::getContext()->language->date_format_lite, $request->input('date')), 'model_name' => '', 'document_id' => 0, 'document_line_id' => 0, 'combination_id' => $combination_id, 'user_id' => \Auth::id()];
        $stockmovement = $this->stockmovement->create(array_merge($request->all(), $extradata));
        // Stock movement fulfillment (perform stock movements)
        $stockmovement->fulfill();
        return redirect('stockmovements')->with('info', l('This record has been successfully created &#58&#58 (:id) ', ['id' => $stockmovement->id], 'layouts') . $request->get('document_reference') . ' - ' . $request->input('date'));
    }
예제 #3
0
function l($string = NULL, $data = [], $langfile = NULL)
{
    if ($langfile == NULL) {
        $langfile = \App\Context::getContext()->controller;
    }
    if (Lang::has($langfile . '.' . $string)) {
        return Lang::get($langfile . '.' . $string, $data);
    } else {
        foreach ($data as $key => $value) {
            $string = str_replace(':' . $key, $value, $string);
        }
        return $string;
    }
}
 /**
  * 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);
 }