Created
August 11, 2015 16:25
-
-
Save rbrahul/38a2421af5c4b706a0fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSumProductPurchaseAmount($product_id){ | |
$CI=&get_instance(); | |
$result=$CI->db->select_sum('amount','total')->get_where('purchase',['product_id'=>$product_id])->row()->total; | |
return $result; | |
} | |
function getSumProductSaleAmount($product_id){ | |
$CI=&get_instance(); | |
$numrows=$CI->db->get_where('sale',['product_id'=>$product_id])->num_rows(); | |
if($numrows>0){ | |
$result=$CI->db->select_sum('amount','total')->get_where('sale',['product_id'=>$product_id])->row()->total; | |
return $result; | |
}else{ | |
return 0; | |
} | |
} | |
function getSumProductDamageReturnAmount($product_id){ | |
$CI=&get_instance(); | |
$numrows=$CI->db->get_where('damage_return',['product_id'=>$product_id])->num_rows(); | |
if($numrows>0){ | |
$result=$CI->db->query("select *, SUM(dr.quantity*p.amount/p.quantity) as total_damaged from purchase p JOIN purchase_details pd JOIN damage_return dr WHERE p.purchase_id=pd.id AND pd.refference_no=dr.refference_no AND p.product_id='$product_id' AND p.product_id=dr.product_id group by dr.product_id")->row()->total_damaged; | |
return $result; | |
}else{ | |
return 0; | |
} | |
} | |
function getSumProductPurchaseReturnAmount($product_id){ | |
$CI=&get_instance(); | |
$numrows=$CI->db->get_where('purchase_return',['product_id'=>$product_id])->num_rows(); | |
if($numrows>0){ | |
$result=$CI->db->query("select *, SUM(pr.quantity*(p.amount/p.quantity)) as total_returned from purchase p JOIN | |
purchase_details pd | |
JOIN purchase_return pr | |
WHERE p.purchase_id=pd.id | |
AND pd.refference_no=pr.refference_no | |
AND p.product_id='$product_id' | |
AND p.product_id=pr.product_id | |
group by pr.product_id")->row()->total_returned; | |
return $result; | |
}else{ | |
return 0; | |
} | |
} | |
function getSumProductSaleReturnAmount($product_id){ | |
$CI=&get_instance(); | |
$numrows=$CI->db->get_where('sale_return',['product_id'=>$product_id])->num_rows(); | |
if($numrows>0){ | |
$result=$CI->db->query("select *, SUM(sr.quantity*(s.amount/s.quantity)) as total_returned from sale s JOIN | |
sale_details sd | |
JOIN sale_return sr | |
WHERE s.sale_id=sd.id | |
AND sd.refference_no=sr.refference_no | |
AND s.product_id='$product_id' | |
AND s.product_id=sr.product_id | |
group by sr.product_id")->row()->total_returned; | |
return $result; | |
}else{ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment