public function post() { $post = Input::all(); $validator = Adjustment::validate($post); $adjustmentId = $post['id']; if ($validator->fails()) { return Redirect::to('ajustes/' . $adjustmentId)->withErrors($validator)->withInput(); } else { $adjustment = self::__checkExistence($adjustmentId); if (!$adjustmentId) { DB::beginTransaction(); $adjustment = new Adjustment(); $adjustment->products_id = $post['products_id']; $adjustment->users_id = Auth::user()->id; $adjustment->type = $post['type']; $adjustment->amount = $post['amount']; $adjustment->reason = $post['reason']; $adjustment->save(); $product = Product::find($post['products_id']); if ($post['type'] == 'credit') { $product->stock = $product->stock + $post['amount']; $product->save(); } else { if ($product->stock >= $post['amount']) { $product->stock = $product->stock - $post['amount']; $product->save(); Globals::triggerAlerts(1, array('productId' => $product->id)); Globals::triggerAlerts(2, array('productId' => $product->id)); } else { Session::flash('error', 'No se puede debitar más de lo que hay en stock.'); DB::rollback(); return Redirect::to('ajustes'); } } Session::flash('success', 'Ajuste realizado exitosamente.'); DB::commit(); } return Redirect::to('ajustes'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $validator = $this->validate(); if ($validator->fails()) { return Redirect::back()->withErrors($validator->messages())->withInput(Input::all()); } $type = Input::get('type'); $product = Product::find(Input::get('product_id')); $location = Location::find(Input::get('location_id')); $quantity = Input::get('quantity'); $adjustment_date = Input::get('adjustment_date'); $description = Input::get('description'); DB::beginTransaction(); $adjustment = new Adjustment(); // Record details in adjustment table // Type [1 : Positive] [2 : Negative] $adjustment->type = $type; $adjustment->adjustment_date = $adjustment_date; $adjustment->description = $description; $adjustment->save(); // Store other details in a new array $extra = array('product-id ' => $product->id, 'quantity' => $quantity, 'location_id' => $location->id); // Get the current adjustment id; //Update records in the adjustment_products table //If type : POSITIVE // 1.Find the correct record and Increment the product qty in location_products table // 2.Update item_in table //If type : NEGATIVE // 1.Find the correct record and Decrement the product qty in location_products table // 2.Update item_out table $response = Event::fire('adjustment.create', array($adjustment, $extra)); DB::commit(); print_r($response); exit; Session::flash('success', 'Successfully created donation!'); return Redirect::route('adjustment.index'); }
public static function billadjustment($account_id, $for_month, $amount, $bill) { $bill_info = Billinformation::where('bill_no', $bill->bill_no)->get(); foreach ($bill_info as $key) { $amount_id[] = $key->adjustment_id; } if (count($bill_info) == 0) { $amount_id[] = NULL; } $bill_amount = Adjustment::whereIn('id', $amount_id)->sum('amount'); if ($bill->adjustments == $bill_amount) { return $bill_amount; } else { if ($bill->adjustments && $bill_amount == 0) { $adjustment = new Adjustment(); $adjustment->account_id = $account_id; $adjustment->for_month = $for_month; $adjustment->amount = $amount; $adjustment->date = date('Y-m-d'); $adjustment->remarks = "billadjustment retransaction"; $adjustment->is_considered = 1; $adjustment->save(); $bill_info = Adjustment::adjustments($adjustment->id, $adjustment->account_id, $adjustment->for_month); return $adjustment->amount; } else { if ($bill->adjustments != $bill_amount) { return false; } } } }