Files
opensourcepos/application/models/receiving.php
jekkos-t520 6c8cea9846 Merge branch 'master' of https://github.com/pappastech/ospos into ospos
Fixed customer + supplier search box width + spinner position under linux
Fonts set to relative browser size
Dutch language files updated (missing labels added)

Conflicts:
	WHATS_NEW.txt
	application/config/autoload.php
	application/config/config.php
	application/config/migration.php
	application/config/routes.php
	application/controllers/giftcards.php
	application/controllers/items.php
	application/controllers/person_controller.php
	application/controllers/receivings.php
	application/controllers/reports.php
	application/controllers/sales.php
	application/controllers/suppliers.php
	application/helpers/table_helper.php
	application/hooks/load_config.php
	application/language/english/common_lang.php
	application/language/english/config_lang.php
	application/language/english/customers_lang.php
	application/language/english/employees_lang.php
	application/language/english/error_lang.php
	application/language/english/giftcards_lang.php
	application/language/english/index.html
	application/language/english/items_lang.php
	application/language/english/login_lang.php
	application/language/english/module_lang.php
	application/language/english/receivings_lang.php
	application/language/english/reports_lang.php
	application/language/english/sales_lang.php
	application/language/english/suppliers_lang.php
	application/libraries/Receiving_lib.php
	application/libraries/ofc-library/JSON.php
	application/libraries/ofc-library/README.txt
	application/libraries/ofc-library/dot_base.php
	application/libraries/ofc-library/json_format.php
	application/libraries/ofc-library/ofc_area_base.php
	application/libraries/ofc-library/ofc_area_hollow.php
	application/libraries/ofc-library/ofc_area_line.php
	application/libraries/ofc-library/ofc_arrow.php
	application/libraries/ofc-library/ofc_bar.php
	application/libraries/ofc-library/ofc_bar_3d.php
	application/libraries/ofc-library/ofc_bar_base.php
	application/libraries/ofc-library/ofc_bar_filled.php
	application/libraries/ofc-library/ofc_bar_glass.php
	application/libraries/ofc-library/ofc_bar_sketch.php
	application/libraries/ofc-library/ofc_bar_stack.php
	application/libraries/ofc-library/ofc_candle.php
	application/libraries/ofc-library/ofc_hbar.php
	application/libraries/ofc-library/ofc_line.php
	application/libraries/ofc-library/ofc_line_base.php
	application/libraries/ofc-library/ofc_line_dot.php
	application/libraries/ofc-library/ofc_line_hollow.php
	application/libraries/ofc-library/ofc_line_style.php
	application/libraries/ofc-library/ofc_menu.php
	application/libraries/ofc-library/ofc_pie.php
	application/libraries/ofc-library/ofc_radar_axis.php
	application/libraries/ofc-library/ofc_radar_axis_labels.php
	application/libraries/ofc-library/ofc_radar_spoke_labels.php
	application/libraries/ofc-library/ofc_scatter.php
	application/libraries/ofc-library/ofc_scatter_line.php
	application/libraries/ofc-library/ofc_shape.php
	application/libraries/ofc-library/ofc_sugar.php
	application/libraries/ofc-library/ofc_tags.php
	application/libraries/ofc-library/ofc_title.php
	application/libraries/ofc-library/ofc_tooltip.php
	application/libraries/ofc-library/ofc_x_axis.php
	application/libraries/ofc-library/ofc_x_axis_label.php
	application/libraries/ofc-library/ofc_x_axis_labels.php
	application/libraries/ofc-library/ofc_x_legend.php
	application/libraries/ofc-library/ofc_y_axis.php
	application/libraries/ofc-library/ofc_y_axis_base.php
	application/libraries/ofc-library/ofc_y_axis_label.php
	application/libraries/ofc-library/ofc_y_axis_labels.php
	application/libraries/ofc-library/ofc_y_axis_right.php
	application/libraries/ofc-library/ofc_y_legend.php
	application/libraries/ofc-library/open-flash-chart-object.php
	application/libraries/ofc-library/open-flash-chart.php
	application/models/giftcard.php
	application/models/item.php
	application/models/person.php
	application/models/receiving.php
	application/models/sale.php
	application/models/supplier.php
	application/views/config.php
	application/views/items/form.php
	application/views/items/form_bulk.php
	application/views/items/manage.php
	application/views/receivings/receiving.php
	application/views/reports/date_input.php
	application/views/reports/listing.php
	application/views/reports/tabular_details.php
	application/views/sales/edit.php
	application/views/sales/register.php
	application/views/suppliers/form.php
	css/reports.css
	css/tables.css
	database/database.sql
	import_items.csv
	index.php
	js/jquery.ajax_queue.js
	js/jquery.metadata.js
	license/license.txt
