• Neuralab.Net – digitalna dizajn agencija za Web, Mobilne aplikacije, Društvene mreže i Cloud hosting
  • Kontaktirajte nas
  • Check out our portfolio in English here
  • Zapratite nas na Twitteru
  • Lajkamo FB Timeline
  • Pretplatite se na Tumblr blog
  • Search Site

  • O Neuralabu
    • Junaci Neuralab straniceUpoznajte tim i što sve volimo raditi :)
    • Nagrade & FestivaliSim pak tam
    • Mediji o nama (Press kutak)Što je Neuralab / Što je Transmeet.Tv … Najbolje da čujete od drugih :)
    • Partneri i suradniciPartneri i suradnici pri realizaciji IT / Web / Mobile projekata
  • Što radimo
    • Dizajn i korisnička sučeljaKoncepti, Wireframing, Web dizajn, Grafički dizajn, UX / UI, Interaktivni razvoj
    • Web razvoj i programiranjeWeb stranice, Mobilne aplikacije, CMS-ovi, Flash igre, B2B Web sučelja, SEO / SEM, Baze podataka
    • Multimedia, Video & Live streamingVideo produkcija, Live streaming, Animacije, Multimedia, Post-produkcija
    • Društvene mreže & MarketingVođenje Social kampanja, Facebook Aplikacije, Twitter, Marketing, Content Strategy
    • Cloud HostingWeb Hosting, Google Apps, Integracija Cloud usluga, LAMP, Windows + IIS, Premium Support
  • Mapa radova
    • Web dizajnDizajniranje webova + User eXperience
    • Mobilne aplikacijeRazvoj / Dizajn mobilnih aplikacija
    • Grafički dizajnPrint, Street, Art, Guerrilla
    • Razvoj i programiranjeWeb / Mobilno / Software / Arhitektura
    • Društvene mrežeFacebok aplikacije, Sadržaj, Upravljanje
    • Interaktivna multimedijaBanneri, Mikro flash Igre, Online DVD…
    • Live streamingLive prijenosi, MultiCam, Encoding
    • Video & FotoVideo, Snimanje, Postprodukcija, Produkcija
    • AnimacijeAnimiranje, postprodukcija, 3D
    • Cloud hostingHosting, Cloud, Google Apps

      • Neke od osvojenih nagrada…
  • Blog
    • Dizajn & ArtDizajn, koncepti, korisnička sučelja :)
    • Programiranje & SoftwareProgramiranje, razvoj, baze podataka, aplikacije
    • Mobilne platforme i aplikacijeMobilni razvoj, dizajn i aplikacije
    • Multimedia + VideoLive streaming, video, animacije, produkcija, post.
    • Društvene mrežeFacebook, Twitter + ostale socijalne mreže
    • Cloud & HostingGoogle apps, Cloud, CDN, Serveri, Web hosting

        • Pins, Tweets + Likes s Neuralab kauča – week 17
          K Kr...
        • Posjetili smo Google Analytics Day
          Dan posvećen analizi podataka, ključnim pokazate...

      • tumblr follow button

          - Proskenirajte i naš TUMLBR unofficial blog za all-things-l33t-digital

  • Kontaktirajte nas
  • Generate Harvest invoice from Google Docs spreadsheet ... Cloud style

Generate Harvest invoice from Google Docs spreadsheet … Cloud style

15 Apr 2012 / 1 Comment / in Cloud & Hosting, Coding & Software/by KresimirKoncic

The thing about web hosting is that…you know…it’s somewhat a comodity and somewhat a geeky-techy thing –  you need to have a good pricing model but also a good  technology background to run the operations (as smoothly as possible :)). When the “Cloud hit the shelves” it didn’t make the whole thing a lot easier, at least for us back-end guys. Sure the clients wanted the new model, usage-based pricing, scalability and availability but didn’t want to know about complex pricing models behind it.

But to reverse few years in the past…we started as a web design company with limited hosting packages that looked a lot like a standard old-school hosting from the 90′s (silver,gold and unlimited packages for 9, 19, 29 $ per month :))) and I don’t need to explain what happens when 100k pageviews per day portal tries to buy “unlimited package”…talking about Overselling that is…these times are now over.

Anyways, making invoices at that time was pretty easy. We invoiced clients on a yearly basis and they deposited regular and stable amounts of money based on the package they consumed.  But why did i mentioned “Le cloud” in the first paragraph…well as the time passed by a lot more clients started asking for that cloud thing and we as a company also had a “thing” for new technologies. We started to implement Cloud solutions to our clients web sites, back-ends, business processes and so forth. We had Google Apps integration with Salesforces. We had Rackspace integrate with S3. We had S3 integrate with Encoding integrate with s3 and back….you get the picture.

