Ejemplo n.º 1
0
        string modifyProject(SOOrder sOOrder)
        {
            int?customerSalesAcctId;
            int?customerSalesSubId;
            int?cogsAcctId;
            int?cogsSubId;
            int?invtAcctId;
            int?invtSubId;
            int?cARAccountID;

            string cogsAcctCd      = "";
            string cogsSubCd       = "";
            string invtAcctCd      = "";
            string invtSubCd       = "";
            string custSalesAcctCD = "";
            string custSalesSubCD  = "";
            string cARAccountCD    = string.Empty;
            string custCD          = "";
            string transID         = "";

            string result = "";

            try
            {
                ClientConversation.authenticate(userName, password);
                TransactionService transactionService = new TransactionService()
                {
                    Timeout = sessionTimeout,
                    Url     = $"{urlPrefix(dbName)}TransactionService"
                };
                PLNSC.TransactionRef.OperationContext transContext = new PLNSC.TransactionRef.OperationContext()
                {
                    district     = districtCode,
                    position     = positionID,
                    maxInstances = maxInstance
                };

                transID = transactionService.begin(transContext);

                BAccount2 customer = PXSelect <BAccount2,
                                               Where <BAccount2.bAccountID, Equal <Required <BAccount2.bAccountID> >,
                                                      And <BAccount2.defLocationID, Equal <Required <BAccount2.defLocationID> >,
                                                           And <BAccount.type, Equal <Required <BAccount.type> > > > > > .Select(Base, sOOrder.CustomerID, sOOrder.CustomerLocationID, "CU");

                Location custLocation = PXSelect <Location,
                                                  Where <Location.bAccountID, Equal <Required <Location.bAccountID> >,
                                                         And <Location.locationID, Equal <Required <Location.locationID> > > > > .Select(Base, sOOrder.CustomerID, sOOrder.CustomerLocationID);

                customerSalesAcctId = custLocation.CSalesAcctID;
                customerSalesSubId  = custLocation.CSalesSubID;
                cARAccountID        = custLocation.CARAccountID;

                Account custSalesAccount = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(Base, customerSalesAcctId);

                Account custARAccount = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(Base, cARAccountID);

                Sub custSalesSub = PXSelect <Sub, Where <Sub.subID, Equal <Required <Sub.subID> > > > .Select(Base, customerSalesSubId);

                custSalesAcctCD = custSalesAccount.AccountCD;
                custSalesSubCD  = custSalesSub.SubCD;
                cARAccountCD    = custARAccount.AccountCD;
                custCD          = customer.AcctCD.Trim();

                foreach (SOLine soLine in Base.Transactions.Select(sOOrder.OrderNbr))
                {
                    InventoryItem inventoryItem = PXSelect <InventoryItem,
                                                            Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, soLine.InventoryID);

                    cogsAcctId = inventoryItem.COGSAcctID;
                    cogsSubId  = inventoryItem.COGSSubID;
                    invtAcctId = inventoryItem.InvtAcctID;
                    invtSubId  = inventoryItem.InvtSubID;

                    if (cogsAcctId == null && cogsSubId == null)
                    {
                        throw new PXException(CustomMessage.COGSAccountEmpty);
                    }

                    Account itemInvtAcct = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(Base, invtAcctId);

                    Sub itemInvtSub = PXSelect <Sub, Where <Sub.subID, Equal <Required <Sub.subID> > > > .Select(Base, invtSubId);

                    Account invtCogsAccount = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(Base, cogsAcctId);

                    Sub invtCogsSub = PXSelect <Sub, Where <Sub.subID, Equal <Required <Sub.subID> > > > .Select(Base, cogsSubId);

                    cogsAcctCd = invtCogsAccount.AccountCD;
                    cogsSubCd  = invtCogsSub.SubCD;
                    invtAcctCd = itemInvtAcct.AccountCD;
                    invtSubCd  = itemInvtSub.SubCD;

                    if (cogsAcctId != null && cogsSubId != null)
                    {
                        break;
                    }
                }

                EPEmployee ePEmployee = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(Base, sOOrder.OwnerID);

                string   originatorId         = ePEmployee != null ? ePEmployee.AcctCD : "ADMIN";
                string   stockItemAccount     = custSalesSubCD.Substring(0, 11).Trim() + cogsSubCd.Substring(11, 4).Trim(); // + cogsAcctCd.Trim();
                string   nonStockItemAccount  = cogsSubCd.Trim();                                                           // + cogsAcctCd.Trim();
                string   itemInventoryAccount = invtSubCd.Trim() + invtAcctCd.Trim();
                DateTime actStartDate         = sOOrder.OrderDate ?? DateTime.Now;
                string   raisedDate           = actStartDate.ToString("yyyyMMdd");
                string   planFinishDate       = (sOOrder.RequestDate ?? actStartDate.AddDays(60)).ToString("yyyyMMdd");

                try
                {
                    //ClientConversation.authenticate(userName, password);
                    PLNSC.ProjectService.OperationContext projectOperationContext = new PLNSC.ProjectService.OperationContext()
                    {
                        district     = districtCode,
                        position     = positionID,
                        maxInstances = maxInstance,
                        transaction  = transID
                    };

                    ProjectService projectService = new ProjectService()
                    {
                        Timeout = sessionTimeout,
                        Url     = $"{urlPrefix(dbName)}ProjectService"
                    };

                    ProjectServiceModifyRequestDTO projectRequest = new ProjectServiceModifyRequestDTO()
                    {
                        districtCode       = "SC01",
                        projectNo          = sOOrder.OrderNbr,
                        projDesc           = sOOrder.OrderDesc,
                        originatorId       = originatorId,
                        raisedDate         = raisedDate,
                        planFinDate        = planFinishDate,
                        accountCode        = cARAccountCD,
                        accountCodeEnabled = true
                    };

                    ProjectServiceModifyReplyDTO             projectReply       = projectService.modify(projectOperationContext, projectRequest);
                    PLNSC.ProjectService.WarningMessageDTO[] warningMessageDTOs = projectReply.warningsAndInformation;

                    if (warningMessageDTOs.Length > 0)
                    {
                        result = warningMessageDTOs[0].message;
                        transContext.transaction = transID;
                        transactionService.rollback(transContext);
                    }
                    else
                    {
                        result = "OK";
                        transContext.transaction = transID;
                        transactionService.commit(transContext);
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                    transContext.transaction = transID;
                    transactionService.rollback(transContext);
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 2
0
        string modifyProjectRefCodes(SOOrder sOOrder)
        {
            string transID = "";
            string result  = "";

            try
            {
                ClientConversation.authenticate(userName, password);
                TransactionService transactionService = new TransactionService()
                {
                    Timeout = sessionTimeout,
                    Url     = $"{urlPrefix(dbName)}TransactionService"
                };
                PLNSC.TransactionRef.OperationContext transContext = new PLNSC.TransactionRef.OperationContext()
                {
                    district     = districtCode,
                    position     = positionID,
                    maxInstances = maxInstance
                };

                transID = transactionService.begin(transContext);

                BAccount2 customer = PXSelect <BAccount2,
                                               Where <BAccount2.bAccountID, Equal <Required <BAccount2.bAccountID> >,
                                                      And <BAccount2.defLocationID, Equal <Required <BAccount2.defLocationID> >,
                                                           And <BAccount.type, Equal <Required <BAccount.type> > > > > > .Select(Base, sOOrder.CustomerID, sOOrder.CustomerLocationID, "CU");

                string custCD = customer.AcctCD.Trim();

                PLNSC.RefCodesRef.OperationContext refCodesOperation = new PLNSC.RefCodesRef.OperationContext()
                {
                    district     = transContext.district,
                    position     = transContext.position,
                    maxInstances = transContext.maxInstances
                };

                RefCodesService refCodesService = new RefCodesService()
                {
                    Timeout = transactionService.Timeout,
                    Url     = $"{urlPrefix(dbName)}RefCodesService"
                };

                RefCodesServiceModifyRequestDTO refCodesServiceModifyRequestDTO = new RefCodesServiceModifyRequestDTO()
                {
                    entityType  = "PRJ",
                    entityValue = transContext.district.Trim() + sOOrder.OrderNbr.Trim(),
                    refNo       = "001",
                    seqNum      = "001",
                    refCode     = sOOrder.CustomerOrderNbr.Trim()
                };

                RefCodesServiceModifyReplyDTO         refCodesServiceModifyReplyDTO = refCodesService.modify(refCodesOperation, refCodesServiceModifyRequestDTO);
                PLNSC.RefCodesRef.WarningMessageDTO[] refCodesErrors = refCodesServiceModifyReplyDTO.warningsAndInformation;
                if (refCodesErrors.Length > 0)
                {
                    result = refCodesErrors[0].message;
                    transactionService.rollback(transContext);
                }
                else
                {
                    if (sOOrder.CustomerID != null)
                    {
                        RefCodesServiceModifyRequestDTO refCodesServiceModifyRequestDTO2 = new RefCodesServiceModifyRequestDTO()
                        {
                            entityType  = "PRJ",
                            entityValue = transContext.district.Trim() + sOOrder.OrderNbr.Trim(),
                            refNo       = "002",
                            seqNum      = "001",
                            refCode     = custCD
                        };

                        RefCodesServiceModifyReplyDTO         refCodesServiceModifyReplyDTO2 = refCodesService.modify(refCodesOperation, refCodesServiceModifyRequestDTO2);
                        PLNSC.RefCodesRef.WarningMessageDTO[] refCodesErrors2 = refCodesServiceModifyReplyDTO2.warningsAndInformation;
                        if (refCodesErrors2.Length > 0)
                        {
                            result = refCodesErrors2[0].message;
                            transContext.transaction = transID;
                            transactionService.rollback(transContext);
                        }
                        else
                        {
                            result = "OK";
                            transContext.transaction = transID;
                            transactionService.commit(transContext);
                        }
                    }
                    else
                    {
                        result = "OK";
                        transContext.transaction = transID;
                        transactionService.commit(transContext);
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            return(result);
        }