StoreController.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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($docno){
  125. //$docno = ""; //订单号 非ASN号
  126. $db = DB::connection('oracle');
  127. //判断单据有效性
  128. $cus_bs_asnheader = $db->select(DB::raw("SELECT t.addwho FROM CUS_BS_ASNHEADER t WHERE t.ASNREFERENCE1 = '".$docno."'"));
  129. if (!$cus_bs_asnheader) return ['success'=>false, 'data'=>'单据不存在'];
  130. $addwho = $cus_bs_asnheader[0]->addwho;
  131. if ($addwho == "WCS"){
  132. //判断单据状态
  133. $cus_bs_asnheader = $db->select(
  134. DB::raw("SELECT 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'"));
  135. if (!$cus_bs_asnheader) return ['success'=>false, 'data'=>"该单据已完成收货"];
  136. $sql = "select a.warehouseid,a.asnno as docno,a1.asnlineno,a.customerid,t1.sku,a1.packid,t1.receivedqty_each,t1.lotatt01,t1.lotatt02,";
  137. $sql .= " t1.lotatt04,t1.lotatt05,t1.lotatt08,t1.userdefine1 as new_traceid,a.userdefine1,a.userdefine2,a.userdefine3,a.userdefine4,a.userdefine5,t.addwho";
  138. $sql .= " from doc_asn_details a1";
  139. $sql .= " inner join doc_asn_header a on a.asnno = a1.asnno";
  140. $sql .= " inner join cus_bs_asndetails t1 on t1.asnno = a.asnno and t1.asnlineno = a1.asnlineno";
  141. $sql .= " inner join cus_bs_asnheader t on t.asnno = a1.asnno";
  142. $sql .= " where t.asnreference1 = '".$docno."' and nvl(t1.rcvflag,'N') = 'N'";
  143. $doc_asn_details = $db->select(DB::raw($sql));
  144. $db->beginTransaction();
  145. try{
  146. $username=config('database.connections.oracle.username');
  147. $password=config('database.connections.oracle.password');
  148. $host=config('database.connections.oracle.host');
  149. $service_name=config('database.connections.oracle.service_name');
  150. $conn=oci_connect($username,$password,$host.'/'.$service_name);
  151. $sql_sp="begin SPASN_Receiving_Process(:IN_Warehouse, :In_Process_Action, :In_ASNNo_C, :In_ASNLineNo_C, :In_FMTraceID_C, :In_New_TraceID_C, :In_ProductStatus,".
  152. ":In_ProductStatus_Descr, :In_HoldRejectCode_C, :In_HoldRejectReason_C, :In_PONo_C, :In_CustomerID, :In_SKU, :In_ReceivedQty, :In_RejectedQty,:In_UOM, :In_PackID,".
  153. " :In_ContainerID, :In_LotAtt01_C, :In_LotAtt02_C, :In_LotAtt03_C, :In_LotAtt04_C, :In_LotAtt05_C, :In_LotAtt06_C,".
  154. ":In_LotAtt07_C, :In_LotAtt08_C, :In_LotAtt09_C, :In_LotAtt10_C, :In_LotAtt11_C, :In_LotAtt12_C,".
  155. ":In_TotalCubic, :In_TotalGrossWeight, :In_TotalNetWeight, :In_TotalPrice, :In_UserDefine1, :In_UserDefine2,:In_UserDefine3, :In_UserDefine4, :In_UserDefine5, :In_FMLocation,".
  156. ":In_TOLocation_C,:In_QC_Type_C, :In_PlanToLoc_C,:In_ReceivingTime, :In_LPN, :In_Operator, :IN_RCVModule, :IN_RCVStation, :In_Language, :In_UserID, :OUT_Return_Code); end;";
  157. foreach ($doc_asn_details as $doc_asn_detail){
  158. $result = '';
  159. $In_Process_Action = '3';
  160. $In_FMTraceID_C = '';
  161. $In_ProductStatus = '00';
  162. $In_ProductStatus_Descr = '正常';
  163. $In_HoldRejectCode_C = 'OK';
  164. $In_HoldRejectReason_C = '正常';
  165. $In_PONo_C = '';
  166. $In_RejectedQty = '';
  167. $In_UOM = 'EA';
  168. $In_ContainerID = '';
  169. $In_LotAtt03_C = '';
  170. $In_LotAtt06_C = '';
  171. $In_LotAtt07_C = '';
  172. $In_LotAtt09_C = '';
  173. $In_LotAtt10_C = '';
  174. $In_LotAtt11_C = '';
  175. $In_LotAtt12_C = '';
  176. $In_TotalCubic = '0.00';
  177. $In_TotalGrossWeight = '0.00';
  178. $In_TotalNetWeight = '0.00';
  179. $In_TotalPrice = '0.00';
  180. $In_FMLocation = 'STAGE'.$doc_asn_detail->warehouseid;
  181. $In_TOLocation_C = 'STAGE'.$doc_asn_detail->warehouseid;
  182. $In_QC_Type_C = 'OK';
  183. $In_PlanToLoc_C = '';
  184. $In_ReceivingTime = '';
  185. $In_LPN = '*';
  186. $IN_RCVModule = '';
  187. $IN_RCVStation = '';
  188. $In_Language = 'cn';
  189. $stmt = oci_parse($conn, $sql_sp);
  190. oci_bind_by_name($stmt,':IN_Warehouse',$doc_asn_detail->warehouseid);
  191. oci_bind_by_name($stmt,':In_Process_Action',$In_Process_Action);
  192. oci_bind_by_name($stmt,':In_ASNNo_C',$doc_asn_detail->docno);
  193. oci_bind_by_name($stmt,':In_ASNLineNo_C',$doc_asn_detail->asnlineno);
  194. oci_bind_by_name($stmt,':In_FMTraceID_C',$In_FMTraceID_C);
  195. oci_bind_by_name($stmt,':In_New_TraceID_C',$doc_asn_detail->new_traceid);
  196. oci_bind_by_name($stmt,':In_ProductStatus',$In_ProductStatus);
  197. oci_bind_by_name($stmt,':In_ProductStatus_Descr',$In_ProductStatus_Descr);
  198. oci_bind_by_name($stmt,':In_HoldRejectCode_C',$In_HoldRejectCode_C);
  199. oci_bind_by_name($stmt,':In_HoldRejectReason_C',$In_HoldRejectReason_C);
  200. oci_bind_by_name($stmt,':In_PONo_C',$In_PONo_C);
  201. oci_bind_by_name($stmt,':In_CustomerID',$doc_asn_detail->customerid);
  202. oci_bind_by_name($stmt,':In_SKU',$doc_asn_detail->sku);
  203. oci_bind_by_name($stmt,':In_ReceivedQty',$doc_asn_detail->receivedqty_each);
  204. oci_bind_by_name($stmt,':In_RejectedQty',$In_RejectedQty);
  205. oci_bind_by_name($stmt,':In_UOM',$In_UOM);
  206. oci_bind_by_name($stmt,':In_PackID',$doc_asn_detail->packid);
  207. oci_bind_by_name($stmt,':In_ContainerID',$In_ContainerID);
  208. oci_bind_by_name($stmt,':In_LotAtt01_C',$doc_asn_detail->lotatt01);
  209. oci_bind_by_name($stmt,':In_LotAtt02_C',$doc_asn_detail->lotatt02);
  210. oci_bind_by_name($stmt,':In_LotAtt03_C',$In_LotAtt03_C);
  211. oci_bind_by_name($stmt,':In_LotAtt04_C',$doc_asn_detail->lotatt04);
  212. oci_bind_by_name($stmt,':In_LotAtt05_C',$doc_asn_detail->lotatt05);
  213. oci_bind_by_name($stmt,':In_LotAtt06_C',$In_LotAtt06_C);
  214. oci_bind_by_name($stmt,':In_LotAtt07_C',$In_LotAtt07_C);
  215. oci_bind_by_name($stmt,':In_LotAtt08_C',$doc_asn_detail->lotatt08);
  216. oci_bind_by_name($stmt,':In_LotAtt09_C',$In_LotAtt09_C);
  217. oci_bind_by_name($stmt,':In_LotAtt10_C',$In_LotAtt10_C);
  218. oci_bind_by_name($stmt,':In_LotAtt11_C',$In_LotAtt11_C);
  219. oci_bind_by_name($stmt,':In_LotAtt12_C',$In_LotAtt12_C);
  220. oci_bind_by_name($stmt,':In_TotalCubic',$In_TotalCubic);
  221. oci_bind_by_name($stmt,':In_TotalGrossWeight',$In_TotalGrossWeight);
  222. oci_bind_by_name($stmt,':In_TotalNetWeight',$In_TotalNetWeight);
  223. oci_bind_by_name($stmt,':In_TotalPrice',$In_TotalPrice);
  224. oci_bind_by_name($stmt,':In_UserDefine1',$doc_asn_detail->userdefine1);
  225. oci_bind_by_name($stmt,':In_UserDefine2',$doc_asn_detail->userdefine2);
  226. oci_bind_by_name($stmt,':In_UserDefine3',$doc_asn_detail->userdefine3);
  227. oci_bind_by_name($stmt,':In_UserDefine4',$doc_asn_detail->userdefine4);
  228. oci_bind_by_name($stmt,':In_UserDefine5',$doc_asn_detail->userdefine5);
  229. oci_bind_by_name($stmt,':In_FMLocation',$In_FMLocation);
  230. oci_bind_by_name($stmt,':In_TOLocation_C',$In_TOLocation_C);
  231. oci_bind_by_name($stmt,':In_QC_Type_C',$In_QC_Type_C);
  232. oci_bind_by_name($stmt,':In_PlanToLoc_C',$In_PlanToLoc_C);
  233. oci_bind_by_name($stmt,':In_ReceivingTime',$In_ReceivingTime);
  234. oci_bind_by_name($stmt,':In_LPN',$In_LPN);
  235. oci_bind_by_name($stmt,':In_Operator',$doc_asn_detail->addwho);
  236. oci_bind_by_name($stmt,':IN_RCVModule',$IN_RCVModule);
  237. oci_bind_by_name($stmt,':IN_RCVStation',$IN_RCVStation);
  238. oci_bind_by_name($stmt,':In_Language',$In_Language);
  239. oci_bind_by_name($stmt,':In_UserID',$doc_asn_detail->addwho);
  240. oci_bind_by_name($stmt,':OUT_Return_Code',$result);
  241. oci_execute($stmt);
  242. if (substr($result,1,3) == '000'){
  243. $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'Y' where t.asnno = ? and t.asnlineno = ?");
  244. $db->update($query,[$doc_asn_detail->docno,$doc_asn_detail->asnlineno]);
  245. }else{
  246. $query = DB::raw("update cus_bs_asndetails t set t.rcvflag = 'W' where t.asnno = ? and t.asnlineno = ?");
  247. $db->update($query,[$doc_asn_detail->docno,$doc_asn_detail->asnlineno]);
  248. $db->rollBack();
  249. return ['success'=>false, 'data'=>'收货失败','code'=>$result];
  250. }
  251. }
  252. $db->commit();
  253. return ['success'=>true];
  254. }catch (\Exception $e){
  255. $db->rollBack();
  256. return ['success'=>false, 'data'=>$e->getMessage()];
  257. }
  258. }
  259. }
  260. /*$resule = $that->exe($doc_asn_detail->warehouseid,'3',$doc_asn_detail->docno,$doc_asn_detail->asnlineno,'',$doc_asn_detail->new_traceid,'00','正常','OK','正常',
  261. '',$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,
  262. '',$doc_asn_detail->lotatt04,$doc_asn_detail->lotatt05,'','',$doc_asn_detail->lotatt08,'','','','',
  263. '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,
  264. 'STAGE'.$doc_asn_detail->warehouseid,'OK','','','*',$doc_asn_detail->addwho,'','','cn',$doc_asn_detail->addwho,'');*/
  265. /** $In_Process_Action为来源渠道,快速入库调用固定值 为 '3' */
  266. private function exe($IN_Warehouse, $In_Process_Action, $In_ASNNo_C, $In_ASNLineNo_C, $In_FMTraceID_C, $In_New_TraceID_C, $In_ProductStatus,
  267. $In_ProductStatus_Descr, $In_HoldRejectCode_C, $In_HoldRejectReason_C, $In_PONo_C, $In_CustomerID, $In_SKU, $In_ReceivedQty, $In_RejectedQty,
  268. $In_UOM, $In_PackID, $In_ContainerID, $In_LotAtt01_C, $In_LotAtt02_C, $In_LotAtt03_C, $In_LotAtt04_C, $In_LotAtt05_C, $In_LotAtt06_C,
  269. $In_LotAtt07_C, $In_LotAtt08_C, $In_LotAtt09_C, $In_LotAtt10_C, $In_LotAtt11_C, $In_LotAtt12_C,
  270. $In_TotalCubic, $In_TotalGrossWeight, $In_TotalNetWeight, $In_TotalPrice, $In_UserDefine1, $In_UserDefine2,
  271. $In_UserDefine3, $In_UserDefine4, $In_UserDefine5, $In_FMLocation, $In_TOLocation_C, $In_QC_Type_C, $In_PlanToLoc_C,
  272. $In_ReceivingTime, $In_LPN, $In_Operator, $IN_RCVModule, $IN_RCVStation, $In_Language, $In_UserID, $OUT_Return_Code)
  273. {
  274. /*$r_NO_COMMIT $R_CurrentTime $OUT_Return_Code $R_ReceivingTime $r_LPN $r_UDF2_AD $r_UDF2_IN
  275. $R_Qty_PlanPutaway $R_QCTaskID $R_HOLD_FLAG $R_PA_TaskID $R_PA_Flag $R_QC_Sequence $R_PA_Sequence
  276. $R_Reserve_Flag $R_QtyMVOut $r_TotalGrossWeight $r_TotalCubic r_TotalNetWeight r_TotalPrice In_LotAtt01
  277. In_LotAtt02 In_LotAtt03 In_LotAtt04 In_LotAtt05 In_LotAtt06 In_LotAtt07 In_LotAtt08 In_LotAtt09 In_LotAtt10
  278. In_LotAtt11 In_LotAtt12 In_HoldRejectCode In_HoldRejectReason
  279. */
  280. /** IS */
  281. $r_OutboundLifeDays = 0;
  282. $r_InboundLifeDays = 0;
  283. if ($OUT_Return_Code == "NO_COMMIT" || $OUT_Return_Code == "*_*"){
  284. $r_NO_COMMIT = 'N';
  285. }else{
  286. $r_NO_COMMIT = 'Y';
  287. }
  288. //初始化
  289. $R_CurrentTime = Carbon::now();
  290. $OUT_Return_Code ='000';
  291. if (!$In_ReceivingTime){
  292. $R_ReceivingTime = Carbon::now();
  293. }else{
  294. $R_ReceivingTime = $In_ReceivingTime;
  295. }
  296. //else R_ReceivingTime:=To_Date( IN_ReceivingTime,'YYYY/MM/DD hh24:mi:ss'); --2008-11-25 15:53:33
  297. if ($In_LPN && $In_LPN != "*"){
  298. $r_LPN = $In_LPN;
  299. }else $r_LPN = "*";
  300. $bascode = DB::select(DB::raw("SELECT udf2 FROM BAS_CODES WHERE codeid ='TRN_TYP' AND code='AD'"));
  301. $r_UDF2_AD = $bascode[0]->udf2 ?? 'N';
  302. $bascode = DB::select(DB::raw("SELECT udf2 FROM BAS_CODES WHERE codeid ='TRN_TYP' AND code='IN'"));
  303. $r_UDF2_IN = $bascode[0]->udf2 ?? 'N';
  304. $R_Qty_PlanPutaway = 0;
  305. $R_QCTaskID = '*';
  306. $R_HOLD_FLAG = 'N';
  307. $R_PA_TaskID = '*';
  308. $R_PA_Flag = 'N';
  309. $R_QC_Sequence = 0;
  310. $R_PA_Sequence = 0;
  311. $R_Reserve_Flag = 'N';
  312. $R_QtyMVOut = 0;
  313. $r_TotalGrossWeight = $In_TotalGrossWeight;
  314. $r_TotalCubic = $In_TotalCubic;
  315. $r_TotalNetWeight = $In_TotalNetWeight ?? 0;
  316. $r_TotalPrice = $In_TotalPrice;
  317. $In_LotAtt01 = $In_LotAtt01_C;
  318. $In_LotAtt02 = $In_LotAtt02_C;
  319. $In_LotAtt03 = $In_LotAtt03_C;
  320. $In_LotAtt04 = $In_LotAtt04_C;
  321. $In_LotAtt05 = $In_LotAtt05_C;
  322. $In_LotAtt06 = $In_LotAtt06_C;
  323. $In_LotAtt07 = $In_LotAtt07_C;
  324. $In_LotAtt08 = $In_LotAtt08_C;
  325. $In_LotAtt09 = $In_LotAtt09_C;
  326. $In_LotAtt10 = $In_LotAtt10_C;
  327. $In_LotAtt11 = $In_LotAtt11_C;
  328. $In_LotAtt12 = $In_LotAtt12_C;
  329. $In_HoldRejectCode = $In_HoldRejectCode_C;
  330. $In_HoldRejectReason = $In_HoldRejectReason_C;
  331. $In_TOLocation = $In_TOLocation_C;
  332. $In_New_TraceID = $In_New_TraceID_C ?? '*';
  333. $In_QC_Type = $In_QC_Type_C;
  334. $In_FMTraceID = $In_FMTraceID_C;
  335. $In_ASNNo = $In_ASNNo_C;
  336. $In_ASNLineNo = $In_ASNLineNo_C;
  337. $In_PONo = $In_PONo_C;
  338. $In_PlanToLoc = $In_PlanToLoc_C;
  339. $r_nrow = 0;
  340. $OUT_Return_Code = '*_*';
  341. //此处调用必然返回000,所以直接忽视判断进入下层逻辑
  342. $OUT_Return_Code = $this->SPUDF_ProcessA($IN_Warehouse,'RCV_BEFORE',$In_ASNNo,$In_ASNLineNo,$In_ReceivedQty,$In_Language,$In_UserID,$OUT_Return_Code);
  343. //TODO 盲收逻辑 SPASN_Receiving_Process:536行 $In_Process_Action = 2
  344. //如果订单已经关闭或者取消,则报错
  345. $doc_asn_header = DB::connection('oracle')->select(DB::raw("Select 1 from DOC_ASN_Header where ASNNO='".$In_ASNNo."' and (ASNStatus='90' or ASNStatus='99')"));
  346. if ($doc_asn_header) return '201';
  347. //收货数量必须大于0
  348. if ($In_ReceivedQty <= 0 && ((!$In_ProductStatus) || $In_ProductStatus == '00')) return '204';
  349. //批次属性自动复制 系统配置是否允许超量收货
  350. $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'"));
  351. if (!$customer) return '888BAS_Customer,OPEN';
  352. $R_OverReceiving = $customer[0]->overreceiving ?? 'N';
  353. $R_OverRCVPercentage_Customer = $customer[0]->overrcvpercentage ?? 0;
  354. $r_ASN_LNK_PO = $customer[0]->asn_lnk_po ?? 'Y';
  355. $R_AsnRef1ToLot4 = $customer[0]->asnref1tolot4;
  356. $R_AsnRef2ToLot5 = $customer[0]->asnref2tolot5;
  357. $R_AsnRef3ToLot6 = $customer[0]->asnref3tolot6;
  358. $R_AsnRef4ToLot7 = $customer[0]->asnref4tolot7;
  359. $R_AsnRef5ToLot8 = $customer[0]->asnref5tolot8;
  360. $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."'"));
  361. if (!$DOC_ASN_Header) return '888DOC_ASN_Header,OPEN';
  362. $r_ASNReference1 = $DOC_ASN_Header[0]->asnreference1;
  363. $r_ASNReference2 = $DOC_ASN_Header[0]->asnreference2;
  364. $r_ASNReference3 = $DOC_ASN_Header[0]->asnreference3;
  365. $r_ASNReference4 = $DOC_ASN_Header[0]->asnreference4;
  366. $r_ASNReference5 = $DOC_ASN_Header[0]->asnreference5;
  367. $r_ExpectedArriveTime1 = $DOC_ASN_Header[0]->expectedarrivetime1 ?? "2000-01-01 00:00:00";
  368. $r_ExpectedArriveTime2 = $DOC_ASN_Header[0]->expectedarrivetime2 ?? "2099-12-31 00:00:00";
  369. $r_QCStatus = $DOC_ASN_Header[0]->qcstatus;
  370. $r_ASNType = $DOC_ASN_Header[0]->asntype;
  371. $r_WarehouseID = $DOC_ASN_Header[0]->warehouseid;
  372. $R_ReleaseStatus = $DOC_ASN_Header[0]->releasestatus;
  373. $r_Priority = $DOC_ASN_Header[0]->priority ?? '3';
  374. if ($R_AsnRef1ToLot4 == 'Y' && ($r_ASNReference1 && $r_ASNReference1 != "*") && ((!$In_LotAtt04) || $In_LotAtt04=='*')){
  375. $In_LotAtt04 = $r_ASNReference1;
  376. }
  377. if ($R_AsnRef2ToLot5 == 'Y' && ($r_ASNReference2 && $r_ASNReference2 != "*") && ((!$In_LotAtt05) || $In_LotAtt05=='*')){
  378. $In_LotAtt05 = $r_ASNReference2;
  379. }
  380. if ($R_AsnRef3ToLot6 == 'Y' && ($r_ASNReference3 && $r_ASNReference3 != "*") && ((!$In_LotAtt06) || $In_LotAtt06=='*')){
  381. $In_LotAtt06 = $r_ASNReference3;
  382. }
  383. if ($R_AsnRef4ToLot7 == 'Y' && ($r_ASNReference4 && $r_ASNReference4 != "*") && ((!$In_LotAtt07) || $In_LotAtt07=='*')){
  384. $In_LotAtt07 = $r_ASNReference4;
  385. }
  386. if ($R_AsnRef5ToLot8 == 'Y' && ($r_ASNReference5 && $r_ASNReference5 != "*") && ((!$In_LotAtt08) || $In_LotAtt08=='*')){
  387. $In_LotAtt08 = $r_ASNReference5;
  388. }
  389. if ($In_LotAtt01 == 'YYYY-MM-DD') $In_LotAtt01 = null;
  390. if ($In_LotAtt02 == 'YYYY-MM-DD') $In_LotAtt02 = null;
  391. if ($In_LotAtt03 == 'YYYY-MM-DD') $In_LotAtt03 = null;
  392. // TODO SPASN_Receiving_Process:643行 IN_ProductStatus固定值00 跳过
  393. //生产日期、入库日期、失效日期的逻辑校验
  394. 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)))){
  395. return "260";
  396. }
  397. $r_ASN_MDT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_MDT_CHK');
  398. //入库生产日期不能小于在库库存生产日期
  399. if ($r_ASN_MDT_CHK == 'Y' && trim($In_LotAtt01)){
  400. $data = DB::connection('oracle')->select(DB::raw("SELECT 1 c FROM INV_LOT_LOC_ID a,INV_LOT_ATT b, bas_location c WHERE a.CUSTOMERID='".$In_CustomerID.
  401. "' AND a.sku='".$In_SKU."' AND a.LotNum=b.LotNum AND a.LocationID=c.LocationID AND c.LocationUsage<>'ST' AND b.LotAtt01>'".$In_LotAtt01."'"));
  402. if ($data) return '266INV_LOT_LOC_ID';
  403. }
  404. //批次属性必输校验
  405. $BAS_lotID = DB::connection('oracle')->select(DB::raw("SELECT LotAtt01_Flag,LotAtt02_Flag,LotAtt03_Flag,LotAtt04_Flag,LotAtt05_Flag,LotAtt06_Flag,".
  406. "LotAtt07_Flag,LotAtt08_Flag,LotAtt09_Flag,LotAtt10_Flag,LotAtt11_Flag,LotAtt12_Flag,OverRCVPercentage,a.LotID,PackID,".
  407. "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"));
  408. if (!$BAS_lotID)return "888From Bas_SKU*BAS_lotID,OPEN";
  409. $r_LotAtt01_Flag = $BAS_lotID[0]->lotatt01_flag;
  410. $r_LotAtt02_Flag = $BAS_lotID[0]->lotatt02_flag;
  411. $r_LotAtt03_Flag = $BAS_lotID[0]->lotatt03_flag;
  412. $r_LotAtt04_Flag = $BAS_lotID[0]->lotatt04_flag;
  413. $r_LotAtt05_Flag = $BAS_lotID[0]->lotatt05_flag;
  414. $r_LotAtt06_Flag = $BAS_lotID[0]->lotatt06_flag;
  415. $r_LotAtt07_Flag = $BAS_lotID[0]->lotatt07_flag;
  416. $r_LotAtt08_Flag = $BAS_lotID[0]->lotatt08_flag;
  417. $r_LotAtt09_Flag = $BAS_lotID[0]->lotatt09_flag;
  418. $r_LotAtt10_Flag = $BAS_lotID[0]->lotatt10_flag;
  419. $r_LotAtt11_Flag = $BAS_lotID[0]->lotatt11_flag;
  420. $r_LotAtt12_Flag = $BAS_lotID[0]->lotatt12_flag;
  421. $r_OverRCVPercentage_SKU = $BAS_lotID[0]->overrcvpercentage ?? 0;
  422. $r_SKU_LOTID = $BAS_lotID[0]->lotid;
  423. $r_SKU_PackID = $BAS_lotID[0]->packid;
  424. $r_SKU_GrossWeight = $BAS_lotID[0]->grossweight;
  425. $r_SKU_Cube = $BAS_lotID[0]->cube;
  426. $r_CopyPackIDToLotAtt12 = $BAS_lotID[0]->copypackidtolotatt12;
  427. $r_AllowReceiving = $BAS_lotID[0]->allowreceiving;
  428. $r_SKU_Group1 = $BAS_lotID[0]->sku_group1;
  429. //是否被设置禁止入库
  430. if ($r_AllowReceiving == 'N') return "117";
  431. if (($r_LotAtt01_Flag == '3' && !$In_LotAtt01) ||
  432. ($r_LotAtt02_Flag == "3" && !$In_LotAtt02) ||
  433. ($r_LotAtt03_Flag == "3" && !$In_LotAtt03) ||
  434. ($r_LotAtt04_Flag == "3" && !$In_LotAtt04) ||
  435. ($r_LotAtt05_Flag == "3" && !$In_LotAtt05) ||
  436. ($r_LotAtt06_Flag == "3" && !$In_LotAtt06) ||
  437. ($r_LotAtt07_Flag == "3" && !$In_LotAtt07) ||
  438. ($r_LotAtt08_Flag == "3" && !$In_LotAtt08) ||
  439. ($r_LotAtt09_Flag == "3" && !$In_LotAtt09) ||
  440. ($r_LotAtt10_Flag == "3" && !$In_LotAtt10) ||
  441. ($r_LotAtt11_Flag == "3" && !$In_LotAtt11) ||
  442. ($r_LotAtt12_Flag == "3" && !$In_LotAtt12))return "221".$In_ASNLineNo_C;
  443. if ($r_LotAtt01_Flag == '1' && $In_LotAtt01) $In_LotAtt01 = null;
  444. if ($r_LotAtt02_Flag == '1' && $In_LotAtt02) $In_LotAtt02 = null;
  445. if ($r_LotAtt03_Flag == '1' && $In_LotAtt03) $In_LotAtt03 = null;
  446. if ($r_LotAtt04_Flag == '1' && $In_LotAtt04) $In_LotAtt04 = null;
  447. if ($r_LotAtt05_Flag == '1' && $In_LotAtt05) $In_LotAtt05 = null;
  448. if ($r_LotAtt06_Flag == '1' && $In_LotAtt06) $In_LotAtt06 = null;
  449. if ($r_LotAtt07_Flag == '1' && $In_LotAtt07) $In_LotAtt07 = null;
  450. if ($r_LotAtt08_Flag == '1' && $In_LotAtt08) $In_LotAtt08 = null;
  451. if ($r_LotAtt09_Flag == '1' && $In_LotAtt09) $In_LotAtt09 = null;
  452. if ($r_LotAtt10_Flag == '1' && $In_LotAtt10) $In_LotAtt10 = null;
  453. //if ($r_LotAtt11_Flag == '1' && $In_LotAtt11) $In_LotAtt11 = null;
  454. if ($r_LotAtt12_Flag == '1' && $In_LotAtt12) $In_LotAtt12 = null;
  455. $R_LOT_12_PKG = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'LOT_#12_PKG');
  456. // 批次属性12被设置为跟踪包装数量,不允许输入非数字字符'
  457. if ($R_LOT_12_PKG == 'Y' && !is_numeric($In_LotAtt12)) return "232";
  458. if ($r_OverRCVPercentage_SKU != 0) $r_OverRCVPercentage = $r_OverRCVPercentage_SKU;
  459. else $r_OverRCVPercentage = $R_OverRCVPercentage_Customer;
  460. // TODO 药品相关逻辑 SPASN_Receiving_Process:817行 药品有效期 证书有效期 经营许可证有效期校验提示
  461. //基础设置是否维护完全校验
  462. $R_BAS_PAC_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_PAC_CHK');
  463. $R_BAS_LOT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_LOT_CHK');
  464. $R_BAS_GWT_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_GWT_CHK');
  465. $R_BAS_CUB_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'BAS_CUB_CHK');
  466. if ($R_BAS_PAC_CHK == 'Y' && !$r_SKU_PackID)return '110'.$In_SKU;
  467. if ($R_BAS_LOT_CHK == 'Y' && !$r_SKU_LOTID)return '111';
  468. if ($R_BAS_GWT_CHK == 'Y' && $r_SKU_GrossWeight == 0)return '112';
  469. if ($R_BAS_CUB_CHK == 'Y' && $r_SKU_Cube == 0)return '113';
  470. //订单释放状态校验
  471. if($R_ReleaseStatus == 'N') return '226';
  472. /*参数准备 */
  473. //必须输入价格
  474. $R_UNT_PRI_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'UNT_PRI_CTL');
  475. //收货后打印上架标签
  476. $R_PRT_PTA_LBL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PRT_PTA_LBL');
  477. //ASN收货自动产生跟踪号
  478. $r_ASN_GEN_TID = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_GEN_TID');
  479. //收货后将收货结果更新ASN明细
  480. $r_ASN_RCV_UPD = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'ASN_RCV_UPD');
  481. //完全收货后自动关闭ASN
  482. $r_RCV_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_CTL');
  483. //超过产品有效期控制天数是否拒收
  484. $r_EXP_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'EXP_CTL');
  485. //码盘后才能收货
  486. $r_PLT_RCV = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PLT_RCV');
  487. //跨区域货物是否允许收到一个托盘上
  488. $r_RCV_CRS_ARA = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_CRS_ARA');
  489. //收货时必须指定跟踪号
  490. $r_RCV_TID_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_TID_CTL');
  491. //超额收货
  492. $R_OverReceiving = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'OVR_RCV');
  493. //收货时间必须在预期到货时间范围内
  494. $r_RCV_TIM_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_TIM_CTL');
  495. //同一跟踪号不允许在收货区重复收货
  496. $r_RCV_MIX_TID = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_TID');
  497. //只有上架确认后才能关闭ASN
  498. $r_PTA_CLS_CHK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PTA_CLS_CHK');
  499. //收货数量拆分寻找目标库位
  500. $r_RCV_BRK_TSK = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_BRK_TSK');
  501. //扫描收货时记录箱码和序列号
  502. $r_SN_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'SN#_CTL','0');
  503. //质检后才能收货
  504. $r_QC_RCV_CTL = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'QC_RCV_CTL');
  505. //目标库位为拆零拣货位拆箱时作废箱码
  506. $r_PCK_LOS_SN = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'PCK_LOS_SN');
  507. //服装行业插件开关
  508. $r_IND_TEX = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'IND_TEX');
  509. if ($In_Process_Action != '2'){
  510. $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"));
  511. if (!$DOC_ASN_DETAiLS)return '104'.$In_ASNNo.":".$In_ASNLineNo;
  512. $r_ExpectedQty_Each_ASN = $DOC_ASN_DETAiLS[0]->expectedqty_each;
  513. $r_ReceivedQty_Each_ASN = $DOC_ASN_DETAiLS[0]->receivedqty_each;
  514. $r_POLineNO = $DOC_ASN_DETAiLS[0]->polineno;
  515. $r_PONO = $DOC_ASN_DETAiLS[0]->pono;
  516. $R_OverRCVPercentage_ASN = $DOC_ASN_DETAiLS[0]->overrcvpercentage;
  517. $r_ASNContainerID = $DOC_ASN_DETAiLS[0]->containerid ?? '';
  518. $r_QCStatus = $DOC_ASN_DETAiLS[0]->qcstatus ?? '';
  519. }
  520. //目标库位属性
  521. if ($In_TOLocation == '*' || !trim($In_TOLocation))$In_TOLocation = $In_FMLocation;
  522. $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."'"));
  523. if (!$BAS_Location)return '104'.$In_TOLocation;
  524. $R_LocationUsage = $BAS_Location[0]->locationusage;
  525. $R_LoseID_Flag = $BAS_Location[0]->loseid_flag ?? 'N';
  526. $R_Mix_Flag = $BAS_Location[0]->mix_flag ?? 'Y';
  527. $R_Mix_LotFlag = $BAS_Location[0]->mix_lotflag ?? 'Y';
  528. $r_LocationAttribute = $BAS_Location[0]->locationattribute;
  529. $r_SKUCount = $BAS_Location[0]->skucount;
  530. if($r_QC_RCV_CTL == 'Y' && $r_QCStatus != '20')return '272';
  531. //如果ASN中ContainerID有值,并且收货SP没有传递跟踪号,则以ContainerID作为跟踪号
  532. if ($r_ASNContainerID && (!$In_New_TraceID || $In_New_TraceID == '*'))$In_New_TraceID = $r_ASNContainerID;
  533. $IN_New_TraceID_OLD = $In_New_TraceID;
  534. if ($r_RCV_TID_CTL == 'Y' && (!$In_New_TraceID || $In_New_TraceID=='*'))return '270';
  535. //必须维护单价后才能收货
  536. if ($R_UNT_PRI_CTL == 'Y'){
  537. if (!$In_TotalPrice || $In_TotalPrice <= 0)return '050';
  538. }
  539. if($r_RCV_TIM_CTL == 'Y' && ($R_CurrentTime->lt(Carbon::parse($r_ExpectedArriveTime1)) || $R_CurrentTime->gt($r_ExpectedArriveTime2)))return '271';
  540. // 同一跟踪号不允许混收产品
  541. if (strtoupper($In_FMLocation) == 'SCANSTATION')$r_RCV_MIX_SKU = 'Y';
  542. else $r_RCV_MIX_SKU=$this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_SKU', 'Y');
  543. $r_RCV_MIX_GR1 = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'RCV_MIX_GR1', 'Y','C');
  544. //跟踪号的校验处理
  545. if ($In_New_TraceID != '*' && trim($In_New_TraceID)){
  546. if ($R_LoseID_Flag == 'N'){
  547. if ($r_RCV_MIX_TID == 'N'){ //跟踪号是否可以多次收货
  548. $INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT 1 FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b ON a.LOCATIONID = b.LOCATIONID WHERE b.WAREHOUSEID = '".
  549. $IN_Warehouse."' AND TraceID='".$In_New_TraceID."' AND qty>0"));
  550. if ($INV_LOT_LOC_ID) return '218跟踪号重复错误ID='.$In_New_TraceID;
  551. }else{
  552. if ($r_RCV_MIX_SKU == 'N'){
  553. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT 1 FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b ON a.locationid = b.LocationID WHERE b.WarehouseID = '".
  554. $IN_Warehouse."' AND TraceID = '".$In_New_TraceID."' AND sku <> '".$In_SKU."' AND qty>0"));
  555. if ($TABLE_INV_LOT_LOC_ID) return '273';
  556. }elseif ($r_RCV_MIX_GR1 == 'N'){
  557. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT 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 = '".
  558. $IN_Warehouse."' AND TraceID='".$In_New_TraceID."' AND C.SKU_GROUP1 <> '".$r_SKU_Group1."' AND qty>0"));
  559. if ($TABLE_INV_LOT_LOC_ID)return '273';
  560. }
  561. //ID是否重复
  562. $TABLE_INV_LOT_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT 1 FROM INV_LOT_LOC_ID a INNER JOIN view_MultiWarehouse b on a.locationid = b.LocationID where b.WarehouseID ='".
  563. $IN_Warehouse."' AND a.LocationID<>'".$In_TOLocation."' AND a.TraceID='".$In_New_TraceID."' AND a.QTY>0"));
  564. if ($TABLE_INV_LOT_LOC_ID)return '218'.$In_New_TraceID;
  565. }
  566. }else $In_New_TraceID = '*';
  567. }
  568. //r_QtyOnHold:=0
  569. if (!trim($In_HoldRejectCode)) $In_HoldRejectCode = 'OK'; //TODO 1098行
  570. //ID合法性校验 禁止收货到封存库位
  571. if (in_array($r_LocationAttribute,["HD","FI"]))return '228';
  572. //混放产品校验
  573. if (($R_Mix_Flag == 'N' || $r_SKUCount > 0) && $R_LocationUsage != 'ST'){
  574. $TABLE_inv_lot_LOC_ID = DB::connection('oracle')->select(DB::raw("SELECT COUNT(distinct SKU) c FROM inv_lot_LOC_ID WHERE LocationID='".$In_TOLocation."' AND sku <> '".$In_SKU.
  575. "' AND Qty > 0"));
  576. if ($TABLE_inv_lot_LOC_ID){
  577. if ($TABLE_inv_lot_LOC_ID[0]->c >= 1 && $R_Mix_Flag == 'N')return '205'.rtrim($In_TOLocation);
  578. elseif ($R_Mix_Flag == 'Y' && $r_SKUCount > 0 && $TABLE_inv_lot_LOC_ID[0]->c >= $r_SKUCount) return '367'.$r_SKUCount;
  579. }
  580. }
  581. //码盘后才能收货
  582. if (!rtrim($In_FMTraceID))$In_FMTraceID = '*';
  583. if ($r_PLT_RCV == 'Y' && $In_FMTraceID == '*')return '217';
  584. if ($In_FMTraceID != '*'){
  585. //无论是ASn收货还是码盘收货, 交易里的FMUOM/QTY/Packid都取收货的数据
  586. $TABLE_DOC_Trace_Details = DB::connection('oracle')->select(DB::raw("SELECT PlanToLoc, UOM, LineStatus, Reserve_Flag,Lotnum, ExpectedQty_Each - ReceivedQty_Each from DOC_Trace_Details ".
  587. "WHERE TraceID=In_FMTraceID AND ASNNO='".$In_ASNNo."' AND ASNLineNO='".$In_ASNLineNo."'"));
  588. if (!$TABLE_DOC_Trace_Details) return '104'.$In_ASNNo.":".$In_ASNLineNo;
  589. $r_PlanToLoc_Trace = $TABLE_DOC_Trace_Details[0]->plantoloc;
  590. $r_TraceUOM = $TABLE_DOC_Trace_Details[0]->uom;
  591. $r_LineStatus_Trace = $TABLE_DOC_Trace_Details[0]->linestatus;
  592. $R_Reserve_Flag = $TABLE_DOC_Trace_Details[0]->reserve_flag;
  593. $r_Lotnum_Trace = $TABLE_DOC_Trace_Details[0]->lotnum;
  594. $r_CancelQty_Trace = $TABLE_DOC_Trace_Details[0]->expectedqty_each - $TABLE_DOC_Trace_Details[0]->receivedqty_each;
  595. if ($R_Reserve_Flag == 'Y' && $R_LocationUsage != 'ST'){
  596. $OUT_Return_Code = '*_*';
  597. $OUT_Return_Code = $this->spasn_reserve_cancel($IN_Warehouse, 'TRACEID', $In_ASNNo, $In_ASNLineNo, $In_FMTraceID, $In_Language, $In_UserID, $OUT_Return_Code);
  598. if (substr($OUT_Return_Code,1,3) != '000'){
  599. DB::rollBack();
  600. return $OUT_Return_Code;
  601. }
  602. }
  603. }else{
  604. //没有码盘
  605. $r_FMUOM = $In_UOM;
  606. $r_FMPackID = $In_PackID;
  607. $r_FMQty_Each = '';
  608. $r_FMQty = $In_ReceivedQty;
  609. }
  610. //收货时使用的包装数量转换
  611. $TABLE_bas_Package = DB::connection('oracle')->select(DB::raw("SELECT QTY1,QTY2,QTY3,QTY4,QTY5,IN_Label1,IN_Label3,IN_Label4 FROM bas_Package where PackID='".$In_PackID."'"));
  612. if (!$TABLE_bas_Package)return '104'.$In_PackID;
  613. $r_QTY1_P = $TABLE_bas_Package[0]->qty1;
  614. $r_QTY2_P = $TABLE_bas_Package[0]->qty2;
  615. $r_QTY3_P = $TABLE_bas_Package[0]->qty3;
  616. $r_QTY4_P = $TABLE_bas_Package[0]->qty4;
  617. $r_QTY5_P = $TABLE_bas_Package[0]->qty5;
  618. $r_IN_Label1 = $TABLE_bas_Package[0]->in_label1;
  619. $r_IN_Label3 = $TABLE_bas_Package[0]->in_label3;
  620. $r_IN_Label4 = $TABLE_bas_Package[0]->in_label4;
  621. if ($r_CopyPackIDToLotAtt12 == 'Y')$In_LotAtt12 = $r_QTY3_P;
  622. if ($R_LOT_12_PKG == 'Y' && $In_UOM == 'CS')$R_UOMQty_Read = $In_LotAtt12;
  623. else{
  624. switch ($In_UOM){
  625. case 'EA':
  626. $R_UOMQty_Read = $r_QTY1_P;
  627. break;
  628. case 'IP':
  629. $R_UOMQty_Read = $r_QTY2_P;
  630. break;
  631. case 'CS':
  632. $R_UOMQty_Read = $r_QTY3_P;
  633. break;
  634. case 'PL':
  635. $R_UOMQty_Read = $r_QTY4_P;
  636. break;
  637. case 'OT':
  638. $R_UOMQty_Read = $r_QTY5_P;
  639. break;
  640. }
  641. }
  642. $r_FMQty_Each = ($r_FMQty ?? 0) * ($R_UOMQty_Read ?? 0);
  643. $r_ReceivedQty_Each = $In_ReceivedQty * ($R_UOMQty_Read ?? 0);
  644. if (!$r_TotalCubic) $r_TotalCubic = ($r_SKU_Cube ?? 0) * $r_ReceivedQty_Each;
  645. if ($In_Process_Action != 2){
  646. if ($R_OverRCVPercentage_ASN ?? false)$r_OverRCVPercentage = $R_OverRCVPercentage_ASN;
  647. //质检控制
  648. if ($r_QC_RCV_CTL == 'C'){ //校验合格数
  649. $TABLE_ACT_QC_Transaction = DB::connection('oracle')->select(DB::raw("SELECT SUM(QCQty_PASS) pass FROM ACT_QC_Transaction a INNER JOIN DOC_QC_Header b ON A.QCNo = b.QcNo WHERE B.ASNNo = '".$In_ASNNo."' AND A.AsnLineNo = '".$In_ASNLineNo."' AND B.QCStatus < '90'"));
  650. if ($TABLE_ACT_QC_Transaction)$r_QCQTY_Pass = $TABLE_ACT_QC_Transaction[0]->pass;
  651. if ((($r_ReceivedQty_Each_ASN ?? 0) + $r_ReceivedQty_Each) > ($r_QCQTY_Pass ?? 0)) return '225';
  652. }else{
  653. $TABLE_doc_QC_Details = DB::connection('oracle')->select(DB::raw("SELECT C.UDF1 from doc_QC_Details a INNER JOIN doc_QC_Header b ON a.QcNo = b.QcNo INNER JOIN BAS_Codes C ON a.QCResult = C.Code and codeid = 'QC_RST' WHERE B.ASNNo = '".$In_ASNNo."' and A.AsnLineNo = '".$In_ASNLineNo."' and B.QCStatus < '90' and rownum = 1"));
  654. if ($TABLE_doc_QC_Details) $r_UDF1 = $TABLE_doc_QC_Details[0]->udf1;
  655. if ($r_UDF1 ?? false){
  656. if ($r_UDF1 == 'NOPASS')return '229'; //拒收,原因:质检不合格'
  657. if ($r_UDF1 == 'CONTROL'){
  658. $TABLE_ACT_QC_Transaction = DB::connection('oracle')->select(DB::raw("Select SUM(QcQty_Reject) QcQty_Reject from ACT_QC_Transaction a inner join DOC_QC_Header b ON A.QCNo = b.QcNo Where B.ASNNo = '".$In_ASNNo."' and A.AsnLineNo = '".$In_ASNLineNo."' and B.QCStatus <> '90'"));
  659. if ($TABLE_ACT_QC_Transaction) $r_QCQTY_Reject = $TABLE_ACT_QC_Transaction[0]->qcqty_reject;
  660. if (($r_ReceivedQty_Each_ASN ?? 0 + $r_ReceivedQty_Each) > ($r_ExpectedQty_Each_ASN ?? 0 - ($r_QCQTY_Reject ?? 0)))return '225'; //超出质检合格数
  661. }
  662. }
  663. }
  664. }
  665. //超量收货校验
  666. if ($R_OverReceiving != 'Y' && ($r_ExpectedQty_Each_ASN ?? false) && ($In_Process_Action != 2)){
  667. if ((($r_ReceivedQty_Each_ASN ?? 0) + $r_ReceivedQty_Each) > $r_ExpectedQty_Each_ASN)return '215';
  668. if (($r_PONO ?? false) && $r_PONO != '*' && ($r_POLineNO ?? false)){
  669. $TABLE_DOC_PO_DETAiLS = DB::connection('oracle')->select(DB::raw("SELECT OrderedQty_Each, ReceivedQty_Each From DOC_PO_DETAiLS where PONO='".$r_PONO."' AND POLineNo='".$r_POLineNO."'"));
  670. if ($TABLE_DOC_PO_DETAiLS){
  671. $r_OrderedQty_PO = $TABLE_DOC_PO_DETAiLS[0]->orderedqty_each;
  672. $r_ReceivedQty_Each_PO = $TABLE_DOC_PO_DETAiLS[0]->receivedqty_each;
  673. }
  674. if ((($r_ReceivedQty_Each_PO ?? 0) + $r_ReceivedQty_Each > ($r_OrderedQty_PO ?? 0)))return '215'.$In_CustomerID.",PONo=".$r_PONO;
  675. }
  676. }
  677. if ($R_OverReceiving == 'Y' && $r_OverRCVPercentage && ($r_ExpectedQty_Each_ASN ?? false) && $In_Process_Action != 2){//有百分比限制
  678. $r_OVR_RCV_BY = $this->GETSYS_configuration($IN_Warehouse, $In_CustomerID, $r_ASNType, 'OVR_RCV_BY','BOTH');
  679. if (in_array($r_OVR_RCV_BY,["ASN","BOTH"])){
  680. if (((($r_ReceivedQty_Each_ASN ?? 0) + $r_ReceivedQty_Each) / $r_ExpectedQty_Each_ASN) > (1+$r_OverRCVPercentage))return '215'.$In_CustomerID;
  681. }elseif (in_array($r_OVR_RCV_BY,["PO","BOTH"])){
  682. if (($r_PONO ?? false) && $r_PONO!='*' && ($r_POLineNO ?? false)){
  683. $TABLE_DOC_PO_DETAiLS = DB::connection('oracle')->select(DB::raw("Select OrderedQty_Each, ReceivedQty_Each From DOC_PO_DETAiLS where PONO=r_PONO AND POLineNo=r_POLineNo"));
  684. if ($TABLE_DOC_PO_DETAiLS){
  685. $r_OrderedQty_PO = $TABLE_DOC_PO_DETAiLS[0]->orderedqty_each;
  686. $r_ReceivedQty_Each_PO = $TABLE_DOC_PO_DETAiLS[0]->receivedqty_each;
  687. }
  688. if (((($r_ReceivedQty_Each_PO ?? 0) + $r_ReceivedQty_Each) / ($r_OrderedQty_PO ?? 0)) > (1+$r_OverRCVPercentage)) return '215'.$In_CustomerID.',PONo='.$r_PONO;
  689. }
  690. }
  691. }
  692. if ($In_ASNNo == '*') $r_DocType = '*';
  693. else $r_DocType = 'ASN';
  694. //RF收货产生新的ID [In_New_TraceID],自动打印上架标签
  695. if ($In_New_TraceID == '*' && ($R_PRT_PTA_LBL == 'Y' || $r_ASN_GEN_TID == 'Y')){
  696. if ($R_LoseID_Flag != 'Y'){
  697. // $OUT_Return_Code = $this->spcom_getidsequence(); //1331 此SP调用 恒定返回000 无意义调用
  698. $OUT_Return_Code = '000';
  699. }
  700. }
  701. //判断目标库位是否冻结 @LocationHold
  702. $TABLE_ACT_InventoryHold = DB::connection('oracle')->select(DB::raw("Select count(1) c From ACT_InventoryHold Where HoldBy='2' and HoldFlag='Y' and LocationID='".$In_TOLocation."'"));
  703. if ($TABLE_ACT_InventoryHold)$r_nrow = $TABLE_ACT_InventoryHold[0]->c;
  704. if ($r_nrow >= 1) $r_LocationHold = 'Y';
  705. $r_LogicalFMSequence = null;
  706. $r_LogicalToSequence = null;
  707. $TABLE_BAS_Location = DB::connection('oracle')->select(DB::raw("select LogicalSequence From BAS_Location Where LocationID= '".$In_PlanToLoc."'"));
  708. if (!$TABLE_BAS_Location) $r_LogicalToSequence = 0;
  709. else $r_LogicalToSequence = $TABLE_BAS_Location[0]->logicalsequence;
  710. $TABLE_BAS_Location = DB::connection('oracle')->select(DB::raw("select LogicalSequence From BAS_Location Where LocationID='".$In_TOLocation."'"));
  711. if (!$TABLE_BAS_Location) $r_LogicalFMSequence = 0;
  712. else $r_LogicalFMSequence = $TABLE_BAS_Location[0]->logicalsequence;
  713. $r_MaxPATaskID_Sequence = 0;
  714. $r_MaxQCTaskID_Sequence = 0;
  715. // <<Loop1>>
  716. //批号处理
  717. if ($In_Process_Action != '2'){
  718. $r_nrow = 1;
  719. $query = DB::raw("SELECT LotNum from INV_LOT_ATT where CustomerID='".$In_CustomerID."' and SKU=in_SKU".
  720. " and nvl(LotAtt01,'*')=nvl(rtrim('".$In_LotAtt01."'),'*') and nvl(LotAtt02,'*')=nvl(rtrim('".$In_LotAtt02."'),'*') and nvl(LotAtt03,'*')=nvl(rtrim('".$In_LotAtt03."'),'*')".
  721. " and nvl(LotAtt04,'*')=nvl(rtrim('".$In_LotAtt04."'),'*') and nvl(LotAtt05,'*')=nvl(rtrim('".$In_LotAtt05."'),'*') and nvl(LotAtt06,'*')=nvl(rtrim('".$In_LotAtt06."'),'*')".
  722. " and nvl(LotAtt07,'*')=nvl(rtrim('".$In_LotAtt07."'),'*') and nvl(LotAtt08,'*')=nvl(rtrim('".$In_LotAtt08."'),'*') and nvl(LotAtt09,'*')=nvl(rtrim('".$In_LotAtt09."'),'*')".
  723. " and nvl(LotAtt10,'*')=nvl(rtrim('".$In_LotAtt10."'),'*') and nvl(LotAtt11,'*')=nvl(rtrim('".$In_LotAtt11."'),'*') and nvl(LotAtt12,'*')=nvl(rtrim('".$In_LotAtt12."'),'*') and rownum=1");
  724. $data = DB::connection('oracle')->select($query);
  725. if (!$data) $r_nrow = 0;
  726. else $r_Return_LotNum = $data[0]->lotnum;
  727. //产生新的批号
  728. if($r_nrow <= 0){
  729. //SP: SPCOM_GetIDSequence(IN_Warehouse,IN_Language,'LOTNumber',r_Return_LotNum,OUT_Return_Code);
  730. $r_Return_LotNum = '0';
  731. $OUT_Return_Code = '000';
  732. //TODO CREATE INV_LOT_ATT
  733. DB::connection('oracle')->insert(DB::raw("INSERT INTO INV_LOT_ATT (CustomerID,SKU,LotNum,LotAtt01,LotAtt02,LotAtt03,LotAtt04,LotAtt05,LotAtt06,LotAtt07,LotAtt08,LotAtt09,LotAtt10,LotAtt11,LotAtt12,AddTime,AddWho,EditTime,EditWho,ReceivingTime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"),
  734. [$In_CustomerID,$In_SKU,$r_Return_LotNum,rtrim($In_LotAtt01),rtrim($In_LotAtt02),rtrim($In_LotAtt03),rtrim($In_LotAtt04),rtrim($In_LotAtt05),rtrim($In_LotAtt06)
  735. ,rtrim($In_LotAtt07),rtrim($In_LotAtt08),rtrim($In_LotAtt09),rtrim($In_LotAtt10),rtrim($In_LotAtt11),rtrim($In_LotAtt12)
  736. ,$R_CurrentTime->toDateTimeString(),$In_UserID,$R_CurrentTime->toDateTimeString(),$In_UserID,$R_CurrentTime->toDateTimeString()]);
  737. }
  738. //预约库存的数量处理
  739. $r_Lotnum_Trace = $r_Lotnum_Trace ?? '';
  740. $r_PlanToLoc_Trace = $r_PlanToLoc_Trace ?? '';
  741. $r_Return_LotNum = $r_Return_LotNum ?? '';
  742. if ($R_Reserve_Flag == 'Y' && $R_LocationUsage == 'ST' && ($r_Lotnum_Trace ?? '') != $r_Return_LotNum){ //有预约,并且是收到ST库位,批次发生变化
  743. //TODO UPDATE
  744. DB::connection('oracle')->update(DB::raw('UPDATE INV_LOT_LOC_ID SET QTYPA = QTYPA - ? WHERE lotnum = ? and LocationID = ? and traceid = ?'),
  745. [(int)($r_CancelQty_Trace ?? 0),$r_Lotnum_Trace,$r_PlanToLoc_Trace,$In_FMTraceID]);
  746. //TODO DELETE
  747. DB::connection('oracle')->delete(DB::raw('DELETE FROM INV_LOT_LOC_ID where lotnum = ? and LocationID = ? and traceid = ? and QTYPA = 0 and qty = 0 and qtyMvin = 0'),
  748. [$r_Lotnum_Trace,$r_PlanToLoc_Trace,$In_FMTraceID]);
  749. DB::connection('oracle')->select(DB::raw('Select * from INV_LOT_LOC_ID Where LotNum=? and LocationID=? and TraceID=? for update'),[
  750. $r_Return_LotNum, $r_PlanToLoc_Trace, $In_FMTraceID
  751. ]);
  752. $TABLE_inv_lot_loc_id = DB::connection('oracle')->select(DB::raw(' select count(*) c from inv_lot_loc_id where lotnum = ? and LocationID = ? and traceid = ?'),[
  753. $r_Return_LotNum,$r_PlanToLoc_Trace,$In_FMTraceID
  754. ]);
  755. if ($TABLE_inv_lot_loc_id[0]->c > 0){
  756. //TODO UPDATE
  757. DB::connection('oracle')->update(DB::raw('update inv_lot_loc_id set QTYPA = QTYPA + ? where lotnum = ? and LocationID = ? and traceid = ?'),[
  758. (int)$r_ReceivedQty_Each,$r_Return_LotNum,$r_PlanToLoc_Trace,$In_FMTraceID
  759. ]);
  760. }else{
  761. //TODO CREATE INV_LOT_LOC_ID
  762. DB::connection('oracle')->insert(DB::raw('Insert Into INV_LOT_LOC_ID (LotNum, LocationID, TraceID, CustomerID, SKU, Qty, QtyAllocated, QtyRPIn, QtyRPOut, QtyMVIN, QtyMVOut, QtyOnHold, OnHoldLocker,GrossWeight, NetWeight, Cubic, Price, AddTime, AddWho, EditTime, EditWho, LPN, QTYPA) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'),[
  763. $r_Return_LotNum,$r_PlanToLoc_Trace,$In_FMTraceID,$In_CustomerID,$In_SKU,0,0,0,0,0,
  764. 0,0,0,0,0,0,0,$R_CurrentTime->toDateTimeString(),$In_UserID,$R_CurrentTime->toDateTimeString(),
  765. $In_UserID,null,$r_ReceivedQty_Each
  766. ]);
  767. }
  768. }
  769. //混放批次校验
  770. if ($R_Mix_LotFlag == 'N' && $R_LocationUsage != 'ST'){
  771. $TABLE_inv_lot_LOC_ID = DB::connection('oracle')->selectOne(DB::raw('select count(distinct LotNUM) c from inv_lot_LOC_ID where LocationID=? and LotNum<>? and Qty>0 and CustomerID=? and SKU=?'),[
  772. $In_TOLocation,$r_Return_LotNum,$In_CustomerID,$In_SKU
  773. ]);
  774. if ($TABLE_inv_lot_LOC_ID->c >= 1){
  775. DB::rollBack();
  776. return '206'.rtrim($In_TOLocation);
  777. }
  778. }
  779. //货架生命周期,失效日期,自动冻结
  780. $r_Flag = '0';
  781. if (trim($In_LotAtt02)){
  782. if ((strtotime($In_LotAtt02) ? true : false)){
  783. $r_nrow = 1;
  784. $TABLE_BAS_SKU = DB::connection('oracle')->selectOne(DB::raw("SELECT c.OutboundLifeDays,c.InboundLifeDays from BAS_SKU c where c.CustomerID=? and c.SKU=? and c.ShelfLifeFlag='Y' and c.ShelfLifeType='E'"),[
  785. $In_CustomerID,$In_SKU
  786. ]);
  787. if (!$TABLE_BAS_SKU)$r_nrow=0;
  788. else {
  789. $r_OutboundLifeDays = $TABLE_BAS_SKU->outboundlifedays;
  790. $r_InboundLifeDays = $TABLE_BAS_SKU->inboundlifedays;
  791. }
  792. }
  793. if ($r_nrow > 0)$r_Flag = '1';
  794. else $r_Flag = '0';
  795. if ($r_nrow > 0 && (($r_OutboundLifeDays > 0 && (Carbon::parse($In_LotAtt02)->diffInDays($R_CurrentTime) <= $r_OutboundLifeDays)) ||
  796. ($r_InboundLifeDays > 0 && (Carbon::parse($In_LotAtt02)->diffInDays($R_CurrentTime) <= $r_InboundLifeDays)))){
  797. if ($r_EXP_CTL == 'Y')return '222'; //过期 拒收
  798. if ($r_EXP_CTL != 'N')$r_Hold_EP = 'Y';
  799. }
  800. }
  801. //货架生命周期,生产日期,自动冻结
  802. if ($In_LotAtt01 && !(strtotime($In_LotAtt01) ? true : false) && (!$r_Flag || $r_Flag = '0')){
  803. $r_nrow = 1;
  804. $TABLE_BAS_SKU = DB::connection('oracle')->selectOne(DB::raw('select c.OutboundLifeDays,c.InboundLifeDays from BAS_SKU c where c.CustomerID=? and c.SKU=? and c.ShelfLifeFlag=? and c.ShelfLifeType=?') ,[
  805. $In_CustomerID,$In_SKU,'Y','M'
  806. ]);
  807. if (!$TABLE_BAS_SKU)$r_nrow = 0;
  808. else {
  809. $r_OutboundLifeDays = $TABLE_BAS_SKU->outboundlifedays;
  810. $r_InboundLifeDays = $TABLE_BAS_SKU->inboundlifedays;
  811. }
  812. if ($r_nrow > 0 && (($r_OutboundLifeDays > 0 && ($R_CurrentTime->diffInDays(Carbon::parse($In_LotAtt01)) > $r_OutboundLifeDays)) ||
  813. ($r_InboundLifeDays > 0 && ($R_CurrentTime->diffInDays(Carbon::parse($In_LotAtt01)) > $r_InboundLifeDays)))){
  814. if ($r_EXP_CTL == 'Y')return '222'; //有效期受控 拒收
  815. if ($r_EXP_CTL != 'N') $r_Hold_EP ='Y';
  816. }
  817. }
  818. if (trim($In_ContainerID)){
  819. DB::connection('oracle')->update(DB::raw('Update DOC_ASN_SerialNo Set LotNum=?,edittime=?,editwho=? Where LocationID=? and TraceID=? and LotNum=?'),[
  820. $r_Return_LotNum,$R_CurrentTime,$In_UserID,$In_TOLocation,$In_New_TraceID,$In_ContainerID
  821. ]);
  822. }
  823. }
  824. //计算上架库位 1543-1716 INSERT UPDATE
  825. //QTYPA 写入INV_LOT_LOC_ID 1719-1752 INSERT UPDATE
  826. //更新库存MVOut数量 1754-1810 SP:SPASN_Putaway_Calculation INSERT DELETE
  827. //上架库位处理 QTYPA 写入INV_LOT_LOC_ID 1854-1918 UPDATE
  828. // 1920-1989 UPDATE
  829. //任务处理 1992-2105 INSERT
  830. //--指定上架任务时此表为空 TMP_Putaway_task
  831. //混托盘任务处理
  832. //拆分上架任务后,需要分别写入收货交易,不然取消收货会导致QTYPA负数错误 库存交易处理 2107-2294 INSERT
  833. //产生交易记录 INSERT
  834. //更新冻结数 SP:SPINV_Hold_Update
  835. //只有质检后才能上架
  836. //根据收货交易产生质检明细
  837. //获取数据精度
  838. //2298-2378 UPDATE INSERT SP
  839. //更新码盘明细 2403-2460 UPDATE
  840. //码盘收货
  841. //更新ASN明细和ASN Header 2462-2617 SP UPDATE
  842. //判断拒收是否超量r_RejectedQty_Each_ASN
  843. //拒收数量应该< 预期数量-已收数量-已拒数量-本次收货数量,否则报错“拒收数量超量错误”
  844. if ($In_ASNNo != '*'){
  845. $query = DB::raw('Select PackID,UOM,ExpectedQty,ExpectedQty_Each,RejectedQty,RejectedQty_Each,ReceivedQty,ReceivedQty_Each,POLineNO,PONO From DOC_ASN_Details Where ASNNO=? and ASNLineNO=? for update');
  846. $TABLE_DOC_ASN_Details = DB::connection('oracle')->selectOne($query,[$In_ASNNo,$In_ASNLineNo]);
  847. if (!$TABLE_DOC_ASN_Details) return '803'.$In_ASNNo;
  848. $r_PackID_ASN = $TABLE_DOC_ASN_Details->packid;
  849. $r_UOM_ASN = $TABLE_DOC_ASN_Details->uom;
  850. $r_ExpectedQty_ASN = $TABLE_DOC_ASN_Details->expectedqty;
  851. $r_ExpectedQty_Each_ASN = $TABLE_DOC_ASN_Details->expectedqty_each;
  852. $r_RejectedQty_ASN = $TABLE_DOC_ASN_Details->rejectedqty;
  853. $r_RejectedQty_Each_ASN = $TABLE_DOC_ASN_Details->rejectedqty_each;
  854. $r_ReceivedQty_ASN = $TABLE_DOC_ASN_Details->receivedqty;
  855. $r_ReceivedQty_Each_ASN = $TABLE_DOC_ASN_Details->receivedqty_each;
  856. $r_POLineNO = $TABLE_DOC_ASN_Details->polineno;
  857. $In_PONo = $TABLE_DOC_ASN_Details->pono;
  858. //拒收超量
  859. if ($R_OverReceiving != 'Y' && (int)$In_RejectedQty > ((int)$r_ExpectedQty_Each_ASN - (int)$r_RejectedQty_Each_ASN - (int)$r_ReceivedQty_Each_ASN - (int)$r_ReceivedQty_Each_ASN))return '220';
  860. $r_ReceivedQty_Each_ASN = $r_ReceivedQty_Each + $r_ReceivedQty_Each_ASN;
  861. switch ($r_UOM_ASN){
  862. case "EA":
  863. $r_UOMQty_ASN = $r_QTY1_P;
  864. break;
  865. case "IP":
  866. $r_UOMQty_ASN = $r_QTY2_P;
  867. break;
  868. case "CS":
  869. $r_UOMQty_ASN = $r_QTY3_P;
  870. break;
  871. case "PL":
  872. $r_UOMQty_ASN = $r_QTY4_P;
  873. break;
  874. case "OT":
  875. $r_UOMQty_ASN = $r_QTY5_P;
  876. break;
  877. default:
  878. $r_UOMQty_ASN = 0;
  879. break;
  880. }
  881. if ($r_UOMQty_ASN <= 0)return '103'.rtrim($r_PackID_ASN);
  882. if ($r_ReceivedQty_Each_ASN >= $r_ExpectedQty_Each_ASN)$r_LineStatus = '40';
  883. else $r_LineStatus = '30';
  884. if ($r_ASN_RCV_UPD == 'Y'){
  885. $query = DB::raw("Update DOC_ASN_Details Set LineStatus=? ,ReceivedQty= (ReceivedQty_Each+?)/ ?,ReceivedQty_Each=ReceivedQty_Each+?,ReceivedTime=? ,".
  886. "RejectedQty=(RejectedQty_Each + (?))/?,RejectedQty_Each=RejectedQty_Each + (?),Reserve_Flag='Y',HoldRejectCode=?,HoldRejectReason=?,EditTime=? , EditWho=?,".
  887. "LotAtt01=?,LotAtt02=?,LotAtt04=?,LotAtt05=?,LotAtt06=?,LotAtt07=?,LotAtt08=?,LotAtt09=?,LotAtt10=?,LotAtt11=?,LotAtt12=?,Operator= ? Where ASNNO=? and ASNLineNO=?");
  888. DB::connection('oracle')->update($query,[$r_LineStatus,(int)$r_ReceivedQty_Each,(int)$r_UOMQty_ASN,(int)$r_ReceivedQty_Each,$R_ReceivingTime->toDateTimeString(),
  889. (int)$In_RejectedQty,(int)$r_UOMQty_ASN,(int)$In_RejectedQty,$In_HoldRejectCode,
  890. $In_HoldRejectReason,$R_CurrentTime->toDateTimeString(),$In_UserID,
  891. $In_LotAtt01,$In_LotAtt02,$In_LotAtt04,$In_LotAtt05,$In_LotAtt06,$In_LotAtt07,$In_LotAtt08,$In_LotAtt09,$In_LotAtt10,$In_LotAtt11,$In_LotAtt12,$In_Operator,$In_ASNNo,$In_ASNLineNo]);
  892. }else{
  893. $query = DB::raw('Update DOC_ASN_Details Set LineStatus=? ,ReceivedQty= (ReceivedQty_Each+?)/ ?,ReceivedQty_Each=ReceivedQty_Each+?'.
  894. ",ReceivedTime=?,RejectedQty=(RejectedQty_Each + (? ))/?,RejectedQty_Each=RejectedQty_Each + (?),Reserve_Flag='Y',HoldRejectCode=?".
  895. ",HoldRejectReason=?,EditTime=? , EditWho=?,Operator= ? Where ASNNO=? and ASNLineNO=?");
  896. DB::connection('oracle')->update($query,[$r_LineStatus,(int)$r_ReceivedQty_Each,(int)$r_UOMQty_ASN,(int)$r_ReceivedQty_Each,
  897. $R_ReceivingTime->toDateTimeString(),(int)$In_RejectedQty,(int)$r_UOMQty_ASN,(int)$In_RejectedQty,$In_HoldRejectCode,
  898. $In_HoldRejectReason,$R_CurrentTime->toDateTimeString(),$In_UserID,$In_Operator,$In_ASNNo,$In_ASNLineNo]);
  899. }
  900. if ($r_LineStatus == '40'){
  901. $count = DB::connection('oracle')->selectOne(DB::raw("Select Count(1) c from DOC_ASN_Details Where ASNNO=? and ASNLineNO<>? and LineStatus < '40'"),[$In_ASNNo,$In_ASNLineNo]);
  902. $r_nrow = $count->c;
  903. if ($r_nrow > 0) $r_LineStatus = '30';
  904. }
  905. $query = DB::raw("Update DOC_ASN_Header Set ASNStatus=?,Reserve_Flag='Y',LastReceivingTime=?,EditTime=? , EditWho=? Where ASNNO=?");
  906. DB::connection('oracle')->update($query,[$r_LineStatus,$R_ReceivingTime->toDateTimeString(),$R_CurrentTime->toDateTimeString(),$In_UserID, $In_ASNNo]);
  907. if ($r_RCV_CTL == 'Y' && $r_LineStatus == '40'){
  908. $r_nrow = 0;
  909. if ($r_PTA_CLS_CHK == 'Y'){
  910. $count = DB::connection('oracle')->selectOne(DB::raw("select count(1) c from TSK_Tasklists Where DocNo=? and TaskProcess='00' And DocType='ASN'"),[$In_ASNNo]);
  911. $r_nrow = $count->c;
  912. }
  913. if ($r_nrow == 0){
  914. $r_LineStatus = '99';
  915. //断点回滚,关闭ASN如果失败回滚该次操作而不是将上方全部操作回滚
  916. DB::transaction(function (){
  917. //2595-2614 关闭ASN 调用SP SPASN_Close_Process 该SP抛错时不影响全局回滚
  918. });
  919. }
  920. }
  921. }
  922. //更新PO信息 2620-2697 UPDATE
  923. //删除TMP_Putaway_Task(上架任务临时表) 2808 DELETE
  924. //DB::connection('oracle')->delete(DB::raw('delete from TMP_Putaway_Task where TMPID=?'),[$r_TMPID]);
  925. //修改UDF_A的调用方式 SP 2812-2828
  926. //清除0库存 2831-2834 SP
  927. //结束返回与异常判断
  928. return $OUT_Return_Code;
  929. }
  930. /** 对于快速入库 $IN_Parameter1 = 'RCV_AFTER' | 'RCV_BEFORE'
  931. * 目前该SP只存在 RCV_AFTER(校验近期产品) 且已被注释
  932. */
  933. private function SPUDF_ProcessA($IN_Warehouse, $IN_Parameter1, $IN_Parameter2, $IN_Parameter3, $IN_Parameter4, $IN_Language, $IN_UserID, $OUT_Return_Code){
  934. $r_CurrentTime = Carbon::now();
  935. //TODO 状态为 分配之前 走此逻辑,本快速入库不存在分配之前 不会走此逻辑 保留一下
  936. if ($IN_Parameter1='ALLOCATION_BEFORE'){
  937. $doc_order_header = DB::connection('oracle')->select(DB::raw("SELECT t.Carrierid,t.soreference5 FROM DOC_ORDER_HEADER t WHERE ORDERNO='".$IN_Parameter2."'"));
  938. $r_Carrierid = $doc_order_header[0]->carrierid;
  939. $r_soreference5 = $doc_order_header[0]->soreference5;
  940. if (in_array($r_Carrierid,['ZTO','YUNDA','POSTB','YTO','STO','EMS','SF']) && !$r_soreference5){
  941. $OUT_Return_Code = '999面单号未获取!';
  942. DB::rollBack();
  943. return $OUT_Return_Code;
  944. }
  945. }
  946. //TODO 状态为 导入后的逻辑:SPUDF_ProcessA 77行起 此处忽略 IN_Parameter1='SO_IMPORT_AFTER'
  947. //TODO 装箱完成前,做一些数据处理:SPUDF_ProcessA 125行起 此处忽略 IN_Parameter1='PACKING_BEFORE'
  948. //TODO 装箱完成后,做一些数据处理:SPUDF_ProcessA 132行起 此处忽略 IN_Parameter1='PACKING_AFTER'
  949. //TODO 打印标记:SPUDF_ProcessA 281行起 此处忽略 IN_Parameter1='PRINT'
  950. //TODO 发货前校验是否全部复核:SPUDF_ProcessA 553行起 此处忽略 IN_Parameter1='SHIP_BEFORE'
  951. //TODO 转移时校验库位是否允许混放批次:SPUDF_ProcessA 594行起 此处忽略 IN_Parameter1='TRAPPROVE_BEFORE'
  952. //TODO 分配之后,如果是单品单件订单,更新deliveryno:SPUDF_ProcessA 658行起 此处忽略 IN_Parameter1='ALLOCATION_AFTER'
  953. //TODO 上架前,校验此货主是否必须有拣货位,如果无拣货位,则拦截 by mxl 20191205:SPUDF_ProcessA 675行起 此处忽略 IN_Parameter1='PA_BEFORE'
  954. //TODO ASN关闭后 针对JIANSHANG货主,订单关闭后将数据写入临时表CUS_ADJ_H by mxl 20191217:SPUDF_ProcessA 700行起 此处忽略 IN_Parameter1='ASNCLOSE_AFTER'
  955. //TODO SO关闭后 针对JIANSHANG货主,订单关闭后将数据写入临时表CUS_ADJ_H by mxl 20191217:SPUDF_ProcessA 734行起 此处忽略 IN_Parameter1='SHIP_AFTER'
  956. $OUT_Return_Code = '000';
  957. return $OUT_Return_Code;
  958. }
  959. private function GETSYS_configuration($IN_WarehouseID, $IN_CustomerID, $IN_OrderType, $IN_ConfigID, $IN_DefaultValue = 'N', $IN_ValueType = 'C')
  960. {
  961. if ($IN_ValueType == 'C'){
  962. $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."'"));
  963. if (!$sys_configuration){
  964. $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."'"));
  965. if (!$sys_configuration){
  966. $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."'"));
  967. if (!$sys_configuration){
  968. $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."'"));
  969. if (!$sys_configuration) return $IN_DefaultValue;
  970. }
  971. }
  972. }
  973. return trim($sys_configuration[0]->value_string);
  974. }
  975. $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."'"));
  976. if (!$sys_configuration){
  977. $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."'"));
  978. if (!$sys_configuration){
  979. $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."'"));
  980. if (!$sys_configuration){
  981. $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."'"));
  982. if (!$sys_configuration) return $IN_DefaultValue;
  983. }
  984. }
  985. }
  986. return trim($sys_configuration[0]->value_string);
  987. }
  988. /** 码盘调用SP,大概率不会被使用,内部 为游标,UPDATE操作 */
  989. private function spasn_reserve_cancel($in_warehouse, $in_by, $in_asnno, $in_asnlineno, $in_traceid, $in_language, $in_userid, $out_return_code){
  990. $query = DB::raw('Select TraceID,ASNLineNO,CustomerID,SKU,PackID,UOM,LotNUM,PlanToLoc,ExpectedQty,ExpectedQty_Each,TotalGrossWeight,TotalCubic from DOC_Trace_DETAILS '.
  991. "Where (ASNNO='".$in_asnno."' and ReceivedQty_Each=0 and trim(PlanToLoc) is not null and trim(PlanToLoc)<>'*' and Reserve_Flag='Y' and '".$in_by."'='ASNNO') OR".
  992. " (ASNNO='".$in_asnno."' and ASNLineNO='".$in_asnlineno."' and ReceivedQty_Each=0 and trim(PlanToLoc) is not null and trim(PlanToLoc)<>'*' and Reserve_Flag='Y' and upper('".$in_by."')=upper('ASNLineNO')) OR".
  993. " (ASNNO='".$in_asnno."' and TraceID='".$in_traceid."' and ASNLineNO='".$in_asnlineno."' and ReceivedQty_Each=0 and trim(PlanToLoc) is not null and trim(PlanToLoc)<>'*' and Reserve_Flag='Y' and upper('".$in_by."')=upper('TraceID'))");
  994. if ($out_return_code == 'NO_COMMIT')$r_no_commit = 'N';
  995. else $r_no_commit = 'Y';
  996. $sp_sql_r = "''".$in_by."'',''".$in_asnno."'',''".$in_asnlineno."'',''".$in_traceid."'',''".$in_language."'',''".$in_userid."''";
  997. $R_CurrentTime = Carbon::now();
  998. if ($in_by != 'ASNNO' && strtoupper($in_by) != 'ASNLINENO' && strtoupper($in_by) != 'TRACEID')return '887SPASN_Reserve_Cancel';
  999. $ccur_asns = DB::connection('oracle')->select($query);
  1000. foreach ($ccur_asns as $crow_asn){
  1001. $sp_sql_r = 'Fetch cCur_ASN';
  1002. $TABLE_DOC_Trace_Details = DB::connection('oracle')->select(DB::raw("SELECT 1 c from DOC_Trace_Details Where ASNNO='".$in_asnno."' and TraceID='".$crow_asn->traceid."'"));
  1003. if ($TABLE_DOC_Trace_Details && $TABLE_DOC_Trace_Details[0]->c == 1){
  1004. // TODO UPDATE
  1005. $rowcount = DB::connection('oracle')->update(DB::raw("UPDATE INV_LOT_LOC_ID SET QTYPA=(QTYPA-".$crow_asn->expectedqty_each."),EditTime=TO_DATE('".$R_CurrentTime->toDateTimeString()."','yyyy-mm-dd hh24:mi:ss'),EditWho='".$in_userid.
  1006. "' WHERE LotNum='".$crow_asn->lotnum."' and LocationID='".$crow_asn->plantoloc."' and TraceID='".$crow_asn->traceid."'"));
  1007. if ($rowcount == 0) return 'INV_LOT_LOC_ID,UPDATE';
  1008. // TODO UPDATE
  1009. DB::connection('oracle')->update(DB::raw("UPDATE DOC_Trace_Details set PlanToLoc='' ,Reserve_Flag='N',EditTime= TO_DATE('".$R_CurrentTime->toDateTimeString()."','yyyy-mm-dd hh24:mi:ss'), EditWho='".$in_userid.
  1010. "' where ASNNO='".$in_asnno."' and ASNLineNO='".$crow_asn->asnlineno."' and TraceID='".$crow_asn->traceid."'"));
  1011. $TABLE_DOC_Trace_Details = DB::connection('oracle')->select(DB::raw("SELECT 1 FROM DOC_Trace_Details WHERE ASNNO='".$in_asnno."' and ASNLineNO='".$crow_asn->asnlineno."' and trim(PlanToLoc) is not null and trim(PlanToLoc)<>'*'"));
  1012. if (!$TABLE_DOC_Trace_Details){
  1013. //TODO UPDATE
  1014. DB::connection('oracle')->update(DB::raw("Update DOC_ASN_Details set Reserve_Flag='N' ,EditTime=TO_DATE('".$R_CurrentTime->toDateTimeString()."','yyyy-mm-dd hh24:mi:ss') , EditWho='".$in_userid."' where ASNNO='".$in_asnno."' and ASNLineNO='".$crow_asn->asnlineno."'"));
  1015. }
  1016. }
  1017. //TODO COMMIT
  1018. if ($r_no_commit == 'Y')DB::commit();
  1019. }
  1020. $TABLE_DOC_ASN_Details = DB::connection('oracle')->select(DB::raw("SELECT 1 FROM DOC_ASN_Details Where ASNNO='".$in_asnno."' and Reserve_Flag='Y'"));
  1021. if (!$TABLE_DOC_ASN_Details){
  1022. $sp_sql_r = 'Update DOC_ASN_Header';
  1023. //TODO UPDATE
  1024. DB::connection('oracle')->update(DB::raw("Update DOC_ASN_Header set Reserve_Flag='N' ,EditTime=TO_DATE('".$R_CurrentTime->toDateTimeString()."','yyyy-mm-dd hh24:mi:ss') , EditWho='".$in_userid."' where ASNNO='".$in_asnno."'"));
  1025. }
  1026. //TODO COMMIT
  1027. if ($r_no_commit == 'Y')DB::commit();
  1028. return '000';
  1029. }
  1030. //获取数据表的ID(PO, ASN, SO...) $in_sequence_name_c = TraceID LOTNumber TEMPID Traceid TransactionID TaskID QCNO TransactionID
  1031. private function spcom_getidsequence($in_warehouse, $in_language, $in_sequence_name_c, $out_returnno, $out_return_code){
  1032. $out_return_code = '000';
  1033. $out_returnno = '0';
  1034. $in_sequence_name = $in_sequence_name_c;
  1035. $r_id_sequence = -1;
  1036. $r_length = 0;
  1037. //TODO $IN_Parameter1 = 'IDSEQUENCE' 单多包裹逻辑校验 应该调用SPUDF_ProcessA 但其中单多部分逻辑已被注释 恒定返回000 此处同理恒定返回000 不会下行执行其他逻辑
  1038. return;
  1039. //DB::connection('oracle')->select(DB::raw("Select ID_Sequence,Max_ID_Sequence,Length,PreFix,to_CHar(EditTime,'YYMMDD') ,Date_Format ,Date_max From SYS_IDSequence where IDName=upper('".$IN_Sequence_Name."') and WareHouseID = upper('".$in_warehouse."') For Update;"));
  1040. //return [$out_returnno,$out_return_code];
  1041. }
  1042. }