protected void exportAttachmnts()
    {
        var order = Base.Document.Current;

        PXLongOperation.StartOperation(Base, () =>
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (PX.Common.ZipArchive archive = PX.Common.ZipArchive.CreateFrom(stream, false))
                {
                    UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                    Guid[] uids = PXNoteAttribute.GetFileNotes(Base.Document.Cache, order);
                    foreach (Guid uid in uids)
                    {
                        PX.SM.FileInfo fileInfo = upload.GetFile(uid);
                        archive.AddFile(fileInfo.Name, fileInfo.BinData);
                    }
                }
                PX.SM.FileInfo info = new PX.SM.FileInfo(
                    string.Format("{0}-{1}-Attachmets.zip", order.OrderType, order.OrderNbr),
                    null, stream.ToArray());
                throw new PXRedirectToFileException(info, true);
            }
        });
    }
Esempio n. 2
0
        private void SendCopyMessageToInside(PXGraph graph, EMailAccount account, EPActivity message, IEnumerable <Mailbox> email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (EPActivity)cache.CreateCopy(message);

            copy.TaskID       = null;
            copy.IsIncome     = false;
            copy.ParentTaskID = message.TaskID;
            copy.MailTo       = ConcatAddresses(email);       //TODO: need add address description
            copy.MailCc       = null;
            copy.MailBcc      = null;
            copy.MPStatus     = MailStatusListAttribute.PreProcess;
            copy.ClassID      = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID       = null;
            copy.ParentRefNoteID = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID    = imcUid;
            copy.MessageId = GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.Owner     = message.Owner;
            copy.IsPrivate = message.IsPrivate;
            cache.Insert(copy);
            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Esempio n. 3
0
        protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, bool copyNotes, bool copyFiles)
        {
            ARTran tran = (ARTran)arGraph.Transactions.Cache.CreateInstance();

            tran.InventoryID = row.InventoryID;
            tran.TranDesc    = row.TranDesc;
            tran.TranCost    = row.ExtCost;
            tran.Qty         = row.Qty;
            tran.UOM         = row.UOM;
            tran.CuryTranAmt = row.CuryTranAmt;
            tran.AccountID   = row.SalesAccountID;
            tran.SubID       = row.SalesSubID;
            tran.Date        = row.ExpenseDate;
            tran             = arGraph.Transactions.Insert(tran);

            if (copyNotes)
            {
                string note = PXNoteAttribute.GetNote(Caches[typeof(EPExpenseClaimDetails)], row);
                if (note != null)
                {
                    PXNoteAttribute.SetNote(arGraph.Transactions.Cache, tran, note);
                }
            }
            if (copyFiles)
            {
                Guid[] files = PXNoteAttribute.GetFileNotes(Caches[typeof(EPExpenseClaimDetails)], row);
                if (files != null && files.Length > 0)
                {
                    PXNoteAttribute.SetFileNotes(arGraph.Transactions.Cache, tran, files);
                }
            }
        }
Esempio n. 4
0
        protected void SendCopyMessageToInside(PXGraph graph, EMailAccount account, CRSMEmail message, IEnumerable <MailAddress> addresses)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            MailAddress address = null;

            copy.MailFrom = EmailParser.TryParse(message.MailFrom, out address)
                                ? new MailAddress(account.Address, address.DisplayName).ToString()
                                : account.Address;
            copy.MailTo    = PXDBEmailAttribute.ToString(addresses);          //TODO: need add address description
            copy.MailCc    = null;
            copy.MailBcc   = null;
            copy.MailReply = copy.MailFrom;
            copy.MPStatus  = MailStatusListAttribute.PreProcess;
            copy.ClassID   = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID  = null;
            copy.BAccountID = null;
            copy.ContactID  = null;
            copy.Pop3UID    = null;
            copy.ImapUID    = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID      = imcUid;
            copy.MessageId   = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.OwnerID     = null;
            copy.WorkgroupID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.CreateCopy(cache.Update(copy));
            }

            copy.IsPrivate   = message.IsPrivate;
            copy.WorkgroupID = message.WorkgroupID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Esempio n. 5
0
        public virtual IEnumerable trainFaceRecongnition(PXAdapter adapter)
        {
            Save.Press();

            PXLongOperation.StartOperation(this, delegate()
            {
                IFaceClient client = Trainer.Authenticate(MasterView.Current.FaceApiEndpoint, MasterView.Current.FaceApiSubscriptionKey);
                var trainer        = new Trainer(client, MasterView.Current.FaceApiGroupID);
                bool uploaded      = false;
                foreach (EPEmployee emp in PXSelect <EPEmployee> .Select(this))
                {
                    bool deleted  = false;
                    Person person = null;
                    Guid[] files  = PXNoteAttribute.GetFileNotes(this.Caches[typeof(EPEmployee)], emp);

                    foreach (Guid fileID in files)
                    {
                        var fm            = new PX.SM.UploadFileMaintenance();
                        PX.SM.FileInfo fi = fm.GetFile(fileID);
                        string ext        = System.IO.Path.GetExtension(fi.Name).ToLower();
                        PXTrace.WriteWarning(emp.AcctCD.TrimEnd() + " " + ext);
                        if (ext.IsIn(".png", ".jpg", ".bmp"))
                        {
                            if (!deleted)
                            {
                                var utilities = new Utilities(client, MasterView.Current.FaceApiGroupID);
                                utilities.DeleteEmployee(emp.AcctCD.TrimEnd());
                                deleted = true;
                            }

                            if (person == null)
                            {
                                person = trainer.GetEmployee_CreateIfNonExistent(emp.AcctCD.TrimEnd());
                            }


                            using (var stream = new System.IO.MemoryStream(fi.BinData))
                            {
                                PXTrace.WriteWarning(emp.AcctCD.TrimEnd() + " " + fi.Name + " " + stream.Length);
                                trainer.UploadTrainingImageStream(person, stream);
                                Thread.Sleep(1000);
                                uploaded = true;
                            }
                        }
                    }
                }
                if (uploaded)
                {
                    trainer.InvokeTraining();
                }
            });


            return(adapter.Get());
        }
