|
|
@@ -434,6 +434,7 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ //采购到货单弃审的版本
|
|
|
public function materialOut1($data){
|
|
|
if(empty($data['orderId'])) return [false, '领料申请单ID不能为空'];
|
|
|
if(empty($data['orderNo'])) return [false, '领料申请单单号不能为空'];
|
|
|
@@ -664,7 +665,7 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function saleOut1($data){
|
|
|
+ public function saleOut($data){
|
|
|
if(empty($data['orderId'])) return [false, '销售订单ID不能为空'];
|
|
|
if(empty($data['orderNo'])) return [false, '销售订单号不能为空'];
|
|
|
if(empty($data['detail'])) return [false, '表体信息detail不能为空'];
|
|
|
@@ -702,46 +703,73 @@ class U8ThirdPartyService extends Service
|
|
|
"Inum" => "DispatchList",
|
|
|
"Data" => [
|
|
|
"iHead" => [
|
|
|
- "cBusType" => $order['cBusType'], // 业务类型
|
|
|
- "cVouchType" => "05", // 销售发货单类型
|
|
|
- "cSTCode" => $order['cSTCode'], // 销售类型
|
|
|
- "cDepCode" => $order['cDepCode'], // 部门
|
|
|
- "IsVerify" => true, // 是否自动审核
|
|
|
- "cMemo" => "接口生成",
|
|
|
- "dDate" => date("Y-m-d"),
|
|
|
- "bCalPrice" => true, // 由接口计算价格
|
|
|
- "PriceCalKey" => "iTaxUnitPrice", // 以含税单价为准计算
|
|
|
- "cSoCode" => $order['cSOCode'], // 销售订单号
|
|
|
- "cCusCode" => $order['cCusCode'], // 客户编码
|
|
|
- "cinvoicecompany" => $order['cCusCode'], // 开票单位(通常取客户编码)
|
|
|
+ "cVouchType" => "05",
|
|
|
+ "cSTCode" => (string)($order['cSTCode'] ?? "02"), // 示例中是02
|
|
|
+ "cDepCode" => (string)($order['cDepCode'] ?? "01"),
|
|
|
+ "IsVerify" => true,
|
|
|
+ "cMemo" => "接口生成",
|
|
|
+ "dDate" => date("Y-m-d"),
|
|
|
+ "cSoCode" => (string)$order['cSOCode'],
|
|
|
+ "ccuscode" => (string)$order['cCusCode'],
|
|
|
+ "cexch_name" => (string)($order['cexch_name'] ?? "人民币"),
|
|
|
+ "iexchrate" => (float)($order['iExchRate'] ?? 1.0), // 强制转浮点,去掉引号
|
|
|
+ "iTaxRate" => (float)($order['iTaxRate'] ?? 13.0), // 强制转浮点
|
|
|
],
|
|
|
"iBody" => []
|
|
|
]
|
|
|
];
|
|
|
|
|
|
- // 3. 遍历销售订单明细组织表体
|
|
|
- $key = 0; // 初始化行号计数器
|
|
|
- foreach ($order['details'] as $index => $item) {
|
|
|
- // 销售订单存货可能拆分出多行
|
|
|
+ // 3. 遍历销售订单明细组织表体
|
|
|
+ $key = 0;
|
|
|
+ foreach ($order['details'] as $item) {
|
|
|
$p_t = $detail_map[$item['cInvCode']] ?? [];
|
|
|
- if(empty($p_t)) continue;
|
|
|
- foreach ($p_t as $value){
|
|
|
- $key++; // 每进入一次内层循环,行号加 1
|
|
|
+ if (empty($p_t)) continue;
|
|
|
+
|
|
|
+ foreach ($p_t as $value) {
|
|
|
+ $key++;
|
|
|
+
|
|
|
+ $qty = (float)$value['iQuantity'];
|
|
|
+ $taxRate = (float)($item['iTaxRate'] ?? 13.0);
|
|
|
+ $taxUnitPrice = (float)$item['iTaxUnitPrice']; // 含税单价 (如 100)
|
|
|
+
|
|
|
+ // 价税合计 (iSum)
|
|
|
+ $iSum = round($qty * $taxUnitPrice, 2);
|
|
|
+ // 无税金额 (imoney) = 价税合计 / (1 + 税率/100)
|
|
|
+ $iMoney = round($iSum / (1 + ($taxRate / 100)), 2);
|
|
|
+ // 税额 (itax)
|
|
|
+ $iTax = round($iSum - $iMoney, 2);
|
|
|
+ // 无税单价 (iunitprice)
|
|
|
+ $iUnitPrice = round($taxUnitPrice / (1 + ($taxRate / 100)), 10);
|
|
|
+
|
|
|
$tmp["Data"]["iBody"][] = [
|
|
|
- "iRowNo" => $key, // 直接使用累加后的 key
|
|
|
- "cWhCode" => "06",
|
|
|
- "iQuantity" => $value['iQuantity'],
|
|
|
- "iSOsID" => $item['iSOsID'],
|
|
|
- "cBatch" => $value['lot'],
|
|
|
- "dMDate" => $value['productDate'],
|
|
|
- "dvDate" => $value['failureDate'],
|
|
|
- "iTaxUnitPrice" => $item['iTaxUnitPrice'],
|
|
|
- "iTaxRate" => $item['iTaxRate'],
|
|
|
+ "iRowNo" => (int)$key, // 强制转整型
|
|
|
+ "cInvCode" => (string)$item['cInvCode'],
|
|
|
+ "iTaxRate" => (float)$taxRate,
|
|
|
+ "cGroupCode" => (string)($item['cGroupCode'] ?? "01"),
|
|
|
+ "iGroupType" => "0",
|
|
|
+ "cUnitID" => (string)($item['cUnitID'] ?? "003"),
|
|
|
+ "cWhCode" => "06",
|
|
|
+ "iQuantity" => (float)$qty,
|
|
|
+ "iNum" => 0, // 辅计量数量
|
|
|
+ "iSum" => (float)$iSum,
|
|
|
+ "iInvExchRate" => 1.0, // 换算率,必填
|
|
|
+ "imoney" => (float)$iMoney,
|
|
|
+ "itax" => (float)$iTax,
|
|
|
+ "idiscount" => 0,
|
|
|
+ "inatmoney" => (float)$iMoney,
|
|
|
+ "inattax" => (float)$iTax,
|
|
|
+ "inatdiscount" => 0,
|
|
|
+ "inatsum" => (float)$iSum,
|
|
|
+ "itaxunitprice" => (float)$taxUnitPrice,
|
|
|
+ "iunitprice" => (float)$iUnitPrice,
|
|
|
+ "inatunitprice" => (float)$iUnitPrice,
|
|
|
+ "dvDate" => (string)$value['failureDate'], // 示例中只需失效日期
|
|
|
+ "iSOsID" => (int)$item['iSOsID'], // 强制转整型,去掉引号
|
|
|
+ "cBatch" => (string)$value['lot']
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4. 封装成数组返回
|
|
|
$final_data = [$tmp];
|
|
|
|
|
|
//调用所需
|
|
|
@@ -780,7 +808,7 @@ class U8ThirdPartyService extends Service
|
|
|
"cSTCode" => $fhOrder['cSTCode'], // 销售类型
|
|
|
"DLCode" => $fhOrder['cDLCode'], // 关联的发货单号
|
|
|
"cDepCode" => $fhOrder['cDepCode'], // 部门
|
|
|
- "dDate" => date("Y-m-d"), // 出库日期
|
|
|
+ "dDate" => date("Y-m-d"), // 出库日期
|
|
|
],
|
|
|
"iBody" => []
|
|
|
]
|
|
|
@@ -828,7 +856,7 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function saleOut($data){
|
|
|
+ public function saleOut1($data){
|
|
|
if(empty($data['orderId'])) return [false, '销售订单ID不能为空'];
|
|
|
if(empty($data['orderNo'])) return [false, '销售订单号不能为空'];
|
|
|
if(empty($data['detail'])) return [false, '表体信息detail不能为空'];
|
|
|
@@ -1311,7 +1339,83 @@ class U8ThirdPartyService extends Service
|
|
|
}
|
|
|
|
|
|
//检验单生成产成品入库单
|
|
|
- public function productInByZj1($data){
|
|
|
+ public function productInByZj($data){
|
|
|
+ $record = $data['record'];
|
|
|
+ $payload = $data['payload'];
|
|
|
+ $id = $record['u8_id'];
|
|
|
+ $type = $data['type'];
|
|
|
+
|
|
|
+ // 数量逻辑判断
|
|
|
+ $num = ($type == 1) ? (float)$payload['hg_quantity'] : (float)$payload['rb_quantity'];
|
|
|
+
|
|
|
+ // 获取单据 产品检验单
|
|
|
+ $service = new U8ThirtyPartyDatabaseServerService();
|
|
|
+ $order = $service->getJyOrder($id);
|
|
|
+ if(empty($order)) return [false, '产品检验单不存在'];
|
|
|
+
|
|
|
+ // 获取单据 生产订单子表 (用于获取生产订单累计数量 iNQuantity)
|
|
|
+ $product_detail = $service->getScDetails($order['SOURCEID']);
|
|
|
+ if(empty($product_detail)) return [false, '生产订单子表数据不存在'];
|
|
|
+
|
|
|
+ // u8 token 获取
|
|
|
+ list($status, $msg) = $this->getToken();
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ // 组织 ProductIn 结构
|
|
|
+ $tmp = [
|
|
|
+ "Inum" => "ProductIn",
|
|
|
+ "Data" => [
|
|
|
+ "iHead" => [
|
|
|
+ "cWhCode" => (string)($order['cWhCode'] ?? "06"), // 产成品库
|
|
|
+ "cRdCode" => "0103", // 入库类别
|
|
|
+ "cDepCode" => $order['CINSPECTDEPCODE'],
|
|
|
+ "cMemo" => "接口生成",
|
|
|
+ "cSource" => "产品检验单",
|
|
|
+ "cBusType" => "成品入库",
|
|
|
+ "cMPoCode" => (string)$order['SOURCECODE'], // 生产订单号
|
|
|
+ "cChkCode" => (string)$order['CCHECKCODE'], // 检验单号
|
|
|
+ "dDate" => date("Y-m-d"),
|
|
|
+ "IsVerify" => true,
|
|
|
+ ],
|
|
|
+ "iBody" => []
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 组织表体
|
|
|
+ $tmp["Data"]["iBody"][] = [
|
|
|
+ "iRowNo" => 1,
|
|
|
+ "cInvCode" => (string)($order['CINVCODE'] ?? ''),
|
|
|
+ "iinvexchrate" => (float)($order['FCHANGRATE'] ?? 0), // 换算率转为数字
|
|
|
+ "iQuantity" => (float)$num, // 本次入库数量
|
|
|
+ "iNQuantity" => (float)($product_detail['Qty'] ?? 0), // 生产订单总数量
|
|
|
+ "iNum" => 0, // 辅计数量
|
|
|
+ "iNNum" => 0, // 生产订单辅计总数量
|
|
|
+ "iMPoIds" => (int)($order['SOURCEAUTOID'] ?? 0), // 生产订单子表ID,必须是整型
|
|
|
+ "cBatch" => (string)($order['CBATCH'] ?? ''),
|
|
|
+ "dMadeDate" => (string)($order['DPRODATE'] ?? ''),
|
|
|
+ "dVDate" => (string)($order['DVDATE'] ?? ''),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $final_data = [$tmp];
|
|
|
+
|
|
|
+ // 调用参数
|
|
|
+ $host = $msg['host'] ?? "";
|
|
|
+ $token = $msg['token'] ?? "";
|
|
|
+ $url = $host . "/api/ProductIn/Add";
|
|
|
+ $header = ["Authorization: {$token}", 'Content-Type:application/json'];
|
|
|
+
|
|
|
+ $json = json_encode($final_data);
|
|
|
+
|
|
|
+ list($status, $result) = $this->post_helper1($url, $json, $header, 30);
|
|
|
+ if(! $status) return [false, $result];
|
|
|
+
|
|
|
+ if(! isset($result['code'])) return [false, '产成品入库单生成失败'];
|
|
|
+ if($result['code'] != 0) return [false, $result['msg']];
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function productInByZj2($data){
|
|
|
$record = $data['record'];
|
|
|
$payload = $data['payload'];
|
|
|
$id = $record['u8_id'];
|
|
|
@@ -1391,7 +1495,7 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function productInByZj($data){
|
|
|
+ public function productInByZj1($data){
|
|
|
$record = $data['record'];
|
|
|
$payload = $data['payload'];
|
|
|
$id = $record['u8_id'];
|
|
|
@@ -1521,7 +1625,7 @@ class U8ThirdPartyService extends Service
|
|
|
}
|
|
|
|
|
|
//检验单生产采购入库单
|
|
|
- public function purchaseInByZj1($data)
|
|
|
+ public function purchaseInByZj2($data)
|
|
|
{
|
|
|
$record = $data['record'];
|
|
|
$payload = $data['payload'];
|
|
|
@@ -1599,7 +1703,7 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function purchaseInByZj($data)
|
|
|
+ public function purchaseInByZj1($data)
|
|
|
{
|
|
|
$record = $data['record'];
|
|
|
$payload = $data['payload'];
|
|
|
@@ -1673,6 +1777,80 @@ class U8ThirdPartyService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ public function purchaseInByZj($data)
|
|
|
+ {
|
|
|
+ $record = $data['record'];
|
|
|
+ $payload = $data['payload'];
|
|
|
+ $type = $data['type'];
|
|
|
+
|
|
|
+ // 确定入库数量
|
|
|
+ $num = ($type == 1) ? (float)$payload['hg_quantity'] : (float)$payload['rb_quantity'];
|
|
|
+
|
|
|
+ // 1. 获取基础数据 (检验单信息)
|
|
|
+ $service = new U8ThirtyPartyDatabaseServerService();
|
|
|
+ $order = $service->getJyOrder2($record['u8_id']);
|
|
|
+ if(empty($order)) return [false, '检验单不存在'];
|
|
|
+
|
|
|
+ // 2. 获取 U8 Token
|
|
|
+ list($status, $msg) = $this->getToken();
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ // 3. 组织采购入库单 (参照来料检验单模式)
|
|
|
+ $tmp = [
|
|
|
+ "Inum" => "PurchaseIn",
|
|
|
+ "Data" => [
|
|
|
+ "iHead" => [
|
|
|
+ "IsVerify" => true, // 示例中为 false
|
|
|
+ "cWhCode" => (string)($order['CWHCODE'] ?? "01"),
|
|
|
+ "cDepCode" => (string)($order['CDEPCODE']),
|
|
|
+ "cVenCode" => (string)$order['CVENCODE'],
|
|
|
+ "cRdCode" => "0101",
|
|
|
+ "iExchRate" => (float)($order['IEXCHRATE'] ?? 1.0),
|
|
|
+ "iTaxRate" => (float)($order['ITAXRATE'] ?? 13.0),
|
|
|
+ "cExch_Name" => "人民币",
|
|
|
+ "cSource" => "来料检验单", // 匹配示例中的来源
|
|
|
+ "cBusType" => "普通采购",
|
|
|
+ "cMemo" => "接口生成",
|
|
|
+ "dDate" => date("Y-m-d"),
|
|
|
+ "cChkCode" => (string)$order['CCHECKCODE'] // 检验单号
|
|
|
+ ],
|
|
|
+ "iBody" => [
|
|
|
+ [
|
|
|
+ "iRowNo" => 1,
|
|
|
+ "cInvCode" => (string)$order['CINVCODE'],
|
|
|
+ "iQuantity" => (float)$num, // 本次入库实收数量
|
|
|
+ "iNum" => 0,
|
|
|
+ "iNQuantity" => (float)($order['IQUANTITY'] ?? $num), // 检验单关联数量
|
|
|
+ "iNNum" => 0,
|
|
|
+// "iCheckIdBaks" => (int)$order['ICHECKIDBAKS'],
|
|
|
+ "iArrsId" => $order['SOURCEAUTOID'], // 子表id
|
|
|
+ "cBatch" => (string)($order['CBATCH'] ?? ''),
|
|
|
+ "dMadeDate" => (string)($order['DPRODATE'] ?? ''),
|
|
|
+ "dVDate" => (string)($order['DVDATE'] ?? ''),
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ $final_data = [$tmp];
|
|
|
+
|
|
|
+ // 4. 调用 API
|
|
|
+ $host = $msg['host'] ?? "";
|
|
|
+ $token = $msg['token'] ?? "";
|
|
|
+ $header = ["Authorization: {$token}", 'Content-Type:application/json'];
|
|
|
+ $url = $host . "/api/PurchaseIn/Add";
|
|
|
+
|
|
|
+ $json = json_encode($final_data);
|
|
|
+
|
|
|
+ list($status, $result) = $this->post_helper1($url, $json, $header, 30);
|
|
|
+
|
|
|
+ if(! $status) return [false, $result];
|
|
|
+ if(! isset($result['code'])) return [false, '采购入库单生成失败'];
|
|
|
+ if($result['code'] != 0) return [false, $result['msg']];
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
public function post_helper1($url, $data, $header = [], $timeout = 20){
|
|
|
Log::channel('apiLog')->info('POST', ["api" => $url , "param" => json_decode($data,true) ,"header" => $header]);
|
|
|
|