public static void Process(List <PMProforma> list, bool isMassProcess)
        {
            Stopwatch     sw = new Stopwatch();
            ProformaEntry rg = PXGraph.CreateInstance <ProformaEntry>();

            rg.SuppressRowSeleted = true;
            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    rg.Document.Current = PXSelect <PMProforma, Where <PMProforma.refNbr, Equal <Required <PMProforma.refNbr> > > > .Select(rg, list[i].RefNbr);

                    rg.CalculateAvalaraTax(rg.Document.Current);
                    PXProcessing <PMProforma> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <PMProforma> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }
        }
//		public static void Process(POReceipt doc)
//		{
//			List<POReceipt> list = new List<POReceipt>();
//
//			list.Add(doc);
//			Process(list, false);
//		}

        public static void Process(List <POOrder> list, bool isMassProcess)
        {
            POOrderEntry rg = PXGraph.CreateInstance <POOrderEntry>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    rg.Clear();
                    rg.Document.Current = PXSelect <POOrder, Where <POOrder.orderType, Equal <Required <POOrder.orderType> >, And <POOrder.orderNbr, Equal <Required <POOrder.orderNbr> > > > > .Select(rg, list[i].OrderType, list[i].OrderNbr);

                    rg.CalculateExternalTax(rg.Document.Current);
                    PXProcessing <POOrder> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <POOrder> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }
        }
Esempio n. 3
0
 public DeleteDocsProcess()
 {
     Docs.SetProcessCaption(Messages.DeleteProc);
     Docs.SetProcessAllCaption(Messages.DeleteAllProc);
     Docs.SetProcessDelegate(delegate(List <FARegister> list)
     {
         bool failed = false;
         TransactionEntry entryGraph = CreateInstance <TransactionEntry>();
         foreach (FARegister register in list)
         {
             PXProcessing.SetCurrentItem(register);
             try
             {
                 entryGraph.Clear();
                 entryGraph.Document.Current = entryGraph.Document.Search <FARegister.refNbr>(register.RefNbr);
                 entryGraph.Delete.Press();
                 PXProcessing.SetProcessed();
             }
             catch (Exception e)
             {
                 failed = true;
                 PXProcessing.SetError(e);
             }
         }
         if (failed)
         {
             throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
         }
     });
 }
Esempio n. 4
0
        public static void Process(List <FSAppointment> list, bool isMassProcess)
        {
            AppointmentEntry appointmentEntryGraph = PXGraph.CreateInstance <AppointmentEntry>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    appointmentEntryGraph.Clear();
                    appointmentEntryGraph.AppointmentRecords.Current = PXSelect <FSAppointment, Where <FSAppointment.srvOrdType, Equal <Required <FSAppointment.srvOrdType> >, And <FSAppointment.refNbr, Equal <Required <FSAppointment.refNbr> > > > > .Select(appointmentEntryGraph, list[i].SrvOrdType, list[i].RefNbr);

                    appointmentEntryGraph.CalculateExternalTax(appointmentEntryGraph.AppointmentRecords.Current);
                    PXProcessing <FSAppointment> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <FSAppointment> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }
        }
Esempio n. 5
0
        public bool ValidateImportCard(CCSynchronizeCard card, int cardIndex)
        {
            bool ret = true;

            if (card.BAccountID == null)
            {
                PXProcessing <CCSynchronizeCard> .SetError(cardIndex, CA.Messages.CustomerNotDefined);

                ret = false;
            }

            if (card.PaymentMethodID == null)
            {
                PXProcessing <CCSynchronizeCard> .SetError(cardIndex, Messages.PaymentMethodNotDefined);

                ret = false;
            }

            if (card.CashAccountID != null)
            {
                IEnumerable <CashAccount> availableCA = PXSelectorAttribute.SelectAll <CCSynchronizeCard.cashAccountID>(this.CustomerCardPaymentData.Cache, card)
                                                        .RowCast <CashAccount>();
                bool exists = availableCA.Any(i => i.CashAccountID == card.CashAccountID);

                if (!exists)
                {
                    PXProcessing <CCSynchronizeCard> .SetError(cardIndex,
                                                               PXMessages.LocalizeFormatNoPrefixNLA(AR.Messages.CashAccountIsNotConfiguredForPaymentMethodInAR, card.PaymentMethodID));

                    ret = false;
                }
            }
            return(ret);
        }