Esempio n. 6
0
        protected virtual void InsertPMTran(RegisterEntry pmGraph, EPExpenseClaimDetails row, EPExpenseClaim doc, bool copyNotes, bool copyFiles)
        {
            PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(pmGraph, row.ContractID);

            Account account = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(this, row.ExpenseAccountID);

            if (account.AccountGroupID == null && project.BaseType == PMProject.ProjectBaseType.Project)
            {
                throw new PXException(Messages.AccountGroupIsNotAssignedForAccount, account.AccountCD);
            }

            PMTran tran = (PMTran)pmGraph.Transactions.Cache.Insert();

            tran.AccountGroupID = account.AccountGroupID;
            tran.BAccountID     = row.CustomerID;
            tran.LocationID     = row.CustomerLocationID;
            tran.ProjectID      = row.ContractID;
            tran.TaskID         = row.TaskID;
            tran.InventoryID    = row.InventoryID;
            tran.Qty            = row.Qty;
            tran.Billable       = true;
            tran.BillableQty    = row.Qty;
            tran.UOM            = row.UOM;
            tran.UnitRate       = row.UnitCost;
            tran.Amount         = row.TranAmt;
            tran.AccountID      = row.ExpenseAccountID;
            tran.SubID          = row.ExpenseSubID;
            tran.StartDate      = row.ExpenseDate;
            tran.EndDate        = row.ExpenseDate;
            tran.Date           = row.ExpenseDate;
            tran.ResourceID     = doc.EmployeeID;
            tran.Released       = project.BaseType == PMProject.ContractBaseType.Contract;      //contract trans are created as released

            pmGraph.Transactions.Update(tran);

            pmGraph.Document.Current.Released = project.BaseType == PMProject.ContractBaseType.Contract;

            if (copyNotes)
            {
                string note = PXNoteAttribute.GetNote(Caches[typeof(EPExpenseClaimDetails)], row);
                if (note != null)
                {
                    PXNoteAttribute.SetNote(pmGraph.Transactions.Cache, tran, note);
                }
            }
            if (copyFiles)
            {
                Guid[] files = PXNoteAttribute.GetFileNotes(Caches[typeof(EPExpenseClaimDetails)], row);
                if (files != null && files.Length > 0)
                {
                    PXNoteAttribute.SetFileNotes(pmGraph.Transactions.Cache, tran, files);
                }
            }
        }
        private void SendCopyMessage(PXGraph graph, EMailAccount account, CRSMEmail message, string email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            copy.MailTo       = email;       //TODO: need add address description
            copy.MailCc       = null;
            copy.MailBcc      = null;
            copy.MPStatus     = MailStatusListAttribute.PreProcess;
            copy.ClassID      = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID  = null;
            copy.BAccountID = null;
            copy.ContactID  = null;
            copy.Pop3UID    = null;
            copy.ImapUID    = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID      = imcUid;
            copy.MessageId   = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.OwnerID     = null;
            copy.WorkgroupID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.CreateCopy(cache.Update(copy));
            }

            copy.WorkgroupID = message.WorkgroupID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
            graph.EnsureCachePersistence(copy.GetType());
        }
