Ejemplo n.º 1
0
 public function run()
 {
     $faker = Faker::create();
     $users = User::get();
     $products = Product::get();
     for ($i = 0; $i < 10; $i++) {
         $user = $users->random(1);
         $status = $faker->randomElement(['open', 'paid', 'pending', 'installed', 'cancelled']);
         $order = Order::create(['user_id' => $user->id, 'status' => $status, 'end_date' => $status == 'installed' || $status == 'cancelled' ? $faker->dateTime() : null]);
         $random = $faker->numberBetween(1, 2);
         for ($y = 0; $y < $random; $y++) {
             $product = $products->random(1);
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => 1]);
         }
     }
 }
Ejemplo n.º 2
0
 public function run()
 {
     $faker = Faker::create();
     $users = Address::get();
     $status_list = array_keys(trans('globals.order_status'));
     for ($i = 0; $i < 20; $i++) {
         $user = $users->random(1);
         $products = Product::get();
         $type = $faker->randomElement(['cart', 'wishlist', 'order']);
         $status = 'open';
         switch ($type) {
             case 'order':
                 $status = $faker->randomElement($status_list);
                 break;
         }
         $stock = $faker->numberBetween(1, 20);
         $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->id, 'status' => $status, 'type' => $type, 'description' => $type == 'wishlist' ? $faker->companySuffix : '', 'end_date' => $status == 'closed' || $status == 'cancelled' ? $faker->dateTime() : null]);
         $num = $faker->numberBetween(2, 5);
         $list = [];
         if ($num > 1 && count($products) - 1 < $num) {
             $num = count($products) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $product = $products->random(1);
                 if (in_array($product->id, $list)) {
                     $a = false;
                 } else {
                     $list[] = $product->id;
                 }
             } while ($a == false);
             if ($status == 'closed') {
                 $delivery = $faker->dateTime();
             } else {
                 $delivery = $faker->numberBetween(0, 1) ? $faker->dateTime() : null;
             }
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => $stock, 'delivery_date' => $delivery]);
         }
         $order->sendNotice();
     }
 }
 public function order($id, OrderFormRequest $request)
 {
     $receiver_name = $request->input('receiver_name');
     $address = $request->input('address');
     $phone = $request->input('phone');
     $email = $request->input('email');
     $received_date = $request->input('received_date');
     //
     $result = Order::create(['user_id' => $id, 'receiver_name' => $receiver_name, 'received_date' => $received_date, 'address' => $address, 'phone' => $phone, 'email' => $email]);
     if (count($result) > 0) {
         $items = Cart::content();
         $ordered_id = Order::select('id')->orderBy('id', 'desc')->first();
         foreach ($items as $item) {
             OrderDetail::create(['ordered_id' => $ordered_id->id, 'user_id' => $id, 'product_id' => $item->id, 'quantity' => $item->qty, 'price' => $item->price]);
             $update_quantity = Product::find($item->id);
             $update_quantity->update(['quantity' => $update_quantity->quantity - $item->qty]);
         }
     }
     Cart::destroy();
     return redirect()->route('completed');
 }
 public function run()
 {
     $faker = Faker::create();
     $users = UserAddress::get();
     $status_list = array_keys(trans('globals.order_status'));
     for ($i = 0; $i < 40; $i++) {
         $user = $users->random(1);
         $products = Product::where('id', '!=', $user->user_id)->where('type', '!=', 'freeproduct')->get();
         $type = 'freeproduct';
         $status = 'paid';
         $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->address_id, 'status' => 'paid', 'type' => $type, 'description' => '', 'end_date' => null]);
         //Productos a insertar a la orden. Se haran copias de los productos que esten en las ordenes y se le asignara el tipo freeproduct
         $num = $faker->numberBetween(2, 5);
         $list = [];
         if ($num > 1 && count($products) - 1 < $num) {
             $num = count($products) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $product = $products->random(1);
                 $quantity = $faker->numberBetween(1, 5);
                 if (in_array($product->id, $list)) {
                     $a = false;
                 } else {
                     //duplico el producto
                     $productactual = $product->toArray();
                     unset($productactual['id']);
                     unset($productactual['num_of_reviews']);
                     $productactual['user_id'] = '3';
                     //$user->user_id;
                     $productactual['type'] = 'freeproduct';
                     $productactual['parent_id'] = $product->id;
                     $newproduct = Product::create($productactual);
                     $list[] = $product->id;
                 }
             } while ($a == false);
             //el nuevo producto lo asocio al detalle de la orden
             OrderDetail::create(['order_id' => $order->id, 'product_id' => $newproduct->id, 'price' => $product->price, 'quantity' => $quantity, 'delivery_date' => null]);
             //Actualizo el stock
             $product->stock = $product->stock - $quantity;
             $product->save();
         }
         $order->sendNotice();
     }
     $orders = Order::where('type', '=', 'freeproduct')->get();
     $users = User::where('type', 'trusted')->get();
     $list_orders = [];
     for ($i = 0; $i < 15; $i++) {
         //Se crea el free product y se asocia las ordenes
         $user = $users->random(1);
         $end_date = \Carbon\Carbon::now()->addDays($faker->numberBetween(5, 30));
         $freeproduct = FreeProduct::create(['user_id' => '3', 'description' => $faker->unique()->catchPhrase, 'start_date' => \Carbon\Carbon::now(), 'end_date' => $end_date, 'participation_cost' => $faker->numberBetween(10000, 50000), 'min_participants' => $min_participants = $faker->numberBetween(1, 15), 'max_participants' => $faker->numberBetween($min_participants, $min_participants * 2), 'max_participations_per_user' => $faker->numberBetween(1, 5), 'draw_number' => $faker->numberBetween(1, 3), 'draw_date' => $end_date->addDays($faker->numberBetween(1, 5)), 'status' => $faker->randomElement([0, 1])]);
         //asocio una o mas ordenes a un free product
         $num = $faker->numberBetween(1, 3);
         if ($num > 1 && count($orders) - 1 < $num) {
             $num = count($orders) - 1;
         }
         for ($j = 0; $j < $num; $j++) {
             do {
                 $a = true;
                 $order = $orders->random(1);
                 if (in_array($order->id, $list_orders)) {
                     $a = false;
                 } else {
                     $list_orders[] = $order->id;
                 }
             } while ($a == false);
             FreeProductOrder::create(['order_id' => $order->id, 'freeproduct_id' => $freeproduct->id]);
         }
     }
 }
 public function saveMergeOrder(Request $request, $id)
 {
     if ($id == $request->get('to_order_id')) {
         return 2;
     }
     $currentOrderDetail = OrderDetail::with('detailBahan')->where('order_id', $id)->get();
     foreach ($currentOrderDetail as $cod) {
         $toOrderDetail = OrderDetail::where('order_id', $request->get('to_order_id'))->where('produk_id', $cod->produk_id);
         if ($toOrderDetail->count()) {
             // Update Qtys
             $oldQty = $toOrderDetail->first()->qty;
             $updateQty = $oldQty + $cod->qty;
             $toOrderDetail->first()->update(['qty' => $updateQty]);
         } else {
             // New Data
             $in = array_except($cod->toArray(), ['id', 'order_id', 'detail_bahan']) + ['order_id' => $request->get('to_order_id')];
             $odn = OrderDetail::create($in);
             $detailBahan = array_get($cod->toArray(), 'detail_bahan');
             $in = [];
             foreach ($detailBahan as $db) {
                 array_push($in, array_except($db, ['id', 'order_detail_id']) + ['order_detail_id' => $odn->id]);
             }
             OrderDetailBahan::insert($in);
         }
     }
     if (OrderMerge::insert(['order_id' => $id, 'to_order_id' => $request->get('to_order_id')])) {
         if ($request->get('use_place') == '1') {
             $orderPlace = OrderPlace::where('order_id', $id)->get();
             $temp = [];
             foreach ($orderPlace as $op) {
                 array_push($temp, ['order_id' => $request->get('to_order_id'), 'place_id' => $op->place_id, 'harga' => $op->harga]);
             }
             OrderPlace::insert($temp);
         }
         if (Order::find($id)->update(['state' => 'Merged'])) {
             return 1;
         }
     }
     return 0;
 }