For the record, our main hosting platform (PaaS) resides on Rackspace servers but our vital infrastructure is also on AWS (IaaS – CloudFront, S3, ELB, Route53 etc.). In some cases we resell Google Apps, Mailchimp, Salesforce (SaaS) and also some specialized services such as Encoding but that’s another story. The MAIN THING here is that our clients receive only ONE invoice for all that computing power…

CloudProvidersthree Generate Harvest invoice from Google Docs spreadsheet ... Cloud style

 

From starters we can handle all that items only in spreadsheet ’cause we needed the flexibility and reporting possibility of Google spreadsheets. Every client wanted to have monthly stats and we also needed usage reporting for our own business. Getting the numbers through API or some sort of importing is not a big deal when it comes to G.Apps – every cloud service has some sort of adapter or XML format for their own invoices. Parallel to evolution of our hosting platform, we started to use Harvest for our project management, hours and billing but mainly for the “agency side” business i.e. Design, UX/UI, Mobile development and other non-commodity stuff. These projects are spanning through several months and are not high in frequency so automated billing and invoicing is not a priority. As it is a good practice to consolidate all financials in one place, we took a look at Harvest API for automated invoice creation from Google spreadsheets and here is the result…

First you need to have some sort of web service that resides on your website or subdomain that will call Harvest API. We use mainly ASP.NET C# for our developement so here is the code that will generate Harvest invoice from your backend. Note that it parses data from query string so you can be flexible and put all of your data into the POST or GET parameters. Just place this code into the .ASHX generic handler or ASP.NET page…

 

 

using System;
using System.Web;
using System.Configuration;
using System.Net;
using System.IO;
using System.Text;

public class GenerateInvoice : IHttpHandler
{
  public void ProcessRequest (HttpContext context)
  {
    string notesBill = "Insert your note to the customer here";

    string ClientID = context.Request.QueryString["ClientID"].ToString();

    string itemPrice1 = context.Request.QueryString["itemPrice1"].ToString().Replace(".", ",");
    string itemUsage1 = context.Request.QueryString["itemUsage1"].ToString().Replace(".", ",");

    string itemPrice2 = context.Request.QueryString["itemPrice2"].ToString().Replace(".", ",");
    string itemUsage2 = context.Request.QueryString["itemUsage2"].ToString().Replace(".", ",");

    //...YOU CAN HAVE MULTIPLE ITEMS HERE
    //

    DateTime issue = DateTime.Now;
    DateTime due = issue.AddDays(2); //OR INSERT YOUR OWN DUE DATE

    string uri = "https://yourcompany.harvestapp.com/invoices";
    string username = "yourUserName";
    string password = "yourPassWord";

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    request.Method = "POST";
    request.Accept = "application/xml";
    request.ContentType = "application/xml";
    request.AllowWriteStreamBuffering = true;
    request.MaximumAutomaticRedirections = 1;
    request.AllowAutoRedirect = true;
    request.UserAgent = ".Net test application";
    request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(username + ":" + password)));

    StringBuilder xml = new StringBuilder();

        xml.Append("<invoice>");
        xml.AppendLine("<due -at type='date'>"+due.Year.ToString()+"-"+due.Month.ToString()+"-"+due.Day.ToString()+"</due>");

        xml.AppendLine("<client -id type='integer'>"+ClientID+"</client>");

        xml.AppendLine("<currency>Croatia Kuna - HRK</currency>");
        xml.AppendLine("<issued -at type='date'>" + issue.Year.ToString() + "-" + issue.Month.ToString() + "-" + issue.Day.ToString() + "</issued>");

        xml.AppendLine("<subject>Client usage pricing</subject>");
        xml.AppendLine("<notes>"+notesBill+"</notes>");

        xml.AppendLine("<kind>free_form</kind>");

        xml.AppendLine("<csv -line-items>");
        xml.AppendLine("kind,description,quantity,unit_price,amount,taxed,taxed2,project_id");

        xml.AppendLine(",Item 1 usage,\"" + itemUsage1 + "\",\"" + itemPrice1 + "\",true,false,");
        xml.AppendLine(",Item 2 Usage,\"" + itemUsage2 + "\",\"" + itemPrice2 + "\",true,false,");

        xml.AppendLine("</csv>");
        xml.AppendLine("</invoice>");

    StreamWriter sw = new StreamWriter(request.GetRequestStream());
    sw.WriteLine(xml.ToString());
    sw.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    if (request.HaveResponse == true &amp;&amp; response != null)
    {
      context.Response.Write("Invoice generated!");
    }

    response.Close();
  }
}