Esempio n. 8
0
 public static byte[] GetFirstFile(PXCache cache, object row)
 {
     Guid[] guids = PXNoteAttribute.GetFileNotes(cache, row);
     if (guids.Length > 0)
     {
         var            fm = new PX.SM.UploadFileMaintenance();
         PX.SM.FileInfo fi = fm.GetFile(guids[0]);
         return(fi.BinData);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 9
0
        private void SendCopyMessageToOutside(PXGraph graph, EMailAccount account, CRSMEmail message, IEnumerable <Mailbox> email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            Mailbox mailFrom;

            copy.MailFrom = Mailbox.TryParse(message.MailFrom, out mailFrom)
                ? new Mailbox(mailFrom.DisplayName, account.Address).ToString()
                : account.Address;
            copy.MailTo   = ConcatAddresses(email); //TODO: need add address description
            copy.MailCc   = null;
            copy.MailBcc  = null;
            copy.MPStatus = MailStatusListAttribute.PreProcess;
            copy.ClassID  = CRActivityClass.Email;
            var imcUid = Guid.NewGuid();

            copy.ImcUID       = imcUid;
            copy.MessageId    = GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.IsPrivate    = message.IsPrivate;
            copy.OwnerID      = null;
            copy.ParentNoteID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                copy = (CRSMEmail)cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.Update(copy);
            }

            copy.ParentNoteID = message.NoteID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Esempio n. 10
0
        private void SendCopyMessageToOutside(PXGraph graph, EPActivity message, IEnumerable <Mailbox> email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (EPActivity)cache.CreateCopy(message);

            copy.TaskID       = null;
            copy.IsIncome     = false;
            copy.ParentTaskID = message.TaskID;
            copy.MailTo       = ConcatAddresses(email);       //TODO: need add address description
            copy.MailCc       = null;
            copy.MailBcc      = null;
            copy.MPStatus     = MailStatusListAttribute.PreProcess;
            copy.ClassID      = CRActivityClass.Email;
            var imcUid = Guid.NewGuid();

            copy.ImcUID    = imcUid;
            copy.MessageId = GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.IsPrivate = message.IsPrivate;
            copy.Owner     = null;
            copy           = (EPActivity)cache.CreateCopy(cache.Insert(copy));
            //Update owner and reset owner if employee not found
            copy.Owner = message.Owner;
            try
            {
                cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.Owner = null;
                cache.Update(copy);
            }

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Esempio n. 11
0
        protected virtual List <BillingData> BillTask(PMTask task, PMBillingRule rule, DateTime billingDate)
        {
            PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, task.ProjectID);

            Customer customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(this, project.CustomerID);

            List <BillingData>               list         = new List <BillingData>();
            Dictionary <int, decimal>        availableQty = new Dictionary <int, decimal>();
            Dictionary <int, ContractDetail> billingItems = new Dictionary <int, ContractDetail>();

            //recurent Billing:
            PXSelectBase <ContractDetail> selectBilling = new PXSelect <ContractDetail,
                                                                        Where <ContractDetail.contractID, Equal <Required <ContractDetail.contractID> >,
                                                                               And <ContractDetail.taskID, Equal <Required <ContractDetail.taskID> > > > >(this);

            foreach (ContractDetail billing in selectBilling.Select(task.ProjectID, task.TaskID))
            {
                billingItems.Add(billing.InventoryID.Value, billing);

                if (billing.Included > 0)
                {
                    if (billing.ResetUsage == ResetUsageOption.OnBilling)
                    {
                        availableQty.Add(billing.InventoryID.Value, billing.Included.Value);
                    }
                    else
                    {
                        decimal qtyLeft = billing.Included.Value - billing.LastBilledQty ?? 0;

                        if (qtyLeft > 0)
                        {
                            availableQty.Add(billing.InventoryID.Value, qtyLeft);
                        }
                    }
                }

                bool bill = false;
                if (billing.ResetUsage == ResetUsageOption.OnBilling)
                {
                    bill = true;
                }
                else
                {
                    if (billing.LastBilledDate == null)
                    {
                        bill = true;
                    }
                }

                if (bill)
                {
                    ARTran arTran = new ARTran();
                    arTran.InventoryID    = billing.InventoryID;
                    arTran.TranDesc       = billing.Description;
                    arTran.Qty            = billing.Included;
                    arTran.UOM            = billing.UOM;
                    arTran.ExtPrice       = billing.ItemFee;
                    arTran.TranAmt        = arTran.ExtPrice;
                    arTran.ProjectID      = task.ProjectID;
                    arTran.TaskID         = task.TaskID;
                    arTran.Commissionable = false;                     //todo

                    string subCD = null;
                    #region Set Account and Subaccount
                    if (billing.AccountSource != PMAccountSource.None)
                    {
                        if (rule.AccountSource == PMAccountSource.RecurringBillingItem)
                        {
                            if (billing.AccountID != null)
                            {
                                arTran.AccountID = billing.AccountID;
                            }
                            else
                            {
                                InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                                throw new PXException(Messages.BillingRuleAccountIsNotConfiguredForBillingRecurent, item.InventoryCD);
                            }
                        }
                        else if (billing.AccountSource == PMAccountSource.Project)
                        {
                            if (project.DefaultAccountID != null)
                            {
                                arTran.AccountID = project.DefaultAccountID;
                            }
                            else
                            {
                                InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                                throw new PXException(Messages.ProjectAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, project.ContractCD);
                            }
                        }
                        else if (billing.AccountSource == PMAccountSource.Task)
                        {
                            if (task.DefaultAccountID != null)
                            {
                                arTran.AccountID = task.DefaultAccountID;
                            }
                            else
                            {
                                InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                                throw new PXException(Messages.TaskAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, project.ContractCD, task.TaskCD);
                            }
                        }
                        else if (billing.AccountSource == PMAccountSource.InventoryItem)
                        {
                            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                            if (item != null)
                            {
                                if (item.SalesAcctID != null)
                                {
                                    arTran.AccountID = item.SalesAcctID;
                                }
                                else
                                {
                                    throw new PXException(Messages.InventoryAccountIsNotConfiguredForBillingRecurent, item.InventoryCD);
                                }
                            }
                        }
                        else if (billing.AccountSource == PMAccountSource.Customer && customer != null)
                        {
                            CR.Location customerLoc = PXSelect <CR.Location, Where <CR.Location.bAccountID, Equal <Required <CR.Location.bAccountID> >, And <CR.Location.locationID, Equal <Required <CR.Location.locationID> > > > > .Select(this, customer.BAccountID, customer.DefLocationID);

                            if (customerLoc != null)
                            {
                                if (customerLoc.CSalesAcctID != null)
                                {
                                    arTran.AccountID = customerLoc.CSalesAcctID;
                                }
                                else
                                {
                                    InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                                    throw new PXException(Messages.CustomerAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, customer.AcctCD);
                                }
                            }
                        }

                        if (arTran.AccountID == null && !string.IsNullOrEmpty(billing.SubMask))
                        {
                            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID);

                            throw new PXException(Messages.SubAccountCannotBeComposed, item.InventoryCD);
                        }
                        else if (arTran.AccountID != null && !string.IsNullOrEmpty(billing.SubMask))
                        {
                            subCD = PMRecurentBillSubAccountMaskAttribute.MakeSub <PMBillingRule.subMask>(this, billing.SubMask,
                                                                                                          new object[] { billing.SubID, project.DefaultSubID, task.DefaultSubID },
                                                                                                          new Type[] { typeof(PMBillingRule.subID), typeof(PMProject.defaultSubID), typeof(PMTask.defaultSubID) });
                        }
                    }

                    #endregion

                    list.Add(new BillingData(arTran, rule, null, subCD, null, null));

                    billing.LastBilledDate = billingDate;
                    ContractDetail.Update(billing);
                }
            }



            int            mult = 1;
            PMAccountGroup ag   = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, rule.AccountGroupID);

            if (ag == null)
            {
                throw new PXException(Messages.AccountGroupInBillingRuleNotFound, rule.BillingID, rule.AccountGroupID);
            }
            if (ag.Type == GL.AccountType.Liability || ag.Type == GL.AccountType.Income)
            {
                mult = -1;
            }

            DateTime cuttofDate = billingDate;            //all transactions  excluding the current day.
            ContractBillingSchedule schedule = PXSelect <ContractBillingSchedule> .Search <ContractBillingSchedule.contractID>(this, task.ProjectID);

            if (schedule != null && schedule.Type == BillingType.OnDemand)
            {
                cuttofDate = billingDate.AddDays(1);                //all transactions including the current day.
            }
            else
            {
                if (IncludeTodaysTransactions)
                {
                    cuttofDate = billingDate.AddDays(1);
                }
            }

            List <PMTran> billingBase = SelectBillingBase(task.ProjectID, task.TaskID, rule.AccountGroupID, cuttofDate,
                                                          rule.IncludeNonBillable == true);

            foreach (PMTran tran in billingBase)
            {
                ARTran arTran = new ARTran();
                arTran.BranchID = tran.BranchID;
                if (tran.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID)
                {
                    arTran.InventoryID = tran.InventoryID;
                }
                arTran.TranDesc = tran.Description;
                arTran.UOM      = tran.UOM;
                arTran.Qty      = tran.BillableQty * mult;
                arTran.ExtPrice = tran.Amount * mult;
                if (arTran.Qty != 0)
                {
                    arTran.UnitPrice = arTran.ExtPrice / arTran.Qty;
                }
                else
                {
                    arTran.UnitPrice = 0;
                }
                arTran.TranAmt        = arTran.ExtPrice;
                arTran.ProjectID      = task.ProjectID;
                arTran.TaskID         = task.TaskID;
                arTran.PMTranID       = tran.TranID;
                arTran.Commissionable = false;                 //todo
                arTran.Date           = tran.Date;

                string subCD = null;
                #region Set Account and Subaccount

                int?employeeSubID = null;

                if (tran.ResourceID != null)
                {
                    EP.EPEmployee emp = PXSelect <EP.EPEmployee, Where <EP.EPEmployee.bAccountID, Equal <Required <EP.EPEmployee.bAccountID> > > > .Select(this, tran.ResourceID);

                    if (emp != null)
                    {
                        employeeSubID = emp.SalesSubID;
                    }
                }

                if (rule.AccountSource != PMAccountSource.None)
                {
                    if (rule.AccountSource == PMAccountSource.BillingRule)
                    {
                        if (rule.AccountID != null)
                        {
                            arTran.AccountID = rule.AccountID;
                        }
                        else
                        {
                            throw new PXException(Messages.BillingRuleAccountIsNotConfiguredForBilling, rule.BillingID);
                        }
                    }
                    else if (rule.AccountSource == PMAccountSource.Project)
                    {
                        if (project.DefaultAccountID != null)
                        {
                            arTran.AccountID = project.DefaultAccountID;
                        }
                        else
                        {
                            throw new PXException(Messages.ProjectAccountIsNotConfiguredForBilling, rule.BillingID, project.ContractCD);
                        }
                    }
                    else if (rule.AccountSource == PMAccountSource.Task)
                    {
                        if (task.DefaultAccountID != null)
                        {
                            arTran.AccountID = task.DefaultAccountID;
                        }
                        else
                        {
                            throw new PXException(Messages.TaskAccountIsNotConfiguredForBilling, rule.BillingID, project.ContractCD, task.TaskCD);
                        }
                    }
                    else if (rule.AccountSource == PMAccountSource.InventoryItem)
                    {
                        InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, tran.InventoryID);

                        if (item != null)
                        {
                            if (item.SalesAcctID != null)
                            {
                                arTran.AccountID = item.SalesAcctID;
                            }
                            else
                            {
                                throw new PXException(Messages.InventoryAccountIsNotConfiguredForBilling, rule.BillingID, item.InventoryCD);
                            }
                        }
                    }
                    else if (rule.AccountSource == PMAccountSource.Customer && customer != null)
                    {
                        CR.Location customerLoc = PXSelect <CR.Location, Where <CR.Location.bAccountID, Equal <Required <CR.Location.bAccountID> >, And <CR.Location.locationID, Equal <Required <CR.Location.locationID> > > > > .Select(this, customer.BAccountID, customer.DefLocationID);

                        if (customerLoc != null)
                        {
                            if (customerLoc.CSalesAcctID != null)
                            {
                                arTran.AccountID = customerLoc.CSalesAcctID;
                            }
                            else
                            {
                                throw new PXException(Messages.CustomerAccountIsNotConfiguredForBilling, rule.BillingID, customer.AcctCD);
                            }
                        }
                    }
                    else if (rule.AccountSource == PMAccountSource.Resource)
                    {
                        EP.EPEmployee emp = PXSelect <EP.EPEmployee, Where <EP.EPEmployee.bAccountID, Equal <Required <EP.EPEmployee.bAccountID> > > > .Select(this, tran.ResourceID);

                        if (emp != null)
                        {
                            if (emp.SalesAcctID != null)
                            {
                                arTran.AccountID = emp.SalesAcctID;
                            }
                            else
                            {
                                throw new PXException(Messages.EmployeeAccountIsNotConfiguredForBilling, rule.BillingID, emp.AcctCD);
                            }
                        }
                    }

                    if (arTran.AccountID == null && !string.IsNullOrEmpty(rule.SubMask))
                    {
                        throw new PXException(Messages.SubAccountCannotBeComposed, rule.BillingID);
                    }
                    else if (arTran.AccountID != null && !string.IsNullOrEmpty(rule.SubMask))
                    {
                        subCD = PMBillSubAccountMaskAttribute.MakeSub <PMBillingRule.subMask>(this, rule.SubMask,
                                                                                              new object[] { tran.SubID, rule.SubID, project.DefaultSubID, task.DefaultSubID, employeeSubID },
                                                                                              new Type[] { typeof(PMTran.subID), typeof(PMBillingRule.subID), typeof(PMProject.defaultSubID), typeof(PMTask.defaultSubID), typeof(EP.EPEmployee.salesSubID) });
                    }
                }

                #endregion

                string note  = PXNoteAttribute.GetNote(Transactions.Cache, tran);
                Guid[] files = PXNoteAttribute.GetFileNotes(Transactions.Cache, tran);
                list.Add(new BillingData(arTran, rule, tran, subCD, note, files));

                if (billingItems.ContainsKey(tran.InventoryID.Value))
                {
                    if (availableQty.ContainsKey(tran.InventoryID.Value))
                    {
                        decimal available = availableQty[tran.InventoryID.Value];

                        if (tran.BillableQty <= available)
                        {
                            //Transaction is already payed for as a post payment included. Thus it should be free.
                            arTran.TranDesc = PXMessages.LocalizeNoPrefix(CT.Messages.PrefixIncludedUsage) + " " + tran.Description;
                            availableQty[tran.InventoryID.Value] -= arTran.Qty.Value;                            //decrease available qty
                            arTran.UnitPrice = 0;
                            arTran.ExtPrice  = 0;
                            arTran.TranAmt   = 0;
                        }
                        else
                        {
                            arTran.TranDesc = PXMessages.LocalizeNoPrefix(CT.Messages.PrefixOverused) + " " + tran.Description;
                            arTran.Qty      = arTran.Qty - available;
                            availableQty[tran.InventoryID.Value] = 0;                            //all available qty was used.
                        }
                    }
                }

                tran.Billed     = true;
                tran.BilledDate = billingDate;

                Transactions.Update(tran);
            }

            return(list);
        }
