db->table('sales_order') ->where('sales_order_id', $sales_order_id) ->join('branches as B','B.branch_id = sales_order.branch_id','left') ->join('vehicle as V','V.vehicle_id = sales_order.vehicle_id','left') ->join('client as C','V.client_id = C.client_id','left') ->select('sales_order.*') ->select('B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.contact_1 as company_mobile_no_1,B.contact_2 as company_mobile_no_2,B.gstno as company_gstno') ->select('C.gstnumber as client_gst') ->get() ->getResult(); } public function getSalesOrdersWithProducts($logged_user_branch_id) { // Select required fields from both tables $this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no,SUM(sales_order_product.qty) AS product_qty '); // Join the sales_order_product table based on sales_order_id $this->join('sales_order_product', 'sales_order_product.sales_order_id = sales_order.sales_order_id'); $this->join('vehicle', 'vehicle.vehicle_id = sales_order.vehicle_id'); // Group by sales_order_id to get count of products per sales order $this->groupBy('sales_order.sales_order_id'); // Add condition to fetch only active sales orders $this ->where('sales_order.branch_id',$logged_user_branch_id); $this->orderBy('sales_order.sales_order_id','desc'); // Get the results return $this->findAll(); } public function getSalesOrderProductsForPdf($sales_order_id) { // Select required fields from the sales_order_product table $result = $this->db->table('sales_order_product') ->where('sales_order_product.sales_order_id', $sales_order_id) ->join('products', 'products.product_id = sales_order_product.product_id') ->select('sales_order_product.*, products.product_name, products.per, products.ml,products.hsn_sac') ->get() ->getResult(); // echo "
";
        // print_r($result);die;

    return $result;
}

    
}
?>