function TotalRemainRender(&$row, $value, $BeforeAmount, $prevRow) { if (!$prevRow) { $row["Sum"] = $BeforeAmount + $row["CreditorAmount"] - $row["DebtorAmount"]; } else { $row["Sum"] = $prevRow["Sum"] + $row["CreditorAmount"] - $row["DebtorAmount"]; } return "<div style=direction:ltr>" . number_format($row["Sum"]) . "</div>"; } $col = $rpg->addColumn("مانده حساب", "CreditorAmount", "TotalRemainRender", $BeforeAmount); //$col->EnableSummary(true); $rpg->mysql_resource = $dataTable; $rpg->page_size = 12; $rpg->paging = true; if (!$rpg->excel) { BeginReport(); //if($_SESSION["USER"]["UserName"] == "admin") // echo PdoDataAccess::GetLatestQueryString (); echo "<div style=display:none>" . PdoDataAccess::GetLatestQueryString() . "</div>"; echo "<table style='border:2px groove #9BB1CD;border-collapse:collapse;width:100%'><tr>\r\n\t\t\t\t<td width=60px><img src='/framework/icons/logo.jpg' style='width:120px'></td>\r\n\t\t\t\t<td align='center' style='height:100px;vertical-align:middle;font-family:b titr;font-size:15px'>\r\n\t\t\t\t\tگزارش گردش حساب ها \r\n\t\t\t\t\t <br> " . $_SESSION["accounting"]["BranchName"] . "<br>" . "دوره سال " . $_SESSION["accounting"]["CycleID"] . "</td>\r\n\t\t\t\t<td width='200px' align='center' style='font-family:tahoma;font-size:11px'>تاریخ تهیه گزارش : " . DateModules::shNow() . "<br>"; if (!empty($_POST["fromDate"])) { echo "<br>گزارش از تاریخ : " . $_POST["fromDate"] . ($_POST["toDate"] != "" ? " - " . $_POST["toDate"] : ""); } echo "</td></tr></table>"; } echo $BeforeRemaindar; $rpg->generateReport(); die; } ?> <script>
function showReport(){ $levelsDescArr = array( "l1" => "کل", "l2" => "معین", "l3" => "جزء معین", "l4" => "گروه تفصیلی", "l5" => "گروه تفصیلی2", "l6" => "تفصیلی", "l7" => "تفصیلی2" ); global $level; $level = empty($_REQUEST["level"]) ? "l1" : $_REQUEST["level"]; $rpg = new ReportGenerator(); $whereParam = array(); $where = ""; $group = "cc.level1"; $select = "select sum(di.DebtorAmount) bdAmount, sum(di.CreditorAmount) bsAmount, b1.BlockDesc level1Desc, b2.BlockDesc level2Desc, b3.BlockDesc level3Desc, b.InfoDesc TafsiliTypeDesc, t.TafsiliDesc TafsiliDesc, bi2.InfoDesc TafsiliTypeDesc2, t2.TafsiliDesc TafsiliDesc2, cc.level1,cc.level2,cc.level3,di.TafsiliType,di.TafsiliType2,di.TafsiliID,di.TafsiliID2, t.StartCycleDebtor, t.StartCycleCreditor "; $from = " from ACC_DocItems di join ACC_docs d using(DocID) join ACC_CostCodes cc using(CostID) join ACC_blocks b1 on(level1=b1.BlockID) left join ACC_blocks b2 on(level2=b2.BlockID) left join ACC_blocks b3 on(level3=b3.BlockID) left join BaseInfo b on(TypeID=2 AND di.TafsiliType=InfoID) left join ACC_tafsilis t using(TafsiliID) left join BaseInfo bi2 on(bi2.TypeID=2 AND di.TafsiliType2=bi2.InfoID) left join ACC_tafsilis t2 on(t2.TafsiliID=di.TafsiliID2) left join ( select CycleID,CostID,sum(DebtorAmount) StartCycleDebtor, sum(CreditorAmount) StartCycleCreditor from ACC_DocItems join ACC_docs using(DocID) where DocType=1 group by CostID )t on(d.CycleID=t.CycleID AND di.CostID=t.CostID) "; if($level >= "l1") $rpg->addColumn("کل", "level1Desc",$level =="l1" ? "levelRender" : ""); if($level >= "l2") $rpg->addColumn("معین", "level2Desc", $level =="l2" ? "levelRender" : ""); if($level >= "l3") $rpg->addColumn("جزء معین", "level3Desc", $level =="l3" ? "levelRender" : ""); if($level == "l4" || $level == "l6") $rpg->addColumn("گروه تفصیلی", "TafsiliTypeDesc", $level =="l4" ? "levelRender" : ""); if($level == "l4" || $level == "l7") $rpg->addColumn("گروه تفصیلی2", "TafsiliTypeDesc2", $level == "l4" ? "levelRender2" : ""); if($level == "l6") $rpg->addColumn("تفصیلی", "TafsiliDesc", "showDocs"); if($level == "l7") $rpg->addColumn("تفصیلی2", "TafsiliDesc2", "showDocs2"); switch($level) { case "l2" : $group .= ",cc.level2"; break; case "l3" : $group .= ",cc.level3"; break; case "l4" : $group .= ",di.TafsiliType"; break; case "l5" : $group .= ",di.TafsiliType2"; break; case "l6" : $group .= ",di.TafsiliID"; break; case "l7" : $group .= ",di.TafsiliID2"; break; } function levelRender($row, $value){ global $level; if($value == "") $value = "-----"; return "<a onclick=changeLevel('" . $level . "','". ($level >= "l1" ? $row["level1"] : "") . "','" . ($level >= "l2" ? $row["level2"] : "") . "','" . ($level >= "l3" ? $row["level3"] : ""). "','" . ($level == "l4" ? $row["TafsiliType"] : ""). "','" . ($level == "l5" ? $row["TafsiliType2"] : ""). "') "." href='javascript:void(0);'>" . $value . "</a>"; } function levelRender2($row, $value){ global $level; return "<a onclick=changeLevel('l5','". ($level >= "l1" ? $row["level1"] : "") . "','" . ($level >= "l2" ? $row["level2"] : "") . "','" . ($level >= "l3" ? $row["level3"] : ""). "','" . ($level == "l4" ? $row["TafsiliType"] : ""). "','" . ($level == "l5" ? $row["TafsiliType2"] : ""). "') "." href='javascript:void(0);'>" . $value . "</a>"; } function showDocs($row, $value){ if($value == "") $value = "-----"; return "<a onclick=\"window.open('flow.php?show=true&taraz=true". "&level1=" . $row["level1"] . "&level2=" . $row["level2"] . "&level3=" . $row["level3"] . "&TafsiliType=" . $row["TafsiliType"] . "&TafsiliID=" . $row["TafsiliID"] . (!empty($_REQUEST["fromDate"]) ? "&fromDate=" . $_REQUEST["fromDate"] : "") . (!empty($_REQUEST["toDate"]) ? "&toDate=" . $_REQUEST["toDate"] : "") . (!empty($_REQUEST["fromLocalNo"]) ? "&fromLocalNo=" . $_REQUEST["fromLocalNo"] : "") . (!empty($_REQUEST["toLocalNo"]) ? "&toLocalNo=" . $_REQUEST["toLocalNo"] : "") . (!empty($_REQUEST["BranchID"]) ? "&BranchID=" . $_REQUEST["BranchID"] : "") . (!empty($_REQUEST["IncludeRaw"]) ? "&IncludeRaw=1" : "") . "');\" href=javascript:void(0)>" . $value . "</a>"; } function showDocs2($row, $value){ if($value == "") $value = "-----"; return "<a onclick=\"window.open('flow.php?taraz=true&show=true&taraz=true". "&level1=" . $row["level1"] . "&level2=" . $row["level2"] . "&level3=" . $row["level3"] . "&TafsiliID2=" . $row["TafsiliID2"] . (!empty($_POST["fromDate"]) ? "&fromDate=" . $_POST["fromDate"] : "") . (!empty($_POST["toDate"]) ? "&toDate=" . $_POST["toDate"] : "") . (!empty($_REQUEST["BranchID"]) ? "&BranchID=" . $_REQUEST["BranchID"] : "") . (!empty($_REQUEST["IncludeRaw"]) ? "&IncludeRaw=1" : "") . "');\" href=javascript:void(0)>" . $value . "</a>"; } function MakeWhere(&$where, &$whereParam){ if(!isset($_REQUEST["IncludeRaw"])) { $where .= " AND d.DocStatus != 'RAW'"; } if(isset($_REQUEST["level1"])) { if($_REQUEST["level1"] == "") $where .= " AND cc.level1 is null"; else { $where .= " AND cc.level1=:l1"; $whereParam[":l1"] = $_REQUEST["level1"]; } } if(isset($_REQUEST["level2"])) { if($_REQUEST["level2"] == "") $where .= " AND cc.level2 is null"; else { $where .= " AND cc.level2=:l2"; $whereParam[":l2"] = $_REQUEST["level2"]; } } if(isset($_REQUEST["level3"])) { if($_REQUEST["level3"] == "") $where .= " AND cc.level3 is null"; else { $where .= " AND cc.level3=:l3"; $whereParam[":l3"] = $_REQUEST["level3"]; } } if(isset($_REQUEST["tafsiligroup"])) { if($_REQUEST["tafsiligroup"] == "") $where .= " AND di.TafsiliType is null"; else { $where .= " AND di.TafsiliType=:tt"; $whereParam[":tt"] = $_REQUEST["tafsiligroup"]; } } //.............................................. if(!empty($_POST["level1s"])) { $level1s = preg_replace("/[^0-9,]+/", "", $_POST["level1s"]); $where .= " AND cc.level1 in( " . $level1s . ")"; } //---------------------------------------------- if(!empty($_POST["level2s"])) { $level2s = preg_replace("/[^0-9,]+/", "", $_POST["level2s"]); $level2s = substr($level2s, 0, strlen($level2s)-1); $where .= " AND cc.level2 in( " . $level2s . ")"; } //---------------------------------------------- if(!empty($_POST["level3s"])) { $level3s = preg_replace("/[^0-9,]+/", "", $_POST["level3s"]); $level3s = substr($level3s, 0, strlen($level3s)-1); $where .= " AND cc.level3 in( " . $level3s . ")"; } //---------------------------------------------- if(!empty($_POST["TafsiliGroup"])) { $where .= " AND (di.TafsiliType=:tt or di.TafsiliType2=:tt)"; $whereParam[":tt"] = $_POST["TafsiliGroup"]; } /*if(!empty($_POST["TafsiliGroup2"])) { $where .= " AND di.TafsiliType2=:tt2"; $whereParam[":tt2"] = $_POST["TafsiliGroup2"]; }*/ if(!empty($_POST["TafsiliID"])) { $where .= " AND (di.TafsiliID=:tid or di.TafsiliID2=:tid)"; $whereParam[":tid"] = $_POST["TafsiliID"]; } /*if(!empty($_POST["TafsiliID2"])) { $where .= " AND di.TafsiliID2=:tid2"; $whereParam[":tid2"] = $_POST["TafsiliID2"]; }*/ if(!empty($_REQUEST["fromLocalNo"])) { $where .= " AND d.LocalNo >= :lo1 "; $whereParam[":lo1"] = $_REQUEST["fromLocalNo"]; } if(!empty($_REQUEST["toLocalNo"])) { $where .= " AND d.LocalNo <= :lo2 "; $whereParam[":lo2"] = $_REQUEST["toLocalNo"]; } if(!empty($_POST["fromDate"])) { $where .= " AND d.DocDate >= :q1 "; $whereParam[":q1"] = DateModules::shamsi_to_miladi($_POST["fromDate"], "-"); } if(!empty($_POST["toDate"])) { $where .= " AND d.DocDate <= :q2 "; $whereParam[":q2"] = DateModules::shamsi_to_miladi($_POST["toDate"], "-"); } } $where = ""; $whereParam = array(); if(!empty($_POST["BranchID"])) { $where .= " AND d.BranchID=:b"; $whereParam[":b"] = $_POST["BranchID"]; } MakeWhere($where, $whereParam); $query = $select . $from . " where d.CycleID=" . $_SESSION["accounting"]["CycleID"] . $where; $query .= $group != "" ? " group by " . $group : ""; $query .= " order by b1.BlockCode,b2.BlockCode,b3.BlockCode"; $dataTable = PdoDataAccess::runquery($query, $whereParam); //.......................................................................... function dateRender($row, $val){ return DateModules::miladi_to_shamsi($val); } function moneyRender($row, $val) { return number_format($val, 0, '.', ','); } function bdremainRender($row){ $v = $row["bdAmount"] - $row["bsAmount"]; return $v < 0 ? 0 : number_format($v); } function bsremainRender($row){ $v = $row["bsAmount"] - $row["bdAmount"]; return $v < 0 ? 0 : number_format($v); } $col = $rpg->addColumn("بدهکار", "StartCycleDebtor", "moneyRender"); $col->GroupHeader = "حساب ابتدای دوره"; $col->EnableSummary(true); $col = $rpg->addColumn("بستانکار", "StartCycleCreditor", "moneyRender"); $col->GroupHeader = "حساب ابتدای دوره"; $col->EnableSummary(true); $col = $rpg->addColumn("بدهکار", "bdAmount" , "moneyRender"); $col->GroupHeader = "گردش طی دوره"; $col->EnableSummary(); $col = $rpg->addColumn("بستانکار", "bsAmount", "moneyRender"); $col->GroupHeader = "گردش طی دوره"; $col->EnableSummary(); $col = $rpg->addColumn("مانده بدهکار", "bdAmount", "bdremainRender"); $col->GroupHeader = "مانده پایان دوره"; $col->EnableSummary(true); $col = $rpg->addColumn("مانده بستانکار", "bsAmount", "bsremainRender"); $col->GroupHeader = "مانده پایان دوره"; $col->EnableSummary(true); if(!$rpg->excel) { BeginReport(); echo "<div style=display:none>" . PdoDataAccess::GetLatestQueryString() . "</div>"; echo "<table style='border:2px groove #9BB1CD;border-collapse:collapse;width:100%'><tr> <td width=60px><img src='/framework/icons/logo.jpg' style='width:120px'></td> <td align='center' style='height:100px;vertical-align:middle;font-family:b titr;font-size:15px'> تراز دفتر ".$levelsDescArr[$level]." <br> ". $_SESSION["accounting"]["BranchName"]. "<br>" . "دوره سال " . $_SESSION["accounting"]["CycleID"] . "</td> <td width='200px' align='center' style='font-family:tahoma;font-size:11px'>تاریخ تهیه گزارش : " . DateModules::shNow() . "<br>"; if(!empty($_POST["fromDate"])) { echo "<br>گزارش از تاریخ : " . $_POST["fromDate"] . ($_POST["toDate"] != "" ? " - " . $_POST["toDate"] : ""); } echo "</td></tr></table>"; } $rpg->mysql_resource = $dataTable; $rpg->generateReport(); ?> <script> function changeLevel(curlevel,level1,level2,level3,TafsiliGroup,TafsiliID) { nextLevel = (curlevel.substring(1)*1); nextLevel = (nextLevel == 4 || nextLevel == 5) ? nextLevel+2 : nextLevel+1 var form = document.getElementById("subForm"); form.action = "taraz.php?show=true&level=" + "l" + nextLevel; if(curlevel >= "l1") form.action += "&level1=" + level1; if(curlevel >= "l2") form.action += "&level2=" + level2; if(curlevel >= "l3") form.action += "&level3=" + level3; if(curlevel >= "l4") form.action += "&tafsiligroup=" + TafsiliGroup; if(curlevel >= "l5") form.action += "&TafsiliID=" + TafsiliID; form.submit(); return; } </script> <form id="subForm" method="POST" target="_blank"> <input type="hidden" name="fromDate" value="<?= !empty($_REQUEST["fromDate"]) ? $_REQUEST["fromDate"] : "" ?>"> <input type="hidden" name="toDate" value="<?= !empty($_REQUEST["toDate"]) ? $_REQUEST["toDate"] : "" ?>"> <input type="hidden" name="fromLocalNo" value="<?= !empty($_REQUEST["fromLocalNo"]) ? $_REQUEST["fromLocalNo"] : "" ?>"> <input type="hidden" name="toLocalNo" value="<?= !empty($_REQUEST["toLocalNo"]) ? $_REQUEST["toLocalNo"] : "" ?>"> <input type="hidden" name="IncludeRaw" value="<?= !empty($_REQUEST["IncludeRaw"]) ? $_REQUEST["IncludeRaw"] : "" ?>"> <input type="hidden" name="BranchID" value="<?= !empty($_REQUEST["BranchID"]) ? $_REQUEST["BranchID"] : "" ?>"> <input type="hidden" name="level1s" id="level1s" value="<?= $_POST["level1s"] ?>"> <input type="hidden" name="level2s" id="level2s" value="<?= $_POST["level2s"] ?>"> <input type="hidden" name="level3s" id="level3s" value="<?= $_POST["level3s"] ?>"> </form> <? die(); }