public function opb_view_ledeger($coa_code, $start_date, $end_date, $shop_id) { $dBalance = 0; $dDebit = 0; $dCredit = 0; $yesterday = ''; $ClosingBalance = 0; $OpBalance = 0; if ($shop_id == 0 || empty($shop_id)) { $shop_id = 1; } if ($start_date == $end_date) { $yesterday = date('Y-m-d', strtotime($start_date . ' -1 day')); if ($yesterday == "2016-04-01") { $start_date = "2016-04-01"; $yesterday = "2016-04-01"; } else { $start_date = "2016-04-01"; $yesterday = $yesterday; } } else { $yesterday = date('Y-m-d', strtotime($start_date . ' -1 day')); $start_date = "2016-04-01"; } $data = new Sale(); // Get Opening Balance $GetOpBalance = $data->get_opening_balance($coa_code); if ($GetOpBalance[0]->coa_debit == 0) { $OpBalance = $GetOpBalance[0]->coa_credit; } else { $OpBalance = $GetOpBalance[0]->coa_debit; } $arrayLedeger = DB::table('vouchermaster')->join('voucherdetail', 'voucherdetail.vd_vm_id', '=', 'vouchermaster.vm_id')->join('coa', 'coa.coa_code', '=', 'voucherdetail.vd_coa_code')->select('vouchermaster.*', 'voucherdetail.*', 'coa.*')->whereRaw('vouchermaster.shop_id = "' . $shop_id . '" AND vd_coa_code = "' . $coa_code . '" AND vm_date >= "' . $start_date . '" AND vm_date <= "' . $yesterday . '" ')->orderBy('vm_date', 'asc')->get(); $i = 1; if (!empty($arrayLedeger) && count($arrayLedeger) > 0 && $coa_code == "414002") { foreach ($arrayLedeger as $rstRow) { $dBalance = 0; $DateExpense = 0; if ($rstRow->vm_type == "CR") { $DateExpense = $this->GetDateWiseExpense($rstRow->vm_date); $dBalance = $OpBalance - $DateExpense + $rstRow->vd_credit; $rstRow->vd_debit = $rstRow->vd_credit; $rstRow->vd_credit = '0.0000'; } $dDebit += $rstRow->vd_debit; $dCredit += $rstRow->vd_credit; $i++; } $Debit = $dDebit; $Credit = $dCredit; //echo $OpBalance."-----".$Debit."-----".$Credit; die; $ClosingBalance = $OpBalance + $Debit - $Credit; //echo $ClosingBalance."-------"; die; } else { //print_r($arrayLedeger); die; //if(!empty($arrayLedeger) && count($arrayLedeger) > 0) //{ foreach ($arrayLedeger as $rstRow) { $dDebit += $rstRow->vd_debit; $dCredit += $rstRow->vd_credit; $i++; } $Debit = $dDebit; $Credit = $dCredit; $ClosingBalance = $OpBalance + $Debit - $Credit; //} } //$ClosingBalance = 40050; return $ClosingBalance; //} }