public function ProdukStok()
 {
     // Produk stok dibawah ambang batas stok
     $produkStokWarning = Produk::join('stok_produks', 'produks.id', '=', 'stok_produks.produk_id')->where('produks.active', 1)->select(['produks.*', 'stok_produks.stok'])->get()->filter(function ($item) {
         return $item->stok < $item->qty_warning;
     });
     $data = ['data' => $produkStokWarning, 'header' => 'Produk'];
     return view(config('app.template') . '.dashboard.stok', $data);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     MutasiStokProduk::where('tanggal', $this->tanggal)->delete();
     $bahans = \App\Produk::MutasiStok($this->tanggal);
     $inserts = [];
     foreach ($bahans as $bahan) {
         array_push($inserts, ['produk_id' => $bahan['id'], 'before' => $bahan['before'], 'pembelian' => $bahan['pembelian'], 'penjualan' => $bahan['penjualan'], 'adjustment_increase' => $bahan['adjustment_increase'], 'adjustment_reduction' => $bahan['adjustment_reduction'], 'sisa' => $bahan['sisa'], 'tanggal' => $this->tanggal]);
     }
     MutasiStokProduk::insert($inserts);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $oldStok = StokProduk::all();
     $oldStokKey = array_column($oldStok->toArray(), 'produk_id');
     $produks = Produk::stok()->orderBy('produks.id')->get();
     foreach ($produks as $produk) {
         if (in_array($produk->id, $oldStokKey)) {
             StokProduk::where('produk_id', $produk->id)->update(['stok' => $produk->sisa_stok]);
         } else {
             StokProduk::create(['produk_id' => $produk->id, 'stok' => $produk->sisa_stok]);
         }
     }
 }
 public function getProduk(Request $request)
 {
     $produks = Produk::with(['detail' => function ($query) {
         $query->join('bahans', 'produk_details.bahan_id', '=', 'bahans.id');
     }])->where('active', 1)->where('nama', 'like', '%' . $request->get('q') . '%')->get();
     $data = [];
     foreach ($produks as $produk) {
         array_push($data, ['id' => $produk->id, 'nama' => $produk->nama, 'satuan' => $produk->satuan, 'harga' => CountPrice($produk)]);
     }
     return $data;
 }
 public function store(Request $request)
 {
     $denied = false;
     if (!$request->session()->has('data_pembelian')) {
         $denied = true;
     } else {
         $beliBahan = $request->session()->has('data_pembelian.bahan') ? $request->session()->get('data_pembelian.bahan') : [];
         $beliProduk = $request->session()->has('data_pembelian.produk') ? $request->session()->get('data_pembelian.produk') : [];
         if (empty($beliBahan) && empty($beliProduk)) {
             $denied = true;
         }
     }
     if ($denied) {
         return redirect('pembelian/add')->withInput()->withErrors(['no_details' => 'Tidak ada barang yang dibeli.']);
     }
     // Pembelian
     $karyawan_id = Auth::check() ? Auth::user()->karyawan->id : '1';
     $input = $request->only(['supplier_id', 'tanggal']) + ['karyawan_id' => $karyawan_id];
     $pembelian = Pembelian::create($input);
     // Pembelian Bayar
     if ($request->get('bayar') != "0") {
         $input = ['pembelian_id' => $pembelian->id, 'nominal' => $request->get('bayar'), 'karyawan_id' => $karyawan_id, 'tanggal' => $request->get('tanggal')];
         PembelianBayar::create($input);
         // Update Purchase Account
         Artisan::call('purchase:count', ['tanggal' => $pembelian->tanggal->format('Y-m-d')]);
     }
     # Update [Bahan => Harga, Produk => HPP]
     // Bahan
     if (!empty($beliBahan)) {
         $keys = array_keys($beliBahan);
         $bahans = \App\StokBahan::with(['bahan'])->whereIn('bahan_id', $keys)->orderBy('bahan_id')->get();
         foreach ($bahans as $bahan) {
             $bId = $bahan->bahan_id;
             $inStok = $beliBahan[$bId]['stok'];
             $inHarga = $beliBahan[$bId]['harga'] / $inStok;
             if ($bahan->bahan->harga != $inHarga) {
                 $oldTtl = $bahan->stok > 0 ? $bahan->bahan->harga * $bahan->stok : 0;
                 $inTtl = $inStok > 0 ? $inHarga * $inStok : 0;
                 $sumInOld = $oldTtl + $inTtl;
                 $qtyTotal = $bahan->stok + $inStok;
                 $harga = $sumInOld > 0 && $qtyTotal > 0 ? $sumInOld / $qtyTotal : 0;
                 if ($harga != $bahan->bahan->harga) {
                     //echo "<pre>", print_r(['id' => $bId, 'nama' => $bahan->nama, 'harga' => $harga]), "</pre>";
                     \App\Bahan::find($bId)->update(['harga' => $harga]);
                     \App\AveragePriceAction::create(['type' => 'bahan', 'relation_id' => $bId, 'old_price' => $bahan->bahan->harga, 'old_stok' => $bahan->stok, 'input_price' => $inHarga, 'input_stok' => $inStok, 'average_with_round' => $harga, 'action' => "Pembelian #" . $pembelian->id]);
                 }
             }
         }
         Artisan::call('bahan:count');
     }
     // Produk, Harga => HPP
     if (!empty($beliProduk)) {
         $keys = array_keys($beliProduk);
         $produks = \App\StokProduk::with(['produk'])->whereIn('produk_id', $keys)->orderBy('produk_id')->get();
         foreach ($produks as $produk) {
             $pId = $produk->produk_id;
             $inStok = $beliProduk[$pId]['stok'];
             $inHarga = $beliProduk[$pId]['harga'] / $inStok;
             if ($produk->produk->hpp != $inHarga) {
                 $oldTtl = $produk->stok > 0 ? $produk->produk->hpp * $produk->stok : 0;
                 $inTtl = $inStok > 0 ? $inHarga * $inStok : 0;
                 $sumInOld = $oldTtl + $inTtl;
                 $qtyTotal = $produk->stok + $inStok;
                 $harga = $sumInOld > 0 && $qtyTotal > 0 ? $sumInOld / $qtyTotal : 0;
                 // HPP
                 if ($harga != $produk->produk->hpp) {
                     //echo "<pre>", print_r(['id' => $pId, 'nama' => $produk->nama, 'harga' => $harga]), "</pre>";
                     \App\Produk::find($pId)->update(['hpp' => $harga]);
                     \App\AveragePriceAction::create(['type' => 'produk', 'relation_id' => $pId, 'old_price' => $produk->produk->hpp, 'old_stok' => $produk->stok, 'input_price' => $inHarga, 'input_stok' => $inStok, 'average_with_round' => $harga, 'action' => "Pembelian #" . $pembelian->id]);
                 }
             }
         }
         Artisan::call('produk:count');
     }
     // Pembelian Detail
     $details = array_merge($beliBahan, $beliProduk);
     $temp = [];
     foreach ($details as $detail) {
         array_push($temp, $detail + ['pembelian_id' => $pembelian->id]);
     }
     PembelianDetail::insert($temp);
     $request->session()->forget('data_pembelian');
     $request->session()->forget('info_pembelian');
     return redirect('/pembelian')->with('succcess', 'Sukses simpan data pembelian.');
 }
 public function ajaxLoad(Request $request)
 {
     if ($request->get('id')) {
         $produk = Produk::with(['detail' => function ($query) {
             $query->join('bahans', 'produk_details.bahan_id', '=', 'bahans.id');
         }])->where('active', 1)->where('id', $request->get('id'))->first();
         return ['id' => $produk->id, 'nama' => $produk->nama, 'satuan' => $produk->satuan, 'harga' => CountPrice($produk)];
     } else {
         $produk = Produk::leftJoin('produk_details', 'produks.id', '=', 'produk_details.produk_id')->where('nama', 'like', '%' . $request->get('q') . '%')->where('produks.active', 1)->whereNotIn('produks.id', explode('+', $request->get('except')))->select('produks.*')->groupBy('produks.id')->limit($request->get('page'));
         $produk = $request->get('without_has_bahan') == 'Ya' ? $produk->whereNull('produk_details.id') : $produk;
         $produk = $produk->get();
         return $produk;
     }
 }
 public function changeTransaksi(Request $request)
 {
     \Debugbar::disable();
     $id = $request->get('id');
     $data_order_detail = $request->get('data_order') != "" ? json_decode($request->get('data_order'), true) : [];
     // Convert like data session
     $temp = [];
     foreach ($data_order_detail as $d) {
         $key = $d['id'];
         $temp[$key] = $d;
     }
     $data_order_detail = $temp;
     $order = \App\Order::with('place.place')->find($id);
     if (count($data_order_detail)) {
         // Order Detail
         $orderDetailOld = \App\OrderDetail::where('order_id', $id)->whereIn('produk_id', array_keys($data_order_detail))->get();
         # Update Order Detail
         foreach ($orderDetailOld as $odo) {
             $oldQty = $odo->qty;
             $updateQty = $oldQty + $data_order_detail[$odo->produk_id]['qty'];
             $updatePrice = $data_order_detail[$odo->produk_id]['harga'];
             \App\OrderDetail::find($odo->id)->update(['qty' => $updateQty, 'harga_jual' => $updatePrice]);
             unset($data_order_detail[$odo->produk_id]);
         }
         if (count($data_order_detail)) {
             # New Order Detail
             $produks = Produk::with(['detail' => function ($query) {
                 $query->join('bahans', 'produk_details.bahan_id', '=', 'bahans.id');
             }])->whereIn('id', array_keys($data_order_detail))->get();
             $orderDetailBahan = [];
             foreach ($produks as $produk) {
                 $pId = $produk->id;
                 // Order Detail
                 $orderDetail = ['order_id' => $id, 'produk_id' => $produk->id, 'hpp' => CountHpp($produk), 'harga_jual' => $data_order_detail[$pId]['harga'], 'qty' => $data_order_detail[$pId]['qty'], 'use_mark_up' => $produk->use_mark_up, 'mark_up' => $produk->mark_up, 'note' => ""];
                 //echo "<pre>", print_r($orderDetail), "</pre>";
                 $orderDetail = \App\OrderDetail::create($orderDetail);
                 if ($produk->detail->count()) {
                     // Order Detail Bahan
                     foreach ($produk->detail as $pd) {
                         array_push($orderDetailBahan, ['order_detail_id' => $orderDetail->id, 'bahan_id' => $pd->bahan_id, 'harga' => $pd->harga, 'qty' => $pd->qty, 'satuan' => $pd->satuan]);
                     }
                 }
             }
             \App\OrderDetailBahan::insert($orderDetailBahan);
         }
     }
     Artisan::call('bahan:count');
     Artisan::call('produk:count');
     return 1;
 }
 protected function _stokPertahun(Request $request)
 {
     $tahun = $request->get('tahun') ? $request->get('tahun') : date('Y');
     $start = Carbon::parse('first day of January ' . $tahun);
     $end = Carbon::parse('last day of December ' . $tahun);
     $produks = \App\Produk::MutasiStok($start->format('Y-m-d'), $end->format('Y-m-d'));
     return ['tanggal' => Carbon::createFromFormat('Y', $tahun), 'produks' => $produks];
 }
 public function showTest(Request $request)
 {
     $action = $request->get('act') ? $request->get('act') : 'bahan';
     $action = strtolower($action);
     if ($action == 'produk') {
         return \App\Produk::stok()->orderBy('produks.id')->get();
     } elseif ($action == 'bahan') {
         return \App\Bahan::stok()->orderBy('bahans.id')->get();
     } else {
         abort(404);
     }
 }
Пример #10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Produk::destroy($id);
     $showDefault = cmsHelp('App\\Produk', 'produks');
     return Redirect('product')->with($showDefault);
 }
Пример #11
0
 /**
  * Fungsi buat tampilin semua data Produk
  */
 public function Produkpage()
 {
     $produk = Produk::paginate(2);
     $tipe = Type::all();
     return view('FrontEnd.product', compact('produk'));
 }