jeudi 24 mars 2016

Can't find request model with sql

  1. this is my code , in create i want to insert into "invoicesout" not "invoice"
  2. the problem is when i execute the line is added in the table invoice
  3. i want to now where can i find the file who speak with mysql

  4. InvoiceOutController.php

                            public function create()
            {
                $invoiceSettings    = InvoiceSetting::find(1);
    
                $data = array(
                    'clients'       => Project::all(),
                    'products'      => Product::where('status', 1)->get(),
                    'currencies'    => Currency::all(),
                    'taxes'         => Tax::orderBy('value', 'asc')->get(),
                    'invoiceCode'   => isset($invoiceSettings->code)    
                     $invoiceSettings->code         : false,
                    'invoiceNumber' => isset($invoiceSettings->number)  ? 
                     $invoiceSettings->number + 1   : false
                );
                return View::make('user.invoiceout.create', $data);
            }
    
            public function store()
                {
                    if ( Auth::user()->role_id != 1 )
                    {
                        return Redirect::to('dashboard')->with('error', trans('translate.permissions_denied'));
                    }
    
                    $rules = array(
                        'client_id'     => 'required',
                        'number'        => 'required',
                        'start_date'    => 'required|date|date_format:"Y-m-d"',
                        'due_date'      => 'required|date|date_format:"Y-m-d"',
                        'currency_id'   => 'required'
                    );
    
                    $validator = Validator::make(Input::all(), $rules);
    
                    if ($validator->passes())
                    {
                        $invoiceSettings = InvoiceSetting::first();
    
                        if (isset($invoiceSettings->number))
                        {
                            $invoiceNumber              = $invoiceSettings->number + 1;
                            $invoiceSettings->number    = $invoiceNumber;
                            $invoiceSettings->save();
                        }
    
                        $store              = new Invoiceout;
                        $store->number      = isset($invoiceSettings->number) ? $invoiceNumber : Input::get('number');
                        $store->status_id   = 2;
                        $store->discount    = Input::get('invoiceDiscount') ? Input::get('invoiceDiscount') : 0;
                        $store->type        = Input::get('invoiceDiscountType') ? Input::get('invoiceDiscountType') : 0;
                        $store->amount      = $store->calculateInvoice(Input::get('qty'), Input::get('price'), Input::get('taxes'), Input::get('discount'), Input::get('discountType'), Input::get('invoiceDiscount'), Input::get('invoiceDiscountType'));
                        $store->fill(Input::all());
                        $store->save();
    
                        $products           = Input::get('products');
    
                        foreach ($products as $k => $v)
                        {
                            $product                    = new InvoiceProduct;
                            $product->invoice_id        = $store->id;
                            $product->product_id        = $v;
                            $product->quantity          = Input::get('qty')[$k];
                            $product->price             = Input::get('price')[$k];
                            $product->tax               = Input::get('taxes')[$k];
                            $product->discount          = Input::get('discount')[$k] ? Input::get('discount')[$k] : 0;
                            $product->discount_type     = Input::get('discountType')[$k] ? Input::get('discountType')[$k] : 0;
                            $product->discount_value    = $store->calculateProductPrice(1, Input::get('qty')[$k], Input::get('price')[$k], Input::get('taxes')[$k], Input::get('discount')[$k], Input::get('discountType')[$k]);
                            $product->amount            = $store->calculateProductPrice(2, Input::get('qty')[$k], Input::get('price')[$k], Input::get('taxes')[$k], Input::get('discount')[$k], Input::get('discountType')[$k]);
                            $product->save();
    
                            App::make('ProductController')->manageQuantity($v, Input::get('qty')[$k], Input::get('price')[$k]);
                        }
    
                        $invoiceout = new Invoiceout;
                        $invoiceout->invoiceStatus();
    
    
                    }
                    else
                    {
                        $invoiceSettings    = InvoiceSetting::find(1);
    
                        $data = array(
                            'clients'       => Project::all(),
                            'products'      => Product::where('status', 1)->get(),
                            'currencies'    => Currency::all(),
                            'taxes'         => Tax::all(),
                            'invoiceCode'   => isset($invoiceSettings->code)    ? $invoiceSettings->code        : false,
                            'invoiceNumber' => isset($invoiceSettings-
                             >number)   ? $invoiceSettings->number + 1  : false,
                            'errors'        => $validator->errors(),
                            'inputs'        => Input::all()
                        );
    
                        return View::make('user.invoiceout.create', $data);
                    }
    
                    return $this->loadDataTable();
                }
    
    


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire