|
@@ -241,9 +241,9 @@ class PaymentReceiptService extends Service
|
|
|
->first();
|
|
|
$data['id'] = empty($customer->id) ? 0 : $customer->id;
|
|
|
}
|
|
|
-
|
|
|
if(empty($customer)) return [false,'收付款记录不存在或已被删除'];
|
|
|
$customer = $customer->toArray();
|
|
|
+
|
|
|
$array = [
|
|
|
$customer['account'],
|
|
|
$customer['pay_way'],
|
|
@@ -259,50 +259,22 @@ class PaymentReceiptService extends Service
|
|
|
$customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
|
|
|
$customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
|
|
|
$customer['payment_receipt_date'] = $customer['payment_receipt_date'] ? date("Y-m-d",$customer['payment_receipt_date']): '';
|
|
|
- $customer['receipt_amount'] = $customer['state'] == PaymentReceipt::STATE_TWO ? $customer['amount'] : 0;
|
|
|
|
|
|
$file = PaymentReceiptInfo::where('del_time',0)
|
|
|
+ ->whereIn('type',[PaymentReceiptInfo::type_one,PaymentReceiptInfo::type_two])
|
|
|
->where('payment_receipt_id',$data['id'])
|
|
|
->get()->toArray();
|
|
|
$emp_id = [];
|
|
|
- $order_no = [];
|
|
|
foreach ($file as $value){
|
|
|
if(in_array($value['type'],PaymentReceiptInfo::$man)){
|
|
|
$emp_id[] = $value['data_id'];
|
|
|
}
|
|
|
- if(! empty($value['data_order_no'])) $order_no[] = $value['data_order_no'];
|
|
|
- }
|
|
|
- if($customer['data_type'] == PaymentReceipt::data_type_one){
|
|
|
- $order = SalesOrder::where('del_time',0)
|
|
|
- ->whereIn('order_number',$order_no)
|
|
|
- ->pluck('contract_fee','order_number')
|
|
|
- ->toArray();
|
|
|
- $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order));
|
|
|
- }else{
|
|
|
- $order = PurchaseOrder::where('del_time',0)
|
|
|
- ->whereIn('order_number',$order_no)
|
|
|
- ->pluck('purchase_total','order_number')
|
|
|
- ->toArray();
|
|
|
- $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order), ReturnExchangeOrder::Order_type2);
|
|
|
- }
|
|
|
- $infos = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->where('type',PaymentReceiptInfo::type_three)
|
|
|
- ->where('payment_receipt_id','<>',$customer['id'])
|
|
|
- ->get()->toArray();
|
|
|
- $infos_map = [];
|
|
|
- foreach ($infos as $value){
|
|
|
- $keys = $value['data_order_no'] . $value['data_type'];
|
|
|
- if(isset($infos_map[$keys])){
|
|
|
- $infos_map[$keys] += $value['amount'];
|
|
|
- }else{
|
|
|
- $infos_map[$keys] = $value['amount'];
|
|
|
- }
|
|
|
}
|
|
|
$emp_map = Employee::whereIn('id',array_unique($emp_id))
|
|
|
->pluck('emp_name','id')
|
|
|
->toArray();
|
|
|
|
|
|
- $customer['file'] = $customer['employee_one'] = $customer['amount_list'] = [];
|
|
|
+ $customer['file'] = $customer['employee_one'] = [];
|
|
|
foreach ($file as $value){
|
|
|
if($value['type'] == PaymentReceiptInfo::type_one){
|
|
|
$tmp = [
|
|
@@ -321,49 +293,114 @@ class PaymentReceiptService extends Service
|
|
|
$customer['employee_one'][] = $tmp;
|
|
|
}
|
|
|
}
|
|
|
- }elseif ($value['type'] == PaymentReceiptInfo::type_three){
|
|
|
- $total = $has_amount = 0;
|
|
|
- $receipt_amount = $value['amount'];
|
|
|
- if($customer['type'] == PaymentReceipt::type_one){
|
|
|
- //坏账金额
|
|
|
- $bad_amount = $infos_map[$value['data_order_no'] . PaymentReceipt::type_four] ?? 0;
|
|
|
- //除了本单外的已收金额
|
|
|
- $has_amount = $infos_map[$value['data_order_no'] . PaymentReceipt::type_one] ?? 0;
|
|
|
-
|
|
|
- //总回款金额 = 合同金额 - 退换货金额 - 已收金额 - 坏账金额
|
|
|
- $total = ($order[$value['data_order_no']] ?? 0) - ($getDifferentAmountALL[$value['data_order_no']] ?? 0) - $bad_amount - $has_amount;
|
|
|
-
|
|
|
- }elseif($customer['type'] == PaymentReceipt::type_three){
|
|
|
- //已回款金额
|
|
|
- $one = $infos_map[$value['data_order_no'] . PaymentReceipt::type_one] ?? 0;
|
|
|
- //除了本单外的已红冲金额
|
|
|
- $has_amount = $infos_map[$value['data_order_no'] . PaymentReceipt::type_three] ?? 0;
|
|
|
- //总红冲金额 = 已回款金额 - 已红冲金额
|
|
|
- $total = $one - $has_amount;
|
|
|
-
|
|
|
- }elseif($customer['type'] == PaymentReceipt::type_four){
|
|
|
- //已回款金额
|
|
|
- $one = $infos_map[$value['data_order_no'] . PaymentReceipt::type_one] ?? 0;
|
|
|
- //已红冲金额
|
|
|
- $three = $infos_map[$value['data_order_no'] . PaymentReceipt::type_three] ?? 0;
|
|
|
- //除了本单外的已坏账金额
|
|
|
- $has_amount = $infos_map[$value['data_order_no'] . PaymentReceipt::type_four] ?? 0;
|
|
|
- //总坏账金额 = 合同金额 - 退换货金额 - 已收金额 + 已红冲金额 - 坏账金额
|
|
|
- $total = ($order[$value['data_order_no']] ?? 0) - ($getDifferentAmountALL[$value['data_order_no']] ?? 0) - $one + $three - $has_amount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //组织金额
|
|
|
+ $customer['amount_list'] = $this->makeDetail($customer);
|
|
|
+
|
|
|
+ return [true, $customer];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function makeDetail($data){
|
|
|
+ $return = [];
|
|
|
+ $info = PaymentReceiptInfo::where('del_time',0)
|
|
|
+ ->where('type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('payment_receipt_id', $data['id'])
|
|
|
+ ->select('payment_receipt_id','data_order_type','data_type','amount','data_order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $order_no = array_column($info,'data_order_no');
|
|
|
+
|
|
|
+ //退换货金额
|
|
|
+ if($data['type'] == PaymentReceipt::type_one){
|
|
|
+ if($data['data_type'] == PaymentReceipt::data_type_one){
|
|
|
+ $order = SalesOrder::where('del_time',0)
|
|
|
+ ->whereIn('order_number',$order_no)
|
|
|
+ ->pluck('contract_fee','order_number')
|
|
|
+ ->toArray();
|
|
|
+ $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order));
|
|
|
+ }else{
|
|
|
+ $order = PurchaseOrder::where('del_time',0)
|
|
|
+ ->whereIn('order_number',$order_no)
|
|
|
+ ->pluck('purchase_total','order_number')
|
|
|
+ ->toArray();
|
|
|
+ $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order), ReturnExchangeOrder::Order_type2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //除自己这个收付款单外 所有订单已填的金额
|
|
|
+ $infos = PaymentReceiptInfo::where('del_time',0)
|
|
|
+ ->where('type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('data_type',$data['type'])
|
|
|
+ ->where('payment_receipt_id','<>',$data['id'])
|
|
|
+ ->whereIn('data_order_no',$order_no)
|
|
|
+ ->get()->toArray();
|
|
|
+ $infos_map = [];
|
|
|
+ foreach ($infos as $value){
|
|
|
+ if(isset($infos_map[$value['data_order_no']])){
|
|
|
+ $infos_map[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $infos_map[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //收款金额(审核后)
|
|
|
+ $info_one_array = [];
|
|
|
+ if($data['type'] == PaymentReceipt::type_three){
|
|
|
+ $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
|
|
|
+ ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
|
|
|
+ ->where('b.state',PaymentReceipt::STATE_TWO)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('a.type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('a.data_order_type',PaymentReceipt::data_type_one)
|
|
|
+ ->whereIn('a.data_order_no',$order_no)
|
|
|
+ ->where('a.data_type',PaymentReceipt::type_one)
|
|
|
+ ->select('a.data_order_no','a.amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $info_one_array = [];
|
|
|
+ foreach ($info_one as $value){
|
|
|
+ if(isset($info_one_array[$value['data_order_no']])){
|
|
|
+ $info_one_array[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $info_one_array[$value['data_order_no']] = $value['amount'];
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $tmp = [
|
|
|
- 'data_order_no' => $value['data_order_no'],
|
|
|
- 'amount' => $value['amount'],
|
|
|
- 'total_amount' => $total,
|
|
|
- 'has_amount' => $has_amount,
|
|
|
- 'receipt_amount' => $receipt_amount
|
|
|
- ];
|
|
|
- $customer['amount_list'][] = $tmp;
|
|
|
+ foreach ($info as $value){
|
|
|
+ $total = $tmp_receipt = 0;
|
|
|
+ if($data['type'] == PaymentReceipt::type_one){
|
|
|
+ //收款 = 总金额 - 已收 - 退货退款
|
|
|
+ //总金额
|
|
|
+ $total_amount = $order[$value['data_order_no']] ?? 0;
|
|
|
+ //已收
|
|
|
+ $tmp_receipt = $infos_map[$value['data_order_no']] ?? 0;
|
|
|
+ //退货退款
|
|
|
+ $tmp_return = $getDifferentAmountALL[$value['data_order_no']] ?? 0;
|
|
|
+ //收款
|
|
|
+ $total = bcsub(bcsub($total_amount, $tmp_receipt), $tmp_return, 2);
|
|
|
+ }elseif($data['type'] == PaymentReceipt::type_three){
|
|
|
+ //红冲 = 审核后的收款金额 - 已红冲
|
|
|
+ //总金额 收款金额(审核后)
|
|
|
+ $total_amount = $info_one_array[$value['data_order_no']] ?? 0;
|
|
|
+ //已红冲
|
|
|
+ $tmp_receipt = $infos_map[$value['data_order_no']] ?? 0;
|
|
|
+ //红冲
|
|
|
+ $total = bcsub($total_amount, $tmp_receipt, 2);
|
|
|
}
|
|
|
+
|
|
|
+ $tmp = [
|
|
|
+ 'data_order_no' => $value['data_order_no'],
|
|
|
+ 'total_amount' => $total,//总共能填的金额
|
|
|
+ 'has_amount' => $tmp_receipt,//已经填的金额
|
|
|
+ 'amount' => $value['amount'],//本单金额
|
|
|
+ 'receipt_amount' => $value['amount'],//本单金额
|
|
|
+ ];
|
|
|
+ $return[] = $tmp;
|
|
|
}
|
|
|
|
|
|
- return [true, $customer];
|
|
|
+ return $return;
|
|
|
}
|
|
|
|
|
|
public function customerList($data,$user){
|
|
@@ -429,9 +466,6 @@ class PaymentReceiptService extends Service
|
|
|
$data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
|
|
|
}
|
|
|
|
|
|
- list($status,$msg) = $this->limitingSendRequestBackgExpire("paymentReceipt" . $data['order_number']);
|
|
|
- if(! $status) return [false, $msg];
|
|
|
-
|
|
|
if($is_add){
|
|
|
$bool = PaymentReceipt::where('del_time',0)
|
|
|
->where('order_number',$data['order_number'])
|
|
@@ -445,6 +479,184 @@ class PaymentReceiptService extends Service
|
|
|
if($booking['state'] != PaymentReceipt::STATE_ZERO) return [false,'请确认收付款单状态,编辑失败'];
|
|
|
}
|
|
|
|
|
|
+// list($status,$msg) = $this->limitingSendRequestBackgExpire("paymentReceipt" . $data['order_number']);
|
|
|
+// if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ list($status,$msg) = $this->checkRule($data);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function checkRule($data){
|
|
|
+ $payment_receipt_id = $data['id'] ?? 0;
|
|
|
+ $map = [];
|
|
|
+ foreach ($data['amount_list'] as $value){
|
|
|
+ $map[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ $search = array_keys($map);
|
|
|
+
|
|
|
+ if($data['data_type'] == PaymentReceipt::data_type_one){ //合同逻辑
|
|
|
+ //总金额
|
|
|
+ $result = SalesOrder::where('del_time',0)
|
|
|
+ ->whereIn('order_number',$search)
|
|
|
+ ->select('id','order_number','contract_fee as total_amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(count($search) != count($result)) {
|
|
|
+ foreach ($result as $value){
|
|
|
+ if(! isset($map[$value['order_number']])) return [false, $value['order_number'] . '不存在或已被删除'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result_map = array_column($result,'order_number','id');
|
|
|
+
|
|
|
+ //收付款金额
|
|
|
+ $info = PaymentReceiptInfo::where('del_time',0)
|
|
|
+ ->where('type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('data_order_type',PaymentReceipt::data_type_one)
|
|
|
+ ->whereIn('data_order_no',$search)
|
|
|
+ ->where('data_type',$data['type'])
|
|
|
+ ->select('payment_receipt_id','data_order_no','amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $info_array = [];
|
|
|
+ foreach ($info as $value){
|
|
|
+ if($payment_receipt_id > 0 && $value['payment_receipt_id'] == $payment_receipt_id) continue;
|
|
|
+ if(isset($info_array[$value['data_order_no']])){
|
|
|
+ $info_array[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $info_array[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //退货退款金额
|
|
|
+ $return_exchange = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($result,'id'));
|
|
|
+
|
|
|
+ if($data['type'] == PaymentReceipt::type_one){
|
|
|
+ $return_exchange_array = [];
|
|
|
+ foreach ($result_map as $key => $value){
|
|
|
+ // order_number => amount
|
|
|
+ if(isset($return_exchange[$key])) $return_exchange_array[$value] = $return_exchange[$key];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($result as $value){
|
|
|
+ //收款 = 总金额 - 已收 - 退货退款
|
|
|
+ //$max = $value['total_amount'] - $tmp_receipt - $tmp_return;
|
|
|
+ $tmp_receipt = $info_array[$value['order_number']] ?? 0;
|
|
|
+ $tmp_return = $return_exchange_array[$value['order_number']] ?? 0;
|
|
|
+ $max = bcsub(bcsub($value['total_amount'], $tmp_receipt), $tmp_return, 2);
|
|
|
+ if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
|
|
|
+ }
|
|
|
+ }elseif($data['type'] == PaymentReceipt::type_three){
|
|
|
+ //收款金额(审核后)
|
|
|
+ $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
|
|
|
+ ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
|
|
|
+ ->where('b.state',PaymentReceipt::STATE_TWO)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('a.type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('a.data_order_type',PaymentReceipt::data_type_one)
|
|
|
+ ->whereIn('a.data_order_no',$search)
|
|
|
+ ->where('a.data_type',PaymentReceipt::type_one)
|
|
|
+ ->select('a.payment_receipt_id','a.data_order_no','a.amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $info_one_array = [];
|
|
|
+ foreach ($info_one as $value){
|
|
|
+ if(isset($info_one_array[$value['data_order_no']])){
|
|
|
+ $info_one_array[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $info_one_array[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($result as $value){
|
|
|
+ //红冲 = 审核后的收款单金额 - 已红冲
|
|
|
+ $tmp_receipt = $info_one_array[$value['order_number']] ?? 0;
|
|
|
+ $tmp_return = $info_array[$value['order_number']] ?? 0;
|
|
|
+ $max = bcsub($tmp_receipt, $tmp_return, 2);
|
|
|
+ if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }elseif ($data['data_type'] == PaymentReceipt::data_type_two){//采购逻辑
|
|
|
+ //总金额
|
|
|
+ $result = PurchaseOrder::where('del_time',0)
|
|
|
+ ->whereIn('order_number',$search)
|
|
|
+ ->select('id','order_number','purchase_total as total_amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(count($search) != count($result)) {
|
|
|
+ foreach ($result as $value){
|
|
|
+ if(! isset($map[$value['order_number']])) return [false, $value['order_number'] . '不存在或已被删除'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result_map = array_column($result,'order_number','id');
|
|
|
+
|
|
|
+ //收付款金额
|
|
|
+ $info = PaymentReceiptInfo::where('del_time',0)
|
|
|
+ ->where('type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('data_order_type',PaymentReceipt::data_type_two)
|
|
|
+ ->whereIn('data_order_no',$search)
|
|
|
+ ->where('data_type',$data['type'])
|
|
|
+ ->select('payment_receipt_id','data_order_no','amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $info_array = [];
|
|
|
+ foreach ($info as $value){
|
|
|
+ if($payment_receipt_id > 0 && $value['payment_receipt_id'] == $payment_receipt_id) continue;
|
|
|
+ if(isset($info_array[$value['data_order_no']])){
|
|
|
+ $info_array[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $info_array[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //退货退款金额
|
|
|
+ $return_exchange = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($result,'id'),1);
|
|
|
+
|
|
|
+ if($data['type'] == PaymentReceipt::type_one){
|
|
|
+ $return_exchange_array = [];
|
|
|
+ foreach ($result_map as $key => $value){
|
|
|
+ // order_number => amount
|
|
|
+ if(isset($return_exchange[$key])) $return_exchange_array[$value] = $return_exchange[$key];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($result as $value){
|
|
|
+ //收款 = 总金额 - 已收 - 退货退款
|
|
|
+ //$max = $value['total_amount'] - $tmp_receipt - $tmp_return;
|
|
|
+ $tmp_receipt = $info_array[$value['order_number']] ?? 0;
|
|
|
+ $tmp_return = $return_exchange_array[$value['order_number']] ?? 0;
|
|
|
+ $max = bcsub(bcsub($value['total_amount'], $tmp_receipt), $tmp_return, 2);
|
|
|
+ if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
|
|
|
+ }
|
|
|
+ }elseif($data['type'] == PaymentReceipt::type_three){
|
|
|
+ //收款金额(审核后)
|
|
|
+ $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
|
|
|
+ ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
|
|
|
+ ->where('b.state',PaymentReceipt::STATE_TWO)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('a.type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('a.data_order_type',PaymentReceipt::data_type_one)
|
|
|
+ ->whereIn('a.data_order_no',$search)
|
|
|
+ ->where('a.data_type',PaymentReceipt::type_one)
|
|
|
+ ->select('a.payment_receipt_id','a.data_order_no','a.amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $info_one_array = [];
|
|
|
+ foreach ($info_one as $value){
|
|
|
+ if(isset($info_one_array[$value['data_order_no']])){
|
|
|
+ $info_one_array[$value['data_order_no']] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $info_one_array[$value['data_order_no']] = $value['amount'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($result as $value){
|
|
|
+ //红冲 = 审核后的收款单金额 - 已红冲
|
|
|
+ $tmp_receipt = $info_one_array[$value['order_number']] ?? 0;
|
|
|
+ $tmp_return = $info_array[$value['order_number']] ?? 0;
|
|
|
+ $max = bcsub($tmp_receipt, $tmp_return, 2);
|
|
|
+ if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
@@ -485,29 +697,21 @@ class PaymentReceiptService extends Service
|
|
|
}
|
|
|
|
|
|
//详情里
|
|
|
- public function getPaymentReceiptDataList($data){
|
|
|
+ public function getPaymentReceiptDataList($data,$type){
|
|
|
$data['data_order_no'] = $data['order_number'];
|
|
|
|
|
|
- $info1 = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->where('data_order_no',$data['data_order_no'])
|
|
|
- ->where('type',PaymentReceiptInfo::type_three)
|
|
|
- ->get()->toArray();
|
|
|
- $map = [];
|
|
|
- foreach ($info1 as $value){
|
|
|
- $key = $value['payment_receipt_id'] . $value['data_type'];
|
|
|
- if(isset($map[$key])){
|
|
|
- $map[$key] += $value['amount'];
|
|
|
- }else{
|
|
|
- $map[$key] = $value['amount'];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $order = PaymentReceipt::where('del_time',0)
|
|
|
- ->whereIn('id',array_column($info1,'payment_receipt_id'))
|
|
|
+ $info_array = PaymentReceiptInfo::from('payment_receipt_info as a')
|
|
|
+ ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('a.type',PaymentReceiptInfo::type_three)
|
|
|
+ ->where('a.data_order_type',$type)
|
|
|
+ ->where('a.data_order_no',$data['data_order_no'])
|
|
|
+ ->select('a.payment_receipt_id','a.data_order_no','a.amount','a.data_type','b.state','b.payment_receipt_date')
|
|
|
->get()->toArray();
|
|
|
|
|
|
$emp_id = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->whereIn('payment_receipt_id',array_column($order,'id'))
|
|
|
+ ->whereIn('payment_receipt_id',array_column($info_array,'payment_receipt_id'))
|
|
|
->where('type',PaymentReceiptInfo::type_two)
|
|
|
->get()->toArray();
|
|
|
$info = [];
|
|
@@ -517,69 +721,63 @@ class PaymentReceiptService extends Service
|
|
|
->toArray();
|
|
|
foreach ($emp_id as $value){
|
|
|
$name = $emp_map[$value['data_id']] ?? "";
|
|
|
- if(isset($info[$value['data_id']])){
|
|
|
- $info[$value['data_id']] .= ',' . $name;
|
|
|
+ if(isset($info[$value['payment_receipt_id']])){
|
|
|
+ $info[$value['payment_receipt_id']] .= ',' . $name;
|
|
|
}else{
|
|
|
- $info[$value['data_id']] = $name;
|
|
|
+ $info[$value['payment_receipt_id']] = $name;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//四个金额类型
|
|
|
- $one = $two = $three = $four = 0;
|
|
|
- foreach ($order as $key => $value){
|
|
|
- $keys = $value['id'] . $value['type'];
|
|
|
-
|
|
|
+ $one = $two = $three = $four = $not_confirm_receipt_amount = 0;
|
|
|
+ foreach ($info_array as $key => $value){
|
|
|
//归属人
|
|
|
- $order[$key]['belong'] = $info[$value['id']] ?? '';
|
|
|
- $order[$key]['state_title'] = PaymentReceipt::$name[$value['state']] ?? '';
|
|
|
- $order[$key]['type_title'] = PaymentReceipt::$model_type[$value['type']] ?? '';
|
|
|
- $order[$key]['payment_receipt_date'] = $value['payment_receipt_date'] ? date('Y-m-d',$value['payment_receipt_date']) : '';
|
|
|
-
|
|
|
- //统计每个收付款单 =》总收付款金额
|
|
|
- $amount = $map[$keys] ?? 0;
|
|
|
- $order[$key]['amount'] = $amount;
|
|
|
-
|
|
|
- if($value['type'] == PaymentReceipt::type_one){
|
|
|
- $one += $amount;
|
|
|
- }elseif($value['type'] == PaymentReceipt::type_two){
|
|
|
- $two += $amount;
|
|
|
- }elseif($value['type'] == PaymentReceipt::type_three){
|
|
|
- $three += $amount;
|
|
|
- }elseif($value['type'] == PaymentReceipt::type_four){
|
|
|
- $four += $amount;
|
|
|
+ $info_array[$key]['belong'] = $info[$value['payment_receipt_id']] ?? '';
|
|
|
+ $info_array[$key]['state_title'] = PaymentReceipt::$name[$value['state']] ?? '';
|
|
|
+ $info_array[$key]['type_title'] = PaymentReceipt::$model_type[$value['data_type']] ?? '';
|
|
|
+ $info_array[$key]['payment_receipt_date'] = $value['payment_receipt_date'] ? date('Y-m-d',$value['payment_receipt_date']) : '';
|
|
|
+
|
|
|
+ if($value['data_type'] == PaymentReceipt::type_one) $not_confirm_receipt_amount += $value['amount'];
|
|
|
+ if($value['data_type'] == PaymentReceipt::type_one && $value['state'] == PaymentReceipt::STATE_TWO){
|
|
|
+ $one += $value['amount'];
|
|
|
+ }elseif ($value['data_type'] == PaymentReceipt::type_three && $value['state'] == PaymentReceipt::STATE_TWO){
|
|
|
+ $three += $value['amount'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $return['receipt_amount'] = $one;
|
|
|
+ $return['receipt_amount'] = bcsub($one, $three, 2); // 已回款金额
|
|
|
$return['not_receipt_amount'] = 0;
|
|
|
- $return['red_amount'] = $three;
|
|
|
+ $return['red_amount'] = $three;// 已红冲金额
|
|
|
$return['bad_amount'] = $four;
|
|
|
- $return['all_count'] = count($order);
|
|
|
- $return['list'] = $order;
|
|
|
+ $return['all_count'] = count($info_array);
|
|
|
+ $return['not_confirm_receipt_amount'] = $not_confirm_receipt_amount;
|
|
|
+ $return['list'] = $info_array;
|
|
|
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
//列表里 默认:(收款)
|
|
|
- public function getPaymentReceiptDataCountList($data,$type=0){
|
|
|
- $data_order_no = [];
|
|
|
- if(! $type){
|
|
|
- foreach ($data as $value){
|
|
|
- $data_order_no[] = $value['order_number'];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $data_order_no = $data;
|
|
|
- }
|
|
|
-
|
|
|
+ public function getPaymentReceiptDataCountList($data){
|
|
|
+ $data_order_no = $data;
|
|
|
if(empty($data_order_no)) return [];
|
|
|
|
|
|
- $order = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->where('type',PaymentReceiptInfo::type_three)
|
|
|
- ->whereIn('data_order_no',$data_order_no)
|
|
|
+ $order = PaymentReceiptInfo::from('payment_receipt_info as a')
|
|
|
+ ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('a.type',PaymentReceiptInfo::type_three)
|
|
|
+ ->whereIn('a.data_order_no',$data_order_no)
|
|
|
+ ->select('a.payment_receipt_id','a.data_order_no','a.amount','a.data_type','b.state','b.payment_receipt_date')
|
|
|
->get()->toArray();
|
|
|
|
|
|
- $return = [];
|
|
|
+// $order = PaymentReceiptInfo::where('del_time',0)
|
|
|
+// ->where('type',PaymentReceiptInfo::type_three)
|
|
|
+// ->whereIn('data_order_no',$data_order_no)
|
|
|
+// ->get()->toArray();
|
|
|
+
|
|
|
+ // 所有状态都统计 审核成功的统计
|
|
|
+ $return = $return1 = [];
|
|
|
foreach ($order as $value){
|
|
|
$key = $value['data_order_no'] . $value['data_type'];
|
|
|
if(isset($return[$key])){
|
|
@@ -587,72 +785,17 @@ class PaymentReceiptService extends Service
|
|
|
}else{
|
|
|
$return[$key] = $value['amount'];
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
- }
|
|
|
|
|
|
- //废弃
|
|
|
- public function getPaymentReceiptDeatail($data){
|
|
|
- $customer = PaymentReceipt::where('del_time',0)
|
|
|
- ->where('crt_time',$data['crt_time'])
|
|
|
- ->where('id',$data['id'])
|
|
|
- ->first();
|
|
|
- if(empty($customer)) return [];
|
|
|
- $customer = $customer->toArray();
|
|
|
- $array = [
|
|
|
- $customer['account'],
|
|
|
- $customer['pay_way'],
|
|
|
- ];
|
|
|
- $basic_map = BasicType::whereIn('id',$array)
|
|
|
- ->pluck('title','id')
|
|
|
- ->toArray();
|
|
|
- $customer['account_title'] = $basic_map[$customer['account']] ?? "";
|
|
|
- $customer['pay_way_title'] = $basic_map[$customer['pay_way']] ?? "";
|
|
|
- $customer['state_title'] = PaymentReceipt::$name[$customer['state']] ?? "";
|
|
|
- $customer['type_title'] = PaymentReceipt::$model_type[$customer['type']] ?? "";
|
|
|
- $customer['data_type_title'] = PaymentReceipt::$data_type[$customer['data_type']] ?? "";
|
|
|
- $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
|
|
|
- $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
|
|
|
- $customer['payment_receipt_date'] = $customer['payment_receipt_date'] ? date("Y-m-d",$customer['payment_receipt_date']): '';
|
|
|
- $customer['receipt_amount'] = $customer['state'] == PaymentReceipt::STATE_TWO ? $customer['amount'] : 0;
|
|
|
-
|
|
|
- $file = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->where('payment_receipt_id',$data['id'])
|
|
|
- ->get()->toArray();
|
|
|
- $emp_id = [];
|
|
|
- foreach ($file as $value){
|
|
|
- if(in_array($value['type'],PaymentReceiptInfo::$man)){
|
|
|
- $emp_id[] = $value['data_id'];
|
|
|
- }
|
|
|
- }
|
|
|
- $emp_map = Employee::whereIn('id',array_unique($emp_id))
|
|
|
- ->pluck('emp_name','id')
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- $customer['file'] = $customer['employee_one'] = [];
|
|
|
- foreach ($file as $value){
|
|
|
- if($value['type'] == PaymentReceiptInfo::type_one){
|
|
|
- $tmp = [
|
|
|
- 'url' => $value['file'],
|
|
|
- 'name' => $value['name'],
|
|
|
- ];
|
|
|
- $customer['file'][] = $tmp;
|
|
|
- }elseif (in_array($value['type'],PaymentReceiptInfo::$man)){
|
|
|
- $tt = $emp_map[$value['data_id']] ?? '';
|
|
|
- if(! empty($tt)){
|
|
|
- $tmp = [
|
|
|
- 'id' => $value['data_id'],
|
|
|
- 'name' => $emp_map[$value['data_id']] ?? '',
|
|
|
- ];
|
|
|
- if($value['type'] == PaymentReceiptInfo::type_two){
|
|
|
- $customer['employee_one'][] = $tmp;
|
|
|
- }
|
|
|
+ if($value['state'] == PaymentReceipt::STATE_TWO){
|
|
|
+ if(isset($return1[$key])){
|
|
|
+ $return1[$key] += $value['amount'];
|
|
|
+ }else{
|
|
|
+ $return1[$key] = $value['amount'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $customer;
|
|
|
+ return [$return, $return1];
|
|
|
}
|
|
|
|
|
|
public function maked(){
|