Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Sales_model extends CI_Model {
- function __construct() {
- parent::__construct();
- }
- /*
- return all sales details to display list
- */
- public function get_sales_customer($customer_id){
- return $this->db->select('s.customer_id,s.date,s.reference_no,si.quantity,sum(si.quantity) as total_qty,sum(si.gross_total) as total')
- ->from('sales s')
- ->join('customer c','s.customer_id = c.customer_id','left')
- ->join('sales_items si','si.sales_id = s.sales_id','left')
- ->where('s.customer_id = ',$customer_id)
- ->group_by('s.date')
- ->get()
- ->result();
- }
- public function get_sales_customer_filter($customer_id,$awal,$akhir){
- return $this->db->select('s.customer_id,s.date,s.reference_no,si.quantity,sum(si.quantity) as total_qty,sum(si.gross_total) as total')
- ->from('sales s')
- ->join('customer c','s.customer_id = c.customer_id','left')
- ->join('sales_items si','si.sales_id = s.sales_id','left')
- ->where('s.customer_id = ',$customer_id)
- ->where('date >=',$awal)
- ->where('date <= ',$akhir)
- ->group_by('s.date')
- ->get()
- ->result();
- }
- public function getSales2(){
- return $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id')
- ->from('sales s')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->order_by('s.currentdate', 'DESC');
- }
- public function getSales_detail($sales_id){
- return $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id')
- ->from('sales s')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->where('s.sales_id = ',$sales_id)
- ->order_by('s.currentdate', 'DESC');
- }
- public function get_sales_line($sales_id){
- return $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id,products.name as nama_produk,si.quantity,products.unit,si.price,si.tax,si.gross_total')
- ->from('sales s')
- ->join('sales_items si', 'si.sales_id=s.sales_id', 'left')
- ->join('products', 'products.product_id=si.product_id', 'left')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->where('products.quantity >=', 'si.quantity')
- ->group_by('s.sales_id')
- ->order_by('s.currentdate', 'DESC');
- }
- public function getSales($filter) {
- if ($filter != null) {
- if ($filter == "order_ready_to_package") {
- $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id')
- ->from('sales s')
- ->join('sales_items', 'sales_items.sales_id=s.sales_id', 'left')
- ->join('products', 'products.product_id=sales_items.product_id', 'left')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->where('products.quantity >=', 'sales_items.quantity')
- ->group_by('s.sales_id')
- ->order_by('s.currentdate', 'DESC');
- } else {
- $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id')
- ->from('sales s')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->where("s.status_rev", $filter)
- ->order_by('s.currentdate', 'DESC');
- }
- } else {
- $this->db->select('s.*,b.*,c.*,i.*,s.sales_id as sales_id')
- ->from('sales s')
- ->join('biller b', 's.biller_id=b.biller_id', 'left')
- ->join('customer c', 's.customer_id=c.customer_id', 'left')
- ->join('invoice i ', 's.sales_id=i.sales_id', 'left')
- ->order_by('s.currentdate', 'DESC');
- }
- return $this->db->get()->result();
- }
- public function getProducts2() {
- return $this->db->get('products')->result();
- }
- public function getProducts3() {
- return $this->db->get('product_grouping')->result();
- }
- public function getService() {
- return $this->db->get('service')->result();
- }
- /*
- return warehouse detail use drop down
- */
- public function getWarehouse() {
- if ($this->session->userdata('type') == "1") {
- return $this->db->get('warehouse')->result();
- } else {
- $this->db->select('w.*')
- ->from('warehouse w')
- ->join('warehouse_management wm', 'wm.warehouse_id = w.warehouse_id', 'left')
- ->where('wm.user_id', $this->session->userdata('user_id'));
- return $this->db->get()->result();
- }
- }
- /*
- return warehouse details available in warehouse products
- */
- public function getWarehouseProducts() {
- $this->db->select('warehouse.warehouse_id,warehouses_products.product_id,quantity')
- ->from('warehouse')
- ->join('warehouses_products', 'warehouse.warehouse_id = warehouses_products.warehouse_id', 'left');
- return $this->db->get()->result();
- }
- /*
- return biller detail use drop down
- */
- public function getBiller() {
- return $this->db->get('biller')->result();
- }
- public function insert($table,$array)
- {
- return $this->db->insert($table,$array);
- }
- /*
- return customer detail use drop down
- */
- public function getCustomer() {
- return $this->db->get('customer')->result();
- }
- public function getQuatation() {
- return $this->db->get('quotation')->result();
- }
- /*
- return discount detail use drop down
- */
- public function getDiscount() {
- return $this->db->get('discount')->result();
- }
- public function getBonus12() {
- return $this->db->get('bonus_items')->result();
- }
- public function getBonus($product_id) {
- $this->db->select('si.*')
- ->from('bonus_items si')
- ->join('products p', 'si.product = p.product_id', 'left')
- ->where('si.product', $product_id);
- if ($query = $this->db->get()) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- public function getBonus1($product_id) {
- return $this->db->select('p.*, d.id as product_grouping, d.list')
- ->from('products p')
- ->join('product_grouping d', 'd.product_id = p.product_id', 'left')
- ->join('bonus_items bi', 'bi.product = p.product_id','left')
- ->where('p.product_id',$product_id)
- ->get()
- ->result();
- }
- /*
- return tax detail use dynamic table
- */
- public function getTax() {
- return $this->db->get_where('tax', array('delete_status' => 0))->result();
- }
- /*
- generate invoive no
- */
- public function generateInvoiceNo() {
- $query = $this->db->query("SELECT * FROM invoice ORDER BY id DESC LIMIT 1");
- $result = $query->result();
- if ($result == null) {
- $no = sprintf('%06d', intval(1));
- } else {
- foreach ($result as $value) {
- $no = sprintf('%06d', intval($value->id) + 1);
- }
- }
- return "INV-" . $no;
- }
- /*
- generate payment reference no
- */
- public function generateReferenceNo() {
- $query = $this->db->query("SELECT * FROM payment ORDER BY id DESC LIMIT 1");
- $result = $query->result();
- return $result;
- }
- /*
- return last purchase id
- */
- public function createReferenceNo() {
- $query = $this->db->query("SELECT * FROM sales ORDER BY sales_id DESC LIMIT 1");
- $result = $query->result();
- return $result;
- }
- /*
- return sales record
- */
- public function getRecord($id) {
- $sql = "select * from sales where sales_id = ?";
- if ($query = $this->db->query($sql, array($id))) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- /*
- add new sales record in database
- */
- public function addModel($data, $invoice) {
- if ($this->db->insert('sales', $data)) {
- $insert_id = $this->db->insert_id();
- $invoice['sales_id'] = $insert_id;
- $this->db->insert('invoice', $invoice);
- return $insert_id;
- } else {
- echo $this->db->last_query();
- print_r($this->db->error());
- return FALSE;
- }
- }
- public function getTerminSalesId($id) {
- $sql = "select * from sales_termin where sales_id = ?";
- return $this->db->query($sql, array($id))->result();
- }
- public function addTerminModel($data) {
- if ($this->db->insert('sales_termin', $data)) {
- $insert_id = $this->db->insert_id();
- return $insert_id;
- } else {
- return FALSE;
- }
- echo $this->db->last_query();
- }
- public function deleteTerminModel($id) {
- $sql = "delete from sales_termin where sales_id = ?";
- if ($this->db->query($sql, array($id))) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- public function getCurrencyId($id) {
- $sql = "select * from currency where kurs_id = ?";
- return $this->db->query($sql, array($id))->result();
- }
- /*
- return discount detail use drop down when discount change
- */
- public function getDiscountAjax($id) {
- $sql = "select * from discount where discount_id = ?";
- return $this->db->query($sql, array($id))->result();
- }
- /*
- check product available in sales or not
- */
- public function checkProductInSales($sales_id, $product_id) {
- $sql = "select * from sales_items where sales_id = ? AND product_id = ?";
- if ($quantity = $this->db->query($sql, array($sales_id, $product_id))->num_rows() > 0) {
- $sql = "select * from sales_items where sales_id = ? AND product_id = ?";
- $quantity = $this->db->query($sql, array($sales_id, $product_id));
- return $quantity->row()->quantity;
- } else {
- return false;
- }
- }
- /*
- update quantity in product table
- */
- public function updateQuantity($sales_id, $product_id, $warehouse_id, $quantity, $old_quantity, $data) {
- $where = "sales_id = $sales_id AND product_id = $product_id";
- $this->db->where($where);
- $this->db->update('sales_items', $data);
- $sql = "select * from warehouses_products where warehouse_id = ? AND product_id = ?";
- $warehouse_quantity = $this->db->query($sql, array($warehouse_id, $product_id))->row()->quantity;
- $wquantity = $warehouse_quantity - $quantity + $old_quantity;
- $sql = "update warehouses_products set quantity = ? where warehouse_id = ? AND product_id = ?";
- $this->db->query($sql, array($wquantity, $warehouse_id, $product_id));
- $sql = "select * from products where product_id = ?";
- $product_quantity = $this->db->query($sql, array($product_id))->row()->quantity;
- $pquantity = $product_quantity - $quantity + $old_quantity;
- $sql = "update products set quantity = ? where product_id = ?";
- $this->db->query($sql, array($pquantity, $product_id));
- }
- /*
- check product available in warehouse or not
- */
- public function checkProductInWarehouse($product_id, $quantity, $warehouse_id) {
- $sql = "select * from warehouses_products where product_id = ? AND warehouse_id = ?";
- $query = $this->db->query($sql, array($product_id, $warehouse_id));
- if ($query->num_rows() > 0) {
- $warehouse_quantity = $query->row()->quantity;
- if ($warehouse_quantity >= $quantity) {
- $wquantity = $warehouse_quantity - $quantity;
- $sql = "update warehouses_products set quantity = ? where product_id = ? AND warehouse_id = ?";
- $this->db->query($sql, array($wquantity, $product_id, $warehouse_id));
- $sql = "select * from products where product_id = ?";
- $product_quantity = $this->db->query($sql, array($product_id))->row()->quantity;
- $pquantity = $product_quantity - $quantity;
- $sql = "update products set quantity = ? where product_id = ?";
- $this->db->query($sql, array($pquantity, $product_id));
- }
- }
- }
- /*
- add newly sales items record in database
- */
- public function addSalesItem($data) {
- $sql = "insert into sales_items (product_id,quantity,price,gross_total,discount_id,discount_value,discount,tax_id,tax_value,tax,sales_id) values (?,?,?,?,?,?,?,?,?,?,?)";
- if ($this->db->query($sql, $data)) {
- return true;
- } else {
- echo $this->db->last_query();
- print_r($this->db->error());
- return false;
- }
- }
- public function addSalesServiceItem($data) {
- $sql = "insert into salesservice_items (service_id,quantity,price,gross_total,discount_id,discount_value,discount,sales_id) values (?,?,?,?,?,?,?,?)";
- if ($this->db->query($sql, $data)) {
- return true;
- } else {
- return false;
- }
- }
- /*
- return sales item data when edited
- */
- public function getSalesItems($sales_id) {
- $this->db->select('si.*,sum(si.quantity) as quantity, wp.quantity as warehouses_quantity,p.product_id,p.code,p.name,si.price as qprice,p.unit,p.price,p.cost,p.item_namebyp')
- ->from('sales_items si')
- ->join('products p', 'si.product_id = p.product_id', 'left')
- ->join('warehouses_products wp', 'wp.product_id = p.product_id', 'left')
- ->where('si.sales_id', $sales_id)
- ->group_by('si.product_id');
- if ($query = $this->db->get()) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- public function getServiceItems($sales_id) {
- $this->db->select('si.*,p.service_id,p.code,p.service_title,p.service_spec,p.price as pprice,p.cost')
- ->from('salesservice_items si')
- ->join('service p', 'si.service_id = p.service_id', 'left')
- ->where('si.sales_id', $sales_id);
- if ($query = $this->db->get()) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- /*
- return single product to add dynamic table
- */
- public function getProduct($product_id, $warehouse_id) {
- return $this->db->select('p.product_id,p.code,p.hsn_sac_code,p.unit,p.name,p.size,p.cost,p.price,p.alert_quantity,p.image,p.category_id,p.subcategory_id,p.tax_id,wp.quantity,wp.warehouse_id,t.tax_value')
- ->from('products p')
- ->join('warehouses_products wp', 'p.product_id = wp.product_id', 'left')
- ->join('tax t', 'p.tax_id = t.tax_id', 'left')
- ->where('wp.warehouse_id', $warehouse_id)
- ->where('wp.product_id', $product_id)
- ->get()
- ->result();
- }
- public function getServicetable($service_id) {
- return $this->db->select('p.code,p.service_id,p.service_title,p.cost,p.price,p.category_id,p.subcategory_id,p.tax_id,t.tax_value')
- ->from('service p')
- ->join('tax t', 'p.tax_id = t.tax_id', 'left')
- ->where('p.service_id', $service_id)
- ->get()
- ->result();
- }
- public function getProducts212($product_id) {
- return $this->db->select('p.product_id,p.code,p.item_namebyp,p.unit,p.name,p.size,p.cost,p.price,p.alert_quantity,p.quantity qty, p.quantity quantity, p.image,p.category_id,p.subcategory_id,p.tax_id,wp.quantity wquantity,wp.warehouse_id,t.tax_value')
- ->from('products p')
- ->join('warehouses_products wp', 'p.product_id = wp.product_id', 'left')
- ->join('tax t', 'p.tax_id = t.tax_id', 'left')
- ->where('wp.product_id', $product_id)
- ->get()
- ->result();
- }
- public function getProducts21($product_id) {
- return $this->db->select('p.*, d.id as product_grouping, d.list')
- ->from('products p')
- ->join('product_grouping d', 'd.product_id = p.product_id', 'left')
- ->join('bonus_items bi', 'bi.product = p.product_id','left')
- ->where('p.product_id',$product_id)
- ->get()
- ->result();
- }
- /*
- return product list to add product
- */
- public function getProducts() {
- return $this->db->select('p.*')
- ->from('products p')
- ->join('warehouses_products wp', 'p.product_id = wp.product_id', 'left')
- // ->where('wp.warehouse_id',$warehouse_id)
- // ->where('wp.quantity > 0')
- ->get()
- ->result();
- }
- public function getProducts222($warehouse_id) {
- return $this->db->select('p.*')
- ->from('products p')
- ->join('warehouses_products wp', 'p.product_id = wp.product_id', 'left')
- ->where('wp.warehouse_id', $warehouse_id)
- ->where('wp.quantity > 0')
- ->get()
- ->result();
- }
- /*
- return product list category to add product
- public function getProductsCategory($warehouse_id,$category_id){
- $category_id = 1;
- return $this->db->select('p.*')
- ->from('products p')
- ->join('warehouses_products wp', 'p.product_id = wp.product_id', 'left')
- ->join('category_product c', 'c.product_id = p.product_id', 'left')
- ->where('wp.warehouse_id', $warehouse_id)
- ->where('wp.quantity > 0')
- ->where('c.category_id', $category_id)
- ->get()
- ->result();
- }
- /*
- save edited record in database
- */
- public function getPartNumber($brand_id) {
- return $this->db->select('code, name')
- ->from('products')
- ->where('brand_id', $brand_id)
- ->group_by('code')
- ->get()
- ->result();
- }
- public function getCodeProduct($code) {
- return $this->db->select('product_id, name')
- ->from('products')
- ->where('code', $code)
- ->get()
- ->result();
- }
- public function editModel($id, $data) {
- /* $data['sales_id'] = $id;
- $sql = "update sales set date = ?,reference_no = ?,warehouse_id = ?,customer_id = ?,biller_id = ?,total = ?,discount_value=?,tax_value=?,note = ?,shipping_city_id = ?,shipping_state_id= ?,shipping_country_id =?,shipping_address =?,shipping_charge =?,internal_note = ?,mode_of_transport=?,transporter_name=?,transporter_code=?,vehicle_regn_no=?,user = ? where sales_id = ?";
- if($this->db->query($sql,$data)){ */
- $this->db->where('sales_id', $id);
- if ($this->db->update('sales', $data)) {
- return true;
- } else {
- return false;
- }
- }
- /*
- delete old purchase item when edit purchse
- */
- public function deleteSalesItems($sales_id, $product_id, $warehouse_id, $old_warehouse_id) {
- $sql = "select * from sales_items where sales_id = ? AND product_id = ?";
- $delete_quantity = $this->db->query($sql, array($sales_id, $product_id))->row()->quantity;
- $sql = "select * from warehouses_products where warehouse_id = ? AND product_id = ?";
- $warehouse_quantity = $this->db->query($sql, array($warehouse_id, $product_id))->row()->quantity;
- $wquantity = $warehouse_quantity + $delete_quantity;
- $sql = "update warehouses_products set quantity = ? where warehouse_id = ? AND product_id = ?";
- $this->db->query($sql, array($wquantity, $warehouse_id, $product_id));
- $sql = "select * from products where product_id = ?";
- $product_quantity = $this->db->query($sql, array($product_id))->row()->quantity;
- $pquantity = $product_quantity + $delete_quantity;
- $sql = "update products set quantity = ? where product_id = ?";
- $this->db->query($sql, array($pquantity, $product_id));
- $sql = "delete from sales_items where sales_id = ? AND product_id = ?";
- if ($this->db->query($sql, array($sales_id, $product_id))) {
- return true;
- } else {
- return false;
- }
- }
- public function deleteSalesServiceItems($sales_id, $service_id) {
- $sql = "select * from service_items where sales_id = ? AND service_id = ?";
- $delete_quantity = $this->db->query($sql, array($sales_id, $service_id))->row()->quantity;
- $sql = "delete from service_items where sales_id = ? AND service_id = ?";
- if ($this->db->query($sql, array($sales_id, $service_id))) {
- return true;
- } else {
- return false;
- }
- }
- public function deleteSalesItemsAll($sales_id) {
- $sql = "delete from sales_items where sales_id = ?";
- if ($this->db->query($sql, array($sales_id))) {
- return true;
- } else {
- return false;
- }
- }
- public function deleteSalesAdditionalAll($sales_id) {
- $sql = "delete from sales_additional_items where sales_id = ?";
- if ($this->db->query($sql, array($sales_id))) {
- return true;
- } else {
- return false;
- }
- }
- public function deleteSalesServiceItemsAll($sales_id) {
- $sql = "delete from salesservice_items where sales_id = ?";
- if ($this->db->query($sql, array($sales_id))) {
- return true;
- } else {
- return false;
- }
- }
- /*
- when warehouse change selected items is delete this function
- */
- public function changeWarehouseDeleteSalesItems($sales_id, $product_id, $warehouse_id, $old_warehouse_id) {
- $sql = "select * from sales_items where sales_id = ? AND product_id = ?";
- $delete_quantity = $this->db->query($sql, array($sales_id, $product_id))->row()->quantity;
- $sql = "select * from warehouses_products where warehouse_id = ? AND product_id = ?";
- $warehouse_quantity = $this->db->query($sql, array($old_warehouse_id, $product_id))->row()->quantity;
- $wquantity = $warehouse_quantity + $delete_quantity;
- $sql = "update warehouses_products set quantity = ? where warehouse_id = ? AND product_id = ?";
- $this->db->query($sql, array($wquantity, $old_warehouse_id, $product_id));
- $sql = "select * from products where product_id = ?";
- $product_quantity = $this->db->query($sql, array($product_id))->row()->quantity;
- $pquantity = $product_quantity + $delete_quantity;
- $sql = "update products set quantity = ? where product_id = ?";
- $this->db->query($sql, array($pquantity, $product_id));
- $sql = "delete from sales_items where sales_id = ? AND product_id = ?";
- if ($this->db->query($sql, array($sales_id, $product_id))) {
- return true;
- } else {
- return false;
- }
- }
- /*
- delete sales record in database
- */
- public function deleteModel($id) {
- $sql = "delete from sales where sales_id = ?";
- if ($this->db->query($sql, array($id))) {
- $sql = "delete from sales_items where sales_id = ?";
- if ($this->db->query($sql, array($id))) {
- return TRUE;
- }
- } else {
- return FALSE;
- }
- }
- /*
- return all details of sales
- */
- public function getSalesData() {
- return $this->db->get('sales')->result();
- }
- /*
- return all details of purchase
- */
- public function getPurchaseData() {
- return $this->db->get('purchases')->result();
- }
- /*
- return sales data for calendar
- */
- public function getCalendarData() {
- return $this->db->get('sales')->result();
- }
- /*
- return sales details
- */
- public function getDetails($id) {
- $this->db->select('s.*,
- i.invoice_no,
- i.invoice_date,
- i.paid_amount,
- c.customer_name,
- c.address as customer_address,
- c.mobile as customer_mobile,
- c.email as customer_email,
- c.company_name as customer_company,
- c.postal_code as customer_postal_code,
- c.gstid as customer_gstid,
- c.state_id as customer_state_id,
- c.tan_no as tan_no,
- c.cst_reg_no as cst_reg_no,
- c.excise_reg_no as excise_reg_no,
- c.lbt_reg_no as lbt_reg_no,
- c.servicetax_reg_no as servicetax_reg_no,
- ct.name as customer_city,
- c.country_id as customer_country,
- b.biller_name,
- b.address as biller_address,
- cb.name as biller_city,
- co.name as biller_country,
- b.mobile as biller_mobile,
- b.email as biller_email,
- b.company_name as biller_company,
- b.fax as biller_fax,
- b.telephone as biller_telephone,
- b.gstid as biller_gstid,
- b.state_id as biller_state_id,
- w.warehouse_name,
- br.address as branch_address,
- br.city as branch_city,
- u.first_name,
- k.kurs,
- k.nominal,
- k.symbol,
- u.last_name')
- ->from('sales s')
- ->join('kurs k', 'k.kurs_id = s.kurs_id', 'left')
- ->join('invoice i', 'i.sales_id = s.sales_id', 'left')
- ->join('customer c', 's.customer_id = c.customer_id', 'left')
- ->join('cities ct', 'c.city_id = ct.id', 'left')
- ->join('states cs', 'c.state_id = cs.id', 'left')
- ->join('biller b', 's.biller_id = b.biller_id', 'left')
- ->join('cities cb', 'b.city_id = cb.id', 'left')
- ->join('states bs', 'b.state_id = bs.id', 'left')
- ->join('countries co', 'b.country_id = co.id', 'left')
- ->join('warehouse w', 's.warehouse_id = w.warehouse_id', 'left')
- ->join('branch br', 'w.branch_id = br.branch_id', 'left')
- ->join('users u', 's.user = u.id', 'left')
- ->where('s.sales_id', $id);
- if ($query = $this->db->get()) {
- return $query->result();
- } else {
- return FALSE;
- }
- }
- public function checkInvoice($id) {
- return $this->db->select('s.sales_id')
- ->from('sales s')
- ->join('invoice i', 'i.sales_id = s.sales_id', 'left')
- ->where('s.sales_id', $id)
- ->get()
- ->row();
- }
- /*
- return details for payment
- */
- public function getDetailsPayment($id) {
- return $this->db->select('s.*,
- c.customer_name,
- c.address as customer_address,
- c.mobile as customer_mobile,
- c.email as customer_email,
- c.gstid as customer_gstid,
- ct.name as customer_city,
- cco.name as customer_country,
- b.biller_name,
- b.address as biller_address,
- cb.name as biller_city,
- co.name as biller_country,
- b.mobile as biller_mobile,
- b.email as biller_email,
- b.gstid as biller_gstid,
- w.warehouse_name,
- br.address as branch_address,
- br.city as branch_city,
- u.first_name,
- u.last_name')
- ->from('sales s')
- ->join('customer c', 's.customer_id = c.customer_id', 'left')
- ->join('cities ct', 'c.city_id = ct.id', 'left')
- ->join('countries cco', 'c.country_id = cco.id', 'left')
- ->join('biller b', 's.biller_id = b.biller_id', 'left')
- ->join('cities cb', 'b.city_id = cb.id', 'left')
- ->join('countries co', 'b.country_id = co.id', 'left')
- ->join('warehouse w', 's.warehouse_id = w.warehouse_id', 'left')
- ->join('branch br', 'w.branch_id = br.branch_id', 'left')
- ->join('users u', 's.user = u.id', 'left')
- ->where('s.sales_id', $id)
- ->get()
- ->result();
- }
- /*
- return sales item details
- */
- public function getItems($id) {
- return $this->db->select('si.*, si.quantity as quantity_item, pr.quantity as quantity_product, pr.name, pr.code,pr.unit,pr.unit,pr.item_namebyp, pr.quantity as pquantity, pr.p_detail as detail, pr.image as image, d.id as product_grouping, d.list')
- ->from('sales_items si')
- ->join('sales s', 'si.sales_id = s.sales_id', 'left')
- ->join('products pr', 'si.product_id = pr.product_id', 'left')
- ->join('product_grouping d', 'd.product_id = pr.product_id', 'left')
- ->where('si.sales_id', $id)
- ->order_by('si.id asc')
- ->get()
- ->result();
- }
- public function getAdditional($id) {
- return $this->db->select('si.*, si.price as qprice,si.quantity as quantity_item, pr.quantity as quantity_product, pr.name,pr.code,pr.unit,pr.unit,pr.item_namebyp, pr.quantity as pquantity, pr.p_detail as detail, pr.image as image, d.id as product_grouping, d.list')
- ->from('sales_additional_items si')
- ->join('sales s', 'si.sales_id = s.sales_id', 'left')
- ->join('products pr', 'si.product_id = pr.product_id', 'left')
- ->join('product_grouping d', 'd.product_id = pr.product_id', 'left')
- ->where('si.sales_id', $id)
- ->order_by('si.id asc')
- ->get()
- ->result();
- }
- /*
- return supplier details
- */
- public function getCustomerEmail($id) {
- return $this->db->select('*')
- ->from('sales s')
- ->join('customer c', 'c.customer_id = s.customer_id', 'left')
- ->where('s.sales_id', $id)
- ->get()
- ->result();
- }
- /*
- add payment details
- */
- public function addPayment($data) {
- $sql = "INSERT INTO payment (sales_id,date,reference_no,amount,paying_by,bank_name,cheque_no,description) VALUES (?,?,?,?,?,?,?,?)";
- if ($this->db->query($sql, $data)) {
- /* if($this->db->insert('payment',$data)){ */
- $this->db->where('sales_id', $data['sales_id']);
- $this->db->update('invoice', array("paid_amount" => $data['amount']));
- return true;
- } else {
- return false;
- }
- }
- /*
- */
- public function invoice() {
- return $this->db->select('*')
- ->from('invoice i')
- ->join('sales s', 's.sales_id = i.sales_id', 'left')
- ->get()
- ->result();
- }
- /*
- return SMTP server Data
- */
- public function getSmtpSetup() {
- return $this->db->get('email_setup')->row();
- }
- /*
- return customer data for shipping address
- */
- public function getCustomerData($id) {
- $this->db->where('customer_id', $id);
- return $this->db->get_where('customer')->row();
- }
- /*
- return country
- */
- public function getCountry() {
- return $this->db->get('countries')->result();
- }
- /*
- return state
- */
- public function getState($id) {
- return $this->db->select('s.*')
- ->from('states s')
- ->join('countries c', 'c.id = s.country_id', 'left')
- ->where('s.country_id', $id)
- ->get()
- ->result();
- }
- /*
- return city
- */
- public function getCity($id) {
- return $this->db->select('c.*')
- ->from('cities c')
- ->join('states s', 's.id = c.state_id', 'left')
- ->where('c.state_id', $id)
- ->get()
- ->result();
- }
- // choerul
- // Generate Autonumber Revision
- public function generateAutoNumberRevision($id) {
- $sql = "SELECT
- MAX(po_new) AS po_new
- FROM
- sales
- WHERE
- po = (
- SELECT po FROM sales
- WHERE sales_id = " . $id . ")";
- $query = $this->db->query($sql);
- $counter = "-R1";
- if ($query->num_rows() > 0 && $query->row()->po_new != "") {
- $new_trans_number = $query->row()->po_new;
- ++$new_trans_number;
- } else {
- $sql_reference = "SELECT po FROM sales WHERE sales_id = " . $id;
- $query_reference = $this->db->query($sql_reference);
- $transaction_number = $query_reference->row()->po;
- $new_trans_number = $transaction_number . $counter;
- }
- return $new_trans_number;
- }
- public function getSalesByProduct(){
- return $this->db->select('s.*,si.*,si.quantity as siqty, si.price as siprc, p.*')
- ->from('sales s')
- ->join('sales_items si', 'si.sales_id = s.sales_id', 'left')
- ->join('products p', 'p.product_id = si.product_id', 'left')
- ->group_by('si.product_id')
- ->get()
- ->result();
- }
- }
- ?>
RAW Paste Data