Esempio n. 12
0
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            string             LastBatchNbr = "0000000000";
            Int64              LastInfoID   = -1;
            List <ScheduleDet> sd           = MakeSchedule(s, Times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet d in sd)
                {
                    foreach (BatchNew b in PXSelect <BatchNew, Where <BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >, And <BatchNew.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(b);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(this, b.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = LastInfoID;
                            copy.CuryInfoID     = LastInfoID;
                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted    = false;
                        copy.Released  = false;
                        copy.Status    = "B";
                        copy.Scheduled = false;

                        copy.DateEntered  = d.ScheduledDate;
                        copy.FinPeriodID  = d.ScheduledPeriod;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = LastBatchNbr;
                        copy.RefBatchNbr = LastBatchNbr;
                        LastBatchNbr     = AutoNumberAttribute.NextNumber(LastBatchNbr);
                        LastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.SetNote(Batch_Created.Cache, copy, PXNoteAttribute.GetNote(Caches[typeof(BatchNew)], b));
                        PXNoteAttribute.SetFileNotes(Batch_Created.Cache, copy, PXNoteAttribute.GetFileNotes(Caches[typeof(BatchNew)], b));

                        foreach (GLTranNew tran in PXSelect <GLTranNew, Where <GLTranNew.module, Equal <Required <GLTranNew.module> >, And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > > .Select(this, b.Module, b.BatchNbr))
                        {
                            GLTranNew trancopy = PXCache <GLTranNew> .CreateCopy(tran);

                            trancopy.OrigBatchNbr = trancopy.BatchNbr;
                            trancopy.OrigModule   = trancopy.Module;
                            trancopy.BatchNbr     = copy.BatchNbr;
                            trancopy.RefBatchNbr  = copy.RefBatchNbr;
                            trancopy.CuryInfoID   = copy.CuryInfoID;
                            trancopy.CATranID     = null;

                            trancopy.TranDate     = d.ScheduledDate;
                            trancopy.FinPeriodID  = d.ScheduledPeriod;
                            trancopy.TranPeriodID = d.ScheduledPeriod;
                            Tran_Created.Cache.Insert(trancopy);
                        }
                    }

                    s.LastRunDate = d.ScheduledDate;
                    Running_Schedule.Cache.Update(s);
                }
                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew tran in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew batch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(batch.RefBatchNbr, tran.RefBatchNbr))
                        {
                            tran.BatchNbr   = batch.BatchNbr;
                            tran.CuryInfoID = batch.CuryInfoID;
                            if (!string.IsNullOrEmpty(batch.RefNbr))
                            {
                                tran.RefNbr = batch.RefNbr;
                            }
                            break;
                        }
                    }
                }
                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
Esempio n. 13
0
        public static void ReleaseDoc(EPExpenseClaim claim)
        {
            APInvoiceEntry    docgraph     = PXGraph.CreateInstance <APInvoiceEntry>();
            ExpenseClaimEntry expenseclaim = PXGraph.CreateInstance <ExpenseClaimEntry>();

            if (claim.FinPeriodID == null)
            {
                throw new PXException(Messages.ReleaseClaimWithoutFinPeriod);
            }
            //docgraph.FieldVerifying.AddHandler<APInvoice.vendorLocationID>(APInterceptor);

            EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID);

            Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID);

            EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph);

            APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph);

            docgraph.vendor.Current   = employee;
            docgraph.location.Current = emplocation;

            CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID);

            CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal);

            info.CuryInfoID = null;
            info            = docgraph.currencyinfo.Insert(info);
            APInvoice invoice = new APInvoice();

            invoice.CuryInfoID = info.CuryInfoID;

            invoice.Hold     = true;
            invoice.Released = false;
            invoice.Printed  = false;
            invoice.OpenDoc  = true;

            invoice.DocDate          = claim.DocDate;
            invoice.InvoiceNbr       = claim.RefNbr;
            invoice.DocDesc          = claim.DocDesc;
            invoice.VendorID         = claim.EmployeeID;
            invoice.CuryID           = info.CuryID;
            invoice.VendorLocationID = claim.LocationID;
            invoice.APAccountID      = emplocation != null ? emplocation.APAccountID : null;
            invoice.APSubID          = emplocation != null ? emplocation.APSubID : null;
            invoice.TaxZoneID        = claim.TaxZoneID;
            invoice = docgraph.Document.Insert(invoice);

            PXCache claimcache       = docgraph.Caches[typeof(EPExpenseClaim)];
            PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)];

            if (epsetup.CopyNotesAP == true)
            {
                string note = PXNoteAttribute.GetNote(claimcache, claim);
                if (note != null)
                {
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, invoice, note);
                }
            }
            if (epsetup.CopyFilesAP == true)
            {
                Guid[] files = PXNoteAttribute.GetFileNotes(claimcache, claim);
                if (files != null && files.Length > 0)
                {
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, invoice, files);
                }
            }

            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);

                    foreach (PXResult <EPExpenseClaimDetails, Contract> res in PXSelectJoin <EPExpenseClaimDetails,
                                                                                             LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID> > >,
                                                                                             Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr))
                    {
                        EPExpenseClaimDetails claimdetail = (EPExpenseClaimDetails)res;
                        Contract contract = (Contract)res;

                        if (claimdetail.TaskID != null)
                        {
                            PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseclaim, claimdetail.TaskID);

                            if (task != null && !(bool)task.VisibleInAP)
                            {
                                throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP);
                            }
                        }

                        APTran tran = new APTran();
                        tran.InventoryID  = claimdetail.InventoryID;
                        tran.TranDesc     = claimdetail.TranDesc;
                        tran.CuryUnitCost = claimdetail.CuryUnitCost;
                        tran.Qty          = claimdetail.Qty;
                        tran.UOM          = claimdetail.UOM;
                        tran.NonBillable  = claimdetail.Billable != true;
                        tran.CuryLineAmt  = claimdetail.CuryTranAmt;
                        tran.Date         = claimdetail.ExpenseDate;

                        if (contract.BaseType == PM.PMProject.ProjectBaseType.Project)
                        {
                            tran.ProjectID = claimdetail.ContractID;
                        }
                        else
                        {
                            tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(docgraph);
                        }

                        tran.TaskID        = claimdetail.TaskID;
                        tran.AccountID     = claimdetail.ExpenseAccountID;
                        tran.SubID         = claimdetail.ExpenseSubID;
                        tran.TaxCategoryID = claimdetail.TaxCategoryID;
                        tran = docgraph.Transactions.Insert(tran);
                        if (epsetup.CopyNotesAP == true)
                        {
                            string note = PXNoteAttribute.GetNote(claimdetailcache, claimdetail);
                            if (note != null)
                            {
                                PXNoteAttribute.SetNote(docgraph.Transactions.Cache, tran, note);
                            }
                        }
                        if (epsetup.CopyFilesAP == true)
                        {
                            Guid[] files = PXNoteAttribute.GetFileNotes(claimdetailcache, claimdetail);
                            if (files != null && files.Length > 0)
                            {
                                PXNoteAttribute.SetFileNotes(docgraph.Transactions.Cache, tran, files);
                            }
                        }
                        claimdetail.Released = true;
                        expenseclaim.ExpenseClaimDetails.Update(claimdetail);
                    }

                    foreach (EPTaxTran tax in PXSelect <EPTaxTran, Where <EPTaxTran.refNbr, Equal <Required <EPTaxTran.refNbr> > > > .Select(docgraph, claim.RefNbr))
                    {
                        APTaxTran new_aptax = new APTaxTran();
                        new_aptax.TaxID = tax.TaxID;

                        new_aptax = docgraph.Taxes.Insert(new_aptax);

                        if (new_aptax != null)
                        {
                            new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax);

                            new_aptax.TaxRate        = tax.TaxRate;
                            new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_aptax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_aptax = docgraph.Taxes.Update(new_aptax);
                        }
                    }

                    invoice.CuryOrigDocAmt = invoice.CuryDocBal;
                    invoice.Hold           = false;
                    docgraph.Document.Update(invoice);
                    docgraph.Save.Press();
                    claim.Status    = EPClaimStatus.Released;
                    claim.Released  = true;
                    claim.APRefNbr  = invoice.RefNbr;
                    claim.APDocType = invoice.DocType;
                    expenseclaim.ExpenseClaim.Update(claim);

                    #region EP History Update
                    EPHistory hist = new EPHistory();
                    hist.EmployeeID  = invoice.VendorID;
                    hist.FinPeriodID = invoice.FinPeriodID;
                    hist             = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(hist);

                    hist.FinPtdClaimed += invoice.DocBal;
                    hist.FinYtdClaimed += invoice.DocBal;
                    if (invoice.FinPeriodID == invoice.TranPeriodID)
                    {
                        hist.TranPtdClaimed += invoice.DocBal;
                        hist.TranYtdClaimed += invoice.DocBal;
                    }
                    else
                    {
                        EPHistory tranhist = new EPHistory();
                        tranhist.EmployeeID      = invoice.VendorID;
                        tranhist.FinPeriodID     = invoice.TranPeriodID;
                        tranhist                 = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(tranhist);
                        tranhist.TranPtdClaimed += invoice.DocBal;
                        tranhist.TranYtdClaimed += invoice.DocBal;
                    }
                    expenseclaim.Views.Caches.Add(typeof(EPHistory));
                    #endregion

                    expenseclaim.Save.Press();

                    ts.Complete();
                }
            }
            if ((bool)epsetup.AutomaticReleaseAP == true)
            {
                List <APRegister> doclist = new List <APRegister>();
                doclist.Add(docgraph.Document.Current);
                APDocumentRelease.ReleaseDoc(doclist, false);
            }
        }
        public static void TransferDocProcessingCenter(PXGraph graph, CABatch doc, CABatchExt docExt)
        {
            var pcGraph = PXGraph.CreateInstance <CCProcessingCenterMaint>();

            pcGraph.ProcessingCenter.Current = pcGraph.
                                               ProcessingCenter.
                                               Search <CCProcessingCenter.processingCenterID>
                                                   (docExt.ProcessingCenterID);

            var processingCenter = pcGraph.ProcessingCenter.Current;

            if (processingCenter != null)
            {
                var providerIsDirectDeposit = PXMultipleProviderTypeSelectorAttribute.IsProvider <CCProcessingCenter.processingTypeName, IDDPaymentProcessing>(pcGraph.ProcessingCenter.Cache, processingCenter);
                if (providerIsDirectDeposit)
                {
                    IDDPaymentProcessing provider = null;
                    try
                    {
                        Type providerType = PXBuildManager.GetType(processingCenter.ProcessingTypeName, true);
                        provider = (IDDPaymentProcessing)Activator.CreateInstance(providerType);
                        provider.Initialize(pcGraph);
                    }
                    catch (Exception ex)
                    {
                        throw new PXException(Messages.FailedToCreateDirectDepositProvider, ex.Message);
                    }
                    var fileNotes = PXNoteAttribute.GetFileNotes(graph.Views[graph.PrimaryView].Cache, doc);
                    if (fileNotes.Length == 1)
                    {
                        var fileNote = fileNotes[0];
                        UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                        var    file = upload.GetFile(fileNote);
                        string message;
                        if (!provider.DoTransaction(file.FullName, file.BinData, out message))
                        {
                            throw new PXException(message);
                        }
                        else
                        {
                            docExt.FileTransferTime = DateTime.Now;
                            graph.Views[graph.PrimaryView].Cache.Update(doc);
                            graph.Actions.PressSave();
                        }
                    }
                    else
                    {
                        if (fileNotes.Length > 1)
                        {
                            throw new Exception(Messages.ACHTransferFailMoreThanOneAttachment);
                        }
                        else
                        {
                            throw new PXException(Messages.ACHTransferFailNoAttachment);
                        }
                    }
                }
                else
                {
                    throw new PXException(Messages.ACHTransferFailProviderIsNotForDirectDeposit);
                }
            }
            else
            {
                throw new PXException(Messages.ACHTransferFailNoProcessingCenterSelected);
            }
        }