Esempio n. 6
0
        public static void Release(List <EPTimeCardRow> timeCards)
        {
            TimeCardMaint timeCardMaint = PXGraph.CreateInstance <TimeCardMaint>();

            for (int i = 0; i < timeCards.Count; i++)
            {
                timeCardMaint.Clear();
                timeCardMaint.Document.Current = timeCardMaint.Document.Search <EPTimeCard.timeCardCD>(timeCards[i].TimeCardCD);

                if (timeCardMaint.Document.Current == null)
                {
                    PXProcessing <EPTimeCardRow> .SetError(i, Messages.TimecardCannotBeReleased_NoRights);
                }
                else
                {
                    try
                    {
                        timeCardMaint.release.Press();
                        PXProcessing <EPTimeCardRow> .SetInfo(i, ActionsMessages.RecordProcessed);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <EPTimeCardRow> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                }
            }
        }
        public void ValidateWorkTypes(IEnumerable <DocumentDetails> documents)
        {
            Dictionary <int, RUTROTWorkType> availableWorkTypes = GetAvailableWorkTypes(this, this.Accessinfo.BusinessDate);
            bool haveUnavailableWorkTypes = false;

            for (int i = 0; i < documents.Count(); i++)
            {
                foreach (ARTran tran in documents.ElementAt(i).Lines)
                {
                    ARTranRUTROT tranRR = RUTROTHelper.GetExtensionNullable <ARTran, ARTranRUTROT>(tran);
                    if (tranRR?.IsRUTROTDeductible == true &&
                        (tranRR.RUTROTItemType == RUTROTItemTypes.MaterialCost || tranRR.RUTROTItemType == RUTROTItemTypes.Service))
                    {
                        if (!availableWorkTypes.ContainsKey(tranRR.RUTROTWorkTypeID.Value))
                        {
                            haveUnavailableWorkTypes = true;
                            PXProcessing.SetError(i, new PXException(RUTROTMessages.CannotClaimWorkType));
                        }
                    }
                }
            }
            if (haveUnavailableWorkTypes)
            {
                throw new PXException(RUTROTMessages.CannotClaimWorkType);
            }
        }
Esempio n. 8
0
        public static void ReleaseDoc(List <POLandedCostDoc> list, bool aIsMassProcess)
        {
            var  docgraph = PXGraph.CreateInstance <POLandedCostDocEntry>();
            int  iRow     = 0;
            bool failed   = false;

            foreach (POLandedCostDoc doc in list)
            {
                try
                {
                    docgraph.ReleaseDoc(doc);
                    PXProcessing <POLandedCostDoc> .SetInfo(iRow, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (aIsMassProcess)
                    {
                        PXProcessing <POLandedCostDoc> .SetError(iRow, e);

                        failed = true;
                    }
                    else
                    {
                        throw;
                    }
                }
                iRow++;
            }
            if (failed)
            {
                throw new PXException(Messages.LandedCostProcessingForOneOrMorePOReceiptsFailed);
            }
        }
Esempio n. 9
0
        public StaffContractScheduleProcess()
        {
            StaffContractScheduleProcess processor = null;

            StaffSchedules.SetProcessDelegate(
                delegate(List <FSStaffSchedule> fsScheduleRowList)
            {
                processor = PXGraph.CreateInstance <StaffContractScheduleProcess>();

                int index = 0;
                foreach (FSStaffSchedule fsScheduleRow in fsScheduleRowList)
                {
                    try
                    {
                        DateTime?fromDate = fsScheduleRow.LastGeneratedElementDate ?? fsScheduleRow.StartDate;

                        processor.processStaffSchedule(Filter.Cache, processor, fsScheduleRow, fromDate, Filter.Current.ToDate);

                        PXProcessing <FSStaffSchedule> .SetInfo(index, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <FSStaffSchedule> .SetError(index, e);
                    }

                    index++;
                }
            });
        }
        public static List <ARCashSale> Process(List <ARCashSale> list, bool isMassProcess)
        {
            List <ARCashSale> listWithTax = new List <ARCashSale>(list.Count);
            ARCashSaleEntry   rg          = PXGraph.CreateInstance <ARCashSaleEntry>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    rg.Clear();
                    rg.Document.Current = PXSelect <ARCashSale, Where <ARCashSale.docType, Equal <Required <ARCashSale.docType> >, And <ARCashSale.refNbr, Equal <Required <ARCashSale.refNbr> > > > > .Select(rg, list[i].DocType, list[i].RefNbr);

                    listWithTax.Add(rg.CalculateExternalTax(rg.Document.Current));
                    PXProcessing <ARCashSale> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <ARCashSale> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }

            return(listWithTax);
        }
Esempio n. 11
0
        protected void _(Events.RowSelected <AMMultiLevelBomFilter> e)
        {
            AMMultiLevelBomFilter row = e.Row;

            if (row != null)
            {
                bool enabled = PXSelect <LifeSyncPreference> .Select(this).TopFirst.EnableProdCostAnlys ?? false;

                PXUIFieldAttribute.SetEnabled <AMMultiLevelBomFilterExt.usrEnblItemRoundUp>(e.Cache, row, enabled);
            }

            Results.SetProcessDelegate(delegate(List <LUMStdBomCost> lists)
            {
                try
                {
                    GenerateBOMCost(lists, row);

                    PXProcessing.SetProcessed();
                }
                catch (Exception ex)
                {
                    PXProcessing.SetError(ex);
                    throw;
                }
            });
        }
        public RouteScheduleProcess()
        {
            RouteScheduleProcess processor = null;

            RouteContractSchedules.SetProcessDelegate(
                delegate(List <FSRouteContractScheduleFSServiceContract> fsScheduleRowList)
            {
                processor = PXGraph.CreateInstance <RouteScheduleProcess>();

                int index = 0;
                foreach (FSRouteContractScheduleFSServiceContract fsScheduleRow in fsScheduleRowList)
                {
                    try
                    {
                        processor.processServiceContract(Filter.Cache, fsScheduleRow, Filter.Current.FromDate, Filter.Current.ToDate);

                        PXProcessing <FSRouteContractScheduleFSServiceContract> .SetInfo(index, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <FSRouteContractScheduleFSServiceContract> .SetError(index, e);
                    }

                    index++;
                }

                updateRoutes(processor.nextGenerationID);
            });
        }
        public static bool RecordCostTrans(RegisterEntry registerEntry, List <EPActivityApprove> activities)
        {
            registerEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });//restriction should be applicable only for budgeting.
            EmployeeCostEngine costEngine = new EmployeeCostEngine(registerEntry);

            registerEntry.Views.Caches.Add(typeof(EPActivity));
            PXCache activityCache = registerEntry.Caches <EPActivity>();

            registerEntry.Document.Cache.Insert();
            bool success       = true;
            bool activityAdded = false;

            for (int i = 0; i < activities.Count; i++)
            {
                EPActivity activity = PXSelect <EPActivity> .Search <EPActivity.taskID>(registerEntry, activities[i].TaskID);

                if (activity.Released == true) //activity can be released to PM via Timecard prior to releasing the case.
                {
                    continue;
                }

                try
                {
                    if (activity.ProjectTaskID != null)                    //cost transactions are created only if project is set.
                    {
                        EPEmployee employee = PXSelect <EPEmployee> .Search <EPEmployee.userID>(registerEntry, activity.Owner);

                        activity.LabourItemID = costEngine.GetLaborClass(activity);
                        activityCache.Update(activity);

                        decimal?cost = costEngine.CalculateEmployeeCost(activity, employee.BAccountID, activity.StartDate.Value);
                        registerEntry.CreateTransaction(activity, employee.BAccountID, activity.StartDate.Value, activity.TimeSpent, activity.TimeBillable, cost);
                        activity.EmployeeRate = cost;
                        activityAdded         = true;
                    }

                    activity.Released = true;
                    activityCache.Update(activity);
                }
                catch (Exception e)
                {
                    PXProcessing <EPActivityApprove> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);

                    success = false;
                }
            }
            if (success)
            {
                if (activityAdded)
                {
                    registerEntry.Save.Press();
                }
                else
                {
                    activityCache.Persist(PXDBOperation.Update);
                }
            }

            return(success);
        }
        public static List <CAAdj> Process(List <CAAdj> list, bool isMassProcess)
        {
            List <CAAdj> listWithTax = new List <CAAdj>(list.Count);
            CATranEntry  rg          = PXGraph.CreateInstance <CATranEntry>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    rg.Clear();
                    rg.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.adjRefNbr, Equal <Required <CAAdj.adjRefNbr> > > > .Select(rg, list[i].AdjRefNbr);

                    listWithTax.Add(rg.CalculateAvalaraTax(rg.CAAdjRecords.Current));
                    PXProcessing <CAAdj> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <CAAdj> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }

            return(listWithTax);
        }
        public static void AssignOrders(List <RSSVWorkOrder> orders)
        {
            // The result set to run the report on.
            PXReportResultset assignedOrders = new PXReportResultset(typeof(RSSVWorkOrder));

            RSSVWorkOrderEntry graph = PXGraph.CreateInstance <RSSVWorkOrderEntry>();

            foreach (RSSVWorkOrder order in orders)
            {
                try
                {
                    //Change the assignee to the value selected on the form
                    order.Assignee = order.AssignTo;

                    graph.Clear();
                    graph.AssignOrder(order, true);

                    // Add to the result set the order that has been successfully assigned.
                    if (order.Status == WorkOrderStatusConstants.Assigned)
                    {
                        assignedOrders.Add(order);
                    }
                }
                catch (Exception e)
                {
                    PXProcessing <RSSVWorkOrder> .SetError(orders.IndexOf(order), e);
                }
            }

            if (assignedOrders.GetRowCount() > 0)
            {
                throw new PXReportRequiredException(assignedOrders, "RS601000", Messages.ReportRS601000Title);
            }
        }
