|
@@ -214,7 +214,7 @@ class PaymentReceiptService extends Service
|
|
|
$customer = PaymentReceipt::where('del_time',0)
|
|
|
->where('id',$data['id'])
|
|
|
->first();
|
|
|
- if(empty($customer)) return [false,'记录不存在或已被删除'];
|
|
|
+ if(empty($customer)) return [false,'收付款记录不存在或已被删除'];
|
|
|
$customer = $customer->toArray();
|
|
|
$array = [
|
|
|
$customer['account'],
|
|
@@ -263,10 +263,11 @@ class PaymentReceiptService extends Service
|
|
|
->get()->toArray();
|
|
|
$infos_map = [];
|
|
|
foreach ($infos as $value){
|
|
|
- if(isset($infos_map[$value['data_order_no']])){
|
|
|
- $infos_map[$value['data_order_no']] += $value['amount'];
|
|
|
+ $keys = $value['data_order_no'] . $value['data_type'];
|
|
|
+ if(isset($infos_map[$keys])){
|
|
|
+ $infos_map[$keys] += $value['amount'];
|
|
|
}else{
|
|
|
- $infos_map[$value['data_order_no']] = $value['amount'];
|
|
|
+ $infos_map[$keys] = $value['amount'];
|
|
|
}
|
|
|
}
|
|
|
$emp_map = Employee::whereIn('id',array_unique($emp_id))
|
|
@@ -294,13 +295,42 @@ class PaymentReceiptService extends Service
|
|
|
}
|
|
|
}
|
|
|
}elseif ($value['type'] == PaymentReceiptInfo::type_three){
|
|
|
- $total = ($order[$value['data_order_no']] ?? 0) + ($getDifferentAmountALL[$value['data_order_no']] ?? 0);
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
$tmp = [
|
|
|
'data_order_no' => $value['data_order_no'],
|
|
|
'amount' => $value['amount'],
|
|
|
'total_amount' => $total,
|
|
|
- 'has_amount' => $infos_map[$value['data_order_no']] ?? 0,
|
|
|
- 'receipt_amount' => $customer['state'] == PaymentReceipt::STATE_TWO ? $value['amount'] : 0
|
|
|
+ 'has_amount' => $has_amount,
|
|
|
+ 'receipt_amount' => $receipt_amount
|
|
|
];
|
|
|
$customer['amount_list'][] = $tmp;
|
|
|
}
|
|
@@ -434,10 +464,11 @@ class PaymentReceiptService extends Service
|
|
|
->get()->toArray();
|
|
|
$map = [];
|
|
|
foreach ($info1 as $value){
|
|
|
- if(isset($map[$value['payment_receipt_id']])){
|
|
|
- $map[$value['payment_receipt_id']] += $value['amount'];
|
|
|
+ $key = $value['payment_receipt_id'] . $value['data_type'];
|
|
|
+ if(isset($map[$key])){
|
|
|
+ $map[$key] += $value['amount'];
|
|
|
}else{
|
|
|
- $map[$value['payment_receipt_id']] = $value['amount'];
|
|
|
+ $map[$key] = $value['amount'];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -464,26 +495,43 @@ class PaymentReceiptService extends Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $finished = $not_finished = 0;
|
|
|
+ //四个金额类型
|
|
|
+ $one = $two = $three = $four = 0;
|
|
|
foreach ($order as $key => $value){
|
|
|
- $tmp = $info[$value['id']] ?? '';
|
|
|
- $order[$key]['belong'] = $tmp;
|
|
|
+ $keys = $value['id'] . $value['type'];
|
|
|
+
|
|
|
+ //归属人
|
|
|
+ $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[$value['id']] ?? 0;
|
|
|
+
|
|
|
+ //统计每个收付款单 =》总收付款金额
|
|
|
+ $amount = $map[$keys] ?? 0;
|
|
|
$order[$key]['amount'] = $amount;
|
|
|
- $finished += $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;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $return['receipt_amount'] = $finished;
|
|
|
- $return['not_receipt_amount'] = $not_finished;
|
|
|
+ $return['receipt_amount'] = $one;
|
|
|
+ $return['not_receipt_amount'] = 0;
|
|
|
+ $return['red_amount'] = $three;
|
|
|
+ $return['bad_amount'] = $four;
|
|
|
$return['all_count'] = count($order);
|
|
|
$return['list'] = $order;
|
|
|
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
- //列表里
|
|
|
+ //列表里 默认:(收款)
|
|
|
public function getPaymentReceiptDataCountList($data){
|
|
|
$data_order_no = [];
|
|
|
foreach ($data as $value){
|
|
@@ -498,10 +546,11 @@ class PaymentReceiptService extends Service
|
|
|
|
|
|
$return = [];
|
|
|
foreach ($order as $value){
|
|
|
- if(isset($return[$value['data_order_no']])){
|
|
|
- $return[$value['data_order_no']] += $value['amount'];
|
|
|
+ $key = $value['data_order_no'] . $value['data_type'];
|
|
|
+ if(isset($return[$key])){
|
|
|
+ $return[$key] += $value['amount'];
|
|
|
}else{
|
|
|
- $return[$value['data_order_no']] = $value['amount'];
|
|
|
+ $return[$key] = $value['amount'];
|
|
|
}
|
|
|
}
|
|
|
|