Esempio n. 15
0
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate);

            ARInvoiceEntry docgraph = CreateGraph();

            foreach (ScheduleDet sdet in sd)
            {
                foreach (PXResult <ARInvoice, Customer, CurrencyInfo> res in PXSelectJoin <ARInvoice, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARInvoice.customerID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <ARInvoice.curyInfoID> > > >, Where <ARInvoice.scheduleID, Equal <Required <ARInvoice.scheduleID> >, And <ARInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                {
                    docgraph.Clear();
                    docgraph.customer.Current = (Customer)res;
                    ARInvoice    apdoc = (ARInvoice)res;
                    CurrencyInfo info  = (CurrencyInfo)res;

                    CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

                    new_info.CuryInfoID = null;
                    new_info            = docgraph.currencyinfo.Insert(new_info);

                    ARInvoice new_ardoc = PXCache <ARInvoice> .CreateCopy(apdoc);

                    new_ardoc.CuryInfoID          = new_info.CuryInfoID;
                    new_ardoc.DocDate             = sdet.ScheduledDate;
                    new_ardoc.FinPeriodID         = sdet.ScheduledPeriod;
                    new_ardoc.TranPeriodID        = null;
                    new_ardoc.DueDate             = null;
                    new_ardoc.DiscDate            = null;
                    new_ardoc.CuryOrigDiscAmt     = null;
                    new_ardoc.OrigDiscAmt         = null;
                    new_ardoc.RefNbr              = null;
                    new_ardoc.Scheduled           = false;
                    new_ardoc.CuryLineTotal       = 0m;
                    new_ardoc.CuryVatTaxableTotal = 0m;
                    new_ardoc.CuryVatExemptTotal  = 0m;
                    new_ardoc.NoteID              = null;
                    bool forceClear = false;
                    bool clearPM    = false;
                    if (new_ardoc.PMInstanceID.HasValue)
                    {
                        PXResult <CustomerPaymentMethod, CA.PaymentMethod> pmiResult = (PXResult <CustomerPaymentMethod, CA.PaymentMethod>) PXSelectJoin <CustomerPaymentMethod, InnerJoin <CA.PaymentMethod, On <CA.PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID> > >, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(docgraph, new_ardoc.PMInstanceID);

                        if (pmiResult != null)
                        {
                            CustomerPaymentMethod pmInstance    = pmiResult;
                            CA.PaymentMethod      paymentMethod = pmiResult;
                            if (pmInstance == null || pmInstance.IsActive != true || paymentMethod.IsActive != true || paymentMethod.UseForAR != true)
                            {
                                clearPM    = true;
                                forceClear = true;
                            }
                        }
                        else
                        {
                            clearPM    = true;
                            forceClear = true;
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(new_ardoc.PaymentMethodID) == false)
                        {
                            CA.PaymentMethod pm = PXSelect <CA.PaymentMethod, Where <CA.PaymentMethod.paymentMethodID, Equal <Required <CA.PaymentMethod.paymentMethodID> > > > .Select(docgraph, new_ardoc.PaymentMethodID);

                            if (pm == null || pm.IsActive != true || pm.UseForAR != true)
                            {
                                clearPM    = true;
                                forceClear = true;
                            }
                        }
                    }

                    if (clearPM)
                    {
                        new_ardoc.PMInstanceID    = null;
                        new_ardoc.PaymentMethodID = null;
                        new_ardoc.CashAccountID   = null;
                    }

                    new_ardoc = docgraph.Document.Insert(new_ardoc);

                    //force creditrule back
                    docgraph.customer.Current = (Customer)res;

                    if (forceClear == true)
                    {
                        ARInvoice copy = PXCache <ARInvoice> .CreateCopy(new_ardoc);

                        copy.PMInstanceID    = null;
                        copy.PaymentMethodID = null;
                        copy.CashAccountID   = null;
                        new_ardoc            = docgraph.Document.Update(copy);
                    }
                    AddressAttribute.CopyRecord <ARInvoice.billAddressID>(docgraph.Document.Cache, new_ardoc, apdoc, false);
                    ContactAttribute.CopyRecord <ARInvoice.billContactID>(docgraph.Document.Cache, new_ardoc, apdoc, false);

                    TaxAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetNote(Caches[typeof(ARInvoice)], apdoc));
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetFileNotes(Caches[typeof(ARInvoice)], apdoc));

                    foreach (ARTran aptran in PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        ARTran new_aptran = PXCache <ARTran> .CreateCopy(aptran);

                        new_aptran.RefNbr     = null;
                        new_aptran.CuryInfoID = null;
                        docgraph.Transactions.Insert(new_aptran);
                    }

                    foreach (ARTaxTran tax in PXSelect <ARTaxTran, Where <ARTaxTran.tranType, Equal <Required <ARTaxTran.tranType> >, And <ARTaxTran.refNbr, Equal <Required <ARTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        ARTaxTran new_artax = new ARTaxTran();
                        new_artax.TaxID = tax.TaxID;

                        new_artax = docgraph.Taxes.Insert(new_artax);

                        if (new_artax != null)
                        {
                            new_artax = PXCache <ARTaxTran> .CreateCopy(new_artax);

                            new_artax.TaxRate        = tax.TaxRate;
                            new_artax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_artax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_artax = docgraph.Taxes.Update(new_artax);
                        }
                    }

                    docgraph.Save.Press();
                }
                s.LastRunDate = sdet.ScheduledDate;
                Running_Schedule.Cache.Update(s);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
        }
Esempio n. 16
0
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate);

            APInvoiceEntry docgraph = CreateGraph();

            foreach (ScheduleDet sdet in sd)
            {
                foreach (PXResult <APInvoice, Vendor, CurrencyInfo> res in PXSelectJoin <APInvoice, InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >, Where <APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >, And <APInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                {
                    docgraph.Clear();
                    docgraph.vendor.Current = (Vendor)res;
                    APInvoice    apdoc = (APInvoice)res;
                    CurrencyInfo info  = (CurrencyInfo)res;

                    CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info);

                    new_info.CuryInfoID = null;
                    new_info            = docgraph.currencyinfo.Insert(new_info);

                    APInvoice new_apdoc = PXCache <APInvoice> .CreateCopy(apdoc);

                    new_apdoc.CuryInfoID          = new_info.CuryInfoID;
                    new_apdoc.DocDate             = sdet.ScheduledDate;
                    new_apdoc.FinPeriodID         = sdet.ScheduledPeriod;
                    new_apdoc.TranPeriodID        = null;
                    new_apdoc.DueDate             = null;
                    new_apdoc.DiscDate            = null;
                    new_apdoc.PayDate             = null;
                    new_apdoc.CuryOrigDiscAmt     = null;
                    new_apdoc.OrigDiscAmt         = null;
                    new_apdoc.RefNbr              = null;
                    new_apdoc.Scheduled           = false;
                    new_apdoc.CuryLineTotal       = 0m;
                    new_apdoc.CuryVatTaxableTotal = 0m;
                    new_apdoc.CuryVatExemptTotal  = 0m;
                    new_apdoc.NoteID              = null;
                    new_apdoc = docgraph.Document.Insert(new_apdoc);

                    TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetNote(Caches[typeof(APInvoice)], apdoc));
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetFileNotes(Caches[typeof(APInvoice)], apdoc));

                    foreach (APTran aptran in PXSelect <APTran, Where <APTran.tranType, Equal <Required <APTran.tranType> >, And <APTran.refNbr, Equal <Required <APTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        APTran new_aptran = PXCache <APTran> .CreateCopy(aptran);

                        new_aptran.RefNbr     = null;
                        new_aptran.CuryInfoID = null;
                        docgraph.Transactions.Insert(new_aptran);
                    }

                    foreach (APTaxTran tax in PXSelect <APTaxTran, Where <APTaxTran.tranType, Equal <Required <APTaxTran.tranType> >, And <APTaxTran.refNbr, Equal <Required <APTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr))
                    {
                        APTaxTran new_aptax = new APTaxTran();
                        new_aptax.TaxID = tax.TaxID;

                        new_aptax = docgraph.Taxes.Insert(new_aptax);

                        if (new_aptax != null)
                        {
                            new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax);

                            new_aptax.TaxRate        = tax.TaxRate;
                            new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_aptax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_aptax = docgraph.Taxes.Update(new_aptax);
                        }
                    }
                    docgraph.Save.Press();
                }
                s.LastRunDate = sdet.ScheduledDate;
                Running_Schedule.Cache.Update(s);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Running_Schedule.Cache.Persist(PXDBOperation.Update);
                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
        }