Ejemplo n.º 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $orderDetail = Request::all();
     OrderDetail::create($orderDetail);
     return redirect('orderDetails');
 }
 public function changeTransaksi(Request $request)
 {
     \Debugbar::disable();
     $id = $request->get('id');
     $data_order_detail = $request->get('data_order') != "" ? json_decode($request->get('data_order'), true) : [];
     // Convert like data session
     $temp = [];
     foreach ($data_order_detail as $d) {
         $key = $d['id'];
         $temp[$key] = $d;
     }
     $data_order_detail = $temp;
     $order = \App\Order::with('place.place')->find($id);
     if (count($data_order_detail)) {
         // Order Detail
         $orderDetailOld = \App\OrderDetail::where('order_id', $id)->whereIn('produk_id', array_keys($data_order_detail))->get();
         # Update Order Detail
         foreach ($orderDetailOld as $odo) {
             $oldQty = $odo->qty;
             $updateQty = $oldQty + $data_order_detail[$odo->produk_id]['qty'];
             $updatePrice = $data_order_detail[$odo->produk_id]['harga'];
             \App\OrderDetail::find($odo->id)->update(['qty' => $updateQty, 'harga_jual' => $updatePrice]);
             unset($data_order_detail[$odo->produk_id]);
         }
         if (count($data_order_detail)) {
             # New Order Detail
             $produks = Produk::with(['detail' => function ($query) {
                 $query->join('bahans', 'produk_details.bahan_id', '=', 'bahans.id');
             }])->whereIn('id', array_keys($data_order_detail))->get();
             $orderDetailBahan = [];
             foreach ($produks as $produk) {
                 $pId = $produk->id;
                 // Order Detail
                 $orderDetail = ['order_id' => $id, 'produk_id' => $produk->id, 'hpp' => CountHpp($produk), 'harga_jual' => $data_order_detail[$pId]['harga'], 'qty' => $data_order_detail[$pId]['qty'], 'use_mark_up' => $produk->use_mark_up, 'mark_up' => $produk->mark_up, 'note' => ""];
                 //echo "<pre>", print_r($orderDetail), "</pre>";
                 $orderDetail = \App\OrderDetail::create($orderDetail);
                 if ($produk->detail->count()) {
                     // Order Detail Bahan
                     foreach ($produk->detail as $pd) {
                         array_push($orderDetailBahan, ['order_detail_id' => $orderDetail->id, 'bahan_id' => $pd->bahan_id, 'harga' => $pd->harga, 'qty' => $pd->qty, 'satuan' => $pd->satuan]);
                     }
                 }
             }
             \App\OrderDetailBahan::insert($orderDetailBahan);
         }
     }
     Artisan::call('bahan:count');
     Artisan::call('produk:count');
     return 1;
 }
