Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickbooks feature #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion application/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/

//sale
$autoload['helper'] = array('form','url','table','text','currency', 'html');
$autoload['helper'] = array('form','url','table','text','currency', 'html', 'quickbooks');


/*
Expand Down
4 changes: 3 additions & 1 deletion application/controllers/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 32 additions & 0 deletions application/helpers/quickbooks_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
function postToQuickbooks($action, $data)
{
$CI =& get_instance();

$response = 'phppos';
if ($CI->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;
}
?>
3 changes: 3 additions & 0 deletions application/language/english/config_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
?>
7 changes: 6 additions & 1 deletion application/models/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
}

}
Expand All @@ -106,15 +108,18 @@ 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));

}

/*
Deletes a list of customers
*/
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));
}
Expand Down
10 changes: 10 additions & 0 deletions application/models/employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions application/models/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
10 changes: 8 additions & 2 deletions application/models/sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']).'<br>';
Expand Down Expand Up @@ -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']);
Expand All @@ -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
Expand Down Expand Up @@ -105,6 +109,7 @@ function save ($items,$customer_id,$employee_id,$comment,$payments,$sale_id=fals
'name' =>$row['name'],
'percent' =>$row['percent']
));

}
}
}
Expand All @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion application/models/supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
}

}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
21 changes: 21 additions & 0 deletions application/views/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@
</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_quickbooks_url').':', 'quickbooks_url',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_input(array(
'name'=>'quickbooks_url',
'id'=>'quickbooks_url',
'value'=>$this->config->item('quickbooks_url')));?>
</div>
</div>

<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_quickbooks_secret_key').':', 'quickbooks_secret_key',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_input(array(
'name'=>'quickbooks_secret_key',
'id'=>'quickbooks_secret_key',
'value'=>$this->config->item('quickbooks_secret_key')));?>
</div>
</div>

<?php
echo form_submit(array(
Expand All @@ -250,6 +269,8 @@
);
?>
</fieldset>


</div>
<?php
echo form_close();
Expand Down