Commit 2f291d78 by lizhilin

更新

parent 963d2f1b
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
use Dcat\Admin\Show; use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController; use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Repositories\CovenantReceivePaymentCollect; use App\Admin\Repositories\CovenantReceivePaymentCollect;
use Carbon\Carbon;
use Dcat\Admin\Support\Helper;
class CovenantReceivePaymentController extends AdminController class CovenantReceivePaymentController extends AdminController
{ {
...@@ -20,14 +22,26 @@ class CovenantReceivePaymentController extends AdminController ...@@ -20,14 +22,26 @@ class CovenantReceivePaymentController extends AdminController
protected function grid() protected function grid()
{ {
return Grid::make(new CovenantReceivePaymentCollect(), function (Grid $grid) { return Grid::make(new CovenantReceivePaymentCollect(), function (Grid $grid) {
// 获取筛选条件
$params = [];
$params['lnum'] = $_GET['lnum'] ?? '';
$params['lname'] = $_GET['lname'] ?? '';
$params['cnum'] = $_GET['cnum'] ?? '';
$params['ctype'] = $_GET['ctype'] ?? '';
$params['principal'] = $_GET['principal'] ?? '';
$received_at = $invoiced_at = [];
$received_at['start'] = $_GET['received_at']['start'] ?? '';
$received_at['end'] = $_GET['received_at']['end'] ?? '';
$invoiced_at['start'] = $_GET['invoiced_at']['start'] ?? '';
$invoiced_at['end'] = $_GET['invoiced_at']['end'] ?? '';
//已收款 //已收款
$receivedMoney = ModelsCovenantReceivePayment::getReceivedMoney(); $receivedMoney = ModelsCovenantReceivePayment::getTotalReceivedAmount($params, $received_at, $invoiced_at);
//开票金额 //开票金额
$invoicedMoney = ModelsCovenantReceivePayment::getInvoicedMoney(); $invoicedMoney = ModelsCovenantReceivePayment::getTotalInvoicedMoney($params, $received_at, $invoiced_at);
//已收款未开票 //已收款未开票
$receiptNoinvoice = ModelsCovenantReceivePayment::getReceiptNoinvoice(); $receiptNoinvoice = ($receivedMoney - $invoicedMoney) > 0 ? $receivedMoney - $invoicedMoney : 0;
//已开票未收款 //已开票未收款
$invoiceNoreceipt = ModelsCovenantReceivePayment::getInvoiceNoreceipt(); $invoiceNoreceipt = ($invoicedMoney - $receivedMoney) > 0 ? $invoicedMoney - $receivedMoney : 0;
// 添加一行表头数据 // 添加一行表头数据
// $grid->header(function () use ($invoicedMoney, $receivedMoney, $receiptNoinvoice, $invoiceNoreceipt) { // $grid->header(function () use ($invoicedMoney, $receivedMoney, $receiptNoinvoice, $invoiceNoreceipt) {
// return '<div class="row" style="text-align:center;">' . // return '<div class="row" style="text-align:center;">' .
...@@ -49,10 +63,10 @@ protected function grid() ...@@ -49,10 +63,10 @@ protected function grid()
<th width="90">合计</th> <th width="90">合计</th>
<th width="90"></th> <th width="90"></th>
<th width="90"></th> <th width="90"></th>
<th width="90">' . $invoicedMoney . '</th> <th width="90" text-align="center"> ' . $invoicedMoney . '</th>
<th width="90">' . $receivedMoney . '</th> <th width="90"> ' . $receivedMoney . '</th>
<th width="90">' . $receiptNoinvoice . '</th> <th width="90"> ' . $receiptNoinvoice . '</th>
<th width="90">' . $invoiceNoreceipt . '</th> <th width="90"> ' . $invoiceNoreceipt . '</th>
</tr> </tr>
</thead> </thead>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Admin\Repositories; namespace App\Admin\Repositories;
use App\Command\Log;
use App\Models\Covenant as ModelsCovenant; use App\Models\Covenant as ModelsCovenant;
use App\Models\Principal as ModelsPrincipal; use App\Models\Principal as ModelsPrincipal;
use App\Models\CovenantReceivePayment; use App\Models\CovenantReceivePayment;
...@@ -69,7 +70,7 @@ public function get(Grid\Model $model) ...@@ -69,7 +70,7 @@ public function get(Grid\Model $model)
public function getList(array $param) public function getList(array $param)
{ {
$prePage = $param['per_page'] ?? 20; $prePage = $param['per_page'] ?? 20;
$start = $param['start'] ?? 0; $offset_start = $param['start'] ?? 0;
$lnum = $param['search']['lnum'] ?? ''; $lnum = $param['search']['lnum'] ?? '';
$lname = $param['search']['lname'] ?? ''; $lname = $param['search']['lname'] ?? '';
$cnum = $param['search']['cnum'] ?? ''; $cnum = $param['search']['cnum'] ?? '';
...@@ -78,7 +79,7 @@ public function getList(array $param) ...@@ -78,7 +79,7 @@ public function getList(array $param)
$invoiced_at = $param['search']['invoiced_at'] ?? []; $invoiced_at = $param['search']['invoiced_at'] ?? [];
$received_at = $param['search']['received_at'] ?? []; $received_at = $param['search']['received_at'] ?? [];
$list = []; $list = [];
DB::enableQueryLog();
$note_monitor = DB::table("covenant_receive_payment as rp") $note_monitor = DB::table("covenant_receive_payment as rp")
->select(DB::raw('rp.cid, c.cname,c.ctype,c.number as cnum,c.principal,c.principal_id,l.number as lnum,l.name as lname,sum(invoiced_money) as invoiced_money,sum(received_amount) as received_amount')) ->select(DB::raw('rp.cid, c.cname,c.ctype,c.number as cnum,c.principal,c.principal_id,l.number as lnum,l.name as lname,sum(invoiced_money) as invoiced_money,sum(received_amount) as received_amount'))
//->select(['rp.cid', 'c.cname', 'c.ctype', 'c.number as cnum', 'c.principal', 'l.number as lnum', 'l.name as lname', 'sum(invoiced_money) as invoiced_money']) //->select(['rp.cid', 'c.cname', 'c.ctype', 'c.number as cnum', 'c.principal', 'l.number as lnum', 'l.name as lname', 'sum(invoiced_money) as invoiced_money'])
...@@ -151,13 +152,16 @@ public function getList(array $param) ...@@ -151,13 +152,16 @@ public function getList(array $param)
if ($cObj->toArray()) { if ($cObj->toArray()) {
$count = count($cObj->toArray()); $count = count($cObj->toArray());
} }
// 获取列表 // 获取列表
$data = []; $data = [];
$list = $note_monitor->groupBy('rp.cid') $list = $note_monitor->groupBy('rp.cid')
->limit($prePage) ->limit($prePage)
->offset($start) ->offset($offset_start)
->get() ->get()
->toArray(); ->toArray();
//$queries = DB::getQueryLog();
foreach ($list as $key => $item) { foreach ($list as $key => $item) {
$tmp = []; $tmp = [];
......
...@@ -456,4 +456,189 @@ public static function getTotalAccumulationFund($number, $received_at = []) ...@@ -456,4 +456,189 @@ public static function getTotalAccumulationFund($number, $received_at = [])
return $total_money; return $total_money;
} }
//开票汇总表 总收款金额
public static function getTotalReceivedAmount($params, $received_at, $invoiced_at)
{
// 获取筛选条件
$lnum = $params['lnum'] ?? '';
$lname = $params['lname'] ?? '';
$cnum = $params['cnum'] ?? '';
$ctype = $params['ctype'] ?? '';
$principal = $params['principal'] ?? '';
DB::enableQueryLog();
$note_monitor = DB::table("covenant_receive_payment as rp")
->select(DB::raw('rp.cid, c.cname,c.ctype,c.number as cnum,c.principal,c.principal_id,l.number as lnum,l.name as lname,sum(invoiced_money) as invoiced_money,sum(received_amount) as received_amount'))
//->select(['rp.cid', 'c.cname', 'c.ctype', 'c.number as cnum', 'c.principal', 'l.number as lnum', 'l.name as lname', 'sum(invoiced_money) as invoiced_money'])
->leftJoin('covenant as c', 'rp.cid', '=', 'c.id')
->leftJoin('lawyer as l', 'rp.lawyer_id', '=', 'l.id')
->where('rp.rtype', 1);
if ($lnum) {
$note_monitor = $note_monitor->where("l.number", $lnum);
}
if ($lname) {
$note_monitor = $note_monitor->where("l.name", $lname);
}
if ($cnum) {
$note_monitor = $note_monitor->where("c.number", $cnum);
}
if ($ctype) {
$note_monitor = $note_monitor->where("c.ctype", $ctype);
}
if ($principal) {
$note_monitor = $note_monitor->where("c.principal", $principal);
}
if ($invoiced_at['start'] && $received_at['start']) {
$in_start = $invoiced_at['start'] ?? '';
$in_end = $invoiced_at['end'] ?? '';
$re_start = $received_at['start'] ?? '';
$re_end = $received_at['end'] ?? '';
if ($in_start && $re_start) {
if ($in_end && $re_end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$re_start, $re_end])
->whereBetween('rp.invoiced_at', [$in_start, $in_end]);
} else {
if ($in_end) {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $re_start)
->whereBetween('rp.invoiced_at', [$in_start, $in_end]);
} elseif ($re_end) {
$note_monitor = $note_monitor->whereDate('rp.invoiced_at', '>', $in_start)
->whereBetween('rp.received_at', [$re_start, $re_end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.invoiced_at', '>', $in_start)
->whereDate('rp.received_at', '>', $re_start);
}
}
}
} elseif ($invoiced_at['start'] && !$received_at['start']) { //开票日期
$start = $invoiced_at['start'] ?? '';
$end = $invoiced_at['end'] ?? '';
if ($start) {
if ($end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$start, $end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $start);
}
}
//
} elseif ($received_at['start'] && !$invoiced_at['start']) { //收款日期
$start = $received_at['start'] ?? '';
$end = $received_at['end'] ?? '';
if ($start) {
if ($end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$start, $end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $start);
}
}
}
// 计算列表总数
$total = 0;
$list = $note_monitor->groupBy('rp.cid')->get();
$queries = DB::getQueryLog();
if ($list->toArray()) {
foreach ($list as $item) {
$total += $item->received_amount;
}
}
return $total;
}
//开票汇总表 总开票金额
public static function getTotalInvoicedMoney($params, $received_at, $invoiced_at)
{
// 获取筛选条件
$lnum = $params['lnum'] ?? '';
$lname = $params['lname'] ?? '';
$cnum = $params['cnum'] ?? '';
$ctype = $params['ctype'] ?? '';
$principal = $params['principal'] ?? '';
DB::enableQueryLog();
$note_monitor = DB::table("covenant_receive_payment as rp")
->select(DB::raw('rp.cid, c.cname,c.ctype,c.number as cnum,c.principal,c.principal_id,l.number as lnum,l.name as lname,sum(invoiced_money) as invoiced_money,sum(received_amount) as received_amount'))
//->select(['rp.cid', 'c.cname', 'c.ctype', 'c.number as cnum', 'c.principal', 'l.number as lnum', 'l.name as lname', 'sum(invoiced_money) as invoiced_money'])
->leftJoin('covenant as c', 'rp.cid', '=', 'c.id')
->leftJoin('lawyer as l', 'rp.lawyer_id', '=', 'l.id')
->where('rp.rtype', 2);
if ($lnum) {
$note_monitor = $note_monitor->where("l.number", $lnum);
}
if ($lname) {
$note_monitor = $note_monitor->where("l.name", $lname);
}
if ($cnum) {
$note_monitor = $note_monitor->where("c.number", $cnum);
}
if ($ctype) {
$note_monitor = $note_monitor->where("c.ctype", $ctype);
}
if ($principal) {
$note_monitor = $note_monitor->where("c.principal", $principal);
}
if ($invoiced_at['start'] && $received_at['start']) {
$in_start = $invoiced_at['start'] ?? '';
$in_end = $invoiced_at['end'] ?? '';
$re_start = $received_at['start'] ?? '';
$re_end = $received_at['end'] ?? '';
if ($in_start && $re_start) {
if ($in_end && $re_end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$re_start, $re_end])
->whereBetween('rp.invoiced_at', [$in_start, $in_end]);
} else {
if ($in_end) {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $re_start)
->whereBetween('rp.invoiced_at', [$in_start, $in_end]);
} elseif ($re_end) {
$note_monitor = $note_monitor->whereDate('rp.invoiced_at', '>', $in_start)
->whereBetween('rp.received_at', [$re_start, $re_end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.invoiced_at', '>', $in_start)
->whereDate('rp.received_at', '>', $re_start);
}
}
}
} elseif ($invoiced_at['start'] && !$received_at['start']) { //开票日期
$start = $invoiced_at['start'] ?? '';
$end = $invoiced_at['end'] ?? '';
if ($start) {
if ($end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$start, $end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $start);
}
}
//
} elseif ($received_at['start'] && !$invoiced_at['start']) { //收款日期
$start = $received_at['start'] ?? '';
$end = $received_at['end'] ?? '';
if ($start) {
if ($end) {
$note_monitor = $note_monitor->whereBetween('rp.received_at', [$start, $end]);
} else {
$note_monitor = $note_monitor->whereDate('rp.received_at', '>', $start);
}
}
}
// 计算列表总数
$total = 0;
$list = $note_monitor->groupBy('rp.cid')->get();
if ($list->toArray()) {
foreach ($list as $item) {
$total += $item->invoiced_money;
}
}
$queries = DB::getQueryLog();
return $total;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment