public function index()
 {
     $buyer = null;
     $seller = null;
     $maxSale = Sales::addSelect('items.id AS id', 'items.name AS name', 'bids.price AS price', 'bids.user_id AS buyer_id', 'items.user_id AS seller_id')->join('bids', 'sales.bid_id', '=', 'bids.id')->join('items', 'bids.item_id', '=', 'items.id')->orderBy('bids.price', 'desc')->first();
     if ($maxSale !== null) {
         $buyer = User::withTrashed()->find($maxSale->buyer_id);
         $seller = User::withTrashed()->find($maxSale->seller_id);
     }
     return view('index')->with(compact('maxSale', 'buyer', 'seller'));
 }
 /**
  * Traite un item
  *
  * @param \App\Items $item Item à traiter
  * @return array Logs
  */
 public function handleItem($item)
 {
     $logs = [];
     // Dernière enchère de l'annonce
     $lastBid = $item->bids->last();
     // Est-ce qu'on a au moins eu une enchère ?
     if ($lastBid !== null) {
         $logs[] = $item->user->pseudo . ' a vendu à ' . $lastBid->user->pseudo . '.';
         $this->sendMailForSell($item->user, $lastBid->user, $item, $lastBid);
         // La vente a bien été effectuée ! :-)
         $sale = new Sales();
         $sale->bid_id = $lastBid->id;
         $sale->save();
         // Suppression des enchères de l'utilisateur sur l'annonce en cours
         $lastBid->user->bids()->where('item_id', $item->id)->delete();
         $logs[] = $this->handleBuyer($lastBid->user);
     } else {
         $logs[] = $item->user->pseudo . ' n\'a pas réussi à vendre.';
         $this->sendMailForNotSell($item->user, $item);
     }
     $item->delete();
     $logs[] = $this->handleSeller($item->user);
     return $logs;
 }
Esempio n. 3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Sales::find($id)->delete();
     return redirect('sales');
 }
Esempio n. 4
0
    public function exchange(Request $request, $id)
    {
        $branch = Auth::user()->branch;
        $products = explode(",", session()->get('old_sale')['products']);
        $quantity = explode(",", session()->get('old_sale')['quantity']);
        for ($i = 0; $i < count($products); ++$i) {
            \DB::update('UPDATE stock SET quantity=quantity+"' . $quantity[$i] . '" where pid="' . $products[$i] . '" and branch="' . $branch . '"');
        }
        $categories = '';
        $productNames = '';
        $products = '';
        $unit_prices = '';
        $quantities = '';
        $amounts = '';
        for ($i = 1; $i < 41; $i++) {
            $category = $request->get('category' . $i);
            $product = $request->get('productName' . $i);
            $productName = $request->get('products' . $i);
            $unit_price = $request->get('price' . $i);
            $quantity = $request->get('quantity' . $i);
            $amount = $request->get('amount' . $i);
            if (isset($category)) {
                $categories = $categories . $category . ',';
            }
            if (isset($product)) {
                $products = $products . $product . ',';
                \DB::update('UPDATE stock SET quantity=round(quantity-' . $quantity . ',2) WHERE cid=' . $category . ' AND pid=' . $product . ' AND branch=' . "'" . $branch . "'");
            }
            if (isset($productName)) {
                $productNames = $productNames . $productName . ',';
            }
            if (isset($unit_price)) {
                $unit_prices = $unit_prices . $unit_price . ',';
            }
            if (isset($quantity)) {
                $quantities = $quantities . $quantity . ',';
            }
            if (isset($amount)) {
                $amounts = $amounts . $amount . ',';
            }
        }
        $input = array('total_price' => $request->get('total_price'), 'invoice_no' => $request->get('invoiceNo'), 'customer_id' => $request->get('customerName'), 'customer_address' => $request->get('address'), 'categories' => $categories, 'products' => $products, 'productNames' => $productNames, 'unit_price' => $unit_prices, 'quantity' => $quantities, 'amount' => $amounts, 'total_price' => $request->get('total_price'), 'vat' => $request->get('vat'), 'total_price_vat' => $request->get('totalAmountVat'), 'discount' => $request->get('discount'), 'discount_price' => $request->get('discountAmount'), 'paid' => $request->get('paid'), 'dues' => $request->get('dues'), 'profit' => $request->get('net_profit'), 'sold_by' => Auth::user()->name);
        $data = Sales::findOrFail($id);
        $data->update($input);
        \DB::delete('DELETE FROM income WHERE invoice_no=' . '"' . $request->get('invoiceNo') . '"');
        \DB::insert('insert into income(invoice_no, income_title, amount, branch, status, collected_by, created_at, updated_at) VALUES
("' . $request->get('invoiceNo') . '", "' . 'Sales (Exchange)' . '" , "' . $request->get('paid') . '", "' . $branch . '", "' . 'Valid' . '", "' . Auth::user()->name . '", "' . date('Y-m-d H:i:s') . '", "' . date('Y-m-d H:i:s') . '")');
        \DB::delete('DELETE FROM net_balance WHERE address=' . '"' . $request->get('invoiceNo') . '"');
        \DB::insert('insert into net_balance(transaction_title, address, credit, debit, branch, status, collected_by, created_at, updated_at) VALUES
("' . 'Sales Profit (Exchange)' . '", "' . $request->get('invoiceNo') . '",  "' . $request->get('net_profit') . '", "0", "' . $branch . '", "' . 'Valid' . '", "' . Auth::user()->name . '", "' . date('Y-m-d H:i:s') . '", "' . date('Y-m-d H:i:s') . '")');
        session()->put('sale_input', $input);
        return redirect('/prints');
    }
Esempio n. 5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $data = Customers::find($id)->toArray();
     $sales = Sales::with('karyawan')->get()->toArray();
     return view('customer.edit', compact('data', 'sales'));
 }