|
|
@@ -2586,8 +2586,8 @@ class WorkOrderSpotCheck extends Api{
|
|
|
'关联号' => $item['关联编号'],
|
|
|
'物料编号' => $item['物料编码'],
|
|
|
'物料名称' => $item['物料名称'],
|
|
|
- '领用数量' => intval($Inventory['领用数量']) + intval($item['number']),
|
|
|
- '库存数量' => intval($Inventory['库存数量']) - intval($item['number']),
|
|
|
+ '领用数量' => $Inventory['领用数量'] + $item['number'],
|
|
|
+ '库存数量' => $Inventory['库存数量'] - $item['number'],
|
|
|
'实际门幅' => $item['实际门幅'],
|
|
|
'单位' => $item['单位'],
|
|
|
'状态' => 1,
|
|
|
@@ -2663,90 +2663,174 @@ class WorkOrderSpotCheck extends Api{
|
|
|
if (!$this->request->isPost()) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
+
|
|
|
$param = Request::instance()->post();
|
|
|
if (empty($param)) {
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
- foreach ($param as $item) {
|
|
|
- // 查询是否已存在批次号
|
|
|
- $BatchNumber = \db('物料_库存')
|
|
|
- ->where('物料编号', $item['物料编码'])
|
|
|
- ->where('关联号', $item['关联编号'])
|
|
|
- ->value('批次号');
|
|
|
-
|
|
|
- // 生成批次号
|
|
|
- if (empty($BatchNumber)) {
|
|
|
- $LastNumber = \db('物料_库存')->order('批次号 DESC')->value('批次号');
|
|
|
- $BatchNumber = !empty($LastNumber) ? 'PCH' . ((int)substr($LastNumber, 3) + 1) : 'PCH1';
|
|
|
-
|
|
|
- // 物料_库存
|
|
|
- $InventoryData = [
|
|
|
- '批次号' => $BatchNumber,
|
|
|
- '关联号' => $item['关联编号'],
|
|
|
- '物料编号' => $item['物料编码'],
|
|
|
- '物料名称' => $item['物料名称'],
|
|
|
- '入仓总量' => $item['number'],
|
|
|
- '库存数量' => $item['number'],
|
|
|
- '单位' => $item['单位'],
|
|
|
- '实际门幅' => $item['实际门幅'],
|
|
|
- '状态' => 1,
|
|
|
- 'departname' => $item['departname'],
|
|
|
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
- 'sys_id' => $item['sys_id'],
|
|
|
- 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
- ];
|
|
|
- $sql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
|
|
|
- \db()->query($sql);
|
|
|
- } else {
|
|
|
- // 更新库存数据
|
|
|
- $Inventory = \db('物料_库存')
|
|
|
- ->where('批次号', $BatchNumber)
|
|
|
- ->field('入仓总量,库存数量')
|
|
|
- ->find();
|
|
|
- $InventoryData = [
|
|
|
- '批次号' => $item['批次号'],
|
|
|
- '关联号' => $item['关联编号'],
|
|
|
- '物料编号' => $item['物料编码'],
|
|
|
- '物料名称' => $item['物料名称'],
|
|
|
- '入仓总量' => $Inventory['入仓总量'] + $item['number'],
|
|
|
- '库存数量' => $Inventory['库存数量'] + $item['number'],
|
|
|
- '实际门幅' => $item['实际门幅'],
|
|
|
- '单位' => $item['单位'],
|
|
|
- '状态' => 1,
|
|
|
- 'departname' => $item['departname'],
|
|
|
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
- 'sys_id' => $item['sys_id'],
|
|
|
- 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
- ];
|
|
|
- $sql = \db('物料_库存')->fetchSql(true)->where('批次号',$BatchNumber)->update($InventoryData);
|
|
|
- \db()->query($sql);
|
|
|
- }
|
|
|
|
|
|
- // 记录入库报工日志
|
|
|
- $ReportData = [
|
|
|
+ // 获取当前最大批次号
|
|
|
+ $lastBatch = \db('物料_库存')
|
|
|
+ ->field("批次号")
|
|
|
+ ->orderRaw("CAST(SUBSTRING(批次号, 4) AS UNSIGNED) DESC")
|
|
|
+ ->limit(1)
|
|
|
+ ->value('批次号');
|
|
|
+
|
|
|
+ $currentNumber = 0;
|
|
|
+ if (!empty($lastBatch) && preg_match('/^PCH(\d+)$/i', $lastBatch, $match)) {
|
|
|
+ $currentNumber = intval($match[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($param as $item) {
|
|
|
+ // 查找是否已有相同物料编号 + 关联号的库存记录
|
|
|
+ $existingBatch = \db('物料_库存')
|
|
|
+ ->where('物料编号', $item['物料编码'])
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
+ ->where('关联号', $item['关联编号'])
|
|
|
+ ->value('批次号');
|
|
|
+
|
|
|
+ if ($existingBatch) {
|
|
|
+ $BatchNumber = $existingBatch; // 已入库,使用原批次号
|
|
|
+ } else {
|
|
|
+ // 生成新批次号
|
|
|
+ $currentNumber++;
|
|
|
+ $BatchNumber = 'PCH' . $currentNumber;
|
|
|
+
|
|
|
+ // 插入库存表
|
|
|
+ $InventoryData = [
|
|
|
'批次号' => $BatchNumber,
|
|
|
- 'order_id' => $item['order_id'],
|
|
|
- '款号' => $item['款号'],
|
|
|
- '物料编码' => $item['物料编码'],
|
|
|
+ '关联号' => $item['关联编号'],
|
|
|
+ '物料编号' => $item['物料编码'],
|
|
|
'物料名称' => $item['物料名称'],
|
|
|
+ '入仓总量' => $item['number'],
|
|
|
'库存数量' => $item['number'],
|
|
|
- 'number' => $item['number'],
|
|
|
- 'rq' => $item['rq'],
|
|
|
- 'name' => $item['name'],
|
|
|
+ '单位' => $item['单位'],
|
|
|
+ '实际门幅' => $item['实际门幅'],
|
|
|
+ '状态' => 1,
|
|
|
+ 'departname' => $item['departname'],
|
|
|
+ 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
'sys_id' => $item['sys_id'],
|
|
|
- 'receipt_number' => $item['receipt_number'],
|
|
|
- 'departname' => $item['departname'],
|
|
|
- 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
- '客户编号' => $item['客户编号'],
|
|
|
- '款式' => $item['款式'],
|
|
|
- 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
+ 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
- $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
|
|
|
+ $sql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
|
|
|
\db()->query($sql);
|
|
|
}
|
|
|
- $this->success('成功');
|
|
|
+
|
|
|
+ // 每条都写一条报工日志
|
|
|
+ $ReportData = [
|
|
|
+ '批次号' => $BatchNumber,
|
|
|
+ 'order_id' => $item['order_id'],
|
|
|
+ '款号' => $item['款号'],
|
|
|
+ '物料编码' => $item['物料编码'],
|
|
|
+ '物料名称' => $item['物料名称'],
|
|
|
+ '库存数量' => $item['number'],
|
|
|
+ 'number' => $item['number'],
|
|
|
+ 'rq' => $item['rq'],
|
|
|
+ 'name' => $item['name'],
|
|
|
+ 'sys_id' => $item['sys_id'],
|
|
|
+ 'receipt_number' => $item['receipt_number'],
|
|
|
+ 'departname' => $item['departname'],
|
|
|
+ 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
+ '客户编号' => $item['客户编号'],
|
|
|
+ '款式' => $item['款式'],
|
|
|
+ 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+ $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
|
|
|
+ \db()->query($sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('成功');
|
|
|
}
|
|
|
|
|
|
+// public function inputStash()
|
|
|
+// {
|
|
|
+// if (!$this->request->isPost()) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+// $param = Request::instance()->post();
|
|
|
+// if (empty($param)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+// foreach ($param as $item) {
|
|
|
+// // 查询是否已存在批次号
|
|
|
+// $BatchNumber = \db('物料_库存')
|
|
|
+// ->where('物料编号', $item['物料编码'])
|
|
|
+// ->where('关联号', $item['关联编号'])
|
|
|
+// ->value('批次号');
|
|
|
+//
|
|
|
+// // 生成批次号
|
|
|
+// if (empty($BatchNumber)) {
|
|
|
+// $LastNumber = \db('物料_库存')->order('批次号 DESC')->value('批次号');
|
|
|
+// $BatchNumber = !empty($LastNumber) ? 'PCH' . ((int)substr($LastNumber, 3) + 1) : 'PCH1';
|
|
|
+//
|
|
|
+// // 物料_库存
|
|
|
+// $InventoryData = [
|
|
|
+// '批次号' => $BatchNumber,
|
|
|
+// '关联号' => $item['关联编号'],
|
|
|
+// '物料编号' => $item['物料编码'],
|
|
|
+// '物料名称' => $item['物料名称'],
|
|
|
+// '入仓总量' => $item['number'],
|
|
|
+// '库存数量' => $item['number'],
|
|
|
+// '单位' => $item['单位'],
|
|
|
+// '实际门幅' => $item['实际门幅'],
|
|
|
+// '状态' => 1,
|
|
|
+// 'departname' => $item['departname'],
|
|
|
+// 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
+// 'sys_id' => $item['sys_id'],
|
|
|
+// 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
+// ];
|
|
|
+// $sql = \db('物料_库存')->fetchSql(true)->insert($InventoryData);
|
|
|
+// \db()->query($sql);
|
|
|
+// } else {
|
|
|
+// // 更新库存数据
|
|
|
+// $Inventory = \db('物料_库存')
|
|
|
+// ->where('批次号', $BatchNumber)
|
|
|
+// ->field('入仓总量,库存数量')
|
|
|
+// ->find();
|
|
|
+// $InventoryData = [
|
|
|
+// '批次号' => $item['批次号'],
|
|
|
+// '关联号' => $item['关联编号'],
|
|
|
+// '物料编号' => $item['物料编码'],
|
|
|
+// '物料名称' => $item['物料名称'],
|
|
|
+// '入仓总量' => $Inventory['入仓总量'] + $item['number'],
|
|
|
+// '库存数量' => $Inventory['库存数量'] + $item['number'],
|
|
|
+// '实际门幅' => $item['实际门幅'],
|
|
|
+// '单位' => $item['单位'],
|
|
|
+// '状态' => 1,
|
|
|
+// 'departname' => $item['departname'],
|
|
|
+// 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
+// 'sys_id' => $item['sys_id'],
|
|
|
+// 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
+// ];
|
|
|
+// $sql = \db('物料_库存')->fetchSql(true)->where('批次号',$BatchNumber)->update($InventoryData);
|
|
|
+// \db()->query($sql);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 记录入库报工日志
|
|
|
+// $ReportData = [
|
|
|
+// '批次号' => $BatchNumber,
|
|
|
+// 'order_id' => $item['order_id'],
|
|
|
+// '款号' => $item['款号'],
|
|
|
+// '物料编码' => $item['物料编码'],
|
|
|
+// '物料名称' => $item['物料名称'],
|
|
|
+// '库存数量' => $item['number'],
|
|
|
+// 'number' => $item['number'],
|
|
|
+// 'rq' => $item['rq'],
|
|
|
+// 'name' => $item['name'],
|
|
|
+// 'sys_id' => $item['sys_id'],
|
|
|
+// 'receipt_number' => $item['receipt_number'],
|
|
|
+// 'departname' => $item['departname'],
|
|
|
+// 'remark' => isset($item['remark']) ? $item['remark'] : '',
|
|
|
+// '客户编号' => $item['客户编号'],
|
|
|
+// '款式' => $item['款式'],
|
|
|
+// 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
+// ];
|
|
|
+// $sql = \db('设备_报工日志')->fetchSql(true)->insert($ReportData);
|
|
|
+// \db()->query($sql);
|
|
|
+// }
|
|
|
+// $this->success('成功');
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 出库订单信息查询
|
|
|
@@ -2833,6 +2917,7 @@ class WorkOrderSpotCheck extends Api{
|
|
|
->where('批次号', $item['批次号'])
|
|
|
->where('关联号', $item['关联编号'])
|
|
|
->where('物料编号', $item['物料编码'])
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
->field('库存数量, 退还数量')
|
|
|
->find();
|
|
|
|
|
|
@@ -2869,6 +2954,7 @@ class WorkOrderSpotCheck extends Api{
|
|
|
->where('批次号',$item['批次号'])
|
|
|
->where('关联号',$item['关联编号'])
|
|
|
->where('物料编号',$item['物料编码'])
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
->fetchSql(true)
|
|
|
->update($inventoryData);
|
|
|
\db()->query($InventorySql);
|