/** * * * * * @return Bill bill for given booker */ public function getBillForBooker($booker) { $channel = 'ecommerce'; if ($booker instanceof FlightBookerComponent) { $booker = $booker->getCurrent(); } if ($booker instanceof FlightBooker) { if ($booker->flightVoyage->webService == 'SABRE') { $channel = $booker->flightVoyage->valAirline->payableViaSabre ? 'gds_sabre' : 'ltr'; $channel = 'ltr'; } if ($booker->flightVoyage->webService == 'GALILEO') { $channel = $booker->flightVoyage->valAirline->payableViaGalileo ? 'gds_galileo' : 'ltr'; } } if ($booker->billId) { return Bill::model()->findByPk($booker->billId); } $bill = new Bill(); $bill->setChannel($channel); $bill->status = Bill::STATUS_NEW; $bill->amount = $booker->price; $bill->save(); $booker->billId = $bill->id; $booker->save(); return $bill; }
public function postSavebill() { //data : {'_token':token,'deal_id':deal_id,'bill_start_date':from_date,'bill_end_date':to_date,'agency_commission':agency_commission,'subtotal':subtotal_amount,'service_tax':service_tax_amount,'discount':0,'total_amount':bill_amount}, $bill = new Bill(); $bill->deal_id = Input::get('deal_id'); $bill->invoice_no = Input::get('invoice_no'); $bill->bill_start_date = Input::get('bill_start_date'); $bill->bill_end_date = Input::get('bill_end_date'); $bill->agency_commission = Input::get('agency_commission'); $bill->subtotal = Input::get('subtotal'); $bill->service_tax = Input::get('service_tax'); $bill->swach_bhart_cess = Input::get('swach_bhart_cess'); $bill->khrishi_kalyan_cess = Input::get('khrishi_kalyan_cess'); $bill->discount = Input::get('discount'); $bill->total_amount = Input::get('total_amount'); $bill->user_id = Session::get('user_id'); try { $bill->save(); } catch (Exception $e) { return 0; } return Response::json($bill); }
public static function checkout_response($registrationid, $PayerID, $token) { //we will be using these two variables to execute the "DoExpressCheckoutPayment" //Note: we haven't received any payment yet. $token = $_GET["token"]; $payer_id = $_GET["PayerID"]; $PayPalMode = Config::get('billing.paypalmode'); // sandbox or live $PayPalApiUsername = Config::get('billing.paypalapiusername'); //PayPal API Username $PayPalApiPassword = Config::get('billing.paypalapipassword'); //Paypal API password $PayPalApiSignature = Config::get('billing.paypalapisignature'); //Paypal API Signature $totalitemstring = Session::get('totalitemstring'); $GrandTotal = Session::get('grandtotal'); if ($totalitemstring == NULL || $GrandTotal == NULL) { return Redirect::to('/billing')->with('message', 'Your session has timed out, your card has not been charged, please try again.'); } $padata = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payer_id) . '&PAYMENTREQUEST_0_PAYMENTACTION=' . urlencode("SALE") . $totalitemstring . '&PAYMENTREQUEST_0_AMT=' . urlencode($GrandTotal) . '&PAYMENTREQUEST_0_CUSTOM=' . urlencode($registrationid); //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user. $paypal = new PayPal(); $httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode); // we can retrive transection details using either GetTransactionDetails or GetExpressCheckoutDetails // GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut $paypal = new PayPal(); if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { $orderid = urldecode($httpParsedResponseAr['PAYMENTINFO_0_TRANSACTIONID']); $status = urldecode($httpParsedResponseAr['PAYMENTINFO_0_PAYMENTSTATUS']); } else { $orderid = 'N/A'; } $padata = '&TOKEN=' . urlencode($token); $httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode); $totalamount = urldecode($httpParsedResponseAr['AMT']); $registrationid = Auth::user()->registration->registrationid; $status = str_replace('PaymentAction', '', urldecode($httpParsedResponseAr['CHECKOUTSTATUS'])); $order = new Bill(); $order->registrationid = $registrationid; $order->method = "PayPal"; $order->currency = 'USD'; $order->description = 'PayPal Order Number: ' . $orderid; $order->amount = $totalamount; $order->checkout_id = $orderid; $order->status = ucwords($status); $order->save(); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (Carbon::now()->toDateString() == Carbon::now()->startOfMonth()->toDateString()) { $users = User::where('type', 'ecole')->get(); foreach ($users as $user) { $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first(); if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 1)->where('school_year_id', $sc->id)->orderBy('id', 'desc')->where('nbrMois', 1)->first(); if ($getChild) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonth()->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = $getChild->reductionPrix; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 1; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 1) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix + Transport::where('user_id', $getChild->user_id)->first()->somme; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 1)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if ($getChild) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonth()->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = $getChild->reductionPrix; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 1; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 1) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix + Transport::where('user_id', $getChild->user_id)->first()->somme; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $facture->somme = $taman - $getChild->reductionPrix; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } }
# controllers/newbill.php # Logic Auth::kickout_non_admin('/'); if (Input::posted()) { $bill = new Bill(); $bill->fill(Input::all()); $bill->date = date('Y-m-d H:i:s', strtotime('now')); $bill->splitcost = round($bill->cost / 5, 2, PHP_ROUND_HALF_UP); if ($_FILES) { $files = Upload::to_folder('assets/uploads/'); if ($_FILES[0]['error_message'] == false) { $bill->image = $files[0]['filepath']; } } $bill->save(); $users = new Users_Collection(); $users->get(); foreach ($users->items as $user) { $account = new Account(); $account->user_id = $user->id; $account->bill_id = $bill->id; $account->save(); if ($user->is_admin) { $email = new Email(); $email->to = $user->email; $email->from = 'Bills'; $email->subject = 'New Bill'; $email->message = 'There\'s a new bill to pay on the <a href="bills.reuben.osborne.yoobee.net.nz">Meola Bills</a> website.<br>Created on: ' . $bill->date . '<br>Category: ' . $bill->category . '<br>Price: $' . $bill->splitcost . '<br>Notes: ' . $bill->notes; $email->html = true; $email->send();
function index_put() { $models = json_decode($this->put('models')); $data["results"] = array(); $data["count"] = 0; foreach ($models as $value) { $obj = new Bill(null, $this->entity); $obj->get_by_id($value->id); $obj->contact_id = $value->contact_id; $obj->biller_id = $value->biller_id; $obj->currency_id = $value->currency_id; $obj->type = $value->type; $obj->number = $value->number; $obj->amount = $value->amount; $obj->paid = $value->paid; $obj->paid_usd = $value->paid_usd; $obj->paid_khr = $value->paid_khr; $obj->changes = $value->changes; $obj->discount = $value->discount; $obj->fine = $value->fine; $obj->rate = $value->rate; $obj->memo = $value->memo; $obj->address = $value->address; $obj->status = $value->status; $obj->issued_date = date("Y-m-d", strtotime($value->issued_date)); $obj->due_date = date("Y-m-d", strtotime($value->due_date)); $obj->paid_date = date("Y-m-d", strtotime($value->paid_date)); $obj->delivered = isset($value->delivered) ? $value->delivered : 0; $obj->deleted = $value->deleted; if ($obj->save()) { //Results $data["results"][] = array("id" => $obj->id, "contact_id" => $obj->contact_id, "biller_id" => $obj->biller_id, "currency_id" => $obj->currency_id, "type" => $obj->type, "number" => $obj->number, "amount" => floatval($obj->amount), "paid" => floatval($obj->paid), "paid_usd" => floatval($obj->paid_usd), "paid_khr" => floatval($obj->paid_khr), "changes" => floatval($obj->changes), "discount" => floatval($obj->discount), "fine" => floatval($obj->fine), "rate" => floatval($obj->rate), "memo" => $obj->memo, "address" => $obj->address, "status" => $obj->status, "issued_date" => $obj->issued_date, "due_date" => $obj->due_date, "paid_date" => $obj->paid_date, "delivered" => $obj->delivered, "deleted" => $obj->deleted, "contact" => $obj->contact->get_raw()->result(), "locale" => $obj->currency->get()->locale); } } $data["count"] = count($data["results"]); $this->response($data, 200); }
/** * Execute the console command. * * @return mixed */ public function handle() { $users = User::where('type', 'ecole')->get(); foreach ($users as $user) { $sc = SchoolYear::where('user_id', $user->id)->where('current', 1)->first(); if ($sc->type == 'Semis' && Carbon::now()->between($sc->startch1, $sc->endch2)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 3)->orderBy('id', 'desc')->first(); if ($getChild) { // give us from the end of bill to 3 months ahead $fromStartToNbrMois = $getChild->end->addMonths($getChild->nbrMois); if ($fromStartToNbrMois <= $sc->endch2) { if (Carbon::now() >= $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths($getChild->nbrMois)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * $getChild->nbrMois; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * $getChild->nbrMois; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * $getChild->nbrMois; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } elseif ($fromStartToNbrMois > $sc->endch2) { $last_bill = Bill::where('child_id', $getChild->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if (!$last_bill && Carbon::now() > $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths(1)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = 1; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * 1; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * 1; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * 1; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } elseif ($sc->type == 'Trim' && Carbon::now()->between($sc->startch1, $sc->endch3)) { foreach ($user->children as $child) { foreach ($child->bills as $bill) { $getChild = Bill::where('child_id', $bill->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 3)->orderBy('id', 'desc')->first(); if ($getChild) { // give is from the end of bill to 3 months ahead $fromStartToNbrMois = $getChild->end->addMonths($getChild->nbrMois); if ($fromStartToNbrMois <= $sc->endch3) { if (Carbon::now() >= $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths($getChild->nbrMois)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = $getChild->nbrMois; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * $getChild->nbrMois; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * $getChild->nbrMois; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * $getChild->nbrMois; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } elseif ($fromStartToNbrMois >= $sc->endch3) { $last_bill = Bill::where('child_id', $getChild->child_id)->where('reduction', 0)->where('school_year_id', $sc->id)->where('nbrMois', 1)->orderBy('id', 'desc')->first(); if (!$last_bill && Carbon::now() > $getChild->end) { $facture = new Bill(); $facture->start = $getChild->end->toDateString(); $facture->end = $getChild->end->addMonths(1)->toDateString(); $facture->status = 0; $facture->user_id = $getChild->user_id; $facture->nbrMois = 1; $facture->reductionPrix = null; $facture->school_year_id = $getChild->school_year_id; $facture->reduction = 0; $enfant = Child::where('user_id', $getChild->user_id)->where('id', $getChild->child_id)->first(); $taman = ''; if ($getChild->reduction == 0) { if ($enfant->transport == 1) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $TotalOnMonths = $taman * 1; $total_transport = Transport::where('user_id', $getChild->user_id)->first()->somme * 1; $prix_finale = $TotalOnMonths + $total_transport; $facture->somme = $prix_finale; } elseif ($enfant->transport == 0) { foreach ($enfant->levels as $level) { $getPriceOfLevel = PriceBill::where('niveau', $level->id)->where('user_id', $getChild->user_id)->first(); $taman = $getPriceOfLevel->prix; } $prix_finale = $taman * 1; $facture->somme = $prix_finale; } } $facture->child_id = $getChild->child_id; $facture->f_id = $getChild->f_id; $facture->save(); break; } } } } } } } }
public function generateBills() { $orgs = Organization::all(["live = ?" => true]); foreach ($orgs as $org) { $imp_cost = 0; $click_cost = 0; $month_ini = new DateTime("first day of last month"); $month_end = new DateTime("last day of last month"); $start = $month_ini->format('Y-m-d'); $end = $month_end->format('Y-m-d'); $dateQuery = Utils::dateQuery(['start' => $start, 'end' => $end]); // find advertiser performances to get clicks and impressions $performances = \Performance::overall($dateQuery, User::all(['org_id' => $org->_id, 'type' => 'advertiser'], ['_id'])); $clicks = $performances['total_clicks']; if ($clicks > 1000) { $click_cost = 0.001 * $clicks * $org->meta["bill"]["tcc"]; } $impressions = $performances['total_impressions']; if ($impressions > 100000) { $imp_cost = 0.001 * 0.001 * $impressions * $org->meta["bill"]["mic"]; } $total = $click_cost + $imp_cost; $bill = new Bill(["org_id" => $org->id, "impressions" => $impressions, "clicks" => $clicks, "mic" => $org->meta["bill"]["mic"], "tcc" => $org->meta["bill"]["tcc"], "start" => $start, "end" => $end, "amount" => $total, "live" => false, "created" => Db::time('-1 day')]); if ($total > 1) { $bill->save(); $user = User::first(["org_id = ?" => $org->id, "type = ?" => "admin"]); Mail::send(['user' => $user, 'bill' => $bill, 'template' => 'adminBilling', 'subject' => 'Billing at vNative', 'click_cost' => $click_cost, 'imp_cost' => $imp_cost, 'org' => $org]); } } }
/** * Setup data * * @return null */ private static function _seed() { $database = self::_database(); User::all()->destroy(); Bill::all()->destroy(); Ticket::all()->destroy(); Tocket::all()->destroy(); Account::all()->destroy(); $user = new User(); $user->id = 1; $user->name = "Eustaquio Rangel"; $user->email = "*****@*****.**"; $user->code = "12345"; $user->user_level = 1; $user->save(); $user = new User(); $user->id = 2; $user->name = "Rangel, Eustaquio"; $user->email = "*****@*****.**"; $user->code = "54321"; $user->user_level = 2; $user->save(); for ($i = 1; $i <= 10; $i++) { $bill = new Bill(); $bill->id = $i; $bill->user_id = 1; $bill->description = "Bill #{$i}"; $bill->value = $i; $bill->save(); $ticket = new Ticket(); $ticket->user_id = 1; $ticket->description = "Just another ticket"; $ticket->save(); } $account = new Account(); $account->user_id = 1; $account->account_number = "12345"; $account->save(); $account = new Account(); $account->user_id = 2; $account->account_number = "54321"; $account->save(); }