/** * Run the migrations. * * @return void */ public function up() { Schema::create('packages', function(Blueprint $table) { $table->increments('id'); $table->integer('game_id')->unsigned(); $table->string('name')->unique(); $table->string('status')->nullable(); $table->timestamps(); $table->foreign('game_id') ->references('id') ->on('games') ->onDelete('cascade'); }); $games = Game::all(); foreach ($games as $i=>$game) { $temp = str_replace('http://www.9apps.com/jump/down/', '', $game->download); $temp = str_replace('/app/', '', $temp); $check = Package::where('name', $temp)->first(); if (!$check) { Package::create([ 'game_id' => $game->id, 'name' => $temp ]); } } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $package = Package::where('ttn', $id)->first(); if (is_null($package)) { return "Not Found!"; } else { return View::make('packages.info', ['package' => $package, 'category' => 2]); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request) { // get total rows $totalRecords = Package::where('status', '1')->get()->count(); $main_data = array(); if ($totalRecords > 0) { // set unique token into session $unique = $this->getUniqueNo(); Session::set('secure_url', $unique); $main_data['draw'] = 1; $main_data['recordsTotal'] = $totalRecords; $main_data['recordsFiltered'] = $totalRecords; // condition $orderby = 'id'; $dir = 'asc'; // set starting form to lenght record $skip = 0; $take = 10; // query object $query = Package::query(); $query->select('id', 'name', 'price', 'created_at')->where('status', '1'); // get request from database if ($request->has('search')) { $req = $request->only('search', 'order', 'start', 'length', 'draw'); // pre defined filters list $filters = array('name', 'price', 'created_at'); // serarch records if (!empty($req['search']['value'])) { $query->where('name', 'like', '%' . $req['search']['value'] . '%'); } // record get according $orderby = $filters[$req['order'][0]['column']]; $dir = $req['order'][0]['dir']; // serarch records from to len $skip = $req['start']; $take = $req['length']; $main_data['draw'] = $req['draw']; } // get records $records = $query->orderby($orderby, $orderby)->skip($skip)->take($take)->get(); foreach ($records as $key => $value) { $edit = '<a href="' . Config::get("app.url") . 'admin/package/edit/' . $value->id . 'mlm' . $unique . '"><i class="glyphicon glyphicon-edit"></i></a>'; $delete = '<a href="javascript:;" data-id="' . $value->id . $unique . '" data-token="mlm' . $unique . 'ppa" class="package-delete"><i class="glyphicon glyphicon-remove"></i></a>'; $main_data['data'][] = array($value->name, $value->price, date('d M Y H:i:s', strtotime($value->created_at)), $edit, $delete); } } // return response return Response::json($main_data); }
/** * Execute the console command. * * @return mixed */ public function fire() { $grandfatherPricing = SiteConfig::whereParameter('grandfatherPricing')->first()->data; $priceMethod = SiteConfig::whereParameter('priceMethod')->first()->data; $domainId = SiteConfig::whereParameter('domainId')->first()->data; $tcOrigin = Config::get('taxcloud.originAddress'); $this->taxCloud->setOriginAddress($tcOrigin['address1'], $tcOrigin['address2'], $tcOrigin['city'], $tcOrigin['state'], $tcOrigin['zip']); if ($priceMethod == 'fixedRatio') { $priceData = SiteConfig::where('parameter', 'LIKE', '%Price')->get(); foreach ($priceData as $pd) { $this->pricing[$pd->parameter] = $pd->data; } } else { if ($priceMethod == 'elementPrice') { $priceData = ElementCost::all(); foreach ($priceData as $pd) { $this->pricing[$pd->element]["{$pd->quantity}-{$pd->quantity_type}"] = $pd->price; } } } // Get all of the users with a bill date of today. $users = User::billableToday()->chunk(100, function ($users) use($grandfatherPricing, $priceMethod, $domainId) { foreach ($users as $user) { $acsAccountData = app('Cloudstack\\CloudStackClient')->listUsers(['account' => $user->email, 'domainid' => $domainId])[0]; $invoiceID = uniqid(); $this->info("Working on user {$user->email}, account ID {$acsAccountData->accountid}"); // Get usage records data for VM, disk and general. UsageInstance::where('accountId', '=', $acsAccountData->accountid)->chunk(100, function ($instanceUsage) { // Go through the usage and make a nice array that we can invoice from foreach ($instanceUsage as $record) { $this->repo->addRecord($record); } }); UsageDisk::where('accountId', '=', $acsAccountData->accountid)->chunk(100, function ($diskUsage) { foreach ($diskUsage as $record) { $this->repo->addRecord($record); } }); // Begin pricing VMs and setting TIC on each record. $usage = $this->repo->all(); print_r($usage); $usage['subtotal'] = 0; // Loop through the aggregated records and add pricing and tax information foreach ($usage['instance'] as $vmid => &$instance) { foreach ($instance as $so_id => &$so_instance) { $pkg = Package::where('cpu_number', '=', $so_instance['resources']['cpunumber'])->where('ram', '=', $so_instance['resources']['memory'])->where('disk_size', '=', $so_instance['resources']['disk_size'])->where('disk_type', '=', $so_instance['resources']['disk_type'])->first(); if ($pkg instanceof Package) { $so_instance['tic'] = $pkg->tic; // Set the price $so_instance['price'] = $pkg->price / 720 * $so_instance['usage']; } else { // Instance has custom parameters and should be priced by its individual elements. if ($priceMethod == 'fixedRatio') { $so_instance['price'] = $so_instance['resources']['cpunumber'] * ($this->pricing['corePrice'] / 720) * $so_instance['usage']; $so_instance['price'] += $so_instance['resources']['memory'] / 1024 * ($this->pricing['ramPrice'] / 720) * $so_instance['usage']; $storageType = DiskType::find($so_instance['resources']['disk_type']); $diskAmount = $so_instance['resources']['disk_size'] / 1024 / 1024 / 1024; $so_instance['price'] += $diskAmount * ($this->pricing["{$storageType->tags}Price"] / 720) * $so_instance['usage']; } else { if ($priceMethod == 'elementPrice') { $so_instance['price'] = $this->pricing['CPU']["{$so_instance['resources']['cpunumber']}"] * $so_instance['usage']; $memoryIdentifier = $so_instance['resources']['memory'] / 1024 . "-GB"; $so_instance['price'] += $this->pricing['RAM']["{$memoryIdentifier}"] * $so_instance['usage']; $storageType = DiskType::find($so_instance['resources']['disk_type']); $diskAmount = $so_instance['resources']['disk_size'] / 1024 / 1024 / 1024; $so_instance['price'] += $this->pricing[$storageType->tags][$diskAmount] * $so_instance['usage']; } } $so_instance['tic'] = 30070; // !!REVISE!! } if ($grandfatherPricing == 'YES') { // Check to see if we have this instance on record $gfInstance = VmInstance::where('vm_instance_id', '=', $vmid)->where('cpu_number', '=', $so_instance['resources']['cpunumber'])->where('memory', '=', $so_instance['resources']['memory'])->where('disk_size', '=', $so_instance['resources']['disk_size'])->where('disk_type', '=', $so_instance['resources']['disk_type'])->first(); if ($gfInstance instanceof VmInstance) { $so_instance['price'] = $gfInstance->rate; } else { $newVm = new VmInstance(['vm_instance_id' => $vmid, 'cpu_number' => $so_instance['resources']['cpunumber'], 'memory' => $so_instance['resources']['memory'], 'disk_size' => $so_instance['resources']['disk_size'], 'disk_type' => $so_instance['resources']['disk_type'], 'rate' => $so_instance['price']]); $user->instances()->save($newVm); } } $usage['subtotal'] += $so_instance['price']; } } // Grab a collection of credit cards. We use billing address off the primary card for tax purposes. $cards = CreditCard::where('user_id', '=', $user->id)->orderBy('primary', 'desc')->get(); $paymentGw = app('\\App\\Repositories\\Contracts\\PaymentRepositoryInterface'); $primaryCard = $paymentGw->get($cards->first()->id, $user->id); // Compute Sales Tax $this->taxCloud->setDestAddress($primaryCard['address'], '', $primaryCard['city'], $primaryCard['state'], strpos($primaryCard['zipcode'], '-') === FALSE ? $primaryCard['zipcode'] : substr($primaryCard['zipcode'], 0, 5), ''); $usage['tax'] = $this->taxCloud->calculateSalesTax($user->id, $invoiceID, $usage); $usage['total'] = $usage['subtotal'] + $usage['tax']; // Record the uniqueID. $usage['invoiceNumber'] = $invoiceID; // Record invoice for the total amount. $transInvoice = new Transaction(['amount' => $usage['total'], 'note' => 'Invoice', 'invoice_number' => $invoiceID]); $user->transactions()->save($transInvoice); // Bill the user foreach ($cards as $card) { $response = $paymentGw->charge($card->payment_profile_id, $usage['total']); if ($response == false) { // Notify the user their card failed to charge. // Go on to the next one. continue; } // Record payment and set next bill date $transPayment = new Transaction(['amount' => -$usage['total'], 'note' => 'Payment']); $user->transactions()->save($transPayment); $user->bill_date = date('Y-m-d', strtotime("+1 month")); break; // If its successful, proceed. } // Serialize the cache and save it for the user it was generated for $invoice = new \App\Invoice(['invoice_data' => serialize($usage)]); $user->invoices()->save($invoice); // Reset the cache for the next user $this->repo->clearCache(); } }); }
public function fix() { DB::table('packages')->truncate(); $games = Game::all(); foreach ($games as $game) { if ($game->site == 'http://www.9apps.com') { $temp = str_replace('http://www.9apps.com/jump/down/', '', $game->download); $temp = str_replace('/app/', '', $temp); $temp = trim($temp); } else { $temp = str_replace('https://play.google.com/store/apps/details?id=', '', $game->link); $temp = str_replace('&hl=en&gl=us', '', $temp); $temp = trim($temp); } $count = Package::where('name', $temp)->count(); if ($count == 0) { Package::create([ 'game_id' => $game->id, 'name' => $temp ]); } } }