2014-03-03 22:19:14 +01:00

119 lines
4.0 KiB
PHP

<?php
class Receiving extends CI_Model
{
public function get_info($receiving_id)
{
$this->db->from('receivings');
$this->db->where('receiving_id',$receiving_id);
return $this->db->get();
}
function exists($receiving_id)
{
$this->db->from('receivings');
$this->db->where('receiving_id',$receiving_id);
$query = $this->db->get();
return ($query->num_rows()==1);
}
function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false)
{
if(count($items)==0)
return -1;
$receivings_data = array(
'supplier_id'=> $this->Supplier->exists($supplier_id) ? $supplier_id : null,
'employee_id'=>$employee_id,
'payment_type'=>$payment_type,
'comment'=>$comment
);
//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);
$receiving_id = $this->db->insert_id();
foreach($items as $line=>$item)
{
$cur_item_info = $this->Item->get_info($item['item_id']);
$receivings_items_data = array
(
'receiving_id'=>$receiving_id,
'item_id'=>$item['item_id'],
'line'=>$item['line'],
'description'=>$item['description'],
'serialnumber'=>$item['serialnumber'],
'quantity_purchased'=>$item['quantity'],
'discount_percent'=>$item['discount'],
'item_cost_price' => $cur_item_info->cost_price,
'item_unit_price'=>$item['price']
);
$this->db->insert('receivings_items',$receivings_items_data);
//Update stock quantity
$item_data = array('quantity'=>$cur_item_info->quantity + $item['quantity']);
$this->Item->save($item_data,$item['item_id']);
$qty_recv = $item['quantity'];
$recv_remarks ='RECV '.$receiving_id;
$inv_data = array
(
'trans_date'=>date('Y-m-d H:i:s'),
'trans_items'=>$item['item_id'],
'trans_user'=>$employee_id,
'trans_comment'=>$recv_remarks,
'trans_inventory'=>$qty_recv
);
$this->Inventory->insert($inv_data);
$supplier = $this->Supplier->get_info($supplier_id);
}
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
return -1;
}
return $receiving_id;
}
function get_receiving_items($receiving_id)
{
$this->db->from('receivings_items');
$this->db->where('receiving_id',$receiving_id);
return $this->db->get();
}
function get_supplier($receiving_id)
{
$this->db->from('receivings');
$this->db->where('receiving_id',$receiving_id);
return $this->Supplier->get_info($this->db->get()->row()->supplier_id);
}
//We create a temp table that allows us to do easy report/receiving queries
public function create_receivings_items_temp_table()
{
$this->db->query("CREATE TEMPORARY TABLE ".$this->db->dbprefix('receivings_items_temp')."
(SELECT date(receiving_time) as receiving_date, ".$this->db->dbprefix('receivings_items').".receiving_id, comment,payment_type, employee_id,
".$this->db->dbprefix('items').".item_id, ".$this->db->dbprefix('receivings').".supplier_id, quantity_purchased, item_cost_price, item_unit_price,
discount_percent, (item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) as subtotal,
".$this->db->dbprefix('receivings_items').".line as line, serialnumber, ".$this->db->dbprefix('receivings_items').".description as description,
ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100),2) as total,
(item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100) - (item_cost_price*quantity_purchased) as profit
FROM ".$this->db->dbprefix('receivings_items')."
INNER JOIN ".$this->db->dbprefix('receivings')." ON ".$this->db->dbprefix('receivings_items').'.receiving_id='.$this->db->dbprefix('receivings').'.receiving_id'."
INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('receivings_items').'.item_id='.$this->db->dbprefix('items').'.item_id'."
GROUP BY receiving_id, item_id, line)");
}
}
?>