Ejemplo n.º 8
0
 public function saveClientOrder(Request $request)
 {
     $input = $request->all();
     if (!empty($input['qty'])) {
         $mainArr = array();
         $hbody = '';
         $loc_info = DB::table('test_locations')->where('id', '=', $input['test_location_id'])->first();
         $orderData = array('user_id' => $input['user_id'], 'customer_id' => $input['customer_id'], 'site_id' => $input['site_id'], 'test_location_id' => $input['test_location_id'], 'interval' => $input['interval']);
         $order = new Order();
         $order->create($orderData);
         $order_id = DB::getPdo()->lastInsertId();
         $total = 0;
         foreach ($input['qty'] as $test_id => $qty) {
             $data = DB::table('tests')->where('tests.id', '=', $test_id)->join('parameters', 'tests.parameter_id', '=', 'parameters.id')->join('states', 'tests.state_id', '=', 'states.id')->join('methods', 'tests.method_id', '=', 'methods.id')->join('test_methods', 'tests.test_method_id', '=', 'test_methods.id')->select('tests.id', 'tests.price', 'parameters.name as parameter', 'states.name as state', 'methods.name as method', 'states.name as state', 'test_methods.name as test_method')->first();
             $orderArr = array();
             $orderArr['order_id'] = $order_id;
             $orderArr['test_id'] = $test_id;
             $orderArr['location_id'] = $loc_info->location_id;
             $orderArr['location_type'] = $loc_info->type;
             $orderArr['location_name'] = $loc_info->name;
             $orderArr['location_description'] = $loc_info->description;
             $orderArr['quantity'] = $qty;
             $orderArr['price'] = round($qty * $data->price, 2);
             $orderArr['parameter'] = $data->parameter;
             $orderArr['state'] = $data->state;
             $orderArr['method'] = $data->method . '-' . $data->test_method;
             $orderArr['test_method'] = $data->test_method;
             $orderArr['total'] = $orderArr['price'] * $orderArr['quantity'];
             $hbody .= "<tr>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_id'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_type'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['location_description'] . "</td>\n\t\t\t\t\t<td width='300px'>" . $orderArr['parameter'] . "</td>\n\t\t\t\t\t<td width='30px'>" . $orderArr['state'] . "</td>\n\t\t\t\t\t<td width='50px'>" . $orderArr['method'] . "</td>\n\t\t\t\t\t<td width='200px'>" . $orderArr['test_method'] . "</td>\n\t\t\t\t\t<td width='20px'>" . $orderArr['quantity'] . "</td>\n\t\t\t\t\t<td width='50px'>\$" . $orderArr['price'] . "</td></tr>";
             $orderDetails = new OrderDetail();
             $orderDetails->create($orderArr);
             $total += $orderArr['total'];
         }
         $order = Order::find($order_id);
         $order->update(array('total' => $total));
         $html = "<p>Hi Admin,</p>";
         $html .= "<p>There is order requested by Customer Id: " . $input['customer_id'] . "</p>";
         $html .= "<table style='border:1px solid #ccc'>\n\t\t\t\t\t<thead style='border-bottom:1px solid #ccc'>\n\t\t\t\t\t<td width='300px'><strong>Location ID</strong></td>\n\t\t\t\t\t<td width='30px'><strong>Location type</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Location Description</strong></td>\n\t\t\t\t\t<td width='300px'><strong>Parameter</strong></td>\n\t\t\t\t\t<td width='30px'><strong>State</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Method</strong></td>\n\t\t\t\t\t<td width='200px'><strong>Test Method</strong></td>\n\t\t\t\t\t<td width='20px'><strong>Qty</strong></td>\n\t\t\t\t\t<td width='50px'><strong>Price</strong></td>\n\t\t\t\t\t</thead>\n\t\t\t\t\t<tbody>";
         $hend = "</tbody></table><p>Thanks</p>";
         $allhtml = $html . $hbody . $hend;
         //mail('*****@*****.**', 'Order Request', $allhtml);
         $headers = "MIME-Version: 1.0" . "\r\n";
         $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
         // More headers
         $headers .= 'From: <*****@*****.**>' . "\r\n";
         $to = "*****@*****.**";
         $subject = "Order Request";
         mail($to, $subject, $allhtml, $headers);
     }
     if ($order_id) {
         Session::flash('flash_message', 'Request Submitted Successfully.');
         Session::flash('flash_type', 'alert-success');
     }
     return redirect('order');
 }