Billing Module - external webshop

Post modules, themes or any other code you want to share with the community.

Moderator: Developers

flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Billing Module - external webshop

Postby flo » Sat Mar 06, 2010 12:17 pm

I was wondering if I can use an webshop together with the billing module, is there any api I could use to autmatically generate inovices from an external web application?

I know intermesh is offering a webshop product, but I'm really a great fan of open source and would like to use whereever possible (this doesn't mean that I'm not willing to invest money in it), but as I want to use it together with another open source software I would like to contribute my system/modifications back to the ommunity.
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Billing Module - external webshop

Postby mschering » Mon Mar 08, 2010 8:45 am

It's easy to add an invoice if you can include Group-Office.php in some external script ad use the billing functions to add invoices. I can post some examples if you like.
Best regards,

Merijn Schering
Intermesh
flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Re: Billing Module - external webshop

Postby flo » Mon Mar 08, 2010 9:07 am

Intermesh wrote:It's easy to add an invoice if you can include Group-Office.php in some external script ad use the billing functions to add invoices. I can post some examples if you like.


that sounds good, if you have a little example I don't say no ;)
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Billing Module - external webshop

Postby mschering » Thu Mar 11, 2010 12:37 pm

Here's some code to add an order:

Code: Select all

         

require_once ($GO_MODULES->modules['billing']['class_path']."billing.class.inc.php");
//require_once ($GO_LANGUAGE->get_language_file('billing'));
$billing = new billing();

$order_id=$order['id']=isset($_POST['order_id']) ? ($_POST['order_id']) : 0;
         
         $book = $billing->get_book((trim($_POST['book_id'])));
         
         if($GO_SECURITY->has_permission($GO_SECURITY->user_id, $book['acl_id'])<GO_SECURITY::WRITE_PERMISSION) {
            throw new AccessDeniedException();
         }
         
         $order['book_id']=$_POST['book_id'];
         $order['language_id']=$_POST['language_id'];
         $order['user_id']=$_POST['user_id'];
         
         $order['pagebreak']=isset($_POST['pagebreak']) ? '1' : '0';
         
         if(isset($_POST['webshop_id'])) {
            $order['webshop_id']=intval($_POST['webshop_id']);
         }
         
         $order['po_id']=$_POST['po_id'];
         
         if(isset($_POST['company_id'])) {
            $order['company_id']=$_POST['company_id'];
         }
         if(isset($_POST['contact_id'])) {
            $order['contact_id']=$_POST['contact_id'];
         }
         
         $order['btime']=Date::to_unixtime($_POST['btime']);
         $order['ptime']=Date::to_unixtime($_POST['ptime']);
         
         $order['frontpage_text']=$_POST['frontpage_text'];
         
         $order['customer_name']=$_POST['customer_name'];
         $order['customer_salutation']=$_POST['customer_salutation'];
         $order['customer_contact_name']=$_POST['customer_contact_name'];
         $order['customer_address']=$_POST['customer_address'];
         $order['customer_address_no']=$_POST['customer_address_no'];
         $order['customer_zip']=$_POST['customer_zip'];
         $order['customer_city']=$_POST['customer_city'];
         $order['customer_state']=$_POST['customer_state'];
         $order['customer_country']=$_POST['customer_country'];
         $order['customer_vat_no']=$_POST['customer_vat_no'];
         $order['customer_email']=$_POST['customer_email'];
         $order['customer_extra']=$_POST['customer_extra'];
         
         $order['recur_type']=$_POST['recur_type'];
         $order['reference']=$_POST['reference'];
         $order['mtime']=time();
         
         $new = false;
         
         if($order['id']>0) {
            $old_order = $billing->get_order($order_id);
            
            $billing->update_order($order, $book, $old_order);            
            
            $response['success']=true;
         }else {
            $new = true;
            $order['user_id']=$GO_SECURITY->user_id;
            
            $order_id= $billing->add_order($order, $book);
            
            $response['order_id']=$order_id;
            $response['success']=true;
         }
         
         if(isset($GO_MODULES->modules['customfields'])) {
            require_once($GO_MODULES->modules['customfields']['class_path'].'customfields.class.inc.php');
            $cf = new customfields();
            $cf->update_fields($GO_SECURITY->user_id, $order_id, 7, $_POST);
         }
         
         
         if(!empty($_POST['link'])) {
            $link_props = explode(':', $_POST['link']);
            $GO_LINKS->add_link(
                        ($link_props[1]),
                        ($link_props[0]),
                        $order_id,
                        7);
         }
         
         if(isset($order['contact_id'])) {
            $GO_LINKS->add_link($order['contact_id'], 2, $order_id, 7);
         }
         
         if(isset($order['company_id'])) {
            $GO_LINKS->add_link($order['company_id'], 3, $order_id, 7);
         }
         
         
         //items
         $ids = array();
         if(isset($_POST['items'])) {
            $items = json_decode(($_POST['items']), true);
            for($i=0;$i<count($items);$i++) {
               $item = $items[$i];
               
               //go_debug($i.':'.count($items).' '.$item['description'].' '.$item['unit_price']);
               
               //ignore last empty item
               if($i==count($items)-1 && empty($item['description']) && $item['unit_price']==0) {
                  break;
               }
               
               $item['order_id']=$order_id;
               $item['sort_order']=$i;
               
               //   go_debug(var_export($item, true));
               
               if($item['id']>0) {
                  $ids[]=$item['id'];
                  $billing->update_item($item);
               }else {
                  $item_id= $billing->add_item($item);
                  $ids[]=$item_id;
                  $response['new_items']["$i"]=$item_id;
               }
            }
            $billing->delete_other_items($order_id, $ids);         
            $billing->sync_order_with_items($order_id);
         }            
         
         //status
         if(!empty($_POST['status_id'])) {
            $order = $billing->get_order($order_id);
            
            if($new || $_POST['status_id']!=$order['status_id']) {
               $updates = $billing->change_status($order,$_POST['status_id'],$GO_SECURITY->user_id, isset($_POST['notify_customer']));
               
               //the payment date might have been updated. We must send it to the client
               if(isset($updates['ptime'])) {
                  $response['ptime']=Date::get_timestamp($updates['ptime'], false);
               }
               
               $response['status_history_changed']=true;
            }elseif($order['status_id']>0) {
               if($order['recur_type']=='' && $order['recurred_order_id']>0) {
                  $billing->delete_order($order['recurred_order_id']);
                  $up_order['id']=$order_id;
                  $up_order['recurred_order_id']=0;
                  $billing->update_order($up_order, $book, $order);
                  
               }elseif($order['recur_type']!='') {
                  if($order['recurred_order_id']==0) {
                     $billing->recur_order($order, $book);
                  }else {
                     $recur_order = $billing->get_order($order['recurred_order_id']);
                     if(!$recur_order['status_id']) {
                        $up_order['id'] = $order['recurred_order_id'];
                        $up_order['recur_type'] = $order['recur_type'];
                        $up_order['btime'] = $billing->calcRecurTimestamp($order['btime'], $order['recur_type']);
                        $billing->update_order($up_order);
                     }
                  }
               }
            }
         }