Esempio n. 16
0
        public static void Process(List <CROpportunity> list, bool isMassProcess)
        {
            OpportunityMaint rg = PXGraph.CreateInstance <OpportunityMaint>();

            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    rg.Clear();
                    rg.Opportunity.Current = PXSelect <CROpportunity, Where <CROpportunity.opportunityID, Equal <Required <CROpportunity.opportunityID> > > > .Select(rg, list[i].OpportunityID);

                    CalculateAvalaraTax(rg, rg.Opportunity.Current);
                    PXProcessing <CROpportunity> .SetInfo(i, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (isMassProcess)
                    {
                        PXProcessing <CROpportunity> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);
                    }
                    else
                    {
                        throw new PXMassProcessException(i, e);
                    }
                }
            }
        }
        private void ValidateAmounts(IEnumerable <DocumentDetails> documents)
        {
            bool hasAmountProblems = false;

            for (int i = 0; i < documents.Count(); i++)
            {
                decimal paid  = documents.ElementAt(i).TotalPay;
                decimal claim = documents.ElementAt(i).Rutrot.CuryDistributedAmt ?? 0.0m;


                if (claim + paid - (documents.ElementAt(i).Document.CuryOrigDocAmt ?? 0.0m) > 0)
                {
                    hasAmountProblems = true;
                    PXProcessing.SetError(i, new PXException(RUTROTMessages.ClaimedPaidMustNotExceedTotal));
                }
            }

            if (hasAmountProblems)
            {
                throw new PXException(RUTROTMessages.SomeAmountsIncorrect);
            }

            decimal totalClaimAmt = documents.Sum(d => d.Rutrot.CuryTotalAmt ?? 0.0m);

            if (totalClaimAmt > 50000)
            {
                throw new PXException(RUTROTMessages.ClaimedTotalTooMuch);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Create an sales order from external logistic.
        /// </summary>
        public static void ImportRecords(LUM3DCartSetup curSetup, LUM3DCartProcessOrder processOrder)
        {
            try
            {
                SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>();

                SOOrder order = orderEntry.Document.Cache.CreateInstance() as SOOrder;

                order.OrderType        = curSetup.OrderType;
                order.CustomerID       = curSetup.CustomerID;
                order.CustomerOrderNbr = processOrder.OrderID;
                order.DocDate          = processOrder.OrderDate;

                order = orderEntry.Document.Insert(order);

                CreateOrderDetail(orderEntry, curSetup, order);

                orderEntry.Save.Press();

                CreatePaymentProcess(order);
            }
            catch (PXException ex)
            {
                PXProcessing.SetError <LUM3DCartProcessOrder>(ex.Message);
                throw;
            }
        }
Esempio n. 19
0
        public ConvertItemsToEquipmentProcess()
        {
            SMEquipmentMaint graphSMEquipmentMaint;

            InventoryItems.SetProcessDelegate(
                delegate(List <SoldInventoryItem> inventoryItemRows)
            {
                graphSMEquipmentMaint = CreateInstance <SMEquipmentMaint>();
                bool error            = false;
                for (int i = 0; i < inventoryItemRows.Count; i++)
                {
                    SoldInventoryItem soldInventoryItemRow = inventoryItemRows[i];
                    error = false;

                    try
                    {
                        for (int j = 0; j < soldInventoryItemRow.ShippedQty; j++)
                        {
                            SharedFunctions.CreateSoldEquipment(graphSMEquipmentMaint, soldInventoryItemRow, null, null, null, null);
                        }
                    }
                    catch (Exception e)
                    {
                        error = true;
                        PXProcessing <SoldInventoryItem> .SetError(i, e.Message);
                    }

                    if (error == false)
                    {
                        PXProcessing <SoldInventoryItem> .SetInfo(i, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                    }
                }
            });
        }
 public static void Process(IList <KCStore> stores)
 {
     logger.SetRequestId(GetRequestId());
     for (int i = 0; i < stores.Count; i++)
     {
         var tokenSource = new CancellationTokenSource();
         try
         {
             ProcessStore(stores[i], tokenSource.Token);
             PXProcessing <KCStore> .SetInfo(i, KCMessages.BulkUploadSuccess(stores[i].SiteMasterCD));
         }
         catch (Exception exception)
         {
             string log = KCMessages.ProcessException(stores[i].SiteMasterCD, exception.Message, exception.StackTrace);
             PXTrace.WriteError(exception);
             logger.ClearLoggingIds();
             logger.Error(log);
             PXProcessing <KCStore> .SetError(i, new Exception(log));
         }
         finally
         {
             tokenSource.Cancel(true);
             tokenSource.Dispose();
         }
     }
 }
Esempio n. 21
0
        private static void Process(List <KCPriceAndInventoryMessage> messages)
        {
            logger.SetRequestId(GetRequestId());

            messages = messages.OrderBy(x => x.CreatedDateTime).ToList();
            bool ftp = messages.Count >= GetThresholdValue();

            if (ftp && messages.Count > 0)
            {
                var tokenSource = new CancellationTokenSource();
                try
                {
                    var reversed = new List <KCPriceAndInventoryMessage>(messages);
                    reversed.Reverse();

                    new KCMSMQDataHelper(logger.LoggerProperties).ProcessMessageFTP(reversed, tokenSource.Token);
                    logger.ClearLoggingIds();
                    logger.Information(KCMessages.MSMQSyncFTP(messages.Count));
                    foreach (KCPriceAndInventoryMessage msg in reversed)
                    {
                        PXProcessing <KCPriceAndInventoryMessage> .SetInfo(messages.IndexOf(msg), $"Data Exchange for {msg.Message} has been processed successfully");
                    }
                }
                catch (Exception exception)
                {
                    PXProcessing <KCPriceAndInventoryMessage> .SetError(new Exception(exception.Message));

                    logger.ClearLoggingIds();
                    logger.Error(exception.Message);
                }
                finally
                {
                    tokenSource.Cancel(true);
                    tokenSource.Dispose();
                }
            }
            else if (messages.Count > 0)
            {
                int index = 0;
                try
                {
                    foreach (KCPriceAndInventoryMessage msg in messages)
                    {
                        index = messages.IndexOf(msg);

                        new KCMSMQDataHelper(logger.LoggerProperties).ProcessMessageAPI(msg);
                        PXProcessing <KCPriceAndInventoryMessage> .SetInfo(index, $"Data Exchange for {msg.Message} has been processed successfully");
                    }
                }
                catch (Exception exception)
                {
                    PXProcessing <KCPriceAndInventoryMessage> .SetError(index, new Exception(exception.Message));

                    logger.ClearLoggingIds();
                    logger.Error(exception.Message);
                }
            }
        }
Esempio n. 22
0
        public static void SendData(IEnumerable <SOOrder> data, string name = "orders.csv")
        {
            //Create needed graphs
            var graph = PXGraph.CreateInstance <AFSetupMaint>();

            AFSetup setup = graph.AFSetupView.Current ?? graph.AFSetupView.Select();

            //-----------------------------------------------------------------------------
            //Change for Setup daya
            string bucketName      = setup.AFBucketName;    //"acumatica-forecast";
            string s3DirectoryName = setup.AFDirectoryName; //"dynamics/facturas";
            string accessKey       = setup.AFAccessKey;
            string secretKey       = setup.AFSecretKey;

            //-----------------------------------------------------------------------------

            PXTrace.WriteInformation($"AFAccessKey: {accessKey} AFSecretKey: {secretKey} AFBucketName: {bucketName} AFDirectoryName: {s3DirectoryName}");

            //if (data?.Count == 0) return;

            using (var stream = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(stream))
                {
                    try
                    {
                        // Convert to csv and upload
                        foreach (var i in data)
                        {
                            try
                            {
                                //var row = data[i];
                                //Check current item
                                //PXProcessing.SetCurrentItem(row);

                                //sw.WriteLine(i);
                            }
                            catch (Exception e)
                            {
                                PXProcessing <SOOrder> .SetError(e.Message);
                            }
                        }

                        var line = $"TEST,2020-01-25T00:10:10,1.00";
                        sw.WriteLine(line);

                        //Si existe el CFDI permite la subida del XML y PDF
                        //Se crea la instancia a S3
                        AFAmazonTools myUploader = new AFAmazonTools();
                        var           result     = myUploader.UploadToS3(accessKey, secretKey, stream.ToArray(), bucketName, s3DirectoryName, name);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <SOOrder> .SetError(e.Message);
                    }
                }
            }
        }
        public ServiceOrderProcess()
        {
            ServiceOrderProcess graphServiceOrderProcess;

            ServiceOrderRecords.SetProcessDelegate(
                delegate(List <FSServiceOrder> fsServiceOrderRowList)
            {
                graphServiceOrderProcess = PXGraph.CreateInstance <ServiceOrderProcess>();

                ServiceOrderEntry graphServiceOrderEntry = PXGraph.CreateInstance <ServiceOrderEntry>();

                int index = 0;

                foreach (FSServiceOrder fsServiceOrderRow in fsServiceOrderRowList)
                {
                    try
                    {
                        graphServiceOrderEntry.ServiceOrderRecords.Current = graphServiceOrderEntry.ServiceOrderRecords
                                                                             .Search <FSServiceOrder.refNbr>(fsServiceOrderRow.RefNbr, fsServiceOrderRow.SrvOrdType);

                        switch (Filter.Current.SOAction)
                        {
                        case ID.ServiceOrder_Action_Filter.COMPLETE:
                            graphServiceOrderEntry.CompleteOrder();
                            break;

                        case ID.ServiceOrder_Action_Filter.CANCEL:
                            graphServiceOrderEntry.CancelOrder();
                            break;

                        case ID.ServiceOrder_Action_Filter.REOPEN:
                            graphServiceOrderEntry.ReopenOrder();
                            break;

                        case ID.ServiceOrder_Action_Filter.CLOSE:
                            graphServiceOrderEntry.CloseOrder();
                            break;

                        case ID.ServiceOrder_Action_Filter.UNCLOSE:
                            graphServiceOrderEntry.UncloseOrderWithOptions(false);
                            break;

                        case ID.ServiceOrder_Action_Filter.ALLOWINVOICE:
                            graphServiceOrderEntry.AllowInvoice();
                            break;
                        }

                        PXProcessing <FSServiceOrder> .SetInfo(index, TX.Messages.RECORD_PROCESSED_SUCCESSFULLY);
                    }
                    catch (Exception e)
                    {
                        PXProcessing <FSServiceOrder> .SetError(index, e);
                    }

                    index++;
                }
            });
        }
Esempio n. 24
0
        private const bool AutoReleaseDebitAdjustments = true;         //TODO: now (26.10.2017) we can't apply nonreleased debit adjustment

        public static APInvoice CreateAndReleasePPDDebitAdj(APInvoiceEntry ie, APPPDDebitAdjParameters filter, List <PendingPPDDebitAdjApp> list, bool autoReleaseDebitAdjustments)
        {
            APInvoice invDebitAdj;

            try
            {
                ie.Clear(PXClearOption.ClearAll);
                PXUIFieldAttribute.SetError(ie.Document.Cache, null, null, null);

                using (var ts = new PXTransactionScope())
                {
                    invDebitAdj = ie.CreatePPDDebitAdj(filter, list);
                    if (invDebitAdj != null)
                    {
                        if (autoReleaseDebitAdjustments == true)
                        {
                            using (new PXTimeStampScope(null))
                            {
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);
                                APPaymentEntry paymentEntry = PXGraph.CreateInstance <APPaymentEntry>();
                                APPayment      debitAdj     = PXSelect <APPayment,
                                                                        Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                               And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > >
                                                              .Select(paymentEntry, invDebitAdj.DocType, invDebitAdj.RefNbr)
                                                              .First();

                                paymentEntry.Document.Current = debitAdj;
                                paymentEntry.SelectTimeStamp();
                                CreatePPDApplications(paymentEntry, list, debitAdj);
                                paymentEntry.Persist();
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);                                                                                               // It needs to release applications
                            }
                        }

                        foreach (PendingPPDDebitAdjApp adj in list)
                        {
                            PXProcessing <PendingPPDDebitAdjApp> .SetInfo(adj.Index, ActionsMessages.RecordProcessed);
                        }
                    }
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                foreach (PendingPPDDebitAdjApp adj in list)
                {
                    PXProcessing <PendingPPDDebitAdjApp> .SetError(adj.Index, e);
                }

                invDebitAdj = null;
            }

            return(invDebitAdj);
        }
Esempio n. 25
0
        public static void ReleaseDoc(List <POReceipt> list, bool aIsMassProcess)
        {
            POReceiptEntry            docgraph        = PXGraph.CreateInstance <POReceiptEntry>();
            DocumentList <INRegister> created         = new DocumentList <INRegister>(docgraph);
            DocumentList <APInvoice>  invoicesCreated = new DocumentList <APInvoice>(docgraph);
            INReceiptEntry            iRe             = null;
            INIssueEntry iIe = null;

            AP.APInvoiceEntry apInvoiceGraph = PXGraph.CreateInstance <APInvoiceEntry>();
            int  iRow   = 0;
            bool failed = false;

            foreach (POReceipt order in list)
            {
                try
                {
                    switch (order.ReceiptType)
                    {
                    case POReceiptType.POReceipt:
                    case POReceiptType.TransferReceipt:
                        if (iRe == null)
                        {
                            iRe = docgraph.CreateReceiptEntry();
                        }
                        docgraph.ReleaseReceipt(iRe, apInvoiceGraph, order, created, invoicesCreated, aIsMassProcess);
                        break;

                    case POReceiptType.POReturn:
                        if (iIe == null)
                        {
                            iIe = docgraph.CreateIssueEntry();
                        }
                        docgraph.ReleaseReturn(iIe, apInvoiceGraph, order, created, invoicesCreated, aIsMassProcess);
                        break;
                    }
                    PXProcessing <POReceipt> .SetInfo(iRow, ActionsMessages.RecordProcessed);
                }
                catch (Exception e)
                {
                    if (aIsMassProcess)
                    {
                        PXProcessing <POReceipt> .SetError(iRow, e);

                        failed = true;
                    }
                    else
                    {
                        throw;
                    }
                }
                iRow++;
            }
            if (failed)
            {
                throw new PXException(Messages.ReleaseOfOneOrMoreReceiptsHasFailed);
            }
        }
Esempio n. 26
0
        protected virtual bool CreateAndReleaseCancellationInvoice(ARRegister doc, int index, bool isMassProcess)
        {
            if (doc.IsCorrection != true)
            {
                return(true);
            }

            try
            {
                var invoiceGraph = PXGraph.CreateInstance <SOInvoiceEntry>();

                ARInvoice existingCancellationInvoice = PXSelect <ARInvoice,
                                                                  Where <ARInvoice.origDocType, Equal <Current <ARInvoice.origDocType> >,
                                                                         And <ARInvoice.origRefNbr, Equal <Current <ARInvoice.origRefNbr> >,
                                                                              And <ARInvoice.isCancellation, Equal <True> > > > >
                                                        .SelectSingleBound(invoiceGraph, new[] { doc });

                if (existingCancellationInvoice != null)
                {
                    if (existingCancellationInvoice.Released != true)
                    {
                        throw new PXException(Messages.CancellationInvoiceExists, existingCancellationInvoice.RefNbr, doc.RefNbr);
                    }
                    else
                    {
                        return(true);
                    }
                }

                invoiceGraph.GetExtension <Correction>().CancellationInvoiceCreationOnRelease = true;
                invoiceGraph.Document.Current = invoiceGraph.Document.Search <ARInvoice.refNbr>(doc.OrigRefNbr, doc.OrigDocType);
                invoiceGraph.Actions[nameof(cancelInvoice)].Press();

                using (var scope = new PXTransactionScope())
                {
                    invoiceGraph.Save.Press();

                    invoiceGraph.ReleaseInvoiceProc(
                        new List <ARRegister> {
                        invoiceGraph.Document.Current
                    },
                        isMassProcess: false);

                    scope.Complete();
                }

                return(true);
            }
            catch (PXException e) when(isMassProcess)
            {
                PXProcessing <ARRegister> .SetError(index, e);

                return(false);
            }
        }
Esempio n. 27
0
 public static void CreateAPBill(System.Collections.Generic.List <FLXCommissionTran> list, FLXSetup setup)
 {
     try
     {
         APInvoiceEntry instance1 = PXGraph.CreateInstance <APInvoiceEntry>();
         string         str       = string.Empty;
         string         format    = "[{0}] Isn't A Vendor.";
         for (int index = 0; index < list.Count; ++index)
         {
             FLXCommissionTran flxCommissionTran = list[index];
             if (FLXGenBillAPInvoice.CheckBAType((PXGraph)instance1, flxCommissionTran.SalesRepID))
             {
                 if (instance1.CurrentDocument.Current == null)
                 {
                     APInvoice instance2 = instance1.Document.Cache.CreateInstance() as APInvoice;
                     instance2.DocType    = "INV";
                     instance2.VendorID   = flxCommissionTran.SalesRepID;
                     instance2.DocDate    = flxCommissionTran.APDate;
                     instance2.InvoiceNbr = string.Format("{0} {1}", (object)flxCommissionTran.CommissionTranID, (object)instance1.vendor.Select((object)instance2.VendorID).TopFirst.AcctCD.Trim());
                     instance1.Document.Insert(instance2);
                 }
                 APTran instance3 = instance1.Transactions.Cache.CreateInstance() as APTran;
                 instance3.BranchID     = flxCommissionTran.BranchID;
                 instance3.InventoryID  = setup.CommissionItem;
                 instance3.Qty          = new Decimal?((Decimal)1);
                 instance3.CuryUnitCost = flxCommissionTran.CommisionAmt;
                 instance3.TranDesc     = string.Format("{0},{1},{2},{3},{4}", (object)flxCommissionTran.CommissionTranID, (object)flxCommissionTran.OrderNbr, (object)flxCommissionTran.ProjectNbr, (object)instance1.nonStockItem.Select((object)flxCommissionTran.InventoryID).TopFirst.InventoryCD.Trim(), (object)instance1.nonStockItem.Select((object)flxCommissionTran.NonStockItem).TopFirst.InventoryCD.Trim());
                 instance3.SubID        = instance1.nonStockItem.Select((object)instance3.InventoryID).TopFirst.COGSSubID;
                 instance1.Transactions.Insert(instance3);
                 str = str + flxCommissionTran.CommissionTranID + "/";
             }
             else
             {
                 throw new PXException(format, new object[1]
                 {
                     (object)SelectFrom <BAccountR> .Where <BAccountR.bAccountID.IsEqual <P.AsInt> > .View.Select((PXGraph)instance1, (object)flxCommissionTran.SalesRepID).TopFirst.AcctCD.Trim()
                 });
             }
         }
         instance1.Document.Current.DocDesc = str.Substring(0, (str.Length > PX.Objects.Common.Constants.TranDescLength ? PX.Objects.Common.Constants.TranDescLength : str.Length) - 1);
         instance1.Document.UpdateCurrent();
         instance1.Save.Press();
         for (int index = 0; index < list.Count; ++index)
         {
             FLXCommissionTran flxCommissionTran = list[index];
             PXUpdate <Set <FLXCommissionTran.aPBillCreated, Required <FLXCommissionTran.aPBillCreated>, Set <FLXCommissionTran.aPBillRefNBr, Required <APInvoice.refNbr> > >, FLXCommissionTran, Where <FLXCommissionTran.commissionTranID, Equal <Required <FLXCommissionTran.commissionTranID> > > > .Update((PXGraph)instance1, (object)true, (object)instance1.Document.Current.RefNbr, (object)flxCommissionTran.CommissionTranID);
         }
     }
     catch (PXException ex)
     {
         PXProcessing.SetError((Exception)ex);
         throw ex;
     }
 }
        private void ValidateDates(IEnumerable <DocumentDetails> documents)
        {
            var invoiceDates = documents.Select(d => d.Document.DocDate).Where(date => date != null).Select(date => date.Value);
            int minYear      = DateTime.Today.Month > 1 ? DateTime.Today.Year : DateTime.Today.Year - 1;

            bool hasIncorrectDates = false;

            for (int i = 0; i < documents.Count(); i++)
            {
                var inv = documents.ElementAt(i).Document;
                if (inv.DocDate == null)
                {
                    hasIncorrectDates = true;
                    PXProcessing.SetError(i, new PXException(RUTROTMessages.DateShouldBeSpecifiedOnDocument));
                }

                if (inv.DocDate.Value.Year < minYear)
                {
                    hasIncorrectDates = true;
                    PXProcessing.SetError(i, new PXException(RUTROTMessages.DocumentDateIsBelowAllowed, new DateTime(minYear, 1, 1)));
                }
            }

            if (hasIncorrectDates)
            {
                throw new PXException(RUTROTMessages.SomeDocumentDatesIncorrect);
            }

            if (invoiceDates.Select(d => d.Year).Distinct().Count() > 1)
            {
                throw new PXException(RUTROTMessages.AllDocumentsMustBeSameYear);
            }

            bool hasTooLatePayments = false;

            for (int i = 0; i < documents.Count(); i++)
            {
                foreach (var pay in documents.ElementAt(i).Payments.Select(p => p.Item2))
                {
                    if (pay.AdjgDocDate > DateTime.Today)
                    {
                        hasTooLatePayments = true;
                        PXProcessing.SetError(i, new PXException(RUTROTMessages.PaymentDatesMustNotExceedClaimDate));
                        break;
                    }
                }
            }

            if (hasTooLatePayments)
            {
                throw new PXException(RUTROTMessages.PaymentDatesMustNotExceedClaimDate);
            }
        }
Esempio n. 29
0
        public static void SetProcessDelegate <ProcessGraph>(PXGraph graph, ScheduleRun.Parameters filter, PXProcessing <Schedule> view)
            where ProcessGraph : PXGraph <ProcessGraph>, IScheduleProcessing, new()
        {
            if (filter == null)
            {
                return;
            }

            short times = filter.LimitTypeSel == ScheduleRunLimitType.StopAfterNumberOfExecutions
                                ? filter.RunLimit ?? 1
                                : short.MaxValue;

            DateTime executionDate = filter.LimitTypeSel == ScheduleRunLimitType.StopOnExecutionDate
                                ? filter.ExecutionDate ?? graph.Accessinfo.BusinessDate.Value
                                : DateTime.MaxValue;

            Dictionary <string, string> parametersErrors = PXUIFieldAttribute.GetErrors(
                graph.Caches[typeof(ScheduleRun.Parameters)],
                filter);

            view.SetProcessDelegate(schedules =>
            {
                if (parametersErrors.Any())
                {
                    throw new PXException(parametersErrors.First().Value);
                }

                ProcessGraph processGraph = PXGraph.CreateInstance <ProcessGraph>();
                bool failed = false;
                foreach (Schedule schedule in schedules)
                {
                    try
                    {
                        PXProcessing <Schedule> .SetCurrentItem(schedule);
                        processGraph.Clear();
                        processGraph.GenerateProc(schedule, times, executionDate);
                        PXProcessing <Schedule> .SetInfo(ActionsMessages.RecordProcessed);
                    }
                    catch (Exception e)
                    {
                        failed = true;
                        PXProcessing <Schedule> .SetError(e);
                    }
                }
                if (failed)
                {
                    //Clean current to prevent set exception to the last item
                    PXProcessing <Schedule> .SetCurrentItem(null);
                    throw new PXException(AR.Messages.OneOrMoreItemsAreNotProcessed);
                }
            });
        }
        public static bool RecordContractUsage(List <EPActivityApprove> activities, string description)
        {
            RegisterEntry registerEntry = PXGraph.CreateInstance <RegisterEntry>();

            registerEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            registerEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });//restriction should be applicable only for budgeting.
            registerEntry.Document.Cache.Insert();
            registerEntry.Document.Current.Description = description;
            registerEntry.Document.Current.Released    = true;
            registerEntry.Views.Caches.Add(typeof(EPActivity));
            PXCache activityCache = registerEntry.Caches <EPActivity>();

            bool success       = true;
            bool activityAdded = false;

            for (int i = 0; i < activities.Count; i++)
            {
                EPActivity activity = activities[i];
                try
                {
                    if (activity.RefNoteID != null && PXSelect <CRCase, Where <CRCase.noteID, Equal <Required <CRCase.noteID> > > > .Select(registerEntry, activity.RefNoteID).Count == 1)
                    {
                        //Add Contract-Usage
                        activityAdded   = registerEntry.CreateContractUsage(activity) != null || activityAdded;
                        activity.Billed = true;
                        activityCache.Update(activity);
                    }
                }
                catch (Exception e)
                {
                    PXProcessing <EPActivityApprove> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message);

                    success = false;
                }
            }

            if (success)
            {
                if (activityAdded)
                {
                    registerEntry.Save.Press();
                }
                else
                {
                    activityCache.Persist(PXDBOperation.Update);
                }
            }

            return(success);
        }