Ejemplo n.º 1
0
 protected static function AmbilStokSebelumnya($tanggal)
 {
     $produks = self::leftJoin('produk_details', 'produks.id', '=', 'produk_details.produk_id')->whereNull('produk_details.id')->select(['produks.id', 'produks.nama', 'produks.satuan'])->get();
     $CTanggal = Carbon::createFromFormat('Y-m-d h:i:s', $tanggal . ' 00:00:00');
     $CYesterday = $CTanggal->copy()->addDays(-1);
     $yesterday = $CYesterday->format('Y-m-d');
     $adjustmentIncreaseBefore = [];
     $firstAdjustmentIncrease = \App\AdjustmentDetail::where('type', 'produk')->where('state', 'increase')->with('adjustment')->first();
     if ($firstAdjustmentIncrease) {
         if ($firstAdjustmentIncrease->adjustment->tanggal->lte($CYesterday)) {
             $adjustmentIncreaseBefore = self::_adjustmentIncrease_Stok($firstAdjustmentIncrease->adjustment->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $adjustmentReductionBefore = [];
     $firstAdjustmentReduction = \App\AdjustmentDetail::where('type', 'produk')->where('state', 'reduction')->with('adjustment')->first();
     if ($firstAdjustmentReduction) {
         if ($firstAdjustmentReduction->adjustment->tanggal->lte($CYesterday)) {
             $adjustmentReductionBefore = self::_adjustmentReduction_Stok($firstAdjustmentReduction->adjustment->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $pembelianBefore = [];
     $firstPembelian = \App\PembelianDetail::where('pembelian_details.type', 'produk')->with('pembelian')->first();
     if ($firstPembelian) {
         if ($firstPembelian->pembelian->tanggal->lte($CYesterday)) {
             $pembelianBefore = self::_pembelian($firstPembelian->pembelian->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $penjualanBefore = [];
     $firstPenjualan = \App\OrderDetail::join(DB::raw("(SELECT produks.`id`, produks.`nama`\n                FROM produks LEFT JOIN produk_details ON produks.`id` = produk_details.`produk_id`\n                WHERE produk_details.`id` IS NULL GROUP BY produks.`id`)temp_produk"), 'order_details.produk_id', '=', 'temp_produk.id')->with('order')->select(['temp_produk.nama', 'order_details.*'])->first();
     if ($firstPenjualan) {
         if ($firstPenjualan->order->tanggal->lte($CYesterday)) {
             $penjualanBefore = self::_penjualan($firstPenjualan->order->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $display = [];
     foreach ($produks as $produk) {
         $temp = [];
         $sum = [];
         $idx = array_search($produk['id'], array_column($adjustmentIncreaseBefore, 'id'));
         if (false !== $idx) {
             $sum[] = $adjustmentIncreaseBefore[$idx]['qty'];
         }
         $idx = array_search($produk['id'], array_column($adjustmentReductionBefore, 'id'));
         if (false !== $idx) {
             $sum[] = -abs($adjustmentReductionBefore[$idx]['qty']);
         }
         $idx = array_search($produk['id'], array_column($pembelianBefore, 'id'));
         if (false !== $idx) {
             $sum[] = $pembelianBefore[$idx]['qty'];
         }
         $idx = array_search($produk['id'], array_column($penjualanBefore, 'id'));
         if (false !== $idx) {
             $sum[] = -abs($penjualanBefore[$idx]['qty']);
         }
         $display[] = $produk->toArray() + ['before' => array_sum($sum)];
     }
     return $display;
 }
Ejemplo n.º 2
0
 protected static function AmbilStokSebelumnya($tanggal)
 {
     $bahans = self::select(['bahans.id', 'bahans.nama', 'bahans.satuan'])->get();
     $CTanggal = Carbon::createFromFormat('Y-m-d h:i:s', $tanggal . ' 00:00:00');
     $CYesterday = $CTanggal->copy()->addDays(-1);
     $yesterday = $CYesterday->format('Y-m-d');
     $adjustmentIncreaseBefore = [];
     $firstAdjustmentIncrease = \App\AdjustmentDetail::where('type', 'bahan')->where('state', 'increase')->with('adjustment')->first();
     if ($firstAdjustmentIncrease) {
         if ($firstAdjustmentIncrease->adjustment->tanggal->lte($CYesterday)) {
             $adjustmentIncreaseBefore = self::_adjustmentIncrease_Stok($firstAdjustmentIncrease->adjustment->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $adjustmentReductionBefore = [];
     $firstAdjustmentReduction = \App\AdjustmentDetail::where('type', 'bahan')->where('state', 'reduction')->with('adjustment')->first();
     if ($firstAdjustmentReduction) {
         if ($firstAdjustmentReduction->adjustment->tanggal->lte($CYesterday)) {
             $adjustmentReductionBefore = self::_adjustmentReduction_Stok($firstAdjustmentReduction->adjustment->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $pembelianBefore = [];
     $firstPembelian = \App\PembelianDetail::where('pembelian_details.type', 'bahan')->with('pembelian')->first();
     if ($firstPembelian) {
         if ($firstPembelian->pembelian->tanggal->lte($CYesterday)) {
             $pembelianBefore = self::_pembelian($firstPembelian->pembelian->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $penjualanBefore = [];
     $firstPenjualan = \App\OrderDetailBahan::with('orderDetail.order')->first();
     if ($firstPenjualan) {
         if ($firstPenjualan->orderDetail->order->tanggal->lte($CYesterday)) {
             $penjualanBefore = self::_penjualan($firstPenjualan->orderDetail->order->tanggal->format('Y-m-d'), $yesterday);
         }
     }
     $display = [];
     foreach ($bahans as $bahan) {
         $temp = [];
         $sum = [];
         $idx = array_search($bahan['id'], array_column($adjustmentIncreaseBefore, 'id'));
         if (false !== $idx) {
             $sum[] = $adjustmentIncreaseBefore[$idx]['qty'];
         }
         $idx = array_search($bahan['id'], array_column($adjustmentReductionBefore, 'id'));
         if (false !== $idx) {
             $sum[] = -abs($adjustmentReductionBefore[$idx]['qty']);
         }
         $idx = array_search($bahan['id'], array_column($pembelianBefore, 'id'));
         if (false !== $idx) {
             $sum[] = $pembelianBefore[$idx]['qty'];
         }
         $idx = array_search($bahan['id'], array_column($penjualanBefore, 'id'));
         if (false !== $idx) {
             $sum[] = -abs($penjualanBefore[$idx]['qty']);
         }
         $display[] = $bahan->toArray() + ['before' => array_sum($sum)];
     }
     return $display;
 }