function create() { if ($_POST) { unset($_POST['send']); unset($_POST['_wysihtml5_mode']); unset($_POST['files']); $_POST['estimate'] = 1; $_POST['estimate_status'] = "Open"; $estimate = Invoice::create($_POST); $new_estimate_reference = $_POST['reference'] + 1; $estimate_reference = Setting::first(); $estimate_reference->update_attributes(array('invoice_reference' => $new_estimate_reference)); if (!$estimate) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_estimate_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_estimate_success')); } redirect('estimates'); } else { $this->view_data['estimates'] = Invoice::all(); $this->view_data['next_reference'] = Invoice::last(); $this->view_data['projects'] = Project::all(); $this->view_data['companies'] = Company::find('all', array('conditions' => array('inactive=?', '0'))); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_estimate'); $this->view_data['form_action'] = 'estimates/create'; $this->content_view = 'estimates/_estimate'; } }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Invoice::create([]); } }
/** * Store a newly created invoice in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Invoice::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Invoice::create($data); return Redirect::route('invoices.index'); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { $status = Status::orderByRaw("RAND()")->first(); $user = User::orderByRaw("RAND()")->first(); Invoice::create(['due' => $faker->date(), 'status_id' => $status->id, 'amount' => $faker->randomFloat($nbMaxDecimals = 2), 'owner_id' => $user->id]); } }
/** * Store a newly created product in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Invoice::$rules); if ($validator->passes()) { $invoice = Invoice::create(Input::all()); return Response::json(array('success' => true, "invoice_id" => $invoice->id)); } else { return Response::json(array('success' => false, 'errors' => $validator->errors())); } }
/** * Store a newly created resource in storage. * POST /invoices * * @return Response */ public function store() { $input = Input::all(); $v = Validator::make(Input::All(), array('houseID' => 'required|max:50|', 'invoicedate' => 'required', 'duedate' => 'required')); if ($v->passes()) { Invoice::create($input); return Redirect::intended('invoice'); } return Redirect::back()->withInput()->withErrors($v)->with('message', 'There were validation errors'); }
public function run() { Eloquent::unguard(); DB::table('invoices')->truncate(); DB::table('invoice_items')->truncate(); $faker = Faker\Factory::create(); for ($i = 0; $i < 30; $i++) { $invoice = Invoice::create(array('user_id' => $faker->randomNumber(1, 20), 'due_date' => $faker->dateTimeThisYear, 'status' => $faker->randomElement(array('Draft', 'Unpaid', 'Paid')))); InvoiceItem::create(array('invoice_id' => $invoice->id, 'description' => $faker->sentence, 'unit_price' => $faker->randomNumber(1, 200), 'quantity' => $faker->randomNumber(1, 2))); } }
/** * * @param type $data * * $data = array( * 'header' => 'Header Text', * 'invoice_no' => 'Invoice number auto generate', * 'invoice_of' => 'Invoice type. e.g. quote, po', * 'ref_id' => 'id of the invoice_of', * 'ref_number' => 'number the invoice_of', * 'gst' => 'GST', * 'items' => array( * [] => array( * 'id' => 'db row id of the item', * 'number' => 'Unique Number of the item', * 'desc' => 'Description', * 'qty' => 'Quantity', * 'price' => 'Each Price', * 'total' => 'Total', // NULL in case of autocalculate * ), * ), * 'customer' => array( // null to empty * 'id' => 'Customer ID', * 'name' => 'Name', * 'address' => 'Address', * 'city' => 'City', * 'postal-code' => 'Postal Code', * 'province' => 'Province', * 'country' => 'Country', * 'email' => 'Email', * 'phone' => 'Phone', * ), * 'supplier' => array( // null to empty * 'id' => 'Customer ID', * 'name' => 'Name', * 'address' => 'Address', * 'city' => 'City', * 'postal-code' => 'Postal Code', * 'province' => 'Province', * 'country' => 'Country', * 'email' => 'Email', * 'phone' => 'Phone', * ), * 'total' => 'GST', * 'sales-person' => 'Sales Person', * 'ship-date' => 'Ship Date', * ); */ function createInvoice($data) { App::import('Model', 'InvoiceManager.Invoice'); $invoice = new Invoice(); $data_json = json_encode($data); $invoice_data['Invoice'] = array('invoice_no' => $data['invoice_no'], 'invoice_of' => $data['invoice_of'], 'ref_id' => $data['ref_id'], 'data_set' => $data_json, 'total' => $data['total'], 'invoice_status_id' => $data['invoice_status_id']); $invoice_data['InvoiceLog'] = array('invoice_status_id' => $data['invoice_status_id']); $invoice->create(); $flag = $invoice->save($invoice_data); return $flag; }
/** * Store a newly created quote in storage. * * @return Response */ public function store() { if (!Sentry::getUser()) { return Redirect::route('sessions.create'); } $validator = Validator::make($data = Input::all(), Invoice::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $data['event_date'] = strtotime($data['event_date']); Invoice::create($data); return Redirect::route('finances.index'); }
public static function amendInvoice($booking) { $total = Booking::getTotalBookingAmount($booking); $invoice = Invoice::where('booking_id', $booking->id)->first(); if ($invoice) { $invoice->count = ++$invoice->count; $invoice->amount = $total; $invoice->save(); return true; } else { $invoiceData = array('amount' => $total, 'booking_id' => $booking->id); Invoice::create($invoiceData); return false; } }
/** * Test the generate method */ public function testGenerate() { $invoice = $this->_getNewRecord(); $client = $invoice['Invoice']; unset($client['prefix']); $invoiceLine = $invoice['InvoiceLine']; $result = $this->Invoice->generate($client, $invoiceLine); $resultInvoice = $this->Invoice->read(); $this->assertTrue($result); $this->assertWithinMargin($resultInvoice['Invoice']['global_price'], 119.6, 0.0001); $this->Invoice->setInvoiceNumberGenerator('TestInvoiceNumberGenerator'); $this->Invoice->create($invoice); $this->expectError('PHPUnit_Framework_Error'); $result = $this->Invoice->generate($client, $invoiceLine); $resultInvoice = $this->Invoice->read(); $this->assertTrue($this->__isUuid($resultInvoice['Invoice']['id'])); }
public function run() { DB::table('DEMO_Invoice')->delete(); Invoice::create(array('client' => 'Client A', 'number' => 1, 'date' => date('2014-01-10'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client B', 'number' => 2, 'date' => date('2014-01-11'), 'country' => 'USA')); Invoice::create(array('client' => 'Client C', 'number' => 3, 'date' => date('2014-01-12'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client D', 'number' => 4, 'date' => date('2014-01-13'), 'country' => 'USA')); Invoice::create(array('client' => 'Client E', 'number' => 5, 'date' => date('2014-01-14'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client F', 'number' => 6, 'date' => date('2014-01-15'), 'country' => 'USA')); Invoice::create(array('client' => 'Client G', 'number' => 7, 'date' => date('2014-01-16'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client H', 'number' => 8, 'date' => date('2014-01-17'), 'country' => 'USA')); Invoice::create(array('client' => 'Client I', 'number' => 9, 'date' => date('2014-01-18'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client J', 'number' => 10, 'date' => date('2014-01-19'), 'country' => 'USA')); Invoice::create(array('client' => 'Client K', 'number' => 11, 'date' => date('2014-01-20'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client L', 'number' => 12, 'date' => date('2014-01-21'), 'country' => 'USA')); Invoice::create(array('client' => 'Client M', 'number' => 13, 'date' => date('2014-01-22'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client N', 'number' => 14, 'date' => date('2014-01-23'), 'country' => 'USA')); Invoice::create(array('client' => 'Client O', 'number' => 15, 'date' => date('2014-01-24'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client P', 'number' => 16, 'date' => date('2014-01-25'), 'country' => 'USA')); Invoice::create(array('client' => 'Client Q', 'number' => 17, 'date' => date('2014-01-26'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client R', 'number' => 18, 'date' => date('2014-01-27'), 'country' => 'USA')); Invoice::create(array('client' => 'Client S', 'number' => 19, 'date' => date('2014-01-29'), 'country' => 'Canada')); Invoice::create(array('client' => 'Client T', 'number' => 20, 'date' => date('2014-01-29'), 'country' => 'USA')); }
function planOrder($id = FALSE, $condition = FALSE, $plan_id = FALSE) { $this->load->helper('notification'); $this->view_data['submenu'] = array($this->lang->line('application_back') => 'cprojects', $this->lang->line('application_overview') => 'cprojects/view/' . $id, $this->lang->line('application_tasks') => 'cprojects/tasks/' . $id, $this->lang->line('application_media') => 'cprojects/media/' . $id); switch ($condition) { case 'create': $plan = ProjectHasItem::find($plan_id); $current_inventory = $plan->shipping_available_inventory; if ($_POST) { if (!isset($plan_id) || empty($plan_id)) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_item_empty')); redirect('cprojects/view/' . $id); } if (!$current_inventory) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_inventory_empty')); redirect('cprojects/view/' . $id); } $quantity = $_POST['amount']; $current_inventory_available = $current_inventory - $quantity; if (!$quantity) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_qty_empty')); redirect('cprojects/view/' . $id); } if ($current_inventory_available < 0) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_project_make_plan_qty_empty')); redirect('cprojects/view/' . $id); } unset($_POST['send']); unset($_POST['files']); unset($_POST['amount']); $_POST['shipping_lebel'] = ''; $config['upload_path'] = './files/media'; $config['encrypt_name'] = TRUE; $config['allowed_types'] = '*'; $this->load->library('upload', $config); if ($this->upload->do_upload()) { $data = array('upload_data' => $this->upload->data()); $_POST['shipping_lebel'] = $data['upload_data']['file_name']; } unset($_POST['userfile']); unset($_POST['dummy']); $_POST = array_map('htmlspecialchars', $_POST); $shipping_address = array('shipping_name' => $_POST['shipping_name'], 'shipping_company' => $_POST['shipping_company'], 'shipping_address' => $_POST['shipping_address'], 'shipping_city' => $_POST['shipping_city'], 'shipping_state' => $_POST['shipping_state'], 'shipping_zip' => $_POST['shipping_zip'], 'shipping_country' => $_POST['shipping_country'], 'shipping_phone' => $_POST['shipping_phone'], 'shipping_email' => $_POST['shipping_email'], 'shipping_website' => $_POST['shipping_website']); unset($_POST['shipping_name']); unset($_POST['shipping_company']); unset($_POST['shipping_address']); unset($_POST['shipping_city']); unset($_POST['shipping_state']); unset($_POST['shipping_zip']); unset($_POST['shipping_country']); unset($_POST['shipping_phone']); unset($_POST['shipping_email']); unset($_POST['shipping_website']); $core_settings = Setting::first(); $_POST['reference'] = $core_settings->invoice_reference; $_POST['project_id'] = $id; $_POST['company_id'] = $this->client->company->id; $_POST['status'] = 'Sent'; $_POST['issue_date'] = date('Y-m-d'); $_POST['due_date'] = date('Y-m-d', strtotime('+1 day')); $_POST['currency'] = $core_settings->currency; $_POST['terms'] = $core_settings->invoice_terms; $_POST['invoice_type'] = $this->invoice_shipment_type; $invoice = Invoice::create($_POST); $new_invoice_reference = $_POST['reference'] + 1; $invoice_id = $invoice->id; $this->projectlib->addInvoiceAddress($invoice_id, true, $shipping_address); $invoice_reference = Setting::first(); $invoice_reference->update_attributes(array('invoice_reference' => $new_invoice_reference)); $invoice_item_data = array('invoice_id' => $invoice_id, 'item_id' => $plan->item_id, 'project_item_id' => $plan->id, 'photo' => $plan->photo, 'photo_type' => $plan->photo_type, 'photo_original_name' => $plan->photo_original_name, 'name' => $plan->name, 'amount' => $quantity, 'type' => $plan->type, 'description' => $plan->description, 'sku' => $plan->sku, 'value' => $plan->cost, 'original_cost' => $plan->original_cost, 'shipping_item' => '1', 'shipping_method' => $plan->shipping_method, 'shipping_box_size_length' => $plan->shipping_box_size_length, 'shipping_box_size_width' => $plan->shipping_box_size_width, 'shipping_box_size_height' => $plan->shipping_box_size_height, 'shipping_box_size_weight' => $plan->shipping_box_size_weight, 'shipping_pcs_in_carton' => $plan->shipping_pcs_in_carton); $item_add = InvoiceHasItem::create($invoice_item_data); $plan->shipping_available_inventory = $current_inventory_available; if (!$current_inventory_available) { $plan->payment_status = 'invoiced'; } $plan->save(); $this->projectlib->updateInvoiceTotal($invoice); $this->projectlib->sendInvoice($invoice_id, false); if (!$invoice) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_invoice_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_invoice_success')); } redirect('cinvoices/view/' . $invoice_id); } else { $this->load->library('geolib'); $this->view_data['geolib'] = $this->geolib; $this->view_data['max_qty'] = $plan->shipping_available_inventory; $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_shipping_plan'); $this->view_data['form_action'] = 'cprojects/planOrder/' . $id . '/create/' . $plan_id; $this->content_view = 'projects/client_views/_create_plan'; } break; default: $this->view_data['project'] = Project::find($id); $this->content_view = 'cprojects/view/' . $id; break; } }
public function storeAllData() { $data = Session::pull('MyBookingData'); if (Session::has('rate_box_details') || Session::has('transport_cart_box') || Session::has('predefined_transport') || Session::has('excursion_cart_details')) { if ($booking = Booking::create($data)) { $ehi_users = User::getEhiUsers(); if (Auth::check()) { //DB::table('booking_user')->insert(array('booking_id' => $booking->id, 'user_id' => $user->id)); if (Session::has('client-list')) { $clients = Session::pull('client-list'); foreach ($clients as $client) { $client['booking_id'] = $booking->id; $client['gender'] === 'male' ? $client['gender'] = 1 : ($client['gender'] = 0); Client::create($client); } } $flight_data = []; $flight_data['booking_id'] = $booking->id; $flight_data['date'] = $data['date_arrival']; $flight_data['time'] = $data['arrival_time']; $flight_data['flight'] = $data['arrival_flight']; $flight_data['flight_type'] = 1; FlightDetail::create($flight_data); //departure flight data $flight_data['date'] = $data['date_departure']; $flight_data['time'] = $data['departure_time']; $flight_data['flight'] = $data['departure_flight']; $flight_data['flight_type'] = 0; FlightDetail::create($flight_data); } /** * transport - custom trips */ $a = 0; if (Session::has('transport_cart_box')) { $custom_trips = Session::pull('transport_cart_box'); $a++; $x = 1; foreach ($custom_trips as $custom_trip) { $custom_trip['from'] = date('Y-m-d H:i', strtotime($custom_trip['pick_up_date'] . ' ' . $custom_trip['pick_up_time_hour'] . ':' . $custom_trip['pick_up_time_minutes'])); $custom_trip['to'] = date('Y-m-d H:i', strtotime($custom_trip['drop_off_date'] . ' ' . $custom_trip['drop_off_time_hour'] . ':' . $custom_trip['drop_off_time_minutes'])); $custom_trip['reference_number'] = 'TR' . ($booking->reference_number * 1000 + $x++); $custom_trip['booking_id'] = $booking->id; $custom_trip['locations'] = $custom_trip['destination_1'] . ',' . $custom_trip['destination_2'] or '' . ',' . $custom_trip['destination_3']; $custom_trip['amount'] = rand(100, 200); CustomTrip::create($custom_trip); } } /** * predefined package bookings */ if (Session::has('predefined_transport')) { $a++; $predefined_packages = Session::pull('predefined_transport'); foreach ($predefined_packages as $predefined_package) { $package = []; $package['transport_package_id'] = $predefined_package['predefine_id']; $package['booking_id'] = $booking->id; $package['pick_up_date_time'] = $predefined_package['check_in_date']; $package['amount'] = TransportPackage::find($predefined_package['predefine_id'])->rate; PredefinedTrip::create($package); } } /** * Send Transportation Email to All EHI users */ $pdf = PDF::loadView('emails/transport', array('booking' => $booking)); $pdf->save('public/temp-files/transport' . $booking->id . '.pdf'); // if ($a > 0) { // Mail::send('emails/transport-mail', array( // 'booking' => Booking::find($booking->id) // ), function ($message) use ($booking, $ehi_users) { // $message->attach('public/temp-files/transport.pdf') // ->subject('New Transfer : ' . $booking->reference_number) // ->from('*****@*****.**', 'SriLankaHotels.Travel') // ->bcc('*****@*****.**'); // if (!empty($ehi_users)) // foreach ($ehi_users as $ehi_user) { // $message->to($ehi_user->email, $ehi_user->first_name); // } // }); // } /** * Excursions */ if (Session::has('excursion_cart_details')) { $excursions = Session::pull('excursion_cart_details'); $x = 1; foreach ($excursions as $excursion) { $excursionBooking = ExcursionRate::with(array('city', 'excursion', 'excursionTransportType'))->where('city_id', $excursion['city_id'])->where('excursion_transport_type_id', $excursion['excursion_transport_type'])->where('excursion_id', $excursion['excursion'])->first(); $excursionBookingData = array('booking_id' => $booking->id, 'city_id' => $excursionBooking->city_id, 'excursion_transport_type_id' => $excursionBooking->excursion_transport_type_id, 'excursion_id' => $excursionBooking->excursion_id, 'unit_price' => $excursionBooking->rate, 'pax' => $excursion['excursion_pax'], 'date' => $excursion['excursion_date'], 'reference_number' => 'EX' . ($booking->reference_number * 1000 + $x++)); ExcursionBooking::create($excursionBookingData); } $pdf = PDF::loadView('emails/excursion', array('booking' => $booking)); $pdf->save('public/temp-files/excursions.pdf'); // Mail::send('emails/excursion-mail', array( // 'booking' => $booking // ), function ($message) use ($booking, $ehi_users) { // $message->attach('public/temp-files/excursions.pdf') // ->subject('New Excursions : ' . $booking->reference_number) // ->from('*****@*****.**', 'SriLankaHotels.Travel'); // // $message->to('*****@*****.**', 'Excursions'); // $message->bcc('*****@*****.**', 'Admin'); // if (!empty($ehi_users)) // foreach ($ehi_users as $ehi_user) { // $message->to($ehi_user->email, $ehi_user->first_name); // } // }); } /** * hotel bookings */ if (Session::has('rate_box_details')) { $bookings = Session::pull('rate_box_details'); $vouchers = Voucher::arrangeHotelBookingsVoucherwise($bookings, $booking->id); foreach ($vouchers as $voucher) { $created_voucher = Voucher::create($voucher); for ($c = 0; $c < count($voucher) - 6; $c++) { $voucher[$c]['voucher_id'] = $created_voucher->id; $RoomBooking = RoomBooking::create($voucher[$c]); } // voucher $pdf = PDF::loadView('emails/voucher', array('voucher' => $created_voucher)); $pdf->save('public/temp-files/voucher' . $created_voucher->id . '.pdf'); // $hotel_users = DB::table('users')->leftJoin('hotel_user', 'users.id', '=', 'hotel_user.user_id') // ->where('hotel_user.hotel_id', $created_voucher->hotel_id) // ->get(); // // Mail::send('emails/voucher-mail', array( // 'voucher' => Voucher::find($created_voucher->id) // ), function ($message) use ($booking, $hotel_users,$created_voucher) { // $message->attach('public/temp-files/voucher'.$created_voucher->id.'.pdf') // ->subject('Booking Voucher : ' . $booking->reference_number) // ->from('*****@*****.**', 'SriLankaHotels.Travel') // ->bcc('*****@*****.**', 'SriLankaHotels.Travel'); // if (!empty($hotel_users)) // foreach ($hotel_users as $hotel_user) { // $message->to($hotel_user->email, $hotel_user->first_name); // } // }); } } //Booking details // $pdf = PDF::loadView('emails/booking', array('booking' => $booking)); // $pdf->save('public/temp-files/booking'.$booking->id.'.pdf'); // $ehi_users = User::getEhiUsers(); // $emails = array('*****@*****.**', '*****@*****.**', '*****@*****.**'); // // Mail::send('emails/booking-mail', array( // 'booking' => Booking::getBookingData($booking->id) // ), function ($message) use ($booking, $emails, $ehi_users) { // $message->attach('public/temp-files/booking'.$booking->id.'.pdf') // ->subject('New Booking: ' . $booking->reference_number) // ->from('*****@*****.**', 'SriLankaHotels.Travel') // ->bcc('*****@*****.**', 'Admin'); // foreach ($emails as $emailaddress) { // $message->to($emailaddress, 'Admin'); // } // // if (!empty($ehi_users)) { // foreach ($ehi_users as $ehi_user) { // $message->to($ehi_user->email, $ehi_user->first_name); // } // } // }); Invoice::create(array('booking_id' => $booking->id, 'amount' => Booking::getTotalBookingAmount($booking), 'count' => 1)); //Invoice $pdf = PDF::loadView('emails/invoice', array('booking' => $booking)); $pdf->save('public/temp-files/invoice' . $booking->id . '.pdf'); $pdf = PDF::loadView('emails/service-voucher', array('booking' => $booking)); $pdf->save('public/temp-files/service-voucher.pdf'); // if ($user = $booking->user) { // Mail::send('emails/invoice-mail', array( // 'booking' => Booking::getBookingData($booking->id) // ), function ($message) use ($user, $booking, $emails) { // $message->subject('Booking Invoice : ' . $booking->reference_number) // ->attach('public/temp-files/invoice'.$booking->id.'.pdf'); // $message->to($user->email, $user->first_name . ' ' . $user->last_name); // $message->to('*****@*****.**', 'Accounts'); // if (!empty($ehi_users)) { // foreach ($ehi_users as $ehi_user) { // $message->to($ehi_user->email, $ehi_user->first_name); // } // } // // }); // // } else { // // Mail::send('emails/invoice-mail', array( // 'booking' => Booking::getBookingData($booking->id) // ), function ($message) use ($booking, $emails) { // $message->to($booking->email, $booking->name) // ->subject('Booking Created : ' . $booking->reference_number) // ->attach('public/temp-files/invoice'.$booking->id.'.pdf'); // $message->to('*****@*****.**', 'Accounts'); // if (!empty($ehi_users)) { // foreach ($ehi_users as $ehi_user) { // $message->to($ehi_user->email, $ehi_user->first_name); // } // } // }); // } if (!Auth::check()) { Session::flash('global', 'Emails have been sent to the Respective parties'); return View::make('pages.message'); } } return $booking; } else { return Redirect::back(); } return Redirect::route('bookings.index'); }
public function import($options = array()) { $db = JFactory::getDBO(); $stdfields = array('id', 'name', 'username', 'email', 'password', 'plan_id', 'invoice_number', 'expiration'); foreach ($this->rows as $k => $row) { // Skip first line, if desired if ($k === 0 && !empty($options['skip_first'])) { continue; } $userid = null; $user = $this->convertRow($row); if (empty($user['username']) && empty($user['id'])) { continue; } if (!empty($user['id'])) { $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `id` = \'' . $user['id'] . '\''; $db->setQuery($query); $userid = $db->loadResult(); } if (empty($userid)) { $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $user['username'] . '\''; $db->setQuery($query); $userid = $db->loadResult(); } if (!$userid) { // We cannot find any user by this id or name, create one if (!empty($user['email']) && !empty($user['username'])) { if (empty($user['password'])) { $user['password'] = AECToolbox::randomstring(8, true); } if (empty($user['name'])) { $user['name'] = $user['username']; } if (!empty($user['password'])) { $user['password2'] = $user['password']; } $fields = $user; $excludefields = array('plan_id', 'invoice_number', 'expiration'); foreach ($excludefields as $field) { if (isset($fields[$field])) { unset($fields[$field]); } } $userid = $this->createUser($fields); } else { continue; } } if (empty($userid)) { $this->errors++; } $metaUser = new metaUser($userid); $custom_params = array(); foreach ($user as $i => $v) { if (!in_array($i, $stdfields)) { $custom_params[$i] = $v; } } if (!empty($custom_params)) { $metaUser->meta->addCustomParams($custom_params); $metaUser->meta->storeload(); } if (!empty($user['plan_id'])) { $pid = $user['plan_id']; } else { $pid = $this->options['assign_plan']; } $subscr_action = false; if (!empty($pid)) { $plan = new SubscriptionPlan(); $plan->load($pid); $metaUser->establishFocus($plan, 'none', true); $metaUser->focusSubscription->applyUsage($pid, 'none', 1); $subscr_action = true; } if (!empty($user['expiration']) && !empty($metaUser->focusSubscription->id)) { $metaUser->focusSubscription->expiration = date('Y-m-d H:i:s', strtotime($user['expiration'])); if ($metaUser->focusSubscription->status == 'Trial') { $metaUser->focusSubscription->status = 'Trial'; } else { $metaUser->focusSubscription->status = 'Active'; } $metaUser->focusSubscription->lifetime = 0; $metaUser->focusSubscription->storeload(); $subscr_action = true; } if (!empty($user['invoice_number']) && !empty($pid)) { // Create Invoice $invoice = new Invoice(); $invoice->create($userid, $pid, 'none', $user['invoice_number']); if ($subscr_action) { $invoice->subscr_id = $metaUser->focusSubscription->id; } $invoice->setTransactionDate(); } } }
print_r($_array); echo "</pre><br><br>"; } $referral = 4; ?> <p style="font-weight: bold;">Show all invoices... </p><p><?php print_array(Invoice::get_all()); ?> </p><p style="font-weight: bold;">Add an invoice... </p><p><?php $data = array(); $data['issued_on'] = today(); $data['type'] = 'R'; $data['employer'] = 'acme123'; $data['payable_by'] = sql_date_add(today(), 30, 'day'); $id = 0; if ($id = Invoice::create($data)) { echo "This invoice has an ID of <b>" . $id . "</b><br><br>"; print_array(Invoice::get($id)); } else { echo "failed"; exit; } ?> </p><p style="font-weight: bold;">Add an item... </p><p><?php if (Invoice::add_item($id, 270.98, 23, 'some references')) { print_array(Invoice::get_items_of($id)); } else { echo "failed"; exit; } ?>
function index() { $this->theme_view = 'blank'; $this->load->helper(array('dompdf', 'file')); $timestamp = time(); $core_settings = Setting::first(); $date = date("Y-m-d"); if ($core_settings->cronjob == "1" && time() > $core_settings->last_cronjob + 300) { $core_settings->last_cronjob = time(); $core_settings->save(); $this->load->database(); //Check Subscriptions $sql = 'SELECT * FROM subscriptions WHERE status != "Inactive" AND end_date > "' . $date . '" AND "' . $date . '" >= next_payment ORDER BY next_payment'; $res = $this->db->query($sql); $res = $res->result(); foreach ($res as $key2 => $value2) { $eventline = 'New invoice created for subscription <a href="' . base_url() . 'subscriptions/view/' . $value2->id . '">#' . $value2->reference . '</a>'; $subscription = Subscription::find($value2->id); $invoice = Invoice::last(); $invoice_reference = Setting::first(); if ($subscription) { $_POST['subscription_id'] = $subscription->id; $_POST['company_id'] = $subscription->company_id; if ($subscription->subscribed != 0) { $_POST['status'] = "Paid"; } else { $_POST['status'] = "Open"; } $_POST['currency'] = $subscription->currency; $_POST['issue_date'] = $subscription->next_payment; $_POST['due_date'] = date('Y-m-d', strtotime('+3 day', strtotime($subscription->next_payment))); $_POST['currency'] = $subscription->currency; $_POST['terms'] = $subscription->terms; $_POST['discount'] = $subscription->discount; $_POST['reference'] = $invoice_reference->invoice_reference; $invoice = Invoice::create($_POST); $invoiceid = Invoice::last(); $items = SubscriptionHasItem::find('all', array('conditions' => array('subscription_id=?', $value2->id))); foreach ($items as $value) { $itemvalues = array('invoice_id' => $invoiceid->id, 'item_id' => $value->item_id, 'amount' => $value->amount, 'description' => $value->description, 'value' => $value->value, 'name' => $value->name, 'type' => $value->type); InvoiceHasItem::create($itemvalues); } $invoice_reference->update_attributes(array('invoice_reference' => $invoice_reference->invoice_reference + 1)); if ($invoice) { $subscription->next_payment = date('Y-m-d', strtotime($subscription->frequency, strtotime($subscription->next_payment))); $subscription->save(); //Send Invoice to Client via email $this->load->library('parser'); $data["invoice"] = Invoice::find($invoiceid->id); $data['items'] = InvoiceHasItem::find('all', array('conditions' => array('invoice_id=?', $invoiceid->id))); $data["core_settings"] = Setting::first(); // Generate PDF $html = $this->load->view($data["core_settings"]->template . '/' . 'invoices/preview', $data, true); $filename = $this->lang->line('application_invoice') . '_' . $data["invoice"]->reference; pdf_create($html, $filename, FALSE); //email $this->email->from($data["core_settings"]->email, $data["core_settings"]->company); $this->email->to($data["invoice"]->company->client->email); $this->email->subject($data["core_settings"]->invoice_mail_subject); $this->email->attach("files/temp/" . $filename . ".pdf"); $due_date = date($data["core_settings"]->date_format, human_to_unix($data["invoice"]->due_date . ' 00:00:00')); //Set parse values $parse_data = array('client_contact' => $data["invoice"]->company->client->firstname . ' ' . $data["invoice"]->company->client->lastname, 'due_date' => $due_date, 'invoice_id' => $data["invoice"]->reference, 'client_link' => $data["core_settings"]->domain, 'company' => $data["core_settings"]->company, 'logo' => '<img src="' . base_url() . '' . $data["core_settings"]->logo . '" alt="' . $data["core_settings"]->company . '"/>', 'invoice_logo' => '<img src="' . base_url() . '' . $data["core_settings"]->invoice_logo . '" alt="' . $data["core_settings"]->company . '"/>'); $email_invoice = read_file('./application/views/' . $data["core_settings"]->template . '/templates/email_invoice.html'); $message = $this->parser->parse_string($email_invoice, $parse_data); $this->email->message($message); if ($this->email->send()) { $data["invoice"]->update_attributes(array('status' => 'Sent', 'sent_date' => date("Y-m-d"))); } log_message('error', $eventline); unlink("files/temp/" . $filename . ".pdf"); } } } //Check Subscriptions end // Auto Backup every 7 days if ($core_settings->autobackup == "1" && time() > $core_settings->last_autobackup + 7 * 24 * 60 * 60) { $this->load->dbutil(); $prefs = array('format' => 'zip', 'filename' => 'Database-auto-full-backup_' . date('Y-m-d_H-i')); $backup =& $this->dbutil->backup($prefs); if (!write_file('./files/backup/Database-auto-full-backup_' . date('Y-m-d_H-i') . '.zip', $backup)) { log_message('error', "Error while creating auto database backup!"); } else { $core_settings->last_autobackup = time(); $core_settings->save(); log_message('error', "Auto backup has been created."); } } echo "Success"; } }
exit; } if (!$is_free_replacement) { $item_added = Invoice::addItem($invoice, $discount, $referral->getId(), 'Discount'); if (!$item_added) { echo "ko"; exit; } $item_added = Invoice::addItem($invoice, $extra_charges, $referral->getId(), 'Extra charges'); if (!$item_added) { echo "ko"; exit; } $data_copy = $data; $data_copy['is_copy'] = '1'; $invoice_copy = Invoice::create($data_copy); if (!$invoice_copy) { echo 'ko'; exit; } $item_copy_added = Invoice::addItem($invoice_copy, $subtotal, $referral->getId(), 'Job referral fee'); $item_copy_added = Invoice::addItem($invoice_copy, $discount, $referral->getId(), 'Discount'); $item_copy_added = Invoice::addItem($invoice_copy, $extra_charges, $referral->getId(), 'Extra charges'); // generate and send invoice $filename = generate_random_string_of(8) . '.' . generate_random_string_of(8); $filename_copy = generate_random_string_of(8) . '.' . generate_random_string_of(8); $branch = $employer->getAssociatedBranch(); $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com'; $currency = $branch[0]['currency']; $items = Invoice::getItems($invoice); $items_copy = Invoice::getItems($invoice_copy);
<?php require '../include/init.inc'; require '../include/util.inc'; $amount = 0; $uid = auth('uid'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $paymethod = $_POST['paymethod']; $amount = $_POST['amount']; if (empty($amount) || is_nan($amount)) { alert(s("请输入有效充值金额", 'please input valid amount'), 'error'); } else { // create order and redirect to payment gateway $order = Invoice::create(array('uid' => $uid, 'total_fee' => $amount, 'trade_ip' => get_client_ip())); alipay($order); } } function alipay($order) { require_once "../lib/alipay_trade_create_by_buyer/lib/alipay_submit.class.php"; global $alipay_config; $payment_type = "1"; $notify_url = PAY_CALLBACK_DOMAIN . "/alipay_trade_create_by_buyer/notify_url.php"; $return_url = PAY_CALLBACK_DOMAIN . "/alipay_trade_create_by_buyer/return_url.php"; $seller_email = "*****@*****.**"; //商户订单号 $out_trade_no = $order->id; //商户网站订单系统中唯一订单号,必填 //订单名称 $subject = PAY_SUBJECT; //必填
require 'core/init.php'; //Create Invoice Object $invoice = new Invoice(); if (isset($_POST['do_create'])) { //Create validator object $validate = new Validator(); //create data array $data = array(); $data['invoice_number'] = $_POST['invoice_number']; $data['user_id'] = getUser()['user_id']; $data['create_date'] = $_POST['create_date']; $data['due'] = $_POST['due']; $data['payee'] = $_POST['payee']; $data['amount'] = $_POST['amount']; $data['description'] = $_POST['description']; //Required Fields $field_array = array('invoice_number', 'create_date', 'due', 'payee', 'amount'); if ($validate->isRequired($field_array)) { if ($invoice->create($data)) { redirect('index.php', 'Your invoice has been saved', 'Success'); } else { redirect('invoice.php?id=' . $invoice_id, 'Something has gone wrong', 'error'); } } else { redirect('create.php', 'Please fill in the required fields', 'error'); } } //Get Template & Assign Vars $template = new Template('templates/create.php'); //Display template echo $template;
function create_invoice($id = FALSE) { $subscription = Subscription::find($id); $invoice = Invoice::last(); $invoice_reference = Setting::first(); if ($subscription) { $_POST['subscription_id'] = $subscription->id; $_POST['company_id'] = $subscription->company_id; if ($subscription->subscribed != 0) { $_POST['status'] = "Paid"; } else { $_POST['status'] = "Open"; } $_POST['currency'] = $subscription->currency; $_POST['issue_date'] = $subscription->next_payment; $_POST['due_date'] = date('Y-m-d', strtotime('+14 day', strtotime($subscription->next_payment))); $_POST['currency'] = $subscription->currency; $_POST['terms'] = $subscription->terms; $_POST['discount'] = $subscription->discount; $_POST['tax'] = $subscription->tax; $_POST['second_tax'] = $subscription->second_tax; $_POST['reference'] = $invoice_reference->invoice_reference; $invoice = Invoice::create($_POST); $invoiceid = Invoice::last(); $items = SubscriptionHasItem::find('all', array('conditions' => array('subscription_id=?', $id))); foreach ($items as $value) { $itemvalues = array('invoice_id' => $invoiceid->id, 'item_id' => $value->item_id, 'amount' => $value->amount, 'description' => $value->description, 'value' => $value->value, 'name' => $value->name, 'type' => $value->type); InvoiceHasItem::create($itemvalues); } $invoice_reference->update_attributes(array('invoice_reference' => $invoice_reference->invoice_reference + 1)); if (!$invoice) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_invoice_error')); } else { $subscription->next_payment = date('Y-m-d', strtotime($subscription->frequency, strtotime($subscription->next_payment))); $subscription->save(); $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_invoice_success')); } redirect('subscriptions/view/' . $id); } }
/** * This void private method adds related invoices of this order to the database using Invoice class. * Invoice example: * number price date */ private function add_invoices() { foreach ($this->installments_array as $installment) { $install_array = explode(" ", $installment); if ($install_array[1] == 0) { continue; } $constructor_array = array("owner_id" => $this->owner_id, "order_id" => $this->id, "status" => 0, "price" => intval($install_array[1]), "discount" => floatval($this->discount), "create_date" => $install_array[2], "expire_date" => date("Y/m/d", strtotime("+3 days", strtotime($install_array[2]))), "installment_number" => intval($install_array[0])); $invoice = new Invoice($constructor_array); $invoice->create(); } }
public function run() { Invoice::create([]); }
function send_invoice(&$_employer, $_paid_postings, $_subscription_period) { if (!is_a($_employer, 'Employer')) { return false; } $today = date('Y-m-d'); $branch = $_employer->getAssociatedBranch(); $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com'; $branch[0]['address'] = str_replace(array("\r\n", "\r"), "\n", $branch[0]['address']); $branch['address_lines'] = explode("\n", $branch[0]['address']); $currency = Currency::getSymbolFromCountryCode($branch[0]['country']); if ($_paid_postings > 0) { // 0. get the job postings pricing and currency $posting_rates = $GLOBALS['postings_rates']; $price = $posting_rates[$currency]; // 1. generate invoice in the system $data = array(); $data['issued_on'] = $today; $data['type'] = 'P'; $data['employer'] = $_POST['id']; $data['payable_by'] = sql_date_add($today, $_employer->getPaymentTermsInDays(), 'day'); $invoice = Invoice::create($data); if ($invoice === false) { echo 'ko'; exit; } $amount = $price * $_paid_postings; $desc = $_paid_postings . ' Job Posting(s) @ ' . $currency . ' $' . $price; $item_added = Invoice::addItem($invoice, $amount, '1', $desc); $items = array(); $items[0]['itemdesc'] = $desc; $items[0]['amount'] = number_format($amount, '2', '.', ', '); // 2. generate the invoice as PDF file $pdf = new PaidPostingsInvoice(); $pdf->AliasNbPages(); $pdf->SetAuthor('Yellow Elevator. This invoice was automatically generated. Signature is not required.'); $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Invoice ' . pad($invoice, 11, '0')); $pdf->SetCurrency($currency); $pdf->SetBranch($branch); $pdf->AddPage(); $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(255, 255, 255); $pdf->SetFillColor(54, 54, 54); $pdf->Cell(60, 5, "Invoice Number", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Issuance Date", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Payable By", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Amount Payable (" . $currency . ")", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, pad($invoice, 11, '0'), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['issued_on']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['payable_by']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, number_format($amount, '2', '.', ', '), 1, 0, 'C'); $pdf->Ln(6); $pdf->SetTextColor(255, 255, 255); $pdf->Cell(60, 5, "User ID", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Employer Name", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, $_employer->getId(), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, $_employer->getName(), 1, 0, 'C'); $pdf->Ln(10); $table_header = array("No.", "Item", "Amount (" . $currency . ")"); $pdf->FancyTable($table_header, $items, number_format($amount, '2', '.', ', ')); $pdf->Ln(13); $pdf->SetFont('', 'I'); $pdf->Cell(0, 0, "This invoice was automatically generated. Signature is not required.", 0, 0, 'C'); $pdf->Ln(6); $pdf->Cell(0, 5, "Payment Notice", 'LTR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- Payment shall be made payable to " . $branch[0]['branch'] . ".", 'LR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- To facilitate the processing of the payment, please write down the invoice number(s) on your cheque(s)/payment slip(s)", 'LBR', 0, 'C'); $pdf->Ln(10); $pdf->Cell(0, 0, "E. & O. E.", 0, 0, 'C'); $pdf->Close(); $pdf->Output($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf', 'F'); // 3. sends it as an email $attachment = chunk_split(base64_encode(file_get_contents($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'))); $subject = "Subscription Invoice " . pad($invoice, 11, '0'); $headers = 'From: YellowElevator.com <*****@*****.**>' . "\n"; $headers .= 'Bcc: ' . $sales . "\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="yel_mail_sep_' . $invoice . '";' . "\n\n"; $body = '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: multipart/alternative; boundary="yel_mail_sep_alt_' . $invoice . '"' . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "\n"; $body .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $body .= 'Content-Transfer-Encoding: 7bit"' . "\n"; $mail_lines = file('../private/mail/employer_posting_invoice.txt'); $message = ''; foreach ($mail_lines as $line) { $message .= $line; } $message = str_replace('%employer%', $_employer->getName(), $message); $message = str_replace('%postings%', $_POST['paid_postings'], $message); $message = str_replace('%price%', $price, $message); $message = str_replace('%currency%', $currency, $message); $message = str_replace('%amount%', number_format($amount, 2, '.', ', '), $message); $issued_date = explode('-', $data['issued_on']); $issued_timestamp = $issued_date[0] . $issued_date[1] . $issued_date[2]; $message = str_replace('%purchased_on%', date('j M', $issued_timestamp) . ', ' . $issued_date[0], $message); $body .= $message . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "--\n\n"; $body .= '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: application/pdf; name="yel_invoice_' . pad($invoice, 11, '0') . '.pdf"' . "\n"; $body .= 'Content-Transfer-Encoding: base64' . "\n"; $body .= 'Content-Disposition: attachment' . "\n"; $body .= $attachment . "\n"; $body .= '--yel_mail_sep_' . $invoice . "--\n\n"; mail($_employer->getEmailAddress(), $subject, $body, $headers); // $handle = fopen('/tmp/email_to_'. $_employer->getEmailAddress(). '.txt', 'w'); // fwrite($handle, 'Subject: '. $subject. "\n\n"); // fwrite($handle, $body); // fclose($handle); unlink($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'); } if ($_subscription_period > 0) { $single_subscription_prices = array('MYR' => 1000, 'SGD' => 1000); // 0. get the job postings pricing and currency $subscriptions_rates = $GLOBALS['subscriptions_rates']; $amount = $subscriptions_rates[$currency][$_subscription_period]; if ($_subscription_period == 1) { $amount = $single_subscription_prices[$currency]; } $admin_fee = 0.05 * $amount; $total = $admin_fee + $amount; // 1. generate invoice in the system $data = array(); $data['issued_on'] = $today; $data['type'] = 'J'; $data['employer'] = $_employer->getId(); $data['payable_by'] = sql_date_add($today, $_employer->getPaymentTermsInDays(), 'day'); $invoice = Invoice::create($data); if ($invoice === false) { echo 'ko'; exit; } $desc = $_subscription_period . ' month(s) of subscription'; $item_added = Invoice::addItem($invoice, $total, '1', $desc); $items = array(); $items[0]['itemdesc'] = $desc; $items[0]['amount'] = number_format($amount, '2', '.', ', '); $items[1]['itemdesc'] = 'Administration Fee'; $items[1]['amount'] = number_format($admin_fee, '2', '.', ', '); // 2. generate the PDF version to be attached to sales.xx and the employer $pdf = new SubscriptionInvoice(); $pdf->AliasNbPages(); $pdf->SetAuthor('Yellow Elevator. This invoice was automatically generated. Signature is not required.'); $pdf->SetTitle($GLOBALS['COMPANYNAME'] . ' - Invoice ' . pad($invoice, 11, '0')); $pdf->SetCurrency($currency); $pdf->SetBranch($branch); $pdf->AddPage(); $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(255, 255, 255); $pdf->SetFillColor(54, 54, 54); $pdf->Cell(60, 5, "Invoice Number", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Issuance Date", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(33, 5, "Payable By", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Amount Payable (" . $currency . ")", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, pad($invoice, 11, '0'), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['issued_on']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(33, 5, sql_date_format($data['payable_by']), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, number_format($total, '2', '.', ', '), 1, 0, 'C'); $pdf->Ln(6); $pdf->SetTextColor(255, 255, 255); $pdf->Cell(60, 5, "User ID", 1, 0, 'C', 1); $pdf->Cell(1); $pdf->Cell(0, 5, "Employer Name", 1, 0, 'C', 1); $pdf->Ln(6); $pdf->SetTextColor(0, 0, 0); $pdf->Cell(60, 5, $_employer->getId(), 1, 0, 'C'); $pdf->Cell(1); $pdf->Cell(0, 5, $_employer->getName(), 1, 0, 'C'); $pdf->Ln(10); $table_header = array("No.", "Item", "Amount (" . $currency . ")"); $pdf->FancyTable($table_header, $items, number_format($total, '2', '.', ', ')); $pdf->Ln(13); $pdf->SetFont('', 'I'); $pdf->Cell(0, 0, "This invoice was automatically generated. Signature is not required.", 0, 0, 'C'); $pdf->Ln(6); $pdf->Cell(0, 5, "Payment Notice", 'LTR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- Payment shall be made payable to " . $branch[0]['branch'] . ".", 'LR', 0, 'C'); $pdf->Ln(); $pdf->Cell(0, 5, "- To facilitate the processing of the payment, please write down the invoice number(s) on your cheque(s)/payment slip(s)", 'LBR', 0, 'C'); $pdf->Ln(10); $pdf->Cell(0, 0, "E. & O. E.", 0, 0, 'C'); $pdf->Close(); $pdf->Output($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf', 'F'); // 3. attach it to email $attachment = chunk_split(base64_encode(file_get_contents($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'))); $subject = "Subscription Invoice " . pad($invoice, 11, '0'); $headers = 'From: YellowElevator.com <*****@*****.**>' . "\n"; $headers .= 'Bcc: ' . $sales . "\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: multipart/mixed; boundary="yel_mail_sep_' . $invoice . '";' . "\n\n"; $body = '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: multipart/alternative; boundary="yel_mail_sep_alt_' . $invoice . '"' . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "\n"; $body .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n"; $body .= 'Content-Transfer-Encoding: 7bit"' . "\n"; $mail_lines = file('../private/mail/employer_subscription_invoice.txt'); $message = ''; foreach ($mail_lines as $line) { $message .= $line; } $message = str_replace('%employer%', $_employer->getName(), $message); $message = str_replace('%period%', $_subscription_period, $message); $message = str_replace('%currency%', $currency, $message); $message = str_replace('%amount%', number_format($total, 2, '.', ', '), $message); $issued_date = explode('-', $data['issued_on']); $issued_timestamp = $issued_date[0] . $issued_date[1] . $issued_date[2]; $message = str_replace('%purchased_on%', date('j M', $issued_timestamp) . ', ' . $issued_date[0], $message); $body .= $message . "\n"; $body .= '--yel_mail_sep_alt_' . $invoice . "--\n\n"; $body .= '--yel_mail_sep_' . $invoice . "\n"; $body .= 'Content-Type: application/pdf; name="yel_invoice_' . pad($invoice, 11, '0') . '.pdf"' . "\n"; $body .= 'Content-Transfer-Encoding: base64' . "\n"; $body .= 'Content-Disposition: attachment' . "\n"; $body .= $attachment . "\n"; $body .= '--yel_mail_sep_' . $invoice . "--\n\n"; mail($_employer->getEmailAddress(), $subject, $body, $headers); /*$handle = fopen('/tmp/email_to_'. $_employer->getEmailAddress(). '.txt', 'w'); fwrite($handle, 'Subject: '. $subject. "\n\n"); fwrite($handle, $body); fclose($handle);*/ unlink($GLOBALS['data_path'] . '/subscription_invoices/' . $invoice . '.pdf'); } return true; }
$discount = $extra_charges = 0.0; $subtotal = $amount_difference; } } // 2.3 Generate the invoice $data = array(); $data['issued_on'] = today(); $data['type'] = 'R'; $data['employer'] = $_POST['employer']; $data['payable_by'] = sql_date_add($data['issued_on'], $payment_terms_days, 'day'); if ($is_free_replacement) { $data['paid_on'] = $data['issued_on']; $data['paid_through'] = 'CSH'; $data['paid_id'] = 'FREE_REPLACEMENT'; } $invoice = Invoice::create($data); if (!$invoice) { echo "ko"; exit; } $referral_desc = 'Reference fee for [' . $job[0]['job'] . '] ' . $job[0]['title']; if ($is_free_replacement) { $referral_desc = 'Free replacement for Invoice: ' . pad($previous_invoice, 11, '0'); } if ($is_replacement && !$is_free_replacement) { $referral_desc = 'Replacement fee for Invoice: ' . pad($previous_invoice, 11, '0'); } $item_added = Invoice::add_item($invoice, $subtotal, $_POST['id'], $referral_desc); if (!$item_added) { echo "ko"; exit;
function createShippingEstimate() { $this->load->helper('notification'); $this->view_data['submenu'] = array(); if ($_POST) { unset($_POST['send']); unset($_POST['files']); $_POST['shipping_lebel'] = ''; $config['upload_path'] = './files/media'; $config['encrypt_name'] = TRUE; $config['allowed_types'] = '*'; $this->load->library('upload', $config); if ($this->upload->do_upload()) { $data = array('upload_data' => $this->upload->data()); $_POST['shipping_lebel'] = $data['upload_data']['file_name']; } unset($_POST['userfile']); unset($_POST['dummy']); $_POST = array_map('htmlspecialchars', $_POST); $shipping_address = array('shipping_name' => $_POST['shipping_name'], 'shipping_company' => $_POST['shipping_company'], 'shipping_address' => $_POST['shipping_address'], 'shipping_city' => $_POST['shipping_city'], 'shipping_state' => $_POST['shipping_state'], 'shipping_zip' => $_POST['shipping_zip'], 'shipping_country' => $_POST['shipping_country'], 'shipping_phone' => $_POST['shipping_phone'], 'shipping_email' => $_POST['shipping_email'], 'shipping_website' => $_POST['shipping_website']); unset($_POST['shipping_name']); unset($_POST['shipping_company']); unset($_POST['shipping_address']); unset($_POST['shipping_city']); unset($_POST['shipping_state']); unset($_POST['shipping_zip']); unset($_POST['shipping_country']); unset($_POST['shipping_phone']); unset($_POST['shipping_email']); unset($_POST['shipping_website']); $core_settings = Setting::first(); $_POST['reference'] = $core_settings->invoice_reference; $_POST['project_id'] = '0'; $_POST['company_id'] = $this->client->company->id; $_POST['status'] = 'Sent'; $_POST['estimate_status'] = 'Sent'; $_POST['issue_date'] = date('Y-m-d'); $_POST['due_date'] = date('Y-m-d', strtotime('+7 days')); $_POST['currency'] = $core_settings->currency; $_POST['terms'] = $core_settings->invoice_terms; $_POST['invoice_type'] = $this->invoice_shipment_type; $_POST['estimate'] = 1; $estimate = Invoice::create($_POST); $new_estimate_reference = $_POST['reference'] + 1; $estimate_id = $estimate->id; $this->projectlib->addInvoiceAddress($estimate_id, true, $shipping_address); $estimate_reference = Setting::first(); $estimate_reference->update_attributes(array('invoice_reference' => $new_estimate_reference)); if (!$estimate) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_estimate_error')); } else { $this->load->library('userlib'); $this->load->library('parser'); $this->load->helper(array('dompdf', 'file')); $module_estimate = Module::find_by_link('estimates'); $admins = $this->userlib->getAdmins($module_estimate->id); $admin_list = array_keys($admins); $parse_data = array('client_contact' => $estimate->company->client->firstname . ' ' . $estimate->company->client->lastname, 'client_company' => $estimate->company->name, 'estimate_id' => $core_settings->estimate_prefix . $estimate->reference, 'estimate_link' => base_url() . 'estimates/view/32' . $estimate->id, 'company' => $core_settings->company, 'logo' => '<img src="' . base_url() . '' . $core_settings->logo . '" alt="' . $core_settings->company . '"/>', 'invoice_logo' => '<img src="' . base_url() . '' . $core_settings->invoice_logo . '" alt="' . $core_settings->company . '"/>'); $subject = $this->parser->parse_string($core_settings->estimate_mail_subject, $parse_data); $this->email->from($core_settings->email, $core_settings->company); $this->email->to($admin_list); $this->email->subject($subject); $email_estimate = read_file('./application/views/' . $core_settings->template . '/templates/email_admin_estimate.html'); $message = $this->parser->parse_string($email_estimate, $parse_data); $this->email->message($message); if ($this->email->send()) { log_message('error', 'Estimate #' . $core_settings->estimate_prefix . $estimate->reference . ' has been send to admins who has access to estimate'); } else { log_message('error', 'ERROR: Estimate #' . $core_settings->estimate_prefix . $estimate->reference . ' has not been send to admins who has access to estimate. Please check your servers email settings.'); } $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_estimate_success')); } redirect('cestimates'); } else { $this->load->library('geolib'); $this->view_data['geolib'] = $this->geolib; $this->view_data['shipping_methods'] = ShippingMethod::find('all', array('order' => 'name desc')); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_create_shipping_estimate'); $this->view_data['form_action'] = 'cestimates/createShippingEstimate'; $this->content_view = 'estimates/client_views/_cestimate'; } }
public function procTriggerCreate($user, $payment, $usage) { $db = JFactory::getDBO(); // Create a new cmsUser from user details - only allowing basic details so far // Try different types of usernames to make sure we have a unique one $usernames = array($user['username'], $user['username'] . substr(md5($user['name']), 0, 3), $user['username'] . substr(md5($user['name'] . (int) gmdate('U')), 0, 3)); $username = ''; // Iterate through semi-random and pseudo-random usernames until a non-existing is found $id = 1; $k = 0; while ($id) { $username = $usernames[min($k, count($usernames) - 1)]; $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $username . '\''; $db->setQuery($query); $id = $db->loadResult(); $k++; } $var['id'] = 0; $var['gid'] = 0; $var['username'] = $username; $var['name'] = $user['name']; $var['email'] = $user['email']; $var['password'] = $user['password']; $userid = aecRegistration::saveUserRegistration($var, true); // Create a new invoice with $invoiceid as secondary ident $invoice = new Invoice(); $invoice->create($userid, $usage, $payment['processor'], $payment['secondary_ident']); // return nothing, the invoice will be handled by the second ident anyways return; }
public function create() { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); $cover = OAInput::file('cover'); $pictures = OAInput::file('pictures[]'); // if (!$cover) // return redirect_message (array ('admin', $this->get_class (), 'add'), array ( // '_flash_message' => '請選擇照片(gif、jpg、png)檔案,或提供照片網址!', // 'posts' => $posts // )); if ($msg = $this->_validation_posts($posts)) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => $msg, 'posts' => $posts)); } $invoice = null; $create = Invoice::transaction(function () use($posts, $cover, &$invoice) { if (!verifyCreateOrm($invoice = Invoice::create(array_intersect_key($posts, Invoice::table()->columns)))) { return false; } if ($cover && !$invoice->cover->put($cover)) { return false; } return true; }); if (!($create && $invoice)) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '新增失敗!', 'posts' => $posts)); } if ($pictures) { foreach ($pictures as $picture) { InvoicePicture::transaction(function () use($picture, $invoice) { return verifyCreateOrm($pic = InvoicePicture::create(array_intersect_key(array_merge($picture, array('invoice_id' => $invoice->id)), InvoicePicture::table()->columns))) && $pic->name->put($picture); }); } } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '新增成功!')); }
| definitions instead of putting them all in the main routes file. | */ require app_path() . '/filters.php'; // Events Event::listen('invoice.email', function ($userId, $subscriptionId, $paymentId, $faktura = false) { $data['user'] = User::find($userId); $data['subscription'] = Subscription::find($subscriptionId); $data['payment'] = Payment::find($paymentId); $id = str_random(10); $name = $faktura ? 'faktura' : 'rachunek'; $path = '/system/docs/' . $name . '-hasztaginfo-' . $id . '.pdf'; $savepath = public_path() . $path; $template = $faktura ? 'docs.faktura' : 'docs.invoice'; $pdf = PDF::loadView($template, $data)->setWarnings(false)->save($savepath); $invoice = Invoice::create(array('user_id' => $data['user']->id, 'subscription_id' => $data['subscription']->id, 'payment_id' => $data['payment']->id, 'path' => $path, 'token' => $id, 'type' => $faktura ? 2 : 1)); $payment = Payment::find($paymentId); $payment->invoice_id = $invoice->id; $payment->save(); $email = $data['subscription']->email; $data = ['path' => $savepath, 'email' => $email]; Mail::later(5, 'emails.invoice', $data, function ($message) use($savepath, $email) { $message->to($email)->subject('[hasztag.info] Potwierdzenie wpłaty'); $message->attach($savepath); }); }); Event::listen('deactivate.subscription', function ($subscriptionId, $paymentDate) { $subscription = Subscription::find($subscriptionId); $subscription->is_active = 0; $subscription->save(); $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
public function cartItemsPPselectForm() { $pgroups = aecCartHelper::getCartProcessorGroups($this->cartobject, $this->recurring); $c = false; $exception = false; $selected = array(); $selected_form = array(); $single_select = true; foreach ($pgroups as $pgid => $pgroup) { if (count($pgroup['processors']) < 2) { if (!empty($pgroup['processors'][0])) { $pgroups[$pgid]['processor'] = $pgroup['processors'][0]; } continue; } $ex = array(); if ($c) { $ex['head'] = null; $ex['desc'] = null; } else { $ex['head'] = "Select Payment Processor"; $ex['desc'] = "There are a number of possible payment processors for one or more of your items, please select one below:<br />"; } $ex['rows'] = array(); $fname = 'cartgroup_' . $pgid . '_processor'; $pgsel = aecGetParam($fname, null, true, array('word', 'string')); if (empty($pgsel)) { $pgsel = aecGetParam($pgid . '_' . $fname, null, true, array('word', 'string')); } $selection = false; if (!is_null($pgsel)) { if (in_array($pgsel, $pgroup['processors'])) { $selection = $pgsel; } } if (!empty($selection)) { if (count($selected) > 0) { if (!in_array($selection, $selected)) { $single_select = false; } } $pgroups[$pgid]['processor'] = $selection; $selected[] = $selection; $selected_form[] = array('hidden', $pgsel, $fname, $pgsel); $this->processor_userselect = true; continue; } else { $c = true; $ex['desc'] .= "<ul>"; foreach ($pgroup['members'] as $pgmember) { $ex['desc'] .= "<li><strong>" . $this->cart[$pgmember]['name'] . "</strong><br /></li>"; } $ex['desc'] .= "</ul>"; foreach ($pgroup['processors'] as $pid => $pgproc) { $recurring = true; if (strpos($pgproc, '_recurring')) { $pgproc = str_replace('_recurring', '', $pgproc); } else { $recurring = false; } $ex['rows'][] = array('radio', $fname, $pgproc, true, $pgroup['processor_names'][$pid] . ($recurring ? ' (recurring billing)' : '')); } } if (!empty($ex['rows']) && $c) { $this->raiseException($ex); $exception = true; } } if ($exception && !empty($selected_form)) { $ex = array(); $ex['head'] = null; $ex['desc'] = null; $ex['rows'] = array(); foreach ($selected_form as $silent) { $ex['rows'][] = $silent; } $this->raiseException($ex); } $finalinvoice = null; if ($single_select) { if (!empty($selection)) { $this->processor = PaymentProcessor::getNameById(str_replace('_recurring', '', $selection)); } } else { // We have different processors selected for this cart $prelg = array(); foreach ($pgroups as $pgid => $pgroup) { $prelg[$pgroup['processor']][] = $pgroup; } foreach ($prelg as $processor => $pgroups) { if (strpos($processor, '_recurring')) { $processor_name = PaymentProcessor::getNameById(str_replace('_recurring', '', $processor)); $procrecurring = true; } else { $processor_name = PaymentProcessor::getNameById($processor); if (isset($_POST['recurring'])) { $procrecurring = $_POST['recurring']; } else { $procrecurring = false; } } $groupkeys = array_keys($pgroups); $mpg = array_pop($groupkeys); if (count($pgroups) > 1 || count($pgroups[$mpg]['members']) > 1) { // We have more than one item for this processor, create temporary cart $tempcart = new aecCart(); $tempcart->userid = $this->userid; foreach ($pgroups as $pgr) { foreach ($pgr['members'] as $member) { $tempcart->addItem(array(), $this->cartobject->content[$member]['id']); } } $tempcart->storeload(); $carthash = 'c.' . $tempcart->id; // Create a cart invoice $invoice = new Invoice(); $invoice->create($this->userid, $carthash, $processor_name, null, true, $this, $procrecurring); } else { // Only one item in this, create a simple invoice $member = $pgroups[$mpg]['members'][0]; $invoice = new Invoice(); $invoice->create($this->userid, $this->cartobject->content[$member]['id'], $processor_name, null, true, $this, $procrecurring); } if ($invoice->amount == "0.00") { $invoice->pay(); } else { $finalinvoice = $invoice; } } $ex = array(); $ex['head'] = "Invoice split up"; $ex['desc'] = "The contents of your shopping cart cannot be processed in one go. This is why we have split up the invoice - you can pay for the first part right now and access the other parts as separate invoices later from your membership page."; $ex['rows'] = array(); $this->raiseException($ex); $this->invoice_number = $finalinvoice->invoice_number; $this->invoice = $finalinvoice; $this->touchInvoice(); $objUsage = $this->invoice->getObjUsage(); if (is_a($objUsage, 'aecCart')) { $this->cartobject = $objUsage; $this->getCart(); } else { $this->plan = $objUsage; } } }