/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $input = Input::all();
     Suppliers::create($input);
     // redirect
     // Session::flash('message', 'Berhasil Menambah Data!');
     return redirect('suppliers')->with('message', 'Record added.');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['vat' => 'max:20']);
     $input = $request->all();
     Suppliers::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added new suppliers ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('SuppliersController@index');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['number' => 'unique:purchases,number']);
     $input = $request->all();
     if (array_key_exists('new_supplier', $input)) {
         $check_supplier = Suppliers::where(['title' => $input['custom_supplier']])->get();
         if (count($check_supplier) > 0) {
             $this->validate($request, ['custom_supplier' => 'unique:suppliers,title']);
             echo 'here';
         } else {
             $supplier = Suppliers::create(['title' => $input['custom_supplier']]);
             $input['supplier_id'] = $supplier->id;
             echo 'there';
         }
     }
     if ($input['category_id'] == 0) {
         $input['category_id'] = null;
     }
     if (array_key_exists('status', $input)) {
         $input['status'] = 1;
         $input['date_paid'] = date('Y-m-d H:i:s', time());
     } else {
         $input['status'] = 0;
     }
     if (array_key_exists('file', $input)) {
         if ($input['file']->isValid()) {
             $filename = 'invoice_' . date('Y_m_d_His') . '.' . $input['file']->getClientOriginalExtension();
             $input['file']->move(storage_path() . '/upload', $filename);
             $file = Files::create(['filename' => $filename]);
             $input['invoice_id'] = $file->id;
         }
     }
     $currentPeriodId = array_key_exists('stock_period_id', $input) ? $input['stock_period_id'] : Helper::currentPeriodId();
     $input['stock_period_id'] = $currentPeriodId;
     $purchase = Purchases::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'created new invoice ID ' . DB::getPdo()->lastInsertId());
     return Redirect::action('ItemPurchasesController@index', $purchase->id);
 }