public function newItem()
 {
     $type = Input::get('type');
     if ($type == 1) {
         $ReceivingTemps = new ReceivingTemp();
         $ReceivingTemps->item_id = Input::get('item_id');
         $ReceivingTemps->cost_price = Input::get('cost_price');
         $ReceivingTemps->total_cost = Input::get('total_cost');
         $ReceivingTemps->quantity = 1;
         $ReceivingTemps->save();
         return $ReceivingTemps;
     } else {
         $itemkits = ItemKitItem::where('item_kit_id', Input::get('item_id'))->get();
         foreach ($itemkits as $value) {
             $item = Item::where('id', $value->item_id)->first();
             $ReceivingTemps = new ReceivingTemp();
             $ReceivingTemps->item_id = $value->item_id;
             $ReceivingTemps->cost_price = $item->cost_price;
             $ReceivingTemps->total_cost = $item->cost_price * $value->quantity;
             $ReceivingTemps->quantity = $value->quantity;
             $ReceivingTemps->save();
             //return $ReceivingTemps;
         }
         return $ReceivingTemps;
     }
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $sales = new Sale();
     // $sales->customer_id = Input::get('customer_id');
     Session::put('add_payment', Input::get('add_payment'));
     $sales->customer_id = 1;
     $sales->customer_name = Input::get('customer_name');
     $sales->user_id = Auth::user()->id;
     $sales->payment_type = Input::get('payment_type');
     $sales->comments = Input::get('comments');
     $sales->save();
     // process sale items
     $saleItems = SaleTemp::all();
     foreach ($saleItems as $value) {
         $saleItemsData = new SaleItem();
         $saleItemsData->sale_id = $sales->id;
         $saleItemsData->item_id = $value->item_id;
         $saleItemsData->cost_price = $value->cost_price;
         $saleItemsData->selling_price = $value->selling_price;
         $saleItemsData->quantity = $value->quantity;
         $saleItemsData->total_cost = $value->total_cost;
         $saleItemsData->total_selling = $value->total_selling;
         $saleItemsData->save();
         //process inventory
         $items = Item::find($value->item_id);
         if ($items->type == 1) {
             $inventories = new Inventory();
             $inventories->item_id = $value->item_id;
             $inventories->user_id = Auth::user()->id;
             $inventories->in_out_qty = -$value->quantity;
             $inventories->remarks = 'SL0000' . $sales->id;
             $inventories->save();
             //process item quantity
             $items->quantity = $items->quantity - $value->quantity;
             $items->save();
         } else {
             $itemkits = ItemKitItem::where('item_kit_id', $value->item_id)->get();
             foreach ($itemkits as $item_kit_value) {
                 $inventories = new Inventory();
                 $inventories->item_id = $item_kit_value->item_id;
                 $inventories->user_id = Auth::user()->id;
                 $inventories->in_out_qty = -($item_kit_value->quantity * $value->quantity);
                 $inventories->remarks = 'SL0000' . $sales->id;
                 $inventories->save();
                 //process item quantity
                 $item_quantity = Item::find($item_kit_value->item_id);
                 $item_quantity->quantity = $item_quantity->quantity - $item_kit_value->quantity * $value->quantity;
                 $item_quantity->save();
             }
         }
     }
     //delete all data on SaleTemp model
     SaleTemp::truncate();
     $itemssale = SaleItem::where('sale_id', $saleItemsData->sale_id)->get();
     Session::flash('message', 'You have successfully added sales');
     //return Redirect::to('receivings');
     return view('sale.complete2')->with('sales', $sales)->with('saleItemsData', $saleItemsData)->with('saleItems', $itemssale);
 }