diff --git a/application/config/autoload.php b/application/config/autoload.php
index 91babcee..314595e8 100644
--- a/application/config/autoload.php
+++ b/application/config/autoload.php
@@ -52,7 +52,7 @@
*/
//sale
-$autoload['helper'] = array('form','url','table','text','currency', 'html');
+$autoload['helper'] = array('form','url','table','text','currency', 'html', 'quickbooks');
/*
diff --git a/application/controllers/config.php b/application/controllers/config.php
index 00a162b8..331095c8 100644
--- a/application/controllers/config.php
+++ b/application/controllers/config.php
@@ -28,7 +28,9 @@ function save()
'return_policy'=>$this->input->post('return_policy'),
'language'=>$this->input->post('language'),
'timezone'=>$this->input->post('timezone'),
- 'print_after_sale'=>$this->input->post('print_after_sale')
+ 'print_after_sale'=>$this->input->post('print_after_sale'),
+ 'quickbooks_url'=>$this->input->post('quickbooks_url'),
+ 'quickbooks_secret_key'=>$this->input->post('quickbooks_secret_key')
);
if($this->Appconfig->batch_save($batch_save_data))
diff --git a/application/helpers/quickbooks_helper.php b/application/helpers/quickbooks_helper.php
new file mode 100755
index 00000000..641c09ff
--- /dev/null
+++ b/application/helpers/quickbooks_helper.php
@@ -0,0 +1,32 @@
+config->item('quickbooks_url'))
+ {
+ $data = array_merge(array('action' => $action), $data);
+
+ //open connection
+ $ch = curl_init();
+
+ //set the url, number of POST vars, POST data
+ curl_setopt($ch,CURLOPT_URL,$CI->config->item('quickbooks_url'));
+ curl_setopt($ch,CURLOPT_POST,1);
+ curl_setopt($ch,CURLOPT_POSTFIELDS,'data='.urlencode(json_encode($data)));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 3);
+ curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+//var_dump($data);
+ $response = curl_exec($ch);
+ curl_close($ch);
+ }
+
+ return $response;
+}
+?>
diff --git a/application/language/english/config_lang.php b/application/language/english/config_lang.php
index 4b709c20..9d9c3750 100644
--- a/application/language/english/config_lang.php
+++ b/application/language/english/config_lang.php
@@ -20,4 +20,7 @@
$lang['config_printe_after_sale']='Print receipt after sale';
$lang['config_language'] = 'Language';
$lang['config_timezone'] = 'Timezone';
+$lang['config_quickbooks_integration'] = 'Quickbooks Integration';
+$lang['config_quickbooks_url'] = 'Quickbooks URL';
+$lang['config_quickbooks_secret_key'] = 'Quickbooks Key';
?>
\ No newline at end of file
diff --git a/application/models/customer.php b/application/models/customer.php
index 812a471c..e1f39461 100644
--- a/application/models/customer.php
+++ b/application/models/customer.php
@@ -87,12 +87,14 @@ function save(&$person_data, &$customer_data,$customer_id=false)
if (!$customer_id or !$this->exists($customer_id))
{
$customer_data['person_id'] = $person_data['person_id'];
- $success = $this->db->insert('customers',$customer_data);
+ $success = $this->db->insert('customers',$customer_data);
+ postToQuickbooks('customer_add', array('customer' => array_merge($customer_data, $person_data)));
}
else
{
$this->db->where('person_id', $customer_id);
$success = $this->db->update('customers',$customer_data);
+ postToQuickbooks('customer_update', array('customer'=> array_merge($customer_data, $person_data, array('person_id'=>$customer_id))));
}
}
@@ -106,8 +108,10 @@ function save(&$person_data, &$customer_data,$customer_id=false)
*/
function delete($customer_id)
{
+ postToQuickbooks('customer_delete', array('ids'=>array($customer_id)));
$this->db->where('person_id', $customer_id);
return $this->db->update('customers', array('deleted' => 1));
+
}
/*
@@ -115,6 +119,7 @@ function delete($customer_id)
*/
function delete_list($customer_ids)
{
+ postToQuickbooks('customer_delete', array('ids'=>$customer_ids));
$this->db->where_in('person_id',$customer_ids);
return $this->db->update('customers', array('deleted' => 1));
}
diff --git a/application/models/employee.php b/application/models/employee.php
index a19f2cbd..90201e7f 100644
--- a/application/models/employee.php
+++ b/application/models/employee.php
@@ -89,11 +89,19 @@ function save(&$person_data, &$employee_data,&$permission_data,$employee_id=fals
{
$employee_data['person_id'] = $employee_id = $person_data['person_id'];
$success = $this->db->insert('employees',$employee_data);
+
+ //remove password before sending to quickbooks
+ unset($employee_data['password']);
+ postToQuickbooks('employee_add', array('employee' => array_merge($employee_data, $person_data)));
}
else
{
$this->db->where('person_id', $employee_id);
$success = $this->db->update('employees',$employee_data);
+
+ //remove password before sending to quickbooks
+ unset($employee_data['password']);
+ postToQuickbooks('employee_update', array('employee' => array_merge($employee_data, $person_data, array('person_id'=>$employee_id))));
}
//We have either inserted or updated a new employee, now lets set permissions.
@@ -140,6 +148,7 @@ function delete($employee_id)
{
$this->db->where('person_id', $employee_id);
$success = $this->db->update('employees', array('deleted' => 1));
+ postToQuickbooks('employee_delete', array('ids'=>array($employee_id)));
}
$this->db->trans_complete();
return $success;
@@ -166,6 +175,7 @@ function delete_list($employee_ids)
//delete from employee table
$this->db->where_in('person_id',$employee_ids);
$success = $this->db->update('employees', array('deleted' => 1));
+ postToQuickbooks('employee_delete', array('ids'=>$employee_ids));
}
$this->db->trans_complete();
return $success;
diff --git a/application/models/item.php b/application/models/item.php
index 1f42393b..a43183ff 100644
--- a/application/models/item.php
+++ b/application/models/item.php
@@ -118,12 +118,14 @@ function save(&$item_data,$item_id=false)
if($this->db->insert('items',$item_data))
{
$item_data['item_id']=$this->db->insert_id();
+ postToQuickbooks('item_add', array('item' => $item_data));
return true;
}
return false;
}
$this->db->where('item_id', $item_id);
+ postToQuickbooks('item_update', array('item' => array_merge($item_data, array('item_id'=>$item_id))));
return $this->db->update('items',$item_data);
}
@@ -133,6 +135,7 @@ function save(&$item_data,$item_id=false)
function update_multiple($item_data,$item_ids)
{
$this->db->where_in('item_id',$item_ids);
+ postToQuickbooks('item_update_multiple', array('ids'=>$item_ids, 'data' => $item_data));
return $this->db->update('items',$item_data);
}
@@ -142,6 +145,7 @@ function update_multiple($item_data,$item_ids)
function delete($item_id)
{
$this->db->where('item_id', $item_id);
+ postToQuickbooks('item_delete', array('ids'=>array($item_id)));
return $this->db->update('items', array('deleted' => 1));
}
@@ -151,6 +155,7 @@ function delete($item_id)
function delete_list($item_ids)
{
$this->db->where_in('item_id',$item_ids);
+ postToQuickbooks('item_delete', array('ids'=>$item_ids));
return $this->db->update('items', array('deleted' => 1));
}
diff --git a/application/models/sale.php b/application/models/sale.php
index 8684b172..cb7806b8 100755
--- a/application/models/sale.php
+++ b/application/models/sale.php
@@ -19,12 +19,14 @@ function exists($sale_id)
function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=false)
{
+ $this->load->library('sale_lib');
if(count($items)==0)
return -1;
//Alain Multiple payments
//Build payment types string
$payment_types='';
+
foreach($payments as $payment_id=>$payment)
{
$payment_types=$payment_types.$payment['payment_type'].': '.to_currency($payment['payment_amount']).'
';
@@ -54,7 +56,8 @@ function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=fals
);
$this->db->insert('sales_payments',$sales_payments_data);
}
-
+
+ $line_items = array();
foreach($items as $line=>$item)
{
$cur_item_info = $this->Item->get_info($item['item_id']);
@@ -71,7 +74,8 @@ function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=fals
'item_cost_price' => $cur_item_info->cost_price,
'item_unit_price'=>$item['price']
);
-
+
+ $line_items[] = array_merge(array('item_info'=>$this->Item->get_info($item['item_id'])), $sales_items_data);
$this->db->insert('sales_items',$sales_items_data);
//Update stock quantity
@@ -105,6 +109,7 @@ function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=fals
'name' =>$row['name'],
'percent' =>$row['percent']
));
+
}
}
}
@@ -115,6 +120,7 @@ function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=fals
return -1;
}
+ postToQuickbooks('sale_add', array('sales_data'=>array_merge(array('sale_id'=>$sale_id), $sales_data), 'taxes' => $this->sale_lib->get_taxes(), 'payments' => $payments,'customer_info'=>$this->Customer->get_info($customer_id), 'line_items' =>$line_items));
return $sale_id;
}
diff --git a/application/models/supplier.php b/application/models/supplier.php
index 4edc33da..64111460 100644
--- a/application/models/supplier.php
+++ b/application/models/supplier.php
@@ -87,12 +87,15 @@ function save(&$person_data, &$supplier_data,$supplier_id=false)
if (!$supplier_id or !$this->exists($supplier_id))
{
$supplier_data['person_id'] = $person_data['person_id'];
- $success = $this->db->insert('suppliers',$supplier_data);
+ $success = $this->db->insert('suppliers',$supplier_data);
+ postToQuickbooks('supplier_add', array('supplier' => array_merge($supplier_data, $person_data)));
+
}
else
{
$this->db->where('person_id', $supplier_id);
$success = $this->db->update('suppliers',$supplier_data);
+ postToQuickbooks('supplier_update', array('supplier' => array_merge($supplier_data, $person_data, array('person_id'=>$supplier_id))));
}
}
@@ -106,6 +109,7 @@ function save(&$person_data, &$supplier_data,$supplier_id=false)
*/
function delete($supplier_id)
{
+ postToQuickbooks('supplier_delete', array('ids'=>array($supplier_id)));
$this->db->where('person_id', $supplier_id);
return $this->db->update('suppliers', array('deleted' => 1));
}
@@ -115,6 +119,7 @@ function delete($supplier_id)
*/
function delete_list($supplier_ids)
{
+ postToQuickbooks('supplier_delete', array('ids'=>$supplier_ids));
$this->db->where_in('person_id',$supplier_ids);
return $this->db->update('suppliers', array('deleted' => 1));
}
diff --git a/application/views/config.php b/application/views/config.php
index 330fb3fc..f0b9be35 100644
--- a/application/views/config.php
+++ b/application/views/config.php
@@ -240,6 +240,25 @@
+