Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MocaResults res = moca.newResults();
- MocaResults resLines = moca.newResults();
- String cmd = "";
- String unexpectedStatusClause = "";
- String newRcvKey = "";
- /* Check first if receiving an unexpected status is on... */
- if (allowUnexpectedStatus == 1 && foundLines == 0)
- {
- moca.trace("Trying to create a line for unexpected inventory status...");
- try
- {
- /* Did part existed in the receipt?
- * Then select all the rcvlin attributtes
- * and copy them over to the new rcvlin. */
- cmd = " [select client_id, " +
- " supnum, " +
- " invnum, " +
- " invlin, " +
- " invsln, " +
- " seqnum, " +
- " retcod, " +
- " orgcod, " +
- " revlvl, " +
- " lotnum, " +
- " to_char(mandte, 'YYYYMMDDHH24MISS') mandte " +
- " from rcvlin " +
- " where trknum = @trknum " +
- " and wh_id = @wh_id " +
- " and prtnum = @prtnum " +
- " and blind_flg = 0 " +
- " and @+client_id " +
- " and @+invnum " +
- " and @+supnum " +
- " and @+lotnum " +
- " and @+orgcod " +
- " and @+revlvl " +
- " order by seqnum desc] >> res " +
- " | " +
- " publish top rows where res = @res and rows = 1 ";
- res = moca.executeInline(cmd);
- res.next();
- if (res.client_id == null || res.supnum == null ||
- res.invnum == null || res.invlin == null ||
- res.invsln == null || res.seqnum == null)
- {
- throw new NotFoundException();
- }
- /* Check if manufacturing date is null */
- if (res.mandte == null)
- {
- mandte = "";
- }
- else
- {
- mandte = res.mandte;
- }
- /* Create a duplicate line for the unexpected status inventory */
- cmd = " create receive invoice line " +
- " where trknum = '" + trknum + "'" +
- " and wh_id = '" + wh_id + "'" +
- " and prtnum = '" + prtnum + "'" +
- " and rcvsts = '" + invsts + "'" +
- " and client_id = '" + res.client_id + "'" +
- " and supnum = '" + res.supnum + "'" +
- " and invnum = '" + res.invnum + "'" +
- " and invlin = '" + res.invlin + "'" +
- " and invsln = '" + res.invsln + "'" +
- " and seqnum = " + (res.seqnum + 1) +
- " and orgcod = '" + res.orgcod + "'" +
- " and revlvl = '" + res.revlvl + "'" +
- " and lotnum = '" + res.lotnum + "'" +
- " and mandte = '" + mandte + "'" +
- " and expqty = 0 " +
- " and exp_catch_qty = 0 ";
- if (isReturnInvoice == 1)
- {
- cmd = cmd +
- " and retcod = '" + res.retCod + "'";
- }
- /* Note: Run on its own context, to avoid passing
- * the rcvkey from the list inventory */
- res = moca.executeCommand(cmd);
- res.next();
- newRcvKey = res.rcvkey;
- foundLines = 1;
- moca.trace(" Success: Receive line was created for the inventory.");
- }
- catch(NotFoundException e)
- {
- moca.trace(" Error: Non of the Expected Receive Lines contains this part.");
- }
- }
- /* Try creating an unexpected attribute receive line if still is required... */
- if (allowUnexpectedAttribute == 1 && foundLines == 0)
- {
- moca.trace("Trying to create a line for receiving...");
- try
- {
- if (allowUnexpectedStatus != 1)
- {
- unexpectedStatusClause = " and rcvsts = @invsts ";
- }
- /* Did part existed in the receipt?
- * Then select all the rcvlin attributtes
- * and copy them over to the new rcvlin. */
- cmd = " [select client_id, " +
- " supnum, " +
- " invnum, " +
- " invlin, " +
- " invsln, " +
- " seqnum, " +
- " retcod, " +
- " orgcod, " +
- " revlvl, " +
- " lotnum, " +
- " to_char(mandte, 'YYYYMMDDHH24MISS') mandte " +
- " from rcvlin " +
- " where trknum = @trknum " +
- " and wh_id = @wh_id " +
- " and prtnum = @prtnum " +
- " and blind_flg = 0 " +
- " and @+client_id " +
- " and @+invnum " +
- " and @+supnum " +
- " and (lotnum = @lotnum or lotnum = '----') " +
- " and (orgcod = @orgcod or orgcod = '----') " +
- " and (revlvl = @revlvl or revlvl = '----') " + unexpectedStatusClause +
- " and rownum < 2 " +
- " order by seqnum desc] >> res " +
- " | " +
- " publish top rows where res = @res and rows = 1 ";
- res = moca.executeInline(cmd);
- res.next();
- if (res.client_id == null || res.supnum == null ||
- res.invnum == null || res.invlin == null ||
- res.invsln == null || res.seqnum == null)
- {
- throw new NotFoundException();
- }
- /* Check if manufacturing date is null */
- if (res.mandte == null)
- {
- mandte = "";
- }
- else
- {
- mandte = res.mandte;
- }
- /* Create a duplicate line for the unexpected attribute inventory */
- cmd = " create receive invoice line " +
- " where trknum = '" + trknum + "'" +
- " and wh_id = '" + wh_id + "'" +
- " and prtnum = '" + prtnum + "'" +
- " and rcvsts = '" + invsts + "'" +
- " and client_id = '" + res.client_id + "'" +
- " and supnum = '" + res.supnum + "'" +
- " and invnum = '" + res.invnum + "'" +
- " and invlin = '" + res.invlin + "'" +
- " and invsln = '" + res.invsln + "'" +
- " and seqnum = '" + max_seq + "'" +
- " and orgcod = '" + input_orgcod + "'" +
- " and revlvl = '" + input_revlvl + "'" +
- " and lotnum = '" + input_lotnum + "'" +
- " and mandte = '" + mandte + "'" +
- " and blind_flg = 1 " +
- " and expqty = 0 " +
- " and exp_catch_qty = 0 ";
- if (isReturnInvoice == 1)
- {
- cmd = cmd +
- " and retcod = '" + res.retCod + "'";
- }
- /* Note: Run on its own context, to avoid passing
- * the rcvkey from the list inventory */
- res = moca.executeCommand(cmd);
- res.next();
- newRcvKey = res.rcvkey;
- foundLines = 1;
- moca.trace(" Success: Receive line was created for the inventory.");
- }
- catch(NotFoundException e)
- {
- moca.trace(" Error: Non of the Expected Receive Lines contains this part.");
- }
- }
- /* Try creating a blind receive line if still is required... */
- if (allowUnexpectedPart == 1 && foundLines == 0)
- {
- moca.trace("Trying to create a line for blind receiving...");
- try
- {
- /* Get the invoice information to create a blind line */
- cmd = " [select * " +
- " from rcvinv " +
- " where trknum = @trknum " +
- " and invnum = @invnum " +
- " and wh_id = @wh_id " +
- " and @+client_id " +
- " and @+supnum] ";
- res = moca.executeInline(cmd);
- res.next();
- /* Create the blind line for receiving this inventory */
- cmd = " create blind receive invoice line " +
- " where trknum = '" + trknum + "'" +
- " and invnum = '" + invnum + "'" +
- " and wh_id = '" + wh_id + "'" +
- " and dtlnum = '" + dtlnum + "'" +
- " and client_id = '" + res.client_id + "'" +
- " and supnum = '" + res.supnum + "'";
- /* Note: Run on its own context, to avoid passing
- * the rcvkey from the list inventory */
- res = moca.executeCommand(cmd);
- res.next();
- newRcvKey = res.rcvkey;
- foundLines = 1;
- moca.trace(" Success: Blind Receive line was created for the inventory.");
- }
- catch(NotFoundException e)
- {
- moca.trace(" Error: Invoice was not found, don't know where to create blind line against.");
- }
- }
- /* By this time if a line was found, is because it got created... */
- if (foundLines == 1 && newRcvKey != "")
- {
- /* Find the created matching lines which will be returned */
- cmd = " [select * " +
- " from rcvlin " +
- " where rcvkey = '" + newRcvKey + "']";
- resLines = moca.executeInline(cmd);
- }
- /* publish the result set out */
- resLines
Add Comment
Please, Sign In to add comment