StoreController.php 35 KB

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