Пример #1
0
 /**
  * Remove the specified customer from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if ($pj = Penjualan::where('customer_id', '=', $id)->first()) {
         $pjid = $pj->id;
         DetailPenjualan::where('penjualan_id', '=', $pjid)->delete();
     }
     Penjualan::where('customer_id', '=', $id)->delete();
     Customer::destroy($id);
     return Redirect::to('admin/customer/tipe/1')->with('message', 'berhasil menghapus customer');
 }
 public function deleteDetail()
 {
     if (isset($_POST)) {
         $id = $_POST['id'];
         $det = DetailPenjualan::findOrFail($id);
         $penjualan = Penjualan::where('id', '=', $det->penjualan_id)->first();
         // dd($penjualan->id);
         if (DetailPenjualan::destroy($id)) {
             $barangs = DetailPenjualan::where('penjualan_id', '=', $penjualan->id)->get();
             $nominal = 0;
             foreach ($barangs as $key => $value) {
                 $nominal += $value->total;
             }
             $penjualan->nominal = $nominal;
             $penjualan->save();
         }
     }
 }