mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-16 04:50:09 -04:00
Sanity checked SQL insert and update, minor fixes (#598)
This commit is contained in:
@@ -161,7 +161,9 @@ class Config extends Secure_area
|
||||
$this->Stock_location->delete($location_id);
|
||||
}
|
||||
|
||||
$success = $this->db->trans_complete();
|
||||
$this->db->trans_complete();
|
||||
|
||||
$success = $this->db->trans_status();
|
||||
|
||||
echo json_encode(array('success'=>$success, 'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
|
||||
}
|
||||
|
||||
@@ -692,7 +692,8 @@ class Items extends Secure_area implements iData_controller
|
||||
'trans_location'=>$location_id,
|
||||
'trans_inventory'=>0
|
||||
);
|
||||
$this->db->insert('inventory',$excel_data);
|
||||
|
||||
$this->Inventory->insert($excel_data);
|
||||
}
|
||||
}
|
||||
else //insert or update item failure
|
||||
|
||||
@@ -31,40 +31,42 @@ class Appconfig extends CI_Model
|
||||
|
||||
}
|
||||
|
||||
function save($key,$value)
|
||||
function save($key, $value)
|
||||
{
|
||||
$config_data=array(
|
||||
'key'=>$key,
|
||||
'value'=>$value
|
||||
$config_data = array(
|
||||
'key'=>$key,
|
||||
'value'=>$value
|
||||
);
|
||||
|
||||
if (!$this->exists($key))
|
||||
{
|
||||
return $this->db->insert('app_config',$config_data);
|
||||
return $this->db->insert('app_config', $config_data);
|
||||
}
|
||||
|
||||
$this->db->where('key', $key);
|
||||
return $this->db->update('app_config',$config_data);
|
||||
|
||||
return $this->db->update('app_config', $config_data);
|
||||
}
|
||||
|
||||
function batch_save($data)
|
||||
{
|
||||
$success=true;
|
||||
$success = true;
|
||||
|
||||
//Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->trans_start();
|
||||
|
||||
foreach($data as $key=>$value)
|
||||
{
|
||||
if(!$this->save($key,$value))
|
||||
if(!$this->save($key, $value))
|
||||
{
|
||||
$success=false;
|
||||
$success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
return $success;
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
function delete($key)
|
||||
|
||||
@@ -115,7 +115,6 @@ class Customer extends Person
|
||||
*/
|
||||
function save_customer(&$person_data, &$customer_data, $customer_id=false)
|
||||
{
|
||||
$success=false;
|
||||
//Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->trans_start();
|
||||
|
||||
@@ -124,18 +123,18 @@ class Customer extends Person
|
||||
if (!$customer_id or !$this->exists($customer_id))
|
||||
{
|
||||
$customer_data['person_id'] = $person_data['person_id'];
|
||||
$success = $this->db->insert('customers', $customer_data);
|
||||
$this->db->insert('customers', $customer_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->where('person_id', $customer_id);
|
||||
$success = $this->db->update('customers', $customer_data);
|
||||
$this->db->update('customers', $customer_data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $success;
|
||||
return $this->db->trans_status();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -93,36 +93,34 @@ class Employee extends Person
|
||||
if (!$employee_id or !$this->exists($employee_id))
|
||||
{
|
||||
$employee_data['person_id'] = $employee_id = $person_data['person_id'];
|
||||
$success = $this->db->insert('employees',$employee_data);
|
||||
$success = $this->db->insert('employees', $employee_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->where('person_id', $employee_id);
|
||||
$success = $this->db->update('employees',$employee_data);
|
||||
$success = $this->db->update('employees', $employee_data);
|
||||
}
|
||||
|
||||
//We have either inserted or updated a new employee, now lets set permissions.
|
||||
if($success)
|
||||
{
|
||||
//First lets clear out any grants the employee currently has.
|
||||
$success=$this->db->delete('grants', array('person_id' => $employee_id));
|
||||
$success = $this->db->delete('grants', array('person_id' => $employee_id));
|
||||
|
||||
//Now insert the new grants
|
||||
if($success)
|
||||
{
|
||||
foreach($grants_data as $permission_id)
|
||||
{
|
||||
$success = $this->db->insert('grants',
|
||||
array(
|
||||
'permission_id'=>$permission_id,
|
||||
'person_id'=>$employee_id));
|
||||
$success = $this->db->insert('grants', array('permission_id' => $permission_id, 'person_id' => $employee_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ class Giftcard extends CI_Model
|
||||
|
||||
$this->db->where('giftcard_id', $giftcard_id);
|
||||
|
||||
return $this->db->update('giftcards',$giftcard_data);
|
||||
return $this->db->update('giftcards', $giftcard_data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,18 +3,19 @@ class Inventory extends CI_Model
|
||||
{
|
||||
function insert($inventory_data)
|
||||
{
|
||||
return $this->db->insert('inventory',$inventory_data);
|
||||
return $this->db->insert('inventory', $inventory_data);
|
||||
}
|
||||
|
||||
function get_inventory_data_for_item($item_id, $location_id=false)
|
||||
{
|
||||
$this->db->from('inventory');
|
||||
$this->db->where('trans_items',$item_id);
|
||||
$this->db->where('trans_items', $item_id);
|
||||
if($location_id != false)
|
||||
{
|
||||
$this->db->where('trans_location',$location_id);
|
||||
$this->db->where('trans_location', $location_id);
|
||||
}
|
||||
$this->db->order_by("trans_date", "desc");
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +223,10 @@ class Item extends CI_Model
|
||||
if($this->db->insert('items', $item_data))
|
||||
{
|
||||
$item_data['item_id'] = $this->db->insert_id();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Item_kit_items extends CI_Model
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
return true;
|
||||
return $this->db->trans_status();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,11 +15,7 @@ class Item_quantity extends CI_Model
|
||||
{
|
||||
if (!$this->exists($item_id, $location_id))
|
||||
{
|
||||
if($this->db->insert('item_quantities', $location_detail))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $this->db->insert('item_quantities', $location_detail);
|
||||
}
|
||||
|
||||
$this->db->where('item_id', $item_id);
|
||||
|
||||
@@ -25,10 +25,11 @@ class Item_taxes extends CI_Model
|
||||
foreach ($items_taxes_data as $row)
|
||||
{
|
||||
$row['item_id'] = $item_id;
|
||||
$result &= $this->db->insert('items_taxes',$row);
|
||||
$result &= $this->db->insert('items_taxes', $row);
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ class Person extends CI_Model
|
||||
{
|
||||
if (!$person_id or !$this->exists($person_id))
|
||||
{
|
||||
if ($this->db->insert('people',$person_data))
|
||||
if ($this->db->insert('people', $person_data))
|
||||
{
|
||||
$person_data['person_id']=$this->db->insert_id();
|
||||
$person_data['person_id'] = $this->db->insert_id();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class Receiving extends CI_Model
|
||||
//Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->trans_start();
|
||||
|
||||
$this->db->insert('receivings',$receivings_data);
|
||||
$this->db->insert('receivings', $receivings_data);
|
||||
$receiving_id = $this->db->insert_id();
|
||||
|
||||
foreach($items as $line=>$item)
|
||||
|
||||
@@ -310,7 +310,7 @@ class Sale extends CI_Model
|
||||
'payment_type' => $payment['payment_type'],
|
||||
'payment_amount'=> $payment['payment_amount']
|
||||
);
|
||||
$this->db->insert('sales_payments',$sales_payments_data);
|
||||
$this->db->insert('sales_payments', $sales_payments_data);
|
||||
}
|
||||
|
||||
foreach($items as $line=>$item)
|
||||
@@ -330,7 +330,7 @@ class Sale extends CI_Model
|
||||
'item_location' => $item['item_location']
|
||||
);
|
||||
|
||||
$this->db->insert('sales_items',$sales_items_data);
|
||||
$this->db->insert('sales_items', $sales_items_data);
|
||||
|
||||
// Update stock quantity
|
||||
$item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']);
|
||||
|
||||
@@ -63,7 +63,7 @@ class Sale_suspended extends CI_Model
|
||||
//Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->trans_start();
|
||||
|
||||
$this->db->insert('sales_suspended',$sales_data);
|
||||
$this->db->insert('sales_suspended', $sales_data);
|
||||
$sale_id = $this->db->insert_id();
|
||||
|
||||
foreach($payments as $payment_id=>$payment)
|
||||
@@ -74,7 +74,7 @@ class Sale_suspended extends CI_Model
|
||||
'payment_type'=>$payment['payment_type'],
|
||||
'payment_amount'=>$payment['payment_amount']
|
||||
);
|
||||
$this->db->insert('sales_suspended_payments',$sales_payments_data);
|
||||
$this->db->insert('sales_suspended_payments', $sales_payments_data);
|
||||
}
|
||||
|
||||
foreach($items as $line=>$item)
|
||||
@@ -95,7 +95,7 @@ class Sale_suspended extends CI_Model
|
||||
'item_location'=>$item['item_location']
|
||||
);
|
||||
|
||||
$this->db->insert('sales_suspended_items',$sales_items_data);
|
||||
$this->db->insert('sales_suspended_items', $sales_items_data);
|
||||
|
||||
$customer = $this->Customer->get_info($customer_id);
|
||||
if ($customer_id == -1 or $customer->taxable)
|
||||
|
||||
@@ -85,11 +85,12 @@ class Stock_location extends CI_Model
|
||||
function save(&$location_data,$location_id)
|
||||
{
|
||||
$location_name = $location_data['location_name'];
|
||||
|
||||
if (!$this->exists($location_name))
|
||||
{
|
||||
$this->db->trans_start();
|
||||
$location_data = array('location_name'=>$location_name,'deleted'=>0);
|
||||
$this->db->insert('stock_locations',$location_data);
|
||||
$location_data = array('location_name'=>$location_name, 'deleted'=>0);
|
||||
$this->db->insert('stock_locations', $location_data);
|
||||
$location_id = $this->db->insert_id();
|
||||
|
||||
$this->_insert_new_permission('items', $location_id, $location_name);
|
||||
@@ -105,10 +106,13 @@ class Stock_location extends CI_Model
|
||||
$this->db->insert('item_quantities', $quantity_data);
|
||||
}
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $this->db->trans_status();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->where('location_id', $location_id);
|
||||
|
||||
return $this->db->update('stock_locations',$location_data);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +121,7 @@ class Stock_location extends CI_Model
|
||||
{
|
||||
// insert new permission for stock location
|
||||
$permission_id = $module."_".$location_name;
|
||||
$permission_data = array('permission_id'=>$permission_id,'module_id'=>$module,'location_id' => $location_id);
|
||||
$permission_data = array('permission_id'=>$permission_id, 'module_id'=>$module, 'location_id' => $location_id);
|
||||
$this->db->insert('permissions', $permission_data);
|
||||
|
||||
// insert grants for new permission
|
||||
@@ -127,7 +131,6 @@ class Stock_location extends CI_Model
|
||||
$grants_data = array('permission_id' => $permission_id, 'person_id' => $employee['person_id']);
|
||||
$this->db->insert('grants', $grants_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -84,7 +84,8 @@ class Supplier extends Person
|
||||
$this->db->join('people', 'people.person_id = suppliers.person_id');
|
||||
$this->db->where_in('suppliers.person_id',$suppliers_ids);
|
||||
$this->db->order_by("last_name", "asc");
|
||||
return $this->db->get();
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -93,6 +94,7 @@ class Supplier extends Person
|
||||
function save_supplier(&$person_data, &$supplier_data,$supplier_id=false)
|
||||
{
|
||||
$success=false;
|
||||
|
||||
//Run these queries as a transaction, we want to make sure we do all or nothing
|
||||
$this->db->trans_start();
|
||||
|
||||
@@ -101,17 +103,18 @@ class Supplier extends Person
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->where('person_id', $supplier_id);
|
||||
$success = $this->db->update('suppliers',$supplier_data);
|
||||
$success = $this->db->update('suppliers', $supplier_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->db->trans_complete();
|
||||
$this->db->trans_complete();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user