This service is online so your other back-end processes can use this script to generate invoices. The second phase is to integrate Google API into this process so we can generate Harvest Invoice from within the Google Docs Spreadsheet and this is done through Google Apps scripts.

First it is a good idea to populate spreadsheet menu with buttons that will call our script….

function onOpen()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var menuEntries = [ {name: "Generate Invoice", functionName: "generateInvoice"} ];

  ss.addMenu("HARVEST", menuEntries);
}

Menuitems2 Generate Harvest invoice from Google Docs spreadsheet ... Cloud style

 

Notice that call to “generateInvoice” function? You can find it in the window bellow but first some explanations – Our spreadsheet uses one sheet (first one [0]) for listing of prices that are same for all clients AND separate sheets for each client. That client sheets hold consumption data, usage statistics and so forth. You could setup you back-end any other way. This function will just show you how to send data from spreadsheet to earlier explained Harvest API. Our process is simple… We just select the row in usage statistics and hit the button “Generate Invoice”. That row holds the Client Harvest ID (that you must input manually) and all the usage data that needs to be priced (item1, item2…) you get the idea.

 

function generateInvoice()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // get spreadsheet with prices
  var pricessheet = ss.getSheets()[0];  

  // get prices from the spreadsheet
  var itemPrice1 = pricessheet.getRange("A1").getValue();
  var itemPrice2 = pricessheet.getRange("A2").getValue();

  // get clients usage from active spreadsheet row
  var clientbill = ss.getActiveSheet().getActiveSelection().getValues();
  var clientID = clientbill[0][0];
  var itemUsage1 = clientbill[0][1];
  var itemUsage2 = clientbill[0][2];

  var options = { "method" : "post" }

  var posttoharvestURL = "http://harvestapi.yourcompany.com/cloudHostingGenerateBill.ashx?ClientID=" + clientID + "&amp;itemPrice1 =" + itemPrice1 + "&amp;itemPrice2=" + itemPrice2 + "&amp;itemUsage1=" + itemUsage1 + "&amp;itemUsage2=" + itemUsage2;

  var response = UrlFetchApp.fetch(posttoharvestURL, options);

  Browser.msgBox("Invoice generated");
}

 

Future work: You could probably call Harvest API directly from Google scripts as this service supports OAUTH but we like to have system modulated i.e. we could use server side script for later use in other systems. This is subjective of course and depends on business needs. Also…populating data into the spreadsheet is possible by some cloud services through their API and can be fully automated but this topic is outside this blog post.

If you have any suggestions / ideas or you would like to share some thoughts on your cloud integration…give as a comment or drop us a mention at @transmeettv

Tags: api, apps, automation, billing, cloud, google, harvest, integration, invoice, script, scripts, service, spreadsheet

Related Posts

Did you like this entry?
Here are a few more posts that might be interesting for you.
Related Posts
Što spakirati na Android za ljetovanje? [MOBILE]
Facebook lajka svoje servere i tehnologiju [CLOUD REVIEW]
Pins, Tweets + Likes s Neuralab kauča – week 16
Google apps: Tko je kupac, a tko je korisnik? [INFOGRAFIKA-ANALIZA]
Svaka sekunda je bitna kod zarađivanja ne webu, barem po Internap [INFOGRAFICI]
Cijene cloud hosting usluga padaju i dalje
OFF Tv vol.2 kreće 4.7 u 19 h – Feat. Sergej, Gekko i Radio 808 (Eddy & Ines)
Forrester research najavio povećanje cloud tržišta na 241 milijardu dolara do 2020...
Neuraplex je postao službeni reseller Google Apps usluga
Posjetili smo Google Analytics Day

One Response to Generate Harvest invoice from Google Docs spreadsheet … Cloud style

  1. Evolucija Google Apps scripte u moćnu developersku platformu | Zimo says:
    28/06/2012 at 13:14

    [...] 2. Integracija ASP.NET aplikacije s Apps Scriptom [...]

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Pretražite Neuralab…

socialife sa Neuralabom

Odaberite kategoriju novosti…

  • Cloud & Hosting (31)
  • Coding & Software (28)
  • Design & Art (46)
  • Mobile (18)
  • Multimedia + Video (36)
  • Neuralab (16)
  • News (13)
  • Social media (52)