Best regards,



Merijn Schering

Intermesh
flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Re: Billing Module - external webshop

Postby flo » Mon Mar 15, 2010 11:44 am

thanks, I got a little test form with it working, I can add orders with it into GO, but I have some questions.

I commented out the permission control:

Code: Select all

if($GO_SECURITY->has_permission($GO_SECURITY->user_id, $book['acl_id'])<GO_SECURITY::WRITE_PERMISSION) {
            throw new AccessDeniedException();
           }

I'm not exactly sure what it does, can you give me some info about how I use it correctly.

is it possible to add an image to an order, I'm working on a t-shirt designer shop, and it would be nice if the finished image could be added to the order?

and what's the best way to add the ordered items, or what fields do they need?
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Billing Module - external webshop

Postby mschering » Mon Mar 15, 2010 2:14 pm

That block of code checks if the logged in user has access to the book. You probably want to remove that.

To add an item after you created an order:

Code: Select all

$item['order_id']=$order_id;
$item['sort_order']=0;//sort index
$item['amount']=1;
$item['description']='Item description;
$item['unit_price']=1.00; //price excl. VAT
$item['unit_total']=1.19; //price incl. VAT
$item['vat']=19.00 //VAT percentage
Best regards,



Merijn Schering

Intermesh
flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Re: Billing Module - external webshop

Postby flo » Mon Mar 15, 2010 3:09 pm

Intermesh wrote:That block of code checks if the logged in user has access to the book. You probably want to remove that.

To add an item after you created an order:

Code: Select all

$item['order_id']=$order_id;
$item['sort_order']=0;//sort index
$item['amount']=1;
$item['description']='Item description;
$item['unit_price']=1.00; //price excl. VAT
$item['unit_total']=1.19; //price incl. VAT
$item['vat']=19.00 //VAT percentage


ok, can I add this in the same file like the one wich creates the order?

should I have an $order_id with this line you posted,

Code: Select all

$order_id=$order['id']=isset($_POST['order_id']) ? ($_POST['order_id']) : 0;

because I only get one if I change the status in the billing module.
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Billing Module - external webshop

Postby mschering » Tue Mar 16, 2010 1:05 pm

No you get the order ID from:

Code: Select all

 $order_id= $billing->add_order($order, $book);
Best regards,



Merijn Schering

Intermesh
flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Re: Billing Module - external webshop

Postby flo » Tue Feb 08, 2011 6:53 pm

Intermesh wrote:To add an item after you created an order:

Code: Select all

$item['order_id']=$order_id;
$item['sort_order']=0;//sort index
$item['amount']=1;
$item['description']='Item description;
$item['unit_price']=1.00; //price excl. VAT
$item['unit_total']=1.19; //price incl. VAT
$item['vat']=19.00 //VAT percentage


I can't get that to work. do you have some more explanation for it, or more code snippets how to get the items added to the order it?
denson
Posts: 5
Joined: Sat Jun 25, 2011 12:39 am

Re: Billing Module - external webshop

Postby denson » Mon Jun 27, 2011 12:17 am

I have to agree that writing your own script would save you a lot more as investing in a webshop can set you back some $600 where in you can achieve the same with your own scripting to handle such process. I have looked into the example and luckily made it work, is it possible that the conflict lies within your other code or other files? That codes seems to work fine in my trials.
User avatar
WilmarVB
Group-Office Developer
Group-Office Developer
Posts: 86
Joined: Mon May 10, 2010 3:47 pm
Location: Den Bosch, Netherlands
Contact:

Re: Billing Module - external webshop

Postby WilmarVB » Wed Jul 27, 2011 1:39 pm

Hello Flo,

Do you still need help on this?
Kind regards,
WilmarVB
Intermesh
flo
Posts: 87
Joined: Mon Jan 26, 2009 11:49 am

Re: Billing Module - external webshop

Postby flo » Wed Jul 27, 2011 2:37 pm

WilmarVB wrote:Hello Flo,

Do you still need help on this?


yes, I do.

Return to “Contributed development”

Who is online

Users browsing this forum: No registered users and 1 guest

cron