/** * Execute the job. * * @return void */ public function handle() { //Log::info("Handle Purchase Count Job ".$this->tanggal); $tanggal = $this->tanggal; $pembelian = PembelianBayar::where("tanggal", $tanggal)->select([DB::raw("SUM(nominal)total")])->groupBy("tanggal")->first(); if ($pembelian) { $total = $pembelian->total; if ($total >= 1) { $account = AccountSaldo::where('tanggal', $tanggal)->where('account_id', 1)->first(); if (!$account) { //create new AccountSaldo::create(['tanggal' => $tanggal, 'account_id' => 1, 'type' => 'kredit', 'nominal' => $total]); } else { // update value if ($account->nominal != $total) { AccountSaldo::find($account->id)->update(['nominal' => $total]); } } } } //Log::info("Handle Purchase Count Job ".$pembelian->total); }
public function bayarStore(PembelianBayarRequest $request, $id) { $input = $request->only(['tanggal', 'nominal']) + ['pembelian_id' => $id, 'karyawan_id' => '1']; $pembelian = Pembelian::find($id); if (PembelianBayar::create($input)) { // Update Purchase Account Artisan::call('purchase:count', ['tanggal' => $pembelian->tanggal->format('Y-m-d')]); return redirect()->back()->with('succcess', 'Sukses simpan pembayaran.'); } return redirect()->back()->withErrors(['failed' => 'Gagal simpan pembayaran.']); }