|
@@ -10,6 +10,7 @@ use App\Model\InOutRecord;
|
|
|
use App\Model\InvoiceOrder;
|
|
|
use App\Model\InvoiceOrderInfo;
|
|
|
use App\Model\OrderOperation;
|
|
|
+use App\Model\PaymentReceipt;
|
|
|
use App\Model\ProductInventory;
|
|
|
use App\Model\ProductInventorySet;
|
|
|
use App\Model\PurchaseOrder;
|
|
@@ -40,17 +41,20 @@ class CheckService extends Service
|
|
|
const seven = 7; //采购单确认
|
|
|
const eight = 8; //合同确认
|
|
|
const nine = 9; //合同客户完结
|
|
|
+ const ten = 10; //收付款确认
|
|
|
|
|
|
//中文对照
|
|
|
public $map = [
|
|
|
self::one => '收货单',
|
|
|
self::two => '发货单',//确认后出库
|
|
|
- self::three => '采购单',//确认后入库
|
|
|
- self::four => '合同', // 安装件 合同完结
|
|
|
+ self::three => '采购单入库',//确认后入库
|
|
|
+ self::four => '公司完结', // 安装件 合同完结
|
|
|
self::five => '施工单',//确认后出库
|
|
|
self::six => '退换货单',//确认后出库或出库入库
|
|
|
self::seven => '采购单确认',
|
|
|
self::eight => '合同确认',
|
|
|
+ self::nine => '合同客户完结',
|
|
|
+ self::ten => '收付款确认',
|
|
|
];
|
|
|
|
|
|
//入库操作
|
|
@@ -81,6 +85,7 @@ class CheckService extends Service
|
|
|
self::six => 'waitReturnExchange',//退换货单
|
|
|
self::seven => 'waitPurchaseConfirm', //采购单确认
|
|
|
self::eight => 'waitSales', // 合同安装件 合同确认
|
|
|
+ self::ten => 'waitPaymentReceipt', //收付款确认
|
|
|
];
|
|
|
|
|
|
public static $finished = [
|
|
@@ -97,6 +102,7 @@ class CheckService extends Service
|
|
|
self::six => 'confirmReturnExchangeOrder',
|
|
|
self::seven => 'confirmPurchaseOrderState',
|
|
|
self::eight => 'confirmSales', // 合同 安装件 合同确认
|
|
|
+ self::ten => 'confirmPaymentReceipt', // 确认收付款单
|
|
|
];
|
|
|
|
|
|
//单据库存流水
|
|
@@ -139,10 +145,11 @@ class CheckService extends Service
|
|
|
public static $operation_order = [
|
|
|
self::eight => OrderOperation::three, //合同确认
|
|
|
self::two => OrderOperation::eight, //发货单确认
|
|
|
- self::six => OrderOperation::nine, //退换货审核通过
|
|
|
- self::five => OrderOperation::eve, //施工单通过
|
|
|
+ self::six => OrderOperation::nine, //退换货审核
|
|
|
+ self::five => OrderOperation::eve, //施工单
|
|
|
self::seven => OrderOperation::thi,//采购单确认
|
|
|
- self::three => OrderOperation::fourteen,//采购单入库审核通过
|
|
|
+ self::three => OrderOperation::fourteen,//采购单入库
|
|
|
+ self::ten => OrderOperation::twenty_one,//收付款单
|
|
|
];
|
|
|
|
|
|
//旅程日志 驳回
|
|
@@ -152,6 +159,7 @@ class CheckService extends Service
|
|
|
self::five => OrderOperation::twl, //施工单弃审
|
|
|
self::three => OrderOperation::fif,//采购单入库弃审
|
|
|
self::seven => OrderOperation::twenty,//采购单确认弃审
|
|
|
+ self::ten => OrderOperation::twenty_two,//收付款单
|
|
|
];
|
|
|
|
|
|
//校验
|
|
@@ -277,6 +285,19 @@ class CheckService extends Service
|
|
|
|
|
|
return [true, $model->toArray()];
|
|
|
}
|
|
|
+
|
|
|
+ public function waitPaymentReceipt($data){
|
|
|
+ $model = PaymentReceipt::where('id', $data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(empty($model)) return [false, '收付款单不存在或已被删除'];
|
|
|
+ if($model->state != PaymentReceipt::STATE_ZERO) return [false, '请确认收付款单状态,操作失败'];
|
|
|
+
|
|
|
+ PaymentReceipt::where('del_time',0)->where('id',$data['id'])
|
|
|
+ ->update(['state' => PaymentReceipt::STATE_ONE]);
|
|
|
+
|
|
|
+ return [true, $model->toArray()];
|
|
|
+ }
|
|
|
//改为待审核---------------------------------
|
|
|
|
|
|
//自动生成-----------------------------------
|
|
@@ -381,14 +402,13 @@ class CheckService extends Service
|
|
|
if(empty($product)) return [false, '采购订单产品数据不能为空'];
|
|
|
|
|
|
$time = time();
|
|
|
- $depart_id = Depart::where('del_time',0)->where('parent_id',0)->where('is_main',1)->value('id');
|
|
|
$model = new SalesOrder();
|
|
|
$model->model_type = SalesOrder::Model_type_two;
|
|
|
$model->sales_order_type = SalesOrder::Order_type_two;
|
|
|
$model->order_number = $order_number;
|
|
|
$model->crt_id = $order['crt_id'];
|
|
|
- $model->depart_id = $depart_id;
|
|
|
- $model->top_depart_id = $depart_id;
|
|
|
+ $model->depart_id = $head;
|
|
|
+ $model->top_depart_id = $head;
|
|
|
$model->other_fee = $order['other_fee'];
|
|
|
$model->discount_fee = $order['discount_fee'];
|
|
|
$model->contract_fee = $order['purchase_total'];
|
|
@@ -401,25 +421,10 @@ class CheckService extends Service
|
|
|
//产品字典
|
|
|
$product_map = (new ProductService())->getProductDetail(array_column($product,'product_id'));
|
|
|
|
|
|
-// //获取产品采购使用金额
|
|
|
-// $map = (new ProductService())->getProductPrice(array_column($product,'product_id'));
|
|
|
-// //获取部门目前使用的分社价
|
|
|
-// $basic_type_id = Depart::where('id',$order['top_depart_id'])->value('basic_type_id');
|
|
|
-// //产品对应的分社价
|
|
|
-// $new_map = [];
|
|
|
-// foreach ($map as $product_id => $value){
|
|
|
-// foreach ($value as $v){
|
|
|
-// if($v['basic_type_id'] == $basic_type_id && ! empty($v['price'])) $new_map[$product_id] = $v['price'];
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
$insert = [];
|
|
|
$product_total = 0;
|
|
|
foreach ($product as $value){
|
|
|
$tmp = $product_map[$value['product_id']] ?? [];
|
|
|
-// $fs_price = $new_map[$value['product_id']] ?? 0;
|
|
|
- //有分社价就是分社价格 没有就是零售
|
|
|
-// $price = $fs_price ? $fs_price : $tmp['retail_price'];
|
|
|
$product_total += $value['price'] * $value['number'];
|
|
|
$insert[] = [
|
|
|
'sales_order_id' => $sales_order_id,
|
|
@@ -436,15 +441,26 @@ class CheckService extends Service
|
|
|
if(! $bool) return [false,'合同生成失败!'];
|
|
|
|
|
|
//反写数据
|
|
|
-
|
|
|
$tmp = $product_total + $order['other_fee'];
|
|
|
$tmp = $tmp > 0 ? $tmp : 1;
|
|
|
$rate = ($product_total + $order['other_fee'] - $order['discount_fee']) / $tmp;
|
|
|
SalesOrder::where('id',$sales_order_id)->update([
|
|
|
'product_total' => $product_total,
|
|
|
- 'rate' =>$rate
|
|
|
+ 'rate' => $rate
|
|
|
]);
|
|
|
|
|
|
+ //生成付款单
|
|
|
+ $model = new PaymentReceipt();
|
|
|
+ $model->order_number = OrderNoService::createOrderNumber(PaymentReceipt::prefix);
|
|
|
+ $model->data_order_no = $order_number;
|
|
|
+ $model->data_type = PaymentReceipt::data_type_one;
|
|
|
+ $model->type = PaymentReceipt::type_one;
|
|
|
+ $model->amount = $order['purchase_total'] ?? 0;
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
+ $model->depart_id = $head;
|
|
|
+ $model->top_depart_id = $head;
|
|
|
+ $model->save();
|
|
|
+
|
|
|
return [true,''];
|
|
|
}
|
|
|
//自动生成-----------------------------------
|
|
@@ -453,13 +469,15 @@ class CheckService extends Service
|
|
|
public function delCreatePurchaseOrderSales($data, $order){
|
|
|
$sale_order = SalesOrder::where('del_time',0)
|
|
|
->where('contact_order_no',$order['order_number'])
|
|
|
- ->select('id')
|
|
|
+ ->select('id','order_number')
|
|
|
->get()->toArray();
|
|
|
if(empty($sale_order)) return [true,''];
|
|
|
- $sale_order = array_column($sale_order,'id');
|
|
|
|
|
|
foreach ($sale_order as $value){
|
|
|
- list($status, $msg) = (new SalesOrderService())->salesOrderDel(['id' => $value]);
|
|
|
+ list($status, $msg) = (new SalesOrderService())->salesOrderDel(['id' => $value['id']]);
|
|
|
+ if(! $status) return [false,$msg];
|
|
|
+
|
|
|
+ list($status, $msg) = (new PaymentReceiptService())->customerDel(['id' => $value['id']]);
|
|
|
if(! $status) return [false,$msg];
|
|
|
}
|
|
|
|
|
@@ -468,6 +486,26 @@ class CheckService extends Service
|
|
|
|
|
|
//自动生成删除
|
|
|
|
|
|
+ public function confirmPaymentReceipt($data){
|
|
|
+ $model = PaymentReceipt::where('order_number',$data['order_number'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(empty($model)) return [false, '收付款单不存在或已被删除'];
|
|
|
+ if($model->state != PaymentReceipt::STATE_ONE) return [false, '请确认收付款单状态,操作失败'];
|
|
|
+
|
|
|
+ if($data['type'] == self::TYPE_ONE){
|
|
|
+ //通过
|
|
|
+ $model->state = PaymentReceipt::STATE_TWO;
|
|
|
+ $model->save();
|
|
|
+ }else{
|
|
|
+ //驳回
|
|
|
+ $model->state = InvoiceOrder::STATE_ZERO;
|
|
|
+ $model->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $model->toArray()];
|
|
|
+ }
|
|
|
+
|
|
|
public function confirmInvoiceOrder($data){
|
|
|
$model = InvoiceOrder::where('order_number',$data['order_number'])
|
|
|
->where('del_time',0)
|