My problem is, i am getting the datas which is present in all the 3 tables.But i want to display the data which is not present in any one of the table(that is empty space or 0 is printed on that item if it's not present in anyone of the table)..i googled and found that it can be done by fullouter join but i don't know how to use it.. Controller Code:
public function St_statement(){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');
$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');
$query = $this->db->get();
$data['query'] = $query;
$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');
$query = $this->db->get();
$data['query'] = $query;
$this->load->view('Inventory/St_Stmt', $data);
}
}
}
$query = "SELECT Item
, pgroup
, SUM( Stock
) AS Stock
, SUM( quantity
) AS quantity
, SUM( Qty
) AS Qty
FROM opstock
LEFT JOIN purchaseitem
ON purchaseitem
. Prdtname
= opstock
. Item
LEFT JOIN salesitem
ON salesitem
. Prdtname
= purchaseitem
. Prdtname
LEFT JOIN itemmaster
ON itemmaster
. itemname
= purchaseitem
. Prdtname
LEFT JOIN pgroup
ON pgroup
. pgroupid
= itemmaster
. catcode
WHERE billdate
>= '".$newDate."' AND billdate
<= '".$newDate2."' AND billdte
>= '".$newDate."' AND billdte
<= '".$newDate2."' GROUP BY Item
ORDER BY pgroup
ASC UNION SELECT Item
, pgroup
, SUM( Stock
) AS Stock
, SUM( quantity
) AS quantity
, SUM( Qty
) AS Qty
FROM opstock
RIGHT JOIN purchaseitem
ON purchaseitem
. Prdtname
= opstock
. Item
LEFT JOIN salesitem
ON salesitem
. Prdtname
= purchaseitem
. Prdtname
LEFT JOIN itemmaster
ON itemmaster
. itemname
= purchaseitem
. Prdtname
LEFT JOIN pgroup
ON pgroup
. pgroupid
= itemmaster
. catcode
WHERE billdate
>= '".$newDate."' AND billdate
<= '".$newDate2."' AN D billdte
>= '".$newDate."' AND billdte
<= '".$newDate2."' GROUP BY Item
ORDER BY pgroup
ASC SELECT Item
, pgroup
, SUM( Stock
) AS Stock
, SUM( quantity
) AS quantity
, SUM( Qty
) AS Qty
FROM opstock
LEFT JOIN purchaseitem
ON purchaseitem
. Prdtname
= opstock
. Item
RIGHT JOIN salesitem
ON salesitem
. Prdtname
= purchaseitem
. Prdtname
LEFT JOIN itemmaster
ON itemmaster
. itemname
= purchaseitem
. Prdtname
LEFT JOIN pgroup
ON pgroup
. pgroupid
= itemmaster
. catcode
WHERE billdate
>= '".$newDate."' AND billdate
<= '".$newDate2."' AND billdte
>= '".$newDate."' AND billdte
<= '".$newDate2."' GROUP BY Item
ORDER BY pgroup
ASC UNION SELECT Item
, pgroup
, SUM( Stock
) AS Stock
, SUM( quantity
) AS quantity
, SUM( Qty
) AS Qty
FROM opstock
LEFT JOIN purchaseitem
ON purchaseitem
. Prdtname
= opstock
. Item
LEFT JOIN salesitem
ON salesitem
. Prdtname
= purchaseitem
. Prdtname
RIGHT JOIN itemmaster
ON itemmaster
. itemname
= purchaseitem
. Prdtname
LEFT JOIN pgroup
ON pgroup
. pgroupid
= itemmaster
. catcode
WHERE billdate
>= '".$newDate."' AND billdate
<= '".$newDate2."' AND billdte
>= '".$newDate."' AND billdte
<= '".$newDate2."' GROUP BY Item
ORDER BY pgroup
ASC";
$query = $this->db->query($query);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.