示例#1
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);
 }
示例#2
0
 public static function sale_detailed($sale_id)
 {
     $SaleItems = SaleItem::where('sale_id', $sale_id)->get();
     return $SaleItems;
 }