init
This commit is contained in:
117
modules/EcmReports/getContractorsByProduct.php
Normal file
117
modules/EcmReports/getContractorsByProduct.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
$db = $GLOBALS ['db'];
|
||||
$date_from = $_POST["date_from"];
|
||||
$date_to = $_POST["date_to"];
|
||||
$searchByType = $_POST['type'];
|
||||
$pdf_type = $_POST['pdf_type'];
|
||||
$productId = $_POST['productid'];
|
||||
$date_from = new DateTime($date_from);
|
||||
$date_to = new DateTime($date_to);
|
||||
|
||||
|
||||
$query="SELECT
|
||||
acco.name AS 'name',
|
||||
acco.id AS 'id' ,
|
||||
acco.parent_id AS 'parent_id' ,
|
||||
produkt.code ,
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
CASE WHEN faktura.currency_value is null or faktura.currency_value='' or faktura.currency_value=0
|
||||
THEN
|
||||
pozycja.total_netto
|
||||
ELSE
|
||||
pozycja.total_netto*faktura.currency_value
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN faktura.currency_value is null or faktura.currency_value='' or faktura.currency_value=0
|
||||
THEN
|
||||
pozycja.total_netto_corrected
|
||||
ELSE
|
||||
pozycja.total_netto_corrected*faktura.currency_value
|
||||
END
|
||||
END
|
||||
) as netto,
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
pozycja.quantity
|
||||
ELSE
|
||||
pozycja.quantity_corrected
|
||||
END
|
||||
) as ilosc,
|
||||
sum(
|
||||
CASE WHEN faktura.type!='correct'
|
||||
THEN
|
||||
pozycja.quantity*pozycja.price_purchase
|
||||
ELSE
|
||||
pozycja.quantity_corrected*pozycja.price_purchase
|
||||
END
|
||||
) as koszt
|
||||
FROM
|
||||
ecminvoiceoutitems pozycja
|
||||
JOIN
|
||||
ecminvoiceouts faktura ON pozycja.ecminvoiceout_id = faktura.id
|
||||
JOIN
|
||||
ecmproducts produkt ON pozycja.ecmproduct_id = produkt.id
|
||||
JOIN
|
||||
accounts acco ON acco.id = faktura.parent_id
|
||||
WHERE
|
||||
faktura.register_date BETWEEN
|
||||
'".$date_from->format('Y-m-d')."' AND
|
||||
'".$date_to->format('Y-m-d')."'
|
||||
and faktura.type like '".$searchByType."'
|
||||
";
|
||||
|
||||
if ($pdf_type !='')
|
||||
$query.=" and faktura.pdf_type='$pdf_type' ";
|
||||
|
||||
/*
|
||||
if( $contrator == 1249 )
|
||||
$query .= "and acco.parent_id='".$contrator."'";
|
||||
else
|
||||
$query .= "and faktura.parent_id='".$contrator."'";
|
||||
*/
|
||||
|
||||
|
||||
$query .= "
|
||||
and produkt.id = '".$productId."'
|
||||
and faktura.canceled = 0
|
||||
and faktura.deleted= 0
|
||||
and pozycja.deleted= 0
|
||||
GROUP BY acco.id
|
||||
COLLATE utf8_polish_ci;";
|
||||
|
||||
$data = array();
|
||||
$rows = $db->query ($query);
|
||||
|
||||
// prepare data for Smarty
|
||||
while($r = $db->fetchByAssoc ( $rows ))
|
||||
{
|
||||
$row = array();
|
||||
$row["id"] = $r["id"];
|
||||
$row["name"] = $r["name"];
|
||||
$row["code"] = $r["code"];
|
||||
$row["ilosc"] = $r["ilosc"];
|
||||
$row["netto"] = $r["netto"];
|
||||
$row["srednia"] = $row["netto"]/$row["ilosc"];
|
||||
$row["koszt"] = $r["koszt"];
|
||||
|
||||
//if($row["netto"]>$row["koszt"])
|
||||
//{
|
||||
$row["marza"] = ($row["netto"]-$row["koszt"])/($row["netto"])*100;
|
||||
//}else{
|
||||
// $row["marza"] = 0;
|
||||
//}
|
||||
|
||||
$data [] = $row;
|
||||
|
||||
}
|
||||
$smart = new Sugar_Smarty ();
|
||||
$smart -> assign("data", $data);
|
||||
|
||||
|
||||
|
||||
echo $smart->display ( 'modules/EcmReports/tpls/detailContractors.tpl' );
|
||||
?>
|
||||
Reference in New Issue
Block a user