Arhiva…

  • May 2013 (4)
  • April 2013 (6)
  • March 2013 (7)
  • February 2013 (7)
  • January 2013 (8)
  • December 2012 (7)
  • November 2012 (5)
  • October 2012 (3)
  • July 2012 (2)
  • June 2012 (4)
  • May 2012 (2)
  • April 2012 (3)
  • March 2012 (6)
  • February 2012 (7)
  • January 2012 (7)
  • October 2011 (2)
  • September 2011 (5)
  • August 2011 (1)
  • July 2011 (5)
  • June 2011 (6)
  • May 2011 (9)
  • April 2011 (8)
  • March 2011 (2)
  • February 2011 (8)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (1)
  • October 2010 (4)

Tagovi & Poveznice

adwords algebra amazon aplikacije apps aws blog cloud database design development dizajn event facebook Flash google hosting hypo infografika interview iOs iPad iPhone live management marketing media mobile neuralab oglašavanje seo server services simple social storage strategija streaming tablet transmeet tutorial video web youtube zagreb

Kalendar novosti…

May 2013
M T W T F S S
« Apr    
 12345
6789101112
13141516171819
20212223242526
2728293031  

RSS Cloud hosting status

  • New Status Page | Thursday August 2, 2012 02/08/2012
    Tomorrow, we will be rolling out our new System Status Page which consolidates the system status information for all Rackspace Products and Services onto a single dashboard. The URL for this new site is https://status.rackspace.com. Once the new page is... […]
  • Cloud Sites | mysql50-63.wc1.dfw1 | Degraded 01/08/2012
    This evening we had a scheduled database maintenance for a small percentage of users located in mysql50-63.wc1.dfw1. The maintenance was scheduled to last until 11pm however is taking a little longer to complete.We will continue to update the status page... […]
  • Cloud Sites | Control Panel | Online 31/07/2012
    As of 2:10 PM CT we are getting reports of customers receiving errors such as "No Data for selected period" in the Control Panel. Our engineers are working to resolve this issue as quickly as possible. Update: As of 2:27... […]
  • Cloud Sites | Ticket System Maintenance | Saturday, August 4th, 2012 at 7:30 PM – 8:00 PM CDT 31/07/2012
    On Saturday, August 4th, 2012 at 7:30 PM CDT the Rackspace Cloud Ticketing system will undergo maintenance. This maintenance will be completed on or before 8:00 PM CDT. During the maintenance, there will be periods where the ticketing system will... […]
Creative Commons License
This work by Neuralab is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Kontakt informacije [...]

Neuralab [digitalna agencija za web, social, mobile & motion design]

Transmeet.Tv [ Internetska televizija fokusirana na urbanu kulturu, muziku i dizajn ]

Digitalni oblak d.o.o.
OIB: 63401934653
Tax Num: 02589265

Jurkovićeva 1, 10 000 Zagreb
Tel: +385 98 1717 628
Fax: +385 1 4633 016
Email: info@neuralab.net

Temeljni kapital od 20.000,00 Kn uplaćen u cijelosti pri RBA
IBAN: HR2624840081105295287

Pronađite nas na [...]


Neuralab on behance Neuralab on Github Neuralab on Facebook Neuralab on LinkedIn

Zadnje objavljeno [...]

  • Pins, Tweets + Likes s Neuralab kauča – week 17May 20, 2013, 10:28 am
  • Posjetili smo Google Analytics DayMay 15, 2013, 9:20 am
  • Digitalna revolucija: Print@home 3DMay 10, 2013, 2:18 pm
  • Gostujuće predavanje u Knjižnici grada ZagrebaMay 8, 2013, 3:26 am
  • Dan kada su pala ministarstvaApril 30, 2013, 2:27 pm

Tweetamo [...]

  • Bruno Zagorscak (http://t.co/t8EcFJqwlg) aka Gospodar rata! http://t.co/Bbjv6Es0QI
    10/05/2013 - 14:28
  • Raaaaapidoool (@ Pepermint w/ @msrsan @craftzeefactory) http://t.co/iUOsZeYi88
    08/05/2013 - 19:16
  • Kuhanje metha nedjeljom u 22 ... Lego style ... http://t.co/3MNYuvc6lV
    05/05/2013 - 20:28
  • May the 4th be with you! Neuralab style ... http://t.co/27CGyIaQXI
    04/05/2013 - 21:47
© Copyright - Neuralab - digitalna agencija za web, mobilne aplikacije, društvene mreže i digitalni marketing - You can also visit us on Google+ - a.neuralab.site
  • scroll to top
  • Follow us on Twitter
  • Join our Facebook Group
  • Subscribe to our RSS Feed