StoreController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. namespace App\Http\Controllers\Api\thirdPart\flux;
  3. use App\Http\Controllers\Controller;
  4. use App\Store;
  5. use App\WMSReflectReceive;
  6. use App\WMSReflectReceiveSku;
  7. use Carbon\Carbon;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\DB;
  10. use Zttp\Zttp;
  11. class StoreController extends Controller
  12. {
  13. /**
  14. * 入库回传给WMS
  15. * @param Store $store
  16. * @return bool
  17. */
  18. public function accomplishToWMS(Store $store,array $inputs)
  19. {
  20. $METHOD=__METHOD__;
  21. $FUNCTION=__FUNCTION__;
  22. Controller::logS(__METHOD__, __FUNCTION__, '快递入库进入WMS接口:' . $store['asn_code']);
  23. $wmsReceiveds=WMSReflectReceive::query()->where('ASNNO',$store['asn_code'])->get();
  24. if($wmsReceiveds->isEmpty()){
  25. (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,'没有本地WMS入库单');
  26. return false;
  27. }
  28. $success=true;
  29. $wmsReceiveds->each(function ($wmsReceived)use(&$store,&$amountsItem,&$success,&$inputs,$METHOD,$FUNCTION){
  30. $wmsSkus=$wmsReceived->skus()->get();
  31. $orderNumberCode=$wmsReceived['ASNREFERENCE1']??$store['order_number'];
  32. $amountsSku=(function()use($wmsSkus){
  33. $result=[];
  34. $wmsSkus->each(function($sku)use(&$result){
  35. $result[$sku['id']]= $sku['EXPECTEDQTY_EACH'];
  36. });
  37. return $result;
  38. })();
  39. $skuStrList=[];
  40. $customerCode=$store->owner()->first()['code'];
  41. $wmsSkus->each(function(WMSReflectReceiveSku $sku)use(&$skuList,&$amountsItem,&$amountsSku,&$skuStrList,$wmsReceived,$customerCode,&$inputs) {
  42. $STATUS = 'ZP';
  43. if(isset($inputs['quality'])&&$inputs['quality']
  44. &&$inputs['quality']!='正品') {
  45. $STATUS = 'CC';
  46. }
  47. $repositoryCode=$sku['LOTATT05'];
  48. if(isset($inputs['depository_code'])&&$inputs['depository_code']){
  49. $repositoryCode=$inputs['depository_code'];
  50. }
  51. $skuStr = "
  52. {
  53. \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
  54. \"ASNLINENO\": \"{$sku['ASNLINENO']}\",
  55. \"SKUCODE\": \"{$sku['SKU']}\",
  56. \"QUANTITY\": \"{$sku['EXPECTEDQTY_EACH']}\",
  57. \"LOTATT04\": \"{$sku['LOTATT04']}\",
  58. \"LOTATT05\": \"{$repositoryCode}\",
  59. \"STATUS\": \"{$STATUS}\",
  60. \"USERDEFINE1\": \"{$inputs['follow_code']}\",
  61. \"USERDEFINE2\": \"\",
  62. \"USERDEFINE3\": \"\",
  63. \"UNIQUE_CODE_LIST\": [" .
  64. "]
  65. }
  66. ";
  67. $skuStrList[] = $skuStr;
  68. });
  69. $skuStrList = implode(',',$skuStrList);
  70. $json="
  71. {
  72. \"request\": [
  73. {
  74. \"ORDERNUMBERCODE\": \"{$wmsReceived['ASNNO']}\",
  75. \"CUSTOMERID\": \"{$wmsReceived['CUSTOMERID']}\",
  76. \"ASNTYPE\": \"{$wmsReceived['ASNTYPE']}\",
  77. \"ASNREFERENCE1\": \"{$wmsReceived['ASNREFERENCE1']}\",
  78. \"ADDWHO\": \"WCS\",
  79. \"USERDEFINE1\": \"\",
  80. \"USERDEFINE2\": \"\",
  81. \"USERDEFINE3\": \"\",
  82. \"SKU_LIST\": [{$skuStrList}]
  83. }
  84. ]
  85. }
  86. ";
  87. $sendingJson = json_decode($json,true);
  88. $url=url(config('api.flux.receive.new'));
  89. // (new Controller())->log($METHOD,$FUNCTION,$store['asn_code'].'||' .json_encode($sendingJson));
  90. Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口开始:' . $store['asn_code']);
  91. $response = Zttp::post($url, $sendingJson);
  92. Controller::logS(__METHOD__, __FUNCTION__, '快递入库请求WMS接口结束:' . $store['asn_code'].'||'.$response->body());
  93. $noIssues=true;
  94. $json = $response->json();
  95. if(!$json||!isset($json['Response'])||!$json['Response']['return']['returnFlag']=='1'){
  96. $noIssues=false;
  97. }
  98. if($json&&isset($json['Response'])){
  99. if($json['Response']['return']['returnFlag']=='2'){
  100. (new Controller())->log($METHOD,'error_'.$FUNCTION,$store['asn_code'].'||' . $response->body());
  101. return true;
  102. }
  103. // if(isset($json['Response']['return']['returnDesc'])&&strpos($json['Response']['return']['returnDesc'],'唯一约束')!==false){
  104. // (new Controller())->log($METHOD,'error_'.$FUNCTION,$response->body());
  105. // return true;
  106. // }
  107. if(isset($json['Response']['return']['errordescr'])&&strpos($json['Response']['return']['errordescr'],'已完成')!==false){
  108. (new Controller())->log($METHOD,'error_'.$FUNCTION,$store['asn_code'].'||' . $response->body());
  109. return true;
  110. }
  111. }
  112. if($noIssues&&$json['Response']['return']['returnFlag']=='1'){
  113. $wmsReceived['is_uploaded']=1;
  114. $wmsReceived->save();
  115. (new Controller())->log($METHOD, 'success_' .$FUNCTION, $store['asn_code'].'||' .$response->body());
  116. return true;
  117. }else {
  118. $success = false;
  119. (new Controller())->log($METHOD, 'error_'.$FUNCTION, $store['asn_code'].'||' . $response->body());
  120. }
  121. });
  122. return $success;
  123. }
  124. public function quickStorage($asnno){
  125. $docno = ""; //订单号 非ASN号
  126. //判断单据有效性
  127. $cus_bs_asnheader = DB::connection('oracle')->select(DB::raw("SELECT t.addwho FROM CUS_BS_ASNHEADER t WHERE t.asnreferencel = '".$docno."'"));
  128. if (!$cus_bs_asnheader) return ['success'=>false, 'data'=>'单据不存在'];
  129. $addwho = $cus_bs_asnheader[0]->addwho;
  130. if ($addwho == "WCS"){
  131. //判断单据状态
  132. $cus_bs_asnheader = DB::connection('oracle')->select(
  133. DB::raw("SELECT COUNT(1) FROM CUS_BS_ASNHEADER t INNER JOIN DOC_ASN_HEADER a ON a.asnno = t.asnno WHERE t.asnreference1 = '".$docno."' AND a.asnstatus < '40'"));
  134. if (!$cus_bs_asnheader) return ['success'=>false, 'data'=>"该单据已完成收货"];
  135. $sql = "select a.warehouseid,a.asnno as docno,a1.asnlineno,a.customerid,t1.sku,a1.packid,t1.receivedqty_each,t1.lotatt01,t1.lotatt02,";
  136. $sql .= " t1.lotatt04,t1.lotatt05,t1.lotatt08,t1.userdefine1 as new_traceid,a.userdefine1,a.userdefine2,a.userdefine3,a.userdefine4,a.userdefine5,t.addwho";
  137. $sql .= " from doc_asn_details a1";
  138. $sql .= " inner join doc_asn_header a on a.asnno = a1.asnno";
  139. $sql .= " inner join cus_bs_asndetails t1 on t1.asnno = a.asnno and t1.asnlineno = a1.asnlineno";
  140. $sql .= " inner join cus_bs_asnheader t on t.asnno = a1.asnno";
  141. $sql .= " where t.asnreference1 = ".$docno." and nvl(t1.rcvflag,'N') = 'N'";
  142. $doc_asn_details = DB::connection('oracle')->select(DB::raw($sql));
  143. $that = $this;
  144. DB::transaction(function ()use($doc_asn_details,$that){
  145. foreach ($doc_asn_details as $doc_asn_detail){
  146. $resule = $that->exe($doc_asn_detail->warehouseid,'3',$doc_asn_detail->docno,$doc_asn_detail->asnlineno,'',$doc_asn_detail->new_traceid,'00','正常','OK','正常',
  147. '',$doc_asn_detail->customerid,$doc_asn_detail->sku,$doc_asn_detail->receivedqty_each,'','EA',$doc_asn_detail->packid,'',$doc_asn_detail->lotatt01,$doc_asn_detail->lotatt02,
  148. '',$doc_asn_detail->lotatt04,$doc_asn_detail->lotatt05,'','',$doc_asn_detail->lotatt08,'','','','',
  149. '0.00','0.00','0.00','0.00',$doc_asn_detail->userdefine1,$doc_asn_detail->userdefine2,$doc_asn_detail->userdefine3,$doc_asn_detail->userdefine4,$doc_asn_detail->userdefine5,'STAGE'.$doc_asn_detail->warehouseid,
  150. 'STAGE'.$doc_asn_detail->warehouseid,'OK','','','*',$doc_asn_detail->addwho,'','','cn',$doc_asn_detail->addwho,'');
  151. if (substr($resule,1,3) == '000'){
  152. exe2();
  153. }else{
  154. exe3();
  155. DB::rollBack();
  156. break;
  157. }
  158. }
  159. });
  160. DB::commit();
  161. return ['success'=>true, 'data'=>"OK"];
  162. }
  163. if ($addwho == "BSERP"){
  164. $cus_bs_asnheader = DB::connection('oracle')->select(DB::raw('SELECT t.asnreference1 FROM cus_bs_asnheader t'));
  165. if (!$cus_bs_asnheader) return ['success'=>false, 'data'=>'单据不存在'];
  166. $asnreference1 = $cus_bs_asnheader[0]->asnreference1;
  167. return ['success'=>true, 'data'=>$asnreference1];
  168. }
  169. }
  170. /** $In_Process_Action为来源渠道,快速入库调用固定值 为 '3' */
  171. private function exe($IN_Warehouse, $In_Process_Action, $In_ASNNo_C, $In_ASNLineNo_C, $In_FMTraceID_C, $In_New_TraceID_C, $In_ProductStatus,
  172. $In_ProductStatus_Descr, $In_HoldRejectCode_C, $In_HoldRejectReason_C, $In_PONo_C, $In_CustomerID, $In_SKU, $In_ReceivedQty, $In_RejectedQty,
  173. $In_UOM, $In_PackID, $In_ContainerID, $In_LotAtt01_C, $In_LotAtt02_C, $In_LotAtt03_C, $In_LotAtt04_C, $In_LotAtt05_C, $In_LotAtt06_C,
  174. $In_LotAtt07_C, $In_LotAtt08_C, $In_LotAtt09_C, $In_LotAtt10_C, $In_LotAtt11_C, $In_LotAtt12_C,
  175. $In_TotalCubic, $In_TotalGrossWeight, $In_TotalNetWeight, $In_TotalPrice, $In_UserDefine1, $In_UserDefine2,
  176. $In_UserDefine3, $In_UserDefine4, $In_UserDefine5, $In_FMLocation, $In_TOLocation_C, $In_QC_Type_C, $In_PlanToLoc_C,
  177. $In_ReceivingTime, $In_LPN, $In_Operator, $IN_RCVModule, $IN_RCVStation, $In_Language, $In_UserID, $OUT_Return_Code)
  178. {
  179. /*$r_NO_COMMIT $R_CurrentTime $OUT_Return_Code $R_ReceivingTime $r_LPN $r_UDF2_AD $r_UDF2_IN
  180. $R_Qty_PlanPutaway $R_QCTaskID $R_HOLD_FLAG $R_PA_TaskID $R_PA_Flag $R_QC_Sequence $R_PA_Sequence
  181. $R_Reserve_Flag $R_QtyMVOut $r_TotalGrossWeight $r_TotalCubic r_TotalNetWeight r_TotalPrice In_LotAtt01
  182. In_LotAtt02 In_LotAtt03 In_LotAtt04 In_LotAtt05 In_LotAtt06 In_LotAtt07 In_LotAtt08 In_LotAtt09 In_LotAtt10
  183. In_LotAtt11 In_LotAtt12 In_HoldRejectCode In_HoldRejectReason
  184. */
  185. if ($OUT_Return_Code == "NO_COMMIT" || $OUT_Return_Code == "*_*"){
  186. $r_NO_COMMIT = 'N';
  187. }else{
  188. $r_NO_COMMIT = 'Y';
  189. }
  190. //初始化
  191. $R_CurrentTime = Carbon::now();
  192. $OUT_Return_Code ='000';
  193. if (!$In_ReceivingTime){
  194. $R_ReceivingTime = Carbon::now();
  195. }else{
  196. $R_ReceivingTime = $In_ReceivingTime;
  197. }
  198. //else R_ReceivingTime:=To_Date( IN_ReceivingTime,'YYYY/MM/DD hh24:mi:ss'); --2008-11-25 15:53:33
  199. if ($In_LPN && $In_LPN != "*"){
  200. $r_LPN = $In_LPN;
  201. }else $r_LPN = "*";
  202. $bascode = DB::select(DB::raw("SELECT udf2 FROM BAS_CODES WHERE codeid ='TRN_TYP' AND code='AD'"));
  203. $r_UDF2_AD = $bascode[0]->udf2 ?? 'N';
  204. $bascode = DB::select(DB::raw("SELECT udf2 FROM BAS_CODES WHERE codeid ='TRN_TYP' AND code='IN'"));
  205. $r_UDF2_IN = $bascode[0]->udf2 ?? 'N';
  206. $R_Qty_PlanPutaway = 0;
  207. $R_QCTaskID = '*';
  208. $R_HOLD_FLAG = 'N';
  209. $R_PA_TaskID = '*';
  210. $R_PA_Flag = 'N';
  211. $R_QC_Sequence = 0;
  212. $R_PA_Sequence = 0;
  213. $R_Reserve_Flag = 'N';
  214. $R_QtyMVOut = 0;
  215. $r_TotalGrossWeight = $In_TotalGrossWeight;
  216. $r_TotalCubic = $In_TotalCubic;
  217. $r_TotalNetWeight = $In_TotalNetWeight ?? 0;
  218. $r_TotalPrice = $In_TotalPrice;
  219. $In_LotAtt01 = $In_LotAtt01_C;
  220. $In_LotAtt02 = $In_LotAtt02_C;
  221. $In_LotAtt03 = $In_LotAtt03_C;
  222. $In_LotAtt04 = $In_LotAtt04_C;
  223. $In_LotAtt05 = $In_LotAtt05_C;
  224. $In_LotAtt06 = $In_LotAtt06_C;
  225. $In_LotAtt07 = $In_LotAtt07_C;
  226. $In_LotAtt08 = $In_LotAtt08_C;
  227. $In_LotAtt09 = $In_LotAtt09_C;
  228. $In_LotAtt10 = $In_LotAtt10_C;
  229. $In_LotAtt11 = $In_LotAtt11_C;
  230. $In_LotAtt12 = $In_LotAtt12_C;
  231. $In_HoldRejectCode = $In_HoldRejectCode_C;
  232. $In_HoldRejectReason = $In_HoldRejectReason_C;
  233. $In_TOLocation = $In_TOLocation_C;
  234. $In_New_TraceID = $In_New_TraceID_C ?? '*';
  235. $In_QC_Type = $In_QC_Type_C;
  236. $In_FMTraceID = $In_FMTraceID_C;
  237. $In_ASNNo = $In_ASNNo_C;
  238. $In_ASNLineNo = $In_ASNLineNo_C;
  239. $In_PONo = $In_PONo_C;
  240. $In_PlanToLoc = $In_PlanToLoc_C;
  241. $r_nrow = 0;
  242. $OUT_Return_Code = '*_*';
  243. //此处调用必然返回000,所以直接忽视判断进入下层逻辑
  244. $OUT_Return_Code = $this->SPUDF_ProcessA($IN_Warehouse,'RCV_BEFORE',$In_ASNNo,$In_ASNLineNo,$In_ReceivedQty,$In_Language,$In_UserID,$OUT_Return_Code);
  245. //TODO 盲收逻辑 SPASN_Receiving_Process:536行 $In_Process_Action = 2
  246. //如果订单已经关闭或者取消,则报错
  247. $doc_asn_header = DB::connection('oracle')->select(DB::raw("Select count(1) from DOC_ASN_Header where ASNNO='".$In_ASNNo."' and (ASNStatus='90' or ASNStatus='99')"));
  248. if ($doc_asn_header) return '201';
  249. //收货数量必须大于0
  250. if ($In_ReceivedQty <= 0 && ((!$In_ProductStatus) || $In_ProductStatus == '00')) return '204';
  251. //批次属性自动复制 系统配置是否允许超量收货
  252. $customer = DB::connection('oracle')->select(DB::raw("SELECT OverReceiving,OverRCVPercentage,ASN_LNK_PO,AsnRef1ToLot4,AsnRef2ToLot5,AsnRef3ToLot6,AsnRef4ToLot7,AsnRef5ToLot8 FROM Bas_Customer WHERE CustomerID='".$In_CustomerID."' AND Customer_Type = 'OW'"));
  253. if (!$customer) return '888BAS_Customer,OPEN';
  254. $R_OverReceiving = $customer[0]->overreceiving ?? 'N';
  255. $R_OverRCVPercentage_Customer = $customer[0]->overrcvpercentage ?? 0;
  256. $r_ASN_LNK_PO = $customer[0]->asn_lnk_po ?? 'Y';
  257. $R_AsnRef1ToLot4 = $customer[0]->asnref1tolot4;
  258. $R_AsnRef2ToLot5 = $customer[0]->asnref2tolot5;
  259. $R_AsnRef3ToLot6 = $customer[0]->asnref3tolot6;
  260. $R_AsnRef4ToLot7 = $customer[0]->asnref4tolot7;
  261. $R_AsnRef5ToLot8 = $customer[0]->asnref5tolot8;
  262. $DOC_ASN_Header = DB::connection('oracle')->select(DB::raw("SELECT ASNReference1,ASNReference2,ASNReference3,ASNReference4,ASNReference5,ExpectedArriveTime1,ExpectedArriveTime2,QCStatus,ASNType,WarehouseID,ReleaseStatus,Priority FROM DOC_ASN_Header WHERE ASNNO='".$In_ASNNo."'"));
  263. if (!$DOC_ASN_Header) return '888DOC_ASN_Header,OPEN';
  264. $r_ASNReference1 = $DOC_ASN_Header[0]->asnreference1;
  265. $r_ASNReference2 = $DOC_ASN_Header[0]->asnreference2;
  266. $r_ASNReference3 = $DOC_ASN_Header[0]->asnreference3;
  267. $r_ASNReference4 = $DOC_ASN_Header[0]->asnreference4;
  268. $r_ASNReference5 = $DOC_ASN_Header[0]->asnreference5;
  269. $r_ExpectedArriveTime1 = $DOC_ASN_Header[0]->expectedarrivetime1 ?? "2000-01-01 00:00:00";
  270. $r_ExpectedArriveTime2 = $DOC_ASN_Header[0]->expectedarrivetime2 ?? "2099-12-31 00:00:00";
  271. $r_QCStatus = $DOC_ASN_Header[0]->qcstatus;
  272. $r_ASNType = $DOC_ASN_Header[0]->asntype;
  273. $r_WarehouseID = $DOC_ASN_Header[0]->warehouseid;
  274. $R_ReleaseStatus = $DOC_ASN_Header[0]->releasestatus;
  275. $r_Priority = $DOC_ASN_Header[0]->priority ?? '3';
  276. if ($R_AsnRef1ToLot4 == 'Y' && ($r_ASNReference1 && $r_ASNReference1 != "*") && ((!$In_LotAtt04) || $In_LotAtt04=='*')){
  277. $In_LotAtt04 = $r_ASNReference1;
  278. }
  279. if ($R_AsnRef2ToLot5 == 'Y' && ($r_ASNReference2 && $r_ASNReference2 != "*") && ((!$In_LotAtt05) || $In_LotAtt05=='*')){
  280. $In_LotAtt05 = $r_ASNReference2;
  281. }
  282. if ($R_AsnRef3ToLot6 == 'Y' && ($r_ASNReference3 && $r_ASNReference3 != "*") && ((!$In_LotAtt06) || $In_LotAtt06=='*')){
  283. $In_LotAtt06 = $r_ASNReference3;
  284. }
  285. if ($R_AsnRef4ToLot7 == 'Y' && ($r_ASNReference4 && $r_ASNReference4 != "*") && ((!$In_LotAtt07) || $In_LotAtt07=='*')){
  286. $In_LotAtt07 = $r_ASNReference4;
  287. }
  288. if ($R_AsnRef5ToLot8 == 'Y' && ($r_ASNReference5 && $r_ASNReference5 != "*") && ((!$In_LotAtt08) || $In_LotAtt08=='*')){
  289. $In_LotAtt08 = $r_ASNReference5;
  290. }
  291. if ($In_LotAtt01 == 'YYYY-MM-DD') $In_LotAtt01 = null;
  292. if ($In_LotAtt02 == 'YYYY-MM-DD') $In_LotAtt02 = null;
  293. if ($In_LotAtt03 == 'YYYY-MM-DD') $In_LotAtt03 = null;
  294. // TODO SPASN_Receiving_Process:643行 IN_ProductStatus固定值00 跳过
  295. //生产日期、入库日期、失效日期的逻辑校验
  296. if (($In_LotAtt01 && $In_LotAtt02 && Carbon::parse($In_LotAtt01)->gte(Carbon::parse($In_LotAtt02))) || ($In_LotAtt01 && Carbon::parse($In_LotAtt01)->gt(Carbon::parse($R_CurrentTime)))){
  297. return "260";
  298. }
  299. $r_ASN_MDT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_MDT_CHK');
  300. //入库生产日期不能小于在库库存生产日期
  301. if ($r_ASN_MDT_CHK == 'Y' && trim($In_LotAtt01)){
  302. $data = DB::connection('oracle')->select(DB::raw("SELECT count(*) c FROM INV_LOT_LOC_ID a,INV_LOT_ATT b, bas_location c WHERE a.CUSTOMERID='".$In_CustomerID.
  303. "' AND a.sku='".$In_SKU."' AND a.LotNum=b.LotNum AND a.LocationID=c.LocationID AND c.LocationUsage<>'ST' AND b.LotAtt01>'".$In_LotAtt01."'"));
  304. if ($data) return '266INV_LOT_LOC_ID';
  305. }
  306. //批次属性必输校验
  307. $BAS_lotID = DB::connection('oracle')->select(DB::raw("SELECT LotAtt01_Flag,LotAtt02_Flag,LotAtt03_Flag,LotAtt04_Flag,LotAtt05_Flag,LotAtt06_Flag,".
  308. "LotAtt07_Flag,LotAtt08_Flag,LotAtt09_Flag,LotAtt10_Flag,LotAtt11_Flag,LotAtt12_Flag,OverRCVPercentage,a.LotID,PackID,".
  309. "GrossWeight,Cube,CopyPackIDToLotAtt12,AllowReceiving,A.SKU_Group1 FROM Bas_SKU a, BAS_lotID b WHERE a.CustomerID='".$In_CustomerID."' AND a.sku='".$In_SKU."' AND a.LotID=b.LotID"));
  310. if (!$BAS_lotID)return "888From Bas_SKU*BAS_lotID,OPEN";
  311. $r_LotAtt01_Flag = $BAS_lotID[0]->lotatt01_flag;
  312. $r_LotAtt02_Flag = $BAS_lotID[0]->lotatt02_flag;
  313. $r_LotAtt03_Flag = $BAS_lotID[0]->lotatt03_flag;
  314. $r_LotAtt04_Flag = $BAS_lotID[0]->lotatt04_flag;
  315. $r_LotAtt05_Flag = $BAS_lotID[0]->lotatt05_flag;
  316. $r_LotAtt06_Flag = $BAS_lotID[0]->lotatt06_flag;
  317. $r_LotAtt07_Flag = $BAS_lotID[0]->lotatt07_flag;
  318. $r_LotAtt08_Flag = $BAS_lotID[0]->lotatt08_flag;
  319. $r_LotAtt09_Flag = $BAS_lotID[0]->lotatt09_flag;
  320. $r_LotAtt10_Flag = $BAS_lotID[0]->lotatt10_flag;
  321. $r_LotAtt11_Flag = $BAS_lotID[0]->lotatt11_flag;
  322. $r_LotAtt12_Flag = $BAS_lotID[0]->lotatt12_flag;
  323. $r_OverRCVPercentage_SKU = $BAS_lotID[0]->overrcvpercentage ?? 0;
  324. $r_SKU_LOTID = $BAS_lotID[0]->lotid;
  325. $r_SKU_PackID = $BAS_lotID[0]->packid;
  326. $r_SKU_GrossWeight = $BAS_lotID[0]->grossweight;
  327. $r_SKU_Cube = $BAS_lotID[0]->cube;
  328. $r_CopyPackIDToLotAtt12 = $BAS_lotID[0]->copypackidtolotatt12;
  329. $r_AllowReceiving = $BAS_lotID[0]->allowreceiving;
  330. $r_SKU_Group1 = $BAS_lotID[0]->sku_group1;
  331. //是否被设置禁止入库
  332. if ($r_AllowReceiving == 'N') return "117";
  333. if (($r_LotAtt01_Flag == '3' && !$In_LotAtt01) ||
  334. ($r_LotAtt02_Flag == "3" && !$In_LotAtt02) ||
  335. ($r_LotAtt03_Flag == "3" && !$In_LotAtt03) ||
  336. ($r_LotAtt04_Flag == "3" && !$In_LotAtt04) ||
  337. ($r_LotAtt05_Flag == "3" && !$In_LotAtt05) ||
  338. ($r_LotAtt06_Flag == "3" && !$In_LotAtt06) ||
  339. ($r_LotAtt07_Flag == "3" && !$In_LotAtt07) ||
  340. ($r_LotAtt08_Flag == "3" && !$In_LotAtt08) ||
  341. ($r_LotAtt09_Flag == "3" && !$In_LotAtt09) ||
  342. ($r_LotAtt10_Flag == "3" && !$In_LotAtt10) ||
  343. ($r_LotAtt11_Flag == "3" && !$In_LotAtt11) ||
  344. ($r_LotAtt12_Flag == "3" && !$In_LotAtt12))return "221".$In_ASNLineNo_C;
  345. if ($r_LotAtt01_Flag == '1' && $In_LotAtt01) $In_LotAtt01 = null;
  346. if ($r_LotAtt02_Flag == '1' && $In_LotAtt02) $In_LotAtt02 = null;
  347. if ($r_LotAtt03_Flag == '1' && $In_LotAtt03) $In_LotAtt03 = null;
  348. if ($r_LotAtt04_Flag == '1' && $In_LotAtt04) $In_LotAtt04 = null;
  349. if ($r_LotAtt05_Flag == '1' && $In_LotAtt05) $In_LotAtt05 = null;
  350. if ($r_LotAtt06_Flag == '1' && $In_LotAtt06) $In_LotAtt06 = null;
  351. if ($r_LotAtt07_Flag == '1' && $In_LotAtt07) $In_LotAtt07 = null;
  352. if ($r_LotAtt08_Flag == '1' && $In_LotAtt08) $In_LotAtt08 = null;
  353. if ($r_LotAtt09_Flag == '1' && $In_LotAtt09) $In_LotAtt09 = null;
  354. if ($r_LotAtt10_Flag == '1' && $In_LotAtt10) $In_LotAtt10 = null;
  355. //if ($r_LotAtt11_Flag == '1' && $In_LotAtt11) $In_LotAtt11 = null;
  356. if ($r_LotAtt12_Flag == '1' && $In_LotAtt12) $In_LotAtt12 = null;
  357. $R_LOT_12_PKG = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'LOT_#12_PKG');
  358. // 批次属性12被设置为跟踪包装数量,不允许输入非数字字符'
  359. if ($R_LOT_12_PKG == 'Y' && !is_numeric($In_LotAtt12)) return "232";
  360. if ($r_OverRCVPercentage_SKU != 0) $r_OverRCVPercentage = $r_OverRCVPercentage_SKU;
  361. else $r_OverRCVPercentage = $R_OverRCVPercentage_Customer;
  362. // TODO 药品相关逻辑 SPASN_Receiving_Process:817行 药品有效期 证书有效期 经营许可证有效期校验提示
  363. //基础设置是否维护完全校验
  364. $R_BAS_PAC_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_PAC_CHK');
  365. $R_BAS_LOT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_LOT_CHK');
  366. $R_BAS_GWT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_GWT_CHK');
  367. $R_BAS_CUB_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_CUB_CHK');
  368. if ($R_BAS_PAC_CHK == 'Y' && !$r_SKU_PackID)return '110'.$In_SKU;
  369. if ($R_BAS_LOT_CHK == 'Y' && !$r_SKU_LOTID)return '111';
  370. if ($R_BAS_GWT_CHK == 'Y' && $r_SKU_GrossWeight == 0)return '112';
  371. if ($R_BAS_CUB_CHK == 'Y' && $r_SKU_Cube == 0)return '113';
  372. //订单释放状态校验
  373. if($R_ReleaseStatus == 'N') return '226';
  374. /*参数准备 */
  375. //必须输入价格
  376. $R_UNT_PRI_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'UNT_PRI_CTL');
  377. //收货后打印上架标签
  378. $R_PRT_PTA_LBL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PRT_PTA_LBL');
  379. //ASN收货自动产生跟踪号
  380. $r_ASN_GEN_TID = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_GEN_TID');
  381. //收货后将收货结果更新ASN明细
  382. $r_ASN_RCV_UPD = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_RCV_UPD');
  383. //完全收货后自动关闭ASN
  384. $r_RCV_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_CTL');
  385. //超过产品有效期控制天数是否拒收
  386. $r_EXP_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'EXP_CTL');
  387. //码盘后才能收货
  388. $r_PLT_RCV = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PLT_RCV');
  389. //跨区域货物是否允许收到一个托盘上
  390. $r_RCV_CRS_ARA = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_CRS_ARA');
  391. //收货时必须指定跟踪号
  392. $r_RCV_TID_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_TID_CTL');
  393. //超额收货
  394. $R_OverReceiving = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'OVR_RCV');
  395. //收货时间必须在预期到货时间范围内
  396. $r_RCV_TIM_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_TIM_CTL');
  397. //同一跟踪号不允许在收货区重复收货
  398. $r_RCV_MIX_TID = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_TID');
  399. //只有上架确认后才能关闭ASN
  400. $r_PTA_CLS_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PTA_CLS_CHK');
  401. //收货数量拆分寻找目标库位
  402. $r_RCV_BRK_TSK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_BRK_TSK');
  403. //扫描收货时记录箱码和序列号
  404. $r_SN_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'SN#_CTL','0');
  405. //质检后才能收货
  406. $r_QC_RCV_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'QC_RCV_CTL');
  407. //目标库位为拆零拣货位拆箱时作废箱码
  408. $r_PCK_LOS_SN = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PCK_LOS_SN');
  409. //服装行业插件开关
  410. $r_IND_TEX = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'IND_TEX');
  411. if ($In_Process_Action != '2'){
  412. $DOC_ASN_DETAiLS = DB::connection('oracle')->select(DB::raw("SELECT ExpectedQty_Each,ReceivedQty_Each,POLineNO,PONO,OverRCVPercentage,ContainerID,QCStatus FROM DOC_ASN_DETAiLS WHERE ASNNO='".$In_ASNNo."' AND ASNLineNo='".$In_ASNLineNo."' FOR UPDATE"));
  413. if (!$DOC_ASN_DETAiLS)return '104'.$In_ASNNo.":".$In_ASNLineNo;
  414. $r_ExpectedQty_Each_ASN = $DOC_ASN_DETAiLS[0]->expectedqty_each;
  415. $r_ReceivedQty_Each_ASN = $DOC_ASN_DETAiLS[0]->receivedqty_each;
  416. $r_POLineNO = $DOC_ASN_DETAiLS[0]->polineno;
  417. $r_PONO = $DOC_ASN_DETAiLS[0]->pono;
  418. $R_OverRCVPercentage_ASN = $DOC_ASN_DETAiLS[0]->overrcvpercentage;
  419. $r_ASNContainerID = $DOC_ASN_DETAiLS[0]->containerid ?? '';
  420. $r_QCStatus = $DOC_ASN_DETAiLS[0]->qcstatus ?? '';
  421. }
  422. //目标库位属性
  423. if ($In_TOLocation == '*' || !trim($In_TOLocation))$In_TOLocation = $In_FMLocation;
  424. $BAS_Location = DB::connection('oracle')->select(DB::raw("SELECT LocationUsage,LoseID_Flag,Mix_Flag,Mix_LotFlag,LocationAttribute,SKUCount FROM BAS_Location WHERE LocationID='".$In_TOLocation."'"));
  425. if (!$BAS_Location)return '104'.$In_TOLocation;
  426. $R_LocationUsage = $BAS_Location[0]->locationusage;
  427. $R_LoseID_Flag = $BAS_Location[0]->loseid_flag ?? 'N';
  428. $R_Mix_Flag = $BAS_Location[0]->mix_flag ?? 'Y';
  429. $R_Mix_LotFlag = $BAS_Location[0]->mix_lotflag ?? 'Y';
  430. $r_LocationAttribute = $BAS_Location[0]->locationattribute;
  431. $r_SKUCount = $BAS_Location[0]->skucount;
  432. if($r_QC_RCV_CTL == 'Y' && $r_QCStatus != '20')return '272';
  433. //如果ASN中ContainerID有值,并且收货SP没有传递跟踪号,则以ContainerID作为跟踪号
  434. if ($r_ASNContainerID && (!$In_New_TraceID || $In_New_TraceID == '*'))$In_New_TraceID = $r_ASNContainerID;
  435. $IN_New_TraceID_OLD = $In_New_TraceID;
  436. if ($r_RCV_TID_CTL == 'Y' && (!$In_New_TraceID || $In_New_TraceID=='*'))return '270';
  437. //必须维护单价后才能收货
  438. if ($R_UNT_PRI_CTL == 'Y'){
  439. if (!$In_TotalPrice || $In_TotalPrice <= 0)return '050';
  440. }
  441. if($r_RCV_TIM_CTL == 'Y' && ($R_CurrentTime->lt(Carbon::parse($r_ExpectedArriveTime1)) || $R_CurrentTime->gt($r_ExpectedArriveTime2)))return '271';
  442. // 同一跟踪号不允许混收产品
  443. if (strtoupper($In_FMLocation) == 'SCANSTATION')$r_RCV_MIX_SKU = 'Y';
  444. else $r_RCV_MIX_SKU=$this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_SKU', 'Y');
  445. $r_RCV_MIX_GR1 = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_GR1', 'Y','C');
  446. //跟踪号的校验处理
  447. if ($In_New_TraceID != '*' && trim($In_New_TraceID)){
  448. if ($R_LoseID_Flag == 'N'){
  449. if ($r_RCV_MIX_TID == 'N'){ //跟踪号是否可以多次收货
  450. $INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT COUNT(*) FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b ON a.LOCATIONID = b.LOCATIONID WHERE b.WAREHOUSEID = '".
  451. $IN_Warehouse."' AND TraceID='".$In_New_TraceID."' AND qty>0"));
  452. if ($INV_LOT_LOC_ID) return '218跟踪号重复错误ID='.$In_New_TraceID;
  453. }else{
  454. if ($r_RCV_MIX_SKU == 'N'){
  455. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT COUNT(*) FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b ON a.locationid = b.LocationID WHERE b.WarehouseID = '".
  456. $IN_Warehouse."' AND TraceID = '".$In_New_TraceID."' AND sku <> '".$In_SKU."' AND qty>0"));
  457. if ($TABLE_INV_LOT_LOC_ID) return '273';
  458. }elseif ($r_RCV_MIX_GR1 == 'N'){
  459. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT count(1) FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b ON a.locationid = b.LocationID INNER JOIN Bas_Sku C ON A.CUSTOMERID = C.CUSTOMERID AND A.SKU = C.SKU WHERE b.WarehouseID = '".
  460. $IN_Warehouse."' AND TraceID='".$In_New_TraceID."' AND C.SKU_GROUP1 <> '".$r_SKU_Group1."' AND qty>0"));
  461. if ($TABLE_INV_LOT_LOC_ID)return '273';
  462. }
  463. //ID是否重复
  464. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT COUNT(*) FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b on a.locationid = b.LocationID where b.WarehouseID ='".
  465. $IN_Warehouse."' AND a.LocationID<>'".$In_TOLocation."' AND a.TraceID='".$In_New_TraceID."' AND a.QTY>0"));
  466. if ($TABLE_INV_LOT_LOC_ID)return '218'.$In_New_TraceID;
  467. }
  468. }else $In_New_TraceID = '*';
  469. }
  470. //r_QtyOnHold:=0
  471. if (!trim($In_HoldRejectCode)) $In_HoldRejectCode = 'OK'; //TODO 1098行
  472. return $OUT_Return_Code;
  473. }
  474. /** 对于快速入库 $IN_Parameter1 = 'RCV_AFTER' | 'RCV_BEFORE'
  475. * 目前该SP只存在 RCV_AFTER(校验近期产品) 且已被注释
  476. */
  477. private function SPUDF_ProcessA($IN_Warehouse, $IN_Parameter1, $IN_Parameter2, $IN_Parameter3, $IN_Parameter4, $IN_Language, $IN_UserID, $OUT_Return_Code){
  478. $r_CurrentTime = Carbon::now();
  479. //TODO 状态为 分配之前 走此逻辑,本快速入库不存在分配之前 不会走此逻辑 保留一下
  480. if ($IN_Parameter1='ALLOCATION_BEFORE'){
  481. $doc_order_header = DB::connection('oracle')->select(DB::raw("SELECT t.Carrierid,t.soreference5 FROM DOC_ORDER_HEADER t WHERE ORDERNO='".$IN_Parameter2."'"));
  482. $r_Carrierid = $doc_order_header[0]->carrierid;
  483. $r_soreference5 = $doc_order_header[0]->soreference5;
  484. if (in_array($r_Carrierid,['ZTO','YUNDA','POSTB','YTO','STO','EMS','SF']) && !$r_soreference5){
  485. $OUT_Return_Code = '999面单号未获取!';
  486. DB::rollBack();
  487. return $OUT_Return_Code;
  488. }
  489. }
  490. //TODO 状态为 导入后的逻辑:SPUDF_ProcessA 77行起 此处忽略 IN_Parameter1='SO_IMPORT_AFTER'
  491. //TODO 装箱完成前,做一些数据处理:SPUDF_ProcessA 125行起 此处忽略 IN_Parameter1='PACKING_BEFORE'
  492. //TODO 装箱完成后,做一些数据处理:SPUDF_ProcessA 132行起 此处忽略 IN_Parameter1='PACKING_AFTER'
  493. //TODO 打印标记:SPUDF_ProcessA 281行起 此处忽略 IN_Parameter1='PRINT'
  494. //TODO 发货前校验是否全部复核:SPUDF_ProcessA 553行起 此处忽略 IN_Parameter1='SHIP_BEFORE'
  495. //TODO 转移时校验库位是否允许混放批次:SPUDF_ProcessA 594行起 此处忽略 IN_Parameter1='TRAPPROVE_BEFORE'
  496. //TODO 分配之后,如果是单品单件订单,更新deliveryno:SPUDF_ProcessA 658行起 此处忽略 IN_Parameter1='ALLOCATION_AFTER'
  497. //TODO 上架前,校验此货主是否必须有拣货位,如果无拣货位,则拦截 by mxl 20191205:SPUDF_ProcessA 675行起 此处忽略 IN_Parameter1='PA_BEFORE'
  498. //TODO ASN关闭后 针对JIANSHANG货主,订单关闭后将数据写入临时表CUS_ADJ_H by mxl 20191217:SPUDF_ProcessA 700行起 此处忽略 IN_Parameter1='ASNCLOSE_AFTER'
  499. //TODO SO关闭后 针对JIANSHANG货主,订单关闭后将数据写入临时表CUS_ADJ_H by mxl 20191217:SPUDF_ProcessA 734行起 此处忽略 IN_Parameter1='SHIP_AFTER'
  500. $OUT_Return_Code = '000';
  501. return $OUT_Return_Code;
  502. }
  503. private function GETSYS_configuration($IN_WarehouseID, $IN_CustomerID, $IN_OrderType, $IN_ConfigID, $IN_DefaultValue = 'N', $IN_ValueType = 'C')
  504. {
  505. if ($IN_ValueType == 'C'){
  506. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_STRING FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='".($IN_CustomerID ?? '*')."' AND OrderType='".($IN_OrderType ?? '*')."' AND CONFIG_ID='".$IN_ConfigID."'"));
  507. if (!$sys_configuration){
  508. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_STRING FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='".($IN_CustomerID ?? '*')."' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  509. if (!$sys_configuration){
  510. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_STRING FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='*' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  511. if (!$sys_configuration){
  512. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_STRING FROM sys_configuration WHERE WarehouseID='*' AND CustomerID='*' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  513. if (!$sys_configuration) return $IN_DefaultValue;
  514. }
  515. }
  516. }
  517. return trim($sys_configuration[0]->value_string);
  518. }
  519. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_INT FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='".($IN_CustomerID ?? '*')."' AND OrderType='".($IN_OrderType ?? '*')."' AND CONFIG_ID='".$IN_ConfigID."'"));
  520. if (!$sys_configuration){
  521. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_INT FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='".($IN_CustomerID ?? '*')."' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  522. if (!$sys_configuration){
  523. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_INT FROM sys_configuration WHERE WarehouseID='".($IN_WarehouseID ?? '*')."' AND CustomerID='*' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  524. if (!$sys_configuration){
  525. $sys_configuration = DB::connection('oracle')->select(DB::raw("SELECT VALUE_INT FROM sys_configuration WHERE WarehouseID='*' AND CustomerID='*' AND OrderType='*' AND CONFIG_ID='".$IN_ConfigID."'"));
  526. if (!$sys_configuration) return $IN_DefaultValue;
  527. }
  528. }
  529. }
  530. return trim($sys_configuration[0]->value_string);
  531. }
  532. }